@measured/puck-plugin-heading-analyzer 0.19.0-canary.8d459e4e → 0.19.0-canary.8e1d7223
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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +390 -136
- package/dist/index.mjs +390 -136
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -153,6 +153,120 @@ var require_classnames = __commonJS({
|
|
153
153
|
}
|
154
154
|
});
|
155
155
|
|
156
|
+
// ../../node_modules/flat/index.js
|
157
|
+
var require_flat = __commonJS({
|
158
|
+
"../../node_modules/flat/index.js"(exports2, module2) {
|
159
|
+
"use strict";
|
160
|
+
init_react_import();
|
161
|
+
module2.exports = flatten3;
|
162
|
+
flatten3.flatten = flatten3;
|
163
|
+
flatten3.unflatten = unflatten2;
|
164
|
+
function isBuffer(obj) {
|
165
|
+
return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
166
|
+
}
|
167
|
+
function keyIdentity(key) {
|
168
|
+
return key;
|
169
|
+
}
|
170
|
+
function flatten3(target, opts) {
|
171
|
+
opts = opts || {};
|
172
|
+
const delimiter = opts.delimiter || ".";
|
173
|
+
const maxDepth = opts.maxDepth;
|
174
|
+
const transformKey = opts.transformKey || keyIdentity;
|
175
|
+
const output = {};
|
176
|
+
function step(object, prev, currentDepth) {
|
177
|
+
currentDepth = currentDepth || 1;
|
178
|
+
Object.keys(object).forEach(function(key) {
|
179
|
+
const value = object[key];
|
180
|
+
const isarray = opts.safe && Array.isArray(value);
|
181
|
+
const type = Object.prototype.toString.call(value);
|
182
|
+
const isbuffer = isBuffer(value);
|
183
|
+
const isobject = type === "[object Object]" || type === "[object Array]";
|
184
|
+
const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
|
185
|
+
if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) {
|
186
|
+
return step(value, newKey, currentDepth + 1);
|
187
|
+
}
|
188
|
+
output[newKey] = value;
|
189
|
+
});
|
190
|
+
}
|
191
|
+
step(target);
|
192
|
+
return output;
|
193
|
+
}
|
194
|
+
function unflatten2(target, opts) {
|
195
|
+
opts = opts || {};
|
196
|
+
const delimiter = opts.delimiter || ".";
|
197
|
+
const overwrite = opts.overwrite || false;
|
198
|
+
const transformKey = opts.transformKey || keyIdentity;
|
199
|
+
const result = {};
|
200
|
+
const isbuffer = isBuffer(target);
|
201
|
+
if (isbuffer || Object.prototype.toString.call(target) !== "[object Object]") {
|
202
|
+
return target;
|
203
|
+
}
|
204
|
+
function getkey(key) {
|
205
|
+
const parsedKey = Number(key);
|
206
|
+
return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
|
207
|
+
}
|
208
|
+
function addKeys(keyPrefix, recipient, target2) {
|
209
|
+
return Object.keys(target2).reduce(function(result2, key) {
|
210
|
+
result2[keyPrefix + delimiter + key] = target2[key];
|
211
|
+
return result2;
|
212
|
+
}, recipient);
|
213
|
+
}
|
214
|
+
function isEmpty(val) {
|
215
|
+
const type = Object.prototype.toString.call(val);
|
216
|
+
const isArray = type === "[object Array]";
|
217
|
+
const isObject = type === "[object Object]";
|
218
|
+
if (!val) {
|
219
|
+
return true;
|
220
|
+
} else if (isArray) {
|
221
|
+
return !val.length;
|
222
|
+
} else if (isObject) {
|
223
|
+
return !Object.keys(val).length;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
target = Object.keys(target).reduce(function(result2, key) {
|
227
|
+
const type = Object.prototype.toString.call(target[key]);
|
228
|
+
const isObject = type === "[object Object]" || type === "[object Array]";
|
229
|
+
if (!isObject || isEmpty(target[key])) {
|
230
|
+
result2[key] = target[key];
|
231
|
+
return result2;
|
232
|
+
} else {
|
233
|
+
return addKeys(
|
234
|
+
key,
|
235
|
+
result2,
|
236
|
+
flatten3(target[key], opts)
|
237
|
+
);
|
238
|
+
}
|
239
|
+
}, {});
|
240
|
+
Object.keys(target).forEach(function(key) {
|
241
|
+
const split = key.split(delimiter).map(transformKey);
|
242
|
+
let key1 = getkey(split.shift());
|
243
|
+
let key2 = getkey(split[0]);
|
244
|
+
let recipient = result;
|
245
|
+
while (key2 !== void 0) {
|
246
|
+
if (key1 === "__proto__") {
|
247
|
+
return;
|
248
|
+
}
|
249
|
+
const type = Object.prototype.toString.call(recipient[key1]);
|
250
|
+
const isobject = type === "[object Object]" || type === "[object Array]";
|
251
|
+
if (!overwrite && !isobject && typeof recipient[key1] !== "undefined") {
|
252
|
+
return;
|
253
|
+
}
|
254
|
+
if (overwrite && !isobject || !overwrite && recipient[key1] == null) {
|
255
|
+
recipient[key1] = typeof key2 === "number" && !opts.object ? [] : {};
|
256
|
+
}
|
257
|
+
recipient = recipient[key1];
|
258
|
+
if (split.length > 0) {
|
259
|
+
key1 = getkey(split.shift());
|
260
|
+
key2 = getkey(split[0]);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
recipient[key1] = unflatten2(target[key], opts);
|
264
|
+
});
|
265
|
+
return result;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
});
|
269
|
+
|
156
270
|
// ../../node_modules/fast-deep-equal/index.js
|
157
271
|
var require_fast_deep_equal = __commonJS({
|
158
272
|
"../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
|
@@ -374,43 +488,6 @@ init_react_import();
|
|
374
488
|
// ../core/lib/data/walk-app-state.ts
|
375
489
|
init_react_import();
|
376
490
|
|
377
|
-
// ../core/lib/data/for-each-slot.ts
|
378
|
-
init_react_import();
|
379
|
-
|
380
|
-
// ../core/lib/data/is-slot.ts
|
381
|
-
init_react_import();
|
382
|
-
var isSlot = (prop) => {
|
383
|
-
var _a, _b;
|
384
|
-
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
385
|
-
};
|
386
|
-
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
387
|
-
var _a, _b;
|
388
|
-
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
389
|
-
if (!configForComponent) return isSlot(propValue);
|
390
|
-
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
391
|
-
};
|
392
|
-
|
393
|
-
// ../core/lib/data/for-each-slot.ts
|
394
|
-
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
395
|
-
const props = item.props || {};
|
396
|
-
const propKeys = Object.keys(props);
|
397
|
-
for (let i = 0; i < propKeys.length; i++) {
|
398
|
-
const propKey = propKeys[i];
|
399
|
-
const itemType = "type" in item ? item.type : "root";
|
400
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
401
|
-
const content = props[propKey];
|
402
|
-
cb(props.id, propKey, content);
|
403
|
-
if (recursive) {
|
404
|
-
content.forEach(
|
405
|
-
(childItem) => __async(void 0, null, function* () {
|
406
|
-
return forEachSlot(childItem, cb, true, isSlot2);
|
407
|
-
})
|
408
|
-
);
|
409
|
-
}
|
410
|
-
}
|
411
|
-
}
|
412
|
-
};
|
413
|
-
|
414
491
|
// ../core/lib/data/for-related-zones.ts
|
415
492
|
init_react_import();
|
416
493
|
|
@@ -444,19 +521,154 @@ function forRelatedZones(item, data, cb, path = []) {
|
|
444
521
|
});
|
445
522
|
}
|
446
523
|
|
524
|
+
// ../core/lib/data/map-slots.ts
|
525
|
+
init_react_import();
|
526
|
+
var isPromise = (v) => !!v && typeof v.then === "function";
|
527
|
+
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
528
|
+
var containsPromise = (arr) => arr.some(isPromise);
|
529
|
+
var walkField = ({
|
530
|
+
value,
|
531
|
+
fields,
|
532
|
+
map,
|
533
|
+
propKey = "",
|
534
|
+
propPath = "",
|
535
|
+
id = "",
|
536
|
+
config,
|
537
|
+
recurseSlots = false
|
538
|
+
}) => {
|
539
|
+
var _a, _b, _c;
|
540
|
+
if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
|
541
|
+
const content = value || [];
|
542
|
+
const mappedContent = recurseSlots ? content.map((el) => {
|
543
|
+
var _a2;
|
544
|
+
const componentConfig = config.components[el.type];
|
545
|
+
if (!componentConfig) {
|
546
|
+
throw new Error(`Could not find component config for ${el.type}`);
|
547
|
+
}
|
548
|
+
const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
|
549
|
+
return walkField({
|
550
|
+
value: el,
|
551
|
+
fields: fields2,
|
552
|
+
map,
|
553
|
+
id: el.props.id,
|
554
|
+
config,
|
555
|
+
recurseSlots
|
556
|
+
});
|
557
|
+
}) : content;
|
558
|
+
if (containsPromise(mappedContent)) {
|
559
|
+
return Promise.all(mappedContent);
|
560
|
+
}
|
561
|
+
return map(mappedContent, id, propPath, fields[propKey], propPath);
|
562
|
+
}
|
563
|
+
if (value && typeof value === "object") {
|
564
|
+
if (Array.isArray(value)) {
|
565
|
+
const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
|
566
|
+
if (!arrayFields) return value;
|
567
|
+
const newValue = value.map(
|
568
|
+
(el, idx) => walkField({
|
569
|
+
value: el,
|
570
|
+
fields: arrayFields,
|
571
|
+
map,
|
572
|
+
propKey,
|
573
|
+
propPath: `${propPath}[${idx}]`,
|
574
|
+
id,
|
575
|
+
config,
|
576
|
+
recurseSlots
|
577
|
+
})
|
578
|
+
);
|
579
|
+
if (containsPromise(newValue)) {
|
580
|
+
return Promise.all(newValue);
|
581
|
+
}
|
582
|
+
return newValue;
|
583
|
+
} else if ("$$typeof" in value) {
|
584
|
+
return value;
|
585
|
+
} else {
|
586
|
+
const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
|
587
|
+
return walkObject({
|
588
|
+
value,
|
589
|
+
fields: objectFields,
|
590
|
+
map,
|
591
|
+
id,
|
592
|
+
getPropPath: (k) => `${propPath}.${k}`,
|
593
|
+
config,
|
594
|
+
recurseSlots
|
595
|
+
});
|
596
|
+
}
|
597
|
+
}
|
598
|
+
return value;
|
599
|
+
};
|
600
|
+
var walkObject = ({
|
601
|
+
value,
|
602
|
+
fields,
|
603
|
+
map,
|
604
|
+
id,
|
605
|
+
getPropPath,
|
606
|
+
config,
|
607
|
+
recurseSlots
|
608
|
+
}) => {
|
609
|
+
const newProps = Object.entries(value).map(([k, v]) => {
|
610
|
+
const opts = {
|
611
|
+
value: v,
|
612
|
+
fields,
|
613
|
+
map,
|
614
|
+
propKey: k,
|
615
|
+
propPath: getPropPath(k),
|
616
|
+
id,
|
617
|
+
config,
|
618
|
+
recurseSlots
|
619
|
+
};
|
620
|
+
const newValue = walkField(opts);
|
621
|
+
if (isPromise(newValue)) {
|
622
|
+
return newValue.then((resolvedValue) => ({
|
623
|
+
[k]: resolvedValue
|
624
|
+
}));
|
625
|
+
}
|
626
|
+
return {
|
627
|
+
[k]: newValue
|
628
|
+
};
|
629
|
+
}, {});
|
630
|
+
if (containsPromise(newProps)) {
|
631
|
+
return Promise.all(newProps).then(flatten);
|
632
|
+
}
|
633
|
+
return flatten(newProps);
|
634
|
+
};
|
635
|
+
function mapSlots(item, map, config, recurseSlots = false) {
|
636
|
+
var _a, _b, _c, _d;
|
637
|
+
const itemType = "type" in item ? item.type : "root";
|
638
|
+
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
639
|
+
const newProps = walkObject({
|
640
|
+
value: (_b = item.props) != null ? _b : {},
|
641
|
+
fields: (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {},
|
642
|
+
map,
|
643
|
+
id: item.props ? (_d = item.props.id) != null ? _d : "root" : "root",
|
644
|
+
getPropPath: (k) => k,
|
645
|
+
config,
|
646
|
+
recurseSlots
|
647
|
+
});
|
648
|
+
if (isPromise(newProps)) {
|
649
|
+
return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
|
650
|
+
props: resolvedProps
|
651
|
+
}));
|
652
|
+
}
|
653
|
+
return __spreadProps(__spreadValues({}, item), {
|
654
|
+
props: newProps
|
655
|
+
});
|
656
|
+
}
|
657
|
+
|
658
|
+
// ../core/lib/data/flatten-node.ts
|
659
|
+
init_react_import();
|
660
|
+
var import_flat = __toESM(require_flat());
|
661
|
+
|
447
662
|
// ../core/lib/data/strip-slots.ts
|
448
663
|
init_react_import();
|
449
|
-
var stripSlots = (data) => {
|
450
|
-
return
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
},
|
458
|
-
{ id: data.props.id }
|
459
|
-
)
|
664
|
+
var stripSlots = (data, config) => {
|
665
|
+
return mapSlots(data, () => null, config);
|
666
|
+
};
|
667
|
+
|
668
|
+
// ../core/lib/data/flatten-node.ts
|
669
|
+
var flattenNode = (node, config) => {
|
670
|
+
return __spreadProps(__spreadValues({}, node), {
|
671
|
+
props: (0, import_flat.flatten)(stripSlots(node, config).props)
|
460
672
|
});
|
461
673
|
};
|
462
674
|
|
@@ -502,10 +714,9 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
502
714
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
503
715
|
if (!mappedItem) return item;
|
504
716
|
const id = mappedItem.props.id;
|
505
|
-
const newProps = __spreadValues({},
|
506
|
-
forEachSlot(
|
717
|
+
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
507
718
|
mappedItem,
|
508
|
-
(parentId2, slotId
|
719
|
+
(content, parentId2, slotId) => {
|
509
720
|
const zoneCompound = `${parentId2}:${slotId}`;
|
510
721
|
const [_2, newContent2] = processContent(
|
511
722
|
path,
|
@@ -514,18 +725,19 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
514
725
|
"slot",
|
515
726
|
parentId2
|
516
727
|
);
|
517
|
-
|
728
|
+
return newContent2;
|
518
729
|
},
|
519
|
-
|
520
|
-
|
521
|
-
|
730
|
+
config
|
731
|
+
).props), {
|
732
|
+
id
|
733
|
+
});
|
522
734
|
processRelatedZones(item, id, path);
|
523
735
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
524
736
|
const thisZoneCompound = path[path.length - 1];
|
525
737
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
526
738
|
newNodeIndex[id] = {
|
527
739
|
data: newItem,
|
528
|
-
flatData:
|
740
|
+
flatData: flattenNode(newItem, config),
|
529
741
|
path,
|
530
742
|
parentId,
|
531
743
|
zone
|
@@ -680,15 +892,74 @@ var getIdsForParent = (zoneCompound, state) => {
|
|
680
892
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
681
893
|
};
|
682
894
|
|
895
|
+
// ../core/lib/data/populate-ids.ts
|
896
|
+
init_react_import();
|
897
|
+
|
898
|
+
// ../core/lib/data/walk-tree.ts
|
899
|
+
init_react_import();
|
900
|
+
function walkTree(data, config, callbackFn) {
|
901
|
+
var _a, _b;
|
902
|
+
const walkItem = (item) => {
|
903
|
+
return mapSlots(
|
904
|
+
item,
|
905
|
+
(content, parentId, propName) => {
|
906
|
+
var _a2;
|
907
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
908
|
+
},
|
909
|
+
config,
|
910
|
+
true
|
911
|
+
);
|
912
|
+
};
|
913
|
+
if ("props" in data) {
|
914
|
+
return walkItem(data);
|
915
|
+
}
|
916
|
+
const _data = data;
|
917
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
918
|
+
const mappedContent = _data.content.map(walkItem);
|
919
|
+
return {
|
920
|
+
root: walkItem(_data.root),
|
921
|
+
content: (_b = callbackFn(mappedContent, {
|
922
|
+
parentId: "root",
|
923
|
+
propName: "default-zone"
|
924
|
+
})) != null ? _b : mappedContent,
|
925
|
+
zones: Object.keys(zones).reduce(
|
926
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
927
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
928
|
+
}),
|
929
|
+
{}
|
930
|
+
)
|
931
|
+
};
|
932
|
+
}
|
933
|
+
|
934
|
+
// ../core/lib/data/populate-ids.ts
|
935
|
+
var populateIds = (data, config, override = false) => {
|
936
|
+
const id = generateId(data.type);
|
937
|
+
return walkTree(
|
938
|
+
__spreadProps(__spreadValues({}, data), {
|
939
|
+
props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
|
940
|
+
}),
|
941
|
+
config,
|
942
|
+
(contents) => contents.map((item) => {
|
943
|
+
const id2 = generateId(item.type);
|
944
|
+
return __spreadProps(__spreadValues({}, item), {
|
945
|
+
props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
|
946
|
+
});
|
947
|
+
})
|
948
|
+
);
|
949
|
+
};
|
950
|
+
|
683
951
|
// ../core/reducer/actions/insert.ts
|
684
952
|
function insertAction(state, action, appStore) {
|
685
953
|
const id = action.id || generateId(action.componentType);
|
686
|
-
const emptyComponentData =
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
954
|
+
const emptyComponentData = populateIds(
|
955
|
+
{
|
956
|
+
type: action.componentType,
|
957
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
958
|
+
id
|
959
|
+
})
|
960
|
+
},
|
961
|
+
appStore.config
|
962
|
+
);
|
692
963
|
const [parentId] = action.destinationZone.split(":");
|
693
964
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
694
965
|
return walkAppState(
|
@@ -729,25 +1000,26 @@ var replaceAction = (state, action, appStore) => {
|
|
729
1000
|
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
730
1001
|
);
|
731
1002
|
}
|
1003
|
+
const data = populateIds(action.data, appStore.config);
|
732
1004
|
return walkAppState(
|
733
1005
|
state,
|
734
1006
|
appStore.config,
|
735
1007
|
(content, zoneCompound) => {
|
736
1008
|
const newContent = [...content];
|
737
1009
|
if (zoneCompound === action.destinationZone) {
|
738
|
-
newContent[action.destinationIndex] =
|
1010
|
+
newContent[action.destinationIndex] = data;
|
739
1011
|
}
|
740
1012
|
return newContent;
|
741
1013
|
},
|
742
1014
|
(childItem, path) => {
|
743
1015
|
const pathIds = path.map((p) => p.split(":")[0]);
|
744
|
-
if (childItem.props.id ===
|
745
|
-
return
|
1016
|
+
if (childItem.props.id === data.props.id) {
|
1017
|
+
return data;
|
746
1018
|
} else if (childItem.props.id === parentId) {
|
747
1019
|
return childItem;
|
748
1020
|
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
749
1021
|
return childItem;
|
750
|
-
} else if (pathIds.indexOf(
|
1022
|
+
} else if (pathIds.indexOf(data.props.id) > -1) {
|
751
1023
|
return childItem;
|
752
1024
|
}
|
753
1025
|
return null;
|
@@ -1321,7 +1593,11 @@ var createNodesSlice = (set, get) => ({
|
|
1321
1593
|
const s = get().nodes;
|
1322
1594
|
const emptyNode = {
|
1323
1595
|
id,
|
1324
|
-
methods: {
|
1596
|
+
methods: {
|
1597
|
+
sync: () => null,
|
1598
|
+
hideOverlay: () => null,
|
1599
|
+
showOverlay: () => null
|
1600
|
+
},
|
1325
1601
|
element: null
|
1326
1602
|
};
|
1327
1603
|
const existingNode = s.nodes[id];
|
@@ -1372,12 +1648,13 @@ var flattenData = (state, config) => {
|
|
1372
1648
|
|
1373
1649
|
// ../core/lib/get-changed.ts
|
1374
1650
|
init_react_import();
|
1651
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1375
1652
|
var getChanged = (newItem, oldItem) => {
|
1376
1653
|
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1377
1654
|
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1378
1655
|
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1379
1656
|
return __spreadProps(__spreadValues({}, acc), {
|
1380
|
-
[item]: oldItemProps[item]
|
1657
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
1381
1658
|
});
|
1382
1659
|
}, {}) : {};
|
1383
1660
|
};
|
@@ -1495,45 +1772,23 @@ var createFieldsSlice = (_set, _get) => {
|
|
1495
1772
|
return {
|
1496
1773
|
fields: {},
|
1497
1774
|
loading: false,
|
1498
|
-
lastResolvedData: {}
|
1775
|
+
lastResolvedData: {},
|
1776
|
+
id: void 0
|
1499
1777
|
};
|
1500
1778
|
};
|
1501
1779
|
|
1502
1780
|
// ../core/lib/resolve-component-data.ts
|
1503
1781
|
init_react_import();
|
1504
|
-
|
1505
|
-
// ../core/lib/data/map-slots.ts
|
1506
|
-
init_react_import();
|
1507
|
-
function mapSlotsAsync(_0, _1) {
|
1508
|
-
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1509
|
-
const props = __spreadValues({}, item.props);
|
1510
|
-
const propKeys = Object.keys(props);
|
1511
|
-
for (let i = 0; i < propKeys.length; i++) {
|
1512
|
-
const propKey = propKeys[i];
|
1513
|
-
const itemType = "type" in item ? item.type : "root";
|
1514
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
1515
|
-
const content = props[propKey];
|
1516
|
-
const mappedContent = recursive ? yield Promise.all(
|
1517
|
-
content.map((item2) => __async(this, null, function* () {
|
1518
|
-
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
1519
|
-
}))
|
1520
|
-
) : content;
|
1521
|
-
props[propKey] = yield map(mappedContent, propKey);
|
1522
|
-
}
|
1523
|
-
}
|
1524
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
1525
|
-
});
|
1526
|
-
}
|
1527
|
-
|
1528
|
-
// ../core/lib/resolve-component-data.ts
|
1529
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1782
|
+
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1530
1783
|
var cache = { lastChange: {} };
|
1531
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace"
|
1784
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
1532
1785
|
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1533
|
-
|
1534
|
-
|
1786
|
+
const resolvedItem = __spreadValues({}, item);
|
1787
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
1788
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1789
|
+
if (shouldRunResolver) {
|
1535
1790
|
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1536
|
-
if (item && (0,
|
1791
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
1537
1792
|
return { node: resolved, didChange: false };
|
1538
1793
|
}
|
1539
1794
|
const changed = getChanged(item, oldItem);
|
@@ -1546,46 +1801,42 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1546
1801
|
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1547
1802
|
trigger
|
1548
1803
|
});
|
1549
|
-
|
1550
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1551
|
-
});
|
1552
|
-
if (recursive) {
|
1553
|
-
resolvedItem = yield mapSlotsAsync(
|
1554
|
-
resolvedItem,
|
1555
|
-
(content) => __async(void 0, null, function* () {
|
1556
|
-
return Promise.all(
|
1557
|
-
content.map(
|
1558
|
-
(childItem) => __async(void 0, null, function* () {
|
1559
|
-
return (yield resolveComponentData(
|
1560
|
-
childItem,
|
1561
|
-
config,
|
1562
|
-
metadata,
|
1563
|
-
onResolveStart,
|
1564
|
-
onResolveEnd,
|
1565
|
-
trigger,
|
1566
|
-
false
|
1567
|
-
)).node;
|
1568
|
-
})
|
1569
|
-
)
|
1570
|
-
);
|
1571
|
-
}),
|
1572
|
-
false,
|
1573
|
-
createIsSlotConfig(config)
|
1574
|
-
);
|
1575
|
-
}
|
1804
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
1576
1805
|
if (Object.keys(readOnly).length) {
|
1577
1806
|
resolvedItem.readOnly = readOnly;
|
1578
1807
|
}
|
1579
|
-
cache.lastChange[id] = {
|
1580
|
-
item,
|
1581
|
-
resolved: resolvedItem
|
1582
|
-
};
|
1583
|
-
if (onResolveEnd) {
|
1584
|
-
onResolveEnd(resolvedItem);
|
1585
|
-
}
|
1586
|
-
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1587
1808
|
}
|
1588
|
-
|
1809
|
+
let itemWithResolvedChildren = yield mapSlots(
|
1810
|
+
resolvedItem,
|
1811
|
+
(content) => __async(void 0, null, function* () {
|
1812
|
+
return yield Promise.all(
|
1813
|
+
content.map(
|
1814
|
+
(childItem) => __async(void 0, null, function* () {
|
1815
|
+
return (yield resolveComponentData(
|
1816
|
+
childItem,
|
1817
|
+
config,
|
1818
|
+
metadata,
|
1819
|
+
onResolveStart,
|
1820
|
+
onResolveEnd,
|
1821
|
+
trigger
|
1822
|
+
)).node;
|
1823
|
+
})
|
1824
|
+
)
|
1825
|
+
);
|
1826
|
+
}),
|
1827
|
+
config
|
1828
|
+
);
|
1829
|
+
if (shouldRunResolver && onResolveEnd) {
|
1830
|
+
onResolveEnd(resolvedItem);
|
1831
|
+
}
|
1832
|
+
cache.lastChange[id] = {
|
1833
|
+
item,
|
1834
|
+
resolved: itemWithResolvedChildren
|
1835
|
+
};
|
1836
|
+
return {
|
1837
|
+
node: itemWithResolvedChildren,
|
1838
|
+
didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
|
1839
|
+
};
|
1589
1840
|
});
|
1590
1841
|
|
1591
1842
|
// ../core/lib/data/to-root.ts
|
@@ -1605,7 +1856,8 @@ var toRoot = (item) => {
|
|
1605
1856
|
return { props: {}, readOnly };
|
1606
1857
|
};
|
1607
1858
|
|
1608
|
-
// ../core/store/
|
1859
|
+
// ../core/store/default-app-state.ts
|
1860
|
+
init_react_import();
|
1609
1861
|
var defaultAppState = {
|
1610
1862
|
data: { content: [], root: {}, zones: {} },
|
1611
1863
|
ui: {
|
@@ -1631,6 +1883,8 @@ var defaultAppState = {
|
|
1631
1883
|
zones: {}
|
1632
1884
|
}
|
1633
1885
|
};
|
1886
|
+
|
1887
|
+
// ../core/store/index.ts
|
1634
1888
|
var defaultPageFields = {
|
1635
1889
|
title: { type: "text" }
|
1636
1890
|
};
|
package/dist/index.mjs
CHANGED
@@ -146,6 +146,120 @@ var require_classnames = __commonJS({
|
|
146
146
|
}
|
147
147
|
});
|
148
148
|
|
149
|
+
// ../../node_modules/flat/index.js
|
150
|
+
var require_flat = __commonJS({
|
151
|
+
"../../node_modules/flat/index.js"(exports, module) {
|
152
|
+
"use strict";
|
153
|
+
init_react_import();
|
154
|
+
module.exports = flatten3;
|
155
|
+
flatten3.flatten = flatten3;
|
156
|
+
flatten3.unflatten = unflatten2;
|
157
|
+
function isBuffer(obj) {
|
158
|
+
return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
159
|
+
}
|
160
|
+
function keyIdentity(key) {
|
161
|
+
return key;
|
162
|
+
}
|
163
|
+
function flatten3(target, opts) {
|
164
|
+
opts = opts || {};
|
165
|
+
const delimiter = opts.delimiter || ".";
|
166
|
+
const maxDepth = opts.maxDepth;
|
167
|
+
const transformKey = opts.transformKey || keyIdentity;
|
168
|
+
const output = {};
|
169
|
+
function step(object, prev, currentDepth) {
|
170
|
+
currentDepth = currentDepth || 1;
|
171
|
+
Object.keys(object).forEach(function(key) {
|
172
|
+
const value = object[key];
|
173
|
+
const isarray = opts.safe && Array.isArray(value);
|
174
|
+
const type = Object.prototype.toString.call(value);
|
175
|
+
const isbuffer = isBuffer(value);
|
176
|
+
const isobject = type === "[object Object]" || type === "[object Array]";
|
177
|
+
const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
|
178
|
+
if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) {
|
179
|
+
return step(value, newKey, currentDepth + 1);
|
180
|
+
}
|
181
|
+
output[newKey] = value;
|
182
|
+
});
|
183
|
+
}
|
184
|
+
step(target);
|
185
|
+
return output;
|
186
|
+
}
|
187
|
+
function unflatten2(target, opts) {
|
188
|
+
opts = opts || {};
|
189
|
+
const delimiter = opts.delimiter || ".";
|
190
|
+
const overwrite = opts.overwrite || false;
|
191
|
+
const transformKey = opts.transformKey || keyIdentity;
|
192
|
+
const result = {};
|
193
|
+
const isbuffer = isBuffer(target);
|
194
|
+
if (isbuffer || Object.prototype.toString.call(target) !== "[object Object]") {
|
195
|
+
return target;
|
196
|
+
}
|
197
|
+
function getkey(key) {
|
198
|
+
const parsedKey = Number(key);
|
199
|
+
return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
|
200
|
+
}
|
201
|
+
function addKeys(keyPrefix, recipient, target2) {
|
202
|
+
return Object.keys(target2).reduce(function(result2, key) {
|
203
|
+
result2[keyPrefix + delimiter + key] = target2[key];
|
204
|
+
return result2;
|
205
|
+
}, recipient);
|
206
|
+
}
|
207
|
+
function isEmpty(val) {
|
208
|
+
const type = Object.prototype.toString.call(val);
|
209
|
+
const isArray = type === "[object Array]";
|
210
|
+
const isObject = type === "[object Object]";
|
211
|
+
if (!val) {
|
212
|
+
return true;
|
213
|
+
} else if (isArray) {
|
214
|
+
return !val.length;
|
215
|
+
} else if (isObject) {
|
216
|
+
return !Object.keys(val).length;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
target = Object.keys(target).reduce(function(result2, key) {
|
220
|
+
const type = Object.prototype.toString.call(target[key]);
|
221
|
+
const isObject = type === "[object Object]" || type === "[object Array]";
|
222
|
+
if (!isObject || isEmpty(target[key])) {
|
223
|
+
result2[key] = target[key];
|
224
|
+
return result2;
|
225
|
+
} else {
|
226
|
+
return addKeys(
|
227
|
+
key,
|
228
|
+
result2,
|
229
|
+
flatten3(target[key], opts)
|
230
|
+
);
|
231
|
+
}
|
232
|
+
}, {});
|
233
|
+
Object.keys(target).forEach(function(key) {
|
234
|
+
const split = key.split(delimiter).map(transformKey);
|
235
|
+
let key1 = getkey(split.shift());
|
236
|
+
let key2 = getkey(split[0]);
|
237
|
+
let recipient = result;
|
238
|
+
while (key2 !== void 0) {
|
239
|
+
if (key1 === "__proto__") {
|
240
|
+
return;
|
241
|
+
}
|
242
|
+
const type = Object.prototype.toString.call(recipient[key1]);
|
243
|
+
const isobject = type === "[object Object]" || type === "[object Array]";
|
244
|
+
if (!overwrite && !isobject && typeof recipient[key1] !== "undefined") {
|
245
|
+
return;
|
246
|
+
}
|
247
|
+
if (overwrite && !isobject || !overwrite && recipient[key1] == null) {
|
248
|
+
recipient[key1] = typeof key2 === "number" && !opts.object ? [] : {};
|
249
|
+
}
|
250
|
+
recipient = recipient[key1];
|
251
|
+
if (split.length > 0) {
|
252
|
+
key1 = getkey(split.shift());
|
253
|
+
key2 = getkey(split[0]);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
recipient[key1] = unflatten2(target[key], opts);
|
257
|
+
});
|
258
|
+
return result;
|
259
|
+
}
|
260
|
+
}
|
261
|
+
});
|
262
|
+
|
149
263
|
// ../../node_modules/fast-deep-equal/index.js
|
150
264
|
var require_fast_deep_equal = __commonJS({
|
151
265
|
"../../node_modules/fast-deep-equal/index.js"(exports, module) {
|
@@ -362,43 +476,6 @@ init_react_import();
|
|
362
476
|
// ../core/lib/data/walk-app-state.ts
|
363
477
|
init_react_import();
|
364
478
|
|
365
|
-
// ../core/lib/data/for-each-slot.ts
|
366
|
-
init_react_import();
|
367
|
-
|
368
|
-
// ../core/lib/data/is-slot.ts
|
369
|
-
init_react_import();
|
370
|
-
var isSlot = (prop) => {
|
371
|
-
var _a, _b;
|
372
|
-
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
373
|
-
};
|
374
|
-
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
375
|
-
var _a, _b;
|
376
|
-
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
377
|
-
if (!configForComponent) return isSlot(propValue);
|
378
|
-
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
379
|
-
};
|
380
|
-
|
381
|
-
// ../core/lib/data/for-each-slot.ts
|
382
|
-
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
383
|
-
const props = item.props || {};
|
384
|
-
const propKeys = Object.keys(props);
|
385
|
-
for (let i = 0; i < propKeys.length; i++) {
|
386
|
-
const propKey = propKeys[i];
|
387
|
-
const itemType = "type" in item ? item.type : "root";
|
388
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
389
|
-
const content = props[propKey];
|
390
|
-
cb(props.id, propKey, content);
|
391
|
-
if (recursive) {
|
392
|
-
content.forEach(
|
393
|
-
(childItem) => __async(void 0, null, function* () {
|
394
|
-
return forEachSlot(childItem, cb, true, isSlot2);
|
395
|
-
})
|
396
|
-
);
|
397
|
-
}
|
398
|
-
}
|
399
|
-
}
|
400
|
-
};
|
401
|
-
|
402
479
|
// ../core/lib/data/for-related-zones.ts
|
403
480
|
init_react_import();
|
404
481
|
|
@@ -432,19 +509,154 @@ function forRelatedZones(item, data, cb, path = []) {
|
|
432
509
|
});
|
433
510
|
}
|
434
511
|
|
512
|
+
// ../core/lib/data/map-slots.ts
|
513
|
+
init_react_import();
|
514
|
+
var isPromise = (v) => !!v && typeof v.then === "function";
|
515
|
+
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
516
|
+
var containsPromise = (arr) => arr.some(isPromise);
|
517
|
+
var walkField = ({
|
518
|
+
value,
|
519
|
+
fields,
|
520
|
+
map,
|
521
|
+
propKey = "",
|
522
|
+
propPath = "",
|
523
|
+
id = "",
|
524
|
+
config,
|
525
|
+
recurseSlots = false
|
526
|
+
}) => {
|
527
|
+
var _a, _b, _c;
|
528
|
+
if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
|
529
|
+
const content = value || [];
|
530
|
+
const mappedContent = recurseSlots ? content.map((el) => {
|
531
|
+
var _a2;
|
532
|
+
const componentConfig = config.components[el.type];
|
533
|
+
if (!componentConfig) {
|
534
|
+
throw new Error(`Could not find component config for ${el.type}`);
|
535
|
+
}
|
536
|
+
const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
|
537
|
+
return walkField({
|
538
|
+
value: el,
|
539
|
+
fields: fields2,
|
540
|
+
map,
|
541
|
+
id: el.props.id,
|
542
|
+
config,
|
543
|
+
recurseSlots
|
544
|
+
});
|
545
|
+
}) : content;
|
546
|
+
if (containsPromise(mappedContent)) {
|
547
|
+
return Promise.all(mappedContent);
|
548
|
+
}
|
549
|
+
return map(mappedContent, id, propPath, fields[propKey], propPath);
|
550
|
+
}
|
551
|
+
if (value && typeof value === "object") {
|
552
|
+
if (Array.isArray(value)) {
|
553
|
+
const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
|
554
|
+
if (!arrayFields) return value;
|
555
|
+
const newValue = value.map(
|
556
|
+
(el, idx) => walkField({
|
557
|
+
value: el,
|
558
|
+
fields: arrayFields,
|
559
|
+
map,
|
560
|
+
propKey,
|
561
|
+
propPath: `${propPath}[${idx}]`,
|
562
|
+
id,
|
563
|
+
config,
|
564
|
+
recurseSlots
|
565
|
+
})
|
566
|
+
);
|
567
|
+
if (containsPromise(newValue)) {
|
568
|
+
return Promise.all(newValue);
|
569
|
+
}
|
570
|
+
return newValue;
|
571
|
+
} else if ("$$typeof" in value) {
|
572
|
+
return value;
|
573
|
+
} else {
|
574
|
+
const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
|
575
|
+
return walkObject({
|
576
|
+
value,
|
577
|
+
fields: objectFields,
|
578
|
+
map,
|
579
|
+
id,
|
580
|
+
getPropPath: (k) => `${propPath}.${k}`,
|
581
|
+
config,
|
582
|
+
recurseSlots
|
583
|
+
});
|
584
|
+
}
|
585
|
+
}
|
586
|
+
return value;
|
587
|
+
};
|
588
|
+
var walkObject = ({
|
589
|
+
value,
|
590
|
+
fields,
|
591
|
+
map,
|
592
|
+
id,
|
593
|
+
getPropPath,
|
594
|
+
config,
|
595
|
+
recurseSlots
|
596
|
+
}) => {
|
597
|
+
const newProps = Object.entries(value).map(([k, v]) => {
|
598
|
+
const opts = {
|
599
|
+
value: v,
|
600
|
+
fields,
|
601
|
+
map,
|
602
|
+
propKey: k,
|
603
|
+
propPath: getPropPath(k),
|
604
|
+
id,
|
605
|
+
config,
|
606
|
+
recurseSlots
|
607
|
+
};
|
608
|
+
const newValue = walkField(opts);
|
609
|
+
if (isPromise(newValue)) {
|
610
|
+
return newValue.then((resolvedValue) => ({
|
611
|
+
[k]: resolvedValue
|
612
|
+
}));
|
613
|
+
}
|
614
|
+
return {
|
615
|
+
[k]: newValue
|
616
|
+
};
|
617
|
+
}, {});
|
618
|
+
if (containsPromise(newProps)) {
|
619
|
+
return Promise.all(newProps).then(flatten);
|
620
|
+
}
|
621
|
+
return flatten(newProps);
|
622
|
+
};
|
623
|
+
function mapSlots(item, map, config, recurseSlots = false) {
|
624
|
+
var _a, _b, _c, _d;
|
625
|
+
const itemType = "type" in item ? item.type : "root";
|
626
|
+
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
627
|
+
const newProps = walkObject({
|
628
|
+
value: (_b = item.props) != null ? _b : {},
|
629
|
+
fields: (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {},
|
630
|
+
map,
|
631
|
+
id: item.props ? (_d = item.props.id) != null ? _d : "root" : "root",
|
632
|
+
getPropPath: (k) => k,
|
633
|
+
config,
|
634
|
+
recurseSlots
|
635
|
+
});
|
636
|
+
if (isPromise(newProps)) {
|
637
|
+
return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
|
638
|
+
props: resolvedProps
|
639
|
+
}));
|
640
|
+
}
|
641
|
+
return __spreadProps(__spreadValues({}, item), {
|
642
|
+
props: newProps
|
643
|
+
});
|
644
|
+
}
|
645
|
+
|
646
|
+
// ../core/lib/data/flatten-node.ts
|
647
|
+
init_react_import();
|
648
|
+
var import_flat = __toESM(require_flat());
|
649
|
+
|
435
650
|
// ../core/lib/data/strip-slots.ts
|
436
651
|
init_react_import();
|
437
|
-
var stripSlots = (data) => {
|
438
|
-
return
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
},
|
446
|
-
{ id: data.props.id }
|
447
|
-
)
|
652
|
+
var stripSlots = (data, config) => {
|
653
|
+
return mapSlots(data, () => null, config);
|
654
|
+
};
|
655
|
+
|
656
|
+
// ../core/lib/data/flatten-node.ts
|
657
|
+
var flattenNode = (node, config) => {
|
658
|
+
return __spreadProps(__spreadValues({}, node), {
|
659
|
+
props: (0, import_flat.flatten)(stripSlots(node, config).props)
|
448
660
|
});
|
449
661
|
};
|
450
662
|
|
@@ -490,10 +702,9 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
490
702
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
491
703
|
if (!mappedItem) return item;
|
492
704
|
const id = mappedItem.props.id;
|
493
|
-
const newProps = __spreadValues({},
|
494
|
-
forEachSlot(
|
705
|
+
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
495
706
|
mappedItem,
|
496
|
-
(parentId2, slotId
|
707
|
+
(content, parentId2, slotId) => {
|
497
708
|
const zoneCompound = `${parentId2}:${slotId}`;
|
498
709
|
const [_2, newContent2] = processContent(
|
499
710
|
path,
|
@@ -502,18 +713,19 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
502
713
|
"slot",
|
503
714
|
parentId2
|
504
715
|
);
|
505
|
-
|
716
|
+
return newContent2;
|
506
717
|
},
|
507
|
-
|
508
|
-
|
509
|
-
|
718
|
+
config
|
719
|
+
).props), {
|
720
|
+
id
|
721
|
+
});
|
510
722
|
processRelatedZones(item, id, path);
|
511
723
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
512
724
|
const thisZoneCompound = path[path.length - 1];
|
513
725
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
514
726
|
newNodeIndex[id] = {
|
515
727
|
data: newItem,
|
516
|
-
flatData:
|
728
|
+
flatData: flattenNode(newItem, config),
|
517
729
|
path,
|
518
730
|
parentId,
|
519
731
|
zone
|
@@ -668,15 +880,74 @@ var getIdsForParent = (zoneCompound, state) => {
|
|
668
880
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
669
881
|
};
|
670
882
|
|
883
|
+
// ../core/lib/data/populate-ids.ts
|
884
|
+
init_react_import();
|
885
|
+
|
886
|
+
// ../core/lib/data/walk-tree.ts
|
887
|
+
init_react_import();
|
888
|
+
function walkTree(data, config, callbackFn) {
|
889
|
+
var _a, _b;
|
890
|
+
const walkItem = (item) => {
|
891
|
+
return mapSlots(
|
892
|
+
item,
|
893
|
+
(content, parentId, propName) => {
|
894
|
+
var _a2;
|
895
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
896
|
+
},
|
897
|
+
config,
|
898
|
+
true
|
899
|
+
);
|
900
|
+
};
|
901
|
+
if ("props" in data) {
|
902
|
+
return walkItem(data);
|
903
|
+
}
|
904
|
+
const _data = data;
|
905
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
906
|
+
const mappedContent = _data.content.map(walkItem);
|
907
|
+
return {
|
908
|
+
root: walkItem(_data.root),
|
909
|
+
content: (_b = callbackFn(mappedContent, {
|
910
|
+
parentId: "root",
|
911
|
+
propName: "default-zone"
|
912
|
+
})) != null ? _b : mappedContent,
|
913
|
+
zones: Object.keys(zones).reduce(
|
914
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
915
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
916
|
+
}),
|
917
|
+
{}
|
918
|
+
)
|
919
|
+
};
|
920
|
+
}
|
921
|
+
|
922
|
+
// ../core/lib/data/populate-ids.ts
|
923
|
+
var populateIds = (data, config, override = false) => {
|
924
|
+
const id = generateId(data.type);
|
925
|
+
return walkTree(
|
926
|
+
__spreadProps(__spreadValues({}, data), {
|
927
|
+
props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
|
928
|
+
}),
|
929
|
+
config,
|
930
|
+
(contents) => contents.map((item) => {
|
931
|
+
const id2 = generateId(item.type);
|
932
|
+
return __spreadProps(__spreadValues({}, item), {
|
933
|
+
props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
|
934
|
+
});
|
935
|
+
})
|
936
|
+
);
|
937
|
+
};
|
938
|
+
|
671
939
|
// ../core/reducer/actions/insert.ts
|
672
940
|
function insertAction(state, action, appStore) {
|
673
941
|
const id = action.id || generateId(action.componentType);
|
674
|
-
const emptyComponentData =
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
942
|
+
const emptyComponentData = populateIds(
|
943
|
+
{
|
944
|
+
type: action.componentType,
|
945
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
946
|
+
id
|
947
|
+
})
|
948
|
+
},
|
949
|
+
appStore.config
|
950
|
+
);
|
680
951
|
const [parentId] = action.destinationZone.split(":");
|
681
952
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
682
953
|
return walkAppState(
|
@@ -717,25 +988,26 @@ var replaceAction = (state, action, appStore) => {
|
|
717
988
|
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
718
989
|
);
|
719
990
|
}
|
991
|
+
const data = populateIds(action.data, appStore.config);
|
720
992
|
return walkAppState(
|
721
993
|
state,
|
722
994
|
appStore.config,
|
723
995
|
(content, zoneCompound) => {
|
724
996
|
const newContent = [...content];
|
725
997
|
if (zoneCompound === action.destinationZone) {
|
726
|
-
newContent[action.destinationIndex] =
|
998
|
+
newContent[action.destinationIndex] = data;
|
727
999
|
}
|
728
1000
|
return newContent;
|
729
1001
|
},
|
730
1002
|
(childItem, path) => {
|
731
1003
|
const pathIds = path.map((p) => p.split(":")[0]);
|
732
|
-
if (childItem.props.id ===
|
733
|
-
return
|
1004
|
+
if (childItem.props.id === data.props.id) {
|
1005
|
+
return data;
|
734
1006
|
} else if (childItem.props.id === parentId) {
|
735
1007
|
return childItem;
|
736
1008
|
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
737
1009
|
return childItem;
|
738
|
-
} else if (pathIds.indexOf(
|
1010
|
+
} else if (pathIds.indexOf(data.props.id) > -1) {
|
739
1011
|
return childItem;
|
740
1012
|
}
|
741
1013
|
return null;
|
@@ -1309,7 +1581,11 @@ var createNodesSlice = (set, get) => ({
|
|
1309
1581
|
const s = get().nodes;
|
1310
1582
|
const emptyNode = {
|
1311
1583
|
id,
|
1312
|
-
methods: {
|
1584
|
+
methods: {
|
1585
|
+
sync: () => null,
|
1586
|
+
hideOverlay: () => null,
|
1587
|
+
showOverlay: () => null
|
1588
|
+
},
|
1313
1589
|
element: null
|
1314
1590
|
};
|
1315
1591
|
const existingNode = s.nodes[id];
|
@@ -1360,12 +1636,13 @@ var flattenData = (state, config) => {
|
|
1360
1636
|
|
1361
1637
|
// ../core/lib/get-changed.ts
|
1362
1638
|
init_react_import();
|
1639
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1363
1640
|
var getChanged = (newItem, oldItem) => {
|
1364
1641
|
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1365
1642
|
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1366
1643
|
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1367
1644
|
return __spreadProps(__spreadValues({}, acc), {
|
1368
|
-
[item]: oldItemProps[item]
|
1645
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
1369
1646
|
});
|
1370
1647
|
}, {}) : {};
|
1371
1648
|
};
|
@@ -1483,45 +1760,23 @@ var createFieldsSlice = (_set, _get) => {
|
|
1483
1760
|
return {
|
1484
1761
|
fields: {},
|
1485
1762
|
loading: false,
|
1486
|
-
lastResolvedData: {}
|
1763
|
+
lastResolvedData: {},
|
1764
|
+
id: void 0
|
1487
1765
|
};
|
1488
1766
|
};
|
1489
1767
|
|
1490
1768
|
// ../core/lib/resolve-component-data.ts
|
1491
1769
|
init_react_import();
|
1492
|
-
|
1493
|
-
// ../core/lib/data/map-slots.ts
|
1494
|
-
init_react_import();
|
1495
|
-
function mapSlotsAsync(_0, _1) {
|
1496
|
-
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1497
|
-
const props = __spreadValues({}, item.props);
|
1498
|
-
const propKeys = Object.keys(props);
|
1499
|
-
for (let i = 0; i < propKeys.length; i++) {
|
1500
|
-
const propKey = propKeys[i];
|
1501
|
-
const itemType = "type" in item ? item.type : "root";
|
1502
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
1503
|
-
const content = props[propKey];
|
1504
|
-
const mappedContent = recursive ? yield Promise.all(
|
1505
|
-
content.map((item2) => __async(this, null, function* () {
|
1506
|
-
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
1507
|
-
}))
|
1508
|
-
) : content;
|
1509
|
-
props[propKey] = yield map(mappedContent, propKey);
|
1510
|
-
}
|
1511
|
-
}
|
1512
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
1513
|
-
});
|
1514
|
-
}
|
1515
|
-
|
1516
|
-
// ../core/lib/resolve-component-data.ts
|
1517
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1770
|
+
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1518
1771
|
var cache = { lastChange: {} };
|
1519
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace"
|
1772
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
1520
1773
|
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1521
|
-
|
1522
|
-
|
1774
|
+
const resolvedItem = __spreadValues({}, item);
|
1775
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
1776
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1777
|
+
if (shouldRunResolver) {
|
1523
1778
|
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1524
|
-
if (item && (0,
|
1779
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
1525
1780
|
return { node: resolved, didChange: false };
|
1526
1781
|
}
|
1527
1782
|
const changed = getChanged(item, oldItem);
|
@@ -1534,46 +1789,42 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1534
1789
|
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1535
1790
|
trigger
|
1536
1791
|
});
|
1537
|
-
|
1538
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1539
|
-
});
|
1540
|
-
if (recursive) {
|
1541
|
-
resolvedItem = yield mapSlotsAsync(
|
1542
|
-
resolvedItem,
|
1543
|
-
(content) => __async(void 0, null, function* () {
|
1544
|
-
return Promise.all(
|
1545
|
-
content.map(
|
1546
|
-
(childItem) => __async(void 0, null, function* () {
|
1547
|
-
return (yield resolveComponentData(
|
1548
|
-
childItem,
|
1549
|
-
config,
|
1550
|
-
metadata,
|
1551
|
-
onResolveStart,
|
1552
|
-
onResolveEnd,
|
1553
|
-
trigger,
|
1554
|
-
false
|
1555
|
-
)).node;
|
1556
|
-
})
|
1557
|
-
)
|
1558
|
-
);
|
1559
|
-
}),
|
1560
|
-
false,
|
1561
|
-
createIsSlotConfig(config)
|
1562
|
-
);
|
1563
|
-
}
|
1792
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
1564
1793
|
if (Object.keys(readOnly).length) {
|
1565
1794
|
resolvedItem.readOnly = readOnly;
|
1566
1795
|
}
|
1567
|
-
cache.lastChange[id] = {
|
1568
|
-
item,
|
1569
|
-
resolved: resolvedItem
|
1570
|
-
};
|
1571
|
-
if (onResolveEnd) {
|
1572
|
-
onResolveEnd(resolvedItem);
|
1573
|
-
}
|
1574
|
-
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1575
1796
|
}
|
1576
|
-
|
1797
|
+
let itemWithResolvedChildren = yield mapSlots(
|
1798
|
+
resolvedItem,
|
1799
|
+
(content) => __async(void 0, null, function* () {
|
1800
|
+
return yield Promise.all(
|
1801
|
+
content.map(
|
1802
|
+
(childItem) => __async(void 0, null, function* () {
|
1803
|
+
return (yield resolveComponentData(
|
1804
|
+
childItem,
|
1805
|
+
config,
|
1806
|
+
metadata,
|
1807
|
+
onResolveStart,
|
1808
|
+
onResolveEnd,
|
1809
|
+
trigger
|
1810
|
+
)).node;
|
1811
|
+
})
|
1812
|
+
)
|
1813
|
+
);
|
1814
|
+
}),
|
1815
|
+
config
|
1816
|
+
);
|
1817
|
+
if (shouldRunResolver && onResolveEnd) {
|
1818
|
+
onResolveEnd(resolvedItem);
|
1819
|
+
}
|
1820
|
+
cache.lastChange[id] = {
|
1821
|
+
item,
|
1822
|
+
resolved: itemWithResolvedChildren
|
1823
|
+
};
|
1824
|
+
return {
|
1825
|
+
node: itemWithResolvedChildren,
|
1826
|
+
didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
|
1827
|
+
};
|
1577
1828
|
});
|
1578
1829
|
|
1579
1830
|
// ../core/lib/data/to-root.ts
|
@@ -1593,7 +1844,8 @@ var toRoot = (item) => {
|
|
1593
1844
|
return { props: {}, readOnly };
|
1594
1845
|
};
|
1595
1846
|
|
1596
|
-
// ../core/store/
|
1847
|
+
// ../core/store/default-app-state.ts
|
1848
|
+
init_react_import();
|
1597
1849
|
var defaultAppState = {
|
1598
1850
|
data: { content: [], root: {}, zones: {} },
|
1599
1851
|
ui: {
|
@@ -1619,6 +1871,8 @@ var defaultAppState = {
|
|
1619
1871
|
zones: {}
|
1620
1872
|
}
|
1621
1873
|
};
|
1874
|
+
|
1875
|
+
// ../core/store/index.ts
|
1622
1876
|
var defaultPageFields = {
|
1623
1877
|
title: { type: "text" }
|
1624
1878
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@measured/puck-plugin-heading-analyzer",
|
3
|
-
"version": "0.19.0-canary.
|
3
|
+
"version": "0.19.0-canary.8e1d7223",
|
4
4
|
"author": "Chris Villa <chris@puckeditor.com>",
|
5
5
|
"repository": "measuredco/puck",
|
6
6
|
"bugs": "https://github.com/measuredco/puck/issues",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"dist"
|
26
26
|
],
|
27
27
|
"devDependencies": {
|
28
|
-
"@measured/puck": "^0.19.0-canary.
|
28
|
+
"@measured/puck": "^0.19.0-canary.8e1d7223",
|
29
29
|
"@types/react": "^19.0.1",
|
30
30
|
"@types/react-dom": "^19.0.2",
|
31
31
|
"eslint": "^7.32.0",
|