@microsoft/fast-element 1.10.5 → 2.0.0-beta.10

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 (122) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +629 -6
  3. package/CHANGELOG.md +152 -5
  4. package/dist/dts/components/attributes.d.ts +14 -1
  5. package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +32 -32
  6. package/dist/dts/components/fast-definitions.d.ts +51 -11
  7. package/dist/dts/components/fast-element.d.ts +18 -23
  8. package/dist/dts/context.d.ts +157 -0
  9. package/dist/{esm/observation/behavior.js → dts/debug.d.ts} +0 -0
  10. package/dist/dts/di/di.d.ts +899 -0
  11. package/dist/dts/index.d.ts +17 -16
  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 +176 -0
  16. package/dist/dts/metadata.d.ts +25 -0
  17. package/dist/dts/observation/arrays.d.ts +207 -0
  18. package/dist/dts/observation/notifier.d.ts +18 -18
  19. package/dist/dts/observation/observable.d.ts +117 -34
  20. package/dist/dts/observation/update-queue.d.ts +40 -0
  21. package/dist/dts/pending-task.d.ts +20 -0
  22. package/dist/dts/platform.d.ts +23 -66
  23. package/dist/dts/polyfills.d.ts +8 -0
  24. package/dist/dts/state/exports.d.ts +3 -0
  25. package/dist/dts/state/reactive.d.ts +8 -0
  26. package/dist/dts/state/state.d.ts +141 -0
  27. package/dist/dts/state/visitor.d.ts +6 -0
  28. package/dist/dts/state/watch.d.ts +10 -0
  29. package/dist/dts/styles/css-directive.d.ts +44 -6
  30. package/dist/dts/styles/css.d.ts +19 -3
  31. package/dist/dts/styles/element-styles.d.ts +49 -63
  32. package/dist/dts/styles/host.d.ts +68 -0
  33. package/dist/dts/templating/binding-signal.d.ts +21 -0
  34. package/dist/dts/templating/binding-two-way.d.ts +39 -0
  35. package/dist/dts/templating/binding.d.ts +101 -70
  36. package/dist/dts/templating/children.d.ts +18 -15
  37. package/dist/dts/templating/compiler.d.ts +46 -28
  38. package/dist/dts/templating/dom.d.ts +41 -0
  39. package/dist/dts/templating/html-directive.d.ts +239 -45
  40. package/dist/dts/templating/markup.d.ts +48 -0
  41. package/dist/dts/templating/node-observation.d.ts +45 -30
  42. package/dist/dts/templating/ref.d.ts +6 -20
  43. package/dist/dts/templating/render.d.ts +272 -0
  44. package/dist/dts/templating/repeat.d.ts +36 -33
  45. package/dist/dts/templating/slotted.d.ts +13 -14
  46. package/dist/dts/templating/template.d.ts +28 -22
  47. package/dist/dts/templating/view.d.ts +82 -24
  48. package/dist/dts/templating/when.d.ts +3 -3
  49. package/dist/dts/testing/exports.d.ts +3 -0
  50. package/dist/dts/testing/fakes.d.ts +4 -0
  51. package/dist/dts/testing/fixture.d.ts +84 -0
  52. package/dist/dts/testing/timeout.d.ts +7 -0
  53. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  54. package/dist/dts/utilities.d.ts +22 -0
  55. package/dist/esm/components/attributes.js +38 -28
  56. package/dist/esm/components/{controller.js → element-controller.js} +150 -140
  57. package/dist/esm/components/fast-definitions.js +48 -46
  58. package/dist/esm/components/fast-element.js +31 -12
  59. package/dist/esm/context.js +163 -0
  60. package/dist/esm/debug.js +61 -0
  61. package/dist/esm/di/di.js +1435 -0
  62. package/dist/esm/index.debug.js +2 -0
  63. package/dist/esm/index.js +20 -14
  64. package/dist/esm/index.rollup.debug.js +3 -0
  65. package/dist/esm/index.rollup.js +2 -0
  66. package/dist/esm/interfaces.js +12 -1
  67. package/dist/esm/metadata.js +60 -0
  68. package/dist/esm/observation/arrays.js +570 -0
  69. package/dist/esm/observation/notifier.js +27 -35
  70. package/dist/esm/observation/observable.js +116 -149
  71. package/dist/esm/observation/update-queue.js +67 -0
  72. package/dist/esm/pending-task.js +16 -0
  73. package/dist/esm/platform.js +60 -42
  74. package/dist/esm/polyfills.js +85 -0
  75. package/dist/esm/state/exports.js +3 -0
  76. package/dist/esm/state/reactive.js +34 -0
  77. package/dist/esm/state/state.js +148 -0
  78. package/dist/esm/state/visitor.js +28 -0
  79. package/dist/esm/state/watch.js +36 -0
  80. package/dist/esm/styles/css-directive.js +29 -13
  81. package/dist/esm/styles/css.js +29 -42
  82. package/dist/esm/styles/element-styles.js +79 -104
  83. package/dist/esm/styles/host.js +1 -0
  84. package/dist/esm/templating/binding-signal.js +83 -0
  85. package/dist/esm/templating/binding-two-way.js +103 -0
  86. package/dist/esm/templating/binding.js +189 -159
  87. package/dist/esm/templating/children.js +33 -23
  88. package/dist/esm/templating/compiler.js +258 -152
  89. package/dist/esm/templating/dom.js +49 -0
  90. package/dist/esm/templating/html-directive.js +193 -36
  91. package/dist/esm/templating/markup.js +75 -0
  92. package/dist/esm/templating/node-observation.js +51 -45
  93. package/dist/esm/templating/ref.js +8 -25
  94. package/dist/esm/templating/render.js +391 -0
  95. package/dist/esm/templating/repeat.js +83 -79
  96. package/dist/esm/templating/slotted.js +23 -20
  97. package/dist/esm/templating/template.js +51 -93
  98. package/dist/esm/templating/view.js +125 -46
  99. package/dist/esm/templating/when.js +6 -4
  100. package/dist/esm/testing/exports.js +3 -0
  101. package/dist/esm/testing/fakes.js +76 -0
  102. package/dist/esm/testing/fixture.js +86 -0
  103. package/dist/esm/testing/timeout.js +24 -0
  104. package/dist/esm/utilities.js +44 -0
  105. package/dist/fast-element.api.json +12153 -5373
  106. package/dist/fast-element.d.ts +1448 -696
  107. package/dist/fast-element.debug.js +4107 -0
  108. package/dist/fast-element.debug.min.js +1 -0
  109. package/dist/fast-element.js +3817 -4029
  110. package/dist/fast-element.min.js +1 -1
  111. package/dist/fast-element.untrimmed.d.ts +2814 -0
  112. package/docs/api-report.md +567 -254
  113. package/docs/fast-element-2-changes.md +15 -0
  114. package/karma.conf.cjs +6 -17
  115. package/package.json +76 -15
  116. package/dist/dts/dom.d.ts +0 -112
  117. package/dist/dts/observation/array-change-records.d.ts +0 -48
  118. package/dist/dts/observation/array-observer.d.ts +0 -9
  119. package/dist/dts/observation/behavior.d.ts +0 -19
  120. package/dist/esm/dom.js +0 -207
  121. package/dist/esm/observation/array-change-records.js +0 -326
  122. package/dist/esm/observation/array-observer.js +0 -177
@@ -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
+ }>;
@@ -1,90 +1,284 @@
1
- import type { Behavior } from "../observation/behavior.js";
1
+ import type { HostBehavior } from "../index.js";
2
+ import type { Constructable } from "../interfaces.js";
3
+ import type { Subscriber } from "../observation/notifier.js";
4
+ import { Expression, ExpressionController, ExpressionObserver } from "../observation/observable.js";
2
5
  /**
3
- * A factory that can create a {@link Behavior} associated with a particular
6
+ * The target nodes available to a behavior.
7
+ * @public
8
+ */
9
+ export declare type ViewBehaviorTargets = {
10
+ [id: string]: Node;
11
+ };
12
+ /**
13
+ * Controls the lifecycle of a view and provides relevant context.
14
+ * @public
15
+ */
16
+ export interface ViewController<TSource = any, TParent = any> extends ExpressionController<TSource, TParent> {
17
+ /**
18
+ * The parts of the view that are targeted by view behaviors.
19
+ */
20
+ readonly targets: ViewBehaviorTargets;
21
+ }
22
+ /**
23
+ * Bridges between ViewBehaviors and HostBehaviors, enabling a host to
24
+ * control ViewBehaviors.
25
+ * @public
26
+ */
27
+ export interface ViewBehaviorOrchestrator<TSource = any, TParent = any> extends ViewController<TSource, TParent>, HostBehavior<TSource> {
28
+ /**
29
+ *
30
+ * @param nodeId - The structural id of the DOM node to which a behavior will apply.
31
+ * @param target - The DOM node associated with the id.
32
+ */
33
+ addTarget(nodeId: string, target: Node): void;
34
+ /**
35
+ * Adds a behavior.
36
+ * @param behavior - The behavior to add.
37
+ */
38
+ addBehavior(behavior: ViewBehavior): void;
39
+ /**
40
+ * Adds a behavior factory.
41
+ * @param factory - The behavior factory to add.
42
+ * @param target - The target the factory will create behaviors for.
43
+ */
44
+ addBehaviorFactory(factory: ViewBehaviorFactory, target: Node): void;
45
+ }
46
+ /**
47
+ * Bridges between ViewBehaviors and HostBehaviors, enabling a host to
48
+ * control ViewBehaviors.
49
+ * @public
50
+ */
51
+ export declare const ViewBehaviorOrchestrator: Readonly<{
52
+ /**
53
+ * Creates a ViewBehaviorOrchestrator.
54
+ * @param source - The source to to associate behaviors with.
55
+ * @returns A ViewBehaviorOrchestrator.
56
+ */
57
+ create<TSource = any, TParent = any>(source: TSource): ViewBehaviorOrchestrator<TSource, TParent>;
58
+ }>;
59
+ /**
60
+ * Represents an object that can contribute behavior to a view.
61
+ * @public
62
+ */
63
+ export interface ViewBehavior<TSource = any, TParent = any> {
64
+ /**
65
+ * Bind this behavior.
66
+ * @param controller - The view controller that manages the lifecycle of this behavior.
67
+ */
68
+ bind(controller: ViewController<TSource, TParent>): void;
69
+ }
70
+ /**
71
+ * A factory that can create a {@link ViewBehavior} associated with a particular
4
72
  * location within a DOM fragment.
5
73
  * @public
6
74
  */
7
- export interface NodeBehaviorFactory {
75
+ export interface ViewBehaviorFactory {
76
+ /**
77
+ * The unique id of the factory.
78
+ */
79
+ id: string;
8
80
  /**
9
- * The index of the DOM node to which the created behavior will apply.
81
+ * The structural id of the DOM node to which the created behavior will apply.
10
82
  */
11
- targetIndex: number;
83
+ nodeId: string;
12
84
  /**
13
- * Creates a behavior for the provided target node.
14
- * @param target - The node instance to create the behavior for.
85
+ * Creates a behavior.
15
86
  */
16
- createBehavior(target: Node): Behavior;
87
+ createBehavior(): ViewBehavior;
17
88
  }
89
+ /**
90
+ * Used to add behavior factories when constructing templates.
91
+ * @public
92
+ */
93
+ export declare type AddViewBehaviorFactory = (factory: ViewBehaviorFactory) => string;
18
94
  /**
19
95
  * Instructs the template engine to apply behavior to a node.
20
96
  * @public
21
97
  */
22
- export declare abstract class HTMLDirective implements NodeBehaviorFactory {
98
+ export interface HTMLDirective {
23
99
  /**
24
- * The index of the DOM node to which the created behavior will apply.
100
+ * Creates HTML to be used within a template.
101
+ * @param add - Can be used to add behavior factories to a template.
25
102
  */
26
- targetIndex: number;
103
+ createHTML(add: AddViewBehaviorFactory): string;
104
+ }
105
+ /**
106
+ * Represents metadata configuration for an HTMLDirective.
107
+ * @public
108
+ */
109
+ export interface PartialHTMLDirectiveDefinition {
27
110
  /**
28
- * Creates a placeholder string based on the directive's index within the template.
29
- * @param index - The index of the directive within the template.
111
+ * Indicates whether the directive needs access to template contextual information
112
+ * such as the sourceAspect, targetAspect, and aspectType.
30
113
  */
31
- abstract createPlaceholder(index: number): string;
114
+ aspected?: boolean;
115
+ }
116
+ /**
117
+ * Defines metadata for an HTMLDirective.
118
+ * @public
119
+ */
120
+ export interface HTMLDirectiveDefinition<TType extends Constructable<HTMLDirective> = Constructable<HTMLDirective>> extends Required<PartialHTMLDirectiveDefinition> {
32
121
  /**
33
- * Creates a behavior for the provided target node.
34
- * @param target - The node instance to create the behavior for.
122
+ * The type that the definition provides metadata for.
35
123
  */
36
- abstract createBehavior(target: Node): Behavior;
124
+ readonly type: TType;
37
125
  }
38
126
  /**
39
- * A {@link HTMLDirective} that targets a named attribute or property on a node.
127
+ * Instructs the template engine to apply behavior to a node.
40
128
  * @public
41
129
  */
42
- export declare abstract class TargetedHTMLDirective extends HTMLDirective {
130
+ export declare const HTMLDirective: Readonly<{
43
131
  /**
44
- * Gets/sets the name of the attribute or property that this
45
- * directive is targeting on the associated node.
132
+ * Gets the directive definition associated with the instance.
133
+ * @param instance - The directive instance to retrieve the definition for.
46
134
  */
47
- abstract targetName: string | undefined;
135
+ getForInstance: (object: any) => HTMLDirectiveDefinition<Constructable<HTMLDirective>> | undefined;
48
136
  /**
49
- * Creates a placeholder string based on the directive's index within the template.
50
- * @param index - The index of the directive within the template.
137
+ * Gets the directive definition associated with the specified type.
138
+ * @param type - The directive type to retrieve the definition for.
51
139
  */
52
- createPlaceholder: (index: number) => string;
53
- }
140
+ getByType: (key: Function) => HTMLDirectiveDefinition<Constructable<HTMLDirective>> | undefined;
141
+ /**
142
+ * Defines an HTMLDirective based on the options.
143
+ * @param type - The type to define as a directive.
144
+ * @param options - Options that specify the directive's application.
145
+ */
146
+ define<TType extends Constructable<HTMLDirective>>(type: TType, options?: PartialHTMLDirectiveDefinition): TType;
147
+ }>;
54
148
  /**
55
- * Describes the shape of a behavior constructor that can be created by
56
- * an {@link AttachedBehaviorHTMLDirective}.
149
+ * Decorator: Defines an HTMLDirective.
150
+ * @param options - Provides options that specify the directive's application.
57
151
  * @public
58
152
  */
59
- export declare type AttachedBehaviorType<T = any> = new (target: any, options: T) => Behavior;
153
+ export declare function htmlDirective(options?: PartialHTMLDirectiveDefinition): (type: Constructable<HTMLDirective>) => void;
60
154
  /**
61
- * A directive that attaches special behavior to an element via a custom attribute.
155
+ * Captures a binding expression along with related information and capabilities.
156
+ *
62
157
  * @public
63
158
  */
64
- export declare class AttachedBehaviorHTMLDirective<T = any> extends HTMLDirective {
65
- private name;
66
- private behavior;
67
- private options;
159
+ export declare abstract class Binding<TSource = any, TReturn = any, TParent = any> {
160
+ evaluate: Expression<TSource, TReturn, TParent>;
161
+ isVolatile: boolean;
162
+ /**
163
+ * Options associated with the binding.
164
+ */
165
+ options?: any;
166
+ /**
167
+ * Creates a binding.
168
+ * @param evaluate - Evaluates the binding.
169
+ * @param isVolatile - Indicates whether the binding is volatile.
170
+ */
171
+ constructor(evaluate: Expression<TSource, TReturn, TParent>, isVolatile?: boolean);
172
+ /**
173
+ * Creates an observer capable of notifying a subscriber when the output of a binding changes.
174
+ * @param directive - The HTML Directive to create the observer for.
175
+ * @param subscriber - The subscriber to changes in the binding.
176
+ */
177
+ abstract createObserver(directive: HTMLDirective, subscriber: Subscriber): ExpressionObserver<TSource, TReturn, TParent>;
178
+ }
179
+ /**
180
+ * The type of HTML aspect to target.
181
+ * @public
182
+ */
183
+ export declare const Aspect: Readonly<{
184
+ /**
185
+ * Not aspected.
186
+ */
187
+ readonly none: 0;
188
+ /**
189
+ * An attribute.
190
+ */
191
+ readonly attribute: 1;
192
+ /**
193
+ * A boolean attribute.
194
+ */
195
+ readonly booleanAttribute: 2;
196
+ /**
197
+ * A property.
198
+ */
199
+ readonly property: 3;
200
+ /**
201
+ * Content
202
+ */
203
+ readonly content: 4;
204
+ /**
205
+ * A token list.
206
+ */
207
+ readonly tokenList: 5;
208
+ /**
209
+ * An event.
210
+ */
211
+ readonly event: 6;
68
212
  /**
69
213
  *
70
- * @param name - The name of the behavior; used as a custom attribute on the element.
71
- * @param behavior - The behavior to instantiate and attach to the element.
72
- * @param options - Options to pass to the behavior during creation.
214
+ * @param directive - The directive to assign the aspect to.
215
+ * @param value - The value to base the aspect determination on.
216
+ * @remarks
217
+ * If a falsy value is provided, then the content aspect will be assigned.
218
+ */
219
+ readonly assign: (directive: Aspected, value?: string) => void;
220
+ }>;
221
+ /**
222
+ * The type of HTML aspect to target.
223
+ * @public
224
+ */
225
+ export declare type Aspect = typeof Aspect[Exclude<keyof typeof Aspect, "assign" | "none">];
226
+ /**
227
+ * Represents something that applies to a specific aspect of the DOM.
228
+ * @public
229
+ */
230
+ export interface Aspected {
231
+ /**
232
+ * The original source aspect exactly as represented in markup.
233
+ */
234
+ sourceAspect: string;
235
+ /**
236
+ * The evaluated target aspect, determined after processing the source.
237
+ */
238
+ targetAspect: string;
239
+ /**
240
+ * The type of aspect to target.
241
+ */
242
+ aspectType: Aspect;
243
+ /**
244
+ * A binding if one is associated with the aspect.
73
245
  */
74
- constructor(name: string, behavior: AttachedBehaviorType<T>, options: T);
246
+ dataBinding?: Binding;
247
+ }
248
+ /**
249
+ * A base class used for attribute directives that don't need internal state.
250
+ * @public
251
+ */
252
+ export declare abstract class StatelessAttachedAttributeDirective<TOptions> implements HTMLDirective, ViewBehaviorFactory, ViewBehavior {
253
+ protected options: TOptions;
254
+ /**
255
+ * The unique id of the factory.
256
+ */
257
+ id: string;
258
+ /**
259
+ * The structural id of the DOM node to which the created behavior will apply.
260
+ */
261
+ nodeId: string;
262
+ /**
263
+ * Creates an instance of RefDirective.
264
+ * @param options - The options to use in configuring the directive.
265
+ */
266
+ constructor(options: TOptions);
75
267
  /**
76
268
  * Creates a placeholder string based on the directive's index within the template.
77
269
  * @param index - The index of the directive within the template.
78
270
  * @remarks
79
271
  * Creates a custom attribute placeholder.
80
272
  */
81
- createPlaceholder(index: number): string;
273
+ createHTML(add: AddViewBehaviorFactory): string;
82
274
  /**
83
- * Creates a behavior for the provided target node.
84
- * @param target - The node instance to create the behavior for.
85
- * @remarks
86
- * Creates an instance of the `behavior` type this directive was constructed with
87
- * and passes the target and options to that `behavior`'s constructor.
275
+ * Creates a behavior.
276
+ * @param targets - The targets available for behaviors to be attached to.
277
+ */
278
+ createBehavior(): ViewBehavior;
279
+ /**
280
+ * Bind this behavior.
281
+ * @param controller - The view controller that manages the lifecycle of this behavior.
88
282
  */
89
- createBehavior(target: Node): Behavior;
283
+ abstract bind(controller: ViewController): void;
90
284
  }
@@ -0,0 +1,48 @@
1
+ import type { ViewBehaviorFactory } from "./html-directive.js";
2
+ /** @internal */
3
+ export declare const nextId: () => string;
4
+ /**
5
+ * Common APIs related to markup generation.
6
+ * @public
7
+ */
8
+ export declare const Markup: Readonly<{
9
+ /**
10
+ * Creates a placeholder string suitable for marking out a location *within*
11
+ * an attribute value or HTML content.
12
+ * @param index - The directive index to create the placeholder for.
13
+ * @remarks
14
+ * Used internally by binding directives.
15
+ */
16
+ interpolation: (id: string) => string;
17
+ /**
18
+ * Creates a placeholder that manifests itself as an attribute on an
19
+ * element.
20
+ * @param attributeName - The name of the custom attribute.
21
+ * @param index - The directive index to create the placeholder for.
22
+ * @remarks
23
+ * Used internally by attribute directives such as `ref`, `slotted`, and `children`.
24
+ */
25
+ attribute: (id: string) => string;
26
+ /**
27
+ * Creates a placeholder that manifests itself as a marker within the DOM structure.
28
+ * @param index - The directive index to create the placeholder for.
29
+ * @remarks
30
+ * Used internally by structural directives such as `repeat`.
31
+ */
32
+ comment: (id: string) => string;
33
+ }>;
34
+ /**
35
+ * Common APIs related to content parsing.
36
+ * @public
37
+ */
38
+ export declare const Parser: Readonly<{
39
+ /**
40
+ * Parses text content or HTML attribute content, separating out the static strings
41
+ * from the directives.
42
+ * @param value - The content or attribute string to parse.
43
+ * @param factories - A list of directives to search for in the string.
44
+ * @returns A heterogeneous array of static strings interspersed with
45
+ * directives or null if no directives are found in the string.
46
+ */
47
+ parse(value: string, factories: Record<string, ViewBehaviorFactory>): (string | ViewBehaviorFactory)[] | null;
48
+ }>;
@@ -1,4 +1,4 @@
1
- import type { Behavior } from "../observation/behavior.js";
1
+ import { StatelessAttachedAttributeDirective, ViewController } from "./html-directive.js";
2
2
  /**
3
3
  * Options for configuring node observation behavior.
4
4
  * @public
@@ -22,53 +22,68 @@ export interface NodeBehaviorOptions<T = any> {
22
22
  *
23
23
  * @public
24
24
  */
25
- export declare type ElementsFilter = (value: Node, index: number, array: Node[]) => boolean;
25
+ export declare type ElementsFilter = (value: Node, index?: number, array?: Node[]) => boolean;
26
26
  /**
27
27
  * Creates a function that can be used to filter a Node array, selecting only elements.
28
28
  * @param selector - An optional selector to restrict the filter to.
29
29
  * @public
30
30
  */
31
- export declare function elements(selector?: string): ElementsFilter;
31
+ export declare const elements: (selector?: string) => ElementsFilter;
32
32
  /**
33
33
  * A base class for node observation.
34
- * @internal
34
+ * @public
35
+ * @remarks
36
+ * Internally used by the SlottedDirective and the ChildrenDirective.
35
37
  */
36
- export declare abstract class NodeObservationBehavior<T extends NodeBehaviorOptions> implements Behavior {
37
- protected target: HTMLElement;
38
- protected options: T;
39
- private source;
40
- private shouldUpdate;
38
+ export declare abstract class NodeObservationDirective<T extends NodeBehaviorOptions> extends StatelessAttachedAttributeDirective<T> {
39
+ private sourceProperty;
41
40
  /**
42
- * Creates an instance of NodeObservationBehavior.
43
- * @param target - The target to assign the nodes property on.
44
- * @param options - The options to use in configuring node observation.
41
+ * Bind this behavior to the source.
42
+ * @param source - The source to bind to.
43
+ * @param context - The execution context that the binding is operating within.
44
+ * @param targets - The targets that behaviors in a view can attach to.
45
45
  */
46
- constructor(target: HTMLElement, options: T);
46
+ bind(controller: ViewController): void;
47
47
  /**
48
- * Begins observation of the nodes.
48
+ * Unbinds this behavior from the source.
49
+ * @param source - The source to unbind from.
50
+ * @param context - The execution context that the binding is operating within.
51
+ * @param targets - The targets that behaviors in a view can attach to.
49
52
  */
50
- abstract observe(): void;
53
+ unbind(controller: ViewController): void;
51
54
  /**
52
- * Disconnects observation of the nodes.
55
+ * Gets the data source for the target.
56
+ * @param target - The target to get the source for.
57
+ * @returns The source.
53
58
  */
54
- abstract disconnect(): void;
59
+ protected getSource(target: Node): any;
55
60
  /**
56
- * Retrieves the nodes that should be assigned to the target.
61
+ * Updates the source property with the computed nodes.
62
+ * @param source - The source object to assign the nodes property to.
63
+ * @param value - The nodes to assign to the source object property.
57
64
  */
58
- protected abstract getNodes(): Node[];
65
+ protected updateTarget(source: any, value: ReadonlyArray<any>): void;
59
66
  /**
60
- * Bind this behavior to the source.
61
- * @param source - The source to bind to.
62
- * @param context - The execution context that the binding is operating within.
67
+ * Computes the set of nodes that should be assigned to the source property.
68
+ * @param target - The target to compute the nodes for.
69
+ * @returns The computed nodes.
70
+ * @remarks
71
+ * Applies filters if provided.
63
72
  */
64
- bind(source: any): void;
73
+ protected computeNodes(target: any): Node[];
65
74
  /**
66
- * Unbinds this behavior from the source.
67
- * @param source - The source to unbind from.
75
+ * Begins observation of the nodes.
76
+ * @param target - The target to observe.
77
+ */
78
+ protected abstract observe(target: any): void;
79
+ /**
80
+ * Disconnects observation of the nodes.
81
+ * @param target - The target to unobserve.
82
+ */
83
+ protected abstract disconnect(target: any): void;
84
+ /**
85
+ * Retrieves the raw nodes that should be assigned to the source property.
86
+ * @param target - The target to get the node to.
68
87
  */
69
- unbind(): void;
70
- /** @internal */
71
- handleEvent(): void;
72
- private computeNodes;
73
- private updateTarget;
88
+ protected abstract getNodes(target: any): Node[];
74
89
  }
@@ -1,33 +1,19 @@
1
- import type { Behavior } from "../observation/behavior.js";
1
+ import { StatelessAttachedAttributeDirective, ViewController } from "./html-directive.js";
2
2
  import type { CaptureType } from "./template.js";
3
3
  /**
4
4
  * The runtime behavior for template references.
5
5
  * @public
6
6
  */
7
- export declare class RefBehavior implements Behavior {
8
- private target;
9
- private propertyName;
7
+ export declare class RefDirective extends StatelessAttachedAttributeDirective<string> {
10
8
  /**
11
- * Creates an instance of RefBehavior.
12
- * @param target - The element to reference.
13
- * @param propertyName - The name of the property to assign the reference to.
9
+ * Bind this behavior.
10
+ * @param controller - The view controller that manages the lifecycle of this behavior.
14
11
  */
15
- constructor(target: HTMLElement, propertyName: string);
16
- /**
17
- * Bind this behavior to the source.
18
- * @param source - The source to bind to.
19
- * @param context - The execution context that the binding is operating within.
20
- */
21
- bind(source: any): void;
22
- /**
23
- * Unbinds this behavior from the source.
24
- * @param source - The source to unbind from.
25
- */
26
- unbind(): void;
12
+ bind(controller: ViewController): void;
27
13
  }
28
14
  /**
29
15
  * A directive that observes the updates a property with a reference to the element.
30
16
  * @param propertyName - The name of the property to assign the reference to.
31
17
  * @public
32
18
  */
33
- export declare function ref<T = any>(propertyName: keyof T & string): CaptureType<T>;
19
+ export declare const ref: <TSource = any, TParent = any>(propertyName: keyof TSource & string) => CaptureType<TSource, TParent>;