@measured/puck-plugin-heading-analyzer 0.19.0-canary.a281c342 → 0.19.0-canary.a6dd529f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +623 -540
- package/dist/index.mjs +623 -540
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -356,123 +356,16 @@ init_react_import();
|
|
356
356
|
// ../core/reducer/index.ts
|
357
357
|
init_react_import();
|
358
358
|
|
359
|
-
// ../core/reducer/
|
359
|
+
// ../core/reducer/actions/set.ts
|
360
360
|
init_react_import();
|
361
361
|
|
362
|
-
// ../core/lib/
|
362
|
+
// ../core/lib/data/walk-tree.ts
|
363
363
|
init_react_import();
|
364
|
-
var insert = (list, index, item) => {
|
365
|
-
const result = Array.from(list || []);
|
366
|
-
result.splice(index, 0, item);
|
367
|
-
return result;
|
368
|
-
};
|
369
|
-
|
370
|
-
// ../core/lib/remove.ts
|
371
|
-
init_react_import();
|
372
|
-
var remove = (list, index) => {
|
373
|
-
const result = Array.from(list);
|
374
|
-
result.splice(index, 1);
|
375
|
-
return result;
|
376
|
-
};
|
377
|
-
|
378
|
-
// ../core/lib/setup-zone.ts
|
379
|
-
init_react_import();
|
380
|
-
|
381
|
-
// ../core/lib/root-droppable-id.ts
|
382
|
-
init_react_import();
|
383
|
-
var rootAreaId = "root";
|
384
|
-
var rootZone = "default-zone";
|
385
|
-
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
386
|
-
|
387
|
-
// ../core/lib/setup-zone.ts
|
388
|
-
var setupZone = (data, zoneKey) => {
|
389
|
-
if (zoneKey === rootDroppableId) {
|
390
|
-
return data;
|
391
|
-
}
|
392
|
-
const newData = __spreadProps(__spreadValues({}, data), {
|
393
|
-
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
394
|
-
});
|
395
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
396
|
-
return newData;
|
397
|
-
};
|
398
|
-
|
399
|
-
// ../core/lib/get-item.ts
|
400
|
-
init_react_import();
|
401
|
-
function getItem(selector, state) {
|
402
|
-
var _a, _b;
|
403
|
-
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
404
|
-
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
405
|
-
}
|
406
|
-
|
407
|
-
// ../core/lib/generate-id.ts
|
408
|
-
init_react_import();
|
409
|
-
|
410
|
-
// ../../node_modules/uuid/dist/esm-node/index.js
|
411
|
-
init_react_import();
|
412
|
-
|
413
|
-
// ../../node_modules/uuid/dist/esm-node/rng.js
|
414
|
-
init_react_import();
|
415
|
-
import crypto from "crypto";
|
416
|
-
var rnds8Pool = new Uint8Array(256);
|
417
|
-
var poolPtr = rnds8Pool.length;
|
418
|
-
function rng() {
|
419
|
-
if (poolPtr > rnds8Pool.length - 16) {
|
420
|
-
crypto.randomFillSync(rnds8Pool);
|
421
|
-
poolPtr = 0;
|
422
|
-
}
|
423
|
-
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
424
|
-
}
|
425
|
-
|
426
|
-
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
427
|
-
init_react_import();
|
428
|
-
var byteToHex = [];
|
429
|
-
for (let i = 0; i < 256; ++i) {
|
430
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
431
|
-
}
|
432
|
-
function unsafeStringify(arr, offset = 0) {
|
433
|
-
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
434
|
-
}
|
435
|
-
|
436
|
-
// ../../node_modules/uuid/dist/esm-node/v4.js
|
437
|
-
init_react_import();
|
438
|
-
|
439
|
-
// ../../node_modules/uuid/dist/esm-node/native.js
|
440
|
-
init_react_import();
|
441
|
-
import crypto2 from "crypto";
|
442
|
-
var native_default = {
|
443
|
-
randomUUID: crypto2.randomUUID
|
444
|
-
};
|
445
|
-
|
446
|
-
// ../../node_modules/uuid/dist/esm-node/v4.js
|
447
|
-
function v4(options, buf, offset) {
|
448
|
-
if (native_default.randomUUID && !buf && !options) {
|
449
|
-
return native_default.randomUUID();
|
450
|
-
}
|
451
|
-
options = options || {};
|
452
|
-
const rnds = options.random || (options.rng || rng)();
|
453
|
-
rnds[6] = rnds[6] & 15 | 64;
|
454
|
-
rnds[8] = rnds[8] & 63 | 128;
|
455
|
-
if (buf) {
|
456
|
-
offset = offset || 0;
|
457
|
-
for (let i = 0; i < 16; ++i) {
|
458
|
-
buf[offset + i] = rnds[i];
|
459
|
-
}
|
460
|
-
return buf;
|
461
|
-
}
|
462
|
-
return unsafeStringify(rnds);
|
463
|
-
}
|
464
|
-
var v4_default = v4;
|
465
|
-
|
466
|
-
// ../core/lib/generate-id.ts
|
467
|
-
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
468
364
|
|
469
|
-
// ../core/lib/
|
365
|
+
// ../core/lib/data/for-each-slot.ts
|
470
366
|
init_react_import();
|
471
367
|
|
472
|
-
// ../core/lib/
|
473
|
-
init_react_import();
|
474
|
-
|
475
|
-
// ../core/lib/is-slot.ts
|
368
|
+
// ../core/lib/data/is-slot.ts
|
476
369
|
init_react_import();
|
477
370
|
var isSlot = (prop) => {
|
478
371
|
var _a, _b;
|
@@ -485,8 +378,8 @@ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
|
485
378
|
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
486
379
|
};
|
487
380
|
|
488
|
-
// ../core/lib/for-each-slot.ts
|
489
|
-
var forEachSlot = (
|
381
|
+
// ../core/lib/data/for-each-slot.ts
|
382
|
+
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
490
383
|
const props = item.props || {};
|
491
384
|
const propKeys = Object.keys(props);
|
492
385
|
for (let i = 0; i < propKeys.length; i++) {
|
@@ -494,23 +387,31 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
|
|
494
387
|
const itemType = "type" in item ? item.type : "root";
|
495
388
|
if (isSlot2(itemType, propKey, props[propKey])) {
|
496
389
|
const content = props[propKey];
|
497
|
-
|
390
|
+
cb(props.id, propKey, content);
|
498
391
|
if (recursive) {
|
499
392
|
content.forEach(
|
500
393
|
(childItem) => __async(void 0, null, function* () {
|
501
|
-
return
|
394
|
+
return forEachSlot(childItem, cb, true, isSlot2);
|
502
395
|
})
|
503
396
|
);
|
504
397
|
}
|
505
398
|
}
|
506
399
|
}
|
507
|
-
}
|
400
|
+
};
|
508
401
|
|
509
|
-
// ../core/lib/for-related-zones.ts
|
402
|
+
// ../core/lib/data/for-related-zones.ts
|
510
403
|
init_react_import();
|
511
404
|
|
512
405
|
// ../core/lib/get-zone-id.ts
|
513
406
|
init_react_import();
|
407
|
+
|
408
|
+
// ../core/lib/root-droppable-id.ts
|
409
|
+
init_react_import();
|
410
|
+
var rootAreaId = "root";
|
411
|
+
var rootZone = "default-zone";
|
412
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
413
|
+
|
414
|
+
// ../core/lib/get-zone-id.ts
|
514
415
|
var getZoneId = (zoneCompound) => {
|
515
416
|
if (!zoneCompound) {
|
516
417
|
return [];
|
@@ -521,19 +422,17 @@ var getZoneId = (zoneCompound) => {
|
|
521
422
|
return [rootDroppableId, zoneCompound];
|
522
423
|
};
|
523
424
|
|
524
|
-
// ../core/lib/for-related-zones.ts
|
425
|
+
// ../core/lib/data/for-related-zones.ts
|
525
426
|
function forRelatedZones(item, data, cb, path = []) {
|
526
427
|
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
527
428
|
const [parentId] = getZoneId(zoneCompound);
|
528
429
|
if (parentId === item.props.id) {
|
529
|
-
const newPath = [...path, zoneCompound];
|
530
|
-
content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
|
531
430
|
cb(path, zoneCompound, content);
|
532
431
|
}
|
533
432
|
});
|
534
433
|
}
|
535
434
|
|
536
|
-
// ../core/lib/strip-slots.ts
|
435
|
+
// ../core/lib/data/strip-slots.ts
|
537
436
|
init_react_import();
|
538
437
|
var stripSlots = (data) => {
|
539
438
|
return __spreadProps(__spreadValues({}, data), {
|
@@ -549,7 +448,7 @@ var stripSlots = (data) => {
|
|
549
448
|
});
|
550
449
|
};
|
551
450
|
|
552
|
-
// ../core/lib/walk-tree.ts
|
451
|
+
// ../core/lib/data/walk-tree.ts
|
553
452
|
function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
554
453
|
var _a;
|
555
454
|
let newZones = {};
|
@@ -591,7 +490,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
591
490
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
592
491
|
if (!mappedItem) return item;
|
593
492
|
const id = mappedItem.props.id;
|
594
|
-
processRelatedZones(item, id, path);
|
595
493
|
const newProps = __spreadValues({}, mappedItem.props);
|
596
494
|
forEachSlot(
|
597
495
|
mappedItem,
|
@@ -609,6 +507,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
609
507
|
false,
|
610
508
|
createIsSlotConfig(config)
|
611
509
|
);
|
510
|
+
processRelatedZones(item, id, path);
|
612
511
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
613
512
|
const thisZoneCompound = path[path.length - 1];
|
614
513
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
@@ -663,7 +562,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
663
562
|
return __spreadProps(__spreadValues({}, state), {
|
664
563
|
data: {
|
665
564
|
root,
|
666
|
-
// root: state.data.root, // TODO changing root causes it's entire subtree to re-render. Let's keep this disabled until the performance issues are resolved in #644.
|
667
565
|
content: processedContent,
|
668
566
|
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
669
567
|
},
|
@@ -674,18 +572,108 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
674
572
|
});
|
675
573
|
}
|
676
574
|
|
677
|
-
// ../core/reducer/
|
678
|
-
var
|
575
|
+
// ../core/reducer/actions/set.ts
|
576
|
+
var setAction = (state, action, appStore) => {
|
577
|
+
if (typeof action.state === "object") {
|
578
|
+
const newState = __spreadValues(__spreadValues({}, state), action.state);
|
579
|
+
if (action.state.indexes) {
|
580
|
+
return newState;
|
581
|
+
}
|
582
|
+
console.warn(
|
583
|
+
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
584
|
+
);
|
585
|
+
return walkTree(newState, appStore.config);
|
586
|
+
}
|
587
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
588
|
+
};
|
589
|
+
|
590
|
+
// ../core/reducer/actions/insert.ts
|
591
|
+
init_react_import();
|
592
|
+
|
593
|
+
// ../core/lib/data/insert.ts
|
594
|
+
init_react_import();
|
595
|
+
var insert = (list, index, item) => {
|
596
|
+
const result = Array.from(list || []);
|
597
|
+
result.splice(index, 0, item);
|
598
|
+
return result;
|
599
|
+
};
|
600
|
+
|
601
|
+
// ../core/lib/generate-id.ts
|
602
|
+
init_react_import();
|
603
|
+
|
604
|
+
// ../../node_modules/uuid/dist/esm-node/index.js
|
605
|
+
init_react_import();
|
606
|
+
|
607
|
+
// ../../node_modules/uuid/dist/esm-node/rng.js
|
608
|
+
init_react_import();
|
609
|
+
import crypto from "crypto";
|
610
|
+
var rnds8Pool = new Uint8Array(256);
|
611
|
+
var poolPtr = rnds8Pool.length;
|
612
|
+
function rng() {
|
613
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
614
|
+
crypto.randomFillSync(rnds8Pool);
|
615
|
+
poolPtr = 0;
|
616
|
+
}
|
617
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
618
|
+
}
|
619
|
+
|
620
|
+
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
621
|
+
init_react_import();
|
622
|
+
var byteToHex = [];
|
623
|
+
for (let i = 0; i < 256; ++i) {
|
624
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
625
|
+
}
|
626
|
+
function unsafeStringify(arr, offset = 0) {
|
627
|
+
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
628
|
+
}
|
629
|
+
|
630
|
+
// ../../node_modules/uuid/dist/esm-node/v4.js
|
631
|
+
init_react_import();
|
632
|
+
|
633
|
+
// ../../node_modules/uuid/dist/esm-node/native.js
|
634
|
+
init_react_import();
|
635
|
+
import crypto2 from "crypto";
|
636
|
+
var native_default = {
|
637
|
+
randomUUID: crypto2.randomUUID
|
638
|
+
};
|
639
|
+
|
640
|
+
// ../../node_modules/uuid/dist/esm-node/v4.js
|
641
|
+
function v4(options, buf, offset) {
|
642
|
+
if (native_default.randomUUID && !buf && !options) {
|
643
|
+
return native_default.randomUUID();
|
644
|
+
}
|
645
|
+
options = options || {};
|
646
|
+
const rnds = options.random || (options.rng || rng)();
|
647
|
+
rnds[6] = rnds[6] & 15 | 64;
|
648
|
+
rnds[8] = rnds[8] & 63 | 128;
|
649
|
+
if (buf) {
|
650
|
+
offset = offset || 0;
|
651
|
+
for (let i = 0; i < 16; ++i) {
|
652
|
+
buf[offset + i] = rnds[i];
|
653
|
+
}
|
654
|
+
return buf;
|
655
|
+
}
|
656
|
+
return unsafeStringify(rnds);
|
657
|
+
}
|
658
|
+
var v4_default = v4;
|
659
|
+
|
660
|
+
// ../core/lib/generate-id.ts
|
661
|
+
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
662
|
+
|
663
|
+
// ../core/lib/data/get-ids-for-parent.ts
|
664
|
+
init_react_import();
|
679
665
|
var getIdsForParent = (zoneCompound, state) => {
|
680
666
|
const [parentId] = zoneCompound.split(":");
|
681
667
|
const node = state.indexes.nodes[parentId];
|
682
668
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
683
669
|
};
|
684
|
-
|
670
|
+
|
671
|
+
// ../core/reducer/actions/insert.ts
|
672
|
+
function insertAction(state, action, appStore) {
|
685
673
|
const id = action.id || generateId(action.componentType);
|
686
674
|
const emptyComponentData = {
|
687
675
|
type: action.componentType,
|
688
|
-
props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
|
676
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
689
677
|
id
|
690
678
|
})
|
691
679
|
};
|
@@ -693,29 +681,164 @@ function insertAction(state, action, config) {
|
|
693
681
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
694
682
|
return walkTree(
|
695
683
|
state,
|
696
|
-
config,
|
684
|
+
appStore.config,
|
685
|
+
(content, zoneCompound) => {
|
686
|
+
if (zoneCompound === action.destinationZone) {
|
687
|
+
return insert(
|
688
|
+
content || [],
|
689
|
+
action.destinationIndex,
|
690
|
+
emptyComponentData
|
691
|
+
);
|
692
|
+
}
|
693
|
+
return content;
|
694
|
+
},
|
695
|
+
(childItem, path) => {
|
696
|
+
if (childItem.props.id === id || childItem.props.id === parentId) {
|
697
|
+
return childItem;
|
698
|
+
} else if (idsInPath.includes(childItem.props.id)) {
|
699
|
+
return childItem;
|
700
|
+
} else if (path.includes(action.destinationZone)) {
|
701
|
+
return childItem;
|
702
|
+
}
|
703
|
+
return null;
|
704
|
+
}
|
705
|
+
);
|
706
|
+
}
|
707
|
+
|
708
|
+
// ../core/reducer/actions/replace.ts
|
709
|
+
init_react_import();
|
710
|
+
var replaceAction = (state, action, appStore) => {
|
711
|
+
const [parentId] = action.destinationZone.split(":");
|
712
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
713
|
+
const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
|
714
|
+
const idChanged = originalId !== action.data.props.id;
|
715
|
+
if (idChanged) {
|
716
|
+
throw new Error(
|
717
|
+
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
718
|
+
);
|
719
|
+
}
|
720
|
+
return walkTree(
|
721
|
+
state,
|
722
|
+
appStore.config,
|
723
|
+
(content, zoneCompound) => {
|
724
|
+
const newContent = [...content];
|
725
|
+
if (zoneCompound === action.destinationZone) {
|
726
|
+
newContent[action.destinationIndex] = action.data;
|
727
|
+
}
|
728
|
+
return newContent;
|
729
|
+
},
|
730
|
+
(childItem, path) => {
|
731
|
+
const pathIds = path.map((p) => p.split(":")[0]);
|
732
|
+
if (childItem.props.id === action.data.props.id) {
|
733
|
+
return action.data;
|
734
|
+
} else if (childItem.props.id === parentId) {
|
735
|
+
return childItem;
|
736
|
+
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
737
|
+
return childItem;
|
738
|
+
} else if (pathIds.indexOf(action.data.props.id) > -1) {
|
739
|
+
return childItem;
|
740
|
+
}
|
741
|
+
return null;
|
742
|
+
}
|
743
|
+
);
|
744
|
+
};
|
745
|
+
|
746
|
+
// ../core/reducer/actions/replace-root.ts
|
747
|
+
init_react_import();
|
748
|
+
var replaceRootAction = (state, action, appStore) => {
|
749
|
+
return walkTree(
|
750
|
+
state,
|
751
|
+
appStore.config,
|
752
|
+
(content) => content,
|
753
|
+
(childItem) => {
|
754
|
+
if (childItem.props.id === "root") {
|
755
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
756
|
+
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
757
|
+
readOnly: action.root.readOnly
|
758
|
+
});
|
759
|
+
}
|
760
|
+
return childItem;
|
761
|
+
}
|
762
|
+
);
|
763
|
+
};
|
764
|
+
|
765
|
+
// ../core/reducer/actions/duplicate.ts
|
766
|
+
init_react_import();
|
767
|
+
|
768
|
+
// ../core/lib/data/get-item.ts
|
769
|
+
init_react_import();
|
770
|
+
function getItem(selector, state) {
|
771
|
+
var _a, _b;
|
772
|
+
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
773
|
+
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
774
|
+
}
|
775
|
+
|
776
|
+
// ../core/reducer/actions/duplicate.ts
|
777
|
+
function duplicateAction(state, action, appStore) {
|
778
|
+
const item = getItem(
|
779
|
+
{ index: action.sourceIndex, zone: action.sourceZone },
|
780
|
+
state
|
781
|
+
);
|
782
|
+
const idsInPath = getIdsForParent(action.sourceZone, state);
|
783
|
+
const newItem = __spreadProps(__spreadValues({}, item), {
|
784
|
+
props: __spreadProps(__spreadValues({}, item.props), {
|
785
|
+
id: generateId(item.type)
|
786
|
+
})
|
787
|
+
});
|
788
|
+
const modified = walkTree(
|
789
|
+
state,
|
790
|
+
appStore.config,
|
697
791
|
(content, zoneCompound) => {
|
698
|
-
if (zoneCompound === action.
|
699
|
-
return insert(
|
700
|
-
content || [],
|
701
|
-
action.destinationIndex,
|
702
|
-
emptyComponentData
|
703
|
-
);
|
792
|
+
if (zoneCompound === action.sourceZone) {
|
793
|
+
return insert(content, action.sourceIndex + 1, item);
|
704
794
|
}
|
705
795
|
return content;
|
706
796
|
},
|
707
|
-
(childItem, path) => {
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
return childItem
|
712
|
-
|
797
|
+
(childItem, path, index) => {
|
798
|
+
const zoneCompound = path[path.length - 1];
|
799
|
+
const parents = path.map((p) => p.split(":")[0]);
|
800
|
+
if (parents.indexOf(newItem.props.id) > -1) {
|
801
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
802
|
+
props: __spreadProps(__spreadValues({}, childItem.props), {
|
803
|
+
id: generateId(childItem.type)
|
804
|
+
})
|
805
|
+
});
|
806
|
+
}
|
807
|
+
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
808
|
+
return newItem;
|
809
|
+
}
|
810
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
811
|
+
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
713
812
|
return childItem;
|
714
813
|
}
|
715
814
|
return null;
|
716
815
|
}
|
717
816
|
);
|
817
|
+
return __spreadProps(__spreadValues({}, modified), {
|
818
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
819
|
+
itemSelector: {
|
820
|
+
index: action.sourceIndex + 1,
|
821
|
+
zone: action.sourceZone
|
822
|
+
}
|
823
|
+
})
|
824
|
+
});
|
718
825
|
}
|
826
|
+
|
827
|
+
// ../core/reducer/actions/reorder.ts
|
828
|
+
init_react_import();
|
829
|
+
|
830
|
+
// ../core/reducer/actions/move.ts
|
831
|
+
init_react_import();
|
832
|
+
|
833
|
+
// ../core/lib/data/remove.ts
|
834
|
+
init_react_import();
|
835
|
+
var remove = (list, index) => {
|
836
|
+
const result = Array.from(list);
|
837
|
+
result.splice(index, 1);
|
838
|
+
return result;
|
839
|
+
};
|
840
|
+
|
841
|
+
// ../core/reducer/actions/move.ts
|
719
842
|
var moveAction = (state, action, appStore) => {
|
720
843
|
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
721
844
|
return state;
|
@@ -755,57 +878,26 @@ var moveAction = (state, action, appStore) => {
|
|
755
878
|
}
|
756
879
|
);
|
757
880
|
};
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
const idChanged = originalId !== action.data.props.id;
|
763
|
-
if (idChanged) {
|
764
|
-
throw new Error(
|
765
|
-
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
766
|
-
);
|
767
|
-
}
|
768
|
-
return walkTree(
|
881
|
+
|
882
|
+
// ../core/reducer/actions/reorder.ts
|
883
|
+
var reorderAction = (state, action, appStore) => {
|
884
|
+
return moveAction(
|
769
885
|
state,
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
return newContent;
|
886
|
+
{
|
887
|
+
type: "move",
|
888
|
+
sourceIndex: action.sourceIndex,
|
889
|
+
sourceZone: action.destinationZone,
|
890
|
+
destinationIndex: action.destinationIndex,
|
891
|
+
destinationZone: action.destinationZone
|
777
892
|
},
|
778
|
-
|
779
|
-
const pathIds = path.map((p) => p.split(":")[0]);
|
780
|
-
if (childItem.props.id === action.data.props.id) {
|
781
|
-
return action.data;
|
782
|
-
} else if (childItem.props.id === parentId) {
|
783
|
-
return childItem;
|
784
|
-
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
785
|
-
return childItem;
|
786
|
-
} else if (pathIds.indexOf(action.data.props.id) > -1) {
|
787
|
-
return childItem;
|
788
|
-
}
|
789
|
-
return null;
|
790
|
-
}
|
893
|
+
appStore
|
791
894
|
);
|
792
895
|
};
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
if (action.state.indexes) {
|
797
|
-
console.warn(
|
798
|
-
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
799
|
-
);
|
800
|
-
return newState;
|
801
|
-
}
|
802
|
-
return walkTree(newState, appStore.config);
|
803
|
-
}
|
804
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
805
|
-
};
|
896
|
+
|
897
|
+
// ../core/reducer/actions/remove.ts
|
898
|
+
init_react_import();
|
806
899
|
var removeAction = (state, action, appStore) => {
|
807
900
|
const item = getItem({ index: action.index, zone: action.zone }, state);
|
808
|
-
const [parentId] = action.zone.split(":");
|
809
901
|
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
810
902
|
(acc, [nodeId, nodeData]) => {
|
811
903
|
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
@@ -824,24 +916,17 @@ var removeAction = (state, action, appStore) => {
|
|
824
916
|
return remove(content, action.index);
|
825
917
|
}
|
826
918
|
return content;
|
827
|
-
},
|
828
|
-
(childItem, path) => {
|
829
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
830
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
831
|
-
return childItem;
|
832
|
-
}
|
833
|
-
return null;
|
834
919
|
}
|
835
920
|
);
|
836
921
|
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
837
|
-
const
|
838
|
-
if (nodesToDelete.includes(
|
922
|
+
const parentId = zoneCompound.split(":")[0];
|
923
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
839
924
|
delete newState.data.zones[zoneCompound];
|
840
925
|
}
|
841
926
|
});
|
842
927
|
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
843
|
-
const
|
844
|
-
if (nodesToDelete.includes(
|
928
|
+
const parentId = zoneCompound.split(":")[0];
|
929
|
+
if (nodesToDelete.includes(parentId)) {
|
845
930
|
delete newState.indexes.zones[zoneCompound];
|
846
931
|
}
|
847
932
|
});
|
@@ -850,168 +935,104 @@ var removeAction = (state, action, appStore) => {
|
|
850
935
|
});
|
851
936
|
return newState;
|
852
937
|
};
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
if (
|
861
|
-
return
|
862
|
-
}
|
863
|
-
if (action.type === "replaceRoot") {
|
864
|
-
return walkTree(
|
865
|
-
state,
|
866
|
-
appStore.config,
|
867
|
-
(content) => content,
|
868
|
-
(childItem) => {
|
869
|
-
if (childItem.props.id === "root") {
|
870
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
871
|
-
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
872
|
-
readOnly: action.root.readOnly
|
873
|
-
});
|
874
|
-
}
|
875
|
-
return childItem;
|
876
|
-
}
|
877
|
-
);
|
878
|
-
}
|
879
|
-
if (action.type === "duplicate") {
|
880
|
-
const item = getItem(
|
881
|
-
{ index: action.sourceIndex, zone: action.sourceZone },
|
882
|
-
state
|
883
|
-
);
|
884
|
-
const idsInPath = getIdsForParent(action.sourceZone, state);
|
885
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
886
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
887
|
-
id: generateId(item.type)
|
888
|
-
})
|
889
|
-
});
|
890
|
-
const modified = walkTree(
|
891
|
-
state,
|
892
|
-
appStore.config,
|
893
|
-
(content, zoneCompound) => {
|
894
|
-
if (zoneCompound === action.sourceZone) {
|
895
|
-
return insert(content, action.sourceIndex + 1, item);
|
896
|
-
}
|
897
|
-
return content;
|
898
|
-
},
|
899
|
-
(childItem, path, index) => {
|
900
|
-
const zoneCompound = path[path.length - 1];
|
901
|
-
const parents = path.map((p) => p.split(":")[0]);
|
902
|
-
if (parents.indexOf(newItem.props.id) > -1) {
|
903
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
904
|
-
props: __spreadProps(__spreadValues({}, childItem.props), {
|
905
|
-
id: generateId(childItem.type)
|
906
|
-
})
|
907
|
-
});
|
908
|
-
}
|
909
|
-
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
910
|
-
return newItem;
|
911
|
-
}
|
912
|
-
const [sourceZoneParent] = action.sourceZone.split(":");
|
913
|
-
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
914
|
-
return childItem;
|
915
|
-
}
|
916
|
-
return null;
|
917
|
-
}
|
918
|
-
);
|
919
|
-
return __spreadProps(__spreadValues({}, modified), {
|
920
|
-
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
921
|
-
itemSelector: {
|
922
|
-
index: action.sourceIndex + 1,
|
923
|
-
zone: action.sourceZone
|
924
|
-
}
|
925
|
-
})
|
926
|
-
});
|
927
|
-
}
|
928
|
-
if (action.type === "reorder") {
|
929
|
-
return moveAction(
|
930
|
-
state,
|
931
|
-
{
|
932
|
-
type: "move",
|
933
|
-
sourceIndex: action.sourceIndex,
|
934
|
-
sourceZone: action.destinationZone,
|
935
|
-
destinationIndex: action.destinationIndex,
|
936
|
-
destinationZone: action.destinationZone
|
937
|
-
},
|
938
|
-
appStore
|
939
|
-
);
|
940
|
-
}
|
941
|
-
if (action.type === "move") {
|
942
|
-
return moveAction(state, action, appStore);
|
943
|
-
}
|
944
|
-
if (action.type === "remove") {
|
945
|
-
return removeAction(state, action, appStore);
|
946
|
-
}
|
947
|
-
if (action.type === "registerZone") {
|
948
|
-
if (zoneCache[action.zone]) {
|
949
|
-
return __spreadProps(__spreadValues({}, state), {
|
950
|
-
data: __spreadProps(__spreadValues({}, state.data), {
|
951
|
-
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
952
|
-
[action.zone]: zoneCache[action.zone]
|
953
|
-
})
|
954
|
-
}),
|
955
|
-
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
956
|
-
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
957
|
-
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
958
|
-
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
959
|
-
type: "dropzone"
|
960
|
-
})
|
961
|
-
})
|
962
|
-
})
|
963
|
-
});
|
964
|
-
}
|
965
|
-
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
938
|
+
|
939
|
+
// ../core/reducer/actions/register-zone.ts
|
940
|
+
init_react_import();
|
941
|
+
|
942
|
+
// ../core/lib/data/setup-zone.ts
|
943
|
+
init_react_import();
|
944
|
+
var setupZone = (data, zoneKey) => {
|
945
|
+
if (zoneKey === rootDroppableId) {
|
946
|
+
return data;
|
966
947
|
}
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
948
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
949
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
950
|
+
});
|
951
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
952
|
+
return newData;
|
953
|
+
};
|
954
|
+
|
955
|
+
// ../core/reducer/actions/register-zone.ts
|
956
|
+
var zoneCache = {};
|
957
|
+
function registerZoneAction(state, action) {
|
958
|
+
if (zoneCache[action.zone]) {
|
975
959
|
return __spreadProps(__spreadValues({}, state), {
|
976
960
|
data: __spreadProps(__spreadValues({}, state.data), {
|
977
|
-
zones:
|
961
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
962
|
+
[action.zone]: zoneCache[action.zone]
|
963
|
+
})
|
978
964
|
}),
|
979
965
|
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
980
|
-
zones:
|
966
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
967
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
968
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
969
|
+
type: "dropzone"
|
970
|
+
})
|
971
|
+
})
|
981
972
|
})
|
982
973
|
});
|
983
974
|
}
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
}
|
975
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
976
|
+
}
|
977
|
+
function unregisterZoneAction(state, action) {
|
978
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
979
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
980
|
+
if (_zones[action.zone]) {
|
981
|
+
zoneCache[action.zone] = _zones[action.zone];
|
982
|
+
delete _zones[action.zone];
|
983
|
+
}
|
984
|
+
delete zoneIndex[action.zone];
|
985
|
+
return __spreadProps(__spreadValues({}, state), {
|
986
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
987
|
+
zones: _zones
|
988
|
+
}),
|
989
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
990
|
+
zones: zoneIndex
|
991
|
+
})
|
992
|
+
});
|
993
|
+
}
|
994
|
+
|
995
|
+
// ../core/reducer/actions/set-data.ts
|
996
|
+
init_react_import();
|
997
|
+
var setDataAction = (state, action, appStore) => {
|
998
|
+
if (typeof action.data === "object") {
|
999
|
+
console.warn(
|
1000
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1001
|
+
);
|
996
1002
|
return walkTree(
|
997
1003
|
__spreadProps(__spreadValues({}, state), {
|
998
|
-
data: __spreadValues(__spreadValues({}, state.data), action.data
|
1004
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
999
1005
|
}),
|
1000
1006
|
appStore.config
|
1001
1007
|
);
|
1002
1008
|
}
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
+
return walkTree(
|
1010
|
+
__spreadProps(__spreadValues({}, state), {
|
1011
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1012
|
+
}),
|
1013
|
+
appStore.config
|
1014
|
+
);
|
1015
|
+
};
|
1016
|
+
|
1017
|
+
// ../core/reducer/actions/set-ui.ts
|
1018
|
+
init_react_import();
|
1019
|
+
var setUiAction = (state, action) => {
|
1020
|
+
if (typeof action.ui === "object") {
|
1009
1021
|
return __spreadProps(__spreadValues({}, state), {
|
1010
|
-
ui: __spreadValues(__spreadValues({}, state.ui), action.ui
|
1022
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
1011
1023
|
});
|
1012
1024
|
}
|
1013
|
-
return state
|
1014
|
-
}
|
1025
|
+
return __spreadProps(__spreadValues({}, state), {
|
1026
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
1027
|
+
});
|
1028
|
+
};
|
1029
|
+
|
1030
|
+
// ../core/lib/data/make-state-public.ts
|
1031
|
+
init_react_import();
|
1032
|
+
var makeStatePublic = (state) => {
|
1033
|
+
const { data, ui } = state;
|
1034
|
+
return { data, ui };
|
1035
|
+
};
|
1015
1036
|
|
1016
1037
|
// ../core/reducer/actions.tsx
|
1017
1038
|
init_react_import();
|
@@ -1030,7 +1051,7 @@ function storeInterceptor(reducer, record, onAction) {
|
|
1030
1051
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
1031
1052
|
if (record) record(newAppState);
|
1032
1053
|
}
|
1033
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1054
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
1034
1055
|
return newAppState;
|
1035
1056
|
};
|
1036
1057
|
}
|
@@ -1041,8 +1062,43 @@ function createReducer({
|
|
1041
1062
|
}) {
|
1042
1063
|
return storeInterceptor(
|
1043
1064
|
(state, action) => {
|
1044
|
-
|
1045
|
-
|
1065
|
+
if (action.type === "set") {
|
1066
|
+
return setAction(state, action, appStore);
|
1067
|
+
}
|
1068
|
+
if (action.type === "insert") {
|
1069
|
+
return insertAction(state, action, appStore);
|
1070
|
+
}
|
1071
|
+
if (action.type === "replace") {
|
1072
|
+
return replaceAction(state, action, appStore);
|
1073
|
+
}
|
1074
|
+
if (action.type === "replaceRoot") {
|
1075
|
+
return replaceRootAction(state, action, appStore);
|
1076
|
+
}
|
1077
|
+
if (action.type === "duplicate") {
|
1078
|
+
return duplicateAction(state, action, appStore);
|
1079
|
+
}
|
1080
|
+
if (action.type === "reorder") {
|
1081
|
+
return reorderAction(state, action, appStore);
|
1082
|
+
}
|
1083
|
+
if (action.type === "move") {
|
1084
|
+
return moveAction(state, action, appStore);
|
1085
|
+
}
|
1086
|
+
if (action.type === "remove") {
|
1087
|
+
return removeAction(state, action, appStore);
|
1088
|
+
}
|
1089
|
+
if (action.type === "registerZone") {
|
1090
|
+
return registerZoneAction(state, action);
|
1091
|
+
}
|
1092
|
+
if (action.type === "unregisterZone") {
|
1093
|
+
return unregisterZoneAction(state, action);
|
1094
|
+
}
|
1095
|
+
if (action.type === "setData") {
|
1096
|
+
return setDataAction(state, action, appStore);
|
1097
|
+
}
|
1098
|
+
if (action.type === "setUi") {
|
1099
|
+
return setUiAction(state, action);
|
1100
|
+
}
|
1101
|
+
return state;
|
1046
1102
|
},
|
1047
1103
|
record,
|
1048
1104
|
onAction
|
@@ -1237,7 +1293,7 @@ var createHistorySlice = (set, get) => {
|
|
1237
1293
|
const { dispatch, history } = get();
|
1238
1294
|
dispatch({
|
1239
1295
|
type: "set",
|
1240
|
-
state: ((_a = history.histories[
|
1296
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1241
1297
|
});
|
1242
1298
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1243
1299
|
},
|
@@ -1286,7 +1342,7 @@ var createNodesSlice = (set, get) => ({
|
|
1286
1342
|
init_react_import();
|
1287
1343
|
import { useEffect as useEffect3 } from "react";
|
1288
1344
|
|
1289
|
-
// ../core/lib/flatten-data.ts
|
1345
|
+
// ../core/lib/data/flatten-data.ts
|
1290
1346
|
init_react_import();
|
1291
1347
|
var flattenData = (state, config) => {
|
1292
1348
|
const data = [];
|
@@ -1321,12 +1377,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1321
1377
|
const { cache: cache2, globalPermissions } = permissions;
|
1322
1378
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1323
1379
|
var _a, _b, _c;
|
1324
|
-
const {
|
1325
|
-
config: config2,
|
1326
|
-
state: appState,
|
1327
|
-
setComponentLoading,
|
1328
|
-
unsetComponentLoading
|
1329
|
-
} = get();
|
1380
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1330
1381
|
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1331
1382
|
if (!componentConfig) {
|
1332
1383
|
return;
|
@@ -1335,14 +1386,14 @@ var createPermissionsSlice = (set, get) => {
|
|
1335
1386
|
if (componentConfig.resolvePermissions) {
|
1336
1387
|
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1337
1388
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1338
|
-
setComponentLoading(item2.props.id);
|
1389
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1339
1390
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1340
1391
|
item2,
|
1341
1392
|
{
|
1342
1393
|
changed,
|
1343
1394
|
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1344
1395
|
permissions: initialPermissions,
|
1345
|
-
appState,
|
1396
|
+
appState: makeStatePublic(appState),
|
1346
1397
|
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1347
1398
|
}
|
1348
1399
|
);
|
@@ -1360,7 +1411,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1360
1411
|
})
|
1361
1412
|
})
|
1362
1413
|
});
|
1363
|
-
|
1414
|
+
clearTimeout2();
|
1364
1415
|
}
|
1365
1416
|
}
|
1366
1417
|
});
|
@@ -1370,7 +1421,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1370
1421
|
// Shim the root data in by conforming to component data shape
|
1371
1422
|
{
|
1372
1423
|
type: "root",
|
1373
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1424
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1374
1425
|
},
|
1375
1426
|
force2
|
1376
1427
|
);
|
@@ -1385,7 +1436,6 @@ var createPermissionsSlice = (set, get) => {
|
|
1385
1436
|
} else if (root) {
|
1386
1437
|
resolveDataForRoot(force);
|
1387
1438
|
} else {
|
1388
|
-
resolveDataForRoot(force);
|
1389
1439
|
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1390
1440
|
yield resolveDataForItem(item2, force);
|
1391
1441
|
}));
|
@@ -1416,7 +1466,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1416
1466
|
} else if (root) {
|
1417
1467
|
const rootConfig = config.root;
|
1418
1468
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1419
|
-
const resolvedForItem = resolvedPermissions["
|
1469
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1420
1470
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1421
1471
|
}
|
1422
1472
|
return globalPermissions;
|
@@ -1440,24 +1490,25 @@ var createFieldsSlice = (_set, _get) => {
|
|
1440
1490
|
// ../core/lib/resolve-component-data.ts
|
1441
1491
|
init_react_import();
|
1442
1492
|
|
1443
|
-
// ../core/lib/map-slots.ts
|
1493
|
+
// ../core/lib/data/map-slots.ts
|
1444
1494
|
init_react_import();
|
1445
|
-
function
|
1446
|
-
return __async(this,
|
1495
|
+
function mapSlotsAsync(_0, _1) {
|
1496
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1447
1497
|
const props = __spreadValues({}, item.props);
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1498
|
+
const propKeys = Object.keys(props);
|
1499
|
+
for (let i = 0; i < propKeys.length; i++) {
|
1500
|
+
const propKey = propKeys[i];
|
1501
|
+
const itemType = "type" in item ? item.type : "root";
|
1502
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
1503
|
+
const content = props[propKey];
|
1451
1504
|
const mappedContent = recursive ? yield Promise.all(
|
1452
1505
|
content.map((item2) => __async(this, null, function* () {
|
1453
|
-
return yield
|
1506
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
1454
1507
|
}))
|
1455
1508
|
) : content;
|
1456
|
-
props[
|
1457
|
-
}
|
1458
|
-
|
1459
|
-
isSlot2
|
1460
|
-
);
|
1509
|
+
props[propKey] = yield map(mappedContent, propKey);
|
1510
|
+
}
|
1511
|
+
}
|
1461
1512
|
return __spreadProps(__spreadValues({}, item), { props });
|
1462
1513
|
});
|
1463
1514
|
}
|
@@ -1480,14 +1531,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1480
1531
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1481
1532
|
changed,
|
1482
1533
|
lastData: oldItem,
|
1483
|
-
metadata,
|
1534
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1484
1535
|
trigger
|
1485
1536
|
});
|
1486
1537
|
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1487
1538
|
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1488
1539
|
});
|
1489
1540
|
if (recursive) {
|
1490
|
-
resolvedItem = yield
|
1541
|
+
resolvedItem = yield mapSlotsAsync(
|
1491
1542
|
resolvedItem,
|
1492
1543
|
(content) => __async(void 0, null, function* () {
|
1493
1544
|
return Promise.all(
|
@@ -1525,7 +1576,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1525
1576
|
return { node: item, didChange: false };
|
1526
1577
|
});
|
1527
1578
|
|
1528
|
-
// ../core/lib/to-root.ts
|
1579
|
+
// ../core/lib/data/to-root.ts
|
1529
1580
|
init_react_import();
|
1530
1581
|
var toRoot = (item) => {
|
1531
1582
|
if ("type" in item && item.type !== "root") {
|
@@ -1572,166 +1623,176 @@ var defaultPageFields = {
|
|
1572
1623
|
title: { type: "text" }
|
1573
1624
|
};
|
1574
1625
|
var createAppStore = (initialAppStore) => create()(
|
1575
|
-
subscribeWithSelector((set, get) =>
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1626
|
+
subscribeWithSelector((set, get) => {
|
1627
|
+
var _a, _b;
|
1628
|
+
return __spreadProps(__spreadValues({
|
1629
|
+
state: defaultAppState,
|
1630
|
+
config: { components: {} },
|
1631
|
+
componentState: {},
|
1632
|
+
plugins: [],
|
1633
|
+
overrides: {},
|
1634
|
+
viewports: defaultViewports,
|
1635
|
+
zoomConfig: {
|
1636
|
+
autoZoom: 1,
|
1637
|
+
rootHeight: 0,
|
1638
|
+
zoom: 1
|
1639
|
+
},
|
1640
|
+
status: "LOADING",
|
1641
|
+
iframe: {},
|
1642
|
+
metadata: {}
|
1643
|
+
}, initialAppStore), {
|
1644
|
+
fields: createFieldsSlice(set, get),
|
1645
|
+
history: createHistorySlice(set, get),
|
1646
|
+
nodes: createNodesSlice(set, get),
|
1647
|
+
permissions: createPermissionsSlice(set, get),
|
1648
|
+
getComponentConfig: (type) => {
|
1649
|
+
var _a2;
|
1650
|
+
const { config, selectedItem } = get();
|
1651
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1652
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1653
|
+
},
|
1654
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1655
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1656
|
+
initialAppStore.state
|
1657
|
+
) : null,
|
1658
|
+
dispatch: (action) => set((s) => {
|
1659
|
+
var _a2, _b2;
|
1660
|
+
const { record } = get().history;
|
1661
|
+
const dispatch = createReducer({
|
1662
|
+
record,
|
1663
|
+
appStore: s
|
1664
|
+
});
|
1665
|
+
const state = dispatch(s.state, action);
|
1666
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1667
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1668
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1669
|
+
}),
|
1670
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1671
|
+
setStatus: (status) => set({ status }),
|
1672
|
+
setComponentState: (componentState) => set({ componentState }),
|
1673
|
+
pendingLoadTimeouts: {},
|
1674
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1675
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1676
|
+
const loadId = generateId();
|
1677
|
+
const setLoading = () => {
|
1678
|
+
var _a2;
|
1679
|
+
const { componentState } = get();
|
1680
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1681
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1682
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1683
|
+
})
|
1684
|
+
}));
|
1685
|
+
};
|
1686
|
+
const unsetLoading = () => {
|
1687
|
+
var _a2;
|
1688
|
+
const { componentState } = get();
|
1689
|
+
clearTimeout(timeout);
|
1690
|
+
delete pendingLoadTimeouts[loadId];
|
1691
|
+
set({ pendingLoadTimeouts });
|
1692
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1693
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1694
|
+
loadingCount: Math.max(
|
1695
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1696
|
+
0
|
1697
|
+
)
|
1698
|
+
})
|
1699
|
+
}));
|
1700
|
+
};
|
1701
|
+
const timeout = setTimeout(() => {
|
1702
|
+
if (loading) {
|
1703
|
+
setLoading();
|
1704
|
+
} else {
|
1705
|
+
unsetLoading();
|
1706
|
+
}
|
1707
|
+
delete pendingLoadTimeouts[loadId];
|
1708
|
+
set({ pendingLoadTimeouts });
|
1709
|
+
}, defer);
|
1710
|
+
set({
|
1711
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1712
|
+
[id]: timeout
|
1638
1713
|
})
|
1639
|
-
})
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
}
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1679
|
-
}),
|
1680
|
-
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1681
|
-
const { config, metadata, setComponentLoading } = get();
|
1682
|
-
return yield resolveComponentData(
|
1683
|
-
componentData,
|
1684
|
-
config,
|
1685
|
-
metadata,
|
1686
|
-
(item) => setComponentLoading(
|
1687
|
-
"id" in item.props ? item.props.id : "root",
|
1688
|
-
true,
|
1689
|
-
50
|
1690
|
-
),
|
1691
|
-
(item) => setComponentLoading(
|
1692
|
-
"id" in item.props ? item.props.id : "root",
|
1693
|
-
false,
|
1694
|
-
0
|
1695
|
-
),
|
1696
|
-
trigger
|
1697
|
-
);
|
1698
|
-
}),
|
1699
|
-
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1700
|
-
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1701
|
-
walkTree(
|
1702
|
-
state,
|
1703
|
-
config,
|
1704
|
-
(content) => content,
|
1705
|
-
(childItem) => {
|
1706
|
-
resolveComponentData2(childItem, "load").then((resolved) => {
|
1707
|
-
const { state: state2 } = get();
|
1708
|
-
const node = state2.indexes.nodes[resolved.node.props.id];
|
1709
|
-
if (node && resolved.didChange) {
|
1710
|
-
if (resolved.node.props.id === "root") {
|
1711
|
-
dispatch({
|
1712
|
-
type: "replaceRoot",
|
1713
|
-
root: toRoot(resolved.node)
|
1714
|
-
});
|
1715
|
-
} else {
|
1716
|
-
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1717
|
-
const parentZone = state2.indexes.zones[zoneCompound];
|
1718
|
-
const index = parentZone.contentIds.indexOf(
|
1719
|
-
resolved.node.props.id
|
1720
|
-
);
|
1721
|
-
dispatch({
|
1722
|
-
type: "replace",
|
1723
|
-
data: resolved.node,
|
1724
|
-
destinationIndex: index,
|
1725
|
-
destinationZone: zoneCompound
|
1726
|
-
});
|
1727
|
-
}
|
1714
|
+
});
|
1715
|
+
return unsetLoading;
|
1716
|
+
},
|
1717
|
+
unsetComponentLoading: (id) => {
|
1718
|
+
const { setComponentLoading } = get();
|
1719
|
+
setComponentLoading(id, false);
|
1720
|
+
},
|
1721
|
+
// Helper
|
1722
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1723
|
+
const dispatch = createReducer({
|
1724
|
+
record: () => {
|
1725
|
+
},
|
1726
|
+
appStore: s
|
1727
|
+
});
|
1728
|
+
const state = dispatch(s.state, {
|
1729
|
+
type: "setUi",
|
1730
|
+
ui,
|
1731
|
+
recordHistory
|
1732
|
+
});
|
1733
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1734
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1735
|
+
}),
|
1736
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1737
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
1738
|
+
const timeouts = {};
|
1739
|
+
return yield resolveComponentData(
|
1740
|
+
componentData,
|
1741
|
+
config,
|
1742
|
+
metadata,
|
1743
|
+
(item) => {
|
1744
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1745
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
1746
|
+
},
|
1747
|
+
(item) => __async(void 0, null, function* () {
|
1748
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1749
|
+
if ("type" in item) {
|
1750
|
+
yield permissions.refreshPermissions({ item });
|
1751
|
+
} else {
|
1752
|
+
yield permissions.refreshPermissions({ root: true });
|
1728
1753
|
}
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1754
|
+
timeouts[id]();
|
1755
|
+
}),
|
1756
|
+
trigger
|
1757
|
+
);
|
1758
|
+
}),
|
1759
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1760
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1761
|
+
walkTree(
|
1762
|
+
state,
|
1763
|
+
config,
|
1764
|
+
(content) => content,
|
1765
|
+
(childItem) => {
|
1766
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
1767
|
+
const { state: state2 } = get();
|
1768
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
1769
|
+
if (node && resolved.didChange) {
|
1770
|
+
if (resolved.node.props.id === "root") {
|
1771
|
+
dispatch({
|
1772
|
+
type: "replaceRoot",
|
1773
|
+
root: toRoot(resolved.node)
|
1774
|
+
});
|
1775
|
+
} else {
|
1776
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1777
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
1778
|
+
const index = parentZone.contentIds.indexOf(
|
1779
|
+
resolved.node.props.id
|
1780
|
+
);
|
1781
|
+
dispatch({
|
1782
|
+
type: "replace",
|
1783
|
+
data: resolved.node,
|
1784
|
+
destinationIndex: index,
|
1785
|
+
destinationZone: zoneCompound
|
1786
|
+
});
|
1787
|
+
}
|
1788
|
+
}
|
1789
|
+
});
|
1790
|
+
return childItem;
|
1791
|
+
}
|
1792
|
+
);
|
1793
|
+
})
|
1794
|
+
});
|
1795
|
+
})
|
1735
1796
|
);
|
1736
1797
|
var appStoreContext = createContext(createAppStore());
|
1737
1798
|
function useAppStore(selector) {
|
@@ -1793,10 +1854,10 @@ init_react_import();
|
|
1793
1854
|
// ../core/lib/filter.ts
|
1794
1855
|
init_react_import();
|
1795
1856
|
|
1796
|
-
// ../core/lib/reorder.ts
|
1857
|
+
// ../core/lib/data/reorder.ts
|
1797
1858
|
init_react_import();
|
1798
1859
|
|
1799
|
-
// ../core/lib/replace.ts
|
1860
|
+
// ../core/lib/data/replace.ts
|
1800
1861
|
init_react_import();
|
1801
1862
|
|
1802
1863
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
@@ -1982,15 +2043,37 @@ var HeadingAnalyzer = () => {
|
|
1982
2043
|
const [hierarchy, setHierarchy] = useState([]);
|
1983
2044
|
useEffect5(() => {
|
1984
2045
|
const frame = getFrame();
|
1985
|
-
|
1986
|
-
|
1987
|
-
setHierarchy(buildHierarchy(entry));
|
1988
|
-
const observer = new MutationObserver(() => {
|
2046
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2047
|
+
const createHierarchy = () => {
|
1989
2048
|
setHierarchy(buildHierarchy(entry));
|
2049
|
+
};
|
2050
|
+
const entryObserver = new MutationObserver(() => {
|
2051
|
+
createHierarchy();
|
2052
|
+
});
|
2053
|
+
const frameObserver = new MutationObserver(() => {
|
2054
|
+
entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2055
|
+
if (entry) {
|
2056
|
+
registerEntryObserver();
|
2057
|
+
frameObserver.disconnect();
|
2058
|
+
}
|
1990
2059
|
});
|
1991
|
-
|
2060
|
+
const registerEntryObserver = () => {
|
2061
|
+
if (!entry) return;
|
2062
|
+
entryObserver.observe(entry, { subtree: true, childList: true });
|
2063
|
+
};
|
2064
|
+
const registerFrameObserver = () => {
|
2065
|
+
if (!frame) return;
|
2066
|
+
frameObserver.observe(frame, { subtree: true, childList: true });
|
2067
|
+
};
|
2068
|
+
if (entry) {
|
2069
|
+
createHierarchy();
|
2070
|
+
registerEntryObserver();
|
2071
|
+
} else {
|
2072
|
+
registerFrameObserver();
|
2073
|
+
}
|
1992
2074
|
return () => {
|
1993
|
-
|
2075
|
+
entryObserver.disconnect();
|
2076
|
+
frameObserver.disconnect();
|
1994
2077
|
};
|
1995
2078
|
}, [data]);
|
1996
2079
|
return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [
|