diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fe45169a2..709c47d0b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Include source maps for Parchment - **Clipboard** Support pasting links copied from iOS share sheets +- Fix config parsing where undefined values were kept # 2.0.0-rc.3 diff --git a/packages/quill/src/core/quill.ts b/packages/quill/src/core/quill.ts index 148933a4ee..ab900c5785 100644 --- a/packages/quill/src/core/quill.ts +++ b/packages/quill/src/core/quill.ts @@ -747,6 +747,12 @@ function expandModuleConfig(config: Record | undefined) { ); } +function omitUndefinedValuesFromOptions(obj: Options) { + return Object.fromEntries( + Object.entries(obj).filter((entry) => entry[1] !== undefined), + ); +} + function expandConfig( containerOrSelector: HTMLElement | string, options: Options, @@ -785,7 +791,11 @@ function expandConfig( }; } - const config = { ...quillDefaults, ...themeDefaults, ...options }; + const config = { + ...quillDefaults, + ...omitUndefinedValuesFromOptions(themeDefaults), + ...omitUndefinedValuesFromOptions(options), + }; let registry = options.registry; if (registry) { diff --git a/packages/quill/test/unit/core/quill.spec.ts b/packages/quill/test/unit/core/quill.spec.ts index 9680b200a8..dc17087b96 100644 --- a/packages/quill/test/unit/core/quill.spec.ts +++ b/packages/quill/test/unit/core/quill.spec.ts @@ -790,6 +790,13 @@ describe('Quill', () => { expect(config.registry).toBe(globalRegistry); }); + test('registry with undefined values', () => { + const config = expandConfig(`#${testContainerId}`, { + registry: undefined, + }); + expect(config.registry).toBe(globalRegistry); + }); + describe('formats', () => { test('null value allows all formats', () => { const config = expandConfig(`#${testContainerId}`, { @@ -800,6 +807,15 @@ describe('Quill', () => { expect(config.registry.query('bold')).toBeTruthy(); }); + test('undefined value allows all formats', () => { + const config = expandConfig(`#${testContainerId}`, { + formats: undefined, + }); + + expect(config.registry.query('cursor')).toBeTruthy(); + expect(config.registry.query('bold')).toBeTruthy(); + }); + test('always allows core formats', () => { const config = expandConfig(`#${testContainerId}`, { formats: ['bold'],