@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.js
CHANGED
@@ -368,123 +368,16 @@ init_react_import();
|
|
368
368
|
// ../core/reducer/index.ts
|
369
369
|
init_react_import();
|
370
370
|
|
371
|
-
// ../core/reducer/
|
371
|
+
// ../core/reducer/actions/set.ts
|
372
372
|
init_react_import();
|
373
373
|
|
374
|
-
// ../core/lib/
|
374
|
+
// ../core/lib/data/walk-tree.ts
|
375
375
|
init_react_import();
|
376
|
-
var insert = (list, index, item) => {
|
377
|
-
const result = Array.from(list || []);
|
378
|
-
result.splice(index, 0, item);
|
379
|
-
return result;
|
380
|
-
};
|
381
|
-
|
382
|
-
// ../core/lib/remove.ts
|
383
|
-
init_react_import();
|
384
|
-
var remove = (list, index) => {
|
385
|
-
const result = Array.from(list);
|
386
|
-
result.splice(index, 1);
|
387
|
-
return result;
|
388
|
-
};
|
389
|
-
|
390
|
-
// ../core/lib/setup-zone.ts
|
391
|
-
init_react_import();
|
392
|
-
|
393
|
-
// ../core/lib/root-droppable-id.ts
|
394
|
-
init_react_import();
|
395
|
-
var rootAreaId = "root";
|
396
|
-
var rootZone = "default-zone";
|
397
|
-
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
398
|
-
|
399
|
-
// ../core/lib/setup-zone.ts
|
400
|
-
var setupZone = (data, zoneKey) => {
|
401
|
-
if (zoneKey === rootDroppableId) {
|
402
|
-
return data;
|
403
|
-
}
|
404
|
-
const newData = __spreadProps(__spreadValues({}, data), {
|
405
|
-
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
406
|
-
});
|
407
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
408
|
-
return newData;
|
409
|
-
};
|
410
|
-
|
411
|
-
// ../core/lib/get-item.ts
|
412
|
-
init_react_import();
|
413
|
-
function getItem(selector, state) {
|
414
|
-
var _a, _b;
|
415
|
-
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
416
|
-
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
417
|
-
}
|
418
|
-
|
419
|
-
// ../core/lib/generate-id.ts
|
420
|
-
init_react_import();
|
421
|
-
|
422
|
-
// ../../node_modules/uuid/dist/esm-node/index.js
|
423
|
-
init_react_import();
|
424
|
-
|
425
|
-
// ../../node_modules/uuid/dist/esm-node/rng.js
|
426
|
-
init_react_import();
|
427
|
-
var import_crypto = __toESM(require("crypto"));
|
428
|
-
var rnds8Pool = new Uint8Array(256);
|
429
|
-
var poolPtr = rnds8Pool.length;
|
430
|
-
function rng() {
|
431
|
-
if (poolPtr > rnds8Pool.length - 16) {
|
432
|
-
import_crypto.default.randomFillSync(rnds8Pool);
|
433
|
-
poolPtr = 0;
|
434
|
-
}
|
435
|
-
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
436
|
-
}
|
437
|
-
|
438
|
-
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
439
|
-
init_react_import();
|
440
|
-
var byteToHex = [];
|
441
|
-
for (let i = 0; i < 256; ++i) {
|
442
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
443
|
-
}
|
444
|
-
function unsafeStringify(arr, offset = 0) {
|
445
|
-
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]];
|
446
|
-
}
|
447
|
-
|
448
|
-
// ../../node_modules/uuid/dist/esm-node/v4.js
|
449
|
-
init_react_import();
|
450
|
-
|
451
|
-
// ../../node_modules/uuid/dist/esm-node/native.js
|
452
|
-
init_react_import();
|
453
|
-
var import_crypto2 = __toESM(require("crypto"));
|
454
|
-
var native_default = {
|
455
|
-
randomUUID: import_crypto2.default.randomUUID
|
456
|
-
};
|
457
|
-
|
458
|
-
// ../../node_modules/uuid/dist/esm-node/v4.js
|
459
|
-
function v4(options, buf, offset) {
|
460
|
-
if (native_default.randomUUID && !buf && !options) {
|
461
|
-
return native_default.randomUUID();
|
462
|
-
}
|
463
|
-
options = options || {};
|
464
|
-
const rnds = options.random || (options.rng || rng)();
|
465
|
-
rnds[6] = rnds[6] & 15 | 64;
|
466
|
-
rnds[8] = rnds[8] & 63 | 128;
|
467
|
-
if (buf) {
|
468
|
-
offset = offset || 0;
|
469
|
-
for (let i = 0; i < 16; ++i) {
|
470
|
-
buf[offset + i] = rnds[i];
|
471
|
-
}
|
472
|
-
return buf;
|
473
|
-
}
|
474
|
-
return unsafeStringify(rnds);
|
475
|
-
}
|
476
|
-
var v4_default = v4;
|
477
|
-
|
478
|
-
// ../core/lib/generate-id.ts
|
479
|
-
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
480
376
|
|
481
|
-
// ../core/lib/
|
377
|
+
// ../core/lib/data/for-each-slot.ts
|
482
378
|
init_react_import();
|
483
379
|
|
484
|
-
// ../core/lib/
|
485
|
-
init_react_import();
|
486
|
-
|
487
|
-
// ../core/lib/is-slot.ts
|
380
|
+
// ../core/lib/data/is-slot.ts
|
488
381
|
init_react_import();
|
489
382
|
var isSlot = (prop) => {
|
490
383
|
var _a, _b;
|
@@ -497,8 +390,8 @@ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
|
497
390
|
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
498
391
|
};
|
499
392
|
|
500
|
-
// ../core/lib/for-each-slot.ts
|
501
|
-
var forEachSlot = (
|
393
|
+
// ../core/lib/data/for-each-slot.ts
|
394
|
+
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
502
395
|
const props = item.props || {};
|
503
396
|
const propKeys = Object.keys(props);
|
504
397
|
for (let i = 0; i < propKeys.length; i++) {
|
@@ -506,23 +399,31 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
|
|
506
399
|
const itemType = "type" in item ? item.type : "root";
|
507
400
|
if (isSlot2(itemType, propKey, props[propKey])) {
|
508
401
|
const content = props[propKey];
|
509
|
-
|
402
|
+
cb(props.id, propKey, content);
|
510
403
|
if (recursive) {
|
511
404
|
content.forEach(
|
512
405
|
(childItem) => __async(void 0, null, function* () {
|
513
|
-
return
|
406
|
+
return forEachSlot(childItem, cb, true, isSlot2);
|
514
407
|
})
|
515
408
|
);
|
516
409
|
}
|
517
410
|
}
|
518
411
|
}
|
519
|
-
}
|
412
|
+
};
|
520
413
|
|
521
|
-
// ../core/lib/for-related-zones.ts
|
414
|
+
// ../core/lib/data/for-related-zones.ts
|
522
415
|
init_react_import();
|
523
416
|
|
524
417
|
// ../core/lib/get-zone-id.ts
|
525
418
|
init_react_import();
|
419
|
+
|
420
|
+
// ../core/lib/root-droppable-id.ts
|
421
|
+
init_react_import();
|
422
|
+
var rootAreaId = "root";
|
423
|
+
var rootZone = "default-zone";
|
424
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
425
|
+
|
426
|
+
// ../core/lib/get-zone-id.ts
|
526
427
|
var getZoneId = (zoneCompound) => {
|
527
428
|
if (!zoneCompound) {
|
528
429
|
return [];
|
@@ -533,19 +434,17 @@ var getZoneId = (zoneCompound) => {
|
|
533
434
|
return [rootDroppableId, zoneCompound];
|
534
435
|
};
|
535
436
|
|
536
|
-
// ../core/lib/for-related-zones.ts
|
437
|
+
// ../core/lib/data/for-related-zones.ts
|
537
438
|
function forRelatedZones(item, data, cb, path = []) {
|
538
439
|
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
539
440
|
const [parentId] = getZoneId(zoneCompound);
|
540
441
|
if (parentId === item.props.id) {
|
541
|
-
const newPath = [...path, zoneCompound];
|
542
|
-
content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
|
543
442
|
cb(path, zoneCompound, content);
|
544
443
|
}
|
545
444
|
});
|
546
445
|
}
|
547
446
|
|
548
|
-
// ../core/lib/strip-slots.ts
|
447
|
+
// ../core/lib/data/strip-slots.ts
|
549
448
|
init_react_import();
|
550
449
|
var stripSlots = (data) => {
|
551
450
|
return __spreadProps(__spreadValues({}, data), {
|
@@ -561,7 +460,7 @@ var stripSlots = (data) => {
|
|
561
460
|
});
|
562
461
|
};
|
563
462
|
|
564
|
-
// ../core/lib/walk-tree.ts
|
463
|
+
// ../core/lib/data/walk-tree.ts
|
565
464
|
function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
566
465
|
var _a;
|
567
466
|
let newZones = {};
|
@@ -603,7 +502,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
603
502
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
604
503
|
if (!mappedItem) return item;
|
605
504
|
const id = mappedItem.props.id;
|
606
|
-
processRelatedZones(item, id, path);
|
607
505
|
const newProps = __spreadValues({}, mappedItem.props);
|
608
506
|
forEachSlot(
|
609
507
|
mappedItem,
|
@@ -621,6 +519,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
621
519
|
false,
|
622
520
|
createIsSlotConfig(config)
|
623
521
|
);
|
522
|
+
processRelatedZones(item, id, path);
|
624
523
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
625
524
|
const thisZoneCompound = path[path.length - 1];
|
626
525
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
@@ -675,7 +574,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
675
574
|
return __spreadProps(__spreadValues({}, state), {
|
676
575
|
data: {
|
677
576
|
root,
|
678
|
-
// 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.
|
679
577
|
content: processedContent,
|
680
578
|
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
681
579
|
},
|
@@ -686,18 +584,108 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
686
584
|
});
|
687
585
|
}
|
688
586
|
|
689
|
-
// ../core/reducer/
|
690
|
-
var
|
587
|
+
// ../core/reducer/actions/set.ts
|
588
|
+
var setAction = (state, action, appStore) => {
|
589
|
+
if (typeof action.state === "object") {
|
590
|
+
const newState = __spreadValues(__spreadValues({}, state), action.state);
|
591
|
+
if (action.state.indexes) {
|
592
|
+
return newState;
|
593
|
+
}
|
594
|
+
console.warn(
|
595
|
+
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
596
|
+
);
|
597
|
+
return walkTree(newState, appStore.config);
|
598
|
+
}
|
599
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
600
|
+
};
|
601
|
+
|
602
|
+
// ../core/reducer/actions/insert.ts
|
603
|
+
init_react_import();
|
604
|
+
|
605
|
+
// ../core/lib/data/insert.ts
|
606
|
+
init_react_import();
|
607
|
+
var insert = (list, index, item) => {
|
608
|
+
const result = Array.from(list || []);
|
609
|
+
result.splice(index, 0, item);
|
610
|
+
return result;
|
611
|
+
};
|
612
|
+
|
613
|
+
// ../core/lib/generate-id.ts
|
614
|
+
init_react_import();
|
615
|
+
|
616
|
+
// ../../node_modules/uuid/dist/esm-node/index.js
|
617
|
+
init_react_import();
|
618
|
+
|
619
|
+
// ../../node_modules/uuid/dist/esm-node/rng.js
|
620
|
+
init_react_import();
|
621
|
+
var import_crypto = __toESM(require("crypto"));
|
622
|
+
var rnds8Pool = new Uint8Array(256);
|
623
|
+
var poolPtr = rnds8Pool.length;
|
624
|
+
function rng() {
|
625
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
626
|
+
import_crypto.default.randomFillSync(rnds8Pool);
|
627
|
+
poolPtr = 0;
|
628
|
+
}
|
629
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
630
|
+
}
|
631
|
+
|
632
|
+
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
633
|
+
init_react_import();
|
634
|
+
var byteToHex = [];
|
635
|
+
for (let i = 0; i < 256; ++i) {
|
636
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
637
|
+
}
|
638
|
+
function unsafeStringify(arr, offset = 0) {
|
639
|
+
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]];
|
640
|
+
}
|
641
|
+
|
642
|
+
// ../../node_modules/uuid/dist/esm-node/v4.js
|
643
|
+
init_react_import();
|
644
|
+
|
645
|
+
// ../../node_modules/uuid/dist/esm-node/native.js
|
646
|
+
init_react_import();
|
647
|
+
var import_crypto2 = __toESM(require("crypto"));
|
648
|
+
var native_default = {
|
649
|
+
randomUUID: import_crypto2.default.randomUUID
|
650
|
+
};
|
651
|
+
|
652
|
+
// ../../node_modules/uuid/dist/esm-node/v4.js
|
653
|
+
function v4(options, buf, offset) {
|
654
|
+
if (native_default.randomUUID && !buf && !options) {
|
655
|
+
return native_default.randomUUID();
|
656
|
+
}
|
657
|
+
options = options || {};
|
658
|
+
const rnds = options.random || (options.rng || rng)();
|
659
|
+
rnds[6] = rnds[6] & 15 | 64;
|
660
|
+
rnds[8] = rnds[8] & 63 | 128;
|
661
|
+
if (buf) {
|
662
|
+
offset = offset || 0;
|
663
|
+
for (let i = 0; i < 16; ++i) {
|
664
|
+
buf[offset + i] = rnds[i];
|
665
|
+
}
|
666
|
+
return buf;
|
667
|
+
}
|
668
|
+
return unsafeStringify(rnds);
|
669
|
+
}
|
670
|
+
var v4_default = v4;
|
671
|
+
|
672
|
+
// ../core/lib/generate-id.ts
|
673
|
+
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
674
|
+
|
675
|
+
// ../core/lib/data/get-ids-for-parent.ts
|
676
|
+
init_react_import();
|
691
677
|
var getIdsForParent = (zoneCompound, state) => {
|
692
678
|
const [parentId] = zoneCompound.split(":");
|
693
679
|
const node = state.indexes.nodes[parentId];
|
694
680
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
695
681
|
};
|
696
|
-
|
682
|
+
|
683
|
+
// ../core/reducer/actions/insert.ts
|
684
|
+
function insertAction(state, action, appStore) {
|
697
685
|
const id = action.id || generateId(action.componentType);
|
698
686
|
const emptyComponentData = {
|
699
687
|
type: action.componentType,
|
700
|
-
props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
|
688
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
701
689
|
id
|
702
690
|
})
|
703
691
|
};
|
@@ -705,29 +693,164 @@ function insertAction(state, action, config) {
|
|
705
693
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
706
694
|
return walkTree(
|
707
695
|
state,
|
708
|
-
config,
|
696
|
+
appStore.config,
|
697
|
+
(content, zoneCompound) => {
|
698
|
+
if (zoneCompound === action.destinationZone) {
|
699
|
+
return insert(
|
700
|
+
content || [],
|
701
|
+
action.destinationIndex,
|
702
|
+
emptyComponentData
|
703
|
+
);
|
704
|
+
}
|
705
|
+
return content;
|
706
|
+
},
|
707
|
+
(childItem, path) => {
|
708
|
+
if (childItem.props.id === id || childItem.props.id === parentId) {
|
709
|
+
return childItem;
|
710
|
+
} else if (idsInPath.includes(childItem.props.id)) {
|
711
|
+
return childItem;
|
712
|
+
} else if (path.includes(action.destinationZone)) {
|
713
|
+
return childItem;
|
714
|
+
}
|
715
|
+
return null;
|
716
|
+
}
|
717
|
+
);
|
718
|
+
}
|
719
|
+
|
720
|
+
// ../core/reducer/actions/replace.ts
|
721
|
+
init_react_import();
|
722
|
+
var replaceAction = (state, action, appStore) => {
|
723
|
+
const [parentId] = action.destinationZone.split(":");
|
724
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
725
|
+
const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
|
726
|
+
const idChanged = originalId !== action.data.props.id;
|
727
|
+
if (idChanged) {
|
728
|
+
throw new Error(
|
729
|
+
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
730
|
+
);
|
731
|
+
}
|
732
|
+
return walkTree(
|
733
|
+
state,
|
734
|
+
appStore.config,
|
735
|
+
(content, zoneCompound) => {
|
736
|
+
const newContent = [...content];
|
737
|
+
if (zoneCompound === action.destinationZone) {
|
738
|
+
newContent[action.destinationIndex] = action.data;
|
739
|
+
}
|
740
|
+
return newContent;
|
741
|
+
},
|
742
|
+
(childItem, path) => {
|
743
|
+
const pathIds = path.map((p) => p.split(":")[0]);
|
744
|
+
if (childItem.props.id === action.data.props.id) {
|
745
|
+
return action.data;
|
746
|
+
} else if (childItem.props.id === parentId) {
|
747
|
+
return childItem;
|
748
|
+
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
749
|
+
return childItem;
|
750
|
+
} else if (pathIds.indexOf(action.data.props.id) > -1) {
|
751
|
+
return childItem;
|
752
|
+
}
|
753
|
+
return null;
|
754
|
+
}
|
755
|
+
);
|
756
|
+
};
|
757
|
+
|
758
|
+
// ../core/reducer/actions/replace-root.ts
|
759
|
+
init_react_import();
|
760
|
+
var replaceRootAction = (state, action, appStore) => {
|
761
|
+
return walkTree(
|
762
|
+
state,
|
763
|
+
appStore.config,
|
764
|
+
(content) => content,
|
765
|
+
(childItem) => {
|
766
|
+
if (childItem.props.id === "root") {
|
767
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
768
|
+
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
769
|
+
readOnly: action.root.readOnly
|
770
|
+
});
|
771
|
+
}
|
772
|
+
return childItem;
|
773
|
+
}
|
774
|
+
);
|
775
|
+
};
|
776
|
+
|
777
|
+
// ../core/reducer/actions/duplicate.ts
|
778
|
+
init_react_import();
|
779
|
+
|
780
|
+
// ../core/lib/data/get-item.ts
|
781
|
+
init_react_import();
|
782
|
+
function getItem(selector, state) {
|
783
|
+
var _a, _b;
|
784
|
+
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
785
|
+
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
786
|
+
}
|
787
|
+
|
788
|
+
// ../core/reducer/actions/duplicate.ts
|
789
|
+
function duplicateAction(state, action, appStore) {
|
790
|
+
const item = getItem(
|
791
|
+
{ index: action.sourceIndex, zone: action.sourceZone },
|
792
|
+
state
|
793
|
+
);
|
794
|
+
const idsInPath = getIdsForParent(action.sourceZone, state);
|
795
|
+
const newItem = __spreadProps(__spreadValues({}, item), {
|
796
|
+
props: __spreadProps(__spreadValues({}, item.props), {
|
797
|
+
id: generateId(item.type)
|
798
|
+
})
|
799
|
+
});
|
800
|
+
const modified = walkTree(
|
801
|
+
state,
|
802
|
+
appStore.config,
|
709
803
|
(content, zoneCompound) => {
|
710
|
-
if (zoneCompound === action.
|
711
|
-
return insert(
|
712
|
-
content || [],
|
713
|
-
action.destinationIndex,
|
714
|
-
emptyComponentData
|
715
|
-
);
|
804
|
+
if (zoneCompound === action.sourceZone) {
|
805
|
+
return insert(content, action.sourceIndex + 1, item);
|
716
806
|
}
|
717
807
|
return content;
|
718
808
|
},
|
719
|
-
(childItem, path) => {
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
return childItem
|
724
|
-
|
809
|
+
(childItem, path, index) => {
|
810
|
+
const zoneCompound = path[path.length - 1];
|
811
|
+
const parents = path.map((p) => p.split(":")[0]);
|
812
|
+
if (parents.indexOf(newItem.props.id) > -1) {
|
813
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
814
|
+
props: __spreadProps(__spreadValues({}, childItem.props), {
|
815
|
+
id: generateId(childItem.type)
|
816
|
+
})
|
817
|
+
});
|
818
|
+
}
|
819
|
+
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
820
|
+
return newItem;
|
821
|
+
}
|
822
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
823
|
+
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
725
824
|
return childItem;
|
726
825
|
}
|
727
826
|
return null;
|
728
827
|
}
|
729
828
|
);
|
829
|
+
return __spreadProps(__spreadValues({}, modified), {
|
830
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
831
|
+
itemSelector: {
|
832
|
+
index: action.sourceIndex + 1,
|
833
|
+
zone: action.sourceZone
|
834
|
+
}
|
835
|
+
})
|
836
|
+
});
|
730
837
|
}
|
838
|
+
|
839
|
+
// ../core/reducer/actions/reorder.ts
|
840
|
+
init_react_import();
|
841
|
+
|
842
|
+
// ../core/reducer/actions/move.ts
|
843
|
+
init_react_import();
|
844
|
+
|
845
|
+
// ../core/lib/data/remove.ts
|
846
|
+
init_react_import();
|
847
|
+
var remove = (list, index) => {
|
848
|
+
const result = Array.from(list);
|
849
|
+
result.splice(index, 1);
|
850
|
+
return result;
|
851
|
+
};
|
852
|
+
|
853
|
+
// ../core/reducer/actions/move.ts
|
731
854
|
var moveAction = (state, action, appStore) => {
|
732
855
|
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
733
856
|
return state;
|
@@ -767,57 +890,26 @@ var moveAction = (state, action, appStore) => {
|
|
767
890
|
}
|
768
891
|
);
|
769
892
|
};
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
const idChanged = originalId !== action.data.props.id;
|
775
|
-
if (idChanged) {
|
776
|
-
throw new Error(
|
777
|
-
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
778
|
-
);
|
779
|
-
}
|
780
|
-
return walkTree(
|
893
|
+
|
894
|
+
// ../core/reducer/actions/reorder.ts
|
895
|
+
var reorderAction = (state, action, appStore) => {
|
896
|
+
return moveAction(
|
781
897
|
state,
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
return newContent;
|
898
|
+
{
|
899
|
+
type: "move",
|
900
|
+
sourceIndex: action.sourceIndex,
|
901
|
+
sourceZone: action.destinationZone,
|
902
|
+
destinationIndex: action.destinationIndex,
|
903
|
+
destinationZone: action.destinationZone
|
789
904
|
},
|
790
|
-
|
791
|
-
const pathIds = path.map((p) => p.split(":")[0]);
|
792
|
-
if (childItem.props.id === action.data.props.id) {
|
793
|
-
return action.data;
|
794
|
-
} else if (childItem.props.id === parentId) {
|
795
|
-
return childItem;
|
796
|
-
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
797
|
-
return childItem;
|
798
|
-
} else if (pathIds.indexOf(action.data.props.id) > -1) {
|
799
|
-
return childItem;
|
800
|
-
}
|
801
|
-
return null;
|
802
|
-
}
|
905
|
+
appStore
|
803
906
|
);
|
804
907
|
};
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
if (action.state.indexes) {
|
809
|
-
console.warn(
|
810
|
-
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
811
|
-
);
|
812
|
-
return newState;
|
813
|
-
}
|
814
|
-
return walkTree(newState, appStore.config);
|
815
|
-
}
|
816
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
817
|
-
};
|
908
|
+
|
909
|
+
// ../core/reducer/actions/remove.ts
|
910
|
+
init_react_import();
|
818
911
|
var removeAction = (state, action, appStore) => {
|
819
912
|
const item = getItem({ index: action.index, zone: action.zone }, state);
|
820
|
-
const [parentId] = action.zone.split(":");
|
821
913
|
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
822
914
|
(acc, [nodeId, nodeData]) => {
|
823
915
|
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
@@ -836,24 +928,17 @@ var removeAction = (state, action, appStore) => {
|
|
836
928
|
return remove(content, action.index);
|
837
929
|
}
|
838
930
|
return content;
|
839
|
-
},
|
840
|
-
(childItem, path) => {
|
841
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
842
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
843
|
-
return childItem;
|
844
|
-
}
|
845
|
-
return null;
|
846
931
|
}
|
847
932
|
);
|
848
933
|
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
849
|
-
const
|
850
|
-
if (nodesToDelete.includes(
|
934
|
+
const parentId = zoneCompound.split(":")[0];
|
935
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
851
936
|
delete newState.data.zones[zoneCompound];
|
852
937
|
}
|
853
938
|
});
|
854
939
|
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
855
|
-
const
|
856
|
-
if (nodesToDelete.includes(
|
940
|
+
const parentId = zoneCompound.split(":")[0];
|
941
|
+
if (nodesToDelete.includes(parentId)) {
|
857
942
|
delete newState.indexes.zones[zoneCompound];
|
858
943
|
}
|
859
944
|
});
|
@@ -862,168 +947,104 @@ var removeAction = (state, action, appStore) => {
|
|
862
947
|
});
|
863
948
|
return newState;
|
864
949
|
};
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
if (
|
873
|
-
return
|
874
|
-
}
|
875
|
-
if (action.type === "replaceRoot") {
|
876
|
-
return walkTree(
|
877
|
-
state,
|
878
|
-
appStore.config,
|
879
|
-
(content) => content,
|
880
|
-
(childItem) => {
|
881
|
-
if (childItem.props.id === "root") {
|
882
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
883
|
-
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
884
|
-
readOnly: action.root.readOnly
|
885
|
-
});
|
886
|
-
}
|
887
|
-
return childItem;
|
888
|
-
}
|
889
|
-
);
|
890
|
-
}
|
891
|
-
if (action.type === "duplicate") {
|
892
|
-
const item = getItem(
|
893
|
-
{ index: action.sourceIndex, zone: action.sourceZone },
|
894
|
-
state
|
895
|
-
);
|
896
|
-
const idsInPath = getIdsForParent(action.sourceZone, state);
|
897
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
898
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
899
|
-
id: generateId(item.type)
|
900
|
-
})
|
901
|
-
});
|
902
|
-
const modified = walkTree(
|
903
|
-
state,
|
904
|
-
appStore.config,
|
905
|
-
(content, zoneCompound) => {
|
906
|
-
if (zoneCompound === action.sourceZone) {
|
907
|
-
return insert(content, action.sourceIndex + 1, item);
|
908
|
-
}
|
909
|
-
return content;
|
910
|
-
},
|
911
|
-
(childItem, path, index) => {
|
912
|
-
const zoneCompound = path[path.length - 1];
|
913
|
-
const parents = path.map((p) => p.split(":")[0]);
|
914
|
-
if (parents.indexOf(newItem.props.id) > -1) {
|
915
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
916
|
-
props: __spreadProps(__spreadValues({}, childItem.props), {
|
917
|
-
id: generateId(childItem.type)
|
918
|
-
})
|
919
|
-
});
|
920
|
-
}
|
921
|
-
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
922
|
-
return newItem;
|
923
|
-
}
|
924
|
-
const [sourceZoneParent] = action.sourceZone.split(":");
|
925
|
-
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
926
|
-
return childItem;
|
927
|
-
}
|
928
|
-
return null;
|
929
|
-
}
|
930
|
-
);
|
931
|
-
return __spreadProps(__spreadValues({}, modified), {
|
932
|
-
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
933
|
-
itemSelector: {
|
934
|
-
index: action.sourceIndex + 1,
|
935
|
-
zone: action.sourceZone
|
936
|
-
}
|
937
|
-
})
|
938
|
-
});
|
939
|
-
}
|
940
|
-
if (action.type === "reorder") {
|
941
|
-
return moveAction(
|
942
|
-
state,
|
943
|
-
{
|
944
|
-
type: "move",
|
945
|
-
sourceIndex: action.sourceIndex,
|
946
|
-
sourceZone: action.destinationZone,
|
947
|
-
destinationIndex: action.destinationIndex,
|
948
|
-
destinationZone: action.destinationZone
|
949
|
-
},
|
950
|
-
appStore
|
951
|
-
);
|
952
|
-
}
|
953
|
-
if (action.type === "move") {
|
954
|
-
return moveAction(state, action, appStore);
|
955
|
-
}
|
956
|
-
if (action.type === "remove") {
|
957
|
-
return removeAction(state, action, appStore);
|
958
|
-
}
|
959
|
-
if (action.type === "registerZone") {
|
960
|
-
if (zoneCache[action.zone]) {
|
961
|
-
return __spreadProps(__spreadValues({}, state), {
|
962
|
-
data: __spreadProps(__spreadValues({}, state.data), {
|
963
|
-
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
964
|
-
[action.zone]: zoneCache[action.zone]
|
965
|
-
})
|
966
|
-
}),
|
967
|
-
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
968
|
-
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
969
|
-
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
970
|
-
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
971
|
-
type: "dropzone"
|
972
|
-
})
|
973
|
-
})
|
974
|
-
})
|
975
|
-
});
|
976
|
-
}
|
977
|
-
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
950
|
+
|
951
|
+
// ../core/reducer/actions/register-zone.ts
|
952
|
+
init_react_import();
|
953
|
+
|
954
|
+
// ../core/lib/data/setup-zone.ts
|
955
|
+
init_react_import();
|
956
|
+
var setupZone = (data, zoneKey) => {
|
957
|
+
if (zoneKey === rootDroppableId) {
|
958
|
+
return data;
|
978
959
|
}
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
960
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
961
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
962
|
+
});
|
963
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
964
|
+
return newData;
|
965
|
+
};
|
966
|
+
|
967
|
+
// ../core/reducer/actions/register-zone.ts
|
968
|
+
var zoneCache = {};
|
969
|
+
function registerZoneAction(state, action) {
|
970
|
+
if (zoneCache[action.zone]) {
|
987
971
|
return __spreadProps(__spreadValues({}, state), {
|
988
972
|
data: __spreadProps(__spreadValues({}, state.data), {
|
989
|
-
zones:
|
973
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
974
|
+
[action.zone]: zoneCache[action.zone]
|
975
|
+
})
|
990
976
|
}),
|
991
977
|
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
992
|
-
zones:
|
978
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
979
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
980
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
981
|
+
type: "dropzone"
|
982
|
+
})
|
983
|
+
})
|
993
984
|
})
|
994
985
|
});
|
995
986
|
}
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
}
|
987
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
988
|
+
}
|
989
|
+
function unregisterZoneAction(state, action) {
|
990
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
991
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
992
|
+
if (_zones[action.zone]) {
|
993
|
+
zoneCache[action.zone] = _zones[action.zone];
|
994
|
+
delete _zones[action.zone];
|
995
|
+
}
|
996
|
+
delete zoneIndex[action.zone];
|
997
|
+
return __spreadProps(__spreadValues({}, state), {
|
998
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
999
|
+
zones: _zones
|
1000
|
+
}),
|
1001
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1002
|
+
zones: zoneIndex
|
1003
|
+
})
|
1004
|
+
});
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
// ../core/reducer/actions/set-data.ts
|
1008
|
+
init_react_import();
|
1009
|
+
var setDataAction = (state, action, appStore) => {
|
1010
|
+
if (typeof action.data === "object") {
|
1011
|
+
console.warn(
|
1012
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1013
|
+
);
|
1008
1014
|
return walkTree(
|
1009
1015
|
__spreadProps(__spreadValues({}, state), {
|
1010
|
-
data: __spreadValues(__spreadValues({}, state.data), action.data
|
1016
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1011
1017
|
}),
|
1012
1018
|
appStore.config
|
1013
1019
|
);
|
1014
1020
|
}
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
+
return walkTree(
|
1022
|
+
__spreadProps(__spreadValues({}, state), {
|
1023
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1024
|
+
}),
|
1025
|
+
appStore.config
|
1026
|
+
);
|
1027
|
+
};
|
1028
|
+
|
1029
|
+
// ../core/reducer/actions/set-ui.ts
|
1030
|
+
init_react_import();
|
1031
|
+
var setUiAction = (state, action) => {
|
1032
|
+
if (typeof action.ui === "object") {
|
1021
1033
|
return __spreadProps(__spreadValues({}, state), {
|
1022
|
-
ui: __spreadValues(__spreadValues({}, state.ui), action.ui
|
1034
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
1023
1035
|
});
|
1024
1036
|
}
|
1025
|
-
return state
|
1026
|
-
}
|
1037
|
+
return __spreadProps(__spreadValues({}, state), {
|
1038
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
1039
|
+
});
|
1040
|
+
};
|
1041
|
+
|
1042
|
+
// ../core/lib/data/make-state-public.ts
|
1043
|
+
init_react_import();
|
1044
|
+
var makeStatePublic = (state) => {
|
1045
|
+
const { data, ui } = state;
|
1046
|
+
return { data, ui };
|
1047
|
+
};
|
1027
1048
|
|
1028
1049
|
// ../core/reducer/actions.tsx
|
1029
1050
|
init_react_import();
|
@@ -1042,7 +1063,7 @@ function storeInterceptor(reducer, record, onAction) {
|
|
1042
1063
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
1043
1064
|
if (record) record(newAppState);
|
1044
1065
|
}
|
1045
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1066
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
1046
1067
|
return newAppState;
|
1047
1068
|
};
|
1048
1069
|
}
|
@@ -1053,8 +1074,43 @@ function createReducer({
|
|
1053
1074
|
}) {
|
1054
1075
|
return storeInterceptor(
|
1055
1076
|
(state, action) => {
|
1056
|
-
|
1057
|
-
|
1077
|
+
if (action.type === "set") {
|
1078
|
+
return setAction(state, action, appStore);
|
1079
|
+
}
|
1080
|
+
if (action.type === "insert") {
|
1081
|
+
return insertAction(state, action, appStore);
|
1082
|
+
}
|
1083
|
+
if (action.type === "replace") {
|
1084
|
+
return replaceAction(state, action, appStore);
|
1085
|
+
}
|
1086
|
+
if (action.type === "replaceRoot") {
|
1087
|
+
return replaceRootAction(state, action, appStore);
|
1088
|
+
}
|
1089
|
+
if (action.type === "duplicate") {
|
1090
|
+
return duplicateAction(state, action, appStore);
|
1091
|
+
}
|
1092
|
+
if (action.type === "reorder") {
|
1093
|
+
return reorderAction(state, action, appStore);
|
1094
|
+
}
|
1095
|
+
if (action.type === "move") {
|
1096
|
+
return moveAction(state, action, appStore);
|
1097
|
+
}
|
1098
|
+
if (action.type === "remove") {
|
1099
|
+
return removeAction(state, action, appStore);
|
1100
|
+
}
|
1101
|
+
if (action.type === "registerZone") {
|
1102
|
+
return registerZoneAction(state, action);
|
1103
|
+
}
|
1104
|
+
if (action.type === "unregisterZone") {
|
1105
|
+
return unregisterZoneAction(state, action);
|
1106
|
+
}
|
1107
|
+
if (action.type === "setData") {
|
1108
|
+
return setDataAction(state, action, appStore);
|
1109
|
+
}
|
1110
|
+
if (action.type === "setUi") {
|
1111
|
+
return setUiAction(state, action);
|
1112
|
+
}
|
1113
|
+
return state;
|
1058
1114
|
},
|
1059
1115
|
record,
|
1060
1116
|
onAction
|
@@ -1249,7 +1305,7 @@ var createHistorySlice = (set, get) => {
|
|
1249
1305
|
const { dispatch, history } = get();
|
1250
1306
|
dispatch({
|
1251
1307
|
type: "set",
|
1252
|
-
state: ((_a = history.histories[
|
1308
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1253
1309
|
});
|
1254
1310
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1255
1311
|
},
|
@@ -1298,7 +1354,7 @@ var createNodesSlice = (set, get) => ({
|
|
1298
1354
|
init_react_import();
|
1299
1355
|
var import_react7 = require("react");
|
1300
1356
|
|
1301
|
-
// ../core/lib/flatten-data.ts
|
1357
|
+
// ../core/lib/data/flatten-data.ts
|
1302
1358
|
init_react_import();
|
1303
1359
|
var flattenData = (state, config) => {
|
1304
1360
|
const data = [];
|
@@ -1333,12 +1389,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1333
1389
|
const { cache: cache2, globalPermissions } = permissions;
|
1334
1390
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1335
1391
|
var _a, _b, _c;
|
1336
|
-
const {
|
1337
|
-
config: config2,
|
1338
|
-
state: appState,
|
1339
|
-
setComponentLoading,
|
1340
|
-
unsetComponentLoading
|
1341
|
-
} = get();
|
1392
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1342
1393
|
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1343
1394
|
if (!componentConfig) {
|
1344
1395
|
return;
|
@@ -1347,14 +1398,14 @@ var createPermissionsSlice = (set, get) => {
|
|
1347
1398
|
if (componentConfig.resolvePermissions) {
|
1348
1399
|
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1349
1400
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1350
|
-
setComponentLoading(item2.props.id);
|
1401
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1351
1402
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1352
1403
|
item2,
|
1353
1404
|
{
|
1354
1405
|
changed,
|
1355
1406
|
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1356
1407
|
permissions: initialPermissions,
|
1357
|
-
appState,
|
1408
|
+
appState: makeStatePublic(appState),
|
1358
1409
|
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1359
1410
|
}
|
1360
1411
|
);
|
@@ -1372,7 +1423,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1372
1423
|
})
|
1373
1424
|
})
|
1374
1425
|
});
|
1375
|
-
|
1426
|
+
clearTimeout2();
|
1376
1427
|
}
|
1377
1428
|
}
|
1378
1429
|
});
|
@@ -1382,7 +1433,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1382
1433
|
// Shim the root data in by conforming to component data shape
|
1383
1434
|
{
|
1384
1435
|
type: "root",
|
1385
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1436
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1386
1437
|
},
|
1387
1438
|
force2
|
1388
1439
|
);
|
@@ -1397,7 +1448,6 @@ var createPermissionsSlice = (set, get) => {
|
|
1397
1448
|
} else if (root) {
|
1398
1449
|
resolveDataForRoot(force);
|
1399
1450
|
} else {
|
1400
|
-
resolveDataForRoot(force);
|
1401
1451
|
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1402
1452
|
yield resolveDataForItem(item2, force);
|
1403
1453
|
}));
|
@@ -1428,7 +1478,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1428
1478
|
} else if (root) {
|
1429
1479
|
const rootConfig = config.root;
|
1430
1480
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1431
|
-
const resolvedForItem = resolvedPermissions["
|
1481
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1432
1482
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1433
1483
|
}
|
1434
1484
|
return globalPermissions;
|
@@ -1452,24 +1502,25 @@ var createFieldsSlice = (_set, _get) => {
|
|
1452
1502
|
// ../core/lib/resolve-component-data.ts
|
1453
1503
|
init_react_import();
|
1454
1504
|
|
1455
|
-
// ../core/lib/map-slots.ts
|
1505
|
+
// ../core/lib/data/map-slots.ts
|
1456
1506
|
init_react_import();
|
1457
|
-
function
|
1458
|
-
return __async(this,
|
1507
|
+
function mapSlotsAsync(_0, _1) {
|
1508
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1459
1509
|
const props = __spreadValues({}, item.props);
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1510
|
+
const propKeys = Object.keys(props);
|
1511
|
+
for (let i = 0; i < propKeys.length; i++) {
|
1512
|
+
const propKey = propKeys[i];
|
1513
|
+
const itemType = "type" in item ? item.type : "root";
|
1514
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
1515
|
+
const content = props[propKey];
|
1463
1516
|
const mappedContent = recursive ? yield Promise.all(
|
1464
1517
|
content.map((item2) => __async(this, null, function* () {
|
1465
|
-
return yield
|
1518
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
1466
1519
|
}))
|
1467
1520
|
) : content;
|
1468
|
-
props[
|
1469
|
-
}
|
1470
|
-
|
1471
|
-
isSlot2
|
1472
|
-
);
|
1521
|
+
props[propKey] = yield map(mappedContent, propKey);
|
1522
|
+
}
|
1523
|
+
}
|
1473
1524
|
return __spreadProps(__spreadValues({}, item), { props });
|
1474
1525
|
});
|
1475
1526
|
}
|
@@ -1492,14 +1543,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1492
1543
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1493
1544
|
changed,
|
1494
1545
|
lastData: oldItem,
|
1495
|
-
metadata,
|
1546
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1496
1547
|
trigger
|
1497
1548
|
});
|
1498
1549
|
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1499
1550
|
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1500
1551
|
});
|
1501
1552
|
if (recursive) {
|
1502
|
-
resolvedItem = yield
|
1553
|
+
resolvedItem = yield mapSlotsAsync(
|
1503
1554
|
resolvedItem,
|
1504
1555
|
(content) => __async(void 0, null, function* () {
|
1505
1556
|
return Promise.all(
|
@@ -1537,7 +1588,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1537
1588
|
return { node: item, didChange: false };
|
1538
1589
|
});
|
1539
1590
|
|
1540
|
-
// ../core/lib/to-root.ts
|
1591
|
+
// ../core/lib/data/to-root.ts
|
1541
1592
|
init_react_import();
|
1542
1593
|
var toRoot = (item) => {
|
1543
1594
|
if ("type" in item && item.type !== "root") {
|
@@ -1584,166 +1635,176 @@ var defaultPageFields = {
|
|
1584
1635
|
title: { type: "text" }
|
1585
1636
|
};
|
1586
1637
|
var createAppStore = (initialAppStore) => create()(
|
1587
|
-
subscribeWithSelector((set, get) =>
|
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
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1638
|
+
subscribeWithSelector((set, get) => {
|
1639
|
+
var _a, _b;
|
1640
|
+
return __spreadProps(__spreadValues({
|
1641
|
+
state: defaultAppState,
|
1642
|
+
config: { components: {} },
|
1643
|
+
componentState: {},
|
1644
|
+
plugins: [],
|
1645
|
+
overrides: {},
|
1646
|
+
viewports: defaultViewports,
|
1647
|
+
zoomConfig: {
|
1648
|
+
autoZoom: 1,
|
1649
|
+
rootHeight: 0,
|
1650
|
+
zoom: 1
|
1651
|
+
},
|
1652
|
+
status: "LOADING",
|
1653
|
+
iframe: {},
|
1654
|
+
metadata: {}
|
1655
|
+
}, initialAppStore), {
|
1656
|
+
fields: createFieldsSlice(set, get),
|
1657
|
+
history: createHistorySlice(set, get),
|
1658
|
+
nodes: createNodesSlice(set, get),
|
1659
|
+
permissions: createPermissionsSlice(set, get),
|
1660
|
+
getComponentConfig: (type) => {
|
1661
|
+
var _a2;
|
1662
|
+
const { config, selectedItem } = get();
|
1663
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1664
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1665
|
+
},
|
1666
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1667
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1668
|
+
initialAppStore.state
|
1669
|
+
) : null,
|
1670
|
+
dispatch: (action) => set((s) => {
|
1671
|
+
var _a2, _b2;
|
1672
|
+
const { record } = get().history;
|
1673
|
+
const dispatch = createReducer({
|
1674
|
+
record,
|
1675
|
+
appStore: s
|
1676
|
+
});
|
1677
|
+
const state = dispatch(s.state, action);
|
1678
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1679
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1680
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1681
|
+
}),
|
1682
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1683
|
+
setStatus: (status) => set({ status }),
|
1684
|
+
setComponentState: (componentState) => set({ componentState }),
|
1685
|
+
pendingLoadTimeouts: {},
|
1686
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1687
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1688
|
+
const loadId = generateId();
|
1689
|
+
const setLoading = () => {
|
1690
|
+
var _a2;
|
1691
|
+
const { componentState } = get();
|
1692
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1693
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1694
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1695
|
+
})
|
1696
|
+
}));
|
1697
|
+
};
|
1698
|
+
const unsetLoading = () => {
|
1699
|
+
var _a2;
|
1700
|
+
const { componentState } = get();
|
1701
|
+
clearTimeout(timeout);
|
1702
|
+
delete pendingLoadTimeouts[loadId];
|
1703
|
+
set({ pendingLoadTimeouts });
|
1704
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1705
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1706
|
+
loadingCount: Math.max(
|
1707
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1708
|
+
0
|
1709
|
+
)
|
1710
|
+
})
|
1711
|
+
}));
|
1712
|
+
};
|
1713
|
+
const timeout = setTimeout(() => {
|
1714
|
+
if (loading) {
|
1715
|
+
setLoading();
|
1716
|
+
} else {
|
1717
|
+
unsetLoading();
|
1718
|
+
}
|
1719
|
+
delete pendingLoadTimeouts[loadId];
|
1720
|
+
set({ pendingLoadTimeouts });
|
1721
|
+
}, defer);
|
1722
|
+
set({
|
1723
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1724
|
+
[id]: timeout
|
1650
1725
|
})
|
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
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1691
|
-
}),
|
1692
|
-
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1693
|
-
const { config, metadata, setComponentLoading } = get();
|
1694
|
-
return yield resolveComponentData(
|
1695
|
-
componentData,
|
1696
|
-
config,
|
1697
|
-
metadata,
|
1698
|
-
(item) => setComponentLoading(
|
1699
|
-
"id" in item.props ? item.props.id : "root",
|
1700
|
-
true,
|
1701
|
-
50
|
1702
|
-
),
|
1703
|
-
(item) => setComponentLoading(
|
1704
|
-
"id" in item.props ? item.props.id : "root",
|
1705
|
-
false,
|
1706
|
-
0
|
1707
|
-
),
|
1708
|
-
trigger
|
1709
|
-
);
|
1710
|
-
}),
|
1711
|
-
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1712
|
-
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1713
|
-
walkTree(
|
1714
|
-
state,
|
1715
|
-
config,
|
1716
|
-
(content) => content,
|
1717
|
-
(childItem) => {
|
1718
|
-
resolveComponentData2(childItem, "load").then((resolved) => {
|
1719
|
-
const { state: state2 } = get();
|
1720
|
-
const node = state2.indexes.nodes[resolved.node.props.id];
|
1721
|
-
if (node && resolved.didChange) {
|
1722
|
-
if (resolved.node.props.id === "root") {
|
1723
|
-
dispatch({
|
1724
|
-
type: "replaceRoot",
|
1725
|
-
root: toRoot(resolved.node)
|
1726
|
-
});
|
1727
|
-
} else {
|
1728
|
-
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1729
|
-
const parentZone = state2.indexes.zones[zoneCompound];
|
1730
|
-
const index = parentZone.contentIds.indexOf(
|
1731
|
-
resolved.node.props.id
|
1732
|
-
);
|
1733
|
-
dispatch({
|
1734
|
-
type: "replace",
|
1735
|
-
data: resolved.node,
|
1736
|
-
destinationIndex: index,
|
1737
|
-
destinationZone: zoneCompound
|
1738
|
-
});
|
1739
|
-
}
|
1726
|
+
});
|
1727
|
+
return unsetLoading;
|
1728
|
+
},
|
1729
|
+
unsetComponentLoading: (id) => {
|
1730
|
+
const { setComponentLoading } = get();
|
1731
|
+
setComponentLoading(id, false);
|
1732
|
+
},
|
1733
|
+
// Helper
|
1734
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1735
|
+
const dispatch = createReducer({
|
1736
|
+
record: () => {
|
1737
|
+
},
|
1738
|
+
appStore: s
|
1739
|
+
});
|
1740
|
+
const state = dispatch(s.state, {
|
1741
|
+
type: "setUi",
|
1742
|
+
ui,
|
1743
|
+
recordHistory
|
1744
|
+
});
|
1745
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1746
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1747
|
+
}),
|
1748
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1749
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
1750
|
+
const timeouts = {};
|
1751
|
+
return yield resolveComponentData(
|
1752
|
+
componentData,
|
1753
|
+
config,
|
1754
|
+
metadata,
|
1755
|
+
(item) => {
|
1756
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1757
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
1758
|
+
},
|
1759
|
+
(item) => __async(void 0, null, function* () {
|
1760
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1761
|
+
if ("type" in item) {
|
1762
|
+
yield permissions.refreshPermissions({ item });
|
1763
|
+
} else {
|
1764
|
+
yield permissions.refreshPermissions({ root: true });
|
1740
1765
|
}
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1766
|
+
timeouts[id]();
|
1767
|
+
}),
|
1768
|
+
trigger
|
1769
|
+
);
|
1770
|
+
}),
|
1771
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1772
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1773
|
+
walkTree(
|
1774
|
+
state,
|
1775
|
+
config,
|
1776
|
+
(content) => content,
|
1777
|
+
(childItem) => {
|
1778
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
1779
|
+
const { state: state2 } = get();
|
1780
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
1781
|
+
if (node && resolved.didChange) {
|
1782
|
+
if (resolved.node.props.id === "root") {
|
1783
|
+
dispatch({
|
1784
|
+
type: "replaceRoot",
|
1785
|
+
root: toRoot(resolved.node)
|
1786
|
+
});
|
1787
|
+
} else {
|
1788
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1789
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
1790
|
+
const index = parentZone.contentIds.indexOf(
|
1791
|
+
resolved.node.props.id
|
1792
|
+
);
|
1793
|
+
dispatch({
|
1794
|
+
type: "replace",
|
1795
|
+
data: resolved.node,
|
1796
|
+
destinationIndex: index,
|
1797
|
+
destinationZone: zoneCompound
|
1798
|
+
});
|
1799
|
+
}
|
1800
|
+
}
|
1801
|
+
});
|
1802
|
+
return childItem;
|
1803
|
+
}
|
1804
|
+
);
|
1805
|
+
})
|
1806
|
+
});
|
1807
|
+
})
|
1747
1808
|
);
|
1748
1809
|
var appStoreContext = (0, import_react9.createContext)(createAppStore());
|
1749
1810
|
function useAppStore(selector) {
|
@@ -1805,10 +1866,10 @@ init_react_import();
|
|
1805
1866
|
// ../core/lib/filter.ts
|
1806
1867
|
init_react_import();
|
1807
1868
|
|
1808
|
-
// ../core/lib/reorder.ts
|
1869
|
+
// ../core/lib/data/reorder.ts
|
1809
1870
|
init_react_import();
|
1810
1871
|
|
1811
|
-
// ../core/lib/replace.ts
|
1872
|
+
// ../core/lib/data/replace.ts
|
1812
1873
|
init_react_import();
|
1813
1874
|
|
1814
1875
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
@@ -1994,15 +2055,37 @@ var HeadingAnalyzer = () => {
|
|
1994
2055
|
const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
|
1995
2056
|
(0, import_react11.useEffect)(() => {
|
1996
2057
|
const frame = getFrame();
|
1997
|
-
|
1998
|
-
|
1999
|
-
setHierarchy(buildHierarchy(entry));
|
2000
|
-
const observer = new MutationObserver(() => {
|
2058
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2059
|
+
const createHierarchy = () => {
|
2001
2060
|
setHierarchy(buildHierarchy(entry));
|
2061
|
+
};
|
2062
|
+
const entryObserver = new MutationObserver(() => {
|
2063
|
+
createHierarchy();
|
2064
|
+
});
|
2065
|
+
const frameObserver = new MutationObserver(() => {
|
2066
|
+
entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2067
|
+
if (entry) {
|
2068
|
+
registerEntryObserver();
|
2069
|
+
frameObserver.disconnect();
|
2070
|
+
}
|
2002
2071
|
});
|
2003
|
-
|
2072
|
+
const registerEntryObserver = () => {
|
2073
|
+
if (!entry) return;
|
2074
|
+
entryObserver.observe(entry, { subtree: true, childList: true });
|
2075
|
+
};
|
2076
|
+
const registerFrameObserver = () => {
|
2077
|
+
if (!frame) return;
|
2078
|
+
frameObserver.observe(frame, { subtree: true, childList: true });
|
2079
|
+
};
|
2080
|
+
if (entry) {
|
2081
|
+
createHierarchy();
|
2082
|
+
registerEntryObserver();
|
2083
|
+
} else {
|
2084
|
+
registerFrameObserver();
|
2085
|
+
}
|
2004
2086
|
return () => {
|
2005
|
-
|
2087
|
+
entryObserver.disconnect();
|
2088
|
+
frameObserver.disconnect();
|
2006
2089
|
};
|
2007
2090
|
}, [data]);
|
2008
2091
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
|