@embedpdf/plugin-commands 3.0.0-next.19 → 3.0.0-next.20

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.
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("../contract-BlOznyrj.cjs");
2
+ const require_contract = require("../contract-sqmSSPlP.cjs");
3
3
  //#region src/host-contract.ts
4
4
  /**
5
5
  * @embedpdf/plugin-commands/contract/host — the host lens: the keystroke
@@ -1,3 +1,3 @@
1
- import { 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 CommandDef, 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-DAV5VR3P.cjs";
2
- import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-Cqz-V6kP.cjs";
1
+ import { 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 CommandDef, 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-lGfvyWMG.cjs";
2
+ import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-DmzPrsSX.cjs";
3
3
  export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsHostCapability, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, ShortcutMatch, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,3 +1,3 @@
1
- import { 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 CommandDef, 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-DAV5VR3P.js";
2
- import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-DkuusR8r.js";
1
+ import { 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 CommandDef, 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-lGfvyWMG.js";
2
+ import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-Cekzl4U8.js";
3
3
  export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsHostCapability, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, ShortcutMatch, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,4 +1,4 @@
1
- import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken$1, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "../contract-Cj5BTtO7.js";
1
+ import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken$1, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "../contract-FbiUhTWC.js";
2
2
  import { createHostToken } from "@embedpdf/core";
3
3
  //#region src/host-contract.ts
4
4
  /**
@@ -46,6 +46,7 @@ function boundCommandOf(command, execute, options) {
46
46
  /** What the commands settings are when the app registers none. */
47
47
  const COMMANDS_DEFAULTS = {
48
48
  commands: [],
49
+ appState: void 0,
49
50
  disabledCategories: [],
50
51
  disabledCommands: [],
51
52
  notAllowed: "hide"
@@ -53,4 +54,4 @@ const COMMANDS_DEFAULTS = {
53
54
  //#endregion
54
55
  export { unregisteredCommand as a, unknownCommandWarning as i, boundCommandOf as n, CommandsToken as o, resolvedCommandsEqual as r, COMMANDS_DEFAULTS as t };
55
56
 
56
- //# sourceMappingURL=contract-Cj5BTtO7.js.map
57
+ //# sourceMappingURL=contract-FbiUhTWC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-FbiUhTWC.js","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here; `contract.ts` re-exports it and\n * `host-contract.ts` widens it to the host capability. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { CommandsCapability } from './contract';\n\nexport const CommandsToken = createCapabilityToken<CommandsCapability>('commands', {\n hint: `add commandsPlugin() from '@embedpdf/plugin-commands' to your plugins list`,\n});\n","/**\n * @embedpdf/plugin-commands/contract — the commands that toolbars, menus,\n * shortcuts and a command palette all show and run.\n *\n * A command's state is read from live state: `resolveCommand` asks the other\n * capabilities when it's called, so every reader follows the kernel's one\n * change stream, with no events. Definitions hold functions, so they live in\n * the settings and the plugin's registry, never in state.\n */\nimport type {\n CapabilityToken,\n DeepPartial,\n EventHook,\n OperationOptions,\n Permission,\n PluginErrorInfo,\n SettingLock,\n SettingsApi,\n Unsubscribe,\n} from '@embedpdf/core';\nimport { didYouMean, formatShortcut } from '@embedpdf/core-ui';\n\nexport { CommandsToken } from './token';\n\nexport type CommandId = string;\n\n/**\n * What a command's derivations and `run` see: capabilities resolved for the command's document\n * (the one named, else the document in scope, else the active one), and your app's state.\n */\nexport interface CommandContext<AppState = any> {\n /** The command's document, or `null` when none is open. */\n readonly documentId: string | null;\n /** Your app's state, as the `appState` setting has it now: `any` until you give its type. */\n readonly appState: AppState;\n /** What the caller passed: `execute(id, { args })`. */\n readonly args?: unknown;\n /** Fires when the caller cancels `execute()`: pass it on to the calls `run` makes. */\n readonly signal?: AbortSignal;\n /** A capability, for the command's document when the plugin is document-scoped. Throws when it isn't available. */\n get<T>(token: CapabilityToken<T>): T;\n /** Like `get`, but `null` when the capability isn't available (no plugin, no document). */\n tryGet<T>(token: CapabilityToken<T>): T | null;\n}\n\n/**\n * Up to two colors that go with a command's icon, such as a tool's current color: data a\n * renderer may use (tint the icon, show a swatch), like `icon` itself.\n */\nexport interface IconAccent {\n /** The mark: a stroke, the markup or the text color. */\n readonly primary?: string;\n /** The fill, when there is one. */\n readonly secondary?: string;\n}\n\n/**\n * One command, as you define it. Its functions get your app's state as `AppState`; they're\n * methods, so a command typed for your state (`CommandDef<Review>`) goes wherever a command does.\n */\nexport interface CommandDef<AppState = any> {\n /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */\n readonly id: string;\n /** What the user sees. With `labelKey` too, it's what shows when no language has the key. */\n readonly label?: string;\n /**\n * A translation key for the label, read through the i18n plugin. Without the plugin, or a\n * string for the key, the command shows `label`, else the key.\n */\n readonly labelKey?: string;\n /** Your icon's name; your buttons turn it into an icon. */\n readonly icon?: string;\n /** Colors for the icon, read from live state like `active`. */\n iconAccent?(context: CommandContext<AppState>): IconAccent | null;\n /** A key such as `'Mod+K'` (`Mod` is Cmd on a Mac, Ctrl elsewhere), or a list of them. */\n readonly shortcut?: string | readonly string[];\n /**\n * Whether its shortcut also runs while the cursor is in a text field where the shortcuts\n * listen (a search box, a comment), as the viewer's Find does. Default false: a key typed in\n * a field is the field's.\n */\n readonly shortcutInTextFields?: boolean;\n /**\n * The features it belongs to, so turning one off turns it off: `['annotations.highlight']`.\n * Turning off a feature turns off every feature under it, on whole dotted parts: `annotations`\n * covers `annotations.highlight`, not `annotationsExtra`.\n */\n readonly categories?: readonly string[];\n /**\n * The scope permissions it needs, such as `'doc.annotate.modify'`, checked against its\n * document. Without them it's hidden, or shown disabled with its reason under the\n * `notAllowed: 'disable'` setting. With no document open there is nothing to check.\n */\n readonly requires?: readonly Permission[];\n /**\n * Whether the session may run it, from the plugins' `can*` checks\n * (`documents.canPrint()`), for a command whose permission is a plugin's to know. When it\n * says no, the command isn't allowed, as with `requires`. Asked only while a document is\n * open; one that throws allows it.\n */\n allowed?(context: CommandContext<AppState>): boolean;\n /**\n * The translation key of the sentence that says why `allowed` refused it, with `{label}` for\n * its label: `'commands.notAllowed.doc-print'`. Without it, or a string for it,\n * `commands.notAllowed.default`.\n */\n readonly notAllowedKey?: string;\n /**\n * The lock on the setting it changes, for a command that changes one\n * (`(context) => context.get(StageToken).getLock('spread')`), or `null`.\n * While a lock holds, it shows disabled, whatever the `notAllowed` setting\n * says, with the sentence under the lock's `reasonKey` (else\n * `commands.locked.default`) as its `disabledReason`; it stays `active` for\n * its own value. One that throws counts as unlocked.\n */\n locked?(context: CommandContext<AppState>): SettingLock | null;\n\n // ── what the command opens ───────────────────────────────────────────────\n // A command that opens a panel, menu or dialog says so instead of opening\n // it in `run`: it then needs no `run`, it shows as active while the surface\n // is open, and a button can show that it opens a menu.\n /** Opens and closes a menu of yours, by its id. */\n readonly menu?: string;\n /**\n * Opens and closes a panel, closing the others with the same `exclusive` tag. With `focus`,\n * opening it asks for the cursor (the shell's `open(id, { focus: true })`).\n */\n readonly panel?:\n | string\n | { readonly id: string; readonly exclusive?: string; readonly focus?: boolean };\n /** Opens and closes a dialog; one dialog is open at a time. */\n readonly modal?: string;\n\n // ── read from live state and your app's, again whenever either changes ──\n /** When it can run. Default: always. One that throws counts as false. */\n enabled?(context: CommandContext<AppState>): boolean;\n /** When it shows as pressed, such as the current tool. One that throws counts as false. */\n active?(context: CommandContext<AppState>): boolean;\n /** When it shows at all. Default: always. One that throws counts as false. */\n visible?(context: CommandContext<AppState>): boolean;\n\n /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */\n run?(context: CommandContext<AppState>): void | Promise<unknown>;\n}\n\n/**\n * A command for each of a set of names, made from one definition, such as `tool:<id>` for every\n * tool a document has. Its commands resolve and run like any other, and `listCommands()` lists\n * one per name. A command defined with the same id wins over the family's.\n */\nexport interface CommandFamily {\n /** Where the commands' ids start: `'tool:'` makes `tool:highlight`. */\n readonly prefix: string;\n /** The names the command's document has, in order. Return the same array while nothing changed. */\n readonly names: (context: CommandContext) => readonly string[];\n /** The command for one name. A family's commands have no shortcuts. */\n readonly command: (name: string) => Omit<CommandDef, 'id' | 'shortcut'>;\n}\n\n/** A command as a button shows it: everything read for its 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 * Why it's disabled, as a sentence for its tooltip: set when the scope doesn't allow it and\n * the `notAllowed` setting is `'disable'`, or when a lock holds the setting it changes.\n */\n readonly disabledReason?: string;\n}\n\n/**\n * Why a command won't run whatever the moment: it's turned off in this viewer\n * (`disabledCategories`, `disabledCommands`), the scope doesn't allow it (`requires`), or a lock\n * holds the setting it changes (`locked`). A command that only can't run right now (`enabled`,\n * `visible`) has no refusal.\n */\nexport interface CommandRefusal {\n readonly reason: 'turned-off' | 'not-allowed' | 'locked';\n /** A sentence for the user, translated through the i18n plugin when it's there. */\n readonly message: string;\n}\n\n/**\n * Whether two resolved commands show the same, for readers that compare what a command looks\n * like rather than which object holds it (a group of commands, or one command for two documents).\n */\nexport const resolvedCommandsEqual = (\n left: ResolvedCommand | null,\n right: ResolvedCommand | null,\n): boolean => {\n if (left === right) return true;\n if (!left || !right) return false;\n return (\n left.id === right.id &&\n left.label === right.label &&\n left.icon === right.icon &&\n left.iconAccent?.primary === right.iconAccent?.primary &&\n left.iconAccent?.secondary === right.iconAccent?.secondary &&\n left.menu === right.menu &&\n left.enabled === right.enabled &&\n left.active === right.active &&\n left.visible === right.visible &&\n left.disabledReason === right.disabledReason &&\n left.shortcuts.length === right.shortcuts.length &&\n left.shortcuts.every((shortcut, index) => shortcut === right.shortcuts[index])\n );\n};\n\n/**\n * What a component or a toolbar draws for a command id no plugin registered: labelled with its\n * id, neither enabled nor visible, the way a turned-off command is.\n */\nexport const unregisteredCommand = (id: CommandId): ResolvedCommand => ({\n id,\n label: id,\n shortcuts: [],\n enabled: false,\n active: false,\n visible: false,\n categories: [],\n});\n\n/** What a component that asks for an id no plugin registered hears, in development. */\nexport const unknownCommandWarning = (id: CommandId, known: Iterable<CommandId>): string =>\n `no command \"${id}\"${didYouMean(id, known)}: it shows as neither visible nor enabled`;\n\n/** A command with everything a button needs: what it shows, `run`, and its shortcut for a tooltip. */\nexport interface BoundCommand extends ResolvedCommand {\n /** Run the command for the document it was read for. */\n readonly run: () => Promise<ExecuteResult>;\n /** Its first shortcut, formatted for the platform (`'⌘K'` on a Mac, `'Ctrl+K'` elsewhere), or `null`. */\n readonly shortcut: string | null;\n}\n\n/**\n * A resolved command, bound for a button: `run` executes it through `execute`, and `shortcut` is\n * its first shortcut formatted for the platform. Which platform is the caller's to know\n * (`isMacPlatform()` in `@embedpdf/web`).\n */\nexport function boundCommandOf(\n command: ResolvedCommand,\n execute: (id: CommandId) => Promise<ExecuteResult>,\n options: { readonly isMac: boolean },\n): BoundCommand {\n const [first] = command.shortcuts;\n return {\n ...command,\n run: () => execute(command.id),\n shortcut: first === undefined ? null : formatShortcut(first, { isMac: options.isMac }),\n };\n}\n\n/**\n * The commands plugin's settings. `commandsPlugin(config)` registers them over\n * {@link COMMANDS_DEFAULTS}, and `updateSettings()` changes them while the app runs.\n */\nexport interface CommandsSettings {\n /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */\n readonly commands: readonly (CommandDef | CommandFamily)[];\n /**\n * Your app's state, which every command's functions get as `appState`: values, and functions\n * that change them. A new value replaces the old one whole, and every command is asked again.\n */\n readonly appState: unknown;\n /**\n * Categories turned off, with every category under them: their commands are hidden and\n * refused wherever they appear.\n */\n readonly disabledCategories: readonly string[];\n /** Commands turned off one by one, by id: hidden and refused wherever they appear. */\n readonly disabledCommands: readonly CommandId[];\n /**\n * What a command the scope doesn't allow does: `'hide'` leaves it out, `'disable'` shows it\n * disabled, with the reason in its `disabledReason`.\n */\n readonly notAllowed: NotAllowedMode;\n}\n\n/** How a command shows when the scope doesn't allow it: hidden, or disabled with its reason. */\nexport type NotAllowedMode = 'hide' | 'disable';\n\n/** What the commands settings are when the app registers none. */\nexport const COMMANDS_DEFAULTS: CommandsSettings = {\n commands: [],\n appState: undefined,\n disabledCategories: [],\n disabledCommands: [],\n notAllowed: 'hide',\n};\n\n/** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type CommandsConfig<AppState = any> = Omit<\n DeepPartial<CommandsSettings>,\n 'commands' | 'appState'\n> & {\n readonly commands?: readonly (CommandDef<AppState> | CommandFamily)[];\n readonly appState?: AppState;\n};\n\nexport interface RegisterCommandOptions {\n /** Replace a command with the same id; without it, a taken id throws `conflict`. */\n replace?: boolean;\n}\n\nexport interface ExecuteOptions extends OperationOptions {\n /** The document to run it for; the document in scope, else the active one, when left out. */\n documentId?: string;\n /** Passed to the command's `run` and derivations as `args`. */\n args?: unknown;\n}\n\n/** How `execute()` went: it ran, or it was refused before running, and why. */\nexport type ExecuteResult =\n | { readonly status: 'executed' }\n | { readonly status: 'rejected'; readonly reason: 'not-found' | 'disabled' | 'hidden' };\n\n// ── events ──\nexport interface CommandExecutedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly args: unknown;\n}\nexport interface CommandExecutionFailedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly error: PluginErrorInfo;\n}\n\n/**\n * The commands. A call that leaves out the document is for the document in scope when the\n * capability was resolved for one (`ctx.forDocument`, a `<DocumentScope>`), and for the active\n * document otherwise.\n */\nexport interface CommandsCapability extends SettingsApi<CommandsSettings> {\n // ── the commands ──\n /**\n * Add a command while the app runs, and get a function that removes it. A taken id throws\n * `conflict` unless `replace`.\n */\n registerCommand(definition: CommandDef, options?: RegisterCommandOptions): Unsubscribe;\n /** `registerCommand` for several definitions; the function removes all of them. */\n registerCommands(\n definitions: readonly CommandDef[],\n options?: RegisterCommandOptions,\n ): Unsubscribe;\n /** Whether a command has this id; with a family, every id that starts with its prefix does. */\n hasCommand(id: CommandId): boolean;\n /** A command as you defined it, or `null`. */\n getCommand(id: CommandId): CommandDef | null;\n /** Every command's id for the active document, in the order they were added. The same array until one changes. */\n listCommandIds(): readonly CommandId[];\n\n // ── what a button shows ──\n /** A command as a button shows it, or `null` for an unknown id. The same object while nothing about it changed. */\n resolveCommand(id: CommandId, documentId?: string): ResolvedCommand | null;\n /** Every command, resolved, in the order they were added. The same array while nothing changed. */\n listCommands(documentId?: string): readonly ResolvedCommand[];\n /** The visible commands whose label or id contains the query, for a command palette. */\n searchCommands(query: string, documentId?: string): readonly ResolvedCommand[];\n /** Every shortcut with its command, for a keyboard help sheet. The same array until the commands change. */\n listShortcuts(): readonly { readonly commandId: CommandId; readonly shortcut: string }[];\n\n // ── running them ──\n /**\n * Run a command; resolves once its `run` has, with `{ status: 'executed' }` and\n * `onExecuted`, or `{ status: 'rejected', reason }` for a command that is unknown, hidden or\n * disabled (a command turned off is hidden). A `run` that throws fires `onExecutionFailed` and rejects with its `PluginError`;\n * the signal rejects `operation-cancelled`.\n */\n execute(id: CommandId, options?: ExecuteOptions): Promise<ExecuteResult>;\n /** Whether a command can run now: it exists, and is enabled and visible. */\n canExecute(id: CommandId, documentId?: string): boolean;\n /**\n * Why a command won't run whatever the moment: it's turned off, or not allowed for its\n * document. `null` when it may run (or only can't right now), and for an unknown id.\n */\n getRefusal(id: CommandId, documentId?: string): CommandRefusal | null;\n\n // ── turning commands off ──\n /** The categories turned off. */\n getDisabledCategories(): readonly string[];\n /** Whether a category is turned off: it, or a category it's under (`annotations` for `annotations.highlight`). */\n isCategoryDisabled(category: string): boolean;\n /** Turn a category off, with every category under it: the `disabledCategories` setting gains it. */\n disableCategory(category: string): void;\n /** Turn a category on again. */\n enableCategory(category: string): void;\n /** Replace the categories that are off. */\n setDisabledCategories(categories: readonly string[]): void;\n /** The commands turned off one by one. */\n getDisabledCommands(): readonly CommandId[];\n /** Whether a command is turned off: by its id, or through one of its categories. */\n isCommandDisabled(id: CommandId): boolean;\n /** Turn one command off: the `disabledCommands` setting gains it. */\n disableCommand(id: CommandId): void;\n /** Turn a command on again; it stays off while one of its categories is. */\n enableCommand(id: CommandId): void;\n /** Replace the commands that are off one by one. */\n setDisabledCommands(ids: readonly CommandId[]): void;\n\n // ── events ──\n /** A command ran. */\n readonly onExecuted: EventHook<CommandExecutedEvent>;\n /** A command's `run` threw; `execute` rejects with the same error. */\n readonly onExecutionFailed: EventHook<CommandExecutionFailedEvent>;\n}\n"],"mappings":";;;;;AAMA,MAAa,gBAAgB,sBAA0C,YAAY,EACjF,MAAM,6EACR,CAAC;;;;;;;AC0LD,MAAa,yBACX,MACA,UACY;CACZ,IAAI,SAAS,OAAO,OAAO;CAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO,OAAO;CAC5B,OACE,KAAK,OAAO,MAAM,MAClB,KAAK,UAAU,MAAM,SACrB,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,YAAY,MAAM,YAAY,WAC/C,KAAK,YAAY,cAAc,MAAM,YAAY,aACjD,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,MAAM,WACvB,KAAK,WAAW,MAAM,UACtB,KAAK,YAAY,MAAM,WACvB,KAAK,mBAAmB,MAAM,kBAC9B,KAAK,UAAU,WAAW,MAAM,UAAU,UAC1C,KAAK,UAAU,OAAO,UAAU,UAAU,aAAa,MAAM,UAAU,MAAM;AAEjF;;;;;AAMA,MAAa,uBAAuB,QAAoC;CACtE;CACA,OAAO;CACP,WAAW,CAAC;CACZ,SAAS;CACT,QAAQ;CACR,SAAS;CACT,YAAY,CAAC;AACf;;AAGA,MAAa,yBAAyB,IAAe,UACnD,eAAe,GAAG,GAAG,WAAW,IAAI,KAAK,EAAE;;;;;;AAe7C,SAAgB,eACd,SACA,SACA,SACc;CACd,MAAM,CAAC,SAAS,QAAQ;CACxB,OAAO;EACL,GAAG;EACH,WAAW,QAAQ,QAAQ,EAAE;EAC7B,UAAU,UAAU,KAAA,IAAY,OAAO,eAAe,OAAO,EAAE,OAAO,QAAQ,MAAM,CAAC;CACvF;AACF;;AAgCA,MAAa,oBAAsC;CACjD,UAAU,CAAC;CACX,UAAU,KAAA;CACV,oBAAoB,CAAC;CACrB,kBAAkB,CAAC;CACnB,YAAY;AACd"}
@@ -1,4 +1,4 @@
1
- import { CapabilityToken, DeepPartial, EventHook, OperationOptions, Permission, PluginErrorInfo, SettingsApi, Unsubscribe } from "@embedpdf/core";
1
+ import { CapabilityToken, DeepPartial, EventHook, OperationOptions, Permission, PluginErrorInfo, SettingLock, SettingsApi, Unsubscribe } from "@embedpdf/core";
2
2
  //#region src/token.d.ts
3
3
  declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsCapability>;
4
4
  //#endregion
@@ -6,11 +6,13 @@ declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsCa
6
6
  type CommandId = string;
7
7
  /**
8
8
  * What a command's derivations and `run` see: capabilities resolved for the command's document
9
- * (the one named, else the document in scope, else the active one).
9
+ * (the one named, else the document in scope, else the active one), and your app's state.
10
10
  */
11
- interface CommandContext {
11
+ interface CommandContext<AppState = any> {
12
12
  /** The command's document, or `null` when none is open. */
13
13
  readonly documentId: string | null;
14
+ /** Your app's state, as the `appState` setting has it now: `any` until you give its type. */
15
+ readonly appState: AppState;
14
16
  /** What the caller passed: `execute(id, { args })`. */
15
17
  readonly args?: unknown;
16
18
  /** Fires when the caller cancels `execute()`: pass it on to the calls `run` makes. */
@@ -30,8 +32,11 @@ interface IconAccent {
30
32
  /** The fill, when there is one. */
31
33
  readonly secondary?: string;
32
34
  }
33
- /** One command, as you define it. */
34
- interface CommandDef {
35
+ /**
36
+ * One command, as you define it. Its functions get your app's state as `AppState`; they're
37
+ * methods, so a command typed for your state (`CommandDef<Review>`) goes wherever a command does.
38
+ */
39
+ interface CommandDef<AppState = any> {
35
40
  /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */
36
41
  readonly id: string;
37
42
  /** What the user sees. With `labelKey` too, it's what shows when no language has the key. */
@@ -44,7 +49,7 @@ interface CommandDef {
44
49
  /** Your icon's name; your buttons turn it into an icon. */
45
50
  readonly icon?: string;
46
51
  /** Colors for the icon, read from live state like `active`. */
47
- readonly iconAccent?: (context: CommandContext) => IconAccent | null;
52
+ iconAccent?(context: CommandContext<AppState>): IconAccent | null;
48
53
  /** A key such as `'Mod+K'` (`Mod` is Cmd on a Mac, Ctrl elsewhere), or a list of them. */
49
54
  readonly shortcut?: string | readonly string[];
50
55
  /**
@@ -71,13 +76,22 @@ interface CommandDef {
71
76
  * says no, the command isn't allowed, as with `requires`. Asked only while a document is
72
77
  * open; one that throws allows it.
73
78
  */
74
- readonly allowed?: (context: CommandContext) => boolean;
79
+ allowed?(context: CommandContext<AppState>): boolean;
75
80
  /**
76
81
  * The translation key of the sentence that says why `allowed` refused it, with `{label}` for
77
82
  * its label: `'commands.notAllowed.doc-print'`. Without it, or a string for it,
78
83
  * `commands.notAllowed.default`.
79
84
  */
80
85
  readonly notAllowedKey?: string;
86
+ /**
87
+ * The lock on the setting it changes, for a command that changes one
88
+ * (`(context) => context.get(StageToken).getLock('spread')`), or `null`.
89
+ * While a lock holds, it shows disabled, whatever the `notAllowed` setting
90
+ * says, with the sentence under the lock's `reasonKey` (else
91
+ * `commands.locked.default`) as its `disabledReason`; it stays `active` for
92
+ * its own value. One that throws counts as unlocked.
93
+ */
94
+ locked?(context: CommandContext<AppState>): SettingLock | null;
81
95
  /** Opens and closes a menu of yours, by its id. */
82
96
  readonly menu?: string;
83
97
  /**
@@ -91,14 +105,14 @@ interface CommandDef {
91
105
  };
92
106
  /** Opens and closes a dialog; one dialog is open at a time. */
93
107
  readonly modal?: string;
94
- /** When it can run. Default: always. */
95
- readonly enabled?: (context: CommandContext) => boolean;
96
- /** When it shows as pressed, such as the current tool. */
97
- readonly active?: (context: CommandContext) => boolean;
98
- /** When it shows at all. Default: always. */
99
- readonly visible?: (context: CommandContext) => boolean;
108
+ /** When it can run. Default: always. One that throws counts as false. */
109
+ enabled?(context: CommandContext<AppState>): boolean;
110
+ /** When it shows as pressed, such as the current tool. One that throws counts as false. */
111
+ active?(context: CommandContext<AppState>): boolean;
112
+ /** When it shows at all. Default: always. One that throws counts as false. */
113
+ visible?(context: CommandContext<AppState>): boolean;
100
114
  /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */
101
- readonly run?: (context: CommandContext) => void | Promise<unknown>;
115
+ run?(context: CommandContext<AppState>): void | Promise<unknown>;
102
116
  }
103
117
  /**
104
118
  * A command for each of a set of names, made from one definition, such as `tool:<id>` for every
@@ -127,17 +141,18 @@ interface ResolvedCommand {
127
141
  readonly categories: readonly string[];
128
142
  /**
129
143
  * Why it's disabled, as a sentence for its tooltip: set when the scope doesn't allow it and
130
- * the `notAllowed` setting is `'disable'`.
144
+ * the `notAllowed` setting is `'disable'`, or when a lock holds the setting it changes.
131
145
  */
132
146
  readonly disabledReason?: string;
133
147
  }
134
148
  /**
135
149
  * Why a command won't run whatever the moment: it's turned off in this viewer
136
- * (`disabledCategories`, `disabledCommands`), or the scope doesn't allow it (`requires`).
137
- * A command that only can't run right now (`enabled`, `visible`) has no refusal.
150
+ * (`disabledCategories`, `disabledCommands`), the scope doesn't allow it (`requires`), or a lock
151
+ * holds the setting it changes (`locked`). A command that only can't run right now (`enabled`,
152
+ * `visible`) has no refusal.
138
153
  */
139
154
  interface CommandRefusal {
140
- readonly reason: 'turned-off' | 'not-allowed';
155
+ readonly reason: 'turned-off' | 'not-allowed' | 'locked';
141
156
  /** A sentence for the user, translated through the i18n plugin when it's there. */
142
157
  readonly message: string;
143
158
  }
@@ -175,6 +190,11 @@ declare function boundCommandOf(command: ResolvedCommand, execute: (id: CommandI
175
190
  interface CommandsSettings {
176
191
  /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */
177
192
  readonly commands: readonly (CommandDef | CommandFamily)[];
193
+ /**
194
+ * Your app's state, which every command's functions get as `appState`: values, and functions
195
+ * that change them. A new value replaces the old one whole, and every command is asked again.
196
+ */
197
+ readonly appState: unknown;
178
198
  /**
179
199
  * Categories turned off, with every category under them: their commands are hidden and
180
200
  * refused wherever they appear.
@@ -193,7 +213,10 @@ type NotAllowedMode = 'hide' | 'disable';
193
213
  /** What the commands settings are when the app registers none. */
194
214
  declare const COMMANDS_DEFAULTS: CommandsSettings;
195
215
  /** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */
196
- type CommandsConfig = DeepPartial<CommandsSettings>;
216
+ type CommandsConfig<AppState = any> = Omit<DeepPartial<CommandsSettings>, 'commands' | 'appState'> & {
217
+ readonly commands?: readonly (CommandDef<AppState> | CommandFamily)[];
218
+ readonly appState?: AppState;
219
+ };
197
220
  interface RegisterCommandOptions {
198
221
  /** Replace a command with the same id; without it, a taken id throws `conflict`. */
199
222
  replace?: boolean;
@@ -292,4 +315,4 @@ interface CommandsCapability extends SettingsApi<CommandsSettings> {
292
315
  }
293
316
  //#endregion
294
317
  export { CommandsToken as C, unregisteredCommand as S, RegisterCommandOptions as _, CommandExecutedEvent as a, resolvedCommandsEqual as b, CommandId as c, CommandsConfig as d, CommandsSettings as f, NotAllowedMode as g, IconAccent as h, CommandDef as i, CommandRefusal as l, ExecuteResult as m, COMMANDS_DEFAULTS as n, CommandExecutionFailedEvent as o, ExecuteOptions as p, CommandContext as r, CommandFamily as s, BoundCommand as t, CommandsCapability as u, ResolvedCommand as v, unknownCommandWarning as x, boundCommandOf as y };
295
- //# sourceMappingURL=contract-DAV5VR3P.d.ts.map
318
+ //# sourceMappingURL=contract-lGfvyWMG.d.cts.map
@@ -1,4 +1,4 @@
1
- import { CapabilityToken, DeepPartial, EventHook, OperationOptions, Permission, PluginErrorInfo, SettingsApi, Unsubscribe } from "@embedpdf/core";
1
+ import { CapabilityToken, DeepPartial, EventHook, OperationOptions, Permission, PluginErrorInfo, SettingLock, SettingsApi, Unsubscribe } from "@embedpdf/core";
2
2
  //#region src/token.d.ts
3
3
  declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsCapability>;
4
4
  //#endregion
@@ -6,11 +6,13 @@ declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsCa
6
6
  type CommandId = string;
7
7
  /**
8
8
  * What a command's derivations and `run` see: capabilities resolved for the command's document
9
- * (the one named, else the document in scope, else the active one).
9
+ * (the one named, else the document in scope, else the active one), and your app's state.
10
10
  */
11
- interface CommandContext {
11
+ interface CommandContext<AppState = any> {
12
12
  /** The command's document, or `null` when none is open. */
13
13
  readonly documentId: string | null;
14
+ /** Your app's state, as the `appState` setting has it now: `any` until you give its type. */
15
+ readonly appState: AppState;
14
16
  /** What the caller passed: `execute(id, { args })`. */
15
17
  readonly args?: unknown;
16
18
  /** Fires when the caller cancels `execute()`: pass it on to the calls `run` makes. */
@@ -30,8 +32,11 @@ interface IconAccent {
30
32
  /** The fill, when there is one. */
31
33
  readonly secondary?: string;
32
34
  }
33
- /** One command, as you define it. */
34
- interface CommandDef {
35
+ /**
36
+ * One command, as you define it. Its functions get your app's state as `AppState`; they're
37
+ * methods, so a command typed for your state (`CommandDef<Review>`) goes wherever a command does.
38
+ */
39
+ interface CommandDef<AppState = any> {
35
40
  /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */
36
41
  readonly id: string;
37
42
  /** What the user sees. With `labelKey` too, it's what shows when no language has the key. */
@@ -44,7 +49,7 @@ interface CommandDef {
44
49
  /** Your icon's name; your buttons turn it into an icon. */
45
50
  readonly icon?: string;
46
51
  /** Colors for the icon, read from live state like `active`. */
47
- readonly iconAccent?: (context: CommandContext) => IconAccent | null;
52
+ iconAccent?(context: CommandContext<AppState>): IconAccent | null;
48
53
  /** A key such as `'Mod+K'` (`Mod` is Cmd on a Mac, Ctrl elsewhere), or a list of them. */
49
54
  readonly shortcut?: string | readonly string[];
50
55
  /**
@@ -71,13 +76,22 @@ interface CommandDef {
71
76
  * says no, the command isn't allowed, as with `requires`. Asked only while a document is
72
77
  * open; one that throws allows it.
73
78
  */
74
- readonly allowed?: (context: CommandContext) => boolean;
79
+ allowed?(context: CommandContext<AppState>): boolean;
75
80
  /**
76
81
  * The translation key of the sentence that says why `allowed` refused it, with `{label}` for
77
82
  * its label: `'commands.notAllowed.doc-print'`. Without it, or a string for it,
78
83
  * `commands.notAllowed.default`.
79
84
  */
80
85
  readonly notAllowedKey?: string;
86
+ /**
87
+ * The lock on the setting it changes, for a command that changes one
88
+ * (`(context) => context.get(StageToken).getLock('spread')`), or `null`.
89
+ * While a lock holds, it shows disabled, whatever the `notAllowed` setting
90
+ * says, with the sentence under the lock's `reasonKey` (else
91
+ * `commands.locked.default`) as its `disabledReason`; it stays `active` for
92
+ * its own value. One that throws counts as unlocked.
93
+ */
94
+ locked?(context: CommandContext<AppState>): SettingLock | null;
81
95
  /** Opens and closes a menu of yours, by its id. */
82
96
  readonly menu?: string;
83
97
  /**
@@ -91,14 +105,14 @@ interface CommandDef {
91
105
  };
92
106
  /** Opens and closes a dialog; one dialog is open at a time. */
93
107
  readonly modal?: string;
94
- /** When it can run. Default: always. */
95
- readonly enabled?: (context: CommandContext) => boolean;
96
- /** When it shows as pressed, such as the current tool. */
97
- readonly active?: (context: CommandContext) => boolean;
98
- /** When it shows at all. Default: always. */
99
- readonly visible?: (context: CommandContext) => boolean;
108
+ /** When it can run. Default: always. One that throws counts as false. */
109
+ enabled?(context: CommandContext<AppState>): boolean;
110
+ /** When it shows as pressed, such as the current tool. One that throws counts as false. */
111
+ active?(context: CommandContext<AppState>): boolean;
112
+ /** When it shows at all. Default: always. One that throws counts as false. */
113
+ visible?(context: CommandContext<AppState>): boolean;
100
114
  /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */
101
- readonly run?: (context: CommandContext) => void | Promise<unknown>;
115
+ run?(context: CommandContext<AppState>): void | Promise<unknown>;
102
116
  }
103
117
  /**
104
118
  * A command for each of a set of names, made from one definition, such as `tool:<id>` for every
@@ -127,17 +141,18 @@ interface ResolvedCommand {
127
141
  readonly categories: readonly string[];
128
142
  /**
129
143
  * Why it's disabled, as a sentence for its tooltip: set when the scope doesn't allow it and
130
- * the `notAllowed` setting is `'disable'`.
144
+ * the `notAllowed` setting is `'disable'`, or when a lock holds the setting it changes.
131
145
  */
132
146
  readonly disabledReason?: string;
133
147
  }
134
148
  /**
135
149
  * Why a command won't run whatever the moment: it's turned off in this viewer
136
- * (`disabledCategories`, `disabledCommands`), or the scope doesn't allow it (`requires`).
137
- * A command that only can't run right now (`enabled`, `visible`) has no refusal.
150
+ * (`disabledCategories`, `disabledCommands`), the scope doesn't allow it (`requires`), or a lock
151
+ * holds the setting it changes (`locked`). A command that only can't run right now (`enabled`,
152
+ * `visible`) has no refusal.
138
153
  */
139
154
  interface CommandRefusal {
140
- readonly reason: 'turned-off' | 'not-allowed';
155
+ readonly reason: 'turned-off' | 'not-allowed' | 'locked';
141
156
  /** A sentence for the user, translated through the i18n plugin when it's there. */
142
157
  readonly message: string;
143
158
  }
@@ -175,6 +190,11 @@ declare function boundCommandOf(command: ResolvedCommand, execute: (id: CommandI
175
190
  interface CommandsSettings {
176
191
  /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */
177
192
  readonly commands: readonly (CommandDef | CommandFamily)[];
193
+ /**
194
+ * Your app's state, which every command's functions get as `appState`: values, and functions
195
+ * that change them. A new value replaces the old one whole, and every command is asked again.
196
+ */
197
+ readonly appState: unknown;
178
198
  /**
179
199
  * Categories turned off, with every category under them: their commands are hidden and
180
200
  * refused wherever they appear.
@@ -193,7 +213,10 @@ type NotAllowedMode = 'hide' | 'disable';
193
213
  /** What the commands settings are when the app registers none. */
194
214
  declare const COMMANDS_DEFAULTS: CommandsSettings;
195
215
  /** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */
196
- type CommandsConfig = DeepPartial<CommandsSettings>;
216
+ type CommandsConfig<AppState = any> = Omit<DeepPartial<CommandsSettings>, 'commands' | 'appState'> & {
217
+ readonly commands?: readonly (CommandDef<AppState> | CommandFamily)[];
218
+ readonly appState?: AppState;
219
+ };
197
220
  interface RegisterCommandOptions {
198
221
  /** Replace a command with the same id; without it, a taken id throws `conflict`. */
199
222
  replace?: boolean;
@@ -292,4 +315,4 @@ interface CommandsCapability extends SettingsApi<CommandsSettings> {
292
315
  }
293
316
  //#endregion
294
317
  export { CommandsToken as C, unregisteredCommand as S, RegisterCommandOptions as _, CommandExecutedEvent as a, resolvedCommandsEqual as b, CommandId as c, CommandsConfig as d, CommandsSettings as f, NotAllowedMode as g, IconAccent as h, CommandDef as i, CommandRefusal as l, ExecuteResult as m, COMMANDS_DEFAULTS as n, CommandExecutionFailedEvent as o, ExecuteOptions as p, CommandContext as r, CommandFamily as s, BoundCommand as t, CommandsCapability as u, ResolvedCommand as v, unknownCommandWarning as x, boundCommandOf as y };
295
- //# sourceMappingURL=contract-DAV5VR3P.d.cts.map
318
+ //# sourceMappingURL=contract-lGfvyWMG.d.ts.map
@@ -46,6 +46,7 @@ function boundCommandOf(command, execute, options) {
46
46
  /** What the commands settings are when the app registers none. */
47
47
  const COMMANDS_DEFAULTS = {
48
48
  commands: [],
49
+ appState: void 0,
49
50
  disabledCategories: [],
50
51
  disabledCommands: [],
51
52
  notAllowed: "hide"
@@ -88,4 +89,4 @@ Object.defineProperty(exports, "unregisteredCommand", {
88
89
  }
89
90
  });
90
91
 
91
- //# sourceMappingURL=contract-BlOznyrj.cjs.map
92
+ //# sourceMappingURL=contract-sqmSSPlP.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-sqmSSPlP.cjs","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here; `contract.ts` re-exports it and\n * `host-contract.ts` widens it to the host capability. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { CommandsCapability } from './contract';\n\nexport const CommandsToken = createCapabilityToken<CommandsCapability>('commands', {\n hint: `add commandsPlugin() from '@embedpdf/plugin-commands' to your plugins list`,\n});\n","/**\n * @embedpdf/plugin-commands/contract — the commands that toolbars, menus,\n * shortcuts and a command palette all show and run.\n *\n * A command's state is read from live state: `resolveCommand` asks the other\n * capabilities when it's called, so every reader follows the kernel's one\n * change stream, with no events. Definitions hold functions, so they live in\n * the settings and the plugin's registry, never in state.\n */\nimport type {\n CapabilityToken,\n DeepPartial,\n EventHook,\n OperationOptions,\n Permission,\n PluginErrorInfo,\n SettingLock,\n SettingsApi,\n Unsubscribe,\n} from '@embedpdf/core';\nimport { didYouMean, formatShortcut } from '@embedpdf/core-ui';\n\nexport { CommandsToken } from './token';\n\nexport type CommandId = string;\n\n/**\n * What a command's derivations and `run` see: capabilities resolved for the command's document\n * (the one named, else the document in scope, else the active one), and your app's state.\n */\nexport interface CommandContext<AppState = any> {\n /** The command's document, or `null` when none is open. */\n readonly documentId: string | null;\n /** Your app's state, as the `appState` setting has it now: `any` until you give its type. */\n readonly appState: AppState;\n /** What the caller passed: `execute(id, { args })`. */\n readonly args?: unknown;\n /** Fires when the caller cancels `execute()`: pass it on to the calls `run` makes. */\n readonly signal?: AbortSignal;\n /** A capability, for the command's document when the plugin is document-scoped. Throws when it isn't available. */\n get<T>(token: CapabilityToken<T>): T;\n /** Like `get`, but `null` when the capability isn't available (no plugin, no document). */\n tryGet<T>(token: CapabilityToken<T>): T | null;\n}\n\n/**\n * Up to two colors that go with a command's icon, such as a tool's current color: data a\n * renderer may use (tint the icon, show a swatch), like `icon` itself.\n */\nexport interface IconAccent {\n /** The mark: a stroke, the markup or the text color. */\n readonly primary?: string;\n /** The fill, when there is one. */\n readonly secondary?: string;\n}\n\n/**\n * One command, as you define it. Its functions get your app's state as `AppState`; they're\n * methods, so a command typed for your state (`CommandDef<Review>`) goes wherever a command does.\n */\nexport interface CommandDef<AppState = any> {\n /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */\n readonly id: string;\n /** What the user sees. With `labelKey` too, it's what shows when no language has the key. */\n readonly label?: string;\n /**\n * A translation key for the label, read through the i18n plugin. Without the plugin, or a\n * string for the key, the command shows `label`, else the key.\n */\n readonly labelKey?: string;\n /** Your icon's name; your buttons turn it into an icon. */\n readonly icon?: string;\n /** Colors for the icon, read from live state like `active`. */\n iconAccent?(context: CommandContext<AppState>): IconAccent | null;\n /** A key such as `'Mod+K'` (`Mod` is Cmd on a Mac, Ctrl elsewhere), or a list of them. */\n readonly shortcut?: string | readonly string[];\n /**\n * Whether its shortcut also runs while the cursor is in a text field where the shortcuts\n * listen (a search box, a comment), as the viewer's Find does. Default false: a key typed in\n * a field is the field's.\n */\n readonly shortcutInTextFields?: boolean;\n /**\n * The features it belongs to, so turning one off turns it off: `['annotations.highlight']`.\n * Turning off a feature turns off every feature under it, on whole dotted parts: `annotations`\n * covers `annotations.highlight`, not `annotationsExtra`.\n */\n readonly categories?: readonly string[];\n /**\n * The scope permissions it needs, such as `'doc.annotate.modify'`, checked against its\n * document. Without them it's hidden, or shown disabled with its reason under the\n * `notAllowed: 'disable'` setting. With no document open there is nothing to check.\n */\n readonly requires?: readonly Permission[];\n /**\n * Whether the session may run it, from the plugins' `can*` checks\n * (`documents.canPrint()`), for a command whose permission is a plugin's to know. When it\n * says no, the command isn't allowed, as with `requires`. Asked only while a document is\n * open; one that throws allows it.\n */\n allowed?(context: CommandContext<AppState>): boolean;\n /**\n * The translation key of the sentence that says why `allowed` refused it, with `{label}` for\n * its label: `'commands.notAllowed.doc-print'`. Without it, or a string for it,\n * `commands.notAllowed.default`.\n */\n readonly notAllowedKey?: string;\n /**\n * The lock on the setting it changes, for a command that changes one\n * (`(context) => context.get(StageToken).getLock('spread')`), or `null`.\n * While a lock holds, it shows disabled, whatever the `notAllowed` setting\n * says, with the sentence under the lock's `reasonKey` (else\n * `commands.locked.default`) as its `disabledReason`; it stays `active` for\n * its own value. One that throws counts as unlocked.\n */\n locked?(context: CommandContext<AppState>): SettingLock | null;\n\n // ── what the command opens ───────────────────────────────────────────────\n // A command that opens a panel, menu or dialog says so instead of opening\n // it in `run`: it then needs no `run`, it shows as active while the surface\n // is open, and a button can show that it opens a menu.\n /** Opens and closes a menu of yours, by its id. */\n readonly menu?: string;\n /**\n * Opens and closes a panel, closing the others with the same `exclusive` tag. With `focus`,\n * opening it asks for the cursor (the shell's `open(id, { focus: true })`).\n */\n readonly panel?:\n | string\n | { readonly id: string; readonly exclusive?: string; readonly focus?: boolean };\n /** Opens and closes a dialog; one dialog is open at a time. */\n readonly modal?: string;\n\n // ── read from live state and your app's, again whenever either changes ──\n /** When it can run. Default: always. One that throws counts as false. */\n enabled?(context: CommandContext<AppState>): boolean;\n /** When it shows as pressed, such as the current tool. One that throws counts as false. */\n active?(context: CommandContext<AppState>): boolean;\n /** When it shows at all. Default: always. One that throws counts as false. */\n visible?(context: CommandContext<AppState>): boolean;\n\n /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */\n run?(context: CommandContext<AppState>): void | Promise<unknown>;\n}\n\n/**\n * A command for each of a set of names, made from one definition, such as `tool:<id>` for every\n * tool a document has. Its commands resolve and run like any other, and `listCommands()` lists\n * one per name. A command defined with the same id wins over the family's.\n */\nexport interface CommandFamily {\n /** Where the commands' ids start: `'tool:'` makes `tool:highlight`. */\n readonly prefix: string;\n /** The names the command's document has, in order. Return the same array while nothing changed. */\n readonly names: (context: CommandContext) => readonly string[];\n /** The command for one name. A family's commands have no shortcuts. */\n readonly command: (name: string) => Omit<CommandDef, 'id' | 'shortcut'>;\n}\n\n/** A command as a button shows it: everything read for its 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 * Why it's disabled, as a sentence for its tooltip: set when the scope doesn't allow it and\n * the `notAllowed` setting is `'disable'`, or when a lock holds the setting it changes.\n */\n readonly disabledReason?: string;\n}\n\n/**\n * Why a command won't run whatever the moment: it's turned off in this viewer\n * (`disabledCategories`, `disabledCommands`), the scope doesn't allow it (`requires`), or a lock\n * holds the setting it changes (`locked`). A command that only can't run right now (`enabled`,\n * `visible`) has no refusal.\n */\nexport interface CommandRefusal {\n readonly reason: 'turned-off' | 'not-allowed' | 'locked';\n /** A sentence for the user, translated through the i18n plugin when it's there. */\n readonly message: string;\n}\n\n/**\n * Whether two resolved commands show the same, for readers that compare what a command looks\n * like rather than which object holds it (a group of commands, or one command for two documents).\n */\nexport const resolvedCommandsEqual = (\n left: ResolvedCommand | null,\n right: ResolvedCommand | null,\n): boolean => {\n if (left === right) return true;\n if (!left || !right) return false;\n return (\n left.id === right.id &&\n left.label === right.label &&\n left.icon === right.icon &&\n left.iconAccent?.primary === right.iconAccent?.primary &&\n left.iconAccent?.secondary === right.iconAccent?.secondary &&\n left.menu === right.menu &&\n left.enabled === right.enabled &&\n left.active === right.active &&\n left.visible === right.visible &&\n left.disabledReason === right.disabledReason &&\n left.shortcuts.length === right.shortcuts.length &&\n left.shortcuts.every((shortcut, index) => shortcut === right.shortcuts[index])\n );\n};\n\n/**\n * What a component or a toolbar draws for a command id no plugin registered: labelled with its\n * id, neither enabled nor visible, the way a turned-off command is.\n */\nexport const unregisteredCommand = (id: CommandId): ResolvedCommand => ({\n id,\n label: id,\n shortcuts: [],\n enabled: false,\n active: false,\n visible: false,\n categories: [],\n});\n\n/** What a component that asks for an id no plugin registered hears, in development. */\nexport const unknownCommandWarning = (id: CommandId, known: Iterable<CommandId>): string =>\n `no command \"${id}\"${didYouMean(id, known)}: it shows as neither visible nor enabled`;\n\n/** A command with everything a button needs: what it shows, `run`, and its shortcut for a tooltip. */\nexport interface BoundCommand extends ResolvedCommand {\n /** Run the command for the document it was read for. */\n readonly run: () => Promise<ExecuteResult>;\n /** Its first shortcut, formatted for the platform (`'⌘K'` on a Mac, `'Ctrl+K'` elsewhere), or `null`. */\n readonly shortcut: string | null;\n}\n\n/**\n * A resolved command, bound for a button: `run` executes it through `execute`, and `shortcut` is\n * its first shortcut formatted for the platform. Which platform is the caller's to know\n * (`isMacPlatform()` in `@embedpdf/web`).\n */\nexport function boundCommandOf(\n command: ResolvedCommand,\n execute: (id: CommandId) => Promise<ExecuteResult>,\n options: { readonly isMac: boolean },\n): BoundCommand {\n const [first] = command.shortcuts;\n return {\n ...command,\n run: () => execute(command.id),\n shortcut: first === undefined ? null : formatShortcut(first, { isMac: options.isMac }),\n };\n}\n\n/**\n * The commands plugin's settings. `commandsPlugin(config)` registers them over\n * {@link COMMANDS_DEFAULTS}, and `updateSettings()` changes them while the app runs.\n */\nexport interface CommandsSettings {\n /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */\n readonly commands: readonly (CommandDef | CommandFamily)[];\n /**\n * Your app's state, which every command's functions get as `appState`: values, and functions\n * that change them. A new value replaces the old one whole, and every command is asked again.\n */\n readonly appState: unknown;\n /**\n * Categories turned off, with every category under them: their commands are hidden and\n * refused wherever they appear.\n */\n readonly disabledCategories: readonly string[];\n /** Commands turned off one by one, by id: hidden and refused wherever they appear. */\n readonly disabledCommands: readonly CommandId[];\n /**\n * What a command the scope doesn't allow does: `'hide'` leaves it out, `'disable'` shows it\n * disabled, with the reason in its `disabledReason`.\n */\n readonly notAllowed: NotAllowedMode;\n}\n\n/** How a command shows when the scope doesn't allow it: hidden, or disabled with its reason. */\nexport type NotAllowedMode = 'hide' | 'disable';\n\n/** What the commands settings are when the app registers none. */\nexport const COMMANDS_DEFAULTS: CommandsSettings = {\n commands: [],\n appState: undefined,\n disabledCategories: [],\n disabledCommands: [],\n notAllowed: 'hide',\n};\n\n/** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type CommandsConfig<AppState = any> = Omit<\n DeepPartial<CommandsSettings>,\n 'commands' | 'appState'\n> & {\n readonly commands?: readonly (CommandDef<AppState> | CommandFamily)[];\n readonly appState?: AppState;\n};\n\nexport interface RegisterCommandOptions {\n /** Replace a command with the same id; without it, a taken id throws `conflict`. */\n replace?: boolean;\n}\n\nexport interface ExecuteOptions extends OperationOptions {\n /** The document to run it for; the document in scope, else the active one, when left out. */\n documentId?: string;\n /** Passed to the command's `run` and derivations as `args`. */\n args?: unknown;\n}\n\n/** How `execute()` went: it ran, or it was refused before running, and why. */\nexport type ExecuteResult =\n | { readonly status: 'executed' }\n | { readonly status: 'rejected'; readonly reason: 'not-found' | 'disabled' | 'hidden' };\n\n// ── events ──\nexport interface CommandExecutedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly args: unknown;\n}\nexport interface CommandExecutionFailedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly error: PluginErrorInfo;\n}\n\n/**\n * The commands. A call that leaves out the document is for the document in scope when the\n * capability was resolved for one (`ctx.forDocument`, a `<DocumentScope>`), and for the active\n * document otherwise.\n */\nexport interface CommandsCapability extends SettingsApi<CommandsSettings> {\n // ── the commands ──\n /**\n * Add a command while the app runs, and get a function that removes it. A taken id throws\n * `conflict` unless `replace`.\n */\n registerCommand(definition: CommandDef, options?: RegisterCommandOptions): Unsubscribe;\n /** `registerCommand` for several definitions; the function removes all of them. */\n registerCommands(\n definitions: readonly CommandDef[],\n options?: RegisterCommandOptions,\n ): Unsubscribe;\n /** Whether a command has this id; with a family, every id that starts with its prefix does. */\n hasCommand(id: CommandId): boolean;\n /** A command as you defined it, or `null`. */\n getCommand(id: CommandId): CommandDef | null;\n /** Every command's id for the active document, in the order they were added. The same array until one changes. */\n listCommandIds(): readonly CommandId[];\n\n // ── what a button shows ──\n /** A command as a button shows it, or `null` for an unknown id. The same object while nothing about it changed. */\n resolveCommand(id: CommandId, documentId?: string): ResolvedCommand | null;\n /** Every command, resolved, in the order they were added. The same array while nothing changed. */\n listCommands(documentId?: string): readonly ResolvedCommand[];\n /** The visible commands whose label or id contains the query, for a command palette. */\n searchCommands(query: string, documentId?: string): readonly ResolvedCommand[];\n /** Every shortcut with its command, for a keyboard help sheet. The same array until the commands change. */\n listShortcuts(): readonly { readonly commandId: CommandId; readonly shortcut: string }[];\n\n // ── running them ──\n /**\n * Run a command; resolves once its `run` has, with `{ status: 'executed' }` and\n * `onExecuted`, or `{ status: 'rejected', reason }` for a command that is unknown, hidden or\n * disabled (a command turned off is hidden). A `run` that throws fires `onExecutionFailed` and rejects with its `PluginError`;\n * the signal rejects `operation-cancelled`.\n */\n execute(id: CommandId, options?: ExecuteOptions): Promise<ExecuteResult>;\n /** Whether a command can run now: it exists, and is enabled and visible. */\n canExecute(id: CommandId, documentId?: string): boolean;\n /**\n * Why a command won't run whatever the moment: it's turned off, or not allowed for its\n * document. `null` when it may run (or only can't right now), and for an unknown id.\n */\n getRefusal(id: CommandId, documentId?: string): CommandRefusal | null;\n\n // ── turning commands off ──\n /** The categories turned off. */\n getDisabledCategories(): readonly string[];\n /** Whether a category is turned off: it, or a category it's under (`annotations` for `annotations.highlight`). */\n isCategoryDisabled(category: string): boolean;\n /** Turn a category off, with every category under it: the `disabledCategories` setting gains it. */\n disableCategory(category: string): void;\n /** Turn a category on again. */\n enableCategory(category: string): void;\n /** Replace the categories that are off. */\n setDisabledCategories(categories: readonly string[]): void;\n /** The commands turned off one by one. */\n getDisabledCommands(): readonly CommandId[];\n /** Whether a command is turned off: by its id, or through one of its categories. */\n isCommandDisabled(id: CommandId): boolean;\n /** Turn one command off: the `disabledCommands` setting gains it. */\n disableCommand(id: CommandId): void;\n /** Turn a command on again; it stays off while one of its categories is. */\n enableCommand(id: CommandId): void;\n /** Replace the commands that are off one by one. */\n setDisabledCommands(ids: readonly CommandId[]): void;\n\n // ── events ──\n /** A command ran. */\n readonly onExecuted: EventHook<CommandExecutedEvent>;\n /** A command's `run` threw; `execute` rejects with the same error. */\n readonly onExecutionFailed: EventHook<CommandExecutionFailedEvent>;\n}\n"],"mappings":";;;;;AAMA,MAAa,iBAAA,GAAA,eAAA,sBAAA,CAA0D,YAAY,EACjF,MAAM,6EACR,CAAC;;;;;;;AC0LD,MAAa,yBACX,MACA,UACY;CACZ,IAAI,SAAS,OAAO,OAAO;CAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO,OAAO;CAC5B,OACE,KAAK,OAAO,MAAM,MAClB,KAAK,UAAU,MAAM,SACrB,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,YAAY,MAAM,YAAY,WAC/C,KAAK,YAAY,cAAc,MAAM,YAAY,aACjD,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,MAAM,WACvB,KAAK,WAAW,MAAM,UACtB,KAAK,YAAY,MAAM,WACvB,KAAK,mBAAmB,MAAM,kBAC9B,KAAK,UAAU,WAAW,MAAM,UAAU,UAC1C,KAAK,UAAU,OAAO,UAAU,UAAU,aAAa,MAAM,UAAU,MAAM;AAEjF;;;;;AAMA,MAAa,uBAAuB,QAAoC;CACtE;CACA,OAAO;CACP,WAAW,CAAC;CACZ,SAAS;CACT,QAAQ;CACR,SAAS;CACT,YAAY,CAAC;AACf;;AAGA,MAAa,yBAAyB,IAAe,UACnD,eAAe,GAAG,IAAA,GAAA,kBAAA,WAAA,CAAc,IAAI,KAAK,EAAE;;;;;;AAe7C,SAAgB,eACd,SACA,SACA,SACc;CACd,MAAM,CAAC,SAAS,QAAQ;CACxB,OAAO;EACL,GAAG;EACH,WAAW,QAAQ,QAAQ,EAAE;EAC7B,UAAU,UAAU,KAAA,IAAY,QAAA,GAAA,kBAAA,eAAA,CAAsB,OAAO,EAAE,OAAO,QAAQ,MAAM,CAAC;CACvF;AACF;;AAgCA,MAAa,oBAAsC;CACjD,UAAU,CAAC;CACX,UAAU,KAAA;CACV,oBAAoB,CAAC;CACrB,kBAAkB,CAAC;CACnB,YAAY;AACd"}
package/dist/contract.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("./contract-BlOznyrj.cjs");
2
+ const require_contract = require("./contract-sqmSSPlP.cjs");
3
3
  exports.COMMANDS_DEFAULTS = require_contract.COMMANDS_DEFAULTS;
4
4
  exports.CommandsToken = require_contract.CommandsToken;
5
5
  exports.boundCommandOf = require_contract.boundCommandOf;
@@ -1,2 +1,2 @@
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 CommandDef, 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-DAV5VR3P.cjs";
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 CommandDef, 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-lGfvyWMG.cjs";
2
2
  export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,2 +1,2 @@
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 CommandDef, 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-DAV5VR3P.js";
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 CommandDef, 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-lGfvyWMG.js";
2
2
  export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
package/dist/contract.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "./contract-Cj5BTtO7.js";
1
+ import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "./contract-FbiUhTWC.js";
2
2
  export { COMMANDS_DEFAULTS, CommandsToken, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,4 +1,4 @@
1
- import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-DAV5VR3P.js";
1
+ import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-lGfvyWMG.js";
2
2
  import { KeyStroke } from "@embedpdf/core-ui";
3
3
  //#region src/host-contract.d.ts
4
4
  /** The command a keystroke's shortcut names, and why it won't run when it's refused. */
@@ -26,4 +26,4 @@ interface CommandsHostCapability extends CommandsCapability {
26
26
  declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsHostCapability>;
27
27
  //#endregion
28
28
  export { CommandsToken as n, ShortcutMatch as r, CommandsHostCapability as t };
29
- //# sourceMappingURL=host-contract-DkuusR8r.d.ts.map
29
+ //# sourceMappingURL=host-contract-Cekzl4U8.d.ts.map
@@ -1,4 +1,4 @@
1
- import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-DAV5VR3P.cjs";
1
+ import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-lGfvyWMG.cjs";
2
2
  import { KeyStroke } from "@embedpdf/core-ui";
3
3
  //#region src/host-contract.d.ts
4
4
  /** The command a keystroke's shortcut names, and why it won't run when it's refused. */
@@ -26,4 +26,4 @@ interface CommandsHostCapability extends CommandsCapability {
26
26
  declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsHostCapability>;
27
27
  //#endregion
28
28
  export { CommandsToken as n, ShortcutMatch as r, CommandsHostCapability as t };
29
- //# sourceMappingURL=host-contract-Cqz-V6kP.d.cts.map
29
+ //# sourceMappingURL=host-contract-DmzPrsSX.d.cts.map