diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4396c901..2c783388 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 2.22.3 + +- `Fix` — Tool config is passed to `prepare` method [editor-js/embed#68](https://github.com/editor-js/embed/issues/68) + ### 2.22.2 - `Improvement` — Inline Toolbar might be used for any contenteditable element inside Editor.js zone diff --git a/src/components/modules/tools.ts b/src/components/modules/tools.ts index 2b4c9bcc..5ff3cf7a 100644 --- a/src/components/modules/tools.ts +++ b/src/components/modules/tools.ts @@ -1,7 +1,7 @@ import Paragraph from '../../tools/paragraph/dist/bundle'; import Module from '../__module'; import * as _ from '../utils'; -import { SanitizerConfig, ToolConstructable, ToolSettings } from '../../../types'; +import { SanitizerConfig, ToolConfig, ToolConstructable, ToolSettings } from '../../../types'; import BoldInlineTool from '../inline-tools/inline-tool-bold'; import ItalicInlineTool from '../inline-tools/inline-tool-italic'; import LinkInlineTool from '../inline-tools/inline-tool-link'; @@ -274,12 +274,12 @@ export default class Tools extends Module { * @param config - tools config */ private getListOfPrepareFunctions(config: {[name: string]: ToolSettings}): { - function: (data: { toolName: string }) => void | Promise; - data: { toolName: string }; + function: (data: { toolName: string; config: ToolConfig }) => void | Promise; + data: { toolName: string; config: ToolConfig }; }[] { const toolPreparationList: { function: (data: { toolName: string }) => void | Promise; - data: { toolName: string }; + data: { toolName: string; config: ToolConfig }; }[] = []; Object @@ -290,6 +290,7 @@ export default class Tools extends Module { function: _.isFunction(settings.class.prepare) ? settings.class.prepare : (): void => {}, data: { toolName, + config: settings.config, }, }); }); diff --git a/test/cypress/tests/modules/Tools.spec.ts b/test/cypress/tests/modules/Tools.spec.ts index 7e15a34f..208916b5 100644 --- a/test/cypress/tests/modules/Tools.spec.ts +++ b/test/cypress/tests/modules/Tools.spec.ts @@ -72,6 +72,32 @@ describe('Tools module', () => { expect(err).to.be.instanceOf(Error); }); + + // eslint-disable-next-line cypress/no-async-tests + it('should call Tools prepare method with user config', async () => { + class WithSuccessfulPrepare { + // eslint-disable-next-line @typescript-eslint/no-empty-function + public static prepare = cy.stub() + } + + const config = { + property: 'value', + }; + + const module = constructModule({ + defaultBlock: 'withSuccessfulPrepare', + tools: { + withSuccessfulPrepare: { + class: WithSuccessfulPrepare as any, + config, + }, + }, + }); + + await module.prepare(); + + expect(WithSuccessfulPrepare.prepare).to.be.calledWithExactly({ toolName: 'withSuccessfulPrepare', config }); + }); }); context('collection accessors', () => { @@ -173,7 +199,7 @@ describe('Tools module', () => { expect(module.unavailable).to.be.instanceOf(Map); }); - it('should contain only ready to use Tools', () => { + it('should contain unavailable Tools', () => { expect(module.unavailable.has('withSuccessfulPrepare')).to.be.false; expect(module.unavailable.has('withoutPrepare')).to.be.false; expect(module.unavailable.has('withFailedPrepare')).to.be.true;