@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
@@ -0,0 +1,84 @@
1
+ import { isString } from "../interfaces.js";
2
+ import { BindingMode, UpdateBinding } from "./binding.js";
3
+ const signals = Object.create(null);
4
+ /**
5
+ * A binding behavior for signal bindings.
6
+ * @public
7
+ */
8
+ export class SignalBinding extends UpdateBinding {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.handlerProperty = `${this.directive.id}-h`;
12
+ }
13
+ /**
14
+ * Bind this behavior to the source.
15
+ * @param source - The source to bind to.
16
+ * @param context - The execution context that the binding is operating within.
17
+ * @param targets - The targets that behaviors in a view can attach to.
18
+ */
19
+ bind(source, context, targets) {
20
+ const directive = this.directive;
21
+ const target = targets[directive.nodeId];
22
+ const signal = this.getSignal(source, context);
23
+ const handler = (target[this.handlerProperty] = () => {
24
+ this.updateTarget(target, directive.targetAspect, directive.binding(source, context), source, context);
25
+ });
26
+ handler();
27
+ const found = signals[signal];
28
+ if (found) {
29
+ Array.isArray(found)
30
+ ? found.push(handler)
31
+ : (signals[signal] = [found, handler]);
32
+ }
33
+ else {
34
+ signals[signal] = handler;
35
+ }
36
+ }
37
+ /**
38
+ * Unbinds this behavior from the source.
39
+ * @param source - The source to unbind from.
40
+ * @param context - The execution context that the binding is operating within.
41
+ * @param targets - The targets that behaviors in a view can attach to.
42
+ */
43
+ unbind(source, context, targets) {
44
+ const signal = this.getSignal(source, context);
45
+ const found = signals[signal];
46
+ if (found && Array.isArray(found)) {
47
+ const directive = this.directive;
48
+ const target = targets[directive.nodeId];
49
+ const handler = target[this.handlerProperty];
50
+ const index = found.indexOf(handler);
51
+ if (index !== -1) {
52
+ found.splice(index, 1);
53
+ }
54
+ }
55
+ else {
56
+ signals[signal] = void 0;
57
+ }
58
+ }
59
+ getSignal(source, context) {
60
+ const options = this.directive.options;
61
+ return isString(options) ? options : options(source, context);
62
+ }
63
+ /**
64
+ * Sends the specified signal to signaled bindings.
65
+ * @param signal - The signal to send.
66
+ * @public
67
+ */
68
+ static send(signal) {
69
+ const found = signals[signal];
70
+ if (found) {
71
+ Array.isArray(found) ? found.forEach(x => x()) : found();
72
+ }
73
+ }
74
+ }
75
+ const signalMode = BindingMode.define(SignalBinding);
76
+ /**
77
+ * Creates a signal binding configuration with the supplied options.
78
+ * @param options - The signal name or a binding to use to retrieve the signal name.
79
+ * @returns A binding configuration.
80
+ * @public
81
+ */
82
+ export const signal = (options) => {
83
+ return { mode: signalMode, options };
84
+ };
@@ -0,0 +1,82 @@
1
+ import "../interfaces.js";
2
+ import { FAST } from "../platform.js";
3
+ import { BindingConfig, BindingMode, ChangeBinding, } from "./binding.js";
4
+ let twoWaySettings = {
5
+ determineChangeEvent() {
6
+ return "change";
7
+ },
8
+ };
9
+ /**
10
+ * A binding behavior for bindings that update in two directions.
11
+ * @public
12
+ */
13
+ export class TwoWayBinding extends ChangeBinding {
14
+ /**
15
+ * Bind this behavior to the source.
16
+ * @param source - The source to bind to.
17
+ * @param context - The execution context that the binding is operating within.
18
+ * @param targets - The targets that behaviors in a view can attach to.
19
+ */
20
+ bind(source, context, targets) {
21
+ var _a;
22
+ super.bind(source, context, targets);
23
+ const directive = this.directive;
24
+ const target = targets[directive.nodeId];
25
+ if (!this.changeEvent) {
26
+ this.changeEvent =
27
+ (_a = directive.options.changeEvent) !== null && _a !== void 0 ? _a : twoWaySettings.determineChangeEvent(directive, target);
28
+ }
29
+ target.addEventListener(this.changeEvent, this);
30
+ }
31
+ /**
32
+ * Unbinds this behavior from the source.
33
+ * @param source - The source to unbind from.
34
+ * @param context - The execution context that the binding is operating within.
35
+ * @param targets - The targets that behaviors in a view can attach to.
36
+ */
37
+ unbind(source, context, targets) {
38
+ super.unbind(source, context, targets);
39
+ targets[this.directive.nodeId].removeEventListener(this.changeEvent, this);
40
+ }
41
+ /** @internal */
42
+ handleEvent(event) {
43
+ const directive = this.directive;
44
+ const target = event.currentTarget;
45
+ const observer = this.getObserver(target);
46
+ const last = observer.last; // using internal API!!!
47
+ if (!last) {
48
+ FAST.warn(1203 /* Message.twoWayBindingRequiresObservables */);
49
+ return;
50
+ }
51
+ let value;
52
+ switch (directive.aspectType) {
53
+ case 1:
54
+ value = target.getAttribute(directive.targetAspect);
55
+ break;
56
+ case 2:
57
+ value = target.hasAttribute(directive.targetAspect);
58
+ break;
59
+ case 4:
60
+ value = target.innerText;
61
+ break;
62
+ default:
63
+ value = target[directive.targetAspect];
64
+ break;
65
+ }
66
+ last.propertySource[last.propertyName] = directive.options.fromView(value);
67
+ }
68
+ /**
69
+ * Configures two-way binding.
70
+ * @param settings - The settings to use for the two-way binding system.
71
+ */
72
+ static configure(settings) {
73
+ twoWaySettings = settings;
74
+ }
75
+ }
76
+ /**
77
+ * The default twoWay binding configuration.
78
+ * @public
79
+ */
80
+ export const twoWay = BindingConfig.define(BindingMode.define(TwoWayBinding), {
81
+ fromView: v => v,
82
+ });