@microsoft/fast-element 1.10.5 → 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.
Files changed (122) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +629 -6
  3. package/CHANGELOG.md +152 -5
  4. package/dist/dts/components/attributes.d.ts +14 -1
  5. package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +32 -32
  6. package/dist/dts/components/fast-definitions.d.ts +51 -11
  7. package/dist/dts/components/fast-element.d.ts +18 -23
  8. package/dist/dts/context.d.ts +157 -0
  9. package/dist/{esm/observation/behavior.js → dts/debug.d.ts} +0 -0
  10. package/dist/dts/di/di.d.ts +899 -0
  11. package/dist/dts/index.d.ts +17 -16
  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 +176 -0
  16. package/dist/dts/metadata.d.ts +25 -0
  17. package/dist/dts/observation/arrays.d.ts +207 -0
  18. package/dist/dts/observation/notifier.d.ts +18 -18
  19. package/dist/dts/observation/observable.d.ts +117 -34
  20. package/dist/dts/observation/update-queue.d.ts +40 -0
  21. package/dist/dts/pending-task.d.ts +20 -0
  22. package/dist/dts/platform.d.ts +23 -66
  23. package/dist/dts/polyfills.d.ts +8 -0
  24. package/dist/dts/state/exports.d.ts +3 -0
  25. package/dist/dts/state/reactive.d.ts +8 -0
  26. package/dist/dts/state/state.d.ts +141 -0
  27. package/dist/dts/state/visitor.d.ts +6 -0
  28. package/dist/dts/state/watch.d.ts +10 -0
  29. package/dist/dts/styles/css-directive.d.ts +44 -6
  30. package/dist/dts/styles/css.d.ts +19 -3
  31. package/dist/dts/styles/element-styles.d.ts +49 -63
  32. package/dist/dts/styles/host.d.ts +68 -0
  33. package/dist/dts/templating/binding-signal.d.ts +21 -0
  34. package/dist/dts/templating/binding-two-way.d.ts +39 -0
  35. package/dist/dts/templating/binding.d.ts +101 -70
  36. package/dist/dts/templating/children.d.ts +18 -15
  37. package/dist/dts/templating/compiler.d.ts +46 -28
  38. package/dist/dts/templating/dom.d.ts +41 -0
  39. package/dist/dts/templating/html-directive.d.ts +239 -45
  40. package/dist/dts/templating/markup.d.ts +48 -0
  41. package/dist/dts/templating/node-observation.d.ts +45 -30
  42. package/dist/dts/templating/ref.d.ts +6 -20
  43. package/dist/dts/templating/render.d.ts +272 -0
  44. package/dist/dts/templating/repeat.d.ts +36 -33
  45. package/dist/dts/templating/slotted.d.ts +13 -14
  46. package/dist/dts/templating/template.d.ts +28 -22
  47. package/dist/dts/templating/view.d.ts +82 -24
  48. package/dist/dts/templating/when.d.ts +3 -3
  49. package/dist/dts/testing/exports.d.ts +3 -0
  50. package/dist/dts/testing/fakes.d.ts +4 -0
  51. package/dist/dts/testing/fixture.d.ts +84 -0
  52. package/dist/dts/testing/timeout.d.ts +7 -0
  53. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  54. package/dist/dts/utilities.d.ts +22 -0
  55. package/dist/esm/components/attributes.js +38 -28
  56. package/dist/esm/components/{controller.js → element-controller.js} +150 -140
  57. package/dist/esm/components/fast-definitions.js +48 -46
  58. package/dist/esm/components/fast-element.js +31 -12
  59. package/dist/esm/context.js +163 -0
  60. package/dist/esm/debug.js +61 -0
  61. package/dist/esm/di/di.js +1435 -0
  62. package/dist/esm/index.debug.js +2 -0
  63. package/dist/esm/index.js +20 -14
  64. package/dist/esm/index.rollup.debug.js +3 -0
  65. package/dist/esm/index.rollup.js +2 -0
  66. package/dist/esm/interfaces.js +12 -1
  67. package/dist/esm/metadata.js +60 -0
  68. package/dist/esm/observation/arrays.js +570 -0
  69. package/dist/esm/observation/notifier.js +27 -35
  70. package/dist/esm/observation/observable.js +116 -149
  71. package/dist/esm/observation/update-queue.js +67 -0
  72. package/dist/esm/pending-task.js +16 -0
  73. package/dist/esm/platform.js +60 -42
  74. package/dist/esm/polyfills.js +85 -0
  75. package/dist/esm/state/exports.js +3 -0
  76. package/dist/esm/state/reactive.js +34 -0
  77. package/dist/esm/state/state.js +148 -0
  78. package/dist/esm/state/visitor.js +28 -0
  79. package/dist/esm/state/watch.js +36 -0
  80. package/dist/esm/styles/css-directive.js +29 -13
  81. package/dist/esm/styles/css.js +29 -42
  82. package/dist/esm/styles/element-styles.js +79 -104
  83. package/dist/esm/styles/host.js +1 -0
  84. package/dist/esm/templating/binding-signal.js +83 -0
  85. package/dist/esm/templating/binding-two-way.js +103 -0
  86. package/dist/esm/templating/binding.js +189 -159
  87. package/dist/esm/templating/children.js +33 -23
  88. package/dist/esm/templating/compiler.js +258 -152
  89. package/dist/esm/templating/dom.js +49 -0
  90. package/dist/esm/templating/html-directive.js +193 -36
  91. package/dist/esm/templating/markup.js +75 -0
  92. package/dist/esm/templating/node-observation.js +51 -45
  93. package/dist/esm/templating/ref.js +8 -25
  94. package/dist/esm/templating/render.js +391 -0
  95. package/dist/esm/templating/repeat.js +83 -79
  96. package/dist/esm/templating/slotted.js +23 -20
  97. package/dist/esm/templating/template.js +51 -93
  98. package/dist/esm/templating/view.js +125 -46
  99. package/dist/esm/templating/when.js +6 -4
  100. package/dist/esm/testing/exports.js +3 -0
  101. package/dist/esm/testing/fakes.js +76 -0
  102. package/dist/esm/testing/fixture.js +86 -0
  103. package/dist/esm/testing/timeout.js +24 -0
  104. package/dist/esm/utilities.js +44 -0
  105. package/dist/fast-element.api.json +12153 -5373
  106. package/dist/fast-element.d.ts +1448 -696
  107. package/dist/fast-element.debug.js +4107 -0
  108. package/dist/fast-element.debug.min.js +1 -0
  109. package/dist/fast-element.js +3817 -4029
  110. package/dist/fast-element.min.js +1 -1
  111. package/dist/fast-element.untrimmed.d.ts +2814 -0
  112. package/docs/api-report.md +567 -254
  113. package/docs/fast-element-2-changes.md +15 -0
  114. package/karma.conf.cjs +6 -17
  115. package/package.json +76 -15
  116. package/dist/dts/dom.d.ts +0 -112
  117. package/dist/dts/observation/array-change-records.d.ts +0 -48
  118. package/dist/dts/observation/array-observer.d.ts +0 -9
  119. package/dist/dts/observation/behavior.d.ts +0 -19
  120. package/dist/esm/dom.js +0 -207
  121. package/dist/esm/observation/array-change-records.js +0 -326
  122. package/dist/esm/observation/array-observer.js +0 -177
@@ -6,13 +6,29 @@ import { ComposableStyles, ElementStyles } from "./element-styles.js";
6
6
  * @param values - The values that are interpolated with the string fragments.
7
7
  * @remarks
8
8
  * The css helper supports interpolation of strings and ElementStyle instances.
9
+ * Use the .partial method to create partial CSS fragments.
9
10
  * @public
10
11
  */
11
- export declare function css(strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]): ElementStyles;
12
+ export declare type CSSTemplateTag = ((strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]) => ElementStyles) & {
13
+ /**
14
+ * Transforms a template literal string into partial CSS.
15
+ * @param strings - The string fragments that are interpolated with the values.
16
+ * @param values - The values that are interpolated with the string fragments.
17
+ * @public
18
+ */
19
+ partial(strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]): CSSDirective;
20
+ };
12
21
  /**
13
- * Transforms a template literal string into partial CSS.
22
+ * Transforms a template literal string into styles.
14
23
  * @param strings - The string fragments that are interpolated with the values.
15
24
  * @param values - The values that are interpolated with the string fragments.
25
+ * @remarks
26
+ * The css helper supports interpolation of strings and ElementStyle instances.
27
+ * @public
28
+ */
29
+ export declare const css: CSSTemplateTag;
30
+ /**
31
+ * @deprecated Use css.partial instead.
16
32
  * @public
17
33
  */
18
- export declare function cssPartial(strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]): CSSDirective;
34
+ export declare const cssPartial: (strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]) => CSSDirective;
@@ -1,55 +1,42 @@
1
- import type { Behavior } from "../observation/behavior.js";
2
- /**
3
- * A node that can be targeted by styles.
4
- * @public
5
- */
6
- export interface StyleTarget {
7
- /**
8
- * Stylesheets to be adopted by the node.
9
- */
10
- adoptedStyleSheets?: CSSStyleSheet[];
11
- /**
12
- * Adds styles to the target by appending the styles.
13
- * @param styles - The styles element to add.
14
- */
15
- append(styles: HTMLStyleElement): void;
16
- /**
17
- * Adds styles to the target by prepending the styles.
18
- * @param styles - The styles element to add.
19
- * @deprecated - use append()
20
- */
21
- prepend(styles: HTMLStyleElement): void;
22
- /**
23
- * Removes styles from the target.
24
- * @param styles - The styles element to remove.
25
- */
26
- removeChild(styles: HTMLStyleElement): void;
27
- /**
28
- * Returns all element descendants of node that match selectors.
29
- * @param selectors - The CSS selector to use for the query.
30
- */
31
- querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
32
- }
1
+ import { StyleStrategy, StyleTarget } from "../interfaces.js";
2
+ import type { HostBehavior } from "./host.js";
33
3
  /**
34
4
  * Represents styles that can be composed into the ShadowDOM of a custom element.
35
5
  * @public
36
6
  */
37
7
  export declare type ComposableStyles = string | ElementStyles | CSSStyleSheet;
38
8
  /**
39
- * Creates an ElementStyles instance for an array of ComposableStyles.
9
+ * A type that instantiates a StyleStrategy.
40
10
  * @public
41
11
  */
42
- export declare type ElementStyleFactory = (styles: ReadonlyArray<ComposableStyles>) => ElementStyles;
12
+ export declare type ConstructibleStyleStrategy = {
13
+ /**
14
+ * Creates an instance of the strategy.
15
+ * @param styles - The styles to initialize the strategy with.
16
+ */
17
+ new (styles: (string | CSSStyleSheet)[]): StyleStrategy;
18
+ };
43
19
  /**
44
20
  * Represents styles that can be applied to a custom element.
45
21
  * @public
46
22
  */
47
- export declare abstract class ElementStyles {
23
+ export declare class ElementStyles {
24
+ readonly styles: ReadonlyArray<ComposableStyles>;
48
25
  private targets;
49
- /** @internal */
50
- abstract readonly styles: ReadonlyArray<ComposableStyles>;
51
- /** @internal */
52
- abstract readonly behaviors: ReadonlyArray<Behavior> | null;
26
+ private _strategy;
27
+ /**
28
+ * The behaviors associated with this set of styles.
29
+ */
30
+ readonly behaviors: ReadonlyArray<HostBehavior<HTMLElement>> | null;
31
+ /**
32
+ * Gets the StyleStrategy associated with these element styles.
33
+ */
34
+ get strategy(): StyleStrategy;
35
+ /**
36
+ * Creates an instance of ElementStyles.
37
+ * @param styles - The styles that will be associated with elements.
38
+ */
39
+ constructor(styles: ReadonlyArray<ComposableStyles>);
53
40
  /** @internal */
54
41
  addStylesTo(target: StyleTarget): void;
55
42
  /** @internal */
@@ -60,11 +47,27 @@ export declare abstract class ElementStyles {
60
47
  * Associates behaviors with this set of styles.
61
48
  * @param behaviors - The behaviors to associate.
62
49
  */
63
- withBehaviors(...behaviors: Behavior[]): this;
50
+ withBehaviors(...behaviors: HostBehavior<HTMLElement>[]): this;
64
51
  /**
65
- * Create ElementStyles from ComposableStyles.
52
+ * Sets the strategy that handles adding/removing these styles for an element.
53
+ * @param strategy - The strategy to use.
66
54
  */
67
- static readonly create: ElementStyleFactory;
55
+ withStrategy(Strategy: ConstructibleStyleStrategy): this;
56
+ /**
57
+ * Sets the default strategy type to use when creating style strategies.
58
+ * @param Strategy - The strategy type to construct.
59
+ */
60
+ static setDefaultStrategy(Strategy: ConstructibleStyleStrategy): void;
61
+ /**
62
+ * Normalizes a set of composable style options.
63
+ * @param styles - The style options to normalize.
64
+ * @returns A singular ElementStyles instance or undefined.
65
+ */
66
+ static normalize(styles: ComposableStyles | ComposableStyles[] | undefined): ElementStyles | undefined;
67
+ /**
68
+ * Indicates whether the DOM supports the adoptedStyleSheets feature.
69
+ */
70
+ static readonly supportsAdoptedStyleSheets: boolean;
68
71
  }
69
72
  /**
70
73
  * https://wicg.github.io/construct-stylesheets/
@@ -72,27 +75,10 @@ export declare abstract class ElementStyles {
72
75
  *
73
76
  * @internal
74
77
  */
75
- export declare class AdoptedStyleSheetsStyles extends ElementStyles {
76
- styles: ComposableStyles[];
77
- private styleSheetCache;
78
- private _styleSheets;
79
- private get styleSheets();
80
- readonly behaviors: ReadonlyArray<Behavior> | null;
81
- constructor(styles: ComposableStyles[], styleSheetCache: Map<string, CSSStyleSheet>);
82
- addStylesTo(target: StyleTarget): void;
83
- removeStylesFrom(target: StyleTarget): void;
84
- }
85
- /**
86
- * @internal
87
- */
88
- export declare class StyleElementStyles extends ElementStyles {
89
- styles: ComposableStyles[];
90
- private readonly styleSheets;
91
- private readonly styleClass;
92
- readonly behaviors: ReadonlyArray<Behavior> | null;
93
- constructor(styles: ComposableStyles[]);
78
+ export declare class AdoptedStyleSheetsStrategy implements StyleStrategy {
79
+ /** @internal */
80
+ readonly sheets: CSSStyleSheet[];
81
+ constructor(styles: (string | CSSStyleSheet)[]);
94
82
  addStylesTo(target: StyleTarget): void;
95
83
  removeStylesFrom(target: StyleTarget): void;
96
- isAttachedTo(target: StyleTarget): boolean;
97
- private normalizeTarget;
98
84
  }
@@ -0,0 +1,68 @@
1
+ import type { ElementStyles } from "./element-styles.js";
2
+ /**
3
+ * Controls the lifecycle and context of behaviors and styles
4
+ * associated with a component host.
5
+ * @public
6
+ */
7
+ export interface HostController<TSource = any> {
8
+ /**
9
+ * The component source.
10
+ */
11
+ readonly source: TSource;
12
+ /**
13
+ * Indicates whether the host is connected or not.
14
+ */
15
+ readonly isConnected: boolean;
16
+ /**
17
+ * The main set of styles used for the component, independent
18
+ * of any behavior-specific styles.
19
+ */
20
+ mainStyles: ElementStyles | null;
21
+ /**
22
+ * Adds the behavior to the component.
23
+ * @param behavior - The behavior to add.
24
+ */
25
+ addBehavior(behavior: HostBehavior<TSource>): void;
26
+ /**
27
+ * Removes the behavior from the component.
28
+ * @param behavior - The behavior to remove.
29
+ * @param force - Forces removal even if this behavior was added more than once.
30
+ */
31
+ removeBehavior(behavior: HostBehavior<TSource>, force?: boolean): void;
32
+ /**
33
+ * Adds styles to this element. Providing an HTMLStyleElement will attach the element instance to the shadowRoot.
34
+ * @param styles - The styles to add.
35
+ */
36
+ addStyles(styles: ElementStyles | HTMLStyleElement | null | undefined): void;
37
+ /**
38
+ * Removes styles from this element. Providing an HTMLStyleElement will detach the element instance from the shadowRoot.
39
+ * @param styles - the styles to remove.
40
+ */
41
+ removeStyles(styles: ElementStyles | HTMLStyleElement | null | undefined): void;
42
+ }
43
+ /**
44
+ * Represents an object that can contribute behavior to a host.
45
+ * @public
46
+ */
47
+ export interface HostBehavior<TSource = any> {
48
+ /**
49
+ * Executed when this behavior is attached to a controller.
50
+ * @param controller - Controls the behavior lifecycle.
51
+ */
52
+ addedCallback?(controller: HostController<TSource>): void;
53
+ /**
54
+ * Executed when this behavior is detached from a controller.
55
+ * @param controller - Controls the behavior lifecycle.
56
+ */
57
+ removedCallback?(controller: HostController<TSource>): void;
58
+ /**
59
+ * Executed when this behavior's host is connected.
60
+ * @param controller - Controls the behavior lifecycle.
61
+ */
62
+ connectedCallback?(controller: HostController<TSource>): void;
63
+ /**
64
+ * Executed when this behavior's host is disconnected.
65
+ * @param controller - Controls the behavior lifecycle.
66
+ */
67
+ disconnectedCallback?(controller: HostController<TSource>): void;
68
+ }
@@ -0,0 +1,21 @@
1
+ import type { Expression } from "../observation/observable.js";
2
+ import type { Subscriber } from "../observation/notifier.js";
3
+ import { Binding } from "./html-directive.js";
4
+ export declare const Signal: Readonly<{
5
+ subscribe(signal: string, subscriber: Subscriber): void;
6
+ unsubscribe(signal: string, subscriber: Subscriber): void;
7
+ /**
8
+ * Sends the specified signal to signaled bindings.
9
+ * @param signal - The signal to send.
10
+ * @public
11
+ */
12
+ send(signal: string): void;
13
+ }>;
14
+ /**
15
+ * Creates a signal binding configuration with the supplied options.
16
+ * @param expression - The binding to refresh when signaled.
17
+ * @param options - The signal name or a binding to use to retrieve the signal name.
18
+ * @returns A binding configuration.
19
+ * @public
20
+ */
21
+ export declare function signal<T = any>(expression: Expression<T>, options: string | Expression<T>): Binding<T>;
@@ -0,0 +1,39 @@
1
+ import { Expression } from "../observation/observable.js";
2
+ import type { HTMLBindingDirective } from "./binding.js";
3
+ import { Binding } from "./html-directive.js";
4
+ /**
5
+ * The twoWay binding options.
6
+ * @public
7
+ */
8
+ export declare type TwoWayBindingOptions = {
9
+ changeEvent?: string;
10
+ fromView?: (value: any) => any;
11
+ };
12
+ /**
13
+ * The settings required to enable two-way binding.
14
+ * @public
15
+ */
16
+ export interface TwoWaySettings {
17
+ /**
18
+ * Determines which event to listen to, to detect changes in the view.
19
+ * @param directive - The directive to determine the change event for.
20
+ * @param target - The target element to determine the change event for.
21
+ */
22
+ determineChangeEvent(directive: HTMLBindingDirective, target: HTMLElement): string;
23
+ }
24
+ export declare const TwoWaySettings: Readonly<{
25
+ /**
26
+ * Configures two-way binding.
27
+ * @param settings - The settings to use for the two-way binding system.
28
+ */
29
+ configure(settings: TwoWaySettings): void;
30
+ }>;
31
+ /**
32
+ * Creates a default binding.
33
+ * @param expression - The binding to refresh when changed.
34
+ * @param optionsOrChangeEvent - The binding options or the name of the change event to use.
35
+ * @param isBindingVolatile - Indicates whether the binding is volatile or not.
36
+ * @returns A binding.
37
+ * @public
38
+ */
39
+ export declare function twoWay<T = any>(expression: Expression<T>, optionsOrChangeEvent?: TwoWayBindingOptions | string, isBindingVolatile?: boolean): Binding<T>;
@@ -1,95 +1,126 @@
1
- import type { Behavior } from "../observation/behavior.js";
2
- import { Binding, BindingObserver, ExecutionContext } from "../observation/observable.js";
3
- import { TargetedHTMLDirective } from "./html-directive.js";
4
- declare function normalBind(this: BindingBehavior, source: unknown, context: ExecutionContext): void;
5
- declare function normalUnbind(this: BindingBehavior): void;
6
- declare function updatePropertyTarget(this: BindingBehavior, value: unknown): void;
1
+ import { ExecutionContext, Expression, ExpressionObserver } from "../observation/observable.js";
2
+ import { AddViewBehaviorFactory, Aspect, Aspected, Binding, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewController } from "./html-directive.js";
7
3
  /**
8
- * A directive that configures data binding to element content and attributes.
4
+ * A simple View that can be interpolated into HTML content.
9
5
  * @public
10
6
  */
11
- export declare class HTMLBindingDirective extends TargetedHTMLDirective {
12
- binding: Binding;
13
- private cleanedTargetName?;
14
- private originalTargetName?;
15
- private bind;
16
- private unbind;
17
- private updateTarget;
18
- private isBindingVolatile;
7
+ export interface ContentView {
8
+ readonly context: ExecutionContext;
19
9
  /**
20
- * Creates an instance of BindingDirective.
21
- * @param binding - A binding that returns the data used to update the DOM.
10
+ * Binds a view's behaviors to its binding source.
11
+ * @param source - The binding source for the view's binding behaviors.
12
+ * @param context - The execution context to run the view within.
22
13
  */
23
- constructor(binding: Binding);
14
+ bind(source: any, context?: ExecutionContext): void;
24
15
  /**
25
- * Gets/sets the name of the attribute or property that this
26
- * binding is targeting.
16
+ * Unbinds a view's behaviors from its binding source and context.
27
17
  */
28
- get targetName(): string | undefined;
29
- set targetName(value: string | undefined);
18
+ unbind(): void;
30
19
  /**
31
- * Makes this binding target the content of an element rather than
32
- * a particular attribute or property.
20
+ * Inserts the view's DOM nodes before the referenced node.
21
+ * @param node - The node to insert the view's DOM before.
33
22
  */
34
- targetAtContent(): void;
23
+ insertBefore(node: Node): void;
35
24
  /**
36
- * Creates the runtime BindingBehavior instance based on the configuration
37
- * information stored in the BindingDirective.
38
- * @param target - The target node that the binding behavior should attach to.
25
+ * Removes the view's DOM nodes.
26
+ * The nodes are not disposed and the view can later be re-inserted.
39
27
  */
40
- createBehavior(target: Node): BindingBehavior;
28
+ remove(): void;
41
29
  }
42
30
  /**
43
- * A behavior that updates content and attributes based on a configured
44
- * BindingDirective.
31
+ * A simple template that can create ContentView instances.
45
32
  * @public
46
33
  */
47
- export declare class BindingBehavior implements Behavior {
48
- /** @internal */
49
- source: unknown;
50
- /** @internal */
51
- context: ExecutionContext | null;
52
- /** @internal */
53
- bindingObserver: BindingObserver | null;
54
- /** @internal */
55
- classVersions: Record<string, number>;
56
- /** @internal */
57
- version: number;
58
- /** @internal */
59
- target: any;
60
- /** @internal */
61
- binding: Binding;
62
- /** @internal */
63
- isBindingVolatile: boolean;
64
- /** @internal */
65
- updateTarget: typeof updatePropertyTarget;
66
- /** @internal */
67
- targetName?: string;
34
+ export interface ContentTemplate {
68
35
  /**
69
- * Bind this behavior to the source.
70
- * @param source - The source to bind to.
71
- * @param context - The execution context that the binding is operating within.
36
+ * Creates a simple content view instance.
72
37
  */
73
- bind: typeof normalBind;
38
+ create(): ContentView;
39
+ }
40
+ /**
41
+ * A directive that applies bindings.
42
+ * @public
43
+ */
44
+ export declare class HTMLBindingDirective implements HTMLDirective, ViewBehaviorFactory, ViewBehavior, Aspected {
45
+ dataBinding: Binding;
46
+ private data;
47
+ private updateTarget;
48
+ /**
49
+ * The unique id of the factory.
50
+ */
51
+ id: string;
74
52
  /**
75
- * Unbinds this behavior from the source.
76
- * @param source - The source to unbind from.
53
+ * The structural id of the DOM node to which the created behavior will apply.
77
54
  */
78
- unbind: typeof normalUnbind;
55
+ nodeId: string;
79
56
  /**
80
- * Creates an instance of BindingBehavior.
81
- * @param target - The target of the data updates.
82
- * @param binding - The binding that returns the latest value for an update.
83
- * @param isBindingVolatile - Indicates whether the binding has volatile dependencies.
84
- * @param bind - The operation to perform during binding.
85
- * @param unbind - The operation to perform during unbinding.
86
- * @param updateTarget - The operation to perform when updating.
87
- * @param targetName - The name of the target attribute or property to update.
57
+ * The original source aspect exactly as represented in markup.
88
58
  */
89
- constructor(target: any, binding: Binding, isBindingVolatile: boolean, bind: typeof normalBind, unbind: typeof normalUnbind, updateTarget: typeof updatePropertyTarget, targetName?: string);
59
+ sourceAspect: string;
60
+ /**
61
+ * The evaluated target aspect, determined after processing the source.
62
+ */
63
+ targetAspect: string;
64
+ /**
65
+ * The type of aspect to target.
66
+ */
67
+ aspectType: Aspect;
68
+ /**
69
+ * Creates an instance of HTMLBindingDirective.
70
+ * @param dataBinding - The binding configuration to apply.
71
+ */
72
+ constructor(dataBinding: Binding);
73
+ /**
74
+ * Creates HTML to be used within a template.
75
+ * @param add - Can be used to add behavior factories to a template.
76
+ */
77
+ createHTML(add: AddViewBehaviorFactory): string;
78
+ /**
79
+ * Creates a behavior.
80
+ */
81
+ createBehavior(): ViewBehavior;
82
+ /** @internal */
83
+ bindDefault(controller: ViewController): void;
90
84
  /** @internal */
91
- handleChange(): void;
85
+ bind: (controller: ViewController) => void;
86
+ /** @internal */
87
+ bindContent(controller: ViewController): void;
88
+ /** @internal */
89
+ bindEvent(controller: ViewController): void;
90
+ /** @internal */
91
+ unbind(controller: ViewController): void;
92
92
  /** @internal */
93
93
  handleEvent(event: Event): void;
94
+ /** @internal */
95
+ handleChange(binding: Expression, observer: ExpressionObserver): void;
94
96
  }
95
- export {};
97
+ /**
98
+ * Creates an standard binding.
99
+ * @param binding - The binding to refresh when changed.
100
+ * @param isVolatile - Indicates whether the binding is volatile or not.
101
+ * @returns A binding configuration.
102
+ * @public
103
+ */
104
+ export declare function bind<T = any>(binding: Expression<T>, isVolatile?: boolean): Binding<T>;
105
+ /**
106
+ * Creates a one time binding
107
+ * @param binding - The binding to refresh when signaled.
108
+ * @returns A binding configuration.
109
+ * @public
110
+ */
111
+ export declare function oneTime<T = any>(binding: Expression<T>): Binding<T>;
112
+ /**
113
+ * Creates an event listener binding.
114
+ * @param binding - The binding to invoke when the event is raised.
115
+ * @param options - Event listener options.
116
+ * @returns A binding configuration.
117
+ * @public
118
+ */
119
+ export declare function listener<T = any>(binding: Expression<T>, options?: AddEventListenerOptions): Binding<T>;
120
+ /**
121
+ * Normalizes the input value into a binding.
122
+ * @param value - The value to create the default binding for.
123
+ * @returns A binding configuration for the provided value.
124
+ * @public
125
+ */
126
+ export declare function normalizeBinding<TSource = any, TReturn = any, TParent = any>(value: Expression<TSource, TReturn, TParent> | Binding<TSource, TReturn, TParent> | {}): Binding<TSource, TReturn, TParent>;
@@ -1,16 +1,16 @@
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 child list observation.
5
5
  * @public
6
6
  */
7
- export interface ChildListBehaviorOptions<T = any> extends NodeBehaviorOptions<T>, Omit<MutationObserverInit, "subtree" | "childList"> {
7
+ export interface ChildListDirectiveOptions<T = any> extends NodeBehaviorOptions<T>, Omit<MutationObserverInit, "subtree" | "childList"> {
8
8
  }
9
9
  /**
10
10
  * The options used to configure subtree observation.
11
11
  * @public
12
12
  */
13
- export interface SubtreeBehaviorOptions<T = any> extends Omit<NodeBehaviorOptions<T>, "filter">, Omit<MutationObserverInit, "subtree" | "childList"> {
13
+ export interface SubtreeDirectiveOptions<T = any> extends NodeBehaviorOptions<T>, Omit<MutationObserverInit, "subtree" | "childList"> {
14
14
  /**
15
15
  * Indicates that child subtrees should be observed for changes.
16
16
  */
@@ -25,31 +25,34 @@ export interface SubtreeBehaviorOptions<T = any> extends Omit<NodeBehaviorOption
25
25
  * The options used to configure child/subtree node observation.
26
26
  * @public
27
27
  */
28
- export declare type ChildrenBehaviorOptions<T = any> = ChildListBehaviorOptions<T> | SubtreeBehaviorOptions<T>;
28
+ export declare type ChildrenDirectiveOptions<T = any> = ChildListDirectiveOptions<T> | SubtreeDirectiveOptions<T>;
29
29
  /**
30
30
  * The runtime behavior for child node observation.
31
31
  * @public
32
32
  */
33
- export declare class ChildrenBehavior extends NodeObservationBehavior<ChildrenBehaviorOptions> {
34
- private observer;
33
+ export declare class ChildrenDirective extends NodeObservationDirective<ChildrenDirectiveOptions> {
34
+ private observerProperty;
35
35
  /**
36
- * Creates an instance of ChildrenBehavior.
37
- * @param target - The element target to observe children on.
38
- * @param options - The options to use when observing the element children.
36
+ * Creates an instance of ChildrenDirective.
37
+ * @param options - The options to use in configuring the child observation behavior.
39
38
  */
40
- constructor(target: HTMLElement, options: ChildrenBehaviorOptions);
39
+ constructor(options: ChildrenDirectiveOptions);
41
40
  /**
42
41
  * Begins observation of the nodes.
42
+ * @param target - The target to observe.
43
43
  */
44
- observe(): void;
44
+ observe(target: any): void;
45
45
  /**
46
46
  * Disconnects observation of the nodes.
47
+ * @param target - The target to unobserve.
47
48
  */
48
- disconnect(): void;
49
+ disconnect(target: any): void;
49
50
  /**
50
- * Retrieves the nodes that should be assigned to the target.
51
+ * Retrieves the raw nodes that should be assigned to the source property.
52
+ * @param target - The target to get the node to.
51
53
  */
52
- protected getNodes(): ChildNode[];
54
+ getNodes(target: Element): Node[];
55
+ private handleEvent;
53
56
  }
54
57
  /**
55
58
  * A directive that observes the `childNodes` of an element and updates a property
@@ -57,4 +60,4 @@ export declare class ChildrenBehavior extends NodeObservationBehavior<ChildrenBe
57
60
  * @param propertyOrOptions - The options used to configure child node observation.
58
61
  * @public
59
62
  */
60
- export declare function children<T = any>(propertyOrOptions: (keyof T & string) | ChildrenBehaviorOptions<keyof T & string>): CaptureType<T>;
63
+ export declare function children<TSource = any, TParent = any>(propertyOrOptions: (keyof TSource & string) | ChildrenDirectiveOptions<keyof TSource & string>): CaptureType<TSource, TParent>;
@@ -1,38 +1,56 @@
1
- import type { HTMLDirective, NodeBehaviorFactory } from "./html-directive.js";
1
+ import { TrustedTypesPolicy } from "../interfaces.js";
2
+ import { ViewBehaviorFactory } from "./html-directive.js";
3
+ import type { HTMLTemplateCompilationResult as TemplateCompilationResult } from "./template.js";
2
4
  /**
3
- * The result of compiling a template and its directives.
4
- * @beta
5
+ * A function capable of compiling a template from the preprocessed form produced
6
+ * by the html template function into a result that can instantiate views.
7
+ * @public
8
+ */
9
+ export declare type CompilationStrategy = (
10
+ /**
11
+ * The preprocessed HTML string or template to compile.
5
12
  */
6
- export interface CompilationResult {
13
+ html: string | HTMLTemplateElement,
14
+ /**
15
+ * The behavior factories used within the html that is being compiled.
16
+ */
17
+ factories: Record<string, ViewBehaviorFactory>) => TemplateCompilationResult;
18
+ /**
19
+ * Common APIs related to compilation.
20
+ * @public
21
+ */
22
+ export declare const Compiler: {
7
23
  /**
8
- * A cloneable DocumentFragment representing the compiled HTML.
24
+ * Sets the HTML trusted types policy used by the compiler.
25
+ * @param policy - The policy to set for HTML.
26
+ * @remarks
27
+ * This API can only be called once, for security reasons. It should be
28
+ * called by the application developer at the start of their program.
9
29
  */
10
- fragment: DocumentFragment;
30
+ setHTMLPolicy(policy: TrustedTypesPolicy): void;
11
31
  /**
12
- * The behaviors that should be applied to the template's HTML.
32
+ * Compiles a template and associated directives into a compilation
33
+ * result which can be used to create views.
34
+ * @param html - The html string or template element to compile.
35
+ * @param directives - The directives referenced by the template.
36
+ * @remarks
37
+ * The template that is provided for compilation is altered in-place
38
+ * and cannot be compiled again. If the original template must be preserved,
39
+ * it is recommended that you clone the original and pass the clone to this API.
40
+ * @public
13
41
  */
14
- viewBehaviorFactories: NodeBehaviorFactory[];
42
+ compile<TSource = any, TParent = any>(html: string | HTMLTemplateElement, directives: Record<string, ViewBehaviorFactory>): TemplateCompilationResult<TSource, TParent>;
15
43
  /**
16
- * The behaviors that should be applied to the host element that
17
- * the template is rendered into.
44
+ * Sets the default compilation strategy that will be used by the ViewTemplate whenever
45
+ * it needs to compile a view preprocessed with the html template function.
46
+ * @param strategy - The compilation strategy to use when compiling templates.
18
47
  */
19
- hostBehaviorFactories: NodeBehaviorFactory[];
48
+ setDefaultStrategy(strategy: CompilationStrategy): void;
20
49
  /**
21
- * An index offset to apply to BehaviorFactory target indexes when
22
- * matching factories to targets.
50
+ * Aggregates an array of strings and directives into a single directive.
51
+ * @param parts - A heterogeneous array of static strings interspersed with
52
+ * directives.
53
+ * @returns A single inline directive that aggregates the behavior of all the parts.
23
54
  */
24
- targetOffset: number;
25
- }
26
- /**
27
- * Compiles a template and associated directives into a raw compilation
28
- * result which include a cloneable DocumentFragment and factories capable
29
- * of attaching runtime behavior to nodes within the fragment.
30
- * @param template - The template to compile.
31
- * @param directives - The directives referenced by the template.
32
- * @remarks
33
- * The template that is provided for compilation is altered in-place
34
- * and cannot be compiled again. If the original template must be preserved,
35
- * it is recommended that you clone the original and pass the clone to this API.
36
- * @public
37
- */
38
- export declare function compileTemplate(template: HTMLTemplateElement, directives: ReadonlyArray<HTMLDirective>): CompilationResult;
55
+ aggregate(parts: (string | ViewBehaviorFactory)[]): ViewBehaviorFactory;
56
+ };