@microsoft/fast-element 1.10.1 → 2.0.0-beta.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 (106) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +432 -1
  3. package/CHANGELOG.md +74 -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 +10 -2
  8. package/dist/dts/components/fast-element.d.ts +12 -5
  9. package/dist/dts/context.d.ts +157 -0
  10. package/dist/dts/debug.d.ts +1 -0
  11. package/dist/dts/hooks.d.ts +20 -0
  12. package/dist/dts/index.d.ts +16 -15
  13. package/dist/dts/index.debug.d.ts +2 -0
  14. package/dist/dts/index.rollup.d.ts +2 -0
  15. package/dist/dts/index.rollup.debug.d.ts +3 -0
  16. package/dist/dts/interfaces.d.ts +144 -0
  17. package/dist/dts/metadata.d.ts +25 -0
  18. package/dist/dts/observation/arrays.d.ts +207 -0
  19. package/dist/dts/observation/behavior.d.ts +4 -4
  20. package/dist/dts/observation/notifier.d.ts +18 -18
  21. package/dist/dts/observation/observable.d.ts +56 -18
  22. package/dist/dts/observation/splice-strategies.d.ts +13 -0
  23. package/dist/dts/observation/update-queue.d.ts +40 -0
  24. package/dist/dts/platform.d.ts +18 -67
  25. package/dist/dts/polyfills.d.ts +8 -0
  26. package/dist/dts/styles/css-directive.d.ts +43 -5
  27. package/dist/dts/styles/css.d.ts +19 -3
  28. package/dist/dts/styles/element-styles.d.ts +42 -62
  29. package/dist/dts/templating/binding-signal.d.ts +38 -0
  30. package/dist/dts/templating/binding-two-way.d.ts +56 -0
  31. package/dist/dts/templating/binding.d.ts +233 -65
  32. package/dist/dts/templating/children.d.ts +18 -15
  33. package/dist/dts/templating/compiler.d.ts +46 -28
  34. package/dist/dts/templating/dom.d.ts +41 -0
  35. package/dist/dts/templating/html-directive.d.ts +179 -43
  36. package/dist/dts/templating/markup.d.ts +48 -0
  37. package/dist/dts/templating/node-observation.d.ts +45 -29
  38. package/dist/dts/templating/ref.d.ts +6 -12
  39. package/dist/dts/templating/repeat.d.ts +26 -14
  40. package/dist/dts/templating/slotted.d.ts +13 -14
  41. package/dist/dts/templating/template.d.ts +27 -21
  42. package/dist/dts/templating/view.d.ts +15 -22
  43. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  44. package/dist/dts/utilities.d.ts +40 -0
  45. package/dist/esm/components/attributes.js +25 -24
  46. package/dist/esm/components/controller.js +77 -57
  47. package/dist/esm/components/fast-definitions.js +16 -22
  48. package/dist/esm/components/fast-element.js +10 -2
  49. package/dist/esm/context.js +159 -0
  50. package/dist/esm/debug.js +29 -0
  51. package/dist/esm/hooks.js +32 -0
  52. package/dist/esm/index.debug.js +2 -0
  53. package/dist/esm/index.js +19 -14
  54. package/dist/esm/index.rollup.debug.js +3 -0
  55. package/dist/esm/index.rollup.js +2 -0
  56. package/dist/esm/interfaces.js +8 -1
  57. package/dist/esm/metadata.js +60 -0
  58. package/dist/esm/observation/arrays.js +269 -0
  59. package/dist/esm/observation/notifier.js +75 -83
  60. package/dist/esm/observation/observable.js +93 -68
  61. package/dist/esm/observation/{array-change-records.js → splice-strategies.js} +136 -62
  62. package/dist/esm/observation/update-queue.js +67 -0
  63. package/dist/esm/platform.js +36 -42
  64. package/dist/esm/polyfills.js +85 -0
  65. package/dist/esm/styles/css-directive.js +29 -13
  66. package/dist/esm/styles/css.js +27 -40
  67. package/dist/esm/styles/element-styles.js +65 -104
  68. package/dist/esm/templating/binding-signal.js +84 -0
  69. package/dist/esm/templating/binding-two-way.js +76 -0
  70. package/dist/esm/templating/binding.js +306 -153
  71. package/dist/esm/templating/children.js +33 -23
  72. package/dist/esm/templating/compiler.js +235 -152
  73. package/dist/esm/templating/dom.js +49 -0
  74. package/dist/esm/templating/html-directive.js +125 -40
  75. package/dist/esm/templating/markup.js +75 -0
  76. package/dist/esm/templating/node-observation.js +50 -45
  77. package/dist/esm/templating/ref.js +7 -16
  78. package/dist/esm/templating/repeat.js +39 -36
  79. package/dist/esm/templating/slotted.js +23 -20
  80. package/dist/esm/templating/template.js +51 -95
  81. package/dist/esm/templating/view.js +44 -43
  82. package/dist/esm/templating/when.js +2 -1
  83. package/dist/esm/utilities.js +139 -0
  84. package/dist/fast-element.api.json +11789 -5377
  85. package/dist/fast-element.d.ts +1177 -531
  86. package/dist/fast-element.debug.js +3717 -0
  87. package/dist/fast-element.debug.min.js +1 -0
  88. package/dist/fast-element.js +3466 -4022
  89. package/dist/fast-element.min.js +1 -1
  90. package/dist/fast-element.untrimmed.d.ts +2697 -0
  91. package/docs/api-report.md +472 -219
  92. package/docs/fast-element-2-changes.md +15 -0
  93. package/docs/guide/declaring-templates.md +5 -4
  94. package/docs/guide/defining-elements.md +3 -2
  95. package/docs/guide/leveraging-css.md +1 -0
  96. package/docs/guide/next-steps.md +3 -2
  97. package/docs/guide/observables-and-state.md +2 -1
  98. package/docs/guide/using-directives.md +2 -1
  99. package/docs/guide/working-with-shadow-dom.md +1 -0
  100. package/karma.conf.cjs +6 -17
  101. package/package.json +65 -15
  102. package/dist/dts/dom.d.ts +0 -112
  103. package/dist/dts/observation/array-change-records.d.ts +0 -48
  104. package/dist/dts/observation/array-observer.d.ts +0 -9
  105. package/dist/esm/dom.js +0 -207
  106. package/dist/esm/observation/array-observer.js +0 -173
@@ -1,38 +1,56 @@
1
- import type { HTMLDirective, NodeBehaviorFactory } from "./html-directive.js";
1
+ import { TrustedTypesPolicy } from "../interfaces.js";
2
+ import { ViewBehaviorFactory } from "./html-directive.js";
3
+ import type { HTMLTemplateCompilationResult as TemplateCompilationResult } from "./template.js";
2
4
  /**
3
- * The result of compiling a template and its directives.
4
- * @beta
5
+ * A function capable of compiling a template from the preprocessed form produced
6
+ * by the html template function into a result that can instantiate views.
7
+ * @public
8
+ */
9
+ export declare type CompilationStrategy = (
10
+ /**
11
+ * The preprocessed HTML string or template to compile.
5
12
  */
6
- export interface CompilationResult {
13
+ html: string | HTMLTemplateElement,
14
+ /**
15
+ * The behavior factories used within the html that is being compiled.
16
+ */
17
+ factories: Record<string, ViewBehaviorFactory>) => TemplateCompilationResult;
18
+ /**
19
+ * Common APIs related to compilation.
20
+ * @public
21
+ */
22
+ export declare const Compiler: {
7
23
  /**
8
- * A cloneable DocumentFragment representing the compiled HTML.
24
+ * Sets the HTML trusted types policy used by the compiler.
25
+ * @param policy - The policy to set for HTML.
26
+ * @remarks
27
+ * This API can only be called once, for security reasons. It should be
28
+ * called by the application developer at the start of their program.
9
29
  */
10
- fragment: DocumentFragment;
30
+ setHTMLPolicy(policy: TrustedTypesPolicy): void;
11
31
  /**
12
- * The behaviors that should be applied to the template's HTML.
32
+ * Compiles a template and associated directives into a compilation
33
+ * result which can be used to create views.
34
+ * @param html - The html string or template element to compile.
35
+ * @param directives - The directives referenced by the template.
36
+ * @remarks
37
+ * The template that is provided for compilation is altered in-place
38
+ * and cannot be compiled again. If the original template must be preserved,
39
+ * it is recommended that you clone the original and pass the clone to this API.
40
+ * @public
13
41
  */
14
- viewBehaviorFactories: NodeBehaviorFactory[];
42
+ compile<TSource = any, TParent = any>(html: string | HTMLTemplateElement, directives: Record<string, ViewBehaviorFactory>): TemplateCompilationResult<TSource, TParent>;
15
43
  /**
16
- * The behaviors that should be applied to the host element that
17
- * the template is rendered into.
44
+ * Sets the default compilation strategy that will be used by the ViewTemplate whenever
45
+ * it needs to compile a view preprocessed with the html template function.
46
+ * @param strategy - The compilation strategy to use when compiling templates.
18
47
  */
19
- hostBehaviorFactories: NodeBehaviorFactory[];
48
+ setDefaultStrategy(strategy: CompilationStrategy): void;
20
49
  /**
21
- * An index offset to apply to BehaviorFactory target indexes when
22
- * matching factories to targets.
50
+ * Aggregates an array of strings and directives into a single directive.
51
+ * @param parts - A heterogeneous array of static strings interspersed with
52
+ * directives.
53
+ * @returns A single inline directive that aggregates the behavior of all the parts.
23
54
  */
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;
55
+ aggregate(parts: (string | ViewBehaviorFactory)[]): ViewBehaviorFactory;
56
+ };
@@ -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,226 @@
1
+ import type { Constructable } from "../interfaces.js";
1
2
  import type { Behavior } from "../observation/behavior.js";
3
+ import type { Binding, ExecutionContext } from "../observation/observable.js";
4
+ /**
5
+ * The target nodes available to a behavior.
6
+ * @public
7
+ */
8
+ export declare type ViewBehaviorTargets = {
9
+ [id: string]: Node;
10
+ };
11
+ /**
12
+ * Represents an object that can contribute behavior to a view.
13
+ * @public
14
+ */
15
+ export interface ViewBehavior<TSource = any, TParent = any> {
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
+ * @param targets - The targets that behaviors in a view can attach to.
21
+ */
22
+ bind(source: TSource, context: ExecutionContext<TParent>, targets: ViewBehaviorTargets): void;
23
+ /**
24
+ * Unbinds this behavior from the source.
25
+ * @param source - The source to unbind from.
26
+ * @param context - The execution context that the binding is operating within.
27
+ * @param targets - The targets that behaviors in a view can attach to.
28
+ */
29
+ unbind(source: TSource, context: ExecutionContext<TParent>, targets: ViewBehaviorTargets): void;
30
+ }
2
31
  /**
3
32
  * A factory that can create a {@link Behavior} associated with a particular
4
33
  * location within a DOM fragment.
5
34
  * @public
6
35
  */
7
- export interface NodeBehaviorFactory {
36
+ export interface ViewBehaviorFactory {
37
+ /**
38
+ * The unique id of the factory.
39
+ */
40
+ id: string;
8
41
  /**
9
- * The index of the DOM node to which the created behavior will apply.
42
+ * The structural id of the DOM node to which the created behavior will apply.
10
43
  */
11
- targetIndex: number;
44
+ nodeId: string;
12
45
  /**
13
- * Creates a behavior for the provided target node.
14
- * @param target - The node instance to create the behavior for.
46
+ * Creates a behavior.
47
+ * @param targets - The targets available for behaviors to be attached to.
15
48
  */
16
- createBehavior(target: Node): Behavior;
49
+ createBehavior(targets: ViewBehaviorTargets): Behavior | ViewBehavior;
17
50
  }
51
+ /**
52
+ * Used to add behavior factories when constructing templates.
53
+ * @public
54
+ */
55
+ export declare type AddViewBehaviorFactory = (factory: ViewBehaviorFactory) => string;
18
56
  /**
19
57
  * Instructs the template engine to apply behavior to a node.
20
58
  * @public
21
59
  */
22
- export declare abstract class HTMLDirective implements NodeBehaviorFactory {
60
+ export interface HTMLDirective {
23
61
  /**
24
- * The index of the DOM node to which the created behavior will apply.
62
+ * Creates HTML to be used within a template.
63
+ * @param add - Can be used to add behavior factories to a template.
25
64
  */
26
- targetIndex: number;
65
+ createHTML(add: AddViewBehaviorFactory): string;
66
+ }
67
+ /**
68
+ * Represents metadata configuration for an HTMLDirective.
69
+ * @public
70
+ */
71
+ export interface PartialHTMLDirectiveDefinition {
27
72
  /**
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.
73
+ * Indicates whether the directive needs access to template contextual information
74
+ * such as the sourceAspect, targetAspect, and aspectType.
30
75
  */
31
- abstract createPlaceholder(index: number): string;
76
+ aspected?: boolean;
77
+ }
78
+ /**
79
+ * Defines metadata for an HTMLDirective.
80
+ * @public
81
+ */
82
+ export interface HTMLDirectiveDefinition<TType extends Constructable<HTMLDirective> = Constructable<HTMLDirective>> extends Required<PartialHTMLDirectiveDefinition> {
32
83
  /**
33
- * Creates a behavior for the provided target node.
34
- * @param target - The node instance to create the behavior for.
84
+ * The type that the definition provides metadata for.
35
85
  */
36
- abstract createBehavior(target: Node): Behavior;
86
+ readonly type: TType;
37
87
  }
38
88
  /**
39
- * A {@link HTMLDirective} that targets a named attribute or property on a node.
89
+ * Instructs the template engine to apply behavior to a node.
40
90
  * @public
41
91
  */
42
- export declare abstract class TargetedHTMLDirective extends HTMLDirective {
92
+ export declare const HTMLDirective: Readonly<{
43
93
  /**
44
- * Gets/sets the name of the attribute or property that this
45
- * directive is targeting on the associated node.
94
+ * Gets the directive definition associated with the instance.
95
+ * @param instance - The directive instance to retrieve the definition for.
46
96
  */
47
- abstract targetName: string | undefined;
97
+ getForInstance: (object: any) => HTMLDirectiveDefinition<Constructable<HTMLDirective>> | undefined;
48
98
  /**
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.
99
+ * Gets the directive definition associated with the specified type.
100
+ * @param type - The directive type to retrieve the definition for.
51
101
  */
52
- createPlaceholder: (index: number) => string;
53
- }
102
+ getByType: (key: Function) => HTMLDirectiveDefinition<Constructable<HTMLDirective>> | undefined;
103
+ /**
104
+ * Defines an HTMLDirective based on the options.
105
+ * @param type - The type to define as a directive.
106
+ * @param options - Options that specify the directive's application.
107
+ */
108
+ define<TType extends Constructable<HTMLDirective>>(type: TType, options?: PartialHTMLDirectiveDefinition): TType;
109
+ }>;
54
110
  /**
55
- * Describes the shape of a behavior constructor that can be created by
56
- * an {@link AttachedBehaviorHTMLDirective}.
111
+ * Decorator: Defines an HTMLDirective.
112
+ * @param options - Provides options that specify the directive's application.
57
113
  * @public
58
114
  */
59
- export declare type AttachedBehaviorType<T = any> = new (target: any, options: T) => Behavior;
115
+ export declare function htmlDirective(options?: PartialHTMLDirectiveDefinition): (type: Constructable<HTMLDirective>) => void;
60
116
  /**
61
- * A directive that attaches special behavior to an element via a custom attribute.
117
+ * The type of HTML aspect to target.
62
118
  * @public
63
119
  */
64
- export declare class AttachedBehaviorHTMLDirective<T = any> extends HTMLDirective {
65
- private name;
66
- private behavior;
67
- private options;
120
+ export declare const Aspect: Readonly<{
121
+ /**
122
+ * Not aspected.
123
+ */
124
+ readonly none: 0;
125
+ /**
126
+ * An attribute.
127
+ */
128
+ readonly attribute: 1;
129
+ /**
130
+ * A boolean attribute.
131
+ */
132
+ readonly booleanAttribute: 2;
133
+ /**
134
+ * A property.
135
+ */
136
+ readonly property: 3;
137
+ /**
138
+ * Content
139
+ */
140
+ readonly content: 4;
141
+ /**
142
+ * A token list.
143
+ */
144
+ readonly tokenList: 5;
145
+ /**
146
+ * An event.
147
+ */
148
+ readonly event: 6;
68
149
  /**
69
150
  *
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.
151
+ * @param directive - The directive to assign the aspect to.
152
+ * @param value - The value to base the aspect determination on.
73
153
  */
74
- constructor(name: string, behavior: AttachedBehaviorType<T>, options: T);
154
+ readonly assign: (directive: Aspected, value: string) => void;
155
+ }>;
156
+ /**
157
+ * The type of HTML aspect to target.
158
+ * @public
159
+ */
160
+ export declare type Aspect = typeof Aspect[Exclude<keyof typeof Aspect, "assign" | "none">];
161
+ /**
162
+ * Represents something that applies to a specific aspect of the DOM.
163
+ * @public
164
+ */
165
+ export interface Aspected {
166
+ /**
167
+ * The original source aspect exactly as represented in markup.
168
+ */
169
+ sourceAspect: string;
170
+ /**
171
+ * The evaluated target aspect, determined after processing the source.
172
+ */
173
+ targetAspect: string;
174
+ /**
175
+ * The type of aspect to target.
176
+ */
177
+ aspectType: Aspect;
178
+ /**
179
+ * A binding if one is associated with the aspect.
180
+ */
181
+ binding?: Binding;
182
+ }
183
+ /**
184
+ * A base class used for attribute directives that don't need internal state.
185
+ * @public
186
+ */
187
+ export declare abstract class StatelessAttachedAttributeDirective<T> implements HTMLDirective, ViewBehaviorFactory, ViewBehavior {
188
+ protected options: T;
189
+ /**
190
+ * The unique id of the factory.
191
+ */
192
+ id: string;
193
+ /**
194
+ * The structural id of the DOM node to which the created behavior will apply.
195
+ */
196
+ nodeId: string;
197
+ /**
198
+ * Creates an instance of RefDirective.
199
+ * @param options - The options to use in configuring the directive.
200
+ */
201
+ constructor(options: T);
202
+ /**
203
+ * Creates a behavior.
204
+ * @param targets - The targets available for behaviors to be attached to.
205
+ */
206
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
75
207
  /**
76
208
  * Creates a placeholder string based on the directive's index within the template.
77
209
  * @param index - The index of the directive within the template.
78
210
  * @remarks
79
211
  * Creates a custom attribute placeholder.
80
212
  */
81
- createPlaceholder(index: number): string;
213
+ createHTML(add: AddViewBehaviorFactory): string;
82
214
  /**
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.
215
+ * Bind this behavior to the source.
216
+ * @param source - The source to bind to.
217
+ * @param context - The execution context that the binding is operating within.
218
+ * @param targets - The targets that behaviors in a view can attach to.
219
+ */
220
+ abstract bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
221
+ /**
222
+ * Unbinds this behavior from the source.
223
+ * @param source - The source to unbind from.
88
224
  */
89
- createBehavior(target: Node): Behavior;
225
+ abstract unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
90
226
  }
@@ -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,5 @@
1
- import type { Behavior } from "../observation/behavior.js";
1
+ import type { ExecutionContext } from "../observation/observable.js";
2
+ import { StatelessAttachedAttributeDirective, ViewBehaviorTargets } from "./html-directive.js";
2
3
  /**
3
4
  * Options for configuring node observation behavior.
4
5
  * @public
@@ -28,47 +29,62 @@ export declare type ElementsFilter = (value: Node, index: number, array: Node[])
28
29
  * @param selector - An optional selector to restrict the filter to.
29
30
  * @public
30
31
  */
31
- export declare function elements(selector?: string): ElementsFilter;
32
+ export declare const elements: (selector?: string) => ElementsFilter;
32
33
  /**
33
34
  * A base class for node observation.
34
- * @internal
35
+ * @public
36
+ * @remarks
37
+ * Internally used by the SlottedDirective and the ChildrenDirective.
35
38
  */
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;
39
+ export declare abstract class NodeObservationDirective<T extends NodeBehaviorOptions> extends StatelessAttachedAttributeDirective<T> {
40
+ private sourceProperty;
41
41
  /**
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.
42
+ * Bind this behavior to the source.
43
+ * @param source - The source to bind to.
44
+ * @param context - The execution context that the binding is operating within.
45
+ * @param targets - The targets that behaviors in a view can attach to.
45
46
  */
46
- constructor(target: HTMLElement, options: T);
47
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
47
48
  /**
48
- * Begins observation of the nodes.
49
+ * Unbinds this behavior from the source.
50
+ * @param source - The source to unbind from.
51
+ * @param context - The execution context that the binding is operating within.
52
+ * @param targets - The targets that behaviors in a view can attach to.
49
53
  */
50
- abstract observe(): void;
54
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
51
55
  /**
52
- * Disconnects observation of the nodes.
56
+ * Gets the data source for the target.
57
+ * @param target - The target to get the source for.
58
+ * @returns The source.
53
59
  */
54
- abstract disconnect(): void;
60
+ protected getSource(target: Node): any;
55
61
  /**
56
- * Retrieves the nodes that should be assigned to the target.
62
+ * Updates the source property with the computed nodes.
63
+ * @param source - The source object to assign the nodes property to.
64
+ * @param value - The nodes to assign to the source object property.
57
65
  */
58
- protected abstract getNodes(): Node[];
66
+ protected updateTarget(source: any, value: ReadonlyArray<any>): void;
59
67
  /**
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.
68
+ * Computes the set of nodes that should be assigned to the source property.
69
+ * @param target - The target to compute the nodes for.
70
+ * @returns The computed nodes.
71
+ * @remarks
72
+ * Applies filters if provided.
63
73
  */
64
- bind(source: any): void;
74
+ protected computeNodes(target: any): Node[];
65
75
  /**
66
- * Unbinds this behavior from the source.
67
- * @param source - The source to unbind from.
76
+ * Begins observation of the nodes.
77
+ * @param target - The target to observe.
78
+ */
79
+ protected abstract observe(target: any): void;
80
+ /**
81
+ * Disconnects observation of the nodes.
82
+ * @param target - The target to unobserve.
83
+ */
84
+ protected abstract disconnect(target: any): void;
85
+ /**
86
+ * Retrieves the raw nodes that should be assigned to the source property.
87
+ * @param target - The target to get the node to.
68
88
  */
69
- unbind(): void;
70
- /** @internal */
71
- handleEvent(): void;
72
- private computeNodes;
73
- private updateTarget;
89
+ protected abstract getNodes(target: any): Node[];
74
90
  }
@@ -1,24 +1,18 @@
1
- import type { Behavior } from "../observation/behavior.js";
1
+ import type { ExecutionContext } from "../observation/observable.js";
2
+ import { StatelessAttachedAttributeDirective, ViewBehaviorTargets } from "./html-directive.js";
2
3
  import type { CaptureType } from "./template.js";
3
4
  /**
4
5
  * The runtime behavior for template references.
5
6
  * @public
6
7
  */
7
- export declare class RefBehavior implements Behavior {
8
- private target;
9
- private propertyName;
10
- /**
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.
14
- */
15
- constructor(target: HTMLElement, propertyName: string);
8
+ export declare class RefDirective extends StatelessAttachedAttributeDirective<string> {
16
9
  /**
17
10
  * Bind this behavior to the source.
18
11
  * @param source - The source to bind to.
19
12
  * @param context - The execution context that the binding is operating within.
13
+ * @param targets - The targets that behaviors in a view can attach to.
20
14
  */
21
- bind(source: any): void;
15
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
22
16
  /**
23
17
  * Unbinds this behavior from the source.
24
18
  * @param source - The source to unbind from.
@@ -30,4 +24,4 @@ export declare class RefBehavior implements Behavior {
30
24
  * @param propertyName - The name of the property to assign the reference to.
31
25
  * @public
32
26
  */
33
- export declare function ref<T = any>(propertyName: keyof T & string): CaptureType<T>;
27
+ export declare const ref: <T = any>(propertyName: keyof T & string) => CaptureType<T>;