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

image selector fix #4120

Merged
merged 2 commits into from
Apr 22, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# [Unreleased]

- Prevent overriding of theme's default toolbar settings mistakenly [#4120](https://github.com/quilljs/quill/pull/4120)

# 2.0.0

We are thrilled to announce the release of Quill 2.0! Please check out the [announcement post](https://slab.com/blog/announcing-quill-2-0/).
Expand Down
27 changes: 15 additions & 12 deletions packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ function expandModuleConfig(config: Record<string, unknown> | undefined) {
...expanded,
[key]: value === true ? {} : value,
}),
{},
{} as Record<string, unknown>,
);
}

Expand Down Expand Up @@ -797,23 +797,26 @@ function expandConfig(
const { modules: quillModuleDefaults, ...quillDefaults } = Quill.DEFAULTS;
const { modules: themeModuleDefaults, ...themeDefaults } = theme.DEFAULTS;

const modules: ExpandedQuillOptions['modules'] = merge(
{},
expandModuleConfig(quillModuleDefaults),
expandModuleConfig(themeModuleDefaults),
expandModuleConfig(options.modules),
);
let userModuleOptions = expandModuleConfig(options.modules);
// Special case toolbar shorthand
if (
modules != null &&
modules.toolbar &&
modules.toolbar.constructor !== Object
userModuleOptions != null &&
userModuleOptions.toolbar &&
userModuleOptions.toolbar.constructor !== Object
) {
modules.toolbar = {
container: modules.toolbar,
userModuleOptions = {
...userModuleOptions,
toolbar: { container: userModuleOptions.toolbar },
};
}

const modules: ExpandedQuillOptions['modules'] = merge(
{},
expandModuleConfig(quillModuleDefaults),
expandModuleConfig(themeModuleDefaults),
userModuleOptions,
);

const config = {
...quillDefaults,
...omitUndefinedValuesFromOptions(themeDefaults),
Expand Down
15 changes: 15 additions & 0 deletions packages/quill/test/unit/core/quill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,21 @@ describe('Quill', () => {
});
});

test('toolbar container shorthand with theme options', () => {
const config = expandConfig(`#${testContainerId}`, {
modules: {
toolbar: document.querySelector(`#${testContainerId}`),
},
theme: 'snow',
});
for (const [format, handler] of Object.entries(
Snow.DEFAULTS.modules.toolbar!.handlers ?? {},
)) {
// @ts-expect-error
expect(config.modules.toolbar.handlers[format]).toBe(handler);
}
});

test('toolbar format array', () => {
const config = expandConfig(`#${testContainerId}`, {
modules: {
Expand Down
Loading