@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.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,386 @@ 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 [parentId] = action.zone.split(":");
|
914
|
+
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
915
|
+
(acc, [nodeId, nodeData]) => {
|
916
|
+
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
917
|
+
if (pathIds.includes(item.props.id)) {
|
918
|
+
return [...acc, nodeId];
|
919
|
+
}
|
920
|
+
return acc;
|
921
|
+
},
|
922
|
+
[item.props.id]
|
923
|
+
);
|
924
|
+
const newState = walkTree(
|
925
|
+
state,
|
926
|
+
appStore.config,
|
927
|
+
(content, zoneCompound) => {
|
928
|
+
if (zoneCompound === action.zone) {
|
929
|
+
return remove(content, action.index);
|
930
|
+
}
|
931
|
+
return content;
|
932
|
+
},
|
933
|
+
(childItem, path) => {
|
934
|
+
const parentIds = path.map((p) => p.split(":")[0]);
|
935
|
+
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
936
|
+
return childItem;
|
937
|
+
}
|
938
|
+
return null;
|
714
939
|
}
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
newData.zones[action.sourceZone],
|
721
|
-
action.sourceIndex
|
722
|
-
)
|
723
|
-
})
|
724
|
-
});
|
940
|
+
);
|
941
|
+
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
942
|
+
const parentId2 = zoneCompound.split(":")[0];
|
943
|
+
if (nodesToDelete.includes(parentId2) && newState.data.zones) {
|
944
|
+
delete newState.data.zones[zoneCompound];
|
725
945
|
}
|
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
|
-
});
|
946
|
+
});
|
947
|
+
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
948
|
+
const parentId2 = zoneCompound.split(":")[0];
|
949
|
+
if (nodesToDelete.includes(parentId2)) {
|
950
|
+
delete newState.indexes.zones[zoneCompound];
|
753
951
|
}
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
952
|
+
});
|
953
|
+
nodesToDelete.forEach((id) => {
|
954
|
+
delete newState.indexes.nodes[id];
|
955
|
+
});
|
956
|
+
return newState;
|
957
|
+
};
|
958
|
+
|
959
|
+
// ../core/reducer/actions/register-zone.ts
|
960
|
+
init_react_import();
|
961
|
+
|
962
|
+
// ../core/lib/data/setup-zone.ts
|
963
|
+
init_react_import();
|
964
|
+
var setupZone = (data, zoneKey) => {
|
965
|
+
if (zoneKey === rootDroppableId) {
|
966
|
+
return data;
|
762
967
|
}
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
968
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
969
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
970
|
+
});
|
971
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
972
|
+
return newData;
|
973
|
+
};
|
974
|
+
|
975
|
+
// ../core/reducer/actions/register-zone.ts
|
976
|
+
var zoneCache = {};
|
977
|
+
function registerZoneAction(state, action) {
|
978
|
+
if (zoneCache[action.zone]) {
|
979
|
+
return __spreadProps(__spreadValues({}, state), {
|
980
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
981
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
767
982
|
[action.zone]: zoneCache[action.zone]
|
768
983
|
})
|
769
|
-
})
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
}
|
779
|
-
return __spreadProps(__spreadValues({}, data), { zones: _zones });
|
984
|
+
}),
|
985
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
986
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
987
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
988
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
989
|
+
type: "dropzone"
|
990
|
+
})
|
991
|
+
})
|
992
|
+
})
|
993
|
+
});
|
780
994
|
}
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
995
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
996
|
+
}
|
997
|
+
function unregisterZoneAction(state, action) {
|
998
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
999
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
1000
|
+
if (_zones[action.zone]) {
|
1001
|
+
zoneCache[action.zone] = _zones[action.zone];
|
1002
|
+
delete _zones[action.zone];
|
786
1003
|
}
|
787
|
-
|
1004
|
+
delete zoneIndex[action.zone];
|
1005
|
+
return __spreadProps(__spreadValues({}, state), {
|
1006
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
1007
|
+
zones: _zones
|
1008
|
+
}),
|
1009
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1010
|
+
zones: zoneIndex
|
1011
|
+
})
|
1012
|
+
});
|
788
1013
|
}
|
789
1014
|
|
790
|
-
// ../core/reducer/
|
1015
|
+
// ../core/reducer/actions/set-data.ts
|
791
1016
|
init_react_import();
|
792
|
-
var
|
793
|
-
if (action.
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
return
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
1017
|
+
var setDataAction = (state, action, appStore) => {
|
1018
|
+
if (typeof action.data === "object") {
|
1019
|
+
console.warn(
|
1020
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1021
|
+
);
|
1022
|
+
return walkTree(
|
1023
|
+
__spreadProps(__spreadValues({}, state), {
|
1024
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1025
|
+
}),
|
1026
|
+
appStore.config
|
1027
|
+
);
|
803
1028
|
}
|
804
|
-
|
805
|
-
|
806
|
-
|
1029
|
+
return walkTree(
|
1030
|
+
__spreadProps(__spreadValues({}, state), {
|
1031
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1032
|
+
}),
|
1033
|
+
appStore.config
|
1034
|
+
);
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
// ../core/reducer/actions/set-ui.ts
|
1038
|
+
init_react_import();
|
1039
|
+
var setUiAction = (state, action) => {
|
1040
|
+
if (typeof action.ui === "object") {
|
1041
|
+
return __spreadProps(__spreadValues({}, state), {
|
1042
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
807
1043
|
});
|
808
1044
|
}
|
809
|
-
return
|
1045
|
+
return __spreadProps(__spreadValues({}, state), {
|
1046
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
1047
|
+
});
|
1048
|
+
};
|
1049
|
+
|
1050
|
+
// ../core/lib/data/make-state-public.ts
|
1051
|
+
init_react_import();
|
1052
|
+
var makeStatePublic = (state) => {
|
1053
|
+
const { data, ui } = state;
|
1054
|
+
return { data, ui };
|
810
1055
|
};
|
811
1056
|
|
812
1057
|
// ../core/reducer/actions.tsx
|
@@ -826,29 +1071,54 @@ function storeInterceptor(reducer, record, onAction) {
|
|
826
1071
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
827
1072
|
if (record) record(newAppState);
|
828
1073
|
}
|
829
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1074
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
830
1075
|
return newAppState;
|
831
1076
|
};
|
832
1077
|
}
|
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
1078
|
function createReducer({
|
840
|
-
config,
|
841
1079
|
record,
|
842
|
-
onAction
|
1080
|
+
onAction,
|
1081
|
+
appStore
|
843
1082
|
}) {
|
844
1083
|
return storeInterceptor(
|
845
1084
|
(state, action) => {
|
846
|
-
const data = reduceData(state.data, action, config);
|
847
|
-
const ui = reduceUi(state.ui, action);
|
848
1085
|
if (action.type === "set") {
|
849
|
-
return setAction(state, action);
|
1086
|
+
return setAction(state, action, appStore);
|
1087
|
+
}
|
1088
|
+
if (action.type === "insert") {
|
1089
|
+
return insertAction(state, action, appStore);
|
1090
|
+
}
|
1091
|
+
if (action.type === "replace") {
|
1092
|
+
return replaceAction(state, action, appStore);
|
1093
|
+
}
|
1094
|
+
if (action.type === "replaceRoot") {
|
1095
|
+
return replaceRootAction(state, action, appStore);
|
1096
|
+
}
|
1097
|
+
if (action.type === "duplicate") {
|
1098
|
+
return duplicateAction(state, action, appStore);
|
1099
|
+
}
|
1100
|
+
if (action.type === "reorder") {
|
1101
|
+
return reorderAction(state, action, appStore);
|
1102
|
+
}
|
1103
|
+
if (action.type === "move") {
|
1104
|
+
return moveAction(state, action, appStore);
|
1105
|
+
}
|
1106
|
+
if (action.type === "remove") {
|
1107
|
+
return removeAction(state, action, appStore);
|
1108
|
+
}
|
1109
|
+
if (action.type === "registerZone") {
|
1110
|
+
return registerZoneAction(state, action);
|
850
1111
|
}
|
851
|
-
|
1112
|
+
if (action.type === "unregisterZone") {
|
1113
|
+
return unregisterZoneAction(state, action);
|
1114
|
+
}
|
1115
|
+
if (action.type === "setData") {
|
1116
|
+
return setDataAction(state, action, appStore);
|
1117
|
+
}
|
1118
|
+
if (action.type === "setUi") {
|
1119
|
+
return setUiAction(state, action);
|
1120
|
+
}
|
1121
|
+
return state;
|
852
1122
|
},
|
853
1123
|
record,
|
854
1124
|
onAction
|
@@ -868,11 +1138,11 @@ init_react_import();
|
|
868
1138
|
var createStoreImpl = (createState) => {
|
869
1139
|
let state;
|
870
1140
|
const listeners = /* @__PURE__ */ new Set();
|
871
|
-
const setState = (partial,
|
1141
|
+
const setState = (partial, replace) => {
|
872
1142
|
const nextState = typeof partial === "function" ? partial(state) : partial;
|
873
1143
|
if (!Object.is(nextState, state)) {
|
874
1144
|
const previousState = state;
|
875
|
-
state = (
|
1145
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
876
1146
|
listeners.forEach((listener) => listener(state, previousState));
|
877
1147
|
}
|
878
1148
|
};
|
@@ -936,208 +1206,8 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
|
|
936
1206
|
};
|
937
1207
|
var subscribeWithSelector = subscribeWithSelectorImpl;
|
938
1208
|
|
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
1209
|
// ../core/store/index.ts
|
1140
|
-
var
|
1210
|
+
var import_react9 = require("react");
|
1141
1211
|
|
1142
1212
|
// ../core/store/slices/history.ts
|
1143
1213
|
init_react_import();
|
@@ -1253,31 +1323,14 @@ var createHistorySlice = (set, get) => {
|
|
1253
1323
|
|
1254
1324
|
// ../core/store/slices/nodes.ts
|
1255
1325
|
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
1326
|
var createNodesSlice = (set, get) => ({
|
1266
1327
|
nodes: {},
|
1267
1328
|
registerNode: (id, node) => {
|
1268
1329
|
const s = get().nodes;
|
1269
|
-
if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
|
1270
|
-
return;
|
1271
|
-
}
|
1272
1330
|
const emptyNode = {
|
1273
1331
|
id,
|
1274
1332
|
methods: { sync: () => null },
|
1275
|
-
|
1276
|
-
parentId: "",
|
1277
|
-
zone: "",
|
1278
|
-
path: [],
|
1279
|
-
element: null,
|
1280
|
-
index: -1
|
1333
|
+
element: null
|
1281
1334
|
};
|
1282
1335
|
const existingNode = s.nodes[id];
|
1283
1336
|
set({
|
@@ -1307,36 +1360,61 @@ var createNodesSlice = (set, get) => ({
|
|
1307
1360
|
|
1308
1361
|
// ../core/store/slices/permissions.ts
|
1309
1362
|
init_react_import();
|
1310
|
-
var
|
1363
|
+
var import_react7 = require("react");
|
1364
|
+
|
1365
|
+
// ../core/lib/data/flatten-data.ts
|
1366
|
+
init_react_import();
|
1367
|
+
var flattenData = (state, config) => {
|
1368
|
+
const data = [];
|
1369
|
+
walkTree(
|
1370
|
+
state,
|
1371
|
+
config,
|
1372
|
+
(content) => content,
|
1373
|
+
(item) => {
|
1374
|
+
data.push(item);
|
1375
|
+
return null;
|
1376
|
+
}
|
1377
|
+
);
|
1378
|
+
return data;
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
// ../core/lib/get-changed.ts
|
1382
|
+
init_react_import();
|
1383
|
+
var getChanged = (newItem, oldItem) => {
|
1384
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1385
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1386
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1387
|
+
return __spreadProps(__spreadValues({}, acc), {
|
1388
|
+
[item]: oldItemProps[item] !== newItemProps[item]
|
1389
|
+
});
|
1390
|
+
}, {}) : {};
|
1391
|
+
};
|
1392
|
+
|
1393
|
+
// ../core/store/slices/permissions.ts
|
1311
1394
|
var createPermissionsSlice = (set, get) => {
|
1312
1395
|
const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
|
1313
|
-
const { state, permissions } = get();
|
1314
|
-
const { cache:
|
1396
|
+
const { state, permissions, config } = get();
|
1397
|
+
const { cache: cache2, globalPermissions } = permissions;
|
1315
1398
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1316
1399
|
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];
|
1400
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1401
|
+
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1324
1402
|
if (!componentConfig) {
|
1325
1403
|
return;
|
1326
1404
|
}
|
1327
1405
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
1328
1406
|
if (componentConfig.resolvePermissions) {
|
1329
|
-
const changed = getChanged(item2, (_a =
|
1407
|
+
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1330
1408
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1331
|
-
setComponentLoading(item2.props.id);
|
1409
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1332
1410
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1333
1411
|
item2,
|
1334
1412
|
{
|
1335
1413
|
changed,
|
1336
|
-
lastPermissions: ((_b =
|
1414
|
+
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1337
1415
|
permissions: initialPermissions,
|
1338
|
-
appState,
|
1339
|
-
lastData: ((_c =
|
1416
|
+
appState: makeStatePublic(appState),
|
1417
|
+
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1340
1418
|
}
|
1341
1419
|
);
|
1342
1420
|
const latest = get().permissions;
|
@@ -1353,7 +1431,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1353
1431
|
})
|
1354
1432
|
})
|
1355
1433
|
});
|
1356
|
-
|
1434
|
+
clearTimeout2();
|
1357
1435
|
}
|
1358
1436
|
}
|
1359
1437
|
});
|
@@ -1363,7 +1441,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1363
1441
|
// Shim the root data in by conforming to component data shape
|
1364
1442
|
{
|
1365
1443
|
type: "root",
|
1366
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1444
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1367
1445
|
},
|
1368
1446
|
force2
|
1369
1447
|
);
|
@@ -1372,14 +1450,13 @@ var createPermissionsSlice = (set, get) => {
|
|
1372
1450
|
if (item) {
|
1373
1451
|
yield resolveDataForItem(item, force);
|
1374
1452
|
} else if (type) {
|
1375
|
-
flattenData(state
|
1453
|
+
flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
1376
1454
|
yield resolveDataForItem(item2, force);
|
1377
1455
|
}));
|
1378
1456
|
} else if (root) {
|
1379
1457
|
resolveDataForRoot(force);
|
1380
1458
|
} else {
|
1381
|
-
|
1382
|
-
flattenData(state.data).map((item2) => __async(void 0, null, function* () {
|
1459
|
+
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1383
1460
|
yield resolveDataForItem(item2, force);
|
1384
1461
|
}));
|
1385
1462
|
}
|
@@ -1409,7 +1486,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1409
1486
|
} else if (root) {
|
1410
1487
|
const rootConfig = config.root;
|
1411
1488
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1412
|
-
const resolvedForItem = resolvedPermissions["
|
1489
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1413
1490
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1414
1491
|
}
|
1415
1492
|
return globalPermissions;
|
@@ -1421,8 +1498,8 @@ var createPermissionsSlice = (set, get) => {
|
|
1421
1498
|
|
1422
1499
|
// ../core/store/slices/fields.ts
|
1423
1500
|
init_react_import();
|
1424
|
-
var
|
1425
|
-
var
|
1501
|
+
var import_react8 = require("react");
|
1502
|
+
var createFieldsSlice = (_set, _get) => {
|
1426
1503
|
return {
|
1427
1504
|
fields: {},
|
1428
1505
|
loading: false,
|
@@ -1430,6 +1507,112 @@ var createFieldsStore = (_set, _get) => {
|
|
1430
1507
|
};
|
1431
1508
|
};
|
1432
1509
|
|
1510
|
+
// ../core/lib/resolve-component-data.ts
|
1511
|
+
init_react_import();
|
1512
|
+
|
1513
|
+
// ../core/lib/data/map-slots.ts
|
1514
|
+
init_react_import();
|
1515
|
+
function mapSlots(_0, _1) {
|
1516
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1517
|
+
const props = __spreadValues({}, item.props);
|
1518
|
+
const propKeys = Object.keys(props);
|
1519
|
+
for (let i = 0; i < propKeys.length; i++) {
|
1520
|
+
const propKey = propKeys[i];
|
1521
|
+
const itemType = "type" in item ? item.type : "root";
|
1522
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
1523
|
+
const content = props[propKey];
|
1524
|
+
const mappedContent = recursive ? yield Promise.all(
|
1525
|
+
content.map((item2) => __async(this, null, function* () {
|
1526
|
+
return yield mapSlots(item2, map, recursive, isSlot2);
|
1527
|
+
}))
|
1528
|
+
) : content;
|
1529
|
+
props[propKey] = yield map(mappedContent, propKey);
|
1530
|
+
}
|
1531
|
+
}
|
1532
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
1533
|
+
});
|
1534
|
+
}
|
1535
|
+
|
1536
|
+
// ../core/lib/resolve-component-data.ts
|
1537
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1538
|
+
var cache = { lastChange: {} };
|
1539
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
1540
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1541
|
+
if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
|
1542
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1543
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1544
|
+
if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
|
1545
|
+
return { node: resolved, didChange: false };
|
1546
|
+
}
|
1547
|
+
const changed = getChanged(item, oldItem);
|
1548
|
+
if (onResolveStart) {
|
1549
|
+
onResolveStart(item);
|
1550
|
+
}
|
1551
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1552
|
+
changed,
|
1553
|
+
lastData: oldItem,
|
1554
|
+
metadata,
|
1555
|
+
trigger
|
1556
|
+
});
|
1557
|
+
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1558
|
+
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1559
|
+
});
|
1560
|
+
if (recursive) {
|
1561
|
+
resolvedItem = yield mapSlots(
|
1562
|
+
resolvedItem,
|
1563
|
+
(content) => __async(void 0, null, function* () {
|
1564
|
+
return Promise.all(
|
1565
|
+
content.map(
|
1566
|
+
(childItem) => __async(void 0, null, function* () {
|
1567
|
+
return (yield resolveComponentData(
|
1568
|
+
childItem,
|
1569
|
+
config,
|
1570
|
+
metadata,
|
1571
|
+
onResolveStart,
|
1572
|
+
onResolveEnd,
|
1573
|
+
trigger,
|
1574
|
+
false
|
1575
|
+
)).node;
|
1576
|
+
})
|
1577
|
+
)
|
1578
|
+
);
|
1579
|
+
}),
|
1580
|
+
false,
|
1581
|
+
createIsSlotConfig(config)
|
1582
|
+
);
|
1583
|
+
}
|
1584
|
+
if (Object.keys(readOnly).length) {
|
1585
|
+
resolvedItem.readOnly = readOnly;
|
1586
|
+
}
|
1587
|
+
cache.lastChange[id] = {
|
1588
|
+
item,
|
1589
|
+
resolved: resolvedItem
|
1590
|
+
};
|
1591
|
+
if (onResolveEnd) {
|
1592
|
+
onResolveEnd(resolvedItem);
|
1593
|
+
}
|
1594
|
+
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1595
|
+
}
|
1596
|
+
return { node: item, didChange: false };
|
1597
|
+
});
|
1598
|
+
|
1599
|
+
// ../core/lib/data/to-root.ts
|
1600
|
+
init_react_import();
|
1601
|
+
var toRoot = (item) => {
|
1602
|
+
if ("type" in item && item.type !== "root") {
|
1603
|
+
throw new Error("Converting non-root item to root.");
|
1604
|
+
}
|
1605
|
+
const { readOnly } = item;
|
1606
|
+
if (item.props) {
|
1607
|
+
if ("id" in item.props) {
|
1608
|
+
const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
|
1609
|
+
return { props, readOnly };
|
1610
|
+
}
|
1611
|
+
return { props: item.props, readOnly };
|
1612
|
+
}
|
1613
|
+
return { props: {}, readOnly };
|
1614
|
+
};
|
1615
|
+
|
1433
1616
|
// ../core/store/index.ts
|
1434
1617
|
var defaultAppState = {
|
1435
1618
|
data: { content: [], root: {}, zones: {} },
|
@@ -1450,100 +1633,194 @@ var defaultAppState = {
|
|
1450
1633
|
controlsVisible: true
|
1451
1634
|
},
|
1452
1635
|
field: { focus: null }
|
1636
|
+
},
|
1637
|
+
indexes: {
|
1638
|
+
nodes: {},
|
1639
|
+
zones: {}
|
1453
1640
|
}
|
1454
1641
|
};
|
1455
1642
|
var defaultPageFields = {
|
1456
1643
|
title: { type: "text" }
|
1457
1644
|
};
|
1458
1645
|
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
|
-
|
1646
|
+
subscribeWithSelector((set, get) => {
|
1647
|
+
var _a, _b;
|
1648
|
+
return __spreadProps(__spreadValues({
|
1649
|
+
state: defaultAppState,
|
1650
|
+
config: { components: {} },
|
1651
|
+
componentState: {},
|
1652
|
+
plugins: [],
|
1653
|
+
overrides: {},
|
1654
|
+
viewports: defaultViewports,
|
1655
|
+
zoomConfig: {
|
1656
|
+
autoZoom: 1,
|
1657
|
+
rootHeight: 0,
|
1658
|
+
zoom: 1
|
1659
|
+
},
|
1660
|
+
status: "LOADING",
|
1661
|
+
iframe: {},
|
1662
|
+
metadata: {}
|
1663
|
+
}, initialAppStore), {
|
1664
|
+
fields: createFieldsSlice(set, get),
|
1665
|
+
history: createHistorySlice(set, get),
|
1666
|
+
nodes: createNodesSlice(set, get),
|
1667
|
+
permissions: createPermissionsSlice(set, get),
|
1668
|
+
getComponentConfig: (type) => {
|
1669
|
+
var _a2;
|
1670
|
+
const { config, selectedItem } = get();
|
1671
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1672
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1673
|
+
},
|
1674
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1675
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1676
|
+
initialAppStore.state
|
1677
|
+
) : null,
|
1678
|
+
dispatch: (action) => set((s) => {
|
1679
|
+
var _a2, _b2;
|
1680
|
+
const { record } = get().history;
|
1681
|
+
const dispatch = createReducer({
|
1682
|
+
record,
|
1683
|
+
appStore: s
|
1684
|
+
});
|
1685
|
+
const state = dispatch(s.state, action);
|
1686
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1687
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1688
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1689
|
+
}),
|
1690
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1691
|
+
setStatus: (status) => set({ status }),
|
1692
|
+
setComponentState: (componentState) => set({ componentState }),
|
1693
|
+
pendingLoadTimeouts: {},
|
1694
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1695
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1696
|
+
const loadId = generateId();
|
1697
|
+
const setLoading = () => {
|
1698
|
+
var _a2;
|
1699
|
+
const { componentState } = get();
|
1700
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1701
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1702
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1703
|
+
})
|
1704
|
+
}));
|
1705
|
+
};
|
1706
|
+
const unsetLoading = () => {
|
1707
|
+
var _a2;
|
1708
|
+
const { componentState } = get();
|
1709
|
+
clearTimeout(timeout);
|
1710
|
+
delete pendingLoadTimeouts[loadId];
|
1711
|
+
set({ pendingLoadTimeouts });
|
1712
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1713
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1714
|
+
loadingCount: Math.max(
|
1715
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1716
|
+
0
|
1717
|
+
)
|
1718
|
+
})
|
1719
|
+
}));
|
1720
|
+
};
|
1721
|
+
const timeout = setTimeout(() => {
|
1722
|
+
if (loading) {
|
1723
|
+
setLoading();
|
1724
|
+
} else {
|
1725
|
+
unsetLoading();
|
1726
|
+
}
|
1727
|
+
delete pendingLoadTimeouts[loadId];
|
1728
|
+
set({ pendingLoadTimeouts });
|
1729
|
+
}, defer);
|
1730
|
+
set({
|
1731
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1732
|
+
[id]: timeout
|
1733
|
+
})
|
1734
|
+
});
|
1735
|
+
return unsetLoading;
|
1736
|
+
},
|
1737
|
+
unsetComponentLoading: (id) => {
|
1738
|
+
const { setComponentLoading } = get();
|
1739
|
+
setComponentLoading(id, false);
|
1740
|
+
},
|
1741
|
+
// Helper
|
1742
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1743
|
+
const dispatch = createReducer({
|
1744
|
+
record: () => {
|
1745
|
+
},
|
1746
|
+
appStore: s
|
1747
|
+
});
|
1748
|
+
const state = dispatch(s.state, {
|
1749
|
+
type: "setUi",
|
1750
|
+
ui,
|
1751
|
+
recordHistory
|
1752
|
+
});
|
1753
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1754
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1755
|
+
}),
|
1756
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1757
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
1758
|
+
const timeouts = {};
|
1759
|
+
return yield resolveComponentData(
|
1760
|
+
componentData,
|
1761
|
+
config,
|
1762
|
+
metadata,
|
1763
|
+
(item) => {
|
1764
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1765
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
1766
|
+
},
|
1767
|
+
(item) => __async(void 0, null, function* () {
|
1768
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1769
|
+
if ("type" in item) {
|
1770
|
+
yield permissions.refreshPermissions({ item });
|
1771
|
+
} else {
|
1772
|
+
yield permissions.refreshPermissions({ root: true });
|
1773
|
+
}
|
1774
|
+
timeouts[id]();
|
1775
|
+
}),
|
1776
|
+
trigger
|
1777
|
+
);
|
1778
|
+
}),
|
1779
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1780
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1781
|
+
walkTree(
|
1782
|
+
state,
|
1783
|
+
config,
|
1784
|
+
(content) => content,
|
1785
|
+
(childItem) => {
|
1786
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
1787
|
+
const { state: state2 } = get();
|
1788
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
1789
|
+
if (node && resolved.didChange) {
|
1790
|
+
if (resolved.node.props.id === "root") {
|
1791
|
+
dispatch({
|
1792
|
+
type: "replaceRoot",
|
1793
|
+
root: toRoot(resolved.node)
|
1794
|
+
});
|
1795
|
+
} else {
|
1796
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1797
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
1798
|
+
const index = parentZone.contentIds.indexOf(
|
1799
|
+
resolved.node.props.id
|
1800
|
+
);
|
1801
|
+
dispatch({
|
1802
|
+
type: "replace",
|
1803
|
+
data: resolved.node,
|
1804
|
+
destinationIndex: index,
|
1805
|
+
destinationZone: zoneCompound
|
1806
|
+
});
|
1807
|
+
}
|
1808
|
+
}
|
1809
|
+
});
|
1810
|
+
return childItem;
|
1811
|
+
}
|
1812
|
+
);
|
1813
|
+
})
|
1814
|
+
});
|
1815
|
+
})
|
1539
1816
|
);
|
1540
|
-
var appStoreContext = (0,
|
1817
|
+
var appStoreContext = (0, import_react9.createContext)(createAppStore());
|
1541
1818
|
function useAppStore(selector) {
|
1542
|
-
const context = (0,
|
1819
|
+
const context = (0, import_react9.useContext)(appStoreContext);
|
1543
1820
|
return useStore(context, selector);
|
1544
1821
|
}
|
1545
1822
|
function useAppStoreApi() {
|
1546
|
-
return (0,
|
1823
|
+
return (0, import_react9.useContext)(appStoreContext);
|
1547
1824
|
}
|
1548
1825
|
|
1549
1826
|
// ../core/lib/use-breadcrumbs.ts
|
@@ -1555,12 +1832,12 @@ var useBreadcrumbs = (renderCount) => {
|
|
1555
1832
|
const config = useAppStore((s) => s.config);
|
1556
1833
|
const path = useAppStore((s) => {
|
1557
1834
|
var _a;
|
1558
|
-
return (_a = s.
|
1835
|
+
return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
|
1559
1836
|
});
|
1560
1837
|
const appStore = useAppStoreApi();
|
1561
|
-
return (0,
|
1838
|
+
return (0, import_react10.useMemo)(() => {
|
1562
1839
|
const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
|
1563
|
-
var _a, _b;
|
1840
|
+
var _a, _b, _c;
|
1564
1841
|
const [componentId] = zoneCompound.split(":");
|
1565
1842
|
if (componentId === "root") {
|
1566
1843
|
return {
|
@@ -1568,12 +1845,15 @@ var useBreadcrumbs = (renderCount) => {
|
|
1568
1845
|
selector: null
|
1569
1846
|
};
|
1570
1847
|
}
|
1571
|
-
const node = appStore.getState().
|
1572
|
-
const
|
1848
|
+
const node = appStore.getState().state.indexes.nodes[componentId];
|
1849
|
+
const parentId = node.path[node.path.length - 1];
|
1850
|
+
const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
|
1851
|
+
const index = contentIds.indexOf(componentId);
|
1852
|
+
const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
|
1573
1853
|
return {
|
1574
1854
|
label,
|
1575
1855
|
selector: node ? {
|
1576
|
-
index
|
1856
|
+
index,
|
1577
1857
|
zone: node.path[node.path.length - 1]
|
1578
1858
|
} : null
|
1579
1859
|
};
|
@@ -1594,6 +1874,12 @@ init_react_import();
|
|
1594
1874
|
// ../core/lib/filter.ts
|
1595
1875
|
init_react_import();
|
1596
1876
|
|
1877
|
+
// ../core/lib/data/reorder.ts
|
1878
|
+
init_react_import();
|
1879
|
+
|
1880
|
+
// ../core/lib/data/replace.ts
|
1881
|
+
init_react_import();
|
1882
|
+
|
1597
1883
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
1598
1884
|
init_react_import();
|
1599
1885
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
@@ -1774,18 +2060,40 @@ function buildHierarchy(frame) {
|
|
1774
2060
|
var usePuck = (0, import_puck.createUsePuck)();
|
1775
2061
|
var HeadingAnalyzer = () => {
|
1776
2062
|
const data = usePuck((s) => s.appState.data);
|
1777
|
-
const [hierarchy, setHierarchy] = (0,
|
1778
|
-
(0,
|
2063
|
+
const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
|
2064
|
+
(0, import_react11.useEffect)(() => {
|
1779
2065
|
const frame = getFrame();
|
1780
|
-
|
1781
|
-
|
1782
|
-
setHierarchy(buildHierarchy(entry));
|
1783
|
-
const observer = new MutationObserver(() => {
|
2066
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2067
|
+
const createHierarchy = () => {
|
1784
2068
|
setHierarchy(buildHierarchy(entry));
|
2069
|
+
};
|
2070
|
+
const entryObserver = new MutationObserver(() => {
|
2071
|
+
createHierarchy();
|
2072
|
+
});
|
2073
|
+
const frameObserver = new MutationObserver(() => {
|
2074
|
+
entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2075
|
+
if (entry) {
|
2076
|
+
registerEntryObserver();
|
2077
|
+
frameObserver.disconnect();
|
2078
|
+
}
|
1785
2079
|
});
|
1786
|
-
|
2080
|
+
const registerEntryObserver = () => {
|
2081
|
+
if (!entry) return;
|
2082
|
+
entryObserver.observe(entry, { subtree: true, childList: true });
|
2083
|
+
};
|
2084
|
+
const registerFrameObserver = () => {
|
2085
|
+
if (!frame) return;
|
2086
|
+
frameObserver.observe(frame, { subtree: true, childList: true });
|
2087
|
+
};
|
2088
|
+
if (entry) {
|
2089
|
+
createHierarchy();
|
2090
|
+
registerEntryObserver();
|
2091
|
+
} else {
|
2092
|
+
registerFrameObserver();
|
2093
|
+
}
|
1787
2094
|
return () => {
|
1788
|
-
|
2095
|
+
entryObserver.disconnect();
|
2096
|
+
frameObserver.disconnect();
|
1789
2097
|
};
|
1790
2098
|
}, [data]);
|
1791
2099
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
|