@arcgis/lumina 4.33.0-next.99 → 4.34.0-next.0

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 (36) hide show
  1. package/dist/{Controller-CZ8Djohh.js → Controller-BQOv8BAL.js} +170 -210
  2. package/dist/LitElement.d.ts +22 -18
  3. package/dist/config.d.ts +7 -9
  4. package/dist/config.js +15 -12
  5. package/dist/context.d.ts +2 -2
  6. package/dist/controllers/Controller.d.ts +4 -10
  7. package/dist/controllers/ControllerInternals.d.ts +7 -13
  8. package/dist/controllers/ControllerManager.d.ts +6 -21
  9. package/dist/controllers/accessor/index.d.ts +3 -1
  10. package/dist/controllers/accessor/index.js +208 -222
  11. package/dist/controllers/accessor/reEmitEvent.d.ts +1 -1
  12. package/dist/controllers/accessor/store.d.ts +17 -0
  13. package/dist/controllers/accessor/useAccessor.d.ts +29 -32
  14. package/dist/controllers/index.d.ts +2 -2
  15. package/dist/controllers/index.js +45 -38
  16. package/dist/controllers/trackKey.d.ts +1 -1
  17. package/dist/controllers/trackPropKey.d.ts +1 -1
  18. package/dist/controllers/trackPropertyKey.d.ts +2 -2
  19. package/dist/controllers/types.d.ts +35 -0
  20. package/dist/controllers/usePropertyChange.d.ts +3 -1
  21. package/dist/controllers/utils.d.ts +6 -9
  22. package/dist/createEvent.d.ts +4 -4
  23. package/dist/hmrSupport.js +22 -22
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.js +193 -200
  26. package/dist/jsx/generatedTypes.d.ts +414 -80
  27. package/dist/lazyLoad-DUvrNd2L.js +406 -0
  28. package/dist/lazyLoad.d.ts +22 -67
  29. package/dist/lifecycleSupport.d.ts +1 -1
  30. package/dist/makeRuntime.d.ts +40 -1
  31. package/dist/{proxyExports-CK5BLFLO.js → proxyExports-Cdzj7WL_.js} +8 -8
  32. package/dist/render.d.ts +1 -1
  33. package/dist/utils.d.ts +8 -0
  34. package/dist/wrappersUtils.d.ts +13 -1
  35. package/package.json +5 -5
  36. package/dist/utils-DBdf1Dqp.js +0 -405
@@ -27,7 +27,19 @@ export declare const makeReactWrapperFactory: (react: unknown, createComponent:
27
27
  *
28
28
  * @private
29
29
  */
30
- export declare const getReactWrapperOptions: <Element extends HTMLElement, Events extends EventNames>(tagNameAndElement: Element, events: Events) => Options<Element & {
30
+ export declare const getReactWrapperOptions: <Element extends HTMLElement, Events extends EventNames>(
31
+ /**
32
+ * We want "Events" type argument to be inferred, but Element type
33
+ * argument to be explicitly specified. That isn't possible until
34
+ * https://github.com/microsoft/TypeScript/issues/26242.
35
+ *
36
+ * As a workaround we are making Element inferred by passing Element type as
37
+ * a tag name:
38
+ * ```ts
39
+ * getReactWrapperOptions("te-st" as HTMLTeStElement, {});
40
+ * ```
41
+ */
42
+ tagNameAndElement: Element, events: Events) => Options<Element & {
31
43
  class?: string;
32
44
  }, Events>;
33
45
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/lumina",
3
- "version": "4.33.0-next.99",
3
+ "version": "4.34.0-next.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -22,12 +22,12 @@
22
22
  ],
23
23
  "license": "SEE LICENSE IN LICENSE.md",
24
24
  "dependencies": {
25
- "@arcgis/components-utils": "4.33.0-next.99",
25
+ "@arcgis/components-utils": "4.34.0-next.0",
26
26
  "@lit-labs/ssr": "^3.2.2",
27
27
  "@lit-labs/ssr-client": "^1.1.7",
28
- "@lit/context": "^1.1.3",
28
+ "@lit/context": "^1.1.5",
29
29
  "csstype": "^3.1.3",
30
- "lit": "^3.2.0",
31
- "tslib": "^2.7.0"
30
+ "lit": "^3.3.0",
31
+ "tslib": "^2.8.1"
32
32
  }
33
33
  }
@@ -1,405 +0,0 @@
1
- import { Deferred, isEsriInternalEnv, camelToKebab } from "@arcgis/components-utils";
2
- import { lazyMetaSubItemJoiner, lazyMetaGroupJoiner, lazyMetaItemJoiner } from "./config.js";
3
- function devOnlyDetectIncorrectLazyUsages(LitClass) {
4
- const genericPrototype = LitClass.prototype;
5
- const descriptor = Object.getOwnPropertyDescriptor(genericPrototype, "innerText");
6
- if (descriptor !== void 0 && descriptor.set?.name === "setWrapper") {
7
- return;
8
- }
9
- const allowList = /* @__PURE__ */ new Set([
10
- // We shouldn't be overwriting this property
11
- "constructor",
12
- // Called by Lit - we proxy it to this.el in ProxyComponent
13
- "setAttribute",
14
- // Called by Lit SSR - we proxy it to this.el in ProxyComponent
15
- "removeAttribute",
16
- // Called by Lit - we proxy it to this.el in ProxyComponent
17
- "isConnected",
18
- // Called by Lit, but only in dev mode for warnings, so we don't have to proxy.
19
- "localName",
20
- // Called by Lit Context - we proxy it to this.el in ProxyComponent.
21
- // Interestingly, they never call removeEventListener.
22
- "addEventListener"
23
- ]);
24
- const customErrorMessages = {
25
- addEventListener: "use this.listen() or this.el.addEventListener()"
26
- };
27
- Object.entries({
28
- ...Object.getOwnPropertyDescriptors(HTMLElement.prototype),
29
- ...Object.getOwnPropertyDescriptors(Element.prototype),
30
- ...Object.getOwnPropertyDescriptors(Node.prototype),
31
- ...Object.getOwnPropertyDescriptors(EventTarget.prototype)
32
- }).forEach(([key, value]) => {
33
- if (allowList.has(key)) {
34
- return;
35
- }
36
- function validateUsage(...args) {
37
- const isDynamicallyCreatedComponentInTest = this === this.el;
38
- if (isDynamicallyCreatedComponentInTest) {
39
- return;
40
- }
41
- if (key === "hasAttribute" && args[0] === "defer-hydration") {
42
- return false;
43
- }
44
- throw new Error(
45
- `You should not be trying to access this.${key} directly as it won't work correctly in lazy-builds. Instead, ${customErrorMessages[key] ?? `use this.el.${key}`}`
46
- );
47
- }
48
- if (typeof value.value === "function") {
49
- genericPrototype[key] = function functionWrapper(...args) {
50
- return validateUsage.call(this, ...args) ?? value.value.call(this, ...args);
51
- };
52
- } else if (typeof value.get === "function") {
53
- Object.defineProperty(genericPrototype, key, {
54
- get() {
55
- validateUsage.call(this);
56
- return value.get.call(this);
57
- },
58
- set: typeof value.set === "function" ? function setWrapper(setValue) {
59
- validateUsage.call(this);
60
- value.set.call(this, setValue);
61
- } : void 0
62
- });
63
- } else if (key === key.toUpperCase() && typeof value.value === "number") {
64
- return;
65
- } else {
66
- throw new Error(`Unexpected value type for ${key}: ${value}`);
67
- }
68
- });
69
- }
70
- function attachToAncestor(child) {
71
- let ancestor = child;
72
- while (ancestor = ancestor.parentNode ?? ancestor.host) {
73
- if (ancestor?.constructor?.lumina) {
74
- const litParent = ancestor;
75
- if (!litParent.manager?.loadedCalled) {
76
- litParent._offspring.push(child);
77
- }
78
- return litParent._postLoad.promise;
79
- }
80
- }
81
- return false;
82
- }
83
- const makeDefineCustomElements = (runtime, structure) => function defineCustomElements(windowOrOptions, options) {
84
- if (!globalThis.customElements) {
85
- return;
86
- }
87
- const resolvedOptions = options ?? windowOrOptions ?? {};
88
- const resourcesUrl = resolvedOptions.resourcesUrl;
89
- if (resourcesUrl) {
90
- runtime.setAssetPath(resourcesUrl);
91
- }
92
- Object.entries(structure).forEach(createLazyElement);
93
- };
94
- function createLazyElement([tagName, [load, compactMeta = ""]]) {
95
- if (customElements.get(tagName)) {
96
- return;
97
- }
98
- const [compactObservedProps, compactAsyncMethods, compactSyncMethods] = compactMeta.split(lazyMetaGroupJoiner);
99
- const observedProps = compactObservedProps ? compactObservedProps?.split(lazyMetaItemJoiner).map(parseCondensedProp) : void 0;
100
- const observedProperties = observedProps?.map(([property]) => property);
101
- const ProxyClass = class extends ProxyComponent {
102
- static {
103
- this.observedAttributes = observedProps?.map(([, attribute]) => attribute).filter((attribute) => attribute !== "");
104
- }
105
- static {
106
- this._properties = observedProperties;
107
- }
108
- static {
109
- this._asyncMethods = compactAsyncMethods ? compactAsyncMethods?.split(lazyMetaItemJoiner) : void 0;
110
- }
111
- static {
112
- this._syncMethods = compactSyncMethods?.split(lazyMetaItemJoiner);
113
- }
114
- static {
115
- this._name = tagName;
116
- }
117
- constructor() {
118
- const isFirstInstanceOfType = !ProxyClass._loadPromise;
119
- if (isFirstInstanceOfType) {
120
- ProxyClass._loadPromise = load();
121
- ProxyClass._initializePrototype();
122
- }
123
- super();
124
- }
125
- };
126
- customElements.define(tagName, ProxyClass);
127
- if (process.env.NODE_ENV !== "production") {
128
- globalThis.devOnly$ownTagNames?.add(tagName);
129
- }
130
- }
131
- const defineProperty = Object.defineProperty;
132
- function parseCondensedProp(propAndAttribute) {
133
- const name = propAndAttribute.split(lazyMetaSubItemJoiner);
134
- return name.length === 1 ? [name[0], camelToKebab(name[0])] : name;
135
- }
136
- const HtmlElement = globalThis.HTMLElement ?? parseCondensedProp;
137
- class ProxyComponent extends HtmlElement {
138
- constructor() {
139
- super();
140
- this._store = {};
141
- this._pendingAttributes = [];
142
- this._postLoad = new Deferred();
143
- this._postLoaded = new Deferred();
144
- this._offspring = [];
145
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
146
- this._hmrSetProps = /* @__PURE__ */ new Set();
147
- this._hmrSetAttributes = /* @__PURE__ */ new Set();
148
- globalThis.devOnly$createdElements ??= [];
149
- globalThis.devOnly$createdElements.push(new WeakRef(this));
150
- }
151
- this._saveInstanceProperties();
152
- const ProxyClass = this.constructor;
153
- if (ProxyClass._LitConstructor) {
154
- this._initializeComponent({ a: ProxyClass._LitConstructor });
155
- } else {
156
- void ProxyClass._loadPromise.then(awaitTopLevelPolyfill).then(this._initializeComponent.bind(this)).catch((error) => {
157
- this._postLoaded.reject(error);
158
- setTimeout(() => {
159
- throw error;
160
- });
161
- });
162
- }
163
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
164
- ProxyClass._hmrInstances ??= [];
165
- ProxyClass._hmrInstances.push(new WeakRef(this));
166
- Object.defineProperty(this, "_store", { value: this._store, enumerable: false, configurable: true });
167
- }
168
- }
169
- static {
170
- this.lumina = true;
171
- }
172
- /** private */
173
- static _initializePrototype() {
174
- this._properties?.forEach(this._bindProp, this);
175
- this._asyncMethods?.forEach(this._bindAsync, this);
176
- this._syncMethods?.forEach(this._bindSync, this);
177
- }
178
- static _bindProp(propName) {
179
- defineProperty(this.prototype, propName, {
180
- configurable: true,
181
- enumerable: true,
182
- get() {
183
- return this._store[propName];
184
- },
185
- set(value) {
186
- this._store[propName] = value;
187
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
188
- this._hmrSetProps.add(propName);
189
- }
190
- }
191
- });
192
- }
193
- static _bindAsync(methodName) {
194
- defineProperty(this.prototype, methodName, {
195
- async value(...args) {
196
- if (!this._litElement) {
197
- await this._postLoaded.promise;
198
- }
199
- const genericLitElement = this._litElement;
200
- return await genericLitElement[methodName](...args);
201
- },
202
- configurable: true
203
- });
204
- }
205
- static _bindSync(methodName) {
206
- defineProperty(this.prototype, methodName, {
207
- value(...args) {
208
- if (process.env.NODE_ENV !== "production" && !this._litElement) {
209
- const ProxyClass = this.constructor;
210
- throw new Error(
211
- `Tried to call method ${methodName}() on <${ProxyClass._name}> component before it's fully loaded. Please do 'await component.componentOnReady();' before calling this method.`
212
- );
213
- }
214
- const genericLitElement = this._litElement;
215
- return genericLitElement[methodName](...args);
216
- },
217
- configurable: true
218
- });
219
- }
220
- get manager() {
221
- return this._litElement?.manager;
222
- }
223
- /**
224
- * Until the custom element is registered on the page, an instance of that
225
- * element can be constructed and some properties on that instance set.
226
- *
227
- * These properties are set before the element prototype is set to this proxy
228
- * class and thus none of our getters/setters are yet registered - such
229
- * properties will be set by JavaScript on the instance directly.
230
- *
231
- * Once element is registered, the properties set in the meanwhile will shadow
232
- * the getter/setters, and thus break reactivity. The fix is to delete these
233
- * properties from the instance, and re-apply them once accessors are set.
234
- *
235
- * @example
236
- * ```ts
237
- * import { defineCustomElements } from '@arcgis/map-components';
238
- * const map = document.createElement('arcgis-map');
239
- * // This will shadow the getter/setters
240
- * map.itemId = '...';
241
- * // This finally defines the custom elements and sets the property accessors
242
- * defineCustomElements();
243
- * ```
244
- *
245
- * @remarks
246
- * This is an equivalent of the __saveInstanceProperties method in Lit's
247
- * ReactiveElement. Lit takes care of this on LitElement, but we have to take
248
- * care of this on the lazy proxy
249
- */
250
- _saveInstanceProperties() {
251
- const ProxyClass = this.constructor;
252
- const genericThis = this;
253
- ProxyClass._properties?.forEach((propName) => {
254
- if (Object.hasOwn(this, propName)) {
255
- this._store[propName] = genericThis[propName];
256
- delete genericThis[propName];
257
- }
258
- });
259
- }
260
- /*
261
- * This method must be statically present rather than added later, or else,
262
- * browsers won't call it. Same for connected and disconnected callbacks.
263
- */
264
- attributeChangedCallback(name, oldValue, newValue) {
265
- this._litElement?.attributeChangedCallback(name, oldValue, newValue);
266
- if (!this._litElement) {
267
- this._pendingAttributes.push(name);
268
- }
269
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
270
- this._hmrSetAttributes.add(name);
271
- }
272
- }
273
- connectedCallback() {
274
- if (this._litElement) {
275
- this._litElement.connectedCallback?.();
276
- } else {
277
- queueMicrotask(() => {
278
- this._ancestorLoad = attachToAncestor(this);
279
- });
280
- }
281
- }
282
- disconnectedCallback() {
283
- this._litElement?.disconnectedCallback?.();
284
- }
285
- /**
286
- * Create a promise that resolves once component is fully loaded
287
- */
288
- async componentOnReady() {
289
- await this._postLoaded.promise;
290
- return this;
291
- }
292
- /** private */
293
- _initializeComponent(module) {
294
- const ProxyClass = this.constructor;
295
- const tagName = ProxyClass._name;
296
- const store = this._store;
297
- const LitConstructor = Object.values(module).find(
298
- (LitConstructor2) => LitConstructor2.tagName === tagName
299
- );
300
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && !LitConstructor) {
301
- throw new Error(
302
- `Unable to find the LitElement class for the "${tagName}" custom element in the lazy-loaded module`
303
- );
304
- }
305
- const lazyTagName = process.env.NODE_ENV !== "production" && isEsriInternalEnv() ? (ProxyClass._hmrIndex ?? 0) === 0 ? `${tagName}--lazy` : `${tagName}--lazy-${ProxyClass._hmrIndex}` : `${tagName}--lazy`;
306
- let parentClass = LitConstructor;
307
- while (parentClass && !Object.hasOwn(parentClass, "lumina")) {
308
- parentClass = Object.getPrototypeOf(parentClass);
309
- }
310
- patchLitElement(parentClass);
311
- const isFirstInitialization = !ProxyClass._LitConstructor;
312
- if (isFirstInitialization) {
313
- ProxyClass._LitConstructor = LitConstructor;
314
- customElements.define(lazyTagName, LitConstructor);
315
- }
316
- LitConstructor.lazy = this;
317
- const litElement = document.createElement(lazyTagName);
318
- LitConstructor.lazy = void 0;
319
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
320
- Object.defineProperty(this, "_litElement", { value: litElement, configurable: true, enumerable: false });
321
- } else {
322
- this._litElement = litElement;
323
- }
324
- this._store = litElement;
325
- this._pendingAttributes.forEach((name) => {
326
- const value = this.getAttribute(name);
327
- litElement.attributeChangedCallback(
328
- name,
329
- // Lit doesn't look at this value, thus even if attribute already exists, that's ok
330
- null,
331
- value
332
- );
333
- });
334
- Object.entries(store).forEach(syncLitElement, litElement);
335
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
336
- const litObserved = LitConstructor.observedAttributes ?? [];
337
- const lazyObserved = ProxyClass.observedAttributes ?? [];
338
- const missingFromLazy = litObserved.filter((attribute) => !lazyObserved.includes(attribute));
339
- const missingFromLit = lazyObserved.filter((attribute) => !litObserved.includes(attribute));
340
- if (missingFromLazy.length > 0) {
341
- console.warn(
342
- `The following attributes on <${ProxyClass._name}> are present on the Lit element, but are missing from the lazy proxy component: ${missingFromLazy.join(", ")}. This either indicates a bug in Lumina, or you are creating the attribute dynamically in a way that compiler cannot infer statically. For these attributes, lazy-loading version of your component won't work correctly, thus this must be resolved`
343
- );
344
- }
345
- if (missingFromLit.length > 0) {
346
- console.warn(
347
- `The following attributes on <${ProxyClass._name}> are defined on the lazy proxy component, but not on the actual Lit element: ${missingFromLit.join(", ")}. This either indicates a bug in Lumina, or you are creating the attribute dynamically in a way that compiler cannot infer statically. This is a non-critical issue, but does indicate that something is going wrong and should be fixed`
348
- );
349
- }
350
- }
351
- const isStillConnected = this.isConnected;
352
- if (isStillConnected || this._ancestorLoad) {
353
- litElement.connectedCallback?.();
354
- if (!isStillConnected) {
355
- litElement.disconnectedCallback();
356
- }
357
- }
358
- }
359
- /**
360
- * Implemented on the proxy for compatibility with Lit Context.
361
- */
362
- addController() {
363
- }
364
- /**
365
- * Implemented on the proxy for compatibility with Lit Context.
366
- */
367
- requestUpdate() {
368
- this._litElement?.requestUpdate();
369
- }
370
- }
371
- function syncLitElement([key, value]) {
372
- this[key] = value;
373
- }
374
- function patchLitElement(parentClass) {
375
- const litElementPrototype = parentClass.prototype;
376
- const elementPrototype = Element.prototype;
377
- const alreadyPatched = Object.hasOwn(litElementPrototype, "isConnected");
378
- if (!alreadyPatched) {
379
- litElementPrototype.setAttribute = function(qualifiedName, value) {
380
- elementPrototype.setAttribute.call(this.el, qualifiedName, value);
381
- };
382
- litElementPrototype.removeAttribute = function(qualifiedName) {
383
- elementPrototype.removeAttribute.call(this.el, qualifiedName);
384
- };
385
- defineProperty(litElementPrototype, "isConnected", {
386
- get() {
387
- return Reflect.get(elementPrototype, "isConnected", this.el);
388
- }
389
- });
390
- }
391
- if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
392
- devOnlyDetectIncorrectLazyUsages(parentClass);
393
- }
394
- }
395
- const awaitTopLevelPolyfill = async (module) => {
396
- await module.$$;
397
- return module;
398
- };
399
- const noShadowRoot = {};
400
- export {
401
- ProxyComponent as P,
402
- attachToAncestor as a,
403
- makeDefineCustomElements as m,
404
- noShadowRoot as n
405
- };