editor.js/src/components/tools/inline.ts
Peter 2275ddfc3a
feat(inline-toolbar): inline tools now can be used in the readonly mode (#2832)
* feat(inline-toolbar): inline tools now can be used in the readonly mode

* tests added

* docs improved
2024-10-08 11:38:22 +03:00

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;
}
}