mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 23:55:49 +01:00
* feat(inline-toolbar): inline tools now can be used in the readonly mode * tests added * docs improved
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import BaseToolAdapter, { InternalInlineToolSettings } from './base';
|
|
import type { InlineTool as IInlineTool, InlineToolConstructable } from '@/types';
|
|
import type { InlineToolAdapter as InlineToolAdapterInterface } from '@/types/tools/adapters/inline-tool-adapter';
|
|
import { ToolType } from '@/types/tools/adapters/tool-type';
|
|
|
|
/**
|
|
* InlineTool object to work with Inline Tools constructables
|
|
*/
|
|
export default class InlineToolAdapter extends BaseToolAdapter<ToolType.Inline, IInlineTool> implements InlineToolAdapterInterface {
|
|
/**
|
|
* Tool type — Inline
|
|
*/
|
|
public type: ToolType.Inline = ToolType.Inline;
|
|
|
|
/**
|
|
* Tool's constructable blueprint
|
|
*/
|
|
protected constructable: InlineToolConstructable;
|
|
|
|
/**
|
|
* Returns title for Inline Tool if specified by user
|
|
*/
|
|
public get title(): string {
|
|
return this.constructable[InternalInlineToolSettings.Title];
|
|
}
|
|
|
|
/**
|
|
* Constructs new InlineTool instance from constructable
|
|
*/
|
|
public create(): IInlineTool {
|
|
// eslint-disable-next-line new-cap
|
|
return new this.constructable({
|
|
api: this.api,
|
|
config: this.settings,
|
|
}) as IInlineTool;
|
|
}
|
|
|
|
/**
|
|
* Allows inline tool to be available in read-only mode
|
|
* Can be used, for example, by comments tool
|
|
*/
|
|
public get isReadOnlySupported(): boolean {
|
|
return this.constructable[InternalInlineToolSettings.IsReadOnlySupported] ?? false;
|
|
}
|
|
}
|