@measured/puck-plugin-heading-analyzer 0.19.0-canary.c33636f → 0.19.0-canary.cb4b6ee5
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 +1236 -673
- package/dist/index.mjs +1229 -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,336 @@ 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 remove = (list, index) => {
|
400
|
-
const result = Array.from(list);
|
401
|
-
result.splice(index, 1);
|
402
|
-
return result;
|
403
|
-
};
|
404
526
|
|
405
|
-
// ../core/lib/
|
527
|
+
// ../core/lib/data/default-slots.ts
|
406
528
|
init_react_import();
|
407
|
-
var
|
408
|
-
|
409
|
-
|
529
|
+
var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
530
|
+
(acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
|
531
|
+
value
|
532
|
+
);
|
533
|
+
|
534
|
+
// ../core/lib/data/map-slots.ts
|
535
|
+
var isPromise = (v) => !!v && typeof v.then === "function";
|
536
|
+
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
537
|
+
var containsPromise = (arr) => arr.some(isPromise);
|
538
|
+
var walkField = ({
|
539
|
+
value,
|
540
|
+
fields,
|
541
|
+
map,
|
542
|
+
propKey = "",
|
543
|
+
propPath = "",
|
544
|
+
id = "",
|
545
|
+
config,
|
546
|
+
recurseSlots = false
|
547
|
+
}) => {
|
548
|
+
var _a, _b, _c;
|
549
|
+
if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
|
550
|
+
const content = value || [];
|
551
|
+
const mappedContent = recurseSlots ? content.map((el) => {
|
552
|
+
var _a2;
|
553
|
+
const componentConfig = config.components[el.type];
|
554
|
+
if (!componentConfig) {
|
555
|
+
throw new Error(`Could not find component config for ${el.type}`);
|
556
|
+
}
|
557
|
+
const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
|
558
|
+
return walkField({
|
559
|
+
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
560
|
+
fields: fields2,
|
561
|
+
map,
|
562
|
+
id: el.props.id,
|
563
|
+
config,
|
564
|
+
recurseSlots
|
565
|
+
});
|
566
|
+
}) : content;
|
567
|
+
if (containsPromise(mappedContent)) {
|
568
|
+
return Promise.all(mappedContent);
|
569
|
+
}
|
570
|
+
return map(mappedContent, id, propPath, fields[propKey], propPath);
|
410
571
|
}
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
572
|
+
if (value && typeof value === "object") {
|
573
|
+
if (Array.isArray(value)) {
|
574
|
+
const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
|
575
|
+
if (!arrayFields) return value;
|
576
|
+
const newValue = value.map(
|
577
|
+
(el, idx) => walkField({
|
578
|
+
value: el,
|
579
|
+
fields: arrayFields,
|
580
|
+
map,
|
581
|
+
propKey,
|
582
|
+
propPath: `${propPath}[${idx}]`,
|
583
|
+
id,
|
584
|
+
config,
|
585
|
+
recurseSlots
|
586
|
+
})
|
587
|
+
);
|
588
|
+
if (containsPromise(newValue)) {
|
589
|
+
return Promise.all(newValue);
|
590
|
+
}
|
591
|
+
return newValue;
|
592
|
+
} else if ("$$typeof" in value) {
|
593
|
+
return value;
|
594
|
+
} else {
|
595
|
+
const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
|
596
|
+
return walkObject({
|
597
|
+
value,
|
598
|
+
fields: objectFields,
|
599
|
+
map,
|
600
|
+
id,
|
601
|
+
getPropPath: (k) => `${propPath}.${k}`,
|
602
|
+
config,
|
603
|
+
recurseSlots
|
604
|
+
});
|
605
|
+
}
|
606
|
+
}
|
607
|
+
return value;
|
416
608
|
};
|
609
|
+
var walkObject = ({
|
610
|
+
value,
|
611
|
+
fields,
|
612
|
+
map,
|
613
|
+
id,
|
614
|
+
getPropPath,
|
615
|
+
config,
|
616
|
+
recurseSlots
|
617
|
+
}) => {
|
618
|
+
const newProps = Object.entries(value).map(([k, v]) => {
|
619
|
+
const opts = {
|
620
|
+
value: v,
|
621
|
+
fields,
|
622
|
+
map,
|
623
|
+
propKey: k,
|
624
|
+
propPath: getPropPath(k),
|
625
|
+
id,
|
626
|
+
config,
|
627
|
+
recurseSlots
|
628
|
+
};
|
629
|
+
const newValue = walkField(opts);
|
630
|
+
if (isPromise(newValue)) {
|
631
|
+
return newValue.then((resolvedValue) => ({
|
632
|
+
[k]: resolvedValue
|
633
|
+
}));
|
634
|
+
}
|
635
|
+
return {
|
636
|
+
[k]: newValue
|
637
|
+
};
|
638
|
+
}, {});
|
639
|
+
if (containsPromise(newProps)) {
|
640
|
+
return Promise.all(newProps).then(flatten);
|
641
|
+
}
|
642
|
+
return flatten(newProps);
|
643
|
+
};
|
644
|
+
function mapSlots(item, map, config, recurseSlots = false) {
|
645
|
+
var _a, _b, _c, _d, _e;
|
646
|
+
const itemType = "type" in item ? item.type : "root";
|
647
|
+
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
648
|
+
const newProps = walkObject({
|
649
|
+
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
650
|
+
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
651
|
+
map,
|
652
|
+
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
653
|
+
getPropPath: (k) => k,
|
654
|
+
config,
|
655
|
+
recurseSlots
|
656
|
+
});
|
657
|
+
if (isPromise(newProps)) {
|
658
|
+
return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
|
659
|
+
props: resolvedProps
|
660
|
+
}));
|
661
|
+
}
|
662
|
+
return __spreadProps(__spreadValues({}, item), {
|
663
|
+
props: newProps
|
664
|
+
});
|
665
|
+
}
|
417
666
|
|
418
|
-
// ../core/lib/
|
667
|
+
// ../core/lib/data/flatten-node.ts
|
419
668
|
init_react_import();
|
420
|
-
var
|
421
|
-
const result = Array.from(list);
|
422
|
-
result.splice(index, 1);
|
423
|
-
result.splice(index, 0, newItem);
|
424
|
-
return result;
|
425
|
-
};
|
669
|
+
var import_flat = __toESM(require_flat());
|
426
670
|
|
427
|
-
// ../core/lib/
|
671
|
+
// ../core/lib/data/strip-slots.ts
|
428
672
|
init_react_import();
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
return
|
673
|
+
var stripSlots = (data, config) => {
|
674
|
+
return mapSlots(data, () => null, config);
|
675
|
+
};
|
676
|
+
|
677
|
+
// ../core/lib/data/flatten-node.ts
|
678
|
+
var flattenNode = (node, config) => {
|
679
|
+
return __spreadProps(__spreadValues({}, node), {
|
680
|
+
props: (0, import_flat.flatten)(stripSlots(node, config).props)
|
681
|
+
});
|
682
|
+
};
|
683
|
+
|
684
|
+
// ../core/lib/data/walk-app-state.ts
|
685
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
686
|
+
var _a;
|
687
|
+
let newZones = {};
|
688
|
+
const newZoneIndex = {};
|
689
|
+
const newNodeIndex = {};
|
690
|
+
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
691
|
+
var _a2;
|
692
|
+
const [parentId] = zoneCompound.split(":");
|
693
|
+
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
694
|
+
const [_2, zone] = zoneCompound.split(":");
|
695
|
+
const newZoneCompound = `${newId || parentId}:${zone}`;
|
696
|
+
const newContent2 = mappedContent.map(
|
697
|
+
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
698
|
+
);
|
699
|
+
newZoneIndex[newZoneCompound] = {
|
700
|
+
contentIds: newContent2.map((item) => item.props.id),
|
701
|
+
type: zoneType
|
702
|
+
};
|
703
|
+
return [newZoneCompound, newContent2];
|
704
|
+
};
|
705
|
+
const processRelatedZones = (item, newId, initialPath) => {
|
706
|
+
forRelatedZones(
|
707
|
+
item,
|
708
|
+
state.data,
|
709
|
+
(relatedPath, relatedZoneCompound, relatedContent) => {
|
710
|
+
const [zoneCompound, newContent2] = processContent(
|
711
|
+
relatedPath,
|
712
|
+
relatedZoneCompound,
|
713
|
+
relatedContent,
|
714
|
+
"dropzone",
|
715
|
+
newId
|
716
|
+
);
|
717
|
+
newZones[zoneCompound] = newContent2;
|
718
|
+
},
|
719
|
+
initialPath
|
720
|
+
);
|
721
|
+
};
|
722
|
+
const processItem = (item, path, index) => {
|
723
|
+
const mappedItem = mapNodeOrSkip(item, path, index);
|
724
|
+
if (!mappedItem) return item;
|
725
|
+
const id = mappedItem.props.id;
|
726
|
+
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
727
|
+
mappedItem,
|
728
|
+
(content, parentId2, slotId) => {
|
729
|
+
const zoneCompound = `${parentId2}:${slotId}`;
|
730
|
+
const [_2, newContent2] = processContent(
|
731
|
+
path,
|
732
|
+
zoneCompound,
|
733
|
+
content,
|
734
|
+
"slot",
|
735
|
+
parentId2
|
736
|
+
);
|
737
|
+
return newContent2;
|
738
|
+
},
|
739
|
+
config
|
740
|
+
).props), {
|
741
|
+
id
|
742
|
+
});
|
743
|
+
processRelatedZones(item, id, path);
|
744
|
+
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
745
|
+
const thisZoneCompound = path[path.length - 1];
|
746
|
+
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
747
|
+
newNodeIndex[id] = {
|
748
|
+
data: newItem,
|
749
|
+
flatData: flattenNode(newItem, config),
|
750
|
+
path,
|
751
|
+
parentId,
|
752
|
+
zone
|
753
|
+
};
|
754
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
755
|
+
if (newProps.id === "root") {
|
756
|
+
delete finalData["type"];
|
757
|
+
delete finalData.props["id"];
|
758
|
+
}
|
759
|
+
return finalData;
|
760
|
+
};
|
761
|
+
const zones = state.data.zones || {};
|
762
|
+
const [_, newContent] = processContent(
|
763
|
+
[],
|
764
|
+
rootDroppableId,
|
765
|
+
state.data.content,
|
766
|
+
"root"
|
767
|
+
);
|
768
|
+
const processedContent = newContent;
|
769
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
770
|
+
Object.keys(zones || {}).forEach((zoneCompound) => {
|
771
|
+
const [parentId] = zoneCompound.split(":");
|
772
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
773
|
+
return;
|
774
|
+
}
|
775
|
+
const [_2, newContent2] = processContent(
|
776
|
+
[rootDroppableId],
|
777
|
+
zoneCompound,
|
778
|
+
zones[zoneCompound],
|
779
|
+
"dropzone",
|
780
|
+
parentId
|
781
|
+
);
|
782
|
+
newZones[zoneCompound] = newContent2;
|
783
|
+
}, newZones);
|
784
|
+
const processedRoot = processItem(
|
785
|
+
{
|
786
|
+
type: "root",
|
787
|
+
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
788
|
+
},
|
789
|
+
[],
|
790
|
+
-1
|
791
|
+
);
|
792
|
+
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
793
|
+
props: processedRoot.props
|
794
|
+
});
|
795
|
+
return __spreadProps(__spreadValues({}, state), {
|
796
|
+
data: {
|
797
|
+
root,
|
798
|
+
content: processedContent,
|
799
|
+
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
800
|
+
},
|
801
|
+
indexes: {
|
802
|
+
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
803
|
+
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
804
|
+
}
|
805
|
+
});
|
436
806
|
}
|
437
807
|
|
438
|
-
// ../core/
|
808
|
+
// ../core/reducer/actions/set.ts
|
809
|
+
var setAction = (state, action, appStore) => {
|
810
|
+
if (typeof action.state === "object") {
|
811
|
+
const newState = __spreadValues(__spreadValues({}, state), action.state);
|
812
|
+
if (action.state.indexes) {
|
813
|
+
return newState;
|
814
|
+
}
|
815
|
+
console.warn(
|
816
|
+
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
817
|
+
);
|
818
|
+
return walkAppState(newState, appStore.config);
|
819
|
+
}
|
820
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
821
|
+
};
|
822
|
+
|
823
|
+
// ../core/reducer/actions/insert.ts
|
824
|
+
init_react_import();
|
825
|
+
|
826
|
+
// ../core/lib/data/insert.ts
|
439
827
|
init_react_import();
|
828
|
+
var insert = (list, index, item) => {
|
829
|
+
const result = Array.from(list || []);
|
830
|
+
result.splice(index, 0, item);
|
831
|
+
return result;
|
832
|
+
};
|
440
833
|
|
441
834
|
// ../core/lib/generate-id.ts
|
442
835
|
init_react_import();
|
@@ -500,313 +893,438 @@ var v4_default = v4;
|
|
500
893
|
// ../core/lib/generate-id.ts
|
501
894
|
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
502
895
|
|
503
|
-
// ../core/lib/get-
|
896
|
+
// ../core/lib/data/get-ids-for-parent.ts
|
504
897
|
init_react_import();
|
505
|
-
var
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
510
|
-
return zoneCompound.split(":");
|
511
|
-
}
|
512
|
-
return [rootDroppableId, zoneCompound];
|
898
|
+
var getIdsForParent = (zoneCompound, state) => {
|
899
|
+
const [parentId] = zoneCompound.split(":");
|
900
|
+
const node = state.indexes.nodes[parentId];
|
901
|
+
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
513
902
|
};
|
514
903
|
|
515
|
-
// ../core/lib/
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
904
|
+
// ../core/lib/data/populate-ids.ts
|
905
|
+
init_react_import();
|
906
|
+
|
907
|
+
// ../core/lib/data/walk-tree.ts
|
908
|
+
init_react_import();
|
909
|
+
function walkTree(data, config, callbackFn) {
|
910
|
+
var _a, _b;
|
911
|
+
const walkItem = (item) => {
|
912
|
+
return mapSlots(
|
913
|
+
item,
|
914
|
+
(content, parentId, propName) => {
|
915
|
+
var _a2;
|
916
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
526
917
|
},
|
918
|
+
config,
|
919
|
+
true
|
920
|
+
);
|
921
|
+
};
|
922
|
+
if ("props" in data) {
|
923
|
+
return walkItem(data);
|
924
|
+
}
|
925
|
+
const _data = data;
|
926
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
927
|
+
const mappedContent = _data.content.map(walkItem);
|
928
|
+
return {
|
929
|
+
root: walkItem(_data.root),
|
930
|
+
content: (_b = callbackFn(mappedContent, {
|
931
|
+
parentId: "root",
|
932
|
+
propName: "default-zone"
|
933
|
+
})) != null ? _b : mappedContent,
|
934
|
+
zones: Object.keys(zones).reduce(
|
935
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
936
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
937
|
+
}),
|
527
938
|
{}
|
528
939
|
)
|
529
|
-
}
|
940
|
+
};
|
530
941
|
}
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
942
|
+
|
943
|
+
// ../core/lib/data/populate-ids.ts
|
944
|
+
var populateIds = (data, config, override = false) => {
|
945
|
+
const id = generateId(data.type);
|
946
|
+
return walkTree(
|
947
|
+
__spreadProps(__spreadValues({}, data), {
|
948
|
+
props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
|
949
|
+
}),
|
950
|
+
config,
|
951
|
+
(contents) => contents.map((item) => {
|
952
|
+
const id2 = generateId(item.type);
|
953
|
+
return __spreadProps(__spreadValues({}, item), {
|
954
|
+
props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
|
955
|
+
});
|
956
|
+
})
|
957
|
+
);
|
958
|
+
};
|
959
|
+
|
960
|
+
// ../core/reducer/actions/insert.ts
|
961
|
+
function insertAction(state, action, appStore) {
|
962
|
+
const id = action.id || generateId(action.componentType);
|
963
|
+
const emptyComponentData = populateIds(
|
964
|
+
{
|
965
|
+
type: action.componentType,
|
966
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
967
|
+
id
|
968
|
+
})
|
969
|
+
},
|
970
|
+
appStore.config
|
971
|
+
);
|
972
|
+
const [parentId] = action.destinationZone.split(":");
|
973
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
974
|
+
return walkAppState(
|
975
|
+
state,
|
976
|
+
appStore.config,
|
977
|
+
(content, zoneCompound) => {
|
978
|
+
if (zoneCompound === action.destinationZone) {
|
979
|
+
return insert(
|
980
|
+
content || [],
|
981
|
+
action.destinationIndex,
|
982
|
+
emptyComponentData
|
983
|
+
);
|
538
984
|
}
|
539
|
-
return
|
985
|
+
return content;
|
540
986
|
},
|
541
|
-
{
|
987
|
+
(childItem, path) => {
|
988
|
+
if (childItem.props.id === id || childItem.props.id === parentId) {
|
989
|
+
return childItem;
|
990
|
+
} else if (idsInPath.includes(childItem.props.id)) {
|
991
|
+
return childItem;
|
992
|
+
} else if (path.includes(action.destinationZone)) {
|
993
|
+
return childItem;
|
994
|
+
}
|
995
|
+
return null;
|
996
|
+
}
|
542
997
|
);
|
543
|
-
}
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
998
|
+
}
|
999
|
+
|
1000
|
+
// ../core/reducer/actions/replace.ts
|
1001
|
+
init_react_import();
|
1002
|
+
var replaceAction = (state, action, appStore) => {
|
1003
|
+
const [parentId] = action.destinationZone.split(":");
|
1004
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
1005
|
+
const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
|
1006
|
+
const idChanged = originalId !== action.data.props.id;
|
1007
|
+
if (idChanged) {
|
1008
|
+
throw new Error(
|
1009
|
+
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
1010
|
+
);
|
1011
|
+
}
|
1012
|
+
const data = populateIds(action.data, appStore.config);
|
1013
|
+
return walkAppState(
|
1014
|
+
state,
|
1015
|
+
appStore.config,
|
1016
|
+
(content, zoneCompound) => {
|
1017
|
+
const newContent = [...content];
|
1018
|
+
if (zoneCompound === action.destinationZone) {
|
1019
|
+
newContent[action.destinationIndex] = data;
|
553
1020
|
}
|
554
|
-
return
|
1021
|
+
return newContent;
|
555
1022
|
},
|
556
|
-
{
|
1023
|
+
(childItem, path) => {
|
1024
|
+
const pathIds = path.map((p) => p.split(":")[0]);
|
1025
|
+
if (childItem.props.id === data.props.id) {
|
1026
|
+
return data;
|
1027
|
+
} else if (childItem.props.id === parentId) {
|
1028
|
+
return childItem;
|
1029
|
+
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
1030
|
+
return childItem;
|
1031
|
+
} else if (pathIds.indexOf(data.props.id) > -1) {
|
1032
|
+
return childItem;
|
1033
|
+
}
|
1034
|
+
return null;
|
1035
|
+
}
|
557
1036
|
);
|
558
1037
|
};
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
1038
|
+
|
1039
|
+
// ../core/reducer/actions/replace-root.ts
|
1040
|
+
init_react_import();
|
1041
|
+
var replaceRootAction = (state, action, appStore) => {
|
1042
|
+
return walkAppState(
|
1043
|
+
state,
|
1044
|
+
appStore.config,
|
1045
|
+
(content) => content,
|
1046
|
+
(childItem) => {
|
1047
|
+
if (childItem.props.id === "root") {
|
1048
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
1049
|
+
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
1050
|
+
readOnly: action.root.readOnly
|
1051
|
+
});
|
1052
|
+
}
|
1053
|
+
return childItem;
|
1054
|
+
}
|
1055
|
+
);
|
566
1056
|
};
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
return __spreadProps(__spreadValues({}, dupeOfDupes), {
|
578
|
-
[key]: zone,
|
579
|
-
[`${newId}:${zoneId}`]: dupedZone
|
580
|
-
});
|
581
|
-
});
|
1057
|
+
|
1058
|
+
// ../core/reducer/actions/duplicate.ts
|
1059
|
+
init_react_import();
|
1060
|
+
|
1061
|
+
// ../core/lib/data/get-item.ts
|
1062
|
+
init_react_import();
|
1063
|
+
function getItem(selector, state) {
|
1064
|
+
var _a, _b;
|
1065
|
+
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
1066
|
+
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
582
1067
|
}
|
583
1068
|
|
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
|
-
)
|
1069
|
+
// ../core/reducer/actions/duplicate.ts
|
1070
|
+
function duplicateAction(state, action, appStore) {
|
1071
|
+
const item = getItem(
|
1072
|
+
{ index: action.sourceIndex, zone: action.sourceZone },
|
1073
|
+
state
|
1074
|
+
);
|
1075
|
+
const idsInPath = getIdsForParent(action.sourceZone, state);
|
1076
|
+
const newItem = __spreadProps(__spreadValues({}, item), {
|
1077
|
+
props: __spreadProps(__spreadValues({}, item.props), {
|
1078
|
+
id: generateId(item.type)
|
600
1079
|
})
|
601
1080
|
});
|
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
|
-
|
1081
|
+
const modified = walkAppState(
|
1082
|
+
state,
|
1083
|
+
appStore.config,
|
1084
|
+
(content, zoneCompound) => {
|
1085
|
+
if (zoneCompound === action.sourceZone) {
|
1086
|
+
return insert(content, action.sourceIndex + 1, item);
|
1087
|
+
}
|
1088
|
+
return content;
|
1089
|
+
},
|
1090
|
+
(childItem, path, index) => {
|
1091
|
+
const zoneCompound = path[path.length - 1];
|
1092
|
+
const parents = path.map((p) => p.split(":")[0]);
|
1093
|
+
if (parents.indexOf(newItem.props.id) > -1) {
|
1094
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
1095
|
+
props: __spreadProps(__spreadValues({}, childItem.props), {
|
1096
|
+
id: generateId(childItem.type)
|
1097
|
+
})
|
1098
|
+
});
|
1099
|
+
}
|
1100
|
+
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
1101
|
+
return newItem;
|
1102
|
+
}
|
1103
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
1104
|
+
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
1105
|
+
return childItem;
|
1106
|
+
}
|
1107
|
+
return null;
|
1108
|
+
}
|
1109
|
+
);
|
1110
|
+
return __spreadProps(__spreadValues({}, modified), {
|
1111
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
1112
|
+
itemSelector: {
|
1113
|
+
index: action.sourceIndex + 1,
|
1114
|
+
zone: action.sourceZone
|
1115
|
+
}
|
627
1116
|
})
|
628
1117
|
});
|
629
1118
|
}
|
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
|
-
});
|
1119
|
+
|
1120
|
+
// ../core/reducer/actions/reorder.ts
|
1121
|
+
init_react_import();
|
1122
|
+
|
1123
|
+
// ../core/reducer/actions/move.ts
|
1124
|
+
init_react_import();
|
1125
|
+
|
1126
|
+
// ../core/lib/data/remove.ts
|
1127
|
+
init_react_import();
|
1128
|
+
var remove = (list, index) => {
|
1129
|
+
const result = Array.from(list);
|
1130
|
+
result.splice(index, 1);
|
1131
|
+
return result;
|
650
1132
|
};
|
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);
|
1133
|
+
|
1134
|
+
// ../core/reducer/actions/move.ts
|
1135
|
+
var moveAction = (state, action, appStore) => {
|
1136
|
+
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
1137
|
+
return state;
|
687
1138
|
}
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
1139
|
+
const item = getItem(
|
1140
|
+
{ zone: action.sourceZone, index: action.sourceIndex },
|
1141
|
+
state
|
1142
|
+
);
|
1143
|
+
if (!item) return state;
|
1144
|
+
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
1145
|
+
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
1146
|
+
return walkAppState(
|
1147
|
+
state,
|
1148
|
+
appStore.config,
|
1149
|
+
(content, zoneCompound) => {
|
1150
|
+
if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
|
1151
|
+
return insert(
|
1152
|
+
remove(content, action.sourceIndex),
|
1153
|
+
action.destinationIndex,
|
1154
|
+
item
|
1155
|
+
);
|
1156
|
+
} else if (zoneCompound === action.sourceZone) {
|
1157
|
+
return remove(content, action.sourceIndex);
|
1158
|
+
} else if (zoneCompound === action.destinationZone) {
|
1159
|
+
return insert(content, action.destinationIndex, item);
|
1160
|
+
}
|
1161
|
+
return content;
|
1162
|
+
},
|
1163
|
+
(childItem, path) => {
|
1164
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
1165
|
+
const [destinationZoneParent] = action.destinationZone.split(":");
|
1166
|
+
const childId = childItem.props.id;
|
1167
|
+
if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
|
1168
|
+
return childItem;
|
1169
|
+
}
|
1170
|
+
return null;
|
702
1171
|
}
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
1172
|
+
);
|
1173
|
+
};
|
1174
|
+
|
1175
|
+
// ../core/reducer/actions/reorder.ts
|
1176
|
+
var reorderAction = (state, action, appStore) => {
|
1177
|
+
return moveAction(
|
1178
|
+
state,
|
1179
|
+
{
|
1180
|
+
type: "move",
|
1181
|
+
sourceIndex: action.sourceIndex,
|
1182
|
+
sourceZone: action.destinationZone,
|
1183
|
+
destinationIndex: action.destinationIndex,
|
1184
|
+
destinationZone: action.destinationZone
|
1185
|
+
},
|
1186
|
+
appStore
|
1187
|
+
);
|
1188
|
+
};
|
1189
|
+
|
1190
|
+
// ../core/reducer/actions/remove.ts
|
1191
|
+
init_react_import();
|
1192
|
+
var removeAction = (state, action, appStore) => {
|
1193
|
+
const item = getItem({ index: action.index, zone: action.zone }, state);
|
1194
|
+
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
1195
|
+
(acc, [nodeId, nodeData]) => {
|
1196
|
+
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
1197
|
+
if (pathIds.includes(item.props.id)) {
|
1198
|
+
return [...acc, nodeId];
|
1199
|
+
}
|
1200
|
+
return acc;
|
1201
|
+
},
|
1202
|
+
[item.props.id]
|
1203
|
+
);
|
1204
|
+
const newState = walkAppState(
|
1205
|
+
state,
|
1206
|
+
appStore.config,
|
1207
|
+
(content, zoneCompound) => {
|
1208
|
+
if (zoneCompound === action.zone) {
|
1209
|
+
return remove(content, action.index);
|
1210
|
+
}
|
1211
|
+
return content;
|
714
1212
|
}
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
newData.zones[action.sourceZone],
|
721
|
-
action.sourceIndex
|
722
|
-
)
|
723
|
-
})
|
724
|
-
});
|
1213
|
+
);
|
1214
|
+
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
1215
|
+
const parentId = zoneCompound.split(":")[0];
|
1216
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
1217
|
+
delete newState.data.zones[zoneCompound];
|
725
1218
|
}
|
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
|
-
});
|
1219
|
+
});
|
1220
|
+
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
1221
|
+
const parentId = zoneCompound.split(":")[0];
|
1222
|
+
if (nodesToDelete.includes(parentId)) {
|
1223
|
+
delete newState.indexes.zones[zoneCompound];
|
753
1224
|
}
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
1225
|
+
});
|
1226
|
+
nodesToDelete.forEach((id) => {
|
1227
|
+
delete newState.indexes.nodes[id];
|
1228
|
+
});
|
1229
|
+
return newState;
|
1230
|
+
};
|
1231
|
+
|
1232
|
+
// ../core/reducer/actions/register-zone.ts
|
1233
|
+
init_react_import();
|
1234
|
+
|
1235
|
+
// ../core/lib/data/setup-zone.ts
|
1236
|
+
init_react_import();
|
1237
|
+
var setupZone = (data, zoneKey) => {
|
1238
|
+
if (zoneKey === rootDroppableId) {
|
1239
|
+
return data;
|
762
1240
|
}
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
1241
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
1242
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
1243
|
+
});
|
1244
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
1245
|
+
return newData;
|
1246
|
+
};
|
1247
|
+
|
1248
|
+
// ../core/reducer/actions/register-zone.ts
|
1249
|
+
var zoneCache = {};
|
1250
|
+
function registerZoneAction(state, action) {
|
1251
|
+
if (zoneCache[action.zone]) {
|
1252
|
+
return __spreadProps(__spreadValues({}, state), {
|
1253
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
1254
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
767
1255
|
[action.zone]: zoneCache[action.zone]
|
768
1256
|
})
|
769
|
-
})
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
}
|
779
|
-
return __spreadProps(__spreadValues({}, data), { zones: _zones });
|
1257
|
+
}),
|
1258
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1259
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
1260
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
1261
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
1262
|
+
type: "dropzone"
|
1263
|
+
})
|
1264
|
+
})
|
1265
|
+
})
|
1266
|
+
});
|
780
1267
|
}
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
1268
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
1269
|
+
}
|
1270
|
+
function unregisterZoneAction(state, action) {
|
1271
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
1272
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
1273
|
+
if (_zones[action.zone]) {
|
1274
|
+
zoneCache[action.zone] = _zones[action.zone];
|
1275
|
+
delete _zones[action.zone];
|
786
1276
|
}
|
787
|
-
|
1277
|
+
delete zoneIndex[action.zone];
|
1278
|
+
return __spreadProps(__spreadValues({}, state), {
|
1279
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
1280
|
+
zones: _zones
|
1281
|
+
}),
|
1282
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1283
|
+
zones: zoneIndex
|
1284
|
+
})
|
1285
|
+
});
|
788
1286
|
}
|
789
1287
|
|
790
|
-
// ../core/reducer/
|
1288
|
+
// ../core/reducer/actions/set-data.ts
|
791
1289
|
init_react_import();
|
792
|
-
var
|
793
|
-
if (action.
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
return
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
1290
|
+
var setDataAction = (state, action, appStore) => {
|
1291
|
+
if (typeof action.data === "object") {
|
1292
|
+
console.warn(
|
1293
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1294
|
+
);
|
1295
|
+
return walkAppState(
|
1296
|
+
__spreadProps(__spreadValues({}, state), {
|
1297
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1298
|
+
}),
|
1299
|
+
appStore.config
|
1300
|
+
);
|
803
1301
|
}
|
804
|
-
|
805
|
-
|
806
|
-
|
1302
|
+
return walkAppState(
|
1303
|
+
__spreadProps(__spreadValues({}, state), {
|
1304
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1305
|
+
}),
|
1306
|
+
appStore.config
|
1307
|
+
);
|
1308
|
+
};
|
1309
|
+
|
1310
|
+
// ../core/reducer/actions/set-ui.ts
|
1311
|
+
init_react_import();
|
1312
|
+
var setUiAction = (state, action) => {
|
1313
|
+
if (typeof action.ui === "object") {
|
1314
|
+
return __spreadProps(__spreadValues({}, state), {
|
1315
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
807
1316
|
});
|
808
1317
|
}
|
809
|
-
return
|
1318
|
+
return __spreadProps(__spreadValues({}, state), {
|
1319
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
1320
|
+
});
|
1321
|
+
};
|
1322
|
+
|
1323
|
+
// ../core/lib/data/make-state-public.ts
|
1324
|
+
init_react_import();
|
1325
|
+
var makeStatePublic = (state) => {
|
1326
|
+
const { data, ui } = state;
|
1327
|
+
return { data, ui };
|
810
1328
|
};
|
811
1329
|
|
812
1330
|
// ../core/reducer/actions.tsx
|
@@ -826,29 +1344,54 @@ function storeInterceptor(reducer, record, onAction) {
|
|
826
1344
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
827
1345
|
if (record) record(newAppState);
|
828
1346
|
}
|
829
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1347
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
830
1348
|
return newAppState;
|
831
1349
|
};
|
832
1350
|
}
|
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
1351
|
function createReducer({
|
840
|
-
config,
|
841
1352
|
record,
|
842
|
-
onAction
|
1353
|
+
onAction,
|
1354
|
+
appStore
|
843
1355
|
}) {
|
844
1356
|
return storeInterceptor(
|
845
1357
|
(state, action) => {
|
846
|
-
const data = reduceData(state.data, action, config);
|
847
|
-
const ui = reduceUi(state.ui, action);
|
848
1358
|
if (action.type === "set") {
|
849
|
-
return setAction(state, action);
|
1359
|
+
return setAction(state, action, appStore);
|
1360
|
+
}
|
1361
|
+
if (action.type === "insert") {
|
1362
|
+
return insertAction(state, action, appStore);
|
1363
|
+
}
|
1364
|
+
if (action.type === "replace") {
|
1365
|
+
return replaceAction(state, action, appStore);
|
1366
|
+
}
|
1367
|
+
if (action.type === "replaceRoot") {
|
1368
|
+
return replaceRootAction(state, action, appStore);
|
1369
|
+
}
|
1370
|
+
if (action.type === "duplicate") {
|
1371
|
+
return duplicateAction(state, action, appStore);
|
1372
|
+
}
|
1373
|
+
if (action.type === "reorder") {
|
1374
|
+
return reorderAction(state, action, appStore);
|
1375
|
+
}
|
1376
|
+
if (action.type === "move") {
|
1377
|
+
return moveAction(state, action, appStore);
|
850
1378
|
}
|
851
|
-
|
1379
|
+
if (action.type === "remove") {
|
1380
|
+
return removeAction(state, action, appStore);
|
1381
|
+
}
|
1382
|
+
if (action.type === "registerZone") {
|
1383
|
+
return registerZoneAction(state, action);
|
1384
|
+
}
|
1385
|
+
if (action.type === "unregisterZone") {
|
1386
|
+
return unregisterZoneAction(state, action);
|
1387
|
+
}
|
1388
|
+
if (action.type === "setData") {
|
1389
|
+
return setDataAction(state, action, appStore);
|
1390
|
+
}
|
1391
|
+
if (action.type === "setUi") {
|
1392
|
+
return setUiAction(state, action);
|
1393
|
+
}
|
1394
|
+
return state;
|
852
1395
|
},
|
853
1396
|
record,
|
854
1397
|
onAction
|
@@ -868,11 +1411,11 @@ init_react_import();
|
|
868
1411
|
var createStoreImpl = (createState) => {
|
869
1412
|
let state;
|
870
1413
|
const listeners = /* @__PURE__ */ new Set();
|
871
|
-
const setState = (partial,
|
1414
|
+
const setState = (partial, replace) => {
|
872
1415
|
const nextState = typeof partial === "function" ? partial(state) : partial;
|
873
1416
|
if (!Object.is(nextState, state)) {
|
874
1417
|
const previousState = state;
|
875
|
-
state = (
|
1418
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
876
1419
|
listeners.forEach((listener) => listener(state, previousState));
|
877
1420
|
}
|
878
1421
|
};
|
@@ -936,208 +1479,8 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
|
|
936
1479
|
};
|
937
1480
|
var subscribeWithSelector = subscribeWithSelectorImpl;
|
938
1481
|
|
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
1482
|
// ../core/store/index.ts
|
1140
|
-
var
|
1483
|
+
var import_react9 = require("react");
|
1141
1484
|
|
1142
1485
|
// ../core/store/slices/history.ts
|
1143
1486
|
init_react_import();
|
@@ -1243,7 +1586,7 @@ var createHistorySlice = (set, get) => {
|
|
1243
1586
|
const { dispatch, history } = get();
|
1244
1587
|
dispatch({
|
1245
1588
|
type: "set",
|
1246
|
-
state: ((_a = history.histories[
|
1589
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1247
1590
|
});
|
1248
1591
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1249
1592
|
},
|
@@ -1253,31 +1596,18 @@ var createHistorySlice = (set, get) => {
|
|
1253
1596
|
|
1254
1597
|
// ../core/store/slices/nodes.ts
|
1255
1598
|
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
1599
|
var createNodesSlice = (set, get) => ({
|
1266
1600
|
nodes: {},
|
1267
1601
|
registerNode: (id, node) => {
|
1268
1602
|
const s = get().nodes;
|
1269
|
-
if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
|
1270
|
-
return;
|
1271
|
-
}
|
1272
1603
|
const emptyNode = {
|
1273
1604
|
id,
|
1274
|
-
methods: {
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
element: null
|
1280
|
-
index: -1
|
1605
|
+
methods: {
|
1606
|
+
sync: () => null,
|
1607
|
+
hideOverlay: () => null,
|
1608
|
+
showOverlay: () => null
|
1609
|
+
},
|
1610
|
+
element: null
|
1281
1611
|
};
|
1282
1612
|
const existingNode = s.nodes[id];
|
1283
1613
|
set({
|
@@ -1307,36 +1637,62 @@ var createNodesSlice = (set, get) => ({
|
|
1307
1637
|
|
1308
1638
|
// ../core/store/slices/permissions.ts
|
1309
1639
|
init_react_import();
|
1310
|
-
var
|
1640
|
+
var import_react7 = require("react");
|
1641
|
+
|
1642
|
+
// ../core/lib/data/flatten-data.ts
|
1643
|
+
init_react_import();
|
1644
|
+
var flattenData = (state, config) => {
|
1645
|
+
const data = [];
|
1646
|
+
walkAppState(
|
1647
|
+
state,
|
1648
|
+
config,
|
1649
|
+
(content) => content,
|
1650
|
+
(item) => {
|
1651
|
+
data.push(item);
|
1652
|
+
return null;
|
1653
|
+
}
|
1654
|
+
);
|
1655
|
+
return data;
|
1656
|
+
};
|
1657
|
+
|
1658
|
+
// ../core/lib/get-changed.ts
|
1659
|
+
init_react_import();
|
1660
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1661
|
+
var getChanged = (newItem, oldItem) => {
|
1662
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1663
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1664
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1665
|
+
return __spreadProps(__spreadValues({}, acc), {
|
1666
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
1667
|
+
});
|
1668
|
+
}, {}) : {};
|
1669
|
+
};
|
1670
|
+
|
1671
|
+
// ../core/store/slices/permissions.ts
|
1311
1672
|
var createPermissionsSlice = (set, get) => {
|
1312
1673
|
const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
|
1313
|
-
const { state, permissions } = get();
|
1314
|
-
const { cache:
|
1674
|
+
const { state, permissions, config } = get();
|
1675
|
+
const { cache: cache2, globalPermissions } = permissions;
|
1315
1676
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1316
1677
|
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];
|
1678
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1679
|
+
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1324
1680
|
if (!componentConfig) {
|
1325
1681
|
return;
|
1326
1682
|
}
|
1327
1683
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
1328
1684
|
if (componentConfig.resolvePermissions) {
|
1329
|
-
const changed = getChanged(item2, (_a =
|
1685
|
+
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1330
1686
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1331
|
-
setComponentLoading(item2.props.id);
|
1687
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1332
1688
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1333
1689
|
item2,
|
1334
1690
|
{
|
1335
1691
|
changed,
|
1336
|
-
lastPermissions: ((_b =
|
1692
|
+
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1337
1693
|
permissions: initialPermissions,
|
1338
|
-
appState,
|
1339
|
-
lastData: ((_c =
|
1694
|
+
appState: makeStatePublic(appState),
|
1695
|
+
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1340
1696
|
}
|
1341
1697
|
);
|
1342
1698
|
const latest = get().permissions;
|
@@ -1353,7 +1709,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1353
1709
|
})
|
1354
1710
|
})
|
1355
1711
|
});
|
1356
|
-
|
1712
|
+
clearTimeout2();
|
1357
1713
|
}
|
1358
1714
|
}
|
1359
1715
|
});
|
@@ -1363,7 +1719,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1363
1719
|
// Shim the root data in by conforming to component data shape
|
1364
1720
|
{
|
1365
1721
|
type: "root",
|
1366
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1722
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1367
1723
|
},
|
1368
1724
|
force2
|
1369
1725
|
);
|
@@ -1372,14 +1728,13 @@ var createPermissionsSlice = (set, get) => {
|
|
1372
1728
|
if (item) {
|
1373
1729
|
yield resolveDataForItem(item, force);
|
1374
1730
|
} else if (type) {
|
1375
|
-
flattenData(state
|
1731
|
+
flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
1376
1732
|
yield resolveDataForItem(item2, force);
|
1377
1733
|
}));
|
1378
1734
|
} else if (root) {
|
1379
1735
|
resolveDataForRoot(force);
|
1380
1736
|
} else {
|
1381
|
-
|
1382
|
-
flattenData(state.data).map((item2) => __async(void 0, null, function* () {
|
1737
|
+
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1383
1738
|
yield resolveDataForItem(item2, force);
|
1384
1739
|
}));
|
1385
1740
|
}
|
@@ -1409,7 +1764,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1409
1764
|
} else if (root) {
|
1410
1765
|
const rootConfig = config.root;
|
1411
1766
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1412
|
-
const resolvedForItem = resolvedPermissions["
|
1767
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1413
1768
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1414
1769
|
}
|
1415
1770
|
return globalPermissions;
|
@@ -1421,16 +1776,97 @@ var createPermissionsSlice = (set, get) => {
|
|
1421
1776
|
|
1422
1777
|
// ../core/store/slices/fields.ts
|
1423
1778
|
init_react_import();
|
1424
|
-
var
|
1425
|
-
var
|
1779
|
+
var import_react8 = require("react");
|
1780
|
+
var createFieldsSlice = (_set, _get) => {
|
1426
1781
|
return {
|
1427
1782
|
fields: {},
|
1428
1783
|
loading: false,
|
1429
|
-
lastResolvedData: {}
|
1784
|
+
lastResolvedData: {},
|
1785
|
+
id: void 0
|
1430
1786
|
};
|
1431
1787
|
};
|
1432
1788
|
|
1433
|
-
// ../core/
|
1789
|
+
// ../core/lib/resolve-component-data.ts
|
1790
|
+
init_react_import();
|
1791
|
+
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1792
|
+
var cache = { lastChange: {} };
|
1793
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
1794
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1795
|
+
const resolvedItem = __spreadValues({}, item);
|
1796
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
1797
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1798
|
+
if (shouldRunResolver) {
|
1799
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1800
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
1801
|
+
return { node: resolved, didChange: false };
|
1802
|
+
}
|
1803
|
+
const changed = getChanged(item, oldItem);
|
1804
|
+
if (onResolveStart) {
|
1805
|
+
onResolveStart(item);
|
1806
|
+
}
|
1807
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1808
|
+
changed,
|
1809
|
+
lastData: oldItem,
|
1810
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1811
|
+
trigger
|
1812
|
+
});
|
1813
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
1814
|
+
if (Object.keys(readOnly).length) {
|
1815
|
+
resolvedItem.readOnly = readOnly;
|
1816
|
+
}
|
1817
|
+
}
|
1818
|
+
let itemWithResolvedChildren = yield mapSlots(
|
1819
|
+
resolvedItem,
|
1820
|
+
(content) => __async(void 0, null, function* () {
|
1821
|
+
return yield Promise.all(
|
1822
|
+
content.map(
|
1823
|
+
(childItem) => __async(void 0, null, function* () {
|
1824
|
+
return (yield resolveComponentData(
|
1825
|
+
childItem,
|
1826
|
+
config,
|
1827
|
+
metadata,
|
1828
|
+
onResolveStart,
|
1829
|
+
onResolveEnd,
|
1830
|
+
trigger
|
1831
|
+
)).node;
|
1832
|
+
})
|
1833
|
+
)
|
1834
|
+
);
|
1835
|
+
}),
|
1836
|
+
config
|
1837
|
+
);
|
1838
|
+
if (shouldRunResolver && onResolveEnd) {
|
1839
|
+
onResolveEnd(resolvedItem);
|
1840
|
+
}
|
1841
|
+
cache.lastChange[id] = {
|
1842
|
+
item,
|
1843
|
+
resolved: itemWithResolvedChildren
|
1844
|
+
};
|
1845
|
+
return {
|
1846
|
+
node: itemWithResolvedChildren,
|
1847
|
+
didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
|
1848
|
+
};
|
1849
|
+
});
|
1850
|
+
|
1851
|
+
// ../core/lib/data/to-root.ts
|
1852
|
+
init_react_import();
|
1853
|
+
var toRoot = (item) => {
|
1854
|
+
if ("type" in item && item.type !== "root") {
|
1855
|
+
throw new Error("Converting non-root item to root.");
|
1856
|
+
}
|
1857
|
+
const { readOnly } = item;
|
1858
|
+
if (item.props) {
|
1859
|
+
if ("id" in item.props) {
|
1860
|
+
const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
|
1861
|
+
return { props, readOnly };
|
1862
|
+
}
|
1863
|
+
return { props: item.props, readOnly };
|
1864
|
+
}
|
1865
|
+
return { props: {}, readOnly };
|
1866
|
+
};
|
1867
|
+
|
1868
|
+
// ../core/store/default-app-state.ts
|
1869
|
+
init_react_import();
|
1434
1870
|
var defaultAppState = {
|
1435
1871
|
data: { content: [], root: {}, zones: {} },
|
1436
1872
|
ui: {
|
@@ -1450,100 +1886,196 @@ var defaultAppState = {
|
|
1450
1886
|
controlsVisible: true
|
1451
1887
|
},
|
1452
1888
|
field: { focus: null }
|
1889
|
+
},
|
1890
|
+
indexes: {
|
1891
|
+
nodes: {},
|
1892
|
+
zones: {}
|
1453
1893
|
}
|
1454
1894
|
};
|
1895
|
+
|
1896
|
+
// ../core/store/index.ts
|
1455
1897
|
var defaultPageFields = {
|
1456
1898
|
title: { type: "text" }
|
1457
1899
|
};
|
1458
1900
|
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
|
-
|
1901
|
+
subscribeWithSelector((set, get) => {
|
1902
|
+
var _a, _b;
|
1903
|
+
return __spreadProps(__spreadValues({
|
1904
|
+
state: defaultAppState,
|
1905
|
+
config: { components: {} },
|
1906
|
+
componentState: {},
|
1907
|
+
plugins: [],
|
1908
|
+
overrides: {},
|
1909
|
+
viewports: defaultViewports,
|
1910
|
+
zoomConfig: {
|
1911
|
+
autoZoom: 1,
|
1912
|
+
rootHeight: 0,
|
1913
|
+
zoom: 1
|
1914
|
+
},
|
1915
|
+
status: "LOADING",
|
1916
|
+
iframe: {},
|
1917
|
+
metadata: {}
|
1918
|
+
}, initialAppStore), {
|
1919
|
+
fields: createFieldsSlice(set, get),
|
1920
|
+
history: createHistorySlice(set, get),
|
1921
|
+
nodes: createNodesSlice(set, get),
|
1922
|
+
permissions: createPermissionsSlice(set, get),
|
1923
|
+
getComponentConfig: (type) => {
|
1924
|
+
var _a2;
|
1925
|
+
const { config, selectedItem } = get();
|
1926
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1927
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1928
|
+
},
|
1929
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1930
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1931
|
+
initialAppStore.state
|
1932
|
+
) : null,
|
1933
|
+
dispatch: (action) => set((s) => {
|
1934
|
+
var _a2, _b2;
|
1935
|
+
const { record } = get().history;
|
1936
|
+
const dispatch = createReducer({
|
1937
|
+
record,
|
1938
|
+
appStore: s
|
1939
|
+
});
|
1940
|
+
const state = dispatch(s.state, action);
|
1941
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1942
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1943
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1944
|
+
}),
|
1945
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1946
|
+
setStatus: (status) => set({ status }),
|
1947
|
+
setComponentState: (componentState) => set({ componentState }),
|
1948
|
+
pendingLoadTimeouts: {},
|
1949
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1950
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1951
|
+
const loadId = generateId();
|
1952
|
+
const setLoading = () => {
|
1953
|
+
var _a2;
|
1954
|
+
const { componentState } = get();
|
1955
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1956
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1957
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1958
|
+
})
|
1959
|
+
}));
|
1960
|
+
};
|
1961
|
+
const unsetLoading = () => {
|
1962
|
+
var _a2;
|
1963
|
+
const { componentState } = get();
|
1964
|
+
clearTimeout(timeout);
|
1965
|
+
delete pendingLoadTimeouts[loadId];
|
1966
|
+
set({ pendingLoadTimeouts });
|
1967
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1968
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1969
|
+
loadingCount: Math.max(
|
1970
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1971
|
+
0
|
1972
|
+
)
|
1973
|
+
})
|
1974
|
+
}));
|
1975
|
+
};
|
1976
|
+
const timeout = setTimeout(() => {
|
1977
|
+
if (loading) {
|
1978
|
+
setLoading();
|
1979
|
+
} else {
|
1980
|
+
unsetLoading();
|
1981
|
+
}
|
1982
|
+
delete pendingLoadTimeouts[loadId];
|
1983
|
+
set({ pendingLoadTimeouts });
|
1984
|
+
}, defer);
|
1985
|
+
set({
|
1986
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1987
|
+
[id]: timeout
|
1988
|
+
})
|
1989
|
+
});
|
1990
|
+
return unsetLoading;
|
1991
|
+
},
|
1992
|
+
unsetComponentLoading: (id) => {
|
1993
|
+
const { setComponentLoading } = get();
|
1994
|
+
setComponentLoading(id, false);
|
1995
|
+
},
|
1996
|
+
// Helper
|
1997
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1998
|
+
const dispatch = createReducer({
|
1999
|
+
record: () => {
|
2000
|
+
},
|
2001
|
+
appStore: s
|
2002
|
+
});
|
2003
|
+
const state = dispatch(s.state, {
|
2004
|
+
type: "setUi",
|
2005
|
+
ui,
|
2006
|
+
recordHistory
|
2007
|
+
});
|
2008
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
2009
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
2010
|
+
}),
|
2011
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
2012
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
2013
|
+
const timeouts = {};
|
2014
|
+
return yield resolveComponentData(
|
2015
|
+
componentData,
|
2016
|
+
config,
|
2017
|
+
metadata,
|
2018
|
+
(item) => {
|
2019
|
+
const id = "id" in item.props ? item.props.id : "root";
|
2020
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
2021
|
+
},
|
2022
|
+
(item) => __async(void 0, null, function* () {
|
2023
|
+
const id = "id" in item.props ? item.props.id : "root";
|
2024
|
+
if ("type" in item) {
|
2025
|
+
yield permissions.refreshPermissions({ item });
|
2026
|
+
} else {
|
2027
|
+
yield permissions.refreshPermissions({ root: true });
|
2028
|
+
}
|
2029
|
+
timeouts[id]();
|
2030
|
+
}),
|
2031
|
+
trigger
|
2032
|
+
);
|
2033
|
+
}),
|
2034
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
2035
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
2036
|
+
walkAppState(
|
2037
|
+
state,
|
2038
|
+
config,
|
2039
|
+
(content) => content,
|
2040
|
+
(childItem) => {
|
2041
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
2042
|
+
const { state: state2 } = get();
|
2043
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
2044
|
+
if (node && resolved.didChange) {
|
2045
|
+
if (resolved.node.props.id === "root") {
|
2046
|
+
dispatch({
|
2047
|
+
type: "replaceRoot",
|
2048
|
+
root: toRoot(resolved.node)
|
2049
|
+
});
|
2050
|
+
} else {
|
2051
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
2052
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
2053
|
+
const index = parentZone.contentIds.indexOf(
|
2054
|
+
resolved.node.props.id
|
2055
|
+
);
|
2056
|
+
dispatch({
|
2057
|
+
type: "replace",
|
2058
|
+
data: resolved.node,
|
2059
|
+
destinationIndex: index,
|
2060
|
+
destinationZone: zoneCompound
|
2061
|
+
});
|
2062
|
+
}
|
2063
|
+
}
|
2064
|
+
});
|
2065
|
+
return childItem;
|
2066
|
+
}
|
2067
|
+
);
|
2068
|
+
})
|
2069
|
+
});
|
2070
|
+
})
|
1539
2071
|
);
|
1540
|
-
var appStoreContext = (0,
|
2072
|
+
var appStoreContext = (0, import_react9.createContext)(createAppStore());
|
1541
2073
|
function useAppStore(selector) {
|
1542
|
-
const context = (0,
|
2074
|
+
const context = (0, import_react9.useContext)(appStoreContext);
|
1543
2075
|
return useStore(context, selector);
|
1544
2076
|
}
|
1545
2077
|
function useAppStoreApi() {
|
1546
|
-
return (0,
|
2078
|
+
return (0, import_react9.useContext)(appStoreContext);
|
1547
2079
|
}
|
1548
2080
|
|
1549
2081
|
// ../core/lib/use-breadcrumbs.ts
|
@@ -1555,12 +2087,12 @@ var useBreadcrumbs = (renderCount) => {
|
|
1555
2087
|
const config = useAppStore((s) => s.config);
|
1556
2088
|
const path = useAppStore((s) => {
|
1557
2089
|
var _a;
|
1558
|
-
return (_a = s.
|
2090
|
+
return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
|
1559
2091
|
});
|
1560
2092
|
const appStore = useAppStoreApi();
|
1561
|
-
return (0,
|
2093
|
+
return (0, import_react10.useMemo)(() => {
|
1562
2094
|
const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
|
1563
|
-
var _a, _b;
|
2095
|
+
var _a, _b, _c;
|
1564
2096
|
const [componentId] = zoneCompound.split(":");
|
1565
2097
|
if (componentId === "root") {
|
1566
2098
|
return {
|
@@ -1568,12 +2100,15 @@ var useBreadcrumbs = (renderCount) => {
|
|
1568
2100
|
selector: null
|
1569
2101
|
};
|
1570
2102
|
}
|
1571
|
-
const node = appStore.getState().
|
1572
|
-
const
|
2103
|
+
const node = appStore.getState().state.indexes.nodes[componentId];
|
2104
|
+
const parentId = node.path[node.path.length - 1];
|
2105
|
+
const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
|
2106
|
+
const index = contentIds.indexOf(componentId);
|
2107
|
+
const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
|
1573
2108
|
return {
|
1574
2109
|
label,
|
1575
2110
|
selector: node ? {
|
1576
|
-
index
|
2111
|
+
index,
|
1577
2112
|
zone: node.path[node.path.length - 1]
|
1578
2113
|
} : null
|
1579
2114
|
};
|
@@ -1594,6 +2129,12 @@ init_react_import();
|
|
1594
2129
|
// ../core/lib/filter.ts
|
1595
2130
|
init_react_import();
|
1596
2131
|
|
2132
|
+
// ../core/lib/data/reorder.ts
|
2133
|
+
init_react_import();
|
2134
|
+
|
2135
|
+
// ../core/lib/data/replace.ts
|
2136
|
+
init_react_import();
|
2137
|
+
|
1597
2138
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
1598
2139
|
init_react_import();
|
1599
2140
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
@@ -1774,18 +2315,40 @@ function buildHierarchy(frame) {
|
|
1774
2315
|
var usePuck = (0, import_puck.createUsePuck)();
|
1775
2316
|
var HeadingAnalyzer = () => {
|
1776
2317
|
const data = usePuck((s) => s.appState.data);
|
1777
|
-
const [hierarchy, setHierarchy] = (0,
|
1778
|
-
(0,
|
2318
|
+
const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
|
2319
|
+
(0, import_react11.useEffect)(() => {
|
1779
2320
|
const frame = getFrame();
|
1780
|
-
|
1781
|
-
|
1782
|
-
setHierarchy(buildHierarchy(entry));
|
1783
|
-
const observer = new MutationObserver(() => {
|
2321
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2322
|
+
const createHierarchy = () => {
|
1784
2323
|
setHierarchy(buildHierarchy(entry));
|
2324
|
+
};
|
2325
|
+
const entryObserver = new MutationObserver(() => {
|
2326
|
+
createHierarchy();
|
2327
|
+
});
|
2328
|
+
const frameObserver = new MutationObserver(() => {
|
2329
|
+
entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2330
|
+
if (entry) {
|
2331
|
+
registerEntryObserver();
|
2332
|
+
frameObserver.disconnect();
|
2333
|
+
}
|
1785
2334
|
});
|
1786
|
-
|
2335
|
+
const registerEntryObserver = () => {
|
2336
|
+
if (!entry) return;
|
2337
|
+
entryObserver.observe(entry, { subtree: true, childList: true });
|
2338
|
+
};
|
2339
|
+
const registerFrameObserver = () => {
|
2340
|
+
if (!frame) return;
|
2341
|
+
frameObserver.observe(frame, { subtree: true, childList: true });
|
2342
|
+
};
|
2343
|
+
if (entry) {
|
2344
|
+
createHierarchy();
|
2345
|
+
registerEntryObserver();
|
2346
|
+
} else {
|
2347
|
+
registerFrameObserver();
|
2348
|
+
}
|
1787
2349
|
return () => {
|
1788
|
-
|
2350
|
+
entryObserver.disconnect();
|
2351
|
+
frameObserver.disconnect();
|
1789
2352
|
};
|
1790
2353
|
}, [data]);
|
1791
2354
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
|