Skip to content

Commit

Permalink
refactor: generate header format
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxming committed Dec 27, 2024
1 parent 4740c46 commit 1d15c89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/header.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type TypeHeader from 'quill/formats/header';
import Quill from 'quill';
import { randomID } from './utils';

const Header = Quill.import('formats/header') as typeof TypeHeader;

export class HeaderWithID extends Header {
static create(value: any) {
const node = super.create(value);
node.id = randomID();
return node;
}
export function generateHeaderWithId(Header: typeof TypeHeader): typeof TypeHeader {
return class extends Header {
static create(value: any) {
const node = super.create(value);
node.id = randomID();
return node;
}
};
}
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type TypeHeader from 'quill/formats/header';
import type TypeToolbar from 'quill/modules/toolbar';
import Quill from 'quill';
import { HeaderWithID } from './formats';
import { generateHeaderWithId } from './header';
import headerListSvg from './svg/header-list.svg';
import { createBEM, isFunction, isNumber, isString, throttleAndDebounce } from './utils';

Expand Down Expand Up @@ -31,6 +32,9 @@ export class HeaderList {
const icons = Quill.import('ui/icons') as Record<string, string>;
icons[HeaderList.toolName] = headerListSvg;

const Header = Quill.import('formats/header') as typeof TypeHeader;
const HeaderWithID = generateHeaderWithId(Header);

Quill.register({
'formats/header': HeaderWithID,
}, true);
Expand Down

0 comments on commit 1d15c89

Please sign in to comment.