diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 29974bf9..002d8555 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,9 +7,9 @@ import { EventBus, type InlineToolConstructor, PluginType, - ToolType + ToolType, + type ToolStaticOptions } from '@editorjs/sdk'; -import type { ToolSettings } from './tools/ToolsFactory'; import { composeDataFromVersion2 } from './utils/composeDataFromVersion2.js'; import ToolsManager from './tools/ToolsManager.js'; import type { CoreConfigValidated, CoreConfig, EditorjsPluginConstructor, BlockTuneConstructor, ToolConstructable, EditorjsAdapterPluginConstructor } from '@editorjs/sdk'; @@ -126,9 +126,9 @@ export default class Core { /** * Injects Tool constructor and options into the container * @param tool - Tool constructor class (static `options` defines defaults merged with the second argument) - * @param options - feature flags, `config` for the tool plugin, etc. + * @param options - Overrides for the tool's static `options` (toolbox, title, config, shortcuts, etc.) */ - public use(tool: ToolConstructable, options?: Omit): Core; + public use(tool: ToolConstructable, options?: ToolStaticOptions): Core; /** * Injects Plugin into the container to initialize on Editor's init * @param plugin - allows to pass any implementation of editor plugins @@ -141,7 +141,7 @@ export default class Core { */ public use( pluginOrTool: ToolConstructable | EditorjsPluginConstructor | EditorjsAdapterPluginConstructor, - options?: Omit + options?: ToolStaticOptions ): Core { const pluginType = pluginOrTool.type; @@ -149,7 +149,7 @@ export default class Core { case ToolType.Block: case ToolType.Inline: case ToolType.Tune: - this.#plugins.bind<[ToolConstructable, ToolSettings | undefined]>(pluginType).toConstantValue([pluginOrTool as ToolConstructable, options as ToolSettings | undefined]); + this.#plugins.bind<[ToolConstructable, ToolStaticOptions | undefined]>(pluginType).toConstantValue([pluginOrTool as ToolConstructable, options]); break; case PluginType.Adapter: if (this.#plugins.isBound(PluginType.Adapter)) { @@ -193,9 +193,9 @@ export default class Core { * Initalizes loaded tools */ async #initializeTools(): Promise { - const blockTools = this.#plugins.getAll<[BlockToolConstructor, ToolSettings]>(ToolType.Block); - const inlineTools = this.#plugins.getAll<[InlineToolConstructor, ToolSettings]>(ToolType.Inline); - const blockTunes = this.#plugins.getAll<[BlockTuneConstructor, ToolSettings]>(ToolType.Tune); + const blockTools = this.#plugins.getAll<[BlockToolConstructor, ToolStaticOptions | undefined]>(ToolType.Block); + const inlineTools = this.#plugins.getAll<[InlineToolConstructor, ToolStaticOptions | undefined]>(ToolType.Inline); + const blockTunes = this.#plugins.getAll<[BlockTuneConstructor, ToolStaticOptions | undefined]>(ToolType.Tune); return this.#toolsManager.prepareTools([...blockTools, ...inlineTools, ...blockTunes]); } diff --git a/packages/core/src/tools/ToolsFactory.ts b/packages/core/src/tools/ToolsFactory.ts index 83e3625c..36b3790e 100644 --- a/packages/core/src/tools/ToolsFactory.ts +++ b/packages/core/src/tools/ToolsFactory.ts @@ -1,25 +1,24 @@ /* eslint-disable jsdoc/informative-docs */ import type { EditorAPI } from '@editorjs/sdk'; import { ToolType } from '@editorjs/sdk'; -import type { ToolConstructable } from '@editorjs/sdk'; +import type { ToolConstructable, ToolStaticOptions } from '@editorjs/sdk'; import { InlineToolFacade, BlockTuneFacade, BlockToolFacade } from '@editorjs/sdk'; import type { - EditorConfig, - ToolSettings as ToolSettingsV2 + EditorConfig } from '@editorjs/editorjs'; type ToolConstructor = typeof InlineToolFacade | typeof BlockToolFacade | typeof BlockTuneFacade; /** - * Need this utility type to override some V2 options + * Full tool registration entry: the constructor class plus its options. */ -export type ToolSettings = Omit & { +export type ToolSettings = ToolStaticOptions & { /** - * Redefine constructable to match V3 + * Tool's constructor */ class: ToolConstructable; }; @@ -70,10 +69,10 @@ export class ToolsFactory { * Register tools in the factory * @param tools - tools to register in the factory */ - public setTools(tools: [ToolConstructable, ToolSettings][]): void { + public setTools(tools: [ToolConstructable, ToolStaticOptions | undefined][]): void { tools.forEach(([tool, settings]) => { this.#toolsSettings.set(tool.name, { - ...settings, + ...(settings ?? {}), class: tool, }); }); diff --git a/packages/core/src/tools/ToolsManager.ts b/packages/core/src/tools/ToolsManager.ts index d58a09df..a818d811 100644 --- a/packages/core/src/tools/ToolsManager.ts +++ b/packages/core/src/tools/ToolsManager.ts @@ -14,7 +14,8 @@ import { ToolFacadeClass, ToolsCollection, EventBus, - ToolConstructable + type ToolConstructable, + type ToolStaticOptions } from '@editorjs/sdk'; /** @@ -105,7 +106,7 @@ export default class ToolsManager { * Calls tools prepare method if it exists and adds tools to relevant collection (available or unavailable tools) * @param tools - tools to prepare and their settings */ - public async prepareTools(tools: [ToolConstructable, ToolSettings][]): Promise { + public async prepareTools(tools: [ToolConstructable, ToolStaticOptions | undefined][]): Promise { const promiseQueue = new PromiseQueue(); const setToAvailableToolsCollection = (toolName: string, tool: ToolFacadeClass): void => { diff --git a/packages/core/src/tools/internal/inline-tools/bold/index.ts b/packages/core/src/tools/internal/inline-tools/bold/index.ts index 265394c1..ba3ec7bf 100644 --- a/packages/core/src/tools/internal/inline-tools/bold/index.ts +++ b/packages/core/src/tools/internal/inline-tools/bold/index.ts @@ -19,12 +19,19 @@ export class BoldInlineTool implements InlineTool { */ public static type = ToolType.Inline as const; - public static title = 'Bold'; + /** + * Tool name used to identify the tool across the editor. + */ + public static name = 'bold'; /** * Predefined options (can be overriden on connection) */ public static readonly options = { + /** + * Tool title shown in the inline toolbar + */ + title: 'Bold', /** * Shortcuts plugin options */ diff --git a/packages/core/src/tools/internal/inline-tools/italic/index.ts b/packages/core/src/tools/internal/inline-tools/italic/index.ts index 3eee2e7e..00d848b5 100644 --- a/packages/core/src/tools/internal/inline-tools/italic/index.ts +++ b/packages/core/src/tools/internal/inline-tools/italic/index.ts @@ -19,12 +19,19 @@ export class ItalicInlineTool implements InlineTool { */ public static type = ToolType.Inline as const; - public static title = 'Italic'; + /** + * Tool name used to identify the tool across the editor. + */ + public static name = 'italic'; /** * Default options (merged with second argument of `use(ItalicInlineTool, options)`). */ public static readonly options = { + /** + * Tool title shown in the inline toolbar + */ + title: 'Italic', /** * Shortcuts plugin options */ diff --git a/packages/core/src/tools/internal/inline-tools/link/index.ts b/packages/core/src/tools/internal/inline-tools/link/index.ts index 7f2bfd04..57d15c29 100644 --- a/packages/core/src/tools/internal/inline-tools/link/index.ts +++ b/packages/core/src/tools/internal/inline-tools/link/index.ts @@ -26,7 +26,20 @@ export class LinkInlineTool implements InlineTool { */ public static type = ToolType.Inline as const; - public static title = 'Link'; + /** + * Tool name used to identify the tool across the editor. + */ + public static name = 'link'; + + /** + * Default options (merged with second argument of `use(LinkInlineTool, options)`). + */ + public static readonly options = { + /** + * Tool title shown in the inline toolbar + */ + title: 'Link', + }; /** * Type of behaviour of the tool if new selection range intersect with existing fragment diff --git a/packages/sdk/src/entities/BaseTool.ts b/packages/sdk/src/entities/BaseTool.ts index 984adec3..c54d4d42 100644 --- a/packages/sdk/src/entities/BaseTool.ts +++ b/packages/sdk/src/entities/BaseTool.ts @@ -1,35 +1,96 @@ import type { ToolConfig } from '@editorjs/editorjs'; +import type { BlockToolOptions } from './BlockTool.js'; +import type { InlineToolOptions } from './InlineTool.js'; +import type { BlockTuneOptions } from './BlockTune.js'; +import type { ToolType } from './EntityType.js'; /** - * Common interface for Tools static properties + * Canonical keys shared by every tool options interface. */ -export interface BaseToolConstructor { +export enum BaseToolOptionKey { /** - * Default tool options (`static get options()`) provided by the tool developer. + * Plugin-specific configuration object passed to the tool instance. */ - options?: { - /** - * Internal tool configuration - */ - config?: Record; + Config = 'config' +} + +/** + * Options common to every tool type. + * @template Config - Shape of the plugin-specific {@link BaseToolOptionKey.Config} object. + */ +export interface BaseToolOptions { + /** + * Plugin-specific configuration passed to the tool instance. + * Defaults set here are merged with (and overridden by) the `config` key + * in the second argument of `core.use(Tool, options)`. + */ + [BaseToolOptionKey.Config]?: Config; +} - /** - * Other tool options - */ - [key: string]: unknown; - }; +// Re-export so consumers can import all option types from this file +export type { BlockToolOptions, InlineToolOptions, BlockTuneOptions }; + +/** + * Union of all per-tool option shapes. + * Used as the type of the second argument of `core.use(Tool, options)`. + */ +export type ToolStaticOptions = BlockToolOptions | InlineToolOptions | BlockTuneOptions; + +/** + * Maps a {@link ToolType} value to its corresponding tool options interface. + * @example + * function getTitle(type: T, options: ToolTypeToOptions[T]) { ... } + */ +export type ToolTypeToOptions = { + /** + * BlockTool Options + */ + [ToolType.Block]: BlockToolOptions; + /** + * InlineTool Options + */ + [ToolType.Inline]: InlineToolOptions; + /** + * BlockTune Options + */ + [ToolType.Tune]: BlockTuneOptions; +}; + +/** + * Common interface for Tool constructor (static) side. + * @template Config - Shape of the plugin-specific config object. Passed to + * {@link prepare} and used to type {@link options.config}. + * @template Options - The concrete options interface for this tool type + * (defaults to the generic {@link BaseToolOptions}). + */ +export interface BaseToolConstructor< + Config extends ToolConfig = ToolConfig, + Options extends BaseToolOptions = BaseToolOptions +> { + /** + * Tool name used to identify the tool across the editor. + * Falls back to the JavaScript class name if not explicitly set. + */ + name: string; + + /** + * All static configuration for the tool. + * Values here are defaults; they can be overridden via the second argument + * of `core.use(Tool, options)`. + */ + options?: Options; /** - * Tool's prepare method. Can be async + * Tool's prepare method. Can be async. * @param data - Object with toolName and config properties * @param data.toolName - Tool's own name - * @param data.config - Tool's configuration + * @param data.config - Merged plugin configuration */ // eslint-disable-next-line -- ESLint doesn't understand it's a type prepare?(data: { toolName: string, config: Config }): void | Promise; /** - * Tool's reset method to clean up anything set by prepare. Can be async + * Tool's reset method to clean up anything set by prepare. Can be async. */ reset?(): void | Promise; } diff --git a/packages/sdk/src/entities/BlockTool.ts b/packages/sdk/src/entities/BlockTool.ts index ee08c993..5361dafd 100644 --- a/packages/sdk/src/entities/BlockTool.ts +++ b/packages/sdk/src/entities/BlockTool.ts @@ -1,13 +1,68 @@ import type { - BlockTool as BlockToolVersion2, ToolboxConfigEntry, - ToolConfig + BlockTool as BlockToolVersion2, + ToolConfig, + ToolboxConfigEntry } from '@editorjs/editorjs'; import type { BlockToolConstructorOptions as BlockToolConstructorOptionsVersion2 } from '@editorjs/editorjs'; import type { ValueSerialized } from '@editorjs/model'; import type { BlockToolAdapter } from './BlockToolAdapter.js'; import type { ToolType } from '@/entities/EntityType.js'; -import type { InternalBlockToolSettings } from '@/tools'; -import type { BaseToolConstructor } from '@/entities/BaseTool'; +import type { BaseToolConstructor, BaseToolOptions } from '@/entities/BaseTool'; + +/** + * Canonical keys for Block Tool options. + * Use these instead of raw string literals when reading or writing block-tool options. + */ +export enum BlockToolOptionKey { + /** Toolbox entry / entries for this tool. */ + Toolbox = 'toolbox', + /** Whether read-only mode is supported. */ + IsReadOnlySupported = 'isReadOnlySupported', + /** Keyboard shortcut string (e.g. `CMD+SHIFT+H`). */ + Shortcut = 'shortcut', + /** Inline tools enabled for blocks of this type. */ + InlineToolbar = 'inlineToolbar', + /** Block tunes enabled for blocks of this type. */ + Tunes = 'tunes' +} + +/** + * Options available on **Block Tools** (`static options` or `use()` overrides). + * @template Config - Shape of the plugin-specific {@link BaseToolOptions.config} object. + */ +export interface BlockToolOptions + extends BaseToolOptions { + /** + * Toolbox entry (or entries) that represent this tool in the toolbox. + * Set to `false` to hide the tool from the toolbox entirely. + */ + [BlockToolOptionKey.Toolbox]?: ToolboxConfigEntry | ToolboxConfigEntry[] | false; + + /** + * Whether read-only mode is supported by this tool. + */ + [BlockToolOptionKey.IsReadOnlySupported]?: boolean; + + /** + * Keyboard shortcut string (e.g. `CMD+SHIFT+H`). + */ + [BlockToolOptionKey.Shortcut]?: string; + + /** + * Inline tools to enable for this block tool. + * Pass `true` to enable all registered inline tools, or an array of names. + */ + [BlockToolOptionKey.InlineToolbar]?: boolean | string[]; + + /** + * Block tunes to enable for this block tool. + * Pass `true` to enable all registered tunes, or an array of names. + */ + [BlockToolOptionKey.Tunes]?: boolean | string[]; + + /** Any additional custom options exposed by the tool developer. */ + [key: string]: unknown; +} /** * Extended BlockToolConstructorOptions interface for version 3. @@ -70,37 +125,19 @@ export type BlockTool< * Block Tool constructor class */ export interface BlockToolConstructor< - /** - * Data structure describing the tool's input/output data - */ Data extends BlockToolData = BlockToolData, /** - * User-end configuration for the tool + * Plugin-specific configuration type — also types `options.config` */ Config extends ToolConfig = ToolConfig, - /** - * Adapter type — defaults to the base BlockToolAdapter. - * Override with a more specific adapter type if your tool needs - * access to adapter methods beyond the base interface. - */ Adapter extends BlockToolAdapter = BlockToolAdapter -> extends BaseToolConstructor { +> extends BaseToolConstructor> { new(options: BlockToolConstructorOptions): BlockTool; /** * Property specifies that the class is a Block Tool */ type: ToolType.Block; - - /** - * If Tool supports read-only mode, this property should return true - */ - [InternalBlockToolSettings.IsReadOnlySupported]?: boolean; - - /** - * Returns Tool toolbox configuration (internal or user-specified) - */ - [InternalBlockToolSettings.Toolbox]?: ToolboxConfigEntry[]; } /** diff --git a/packages/sdk/src/entities/BlockTune.ts b/packages/sdk/src/entities/BlockTune.ts index a4603bba..66ebbbf4 100644 --- a/packages/sdk/src/entities/BlockTune.ts +++ b/packages/sdk/src/entities/BlockTune.ts @@ -4,7 +4,17 @@ import type { BlockTune as BlockTuneV2 } from '@editorjs/editorjs'; import type { ToolType } from '@/entities/EntityType.js'; -import type { BaseToolConstructor } from '@/entities/BaseTool'; +import type { BaseToolConstructor, BaseToolOptions } from '@/entities/BaseTool'; + +/** + * Options available on **Block Tunes** (`static options` or `use()` overrides). + * @template Config - Shape of the plugin-specific {@link BaseToolOptions.config} object. + */ +export interface BlockTuneOptions + extends BaseToolOptions { + /** Any additional custom options exposed by the tune developer. */ + [key: string]: unknown; +} /** * BlockTune data type @@ -58,9 +68,9 @@ export type BlockTune< > = Omit; /** - * Block Tool constructor class + * Block Tune constructor class */ -export interface BlockTuneConstructor extends BaseToolConstructor { +export interface BlockTuneConstructor extends BaseToolConstructor { new(options: BlockTuneConstructorOptions): BlockTune; /** diff --git a/packages/sdk/src/entities/InlineTool.ts b/packages/sdk/src/entities/InlineTool.ts index d8bfca05..35ca6190 100644 --- a/packages/sdk/src/entities/InlineTool.ts +++ b/packages/sdk/src/entities/InlineTool.ts @@ -1,9 +1,39 @@ import type { TextRange, InlineFragment, FormattingAction, IntersectType } from '@editorjs/model'; import type { InlineTool as InlineToolVersion2 } from '@editorjs/editorjs'; -import type { InlineToolConstructorOptions as InlineToolConstructorOptionsVersion2 } from '@editorjs/editorjs'; +import type { InlineToolConstructorOptions as InlineToolConstructorOptionsVersion2, ToolConfig } from '@editorjs/editorjs'; import type { ToolType } from '@/entities/EntityType.js'; -import type { InternalInlineToolSettings } from '@/tools'; -import type { BaseToolConstructor } from '@/entities/BaseTool'; +import type { BaseToolConstructor, BaseToolOptions } from '@/entities/BaseTool'; + +/** + * Canonical keys for Inline Tool options. + * Use these instead of raw string literals when reading or writing inline-tool options. + */ +export enum InlineToolOptionKey { + /** Human-readable title shown in the inline toolbar. */ + Title = 'title', + /** Keyboard shortcut string (e.g. `CMD+B`). */ + Shortcut = 'shortcut' +} + +/** + * Options available on **Inline Tools** (`static options` or `use()` overrides). + * @template Config - Shape of the plugin-specific {@link BaseToolOptions.config} object. + */ +export interface InlineToolOptions + extends BaseToolOptions { + /** + * Human-readable title shown in the inline toolbar. + */ + [InlineToolOptionKey.Title]?: string; + + /** + * Keyboard shortcut string (e.g. `CMD+B`). + */ + [InlineToolOptionKey.Shortcut]?: string; + + /** Any additional custom options exposed by the tool developer. */ + [key: string]: unknown; +} /** * Extended InlineToolConstructorOptions interface for version 3. @@ -100,19 +130,13 @@ export interface InlineTool extends Omit {}; /** - * @todo support options: InlineToolConstructableOptions * Inline Tool constructor class */ -export interface InlineToolConstructor extends BaseToolConstructor { +export interface InlineToolConstructor extends BaseToolConstructor { new(): InlineTool; /** * Property specifies the entity is an Inline Tool */ type: ToolType.Inline; - - /** - * Tool title - */ - [InternalInlineToolSettings.Title]: string; } diff --git a/packages/sdk/src/entities/index.ts b/packages/sdk/src/entities/index.ts index 89ba9d0d..12d13483 100644 --- a/packages/sdk/src/entities/index.ts +++ b/packages/sdk/src/entities/index.ts @@ -1,3 +1,4 @@ +export type * from './BaseTool.js'; export type * from './InlineTool.js'; export type * from './BlockTool.js'; export type * from './BlockTune.js'; diff --git a/packages/sdk/src/tools/facades/BaseToolFacade.ts b/packages/sdk/src/tools/facades/BaseToolFacade.ts index a6c5ba45..043e743b 100644 --- a/packages/sdk/src/tools/facades/BaseToolFacade.ts +++ b/packages/sdk/src/tools/facades/BaseToolFacade.ts @@ -1,111 +1,47 @@ import type { // SanitizerConfig, API as ApiMethods, - Tool, - ToolSettings + Tool } from '@editorjs/editorjs'; import { isFunction } from '@editorjs/helpers'; import { type BlockToolFacade } from './BlockToolFacade.js'; import { type InlineToolFacade } from './InlineToolFacade.js'; import { ToolType } from '../../entities/EntityType.js'; import { type BlockTuneFacade } from './BlockTuneFacade.js'; -import type { BlockTool, BlockToolConstructor, InlineTool, InlineToolConstructor, BlockTuneConstructor } from '../../entities'; +import type { + BlockTool, BlockToolConstructor, InlineTool, InlineToolConstructor, BlockTuneConstructor, + ToolTypeToOptions +} from '../../entities'; +import type { ToolStaticOptions, BlockToolOptions, InlineToolOptions, BlockTuneOptions } from '../../entities/BaseTool.js'; +import { BaseToolOptionKey } from '../../entities/BaseTool.js'; // eslint-disable-next-line @typescript-eslint/no-explicit-any -- need to allow any type here so extended interfaces pass export type ToolConstructable = BlockToolConstructor | InlineToolConstructor | BlockTuneConstructor; +// Re-export canonical option-key enums so facades/consumers can import from one place +export { BaseToolOptionKey } from '../../entities/BaseTool.js'; +export { BlockToolOptionKey } from '../../entities/BlockTool.js'; +export { InlineToolOptionKey } from '../../entities/InlineTool.js'; + /** - * Enum of Tool options provided by user + * Keys for the options the **user** supplies as the second argument of `core.use(Tool, options)`. + * Mirrors the keys of {@link BlockToolOptions} with user-facing names. */ export enum UserToolOptions { - /** - * Toolbox config for Tool - */ + /** Toolbox entry override for the tool. */ Toolbox = 'toolbox', - /** - * Enabled Inline Tools for Block Tool - */ + /** Inline tools enabled for blocks of this type. */ EnabledInlineTools = 'inlineToolbar', - /** - * Enabled Block Tunes for Block Tool - */ + /** Block tunes enabled for blocks of this type. */ EnabledBlockTunes = 'tunes', - /** - * Tool configuration - */ + /** Plugin-specific configuration. */ Config = 'config' } -/** - * Enum of Tool options provided by Tool - */ -export enum CommonInternalSettings { - /** - * Sanitize configuration for Tool - */ - SanitizeConfig = 'sanitize' -} +export type ToolOptions = ToolStaticOptions; -/** - * Enum of Tool options provided by Block Tool - */ -export enum InternalBlockToolSettings { - /** - * Is line breaks enabled for Tool - */ - IsEnabledLineBreaks = 'enableLineBreaks', - /** - * Tool Toolbox config - */ - Toolbox = 'toolbox', - /** - * Tool conversion config - */ - ConversionConfig = 'conversionConfig', - /** - * Is readonly mode supported for Tool - */ - IsReadOnlySupported = 'isReadOnlySupported', - /** - * Tool paste config - */ - PasteConfig = 'pasteConfig' -} - -/** - * Enum of Tool options provided by Inline Tool - */ -export enum InternalInlineToolSettings { - /** - * Inline Tool title for toolbar - */ - Title = 'title' // for Inline Tools. Block Tools can pass title along with icon through the 'toolbox' static prop. -} - -/** - * Enum of Tool options provided by Block Tune - */ -export enum InternalTuneSettings { - /** - * Flag specifies Tool is Block Tune - */ - IsTune = 'isTune' -} - -export type ToolOptions = Omit; - -/** - * Static `options` on the tool class (plugin-side defaults) - * provided by the tool developer - */ -export type StaticToolOptions = Record; - -/** - * Result of merging static {@link ToolConstructable.options} with the second argument of `use(Tool, options)`. - */ -export interface MergedToolOptions { - [key: string]: unknown; -} +// Re-export per-tool option types so consumers can import them from here +export type { BlockToolOptions, InlineToolOptions, BlockTuneOptions }; /** * BlockToolFacade constructor options inteface @@ -164,7 +100,7 @@ export abstract class BaseToolFacade { - /* eslint-disable jsdoc/require-jsdoc -- inline cast only; shape is not a public API surface */ - const staticOpts = (this.constructable as { options?: { config?: Record } }).options; - const fromTool = staticOpts?.config ?? {}; + const staticOpts = this.constructable.options; + const fromTool = (staticOpts?.[BaseToolOptionKey.Config] ?? {}) as Record; const fromUse = (this.useToolOptions[UserToolOptions.Config] ?? {}) as Record; const merged: Record = { ...fromTool, diff --git a/packages/sdk/src/tools/facades/BlockToolFacade.ts b/packages/sdk/src/tools/facades/BlockToolFacade.ts index b16135c8..bada5e22 100644 --- a/packages/sdk/src/tools/facades/BlockToolFacade.ts +++ b/packages/sdk/src/tools/facades/BlockToolFacade.ts @@ -1,4 +1,6 @@ -import { BaseToolFacade, InternalBlockToolSettings, UserToolOptions } from './BaseToolFacade.js'; +import { BaseToolFacade, UserToolOptions } from './BaseToolFacade.js'; +import type { BlockToolOptions } from './BaseToolFacade.js'; +import { BlockToolOptionKey } from '../../entities/BlockTool.js'; import type { // ConversionConfig, // PasteConfig, @@ -37,10 +39,15 @@ export class BlockToolFacade extends BaseToolFacade public tunes: ToolsCollection = new ToolsCollection(); /** - * Tool's constructable blueprint + * Tool's constructable blueprint — narrowed to BlockToolConstructor */ protected declare constructable: BlockToolConstructor; + /** + * Narrowed to BlockToolOptions so block-specific properties are fully typed + */ + protected declare useToolOptions: BlockToolOptions; + /** * Creates new Tool instance * @param options - Tool constructor options @@ -64,7 +71,7 @@ export class BlockToolFacade extends BaseToolFacade * Returns true if read-only mode is supported by Tool */ public get isReadOnlySupported(): boolean { - return this.constructable[InternalBlockToolSettings.IsReadOnlySupported] === true; + return this.constructable.options?.[BlockToolOptionKey.IsReadOnlySupported] === true; } /** @@ -89,7 +96,7 @@ export class BlockToolFacade extends BaseToolFacade * config. This is made to allow user to override default tool's toolbox representation (single/multiple entries) */ public get toolbox(): ToolboxConfigEntry[] | undefined { - const toolToolboxSettings = this.constructable[InternalBlockToolSettings.Toolbox] as ToolboxConfig; + const toolToolboxSettings = this.constructable.options?.[BlockToolOptionKey.Toolbox] as ToolboxConfig; const userToolboxSettings = this.useToolOptions[UserToolOptions.Toolbox]; if (isEmpty(toolToolboxSettings)) { diff --git a/packages/sdk/src/tools/facades/InlineToolFacade.ts b/packages/sdk/src/tools/facades/InlineToolFacade.ts index 27c983fd..9021574c 100644 --- a/packages/sdk/src/tools/facades/InlineToolFacade.ts +++ b/packages/sdk/src/tools/facades/InlineToolFacade.ts @@ -1,4 +1,6 @@ -import { BaseToolFacade, InternalInlineToolSettings } from './BaseToolFacade.js'; +import { BaseToolFacade } from './BaseToolFacade.js'; +import type { InlineToolOptions } from './BaseToolFacade.js'; +import { InlineToolOptionKey } from '../../entities/InlineTool.js'; import type { InlineTool, InlineToolConstructor } from '../../entities'; import { ToolType } from '../../entities'; @@ -12,10 +14,15 @@ export class InlineToolFacade extends BaseToolFacade