@blocklet/pages-kit 0.2.220 → 0.2.222
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/lib/cjs/builtin/mui/material.js +5 -1
- package/lib/cjs/components/CustomComponentRenderer/index.js +12 -12
- package/lib/cjs/utils/preload-client.js +51 -0
- package/lib/esm/builtin/mui/material.js +2 -0
- package/lib/esm/components/CustomComponentRenderer/index.js +12 -12
- package/lib/esm/utils/preload-client.js +47 -0
- package/lib/types/builtin/mui/material.d.ts +2 -0
- package/lib/types/components/CustomComponentRenderer/index.d.ts +1 -1
- package/lib/types/utils/preload-client.d.ts +8 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextField = exports.Switch = exports.Stack = exports.Popper = exports.Paper = exports.DialogTitle = exports.DialogContent = exports.DialogActions = exports.Dialog = exports.ClickAwayListener = exports.Button = exports.Box = exports.Autocomplete = void 0;
|
|
3
|
+
exports.Typography = exports.Container = exports.TextField = exports.Switch = exports.Stack = exports.Popper = exports.Paper = exports.DialogTitle = exports.DialogContent = exports.DialogActions = exports.Dialog = exports.ClickAwayListener = exports.Button = exports.Box = exports.Autocomplete = void 0;
|
|
4
4
|
var material_1 = require("@mui/material");
|
|
5
5
|
Object.defineProperty(exports, "Autocomplete", { enumerable: true, get: function () { return material_1.Autocomplete; } });
|
|
6
6
|
var material_2 = require("@mui/material");
|
|
@@ -27,3 +27,7 @@ var material_12 = require("@mui/material");
|
|
|
27
27
|
Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return material_12.Switch; } });
|
|
28
28
|
var material_13 = require("@mui/material");
|
|
29
29
|
Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return material_13.TextField; } });
|
|
30
|
+
var material_14 = require("@mui/material");
|
|
31
|
+
Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return material_14.Container; } });
|
|
32
|
+
var material_15 = require("@mui/material");
|
|
33
|
+
Object.defineProperty(exports, "Typography", { enumerable: true, get: function () { return material_15.Typography; } });
|
|
@@ -56,8 +56,8 @@ const property_1 = require("../../utils/property");
|
|
|
56
56
|
const MAXIMUM_RENDER_STACK_SIZE = 20;
|
|
57
57
|
function CustomComponentRenderer(_a) {
|
|
58
58
|
var _b;
|
|
59
|
-
var props = __rest(_a, []);
|
|
60
|
-
return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: (0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
|
|
59
|
+
var { defaultLocale = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config.defaultLocale } = _a, props = __rest(_a, ["defaultLocale"]);
|
|
60
|
+
return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: (0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { defaultLocale: defaultLocale, instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
|
|
61
61
|
}
|
|
62
62
|
exports.default = CustomComponentRenderer;
|
|
63
63
|
function ComponentRenderer(_a) {
|
|
@@ -151,7 +151,7 @@ function loadRemoteComponent({ mode, instanceId, componentId, locale, }) {
|
|
|
151
151
|
}));
|
|
152
152
|
return LOAD_REMOTE_COMPONENT_TASKS[key];
|
|
153
153
|
}
|
|
154
|
-
function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters,
|
|
154
|
+
function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters, }) {
|
|
155
155
|
var _a;
|
|
156
156
|
const scriptRef = (0, react_1.useRef)({});
|
|
157
157
|
const preloadComponent = (0, react_1.useMemo)(() => getScriptComponent(componentId), [componentId, PRELOAD_COMPONENTS_STATE_KEY]);
|
|
@@ -162,17 +162,10 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
|
|
|
162
162
|
const preloadDefaultState = (0, react_1.useMemo)(() => {
|
|
163
163
|
var _a, _b;
|
|
164
164
|
return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[defaultLocale];
|
|
165
|
-
}, [instanceId,
|
|
165
|
+
}, [instanceId, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
|
|
166
166
|
const previousPreload = (0, react_1.useRef)();
|
|
167
167
|
const [, update] = (0, react_1.useState)(0);
|
|
168
|
-
if ((
|
|
169
|
-
previousPreload.current = {
|
|
170
|
-
Component: preloadComponent.Component,
|
|
171
|
-
properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
|
|
172
|
-
};
|
|
173
|
-
return previousPreload.current;
|
|
174
|
-
}
|
|
175
|
-
if (!(components === null || components === void 0 ? void 0 : components.length) && preloadComponent) {
|
|
168
|
+
if (!(components === null || components === void 0 ? void 0 : components.length) && !preloadState && preloadComponent) {
|
|
176
169
|
loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale }).then(() => {
|
|
177
170
|
update(PRELOAD_COMPONENTS_STATE_KEY);
|
|
178
171
|
});
|
|
@@ -180,6 +173,13 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
|
|
|
180
173
|
return previousPreload.current;
|
|
181
174
|
}
|
|
182
175
|
}
|
|
176
|
+
if ((preloadState || preloadDefaultState) && preloadComponent) {
|
|
177
|
+
previousPreload.current = {
|
|
178
|
+
Component: preloadComponent.Component,
|
|
179
|
+
properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
|
|
180
|
+
};
|
|
181
|
+
return previousPreload.current;
|
|
182
|
+
}
|
|
183
183
|
const component = (0, property_1.mergeComponent)({
|
|
184
184
|
componentId,
|
|
185
185
|
getComponent: (componentId) => components === null || components === void 0 ? void 0 : components.find((i) => i.id === componentId),
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var _a;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.loadAndInjectComponents = exports.PRELOAD_COMPONENTS_STATE = void 0;
|
|
14
|
+
const api_1 = require("../api");
|
|
15
|
+
const preload_1 = require("../types/preload");
|
|
16
|
+
(_a = window[preload_1.PreloadComponentsStateGlobalVariableName]) !== null && _a !== void 0 ? _a : (window[preload_1.PreloadComponentsStateGlobalVariableName] = {
|
|
17
|
+
config: {},
|
|
18
|
+
components: {},
|
|
19
|
+
props: {},
|
|
20
|
+
});
|
|
21
|
+
exports.PRELOAD_COMPONENTS_STATE = window[preload_1.PreloadComponentsStateGlobalVariableName];
|
|
22
|
+
function loadAndInjectComponents({ mode, name, locale, }) {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f;
|
|
24
|
+
var _g, _h, _j;
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { components, props } = exports.PRELOAD_COMPONENTS_STATE;
|
|
27
|
+
const c = Object.values(components).find((i) => !!i.component.name && i.component.name.toLowerCase() === name.toLowerCase());
|
|
28
|
+
if (c && props[c.component.id]) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const result = yield (0, api_1.preloadComponents)({ mode, name, locale });
|
|
32
|
+
const componentId = Object.keys(result.props)[0];
|
|
33
|
+
for (const i of Object.values(result.components)) {
|
|
34
|
+
if (!window[i.script.umd.moduleName]) {
|
|
35
|
+
const script = document.createElement('script');
|
|
36
|
+
script.textContent = i.script.umd.script;
|
|
37
|
+
document.body.appendChild(script);
|
|
38
|
+
}
|
|
39
|
+
exports.PRELOAD_COMPONENTS_STATE.components[i.component.id] = {
|
|
40
|
+
preloadComponentModuleName: i.script.umd.moduleName,
|
|
41
|
+
component: i.component,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
(_a = (_g = exports.PRELOAD_COMPONENTS_STATE.props)[componentId]) !== null && _a !== void 0 ? _a : (_g[componentId] = {});
|
|
45
|
+
(_b = (_h = exports.PRELOAD_COMPONENTS_STATE.props[componentId]).locales) !== null && _b !== void 0 ? _b : (_h.locales = {});
|
|
46
|
+
(_c = (_j = exports.PRELOAD_COMPONENTS_STATE.props[componentId].locales)[locale]) !== null && _c !== void 0 ? _c : (_j[locale] = {});
|
|
47
|
+
exports.PRELOAD_COMPONENTS_STATE.props[componentId].locales[locale].props =
|
|
48
|
+
(_f = (_e = (_d = result.props[componentId]) === null || _d === void 0 ? void 0 : _d.locales) === null || _e === void 0 ? void 0 : _e[locale]) === null || _f === void 0 ? void 0 : _f.props;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.loadAndInjectComponents = loadAndInjectComponents;
|
|
@@ -30,8 +30,8 @@ import { RenderNestedComponent, mergeComponent } from '../../utils/property';
|
|
|
30
30
|
const MAXIMUM_RENDER_STACK_SIZE = 20;
|
|
31
31
|
export default function CustomComponentRenderer(_a) {
|
|
32
32
|
var _b;
|
|
33
|
-
var props = __rest(_a, []);
|
|
34
|
-
return (_jsx(ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: _jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
|
|
33
|
+
var { defaultLocale = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config.defaultLocale } = _a, props = __rest(_a, ["defaultLocale"]);
|
|
34
|
+
return (_jsx(ErrorBoundary, { fallbackRender: E, resetKeys: [Date.now()], children: _jsx(ComponentRenderer, Object.assign({}, props, { defaultLocale: defaultLocale, instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
|
|
35
35
|
}
|
|
36
36
|
function ComponentRenderer(_a) {
|
|
37
37
|
var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
|
|
@@ -124,7 +124,7 @@ function loadRemoteComponent({ mode, instanceId, componentId, locale, }) {
|
|
|
124
124
|
}));
|
|
125
125
|
return LOAD_REMOTE_COMPONENT_TASKS[key];
|
|
126
126
|
}
|
|
127
|
-
function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters,
|
|
127
|
+
function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters, }) {
|
|
128
128
|
var _a;
|
|
129
129
|
const scriptRef = useRef({});
|
|
130
130
|
const preloadComponent = useMemo(() => getScriptComponent(componentId), [componentId, PRELOAD_COMPONENTS_STATE_KEY]);
|
|
@@ -135,17 +135,10 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
|
|
|
135
135
|
const preloadDefaultState = useMemo(() => {
|
|
136
136
|
var _a, _b;
|
|
137
137
|
return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[defaultLocale];
|
|
138
|
-
}, [instanceId,
|
|
138
|
+
}, [instanceId, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
|
|
139
139
|
const previousPreload = useRef();
|
|
140
140
|
const [, update] = useState(0);
|
|
141
|
-
if ((
|
|
142
|
-
previousPreload.current = {
|
|
143
|
-
Component: preloadComponent.Component,
|
|
144
|
-
properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
|
|
145
|
-
};
|
|
146
|
-
return previousPreload.current;
|
|
147
|
-
}
|
|
148
|
-
if (!(components === null || components === void 0 ? void 0 : components.length) && preloadComponent) {
|
|
141
|
+
if (!(components === null || components === void 0 ? void 0 : components.length) && !preloadState && preloadComponent) {
|
|
149
142
|
loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale }).then(() => {
|
|
150
143
|
update(PRELOAD_COMPONENTS_STATE_KEY);
|
|
151
144
|
});
|
|
@@ -153,6 +146,13 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
|
|
|
153
146
|
return previousPreload.current;
|
|
154
147
|
}
|
|
155
148
|
}
|
|
149
|
+
if ((preloadState || preloadDefaultState) && preloadComponent) {
|
|
150
|
+
previousPreload.current = {
|
|
151
|
+
Component: preloadComponent.Component,
|
|
152
|
+
properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
|
|
153
|
+
};
|
|
154
|
+
return previousPreload.current;
|
|
155
|
+
}
|
|
156
156
|
const component = mergeComponent({
|
|
157
157
|
componentId,
|
|
158
158
|
getComponent: (componentId) => components === null || components === void 0 ? void 0 : components.find((i) => i.id === componentId),
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var _a;
|
|
11
|
+
import { preloadComponents } from '../api';
|
|
12
|
+
import { PreloadComponentsStateGlobalVariableName } from '../types/preload';
|
|
13
|
+
(_a = window[PreloadComponentsStateGlobalVariableName]) !== null && _a !== void 0 ? _a : (window[PreloadComponentsStateGlobalVariableName] = {
|
|
14
|
+
config: {},
|
|
15
|
+
components: {},
|
|
16
|
+
props: {},
|
|
17
|
+
});
|
|
18
|
+
export const PRELOAD_COMPONENTS_STATE = window[PreloadComponentsStateGlobalVariableName];
|
|
19
|
+
export function loadAndInjectComponents({ mode, name, locale, }) {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f;
|
|
21
|
+
var _g, _h, _j;
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const { components, props } = PRELOAD_COMPONENTS_STATE;
|
|
24
|
+
const c = Object.values(components).find((i) => !!i.component.name && i.component.name.toLowerCase() === name.toLowerCase());
|
|
25
|
+
if (c && props[c.component.id]) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const result = yield preloadComponents({ mode, name, locale });
|
|
29
|
+
const componentId = Object.keys(result.props)[0];
|
|
30
|
+
for (const i of Object.values(result.components)) {
|
|
31
|
+
if (!window[i.script.umd.moduleName]) {
|
|
32
|
+
const script = document.createElement('script');
|
|
33
|
+
script.textContent = i.script.umd.script;
|
|
34
|
+
document.body.appendChild(script);
|
|
35
|
+
}
|
|
36
|
+
PRELOAD_COMPONENTS_STATE.components[i.component.id] = {
|
|
37
|
+
preloadComponentModuleName: i.script.umd.moduleName,
|
|
38
|
+
component: i.component,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
(_a = (_g = PRELOAD_COMPONENTS_STATE.props)[componentId]) !== null && _a !== void 0 ? _a : (_g[componentId] = {});
|
|
42
|
+
(_b = (_h = PRELOAD_COMPONENTS_STATE.props[componentId]).locales) !== null && _b !== void 0 ? _b : (_h.locales = {});
|
|
43
|
+
(_c = (_j = PRELOAD_COMPONENTS_STATE.props[componentId].locales)[locale]) !== null && _c !== void 0 ? _c : (_j[locale] = {});
|
|
44
|
+
PRELOAD_COMPONENTS_STATE.props[componentId].locales[locale].props =
|
|
45
|
+
(_f = (_e = (_d = result.props[componentId]) === null || _d === void 0 ? void 0 : _d.locales) === null || _e === void 0 ? void 0 : _e[locale]) === null || _f === void 0 ? void 0 : _f.props;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -17,5 +17,5 @@ export interface CustomComponentRendererProps {
|
|
|
17
17
|
[key: string]: any;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
export default function CustomComponentRenderer({ ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export default function CustomComponentRenderer({ defaultLocale, ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
21
21
|
export declare function transpileAndLoadScript(script: string): Promise<any>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StateMode } from '../types';
|
|
2
|
+
import { PreloadComponentsState } from '../types/preload';
|
|
3
|
+
export declare const PRELOAD_COMPONENTS_STATE: PreloadComponentsState;
|
|
4
|
+
export declare function loadAndInjectComponents({ mode, name, locale, }: {
|
|
5
|
+
mode?: StateMode;
|
|
6
|
+
name: string;
|
|
7
|
+
locale: string;
|
|
8
|
+
}): Promise<void>;
|