@blocklet/pages-kit 0.2.437 → 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
|
@@ -47,10 +47,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
47
47
|
};
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
49
|
exports.customComponentStates = void 0;
|
|
50
|
+
exports.getPropertiesFromCode = getPropertiesFromCode;
|
|
50
51
|
exports.useComponent = useComponent;
|
|
51
52
|
exports.transpileAndLoadScript = transpileAndLoadScript;
|
|
52
53
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
53
54
|
const css_1 = require("@emotion/css");
|
|
55
|
+
const lodash_1 = require("lodash");
|
|
54
56
|
const set_1 = __importDefault(require("lodash/set"));
|
|
55
57
|
const react_1 = require("react");
|
|
56
58
|
const react_helmet_1 = require("react-helmet");
|
|
@@ -75,6 +77,29 @@ function importCustomComponent(m, { componentId }) {
|
|
|
75
77
|
}
|
|
76
78
|
return Component;
|
|
77
79
|
}
|
|
80
|
+
function getPropertiesFromCode(m) {
|
|
81
|
+
let propertiesFromCode = null;
|
|
82
|
+
if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
|
|
83
|
+
propertiesFromCode = {};
|
|
84
|
+
m.PROPERTIES_SCHEMA.forEach((data, index) => {
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
(_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) => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const { code: localKey } = item;
|
|
90
|
+
if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
|
|
91
|
+
// fallback to en
|
|
92
|
+
(0, set_1.default)(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
propertiesFromCode[data.id] = {
|
|
96
|
+
index,
|
|
97
|
+
data,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return propertiesFromCode;
|
|
102
|
+
}
|
|
78
103
|
const customComponentStates = () => {
|
|
79
104
|
states !== null && states !== void 0 ? states : (states = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
80
105
|
state: {
|
|
@@ -215,7 +240,7 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
|
|
|
215
240
|
getComponent: (componentId) => {
|
|
216
241
|
var _a, _b, _c, _d;
|
|
217
242
|
// setting properties from code if it's not set from components props
|
|
218
|
-
if (propertiesFromCode &&
|
|
243
|
+
if (propertiesFromCode && (0, lodash_1.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)) {
|
|
219
244
|
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 });
|
|
220
245
|
}
|
|
221
246
|
return (_d = components === null || components === void 0 ? void 0 : components[componentId]) === null || _d === void 0 ? void 0 : _d.data;
|
|
@@ -229,27 +254,8 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
|
|
|
229
254
|
if (script) {
|
|
230
255
|
transpileAndLoadScript(script)
|
|
231
256
|
.then((m) => {
|
|
232
|
-
let propertiesFromCode;
|
|
233
257
|
// get properties from code
|
|
234
|
-
|
|
235
|
-
propertiesFromCode = {};
|
|
236
|
-
m.PROPERTIES_SCHEMA.forEach((data, index) => {
|
|
237
|
-
var _a, _b, _c;
|
|
238
|
-
// @ts-ignore
|
|
239
|
-
(_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) => {
|
|
240
|
-
var _a, _b;
|
|
241
|
-
const { code: localKey } = item;
|
|
242
|
-
if (!((_a = data === null || data === void 0 ? void 0 : data.locales) === null || _a === void 0 ? void 0 : _a[localKey])) {
|
|
243
|
-
// fallback to en
|
|
244
|
-
(0, set_1.default)(data, `locales.${localKey}`, (_b = data.locales) === null || _b === void 0 ? void 0 : _b.en);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
propertiesFromCode[data.id] = {
|
|
248
|
-
index,
|
|
249
|
-
data,
|
|
250
|
-
};
|
|
251
|
-
});
|
|
252
|
-
}
|
|
258
|
+
const propertiesFromCode = getPropertiesFromCode(m);
|
|
253
259
|
setComponent({ Component: m.default, propertiesFromCode });
|
|
254
260
|
})
|
|
255
261
|
.catch((error) => {
|