mirror of
https://github.com/codex-team/editor.js
synced 2024-06-27 01:40:22 +02:00
2d89105670
* Add internal wrappers for tools classes * FIx lint * Change tools collections to map * Apply some more refactoring * Make tool instance private field * Add some docs * Fix eslint * Basic implementation for Block Tunes * Small fix for demo * Review changes * Fix * Add common tunes and ToolsCollection class * Fixes after review * Rename tools collections * Readonly fix * Some fixes after review * Apply suggestions from code review Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Fixes after review * Add docs and changelog * Update docs/block-tunes.md Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Apply suggestions from code review Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update src/components/block/index.ts Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com> * [Dev] Tools utils tests (#1602) * Add tests for tools utils and coverage report * Fix eslint * Adjust test * Add more tests * Update after code review * Fix test & bump version Co-authored-by: Peter Savchenko <specc.dev@gmail.com> Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com>
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import BlockTool from './block';
|
|
import InlineTool from './inline';
|
|
import BlockTune from './tune';
|
|
|
|
export type ToolClass = BlockTool | InlineTool | BlockTune;
|
|
|
|
/**
|
|
* Class to store Editor Tools
|
|
*/
|
|
export default class ToolsCollection<V extends ToolClass = ToolClass> extends Map<string, V> {
|
|
/**
|
|
* Returns Block Tools collection
|
|
*/
|
|
public get blockTools(): ToolsCollection<BlockTool> {
|
|
const tools = Array
|
|
.from(this.entries())
|
|
.filter(([, tool]) => tool.isBlock()) as [string, BlockTool][];
|
|
|
|
return new ToolsCollection<BlockTool>(tools);
|
|
}
|
|
|
|
/**
|
|
* Returns Inline Tools collection
|
|
*/
|
|
public get inlineTools(): ToolsCollection<InlineTool> {
|
|
const tools = Array
|
|
.from(this.entries())
|
|
.filter(([, tool]) => tool.isInline()) as [string, InlineTool][];
|
|
|
|
return new ToolsCollection<InlineTool>(tools);
|
|
}
|
|
|
|
/**
|
|
* Returns Block Tunes collection
|
|
*/
|
|
public get blockTunes(): ToolsCollection<BlockTune> {
|
|
const tools = Array
|
|
.from(this.entries())
|
|
.filter(([, tool]) => tool.isTune()) as [string, BlockTune][];
|
|
|
|
return new ToolsCollection<BlockTune>(tools);
|
|
}
|
|
|
|
/**
|
|
* Returns internal Tools collection
|
|
*/
|
|
public get internalTools(): ToolsCollection<V> {
|
|
const tools = Array
|
|
.from(this.entries())
|
|
.filter(([, tool]) => tool.isInternal);
|
|
|
|
return new ToolsCollection<V>(tools);
|
|
}
|
|
|
|
/**
|
|
* Returns Tools collection provided by user
|
|
*/
|
|
public get externalTools(): ToolsCollection<V> {
|
|
const tools = Array
|
|
.from(this.entries())
|
|
.filter(([, tool]) => !tool.isInternal);
|
|
|
|
return new ToolsCollection<V>(tools);
|
|
}
|
|
}
|