@blocklet/pages-kit 0.2.221 → 0.2.222

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TextField = exports.Switch = exports.Stack = exports.Popper = exports.Paper = exports.DialogTitle = exports.DialogContent = exports.DialogActions = exports.Dialog = exports.ClickAwayListener = exports.Button = exports.Box = exports.Autocomplete = void 0;
3
+ exports.Typography = exports.Container = exports.TextField = exports.Switch = exports.Stack = exports.Popper = exports.Paper = exports.DialogTitle = exports.DialogContent = exports.DialogActions = exports.Dialog = exports.ClickAwayListener = exports.Button = exports.Box = exports.Autocomplete = void 0;
4
4
  var material_1 = require("@mui/material");
5
5
  Object.defineProperty(exports, "Autocomplete", { enumerable: true, get: function () { return material_1.Autocomplete; } });
6
6
  var material_2 = require("@mui/material");
@@ -27,3 +27,7 @@ var material_12 = require("@mui/material");
27
27
  Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return material_12.Switch; } });
28
28
  var material_13 = require("@mui/material");
29
29
  Object.defineProperty(exports, "TextField", { enumerable: true, get: function () { return material_13.TextField; } });
30
+ var material_14 = require("@mui/material");
31
+ Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return material_14.Container; } });
32
+ var material_15 = require("@mui/material");
33
+ Object.defineProperty(exports, "Typography", { enumerable: true, get: function () { return material_15.Typography; } });
@@ -151,28 +151,21 @@ function loadRemoteComponent({ mode, instanceId, componentId, locale, }) {
151
151
  }));
152
152
  return LOAD_REMOTE_COMPONENT_TASKS[key];
153
153
  }
154
- function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters, props, }) {
154
+ function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters, }) {
155
155
  var _a;
156
156
  const scriptRef = (0, react_1.useRef)({});
157
157
  const preloadComponent = (0, react_1.useMemo)(() => getScriptComponent(componentId), [componentId, PRELOAD_COMPONENTS_STATE_KEY]);
158
158
  const preloadState = (0, react_1.useMemo)(() => {
159
159
  var _a, _b;
160
- 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];
161
- }, [instanceId, locale, PRELOAD_COMPONENTS_STATE_KEY]);
160
+ 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];
161
+ }, [instanceId, locale, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
162
162
  const preloadDefaultState = (0, react_1.useMemo)(() => {
163
163
  var _a, _b;
164
164
  return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[defaultLocale];
165
165
  }, [instanceId, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
166
166
  const previousPreload = (0, react_1.useRef)();
167
167
  const [, update] = (0, react_1.useState)(0);
168
- if ((props || preloadState) && preloadComponent) {
169
- previousPreload.current = {
170
- Component: preloadComponent.Component,
171
- properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
172
- };
173
- return previousPreload.current;
174
- }
175
- if (!(components === null || components === void 0 ? void 0 : components.length) && preloadComponent) {
168
+ if (!(components === null || components === void 0 ? void 0 : components.length) && !preloadState && preloadComponent) {
176
169
  loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale }).then(() => {
177
170
  update(PRELOAD_COMPONENTS_STATE_KEY);
178
171
  });
@@ -180,6 +173,13 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
180
173
  return previousPreload.current;
181
174
  }
182
175
  }
176
+ if ((preloadState || preloadDefaultState) && preloadComponent) {
177
+ previousPreload.current = {
178
+ Component: preloadComponent.Component,
179
+ properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
180
+ };
181
+ return previousPreload.current;
182
+ }
183
183
  const component = (0, property_1.mergeComponent)({
184
184
  componentId,
185
185
  getComponent: (componentId) => components === null || components === void 0 ? void 0 : components.find((i) => i.id === componentId),
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var _a;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.loadAndInjectComponents = exports.PRELOAD_COMPONENTS_STATE = void 0;
14
+ const api_1 = require("../api");
15
+ const preload_1 = require("../types/preload");
16
+ (_a = window[preload_1.PreloadComponentsStateGlobalVariableName]) !== null && _a !== void 0 ? _a : (window[preload_1.PreloadComponentsStateGlobalVariableName] = {
17
+ config: {},
18
+ components: {},
19
+ props: {},
20
+ });
21
+ exports.PRELOAD_COMPONENTS_STATE = window[preload_1.PreloadComponentsStateGlobalVariableName];
22
+ function loadAndInjectComponents({ mode, name, locale, }) {
23
+ var _a, _b, _c, _d, _e, _f;
24
+ var _g, _h, _j;
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const { components, props } = exports.PRELOAD_COMPONENTS_STATE;
27
+ const c = Object.values(components).find((i) => !!i.component.name && i.component.name.toLowerCase() === name.toLowerCase());
28
+ if (c && props[c.component.id]) {
29
+ return;
30
+ }
31
+ const result = yield (0, api_1.preloadComponents)({ mode, name, locale });
32
+ const componentId = Object.keys(result.props)[0];
33
+ for (const i of Object.values(result.components)) {
34
+ if (!window[i.script.umd.moduleName]) {
35
+ const script = document.createElement('script');
36
+ script.textContent = i.script.umd.script;
37
+ document.body.appendChild(script);
38
+ }
39
+ exports.PRELOAD_COMPONENTS_STATE.components[i.component.id] = {
40
+ preloadComponentModuleName: i.script.umd.moduleName,
41
+ component: i.component,
42
+ };
43
+ }
44
+ (_a = (_g = exports.PRELOAD_COMPONENTS_STATE.props)[componentId]) !== null && _a !== void 0 ? _a : (_g[componentId] = {});
45
+ (_b = (_h = exports.PRELOAD_COMPONENTS_STATE.props[componentId]).locales) !== null && _b !== void 0 ? _b : (_h.locales = {});
46
+ (_c = (_j = exports.PRELOAD_COMPONENTS_STATE.props[componentId].locales)[locale]) !== null && _c !== void 0 ? _c : (_j[locale] = {});
47
+ exports.PRELOAD_COMPONENTS_STATE.props[componentId].locales[locale].props =
48
+ (_f = (_e = (_d = result.props[componentId]) === null || _d === void 0 ? void 0 : _d.locales) === null || _e === void 0 ? void 0 : _e[locale]) === null || _f === void 0 ? void 0 : _f.props;
49
+ });
50
+ }
51
+ exports.loadAndInjectComponents = loadAndInjectComponents;
@@ -11,3 +11,5 @@ export { Popper } from '@mui/material';
11
11
  export { Stack } from '@mui/material';
12
12
  export { Switch } from '@mui/material';
13
13
  export { TextField } from '@mui/material';
14
+ export { Container } from '@mui/material';
15
+ export { Typography } from '@mui/material';
@@ -124,28 +124,21 @@ function loadRemoteComponent({ mode, instanceId, componentId, locale, }) {
124
124
  }));
125
125
  return LOAD_REMOTE_COMPONENT_TASKS[key];
126
126
  }
127
- function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters, props, }) {
127
+ function useComponent({ mode, instanceId, componentId, components, locale, defaultLocale, properties: parameters, }) {
128
128
  var _a;
129
129
  const scriptRef = useRef({});
130
130
  const preloadComponent = useMemo(() => getScriptComponent(componentId), [componentId, PRELOAD_COMPONENTS_STATE_KEY]);
131
131
  const preloadState = useMemo(() => {
132
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];
134
- }, [instanceId, locale, PRELOAD_COMPONENTS_STATE_KEY]);
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
135
  const preloadDefaultState = useMemo(() => {
136
136
  var _a, _b;
137
137
  return (_b = (_a = PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.props[instanceId]) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[defaultLocale];
138
138
  }, [instanceId, defaultLocale, PRELOAD_COMPONENTS_STATE_KEY]);
139
139
  const previousPreload = useRef();
140
140
  const [, update] = useState(0);
141
- if ((props || preloadState) && preloadComponent) {
142
- previousPreload.current = {
143
- Component: preloadComponent.Component,
144
- properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
145
- };
146
- return previousPreload.current;
147
- }
148
- if (!(components === null || components === void 0 ? void 0 : components.length) && preloadComponent) {
141
+ if (!(components === null || components === void 0 ? void 0 : components.length) && !preloadState && preloadComponent) {
149
142
  loadRemoteComponent({ mode, instanceId, componentId, locale: locale || defaultLocale }).then(() => {
150
143
  update(PRELOAD_COMPONENTS_STATE_KEY);
151
144
  });
@@ -153,6 +146,13 @@ function useComponent({ mode, instanceId, componentId, components, locale, defau
153
146
  return previousPreload.current;
154
147
  }
155
148
  }
149
+ if ((preloadState || preloadDefaultState) && preloadComponent) {
150
+ previousPreload.current = {
151
+ Component: preloadComponent.Component,
152
+ properties: (_a = preloadState === null || preloadState === void 0 ? void 0 : preloadState.props) !== null && _a !== void 0 ? _a : preloadDefaultState === null || preloadDefaultState === void 0 ? void 0 : preloadDefaultState.props,
153
+ };
154
+ return previousPreload.current;
155
+ }
156
156
  const component = mergeComponent({
157
157
  componentId,
158
158
  getComponent: (componentId) => components === null || components === void 0 ? void 0 : components.find((i) => i.id === componentId),
@@ -0,0 +1,47 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var _a;
11
+ import { preloadComponents } from '../api';
12
+ import { PreloadComponentsStateGlobalVariableName } from '../types/preload';
13
+ (_a = window[PreloadComponentsStateGlobalVariableName]) !== null && _a !== void 0 ? _a : (window[PreloadComponentsStateGlobalVariableName] = {
14
+ config: {},
15
+ components: {},
16
+ props: {},
17
+ });
18
+ export const PRELOAD_COMPONENTS_STATE = window[PreloadComponentsStateGlobalVariableName];
19
+ export function loadAndInjectComponents({ mode, name, locale, }) {
20
+ var _a, _b, _c, _d, _e, _f;
21
+ var _g, _h, _j;
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const { components, props } = PRELOAD_COMPONENTS_STATE;
24
+ const c = Object.values(components).find((i) => !!i.component.name && i.component.name.toLowerCase() === name.toLowerCase());
25
+ if (c && props[c.component.id]) {
26
+ return;
27
+ }
28
+ const result = yield preloadComponents({ mode, name, locale });
29
+ const componentId = Object.keys(result.props)[0];
30
+ for (const i of Object.values(result.components)) {
31
+ if (!window[i.script.umd.moduleName]) {
32
+ const script = document.createElement('script');
33
+ script.textContent = i.script.umd.script;
34
+ document.body.appendChild(script);
35
+ }
36
+ PRELOAD_COMPONENTS_STATE.components[i.component.id] = {
37
+ preloadComponentModuleName: i.script.umd.moduleName,
38
+ component: i.component,
39
+ };
40
+ }
41
+ (_a = (_g = PRELOAD_COMPONENTS_STATE.props)[componentId]) !== null && _a !== void 0 ? _a : (_g[componentId] = {});
42
+ (_b = (_h = PRELOAD_COMPONENTS_STATE.props[componentId]).locales) !== null && _b !== void 0 ? _b : (_h.locales = {});
43
+ (_c = (_j = PRELOAD_COMPONENTS_STATE.props[componentId].locales)[locale]) !== null && _c !== void 0 ? _c : (_j[locale] = {});
44
+ PRELOAD_COMPONENTS_STATE.props[componentId].locales[locale].props =
45
+ (_f = (_e = (_d = result.props[componentId]) === null || _d === void 0 ? void 0 : _d.locales) === null || _e === void 0 ? void 0 : _e[locale]) === null || _f === void 0 ? void 0 : _f.props;
46
+ });
47
+ }
@@ -11,3 +11,5 @@ export { Popper } from '@mui/material';
11
11
  export { Stack } from '@mui/material';
12
12
  export { Switch } from '@mui/material';
13
13
  export { TextField } from '@mui/material';
14
+ export { Container } from '@mui/material';
15
+ export { Typography } from '@mui/material';
@@ -0,0 +1,8 @@
1
+ import { StateMode } from '../types';
2
+ import { PreloadComponentsState } from '../types/preload';
3
+ export declare const PRELOAD_COMPONENTS_STATE: PreloadComponentsState;
4
+ export declare function loadAndInjectComponents({ mode, name, locale, }: {
5
+ mode?: StateMode;
6
+ name: string;
7
+ locale: string;
8
+ }): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.221",
3
+ "version": "0.2.222",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"