@arcgis/lumina 4.32.0-next.34 → 4.32.0-next.35

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/dist/index.d.ts CHANGED
@@ -12,4 +12,4 @@ export * from "./jsx/jsx";
12
12
  export { safeClassMap, safeStyleMap, directive, live } from "./jsx/directives";
13
13
  export { nothing, noChange, setAttribute, stringOrBoolean } from "./jsx/utils";
14
14
  export { noShadowRoot } from "./utils";
15
- export { createPrototypeProxy } from "./wrappersUtils";
15
+ export { makeReactWrapperFactory, getReactWrapperOptions } from "./wrappersUtils";
package/dist/index.js CHANGED
@@ -357,24 +357,46 @@ var stringOrBoolean = {
357
357
  };
358
358
 
359
359
  // src/wrappersUtils.ts
360
- function createPrototypeProxy(tagName) {
361
- const customElement = {
360
+ var emptyObject = {};
361
+ var makeReactWrapperFactory = (react, createComponent) => (options) => {
362
+ const tagName = options.tagName;
363
+ let customElementPrototype = emptyObject;
364
+ const elementClass = {
362
365
  name: tagName,
366
+ /**
367
+ * Lit's createComponent tries to access the elementClass.prototype in
368
+ * global scope (in development mode). The elementClass may not be defined
369
+ * yet (because we are in a lazy loading build, or because current app
370
+ * doesn't import a given custom element as it doesn't use it).
371
+ *
372
+ * Thus, we return an empty object as a fake prototype.
373
+ *
374
+ * Right after the call to `createComponent`, we set to
375
+ * customElementPrototype undefined so that the next access of
376
+ * `.prototype` tries to get the real prototype.
377
+ * `createPrototypeProxy()` is called, this small proxy delays retrieving the custom
378
+ * element prototype until it is actually needed, and caches the result for future calls.
379
+ */
363
380
  get prototype() {
364
- const customElementPrototype = customElements.get(tagName)?.prototype;
365
- if (!customElementPrototype) {
366
- if (typeof process === "object" && process.env.NODE_ENV !== "production") {
367
- return Object.create(HTMLElement.prototype);
368
- } else {
381
+ if (customElementPrototype === void 0) {
382
+ customElementPrototype = customElements.get(tagName)?.prototype;
383
+ if (!customElementPrototype) {
369
384
  throw new Error(`Custom element "${tagName}" not found`);
370
385
  }
386
+ Object.defineProperty(elementClass, "prototype", { value: customElementPrototype });
371
387
  }
372
- Object.defineProperty(customElement, "prototype", { value: customElementPrototype });
373
388
  return customElementPrototype;
374
389
  }
375
390
  };
376
- return customElement;
377
- }
391
+ const result = createComponent({
392
+ ...options,
393
+ react,
394
+ elementClass
395
+ });
396
+ customElementPrototype = void 0;
397
+ return result;
398
+ };
399
+ var getReactWrapperOptions = (tagNameAndElement, events) => ({ tagName: tagNameAndElement, events });
378
400
  export {
379
401
  Fragment,
380
402
  LitElement,
@@ -383,10 +405,11 @@ export {
383
405
  bindEvent,
384
406
  bindProperty,
385
407
  createEvent,
386
- createPrototypeProxy,
387
408
  directive,
409
+ getReactWrapperOptions,
388
410
  live,
389
411
  makeDefineCustomElements,
412
+ makeReactWrapperFactory,
390
413
  makeRuntime,
391
414
  method,
392
415
  noChange,
@@ -1,11 +1,31 @@
1
+ export interface Options<I extends HTMLElement, E extends EventNames> {
2
+ react: any;
3
+ tagName: string;
4
+ elementClass: Constructor<I>;
5
+ events?: E;
6
+ displayName?: string;
7
+ }
8
+ export type EventNames = Record<string, string>;
9
+ type Constructor<T> = new () => T;
1
10
  /**
2
- * Returns a proxy object for a custom element prototype.
3
- * The function that creates a React wrapper component for a custom element,
4
- * if rendered, will need the custom element prototype to define the React component properties.
5
- * Because the custom element may not yet be defined in global scope when
6
- * `createPrototypeProxy()` is called, this small proxy delays retrieving the custom
7
- * element prototype until it is actually needed, and caches the result for future calls.
11
+ * Wrap `createComponent` from `@lit/react` to improve lazy loading
12
+ * compatibility.
8
13
  *
9
14
  * @private
10
15
  */
11
- export declare function createPrototypeProxy<T extends HTMLElement>(tagName: string): new () => T;
16
+ export declare const makeReactWrapperFactory: (react: unknown, createComponent: (options: Options<HTMLElement, EventNames>) => unknown) => (options: Pick<Options<HTMLElement, EventNames>, "events" | "tagName">) => unknown;
17
+ /**
18
+ * Helper for `createComponent` to declare options in a type-safe and concise
19
+ * manner.
20
+ *
21
+ * @remarks
22
+ * Only tagName and events need to be provided to the wrapped version of the
23
+ * `createComponent` function. However, since we inherit the typings from
24
+ * the original `createComponent`, TypeScript would still force us to provide
25
+ * `react` and `elementClass` properties - instead, this helper convinces
26
+ * TypeScript that we are providing `react` and `elementClass` properties.
27
+ *
28
+ * @private
29
+ */
30
+ export declare const getReactWrapperOptions: <Element extends HTMLElement, Events extends EventNames>(tagNameAndElement: Element, events: Events) => Options<Element, Events>;
31
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/lumina",
3
- "version": "4.32.0-next.34",
3
+ "version": "4.32.0-next.35",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -20,8 +20,8 @@
20
20
  ],
21
21
  "license": "SEE LICENSE IN LICENSE.md",
22
22
  "dependencies": {
23
- "@arcgis/components-controllers": "4.32.0-next.34",
24
- "@arcgis/components-utils": "4.32.0-next.34",
23
+ "@arcgis/components-controllers": "4.32.0-next.35",
24
+ "@arcgis/components-utils": "4.32.0-next.35",
25
25
  "@lit-labs/ssr": "^3.2.2",
26
26
  "@lit-labs/ssr-client": "^1.1.7",
27
27
  "@lit/context": "^1.1.3",