@arcgis/coding-components 4.31.0-next.150 → 4.31.0-next.151

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 (151) hide show
  1. package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +2 -2
  2. package/dist/arcgis-coding-components/assets/arcade-language/api/test.json +6861 -0
  3. package/dist/arcgis-coding-components/index.esm.js +2 -2
  4. package/dist/arcgis-coding-components/{p-561621f5.js → p-0dc5dd37.js} +2 -2
  5. package/dist/arcgis-coding-components/p-14fc05ed.js +12 -0
  6. package/dist/arcgis-coding-components/{p-bc0eeb83.js → p-14fe0e2e.js} +2 -2
  7. package/dist/arcgis-coding-components/{p-11797558.js → p-1625cb1d.js} +2 -2
  8. package/dist/arcgis-coding-components/{p-e9a56e38.entry.js → p-1a9a03d7.entry.js} +2 -2
  9. package/dist/arcgis-coding-components/p-1e47c6e2.entry.js +6 -0
  10. package/dist/arcgis-coding-components/{p-9bf7cf20.js → p-1f96b801.js} +2 -2
  11. package/dist/arcgis-coding-components/{p-c55494c0.entry.js → p-1f990ec7.entry.js} +2 -2
  12. package/dist/arcgis-coding-components/{p-865517bd.js → p-221e692b.js} +2 -2
  13. package/dist/arcgis-coding-components/{p-965e5a15.js → p-236a3928.js} +10 -10
  14. package/dist/arcgis-coding-components/{p-5a8918f9.js → p-2ba5d9f0.js} +2 -2
  15. package/dist/arcgis-coding-components/{p-fc64abaa.js → p-39feeb1b.js} +2 -2
  16. package/dist/arcgis-coding-components/p-467f5d55.js +6 -0
  17. package/dist/arcgis-coding-components/p-501f5282.js +12 -0
  18. package/dist/arcgis-coding-components/{p-ad53776e.js → p-568a56d0.js} +1 -1
  19. package/dist/arcgis-coding-components/{p-d3c751e9.js → p-57d23245.js} +2 -2
  20. package/dist/arcgis-coding-components/p-5ac97486.js +12 -0
  21. package/dist/arcgis-coding-components/{p-b2d9867f.js → p-5ae75475.js} +2 -2
  22. package/dist/arcgis-coding-components/{p-e8a861e0.entry.js → p-60d5af97.entry.js} +2 -2
  23. package/dist/arcgis-coding-components/{p-bf2114f8.js → p-66b621b9.js} +2 -2
  24. package/dist/arcgis-coding-components/p-6eb1581f.js +6 -0
  25. package/dist/arcgis-coding-components/{p-4343aa45.js → p-721af385.js} +1 -1
  26. package/dist/arcgis-coding-components/p-7b35e793.js +12 -0
  27. package/dist/arcgis-coding-components/{p-e3fb2b88.js → p-7d3fe172.js} +2 -2
  28. package/dist/arcgis-coding-components/{p-6d76a0bc.js → p-7eb67844.js} +1 -1
  29. package/dist/arcgis-coding-components/p-a2afc28f.js +6 -0
  30. package/dist/arcgis-coding-components/p-b249112b.entry.js +6 -0
  31. package/dist/arcgis-coding-components/p-b6d568e3.js +6 -0
  32. package/dist/arcgis-coding-components/p-b98edabb.js +12 -0
  33. package/dist/arcgis-coding-components/p-c2b233d3.js +6 -0
  34. package/dist/arcgis-coding-components/p-d011251d.js +68 -0
  35. package/dist/arcgis-coding-components/p-d6c459ae.js +12 -0
  36. package/dist/arcgis-coding-components/p-dc193848.js +7 -0
  37. package/dist/arcgis-coding-components/p-df6d8f1f.js +12 -0
  38. package/dist/arcgis-coding-components/p-e109dc9e.js +12 -0
  39. package/dist/arcgis-coding-components/p-f7bf9210.entry.js +6 -0
  40. package/dist/cjs/{app-globals-e2e63057.js → app-globals-1dbdc02e.js} +1 -1
  41. package/dist/cjs/app-globals-d2c3d493.js +10 -0
  42. package/dist/cjs/{arcade-defaults-e133ed42.js → arcade-defaults-2d74542a.js} +3 -3
  43. package/dist/cjs/arcade-defaults-bc1e723c.js +289 -0
  44. package/dist/cjs/{arcade-mode-63ee903f.js → arcade-mode-47cd03fd.js} +3 -3
  45. package/dist/cjs/arcade-mode-4ab96441.js +611 -0
  46. package/dist/cjs/arcgis-arcade-editor_6.cjs.entry.js +7 -7
  47. package/dist/cjs/arcgis-coding-components.cjs.js +3 -3
  48. package/dist/cjs/arcgis-sql-expression-editor.cjs.entry.js +4 -4
  49. package/dist/cjs/arcgis-sql-expression-fields.cjs.entry.js +4 -4
  50. package/dist/cjs/{css-3a1e0cfe.js → css-782d416d.js} +1 -1
  51. package/dist/cjs/css-87f18d10.js +193 -0
  52. package/dist/cjs/{cssMode-aa9bd85f.js → cssMode-e68b5f49.js} +3 -3
  53. package/dist/cjs/cssMode-ef23ee4d.js +2043 -0
  54. package/dist/cjs/{html-be088389.js → html-10e5b6ee.js} +3 -3
  55. package/dist/cjs/html-42d46974.js +304 -0
  56. package/dist/cjs/{htmlMode-9359cdfb.js → htmlMode-9d5ce987.js} +3 -3
  57. package/dist/cjs/htmlMode-c3117e13.js +2059 -0
  58. package/dist/cjs/{index-92a13be0.js → index-5403bdc9.js} +1 -1
  59. package/dist/cjs/index-c7d67706.js +1375 -0
  60. package/dist/cjs/index.cjs.js +4 -4
  61. package/dist/cjs/{javascript-a6fa8787.js → javascript-30be26a5.js} +4 -4
  62. package/dist/cjs/javascript-7ef34ce8.js +85 -0
  63. package/dist/cjs/{jsonMode-4c6dc37c.js → jsonMode-0970c143.js} +3 -3
  64. package/dist/cjs/jsonMode-0cc66d93.js +2619 -0
  65. package/dist/cjs/loader.cjs.js +3 -3
  66. package/dist/cjs/{sql-expr-defaults-6a5e950c.js → sql-expr-defaults-260e0b42.js} +10 -10
  67. package/dist/cjs/sql-expr-defaults-9721f89b.js +171151 -0
  68. package/dist/cjs/{sql-expr-mode-302f4228.js → sql-expr-mode-ae585c68.js} +3 -3
  69. package/dist/cjs/sql-expr-mode-c9d0fd9a.js +480 -0
  70. package/dist/cjs/{tsMode-e6211caf.js → tsMode-64ef0571.js} +3 -3
  71. package/dist/cjs/tsMode-e24d0cfa.js +1167 -0
  72. package/dist/cjs/{typescript-b9f05def.js → typescript-724b94a5.js} +3 -3
  73. package/dist/cjs/typescript-7f0fb99d.js +350 -0
  74. package/dist/cjs/{useT9n-40bf7857.js → useT9n-0885f1e4.js} +3 -3
  75. package/dist/cjs/useT9n-fc7a9607.js +1252 -0
  76. package/dist/components/arcade-defaults.js +1 -1
  77. package/dist/components/arcade-mode.js +1 -1
  78. package/dist/components/arcade-results.js +1 -1
  79. package/dist/components/arcade-suggestions.js +1 -1
  80. package/dist/components/arcgis-arcade-editor.js +1 -1
  81. package/dist/components/arcgis-arcade-results.js +1 -1
  82. package/dist/components/arcgis-arcade-suggestions.js +1 -1
  83. package/dist/components/arcgis-assets.d.ts +1 -1
  84. package/dist/components/arcgis-assets.js +1 -1
  85. package/dist/components/arcgis-code-editor.js +1 -1
  86. package/dist/components/arcgis-editor-variables.js +1 -1
  87. package/dist/components/arcgis-language-api-panel.js +1 -1
  88. package/dist/components/arcgis-sql-expression-editor.js +1 -1
  89. package/dist/components/arcgis-sql-expression-fields.js +1 -1
  90. package/dist/components/chunk-UFIZBDFE.js +1 -1
  91. package/dist/components/code-editor.js +1 -1
  92. package/dist/components/editor-variables.js +1 -1
  93. package/dist/components/fields.js +1 -1
  94. package/dist/components/index.js +1 -1
  95. package/dist/components/index2.js +1 -1
  96. package/dist/components/language-api-panel.js +1 -1
  97. package/dist/components/markdown.js +1 -1
  98. package/dist/components/sql-expr-defaults.js +1 -1
  99. package/dist/components/sql-expr-mode.js +1 -1
  100. package/dist/components/useT9n.js +1 -1
  101. package/dist/components/utilities.js +1 -1
  102. package/dist/esm/{app-globals-fdade983.js → app-globals-590e2a77.js} +1 -1
  103. package/dist/esm/app-globals-9eb472df.js +8 -0
  104. package/dist/esm/{arcade-defaults-c931a334.js → arcade-defaults-946a53d0.js} +3 -3
  105. package/dist/esm/arcade-defaults-c30590df.js +286 -0
  106. package/dist/esm/{arcade-mode-2a2720ab.js → arcade-mode-6cffe3c1.js} +3 -3
  107. package/dist/esm/arcade-mode-c33fda0d.js +607 -0
  108. package/dist/esm/arcgis-arcade-editor_6.entry.js +7 -7
  109. package/dist/esm/arcgis-coding-components.js +4 -4
  110. package/dist/esm/arcgis-sql-expression-editor.entry.js +4 -4
  111. package/dist/esm/arcgis-sql-expression-fields.entry.js +4 -4
  112. package/dist/esm/{css-c89bd479.js → css-e12310b7.js} +1 -1
  113. package/dist/esm/css-e7ef6d6c.js +190 -0
  114. package/dist/esm/{cssMode-b0baab26.js → cssMode-453bbfcc.js} +3 -3
  115. package/dist/esm/cssMode-c027d78b.js +2022 -0
  116. package/dist/esm/{html-d0b5e659.js → html-97e099d8.js} +3 -3
  117. package/dist/esm/html-ebaad5de.js +301 -0
  118. package/dist/esm/{htmlMode-523c26fe.js → htmlMode-9e54779c.js} +3 -3
  119. package/dist/esm/htmlMode-e30ea0d0.js +2037 -0
  120. package/dist/esm/{index-b3598a82.js → index-7422efbb.js} +1 -1
  121. package/dist/esm/index-c18b3435.js +1344 -0
  122. package/dist/esm/index.js +4 -4
  123. package/dist/esm/{javascript-b17a245b.js → javascript-32941085.js} +4 -4
  124. package/dist/esm/javascript-51965802.js +82 -0
  125. package/dist/esm/{jsonMode-72ee90a8.js → jsonMode-8cbae8ad.js} +3 -3
  126. package/dist/esm/jsonMode-a15607eb.js +2598 -0
  127. package/dist/esm/loader.js +4 -4
  128. package/dist/esm/{sql-expr-defaults-1429a1dd.js → sql-expr-defaults-6d0018f8.js} +10 -10
  129. package/dist/esm/sql-expr-defaults-d1bc79e7.js +171083 -0
  130. package/dist/esm/{sql-expr-mode-b60c1580.js → sql-expr-mode-005919d5.js} +3 -3
  131. package/dist/esm/sql-expr-mode-ea2622f3.js +476 -0
  132. package/dist/esm/{tsMode-e385e048.js → tsMode-0252de17.js} +3 -3
  133. package/dist/esm/tsMode-4d215cd3.js +1143 -0
  134. package/dist/esm/{typescript-1ce38f98.js → typescript-501c9e02.js} +3 -3
  135. package/dist/esm/typescript-d2cd994b.js +347 -0
  136. package/dist/esm/useT9n-40e08c69.js +1248 -0
  137. package/dist/esm/{useT9n-435fabc7.js → useT9n-8342fb27.js} +3 -3
  138. package/dist/loader/cdn.js +1 -1
  139. package/dist/loader/index.cjs.js +1 -1
  140. package/dist/loader/index.es2017.js +1 -1
  141. package/dist/loader/index.js +1 -1
  142. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/stencil.config.d.ts +3 -0
  143. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/arcade-editor.stories.d.ts +27 -0
  144. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/editorContext.d.ts +15 -0
  145. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/stories/internal/code-editor/code-editor.stories.d.ts +6 -0
  146. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/stories/internal/sql-expression-editor/sql-expression-editor.stories.d.ts +15 -0
  147. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/stories/reference/stories/arcade-editor.stories.d.ts +9 -0
  148. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/support/sass-inline-url-importer.d.ts +9 -0
  149. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/support/sass-json-importer.d.ts +19 -0
  150. package/dist/types/Users/fred/Projects/arcgis-web-components-work/packages/coding-packages/coding-components/.stencil/support/stencil-monaco-plugins.d.ts +6 -0
  151. package/package.json +6 -6
@@ -0,0 +1,1248 @@
1
+ /*!
2
+ * All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
+ * See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
+ * v4.31.0-next.131
5
+ */
6
+ import { F as isNotUndefined, D as Deferred, G as safeAsyncCall, H as devToolsAwareTimeout, J as safeCall, M as startLocaleObserver, N as getElementLocales } from './sql-expr-defaults-6d0018f8.js';
7
+ import { g as getAssetPath } from './index-7422efbb.js';
8
+
9
+ // src/framework.ts
10
+ function retrieveComponentMembers(component, isLit) {
11
+ if (isLit) {
12
+ const elementProperties = component.constructor.elementProperties;
13
+ component.manager.internals.members = Object.fromEntries(
14
+ Array.from(
15
+ elementProperties,
16
+ ([name, descriptor]) => descriptor.noAccessor ? void 0 : [
17
+ name,
18
+ [
19
+ (descriptor.readOnly ? 2048 /* ReadOnly */ : 0) | (descriptor.state ? 32 /* State */ : 16 /* Unknown */)
20
+ ]
21
+ ]
22
+ ).filter(isNotUndefined)
23
+ );
24
+ } else {
25
+ const constructor = component.constructor;
26
+ const members = constructor.__registerControllers?.(component) ?? void 0;
27
+ constructor.__registerControllers = void 0;
28
+ if (typeof members !== "object") {
29
+ throw new Error(
30
+ "Failed to retrieve component meta"
31
+ );
32
+ }
33
+ component.manager.internals.members = Object.fromEntries(
34
+ Object.entries(members).filter(([_name, [propType]]) => (propType & 63 /* PropLike */) !== 0)
35
+ );
36
+ }
37
+ }
38
+ function parsePropertyValue(value, type = 8 /* Any */) {
39
+ const isComplex = value == null || typeof value === "object" || typeof value === "function";
40
+ if (isComplex) {
41
+ return value;
42
+ }
43
+ if ((type & 4 /* Boolean */) !== 0) {
44
+ return value === "false" ? false : value === "" || !!value;
45
+ } else if ((type & 2 /* Number */) !== 0) {
46
+ return Number.parseFloat(value);
47
+ } else if ((type & 1 /* String */) !== 0) {
48
+ return String(value);
49
+ } else {
50
+ return value;
51
+ }
52
+ }
53
+ var getMemberType = (component, name) => component.manager.internals.members?.[name]?.[0];
54
+
55
+ // src/types.ts
56
+ var controllerSymbol = Symbol.for("controller");
57
+
58
+ // src/utils.ts
59
+ var isController = (value) => typeof value === "object" && value !== null && (controllerSymbol in value || "hostConnected" in value || "hostDisconnected" in value || "hostUpdate" in value || "hostUpdated" in value);
60
+
61
+ // src/ControllerInternals.ts
62
+ var ambientComponent;
63
+ function setAmbientComponent(component) {
64
+ if (ambientComponent === component) {
65
+ return;
66
+ }
67
+ ambientComponent = component;
68
+ queueMicrotask(() => {
69
+ if (ambientComponent === component) {
70
+ ambientComponent = void 0;
71
+ }
72
+ });
73
+ }
74
+ function retrieveComponent(name2) {
75
+ return ambientComponent;
76
+ }
77
+ var ambientControllers = [];
78
+ function setParentController(controller) {
79
+ if (controller === void 0) {
80
+ ambientControllers = [];
81
+ return;
82
+ }
83
+ const index = ambientControllers.indexOf(controller);
84
+ ambientControllers = index === -1 ? [...ambientControllers, controller] : ambientControllers.slice(0, index + 1);
85
+ queueMicrotask(() => {
86
+ ambientControllers = [];
87
+ });
88
+ }
89
+ function retrieveParentControllers() {
90
+ return ambientControllers;
91
+ }
92
+ var ambientChildController;
93
+ function setAmbientChildController(controller) {
94
+ if (ambientChildController === controller) {
95
+ return;
96
+ }
97
+ ambientChildController = controller;
98
+ queueMicrotask(() => {
99
+ if (ambientChildController === controller) {
100
+ ambientChildController = void 0;
101
+ }
102
+ });
103
+ }
104
+ function retrieveAmbientChildController() {
105
+ const controller = ambientChildController;
106
+ ambientChildController = void 0;
107
+ return controller;
108
+ }
109
+ var use = async (value, watchExports) => {
110
+ const controller = useRefSync(value);
111
+ if (controller === void 0) {
112
+ return value;
113
+ }
114
+ await controller.ready;
115
+ if (typeof watchExports === "function") {
116
+ const unsubscribe = controller.watchExports(
117
+ (exports) => watchExports(exports, unsubscribe)
118
+ );
119
+ }
120
+ return controller.exports;
121
+ };
122
+ var useRef = async (value) => {
123
+ const controller = useRefSync(value);
124
+ await controller.ready;
125
+ return controller;
126
+ };
127
+ var useRefSync = (value) => {
128
+ const ambientChildController2 = retrieveAmbientChildController();
129
+ if (ambientChildController2 !== void 0) {
130
+ return ambientChildController2;
131
+ }
132
+ const component = retrieveComponent();
133
+ const controller = component.manager.internals.resolveExports(value);
134
+ if (controller !== void 0) {
135
+ return controller;
136
+ }
137
+ if (isController(value)) {
138
+ return value;
139
+ }
140
+ return void 0;
141
+ };
142
+ var shouldBypass = {
143
+ setter: false,
144
+ getter: false,
145
+ readOnly: false
146
+ };
147
+ var elementToInstance = /* @__PURE__ */ new WeakMap();
148
+ var _a;
149
+ _a = controllerSymbol;
150
+ var Controller = class {
151
+ constructor(component) {
152
+ this._callbacks = {
153
+ hostConnected: [],
154
+ hostDisconnected: [],
155
+ hostLoad: [],
156
+ hostLoaded: [],
157
+ hostUpdate: [],
158
+ hostUpdated: [],
159
+ hostDestroy: [],
160
+ hostLifecycle: []
161
+ };
162
+ this._ready = new Deferred();
163
+ this._lifecycleCleanups = [];
164
+ this.connectedCalled = false;
165
+ this._loadCalled = false;
166
+ this.loadedCalled = false;
167
+ this[_a] = true;
168
+ this.ready = this._ready.promise;
169
+ /*
170
+ * Setting default exports to "this" so that controllers that don't use
171
+ * exports/proxyExports(), could still be used as if they did
172
+ * (i.e with controller.use)
173
+ */
174
+ this._exports = makeProvisionalValue(this);
175
+ this._exportWatchers = /* @__PURE__ */ new Set();
176
+ const resolvedComponent = toControllerHost(component ?? retrieveComponent());
177
+ {
178
+ this.component = resolvedComponent;
179
+ }
180
+ this.component.addController(this);
181
+ setParentController(this);
182
+ const manager = this.component.manager;
183
+ const isInControllerManager = manager === void 0;
184
+ if (!isInControllerManager) {
185
+ queueMicrotask(() => this.catchUpLifecycle());
186
+ }
187
+ }
188
+ /**
189
+ * If controller is being added dynamically, after the component
190
+ * construction, then trigger connected and load right away
191
+ */
192
+ catchUpLifecycle() {
193
+ const { manager } = this.component;
194
+ const connectedWillStillHappen = !manager.connectedCalled;
195
+ if (!connectedWillStillHappen && !this.connectedCalled) {
196
+ this.triggerConnected();
197
+ }
198
+ const loadWillStillHappen = !manager._loadCalled;
199
+ if (loadWillStillHappen) {
200
+ return;
201
+ }
202
+ this.triggerLoad().then(() => {
203
+ const loadedWillStillHappen = !manager.loadedCalled;
204
+ if (loadedWillStillHappen) {
205
+ return;
206
+ }
207
+ this.triggerLoaded();
208
+ }).catch(console.error);
209
+ }
210
+ get exports() {
211
+ return this._exports;
212
+ }
213
+ /**
214
+ * Set controller's exports property (for usage with proxyExports()) and mark
215
+ * controller as ready (for usage in other controllers). Also, triggers
216
+ * re-render of the component
217
+ */
218
+ set exports(exports) {
219
+ const oldExports = this._exports;
220
+ if (oldExports !== exports) {
221
+ this._exports = exports;
222
+ this._exportWatchers.forEach(safeCall);
223
+ if (this.connectedCalled && this.assignedProperty !== false) {
224
+ this.component.requestUpdate(this.assignedProperty, oldExports);
225
+ }
226
+ }
227
+ this._ready.resolve(exports);
228
+ }
229
+ setProvisionalExports(exports) {
230
+ this._exports = makeProvisionalValue(exports);
231
+ this._exportWatchers.forEach(safeCall);
232
+ }
233
+ watchExports(callback) {
234
+ const safeCallback = () => callback(this._exports);
235
+ this._exportWatchers.add(safeCallback);
236
+ return () => void this._exportWatchers.delete(safeCallback);
237
+ }
238
+ /**
239
+ * A flexible utility for making sure a controller is loaded before it's used,
240
+ * regardless of how or where a controller was defined:
241
+ *
242
+ * @example
243
+ * makeGenericController(async (component, controller) => {
244
+ * // Await some controller from the component:
245
+ * await controller.use(component.someController);
246
+ * // Initialize new controllers
247
+ * await controller.use(load(importCoreReactiveUtils));
248
+ * await controller.use(new ViewModelController(component,newWidgetsHomeHomeViewModel));
249
+ * await controller.use(someController(component));
250
+ * });
251
+ *
252
+ * @remarks
253
+ * If your controller is not async, and you are not creating it async, then
254
+ * you are not required to use controller.use - you can use it directly.
255
+ * Similarly, accessing controllers after componentWillLoad callback does not
256
+ * require awaiting them as they are guaranteed to be loaded by then.
257
+ */
258
+ get use() {
259
+ setAmbientComponent(this.component);
260
+ return use;
261
+ }
262
+ /**
263
+ * Just like controller.use, but returns the controller itself, rather than it's
264
+ * exports
265
+ *
266
+ * Use cases:
267
+ * - You have a controller and you want to make sure it's loaded before you
268
+ * try to use it
269
+ * - Your controller is not using exports, so you wish to access some props on
270
+ * it directly
271
+ * - You have a controller exports only, and you want to retrieve the
272
+ * controller itself. This is useful if you wish to call .watchExports() or
273
+ * some other method on the controller
274
+ */
275
+ get useRef() {
276
+ setAmbientComponent(this.component);
277
+ return useRef;
278
+ }
279
+ /**
280
+ * Like useRef, but doesn't wait for the controller to get ready
281
+ *
282
+ * @internal
283
+ */
284
+ get useRefSync() {
285
+ setAmbientComponent(this.component);
286
+ return useRefSync;
287
+ }
288
+ controllerRemoved() {
289
+ if (this.component.el.isConnected) {
290
+ this.triggerDisconnected();
291
+ }
292
+ this.triggerDestroy();
293
+ }
294
+ // Register a lifecycle callback
295
+ onConnected(callback) {
296
+ this._callbacks.hostConnected.push(callback);
297
+ }
298
+ onDisconnected(callback) {
299
+ this._callbacks.hostDisconnected.push(callback);
300
+ }
301
+ onLoad(callback) {
302
+ this._callbacks.hostLoad.push(callback);
303
+ }
304
+ onLoaded(callback) {
305
+ this._callbacks.hostLoaded.push(callback);
306
+ }
307
+ onUpdate(callback) {
308
+ this._callbacks.hostUpdate.push(callback);
309
+ }
310
+ onUpdated(callback) {
311
+ this._callbacks.hostUpdated.push(callback);
312
+ }
313
+ onDestroy(callback) {
314
+ this._callbacks.hostDestroy.push(callback);
315
+ }
316
+ onLifecycle(callback) {
317
+ this._callbacks.hostLifecycle.push(callback);
318
+ if (this.connectedCalled && this.component.el.isConnected) {
319
+ this._callLifecycle(callback);
320
+ }
321
+ }
322
+ // Call each lifecycle hook
323
+ /** @internal */
324
+ triggerConnected() {
325
+ const genericController = this;
326
+ if (genericController.hostConnected) {
327
+ safeCall(genericController.hostConnected, genericController);
328
+ }
329
+ this._callbacks.hostConnected.forEach(safeCall);
330
+ this.triggerLifecycle();
331
+ this.connectedCalled = true;
332
+ }
333
+ /** @internal */
334
+ triggerDisconnected() {
335
+ const genericController = this;
336
+ if (genericController.hostDisconnected) {
337
+ safeCall(genericController.hostDisconnected, genericController);
338
+ }
339
+ this._callbacks.hostDisconnected.forEach(safeCall);
340
+ this._lifecycleCleanups.forEach(safeCall);
341
+ this._lifecycleCleanups = [];
342
+ }
343
+ /** @internal */
344
+ async triggerLoad() {
345
+ if (this._loadCalled) {
346
+ return;
347
+ }
348
+ this._loadCalled = true;
349
+ const genericController = this;
350
+ if (genericController.hostLoad) {
351
+ await safeAsyncCall(genericController.hostLoad, genericController);
352
+ }
353
+ if (this._callbacks.hostLoad.length > 0) {
354
+ await Promise.allSettled(this._callbacks.hostLoad.map(safeAsyncCall));
355
+ }
356
+ this._ready.resolve(this._exports);
357
+ }
358
+ /** @internal */
359
+ triggerLoaded() {
360
+ if (this.loadedCalled) {
361
+ return;
362
+ }
363
+ const genericController = this;
364
+ if (genericController.hostLoaded) {
365
+ safeCall(genericController.hostLoaded, genericController);
366
+ }
367
+ this._callbacks.hostLoaded.forEach(safeCall);
368
+ this.loadedCalled = true;
369
+ }
370
+ /** @internal */
371
+ triggerUpdate(changedProperties) {
372
+ const genericController = this;
373
+ if (genericController.hostUpdate) {
374
+ safeCall(genericController.hostUpdate, genericController, changedProperties);
375
+ }
376
+ this._callbacks.hostUpdate.forEach(callUpdate, changedProperties);
377
+ }
378
+ /** @internal */
379
+ triggerUpdated(changedProperties) {
380
+ const genericController = this;
381
+ if (genericController.hostUpdated) {
382
+ safeCall(genericController.hostUpdated, genericController, changedProperties);
383
+ }
384
+ this._callbacks.hostUpdated.forEach(callUpdate, changedProperties);
385
+ }
386
+ /** @internal */
387
+ triggerDestroy() {
388
+ const genericController = this;
389
+ if (genericController.hostDestroy) {
390
+ safeCall(genericController.hostDestroy, genericController);
391
+ }
392
+ this._callbacks.hostDestroy.forEach(safeCall);
393
+ }
394
+ /** @internal */
395
+ triggerLifecycle() {
396
+ const genericController = this;
397
+ if (genericController.hostLifecycle) {
398
+ this._callLifecycle(() => genericController.hostLifecycle());
399
+ }
400
+ this._callbacks.hostLifecycle.forEach(this._callLifecycle, this);
401
+ }
402
+ _callLifecycle(callback) {
403
+ setAmbientComponent(this.component);
404
+ const cleanupRaw = safeCall(callback);
405
+ const cleanup = Array.isArray(cleanupRaw) ? cleanupRaw : [cleanupRaw];
406
+ cleanup.forEach((cleanup2) => {
407
+ if (typeof cleanup2 === "function") {
408
+ this._lifecycleCleanups.push(cleanup2);
409
+ } else if (typeof cleanup2 === "object" && typeof cleanup2.remove === "function") {
410
+ this._lifecycleCleanups.push(cleanup2.remove);
411
+ }
412
+ });
413
+ }
414
+ };
415
+ function callUpdate(callback) {
416
+ safeCall(callback, void 0, this);
417
+ }
418
+ var GenericController = Controller;
419
+ function makeProvisionalValue(base) {
420
+ if (typeof base !== "object" && typeof base !== "function" || base === null) {
421
+ return base;
422
+ }
423
+ const proxy = new Proxy(base, {
424
+ get(target, prop, receiver) {
425
+ if (cyclical.has(prop) && prop in target && target[prop] === proxy) {
426
+ return void 0;
427
+ }
428
+ if (prop in target || prop in Promise.prototype || typeof prop === "symbol") {
429
+ return typeof target === "function" ? target[prop] : Reflect.get(target, prop, receiver);
430
+ }
431
+ return void 0;
432
+ },
433
+ set: (target, prop, newValue, receiver) => {
434
+ return Reflect.set(target, prop, newValue, receiver);
435
+ }
436
+ });
437
+ return proxy;
438
+ }
439
+ var cyclical = /* @__PURE__ */ new Set(["exports", "_exports"]);
440
+ function toControllerHost(component) {
441
+ {
442
+ return component;
443
+ }
444
+ }
445
+ function trackPropertyKey(object, onResolved, defaultValue) {
446
+ const keys = Object.keys(object);
447
+ const keyCount = keys.length;
448
+ if (keyTrackMap === void 0) {
449
+ queueMicrotask(keyTrackResolve);
450
+ }
451
+ keyTrackMap ?? (keyTrackMap = /* @__PURE__ */ new Map());
452
+ let pendingTrackers = keyTrackMap.get(object);
453
+ if (pendingTrackers === void 0) {
454
+ pendingTrackers = { callbacks: [], keyCount };
455
+ keyTrackMap.set(object, pendingTrackers);
456
+ }
457
+ if (pendingTrackers.keyCount !== keyCount) {
458
+ pendingTrackers.callbacks.forEach((resolve) => resolve(keys));
459
+ pendingTrackers.callbacks = [];
460
+ pendingTrackers.keyCount = keyCount;
461
+ }
462
+ pendingTrackers.callbacks.push((keys2) => {
463
+ const callback = (key2) => safeCall(onResolved, null, key2);
464
+ const key = keys2[keyCount];
465
+ if (key === void 0) {
466
+ callback(void 0);
467
+ } else if (object[key] === defaultValue) {
468
+ callback(key);
469
+ } else {
470
+ callback(void 0);
471
+ }
472
+ });
473
+ return defaultValue;
474
+ }
475
+ var keyTrackMap = void 0;
476
+ function keyTrackResolve() {
477
+ Array.from(keyTrackMap?.entries() ?? []).forEach(([object, { callbacks }]) => {
478
+ const keys = Object.keys(object);
479
+ callbacks.forEach((commit) => commit(keys));
480
+ });
481
+ keyTrackMap = void 0;
482
+ }
483
+ function watch(component, property, callback) {
484
+ var _a2;
485
+ const genericProperty = property;
486
+ const internals = component.manager.internals;
487
+ (_a2 = internals.allWatchers)[genericProperty] ?? (_a2[genericProperty] = []);
488
+ const watchers = internals.allWatchers[genericProperty];
489
+ const genericCallback = callback;
490
+ const safeCallback = (newValue, oldValue, propertyName) => safeCall(genericCallback, null, newValue, oldValue, propertyName);
491
+ watchers.push(safeCallback);
492
+ return () => {
493
+ const index = watchers.indexOf(safeCallback);
494
+ if (index !== -1) {
495
+ watchers.splice(index, 1);
496
+ }
497
+ };
498
+ }
499
+
500
+ // src/ComponentInternals.ts
501
+ var ComponentInternals = class {
502
+ constructor(component) {
503
+ /**
504
+ * When watchers are set, they are set into `allWatchers`. When watchers are
505
+ * read in the setter, they are read from `enabledWatchers`.
506
+ *
507
+ * In Stencil, on connectedCallback(), controller manager does
508
+ * `enabledWatchers=allWatchers`. Reasoning:
509
+ * - This disables watchers until connected callback (matches behavior of
510
+ * Stencil's watchers)
511
+ * - This removes the need for a check in the setter for whether the watchers
512
+ * were enabled already or not (as getters/setters are hot path, and should
513
+ * be streamlined)
514
+ *
515
+ * In Lit, we set enabledWatchers to allWatchers in the constructor.
516
+ * Reasoning:
517
+ * - While in Stencil all user provided properties are either set before the
518
+ * component constructor (this is possible since Stencil's props store is
519
+ * externalized) or after connectedCallback, in Lit the properties may be
520
+ * set by attributeChangedCallback before connectedCallback. Thus, we need
521
+ * to enable watchers even before connectedCallback.
522
+ * - This means, that a watcher set for some prop before your component got
523
+ * a chance to set the default value will trigger the watcher when the
524
+ * default value is set - but, that is inline with Lit's willUpdate behavior
525
+ * of triggering for default values AND, the only way to set a watcher
526
+ * before default value is if you called watcher inside a controller. For
527
+ * now, there are no controllers written outside of arcgis-map-components
528
+ * package, so I was able to verify that this change would have no
529
+ * negative impact.
530
+ *
531
+ * In either way, I plan to remove watchers from controllers once Stencil
532
+ * support is removed.
533
+ */
534
+ this.enabledWatchers = {};
535
+ this.allWatchers = {};
536
+ /**
537
+ * "readOnly" is not enabled initially since we need to allow to set property
538
+ * default values in the constructor.
539
+ * For Stencil, readonly is enabled by the `readonly()` controller.
540
+ * For Lit, we have the following logic:
541
+ */
542
+ this.enableReadonly = () => {
543
+ this.enableReadonly = void 0;
544
+ if (!this.component.manager.isLit) {
545
+ return;
546
+ }
547
+ const internals = this.component.manager.internals;
548
+ Object.entries(internals.members).forEach(([name2, [type]]) => {
549
+ var _a2;
550
+ const isReadOnly = type & 2048 /* ReadOnly */;
551
+ if (isReadOnly) {
552
+ (_a2 = internals.setters)[name2] ?? (_a2[name2] = []);
553
+ internals.setters[name2].push(internals.readonlySetter);
554
+ }
555
+ });
556
+ };
557
+ this.trackedValue = nothing;
558
+ this.keyTrackers = [];
559
+ this.getters = {};
560
+ this.setters = {};
561
+ this.accessorGetter = {};
562
+ this.accessorSetter = {};
563
+ this.reactiveUtilsIntegrations = /* @__PURE__ */ new Set();
564
+ this._exports = /* @__PURE__ */ new WeakMap();
565
+ this.readonlySetter = (newValue, _oldValue, property) => {
566
+ if (shouldBypass.readOnly) {
567
+ return newValue;
568
+ }
569
+ throw new Error(
570
+ `Cannot assign to read-only property "${property}" of ${this.component.el.tagName.toLowerCase()}. Trying to assign "${String(
571
+ newValue
572
+ )}"`
573
+ );
574
+ };
575
+ {
576
+ this.component = component;
577
+ }
578
+ }
579
+ firePropTrackers(key, value) {
580
+ const trackers = this.keyTrackers;
581
+ this.trackedValue = nothing;
582
+ this.keyTrackers = [];
583
+ trackers.forEach((tracker) => tracker(key, value));
584
+ }
585
+ // REFACTOR: once Stencil is no longer supported, simplify this with Lit's getPropertyDescriptor(), or https://github.com/shoelace-style/shoelace/issues/1990
586
+ /**
587
+ * Configure a getter or setter for a given \@Prop/\@State
588
+ *
589
+ * Since props are defined on the prototype, they are shared between all
590
+ * instances of a component. Thus, instead of passing a reference to the
591
+ * getter/setter function, you should update the
592
+ * ComponentInternals.getters/setters properties, and then call getSetProxy
593
+ * to apply the changes to the prototype
594
+ */
595
+ getSetProxy(property) {
596
+ const component = this.component;
597
+ const classPrototype = component.constructor.prototype;
598
+ this._getSetProxy(classPrototype, property, "class");
599
+ if (component.manager.isLit) {
600
+ return;
601
+ }
602
+ const htmlPrototype = component.el.constructor.prototype;
603
+ if (classPrototype !== htmlPrototype) {
604
+ this._getSetProxy(htmlPrototype, property, "html");
605
+ }
606
+ }
607
+ _getSetProxy(prototype, name2, type) {
608
+ const component = this.component;
609
+ const propType = getMemberType(component, name2);
610
+ let descriptor;
611
+ do {
612
+ descriptor = Object.getOwnPropertyDescriptor(prototype, name2);
613
+ } while (!descriptor && (prototype = Object.getPrototypeOf(prototype)));
614
+ if (!descriptor) {
615
+ return void 0;
616
+ }
617
+ const originalGet = descriptor.get;
618
+ const originalSet = descriptor.set;
619
+ const isGetterAlreadyOverwritten = customAccessor in originalGet;
620
+ const isSetterAlreadyOverwritten = customAccessor in originalSet;
621
+ if (isGetterAlreadyOverwritten && isSetterAlreadyOverwritten) {
622
+ return;
623
+ }
624
+ const shouldOverwriteGet = !isGetterAlreadyOverwritten;
625
+ const shouldOverwriteSet = !isSetterAlreadyOverwritten;
626
+ const finalGetter = shouldOverwriteGet ? function getter() {
627
+ let value = originalGet.call(this);
628
+ const component2 = elementToInstance.get(this);
629
+ if (component2 === void 0) {
630
+ return value;
631
+ }
632
+ const internals = component2.manager.internals;
633
+ value = internals.accessorGetter[name2](value, name2);
634
+ const getters = internals.getters[name2] ?? emptyArray;
635
+ for (let i = 0; i < getters.length; i++) {
636
+ value = getters[i](value, name2);
637
+ }
638
+ return value;
639
+ } : originalGet;
640
+ const finalSetter = shouldOverwriteSet ? function setter(rawNewValue) {
641
+ const oldValue = originalGet.call(this);
642
+ const component2 = elementToInstance.get(this);
643
+ if (component2 === void 0) {
644
+ originalSet.call(this, rawNewValue);
645
+ return;
646
+ }
647
+ let newValue = component2.manager.isLit ? (
648
+ /*
649
+ * Cast `null` to `undefined`.
650
+ * See https://devtopia.esri.com/WebGIS/arcgis-web-components/discussions/1299
651
+ */
652
+ rawNewValue ?? void 0
653
+ ) : parsePropertyValue(rawNewValue, propType);
654
+ const internals = component2.manager.internals;
655
+ if (newValue === oldValue) {
656
+ originalSet.call(this, newValue);
657
+ } else {
658
+ const setters = shouldBypass.setter ? emptyArray : internals.setters[name2] ?? emptyArray;
659
+ for (let i = 0; i < setters.length; i++) {
660
+ newValue = setters[i](newValue, oldValue, name2);
661
+ if (newValue === oldValue) {
662
+ break;
663
+ }
664
+ }
665
+ newValue = internals.accessorSetter[name2](newValue, oldValue, name2);
666
+ originalSet.call(this, newValue);
667
+ if (newValue !== oldValue) {
668
+ internals.enabledWatchers[name2]?.forEach((watcher) => watcher(newValue, oldValue, name2));
669
+ }
670
+ }
671
+ if (internals.keyTrackers.length > 0) {
672
+ internals?.firePropTrackers(name2, rawNewValue);
673
+ }
674
+ } : originalSet;
675
+ if (shouldOverwriteGet) {
676
+ finalGetter[customAccessor] = true;
677
+ }
678
+ if (shouldOverwriteSet) {
679
+ finalSetter[customAccessor] = true;
680
+ }
681
+ Object.defineProperty(prototype, name2, {
682
+ ...descriptor,
683
+ get: finalGetter,
684
+ set: finalSetter
685
+ });
686
+ }
687
+ /**
688
+ * Associate an exports object with a controller for reverse lookup in
689
+ * controller.use
690
+ */
691
+ markExports(controller, exports) {
692
+ if (typeof exports === "object" && exports !== null || typeof exports === "function") {
693
+ this._exports.set(exports, controller);
694
+ }
695
+ }
696
+ resolveExports(exports) {
697
+ if (typeof exports === "object" && exports !== null || typeof exports === "function") {
698
+ return this._exports.get(exports);
699
+ } else {
700
+ return void 0;
701
+ }
702
+ }
703
+ };
704
+ var emptyArray = [];
705
+ var customAccessor = Symbol();
706
+ var nothing = Symbol() ;
707
+ var useControllerManager = (component, forceUpdate) => new ControllerManager(component, forceUpdate);
708
+ var ControllerManager = class extends GenericController {
709
+ constructor(component, forceUpdate) {
710
+ const isLit = "addController" in component;
711
+ const controllers = /* @__PURE__ */ new Set();
712
+ function addController(controller) {
713
+ controllers.add(controller);
714
+ if (!(controllerSymbol in controller) && component.renderRoot && component.el.isConnected) {
715
+ controller.hostConnected?.();
716
+ }
717
+ }
718
+ function removeController(controller) {
719
+ void controllers.delete(controller);
720
+ controller.controllerRemoved?.();
721
+ }
722
+ const controllerHost = component;
723
+ controllerHost.addController = addController;
724
+ controllerHost.removeController = removeController;
725
+ if (!isLit) {
726
+ const update = forceUpdate ?? component.constructor.__forceUpdate;
727
+ controllerHost.requestUpdate = () => update(component);
728
+ }
729
+ super(component);
730
+ /** @internal */
731
+ this.internals = new ComponentInternals(this.component);
732
+ this.destroyed = false;
733
+ this._updatePromise = new Deferred();
734
+ this._originalLifecycles = {};
735
+ this.isLit = isLit;
736
+ this.component.manager = this;
737
+ retrieveComponentMembers(component, isLit);
738
+ this._controllers = controllers;
739
+ this.exports = void 0;
740
+ this.hasDestroy = autoDestroyDisabledPropName in this.component && typeof this.component.destroy === "function";
741
+ this._bindLifecycleMethods();
742
+ const internals = this.internals;
743
+ Object.keys(internals.members).forEach((name2) => {
744
+ internals.accessorGetter[name2] = defaultGetterSetter;
745
+ internals.accessorSetter[name2] = defaultGetterSetter;
746
+ internals.getSetProxy(name2);
747
+ });
748
+ if (isLit) {
749
+ this.internals.enabledWatchers = this.internals.allWatchers;
750
+ } else {
751
+ Object.defineProperty(component, "updateComplete", {
752
+ get: async () => await this._updatePromise.promise
753
+ });
754
+ }
755
+ queueMicrotask(internals.enableReadonly);
756
+ setParentController(void 0);
757
+ setAmbientComponent(component);
758
+ elementToInstance.set(component.el, component);
759
+ elementToInstance.set(component, component);
760
+ }
761
+ _bindLifecycleMethods() {
762
+ const component = this.component;
763
+ const isLit = this.isLit;
764
+ const isStencilDistBuild = component.el === component;
765
+ this._originalLifecycles = {
766
+ // These component's callbacks will be called by Lit, so we don't have to
767
+ _connectedCallback: isLit || isStencilDistBuild ? void 0 : component.connectedCallback,
768
+ _disconnectedCallback: isLit || isStencilDistBuild ? void 0 : component.disconnectedCallback,
769
+ _load: isLit ? component.load : component.componentWillLoad,
770
+ _loaded: isLit ? component.loaded : component.componentDidLoad,
771
+ _willUpdate: isLit ? void 0 : component.componentWillUpdate,
772
+ _updated: isLit ? void 0 : component.componentDidUpdate,
773
+ _destroy: component.destroy
774
+ };
775
+ const hostConnected = this._connectedCallback.bind(this);
776
+ const hostDisconnected = this._disconnectedCallback.bind(this);
777
+ const hostUpdate = this._update.bind(this);
778
+ const hostUpdated = this._updated.bind(this);
779
+ if (isLit) {
780
+ component.constructor.prototype.addController.call(component, {
781
+ // Lit will call these callbacks
782
+ hostConnected,
783
+ hostDisconnected,
784
+ hostUpdate,
785
+ hostUpdated
786
+ });
787
+ } else {
788
+ component.connectedCallback = hostConnected;
789
+ component.disconnectedCallback = hostDisconnected;
790
+ component.componentWillLoad = this._load.bind(this);
791
+ component.componentDidLoad = this._loaded.bind(this);
792
+ component.componentWillUpdate = hostUpdate;
793
+ component.componentDidUpdate = hostUpdated;
794
+ }
795
+ if (this.hasDestroy) {
796
+ component.destroy = this.destroy.bind(this);
797
+ }
798
+ }
799
+ /**
800
+ * Private because this is not supposed to be called by Component directly.
801
+ * Instead, _bindLifecycleMethods will take care of that. Otherwise, you risk
802
+ * calling lifecycle methods twice.
803
+ *
804
+ * @internal
805
+ */
806
+ _connectedCallback() {
807
+ if (this.destroyed) {
808
+ const tagName = this.component.el.tagName.toLowerCase();
809
+ this.component.el.remove();
810
+ throw new Error(
811
+ `The ${tagName} component has already been destroyed. It cannot be used again. If you meant to disconnect and reconnect a component without automatic destroy, set the ${autoDestroyDisabledPropName} prop.`
812
+ );
813
+ }
814
+ if (this._autoDestroyTimeout !== void 0) {
815
+ clearTimeout(this._autoDestroyTimeout);
816
+ }
817
+ const internals = this.internals;
818
+ internals.enabledWatchers = internals.allWatchers;
819
+ keyTrackResolve();
820
+ internals.enableReadonly?.();
821
+ this._controllers.forEach(callConnected);
822
+ this._originalLifecycles._connectedCallback?.call(this.component);
823
+ }
824
+ /** @internal */
825
+ _disconnectedCallback() {
826
+ if (this.destroyed) {
827
+ return;
828
+ }
829
+ this._controllers.forEach(callDisconnected);
830
+ this._originalLifecycles._disconnectedCallback?.call(this.component);
831
+ if (this.hasDestroy) {
832
+ this._setAutoDestroyTimeout();
833
+ }
834
+ }
835
+ /** @internal */
836
+ async _load() {
837
+ const integrations = this.internals.reactiveUtilsIntegrations;
838
+ if (integrations.size > 0) {
839
+ for (const controller of integrations) {
840
+ if ("triggerLoad" in controller) {
841
+ await controller.triggerLoad();
842
+ } else {
843
+ await safeAsyncCall(controller.hostLoad, controller);
844
+ }
845
+ }
846
+ }
847
+ await Promise.allSettled(Array.from(this._controllers, callLoad, integrations));
848
+ await this._originalLifecycles._load?.call(this.component);
849
+ if (this.hasDestroy) {
850
+ watch(this.component, autoDestroyDisabledPropName, () => this._setAutoDestroyTimeout());
851
+ }
852
+ }
853
+ /** @internal */
854
+ _loaded() {
855
+ this._controllers.forEach(callLoaded);
856
+ this._originalLifecycles._loaded?.call(this.component);
857
+ }
858
+ _update() {
859
+ const maybeLitComponent = this.component;
860
+ this._controllers.forEach(callUpdate2, maybeLitComponent.$changes);
861
+ this._originalLifecycles._willUpdate?.call(this.component);
862
+ }
863
+ _updated() {
864
+ const maybeLitComponent = this.component;
865
+ this._controllers.forEach(callUpdated, maybeLitComponent.$changes);
866
+ this._originalLifecycles._updated?.call(this.component);
867
+ if (this.isLit) {
868
+ maybeLitComponent.$changes = /* @__PURE__ */ new Map();
869
+ } else {
870
+ const updatePromise = this._updatePromise;
871
+ this._updatePromise = new Deferred();
872
+ updatePromise.resolve(true);
873
+ }
874
+ }
875
+ async destroy() {
876
+ if (this.destroyed) {
877
+ return;
878
+ }
879
+ if (this.component.el.isConnected) {
880
+ this.hasDestroy = false;
881
+ try {
882
+ this.component.el.remove();
883
+ } finally {
884
+ this.hasDestroy = true;
885
+ }
886
+ }
887
+ this._autoDestroyTimeout = void 0;
888
+ this.destroyed = true;
889
+ this._controllers.forEach(callDestroy);
890
+ this._controllers.clear();
891
+ await this._originalLifecycles._destroy?.call(this.component);
892
+ }
893
+ _setAutoDestroyTimeout() {
894
+ if (this._autoDestroyTimeout !== void 0) {
895
+ clearTimeout(this._autoDestroyTimeout);
896
+ }
897
+ if (!this.component.el.isConnected && !this.component.autoDestroyDisabled) {
898
+ const destroy = () => void this.destroy().catch(console.error);
899
+ {
900
+ this._autoDestroyTimeout = devToolsAwareTimeout(destroy, autoDestroyOnDisconnectTimeout);
901
+ }
902
+ }
903
+ }
904
+ };
905
+ var autoDestroyDisabledPropName = "autoDestroyDisabled";
906
+ var autoDestroyOnDisconnectTimeout = 1e3;
907
+ var defaultGetterSetter = (value) => value;
908
+ function callConnected(controller) {
909
+ if ("triggerConnected" in controller) {
910
+ controller.triggerConnected();
911
+ } else {
912
+ safeCall(controller.hostConnected, controller);
913
+ }
914
+ }
915
+ function callDisconnected(controller) {
916
+ if ("triggerDisconnected" in controller) {
917
+ controller.triggerDisconnected();
918
+ } else {
919
+ safeCall(controller.hostDisconnected, controller);
920
+ }
921
+ }
922
+ async function callLoad(controller) {
923
+ if (!this.has(controller)) {
924
+ if ("triggerLoad" in controller) {
925
+ await controller.triggerLoad();
926
+ } else {
927
+ await safeAsyncCall(controller.hostLoad, controller);
928
+ }
929
+ }
930
+ }
931
+ function callLoaded(controller) {
932
+ if ("triggerLoaded" in controller) {
933
+ controller.triggerLoaded();
934
+ } else {
935
+ safeCall(controller.hostLoaded, controller);
936
+ }
937
+ }
938
+ function callUpdate2(controller) {
939
+ if ("triggerUpdate" in controller) {
940
+ controller.triggerUpdate(this);
941
+ } else {
942
+ safeCall(controller.hostUpdate, controller, this);
943
+ }
944
+ }
945
+ function callUpdated(controller) {
946
+ if ("triggerUpdated" in controller) {
947
+ controller.triggerUpdated(this);
948
+ } else {
949
+ safeCall(controller.hostUpdated, controller, this);
950
+ }
951
+ }
952
+ function callDestroy(controller) {
953
+ if ("triggerDestroy" in controller) {
954
+ controller.triggerDestroy();
955
+ } else {
956
+ safeCall(controller.hostDestroy, controller);
957
+ }
958
+ }
959
+ function trackPropKey(component, onResolved, defaultValue) {
960
+ const internals = component.manager.internals;
961
+ if (internals.trackedValue !== nothing && internals.trackedValue !== defaultValue) {
962
+ internals.firePropTrackers(void 0, void 0);
963
+ }
964
+ if (internals.keyTrackers.length === 0) {
965
+ queueMicrotask(() => internals.firePropTrackers(void 0, void 0));
966
+ }
967
+ internals.trackedValue = defaultValue;
968
+ internals.keyTrackers.push((key, value) => safeCall(onResolved, void 0, defaultValue === value ? key : void 0));
969
+ return defaultValue;
970
+ }
971
+
972
+ // src/trackKey.ts
973
+ function trackKey(hostsCandidates, onResolved, defaultValue) {
974
+ const candidateHosts = Array.isArray(hostsCandidates) ? hostsCandidates : [hostsCandidates];
975
+ let leftToResolve = candidateHosts.length + 1;
976
+ const resolved = (resolution) => {
977
+ leftToResolve -= 1;
978
+ if (resolution !== void 0) {
979
+ leftToResolve = Math.min(leftToResolve, 0);
980
+ }
981
+ if (leftToResolve === 0) {
982
+ onResolved(resolution);
983
+ }
984
+ };
985
+ candidateHosts.forEach(
986
+ (host) => trackPropertyKey(
987
+ host,
988
+ (key) => resolved(
989
+ key === void 0 ? void 0 : {
990
+ key,
991
+ host,
992
+ isReactive: false
993
+ }
994
+ ),
995
+ defaultValue
996
+ )
997
+ );
998
+ const component = candidateHosts.find(
999
+ (host) => "manager" in host && typeof host.manager === "object" && host.manager.component === host
1000
+ );
1001
+ if (component) {
1002
+ trackPropKey(
1003
+ component,
1004
+ (key) => resolved(
1005
+ key === void 0 ? void 0 : {
1006
+ key,
1007
+ host: component,
1008
+ isReactive: getMemberType(component, key) !== void 0
1009
+ }
1010
+ ),
1011
+ defaultValue
1012
+ );
1013
+ }
1014
+ return defaultValue;
1015
+ }
1016
+
1017
+ // src/getSet.ts
1018
+ function getSet(defaultValue, getSet2) {
1019
+ const component = retrieveComponent();
1020
+ return trackPropKey(
1021
+ component,
1022
+ (rawName) => {
1023
+ const name2 = rawName;
1024
+ const manager = component.manager;
1025
+ const genericComponent = component;
1026
+ const value = genericComponent[name2];
1027
+ const isStencilHotReload = "production" !== "production" ;
1028
+ if (value != null && value !== defaultValue && typeof getSet2.set === "function" && !isStencilHotReload) {
1029
+ const newValue = getSet2.set(value, defaultValue, name2);
1030
+ if (newValue !== value) {
1031
+ if (manager.isLit) {
1032
+ genericComponent[name2] = newValue;
1033
+ } else {
1034
+ let firstConnected = true;
1035
+ manager.onConnected(() => {
1036
+ if (!firstConnected) {
1037
+ return;
1038
+ }
1039
+ firstConnected = true;
1040
+ bypassSetter(() => {
1041
+ genericComponent[name2] = newValue;
1042
+ });
1043
+ });
1044
+ }
1045
+ }
1046
+ }
1047
+ genericGetSet(component, name2, getSet2);
1048
+ },
1049
+ defaultValue
1050
+ );
1051
+ }
1052
+ function bypassSetter(callback) {
1053
+ shouldBypass.setter = true;
1054
+ try {
1055
+ return callback();
1056
+ } finally {
1057
+ shouldBypass.setter = false;
1058
+ }
1059
+ }
1060
+ function genericGetSet(component, property, getSet2) {
1061
+ var _a2, _b;
1062
+ const genericGetSet2 = getSet2;
1063
+ const internals = component.manager.internals;
1064
+ const get = typeof genericGetSet2.get === "function" ? genericGetSet2.get : void 0;
1065
+ if (get) {
1066
+ (_a2 = internals.getters)[property] ?? (_a2[property] = []);
1067
+ internals.getters[property].unshift(get);
1068
+ }
1069
+ const set = genericGetSet2.set === "ignore" ? ignoreSet : genericGetSet2.set;
1070
+ if (set) {
1071
+ (_b = internals.setters)[property] ?? (_b[property] = []);
1072
+ internals.setters[property].unshift(
1073
+ set
1074
+ );
1075
+ }
1076
+ }
1077
+ var ignoreSet = (_, value) => value;
1078
+ function bypassReadOnly(callback) {
1079
+ shouldBypass.readOnly = true;
1080
+ try {
1081
+ return callback();
1082
+ } finally {
1083
+ shouldBypass.readOnly = false;
1084
+ }
1085
+ }
1086
+
1087
+ // src/proxyExports.ts
1088
+ var proxyExports = (Class) => (...args) => {
1089
+ const ambientControllers2 = retrieveParentControllers();
1090
+ const instance = new Class(...args);
1091
+ const initialExports = instance.exports;
1092
+ setParentController(ambientControllers2.at(-1));
1093
+ const internals = instance.component.manager.internals;
1094
+ internals.markExports(instance, initialExports);
1095
+ instance.watchExports((exports) => internals.markExports(instance, exports));
1096
+ setAmbientChildController(instance);
1097
+ const hostCandidates = [instance.component, ...ambientControllers2].reverse();
1098
+ return trackKey(
1099
+ hostCandidates,
1100
+ (resolution) => resolution === void 0 ? void 0 : setProxy(instance, resolution, initialExports),
1101
+ initialExports
1102
+ );
1103
+ };
1104
+ function setProxy(controller, { host, key, isReactive: assignedToProp }, initialExports) {
1105
+ const genericHost = host;
1106
+ const controllerValueChanged = genericHost[key] !== controller.exports;
1107
+ const hostValueChanged = genericHost[key] !== initialExports;
1108
+ const controllerUpdatedExports = initialExports !== controller.exports;
1109
+ if (controllerValueChanged && !hostValueChanged && controllerUpdatedExports) {
1110
+ genericHost[key] = controller.exports;
1111
+ }
1112
+ const isProxyExportsOnComponent = host === controller.component;
1113
+ if (isProxyExportsOnComponent) {
1114
+ if (assignedToProp) {
1115
+ const internals = controller.component.manager.internals;
1116
+ if (hostValueChanged) {
1117
+ internals.markExports(controller, genericHost[key]);
1118
+ }
1119
+ watch(controller.component, key, (value) => {
1120
+ if (value !== controller.exports) {
1121
+ internals.markExports(controller, value);
1122
+ }
1123
+ });
1124
+ }
1125
+ controller.assignedProperty = assignedToProp ? void 0 : key;
1126
+ }
1127
+ controller.watchExports(() => {
1128
+ if (genericHost[key] === controller.exports) {
1129
+ return;
1130
+ }
1131
+ const manager = controller.component.manager;
1132
+ const isReadOnly = manager.internals.setters[key]?.includes(manager.internals.readonlySetter);
1133
+ if (isReadOnly) {
1134
+ bypassReadOnly(() => {
1135
+ genericHost[key] = controller.exports;
1136
+ });
1137
+ } else {
1138
+ genericHost[key] = controller.exports;
1139
+ }
1140
+ });
1141
+ }
1142
+
1143
+ // src/functional.ts
1144
+ var makeController = (constructor) => proxy(void 0, constructor);
1145
+ var FunctionalController = class extends Controller {
1146
+ constructor(component, constructor) {
1147
+ super(component);
1148
+ const originalExports = this.exports;
1149
+ try {
1150
+ setAmbientComponent(this.component);
1151
+ const value = constructor(this.component, this);
1152
+ const constructorChangedExports = this.exports !== originalExports;
1153
+ if (value instanceof Promise) {
1154
+ if (!constructorChangedExports) {
1155
+ this.setProvisionalExports(value);
1156
+ }
1157
+ const resolved = value.then((result) => {
1158
+ this.exports = result;
1159
+ super.catchUpLifecycle();
1160
+ }).catch((error) => {
1161
+ this._ready.reject(error);
1162
+ console.error(error);
1163
+ });
1164
+ this.onLoad(async () => await resolved);
1165
+ } else {
1166
+ if (!constructorChangedExports || value !== void 0) {
1167
+ this.exports = value;
1168
+ }
1169
+ queueMicrotask(() => super.catchUpLifecycle());
1170
+ }
1171
+ } catch (error) {
1172
+ this._ready.reject(error);
1173
+ console.error(error);
1174
+ }
1175
+ }
1176
+ /** Noop - will be called in the constructor instead */
1177
+ catchUpLifecycle() {
1178
+ return;
1179
+ }
1180
+ };
1181
+ var proxy = proxyExports(FunctionalController);
1182
+ var makeT9nController = (getAssetPath) => (options = {}) => (
1183
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1184
+ makeController((component, controller) => {
1185
+ const componentWithOverrides = component;
1186
+ controller.onLifecycle(
1187
+ () => startLocaleObserver(
1188
+ component.el,
1189
+ getAssetPath("./assets"),
1190
+ ({ t9nLocale, t9nStrings, lang }) => {
1191
+ const withoutOverrides = {
1192
+ ...t9nStrings,
1193
+ _lang: lang,
1194
+ _t9nLocale: t9nLocale,
1195
+ _loading: false
1196
+ };
1197
+ controller.exports = withoutOverrides;
1198
+ const label = t9nStrings.componentLabel ?? t9nStrings.widgetLabel;
1199
+ if (typeof label === "string" && "label" in component && component.label == null) {
1200
+ component.label ?? (component.label = label);
1201
+ }
1202
+ applyOverrides(componentWithOverrides.messageOverrides);
1203
+ },
1204
+ options.name
1205
+ )
1206
+ );
1207
+ function applyOverrides(messageOverrides) {
1208
+ const currentValue = controller.exports;
1209
+ const rawMessages = currentValue._original ?? currentValue;
1210
+ const updated = deepMerge(rawMessages, messageOverrides);
1211
+ if (messageOverrides) {
1212
+ updated._original = rawMessages;
1213
+ }
1214
+ controller.exports = updated;
1215
+ }
1216
+ if ("messageOverrides" in componentWithOverrides) {
1217
+ controller.onLifecycle(() => watch(componentWithOverrides, "messageOverrides", applyOverrides));
1218
+ }
1219
+ if (options.blocking) {
1220
+ return controller.ready;
1221
+ }
1222
+ const locale = getElementLocales(component.el);
1223
+ const pending = {
1224
+ _lang: locale.lang,
1225
+ _t9nLocale: locale.t9nLocale,
1226
+ _loading: true
1227
+ };
1228
+ return pending;
1229
+ })
1230
+ );
1231
+ function deepMerge(original, overwrites) {
1232
+ if (!overwrites) {
1233
+ return original;
1234
+ }
1235
+ const merged = { ...original };
1236
+ Object.entries(overwrites).forEach(([key, value]) => {
1237
+ if (typeof value === "object") {
1238
+ merged[key] = deepMerge(original[key], value);
1239
+ } else {
1240
+ merged[key] = value ?? original[key];
1241
+ }
1242
+ });
1243
+ return merged;
1244
+ }
1245
+
1246
+ const useT9n = makeT9nController(getAssetPath);
1247
+
1248
+ export { useT9n as a, getSet as g, useControllerManager as u };