@microsoft/fast-element 1.10.0 → 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.
- package/.eslintrc.json +1 -12
- package/CHANGELOG.json +396 -1
- package/CHANGELOG.md +68 -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 +8 -2
- package/dist/dts/components/fast-element.d.ts +5 -4
- 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 +144 -0
- package/dist/dts/observation/arrays.d.ts +207 -0
- package/dist/dts/observation/behavior.d.ts +5 -5
- package/dist/dts/observation/notifier.d.ts +18 -18
- package/dist/dts/observation/observable.d.ts +86 -29
- 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.d.ts +320 -64
- package/dist/dts/templating/children.d.ts +18 -15
- package/dist/dts/templating/compiler.d.ts +47 -28
- package/dist/dts/templating/dom.d.ts +41 -0
- package/dist/dts/templating/html-directive.d.ts +179 -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 +72 -14
- package/dist/dts/templating/slotted.d.ts +13 -14
- package/dist/dts/templating/template.d.ts +78 -23
- package/dist/dts/templating/view.d.ts +16 -23
- 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 +14 -22
- package/dist/esm/debug.js +29 -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/observation/arrays.js +269 -0
- package/dist/esm/observation/notifier.js +75 -83
- package/dist/esm/observation/observable.js +80 -107
- 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.js +465 -155
- package/dist/esm/templating/children.js +33 -23
- package/dist/esm/templating/compiler.js +235 -152
- package/dist/esm/templating/dom.js +49 -0
- package/dist/esm/templating/html-directive.js +125 -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 +38 -43
- package/dist/esm/templating/slotted.js +23 -20
- package/dist/esm/templating/template.js +71 -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 +14062 -5235
- package/dist/fast-element.d.ts +1434 -579
- package/dist/fast-element.debug.js +3824 -0
- package/dist/fast-element.debug.min.js +1 -0
- package/dist/fast-element.js +3565 -4014
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +2908 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/docs/api-report.md +590 -231
- package/docs/fast-element-2-changes.md +15 -0
- package/docs/guide/declaring-templates.md +5 -4
- package/docs/guide/defining-elements.md +3 -2
- package/docs/guide/leveraging-css.md +1 -0
- package/docs/guide/next-steps.md +3 -2
- package/docs/guide/observables-and-state.md +2 -1
- package/docs/guide/using-directives.md +2 -1
- package/docs/guide/working-with-shadow-dom.md +1 -0
- package/karma.conf.cjs +6 -17
- package/package.json +48 -14
- 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 -173
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Binding } from "../observation/observable.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Binding, ChildContext, ExecutionContext, ItemContext } 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
|
+
type: "element";
|
|
9
10
|
/**
|
|
10
11
|
* Creates an ElementView instance based on this template definition.
|
|
11
12
|
* @param hostBindingTarget - The element that host behaviors will be bound to.
|
|
12
13
|
*/
|
|
13
|
-
create(hostBindingTarget: Element): ElementView
|
|
14
|
+
create(hostBindingTarget: Element): ElementView<TSource, TParent>;
|
|
14
15
|
/**
|
|
15
16
|
* Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
|
|
16
17
|
* @param source - The data source to bind the template to.
|
|
@@ -18,29 +19,63 @@ export interface ElementViewTemplate {
|
|
|
18
19
|
* @param hostBindingTarget - An HTML element to target the host bindings at if different from the
|
|
19
20
|
* host that the template is being attached to.
|
|
20
21
|
*/
|
|
21
|
-
render(source:
|
|
22
|
+
render(source: TSource, host: Node, hostBindingTarget?: Element): ElementView<TSource, TParent>;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* A template capable of rendering views not specifically connected to custom elements.
|
|
25
26
|
* @public
|
|
26
27
|
*/
|
|
27
|
-
export interface SyntheticViewTemplate<TSource = any, TParent = any> {
|
|
28
|
+
export interface SyntheticViewTemplate<TSource = any, TParent = any, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>> {
|
|
29
|
+
type: "synthetic";
|
|
28
30
|
/**
|
|
29
31
|
* Creates a SyntheticView instance based on this template definition.
|
|
30
32
|
*/
|
|
31
|
-
create(): SyntheticView
|
|
33
|
+
create(): SyntheticView<TSource, TParent, TContext>;
|
|
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>>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The result of a template compilation operation.
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export interface HTMLTemplateCompilationResult<TSource = any, TParent = any, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>> {
|
|
62
|
+
/**
|
|
63
|
+
* Creates a view instance.
|
|
64
|
+
* @param hostBindingTarget - The host binding target for the view.
|
|
65
|
+
*/
|
|
66
|
+
createView(hostBindingTarget?: Element): HTMLView<TSource, TParent, TContext>;
|
|
32
67
|
}
|
|
33
68
|
/**
|
|
34
69
|
* A template capable of creating HTMLView instances or rendering directly to DOM.
|
|
35
70
|
* @public
|
|
36
71
|
*/
|
|
37
|
-
export declare class ViewTemplate<TSource = any, TParent = any> implements ElementViewTemplate, SyntheticViewTemplate {
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
72
|
+
export declare class ViewTemplate<TSource = any, TParent = any, TContext extends ExecutionContext<TParent> = ExecutionContext> implements ElementViewTemplate<TSource, TParent>, SyntheticViewTemplate<TSource, TParent, TContext> {
|
|
73
|
+
private result;
|
|
74
|
+
/**
|
|
75
|
+
* Used for TypeScript purposes only.
|
|
76
|
+
* Do not use.
|
|
77
|
+
*/
|
|
78
|
+
type: any;
|
|
44
79
|
/**
|
|
45
80
|
* The html representing what this template will
|
|
46
81
|
* instantiate, including placeholders for directives.
|
|
@@ -49,18 +84,18 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
|
|
|
49
84
|
/**
|
|
50
85
|
* The directives that will be connected to placeholders in the html.
|
|
51
86
|
*/
|
|
52
|
-
readonly
|
|
87
|
+
readonly factories: Record<string, ViewBehaviorFactory>;
|
|
53
88
|
/**
|
|
54
89
|
* Creates an instance of ViewTemplate.
|
|
55
90
|
* @param html - The html representing what this template will instantiate, including placeholders for directives.
|
|
56
|
-
* @param
|
|
91
|
+
* @param factories - The directives that will be connected to placeholders in the html.
|
|
57
92
|
*/
|
|
58
|
-
constructor(html: string | HTMLTemplateElement,
|
|
93
|
+
constructor(html: string | HTMLTemplateElement, factories: Record<string, ViewBehaviorFactory>);
|
|
59
94
|
/**
|
|
60
95
|
* Creates an HTMLView instance based on this template definition.
|
|
61
96
|
* @param hostBindingTarget - The element that host behaviors will be bound to.
|
|
62
97
|
*/
|
|
63
|
-
create(hostBindingTarget?: Element): HTMLView
|
|
98
|
+
create(hostBindingTarget?: Element): HTMLView<TSource, TParent, TContext>;
|
|
64
99
|
/**
|
|
65
100
|
* Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
|
|
66
101
|
* @param source - The data source to bind the template to.
|
|
@@ -68,7 +103,7 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
|
|
|
68
103
|
* @param hostBindingTarget - An HTML element to target the host bindings at if different from the
|
|
69
104
|
* host that the template is being attached to.
|
|
70
105
|
*/
|
|
71
|
-
render(source: TSource, host: Node
|
|
106
|
+
render(source: TSource, host: Node, hostBindingTarget?: Element, context?: TContext): HTMLView<TSource, TParent, TContext>;
|
|
72
107
|
}
|
|
73
108
|
/**
|
|
74
109
|
* A marker interface used to capture types when interpolating Directive helpers
|
|
@@ -81,9 +116,29 @@ export interface CaptureType<TSource> {
|
|
|
81
116
|
* Represents the types of values that can be interpolated into a template.
|
|
82
117
|
* @public
|
|
83
118
|
*/
|
|
84
|
-
export declare type TemplateValue<
|
|
119
|
+
export declare type TemplateValue<TSource, TParent = any, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>> = Binding<TSource, any, TContext> | HTMLDirective | CaptureType<TSource>;
|
|
120
|
+
/**
|
|
121
|
+
* Transforms a template literal string into a ViewTemplate.
|
|
122
|
+
* @param strings - The string fragments that are interpolated with the values.
|
|
123
|
+
* @param values - The values that are interpolated with the string fragments.
|
|
124
|
+
* @remarks
|
|
125
|
+
* The html helper supports interpolation of strings, numbers, binding expressions,
|
|
126
|
+
* other template instances, and Directive instances.
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
export declare function html<TSource = any, TParent = any, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>>(strings: TemplateStringsArray, ...values: TemplateValue<TSource, TParent, TContext>[]): ViewTemplate<TSource, TParent>;
|
|
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>;
|
|
85
140
|
/**
|
|
86
|
-
* Transforms a template literal string into
|
|
141
|
+
* Transforms a template literal string into an ItemViewTemplate.
|
|
87
142
|
* @param strings - The string fragments that are interpolated with the values.
|
|
88
143
|
* @param values - The values that are interpolated with the string fragments.
|
|
89
144
|
* @remarks
|
|
@@ -91,4 +146,4 @@ export declare type TemplateValue<TScope, TParent = any> = Binding<TScope, any,
|
|
|
91
146
|
* other template instances, and Directive instances.
|
|
92
147
|
* @public
|
|
93
148
|
*/
|
|
94
|
-
export declare
|
|
149
|
+
export declare const item: <TItem = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TItem, TParent, ItemContext<TParent>>[]) => ItemViewTemplate<TItem, TParent>;
|
|
@@ -1,39 +1,35 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ExecutionContext } from "../observation/observable.js";
|
|
1
|
+
import type { Disposable } from "../interfaces.js";
|
|
2
|
+
import type { ExecutionContext, RootContext } 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, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>> extends Disposable {
|
|
8
9
|
/**
|
|
9
10
|
* The execution context the view is running within.
|
|
10
11
|
*/
|
|
11
|
-
readonly context:
|
|
12
|
+
readonly context: TContext | 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: TContext): 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, RootContext> {
|
|
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, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>> extends View<TSource, TParent, TContext> {
|
|
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, TContext extends ExecutionContext<TParent> = ExecutionContext<TParent>> implements ElementView<TSource, TParent>, SyntheticView<TSource, TParent, TContext> {
|
|
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:
|
|
79
|
+
context: TContext | 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: TContext): 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 {
|