@measured/puck-plugin-heading-analyzer 0.19.0-canary.896a6279 → 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/README.md +1 -1
- package/dist/index.d.mts +18 -9
- package/dist/index.d.ts +18 -9
- package/dist/index.js +410 -164
- package/dist/index.mjs +410 -164
- package/package.json +3 -3
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) {
|
@@ -359,45 +473,8 @@ init_react_import();
|
|
359
473
|
// ../core/reducer/actions/set.ts
|
360
474
|
init_react_import();
|
361
475
|
|
362
|
-
// ../core/lib/data/walk-
|
363
|
-
init_react_import();
|
364
|
-
|
365
|
-
// ../core/lib/data/for-each-slot.ts
|
366
|
-
init_react_import();
|
367
|
-
|
368
|
-
// ../core/lib/data/is-slot.ts
|
476
|
+
// ../core/lib/data/walk-app-state.ts
|
369
477
|
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
478
|
|
402
479
|
// ../core/lib/data/for-related-zones.ts
|
403
480
|
init_react_import();
|
@@ -432,24 +509,159 @@ 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
|
|
451
|
-
// ../core/lib/data/walk-
|
452
|
-
function
|
663
|
+
// ../core/lib/data/walk-app-state.ts
|
664
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
453
665
|
var _a;
|
454
666
|
let newZones = {};
|
455
667
|
const newZoneIndex = {};
|
@@ -490,10 +702,9 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
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 walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
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
|
@@ -582,7 +794,7 @@ var setAction = (state, action, appStore) => {
|
|
582
794
|
console.warn(
|
583
795
|
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
584
796
|
);
|
585
|
-
return
|
797
|
+
return walkAppState(newState, appStore.config);
|
586
798
|
}
|
587
799
|
return __spreadValues(__spreadValues({}, state), action.state(state));
|
588
800
|
};
|
@@ -668,18 +880,77 @@ 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
|
-
return
|
953
|
+
return walkAppState(
|
683
954
|
state,
|
684
955
|
appStore.config,
|
685
956
|
(content, zoneCompound) => {
|
@@ -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
|
}
|
720
|
-
|
991
|
+
const data = populateIds(action.data, appStore.config);
|
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;
|
@@ -746,7 +1018,7 @@ var replaceAction = (state, action, appStore) => {
|
|
746
1018
|
// ../core/reducer/actions/replace-root.ts
|
747
1019
|
init_react_import();
|
748
1020
|
var replaceRootAction = (state, action, appStore) => {
|
749
|
-
return
|
1021
|
+
return walkAppState(
|
750
1022
|
state,
|
751
1023
|
appStore.config,
|
752
1024
|
(content) => content,
|
@@ -785,7 +1057,7 @@ function duplicateAction(state, action, appStore) {
|
|
785
1057
|
id: generateId(item.type)
|
786
1058
|
})
|
787
1059
|
});
|
788
|
-
const modified =
|
1060
|
+
const modified = walkAppState(
|
789
1061
|
state,
|
790
1062
|
appStore.config,
|
791
1063
|
(content, zoneCompound) => {
|
@@ -850,7 +1122,7 @@ var moveAction = (state, action, appStore) => {
|
|
850
1122
|
if (!item) return state;
|
851
1123
|
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
852
1124
|
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
853
|
-
return
|
1125
|
+
return walkAppState(
|
854
1126
|
state,
|
855
1127
|
appStore.config,
|
856
1128
|
(content, zoneCompound) => {
|
@@ -898,7 +1170,6 @@ var reorderAction = (state, action, appStore) => {
|
|
898
1170
|
init_react_import();
|
899
1171
|
var removeAction = (state, action, appStore) => {
|
900
1172
|
const item = getItem({ index: action.index, zone: action.zone }, state);
|
901
|
-
const [parentId] = action.zone.split(":");
|
902
1173
|
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
903
1174
|
(acc, [nodeId, nodeData]) => {
|
904
1175
|
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
@@ -909,7 +1180,7 @@ var removeAction = (state, action, appStore) => {
|
|
909
1180
|
},
|
910
1181
|
[item.props.id]
|
911
1182
|
);
|
912
|
-
const newState =
|
1183
|
+
const newState = walkAppState(
|
913
1184
|
state,
|
914
1185
|
appStore.config,
|
915
1186
|
(content, zoneCompound) => {
|
@@ -917,24 +1188,17 @@ var removeAction = (state, action, appStore) => {
|
|
917
1188
|
return remove(content, action.index);
|
918
1189
|
}
|
919
1190
|
return content;
|
920
|
-
},
|
921
|
-
(childItem, path) => {
|
922
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
923
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
924
|
-
return childItem;
|
925
|
-
}
|
926
|
-
return null;
|
927
1191
|
}
|
928
1192
|
);
|
929
1193
|
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
930
|
-
const
|
931
|
-
if (nodesToDelete.includes(
|
1194
|
+
const parentId = zoneCompound.split(":")[0];
|
1195
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
932
1196
|
delete newState.data.zones[zoneCompound];
|
933
1197
|
}
|
934
1198
|
});
|
935
1199
|
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
936
|
-
const
|
937
|
-
if (nodesToDelete.includes(
|
1200
|
+
const parentId = zoneCompound.split(":")[0];
|
1201
|
+
if (nodesToDelete.includes(parentId)) {
|
938
1202
|
delete newState.indexes.zones[zoneCompound];
|
939
1203
|
}
|
940
1204
|
});
|
@@ -1007,14 +1271,14 @@ var setDataAction = (state, action, appStore) => {
|
|
1007
1271
|
console.warn(
|
1008
1272
|
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1009
1273
|
);
|
1010
|
-
return
|
1274
|
+
return walkAppState(
|
1011
1275
|
__spreadProps(__spreadValues({}, state), {
|
1012
1276
|
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1013
1277
|
}),
|
1014
1278
|
appStore.config
|
1015
1279
|
);
|
1016
1280
|
}
|
1017
|
-
return
|
1281
|
+
return walkAppState(
|
1018
1282
|
__spreadProps(__spreadValues({}, state), {
|
1019
1283
|
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1020
1284
|
}),
|
@@ -1301,7 +1565,7 @@ var createHistorySlice = (set, get) => {
|
|
1301
1565
|
const { dispatch, history } = get();
|
1302
1566
|
dispatch({
|
1303
1567
|
type: "set",
|
1304
|
-
state: ((_a = history.histories[
|
1568
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1305
1569
|
});
|
1306
1570
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1307
1571
|
},
|
@@ -1317,7 +1581,11 @@ var createNodesSlice = (set, get) => ({
|
|
1317
1581
|
const s = get().nodes;
|
1318
1582
|
const emptyNode = {
|
1319
1583
|
id,
|
1320
|
-
methods: {
|
1584
|
+
methods: {
|
1585
|
+
sync: () => null,
|
1586
|
+
hideOverlay: () => null,
|
1587
|
+
showOverlay: () => null
|
1588
|
+
},
|
1321
1589
|
element: null
|
1322
1590
|
};
|
1323
1591
|
const existingNode = s.nodes[id];
|
@@ -1354,7 +1622,7 @@ import { useEffect as useEffect3 } from "react";
|
|
1354
1622
|
init_react_import();
|
1355
1623
|
var flattenData = (state, config) => {
|
1356
1624
|
const data = [];
|
1357
|
-
|
1625
|
+
walkAppState(
|
1358
1626
|
state,
|
1359
1627
|
config,
|
1360
1628
|
(content) => content,
|
@@ -1368,12 +1636,13 @@ var flattenData = (state, config) => {
|
|
1368
1636
|
|
1369
1637
|
// ../core/lib/get-changed.ts
|
1370
1638
|
init_react_import();
|
1639
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1371
1640
|
var getChanged = (newItem, oldItem) => {
|
1372
1641
|
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1373
1642
|
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1374
1643
|
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1375
1644
|
return __spreadProps(__spreadValues({}, acc), {
|
1376
|
-
[item]: oldItemProps[item]
|
1645
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
1377
1646
|
});
|
1378
1647
|
}, {}) : {};
|
1379
1648
|
};
|
@@ -1491,45 +1760,23 @@ var createFieldsSlice = (_set, _get) => {
|
|
1491
1760
|
return {
|
1492
1761
|
fields: {},
|
1493
1762
|
loading: false,
|
1494
|
-
lastResolvedData: {}
|
1763
|
+
lastResolvedData: {},
|
1764
|
+
id: void 0
|
1495
1765
|
};
|
1496
1766
|
};
|
1497
1767
|
|
1498
1768
|
// ../core/lib/resolve-component-data.ts
|
1499
1769
|
init_react_import();
|
1500
|
-
|
1501
|
-
// ../core/lib/data/map-slots.ts
|
1502
|
-
init_react_import();
|
1503
|
-
function mapSlots(_0, _1) {
|
1504
|
-
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1505
|
-
const props = __spreadValues({}, item.props);
|
1506
|
-
const propKeys = Object.keys(props);
|
1507
|
-
for (let i = 0; i < propKeys.length; i++) {
|
1508
|
-
const propKey = propKeys[i];
|
1509
|
-
const itemType = "type" in item ? item.type : "root";
|
1510
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
1511
|
-
const content = props[propKey];
|
1512
|
-
const mappedContent = recursive ? yield Promise.all(
|
1513
|
-
content.map((item2) => __async(this, null, function* () {
|
1514
|
-
return yield mapSlots(item2, map, recursive, isSlot2);
|
1515
|
-
}))
|
1516
|
-
) : content;
|
1517
|
-
props[propKey] = yield map(mappedContent, propKey);
|
1518
|
-
}
|
1519
|
-
}
|
1520
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
1521
|
-
});
|
1522
|
-
}
|
1523
|
-
|
1524
|
-
// ../core/lib/resolve-component-data.ts
|
1525
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1770
|
+
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1526
1771
|
var cache = { lastChange: {} };
|
1527
|
-
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") {
|
1528
1773
|
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1529
|
-
|
1530
|
-
|
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) {
|
1531
1778
|
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1532
|
-
if (item && (0,
|
1779
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
1533
1780
|
return { node: resolved, didChange: false };
|
1534
1781
|
}
|
1535
1782
|
const changed = getChanged(item, oldItem);
|
@@ -1539,49 +1786,45 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1539
1786
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1540
1787
|
changed,
|
1541
1788
|
lastData: oldItem,
|
1542
|
-
metadata,
|
1789
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1543
1790
|
trigger
|
1544
1791
|
});
|
1545
|
-
|
1546
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1547
|
-
});
|
1548
|
-
if (recursive) {
|
1549
|
-
resolvedItem = yield mapSlots(
|
1550
|
-
resolvedItem,
|
1551
|
-
(content) => __async(void 0, null, function* () {
|
1552
|
-
return Promise.all(
|
1553
|
-
content.map(
|
1554
|
-
(childItem) => __async(void 0, null, function* () {
|
1555
|
-
return (yield resolveComponentData(
|
1556
|
-
childItem,
|
1557
|
-
config,
|
1558
|
-
metadata,
|
1559
|
-
onResolveStart,
|
1560
|
-
onResolveEnd,
|
1561
|
-
trigger,
|
1562
|
-
false
|
1563
|
-
)).node;
|
1564
|
-
})
|
1565
|
-
)
|
1566
|
-
);
|
1567
|
-
}),
|
1568
|
-
false,
|
1569
|
-
createIsSlotConfig(config)
|
1570
|
-
);
|
1571
|
-
}
|
1792
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
1572
1793
|
if (Object.keys(readOnly).length) {
|
1573
1794
|
resolvedItem.readOnly = readOnly;
|
1574
1795
|
}
|
1575
|
-
cache.lastChange[id] = {
|
1576
|
-
item,
|
1577
|
-
resolved: resolvedItem
|
1578
|
-
};
|
1579
|
-
if (onResolveEnd) {
|
1580
|
-
onResolveEnd(resolvedItem);
|
1581
|
-
}
|
1582
|
-
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1583
1796
|
}
|
1584
|
-
|
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
|
+
};
|
1585
1828
|
});
|
1586
1829
|
|
1587
1830
|
// ../core/lib/data/to-root.ts
|
@@ -1601,7 +1844,8 @@ var toRoot = (item) => {
|
|
1601
1844
|
return { props: {}, readOnly };
|
1602
1845
|
};
|
1603
1846
|
|
1604
|
-
// ../core/store/
|
1847
|
+
// ../core/store/default-app-state.ts
|
1848
|
+
init_react_import();
|
1605
1849
|
var defaultAppState = {
|
1606
1850
|
data: { content: [], root: {}, zones: {} },
|
1607
1851
|
ui: {
|
@@ -1627,6 +1871,8 @@ var defaultAppState = {
|
|
1627
1871
|
zones: {}
|
1628
1872
|
}
|
1629
1873
|
};
|
1874
|
+
|
1875
|
+
// ../core/store/index.ts
|
1630
1876
|
var defaultPageFields = {
|
1631
1877
|
title: { type: "text" }
|
1632
1878
|
};
|
@@ -1766,7 +2012,7 @@ var createAppStore = (initialAppStore) => create()(
|
|
1766
2012
|
}),
|
1767
2013
|
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1768
2014
|
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1769
|
-
|
2015
|
+
walkAppState(
|
1770
2016
|
state,
|
1771
2017
|
config,
|
1772
2018
|
(content) => content,
|