@measured/puck 0.19.0-canary.d9be813b → 0.19.0-canary.e52d3b85
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 -0
- package/dist/{chunk-SYX4T2Z2.mjs → chunk-ZOHJNF5K.mjs} +899 -746
- package/dist/index.css +44 -38
- package/dist/index.d.mts +18 -8
- package/dist/index.d.ts +18 -8
- package/dist/index.js +997 -795
- package/dist/index.mjs +131 -77
- package/dist/{resolve-all-data-Cs8PfTrg.d.mts → resolve-all-data-BFRAghCj.d.mts} +5 -1
- package/dist/{resolve-all-data-Cs8PfTrg.d.ts → resolve-all-data-BFRAghCj.d.ts} +5 -1
- package/dist/rsc.css +12 -11
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +804 -672
- package/dist/rsc.mjs +1 -1
- package/package.json +1 -1
package/dist/rsc.js
CHANGED
@@ -179,7 +179,7 @@ var rootAreaId = "root";
|
|
179
179
|
var rootZone = "default-zone";
|
180
180
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
181
181
|
|
182
|
-
// lib/setup-zone.ts
|
182
|
+
// lib/data/setup-zone.ts
|
183
183
|
init_react_import();
|
184
184
|
var setupZone = (data, zoneKey) => {
|
185
185
|
if (zoneKey === rootDroppableId) {
|
@@ -192,26 +192,33 @@ var setupZone = (data, zoneKey) => {
|
|
192
192
|
return newData;
|
193
193
|
};
|
194
194
|
|
195
|
-
// lib/use-slots.
|
195
|
+
// lib/use-slots.tsx
|
196
196
|
init_react_import();
|
197
197
|
var import_react2 = require("react");
|
198
|
-
function useSlots(config, props,
|
199
|
-
|
198
|
+
function useSlots(config, props, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
199
|
+
const slotProps = (0, import_react2.useMemo)(() => {
|
200
200
|
if (!(config == null ? void 0 : config.fields)) return props;
|
201
|
-
const
|
201
|
+
const slotProps2 = {};
|
202
202
|
const fieldKeys = Object.keys(config.fields);
|
203
203
|
for (let i = 0; i < fieldKeys.length; i++) {
|
204
204
|
const fieldKey = fieldKeys[i];
|
205
205
|
const field = config.fields[fieldKey];
|
206
206
|
if ((field == null ? void 0 : field.type) === "slot") {
|
207
|
-
|
207
|
+
const content = props[fieldKey] || [];
|
208
|
+
const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
|
209
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
210
|
+
allow: field.allow,
|
211
|
+
disallow: field.disallow
|
212
|
+
}, dzProps), {
|
208
213
|
zone: fieldKey,
|
209
|
-
content
|
214
|
+
content
|
210
215
|
}));
|
216
|
+
slotProps2[fieldKey] = Slot;
|
211
217
|
}
|
212
218
|
}
|
213
|
-
return
|
214
|
-
}, [config,
|
219
|
+
return slotProps2;
|
220
|
+
}, [config, readOnly, forceReadOnly]);
|
221
|
+
return __spreadValues(__spreadValues({}, props), slotProps);
|
215
222
|
}
|
216
223
|
|
217
224
|
// components/SlotRender/index.tsx
|
@@ -228,7 +235,7 @@ var import_react13 = require("react");
|
|
228
235
|
|
229
236
|
// css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
|
230
237
|
init_react_import();
|
231
|
-
var styles_module_default = { "DraggableComponent": "
|
238
|
+
var styles_module_default = { "DraggableComponent": "_DraggableComponent_qzbgx_1", "DraggableComponent-overlay": "_DraggableComponent-overlay_qzbgx_12", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_qzbgx_29", "DraggableComponent--hover": "_DraggableComponent--hover_qzbgx_45", "DraggableComponent--isLocked": "_DraggableComponent--isLocked_qzbgx_45", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_qzbgx_54", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_qzbgx_66", "DraggableComponent-actions": "_DraggableComponent-actions_qzbgx_66" };
|
232
239
|
|
233
240
|
// lib/get-class-name-factory.ts
|
234
241
|
init_react_import();
|
@@ -372,62 +379,30 @@ init_react_import();
|
|
372
379
|
// reducer/index.ts
|
373
380
|
init_react_import();
|
374
381
|
|
375
|
-
// reducer/
|
382
|
+
// reducer/actions/set.ts
|
376
383
|
init_react_import();
|
377
384
|
|
378
|
-
// lib/
|
379
|
-
init_react_import();
|
380
|
-
var reorder = (list, startIndex, endIndex) => {
|
381
|
-
const result = Array.from(list);
|
382
|
-
const [removed] = result.splice(startIndex, 1);
|
383
|
-
result.splice(endIndex, 0, removed);
|
384
|
-
return result;
|
385
|
-
};
|
386
|
-
|
387
|
-
// lib/insert.ts
|
388
|
-
init_react_import();
|
389
|
-
var insert = (list, index, item) => {
|
390
|
-
const result = Array.from(list || []);
|
391
|
-
result.splice(index, 0, item);
|
392
|
-
return result;
|
393
|
-
};
|
394
|
-
|
395
|
-
// lib/remove.ts
|
396
|
-
init_react_import();
|
397
|
-
var remove = (list, index) => {
|
398
|
-
const result = Array.from(list);
|
399
|
-
result.splice(index, 1);
|
400
|
-
return result;
|
401
|
-
};
|
402
|
-
|
403
|
-
// lib/get-item.ts
|
404
|
-
init_react_import();
|
405
|
-
function getItem(selector, state) {
|
406
|
-
var _a, _b;
|
407
|
-
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
408
|
-
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
409
|
-
}
|
410
|
-
|
411
|
-
// lib/generate-id.ts
|
412
|
-
init_react_import();
|
413
|
-
var import_uuid = require("uuid");
|
414
|
-
var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
|
415
|
-
|
416
|
-
// lib/walk-tree.ts
|
385
|
+
// lib/data/walk-tree.ts
|
417
386
|
init_react_import();
|
418
387
|
|
419
|
-
// lib/for-each-slot.ts
|
388
|
+
// lib/data/for-each-slot.ts
|
420
389
|
init_react_import();
|
421
390
|
|
422
|
-
// lib/is-slot.ts
|
391
|
+
// lib/data/is-slot.ts
|
423
392
|
init_react_import();
|
424
393
|
var isSlot = (prop) => {
|
425
394
|
var _a, _b;
|
426
395
|
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
427
396
|
};
|
397
|
+
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
398
|
+
var _a, _b;
|
399
|
+
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
400
|
+
if (!configForComponent) return isSlot(propValue);
|
401
|
+
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
402
|
+
};
|
428
403
|
|
429
|
-
// lib/for-each-slot.ts
|
430
|
-
var forEachSlot = (
|
404
|
+
// lib/data/for-each-slot.ts
|
405
|
+
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
431
406
|
const props = item.props || {};
|
432
407
|
const propKeys = Object.keys(props);
|
433
408
|
for (let i = 0; i < propKeys.length; i++) {
|
@@ -435,19 +410,19 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
|
|
435
410
|
const itemType = "type" in item ? item.type : "root";
|
436
411
|
if (isSlot2(itemType, propKey, props[propKey])) {
|
437
412
|
const content = props[propKey];
|
438
|
-
|
413
|
+
cb(props.id, propKey, content);
|
439
414
|
if (recursive) {
|
440
415
|
content.forEach(
|
441
416
|
(childItem) => __async(void 0, null, function* () {
|
442
|
-
return
|
417
|
+
return forEachSlot(childItem, cb, true, isSlot2);
|
443
418
|
})
|
444
419
|
);
|
445
420
|
}
|
446
421
|
}
|
447
422
|
}
|
448
|
-
}
|
423
|
+
};
|
449
424
|
|
450
|
-
// lib/for-related-zones.ts
|
425
|
+
// lib/data/for-related-zones.ts
|
451
426
|
init_react_import();
|
452
427
|
|
453
428
|
// lib/get-zone-id.ts
|
@@ -462,19 +437,17 @@ var getZoneId = (zoneCompound) => {
|
|
462
437
|
return [rootDroppableId, zoneCompound];
|
463
438
|
};
|
464
439
|
|
465
|
-
// lib/for-related-zones.ts
|
440
|
+
// lib/data/for-related-zones.ts
|
466
441
|
function forRelatedZones(item, data, cb, path = []) {
|
467
442
|
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
468
443
|
const [parentId] = getZoneId(zoneCompound);
|
469
444
|
if (parentId === item.props.id) {
|
470
|
-
const newPath = [...path, zoneCompound];
|
471
|
-
content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
|
472
445
|
cb(path, zoneCompound, content);
|
473
446
|
}
|
474
447
|
});
|
475
448
|
}
|
476
449
|
|
477
|
-
// lib/strip-slots.ts
|
450
|
+
// lib/data/strip-slots.ts
|
478
451
|
init_react_import();
|
479
452
|
var stripSlots = (data) => {
|
480
453
|
return __spreadProps(__spreadValues({}, data), {
|
@@ -490,7 +463,7 @@ var stripSlots = (data) => {
|
|
490
463
|
});
|
491
464
|
};
|
492
465
|
|
493
|
-
// lib/walk-tree.ts
|
466
|
+
// lib/data/walk-tree.ts
|
494
467
|
function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
495
468
|
var _a;
|
496
469
|
let newZones = {};
|
@@ -532,7 +505,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
532
505
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
533
506
|
if (!mappedItem) return item;
|
534
507
|
const id = mappedItem.props.id;
|
535
|
-
processRelatedZones(item, id, path);
|
536
508
|
const newProps = __spreadValues({}, mappedItem.props);
|
537
509
|
forEachSlot(
|
538
510
|
mappedItem,
|
@@ -548,13 +520,9 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
548
520
|
newProps[slotId] = newContent2;
|
549
521
|
},
|
550
522
|
false,
|
551
|
-
(
|
552
|
-
var _a2, _b;
|
553
|
-
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
554
|
-
if (!configForComponent) return isSlot(propValue);
|
555
|
-
return ((_b = (_a2 = configForComponent.fields) == null ? void 0 : _a2[propName]) == null ? void 0 : _b.type) === "slot";
|
556
|
-
}
|
523
|
+
createIsSlotConfig(config)
|
557
524
|
);
|
525
|
+
processRelatedZones(item, id, path);
|
558
526
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
559
527
|
const thisZoneCompound = path[path.length - 1];
|
560
528
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
@@ -565,7 +533,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
565
533
|
parentId,
|
566
534
|
zone
|
567
535
|
};
|
568
|
-
const finalData = newItem;
|
536
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
569
537
|
if (newProps.id === "root") {
|
570
538
|
delete finalData["type"];
|
571
539
|
delete finalData.props["id"];
|
@@ -580,8 +548,12 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
580
548
|
"root"
|
581
549
|
);
|
582
550
|
const processedContent = newContent;
|
551
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
583
552
|
Object.keys(zones || {}).forEach((zoneCompound) => {
|
584
553
|
const [parentId] = zoneCompound.split(":");
|
554
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
555
|
+
return;
|
556
|
+
}
|
585
557
|
const [_2, newContent2] = processContent(
|
586
558
|
[rootDroppableId],
|
587
559
|
zoneCompound,
|
@@ -605,7 +577,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
605
577
|
return __spreadProps(__spreadValues({}, state), {
|
606
578
|
data: {
|
607
579
|
root,
|
608
|
-
// root: state.data.root, // TODO changing root causes it's entire subtree to re-render. Let's keep this disabled until the performance issues are resolved in #644.
|
609
580
|
content: processedContent,
|
610
581
|
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
611
582
|
},
|
@@ -616,59 +587,59 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
616
587
|
});
|
617
588
|
}
|
618
589
|
|
619
|
-
//
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
delete nodes[subItem.props.id];
|
629
|
-
});
|
630
|
-
delete zones[zoneCompound];
|
631
|
-
});
|
632
|
-
};
|
633
|
-
const dindexChildren = (item) => {
|
634
|
-
forEachSlot(
|
635
|
-
item,
|
636
|
-
(parentId, slotId, content) => {
|
637
|
-
const zoneCompound = `${parentId}:${slotId}`;
|
638
|
-
delete zones[zoneCompound];
|
639
|
-
content.forEach((item2) => {
|
640
|
-
dindexRelatedZones(item2);
|
641
|
-
delete nodes[item2.props.id];
|
642
|
-
});
|
643
|
-
},
|
644
|
-
true
|
590
|
+
// reducer/actions/set.ts
|
591
|
+
var setAction = (state, action, appStore) => {
|
592
|
+
if (typeof action.state === "object") {
|
593
|
+
const newState = __spreadValues(__spreadValues({}, state), action.state);
|
594
|
+
if (action.state.indexes) {
|
595
|
+
return newState;
|
596
|
+
}
|
597
|
+
console.warn(
|
598
|
+
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
645
599
|
);
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
delete nodes[componentData.props.id];
|
650
|
-
return { nodes, zones };
|
600
|
+
return walkTree(newState, appStore.config);
|
601
|
+
}
|
602
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
651
603
|
};
|
652
604
|
|
653
|
-
// reducer/
|
654
|
-
|
605
|
+
// reducer/actions/insert.ts
|
606
|
+
init_react_import();
|
607
|
+
|
608
|
+
// lib/data/insert.ts
|
609
|
+
init_react_import();
|
610
|
+
var insert = (list, index, item) => {
|
611
|
+
const result = Array.from(list || []);
|
612
|
+
result.splice(index, 0, item);
|
613
|
+
return result;
|
614
|
+
};
|
615
|
+
|
616
|
+
// lib/generate-id.ts
|
617
|
+
init_react_import();
|
618
|
+
var import_uuid = require("uuid");
|
619
|
+
var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
|
620
|
+
|
621
|
+
// lib/data/get-ids-for-parent.ts
|
622
|
+
init_react_import();
|
655
623
|
var getIdsForParent = (zoneCompound, state) => {
|
656
624
|
const [parentId] = zoneCompound.split(":");
|
657
625
|
const node = state.indexes.nodes[parentId];
|
658
626
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
659
627
|
};
|
660
|
-
|
628
|
+
|
629
|
+
// reducer/actions/insert.ts
|
630
|
+
function insertAction(state, action, appStore) {
|
661
631
|
const id = action.id || generateId(action.componentType);
|
662
632
|
const emptyComponentData = {
|
663
633
|
type: action.componentType,
|
664
|
-
props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
|
634
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
665
635
|
id
|
666
636
|
})
|
667
637
|
};
|
668
638
|
const [parentId] = action.destinationZone.split(":");
|
639
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
669
640
|
return walkTree(
|
670
641
|
state,
|
671
|
-
config,
|
642
|
+
appStore.config,
|
672
643
|
(content, zoneCompound) => {
|
673
644
|
if (zoneCompound === action.destinationZone) {
|
674
645
|
return insert(
|
@@ -679,44 +650,41 @@ function insertAction(state, action, config) {
|
|
679
650
|
}
|
680
651
|
return content;
|
681
652
|
},
|
682
|
-
(childItem) => {
|
653
|
+
(childItem, path) => {
|
683
654
|
if (childItem.props.id === id || childItem.props.id === parentId) {
|
684
655
|
return childItem;
|
656
|
+
} else if (idsInPath.includes(childItem.props.id)) {
|
657
|
+
return childItem;
|
658
|
+
} else if (path.includes(action.destinationZone)) {
|
659
|
+
return childItem;
|
685
660
|
}
|
686
661
|
return null;
|
687
662
|
}
|
688
663
|
);
|
689
664
|
}
|
690
|
-
|
665
|
+
|
666
|
+
// reducer/actions/replace.ts
|
667
|
+
init_react_import();
|
668
|
+
var replaceAction = (state, action, appStore) => {
|
669
|
+
const [parentId] = action.destinationZone.split(":");
|
670
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
671
|
+
const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
|
672
|
+
const idChanged = originalId !== action.data.props.id;
|
673
|
+
if (idChanged) {
|
674
|
+
throw new Error(
|
675
|
+
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
676
|
+
);
|
677
|
+
}
|
691
678
|
return walkTree(
|
692
679
|
state,
|
693
680
|
appStore.config,
|
694
681
|
(content, zoneCompound) => {
|
682
|
+
const newContent = [...content];
|
695
683
|
if (zoneCompound === action.destinationZone) {
|
696
|
-
|
697
|
-
content || [],
|
698
|
-
action.sourceIndex,
|
699
|
-
action.destinationIndex
|
700
|
-
);
|
684
|
+
newContent[action.destinationIndex] = action.data;
|
701
685
|
}
|
702
|
-
return
|
686
|
+
return newContent;
|
703
687
|
},
|
704
|
-
(childItem, path, index) => {
|
705
|
-
const zoneCompound = path[path.length - 1];
|
706
|
-
if (index === action.sourceIndex && zoneCompound === action.destinationZone || index === action.destinationIndex && zoneCompound === action.destinationZone) {
|
707
|
-
return childItem;
|
708
|
-
}
|
709
|
-
return null;
|
710
|
-
}
|
711
|
-
);
|
712
|
-
};
|
713
|
-
var replaceAction = (state, action, appStore) => {
|
714
|
-
const [parentId] = action.destinationZone.split(":");
|
715
|
-
const idsInPath = getIdsForParent(action.destinationZone, state);
|
716
|
-
return walkTree(
|
717
|
-
state,
|
718
|
-
appStore.config,
|
719
|
-
(content) => content,
|
720
688
|
(childItem, path) => {
|
721
689
|
const pathIds = path.map((p) => p.split(":")[0]);
|
722
690
|
if (childItem.props.id === action.data.props.id) {
|
@@ -732,226 +700,282 @@ var replaceAction = (state, action, appStore) => {
|
|
732
700
|
}
|
733
701
|
);
|
734
702
|
};
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
703
|
+
|
704
|
+
// reducer/actions/replace-root.ts
|
705
|
+
init_react_import();
|
706
|
+
var replaceRootAction = (state, action, appStore) => {
|
707
|
+
return walkTree(
|
708
|
+
state,
|
709
|
+
appStore.config,
|
710
|
+
(content) => content,
|
711
|
+
(childItem) => {
|
712
|
+
if (childItem.props.id === "root") {
|
713
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
714
|
+
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
715
|
+
readOnly: action.root.readOnly
|
716
|
+
});
|
717
|
+
}
|
718
|
+
return childItem;
|
743
719
|
}
|
744
|
-
|
745
|
-
}
|
746
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
720
|
+
);
|
747
721
|
};
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
722
|
+
|
723
|
+
// reducer/actions/duplicate.ts
|
724
|
+
init_react_import();
|
725
|
+
|
726
|
+
// lib/data/get-item.ts
|
727
|
+
init_react_import();
|
728
|
+
function getItem(selector, state) {
|
729
|
+
var _a, _b;
|
730
|
+
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
731
|
+
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
732
|
+
}
|
733
|
+
|
734
|
+
// reducer/actions/duplicate.ts
|
735
|
+
function duplicateAction(state, action, appStore) {
|
736
|
+
const item = getItem(
|
737
|
+
{ index: action.sourceIndex, zone: action.sourceZone },
|
738
|
+
state
|
739
|
+
);
|
740
|
+
const idsInPath = getIdsForParent(action.sourceZone, state);
|
741
|
+
const newItem = __spreadProps(__spreadValues({}, item), {
|
742
|
+
props: __spreadProps(__spreadValues({}, item.props), {
|
743
|
+
id: generateId(item.type)
|
744
|
+
})
|
745
|
+
});
|
746
|
+
const modified = walkTree(
|
747
|
+
state,
|
748
|
+
appStore.config,
|
749
|
+
(content, zoneCompound) => {
|
750
|
+
if (zoneCompound === action.sourceZone) {
|
751
|
+
return insert(content, action.sourceIndex + 1, item);
|
752
|
+
}
|
753
|
+
return content;
|
754
|
+
},
|
755
|
+
(childItem, path, index) => {
|
756
|
+
const zoneCompound = path[path.length - 1];
|
757
|
+
const parents = path.map((p) => p.split(":")[0]);
|
758
|
+
if (parents.indexOf(newItem.props.id) > -1) {
|
759
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
760
|
+
props: __spreadProps(__spreadValues({}, childItem.props), {
|
761
|
+
id: generateId(childItem.type)
|
762
|
+
})
|
763
|
+
});
|
764
|
+
}
|
765
|
+
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
766
|
+
return newItem;
|
767
|
+
}
|
768
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
769
|
+
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
770
770
|
return childItem;
|
771
771
|
}
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
781
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
782
|
-
id: generateId(item.type)
|
783
|
-
})
|
784
|
-
});
|
785
|
-
const modified = walkTree(
|
786
|
-
state,
|
787
|
-
appStore.config,
|
788
|
-
(content, zoneCompound) => {
|
789
|
-
if (zoneCompound === action.sourceZone) {
|
790
|
-
return insert(content, action.sourceIndex + 1, item);
|
791
|
-
}
|
792
|
-
return content;
|
793
|
-
},
|
794
|
-
(childItem, path, index) => {
|
795
|
-
const zoneCompound = path[path.length - 1];
|
796
|
-
const parents = path.map((p) => p.split(":")[0]);
|
797
|
-
if (parents.indexOf(newItem.props.id) > -1) {
|
798
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
799
|
-
props: __spreadProps(__spreadValues({}, childItem.props), {
|
800
|
-
id: generateId(childItem.type)
|
801
|
-
})
|
802
|
-
});
|
803
|
-
}
|
804
|
-
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
805
|
-
return newItem;
|
806
|
-
}
|
807
|
-
const [sourceZoneParent] = action.sourceZone.split(":");
|
808
|
-
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
809
|
-
return childItem;
|
810
|
-
}
|
811
|
-
return null;
|
772
|
+
return null;
|
773
|
+
}
|
774
|
+
);
|
775
|
+
return __spreadProps(__spreadValues({}, modified), {
|
776
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
777
|
+
itemSelector: {
|
778
|
+
index: action.sourceIndex + 1,
|
779
|
+
zone: action.sourceZone
|
812
780
|
}
|
813
|
-
)
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
781
|
+
})
|
782
|
+
});
|
783
|
+
}
|
784
|
+
|
785
|
+
// reducer/actions/reorder.ts
|
786
|
+
init_react_import();
|
787
|
+
|
788
|
+
// reducer/actions/move.ts
|
789
|
+
init_react_import();
|
790
|
+
|
791
|
+
// lib/data/remove.ts
|
792
|
+
init_react_import();
|
793
|
+
var remove = (list, index) => {
|
794
|
+
const result = Array.from(list);
|
795
|
+
result.splice(index, 1);
|
796
|
+
return result;
|
797
|
+
};
|
798
|
+
|
799
|
+
// reducer/actions/move.ts
|
800
|
+
var moveAction = (state, action, appStore) => {
|
801
|
+
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
802
|
+
return state;
|
825
803
|
}
|
826
|
-
|
827
|
-
|
828
|
-
|
804
|
+
const item = getItem(
|
805
|
+
{ zone: action.sourceZone, index: action.sourceIndex },
|
806
|
+
state
|
807
|
+
);
|
808
|
+
if (!item) return state;
|
809
|
+
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
810
|
+
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
811
|
+
return walkTree(
|
812
|
+
state,
|
813
|
+
appStore.config,
|
814
|
+
(content, zoneCompound) => {
|
815
|
+
if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
|
816
|
+
return insert(
|
817
|
+
remove(content, action.sourceIndex),
|
818
|
+
action.destinationIndex,
|
819
|
+
item
|
820
|
+
);
|
821
|
+
} else if (zoneCompound === action.sourceZone) {
|
822
|
+
return remove(content, action.sourceIndex);
|
823
|
+
} else if (zoneCompound === action.destinationZone) {
|
824
|
+
return insert(content, action.destinationIndex, item);
|
825
|
+
}
|
826
|
+
return content;
|
827
|
+
},
|
828
|
+
(childItem, path) => {
|
829
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
830
|
+
const [destinationZoneParent] = action.destinationZone.split(":");
|
831
|
+
const childId = childItem.props.id;
|
832
|
+
if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
|
833
|
+
return childItem;
|
834
|
+
}
|
835
|
+
return null;
|
829
836
|
}
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
(
|
855
|
-
|
856
|
-
|
857
|
-
const childId = childItem.props.id;
|
858
|
-
if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1) {
|
859
|
-
return childItem;
|
860
|
-
}
|
861
|
-
return null;
|
837
|
+
);
|
838
|
+
};
|
839
|
+
|
840
|
+
// reducer/actions/reorder.ts
|
841
|
+
var reorderAction = (state, action, appStore) => {
|
842
|
+
return moveAction(
|
843
|
+
state,
|
844
|
+
{
|
845
|
+
type: "move",
|
846
|
+
sourceIndex: action.sourceIndex,
|
847
|
+
sourceZone: action.destinationZone,
|
848
|
+
destinationIndex: action.destinationIndex,
|
849
|
+
destinationZone: action.destinationZone
|
850
|
+
},
|
851
|
+
appStore
|
852
|
+
);
|
853
|
+
};
|
854
|
+
|
855
|
+
// reducer/actions/remove.ts
|
856
|
+
init_react_import();
|
857
|
+
var removeAction = (state, action, appStore) => {
|
858
|
+
const item = getItem({ index: action.index, zone: action.zone }, state);
|
859
|
+
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
860
|
+
(acc, [nodeId, nodeData]) => {
|
861
|
+
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
862
|
+
if (pathIds.includes(item.props.id)) {
|
863
|
+
return [...acc, nodeId];
|
862
864
|
}
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
if (zoneCompound === action.zone) {
|
874
|
-
return remove(content, action.index);
|
875
|
-
}
|
876
|
-
return content;
|
877
|
-
},
|
878
|
-
(childItem, path) => {
|
879
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
880
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
881
|
-
return childItem;
|
882
|
-
}
|
883
|
-
return null;
|
865
|
+
return acc;
|
866
|
+
},
|
867
|
+
[item.props.id]
|
868
|
+
);
|
869
|
+
const newState = walkTree(
|
870
|
+
state,
|
871
|
+
appStore.config,
|
872
|
+
(content, zoneCompound) => {
|
873
|
+
if (zoneCompound === action.zone) {
|
874
|
+
return remove(content, action.index);
|
884
875
|
}
|
885
|
-
|
886
|
-
}
|
887
|
-
if (action.type === "registerZone") {
|
888
|
-
if (zoneCache[action.zone]) {
|
889
|
-
return __spreadProps(__spreadValues({}, state), {
|
890
|
-
data: __spreadProps(__spreadValues({}, state.data), {
|
891
|
-
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
892
|
-
[action.zone]: zoneCache[action.zone]
|
893
|
-
})
|
894
|
-
}),
|
895
|
-
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
896
|
-
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
897
|
-
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
898
|
-
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
899
|
-
type: "dropzone"
|
900
|
-
})
|
901
|
-
})
|
902
|
-
})
|
903
|
-
});
|
876
|
+
return content;
|
904
877
|
}
|
905
|
-
|
906
|
-
}
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
878
|
+
);
|
879
|
+
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
880
|
+
const parentId = zoneCompound.split(":")[0];
|
881
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
882
|
+
delete newState.data.zones[zoneCompound];
|
883
|
+
}
|
884
|
+
});
|
885
|
+
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
886
|
+
const parentId = zoneCompound.split(":")[0];
|
887
|
+
if (nodesToDelete.includes(parentId)) {
|
888
|
+
delete newState.indexes.zones[zoneCompound];
|
913
889
|
}
|
914
|
-
|
890
|
+
});
|
891
|
+
nodesToDelete.forEach((id) => {
|
892
|
+
delete newState.indexes.nodes[id];
|
893
|
+
});
|
894
|
+
return newState;
|
895
|
+
};
|
896
|
+
|
897
|
+
// reducer/actions/register-zone.ts
|
898
|
+
init_react_import();
|
899
|
+
var zoneCache = {};
|
900
|
+
function registerZoneAction(state, action) {
|
901
|
+
if (zoneCache[action.zone]) {
|
915
902
|
return __spreadProps(__spreadValues({}, state), {
|
916
903
|
data: __spreadProps(__spreadValues({}, state.data), {
|
917
|
-
zones:
|
904
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
905
|
+
[action.zone]: zoneCache[action.zone]
|
906
|
+
})
|
918
907
|
}),
|
919
908
|
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
920
|
-
zones:
|
909
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
910
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
911
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
912
|
+
type: "dropzone"
|
913
|
+
})
|
914
|
+
})
|
921
915
|
})
|
922
916
|
});
|
923
917
|
}
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
}
|
918
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
919
|
+
}
|
920
|
+
function unregisterZoneAction(state, action) {
|
921
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
922
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
923
|
+
if (_zones[action.zone]) {
|
924
|
+
zoneCache[action.zone] = _zones[action.zone];
|
925
|
+
delete _zones[action.zone];
|
926
|
+
}
|
927
|
+
delete zoneIndex[action.zone];
|
928
|
+
return __spreadProps(__spreadValues({}, state), {
|
929
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
930
|
+
zones: _zones
|
931
|
+
}),
|
932
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
933
|
+
zones: zoneIndex
|
934
|
+
})
|
935
|
+
});
|
936
|
+
}
|
937
|
+
|
938
|
+
// reducer/actions/set-data.ts
|
939
|
+
init_react_import();
|
940
|
+
var setDataAction = (state, action, appStore) => {
|
941
|
+
if (typeof action.data === "object") {
|
942
|
+
console.warn(
|
943
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
944
|
+
);
|
936
945
|
return walkTree(
|
937
946
|
__spreadProps(__spreadValues({}, state), {
|
938
|
-
data: __spreadValues(__spreadValues({}, state.data), action.data
|
947
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
939
948
|
}),
|
940
949
|
appStore.config
|
941
950
|
);
|
942
951
|
}
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
952
|
+
return walkTree(
|
953
|
+
__spreadProps(__spreadValues({}, state), {
|
954
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
955
|
+
}),
|
956
|
+
appStore.config
|
957
|
+
);
|
958
|
+
};
|
959
|
+
|
960
|
+
// reducer/actions/set-ui.ts
|
961
|
+
init_react_import();
|
962
|
+
var setUiAction = (state, action) => {
|
963
|
+
if (typeof action.ui === "object") {
|
949
964
|
return __spreadProps(__spreadValues({}, state), {
|
950
|
-
ui: __spreadValues(__spreadValues({}, state.ui), action.ui
|
965
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
951
966
|
});
|
952
967
|
}
|
953
|
-
return state
|
954
|
-
}
|
968
|
+
return __spreadProps(__spreadValues({}, state), {
|
969
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
970
|
+
});
|
971
|
+
};
|
972
|
+
|
973
|
+
// lib/data/make-state-public.ts
|
974
|
+
init_react_import();
|
975
|
+
var makeStatePublic = (state) => {
|
976
|
+
const { data, ui } = state;
|
977
|
+
return { data, ui };
|
978
|
+
};
|
955
979
|
|
956
980
|
// reducer/actions.tsx
|
957
981
|
init_react_import();
|
@@ -970,21 +994,54 @@ function storeInterceptor(reducer, record, onAction) {
|
|
970
994
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
971
995
|
if (record) record(newAppState);
|
972
996
|
}
|
973
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
997
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
974
998
|
return newAppState;
|
975
999
|
};
|
976
1000
|
}
|
977
1001
|
function createReducer({
|
978
|
-
config,
|
979
1002
|
record,
|
980
1003
|
onAction,
|
981
1004
|
appStore
|
982
1005
|
}) {
|
983
1006
|
return storeInterceptor(
|
984
1007
|
(state, action) => {
|
985
|
-
|
986
|
-
|
987
|
-
|
1008
|
+
if (action.type === "set") {
|
1009
|
+
return setAction(state, action, appStore);
|
1010
|
+
}
|
1011
|
+
if (action.type === "insert") {
|
1012
|
+
return insertAction(state, action, appStore);
|
1013
|
+
}
|
1014
|
+
if (action.type === "replace") {
|
1015
|
+
return replaceAction(state, action, appStore);
|
1016
|
+
}
|
1017
|
+
if (action.type === "replaceRoot") {
|
1018
|
+
return replaceRootAction(state, action, appStore);
|
1019
|
+
}
|
1020
|
+
if (action.type === "duplicate") {
|
1021
|
+
return duplicateAction(state, action, appStore);
|
1022
|
+
}
|
1023
|
+
if (action.type === "reorder") {
|
1024
|
+
return reorderAction(state, action, appStore);
|
1025
|
+
}
|
1026
|
+
if (action.type === "move") {
|
1027
|
+
return moveAction(state, action, appStore);
|
1028
|
+
}
|
1029
|
+
if (action.type === "remove") {
|
1030
|
+
return removeAction(state, action, appStore);
|
1031
|
+
}
|
1032
|
+
if (action.type === "registerZone") {
|
1033
|
+
return registerZoneAction(state, action);
|
1034
|
+
}
|
1035
|
+
if (action.type === "unregisterZone") {
|
1036
|
+
return unregisterZoneAction(state, action);
|
1037
|
+
}
|
1038
|
+
if (action.type === "setData") {
|
1039
|
+
return setDataAction(state, action, appStore);
|
1040
|
+
}
|
1041
|
+
if (action.type === "setUi") {
|
1042
|
+
return setUiAction(state, action);
|
1043
|
+
}
|
1044
|
+
return state;
|
988
1045
|
},
|
989
1046
|
record,
|
990
1047
|
onAction
|
@@ -1110,7 +1167,7 @@ var createHistorySlice = (set, get) => {
|
|
1110
1167
|
const { dispatch, history } = get();
|
1111
1168
|
dispatch({
|
1112
1169
|
type: "set",
|
1113
|
-
state: ((_a = history.histories[
|
1170
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1114
1171
|
});
|
1115
1172
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1116
1173
|
},
|
@@ -1159,7 +1216,7 @@ var createNodesSlice = (set, get) => ({
|
|
1159
1216
|
init_react_import();
|
1160
1217
|
var import_react7 = require("react");
|
1161
1218
|
|
1162
|
-
// lib/flatten-data.ts
|
1219
|
+
// lib/data/flatten-data.ts
|
1163
1220
|
init_react_import();
|
1164
1221
|
var flattenData = (state, config) => {
|
1165
1222
|
const data = [];
|
@@ -1194,12 +1251,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1194
1251
|
const { cache: cache2, globalPermissions } = permissions;
|
1195
1252
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1196
1253
|
var _a, _b, _c;
|
1197
|
-
const {
|
1198
|
-
config: config2,
|
1199
|
-
state: appState,
|
1200
|
-
setComponentLoading,
|
1201
|
-
unsetComponentLoading
|
1202
|
-
} = get();
|
1254
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1203
1255
|
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1204
1256
|
if (!componentConfig) {
|
1205
1257
|
return;
|
@@ -1208,14 +1260,14 @@ var createPermissionsSlice = (set, get) => {
|
|
1208
1260
|
if (componentConfig.resolvePermissions) {
|
1209
1261
|
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1210
1262
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1211
|
-
setComponentLoading(item2.props.id);
|
1263
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1212
1264
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1213
1265
|
item2,
|
1214
1266
|
{
|
1215
1267
|
changed,
|
1216
1268
|
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1217
1269
|
permissions: initialPermissions,
|
1218
|
-
appState,
|
1270
|
+
appState: makeStatePublic(appState),
|
1219
1271
|
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1220
1272
|
}
|
1221
1273
|
);
|
@@ -1233,7 +1285,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1233
1285
|
})
|
1234
1286
|
})
|
1235
1287
|
});
|
1236
|
-
|
1288
|
+
clearTimeout2();
|
1237
1289
|
}
|
1238
1290
|
}
|
1239
1291
|
});
|
@@ -1243,7 +1295,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1243
1295
|
// Shim the root data in by conforming to component data shape
|
1244
1296
|
{
|
1245
1297
|
type: "root",
|
1246
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1298
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1247
1299
|
},
|
1248
1300
|
force2
|
1249
1301
|
);
|
@@ -1258,7 +1310,6 @@ var createPermissionsSlice = (set, get) => {
|
|
1258
1310
|
} else if (root) {
|
1259
1311
|
resolveDataForRoot(force);
|
1260
1312
|
} else {
|
1261
|
-
resolveDataForRoot(force);
|
1262
1313
|
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1263
1314
|
yield resolveDataForItem(item2, force);
|
1264
1315
|
}));
|
@@ -1289,7 +1340,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1289
1340
|
} else if (root) {
|
1290
1341
|
const rootConfig = config.root;
|
1291
1342
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1292
|
-
const resolvedForItem = resolvedPermissions["
|
1343
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1293
1344
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1294
1345
|
}
|
1295
1346
|
return globalPermissions;
|
@@ -1313,24 +1364,25 @@ var createFieldsSlice = (_set, _get) => {
|
|
1313
1364
|
// lib/resolve-component-data.ts
|
1314
1365
|
init_react_import();
|
1315
1366
|
|
1316
|
-
// lib/map-slots.ts
|
1367
|
+
// lib/data/map-slots.ts
|
1317
1368
|
init_react_import();
|
1318
|
-
function
|
1319
|
-
return __async(this,
|
1369
|
+
function mapSlotsAsync(_0, _1) {
|
1370
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1320
1371
|
const props = __spreadValues({}, item.props);
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1372
|
+
const propKeys = Object.keys(props);
|
1373
|
+
for (let i = 0; i < propKeys.length; i++) {
|
1374
|
+
const propKey = propKeys[i];
|
1375
|
+
const itemType = "type" in item ? item.type : "root";
|
1376
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
1377
|
+
const content = props[propKey];
|
1324
1378
|
const mappedContent = recursive ? yield Promise.all(
|
1325
1379
|
content.map((item2) => __async(this, null, function* () {
|
1326
|
-
return yield
|
1380
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
1327
1381
|
}))
|
1328
1382
|
) : content;
|
1329
|
-
props[
|
1330
|
-
}
|
1331
|
-
|
1332
|
-
isSlot2
|
1333
|
-
);
|
1383
|
+
props[propKey] = yield map(mappedContent, propKey);
|
1384
|
+
}
|
1385
|
+
}
|
1334
1386
|
return __spreadProps(__spreadValues({}, item), { props });
|
1335
1387
|
});
|
1336
1388
|
}
|
@@ -1339,12 +1391,12 @@ function mapSlots(item, map, recursive = true, isSlot2) {
|
|
1339
1391
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
1340
1392
|
var cache = { lastChange: {} };
|
1341
1393
|
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
1342
|
-
const configForItem = "type" in item ? config.components[item.type] : config.root;
|
1394
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1343
1395
|
if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
|
1344
1396
|
const id = "id" in item.props ? item.props.id : "root";
|
1345
1397
|
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1346
|
-
if (item && item
|
1347
|
-
return resolved;
|
1398
|
+
if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
|
1399
|
+
return { node: resolved, didChange: false };
|
1348
1400
|
}
|
1349
1401
|
const changed = getChanged(item, oldItem);
|
1350
1402
|
if (onResolveStart) {
|
@@ -1353,30 +1405,35 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1353
1405
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1354
1406
|
changed,
|
1355
1407
|
lastData: oldItem,
|
1356
|
-
metadata,
|
1408
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1357
1409
|
trigger
|
1358
1410
|
});
|
1359
1411
|
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1360
1412
|
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1361
1413
|
});
|
1362
1414
|
if (recursive) {
|
1363
|
-
resolvedItem = yield
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1415
|
+
resolvedItem = yield mapSlotsAsync(
|
1416
|
+
resolvedItem,
|
1417
|
+
(content) => __async(void 0, null, function* () {
|
1418
|
+
return Promise.all(
|
1419
|
+
content.map(
|
1420
|
+
(childItem) => __async(void 0, null, function* () {
|
1421
|
+
return (yield resolveComponentData(
|
1422
|
+
childItem,
|
1423
|
+
config,
|
1424
|
+
metadata,
|
1425
|
+
onResolveStart,
|
1426
|
+
onResolveEnd,
|
1427
|
+
trigger,
|
1428
|
+
false
|
1429
|
+
)).node;
|
1430
|
+
})
|
1431
|
+
)
|
1432
|
+
);
|
1433
|
+
}),
|
1434
|
+
false,
|
1435
|
+
createIsSlotConfig(config)
|
1436
|
+
);
|
1380
1437
|
}
|
1381
1438
|
if (Object.keys(readOnly).length) {
|
1382
1439
|
resolvedItem.readOnly = readOnly;
|
@@ -1393,7 +1450,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1393
1450
|
return { node: item, didChange: false };
|
1394
1451
|
});
|
1395
1452
|
|
1396
|
-
// lib/to-root.ts
|
1453
|
+
// lib/data/to-root.ts
|
1397
1454
|
init_react_import();
|
1398
1455
|
var toRoot = (item) => {
|
1399
1456
|
if ("type" in item && item.type !== "root") {
|
@@ -1440,174 +1497,176 @@ var defaultPageFields = {
|
|
1440
1497
|
title: { type: "text" }
|
1441
1498
|
};
|
1442
1499
|
var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
|
1443
|
-
(0, import_middleware2.subscribeWithSelector)((set, get) =>
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
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
|
-
setComponentState
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1500
|
+
(0, import_middleware2.subscribeWithSelector)((set, get) => {
|
1501
|
+
var _a, _b;
|
1502
|
+
return __spreadProps(__spreadValues({
|
1503
|
+
state: defaultAppState,
|
1504
|
+
config: { components: {} },
|
1505
|
+
componentState: {},
|
1506
|
+
plugins: [],
|
1507
|
+
overrides: {},
|
1508
|
+
viewports: defaultViewports,
|
1509
|
+
zoomConfig: {
|
1510
|
+
autoZoom: 1,
|
1511
|
+
rootHeight: 0,
|
1512
|
+
zoom: 1
|
1513
|
+
},
|
1514
|
+
status: "LOADING",
|
1515
|
+
iframe: {},
|
1516
|
+
metadata: {}
|
1517
|
+
}, initialAppStore), {
|
1518
|
+
fields: createFieldsSlice(set, get),
|
1519
|
+
history: createHistorySlice(set, get),
|
1520
|
+
nodes: createNodesSlice(set, get),
|
1521
|
+
permissions: createPermissionsSlice(set, get),
|
1522
|
+
getComponentConfig: (type) => {
|
1523
|
+
var _a2;
|
1524
|
+
const { config, selectedItem } = get();
|
1525
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
1526
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
1527
|
+
},
|
1528
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
1529
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
1530
|
+
initialAppStore.state
|
1531
|
+
) : null,
|
1532
|
+
dispatch: (action) => set((s) => {
|
1533
|
+
var _a2, _b2;
|
1534
|
+
const { record } = get().history;
|
1535
|
+
const dispatch = createReducer({
|
1536
|
+
record,
|
1537
|
+
appStore: s
|
1538
|
+
});
|
1539
|
+
const state = dispatch(s.state, action);
|
1540
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1541
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
1542
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1543
|
+
}),
|
1544
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
1545
|
+
setStatus: (status) => set({ status }),
|
1546
|
+
setComponentState: (componentState) => set({ componentState }),
|
1547
|
+
pendingLoadTimeouts: {},
|
1548
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
1549
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
1550
|
+
const loadId = generateId();
|
1551
|
+
const setLoading = () => {
|
1552
|
+
var _a2;
|
1553
|
+
const { componentState } = get();
|
1554
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1555
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1556
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
1557
|
+
})
|
1558
|
+
}));
|
1559
|
+
};
|
1560
|
+
const unsetLoading = () => {
|
1561
|
+
var _a2;
|
1562
|
+
const { componentState } = get();
|
1563
|
+
clearTimeout(timeout2);
|
1564
|
+
delete pendingLoadTimeouts[loadId];
|
1565
|
+
set({ pendingLoadTimeouts });
|
1566
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
1567
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
1568
|
+
loadingCount: Math.max(
|
1569
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
1570
|
+
0
|
1571
|
+
)
|
1572
|
+
})
|
1573
|
+
}));
|
1574
|
+
};
|
1575
|
+
const timeout2 = setTimeout(() => {
|
1576
|
+
if (loading) {
|
1577
|
+
setLoading();
|
1578
|
+
} else {
|
1579
|
+
unsetLoading();
|
1580
|
+
}
|
1581
|
+
delete pendingLoadTimeouts[loadId];
|
1582
|
+
set({ pendingLoadTimeouts });
|
1583
|
+
}, defer);
|
1584
|
+
set({
|
1585
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
1586
|
+
[id]: timeout2
|
1507
1587
|
})
|
1508
|
-
})
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
}
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1548
|
-
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1549
|
-
}),
|
1550
|
-
// resolveDataRuns: 0,
|
1551
|
-
// resolveData: (newAppState) =>
|
1552
|
-
// set((s) => {
|
1553
|
-
// resolveData(newAppState, get);
|
1554
|
-
// return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
|
1555
|
-
// }),
|
1556
|
-
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1557
|
-
const { config, metadata, setComponentLoading } = get();
|
1558
|
-
return yield resolveComponentData(
|
1559
|
-
componentData,
|
1560
|
-
config,
|
1561
|
-
metadata,
|
1562
|
-
(item) => setComponentLoading(
|
1563
|
-
"id" in item.props ? item.props.id : "root",
|
1564
|
-
true,
|
1565
|
-
50
|
1566
|
-
),
|
1567
|
-
(item) => setComponentLoading(
|
1568
|
-
"id" in item.props ? item.props.id : "root",
|
1569
|
-
false,
|
1570
|
-
0
|
1571
|
-
),
|
1572
|
-
trigger
|
1573
|
-
);
|
1574
|
-
}),
|
1575
|
-
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1576
|
-
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1577
|
-
walkTree(
|
1578
|
-
state,
|
1579
|
-
config,
|
1580
|
-
(content) => content,
|
1581
|
-
(childItem) => {
|
1582
|
-
resolveComponentData2(childItem, "load").then((resolved) => {
|
1583
|
-
const { state: state2 } = get();
|
1584
|
-
const node = state2.indexes.nodes[resolved.node.props.id];
|
1585
|
-
if (node && resolved.didChange) {
|
1586
|
-
if (resolved.node.props.id === "root") {
|
1587
|
-
dispatch({
|
1588
|
-
type: "replaceRoot",
|
1589
|
-
root: toRoot(resolved.node)
|
1590
|
-
});
|
1591
|
-
} else {
|
1592
|
-
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1593
|
-
const parentZone = state2.indexes.zones[zoneCompound];
|
1594
|
-
const index = parentZone.contentIds.indexOf(
|
1595
|
-
resolved.node.props.id
|
1596
|
-
);
|
1597
|
-
dispatch({
|
1598
|
-
type: "replace",
|
1599
|
-
data: resolved.node,
|
1600
|
-
destinationIndex: index,
|
1601
|
-
destinationZone: zoneCompound
|
1602
|
-
});
|
1603
|
-
}
|
1588
|
+
});
|
1589
|
+
return unsetLoading;
|
1590
|
+
},
|
1591
|
+
unsetComponentLoading: (id) => {
|
1592
|
+
const { setComponentLoading } = get();
|
1593
|
+
setComponentLoading(id, false);
|
1594
|
+
},
|
1595
|
+
// Helper
|
1596
|
+
setUi: (ui, recordHistory) => set((s) => {
|
1597
|
+
const dispatch = createReducer({
|
1598
|
+
record: () => {
|
1599
|
+
},
|
1600
|
+
appStore: s
|
1601
|
+
});
|
1602
|
+
const state = dispatch(s.state, {
|
1603
|
+
type: "setUi",
|
1604
|
+
ui,
|
1605
|
+
recordHistory
|
1606
|
+
});
|
1607
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
1608
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1609
|
+
}),
|
1610
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1611
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
1612
|
+
const timeouts = {};
|
1613
|
+
return yield resolveComponentData(
|
1614
|
+
componentData,
|
1615
|
+
config,
|
1616
|
+
metadata,
|
1617
|
+
(item) => {
|
1618
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1619
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
1620
|
+
},
|
1621
|
+
(item) => __async(void 0, null, function* () {
|
1622
|
+
const id = "id" in item.props ? item.props.id : "root";
|
1623
|
+
if ("type" in item) {
|
1624
|
+
yield permissions.refreshPermissions({ item });
|
1625
|
+
} else {
|
1626
|
+
yield permissions.refreshPermissions({ root: true });
|
1604
1627
|
}
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1628
|
+
timeouts[id]();
|
1629
|
+
}),
|
1630
|
+
trigger
|
1631
|
+
);
|
1632
|
+
}),
|
1633
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1634
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1635
|
+
walkTree(
|
1636
|
+
state,
|
1637
|
+
config,
|
1638
|
+
(content) => content,
|
1639
|
+
(childItem) => {
|
1640
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
1641
|
+
const { state: state2 } = get();
|
1642
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
1643
|
+
if (node && resolved.didChange) {
|
1644
|
+
if (resolved.node.props.id === "root") {
|
1645
|
+
dispatch({
|
1646
|
+
type: "replaceRoot",
|
1647
|
+
root: toRoot(resolved.node)
|
1648
|
+
});
|
1649
|
+
} else {
|
1650
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1651
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
1652
|
+
const index = parentZone.contentIds.indexOf(
|
1653
|
+
resolved.node.props.id
|
1654
|
+
);
|
1655
|
+
dispatch({
|
1656
|
+
type: "replace",
|
1657
|
+
data: resolved.node,
|
1658
|
+
destinationIndex: index,
|
1659
|
+
destinationZone: zoneCompound
|
1660
|
+
});
|
1661
|
+
}
|
1662
|
+
}
|
1663
|
+
});
|
1664
|
+
return childItem;
|
1665
|
+
}
|
1666
|
+
);
|
1667
|
+
})
|
1668
|
+
});
|
1669
|
+
})
|
1611
1670
|
);
|
1612
1671
|
var appStoreContext = (0, import_react9.createContext)(createAppStore());
|
1613
1672
|
function useAppStore(selector) {
|
@@ -1627,7 +1686,10 @@ init_react_import();
|
|
1627
1686
|
// lib/filter.ts
|
1628
1687
|
init_react_import();
|
1629
1688
|
|
1630
|
-
// lib/
|
1689
|
+
// lib/data/reorder.ts
|
1690
|
+
init_react_import();
|
1691
|
+
|
1692
|
+
// lib/data/replace.ts
|
1631
1693
|
init_react_import();
|
1632
1694
|
|
1633
1695
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
@@ -2110,7 +2172,6 @@ var DropZoneProvider = ({
|
|
2110
2172
|
value
|
2111
2173
|
}) => {
|
2112
2174
|
const [hoveringComponent, setHoveringComponent] = (0, import_react11.useState)();
|
2113
|
-
const [activeZones, setActiveZones] = (0, import_react11.useState)({});
|
2114
2175
|
const dispatch = useAppStore((s) => s.dispatch);
|
2115
2176
|
const registerZone = (0, import_react11.useCallback)(
|
2116
2177
|
(zoneCompound) => {
|
@@ -2119,7 +2180,7 @@ var DropZoneProvider = ({
|
|
2119
2180
|
zone: zoneCompound
|
2120
2181
|
});
|
2121
2182
|
},
|
2122
|
-
[
|
2183
|
+
[dispatch]
|
2123
2184
|
);
|
2124
2185
|
const unregisterZone = (0, import_react11.useCallback)(
|
2125
2186
|
(zoneCompound) => {
|
@@ -2128,17 +2189,16 @@ var DropZoneProvider = ({
|
|
2128
2189
|
zone: zoneCompound
|
2129
2190
|
});
|
2130
2191
|
},
|
2131
|
-
[
|
2192
|
+
[dispatch]
|
2132
2193
|
);
|
2133
2194
|
const memoValue = (0, import_react11.useMemo)(
|
2134
2195
|
() => __spreadValues({
|
2135
2196
|
hoveringComponent,
|
2136
2197
|
setHoveringComponent,
|
2137
2198
|
registerZone,
|
2138
|
-
unregisterZone
|
2139
|
-
activeZones
|
2199
|
+
unregisterZone
|
2140
2200
|
}, value),
|
2141
|
-
[value, hoveringComponent
|
2201
|
+
[value, hoveringComponent]
|
2142
2202
|
);
|
2143
2203
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: memoValue && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(dropZoneContext.Provider, { value: memoValue, children }) });
|
2144
2204
|
};
|
@@ -2231,8 +2291,10 @@ var DraggableComponent = ({
|
|
2231
2291
|
return (_a = s.state.indexes.nodes[id]) == null ? void 0 : _a.path;
|
2232
2292
|
}));
|
2233
2293
|
const permissions = useAppStore(
|
2234
|
-
(0, import_shallow2.useShallow)((s) =>
|
2235
|
-
|
2294
|
+
(0, import_shallow2.useShallow)((s) => {
|
2295
|
+
const item = getItem({ index, zone: zoneCompound }, s.state);
|
2296
|
+
return s.permissions.getPermissions({ item });
|
2297
|
+
})
|
2236
2298
|
);
|
2237
2299
|
const userIsDragging = useContextStore(
|
2238
2300
|
ZoneStoreContext,
|
@@ -2486,76 +2548,82 @@ var DraggableComponent = ({
|
|
2486
2548
|
setDragAxis(autoDragAxis);
|
2487
2549
|
}, [ref, userDragAxis, autoDragAxis]);
|
2488
2550
|
const parentAction = (ctx == null ? void 0 : ctx.areaId) && (ctx == null ? void 0 : ctx.areaId) !== "root" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onSelectParent, label: "Select parent", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CornerLeftUp, { size: 16 }) });
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2492
|
-
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2551
|
+
const nextContextValue = (0, import_react13.useMemo)(
|
2552
|
+
() => __spreadProps(__spreadValues({}, ctx), {
|
2553
|
+
areaId: id,
|
2554
|
+
zoneCompound,
|
2555
|
+
index,
|
2556
|
+
depth: depth + 1,
|
2557
|
+
registerLocalZone,
|
2558
|
+
unregisterLocalZone
|
2559
|
+
}),
|
2560
|
+
[
|
2561
|
+
ctx,
|
2562
|
+
id,
|
2563
|
+
zoneCompound,
|
2564
|
+
index,
|
2565
|
+
depth,
|
2566
|
+
registerLocalZone,
|
2567
|
+
unregisterLocalZone
|
2568
|
+
]
|
2569
|
+
);
|
2570
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(DropZoneProvider, { value: nextContextValue, children: [
|
2571
|
+
isVisible && (0, import_react_dom.createPortal)(
|
2572
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
2573
|
+
"div",
|
2574
|
+
{
|
2575
|
+
className: getClassName3({
|
2576
|
+
isSelected,
|
2577
|
+
isDragging: thisIsDragging,
|
2578
|
+
hover: hover || indicativeHover
|
2579
|
+
}),
|
2580
|
+
style: __spreadValues({}, style),
|
2581
|
+
"data-puck-overlay": true,
|
2582
|
+
children: [
|
2583
|
+
debug,
|
2584
|
+
isLoading && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Loader, {}) }),
|
2585
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
2586
|
+
"div",
|
2587
|
+
{
|
2588
|
+
className: getClassName3("actionsOverlay"),
|
2589
|
+
style: {
|
2590
|
+
top: actionsOverlayTop / zoom
|
2591
|
+
},
|
2592
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
2516
2593
|
"div",
|
2517
2594
|
{
|
2518
|
-
className: getClassName3("
|
2595
|
+
className: getClassName3("actions"),
|
2519
2596
|
style: {
|
2520
|
-
|
2597
|
+
transform: `scale(${1 / zoom}`,
|
2598
|
+
top: actionsTop / zoom,
|
2599
|
+
right: 0,
|
2600
|
+
paddingLeft: actionsSide,
|
2601
|
+
paddingRight: actionsSide
|
2521
2602
|
},
|
2522
|
-
|
2523
|
-
|
2603
|
+
ref: syncActionsPosition,
|
2604
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
2605
|
+
CustomActionBar,
|
2524
2606
|
{
|
2525
|
-
|
2526
|
-
|
2527
|
-
|
2528
|
-
|
2529
|
-
|
2530
|
-
|
2531
|
-
paddingRight: actionsSide
|
2532
|
-
},
|
2533
|
-
ref: syncActionsPosition,
|
2534
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
2535
|
-
CustomActionBar,
|
2536
|
-
{
|
2537
|
-
parentAction,
|
2538
|
-
label: DEBUG2 ? id : label,
|
2539
|
-
children: [
|
2540
|
-
permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Copy, { size: 16 }) }),
|
2541
|
-
permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Trash, { size: 16 }) })
|
2542
|
-
]
|
2543
|
-
}
|
2544
|
-
)
|
2607
|
+
parentAction,
|
2608
|
+
label: DEBUG2 ? id : label,
|
2609
|
+
children: [
|
2610
|
+
permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Copy, { size: 16 }) }),
|
2611
|
+
permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Trash, { size: 16 }) })
|
2612
|
+
]
|
2545
2613
|
}
|
2546
2614
|
)
|
2547
2615
|
}
|
2548
|
-
)
|
2549
|
-
|
2550
|
-
|
2551
|
-
}
|
2552
|
-
|
2553
|
-
|
2554
|
-
|
2555
|
-
|
2556
|
-
|
2557
|
-
|
2558
|
-
);
|
2616
|
+
)
|
2617
|
+
}
|
2618
|
+
),
|
2619
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("overlay") })
|
2620
|
+
]
|
2621
|
+
}
|
2622
|
+
),
|
2623
|
+
portalEl || document.body
|
2624
|
+
),
|
2625
|
+
children(refSetter)
|
2626
|
+
] });
|
2559
2627
|
};
|
2560
2628
|
|
2561
2629
|
// css-module:/home/runner/work/puck/puck/packages/core/components/DropZone/styles.module.css#css-module
|
@@ -3254,14 +3322,8 @@ var DropZoneChild = ({
|
|
3254
3322
|
}) => {
|
3255
3323
|
var _a, _b;
|
3256
3324
|
const metadata = useAppStore((s) => s.metadata);
|
3257
|
-
const puckProps = {
|
3258
|
-
renderDropZone: DropZoneEditPure,
|
3259
|
-
isEditing: true,
|
3260
|
-
dragRef: null,
|
3261
|
-
metadata
|
3262
|
-
};
|
3263
3325
|
const ctx = (0, import_react25.useContext)(dropZoneContext);
|
3264
|
-
const { depth } = ctx;
|
3326
|
+
const { depth = 1 } = ctx != null ? ctx : {};
|
3265
3327
|
const nodeProps = useAppStore(
|
3266
3328
|
(0, import_shallow3.useShallow)((s) => {
|
3267
3329
|
var _a2;
|
@@ -3274,11 +3336,23 @@ var DropZoneChild = ({
|
|
3274
3336
|
return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.type;
|
3275
3337
|
}
|
3276
3338
|
);
|
3339
|
+
const nodeReadOnly = useAppStore(
|
3340
|
+
(0, import_shallow3.useShallow)((s) => {
|
3341
|
+
var _a2;
|
3342
|
+
return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.readOnly;
|
3343
|
+
})
|
3344
|
+
);
|
3277
3345
|
const node = { type: nodeType, props: nodeProps };
|
3278
3346
|
const item = nodeProps ? node : (preview == null ? void 0 : preview.componentType) ? { type: preview.componentType, props: preview.props } : null;
|
3279
3347
|
const componentConfig = useAppStore(
|
3280
3348
|
(s) => (item == null ? void 0 : item.type) ? s.config.components[item.type] : null
|
3281
3349
|
);
|
3350
|
+
const puckProps = {
|
3351
|
+
renderDropZone: DropZoneEditPure,
|
3352
|
+
isEditing: true,
|
3353
|
+
dragRef: null,
|
3354
|
+
metadata: __spreadValues(__spreadValues({}, metadata), componentConfig == null ? void 0 : componentConfig.metadata)
|
3355
|
+
};
|
3282
3356
|
const overrides = useAppStore((s) => s.overrides);
|
3283
3357
|
const isLoading = useAppStore(
|
3284
3358
|
(s) => {
|
@@ -3310,7 +3384,10 @@ var DropZoneChild = ({
|
|
3310
3384
|
const defaultedPropsWithSlots = useSlots(
|
3311
3385
|
componentConfig,
|
3312
3386
|
defaultsProps,
|
3313
|
-
DropZoneEditPure
|
3387
|
+
DropZoneEditPure,
|
3388
|
+
(slotProps) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ContextSlotRender, { componentId, zone: slotProps.zone }),
|
3389
|
+
nodeReadOnly,
|
3390
|
+
isLoading
|
3314
3391
|
);
|
3315
3392
|
if (!item) return;
|
3316
3393
|
let Render2 = componentConfig ? componentConfig.render : () => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { padding: 48, textAlign: "center" }, children: [
|
@@ -3348,6 +3425,7 @@ var DropZoneChild = ({
|
|
3348
3425
|
}
|
3349
3426
|
);
|
3350
3427
|
};
|
3428
|
+
var DropZoneChildMemo = (0, import_react25.memo)(DropZoneChild);
|
3351
3429
|
var DropZoneEdit = (0, import_react25.forwardRef)(
|
3352
3430
|
function DropZoneEditInternal({
|
3353
3431
|
zone,
|
@@ -3362,10 +3440,10 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
|
|
3362
3440
|
const {
|
3363
3441
|
// These all need setting via context
|
3364
3442
|
areaId,
|
3365
|
-
depth,
|
3443
|
+
depth = 0,
|
3366
3444
|
registerLocalZone,
|
3367
3445
|
unregisterLocalZone
|
3368
|
-
} = ctx;
|
3446
|
+
} = ctx != null ? ctx : {};
|
3369
3447
|
const path = useAppStore(
|
3370
3448
|
(0, import_shallow3.useShallow)((s) => {
|
3371
3449
|
var _a;
|
@@ -3407,6 +3485,11 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
|
|
3407
3485
|
);
|
3408
3486
|
(0, import_react25.useEffect)(() => {
|
3409
3487
|
if (!zoneType || zoneType === "dropzone") {
|
3488
|
+
if (zoneCompound !== rootDroppableId) {
|
3489
|
+
console.warn(
|
3490
|
+
"DropZones have been deprecated in favor of slot fields and will be removed in a future version of Puck. Please see the migration guide: https://www.puckeditor.com/docs/guides/migrations/dropzones-to-slots"
|
3491
|
+
);
|
3492
|
+
}
|
3410
3493
|
if (ctx == null ? void 0 : ctx.registerZone) {
|
3411
3494
|
ctx == null ? void 0 : ctx.registerZone(zoneCompound);
|
3412
3495
|
}
|
@@ -3512,7 +3595,7 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
|
|
3512
3595
|
}),
|
3513
3596
|
children: contentIdsWithPreview.map((componentId, i) => {
|
3514
3597
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
3515
|
-
|
3598
|
+
DropZoneChildMemo,
|
3516
3599
|
{
|
3517
3600
|
zoneCompound,
|
3518
3601
|
componentId,
|
@@ -3530,6 +3613,30 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
|
|
3530
3613
|
);
|
3531
3614
|
}
|
3532
3615
|
);
|
3616
|
+
var DropZoneRenderItem = ({
|
3617
|
+
config,
|
3618
|
+
item,
|
3619
|
+
metadata
|
3620
|
+
}) => {
|
3621
|
+
const Component = config.components[item.type];
|
3622
|
+
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
3623
|
+
const nextContextValue = (0, import_react25.useMemo)(
|
3624
|
+
() => ({
|
3625
|
+
areaId: props.id,
|
3626
|
+
depth: 1
|
3627
|
+
}),
|
3628
|
+
[props]
|
3629
|
+
);
|
3630
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
3631
|
+
Component.render,
|
3632
|
+
__spreadProps(__spreadValues({}, props), {
|
3633
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
3634
|
+
renderDropZone: DropZoneRenderPure,
|
3635
|
+
metadata: __spreadValues(__spreadValues({}, metadata), Component.metadata)
|
3636
|
+
})
|
3637
|
+
})
|
3638
|
+
) }, props.id);
|
3639
|
+
};
|
3533
3640
|
var DropZoneRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneRender, __spreadValues({}, props));
|
3534
3641
|
var DropZoneRender = (0, import_react25.forwardRef)(
|
3535
3642
|
function DropZoneRenderInternal({ className, style, zone }, ref) {
|
@@ -3560,31 +3667,14 @@ var DropZoneRender = (0, import_react25.forwardRef)(
|
|
3560
3667
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className, style, ref, children: content.map((item) => {
|
3561
3668
|
const Component = config.components[item.type];
|
3562
3669
|
if (Component) {
|
3563
|
-
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
3564
|
-
SlotRenderPure,
|
3565
|
-
__spreadProps(__spreadValues({}, slotProps), {
|
3566
|
-
config,
|
3567
|
-
metadata
|
3568
|
-
})
|
3569
|
-
));
|
3570
3670
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
3571
|
-
|
3671
|
+
DropZoneRenderItem,
|
3572
3672
|
{
|
3573
|
-
|
3574
|
-
|
3575
|
-
|
3576
|
-
},
|
3577
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
3578
|
-
Component.render,
|
3579
|
-
__spreadProps(__spreadValues({}, props), {
|
3580
|
-
puck: {
|
3581
|
-
renderDropZone: DropZoneRenderPure,
|
3582
|
-
metadata: metadata || {}
|
3583
|
-
}
|
3584
|
-
})
|
3585
|
-
)
|
3673
|
+
config,
|
3674
|
+
item,
|
3675
|
+
metadata
|
3586
3676
|
},
|
3587
|
-
props.id
|
3677
|
+
item.props.id
|
3588
3678
|
);
|
3589
3679
|
}
|
3590
3680
|
return null;
|
@@ -3604,30 +3694,60 @@ var DropZone = (0, import_react25.forwardRef)(
|
|
3604
3694
|
// components/SlotRender/index.tsx
|
3605
3695
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
3606
3696
|
var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SlotRender, __spreadValues({}, props));
|
3697
|
+
var ContextSlotRender = ({
|
3698
|
+
componentId,
|
3699
|
+
zone
|
3700
|
+
}) => {
|
3701
|
+
const config = useAppStore((s) => s.config);
|
3702
|
+
const metadata = useAppStore((s) => s.metadata);
|
3703
|
+
const slotContent = useAppStore(
|
3704
|
+
(s) => {
|
3705
|
+
var _a, _b;
|
3706
|
+
return (_b = (_a = s.state.indexes.nodes[componentId]) == null ? void 0 : _a.data.props[zone]) != null ? _b : null;
|
3707
|
+
}
|
3708
|
+
);
|
3709
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
3710
|
+
SlotRenderPure,
|
3711
|
+
{
|
3712
|
+
content: slotContent,
|
3713
|
+
zone,
|
3714
|
+
config,
|
3715
|
+
metadata
|
3716
|
+
}
|
3717
|
+
);
|
3718
|
+
};
|
3719
|
+
var Item = ({
|
3720
|
+
config,
|
3721
|
+
item,
|
3722
|
+
metadata
|
3723
|
+
}) => {
|
3724
|
+
const Component = config.components[item.type];
|
3725
|
+
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
3726
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
3727
|
+
Component.render,
|
3728
|
+
__spreadProps(__spreadValues({}, props), {
|
3729
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
3730
|
+
renderDropZone: DropZoneRenderPure,
|
3731
|
+
metadata: metadata || {}
|
3732
|
+
})
|
3733
|
+
})
|
3734
|
+
);
|
3735
|
+
};
|
3607
3736
|
var SlotRender = (0, import_react26.forwardRef)(
|
3608
3737
|
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
3609
3738
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className, style, ref, children: content.map((item) => {
|
3610
|
-
|
3611
|
-
|
3612
|
-
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
3613
|
-
SlotRenderPure,
|
3614
|
-
__spreadProps(__spreadValues({}, slotProps), {
|
3615
|
-
config,
|
3616
|
-
metadata
|
3617
|
-
})
|
3618
|
-
));
|
3619
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
3620
|
-
Component.render,
|
3621
|
-
__spreadProps(__spreadValues({}, props), {
|
3622
|
-
puck: {
|
3623
|
-
renderDropZone: DropZoneRenderPure,
|
3624
|
-
metadata: metadata || {}
|
3625
|
-
}
|
3626
|
-
}),
|
3627
|
-
props.id
|
3628
|
-
);
|
3739
|
+
if (!config.components[item.type]) {
|
3740
|
+
return null;
|
3629
3741
|
}
|
3630
|
-
return
|
3742
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
3743
|
+
Item,
|
3744
|
+
{
|
3745
|
+
config,
|
3746
|
+
item,
|
3747
|
+
metadata
|
3748
|
+
},
|
3749
|
+
item.props.id
|
3750
|
+
);
|
3631
3751
|
}) });
|
3632
3752
|
}
|
3633
3753
|
);
|
@@ -3727,14 +3847,14 @@ function Render({
|
|
3727
3847
|
// lib/resolve-all-data.ts
|
3728
3848
|
init_react_import();
|
3729
3849
|
|
3730
|
-
// lib/default-data.ts
|
3850
|
+
// lib/data/default-data.ts
|
3731
3851
|
init_react_import();
|
3732
3852
|
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
3733
3853
|
root: data.root || {},
|
3734
3854
|
content: data.content || []
|
3735
3855
|
});
|
3736
3856
|
|
3737
|
-
// lib/to-component.ts
|
3857
|
+
// lib/data/to-component.ts
|
3738
3858
|
init_react_import();
|
3739
3859
|
var toComponent = (item) => {
|
3740
3860
|
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
@@ -3762,17 +3882,29 @@ function resolveAllData(_0, _1) {
|
|
3762
3882
|
"force",
|
3763
3883
|
false
|
3764
3884
|
)).node;
|
3765
|
-
const resolvedDeep = yield
|
3885
|
+
const resolvedDeep = yield mapSlotsAsync(
|
3886
|
+
resolved,
|
3887
|
+
processContent,
|
3888
|
+
false
|
3889
|
+
);
|
3766
3890
|
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
3767
3891
|
return resolvedDeep;
|
3768
3892
|
});
|
3769
3893
|
const processContent = (content) => __async(this, null, function* () {
|
3770
3894
|
return Promise.all(content.map(resolveNode));
|
3771
3895
|
});
|
3896
|
+
const processZones = () => __async(this, null, function* () {
|
3897
|
+
var _a2;
|
3898
|
+
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
3899
|
+
Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
|
3900
|
+
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
3901
|
+
}));
|
3902
|
+
return zones;
|
3903
|
+
});
|
3772
3904
|
const dynamic = {
|
3773
3905
|
root: yield resolveNode(defaultedData.root),
|
3774
3906
|
content: yield processContent(defaultedData.content),
|
3775
|
-
zones:
|
3907
|
+
zones: yield processZones()
|
3776
3908
|
};
|
3777
3909
|
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
|
3778
3910
|
const content = defaultedData.zones[zoneKey];
|