@lushly-dev/fast-element 3.0.1-preview.0 → 3.0.1-preview.1

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.
Files changed (250) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/command/command.api.json +7857 -0
  3. package/dist/context/context.api.json +1084 -0
  4. package/dist/declarative/declarative.api.json +8130 -0
  5. package/dist/definition-schema/definition-schema.api.json +2689 -0
  6. package/dist/di/di.api.json +4945 -0
  7. package/dist/dts/arrays.d.ts +2 -0
  8. package/dist/dts/binding/binding.d.ts +59 -0
  9. package/dist/dts/binding/exports.d.ts +9 -0
  10. package/dist/dts/binding/normalize.d.ts +9 -0
  11. package/dist/dts/binding/one-time.d.ts +11 -0
  12. package/dist/dts/binding/one-way.d.ts +20 -0
  13. package/dist/dts/binding/signal.d.ts +36 -0
  14. package/dist/dts/binding/two-way.d.ts +44 -0
  15. package/dist/dts/command/behavior.d.ts +94 -0
  16. package/dist/dts/command/behaviors/confirm-behavior.d.ts +139 -0
  17. package/dist/dts/command/behaviors/undo-behavior.d.ts +178 -0
  18. package/dist/dts/command/command.d.ts +79 -0
  19. package/dist/dts/command/component-registry.d.ts +50 -0
  20. package/dist/dts/command/components/confirm-dialog.d.ts +117 -0
  21. package/dist/dts/command/index.d.ts +21 -0
  22. package/dist/dts/command/registry.d.ts +201 -0
  23. package/dist/dts/command/schema-validation.d.ts +45 -0
  24. package/dist/dts/command/types.d.ts +332 -0
  25. package/dist/dts/command/validation.d.ts +116 -0
  26. package/dist/dts/command/weak-ref.d.ts +11 -0
  27. package/dist/dts/components/attributes.d.ts +153 -0
  28. package/dist/dts/components/definition-schema-transforms.d.ts +9 -0
  29. package/dist/dts/components/element-controller.d.ts +349 -0
  30. package/dist/dts/components/element-hydration.d.ts +2 -0
  31. package/dist/dts/components/enable-hydration.d.ts +66 -0
  32. package/dist/dts/components/fast-definitions.d.ts +211 -0
  33. package/dist/dts/components/fast-element-registry.d.ts +23 -0
  34. package/dist/dts/components/fast-element.d.ts +91 -0
  35. package/dist/dts/components/hydration-tracker.d.ts +110 -0
  36. package/dist/dts/components/hydration.d.ts +52 -0
  37. package/dist/dts/components/schema.d.ts +205 -0
  38. package/dist/dts/context.d.ts +171 -0
  39. package/dist/dts/debug.d.ts +5 -0
  40. package/dist/dts/declarative/attribute-map.d.ts +58 -0
  41. package/dist/dts/declarative/debug.d.ts +4 -0
  42. package/dist/dts/declarative/index.d.ts +14 -0
  43. package/dist/dts/declarative/interfaces.d.ts +8 -0
  44. package/dist/dts/declarative/observer-map-utilities.d.ts +58 -0
  45. package/dist/dts/declarative/observer-map.d.ts +89 -0
  46. package/dist/dts/declarative/runtime.d.ts +5 -0
  47. package/dist/dts/declarative/syntax.d.ts +21 -0
  48. package/dist/dts/declarative/template-bridge.d.ts +33 -0
  49. package/dist/dts/declarative/template-parser.d.ts +98 -0
  50. package/dist/dts/declarative/template.d.ts +9 -0
  51. package/dist/dts/declarative/utilities.d.ts +358 -0
  52. package/dist/dts/definition-schema/api.d.ts +42 -0
  53. package/dist/dts/definition-schema/cem.d.ts +78 -0
  54. package/dist/dts/definition-schema/extension.d.ts +18 -0
  55. package/dist/dts/definition-schema/extract.d.ts +38 -0
  56. package/dist/dts/definition-schema/index.d.ts +9 -0
  57. package/dist/dts/definition-schema/storage.d.ts +35 -0
  58. package/dist/dts/definition-schema/types.d.ts +176 -0
  59. package/dist/dts/dev-mode.d.ts +13 -0
  60. package/dist/dts/di/di.d.ts +894 -0
  61. package/dist/dts/dom-policy.d.ts +101 -0
  62. package/dist/dts/dom.d.ts +88 -0
  63. package/dist/dts/hydration/diagnostics.d.ts +93 -0
  64. package/dist/dts/hydration/exports.d.ts +18 -0
  65. package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
  66. package/dist/dts/hydration/messages.d.ts +62 -0
  67. package/dist/dts/hydration/runtime.d.ts +7 -0
  68. package/dist/dts/hydration/target-builder.d.ts +107 -0
  69. package/dist/dts/index.d.ts +51 -0
  70. package/dist/dts/index.debug.d.ts +1 -0
  71. package/dist/dts/index.rollup.d.ts +1 -0
  72. package/dist/dts/index.rollup.debug.d.ts +1 -0
  73. package/dist/dts/interfaces.d.ts +106 -0
  74. package/dist/dts/metadata.d.ts +26 -0
  75. package/dist/dts/observation/arrays.d.ts +248 -0
  76. package/dist/dts/observation/notifier.d.ts +127 -0
  77. package/dist/dts/observation/observable.d.ts +276 -0
  78. package/dist/dts/observation/update-queue.d.ts +40 -0
  79. package/dist/dts/observation/volatile.d.ts +9 -0
  80. package/dist/dts/platform.d.ts +87 -0
  81. package/dist/dts/registry.d.ts +2 -0
  82. package/dist/dts/render.d.ts +7 -0
  83. package/dist/dts/schema.d.ts +1 -0
  84. package/dist/dts/scoped/detection.d.ts +55 -0
  85. package/dist/dts/scoped/index.d.ts +68 -0
  86. package/dist/dts/scoped/mixin.d.ts +118 -0
  87. package/dist/dts/scoped/registry.d.ts +76 -0
  88. package/dist/dts/scoped/types.d.ts +48 -0
  89. package/dist/dts/state/exports.d.ts +3 -0
  90. package/dist/dts/state/reactive.d.ts +8 -0
  91. package/dist/dts/state/state.d.ts +141 -0
  92. package/dist/dts/state/visitor.d.ts +6 -0
  93. package/dist/dts/state/watch.d.ts +10 -0
  94. package/dist/dts/styles/css-directive.d.ts +50 -0
  95. package/dist/dts/styles/css.d.ts +34 -0
  96. package/dist/dts/styles/element-styles.d.ts +61 -0
  97. package/dist/dts/styles/host.d.ts +65 -0
  98. package/dist/dts/styles/style-strategy.d.ts +42 -0
  99. package/dist/dts/templating/children.d.ts +62 -0
  100. package/dist/dts/templating/compiler.d.ts +54 -0
  101. package/dist/dts/templating/html-binding-directive.d.ts +155 -0
  102. package/dist/dts/templating/html-directive.d.ts +218 -0
  103. package/dist/dts/templating/html.d.ts +1 -0
  104. package/dist/dts/templating/hydration-view.d.ts +130 -0
  105. package/dist/dts/templating/markup.d.ts +48 -0
  106. package/dist/dts/templating/node-observation.d.ts +99 -0
  107. package/dist/dts/templating/ref.d.ts +23 -0
  108. package/dist/dts/templating/render.d.ts +318 -0
  109. package/dist/dts/templating/repeat.d.ts +131 -0
  110. package/dist/dts/templating/slotted.d.ts +38 -0
  111. package/dist/dts/templating/template.d.ts +221 -0
  112. package/dist/dts/templating/view.d.ts +268 -0
  113. package/dist/dts/templating/when.d.ts +12 -0
  114. package/dist/dts/testing/exports.d.ts +3 -0
  115. package/dist/dts/testing/fakes.d.ts +15 -0
  116. package/dist/dts/testing/fixture.d.ts +84 -0
  117. package/dist/dts/testing/models.d.ts +20 -0
  118. package/dist/dts/testing/timeout.d.ts +7 -0
  119. package/dist/dts/trust/index.d.ts +8 -0
  120. package/dist/dts/trust/types.d.ts +48 -0
  121. package/dist/dts/trust/utils.d.ts +26 -0
  122. package/dist/dts/tsdoc-metadata.json +11 -0
  123. package/dist/dts/utilities.d.ts +76 -0
  124. package/dist/esm/arrays.js +1 -0
  125. package/dist/esm/binding/binding.js +18 -0
  126. package/dist/esm/binding/exports.js +6 -0
  127. package/dist/esm/binding/normalize.js +17 -0
  128. package/dist/esm/binding/one-time.js +21 -0
  129. package/dist/esm/binding/one-way.js +30 -0
  130. package/dist/esm/binding/signal.js +99 -0
  131. package/dist/esm/binding/two-way.js +110 -0
  132. package/dist/esm/command/behavior.js +155 -0
  133. package/dist/esm/command/behaviors/confirm-behavior.js +225 -0
  134. package/dist/esm/command/behaviors/undo-behavior.js +312 -0
  135. package/dist/esm/command/command.js +104 -0
  136. package/dist/esm/command/component-registry.js +107 -0
  137. package/dist/esm/command/components/confirm-dialog.js +370 -0
  138. package/dist/esm/command/index.js +22 -0
  139. package/dist/esm/command/registry.js +752 -0
  140. package/dist/esm/command/schema-validation.js +194 -0
  141. package/dist/esm/command/types.js +86 -0
  142. package/dist/esm/command/validation.js +511 -0
  143. package/dist/esm/command/weak-ref.js +5 -0
  144. package/dist/esm/components/attributes.js +219 -0
  145. package/dist/esm/components/definition-schema-transforms.js +23 -0
  146. package/dist/esm/components/element-controller.js +839 -0
  147. package/dist/esm/components/element-hydration.js +2 -0
  148. package/dist/esm/components/enable-hydration.js +123 -0
  149. package/dist/esm/components/fast-definitions.js +294 -0
  150. package/dist/esm/components/fast-element-registry.js +67 -0
  151. package/dist/esm/components/fast-element.js +82 -0
  152. package/dist/esm/components/hydration-tracker.js +210 -0
  153. package/dist/esm/components/hydration.js +187 -0
  154. package/dist/esm/components/schema.js +253 -0
  155. package/dist/esm/context.js +185 -0
  156. package/dist/esm/debug.js +71 -0
  157. package/dist/esm/declarative/attribute-map.js +121 -0
  158. package/dist/esm/declarative/debug.js +4 -0
  159. package/dist/esm/declarative/index.js +10 -0
  160. package/dist/esm/declarative/interfaces.js +9 -0
  161. package/dist/esm/declarative/observer-map-utilities.js +565 -0
  162. package/dist/esm/declarative/observer-map.js +216 -0
  163. package/dist/esm/declarative/runtime.js +14 -0
  164. package/dist/esm/declarative/syntax.js +36 -0
  165. package/dist/esm/declarative/template-bridge.js +160 -0
  166. package/dist/esm/declarative/template-parser.js +306 -0
  167. package/dist/esm/declarative/template.js +116 -0
  168. package/dist/esm/declarative/utilities.js +1069 -0
  169. package/dist/esm/definition-schema/api.js +129 -0
  170. package/dist/esm/definition-schema/cem.js +89 -0
  171. package/dist/esm/definition-schema/extension.js +53 -0
  172. package/dist/esm/definition-schema/extract.js +167 -0
  173. package/dist/esm/definition-schema/index.js +8 -0
  174. package/dist/esm/definition-schema/storage.js +58 -0
  175. package/dist/esm/definition-schema/types.js +8 -0
  176. package/dist/esm/dev-mode.js +22 -0
  177. package/dist/esm/di/di.js +1440 -0
  178. package/dist/esm/dom-policy.js +374 -0
  179. package/dist/esm/dom.js +101 -0
  180. package/dist/esm/hydration/diagnostics.js +50 -0
  181. package/dist/esm/hydration/exports.js +6 -0
  182. package/dist/esm/hydration/hydration-debugger.js +112 -0
  183. package/dist/esm/hydration/messages.js +84 -0
  184. package/dist/esm/hydration/runtime.js +33 -0
  185. package/dist/esm/hydration/target-builder.js +264 -0
  186. package/dist/esm/index.debug.js +3 -0
  187. package/dist/esm/index.js +49 -0
  188. package/dist/esm/index.rollup.debug.js +6 -0
  189. package/dist/esm/index.rollup.js +4 -0
  190. package/dist/esm/interfaces.js +55 -0
  191. package/dist/esm/metadata.js +63 -0
  192. package/dist/esm/observation/arrays.js +661 -0
  193. package/dist/esm/observation/notifier.js +164 -0
  194. package/dist/esm/observation/observable.js +324 -0
  195. package/dist/esm/observation/update-queue.js +56 -0
  196. package/dist/esm/observation/volatile.js +16 -0
  197. package/dist/esm/platform.js +98 -0
  198. package/dist/esm/registry.js +2 -0
  199. package/dist/esm/render.js +1 -0
  200. package/dist/esm/schema.js +1 -0
  201. package/dist/esm/scoped/detection.js +102 -0
  202. package/dist/esm/scoped/index.js +69 -0
  203. package/dist/esm/scoped/mixin.js +127 -0
  204. package/dist/esm/scoped/registry.js +125 -0
  205. package/dist/esm/scoped/types.js +4 -0
  206. package/dist/esm/state/exports.js +3 -0
  207. package/dist/esm/state/reactive.js +34 -0
  208. package/dist/esm/state/state.js +148 -0
  209. package/dist/esm/state/visitor.js +28 -0
  210. package/dist/esm/state/watch.js +36 -0
  211. package/dist/esm/styles/css-directive.js +36 -0
  212. package/dist/esm/styles/css.js +56 -0
  213. package/dist/esm/styles/element-styles.js +144 -0
  214. package/dist/esm/styles/host.js +1 -0
  215. package/dist/esm/styles/style-strategy.js +1 -0
  216. package/dist/esm/templating/children.js +67 -0
  217. package/dist/esm/templating/compiler.js +359 -0
  218. package/dist/esm/templating/html-binding-directive.js +288 -0
  219. package/dist/esm/templating/html-directive.js +113 -0
  220. package/dist/esm/templating/html.js +1 -0
  221. package/dist/esm/templating/hydration-view.js +228 -0
  222. package/dist/esm/templating/markup.js +83 -0
  223. package/dist/esm/templating/node-observation.js +84 -0
  224. package/dist/esm/templating/ref.js +21 -0
  225. package/dist/esm/templating/render.js +468 -0
  226. package/dist/esm/templating/repeat.js +434 -0
  227. package/dist/esm/templating/slotted.js +49 -0
  228. package/dist/esm/templating/template.js +206 -0
  229. package/dist/esm/templating/view.js +298 -0
  230. package/dist/esm/templating/when.js +22 -0
  231. package/dist/esm/testing/exports.js +3 -0
  232. package/dist/esm/testing/fakes.js +107 -0
  233. package/dist/esm/testing/fixture.js +86 -0
  234. package/dist/esm/testing/models.js +58 -0
  235. package/dist/esm/testing/timeout.js +24 -0
  236. package/dist/esm/trust/index.js +7 -0
  237. package/dist/esm/trust/types.js +6 -0
  238. package/dist/esm/trust/utils.js +126 -0
  239. package/dist/esm/utilities.js +140 -0
  240. package/dist/fast-element.api.json +26798 -0
  241. package/dist/fast-element.d.ts +3985 -0
  242. package/dist/fast-element.debug.js +7618 -0
  243. package/dist/fast-element.debug.min.js +3 -0
  244. package/dist/fast-element.js +7617 -0
  245. package/dist/fast-element.min.js +3 -0
  246. package/dist/fast-element.untrimmed.d.ts +4103 -0
  247. package/dist/observation/arrays/arrays.api.json +2621 -0
  248. package/dist/scoped/scoped.api.json +891 -0
  249. package/dist/trust/trust.api.json +629 -0
  250. package/package.json +12 -12
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Component introspection commands for FAST elements.
3
+ * Pure runtime introspection - no Creator dependencies.
4
+ *
5
+ * @remarks
6
+ * These commands expose FAST component metadata to AI agents and command palettes.
7
+ * Task 9 will add fast.component.getAPI to this file.
8
+ */
9
+ import type { ComponentSchema } from "../definition-schema/types.js";
10
+ /**
11
+ * Component list result item.
12
+ * @public
13
+ */
14
+ export interface ComponentInfo {
15
+ /** The custom element tag name */
16
+ name: string;
17
+ /** The constructor function name */
18
+ constructor: string;
19
+ /** Whether the element is defined in the platform registry */
20
+ isDefined: boolean;
21
+ }
22
+ /**
23
+ * Component API result from fast.component.getAPI.
24
+ * @public
25
+ */
26
+ export interface ComponentAPIInfo {
27
+ /** The custom element tag name */
28
+ name: string;
29
+ /** Properties exposed by the component */
30
+ properties: ComponentSchema["properties"];
31
+ /** Events emitted by the component */
32
+ events: ComponentSchema["events"];
33
+ /** Slots available in the component */
34
+ slots: ComponentSchema["slots"];
35
+ /** CSS custom properties (design tokens) */
36
+ cssProperties: ComponentSchema["cssProperties"];
37
+ /** Commands exposed by the component */
38
+ commands?: ComponentSchema["commands"];
39
+ }
40
+ /**
41
+ * Register fast.component.* commands with the CommandRegistry.
42
+ * Called during fast-element initialization.
43
+ *
44
+ * @remarks
45
+ * These commands provide runtime introspection of registered FAST elements.
46
+ * They have no dependencies on Creator or design-to-code packages.
47
+ *
48
+ * @public
49
+ */
50
+ export declare function registerComponentCommands(): void;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * ConfirmDialog component for command safety confirmations.
3
+ * Modal dialog for confirming destructive actions.
4
+ *
5
+ * @remarks
6
+ * Provides an accessible modal dialog with:
7
+ * - open/prompt attributes for state management
8
+ * - confirm/cancel events for user response
9
+ * - Full ARIA support (role, aria-modal, aria-labelledby, aria-describedby)
10
+ * - Focus trap to keep keyboard navigation within dialog
11
+ * - Escape key to cancel
12
+ *
13
+ * @example
14
+ * ```html
15
+ * <fast-af-confirm-dialog
16
+ * open
17
+ * prompt="Are you sure you want to delete this item?"
18
+ * @confirm=${handleConfirm}
19
+ * @cancel=${handleCancel}
20
+ * ></fast-af-confirm-dialog>
21
+ * ```
22
+ */
23
+ import { FASTElement } from "../../components/fast-element.js";
24
+ /**
25
+ * A modal dialog component for confirming destructive actions.
26
+ *
27
+ * Events: `confirm` is dispatched when the user confirms; `cancel` is dispatched
28
+ * when the user cancels, presses Escape, or clicks the overlay.
29
+ *
30
+ * Slots: the default slot supplies additional content; `title`, `cancel-text`, and
31
+ * `confirm-text` replace their corresponding labels.
32
+ *
33
+ * CSS parts: `overlay`, `dialog`, `title`, `prompt`, `actions`, `cancel-button`, and
34
+ * `confirm-button`.
35
+ *
36
+ * @internal
37
+ */
38
+ export declare class ConfirmDialog extends FASTElement {
39
+ /**
40
+ * Whether the dialog is open/visible.
41
+ * @public
42
+ */
43
+ open: boolean;
44
+ /**
45
+ * The prompt message to display in the dialog.
46
+ * @public
47
+ */
48
+ prompt: string;
49
+ /**
50
+ * Reference to the previously focused element for restoring focus on close.
51
+ * @internal
52
+ */
53
+ private previouslyFocused;
54
+ /**
55
+ * List of focusable elements within the dialog for focus trapping.
56
+ * @internal
57
+ */
58
+ private focusableElements;
59
+ /**
60
+ * Called when the open attribute changes.
61
+ * Manages focus trap and body scroll lock.
62
+ * @param oldValue - Previous value
63
+ * @param newValue - New value
64
+ */
65
+ openChanged(oldValue: boolean, newValue: boolean): void;
66
+ /**
67
+ * Sets up focus trap within the dialog.
68
+ * @internal
69
+ */
70
+ private trapFocus;
71
+ /**
72
+ * Handles keydown events for focus trap and escape key.
73
+ * @param event - The keyboard event
74
+ * @internal
75
+ */
76
+ handleKeydown(event: KeyboardEvent): void;
77
+ /**
78
+ * Handles tab key for focus trapping.
79
+ * @param event - The keyboard event
80
+ * @internal
81
+ */
82
+ private handleTabKey;
83
+ /**
84
+ * Handles overlay click to cancel.
85
+ * @param event - The mouse event
86
+ * @internal
87
+ */
88
+ handleOverlayClick(event: MouseEvent): void;
89
+ /**
90
+ * Handles confirm button click.
91
+ * Emits 'confirm' event and closes the dialog.
92
+ * @public
93
+ */
94
+ handleConfirm(): void;
95
+ /**
96
+ * Handles cancel button click.
97
+ * Emits 'cancel' event and closes the dialog.
98
+ * @public
99
+ */
100
+ handleCancel(): void;
101
+ }
102
+ /**
103
+ * The namespaced tag used by the opt-in confirmation dialog.
104
+ * @public
105
+ */
106
+ export declare const confirmDialogTagName: "fast-af-confirm-dialog";
107
+ /**
108
+ * Defines the confirmation dialog in the provided registry.
109
+ *
110
+ * @remarks
111
+ * Registration is explicit so importing the command API remains side-effect free.
112
+ * Repeated calls for the same registry are safe.
113
+ *
114
+ * @param registry - Registry in which to define the dialog.
115
+ * @public
116
+ */
117
+ export declare function defineConfirmDialog(registry?: CustomElementRegistry): Promise<void>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Public API for the `command` decorator system.
3
+ * Enables AI agents to interact with FASTElement components through structured commands.
4
+ */
5
+ export type { ResultMetadata, CommandError, CommandResult, CommandId, CommandMetadata, CommandOptions, CommandEntry, Action, InterfaceType, ExposeConfig, ActionFilter, JSONSchema, } from "./types.js";
6
+ export { ErrorCodes, success, failure, isSuccess, isFailure, createError, DEFAULT_EXPOSE_CONFIG, } from "./types.js";
7
+ export { command, getCommandMetadata } from "./command.js";
8
+ export { CommandBehavior } from "./behavior.js";
9
+ export type { CommandHostController } from "./behavior.js";
10
+ export { ConfirmBehavior, USER_CANCELLED } from "./behaviors/confirm-behavior.js";
11
+ export type { PendingConfirmation } from "./behaviors/confirm-behavior.js";
12
+ export { UndoBehavior } from "./behaviors/undo-behavior.js";
13
+ export type { UndoEntry, UndoBehaviorOptions } from "./behaviors/undo-behavior.js";
14
+ export { CommandRegistry } from "./registry.js";
15
+ export type { CommandRegistryAPI, CommandListener, TelemetryHandler, InvokeOptions, Interceptor, PostHook, } from "./registry.js";
16
+ export { confirmDialogTagName, defineConfirmDialog, } from "./components/confirm-dialog.js";
17
+ export { registerComponentCommands } from "./component-registry.js";
18
+ export type { ComponentInfo, ComponentAPIInfo } from "./component-registry.js";
19
+ export type { AriaHint, CommandSchema, ComponentSchema, CSSPropertySchema, EventSchema, JSONSchema as DefinitionJSONSchema, PropertySchema, PropertyType, SlotSchema, } from "../definition-schema/types.js";
20
+ export { registerValidationCommands } from "./validation.js";
21
+ export type { LintSeverity, LintIssue, LintCounts, LintPlanStep, LintResult, WcagLevel, A11yImpact, A11yViolation, A11yAuditResult, } from "./validation.js";
@@ -0,0 +1,201 @@
1
+ /**
2
+ * CommandRegistry singleton for managing command lifecycle.
3
+ * Enables AI agents and command palettes to discover and execute commands.
4
+ *
5
+ * @remarks
6
+ * - SSR-safe: Guards against document access in Node.js
7
+ * - The `cmd-exec` document event bridge is opt-in (`enableEventBridge()`)
8
+ * - Uses AFD's failure() helper for error results
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { CommandRegistry } from '@lushly-dev/fast-element/command.js';
13
+ *
14
+ * // Execute a command
15
+ * const result = await CommandRegistry.execute('editor.save');
16
+ * if (result.success) {
17
+ * console.log('Saved:', result.data);
18
+ * } else {
19
+ * console.error('Failed:', result.error.message);
20
+ * }
21
+ *
22
+ * // Get actions for command palette
23
+ * const actions = CommandRegistry.getActions();
24
+ *
25
+ * // Subscribe to changes
26
+ * const unsubscribe = CommandRegistry.onChange((added, removed) => {
27
+ * console.log('Commands changed:', { added, removed });
28
+ * });
29
+ * ```
30
+ */
31
+ import type { Action, ActionFilter, CommandEntry, CommandResult, InterfaceType } from "./types.js";
32
+ /**
33
+ * Interceptor for command execution.
34
+ * Interceptors can modify, block, or wrap command execution.
35
+ *
36
+ * @remarks
37
+ * Interceptors run in priority order (lower priority runs first).
38
+ * Each interceptor must call `next()` to continue the chain.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * CommandRegistry.addInterceptor({
43
+ * name: 'confirm',
44
+ * priority: 10,
45
+ * intercept: async (command, args, next) => {
46
+ * if (command.destructive) {
47
+ * const confirmed = await showConfirm('Are you sure?');
48
+ * if (!confirmed) return { success: false, error: { code: 'USER_CANCELLED', message: 'Cancelled' } };
49
+ * }
50
+ * return next();
51
+ * }
52
+ * });
53
+ * ```
54
+ *
55
+ * @public
56
+ */
57
+ export interface Interceptor {
58
+ /** Unique name for the interceptor (used for removal) */
59
+ name: string;
60
+ /** Priority order (lower runs first, default: 100) */
61
+ priority?: number;
62
+ /**
63
+ * Marks the interceptor as one that asks for user confirmation of destructive
64
+ * commands.
65
+ *
66
+ * @remarks
67
+ * Externally-originated invocations (see {@link CommandRegistryAPI.invoke}) of
68
+ * `destructive` commands fail closed with `CONFIRMATION_REQUIRED` unless an
69
+ * interceptor with this flag, or one named `confirm`, is installed.
70
+ */
71
+ confirms?: boolean;
72
+ /**
73
+ * Intercept the command execution.
74
+ * @param command - The command entry being executed
75
+ * @param args - Arguments passed to the command
76
+ * @param next - Call to continue to next interceptor or execute the command
77
+ * @returns The command result
78
+ */
79
+ intercept(command: CommandEntry, args: unknown[], next: () => Promise<CommandResult>): Promise<CommandResult>;
80
+ }
81
+ /**
82
+ * PostHook for observing command execution results.
83
+ * PostHooks run after command execution completes (success or failure).
84
+ *
85
+ * @remarks
86
+ * Unlike interceptors, post-hooks cannot modify the result.
87
+ * They are useful for:
88
+ * - Logging and analytics
89
+ * - Building undo stacks
90
+ * - Triggering side effects
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * CommandRegistry.addPostHook({
95
+ * name: 'undo',
96
+ * afterExecute: (command, args, result) => {
97
+ * if (result.success && command.undoable) {
98
+ * undoStack.push({ command, args, result });
99
+ * }
100
+ * }
101
+ * });
102
+ * ```
103
+ *
104
+ * @public
105
+ */
106
+ export interface PostHook {
107
+ /** Unique name for the post-hook (used for removal) */
108
+ name: string;
109
+ /**
110
+ * Called after command execution completes.
111
+ * @param command - The command entry that was executed
112
+ * @param args - Arguments that were passed to the command
113
+ * @param result - The result of command execution
114
+ */
115
+ afterExecute(command: CommandEntry, args: unknown[], result: CommandResult): void;
116
+ }
117
+ /**
118
+ * Listener function signature for command registry changes.
119
+ * @param added - Array of newly registered command IDs
120
+ * @param removed - Array of unregistered command IDs
121
+ * @public
122
+ */
123
+ export type CommandListener = (added: string[], removed: string[]) => void;
124
+ /**
125
+ * Telemetry handler function signature.
126
+ * @param event - Event name (e.g., "command.registered", "command.executed")
127
+ * @param data - Event data
128
+ * @public
129
+ */
130
+ export type TelemetryHandler = (event: string, data: Record<string, unknown>) => void;
131
+ /**
132
+ * Describes who is invoking a command from outside the component's own code.
133
+ * @public
134
+ */
135
+ export interface InvokeOptions {
136
+ /**
137
+ * The interface the invocation arrives through (`agent`, `mcp`, `cli` or
138
+ * `palette`). The command's `expose` configuration must enable it.
139
+ */
140
+ origin: InterfaceType;
141
+ }
142
+ /**
143
+ * Public contract for the global command registry.
144
+ * @public
145
+ */
146
+ export interface CommandRegistryAPI {
147
+ register(id: string, command: CommandEntry): void;
148
+ unregister(id: string, expected?: CommandEntry): void;
149
+ get(id: string): CommandEntry | undefined;
150
+ execute(id: string, ...args: unknown[]): Promise<CommandResult>;
151
+ invoke(id: string, args: unknown[], options: InvokeOptions): Promise<CommandResult>;
152
+ enableEventBridge(): () => void;
153
+ getActions(filter?: ActionFilter): Action[];
154
+ onChange(listener: CommandListener): () => void;
155
+ clear(): void;
156
+ forScope(shadowRoot: ShadowRoot): CommandRegistryAPI;
157
+ setTelemetryHandler(handler?: TelemetryHandler): void;
158
+ addInterceptor(interceptor: Interceptor): void;
159
+ removeInterceptor(name: string): void;
160
+ addPostHook(hook: PostHook): void;
161
+ removePostHook(name: string): void;
162
+ }
163
+ /**
164
+ * Global CommandRegistry singleton.
165
+ *
166
+ * @remarks
167
+ * The CommandRegistry is the central hub for command management.
168
+ * Commands are registered automatically when FASTElement components
169
+ * with \@command decorators connect to the DOM.
170
+ *
171
+ * Key features:
172
+ * - SSR-safe with lazy initialization
173
+ * - Reactive: subscribe to changes via onChange()
174
+ * - Command palette integration via getActions()
175
+ * - Telemetry hooks for analytics
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * import { CommandRegistry, success, failure } from '\@lushly-dev/fast-element/command.js';
180
+ *
181
+ * // Manual command registration (usually done automatically)
182
+ * CommandRegistry.register('custom.action', \{
183
+ * id: 'custom.action',
184
+ * label: 'Custom Action',
185
+ * execute: () => success(\{ done: true \}),
186
+ * canExecute: true,
187
+ * when: true,
188
+ * source: new WeakRef(document.body),
189
+ * \});
190
+ *
191
+ * // Execute command
192
+ * const result = await CommandRegistry.execute('custom.action');
193
+ *
194
+ * // Command palette integration
195
+ * const actions = CommandRegistry.getActions();
196
+ * ninjaKeys.data = actions;
197
+ * ```
198
+ *
199
+ * @public
200
+ */
201
+ export declare const CommandRegistry: CommandRegistryAPI;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A small, dependency-free JSON Schema validator for command `parameters`.
3
+ *
4
+ * @remarks
5
+ * Deliberately limited to the keywords agents and command palettes actually
6
+ * rely on: `type`, `enum`, `const`, `required`, `properties`,
7
+ * `additionalProperties`, `items`, `minimum`/`maximum` (plus the numeric
8
+ * exclusive forms), `minLength`/`maxLength` and `minItems`/`maxItems`.
9
+ * Unknown keywords (including `pattern`, `$ref`, `oneOf`, ...) are ignored, so a
10
+ * schema that uses them is validated on a best-effort basis rather than rejected.
11
+ *
12
+ * @internal
13
+ */
14
+ /**
15
+ * A single validation problem.
16
+ * @internal
17
+ */
18
+ export interface SchemaIssue {
19
+ /** JSON-pointer-like location of the problem (e.g. `$.items[0].id`). */
20
+ path: string;
21
+ /** Human-readable description. */
22
+ message: string;
23
+ }
24
+ /**
25
+ * Validates a value against a (basic) JSON Schema.
26
+ * @param value - The value to validate.
27
+ * @param schema - The JSON Schema.
28
+ * @returns The list of problems; empty when the value is valid.
29
+ * @internal
30
+ */
31
+ export declare function validateSchema(value: unknown, schema: Record<string, unknown>): SchemaIssue[];
32
+ /**
33
+ * Validates the arguments of a command invocation against the command's
34
+ * `parameters` schema.
35
+ *
36
+ * @remarks
37
+ * Command arguments are positional (`execute(...args)`), but the `parameters`
38
+ * schema describes a single structured argument, which is how every built-in
39
+ * command (and agent tool call) consumes input. The schema is therefore applied to
40
+ * `args[0]`. When no argument is supplied and the schema describes an object,
41
+ * an empty object is validated so `required` still fires.
42
+ *
43
+ * @internal
44
+ */
45
+ export declare function validateCommandArguments(args: unknown[], schema: Record<string, unknown>): SchemaIssue[];