@measured/puck-plugin-heading-analyzer 0.19.0-canary.85ee736 → 0.19.0-canary.896a6279
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 +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +981 -673
- package/dist/index.mjs +974 -666
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -187,7 +187,7 @@ init_react_import();
|
|
187
187
|
|
188
188
|
// src/HeadingAnalyzer.tsx
|
189
189
|
init_react_import();
|
190
|
-
import { useEffect as
|
190
|
+
import { useEffect as useEffect5, useState } from "react";
|
191
191
|
|
192
192
|
// css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
|
193
193
|
init_react_import();
|
@@ -356,75 +356,247 @@ 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
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
364
|
+
|
365
|
+
// ../core/lib/data/for-each-slot.ts
|
366
|
+
init_react_import();
|
367
|
+
|
368
|
+
// ../core/lib/data/is-slot.ts
|
369
|
+
init_react_import();
|
370
|
+
var isSlot = (prop) => {
|
371
|
+
var _a, _b;
|
372
|
+
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
373
|
+
};
|
374
|
+
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
375
|
+
var _a, _b;
|
376
|
+
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
377
|
+
if (!configForComponent) return isSlot(propValue);
|
378
|
+
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
369
379
|
};
|
370
380
|
|
381
|
+
// ../core/lib/data/for-each-slot.ts
|
382
|
+
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
383
|
+
const props = item.props || {};
|
384
|
+
const propKeys = Object.keys(props);
|
385
|
+
for (let i = 0; i < propKeys.length; i++) {
|
386
|
+
const propKey = propKeys[i];
|
387
|
+
const itemType = "type" in item ? item.type : "root";
|
388
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
389
|
+
const content = props[propKey];
|
390
|
+
cb(props.id, propKey, content);
|
391
|
+
if (recursive) {
|
392
|
+
content.forEach(
|
393
|
+
(childItem) => __async(void 0, null, function* () {
|
394
|
+
return forEachSlot(childItem, cb, true, isSlot2);
|
395
|
+
})
|
396
|
+
);
|
397
|
+
}
|
398
|
+
}
|
399
|
+
}
|
400
|
+
};
|
401
|
+
|
402
|
+
// ../core/lib/data/for-related-zones.ts
|
403
|
+
init_react_import();
|
404
|
+
|
405
|
+
// ../core/lib/get-zone-id.ts
|
406
|
+
init_react_import();
|
407
|
+
|
371
408
|
// ../core/lib/root-droppable-id.ts
|
372
409
|
init_react_import();
|
373
410
|
var rootAreaId = "root";
|
374
411
|
var rootZone = "default-zone";
|
375
412
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
376
413
|
|
377
|
-
// ../core/lib/
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
414
|
+
// ../core/lib/get-zone-id.ts
|
415
|
+
var getZoneId = (zoneCompound) => {
|
416
|
+
if (!zoneCompound) {
|
417
|
+
return [];
|
418
|
+
}
|
419
|
+
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
420
|
+
return zoneCompound.split(":");
|
421
|
+
}
|
422
|
+
return [rootDroppableId, zoneCompound];
|
383
423
|
};
|
384
424
|
|
385
|
-
// ../core/lib/
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
}
|
425
|
+
// ../core/lib/data/for-related-zones.ts
|
426
|
+
function forRelatedZones(item, data, cb, path = []) {
|
427
|
+
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
428
|
+
const [parentId] = getZoneId(zoneCompound);
|
429
|
+
if (parentId === item.props.id) {
|
430
|
+
cb(path, zoneCompound, content);
|
431
|
+
}
|
432
|
+
});
|
433
|
+
}
|
392
434
|
|
393
|
-
// ../core/lib/
|
435
|
+
// ../core/lib/data/strip-slots.ts
|
394
436
|
init_react_import();
|
395
|
-
var
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
437
|
+
var stripSlots = (data) => {
|
438
|
+
return __spreadProps(__spreadValues({}, data), {
|
439
|
+
props: Object.entries(data.props).reduce(
|
440
|
+
(acc, [propKey, propVal]) => {
|
441
|
+
if (isSlot(propVal)) {
|
442
|
+
return acc;
|
443
|
+
}
|
444
|
+
return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
|
445
|
+
},
|
446
|
+
{ id: data.props.id }
|
447
|
+
)
|
401
448
|
});
|
402
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
403
|
-
return newData;
|
404
449
|
};
|
405
450
|
|
406
|
-
// ../core/lib/
|
407
|
-
|
408
|
-
var
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
451
|
+
// ../core/lib/data/walk-tree.ts
|
452
|
+
function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
453
|
+
var _a;
|
454
|
+
let newZones = {};
|
455
|
+
const newZoneIndex = {};
|
456
|
+
const newNodeIndex = {};
|
457
|
+
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
458
|
+
var _a2;
|
459
|
+
const [parentId] = zoneCompound.split(":");
|
460
|
+
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
461
|
+
const [_2, zone] = zoneCompound.split(":");
|
462
|
+
const newZoneCompound = `${newId || parentId}:${zone}`;
|
463
|
+
const newContent2 = mappedContent.map(
|
464
|
+
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
465
|
+
);
|
466
|
+
newZoneIndex[newZoneCompound] = {
|
467
|
+
contentIds: newContent2.map((item) => item.props.id),
|
468
|
+
type: zoneType
|
469
|
+
};
|
470
|
+
return [newZoneCompound, newContent2];
|
471
|
+
};
|
472
|
+
const processRelatedZones = (item, newId, initialPath) => {
|
473
|
+
forRelatedZones(
|
474
|
+
item,
|
475
|
+
state.data,
|
476
|
+
(relatedPath, relatedZoneCompound, relatedContent) => {
|
477
|
+
const [zoneCompound, newContent2] = processContent(
|
478
|
+
relatedPath,
|
479
|
+
relatedZoneCompound,
|
480
|
+
relatedContent,
|
481
|
+
"dropzone",
|
482
|
+
newId
|
483
|
+
);
|
484
|
+
newZones[zoneCompound] = newContent2;
|
485
|
+
},
|
486
|
+
initialPath
|
487
|
+
);
|
488
|
+
};
|
489
|
+
const processItem = (item, path, index) => {
|
490
|
+
const mappedItem = mapNodeOrSkip(item, path, index);
|
491
|
+
if (!mappedItem) return item;
|
492
|
+
const id = mappedItem.props.id;
|
493
|
+
const newProps = __spreadValues({}, mappedItem.props);
|
494
|
+
forEachSlot(
|
495
|
+
mappedItem,
|
496
|
+
(parentId2, slotId, content) => {
|
497
|
+
const zoneCompound = `${parentId2}:${slotId}`;
|
498
|
+
const [_2, newContent2] = processContent(
|
499
|
+
path,
|
500
|
+
zoneCompound,
|
501
|
+
content,
|
502
|
+
"slot",
|
503
|
+
parentId2
|
504
|
+
);
|
505
|
+
newProps[slotId] = newContent2;
|
506
|
+
},
|
507
|
+
false,
|
508
|
+
createIsSlotConfig(config)
|
509
|
+
);
|
510
|
+
processRelatedZones(item, id, path);
|
511
|
+
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
512
|
+
const thisZoneCompound = path[path.length - 1];
|
513
|
+
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
514
|
+
newNodeIndex[id] = {
|
515
|
+
data: newItem,
|
516
|
+
flatData: stripSlots(newItem),
|
517
|
+
path,
|
518
|
+
parentId,
|
519
|
+
zone
|
520
|
+
};
|
521
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
522
|
+
if (newProps.id === "root") {
|
523
|
+
delete finalData["type"];
|
524
|
+
delete finalData.props["id"];
|
525
|
+
}
|
526
|
+
return finalData;
|
527
|
+
};
|
528
|
+
const zones = state.data.zones || {};
|
529
|
+
const [_, newContent] = processContent(
|
530
|
+
[],
|
531
|
+
rootDroppableId,
|
532
|
+
state.data.content,
|
533
|
+
"root"
|
534
|
+
);
|
535
|
+
const processedContent = newContent;
|
536
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
537
|
+
Object.keys(zones || {}).forEach((zoneCompound) => {
|
538
|
+
const [parentId] = zoneCompound.split(":");
|
539
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
540
|
+
return;
|
541
|
+
}
|
542
|
+
const [_2, newContent2] = processContent(
|
543
|
+
[rootDroppableId],
|
544
|
+
zoneCompound,
|
545
|
+
zones[zoneCompound],
|
546
|
+
"dropzone",
|
547
|
+
parentId
|
548
|
+
);
|
549
|
+
newZones[zoneCompound] = newContent2;
|
550
|
+
}, newZones);
|
551
|
+
const processedRoot = processItem(
|
552
|
+
{
|
553
|
+
type: "root",
|
554
|
+
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
555
|
+
},
|
556
|
+
[],
|
557
|
+
-1
|
558
|
+
);
|
559
|
+
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
560
|
+
props: processedRoot.props
|
561
|
+
});
|
562
|
+
return __spreadProps(__spreadValues({}, state), {
|
563
|
+
data: {
|
564
|
+
root,
|
565
|
+
content: processedContent,
|
566
|
+
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
567
|
+
},
|
568
|
+
indexes: {
|
569
|
+
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
570
|
+
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
571
|
+
}
|
572
|
+
});
|
573
|
+
}
|
574
|
+
|
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));
|
413
588
|
};
|
414
589
|
|
415
|
-
// ../core/
|
590
|
+
// ../core/reducer/actions/insert.ts
|
416
591
|
init_react_import();
|
417
|
-
function getItem(selector, data, dynamicProps = {}) {
|
418
|
-
if (!selector.zone || selector.zone === rootDroppableId) {
|
419
|
-
const item2 = data.content[selector.index];
|
420
|
-
return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
|
421
|
-
}
|
422
|
-
const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
|
423
|
-
return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
|
424
|
-
}
|
425
592
|
|
426
|
-
// ../core/lib/
|
593
|
+
// ../core/lib/data/insert.ts
|
427
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
|
+
};
|
428
600
|
|
429
601
|
// ../core/lib/generate-id.ts
|
430
602
|
init_react_import();
|
@@ -488,313 +660,386 @@ var v4_default = v4;
|
|
488
660
|
// ../core/lib/generate-id.ts
|
489
661
|
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
490
662
|
|
491
|
-
// ../core/lib/get-
|
663
|
+
// ../core/lib/data/get-ids-for-parent.ts
|
492
664
|
init_react_import();
|
493
|
-
var
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
498
|
-
return zoneCompound.split(":");
|
499
|
-
}
|
500
|
-
return [rootDroppableId, zoneCompound];
|
665
|
+
var getIdsForParent = (zoneCompound, state) => {
|
666
|
+
const [parentId] = zoneCompound.split(":");
|
667
|
+
const node = state.indexes.nodes[parentId];
|
668
|
+
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
501
669
|
};
|
502
670
|
|
503
|
-
// ../core/
|
504
|
-
function
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
671
|
+
// ../core/reducer/actions/insert.ts
|
672
|
+
function insertAction(state, action, appStore) {
|
673
|
+
const id = action.id || generateId(action.componentType);
|
674
|
+
const emptyComponentData = {
|
675
|
+
type: action.componentType,
|
676
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
677
|
+
id
|
678
|
+
})
|
679
|
+
};
|
680
|
+
const [parentId] = action.destinationZone.split(":");
|
681
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
682
|
+
return walkTree(
|
683
|
+
state,
|
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
|
+
);
|
518
706
|
}
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
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;
|
526
727
|
}
|
527
|
-
return
|
728
|
+
return newContent;
|
528
729
|
},
|
529
|
-
{
|
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
|
+
}
|
530
743
|
);
|
531
744
|
};
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
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
|
540
758
|
});
|
541
759
|
}
|
542
|
-
return
|
543
|
-
}
|
544
|
-
{}
|
760
|
+
return childItem;
|
761
|
+
}
|
545
762
|
);
|
546
763
|
};
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
return
|
557
|
-
const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
|
558
|
-
props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
|
559
|
-
}));
|
560
|
-
const dupeOfDupes = dupedZone.reduce(
|
561
|
-
(dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
|
562
|
-
acc
|
563
|
-
);
|
564
|
-
const [_, zoneId] = getZoneId(key);
|
565
|
-
return __spreadProps(__spreadValues({}, dupeOfDupes), {
|
566
|
-
[key]: zone,
|
567
|
-
[`${newId}:${zoneId}`]: dupedZone
|
568
|
-
});
|
569
|
-
});
|
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;
|
570
774
|
}
|
571
775
|
|
572
|
-
// ../core/reducer/
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
}
|
580
|
-
|
581
|
-
|
582
|
-
zones: __spreadProps(__spreadValues({}, newData.zones), {
|
583
|
-
[action.destinationZone]: replace(
|
584
|
-
newData.zones[action.destinationZone],
|
585
|
-
action.destinationIndex,
|
586
|
-
action.data
|
587
|
-
)
|
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)
|
588
786
|
})
|
589
787
|
});
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
788
|
+
const modified = walkTree(
|
789
|
+
state,
|
790
|
+
appStore.config,
|
791
|
+
(content, zoneCompound) => {
|
792
|
+
if (zoneCompound === action.sourceZone) {
|
793
|
+
return insert(content, action.sourceIndex + 1, item);
|
794
|
+
}
|
795
|
+
return content;
|
796
|
+
},
|
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) {
|
812
|
+
return childItem;
|
813
|
+
}
|
814
|
+
return null;
|
815
|
+
}
|
816
|
+
);
|
817
|
+
return __spreadProps(__spreadValues({}, modified), {
|
818
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
819
|
+
itemSelector: {
|
820
|
+
index: action.sourceIndex + 1,
|
821
|
+
zone: action.sourceZone
|
822
|
+
}
|
615
823
|
})
|
616
824
|
});
|
617
825
|
}
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
const
|
629
|
-
|
630
|
-
|
631
|
-
[action.destinationZone]: reorder(
|
632
|
-
newData.zones[action.destinationZone],
|
633
|
-
action.sourceIndex,
|
634
|
-
action.destinationIndex
|
635
|
-
)
|
636
|
-
})
|
637
|
-
});
|
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;
|
638
839
|
};
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
const item = getItem(
|
645
|
-
{ index: action.sourceIndex, zone: action.sourceZone },
|
646
|
-
data
|
647
|
-
);
|
648
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
649
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
650
|
-
id: generateId(item.type)
|
651
|
-
})
|
652
|
-
});
|
653
|
-
const dataWithRelatedDuplicated = duplicateRelatedZones(
|
654
|
-
item,
|
655
|
-
data,
|
656
|
-
newItem.props.id
|
657
|
-
);
|
658
|
-
if (action.sourceZone === rootDroppableId) {
|
659
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
|
660
|
-
content: insert(data.content, action.sourceIndex + 1, newItem)
|
661
|
-
});
|
662
|
-
}
|
663
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
|
664
|
-
zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
|
665
|
-
[action.sourceZone]: insert(
|
666
|
-
dataWithRelatedDuplicated.zones[action.sourceZone],
|
667
|
-
action.sourceIndex + 1,
|
668
|
-
newItem
|
669
|
-
)
|
670
|
-
})
|
671
|
-
});
|
672
|
-
}
|
673
|
-
if (action.type === "reorder") {
|
674
|
-
return reorderAction(data, action);
|
840
|
+
|
841
|
+
// ../core/reducer/actions/move.ts
|
842
|
+
var moveAction = (state, action, appStore) => {
|
843
|
+
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
844
|
+
return state;
|
675
845
|
}
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
846
|
+
const item = getItem(
|
847
|
+
{ zone: action.sourceZone, index: action.sourceIndex },
|
848
|
+
state
|
849
|
+
);
|
850
|
+
if (!item) return state;
|
851
|
+
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
852
|
+
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
853
|
+
return walkTree(
|
854
|
+
state,
|
855
|
+
appStore.config,
|
856
|
+
(content, zoneCompound) => {
|
857
|
+
if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
|
858
|
+
return insert(
|
859
|
+
remove(content, action.sourceIndex),
|
860
|
+
action.destinationIndex,
|
861
|
+
item
|
862
|
+
);
|
863
|
+
} else if (zoneCompound === action.sourceZone) {
|
864
|
+
return remove(content, action.sourceIndex);
|
865
|
+
} else if (zoneCompound === action.destinationZone) {
|
866
|
+
return insert(content, action.destinationIndex, item);
|
867
|
+
}
|
868
|
+
return content;
|
869
|
+
},
|
870
|
+
(childItem, path) => {
|
871
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
872
|
+
const [destinationZoneParent] = action.destinationZone.split(":");
|
873
|
+
const childId = childItem.props.id;
|
874
|
+
if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
|
875
|
+
return childItem;
|
876
|
+
}
|
877
|
+
return null;
|
690
878
|
}
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
879
|
+
);
|
880
|
+
};
|
881
|
+
|
882
|
+
// ../core/reducer/actions/reorder.ts
|
883
|
+
var reorderAction = (state, action, appStore) => {
|
884
|
+
return moveAction(
|
885
|
+
state,
|
886
|
+
{
|
887
|
+
type: "move",
|
888
|
+
sourceIndex: action.sourceIndex,
|
889
|
+
sourceZone: action.destinationZone,
|
890
|
+
destinationIndex: action.destinationIndex,
|
891
|
+
destinationZone: action.destinationZone
|
892
|
+
},
|
893
|
+
appStore
|
894
|
+
);
|
895
|
+
};
|
896
|
+
|
897
|
+
// ../core/reducer/actions/remove.ts
|
898
|
+
init_react_import();
|
899
|
+
var removeAction = (state, action, appStore) => {
|
900
|
+
const item = getItem({ index: action.index, zone: action.zone }, state);
|
901
|
+
const [parentId] = action.zone.split(":");
|
902
|
+
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
903
|
+
(acc, [nodeId, nodeData]) => {
|
904
|
+
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
905
|
+
if (pathIds.includes(item.props.id)) {
|
906
|
+
return [...acc, nodeId];
|
907
|
+
}
|
908
|
+
return acc;
|
909
|
+
},
|
910
|
+
[item.props.id]
|
911
|
+
);
|
912
|
+
const newState = walkTree(
|
913
|
+
state,
|
914
|
+
appStore.config,
|
915
|
+
(content, zoneCompound) => {
|
916
|
+
if (zoneCompound === action.zone) {
|
917
|
+
return remove(content, action.index);
|
918
|
+
}
|
919
|
+
return content;
|
920
|
+
},
|
921
|
+
(childItem, path) => {
|
922
|
+
const parentIds = path.map((p) => p.split(":")[0]);
|
923
|
+
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
924
|
+
return childItem;
|
925
|
+
}
|
926
|
+
return null;
|
702
927
|
}
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
newData.zones[action.sourceZone],
|
709
|
-
action.sourceIndex
|
710
|
-
)
|
711
|
-
})
|
712
|
-
});
|
928
|
+
);
|
929
|
+
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
930
|
+
const parentId2 = zoneCompound.split(":")[0];
|
931
|
+
if (nodesToDelete.includes(parentId2) && newState.data.zones) {
|
932
|
+
delete newState.data.zones[zoneCompound];
|
713
933
|
}
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
),
|
720
|
-
[action.destinationZone]: insert(
|
721
|
-
newData.zones[action.destinationZone],
|
722
|
-
action.destinationIndex,
|
723
|
-
item
|
724
|
-
)
|
725
|
-
})
|
726
|
-
});
|
727
|
-
}
|
728
|
-
if (action.type === "replace") {
|
729
|
-
return replaceAction(data, action);
|
730
|
-
}
|
731
|
-
if (action.type === "remove") {
|
732
|
-
const item = getItem({ index: action.index, zone: action.zone }, data);
|
733
|
-
const dataWithRelatedRemoved = setupZone(
|
734
|
-
removeRelatedZones(item, data),
|
735
|
-
action.zone
|
736
|
-
);
|
737
|
-
if (action.zone === rootDroppableId) {
|
738
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
|
739
|
-
content: remove(data.content, action.index)
|
740
|
-
});
|
934
|
+
});
|
935
|
+
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
936
|
+
const parentId2 = zoneCompound.split(":")[0];
|
937
|
+
if (nodesToDelete.includes(parentId2)) {
|
938
|
+
delete newState.indexes.zones[zoneCompound];
|
741
939
|
}
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
940
|
+
});
|
941
|
+
nodesToDelete.forEach((id) => {
|
942
|
+
delete newState.indexes.nodes[id];
|
943
|
+
});
|
944
|
+
return newState;
|
945
|
+
};
|
946
|
+
|
947
|
+
// ../core/reducer/actions/register-zone.ts
|
948
|
+
init_react_import();
|
949
|
+
|
950
|
+
// ../core/lib/data/setup-zone.ts
|
951
|
+
init_react_import();
|
952
|
+
var setupZone = (data, zoneKey) => {
|
953
|
+
if (zoneKey === rootDroppableId) {
|
954
|
+
return data;
|
750
955
|
}
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
956
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
957
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
958
|
+
});
|
959
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
960
|
+
return newData;
|
961
|
+
};
|
962
|
+
|
963
|
+
// ../core/reducer/actions/register-zone.ts
|
964
|
+
var zoneCache = {};
|
965
|
+
function registerZoneAction(state, action) {
|
966
|
+
if (zoneCache[action.zone]) {
|
967
|
+
return __spreadProps(__spreadValues({}, state), {
|
968
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
969
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
755
970
|
[action.zone]: zoneCache[action.zone]
|
756
971
|
})
|
757
|
-
})
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
}
|
767
|
-
return __spreadProps(__spreadValues({}, data), { zones: _zones });
|
972
|
+
}),
|
973
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
974
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
975
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
976
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
977
|
+
type: "dropzone"
|
978
|
+
})
|
979
|
+
})
|
980
|
+
})
|
981
|
+
});
|
768
982
|
}
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
983
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
984
|
+
}
|
985
|
+
function unregisterZoneAction(state, action) {
|
986
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
987
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
988
|
+
if (_zones[action.zone]) {
|
989
|
+
zoneCache[action.zone] = _zones[action.zone];
|
990
|
+
delete _zones[action.zone];
|
774
991
|
}
|
775
|
-
|
992
|
+
delete zoneIndex[action.zone];
|
993
|
+
return __spreadProps(__spreadValues({}, state), {
|
994
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
995
|
+
zones: _zones
|
996
|
+
}),
|
997
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
998
|
+
zones: zoneIndex
|
999
|
+
})
|
1000
|
+
});
|
776
1001
|
}
|
777
1002
|
|
778
|
-
// ../core/reducer/
|
1003
|
+
// ../core/reducer/actions/set-data.ts
|
779
1004
|
init_react_import();
|
780
|
-
var
|
781
|
-
if (action.
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
return
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
1005
|
+
var setDataAction = (state, action, appStore) => {
|
1006
|
+
if (typeof action.data === "object") {
|
1007
|
+
console.warn(
|
1008
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1009
|
+
);
|
1010
|
+
return walkTree(
|
1011
|
+
__spreadProps(__spreadValues({}, state), {
|
1012
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1013
|
+
}),
|
1014
|
+
appStore.config
|
1015
|
+
);
|
791
1016
|
}
|
792
|
-
|
793
|
-
|
794
|
-
|
1017
|
+
return walkTree(
|
1018
|
+
__spreadProps(__spreadValues({}, state), {
|
1019
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1020
|
+
}),
|
1021
|
+
appStore.config
|
1022
|
+
);
|
1023
|
+
};
|
1024
|
+
|
1025
|
+
// ../core/reducer/actions/set-ui.ts
|
1026
|
+
init_react_import();
|
1027
|
+
var setUiAction = (state, action) => {
|
1028
|
+
if (typeof action.ui === "object") {
|
1029
|
+
return __spreadProps(__spreadValues({}, state), {
|
1030
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
795
1031
|
});
|
796
1032
|
}
|
797
|
-
return
|
1033
|
+
return __spreadProps(__spreadValues({}, state), {
|
1034
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
1035
|
+
});
|
1036
|
+
};
|
1037
|
+
|
1038
|
+
// ../core/lib/data/make-state-public.ts
|
1039
|
+
init_react_import();
|
1040
|
+
var makeStatePublic = (state) => {
|
1041
|
+
const { data, ui } = state;
|
1042
|
+
return { data, ui };
|
798
1043
|
};
|
799
1044
|
|
800
1045
|
// ../core/reducer/actions.tsx
|
@@ -814,29 +1059,54 @@ function storeInterceptor(reducer, record, onAction) {
|
|
814
1059
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
815
1060
|
if (record) record(newAppState);
|
816
1061
|
}
|
817
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1062
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
818
1063
|
return newAppState;
|
819
1064
|
};
|
820
1065
|
}
|
821
|
-
var setAction = (state, action) => {
|
822
|
-
if (typeof action.state === "object") {
|
823
|
-
return __spreadValues(__spreadValues({}, state), action.state);
|
824
|
-
}
|
825
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
826
|
-
};
|
827
1066
|
function createReducer({
|
828
|
-
config,
|
829
1067
|
record,
|
830
|
-
onAction
|
1068
|
+
onAction,
|
1069
|
+
appStore
|
831
1070
|
}) {
|
832
1071
|
return storeInterceptor(
|
833
1072
|
(state, action) => {
|
834
|
-
const data = reduceData(state.data, action, config);
|
835
|
-
const ui = reduceUi(state.ui, action);
|
836
1073
|
if (action.type === "set") {
|
837
|
-
return setAction(state, action);
|
1074
|
+
return setAction(state, action, appStore);
|
1075
|
+
}
|
1076
|
+
if (action.type === "insert") {
|
1077
|
+
return insertAction(state, action, appStore);
|
1078
|
+
}
|
1079
|
+
if (action.type === "replace") {
|
1080
|
+
return replaceAction(state, action, appStore);
|
1081
|
+
}
|
1082
|
+
if (action.type === "replaceRoot") {
|
1083
|
+
return replaceRootAction(state, action, appStore);
|
838
1084
|
}
|
839
|
-
|
1085
|
+
if (action.type === "duplicate") {
|
1086
|
+
return duplicateAction(state, action, appStore);
|
1087
|
+
}
|
1088
|
+
if (action.type === "reorder") {
|
1089
|
+
return reorderAction(state, action, appStore);
|
1090
|
+
}
|
1091
|
+
if (action.type === "move") {
|
1092
|
+
return moveAction(state, action, appStore);
|
1093
|
+
}
|
1094
|
+
if (action.type === "remove") {
|
1095
|
+
return removeAction(state, action, appStore);
|
1096
|
+
}
|
1097
|
+
if (action.type === "registerZone") {
|
1098
|
+
return registerZoneAction(state, action);
|
1099
|
+
}
|
1100
|
+
if (action.type === "unregisterZone") {
|
1101
|
+
return unregisterZoneAction(state, action);
|
1102
|
+
}
|
1103
|
+
if (action.type === "setData") {
|
1104
|
+
return setDataAction(state, action, appStore);
|
1105
|
+
}
|
1106
|
+
if (action.type === "setUi") {
|
1107
|
+
return setUiAction(state, action);
|
1108
|
+
}
|
1109
|
+
return state;
|
840
1110
|
},
|
841
1111
|
record,
|
842
1112
|
onAction
|
@@ -856,11 +1126,11 @@ init_react_import();
|
|
856
1126
|
var createStoreImpl = (createState) => {
|
857
1127
|
let state;
|
858
1128
|
const listeners = /* @__PURE__ */ new Set();
|
859
|
-
const setState = (partial,
|
1129
|
+
const setState = (partial, replace) => {
|
860
1130
|
const nextState = typeof partial === "function" ? partial(state) : partial;
|
861
1131
|
if (!Object.is(nextState, state)) {
|
862
1132
|
const previousState = state;
|
863
|
-
state = (
|
1133
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
864
1134
|
listeners.forEach((listener) => listener(state, previousState));
|
865
1135
|
}
|
866
1136
|
};
|
@@ -924,206 +1194,6 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
|
|
924
1194
|
};
|
925
1195
|
var subscribeWithSelector = subscribeWithSelectorImpl;
|
926
1196
|
|
927
|
-
// ../core/lib/resolve-data.ts
|
928
|
-
init_react_import();
|
929
|
-
|
930
|
-
// ../core/lib/resolve-component-data.ts
|
931
|
-
init_react_import();
|
932
|
-
|
933
|
-
// ../core/lib/get-changed.ts
|
934
|
-
init_react_import();
|
935
|
-
var getChanged = (newItem, oldItem) => {
|
936
|
-
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
937
|
-
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
938
|
-
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
939
|
-
return __spreadProps(__spreadValues({}, acc), {
|
940
|
-
[item]: oldItemProps[item] !== newItemProps[item]
|
941
|
-
});
|
942
|
-
}, {}) : {};
|
943
|
-
};
|
944
|
-
|
945
|
-
// ../core/lib/resolve-component-data.ts
|
946
|
-
var cache = { lastChange: {} };
|
947
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
|
948
|
-
const configForItem = config.components[item.type];
|
949
|
-
if (configForItem.resolveData) {
|
950
|
-
const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
|
951
|
-
if (item && item === oldItem) {
|
952
|
-
return resolved;
|
953
|
-
}
|
954
|
-
const changed = getChanged(item, oldItem);
|
955
|
-
if (onResolveStart) {
|
956
|
-
onResolveStart(item);
|
957
|
-
}
|
958
|
-
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
959
|
-
changed,
|
960
|
-
lastData: oldItem,
|
961
|
-
metadata
|
962
|
-
});
|
963
|
-
const resolvedItem = __spreadProps(__spreadValues({}, item), {
|
964
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
965
|
-
});
|
966
|
-
if (Object.keys(readOnly).length) {
|
967
|
-
resolvedItem.readOnly = readOnly;
|
968
|
-
}
|
969
|
-
cache.lastChange[item.props.id] = {
|
970
|
-
item,
|
971
|
-
resolved: resolvedItem
|
972
|
-
};
|
973
|
-
if (onResolveEnd) {
|
974
|
-
onResolveEnd(resolvedItem);
|
975
|
-
}
|
976
|
-
return resolvedItem;
|
977
|
-
}
|
978
|
-
return item;
|
979
|
-
});
|
980
|
-
|
981
|
-
// ../core/lib/apply-dynamic-props.ts
|
982
|
-
init_react_import();
|
983
|
-
var applyDynamicProps = (data, dynamicProps, rootData) => {
|
984
|
-
return __spreadProps(__spreadValues({}, data), {
|
985
|
-
root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
|
986
|
-
content: data.content.map((item) => {
|
987
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
988
|
-
}),
|
989
|
-
zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
|
990
|
-
return __spreadProps(__spreadValues({}, acc), {
|
991
|
-
[zoneKey]: data.zones[zoneKey].map((item) => {
|
992
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
993
|
-
})
|
994
|
-
});
|
995
|
-
}, {})
|
996
|
-
});
|
997
|
-
};
|
998
|
-
|
999
|
-
// ../core/lib/resolve-root-data.ts
|
1000
|
-
init_react_import();
|
1001
|
-
var cache2 = {};
|
1002
|
-
function resolveRootData(data, config, metadata) {
|
1003
|
-
return __async(this, null, function* () {
|
1004
|
-
var _a, _b, _c, _d, _e;
|
1005
|
-
if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
|
1006
|
-
if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
|
1007
|
-
return cache2.lastChange.resolved;
|
1008
|
-
}
|
1009
|
-
const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
|
1010
|
-
const rootWithProps = data.root;
|
1011
|
-
const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
|
1012
|
-
changed,
|
1013
|
-
lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
|
1014
|
-
metadata: metadata || {}
|
1015
|
-
});
|
1016
|
-
cache2.lastChange = {
|
1017
|
-
original: data.root,
|
1018
|
-
resolved: resolvedRoot
|
1019
|
-
};
|
1020
|
-
return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
|
1021
|
-
props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
|
1022
|
-
});
|
1023
|
-
}
|
1024
|
-
return data.root;
|
1025
|
-
});
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
// ../core/lib/flatten-data.ts
|
1029
|
-
init_react_import();
|
1030
|
-
var flattenData = (data) => {
|
1031
|
-
return Object.keys(data.zones || {}).reduce(
|
1032
|
-
(acc, zone) => [...acc, ...data.zones[zone]],
|
1033
|
-
data.content
|
1034
|
-
);
|
1035
|
-
};
|
1036
|
-
|
1037
|
-
// ../core/lib/resolve-data.ts
|
1038
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1039
|
-
var resolveData = (newAppState, appStoreData) => {
|
1040
|
-
const {
|
1041
|
-
state: appState,
|
1042
|
-
config,
|
1043
|
-
dispatch,
|
1044
|
-
resolveDataRuns,
|
1045
|
-
setComponentLoading,
|
1046
|
-
unsetComponentLoading,
|
1047
|
-
metadata,
|
1048
|
-
permissions
|
1049
|
-
} = appStoreData;
|
1050
|
-
const deferredSetStates = {};
|
1051
|
-
const _setComponentLoading = (id, loading, defer = 0) => {
|
1052
|
-
if (deferredSetStates[id]) {
|
1053
|
-
clearTimeout(deferredSetStates[id]);
|
1054
|
-
delete deferredSetStates[id];
|
1055
|
-
}
|
1056
|
-
deferredSetStates[id] = setTimeout(() => {
|
1057
|
-
if (loading) {
|
1058
|
-
setComponentLoading(id);
|
1059
|
-
} else {
|
1060
|
-
unsetComponentLoading(id);
|
1061
|
-
}
|
1062
|
-
delete deferredSetStates[id];
|
1063
|
-
}, defer);
|
1064
|
-
};
|
1065
|
-
const runResolvers = () => __async(void 0, null, function* () {
|
1066
|
-
const newData = newAppState.data;
|
1067
|
-
const flatContent = flattenData(newData).filter(
|
1068
|
-
(item) => {
|
1069
|
-
var _a;
|
1070
|
-
return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
|
1071
|
-
}
|
1072
|
-
);
|
1073
|
-
const applyIfChange = (dynamicDataMap, dynamicRoot) => {
|
1074
|
-
const processed = applyDynamicProps(
|
1075
|
-
__spreadValues({}, appState.data),
|
1076
|
-
dynamicDataMap,
|
1077
|
-
dynamicRoot
|
1078
|
-
);
|
1079
|
-
const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
|
1080
|
-
const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
|
1081
|
-
if (containsChanges) {
|
1082
|
-
dispatch({
|
1083
|
-
type: "set",
|
1084
|
-
state: (prev) => __spreadProps(__spreadValues({}, prev), {
|
1085
|
-
data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
|
1086
|
-
ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
|
1087
|
-
}),
|
1088
|
-
recordHistory: resolveDataRuns > 0
|
1089
|
-
});
|
1090
|
-
}
|
1091
|
-
};
|
1092
|
-
const promises = [];
|
1093
|
-
promises.push(
|
1094
|
-
(() => __async(void 0, null, function* () {
|
1095
|
-
_setComponentLoading("puck-root", true, 50);
|
1096
|
-
const dynamicRoot = yield resolveRootData(newData, config, metadata);
|
1097
|
-
applyIfChange({}, dynamicRoot);
|
1098
|
-
_setComponentLoading("puck-root", false);
|
1099
|
-
}))()
|
1100
|
-
);
|
1101
|
-
flatContent.forEach((item) => {
|
1102
|
-
promises.push(
|
1103
|
-
(() => __async(void 0, null, function* () {
|
1104
|
-
permissions.resolvePermissions({ item }, true);
|
1105
|
-
const dynamicData = yield resolveComponentData(
|
1106
|
-
item,
|
1107
|
-
config,
|
1108
|
-
metadata,
|
1109
|
-
(item2) => {
|
1110
|
-
_setComponentLoading(item2.props.id, true, 50);
|
1111
|
-
},
|
1112
|
-
(item2) => {
|
1113
|
-
deferredSetStates[item2.props.id];
|
1114
|
-
_setComponentLoading(item2.props.id, false);
|
1115
|
-
}
|
1116
|
-
);
|
1117
|
-
const dynamicDataMap = { [item.props.id]: dynamicData };
|
1118
|
-
applyIfChange(dynamicDataMap);
|
1119
|
-
}))()
|
1120
|
-
);
|
1121
|
-
});
|
1122
|
-
yield Promise.all(promises);
|
1123
|
-
});
|
1124
|
-
return runResolvers();
|
1125
|
-
};
|
1126
|
-
|
1127
1197
|
// ../core/store/index.ts
|
1128
1198
|
import { createContext, useContext } from "react";
|
1129
1199
|
|
@@ -1241,31 +1311,14 @@ var createHistorySlice = (set, get) => {
|
|
1241
1311
|
|
1242
1312
|
// ../core/store/slices/nodes.ts
|
1243
1313
|
init_react_import();
|
1244
|
-
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1245
|
-
import { useEffect as useEffect3 } from "react";
|
1246
|
-
var partialDeepEqual = (newItem, existingItem) => {
|
1247
|
-
const filteredExistingItem = Object.keys(newItem).reduce(
|
1248
|
-
(acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
|
1249
|
-
{}
|
1250
|
-
);
|
1251
|
-
return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
|
1252
|
-
};
|
1253
1314
|
var createNodesSlice = (set, get) => ({
|
1254
1315
|
nodes: {},
|
1255
1316
|
registerNode: (id, node) => {
|
1256
1317
|
const s = get().nodes;
|
1257
|
-
if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
|
1258
|
-
return;
|
1259
|
-
}
|
1260
1318
|
const emptyNode = {
|
1261
1319
|
id,
|
1262
1320
|
methods: { sync: () => null },
|
1263
|
-
|
1264
|
-
parentId: "",
|
1265
|
-
zone: "",
|
1266
|
-
path: [],
|
1267
|
-
element: null,
|
1268
|
-
index: -1
|
1321
|
+
element: null
|
1269
1322
|
};
|
1270
1323
|
const existingNode = s.nodes[id];
|
1271
1324
|
set({
|
@@ -1295,36 +1348,61 @@ var createNodesSlice = (set, get) => ({
|
|
1295
1348
|
|
1296
1349
|
// ../core/store/slices/permissions.ts
|
1297
1350
|
init_react_import();
|
1298
|
-
import { useEffect as
|
1351
|
+
import { useEffect as useEffect3 } from "react";
|
1352
|
+
|
1353
|
+
// ../core/lib/data/flatten-data.ts
|
1354
|
+
init_react_import();
|
1355
|
+
var flattenData = (state, config) => {
|
1356
|
+
const data = [];
|
1357
|
+
walkTree(
|
1358
|
+
state,
|
1359
|
+
config,
|
1360
|
+
(content) => content,
|
1361
|
+
(item) => {
|
1362
|
+
data.push(item);
|
1363
|
+
return null;
|
1364
|
+
}
|
1365
|
+
);
|
1366
|
+
return data;
|
1367
|
+
};
|
1368
|
+
|
1369
|
+
// ../core/lib/get-changed.ts
|
1370
|
+
init_react_import();
|
1371
|
+
var getChanged = (newItem, oldItem) => {
|
1372
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1373
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1374
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1375
|
+
return __spreadProps(__spreadValues({}, acc), {
|
1376
|
+
[item]: oldItemProps[item] !== newItemProps[item]
|
1377
|
+
});
|
1378
|
+
}, {}) : {};
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
// ../core/store/slices/permissions.ts
|
1299
1382
|
var createPermissionsSlice = (set, get) => {
|
1300
1383
|
const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
|
1301
|
-
const { state, permissions } = get();
|
1302
|
-
const { cache:
|
1384
|
+
const { state, permissions, config } = get();
|
1385
|
+
const { cache: cache2, globalPermissions } = permissions;
|
1303
1386
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1304
1387
|
var _a, _b, _c;
|
1305
|
-
const {
|
1306
|
-
|
1307
|
-
state: appState,
|
1308
|
-
setComponentLoading,
|
1309
|
-
unsetComponentLoading
|
1310
|
-
} = get();
|
1311
|
-
const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
|
1388
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1389
|
+
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1312
1390
|
if (!componentConfig) {
|
1313
1391
|
return;
|
1314
1392
|
}
|
1315
1393
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
1316
1394
|
if (componentConfig.resolvePermissions) {
|
1317
|
-
const changed = getChanged(item2, (_a =
|
1395
|
+
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1318
1396
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1319
|
-
setComponentLoading(item2.props.id);
|
1397
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1320
1398
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1321
1399
|
item2,
|
1322
1400
|
{
|
1323
1401
|
changed,
|
1324
|
-
lastPermissions: ((_b =
|
1402
|
+
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1325
1403
|
permissions: initialPermissions,
|
1326
|
-
appState,
|
1327
|
-
lastData: ((_c =
|
1404
|
+
appState: makeStatePublic(appState),
|
1405
|
+
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1328
1406
|
}
|
1329
1407
|
);
|
1330
1408
|
const latest = get().permissions;
|
@@ -1341,7 +1419,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1341
1419
|
})
|
1342
1420
|
})
|
1343
1421
|
});
|
1344
|
-
|
1422
|
+
clearTimeout2();
|
1345
1423
|
}
|
1346
1424
|
}
|
1347
1425
|
});
|
@@ -1351,7 +1429,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1351
1429
|
// Shim the root data in by conforming to component data shape
|
1352
1430
|
{
|
1353
1431
|
type: "root",
|
1354
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1432
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1355
1433
|
},
|
1356
1434
|
force2
|
1357
1435
|
);
|
@@ -1360,14 +1438,13 @@ var createPermissionsSlice = (set, get) => {
|
|
1360
1438
|
if (item) {
|
1361
1439
|
yield resolveDataForItem(item, force);
|
1362
1440
|
} else if (type) {
|
1363
|
-
flattenData(state
|
1441
|
+
flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
1364
1442
|
yield resolveDataForItem(item2, force);
|
1365
1443
|
}));
|
1366
1444
|
} else if (root) {
|
1367
1445
|
resolveDataForRoot(force);
|
1368
1446
|
} else {
|
1369
|
-
|
1370
|
-
flattenData(state.data).map((item2) => __async(void 0, null, function* () {
|
1447
|
+
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1371
1448
|
yield resolveDataForItem(item2, force);
|
1372
1449
|
}));
|
1373
1450
|
}
|
@@ -1397,7 +1474,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1397
1474
|
} else if (root) {
|
1398
1475
|
const rootConfig = config.root;
|
1399
1476
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1400
|
-
const resolvedForItem = resolvedPermissions["
|
1477
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1401
1478
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1402
1479
|
}
|
1403
1480
|
return globalPermissions;
|
@@ -1409,8 +1486,8 @@ var createPermissionsSlice = (set, get) => {
|
|
1409
1486
|
|
1410
1487
|
// ../core/store/slices/fields.ts
|
1411
1488
|
init_react_import();
|
1412
|
-
import { useCallback, useEffect as
|
1413
|
-
var
|
1489
|
+
import { useCallback, useEffect as useEffect4 } from "react";
|
1490
|
+
var createFieldsSlice = (_set, _get) => {
|
1414
1491
|
return {
|
1415
1492
|
fields: {},
|
1416
1493
|
loading: false,
|
@@ -1418,6 +1495,112 @@ var createFieldsStore = (_set, _get) => {
|
|
1418
1495
|
};
|
1419
1496
|
};
|
1420
1497
|
|
1498
|
+
// ../core/lib/resolve-component-data.ts
|
1499
|
+
init_react_import();
|
1500
|
+
|
1501
|
+
// ../core/lib/data/map-slots.ts
|
1502
|
+
init_react_import();
|
1503
|
+
function mapSlots(_0, _1) {
|
1504
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1505
|
+
const props = __spreadValues({}, item.props);
|
1506
|
+
const propKeys = Object.keys(props);
|
1507
|
+
for (let i = 0; i < propKeys.length; i++) {
|
1508
|
+
const propKey = propKeys[i];
|
1509
|
+
const itemType = "type" in item ? item.type : "root";
|
1510
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
1511
|
+
const content = props[propKey];
|
1512
|
+
const mappedContent = recursive ? yield Promise.all(
|
1513
|
+
content.map((item2) => __async(this, null, function* () {
|
1514
|
+
return yield mapSlots(item2, map, recursive, isSlot2);
|
1515
|
+
}))
|
1516
|
+
) : content;
|
1517
|
+
props[propKey] = yield map(mappedContent, propKey);
|
1518
|
+
}
|
1519
|
+
}
|
1520
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
1521
|
+
});
|
1522
|
+
}
|
1523
|
+
|
1524
|
+
// ../core/lib/resolve-component-data.ts
|
1525
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1526
|
+
var cache = { lastChange: {} };
|
1527
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
1528
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1529
|
+
if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
|
1530
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1531
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1532
|
+
if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
|
1533
|
+
return { node: resolved, didChange: false };
|
1534
|
+
}
|
1535
|
+
const changed = getChanged(item, oldItem);
|
1536
|
+
if (onResolveStart) {
|
1537
|
+
onResolveStart(item);
|
1538
|
+
}
|
1539
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1540
|
+
changed,
|
1541
|
+
lastData: oldItem,
|
1542
|
+
metadata,
|
1543
|
+
trigger
|
1544
|
+
});
|
1545
|
+
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1546
|
+
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1547
|
+
});
|
1548
|
+
if (recursive) {
|
1549
|
+
resolvedItem = yield mapSlots(
|
1550
|
+
resolvedItem,
|
1551
|
+
(content) => __async(void 0, null, function* () {
|
1552
|
+
return Promise.all(
|
1553
|
+
content.map(
|
1554
|
+
(childItem) => __async(void 0, null, function* () {
|
1555
|
+
return (yield resolveComponentData(
|
1556
|
+
childItem,
|
1557
|
+
config,
|
1558
|
+
metadata,
|
1559
|
+
onResolveStart,
|
1560
|
+
onResolveEnd,
|
1561
|
+
trigger,
|
1562
|
+
false
|
1563
|
+
)).node;
|
1564
|
+
})
|
1565
|
+
)
|
1566
|
+
);
|
1567
|
+
}),
|
1568
|
+
false,
|
1569
|
+
createIsSlotConfig(config)
|
1570
|
+
);
|
1571
|
+
}
|
1572
|
+
if (Object.keys(readOnly).length) {
|
1573
|
+
resolvedItem.readOnly = readOnly;
|
1574
|
+
}
|
1575
|
+
cache.lastChange[id] = {
|
1576
|
+
item,
|
1577
|
+
resolved: resolvedItem
|
1578
|
+
};
|
1579
|
+
if (onResolveEnd) {
|
1580
|
+
onResolveEnd(resolvedItem);
|
1581
|
+
}
|
1582
|
+
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1583
|
+
}
|
1584
|
+
return { node: item, didChange: false };
|
1585
|
+
});
|
1586
|
+
|
1587
|
+
// ../core/lib/data/to-root.ts
|
1588
|
+
init_react_import();
|
1589
|
+
var toRoot = (item) => {
|
1590
|
+
if ("type" in item && item.type !== "root") {
|
1591
|
+
throw new Error("Converting non-root item to root.");
|
1592
|
+
}
|
1593
|
+
const { readOnly } = item;
|
1594
|
+
if (item.props) {
|
1595
|
+
if ("id" in item.props) {
|
1596
|
+
const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
|
1597
|
+
return { props, readOnly };
|
1598
|
+
}
|
1599
|
+
return { props: item.props, readOnly };
|
1600
|
+
}
|
1601
|
+
return { props: {}, readOnly };
|
1602
|
+
};
|
1603
|
+
|
1421
1604
|
// ../core/store/index.ts
|
1422
1605
|
var defaultAppState = {
|
1423
1606
|
data: { content: [], root: {}, zones: {} },
|
@@ -1438,92 +1621,186 @@ var defaultAppState = {
|
|
1438
1621
|
controlsVisible: true
|
1439
1622
|
},
|
1440
1623
|
field: { focus: null }
|
1624
|
+
},
|
1625
|
+
indexes: {
|
1626
|
+
nodes: {},
|
1627
|
+
zones: {}
|
1441
1628
|
}
|
1442
1629
|
};
|
1443
1630
|
var defaultPageFields = {
|
1444
1631
|
title: { type: "text" }
|
1445
1632
|
};
|
1446
1633
|
var createAppStore = (initialAppStore) => create()(
|
1447
|
-
subscribeWithSelector((set, get) =>
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
})
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1634
|
+
subscribeWithSelector((set, get) => {
|
1635
|
+
var _a, _b;
|
1636
|
+
return __spreadProps(__spreadValues({
|
1637
|
+
state: defaultAppState,
|
1638
|
+
config: { components: {} },
|
1639
|
+
componentState: {},
|
1640
|
+
plugins: [],
|
1641
|
+
overrides: {},
|
1642
|
+
viewports: defaultViewports,
|
1643
|
+
zoomConfig: {
|
1644
|
+
autoZoom: 1,
|
1645
|
+
rootHeight: 0,
|
1646
|
+
zoom: 1
|
1647
|
+
},
|
1648
|
+
status: "LOADING",
|
1649
|
+
iframe: {},
|
1650
|
+
metadata: {}
|
1651
|
+
}, initialAppStore), {
|
1652
|
+
fields: createFieldsSlice(set, get),
|
1653
|
+
history: createHistorySlice(set, get),
|
1654
|
+
nodes: createNodesSlice(set, get),
|
1655
|
+
permissions: createPermissionsSlice(set, get),
|
1656
|
+
getComponentConfig: (type) => {
|
1657
|
+
var _a2;
|
1658
|
+
const { config, selectedItem } = get();
|
1659
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1660
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1661
|
+
},
|
1662
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1663
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1664
|
+
initialAppStore.state
|
1665
|
+
) : null,
|
1666
|
+
dispatch: (action) => set((s) => {
|
1667
|
+
var _a2, _b2;
|
1668
|
+
const { record } = get().history;
|
1669
|
+
const dispatch = createReducer({
|
1670
|
+
record,
|
1671
|
+
appStore: s
|
1672
|
+
});
|
1673
|
+
const state = dispatch(s.state, action);
|
1674
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1675
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1676
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1677
|
+
}),
|
1678
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1679
|
+
setStatus: (status) => set({ status }),
|
1680
|
+
setComponentState: (componentState) => set({ componentState }),
|
1681
|
+
pendingLoadTimeouts: {},
|
1682
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1683
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1684
|
+
const loadId = generateId();
|
1685
|
+
const setLoading = () => {
|
1686
|
+
var _a2;
|
1687
|
+
const { componentState } = get();
|
1688
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1689
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1690
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1691
|
+
})
|
1692
|
+
}));
|
1693
|
+
};
|
1694
|
+
const unsetLoading = () => {
|
1695
|
+
var _a2;
|
1696
|
+
const { componentState } = get();
|
1697
|
+
clearTimeout(timeout);
|
1698
|
+
delete pendingLoadTimeouts[loadId];
|
1699
|
+
set({ pendingLoadTimeouts });
|
1700
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1701
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1702
|
+
loadingCount: Math.max(
|
1703
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1704
|
+
0
|
1705
|
+
)
|
1706
|
+
})
|
1707
|
+
}));
|
1708
|
+
};
|
1709
|
+
const timeout = setTimeout(() => {
|
1710
|
+
if (loading) {
|
1711
|
+
setLoading();
|
1712
|
+
} else {
|
1713
|
+
unsetLoading();
|
1714
|
+
}
|
1715
|
+
delete pendingLoadTimeouts[loadId];
|
1716
|
+
set({ pendingLoadTimeouts });
|
1717
|
+
}, defer);
|
1718
|
+
set({
|
1719
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1720
|
+
[id]: timeout
|
1721
|
+
})
|
1722
|
+
});
|
1723
|
+
return unsetLoading;
|
1724
|
+
},
|
1725
|
+
unsetComponentLoading: (id) => {
|
1726
|
+
const { setComponentLoading } = get();
|
1727
|
+
setComponentLoading(id, false);
|
1728
|
+
},
|
1729
|
+
// Helper
|
1730
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1731
|
+
const dispatch = createReducer({
|
1732
|
+
record: () => {
|
1733
|
+
},
|
1734
|
+
appStore: s
|
1735
|
+
});
|
1736
|
+
const state = dispatch(s.state, {
|
1737
|
+
type: "setUi",
|
1738
|
+
ui,
|
1739
|
+
recordHistory
|
1740
|
+
});
|
1741
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1742
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1743
|
+
}),
|
1744
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1745
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
1746
|
+
const timeouts = {};
|
1747
|
+
return yield resolveComponentData(
|
1748
|
+
componentData,
|
1749
|
+
config,
|
1750
|
+
metadata,
|
1751
|
+
(item) => {
|
1752
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1753
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
1754
|
+
},
|
1755
|
+
(item) => __async(void 0, null, function* () {
|
1756
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1757
|
+
if ("type" in item) {
|
1758
|
+
yield permissions.refreshPermissions({ item });
|
1759
|
+
} else {
|
1760
|
+
yield permissions.refreshPermissions({ root: true });
|
1761
|
+
}
|
1762
|
+
timeouts[id]();
|
1763
|
+
}),
|
1764
|
+
trigger
|
1765
|
+
);
|
1766
|
+
}),
|
1767
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1768
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1769
|
+
walkTree(
|
1770
|
+
state,
|
1771
|
+
config,
|
1772
|
+
(content) => content,
|
1773
|
+
(childItem) => {
|
1774
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
1775
|
+
const { state: state2 } = get();
|
1776
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
1777
|
+
if (node && resolved.didChange) {
|
1778
|
+
if (resolved.node.props.id === "root") {
|
1779
|
+
dispatch({
|
1780
|
+
type: "replaceRoot",
|
1781
|
+
root: toRoot(resolved.node)
|
1782
|
+
});
|
1783
|
+
} else {
|
1784
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1785
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
1786
|
+
const index = parentZone.contentIds.indexOf(
|
1787
|
+
resolved.node.props.id
|
1788
|
+
);
|
1789
|
+
dispatch({
|
1790
|
+
type: "replace",
|
1791
|
+
data: resolved.node,
|
1792
|
+
destinationIndex: index,
|
1793
|
+
destinationZone: zoneCompound
|
1794
|
+
});
|
1795
|
+
}
|
1796
|
+
}
|
1797
|
+
});
|
1798
|
+
return childItem;
|
1799
|
+
}
|
1800
|
+
);
|
1801
|
+
})
|
1802
|
+
});
|
1803
|
+
})
|
1527
1804
|
);
|
1528
1805
|
var appStoreContext = createContext(createAppStore());
|
1529
1806
|
function useAppStore(selector) {
|
@@ -1543,12 +1820,12 @@ var useBreadcrumbs = (renderCount) => {
|
|
1543
1820
|
const config = useAppStore((s) => s.config);
|
1544
1821
|
const path = useAppStore((s) => {
|
1545
1822
|
var _a;
|
1546
|
-
return (_a = s.
|
1823
|
+
return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
|
1547
1824
|
});
|
1548
1825
|
const appStore = useAppStoreApi();
|
1549
1826
|
return useMemo(() => {
|
1550
1827
|
const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
|
1551
|
-
var _a, _b;
|
1828
|
+
var _a, _b, _c;
|
1552
1829
|
const [componentId] = zoneCompound.split(":");
|
1553
1830
|
if (componentId === "root") {
|
1554
1831
|
return {
|
@@ -1556,12 +1833,15 @@ var useBreadcrumbs = (renderCount) => {
|
|
1556
1833
|
selector: null
|
1557
1834
|
};
|
1558
1835
|
}
|
1559
|
-
const node = appStore.getState().
|
1560
|
-
const
|
1836
|
+
const node = appStore.getState().state.indexes.nodes[componentId];
|
1837
|
+
const parentId = node.path[node.path.length - 1];
|
1838
|
+
const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
|
1839
|
+
const index = contentIds.indexOf(componentId);
|
1840
|
+
const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
|
1561
1841
|
return {
|
1562
1842
|
label,
|
1563
1843
|
selector: node ? {
|
1564
|
-
index
|
1844
|
+
index,
|
1565
1845
|
zone: node.path[node.path.length - 1]
|
1566
1846
|
} : null
|
1567
1847
|
};
|
@@ -1582,6 +1862,12 @@ init_react_import();
|
|
1582
1862
|
// ../core/lib/filter.ts
|
1583
1863
|
init_react_import();
|
1584
1864
|
|
1865
|
+
// ../core/lib/data/reorder.ts
|
1866
|
+
init_react_import();
|
1867
|
+
|
1868
|
+
// ../core/lib/data/replace.ts
|
1869
|
+
init_react_import();
|
1870
|
+
|
1585
1871
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
1586
1872
|
init_react_import();
|
1587
1873
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
@@ -1763,17 +2049,39 @@ var usePuck = createUsePuck();
|
|
1763
2049
|
var HeadingAnalyzer = () => {
|
1764
2050
|
const data = usePuck((s) => s.appState.data);
|
1765
2051
|
const [hierarchy, setHierarchy] = useState([]);
|
1766
|
-
|
2052
|
+
useEffect5(() => {
|
1767
2053
|
const frame = getFrame();
|
1768
|
-
|
1769
|
-
|
1770
|
-
setHierarchy(buildHierarchy(entry));
|
1771
|
-
const observer = new MutationObserver(() => {
|
2054
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2055
|
+
const createHierarchy = () => {
|
1772
2056
|
setHierarchy(buildHierarchy(entry));
|
2057
|
+
};
|
2058
|
+
const entryObserver = new MutationObserver(() => {
|
2059
|
+
createHierarchy();
|
2060
|
+
});
|
2061
|
+
const frameObserver = new MutationObserver(() => {
|
2062
|
+
entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2063
|
+
if (entry) {
|
2064
|
+
registerEntryObserver();
|
2065
|
+
frameObserver.disconnect();
|
2066
|
+
}
|
1773
2067
|
});
|
1774
|
-
|
2068
|
+
const registerEntryObserver = () => {
|
2069
|
+
if (!entry) return;
|
2070
|
+
entryObserver.observe(entry, { subtree: true, childList: true });
|
2071
|
+
};
|
2072
|
+
const registerFrameObserver = () => {
|
2073
|
+
if (!frame) return;
|
2074
|
+
frameObserver.observe(frame, { subtree: true, childList: true });
|
2075
|
+
};
|
2076
|
+
if (entry) {
|
2077
|
+
createHierarchy();
|
2078
|
+
registerEntryObserver();
|
2079
|
+
} else {
|
2080
|
+
registerFrameObserver();
|
2081
|
+
}
|
1775
2082
|
return () => {
|
1776
|
-
|
2083
|
+
entryObserver.disconnect();
|
2084
|
+
frameObserver.disconnect();
|
1777
2085
|
};
|
1778
2086
|
}, [data]);
|
1779
2087
|
return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [
|