@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
@@ -0,0 +1,15 @@
1
+ # Changes in FASTElement 2.0
2
+
3
+ ## Breaking Changes
4
+
5
+ * `HTMLDirective` - The `targetIndex: number` property has been replaced by a `targetId: string` property. The `createBehavior` method no longer takes a target `Node` but instead takes a `BehaviorTargets` instance. The actual target can be looked up on the `BehaviorTargets` instance by indexing with the `targetId` property.
6
+ * `compileTemplate()` - Internals have been significantly changed. The implementation no longer uses a TreeWalker. The return type has change to an `HTMLTemplateCompilationResult` with different properties.
7
+ * `View` and `HTMLView` - Type parameters added to enable strongly typed views based on their data source. The constructor of `HTMLView` has a new signature based on changes to the compiler's output. Internals have been cleaned up and no longer rely on the Range type.
8
+ * `ElementViewTemplate`, `SyntheticViewTemplate`, and `ViewTemplate` - Added type parameters throughout. Logic to instantiate and apply behaviors moved out of the template and into the view where it can be lazily executed. Removed the ability of the `render` method to take a string id of the node to render to. You must provide a node.
9
+ * `DOM` - Tree Walker methods are no longer used and are thus removed. The API for removing child nodes has been removed as well since it was only used in one place and could be inlined. The helper `createCustomAttributePlaceholder()` no longer requires an attribute name. It will be uniquely generated internally.
10
+ * `class` - Bindings to `class` are now more nuanced. Binding directly to `class` will simply set the `className` property. If you need to bind to `class` knowing that manual JS will also manipulate the `classList` in addition to the binding, then you should now bind to `:classList` instead. This allows for performance optimizations in the simple, most common case.
11
+ * `Behavior` and `ViewBehavior` - `Behavior` now requires an `ExecutionContext` for `unbind`. Behaviors can be used for elements or views. `ViewBehavior` has been introduced for use exclusively with views, and provides some optimization opportunities.
12
+ * `RefBehavior` has been replaced with `RefDirective`. The directive also implements `ViewBehavior` allowing a single directive instance to be shared across all template instances that use the ref.
13
+ * Removed `SlottedBehavior` and `ChildrenBehavior` have been replaced with `SlottedDirective` and `ChildrenDirective`. These directives allow a single directive instance to be shared across all template instances that use the ref.
14
+ * Removed `AttachedBehaviorHTMLDirective` and `AttachedBehaviorType` since they are no longer used in the new directive/behavior architecture for ref, slotted, and children.
15
+ * Renamed `Notifier#source` to `Notifier#subject` to align with other observable terminology and prevent name clashes with `BindingObserver` properties.
package/karma.conf.cjs CHANGED
@@ -1,5 +1,4 @@
1
1
  const path = require("path");
2
-
3
2
  const basePath = path.resolve(__dirname);
4
3
 
5
4
  const commonChromeFlags = [
@@ -44,9 +43,9 @@ module.exports = function (config) {
44
43
  require("karma-chrome-launcher"),
45
44
  require("karma-firefox-launcher"),
46
45
  ],
47
- files: [`dist/esm/__test__/${setup}.js`],
46
+ files: [`dist/esm/__test__/${setup}.cjs`],
48
47
  preprocessors: {
49
- [`dist/esm/__test__/${setup}.js`]: ["webpack", "sourcemap"],
48
+ [`dist/esm/__test__/${setup}.cjs`]: ["webpack", "sourcemap"],
50
49
  },
51
50
  webpackMiddleware: {
52
51
  // webpack-dev-middleware configuration
@@ -54,7 +53,7 @@ module.exports = function (config) {
54
53
  stats: "errors-only",
55
54
  },
56
55
  webpack: {
57
- mode: "none",
56
+ mode: "development",
58
57
  resolve: {
59
58
  extensions: [".js"],
60
59
  modules: ["dist", "node_modules"],
@@ -65,12 +64,8 @@ module.exports = function (config) {
65
64
  hints: false,
66
65
  },
67
66
  optimization: {
68
- namedModules: false,
69
- namedChunks: false,
70
- nodeEnv: false,
71
67
  usedExports: true,
72
68
  flagIncludedChunks: false,
73
- occurrenceOrder: false,
74
69
  sideEffects: true,
75
70
  concatenateModules: true,
76
71
  splitChunks: {
@@ -89,14 +84,8 @@ module.exports = function (config) {
89
84
  },
90
85
  {
91
86
  test: /\.js$/,
92
- use: [
93
- {
94
- loader: "source-map-loader",
95
- options: {
96
- enforce: "pre",
97
- },
98
- },
99
- ],
87
+ use: ["source-map-loader"],
88
+ enforce: "pre",
100
89
  },
101
90
  ],
102
91
  },
@@ -125,7 +114,7 @@ module.exports = function (config) {
125
114
  timeout: 5000,
126
115
  },
127
116
  },
128
- logLevel: config.LOG_ERROR, // to disable the WARN 404 for image requests
117
+ logLevel: config.LOG_ERROR, // to disable the WARN 404 for image requests,
129
118
  };
130
119
 
131
120
  if (config.coverage) {
package/package.json CHANGED
@@ -1,24 +1,86 @@
1
1
  {
2
2
  "name": "@microsoft/fast-element",
3
3
  "description": "A library for constructing Web Components",
4
- "sideEffects": false,
5
- "version": "1.10.5",
4
+ "version": "2.0.0-beta.10",
6
5
  "author": {
7
6
  "name": "Microsoft",
8
7
  "url": "https://discord.gg/FcSNfg4"
9
8
  },
9
+ "homepage": "https://www.fast.design/",
10
10
  "license": "MIT",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/Microsoft/fast.git"
13
+ "url": "git+https://github.com/Microsoft/fast.git",
14
+ "directory": "packages/web-components/fast-element"
14
15
  },
15
16
  "bugs": {
16
17
  "url": "https://github.com/Microsoft/fast/issues/new/choose"
17
18
  },
18
- "main": "dist/esm/index.js",
19
- "types": "dist/fast-element.d.ts",
20
19
  "type": "module",
20
+ "main": "dist/esm/index.js",
21
+ "types": "dist/dts/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/dts/index.d.ts",
25
+ "production": "./dist/esm/index.js",
26
+ "development": "./dist/esm/index.debug.js",
27
+ "default": "./dist/esm/index.js"
28
+ },
29
+ "./polyfills": {
30
+ "types": "./dist/dts/polyfills.d.ts",
31
+ "default": "./dist/esm/polyfills.js"
32
+ },
33
+ "./debug": {
34
+ "types": "./dist/dts/debug.d.ts",
35
+ "default": "./dist/esm/debug.js"
36
+ },
37
+ "./binding/two-way": {
38
+ "types": "./dist/dts/templating/binding-two-way.d.ts",
39
+ "default": "./dist/esm/templating/binding-two-way.js"
40
+ },
41
+ "./binding/signal": {
42
+ "types": "./dist/dts/templating/binding-signal.d.ts",
43
+ "default": "./dist/esm/templating/binding-signal.js"
44
+ },
45
+ "./render": {
46
+ "types": "./dist/dts/templating/render.d.ts",
47
+ "default": "./dist/esm/templating/render.js"
48
+ },
49
+ "./utilities": {
50
+ "types": "./dist/dts/utilities.d.ts",
51
+ "default": "./dist/esm/utilities.js"
52
+ },
53
+ "./state": {
54
+ "types": "./dist/dts/state/exports.d.ts",
55
+ "default": "./dist/esm/state/exports.js"
56
+ },
57
+ "./context": {
58
+ "types": "./dist/dts/context.d.ts",
59
+ "default": "./dist/esm/context.js"
60
+ },
61
+ "./metadata": {
62
+ "types": "./dist/dts/metadata.d.ts",
63
+ "default": "./dist/esm/metadata.js"
64
+ },
65
+ "./testing": {
66
+ "types": "./dist/dts/testing/exports.d.ts",
67
+ "default": "./dist/esm/testing/exports.js"
68
+ },
69
+ "./di": {
70
+ "types": "./dist/dts/di/di.d.ts",
71
+ "default": "./dist/esm/di/di.js"
72
+ },
73
+ "./pending-task": {
74
+ "types": "./dist/dts/pending-task.d.ts",
75
+ "default": "./dist/esm/pending-task.js"
76
+ },
77
+ "./package.json": "./package.json"
78
+ },
21
79
  "unpkg": "dist/fast-element.min.js",
80
+ "sideEffects": [
81
+ "./dist/esm/debug.js",
82
+ "./dist/esm/polyfills.js"
83
+ ],
22
84
  "scripts": {
23
85
  "clean:dist": "node ../../../build/clean.js dist",
24
86
  "doc": "api-extractor run --local",
@@ -46,13 +108,12 @@
46
108
  "test-firefox:verbose": "karma start karma.conf.cjs --browsers=FirefoxHeadless --single-run --coverage --reporter=mocha"
47
109
  },
48
110
  "devDependencies": {
49
- "@microsoft/api-extractor": "7.23.1",
111
+ "@microsoft/api-extractor": "7.24.2",
50
112
  "@types/chai": "^4.2.11",
51
113
  "@types/chai-spies": "^1.0.3",
52
114
  "@types/karma": "^5.0.0",
53
115
  "@types/mocha": "^7.0.2",
54
116
  "@types/webpack-env": "^1.15.2",
55
- "@types/web-ie11": "^0.0.0",
56
117
  "chai": "^4.2.0",
57
118
  "chai-spies": "^1.0.0",
58
119
  "esm": "^3.2.25",
@@ -70,21 +131,21 @@
70
131
  "karma-mocha-reporter": "^2.2.5",
71
132
  "karma-source-map-support": "^1.4.0",
72
133
  "karma-sourcemap-loader": "^0.3.7",
73
- "karma-webpack": "^4.0.2",
134
+ "karma-webpack": "^5.0.0",
74
135
  "mocha": "^7.1.2",
75
136
  "prettier": "2.0.2",
76
- "rollup": "^2.7.6",
137
+ "rollup": "^2.71.1",
77
138
  "rollup-plugin-filesize": "^9.1.2",
78
- "rollup-plugin-terser": "^5.3.0",
79
- "rollup-plugin-transform-tagged-template": "^0.0.3",
80
- "rollup-plugin-typescript2": "^0.27.0",
139
+ "rollup-plugin-terser": "^7.0.2",
140
+ "@rollup/plugin-typescript": "^8.3.2",
81
141
  "source-map": "^0.7.3",
82
142
  "source-map-loader": "^0.2.4",
83
143
  "ts-loader": "^7.0.2",
84
144
  "ts-node": "^8.9.1",
85
145
  "tsconfig-paths": "^3.9.0",
86
- "tslib": "^1.11.1",
87
- "typescript": "^4.6.2",
88
- "webpack": "^4.44.0"
146
+ "tslib": "^2.4.0",
147
+ "typescript": "^4.7.0",
148
+ "webpack": "^5.72.0",
149
+ "webpack-cli": "^4.9.2"
89
150
  }
90
151
  }
package/dist/dts/dom.d.ts DELETED
@@ -1,112 +0,0 @@
1
- import type { Callable } from "./interfaces.js";
2
- import { TrustedTypesPolicy } from "./platform.js";
3
- /** @internal */
4
- export declare const _interpolationStart: string;
5
- /** @internal */
6
- export declare const _interpolationEnd: string;
7
- /**
8
- * Common DOM APIs.
9
- * @public
10
- */
11
- export declare const DOM: Readonly<{
12
- /**
13
- * Indicates whether the DOM supports the adoptedStyleSheets feature.
14
- */
15
- supportsAdoptedStyleSheets: boolean;
16
- /**
17
- * Sets the HTML trusted types policy used by the templating engine.
18
- * @param policy - The policy to set for HTML.
19
- * @remarks
20
- * This API can only be called once, for security reasons. It should be
21
- * called by the application developer at the start of their program.
22
- */
23
- setHTMLPolicy(policy: TrustedTypesPolicy): void;
24
- /**
25
- * Turns a string into trusted HTML using the configured trusted types policy.
26
- * @param html - The string to turn into trusted HTML.
27
- * @remarks
28
- * Used internally by the template engine when creating templates
29
- * and setting innerHTML.
30
- */
31
- createHTML(html: string): string;
32
- /**
33
- * Determines if the provided node is a template marker used by the runtime.
34
- * @param node - The node to test.
35
- */
36
- isMarker(node: Node): node is Comment;
37
- /**
38
- * Given a marker node, extract the {@link HTMLDirective} index from the placeholder.
39
- * @param node - The marker node to extract the index from.
40
- */
41
- extractDirectiveIndexFromMarker(node: Comment): number;
42
- /**
43
- * Creates a placeholder string suitable for marking out a location *within*
44
- * an attribute value or HTML content.
45
- * @param index - The directive index to create the placeholder for.
46
- * @remarks
47
- * Used internally by binding directives.
48
- */
49
- createInterpolationPlaceholder(index: number): string;
50
- /**
51
- * Creates a placeholder that manifests itself as an attribute on an
52
- * element.
53
- * @param attributeName - The name of the custom attribute.
54
- * @param index - The directive index to create the placeholder for.
55
- * @remarks
56
- * Used internally by attribute directives such as `ref`, `slotted`, and `children`.
57
- */
58
- createCustomAttributePlaceholder(attributeName: string, index: number): string;
59
- /**
60
- * Creates a placeholder that manifests itself as a marker within the DOM structure.
61
- * @param index - The directive index to create the placeholder for.
62
- * @remarks
63
- * Used internally by structural directives such as `repeat`.
64
- */
65
- createBlockPlaceholder(index: number): string;
66
- /**
67
- * Schedules DOM update work in the next async batch.
68
- * @param callable - The callable function or object to queue.
69
- */
70
- queueUpdate: (callable: Callable) => void;
71
- /**
72
- * Immediately processes all work previously scheduled
73
- * through queueUpdate.
74
- * @remarks
75
- * This also forces nextUpdate promises
76
- * to resolve.
77
- */
78
- processUpdates: () => void;
79
- /**
80
- * Resolves with the next DOM update.
81
- */
82
- nextUpdate(): Promise<void>;
83
- /**
84
- * Sets an attribute value on an element.
85
- * @param element - The element to set the attribute value on.
86
- * @param attributeName - The attribute name to set.
87
- * @param value - The value of the attribute to set.
88
- * @remarks
89
- * If the value is `null` or `undefined`, the attribute is removed, otherwise
90
- * it is set to the provided value using the standard `setAttribute` API.
91
- */
92
- setAttribute(element: HTMLElement, attributeName: string, value: any): void;
93
- /**
94
- * Sets a boolean attribute value.
95
- * @param element - The element to set the boolean attribute value on.
96
- * @param attributeName - The attribute name to set.
97
- * @param value - The value of the attribute to set.
98
- * @remarks
99
- * If the value is true, the attribute is added; otherwise it is removed.
100
- */
101
- setBooleanAttribute(element: HTMLElement, attributeName: string, value: boolean): void;
102
- /**
103
- * Removes all the child nodes of the provided parent node.
104
- * @param parent - The node to remove the children from.
105
- */
106
- removeChildNodes(parent: Node): void;
107
- /**
108
- * Creates a TreeWalker configured to walk a template fragment.
109
- * @param fragment - The fragment to walk.
110
- */
111
- createTemplateWalker(fragment: DocumentFragment): TreeWalker;
112
- }>;
@@ -1,48 +0,0 @@
1
- /**
2
- * Represents a set of splice-based changes against an Array.
3
- * @public
4
- */
5
- export interface Splice {
6
- /**
7
- * The index that the splice occurs at.
8
- */
9
- index: number;
10
- /**
11
- * The items that were removed.
12
- */
13
- removed: any[];
14
- /**
15
- * The number of items that were added.
16
- */
17
- addedCount: number;
18
- }
19
- /** @internal */
20
- export declare function newSplice(index: number, removed: any[], addedCount: number): Splice;
21
- /**
22
- * Splice Projection functions:
23
- *
24
- * A splice map is a representation of how a previous array of items
25
- * was transformed into a new array of items. Conceptually it is a list of
26
- * tuples of
27
- *
28
- * <index, removed, addedCount>
29
- *
30
- * which are kept in ascending index order of. The tuple represents that at
31
- * the |index|, |removed| sequence of items were removed, and counting forward
32
- * from |index|, |addedCount| items were added.
33
- */
34
- /**
35
- * @internal
36
- * @remarks
37
- * Lacking individual splice mutation information, the minimal set of
38
- * splices can be synthesized given the previous state and final state of an
39
- * array. The basic approach is to calculate the edit distance matrix and
40
- * choose the shortest path through it.
41
- *
42
- * Complexity: O(l * p)
43
- * l: The length of the current array
44
- * p: The length of the old array
45
- */
46
- export declare function calcSplices(current: any[], currentStart: number, currentEnd: number, old: any[], oldStart: number, oldEnd: number): ReadonlyArray<never> | Splice[];
47
- /** @internal */
48
- export declare function projectArraySplices(array: any[], changeRecords: any[]): Splice[];
@@ -1,9 +0,0 @@
1
- /**
2
- * Enables the array observation mechanism.
3
- * @remarks
4
- * Array observation is enabled automatically when using the
5
- * {@link RepeatDirective}, so calling this API manually is
6
- * not typically necessary.
7
- * @public
8
- */
9
- export declare function enableArrayObservation(): void;
@@ -1,19 +0,0 @@
1
- import type { ExecutionContext } from "./observable.js";
2
- /**
3
- * Represents and object that can contribute behavior to a view or
4
- * element's bind/unbind operations.
5
- * @public
6
- */
7
- export interface Behavior {
8
- /**
9
- * Bind this behavior to the source.
10
- * @param source - The source to bind to.
11
- * @param context - The execution context that the binding is operating within.
12
- */
13
- bind(source: unknown, context: ExecutionContext): void;
14
- /**
15
- * Unbinds this behavior from the source.
16
- * @param source - The source to unbind from.
17
- */
18
- unbind(source: unknown): void;
19
- }
package/dist/esm/dom.js DELETED
@@ -1,207 +0,0 @@
1
- import { $global } from "./platform.js";
2
- const updateQueue = $global.FAST.getById(1 /* updateQueue */, () => {
3
- const tasks = [];
4
- const pendingErrors = [];
5
- function throwFirstError() {
6
- if (pendingErrors.length) {
7
- throw pendingErrors.shift();
8
- }
9
- }
10
- function tryRunTask(task) {
11
- try {
12
- task.call();
13
- }
14
- catch (error) {
15
- pendingErrors.push(error);
16
- setTimeout(throwFirstError, 0);
17
- }
18
- }
19
- function process() {
20
- const capacity = 1024;
21
- let index = 0;
22
- while (index < tasks.length) {
23
- tryRunTask(tasks[index]);
24
- index++;
25
- // Prevent leaking memory for long chains of recursive calls to `DOM.queueUpdate`.
26
- // If we call `DOM.queueUpdate` within a task scheduled by `DOM.queueUpdate`, the queue will
27
- // grow, but to avoid an O(n) walk for every task we execute, we don't
28
- // shift tasks off the queue after they have been executed.
29
- // Instead, we periodically shift 1024 tasks off the queue.
30
- if (index > capacity) {
31
- // Manually shift all values starting at the index back to the
32
- // beginning of the queue.
33
- for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
34
- tasks[scan] = tasks[scan + index];
35
- }
36
- tasks.length -= index;
37
- index = 0;
38
- }
39
- }
40
- tasks.length = 0;
41
- }
42
- function enqueue(callable) {
43
- if (tasks.length < 1) {
44
- $global.requestAnimationFrame(process);
45
- }
46
- tasks.push(callable);
47
- }
48
- return Object.freeze({
49
- enqueue,
50
- process,
51
- });
52
- });
53
- /* eslint-disable */
54
- const fastHTMLPolicy = $global.trustedTypes.createPolicy("fast-html", {
55
- createHTML: html => html,
56
- });
57
- /* eslint-enable */
58
- let htmlPolicy = fastHTMLPolicy;
59
- const marker = `fast-${Math.random().toString(36).substring(2, 8)}`;
60
- /** @internal */
61
- export const _interpolationStart = `${marker}{`;
62
- /** @internal */
63
- export const _interpolationEnd = `}${marker}`;
64
- /**
65
- * Common DOM APIs.
66
- * @public
67
- */
68
- export const DOM = Object.freeze({
69
- /**
70
- * Indicates whether the DOM supports the adoptedStyleSheets feature.
71
- */
72
- supportsAdoptedStyleSheets: Array.isArray(document.adoptedStyleSheets) &&
73
- "replace" in CSSStyleSheet.prototype,
74
- /**
75
- * Sets the HTML trusted types policy used by the templating engine.
76
- * @param policy - The policy to set for HTML.
77
- * @remarks
78
- * This API can only be called once, for security reasons. It should be
79
- * called by the application developer at the start of their program.
80
- */
81
- setHTMLPolicy(policy) {
82
- if (htmlPolicy !== fastHTMLPolicy) {
83
- throw new Error("The HTML policy can only be set once.");
84
- }
85
- htmlPolicy = policy;
86
- },
87
- /**
88
- * Turns a string into trusted HTML using the configured trusted types policy.
89
- * @param html - The string to turn into trusted HTML.
90
- * @remarks
91
- * Used internally by the template engine when creating templates
92
- * and setting innerHTML.
93
- */
94
- createHTML(html) {
95
- return htmlPolicy.createHTML(html);
96
- },
97
- /**
98
- * Determines if the provided node is a template marker used by the runtime.
99
- * @param node - The node to test.
100
- */
101
- isMarker(node) {
102
- return node && node.nodeType === 8 && node.data.startsWith(marker);
103
- },
104
- /**
105
- * Given a marker node, extract the {@link HTMLDirective} index from the placeholder.
106
- * @param node - The marker node to extract the index from.
107
- */
108
- extractDirectiveIndexFromMarker(node) {
109
- return parseInt(node.data.replace(`${marker}:`, ""));
110
- },
111
- /**
112
- * Creates a placeholder string suitable for marking out a location *within*
113
- * an attribute value or HTML content.
114
- * @param index - The directive index to create the placeholder for.
115
- * @remarks
116
- * Used internally by binding directives.
117
- */
118
- createInterpolationPlaceholder(index) {
119
- return `${_interpolationStart}${index}${_interpolationEnd}`;
120
- },
121
- /**
122
- * Creates a placeholder that manifests itself as an attribute on an
123
- * element.
124
- * @param attributeName - The name of the custom attribute.
125
- * @param index - The directive index to create the placeholder for.
126
- * @remarks
127
- * Used internally by attribute directives such as `ref`, `slotted`, and `children`.
128
- */
129
- createCustomAttributePlaceholder(attributeName, index) {
130
- return `${attributeName}="${this.createInterpolationPlaceholder(index)}"`;
131
- },
132
- /**
133
- * Creates a placeholder that manifests itself as a marker within the DOM structure.
134
- * @param index - The directive index to create the placeholder for.
135
- * @remarks
136
- * Used internally by structural directives such as `repeat`.
137
- */
138
- createBlockPlaceholder(index) {
139
- return `<!--${marker}:${index}-->`;
140
- },
141
- /**
142
- * Schedules DOM update work in the next async batch.
143
- * @param callable - The callable function or object to queue.
144
- */
145
- queueUpdate: updateQueue.enqueue,
146
- /**
147
- * Immediately processes all work previously scheduled
148
- * through queueUpdate.
149
- * @remarks
150
- * This also forces nextUpdate promises
151
- * to resolve.
152
- */
153
- processUpdates: updateQueue.process,
154
- /**
155
- * Resolves with the next DOM update.
156
- */
157
- nextUpdate() {
158
- return new Promise(updateQueue.enqueue);
159
- },
160
- /**
161
- * Sets an attribute value on an element.
162
- * @param element - The element to set the attribute value on.
163
- * @param attributeName - The attribute name to set.
164
- * @param value - The value of the attribute to set.
165
- * @remarks
166
- * If the value is `null` or `undefined`, the attribute is removed, otherwise
167
- * it is set to the provided value using the standard `setAttribute` API.
168
- */
169
- setAttribute(element, attributeName, value) {
170
- if (value === null || value === undefined) {
171
- element.removeAttribute(attributeName);
172
- }
173
- else {
174
- element.setAttribute(attributeName, value);
175
- }
176
- },
177
- /**
178
- * Sets a boolean attribute value.
179
- * @param element - The element to set the boolean attribute value on.
180
- * @param attributeName - The attribute name to set.
181
- * @param value - The value of the attribute to set.
182
- * @remarks
183
- * If the value is true, the attribute is added; otherwise it is removed.
184
- */
185
- setBooleanAttribute(element, attributeName, value) {
186
- value
187
- ? element.setAttribute(attributeName, "")
188
- : element.removeAttribute(attributeName);
189
- },
190
- /**
191
- * Removes all the child nodes of the provided parent node.
192
- * @param parent - The node to remove the children from.
193
- */
194
- removeChildNodes(parent) {
195
- for (let child = parent.firstChild; child !== null; child = parent.firstChild) {
196
- parent.removeChild(child);
197
- }
198
- },
199
- /**
200
- * Creates a TreeWalker configured to walk a template fragment.
201
- * @param fragment - The fragment to walk.
202
- */
203
- createTemplateWalker(fragment) {
204
- return document.createTreeWalker(fragment, 133, // element, text, comment
205
- null, false);
206
- },
207
- });