@measured/puck-plugin-heading-analyzer 0.15.0-canary.480467a → 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 +117 -53
- 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;
|
@@ -79567,7 +79619,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
79567
79619
|
() => createReducer({ config, record: historyStore.record })
|
79568
79620
|
);
|
79569
79621
|
const [initialAppState] = (0, import_react29.useState)(() => {
|
79570
|
-
var _a22, _b, _c, _d, _e;
|
79622
|
+
var _a22, _b, _c, _d, _e, _f;
|
79571
79623
|
const initial = __spreadValues2(__spreadValues2({}, defaultAppState2.ui), initialUi);
|
79572
79624
|
let clientUiState = {};
|
79573
79625
|
if (typeof window !== "undefined") {
|
@@ -79594,11 +79646,12 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
79594
79646
|
};
|
79595
79647
|
}
|
79596
79648
|
}
|
79597
|
-
const rootProps2 = initialData.root.props || initialData.root;
|
79598
|
-
const defaultedRootProps = __spreadValues2(__spreadValues2({}, (
|
79649
|
+
const rootProps2 = ((_e = initialData == null ? void 0 : initialData.root) == null ? void 0 : _e.props) || initialData.root || {};
|
79650
|
+
const defaultedRootProps = __spreadValues2(__spreadValues2({}, (_f = config.root) == null ? void 0 : _f.defaultProps), rootProps2);
|
79599
79651
|
return __spreadProps2(__spreadValues2({}, defaultAppState2), {
|
79600
79652
|
data: __spreadProps2(__spreadValues2({}, initialData), {
|
79601
|
-
root: defaultedRootProps
|
79653
|
+
root: defaultedRootProps,
|
79654
|
+
content: initialData.content || []
|
79602
79655
|
}),
|
79603
79656
|
ui: __spreadProps2(__spreadValues2(__spreadValues2({}, initial), clientUiState), {
|
79604
79657
|
// Store categories under componentList on state to allow render functions and plugins to modify
|
@@ -79964,10 +80017,14 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
79964
80017
|
data
|
79965
80018
|
}) {
|
79966
80019
|
var _a3;
|
79967
|
-
const
|
80020
|
+
const defaultedData = __spreadProps2(__spreadValues2({}, data), {
|
80021
|
+
root: data.root || {},
|
80022
|
+
content: data.content || []
|
80023
|
+
});
|
80024
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
79968
80025
|
const title = (rootProps == null ? void 0 : rootProps.title) || "";
|
79969
80026
|
if ((_a3 = config.root) == null ? void 0 : _a3.render) {
|
79970
|
-
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
80027
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(DropZoneProvider, { value: { data: defaultedData, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
79971
80028
|
config.root.render,
|
79972
80029
|
__spreadProps2(__spreadValues2({}, rootProps), {
|
79973
80030
|
puck: {
|
@@ -79980,7 +80037,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
79980
80037
|
})
|
79981
80038
|
) });
|
79982
80039
|
}
|
79983
|
-
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(DropZone, { zone: rootDroppableId2 }) });
|
80040
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(DropZoneProvider, { value: { data: defaultedData, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(DropZone, { zone: rootDroppableId2 }) });
|
79984
80041
|
}
|
79985
80042
|
init_react_import2();
|
79986
80043
|
var migrations = [
|
@@ -80004,6 +80061,11 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
80004
80061
|
return migrations == null ? void 0 : migrations.reduce((acc, migration) => migration(acc), data);
|
80005
80062
|
}
|
80006
80063
|
init_react_import2();
|
80064
|
+
init_react_import2();
|
80065
|
+
var defaultData = (data) => __spreadProps2(__spreadValues2({}, data), {
|
80066
|
+
root: data.root || {},
|
80067
|
+
content: data.content || []
|
80068
|
+
});
|
80007
80069
|
function transformProps(data, propTransforms) {
|
80008
80070
|
const mapItem = (item) => {
|
80009
80071
|
if (propTransforms[item.type]) {
|
@@ -80013,18 +80075,19 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
80013
80075
|
}
|
80014
80076
|
return item;
|
80015
80077
|
};
|
80016
|
-
const
|
80017
|
-
|
80078
|
+
const defaultedData = defaultData(data);
|
80079
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
80080
|
+
let newRoot = __spreadValues2({}, defaultedData.root);
|
80018
80081
|
if (propTransforms["root"]) {
|
80019
|
-
if (
|
80082
|
+
if (defaultedData.root.props) {
|
80020
80083
|
newRoot.props = propTransforms["root"](rootProps);
|
80021
80084
|
} else {
|
80022
80085
|
newRoot = propTransforms["root"](rootProps);
|
80023
80086
|
}
|
80024
80087
|
}
|
80025
|
-
const afterPropTransforms = __spreadProps2(__spreadValues2({},
|
80088
|
+
const afterPropTransforms = __spreadProps2(__spreadValues2({}, defaultedData), {
|
80026
80089
|
root: newRoot,
|
80027
|
-
content:
|
80090
|
+
content: defaultedData.content.map(mapItem),
|
80028
80091
|
zones: Object.keys(data.zones || {}).reduce(
|
80029
80092
|
(acc, zoneKey) => __spreadProps2(__spreadValues2({}, acc), {
|
80030
80093
|
[zoneKey]: data.zones[zoneKey].map(mapItem)
|
@@ -80037,7 +80100,8 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
80037
80100
|
init_react_import2();
|
80038
80101
|
function resolveAllData(data, config, onResolveStart, onResolveEnd) {
|
80039
80102
|
return __async2(this, null, function* () {
|
80040
|
-
const
|
80103
|
+
const defaultedData = defaultData(data);
|
80104
|
+
const dynamicRoot = yield resolveRootData(defaultedData, config);
|
80041
80105
|
const { zones = {} } = data;
|
80042
80106
|
const zoneKeys = Object.keys(zones);
|
80043
80107
|
const resolvedZones = {};
|
@@ -80050,10 +80114,10 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
80050
80114
|
onResolveEnd
|
80051
80115
|
);
|
80052
80116
|
}
|
80053
|
-
return __spreadProps2(__spreadValues2({},
|
80117
|
+
return __spreadProps2(__spreadValues2({}, defaultedData), {
|
80054
80118
|
root: dynamicRoot,
|
80055
80119
|
content: yield resolveAllComponentData(
|
80056
|
-
|
80120
|
+
defaultedData.content,
|
80057
80121
|
config,
|
80058
80122
|
onResolveStart,
|
80059
80123
|
onResolveEnd
|
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",
|