@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 +1 -1
- package/dist/index.js +34 -11
- package/dist/wrappersUtils.d.ts +27 -7
- package/dist/wrappersUtils.test.d.ts +1 -0
- package/package.json +3 -3
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 {
|
|
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
|
-
|
|
361
|
-
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
if (
|
|
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
|
-
|
|
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,
|
package/dist/wrappersUtils.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
3
|
-
*
|
|
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
|
|
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.
|
|
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.
|
|
24
|
-
"@arcgis/components-utils": "4.32.0-next.
|
|
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",
|