@microsoft/fast-element 1.10.0 → 2.0.0-beta.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 (97) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +396 -1
  3. package/CHANGELOG.md +68 -2
  4. package/README.md +2 -2
  5. package/dist/dts/components/attributes.d.ts +4 -1
  6. package/dist/dts/components/controller.d.ts +12 -11
  7. package/dist/dts/components/fast-definitions.d.ts +8 -2
  8. package/dist/dts/components/fast-element.d.ts +5 -4
  9. package/dist/dts/debug.d.ts +1 -0
  10. package/dist/dts/hooks.d.ts +20 -0
  11. package/dist/dts/index.d.ts +16 -15
  12. package/dist/dts/index.debug.d.ts +2 -0
  13. package/dist/dts/index.rollup.d.ts +2 -0
  14. package/dist/dts/index.rollup.debug.d.ts +3 -0
  15. package/dist/dts/interfaces.d.ts +144 -0
  16. package/dist/dts/observation/arrays.d.ts +207 -0
  17. package/dist/dts/observation/behavior.d.ts +5 -5
  18. package/dist/dts/observation/notifier.d.ts +18 -18
  19. package/dist/dts/observation/observable.d.ts +86 -29
  20. package/dist/dts/observation/splice-strategies.d.ts +13 -0
  21. package/dist/dts/observation/update-queue.d.ts +40 -0
  22. package/dist/dts/platform.d.ts +18 -67
  23. package/dist/dts/polyfills.d.ts +8 -0
  24. package/dist/dts/styles/css-directive.d.ts +43 -5
  25. package/dist/dts/styles/css.d.ts +19 -3
  26. package/dist/dts/styles/element-styles.d.ts +42 -62
  27. package/dist/dts/templating/binding.d.ts +320 -64
  28. package/dist/dts/templating/children.d.ts +18 -15
  29. package/dist/dts/templating/compiler.d.ts +47 -28
  30. package/dist/dts/templating/dom.d.ts +41 -0
  31. package/dist/dts/templating/html-directive.d.ts +179 -43
  32. package/dist/dts/templating/markup.d.ts +48 -0
  33. package/dist/dts/templating/node-observation.d.ts +45 -29
  34. package/dist/dts/templating/ref.d.ts +6 -12
  35. package/dist/dts/templating/repeat.d.ts +72 -14
  36. package/dist/dts/templating/slotted.d.ts +13 -14
  37. package/dist/dts/templating/template.d.ts +78 -23
  38. package/dist/dts/templating/view.d.ts +16 -23
  39. package/dist/dts/utilities.d.ts +40 -0
  40. package/dist/esm/components/attributes.js +25 -24
  41. package/dist/esm/components/controller.js +77 -57
  42. package/dist/esm/components/fast-definitions.js +14 -22
  43. package/dist/esm/debug.js +29 -0
  44. package/dist/esm/hooks.js +32 -0
  45. package/dist/esm/index.debug.js +2 -0
  46. package/dist/esm/index.js +19 -14
  47. package/dist/esm/index.rollup.debug.js +3 -0
  48. package/dist/esm/index.rollup.js +2 -0
  49. package/dist/esm/interfaces.js +8 -1
  50. package/dist/esm/observation/arrays.js +269 -0
  51. package/dist/esm/observation/notifier.js +75 -83
  52. package/dist/esm/observation/observable.js +80 -107
  53. package/dist/esm/observation/{array-change-records.js → splice-strategies.js} +136 -62
  54. package/dist/esm/observation/update-queue.js +67 -0
  55. package/dist/esm/platform.js +36 -42
  56. package/dist/esm/polyfills.js +85 -0
  57. package/dist/esm/styles/css-directive.js +29 -13
  58. package/dist/esm/styles/css.js +27 -40
  59. package/dist/esm/styles/element-styles.js +65 -104
  60. package/dist/esm/templating/binding.js +465 -155
  61. package/dist/esm/templating/children.js +33 -23
  62. package/dist/esm/templating/compiler.js +235 -152
  63. package/dist/esm/templating/dom.js +49 -0
  64. package/dist/esm/templating/html-directive.js +125 -40
  65. package/dist/esm/templating/markup.js +75 -0
  66. package/dist/esm/templating/node-observation.js +50 -45
  67. package/dist/esm/templating/ref.js +7 -16
  68. package/dist/esm/templating/repeat.js +38 -43
  69. package/dist/esm/templating/slotted.js +23 -20
  70. package/dist/esm/templating/template.js +71 -95
  71. package/dist/esm/templating/view.js +44 -43
  72. package/dist/esm/templating/when.js +2 -1
  73. package/dist/esm/utilities.js +139 -0
  74. package/dist/fast-element.api.json +14062 -5235
  75. package/dist/fast-element.d.ts +1434 -579
  76. package/dist/fast-element.debug.js +3824 -0
  77. package/dist/fast-element.debug.min.js +1 -0
  78. package/dist/fast-element.js +3565 -4014
  79. package/dist/fast-element.min.js +1 -1
  80. package/dist/fast-element.untrimmed.d.ts +2908 -0
  81. package/dist/tsdoc-metadata.json +1 -1
  82. package/docs/api-report.md +590 -231
  83. package/docs/fast-element-2-changes.md +15 -0
  84. package/docs/guide/declaring-templates.md +5 -4
  85. package/docs/guide/defining-elements.md +3 -2
  86. package/docs/guide/leveraging-css.md +1 -0
  87. package/docs/guide/next-steps.md +3 -2
  88. package/docs/guide/observables-and-state.md +2 -1
  89. package/docs/guide/using-directives.md +2 -1
  90. package/docs/guide/working-with-shadow-dom.md +1 -0
  91. package/karma.conf.cjs +6 -17
  92. package/package.json +48 -14
  93. package/dist/dts/dom.d.ts +0 -112
  94. package/dist/dts/observation/array-change-records.d.ts +0 -48
  95. package/dist/dts/observation/array-observer.d.ts +0 -9
  96. package/dist/esm/dom.js +0 -207
  97. package/dist/esm/observation/array-observer.js +0 -173
@@ -1,95 +1,351 @@
1
- import type { Behavior } from "../observation/behavior.js";
2
1
  import { Binding, BindingObserver, ExecutionContext } from "../observation/observable.js";
3
- import { TargetedHTMLDirective } from "./html-directive.js";
4
- declare function normalBind(this: BindingBehavior, source: unknown, context: ExecutionContext): void;
5
- declare function normalUnbind(this: BindingBehavior): void;
6
- declare function updatePropertyTarget(this: BindingBehavior, value: unknown): void;
2
+ import { AddViewBehaviorFactory, Aspect, Aspected, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
3
+ import type { CaptureType } from "./template.js";
7
4
  /**
8
- * A directive that configures data binding to element content and attributes.
5
+ * Describes how aspects of an HTML element will be affected by bindings.
9
6
  * @public
10
7
  */
11
- export declare class HTMLBindingDirective extends TargetedHTMLDirective {
12
- binding: Binding;
13
- private cleanedTargetName?;
14
- private originalTargetName?;
15
- private bind;
16
- private unbind;
17
- private updateTarget;
18
- private isBindingVolatile;
8
+ export declare type BindingMode = Record<Aspect, (directive: HTMLBindingDirective) => Pick<ViewBehaviorFactory, "createBehavior">>;
9
+ /**
10
+ * Describes how aspects of an HTML element will be affected by bindings.
11
+ * @public
12
+ */
13
+ export declare const BindingMode: Readonly<{
19
14
  /**
20
- * Creates an instance of BindingDirective.
21
- * @param binding - A binding that returns the data used to update the DOM.
15
+ * Creates a binding mode based on the supplied behavior types.
16
+ * @param UpdateType - The base behavior type used to update aspects.
17
+ * @param EventType - The base behavior type used to respond to events.
18
+ * @returns A new binding mode.
22
19
  */
23
- constructor(binding: Binding);
20
+ define(UpdateType: typeof UpdateBinding, EventType?: typeof EventBinding): BindingMode;
21
+ }>;
22
+ /**
23
+ * Describes the configuration for a binding expression.
24
+ * @public
25
+ */
26
+ export interface BindingConfig<T = any> {
24
27
  /**
25
- * Gets/sets the name of the attribute or property that this
26
- * binding is targeting.
28
+ * The binding mode to configure the binding with.
27
29
  */
28
- get targetName(): string | undefined;
29
- set targetName(value: string | undefined);
30
+ mode: BindingMode;
30
31
  /**
31
- * Makes this binding target the content of an element rather than
32
- * a particular attribute or property.
32
+ * Options to be supplied to the binding behaviors.
33
33
  */
34
- targetAtContent(): void;
34
+ options: T;
35
+ }
36
+ /**
37
+ * Creates a new binding configuration based on the supplied options.
38
+ * @public
39
+ */
40
+ export declare type BindingConfigResolver<T> = (options: T) => BindingConfig<T>;
41
+ /**
42
+ * Describes the configuration for a binding expression.
43
+ * @public
44
+ */
45
+ export declare const BindingConfig: Readonly<{
46
+ /**
47
+ * Creates a binding configuration based on the provided mode and options.
48
+ * @param mode - The mode to use for the configuration.
49
+ * @param defaultOptions - The default options to use for the configuration.
50
+ * @returns A new binding configuration.
51
+ */
52
+ define<T>(mode: BindingMode, defaultOptions: T): BindingConfig<T> & BindingConfigResolver<T>;
53
+ }>;
54
+ /**
55
+ * The "this" context for an update target function.
56
+ * @public
57
+ */
58
+ export interface UpdateTargetThis {
35
59
  /**
36
- * Creates the runtime BindingBehavior instance based on the configuration
37
- * information stored in the BindingDirective.
38
- * @param target - The target node that the binding behavior should attach to.
60
+ * The directive configuration for the update.
39
61
  */
40
- createBehavior(target: Node): BindingBehavior;
62
+ directive: HTMLBindingDirective;
41
63
  }
42
64
  /**
43
- * A behavior that updates content and attributes based on a configured
44
- * BindingDirective.
65
+ * A target update function.
66
+ * @param this - The "this" context for the update.
67
+ * @param target - The node that is targeted by the update.
68
+ * @param aspect - The aspect of the node that is being targeted.
69
+ * @param value - The value to assign to the aspect.
70
+ * @param source - The source object that the value was derived from.
71
+ * @param context - The execution context that the binding is being run under.
45
72
  * @public
46
73
  */
47
- export declare class BindingBehavior implements Behavior {
48
- /** @internal */
49
- source: unknown;
50
- /** @internal */
51
- context: ExecutionContext | null;
52
- /** @internal */
53
- bindingObserver: BindingObserver | null;
54
- /** @internal */
55
- classVersions: Record<string, number>;
56
- /** @internal */
57
- version: number;
58
- /** @internal */
59
- target: any;
60
- /** @internal */
61
- binding: Binding;
62
- /** @internal */
63
- isBindingVolatile: boolean;
64
- /** @internal */
65
- updateTarget: typeof updatePropertyTarget;
66
- /** @internal */
67
- targetName?: string;
74
+ export declare type UpdateTarget = (this: UpdateTargetThis, target: Node, aspect: string, value: any, source: any, context: ExecutionContext) => void;
75
+ /**
76
+ * A base binding behavior for DOM updates.
77
+ * @public
78
+ */
79
+ export declare class UpdateBinding implements ViewBehavior {
80
+ readonly directive: HTMLBindingDirective;
81
+ protected updateTarget: UpdateTarget;
82
+ /**
83
+ * Creates an instance of UpdateBinding.
84
+ * @param directive - The directive that has the configuration for this behavior.
85
+ * @param updateTarget - The function used to update the target with the latest value.
86
+ */
87
+ constructor(directive: HTMLBindingDirective, updateTarget: UpdateTarget);
68
88
  /**
69
89
  * Bind this behavior to the source.
70
90
  * @param source - The source to bind to.
71
91
  * @param context - The execution context that the binding is operating within.
92
+ * @param targets - The targets that behaviors in a view can attach to.
72
93
  */
73
- bind: typeof normalBind;
94
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
74
95
  /**
75
96
  * Unbinds this behavior from the source.
76
97
  * @param source - The source to unbind from.
98
+ * @param context - The execution context that the binding is operating within.
99
+ * @param targets - The targets that behaviors in a view can attach to.
77
100
  */
78
- unbind: typeof normalUnbind;
101
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
79
102
  /**
80
- * Creates an instance of BindingBehavior.
81
- * @param target - The target of the data updates.
82
- * @param binding - The binding that returns the latest value for an update.
83
- * @param isBindingVolatile - Indicates whether the binding has volatile dependencies.
84
- * @param bind - The operation to perform during binding.
85
- * @param unbind - The operation to perform during unbinding.
86
- * @param updateTarget - The operation to perform when updating.
87
- * @param targetName - The name of the target attribute or property to update.
103
+ * Creates a behavior.
104
+ * @param targets - The targets available for behaviors to be attached to.
88
105
  */
89
- constructor(target: any, binding: Binding, isBindingVolatile: boolean, bind: typeof normalBind, unbind: typeof normalUnbind, updateTarget: typeof updatePropertyTarget, targetName?: string);
106
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
107
+ }
108
+ /**
109
+ * A binding behavior for one-time bindings.
110
+ * @public
111
+ */
112
+ export declare class OneTimeBinding extends UpdateBinding {
113
+ /**
114
+ * Bind this behavior to the source.
115
+ * @param source - The source to bind to.
116
+ * @param context - The execution context that the binding is operating within.
117
+ * @param targets - The targets that behaviors in a view can attach to.
118
+ */
119
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
120
+ }
121
+ /**
122
+ * A binding behavior for signal bindings.
123
+ * @public
124
+ */
125
+ export declare class SignalBinding extends UpdateBinding {
126
+ private handlerProperty;
127
+ /**
128
+ * Bind this behavior to the source.
129
+ * @param source - The source to bind to.
130
+ * @param context - The execution context that the binding is operating within.
131
+ * @param targets - The targets that behaviors in a view can attach to.
132
+ */
133
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
134
+ /**
135
+ * Unbinds this behavior from the source.
136
+ * @param source - The source to unbind from.
137
+ * @param context - The execution context that the binding is operating within.
138
+ * @param targets - The targets that behaviors in a view can attach to.
139
+ */
140
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
141
+ private getSignal;
142
+ /**
143
+ * Sends the specified signal to signaled bindings.
144
+ * @param signal - The signal to send.
145
+ * @public
146
+ */
147
+ static send(signal: string): void;
148
+ }
149
+ /**
150
+ * A binding behavior for bindings that change.
151
+ * @public
152
+ */
153
+ export declare class ChangeBinding extends UpdateBinding {
154
+ private isBindingVolatile;
155
+ private observerProperty;
156
+ /**
157
+ * Creates an instance of ChangeBinding.
158
+ * @param directive - The directive that has the configuration for this behavior.
159
+ * @param updateTarget - The function used to update the target with the latest value.
160
+ */
161
+ constructor(directive: HTMLBindingDirective, updateTarget: UpdateTarget);
162
+ /**
163
+ * Returns the binding observer used to update the node.
164
+ * @param target - The target node.
165
+ * @returns A BindingObserver.
166
+ */
167
+ protected getObserver(target: Node): BindingObserver;
168
+ /**
169
+ * Bind this behavior to the source.
170
+ * @param source - The source to bind to.
171
+ * @param context - The execution context that the binding is operating within.
172
+ * @param targets - The targets that behaviors in a view can attach to.
173
+ */
174
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
175
+ /**
176
+ * Unbinds this behavior from the source.
177
+ * @param source - The source to unbind from.
178
+ * @param context - The execution context that the binding is operating within.
179
+ * @param targets - The targets that behaviors in a view can attach to.
180
+ */
181
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
90
182
  /** @internal */
91
- handleChange(): void;
183
+ handleChange(binding: Binding, observer: BindingObserver): void;
184
+ }
185
+ /**
186
+ * A binding behavior for handling events.
187
+ * @public
188
+ */
189
+ export declare class EventBinding {
190
+ readonly directive: HTMLBindingDirective;
191
+ private contextProperty;
192
+ private sourceProperty;
193
+ /**
194
+ * Creates an instance of EventBinding.
195
+ * @param directive - The directive that has the configuration for this behavior.
196
+ */
197
+ constructor(directive: HTMLBindingDirective);
198
+ /**
199
+ * Bind this behavior to the source.
200
+ * @param source - The source to bind to.
201
+ * @param context - The execution context that the binding is operating within.
202
+ * @param targets - The targets that behaviors in a view can attach to.
203
+ */
204
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
205
+ /**
206
+ * Unbinds this behavior from the source.
207
+ * @param source - The source to unbind from.
208
+ * @param context - The execution context that the binding is operating within.
209
+ * @param targets - The targets that behaviors in a view can attach to.
210
+ */
211
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
212
+ /**
213
+ * Creates a behavior.
214
+ * @param targets - The targets available for behaviors to be attached to.
215
+ */
216
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
217
+ /**
218
+ * @internal
219
+ */
220
+ handleEvent(event: Event): void;
221
+ }
222
+ /**
223
+ * The settings required to enable two-way binding.
224
+ * @public
225
+ */
226
+ export interface TwoWaySettings {
227
+ /**
228
+ * Determines which event to listen to, to detect changes in the view.
229
+ * @param directive - The directive to determine the change event for.
230
+ * @param target - The target element to determine the change event for.
231
+ */
232
+ determineChangeEvent(directive: HTMLBindingDirective, target: HTMLElement): string;
233
+ }
234
+ /**
235
+ * A binding behavior for bindings that update in two directions.
236
+ * @public
237
+ */
238
+ export declare class TwoWayBinding extends ChangeBinding {
239
+ private changeEvent;
240
+ /**
241
+ * Bind this behavior to the source.
242
+ * @param source - The source to bind to.
243
+ * @param context - The execution context that the binding is operating within.
244
+ * @param targets - The targets that behaviors in a view can attach to.
245
+ */
246
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
247
+ /**
248
+ * Unbinds this behavior from the source.
249
+ * @param source - The source to unbind from.
250
+ * @param context - The execution context that the binding is operating within.
251
+ * @param targets - The targets that behaviors in a view can attach to.
252
+ */
253
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
92
254
  /** @internal */
93
255
  handleEvent(event: Event): void;
256
+ /**
257
+ * Configures two-way binding.
258
+ * @param settings - The settings to use for the two-way binding system.
259
+ */
260
+ static configure(settings: TwoWaySettings): void;
94
261
  }
95
- export {};
262
+ /**
263
+ * The default binding options.
264
+ * @public
265
+ */
266
+ export declare type DefaultBindingOptions = AddEventListenerOptions;
267
+ /**
268
+ * The default onChange binding configuration.
269
+ * @public
270
+ */
271
+ export declare const onChange: BindingConfig<AddEventListenerOptions> & BindingConfigResolver<AddEventListenerOptions>;
272
+ /**
273
+ * The default twoWay binding options.
274
+ * @public
275
+ */
276
+ export declare type DefaultTwoWayBindingOptions = DefaultBindingOptions & {
277
+ changeEvent?: string;
278
+ fromView?: (value: any) => any;
279
+ };
280
+ /**
281
+ * The default twoWay binding configuration.
282
+ * @public
283
+ */
284
+ export declare const twoWay: BindingConfig<DefaultTwoWayBindingOptions> & BindingConfigResolver<DefaultTwoWayBindingOptions>;
285
+ /**
286
+ * The default onTime binding configuration.
287
+ * @public
288
+ */
289
+ export declare const oneTime: BindingConfig<AddEventListenerOptions> & BindingConfigResolver<AddEventListenerOptions>;
290
+ /**
291
+ * Creates a signal binding configuration with the supplied options.
292
+ * @param options - The signal name or a binding to use to retrieve the signal name.
293
+ * @returns A binding configuration.
294
+ * @public
295
+ */
296
+ export declare const signal: <T = any>(options: string | Binding<T, any, ExecutionContext<any>>) => BindingConfig<string | Binding<T, any, ExecutionContext<any>>>;
297
+ /**
298
+ * A directive that applies bindings.
299
+ * @public
300
+ */
301
+ export declare class HTMLBindingDirective implements HTMLDirective, ViewBehaviorFactory, Aspected {
302
+ binding: Binding;
303
+ mode: BindingMode;
304
+ options: any;
305
+ private factory;
306
+ /**
307
+ * The unique id of the factory.
308
+ */
309
+ id: string;
310
+ /**
311
+ * The structural id of the DOM node to which the created behavior will apply.
312
+ */
313
+ nodeId: string;
314
+ /**
315
+ * The original source aspect exactly as represented in markup.
316
+ */
317
+ sourceAspect: string;
318
+ /**
319
+ * The evaluated target aspect, determined after processing the source.
320
+ */
321
+ targetAspect: string;
322
+ /**
323
+ * The type of aspect to target.
324
+ */
325
+ aspectType: Aspect;
326
+ /**
327
+ * Creates an instance of HTMLBindingDirective.
328
+ * @param binding - The binding to apply.
329
+ * @param mode - The binding mode to use when applying the binding.
330
+ * @param options - The options to configure the binding with.
331
+ */
332
+ constructor(binding: Binding, mode: BindingMode, options: any);
333
+ /**
334
+ * Creates HTML to be used within a template.
335
+ * @param add - Can be used to add behavior factories to a template.
336
+ */
337
+ createHTML(add: AddViewBehaviorFactory): string;
338
+ /**
339
+ * Creates a behavior.
340
+ * @param targets - The targets available for behaviors to be attached to.
341
+ */
342
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
343
+ }
344
+ /**
345
+ * Creates a binding directive with the specified configuration.
346
+ * @param binding - The binding expression.
347
+ * @param config - The binding configuration.
348
+ * @returns A binding directive.
349
+ * @public
350
+ */
351
+ export declare function bind<T = any>(binding: Binding<T>, config?: BindingConfig | DefaultBindingOptions): CaptureType<T>;
@@ -1,16 +1,16 @@
1
- import { NodeBehaviorOptions, NodeObservationBehavior } from "./node-observation.js";
1
+ import { NodeBehaviorOptions, NodeObservationDirective } from "./node-observation.js";
2
2
  import type { CaptureType } from "./template.js";
3
3
  /**
4
4
  * The options used to configure child list observation.
5
5
  * @public
6
6
  */
7
- export interface ChildListBehaviorOptions<T = any> extends NodeBehaviorOptions<T>, Omit<MutationObserverInit, "subtree" | "childList"> {
7
+ export interface ChildListDirectiveOptions<T = any> extends NodeBehaviorOptions<T>, Omit<MutationObserverInit, "subtree" | "childList"> {
8
8
  }
9
9
  /**
10
10
  * The options used to configure subtree observation.
11
11
  * @public
12
12
  */
13
- export interface SubtreeBehaviorOptions<T = any> extends Omit<NodeBehaviorOptions<T>, "filter">, Omit<MutationObserverInit, "subtree" | "childList"> {
13
+ export interface SubtreeDirectiveOptions<T = any> extends NodeBehaviorOptions<T>, Omit<MutationObserverInit, "subtree" | "childList"> {
14
14
  /**
15
15
  * Indicates that child subtrees should be observed for changes.
16
16
  */
@@ -25,31 +25,34 @@ export interface SubtreeBehaviorOptions<T = any> extends Omit<NodeBehaviorOption
25
25
  * The options used to configure child/subtree node observation.
26
26
  * @public
27
27
  */
28
- export declare type ChildrenBehaviorOptions<T = any> = ChildListBehaviorOptions<T> | SubtreeBehaviorOptions<T>;
28
+ export declare type ChildrenDirectiveOptions<T = any> = ChildListDirectiveOptions<T> | SubtreeDirectiveOptions<T>;
29
29
  /**
30
30
  * The runtime behavior for child node observation.
31
31
  * @public
32
32
  */
33
- export declare class ChildrenBehavior extends NodeObservationBehavior<ChildrenBehaviorOptions> {
34
- private observer;
33
+ export declare class ChildrenDirective extends NodeObservationDirective<ChildrenDirectiveOptions> {
34
+ private observerProperty;
35
35
  /**
36
- * Creates an instance of ChildrenBehavior.
37
- * @param target - The element target to observe children on.
38
- * @param options - The options to use when observing the element children.
36
+ * Creates an instance of ChildrenDirective.
37
+ * @param options - The options to use in configuring the child observation behavior.
39
38
  */
40
- constructor(target: HTMLElement, options: ChildrenBehaviorOptions);
39
+ constructor(options: ChildrenDirectiveOptions);
41
40
  /**
42
41
  * Begins observation of the nodes.
42
+ * @param target - The target to observe.
43
43
  */
44
- observe(): void;
44
+ observe(target: any): void;
45
45
  /**
46
46
  * Disconnects observation of the nodes.
47
+ * @param target - The target to unobserve.
47
48
  */
48
- disconnect(): void;
49
+ disconnect(target: any): void;
49
50
  /**
50
- * Retrieves the nodes that should be assigned to the target.
51
+ * Retrieves the raw nodes that should be assigned to the source property.
52
+ * @param target - The target to get the node to.
51
53
  */
52
- protected getNodes(): ChildNode[];
54
+ getNodes(target: Element): Node[];
55
+ private handleEvent;
53
56
  }
54
57
  /**
55
58
  * A directive that observes the `childNodes` of an element and updates a property
@@ -57,4 +60,4 @@ export declare class ChildrenBehavior extends NodeObservationBehavior<ChildrenBe
57
60
  * @param propertyOrOptions - The options used to configure child node observation.
58
61
  * @public
59
62
  */
60
- export declare function children<T = any>(propertyOrOptions: (keyof T & string) | ChildrenBehaviorOptions<keyof T & string>): CaptureType<T>;
63
+ export declare function children<T = any>(propertyOrOptions: (keyof T & string) | ChildrenDirectiveOptions<keyof T & string>): CaptureType<T>;
@@ -1,38 +1,57 @@
1
- import type { HTMLDirective, NodeBehaviorFactory } from "./html-directive.js";
1
+ import { TrustedTypesPolicy } from "../interfaces.js";
2
+ import type { ExecutionContext } from "../observation/observable.js";
3
+ import { ViewBehaviorFactory } from "./html-directive.js";
4
+ import type { HTMLTemplateCompilationResult as TemplateCompilationResult } from "./template.js";
2
5
  /**
3
- * The result of compiling a template and its directives.
4
- * @beta
6
+ * A function capable of compiling a template from the preprocessed form produced
7
+ * by the html template function into a result that can instantiate views.
8
+ * @public
9
+ */
10
+ export declare type CompilationStrategy = (
11
+ /**
12
+ * The preprocessed HTML string or template to compile.
5
13
  */
6
- export interface CompilationResult {
14
+ html: string | HTMLTemplateElement,
15
+ /**
16
+ * The behavior factories used within the html that is being compiled.
17
+ */
18
+ factories: Record<string, ViewBehaviorFactory>) => TemplateCompilationResult;
19
+ /**
20
+ * Common APIs related to compilation.
21
+ * @public
22
+ */
23
+ export declare const Compiler: {
7
24
  /**
8
- * A cloneable DocumentFragment representing the compiled HTML.
25
+ * Sets the HTML trusted types policy used by the compiler.
26
+ * @param policy - The policy to set for HTML.
27
+ * @remarks
28
+ * This API can only be called once, for security reasons. It should be
29
+ * called by the application developer at the start of their program.
9
30
  */
10
- fragment: DocumentFragment;
31
+ setHTMLPolicy(policy: TrustedTypesPolicy): void;
11
32
  /**
12
- * The behaviors that should be applied to the template's HTML.
33
+ * Compiles a template and associated directives into a compilation
34
+ * result which can be used to create views.
35
+ * @param html - The html string or template element to compile.
36
+ * @param directives - The directives referenced by the template.
37
+ * @remarks
38
+ * The template that is provided for compilation is altered in-place
39
+ * and cannot be compiled again. If the original template must be preserved,
40
+ * it is recommended that you clone the original and pass the clone to this API.
41
+ * @public
13
42
  */
14
- viewBehaviorFactories: NodeBehaviorFactory[];
43
+ compile<TSource = any, TParent = any, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>>(html: string | HTMLTemplateElement, directives: Record<string, ViewBehaviorFactory>): TemplateCompilationResult<TSource, TParent, TContext>;
15
44
  /**
16
- * The behaviors that should be applied to the host element that
17
- * the template is rendered into.
45
+ * Sets the default compilation strategy that will be used by the ViewTemplate whenever
46
+ * it needs to compile a view preprocessed with the html template function.
47
+ * @param strategy - The compilation strategy to use when compiling templates.
18
48
  */
19
- hostBehaviorFactories: NodeBehaviorFactory[];
49
+ setDefaultStrategy(strategy: CompilationStrategy): void;
20
50
  /**
21
- * An index offset to apply to BehaviorFactory target indexes when
22
- * matching factories to targets.
51
+ * Aggregates an array of strings and directives into a single directive.
52
+ * @param parts - A heterogeneous array of static strings interspersed with
53
+ * directives.
54
+ * @returns A single inline directive that aggregates the behavior of all the parts.
23
55
  */
24
- targetOffset: number;
25
- }
26
- /**
27
- * Compiles a template and associated directives into a raw compilation
28
- * result which include a cloneable DocumentFragment and factories capable
29
- * of attaching runtime behavior to nodes within the fragment.
30
- * @param template - The template to compile.
31
- * @param directives - The directives referenced by the template.
32
- * @remarks
33
- * The template that is provided for compilation is altered in-place
34
- * and cannot be compiled again. If the original template must be preserved,
35
- * it is recommended that you clone the original and pass the clone to this API.
36
- * @public
37
- */
38
- export declare function compileTemplate(template: HTMLTemplateElement, directives: ReadonlyArray<HTMLDirective>): CompilationResult;
56
+ aggregate(parts: (string | ViewBehaviorFactory)[]): ViewBehaviorFactory;
57
+ };
@@ -0,0 +1,41 @@
1
+ import type { Callable } from "../interfaces.js";
2
+ /**
3
+ * Common DOM APIs.
4
+ * @public
5
+ */
6
+ export declare const DOM: Readonly<{
7
+ /**
8
+ * @deprecated
9
+ * Use Updates.enqueue().
10
+ */
11
+ queueUpdate: (callable: Callable) => void;
12
+ /**
13
+ * @deprecated
14
+ * Use Updates.next()
15
+ */
16
+ nextUpdate: () => Promise<void>;
17
+ /**
18
+ * @deprecated
19
+ * Use Updates.process()
20
+ */
21
+ processUpdates: () => void;
22
+ /**
23
+ * Sets an attribute value on an element.
24
+ * @param element - The element to set the attribute value on.
25
+ * @param attributeName - The attribute name to set.
26
+ * @param value - The value of the attribute to set.
27
+ * @remarks
28
+ * If the value is `null` or `undefined`, the attribute is removed, otherwise
29
+ * it is set to the provided value using the standard `setAttribute` API.
30
+ */
31
+ setAttribute(element: HTMLElement, attributeName: string, value: any): void;
32
+ /**
33
+ * Sets a boolean attribute value.
34
+ * @param element - The element to set the boolean attribute value on.
35
+ * @param attributeName - The attribute name to set.
36
+ * @param value - The value of the attribute to set.
37
+ * @remarks
38
+ * If the value is true, the attribute is added; otherwise it is removed.
39
+ */
40
+ setBooleanAttribute(element: HTMLElement, attributeName: string, value: boolean): void;
41
+ }>;