@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/README.md +1 -0
- package/dist/{chunk-6SCV2ENX.mjs → chunk-ZOHJNF5K.mjs} +812 -661
- package/dist/index.css +44 -38
- package/dist/index.d.mts +18 -8
- package/dist/index.d.ts +18 -8
- package/dist/index.js +912 -712
- 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 +718 -582
- package/dist/rsc.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -176,6 +176,7 @@ __export(core_exports, {
|
|
176
176
|
Puck: () => Puck,
|
177
177
|
Render: () => Render,
|
178
178
|
createUsePuck: () => createUsePuck,
|
179
|
+
mapSlots: () => mapSlotsPublic,
|
179
180
|
migrate: () => migrate,
|
180
181
|
overrideKeys: () => overrideKeys,
|
181
182
|
renderContext: () => renderContext,
|
@@ -308,7 +309,7 @@ init_react_import();
|
|
308
309
|
|
309
310
|
// css-module:/home/runner/work/puck/puck/packages/core/components/AutoField/styles.module.css#css-module
|
310
311
|
init_react_import();
|
311
|
-
var styles_module_default2 = { "InputWrapper": "
|
312
|
+
var styles_module_default2 = { "InputWrapper": "_InputWrapper_4xor1_1", "Input-label": "_Input-label_4xor1_5", "Input-labelIcon": "_Input-labelIcon_4xor1_14", "Input-disabledIcon": "_Input-disabledIcon_4xor1_21", "Input-input": "_Input-input_4xor1_26", "Input": "_Input_4xor1_1", "Input--readOnly": "_Input--readOnly_4xor1_75", "Input-radioGroupItems": "_Input-radioGroupItems_4xor1_86", "Input-radio": "_Input-radio_4xor1_86", "Input-radioInner": "_Input-radioInner_4xor1_103", "Input-radioInput": "_Input-radioInput_4xor1_148" };
|
312
313
|
|
313
314
|
// components/AutoField/index.tsx
|
314
315
|
var import_react22 = require("react");
|
@@ -670,7 +671,7 @@ init_react_import();
|
|
670
671
|
// lib/filter.ts
|
671
672
|
init_react_import();
|
672
673
|
|
673
|
-
// lib/reorder.ts
|
674
|
+
// lib/data/reorder.ts
|
674
675
|
init_react_import();
|
675
676
|
var reorder = (list, startIndex, endIndex) => {
|
676
677
|
const result = Array.from(list);
|
@@ -679,7 +680,7 @@ var reorder = (list, startIndex, endIndex) => {
|
|
679
680
|
return result;
|
680
681
|
};
|
681
682
|
|
682
|
-
// lib/replace.ts
|
683
|
+
// lib/data/replace.ts
|
683
684
|
init_react_import();
|
684
685
|
var replace = (list, index, newItem) => {
|
685
686
|
const result = Array.from(list);
|
@@ -791,66 +792,16 @@ init_react_import();
|
|
791
792
|
// reducer/index.ts
|
792
793
|
init_react_import();
|
793
794
|
|
794
|
-
// reducer/
|
795
|
+
// reducer/actions/set.ts
|
795
796
|
init_react_import();
|
796
797
|
|
797
|
-
// lib/
|
798
|
+
// lib/data/walk-tree.ts
|
798
799
|
init_react_import();
|
799
|
-
var insert = (list, index, item) => {
|
800
|
-
const result = Array.from(list || []);
|
801
|
-
result.splice(index, 0, item);
|
802
|
-
return result;
|
803
|
-
};
|
804
800
|
|
805
|
-
// lib/
|
801
|
+
// lib/data/for-each-slot.ts
|
806
802
|
init_react_import();
|
807
|
-
var remove = (list, index) => {
|
808
|
-
const result = Array.from(list);
|
809
|
-
result.splice(index, 1);
|
810
|
-
return result;
|
811
|
-
};
|
812
803
|
|
813
|
-
// lib/
|
814
|
-
init_react_import();
|
815
|
-
|
816
|
-
// lib/root-droppable-id.ts
|
817
|
-
init_react_import();
|
818
|
-
var rootAreaId = "root";
|
819
|
-
var rootZone = "default-zone";
|
820
|
-
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
821
|
-
|
822
|
-
// lib/setup-zone.ts
|
823
|
-
var setupZone = (data, zoneKey) => {
|
824
|
-
if (zoneKey === rootDroppableId) {
|
825
|
-
return data;
|
826
|
-
}
|
827
|
-
const newData = __spreadProps(__spreadValues({}, data), {
|
828
|
-
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
829
|
-
});
|
830
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
831
|
-
return newData;
|
832
|
-
};
|
833
|
-
|
834
|
-
// lib/get-item.ts
|
835
|
-
init_react_import();
|
836
|
-
function getItem(selector, state) {
|
837
|
-
var _a, _b;
|
838
|
-
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
839
|
-
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
840
|
-
}
|
841
|
-
|
842
|
-
// lib/generate-id.ts
|
843
|
-
init_react_import();
|
844
|
-
var import_uuid = require("uuid");
|
845
|
-
var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
|
846
|
-
|
847
|
-
// lib/walk-tree.ts
|
848
|
-
init_react_import();
|
849
|
-
|
850
|
-
// lib/for-each-slot.ts
|
851
|
-
init_react_import();
|
852
|
-
|
853
|
-
// lib/is-slot.ts
|
804
|
+
// lib/data/is-slot.ts
|
854
805
|
init_react_import();
|
855
806
|
var isSlot = (prop) => {
|
856
807
|
var _a, _b;
|
@@ -863,8 +814,8 @@ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
|
863
814
|
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
864
815
|
};
|
865
816
|
|
866
|
-
// lib/for-each-slot.ts
|
867
|
-
var forEachSlot = (
|
817
|
+
// lib/data/for-each-slot.ts
|
818
|
+
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
868
819
|
const props = item.props || {};
|
869
820
|
const propKeys = Object.keys(props);
|
870
821
|
for (let i = 0; i < propKeys.length; i++) {
|
@@ -872,23 +823,31 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
|
|
872
823
|
const itemType = "type" in item ? item.type : "root";
|
873
824
|
if (isSlot2(itemType, propKey, props[propKey])) {
|
874
825
|
const content = props[propKey];
|
875
|
-
|
826
|
+
cb(props.id, propKey, content);
|
876
827
|
if (recursive) {
|
877
828
|
content.forEach(
|
878
829
|
(childItem) => __async(void 0, null, function* () {
|
879
|
-
return
|
830
|
+
return forEachSlot(childItem, cb, true, isSlot2);
|
880
831
|
})
|
881
832
|
);
|
882
833
|
}
|
883
834
|
}
|
884
835
|
}
|
885
|
-
}
|
836
|
+
};
|
886
837
|
|
887
|
-
// lib/for-related-zones.ts
|
838
|
+
// lib/data/for-related-zones.ts
|
888
839
|
init_react_import();
|
889
840
|
|
890
841
|
// lib/get-zone-id.ts
|
891
842
|
init_react_import();
|
843
|
+
|
844
|
+
// lib/root-droppable-id.ts
|
845
|
+
init_react_import();
|
846
|
+
var rootAreaId = "root";
|
847
|
+
var rootZone = "default-zone";
|
848
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
849
|
+
|
850
|
+
// lib/get-zone-id.ts
|
892
851
|
var getZoneId = (zoneCompound) => {
|
893
852
|
if (!zoneCompound) {
|
894
853
|
return [];
|
@@ -899,19 +858,17 @@ var getZoneId = (zoneCompound) => {
|
|
899
858
|
return [rootDroppableId, zoneCompound];
|
900
859
|
};
|
901
860
|
|
902
|
-
// lib/for-related-zones.ts
|
861
|
+
// lib/data/for-related-zones.ts
|
903
862
|
function forRelatedZones(item, data, cb, path = []) {
|
904
863
|
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
905
864
|
const [parentId] = getZoneId(zoneCompound);
|
906
865
|
if (parentId === item.props.id) {
|
907
|
-
const newPath = [...path, zoneCompound];
|
908
|
-
content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
|
909
866
|
cb(path, zoneCompound, content);
|
910
867
|
}
|
911
868
|
});
|
912
869
|
}
|
913
870
|
|
914
|
-
// lib/strip-slots.ts
|
871
|
+
// lib/data/strip-slots.ts
|
915
872
|
init_react_import();
|
916
873
|
var stripSlots = (data) => {
|
917
874
|
return __spreadProps(__spreadValues({}, data), {
|
@@ -927,7 +884,7 @@ var stripSlots = (data) => {
|
|
927
884
|
});
|
928
885
|
};
|
929
886
|
|
930
|
-
// lib/walk-tree.ts
|
887
|
+
// lib/data/walk-tree.ts
|
931
888
|
function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
932
889
|
var _a;
|
933
890
|
let newZones = {};
|
@@ -969,7 +926,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
969
926
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
970
927
|
if (!mappedItem) return item;
|
971
928
|
const id = mappedItem.props.id;
|
972
|
-
processRelatedZones(item, id, path);
|
973
929
|
const newProps = __spreadValues({}, mappedItem.props);
|
974
930
|
forEachSlot(
|
975
931
|
mappedItem,
|
@@ -987,6 +943,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
987
943
|
false,
|
988
944
|
createIsSlotConfig(config)
|
989
945
|
);
|
946
|
+
processRelatedZones(item, id, path);
|
990
947
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
991
948
|
const thisZoneCompound = path[path.length - 1];
|
992
949
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
@@ -1041,7 +998,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
1041
998
|
return __spreadProps(__spreadValues({}, state), {
|
1042
999
|
data: {
|
1043
1000
|
root,
|
1044
|
-
// 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.
|
1045
1001
|
content: processedContent,
|
1046
1002
|
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
1047
1003
|
},
|
@@ -1052,18 +1008,51 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
1052
1008
|
});
|
1053
1009
|
}
|
1054
1010
|
|
1055
|
-
// reducer/
|
1056
|
-
var
|
1011
|
+
// reducer/actions/set.ts
|
1012
|
+
var setAction = (state, action, appStore) => {
|
1013
|
+
if (typeof action.state === "object") {
|
1014
|
+
const newState = __spreadValues(__spreadValues({}, state), action.state);
|
1015
|
+
if (action.state.indexes) {
|
1016
|
+
return newState;
|
1017
|
+
}
|
1018
|
+
console.warn(
|
1019
|
+
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1020
|
+
);
|
1021
|
+
return walkTree(newState, appStore.config);
|
1022
|
+
}
|
1023
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
1024
|
+
};
|
1025
|
+
|
1026
|
+
// reducer/actions/insert.ts
|
1027
|
+
init_react_import();
|
1028
|
+
|
1029
|
+
// lib/data/insert.ts
|
1030
|
+
init_react_import();
|
1031
|
+
var insert = (list, index, item) => {
|
1032
|
+
const result = Array.from(list || []);
|
1033
|
+
result.splice(index, 0, item);
|
1034
|
+
return result;
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
// lib/generate-id.ts
|
1038
|
+
init_react_import();
|
1039
|
+
var import_uuid = require("uuid");
|
1040
|
+
var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
|
1041
|
+
|
1042
|
+
// lib/data/get-ids-for-parent.ts
|
1043
|
+
init_react_import();
|
1057
1044
|
var getIdsForParent = (zoneCompound, state) => {
|
1058
1045
|
const [parentId] = zoneCompound.split(":");
|
1059
1046
|
const node = state.indexes.nodes[parentId];
|
1060
1047
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
1061
1048
|
};
|
1062
|
-
|
1049
|
+
|
1050
|
+
// reducer/actions/insert.ts
|
1051
|
+
function insertAction(state, action, appStore) {
|
1063
1052
|
const id = action.id || generateId(action.componentType);
|
1064
1053
|
const emptyComponentData = {
|
1065
1054
|
type: action.componentType,
|
1066
|
-
props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
|
1055
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
1067
1056
|
id
|
1068
1057
|
})
|
1069
1058
|
};
|
@@ -1071,7 +1060,7 @@ function insertAction(state, action, config) {
|
|
1071
1060
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
1072
1061
|
return walkTree(
|
1073
1062
|
state,
|
1074
|
-
config,
|
1063
|
+
appStore.config,
|
1075
1064
|
(content, zoneCompound) => {
|
1076
1065
|
if (zoneCompound === action.destinationZone) {
|
1077
1066
|
return insert(
|
@@ -1094,6 +1083,141 @@ function insertAction(state, action, config) {
|
|
1094
1083
|
}
|
1095
1084
|
);
|
1096
1085
|
}
|
1086
|
+
|
1087
|
+
// reducer/actions/replace.ts
|
1088
|
+
init_react_import();
|
1089
|
+
var replaceAction = (state, action, appStore) => {
|
1090
|
+
const [parentId] = action.destinationZone.split(":");
|
1091
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
1092
|
+
const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
|
1093
|
+
const idChanged = originalId !== action.data.props.id;
|
1094
|
+
if (idChanged) {
|
1095
|
+
throw new Error(
|
1096
|
+
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
1097
|
+
);
|
1098
|
+
}
|
1099
|
+
return walkTree(
|
1100
|
+
state,
|
1101
|
+
appStore.config,
|
1102
|
+
(content, zoneCompound) => {
|
1103
|
+
const newContent = [...content];
|
1104
|
+
if (zoneCompound === action.destinationZone) {
|
1105
|
+
newContent[action.destinationIndex] = action.data;
|
1106
|
+
}
|
1107
|
+
return newContent;
|
1108
|
+
},
|
1109
|
+
(childItem, path) => {
|
1110
|
+
const pathIds = path.map((p) => p.split(":")[0]);
|
1111
|
+
if (childItem.props.id === action.data.props.id) {
|
1112
|
+
return action.data;
|
1113
|
+
} else if (childItem.props.id === parentId) {
|
1114
|
+
return childItem;
|
1115
|
+
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
1116
|
+
return childItem;
|
1117
|
+
} else if (pathIds.indexOf(action.data.props.id) > -1) {
|
1118
|
+
return childItem;
|
1119
|
+
}
|
1120
|
+
return null;
|
1121
|
+
}
|
1122
|
+
);
|
1123
|
+
};
|
1124
|
+
|
1125
|
+
// reducer/actions/replace-root.ts
|
1126
|
+
init_react_import();
|
1127
|
+
var replaceRootAction = (state, action, appStore) => {
|
1128
|
+
return walkTree(
|
1129
|
+
state,
|
1130
|
+
appStore.config,
|
1131
|
+
(content) => content,
|
1132
|
+
(childItem) => {
|
1133
|
+
if (childItem.props.id === "root") {
|
1134
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
1135
|
+
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
1136
|
+
readOnly: action.root.readOnly
|
1137
|
+
});
|
1138
|
+
}
|
1139
|
+
return childItem;
|
1140
|
+
}
|
1141
|
+
);
|
1142
|
+
};
|
1143
|
+
|
1144
|
+
// reducer/actions/duplicate.ts
|
1145
|
+
init_react_import();
|
1146
|
+
|
1147
|
+
// lib/data/get-item.ts
|
1148
|
+
init_react_import();
|
1149
|
+
function getItem(selector, state) {
|
1150
|
+
var _a, _b;
|
1151
|
+
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
1152
|
+
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
// reducer/actions/duplicate.ts
|
1156
|
+
function duplicateAction(state, action, appStore) {
|
1157
|
+
const item = getItem(
|
1158
|
+
{ index: action.sourceIndex, zone: action.sourceZone },
|
1159
|
+
state
|
1160
|
+
);
|
1161
|
+
const idsInPath = getIdsForParent(action.sourceZone, state);
|
1162
|
+
const newItem = __spreadProps(__spreadValues({}, item), {
|
1163
|
+
props: __spreadProps(__spreadValues({}, item.props), {
|
1164
|
+
id: generateId(item.type)
|
1165
|
+
})
|
1166
|
+
});
|
1167
|
+
const modified = walkTree(
|
1168
|
+
state,
|
1169
|
+
appStore.config,
|
1170
|
+
(content, zoneCompound) => {
|
1171
|
+
if (zoneCompound === action.sourceZone) {
|
1172
|
+
return insert(content, action.sourceIndex + 1, item);
|
1173
|
+
}
|
1174
|
+
return content;
|
1175
|
+
},
|
1176
|
+
(childItem, path, index) => {
|
1177
|
+
const zoneCompound = path[path.length - 1];
|
1178
|
+
const parents = path.map((p) => p.split(":")[0]);
|
1179
|
+
if (parents.indexOf(newItem.props.id) > -1) {
|
1180
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
1181
|
+
props: __spreadProps(__spreadValues({}, childItem.props), {
|
1182
|
+
id: generateId(childItem.type)
|
1183
|
+
})
|
1184
|
+
});
|
1185
|
+
}
|
1186
|
+
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
1187
|
+
return newItem;
|
1188
|
+
}
|
1189
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
1190
|
+
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
1191
|
+
return childItem;
|
1192
|
+
}
|
1193
|
+
return null;
|
1194
|
+
}
|
1195
|
+
);
|
1196
|
+
return __spreadProps(__spreadValues({}, modified), {
|
1197
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
1198
|
+
itemSelector: {
|
1199
|
+
index: action.sourceIndex + 1,
|
1200
|
+
zone: action.sourceZone
|
1201
|
+
}
|
1202
|
+
})
|
1203
|
+
});
|
1204
|
+
}
|
1205
|
+
|
1206
|
+
// reducer/actions/reorder.ts
|
1207
|
+
init_react_import();
|
1208
|
+
|
1209
|
+
// reducer/actions/move.ts
|
1210
|
+
init_react_import();
|
1211
|
+
|
1212
|
+
// lib/data/remove.ts
|
1213
|
+
init_react_import();
|
1214
|
+
var remove = (list, index) => {
|
1215
|
+
const result = Array.from(list);
|
1216
|
+
result.splice(index, 1);
|
1217
|
+
return result;
|
1218
|
+
};
|
1219
|
+
|
1220
|
+
// reducer/actions/move.ts
|
1097
1221
|
var moveAction = (state, action, appStore) => {
|
1098
1222
|
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
1099
1223
|
return state;
|
@@ -1133,57 +1257,26 @@ var moveAction = (state, action, appStore) => {
|
|
1133
1257
|
}
|
1134
1258
|
);
|
1135
1259
|
};
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
const idChanged = originalId !== action.data.props.id;
|
1141
|
-
if (idChanged) {
|
1142
|
-
throw new Error(
|
1143
|
-
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
1144
|
-
);
|
1145
|
-
}
|
1146
|
-
return walkTree(
|
1260
|
+
|
1261
|
+
// reducer/actions/reorder.ts
|
1262
|
+
var reorderAction = (state, action, appStore) => {
|
1263
|
+
return moveAction(
|
1147
1264
|
state,
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
return newContent;
|
1265
|
+
{
|
1266
|
+
type: "move",
|
1267
|
+
sourceIndex: action.sourceIndex,
|
1268
|
+
sourceZone: action.destinationZone,
|
1269
|
+
destinationIndex: action.destinationIndex,
|
1270
|
+
destinationZone: action.destinationZone
|
1155
1271
|
},
|
1156
|
-
|
1157
|
-
const pathIds = path.map((p) => p.split(":")[0]);
|
1158
|
-
if (childItem.props.id === action.data.props.id) {
|
1159
|
-
return action.data;
|
1160
|
-
} else if (childItem.props.id === parentId) {
|
1161
|
-
return childItem;
|
1162
|
-
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
1163
|
-
return childItem;
|
1164
|
-
} else if (pathIds.indexOf(action.data.props.id) > -1) {
|
1165
|
-
return childItem;
|
1166
|
-
}
|
1167
|
-
return null;
|
1168
|
-
}
|
1272
|
+
appStore
|
1169
1273
|
);
|
1170
1274
|
};
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
if (action.state.indexes) {
|
1175
|
-
console.warn(
|
1176
|
-
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1177
|
-
);
|
1178
|
-
return newState;
|
1179
|
-
}
|
1180
|
-
return walkTree(newState, appStore.config);
|
1181
|
-
}
|
1182
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
1183
|
-
};
|
1275
|
+
|
1276
|
+
// reducer/actions/remove.ts
|
1277
|
+
init_react_import();
|
1184
1278
|
var removeAction = (state, action, appStore) => {
|
1185
1279
|
const item = getItem({ index: action.index, zone: action.zone }, state);
|
1186
|
-
const [parentId] = action.zone.split(":");
|
1187
1280
|
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
1188
1281
|
(acc, [nodeId, nodeData]) => {
|
1189
1282
|
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
@@ -1202,24 +1295,17 @@ var removeAction = (state, action, appStore) => {
|
|
1202
1295
|
return remove(content, action.index);
|
1203
1296
|
}
|
1204
1297
|
return content;
|
1205
|
-
},
|
1206
|
-
(childItem, path) => {
|
1207
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
1208
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
1209
|
-
return childItem;
|
1210
|
-
}
|
1211
|
-
return null;
|
1212
1298
|
}
|
1213
1299
|
);
|
1214
1300
|
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
1215
|
-
const
|
1216
|
-
if (nodesToDelete.includes(
|
1301
|
+
const parentId = zoneCompound.split(":")[0];
|
1302
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
1217
1303
|
delete newState.data.zones[zoneCompound];
|
1218
1304
|
}
|
1219
1305
|
});
|
1220
1306
|
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
1221
|
-
const
|
1222
|
-
if (nodesToDelete.includes(
|
1307
|
+
const parentId = zoneCompound.split(":")[0];
|
1308
|
+
if (nodesToDelete.includes(parentId)) {
|
1223
1309
|
delete newState.indexes.zones[zoneCompound];
|
1224
1310
|
}
|
1225
1311
|
});
|
@@ -1228,168 +1314,104 @@ var removeAction = (state, action, appStore) => {
|
|
1228
1314
|
});
|
1229
1315
|
return newState;
|
1230
1316
|
};
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
if (
|
1239
|
-
return
|
1240
|
-
}
|
1241
|
-
if (action.type === "replaceRoot") {
|
1242
|
-
return walkTree(
|
1243
|
-
state,
|
1244
|
-
appStore.config,
|
1245
|
-
(content) => content,
|
1246
|
-
(childItem) => {
|
1247
|
-
if (childItem.props.id === "root") {
|
1248
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
1249
|
-
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
1250
|
-
readOnly: action.root.readOnly
|
1251
|
-
});
|
1252
|
-
}
|
1253
|
-
return childItem;
|
1254
|
-
}
|
1255
|
-
);
|
1256
|
-
}
|
1257
|
-
if (action.type === "duplicate") {
|
1258
|
-
const item = getItem(
|
1259
|
-
{ index: action.sourceIndex, zone: action.sourceZone },
|
1260
|
-
state
|
1261
|
-
);
|
1262
|
-
const idsInPath = getIdsForParent(action.sourceZone, state);
|
1263
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
1264
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
1265
|
-
id: generateId(item.type)
|
1266
|
-
})
|
1267
|
-
});
|
1268
|
-
const modified = walkTree(
|
1269
|
-
state,
|
1270
|
-
appStore.config,
|
1271
|
-
(content, zoneCompound) => {
|
1272
|
-
if (zoneCompound === action.sourceZone) {
|
1273
|
-
return insert(content, action.sourceIndex + 1, item);
|
1274
|
-
}
|
1275
|
-
return content;
|
1276
|
-
},
|
1277
|
-
(childItem, path, index) => {
|
1278
|
-
const zoneCompound = path[path.length - 1];
|
1279
|
-
const parents = path.map((p) => p.split(":")[0]);
|
1280
|
-
if (parents.indexOf(newItem.props.id) > -1) {
|
1281
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
1282
|
-
props: __spreadProps(__spreadValues({}, childItem.props), {
|
1283
|
-
id: generateId(childItem.type)
|
1284
|
-
})
|
1285
|
-
});
|
1286
|
-
}
|
1287
|
-
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
1288
|
-
return newItem;
|
1289
|
-
}
|
1290
|
-
const [sourceZoneParent] = action.sourceZone.split(":");
|
1291
|
-
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
1292
|
-
return childItem;
|
1293
|
-
}
|
1294
|
-
return null;
|
1295
|
-
}
|
1296
|
-
);
|
1297
|
-
return __spreadProps(__spreadValues({}, modified), {
|
1298
|
-
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
1299
|
-
itemSelector: {
|
1300
|
-
index: action.sourceIndex + 1,
|
1301
|
-
zone: action.sourceZone
|
1302
|
-
}
|
1303
|
-
})
|
1304
|
-
});
|
1305
|
-
}
|
1306
|
-
if (action.type === "reorder") {
|
1307
|
-
return moveAction(
|
1308
|
-
state,
|
1309
|
-
{
|
1310
|
-
type: "move",
|
1311
|
-
sourceIndex: action.sourceIndex,
|
1312
|
-
sourceZone: action.destinationZone,
|
1313
|
-
destinationIndex: action.destinationIndex,
|
1314
|
-
destinationZone: action.destinationZone
|
1315
|
-
},
|
1316
|
-
appStore
|
1317
|
-
);
|
1318
|
-
}
|
1319
|
-
if (action.type === "move") {
|
1320
|
-
return moveAction(state, action, appStore);
|
1321
|
-
}
|
1322
|
-
if (action.type === "remove") {
|
1323
|
-
return removeAction(state, action, appStore);
|
1324
|
-
}
|
1325
|
-
if (action.type === "registerZone") {
|
1326
|
-
if (zoneCache[action.zone]) {
|
1327
|
-
return __spreadProps(__spreadValues({}, state), {
|
1328
|
-
data: __spreadProps(__spreadValues({}, state.data), {
|
1329
|
-
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
1330
|
-
[action.zone]: zoneCache[action.zone]
|
1331
|
-
})
|
1332
|
-
}),
|
1333
|
-
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1334
|
-
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
1335
|
-
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
1336
|
-
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
1337
|
-
type: "dropzone"
|
1338
|
-
})
|
1339
|
-
})
|
1340
|
-
})
|
1341
|
-
});
|
1342
|
-
}
|
1343
|
-
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
1317
|
+
|
1318
|
+
// reducer/actions/register-zone.ts
|
1319
|
+
init_react_import();
|
1320
|
+
|
1321
|
+
// lib/data/setup-zone.ts
|
1322
|
+
init_react_import();
|
1323
|
+
var setupZone = (data, zoneKey) => {
|
1324
|
+
if (zoneKey === rootDroppableId) {
|
1325
|
+
return data;
|
1344
1326
|
}
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1327
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
1328
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
1329
|
+
});
|
1330
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
1331
|
+
return newData;
|
1332
|
+
};
|
1333
|
+
|
1334
|
+
// reducer/actions/register-zone.ts
|
1335
|
+
var zoneCache = {};
|
1336
|
+
function registerZoneAction(state, action) {
|
1337
|
+
if (zoneCache[action.zone]) {
|
1353
1338
|
return __spreadProps(__spreadValues({}, state), {
|
1354
1339
|
data: __spreadProps(__spreadValues({}, state.data), {
|
1355
|
-
zones:
|
1340
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
1341
|
+
[action.zone]: zoneCache[action.zone]
|
1342
|
+
})
|
1356
1343
|
}),
|
1357
1344
|
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1358
|
-
zones:
|
1345
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
1346
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
1347
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
1348
|
+
type: "dropzone"
|
1349
|
+
})
|
1350
|
+
})
|
1359
1351
|
})
|
1360
1352
|
});
|
1361
1353
|
}
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
}
|
1354
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
1355
|
+
}
|
1356
|
+
function unregisterZoneAction(state, action) {
|
1357
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
1358
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
1359
|
+
if (_zones[action.zone]) {
|
1360
|
+
zoneCache[action.zone] = _zones[action.zone];
|
1361
|
+
delete _zones[action.zone];
|
1362
|
+
}
|
1363
|
+
delete zoneIndex[action.zone];
|
1364
|
+
return __spreadProps(__spreadValues({}, state), {
|
1365
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
1366
|
+
zones: _zones
|
1367
|
+
}),
|
1368
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
1369
|
+
zones: zoneIndex
|
1370
|
+
})
|
1371
|
+
});
|
1372
|
+
}
|
1373
|
+
|
1374
|
+
// reducer/actions/set-data.ts
|
1375
|
+
init_react_import();
|
1376
|
+
var setDataAction = (state, action, appStore) => {
|
1377
|
+
if (typeof action.data === "object") {
|
1378
|
+
console.warn(
|
1379
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1380
|
+
);
|
1374
1381
|
return walkTree(
|
1375
1382
|
__spreadProps(__spreadValues({}, state), {
|
1376
|
-
data: __spreadValues(__spreadValues({}, state.data), action.data
|
1383
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1377
1384
|
}),
|
1378
1385
|
appStore.config
|
1379
1386
|
);
|
1380
1387
|
}
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1388
|
+
return walkTree(
|
1389
|
+
__spreadProps(__spreadValues({}, state), {
|
1390
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1391
|
+
}),
|
1392
|
+
appStore.config
|
1393
|
+
);
|
1394
|
+
};
|
1395
|
+
|
1396
|
+
// reducer/actions/set-ui.ts
|
1397
|
+
init_react_import();
|
1398
|
+
var setUiAction = (state, action) => {
|
1399
|
+
if (typeof action.ui === "object") {
|
1387
1400
|
return __spreadProps(__spreadValues({}, state), {
|
1388
|
-
ui: __spreadValues(__spreadValues({}, state.ui), action.ui
|
1401
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
1389
1402
|
});
|
1390
1403
|
}
|
1391
|
-
return state
|
1392
|
-
}
|
1404
|
+
return __spreadProps(__spreadValues({}, state), {
|
1405
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
1406
|
+
});
|
1407
|
+
};
|
1408
|
+
|
1409
|
+
// lib/data/make-state-public.ts
|
1410
|
+
init_react_import();
|
1411
|
+
var makeStatePublic = (state) => {
|
1412
|
+
const { data, ui } = state;
|
1413
|
+
return { data, ui };
|
1414
|
+
};
|
1393
1415
|
|
1394
1416
|
// reducer/actions.tsx
|
1395
1417
|
init_react_import();
|
@@ -1408,7 +1430,7 @@ function storeInterceptor(reducer, record, onAction) {
|
|
1408
1430
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
1409
1431
|
if (record) record(newAppState);
|
1410
1432
|
}
|
1411
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1433
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
1412
1434
|
return newAppState;
|
1413
1435
|
};
|
1414
1436
|
}
|
@@ -1419,8 +1441,43 @@ function createReducer({
|
|
1419
1441
|
}) {
|
1420
1442
|
return storeInterceptor(
|
1421
1443
|
(state, action) => {
|
1422
|
-
|
1423
|
-
|
1444
|
+
if (action.type === "set") {
|
1445
|
+
return setAction(state, action, appStore);
|
1446
|
+
}
|
1447
|
+
if (action.type === "insert") {
|
1448
|
+
return insertAction(state, action, appStore);
|
1449
|
+
}
|
1450
|
+
if (action.type === "replace") {
|
1451
|
+
return replaceAction(state, action, appStore);
|
1452
|
+
}
|
1453
|
+
if (action.type === "replaceRoot") {
|
1454
|
+
return replaceRootAction(state, action, appStore);
|
1455
|
+
}
|
1456
|
+
if (action.type === "duplicate") {
|
1457
|
+
return duplicateAction(state, action, appStore);
|
1458
|
+
}
|
1459
|
+
if (action.type === "reorder") {
|
1460
|
+
return reorderAction(state, action, appStore);
|
1461
|
+
}
|
1462
|
+
if (action.type === "move") {
|
1463
|
+
return moveAction(state, action, appStore);
|
1464
|
+
}
|
1465
|
+
if (action.type === "remove") {
|
1466
|
+
return removeAction(state, action, appStore);
|
1467
|
+
}
|
1468
|
+
if (action.type === "registerZone") {
|
1469
|
+
return registerZoneAction(state, action);
|
1470
|
+
}
|
1471
|
+
if (action.type === "unregisterZone") {
|
1472
|
+
return unregisterZoneAction(state, action);
|
1473
|
+
}
|
1474
|
+
if (action.type === "setData") {
|
1475
|
+
return setDataAction(state, action, appStore);
|
1476
|
+
}
|
1477
|
+
if (action.type === "setUi") {
|
1478
|
+
return setUiAction(state, action);
|
1479
|
+
}
|
1480
|
+
return state;
|
1424
1481
|
},
|
1425
1482
|
record,
|
1426
1483
|
onAction
|
@@ -1632,7 +1689,7 @@ var createHistorySlice = (set, get) => {
|
|
1632
1689
|
const { dispatch, history } = get();
|
1633
1690
|
dispatch({
|
1634
1691
|
type: "set",
|
1635
|
-
state: ((_a = history.histories[
|
1692
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1636
1693
|
});
|
1637
1694
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1638
1695
|
},
|
@@ -1709,7 +1766,7 @@ var createNodesSlice = (set, get) => ({
|
|
1709
1766
|
init_react_import();
|
1710
1767
|
var import_react7 = require("react");
|
1711
1768
|
|
1712
|
-
// lib/flatten-data.ts
|
1769
|
+
// lib/data/flatten-data.ts
|
1713
1770
|
init_react_import();
|
1714
1771
|
var flattenData = (state, config) => {
|
1715
1772
|
const data = [];
|
@@ -1744,12 +1801,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1744
1801
|
const { cache: cache2, globalPermissions } = permissions;
|
1745
1802
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1746
1803
|
var _a, _b, _c;
|
1747
|
-
const {
|
1748
|
-
config: config2,
|
1749
|
-
state: appState,
|
1750
|
-
setComponentLoading,
|
1751
|
-
unsetComponentLoading
|
1752
|
-
} = get();
|
1804
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1753
1805
|
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1754
1806
|
if (!componentConfig) {
|
1755
1807
|
return;
|
@@ -1758,14 +1810,14 @@ var createPermissionsSlice = (set, get) => {
|
|
1758
1810
|
if (componentConfig.resolvePermissions) {
|
1759
1811
|
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1760
1812
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1761
|
-
setComponentLoading(item2.props.id);
|
1813
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1762
1814
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1763
1815
|
item2,
|
1764
1816
|
{
|
1765
1817
|
changed,
|
1766
1818
|
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1767
1819
|
permissions: initialPermissions,
|
1768
|
-
appState,
|
1820
|
+
appState: makeStatePublic(appState),
|
1769
1821
|
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1770
1822
|
}
|
1771
1823
|
);
|
@@ -1783,7 +1835,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1783
1835
|
})
|
1784
1836
|
})
|
1785
1837
|
});
|
1786
|
-
|
1838
|
+
clearTimeout2();
|
1787
1839
|
}
|
1788
1840
|
}
|
1789
1841
|
});
|
@@ -1793,7 +1845,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1793
1845
|
// Shim the root data in by conforming to component data shape
|
1794
1846
|
{
|
1795
1847
|
type: "root",
|
1796
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1848
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1797
1849
|
},
|
1798
1850
|
force2
|
1799
1851
|
);
|
@@ -1808,7 +1860,6 @@ var createPermissionsSlice = (set, get) => {
|
|
1808
1860
|
} else if (root) {
|
1809
1861
|
resolveDataForRoot(force);
|
1810
1862
|
} else {
|
1811
|
-
resolveDataForRoot(force);
|
1812
1863
|
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1813
1864
|
yield resolveDataForItem(item2, force);
|
1814
1865
|
}));
|
@@ -1839,7 +1890,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1839
1890
|
} else if (root) {
|
1840
1891
|
const rootConfig = config.root;
|
1841
1892
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1842
|
-
const resolvedForItem = resolvedPermissions["
|
1893
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1843
1894
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1844
1895
|
}
|
1845
1896
|
return globalPermissions;
|
@@ -1922,7 +1973,7 @@ var useRegisterFieldsSlice = (appStore, id) => {
|
|
1922
1973
|
fields: defaultFields,
|
1923
1974
|
lastFields,
|
1924
1975
|
lastData,
|
1925
|
-
appState: state,
|
1976
|
+
appState: makeStatePublic(state),
|
1926
1977
|
parent
|
1927
1978
|
});
|
1928
1979
|
clearTimeout(timeout3);
|
@@ -1956,27 +2007,52 @@ var useRegisterFieldsSlice = (appStore, id) => {
|
|
1956
2007
|
// lib/resolve-component-data.ts
|
1957
2008
|
init_react_import();
|
1958
2009
|
|
1959
|
-
// lib/map-slots.ts
|
2010
|
+
// lib/data/map-slots.ts
|
1960
2011
|
init_react_import();
|
1961
|
-
function
|
1962
|
-
return __async(this,
|
2012
|
+
function mapSlotsAsync(_0, _1) {
|
2013
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1963
2014
|
const props = __spreadValues({}, item.props);
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
2015
|
+
const propKeys = Object.keys(props);
|
2016
|
+
for (let i = 0; i < propKeys.length; i++) {
|
2017
|
+
const propKey = propKeys[i];
|
2018
|
+
const itemType = "type" in item ? item.type : "root";
|
2019
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
2020
|
+
const content = props[propKey];
|
1967
2021
|
const mappedContent = recursive ? yield Promise.all(
|
1968
2022
|
content.map((item2) => __async(this, null, function* () {
|
1969
|
-
return yield
|
2023
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
1970
2024
|
}))
|
1971
2025
|
) : content;
|
1972
|
-
props[
|
1973
|
-
}
|
1974
|
-
|
1975
|
-
isSlot2
|
1976
|
-
);
|
2026
|
+
props[propKey] = yield map(mappedContent, propKey);
|
2027
|
+
}
|
2028
|
+
}
|
1977
2029
|
return __spreadProps(__spreadValues({}, item), { props });
|
1978
2030
|
});
|
1979
2031
|
}
|
2032
|
+
function mapSlotsSync(item, map, isSlot2 = isSlot) {
|
2033
|
+
const props = __spreadValues({}, item.props);
|
2034
|
+
const propKeys = Object.keys(props);
|
2035
|
+
for (let i = 0; i < propKeys.length; i++) {
|
2036
|
+
const propKey = propKeys[i];
|
2037
|
+
const itemType = "type" in item ? item.type : "root";
|
2038
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
2039
|
+
const content = props[propKey];
|
2040
|
+
const mappedContent = content.map((item2) => {
|
2041
|
+
return mapSlotsSync(item2, map, isSlot2);
|
2042
|
+
});
|
2043
|
+
props[propKey] = map(mappedContent, props.id, propKey);
|
2044
|
+
}
|
2045
|
+
}
|
2046
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
2047
|
+
}
|
2048
|
+
function mapSlotsPublic(item, config, map) {
|
2049
|
+
const isSlot2 = createIsSlotConfig(config);
|
2050
|
+
return mapSlotsSync(
|
2051
|
+
item,
|
2052
|
+
(content, parentId, propName) => map(content, { parentId, propName }),
|
2053
|
+
isSlot2
|
2054
|
+
);
|
2055
|
+
}
|
1980
2056
|
|
1981
2057
|
// lib/resolve-component-data.ts
|
1982
2058
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
@@ -1996,14 +2072,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1996
2072
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1997
2073
|
changed,
|
1998
2074
|
lastData: oldItem,
|
1999
|
-
metadata,
|
2075
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
2000
2076
|
trigger
|
2001
2077
|
});
|
2002
2078
|
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
2003
2079
|
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
2004
2080
|
});
|
2005
2081
|
if (recursive) {
|
2006
|
-
resolvedItem = yield
|
2082
|
+
resolvedItem = yield mapSlotsAsync(
|
2007
2083
|
resolvedItem,
|
2008
2084
|
(content) => __async(void 0, null, function* () {
|
2009
2085
|
return Promise.all(
|
@@ -2041,7 +2117,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
2041
2117
|
return { node: item, didChange: false };
|
2042
2118
|
});
|
2043
2119
|
|
2044
|
-
// lib/to-root.ts
|
2120
|
+
// lib/data/to-root.ts
|
2045
2121
|
init_react_import();
|
2046
2122
|
var toRoot = (item) => {
|
2047
2123
|
if ("type" in item && item.type !== "root") {
|
@@ -2088,166 +2164,176 @@ var defaultPageFields = {
|
|
2088
2164
|
title: { type: "text" }
|
2089
2165
|
};
|
2090
2166
|
var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
|
2091
|
-
(0, import_middleware2.subscribeWithSelector)((set, get) =>
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2167
|
+
(0, import_middleware2.subscribeWithSelector)((set, get) => {
|
2168
|
+
var _a, _b;
|
2169
|
+
return __spreadProps(__spreadValues({
|
2170
|
+
state: defaultAppState,
|
2171
|
+
config: { components: {} },
|
2172
|
+
componentState: {},
|
2173
|
+
plugins: [],
|
2174
|
+
overrides: {},
|
2175
|
+
viewports: defaultViewports,
|
2176
|
+
zoomConfig: {
|
2177
|
+
autoZoom: 1,
|
2178
|
+
rootHeight: 0,
|
2179
|
+
zoom: 1
|
2180
|
+
},
|
2181
|
+
status: "LOADING",
|
2182
|
+
iframe: {},
|
2183
|
+
metadata: {}
|
2184
|
+
}, initialAppStore), {
|
2185
|
+
fields: createFieldsSlice(set, get),
|
2186
|
+
history: createHistorySlice(set, get),
|
2187
|
+
nodes: createNodesSlice(set, get),
|
2188
|
+
permissions: createPermissionsSlice(set, get),
|
2189
|
+
getComponentConfig: (type) => {
|
2190
|
+
var _a2;
|
2191
|
+
const { config, selectedItem } = get();
|
2192
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
2193
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
2194
|
+
},
|
2195
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
2196
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
2197
|
+
initialAppStore.state
|
2198
|
+
) : null,
|
2199
|
+
dispatch: (action) => set((s) => {
|
2200
|
+
var _a2, _b2;
|
2201
|
+
const { record } = get().history;
|
2202
|
+
const dispatch = createReducer({
|
2203
|
+
record,
|
2204
|
+
appStore: s
|
2205
|
+
});
|
2206
|
+
const state = dispatch(s.state, action);
|
2207
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
2208
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
2209
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
2210
|
+
}),
|
2211
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
2212
|
+
setStatus: (status) => set({ status }),
|
2213
|
+
setComponentState: (componentState) => set({ componentState }),
|
2214
|
+
pendingLoadTimeouts: {},
|
2215
|
+
setComponentLoading: (id, loading = true, defer2 = 0) => {
|
2216
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
2217
|
+
const loadId = generateId();
|
2218
|
+
const setLoading = () => {
|
2219
|
+
var _a2;
|
2220
|
+
const { componentState } = get();
|
2221
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
2222
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
2223
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
2224
|
+
})
|
2225
|
+
}));
|
2226
|
+
};
|
2227
|
+
const unsetLoading = () => {
|
2228
|
+
var _a2;
|
2229
|
+
const { componentState } = get();
|
2230
|
+
clearTimeout(timeout3);
|
2231
|
+
delete pendingLoadTimeouts[loadId];
|
2232
|
+
set({ pendingLoadTimeouts });
|
2233
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
2234
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
2235
|
+
loadingCount: Math.max(
|
2236
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
2237
|
+
0
|
2238
|
+
)
|
2239
|
+
})
|
2240
|
+
}));
|
2241
|
+
};
|
2242
|
+
const timeout3 = setTimeout(() => {
|
2243
|
+
if (loading) {
|
2244
|
+
setLoading();
|
2245
|
+
} else {
|
2246
|
+
unsetLoading();
|
2247
|
+
}
|
2248
|
+
delete pendingLoadTimeouts[loadId];
|
2249
|
+
set({ pendingLoadTimeouts });
|
2250
|
+
}, defer2);
|
2251
|
+
set({
|
2252
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
2253
|
+
[id]: timeout3
|
2154
2254
|
})
|
2155
|
-
})
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
}
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
2195
|
-
}),
|
2196
|
-
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
2197
|
-
const { config, metadata, setComponentLoading } = get();
|
2198
|
-
return yield resolveComponentData(
|
2199
|
-
componentData,
|
2200
|
-
config,
|
2201
|
-
metadata,
|
2202
|
-
(item) => setComponentLoading(
|
2203
|
-
"id" in item.props ? item.props.id : "root",
|
2204
|
-
true,
|
2205
|
-
50
|
2206
|
-
),
|
2207
|
-
(item) => setComponentLoading(
|
2208
|
-
"id" in item.props ? item.props.id : "root",
|
2209
|
-
false,
|
2210
|
-
0
|
2211
|
-
),
|
2212
|
-
trigger
|
2213
|
-
);
|
2214
|
-
}),
|
2215
|
-
resolveAndCommitData: () => __async(void 0, null, function* () {
|
2216
|
-
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
2217
|
-
walkTree(
|
2218
|
-
state,
|
2219
|
-
config,
|
2220
|
-
(content) => content,
|
2221
|
-
(childItem) => {
|
2222
|
-
resolveComponentData2(childItem, "load").then((resolved) => {
|
2223
|
-
const { state: state2 } = get();
|
2224
|
-
const node = state2.indexes.nodes[resolved.node.props.id];
|
2225
|
-
if (node && resolved.didChange) {
|
2226
|
-
if (resolved.node.props.id === "root") {
|
2227
|
-
dispatch({
|
2228
|
-
type: "replaceRoot",
|
2229
|
-
root: toRoot(resolved.node)
|
2230
|
-
});
|
2231
|
-
} else {
|
2232
|
-
const zoneCompound = `${node.parentId}:${node.zone}`;
|
2233
|
-
const parentZone = state2.indexes.zones[zoneCompound];
|
2234
|
-
const index = parentZone.contentIds.indexOf(
|
2235
|
-
resolved.node.props.id
|
2236
|
-
);
|
2237
|
-
dispatch({
|
2238
|
-
type: "replace",
|
2239
|
-
data: resolved.node,
|
2240
|
-
destinationIndex: index,
|
2241
|
-
destinationZone: zoneCompound
|
2242
|
-
});
|
2243
|
-
}
|
2255
|
+
});
|
2256
|
+
return unsetLoading;
|
2257
|
+
},
|
2258
|
+
unsetComponentLoading: (id) => {
|
2259
|
+
const { setComponentLoading } = get();
|
2260
|
+
setComponentLoading(id, false);
|
2261
|
+
},
|
2262
|
+
// Helper
|
2263
|
+
setUi: (ui, recordHistory) => set((s) => {
|
2264
|
+
const dispatch = createReducer({
|
2265
|
+
record: () => {
|
2266
|
+
},
|
2267
|
+
appStore: s
|
2268
|
+
});
|
2269
|
+
const state = dispatch(s.state, {
|
2270
|
+
type: "setUi",
|
2271
|
+
ui,
|
2272
|
+
recordHistory
|
2273
|
+
});
|
2274
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
2275
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
2276
|
+
}),
|
2277
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
2278
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
2279
|
+
const timeouts = {};
|
2280
|
+
return yield resolveComponentData(
|
2281
|
+
componentData,
|
2282
|
+
config,
|
2283
|
+
metadata,
|
2284
|
+
(item) => {
|
2285
|
+
const id = "id" in item.props ? item.props.id : "root";
|
2286
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
2287
|
+
},
|
2288
|
+
(item) => __async(void 0, null, function* () {
|
2289
|
+
const id = "id" in item.props ? item.props.id : "root";
|
2290
|
+
if ("type" in item) {
|
2291
|
+
yield permissions.refreshPermissions({ item });
|
2292
|
+
} else {
|
2293
|
+
yield permissions.refreshPermissions({ root: true });
|
2244
2294
|
}
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2295
|
+
timeouts[id]();
|
2296
|
+
}),
|
2297
|
+
trigger
|
2298
|
+
);
|
2299
|
+
}),
|
2300
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
2301
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
2302
|
+
walkTree(
|
2303
|
+
state,
|
2304
|
+
config,
|
2305
|
+
(content) => content,
|
2306
|
+
(childItem) => {
|
2307
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
2308
|
+
const { state: state2 } = get();
|
2309
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
2310
|
+
if (node && resolved.didChange) {
|
2311
|
+
if (resolved.node.props.id === "root") {
|
2312
|
+
dispatch({
|
2313
|
+
type: "replaceRoot",
|
2314
|
+
root: toRoot(resolved.node)
|
2315
|
+
});
|
2316
|
+
} else {
|
2317
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
2318
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
2319
|
+
const index = parentZone.contentIds.indexOf(
|
2320
|
+
resolved.node.props.id
|
2321
|
+
);
|
2322
|
+
dispatch({
|
2323
|
+
type: "replace",
|
2324
|
+
data: resolved.node,
|
2325
|
+
destinationIndex: index,
|
2326
|
+
destinationZone: zoneCompound
|
2327
|
+
});
|
2328
|
+
}
|
2329
|
+
}
|
2330
|
+
});
|
2331
|
+
return childItem;
|
2332
|
+
}
|
2333
|
+
);
|
2334
|
+
})
|
2335
|
+
});
|
2336
|
+
})
|
2251
2337
|
);
|
2252
2338
|
var appStoreContext = (0, import_react9.createContext)(createAppStore());
|
2253
2339
|
function useAppStore(selector) {
|
@@ -4342,7 +4428,7 @@ var import_react25 = require("react");
|
|
4342
4428
|
|
4343
4429
|
// css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
|
4344
4430
|
init_react_import();
|
4345
|
-
var styles_module_default11 = { "DraggableComponent": "
|
4431
|
+
var styles_module_default11 = { "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" };
|
4346
4432
|
|
4347
4433
|
// components/DraggableComponent/index.tsx
|
4348
4434
|
var import_react_dom2 = require("react-dom");
|
@@ -4393,7 +4479,6 @@ var DropZoneProvider = ({
|
|
4393
4479
|
value
|
4394
4480
|
}) => {
|
4395
4481
|
const [hoveringComponent, setHoveringComponent] = (0, import_react23.useState)();
|
4396
|
-
const [activeZones, setActiveZones] = (0, import_react23.useState)({});
|
4397
4482
|
const dispatch = useAppStore((s) => s.dispatch);
|
4398
4483
|
const registerZone = (0, import_react23.useCallback)(
|
4399
4484
|
(zoneCompound) => {
|
@@ -4402,7 +4487,7 @@ var DropZoneProvider = ({
|
|
4402
4487
|
zone: zoneCompound
|
4403
4488
|
});
|
4404
4489
|
},
|
4405
|
-
[
|
4490
|
+
[dispatch]
|
4406
4491
|
);
|
4407
4492
|
const unregisterZone = (0, import_react23.useCallback)(
|
4408
4493
|
(zoneCompound) => {
|
@@ -4411,17 +4496,16 @@ var DropZoneProvider = ({
|
|
4411
4496
|
zone: zoneCompound
|
4412
4497
|
});
|
4413
4498
|
},
|
4414
|
-
[
|
4499
|
+
[dispatch]
|
4415
4500
|
);
|
4416
4501
|
const memoValue = (0, import_react23.useMemo)(
|
4417
4502
|
() => __spreadValues({
|
4418
4503
|
hoveringComponent,
|
4419
4504
|
setHoveringComponent,
|
4420
4505
|
registerZone,
|
4421
|
-
unregisterZone
|
4422
|
-
activeZones
|
4506
|
+
unregisterZone
|
4423
4507
|
}, value),
|
4424
|
-
[value, hoveringComponent
|
4508
|
+
[value, hoveringComponent]
|
4425
4509
|
);
|
4426
4510
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_jsx_runtime19.Fragment, { children: memoValue && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(dropZoneContext.Provider, { value: memoValue, children }) });
|
4427
4511
|
};
|
@@ -4514,8 +4598,10 @@ var DraggableComponent = ({
|
|
4514
4598
|
return (_a = s.state.indexes.nodes[id]) == null ? void 0 : _a.path;
|
4515
4599
|
}));
|
4516
4600
|
const permissions = useAppStore(
|
4517
|
-
(0, import_shallow2.useShallow)((s) =>
|
4518
|
-
|
4601
|
+
(0, import_shallow2.useShallow)((s) => {
|
4602
|
+
const item = getItem({ index, zone: zoneCompound }, s.state);
|
4603
|
+
return s.permissions.getPermissions({ item });
|
4604
|
+
})
|
4519
4605
|
);
|
4520
4606
|
const userIsDragging = useContextStore(
|
4521
4607
|
ZoneStoreContext,
|
@@ -4769,76 +4855,82 @@ var DraggableComponent = ({
|
|
4769
4855
|
setDragAxis(autoDragAxis);
|
4770
4856
|
}, [ref, userDragAxis, autoDragAxis]);
|
4771
4857
|
const parentAction = (ctx == null ? void 0 : ctx.areaId) && (ctx == null ? void 0 : ctx.areaId) !== "root" && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ActionBar.Action, { onClick: onSelectParent, label: "Select parent", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CornerLeftUp, { size: 16 }) });
|
4772
|
-
|
4773
|
-
|
4774
|
-
|
4775
|
-
|
4776
|
-
|
4777
|
-
|
4778
|
-
|
4779
|
-
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4858
|
+
const nextContextValue = (0, import_react25.useMemo)(
|
4859
|
+
() => __spreadProps(__spreadValues({}, ctx), {
|
4860
|
+
areaId: id,
|
4861
|
+
zoneCompound,
|
4862
|
+
index,
|
4863
|
+
depth: depth + 1,
|
4864
|
+
registerLocalZone,
|
4865
|
+
unregisterLocalZone
|
4866
|
+
}),
|
4867
|
+
[
|
4868
|
+
ctx,
|
4869
|
+
id,
|
4870
|
+
zoneCompound,
|
4871
|
+
index,
|
4872
|
+
depth,
|
4873
|
+
registerLocalZone,
|
4874
|
+
unregisterLocalZone
|
4875
|
+
]
|
4876
|
+
);
|
4877
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(DropZoneProvider, { value: nextContextValue, children: [
|
4878
|
+
isVisible && (0, import_react_dom2.createPortal)(
|
4879
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
4880
|
+
"div",
|
4881
|
+
{
|
4882
|
+
className: getClassName16({
|
4883
|
+
isSelected,
|
4884
|
+
isDragging: thisIsDragging,
|
4885
|
+
hover: hover || indicativeHover
|
4886
|
+
}),
|
4887
|
+
style: __spreadValues({}, style),
|
4888
|
+
"data-puck-overlay": true,
|
4889
|
+
children: [
|
4890
|
+
debug,
|
4891
|
+
isLoading && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Loader, {}) }),
|
4892
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
4893
|
+
"div",
|
4894
|
+
{
|
4895
|
+
className: getClassName16("actionsOverlay"),
|
4896
|
+
style: {
|
4897
|
+
top: actionsOverlayTop / zoom
|
4898
|
+
},
|
4899
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
4799
4900
|
"div",
|
4800
4901
|
{
|
4801
|
-
className: getClassName16("
|
4902
|
+
className: getClassName16("actions"),
|
4802
4903
|
style: {
|
4803
|
-
|
4904
|
+
transform: `scale(${1 / zoom}`,
|
4905
|
+
top: actionsTop / zoom,
|
4906
|
+
right: 0,
|
4907
|
+
paddingLeft: actionsSide,
|
4908
|
+
paddingRight: actionsSide
|
4804
4909
|
},
|
4805
|
-
|
4806
|
-
|
4910
|
+
ref: syncActionsPosition,
|
4911
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
4912
|
+
CustomActionBar,
|
4807
4913
|
{
|
4808
|
-
|
4809
|
-
|
4810
|
-
|
4811
|
-
|
4812
|
-
|
4813
|
-
|
4814
|
-
paddingRight: actionsSide
|
4815
|
-
},
|
4816
|
-
ref: syncActionsPosition,
|
4817
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
4818
|
-
CustomActionBar,
|
4819
|
-
{
|
4820
|
-
parentAction,
|
4821
|
-
label: DEBUG2 ? id : label,
|
4822
|
-
children: [
|
4823
|
-
permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Copy, { size: 16 }) }),
|
4824
|
-
permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Trash, { size: 16 }) })
|
4825
|
-
]
|
4826
|
-
}
|
4827
|
-
)
|
4914
|
+
parentAction,
|
4915
|
+
label: DEBUG2 ? id : label,
|
4916
|
+
children: [
|
4917
|
+
permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Copy, { size: 16 }) }),
|
4918
|
+
permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Trash, { size: 16 }) })
|
4919
|
+
]
|
4828
4920
|
}
|
4829
4921
|
)
|
4830
4922
|
}
|
4831
|
-
)
|
4832
|
-
|
4833
|
-
|
4834
|
-
}
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
);
|
4923
|
+
)
|
4924
|
+
}
|
4925
|
+
),
|
4926
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName16("overlay") })
|
4927
|
+
]
|
4928
|
+
}
|
4929
|
+
),
|
4930
|
+
portalEl || document.body
|
4931
|
+
),
|
4932
|
+
children(refSetter)
|
4933
|
+
] });
|
4842
4934
|
};
|
4843
4935
|
|
4844
4936
|
// css-module:/home/runner/work/puck/puck/packages/core/components/DropZone/styles.module.css#css-module
|
@@ -5024,26 +5116,33 @@ var import_shallow3 = require("zustand/react/shallow");
|
|
5024
5116
|
// components/Render/index.tsx
|
5025
5117
|
init_react_import();
|
5026
5118
|
|
5027
|
-
// lib/use-slots.
|
5119
|
+
// lib/use-slots.tsx
|
5028
5120
|
init_react_import();
|
5029
5121
|
var import_react31 = require("react");
|
5030
|
-
function useSlots(config, props,
|
5031
|
-
|
5122
|
+
function useSlots(config, props, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
5123
|
+
const slotProps = (0, import_react31.useMemo)(() => {
|
5032
5124
|
if (!(config == null ? void 0 : config.fields)) return props;
|
5033
|
-
const
|
5125
|
+
const slotProps2 = {};
|
5034
5126
|
const fieldKeys = Object.keys(config.fields);
|
5035
5127
|
for (let i = 0; i < fieldKeys.length; i++) {
|
5036
5128
|
const fieldKey = fieldKeys[i];
|
5037
5129
|
const field = config.fields[fieldKey];
|
5038
5130
|
if ((field == null ? void 0 : field.type) === "slot") {
|
5039
|
-
|
5131
|
+
const content = props[fieldKey] || [];
|
5132
|
+
const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
|
5133
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
5134
|
+
allow: field.allow,
|
5135
|
+
disallow: field.disallow
|
5136
|
+
}, dzProps), {
|
5040
5137
|
zone: fieldKey,
|
5041
|
-
content
|
5138
|
+
content
|
5042
5139
|
}));
|
5140
|
+
slotProps2[fieldKey] = Slot;
|
5043
5141
|
}
|
5044
5142
|
}
|
5045
|
-
return
|
5046
|
-
}, [config,
|
5143
|
+
return slotProps2;
|
5144
|
+
}, [config, readOnly, forceReadOnly]);
|
5145
|
+
return __spreadValues(__spreadValues({}, props), slotProps);
|
5047
5146
|
}
|
5048
5147
|
|
5049
5148
|
// components/Render/index.tsx
|
@@ -5054,30 +5153,60 @@ init_react_import();
|
|
5054
5153
|
var import_react32 = require("react");
|
5055
5154
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
5056
5155
|
var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SlotRender, __spreadValues({}, props));
|
5156
|
+
var ContextSlotRender = ({
|
5157
|
+
componentId,
|
5158
|
+
zone
|
5159
|
+
}) => {
|
5160
|
+
const config = useAppStore((s) => s.config);
|
5161
|
+
const metadata = useAppStore((s) => s.metadata);
|
5162
|
+
const slotContent = useAppStore(
|
5163
|
+
(s) => {
|
5164
|
+
var _a, _b;
|
5165
|
+
return (_b = (_a = s.state.indexes.nodes[componentId]) == null ? void 0 : _a.data.props[zone]) != null ? _b : null;
|
5166
|
+
}
|
5167
|
+
);
|
5168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
5169
|
+
SlotRenderPure,
|
5170
|
+
{
|
5171
|
+
content: slotContent,
|
5172
|
+
zone,
|
5173
|
+
config,
|
5174
|
+
metadata
|
5175
|
+
}
|
5176
|
+
);
|
5177
|
+
};
|
5178
|
+
var Item = ({
|
5179
|
+
config,
|
5180
|
+
item,
|
5181
|
+
metadata
|
5182
|
+
}) => {
|
5183
|
+
const Component = config.components[item.type];
|
5184
|
+
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
5185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
5186
|
+
Component.render,
|
5187
|
+
__spreadProps(__spreadValues({}, props), {
|
5188
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
5189
|
+
renderDropZone: DropZoneRenderPure,
|
5190
|
+
metadata: metadata || {}
|
5191
|
+
})
|
5192
|
+
})
|
5193
|
+
);
|
5194
|
+
};
|
5057
5195
|
var SlotRender = (0, import_react32.forwardRef)(
|
5058
5196
|
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
5059
5197
|
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className, style, ref, children: content.map((item) => {
|
5060
|
-
|
5061
|
-
|
5062
|
-
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
5063
|
-
SlotRenderPure,
|
5064
|
-
__spreadProps(__spreadValues({}, slotProps), {
|
5065
|
-
config,
|
5066
|
-
metadata
|
5067
|
-
})
|
5068
|
-
));
|
5069
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
5070
|
-
Component.render,
|
5071
|
-
__spreadProps(__spreadValues({}, props), {
|
5072
|
-
puck: {
|
5073
|
-
renderDropZone: DropZoneRenderPure,
|
5074
|
-
metadata: metadata || {}
|
5075
|
-
}
|
5076
|
-
}),
|
5077
|
-
props.id
|
5078
|
-
);
|
5198
|
+
if (!config.components[item.type]) {
|
5199
|
+
return null;
|
5079
5200
|
}
|
5080
|
-
return
|
5201
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
5202
|
+
Item,
|
5203
|
+
{
|
5204
|
+
config,
|
5205
|
+
item,
|
5206
|
+
metadata
|
5207
|
+
},
|
5208
|
+
item.props.id
|
5209
|
+
);
|
5081
5210
|
}) });
|
5082
5211
|
}
|
5083
5212
|
);
|
@@ -5113,28 +5242,17 @@ function Render({
|
|
5113
5242
|
id: "puck-root"
|
5114
5243
|
});
|
5115
5244
|
const propsWithSlots = useSlots(config.root, pageProps, (props) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(SlotRender, __spreadProps(__spreadValues({}, props), { config, metadata })));
|
5245
|
+
const nextContextValue = (0, import_react33.useMemo)(
|
5246
|
+
() => ({
|
5247
|
+
mode: "render",
|
5248
|
+
depth: 0
|
5249
|
+
}),
|
5250
|
+
[]
|
5251
|
+
);
|
5116
5252
|
if ((_a = config.root) == null ? void 0 : _a.render) {
|
5117
|
-
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
5118
|
-
DropZoneProvider,
|
5119
|
-
{
|
5120
|
-
value: {
|
5121
|
-
mode: "render",
|
5122
|
-
depth: 0
|
5123
|
-
},
|
5124
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneRenderPure, { zone: rootZone }) }))
|
5125
|
-
}
|
5126
|
-
) });
|
5253
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneRenderPure, { zone: rootZone }) })) }) });
|
5127
5254
|
}
|
5128
|
-
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
5129
|
-
DropZoneProvider,
|
5130
|
-
{
|
5131
|
-
value: {
|
5132
|
-
mode: "render",
|
5133
|
-
depth: 0
|
5134
|
-
},
|
5135
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneRenderPure, { zone: rootZone })
|
5136
|
-
}
|
5137
|
-
) });
|
5255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneRenderPure, { zone: rootZone }) }) });
|
5138
5256
|
}
|
5139
5257
|
|
5140
5258
|
// components/DropZone/index.tsx
|
@@ -5155,14 +5273,8 @@ var DropZoneChild = ({
|
|
5155
5273
|
}) => {
|
5156
5274
|
var _a, _b;
|
5157
5275
|
const metadata = useAppStore((s) => s.metadata);
|
5158
|
-
const puckProps = {
|
5159
|
-
renderDropZone: DropZoneEditPure,
|
5160
|
-
isEditing: true,
|
5161
|
-
dragRef: null,
|
5162
|
-
metadata
|
5163
|
-
};
|
5164
5276
|
const ctx = (0, import_react34.useContext)(dropZoneContext);
|
5165
|
-
const { depth } = ctx;
|
5277
|
+
const { depth = 1 } = ctx != null ? ctx : {};
|
5166
5278
|
const nodeProps = useAppStore(
|
5167
5279
|
(0, import_shallow3.useShallow)((s) => {
|
5168
5280
|
var _a2;
|
@@ -5175,11 +5287,23 @@ var DropZoneChild = ({
|
|
5175
5287
|
return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.type;
|
5176
5288
|
}
|
5177
5289
|
);
|
5290
|
+
const nodeReadOnly = useAppStore(
|
5291
|
+
(0, import_shallow3.useShallow)((s) => {
|
5292
|
+
var _a2;
|
5293
|
+
return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.readOnly;
|
5294
|
+
})
|
5295
|
+
);
|
5178
5296
|
const node = { type: nodeType, props: nodeProps };
|
5179
5297
|
const item = nodeProps ? node : (preview == null ? void 0 : preview.componentType) ? { type: preview.componentType, props: preview.props } : null;
|
5180
5298
|
const componentConfig = useAppStore(
|
5181
5299
|
(s) => (item == null ? void 0 : item.type) ? s.config.components[item.type] : null
|
5182
5300
|
);
|
5301
|
+
const puckProps = {
|
5302
|
+
renderDropZone: DropZoneEditPure,
|
5303
|
+
isEditing: true,
|
5304
|
+
dragRef: null,
|
5305
|
+
metadata: __spreadValues(__spreadValues({}, metadata), componentConfig == null ? void 0 : componentConfig.metadata)
|
5306
|
+
};
|
5183
5307
|
const overrides = useAppStore((s) => s.overrides);
|
5184
5308
|
const isLoading = useAppStore(
|
5185
5309
|
(s) => {
|
@@ -5211,7 +5335,10 @@ var DropZoneChild = ({
|
|
5211
5335
|
const defaultedPropsWithSlots = useSlots(
|
5212
5336
|
componentConfig,
|
5213
5337
|
defaultsProps,
|
5214
|
-
DropZoneEditPure
|
5338
|
+
DropZoneEditPure,
|
5339
|
+
(slotProps) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ContextSlotRender, { componentId, zone: slotProps.zone }),
|
5340
|
+
nodeReadOnly,
|
5341
|
+
isLoading
|
5215
5342
|
);
|
5216
5343
|
if (!item) return;
|
5217
5344
|
let Render2 = componentConfig ? componentConfig.render : () => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { style: { padding: 48, textAlign: "center" }, children: [
|
@@ -5249,6 +5376,7 @@ var DropZoneChild = ({
|
|
5249
5376
|
}
|
5250
5377
|
);
|
5251
5378
|
};
|
5379
|
+
var DropZoneChildMemo = (0, import_react34.memo)(DropZoneChild);
|
5252
5380
|
var DropZoneEdit = (0, import_react34.forwardRef)(
|
5253
5381
|
function DropZoneEditInternal({
|
5254
5382
|
zone,
|
@@ -5263,10 +5391,10 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
|
|
5263
5391
|
const {
|
5264
5392
|
// These all need setting via context
|
5265
5393
|
areaId,
|
5266
|
-
depth,
|
5394
|
+
depth = 0,
|
5267
5395
|
registerLocalZone,
|
5268
5396
|
unregisterLocalZone
|
5269
|
-
} = ctx;
|
5397
|
+
} = ctx != null ? ctx : {};
|
5270
5398
|
const path = useAppStore(
|
5271
5399
|
(0, import_shallow3.useShallow)((s) => {
|
5272
5400
|
var _a;
|
@@ -5308,6 +5436,11 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
|
|
5308
5436
|
);
|
5309
5437
|
(0, import_react34.useEffect)(() => {
|
5310
5438
|
if (!zoneType || zoneType === "dropzone") {
|
5439
|
+
if (zoneCompound !== rootDroppableId) {
|
5440
|
+
console.warn(
|
5441
|
+
"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"
|
5442
|
+
);
|
5443
|
+
}
|
5311
5444
|
if (ctx == null ? void 0 : ctx.registerZone) {
|
5312
5445
|
ctx == null ? void 0 : ctx.registerZone(zoneCompound);
|
5313
5446
|
}
|
@@ -5413,7 +5546,7 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
|
|
5413
5546
|
}),
|
5414
5547
|
children: contentIdsWithPreview.map((componentId, i) => {
|
5415
5548
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
5416
|
-
|
5549
|
+
DropZoneChildMemo,
|
5417
5550
|
{
|
5418
5551
|
zoneCompound,
|
5419
5552
|
componentId,
|
@@ -5431,6 +5564,30 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
|
|
5431
5564
|
);
|
5432
5565
|
}
|
5433
5566
|
);
|
5567
|
+
var DropZoneRenderItem = ({
|
5568
|
+
config,
|
5569
|
+
item,
|
5570
|
+
metadata
|
5571
|
+
}) => {
|
5572
|
+
const Component = config.components[item.type];
|
5573
|
+
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
5574
|
+
const nextContextValue = (0, import_react34.useMemo)(
|
5575
|
+
() => ({
|
5576
|
+
areaId: props.id,
|
5577
|
+
depth: 1
|
5578
|
+
}),
|
5579
|
+
[props]
|
5580
|
+
);
|
5581
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
5582
|
+
Component.render,
|
5583
|
+
__spreadProps(__spreadValues({}, props), {
|
5584
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
5585
|
+
renderDropZone: DropZoneRenderPure,
|
5586
|
+
metadata: __spreadValues(__spreadValues({}, metadata), Component.metadata)
|
5587
|
+
})
|
5588
|
+
})
|
5589
|
+
) }, props.id);
|
5590
|
+
};
|
5434
5591
|
var DropZoneRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZoneRender, __spreadValues({}, props));
|
5435
5592
|
var DropZoneRender = (0, import_react34.forwardRef)(
|
5436
5593
|
function DropZoneRenderInternal({ className, style, zone }, ref) {
|
@@ -5461,31 +5618,14 @@ var DropZoneRender = (0, import_react34.forwardRef)(
|
|
5461
5618
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className, style, ref, children: content.map((item) => {
|
5462
5619
|
const Component = config.components[item.type];
|
5463
5620
|
if (Component) {
|
5464
|
-
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
5465
|
-
SlotRenderPure,
|
5466
|
-
__spreadProps(__spreadValues({}, slotProps), {
|
5467
|
-
config,
|
5468
|
-
metadata
|
5469
|
-
})
|
5470
|
-
));
|
5471
5621
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
5472
|
-
|
5622
|
+
DropZoneRenderItem,
|
5473
5623
|
{
|
5474
|
-
|
5475
|
-
|
5476
|
-
|
5477
|
-
},
|
5478
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
5479
|
-
Component.render,
|
5480
|
-
__spreadProps(__spreadValues({}, props), {
|
5481
|
-
puck: {
|
5482
|
-
renderDropZone: DropZoneRenderPure,
|
5483
|
-
metadata: metadata || {}
|
5484
|
-
}
|
5485
|
-
})
|
5486
|
-
)
|
5624
|
+
config,
|
5625
|
+
item,
|
5626
|
+
metadata
|
5487
5627
|
},
|
5488
|
-
props.id
|
5628
|
+
item.props.id
|
5489
5629
|
);
|
5490
5630
|
}
|
5491
5631
|
return null;
|
@@ -5773,8 +5913,8 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
|
|
5773
5913
|
destinationZone: zone,
|
5774
5914
|
id
|
5775
5915
|
};
|
5776
|
-
const { state,
|
5777
|
-
const insertedState = insertAction(state, insertActionData,
|
5916
|
+
const { state, dispatch, resolveComponentData: resolveComponentData2 } = appStore;
|
5917
|
+
const insertedState = insertAction(state, insertActionData, appStore);
|
5778
5918
|
dispatch(__spreadProps(__spreadValues({}, insertActionData), {
|
5779
5919
|
// Dispatch insert rather set, as user's may rely on this via onAction
|
5780
5920
|
// We must always record history here so the insert is added to user history
|
@@ -5976,6 +6116,14 @@ var DragDropContextClient = ({
|
|
5976
6116
|
const [dragListeners, setDragListeners] = (0, import_react36.useState)({});
|
5977
6117
|
const dragMode = (0, import_react36.useRef)(null);
|
5978
6118
|
const initialSelector = (0, import_react36.useRef)(void 0);
|
6119
|
+
const nextContextValue = (0, import_react36.useMemo)(
|
6120
|
+
() => ({
|
6121
|
+
mode: "edit",
|
6122
|
+
areaId: "root",
|
6123
|
+
depth: 0
|
6124
|
+
}),
|
6125
|
+
[]
|
6126
|
+
);
|
5979
6127
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { id, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
5980
6128
|
dragListenerContext.Provider,
|
5981
6129
|
{
|
@@ -6017,7 +6165,6 @@ var DragDropContextClient = ({
|
|
6017
6165
|
}
|
6018
6166
|
if (thisPreview) {
|
6019
6167
|
zoneStore.setState({ previewIndex: {} });
|
6020
|
-
const state = appStore.getState().state;
|
6021
6168
|
if (thisPreview.type === "insert") {
|
6022
6169
|
insertComponent(
|
6023
6170
|
thisPreview.componentType,
|
@@ -6174,17 +6321,7 @@ var DragDropContextClient = ({
|
|
6174
6321
|
initialSelector.current = void 0;
|
6175
6322
|
zoneStore.setState({ draggedItem: event.operation.source });
|
6176
6323
|
},
|
6177
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ZoneStoreProvider, { store: zoneStore, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
6178
|
-
DropZoneProvider,
|
6179
|
-
{
|
6180
|
-
value: {
|
6181
|
-
mode: "edit",
|
6182
|
-
areaId: "root",
|
6183
|
-
depth: 0
|
6184
|
-
},
|
6185
|
-
children
|
6186
|
-
}
|
6187
|
-
) })
|
6324
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ZoneStoreProvider, { store: zoneStore, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DropZoneProvider, { value: nextContextValue, children }) })
|
6188
6325
|
}
|
6189
6326
|
)
|
6190
6327
|
}
|
@@ -7368,7 +7505,7 @@ var LayerTree = ({
|
|
7368
7505
|
// components/Puck/components/Outline/index.tsx
|
7369
7506
|
var import_react45 = require("react");
|
7370
7507
|
|
7371
|
-
// lib/find-zones-for-area.ts
|
7508
|
+
// lib/data/find-zones-for-area.ts
|
7372
7509
|
init_react_import();
|
7373
7510
|
var findZonesForArea = (state, area) => {
|
7374
7511
|
return Object.keys(state.indexes.zones).filter(
|
@@ -7978,13 +8115,22 @@ var generateUsePuck = (store) => {
|
|
7978
8115
|
index: store.history.index
|
7979
8116
|
};
|
7980
8117
|
const storeData = {
|
7981
|
-
appState: store.state,
|
8118
|
+
appState: makeStatePublic(store.state),
|
7982
8119
|
config: store.config,
|
7983
8120
|
dispatch: store.dispatch,
|
7984
8121
|
getPermissions: store.permissions.getPermissions,
|
7985
8122
|
refreshPermissions: store.permissions.refreshPermissions,
|
7986
8123
|
history,
|
7987
|
-
selectedItem: store.selectedItem || null
|
8124
|
+
selectedItem: store.selectedItem || null,
|
8125
|
+
getItemBySelector: (selector) => getItem(selector, store.state),
|
8126
|
+
getItemById: (id) => store.state.indexes.nodes[id].data,
|
8127
|
+
getSelectorForId: (id) => {
|
8128
|
+
const node = store.state.indexes.nodes[id];
|
8129
|
+
if (!node) return;
|
8130
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
8131
|
+
const index = store.state.indexes.zones[zoneCompound].contentIds.indexOf(id);
|
8132
|
+
return { zone: zoneCompound, index };
|
8133
|
+
}
|
7988
8134
|
};
|
7989
8135
|
const get = () => storeData;
|
7990
8136
|
return __spreadProps(__spreadValues({}, storeData), { get });
|
@@ -7992,23 +8138,25 @@ var generateUsePuck = (store) => {
|
|
7992
8138
|
var UsePuckStoreContext = (0, import_react51.createContext)(
|
7993
8139
|
null
|
7994
8140
|
);
|
8141
|
+
var convertToPickedStore = (store) => {
|
8142
|
+
return {
|
8143
|
+
state: store.state,
|
8144
|
+
config: store.config,
|
8145
|
+
dispatch: store.dispatch,
|
8146
|
+
permissions: store.permissions,
|
8147
|
+
history: store.history,
|
8148
|
+
selectedItem: store.selectedItem
|
8149
|
+
};
|
8150
|
+
};
|
7995
8151
|
var useRegisterUsePuckStore = (appStore) => {
|
7996
8152
|
const [usePuckStore] = (0, import_react51.useState)(
|
7997
|
-
() => (0, import_zustand6.createStore)(
|
8153
|
+
() => (0, import_zustand6.createStore)(
|
8154
|
+
() => generateUsePuck(convertToPickedStore(appStore.getState()))
|
8155
|
+
)
|
7998
8156
|
);
|
7999
8157
|
(0, import_react51.useEffect)(() => {
|
8000
8158
|
return appStore.subscribe(
|
8001
|
-
(store) =>
|
8002
|
-
const pickedStore = {
|
8003
|
-
state: store.state,
|
8004
|
-
config: store.config,
|
8005
|
-
dispatch: store.dispatch,
|
8006
|
-
permissions: store.permissions,
|
8007
|
-
history: store.history,
|
8008
|
-
selectedItem: store.selectedItem
|
8009
|
-
};
|
8010
|
-
return pickedStore;
|
8011
|
-
},
|
8159
|
+
(store) => convertToPickedStore(store),
|
8012
8160
|
(pickedStore) => {
|
8013
8161
|
usePuckStore.setState(generateUsePuck(pickedStore));
|
8014
8162
|
}
|
@@ -8051,29 +8199,11 @@ var FieldSideBar = () => {
|
|
8051
8199
|
);
|
8052
8200
|
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Fields, {}) });
|
8053
8201
|
};
|
8054
|
-
var DEBUG4 = false;
|
8055
8202
|
var propsContext = (0, import_react52.createContext)({});
|
8056
8203
|
function PropsProvider(props) {
|
8057
8204
|
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(propsContext.Provider, { value: props, children: props.children });
|
8058
8205
|
}
|
8059
8206
|
var usePropsContext = () => (0, import_react52.useContext)(propsContext);
|
8060
|
-
var debugPlugin = {
|
8061
|
-
overrides: {
|
8062
|
-
fields: ({ children }) => {
|
8063
|
-
const state = useAppStore((s) => s.state);
|
8064
|
-
const selectedItem = useAppStore((s) => s.selectedItem);
|
8065
|
-
return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_jsx_runtime39.Fragment, { children: [
|
8066
|
-
children,
|
8067
|
-
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SidebarSection, { title: "Debug: Data", children: JSON.stringify(state.data) }),
|
8068
|
-
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SidebarSection, { title: "Debug: UI", children: JSON.stringify(state.ui) }),
|
8069
|
-
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SidebarSection, { title: "Debug: Other", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("ul", { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("li", { children: [
|
8070
|
-
"Selected Item: ",
|
8071
|
-
JSON.stringify(selectedItem)
|
8072
|
-
] }) }) })
|
8073
|
-
] });
|
8074
|
-
}
|
8075
|
-
}
|
8076
|
-
};
|
8077
8207
|
function PuckProvider({ children }) {
|
8078
8208
|
const {
|
8079
8209
|
config,
|
@@ -8081,7 +8211,7 @@ function PuckProvider({ children }) {
|
|
8081
8211
|
ui: initialUi,
|
8082
8212
|
onChange,
|
8083
8213
|
permissions = {},
|
8084
|
-
plugins
|
8214
|
+
plugins,
|
8085
8215
|
overrides,
|
8086
8216
|
viewports = defaultViewports,
|
8087
8217
|
iframe: _iframe,
|
@@ -8153,57 +8283,57 @@ function PuckProvider({ children }) {
|
|
8153
8283
|
return walkTree(newAppState, config);
|
8154
8284
|
});
|
8155
8285
|
const { appendData = true } = _initialHistory || {};
|
8156
|
-
const blendedHistories =
|
8157
|
-
|
8158
|
-
|
8159
|
-
|
8160
|
-
|
8161
|
-
|
8162
|
-
|
8286
|
+
const [blendedHistories] = (0, import_react52.useState)(
|
8287
|
+
[
|
8288
|
+
...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
|
8289
|
+
...appendData ? [{ state: generatedAppState }] : []
|
8290
|
+
].map((history) => {
|
8291
|
+
let newState = __spreadValues(__spreadValues({}, generatedAppState), history.state);
|
8292
|
+
if (!history.state.indexes) {
|
8293
|
+
newState = walkTree(newState, config);
|
8294
|
+
}
|
8295
|
+
return __spreadProps(__spreadValues({}, history), {
|
8296
|
+
state: newState
|
8297
|
+
});
|
8298
|
+
})
|
8299
|
+
);
|
8163
8300
|
const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || blendedHistories.length - 1;
|
8164
8301
|
const initialAppState = blendedHistories[initialHistoryIndex].state;
|
8165
|
-
const plugins = (0, import_react52.useMemo)(
|
8166
|
-
() => DEBUG4 ? [..._plugins || [], debugPlugin] : _plugins,
|
8167
|
-
[_plugins]
|
8168
|
-
);
|
8169
8302
|
const loadedOverrides = useLoadedOverrides({
|
8170
8303
|
overrides,
|
8171
8304
|
plugins
|
8172
8305
|
});
|
8173
|
-
const generateAppStore = (0, import_react52.useCallback)(
|
8174
|
-
|
8175
|
-
|
8306
|
+
const generateAppStore = (0, import_react52.useCallback)(
|
8307
|
+
(state) => {
|
8308
|
+
return {
|
8309
|
+
state,
|
8310
|
+
config,
|
8311
|
+
plugins: plugins || [],
|
8312
|
+
overrides: loadedOverrides,
|
8313
|
+
viewports,
|
8314
|
+
iframe,
|
8315
|
+
onAction,
|
8316
|
+
metadata
|
8317
|
+
};
|
8318
|
+
},
|
8319
|
+
[
|
8320
|
+
initialAppState,
|
8176
8321
|
config,
|
8177
|
-
plugins
|
8178
|
-
|
8322
|
+
plugins,
|
8323
|
+
loadedOverrides,
|
8179
8324
|
viewports,
|
8180
8325
|
iframe,
|
8181
8326
|
onAction,
|
8182
8327
|
metadata
|
8183
|
-
|
8184
|
-
|
8185
|
-
|
8186
|
-
|
8187
|
-
|
8188
|
-
loadedOverrides,
|
8189
|
-
viewports,
|
8190
|
-
iframe,
|
8191
|
-
onAction,
|
8192
|
-
metadata
|
8193
|
-
]);
|
8194
|
-
const [appStore] = (0, import_react52.useState)(() => createAppStore(generateAppStore()));
|
8328
|
+
]
|
8329
|
+
);
|
8330
|
+
const [appStore] = (0, import_react52.useState)(
|
8331
|
+
() => createAppStore(generateAppStore(initialAppState))
|
8332
|
+
);
|
8195
8333
|
(0, import_react52.useEffect)(() => {
|
8196
|
-
appStore.
|
8197
|
-
|
8198
|
-
|
8199
|
-
config,
|
8200
|
-
plugins,
|
8201
|
-
loadedOverrides,
|
8202
|
-
viewports,
|
8203
|
-
iframe,
|
8204
|
-
onAction,
|
8205
|
-
metadata
|
8206
|
-
]);
|
8334
|
+
const state = appStore.getState().state;
|
8335
|
+
appStore.setState(__spreadValues({}, generateAppStore(state)));
|
8336
|
+
}, [config, plugins, loadedOverrides, viewports, iframe, onAction, metadata]);
|
8207
8337
|
useRegisterHistorySlice(appStore, {
|
8208
8338
|
histories: blendedHistories,
|
8209
8339
|
index: initialHistoryIndex,
|
@@ -8493,16 +8623,73 @@ var migrations = [
|
|
8493
8623
|
});
|
8494
8624
|
}
|
8495
8625
|
return data;
|
8626
|
+
},
|
8627
|
+
// Migrate zones to slots
|
8628
|
+
(data, config) => {
|
8629
|
+
var _a;
|
8630
|
+
if (!config) return data;
|
8631
|
+
console.log("Migrating DropZones to slots...");
|
8632
|
+
const updatedItems = {};
|
8633
|
+
const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
|
8634
|
+
const { indexes } = walkTree(appState, config);
|
8635
|
+
const deletedCompounds = [];
|
8636
|
+
walkTree(appState, config, (content, zoneCompound, zoneType) => {
|
8637
|
+
var _a2, _b;
|
8638
|
+
if (zoneType === "dropzone") {
|
8639
|
+
const [id, slotName] = zoneCompound.split(":");
|
8640
|
+
const nodeData = indexes.nodes[id].data;
|
8641
|
+
const componentType = nodeData.type;
|
8642
|
+
const configForComponent = config.components[componentType];
|
8643
|
+
if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
|
8644
|
+
updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
|
8645
|
+
props: __spreadProps(__spreadValues({}, nodeData.props), {
|
8646
|
+
[slotName]: content
|
8647
|
+
})
|
8648
|
+
});
|
8649
|
+
deletedCompounds.push(zoneCompound);
|
8650
|
+
}
|
8651
|
+
return content;
|
8652
|
+
}
|
8653
|
+
return content;
|
8654
|
+
});
|
8655
|
+
const updated = walkTree(
|
8656
|
+
appState,
|
8657
|
+
config,
|
8658
|
+
(content) => content,
|
8659
|
+
(item) => {
|
8660
|
+
var _a2;
|
8661
|
+
return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
|
8662
|
+
}
|
8663
|
+
);
|
8664
|
+
deletedCompounds.forEach((zoneCompound) => {
|
8665
|
+
var _a2;
|
8666
|
+
const [_, propName] = zoneCompound.split(":");
|
8667
|
+
console.log(
|
8668
|
+
`\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
|
8669
|
+
);
|
8670
|
+
(_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
|
8671
|
+
});
|
8672
|
+
Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
|
8673
|
+
const [_, propName] = zoneCompound.split(":");
|
8674
|
+
throw new Error(
|
8675
|
+
`Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
|
8676
|
+
);
|
8677
|
+
});
|
8678
|
+
delete updated.data.zones;
|
8679
|
+
return updated.data;
|
8496
8680
|
}
|
8497
8681
|
];
|
8498
|
-
function migrate(data) {
|
8499
|
-
return migrations == null ? void 0 : migrations.reduce(
|
8682
|
+
function migrate(data, config) {
|
8683
|
+
return migrations == null ? void 0 : migrations.reduce(
|
8684
|
+
(acc, migration) => migration(acc, config),
|
8685
|
+
data
|
8686
|
+
);
|
8500
8687
|
}
|
8501
8688
|
|
8502
8689
|
// lib/transform-props.ts
|
8503
8690
|
init_react_import();
|
8504
8691
|
|
8505
|
-
// lib/default-data.ts
|
8692
|
+
// lib/data/default-data.ts
|
8506
8693
|
init_react_import();
|
8507
8694
|
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
8508
8695
|
root: data.root || {},
|
@@ -8545,7 +8732,7 @@ function transformProps(data, propTransforms) {
|
|
8545
8732
|
// lib/resolve-all-data.ts
|
8546
8733
|
init_react_import();
|
8547
8734
|
|
8548
|
-
// lib/to-component.ts
|
8735
|
+
// lib/data/to-component.ts
|
8549
8736
|
init_react_import();
|
8550
8737
|
var toComponent = (item) => {
|
8551
8738
|
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
@@ -8573,17 +8760,29 @@ function resolveAllData(_0, _1) {
|
|
8573
8760
|
"force",
|
8574
8761
|
false
|
8575
8762
|
)).node;
|
8576
|
-
const resolvedDeep = yield
|
8763
|
+
const resolvedDeep = yield mapSlotsAsync(
|
8764
|
+
resolved,
|
8765
|
+
processContent,
|
8766
|
+
false
|
8767
|
+
);
|
8577
8768
|
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
8578
8769
|
return resolvedDeep;
|
8579
8770
|
});
|
8580
8771
|
const processContent = (content) => __async(this, null, function* () {
|
8581
8772
|
return Promise.all(content.map(resolveNode));
|
8582
8773
|
});
|
8774
|
+
const processZones = () => __async(this, null, function* () {
|
8775
|
+
var _a2;
|
8776
|
+
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
8777
|
+
Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
|
8778
|
+
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
8779
|
+
}));
|
8780
|
+
return zones;
|
8781
|
+
});
|
8583
8782
|
const dynamic = {
|
8584
8783
|
root: yield resolveNode(defaultedData.root),
|
8585
8784
|
content: yield processContent(defaultedData.content),
|
8586
|
-
zones:
|
8785
|
+
zones: yield processZones()
|
8587
8786
|
};
|
8588
8787
|
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
|
8589
8788
|
const content = defaultedData.zones[zoneKey];
|
@@ -8607,6 +8806,7 @@ function resolveAllData(_0, _1) {
|
|
8607
8806
|
Puck,
|
8608
8807
|
Render,
|
8609
8808
|
createUsePuck,
|
8809
|
+
mapSlots,
|
8610
8810
|
migrate,
|
8611
8811
|
overrideKeys,
|
8612
8812
|
renderContext,
|