@blocklet/pages-kit 0.2.222 → 0.2.224

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.
@@ -1,12 +1,3 @@
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
1
  var __rest = (this && this.__rest) || function (s, e) {
11
2
  var t = {};
12
3
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -21,169 +12,48 @@ var __rest = (this && this.__rest) || function (s, e) {
21
12
  import { jsx as _jsx } from "react/jsx-runtime";
22
13
  import '../../utils/inject-global-components';
23
14
  import { Alert, Box } from '@mui/material';
24
- import { pick } from 'lodash';
25
- import { useEffect, useMemo, useRef, useState } from 'react';
26
15
  import { ErrorBoundary } from 'react-error-boundary';
27
- import { preloadComponents } from '../../api';
28
- import { PreloadComponentsStateGlobalVariableName } from '../../types/preload';
29
- import { RenderNestedComponent, mergeComponent } from '../../utils/property';
16
+ import { RenderNestedComponent } from '../../utils/property';
17
+ import { usePreloadComponent, useTranspileComponent } from './state';
18
+ export * from './state';
30
19
  const MAXIMUM_RENDER_STACK_SIZE = 20;
31
20
  export default function CustomComponentRenderer(_a) {
32
21
  var _b;
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 })) }));
22
+ var props = __rest(_a, []);
23
+ return (_jsx(ErrorBoundary, { fallbackRender: ErrorView, resetKeys: [Date.now()], children: _jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
24
+ }
25
+ function ErrorView({ error }) {
26
+ return (_jsx(Box, { children: _jsx(Alert, { severity: "error", children: error.message }) }));
35
27
  }
36
28
  function ComponentRenderer(_a) {
29
+ var _b;
37
30
  var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
38
31
  if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
39
32
  throw new Error('Maximum render stack size exceeded');
40
33
  }
41
- return _jsx(Renderer, Object.assign({ renderCount: renderCount + 1 }, props));
34
+ if (!((_b = props.dev) === null || _b === void 0 ? void 0 : _b.components)) {
35
+ return _jsx(PreloadRenderer, Object.assign({ renderCount: renderCount + 1 }, props));
36
+ }
37
+ return _jsx(DebugRenderer, Object.assign({ renderCount: renderCount + 1 }, props));
42
38
  }
43
- function Renderer(props) {
44
- const component = useComponent(props);
39
+ function PreloadRenderer(props) {
40
+ const component = usePreloadComponent(props);
45
41
  if (!component)
46
42
  return null;
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
- }));
54
- if (Component) {
55
- return _jsx(Component, Object.assign({ locale: props.locale }, componentProps));
56
- }
57
- if (AsyncComponent) {
58
- return _jsx(AsyncComponentRenderer, Object.assign({ AsyncComponent: AsyncComponent, locale: props.locale }, componentProps));
59
- }
60
- return null;
61
- }
62
- function AsyncComponentRenderer(_a) {
63
- var { AsyncComponent } = _a, props = __rest(_a, ["AsyncComponent"]);
64
- const [{ Component, error }, setState] = useState({});
65
- useEffect(() => {
66
- AsyncComponent.then((m) => setState({ Component: m.default, key: Date.now() })).catch((error) => setState({ error }));
67
- }, [AsyncComponent]);
68
- if (error) {
69
- return _jsx(Alert, { severity: "error", children: error.stack });
70
- }
71
- if (Component) {
72
- return _jsx(Component, Object.assign({}, props));
73
- }
74
- return null;
75
- }
76
- function E({ error }) {
77
- return (_jsx(Box, { children: _jsx(Alert, { severity: "error", children: error.message }) }));
78
- }
79
- let PRELOAD_COMPONENTS_STATE = window[PreloadComponentsStateGlobalVariableName];
80
- let PRELOAD_COMPONENTS_STATE_KEY = 0;
81
- const COMPONENTS_MAP = {};
82
- function getScriptComponent(componentId) {
83
- if (!COMPONENTS_MAP[componentId]) {
84
- const preload = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components[componentId];
85
- if (preload) {
86
- const mod = window[preload.preloadComponentModuleName];
87
- if (typeof mod === 'function') {
88
- COMPONENTS_MAP[componentId] = { component: preload.component, Component: mod() };
89
- }
90
- }
91
- }
92
- return COMPONENTS_MAP[componentId];
43
+ return _jsx(Renderer, Object.assign({}, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) }));
93
44
  }
94
- const LOAD_REMOTE_COMPONENT_TASKS = {};
95
- function loadRemoteComponent({ mode, instanceId, componentId, locale, }) {
96
- var _a;
97
- const key = [mode, instanceId, locale].join('-');
98
- (_a = LOAD_REMOTE_COMPONENT_TASKS[key]) !== null && _a !== void 0 ? _a : (LOAD_REMOTE_COMPONENT_TASKS[key] = preloadComponents({ mode, id: componentId, locale })
99
- .then((result) => {
100
- var _a, _b, _c, _d, _e, _f;
101
- var _g, _h, _j, _k;
102
- PRELOAD_COMPONENTS_STATE !== null && PRELOAD_COMPONENTS_STATE !== void 0 ? PRELOAD_COMPONENTS_STATE : (PRELOAD_COMPONENTS_STATE = { config: result.config, components: {}, props: {} });
103
- for (const i of Object.values(result.components)) {
104
- if (!window[i.script.umd.moduleName]) {
105
- const script = document.createElement('script');
106
- script.textContent = i.script.umd.script;
107
- document.body.appendChild(script);
108
- }
109
- PRELOAD_COMPONENTS_STATE.components[i.component.id] = {
110
- preloadComponentModuleName: i.script.umd.moduleName,
111
- component: i.component,
112
- };
113
- }
114
- (_a = (_g = PRELOAD_COMPONENTS_STATE.props)[instanceId]) !== null && _a !== void 0 ? _a : (_g[instanceId] = {});
115
- (_b = (_h = PRELOAD_COMPONENTS_STATE.props[instanceId]).locales) !== null && _b !== void 0 ? _b : (_h.locales = {});
116
- (_c = (_j = PRELOAD_COMPONENTS_STATE.props[instanceId].locales)[_k = locale]) !== null && _c !== void 0 ? _c : (_j[_k] = {});
117
- PRELOAD_COMPONENTS_STATE.props[instanceId].locales[locale].props =
118
- (_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;
119
- PRELOAD_COMPONENTS_STATE_KEY += 1;
120
- })
121
- .catch((error) => {
122
- console.error('load remote component error', error);
123
- LOAD_REMOTE_COMPONENT_TASKS[key] = undefined;
124
- }));
125
- return LOAD_REMOTE_COMPONENT_TASKS[key];
126
- }
127
- function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters, }) {
128
- var _a;
129
- const scriptRef = useRef({});
130
- const preloadComponent = useMemo(() => getScriptComponent(componentId), [componentId, PRELOAD_COMPONENTS_STATE_KEY]);
131
- const preloadState = useMemo(() => {
132
- var _a, _b;
133
- 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[locale || defaultLocale];
134
- }, [instanceId, locale, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
135
- const preloadDefaultState = useMemo(() => {
136
- var _a, _b;
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, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
139
- const previousPreload = useRef();
140
- const [, update] = useState(0);
141
- if (!(components === null || components === void 0 ? void 0 : components.length) && !preloadState && preloadComponent) {
142
- loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale }).then(() => {
143
- update(PRELOAD_COMPONENTS_STATE_KEY);
144
- });
145
- if (previousPreload.current) {
146
- return previousPreload.current;
147
- }
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
- const component = mergeComponent({
157
- componentId,
158
- getComponent: (componentId) => components === null || components === void 0 ? void 0 : components.find((i) => i.id === componentId),
159
- locale,
160
- defaultLocale,
161
- properties: parameters,
162
- });
45
+ function DebugRenderer(props) {
46
+ const component = useTranspileComponent(props);
163
47
  if (!component)
164
48
  return null;
165
- if (scriptRef.current.script !== component.script) {
166
- scriptRef.current.script = component.script;
167
- scriptRef.current.module = transpileAndLoadScript(component.script);
168
- }
169
- return {
170
- AsyncComponent: scriptRef.current.module,
171
- properties: component.properties,
172
- };
49
+ return _jsx(Renderer, Object.assign({}, props, { Component: component.Component, props: Object.assign(Object.assign({}, component.props), props.props) }));
173
50
  }
174
- export function transpileAndLoadScript(script) {
175
- return __awaiter(this, void 0, void 0, function* () {
176
- const [ts, { createBuiltinModuleTransformer }] = yield Promise.all([
177
- import('typescript'),
178
- import('../../utils/typescript/builtin-module-transformer'),
179
- ]);
180
- const compiled = ts.transpileModule(script, {
181
- compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
182
- transformers: {
183
- before: [createBuiltinModuleTransformer(ts)],
184
- },
185
- }).outputText;
186
- const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
187
- return import(/* @vite-ignore */ url);
188
- });
51
+ function Renderer({ renderCount, Component, locale, props, dev, }) {
52
+ const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
53
+ return [
54
+ key,
55
+ (val === null || val === void 0 ? void 0 : val.type) === RenderNestedComponent ? (_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props, dev: dev })) : (val),
56
+ ];
57
+ }));
58
+ return _jsx(Component, Object.assign({ locale: locale }, componentProps));
189
59
  }
@@ -0,0 +1,175 @@
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 __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { useDeferredValue, useEffect, useRef, useState } from 'react';
22
+ import { create } from 'zustand';
23
+ import { immer } from 'zustand/middleware/immer';
24
+ import { preloadComponents } from '../../api';
25
+ import { PreloadComponentScriptModule } from '../../types';
26
+ import { PreloadComponentsStateGlobalVariableName } from '../../types/preload';
27
+ import { mergeComponent } from '../../utils/property';
28
+ const PRELOAD_COMPONENTS_STATE = window[PreloadComponentsStateGlobalVariableName];
29
+ export const customComponentStates = create()(immer((set, get) => ({
30
+ state: {
31
+ config: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config),
32
+ components: Object.fromEntries(Object.entries(Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components)).map(([componentId, preload]) => {
33
+ let Component;
34
+ if (preload.componentModuleGlobalVariable) {
35
+ const m = window[preload.componentModuleGlobalVariable];
36
+ if (typeof m === 'function')
37
+ Component = m();
38
+ }
39
+ return [componentId, Object.assign(Object.assign({}, preload), { Component })];
40
+ })),
41
+ instances: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.instances),
42
+ },
43
+ getComponent({ instanceId, componentId, locale }) {
44
+ var _a, _b;
45
+ const { config: { supportedLocales }, components, instances, } = get().state;
46
+ if (!(supportedLocales === null || supportedLocales === void 0 ? void 0 : supportedLocales.some((i) => i.locale === locale)))
47
+ return null;
48
+ const c = components[componentId];
49
+ if (!c)
50
+ return null;
51
+ const { component, Component } = c;
52
+ if (!Component)
53
+ return null;
54
+ if (!instanceId) {
55
+ return { component, Component };
56
+ }
57
+ const instance = instances[instanceId];
58
+ if (!instance)
59
+ return null;
60
+ const props = (_b = (_a = instance.locales) === null || _a === void 0 ? void 0 : _a[locale]) === null || _b === void 0 ? void 0 : _b.props;
61
+ if (!props)
62
+ return null;
63
+ return { component, Component, props };
64
+ },
65
+ loadComponents(input) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const result = yield loadComponents(input);
68
+ if (result) {
69
+ set((s) => {
70
+ s.state.config = result.config;
71
+ Object.assign(s.state.components, result.components);
72
+ Object.entries(result.instances).forEach(([instanceId, instance]) => {
73
+ var _a, _b;
74
+ var _c, _d;
75
+ (_a = (_c = s.state.instances)[instanceId]) !== null && _a !== void 0 ? _a : (_c[instanceId] = { componentId: instance.componentId });
76
+ (_b = (_d = s.state.instances[instanceId]).locales) !== null && _b !== void 0 ? _b : (_d.locales = {});
77
+ Object.assign(s.state.instances[instanceId].locales, instance.locales);
78
+ });
79
+ });
80
+ }
81
+ });
82
+ },
83
+ })));
84
+ function loadComponents(input) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const result = yield preloadComponents(Object.assign(Object.assign({}, input), { module: PreloadComponentScriptModule.ESM }));
87
+ if (!result)
88
+ return null;
89
+ const components = Object.fromEntries(yield Promise.all(Object.values(result.components).map((item) => __awaiter(this, void 0, void 0, function* () {
90
+ if (item.script.module !== PreloadComponentScriptModule.ESM) {
91
+ throw new Error('received non esm component script');
92
+ }
93
+ const url = URL.createObjectURL(new Blob([item.script.script], { type: 'application/javascript' }));
94
+ const m = yield import(/* @vite-ignore */ url);
95
+ if (typeof (m === null || m === void 0 ? void 0 : m.default) !== 'function') {
96
+ throw new Error(`Invalid custom component module: ${typeof (m === null || m === void 0 ? void 0 : m.default)}`);
97
+ }
98
+ return [
99
+ item.component.id,
100
+ {
101
+ component: item.component,
102
+ Component: m.default,
103
+ },
104
+ ];
105
+ }))));
106
+ return Object.assign(Object.assign({}, result), { components, instances: Object.fromEntries(result.instances.map((_a) => {
107
+ var { id } = _a, instance = __rest(_a, ["id"]);
108
+ return [id, instance];
109
+ })) });
110
+ });
111
+ }
112
+ const COMPONENT_LOADER_MAP = {};
113
+ export function usePreloadComponent({ instanceId, componentId, properties: parameters, locale: requestLocale, dev: { mode } = {}, }) {
114
+ var _a;
115
+ const previousRef = useRef();
116
+ const locale = customComponentStates((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === requestLocale)) ? requestLocale : undefined; });
117
+ const defaultLocale = customComponentStates((s) => s.state.config.defaultLocale);
118
+ const realLocale = locale || defaultLocale;
119
+ const result = customComponentStates((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
120
+ if (result) {
121
+ previousRef.current = result;
122
+ return result;
123
+ }
124
+ if (realLocale && instanceId) {
125
+ const key = [instanceId, realLocale].join('-');
126
+ (_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = customComponentStates.getState().loadComponents({
127
+ mode,
128
+ locale: realLocale,
129
+ instances: [{ id: instanceId, component: { id: componentId }, properties: parameters }],
130
+ }));
131
+ if (previousRef.current)
132
+ return previousRef.current;
133
+ }
134
+ return null;
135
+ }
136
+ export function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
137
+ const [Component, setComponent] = useState();
138
+ const component = mergeComponent({
139
+ componentId,
140
+ getComponent: (componentId) => { var _a; return (_a = components === null || components === void 0 ? void 0 : components[componentId]) === null || _a === void 0 ? void 0 : _a.data; },
141
+ locale,
142
+ defaultLocale,
143
+ properties,
144
+ });
145
+ const script = useDeferredValue(component === null || component === void 0 ? void 0 : component.script);
146
+ useEffect(() => {
147
+ if (script) {
148
+ transpileAndLoadScript(script).then((m) => {
149
+ setComponent(() => m.default);
150
+ });
151
+ }
152
+ }, [script]);
153
+ if (!component || !Component)
154
+ return null;
155
+ return {
156
+ Component,
157
+ props: component.properties,
158
+ };
159
+ }
160
+ function transpileAndLoadScript(script) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ const [ts, { createBuiltinModuleTransformer }] = yield Promise.all([
163
+ import('typescript'),
164
+ import('../../utils/typescript/builtin-module-transformer'),
165
+ ]);
166
+ const compiled = ts.transpileModule(script, {
167
+ compilerOptions: { jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2016 },
168
+ transformers: {
169
+ before: [createBuiltinModuleTransformer(ts)],
170
+ },
171
+ }).outputText;
172
+ const url = URL.createObjectURL(new Blob([compiled], { type: 'application/javascript' }));
173
+ return import(/* @vite-ignore */ url);
174
+ });
175
+ }
@@ -1 +1,5 @@
1
- export {};
1
+ export var PreloadComponentScriptModule;
2
+ (function (PreloadComponentScriptModule) {
3
+ PreloadComponentScriptModule["UMD_FN"] = "umd_fn";
4
+ PreloadComponentScriptModule["ESM"] = "esm";
5
+ })(PreloadComponentScriptModule || (PreloadComponentScriptModule = {}));
@@ -3,6 +3,7 @@ import * as builtinMuiLab from '../builtin/mui/lab';
3
3
  import * as builtinMuiMaterial from '../builtin/mui/material';
4
4
  import * as builtinReact from '../builtin/react';
5
5
  import * as builtinReactHookForm from '../builtin/react-hook-form';
6
+ import * as reactWrapBalancer from '../builtin/react-wrap-balancer';
6
7
  import * as builtinUtils from '../builtin/utils';
7
8
  import * as builtinZustand from '../builtin/zustand';
8
9
  import * as builtinZustandMiddlewareImmer from '../builtin/zustand/middleware/immer';
@@ -19,6 +20,7 @@ function injectGlobalComponents() {
19
20
  '@blocklet/pages-kit/builtin/iconify/react': builtinIconifyReact,
20
21
  '@blocklet/pages-kit/builtin/zustand': builtinZustand,
21
22
  '@blocklet/pages-kit/builtin/zustand/middleware/immer': builtinZustandMiddlewareImmer,
23
+ '@blocklet/pages-kit/builtin/react-wrap-balancer': reactWrapBalancer,
22
24
  },
23
25
  require(module) {
24
26
  return win[BuiltinModulesGlobalVariableName].modules[module];
@@ -1,29 +1,34 @@
1
- import { PreloadComponentsStateGlobalVariableName } from '../types';
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));
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { PreloadComponentScriptModule, PreloadComponentsStateGlobalVariableName, } from '../types';
13
+ export function injectPreloadComponents(data) {
13
14
  const injectState = {
14
15
  config: data.config,
15
- components: Object.fromEntries(Object.entries(data.components).map(([componentId, { script, component }]) => [
16
- componentId,
17
- { preloadComponentModuleName: script.umd.moduleName, component },
18
- ])),
19
- props: data.props,
16
+ components: Object.fromEntries(Object.entries(data.components).map(([componentId, { script, component }]) => {
17
+ if (script.module !== PreloadComponentScriptModule.UMD_FN)
18
+ throw new Error(`Only support inject script with module ${PreloadComponentScriptModule.UMD_FN}`);
19
+ return [componentId, { componentModuleGlobalVariable: script.moduleName, component }];
20
+ })),
21
+ instances: Object.fromEntries(data.instances.map((_a) => {
22
+ var { id } = _a, instance = __rest(_a, ["id"]);
23
+ return [id, instance];
24
+ })),
20
25
  };
21
26
  return {
22
27
  html: `\
23
28
  ${Object.values(data.components)
24
- .map(({ script }) => `\
29
+ .map(({ script: { script } }) => `\
25
30
  <script>
26
- ${script.umd.script}
31
+ ${script}
27
32
  </script>
28
33
  `)
29
34
  .join('\n')}
@@ -1,2 +1,2 @@
1
- import { PreloadComponentQuery, PreloadComponentsResult } from '../types';
2
- export declare function preloadComponents({ mode, name, id, locale, }: PreloadComponentQuery): Promise<PreloadComponentsResult>;
1
+ import { PreloadComponentsInput, PreloadComponentsResult } from '../types';
2
+ export declare function preloadComponents(input: PreloadComponentsInput): Promise<PreloadComponentsResult>;
@@ -1,2 +1,2 @@
1
- import { PreloadComponentQuery, PreloadComponentsResult } from '../types';
2
- export declare function preloadComponents({ mode, name, id, locale, }: PreloadComponentQuery): Promise<PreloadComponentsResult>;
1
+ import { PreloadComponentsInput, PreloadComponentsResult } from '../types';
2
+ export declare function preloadComponents(input: PreloadComponentsInput): Promise<PreloadComponentsResult | null>;
@@ -0,0 +1 @@
1
+ export * from 'react-wrap-balancer';
@@ -1,13 +1,20 @@
1
1
  import '../../utils/inject-global-components';
2
2
  import { StateMode } from '../../types';
3
3
  import { CustomComponent } from '../../types/core';
4
- export interface CustomComponentRendererProps {
4
+ export * from './state';
5
+ export interface CustomComponentRendererDevProps {
5
6
  mode?: StateMode;
7
+ defaultLocale?: string;
8
+ components?: {
9
+ [id: string]: {
10
+ data: CustomComponent;
11
+ };
12
+ };
13
+ }
14
+ export interface CustomComponentRendererProps {
6
15
  instanceId?: string;
7
16
  componentId: string;
8
17
  locale?: string;
9
- defaultLocale?: string;
10
- components?: CustomComponent[];
11
18
  properties?: {
12
19
  [key: string]: {
13
20
  value: any;
@@ -16,6 +23,6 @@ export interface CustomComponentRendererProps {
16
23
  props?: {
17
24
  [key: string]: any;
18
25
  };
26
+ dev?: CustomComponentRendererDevProps;
19
27
  }
20
- export default function CustomComponentRenderer({ defaultLocale, ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
21
- export declare function transpileAndLoadScript(script: string): Promise<any>;
28
+ export default function CustomComponentRenderer({ ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;