diff --git a/package.json b/package.json index 9013f4cf..1d49ecb6 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,8 @@ "LICENSE" ], "dependencies": { - "@types/quill": "^1.3.10", - "lodash": "^4.17.4", - "quill": "^1.3.7" + "lodash": "^4.17.21", + "quill": "^2.0.0-rc.4" }, "peerDependencies": { "react": "^16 || ^17 || ^18", @@ -70,6 +69,7 @@ "jsdom-global": "^3.0.2", "mocha": "^6.2.2", "mocha-text-cov": "^0.1.1", + "quill-delta": "^5.1.0", "react": "^16.11.0", "react-dom": "^16.11.0", "react-test-renderer": "^16.11.0", diff --git a/src/index.tsx b/src/index.tsx index f83a11db..dca751b8 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,14 +7,10 @@ import React from 'react'; import ReactDOM from 'react-dom'; import isEqual from 'lodash/isEqual'; -import Quill, { - QuillOptionsStatic, - DeltaStatic, - RangeStatic, - BoundsStatic, - StringMap, - Sources, -} from 'quill'; +import Quill, { QuillOptions as QuillOptionsStatic } from 'quill'; +import type { EmitterSource as Sources } from 'quill/core/emitter'; +import type { Range as RangeStatic } from 'quill/core/selection'; +import type DeltaStatic from 'quill-delta'; // Merged namespace hack to export types along with default object // See: https://github.com/Microsoft/TypeScript/issues/2719 @@ -23,6 +19,8 @@ namespace ReactQuill { export type Range = RangeStatic | null; export interface QuillOptions extends QuillOptionsStatic { + scrollingContainer?: HTMLElement | string | undefined, + strict?: boolean | undefined, tabIndex?: number, } @@ -33,7 +31,7 @@ namespace ReactQuill { defaultValue?: Value, formats?: string[], id?: string, - modules?: StringMap, + modules?: QuillOptions['modules'], onChange?( value: string, delta: DeltaStatic, @@ -69,12 +67,12 @@ namespace ReactQuill { } export interface UnprivilegedEditor { - getLength(): number; - getText(index?: number, length?: number): string; - getHTML(): string; - getBounds(index: number, length?: number): BoundsStatic; - getSelection(focus?: boolean): RangeStatic; - getContents(index?: number, length?: number): DeltaStatic; + getLength: Quill['getLength']; + getText: Quill['getText']; + getHTML: Quill['getSemanticHTML']; + getBounds: Quill['getBounds']; + getSelection: Quill['getSelection']; + getContents: Quill['getContents']; } } @@ -328,7 +326,7 @@ class ReactQuill extends React.Component { Creates an editor on the given element. The editor will be passed the configuration, have its events bound, */ - createEditor(element: Element, config: QuillOptions) { + createEditor(element: HTMLElement, config: QuillOptions) { const editor = new Quill(element, config); if (config.tabIndex != null) { this.setEditorTabIndex(editor, config.tabIndex); @@ -384,7 +382,7 @@ class ReactQuill extends React.Component { this.value = value; const sel = this.getEditorSelection(); if (typeof value === 'string') { - editor.setContents(editor.clipboard.convert(value)); + editor.setContents(editor.clipboard.convert({html: value})); } else { editor.setContents(value); } @@ -432,7 +430,7 @@ class ReactQuill extends React.Component { }; } - getEditingArea(): Element { + getEditingArea(): HTMLElement { if (!this.editingArea) { throw new Error('Instantiating on missing editing area'); } @@ -443,7 +441,7 @@ class ReactQuill extends React.Component { if (element.nodeType === 3) { throw new Error('Editing area cannot be a text node'); } - return element as Element; + return element as HTMLElement; } /*