@blocklet/pages-kit 0.2.438 → 0.2.439
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/components/CustomComponentRenderer/state.js +27 -21
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/components/CustomComponentRenderer/state.js +26 -21
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
};
|
|
21
21
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
22
|
import { cx } from '@emotion/css';
|
|
23
|
+
import { isEmpty } from 'lodash';
|
|
23
24
|
import set from 'lodash/set';
|
|
24
25
|
import { useDeferredValue, useEffect, useRef, useState } from 'react';
|
|
25
26
|
import { Helmet } from 'react-helmet';
|
|
@@ -44,6 +45,29 @@ function importCustomComponent(m, { componentId }) {
|
|
|
44
45
|
}
|
|
45
46
|
return Component;
|
|
46
47
|
}
|
|
48
|
+
export function getPropertiesFromCode(m) {
|
|
49
|
+
let propertiesFromCode = null;
|
|
50
|
+
if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
|
|
51
|
+
propertiesFromCode = {};
|
|
52
|
+
m.PROPERTIES_SCHEMA.forEach((data, index) => {
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
(_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.blocklet) === null || _a === void 0 ? void 0 : _a.languages) === null || _b === void 0 ? void 0 : _b.forEach) === null || _c === void 0 ? void 0 : _c.call(_b, (item) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const { code: localKey } = item;
|
|
58
|
+
if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
|
|
59
|
+
// fallback to en
|
|
60
|
+
set(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
propertiesFromCode[data.id] = {
|
|
64
|
+
index,
|
|
65
|
+
data,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return propertiesFromCode;
|
|
70
|
+
}
|
|
47
71
|
export const customComponentStates = () => {
|
|
48
72
|
states !== null && states !== void 0 ? states : (states = create()(immer((set, get) => ({
|
|
49
73
|
state: {
|
|
@@ -183,7 +207,7 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
|
|
|
183
207
|
getComponent: (componentId) => {
|
|
184
208
|
var _a, _b, _c, _d;
|
|
185
209
|
// setting properties from code if it's not set from components props
|
|
186
|
-
if (propertiesFromCode &&
|
|
210
|
+
if (propertiesFromCode && isEmpty((_b = (_a = components === null || components === void 0 ? void 0 : components[componentId]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.properties)) {
|
|
187
211
|
return Object.assign(Object.assign({}, (_c = components === null || components === void 0 ? void 0 : components[componentId]) === null || _c === void 0 ? void 0 : _c.data), { properties: propertiesFromCode });
|
|
188
212
|
}
|
|
189
213
|
return (_d = components === null || components === void 0 ? void 0 : components[componentId]) === null || _d === void 0 ? void 0 : _d.data;
|
|
@@ -197,27 +221,8 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
|
|
|
197
221
|
if (script) {
|
|
198
222
|
transpileAndLoadScript(script)
|
|
199
223
|
.then((m) => {
|
|
200
|
-
let propertiesFromCode;
|
|
201
224
|
// get properties from code
|
|
202
|
-
|
|
203
|
-
propertiesFromCode = {};
|
|
204
|
-
m.PROPERTIES_SCHEMA.forEach((data, index) => {
|
|
205
|
-
var _a, _b, _c;
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
(_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.blocklet) === null || _a === void 0 ? void 0 : _a.languages) === null || _b === void 0 ? void 0 : _b.forEach) === null || _c === void 0 ? void 0 : _c.call(_b, (item) => {
|
|
208
|
-
var _a, _b;
|
|
209
|
-
const { code: localKey } = item;
|
|
210
|
-
if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
|
|
211
|
-
// fallback to en
|
|
212
|
-
set(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
propertiesFromCode[data.id] = {
|
|
216
|
-
index,
|
|
217
|
-
data,
|
|
218
|
-
};
|
|
219
|
-
});
|
|
220
|
-
}
|
|
225
|
+
const propertiesFromCode = getPropertiesFromCode(m);
|
|
221
226
|
setComponent({ Component: m.default, propertiesFromCode });
|
|
222
227
|
})
|
|
223
228
|
.catch((error) => {
|