@arcgis/coding-components 4.30.0-next.21 → 4.30.0-next.22

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 (135) 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/arcade-api.t9n.ar.json +25 -0
  3. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.bg.json +25 -0
  4. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.bs.json +25 -0
  5. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ca.json +25 -0
  6. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.cs.json +25 -0
  7. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.da.json +25 -0
  8. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.de.json +25 -0
  9. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.el.json +25 -0
  10. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.en.json +25 -0
  11. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.es.json +25 -0
  12. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.et.json +25 -0
  13. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.fi.json +25 -0
  14. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.fr.json +25 -0
  15. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.he.json +25 -0
  16. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.hr.json +25 -0
  17. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.hu.json +25 -0
  18. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.id.json +25 -0
  19. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.it.json +25 -0
  20. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ja.json +25 -0
  21. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ko.json +25 -0
  22. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.lt.json +25 -0
  23. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.lv.json +25 -0
  24. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.nb.json +25 -0
  25. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.nl.json +25 -0
  26. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.pl.json +25 -0
  27. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.pt-BR.json +25 -0
  28. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.pt-PT.json +25 -0
  29. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ro.json +25 -0
  30. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.ru.json +25 -0
  31. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sk.json +25 -0
  32. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sl.json +25 -0
  33. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sr.json +25 -0
  34. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.sv.json +25 -0
  35. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.th.json +25 -0
  36. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.tr.json +25 -0
  37. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.uk.json +25 -0
  38. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.vi.json +25 -0
  39. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.zh-CN.json +25 -0
  40. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.zh-HK.json +25 -0
  41. package/dist/arcgis-coding-components/assets/arcade-language/api/arcade-api.t9n.zh-TW.json +25 -0
  42. package/dist/arcgis-coding-components/index.esm.js +2 -2
  43. package/dist/arcgis-coding-components/p-0596e58a.js +68 -0
  44. package/dist/arcgis-coding-components/p-09b3d456.js +6 -0
  45. package/dist/arcgis-coding-components/{p-5583b25d.js → p-237cd069.js} +2 -2
  46. package/dist/arcgis-coding-components/{p-a63eeed9.js → p-3c4c9bb1.js} +1 -1
  47. package/dist/arcgis-coding-components/{p-253f92ea.js → p-52af3d36.js} +2 -2
  48. package/dist/arcgis-coding-components/{p-cb5166f2.js → p-54a3c846.js} +2 -2
  49. package/dist/arcgis-coding-components/{p-192601ca.js → p-68c09f28.js} +2 -2
  50. package/dist/arcgis-coding-components/p-704509f4.entry.js +6 -0
  51. package/dist/arcgis-coding-components/{p-b177db92.js → p-89a837be.js} +2 -2
  52. package/dist/arcgis-coding-components/p-8be62afd.js +7 -0
  53. package/dist/arcgis-coding-components/{p-eb16cce2.js → p-a8a82d95.js} +2 -2
  54. package/dist/arcgis-coding-components/{p-1451e0cc.js → p-bf1aaa39.js} +2 -2
  55. package/dist/arcgis-coding-components/{p-0e7b5896.js → p-bf789380.js} +2 -2
  56. package/dist/arcgis-coding-components/p-f31fa95c.js +6 -0
  57. package/dist/arcgis-coding-components/p-f9bdf871.js +6 -0
  58. package/dist/cjs/Accessor-YDTURKZ7-064d4ec3.js +1249 -0
  59. package/dist/cjs/{arcade-defaults-9d57f506.js → arcade-defaults-75be7a9b.js} +294 -295
  60. package/dist/cjs/{arcade-mode-9079b8e0.js → arcade-mode-bf406304.js} +4 -4
  61. package/dist/cjs/arcgis-arcade-api_6.cjs.entry.js +1347 -89
  62. package/dist/cjs/arcgis-coding-components.cjs.js +3 -3
  63. package/dist/cjs/chunk-OMA4PI5N-c7c531ca.js +1286 -0
  64. package/dist/cjs/{css-9aa4569b.js → css-a1b28a9f.js} +1 -1
  65. package/dist/cjs/{cssMode-6f57c416.js → cssMode-5b3b9c9b.js} +3 -3
  66. package/dist/cjs/decorators-443AWDOE-ab85b9eb.js +120 -0
  67. package/dist/cjs/{html-95d3a234.js → html-51efc5f2.js} +3 -3
  68. package/dist/cjs/{htmlMode-ebd8894d.js → htmlMode-a3589bc9.js} +3 -3
  69. package/dist/cjs/{index-a3f52cf5.js → index-6a3d1ddd.js} +42 -4
  70. package/dist/cjs/index.cjs.js +3 -3
  71. package/dist/cjs/{javascript-1a01235b.js → javascript-f387480b.js} +4 -4
  72. package/dist/cjs/{jsonMode-26ed7799.js → jsonMode-f9b19644.js} +3 -3
  73. package/dist/cjs/loader.cjs.js +3 -3
  74. package/dist/cjs/{tsMode-9cfeb9a5.js → tsMode-b1e0bb57.js} +3 -3
  75. package/dist/cjs/{typescript-f9907455.js → typescript-64e66362.js} +3 -3
  76. package/dist/components/Accessor-YDTURKZ7.js +1247 -0
  77. package/dist/components/arcade-api.js +9 -15
  78. package/dist/components/arcade-contribution.js +3 -3
  79. package/dist/components/arcade-defaults.js +10 -10
  80. package/dist/components/arcade-mode.js +3 -3
  81. package/dist/components/arcade-results.js +24 -35
  82. package/dist/components/arcade-suggestions.js +10 -16
  83. package/dist/components/arcade-variables.js +11 -20
  84. package/dist/components/arcgis-arcade-api.js +1 -1
  85. package/dist/components/arcgis-arcade-editor.js +20 -24
  86. package/dist/components/arcgis-arcade-results.js +1 -1
  87. package/dist/components/arcgis-arcade-suggestions.js +1 -1
  88. package/dist/components/arcgis-arcade-variables.js +1 -1
  89. package/dist/components/arcgis-assets.d.ts +1 -1
  90. package/dist/components/arcgis-assets.js +1 -1
  91. package/dist/components/arcgis-code-editor.js +1 -1
  92. package/dist/components/chunk-3I7AEPTU.js +1290 -0
  93. package/dist/components/chunk-OMA4PI5N.js +1257 -0
  94. package/dist/components/code-editor.js +6 -6
  95. package/dist/components/decorators-443AWDOE.js +109 -0
  96. package/dist/components/fields.js +40 -39
  97. package/dist/components/index.js +1 -1
  98. package/dist/components/index2.js +3 -3
  99. package/dist/components/markdown.js +1 -1
  100. package/dist/components/utilities.js +3 -3
  101. package/dist/esm/Accessor-YDTURKZ7-4eefd1d8.js +1247 -0
  102. package/dist/esm/{arcade-defaults-1577045c.js → arcade-defaults-fcc709e4.js} +286 -285
  103. package/dist/esm/{arcade-mode-ec8b7890.js → arcade-mode-dbf28353.js} +4 -4
  104. package/dist/esm/arcgis-arcade-api_6.entry.js +1389 -131
  105. package/dist/esm/arcgis-coding-components.js +4 -4
  106. package/dist/esm/chunk-OMA4PI5N-0c09fa7b.js +1257 -0
  107. package/dist/esm/{css-6350c0f7.js → css-6122a30a.js} +1 -1
  108. package/dist/esm/{cssMode-629b1349.js → cssMode-b890adfc.js} +3 -3
  109. package/dist/esm/decorators-443AWDOE-77ed5d5a.js +109 -0
  110. package/dist/esm/{html-979016b0.js → html-2f56c6c3.js} +3 -3
  111. package/dist/esm/{htmlMode-dd504dae.js → htmlMode-84b5c7ea.js} +3 -3
  112. package/dist/esm/{index-093931a1.js → index-e75c4ffc.js} +42 -5
  113. package/dist/esm/index.js +3 -3
  114. package/dist/esm/{javascript-7af48cb1.js → javascript-8456a624.js} +4 -4
  115. package/dist/esm/{jsonMode-eb6b41d1.js → jsonMode-29439efe.js} +3 -3
  116. package/dist/esm/loader.js +4 -4
  117. package/dist/esm/{tsMode-64deb000.js → tsMode-ec7fe1bf.js} +3 -3
  118. package/dist/esm/{typescript-c9b14542.js → typescript-d9362143.js} +3 -3
  119. package/dist/loader/cdn.js +1 -1
  120. package/dist/loader/index.cjs.js +1 -1
  121. package/dist/loader/index.es2017.js +1 -1
  122. package/dist/loader/index.js +1 -1
  123. package/dist/types/components/arcade-api/arcade-api.d.ts +4 -5
  124. package/dist/types/components/arcade-editor/arcade-editor.d.ts +7 -4
  125. package/dist/types/components/arcade-results/arcade-results.d.ts +4 -7
  126. package/dist/types/components/arcade-suggestions/arcade-suggestions.d.ts +4 -5
  127. package/dist/types/components/arcade-variables/arcade-variables.d.ts +4 -6
  128. package/package.json +12 -12
  129. package/dist/arcgis-coding-components/p-81935687.js +0 -68
  130. package/dist/arcgis-coding-components/p-a2190df0.js +0 -7
  131. package/dist/arcgis-coding-components/p-e8c2933f.entry.js +0 -6
  132. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stencil.config.d.ts +0 -3
  133. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/sass-inline-url-importer.d.ts +0 -9
  134. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/sass-json-importer.d.ts +0 -19
  135. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/support/stencil-monaco-plugins.d.ts +0 -6
@@ -0,0 +1,1290 @@
1
+ /*!
2
+ * All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
+ * See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
+ * v4.30.0-next.22
5
+ */
6
+ import { forceUpdate } from '@stencil/core/internal/client';
7
+ import { getArcgisAssetPath as getAssetPath } from "./arcgis-assets.js";
8
+
9
+ // ../components-utils/dist/index.js
10
+ var h = class {
11
+ constructor() {
12
+ this.resolve = () => {
13
+ }, this.reject = () => {
14
+ }, this.promise = new Promise((t, n) => {
15
+ this.resolve = t, this.reject = n;
16
+ });
17
+ }
18
+ };
19
+ function w(e, t) {
20
+ let n = e;
21
+ for (; n; ) {
22
+ if (n === t)
23
+ return true;
24
+ if (!n.parentNode)
25
+ return false;
26
+ n.parentNode instanceof ShadowRoot ? n = n.parentNode.host : n = n.parentNode;
27
+ }
28
+ return false;
29
+ }
30
+ function b(e, t, n) {
31
+ let { subscribe: r } = $(t);
32
+ return r((o) => {
33
+ o.some((s) => w(e, s.target)) && n();
34
+ });
35
+ }
36
+ var f = {};
37
+ function $(e) {
38
+ let t = e.join(","), n = f[t];
39
+ if (n !== void 0)
40
+ return n;
41
+ let r = /* @__PURE__ */ new Set(), o = new MutationObserver((s) => r.forEach((a) => a(s)));
42
+ o.observe(document.documentElement, { attributes: true, attributeFilter: e, subtree: true });
43
+ let i = { subscribe(s) {
44
+ return r.add(s), { remove: () => {
45
+ r.delete(s), r.size === 0 && (o.disconnect(), f[t] = void 0);
46
+ } };
47
+ } };
48
+ return f[t] = i, i;
49
+ }
50
+ function x(e, t) {
51
+ let n = e;
52
+ for (; n; ) {
53
+ let r = n.closest(t);
54
+ if (r)
55
+ return r;
56
+ let o = n.getRootNode();
57
+ if (o === document)
58
+ return null;
59
+ n = o.host;
60
+ }
61
+ return null;
62
+ }
63
+ function m(e, t, n) {
64
+ return x(e, `[${t}]`)?.getAttribute(t) ?? n;
65
+ }
66
+ var A = (e) => e.charAt(0).toUpperCase() + e.slice(1);
67
+ var T = (e) => A(e.replaceAll(/([a-z])([A-Z])/gu, "$1 $2"));
68
+ var v = /* @__PURE__ */ new Set(["ar", "bg", "bs", "ca", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "he", "hr", "hu", "id", "it", "ja", "ko", "lt", "lv", "nl", "nb", "pl", "pt-BR", "pt-PT", "ro", "ru", "sk", "sl", "sr", "sv", "th", "tr", "uk", "vi", "zh-CN", "zh-HK", "zh-TW"]);
69
+ var g = "en";
70
+ async function j(e, t, n = "") {
71
+ let r = `${t}/${n}`, o = `${r}${e}.json`;
72
+ return u[o] ?? (u[o] = S(e, r)), await u[o];
73
+ }
74
+ var u = {};
75
+ async function S(e, t) {
76
+ let n = `${t}${e}.json`;
77
+ try {
78
+ let r = await fetch(n);
79
+ if (r.ok)
80
+ return await r.json();
81
+ } catch (r) {
82
+ return console.error(r), E;
83
+ }
84
+ return e === g ? E : await S(g, t);
85
+ }
86
+ var E = new Proxy({}, { get: (e, t) => T(t.toString()) });
87
+ function M(e) {
88
+ let t = m(e, "lang", navigator.language || g);
89
+ if (v.has(t))
90
+ return { lang: t, t9nLocale: t };
91
+ let n = t.slice(0, 2);
92
+ return { lang: t, t9nLocale: v.has(n) ? n : g };
93
+ }
94
+ function Y(e, t, n, r) {
95
+ let o, i = () => void P(e, t, r).then((s) => {
96
+ (o?.lang !== s.lang || o.t9nLocale !== s.t9nLocale || o.t9nStrings !== s.t9nStrings) && n(s), o = s;
97
+ }).catch(console.error);
98
+ return i(), b(e, ["lang"], i);
99
+ }
100
+ async function P(e, t, n = e.tagName.toLowerCase().replace("arcgis-", "")) {
101
+ let { lang: r, t9nLocale: o } = M(e), i = `${t}/${n}/t9n`, s = `${n}.t9n.`, a = await j(o, i, s);
102
+ return { lang: r, t9nLocale: o, t9nStrings: a };
103
+ }
104
+
105
+ // src/types.ts
106
+ var controllerSymbol = Symbol("controller");
107
+
108
+ // src/utils.ts
109
+ function safeCall(callback) {
110
+ try {
111
+ return callback?.();
112
+ } catch (error) {
113
+ console.error(error, callback);
114
+ }
115
+ return void 0;
116
+ }
117
+ async function safeAsyncCall(callback) {
118
+ try {
119
+ return await callback();
120
+ } catch (error) {
121
+ console.error(error, callback);
122
+ }
123
+ return void 0;
124
+ }
125
+ function extendObject(base, extend) {
126
+ Object.entries(extend).forEach(([key, value]) => {
127
+ if (key in base)
128
+ throw new Error(`Unable to extend object because property "${key}" is already defined`);
129
+ const thisBase = base;
130
+ thisBase[key] = value;
131
+ });
132
+ return base;
133
+ }
134
+ var isController = (value) => typeof value === "object" && value !== null && (controllerSymbol in value || "hostConnected" in value || "hostDisconnected" in value || "hostUpdate" in value || "hostUpdated" in value);
135
+
136
+ // src/ControllerInternals.ts
137
+ var ControllerInternals = class {
138
+ constructor() {
139
+ this._ambientControllers = [];
140
+ /**
141
+ * The type definition has to be duplicated due to the
142
+ * "'use' is referenced directly or indirectly in its own type annotation."
143
+ * error
144
+ */
145
+ this.use = async (value, watchExports) => {
146
+ const controller = this._useRefSync(value);
147
+ if (controller === void 0) {
148
+ if (typeof watchExports === "function") {
149
+ const error = new Error(
150
+ `Unable to resolve a controller from the provided value, so can't watch it's exports. ${unresolvableExports}`
151
+ );
152
+ console.error(error);
153
+ }
154
+ return value;
155
+ }
156
+ await controller.ready;
157
+ if (typeof watchExports === "function") {
158
+ if (controller.watchExports === void 0)
159
+ throw new Error(`The controller must implement watchExports method to support watching exports`);
160
+ const unsubscribe = controller.watchExports(
161
+ (exports) => watchExports(exports, unsubscribe)
162
+ );
163
+ }
164
+ return controller.exports;
165
+ };
166
+ this.useRef = async (value) => {
167
+ const controller = this._useRefSync(value);
168
+ if (controller === void 0)
169
+ throw new Error(`Unable to resolve a controller from the provided value. ${unresolvableExports}`);
170
+ await controller.ready;
171
+ return controller;
172
+ };
173
+ this.shouldBypassSetter = false;
174
+ /**
175
+ * A map from component instance or component element to component instance.
176
+ * To get from component instance or component element to component element,
177
+ * you can just use the .el property
178
+ */
179
+ this.elementToInstance = /* @__PURE__ */ new WeakMap();
180
+ }
181
+ /*
182
+ * Allow controllers to implicitly retrive which component they are in, to
183
+ * improve DX (avoids the need to pass "this" explicitly for each controller)
184
+ */
185
+ setAmbientComponent(component) {
186
+ if (this._ambientComponent === component)
187
+ return;
188
+ this._ambientComponent = component;
189
+ queueMicrotask(() => {
190
+ if (this._ambientComponent === component)
191
+ this._ambientComponent = void 0;
192
+ });
193
+ }
194
+ retriveComponent(name) {
195
+ if (this._ambientComponent === void 0)
196
+ throw new Error(
197
+ [
198
+ `Unable to find out which component ${name || "this"} controller `,
199
+ "belongs to. This might happen if you tried to create a controller ",
200
+ "outside the component. If so, please wrap your controller ",
201
+ "definition in an arrow function, ",
202
+ "`const myController = ()=>makeController(...);` and call that",
203
+ "function inside the component `my = myController();`, or ",
204
+ "define your controller using makeGenericController/GenericController ",
205
+ "instead.\n",
206
+ "If you wish to use a controller inside an async controller, ",
207
+ "make sure you are using controller.use.\n",
208
+ "You might also have multiple instances of Controllers loaded"
209
+ ].join("\n")
210
+ );
211
+ return this._ambientComponent;
212
+ }
213
+ /*
214
+ * Aids proxyExports() in knowing who is it's host
215
+ */
216
+ setParentController(controller) {
217
+ if (controller === void 0) {
218
+ this._ambientControllers = [];
219
+ return;
220
+ }
221
+ const index = this._ambientControllers.indexOf(controller);
222
+ this._ambientControllers = index === -1 ? [...this._ambientControllers, controller] : this._ambientControllers.slice(0, index + 1);
223
+ queueMicrotask(() => {
224
+ this._ambientControllers = [];
225
+ });
226
+ }
227
+ retriveParentControllers() {
228
+ return this._ambientControllers;
229
+ }
230
+ /*
231
+ * Aids controller.use in retrieving controller value when it receives
232
+ * controller exports, rather than the controller itself
233
+ */
234
+ setAmbientChildController(controller) {
235
+ if (this._ambientChildController === controller)
236
+ return;
237
+ this._ambientChildController = controller;
238
+ queueMicrotask(() => {
239
+ if (this._ambientChildController === controller)
240
+ this._ambientChildController = void 0;
241
+ });
242
+ }
243
+ retriveAmbientChildController() {
244
+ const controller = this._ambientChildController;
245
+ this._ambientChildController = void 0;
246
+ return controller;
247
+ }
248
+ /**
249
+ * Try to resolve a controller, without awaiting it's load
250
+ */
251
+ _useRefSync(value) {
252
+ const ambientChildController = this.retriveAmbientChildController();
253
+ if (ambientChildController !== void 0)
254
+ return ambientChildController;
255
+ const component = Controller.internals.retriveComponent();
256
+ const controller = component.manager.internals.resolveExports(value);
257
+ if (controller !== void 0)
258
+ return controller;
259
+ if (isController(value))
260
+ return value;
261
+ return void 0;
262
+ }
263
+ };
264
+ var unresolvableExports = [
265
+ "The value you passed is not a controller and not a controller exports. If ",
266
+ "your controller exports a literal value, try making your controller export ",
267
+ "an object instead"
268
+ ].join("");
269
+
270
+ // src/stencil.ts
271
+ function retrieveComponentMeta(component) {
272
+ const constructor = component.constructor;
273
+ const meta = constructor.__registerControllers?.(component)?.$cmpMeta$ ?? void 0;
274
+ constructor.__registerControllers = void 0;
275
+ if (typeof meta !== "object")
276
+ throw new Error(
277
+ "Failed to retrive internal component meta. Make sure you have the useComponentsControllers() Rollup Plugin for Stencil Controllers configured in your Stencil config."
278
+ );
279
+ component.manager.internals.meta = meta;
280
+ }
281
+ function parsePropertyValue(value, type = 0) {
282
+ if (value == null || typeof type !== "number")
283
+ return value;
284
+ if ((type & 4 /* Boolean */) !== 0)
285
+ return value === "false" ? false : value === "" || !!value;
286
+ else if ((type & 2 /* Number */) !== 0)
287
+ return Number.parseFloat(value.toString());
288
+ else if ((type & 1 /* String */) !== 0)
289
+ return String(value);
290
+ else
291
+ return value;
292
+ }
293
+ var makeMemberFilter = (filter) => (component) => {
294
+ const meta = component.manager.internals.meta;
295
+ return Object.entries(meta.$members$ ?? {}).filter(([_name, [propType]]) => (propType & filter) !== 0).map(([name]) => name);
296
+ };
297
+ var getPropLikeMembers = makeMemberFilter(63 /* PropLike */);
298
+ var getMemberType = (component, name) => component.manager.internals.meta.$members$?.[name]?.[0];
299
+ function getPropType(component, name) {
300
+ const type = getMemberType(component, name);
301
+ if (type === void 0)
302
+ return void 0;
303
+ else if (type & 32 /* State */)
304
+ return "state";
305
+ else
306
+ return "prop";
307
+ }
308
+ function addPropertyWatcher(component, property) {
309
+ const meta = component.manager.internals.meta;
310
+ meta.$watchers$ ?? (meta.$watchers$ = {});
311
+ const watchers = meta.$watchers$;
312
+ if (!(property in watchers))
313
+ watchers[property] = [];
314
+ if (!watchers[property].includes(watcherCallbackName))
315
+ watchers[property].push(watcherCallbackName);
316
+ }
317
+ var watcherCallbackName = "dynamicWatcherCallback";
318
+
319
+ // src/Controller.ts
320
+ var _a;
321
+ var _Controller = class _Controller {
322
+ constructor(component) {
323
+ this._ready = new h();
324
+ this._lifecycleDisconnected = [];
325
+ this.connectedCalled = false;
326
+ this.willLoadCalled = false;
327
+ this.didLoadCalled = false;
328
+ this[_a] = true;
329
+ this.ready = this._ready.promise;
330
+ /*
331
+ * Setting default exports to "this" so that controllers that don't use
332
+ * exports/proxyExports(), could still be used as if they did
333
+ * (i.e with controller.use)
334
+ */
335
+ this._exports = makeProvisionalValue(this);
336
+ this._exportWatchers = /* @__PURE__ */ new Set();
337
+ const resolvedComponent = toControllerHost(
338
+ component ?? _Controller.internals.retriveComponent(new.target.name)
339
+ );
340
+ Object.defineProperty(this, "component", {
341
+ writable: false,
342
+ enumerable: false,
343
+ configurable: true,
344
+ value: resolvedComponent
345
+ });
346
+ this.component.addController(this);
347
+ const manager = this.component.manager;
348
+ this.connected = manager?.connected;
349
+ this.internals = manager?.internals;
350
+ _Controller.internals.setParentController(this);
351
+ if ("hostDestroy" in this)
352
+ this.component.manager.ensureHasDestroy();
353
+ if (manager !== void 0)
354
+ queueMicrotask(() => this.catchUpLifecycle());
355
+ const controller = this;
356
+ this._callbacks = {
357
+ hostConnected: "hostConnected" in this ? [() => controller.hostConnected?.()] : [],
358
+ hostDisconnected: "hostDisconnected" in this ? [() => controller.hostDisconnected?.()] : [],
359
+ hostLoad: "hostLoad" in this ? [() => controller.hostLoad?.()] : [],
360
+ hostLoaded: "hostLoaded" in this ? [() => controller.hostLoaded?.()] : [],
361
+ hostRender: "hostRender" in this ? [() => controller.hostRender?.()] : [],
362
+ hostRendered: "hostRendered" in this ? [() => controller.hostRendered?.()] : [],
363
+ hostUpdate: "hostUpdate" in this ? [() => controller.hostUpdate?.()] : [],
364
+ hostUpdated: "hostUpdated" in this ? [() => controller.hostUpdated?.()] : [],
365
+ hostDestroy: "hostDestroy" in this ? [() => controller.hostDestroy?.()] : [],
366
+ hostLifecycle: "hostLifecycle" in this ? [() => controller.hostLifecycle?.()] : []
367
+ };
368
+ }
369
+ /**
370
+ * If controller is being added dynamically, after the component
371
+ * construction, then trigger connected and load right away
372
+ */
373
+ catchUpLifecycle() {
374
+ if (this.connectedCalled)
375
+ return;
376
+ this.triggerConnected();
377
+ this.triggerLoad().then(() => this.triggerLoaded()).catch(console.error);
378
+ }
379
+ get exports() {
380
+ return this._exports;
381
+ }
382
+ /**
383
+ * Set controller's exports property (for usage with proxyExports()) and mark
384
+ * controller as ready (for usage in other controllers). Also, triggers
385
+ * re-render of the component
386
+ */
387
+ set exports(exports) {
388
+ if (this._exports !== exports) {
389
+ this._exports = exports;
390
+ if (this.connectedCalled)
391
+ this.component.requestUpdate();
392
+ this._exportWatchers.forEach((callback) => callback(exports));
393
+ }
394
+ this._ready.resolve(exports);
395
+ }
396
+ setProvisionalExports(exports) {
397
+ this._exports = makeProvisionalValue(exports);
398
+ this._exportWatchers.forEach((callback) => callback(this._exports));
399
+ }
400
+ watchExports(callback) {
401
+ const safeCallback = (exports) => safeCall(() => callback(exports));
402
+ this._exportWatchers.add(safeCallback);
403
+ return () => void this._exportWatchers.delete(safeCallback);
404
+ }
405
+ /**
406
+ * A flexible utility for making sure a controller is loaded before it's used,
407
+ * regardless of how or where a controller was defined:
408
+ *
409
+ * @example
410
+ * makeGenericController(async (component, controller) => {
411
+ * // Await some controller from the component:
412
+ * await controller.use(component.someController);
413
+ * // Initialize new controllers
414
+ * await controller.use(load(importCoreReactiveUtils));
415
+ * await controller.use(new ViewModelController(component,newWidgetsHomeHomeViewModel));
416
+ * await controller.use(someController(component));
417
+ * });
418
+ *
419
+ * @remarks
420
+ * If your controller is not async, and you are not creating it async, then
421
+ * you are not required to use controller.use - you can use it directly.
422
+ * Similarly, accessing controllers after componentWillLoad callback does not
423
+ * require awaiting them as they are guaranteed to be loaded by then.
424
+ */
425
+ get use() {
426
+ _Controller.internals.setAmbientComponent(this.component);
427
+ return _Controller.internals.use;
428
+ }
429
+ /**
430
+ * Just like controller.use, but returns the controller itself, rather than it's
431
+ * exports
432
+ *
433
+ * Use cases:
434
+ * - You have a controller and you want to make sure it's loaded before you
435
+ * try to use it
436
+ * - Your contoller is not using exports, so you wish to access some props on
437
+ * it directly
438
+ * - You have a controller exports only, and you want to retrieve the
439
+ * controller itself. This is useful if you wish to call .watchExports() or
440
+ * some other method on the controller
441
+ */
442
+ get useRef() {
443
+ _Controller.internals.setAmbientComponent(this.component);
444
+ return _Controller.internals.useRef;
445
+ }
446
+ /**
447
+ * If you need to set a prop/state without triggering the custom setter you
448
+ * defined with getSet()/dynamicGetSet()/readonly(), set the value inside
449
+ * of this function
450
+ *
451
+ * @example
452
+ * @Prop({mutable:true}) readOnly = this.manager.readOnly(true);
453
+ *
454
+ * someAction(): void {
455
+ * this.manager.bypassSetter(()=>{
456
+ * this.readOnly = false;
457
+ * });
458
+ * }
459
+ *
460
+ */
461
+ bypassSetter(callback) {
462
+ _Controller.internals.shouldBypassSetter = true;
463
+ const result = safeCall(callback);
464
+ _Controller.internals.shouldBypassSetter = false;
465
+ return result;
466
+ }
467
+ /**
468
+ * Like this.manager.getSet(), but can be called on any component's
469
+ * state/prop from anywhere, rather than just from the default value
470
+ */
471
+ dynamicGetSet(name, getSet) {
472
+ this.genericGetSet(name, getSet);
473
+ }
474
+ /**
475
+ * Like dynamicGetSet, but less type-safe. Useful in cases when trying to set
476
+ * getters/setters in place where property names & types are not known
477
+ * statically
478
+ */
479
+ genericGetSet(property, getSet) {
480
+ var _a2, _b;
481
+ const classPrototype = Object.getPrototypeOf(this.component);
482
+ this.internals.getSetProxy(classPrototype, property, getSet, "class");
483
+ const htmlPrototype = Object.getPrototypeOf(this.component.el);
484
+ if (classPrototype !== htmlPrototype)
485
+ this.internals.getSetProxy(htmlPrototype, property, getSet, "html");
486
+ const genericGetSet = getSet;
487
+ if (genericGetSet.get !== void 0) {
488
+ (_a2 = this.internals.getters)[property] ?? (_a2[property] = []);
489
+ if (getSet.order === "last")
490
+ this.internals.getters[property].splice(-1, 0, genericGetSet.get);
491
+ else
492
+ this.internals.getters[property].unshift(genericGetSet.get);
493
+ }
494
+ if (genericGetSet.set !== void 0) {
495
+ (_b = this.internals.setters)[property] ?? (_b[property] = []);
496
+ if (getSet.order === "last")
497
+ this.internals.setters[property].splice(-1, 0, genericGetSet.set);
498
+ else
499
+ this.internals.setters[property].unshift(genericGetSet.set);
500
+ }
501
+ }
502
+ // FEATURE: improve typings
503
+ /**
504
+ * Dynamically set a watcher for any @Prop()/@State() property
505
+ */
506
+ watch(property, callback) {
507
+ var _a2;
508
+ const type = getMemberType(this.component, property);
509
+ if (type === void 0)
510
+ throw new Error(
511
+ `Trying to watch a non-@Prop, non-@State property "${property}". Either convert it into a @State() or use manager.getSet/dynamicGetSet`
512
+ );
513
+ addPropertyWatcher(this.component, property);
514
+ (_a2 = this.internals.watchers)[property] ?? (_a2[property] = []);
515
+ const watchers = this.internals.watchers[property];
516
+ const genericCallback = callback;
517
+ const safeCallback = (newValue, oldValue, propertyName) => safeCall(() => genericCallback(newValue, oldValue, propertyName));
518
+ watchers.push(safeCallback);
519
+ return () => {
520
+ const index = watchers.indexOf(safeCallback);
521
+ if (index !== -1)
522
+ watchers.splice(index, 1);
523
+ };
524
+ }
525
+ // Register a lifecycle callback
526
+ onConnected(callback) {
527
+ this._callbacks.hostConnected.push(callback);
528
+ }
529
+ onDisconnected(callback) {
530
+ this._callbacks.hostDisconnected.push(callback);
531
+ }
532
+ onLoad(callback) {
533
+ this._callbacks.hostLoad.push(callback);
534
+ }
535
+ onLoaded(callback) {
536
+ this._callbacks.hostLoaded.push(callback);
537
+ }
538
+ onRender(callback) {
539
+ this._callbacks.hostRender.push(callback);
540
+ }
541
+ onRendered(callback) {
542
+ this._callbacks.hostRendered.push(callback);
543
+ }
544
+ onUpdate(callback) {
545
+ this._callbacks.hostUpdate.push(callback);
546
+ }
547
+ onUpdated(callback) {
548
+ this._callbacks.hostUpdated.push(callback);
549
+ }
550
+ onDestroy(callback) {
551
+ this.component.manager.ensureHasDestroy();
552
+ this._callbacks.hostDestroy.push(callback);
553
+ }
554
+ onLifecycle(callback) {
555
+ this._callbacks.hostLifecycle.push(callback);
556
+ if (this.connectedCalled && this.component.el.isConnected)
557
+ this._callLifecycle(callback);
558
+ }
559
+ // Call each lifecycle hook
560
+ triggerConnected() {
561
+ this._callbacks.hostConnected.forEach(safeCall);
562
+ this.triggerLifecycle();
563
+ this.connectedCalled = true;
564
+ }
565
+ triggerDisconnected() {
566
+ this._callbacks.hostDisconnected.forEach(safeCall);
567
+ this._lifecycleDisconnected.forEach(safeCall);
568
+ this._lifecycleDisconnected = [];
569
+ }
570
+ async triggerLoad() {
571
+ if (this.willLoadCalled)
572
+ return;
573
+ this.willLoadCalled = true;
574
+ if (this._callbacks.hostLoad.length > 0)
575
+ await Promise.allSettled(this._callbacks.hostLoad.map(safeAsyncCall));
576
+ this._ready.resolve(this._exports);
577
+ }
578
+ triggerLoaded() {
579
+ if (this.didLoadCalled)
580
+ return;
581
+ this._callbacks.hostLoaded.forEach(safeCall);
582
+ this.didLoadCalled = true;
583
+ }
584
+ async triggerRender() {
585
+ if (this._callbacks.hostRender.length > 0)
586
+ await Promise.allSettled(this._callbacks.hostRender.map(safeAsyncCall));
587
+ }
588
+ triggerRendered() {
589
+ this._callbacks.hostRendered.forEach(safeCall);
590
+ }
591
+ async triggerUpdate() {
592
+ if (this._callbacks.hostUpdate.length > 0)
593
+ await Promise.allSettled(this._callbacks.hostUpdate.map(safeAsyncCall));
594
+ }
595
+ triggerUpdated() {
596
+ this._callbacks.hostUpdated.forEach(safeCall);
597
+ }
598
+ triggerDestroy() {
599
+ this._callbacks.hostDestroy.forEach(safeCall);
600
+ }
601
+ triggerLifecycle() {
602
+ this._callbacks.hostLifecycle.forEach((callback) => this._callLifecycle(callback));
603
+ }
604
+ _callLifecycle(callback) {
605
+ const cleanupRaw = safeCall(callback);
606
+ const cleanup = Array.isArray(cleanupRaw) ? cleanupRaw : [cleanupRaw];
607
+ cleanup.forEach((cleanup2) => {
608
+ if (typeof cleanup2 === "function")
609
+ this._lifecycleDisconnected.push(cleanup2);
610
+ else if (typeof cleanup2 === "object" && typeof cleanup2.remove === "function")
611
+ this._lifecycleDisconnected.push(cleanup2.remove);
612
+ });
613
+ }
614
+ };
615
+ _a = controllerSymbol;
616
+ _Controller.internals = new ControllerInternals();
617
+ var Controller = _Controller;
618
+ var GenericController = class extends Controller {
619
+ // Redundant constructor needed to improve typing
620
+ constructor(component) {
621
+ super(component);
622
+ }
623
+ // Overriding super's watch only to improve typing
624
+ watch(property, callback) {
625
+ return super.watch(
626
+ property,
627
+ callback
628
+ );
629
+ }
630
+ /**
631
+ * Silence "Property 'dynamicGetSet' in type
632
+ * 'GenericController<Exports, Requires>' is not assignable to the same
633
+ * property in base type 'Controller<Exports>'", as TypeScript is being overly
634
+ * conservative here with what it allows
635
+ */
636
+ dynamicGetSet(property, getSet) {
637
+ super.genericGetSet(property, getSet);
638
+ }
639
+ };
640
+ function makeProvisionalValue(base) {
641
+ if (typeof base !== "object" && typeof base !== "function" || base === null)
642
+ return base;
643
+ const proxy3 = new Proxy(base, {
644
+ get(target, prop, receiver) {
645
+ if (cyclical.has(prop) && prop in target && target[prop] === proxy3)
646
+ return void 0;
647
+ if (prop in target || promiseMethods.has(prop) || typeof prop === "symbol")
648
+ return typeof target === "function" ? target[prop] : Reflect.get(target, prop, receiver);
649
+ console.error(`Trying to access "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`);
650
+ return void 0;
651
+ },
652
+ set(target, prop, newValue, reciever) {
653
+ console.error(`Trying to set "${prop.toString()}" on the controller before it's loaded. ${accessBeforeLoad}`);
654
+ return Reflect.set(target, prop, newValue, reciever);
655
+ }
656
+ });
657
+ return proxy3;
658
+ }
659
+ var promiseMethods = /* @__PURE__ */ new Set(["then", "catch", "finally"]);
660
+ var cyclical = /* @__PURE__ */ new Set(["exports", "_exports"]);
661
+ var accessBeforeLoad = [
662
+ "This might be the case if you are trying to access an async controller in ",
663
+ "connectedCallback(). Or, if you are using it inside of ",
664
+ "componentWillLoad()/another controller without controller.use. Example correct ",
665
+ "usage:\n",
666
+ "makeController(async (component, controller)=>{ await controller.use(someOtherController); });"
667
+ ].join("");
668
+ function toControllerHost(component) {
669
+ if ("addController" in component)
670
+ return component;
671
+ else
672
+ throw new Error(
673
+ "Component does not implement ControllerHost. This might be because you forgot to add 'manager: Controller<this> = useControllerManager(this);' in your component, or you tried to use some controller before that line"
674
+ );
675
+ }
676
+
677
+ // src/trackPropertyKey.ts
678
+ function trackPropertyKey(object, onResolved, defaultValue) {
679
+ const keys = Object.keys(object);
680
+ const keyCount = keys.length;
681
+ if (keyTrackMap === void 0)
682
+ queueMicrotask(keyTrackResolve);
683
+ keyTrackMap ?? (keyTrackMap = /* @__PURE__ */ new Map());
684
+ let pendingTrackers = keyTrackMap.get(object);
685
+ if (pendingTrackers === void 0) {
686
+ pendingTrackers = { callbacks: [], keyCount };
687
+ keyTrackMap.set(object, pendingTrackers);
688
+ }
689
+ if (pendingTrackers.keyCount !== keyCount) {
690
+ pendingTrackers.callbacks.forEach((resolve) => resolve(keys));
691
+ pendingTrackers.callbacks = [];
692
+ pendingTrackers.keyCount = keyCount;
693
+ }
694
+ pendingTrackers.callbacks.push((keys2) => {
695
+ const key = keys2[keyCount];
696
+ if (key === void 0)
697
+ onResolved(void 0);
698
+ else if (object[key] === defaultValue)
699
+ onResolved(key);
700
+ else
701
+ onResolved(void 0);
702
+ });
703
+ return defaultValue;
704
+ }
705
+ var keyTrackMap = void 0;
706
+ function keyTrackResolve() {
707
+ Array.from(keyTrackMap?.entries() ?? []).forEach(([object, { callbacks }]) => {
708
+ const keys = Object.keys(object);
709
+ callbacks.forEach((commit) => commit(keys));
710
+ });
711
+ keyTrackMap = void 0;
712
+ }
713
+
714
+ // src/ComponentInternals.ts
715
+ var ComponentInternals = class {
716
+ constructor(component) {
717
+ this.trackKey = (hostsCandidates, onResolved, defaultValue) => {
718
+ const candidateHosts = Array.isArray(hostsCandidates) ? hostsCandidates : [hostsCandidates];
719
+ let leftToResolve = candidateHosts.length + 1;
720
+ const resolved = (resolution) => {
721
+ leftToResolve -= 1;
722
+ if (resolution !== void 0)
723
+ leftToResolve = 0;
724
+ if (leftToResolve === 0)
725
+ onResolved(resolution);
726
+ };
727
+ candidateHosts.forEach(
728
+ (host) => this.component.manager.trackPropertyKey(
729
+ host,
730
+ (key) => resolved(
731
+ key === void 0 ? void 0 : {
732
+ key,
733
+ host,
734
+ type: "property",
735
+ domValue: void 0
736
+ }
737
+ ),
738
+ defaultValue
739
+ )
740
+ );
741
+ this.component.manager.trackPropKey((key, domValue) => {
742
+ const propType = key === void 0 ? void 0 : getPropType(this.component, key);
743
+ resolved(
744
+ key === void 0 ? void 0 : {
745
+ key,
746
+ host: this.component,
747
+ type: propType ?? "prop",
748
+ domValue: propType === "prop" ? domValue : void 0
749
+ }
750
+ );
751
+ }, defaultValue);
752
+ return defaultValue;
753
+ };
754
+ this.trackPropKey = (onResolved, defaultValue) => {
755
+ if (this._trackedValue !== nothing && this._trackedValue !== defaultValue)
756
+ this._firePropertyTrackers(void 0, void 0, void 0);
757
+ if (this._keyTrackers.length === 0)
758
+ queueMicrotask(() => this._firePropertyTrackers(void 0, void 0, void 0));
759
+ this._trackedValue = defaultValue;
760
+ this._keyTrackers.push(
761
+ (key, value, previousValue) => onResolved(defaultValue === value ? key : void 0, previousValue)
762
+ );
763
+ return defaultValue;
764
+ };
765
+ this._trackedValue = nothing;
766
+ this._keyTrackers = [];
767
+ this.getters = {};
768
+ this.setters = {};
769
+ this._exports = /* @__PURE__ */ new WeakMap();
770
+ Object.defineProperty(this, "component", {
771
+ writable: false,
772
+ enumerable: false,
773
+ configurable: true,
774
+ value: component
775
+ });
776
+ }
777
+ _firePropertyTrackers(key, value, oldValue) {
778
+ const trackers = this._keyTrackers;
779
+ this._trackedValue = nothing;
780
+ this._keyTrackers = [];
781
+ trackers.forEach((tracker) => tracker(key, value, oldValue));
782
+ }
783
+ /**
784
+ * Configure a getter or setter for a given @Prop/@State. Note, since props
785
+ * are defined on the prototype, they are shared between all instances of a
786
+ * component. Thus instead of passing function reference to
787
+ * Object.defineProperty, we use instance-owned getters and setters array.
788
+ */
789
+ getSetProxy(prototype, name, {
790
+ get,
791
+ set
792
+ }, type) {
793
+ const component = this.component;
794
+ const propType = getMemberType(component, name);
795
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
796
+ const tolerateNotFound = type === "html";
797
+ if (descriptor?.set === void 0 || descriptor.get === void 0)
798
+ if (descriptor !== void 0 && "value" in descriptor)
799
+ throw new Error(
800
+ `getSet() should only be used on Stencil's @Prop and @State properties. For internal component properties, use regular get/set syntax. Tried to use it on "${name}" in ${component.el.tagName}`
801
+ );
802
+ else if (tolerateNotFound)
803
+ return;
804
+ else
805
+ throw new Error(`Unable to find "${name}" property on the ${component.el.tagName} component`);
806
+ const { get: originalGet, set: originalSet } = descriptor;
807
+ const isGetterAlreadyOverwritten = customAccessor in originalGet;
808
+ const isSetterAlreadyOverwritten = customAccessor in originalSet;
809
+ const shouldOverwriteGet = !isGetterAlreadyOverwritten && typeof get === "function";
810
+ const shouldOverwriteSet = !isSetterAlreadyOverwritten && typeof set === "function";
811
+ if (!shouldOverwriteGet && !shouldOverwriteSet)
812
+ return;
813
+ const finalGetter = shouldOverwriteGet ? function getter() {
814
+ let value = originalGet.call(this);
815
+ const component2 = Controller.internals.elementToInstance.get(this);
816
+ const getters = component2?.manager.internals.getters[name] ?? [];
817
+ for (let i = 0; i < getters.length; i++)
818
+ value = getters[i](value, name);
819
+ return value;
820
+ } : originalGet;
821
+ const finalSetter = shouldOverwriteSet ? function setter(rawNewValue) {
822
+ if (Controller.internals.shouldBypassSetter) {
823
+ originalSet.call(this, rawNewValue);
824
+ return;
825
+ }
826
+ const oldValue = originalGet.call(this);
827
+ let newValue = parsePropertyValue(rawNewValue, propType);
828
+ const component2 = Controller.internals.elementToInstance.get(this);
829
+ const internals = component2?.manager.internals;
830
+ if (newValue === oldValue)
831
+ originalSet.call(this, rawNewValue);
832
+ else {
833
+ const setters = internals?.setters[name] ?? [];
834
+ for (let i = 0; i < setters.length; i++)
835
+ newValue = setters[i](newValue, oldValue, name);
836
+ originalSet.call(this, newValue);
837
+ }
838
+ if ((internals?._keyTrackers.length ?? 0) > 0)
839
+ internals?._firePropertyTrackers(name, rawNewValue, oldValue);
840
+ } : originalSet;
841
+ if (shouldOverwriteGet)
842
+ Object.defineProperty(finalGetter, customAccessor, { value: true });
843
+ if (shouldOverwriteSet)
844
+ Object.defineProperty(finalSetter, customAccessor, { value: true });
845
+ Object.defineProperty(prototype, name, {
846
+ ...descriptor,
847
+ get: finalGetter,
848
+ set: finalSetter
849
+ });
850
+ }
851
+ /**
852
+ * Associate an exports object with a controller for reverse lookup in
853
+ * controller.use
854
+ */
855
+ markExports(controller, exports) {
856
+ if (typeof exports === "object" && exports !== null || typeof exports === "function")
857
+ this._exports.set(exports, controller);
858
+ }
859
+ resolveExports(exports) {
860
+ if (typeof exports === "object" && exports !== null || typeof exports === "function")
861
+ return this._exports.get(exports);
862
+ else
863
+ return void 0;
864
+ }
865
+ };
866
+ var customAccessor = Symbol("controllersCustomAccessor");
867
+ var nothing = Symbol("nothing");
868
+
869
+ // ../core-adapter/dist/index.js
870
+ var isAMD = typeof window !== "undefined" && "$arcgis" in window && typeof window.$arcgis === "object" && "import" in window.$arcgis;
871
+ function isDefaultModule(module) {
872
+ return module.default !== void 0;
873
+ }
874
+ async function importCoreAccessor() {
875
+ if (isAMD) {
876
+ return await window.$arcgis.import("esri/core/Accessor");
877
+ }
878
+ const module = await import('./Accessor-YDTURKZ7.js');
879
+ return isDefaultModule(module) ? module.default : module;
880
+ }
881
+ async function importCoreAccessorSupportDecorators() {
882
+ if (isAMD) {
883
+ return await window.$arcgis.import("esri/core/accessorSupport/decorators");
884
+ }
885
+ const module = await import('./decorators-443AWDOE.js');
886
+ return isDefaultModule(module) ? module.default : module;
887
+ }
888
+
889
+ // src/accessorIntegration.ts
890
+ var accessorPromise = Promise.all([importCoreAccessor(), importCoreAccessorSupportDecorators()]);
891
+ async function accessorIntegration(component) {
892
+ let accessor = void 0;
893
+ const getSet = {
894
+ get: (value, propertyName) => {
895
+ const accessorValue = accessor?.[propertyName];
896
+ return value ?? accessorValue;
897
+ },
898
+ set: (newValue, oldValue, propertyName) => {
899
+ if (accessor !== void 0)
900
+ accessor[propertyName] = newValue;
901
+ return newValue;
902
+ }
903
+ };
904
+ const members = getPropLikeMembers(component);
905
+ members.forEach((member) => component.manager.genericGetSet(member, getSet));
906
+ const [Accessor, { subclass, property }] = await accessorPromise;
907
+ return () => {
908
+ class AccessorSubclass extends Accessor {
909
+ }
910
+ members.forEach(
911
+ (name) => property({
912
+ value: component[name]
913
+ })(AccessorSubclass.prototype, name)
914
+ );
915
+ const Subclass = subclass(component.el.tagName)(AccessorSubclass);
916
+ accessor = new Subclass();
917
+ };
918
+ }
919
+
920
+ // src/ControllerManager.ts
921
+ var useControllerManager = (component) => new ControllerManager(component);
922
+ var ControllerManager = class extends GenericController {
923
+ constructor(component) {
924
+ const controllers = /* @__PURE__ */ new Set();
925
+ const watchers = {};
926
+ const controllerHost = {
927
+ addController: (controller) => {
928
+ controllers.add(controller);
929
+ },
930
+ [watcherCallbackName]: (newValue, oldValue, propertyName) => {
931
+ watchers[propertyName]?.forEach((callback) => callback(newValue, oldValue, propertyName));
932
+ },
933
+ removeController: (controller) => {
934
+ controllers.delete(controller);
935
+ },
936
+ requestUpdate: () => forceUpdate(component)
937
+ };
938
+ extendObject(component, controllerHost);
939
+ super(component);
940
+ this._connected = new h();
941
+ this.internals = new ComponentInternals(this.component);
942
+ this.connected = this._connected.promise;
943
+ this.hasDestroy = false;
944
+ this.destroyed = false;
945
+ this._updatePromise = new h();
946
+ this._originalLifecycles = {};
947
+ /**
948
+ * A magical solution to finding out what property name a given controller
949
+ * on a given object was assigned to. Note, this does not work for properties
950
+ * that have \@Prop() or \@State() decorator - for those, use
951
+ * manager.trackPropKey() instead.
952
+ *
953
+ * @example
954
+ * function trackMe<T>(defaultValue:T, component:BaseComponent):T {
955
+ * component.manager.trackPropertyKey(component, (key)=>console.log(key), defaultValue);
956
+ * return defaultValue;
957
+ * }
958
+ *
959
+ * class MyComponent extends BaseComponent {
960
+ * // Will console log "myProp"
961
+ * myProp = trackMe('a', this);
962
+ * }
963
+ *
964
+ */
965
+ this.trackPropertyKey = trackPropertyKey;
966
+ /**
967
+ * Like manager.trackPropertyKey(), but for props that have \@State() or \@Prop()
968
+ * decorator
969
+ *
970
+ * @example
971
+ * function trackMe(component:BaseComponent) {
972
+ * component.manager.trackPropKey((key)=>console.log(key));
973
+ * }
974
+ *
975
+ * class MyComponent extends BaseComponent {
976
+ * // Will console log "myProp"
977
+ * @Prop() myProp = trackMe(this);
978
+ *
979
+ * // Will console log "myState"
980
+ * @State() myState = trackMe(this);
981
+ * }
982
+ */
983
+ this.trackPropKey = this.internals.trackPropKey;
984
+ /**
985
+ * A combination of trackPropertyKey() and trackPropKey(). For usage when
986
+ * you want to track a property, but don't know if it will be defined with the
987
+ * \@Prop() decorator or not
988
+ */
989
+ this.trackKey = this.internals.trackKey;
990
+ this.component.manager = this;
991
+ retrieveComponentMeta(component);
992
+ this._controllers = controllers;
993
+ this.internals.watchers = watchers;
994
+ this.exports = void 0;
995
+ this.hasDestroy = "preserveOnDisconnect" in this.component && typeof this.component.destroy === "function";
996
+ if (this.hasDestroy)
997
+ this.watch("preserveOnDisconnect", () => this._preserveOnDisconnectWatcher());
998
+ this._bindLifecycleMethods();
999
+ Object.defineProperty(component, "updateComplete", {
1000
+ get: async () => await this._updatePromise.promise
1001
+ });
1002
+ this.component.addController(this);
1003
+ this._accessorIntegrationReady = accessorIntegration(this.component);
1004
+ Controller.internals.setParentController(void 0);
1005
+ Controller.internals.setAmbientComponent(component);
1006
+ Controller.internals.elementToInstance.set(component.el, component);
1007
+ Controller.internals.elementToInstance.set(component, component);
1008
+ }
1009
+ _bindLifecycleMethods() {
1010
+ const component = this.component;
1011
+ this._originalLifecycles = {
1012
+ connectedCallback: component.connectedCallback,
1013
+ disconnectedCallback: component.disconnectedCallback,
1014
+ componentWillLoad: component.componentWillLoad,
1015
+ componentDidLoad: component.componentDidLoad,
1016
+ componentWillRender: component.componentWillRender,
1017
+ componentDidRender: component.componentDidRender,
1018
+ componentWillUpdate: component.componentWillUpdate,
1019
+ componentDidUpdate: component.componentDidUpdate,
1020
+ destroy: component.destroy
1021
+ };
1022
+ component.connectedCallback = this._connectedCallback.bind(this);
1023
+ component.disconnectedCallback = this._disconnectedCallback.bind(this);
1024
+ component.componentWillLoad = this._componentWillLoad.bind(this);
1025
+ component.componentDidLoad = this._componentDidLoad.bind(this);
1026
+ component.componentWillRender = this._componentWillRender.bind(this);
1027
+ component.componentDidRender = this._componentDidRender.bind(this);
1028
+ component.componentWillUpdate = this._componentWillUpdate.bind(this);
1029
+ component.componentDidUpdate = this._componentDidUpdate.bind(this);
1030
+ if (this.hasDestroy)
1031
+ component.destroy = this.destroy.bind(this);
1032
+ }
1033
+ /**
1034
+ * Throws an error if component does not implement destroy() lifecycle, but
1035
+ * tries to use it.
1036
+ */
1037
+ ensureHasDestroy() {
1038
+ if (!this.hasDestroy)
1039
+ throw new Error(destroyErrorMessage);
1040
+ }
1041
+ /**
1042
+ * Private because this is not supposed to be called by Component directly.
1043
+ * Instead, _bindLifecycleMethods will take care of that. Otherwise, you risk
1044
+ * calling lifecycle methods twice.
1045
+ */
1046
+ _connectedCallback() {
1047
+ if (this.destroyed) {
1048
+ const tagName = this.component.el.tagName.toLowerCase();
1049
+ this.component.el.remove();
1050
+ throw new Error(
1051
+ `The ${tagName} component has already been destroyed. It can not be used again. If you meant to disconnect and reconnect a component without automatic destroy, set the preserveOnDisconnect prop.`
1052
+ );
1053
+ }
1054
+ keyTrackResolve();
1055
+ this._connected.resolve();
1056
+ this._controllers.forEach(
1057
+ (controller) => "triggerConnected" in controller ? controller.triggerConnected() : safeCall(() => controller.hostConnected?.())
1058
+ );
1059
+ this._originalLifecycles.connectedCallback?.call(this.component);
1060
+ }
1061
+ _disconnectedCallback() {
1062
+ if (this.destroyed)
1063
+ return;
1064
+ this._controllers.forEach(
1065
+ (controller) => "triggerDisconnected" in controller ? controller.triggerDisconnected() : safeCall(() => controller.hostDisconnected?.())
1066
+ );
1067
+ this._originalLifecycles.disconnectedCallback?.call(this.component);
1068
+ if (this.hasDestroy)
1069
+ this._preserveOnDisconnectWatcher();
1070
+ }
1071
+ async _componentWillLoad() {
1072
+ const enableIntegration = await this._accessorIntegrationReady;
1073
+ enableIntegration();
1074
+ await Promise.allSettled(
1075
+ Array.from(
1076
+ this._controllers,
1077
+ async (controller) => "triggerLoad" in controller ? await controller.triggerLoad() : await safeAsyncCall(async () => await controller.hostLoad?.())
1078
+ )
1079
+ );
1080
+ await this._originalLifecycles.componentWillLoad?.call(this.component);
1081
+ }
1082
+ _componentDidLoad() {
1083
+ this._controllers.forEach(
1084
+ (controller) => "triggerLoaded" in controller ? controller.triggerLoaded() : safeCall(() => controller.hostLoaded?.())
1085
+ );
1086
+ this._originalLifecycles.componentDidLoad?.call(this.component);
1087
+ }
1088
+ async _componentWillRender() {
1089
+ await Promise.allSettled(
1090
+ Array.from(
1091
+ this._controllers,
1092
+ async (controller) => "triggerRender" in controller ? await controller.triggerRender() : await safeAsyncCall(async () => await controller.hostRender?.())
1093
+ )
1094
+ );
1095
+ await this._originalLifecycles.componentWillRender?.call(this.component);
1096
+ }
1097
+ _componentDidRender() {
1098
+ this._controllers.forEach(
1099
+ (controller) => "triggerRendered" in controller ? controller.triggerRendered() : safeCall(() => controller.hostRendered?.())
1100
+ );
1101
+ this._originalLifecycles.componentDidRender?.call(this.component);
1102
+ }
1103
+ async _componentWillUpdate() {
1104
+ await Promise.allSettled(
1105
+ Array.from(
1106
+ this._controllers,
1107
+ async (controller) => "triggerUpdate" in controller ? await controller.triggerUpdate() : await safeAsyncCall(async () => await controller.hostUpdate?.())
1108
+ )
1109
+ );
1110
+ await this._originalLifecycles.componentWillUpdate?.call(this.component);
1111
+ }
1112
+ _componentDidUpdate() {
1113
+ this._controllers.forEach(
1114
+ (controller) => "triggerUpdated" in controller ? controller.triggerUpdated() : safeCall(() => controller.hostUpdated?.())
1115
+ );
1116
+ this._originalLifecycles.componentDidUpdate?.call(this.component);
1117
+ const updatePromise = this._updatePromise;
1118
+ this._updatePromise = new h();
1119
+ updatePromise.resolve(true);
1120
+ }
1121
+ async destroy() {
1122
+ this.ensureHasDestroy();
1123
+ if (this.destroyed)
1124
+ return;
1125
+ if (this.component.el.isConnected) {
1126
+ this.hasDestroy = false;
1127
+ this.component.el.remove();
1128
+ this.hasDestroy = true;
1129
+ }
1130
+ this.destroyed = true;
1131
+ this._controllers.forEach(
1132
+ (controller) => "triggerDestroy" in controller ? controller.triggerDestroy() : safeCall(() => controller.hostDestroy?.())
1133
+ );
1134
+ await this._originalLifecycles.destroy?.call(this.component);
1135
+ }
1136
+ _preserveOnDisconnectWatcher() {
1137
+ if (!this.component.el.isConnected && !this.component.preserveOnDisconnect)
1138
+ void this.destroy().catch(console.error);
1139
+ }
1140
+ readonly(value) {
1141
+ return this.getSet(value, {
1142
+ set: (newValue, _oldValue, property) => {
1143
+ throw new Error(
1144
+ `Cannot assign to read-only property "${property}" of ${this.component.el.tagName.toLowerCase()}. Trying to assign "${String(
1145
+ newValue
1146
+ )}"`
1147
+ );
1148
+ }
1149
+ });
1150
+ }
1151
+ /**
1152
+ * Listen for any component's @State()/@Prop() change, and mutate it's
1153
+ * value before it is set.
1154
+ * This is necessary because Stencil's Compiler does not support get/set for
1155
+ * @State()/@Prop().
1156
+ * For private component properties, you should use regular get/set syntax.
1157
+ *
1158
+ * @example
1159
+ * @Prop() exampleProp = this.manager.getSet(defaultValue,{get,set})
1160
+ * @Prop() someProp = this.manager.getSet(
1161
+ * undefined as string | undefined,
1162
+ * {
1163
+ * get: (value)=>value.trim(),
1164
+ * set: (newValue,oldValue) => newValue.trim() ?? oldValue
1165
+ * }
1166
+ * )
1167
+ *
1168
+ * @remarks
1169
+ * Unlike a native get/set, the get function receives the current attribute
1170
+ * value, and can modify it before returning it (or can disregard the current
1171
+ * value and get it from elsewhere instead).
1172
+ * Similarly, setter is called with the new and old value, and is expected to
1173
+ * return the final new value (or return the old value to undo the change)
1174
+ */
1175
+ getSet(defaultValue, getSet) {
1176
+ return this.component.manager.trackPropKey((name) => {
1177
+ if (name === void 0)
1178
+ throw new Error(
1179
+ "Unable to resolve get/set's prop name. Make sure you are using it like @Prop() someProp = this.manager.getSet(defaultValue,{get,set})"
1180
+ );
1181
+ const genericComponent = this.component;
1182
+ const value = genericComponent[name];
1183
+ if (value != null && value !== defaultValue && typeof getSet.set === "function" && getSet.initialSet !== false) {
1184
+ const newValue = getSet.set(value, defaultValue, name);
1185
+ if (newValue !== value)
1186
+ genericComponent[name] = newValue;
1187
+ }
1188
+ this.genericGetSet(name, getSet);
1189
+ }, defaultValue);
1190
+ }
1191
+ };
1192
+ var destroyErrorMessage = `
1193
+ If the component uses a controller that uses destroy() method, then the
1194
+ component must have the following properties:
1195
+ ${// Don't expose internal code in production, and keep bundle smaller:
1196
+ `preserveOnDisconnect and destroy` }
1197
+ `.trim();
1198
+
1199
+ // src/proxyExports.ts
1200
+ var proxyExports = (Class) => (...args) => {
1201
+ const ambientControllers = Controller.internals.retriveParentControllers();
1202
+ const instance = new Class(...args);
1203
+ const initialExports = instance.exports;
1204
+ Controller.internals.setParentController(ambientControllers.at(-1));
1205
+ const internals = instance.component.manager.internals;
1206
+ internals.markExports(instance, initialExports);
1207
+ instance.watchExports((exports) => internals.markExports(instance, exports));
1208
+ Controller.internals.setAmbientChildController(instance);
1209
+ const hostCandidates = [instance.component, ...ambientControllers].reverse();
1210
+ return internals.trackKey(
1211
+ hostCandidates,
1212
+ (resolution) => resolution === void 0 ? void 0 : setProxy(instance, resolution.host, resolution.key, initialExports),
1213
+ initialExports
1214
+ );
1215
+ };
1216
+ function setProxy(controller, host, key, initialExports) {
1217
+ const genericHost = host;
1218
+ const controllerValueChanged = genericHost[key] !== controller.exports;
1219
+ const hostValueChanged = genericHost[key] !== initialExports;
1220
+ const controllerUpdatedExports = initialExports !== controller.exports;
1221
+ if (controllerValueChanged && !hostValueChanged && controllerUpdatedExports)
1222
+ genericHost[key] = controller.exports;
1223
+ controller.watchExports(() => {
1224
+ if (genericHost[key] !== controller.exports)
1225
+ genericHost[key] = controller.exports;
1226
+ });
1227
+ }
1228
+
1229
+ // src/functional.ts
1230
+ var makeController = (constructor) => proxy(void 0, constructor);
1231
+ var FunctionalController = class extends Controller {
1232
+ constructor(component, constructor) {
1233
+ super(component);
1234
+ const originalExports = this.exports;
1235
+ try {
1236
+ Controller.internals.setAmbientComponent(this.component);
1237
+ const value = constructor(this.component, this);
1238
+ const constructorChangedExports = this.exports !== originalExports;
1239
+ if (value instanceof Promise) {
1240
+ if (!constructorChangedExports)
1241
+ this.setProvisionalExports(value);
1242
+ const resolved = value.then((result) => {
1243
+ this.exports = result;
1244
+ super.catchUpLifecycle();
1245
+ }).catch((error) => {
1246
+ this._ready.reject(error);
1247
+ console.error(error);
1248
+ });
1249
+ this.onLoad(async () => await resolved);
1250
+ } else {
1251
+ if (!constructorChangedExports || value !== void 0)
1252
+ this.exports = value;
1253
+ super.catchUpLifecycle();
1254
+ }
1255
+ } catch (error) {
1256
+ this._ready.reject(error);
1257
+ console.error(error);
1258
+ }
1259
+ }
1260
+ /** Noop - will be called in the constructor instead */
1261
+ catchUpLifecycle() {
1262
+ return;
1263
+ }
1264
+ };
1265
+ var proxy = proxyExports(FunctionalController);
1266
+ function useT9n({
1267
+ blocking = false,
1268
+ name
1269
+ } = {}) {
1270
+ return makeController((component, controller) => {
1271
+ controller.onLifecycle(
1272
+ () => Y(
1273
+ component.el,
1274
+ getAssetPath("./assets"),
1275
+ ({ t9nLocale, t9nStrings, lang }) => {
1276
+ controller.exports = { ...t9nStrings, _lang: lang, _t9nLocale: t9nLocale };
1277
+ if (typeof t9nStrings.widgetLabel === "string" && "label" in component)
1278
+ component.label ?? (component.label = t9nStrings.widgetLabel);
1279
+ },
1280
+ name
1281
+ )
1282
+ );
1283
+ if (blocking)
1284
+ return controller.ready;
1285
+ const locale = M(component.el);
1286
+ return { _lang: locale.lang, _t9nLocale: locale.t9nLocale };
1287
+ });
1288
+ }
1289
+
1290
+ export { useT9n as a, useControllerManager as u };