@arcgis/lumina 4.32.0-next.14 → 4.32.0-next.141

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.
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Licensing
2
2
 
3
- COPYRIGHT © 2024 Esri
3
+ COPYRIGHT © 2025 Esri
4
4
 
5
5
  All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions.
6
6
 
package/README.md CHANGED
@@ -8,7 +8,7 @@ It is not intended to be used directly, but rather used as a dependency by other
8
8
 
9
9
  ## License
10
10
 
11
- COPYRIGHT © 2024 Esri
11
+ COPYRIGHT © 2025 Esri
12
12
 
13
13
  All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions.
14
14
 
@@ -3,7 +3,7 @@ import { LitElement as OriginalLitElement } from "lit";
3
3
  import type { LuminaPropertyDeclaration } from "@arcgis/components-controllers";
4
4
  import type { Runtime } from "./runtime";
5
5
  import type { ProxyComponent } from "./lazyLoad";
6
- import type { ToElement } from "./jsx/jsx";
6
+ import type { ToElement } from "./jsx/types";
7
7
  type ComponentLifecycle = {
8
8
  connectedCallback?: () => void;
9
9
  disconnectedCallback?: () => void;
@@ -80,7 +80,7 @@ export declare class LitElement extends OriginalLitElement implements ComponentL
80
80
  */
81
81
  el: ToElement<this>;
82
82
  /**
83
- * Controller Manager orchestrates all components used by this component,
83
+ * Controller Manager orchestrates all controllers used by this component,
84
84
  * connecting their lifecycle hooks and providing context information.
85
85
  */
86
86
  manager: import("@arcgis/components-controllers").ControllerManager<never>;
@@ -233,4 +233,12 @@ export declare class LitElement extends OriginalLitElement implements ComponentL
233
233
  type Listener<ThisType, EventType> = ((this: ThisType, event: EventType) => unknown) | {
234
234
  handleEvent(event: EventType): unknown;
235
235
  };
236
+ /**
237
+ * List of tag names defined by this library.
238
+ *
239
+ * @private
240
+ */
241
+ export type GlobalThisWithOwnTagNames = typeof globalThis & {
242
+ devOnly$ownTagNames?: Set<string>;
243
+ };
236
244
  export {};
@@ -13,4 +13,5 @@ export declare class PublicLitElement extends HTMLElement {
13
13
  * });
14
14
  */
15
15
  componentOnReady(): Promise<this>;
16
+ private el;
16
17
  }
@@ -0,0 +1,421 @@
1
+ import {
2
+ lazyMetaGroupJoiner,
3
+ lazyMetaItemJoiner,
4
+ lazyMetaSubItemJoiner
5
+ } from "./chunk-PGHUBTOM.js";
6
+
7
+ // src/lazyLoad.ts
8
+ import { Deferred, camelToKebab, isEsriInternalEnv } from "@arcgis/components-utils";
9
+
10
+ // src/devOnlyDetectIncorrectLazyUsages.ts
11
+ function devOnlyDetectIncorrectLazyUsages(LitClass) {
12
+ const genericPrototype = LitClass.prototype;
13
+ const descriptor = Object.getOwnPropertyDescriptor(genericPrototype, "innerText");
14
+ if (descriptor !== void 0 && descriptor.get === descriptor.set) {
15
+ return;
16
+ }
17
+ const allowList = /* @__PURE__ */ new Set([
18
+ // We shouldn't be overwriting this property
19
+ "constructor",
20
+ // Called by Lit - we proxy it to this.el in ProxyComponent
21
+ "setAttribute",
22
+ // Called by Lit SSR - we proxy it to this.el in ProxyComponent
23
+ "removeAttribute",
24
+ // Called by Lit - we proxy it to this.el in ProxyComponent
25
+ "isConnected",
26
+ // Called by Lit, but only in dev mode for warnings, so we don't have to proxy.
27
+ "localName",
28
+ // Called by Lit Context - we proxy it to this.el in ProxyComponent.
29
+ // Interestingly, they never call removeEventListener.
30
+ "addEventListener"
31
+ ]);
32
+ const customErrorMessages = {
33
+ addEventListener: "use this.listen() or this.el.addEventListener()"
34
+ };
35
+ Object.entries({
36
+ ...Object.getOwnPropertyDescriptors(HTMLElement.prototype),
37
+ ...Object.getOwnPropertyDescriptors(Element.prototype),
38
+ ...Object.getOwnPropertyDescriptors(Node.prototype),
39
+ ...Object.getOwnPropertyDescriptors(EventTarget.prototype)
40
+ }).forEach(([key, value]) => {
41
+ if (allowList.has(key)) {
42
+ return;
43
+ }
44
+ const callback = (...args) => {
45
+ if (key === "hasAttribute" && args[0] === "defer-hydration") {
46
+ return false;
47
+ }
48
+ throw new Error(
49
+ `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}`}`
50
+ );
51
+ };
52
+ if (typeof value.value === "function") {
53
+ genericPrototype[key] = callback;
54
+ } else {
55
+ Object.defineProperty(genericPrototype, key, { get: callback, set: callback });
56
+ }
57
+ });
58
+ }
59
+
60
+ // src/lifecycleSupport.ts
61
+ function attachToAncestor(child) {
62
+ let ancestor = child;
63
+ while (ancestor = ancestor.parentNode ?? ancestor.host) {
64
+ if (ancestor?.constructor?.lumina) {
65
+ const litParent = ancestor;
66
+ if (!litParent.manager?.loadedCalled) {
67
+ litParent._offspring.push(child);
68
+ }
69
+ return litParent._postLoad.promise;
70
+ }
71
+ }
72
+ return false;
73
+ }
74
+
75
+ // src/lazyLoad.ts
76
+ var makeDefineCustomElements = (runtime, structure) => function defineCustomElements(windowOrOptions, options) {
77
+ if (!globalThis.customElements) {
78
+ return;
79
+ }
80
+ const resolvedOptions = options ?? windowOrOptions ?? {};
81
+ const resourcesUrl = resolvedOptions.resourcesUrl;
82
+ if (resourcesUrl) {
83
+ runtime.setAssetPath(resourcesUrl);
84
+ }
85
+ Object.entries(structure).forEach(createLazyElement);
86
+ };
87
+ function createLazyElement([tagName, [load, compactMeta = ""]]) {
88
+ if (customElements.get(tagName)) {
89
+ return;
90
+ }
91
+ const [compactObservedProps, compactAsyncMethods, compactSyncMethods] = compactMeta.split(lazyMetaGroupJoiner);
92
+ const observedProps = compactObservedProps ? compactObservedProps?.split(lazyMetaItemJoiner).map(parseCondensedProp) : void 0;
93
+ const observedProperties = observedProps?.map(([property]) => property);
94
+ const ProxyClass = class extends ProxyComponent {
95
+ static {
96
+ this.observedAttributes = observedProps?.map(([, attribute]) => attribute).filter((attribute) => attribute !== "");
97
+ }
98
+ static {
99
+ this._properties = observedProperties;
100
+ }
101
+ static {
102
+ this._asyncMethods = compactAsyncMethods ? compactAsyncMethods?.split(lazyMetaItemJoiner) : void 0;
103
+ }
104
+ static {
105
+ this._syncMethods = compactSyncMethods?.split(lazyMetaItemJoiner);
106
+ }
107
+ static {
108
+ this._name = tagName;
109
+ }
110
+ constructor() {
111
+ const isFirstInstanceOfType = !ProxyClass._loadPromise;
112
+ if (isFirstInstanceOfType) {
113
+ ProxyClass._loadPromise = load();
114
+ ProxyClass._initializePrototype();
115
+ }
116
+ super();
117
+ }
118
+ };
119
+ customElements.define(tagName, ProxyClass);
120
+ if (process.env.NODE_ENV !== "production") {
121
+ globalThis.devOnly$ownTagNames?.add(tagName);
122
+ }
123
+ }
124
+ var defineProperty = Object.defineProperty;
125
+ function parseCondensedProp(propAndAttribute) {
126
+ const name = propAndAttribute.split(lazyMetaSubItemJoiner);
127
+ return name.length === 1 ? [name[0], camelToKebab(name[0])] : name;
128
+ }
129
+ var HtmlElement = globalThis.HTMLElement ?? parseCondensedProp;
130
+ var ProxyComponent = class extends HtmlElement {
131
+ constructor() {
132
+ super();
133
+ /** @internal */
134
+ this._store = {};
135
+ /**
136
+ * If attributeChangedCallback() is called before the LitElement is loaded,
137
+ * store the attributes here, and replay later
138
+ */
139
+ this._pendingAttributes = [];
140
+ /**
141
+ * Resolved once LitElement's load() is complete.
142
+ * Not read inside of this class, but needed for LitElement to determine if
143
+ * it's closest ancestor finished load()
144
+ */
145
+ this._postLoad = new Deferred();
146
+ /**
147
+ * Resolved once LitElement's loaded() is complete
148
+ */
149
+ this._postLoaded = new Deferred();
150
+ /**
151
+ * Direct offspring that should be awaited before loaded() is emitted
152
+ */
153
+ this._offspring = [];
154
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
155
+ this._hmrSetProps = /* @__PURE__ */ new Set();
156
+ this._hmrSetAttributes = /* @__PURE__ */ new Set();
157
+ globalThis.devOnly$createdElements ??= [];
158
+ globalThis.devOnly$createdElements.push(new WeakRef(this));
159
+ }
160
+ this._saveInstanceProperties();
161
+ const ProxyClass = this.constructor;
162
+ if (ProxyClass._LitConstructor) {
163
+ this._initializeComponent({ a: ProxyClass._LitConstructor });
164
+ } else {
165
+ void ProxyClass._loadPromise.then(this._initializeComponent.bind(this)).catch((error) => {
166
+ this._postLoaded.reject(error);
167
+ setTimeout(() => {
168
+ throw error;
169
+ });
170
+ });
171
+ }
172
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
173
+ ProxyClass._hmrInstances ??= [];
174
+ ProxyClass._hmrInstances.push(new WeakRef(this));
175
+ Object.defineProperty(this, "_store", {
176
+ value: this._store,
177
+ enumerable: false,
178
+ configurable: true
179
+ });
180
+ }
181
+ }
182
+ static {
183
+ this.lumina = true;
184
+ }
185
+ /** @internal */
186
+ static _initializePrototype() {
187
+ this._properties?.forEach(this._bindProp, this);
188
+ this._asyncMethods?.forEach(this._bindAsync, this);
189
+ this._syncMethods?.forEach(this._bindSync, this);
190
+ }
191
+ static _bindProp(propName) {
192
+ defineProperty(this.prototype, propName, {
193
+ configurable: true,
194
+ enumerable: true,
195
+ get() {
196
+ return this._store[propName];
197
+ },
198
+ set(value) {
199
+ this._store[propName] = value;
200
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
201
+ this._hmrSetProps.add(propName);
202
+ }
203
+ }
204
+ });
205
+ }
206
+ static _bindAsync(methodName) {
207
+ defineProperty(this.prototype, methodName, {
208
+ async value(...args) {
209
+ if (!this._litElement) {
210
+ await this._postLoaded.promise;
211
+ }
212
+ const genericLitElement = this._litElement;
213
+ return await genericLitElement[methodName](...args);
214
+ },
215
+ configurable: true
216
+ });
217
+ }
218
+ static _bindSync(methodName) {
219
+ defineProperty(this.prototype, methodName, {
220
+ value(...args) {
221
+ if (process.env.NODE_ENV !== "production" && !this._litElement) {
222
+ const ProxyClass = this.constructor;
223
+ throw new Error(
224
+ `Tried to call method ${methodName}() on <${ProxyClass._name}> component before it's fully loaded. Please do 'await component.componentOnReady();' before calling this method.`
225
+ );
226
+ }
227
+ const genericLitElement = this._litElement;
228
+ return genericLitElement[methodName](...args);
229
+ },
230
+ configurable: true
231
+ });
232
+ }
233
+ get manager() {
234
+ return this._litElement?.manager;
235
+ }
236
+ /**
237
+ * Until the custom element is registered on the page, an instance of that
238
+ * element can be constructed and some properties on that instance set.
239
+ *
240
+ * These properties are set before the element prototype is set to this proxy
241
+ * class and thus none of our getters/setters are yet registered - such
242
+ * properties will be set by JavaScript on the instance directly.
243
+ *
244
+ * Once element is registered, the properties set in the meanwhile will shadow
245
+ * the getter/setters, and thus break reactivity. The fix is to delete these
246
+ * properties from the instance, and re-apply them once accessors are set.
247
+ *
248
+ * @example
249
+ * ```ts
250
+ * import { defineCustomElements } from '@arcgis/map-components';
251
+ * const map = document.createElement('arcgis-map');
252
+ * // This will shadow the getter/setters
253
+ * map.itemId = '...';
254
+ * // This finally defines the custom elements and sets the property accessors
255
+ * defineCustomElements();
256
+ * ```
257
+ *
258
+ * @remarks
259
+ * This is an equivalent of the __saveInstanceProperties method in Lit's
260
+ * ReactiveElement. Lit takes care of this on LitElement, but we have to take
261
+ * care of this on the lazy proxy
262
+ */
263
+ _saveInstanceProperties() {
264
+ const ProxyClass = this.constructor;
265
+ const genericThis = this;
266
+ ProxyClass._properties?.forEach((propName) => {
267
+ if (Object.hasOwn(this, propName)) {
268
+ this._store[propName] = genericThis[propName];
269
+ delete genericThis[propName];
270
+ }
271
+ });
272
+ }
273
+ /*
274
+ * This method must be statically present rather than added later, or else,
275
+ * browsers won't call it. Same for connected and disconnected callbacks.
276
+ */
277
+ attributeChangedCallback(name, oldValue, newValue) {
278
+ this._litElement?.attributeChangedCallback(name, oldValue, newValue);
279
+ if (!this._litElement) {
280
+ this._pendingAttributes.push(name);
281
+ }
282
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
283
+ this._hmrSetAttributes.add(name);
284
+ }
285
+ }
286
+ connectedCallback() {
287
+ if (this._litElement) {
288
+ this._litElement.connectedCallback?.();
289
+ } else {
290
+ queueMicrotask(() => {
291
+ this._ancestorLoad = attachToAncestor(this);
292
+ });
293
+ }
294
+ }
295
+ disconnectedCallback() {
296
+ this._litElement?.disconnectedCallback?.();
297
+ }
298
+ /**
299
+ * Create a promise that resolves once component is fully loaded
300
+ */
301
+ async componentOnReady() {
302
+ await this._postLoaded.promise;
303
+ return this;
304
+ }
305
+ /** @internal */
306
+ _initializeComponent(module) {
307
+ const ProxyClass = this.constructor;
308
+ const tagName = ProxyClass._name;
309
+ const store = this._store;
310
+ const LitConstructor = Object.values(module).find(
311
+ (LitConstructor2) => LitConstructor2.tagName === tagName
312
+ );
313
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv() && !LitConstructor) {
314
+ throw new Error(
315
+ `Unable to find the LitElement class for the "${tagName}" custom element in the lazy-loaded module`
316
+ );
317
+ }
318
+ const lazyTagName = process.env.NODE_ENV !== "production" && isEsriInternalEnv() ? (ProxyClass._hmrIndex ?? 0) === 0 ? `${tagName}--lazy` : `${tagName}--lazy-${ProxyClass._hmrIndex}` : `${tagName}--lazy`;
319
+ let parentClass = LitConstructor;
320
+ while (parentClass && !Object.hasOwn(parentClass, "lumina")) {
321
+ parentClass = Object.getPrototypeOf(parentClass);
322
+ }
323
+ patchLitElement(parentClass);
324
+ const isFirstInitialization = !ProxyClass._LitConstructor;
325
+ if (isFirstInitialization) {
326
+ ProxyClass._LitConstructor = LitConstructor;
327
+ customElements.define(lazyTagName, LitConstructor);
328
+ }
329
+ LitConstructor.lazy = this;
330
+ const litElement = document.createElement(lazyTagName);
331
+ LitConstructor.lazy = void 0;
332
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
333
+ Object.defineProperty(this, "_litElement", {
334
+ value: litElement,
335
+ configurable: true,
336
+ enumerable: false
337
+ });
338
+ } else {
339
+ this._litElement = litElement;
340
+ }
341
+ this._store = litElement;
342
+ this._pendingAttributes.forEach((name) => {
343
+ const value = this.getAttribute(name);
344
+ litElement.attributeChangedCallback(
345
+ name,
346
+ // Lit doesn't look at this value, thus even if attribute already exists, that's ok
347
+ null,
348
+ value
349
+ );
350
+ });
351
+ Object.entries(store).forEach(syncLitElement, litElement);
352
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
353
+ const litObserved = LitConstructor.observedAttributes ?? [];
354
+ const lazyObserved = ProxyClass.observedAttributes ?? [];
355
+ const missingFromLazy = litObserved.filter((attribute) => !lazyObserved.includes(attribute));
356
+ const missingFromLit = lazyObserved.filter((attribute) => !litObserved.includes(attribute));
357
+ if (missingFromLazy.length > 0) {
358
+ console.warn(
359
+ `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`
360
+ );
361
+ }
362
+ if (missingFromLit.length > 0) {
363
+ console.warn(
364
+ `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`
365
+ );
366
+ }
367
+ }
368
+ const isStillConnected = this.isConnected;
369
+ if (isStillConnected || this._ancestorLoad) {
370
+ litElement.connectedCallback?.();
371
+ if (!isStillConnected) {
372
+ litElement.disconnectedCallback();
373
+ }
374
+ }
375
+ }
376
+ /**
377
+ * Implemented on the proxy for compatibility with Lit Context.
378
+ */
379
+ addController() {
380
+ }
381
+ /**
382
+ * Implemented on the proxy for compatibility with Lit Context.
383
+ */
384
+ requestUpdate() {
385
+ this._litElement?.requestUpdate();
386
+ }
387
+ };
388
+ function syncLitElement([key, value]) {
389
+ this[key] = value;
390
+ }
391
+ function patchLitElement(parentClass) {
392
+ const litElementPrototype = parentClass.prototype;
393
+ const elementPrototype = Element.prototype;
394
+ const alreadyPatched = Object.hasOwn(litElementPrototype, "isConnected");
395
+ if (!alreadyPatched) {
396
+ litElementPrototype.setAttribute = function(qualifiedName, value) {
397
+ elementPrototype.setAttribute.call(this.el, qualifiedName, value);
398
+ };
399
+ litElementPrototype.removeAttribute = function(qualifiedName) {
400
+ elementPrototype.removeAttribute.call(this.el, qualifiedName);
401
+ };
402
+ defineProperty(litElementPrototype, "isConnected", {
403
+ get() {
404
+ return Reflect.get(elementPrototype, "isConnected", this.el);
405
+ }
406
+ });
407
+ }
408
+ if (process.env.NODE_ENV !== "production" && isEsriInternalEnv()) {
409
+ devOnlyDetectIncorrectLazyUsages(parentClass);
410
+ }
411
+ }
412
+
413
+ // src/utils.ts
414
+ var noShadowRoot = {};
415
+
416
+ export {
417
+ attachToAncestor,
418
+ makeDefineCustomElements,
419
+ ProxyComponent,
420
+ noShadowRoot
421
+ };
@@ -0,0 +1,26 @@
1
+ import { type ControllerHost } from "@arcgis/components-controllers";
2
+ import { ContextConsumer, ContextProvider, type Context, type ContextType } from "@lit/context";
3
+ interface ContextProviderOptions<C extends Context<unknown, unknown>> {
4
+ context: C;
5
+ initialValue?: ContextType<C>;
6
+ }
7
+ interface ContextConsumerOptions<C extends Context<unknown, unknown>> {
8
+ context: C;
9
+ callback?: (value: ContextType<C>, dispose?: () => void) => void;
10
+ subscribe?: boolean;
11
+ }
12
+ /**
13
+ * Wrapper for Lit's ContextProvider controller to provide lazy-loading compatibility.
14
+ *
15
+ * @see https://lit.dev/docs/data/context/
16
+ */
17
+ export declare function useContextProvider<C extends Context<unknown, unknown>>(options: ContextProviderOptions<C>): ContextProvider<C>;
18
+ /**
19
+ * Wrapper for Lit's ContextConsumer controller to provide lazy-loading compatibility.
20
+ *
21
+ * @see https://lit.dev/docs/data/context/
22
+ *
23
+ * FEATURE: wrap this in proxyExports to improve DX, or keep it simple?
24
+ */
25
+ export declare function useContextConsumer<C extends Context<unknown, unknown>>(options: ContextConsumerOptions<C>): ContextConsumer<C, ControllerHost & HTMLElement>;
26
+ export {};
@@ -52,4 +52,4 @@ declare type CustomMethodDecorator<T> = (target: unknown, propertyKey: string |
52
52
  * This decorator does not exist at runtime and is only used as a hint for the
53
53
  * compiler to declare certain methods as public.
54
54
  */
55
- export declare const method: () => CustomMethodDecorator<any>;
55
+ export declare const method: () => CustomMethodDecorator<(...args: never[]) => any>;
@@ -5,8 +5,11 @@ import type { ModuleNamespace } from "vite/types/hot.js";
5
5
  * @remarks
6
6
  * You should not need to call this function directly - it will be inserted
7
7
  * automatically when running in serve mode.
8
+ *
9
+ * @private
8
10
  */
9
11
  export declare function handleHmrUpdate(newModules: (ModuleNamespace | undefined)[]): void;
12
+ /** @private */
10
13
  export type HmrComponentMeta = {
11
14
  readonly tagName: string;
12
15
  /**
@@ -25,5 +28,7 @@ export type HmrComponentMeta = {
25
28
  * @remarks
26
29
  * You should not need to call this function directly - it will be inserted
27
30
  * automatically when running in serve mode.
31
+ *
32
+ * @private
28
33
  */
29
34
  export declare function handleComponentMetaUpdate(meta: HmrComponentMeta): void;
@@ -0,0 +1,127 @@
1
+ import {
2
+ ProxyComponent,
3
+ noShadowRoot
4
+ } from "./chunk-NO7HOBNA.js";
5
+ import "./chunk-PGHUBTOM.js";
6
+
7
+ // src/hmrSupport.ts
8
+ import { camelToKebab } from "@arcgis/components-utils";
9
+ function handleHmrUpdate(newModules) {
10
+ newModules.forEach((newModule) => {
11
+ if (newModule === void 0) {
12
+ return;
13
+ }
14
+ Object.values(newModule).forEach((exported) => {
15
+ if (typeof exported !== "function" || typeof exported.tagName !== "string") {
16
+ return;
17
+ }
18
+ const LitConstructor = exported;
19
+ const ProxyClass = customElements.get(LitConstructor.tagName);
20
+ if (ProxyClass === void 0) {
21
+ throw new Error(`Failed to find custom element proxy for tag name: ${LitConstructor.tagName}`);
22
+ }
23
+ ProxyClass._LitConstructor = void 0;
24
+ ProxyClass._loadPromise = void 0;
25
+ ProxyClass._hmrIndex ??= 0;
26
+ ProxyClass._hmrIndex += 1;
27
+ ProxyClass._initializePrototype();
28
+ ProxyClass._hmrInstances?.forEach((instanceWeakRef) => {
29
+ const instance = instanceWeakRef.deref();
30
+ if (instance === void 0) {
31
+ return;
32
+ }
33
+ if (instance._litElement === void 0) {
34
+ void ProxyClass._loadPromise.then(() => reInitialize(instance, newModule));
35
+ } else {
36
+ reInitialize(instance, newModule);
37
+ }
38
+ });
39
+ return;
40
+ });
41
+ });
42
+ }
43
+ function reInitialize(instance, newModule) {
44
+ const PreviousLitConstructor = instance._litElement.constructor;
45
+ const isShadowRoot = PreviousLitConstructor.shadowRootOptions !== noShadowRoot;
46
+ if (!isShadowRoot) {
47
+ const root = instance.getRootNode() ?? document;
48
+ if ("adoptedStyleSheets" in root) {
49
+ const rootStyles = Array.from(root.adoptedStyleSheets);
50
+ PreviousLitConstructor.elementStyles.forEach((style) => {
51
+ const styleSheet = "styleSheet" in style ? style.styleSheet : style;
52
+ const index = rootStyles.lastIndexOf(styleSheet);
53
+ if (index > -1) {
54
+ rootStyles.splice(index, 1);
55
+ }
56
+ });
57
+ root.adoptedStyleSheets = rootStyles;
58
+ }
59
+ }
60
+ const properties = PreviousLitConstructor.elementProperties;
61
+ const preservedProperties = Array.from(properties.entries()).filter(
62
+ ([propertyName, descriptor]) => typeof propertyName === "string" && (instance._hmrSetProps.has(propertyName) || typeof descriptor.attribute === "string" && instance._hmrSetAttributes.has(descriptor.attribute))
63
+ ).map(([key]) => [key, instance[key]]);
64
+ instance._store = Object.fromEntries(preservedProperties);
65
+ if (instance.isConnected) {
66
+ instance._litElement.disconnectedCallback();
67
+ }
68
+ const renderRoot = instance._litElement?.renderRoot;
69
+ if (renderRoot) {
70
+ renderRoot._$litPart$ = void 0;
71
+ while (renderRoot.firstChild) {
72
+ renderRoot.removeChild(renderRoot.firstChild);
73
+ }
74
+ }
75
+ instance._initializeComponent(newModule);
76
+ }
77
+ function handleComponentMetaUpdate(meta) {
78
+ const ProxyClass = customElements.get(meta.tagName);
79
+ if (ProxyClass === void 0) {
80
+ return;
81
+ }
82
+ const attributes = meta.properties.map(([property, attribute]) => attribute ?? camelToKebab(property)).filter(Boolean);
83
+ const observedAttributes = initializeAttributeObserver();
84
+ observedAttributes[meta.tagName] ??= {};
85
+ observedAttributes[meta.tagName].original ??= new Set(ProxyClass.observedAttributes);
86
+ const originallyObserved = observedAttributes[meta.tagName].original;
87
+ observedAttributes[meta.tagName].manuallyObserved = new Set(
88
+ /**
89
+ * Never manually observe attributes that were in the original
90
+ * observedAttributes as those would be observed by the browser
91
+ */
92
+ attributes.filter((attribute) => !originallyObserved.has(attribute))
93
+ );
94
+ ProxyClass._asyncMethods = meta.asyncMethods;
95
+ ProxyClass._syncMethods = meta.syncMethods;
96
+ ProxyClass._properties = meta.properties.map(([name]) => name);
97
+ ProxyClass.observedAttributes = attributes;
98
+ }
99
+ function initializeAttributeObserver() {
100
+ const observedAttributesSymbol = Symbol.for("@arcgis/lumina:observedAttributes");
101
+ const globalThisWithObservedAttributes = globalThis;
102
+ const alreadyHadObservers = observedAttributesSymbol in globalThisWithObservedAttributes;
103
+ globalThisWithObservedAttributes[observedAttributesSymbol] ??= {};
104
+ const observedAttributes = globalThisWithObservedAttributes[observedAttributesSymbol];
105
+ if (!alreadyHadObservers) {
106
+ const makeObserver = (original) => function observeAttributes(qualifiedName, ...rest) {
107
+ const observed = observedAttributes[this.tagName.toLowerCase()]?.manuallyObserved;
108
+ if (observed?.has(qualifiedName)) {
109
+ const oldValue = this.getAttribute(qualifiedName);
110
+ const returns = original.call(this, qualifiedName, ...rest);
111
+ const newValue = this.getAttribute(qualifiedName);
112
+ this.attributeChangedCallback(qualifiedName, oldValue, newValue);
113
+ return returns;
114
+ } else {
115
+ return original.call(this, qualifiedName, ...rest);
116
+ }
117
+ };
118
+ ProxyComponent.prototype.setAttribute = makeObserver(ProxyComponent.prototype.setAttribute);
119
+ ProxyComponent.prototype.toggleAttribute = makeObserver(ProxyComponent.prototype.toggleAttribute);
120
+ ProxyComponent.prototype.removeAttribute = makeObserver(ProxyComponent.prototype.removeAttribute);
121
+ }
122
+ return observedAttributes;
123
+ }
124
+ export {
125
+ handleComponentMetaUpdate,
126
+ handleHmrUpdate
127
+ };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
+ export { useContextProvider, useContextConsumer } from "./context";
1
2
  export type { EventOptions } from "./createEvent";
2
3
  export { createEvent } from "./createEvent";
3
4
  export { state, property, method } from "./decorators";
4
- export type { HmrComponentMeta } from "./hmrSupport";
5
- export { handleComponentMetaUpdate, handleHmrUpdate } from "./hmrSupport";
6
5
  export type { DefineCustomElements, LazyLoadOptions, GlobalThisWithPuppeteerEnv } from "./lazyLoad";
7
6
  export { makeDefineCustomElements } from "./lazyLoad";
8
7
  export { LitElement } from "./LitElement";
9
8
  export type { PublicLitElement } from "./PublicLitElement";
10
9
  export type { Runtime, RuntimeOptions, DevOnlyGlobalRuntime, DevOnlyGlobalComponentRefCallback } from "./runtime";
11
10
  export { makeRuntime } from "./runtime";
12
- export * from "./jsx/jsx";
11
+ export type { EventHandler } from "./jsx/baseTypes";
12
+ export * from "./jsx/types";
13
13
  export { safeClassMap, safeStyleMap, directive, live } from "./jsx/directives";
14
14
  export { nothing, noChange, setAttribute, stringOrBoolean } from "./jsx/utils";
15
15
  export { noShadowRoot } from "./utils";
16
- export { createPrototypeProxy } from "./wrappersUtils";
16
+ export { makeReactWrapperFactory, getReactWrapperOptions } from "./wrappersUtils";