@microsoft/fast-element 2.0.0-beta.1 → 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.
- package/CHANGELOG.json +333 -0
- package/CHANGELOG.md +106 -1
- package/dist/dts/components/attributes.d.ts +10 -0
- package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +24 -25
- package/dist/dts/components/fast-definitions.d.ts +43 -9
- package/dist/dts/components/fast-element.d.ts +15 -21
- package/dist/dts/context.d.ts +157 -0
- package/dist/dts/di/di.d.ts +899 -0
- package/dist/dts/index.d.ts +2 -2
- package/dist/dts/interfaces.d.ts +44 -12
- package/dist/dts/metadata.d.ts +25 -0
- package/dist/dts/observation/arrays.d.ts +1 -1
- package/dist/dts/observation/observable.d.ts +101 -75
- package/dist/dts/pending-task.d.ts +20 -0
- package/dist/dts/platform.d.ts +6 -0
- package/dist/dts/state/exports.d.ts +3 -0
- package/dist/dts/state/reactive.d.ts +8 -0
- package/dist/dts/state/state.d.ts +141 -0
- package/dist/dts/state/visitor.d.ts +6 -0
- package/dist/dts/state/watch.d.ts +10 -0
- package/dist/dts/styles/css-directive.d.ts +2 -2
- package/dist/dts/styles/element-styles.d.ts +9 -3
- package/dist/dts/styles/host.d.ts +68 -0
- package/dist/dts/templating/binding-signal.d.ts +21 -0
- package/dist/dts/templating/binding-two-way.d.ts +39 -0
- package/dist/dts/templating/binding.d.ts +69 -294
- package/dist/dts/templating/children.d.ts +1 -1
- package/dist/dts/templating/compiler.d.ts +1 -2
- package/dist/dts/templating/html-directive.d.ts +93 -35
- package/dist/dts/templating/node-observation.d.ts +4 -5
- package/dist/dts/templating/ref.d.ts +5 -13
- package/dist/dts/templating/render.d.ts +272 -0
- package/dist/dts/templating/repeat.d.ts +20 -75
- package/dist/dts/templating/slotted.d.ts +1 -1
- package/dist/dts/templating/template.d.ts +12 -61
- package/dist/dts/templating/view.d.ts +77 -12
- package/dist/dts/templating/when.d.ts +3 -3
- package/dist/dts/testing/exports.d.ts +3 -0
- package/dist/dts/testing/fakes.d.ts +4 -0
- package/dist/dts/testing/fixture.d.ts +84 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +0 -0
- package/dist/dts/utilities.d.ts +0 -18
- package/dist/esm/components/attributes.js +13 -4
- package/dist/esm/components/{controller.js → element-controller.js} +95 -105
- package/dist/esm/components/fast-definitions.js +38 -28
- package/dist/esm/components/fast-element.js +31 -12
- package/dist/esm/context.js +163 -0
- package/dist/esm/debug.js +36 -4
- package/dist/esm/di/di.js +1435 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/interfaces.js +4 -0
- package/dist/esm/metadata.js +60 -0
- package/dist/esm/observation/arrays.js +304 -3
- package/dist/esm/observation/observable.js +81 -87
- package/dist/esm/pending-task.js +16 -0
- package/dist/esm/platform.js +25 -1
- package/dist/esm/state/exports.js +3 -0
- package/dist/esm/state/reactive.js +34 -0
- package/dist/esm/state/state.js +148 -0
- package/dist/esm/state/visitor.js +28 -0
- package/dist/esm/state/watch.js +36 -0
- package/dist/esm/styles/css.js +4 -4
- package/dist/esm/styles/element-styles.js +14 -0
- package/dist/esm/{observation/behavior.js → styles/host.js} +0 -0
- package/dist/esm/templating/binding-signal.js +83 -0
- package/dist/esm/templating/binding-two-way.js +103 -0
- package/dist/esm/templating/binding.js +134 -414
- package/dist/esm/templating/compiler.js +30 -7
- package/dist/esm/templating/html-directive.js +100 -28
- package/dist/esm/templating/node-observation.js +9 -8
- package/dist/esm/templating/ref.js +4 -12
- package/dist/esm/templating/render.js +391 -0
- package/dist/esm/templating/repeat.js +96 -72
- package/dist/esm/templating/template.js +11 -29
- package/dist/esm/templating/view.js +107 -29
- package/dist/esm/templating/when.js +5 -4
- package/dist/esm/testing/exports.js +3 -0
- package/dist/esm/testing/fakes.js +76 -0
- package/dist/esm/testing/fixture.js +86 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/utilities.js +0 -95
- package/dist/fast-element.api.json +9034 -10524
- package/dist/fast-element.d.ts +707 -811
- package/dist/fast-element.debug.js +1133 -850
- package/dist/fast-element.debug.min.js +1 -1
- package/dist/fast-element.js +1097 -846
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +724 -818
- package/docs/api-report.md +264 -305
- package/package.json +39 -10
- package/dist/dts/hooks.d.ts +0 -20
- package/dist/dts/observation/behavior.d.ts +0 -19
- package/dist/dts/observation/splice-strategies.d.ts +0 -13
- package/dist/esm/hooks.js +0 -32
- package/dist/esm/observation/splice-strategies.js +0 -400
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Behavior } from "../observation/behavior.js";
|
|
2
1
|
import type { Subscriber } from "../observation/notifier.js";
|
|
3
|
-
import {
|
|
2
|
+
import { Expression, ExpressionObserver } from "../observation/observable.js";
|
|
4
3
|
import { Splice } from "../observation/arrays.js";
|
|
5
|
-
import { AddViewBehaviorFactory, HTMLDirective, ViewBehaviorFactory,
|
|
6
|
-
import type { CaptureType,
|
|
4
|
+
import { AddViewBehaviorFactory, Binding, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewController } from "./html-directive.js";
|
|
5
|
+
import type { CaptureType, SyntheticViewTemplate, ViewTemplate } from "./template.js";
|
|
7
6
|
/**
|
|
8
7
|
* Options for configuring repeat behavior.
|
|
9
8
|
* @public
|
|
@@ -22,40 +21,34 @@ export interface RepeatOptions {
|
|
|
22
21
|
* A behavior that renders a template for each item in an array.
|
|
23
22
|
* @public
|
|
24
23
|
*/
|
|
25
|
-
export declare class RepeatBehavior<TSource = any> implements
|
|
24
|
+
export declare class RepeatBehavior<TSource = any> implements ViewBehavior, Subscriber {
|
|
25
|
+
private directive;
|
|
26
26
|
private location;
|
|
27
|
-
private
|
|
28
|
-
private templateBinding;
|
|
29
|
-
private options;
|
|
30
|
-
private source;
|
|
27
|
+
private controller;
|
|
31
28
|
private views;
|
|
32
29
|
private template;
|
|
33
30
|
private templateBindingObserver;
|
|
34
31
|
private items;
|
|
35
32
|
private itemsObserver;
|
|
36
33
|
private itemsBindingObserver;
|
|
37
|
-
private context;
|
|
38
|
-
private childContext;
|
|
39
34
|
private bindView;
|
|
40
35
|
/**
|
|
41
36
|
* Creates an instance of RepeatBehavior.
|
|
42
37
|
* @param location - The location in the DOM to render the repeat.
|
|
43
|
-
* @param
|
|
38
|
+
* @param dataBinding - The array to render.
|
|
44
39
|
* @param isItemsBindingVolatile - Indicates whether the items binding has volatile dependencies.
|
|
45
40
|
* @param templateBinding - The template to render for each item.
|
|
46
41
|
* @param isTemplateBindingVolatile - Indicates whether the template binding has volatile dependencies.
|
|
47
42
|
* @param options - Options used to turn on special repeat features.
|
|
48
43
|
*/
|
|
49
|
-
constructor(
|
|
44
|
+
constructor(directive: RepeatDirective);
|
|
50
45
|
/**
|
|
51
|
-
* Bind this behavior
|
|
52
|
-
* @param
|
|
53
|
-
* @param context - The execution context that the binding is operating within.
|
|
46
|
+
* Bind this behavior.
|
|
47
|
+
* @param controller - The view controller that manages the lifecycle of this behavior.
|
|
54
48
|
*/
|
|
55
|
-
bind(
|
|
49
|
+
bind(controller: ViewController): void;
|
|
56
50
|
/**
|
|
57
|
-
* Unbinds this behavior
|
|
58
|
-
* @param source - The source to unbind from.
|
|
51
|
+
* Unbinds this behavior.
|
|
59
52
|
*/
|
|
60
53
|
unbind(): void;
|
|
61
54
|
/**
|
|
@@ -63,7 +56,7 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
|
|
|
63
56
|
* @param source - The source of the change.
|
|
64
57
|
* @param args - The details about what was changed.
|
|
65
58
|
*/
|
|
66
|
-
handleChange(source: any, args: Splice[]): void;
|
|
59
|
+
handleChange(source: any, args: Splice[] | ExpressionObserver): void;
|
|
67
60
|
private observeItems;
|
|
68
61
|
private updateViews;
|
|
69
62
|
private refreshAllViews;
|
|
@@ -74,11 +67,9 @@ export declare class RepeatBehavior<TSource = any> implements Behavior, Subscrib
|
|
|
74
67
|
* @public
|
|
75
68
|
*/
|
|
76
69
|
export declare class RepeatDirective<TSource = any> implements HTMLDirective, ViewBehaviorFactory {
|
|
77
|
-
readonly
|
|
70
|
+
readonly dataBinding: Binding<TSource>;
|
|
78
71
|
readonly templateBinding: Binding<TSource, SyntheticViewTemplate>;
|
|
79
72
|
readonly options: RepeatOptions;
|
|
80
|
-
private isItemsBindingVolatile;
|
|
81
|
-
private isTemplateBindingVolatile;
|
|
82
73
|
/**
|
|
83
74
|
* The unique id of the factory.
|
|
84
75
|
*/
|
|
@@ -94,69 +85,23 @@ export declare class RepeatDirective<TSource = any> implements HTMLDirective, Vi
|
|
|
94
85
|
createHTML(add: AddViewBehaviorFactory): string;
|
|
95
86
|
/**
|
|
96
87
|
* Creates an instance of RepeatDirective.
|
|
97
|
-
* @param
|
|
88
|
+
* @param dataBinding - The binding that provides the array to render.
|
|
98
89
|
* @param templateBinding - The template binding used to obtain a template to render for each item in the array.
|
|
99
90
|
* @param options - Options used to turn on special repeat features.
|
|
100
91
|
*/
|
|
101
|
-
constructor(
|
|
92
|
+
constructor(dataBinding: Binding<TSource>, templateBinding: Binding<TSource, SyntheticViewTemplate>, options: RepeatOptions);
|
|
102
93
|
/**
|
|
103
94
|
* Creates a behavior for the provided target node.
|
|
104
95
|
* @param target - The node instance to create the behavior for.
|
|
105
96
|
*/
|
|
106
|
-
createBehavior(
|
|
97
|
+
createBehavior(): RepeatBehavior<TSource>;
|
|
107
98
|
}
|
|
108
99
|
/**
|
|
109
100
|
* A directive that enables list rendering.
|
|
110
|
-
* @param
|
|
111
|
-
* @param
|
|
101
|
+
* @param items - The array to render.
|
|
102
|
+
* @param template - The template or a template binding used obtain a template
|
|
112
103
|
* to render for each item in the array.
|
|
113
104
|
* @param options - Options used to turn on special repeat features.
|
|
114
105
|
* @public
|
|
115
106
|
*/
|
|
116
|
-
export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any
|
|
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>;
|
|
107
|
+
export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>, TParent = any>(items: Expression<TSource, TArray, TParent> | Binding<TSource, TArray, TParent> | ReadonlyArray<any>, template: Expression<TSource, ViewTemplate<any, TSource>> | Binding<TSource, ViewTemplate<any, TSource>> | ViewTemplate<any, TSource>, options?: RepeatOptions): CaptureType<TSource, TParent>;
|
|
@@ -35,4 +35,4 @@ export declare class SlottedDirective extends NodeObservationDirective<SlottedDi
|
|
|
35
35
|
* @param propertyOrOptions - The options used to configure slotted node observation.
|
|
36
36
|
* @public
|
|
37
37
|
*/
|
|
38
|
-
export declare function slotted<
|
|
38
|
+
export declare function slotted<TSource = any, TParent = any>(propertyOrOptions: (keyof TSource & string) | SlottedDirectiveOptions<keyof TSource & string>): CaptureType<TSource, TParent>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
|
|
1
|
+
import type { Expression } from "../observation/observable.js";
|
|
2
|
+
import { Binding, HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
|
|
3
3
|
import type { ElementView, HTMLView, SyntheticView } from "./view.js";
|
|
4
4
|
/**
|
|
5
5
|
* A template capable of creating views specifically for rendering custom elements.
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
8
|
export interface ElementViewTemplate<TSource = any, TParent = any> {
|
|
9
|
-
type: "element";
|
|
10
9
|
/**
|
|
11
10
|
* Creates an ElementView instance based on this template definition.
|
|
12
11
|
* @param hostBindingTarget - The element that host behaviors will be bound to.
|
|
@@ -25,57 +24,29 @@ export interface ElementViewTemplate<TSource = any, TParent = any> {
|
|
|
25
24
|
* A template capable of rendering views not specifically connected to custom elements.
|
|
26
25
|
* @public
|
|
27
26
|
*/
|
|
28
|
-
export interface SyntheticViewTemplate<TSource = any, TParent = any
|
|
29
|
-
type: "synthetic";
|
|
27
|
+
export interface SyntheticViewTemplate<TSource = any, TParent = any> {
|
|
30
28
|
/**
|
|
31
29
|
* Creates a SyntheticView instance based on this template definition.
|
|
32
30
|
*/
|
|
33
|
-
create(): SyntheticView<TSource, TParent
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* A template capable of rendering child views not specifically connected to custom elements.
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export interface ChildViewTemplate<TSource = any, TParent = any> {
|
|
40
|
-
type: "child";
|
|
41
|
-
/**
|
|
42
|
-
* Creates a SyntheticView instance based on this template definition.
|
|
43
|
-
*/
|
|
44
|
-
create(): SyntheticView<TSource, TParent, ChildContext<TParent>>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* A template capable of rendering item views not specifically connected to custom elements.
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
export interface ItemViewTemplate<TSource = any, TParent = any> {
|
|
51
|
-
type: "item";
|
|
52
|
-
/**
|
|
53
|
-
* Creates a SyntheticView instance based on this template definition.
|
|
54
|
-
*/
|
|
55
|
-
create(): SyntheticView<TSource, TParent, ItemContext<TParent>>;
|
|
31
|
+
create(): SyntheticView<TSource, TParent>;
|
|
56
32
|
}
|
|
57
33
|
/**
|
|
58
34
|
* The result of a template compilation operation.
|
|
59
35
|
* @public
|
|
60
36
|
*/
|
|
61
|
-
export interface HTMLTemplateCompilationResult<TSource = any, TParent = any
|
|
37
|
+
export interface HTMLTemplateCompilationResult<TSource = any, TParent = any> {
|
|
62
38
|
/**
|
|
63
39
|
* Creates a view instance.
|
|
64
40
|
* @param hostBindingTarget - The host binding target for the view.
|
|
65
41
|
*/
|
|
66
|
-
createView(hostBindingTarget?: Element): HTMLView<TSource, TParent
|
|
42
|
+
createView(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
|
|
67
43
|
}
|
|
68
44
|
/**
|
|
69
45
|
* A template capable of creating HTMLView instances or rendering directly to DOM.
|
|
70
46
|
* @public
|
|
71
47
|
*/
|
|
72
|
-
export declare class ViewTemplate<TSource = any, TParent = any
|
|
48
|
+
export declare class ViewTemplate<TSource = any, TParent = any> implements ElementViewTemplate<TSource, TParent>, SyntheticViewTemplate<TSource, TParent> {
|
|
73
49
|
private result;
|
|
74
|
-
/**
|
|
75
|
-
* Used for TypeScript purposes only.
|
|
76
|
-
* Do not use.
|
|
77
|
-
*/
|
|
78
|
-
type: any;
|
|
79
50
|
/**
|
|
80
51
|
* The html representing what this template will
|
|
81
52
|
* instantiate, including placeholders for directives.
|
|
@@ -95,7 +66,7 @@ export declare class ViewTemplate<TSource = any, TParent = any, TContext extends
|
|
|
95
66
|
* Creates an HTMLView instance based on this template definition.
|
|
96
67
|
* @param hostBindingTarget - The element that host behaviors will be bound to.
|
|
97
68
|
*/
|
|
98
|
-
create(hostBindingTarget?: Element): HTMLView<TSource, TParent
|
|
69
|
+
create(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
|
|
99
70
|
/**
|
|
100
71
|
* Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
|
|
101
72
|
* @param source - The data source to bind the template to.
|
|
@@ -103,20 +74,20 @@ export declare class ViewTemplate<TSource = any, TParent = any, TContext extends
|
|
|
103
74
|
* @param hostBindingTarget - An HTML element to target the host bindings at if different from the
|
|
104
75
|
* host that the template is being attached to.
|
|
105
76
|
*/
|
|
106
|
-
render(source: TSource, host: Node, hostBindingTarget?: Element
|
|
77
|
+
render(source: TSource, host: Node, hostBindingTarget?: Element): HTMLView<TSource, TParent>;
|
|
107
78
|
}
|
|
108
79
|
/**
|
|
109
80
|
* A marker interface used to capture types when interpolating Directive helpers
|
|
110
81
|
* into templates.
|
|
111
82
|
* @public
|
|
112
83
|
*/
|
|
113
|
-
export interface CaptureType<TSource> {
|
|
84
|
+
export interface CaptureType<TSource, TParent> {
|
|
114
85
|
}
|
|
115
86
|
/**
|
|
116
87
|
* Represents the types of values that can be interpolated into a template.
|
|
117
88
|
* @public
|
|
118
89
|
*/
|
|
119
|
-
export declare type TemplateValue<TSource, TParent = any
|
|
90
|
+
export declare type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource, TParent>;
|
|
120
91
|
/**
|
|
121
92
|
* Transforms a template literal string into a ViewTemplate.
|
|
122
93
|
* @param strings - The string fragments that are interpolated with the values.
|
|
@@ -126,24 +97,4 @@ export declare type TemplateValue<TSource, TParent = any, TContext extends Execu
|
|
|
126
97
|
* other template instances, and Directive instances.
|
|
127
98
|
* @public
|
|
128
99
|
*/
|
|
129
|
-
export declare function html<TSource = any, TParent = any
|
|
130
|
-
/**
|
|
131
|
-
* Transforms a template literal string into a ChildViewTemplate.
|
|
132
|
-
* @param strings - The string fragments that are interpolated with the values.
|
|
133
|
-
* @param values - The values that are interpolated with the string fragments.
|
|
134
|
-
* @remarks
|
|
135
|
-
* The html helper supports interpolation of strings, numbers, binding expressions,
|
|
136
|
-
* other template instances, and Directive instances.
|
|
137
|
-
* @public
|
|
138
|
-
*/
|
|
139
|
-
export declare const child: <TChild = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TChild, TParent, ChildContext<TParent>>[]) => ChildViewTemplate<TChild, TParent>;
|
|
140
|
-
/**
|
|
141
|
-
* Transforms a template literal string into an ItemViewTemplate.
|
|
142
|
-
* @param strings - The string fragments that are interpolated with the values.
|
|
143
|
-
* @param values - The values that are interpolated with the string fragments.
|
|
144
|
-
* @remarks
|
|
145
|
-
* The html helper supports interpolation of strings, numbers, binding expressions,
|
|
146
|
-
* other template instances, and Directive instances.
|
|
147
|
-
* @public
|
|
148
|
-
*/
|
|
149
|
-
export declare const item: <TItem = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TItem, TParent, ItemContext<TParent>>[]) => ItemViewTemplate<TItem, TParent>;
|
|
100
|
+
export declare function html<TSource = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TSource, TParent>[]): ViewTemplate<TSource, TParent>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Disposable } from "../interfaces.js";
|
|
2
|
-
import
|
|
3
|
-
import type { ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
|
|
2
|
+
import { ExecutionContext, SourceLifetime } from "../observation/observable.js";
|
|
3
|
+
import type { ViewBehaviorFactory, ViewBehaviorTargets, ViewController } from "./html-directive.js";
|
|
4
4
|
/**
|
|
5
5
|
* Represents a collection of DOM nodes which can be bound to a data source.
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
export interface View<TSource = any, TParent = any
|
|
8
|
+
export interface View<TSource = any, TParent = any> extends Disposable {
|
|
9
9
|
/**
|
|
10
10
|
* The execution context the view is running within.
|
|
11
11
|
*/
|
|
12
|
-
readonly context:
|
|
12
|
+
readonly context: ExecutionContext<TParent>;
|
|
13
13
|
/**
|
|
14
14
|
* The data that the view is bound to.
|
|
15
15
|
*/
|
|
@@ -17,9 +17,8 @@ export interface View<TSource = any, TParent = any, TContext extends ExecutionCo
|
|
|
17
17
|
/**
|
|
18
18
|
* Binds a view's behaviors to its binding source.
|
|
19
19
|
* @param source - The binding source for the view's binding behaviors.
|
|
20
|
-
* @param context - The execution context to run the view within.
|
|
21
20
|
*/
|
|
22
|
-
bind(source: TSource, context
|
|
21
|
+
bind(source: TSource, context?: ExecutionContext<TParent>): void;
|
|
23
22
|
/**
|
|
24
23
|
* Unbinds a view's behaviors from its binding source and context.
|
|
25
24
|
*/
|
|
@@ -29,7 +28,7 @@ export interface View<TSource = any, TParent = any, TContext extends ExecutionCo
|
|
|
29
28
|
* A View representing DOM nodes specifically for rendering the view of a custom element.
|
|
30
29
|
* @public
|
|
31
30
|
*/
|
|
32
|
-
export interface ElementView<TSource = any, TParent = any> extends View<TSource, TParent
|
|
31
|
+
export interface ElementView<TSource = any, TParent = any> extends View<TSource, TParent> {
|
|
33
32
|
/**
|
|
34
33
|
* Appends the view's DOM nodes to the referenced node.
|
|
35
34
|
* @param node - The parent node to append the view's DOM nodes to.
|
|
@@ -40,7 +39,7 @@ export interface ElementView<TSource = any, TParent = any> extends View<TSource,
|
|
|
40
39
|
* A view representing a range of DOM nodes which can be added/removed ad hoc.
|
|
41
40
|
* @public
|
|
42
41
|
*/
|
|
43
|
-
export interface SyntheticView<TSource = any, TParent = any
|
|
42
|
+
export interface SyntheticView<TSource = any, TParent = any> extends View<TSource, TParent> {
|
|
44
43
|
/**
|
|
45
44
|
* The first DOM node in the range of nodes that make up the view.
|
|
46
45
|
*/
|
|
@@ -64,19 +63,81 @@ export interface SyntheticView<TSource = any, TParent = any, TContext extends Ex
|
|
|
64
63
|
* The standard View implementation, which also implements ElementView and SyntheticView.
|
|
65
64
|
* @public
|
|
66
65
|
*/
|
|
67
|
-
export declare class HTMLView<TSource = any, TParent = any
|
|
66
|
+
export declare class HTMLView<TSource = any, TParent = any> implements ElementView<TSource, TParent>, SyntheticView<TSource, TParent>, ExecutionContext<TParent> {
|
|
68
67
|
private fragment;
|
|
69
68
|
private factories;
|
|
70
|
-
|
|
69
|
+
readonly targets: ViewBehaviorTargets;
|
|
71
70
|
private behaviors;
|
|
71
|
+
private unbindables;
|
|
72
72
|
/**
|
|
73
73
|
* The data that the view is bound to.
|
|
74
74
|
*/
|
|
75
75
|
source: TSource | null;
|
|
76
|
+
/**
|
|
77
|
+
* Indicates whether the controller is bound.
|
|
78
|
+
*/
|
|
79
|
+
isBound: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Indicates how the source's lifetime relates to the controller's lifetime.
|
|
82
|
+
*/
|
|
83
|
+
readonly sourceLifetime: SourceLifetime;
|
|
76
84
|
/**
|
|
77
85
|
* The execution context the view is running within.
|
|
78
86
|
*/
|
|
79
|
-
context:
|
|
87
|
+
context: ExecutionContext<TParent>;
|
|
88
|
+
/**
|
|
89
|
+
* The index of the current item within a repeat context.
|
|
90
|
+
*/
|
|
91
|
+
index: number;
|
|
92
|
+
/**
|
|
93
|
+
* The length of the current collection within a repeat context.
|
|
94
|
+
*/
|
|
95
|
+
length: number;
|
|
96
|
+
/**
|
|
97
|
+
* The parent data source within a nested context.
|
|
98
|
+
*/
|
|
99
|
+
readonly parent: TParent;
|
|
100
|
+
/**
|
|
101
|
+
* The parent execution context when in nested context scenarios.
|
|
102
|
+
*/
|
|
103
|
+
readonly parentContext: ExecutionContext<TParent>;
|
|
104
|
+
/**
|
|
105
|
+
* The current event within an event handler.
|
|
106
|
+
*/
|
|
107
|
+
get event(): Event;
|
|
108
|
+
/**
|
|
109
|
+
* Indicates whether the current item within a repeat context
|
|
110
|
+
* has an even index.
|
|
111
|
+
*/
|
|
112
|
+
get isEven(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Indicates whether the current item within a repeat context
|
|
115
|
+
* has an odd index.
|
|
116
|
+
*/
|
|
117
|
+
get isOdd(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Indicates whether the current item within a repeat context
|
|
120
|
+
* is the first item in the collection.
|
|
121
|
+
*/
|
|
122
|
+
get isFirst(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Indicates whether the current item within a repeat context
|
|
125
|
+
* is somewhere in the middle of the collection.
|
|
126
|
+
*/
|
|
127
|
+
get isInMiddle(): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Indicates whether the current item within a repeat context
|
|
130
|
+
* is the last item in the collection.
|
|
131
|
+
*/
|
|
132
|
+
get isLast(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Returns the typed event detail of a custom event.
|
|
135
|
+
*/
|
|
136
|
+
eventDetail<TDetail>(): TDetail;
|
|
137
|
+
/**
|
|
138
|
+
* Returns the typed event target of the event.
|
|
139
|
+
*/
|
|
140
|
+
eventTarget<TTarget extends EventTarget>(): TTarget;
|
|
80
141
|
/**
|
|
81
142
|
* The first DOM node in the range of nodes that make up the view.
|
|
82
143
|
*/
|
|
@@ -111,16 +172,20 @@ export declare class HTMLView<TSource = any, TParent = any, TContext extends Exe
|
|
|
111
172
|
* Once a view has been disposed, it cannot be inserted or bound again.
|
|
112
173
|
*/
|
|
113
174
|
dispose(): void;
|
|
175
|
+
onUnbind(behavior: {
|
|
176
|
+
unbind(controller: ViewController<TSource, TParent>): any;
|
|
177
|
+
}): void;
|
|
114
178
|
/**
|
|
115
179
|
* Binds a view's behaviors to its binding source.
|
|
116
180
|
* @param source - The binding source for the view's binding behaviors.
|
|
117
181
|
* @param context - The execution context to run the behaviors within.
|
|
118
182
|
*/
|
|
119
|
-
bind(source: TSource, context
|
|
183
|
+
bind(source: TSource, context?: ExecutionContext<TParent>): void;
|
|
120
184
|
/**
|
|
121
185
|
* Unbinds a view's behaviors from its binding source.
|
|
122
186
|
*/
|
|
123
187
|
unbind(): void;
|
|
188
|
+
private evaluateUnbindables;
|
|
124
189
|
/**
|
|
125
190
|
* Efficiently disposes of a contiguous range of synthetic view instances.
|
|
126
191
|
* @param views - A contiguous range of views to be disposed.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Expression } from "../observation/observable.js";
|
|
2
2
|
import type { CaptureType, SyntheticViewTemplate } from "./template.js";
|
|
3
3
|
/**
|
|
4
4
|
* A directive that enables basic conditional rendering in a template.
|
|
5
|
-
* @param
|
|
5
|
+
* @param condition - The condition to test for rendering.
|
|
6
6
|
* @param templateOrTemplateBinding - The template or a binding that gets
|
|
7
7
|
* the template to render when the condition is true.
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
|
-
export declare function when<TSource = any, TReturn = any>(
|
|
10
|
+
export declare function when<TSource = any, TReturn = any, TParent = any>(condition: Expression<TSource, TReturn, TParent> | boolean, templateOrTemplateBinding: SyntheticViewTemplate<TSource, TParent> | Expression<TSource, SyntheticViewTemplate<TSource, TParent>, TParent>): CaptureType<TSource, TParent>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Constructable } from "../interfaces.js";
|
|
2
|
+
import { ViewTemplate } from "../templating/template.js";
|
|
3
|
+
import type { HTMLView } from "../templating/view.js";
|
|
4
|
+
/**
|
|
5
|
+
* Options used to customize the creation of the test fixture.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface FixtureOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The document to run the fixture in.
|
|
11
|
+
* @defaultValue `globalThis.document`
|
|
12
|
+
*/
|
|
13
|
+
document?: Document;
|
|
14
|
+
/**
|
|
15
|
+
* The parent element to append the fixture to.
|
|
16
|
+
* @defaultValue An instance of `HTMLDivElement`.
|
|
17
|
+
*/
|
|
18
|
+
parent?: HTMLElement;
|
|
19
|
+
/**
|
|
20
|
+
* The data source to bind the HTML to.
|
|
21
|
+
* @defaultValue An empty object.
|
|
22
|
+
*/
|
|
23
|
+
source?: any;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A test fixture.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export interface Fixture<TElement = HTMLElement> {
|
|
30
|
+
/**
|
|
31
|
+
* The document the fixture is running in.
|
|
32
|
+
*/
|
|
33
|
+
document: Document;
|
|
34
|
+
/**
|
|
35
|
+
* The template the fixture was created from.
|
|
36
|
+
*/
|
|
37
|
+
template: ViewTemplate;
|
|
38
|
+
/**
|
|
39
|
+
* The view that was created from the fixture's template.
|
|
40
|
+
*/
|
|
41
|
+
view: HTMLView;
|
|
42
|
+
/**
|
|
43
|
+
* The parent element that the view was appended to.
|
|
44
|
+
* @remarks
|
|
45
|
+
* This element will be appended to the DOM only
|
|
46
|
+
* after {@link Fixture.connect} has been called.
|
|
47
|
+
*/
|
|
48
|
+
parent: HTMLElement;
|
|
49
|
+
/**
|
|
50
|
+
* The first element in the {@link Fixture.view}.
|
|
51
|
+
*/
|
|
52
|
+
element: TElement;
|
|
53
|
+
/**
|
|
54
|
+
* Adds the {@link Fixture.parent} to the DOM, causing the
|
|
55
|
+
* connect lifecycle to begin.
|
|
56
|
+
* @remarks
|
|
57
|
+
* Yields control to the caller one Microtask later, in order to
|
|
58
|
+
* ensure that the DOM has settled.
|
|
59
|
+
*/
|
|
60
|
+
connect: () => Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Removes the {@link Fixture.parent} from the DOM, causing the
|
|
63
|
+
* disconnect lifecycle to begin.
|
|
64
|
+
* @remarks
|
|
65
|
+
* Yields control to the caller one Microtask later, in order to
|
|
66
|
+
* ensure that the DOM has settled.
|
|
67
|
+
*/
|
|
68
|
+
disconnect: () => Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a random, unique name suitable for use as a Custom Element name.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export declare function uniqueElementName(prefix?: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a test fixture suitable for testing custom elements, templates, and bindings.
|
|
77
|
+
* @param templateNameOrType An HTML template or single element name to create the fixture for.
|
|
78
|
+
* @param options Enables customizing fixture creation behavior.
|
|
79
|
+
* @remarks
|
|
80
|
+
* Yields control to the caller one Microtask later, in order to
|
|
81
|
+
* ensure that the DOM has settled.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export declare function fixture<TElement = HTMLElement>(templateNameOrType: ViewTemplate | string | Constructable<TElement>, options?: FixtureOptions): Promise<Fixture<TElement>>;
|
|
File without changes
|
package/dist/dts/utilities.d.ts
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
import { Disposable } from "./interfaces.js";
|
|
2
|
-
import type { Subscriber } from "./observation/notifier.js";
|
|
3
|
-
/**
|
|
4
|
-
* Converts a plain object to an observable object.
|
|
5
|
-
* @param object - The object to make observable.
|
|
6
|
-
* @param deep - Indicates whether or not to deeply convert the oject.
|
|
7
|
-
* @returns The converted object.
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
export declare function makeObservable<T>(object: T, deep?: boolean): T;
|
|
11
|
-
/**
|
|
12
|
-
* Deeply subscribes to changes in existing observable objects.
|
|
13
|
-
* @param object - The observable object to watch.
|
|
14
|
-
* @param subscriber - The handler to call when changes are made to the object.
|
|
15
|
-
* @returns A disposable that can be used to unsubscribe from change updates.
|
|
16
|
-
* @beta
|
|
17
|
-
*/
|
|
18
|
-
export declare function watch(object: any, subscriber: Subscriber | ((subject: any, args: any) => void)): Disposable;
|
|
19
1
|
/**
|
|
20
2
|
* Retrieves the "composed parent" element of a node, ignoring DOM tree boundaries.
|
|
21
3
|
* When the parent of a node is a shadow-root, it will return the host
|
|
@@ -2,8 +2,19 @@ import { Observable } from "../observation/observable.js";
|
|
|
2
2
|
import { isString } from "../interfaces.js";
|
|
3
3
|
import { Updates } from "../observation/update-queue.js";
|
|
4
4
|
import { DOM } from "../templating/dom.js";
|
|
5
|
+
import { createMetadataLocator } from "../platform.js";
|
|
5
6
|
const booleanMode = "boolean";
|
|
6
7
|
const reflectMode = "reflect";
|
|
8
|
+
/**
|
|
9
|
+
* Metadata used to configure a custom attribute's behavior.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const AttributeConfiguration = Object.freeze({
|
|
13
|
+
/**
|
|
14
|
+
* Locates all attribute configurations associated with a type.
|
|
15
|
+
*/
|
|
16
|
+
locate: createMetadataLocator(),
|
|
17
|
+
});
|
|
7
18
|
/**
|
|
8
19
|
* A {@link ValueConverter} that converts to and from `boolean` values.
|
|
9
20
|
* @remarks
|
|
@@ -141,7 +152,7 @@ export class AttributeDefinition {
|
|
|
141
152
|
*/
|
|
142
153
|
static collect(Owner, ...attributeLists) {
|
|
143
154
|
const attributes = [];
|
|
144
|
-
attributeLists.push(Owner
|
|
155
|
+
attributeLists.push(AttributeConfiguration.locate(Owner));
|
|
145
156
|
for (let i = 0, ii = attributeLists.length; i < ii; ++i) {
|
|
146
157
|
const list = attributeLists[i];
|
|
147
158
|
if (list === void 0) {
|
|
@@ -171,9 +182,7 @@ export function attr(configOrTarget, prop) {
|
|
|
171
182
|
// - @attr({...opts})
|
|
172
183
|
config.property = $prop;
|
|
173
184
|
}
|
|
174
|
-
|
|
175
|
-
($target.constructor.attributes = []);
|
|
176
|
-
attributes.push(config);
|
|
185
|
+
AttributeConfiguration.locate($target.constructor).push(config);
|
|
177
186
|
}
|
|
178
187
|
if (arguments.length > 1) {
|
|
179
188
|
// Non invocation:
|