@microsoft/fast-element 1.10.2 → 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 (95) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +321 -1
  3. package/CHANGELOG.md +52 -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 +27 -35
  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 +13633 -5266
  75. package/dist/fast-element.d.ts +1434 -578
  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 +3574 -4020
  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 +4 -4
  85. package/docs/guide/defining-elements.md +2 -2
  86. package/docs/guide/next-steps.md +2 -2
  87. package/docs/guide/observables-and-state.md +1 -1
  88. package/docs/guide/using-directives.md +1 -1
  89. package/karma.conf.cjs +6 -17
  90. package/package.json +46 -14
  91. package/dist/dts/dom.d.ts +0 -112
  92. package/dist/dts/observation/array-change-records.d.ts +0 -48
  93. package/dist/dts/observation/array-observer.d.ts +0 -9
  94. package/dist/esm/dom.js +0 -207
  95. package/dist/esm/observation/array-observer.js +0 -177
@@ -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>;
@@ -1,9 +1,9 @@
1
- import { Binding, ExecutionContext } from "../observation/observable.js";
2
- import type { Subscriber } from "../observation/notifier.js";
3
- import type { Splice } from "../observation/array-change-records.js";
4
1
  import type { Behavior } from "../observation/behavior.js";
5
- import { HTMLDirective } from "./html-directive.js";
6
- import type { CaptureType, SyntheticViewTemplate } from "./template.js";
2
+ import type { Subscriber } from "../observation/notifier.js";
3
+ import { Binding, ChildContext, ExecutionContext, ItemContext, RootContext } from "../observation/observable.js";
4
+ import { Splice } from "../observation/arrays.js";
5
+ import { AddViewBehaviorFactory, HTMLDirective, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
6
+ import type { CaptureType, ChildViewTemplate, ItemViewTemplate, SyntheticViewTemplate, ViewTemplate } from "./template.js";
7
7
  /**
8
8
  * Options for configuring repeat behavior.
9
9
  * @public
@@ -34,7 +34,7 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
34
34
  private items;
35
35
  private itemsObserver;
36
36
  private itemsBindingObserver;
37
- private originalContext;
37
+ private context;
38
38
  private childContext;
39
39
  private bindView;
40
40
  /**
@@ -58,7 +58,11 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
58
58
  * @param source - The source to unbind from.
59
59
  */
60
60
  unbind(): void;
61
- /** @internal */
61
+ /**
62
+ * Handles changes in the array, its items, and the repeat template.
63
+ * @param source - The source of the change.
64
+ * @param args - The details about what was changed.
65
+ */
62
66
  handleChange(source: any, args: Splice[]): void;
63
67
  private observeItems;
64
68
  private updateViews;
@@ -69,17 +73,25 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
69
73
  * A directive that configures list rendering.
70
74
  * @public
71
75
  */
72
- export declare class RepeatDirective<TSource = any> extends HTMLDirective {
73
- private itemsBinding;
74
- private templateBinding;
75
- private options;
76
+ export declare class RepeatDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory {
77
+ readonly itemsBinding: Binding;
78
+ readonly templateBinding: Binding<TSource, SyntheticViewTemplate>;
79
+ readonly options: RepeatOptions;
76
80
  private isItemsBindingVolatile;
77
81
  private isTemplateBindingVolatile;
82
+ /**
83
+ * The unique id of the factory.
84
+ */
85
+ id: string;
86
+ /**
87
+ * The structural id of the DOM node to which the created behavior will apply.
88
+ */
89
+ nodeId: string;
78
90
  /**
79
91
  * Creates a placeholder string based on the directive's index within the template.
80
92
  * @param index - The index of the directive within the template.
81
93
  */
82
- createPlaceholder: (index: number) => string;
94
+ createHTML(add: AddViewBehaviorFactory): string;
83
95
  /**
84
96
  * Creates an instance of RepeatDirective.
85
97
  * @param itemsBinding - The binding that provides the array to render.
@@ -91,7 +103,7 @@ export declare class RepeatDirective<TSource = any> extends HTMLDirective {
91
103
  * Creates a behavior for the provided target node.
92
104
  * @param target - The node instance to create the behavior for.
93
105
  */
94
- createBehavior(target: Node): RepeatBehavior<TSource>;
106
+ createBehavior(targets: ViewBehaviorTargets): RepeatBehavior<TSource>;
95
107
  }
96
108
  /**
97
109
  * A directive that enables list rendering.
@@ -101,4 +113,50 @@ export declare class RepeatDirective<TSource = any> extends HTMLDirective {
101
113
  * @param options - Options used to turn on special repeat features.
102
114
  * @public
103
115
  */
104
- export declare function repeat<TSource = any, TItem = any>(itemsBinding: Binding<TSource, readonly TItem[]>, templateOrTemplateBinding: SyntheticViewTemplate | Binding<TSource, SyntheticViewTemplate>, options?: RepeatOptions): CaptureType<TSource>;
116
+ export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>>(itemsBinding: Binding<TSource, TArray, ExecutionContext<TSource>>, templateOrTemplateBinding: ViewTemplate | Binding<TSource, ViewTemplate, RootContext>, options?: {
117
+ positioning: false;
118
+ } | {
119
+ recycle: true;
120
+ } | {
121
+ positioning: false;
122
+ recycle: false;
123
+ } | {
124
+ positioning: false;
125
+ recycle: true;
126
+ }): CaptureType<TSource>;
127
+ /**
128
+ * A directive that enables list rendering.
129
+ * @param itemsBinding - The array to render.
130
+ * @param templateOrTemplateBinding - The template or a template binding used obtain a template
131
+ * to render for each item in the array.
132
+ * @param options - Options used to turn on special repeat features.
133
+ * @public
134
+ */
135
+ export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>>(itemsBinding: Binding<TSource, TArray, ExecutionContext<TSource>>, templateOrTemplateBinding: ChildViewTemplate | Binding<TSource, ChildViewTemplate, ChildContext>, options?: {
136
+ positioning: false;
137
+ } | {
138
+ recycle: true;
139
+ } | {
140
+ positioning: false;
141
+ recycle: false;
142
+ } | {
143
+ positioning: false;
144
+ recycle: true;
145
+ }): CaptureType<TSource>;
146
+ /**
147
+ * A directive that enables list rendering.
148
+ * @param itemsBinding - The array to render.
149
+ * @param templateOrTemplateBinding - The template or a template binding used obtain a template
150
+ * to render for each item in the array.
151
+ * @param options - Options used to turn on special repeat features.
152
+ * @public
153
+ */
154
+ export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>>(itemsBinding: Binding<TSource, TArray, ExecutionContext<TSource>>, templateOrTemplateBinding: ItemViewTemplate | Binding<TSource, ItemViewTemplate, ItemContext>, options: {
155
+ positioning: true;
156
+ } | {
157
+ positioning: true;
158
+ recycle: true;
159
+ } | {
160
+ positioning: true;
161
+ recycle: false;
162
+ }): CaptureType<TSource>;
@@ -1,34 +1,33 @@
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 slotted node observation.
5
5
  * @public
6
6
  */
7
- export interface SlottedBehaviorOptions<T = any> extends NodeBehaviorOptions<T>, AssignedNodesOptions {
7
+ export interface SlottedDirectiveOptions<T = any> extends NodeBehaviorOptions<T>, AssignedNodesOptions {
8
8
  }
9
9
  /**
10
10
  * The runtime behavior for slotted node observation.
11
11
  * @public
12
12
  */
13
- export declare class SlottedBehavior extends NodeObservationBehavior<SlottedBehaviorOptions> {
14
- /**
15
- * Creates an instance of SlottedBehavior.
16
- * @param target - The slot element target to observe.
17
- * @param options - The options to use when observing the slot.
18
- */
19
- constructor(target: HTMLSlotElement, options: SlottedBehaviorOptions);
13
+ export declare class SlottedDirective extends NodeObservationDirective<SlottedDirectiveOptions> {
20
14
  /**
21
15
  * Begins observation of the nodes.
16
+ * @param target - The target to observe.
22
17
  */
23
- observe(): void;
18
+ observe(target: EventSource): void;
24
19
  /**
25
20
  * Disconnects observation of the nodes.
21
+ * @param target - The target to unobserve.
26
22
  */
27
- disconnect(): void;
23
+ disconnect(target: EventSource): void;
28
24
  /**
29
- * Retrieves the nodes that should be assigned to the target.
25
+ * Retrieves the raw nodes that should be assigned to the source property.
26
+ * @param target - The target to get the node to.
30
27
  */
31
- protected getNodes(): Node[];
28
+ getNodes(target: HTMLSlotElement): Node[];
29
+ /** @internal */
30
+ handleEvent(event: Event): void;
32
31
  }
33
32
  /**
34
33
  * A directive that observes the `assignedNodes()` of a slot and updates a property
@@ -36,4 +35,4 @@ export declare class SlottedBehavior extends NodeObservationBehavior<SlottedBeha
36
35
  * @param propertyOrOptions - The options used to configure slotted node observation.
37
36
  * @public
38
37
  */
39
- export declare function slotted<T = any>(propertyOrOptions: (keyof T & string) | SlottedBehaviorOptions<keyof T & string>): CaptureType<T>;
38
+ export declare function slotted<T = any>(propertyOrOptions: (keyof T & string) | SlottedDirectiveOptions<keyof T & string>): CaptureType<T>;