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