@measured/puck-plugin-heading-analyzer 0.19.0-canary.f96dc87b → 0.19.0
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 +22 -10
- package/dist/index.d.ts +22 -10
- package/dist/index.js +1236 -673
- package/dist/index.mjs +1229 -666
- 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) {
|
@@ -187,7 +301,7 @@ init_react_import();
|
|
187
301
|
|
188
302
|
// src/HeadingAnalyzer.tsx
|
189
303
|
init_react_import();
|
190
|
-
import { useEffect as
|
304
|
+
import { useEffect as useEffect5, useState } from "react";
|
191
305
|
|
192
306
|
// css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
|
193
307
|
init_react_import();
|
@@ -356,17 +470,17 @@ init_react_import();
|
|
356
470
|
// ../core/reducer/index.ts
|
357
471
|
init_react_import();
|
358
472
|
|
359
|
-
// ../core/reducer/
|
473
|
+
// ../core/reducer/actions/set.ts
|
360
474
|
init_react_import();
|
361
475
|
|
362
|
-
// ../core/lib/
|
476
|
+
// ../core/lib/data/walk-app-state.ts
|
477
|
+
init_react_import();
|
478
|
+
|
479
|
+
// ../core/lib/data/for-related-zones.ts
|
480
|
+
init_react_import();
|
481
|
+
|
482
|
+
// ../core/lib/get-zone-id.ts
|
363
483
|
init_react_import();
|
364
|
-
var reorder = (list, startIndex, endIndex) => {
|
365
|
-
const result = Array.from(list);
|
366
|
-
const [removed] = result.splice(startIndex, 1);
|
367
|
-
result.splice(endIndex, 0, removed);
|
368
|
-
return result;
|
369
|
-
};
|
370
484
|
|
371
485
|
// ../core/lib/root-droppable-id.ts
|
372
486
|
init_react_import();
|
@@ -374,57 +488,336 @@ var rootAreaId = "root";
|
|
374
488
|
var rootZone = "default-zone";
|
375
489
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
376
490
|
|
377
|
-
// ../core/lib/
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
491
|
+
// ../core/lib/get-zone-id.ts
|
492
|
+
var getZoneId = (zoneCompound) => {
|
493
|
+
if (!zoneCompound) {
|
494
|
+
return [];
|
495
|
+
}
|
496
|
+
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
497
|
+
return zoneCompound.split(":");
|
498
|
+
}
|
499
|
+
return [rootDroppableId, zoneCompound];
|
383
500
|
};
|
384
501
|
|
385
|
-
// ../core/lib/
|
502
|
+
// ../core/lib/data/for-related-zones.ts
|
503
|
+
function forRelatedZones(item, data, cb, path = []) {
|
504
|
+
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
505
|
+
const [parentId] = getZoneId(zoneCompound);
|
506
|
+
if (parentId === item.props.id) {
|
507
|
+
cb(path, zoneCompound, content);
|
508
|
+
}
|
509
|
+
});
|
510
|
+
}
|
511
|
+
|
512
|
+
// ../core/lib/data/map-slots.ts
|
386
513
|
init_react_import();
|
387
|
-
var remove = (list, index) => {
|
388
|
-
const result = Array.from(list);
|
389
|
-
result.splice(index, 1);
|
390
|
-
return result;
|
391
|
-
};
|
392
514
|
|
393
|
-
// ../core/lib/
|
515
|
+
// ../core/lib/data/default-slots.ts
|
394
516
|
init_react_import();
|
395
|
-
var
|
396
|
-
|
397
|
-
|
517
|
+
var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
518
|
+
(acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
|
519
|
+
value
|
520
|
+
);
|
521
|
+
|
522
|
+
// ../core/lib/data/map-slots.ts
|
523
|
+
var isPromise = (v) => !!v && typeof v.then === "function";
|
524
|
+
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
525
|
+
var containsPromise = (arr) => arr.some(isPromise);
|
526
|
+
var walkField = ({
|
527
|
+
value,
|
528
|
+
fields,
|
529
|
+
map,
|
530
|
+
propKey = "",
|
531
|
+
propPath = "",
|
532
|
+
id = "",
|
533
|
+
config,
|
534
|
+
recurseSlots = false
|
535
|
+
}) => {
|
536
|
+
var _a, _b, _c;
|
537
|
+
if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
|
538
|
+
const content = value || [];
|
539
|
+
const mappedContent = recurseSlots ? content.map((el) => {
|
540
|
+
var _a2;
|
541
|
+
const componentConfig = config.components[el.type];
|
542
|
+
if (!componentConfig) {
|
543
|
+
throw new Error(`Could not find component config for ${el.type}`);
|
544
|
+
}
|
545
|
+
const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
|
546
|
+
return walkField({
|
547
|
+
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
548
|
+
fields: fields2,
|
549
|
+
map,
|
550
|
+
id: el.props.id,
|
551
|
+
config,
|
552
|
+
recurseSlots
|
553
|
+
});
|
554
|
+
}) : content;
|
555
|
+
if (containsPromise(mappedContent)) {
|
556
|
+
return Promise.all(mappedContent);
|
557
|
+
}
|
558
|
+
return map(mappedContent, id, propPath, fields[propKey], propPath);
|
398
559
|
}
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
560
|
+
if (value && typeof value === "object") {
|
561
|
+
if (Array.isArray(value)) {
|
562
|
+
const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
|
563
|
+
if (!arrayFields) return value;
|
564
|
+
const newValue = value.map(
|
565
|
+
(el, idx) => walkField({
|
566
|
+
value: el,
|
567
|
+
fields: arrayFields,
|
568
|
+
map,
|
569
|
+
propKey,
|
570
|
+
propPath: `${propPath}[${idx}]`,
|
571
|
+
id,
|
572
|
+
config,
|
573
|
+
recurseSlots
|
574
|
+
})
|
575
|
+
);
|
576
|
+
if (containsPromise(newValue)) {
|
577
|
+
return Promise.all(newValue);
|
578
|
+
}
|
579
|
+
return newValue;
|
580
|
+
} else if ("$$typeof" in value) {
|
581
|
+
return value;
|
582
|
+
} else {
|
583
|
+
const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
|
584
|
+
return walkObject({
|
585
|
+
value,
|
586
|
+
fields: objectFields,
|
587
|
+
map,
|
588
|
+
id,
|
589
|
+
getPropPath: (k) => `${propPath}.${k}`,
|
590
|
+
config,
|
591
|
+
recurseSlots
|
592
|
+
});
|
593
|
+
}
|
594
|
+
}
|
595
|
+
return value;
|
596
|
+
};
|
597
|
+
var walkObject = ({
|
598
|
+
value,
|
599
|
+
fields,
|
600
|
+
map,
|
601
|
+
id,
|
602
|
+
getPropPath,
|
603
|
+
config,
|
604
|
+
recurseSlots
|
605
|
+
}) => {
|
606
|
+
const newProps = Object.entries(value).map(([k, v]) => {
|
607
|
+
const opts = {
|
608
|
+
value: v,
|
609
|
+
fields,
|
610
|
+
map,
|
611
|
+
propKey: k,
|
612
|
+
propPath: getPropPath(k),
|
613
|
+
id,
|
614
|
+
config,
|
615
|
+
recurseSlots
|
616
|
+
};
|
617
|
+
const newValue = walkField(opts);
|
618
|
+
if (isPromise(newValue)) {
|
619
|
+
return newValue.then((resolvedValue) => ({
|
620
|
+
[k]: resolvedValue
|
621
|
+
}));
|
622
|
+
}
|
623
|
+
return {
|
624
|
+
[k]: newValue
|
625
|
+
};
|
626
|
+
}, {});
|
627
|
+
if (containsPromise(newProps)) {
|
628
|
+
return Promise.all(newProps).then(flatten);
|
629
|
+
}
|
630
|
+
return flatten(newProps);
|
404
631
|
};
|
632
|
+
function mapSlots(item, map, config, recurseSlots = false) {
|
633
|
+
var _a, _b, _c, _d, _e;
|
634
|
+
const itemType = "type" in item ? item.type : "root";
|
635
|
+
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
636
|
+
const newProps = walkObject({
|
637
|
+
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
638
|
+
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
639
|
+
map,
|
640
|
+
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
641
|
+
getPropPath: (k) => k,
|
642
|
+
config,
|
643
|
+
recurseSlots
|
644
|
+
});
|
645
|
+
if (isPromise(newProps)) {
|
646
|
+
return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
|
647
|
+
props: resolvedProps
|
648
|
+
}));
|
649
|
+
}
|
650
|
+
return __spreadProps(__spreadValues({}, item), {
|
651
|
+
props: newProps
|
652
|
+
});
|
653
|
+
}
|
405
654
|
|
406
|
-
// ../core/lib/
|
655
|
+
// ../core/lib/data/flatten-node.ts
|
407
656
|
init_react_import();
|
408
|
-
var
|
409
|
-
const result = Array.from(list);
|
410
|
-
result.splice(index, 1);
|
411
|
-
result.splice(index, 0, newItem);
|
412
|
-
return result;
|
413
|
-
};
|
657
|
+
var import_flat = __toESM(require_flat());
|
414
658
|
|
415
|
-
// ../core/lib/
|
659
|
+
// ../core/lib/data/strip-slots.ts
|
416
660
|
init_react_import();
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
return
|
661
|
+
var stripSlots = (data, config) => {
|
662
|
+
return mapSlots(data, () => null, config);
|
663
|
+
};
|
664
|
+
|
665
|
+
// ../core/lib/data/flatten-node.ts
|
666
|
+
var flattenNode = (node, config) => {
|
667
|
+
return __spreadProps(__spreadValues({}, node), {
|
668
|
+
props: (0, import_flat.flatten)(stripSlots(node, config).props)
|
669
|
+
});
|
670
|
+
};
|
671
|
+
|
672
|
+
// ../core/lib/data/walk-app-state.ts
|
673
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
674
|
+
var _a;
|
675
|
+
let newZones = {};
|
676
|
+
const newZoneIndex = {};
|
677
|
+
const newNodeIndex = {};
|
678
|
+
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
679
|
+
var _a2;
|
680
|
+
const [parentId] = zoneCompound.split(":");
|
681
|
+
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
682
|
+
const [_2, zone] = zoneCompound.split(":");
|
683
|
+
const newZoneCompound = `${newId || parentId}:${zone}`;
|
684
|
+
const newContent2 = mappedContent.map(
|
685
|
+
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
686
|
+
);
|
687
|
+
newZoneIndex[newZoneCompound] = {
|
688
|
+
contentIds: newContent2.map((item) => item.props.id),
|
689
|
+
type: zoneType
|
690
|
+
};
|
691
|
+
return [newZoneCompound, newContent2];
|
692
|
+
};
|
693
|
+
const processRelatedZones = (item, newId, initialPath) => {
|
694
|
+
forRelatedZones(
|
695
|
+
item,
|
696
|
+
state.data,
|
697
|
+
(relatedPath, relatedZoneCompound, relatedContent) => {
|
698
|
+
const [zoneCompound, newContent2] = processContent(
|
699
|
+
relatedPath,
|
700
|
+
relatedZoneCompound,
|
701
|
+
relatedContent,
|
702
|
+
"dropzone",
|
703
|
+
newId
|
704
|
+
);
|
705
|
+
newZones[zoneCompound] = newContent2;
|
706
|
+
},
|
707
|
+
initialPath
|
708
|
+
);
|
709
|
+
};
|
710
|
+
const processItem = (item, path, index) => {
|
711
|
+
const mappedItem = mapNodeOrSkip(item, path, index);
|
712
|
+
if (!mappedItem) return item;
|
713
|
+
const id = mappedItem.props.id;
|
714
|
+
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
715
|
+
mappedItem,
|
716
|
+
(content, parentId2, slotId) => {
|
717
|
+
const zoneCompound = `${parentId2}:${slotId}`;
|
718
|
+
const [_2, newContent2] = processContent(
|
719
|
+
path,
|
720
|
+
zoneCompound,
|
721
|
+
content,
|
722
|
+
"slot",
|
723
|
+
parentId2
|
724
|
+
);
|
725
|
+
return newContent2;
|
726
|
+
},
|
727
|
+
config
|
728
|
+
).props), {
|
729
|
+
id
|
730
|
+
});
|
731
|
+
processRelatedZones(item, id, path);
|
732
|
+
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
733
|
+
const thisZoneCompound = path[path.length - 1];
|
734
|
+
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
735
|
+
newNodeIndex[id] = {
|
736
|
+
data: newItem,
|
737
|
+
flatData: flattenNode(newItem, config),
|
738
|
+
path,
|
739
|
+
parentId,
|
740
|
+
zone
|
741
|
+
};
|
742
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
743
|
+
if (newProps.id === "root") {
|
744
|
+
delete finalData["type"];
|
745
|
+
delete finalData.props["id"];
|
746
|
+
}
|
747
|
+
return finalData;
|
748
|
+
};
|
749
|
+
const zones = state.data.zones || {};
|
750
|
+
const [_, newContent] = processContent(
|
751
|
+
[],
|
752
|
+
rootDroppableId,
|
753
|
+
state.data.content,
|
754
|
+
"root"
|
755
|
+
);
|
756
|
+
const processedContent = newContent;
|
757
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
758
|
+
Object.keys(zones || {}).forEach((zoneCompound) => {
|
759
|
+
const [parentId] = zoneCompound.split(":");
|
760
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
761
|
+
return;
|
762
|
+
}
|
763
|
+
const [_2, newContent2] = processContent(
|
764
|
+
[rootDroppableId],
|
765
|
+
zoneCompound,
|
766
|
+
zones[zoneCompound],
|
767
|
+
"dropzone",
|
768
|
+
parentId
|
769
|
+
);
|
770
|
+
newZones[zoneCompound] = newContent2;
|
771
|
+
}, newZones);
|
772
|
+
const processedRoot = processItem(
|
773
|
+
{
|
774
|
+
type: "root",
|
775
|
+
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
776
|
+
},
|
777
|
+
[],
|
778
|
+
-1
|
779
|
+
);
|
780
|
+
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
781
|
+
props: processedRoot.props
|
782
|
+
});
|
783
|
+
return __spreadProps(__spreadValues({}, state), {
|
784
|
+
data: {
|
785
|
+
root,
|
786
|
+
content: processedContent,
|
787
|
+
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
788
|
+
},
|
789
|
+
indexes: {
|
790
|
+
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
791
|
+
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
792
|
+
}
|
793
|
+
});
|
424
794
|
}
|
425
795
|
|
426
|
-
// ../core/
|
796
|
+
// ../core/reducer/actions/set.ts
|
797
|
+
var setAction = (state, action, appStore) => {
|
798
|
+
if (typeof action.state === "object") {
|
799
|
+
const newState = __spreadValues(__spreadValues({}, state), action.state);
|
800
|
+
if (action.state.indexes) {
|
801
|
+
return newState;
|
802
|
+
}
|
803
|
+
console.warn(
|
804
|
+
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
805
|
+
);
|
806
|
+
return walkAppState(newState, appStore.config);
|
807
|
+
}
|
808
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
809
|
+
};
|
810
|
+
|
811
|
+
// ../core/reducer/actions/insert.ts
|
812
|
+
init_react_import();
|
813
|
+
|
814
|
+
// ../core/lib/data/insert.ts
|
427
815
|
init_react_import();
|
816
|
+
var insert = (list, index, item) => {
|
817
|
+
const result = Array.from(list || []);
|
818
|
+
result.splice(index, 0, item);
|
819
|
+
return result;
|
820
|
+
};
|
428
821
|
|
429
822
|
// ../core/lib/generate-id.ts
|
430
823
|
init_react_import();
|
@@ -488,313 +881,438 @@ var v4_default = v4;
|
|
488
881
|
// ../core/lib/generate-id.ts
|
489
882
|
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
490
883
|
|
491
|
-
// ../core/lib/get-
|
884
|
+
// ../core/lib/data/get-ids-for-parent.ts
|
492
885
|
init_react_import();
|
493
|
-
var
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
498
|
-
return zoneCompound.split(":");
|
499
|
-
}
|
500
|
-
return [rootDroppableId, zoneCompound];
|
886
|
+
var getIdsForParent = (zoneCompound, state) => {
|
887
|
+
const [parentId] = zoneCompound.split(":");
|
888
|
+
const node = state.indexes.nodes[parentId];
|
889
|
+
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
501
890
|
};
|
502
891
|
|
503
|
-
// ../core/lib/
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
892
|
+
// ../core/lib/data/populate-ids.ts
|
893
|
+
init_react_import();
|
894
|
+
|
895
|
+
// ../core/lib/data/walk-tree.ts
|
896
|
+
init_react_import();
|
897
|
+
function walkTree(data, config, callbackFn) {
|
898
|
+
var _a, _b;
|
899
|
+
const walkItem = (item) => {
|
900
|
+
return mapSlots(
|
901
|
+
item,
|
902
|
+
(content, parentId, propName) => {
|
903
|
+
var _a2;
|
904
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
514
905
|
},
|
906
|
+
config,
|
907
|
+
true
|
908
|
+
);
|
909
|
+
};
|
910
|
+
if ("props" in data) {
|
911
|
+
return walkItem(data);
|
912
|
+
}
|
913
|
+
const _data = data;
|
914
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
915
|
+
const mappedContent = _data.content.map(walkItem);
|
916
|
+
return {
|
917
|
+
root: walkItem(_data.root),
|
918
|
+
content: (_b = callbackFn(mappedContent, {
|
919
|
+
parentId: "root",
|
920
|
+
propName: "default-zone"
|
921
|
+
})) != null ? _b : mappedContent,
|
922
|
+
zones: Object.keys(zones).reduce(
|
923
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
924
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
925
|
+
}),
|
515
926
|
{}
|
516
927
|
)
|
517
|
-
}
|
928
|
+
};
|
518
929
|
}
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
930
|
+
|
931
|
+
// ../core/lib/data/populate-ids.ts
|
932
|
+
var populateIds = (data, config, override = false) => {
|
933
|
+
const id = generateId(data.type);
|
934
|
+
return walkTree(
|
935
|
+
__spreadProps(__spreadValues({}, data), {
|
936
|
+
props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
|
937
|
+
}),
|
938
|
+
config,
|
939
|
+
(contents) => contents.map((item) => {
|
940
|
+
const id2 = generateId(item.type);
|
941
|
+
return __spreadProps(__spreadValues({}, item), {
|
942
|
+
props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
|
943
|
+
});
|
944
|
+
})
|
945
|
+
);
|
946
|
+
};
|
947
|
+
|
948
|
+
// ../core/reducer/actions/insert.ts
|
949
|
+
function insertAction(state, action, appStore) {
|
950
|
+
const id = action.id || generateId(action.componentType);
|
951
|
+
const emptyComponentData = populateIds(
|
952
|
+
{
|
953
|
+
type: action.componentType,
|
954
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
955
|
+
id
|
956
|
+
})
|
957
|
+
},
|
958
|
+
appStore.config
|
959
|
+
);
|
960
|
+
const [parentId] = action.destinationZone.split(":");
|
961
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
962
|
+
return walkAppState(
|
963
|
+
state,
|
964
|
+
appStore.config,
|
965
|
+
(content, zoneCompound) => {
|
966
|
+
if (zoneCompound === action.destinationZone) {
|
967
|
+
return insert(
|
968
|
+
content || [],
|
969
|
+
action.destinationIndex,
|
970
|
+
emptyComponentData
|
971
|
+
);
|
526
972
|
}
|
527
|
-
return
|
973
|
+
return content;
|
528
974
|
},
|
529
|
-
{
|
975
|
+
(childItem, path) => {
|
976
|
+
if (childItem.props.id === id || childItem.props.id === parentId) {
|
977
|
+
return childItem;
|
978
|
+
} else if (idsInPath.includes(childItem.props.id)) {
|
979
|
+
return childItem;
|
980
|
+
} else if (path.includes(action.destinationZone)) {
|
981
|
+
return childItem;
|
982
|
+
}
|
983
|
+
return null;
|
984
|
+
}
|
530
985
|
);
|
531
|
-
}
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
986
|
+
}
|
987
|
+
|
988
|
+
// ../core/reducer/actions/replace.ts
|
989
|
+
init_react_import();
|
990
|
+
var replaceAction = (state, action, appStore) => {
|
991
|
+
const [parentId] = action.destinationZone.split(":");
|
992
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
993
|
+
const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
|
994
|
+
const idChanged = originalId !== action.data.props.id;
|
995
|
+
if (idChanged) {
|
996
|
+
throw new Error(
|
997
|
+
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
998
|
+
);
|
999
|
+
}
|
1000
|
+
const data = populateIds(action.data, appStore.config);
|
1001
|
+
return walkAppState(
|
1002
|
+
state,
|
1003
|
+
appStore.config,
|
1004
|
+
(content, zoneCompound) => {
|
1005
|
+
const newContent = [...content];
|
1006
|
+
if (zoneCompound === action.destinationZone) {
|
1007
|
+
newContent[action.destinationIndex] = data;
|
541
1008
|
}
|
542
|
-
return
|
1009
|
+
return newContent;
|
543
1010
|
},
|
544
|
-
{
|
1011
|
+
(childItem, path) => {
|
1012
|
+
const pathIds = path.map((p) => p.split(":")[0]);
|
1013
|
+
if (childItem.props.id === data.props.id) {
|
1014
|
+
return data;
|
1015
|
+
} else if (childItem.props.id === parentId) {
|
1016
|
+
return childItem;
|
1017
|
+
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
1018
|
+
return childItem;
|
1019
|
+
} else if (pathIds.indexOf(data.props.id) > -1) {
|
1020
|
+
return childItem;
|
1021
|
+
}
|
1022
|
+
return null;
|
1023
|
+
}
|
545
1024
|
);
|
546
1025
|
};
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
1026
|
+
|
1027
|
+
// ../core/reducer/actions/replace-root.ts
|
1028
|
+
init_react_import();
|
1029
|
+
var replaceRootAction = (state, action, appStore) => {
|
1030
|
+
return walkAppState(
|
1031
|
+
state,
|
1032
|
+
appStore.config,
|
1033
|
+
(content) => content,
|
1034
|
+
(childItem) => {
|
1035
|
+
if (childItem.props.id === "root") {
|
1036
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
1037
|
+
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
1038
|
+
readOnly: action.root.readOnly
|
1039
|
+
});
|
1040
|
+
}
|
1041
|
+
return childItem;
|
1042
|
+
}
|
1043
|
+
);
|
554
1044
|
};
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
return __spreadProps(__spreadValues({}, dupeOfDupes), {
|
566
|
-
[key]: zone,
|
567
|
-
[`${newId}:${zoneId}`]: dupedZone
|
568
|
-
});
|
569
|
-
});
|
1045
|
+
|
1046
|
+
// ../core/reducer/actions/duplicate.ts
|
1047
|
+
init_react_import();
|
1048
|
+
|
1049
|
+
// ../core/lib/data/get-item.ts
|
1050
|
+
init_react_import();
|
1051
|
+
function getItem(selector, state) {
|
1052
|
+
var _a, _b;
|
1053
|
+
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
1054
|
+
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
570
1055
|
}
|
571
1056
|
|
572
|
-
// ../core/reducer/
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
}
|
580
|
-
|
581
|
-
|
582
|
-
zones: __spreadProps(__spreadValues({}, newData.zones), {
|
583
|
-
[action.destinationZone]: replace(
|
584
|
-
newData.zones[action.destinationZone],
|
585
|
-
action.destinationIndex,
|
586
|
-
action.data
|
587
|
-
)
|
1057
|
+
// ../core/reducer/actions/duplicate.ts
|
1058
|
+
function duplicateAction(state, action, appStore) {
|
1059
|
+
const item = getItem(
|
1060
|
+
{ index: action.sourceIndex, zone: action.sourceZone },
|
1061
|
+
state
|
1062
|
+
);
|
1063
|
+
const idsInPath = getIdsForParent(action.sourceZone, state);
|
1064
|
+
const newItem = __spreadProps(__spreadValues({}, item), {
|
1065
|
+
props: __spreadProps(__spreadValues({}, item.props), {
|
1066
|
+
id: generateId(item.type)
|
588
1067
|
})
|
589
1068
|
});
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
1069
|
+
const modified = walkAppState(
|
1070
|
+
state,
|
1071
|
+
appStore.config,
|
1072
|
+
(content, zoneCompound) => {
|
1073
|
+
if (zoneCompound === action.sourceZone) {
|
1074
|
+
return insert(content, action.sourceIndex + 1, item);
|
1075
|
+
}
|
1076
|
+
return content;
|
1077
|
+
},
|
1078
|
+
(childItem, path, index) => {
|
1079
|
+
const zoneCompound = path[path.length - 1];
|
1080
|
+
const parents = path.map((p) => p.split(":")[0]);
|
1081
|
+
if (parents.indexOf(newItem.props.id) > -1) {
|
1082
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
1083
|
+
props: __spreadProps(__spreadValues({}, childItem.props), {
|
1084
|
+
id: generateId(childItem.type)
|
1085
|
+
})
|
1086
|
+
});
|
1087
|
+
}
|
1088
|
+
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
1089
|
+
return newItem;
|
1090
|
+
}
|
1091
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
1092
|
+
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
1093
|
+
return childItem;
|
1094
|
+
}
|
1095
|
+
return null;
|
1096
|
+
}
|
1097
|
+
);
|
1098
|
+
return __spreadProps(__spreadValues({}, modified), {
|
1099
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
1100
|
+
itemSelector: {
|
1101
|
+
index: action.sourceIndex + 1,
|
1102
|
+
zone: action.sourceZone
|
1103
|
+
}
|
615
1104
|
})
|
616
1105
|
});
|
617
1106
|
}
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
const
|
629
|
-
|
630
|
-
|
631
|
-
[action.destinationZone]: reorder(
|
632
|
-
newData.zones[action.destinationZone],
|
633
|
-
action.sourceIndex,
|
634
|
-
action.destinationIndex
|
635
|
-
)
|
636
|
-
})
|
637
|
-
});
|
1107
|
+
|
1108
|
+
// ../core/reducer/actions/reorder.ts
|
1109
|
+
init_react_import();
|
1110
|
+
|
1111
|
+
// ../core/reducer/actions/move.ts
|
1112
|
+
init_react_import();
|
1113
|
+
|
1114
|
+
// ../core/lib/data/remove.ts
|
1115
|
+
init_react_import();
|
1116
|
+
var remove = (list, index) => {
|
1117
|
+
const result = Array.from(list);
|
1118
|
+
result.splice(index, 1);
|
1119
|
+
return result;
|
638
1120
|
};
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
const item = getItem(
|
645
|
-
{ index: action.sourceIndex, zone: action.sourceZone },
|
646
|
-
data
|
647
|
-
);
|
648
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
649
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
650
|
-
id: generateId(item.type)
|
651
|
-
})
|
652
|
-
});
|
653
|
-
const dataWithRelatedDuplicated = duplicateRelatedZones(
|
654
|
-
item,
|
655
|
-
data,
|
656
|
-
newItem.props.id
|
657
|
-
);
|
658
|
-
if (action.sourceZone === rootDroppableId) {
|
659
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
|
660
|
-
content: insert(data.content, action.sourceIndex + 1, newItem)
|
661
|
-
});
|
662
|
-
}
|
663
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
|
664
|
-
zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
|
665
|
-
[action.sourceZone]: insert(
|
666
|
-
dataWithRelatedDuplicated.zones[action.sourceZone],
|
667
|
-
action.sourceIndex + 1,
|
668
|
-
newItem
|
669
|
-
)
|
670
|
-
})
|
671
|
-
});
|
672
|
-
}
|
673
|
-
if (action.type === "reorder") {
|
674
|
-
return reorderAction(data, action);
|
1121
|
+
|
1122
|
+
// ../core/reducer/actions/move.ts
|
1123
|
+
var moveAction = (state, action, appStore) => {
|
1124
|
+
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
1125
|
+
return state;
|
675
1126
|
}
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
1127
|
+
const item = getItem(
|
1128
|
+
{ zone: action.sourceZone, index: action.sourceIndex },
|
1129
|
+
state
|
1130
|
+
);
|
1131
|
+
if (!item) return state;
|
1132
|
+
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
1133
|
+
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
1134
|
+
return walkAppState(
|
1135
|
+
state,
|
1136
|
+
appStore.config,
|
1137
|
+
(content, zoneCompound) => {
|
1138
|
+
if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
|
1139
|
+
return insert(
|
1140
|
+
remove(content, action.sourceIndex),
|
1141
|
+
action.destinationIndex,
|
1142
|
+
item
|
1143
|
+
);
|
1144
|
+
} else if (zoneCompound === action.sourceZone) {
|
1145
|
+
return remove(content, action.sourceIndex);
|
1146
|
+
} else if (zoneCompound === action.destinationZone) {
|
1147
|
+
return insert(content, action.destinationIndex, item);
|
1148
|
+
}
|
1149
|
+
return content;
|
1150
|
+
},
|
1151
|
+
(childItem, path) => {
|
1152
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
1153
|
+
const [destinationZoneParent] = action.destinationZone.split(":");
|
1154
|
+
const childId = childItem.props.id;
|
1155
|
+
if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
|
1156
|
+
return childItem;
|
1157
|
+
}
|
1158
|
+
return null;
|
690
1159
|
}
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
1160
|
+
);
|
1161
|
+
};
|
1162
|
+
|
1163
|
+
// ../core/reducer/actions/reorder.ts
|
1164
|
+
var reorderAction = (state, action, appStore) => {
|
1165
|
+
return moveAction(
|
1166
|
+
state,
|
1167
|
+
{
|
1168
|
+
type: "move",
|
1169
|
+
sourceIndex: action.sourceIndex,
|
1170
|
+
sourceZone: action.destinationZone,
|
1171
|
+
destinationIndex: action.destinationIndex,
|
1172
|
+
destinationZone: action.destinationZone
|
1173
|
+
},
|
1174
|
+
appStore
|
1175
|
+
);
|
1176
|
+
};
|
1177
|
+
|
1178
|
+
// ../core/reducer/actions/remove.ts
|
1179
|
+
init_react_import();
|
1180
|
+
var removeAction = (state, action, appStore) => {
|
1181
|
+
const item = getItem({ index: action.index, zone: action.zone }, state);
|
1182
|
+
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
1183
|
+
(acc, [nodeId, nodeData]) => {
|
1184
|
+
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
1185
|
+
if (pathIds.includes(item.props.id)) {
|
1186
|
+
return [...acc, nodeId];
|
1187
|
+
}
|
1188
|
+
return acc;
|
1189
|
+
},
|
1190
|
+
[item.props.id]
|
1191
|
+
);
|
1192
|
+
const newState = walkAppState(
|
1193
|
+
state,
|
1194
|
+
appStore.config,
|
1195
|
+
(content, zoneCompound) => {
|
1196
|
+
if (zoneCompound === action.zone) {
|
1197
|
+
return remove(content, action.index);
|
1198
|
+
}
|
1199
|
+
return content;
|
702
1200
|
}
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
newData.zones[action.sourceZone],
|
709
|
-
action.sourceIndex
|
710
|
-
)
|
711
|
-
})
|
712
|
-
});
|
1201
|
+
);
|
1202
|
+
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
1203
|
+
const parentId = zoneCompound.split(":")[0];
|
1204
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
1205
|
+
delete newState.data.zones[zoneCompound];
|
713
1206
|
}
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
),
|
720
|
-
[action.destinationZone]: insert(
|
721
|
-
newData.zones[action.destinationZone],
|
722
|
-
action.destinationIndex,
|
723
|
-
item
|
724
|
-
)
|
725
|
-
})
|
726
|
-
});
|
727
|
-
}
|
728
|
-
if (action.type === "replace") {
|
729
|
-
return replaceAction(data, action);
|
730
|
-
}
|
731
|
-
if (action.type === "remove") {
|
732
|
-
const item = getItem({ index: action.index, zone: action.zone }, data);
|
733
|
-
const dataWithRelatedRemoved = setupZone(
|
734
|
-
removeRelatedZones(item, data),
|
735
|
-
action.zone
|
736
|
-
);
|
737
|
-
if (action.zone === rootDroppableId) {
|
738
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
|
739
|
-
content: remove(data.content, action.index)
|
740
|
-
});
|
1207
|
+
});
|
1208
|
+
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
1209
|
+
const parentId = zoneCompound.split(":")[0];
|
1210
|
+
if (nodesToDelete.includes(parentId)) {
|
1211
|
+
delete newState.indexes.zones[zoneCompound];
|
741
1212
|
}
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
1213
|
+
});
|
1214
|
+
nodesToDelete.forEach((id) => {
|
1215
|
+
delete newState.indexes.nodes[id];
|
1216
|
+
});
|
1217
|
+
return newState;
|
1218
|
+
};
|
1219
|
+
|
1220
|
+
// ../core/reducer/actions/register-zone.ts
|
1221
|
+
init_react_import();
|
1222
|
+
|
1223
|
+
// ../core/lib/data/setup-zone.ts
|
1224
|
+
init_react_import();
|
1225
|
+
var setupZone = (data, zoneKey) => {
|
1226
|
+
if (zoneKey === rootDroppableId) {
|
1227
|
+
return data;
|
750
1228
|
}
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
1229
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
1230
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
1231
|
+
});
|
1232
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
1233
|
+
return newData;
|
1234
|
+
};
|
1235
|
+
|
1236
|
+
// ../core/reducer/actions/register-zone.ts
|
1237
|
+
var zoneCache = {};
|
1238
|
+
function registerZoneAction(state, action) {
|
1239
|
+
if (zoneCache[action.zone]) {
|
1240
|
+
return __spreadProps(__spreadValues({}, state), {
|
1241
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
1242
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
755
1243
|
[action.zone]: zoneCache[action.zone]
|
756
1244
|
})
|
757
|
-
})
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
}
|
767
|
-
return __spreadProps(__spreadValues({}, data), { zones: _zones });
|
1245
|
+
}),
|
1246
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1247
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
1248
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
1249
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
1250
|
+
type: "dropzone"
|
1251
|
+
})
|
1252
|
+
})
|
1253
|
+
})
|
1254
|
+
});
|
768
1255
|
}
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
1256
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
1257
|
+
}
|
1258
|
+
function unregisterZoneAction(state, action) {
|
1259
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
1260
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
1261
|
+
if (_zones[action.zone]) {
|
1262
|
+
zoneCache[action.zone] = _zones[action.zone];
|
1263
|
+
delete _zones[action.zone];
|
774
1264
|
}
|
775
|
-
|
1265
|
+
delete zoneIndex[action.zone];
|
1266
|
+
return __spreadProps(__spreadValues({}, state), {
|
1267
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
1268
|
+
zones: _zones
|
1269
|
+
}),
|
1270
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1271
|
+
zones: zoneIndex
|
1272
|
+
})
|
1273
|
+
});
|
776
1274
|
}
|
777
1275
|
|
778
|
-
// ../core/reducer/
|
1276
|
+
// ../core/reducer/actions/set-data.ts
|
779
1277
|
init_react_import();
|
780
|
-
var
|
781
|
-
if (action.
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
return
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
1278
|
+
var setDataAction = (state, action, appStore) => {
|
1279
|
+
if (typeof action.data === "object") {
|
1280
|
+
console.warn(
|
1281
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1282
|
+
);
|
1283
|
+
return walkAppState(
|
1284
|
+
__spreadProps(__spreadValues({}, state), {
|
1285
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1286
|
+
}),
|
1287
|
+
appStore.config
|
1288
|
+
);
|
791
1289
|
}
|
792
|
-
|
793
|
-
|
794
|
-
|
1290
|
+
return walkAppState(
|
1291
|
+
__spreadProps(__spreadValues({}, state), {
|
1292
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1293
|
+
}),
|
1294
|
+
appStore.config
|
1295
|
+
);
|
1296
|
+
};
|
1297
|
+
|
1298
|
+
// ../core/reducer/actions/set-ui.ts
|
1299
|
+
init_react_import();
|
1300
|
+
var setUiAction = (state, action) => {
|
1301
|
+
if (typeof action.ui === "object") {
|
1302
|
+
return __spreadProps(__spreadValues({}, state), {
|
1303
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
795
1304
|
});
|
796
1305
|
}
|
797
|
-
return
|
1306
|
+
return __spreadProps(__spreadValues({}, state), {
|
1307
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
1308
|
+
});
|
1309
|
+
};
|
1310
|
+
|
1311
|
+
// ../core/lib/data/make-state-public.ts
|
1312
|
+
init_react_import();
|
1313
|
+
var makeStatePublic = (state) => {
|
1314
|
+
const { data, ui } = state;
|
1315
|
+
return { data, ui };
|
798
1316
|
};
|
799
1317
|
|
800
1318
|
// ../core/reducer/actions.tsx
|
@@ -814,29 +1332,54 @@ function storeInterceptor(reducer, record, onAction) {
|
|
814
1332
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
815
1333
|
if (record) record(newAppState);
|
816
1334
|
}
|
817
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1335
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
818
1336
|
return newAppState;
|
819
1337
|
};
|
820
1338
|
}
|
821
|
-
var setAction = (state, action) => {
|
822
|
-
if (typeof action.state === "object") {
|
823
|
-
return __spreadValues(__spreadValues({}, state), action.state);
|
824
|
-
}
|
825
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
826
|
-
};
|
827
1339
|
function createReducer({
|
828
|
-
config,
|
829
1340
|
record,
|
830
|
-
onAction
|
1341
|
+
onAction,
|
1342
|
+
appStore
|
831
1343
|
}) {
|
832
1344
|
return storeInterceptor(
|
833
1345
|
(state, action) => {
|
834
|
-
const data = reduceData(state.data, action, config);
|
835
|
-
const ui = reduceUi(state.ui, action);
|
836
1346
|
if (action.type === "set") {
|
837
|
-
return setAction(state, action);
|
1347
|
+
return setAction(state, action, appStore);
|
1348
|
+
}
|
1349
|
+
if (action.type === "insert") {
|
1350
|
+
return insertAction(state, action, appStore);
|
1351
|
+
}
|
1352
|
+
if (action.type === "replace") {
|
1353
|
+
return replaceAction(state, action, appStore);
|
1354
|
+
}
|
1355
|
+
if (action.type === "replaceRoot") {
|
1356
|
+
return replaceRootAction(state, action, appStore);
|
1357
|
+
}
|
1358
|
+
if (action.type === "duplicate") {
|
1359
|
+
return duplicateAction(state, action, appStore);
|
1360
|
+
}
|
1361
|
+
if (action.type === "reorder") {
|
1362
|
+
return reorderAction(state, action, appStore);
|
1363
|
+
}
|
1364
|
+
if (action.type === "move") {
|
1365
|
+
return moveAction(state, action, appStore);
|
1366
|
+
}
|
1367
|
+
if (action.type === "remove") {
|
1368
|
+
return removeAction(state, action, appStore);
|
1369
|
+
}
|
1370
|
+
if (action.type === "registerZone") {
|
1371
|
+
return registerZoneAction(state, action);
|
1372
|
+
}
|
1373
|
+
if (action.type === "unregisterZone") {
|
1374
|
+
return unregisterZoneAction(state, action);
|
838
1375
|
}
|
839
|
-
|
1376
|
+
if (action.type === "setData") {
|
1377
|
+
return setDataAction(state, action, appStore);
|
1378
|
+
}
|
1379
|
+
if (action.type === "setUi") {
|
1380
|
+
return setUiAction(state, action);
|
1381
|
+
}
|
1382
|
+
return state;
|
840
1383
|
},
|
841
1384
|
record,
|
842
1385
|
onAction
|
@@ -856,11 +1399,11 @@ init_react_import();
|
|
856
1399
|
var createStoreImpl = (createState) => {
|
857
1400
|
let state;
|
858
1401
|
const listeners = /* @__PURE__ */ new Set();
|
859
|
-
const setState = (partial,
|
1402
|
+
const setState = (partial, replace) => {
|
860
1403
|
const nextState = typeof partial === "function" ? partial(state) : partial;
|
861
1404
|
if (!Object.is(nextState, state)) {
|
862
1405
|
const previousState = state;
|
863
|
-
state = (
|
1406
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
864
1407
|
listeners.forEach((listener) => listener(state, previousState));
|
865
1408
|
}
|
866
1409
|
};
|
@@ -924,206 +1467,6 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
|
|
924
1467
|
};
|
925
1468
|
var subscribeWithSelector = subscribeWithSelectorImpl;
|
926
1469
|
|
927
|
-
// ../core/lib/resolve-data.ts
|
928
|
-
init_react_import();
|
929
|
-
|
930
|
-
// ../core/lib/resolve-component-data.ts
|
931
|
-
init_react_import();
|
932
|
-
|
933
|
-
// ../core/lib/get-changed.ts
|
934
|
-
init_react_import();
|
935
|
-
var getChanged = (newItem, oldItem) => {
|
936
|
-
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
937
|
-
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
938
|
-
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
939
|
-
return __spreadProps(__spreadValues({}, acc), {
|
940
|
-
[item]: oldItemProps[item] !== newItemProps[item]
|
941
|
-
});
|
942
|
-
}, {}) : {};
|
943
|
-
};
|
944
|
-
|
945
|
-
// ../core/lib/resolve-component-data.ts
|
946
|
-
var cache = { lastChange: {} };
|
947
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
|
948
|
-
const configForItem = config.components[item.type];
|
949
|
-
if (configForItem.resolveData) {
|
950
|
-
const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
|
951
|
-
if (item && item === oldItem) {
|
952
|
-
return resolved;
|
953
|
-
}
|
954
|
-
const changed = getChanged(item, oldItem);
|
955
|
-
if (onResolveStart) {
|
956
|
-
onResolveStart(item);
|
957
|
-
}
|
958
|
-
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
959
|
-
changed,
|
960
|
-
lastData: oldItem,
|
961
|
-
metadata
|
962
|
-
});
|
963
|
-
const resolvedItem = __spreadProps(__spreadValues({}, item), {
|
964
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
965
|
-
});
|
966
|
-
if (Object.keys(readOnly).length) {
|
967
|
-
resolvedItem.readOnly = readOnly;
|
968
|
-
}
|
969
|
-
cache.lastChange[item.props.id] = {
|
970
|
-
item,
|
971
|
-
resolved: resolvedItem
|
972
|
-
};
|
973
|
-
if (onResolveEnd) {
|
974
|
-
onResolveEnd(resolvedItem);
|
975
|
-
}
|
976
|
-
return resolvedItem;
|
977
|
-
}
|
978
|
-
return item;
|
979
|
-
});
|
980
|
-
|
981
|
-
// ../core/lib/apply-dynamic-props.ts
|
982
|
-
init_react_import();
|
983
|
-
var applyDynamicProps = (data, dynamicProps, rootData) => {
|
984
|
-
return __spreadProps(__spreadValues({}, data), {
|
985
|
-
root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
|
986
|
-
content: data.content.map((item) => {
|
987
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
988
|
-
}),
|
989
|
-
zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
|
990
|
-
return __spreadProps(__spreadValues({}, acc), {
|
991
|
-
[zoneKey]: data.zones[zoneKey].map((item) => {
|
992
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
993
|
-
})
|
994
|
-
});
|
995
|
-
}, {})
|
996
|
-
});
|
997
|
-
};
|
998
|
-
|
999
|
-
// ../core/lib/resolve-root-data.ts
|
1000
|
-
init_react_import();
|
1001
|
-
var cache2 = {};
|
1002
|
-
function resolveRootData(data, config, metadata) {
|
1003
|
-
return __async(this, null, function* () {
|
1004
|
-
var _a, _b, _c, _d, _e;
|
1005
|
-
if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
|
1006
|
-
if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
|
1007
|
-
return cache2.lastChange.resolved;
|
1008
|
-
}
|
1009
|
-
const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
|
1010
|
-
const rootWithProps = data.root;
|
1011
|
-
const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
|
1012
|
-
changed,
|
1013
|
-
lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
|
1014
|
-
metadata: metadata || {}
|
1015
|
-
});
|
1016
|
-
cache2.lastChange = {
|
1017
|
-
original: data.root,
|
1018
|
-
resolved: resolvedRoot
|
1019
|
-
};
|
1020
|
-
return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
|
1021
|
-
props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
|
1022
|
-
});
|
1023
|
-
}
|
1024
|
-
return data.root;
|
1025
|
-
});
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
// ../core/lib/flatten-data.ts
|
1029
|
-
init_react_import();
|
1030
|
-
var flattenData = (data) => {
|
1031
|
-
return Object.keys(data.zones || {}).reduce(
|
1032
|
-
(acc, zone) => [...acc, ...data.zones[zone]],
|
1033
|
-
data.content
|
1034
|
-
);
|
1035
|
-
};
|
1036
|
-
|
1037
|
-
// ../core/lib/resolve-data.ts
|
1038
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1039
|
-
var resolveData = (newAppState, appStoreData) => {
|
1040
|
-
const {
|
1041
|
-
state: appState,
|
1042
|
-
config,
|
1043
|
-
dispatch,
|
1044
|
-
resolveDataRuns,
|
1045
|
-
setComponentLoading,
|
1046
|
-
unsetComponentLoading,
|
1047
|
-
metadata,
|
1048
|
-
permissions
|
1049
|
-
} = appStoreData;
|
1050
|
-
const deferredSetStates = {};
|
1051
|
-
const _setComponentLoading = (id, loading, defer = 0) => {
|
1052
|
-
if (deferredSetStates[id]) {
|
1053
|
-
clearTimeout(deferredSetStates[id]);
|
1054
|
-
delete deferredSetStates[id];
|
1055
|
-
}
|
1056
|
-
deferredSetStates[id] = setTimeout(() => {
|
1057
|
-
if (loading) {
|
1058
|
-
setComponentLoading(id);
|
1059
|
-
} else {
|
1060
|
-
unsetComponentLoading(id);
|
1061
|
-
}
|
1062
|
-
delete deferredSetStates[id];
|
1063
|
-
}, defer);
|
1064
|
-
};
|
1065
|
-
const runResolvers = () => __async(void 0, null, function* () {
|
1066
|
-
const newData = newAppState.data;
|
1067
|
-
const flatContent = flattenData(newData).filter(
|
1068
|
-
(item) => {
|
1069
|
-
var _a;
|
1070
|
-
return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
|
1071
|
-
}
|
1072
|
-
);
|
1073
|
-
const applyIfChange = (dynamicDataMap, dynamicRoot) => {
|
1074
|
-
const processed = applyDynamicProps(
|
1075
|
-
__spreadValues({}, appState.data),
|
1076
|
-
dynamicDataMap,
|
1077
|
-
dynamicRoot
|
1078
|
-
);
|
1079
|
-
const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
|
1080
|
-
const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
|
1081
|
-
if (containsChanges) {
|
1082
|
-
dispatch({
|
1083
|
-
type: "set",
|
1084
|
-
state: (prev) => __spreadProps(__spreadValues({}, prev), {
|
1085
|
-
data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
|
1086
|
-
ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
|
1087
|
-
}),
|
1088
|
-
recordHistory: resolveDataRuns > 0
|
1089
|
-
});
|
1090
|
-
}
|
1091
|
-
};
|
1092
|
-
const promises = [];
|
1093
|
-
promises.push(
|
1094
|
-
(() => __async(void 0, null, function* () {
|
1095
|
-
_setComponentLoading("puck-root", true, 50);
|
1096
|
-
const dynamicRoot = yield resolveRootData(newData, config, metadata);
|
1097
|
-
applyIfChange({}, dynamicRoot);
|
1098
|
-
_setComponentLoading("puck-root", false);
|
1099
|
-
}))()
|
1100
|
-
);
|
1101
|
-
flatContent.forEach((item) => {
|
1102
|
-
promises.push(
|
1103
|
-
(() => __async(void 0, null, function* () {
|
1104
|
-
permissions.resolvePermissions({ item }, true);
|
1105
|
-
const dynamicData = yield resolveComponentData(
|
1106
|
-
item,
|
1107
|
-
config,
|
1108
|
-
metadata,
|
1109
|
-
(item2) => {
|
1110
|
-
_setComponentLoading(item2.props.id, true, 50);
|
1111
|
-
},
|
1112
|
-
(item2) => {
|
1113
|
-
deferredSetStates[item2.props.id];
|
1114
|
-
_setComponentLoading(item2.props.id, false);
|
1115
|
-
}
|
1116
|
-
);
|
1117
|
-
const dynamicDataMap = { [item.props.id]: dynamicData };
|
1118
|
-
applyIfChange(dynamicDataMap);
|
1119
|
-
}))()
|
1120
|
-
);
|
1121
|
-
});
|
1122
|
-
yield Promise.all(promises);
|
1123
|
-
});
|
1124
|
-
return runResolvers();
|
1125
|
-
};
|
1126
|
-
|
1127
1470
|
// ../core/store/index.ts
|
1128
1471
|
import { createContext, useContext } from "react";
|
1129
1472
|
|
@@ -1231,7 +1574,7 @@ var createHistorySlice = (set, get) => {
|
|
1231
1574
|
const { dispatch, history } = get();
|
1232
1575
|
dispatch({
|
1233
1576
|
type: "set",
|
1234
|
-
state: ((_a = history.histories[
|
1577
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1235
1578
|
});
|
1236
1579
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1237
1580
|
},
|
@@ -1241,31 +1584,18 @@ var createHistorySlice = (set, get) => {
|
|
1241
1584
|
|
1242
1585
|
// ../core/store/slices/nodes.ts
|
1243
1586
|
init_react_import();
|
1244
|
-
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1245
|
-
import { useEffect as useEffect3 } from "react";
|
1246
|
-
var partialDeepEqual = (newItem, existingItem) => {
|
1247
|
-
const filteredExistingItem = Object.keys(newItem).reduce(
|
1248
|
-
(acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
|
1249
|
-
{}
|
1250
|
-
);
|
1251
|
-
return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
|
1252
|
-
};
|
1253
1587
|
var createNodesSlice = (set, get) => ({
|
1254
1588
|
nodes: {},
|
1255
1589
|
registerNode: (id, node) => {
|
1256
1590
|
const s = get().nodes;
|
1257
|
-
if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
|
1258
|
-
return;
|
1259
|
-
}
|
1260
1591
|
const emptyNode = {
|
1261
1592
|
id,
|
1262
|
-
methods: {
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
element: null
|
1268
|
-
index: -1
|
1593
|
+
methods: {
|
1594
|
+
sync: () => null,
|
1595
|
+
hideOverlay: () => null,
|
1596
|
+
showOverlay: () => null
|
1597
|
+
},
|
1598
|
+
element: null
|
1269
1599
|
};
|
1270
1600
|
const existingNode = s.nodes[id];
|
1271
1601
|
set({
|
@@ -1295,36 +1625,62 @@ var createNodesSlice = (set, get) => ({
|
|
1295
1625
|
|
1296
1626
|
// ../core/store/slices/permissions.ts
|
1297
1627
|
init_react_import();
|
1298
|
-
import { useEffect as
|
1628
|
+
import { useEffect as useEffect3 } from "react";
|
1629
|
+
|
1630
|
+
// ../core/lib/data/flatten-data.ts
|
1631
|
+
init_react_import();
|
1632
|
+
var flattenData = (state, config) => {
|
1633
|
+
const data = [];
|
1634
|
+
walkAppState(
|
1635
|
+
state,
|
1636
|
+
config,
|
1637
|
+
(content) => content,
|
1638
|
+
(item) => {
|
1639
|
+
data.push(item);
|
1640
|
+
return null;
|
1641
|
+
}
|
1642
|
+
);
|
1643
|
+
return data;
|
1644
|
+
};
|
1645
|
+
|
1646
|
+
// ../core/lib/get-changed.ts
|
1647
|
+
init_react_import();
|
1648
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1649
|
+
var getChanged = (newItem, oldItem) => {
|
1650
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1651
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1652
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1653
|
+
return __spreadProps(__spreadValues({}, acc), {
|
1654
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
1655
|
+
});
|
1656
|
+
}, {}) : {};
|
1657
|
+
};
|
1658
|
+
|
1659
|
+
// ../core/store/slices/permissions.ts
|
1299
1660
|
var createPermissionsSlice = (set, get) => {
|
1300
1661
|
const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
|
1301
|
-
const { state, permissions } = get();
|
1302
|
-
const { cache:
|
1662
|
+
const { state, permissions, config } = get();
|
1663
|
+
const { cache: cache2, globalPermissions } = permissions;
|
1303
1664
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1304
1665
|
var _a, _b, _c;
|
1305
|
-
const {
|
1306
|
-
|
1307
|
-
state: appState,
|
1308
|
-
setComponentLoading,
|
1309
|
-
unsetComponentLoading
|
1310
|
-
} = get();
|
1311
|
-
const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
|
1666
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1667
|
+
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1312
1668
|
if (!componentConfig) {
|
1313
1669
|
return;
|
1314
1670
|
}
|
1315
1671
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
1316
1672
|
if (componentConfig.resolvePermissions) {
|
1317
|
-
const changed = getChanged(item2, (_a =
|
1673
|
+
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1318
1674
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1319
|
-
setComponentLoading(item2.props.id);
|
1675
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1320
1676
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1321
1677
|
item2,
|
1322
1678
|
{
|
1323
1679
|
changed,
|
1324
|
-
lastPermissions: ((_b =
|
1680
|
+
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1325
1681
|
permissions: initialPermissions,
|
1326
|
-
appState,
|
1327
|
-
lastData: ((_c =
|
1682
|
+
appState: makeStatePublic(appState),
|
1683
|
+
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1328
1684
|
}
|
1329
1685
|
);
|
1330
1686
|
const latest = get().permissions;
|
@@ -1341,7 +1697,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1341
1697
|
})
|
1342
1698
|
})
|
1343
1699
|
});
|
1344
|
-
|
1700
|
+
clearTimeout2();
|
1345
1701
|
}
|
1346
1702
|
}
|
1347
1703
|
});
|
@@ -1351,7 +1707,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1351
1707
|
// Shim the root data in by conforming to component data shape
|
1352
1708
|
{
|
1353
1709
|
type: "root",
|
1354
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1710
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1355
1711
|
},
|
1356
1712
|
force2
|
1357
1713
|
);
|
@@ -1360,14 +1716,13 @@ var createPermissionsSlice = (set, get) => {
|
|
1360
1716
|
if (item) {
|
1361
1717
|
yield resolveDataForItem(item, force);
|
1362
1718
|
} else if (type) {
|
1363
|
-
flattenData(state
|
1719
|
+
flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
1364
1720
|
yield resolveDataForItem(item2, force);
|
1365
1721
|
}));
|
1366
1722
|
} else if (root) {
|
1367
1723
|
resolveDataForRoot(force);
|
1368
1724
|
} else {
|
1369
|
-
|
1370
|
-
flattenData(state.data).map((item2) => __async(void 0, null, function* () {
|
1725
|
+
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1371
1726
|
yield resolveDataForItem(item2, force);
|
1372
1727
|
}));
|
1373
1728
|
}
|
@@ -1397,7 +1752,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1397
1752
|
} else if (root) {
|
1398
1753
|
const rootConfig = config.root;
|
1399
1754
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1400
|
-
const resolvedForItem = resolvedPermissions["
|
1755
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1401
1756
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1402
1757
|
}
|
1403
1758
|
return globalPermissions;
|
@@ -1409,16 +1764,97 @@ var createPermissionsSlice = (set, get) => {
|
|
1409
1764
|
|
1410
1765
|
// ../core/store/slices/fields.ts
|
1411
1766
|
init_react_import();
|
1412
|
-
import { useCallback, useEffect as
|
1413
|
-
var
|
1767
|
+
import { useCallback, useEffect as useEffect4 } from "react";
|
1768
|
+
var createFieldsSlice = (_set, _get) => {
|
1414
1769
|
return {
|
1415
1770
|
fields: {},
|
1416
1771
|
loading: false,
|
1417
|
-
lastResolvedData: {}
|
1772
|
+
lastResolvedData: {},
|
1773
|
+
id: void 0
|
1418
1774
|
};
|
1419
1775
|
};
|
1420
1776
|
|
1421
|
-
// ../core/
|
1777
|
+
// ../core/lib/resolve-component-data.ts
|
1778
|
+
init_react_import();
|
1779
|
+
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1780
|
+
var cache = { lastChange: {} };
|
1781
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
1782
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1783
|
+
const resolvedItem = __spreadValues({}, item);
|
1784
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
1785
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1786
|
+
if (shouldRunResolver) {
|
1787
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1788
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
1789
|
+
return { node: resolved, didChange: false };
|
1790
|
+
}
|
1791
|
+
const changed = getChanged(item, oldItem);
|
1792
|
+
if (onResolveStart) {
|
1793
|
+
onResolveStart(item);
|
1794
|
+
}
|
1795
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1796
|
+
changed,
|
1797
|
+
lastData: oldItem,
|
1798
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1799
|
+
trigger
|
1800
|
+
});
|
1801
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
1802
|
+
if (Object.keys(readOnly).length) {
|
1803
|
+
resolvedItem.readOnly = readOnly;
|
1804
|
+
}
|
1805
|
+
}
|
1806
|
+
let itemWithResolvedChildren = yield mapSlots(
|
1807
|
+
resolvedItem,
|
1808
|
+
(content) => __async(void 0, null, function* () {
|
1809
|
+
return yield Promise.all(
|
1810
|
+
content.map(
|
1811
|
+
(childItem) => __async(void 0, null, function* () {
|
1812
|
+
return (yield resolveComponentData(
|
1813
|
+
childItem,
|
1814
|
+
config,
|
1815
|
+
metadata,
|
1816
|
+
onResolveStart,
|
1817
|
+
onResolveEnd,
|
1818
|
+
trigger
|
1819
|
+
)).node;
|
1820
|
+
})
|
1821
|
+
)
|
1822
|
+
);
|
1823
|
+
}),
|
1824
|
+
config
|
1825
|
+
);
|
1826
|
+
if (shouldRunResolver && onResolveEnd) {
|
1827
|
+
onResolveEnd(resolvedItem);
|
1828
|
+
}
|
1829
|
+
cache.lastChange[id] = {
|
1830
|
+
item,
|
1831
|
+
resolved: itemWithResolvedChildren
|
1832
|
+
};
|
1833
|
+
return {
|
1834
|
+
node: itemWithResolvedChildren,
|
1835
|
+
didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
|
1836
|
+
};
|
1837
|
+
});
|
1838
|
+
|
1839
|
+
// ../core/lib/data/to-root.ts
|
1840
|
+
init_react_import();
|
1841
|
+
var toRoot = (item) => {
|
1842
|
+
if ("type" in item && item.type !== "root") {
|
1843
|
+
throw new Error("Converting non-root item to root.");
|
1844
|
+
}
|
1845
|
+
const { readOnly } = item;
|
1846
|
+
if (item.props) {
|
1847
|
+
if ("id" in item.props) {
|
1848
|
+
const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
|
1849
|
+
return { props, readOnly };
|
1850
|
+
}
|
1851
|
+
return { props: item.props, readOnly };
|
1852
|
+
}
|
1853
|
+
return { props: {}, readOnly };
|
1854
|
+
};
|
1855
|
+
|
1856
|
+
// ../core/store/default-app-state.ts
|
1857
|
+
init_react_import();
|
1422
1858
|
var defaultAppState = {
|
1423
1859
|
data: { content: [], root: {}, zones: {} },
|
1424
1860
|
ui: {
|
@@ -1438,92 +1874,188 @@ var defaultAppState = {
|
|
1438
1874
|
controlsVisible: true
|
1439
1875
|
},
|
1440
1876
|
field: { focus: null }
|
1877
|
+
},
|
1878
|
+
indexes: {
|
1879
|
+
nodes: {},
|
1880
|
+
zones: {}
|
1441
1881
|
}
|
1442
1882
|
};
|
1883
|
+
|
1884
|
+
// ../core/store/index.ts
|
1443
1885
|
var defaultPageFields = {
|
1444
1886
|
title: { type: "text" }
|
1445
1887
|
};
|
1446
1888
|
var createAppStore = (initialAppStore) => create()(
|
1447
|
-
subscribeWithSelector((set, get) =>
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
})
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1889
|
+
subscribeWithSelector((set, get) => {
|
1890
|
+
var _a, _b;
|
1891
|
+
return __spreadProps(__spreadValues({
|
1892
|
+
state: defaultAppState,
|
1893
|
+
config: { components: {} },
|
1894
|
+
componentState: {},
|
1895
|
+
plugins: [],
|
1896
|
+
overrides: {},
|
1897
|
+
viewports: defaultViewports,
|
1898
|
+
zoomConfig: {
|
1899
|
+
autoZoom: 1,
|
1900
|
+
rootHeight: 0,
|
1901
|
+
zoom: 1
|
1902
|
+
},
|
1903
|
+
status: "LOADING",
|
1904
|
+
iframe: {},
|
1905
|
+
metadata: {}
|
1906
|
+
}, initialAppStore), {
|
1907
|
+
fields: createFieldsSlice(set, get),
|
1908
|
+
history: createHistorySlice(set, get),
|
1909
|
+
nodes: createNodesSlice(set, get),
|
1910
|
+
permissions: createPermissionsSlice(set, get),
|
1911
|
+
getComponentConfig: (type) => {
|
1912
|
+
var _a2;
|
1913
|
+
const { config, selectedItem } = get();
|
1914
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1915
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1916
|
+
},
|
1917
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1918
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1919
|
+
initialAppStore.state
|
1920
|
+
) : null,
|
1921
|
+
dispatch: (action) => set((s) => {
|
1922
|
+
var _a2, _b2;
|
1923
|
+
const { record } = get().history;
|
1924
|
+
const dispatch = createReducer({
|
1925
|
+
record,
|
1926
|
+
appStore: s
|
1927
|
+
});
|
1928
|
+
const state = dispatch(s.state, action);
|
1929
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1930
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1931
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1932
|
+
}),
|
1933
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1934
|
+
setStatus: (status) => set({ status }),
|
1935
|
+
setComponentState: (componentState) => set({ componentState }),
|
1936
|
+
pendingLoadTimeouts: {},
|
1937
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1938
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1939
|
+
const loadId = generateId();
|
1940
|
+
const setLoading = () => {
|
1941
|
+
var _a2;
|
1942
|
+
const { componentState } = get();
|
1943
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1944
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1945
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1946
|
+
})
|
1947
|
+
}));
|
1948
|
+
};
|
1949
|
+
const unsetLoading = () => {
|
1950
|
+
var _a2;
|
1951
|
+
const { componentState } = get();
|
1952
|
+
clearTimeout(timeout);
|
1953
|
+
delete pendingLoadTimeouts[loadId];
|
1954
|
+
set({ pendingLoadTimeouts });
|
1955
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1956
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1957
|
+
loadingCount: Math.max(
|
1958
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1959
|
+
0
|
1960
|
+
)
|
1961
|
+
})
|
1962
|
+
}));
|
1963
|
+
};
|
1964
|
+
const timeout = setTimeout(() => {
|
1965
|
+
if (loading) {
|
1966
|
+
setLoading();
|
1967
|
+
} else {
|
1968
|
+
unsetLoading();
|
1969
|
+
}
|
1970
|
+
delete pendingLoadTimeouts[loadId];
|
1971
|
+
set({ pendingLoadTimeouts });
|
1972
|
+
}, defer);
|
1973
|
+
set({
|
1974
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1975
|
+
[id]: timeout
|
1976
|
+
})
|
1977
|
+
});
|
1978
|
+
return unsetLoading;
|
1979
|
+
},
|
1980
|
+
unsetComponentLoading: (id) => {
|
1981
|
+
const { setComponentLoading } = get();
|
1982
|
+
setComponentLoading(id, false);
|
1983
|
+
},
|
1984
|
+
// Helper
|
1985
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1986
|
+
const dispatch = createReducer({
|
1987
|
+
record: () => {
|
1988
|
+
},
|
1989
|
+
appStore: s
|
1990
|
+
});
|
1991
|
+
const state = dispatch(s.state, {
|
1992
|
+
type: "setUi",
|
1993
|
+
ui,
|
1994
|
+
recordHistory
|
1995
|
+
});
|
1996
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1997
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1998
|
+
}),
|
1999
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
2000
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
2001
|
+
const timeouts = {};
|
2002
|
+
return yield resolveComponentData(
|
2003
|
+
componentData,
|
2004
|
+
config,
|
2005
|
+
metadata,
|
2006
|
+
(item) => {
|
2007
|
+
const id = "id" in item.props ? item.props.id : "root";
|
2008
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
2009
|
+
},
|
2010
|
+
(item) => __async(void 0, null, function* () {
|
2011
|
+
const id = "id" in item.props ? item.props.id : "root";
|
2012
|
+
if ("type" in item) {
|
2013
|
+
yield permissions.refreshPermissions({ item });
|
2014
|
+
} else {
|
2015
|
+
yield permissions.refreshPermissions({ root: true });
|
2016
|
+
}
|
2017
|
+
timeouts[id]();
|
2018
|
+
}),
|
2019
|
+
trigger
|
2020
|
+
);
|
2021
|
+
}),
|
2022
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
2023
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
2024
|
+
walkAppState(
|
2025
|
+
state,
|
2026
|
+
config,
|
2027
|
+
(content) => content,
|
2028
|
+
(childItem) => {
|
2029
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
2030
|
+
const { state: state2 } = get();
|
2031
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
2032
|
+
if (node && resolved.didChange) {
|
2033
|
+
if (resolved.node.props.id === "root") {
|
2034
|
+
dispatch({
|
2035
|
+
type: "replaceRoot",
|
2036
|
+
root: toRoot(resolved.node)
|
2037
|
+
});
|
2038
|
+
} else {
|
2039
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
2040
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
2041
|
+
const index = parentZone.contentIds.indexOf(
|
2042
|
+
resolved.node.props.id
|
2043
|
+
);
|
2044
|
+
dispatch({
|
2045
|
+
type: "replace",
|
2046
|
+
data: resolved.node,
|
2047
|
+
destinationIndex: index,
|
2048
|
+
destinationZone: zoneCompound
|
2049
|
+
});
|
2050
|
+
}
|
2051
|
+
}
|
2052
|
+
});
|
2053
|
+
return childItem;
|
2054
|
+
}
|
2055
|
+
);
|
2056
|
+
})
|
2057
|
+
});
|
2058
|
+
})
|
1527
2059
|
);
|
1528
2060
|
var appStoreContext = createContext(createAppStore());
|
1529
2061
|
function useAppStore(selector) {
|
@@ -1543,12 +2075,12 @@ var useBreadcrumbs = (renderCount) => {
|
|
1543
2075
|
const config = useAppStore((s) => s.config);
|
1544
2076
|
const path = useAppStore((s) => {
|
1545
2077
|
var _a;
|
1546
|
-
return (_a = s.
|
2078
|
+
return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
|
1547
2079
|
});
|
1548
2080
|
const appStore = useAppStoreApi();
|
1549
2081
|
return useMemo(() => {
|
1550
2082
|
const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
|
1551
|
-
var _a, _b;
|
2083
|
+
var _a, _b, _c;
|
1552
2084
|
const [componentId] = zoneCompound.split(":");
|
1553
2085
|
if (componentId === "root") {
|
1554
2086
|
return {
|
@@ -1556,12 +2088,15 @@ var useBreadcrumbs = (renderCount) => {
|
|
1556
2088
|
selector: null
|
1557
2089
|
};
|
1558
2090
|
}
|
1559
|
-
const node = appStore.getState().
|
1560
|
-
const
|
2091
|
+
const node = appStore.getState().state.indexes.nodes[componentId];
|
2092
|
+
const parentId = node.path[node.path.length - 1];
|
2093
|
+
const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
|
2094
|
+
const index = contentIds.indexOf(componentId);
|
2095
|
+
const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
|
1561
2096
|
return {
|
1562
2097
|
label,
|
1563
2098
|
selector: node ? {
|
1564
|
-
index
|
2099
|
+
index,
|
1565
2100
|
zone: node.path[node.path.length - 1]
|
1566
2101
|
} : null
|
1567
2102
|
};
|
@@ -1582,6 +2117,12 @@ init_react_import();
|
|
1582
2117
|
// ../core/lib/filter.ts
|
1583
2118
|
init_react_import();
|
1584
2119
|
|
2120
|
+
// ../core/lib/data/reorder.ts
|
2121
|
+
init_react_import();
|
2122
|
+
|
2123
|
+
// ../core/lib/data/replace.ts
|
2124
|
+
init_react_import();
|
2125
|
+
|
1585
2126
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
1586
2127
|
init_react_import();
|
1587
2128
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
@@ -1763,17 +2304,39 @@ var usePuck = createUsePuck();
|
|
1763
2304
|
var HeadingAnalyzer = () => {
|
1764
2305
|
const data = usePuck((s) => s.appState.data);
|
1765
2306
|
const [hierarchy, setHierarchy] = useState([]);
|
1766
|
-
|
2307
|
+
useEffect5(() => {
|
1767
2308
|
const frame = getFrame();
|
1768
|
-
|
1769
|
-
|
1770
|
-
setHierarchy(buildHierarchy(entry));
|
1771
|
-
const observer = new MutationObserver(() => {
|
2309
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2310
|
+
const createHierarchy = () => {
|
1772
2311
|
setHierarchy(buildHierarchy(entry));
|
2312
|
+
};
|
2313
|
+
const entryObserver = new MutationObserver(() => {
|
2314
|
+
createHierarchy();
|
2315
|
+
});
|
2316
|
+
const frameObserver = new MutationObserver(() => {
|
2317
|
+
entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2318
|
+
if (entry) {
|
2319
|
+
registerEntryObserver();
|
2320
|
+
frameObserver.disconnect();
|
2321
|
+
}
|
1773
2322
|
});
|
1774
|
-
|
2323
|
+
const registerEntryObserver = () => {
|
2324
|
+
if (!entry) return;
|
2325
|
+
entryObserver.observe(entry, { subtree: true, childList: true });
|
2326
|
+
};
|
2327
|
+
const registerFrameObserver = () => {
|
2328
|
+
if (!frame) return;
|
2329
|
+
frameObserver.observe(frame, { subtree: true, childList: true });
|
2330
|
+
};
|
2331
|
+
if (entry) {
|
2332
|
+
createHierarchy();
|
2333
|
+
registerEntryObserver();
|
2334
|
+
} else {
|
2335
|
+
registerFrameObserver();
|
2336
|
+
}
|
1775
2337
|
return () => {
|
1776
|
-
|
2338
|
+
entryObserver.disconnect();
|
2339
|
+
frameObserver.disconnect();
|
1777
2340
|
};
|
1778
2341
|
}, [data]);
|
1779
2342
|
return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [
|