@embedpdf/plugin-commands 3.0.0-next.13 → 3.0.0-next.15
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-BlOznyrj.cjs +91 -0
- package/dist/contract-BlOznyrj.cjs.map +1 -0
- package/dist/contract-Cj5BTtO7.js +56 -0
- package/dist/contract-Cj5BTtO7.js.map +1 -0
- package/dist/contract-DAV5VR3P.d.cts +295 -0
- package/dist/contract-DAV5VR3P.d.ts +295 -0
- package/dist/contract.cjs +5 -1
- package/dist/contract.d.cts +2 -2
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/host-contract-Cqz-V6kP.d.cts +29 -0
- package/dist/host-contract-DkuusR8r.d.ts +29 -0
- package/dist/index.cjs +463 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -11
- package/dist/index.d.ts +9 -11
- package/dist/index.js +461 -130
- package/dist/index.js.map +1 -1
- package/dist/standard.cjs +243 -0
- package/dist/standard.cjs.map +1 -0
- package/dist/standard.d.cts +17 -0
- package/dist/standard.d.ts +17 -0
- package/dist/standard.js +242 -0
- package/dist/standard.js.map +1 -0
- package/package.json +19 -6
- package/dist/contract-CSIfF6wC.d.cts +0 -137
- package/dist/contract-CSIfF6wC.d.ts +0 -137
- package/dist/contract-DYlaVyVk.cjs +0 -25
- package/dist/contract-DYlaVyVk.cjs.map +0 -1
- package/dist/contract-UFgXphIQ.js +0 -14
- package/dist/contract-UFgXphIQ.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contract-UFgXphIQ.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["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"],"mappings":";;;;AAsGA,MAAa,yBACX,GACA,MACY;CACZ,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO;CACrB,OACE,EAAE,OAAO,EAAE,MACX,EAAE,UAAU,EAAE,SACd,EAAE,SAAS,EAAE,QAEb,EAAE,YAAY,YAAY,EAAE,YAAY,WACxC,EAAE,YAAY,cAAc,EAAE,YAAY,aAC1C,EAAE,SAAS,EAAE,QACb,EAAE,YAAY,EAAE,WAChB,EAAE,WAAW,EAAE,UACf,EAAE,YAAY,EAAE,WAChB,EAAE,UAAU,WAAW,EAAE,UAAU,UACnC,EAAE,UAAU,OAAO,GAAG,MAAM,MAAM,EAAE,UAAU,EAAE;AAEpD;AA6CA,MAAa,gBAAgB,sBAA0C,UAAU"}
|