@measured/puck-plugin-heading-analyzer 0.19.0-canary.1fc19b5 → 0.19.0-canary.22f5e3a3
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 +1052 -674
- package/dist/index.mjs +1045 -667
- 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
|
+
};
|
518
747
|
}
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
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
|
+
);
|
526
790
|
}
|
527
|
-
return
|
791
|
+
return content;
|
528
792
|
},
|
529
|
-
{
|
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
|
+
}
|
530
803
|
);
|
531
|
-
}
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
804
|
+
}
|
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;
|
541
826
|
}
|
542
|
-
return
|
827
|
+
return newContent;
|
543
828
|
},
|
544
|
-
{
|
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
|
+
}
|
545
842
|
);
|
546
843
|
};
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
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
|
857
|
+
});
|
858
|
+
}
|
859
|
+
return childItem;
|
860
|
+
}
|
861
|
+
);
|
554
862
|
};
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
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);
|
1166
|
+
}
|
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);
|
838
1187
|
}
|
839
|
-
|
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,14 @@ 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
1411
|
methods: { sync: () => null },
|
1263
|
-
|
1264
|
-
parentId: "",
|
1265
|
-
zone: "",
|
1266
|
-
path: [],
|
1267
|
-
element: null,
|
1268
|
-
index: -1
|
1412
|
+
element: null
|
1269
1413
|
};
|
1270
1414
|
const existingNode = s.nodes[id];
|
1271
1415
|
set({
|
@@ -1295,36 +1439,61 @@ var createNodesSlice = (set, get) => ({
|
|
1295
1439
|
|
1296
1440
|
// ../core/store/slices/permissions.ts
|
1297
1441
|
init_react_import();
|
1298
|
-
import { useEffect as
|
1442
|
+
import { useEffect as useEffect3 } from "react";
|
1443
|
+
|
1444
|
+
// ../core/lib/data/flatten-data.ts
|
1445
|
+
init_react_import();
|
1446
|
+
var flattenData = (state, config) => {
|
1447
|
+
const data = [];
|
1448
|
+
walkAppState(
|
1449
|
+
state,
|
1450
|
+
config,
|
1451
|
+
(content) => content,
|
1452
|
+
(item) => {
|
1453
|
+
data.push(item);
|
1454
|
+
return null;
|
1455
|
+
}
|
1456
|
+
);
|
1457
|
+
return data;
|
1458
|
+
};
|
1459
|
+
|
1460
|
+
// ../core/lib/get-changed.ts
|
1461
|
+
init_react_import();
|
1462
|
+
var getChanged = (newItem, oldItem) => {
|
1463
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1464
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1465
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1466
|
+
return __spreadProps(__spreadValues({}, acc), {
|
1467
|
+
[item]: oldItemProps[item] !== newItemProps[item]
|
1468
|
+
});
|
1469
|
+
}, {}) : {};
|
1470
|
+
};
|
1471
|
+
|
1472
|
+
// ../core/store/slices/permissions.ts
|
1299
1473
|
var createPermissionsSlice = (set, get) => {
|
1300
1474
|
const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
|
1301
|
-
const { state, permissions } = get();
|
1302
|
-
const { cache:
|
1475
|
+
const { state, permissions, config } = get();
|
1476
|
+
const { cache: cache2, globalPermissions } = permissions;
|
1303
1477
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1304
1478
|
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];
|
1479
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1480
|
+
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1312
1481
|
if (!componentConfig) {
|
1313
1482
|
return;
|
1314
1483
|
}
|
1315
1484
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
1316
1485
|
if (componentConfig.resolvePermissions) {
|
1317
|
-
const changed = getChanged(item2, (_a =
|
1486
|
+
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1318
1487
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1319
|
-
setComponentLoading(item2.props.id);
|
1488
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1320
1489
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1321
1490
|
item2,
|
1322
1491
|
{
|
1323
1492
|
changed,
|
1324
|
-
lastPermissions: ((_b =
|
1493
|
+
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1325
1494
|
permissions: initialPermissions,
|
1326
|
-
appState,
|
1327
|
-
lastData: ((_c =
|
1495
|
+
appState: makeStatePublic(appState),
|
1496
|
+
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1328
1497
|
}
|
1329
1498
|
);
|
1330
1499
|
const latest = get().permissions;
|
@@ -1341,7 +1510,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1341
1510
|
})
|
1342
1511
|
})
|
1343
1512
|
});
|
1344
|
-
|
1513
|
+
clearTimeout2();
|
1345
1514
|
}
|
1346
1515
|
}
|
1347
1516
|
});
|
@@ -1351,7 +1520,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1351
1520
|
// Shim the root data in by conforming to component data shape
|
1352
1521
|
{
|
1353
1522
|
type: "root",
|
1354
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1523
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1355
1524
|
},
|
1356
1525
|
force2
|
1357
1526
|
);
|
@@ -1360,14 +1529,13 @@ var createPermissionsSlice = (set, get) => {
|
|
1360
1529
|
if (item) {
|
1361
1530
|
yield resolveDataForItem(item, force);
|
1362
1531
|
} else if (type) {
|
1363
|
-
flattenData(state
|
1532
|
+
flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
1364
1533
|
yield resolveDataForItem(item2, force);
|
1365
1534
|
}));
|
1366
1535
|
} else if (root) {
|
1367
1536
|
resolveDataForRoot(force);
|
1368
1537
|
} else {
|
1369
|
-
|
1370
|
-
flattenData(state.data).map((item2) => __async(void 0, null, function* () {
|
1538
|
+
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1371
1539
|
yield resolveDataForItem(item2, force);
|
1372
1540
|
}));
|
1373
1541
|
}
|
@@ -1397,7 +1565,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1397
1565
|
} else if (root) {
|
1398
1566
|
const rootConfig = config.root;
|
1399
1567
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1400
|
-
const resolvedForItem = resolvedPermissions["
|
1568
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1401
1569
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1402
1570
|
}
|
1403
1571
|
return globalPermissions;
|
@@ -1409,16 +1577,99 @@ var createPermissionsSlice = (set, get) => {
|
|
1409
1577
|
|
1410
1578
|
// ../core/store/slices/fields.ts
|
1411
1579
|
init_react_import();
|
1412
|
-
import { useCallback, useEffect as
|
1413
|
-
var
|
1580
|
+
import { useCallback, useEffect as useEffect4 } from "react";
|
1581
|
+
var createFieldsSlice = (_set, _get) => {
|
1414
1582
|
return {
|
1415
1583
|
fields: {},
|
1416
1584
|
loading: false,
|
1417
|
-
lastResolvedData: {}
|
1585
|
+
lastResolvedData: {},
|
1586
|
+
id: void 0
|
1418
1587
|
};
|
1419
1588
|
};
|
1420
1589
|
|
1421
|
-
// ../core/
|
1590
|
+
// ../core/lib/resolve-component-data.ts
|
1591
|
+
init_react_import();
|
1592
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1593
|
+
var cache = { lastChange: {} };
|
1594
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
1595
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1596
|
+
if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
|
1597
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1598
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1599
|
+
if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
|
1600
|
+
return { node: resolved, didChange: false };
|
1601
|
+
}
|
1602
|
+
const changed = getChanged(item, oldItem);
|
1603
|
+
if (onResolveStart) {
|
1604
|
+
onResolveStart(item);
|
1605
|
+
}
|
1606
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1607
|
+
changed,
|
1608
|
+
lastData: oldItem,
|
1609
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1610
|
+
trigger
|
1611
|
+
});
|
1612
|
+
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1613
|
+
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1614
|
+
});
|
1615
|
+
if (recursive) {
|
1616
|
+
resolvedItem = yield mapSlotsAsync(
|
1617
|
+
resolvedItem,
|
1618
|
+
(content) => __async(void 0, null, function* () {
|
1619
|
+
return Promise.all(
|
1620
|
+
content.map(
|
1621
|
+
(childItem) => __async(void 0, null, function* () {
|
1622
|
+
return (yield resolveComponentData(
|
1623
|
+
childItem,
|
1624
|
+
config,
|
1625
|
+
metadata,
|
1626
|
+
onResolveStart,
|
1627
|
+
onResolveEnd,
|
1628
|
+
trigger,
|
1629
|
+
false
|
1630
|
+
)).node;
|
1631
|
+
})
|
1632
|
+
)
|
1633
|
+
);
|
1634
|
+
}),
|
1635
|
+
false,
|
1636
|
+
createIsSlotConfig(config)
|
1637
|
+
);
|
1638
|
+
}
|
1639
|
+
if (Object.keys(readOnly).length) {
|
1640
|
+
resolvedItem.readOnly = readOnly;
|
1641
|
+
}
|
1642
|
+
cache.lastChange[id] = {
|
1643
|
+
item,
|
1644
|
+
resolved: resolvedItem
|
1645
|
+
};
|
1646
|
+
if (onResolveEnd) {
|
1647
|
+
onResolveEnd(resolvedItem);
|
1648
|
+
}
|
1649
|
+
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1650
|
+
}
|
1651
|
+
return { node: item, didChange: false };
|
1652
|
+
});
|
1653
|
+
|
1654
|
+
// ../core/lib/data/to-root.ts
|
1655
|
+
init_react_import();
|
1656
|
+
var toRoot = (item) => {
|
1657
|
+
if ("type" in item && item.type !== "root") {
|
1658
|
+
throw new Error("Converting non-root item to root.");
|
1659
|
+
}
|
1660
|
+
const { readOnly } = item;
|
1661
|
+
if (item.props) {
|
1662
|
+
if ("id" in item.props) {
|
1663
|
+
const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
|
1664
|
+
return { props, readOnly };
|
1665
|
+
}
|
1666
|
+
return { props: item.props, readOnly };
|
1667
|
+
}
|
1668
|
+
return { props: {}, readOnly };
|
1669
|
+
};
|
1670
|
+
|
1671
|
+
// ../core/store/default-app-state.ts
|
1672
|
+
init_react_import();
|
1422
1673
|
var defaultAppState = {
|
1423
1674
|
data: { content: [], root: {}, zones: {} },
|
1424
1675
|
ui: {
|
@@ -1438,92 +1689,188 @@ var defaultAppState = {
|
|
1438
1689
|
controlsVisible: true
|
1439
1690
|
},
|
1440
1691
|
field: { focus: null }
|
1692
|
+
},
|
1693
|
+
indexes: {
|
1694
|
+
nodes: {},
|
1695
|
+
zones: {}
|
1441
1696
|
}
|
1442
1697
|
};
|
1698
|
+
|
1699
|
+
// ../core/store/index.ts
|
1443
1700
|
var defaultPageFields = {
|
1444
1701
|
title: { type: "text" }
|
1445
1702
|
};
|
1446
1703
|
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
|
-
|
1704
|
+
subscribeWithSelector((set, get) => {
|
1705
|
+
var _a, _b;
|
1706
|
+
return __spreadProps(__spreadValues({
|
1707
|
+
state: defaultAppState,
|
1708
|
+
config: { components: {} },
|
1709
|
+
componentState: {},
|
1710
|
+
plugins: [],
|
1711
|
+
overrides: {},
|
1712
|
+
viewports: defaultViewports,
|
1713
|
+
zoomConfig: {
|
1714
|
+
autoZoom: 1,
|
1715
|
+
rootHeight: 0,
|
1716
|
+
zoom: 1
|
1717
|
+
},
|
1718
|
+
status: "LOADING",
|
1719
|
+
iframe: {},
|
1720
|
+
metadata: {}
|
1721
|
+
}, initialAppStore), {
|
1722
|
+
fields: createFieldsSlice(set, get),
|
1723
|
+
history: createHistorySlice(set, get),
|
1724
|
+
nodes: createNodesSlice(set, get),
|
1725
|
+
permissions: createPermissionsSlice(set, get),
|
1726
|
+
getComponentConfig: (type) => {
|
1727
|
+
var _a2;
|
1728
|
+
const { config, selectedItem } = get();
|
1729
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1730
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1731
|
+
},
|
1732
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1733
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1734
|
+
initialAppStore.state
|
1735
|
+
) : null,
|
1736
|
+
dispatch: (action) => set((s) => {
|
1737
|
+
var _a2, _b2;
|
1738
|
+
const { record } = get().history;
|
1739
|
+
const dispatch = createReducer({
|
1740
|
+
record,
|
1741
|
+
appStore: s
|
1742
|
+
});
|
1743
|
+
const state = dispatch(s.state, action);
|
1744
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1745
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1746
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1747
|
+
}),
|
1748
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1749
|
+
setStatus: (status) => set({ status }),
|
1750
|
+
setComponentState: (componentState) => set({ componentState }),
|
1751
|
+
pendingLoadTimeouts: {},
|
1752
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1753
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1754
|
+
const loadId = generateId();
|
1755
|
+
const setLoading = () => {
|
1756
|
+
var _a2;
|
1757
|
+
const { componentState } = get();
|
1758
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1759
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1760
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1761
|
+
})
|
1762
|
+
}));
|
1763
|
+
};
|
1764
|
+
const unsetLoading = () => {
|
1765
|
+
var _a2;
|
1766
|
+
const { componentState } = get();
|
1767
|
+
clearTimeout(timeout);
|
1768
|
+
delete pendingLoadTimeouts[loadId];
|
1769
|
+
set({ pendingLoadTimeouts });
|
1770
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1771
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1772
|
+
loadingCount: Math.max(
|
1773
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1774
|
+
0
|
1775
|
+
)
|
1776
|
+
})
|
1777
|
+
}));
|
1778
|
+
};
|
1779
|
+
const timeout = setTimeout(() => {
|
1780
|
+
if (loading) {
|
1781
|
+
setLoading();
|
1782
|
+
} else {
|
1783
|
+
unsetLoading();
|
1784
|
+
}
|
1785
|
+
delete pendingLoadTimeouts[loadId];
|
1786
|
+
set({ pendingLoadTimeouts });
|
1787
|
+
}, defer);
|
1788
|
+
set({
|
1789
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1790
|
+
[id]: timeout
|
1791
|
+
})
|
1792
|
+
});
|
1793
|
+
return unsetLoading;
|
1794
|
+
},
|
1795
|
+
unsetComponentLoading: (id) => {
|
1796
|
+
const { setComponentLoading } = get();
|
1797
|
+
setComponentLoading(id, false);
|
1798
|
+
},
|
1799
|
+
// Helper
|
1800
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1801
|
+
const dispatch = createReducer({
|
1802
|
+
record: () => {
|
1803
|
+
},
|
1804
|
+
appStore: s
|
1805
|
+
});
|
1806
|
+
const state = dispatch(s.state, {
|
1807
|
+
type: "setUi",
|
1808
|
+
ui,
|
1809
|
+
recordHistory
|
1810
|
+
});
|
1811
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1812
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1813
|
+
}),
|
1814
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1815
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
1816
|
+
const timeouts = {};
|
1817
|
+
return yield resolveComponentData(
|
1818
|
+
componentData,
|
1819
|
+
config,
|
1820
|
+
metadata,
|
1821
|
+
(item) => {
|
1822
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1823
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
1824
|
+
},
|
1825
|
+
(item) => __async(void 0, null, function* () {
|
1826
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1827
|
+
if ("type" in item) {
|
1828
|
+
yield permissions.refreshPermissions({ item });
|
1829
|
+
} else {
|
1830
|
+
yield permissions.refreshPermissions({ root: true });
|
1831
|
+
}
|
1832
|
+
timeouts[id]();
|
1833
|
+
}),
|
1834
|
+
trigger
|
1835
|
+
);
|
1836
|
+
}),
|
1837
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1838
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1839
|
+
walkAppState(
|
1840
|
+
state,
|
1841
|
+
config,
|
1842
|
+
(content) => content,
|
1843
|
+
(childItem) => {
|
1844
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
1845
|
+
const { state: state2 } = get();
|
1846
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
1847
|
+
if (node && resolved.didChange) {
|
1848
|
+
if (resolved.node.props.id === "root") {
|
1849
|
+
dispatch({
|
1850
|
+
type: "replaceRoot",
|
1851
|
+
root: toRoot(resolved.node)
|
1852
|
+
});
|
1853
|
+
} else {
|
1854
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1855
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
1856
|
+
const index = parentZone.contentIds.indexOf(
|
1857
|
+
resolved.node.props.id
|
1858
|
+
);
|
1859
|
+
dispatch({
|
1860
|
+
type: "replace",
|
1861
|
+
data: resolved.node,
|
1862
|
+
destinationIndex: index,
|
1863
|
+
destinationZone: zoneCompound
|
1864
|
+
});
|
1865
|
+
}
|
1866
|
+
}
|
1867
|
+
});
|
1868
|
+
return childItem;
|
1869
|
+
}
|
1870
|
+
);
|
1871
|
+
})
|
1872
|
+
});
|
1873
|
+
})
|
1527
1874
|
);
|
1528
1875
|
var appStoreContext = createContext(createAppStore());
|
1529
1876
|
function useAppStore(selector) {
|
@@ -1543,12 +1890,12 @@ var useBreadcrumbs = (renderCount) => {
|
|
1543
1890
|
const config = useAppStore((s) => s.config);
|
1544
1891
|
const path = useAppStore((s) => {
|
1545
1892
|
var _a;
|
1546
|
-
return (_a = s.
|
1893
|
+
return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
|
1547
1894
|
});
|
1548
1895
|
const appStore = useAppStoreApi();
|
1549
1896
|
return useMemo(() => {
|
1550
1897
|
const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
|
1551
|
-
var _a, _b;
|
1898
|
+
var _a, _b, _c;
|
1552
1899
|
const [componentId] = zoneCompound.split(":");
|
1553
1900
|
if (componentId === "root") {
|
1554
1901
|
return {
|
@@ -1556,12 +1903,15 @@ var useBreadcrumbs = (renderCount) => {
|
|
1556
1903
|
selector: null
|
1557
1904
|
};
|
1558
1905
|
}
|
1559
|
-
const node = appStore.getState().
|
1560
|
-
const
|
1906
|
+
const node = appStore.getState().state.indexes.nodes[componentId];
|
1907
|
+
const parentId = node.path[node.path.length - 1];
|
1908
|
+
const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
|
1909
|
+
const index = contentIds.indexOf(componentId);
|
1910
|
+
const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
|
1561
1911
|
return {
|
1562
1912
|
label,
|
1563
1913
|
selector: node ? {
|
1564
|
-
index
|
1914
|
+
index,
|
1565
1915
|
zone: node.path[node.path.length - 1]
|
1566
1916
|
} : null
|
1567
1917
|
};
|
@@ -1582,6 +1932,12 @@ init_react_import();
|
|
1582
1932
|
// ../core/lib/filter.ts
|
1583
1933
|
init_react_import();
|
1584
1934
|
|
1935
|
+
// ../core/lib/data/reorder.ts
|
1936
|
+
init_react_import();
|
1937
|
+
|
1938
|
+
// ../core/lib/data/replace.ts
|
1939
|
+
init_react_import();
|
1940
|
+
|
1585
1941
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
1586
1942
|
init_react_import();
|
1587
1943
|
var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
|
@@ -1763,17 +2119,39 @@ var usePuck = createUsePuck();
|
|
1763
2119
|
var HeadingAnalyzer = () => {
|
1764
2120
|
const data = usePuck((s) => s.appState.data);
|
1765
2121
|
const [hierarchy, setHierarchy] = useState([]);
|
1766
|
-
|
2122
|
+
useEffect5(() => {
|
1767
2123
|
const frame = getFrame();
|
1768
|
-
|
1769
|
-
|
1770
|
-
setHierarchy(buildHierarchy(entry));
|
1771
|
-
const observer = new MutationObserver(() => {
|
2124
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2125
|
+
const createHierarchy = () => {
|
1772
2126
|
setHierarchy(buildHierarchy(entry));
|
2127
|
+
};
|
2128
|
+
const entryObserver = new MutationObserver(() => {
|
2129
|
+
createHierarchy();
|
2130
|
+
});
|
2131
|
+
const frameObserver = new MutationObserver(() => {
|
2132
|
+
entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2133
|
+
if (entry) {
|
2134
|
+
registerEntryObserver();
|
2135
|
+
frameObserver.disconnect();
|
2136
|
+
}
|
1773
2137
|
});
|
1774
|
-
|
2138
|
+
const registerEntryObserver = () => {
|
2139
|
+
if (!entry) return;
|
2140
|
+
entryObserver.observe(entry, { subtree: true, childList: true });
|
2141
|
+
};
|
2142
|
+
const registerFrameObserver = () => {
|
2143
|
+
if (!frame) return;
|
2144
|
+
frameObserver.observe(frame, { subtree: true, childList: true });
|
2145
|
+
};
|
2146
|
+
if (entry) {
|
2147
|
+
createHierarchy();
|
2148
|
+
registerEntryObserver();
|
2149
|
+
} else {
|
2150
|
+
registerFrameObserver();
|
2151
|
+
}
|
1775
2152
|
return () => {
|
1776
|
-
|
2153
|
+
entryObserver.disconnect();
|
2154
|
+
frameObserver.disconnect();
|
1777
2155
|
};
|
1778
2156
|
}, [data]);
|
1779
2157
|
return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [
|