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

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 +12 -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 +16 -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 +109 -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 +313 -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 +755 -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 +508 -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 +840 -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 +211 -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 +122 -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 +1441 -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 +57 -0
  192. package/dist/esm/observation/arrays.js +661 -0
  193. package/dist/esm/observation/notifier.js +162 -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 +7604 -0
  243. package/dist/fast-element.debug.min.js +3 -0
  244. package/dist/fast-element.js +7603 -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 +21 -23
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Severity of a {@link Warning}.
3
+ * @public
4
+ */
5
+ export type WarningSeverity = "info" | "warning" | "caution";
6
+ /**
7
+ * A non-fatal issue surfaced alongside an event.
8
+ *
9
+ * @remarks
10
+ * Local stub that mirrors the `Warning` type of AFD's `CommandResult`; it can be
11
+ * re-exported from `@lushly-dev/afd-core` once that package is a dependency.
12
+ *
13
+ * @public
14
+ */
15
+ export interface Warning {
16
+ /** Machine-readable warning code. */
17
+ code: string;
18
+ /** Human-readable warning message. */
19
+ message: string;
20
+ /** Optional severity. Unknown values are dropped when signals are read. */
21
+ severity?: WarningSeverity;
22
+ /** Optional structured details. Only plain objects are kept when signals are read. */
23
+ details?: Record<string, unknown>;
24
+ }
25
+ /**
26
+ * Trust signals attached to component events.
27
+ * @public
28
+ */
29
+ export interface TrustSignals {
30
+ /** Confidence level 0-1. Higher = more certain. */
31
+ confidence?: number;
32
+ /** Human-readable explanation of why this event occurred. */
33
+ reasoning?: string;
34
+ /** Non-fatal issues to surface to the user. An empty array is preserved. */
35
+ warnings?: Warning[];
36
+ }
37
+ /**
38
+ * Extended emit options with trust signals.
39
+ * @public
40
+ */
41
+ export interface TrustEmitOptions extends Omit<CustomEventInit, "detail">, TrustSignals {
42
+ }
43
+ /**
44
+ * Property key (the string `"__trust"`) under which trust metadata is stored in
45
+ * event detail.
46
+ * @public
47
+ */
48
+ export declare const TRUST_KEY: "__trust";
@@ -0,0 +1,26 @@
1
+ import type { TrustSignals } from "./types.js";
2
+ /**
3
+ * Extract trust signals from a CustomEvent.
4
+ * Returns empty object if no trust signals present.
5
+ * @public
6
+ */
7
+ export declare function getTrustSignals(event: CustomEvent): TrustSignals;
8
+ /**
9
+ * Check if an event has trust signals.
10
+ * @public
11
+ */
12
+ export declare function hasTrustSignals(event: CustomEvent): boolean;
13
+ /**
14
+ * Wrap detail with trust signals.
15
+ *
16
+ * @remarks
17
+ * - Plain objects are copied and the signals are added under {@link TRUST_KEY}.
18
+ * - Anything else (primitives, arrays, Dates, class instances, ...) is wrapped in a
19
+ * `{ value, __trust }` envelope so it is never spread into a different shape.
20
+ * - A `__trust` key already present on a plain-object detail is caller-supplied
21
+ * (often from parsed JSON) and is never kept: it is replaced by the real signals,
22
+ * or dropped when there are none, so detail data cannot forge trust signals.
23
+ *
24
+ * @internal
25
+ */
26
+ export declare function wrapDetailWithTrust(detail: unknown, signals?: TrustSignals): unknown;
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.60.1"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,76 @@
1
+ import type { HostBehavior } from "./styles/host.js";
2
+ import type { ViewBehavior, ViewBehaviorFactory, ViewController } from "./templating/html-directive.js";
3
+ /**
4
+ * Retrieves the "composed parent" element of a node, ignoring DOM tree boundaries.
5
+ * When the parent of a node is a shadow-root, it will return the host
6
+ * element of the shadow root. Otherwise it will return the parent node or null if
7
+ * no parent node exists.
8
+ * @param element - The element for which to retrieve the composed parent
9
+ *
10
+ * @public
11
+ */
12
+ export declare function composedParent<T extends HTMLElement>(element: T): HTMLElement | null;
13
+ /**
14
+ * Determines if the reference element contains the test element in a "composed" DOM tree that
15
+ * ignores shadow DOM boundaries.
16
+ *
17
+ * Returns true of the test element is a descendent of the reference, or exists in
18
+ * a shadow DOM that is a logical descendent of the reference. Otherwise returns false.
19
+ * @param reference - The element to test for containment against.
20
+ * @param test - The element being tested for containment.
21
+ *
22
+ * @public
23
+ */
24
+ export declare function composedContains(reference: HTMLElement, test: HTMLElement): boolean;
25
+ /**
26
+ * An extension of MutationObserver that supports unobserving nodes.
27
+ * @internal
28
+ */
29
+ export declare class UnobservableMutationObserver extends MutationObserver {
30
+ private readonly callback;
31
+ private observedNodes;
32
+ /**
33
+ * Creates an instance of UnobservableMutationObserver.
34
+ * @param callback - The callback to invoke when observed nodes are changed.
35
+ */
36
+ constructor(callback: MutationCallback);
37
+ observe(target: Node, options?: MutationObserverInit | undefined): void;
38
+ unobserve(target: Node): void;
39
+ }
40
+ /**
41
+ * Bridges between ViewBehaviors and HostBehaviors, enabling a host to
42
+ * control ViewBehaviors.
43
+ * @public
44
+ */
45
+ export interface ViewBehaviorOrchestrator<TSource = any, TParent = any> extends ViewController<TSource, TParent>, HostBehavior<TSource> {
46
+ /**
47
+ *
48
+ * @param nodeId - The structural id of the DOM node to which a behavior will apply.
49
+ * @param target - The DOM node associated with the id.
50
+ */
51
+ addTarget(nodeId: string, target: Node): void;
52
+ /**
53
+ * Adds a behavior.
54
+ * @param behavior - The behavior to add.
55
+ */
56
+ addBehavior(behavior: ViewBehavior): void;
57
+ /**
58
+ * Adds a behavior factory.
59
+ * @param factory - The behavior factory to add.
60
+ * @param target - The target the factory will create behaviors for.
61
+ */
62
+ addBehaviorFactory(factory: ViewBehaviorFactory, target: Node): void;
63
+ }
64
+ /**
65
+ * Bridges between ViewBehaviors and HostBehaviors, enabling a host to
66
+ * control ViewBehaviors.
67
+ * @public
68
+ */
69
+ export declare const ViewBehaviorOrchestrator: Readonly<{
70
+ /**
71
+ * Creates a ViewBehaviorOrchestrator.
72
+ * @param source - The source to to associate behaviors with.
73
+ * @returns A ViewBehaviorOrchestrator.
74
+ */
75
+ create<TSource = any, TParent = any>(source: TSource): ViewBehaviorOrchestrator<TSource, TParent>;
76
+ }>;
@@ -0,0 +1 @@
1
+ export { lengthOf, Sort, Splice, SpliceStrategy, SpliceStrategySupport, sortedCount, } from "./observation/arrays.js";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Captures a binding expression along with related information and capabilities.
3
+ *
4
+ * @public
5
+ */
6
+ export class Binding {
7
+ /**
8
+ * Creates a binding.
9
+ * @param evaluate - Evaluates the binding.
10
+ * @param policy - The security policy to associate with this binding.
11
+ * @param isVolatile - Indicates whether the binding is volatile.
12
+ */
13
+ constructor(evaluate, policy, isVolatile = false) {
14
+ this.evaluate = evaluate;
15
+ this.policy = policy;
16
+ this.isVolatile = isVolatile;
17
+ }
18
+ }
@@ -0,0 +1,6 @@
1
+ export { Binding } from "./binding.js";
2
+ export { normalizeBinding } from "./normalize.js";
3
+ export { oneTime } from "./one-time.js";
4
+ export { listener, oneWay } from "./one-way.js";
5
+ export { Signal, signal } from "./signal.js";
6
+ export { TwoWaySettings, twoWay, } from "./two-way.js";
@@ -0,0 +1,17 @@
1
+ import { isFunction } from "../interfaces.js";
2
+ import { Binding } from "./binding.js";
3
+ import { oneTime } from "./one-time.js";
4
+ import { oneWay } from "./one-way.js";
5
+ /**
6
+ * Normalizes the input value into a binding.
7
+ * @param value - The value to create the default binding for.
8
+ * @returns A binding configuration for the provided value.
9
+ * @public
10
+ */
11
+ export function normalizeBinding(value) {
12
+ return isFunction(value)
13
+ ? oneWay(value)
14
+ : value instanceof Binding
15
+ ? value
16
+ : oneTime(() => value);
17
+ }
@@ -0,0 +1,21 @@
1
+ import { makeSerializationNoop } from "../platform.js";
2
+ import { Binding } from "./binding.js";
3
+ class OneTimeBinding extends Binding {
4
+ createObserver() {
5
+ return this;
6
+ }
7
+ bind(controller) {
8
+ return this.evaluate(controller.source, controller.context);
9
+ }
10
+ }
11
+ makeSerializationNoop(OneTimeBinding);
12
+ /**
13
+ * Creates a one time binding
14
+ * @param expression - The binding to refresh when signaled.
15
+ * @param policy - The security policy to associate with th binding.
16
+ * @returns A binding configuration.
17
+ * @public
18
+ */
19
+ export function oneTime(expression, policy) {
20
+ return new OneTimeBinding(expression, policy);
21
+ }
@@ -0,0 +1,30 @@
1
+ import { Observable, } from "../observation/observable.js";
2
+ import { Binding } from "./binding.js";
3
+ class OneWayBinding extends Binding {
4
+ createObserver(subscriber) {
5
+ return Observable.binding(this.evaluate, subscriber, this.isVolatile);
6
+ }
7
+ }
8
+ /**
9
+ * Creates an standard binding.
10
+ * @param expression - The binding to refresh when changed.
11
+ * @param policy - The security policy to associate with th binding.
12
+ * @param isVolatile - Indicates whether the binding is volatile or not.
13
+ * @returns A binding configuration.
14
+ * @public
15
+ */
16
+ export function oneWay(expression, policy, isVolatile = Observable.isVolatileBinding(expression)) {
17
+ return new OneWayBinding(expression, policy, isVolatile);
18
+ }
19
+ /**
20
+ * Creates an event listener binding.
21
+ * @param expression - The binding to invoke when the event is raised.
22
+ * @param options - Event listener options.
23
+ * @returns A binding configuration.
24
+ * @public
25
+ */
26
+ export function listener(expression, options) {
27
+ const config = new OneWayBinding(expression);
28
+ config.options = options;
29
+ return config;
30
+ }
@@ -0,0 +1,99 @@
1
+ import { isString } from "../interfaces.js";
2
+ import { makeSerializationNoop } from "../platform.js";
3
+ import { Binding } from "./binding.js";
4
+ const subscribers = Object.create(null);
5
+ /**
6
+ * The gateway to signal APIs.
7
+ * @public
8
+ */
9
+ export const Signal = Object.freeze({
10
+ /**
11
+ * Subscribes to a signal.
12
+ * @param signal - The signal to subscribe to.
13
+ * @param subscriber - The subscriber.
14
+ */
15
+ subscribe(signal, subscriber) {
16
+ const found = subscribers[signal];
17
+ if (found) {
18
+ found instanceof Set
19
+ ? found.add(subscriber)
20
+ : (subscribers[signal] = new Set([found, subscriber]));
21
+ }
22
+ else {
23
+ subscribers[signal] = subscriber;
24
+ }
25
+ },
26
+ /**
27
+ * Unsubscribes from the signal.
28
+ * @param signal - The signal to unsubscribe from.
29
+ * @param subscriber - The subscriber.
30
+ */
31
+ unsubscribe(signal, subscriber) {
32
+ const found = subscribers[signal];
33
+ if (found && found instanceof Set) {
34
+ found.delete(subscriber);
35
+ }
36
+ else {
37
+ subscribers[signal] = void 0;
38
+ }
39
+ },
40
+ /**
41
+ * Sends the specified signal to subscribers.
42
+ * @param signal - The signal to send.
43
+ */
44
+ send(signal) {
45
+ const found = subscribers[signal];
46
+ if (found) {
47
+ found instanceof Set
48
+ ? found.forEach(x => x.handleChange(found, signal))
49
+ : found.handleChange(this, signal);
50
+ }
51
+ },
52
+ });
53
+ class SignalObserver {
54
+ constructor(dataBinding, subscriber) {
55
+ this.dataBinding = dataBinding;
56
+ this.subscriber = subscriber;
57
+ this.isNotBound = true;
58
+ }
59
+ bind(controller) {
60
+ if (this.isNotBound) {
61
+ Signal.subscribe(this.getSignal(controller), this);
62
+ controller.onUnbind(this);
63
+ this.isNotBound = false;
64
+ }
65
+ return this.dataBinding.evaluate(controller.source, controller.context);
66
+ }
67
+ unbind(controller) {
68
+ this.isNotBound = true;
69
+ Signal.unsubscribe(this.getSignal(controller), this);
70
+ }
71
+ handleChange() {
72
+ this.subscriber.handleChange(this.dataBinding.evaluate, this);
73
+ }
74
+ getSignal(controller) {
75
+ const options = this.dataBinding.options;
76
+ return isString(options)
77
+ ? options
78
+ : options(controller.source, controller.context);
79
+ }
80
+ }
81
+ makeSerializationNoop(SignalObserver);
82
+ class SignalBinding extends Binding {
83
+ createObserver(subscriber) {
84
+ return new SignalObserver(this, subscriber);
85
+ }
86
+ }
87
+ /**
88
+ * Creates a signal binding configuration with the supplied options.
89
+ * @param expression - The binding to refresh when signaled.
90
+ * @param options - The signal name or a binding to use to retrieve the signal name.
91
+ * @param policy - The security policy to associate with th binding.
92
+ * @returns A binding configuration.
93
+ * @public
94
+ */
95
+ export function signal(expression, options, policy) {
96
+ const binding = new SignalBinding(expression, policy);
97
+ binding.options = options;
98
+ return binding;
99
+ }
@@ -0,0 +1,109 @@
1
+ import { isString, Message } from "../interfaces.js";
2
+ import { Observable, } from "../observation/observable.js";
3
+ import { FAST, makeSerializationNoop } from "../platform.js";
4
+ import { Binding } from "./binding.js";
5
+ const defaultOptions = {
6
+ fromView: v => v,
7
+ };
8
+ let twoWaySettings = {
9
+ determineChangeEvent() {
10
+ return "change";
11
+ },
12
+ };
13
+ /**
14
+ * Enables configuring two-way binding settings.
15
+ * @public
16
+ */
17
+ export const TwoWaySettings = Object.freeze({
18
+ /**
19
+ * Configures two-way binding.
20
+ * @param settings - The settings to use for the two-way binding system.
21
+ */
22
+ configure(settings) {
23
+ twoWaySettings = settings;
24
+ },
25
+ });
26
+ class TwoWayObserver {
27
+ constructor(directive, subscriber, dataBinding) {
28
+ this.directive = directive;
29
+ this.subscriber = subscriber;
30
+ this.dataBinding = dataBinding;
31
+ this.isNotBound = true;
32
+ this.notifier = Observable.binding(dataBinding.evaluate, this, dataBinding.isVolatile);
33
+ }
34
+ bind(controller) {
35
+ var _a;
36
+ if (!this.changeEvent) {
37
+ this.changeEvent = (_a = this.dataBinding.options.changeEvent) !== null && _a !== void 0 ? _a : twoWaySettings.determineChangeEvent(this.directive, this.target);
38
+ }
39
+ if (this.isNotBound) {
40
+ this.target.addEventListener(this.changeEvent, this);
41
+ controller.onUnbind(this);
42
+ this.isNotBound = false;
43
+ }
44
+ return this.notifier.bind(controller);
45
+ }
46
+ unbind(controller) {
47
+ this.isNotBound = true;
48
+ this.target.removeEventListener(this.changeEvent, this);
49
+ }
50
+ handleChange(subject, args) {
51
+ this.subscriber.handleChange(this.dataBinding.evaluate, this);
52
+ }
53
+ handleEvent(event) {
54
+ const bindingSource = this.directive;
55
+ const target = event.currentTarget;
56
+ const notifier = this.notifier;
57
+ const last = notifier.last; // using internal API!!!
58
+ if (!last) {
59
+ FAST.warn(Message.twoWayBindingRequiresObservables);
60
+ return;
61
+ }
62
+ let value;
63
+ switch (bindingSource.aspectType) {
64
+ case 1:
65
+ value = target.getAttribute(bindingSource.targetAspect);
66
+ break;
67
+ case 2:
68
+ value = target.hasAttribute(bindingSource.targetAspect);
69
+ break;
70
+ case 4:
71
+ value = target.innerText;
72
+ break;
73
+ default:
74
+ value = target[bindingSource.targetAspect];
75
+ break;
76
+ }
77
+ last.propertySource[last.propertyName] =
78
+ this.dataBinding.options.fromView(value);
79
+ }
80
+ }
81
+ makeSerializationNoop(TwoWayObserver);
82
+ class TwoWayBinding extends Binding {
83
+ createObserver(subscriber, bindingSource) {
84
+ return new TwoWayObserver(bindingSource, subscriber, this);
85
+ }
86
+ }
87
+ /**
88
+ * Creates a default binding.
89
+ * @param expression - The binding to refresh when changed.
90
+ * @param optionsOrChangeEvent - The binding options or the name of the change event to use.
91
+ * @param policy - The security policy to associate with the binding.
92
+ * @param isBindingVolatile - Indicates whether the binding is volatile or not.
93
+ * @returns A binding.
94
+ * @public
95
+ */
96
+ export function twoWay(expression, optionsOrChangeEvent, policy, isBindingVolatile = Observable.isVolatileBinding(expression)) {
97
+ if (isString(optionsOrChangeEvent)) {
98
+ optionsOrChangeEvent = { changeEvent: optionsOrChangeEvent };
99
+ }
100
+ if (!optionsOrChangeEvent) {
101
+ optionsOrChangeEvent = defaultOptions;
102
+ }
103
+ else if (!optionsOrChangeEvent.fromView) {
104
+ optionsOrChangeEvent.fromView = defaultOptions.fromView;
105
+ }
106
+ const binding = new TwoWayBinding(expression, policy, isBindingVolatile);
107
+ binding.options = optionsOrChangeEvent;
108
+ return binding;
109
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * CommandBehavior - Lifecycle management for `command`-decorated methods.
3
+ * Bridges `command` decorator metadata to the CommandRegistry.
4
+ *
5
+ * @remarks
6
+ * Implements the FAST host-behavior lifecycle structurally.
7
+ * Commands are discovered in addedCallback, registered on connect, and
8
+ * unregistered on disconnect.
9
+ *
10
+ * Uses Observable.track() for reactive canExecute and when getters,
11
+ * allowing UI to reactively update when command availability changes.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Behavior is automatically added when an element has command decorators
16
+ * class MyEditor extends FASTElement {
17
+ * @observable
18
+ * hasChanges = false;
19
+ *
20
+ * // Reactive canExecute getter
21
+ * get saveCanExecute(): boolean {
22
+ * return this.hasChanges;
23
+ * }
24
+ *
25
+ * @command('editor.save', { label: 'Save' })
26
+ * save(): CommandResult {
27
+ * return success({ saved: true });
28
+ * }
29
+ * }
30
+ * ```
31
+ */
32
+ import { Observable } from "../observation/observable.js";
33
+ import { getCommandMetadata } from "./command.js";
34
+ import { CommandRegistry } from "./registry.js";
35
+ import { createWeakReference } from "./weak-ref.js";
36
+ /**
37
+ * Behavior that manages command lifecycle for FASTElement components.
38
+ *
39
+ * @remarks
40
+ * - Discovers `command`-decorated methods via getCommandMetadata
41
+ * - Registers commands with CommandRegistry on connect
42
+ * - Unregisters commands on disconnect
43
+ * - Provides reactive canExecute/when getters via Observable.track()
44
+ *
45
+ * @public
46
+ */
47
+ export class CommandBehavior {
48
+ constructor() {
49
+ /**
50
+ * Map of command IDs to their registry entries.
51
+ * Populated in addedCallback, used in connect/disconnect.
52
+ */
53
+ this.commands = new Map();
54
+ /**
55
+ * Reference to the host element.
56
+ * Set in addedCallback for use in discoverCommands.
57
+ */
58
+ this.host = null;
59
+ }
60
+ /**
61
+ * Called when the behavior is first attached to a controller.
62
+ * Discovers all `command`-decorated methods on the host element.
63
+ *
64
+ * @param controller - The host controller managing this behavior
65
+ */
66
+ addedCallback(controller) {
67
+ this.host = controller.source;
68
+ this.discoverCommands();
69
+ }
70
+ /**
71
+ * Called when the host element connects to the DOM.
72
+ * Registers all discovered commands with the CommandRegistry.
73
+ *
74
+ * @param controller - The host controller managing this behavior
75
+ */
76
+ connectedCallback(controller) {
77
+ this.commands.forEach((cmd, id) => {
78
+ CommandRegistry.register(id, cmd);
79
+ });
80
+ }
81
+ /**
82
+ * Called when the host element disconnects from the DOM.
83
+ * Unregisters all commands from the CommandRegistry.
84
+ *
85
+ * @param controller - The host controller managing this behavior
86
+ */
87
+ disconnectedCallback(controller) {
88
+ this.commands.forEach((command, id) => {
89
+ CommandRegistry.unregister(id, command);
90
+ });
91
+ }
92
+ /**
93
+ * Discovers all `command`-decorated methods on the host element
94
+ * and creates CommandEntry objects for each.
95
+ *
96
+ * @remarks
97
+ * For each command:
98
+ * - Binds the method to the host element
99
+ * - Creates reactive canExecute getter checking for `${methodName}CanExecute`
100
+ * - Creates reactive when getter checking for `${methodName}When`
101
+ * - Stores WeakRef to host for garbage collection safety
102
+ */
103
+ discoverCommands() {
104
+ var _a;
105
+ if (!this.host)
106
+ return;
107
+ const metadata = getCommandMetadata(this.host.constructor);
108
+ const host = this.host;
109
+ for (const meta of metadata) {
110
+ const entry = {
111
+ id: meta.id,
112
+ methodName: meta.methodName,
113
+ label: (_a = meta.label) !== null && _a !== void 0 ? _a : meta.methodName,
114
+ icon: meta.icon,
115
+ description: meta.description,
116
+ category: meta.category,
117
+ keybinding: meta.keybinding,
118
+ parameters: meta.parameters,
119
+ hidden: meta.hidden,
120
+ destructive: meta.destructive,
121
+ confirmPrompt: meta.confirmPrompt,
122
+ expose: meta.expose,
123
+ execute: host[meta.methodName].bind(host),
124
+ source: createWeakReference(host),
125
+ /**
126
+ * Reactive getter for command executability.
127
+ * Checks for a `${methodName}CanExecute` property on the host.
128
+ * Uses Observable.track() to enable reactive updates.
129
+ */
130
+ get canExecute() {
131
+ const getter = `${meta.methodName}CanExecute`;
132
+ if (getter in host) {
133
+ Observable.track(host, getter);
134
+ return host[getter];
135
+ }
136
+ return true;
137
+ },
138
+ /**
139
+ * Reactive getter for command visibility.
140
+ * Checks for a `${methodName}When` property on the host.
141
+ * Uses Observable.track() to enable reactive updates.
142
+ */
143
+ get when() {
144
+ const getter = `${meta.methodName}When`;
145
+ if (getter in host) {
146
+ Observable.track(host, getter);
147
+ return host[getter];
148
+ }
149
+ return true;
150
+ },
151
+ };
152
+ this.commands.set(meta.id, entry);
153
+ }
154
+ }
155
+ }