@blocklet/pages-kit 0.2.214 → 0.2.216
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/api/call.js +7 -2
- package/lib/cjs/api/pages-kit.js +2 -1
- package/lib/cjs/builtin/iconify/react.js +5 -0
- package/lib/cjs/builtin/mui/lab.js +5 -0
- package/lib/cjs/builtin/mui/material.js +29 -0
- package/lib/cjs/builtin/react-hook-form.js +17 -0
- package/lib/cjs/builtin/react.js +37 -0
- package/lib/cjs/builtin/utils.js +6 -0
- package/lib/cjs/builtin/zustand/middleware/immer.js +17 -0
- package/lib/cjs/builtin/zustand.js +17 -0
- package/lib/cjs/components/CustomComponentRenderer/index.js +59 -36
- package/lib/cjs/types/builtin.js +4 -0
- package/lib/cjs/utils/inject-global-components.js +53 -0
- package/lib/cjs/utils/preload.js +19 -14
- package/lib/cjs/utils/property.js +20 -7
- package/lib/cjs/utils/typescript/builtin-module-transformer.js +55 -0
- package/lib/esm/api/call.js +7 -2
- package/lib/esm/api/pages-kit.js +2 -1
- package/lib/esm/builtin/iconify/react.js +1 -0
- package/lib/esm/builtin/mui/lab.js +1 -0
- package/lib/esm/builtin/mui/material.js +13 -0
- package/lib/esm/builtin/react-hook-form.js +1 -0
- package/lib/esm/builtin/react.js +1 -0
- package/lib/esm/builtin/utils.js +1 -0
- package/lib/esm/builtin/zustand/middleware/immer.js +1 -0
- package/lib/esm/builtin/zustand.js +1 -0
- package/lib/esm/components/CustomComponentRenderer/index.js +59 -38
- package/lib/esm/types/builtin.js +1 -0
- package/lib/esm/utils/inject-global-components.js +28 -0
- package/lib/esm/utils/preload.js +19 -14
- package/lib/esm/utils/property.js +19 -6
- package/lib/esm/utils/typescript/builtin-module-transformer.js +51 -0
- package/lib/types/api/call.d.ts +1 -1
- package/lib/types/api/pages-kit.d.ts +1 -1
- package/lib/types/builtin/iconify/react.d.ts +1 -0
- package/lib/types/builtin/mui/lab.d.ts +1 -0
- package/lib/types/builtin/mui/material.d.ts +13 -0
- package/lib/types/builtin/react-hook-form.d.ts +1 -0
- package/lib/types/builtin/react.d.ts +1 -0
- package/lib/types/builtin/utils.d.ts +1 -0
- package/lib/types/builtin/zustand/middleware/immer.d.ts +1 -0
- package/lib/types/builtin/zustand.d.ts +1 -0
- package/lib/types/components/CustomComponentRenderer/index.d.ts +8 -0
- package/lib/types/types/api.d.ts +14 -11
- package/lib/types/types/builtin.d.ts +1 -0
- package/lib/types/types/core.d.ts +38 -11
- package/lib/types/types/preload.d.ts +8 -8
- package/lib/types/utils/inject-global-components.d.ts +1 -0
- package/lib/types/utils/preload.d.ts +2 -2
- package/lib/types/utils/property.d.ts +5 -1
- package/lib/types/utils/typescript/builtin-module-transformer.d.ts +2 -0
- package/package.json +15 -4
package/lib/cjs/api/call.js
CHANGED
|
@@ -11,13 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.preloadComponents = void 0;
|
|
13
13
|
const component_1 = require("@blocklet/sdk/lib/component");
|
|
14
|
-
function preloadComponents({ mode, name, id }) {
|
|
14
|
+
function preloadComponents({ mode, name, id, locale, }) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
return (0, component_1.call)({
|
|
17
17
|
name: 'pages-kit',
|
|
18
18
|
method: 'GET',
|
|
19
19
|
path: '/api/components/preload',
|
|
20
|
-
params: {
|
|
20
|
+
params: {
|
|
21
|
+
mode,
|
|
22
|
+
id: Array.isArray(id) ? id.join(',') : id,
|
|
23
|
+
name: Array.isArray(name) ? name.join(',') : name,
|
|
24
|
+
locale,
|
|
25
|
+
},
|
|
21
26
|
}).then((res) => res.data);
|
|
22
27
|
});
|
|
23
28
|
}
|
package/lib/cjs/api/pages-kit.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.preloadComponents = void 0;
|
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const ufo_1 = require("ufo");
|
|
18
18
|
const PAGES_KIT_DID = 'z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o';
|
|
19
|
-
function preloadComponents({ mode, name, id }) {
|
|
19
|
+
function preloadComponents({ mode, name, id, locale, }) {
|
|
20
20
|
var _a, _b;
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
const prefix = ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.did === PAGES_KIT_DID)) === null || _b === void 0 ? void 0 : _b.mountPoint) || '/';
|
|
@@ -26,6 +26,7 @@ function preloadComponents({ mode, name, id }) {
|
|
|
26
26
|
mode,
|
|
27
27
|
id: Array.isArray(id) ? id.join(',') : id,
|
|
28
28
|
name: Array.isArray(name) ? name.join(',') : name,
|
|
29
|
+
locale,
|
|
29
30
|
},
|
|
30
31
|
})
|
|
31
32
|
.then((res) => res.data);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
var material_1 = require("@mui/material");
|
|
5
|
+
Object.defineProperty(exports, "Autocomplete", { enumerable: true, get: function () { return material_1.Autocomplete; } });
|
|
6
|
+
var material_2 = require("@mui/material");
|
|
7
|
+
Object.defineProperty(exports, "Box", { enumerable: true, get: function () { return material_2.Box; } });
|
|
8
|
+
var material_3 = require("@mui/material");
|
|
9
|
+
Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return material_3.Button; } });
|
|
10
|
+
var material_4 = require("@mui/material");
|
|
11
|
+
Object.defineProperty(exports, "ClickAwayListener", { enumerable: true, get: function () { return material_4.ClickAwayListener; } });
|
|
12
|
+
var material_5 = require("@mui/material");
|
|
13
|
+
Object.defineProperty(exports, "Dialog", { enumerable: true, get: function () { return material_5.Dialog; } });
|
|
14
|
+
var material_6 = require("@mui/material");
|
|
15
|
+
Object.defineProperty(exports, "DialogActions", { enumerable: true, get: function () { return material_6.DialogActions; } });
|
|
16
|
+
var material_7 = require("@mui/material");
|
|
17
|
+
Object.defineProperty(exports, "DialogContent", { enumerable: true, get: function () { return material_7.DialogContent; } });
|
|
18
|
+
var material_8 = require("@mui/material");
|
|
19
|
+
Object.defineProperty(exports, "DialogTitle", { enumerable: true, get: function () { return material_8.DialogTitle; } });
|
|
20
|
+
var material_9 = require("@mui/material");
|
|
21
|
+
Object.defineProperty(exports, "Paper", { enumerable: true, get: function () { return material_9.Paper; } });
|
|
22
|
+
var material_10 = require("@mui/material");
|
|
23
|
+
Object.defineProperty(exports, "Popper", { enumerable: true, get: function () { return material_10.Popper; } });
|
|
24
|
+
var material_11 = require("@mui/material");
|
|
25
|
+
Object.defineProperty(exports, "Stack", { enumerable: true, get: function () { return material_11.Stack; } });
|
|
26
|
+
var material_12 = require("@mui/material");
|
|
27
|
+
Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return material_12.Switch; } });
|
|
28
|
+
var material_13 = require("@mui/material");
|
|
29
|
+
Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return material_13.TextField; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("react-hook-form"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.version = exports.useTransition = exports.useSyncExternalStore = exports.useState = exports.useRef = exports.useReducer = exports.useMemo = exports.useLayoutEffect = exports.useInsertionEffect = exports.useImperativeHandle = exports.useId = exports.useEffect = exports.useDeferredValue = exports.useDebugValue = exports.useContext = exports.useCallback = exports.startTransition = exports.memo = exports.lazy = exports.isValidElement = exports.forwardRef = exports.createRef = exports.createFactory = exports.createElement = exports.createContext = exports.cloneElement = exports.Suspense = exports.StrictMode = exports.PureComponent = exports.Profiler = exports.Fragment = exports.Component = exports.Children = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
Object.defineProperty(exports, "Children", { enumerable: true, get: function () { return react_1.Children; } });
|
|
6
|
+
Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return react_1.Component; } });
|
|
7
|
+
Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return react_1.Fragment; } });
|
|
8
|
+
Object.defineProperty(exports, "Profiler", { enumerable: true, get: function () { return react_1.Profiler; } });
|
|
9
|
+
Object.defineProperty(exports, "PureComponent", { enumerable: true, get: function () { return react_1.PureComponent; } });
|
|
10
|
+
Object.defineProperty(exports, "StrictMode", { enumerable: true, get: function () { return react_1.StrictMode; } });
|
|
11
|
+
Object.defineProperty(exports, "Suspense", { enumerable: true, get: function () { return react_1.Suspense; } });
|
|
12
|
+
Object.defineProperty(exports, "cloneElement", { enumerable: true, get: function () { return react_1.cloneElement; } });
|
|
13
|
+
Object.defineProperty(exports, "createContext", { enumerable: true, get: function () { return react_1.createContext; } });
|
|
14
|
+
Object.defineProperty(exports, "createElement", { enumerable: true, get: function () { return react_1.createElement; } });
|
|
15
|
+
Object.defineProperty(exports, "createFactory", { enumerable: true, get: function () { return react_1.createFactory; } });
|
|
16
|
+
Object.defineProperty(exports, "createRef", { enumerable: true, get: function () { return react_1.createRef; } });
|
|
17
|
+
Object.defineProperty(exports, "forwardRef", { enumerable: true, get: function () { return react_1.forwardRef; } });
|
|
18
|
+
Object.defineProperty(exports, "isValidElement", { enumerable: true, get: function () { return react_1.isValidElement; } });
|
|
19
|
+
Object.defineProperty(exports, "lazy", { enumerable: true, get: function () { return react_1.lazy; } });
|
|
20
|
+
Object.defineProperty(exports, "memo", { enumerable: true, get: function () { return react_1.memo; } });
|
|
21
|
+
Object.defineProperty(exports, "startTransition", { enumerable: true, get: function () { return react_1.startTransition; } });
|
|
22
|
+
Object.defineProperty(exports, "useCallback", { enumerable: true, get: function () { return react_1.useCallback; } });
|
|
23
|
+
Object.defineProperty(exports, "useContext", { enumerable: true, get: function () { return react_1.useContext; } });
|
|
24
|
+
Object.defineProperty(exports, "useDebugValue", { enumerable: true, get: function () { return react_1.useDebugValue; } });
|
|
25
|
+
Object.defineProperty(exports, "useDeferredValue", { enumerable: true, get: function () { return react_1.useDeferredValue; } });
|
|
26
|
+
Object.defineProperty(exports, "useEffect", { enumerable: true, get: function () { return react_1.useEffect; } });
|
|
27
|
+
Object.defineProperty(exports, "useId", { enumerable: true, get: function () { return react_1.useId; } });
|
|
28
|
+
Object.defineProperty(exports, "useImperativeHandle", { enumerable: true, get: function () { return react_1.useImperativeHandle; } });
|
|
29
|
+
Object.defineProperty(exports, "useInsertionEffect", { enumerable: true, get: function () { return react_1.useInsertionEffect; } });
|
|
30
|
+
Object.defineProperty(exports, "useLayoutEffect", { enumerable: true, get: function () { return react_1.useLayoutEffect; } });
|
|
31
|
+
Object.defineProperty(exports, "useMemo", { enumerable: true, get: function () { return react_1.useMemo; } });
|
|
32
|
+
Object.defineProperty(exports, "useReducer", { enumerable: true, get: function () { return react_1.useReducer; } });
|
|
33
|
+
Object.defineProperty(exports, "useRef", { enumerable: true, get: function () { return react_1.useRef; } });
|
|
34
|
+
Object.defineProperty(exports, "useState", { enumerable: true, get: function () { return react_1.useState; } });
|
|
35
|
+
Object.defineProperty(exports, "useSyncExternalStore", { enumerable: true, get: function () { return react_1.useSyncExternalStore; } });
|
|
36
|
+
Object.defineProperty(exports, "useTransition", { enumerable: true, get: function () { return react_1.useTransition; } });
|
|
37
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return react_1.version; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withQuery = exports.joinURL = void 0;
|
|
4
|
+
var ufo_1 = require("ufo");
|
|
5
|
+
Object.defineProperty(exports, "joinURL", { enumerable: true, get: function () { return ufo_1.joinURL; } });
|
|
6
|
+
Object.defineProperty(exports, "withQuery", { enumerable: true, get: function () { return ufo_1.withQuery; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("zustand/middleware/immer"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("zustand"), exports);
|
|
@@ -43,51 +43,60 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
43
43
|
return t;
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.transpileAndLoadScript = void 0;
|
|
46
47
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
47
|
-
|
|
48
|
+
require("../../utils/inject-global-components");
|
|
48
49
|
const material_1 = require("@mui/material");
|
|
49
|
-
const
|
|
50
|
+
const lodash_1 = require("lodash");
|
|
51
|
+
const react_1 = require("react");
|
|
50
52
|
const react_error_boundary_1 = require("react-error-boundary");
|
|
51
|
-
const ufo_1 = require("ufo");
|
|
52
53
|
const preload_1 = require("../../types/preload");
|
|
53
54
|
const property_1 = require("../../utils/property");
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
win.joinURL = ufo_1.joinURL;
|
|
57
|
-
win.withQuery = ufo_1.withQuery;
|
|
58
|
-
win.React = react_2.default;
|
|
59
|
-
win.Box = material_1.Box;
|
|
60
|
-
win.Stack = material_1.Stack;
|
|
61
|
-
win.Button = material_1.Button;
|
|
62
|
-
win.IconifyIcon = react_1.Icon;
|
|
55
|
+
const builtin_module_transformer_1 = require("../../utils/typescript/builtin-module-transformer");
|
|
56
|
+
const MAXIMUM_RENDER_STACK_SIZE = 50;
|
|
63
57
|
function CustomComponentRenderer(_a) {
|
|
58
|
+
var _b;
|
|
64
59
|
var props = __rest(_a, []);
|
|
65
|
-
return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: E, children: (0, jsx_runtime_1.jsx)(
|
|
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 })) }));
|
|
66
61
|
}
|
|
67
62
|
exports.default = CustomComponentRenderer;
|
|
63
|
+
function ComponentRenderer(_a) {
|
|
64
|
+
var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
|
|
65
|
+
if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
|
|
66
|
+
throw new Error('Maximum render stack size exceeded');
|
|
67
|
+
}
|
|
68
|
+
return (0, jsx_runtime_1.jsx)(Renderer, Object.assign({ renderCount: renderCount + 1 }, props));
|
|
69
|
+
}
|
|
68
70
|
function Renderer(props) {
|
|
69
|
-
const component =
|
|
71
|
+
const component = useComponent(props);
|
|
70
72
|
if (!component)
|
|
71
73
|
return null;
|
|
72
74
|
const { Component, AsyncComponent, properties } = component;
|
|
75
|
+
const componentProps = Object.fromEntries(Object.entries(Object.assign(Object.assign({}, properties), props.props)).map(([key, val]) => {
|
|
76
|
+
return [
|
|
77
|
+
key,
|
|
78
|
+
(val === null || val === void 0 ? void 0 : val.type) === property_1.RenderNestedComponent ? ((0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, (0, lodash_1.pick)(props, 'components', 'locale', 'defaultLocale'), { instanceId: key, renderCount: props.renderCount, componentId: val.componentId, properties: val.properties, props: val.props }))) : (val),
|
|
79
|
+
];
|
|
80
|
+
}));
|
|
73
81
|
if (Component) {
|
|
74
|
-
return (0, jsx_runtime_1.jsx)(Component, Object.assign({},
|
|
82
|
+
return (0, jsx_runtime_1.jsx)(Component, Object.assign({}, componentProps));
|
|
75
83
|
}
|
|
76
84
|
if (AsyncComponent) {
|
|
77
|
-
return (0, jsx_runtime_1.jsx)(AsyncComponentRenderer, { AsyncComponent: AsyncComponent,
|
|
85
|
+
return (0, jsx_runtime_1.jsx)(AsyncComponentRenderer, Object.assign({ AsyncComponent: AsyncComponent }, componentProps));
|
|
78
86
|
}
|
|
79
87
|
return null;
|
|
80
88
|
}
|
|
81
|
-
function AsyncComponentRenderer(
|
|
82
|
-
|
|
83
|
-
(0,
|
|
84
|
-
|
|
89
|
+
function AsyncComponentRenderer(_a) {
|
|
90
|
+
var { AsyncComponent } = _a, props = __rest(_a, ["AsyncComponent"]);
|
|
91
|
+
const [{ Component, error }, setState] = (0, react_1.useState)({});
|
|
92
|
+
(0, react_1.useEffect)(() => {
|
|
93
|
+
AsyncComponent.then((m) => setState({ Component: m.default, key: Date.now() })).catch((error) => setState({ error }));
|
|
85
94
|
}, [AsyncComponent]);
|
|
86
95
|
if (error) {
|
|
87
96
|
return (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.stack });
|
|
88
97
|
}
|
|
89
98
|
if (Component) {
|
|
90
|
-
return (
|
|
99
|
+
return (0, jsx_runtime_1.jsx)(Component, Object.assign({}, props));
|
|
91
100
|
}
|
|
92
101
|
return null;
|
|
93
102
|
}
|
|
@@ -95,20 +104,26 @@ function E({ error }) {
|
|
|
95
104
|
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }) }));
|
|
96
105
|
}
|
|
97
106
|
const PRELOAD_COMPONENTS_STATE = window[preload_1.PreloadComponentsStateGlobalVariableName];
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
function useComponent({ instanceId, componentId, components, locale, defaultLocale, properties: parameters, props, }) {
|
|
108
|
+
const scriptRef = (0, react_1.useRef)({});
|
|
109
|
+
const preloadComponent = (0, react_1.useMemo)(() => {
|
|
110
|
+
const preload = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components[componentId];
|
|
111
|
+
if (preload) {
|
|
112
|
+
const mod = window[preload.preloadComponentModuleName];
|
|
113
|
+
if (typeof mod === 'function') {
|
|
114
|
+
return { component: preload.component, Component: mod() };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}, [componentId]);
|
|
119
|
+
const preloadState = (0, react_1.useMemo)(() => {
|
|
120
|
+
var _a;
|
|
121
|
+
return (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a[locale];
|
|
122
|
+
}, [instanceId, locale]);
|
|
123
|
+
if ((props || preloadState) && preloadComponent) {
|
|
109
124
|
return {
|
|
110
|
-
Component:
|
|
111
|
-
properties:
|
|
125
|
+
Component: preloadComponent.Component,
|
|
126
|
+
properties: preloadState,
|
|
112
127
|
};
|
|
113
128
|
}
|
|
114
129
|
const component = (0, property_1.mergeComponent)({
|
|
@@ -120,8 +135,12 @@ function loadComponent({ componentId, components, locale, defaultLocale, propert
|
|
|
120
135
|
});
|
|
121
136
|
if (!component)
|
|
122
137
|
return null;
|
|
138
|
+
if (scriptRef.current.script !== component.script) {
|
|
139
|
+
scriptRef.current.script = component.script;
|
|
140
|
+
scriptRef.current.module = transpileAndLoadScript(component.script);
|
|
141
|
+
}
|
|
123
142
|
return {
|
|
124
|
-
AsyncComponent:
|
|
143
|
+
AsyncComponent: scriptRef.current.module,
|
|
125
144
|
properties: component.properties,
|
|
126
145
|
};
|
|
127
146
|
}
|
|
@@ -129,9 +148,13 @@ function transpileAndLoadScript(script) {
|
|
|
129
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
149
|
const ts = yield Promise.resolve().then(() => __importStar(require('typescript')));
|
|
131
150
|
const compiled = ts.transpileModule(script, {
|
|
132
|
-
compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext },
|
|
151
|
+
compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
|
|
152
|
+
transformers: {
|
|
153
|
+
before: [(0, builtin_module_transformer_1.createBuiltinModuleTransformer)(ts)],
|
|
154
|
+
},
|
|
133
155
|
}).outputText;
|
|
134
156
|
const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
|
|
135
157
|
return Promise.resolve(`${url}`).then(s => __importStar(require(s)));
|
|
136
158
|
});
|
|
137
159
|
}
|
|
160
|
+
exports.transpileAndLoadScript = transpileAndLoadScript;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const builtinIconifyReact = __importStar(require("../builtin/iconify/react"));
|
|
27
|
+
const builtinMuiLab = __importStar(require("../builtin/mui/lab"));
|
|
28
|
+
const builtinMuiMaterial = __importStar(require("../builtin/mui/material"));
|
|
29
|
+
const builtinReact = __importStar(require("../builtin/react"));
|
|
30
|
+
const builtinReactHookForm = __importStar(require("../builtin/react-hook-form"));
|
|
31
|
+
const builtinUtils = __importStar(require("../builtin/utils"));
|
|
32
|
+
const builtinZustand = __importStar(require("../builtin/zustand"));
|
|
33
|
+
const builtinZustandMiddlewareImmer = __importStar(require("../builtin/zustand/middleware/immer"));
|
|
34
|
+
const builtin_1 = require("../types/builtin");
|
|
35
|
+
function injectGlobalComponents() {
|
|
36
|
+
const win = window;
|
|
37
|
+
win[builtin_1.BuiltinModulesGlobalVariableName] = {
|
|
38
|
+
modules: {
|
|
39
|
+
'@blocklet/pages-kit/builtin/utils': builtinUtils,
|
|
40
|
+
'@blocklet/pages-kit/builtin/react': builtinReact,
|
|
41
|
+
'@blocklet/pages-kit/builtin/mui/material': builtinMuiMaterial,
|
|
42
|
+
'@blocklet/pages-kit/builtin/mui/lab': builtinMuiLab,
|
|
43
|
+
'@blocklet/pages-kit/builtin/react-hook-form': builtinReactHookForm,
|
|
44
|
+
'@blocklet/pages-kit/builtin/iconify/react': builtinIconifyReact,
|
|
45
|
+
'@blocklet/pages-kit/builtin/zustand': builtinZustand,
|
|
46
|
+
'@blocklet/pages-kit/builtin/zustand/middleware/immer': builtinZustandMiddlewareImmer,
|
|
47
|
+
},
|
|
48
|
+
require(module) {
|
|
49
|
+
return win[builtin_1.BuiltinModulesGlobalVariableName].modules[module];
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
injectGlobalComponents();
|
package/lib/cjs/utils/preload.js
CHANGED
|
@@ -2,26 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.injectPreloadComponents = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
function injectPreloadComponents(
|
|
5
|
+
function injectPreloadComponents(...input) {
|
|
6
|
+
const list = input.flat();
|
|
7
|
+
const first = list[0];
|
|
8
|
+
if (!first)
|
|
9
|
+
return null;
|
|
10
|
+
const data = list.reduce((res, i) => {
|
|
11
|
+
Object.assign(res.config, i.config);
|
|
12
|
+
Object.assign(res.components, i.components);
|
|
13
|
+
Object.assign(res.props, i.props);
|
|
14
|
+
return res;
|
|
15
|
+
}, Object.assign({}, first));
|
|
6
16
|
const injectState = {
|
|
7
|
-
config,
|
|
8
|
-
components: Object.fromEntries(components.map(({ script, component
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
preloadComponentModuleName: script.umd.moduleName,
|
|
12
|
-
component,
|
|
13
|
-
locales,
|
|
14
|
-
},
|
|
17
|
+
config: data.config,
|
|
18
|
+
components: Object.fromEntries(Object.entries(data.components).map(([componentId, { script, component }]) => [
|
|
19
|
+
componentId,
|
|
20
|
+
{ preloadComponentModuleName: script.umd.moduleName, component },
|
|
15
21
|
])),
|
|
22
|
+
props: data.props,
|
|
16
23
|
};
|
|
17
|
-
if (!components.length)
|
|
18
|
-
return undefined;
|
|
19
24
|
return {
|
|
20
25
|
html: `\
|
|
21
|
-
${components
|
|
22
|
-
.map((
|
|
26
|
+
${Object.values(data.components)
|
|
27
|
+
.map(({ script }) => `\
|
|
23
28
|
<script>
|
|
24
|
-
${
|
|
29
|
+
${script.umd.script}
|
|
25
30
|
</script>
|
|
26
31
|
`)
|
|
27
32
|
.join('\n')}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assignNullableFields = exports.parsePropertyValue = exports.mergeComponent = exports.componentUMDName = void 0;
|
|
3
|
+
exports.assignNullableFields = exports.parsePropertyValue = exports.RenderNestedComponent = exports.mergeComponent = exports.componentUMDName = void 0;
|
|
4
4
|
function componentUMDName({ componentId }) {
|
|
5
5
|
return `PagesCustomComponent${componentId}`;
|
|
6
6
|
}
|
|
@@ -16,14 +16,14 @@ function mergeComponent({ componentId, getComponent, locale, defaultLocale, prop
|
|
|
16
16
|
const property = (_b = (_a = component === null || component === void 0 ? void 0 : component.properties) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b.data;
|
|
17
17
|
if (!property)
|
|
18
18
|
return [];
|
|
19
|
-
return [property.key, parsePropertyValue(property
|
|
19
|
+
return [property.key, parsePropertyValue(property, value, { locale, defaultLocale })];
|
|
20
20
|
}));
|
|
21
21
|
while (component) {
|
|
22
22
|
assignNullableFields(properties, Object.fromEntries(Object.values((_a = component.properties) !== null && _a !== void 0 ? _a : {}).map(({ data }) => {
|
|
23
23
|
var _a, _b, _c, _d, _e;
|
|
24
24
|
return [
|
|
25
25
|
data.key,
|
|
26
|
-
parsePropertyValue(data
|
|
26
|
+
parsePropertyValue(data, (_c = (_b = (_a = data.locales) === null || _a === void 0 ? void 0 : _a[locale]) === null || _b === void 0 ? void 0 : _b.defaultValue) !== null && _c !== void 0 ? _c : (_e = (_d = data.locales) === null || _d === void 0 ? void 0 : _d[defaultLocale]) === null || _e === void 0 ? void 0 : _e.defaultValue, { locale, defaultLocale }),
|
|
27
27
|
];
|
|
28
28
|
})));
|
|
29
29
|
if (((_b = component.renderer) === null || _b === void 0 ? void 0 : _b.type) === 'react-component') {
|
|
@@ -34,7 +34,7 @@ function mergeComponent({ componentId, getComponent, locale, defaultLocale, prop
|
|
|
34
34
|
script = (_e = component.renderer) === null || _e === void 0 ? void 0 : _e.script;
|
|
35
35
|
break;
|
|
36
36
|
}
|
|
37
|
-
if (((_f = component.renderer) === null || _f === void 0 ? void 0 : _f.type) === '
|
|
37
|
+
if (((_f = component.renderer) === null || _f === void 0 ? void 0 : _f.type) === 'component' && component.renderer.componentId) {
|
|
38
38
|
const { componentId } = component.renderer;
|
|
39
39
|
const next = getComponent(componentId);
|
|
40
40
|
const nextParameters = component.renderer.properties;
|
|
@@ -43,7 +43,7 @@ function mergeComponent({ componentId, getComponent, locale, defaultLocale, prop
|
|
|
43
43
|
const locales = (_a = nextParameters === null || nextParameters === void 0 ? void 0 : nextParameters[id]) === null || _a === void 0 ? void 0 : _a.locales;
|
|
44
44
|
return [
|
|
45
45
|
data.key,
|
|
46
|
-
parsePropertyValue(data
|
|
46
|
+
parsePropertyValue(data, (_h = (_e = (_c = (_b = locales === null || locales === void 0 ? void 0 : locales[locale]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : (_d = locales === null || locales === void 0 ? void 0 : locales[defaultLocale]) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : (_g = (_f = data.locales) === null || _f === void 0 ? void 0 : _f[locale]) === null || _g === void 0 ? void 0 : _g.defaultValue) !== null && _h !== void 0 ? _h : (_k = (_j = data.locales) === null || _j === void 0 ? void 0 : _j[defaultLocale]) === null || _k === void 0 ? void 0 : _k.defaultValue, { locale, defaultLocale }),
|
|
47
47
|
];
|
|
48
48
|
})));
|
|
49
49
|
component = next;
|
|
@@ -57,8 +57,10 @@ function mergeComponent({ componentId, getComponent, locale, defaultLocale, prop
|
|
|
57
57
|
return { script, properties };
|
|
58
58
|
}
|
|
59
59
|
exports.mergeComponent = mergeComponent;
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
exports.RenderNestedComponent = '__RENDER_NESTED_COMPONENT__';
|
|
61
|
+
function parsePropertyValue(property, value, { locale, defaultLocale }) {
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
63
|
+
if (property.type === 'json') {
|
|
62
64
|
if (!value)
|
|
63
65
|
return undefined;
|
|
64
66
|
try {
|
|
@@ -69,6 +71,17 @@ function parsePropertyValue(type, value) {
|
|
|
69
71
|
return undefined;
|
|
70
72
|
}
|
|
71
73
|
}
|
|
74
|
+
if (property.type === 'component') {
|
|
75
|
+
const componentId = (value === null || value === void 0 ? void 0 : value.componentId) || property.componentId;
|
|
76
|
+
if (typeof componentId !== 'string')
|
|
77
|
+
return undefined;
|
|
78
|
+
const { locales } = property;
|
|
79
|
+
return {
|
|
80
|
+
type: exports.RenderNestedComponent,
|
|
81
|
+
componentId,
|
|
82
|
+
properties: Object.assign(Object.assign({}, ((_c = (_b = (_a = locales === null || locales === void 0 ? void 0 : locales[locale]) === null || _a === void 0 ? void 0 : _a.defaultValue) === null || _b === void 0 ? void 0 : _b.properties) !== null && _c !== void 0 ? _c : (_e = (_d = locales === null || locales === void 0 ? void 0 : locales[defaultLocale]) === null || _d === void 0 ? void 0 : _d.defaultValue) === null || _e === void 0 ? void 0 : _e.properties)), value === null || value === void 0 ? void 0 : value.properties),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
72
85
|
return value;
|
|
73
86
|
}
|
|
74
87
|
exports.parsePropertyValue = parsePropertyValue;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBuiltinModuleTransformer = void 0;
|
|
4
|
+
const builtin_1 = require("../../types/builtin");
|
|
5
|
+
const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
|
|
6
|
+
const { factory } = context;
|
|
7
|
+
const builtins = [];
|
|
8
|
+
const statements = file.statements.filter((s) => {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
if (ts.isImportDeclaration(s) &&
|
|
11
|
+
ts.isStringLiteral(s.moduleSpecifier) &&
|
|
12
|
+
s.moduleSpecifier.text.startsWith('@blocklet/pages-kit/builtin/')) {
|
|
13
|
+
const builtin = {
|
|
14
|
+
moduleName: s.moduleSpecifier.text,
|
|
15
|
+
name: (_b = (_a = s.importClause) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.text,
|
|
16
|
+
members: [],
|
|
17
|
+
};
|
|
18
|
+
const namedBindings = (_c = s.importClause) === null || _c === void 0 ? void 0 : _c.namedBindings;
|
|
19
|
+
if (namedBindings) {
|
|
20
|
+
if (ts.isNamespaceImport(namedBindings)) {
|
|
21
|
+
builtin.name = namedBindings.name.text;
|
|
22
|
+
}
|
|
23
|
+
namedBindings.forEachChild((node) => {
|
|
24
|
+
var _a;
|
|
25
|
+
if (ts.isImportSpecifier(node)) {
|
|
26
|
+
builtin.members.push({ name: node.name.text, propertyName: (_a = node.propertyName) === null || _a === void 0 ? void 0 : _a.text });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (builtin.name || builtin.members.length) {
|
|
31
|
+
builtins.push(builtin);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
});
|
|
37
|
+
statements.unshift(...builtins.flatMap((builtin) => {
|
|
38
|
+
const mod = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(builtin_1.BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(builtin.moduleName)]);
|
|
39
|
+
return [
|
|
40
|
+
builtin.name
|
|
41
|
+
? factory.createVariableStatement([], factory.createVariableDeclarationList([
|
|
42
|
+
factory.createVariableDeclaration(factory.createIdentifier(builtin.name), undefined, undefined, mod),
|
|
43
|
+
], ts.NodeFlags.Const))
|
|
44
|
+
: undefined,
|
|
45
|
+
...builtin.members.map((member) => {
|
|
46
|
+
var _a;
|
|
47
|
+
return factory.createVariableStatement([], factory.createVariableDeclarationList([
|
|
48
|
+
factory.createVariableDeclaration(factory.createIdentifier(member.name), undefined, undefined, factory.createPropertyAccessExpression(mod, (_a = member.propertyName) !== null && _a !== void 0 ? _a : member.name)),
|
|
49
|
+
], ts.NodeFlags.Const));
|
|
50
|
+
}),
|
|
51
|
+
].filter((i) => !!i);
|
|
52
|
+
}));
|
|
53
|
+
return factory.updateSourceFile(file, statements);
|
|
54
|
+
};
|
|
55
|
+
exports.createBuiltinModuleTransformer = createBuiltinModuleTransformer;
|
package/lib/esm/api/call.js
CHANGED
|
@@ -8,13 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { call } from '@blocklet/sdk/lib/component';
|
|
11
|
-
export function preloadComponents({ mode, name, id }) {
|
|
11
|
+
export function preloadComponents({ mode, name, id, locale, }) {
|
|
12
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
13
|
return call({
|
|
14
14
|
name: 'pages-kit',
|
|
15
15
|
method: 'GET',
|
|
16
16
|
path: '/api/components/preload',
|
|
17
|
-
params: {
|
|
17
|
+
params: {
|
|
18
|
+
mode,
|
|
19
|
+
id: Array.isArray(id) ? id.join(',') : id,
|
|
20
|
+
name: Array.isArray(name) ? name.join(',') : name,
|
|
21
|
+
locale,
|
|
22
|
+
},
|
|
18
23
|
}).then((res) => res.data);
|
|
19
24
|
});
|
|
20
25
|
}
|
package/lib/esm/api/pages-kit.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import axios from 'axios';
|
|
11
11
|
import { joinURL } from 'ufo';
|
|
12
12
|
const PAGES_KIT_DID = 'z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o';
|
|
13
|
-
export function preloadComponents({ mode, name, id }) {
|
|
13
|
+
export function preloadComponents({ mode, name, id, locale, }) {
|
|
14
14
|
var _a, _b;
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const prefix = ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.did === PAGES_KIT_DID)) === null || _b === void 0 ? void 0 : _b.mountPoint) || '/';
|
|
@@ -20,6 +20,7 @@ export function preloadComponents({ mode, name, id }) {
|
|
|
20
20
|
mode,
|
|
21
21
|
id: Array.isArray(id) ? id.join(',') : id,
|
|
22
22
|
name: Array.isArray(name) ? name.join(',') : name,
|
|
23
|
+
locale,
|
|
23
24
|
},
|
|
24
25
|
})
|
|
25
26
|
.then((res) => res.data);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Icon } from '@iconify/react';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LoadingButton } from '@mui/lab';
|