@arcgis/coding-components 4.30.0-next.8 → 4.30.0-next.80

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