Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config parsing where undefined values were kept #4068

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ function expandModuleConfig(config: Record<string, unknown> | undefined) {
);
}

function omitUndefinedValuesFromOptions(obj: Options) {
return Object.fromEntries(
Object.entries(obj).filter((entry) => entry[1] !== undefined),
);
}

function expandConfig(
containerOrSelector: HTMLElement | string,
options: Options,
Expand Down Expand Up @@ -785,7 +791,11 @@ function expandConfig(
};
}

const config = { ...quillDefaults, ...themeDefaults, ...options };
const config = {
...quillDefaults,
...omitUndefinedValuesFromOptions(themeDefaults),
...omitUndefinedValuesFromOptions(options),
};

let registry = options.registry;
if (registry) {
Expand Down
16 changes: 16 additions & 0 deletions packages/quill/test/unit/core/quill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, {
Expand All @@ -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'],
Expand Down
Loading