diff --git a/CHANGELOG.md b/CHANGELOG.md index 709c47d0b1..dddb05d65f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Include source maps for Parchment - **Clipboard** Support pasting links copied from iOS share sheets - Fix config parsing where undefined values were kept +- Expose types for Quill options # 2.0.0-rc.3 diff --git a/packages/quill/src/core.ts b/packages/quill/src/core.ts index 6de723d644..982f72c6d3 100644 --- a/packages/quill/src/core.ts +++ b/packages/quill/src/core.ts @@ -1,4 +1,9 @@ import Quill from './core/quill.js'; +import type { + DebugLevel, + ExpandedQuillOptions, + QuillOptions, +} from './core/quill.js'; import Block, { BlockEmbed } from './blots/block.js'; import Break from './blots/break.js'; @@ -18,6 +23,7 @@ import Input from './modules/input.js'; import UINode from './modules/uiNode.js'; export { Delta, Op, OpIterator, AttributeMap }; +export type { DebugLevel, ExpandedQuillOptions, QuillOptions }; Quill.register({ 'blots/block': Block, diff --git a/packages/quill/src/core/quill.ts b/packages/quill/src/core/quill.ts index ab900c5785..17219c33f7 100644 --- a/packages/quill/src/core/quill.ts +++ b/packages/quill/src/core/quill.ts @@ -30,18 +30,41 @@ const debug = logger('quill'); const globalRegistry = new Parchment.Registry(); Parchment.ParentBlot.uiClass = 'ql-ui'; -interface Options { +/** + * Options for initializing a Quill instance + */ +export interface QuillOptions { theme?: string; debug?: DebugLevel | boolean; registry?: Parchment.Registry; + /** + * Whether to disable the editing + * @default false + */ readOnly?: boolean; + + /** + * Placeholder text to display when the editor is empty + * @default "" + */ placeholder?: string; bounds?: HTMLElement | string | null; modules?: Record; + + /** + * A list of formats that are recognized and can exist within the editor contents. + * `null` means all formats are allowed. + * @default null + */ formats?: string[] | null; } -interface ExpandedOptions extends Omit { +/** + * Similar to QuillOptions, but with all properties expanded to their default values, + * and all selectors resolved to HTMLElements. + */ +export interface ExpandedQuillOptions + extends Omit { theme: ThemeConstructor; registry: Parchment.Registry; container: HTMLElement; @@ -63,7 +86,7 @@ class Quill { readOnly: false, registry: globalRegistry, theme: 'default', - } satisfies Partial; + } satisfies Partial; static events = Emitter.events; static sources = Emitter.sources; static version = typeof QUILL_VERSION === 'undefined' ? 'dev' : QUILL_VERSION; @@ -145,7 +168,7 @@ class Quill { root: HTMLDivElement; scroll: Scroll; emitter: Emitter; - allowReadOnlyEdits: boolean; + protected allowReadOnlyEdits: boolean; editor: Editor; composition: Composition; selection: Selection; @@ -156,9 +179,9 @@ class Quill { history: History; uploader: Uploader; - options: ExpandedOptions; + options: ExpandedQuillOptions; - constructor(container: HTMLElement | string, options: Options = {}) { + constructor(container: HTMLElement | string, options: QuillOptions = {}) { this.options = expandConfig(container, options); this.container = this.options.container; if (this.container == null) { @@ -747,7 +770,7 @@ function expandModuleConfig(config: Record | undefined) { ); } -function omitUndefinedValuesFromOptions(obj: Options) { +function omitUndefinedValuesFromOptions(obj: QuillOptions) { return Object.fromEntries( Object.entries(obj).filter((entry) => entry[1] !== undefined), ); @@ -755,8 +778,8 @@ function omitUndefinedValuesFromOptions(obj: Options) { function expandConfig( containerOrSelector: HTMLElement | string, - options: Options, -): ExpandedOptions { + options: QuillOptions, +): ExpandedQuillOptions { const container = resolveSelector(containerOrSelector); if (!container) { throw new Error('Invalid Quill container'); @@ -774,7 +797,7 @@ function expandConfig( const { modules: quillModuleDefaults, ...quillDefaults } = Quill.DEFAULTS; const { modules: themeModuleDefaults, ...themeDefaults } = theme.DEFAULTS; - const modules: ExpandedOptions['modules'] = merge( + const modules: ExpandedQuillOptions['modules'] = merge( {}, expandModuleConfig(quillModuleDefaults), expandModuleConfig(themeModuleDefaults), @@ -1004,4 +1027,6 @@ function shiftRange( return new Range(start, end - start); } +export type { DebugLevel }; + export { globalRegistry, expandConfig, overload, Quill as default }; diff --git a/packages/quill/src/quill.ts b/packages/quill/src/quill.ts index 6418df9583..fd364394c4 100644 --- a/packages/quill/src/quill.ts +++ b/packages/quill/src/quill.ts @@ -1,4 +1,5 @@ import Quill from './core.js'; +import type { DebugLevel, ExpandedQuillOptions, QuillOptions } from './core.js'; import { AlignClass, AlignStyle } from './formats/align.js'; import { @@ -108,4 +109,6 @@ Quill.register( true, ); +export type { DebugLevel, ExpandedQuillOptions, QuillOptions }; + export default Quill;