mirror of
https://github.com/codex-team/editor.js
synced 2024-06-06 16:02:50 +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
|
# 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
|
### 2.22.2
|
||||||
|
|
||||||
- `Improvement` — Inline Toolbar might be used for any contenteditable element inside Editor.js zone
|
- `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 Paragraph from '../../tools/paragraph/dist/bundle';
|
||||||
import Module from '../__module';
|
import Module from '../__module';
|
||||||
import * as _ from '../utils';
|
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 BoldInlineTool from '../inline-tools/inline-tool-bold';
|
||||||
import ItalicInlineTool from '../inline-tools/inline-tool-italic';
|
import ItalicInlineTool from '../inline-tools/inline-tool-italic';
|
||||||
import LinkInlineTool from '../inline-tools/inline-tool-link';
|
import LinkInlineTool from '../inline-tools/inline-tool-link';
|
||||||
|
@ -274,12 +274,12 @@ export default class Tools extends Module {
|
||||||
* @param config - tools config
|
* @param config - tools config
|
||||||
*/
|
*/
|
||||||
private getListOfPrepareFunctions(config: {[name: string]: ToolSettings}): {
|
private getListOfPrepareFunctions(config: {[name: string]: ToolSettings}): {
|
||||||
function: (data: { toolName: string }) => void | Promise<void>;
|
function: (data: { toolName: string; config: ToolConfig }) => void | Promise<void>;
|
||||||
data: { toolName: string };
|
data: { toolName: string; config: ToolConfig };
|
||||||
}[] {
|
}[] {
|
||||||
const toolPreparationList: {
|
const toolPreparationList: {
|
||||||
function: (data: { toolName: string }) => void | Promise<void>;
|
function: (data: { toolName: string }) => void | Promise<void>;
|
||||||
data: { toolName: string };
|
data: { toolName: string; config: ToolConfig };
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
Object
|
Object
|
||||||
|
@ -290,6 +290,7 @@ export default class Tools extends Module {
|
||||||
function: _.isFunction(settings.class.prepare) ? settings.class.prepare : (): void => {},
|
function: _.isFunction(settings.class.prepare) ? settings.class.prepare : (): void => {},
|
||||||
data: {
|
data: {
|
||||||
toolName,
|
toolName,
|
||||||
|
config: settings.config,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -72,6 +72,32 @@ describe('Tools module', () => {
|
||||||
|
|
||||||
expect(err).to.be.instanceOf(Error);
|
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', () => {
|
context('collection accessors', () => {
|
||||||
|
@ -173,7 +199,7 @@ describe('Tools module', () => {
|
||||||
expect(module.unavailable).to.be.instanceOf(Map);
|
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('withSuccessfulPrepare')).to.be.false;
|
||||||
expect(module.unavailable.has('withoutPrepare')).to.be.false;
|
expect(module.unavailable.has('withoutPrepare')).to.be.false;
|
||||||
expect(module.unavailable.has('withFailedPrepare')).to.be.true;
|
expect(module.unavailable.has('withFailedPrepare')).to.be.true;
|
||||||
|
|
Loading…
Reference in a new issue