@measured/puck-plugin-heading-analyzer 0.19.0-canary.c33636f → 0.19.0-canary.c79f5db8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +974 -674
- package/dist/index.mjs +967 -667
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -199,7 +199,7 @@ init_react_import();
|
|
199
199
|
|
200
200
|
// src/HeadingAnalyzer.tsx
|
201
201
|
init_react_import();
|
202
|
-
var
|
202
|
+
var import_react11 = require("react");
|
203
203
|
|
204
204
|
// css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
|
205
205
|
init_react_import();
|
@@ -360,7 +360,7 @@ var ChevronRight = createLucideIcon("ChevronRight", [
|
|
360
360
|
|
361
361
|
// ../core/lib/use-breadcrumbs.ts
|
362
362
|
init_react_import();
|
363
|
-
var
|
363
|
+
var import_react10 = require("react");
|
364
364
|
|
365
365
|
// ../core/store/index.ts
|
366
366
|
init_react_import();
|
@@ -368,75 +368,247 @@ 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
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
376
|
+
|
377
|
+
// ../core/lib/data/for-each-slot.ts
|
378
|
+
init_react_import();
|
379
|
+
|
380
|
+
// ../core/lib/data/is-slot.ts
|
381
|
+
init_react_import();
|
382
|
+
var isSlot = (prop) => {
|
383
|
+
var _a, _b;
|
384
|
+
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
385
|
+
};
|
386
|
+
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
387
|
+
var _a, _b;
|
388
|
+
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
389
|
+
if (!configForComponent) return isSlot(propValue);
|
390
|
+
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
391
|
+
};
|
392
|
+
|
393
|
+
// ../core/lib/data/for-each-slot.ts
|
394
|
+
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
395
|
+
const props = item.props || {};
|
396
|
+
const propKeys = Object.keys(props);
|
397
|
+
for (let i = 0; i < propKeys.length; i++) {
|
398
|
+
const propKey = propKeys[i];
|
399
|
+
const itemType = "type" in item ? item.type : "root";
|
400
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
401
|
+
const content = props[propKey];
|
402
|
+
cb(props.id, propKey, content);
|
403
|
+
if (recursive) {
|
404
|
+
content.forEach(
|
405
|
+
(childItem) => __async(void 0, null, function* () {
|
406
|
+
return forEachSlot(childItem, cb, true, isSlot2);
|
407
|
+
})
|
408
|
+
);
|
409
|
+
}
|
410
|
+
}
|
411
|
+
}
|
381
412
|
};
|
382
413
|
|
414
|
+
// ../core/lib/data/for-related-zones.ts
|
415
|
+
init_react_import();
|
416
|
+
|
417
|
+
// ../core/lib/get-zone-id.ts
|
418
|
+
init_react_import();
|
419
|
+
|
383
420
|
// ../core/lib/root-droppable-id.ts
|
384
421
|
init_react_import();
|
385
422
|
var rootAreaId = "root";
|
386
423
|
var rootZone = "default-zone";
|
387
424
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
388
425
|
|
389
|
-
// ../core/lib/
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
426
|
+
// ../core/lib/get-zone-id.ts
|
427
|
+
var getZoneId = (zoneCompound) => {
|
428
|
+
if (!zoneCompound) {
|
429
|
+
return [];
|
430
|
+
}
|
431
|
+
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
432
|
+
return zoneCompound.split(":");
|
433
|
+
}
|
434
|
+
return [rootDroppableId, zoneCompound];
|
395
435
|
};
|
396
436
|
|
397
|
-
// ../core/lib/
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
}
|
437
|
+
// ../core/lib/data/for-related-zones.ts
|
438
|
+
function forRelatedZones(item, data, cb, path = []) {
|
439
|
+
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
440
|
+
const [parentId] = getZoneId(zoneCompound);
|
441
|
+
if (parentId === item.props.id) {
|
442
|
+
cb(path, zoneCompound, content);
|
443
|
+
}
|
444
|
+
});
|
445
|
+
}
|
404
446
|
|
405
|
-
// ../core/lib/
|
447
|
+
// ../core/lib/data/strip-slots.ts
|
406
448
|
init_react_import();
|
407
|
-
var
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
449
|
+
var stripSlots = (data) => {
|
450
|
+
return __spreadProps(__spreadValues({}, data), {
|
451
|
+
props: Object.entries(data.props).reduce(
|
452
|
+
(acc, [propKey, propVal]) => {
|
453
|
+
if (isSlot(propVal)) {
|
454
|
+
return acc;
|
455
|
+
}
|
456
|
+
return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
|
457
|
+
},
|
458
|
+
{ id: data.props.id }
|
459
|
+
)
|
413
460
|
});
|
414
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
415
|
-
return newData;
|
416
461
|
};
|
417
462
|
|
418
|
-
// ../core/lib/
|
419
|
-
|
420
|
-
var
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
463
|
+
// ../core/lib/data/walk-tree.ts
|
464
|
+
function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
465
|
+
var _a;
|
466
|
+
let newZones = {};
|
467
|
+
const newZoneIndex = {};
|
468
|
+
const newNodeIndex = {};
|
469
|
+
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
470
|
+
var _a2;
|
471
|
+
const [parentId] = zoneCompound.split(":");
|
472
|
+
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
473
|
+
const [_2, zone] = zoneCompound.split(":");
|
474
|
+
const newZoneCompound = `${newId || parentId}:${zone}`;
|
475
|
+
const newContent2 = mappedContent.map(
|
476
|
+
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
477
|
+
);
|
478
|
+
newZoneIndex[newZoneCompound] = {
|
479
|
+
contentIds: newContent2.map((item) => item.props.id),
|
480
|
+
type: zoneType
|
481
|
+
};
|
482
|
+
return [newZoneCompound, newContent2];
|
483
|
+
};
|
484
|
+
const processRelatedZones = (item, newId, initialPath) => {
|
485
|
+
forRelatedZones(
|
486
|
+
item,
|
487
|
+
state.data,
|
488
|
+
(relatedPath, relatedZoneCompound, relatedContent) => {
|
489
|
+
const [zoneCompound, newContent2] = processContent(
|
490
|
+
relatedPath,
|
491
|
+
relatedZoneCompound,
|
492
|
+
relatedContent,
|
493
|
+
"dropzone",
|
494
|
+
newId
|
495
|
+
);
|
496
|
+
newZones[zoneCompound] = newContent2;
|
497
|
+
},
|
498
|
+
initialPath
|
499
|
+
);
|
500
|
+
};
|
501
|
+
const processItem = (item, path, index) => {
|
502
|
+
const mappedItem = mapNodeOrSkip(item, path, index);
|
503
|
+
if (!mappedItem) return item;
|
504
|
+
const id = mappedItem.props.id;
|
505
|
+
const newProps = __spreadValues({}, mappedItem.props);
|
506
|
+
forEachSlot(
|
507
|
+
mappedItem,
|
508
|
+
(parentId2, slotId, content) => {
|
509
|
+
const zoneCompound = `${parentId2}:${slotId}`;
|
510
|
+
const [_2, newContent2] = processContent(
|
511
|
+
path,
|
512
|
+
zoneCompound,
|
513
|
+
content,
|
514
|
+
"slot",
|
515
|
+
parentId2
|
516
|
+
);
|
517
|
+
newProps[slotId] = newContent2;
|
518
|
+
},
|
519
|
+
false,
|
520
|
+
createIsSlotConfig(config)
|
521
|
+
);
|
522
|
+
processRelatedZones(item, id, path);
|
523
|
+
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
524
|
+
const thisZoneCompound = path[path.length - 1];
|
525
|
+
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
526
|
+
newNodeIndex[id] = {
|
527
|
+
data: newItem,
|
528
|
+
flatData: stripSlots(newItem),
|
529
|
+
path,
|
530
|
+
parentId,
|
531
|
+
zone
|
532
|
+
};
|
533
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
534
|
+
if (newProps.id === "root") {
|
535
|
+
delete finalData["type"];
|
536
|
+
delete finalData.props["id"];
|
537
|
+
}
|
538
|
+
return finalData;
|
539
|
+
};
|
540
|
+
const zones = state.data.zones || {};
|
541
|
+
const [_, newContent] = processContent(
|
542
|
+
[],
|
543
|
+
rootDroppableId,
|
544
|
+
state.data.content,
|
545
|
+
"root"
|
546
|
+
);
|
547
|
+
const processedContent = newContent;
|
548
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
549
|
+
Object.keys(zones || {}).forEach((zoneCompound) => {
|
550
|
+
const [parentId] = zoneCompound.split(":");
|
551
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
552
|
+
return;
|
553
|
+
}
|
554
|
+
const [_2, newContent2] = processContent(
|
555
|
+
[rootDroppableId],
|
556
|
+
zoneCompound,
|
557
|
+
zones[zoneCompound],
|
558
|
+
"dropzone",
|
559
|
+
parentId
|
560
|
+
);
|
561
|
+
newZones[zoneCompound] = newContent2;
|
562
|
+
}, newZones);
|
563
|
+
const processedRoot = processItem(
|
564
|
+
{
|
565
|
+
type: "root",
|
566
|
+
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
567
|
+
},
|
568
|
+
[],
|
569
|
+
-1
|
570
|
+
);
|
571
|
+
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
572
|
+
props: processedRoot.props
|
573
|
+
});
|
574
|
+
return __spreadProps(__spreadValues({}, state), {
|
575
|
+
data: {
|
576
|
+
root,
|
577
|
+
content: processedContent,
|
578
|
+
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
579
|
+
},
|
580
|
+
indexes: {
|
581
|
+
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
582
|
+
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
583
|
+
}
|
584
|
+
});
|
585
|
+
}
|
586
|
+
|
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));
|
425
600
|
};
|
426
601
|
|
427
|
-
// ../core/
|
602
|
+
// ../core/reducer/actions/insert.ts
|
428
603
|
init_react_import();
|
429
|
-
function getItem(selector, data, dynamicProps = {}) {
|
430
|
-
if (!selector.zone || selector.zone === rootDroppableId) {
|
431
|
-
const item2 = data.content[selector.index];
|
432
|
-
return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
|
433
|
-
}
|
434
|
-
const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
|
435
|
-
return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
|
436
|
-
}
|
437
604
|
|
438
|
-
// ../core/lib/
|
605
|
+
// ../core/lib/data/insert.ts
|
439
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
|
+
};
|
440
612
|
|
441
613
|
// ../core/lib/generate-id.ts
|
442
614
|
init_react_import();
|
@@ -500,313 +672,378 @@ var v4_default = v4;
|
|
500
672
|
// ../core/lib/generate-id.ts
|
501
673
|
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
502
674
|
|
503
|
-
// ../core/lib/get-
|
675
|
+
// ../core/lib/data/get-ids-for-parent.ts
|
504
676
|
init_react_import();
|
505
|
-
var
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
510
|
-
return zoneCompound.split(":");
|
511
|
-
}
|
512
|
-
return [rootDroppableId, zoneCompound];
|
677
|
+
var getIdsForParent = (zoneCompound, state) => {
|
678
|
+
const [parentId] = zoneCompound.split(":");
|
679
|
+
const node = state.indexes.nodes[parentId];
|
680
|
+
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
513
681
|
};
|
514
682
|
|
515
|
-
// ../core/
|
516
|
-
function
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
683
|
+
// ../core/reducer/actions/insert.ts
|
684
|
+
function insertAction(state, action, appStore) {
|
685
|
+
const id = action.id || generateId(action.componentType);
|
686
|
+
const emptyComponentData = {
|
687
|
+
type: action.componentType,
|
688
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
689
|
+
id
|
690
|
+
})
|
691
|
+
};
|
692
|
+
const [parentId] = action.destinationZone.split(":");
|
693
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
694
|
+
return walkTree(
|
695
|
+
state,
|
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
|
+
);
|
530
718
|
}
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
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;
|
538
739
|
}
|
539
|
-
return
|
740
|
+
return newContent;
|
540
741
|
},
|
541
|
-
{
|
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
|
+
}
|
542
755
|
);
|
543
756
|
};
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
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
|
552
770
|
});
|
553
771
|
}
|
554
|
-
return
|
555
|
-
}
|
556
|
-
{}
|
772
|
+
return childItem;
|
773
|
+
}
|
557
774
|
);
|
558
775
|
};
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
return
|
569
|
-
const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
|
570
|
-
props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
|
571
|
-
}));
|
572
|
-
const dupeOfDupes = dupedZone.reduce(
|
573
|
-
(dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
|
574
|
-
acc
|
575
|
-
);
|
576
|
-
const [_, zoneId] = getZoneId(key);
|
577
|
-
return __spreadProps(__spreadValues({}, dupeOfDupes), {
|
578
|
-
[key]: zone,
|
579
|
-
[`${newId}:${zoneId}`]: dupedZone
|
580
|
-
});
|
581
|
-
});
|
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;
|
582
786
|
}
|
583
787
|
|
584
|
-
// ../core/reducer/
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
}
|
592
|
-
|
593
|
-
|
594
|
-
zones: __spreadProps(__spreadValues({}, newData.zones), {
|
595
|
-
[action.destinationZone]: replace(
|
596
|
-
newData.zones[action.destinationZone],
|
597
|
-
action.destinationIndex,
|
598
|
-
action.data
|
599
|
-
)
|
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)
|
600
798
|
})
|
601
799
|
});
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
800
|
+
const modified = walkTree(
|
801
|
+
state,
|
802
|
+
appStore.config,
|
803
|
+
(content, zoneCompound) => {
|
804
|
+
if (zoneCompound === action.sourceZone) {
|
805
|
+
return insert(content, action.sourceIndex + 1, item);
|
806
|
+
}
|
807
|
+
return content;
|
808
|
+
},
|
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) {
|
824
|
+
return childItem;
|
825
|
+
}
|
826
|
+
return null;
|
827
|
+
}
|
828
|
+
);
|
829
|
+
return __spreadProps(__spreadValues({}, modified), {
|
830
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
831
|
+
itemSelector: {
|
832
|
+
index: action.sourceIndex + 1,
|
833
|
+
zone: action.sourceZone
|
834
|
+
}
|
627
835
|
})
|
628
836
|
});
|
629
837
|
}
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
const
|
641
|
-
|
642
|
-
|
643
|
-
[action.destinationZone]: reorder(
|
644
|
-
newData.zones[action.destinationZone],
|
645
|
-
action.sourceIndex,
|
646
|
-
action.destinationIndex
|
647
|
-
)
|
648
|
-
})
|
649
|
-
});
|
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;
|
650
851
|
};
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
const item = getItem(
|
657
|
-
{ index: action.sourceIndex, zone: action.sourceZone },
|
658
|
-
data
|
659
|
-
);
|
660
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
661
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
662
|
-
id: generateId(item.type)
|
663
|
-
})
|
664
|
-
});
|
665
|
-
const dataWithRelatedDuplicated = duplicateRelatedZones(
|
666
|
-
item,
|
667
|
-
data,
|
668
|
-
newItem.props.id
|
669
|
-
);
|
670
|
-
if (action.sourceZone === rootDroppableId) {
|
671
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
|
672
|
-
content: insert(data.content, action.sourceIndex + 1, newItem)
|
673
|
-
});
|
674
|
-
}
|
675
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
|
676
|
-
zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
|
677
|
-
[action.sourceZone]: insert(
|
678
|
-
dataWithRelatedDuplicated.zones[action.sourceZone],
|
679
|
-
action.sourceIndex + 1,
|
680
|
-
newItem
|
681
|
-
)
|
682
|
-
})
|
683
|
-
});
|
684
|
-
}
|
685
|
-
if (action.type === "reorder") {
|
686
|
-
return reorderAction(data, action);
|
852
|
+
|
853
|
+
// ../core/reducer/actions/move.ts
|
854
|
+
var moveAction = (state, action, appStore) => {
|
855
|
+
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
856
|
+
return state;
|
687
857
|
}
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
858
|
+
const item = getItem(
|
859
|
+
{ zone: action.sourceZone, index: action.sourceIndex },
|
860
|
+
state
|
861
|
+
);
|
862
|
+
if (!item) return state;
|
863
|
+
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
864
|
+
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
865
|
+
return walkTree(
|
866
|
+
state,
|
867
|
+
appStore.config,
|
868
|
+
(content, zoneCompound) => {
|
869
|
+
if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
|
870
|
+
return insert(
|
871
|
+
remove(content, action.sourceIndex),
|
872
|
+
action.destinationIndex,
|
873
|
+
item
|
874
|
+
);
|
875
|
+
} else if (zoneCompound === action.sourceZone) {
|
876
|
+
return remove(content, action.sourceIndex);
|
877
|
+
} else if (zoneCompound === action.destinationZone) {
|
878
|
+
return insert(content, action.destinationIndex, item);
|
879
|
+
}
|
880
|
+
return content;
|
881
|
+
},
|
882
|
+
(childItem, path) => {
|
883
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
884
|
+
const [destinationZoneParent] = action.destinationZone.split(":");
|
885
|
+
const childId = childItem.props.id;
|
886
|
+
if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
|
887
|
+
return childItem;
|
888
|
+
}
|
889
|
+
return null;
|
702
890
|
}
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
891
|
+
);
|
892
|
+
};
|
893
|
+
|
894
|
+
// ../core/reducer/actions/reorder.ts
|
895
|
+
var reorderAction = (state, action, appStore) => {
|
896
|
+
return moveAction(
|
897
|
+
state,
|
898
|
+
{
|
899
|
+
type: "move",
|
900
|
+
sourceIndex: action.sourceIndex,
|
901
|
+
sourceZone: action.destinationZone,
|
902
|
+
destinationIndex: action.destinationIndex,
|
903
|
+
destinationZone: action.destinationZone
|
904
|
+
},
|
905
|
+
appStore
|
906
|
+
);
|
907
|
+
};
|
908
|
+
|
909
|
+
// ../core/reducer/actions/remove.ts
|
910
|
+
init_react_import();
|
911
|
+
var removeAction = (state, action, appStore) => {
|
912
|
+
const item = getItem({ index: action.index, zone: action.zone }, state);
|
913
|
+
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
914
|
+
(acc, [nodeId, nodeData]) => {
|
915
|
+
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
916
|
+
if (pathIds.includes(item.props.id)) {
|
917
|
+
return [...acc, nodeId];
|
918
|
+
}
|
919
|
+
return acc;
|
920
|
+
},
|
921
|
+
[item.props.id]
|
922
|
+
);
|
923
|
+
const newState = walkTree(
|
924
|
+
state,
|
925
|
+
appStore.config,
|
926
|
+
(content, zoneCompound) => {
|
927
|
+
if (zoneCompound === action.zone) {
|
928
|
+
return remove(content, action.index);
|
929
|
+
}
|
930
|
+
return content;
|
714
931
|
}
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
newData.zones[action.sourceZone],
|
721
|
-
action.sourceIndex
|
722
|
-
)
|
723
|
-
})
|
724
|
-
});
|
932
|
+
);
|
933
|
+
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
934
|
+
const parentId = zoneCompound.split(":")[0];
|
935
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
936
|
+
delete newState.data.zones[zoneCompound];
|
725
937
|
}
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
),
|
732
|
-
[action.destinationZone]: insert(
|
733
|
-
newData.zones[action.destinationZone],
|
734
|
-
action.destinationIndex,
|
735
|
-
item
|
736
|
-
)
|
737
|
-
})
|
738
|
-
});
|
739
|
-
}
|
740
|
-
if (action.type === "replace") {
|
741
|
-
return replaceAction(data, action);
|
742
|
-
}
|
743
|
-
if (action.type === "remove") {
|
744
|
-
const item = getItem({ index: action.index, zone: action.zone }, data);
|
745
|
-
const dataWithRelatedRemoved = setupZone(
|
746
|
-
removeRelatedZones(item, data),
|
747
|
-
action.zone
|
748
|
-
);
|
749
|
-
if (action.zone === rootDroppableId) {
|
750
|
-
return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
|
751
|
-
content: remove(data.content, action.index)
|
752
|
-
});
|
938
|
+
});
|
939
|
+
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
940
|
+
const parentId = zoneCompound.split(":")[0];
|
941
|
+
if (nodesToDelete.includes(parentId)) {
|
942
|
+
delete newState.indexes.zones[zoneCompound];
|
753
943
|
}
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
944
|
+
});
|
945
|
+
nodesToDelete.forEach((id) => {
|
946
|
+
delete newState.indexes.nodes[id];
|
947
|
+
});
|
948
|
+
return newState;
|
949
|
+
};
|
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;
|
762
959
|
}
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
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]) {
|
971
|
+
return __spreadProps(__spreadValues({}, state), {
|
972
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
973
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
767
974
|
[action.zone]: zoneCache[action.zone]
|
768
975
|
})
|
769
|
-
})
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
}
|
779
|
-
return __spreadProps(__spreadValues({}, data), { zones: _zones });
|
976
|
+
}),
|
977
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
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
|
+
})
|
984
|
+
})
|
985
|
+
});
|
780
986
|
}
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
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];
|
786
995
|
}
|
787
|
-
|
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
|
+
});
|
788
1005
|
}
|
789
1006
|
|
790
|
-
// ../core/reducer/
|
1007
|
+
// ../core/reducer/actions/set-data.ts
|
791
1008
|
init_react_import();
|
792
|
-
var
|
793
|
-
if (action.
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
return
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
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
|
+
);
|
1014
|
+
return walkTree(
|
1015
|
+
__spreadProps(__spreadValues({}, state), {
|
1016
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1017
|
+
}),
|
1018
|
+
appStore.config
|
1019
|
+
);
|
803
1020
|
}
|
804
|
-
|
805
|
-
|
806
|
-
|
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") {
|
1033
|
+
return __spreadProps(__spreadValues({}, state), {
|
1034
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
807
1035
|
});
|
808
1036
|
}
|
809
|
-
return
|
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 };
|
810
1047
|
};
|
811
1048
|
|
812
1049
|
// ../core/reducer/actions.tsx
|
@@ -826,29 +1063,54 @@ function storeInterceptor(reducer, record, onAction) {
|
|
826
1063
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
827
1064
|
if (record) record(newAppState);
|
828
1065
|
}
|
829
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1066
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
830
1067
|
return newAppState;
|
831
1068
|
};
|
832
1069
|
}
|
833
|
-
var setAction = (state, action) => {
|
834
|
-
if (typeof action.state === "object") {
|
835
|
-
return __spreadValues(__spreadValues({}, state), action.state);
|
836
|
-
}
|
837
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
838
|
-
};
|
839
1070
|
function createReducer({
|
840
|
-
config,
|
841
1071
|
record,
|
842
|
-
onAction
|
1072
|
+
onAction,
|
1073
|
+
appStore
|
843
1074
|
}) {
|
844
1075
|
return storeInterceptor(
|
845
1076
|
(state, action) => {
|
846
|
-
const data = reduceData(state.data, action, config);
|
847
|
-
const ui = reduceUi(state.ui, action);
|
848
1077
|
if (action.type === "set") {
|
849
|
-
return setAction(state, action);
|
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);
|
850
1103
|
}
|
851
|
-
|
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;
|
852
1114
|
},
|
853
1115
|
record,
|
854
1116
|
onAction
|
@@ -868,11 +1130,11 @@ init_react_import();
|
|
868
1130
|
var createStoreImpl = (createState) => {
|
869
1131
|
let state;
|
870
1132
|
const listeners = /* @__PURE__ */ new Set();
|
871
|
-
const setState = (partial,
|
1133
|
+
const setState = (partial, replace) => {
|
872
1134
|
const nextState = typeof partial === "function" ? partial(state) : partial;
|
873
1135
|
if (!Object.is(nextState, state)) {
|
874
1136
|
const previousState = state;
|
875
|
-
state = (
|
1137
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
876
1138
|
listeners.forEach((listener) => listener(state, previousState));
|
877
1139
|
}
|
878
1140
|
};
|
@@ -936,208 +1198,8 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
|
|
936
1198
|
};
|
937
1199
|
var subscribeWithSelector = subscribeWithSelectorImpl;
|
938
1200
|
|
939
|
-
// ../core/lib/resolve-data.ts
|
940
|
-
init_react_import();
|
941
|
-
|
942
|
-
// ../core/lib/resolve-component-data.ts
|
943
|
-
init_react_import();
|
944
|
-
|
945
|
-
// ../core/lib/get-changed.ts
|
946
|
-
init_react_import();
|
947
|
-
var getChanged = (newItem, oldItem) => {
|
948
|
-
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
949
|
-
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
950
|
-
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
951
|
-
return __spreadProps(__spreadValues({}, acc), {
|
952
|
-
[item]: oldItemProps[item] !== newItemProps[item]
|
953
|
-
});
|
954
|
-
}, {}) : {};
|
955
|
-
};
|
956
|
-
|
957
|
-
// ../core/lib/resolve-component-data.ts
|
958
|
-
var cache = { lastChange: {} };
|
959
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
|
960
|
-
const configForItem = config.components[item.type];
|
961
|
-
if (configForItem.resolveData) {
|
962
|
-
const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
|
963
|
-
if (item && item === oldItem) {
|
964
|
-
return resolved;
|
965
|
-
}
|
966
|
-
const changed = getChanged(item, oldItem);
|
967
|
-
if (onResolveStart) {
|
968
|
-
onResolveStart(item);
|
969
|
-
}
|
970
|
-
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
971
|
-
changed,
|
972
|
-
lastData: oldItem,
|
973
|
-
metadata
|
974
|
-
});
|
975
|
-
const resolvedItem = __spreadProps(__spreadValues({}, item), {
|
976
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
977
|
-
});
|
978
|
-
if (Object.keys(readOnly).length) {
|
979
|
-
resolvedItem.readOnly = readOnly;
|
980
|
-
}
|
981
|
-
cache.lastChange[item.props.id] = {
|
982
|
-
item,
|
983
|
-
resolved: resolvedItem
|
984
|
-
};
|
985
|
-
if (onResolveEnd) {
|
986
|
-
onResolveEnd(resolvedItem);
|
987
|
-
}
|
988
|
-
return resolvedItem;
|
989
|
-
}
|
990
|
-
return item;
|
991
|
-
});
|
992
|
-
|
993
|
-
// ../core/lib/apply-dynamic-props.ts
|
994
|
-
init_react_import();
|
995
|
-
var applyDynamicProps = (data, dynamicProps, rootData) => {
|
996
|
-
return __spreadProps(__spreadValues({}, data), {
|
997
|
-
root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
|
998
|
-
content: data.content.map((item) => {
|
999
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
1000
|
-
}),
|
1001
|
-
zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
|
1002
|
-
return __spreadProps(__spreadValues({}, acc), {
|
1003
|
-
[zoneKey]: data.zones[zoneKey].map((item) => {
|
1004
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
1005
|
-
})
|
1006
|
-
});
|
1007
|
-
}, {})
|
1008
|
-
});
|
1009
|
-
};
|
1010
|
-
|
1011
|
-
// ../core/lib/resolve-root-data.ts
|
1012
|
-
init_react_import();
|
1013
|
-
var cache2 = {};
|
1014
|
-
function resolveRootData(data, config, metadata) {
|
1015
|
-
return __async(this, null, function* () {
|
1016
|
-
var _a, _b, _c, _d, _e;
|
1017
|
-
if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
|
1018
|
-
if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
|
1019
|
-
return cache2.lastChange.resolved;
|
1020
|
-
}
|
1021
|
-
const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
|
1022
|
-
const rootWithProps = data.root;
|
1023
|
-
const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
|
1024
|
-
changed,
|
1025
|
-
lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
|
1026
|
-
metadata: metadata || {}
|
1027
|
-
});
|
1028
|
-
cache2.lastChange = {
|
1029
|
-
original: data.root,
|
1030
|
-
resolved: resolvedRoot
|
1031
|
-
};
|
1032
|
-
return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
|
1033
|
-
props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
|
1034
|
-
});
|
1035
|
-
}
|
1036
|
-
return data.root;
|
1037
|
-
});
|
1038
|
-
}
|
1039
|
-
|
1040
|
-
// ../core/lib/flatten-data.ts
|
1041
|
-
init_react_import();
|
1042
|
-
var flattenData = (data) => {
|
1043
|
-
return Object.keys(data.zones || {}).reduce(
|
1044
|
-
(acc, zone) => [...acc, ...data.zones[zone]],
|
1045
|
-
data.content
|
1046
|
-
);
|
1047
|
-
};
|
1048
|
-
|
1049
|
-
// ../core/lib/resolve-data.ts
|
1050
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1051
|
-
var resolveData = (newAppState, appStoreData) => {
|
1052
|
-
const {
|
1053
|
-
state: appState,
|
1054
|
-
config,
|
1055
|
-
dispatch,
|
1056
|
-
resolveDataRuns,
|
1057
|
-
setComponentLoading,
|
1058
|
-
unsetComponentLoading,
|
1059
|
-
metadata,
|
1060
|
-
permissions
|
1061
|
-
} = appStoreData;
|
1062
|
-
const deferredSetStates = {};
|
1063
|
-
const _setComponentLoading = (id, loading, defer = 0) => {
|
1064
|
-
if (deferredSetStates[id]) {
|
1065
|
-
clearTimeout(deferredSetStates[id]);
|
1066
|
-
delete deferredSetStates[id];
|
1067
|
-
}
|
1068
|
-
deferredSetStates[id] = setTimeout(() => {
|
1069
|
-
if (loading) {
|
1070
|
-
setComponentLoading(id);
|
1071
|
-
} else {
|
1072
|
-
unsetComponentLoading(id);
|
1073
|
-
}
|
1074
|
-
delete deferredSetStates[id];
|
1075
|
-
}, defer);
|
1076
|
-
};
|
1077
|
-
const runResolvers = () => __async(void 0, null, function* () {
|
1078
|
-
const newData = newAppState.data;
|
1079
|
-
const flatContent = flattenData(newData).filter(
|
1080
|
-
(item) => {
|
1081
|
-
var _a;
|
1082
|
-
return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
|
1083
|
-
}
|
1084
|
-
);
|
1085
|
-
const applyIfChange = (dynamicDataMap, dynamicRoot) => {
|
1086
|
-
const processed = applyDynamicProps(
|
1087
|
-
__spreadValues({}, appState.data),
|
1088
|
-
dynamicDataMap,
|
1089
|
-
dynamicRoot
|
1090
|
-
);
|
1091
|
-
const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
|
1092
|
-
const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
|
1093
|
-
if (containsChanges) {
|
1094
|
-
dispatch({
|
1095
|
-
type: "set",
|
1096
|
-
state: (prev) => __spreadProps(__spreadValues({}, prev), {
|
1097
|
-
data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
|
1098
|
-
ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
|
1099
|
-
}),
|
1100
|
-
recordHistory: resolveDataRuns > 0
|
1101
|
-
});
|
1102
|
-
}
|
1103
|
-
};
|
1104
|
-
const promises = [];
|
1105
|
-
promises.push(
|
1106
|
-
(() => __async(void 0, null, function* () {
|
1107
|
-
_setComponentLoading("puck-root", true, 50);
|
1108
|
-
const dynamicRoot = yield resolveRootData(newData, config, metadata);
|
1109
|
-
applyIfChange({}, dynamicRoot);
|
1110
|
-
_setComponentLoading("puck-root", false);
|
1111
|
-
}))()
|
1112
|
-
);
|
1113
|
-
flatContent.forEach((item) => {
|
1114
|
-
promises.push(
|
1115
|
-
(() => __async(void 0, null, function* () {
|
1116
|
-
permissions.resolvePermissions({ item }, true);
|
1117
|
-
const dynamicData = yield resolveComponentData(
|
1118
|
-
item,
|
1119
|
-
config,
|
1120
|
-
metadata,
|
1121
|
-
(item2) => {
|
1122
|
-
_setComponentLoading(item2.props.id, true, 50);
|
1123
|
-
},
|
1124
|
-
(item2) => {
|
1125
|
-
deferredSetStates[item2.props.id];
|
1126
|
-
_setComponentLoading(item2.props.id, false);
|
1127
|
-
}
|
1128
|
-
);
|
1129
|
-
const dynamicDataMap = { [item.props.id]: dynamicData };
|
1130
|
-
applyIfChange(dynamicDataMap);
|
1131
|
-
}))()
|
1132
|
-
);
|
1133
|
-
});
|
1134
|
-
yield Promise.all(promises);
|
1135
|
-
});
|
1136
|
-
return runResolvers();
|
1137
|
-
};
|
1138
|
-
|
1139
1201
|
// ../core/store/index.ts
|
1140
|
-
var
|
1202
|
+
var import_react9 = require("react");
|
1141
1203
|
|
1142
1204
|
// ../core/store/slices/history.ts
|
1143
1205
|
init_react_import();
|
@@ -1243,7 +1305,7 @@ var createHistorySlice = (set, get) => {
|
|
1243
1305
|
const { dispatch, history } = get();
|
1244
1306
|
dispatch({
|
1245
1307
|
type: "set",
|
1246
|
-
state: ((_a = history.histories[
|
1308
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1247
1309
|
});
|
1248
1310
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1249
1311
|
},
|
@@ -1253,31 +1315,14 @@ var createHistorySlice = (set, get) => {
|
|
1253
1315
|
|
1254
1316
|
// ../core/store/slices/nodes.ts
|
1255
1317
|
init_react_import();
|
1256
|
-
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1257
|
-
var import_react7 = require("react");
|
1258
|
-
var partialDeepEqual = (newItem, existingItem) => {
|
1259
|
-
const filteredExistingItem = Object.keys(newItem).reduce(
|
1260
|
-
(acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
|
1261
|
-
{}
|
1262
|
-
);
|
1263
|
-
return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
|
1264
|
-
};
|
1265
1318
|
var createNodesSlice = (set, get) => ({
|
1266
1319
|
nodes: {},
|
1267
1320
|
registerNode: (id, node) => {
|
1268
1321
|
const s = get().nodes;
|
1269
|
-
if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
|
1270
|
-
return;
|
1271
|
-
}
|
1272
1322
|
const emptyNode = {
|
1273
1323
|
id,
|
1274
1324
|
methods: { sync: () => null },
|
1275
|
-
|
1276
|
-
parentId: "",
|
1277
|
-
zone: "",
|
1278
|
-
path: [],
|
1279
|
-
element: null,
|
1280
|
-
index: -1
|
1325
|
+
element: null
|
1281
1326
|
};
|
1282
1327
|
const existingNode = s.nodes[id];
|
1283
1328
|
set({
|
@@ -1307,36 +1352,61 @@ var createNodesSlice = (set, get) => ({
|
|
1307
1352
|
|
1308
1353
|
// ../core/store/slices/permissions.ts
|
1309
1354
|
init_react_import();
|
1310
|
-
var
|
1355
|
+
var import_react7 = require("react");
|
1356
|
+
|
1357
|
+
// ../core/lib/data/flatten-data.ts
|
1358
|
+
init_react_import();
|
1359
|
+
var flattenData = (state, config) => {
|
1360
|
+
const data = [];
|
1361
|
+
walkTree(
|
1362
|
+
state,
|
1363
|
+
config,
|
1364
|
+
(content) => content,
|
1365
|
+
(item) => {
|
1366
|
+
data.push(item);
|
1367
|
+
return null;
|
1368
|
+
}
|
1369
|
+
);
|
1370
|
+
return data;
|
1371
|
+
};
|
1372
|
+
|
1373
|
+
// ../core/lib/get-changed.ts
|
1374
|
+
init_react_import();
|
1375
|
+
var getChanged = (newItem, oldItem) => {
|
1376
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1377
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1378
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1379
|
+
return __spreadProps(__spreadValues({}, acc), {
|
1380
|
+
[item]: oldItemProps[item] !== newItemProps[item]
|
1381
|
+
});
|
1382
|
+
}, {}) : {};
|
1383
|
+
};
|
1384
|
+
|
1385
|
+
// ../core/store/slices/permissions.ts
|
1311
1386
|
var createPermissionsSlice = (set, get) => {
|
1312
1387
|
const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
|
1313
|
-
const { state, permissions } = get();
|
1314
|
-
const { cache:
|
1388
|
+
const { state, permissions, config } = get();
|
1389
|
+
const { cache: cache2, globalPermissions } = permissions;
|
1315
1390
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1316
1391
|
var _a, _b, _c;
|
1317
|
-
const {
|
1318
|
-
|
1319
|
-
state: appState,
|
1320
|
-
setComponentLoading,
|
1321
|
-
unsetComponentLoading
|
1322
|
-
} = get();
|
1323
|
-
const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
|
1392
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1393
|
+
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1324
1394
|
if (!componentConfig) {
|
1325
1395
|
return;
|
1326
1396
|
}
|
1327
1397
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
1328
1398
|
if (componentConfig.resolvePermissions) {
|
1329
|
-
const changed = getChanged(item2, (_a =
|
1399
|
+
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1330
1400
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1331
|
-
setComponentLoading(item2.props.id);
|
1401
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1332
1402
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1333
1403
|
item2,
|
1334
1404
|
{
|
1335
1405
|
changed,
|
1336
|
-
lastPermissions: ((_b =
|
1406
|
+
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1337
1407
|
permissions: initialPermissions,
|
1338
|
-
appState,
|
1339
|
-
lastData: ((_c =
|
1408
|
+
appState: makeStatePublic(appState),
|
1409
|
+
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1340
1410
|
}
|
1341
1411
|
);
|
1342
1412
|
const latest = get().permissions;
|
@@ -1353,7 +1423,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1353
1423
|
})
|
1354
1424
|
})
|
1355
1425
|
});
|
1356
|
-
|
1426
|
+
clearTimeout2();
|
1357
1427
|
}
|
1358
1428
|
}
|
1359
1429
|
});
|
@@ -1363,7 +1433,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1363
1433
|
// Shim the root data in by conforming to component data shape
|
1364
1434
|
{
|
1365
1435
|
type: "root",
|
1366
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1436
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1367
1437
|
},
|
1368
1438
|
force2
|
1369
1439
|
);
|
@@ -1372,14 +1442,13 @@ var createPermissionsSlice = (set, get) => {
|
|
1372
1442
|
if (item) {
|
1373
1443
|
yield resolveDataForItem(item, force);
|
1374
1444
|
} else if (type) {
|
1375
|
-
flattenData(state
|
1445
|
+
flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
1376
1446
|
yield resolveDataForItem(item2, force);
|
1377
1447
|
}));
|
1378
1448
|
} else if (root) {
|
1379
1449
|
resolveDataForRoot(force);
|
1380
1450
|
} else {
|
1381
|
-
|
1382
|
-
flattenData(state.data).map((item2) => __async(void 0, null, function* () {
|
1451
|
+
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1383
1452
|
yield resolveDataForItem(item2, force);
|
1384
1453
|
}));
|
1385
1454
|
}
|
@@ -1409,7 +1478,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1409
1478
|
} else if (root) {
|
1410
1479
|
const rootConfig = config.root;
|
1411
1480
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1412
|
-
const resolvedForItem = resolvedPermissions["
|
1481
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1413
1482
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1414
1483
|
}
|
1415
1484
|
return globalPermissions;
|
@@ -1421,8 +1490,8 @@ var createPermissionsSlice = (set, get) => {
|
|
1421
1490
|
|
1422
1491
|
// ../core/store/slices/fields.ts
|
1423
1492
|
init_react_import();
|
1424
|
-
var
|
1425
|
-
var
|
1493
|
+
var import_react8 = require("react");
|
1494
|
+
var createFieldsSlice = (_set, _get) => {
|
1426
1495
|
return {
|
1427
1496
|
fields: {},
|
1428
1497
|
loading: false,
|
@@ -1430,6 +1499,112 @@ var createFieldsStore = (_set, _get) => {
|
|
1430
1499
|
};
|
1431
1500
|
};
|
1432
1501
|
|
1502
|
+
// ../core/lib/resolve-component-data.ts
|
1503
|
+
init_react_import();
|
1504
|
+
|
1505
|
+
// ../core/lib/data/map-slots.ts
|
1506
|
+
init_react_import();
|
1507
|
+
function mapSlotsAsync(_0, _1) {
|
1508
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1509
|
+
const props = __spreadValues({}, item.props);
|
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];
|
1516
|
+
const mappedContent = recursive ? yield Promise.all(
|
1517
|
+
content.map((item2) => __async(this, null, function* () {
|
1518
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
1519
|
+
}))
|
1520
|
+
) : content;
|
1521
|
+
props[propKey] = yield map(mappedContent, propKey);
|
1522
|
+
}
|
1523
|
+
}
|
1524
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
1525
|
+
});
|
1526
|
+
}
|
1527
|
+
|
1528
|
+
// ../core/lib/resolve-component-data.ts
|
1529
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1530
|
+
var cache = { lastChange: {} };
|
1531
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
1532
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1533
|
+
if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
|
1534
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1535
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1536
|
+
if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
|
1537
|
+
return { node: resolved, didChange: false };
|
1538
|
+
}
|
1539
|
+
const changed = getChanged(item, oldItem);
|
1540
|
+
if (onResolveStart) {
|
1541
|
+
onResolveStart(item);
|
1542
|
+
}
|
1543
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1544
|
+
changed,
|
1545
|
+
lastData: oldItem,
|
1546
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1547
|
+
trigger
|
1548
|
+
});
|
1549
|
+
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1550
|
+
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1551
|
+
});
|
1552
|
+
if (recursive) {
|
1553
|
+
resolvedItem = yield mapSlotsAsync(
|
1554
|
+
resolvedItem,
|
1555
|
+
(content) => __async(void 0, null, function* () {
|
1556
|
+
return Promise.all(
|
1557
|
+
content.map(
|
1558
|
+
(childItem) => __async(void 0, null, function* () {
|
1559
|
+
return (yield resolveComponentData(
|
1560
|
+
childItem,
|
1561
|
+
config,
|
1562
|
+
metadata,
|
1563
|
+
onResolveStart,
|
1564
|
+
onResolveEnd,
|
1565
|
+
trigger,
|
1566
|
+
false
|
1567
|
+
)).node;
|
1568
|
+
})
|
1569
|
+
)
|
1570
|
+
);
|
1571
|
+
}),
|
1572
|
+
false,
|
1573
|
+
createIsSlotConfig(config)
|
1574
|
+
);
|
1575
|
+
}
|
1576
|
+
if (Object.keys(readOnly).length) {
|
1577
|
+
resolvedItem.readOnly = readOnly;
|
1578
|
+
}
|
1579
|
+
cache.lastChange[id] = {
|
1580
|
+
item,
|
1581
|
+
resolved: resolvedItem
|
1582
|
+
};
|
1583
|
+
if (onResolveEnd) {
|
1584
|
+
onResolveEnd(resolvedItem);
|
1585
|
+
}
|
1586
|
+
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1587
|
+
}
|
1588
|
+
return { node: item, didChange: false };
|
1589
|
+
});
|
1590
|
+
|
1591
|
+
// ../core/lib/data/to-root.ts
|
1592
|
+
init_react_import();
|
1593
|
+
var toRoot = (item) => {
|
1594
|
+
if ("type" in item && item.type !== "root") {
|
1595
|
+
throw new Error("Converting non-root item to root.");
|
1596
|
+
}
|
1597
|
+
const { readOnly } = item;
|
1598
|
+
if (item.props) {
|
1599
|
+
if ("id" in item.props) {
|
1600
|
+
const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
|
1601
|
+
return { props, readOnly };
|
1602
|
+
}
|
1603
|
+
return { props: item.props, readOnly };
|
1604
|
+
}
|
1605
|
+
return { props: {}, readOnly };
|
1606
|
+
};
|
1607
|
+
|
1433
1608
|
// ../core/store/index.ts
|
1434
1609
|
var defaultAppState = {
|
1435
1610
|
data: { content: [], root: {}, zones: {} },
|
@@ -1450,100 +1625,194 @@ var defaultAppState = {
|
|
1450
1625
|
controlsVisible: true
|
1451
1626
|
},
|
1452
1627
|
field: { focus: null }
|
1628
|
+
},
|
1629
|
+
indexes: {
|
1630
|
+
nodes: {},
|
1631
|
+
zones: {}
|
1453
1632
|
}
|
1454
1633
|
};
|
1455
1634
|
var defaultPageFields = {
|
1456
1635
|
title: { type: "text" }
|
1457
1636
|
};
|
1458
1637
|
var createAppStore = (initialAppStore) => create()(
|
1459
|
-
subscribeWithSelector((set, get) =>
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
})
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
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
|
1725
|
+
})
|
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 });
|
1765
|
+
}
|
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
|
+
})
|
1539
1808
|
);
|
1540
|
-
var appStoreContext = (0,
|
1809
|
+
var appStoreContext = (0, import_react9.createContext)(createAppStore());
|
1541
1810
|
function useAppStore(selector) {
|
1542
|
-
const context = (0,
|
1811
|
+
const context = (0, import_react9.useContext)(appStoreContext);
|
1543
1812
|
return useStore(context, selector);
|
1544
1813
|
}
|
1545
1814
|
function useAppStoreApi() {
|
1546
|
-
return (0,
|
1815
|
+
return (0, import_react9.useContext)(appStoreContext);
|
1547
1816
|
}
|
1548
1817
|
|
1549
1818
|
// ../core/lib/use-breadcrumbs.ts
|
@@ -1555,12 +1824,12 @@ var useBreadcrumbs = (renderCount) => {
|
|
1555
1824
|
const config = useAppStore((s) => s.config);
|
1556
1825
|
const path = useAppStore((s) => {
|
1557
1826
|
var _a;
|
1558
|
-
return (_a = s.
|
1827
|
+
return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
|
1559
1828
|
});
|
1560
1829
|
const appStore = useAppStoreApi();
|
1561
|
-
return (0,
|
1830
|
+
return (0, import_react10.useMemo)(() => {
|
1562
1831
|
const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
|
1563
|
-
var _a, _b;
|
1832
|
+
var _a, _b, _c;
|
1564
1833
|
const [componentId] = zoneCompound.split(":");
|
1565
1834
|
if (componentId === "root") {
|
1566
1835
|
return {
|
@@ -1568,12 +1837,15 @@ var useBreadcrumbs = (renderCount) => {
|
|
1568
1837
|
selector: null
|
1569
1838
|
};
|
1570
1839
|
}
|
1571
|
-
const node = appStore.getState().
|
1572
|
-
const
|
1840
|
+
const node = appStore.getState().state.indexes.nodes[componentId];
|
1841
|
+
const parentId = node.path[node.path.length - 1];
|
1842
|
+
const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
|
1843
|
+
const index = contentIds.indexOf(componentId);
|
1844
|
+
const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
|
1573
1845
|
return {
|
1574
1846
|
label,
|
1575
1847
|
selector: node ? {
|
1576
|
-
index
|
1848
|
+
index,
|
1577
1849
|
zone: node.path[node.path.length - 1]
|
1578
1850
|
} : null
|
1579
1851
|
};
|
@@ -1594,6 +1866,12 @@ init_react_import();
|
|
1594
1866
|
// ../core/lib/filter.ts
|
1595
1867
|
init_react_import();
|
1596
1868
|
|
1869
|
+
// ../core/lib/data/reorder.ts
|
1870
|
+
init_react_import();
|
1871
|
+
|
1872
|
+
// ../core/lib/data/replace.ts
|
1873
|
+
init_react_import();
|
1874
|
+
|
1597
1875
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
1598
1876
|
init_react_import();
|
1599
1877
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
@@ -1774,18 +2052,40 @@ function buildHierarchy(frame) {
|
|
1774
2052
|
var usePuck = (0, import_puck.createUsePuck)();
|
1775
2053
|
var HeadingAnalyzer = () => {
|
1776
2054
|
const data = usePuck((s) => s.appState.data);
|
1777
|
-
const [hierarchy, setHierarchy] = (0,
|
1778
|
-
(0,
|
2055
|
+
const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
|
2056
|
+
(0, import_react11.useEffect)(() => {
|
1779
2057
|
const frame = getFrame();
|
1780
|
-
|
1781
|
-
|
1782
|
-
setHierarchy(buildHierarchy(entry));
|
1783
|
-
const observer = new MutationObserver(() => {
|
2058
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2059
|
+
const createHierarchy = () => {
|
1784
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
|
+
}
|
1785
2071
|
});
|
1786
|
-
|
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
|
+
}
|
1787
2086
|
return () => {
|
1788
|
-
|
2087
|
+
entryObserver.disconnect();
|
2088
|
+
frameObserver.disconnect();
|
1789
2089
|
};
|
1790
2090
|
}, [data]);
|
1791
2091
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
|