@embedpdf/plugin-commands 3.0.0-next.9 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contract/host.cjs +18 -0
- package/dist/contract/host.cjs.map +1 -0
- package/dist/contract/host.d.cts +3 -0
- package/dist/contract/host.d.ts +3 -0
- package/dist/contract/host.js +13 -0
- package/dist/contract/host.js.map +1 -0
- package/dist/contract-CeyIrbN0.d.cts +334 -0
- package/dist/contract-CeyIrbN0.d.ts +334 -0
- package/dist/contract-Cln8gHpa.js +58 -0
- package/dist/contract-Cln8gHpa.js.map +1 -0
- package/dist/contract-DK9eNgkr.cjs +93 -0
- package/dist/contract-DK9eNgkr.cjs.map +1 -0
- package/dist/contract.cjs +8 -0
- package/dist/contract.d.cts +2 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/host-contract-BYueFQCF.d.ts +30 -0
- package/dist/host-contract-DQl-nsDH.d.cts +30 -0
- package/dist/index.cjs +590 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -145
- package/dist/index.d.ts +9 -145
- package/dist/index.js +586 -144
- package/dist/index.js.map +1 -1
- package/dist/standard.cjs +297 -0
- package/dist/standard.cjs.map +1 -0
- package/dist/standard.d.cts +21 -0
- package/dist/standard.d.ts +21 -0
- package/dist/standard.js +296 -0
- package/dist/standard.js.map +1 -0
- package/package.json +23 -6
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["parseShortcut","I18nToken","ShellToken"],"sources":["../src/capability.ts","../src/reducer.ts","../src/types.ts","../src/commands.plugin.ts"],"sourcesContent":["import type { CapabilityToken, PluginContext } from '@embedpdf/core';\nimport { I18nToken } from '@embedpdf/plugin-i18n';\nimport { ShellToken } from '@embedpdf/plugin-shell';\nimport { matchShortcut, parseShortcut } from '@embedpdf/core-ui';\nimport type { KeyStroke, ParsedShortcut } from '@embedpdf/core-ui';\nimport type {\n CommandCtx,\n CommandDef,\n CommandsAction,\n CommandsCapability,\n CommandsState,\n IconAccent,\n ResolvedCommand,\n} from './types';\n\n/** A registered command: the definition plus its pre-parsed shortcuts. */\nexport interface RegisteredCommand {\n readonly def: CommandDef;\n readonly shortcuts: readonly string[];\n readonly parsed: readonly ParsedShortcut[];\n}\n\nexport type CommandRegistry = Map<string, RegisteredCommand>;\n\nexport function registerCommand(registry: CommandRegistry, def: CommandDef): void {\n if (registry.has(def.id)) throw new Error(`[commands] duplicate command: ${def.id}`);\n const shortcuts = def.shortcut === undefined ? [] : ([] as string[]).concat(def.shortcut);\n registry.set(def.id, { def, shortcuts, parsed: shortcuts.map(parseShortcut) });\n}\n\nconst panelTarget = (def: CommandDef): { id: string; exclusive?: string } | null =>\n def.panel === undefined ? null : typeof def.panel === 'string' ? { id: def.panel } : def.panel;\n\nexport function createCommandsCapability(\n ctx: PluginContext<CommandsState, CommandsAction>,\n registry: CommandRegistry,\n): CommandsCapability {\n /** Bind capability resolution to the command's target document. The kernel\n * resolves workspace tokens regardless of the document argument, so one\n * code path serves both scopes. */\n const commandCtx = (documentId?: string): CommandCtx => {\n const target = documentId ?? ctx.core().activeId;\n const get = <T>(token: CapabilityToken<T>): T =>\n target ? ctx.forDocument(token, target) : ctx.get(token);\n return {\n documentId: target,\n core: ctx.core,\n get,\n tryGet: <T>(token: CapabilityToken<T>): T | null => {\n try {\n return get(token);\n } catch {\n return null;\n }\n },\n };\n };\n\n /** Derivations run against live state; a derivation that throws (e.g. it\n * needs a document and none is open) falls back to the safe default —\n * the button renders, disabled, exactly like v2's empty state. */\n const derive = (\n fn: ((c: CommandCtx) => boolean) | undefined,\n c: CommandCtx,\n fallback: boolean,\n ): boolean => {\n if (!fn) return fallback;\n try {\n return fn(c);\n } catch {\n return fallback;\n }\n };\n\n /** Same guard as `derive`, for the icon-accent derivation: a throw (no\n * document, provider missing) means \"no accent\" — the icon renders plain. */\n const deriveAccent = (\n fn: ((c: CommandCtx) => IconAccent | null) | undefined,\n c: CommandCtx,\n ): IconAccent | undefined => {\n if (!fn) return undefined;\n try {\n return fn(c) ?? undefined;\n } catch {\n return undefined;\n }\n };\n\n const resolve = (id: string, documentId?: string): ResolvedCommand | null => {\n const entry = registry.get(id);\n if (!entry) return null;\n const { def } = entry;\n const c = commandCtx(documentId);\n\n const disabled = ctx.getState().disabledCategories;\n const categoryHidden = (def.categories ?? []).some((cat) => disabled.includes(cat));\n\n const i18n = c.tryGet(I18nToken);\n const label = i18n ? i18n.t(def.labelKey) : def.labelKey;\n\n // Surface-target commands derive `active` from the surface's open state\n // unless the definition overrides it.\n let active: boolean;\n if (def.active) {\n active = derive(def.active, c, false);\n } else {\n const shell = c.tryGet(ShellToken);\n const panel = panelTarget(def);\n active = shell\n ? def.menu\n ? shell.isMenuOpen(def.menu)\n : panel\n ? shell.isOpen(panel.id)\n : def.modal\n ? shell.isOpen(def.modal)\n : false\n : false;\n }\n\n return {\n id: def.id,\n label,\n icon: def.icon,\n iconAccent: deriveAccent(def.iconAccent, c),\n shortcuts: entry.shortcuts,\n menu: def.menu,\n enabled: derive(def.enabled, c, true) && !categoryHidden,\n active,\n visible: derive(def.visible, c, true) && !categoryHidden,\n categories: def.categories ?? [],\n };\n };\n\n const execute = (id: string, documentId?: string): void => {\n const entry = registry.get(id);\n if (!entry) return;\n const resolved = resolve(id, documentId);\n if (!resolved || !resolved.enabled || !resolved.visible) return;\n const c = commandCtx(documentId);\n\n if (entry.def.run) {\n entry.def.run(c);\n return;\n }\n // Default routing for declarative surface targets.\n const shell = c.tryGet(ShellToken);\n if (!shell) return;\n const panel = panelTarget(entry.def);\n if (entry.def.menu) shell.toggleMenu(entry.def.menu);\n else if (panel) shell.toggle(panel.id, { exclusive: panel.exclusive });\n else if (entry.def.modal) shell.toggle(entry.def.modal, { exclusive: 'modal' });\n };\n\n return {\n register: (def) => registerCommand(registry, def),\n unregister: (id) => void registry.delete(id),\n has: (id) => registry.has(id),\n ids: () => [...registry.keys()],\n\n resolve,\n search: (query, documentId) => {\n const q = query.trim().toLowerCase();\n const hits: ResolvedCommand[] = [];\n for (const id of registry.keys()) {\n const r = resolve(id, documentId);\n if (!r || !r.visible) continue;\n if (q === '' || r.label.toLowerCase().includes(q) || r.id.includes(q)) hits.push(r);\n }\n return hits;\n },\n menuTarget: (id) => {\n const entry = registry.get(id);\n return entry ? { menu: entry.def.menu } : null;\n },\n\n execute,\n matchStroke: (stroke: KeyStroke, opts) => {\n for (const [id, entry] of registry) {\n if (entry.parsed.some((p) => matchShortcut(p, stroke, opts))) return id;\n }\n return null;\n },\n\n disabledCategories: () => ctx.getState().disabledCategories,\n isCategoryDisabled: (category) => ctx.getState().disabledCategories.includes(category),\n disableCategory: (category) => ctx.dispatch({ type: 'COMMANDS/DISABLE_CATEGORY', category }),\n enableCategory: (category) => ctx.dispatch({ type: 'COMMANDS/ENABLE_CATEGORY', category }),\n setDisabledCategories: (categories) =>\n ctx.dispatch({ type: 'COMMANDS/SET_DISABLED_CATEGORIES', categories }),\n };\n}\n","import type { CommandsAction, CommandsState } from './types';\n\nexport const initialCommandsState: CommandsState = {\n disabledCategories: [],\n};\n\nexport function commandsReducer(state: CommandsState, action: CommandsAction): CommandsState {\n switch (action.type) {\n case 'COMMANDS/DISABLE_CATEGORY':\n return state.disabledCategories.includes(action.category)\n ? state\n : { disabledCategories: [...state.disabledCategories, action.category] };\n case 'COMMANDS/ENABLE_CATEGORY':\n return state.disabledCategories.includes(action.category)\n ? { disabledCategories: state.disabledCategories.filter((c) => c !== action.category) }\n : state;\n case 'COMMANDS/SET_DISABLED_CATEGORIES':\n return { disabledCategories: [...action.categories] };\n default:\n return state;\n }\n}\n","import { createCapabilityToken } from '@embedpdf/core';\nimport type { CapabilityToken, CoreState } from '@embedpdf/core';\nimport type { KeyStroke } from '@embedpdf/core-ui';\n\n/**\n * @embedpdf/plugin-commands — the contract.\n *\n * Commands are the single vocabulary of verbs: toolbars, menus, contextual\n * strips, shortcuts, and the palette are all projections of this registry.\n * The plugin ships ZERO commands (mechanism here, definitions in the product\n * — same split as plugin-i18n's locale packs).\n *\n * Command state is a pure DERIVATION over the store: `resolve()` reads other\n * capabilities' selectors at call time, so any store change is reflected on\n * the next read and the framework binding's one change stream makes every\n * consumer reactive. There is no CommandStateChangedEvent, no diffing, no\n * cache — v2's entire notification apparatus has no v3 equivalent because\n * the reactive store subsumes it.\n *\n * Definitions hold functions, so they live in the plugin's registry (config\n * + `register()`), never in the store; store state is only the serializable\n * `disabledCategories`.\n */\n\n/** What a derivation or `run` sees: capability resolution bound to the\n * command's target document (explicit, else the active one). */\nexport interface CommandCtx {\n /** The target document, or null when no document is open. */\n readonly documentId: string | null;\n core(): CoreState;\n /** Resolve a capability; document-scoped tokens bind to the target document. */\n get<T>(token: CapabilityToken<T>): T;\n /** Like `get`, but null when unavailable (no provider / no document). */\n tryGet<T>(token: CapabilityToken<T>): T | null;\n}\n\n/**\n * Up to two theme colors accompanying a command's icon — typed FACTS any\n * renderer can interpret (tint a glyph's slots, show a swatch), never\n * renderer props. The registry carries it the way it carries `icon`: as\n * data it doesn't interpret. Deliberately NOT v2's `iconProps` bag —\n * renderer-specific needs live app-side, joined by command id.\n */\nexport interface IconAccent {\n /** The mark: stroke / markup / font color. */\n readonly primary?: string;\n /** The fill, when there is one. */\n readonly secondary?: string;\n}\n\nexport interface CommandDef {\n /** Convention: 'domain:verb' — 'zoom:in', 'mode:annotate', 'panel:search'. */\n readonly id: string;\n /** i18n key, resolved through I18nToken when present (else shown verbatim). */\n readonly labelKey: string;\n readonly icon?: string;\n /** Live color accent for the icon (a tool previewing its drawing defaults).\n * A pure derivation over the store, exactly like `active`/`enabled`. */\n readonly iconAccent?: (ctx: CommandCtx) => IconAccent | null;\n /** 'Mod+K' style (ui-core grammar). Multiple bindings allowed. */\n readonly shortcut?: string | readonly string[];\n /** Feature-gating tags: a disabled category hides its commands everywhere. */\n readonly categories?: readonly string[];\n\n // ── declarative surface targets ──────────────────────────────────────────\n // A command that opens chrome DECLARES what it opens instead of doing it\n // imperatively. This is load-bearing: buttons render carets/aria-haspopup,\n // `active` derives automatically from the surface's open state, and the\n // overflow projection renders `menu` targets as nested submenus.\n /** Toggles a named dropdown menu (a MenuSchema id in the app's chrome). */\n readonly menu?: string;\n /** Toggles a named shell surface, optionally exclusive within a tag ('left'…). */\n readonly panel?: string | { readonly id: string; readonly exclusive?: string };\n /** Toggles a modal surface (exclusive within the built-in 'modal' tag). */\n readonly modal?: string;\n\n // ── pure derivations over the store ──────────────────────────────────────\n readonly enabled?: (ctx: CommandCtx) => boolean;\n readonly active?: (ctx: CommandCtx) => boolean;\n readonly visible?: (ctx: CommandCtx) => boolean;\n\n /** The verb. Optional for pure surface-target commands. Runs before the\n * default target routing when both are present. */\n readonly run?: (ctx: CommandCtx) => void;\n}\n\n/** A command as a renderer sees it — everything resolved for the target document. */\nexport interface ResolvedCommand {\n readonly id: string;\n readonly label: string;\n readonly icon?: string;\n readonly iconAccent?: IconAccent;\n readonly shortcuts: readonly string[];\n readonly menu?: string;\n readonly enabled: boolean;\n readonly active: boolean;\n readonly visible: boolean;\n readonly categories: readonly string[];\n}\n\n/** Value equality over resolved commands — `resolve()` mints a fresh object\n * per read, so reactive bindings memo by value to re-render on real change. */\nexport const resolvedCommandsEqual = (\n a: ResolvedCommand | null,\n b: ResolvedCommand | null,\n): boolean => {\n if (a === b) return true;\n if (!a || !b) return false;\n return (\n a.id === b.id &&\n a.label === b.label &&\n a.icon === b.icon &&\n // by value: resolve() mints a fresh accent object each read\n a.iconAccent?.primary === b.iconAccent?.primary &&\n a.iconAccent?.secondary === b.iconAccent?.secondary &&\n a.menu === b.menu &&\n a.enabled === b.enabled &&\n a.active === b.active &&\n a.visible === b.visible &&\n a.shortcuts.length === b.shortcuts.length &&\n a.shortcuts.every((s, i) => s === b.shortcuts[i])\n );\n};\n\nexport interface CommandsState {\n readonly disabledCategories: readonly string[];\n}\n\nexport type CommandsAction =\n | { type: 'COMMANDS/DISABLE_CATEGORY'; category: string }\n | { type: 'COMMANDS/ENABLE_CATEGORY'; category: string }\n | { type: 'COMMANDS/SET_DISABLED_CATEGORIES'; categories: readonly string[] };\n\nexport interface CommandsConfig {\n /** The app's command definitions (content — the plugin ships none). */\n commands?: readonly CommandDef[];\n /** Categories disabled at startup (host feature-gating). */\n disabledCategories?: readonly string[];\n}\n\nexport interface CommandsCapability {\n // ── registry ──\n register(def: CommandDef): void;\n unregister(id: string): void;\n has(id: string): boolean;\n ids(): string[];\n\n // ── resolution (pure reads; reactive through the store) ──\n resolve(id: string, documentId?: string): ResolvedCommand | null;\n /** Palette query: visible commands whose resolved label matches. */\n search(query: string, documentId?: string): ResolvedCommand[];\n /** The one fact the overflow projection needs (ResolveMenuTarget-shaped). */\n menuTarget(id: string): { menu?: string } | null;\n\n // ── execution (the ONLY path; guarded by enabled/visible) ──\n execute(id: string, documentId?: string): void;\n /** Match a keystroke against every registered shortcut → command id or null. */\n matchStroke(stroke: KeyStroke, opts: { isMac: boolean }): string | null;\n\n // ── category gating ──\n disabledCategories(): readonly string[];\n isCategoryDisabled(category: string): boolean;\n disableCategory(category: string): void;\n enableCategory(category: string): void;\n setDisabledCategories(categories: readonly string[]): void;\n}\n\nexport const CommandsToken = createCapabilityToken<CommandsCapability>('commands');\n","import { definePlugin } from '@embedpdf/core';\nimport { createCommandsCapability, registerCommand } from './capability';\nimport type { CommandRegistry } from './capability';\nimport { commandsReducer, initialCommandsState } from './reducer';\nimport { CommandsToken } from './types';\nimport type { CommandsAction, CommandsCapability, CommandsConfig, CommandsState } from './types';\n\n/**\n * The commands plugin: workspace-scoped (one vocabulary for the whole\n * workspace; resolution/execution bind to a target document per call).\n * Definitions live in this closure — never in the store (they hold\n * functions); the store slice holds only `disabledCategories`.\n */\nexport const commandsPlugin = (config?: CommandsConfig) => {\n const registry: CommandRegistry = new Map();\n for (const def of config?.commands ?? []) registerCommand(registry, def);\n\n return definePlugin<CommandsState, CommandsAction, CommandsCapability>({\n id: 'commands',\n scope: 'workspace',\n token: CommandsToken,\n initialState: {\n ...initialCommandsState,\n disabledCategories: [...(config?.disabledCategories ?? [])],\n },\n reduce: commandsReducer,\n capability: (ctx) => createCommandsCapability(ctx, registry),\n });\n};\n"],"mappings":";;;;;;AAwBA,SAAgB,gBAAgB,UAA2B,KAAuB;CAChF,IAAI,SAAS,IAAI,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,iCAAiC,IAAI,IAAI;CACnF,MAAM,YAAY,IAAI,aAAa,KAAA,IAAY,CAAC,IAAK,CAAC,CAAC,CAAc,OAAO,IAAI,QAAQ;CACxF,SAAS,IAAI,IAAI,IAAI;EAAE;EAAK;EAAW,QAAQ,UAAU,IAAIA,kBAAAA,aAAa;CAAE,CAAC;AAC/E;AAEA,MAAM,eAAe,QACnB,IAAI,UAAU,KAAA,IAAY,OAAO,OAAO,IAAI,UAAU,WAAW,EAAE,IAAI,IAAI,MAAM,IAAI,IAAI;AAE3F,SAAgB,yBACd,KACA,UACoB;;;;CAIpB,MAAM,cAAc,eAAoC;EACtD,MAAM,SAAS,cAAc,IAAI,KAAK,CAAC,CAAC;EACxC,MAAM,OAAU,UACd,SAAS,IAAI,YAAY,OAAO,MAAM,IAAI,IAAI,IAAI,KAAK;EACzD,OAAO;GACL,YAAY;GACZ,MAAM,IAAI;GACV;GACA,SAAY,UAAwC;IAClD,IAAI;KACF,OAAO,IAAI,KAAK;IAClB,QAAQ;KACN,OAAO;IACT;GACF;EACF;CACF;;;;CAKA,MAAM,UACJ,IACA,GACA,aACY;EACZ,IAAI,CAAC,IAAI,OAAO;EAChB,IAAI;GACF,OAAO,GAAG,CAAC;EACb,QAAQ;GACN,OAAO;EACT;CACF;;;CAIA,MAAM,gBACJ,IACA,MAC2B;EAC3B,IAAI,CAAC,IAAI,OAAO,KAAA;EAChB,IAAI;GACF,OAAO,GAAG,CAAC,KAAK,KAAA;EAClB,QAAQ;GACN;EACF;CACF;CAEA,MAAM,WAAW,IAAY,eAAgD;EAC3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;;;;;;;AC1JjF,MAAa,kBAAkB,WAA4B;CACzD,MAAM,2BAA4B,IAAI,IAAI;CAC1C,KAAK,MAAM,OAAO,QAAQ,YAAY,CAAC,GAAG,gBAAgB,UAAU,GAAG;CAEvE,QAAA,GAAA,eAAA,aAAA,CAAuE;EACrE,IAAI;EACJ,OAAO;EACP,OAAO;EACP,cAAc;GACZ,GAAG;GACH,oBAAoB,CAAC,GAAI,QAAQ,sBAAsB,CAAC,CAAE;EAC5D;EACA,QAAQ;EACR,aAAa,QAAQ,yBAAyB,KAAK,QAAQ;CAC7D,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["parseShortcut","I18nToken","DocumentsToken","ShellToken","PluginError","CommandsToken","I18nToken","ShellToken","COMMANDS_DEFAULTS"],"sources":["../src/registry.ts","../src/services/availability.ts","../src/write/turning-off.ts","../src/controller.ts","../src/commands.plugin.ts"],"sourcesContent":["/** A command definition with its shortcuts parsed once, and how the registry tells a family apart. */\nimport { parseShortcut, type ParsedShortcut } from '@embedpdf/core-ui';\n\nimport type { CommandDefinition, CommandFamily } from './contract';\n\nexport interface RegisteredCommand {\n readonly definition: CommandDefinition;\n readonly shortcuts: readonly string[];\n readonly parsed: readonly ParsedShortcut[];\n}\n\nexport const registeredCommand = (definition: CommandDefinition): RegisteredCommand => {\n const shortcuts =\n definition.shortcut === undefined ? [] : ([] as string[]).concat(definition.shortcut);\n return { definition, shortcuts, parsed: shortcuts.map(parseShortcut) };\n};\n\nexport const isCommandFamily = (item: CommandDefinition | CommandFamily): item is CommandFamily =>\n 'prefix' in item;\n\n/** The commands the settings define, by id (a later id replaces an earlier one), and their families. */\nexport interface ConfiguredCommands {\n readonly commands: ReadonlyMap<string, RegisteredCommand>;\n readonly families: readonly CommandFamily[];\n}\n\nexport function configuredCommands(\n items: readonly (CommandDefinition | CommandFamily)[],\n): ConfiguredCommands {\n const commands = new Map<string, RegisteredCommand>();\n const families: CommandFamily[] = [];\n for (const item of items) {\n if (isCommandFamily(item)) families.push(item);\n else commands.set(item.id, registeredCommand(item));\n }\n return { commands, families };\n}\n","/**\n * Whether a command is there at all, apart from what it says about the\n * moment (`enabled`, `visible`): turned off in this viewer (its id, or one of\n * its categories), not allowed for its document (the scope's `requires`, or\n * the plugins' checks in `allowed`), or held by a lock on the setting it\n * changes (`locked`), and the sentence that says why, translated when the\n * i18n plugin is there.\n */\nimport type {\n DocumentHandle,\n Permission,\n PluginContext,\n SettingLock,\n Settings,\n} from '@embedpdf/core';\nimport { I18nToken, interpolate, type TranslateOptions } from '@embedpdf/plugin-i18n/contract';\n\nimport type {\n CommandContext,\n CommandDefinition,\n CommandRefusal,\n CommandsSettings,\n} from '../contract';\n\n/**\n * Whether a category is off: it, or a category it's under, is in the list. Parts are whole\n * dotted segments, so `annotations` covers `annotations.highlight` and not `annotationsExtra`.\n */\nexport const isCategoryOff = (category: string, disabled: readonly string[]): boolean =>\n disabled.some((off) => category === off || category.startsWith(`${off}.`));\n\n/** How a command's sentences are translated: the i18n plugin's `t`, or `null` without the plugin. */\nexport type Translate = (key: string, options?: TranslateOptions) => string;\n\n/** The translate function for a command's document: a new one only when its strings may differ. */\nexport const translateOf = (context: CommandContext): Translate | null =>\n context.tryGet(I18nToken)?.getTranslator() ?? null;\n\n/** The values for a label's slots, from `labelParams`; none without it, or when it throws. */\nexport const labelParamsOf = (\n definition: CommandDefinition,\n context: CommandContext,\n): Readonly<Record<string, string | number>> | undefined => {\n if (!definition.labelParams) return undefined;\n try {\n return definition.labelParams(context);\n } catch {\n return undefined;\n }\n};\n\n/**\n * The label: a language's string under the command's id, else under its `labelKey` (the current\n * language, then the fallback one), else `label`, else the id, with `labelParams` in its slots.\n * So a string for `'document:download'` relabels that one command, whichever key its label is\n * under.\n */\nexport const labelOf = (\n definition: CommandDefinition,\n params: Readonly<Record<string, string | number>> | undefined,\n t: Translate | null,\n): string => {\n if (!t) return interpolate(definition.label ?? definition.labelKey ?? definition.id, params);\n const options = {\n ...(definition.labelKey ? { fallbackKey: definition.labelKey } : {}),\n ...(params ? { params } : {}),\n };\n // A command with a key and no label of its own warns once when no language has the key.\n return definition.label === undefined && definition.labelKey\n ? t(definition.id, options)\n : t(definition.id, { ...options, fallback: definition.label ?? definition.id });\n};\n\n/**\n * Whether a document's session holds a permission: what `ctx.allows` answers for a\n * document-scoped plugin, asked here of the command's document, since the commands are one\n * set for the whole workspace.\n */\nconst sessionHolds = (security: DocumentHandle['security'], permission: Permission): boolean =>\n permission === 'annotations:create'\n ? security.allowsAnnotation('create')\n : security.allows(permission);\n\n/** Where a language keeps the sentence for a permission: `commands.notAllowed.doc-text-copy`. */\nconst permissionKeyOf = (permission: Permission): string =>\n `commands.notAllowed.${permission.replace(/[.:]/g, '-')}`;\n\n/** The general sentence's key: `{label} isn't allowed`. */\nconst DEFAULT_NOT_ALLOWED_KEY = 'commands.notAllowed.default';\n\n/** The sentence for a command the session may not run, under `key`, else the general one. */\nexport const notAllowedMessage = (key: string, label: string, t: Translate | null): string => {\n const fallback = `${label} isn't allowed`;\n if (!t) return fallback;\n const params = { label };\n return t(key, { params, fallback: t(DEFAULT_NOT_ALLOWED_KEY, { params, fallback }) });\n};\n\n/** The general locked sentence's key: `{label} can't be changed in this document`. */\nconst DEFAULT_LOCKED_KEY = 'commands.locked.default';\n\n/** The sentence for a command whose setting a lock holds, under `key`, else the general one. */\nexport const lockedMessage = (key: string, label: string, t: Translate | null): string => {\n const fallback = `${label} can't be changed in this document`;\n if (!t) return fallback;\n const params = { label };\n return t(key, { params, fallback: t(DEFAULT_LOCKED_KEY, { params, fallback }) });\n};\n\n/** The sentence for a command that's turned off. */\nconst turnedOffMessage = (label: string, t: Translate | null): string =>\n t\n ? t('commands.turnedOff', { params: { label }, fallback: \"{label} isn't available\" })\n : `${label} isn't available`;\n\nexport function createAvailability(\n ctx: PluginContext<void, CommandsSettings>,\n settings: Settings<CommandsSettings>,\n) {\n /** Whether a command is turned off: by its id, or through one of its categories. */\n const isTurnedOff = (definition: CommandDefinition): boolean => {\n const { disabledCategories, disabledCommands } = settings.get();\n return (\n disabledCommands.includes(definition.id) ||\n (definition.categories ?? []).some((category) => isCategoryOff(category, disabledCategories))\n );\n };\n\n /** Whether a command's `allowed` check says yes; one that throws allows it. */\n const passesCheck = (definition: CommandDefinition, context: CommandContext): boolean => {\n if (!definition.allowed) return true;\n try {\n return definition.allowed(context);\n } catch {\n return true;\n }\n };\n\n /**\n * Why a lock holds the setting a command changes, as the key of the sentence that says so (the\n * lock's `reasonKey`, else `commands.locked.default`), or `null` while nothing holds it; a\n * `locked` that throws is no lock.\n */\n const lockedKeyOf = (definition: CommandDefinition, context: CommandContext): string | null => {\n if (!definition.locked) return null;\n let lock: SettingLock | null;\n try {\n lock = definition.locked(context);\n } catch {\n return null;\n }\n return lock === null ? null : (lock.reasonKey ?? DEFAULT_LOCKED_KEY);\n };\n\n /**\n * Why its document's session may not run a command, as the key of the sentence that says\n * so, or `null` when it may: the first permission `requires` names that the session doesn't\n * hold (`commands.notAllowed.doc-print`), else its `allowed` check saying no (its\n * `notAllowedKey`). With no document open there is no session to ask, and nothing is refused.\n */\n const notAllowedKeyOf = (\n definition: CommandDefinition,\n context: CommandContext,\n ): string | null => {\n if (!definition.requires?.length && !definition.allowed) return null;\n const handle = context.documentId === null ? null : ctx.documentHandle(context.documentId);\n if (!handle) return null;\n const missing = definition.requires?.find(\n (permission) => !sessionHolds(handle.security, permission),\n );\n if (missing !== undefined) return permissionKeyOf(missing);\n return passesCheck(definition, context)\n ? null\n : (definition.notAllowedKey ?? DEFAULT_NOT_ALLOWED_KEY);\n };\n\n /** Why a command won't run whatever the moment, or `null` when it may run. */\n const refusalOf = (\n definition: CommandDefinition,\n context: CommandContext,\n ): CommandRefusal | null => {\n const t = translateOf(context);\n const label = () => labelOf(definition, labelParamsOf(definition, context), t);\n if (isTurnedOff(definition)) {\n return { reason: 'turned-off', message: turnedOffMessage(label(), t) };\n }\n const notAllowed = notAllowedKeyOf(definition, context);\n if (notAllowed !== null) {\n return { reason: 'not-allowed', message: notAllowedMessage(notAllowed, label(), t) };\n }\n const locked = lockedKeyOf(definition, context);\n return locked === null\n ? null\n : { reason: 'locked', message: lockedMessage(locked, label(), t) };\n };\n\n return { isTurnedOff, notAllowedKeyOf, lockedKeyOf, refusalOf };\n}\n","/**\n * Turning commands off and on: by category, with every category under it, and\n * one by one. Both lists are settings, so they change live and\n * `resetSettings()` restores what the app registered.\n */\nimport type { Settings } from '@embedpdf/core';\n\nimport type { CommandDefinition, CommandsCapability, CommandsSettings } from '../contract';\nimport { isCategoryOff } from '../services/availability';\n\ntype OffList = 'disabledCategories' | 'disabledCommands';\n\nexport function createTurningOff(\n settings: Settings<CommandsSettings>,\n definitionOf: (id: string) => CommandDefinition | null,\n isTurnedOff: (definition: CommandDefinition) => boolean,\n) {\n const listOf = (list: OffList): readonly string[] => settings.get()[list];\n const replace = (list: OffList, names: readonly string[]): void =>\n settings.api.updateSettings(\n list === 'disabledCategories'\n ? { disabledCategories: [...names] }\n : { disabledCommands: [...names] },\n );\n // Adding a name that's there, or removing one that isn't, changes nothing and fires nothing.\n const add = (list: OffList, name: string): void => {\n const current = listOf(list);\n if (!current.includes(name)) replace(list, [...current, name]);\n };\n const remove = (list: OffList, name: string): void => {\n const current = listOf(list);\n if (current.includes(name))\n replace(\n list,\n current.filter((other) => other !== name),\n );\n };\n\n return {\n getDisabledCategories: () => listOf('disabledCategories'),\n isCategoryDisabled: (category) => isCategoryOff(category, listOf('disabledCategories')),\n disableCategory: (category) => add('disabledCategories', category),\n enableCategory: (category) => remove('disabledCategories', category),\n setDisabledCategories: (categories) => replace('disabledCategories', categories),\n getDisabledCommands: () => listOf('disabledCommands'),\n isCommandDisabled: (id) => {\n const definition = definitionOf(id);\n return definition ? isTurnedOff(definition) : listOf('disabledCommands').includes(id);\n },\n disableCommand: (id) => add('disabledCommands', id),\n enableCommand: (id) => remove('disabledCommands', id),\n setDisabledCommands: (ids) => replace('disabledCommands', ids),\n } satisfies Partial<CommandsCapability>;\n}\n","/**\n * The commands controller: the commands (from the settings, added while the\n * app runs, and from families), resolution for a document (derivations over\n * live state, safe to throw, asked once per store change), the one way to run\n * a command, turning commands off (by category and one by one), what the\n * session may run (the scope's `requires`, the plugins' checks in `allowed`),\n * and the host-only keystroke matcher.\n *\n * Definitions hold functions, so the commands added while the app runs are a\n * map outside state; every change to it calls `ctx.notify()` so readers read\n * again.\n */\nimport {\n DocumentsToken,\n isPluginError,\n memo,\n memoByKey,\n PluginError,\n toPluginError,\n toPluginErrorInfo,\n type CapabilityToken,\n type PluginContext,\n type Unsubscribe,\n} from '@embedpdf/core';\nimport { matchShortcut, type KeyStroke } from '@embedpdf/core-ui';\nimport { ShellToken } from '@embedpdf/plugin-shell/contract';\n\nimport type {\n CommandContext,\n CommandDefinition,\n CommandExecutedEvent,\n CommandExecutionFailedEvent,\n CommandFamily,\n CommandsSettings,\n ExecuteOptions,\n ExecuteResult,\n IconAccent,\n RegisterCommandOptions,\n ResolvedCommand,\n} from './contract';\nimport type { CommandsHostCapability, ShortcutMatch } from './host-contract';\nimport {\n configuredCommands,\n registeredCommand,\n type ConfiguredCommands,\n type RegisteredCommand,\n} from './registry';\nimport {\n createAvailability,\n labelOf,\n labelParamsOf,\n lockedMessage,\n notAllowedMessage,\n translateOf,\n type Translate,\n} from './services/availability';\nimport { createTurningOff } from './write/turning-off';\n\nconst panelTarget = (\n definition: CommandDefinition,\n): { id: string; exclusive?: string; focus?: boolean } | null =>\n definition.panel === undefined\n ? null\n : typeof definition.panel === 'string'\n ? { id: definition.panel }\n : definition.panel;\n\n/**\n * A toggle: it has an `active` of its own, or opens a panel. A menu's button says it's expanded\n * instead.\n */\nconst pressableOf = (definition: CommandDefinition): boolean =>\n !definition.menu && (definition.active !== undefined || definition.panel !== undefined);\n\n/**\n * What one command's derivations answer for a document, as values a memo can compare: the\n * entry, the translate function and its label's `labelParams` (as JSON, so equal values compare\n * equal), the accent colors, the enabled/active/visible flags, and the keys of the sentences that\n * say why it's disabled: the scope doesn't allow it (when it shows disabled for that), or a lock\n * holds its setting. The label and the sentences are translated from these, only when one of them\n * changes.\n */\ntype Answers = readonly [\n entry: RegisteredCommand | null,\n translate: Translate | null,\n labelParams: string | undefined,\n accentPrimary: string | undefined,\n accentSecondary: string | undefined,\n enabled: boolean,\n active: boolean,\n visible: boolean,\n notAllowedKey: string | null,\n lockedKey: string | null,\n];\n\nconst NOT_REGISTERED: Answers = [\n null,\n null,\n undefined,\n undefined,\n undefined,\n false,\n false,\n false,\n null,\n null,\n];\nconst NO_NAMES: readonly string[] = [];\n\nconst accentOf = (primary?: string, secondary?: string): IconAccent | undefined =>\n primary === undefined && secondary === undefined\n ? undefined\n : {\n ...(primary !== undefined ? { primary } : {}),\n ...(secondary !== undefined ? { secondary } : {}),\n };\n\nexport function createCommandsController(ctx: PluginContext<void, CommandsSettings>) {\n const settings = ctx.settings();\n\n /** Commands added while the app runs, in the order they were added. */\n const registered = new Map<string, RegisteredCommand>();\n /** Bumped on every change to `registered`: the input of the reads built from it. */\n let registeredVersion = 0;\n const registeredChanged = (): void => {\n registeredVersion += 1;\n ctx.notify();\n };\n\n /** The commands the settings define, rebuilt when the setting changes. */\n const configured = memo(\n () => [settings.get().commands],\n (items): ConfiguredCommands => configuredCommands(items),\n );\n\n const executed = ctx.events.source<CommandExecutedEvent>();\n const executionFailed = ctx.events.source<CommandExecutionFailedEvent>();\n\n /** Capabilities for the command's document: the one named, else the active one. */\n const commandContext = (\n documentId?: string,\n call: { args?: unknown; signal?: AbortSignal } = {},\n ): CommandContext => {\n const target = documentId ?? ctx.get(DocumentsToken).getActiveId();\n const get = <T>(token: CapabilityToken<T>): T =>\n target ? ctx.forDocument(token, target) : ctx.get(token);\n return {\n documentId: target,\n appState: settings.get().appState,\n ...(call.args === undefined ? {} : { args: call.args }),\n ...(call.signal ? { signal: call.signal } : {}),\n get,\n tryGet: <T>(token: CapabilityToken<T>): T | null => {\n try {\n return get(token);\n } catch {\n return null;\n }\n },\n };\n };\n\n /**\n * The context a document's derivations read (`''` is the active document): the same object\n * until the store changes. It keeps the capabilities it finds, which stay the same objects\n * until then.\n */\n const contextByDocument = memoByKey(\n (_documentKey: string) => [ctx.storeChangeCount()],\n (documentKey): CommandContext => {\n const context = commandContext(documentKey || undefined);\n const found = new Map<CapabilityToken<unknown>, unknown>();\n const tryGet = <T>(token: CapabilityToken<T>): T | null => {\n if (!found.has(token)) found.set(token, context.tryGet(token));\n return found.get(token) as T | null;\n };\n return { ...context, tryGet, get: (token) => tryGet(token) ?? context.get(token) };\n },\n );\n\n /** A family's command for one name, made once so it keeps its identity. */\n const familyCommands = new WeakMap<CommandFamily, Map<string, RegisteredCommand>>();\n const familyCommand = (family: CommandFamily, name: string): RegisteredCommand => {\n let byName = familyCommands.get(family);\n if (!byName) {\n byName = new Map();\n familyCommands.set(family, byName);\n }\n let entry = byName.get(name);\n if (!entry) {\n entry = registeredCommand({ ...family.command(name), id: `${family.prefix}${name}` });\n byName.set(name, entry);\n }\n return entry;\n };\n\n /** The command with this id: one added while the app runs, else the settings', else a family's. */\n const entryOf = (id: string): RegisteredCommand | null => {\n const { commands, families } = configured();\n const entry = registered.get(id) ?? commands.get(id);\n if (entry) return entry;\n const family = families.find(\n (candidate) => id.startsWith(candidate.prefix) && id.length > candidate.prefix.length,\n );\n return family ? familyCommand(family, id.slice(family.prefix.length)) : null;\n };\n\n /** Every command with its own definition (not a family's), each id once. */\n const definedCommands = memo(\n () => [registeredVersion, configured()],\n (_version, { commands }) => {\n const entries = new Map(commands);\n for (const [id, entry] of registered) entries.set(id, entry);\n return [...entries.values()];\n },\n );\n\n // Derivations run against live state: without one, the command is what\n // `absent` says; one that throws (it needs a document and none is open, say)\n // says no, so the button renders disabled, not pressed or hidden instead of\n // breaking.\n const derive = (\n derivation: ((context: CommandContext) => boolean) | undefined,\n context: CommandContext,\n absent: boolean,\n ): boolean => {\n if (!derivation) return absent;\n try {\n return derivation(context);\n } catch {\n return false;\n }\n };\n const deriveAccent = (\n derivation: ((context: CommandContext) => IconAccent | null) | undefined,\n context: CommandContext,\n ): IconAccent | undefined => {\n if (!derivation) return undefined;\n try {\n return derivation(context) ?? undefined;\n } catch {\n return undefined;\n }\n };\n const namesOf = (family: CommandFamily, context: CommandContext): readonly string[] => {\n try {\n return family.names(context);\n } catch {\n return NO_NAMES;\n }\n };\n\n const { isTurnedOff, notAllowedKeyOf, lockedKeyOf, refusalOf } = createAvailability(\n ctx,\n settings,\n );\n\n /** Whether a command shows as pressed: its `active`, else while what it opens is open. */\n const activeOf = (definition: CommandDefinition, context: CommandContext): boolean => {\n if (definition.active) return derive(definition.active, context, false);\n const shell = context.tryGet(ShellToken);\n if (!shell) return false;\n const panel = panelTarget(definition);\n return definition.menu\n ? shell.isMenuOpen(definition.menu)\n : panel\n ? shell.isOpen(panel.id)\n : definition.modal\n ? shell.isOpen(definition.modal)\n : false;\n };\n\n /**\n * Whether a command can run and whether it shows, as its derivations answer now, with the keys\n * of the sentences that say why it's disabled. Turned off hides it; not allowed hides it, or\n * disables it with the reason; a lock on the setting it changes disables it with the lock's\n * reason, whatever `notAllowed` says.\n */\n const availabilityOf = (definition: CommandDefinition, context: CommandContext) => {\n const turnedOff = isTurnedOff(definition);\n const notAllowed = turnedOff ? null : notAllowedKeyOf(definition, context);\n const shownWhenNotAllowed = settings.get().notAllowed === 'disable';\n const lockedKey = turnedOff || notAllowed !== null ? null : lockedKeyOf(definition, context);\n const ruledOut = turnedOff || notAllowed !== null || lockedKey !== null;\n return {\n enabled: !ruledOut && derive(definition.enabled, context, true),\n visible:\n !turnedOff &&\n (notAllowed === null || shownWhenNotAllowed) &&\n derive(definition.visible, context, true),\n notAllowedKey: shownWhenNotAllowed ? notAllowed : null,\n lockedKey,\n };\n };\n\n /** What a command's derivations answer for a document now. */\n const answersOf = (entry: RegisteredCommand, context: CommandContext): Answers => {\n const { definition } = entry;\n const { enabled, visible, notAllowedKey, lockedKey } = availabilityOf(definition, context);\n const labelParams = labelParamsOf(definition, context);\n const accent = deriveAccent(definition.iconAccent, context);\n return [\n entry,\n translateOf(context),\n labelParams === undefined ? undefined : JSON.stringify(labelParams),\n accent?.primary,\n accent?.secondary,\n enabled,\n activeOf(definition, context),\n visible,\n notAllowedKey,\n lockedKey,\n ];\n };\n\n /**\n * One document's commands as buttons show them, by id (`''` is the active document). A\n * command's derivations are asked at most once per store change, however many readers ask for\n * it; its resolved object is built again, label and sentences translated, only when one of their\n * answers changed.\n */\n const documentResolution = (documentKey: string) => {\n const answersById = memoByKey(\n (_id: string) => [ctx.storeChangeCount()],\n (id): Answers => {\n const entry = entryOf(id);\n return entry ? answersOf(entry, contextByDocument(documentKey)) : NOT_REGISTERED;\n },\n );\n return memoByKey(\n (id: string): Answers => answersById(id),\n (\n _id,\n entry,\n translate,\n labelParams,\n accentPrimary,\n accentSecondary,\n enabled,\n active,\n visible,\n notAllowedKey,\n lockedKey,\n ): ResolvedCommand | null => {\n if (!entry) return null;\n const params = labelParams === undefined ? undefined : JSON.parse(labelParams);\n const label = labelOf(entry.definition, params, translate);\n const disabledReason =\n notAllowedKey !== null\n ? notAllowedMessage(notAllowedKey, label, translate)\n : lockedKey !== null\n ? lockedMessage(lockedKey, label, translate)\n : undefined;\n return {\n id: entry.definition.id,\n label,\n icon: entry.definition.icon,\n iconAccent: accentOf(accentPrimary, accentSecondary),\n shortcuts: entry.shortcuts,\n menu: entry.definition.menu,\n enabled,\n active,\n pressable: pressableOf(entry.definition),\n visible,\n categories: entry.definition.categories ?? [],\n ...(disabledReason === undefined ? {} : { disabledReason }),\n };\n },\n );\n };\n /** Each document's resolution, made the first time the document is asked about. */\n const resolutionByDocument = memoByKey((_documentKey: string) => [], documentResolution);\n const resolveCommand = (id: string, documentId?: string): ResolvedCommand | null =>\n resolutionByDocument(documentId ?? '')(id);\n\n /**\n * Every command's id for a document (`''` is the active one): the defined ones in the order\n * they were added, then each family's names that no defined command took.\n */\n const idsByDocument = memoByKey(\n (documentKey: string): readonly unknown[] => {\n const config = configured();\n const context = contextByDocument(documentKey);\n return [\n definedCommands(),\n config,\n ...config.families.map((family) => namesOf(family, context)),\n ];\n },\n (_documentKey, ...inputs): readonly string[] => {\n const [defined, { families }, ...names] = inputs as [\n readonly RegisteredCommand[],\n ConfiguredCommands,\n ...(readonly string[])[],\n ];\n const ids = defined.map((entry) => entry.definition.id);\n const taken = new Set(ids);\n families.forEach((family, index) => {\n for (const name of names[index] ?? NO_NAMES) {\n const id = `${family.prefix}${name}`;\n if (taken.has(id)) continue;\n taken.add(id);\n ids.push(id);\n }\n });\n return ids;\n },\n );\n const commandsByDocument = memoByKey(\n (documentKey: string) =>\n idsByDocument(documentKey).map((id) => resolveCommand(id, documentKey || undefined)),\n (_documentKey, ...resolved) =>\n resolved.filter((command): command is ResolvedCommand => command !== null),\n );\n const listCommands = (documentId?: string): readonly ResolvedCommand[] =>\n commandsByDocument(documentId ?? '');\n\n const listShortcuts = memo(\n () => [definedCommands()],\n (entries) =>\n entries.flatMap((entry) =>\n entry.shortcuts.map((shortcut) => ({ commandId: entry.definition.id, shortcut })),\n ),\n );\n\n /** What running a command does: its `run`, or opening what it opens. */\n const runCommand = async (\n definition: CommandDefinition,\n context: CommandContext,\n ): Promise<void> => {\n if (definition.run) {\n await definition.run(context);\n return;\n }\n const shell = context.tryGet(ShellToken);\n const panel = panelTarget(definition);\n if (!shell) return;\n if (definition.menu) shell.toggleMenu(definition.menu);\n else if (panel) shell.toggle(panel.id, { exclusive: panel.exclusive, focus: panel.focus });\n else if (definition.modal) shell.toggle(definition.modal, { exclusive: 'modal' });\n };\n\n const execute = async (id: string, options: ExecuteOptions = {}): Promise<ExecuteResult> => {\n const { signal, documentId, args } = options;\n if (signal?.aborted) {\n throw new PluginError('operation-cancelled', 'commands', 'operation cancelled');\n }\n const entry = entryOf(id);\n if (!entry) return { status: 'rejected', reason: 'not-found' };\n // Asked at this moment, not as of the last store change: a run goes by what the command\n // answers now, also when something outside the viewer changed it since.\n const now = availabilityOf(entry.definition, contextByDocument(documentId ?? ''));\n if (!now.visible) return { status: 'rejected', reason: 'hidden' };\n if (!now.enabled) return { status: 'rejected', reason: 'disabled' };\n const context = commandContext(documentId, { args, signal });\n try {\n await ctx.cancellable(signal, runCommand(entry.definition, context));\n } catch (error) {\n // The caller cancelling isn't the command failing.\n if (signal?.aborted && isPluginError(error, 'operation-cancelled')) throw error;\n const failure = toPluginError('commands', error);\n executionFailed.emit({\n commandId: id,\n documentId: context.documentId,\n error: toPluginErrorInfo(failure),\n });\n throw failure;\n } finally {\n // A run may change what the commands read outside the viewer (your app's state): every\n // button asks its command again, so the one just pressed shows what it did.\n ctx.notify();\n }\n executed.emit({ commandId: id, documentId: context.documentId, args });\n return { status: 'executed' };\n };\n\n const registerOne = (\n definition: CommandDefinition,\n options?: RegisterCommandOptions,\n ): Unsubscribe => {\n const taken = registered.has(definition.id) || configured().commands.has(definition.id);\n if (taken && !options?.replace) {\n throw new PluginError('conflict', 'commands', `duplicate command '${definition.id}'`);\n }\n const entry = registeredCommand(definition);\n registered.set(definition.id, entry);\n registeredChanged();\n return () => {\n // Own this registration only: a later replacement is not ours to remove.\n if (registered.get(definition.id) !== entry) return;\n registered.delete(definition.id);\n registeredChanged();\n };\n };\n\n const turningOff = createTurningOff(\n settings,\n (id) => entryOf(id)?.definition ?? null,\n isTurnedOff,\n );\n\n const api: CommandsHostCapability = {\n ...settings.api,\n registerCommand: registerOne,\n registerCommands: (definitions, options) => {\n const removers = definitions.map((definition) => registerOne(definition, options));\n return () => removers.forEach((remove) => remove());\n },\n hasCommand: (id) => entryOf(id) !== null,\n getCommand: (id) => entryOf(id)?.definition ?? null,\n listCommandIds: () => idsByDocument(''),\n resolveCommand,\n listCommands,\n searchCommands: (query, documentId) => {\n const needle = query.trim().toLowerCase();\n return listCommands(documentId).filter(\n (command) =>\n command.visible &&\n (needle === '' ||\n command.label.toLowerCase().includes(needle) ||\n command.id.includes(needle)),\n );\n },\n listShortcuts,\n execute,\n canExecute: (id, documentId) => {\n const entry = entryOf(id);\n if (!entry) return false;\n const now = availabilityOf(entry.definition, contextByDocument(documentId ?? ''));\n return now.enabled && now.visible;\n },\n getRefusal: (id, documentId) => {\n const entry = entryOf(id);\n return entry ? refusalOf(entry.definition, contextByDocument(documentId ?? '')) : null;\n },\n ...turningOff,\n onExecuted: executed.on,\n onExecutionFailed: executionFailed.on,\n // ── host lens ──\n matchStroke: (stroke: KeyStroke, options) => {\n let waiting: ShortcutMatch | null = null;\n let refused: ShortcutMatch | null = null;\n for (const entry of definedCommands()) {\n if (options.inTextField && !entry.definition.shortcutInTextFields) continue;\n if (!entry.parsed.some((shortcut) => matchShortcut(shortcut, stroke, options))) continue;\n const context = contextByDocument('');\n const refusal = refusalOf(entry.definition, context);\n const visible = derive(entry.definition.visible, context, true);\n if (!refusal) {\n // Commands that share keys take turns: Escape cancels a drawing while there is one,\n // and lets a snapshot go while there is one.\n if (visible && derive(entry.definition.enabled, context, true)) {\n return { commandId: entry.definition.id, refusal: null };\n }\n waiting ??= { commandId: entry.definition.id, refusal: null };\n continue;\n }\n // A refused command takes its keys only where it would show: Delete with nothing\n // selected stays the page's, even where deleting is turned off.\n if (!visible) continue;\n refused ??= { commandId: entry.definition.id, refusal };\n }\n return waiting ?? refused;\n },\n getMenuTarget: (id) => {\n const entry = entryOf(id);\n return entry ? { menu: entry.definition.menu } : null;\n },\n };\n\n return { api };\n}\n","import { definePlugin } from '@embedpdf/core';\nimport { I18nToken } from '@embedpdf/plugin-i18n/contract';\nimport { ShellToken } from '@embedpdf/plugin-shell/contract';\n\nimport { COMMANDS_DEFAULTS, type CommandsConfig } from './contract';\nimport { createCommandsController } from './controller';\nimport { CommandsToken } from './host-contract';\n\n/**\n * The commands: one set for the whole workspace, each resolved and run for a\n * document (the one named, else the document in scope, else the active one).\n * Definitions are settings and app content, never state, since they hold\n * functions. `config` is the settings the app registers, over\n * {@link COMMANDS_DEFAULTS}.\n */\nexport const commandsPlugin = <AppState = any>(config?: CommandsConfig<AppState>) =>\n definePlugin({\n id: 'commands',\n scope: 'workspace',\n token: CommandsToken,\n // Labels come from i18n, and commands that open a panel, menu or dialog\n // go through shell; without them a label is the command's own, and those\n // commands open nothing.\n optional: [I18nToken, ShellToken],\n // Command definitions come from the app and may use any capability.\n resolvesAnyCapability: true,\n // Your app's state is replaced whole, never merged: a new value is the whole new state.\n settings: {\n defaults: COMMANDS_DEFAULTS,\n registered: config as CommandsConfig | undefined,\n whole: ['appState'],\n },\n create: createCommandsController,\n // Inside a document's scope, a call that leaves out the document is for that one.\n inScope: (commands, documentId) => ({\n ...commands,\n resolveCommand: (id, target = documentId) => commands.resolveCommand(id, target),\n listCommands: (target = documentId) => commands.listCommands(target),\n searchCommands: (query, target = documentId) => commands.searchCommands(query, target),\n execute: (id, options) =>\n commands.execute(id, { ...options, documentId: options?.documentId ?? documentId }),\n canExecute: (id, target = documentId) => commands.canExecute(id, target),\n getRefusal: (id, target = documentId) => commands.getRefusal(id, target),\n }),\n });\n"],"mappings":";;;;;;;;;AAWA,MAAa,qBAAqB,eAAqD;CACrF,MAAM,YACJ,WAAW,aAAa,KAAA,IAAY,CAAC,IAAK,CAAC,CAAC,CAAc,OAAO,WAAW,QAAQ;CACtF,OAAO;EAAE;EAAY;EAAW,QAAQ,UAAU,IAAIA,kBAAAA,aAAa;CAAE;AACvE;AAEA,MAAa,mBAAmB,SAC9B,YAAY;AAQd,SAAgB,mBACd,OACoB;CACpB,MAAM,2BAAW,IAAI,IAA+B;CACpD,MAAM,WAA4B,CAAC;CACnC,KAAK,MAAM,QAAQ,OACjB,IAAI,gBAAgB,IAAI,GAAG,SAAS,KAAK,IAAI;MACxC,SAAS,IAAI,KAAK,IAAI,kBAAkB,IAAI,CAAC;CAEpD,OAAO;EAAE;EAAU;CAAS;AAC9B;;;;;;;ACRA,MAAa,iBAAiB,UAAkB,aAC9C,SAAS,MAAM,QAAQ,aAAa,OAAO,SAAS,WAAW,GAAG,IAAI,EAAE,CAAC;;AAM3E,MAAa,eAAe,YAC1B,QAAQ,OAAOC,+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1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* @embedpdf/plugin-commands — the contract.
|
|
6
|
-
*
|
|
7
|
-
* Commands are the single vocabulary of verbs: toolbars, menus, contextual
|
|
8
|
-
* strips, shortcuts, and the palette are all projections of this registry.
|
|
9
|
-
* The plugin ships ZERO commands (mechanism here, definitions in the product
|
|
10
|
-
* — same split as plugin-i18n's locale packs).
|
|
11
|
-
*
|
|
12
|
-
* Command state is a pure DERIVATION over the store: `resolve()` reads other
|
|
13
|
-
* capabilities' selectors at call time, so any store change is reflected on
|
|
14
|
-
* the next read and the framework binding's one change stream makes every
|
|
15
|
-
* consumer reactive. There is no CommandStateChangedEvent, no diffing, no
|
|
16
|
-
* cache — v2's entire notification apparatus has no v3 equivalent because
|
|
17
|
-
* the reactive store subsumes it.
|
|
18
|
-
*
|
|
19
|
-
* Definitions hold functions, so they live in the plugin's registry (config
|
|
20
|
-
* + `register()`), never in the store; store state is only the serializable
|
|
21
|
-
* `disabledCategories`.
|
|
22
|
-
*/
|
|
23
|
-
/** What a derivation or `run` sees: capability resolution bound to the
|
|
24
|
-
* command's target document (explicit, else the active one). */
|
|
25
|
-
interface CommandCtx {
|
|
26
|
-
/** The target document, or null when no document is open. */
|
|
27
|
-
readonly documentId: string | null;
|
|
28
|
-
core(): CoreState;
|
|
29
|
-
/** Resolve a capability; document-scoped tokens bind to the target document. */
|
|
30
|
-
get<T>(token: CapabilityToken<T>): T;
|
|
31
|
-
/** Like `get`, but null when unavailable (no provider / no document). */
|
|
32
|
-
tryGet<T>(token: CapabilityToken<T>): T | null;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Up to two theme colors accompanying a command's icon — typed FACTS any
|
|
36
|
-
* renderer can interpret (tint a glyph's slots, show a swatch), never
|
|
37
|
-
* renderer props. The registry carries it the way it carries `icon`: as
|
|
38
|
-
* data it doesn't interpret. Deliberately NOT v2's `iconProps` bag —
|
|
39
|
-
* renderer-specific needs live app-side, joined by command id.
|
|
40
|
-
*/
|
|
41
|
-
interface IconAccent {
|
|
42
|
-
/** The mark: stroke / markup / font color. */
|
|
43
|
-
readonly primary?: string;
|
|
44
|
-
/** The fill, when there is one. */
|
|
45
|
-
readonly secondary?: string;
|
|
46
|
-
}
|
|
47
|
-
interface CommandDef {
|
|
48
|
-
/** Convention: 'domain:verb' — 'zoom:in', 'mode:annotate', 'panel:search'. */
|
|
49
|
-
readonly id: string;
|
|
50
|
-
/** i18n key, resolved through I18nToken when present (else shown verbatim). */
|
|
51
|
-
readonly labelKey: string;
|
|
52
|
-
readonly icon?: string;
|
|
53
|
-
/** Live color accent for the icon (a tool previewing its drawing defaults).
|
|
54
|
-
* A pure derivation over the store, exactly like `active`/`enabled`. */
|
|
55
|
-
readonly iconAccent?: (ctx: CommandCtx) => IconAccent | null;
|
|
56
|
-
/** 'Mod+K' style (ui-core grammar). Multiple bindings allowed. */
|
|
57
|
-
readonly shortcut?: string | readonly string[];
|
|
58
|
-
/** Feature-gating tags: a disabled category hides its commands everywhere. */
|
|
59
|
-
readonly categories?: readonly string[];
|
|
60
|
-
/** Toggles a named dropdown menu (a MenuSchema id in the app's chrome). */
|
|
61
|
-
readonly menu?: string;
|
|
62
|
-
/** Toggles a named shell surface, optionally exclusive within a tag ('left'…). */
|
|
63
|
-
readonly panel?: string | {
|
|
64
|
-
readonly id: string;
|
|
65
|
-
readonly exclusive?: string;
|
|
66
|
-
};
|
|
67
|
-
/** Toggles a modal surface (exclusive within the built-in 'modal' tag). */
|
|
68
|
-
readonly modal?: string;
|
|
69
|
-
readonly enabled?: (ctx: CommandCtx) => boolean;
|
|
70
|
-
readonly active?: (ctx: CommandCtx) => boolean;
|
|
71
|
-
readonly visible?: (ctx: CommandCtx) => boolean;
|
|
72
|
-
/** The verb. Optional for pure surface-target commands. Runs before the
|
|
73
|
-
* default target routing when both are present. */
|
|
74
|
-
readonly run?: (ctx: CommandCtx) => void;
|
|
75
|
-
}
|
|
76
|
-
/** A command as a renderer sees it — everything resolved for the target document. */
|
|
77
|
-
interface ResolvedCommand {
|
|
78
|
-
readonly id: string;
|
|
79
|
-
readonly label: string;
|
|
80
|
-
readonly icon?: string;
|
|
81
|
-
readonly iconAccent?: IconAccent;
|
|
82
|
-
readonly shortcuts: readonly string[];
|
|
83
|
-
readonly menu?: string;
|
|
84
|
-
readonly enabled: boolean;
|
|
85
|
-
readonly active: boolean;
|
|
86
|
-
readonly visible: boolean;
|
|
87
|
-
readonly categories: readonly string[];
|
|
88
|
-
}
|
|
89
|
-
/** Value equality over resolved commands — `resolve()` mints a fresh object
|
|
90
|
-
* per read, so reactive bindings memo by value to re-render on real change. */
|
|
91
|
-
declare const resolvedCommandsEqual: (a: ResolvedCommand | null, b: ResolvedCommand | null) => boolean;
|
|
92
|
-
interface CommandsState {
|
|
93
|
-
readonly disabledCategories: readonly string[];
|
|
94
|
-
}
|
|
95
|
-
type CommandsAction = {
|
|
96
|
-
type: 'COMMANDS/DISABLE_CATEGORY';
|
|
97
|
-
category: string;
|
|
98
|
-
} | {
|
|
99
|
-
type: 'COMMANDS/ENABLE_CATEGORY';
|
|
100
|
-
category: string;
|
|
101
|
-
} | {
|
|
102
|
-
type: 'COMMANDS/SET_DISABLED_CATEGORIES';
|
|
103
|
-
categories: readonly string[];
|
|
104
|
-
};
|
|
105
|
-
interface CommandsConfig {
|
|
106
|
-
/** The app's command definitions (content — the plugin ships none). */
|
|
107
|
-
commands?: readonly CommandDef[];
|
|
108
|
-
/** Categories disabled at startup (host feature-gating). */
|
|
109
|
-
disabledCategories?: readonly string[];
|
|
110
|
-
}
|
|
111
|
-
interface CommandsCapability {
|
|
112
|
-
register(def: CommandDef): void;
|
|
113
|
-
unregister(id: string): void;
|
|
114
|
-
has(id: string): boolean;
|
|
115
|
-
ids(): string[];
|
|
116
|
-
resolve(id: string, documentId?: string): ResolvedCommand | null;
|
|
117
|
-
/** Palette query: visible commands whose resolved label matches. */
|
|
118
|
-
search(query: string, documentId?: string): ResolvedCommand[];
|
|
119
|
-
/** The one fact the overflow projection needs (ResolveMenuTarget-shaped). */
|
|
120
|
-
menuTarget(id: string): {
|
|
121
|
-
menu?: string;
|
|
122
|
-
} | null;
|
|
123
|
-
execute(id: string, documentId?: string): void;
|
|
124
|
-
/** Match a keystroke against every registered shortcut → command id or null. */
|
|
125
|
-
matchStroke(stroke: KeyStroke, opts: {
|
|
126
|
-
isMac: boolean;
|
|
127
|
-
}): string | null;
|
|
128
|
-
disabledCategories(): readonly string[];
|
|
129
|
-
isCategoryDisabled(category: string): boolean;
|
|
130
|
-
disableCategory(category: string): void;
|
|
131
|
-
enableCategory(category: string): void;
|
|
132
|
-
setDisabledCategories(categories: readonly string[]): void;
|
|
133
|
-
}
|
|
134
|
-
declare const CommandsToken: CapabilityToken<CommandsCapability>;
|
|
135
|
-
//#endregion
|
|
1
|
+
import { C as CommandsToken, S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDefinition, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "./contract-CeyIrbN0.cjs";
|
|
2
|
+
import { t as CommandsHostCapability } from "./host-contract-DQl-nsDH.cjs";
|
|
136
3
|
//#region src/commands.plugin.d.ts
|
|
137
4
|
/**
|
|
138
|
-
* The commands
|
|
139
|
-
*
|
|
140
|
-
* Definitions
|
|
141
|
-
* functions
|
|
5
|
+
* The commands: one set for the whole workspace, each resolved and run for a
|
|
6
|
+
* document (the one named, else the document in scope, else the active one).
|
|
7
|
+
* Definitions are settings and app content, never state, since they hold
|
|
8
|
+
* functions. `config` is the settings the app registers, over
|
|
9
|
+
* {@link COMMANDS_DEFAULTS}.
|
|
142
10
|
*/
|
|
143
|
-
declare const commandsPlugin: (config?: CommandsConfig) => import("@embedpdf/core").
|
|
144
|
-
//#endregion
|
|
145
|
-
//#region src/reducer.d.ts
|
|
146
|
-
declare const initialCommandsState: CommandsState;
|
|
147
|
-
declare function commandsReducer(state: CommandsState, action: CommandsAction): CommandsState;
|
|
11
|
+
declare const commandsPlugin: <AppState = any>(config?: CommandsConfig<AppState>) => import("@embedpdf/core").PluginDefinition<void, CommandsHostCapability, CommandsSettings>;
|
|
148
12
|
//#endregion
|
|
149
|
-
export {
|
|
13
|
+
export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDefinition, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, commandsPlugin, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
|
|
150
14
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,150 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* @embedpdf/plugin-commands — the contract.
|
|
6
|
-
*
|
|
7
|
-
* Commands are the single vocabulary of verbs: toolbars, menus, contextual
|
|
8
|
-
* strips, shortcuts, and the palette are all projections of this registry.
|
|
9
|
-
* The plugin ships ZERO commands (mechanism here, definitions in the product
|
|
10
|
-
* — same split as plugin-i18n's locale packs).
|
|
11
|
-
*
|
|
12
|
-
* Command state is a pure DERIVATION over the store: `resolve()` reads other
|
|
13
|
-
* capabilities' selectors at call time, so any store change is reflected on
|
|
14
|
-
* the next read and the framework binding's one change stream makes every
|
|
15
|
-
* consumer reactive. There is no CommandStateChangedEvent, no diffing, no
|
|
16
|
-
* cache — v2's entire notification apparatus has no v3 equivalent because
|
|
17
|
-
* the reactive store subsumes it.
|
|
18
|
-
*
|
|
19
|
-
* Definitions hold functions, so they live in the plugin's registry (config
|
|
20
|
-
* + `register()`), never in the store; store state is only the serializable
|
|
21
|
-
* `disabledCategories`.
|
|
22
|
-
*/
|
|
23
|
-
/** What a derivation or `run` sees: capability resolution bound to the
|
|
24
|
-
* command's target document (explicit, else the active one). */
|
|
25
|
-
interface CommandCtx {
|
|
26
|
-
/** The target document, or null when no document is open. */
|
|
27
|
-
readonly documentId: string | null;
|
|
28
|
-
core(): CoreState;
|
|
29
|
-
/** Resolve a capability; document-scoped tokens bind to the target document. */
|
|
30
|
-
get<T>(token: CapabilityToken<T>): T;
|
|
31
|
-
/** Like `get`, but null when unavailable (no provider / no document). */
|
|
32
|
-
tryGet<T>(token: CapabilityToken<T>): T | null;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Up to two theme colors accompanying a command's icon — typed FACTS any
|
|
36
|
-
* renderer can interpret (tint a glyph's slots, show a swatch), never
|
|
37
|
-
* renderer props. The registry carries it the way it carries `icon`: as
|
|
38
|
-
* data it doesn't interpret. Deliberately NOT v2's `iconProps` bag —
|
|
39
|
-
* renderer-specific needs live app-side, joined by command id.
|
|
40
|
-
*/
|
|
41
|
-
interface IconAccent {
|
|
42
|
-
/** The mark: stroke / markup / font color. */
|
|
43
|
-
readonly primary?: string;
|
|
44
|
-
/** The fill, when there is one. */
|
|
45
|
-
readonly secondary?: string;
|
|
46
|
-
}
|
|
47
|
-
interface CommandDef {
|
|
48
|
-
/** Convention: 'domain:verb' — 'zoom:in', 'mode:annotate', 'panel:search'. */
|
|
49
|
-
readonly id: string;
|
|
50
|
-
/** i18n key, resolved through I18nToken when present (else shown verbatim). */
|
|
51
|
-
readonly labelKey: string;
|
|
52
|
-
readonly icon?: string;
|
|
53
|
-
/** Live color accent for the icon (a tool previewing its drawing defaults).
|
|
54
|
-
* A pure derivation over the store, exactly like `active`/`enabled`. */
|
|
55
|
-
readonly iconAccent?: (ctx: CommandCtx) => IconAccent | null;
|
|
56
|
-
/** 'Mod+K' style (ui-core grammar). Multiple bindings allowed. */
|
|
57
|
-
readonly shortcut?: string | readonly string[];
|
|
58
|
-
/** Feature-gating tags: a disabled category hides its commands everywhere. */
|
|
59
|
-
readonly categories?: readonly string[];
|
|
60
|
-
/** Toggles a named dropdown menu (a MenuSchema id in the app's chrome). */
|
|
61
|
-
readonly menu?: string;
|
|
62
|
-
/** Toggles a named shell surface, optionally exclusive within a tag ('left'…). */
|
|
63
|
-
readonly panel?: string | {
|
|
64
|
-
readonly id: string;
|
|
65
|
-
readonly exclusive?: string;
|
|
66
|
-
};
|
|
67
|
-
/** Toggles a modal surface (exclusive within the built-in 'modal' tag). */
|
|
68
|
-
readonly modal?: string;
|
|
69
|
-
readonly enabled?: (ctx: CommandCtx) => boolean;
|
|
70
|
-
readonly active?: (ctx: CommandCtx) => boolean;
|
|
71
|
-
readonly visible?: (ctx: CommandCtx) => boolean;
|
|
72
|
-
/** The verb. Optional for pure surface-target commands. Runs before the
|
|
73
|
-
* default target routing when both are present. */
|
|
74
|
-
readonly run?: (ctx: CommandCtx) => void;
|
|
75
|
-
}
|
|
76
|
-
/** A command as a renderer sees it — everything resolved for the target document. */
|
|
77
|
-
interface ResolvedCommand {
|
|
78
|
-
readonly id: string;
|
|
79
|
-
readonly label: string;
|
|
80
|
-
readonly icon?: string;
|
|
81
|
-
readonly iconAccent?: IconAccent;
|
|
82
|
-
readonly shortcuts: readonly string[];
|
|
83
|
-
readonly menu?: string;
|
|
84
|
-
readonly enabled: boolean;
|
|
85
|
-
readonly active: boolean;
|
|
86
|
-
readonly visible: boolean;
|
|
87
|
-
readonly categories: readonly string[];
|
|
88
|
-
}
|
|
89
|
-
/** Value equality over resolved commands — `resolve()` mints a fresh object
|
|
90
|
-
* per read, so reactive bindings memo by value to re-render on real change. */
|
|
91
|
-
declare const resolvedCommandsEqual: (a: ResolvedCommand | null, b: ResolvedCommand | null) => boolean;
|
|
92
|
-
interface CommandsState {
|
|
93
|
-
readonly disabledCategories: readonly string[];
|
|
94
|
-
}
|
|
95
|
-
type CommandsAction = {
|
|
96
|
-
type: 'COMMANDS/DISABLE_CATEGORY';
|
|
97
|
-
category: string;
|
|
98
|
-
} | {
|
|
99
|
-
type: 'COMMANDS/ENABLE_CATEGORY';
|
|
100
|
-
category: string;
|
|
101
|
-
} | {
|
|
102
|
-
type: 'COMMANDS/SET_DISABLED_CATEGORIES';
|
|
103
|
-
categories: readonly string[];
|
|
104
|
-
};
|
|
105
|
-
interface CommandsConfig {
|
|
106
|
-
/** The app's command definitions (content — the plugin ships none). */
|
|
107
|
-
commands?: readonly CommandDef[];
|
|
108
|
-
/** Categories disabled at startup (host feature-gating). */
|
|
109
|
-
disabledCategories?: readonly string[];
|
|
110
|
-
}
|
|
111
|
-
interface CommandsCapability {
|
|
112
|
-
register(def: CommandDef): void;
|
|
113
|
-
unregister(id: string): void;
|
|
114
|
-
has(id: string): boolean;
|
|
115
|
-
ids(): string[];
|
|
116
|
-
resolve(id: string, documentId?: string): ResolvedCommand | null;
|
|
117
|
-
/** Palette query: visible commands whose resolved label matches. */
|
|
118
|
-
search(query: string, documentId?: string): ResolvedCommand[];
|
|
119
|
-
/** The one fact the overflow projection needs (ResolveMenuTarget-shaped). */
|
|
120
|
-
menuTarget(id: string): {
|
|
121
|
-
menu?: string;
|
|
122
|
-
} | null;
|
|
123
|
-
execute(id: string, documentId?: string): void;
|
|
124
|
-
/** Match a keystroke against every registered shortcut → command id or null. */
|
|
125
|
-
matchStroke(stroke: KeyStroke, opts: {
|
|
126
|
-
isMac: boolean;
|
|
127
|
-
}): string | null;
|
|
128
|
-
disabledCategories(): readonly string[];
|
|
129
|
-
isCategoryDisabled(category: string): boolean;
|
|
130
|
-
disableCategory(category: string): void;
|
|
131
|
-
enableCategory(category: string): void;
|
|
132
|
-
setDisabledCategories(categories: readonly string[]): void;
|
|
133
|
-
}
|
|
134
|
-
declare const CommandsToken: CapabilityToken<CommandsCapability>;
|
|
135
|
-
//#endregion
|
|
1
|
+
import { C as CommandsToken, S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDefinition, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "./contract-CeyIrbN0.js";
|
|
2
|
+
import { t as CommandsHostCapability } from "./host-contract-BYueFQCF.js";
|
|
136
3
|
//#region src/commands.plugin.d.ts
|
|
137
4
|
/**
|
|
138
|
-
* The commands
|
|
139
|
-
*
|
|
140
|
-
* Definitions
|
|
141
|
-
* functions
|
|
5
|
+
* The commands: one set for the whole workspace, each resolved and run for a
|
|
6
|
+
* document (the one named, else the document in scope, else the active one).
|
|
7
|
+
* Definitions are settings and app content, never state, since they hold
|
|
8
|
+
* functions. `config` is the settings the app registers, over
|
|
9
|
+
* {@link COMMANDS_DEFAULTS}.
|
|
142
10
|
*/
|
|
143
|
-
declare const commandsPlugin: (config?: CommandsConfig) => import("@embedpdf/core").
|
|
144
|
-
//#endregion
|
|
145
|
-
//#region src/reducer.d.ts
|
|
146
|
-
declare const initialCommandsState: CommandsState;
|
|
147
|
-
declare function commandsReducer(state: CommandsState, action: CommandsAction): CommandsState;
|
|
11
|
+
declare const commandsPlugin: <AppState = any>(config?: CommandsConfig<AppState>) => import("@embedpdf/core").PluginDefinition<void, CommandsHostCapability, CommandsSettings>;
|
|
148
12
|
//#endregion
|
|
149
|
-
export {
|
|
13
|
+
export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDefinition, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, commandsPlugin, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
|
|
150
14
|
//# sourceMappingURL=index.d.ts.map
|