Prevent overriding of theme's default toolbar settings (#4120)

* theme toolbar's handlers overwritten fix

* Fix handling for true values and add CHANGELOG

---------

Co-authored-by: david ruty <david.ruty@arche-mc2.fr>
Co-authored-by: Zihua Li <i@zihua.li>
This commit is contained in:
medi6 2024-04-22 02:26:44 +02:00 committed by GitHub
parent 9062cb0bf9
commit 69e04334bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 12 deletions

View File

@ -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/).

View File

@ -766,7 +766,7 @@ function expandModuleConfig(config: Record<string, unknown> | undefined) {
...expanded,
[key]: value === true ? {} : value,
}),
{},
{} as Record<string, unknown>,
);
}
@ -797,22 +797,25 @@ function expandConfig(
const { modules: quillModuleDefaults, ...quillDefaults } = Quill.DEFAULTS;
const { modules: themeModuleDefaults, ...themeDefaults } = theme.DEFAULTS;
let userModuleOptions = expandModuleConfig(options.modules);
// Special case toolbar shorthand
if (
userModuleOptions != null &&
userModuleOptions.toolbar &&
userModuleOptions.toolbar.constructor !== Object
) {
userModuleOptions = {
...userModuleOptions,
toolbar: { container: userModuleOptions.toolbar },
};
}
const modules: ExpandedQuillOptions['modules'] = merge(
{},
expandModuleConfig(quillModuleDefaults),
expandModuleConfig(themeModuleDefaults),
expandModuleConfig(options.modules),
userModuleOptions,
);
// Special case toolbar shorthand
if (
modules != null &&
modules.toolbar &&
modules.toolbar.constructor !== Object
) {
modules.toolbar = {
container: modules.toolbar,
};
}
const config = {
...quillDefaults,

View File

@ -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: {