@pushwoosh/smart-components-kit 1.0.55 → 1.0.56
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/SystemParcel/SystemParcel.d.ts +9 -0
- package/SystemParcel/SystemParcel.js +46 -0
- package/SystemParcel/helpers.d.ts +7 -0
- package/SystemParcel/helpers.js +14 -0
- package/SystemParcel/index.d.ts +2 -0
- package/SystemParcel/index.js +2 -0
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type SystemParcelProps = {
|
|
3
|
+
importPath: string;
|
|
4
|
+
methodName?: string;
|
|
5
|
+
mountRootParcel: any;
|
|
6
|
+
Parcel: React.ComponentType<any>;
|
|
7
|
+
} & Record<string, unknown>;
|
|
8
|
+
export declare function SystemParcel({ importPath, mountRootParcel, methodName, Parcel, ...restProps }: SystemParcelProps): React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { useSPAContext } from '../context';
|
|
3
|
+
export function SystemParcel({
|
|
4
|
+
importPath,
|
|
5
|
+
mountRootParcel,
|
|
6
|
+
methodName = 'parcel',
|
|
7
|
+
Parcel,
|
|
8
|
+
...restProps
|
|
9
|
+
}) {
|
|
10
|
+
const spaContext = useSPAContext();
|
|
11
|
+
const parcelConfig = useMemo(() => createSystemParcelConfig(importPath, methodName), [importPath, methodName]);
|
|
12
|
+
return React.createElement(Parcel, {
|
|
13
|
+
config: parcelConfig,
|
|
14
|
+
spaContext: spaContext,
|
|
15
|
+
mountParcel: mountRootParcel,
|
|
16
|
+
...restProps
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function createSystemParcelConfig(importPath, methodName) {
|
|
20
|
+
let parcel;
|
|
21
|
+
return {
|
|
22
|
+
bootstrap({
|
|
23
|
+
domElement
|
|
24
|
+
}) {
|
|
25
|
+
return System.import(importPath).then(module => {
|
|
26
|
+
const factory = module[methodName];
|
|
27
|
+
if (typeof factory !== 'function') {
|
|
28
|
+
throw new Error(`Method "${methodName}" is not a function in module "${importPath}"`);
|
|
29
|
+
}
|
|
30
|
+
parcel = factory(domElement);
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
mount(props) {
|
|
34
|
+
parcel.render(props);
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
},
|
|
37
|
+
unmount() {
|
|
38
|
+
parcel.unmount();
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
},
|
|
41
|
+
update(props) {
|
|
42
|
+
parcel.render(props);
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
type ParcelResult<T> = {
|
|
3
|
+
render: (props: T) => void;
|
|
4
|
+
unmount: () => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function createParcelFunction<T>(render: (props: T) => ReactElement): (container: HTMLElement) => ParcelResult<T>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRoot } from 'react-dom/client';
|
|
2
|
+
export function createParcelFunction(render) {
|
|
3
|
+
return container => {
|
|
4
|
+
const root = createRoot(container);
|
|
5
|
+
return {
|
|
6
|
+
render(props) {
|
|
7
|
+
root.render(render(props));
|
|
8
|
+
},
|
|
9
|
+
unmount() {
|
|
10
|
+
root.unmount();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED