@measured/puck-plugin-heading-analyzer 0.15.0-canary.aedd401 → 0.15.0-canary.dd7051e
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +90 -38
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -77164,6 +77164,16 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
77164
77164
|
init_react_import2();
|
77165
77165
|
var import_react132 = require("react");
|
77166
77166
|
init_react_import2();
|
77167
|
+
init_react_import2();
|
77168
|
+
var getChanged = (newItem, oldItem) => {
|
77169
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
77170
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
77171
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
77172
|
+
return __spreadProps2(__spreadValues2({}, acc), {
|
77173
|
+
[item]: oldItemProps[item] !== newItemProps[item]
|
77174
|
+
});
|
77175
|
+
}, {}) : {};
|
77176
|
+
};
|
77167
77177
|
var cache = { lastChange: {} };
|
77168
77178
|
var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async2(void 0, null, function* () {
|
77169
77179
|
return yield Promise.all(
|
@@ -77180,25 +77190,15 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
77180
77190
|
var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async2(void 0, null, function* () {
|
77181
77191
|
const configForItem = config.components[item.type];
|
77182
77192
|
if (configForItem.resolveData) {
|
77183
|
-
|
77184
|
-
|
77185
|
-
|
77186
|
-
);
|
77187
|
-
if (cache.lastChange[item.props.id]) {
|
77188
|
-
const { item: oldItem, resolved } = cache.lastChange[item.props.id];
|
77189
|
-
if (oldItem === item) {
|
77190
|
-
return resolved;
|
77191
|
-
}
|
77192
|
-
Object.keys(item.props).forEach((propName) => {
|
77193
|
-
if (oldItem.props[propName] === item.props[propName]) {
|
77194
|
-
changed[propName] = false;
|
77195
|
-
}
|
77196
|
-
});
|
77193
|
+
const { item: oldItem = {}, resolved = {} } = cache.lastChange[item.props.id] || {};
|
77194
|
+
if (item && item === oldItem) {
|
77195
|
+
return resolved;
|
77197
77196
|
}
|
77197
|
+
const changed = getChanged(item, oldItem);
|
77198
77198
|
if (onResolveStart) {
|
77199
77199
|
onResolveStart(item);
|
77200
77200
|
}
|
77201
|
-
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed });
|
77201
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed, lastData: oldItem });
|
77202
77202
|
const { readOnly: existingReadOnly = {} } = item || {};
|
77203
77203
|
const newReadOnly = __spreadValues2(__spreadValues2({}, existingReadOnly), readOnly);
|
77204
77204
|
const resolvedItem = __spreadProps2(__spreadValues2({}, item), {
|
@@ -77237,26 +77237,16 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
77237
77237
|
init_react_import2();
|
77238
77238
|
var cache2 = {};
|
77239
77239
|
var resolveRootData = (data, config) => __async2(void 0, null, function* () {
|
77240
|
-
var _a3, _b;
|
77240
|
+
var _a3, _b, _c, _d, _e;
|
77241
77241
|
if (((_a3 = config.root) == null ? void 0 : _a3.resolveData) && data.root.props) {
|
77242
|
-
|
77243
|
-
|
77244
|
-
{}
|
77245
|
-
);
|
77246
|
-
if (cache2.lastChange) {
|
77247
|
-
const { original, resolved } = cache2.lastChange;
|
77248
|
-
if (original === data.root) {
|
77249
|
-
return resolved;
|
77250
|
-
}
|
77251
|
-
Object.keys(data.root.props).forEach((propName) => {
|
77252
|
-
if (original.props[propName] === data.root.props[propName]) {
|
77253
|
-
changed[propName] = false;
|
77254
|
-
}
|
77255
|
-
});
|
77242
|
+
if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
|
77243
|
+
return cache2.lastChange.resolved;
|
77256
77244
|
}
|
77245
|
+
const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
|
77257
77246
|
const rootWithProps = data.root;
|
77258
|
-
const resolvedRoot = yield (
|
77259
|
-
changed
|
77247
|
+
const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
|
77248
|
+
changed,
|
77249
|
+
lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {}
|
77260
77250
|
});
|
77261
77251
|
cache2.lastChange = {
|
77262
77252
|
original: data.root,
|
@@ -78320,7 +78310,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
78320
78310
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Render2, __spreadProps2(__spreadValues2({}, mergedProps), { children }));
|
78321
78311
|
};
|
78322
78312
|
init_react_import2();
|
78323
|
-
var styles_module_default14 = { "PuckFields": "
|
78313
|
+
var styles_module_default14 = { "PuckFields": "_PuckFields_1o0if_1", "PuckFields--isLoading": "_PuckFields--isLoading_1o0if_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_1o0if_10" };
|
78324
78314
|
var import_react19 = require("react");
|
78325
78315
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
78326
78316
|
var getClassName19 = get_class_name_factory_default2("PuckFields", styles_module_default14);
|
@@ -78331,13 +78321,73 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
78331
78321
|
children,
|
78332
78322
|
isLoading
|
78333
78323
|
}) => {
|
78334
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19(), children: [
|
78324
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19({ isLoading }), children: [
|
78335
78325
|
children,
|
78336
78326
|
isLoading && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react_spinners6.ClipLoader, { "aria-label": "loading" }) })
|
78337
78327
|
] });
|
78338
78328
|
};
|
78329
|
+
var useResolvedFields = () => {
|
78330
|
+
var _a3;
|
78331
|
+
const { selectedItem, state, config } = useAppContext2();
|
78332
|
+
const { data } = state;
|
78333
|
+
const rootFields = ((_a3 = config.root) == null ? void 0 : _a3.fields) || defaultPageFields;
|
78334
|
+
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
78335
|
+
const defaultFields = selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields;
|
78336
|
+
const rootProps = data.root.props || data.root;
|
78337
|
+
const [lastSelectedData, setLastSelectedData] = (0, import_react19.useState)(
|
78338
|
+
{}
|
78339
|
+
);
|
78340
|
+
const [resolvedFields, setResolvedFields] = (0, import_react19.useState)(defaultFields || {});
|
78341
|
+
const [fieldsLoading, setFieldsLoading] = (0, import_react19.useState)(false);
|
78342
|
+
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
78343
|
+
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
78344
|
+
const resolveFields = (0, import_react19.useCallback)(
|
78345
|
+
(..._0) => __async2(void 0, [..._0], function* (fields = {}) {
|
78346
|
+
var _a22, _b, _c;
|
78347
|
+
const lastData = ((_a22 = lastSelectedData.props) == null ? void 0 : _a22.id) === componentData.props.id ? lastSelectedData : {};
|
78348
|
+
const changed = getChanged(componentData, lastData);
|
78349
|
+
setLastSelectedData(componentData);
|
78350
|
+
if (selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields)) {
|
78351
|
+
return yield componentConfig == null ? void 0 : componentConfig.resolveFields(
|
78352
|
+
componentData,
|
78353
|
+
{
|
78354
|
+
changed,
|
78355
|
+
fields,
|
78356
|
+
lastFields: resolvedFields,
|
78357
|
+
lastData,
|
78358
|
+
appState: state
|
78359
|
+
}
|
78360
|
+
);
|
78361
|
+
}
|
78362
|
+
if (!selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields)) {
|
78363
|
+
return yield (_c = config.root) == null ? void 0 : _c.resolveFields(componentData, {
|
78364
|
+
changed,
|
78365
|
+
fields,
|
78366
|
+
lastFields: resolvedFields,
|
78367
|
+
lastData,
|
78368
|
+
appState: state
|
78369
|
+
});
|
78370
|
+
}
|
78371
|
+
return defaultResolveFields(componentData, {
|
78372
|
+
changed,
|
78373
|
+
fields,
|
78374
|
+
lastFields: resolvedFields,
|
78375
|
+
lastData
|
78376
|
+
});
|
78377
|
+
}),
|
78378
|
+
[data, config, componentData, selectedItem, resolvedFields, state]
|
78379
|
+
);
|
78380
|
+
(0, import_react19.useEffect)(() => {
|
78381
|
+
setFieldsLoading(true);
|
78382
|
+
resolveFields(defaultFields).then((fields) => {
|
78383
|
+
setResolvedFields(fields || {});
|
78384
|
+
setFieldsLoading(false);
|
78385
|
+
});
|
78386
|
+
}, [data, defaultFields]);
|
78387
|
+
return [resolvedFields, fieldsLoading];
|
78388
|
+
};
|
78339
78389
|
var Fields = () => {
|
78340
|
-
var _a3, _b
|
78390
|
+
var _a3, _b;
|
78341
78391
|
const {
|
78342
78392
|
selectedItem,
|
78343
78393
|
state,
|
@@ -78349,9 +78399,9 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
78349
78399
|
} = useAppContext2();
|
78350
78400
|
const { data, ui } = state;
|
78351
78401
|
const { itemSelector } = ui;
|
78352
|
-
const
|
78353
|
-
const
|
78354
|
-
const isLoading =
|
78402
|
+
const [fields, fieldsResolving] = useResolvedFields();
|
78403
|
+
const componentResolving = selectedItem ? (_a3 = componentState[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a3.loading : (_b = componentState["puck-root"]) == null ? void 0 : _b.loading;
|
78404
|
+
const isLoading = fieldsResolving || componentResolving;
|
78355
78405
|
const rootProps = data.root.props || data.root;
|
78356
78406
|
const Wrapper = (0, import_react19.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
|
78357
78407
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
@@ -78363,6 +78413,8 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
78363
78413
|
},
|
78364
78414
|
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Wrapper, { isLoading, itemSelector, children: Object.keys(fields).map((fieldName) => {
|
78365
78415
|
const field = fields[fieldName];
|
78416
|
+
if (!(field == null ? void 0 : field.type))
|
78417
|
+
return null;
|
78366
78418
|
const onChange = (value, updatedUi) => {
|
78367
78419
|
var _a22, _b2;
|
78368
78420
|
let currentProps;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@measured/puck-plugin-heading-analyzer",
|
3
|
-
"version": "0.15.0-canary.
|
3
|
+
"version": "0.15.0-canary.dd7051e",
|
4
4
|
"author": "Measured Corporation Ltd <hello@measured.co>",
|
5
5
|
"repository": "measuredco/puck",
|
6
6
|
"bugs": "https://github.com/measuredco/puck/issues",
|
@@ -18,7 +18,7 @@
|
|
18
18
|
"dist"
|
19
19
|
],
|
20
20
|
"devDependencies": {
|
21
|
-
"@measured/puck": "^0.15.0-canary.
|
21
|
+
"@measured/puck": "^0.15.0-canary.dd7051e",
|
22
22
|
"@types/react": "^18.2.0",
|
23
23
|
"@types/react-dom": "^18.2.0",
|
24
24
|
"eslint": "^7.32.0",
|