@arcgis/coding-components 4.31.0-next.2 → 4.31.0-next.21

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 (205) hide show
  1. package/README.md +22 -3
  2. package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +2 -2
  3. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ar.json +1 -1
  4. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.bg.json +1 -1
  5. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.bs.json +1 -1
  6. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ca.json +6 -6
  7. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.cs.json +1 -1
  8. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.da.json +1 -1
  9. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.de.json +1 -1
  10. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.el.json +1 -1
  11. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.es.json +1 -1
  12. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.et.json +1 -1
  13. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.fi.json +1 -1
  14. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.fr.json +1 -1
  15. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.he.json +1 -1
  16. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.hr.json +1 -1
  17. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.id.json +1 -1
  18. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.it.json +1 -1
  19. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ko.json +1 -1
  20. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.nb.json +1 -1
  21. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.nl.json +1 -1
  22. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pl.json +1 -1
  23. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pt-BR.json +1 -1
  24. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.pt-PT.json +1 -1
  25. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.ru.json +1 -1
  26. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sk.json +1 -1
  27. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sl.json +1 -1
  28. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sr.json +1 -1
  29. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.sv.json +1 -1
  30. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.th.json +1 -1
  31. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.tr.json +1 -1
  32. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.uk.json +5 -5
  33. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.vi.json +1 -1
  34. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-CN.json +1 -1
  35. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-HK.json +1 -1
  36. package/dist/arcgis-coding-components/assets/arcade-language/t9n/profile.t9n.zh-TW.json +1 -1
  37. package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.ca.json +2 -2
  38. package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.de.json +1 -1
  39. package/dist/arcgis-coding-components/assets/arcade-results/t9n/arcade-results.t9n.he.json +1 -1
  40. package/dist/arcgis-coding-components/assets/arcade-variables/t9n/arcade-variables.t9n.ca.json +1 -1
  41. package/dist/arcgis-coding-components/assets/arcade-variables/t9n/arcade-variables.t9n.it.json +1 -1
  42. package/dist/arcgis-coding-components/assets/code-editor/css.worker.js +1 -1
  43. package/dist/arcgis-coding-components/assets/code-editor/html.worker.js +1 -1
  44. package/dist/arcgis-coding-components/assets/code-editor/json.worker.js +1 -1
  45. package/dist/arcgis-coding-components/assets/code-editor/sql-expr.worker.js +33 -0
  46. package/dist/arcgis-coding-components/assets/code-editor/ts.worker.js +1 -1
  47. package/dist/arcgis-coding-components/assets/language-api-panel/t9n/language-api-panel.t9n.ca.json +1 -1
  48. package/dist/arcgis-coding-components/assets/sql-expression-editor/api/sql-expression-api.t9n.en.json +735 -0
  49. package/dist/arcgis-coding-components/index.esm.js +2 -2
  50. package/dist/arcgis-coding-components/{p-7984ea8e.js → p-1b799777.js} +2 -2
  51. package/dist/arcgis-coding-components/p-4d5cf512.entry.js +6 -0
  52. package/dist/arcgis-coding-components/{p-60c2a820.js → p-56266a64.js} +2 -2
  53. package/dist/arcgis-coding-components/{p-e8211ffe.js → p-57b8bcd7.js} +1 -1
  54. package/dist/arcgis-coding-components/{p-9eced6fc.js → p-5b67b62b.js} +2 -2
  55. package/dist/arcgis-coding-components/{p-93a97573.js → p-64137fec.js} +3 -3
  56. package/dist/arcgis-coding-components/{p-e7ee4d64.js → p-6621a80f.js} +3 -3
  57. package/dist/arcgis-coding-components/p-77dd5521.js +6 -0
  58. package/dist/arcgis-coding-components/p-8eb7e694.js +6 -0
  59. package/dist/arcgis-coding-components/p-a2341e0c.js +6 -0
  60. package/dist/arcgis-coding-components/{p-bb7e832e.js → p-b715834b.js} +3 -3
  61. package/dist/arcgis-coding-components/p-cbee273f.js +6 -0
  62. package/dist/arcgis-coding-components/{p-5ef7cce5.js → p-cdc52d2f.js} +1 -1
  63. package/dist/arcgis-coding-components/{p-36fedc23.js → p-d7d1f130.js} +12 -12
  64. package/dist/arcgis-coding-components/p-e1f9b463.entry.js +6 -0
  65. package/dist/arcgis-coding-components/{p-62ee6251.js → p-e5a924a1.js} +1 -1
  66. package/dist/arcgis-coding-components/p-f2d64a9d.js +6 -0
  67. package/dist/arcgis-coding-components/{p-03ea6cd7.js → p-ff62d134.js} +3 -3
  68. package/dist/arcgis-coding-components/p-ffce0588.entry.js +6 -0
  69. package/dist/cjs/{app-globals-aee5f4b5.js → app-globals-a9ef3ca8.js} +1 -1
  70. package/dist/cjs/arcade-defaults-f5241680.js +349 -0
  71. package/dist/cjs/arcade-language-features-0b9f3947.js +274 -0
  72. package/dist/cjs/arcade-mode-cc08d9cd.js +335 -0
  73. package/dist/cjs/arcgis-arcade-editor_6.cjs.entry.js +181 -1501
  74. package/dist/cjs/arcgis-coding-components.cjs.js +4 -4
  75. package/dist/cjs/arcgis-sql-expression-editor.cjs.entry.js +81 -0
  76. package/dist/cjs/arcgis-sql-expression-fields.cjs.entry.js +80 -0
  77. package/dist/cjs/{css-7cc05f76.js → css-bb6a49ec.js} +1 -1
  78. package/dist/cjs/{cssMode-2b0daeae.js → cssMode-e7fac7d7.js} +3 -4
  79. package/dist/cjs/{html-f56911e1.js → html-7ff4071d.js} +3 -4
  80. package/dist/cjs/{htmlMode-43eed674.js → htmlMode-c89193ec.js} +3 -4
  81. package/dist/cjs/{index-b34238a6.js → index-4b7880ab.js} +9 -1
  82. package/dist/cjs/index.cjs.js +4 -3
  83. package/dist/cjs/{javascript-5115cb76.js → javascript-864c0220.js} +3 -4
  84. package/dist/cjs/{jsonMode-550dda36.js → jsonMode-ac4a7be7.js} +3 -4
  85. package/dist/cjs/{arcade-defaults-a8d8f8e2.js → language-defaults-base-57b37f9f.js} +842 -1183
  86. package/dist/cjs/loader.cjs.js +4 -4
  87. package/dist/cjs/sql-expr-defaults-245b036d.js +1347 -0
  88. package/dist/cjs/sql-expr-mode-304f5ce2.js +20844 -0
  89. package/dist/cjs/{tsMode-336306a9.js → tsMode-d30d4ab1.js} +4 -5
  90. package/dist/cjs/{typescript-b395242f.js → typescript-6c87ddb3.js} +3 -4
  91. package/dist/components/arcade-defaults.js +54 -1369
  92. package/dist/components/arcade-language-features.js +271 -0
  93. package/dist/components/arcade-mode.js +4 -264
  94. package/dist/components/arcade-results.js +7 -5
  95. package/dist/components/arcade-suggestions.js +7 -5
  96. package/dist/components/arcade-variables.js +8 -6
  97. package/dist/components/arcgis-arcade-editor.js +37 -35
  98. package/dist/components/arcgis-arcade-results.js +1 -1
  99. package/dist/components/arcgis-arcade-suggestions.js +1 -1
  100. package/dist/components/arcgis-arcade-variables.js +1 -1
  101. package/dist/components/arcgis-assets.d.ts +1 -1
  102. package/dist/components/arcgis-assets.js +1 -1
  103. package/dist/components/arcgis-code-editor.js +1 -1
  104. package/dist/components/arcgis-language-api-panel.js +1 -1
  105. package/dist/components/arcgis-sql-expression-editor.d.ts +11 -0
  106. package/dist/components/arcgis-sql-expression-editor.js +120 -0
  107. package/dist/components/arcgis-sql-expression-fields.d.ts +11 -0
  108. package/dist/components/arcgis-sql-expression-fields.js +11 -0
  109. package/dist/components/chunk-2JTWBRMN.js +1154 -0
  110. package/dist/components/code-editor.js +40 -13
  111. package/dist/components/fields.js +5 -5
  112. package/dist/components/index.js +1 -1
  113. package/dist/components/index2.js +30 -22
  114. package/dist/components/language-api-panel.js +13 -40
  115. package/dist/components/language-defaults-base.js +1309 -0
  116. package/dist/components/markdown.js +1 -1
  117. package/dist/components/sql-expr-defaults.js +196 -0
  118. package/dist/components/sql-expr-mode.js +20842 -0
  119. package/dist/components/sql-expression-fields.js +102 -0
  120. package/dist/components/useT9n.js +45 -8
  121. package/dist/components/utilities.js +1 -1
  122. package/dist/esm/{app-globals-59faaf33.js → app-globals-6d0ca11d.js} +1 -1
  123. package/dist/esm/arcade-defaults-066445c4.js +344 -0
  124. package/dist/esm/arcade-language-features-0e00c199.js +269 -0
  125. package/dist/esm/{arcade-mode-5d46035e.js → arcade-mode-abf1e1cf.js} +3 -263
  126. package/dist/esm/arcgis-arcade-editor_6.entry.js +127 -1447
  127. package/dist/esm/arcgis-coding-components.js +5 -5
  128. package/dist/esm/arcgis-sql-expression-editor.entry.js +77 -0
  129. package/dist/esm/arcgis-sql-expression-fields.entry.js +76 -0
  130. package/dist/esm/{css-e257dc49.js → css-c6dae12d.js} +1 -1
  131. package/dist/esm/{cssMode-c11f7f40.js → cssMode-052bb603.js} +2 -3
  132. package/dist/esm/{html-a6c37a99.js → html-572696a1.js} +2 -3
  133. package/dist/esm/{htmlMode-1270bc7d.js → htmlMode-fc184f2d.js} +2 -3
  134. package/dist/esm/{index-a970952c.js → index-0edd9846.js} +9 -1
  135. package/dist/esm/index.js +4 -3
  136. package/dist/esm/{javascript-ee179624.js → javascript-8bfc0096.js} +3 -4
  137. package/dist/esm/{jsonMode-07502ccb.js → jsonMode-7adf94ff.js} +2 -3
  138. package/dist/esm/{arcade-defaults-9eb28407.js → language-defaults-base-85a7f476.js} +833 -1179
  139. package/dist/esm/loader.js +5 -5
  140. package/dist/esm/sql-expr-defaults-be84ec7f.js +1339 -0
  141. package/dist/esm/sql-expr-mode-a4413e5c.js +20840 -0
  142. package/dist/esm/{tsMode-96749a12.js → tsMode-d10773c8.js} +2 -3
  143. package/dist/esm/{typescript-a3cf9881.js → typescript-9491f23e.js} +2 -3
  144. package/dist/loader/cdn.js +1 -1
  145. package/dist/loader/index.cjs.js +1 -1
  146. package/dist/loader/index.es2017.js +1 -1
  147. package/dist/loader/index.js +1 -1
  148. package/dist/types/components/arcade-editor/arcade-editor.d.ts +45 -10
  149. package/dist/types/components/arcade-results/arcade-results.d.ts +43 -1
  150. package/dist/types/components/arcade-suggestions/arcade-suggestions.d.ts +22 -1
  151. package/dist/types/components/arcade-variables/arcade-variables.d.ts +28 -1
  152. package/dist/types/components/code-editor/code-editor.d.ts +16 -5
  153. package/dist/types/components/language-api-panel/language-api-panel.d.ts +34 -8
  154. package/dist/types/components/sql-expression-editor/sql-expression-editor.d.ts +24 -0
  155. package/dist/types/components/sql-expression-fields/sql-expression-fields.d.ts +32 -0
  156. package/dist/types/components.d.ts +98 -24
  157. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/arcade-editor.stories.d.ts +8 -1
  158. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/arcade-editor/editorContext.d.ts +5 -1
  159. package/dist/types/data/actions-runner-1/_work/arcgis-web-components/arcgis-web-components/packages/coding-packages/coding-components/.stencil/stories/internal/sql-expression-editor/sql-expression-editor.stories.d.ts +13 -0
  160. package/dist/types/dependencies.d.ts +6 -10
  161. package/dist/types/utils/arcade-monaco/arcade-language-features.d.ts +1 -0
  162. package/dist/types/utils/arcade-monaco/arcade-profile-strategy.d.ts +9 -0
  163. package/dist/types/utils/fields.d.ts +2 -2
  164. package/dist/types/utils/language-defaults-base.d.ts +2 -9
  165. package/dist/types/utils/profile/editor-profile.d.ts +7 -6
  166. package/dist/types/utils/profile/types.d.ts +53 -65
  167. package/dist/types/utils/profile/utils.d.ts +9 -8
  168. package/dist/types/utils/sql-expr-monaco/DependentFiles/DateOnly.d.ts +41 -0
  169. package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlInterval.d.ts +16 -0
  170. package/dist/types/utils/sql-expr-monaco/DependentFiles/SqlTimestampOffset.d.ts +26 -0
  171. package/dist/types/utils/sql-expr-monaco/DependentFiles/TimeOnly.d.ts +37 -0
  172. package/dist/types/utils/sql-expr-monaco/DependentFiles/UnknownTimeZone.d.ts +11 -0
  173. package/dist/types/utils/sql-expr-monaco/DependentFiles/WhereGrammar.d.ts +122 -0
  174. package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlCompareUtils.d.ts +5 -0
  175. package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlDateParsingUtils.d.ts +18 -0
  176. package/dist/types/utils/sql-expr-monaco/DependentFiles/sqlUtils.d.ts +6 -0
  177. package/dist/types/utils/sql-expr-monaco/DependentFiles/standardizedFunctions.d.ts +156 -0
  178. package/dist/types/utils/sql-expr-monaco/DependentFiles/support.d.ts +150 -0
  179. package/dist/types/utils/sql-expr-monaco/PeggyGrammar/sql92grammar.d.ts +1397 -0
  180. package/dist/types/utils/sql-expr-monaco/sql-expr-completion.d.ts +6 -0
  181. package/dist/types/utils/sql-expr-monaco/sql-expr-constants.d.ts +45 -0
  182. package/dist/types/utils/sql-expr-monaco/sql-expr-contribution.d.ts +1 -0
  183. package/dist/types/utils/sql-expr-monaco/sql-expr-defaults.d.ts +21 -0
  184. package/dist/types/utils/sql-expr-monaco/sql-expr-language-features.d.ts +39 -0
  185. package/dist/types/utils/sql-expr-monaco/sql-expr-language-syntax.d.ts +8 -0
  186. package/dist/types/utils/sql-expr-monaco/sql-expr-mode.d.ts +43 -0
  187. package/dist/types/utils/sql-expr-monaco/sql-expr-service-accessors.d.ts +19 -0
  188. package/dist/types/utils/sql-expr-monaco/sql-expr-validation-diagnostic-adapter.d.ts +34 -0
  189. package/dist/types/utils/sql-expr-monaco/sql-expr-validation-utils.d.ts +100 -0
  190. package/dist/types/utils/sql-expr-monaco/sql-expr-validation.d.ts +41 -0
  191. package/dist/types/utils/sql-expr-monaco/sql-expr-worker-manager.d.ts +17 -0
  192. package/dist/types/utils/sql-expr-monaco/sql-expr.worker.d.ts +24 -0
  193. package/dist/types/utils/sql-expr-monaco/sql-expression-profile-strategy.d.ts +13 -0
  194. package/dist/types/utils/sql-expr-monaco/types.d.ts +89 -0
  195. package/package.json +27 -21
  196. package/dist/arcgis-coding-components/p-0c6de9b3.js +0 -6
  197. package/dist/arcgis-coding-components/p-81c37dab.entry.js +0 -6
  198. package/dist/cjs/arcade-mode-b85ae7d4.js +0 -595
  199. package/dist/components/chunk-IHYYRFLQ.js +0 -1363
  200. package/dist/types/components/arcade-editor/t9n-types.d.ts +0 -8
  201. package/dist/types/components/arcade-results/t9n-types.d.ts +0 -13
  202. package/dist/types/components/arcade-suggestions/t9n-types.d.ts +0 -6
  203. package/dist/types/components/arcade-variables/t9n-types.d.ts +0 -8
  204. package/dist/types/components/language-api-panel/t9n-types.d.ts +0 -8
  205. package/dist/types/utils/profile/predefined-profile.d.ts +0 -2
@@ -0,0 +1,1339 @@
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.21
5
+ */
6
+ import { F as isNotUndefined, D as Deferred, G as safeAsyncCall, H as devToolsAwareTimeout, J as safeCall, f as fieldsToProfileValues, i as isPredefinedProfile, b as isFeatureSetDefinition, m as main, L as LanguageDefaultsBase, d as fetchT9nStringsBundle, E as EditorProfile, U as Uri } from './language-defaults-base-85a7f476.js';
7
+ import { g as getAssetPath } from './index-0edd9846.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 */ : descriptor.type === Number ? 2 /* Number */ : descriptor.type === Boolean ? 4 /* Boolean */ : 1 /* String */)
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.willLoadCalled = false;
166
+ this.didLoadCalled = 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.willLoadCalled;
199
+ if (loadWillStillHappen) {
200
+ return;
201
+ }
202
+ this.triggerLoad().then(() => {
203
+ const loadedWillStillHappen = !manager.didLoadCalled;
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.willLoadCalled) {
346
+ return;
347
+ }
348
+ this.willLoadCalled = 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.didLoadCalled) {
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.didLoadCalled = 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 proxy2 = new Proxy(base, {
424
+ get(target, prop, receiver) {
425
+ if (cyclical.has(prop) && prop in target && target[prop] === proxy2) {
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 proxy2;
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, set then into `allWatchers`. When watchers are read
505
+ * in the setter, read from `enabledWatchers`.
506
+ * On connectedCallback(), controller manager does `enabledWatchers=allWatchers`.
507
+ * Reasoning:
508
+ * - This disables watchers until connected callback (matches behavior of
509
+ * Stencil's watchers)
510
+ * - This removes in the setter to check if watchers were enabled already or
511
+ * not (as getters/setters are hot path, and should be streamlined)
512
+ */
513
+ this.enabledWatchers = {};
514
+ this.allWatchers = {};
515
+ /**
516
+ * "readOnly" is not enabled initially since we need to allow to set property
517
+ * default values in the constructor.
518
+ * For Stencil, readonly is enabled by the `readonly()` controller.
519
+ * For Lit, we have the following logic:
520
+ */
521
+ this.enableReadonly = () => {
522
+ this.enableReadonly = void 0;
523
+ if (!this.component.manager.isLit) {
524
+ return;
525
+ }
526
+ const internals = this.component.manager.internals;
527
+ Object.entries(internals.members).forEach(([name2, [type]]) => {
528
+ var _a2;
529
+ const isReadOnly = type & 2048 /* ReadOnly */;
530
+ if (isReadOnly) {
531
+ (_a2 = internals.setters)[name2] ?? (_a2[name2] = []);
532
+ internals.setters[name2].push(internals.readonlySetter);
533
+ }
534
+ });
535
+ };
536
+ this.trackedValue = nothing;
537
+ this.keyTrackers = [];
538
+ this.getters = {};
539
+ this.setters = {};
540
+ this.accessorGetter = {};
541
+ this.accessorSetter = {};
542
+ this.reactiveUtilsIntegrations = /* @__PURE__ */ new Set();
543
+ this._exports = /* @__PURE__ */ new WeakMap();
544
+ this.readonlySetter = (newValue, _oldValue, property) => {
545
+ if (shouldBypass.readOnly) {
546
+ return newValue;
547
+ }
548
+ throw new Error(
549
+ `Cannot assign to read-only property "${property}" of ${this.component.el.tagName.toLowerCase()}. Trying to assign "${String(
550
+ newValue
551
+ )}"`
552
+ );
553
+ };
554
+ {
555
+ this.component = component;
556
+ }
557
+ }
558
+ firePropTrackers(key, value) {
559
+ const trackers = this.keyTrackers;
560
+ this.trackedValue = nothing;
561
+ this.keyTrackers = [];
562
+ trackers.forEach((tracker) => tracker(key, value));
563
+ }
564
+ // REFACTOR: once Stencil is no longer supported, simplify this with Lit's getPropertyDescriptor(), or https://github.com/shoelace-style/shoelace/issues/1990
565
+ /**
566
+ * Configure a getter or setter for a given \@Prop/\@State
567
+ *
568
+ * Note, since props are defined on the prototype, they are shared between all
569
+ * instances of a component. Thus, instead of passing a reference to the
570
+ * getter/setter function, you should update the
571
+ * ComponentInternals.getters/setters properties, and then call getSetProxy
572
+ * to apply the changes to the prototype
573
+ */
574
+ getSetProxy(property) {
575
+ const component = this.component;
576
+ const classPrototype = component.constructor.prototype;
577
+ this._getSetProxy(classPrototype, property, "class");
578
+ if (component.manager.isLit) {
579
+ return;
580
+ }
581
+ const htmlPrototype = component.el.constructor.prototype;
582
+ if (classPrototype !== htmlPrototype) {
583
+ this._getSetProxy(htmlPrototype, property, "html");
584
+ }
585
+ }
586
+ _getSetProxy(prototype, name2, type) {
587
+ const component = this.component;
588
+ const propType = getMemberType(component, name2);
589
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name2);
590
+ if (!descriptor) {
591
+ return void 0;
592
+ }
593
+ const originalGet = descriptor.get;
594
+ const originalSet = descriptor.set;
595
+ const isGetterAlreadyOverwritten = customAccessor in originalGet;
596
+ const isSetterAlreadyOverwritten = customAccessor in originalSet;
597
+ const shouldOverwriteGet = !isGetterAlreadyOverwritten;
598
+ const shouldOverwriteSet = !isSetterAlreadyOverwritten;
599
+ if (!shouldOverwriteGet && !shouldOverwriteSet) {
600
+ return;
601
+ }
602
+ const finalGetter = shouldOverwriteGet ? function getter() {
603
+ let value = originalGet.call(this);
604
+ const component2 = elementToInstance.get(this);
605
+ if (component2 === void 0) {
606
+ return value;
607
+ }
608
+ const internals = component2.manager.internals;
609
+ value = internals.accessorGetter[name2](value, name2);
610
+ const getters = internals.getters[name2] ?? emptyArray;
611
+ for (let i = 0; i < getters.length; i++) {
612
+ value = getters[i](value, name2);
613
+ }
614
+ return value;
615
+ } : originalGet;
616
+ const finalSetter = shouldOverwriteSet ? function setter(rawNewValue) {
617
+ const oldValue = originalGet.call(this);
618
+ const component2 = elementToInstance.get(this);
619
+ if (component2 === void 0) {
620
+ originalSet.call(this, rawNewValue);
621
+ return;
622
+ }
623
+ let newValue = component2.manager.isLit ? rawNewValue : parsePropertyValue(rawNewValue, propType);
624
+ const internals = component2.manager.internals;
625
+ if (newValue === oldValue) {
626
+ originalSet.call(this, rawNewValue);
627
+ } else {
628
+ const setters = shouldBypass.setter ? emptyArray : internals.setters[name2] ?? emptyArray;
629
+ for (let i = 0; i < setters.length; i++) {
630
+ newValue = setters[i](newValue, oldValue, name2);
631
+ if (newValue === oldValue) {
632
+ break;
633
+ }
634
+ }
635
+ newValue = internals.accessorSetter[name2](newValue, oldValue, name2);
636
+ originalSet.call(this, newValue);
637
+ if (newValue !== oldValue) {
638
+ internals.enabledWatchers[name2]?.forEach((watcher) => watcher(newValue, oldValue, name2));
639
+ }
640
+ }
641
+ if (internals.keyTrackers.length > 0) {
642
+ internals?.firePropTrackers(name2, rawNewValue);
643
+ }
644
+ } : originalSet;
645
+ if (shouldOverwriteGet) {
646
+ finalGetter[customAccessor] = true;
647
+ }
648
+ if (shouldOverwriteSet) {
649
+ finalSetter[customAccessor] = true;
650
+ }
651
+ Object.defineProperty(prototype, name2, {
652
+ ...descriptor,
653
+ get: finalGetter,
654
+ set: finalSetter
655
+ });
656
+ }
657
+ /**
658
+ * Associate an exports object with a controller for reverse lookup in
659
+ * controller.use
660
+ */
661
+ markExports(controller, exports) {
662
+ if (typeof exports === "object" && exports !== null || typeof exports === "function") {
663
+ this._exports.set(exports, controller);
664
+ }
665
+ }
666
+ resolveExports(exports) {
667
+ if (typeof exports === "object" && exports !== null || typeof exports === "function") {
668
+ return this._exports.get(exports);
669
+ } else {
670
+ return void 0;
671
+ }
672
+ }
673
+ };
674
+ var emptyArray = [];
675
+ var customAccessor = Symbol();
676
+ var nothing = (
677
+ // eslint-disable-next-line symbol-description
678
+ Symbol()
679
+ ) ;
680
+ var useControllerManager = (component, forceUpdate) => new ControllerManager(component, forceUpdate);
681
+ var ControllerManager = class extends GenericController {
682
+ constructor(component, forceUpdate) {
683
+ const isLit = "addController" in component;
684
+ const controllers = /* @__PURE__ */ new Set();
685
+ function addController(controller) {
686
+ controllers.add(controller);
687
+ if (isLit && !(controllerSymbol in controller) && component.el.isConnected) {
688
+ controller.hostConnected?.();
689
+ }
690
+ }
691
+ function removeController(controller) {
692
+ void controllers.delete(controller);
693
+ controller.controllerRemoved?.();
694
+ }
695
+ const controllerHost = component;
696
+ controllerHost.addController = addController;
697
+ controllerHost.removeController = removeController;
698
+ if (!isLit) {
699
+ const update = forceUpdate ?? component.constructor.__forceUpdate;
700
+ controllerHost.requestUpdate = () => update(component);
701
+ }
702
+ super(component);
703
+ /** @internal */
704
+ this.internals = new ComponentInternals(this.component);
705
+ this.destroyed = false;
706
+ this._updatePromise = new Deferred();
707
+ this._originalLifecycles = {};
708
+ this.isLit = isLit;
709
+ this.component.manager = this;
710
+ retrieveComponentMembers(component, isLit);
711
+ this._controllers = controllers;
712
+ this.exports = void 0;
713
+ this.hasDestroy = autoDestroyDisabledPropName in this.component && typeof this.component.destroy === "function";
714
+ if (this.hasDestroy) {
715
+ watch(component, autoDestroyDisabledPropName, () => this._setAutoDestroyTimeout());
716
+ }
717
+ this._bindLifecycleMethods();
718
+ const internals = this.internals;
719
+ Object.keys(internals.members).forEach((name2) => {
720
+ internals.accessorGetter[name2] = defaultGetterSetter;
721
+ internals.accessorSetter[name2] = defaultGetterSetter;
722
+ internals.getSetProxy(name2);
723
+ });
724
+ if (!isLit) {
725
+ Object.defineProperty(component, "updateComplete", {
726
+ get: async () => await this._updatePromise.promise
727
+ });
728
+ }
729
+ queueMicrotask(internals.enableReadonly);
730
+ setParentController(void 0);
731
+ setAmbientComponent(component);
732
+ elementToInstance.set(component.el, component);
733
+ elementToInstance.set(component, component);
734
+ }
735
+ _bindLifecycleMethods() {
736
+ const component = this.component;
737
+ const isLit = this.isLit;
738
+ const isStencilDistBuild = component.el === component;
739
+ this._originalLifecycles = {
740
+ // These component's callbacks will be called by Lit, so we don't have to
741
+ connectedCallback: isLit || isStencilDistBuild ? void 0 : component.connectedCallback,
742
+ disconnectedCallback: isLit || isStencilDistBuild ? void 0 : component.disconnectedCallback,
743
+ componentWillLoad: isLit ? void 0 : component.componentWillLoad,
744
+ componentDidLoad: isLit ? void 0 : component.componentDidLoad,
745
+ componentWillUpdate: isLit ? void 0 : component.componentWillUpdate,
746
+ componentDidUpdate: isLit ? void 0 : component.componentDidUpdate,
747
+ destroy: component.destroy
748
+ };
749
+ const hostConnected = this._connectedCallback.bind(this);
750
+ const hostDisconnected = this._disconnectedCallback.bind(this);
751
+ const hostUpdate = this._update.bind(this);
752
+ const hostUpdated = this._updated.bind(this);
753
+ if (isLit) {
754
+ component.constructor.prototype.addController.call(component, {
755
+ // Lit will call these callbacks
756
+ hostConnected,
757
+ hostDisconnected,
758
+ hostUpdate,
759
+ hostUpdated
760
+ });
761
+ } else {
762
+ component.connectedCallback = hostConnected;
763
+ component.disconnectedCallback = hostDisconnected;
764
+ component.componentWillLoad = this._load.bind(this);
765
+ component.componentDidLoad = this._loaded.bind(this);
766
+ component.componentWillUpdate = hostUpdate;
767
+ component.componentDidUpdate = hostUpdated;
768
+ }
769
+ if (this.hasDestroy) {
770
+ component.destroy = this.destroy.bind(this);
771
+ }
772
+ }
773
+ /**
774
+ * Private because this is not supposed to be called by Component directly.
775
+ * Instead, _bindLifecycleMethods will take care of that. Otherwise, you risk
776
+ * calling lifecycle methods twice.
777
+ *
778
+ * @internal
779
+ */
780
+ _connectedCallback() {
781
+ if (this.destroyed) {
782
+ const tagName = this.component.el.tagName.toLowerCase();
783
+ this.component.el.remove();
784
+ throw new Error(
785
+ `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 ${autoDestroyDisabledPropName} prop.`
786
+ );
787
+ }
788
+ if (this._autoDestroyTimeout !== void 0) {
789
+ clearTimeout(this._autoDestroyTimeout);
790
+ }
791
+ const internals = this.internals;
792
+ internals.enabledWatchers = internals.allWatchers;
793
+ keyTrackResolve();
794
+ internals.enableReadonly?.();
795
+ this._controllers.forEach(callConnected);
796
+ this._originalLifecycles.connectedCallback?.call(this.component);
797
+ }
798
+ /** @internal */
799
+ _disconnectedCallback() {
800
+ if (this.destroyed) {
801
+ return;
802
+ }
803
+ this._controllers.forEach(callDisconnected);
804
+ this._originalLifecycles.disconnectedCallback?.call(this.component);
805
+ if (this.hasDestroy) {
806
+ this._setAutoDestroyTimeout();
807
+ }
808
+ }
809
+ /** @internal */
810
+ async _load() {
811
+ const integrations = this.internals.reactiveUtilsIntegrations;
812
+ if (integrations.size > 0) {
813
+ for (const controller of integrations) {
814
+ if ("triggerLoad" in controller) {
815
+ await controller.triggerLoad();
816
+ } else {
817
+ await safeAsyncCall(controller.hostLoad, controller);
818
+ }
819
+ }
820
+ }
821
+ await Promise.allSettled(Array.from(this._controllers, callLoad, integrations));
822
+ await this._originalLifecycles.componentWillLoad?.call(this.component);
823
+ }
824
+ /** @internal */
825
+ _loaded() {
826
+ this._controllers.forEach(callLoaded);
827
+ this._originalLifecycles.componentDidLoad?.call(this.component);
828
+ }
829
+ _update() {
830
+ const changedProperties = this.component.changedProperties;
831
+ this._controllers.forEach(callUpdate2, changedProperties);
832
+ void this._originalLifecycles.componentWillUpdate?.call(this.component);
833
+ }
834
+ _updated() {
835
+ const maybeLitComponent = this.component;
836
+ this._controllers.forEach(callUpdated, maybeLitComponent.changedProperties);
837
+ this._originalLifecycles.componentDidUpdate?.call(this.component);
838
+ if (this.isLit) {
839
+ maybeLitComponent.changedProperties = /* @__PURE__ */ new Map();
840
+ } else {
841
+ const updatePromise = this._updatePromise;
842
+ this._updatePromise = new Deferred();
843
+ updatePromise.resolve(true);
844
+ }
845
+ }
846
+ async destroy() {
847
+ if (this.destroyed) {
848
+ return;
849
+ }
850
+ if (this.component.el.isConnected) {
851
+ this.hasDestroy = false;
852
+ try {
853
+ this.component.el.remove();
854
+ } finally {
855
+ this.hasDestroy = true;
856
+ }
857
+ }
858
+ this._autoDestroyTimeout = void 0;
859
+ this.destroyed = true;
860
+ this._controllers.forEach(callDestroy);
861
+ this._controllers.clear();
862
+ await this._originalLifecycles.destroy?.call(this.component);
863
+ }
864
+ _setAutoDestroyTimeout() {
865
+ if (!this.component.el.isConnected && !this.component.autoDestroyDisabled) {
866
+ if (this._autoDestroyTimeout !== void 0) {
867
+ clearTimeout(this._autoDestroyTimeout);
868
+ }
869
+ const destroy = () => void this.destroy().catch(console.error);
870
+ {
871
+ this._autoDestroyTimeout = devToolsAwareTimeout(destroy, autoDestroyOnDisconnectTimeout);
872
+ }
873
+ }
874
+ }
875
+ };
876
+ var autoDestroyDisabledPropName = "autoDestroyDisabled";
877
+ var autoDestroyOnDisconnectTimeout = 1e3;
878
+ var defaultGetterSetter = (value) => value;
879
+ function callConnected(controller) {
880
+ if ("triggerConnected" in controller) {
881
+ controller.triggerConnected();
882
+ } else {
883
+ safeCall(controller.hostConnected, controller);
884
+ }
885
+ }
886
+ function callDisconnected(controller) {
887
+ if ("triggerDisconnected" in controller) {
888
+ controller.triggerDisconnected();
889
+ } else {
890
+ safeCall(controller.hostDisconnected, controller);
891
+ }
892
+ }
893
+ async function callLoad(controller) {
894
+ if (!this.has(controller)) {
895
+ if ("triggerLoad" in controller) {
896
+ await controller.triggerLoad();
897
+ } else {
898
+ await safeAsyncCall(controller.hostLoad, controller);
899
+ }
900
+ }
901
+ }
902
+ function callLoaded(controller) {
903
+ if ("triggerLoaded" in controller) {
904
+ controller.triggerLoaded();
905
+ } else {
906
+ safeCall(controller.hostLoaded, controller);
907
+ }
908
+ }
909
+ function callUpdate2(controller) {
910
+ if ("triggerUpdate" in controller) {
911
+ controller.triggerUpdate(this);
912
+ } else {
913
+ safeCall(controller.hostUpdate, controller, this);
914
+ }
915
+ }
916
+ function callUpdated(controller) {
917
+ if ("triggerUpdated" in controller) {
918
+ controller.triggerUpdated(this);
919
+ } else {
920
+ safeCall(controller.hostUpdated, controller, this);
921
+ }
922
+ }
923
+ function callDestroy(controller) {
924
+ if ("triggerDestroy" in controller) {
925
+ controller.triggerDestroy();
926
+ } else {
927
+ safeCall(controller.hostDestroy, controller);
928
+ }
929
+ }
930
+ function trackPropKey(component, onResolved, defaultValue) {
931
+ const internals = component.manager.internals;
932
+ if (internals.trackedValue !== nothing && internals.trackedValue !== defaultValue) {
933
+ internals.firePropTrackers(void 0, void 0);
934
+ }
935
+ if (internals.keyTrackers.length === 0) {
936
+ queueMicrotask(() => internals.firePropTrackers(void 0, void 0));
937
+ }
938
+ internals.trackedValue = defaultValue;
939
+ internals.keyTrackers.push((key, value) => safeCall(onResolved, void 0, defaultValue === value ? key : void 0));
940
+ return defaultValue;
941
+ }
942
+
943
+ // src/trackKey.ts
944
+ function trackKey(hostsCandidates, onResolved, defaultValue) {
945
+ const candidateHosts = Array.isArray(hostsCandidates) ? hostsCandidates : [hostsCandidates];
946
+ let leftToResolve = candidateHosts.length + 1;
947
+ const resolved = (resolution) => {
948
+ leftToResolve -= 1;
949
+ if (resolution !== void 0) {
950
+ leftToResolve = 0;
951
+ }
952
+ if (leftToResolve === 0) {
953
+ onResolved(resolution);
954
+ }
955
+ };
956
+ candidateHosts.forEach(
957
+ (host) => trackPropertyKey(
958
+ host,
959
+ (key) => resolved(
960
+ key === void 0 ? void 0 : {
961
+ key,
962
+ host,
963
+ isReactive: false
964
+ }
965
+ ),
966
+ defaultValue
967
+ )
968
+ );
969
+ const component = candidateHosts.find(
970
+ (host) => "manager" in host && typeof host.manager === "object" && host.manager.component === host
971
+ );
972
+ if (component) {
973
+ trackPropKey(
974
+ component,
975
+ (key) => resolved(
976
+ key === void 0 ? void 0 : {
977
+ key,
978
+ host: component,
979
+ isReactive: getMemberType(component, key) !== void 0
980
+ }
981
+ ),
982
+ defaultValue
983
+ );
984
+ }
985
+ return defaultValue;
986
+ }
987
+
988
+ // src/getSet.ts
989
+ function getSet(defaultValue, getSet2) {
990
+ const component = retrieveComponent();
991
+ return trackPropKey(
992
+ component,
993
+ (rawName) => {
994
+ const name2 = rawName;
995
+ const manager = component.manager;
996
+ const genericComponent = component;
997
+ const value = genericComponent[name2];
998
+ const isStencilHotReload = "production" !== "production" ;
999
+ const initialSet = getSet2.initialSet ?? true;
1000
+ if (value != null && value !== defaultValue && typeof getSet2.set === "function" && initialSet && !isStencilHotReload) {
1001
+ const newValue = getSet2.set(value, defaultValue, name2);
1002
+ if (newValue !== value) {
1003
+ if (manager.isLit) {
1004
+ genericComponent[name2] = newValue;
1005
+ } else {
1006
+ let firstConnected = true;
1007
+ manager.onConnected(() => {
1008
+ if (!firstConnected) {
1009
+ return;
1010
+ }
1011
+ firstConnected = true;
1012
+ bypassSetter(() => {
1013
+ genericComponent[name2] = newValue;
1014
+ });
1015
+ });
1016
+ }
1017
+ }
1018
+ }
1019
+ genericGetSet(component, name2, getSet2);
1020
+ },
1021
+ defaultValue
1022
+ );
1023
+ }
1024
+ function bypassSetter(callback) {
1025
+ shouldBypass.setter = true;
1026
+ try {
1027
+ return callback();
1028
+ } finally {
1029
+ shouldBypass.setter = false;
1030
+ }
1031
+ }
1032
+ function genericGetSet(component, property, getSet2) {
1033
+ var _a2, _b;
1034
+ const genericGetSet2 = getSet2;
1035
+ const internals = component.manager.internals;
1036
+ const get = typeof genericGetSet2.get === "function" ? genericGetSet2.get : void 0;
1037
+ if (get) {
1038
+ (_a2 = internals.getters)[property] ?? (_a2[property] = []);
1039
+ internals.getters[property].unshift(get);
1040
+ }
1041
+ const set = genericGetSet2.set === "ignore" ? ignoreSet : genericGetSet2.set;
1042
+ if (set) {
1043
+ (_b = internals.setters)[property] ?? (_b[property] = []);
1044
+ internals.setters[property].unshift(
1045
+ set
1046
+ );
1047
+ }
1048
+ }
1049
+ var ignoreSet = (_, value) => value;
1050
+ function bypassReadOnly(callback) {
1051
+ shouldBypass.readOnly = true;
1052
+ try {
1053
+ return callback();
1054
+ } finally {
1055
+ shouldBypass.readOnly = false;
1056
+ }
1057
+ }
1058
+
1059
+ // src/proxyExports.ts
1060
+ var proxyExports = (Class) => (...args) => {
1061
+ const ambientControllers2 = retrieveParentControllers();
1062
+ const instance = new Class(...args);
1063
+ const initialExports = instance.exports;
1064
+ setParentController(ambientControllers2.at(-1));
1065
+ const internals = instance.component.manager.internals;
1066
+ internals.markExports(instance, initialExports);
1067
+ instance.watchExports((exports) => internals.markExports(instance, exports));
1068
+ setAmbientChildController(instance);
1069
+ const hostCandidates = [instance.component, ...ambientControllers2].reverse();
1070
+ return trackKey(
1071
+ hostCandidates,
1072
+ (resolution) => resolution === void 0 ? void 0 : setProxy(instance, resolution, initialExports),
1073
+ initialExports
1074
+ );
1075
+ };
1076
+ function setProxy(controller, { host, key, isReactive: assignedToProp }, initialExports) {
1077
+ const genericHost = host;
1078
+ const controllerValueChanged = genericHost[key] !== controller.exports;
1079
+ const hostValueChanged = genericHost[key] !== initialExports;
1080
+ const controllerUpdatedExports = initialExports !== controller.exports;
1081
+ if (controllerValueChanged && !hostValueChanged && controllerUpdatedExports) {
1082
+ genericHost[key] = controller.exports;
1083
+ }
1084
+ const isProxyExportsOnComponent = host === controller.component;
1085
+ if (isProxyExportsOnComponent) {
1086
+ if (assignedToProp) {
1087
+ const internals = controller.component.manager.internals;
1088
+ if (hostValueChanged) {
1089
+ internals.markExports(controller, genericHost[key]);
1090
+ }
1091
+ watch(controller.component, key, (value) => {
1092
+ if (value !== controller.exports) {
1093
+ internals.markExports(controller, value);
1094
+ }
1095
+ });
1096
+ }
1097
+ controller.assignedProperty = assignedToProp ? void 0 : key;
1098
+ }
1099
+ controller.watchExports(() => {
1100
+ if (genericHost[key] === controller.exports) {
1101
+ return;
1102
+ }
1103
+ const manager = controller.component.manager;
1104
+ const isReadOnly = manager.internals.setters[key]?.includes(manager.internals.readonlySetter);
1105
+ if (isReadOnly) {
1106
+ bypassReadOnly(() => {
1107
+ genericHost[key] = controller.exports;
1108
+ });
1109
+ } else {
1110
+ genericHost[key] = controller.exports;
1111
+ }
1112
+ });
1113
+ }
1114
+
1115
+ // src/functional.ts
1116
+ var makeController = (constructor) => proxy(void 0, constructor);
1117
+ var FunctionalController = class extends Controller {
1118
+ constructor(component, constructor) {
1119
+ super(component);
1120
+ const originalExports = this.exports;
1121
+ try {
1122
+ setAmbientComponent(this.component);
1123
+ const value = constructor(this.component, this);
1124
+ const constructorChangedExports = this.exports !== originalExports;
1125
+ if (value instanceof Promise) {
1126
+ if (!constructorChangedExports) {
1127
+ this.setProvisionalExports(value);
1128
+ }
1129
+ const resolved = value.then((result) => {
1130
+ this.exports = result;
1131
+ super.catchUpLifecycle();
1132
+ }).catch((error) => {
1133
+ this._ready.reject(error);
1134
+ console.error(error);
1135
+ });
1136
+ this.onLoad(async () => await resolved);
1137
+ } else {
1138
+ if (!constructorChangedExports || value !== void 0) {
1139
+ this.exports = value;
1140
+ }
1141
+ queueMicrotask(() => super.catchUpLifecycle());
1142
+ }
1143
+ } catch (error) {
1144
+ this._ready.reject(error);
1145
+ console.error(error);
1146
+ }
1147
+ }
1148
+ /** Noop - will be called in the constructor instead */
1149
+ catchUpLifecycle() {
1150
+ return;
1151
+ }
1152
+ };
1153
+ var proxy = proxyExports(FunctionalController);
1154
+
1155
+ // #region convert editor profile to apiProfile
1156
+ /**
1157
+ * Converts an editor profile to an api profile.
1158
+ * The api profile is an optimized version of the editor profile designed for minimal data transfer between the main thread and the worker.
1159
+ */
1160
+ const sqlExprEditorToApiProfile = (editorProfile) => {
1161
+ const { apiVersion, bundles, hiddenApiItems } = editorProfile.toEditorProfileDefinition();
1162
+ const variable = editorProfile.variables[0];
1163
+ if (!variable || !(variable.type === "featureSet")) {
1164
+ throw Error("No variable found in the editor profile");
1165
+ }
1166
+ const hydratedVariable = variableToApiProfile(variable);
1167
+ return {
1168
+ apiVersion,
1169
+ bundles,
1170
+ variables: [hydratedVariable],
1171
+ hiddenApiItems: hiddenApiItems?.map((s) => s.toLowerCase()),
1172
+ };
1173
+ };
1174
+ function variableToApiProfile(variable) {
1175
+ const { name } = variable;
1176
+ const description = variable.getDescription();
1177
+ const { definition } = variable.toProfileVariableDefinition();
1178
+ const resultCompletion = {
1179
+ label: name,
1180
+ detail: name,
1181
+ insertText: name,
1182
+ insertTextMode: main.exports.InsertTextMode.asIs,
1183
+ insertTextFormat: main.exports.InsertTextFormat.PlainText,
1184
+ kind: main.exports.CompletionItemKind.Field,
1185
+ };
1186
+ const result = {
1187
+ name,
1188
+ description,
1189
+ type: "dictionary",
1190
+ properties: [],
1191
+ completion: resultCompletion,
1192
+ };
1193
+ // No fields or definition, then it will be a feature without any known fields
1194
+ if (!definition || !("fields" in definition)) {
1195
+ return result;
1196
+ }
1197
+ // Create properties for the fields
1198
+ // Also improve the feature completion documentation
1199
+ // TODO: should we add aliases to completion? what about domains?
1200
+ const [properties, featureCompletionDescription] = fieldsToProfileValues(definition.fields, description);
1201
+ result.properties = properties;
1202
+ resultCompletion.documentation = { kind: "markdown", value: featureCompletionDescription };
1203
+ return result;
1204
+ }
1205
+ const tempHardcodedProfile = {
1206
+ en: {
1207
+ id: "field-calculation",
1208
+ variables: [
1209
+ {
1210
+ name: "$layer",
1211
+ type: "featureSet",
1212
+ description: "The layer being calculated.",
1213
+ },
1214
+ ],
1215
+ },
1216
+ };
1217
+ async function getSdkPredefinedProfile(locale = "en") {
1218
+ return await Promise.resolve(tempHardcodedProfile[locale]);
1219
+ }
1220
+ async function convertToEditorProfileDefinition(predefinedProfile, locale = "en") {
1221
+ if (!isPredefinedProfile(predefinedProfile)) {
1222
+ return undefined;
1223
+ }
1224
+ const sdkPredefinedProfile = await getSdkPredefinedProfile(locale);
1225
+ if (!sdkPredefinedProfile) {
1226
+ return undefined;
1227
+ }
1228
+ //
1229
+ const editorProfile = {
1230
+ variables: [],
1231
+ hiddenApiItems: predefinedProfile.hiddenApiItems?.map((s) => s.toLowerCase()),
1232
+ };
1233
+ // Merge the SDK variables' definitions/properties with the predefined profile definitions.
1234
+ sdkPredefinedProfile.variables.forEach((sdkVariable) => {
1235
+ // Don't include disabled variables
1236
+ if (predefinedProfile.disabledVariables?.includes(sdkVariable.name)) {
1237
+ return;
1238
+ }
1239
+ // Try to get a definition from the predefined profile.
1240
+ const definition = predefinedProfile.definitions[sdkVariable.name];
1241
+ switch (sdkVariable.type) {
1242
+ case "featureSet":
1243
+ if (isFeatureSetDefinition(definition)) {
1244
+ return editorProfile.variables.push({ ...sdkVariable, type: sdkVariable.type, definition });
1245
+ }
1246
+ return;
1247
+ default:
1248
+ throw Error(`sdkVariable type not supported (yet) type: ${sdkVariable.type}`);
1249
+ }
1250
+ });
1251
+ return editorProfile;
1252
+ }
1253
+ // #endregion
1254
+ // #region profile utils
1255
+ /**
1256
+ * util to retrieve fields from the $layer variable in the api context.
1257
+ */
1258
+ const getFieldsFromLayerVariable = (profile) => {
1259
+ if (profile.variables) {
1260
+ const layerVar = profile.variables.find((variable) => variable.name === "$layer" && variable.type === "dictionary");
1261
+ return layerVar.properties ?? [];
1262
+ }
1263
+ return [];
1264
+ };
1265
+ // #endregion
1266
+
1267
+ /**
1268
+ * Returns the sql-expression worker for the model.
1269
+ * Example:
1270
+ * ```ts
1271
+ * const sqlExpressionWorker = await getSqlExpressionWorker(model.uri);
1272
+ * ```
1273
+ * @returns sql-expression worker
1274
+ */
1275
+ async function getSqlExprWorker(uri) {
1276
+ const mode = await getMode();
1277
+ return await mode.getSqlExprWorker(uri);
1278
+ }
1279
+ /**
1280
+ * Request the sql-expression mode
1281
+ * @returns sql-expression mode module
1282
+ */
1283
+ async function getMode() {
1284
+ return await import('./sql-expr-mode-a4413e5c.js');
1285
+ }
1286
+
1287
+ const languageId = "arcgis-sql-expression";
1288
+ class SqlExprDefaults extends LanguageDefaultsBase {
1289
+ constructor() {
1290
+ super(...arguments);
1291
+ this._languageId = languageId;
1292
+ this._languageOptions = {};
1293
+ this._layerMap = new Map();
1294
+ }
1295
+ // TODO: try to rely on editor profile instance instead of storing a feature layer
1296
+ updateFeatureLayerForModel(modelId, layer) {
1297
+ const key = this._getApiKey(modelId);
1298
+ this._layerMap.set(key, layer);
1299
+ }
1300
+ setLanguageOptions(languageOptions) {
1301
+ this._languageOptions = languageOptions;
1302
+ }
1303
+ getFeatureLayerForModel(modelId) {
1304
+ const key = this._getApiKey(modelId);
1305
+ return this._layerMap.get(key);
1306
+ }
1307
+ async setProfileForModel(modelId, definition, apiContext = { locale: "en" }) {
1308
+ // for now, it can ONLY be a predefined profile
1309
+ if (isPredefinedProfile(definition)) {
1310
+ definition = await convertToEditorProfileDefinition(definition, apiContext.locale);
1311
+ }
1312
+ // FIXME: using arcades intlStrings for now...
1313
+ const intlStrings = await fetchT9nStringsBundle(apiContext.locale, getAssetPath("./assets/arcade-language/t9n"), "profile.t9n.");
1314
+ if (!intlStrings) {
1315
+ throw new Error(`Failed to load the language bundle for ${apiContext.locale}`);
1316
+ }
1317
+ this.disposeForModel(modelId);
1318
+ const key = this._getApiKey(modelId);
1319
+ const editorProfile = new EditorProfile(definition, intlStrings);
1320
+ this._profileMap.set(key, editorProfile);
1321
+ const apiProfile = sqlExprEditorToApiProfile(editorProfile);
1322
+ this.updateApiContextForModel(modelId, {
1323
+ locale: apiContext.locale,
1324
+ profile: apiProfile,
1325
+ });
1326
+ const layer = definition?.variables?.find((variable) => variable.name === "$layer");
1327
+ if (layer) {
1328
+ this.updateFeatureLayerForModel(modelId, layer.definition);
1329
+ }
1330
+ }
1331
+ async getApiLibrary(modelId) {
1332
+ const uri = Uri.parse(modelId);
1333
+ const worker = await getSqlExprWorker(uri);
1334
+ return await worker.getApiLibrary(this.getApiContextForModel(uri));
1335
+ }
1336
+ }
1337
+ const sqlExprDefaults = new SqlExprDefaults();
1338
+
1339
+ export { getMode as a, getFieldsFromLayerVariable as b, getSet as g, makeController as m, sqlExprDefaults as s, useControllerManager as u, watch as w };