@measured/puck 0.19.0-canary.a281c342 → 0.19.0-canary.a6dd529f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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.ts
195
+ // lib/use-slots.tsx
196
196
  init_react_import();
197
197
  var import_react2 = require("react");
198
- function useSlots(config, props, renderSlot) {
199
- return (0, import_react2.useMemo)(() => {
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 newProps = __spreadValues({}, props);
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
- newProps[fieldKey] = (dzProps) => renderSlot(__spreadProps(__spreadValues({}, dzProps), {
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: props[fieldKey] || []
214
+ content
210
215
  }));
216
+ slotProps2[fieldKey] = Slot;
211
217
  }
212
218
  }
213
- return newProps;
214
- }, [config, props]);
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": "_DraggableComponent_1ukn8_1", "DraggableComponent-overlay": "_DraggableComponent-overlay_1ukn8_12", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_1ukn8_29", "DraggableComponent--hover": "_DraggableComponent--hover_1ukn8_45", "DraggableComponent--isLocked": "_DraggableComponent--isLocked_1ukn8_45", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_1ukn8_54", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_1ukn8_66", "DraggableComponent-actions": "_DraggableComponent-actions_1ukn8_66" };
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,45 +379,16 @@ init_react_import();
372
379
  // reducer/index.ts
373
380
  init_react_import();
374
381
 
375
- // reducer/reduce.ts
382
+ // reducer/actions/set.ts
376
383
  init_react_import();
377
384
 
378
- // lib/insert.ts
385
+ // lib/data/walk-tree.ts
379
386
  init_react_import();
380
- var insert = (list, index, item) => {
381
- const result = Array.from(list || []);
382
- result.splice(index, 0, item);
383
- return result;
384
- };
385
-
386
- // lib/remove.ts
387
- init_react_import();
388
- var remove = (list, index) => {
389
- const result = Array.from(list);
390
- result.splice(index, 1);
391
- return result;
392
- };
393
-
394
- // lib/get-item.ts
395
- init_react_import();
396
- function getItem(selector, state) {
397
- var _a, _b;
398
- const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
399
- return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
400
- }
401
387
 
402
- // lib/generate-id.ts
388
+ // lib/data/for-each-slot.ts
403
389
  init_react_import();
404
- var import_uuid = require("uuid");
405
- var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
406
390
 
407
- // lib/walk-tree.ts
408
- init_react_import();
409
-
410
- // lib/for-each-slot.ts
411
- init_react_import();
412
-
413
- // lib/is-slot.ts
391
+ // lib/data/is-slot.ts
414
392
  init_react_import();
415
393
  var isSlot = (prop) => {
416
394
  var _a, _b;
@@ -423,8 +401,8 @@ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
423
401
  return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
424
402
  };
425
403
 
426
- // lib/for-each-slot.ts
427
- var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, cb, recursive = false, isSlot2 = isSlot) {
404
+ // lib/data/for-each-slot.ts
405
+ var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
428
406
  const props = item.props || {};
429
407
  const propKeys = Object.keys(props);
430
408
  for (let i = 0; i < propKeys.length; i++) {
@@ -432,19 +410,19 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
432
410
  const itemType = "type" in item ? item.type : "root";
433
411
  if (isSlot2(itemType, propKey, props[propKey])) {
434
412
  const content = props[propKey];
435
- yield cb(props.id, propKey, content);
413
+ cb(props.id, propKey, content);
436
414
  if (recursive) {
437
415
  content.forEach(
438
416
  (childItem) => __async(void 0, null, function* () {
439
- return yield forEachSlot(childItem, cb, true, isSlot2);
417
+ return forEachSlot(childItem, cb, true, isSlot2);
440
418
  })
441
419
  );
442
420
  }
443
421
  }
444
422
  }
445
- });
423
+ };
446
424
 
447
- // lib/for-related-zones.ts
425
+ // lib/data/for-related-zones.ts
448
426
  init_react_import();
449
427
 
450
428
  // lib/get-zone-id.ts
@@ -459,19 +437,17 @@ var getZoneId = (zoneCompound) => {
459
437
  return [rootDroppableId, zoneCompound];
460
438
  };
461
439
 
462
- // lib/for-related-zones.ts
440
+ // lib/data/for-related-zones.ts
463
441
  function forRelatedZones(item, data, cb, path = []) {
464
442
  Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
465
443
  const [parentId] = getZoneId(zoneCompound);
466
444
  if (parentId === item.props.id) {
467
- const newPath = [...path, zoneCompound];
468
- content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
469
445
  cb(path, zoneCompound, content);
470
446
  }
471
447
  });
472
448
  }
473
449
 
474
- // lib/strip-slots.ts
450
+ // lib/data/strip-slots.ts
475
451
  init_react_import();
476
452
  var stripSlots = (data) => {
477
453
  return __spreadProps(__spreadValues({}, data), {
@@ -487,7 +463,7 @@ var stripSlots = (data) => {
487
463
  });
488
464
  };
489
465
 
490
- // lib/walk-tree.ts
466
+ // lib/data/walk-tree.ts
491
467
  function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
492
468
  var _a;
493
469
  let newZones = {};
@@ -529,7 +505,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
529
505
  const mappedItem = mapNodeOrSkip(item, path, index);
530
506
  if (!mappedItem) return item;
531
507
  const id = mappedItem.props.id;
532
- processRelatedZones(item, id, path);
533
508
  const newProps = __spreadValues({}, mappedItem.props);
534
509
  forEachSlot(
535
510
  mappedItem,
@@ -547,6 +522,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
547
522
  false,
548
523
  createIsSlotConfig(config)
549
524
  );
525
+ processRelatedZones(item, id, path);
550
526
  const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
551
527
  const thisZoneCompound = path[path.length - 1];
552
528
  const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
@@ -601,7 +577,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
601
577
  return __spreadProps(__spreadValues({}, state), {
602
578
  data: {
603
579
  root,
604
- // 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.
605
580
  content: processedContent,
606
581
  zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
607
582
  },
@@ -612,18 +587,51 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
612
587
  });
613
588
  }
614
589
 
615
- // reducer/reduce.ts
616
- var zoneCache = {};
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."
599
+ );
600
+ return walkTree(newState, appStore.config);
601
+ }
602
+ return __spreadValues(__spreadValues({}, state), action.state(state));
603
+ };
604
+
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();
617
623
  var getIdsForParent = (zoneCompound, state) => {
618
624
  const [parentId] = zoneCompound.split(":");
619
625
  const node = state.indexes.nodes[parentId];
620
626
  return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
621
627
  };
622
- function insertAction(state, action, config) {
628
+
629
+ // reducer/actions/insert.ts
630
+ function insertAction(state, action, appStore) {
623
631
  const id = action.id || generateId(action.componentType);
624
632
  const emptyComponentData = {
625
633
  type: action.componentType,
626
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
634
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
627
635
  id
628
636
  })
629
637
  };
@@ -631,7 +639,7 @@ function insertAction(state, action, config) {
631
639
  const idsInPath = getIdsForParent(action.destinationZone, state);
632
640
  return walkTree(
633
641
  state,
634
- config,
642
+ appStore.config,
635
643
  (content, zoneCompound) => {
636
644
  if (zoneCompound === action.destinationZone) {
637
645
  return insert(
@@ -654,6 +662,141 @@ function insertAction(state, action, config) {
654
662
  }
655
663
  );
656
664
  }
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
+ }
678
+ return walkTree(
679
+ state,
680
+ appStore.config,
681
+ (content, zoneCompound) => {
682
+ const newContent = [...content];
683
+ if (zoneCompound === action.destinationZone) {
684
+ newContent[action.destinationIndex] = action.data;
685
+ }
686
+ return newContent;
687
+ },
688
+ (childItem, path) => {
689
+ const pathIds = path.map((p) => p.split(":")[0]);
690
+ if (childItem.props.id === action.data.props.id) {
691
+ return action.data;
692
+ } else if (childItem.props.id === parentId) {
693
+ return childItem;
694
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
695
+ return childItem;
696
+ } else if (pathIds.indexOf(action.data.props.id) > -1) {
697
+ return childItem;
698
+ }
699
+ return null;
700
+ }
701
+ );
702
+ };
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;
719
+ }
720
+ );
721
+ };
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
+ return childItem;
771
+ }
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
780
+ }
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
657
800
  var moveAction = (state, action, appStore) => {
658
801
  if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
659
802
  return state;
@@ -693,57 +836,26 @@ var moveAction = (state, action, appStore) => {
693
836
  }
694
837
  );
695
838
  };
696
- var replaceAction = (state, action, appStore) => {
697
- const [parentId] = action.destinationZone.split(":");
698
- const idsInPath = getIdsForParent(action.destinationZone, state);
699
- const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
700
- const idChanged = originalId !== action.data.props.id;
701
- if (idChanged) {
702
- throw new Error(
703
- `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
704
- );
705
- }
706
- return walkTree(
839
+
840
+ // reducer/actions/reorder.ts
841
+ var reorderAction = (state, action, appStore) => {
842
+ return moveAction(
707
843
  state,
708
- appStore.config,
709
- (content, zoneCompound) => {
710
- const newContent = [...content];
711
- if (zoneCompound === action.destinationZone) {
712
- newContent[action.destinationIndex] = action.data;
713
- }
714
- return newContent;
844
+ {
845
+ type: "move",
846
+ sourceIndex: action.sourceIndex,
847
+ sourceZone: action.destinationZone,
848
+ destinationIndex: action.destinationIndex,
849
+ destinationZone: action.destinationZone
715
850
  },
716
- (childItem, path) => {
717
- const pathIds = path.map((p) => p.split(":")[0]);
718
- if (childItem.props.id === action.data.props.id) {
719
- return action.data;
720
- } else if (childItem.props.id === parentId) {
721
- return childItem;
722
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
723
- return childItem;
724
- } else if (pathIds.indexOf(action.data.props.id) > -1) {
725
- return childItem;
726
- }
727
- return null;
728
- }
851
+ appStore
729
852
  );
730
853
  };
731
- var setAction = (state, action, appStore) => {
732
- if (typeof action.state === "object") {
733
- const newState = __spreadValues(__spreadValues({}, state), action.state);
734
- if (action.state.indexes) {
735
- console.warn(
736
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
737
- );
738
- return newState;
739
- }
740
- return walkTree(newState, appStore.config);
741
- }
742
- return __spreadValues(__spreadValues({}, state), action.state(state));
743
- };
854
+
855
+ // reducer/actions/remove.ts
856
+ init_react_import();
744
857
  var removeAction = (state, action, appStore) => {
745
858
  const item = getItem({ index: action.index, zone: action.zone }, state);
746
- const [parentId] = action.zone.split(":");
747
859
  const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
748
860
  (acc, [nodeId, nodeData]) => {
749
861
  const pathIds = nodeData.path.map((p) => p.split(":")[0]);
@@ -762,24 +874,17 @@ var removeAction = (state, action, appStore) => {
762
874
  return remove(content, action.index);
763
875
  }
764
876
  return content;
765
- },
766
- (childItem, path) => {
767
- const parentIds = path.map((p) => p.split(":")[0]);
768
- if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
769
- return childItem;
770
- }
771
- return null;
772
877
  }
773
878
  );
774
879
  Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
775
- const parentId2 = zoneCompound.split(":")[0];
776
- if (nodesToDelete.includes(parentId2) && newState.data.zones) {
880
+ const parentId = zoneCompound.split(":")[0];
881
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
777
882
  delete newState.data.zones[zoneCompound];
778
883
  }
779
884
  });
780
885
  Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
781
- const parentId2 = zoneCompound.split(":")[0];
782
- if (nodesToDelete.includes(parentId2)) {
886
+ const parentId = zoneCompound.split(":")[0];
887
+ if (nodesToDelete.includes(parentId)) {
783
888
  delete newState.indexes.zones[zoneCompound];
784
889
  }
785
890
  });
@@ -788,168 +893,89 @@ var removeAction = (state, action, appStore) => {
788
893
  });
789
894
  return newState;
790
895
  };
791
- function reduce(state, action, appStore) {
792
- if (action.type === "set") {
793
- return setAction(state, action, appStore);
794
- }
795
- if (action.type === "insert") {
796
- return insertAction(state, action, appStore.config);
797
- }
798
- if (action.type === "replace") {
799
- return replaceAction(state, action, appStore);
800
- }
801
- if (action.type === "replaceRoot") {
802
- return walkTree(
803
- state,
804
- appStore.config,
805
- (content) => content,
806
- (childItem) => {
807
- if (childItem.props.id === "root") {
808
- return __spreadProps(__spreadValues({}, childItem), {
809
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
810
- readOnly: action.root.readOnly
811
- });
812
- }
813
- return childItem;
814
- }
815
- );
816
- }
817
- if (action.type === "duplicate") {
818
- const item = getItem(
819
- { index: action.sourceIndex, zone: action.sourceZone },
820
- state
821
- );
822
- const idsInPath = getIdsForParent(action.sourceZone, state);
823
- const newItem = __spreadProps(__spreadValues({}, item), {
824
- props: __spreadProps(__spreadValues({}, item.props), {
825
- id: generateId(item.type)
826
- })
827
- });
828
- const modified = walkTree(
829
- state,
830
- appStore.config,
831
- (content, zoneCompound) => {
832
- if (zoneCompound === action.sourceZone) {
833
- return insert(content, action.sourceIndex + 1, item);
834
- }
835
- return content;
836
- },
837
- (childItem, path, index) => {
838
- const zoneCompound = path[path.length - 1];
839
- const parents = path.map((p) => p.split(":")[0]);
840
- if (parents.indexOf(newItem.props.id) > -1) {
841
- return __spreadProps(__spreadValues({}, childItem), {
842
- props: __spreadProps(__spreadValues({}, childItem.props), {
843
- id: generateId(childItem.type)
844
- })
845
- });
846
- }
847
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
848
- return newItem;
849
- }
850
- const [sourceZoneParent] = action.sourceZone.split(":");
851
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
852
- return childItem;
853
- }
854
- return null;
855
- }
856
- );
857
- return __spreadProps(__spreadValues({}, modified), {
858
- ui: __spreadProps(__spreadValues({}, modified.ui), {
859
- itemSelector: {
860
- index: action.sourceIndex + 1,
861
- zone: action.sourceZone
862
- }
863
- })
864
- });
865
- }
866
- if (action.type === "reorder") {
867
- return moveAction(
868
- state,
869
- {
870
- type: "move",
871
- sourceIndex: action.sourceIndex,
872
- sourceZone: action.destinationZone,
873
- destinationIndex: action.destinationIndex,
874
- destinationZone: action.destinationZone
875
- },
876
- appStore
877
- );
878
- }
879
- if (action.type === "move") {
880
- return moveAction(state, action, appStore);
881
- }
882
- if (action.type === "remove") {
883
- return removeAction(state, action, appStore);
884
- }
885
- if (action.type === "registerZone") {
886
- if (zoneCache[action.zone]) {
887
- return __spreadProps(__spreadValues({}, state), {
888
- data: __spreadProps(__spreadValues({}, state.data), {
889
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
890
- [action.zone]: zoneCache[action.zone]
891
- })
892
- }),
893
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
894
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
895
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
896
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
897
- type: "dropzone"
898
- })
899
- })
900
- })
901
- });
902
- }
903
- return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
904
- }
905
- if (action.type === "unregisterZone") {
906
- const _zones = __spreadValues({}, state.data.zones || {});
907
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
908
- if (_zones[action.zone]) {
909
- zoneCache[action.zone] = _zones[action.zone];
910
- delete _zones[action.zone];
911
- }
912
- delete zoneIndex[action.zone];
896
+
897
+ // reducer/actions/register-zone.ts
898
+ init_react_import();
899
+ var zoneCache = {};
900
+ function registerZoneAction(state, action) {
901
+ if (zoneCache[action.zone]) {
913
902
  return __spreadProps(__spreadValues({}, state), {
914
903
  data: __spreadProps(__spreadValues({}, state.data), {
915
- zones: _zones
904
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
905
+ [action.zone]: zoneCache[action.zone]
906
+ })
916
907
  }),
917
908
  indexes: __spreadProps(__spreadValues({}, state.indexes), {
918
- zones: zoneIndex
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
+ })
919
915
  })
920
916
  });
921
917
  }
922
- if (action.type === "setData") {
923
- if (typeof action.data === "object") {
924
- console.warn(
925
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
926
- );
927
- return walkTree(
928
- __spreadProps(__spreadValues({}, state), {
929
- data: __spreadValues(__spreadValues({}, state.data), action.data)
930
- }),
931
- appStore.config
932
- );
933
- }
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
+ );
934
945
  return walkTree(
935
946
  __spreadProps(__spreadValues({}, state), {
936
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
947
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
937
948
  }),
938
949
  appStore.config
939
950
  );
940
951
  }
941
- if (action.type === "setUi") {
942
- if (typeof action.ui === "object") {
943
- return __spreadProps(__spreadValues({}, state), {
944
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
945
- });
946
- }
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") {
947
964
  return __spreadProps(__spreadValues({}, state), {
948
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
965
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
949
966
  });
950
967
  }
951
- return state;
952
- }
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
+ };
953
979
 
954
980
  // reducer/actions.tsx
955
981
  init_react_import();
@@ -968,7 +994,7 @@ function storeInterceptor(reducer, record, onAction) {
968
994
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
969
995
  if (record) record(newAppState);
970
996
  }
971
- onAction == null ? void 0 : onAction(action, newAppState, state);
997
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
972
998
  return newAppState;
973
999
  };
974
1000
  }
@@ -979,8 +1005,43 @@ function createReducer({
979
1005
  }) {
980
1006
  return storeInterceptor(
981
1007
  (state, action) => {
982
- const result = reduce(state, action, appStore);
983
- return result;
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;
984
1045
  },
985
1046
  record,
986
1047
  onAction
@@ -1106,7 +1167,7 @@ var createHistorySlice = (set, get) => {
1106
1167
  const { dispatch, history } = get();
1107
1168
  dispatch({
1108
1169
  type: "set",
1109
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1170
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1110
1171
  });
1111
1172
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1112
1173
  },
@@ -1155,7 +1216,7 @@ var createNodesSlice = (set, get) => ({
1155
1216
  init_react_import();
1156
1217
  var import_react7 = require("react");
1157
1218
 
1158
- // lib/flatten-data.ts
1219
+ // lib/data/flatten-data.ts
1159
1220
  init_react_import();
1160
1221
  var flattenData = (state, config) => {
1161
1222
  const data = [];
@@ -1190,12 +1251,7 @@ var createPermissionsSlice = (set, get) => {
1190
1251
  const { cache: cache2, globalPermissions } = permissions;
1191
1252
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1192
1253
  var _a, _b, _c;
1193
- const {
1194
- config: config2,
1195
- state: appState,
1196
- setComponentLoading,
1197
- unsetComponentLoading
1198
- } = get();
1254
+ const { config: config2, state: appState, setComponentLoading } = get();
1199
1255
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1200
1256
  if (!componentConfig) {
1201
1257
  return;
@@ -1204,14 +1260,14 @@ var createPermissionsSlice = (set, get) => {
1204
1260
  if (componentConfig.resolvePermissions) {
1205
1261
  const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1206
1262
  if (Object.values(changed).some((el) => el === true) || force2) {
1207
- setComponentLoading(item2.props.id);
1263
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1208
1264
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1209
1265
  item2,
1210
1266
  {
1211
1267
  changed,
1212
1268
  lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1213
1269
  permissions: initialPermissions,
1214
- appState,
1270
+ appState: makeStatePublic(appState),
1215
1271
  lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1216
1272
  }
1217
1273
  );
@@ -1229,7 +1285,7 @@ var createPermissionsSlice = (set, get) => {
1229
1285
  })
1230
1286
  })
1231
1287
  });
1232
- unsetComponentLoading(item2.props.id);
1288
+ clearTimeout2();
1233
1289
  }
1234
1290
  }
1235
1291
  });
@@ -1239,7 +1295,7 @@ var createPermissionsSlice = (set, get) => {
1239
1295
  // Shim the root data in by conforming to component data shape
1240
1296
  {
1241
1297
  type: "root",
1242
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1298
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1243
1299
  },
1244
1300
  force2
1245
1301
  );
@@ -1254,7 +1310,6 @@ var createPermissionsSlice = (set, get) => {
1254
1310
  } else if (root) {
1255
1311
  resolveDataForRoot(force);
1256
1312
  } else {
1257
- resolveDataForRoot(force);
1258
1313
  flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1259
1314
  yield resolveDataForItem(item2, force);
1260
1315
  }));
@@ -1285,7 +1340,7 @@ var createPermissionsSlice = (set, get) => {
1285
1340
  } else if (root) {
1286
1341
  const rootConfig = config.root;
1287
1342
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1288
- const resolvedForItem = resolvedPermissions["puck-root"];
1343
+ const resolvedForItem = resolvedPermissions["root"];
1289
1344
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1290
1345
  }
1291
1346
  return globalPermissions;
@@ -1309,24 +1364,25 @@ var createFieldsSlice = (_set, _get) => {
1309
1364
  // lib/resolve-component-data.ts
1310
1365
  init_react_import();
1311
1366
 
1312
- // lib/map-slots.ts
1367
+ // lib/data/map-slots.ts
1313
1368
  init_react_import();
1314
- function mapSlots(item, map, recursive = true, isSlot2) {
1315
- return __async(this, null, function* () {
1369
+ function mapSlotsAsync(_0, _1) {
1370
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
1316
1371
  const props = __spreadValues({}, item.props);
1317
- yield forEachSlot(
1318
- item,
1319
- (_parentId, propName, content) => __async(this, null, function* () {
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];
1320
1378
  const mappedContent = recursive ? yield Promise.all(
1321
1379
  content.map((item2) => __async(this, null, function* () {
1322
- return yield mapSlots(item2, map, recursive, isSlot2);
1380
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
1323
1381
  }))
1324
1382
  ) : content;
1325
- props[propName] = yield map(mappedContent, propName);
1326
- }),
1327
- false,
1328
- isSlot2
1329
- );
1383
+ props[propKey] = yield map(mappedContent, propKey);
1384
+ }
1385
+ }
1330
1386
  return __spreadProps(__spreadValues({}, item), { props });
1331
1387
  });
1332
1388
  }
@@ -1349,14 +1405,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1349
1405
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1350
1406
  changed,
1351
1407
  lastData: oldItem,
1352
- metadata,
1408
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1353
1409
  trigger
1354
1410
  });
1355
1411
  let resolvedItem = __spreadProps(__spreadValues({}, item), {
1356
1412
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1357
1413
  });
1358
1414
  if (recursive) {
1359
- resolvedItem = yield mapSlots(
1415
+ resolvedItem = yield mapSlotsAsync(
1360
1416
  resolvedItem,
1361
1417
  (content) => __async(void 0, null, function* () {
1362
1418
  return Promise.all(
@@ -1394,7 +1450,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1394
1450
  return { node: item, didChange: false };
1395
1451
  });
1396
1452
 
1397
- // lib/to-root.ts
1453
+ // lib/data/to-root.ts
1398
1454
  init_react_import();
1399
1455
  var toRoot = (item) => {
1400
1456
  if ("type" in item && item.type !== "root") {
@@ -1441,166 +1497,176 @@ var defaultPageFields = {
1441
1497
  title: { type: "text" }
1442
1498
  };
1443
1499
  var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
1444
- (0, import_middleware2.subscribeWithSelector)((set, get) => __spreadProps(__spreadValues({
1445
- state: defaultAppState,
1446
- config: { components: {} },
1447
- componentState: {},
1448
- plugins: [],
1449
- overrides: {},
1450
- viewports: defaultViewports,
1451
- zoomConfig: {
1452
- autoZoom: 1,
1453
- rootHeight: 0,
1454
- zoom: 1
1455
- },
1456
- status: "LOADING",
1457
- iframe: {},
1458
- metadata: {}
1459
- }, initialAppStore), {
1460
- fields: createFieldsSlice(set, get),
1461
- history: createHistorySlice(set, get),
1462
- nodes: createNodesSlice(set, get),
1463
- permissions: createPermissionsSlice(set, get),
1464
- getComponentConfig: (type) => {
1465
- var _a;
1466
- const { config, selectedItem } = get();
1467
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1468
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1469
- },
1470
- dispatch: (action) => set((s) => {
1471
- var _a, _b;
1472
- const { record } = get().history;
1473
- const dispatch = createReducer({
1474
- record,
1475
- appStore: s
1476
- });
1477
- const state = dispatch(s.state, action);
1478
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1479
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1480
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1481
- }),
1482
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1483
- setStatus: (status) => set({ status }),
1484
- setComponentState: (componentState) => set({ componentState }),
1485
- pendingComponentLoads: {},
1486
- setComponentLoading: (id, loading = true, defer = 0) => {
1487
- const { setComponentState, pendingComponentLoads } = get();
1488
- const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1489
- const setLoading = () => {
1490
- var _a;
1491
- const { componentState } = get();
1492
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1493
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1494
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1495
- })
1496
- }));
1497
- };
1498
- const unsetLoading = () => {
1499
- var _a;
1500
- const { componentState } = get();
1501
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1502
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1503
- loadingCount: Math.max(
1504
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1505
- 0
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
- if (thisPendingComponentLoads[id]) {
1511
- clearTimeout(thisPendingComponentLoads[id]);
1512
- delete thisPendingComponentLoads[id];
1513
- set({ pendingComponentLoads: thisPendingComponentLoads });
1514
- }
1515
- const timeout2 = setTimeout(() => {
1516
- if (loading) {
1517
- setLoading();
1518
- } else {
1519
- unsetLoading();
1520
- }
1521
- delete thisPendingComponentLoads[id];
1522
- set({ pendingComponentLoads: thisPendingComponentLoads });
1523
- }, defer);
1524
- set({
1525
- pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1526
- [id]: timeout2
1527
- })
1528
- });
1529
- },
1530
- unsetComponentLoading: (id) => {
1531
- const { setComponentLoading } = get();
1532
- setComponentLoading(id, false);
1533
- },
1534
- // Helper
1535
- setUi: (ui, recordHistory) => set((s) => {
1536
- const dispatch = createReducer({
1537
- record: () => {
1538
- },
1539
- appStore: s
1540
- });
1541
- const state = dispatch(s.state, {
1542
- type: "setUi",
1543
- ui,
1544
- recordHistory
1545
- });
1546
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1547
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1548
- }),
1549
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1550
- const { config, metadata, setComponentLoading } = get();
1551
- return yield resolveComponentData(
1552
- componentData,
1553
- config,
1554
- metadata,
1555
- (item) => setComponentLoading(
1556
- "id" in item.props ? item.props.id : "root",
1557
- true,
1558
- 50
1559
- ),
1560
- (item) => setComponentLoading(
1561
- "id" in item.props ? item.props.id : "root",
1562
- false,
1563
- 0
1564
- ),
1565
- trigger
1566
- );
1567
- }),
1568
- resolveAndCommitData: () => __async(void 0, null, function* () {
1569
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1570
- walkTree(
1571
- state,
1572
- config,
1573
- (content) => content,
1574
- (childItem) => {
1575
- resolveComponentData2(childItem, "load").then((resolved) => {
1576
- const { state: state2 } = get();
1577
- const node = state2.indexes.nodes[resolved.node.props.id];
1578
- if (node && resolved.didChange) {
1579
- if (resolved.node.props.id === "root") {
1580
- dispatch({
1581
- type: "replaceRoot",
1582
- root: toRoot(resolved.node)
1583
- });
1584
- } else {
1585
- const zoneCompound = `${node.parentId}:${node.zone}`;
1586
- const parentZone = state2.indexes.zones[zoneCompound];
1587
- const index = parentZone.contentIds.indexOf(
1588
- resolved.node.props.id
1589
- );
1590
- dispatch({
1591
- type: "replace",
1592
- data: resolved.node,
1593
- destinationIndex: index,
1594
- destinationZone: zoneCompound
1595
- });
1596
- }
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 });
1597
1627
  }
1598
- });
1599
- return childItem;
1600
- }
1601
- );
1602
- })
1603
- }))
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
+ })
1604
1670
  );
1605
1671
  var appStoreContext = (0, import_react9.createContext)(createAppStore());
1606
1672
  function useAppStore(selector) {
@@ -1620,10 +1686,10 @@ init_react_import();
1620
1686
  // lib/filter.ts
1621
1687
  init_react_import();
1622
1688
 
1623
- // lib/reorder.ts
1689
+ // lib/data/reorder.ts
1624
1690
  init_react_import();
1625
1691
 
1626
- // lib/replace.ts
1692
+ // lib/data/replace.ts
1627
1693
  init_react_import();
1628
1694
 
1629
1695
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
@@ -2106,7 +2172,6 @@ var DropZoneProvider = ({
2106
2172
  value
2107
2173
  }) => {
2108
2174
  const [hoveringComponent, setHoveringComponent] = (0, import_react11.useState)();
2109
- const [activeZones, setActiveZones] = (0, import_react11.useState)({});
2110
2175
  const dispatch = useAppStore((s) => s.dispatch);
2111
2176
  const registerZone = (0, import_react11.useCallback)(
2112
2177
  (zoneCompound) => {
@@ -2115,7 +2180,7 @@ var DropZoneProvider = ({
2115
2180
  zone: zoneCompound
2116
2181
  });
2117
2182
  },
2118
- [setActiveZones, dispatch]
2183
+ [dispatch]
2119
2184
  );
2120
2185
  const unregisterZone = (0, import_react11.useCallback)(
2121
2186
  (zoneCompound) => {
@@ -2124,17 +2189,16 @@ var DropZoneProvider = ({
2124
2189
  zone: zoneCompound
2125
2190
  });
2126
2191
  },
2127
- [setActiveZones, dispatch]
2192
+ [dispatch]
2128
2193
  );
2129
2194
  const memoValue = (0, import_react11.useMemo)(
2130
2195
  () => __spreadValues({
2131
2196
  hoveringComponent,
2132
2197
  setHoveringComponent,
2133
2198
  registerZone,
2134
- unregisterZone,
2135
- activeZones
2199
+ unregisterZone
2136
2200
  }, value),
2137
- [value, hoveringComponent, activeZones]
2201
+ [value, hoveringComponent]
2138
2202
  );
2139
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 }) });
2140
2204
  };
@@ -2227,8 +2291,10 @@ var DraggableComponent = ({
2227
2291
  return (_a = s.state.indexes.nodes[id]) == null ? void 0 : _a.path;
2228
2292
  }));
2229
2293
  const permissions = useAppStore(
2230
- (0, import_shallow2.useShallow)((s) => s.permissions.getPermissions())
2231
- // TODO call using id
2294
+ (0, import_shallow2.useShallow)((s) => {
2295
+ const item = getItem({ index, zone: zoneCompound }, s.state);
2296
+ return s.permissions.getPermissions({ item });
2297
+ })
2232
2298
  );
2233
2299
  const userIsDragging = useContextStore(
2234
2300
  ZoneStoreContext,
@@ -2482,76 +2548,82 @@ var DraggableComponent = ({
2482
2548
  setDragAxis(autoDragAxis);
2483
2549
  }, [ref, userDragAxis, autoDragAxis]);
2484
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 }) });
2485
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2486
- DropZoneProvider,
2487
- {
2488
- value: __spreadProps(__spreadValues({}, ctx), {
2489
- areaId: id,
2490
- zoneCompound,
2491
- index,
2492
- depth: depth + 1,
2493
- registerLocalZone,
2494
- unregisterLocalZone
2495
- }),
2496
- children: [
2497
- isVisible && (0, import_react_dom.createPortal)(
2498
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2499
- "div",
2500
- {
2501
- className: getClassName3({
2502
- isSelected,
2503
- isDragging: thisIsDragging,
2504
- hover: hover || indicativeHover
2505
- }),
2506
- style: __spreadValues({}, style),
2507
- "data-puck-overlay": true,
2508
- children: [
2509
- debug,
2510
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Loader, {}) }),
2511
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
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)(
2512
2593
  "div",
2513
2594
  {
2514
- className: getClassName3("actionsOverlay"),
2595
+ className: getClassName3("actions"),
2515
2596
  style: {
2516
- top: actionsOverlayTop / zoom
2597
+ transform: `scale(${1 / zoom}`,
2598
+ top: actionsTop / zoom,
2599
+ right: 0,
2600
+ paddingLeft: actionsSide,
2601
+ paddingRight: actionsSide
2517
2602
  },
2518
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2519
- "div",
2603
+ ref: syncActionsPosition,
2604
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2605
+ CustomActionBar,
2520
2606
  {
2521
- className: getClassName3("actions"),
2522
- style: {
2523
- transform: `scale(${1 / zoom}`,
2524
- top: actionsTop / zoom,
2525
- right: 0,
2526
- paddingLeft: actionsSide,
2527
- paddingRight: actionsSide
2528
- },
2529
- ref: syncActionsPosition,
2530
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2531
- CustomActionBar,
2532
- {
2533
- parentAction,
2534
- label: DEBUG2 ? id : label,
2535
- children: [
2536
- permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Copy, { size: 16 }) }),
2537
- permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Trash, { size: 16 }) })
2538
- ]
2539
- }
2540
- )
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
+ ]
2541
2613
  }
2542
2614
  )
2543
2615
  }
2544
- ),
2545
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("overlay") })
2546
- ]
2547
- }
2548
- ),
2549
- portalEl || document.body
2550
- ),
2551
- children(refSetter)
2552
- ]
2553
- }
2554
- );
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
+ ] });
2555
2627
  };
2556
2628
 
2557
2629
  // css-module:/home/runner/work/puck/puck/packages/core/components/DropZone/styles.module.css#css-module
@@ -3250,14 +3322,8 @@ var DropZoneChild = ({
3250
3322
  }) => {
3251
3323
  var _a, _b;
3252
3324
  const metadata = useAppStore((s) => s.metadata);
3253
- const puckProps = {
3254
- renderDropZone: DropZoneEditPure,
3255
- isEditing: true,
3256
- dragRef: null,
3257
- metadata
3258
- };
3259
3325
  const ctx = (0, import_react25.useContext)(dropZoneContext);
3260
- const { depth } = ctx;
3326
+ const { depth = 1 } = ctx != null ? ctx : {};
3261
3327
  const nodeProps = useAppStore(
3262
3328
  (0, import_shallow3.useShallow)((s) => {
3263
3329
  var _a2;
@@ -3270,11 +3336,23 @@ var DropZoneChild = ({
3270
3336
  return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.type;
3271
3337
  }
3272
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
+ );
3273
3345
  const node = { type: nodeType, props: nodeProps };
3274
3346
  const item = nodeProps ? node : (preview == null ? void 0 : preview.componentType) ? { type: preview.componentType, props: preview.props } : null;
3275
3347
  const componentConfig = useAppStore(
3276
3348
  (s) => (item == null ? void 0 : item.type) ? s.config.components[item.type] : null
3277
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
+ };
3278
3356
  const overrides = useAppStore((s) => s.overrides);
3279
3357
  const isLoading = useAppStore(
3280
3358
  (s) => {
@@ -3306,7 +3384,10 @@ var DropZoneChild = ({
3306
3384
  const defaultedPropsWithSlots = useSlots(
3307
3385
  componentConfig,
3308
3386
  defaultsProps,
3309
- DropZoneEditPure
3387
+ DropZoneEditPure,
3388
+ (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ContextSlotRender, { componentId, zone: slotProps.zone }),
3389
+ nodeReadOnly,
3390
+ isLoading
3310
3391
  );
3311
3392
  if (!item) return;
3312
3393
  let Render2 = componentConfig ? componentConfig.render : () => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { padding: 48, textAlign: "center" }, children: [
@@ -3344,6 +3425,7 @@ var DropZoneChild = ({
3344
3425
  }
3345
3426
  );
3346
3427
  };
3428
+ var DropZoneChildMemo = (0, import_react25.memo)(DropZoneChild);
3347
3429
  var DropZoneEdit = (0, import_react25.forwardRef)(
3348
3430
  function DropZoneEditInternal({
3349
3431
  zone,
@@ -3358,10 +3440,10 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
3358
3440
  const {
3359
3441
  // These all need setting via context
3360
3442
  areaId,
3361
- depth,
3443
+ depth = 0,
3362
3444
  registerLocalZone,
3363
3445
  unregisterLocalZone
3364
- } = ctx;
3446
+ } = ctx != null ? ctx : {};
3365
3447
  const path = useAppStore(
3366
3448
  (0, import_shallow3.useShallow)((s) => {
3367
3449
  var _a;
@@ -3403,6 +3485,11 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
3403
3485
  );
3404
3486
  (0, import_react25.useEffect)(() => {
3405
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
+ }
3406
3493
  if (ctx == null ? void 0 : ctx.registerZone) {
3407
3494
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
3408
3495
  }
@@ -3508,7 +3595,7 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
3508
3595
  }),
3509
3596
  children: contentIdsWithPreview.map((componentId, i) => {
3510
3597
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3511
- DropZoneChild,
3598
+ DropZoneChildMemo,
3512
3599
  {
3513
3600
  zoneCompound,
3514
3601
  componentId,
@@ -3526,6 +3613,30 @@ var DropZoneEdit = (0, import_react25.forwardRef)(
3526
3613
  );
3527
3614
  }
3528
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
+ };
3529
3640
  var DropZoneRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneRender, __spreadValues({}, props));
3530
3641
  var DropZoneRender = (0, import_react25.forwardRef)(
3531
3642
  function DropZoneRenderInternal({ className, style, zone }, ref) {
@@ -3556,31 +3667,14 @@ var DropZoneRender = (0, import_react25.forwardRef)(
3556
3667
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className, style, ref, children: content.map((item) => {
3557
3668
  const Component = config.components[item.type];
3558
3669
  if (Component) {
3559
- const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3560
- SlotRenderPure,
3561
- __spreadProps(__spreadValues({}, slotProps), {
3562
- config,
3563
- metadata
3564
- })
3565
- ));
3566
3670
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3567
- DropZoneProvider,
3671
+ DropZoneRenderItem,
3568
3672
  {
3569
- value: {
3570
- areaId: props.id,
3571
- depth: 1
3572
- },
3573
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3574
- Component.render,
3575
- __spreadProps(__spreadValues({}, props), {
3576
- puck: {
3577
- renderDropZone: DropZoneRenderPure,
3578
- metadata: metadata || {}
3579
- }
3580
- })
3581
- )
3673
+ config,
3674
+ item,
3675
+ metadata
3582
3676
  },
3583
- props.id
3677
+ item.props.id
3584
3678
  );
3585
3679
  }
3586
3680
  return null;
@@ -3600,30 +3694,60 @@ var DropZone = (0, import_react25.forwardRef)(
3600
3694
  // components/SlotRender/index.tsx
3601
3695
  var import_jsx_runtime10 = require("react/jsx-runtime");
3602
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
+ };
3603
3736
  var SlotRender = (0, import_react26.forwardRef)(
3604
3737
  function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
3605
3738
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className, style, ref, children: content.map((item) => {
3606
- const Component = config.components[item.type];
3607
- if (Component) {
3608
- const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3609
- SlotRenderPure,
3610
- __spreadProps(__spreadValues({}, slotProps), {
3611
- config,
3612
- metadata
3613
- })
3614
- ));
3615
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3616
- Component.render,
3617
- __spreadProps(__spreadValues({}, props), {
3618
- puck: {
3619
- renderDropZone: DropZoneRenderPure,
3620
- metadata: metadata || {}
3621
- }
3622
- }),
3623
- props.id
3624
- );
3739
+ if (!config.components[item.type]) {
3740
+ return null;
3625
3741
  }
3626
- return null;
3742
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3743
+ Item,
3744
+ {
3745
+ config,
3746
+ item,
3747
+ metadata
3748
+ },
3749
+ item.props.id
3750
+ );
3627
3751
  }) });
3628
3752
  }
3629
3753
  );
@@ -3723,14 +3847,14 @@ function Render({
3723
3847
  // lib/resolve-all-data.ts
3724
3848
  init_react_import();
3725
3849
 
3726
- // lib/default-data.ts
3850
+ // lib/data/default-data.ts
3727
3851
  init_react_import();
3728
3852
  var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
3729
3853
  root: data.root || {},
3730
3854
  content: data.content || []
3731
3855
  });
3732
3856
 
3733
- // lib/to-component.ts
3857
+ // lib/data/to-component.ts
3734
3858
  init_react_import();
3735
3859
  var toComponent = (item) => {
3736
3860
  return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
@@ -3758,17 +3882,29 @@ function resolveAllData(_0, _1) {
3758
3882
  "force",
3759
3883
  false
3760
3884
  )).node;
3761
- const resolvedDeep = yield mapSlots(resolved, processContent, false);
3885
+ const resolvedDeep = yield mapSlotsAsync(
3886
+ resolved,
3887
+ processContent,
3888
+ false
3889
+ );
3762
3890
  onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
3763
3891
  return resolvedDeep;
3764
3892
  });
3765
3893
  const processContent = (content) => __async(this, null, function* () {
3766
3894
  return Promise.all(content.map(resolveNode));
3767
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
+ });
3768
3904
  const dynamic = {
3769
3905
  root: yield resolveNode(defaultedData.root),
3770
3906
  content: yield processContent(defaultedData.content),
3771
- zones: {}
3907
+ zones: yield processZones()
3772
3908
  };
3773
3909
  Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
3774
3910
  const content = defaultedData.zones[zoneKey];