@microsoft/fast-element 1.10.2 → 2.0.0-beta.3
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/.eslintrc.json +1 -12
- package/CHANGELOG.json +387 -1
- package/CHANGELOG.md +74 -2
- package/README.md +2 -2
- package/dist/dts/components/attributes.d.ts +4 -1
- package/dist/dts/components/controller.d.ts +12 -11
- package/dist/dts/components/fast-definitions.d.ts +10 -2
- package/dist/dts/components/fast-element.d.ts +12 -5
- package/dist/dts/context.d.ts +157 -0
- package/dist/dts/debug.d.ts +1 -0
- package/dist/dts/hooks.d.ts +20 -0
- package/dist/dts/index.d.ts +16 -15
- package/dist/dts/index.debug.d.ts +2 -0
- package/dist/dts/index.rollup.d.ts +2 -0
- package/dist/dts/index.rollup.debug.d.ts +3 -0
- package/dist/dts/interfaces.d.ts +145 -0
- package/dist/dts/metadata.d.ts +25 -0
- package/dist/dts/observation/arrays.d.ts +207 -0
- package/dist/dts/observation/behavior.d.ts +4 -4
- package/dist/dts/observation/notifier.d.ts +18 -18
- package/dist/dts/observation/observable.d.ts +56 -18
- package/dist/dts/observation/splice-strategies.d.ts +13 -0
- package/dist/dts/observation/update-queue.d.ts +40 -0
- package/dist/dts/platform.d.ts +18 -67
- package/dist/dts/polyfills.d.ts +8 -0
- package/dist/dts/styles/css-directive.d.ts +43 -5
- package/dist/dts/styles/css.d.ts +19 -3
- package/dist/dts/styles/element-styles.d.ts +42 -62
- package/dist/dts/templating/binding-signal.d.ts +38 -0
- package/dist/dts/templating/binding-two-way.d.ts +56 -0
- package/dist/dts/templating/binding.d.ts +233 -65
- package/dist/dts/templating/children.d.ts +18 -15
- package/dist/dts/templating/compiler.d.ts +46 -28
- package/dist/dts/templating/dom.d.ts +41 -0
- package/dist/dts/templating/html-directive.d.ts +181 -43
- package/dist/dts/templating/markup.d.ts +48 -0
- package/dist/dts/templating/node-observation.d.ts +45 -29
- package/dist/dts/templating/ref.d.ts +6 -12
- package/dist/dts/templating/repeat.d.ts +26 -14
- package/dist/dts/templating/slotted.d.ts +13 -14
- package/dist/dts/templating/template.d.ts +27 -21
- package/dist/dts/templating/view.d.ts +15 -22
- package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
- package/dist/dts/utilities.d.ts +40 -0
- package/dist/esm/components/attributes.js +25 -24
- package/dist/esm/components/controller.js +77 -57
- package/dist/esm/components/fast-definitions.js +16 -22
- package/dist/esm/components/fast-element.js +10 -2
- package/dist/esm/context.js +159 -0
- package/dist/esm/debug.js +30 -0
- package/dist/esm/hooks.js +32 -0
- package/dist/esm/index.debug.js +2 -0
- package/dist/esm/index.js +19 -14
- package/dist/esm/index.rollup.debug.js +3 -0
- package/dist/esm/index.rollup.js +2 -0
- package/dist/esm/interfaces.js +8 -1
- package/dist/esm/metadata.js +60 -0
- package/dist/esm/observation/arrays.js +269 -0
- package/dist/esm/observation/notifier.js +27 -35
- package/dist/esm/observation/observable.js +93 -68
- package/dist/esm/observation/{array-change-records.js → splice-strategies.js} +136 -62
- package/dist/esm/observation/update-queue.js +67 -0
- package/dist/esm/platform.js +36 -42
- package/dist/esm/polyfills.js +85 -0
- package/dist/esm/styles/css-directive.js +29 -13
- package/dist/esm/styles/css.js +27 -40
- package/dist/esm/styles/element-styles.js +65 -104
- package/dist/esm/templating/binding-signal.js +84 -0
- package/dist/esm/templating/binding-two-way.js +82 -0
- package/dist/esm/templating/binding.js +306 -153
- package/dist/esm/templating/children.js +33 -23
- package/dist/esm/templating/compiler.js +236 -152
- package/dist/esm/templating/dom.js +49 -0
- package/dist/esm/templating/html-directive.js +128 -40
- package/dist/esm/templating/markup.js +75 -0
- package/dist/esm/templating/node-observation.js +50 -45
- package/dist/esm/templating/ref.js +7 -16
- package/dist/esm/templating/repeat.js +39 -36
- package/dist/esm/templating/slotted.js +23 -20
- package/dist/esm/templating/template.js +51 -95
- package/dist/esm/templating/view.js +44 -43
- package/dist/esm/templating/when.js +2 -1
- package/dist/esm/utilities.js +139 -0
- package/dist/fast-element.api.json +11789 -5377
- package/dist/fast-element.d.ts +1178 -530
- package/dist/fast-element.debug.js +3722 -0
- package/dist/fast-element.debug.min.js +1 -0
- package/dist/fast-element.js +3484 -4033
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +2699 -0
- package/docs/api-report.md +472 -219
- package/docs/fast-element-2-changes.md +15 -0
- package/docs/guide/declaring-templates.md +4 -4
- package/docs/guide/defining-elements.md +2 -2
- package/docs/guide/next-steps.md +2 -2
- package/docs/guide/observables-and-state.md +1 -1
- package/docs/guide/using-directives.md +1 -1
- package/karma.conf.cjs +6 -17
- package/package.json +63 -15
- package/dist/dts/dom.d.ts +0 -112
- package/dist/dts/observation/array-change-records.d.ts +0 -48
- package/dist/dts/observation/array-observer.d.ts +0 -9
- package/dist/esm/dom.js +0 -207
- package/dist/esm/observation/array-observer.js +0 -177
|
@@ -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 {
|
|
6
|
-
import
|
|
2
|
+
import type { Subscriber } from "../observation/notifier.js";
|
|
3
|
+
import { Binding, ExecutionContext } 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, 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
|
|
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
|
-
/**
|
|
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>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
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(
|
|
106
|
+
createBehavior(targets: ViewBehaviorTargets): RepeatBehavior<TSource>;
|
|
95
107
|
}
|
|
96
108
|
/**
|
|
97
109
|
* A directive that enables list rendering.
|
|
@@ -101,4 +113,4 @@ 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,
|
|
116
|
+
export declare function repeat<TSource = any, TArray extends ReadonlyArray<any> = ReadonlyArray<any>>(itemsBinding: Binding<TSource, TArray, ExecutionContext<TSource>>, templateOrTemplateBinding: ViewTemplate | Binding<TSource, ViewTemplate>, options?: RepeatOptions): CaptureType<TSource>;
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { NodeBehaviorOptions,
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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) |
|
|
38
|
+
export declare function slotted<T = any>(propertyOrOptions: (keyof T & string) | SlottedDirectiveOptions<keyof T & string>): CaptureType<T>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Binding } from "../observation/observable.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Binding, ExecutionContext } from "../observation/observable.js";
|
|
2
|
+
import { HTMLDirective, ViewBehaviorFactory } from "./html-directive.js";
|
|
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
|
-
export interface ElementViewTemplate {
|
|
8
|
+
export interface ElementViewTemplate<TSource = any, TParent = any> {
|
|
9
9
|
/**
|
|
10
10
|
* Creates an ElementView instance based on this template definition.
|
|
11
11
|
* @param hostBindingTarget - The element that host behaviors will be bound to.
|
|
12
12
|
*/
|
|
13
|
-
create(hostBindingTarget: Element): ElementView
|
|
13
|
+
create(hostBindingTarget: Element): ElementView<TSource, TParent>;
|
|
14
14
|
/**
|
|
15
15
|
* Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
|
|
16
16
|
* @param source - The data source to bind the template to.
|
|
@@ -18,7 +18,7 @@ export interface ElementViewTemplate {
|
|
|
18
18
|
* @param hostBindingTarget - An HTML element to target the host bindings at if different from the
|
|
19
19
|
* host that the template is being attached to.
|
|
20
20
|
*/
|
|
21
|
-
render(source:
|
|
21
|
+
render(source: TSource, host: Node, hostBindingTarget?: Element): ElementView<TSource, TParent>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* A template capable of rendering views not specifically connected to custom elements.
|
|
@@ -28,19 +28,25 @@ export interface SyntheticViewTemplate<TSource = any, TParent = any> {
|
|
|
28
28
|
/**
|
|
29
29
|
* Creates a SyntheticView instance based on this template definition.
|
|
30
30
|
*/
|
|
31
|
-
create(): SyntheticView
|
|
31
|
+
create(): SyntheticView<TSource, TParent>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The result of a template compilation operation.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface HTMLTemplateCompilationResult<TSource = any, TParent = any> {
|
|
38
|
+
/**
|
|
39
|
+
* Creates a view instance.
|
|
40
|
+
* @param hostBindingTarget - The host binding target for the view.
|
|
41
|
+
*/
|
|
42
|
+
createView(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
|
|
32
43
|
}
|
|
33
44
|
/**
|
|
34
45
|
* A template capable of creating HTMLView instances or rendering directly to DOM.
|
|
35
46
|
* @public
|
|
36
47
|
*/
|
|
37
|
-
export declare class ViewTemplate<TSource = any, TParent = any> implements ElementViewTemplate, SyntheticViewTemplate {
|
|
38
|
-
private
|
|
39
|
-
private hasHostBehaviors;
|
|
40
|
-
private fragment;
|
|
41
|
-
private targetOffset;
|
|
42
|
-
private viewBehaviorFactories;
|
|
43
|
-
private hostBehaviorFactories;
|
|
48
|
+
export declare class ViewTemplate<TSource = any, TParent = any> implements ElementViewTemplate<TSource, TParent>, SyntheticViewTemplate<TSource, TParent> {
|
|
49
|
+
private result;
|
|
44
50
|
/**
|
|
45
51
|
* The html representing what this template will
|
|
46
52
|
* instantiate, including placeholders for directives.
|
|
@@ -49,18 +55,18 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
|
|
|
49
55
|
/**
|
|
50
56
|
* The directives that will be connected to placeholders in the html.
|
|
51
57
|
*/
|
|
52
|
-
readonly
|
|
58
|
+
readonly factories: Record<string, ViewBehaviorFactory>;
|
|
53
59
|
/**
|
|
54
60
|
* Creates an instance of ViewTemplate.
|
|
55
61
|
* @param html - The html representing what this template will instantiate, including placeholders for directives.
|
|
56
|
-
* @param
|
|
62
|
+
* @param factories - The directives that will be connected to placeholders in the html.
|
|
57
63
|
*/
|
|
58
|
-
constructor(html: string | HTMLTemplateElement,
|
|
64
|
+
constructor(html: string | HTMLTemplateElement, factories: Record<string, ViewBehaviorFactory>);
|
|
59
65
|
/**
|
|
60
66
|
* Creates an HTMLView instance based on this template definition.
|
|
61
67
|
* @param hostBindingTarget - The element that host behaviors will be bound to.
|
|
62
68
|
*/
|
|
63
|
-
create(hostBindingTarget?: Element): HTMLView
|
|
69
|
+
create(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
|
|
64
70
|
/**
|
|
65
71
|
* Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
|
|
66
72
|
* @param source - The data source to bind the template to.
|
|
@@ -68,7 +74,7 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
|
|
|
68
74
|
* @param hostBindingTarget - An HTML element to target the host bindings at if different from the
|
|
69
75
|
* host that the template is being attached to.
|
|
70
76
|
*/
|
|
71
|
-
render(source: TSource, host: Node
|
|
77
|
+
render(source: TSource, host: Node, hostBindingTarget?: Element, context?: ExecutionContext): HTMLView<TSource, TParent>;
|
|
72
78
|
}
|
|
73
79
|
/**
|
|
74
80
|
* A marker interface used to capture types when interpolating Directive helpers
|
|
@@ -81,9 +87,9 @@ export interface CaptureType<TSource> {
|
|
|
81
87
|
* Represents the types of values that can be interpolated into a template.
|
|
82
88
|
* @public
|
|
83
89
|
*/
|
|
84
|
-
export declare type TemplateValue<
|
|
90
|
+
export declare type TemplateValue<TSource, TParent = any> = Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource>;
|
|
85
91
|
/**
|
|
86
|
-
* Transforms a template literal string into a
|
|
92
|
+
* Transforms a template literal string into a ViewTemplate.
|
|
87
93
|
* @param strings - The string fragments that are interpolated with the values.
|
|
88
94
|
* @param values - The values that are interpolated with the string fragments.
|
|
89
95
|
* @remarks
|
|
@@ -1,39 +1,35 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Disposable } from "../interfaces.js";
|
|
2
2
|
import type { ExecutionContext } from "../observation/observable.js";
|
|
3
|
+
import type { ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
|
|
3
4
|
/**
|
|
4
5
|
* Represents a collection of DOM nodes which can be bound to a data source.
|
|
5
6
|
* @public
|
|
6
7
|
*/
|
|
7
|
-
export interface View {
|
|
8
|
+
export interface View<TSource = any, TParent = any> extends Disposable {
|
|
8
9
|
/**
|
|
9
10
|
* The execution context the view is running within.
|
|
10
11
|
*/
|
|
11
|
-
readonly context: ExecutionContext | null;
|
|
12
|
+
readonly context: ExecutionContext<TParent> | null;
|
|
12
13
|
/**
|
|
13
14
|
* The data that the view is bound to.
|
|
14
15
|
*/
|
|
15
|
-
readonly source:
|
|
16
|
+
readonly source: TSource | null;
|
|
16
17
|
/**
|
|
17
18
|
* Binds a view's behaviors to its binding source.
|
|
18
19
|
* @param source - The binding source for the view's binding behaviors.
|
|
19
20
|
* @param context - The execution context to run the view within.
|
|
20
21
|
*/
|
|
21
|
-
bind(source:
|
|
22
|
+
bind(source: TSource, context: ExecutionContext<TParent>): void;
|
|
22
23
|
/**
|
|
23
24
|
* Unbinds a view's behaviors from its binding source and context.
|
|
24
25
|
*/
|
|
25
26
|
unbind(): void;
|
|
26
|
-
/**
|
|
27
|
-
* Removes the view and unbinds its behaviors, disposing of DOM nodes afterward.
|
|
28
|
-
* Once a view has been disposed, it cannot be inserted or bound again.
|
|
29
|
-
*/
|
|
30
|
-
dispose(): void;
|
|
31
27
|
}
|
|
32
28
|
/**
|
|
33
29
|
* A View representing DOM nodes specifically for rendering the view of a custom element.
|
|
34
30
|
* @public
|
|
35
31
|
*/
|
|
36
|
-
export interface ElementView extends View {
|
|
32
|
+
export interface ElementView<TSource = any, TParent = any> extends View<TSource, TParent> {
|
|
37
33
|
/**
|
|
38
34
|
* Appends the view's DOM nodes to the referenced node.
|
|
39
35
|
* @param node - The parent node to append the view's DOM nodes to.
|
|
@@ -44,7 +40,7 @@ export interface ElementView extends View {
|
|
|
44
40
|
* A view representing a range of DOM nodes which can be added/removed ad hoc.
|
|
45
41
|
* @public
|
|
46
42
|
*/
|
|
47
|
-
export interface SyntheticView extends View {
|
|
43
|
+
export interface SyntheticView<TSource = any, TParent = any> extends View<TSource, TParent> {
|
|
48
44
|
/**
|
|
49
45
|
* The first DOM node in the range of nodes that make up the view.
|
|
50
46
|
*/
|
|
@@ -63,27 +59,24 @@ export interface SyntheticView extends View {
|
|
|
63
59
|
* The nodes are not disposed and the view can later be re-inserted.
|
|
64
60
|
*/
|
|
65
61
|
remove(): void;
|
|
66
|
-
/**
|
|
67
|
-
* Removes the view and unbinds its behaviors, disposing of DOM nodes afterward.
|
|
68
|
-
* Once a view has been disposed, it cannot be inserted or bound again.
|
|
69
|
-
*/
|
|
70
|
-
dispose(): void;
|
|
71
62
|
}
|
|
72
63
|
/**
|
|
73
64
|
* The standard View implementation, which also implements ElementView and SyntheticView.
|
|
74
65
|
* @public
|
|
75
66
|
*/
|
|
76
|
-
export declare class HTMLView implements ElementView, SyntheticView {
|
|
67
|
+
export declare class HTMLView<TSource = any, TParent = any> implements ElementView<TSource, TParent>, SyntheticView<TSource, TParent> {
|
|
77
68
|
private fragment;
|
|
69
|
+
private factories;
|
|
70
|
+
private targets;
|
|
78
71
|
private behaviors;
|
|
79
72
|
/**
|
|
80
73
|
* The data that the view is bound to.
|
|
81
74
|
*/
|
|
82
|
-
source:
|
|
75
|
+
source: TSource | null;
|
|
83
76
|
/**
|
|
84
77
|
* The execution context the view is running within.
|
|
85
78
|
*/
|
|
86
|
-
context: ExecutionContext | null;
|
|
79
|
+
context: ExecutionContext<TParent> | null;
|
|
87
80
|
/**
|
|
88
81
|
* The first DOM node in the range of nodes that make up the view.
|
|
89
82
|
*/
|
|
@@ -97,7 +90,7 @@ export declare class HTMLView implements ElementView, SyntheticView {
|
|
|
97
90
|
* @param fragment - The html fragment that contains the nodes for this view.
|
|
98
91
|
* @param behaviors - The behaviors to be applied to this view.
|
|
99
92
|
*/
|
|
100
|
-
constructor(fragment: DocumentFragment,
|
|
93
|
+
constructor(fragment: DocumentFragment, factories: ReadonlyArray<ViewBehaviorFactory>, targets: ViewBehaviorTargets);
|
|
101
94
|
/**
|
|
102
95
|
* Appends the view's DOM nodes to the referenced node.
|
|
103
96
|
* @param node - The parent node to append the view's DOM nodes to.
|
|
@@ -123,7 +116,7 @@ export declare class HTMLView implements ElementView, SyntheticView {
|
|
|
123
116
|
* @param source - The binding source for the view's binding behaviors.
|
|
124
117
|
* @param context - The execution context to run the behaviors within.
|
|
125
118
|
*/
|
|
126
|
-
bind(source:
|
|
119
|
+
bind(source: TSource, context: ExecutionContext<TParent>): void;
|
|
127
120
|
/**
|
|
128
121
|
* Unbinds a view's behaviors from its binding source.
|
|
129
122
|
*/
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* Retrieves the "composed parent" element of a node, ignoring DOM tree boundaries.
|
|
21
|
+
* When the parent of a node is a shadow-root, it will return the host
|
|
22
|
+
* element of the shadow root. Otherwise it will return the parent node or null if
|
|
23
|
+
* no parent node exists.
|
|
24
|
+
* @param element - The element for which to retrieve the composed parent
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function composedParent<T extends HTMLElement>(element: T): HTMLElement | null;
|
|
29
|
+
/**
|
|
30
|
+
* Determines if the reference element contains the test element in a "composed" DOM tree that
|
|
31
|
+
* ignores shadow DOM boundaries.
|
|
32
|
+
*
|
|
33
|
+
* Returns true of the test element is a descendent of the reference, or exist in
|
|
34
|
+
* a shadow DOM that is a logical descendent of the reference. Otherwise returns false.
|
|
35
|
+
* @param reference - The element to test for containment against.
|
|
36
|
+
* @param test - The element being tested for containment.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare function composedContains(reference: HTMLElement, test: HTMLElement): boolean;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Observable } from "../observation/observable.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isString } from "../interfaces.js";
|
|
3
|
+
import { Updates } from "../observation/update-queue.js";
|
|
4
|
+
import { DOM } from "../templating/dom.js";
|
|
5
|
+
const booleanMode = "boolean";
|
|
6
|
+
const reflectMode = "reflect";
|
|
3
7
|
/**
|
|
4
8
|
* A {@link ValueConverter} that converts to and from `boolean` values.
|
|
5
9
|
* @remarks
|
|
@@ -11,16 +15,22 @@ export const booleanConverter = {
|
|
|
11
15
|
return value ? "true" : "false";
|
|
12
16
|
},
|
|
13
17
|
fromView(value) {
|
|
14
|
-
|
|
18
|
+
return value === null ||
|
|
15
19
|
value === void 0 ||
|
|
16
20
|
value === "false" ||
|
|
17
21
|
value === false ||
|
|
18
|
-
value === 0
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return true;
|
|
22
|
+
value === 0
|
|
23
|
+
? false
|
|
24
|
+
: true;
|
|
22
25
|
},
|
|
23
26
|
};
|
|
27
|
+
function toNumber(value) {
|
|
28
|
+
if (value === null || value === undefined) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const number = value * 1;
|
|
32
|
+
return isNaN(number) ? null : number;
|
|
33
|
+
}
|
|
24
34
|
/**
|
|
25
35
|
* A {@link ValueConverter} that converts to and from `number` values.
|
|
26
36
|
* @remarks
|
|
@@ -30,19 +40,10 @@ export const booleanConverter = {
|
|
|
30
40
|
*/
|
|
31
41
|
export const nullableNumberConverter = {
|
|
32
42
|
toView(value) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
const number = value * 1;
|
|
37
|
-
return isNaN(number) ? null : number.toString();
|
|
38
|
-
},
|
|
39
|
-
fromView(value) {
|
|
40
|
-
if (value === null || value === undefined) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const number = value * 1;
|
|
44
|
-
return isNaN(number) ? null : number;
|
|
43
|
+
const output = toNumber(value);
|
|
44
|
+
return output ? output.toString() : output;
|
|
45
45
|
},
|
|
46
|
+
fromView: toNumber,
|
|
46
47
|
};
|
|
47
48
|
/**
|
|
48
49
|
* An implementation of {@link Accessor} that supports reactivity,
|
|
@@ -60,7 +61,7 @@ export class AttributeDefinition {
|
|
|
60
61
|
* @param converter - A {@link ValueConverter} that integrates with the property getter/setter
|
|
61
62
|
* to convert values to and from a DOM string.
|
|
62
63
|
*/
|
|
63
|
-
constructor(Owner, name, attribute = name.toLowerCase(), mode =
|
|
64
|
+
constructor(Owner, name, attribute = name.toLowerCase(), mode = reflectMode, converter) {
|
|
64
65
|
this.guards = new Set();
|
|
65
66
|
this.Owner = Owner;
|
|
66
67
|
this.name = name;
|
|
@@ -70,7 +71,7 @@ export class AttributeDefinition {
|
|
|
70
71
|
this.fieldName = `_${name}`;
|
|
71
72
|
this.callbackName = `${name}Changed`;
|
|
72
73
|
this.hasCallback = this.callbackName in Owner.prototype;
|
|
73
|
-
if (mode ===
|
|
74
|
+
if (mode === booleanMode && converter === void 0) {
|
|
74
75
|
this.converter = booleanConverter;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
@@ -117,15 +118,15 @@ export class AttributeDefinition {
|
|
|
117
118
|
if (guards.has(element) || mode === "fromView") {
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
+
Updates.enqueue(() => {
|
|
121
122
|
guards.add(element);
|
|
122
123
|
const latestValue = element[this.fieldName];
|
|
123
124
|
switch (mode) {
|
|
124
|
-
case
|
|
125
|
+
case reflectMode:
|
|
125
126
|
const converter = this.converter;
|
|
126
127
|
DOM.setAttribute(element, this.attribute, converter !== void 0 ? converter.toView(latestValue) : latestValue);
|
|
127
128
|
break;
|
|
128
|
-
case
|
|
129
|
+
case booleanMode:
|
|
129
130
|
DOM.setBooleanAttribute(element, this.attribute, latestValue);
|
|
130
131
|
break;
|
|
131
132
|
}
|
|
@@ -148,7 +149,7 @@ export class AttributeDefinition {
|
|
|
148
149
|
}
|
|
149
150
|
for (let j = 0, jj = list.length; j < jj; ++j) {
|
|
150
151
|
const config = list[j];
|
|
151
|
-
if (
|
|
152
|
+
if (isString(config)) {
|
|
152
153
|
attributes.push(new AttributeDefinition(Owner, config));
|
|
153
154
|
}
|
|
154
155
|
else {
|