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