mirror of
https://github.com/codex-team/editor.js
synced 2024-05-17 05:46:46 +02:00
Fix: pass user configuration to Tool prepare method (#1781)
* Fix: pass user configuration to Tool prepare method * Fix lint * update types * Update changelog
This commit is contained in:
parent
65b86c9203
commit
a3df3b8ace
|
@ -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
|
||||
|
|
|
@ -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<void>;
|
||||
data: { toolName: string };
|
||||
function: (data: { toolName: string; config: ToolConfig }) => void | Promise<void>;
|
||||
data: { toolName: string; config: ToolConfig };
|
||||
}[] {
|
||||
const toolPreparationList: {
|
||||
function: (data: { toolName: string }) => void | Promise<void>;
|
||||
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,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue