@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.
Files changed (104) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +387 -1
  3. package/CHANGELOG.md +74 -2
  4. package/README.md +2 -2
  5. package/dist/dts/components/attributes.d.ts +4 -1
  6. package/dist/dts/components/controller.d.ts +12 -11
  7. package/dist/dts/components/fast-definitions.d.ts +10 -2
  8. package/dist/dts/components/fast-element.d.ts +12 -5
  9. package/dist/dts/context.d.ts +157 -0
  10. package/dist/dts/debug.d.ts +1 -0
  11. package/dist/dts/hooks.d.ts +20 -0
  12. package/dist/dts/index.d.ts +16 -15
  13. package/dist/dts/index.debug.d.ts +2 -0
  14. package/dist/dts/index.rollup.d.ts +2 -0
  15. package/dist/dts/index.rollup.debug.d.ts +3 -0
  16. package/dist/dts/interfaces.d.ts +145 -0
  17. package/dist/dts/metadata.d.ts +25 -0
  18. package/dist/dts/observation/arrays.d.ts +207 -0
  19. package/dist/dts/observation/behavior.d.ts +4 -4
  20. package/dist/dts/observation/notifier.d.ts +18 -18
  21. package/dist/dts/observation/observable.d.ts +56 -18
  22. package/dist/dts/observation/splice-strategies.d.ts +13 -0
  23. package/dist/dts/observation/update-queue.d.ts +40 -0
  24. package/dist/dts/platform.d.ts +18 -67
  25. package/dist/dts/polyfills.d.ts +8 -0
  26. package/dist/dts/styles/css-directive.d.ts +43 -5
  27. package/dist/dts/styles/css.d.ts +19 -3
  28. package/dist/dts/styles/element-styles.d.ts +42 -62
  29. package/dist/dts/templating/binding-signal.d.ts +38 -0
  30. package/dist/dts/templating/binding-two-way.d.ts +56 -0
  31. package/dist/dts/templating/binding.d.ts +233 -65
  32. package/dist/dts/templating/children.d.ts +18 -15
  33. package/dist/dts/templating/compiler.d.ts +46 -28
  34. package/dist/dts/templating/dom.d.ts +41 -0
  35. package/dist/dts/templating/html-directive.d.ts +181 -43
  36. package/dist/dts/templating/markup.d.ts +48 -0
  37. package/dist/dts/templating/node-observation.d.ts +45 -29
  38. package/dist/dts/templating/ref.d.ts +6 -12
  39. package/dist/dts/templating/repeat.d.ts +26 -14
  40. package/dist/dts/templating/slotted.d.ts +13 -14
  41. package/dist/dts/templating/template.d.ts +27 -21
  42. package/dist/dts/templating/view.d.ts +15 -22
  43. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  44. package/dist/dts/utilities.d.ts +40 -0
  45. package/dist/esm/components/attributes.js +25 -24
  46. package/dist/esm/components/controller.js +77 -57
  47. package/dist/esm/components/fast-definitions.js +16 -22
  48. package/dist/esm/components/fast-element.js +10 -2
  49. package/dist/esm/context.js +159 -0
  50. package/dist/esm/debug.js +30 -0
  51. package/dist/esm/hooks.js +32 -0
  52. package/dist/esm/index.debug.js +2 -0
  53. package/dist/esm/index.js +19 -14
  54. package/dist/esm/index.rollup.debug.js +3 -0
  55. package/dist/esm/index.rollup.js +2 -0
  56. package/dist/esm/interfaces.js +8 -1
  57. package/dist/esm/metadata.js +60 -0
  58. package/dist/esm/observation/arrays.js +269 -0
  59. package/dist/esm/observation/notifier.js +27 -35
  60. package/dist/esm/observation/observable.js +93 -68
  61. package/dist/esm/observation/{array-change-records.js → splice-strategies.js} +136 -62
  62. package/dist/esm/observation/update-queue.js +67 -0
  63. package/dist/esm/platform.js +36 -42
  64. package/dist/esm/polyfills.js +85 -0
  65. package/dist/esm/styles/css-directive.js +29 -13
  66. package/dist/esm/styles/css.js +27 -40
  67. package/dist/esm/styles/element-styles.js +65 -104
  68. package/dist/esm/templating/binding-signal.js +84 -0
  69. package/dist/esm/templating/binding-two-way.js +82 -0
  70. package/dist/esm/templating/binding.js +306 -153
  71. package/dist/esm/templating/children.js +33 -23
  72. package/dist/esm/templating/compiler.js +236 -152
  73. package/dist/esm/templating/dom.js +49 -0
  74. package/dist/esm/templating/html-directive.js +128 -40
  75. package/dist/esm/templating/markup.js +75 -0
  76. package/dist/esm/templating/node-observation.js +50 -45
  77. package/dist/esm/templating/ref.js +7 -16
  78. package/dist/esm/templating/repeat.js +39 -36
  79. package/dist/esm/templating/slotted.js +23 -20
  80. package/dist/esm/templating/template.js +51 -95
  81. package/dist/esm/templating/view.js +44 -43
  82. package/dist/esm/templating/when.js +2 -1
  83. package/dist/esm/utilities.js +139 -0
  84. package/dist/fast-element.api.json +11789 -5377
  85. package/dist/fast-element.d.ts +1178 -530
  86. package/dist/fast-element.debug.js +3722 -0
  87. package/dist/fast-element.debug.min.js +1 -0
  88. package/dist/fast-element.js +3484 -4033
  89. package/dist/fast-element.min.js +1 -1
  90. package/dist/fast-element.untrimmed.d.ts +2699 -0
  91. package/docs/api-report.md +472 -219
  92. package/docs/fast-element-2-changes.md +15 -0
  93. package/docs/guide/declaring-templates.md +4 -4
  94. package/docs/guide/defining-elements.md +2 -2
  95. package/docs/guide/next-steps.md +2 -2
  96. package/docs/guide/observables-and-state.md +1 -1
  97. package/docs/guide/using-directives.md +1 -1
  98. package/karma.conf.cjs +6 -17
  99. package/package.json +63 -15
  100. package/dist/dts/dom.d.ts +0 -112
  101. package/dist/dts/observation/array-change-records.d.ts +0 -48
  102. package/dist/dts/observation/array-observer.d.ts +0 -9
  103. package/dist/esm/dom.js +0 -207
  104. 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
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
- }
2
+ import { StyleStrategy, StyleTarget } from "../interfaces.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<Behavior<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,21 @@ 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: Behavior<HTMLElement>[]): this;
51
+ /**
52
+ * Sets the strategy that handles adding/removing these styles for an element.
53
+ * @param strategy - The strategy to use.
54
+ */
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;
64
61
  /**
65
- * Create ElementStyles from ComposableStyles.
62
+ * Indicates whether the DOM supports the adoptedStyleSheets feature.
66
63
  */
67
- static readonly create: ElementStyleFactory;
64
+ static readonly supportsAdoptedStyleSheets: boolean;
68
65
  }
69
66
  /**
70
67
  * https://wicg.github.io/construct-stylesheets/
@@ -72,27 +69,10 @@ export declare abstract class ElementStyles {
72
69
  *
73
70
  * @internal
74
71
  */
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[]);
72
+ export declare class AdoptedStyleSheetsStrategy implements StyleStrategy {
73
+ /** @internal */
74
+ readonly sheets: CSSStyleSheet[];
75
+ constructor(styles: (string | CSSStyleSheet)[]);
94
76
  addStylesTo(target: StyleTarget): void;
95
77
  removeStylesFrom(target: StyleTarget): void;
96
- isAttachedTo(target: StyleTarget): boolean;
97
- private normalizeTarget;
98
78
  }
@@ -0,0 +1,38 @@
1
+ import type { Binding, ExecutionContext } from "../observation/observable.js";
2
+ import { BindingConfig, UpdateBinding } from "./binding.js";
3
+ import type { ViewBehaviorTargets } from "./html-directive.js";
4
+ /**
5
+ * A binding behavior for signal bindings.
6
+ * @public
7
+ */
8
+ export declare class SignalBinding extends UpdateBinding {
9
+ private handlerProperty;
10
+ /**
11
+ * Bind this behavior to the source.
12
+ * @param source - The source to bind to.
13
+ * @param context - The execution context that the binding is operating within.
14
+ * @param targets - The targets that behaviors in a view can attach to.
15
+ */
16
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
17
+ /**
18
+ * Unbinds this behavior from the source.
19
+ * @param source - The source to unbind from.
20
+ * @param context - The execution context that the binding is operating within.
21
+ * @param targets - The targets that behaviors in a view can attach to.
22
+ */
23
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
24
+ private getSignal;
25
+ /**
26
+ * Sends the specified signal to signaled bindings.
27
+ * @param signal - The signal to send.
28
+ * @public
29
+ */
30
+ static send(signal: string): void;
31
+ }
32
+ /**
33
+ * Creates a signal binding configuration with the supplied options.
34
+ * @param options - The signal name or a binding to use to retrieve the signal name.
35
+ * @returns A binding configuration.
36
+ * @public
37
+ */
38
+ export declare const signal: <T = any>(options: string | Binding<T, any, any>) => BindingConfig<string | Binding<T, any, any>>;
@@ -0,0 +1,56 @@
1
+ import type { ExecutionContext } from "../observation/observable.js";
2
+ import { BindingConfig, ChangeBinding, DefaultBindingOptions, HTMLBindingDirective } from "./binding.js";
3
+ import type { ViewBehaviorTargets } from "./html-directive.js";
4
+ /**
5
+ * The settings required to enable two-way binding.
6
+ * @public
7
+ */
8
+ export interface TwoWaySettings {
9
+ /**
10
+ * Determines which event to listen to, to detect changes in the view.
11
+ * @param directive - The directive to determine the change event for.
12
+ * @param target - The target element to determine the change event for.
13
+ */
14
+ determineChangeEvent(directive: HTMLBindingDirective, target: HTMLElement): string;
15
+ }
16
+ /**
17
+ * A binding behavior for bindings that update in two directions.
18
+ * @public
19
+ */
20
+ export declare class TwoWayBinding extends ChangeBinding {
21
+ private changeEvent;
22
+ /**
23
+ * Bind this behavior to the source.
24
+ * @param source - The source to bind to.
25
+ * @param context - The execution context that the binding is operating within.
26
+ * @param targets - The targets that behaviors in a view can attach to.
27
+ */
28
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
29
+ /**
30
+ * Unbinds this behavior from the source.
31
+ * @param source - The source to unbind from.
32
+ * @param context - The execution context that the binding is operating within.
33
+ * @param targets - The targets that behaviors in a view can attach to.
34
+ */
35
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
36
+ /** @internal */
37
+ handleEvent(event: Event): void;
38
+ /**
39
+ * Configures two-way binding.
40
+ * @param settings - The settings to use for the two-way binding system.
41
+ */
42
+ static configure(settings: TwoWaySettings): void;
43
+ }
44
+ /**
45
+ * The default twoWay binding options.
46
+ * @public
47
+ */
48
+ export declare type DefaultTwoWayBindingOptions = DefaultBindingOptions & {
49
+ changeEvent?: string;
50
+ fromView?: (value: any) => any;
51
+ };
52
+ /**
53
+ * The default twoWay binding configuration.
54
+ * @public
55
+ */
56
+ export declare const twoWay: BindingConfig<DefaultTwoWayBindingOptions> & import("./binding.js").BindingConfigResolver<DefaultTwoWayBindingOptions>;
@@ -1,95 +1,263 @@
1
- import type { Behavior } from "../observation/behavior.js";
2
1
  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;
2
+ import { AddViewBehaviorFactory, Aspect, Aspected, HTMLDirective, ViewBehavior, ViewBehaviorFactory, ViewBehaviorTargets } from "./html-directive.js";
3
+ import type { CaptureType } from "./template.js";
7
4
  /**
8
- * A directive that configures data binding to element content and attributes.
5
+ * Describes how aspects of an HTML element will be affected by bindings.
9
6
  * @public
10
7
  */
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;
8
+ export declare type BindingMode = Record<Aspect, (directive: HTMLBindingDirective) => Pick<ViewBehaviorFactory, "createBehavior">>;
9
+ /**
10
+ * Describes how aspects of an HTML element will be affected by bindings.
11
+ * @public
12
+ */
13
+ export declare const BindingMode: Readonly<{
19
14
  /**
20
- * Creates an instance of BindingDirective.
21
- * @param binding - A binding that returns the data used to update the DOM.
15
+ * Creates a binding mode based on the supplied behavior types.
16
+ * @param UpdateType - The base behavior type used to update aspects.
17
+ * @param EventType - The base behavior type used to respond to events.
18
+ * @returns A new binding mode.
22
19
  */
23
- constructor(binding: Binding);
20
+ define(UpdateType: typeof UpdateBinding, EventType?: typeof EventBinding): BindingMode;
21
+ }>;
22
+ /**
23
+ * Describes the configuration for a binding expression.
24
+ * @public
25
+ */
26
+ export interface BindingConfig<T = any> {
24
27
  /**
25
- * Gets/sets the name of the attribute or property that this
26
- * binding is targeting.
28
+ * The binding mode to configure the binding with.
27
29
  */
28
- get targetName(): string | undefined;
29
- set targetName(value: string | undefined);
30
+ mode: BindingMode;
31
+ /**
32
+ * Options to be supplied to the binding behaviors.
33
+ */
34
+ options: T;
35
+ }
36
+ /**
37
+ * Creates a new binding configuration based on the supplied options.
38
+ * @public
39
+ */
40
+ export declare type BindingConfigResolver<T> = (options: T) => BindingConfig<T>;
41
+ /**
42
+ * Describes the configuration for a binding expression.
43
+ * @public
44
+ */
45
+ export declare const BindingConfig: Readonly<{
30
46
  /**
31
- * Makes this binding target the content of an element rather than
32
- * a particular attribute or property.
47
+ * Creates a binding configuration based on the provided mode and options.
48
+ * @param mode - The mode to use for the configuration.
49
+ * @param defaultOptions - The default options to use for the configuration.
50
+ * @returns A new binding configuration.
33
51
  */
34
- targetAtContent(): void;
52
+ define<T>(mode: BindingMode, defaultOptions: T): BindingConfig<T> & BindingConfigResolver<T>;
53
+ }>;
54
+ /**
55
+ * The "this" context for an update target function.
56
+ * @public
57
+ */
58
+ export interface UpdateTargetThis {
35
59
  /**
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.
60
+ * The directive configuration for the update.
39
61
  */
40
- createBehavior(target: Node): BindingBehavior;
62
+ directive: HTMLBindingDirective;
41
63
  }
42
64
  /**
43
- * A behavior that updates content and attributes based on a configured
44
- * BindingDirective.
65
+ * A target update function.
66
+ * @param this - The "this" context for the update.
67
+ * @param target - The node that is targeted by the update.
68
+ * @param aspect - The aspect of the node that is being targeted.
69
+ * @param value - The value to assign to the aspect.
70
+ * @param source - The source object that the value was derived from.
71
+ * @param context - The execution context that the binding is being run under.
45
72
  * @public
46
73
  */
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;
74
+ export declare type UpdateTarget = (this: UpdateTargetThis, target: Node, aspect: string, value: any, source: any, context: ExecutionContext) => void;
75
+ /**
76
+ * A base binding behavior for DOM updates.
77
+ * @public
78
+ */
79
+ export declare class UpdateBinding implements ViewBehavior {
80
+ readonly directive: HTMLBindingDirective;
81
+ protected updateTarget: UpdateTarget;
82
+ /**
83
+ * Creates an instance of UpdateBinding.
84
+ * @param directive - The directive that has the configuration for this behavior.
85
+ * @param updateTarget - The function used to update the target with the latest value.
86
+ */
87
+ constructor(directive: HTMLBindingDirective, updateTarget: UpdateTarget);
68
88
  /**
69
89
  * Bind this behavior to the source.
70
90
  * @param source - The source to bind to.
71
91
  * @param context - The execution context that the binding is operating within.
92
+ * @param targets - The targets that behaviors in a view can attach to.
72
93
  */
73
- bind: typeof normalBind;
94
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
74
95
  /**
75
96
  * Unbinds this behavior from the source.
76
97
  * @param source - The source to unbind from.
98
+ * @param context - The execution context that the binding is operating within.
99
+ * @param targets - The targets that behaviors in a view can attach to.
77
100
  */
78
- unbind: typeof normalUnbind;
101
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
79
102
  /**
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.
103
+ * Creates a behavior.
104
+ * @param targets - The targets available for behaviors to be attached to.
88
105
  */
89
- constructor(target: any, binding: Binding, isBindingVolatile: boolean, bind: typeof normalBind, unbind: typeof normalUnbind, updateTarget: typeof updatePropertyTarget, targetName?: string);
90
- /** @internal */
91
- handleChange(): void;
106
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
107
+ }
108
+ /**
109
+ * A binding behavior for one-time bindings.
110
+ * @public
111
+ */
112
+ export declare class OneTimeBinding extends UpdateBinding {
113
+ /**
114
+ * Bind this behavior to the source.
115
+ * @param source - The source to bind to.
116
+ * @param context - The execution context that the binding is operating within.
117
+ * @param targets - The targets that behaviors in a view can attach to.
118
+ */
119
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
120
+ }
121
+ /**
122
+ * A binding behavior for bindings that change.
123
+ * @public
124
+ */
125
+ export declare class ChangeBinding extends UpdateBinding {
126
+ private isBindingVolatile;
127
+ private observerProperty;
128
+ /**
129
+ * Creates an instance of ChangeBinding.
130
+ * @param directive - The directive that has the configuration for this behavior.
131
+ * @param updateTarget - The function used to update the target with the latest value.
132
+ */
133
+ constructor(directive: HTMLBindingDirective, updateTarget: UpdateTarget);
134
+ /**
135
+ * Returns the binding observer used to update the node.
136
+ * @param target - The target node.
137
+ * @returns A BindingObserver.
138
+ */
139
+ protected getObserver(target: Node): BindingObserver;
140
+ /**
141
+ * Bind this behavior to the source.
142
+ * @param source - The source to bind to.
143
+ * @param context - The execution context that the binding is operating within.
144
+ * @param targets - The targets that behaviors in a view can attach to.
145
+ */
146
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
147
+ /**
148
+ * Unbinds this behavior from the source.
149
+ * @param source - The source to unbind from.
150
+ * @param context - The execution context that the binding is operating within.
151
+ * @param targets - The targets that behaviors in a view can attach to.
152
+ */
153
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
92
154
  /** @internal */
155
+ handleChange(binding: Binding, observer: BindingObserver): void;
156
+ }
157
+ /**
158
+ * A binding behavior for handling events.
159
+ * @public
160
+ */
161
+ export declare class EventBinding {
162
+ readonly directive: HTMLBindingDirective;
163
+ private contextProperty;
164
+ private sourceProperty;
165
+ /**
166
+ * Creates an instance of EventBinding.
167
+ * @param directive - The directive that has the configuration for this behavior.
168
+ */
169
+ constructor(directive: HTMLBindingDirective);
170
+ /**
171
+ * Bind this behavior to the source.
172
+ * @param source - The source to bind to.
173
+ * @param context - The execution context that the binding is operating within.
174
+ * @param targets - The targets that behaviors in a view can attach to.
175
+ */
176
+ bind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
177
+ /**
178
+ * Unbinds this behavior from the source.
179
+ * @param source - The source to unbind from.
180
+ * @param context - The execution context that the binding is operating within.
181
+ * @param targets - The targets that behaviors in a view can attach to.
182
+ */
183
+ unbind(source: any, context: ExecutionContext, targets: ViewBehaviorTargets): void;
184
+ /**
185
+ * Creates a behavior.
186
+ * @param targets - The targets available for behaviors to be attached to.
187
+ */
188
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
189
+ /**
190
+ * @internal
191
+ */
93
192
  handleEvent(event: Event): void;
94
193
  }
95
- export {};
194
+ /**
195
+ * The default binding options.
196
+ * @public
197
+ */
198
+ export declare type DefaultBindingOptions = AddEventListenerOptions;
199
+ /**
200
+ * The default onChange binding configuration.
201
+ * @public
202
+ */
203
+ export declare const onChange: BindingConfig<AddEventListenerOptions> & BindingConfigResolver<AddEventListenerOptions>;
204
+ /**
205
+ * The default onTime binding configuration.
206
+ * @public
207
+ */
208
+ export declare const oneTime: BindingConfig<AddEventListenerOptions> & BindingConfigResolver<AddEventListenerOptions>;
209
+ /**
210
+ * A directive that applies bindings.
211
+ * @public
212
+ */
213
+ export declare class HTMLBindingDirective implements HTMLDirective, ViewBehaviorFactory, Aspected {
214
+ binding: Binding;
215
+ mode: BindingMode;
216
+ options: any;
217
+ private factory;
218
+ /**
219
+ * The unique id of the factory.
220
+ */
221
+ id: string;
222
+ /**
223
+ * The structural id of the DOM node to which the created behavior will apply.
224
+ */
225
+ nodeId: string;
226
+ /**
227
+ * The original source aspect exactly as represented in markup.
228
+ */
229
+ sourceAspect: string;
230
+ /**
231
+ * The evaluated target aspect, determined after processing the source.
232
+ */
233
+ targetAspect: string;
234
+ /**
235
+ * The type of aspect to target.
236
+ */
237
+ aspectType: Aspect;
238
+ /**
239
+ * Creates an instance of HTMLBindingDirective.
240
+ * @param binding - The binding to apply.
241
+ * @param mode - The binding mode to use when applying the binding.
242
+ * @param options - The options to configure the binding with.
243
+ */
244
+ constructor(binding: Binding, mode: BindingMode, options: any);
245
+ /**
246
+ * Creates HTML to be used within a template.
247
+ * @param add - Can be used to add behavior factories to a template.
248
+ */
249
+ createHTML(add: AddViewBehaviorFactory): string;
250
+ /**
251
+ * Creates a behavior.
252
+ * @param targets - The targets available for behaviors to be attached to.
253
+ */
254
+ createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
255
+ }
256
+ /**
257
+ * Creates a binding directive with the specified configuration.
258
+ * @param binding - The binding expression.
259
+ * @param config - The binding configuration.
260
+ * @returns A binding directive.
261
+ * @public
262
+ */
263
+ export declare function bind<T = any>(binding: Binding<T>, config?: BindingConfig | DefaultBindingOptions): CaptureType<T>;
@@ -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<T = any>(propertyOrOptions: (keyof T & string) | ChildrenDirectiveOptions<keyof T & string>): CaptureType<T>;