@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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { Autocomplete } from '@mui/material';
|
|
2
|
+
export { Box } from '@mui/material';
|
|
3
|
+
export { Button } from '@mui/material';
|
|
4
|
+
export { ClickAwayListener } from '@mui/material';
|
|
5
|
+
export { Dialog } from '@mui/material';
|
|
6
|
+
export { DialogActions } from '@mui/material';
|
|
7
|
+
export { DialogContent } from '@mui/material';
|
|
8
|
+
export { DialogTitle } from '@mui/material';
|
|
9
|
+
export { Paper } from '@mui/material';
|
|
10
|
+
export { Popper } from '@mui/material';
|
|
11
|
+
export { Stack } from '@mui/material';
|
|
12
|
+
export { Switch } from '@mui/material';
|
|
13
|
+
export { TextField } from '@mui/material';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-hook-form';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Children, Component, Fragment, Profiler, PureComponent, StrictMode, Suspense, cloneElement, createContext, createElement, createFactory, createRef, forwardRef, isValidElement, lazy, memo, startTransition, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, version, } from 'react';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { joinURL, withQuery } from 'ufo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'zustand/middleware/immer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'zustand';
|
|
@@ -19,49 +19,57 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
-
import
|
|
23
|
-
import { Alert, Box
|
|
24
|
-
import
|
|
22
|
+
import '../../utils/inject-global-components';
|
|
23
|
+
import { Alert, Box } from '@mui/material';
|
|
24
|
+
import { pick } from 'lodash';
|
|
25
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
25
26
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
26
|
-
import { joinURL, withQuery } from 'ufo';
|
|
27
27
|
import { PreloadComponentsStateGlobalVariableName } from '../../types/preload';
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
win.joinURL = joinURL;
|
|
32
|
-
win.withQuery = withQuery;
|
|
33
|
-
win.React = React;
|
|
34
|
-
win.Box = Box;
|
|
35
|
-
win.Stack = Stack;
|
|
36
|
-
win.Button = Button;
|
|
37
|
-
win.IconifyIcon = IconifyIcon;
|
|
28
|
+
import { RenderNestedComponent, mergeComponent } from '../../utils/property';
|
|
29
|
+
import { createBuiltinModuleTransformer } from '../../utils/typescript/builtin-module-transformer';
|
|
30
|
+
const MAXIMUM_RENDER_STACK_SIZE = 50;
|
|
38
31
|
export default function CustomComponentRenderer(_a) {
|
|
32
|
+
var _b;
|
|
39
33
|
var props = __rest(_a, []);
|
|
40
|
-
return (_jsx(ErrorBoundary, { fallbackRender: E, children: _jsx(
|
|
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 })) }));
|
|
35
|
+
}
|
|
36
|
+
function ComponentRenderer(_a) {
|
|
37
|
+
var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
|
|
38
|
+
if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
|
|
39
|
+
throw new Error('Maximum render stack size exceeded');
|
|
40
|
+
}
|
|
41
|
+
return _jsx(Renderer, Object.assign({ renderCount: renderCount + 1 }, props));
|
|
41
42
|
}
|
|
42
43
|
function Renderer(props) {
|
|
43
|
-
const component =
|
|
44
|
+
const component = useComponent(props);
|
|
44
45
|
if (!component)
|
|
45
46
|
return null;
|
|
46
47
|
const { Component, AsyncComponent, properties } = component;
|
|
48
|
+
const componentProps = Object.fromEntries(Object.entries(Object.assign(Object.assign({}, properties), props.props)).map(([key, val]) => {
|
|
49
|
+
return [
|
|
50
|
+
key,
|
|
51
|
+
(val === null || val === void 0 ? void 0 : val.type) === RenderNestedComponent ? (_jsx(ComponentRenderer, Object.assign({}, pick(props, 'components', 'locale', 'defaultLocale'), { instanceId: key, renderCount: props.renderCount, componentId: val.componentId, properties: val.properties, props: val.props }))) : (val),
|
|
52
|
+
];
|
|
53
|
+
}));
|
|
47
54
|
if (Component) {
|
|
48
|
-
return _jsx(Component, Object.assign({},
|
|
55
|
+
return _jsx(Component, Object.assign({}, componentProps));
|
|
49
56
|
}
|
|
50
57
|
if (AsyncComponent) {
|
|
51
|
-
return _jsx(AsyncComponentRenderer, { AsyncComponent: AsyncComponent,
|
|
58
|
+
return _jsx(AsyncComponentRenderer, Object.assign({ AsyncComponent: AsyncComponent }, componentProps));
|
|
52
59
|
}
|
|
53
60
|
return null;
|
|
54
61
|
}
|
|
55
|
-
function AsyncComponentRenderer(
|
|
56
|
-
|
|
62
|
+
function AsyncComponentRenderer(_a) {
|
|
63
|
+
var { AsyncComponent } = _a, props = __rest(_a, ["AsyncComponent"]);
|
|
64
|
+
const [{ Component, error }, setState] = useState({});
|
|
57
65
|
useEffect(() => {
|
|
58
|
-
AsyncComponent.then((m) => setState({ Component: m.default, key: Date.now() })).catch((error) => setState({ error
|
|
66
|
+
AsyncComponent.then((m) => setState({ Component: m.default, key: Date.now() })).catch((error) => setState({ error }));
|
|
59
67
|
}, [AsyncComponent]);
|
|
60
68
|
if (error) {
|
|
61
69
|
return _jsx(Alert, { severity: "error", children: error.stack });
|
|
62
70
|
}
|
|
63
71
|
if (Component) {
|
|
64
|
-
return
|
|
72
|
+
return _jsx(Component, Object.assign({}, props));
|
|
65
73
|
}
|
|
66
74
|
return null;
|
|
67
75
|
}
|
|
@@ -69,20 +77,26 @@ function E({ error }) {
|
|
|
69
77
|
return (_jsx(Box, { children: _jsx(Alert, { severity: "error", children: error.message }) }));
|
|
70
78
|
}
|
|
71
79
|
const PRELOAD_COMPONENTS_STATE = window[PreloadComponentsStateGlobalVariableName];
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
function useComponent({ instanceId, componentId, components, locale, defaultLocale, properties: parameters, props, }) {
|
|
81
|
+
const scriptRef = useRef({});
|
|
82
|
+
const preloadComponent = useMemo(() => {
|
|
83
|
+
const preload = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components[componentId];
|
|
84
|
+
if (preload) {
|
|
85
|
+
const mod = window[preload.preloadComponentModuleName];
|
|
86
|
+
if (typeof mod === 'function') {
|
|
87
|
+
return { component: preload.component, Component: mod() };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}, [componentId]);
|
|
92
|
+
const preloadState = useMemo(() => {
|
|
93
|
+
var _a;
|
|
94
|
+
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];
|
|
95
|
+
}, [instanceId, locale]);
|
|
96
|
+
if ((props || preloadState) && preloadComponent) {
|
|
83
97
|
return {
|
|
84
|
-
Component:
|
|
85
|
-
properties:
|
|
98
|
+
Component: preloadComponent.Component,
|
|
99
|
+
properties: preloadState,
|
|
86
100
|
};
|
|
87
101
|
}
|
|
88
102
|
const component = mergeComponent({
|
|
@@ -94,16 +108,23 @@ function loadComponent({ componentId, components, locale, defaultLocale, propert
|
|
|
94
108
|
});
|
|
95
109
|
if (!component)
|
|
96
110
|
return null;
|
|
111
|
+
if (scriptRef.current.script !== component.script) {
|
|
112
|
+
scriptRef.current.script = component.script;
|
|
113
|
+
scriptRef.current.module = transpileAndLoadScript(component.script);
|
|
114
|
+
}
|
|
97
115
|
return {
|
|
98
|
-
AsyncComponent:
|
|
116
|
+
AsyncComponent: scriptRef.current.module,
|
|
99
117
|
properties: component.properties,
|
|
100
118
|
};
|
|
101
119
|
}
|
|
102
|
-
function transpileAndLoadScript(script) {
|
|
120
|
+
export function transpileAndLoadScript(script) {
|
|
103
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
122
|
const ts = yield import('typescript');
|
|
105
123
|
const compiled = ts.transpileModule(script, {
|
|
106
|
-
compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext },
|
|
124
|
+
compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
|
|
125
|
+
transformers: {
|
|
126
|
+
before: [createBuiltinModuleTransformer(ts)],
|
|
127
|
+
},
|
|
107
128
|
}).outputText;
|
|
108
129
|
const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
|
|
109
130
|
return import(/* @vite-ignore */ url);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BuiltinModulesGlobalVariableName = '__PAGES_KIT_BUILTIN_MODULES__';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as builtinIconifyReact from '../builtin/iconify/react';
|
|
2
|
+
import * as builtinMuiLab from '../builtin/mui/lab';
|
|
3
|
+
import * as builtinMuiMaterial from '../builtin/mui/material';
|
|
4
|
+
import * as builtinReact from '../builtin/react';
|
|
5
|
+
import * as builtinReactHookForm from '../builtin/react-hook-form';
|
|
6
|
+
import * as builtinUtils from '../builtin/utils';
|
|
7
|
+
import * as builtinZustand from '../builtin/zustand';
|
|
8
|
+
import * as builtinZustandMiddlewareImmer from '../builtin/zustand/middleware/immer';
|
|
9
|
+
import { BuiltinModulesGlobalVariableName } from '../types/builtin';
|
|
10
|
+
function injectGlobalComponents() {
|
|
11
|
+
const win = window;
|
|
12
|
+
win[BuiltinModulesGlobalVariableName] = {
|
|
13
|
+
modules: {
|
|
14
|
+
'@blocklet/pages-kit/builtin/utils': builtinUtils,
|
|
15
|
+
'@blocklet/pages-kit/builtin/react': builtinReact,
|
|
16
|
+
'@blocklet/pages-kit/builtin/mui/material': builtinMuiMaterial,
|
|
17
|
+
'@blocklet/pages-kit/builtin/mui/lab': builtinMuiLab,
|
|
18
|
+
'@blocklet/pages-kit/builtin/react-hook-form': builtinReactHookForm,
|
|
19
|
+
'@blocklet/pages-kit/builtin/iconify/react': builtinIconifyReact,
|
|
20
|
+
'@blocklet/pages-kit/builtin/zustand': builtinZustand,
|
|
21
|
+
'@blocklet/pages-kit/builtin/zustand/middleware/immer': builtinZustandMiddlewareImmer,
|
|
22
|
+
},
|
|
23
|
+
require(module) {
|
|
24
|
+
return win[BuiltinModulesGlobalVariableName].modules[module];
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
injectGlobalComponents();
|
package/lib/esm/utils/preload.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { PreloadComponentsStateGlobalVariableName } from '../types';
|
|
2
|
-
export function injectPreloadComponents(
|
|
2
|
+
export function injectPreloadComponents(...input) {
|
|
3
|
+
const list = input.flat();
|
|
4
|
+
const first = list[0];
|
|
5
|
+
if (!first)
|
|
6
|
+
return null;
|
|
7
|
+
const data = list.reduce((res, i) => {
|
|
8
|
+
Object.assign(res.config, i.config);
|
|
9
|
+
Object.assign(res.components, i.components);
|
|
10
|
+
Object.assign(res.props, i.props);
|
|
11
|
+
return res;
|
|
12
|
+
}, Object.assign({}, first));
|
|
3
13
|
const injectState = {
|
|
4
|
-
config,
|
|
5
|
-
components: Object.fromEntries(components.map(({ script, component
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
preloadComponentModuleName: script.umd.moduleName,
|
|
9
|
-
component,
|
|
10
|
-
locales,
|
|
11
|
-
},
|
|
14
|
+
config: data.config,
|
|
15
|
+
components: Object.fromEntries(Object.entries(data.components).map(([componentId, { script, component }]) => [
|
|
16
|
+
componentId,
|
|
17
|
+
{ preloadComponentModuleName: script.umd.moduleName, component },
|
|
12
18
|
])),
|
|
19
|
+
props: data.props,
|
|
13
20
|
};
|
|
14
|
-
if (!components.length)
|
|
15
|
-
return undefined;
|
|
16
21
|
return {
|
|
17
22
|
html: `\
|
|
18
|
-
${components
|
|
19
|
-
.map((
|
|
23
|
+
${Object.values(data.components)
|
|
24
|
+
.map(({ script }) => `\
|
|
20
25
|
<script>
|
|
21
|
-
${
|
|
26
|
+
${script.umd.script}
|
|
22
27
|
</script>
|
|
23
28
|
`)
|
|
24
29
|
.join('\n')}
|
|
@@ -12,14 +12,14 @@ export function mergeComponent({ componentId, getComponent, locale, defaultLocal
|
|
|
12
12
|
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;
|
|
13
13
|
if (!property)
|
|
14
14
|
return [];
|
|
15
|
-
return [property.key, parsePropertyValue(property
|
|
15
|
+
return [property.key, parsePropertyValue(property, value, { locale, defaultLocale })];
|
|
16
16
|
}));
|
|
17
17
|
while (component) {
|
|
18
18
|
assignNullableFields(properties, Object.fromEntries(Object.values((_a = component.properties) !== null && _a !== void 0 ? _a : {}).map(({ data }) => {
|
|
19
19
|
var _a, _b, _c, _d, _e;
|
|
20
20
|
return [
|
|
21
21
|
data.key,
|
|
22
|
-
parsePropertyValue(data
|
|
22
|
+
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 }),
|
|
23
23
|
];
|
|
24
24
|
})));
|
|
25
25
|
if (((_b = component.renderer) === null || _b === void 0 ? void 0 : _b.type) === 'react-component') {
|
|
@@ -30,7 +30,7 @@ export function mergeComponent({ componentId, getComponent, locale, defaultLocal
|
|
|
30
30
|
script = (_e = component.renderer) === null || _e === void 0 ? void 0 : _e.script;
|
|
31
31
|
break;
|
|
32
32
|
}
|
|
33
|
-
if (((_f = component.renderer) === null || _f === void 0 ? void 0 : _f.type) === '
|
|
33
|
+
if (((_f = component.renderer) === null || _f === void 0 ? void 0 : _f.type) === 'component' && component.renderer.componentId) {
|
|
34
34
|
const { componentId } = component.renderer;
|
|
35
35
|
const next = getComponent(componentId);
|
|
36
36
|
const nextParameters = component.renderer.properties;
|
|
@@ -39,7 +39,7 @@ export function mergeComponent({ componentId, getComponent, locale, defaultLocal
|
|
|
39
39
|
const locales = (_a = nextParameters === null || nextParameters === void 0 ? void 0 : nextParameters[id]) === null || _a === void 0 ? void 0 : _a.locales;
|
|
40
40
|
return [
|
|
41
41
|
data.key,
|
|
42
|
-
parsePropertyValue(data
|
|
42
|
+
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 }),
|
|
43
43
|
];
|
|
44
44
|
})));
|
|
45
45
|
component = next;
|
|
@@ -52,8 +52,10 @@ export function mergeComponent({ componentId, getComponent, locale, defaultLocal
|
|
|
52
52
|
return null;
|
|
53
53
|
return { script, properties };
|
|
54
54
|
}
|
|
55
|
-
export
|
|
56
|
-
|
|
55
|
+
export const RenderNestedComponent = '__RENDER_NESTED_COMPONENT__';
|
|
56
|
+
export function parsePropertyValue(property, value, { locale, defaultLocale }) {
|
|
57
|
+
var _a, _b, _c, _d, _e;
|
|
58
|
+
if (property.type === 'json') {
|
|
57
59
|
if (!value)
|
|
58
60
|
return undefined;
|
|
59
61
|
try {
|
|
@@ -64,6 +66,17 @@ export function parsePropertyValue(type, value) {
|
|
|
64
66
|
return undefined;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
69
|
+
if (property.type === 'component') {
|
|
70
|
+
const componentId = (value === null || value === void 0 ? void 0 : value.componentId) || property.componentId;
|
|
71
|
+
if (typeof componentId !== 'string')
|
|
72
|
+
return undefined;
|
|
73
|
+
const { locales } = property;
|
|
74
|
+
return {
|
|
75
|
+
type: RenderNestedComponent,
|
|
76
|
+
componentId,
|
|
77
|
+
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),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
67
80
|
return value;
|
|
68
81
|
}
|
|
69
82
|
export function assignNullableFields(properties, newProperties) {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BuiltinModulesGlobalVariableName } from '../../types/builtin';
|
|
2
|
+
export const createBuiltinModuleTransformer = (ts) => (context) => (file) => {
|
|
3
|
+
const { factory } = context;
|
|
4
|
+
const builtins = [];
|
|
5
|
+
const statements = file.statements.filter((s) => {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
if (ts.isImportDeclaration(s) &&
|
|
8
|
+
ts.isStringLiteral(s.moduleSpecifier) &&
|
|
9
|
+
s.moduleSpecifier.text.startsWith('@blocklet/pages-kit/builtin/')) {
|
|
10
|
+
const builtin = {
|
|
11
|
+
moduleName: s.moduleSpecifier.text,
|
|
12
|
+
name: (_b = (_a = s.importClause) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.text,
|
|
13
|
+
members: [],
|
|
14
|
+
};
|
|
15
|
+
const namedBindings = (_c = s.importClause) === null || _c === void 0 ? void 0 : _c.namedBindings;
|
|
16
|
+
if (namedBindings) {
|
|
17
|
+
if (ts.isNamespaceImport(namedBindings)) {
|
|
18
|
+
builtin.name = namedBindings.name.text;
|
|
19
|
+
}
|
|
20
|
+
namedBindings.forEachChild((node) => {
|
|
21
|
+
var _a;
|
|
22
|
+
if (ts.isImportSpecifier(node)) {
|
|
23
|
+
builtin.members.push({ name: node.name.text, propertyName: (_a = node.propertyName) === null || _a === void 0 ? void 0 : _a.text });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (builtin.name || builtin.members.length) {
|
|
28
|
+
builtins.push(builtin);
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
statements.unshift(...builtins.flatMap((builtin) => {
|
|
35
|
+
const mod = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier(BuiltinModulesGlobalVariableName), 'require'), undefined, [factory.createStringLiteral(builtin.moduleName)]);
|
|
36
|
+
return [
|
|
37
|
+
builtin.name
|
|
38
|
+
? factory.createVariableStatement([], factory.createVariableDeclarationList([
|
|
39
|
+
factory.createVariableDeclaration(factory.createIdentifier(builtin.name), undefined, undefined, mod),
|
|
40
|
+
], ts.NodeFlags.Const))
|
|
41
|
+
: undefined,
|
|
42
|
+
...builtin.members.map((member) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return factory.createVariableStatement([], factory.createVariableDeclarationList([
|
|
45
|
+
factory.createVariableDeclaration(factory.createIdentifier(member.name), undefined, undefined, factory.createPropertyAccessExpression(mod, (_a = member.propertyName) !== null && _a !== void 0 ? _a : member.name)),
|
|
46
|
+
], ts.NodeFlags.Const));
|
|
47
|
+
}),
|
|
48
|
+
].filter((i) => !!i);
|
|
49
|
+
}));
|
|
50
|
+
return factory.updateSourceFile(file, statements);
|
|
51
|
+
};
|
package/lib/types/api/call.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PreloadComponentQuery, PreloadComponentsResult } from '../types';
|
|
2
|
-
export declare function preloadComponents({ mode, name, id }: PreloadComponentQuery): Promise<PreloadComponentsResult>;
|
|
2
|
+
export declare function preloadComponents({ mode, name, id, locale, }: PreloadComponentQuery): Promise<PreloadComponentsResult>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PreloadComponentQuery, PreloadComponentsResult } from '../types';
|
|
2
|
-
export declare function preloadComponents({ mode, name, id }: PreloadComponentQuery): Promise<PreloadComponentsResult>;
|
|
2
|
+
export declare function preloadComponents({ mode, name, id, locale, }: PreloadComponentQuery): Promise<PreloadComponentsResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Icon } from '@iconify/react';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LoadingButton } from '@mui/lab';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { Autocomplete } from '@mui/material';
|
|
2
|
+
export { Box } from '@mui/material';
|
|
3
|
+
export { Button } from '@mui/material';
|
|
4
|
+
export { ClickAwayListener } from '@mui/material';
|
|
5
|
+
export { Dialog } from '@mui/material';
|
|
6
|
+
export { DialogActions } from '@mui/material';
|
|
7
|
+
export { DialogContent } from '@mui/material';
|
|
8
|
+
export { DialogTitle } from '@mui/material';
|
|
9
|
+
export { Paper } from '@mui/material';
|
|
10
|
+
export { Popper } from '@mui/material';
|
|
11
|
+
export { Stack } from '@mui/material';
|
|
12
|
+
export { Switch } from '@mui/material';
|
|
13
|
+
export { TextField } from '@mui/material';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-hook-form';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Children, Component, Fragment, Profiler, PureComponent, StrictMode, Suspense, cloneElement, createContext, createElement, createFactory, createRef, forwardRef, isValidElement, lazy, memo, startTransition, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, version, } from 'react';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { joinURL, withQuery } from 'ufo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'zustand/middleware/immer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'zustand';
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import '../../utils/inject-global-components';
|
|
1
2
|
import { CustomComponent } from '../../types/core';
|
|
2
3
|
export interface CustomComponentRendererProps {
|
|
4
|
+
instanceId?: string;
|
|
3
5
|
componentId: string;
|
|
4
6
|
locale?: string;
|
|
5
7
|
defaultLocale?: string;
|
|
6
8
|
components?: CustomComponent[];
|
|
7
9
|
properties?: {
|
|
10
|
+
[key: string]: {
|
|
11
|
+
value: any;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
props?: {
|
|
8
15
|
[key: string]: any;
|
|
9
16
|
};
|
|
10
17
|
}
|
|
11
18
|
export default function CustomComponentRenderer({ ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare function transpileAndLoadScript(script: string): Promise<any>;
|
package/lib/types/types/api.d.ts
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import { CustomComponent } from './core';
|
|
2
2
|
import { StateMode } from './state';
|
|
3
3
|
export interface PreloadComponentQuery {
|
|
4
|
+
locale?: string;
|
|
4
5
|
mode?: StateMode;
|
|
5
6
|
name?: string[] | string;
|
|
6
7
|
id?: string[] | string;
|
|
7
8
|
}
|
|
8
9
|
export interface PreloadComponentsResult {
|
|
9
10
|
config: {
|
|
10
|
-
defaultLocale
|
|
11
|
+
defaultLocale: string;
|
|
11
12
|
};
|
|
12
13
|
components: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
[componentId: string]: {
|
|
15
|
+
component: CustomComponent;
|
|
16
|
+
script: {
|
|
17
|
+
umd: {
|
|
18
|
+
script: string;
|
|
19
|
+
moduleName: string;
|
|
20
|
+
};
|
|
18
21
|
};
|
|
19
22
|
};
|
|
20
|
-
|
|
23
|
+
};
|
|
24
|
+
props: {
|
|
25
|
+
[instanceId: string]: {
|
|
21
26
|
[locale: string]: {
|
|
22
|
-
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
};
|
|
27
|
+
[key: string]: any;
|
|
25
28
|
};
|
|
26
29
|
};
|
|
27
|
-
}
|
|
30
|
+
};
|
|
28
31
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BuiltinModulesGlobalVariableName = "__PAGES_KIT_BUILTIN_MODULES__";
|
|
@@ -10,7 +10,7 @@ export type CustomComponent = {
|
|
|
10
10
|
type: 'react-component';
|
|
11
11
|
script?: string;
|
|
12
12
|
} | {
|
|
13
|
-
type: '
|
|
13
|
+
type: 'component';
|
|
14
14
|
componentId?: string;
|
|
15
15
|
properties?: {
|
|
16
16
|
[id: string]: {
|
|
@@ -25,18 +25,45 @@ export type CustomComponent = {
|
|
|
25
25
|
properties?: {
|
|
26
26
|
[id: string]: {
|
|
27
27
|
index: number;
|
|
28
|
-
data:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
data: CustomComponentCommonProperty | CustomComponentCustomProperty | CustomComponentStringProperty | CustomComponentComponentProperty;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export interface CustomComponentPropertyBase {
|
|
33
|
+
id: string;
|
|
34
|
+
key?: string;
|
|
35
|
+
locales?: {
|
|
36
|
+
[locale: string]: {
|
|
37
|
+
name?: string;
|
|
38
|
+
defaultValue?: any;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface CustomComponentCommonProperty extends CustomComponentPropertyBase {
|
|
43
|
+
type: 'number' | 'boolean' | 'json' | 'url';
|
|
44
|
+
}
|
|
45
|
+
export interface CustomComponentCustomProperty extends CustomComponentPropertyBase {
|
|
46
|
+
type: 'custom';
|
|
47
|
+
componentId?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface CustomComponentStringProperty extends CustomComponentPropertyBase {
|
|
50
|
+
type?: 'string';
|
|
51
|
+
multiline?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface CustomComponentComponentProperty extends CustomComponentPropertyBase {
|
|
54
|
+
type: 'component';
|
|
55
|
+
componentId?: string;
|
|
56
|
+
locales?: {
|
|
57
|
+
[locale: string]: {
|
|
58
|
+
name?: undefined;
|
|
59
|
+
defaultValue?: {
|
|
60
|
+
componentId?: string;
|
|
61
|
+
properties: {
|
|
62
|
+
[id: string]: {
|
|
63
|
+
value: any;
|
|
37
64
|
};
|
|
38
65
|
};
|
|
39
66
|
};
|
|
40
67
|
};
|
|
41
68
|
};
|
|
42
|
-
}
|
|
69
|
+
}
|
|
@@ -3,19 +3,19 @@ export declare const PreloadComponentsStateGlobalVariableName = "__PAGES_KIT_PRE
|
|
|
3
3
|
export interface PreloadComponent {
|
|
4
4
|
preloadComponentModuleName: string;
|
|
5
5
|
component: CustomComponent;
|
|
6
|
-
locales?: {
|
|
7
|
-
[locale: string]: {
|
|
8
|
-
properties?: {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
6
|
}
|
|
14
7
|
export interface PreloadComponentsState {
|
|
15
8
|
config: {
|
|
16
9
|
defaultLocale?: string;
|
|
17
10
|
};
|
|
18
11
|
components: {
|
|
19
|
-
[
|
|
12
|
+
[componentId: string]: PreloadComponent;
|
|
13
|
+
};
|
|
14
|
+
props: {
|
|
15
|
+
[instanceId: string]: {
|
|
16
|
+
[locale: string]: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PreloadComponentsResult } from '../types';
|
|
2
|
-
export declare function injectPreloadComponents(
|
|
2
|
+
export declare function injectPreloadComponents(...input: PreloadComponentsResult[] | PreloadComponentsResult[][]): {
|
|
3
3
|
html: string;
|
|
4
|
-
} |
|
|
4
|
+
} | null;
|
|
@@ -18,5 +18,9 @@ export declare function mergeComponent({ componentId, getComponent, locale, defa
|
|
|
18
18
|
[key: string]: any;
|
|
19
19
|
};
|
|
20
20
|
} | null;
|
|
21
|
-
export declare
|
|
21
|
+
export declare const RenderNestedComponent = "__RENDER_NESTED_COMPONENT__";
|
|
22
|
+
export declare function parsePropertyValue(property: NonNullable<CustomComponent['properties']>[string]['data'], value: any, { locale, defaultLocale }: {
|
|
23
|
+
locale?: string;
|
|
24
|
+
defaultLocale?: string;
|
|
25
|
+
}): any;
|
|
22
26
|
export declare function assignNullableFields(properties: any, newProperties: any): any;
|