@measured/puck 0.16.0-canary.f761e5f → 0.16.0-canary.fc564d7
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/{actions-DDAd8cys.d.mts → actions-9pHbVtMU.d.mts} +32 -7
- package/dist/{actions-DDAd8cys.d.ts → actions-9pHbVtMU.d.ts} +32 -7
- package/dist/index.css +96 -77
- package/dist/index.d.mts +48 -50
- package/dist/index.d.ts +48 -50
- package/dist/index.js +817 -676
- package/dist/index.mjs +790 -650
- package/dist/rsc.d.mts +1 -1
- package/dist/rsc.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -156,6 +156,7 @@ __export(core_exports, {
|
|
156
156
|
DropZoneProvider: () => DropZoneProvider,
|
157
157
|
FieldLabel: () => FieldLabel,
|
158
158
|
FieldLabelInternal: () => FieldLabelInternal2,
|
159
|
+
Group: () => Group,
|
159
160
|
IconButton: () => IconButton,
|
160
161
|
Puck: () => Puck,
|
161
162
|
Render: () => Render,
|
@@ -242,11 +243,11 @@ var get_class_name_factory_default = getClassNameFactory;
|
|
242
243
|
|
243
244
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ActionBar/styles.module.css#css-module
|
244
245
|
init_react_import();
|
245
|
-
var styles_module_default = { "
|
246
|
+
var styles_module_default = { "ActionBar": "_ActionBar_fp58q_1", "ActionBar-actionsLabel": "_ActionBar-actionsLabel_fp58q_16", "ActionBar-group": "_ActionBar-group_fp58q_29", "ActionBar-action": "_ActionBar-action_fp58q_16" };
|
246
247
|
|
247
248
|
// components/ActionBar/index.tsx
|
248
249
|
var import_jsx_runtime = require("react/jsx-runtime");
|
249
|
-
var getClassName = get_class_name_factory_default("
|
250
|
+
var getClassName = get_class_name_factory_default("ActionBar", styles_module_default);
|
250
251
|
var ActionBar = ({
|
251
252
|
label,
|
252
253
|
children
|
@@ -268,7 +269,9 @@ var Action = ({
|
|
268
269
|
children
|
269
270
|
}
|
270
271
|
);
|
272
|
+
var Group = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: getClassName("group"), children });
|
271
273
|
ActionBar.Action = Action;
|
274
|
+
ActionBar.Group = Group;
|
272
275
|
|
273
276
|
// components/AutoField/index.tsx
|
274
277
|
init_react_import();
|
@@ -278,7 +281,7 @@ init_react_import();
|
|
278
281
|
var styles_module_default2 = { "Input": "_Input_3pq3z_1", "Input-label": "_Input-label_3pq3z_26", "Input-labelIcon": "_Input-labelIcon_3pq3z_35", "Input-disabledIcon": "_Input-disabledIcon_3pq3z_42", "Input-input": "_Input-input_3pq3z_47", "Input--readOnly": "_Input--readOnly_3pq3z_91", "Input-radioGroupItems": "_Input-radioGroupItems_3pq3z_102", "Input-radio": "_Input-radio_3pq3z_102", "Input-radioInner": "_Input-radioInner_3pq3z_119", "Input-radioInput": "_Input-radioInput_3pq3z_164" };
|
279
282
|
|
280
283
|
// components/AutoField/index.tsx
|
281
|
-
var
|
284
|
+
var import_react13 = require("react");
|
282
285
|
|
283
286
|
// components/AutoField/fields/index.tsx
|
284
287
|
init_react_import();
|
@@ -686,7 +689,7 @@ var import_dnd = require("@measured/dnd");
|
|
686
689
|
|
687
690
|
// components/Puck/context.tsx
|
688
691
|
init_react_import();
|
689
|
-
var
|
692
|
+
var import_react6 = require("react");
|
690
693
|
|
691
694
|
// lib/get-item.ts
|
692
695
|
init_react_import();
|
@@ -728,6 +731,332 @@ var defaultViewports = [
|
|
728
731
|
|
729
732
|
// components/Puck/context.tsx
|
730
733
|
var import_ua_parser_js = require("ua-parser-js");
|
734
|
+
|
735
|
+
// lib/use-resolved-permissions.ts
|
736
|
+
init_react_import();
|
737
|
+
var import_react4 = require("react");
|
738
|
+
|
739
|
+
// lib/flatten-data.ts
|
740
|
+
init_react_import();
|
741
|
+
var flattenData = (data) => {
|
742
|
+
return Object.keys(data.zones || {}).reduce(
|
743
|
+
(acc, zone) => [...acc, ...data.zones[zone]],
|
744
|
+
data.content
|
745
|
+
);
|
746
|
+
};
|
747
|
+
|
748
|
+
// lib/get-changed.ts
|
749
|
+
init_react_import();
|
750
|
+
var getChanged = (newItem, oldItem) => {
|
751
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
752
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
753
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
754
|
+
return __spreadProps(__spreadValues({}, acc), {
|
755
|
+
[item]: oldItemProps[item] !== newItemProps[item]
|
756
|
+
});
|
757
|
+
}, {}) : {};
|
758
|
+
};
|
759
|
+
|
760
|
+
// lib/use-resolved-permissions.ts
|
761
|
+
var useResolvedPermissions = (config, appState, globalPermissions, setComponentLoading, unsetComponentLoading) => {
|
762
|
+
const [cache3, setCache] = (0, import_react4.useState)({});
|
763
|
+
const [resolvedPermissions, setResolvedPermissions] = (0, import_react4.useState)({});
|
764
|
+
const resolveDataForItem = (0, import_react4.useCallback)(
|
765
|
+
(item, force = false) => __async(void 0, null, function* () {
|
766
|
+
var _a, _b, _c;
|
767
|
+
setComponentLoading == null ? void 0 : setComponentLoading(item.props.id);
|
768
|
+
const componentConfig = item.type === "root" ? config.root : config.components[item.type];
|
769
|
+
if (!componentConfig) {
|
770
|
+
unsetComponentLoading == null ? void 0 : unsetComponentLoading(item.props.id);
|
771
|
+
return;
|
772
|
+
}
|
773
|
+
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
774
|
+
if (componentConfig.resolvePermissions) {
|
775
|
+
const changed = getChanged(item, (_a = cache3[item.props.id]) == null ? void 0 : _a.lastData);
|
776
|
+
if (Object.values(changed).some((el) => el === true) || force) {
|
777
|
+
const resolvedPermissions2 = yield componentConfig.resolvePermissions(
|
778
|
+
item,
|
779
|
+
{
|
780
|
+
changed,
|
781
|
+
lastPermissions: ((_b = cache3[item.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
782
|
+
permissions: initialPermissions,
|
783
|
+
appState,
|
784
|
+
lastData: ((_c = cache3[item.props.id]) == null ? void 0 : _c.lastData) || null
|
785
|
+
}
|
786
|
+
);
|
787
|
+
setCache((_cache) => __spreadProps(__spreadValues({}, _cache), {
|
788
|
+
[item.props.id]: {
|
789
|
+
lastData: item,
|
790
|
+
lastPermissions: resolvedPermissions2
|
791
|
+
}
|
792
|
+
}));
|
793
|
+
setResolvedPermissions((p) => __spreadProps(__spreadValues({}, p), {
|
794
|
+
[item.props.id]: resolvedPermissions2
|
795
|
+
}));
|
796
|
+
}
|
797
|
+
}
|
798
|
+
unsetComponentLoading == null ? void 0 : unsetComponentLoading(item.props.id);
|
799
|
+
}),
|
800
|
+
[config, globalPermissions, appState, cache3]
|
801
|
+
);
|
802
|
+
const resolveDataForRoot = (force = false) => {
|
803
|
+
resolveDataForItem(
|
804
|
+
// Shim the root data in by conforming to component data shape
|
805
|
+
{
|
806
|
+
type: "root",
|
807
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
|
808
|
+
},
|
809
|
+
force
|
810
|
+
);
|
811
|
+
};
|
812
|
+
const resolvePermissions = (0, import_react4.useCallback)(
|
813
|
+
(..._0) => __async(void 0, [..._0], function* ({ item, type, root } = {}, force = false) {
|
814
|
+
if (item) {
|
815
|
+
yield resolveDataForItem(item, force);
|
816
|
+
} else if (type) {
|
817
|
+
flattenData(appState.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
818
|
+
yield resolveDataForItem(item2, force);
|
819
|
+
}));
|
820
|
+
} else if (root) {
|
821
|
+
resolveDataForRoot(force);
|
822
|
+
} else {
|
823
|
+
resolveDataForRoot(force);
|
824
|
+
flattenData(appState.data).map((item2) => __async(void 0, null, function* () {
|
825
|
+
yield resolveDataForItem(item2, force);
|
826
|
+
}));
|
827
|
+
}
|
828
|
+
}),
|
829
|
+
[config, appState]
|
830
|
+
);
|
831
|
+
const refreshPermissions = (0, import_react4.useCallback)(
|
832
|
+
(params) => __async(void 0, null, function* () {
|
833
|
+
resolvePermissions(params, true);
|
834
|
+
}),
|
835
|
+
[config, appState]
|
836
|
+
);
|
837
|
+
(0, import_react4.useEffect)(() => {
|
838
|
+
resolvePermissions();
|
839
|
+
}, [config, appState.data]);
|
840
|
+
const getPermissions = (0, import_react4.useCallback)(
|
841
|
+
({ item, type, root } = {}) => {
|
842
|
+
if (item) {
|
843
|
+
const componentConfig = config.components[item.type];
|
844
|
+
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
845
|
+
const resolvedForItem = resolvedPermissions[item.props.id];
|
846
|
+
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
847
|
+
} else if (type) {
|
848
|
+
const componentConfig = config.components[type];
|
849
|
+
return __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
850
|
+
} else if (root) {
|
851
|
+
const rootConfig = config.root;
|
852
|
+
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
853
|
+
const resolvedForItem = resolvedPermissions["puck-root"];
|
854
|
+
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
855
|
+
}
|
856
|
+
return globalPermissions;
|
857
|
+
},
|
858
|
+
[config, resolvedPermissions]
|
859
|
+
);
|
860
|
+
return {
|
861
|
+
getPermissions,
|
862
|
+
refreshPermissions
|
863
|
+
};
|
864
|
+
};
|
865
|
+
|
866
|
+
// lib/use-resolved-data.ts
|
867
|
+
init_react_import();
|
868
|
+
var import_react5 = require("react");
|
869
|
+
|
870
|
+
// lib/resolve-component-data.ts
|
871
|
+
init_react_import();
|
872
|
+
var cache = { lastChange: {} };
|
873
|
+
var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
|
874
|
+
return yield Promise.all(
|
875
|
+
content.map((item) => __async(void 0, null, function* () {
|
876
|
+
return yield resolveComponentData(
|
877
|
+
item,
|
878
|
+
config,
|
879
|
+
onResolveStart,
|
880
|
+
onResolveEnd
|
881
|
+
);
|
882
|
+
}))
|
883
|
+
);
|
884
|
+
});
|
885
|
+
var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
|
886
|
+
const configForItem = config.components[item.type];
|
887
|
+
if (configForItem.resolveData) {
|
888
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
|
889
|
+
if (item && item === oldItem) {
|
890
|
+
return resolved;
|
891
|
+
}
|
892
|
+
const changed = getChanged(item, oldItem);
|
893
|
+
if (onResolveStart) {
|
894
|
+
onResolveStart(item);
|
895
|
+
}
|
896
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed, lastData: oldItem });
|
897
|
+
const { readOnly: existingReadOnly = {} } = item || {};
|
898
|
+
const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
|
899
|
+
const resolvedItem = __spreadProps(__spreadValues({}, item), {
|
900
|
+
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
901
|
+
});
|
902
|
+
if (Object.keys(newReadOnly).length) {
|
903
|
+
resolvedItem.readOnly = newReadOnly;
|
904
|
+
}
|
905
|
+
cache.lastChange[item.props.id] = {
|
906
|
+
item,
|
907
|
+
resolved: resolvedItem
|
908
|
+
};
|
909
|
+
if (onResolveEnd) {
|
910
|
+
onResolveEnd(resolvedItem);
|
911
|
+
}
|
912
|
+
return resolvedItem;
|
913
|
+
}
|
914
|
+
return item;
|
915
|
+
});
|
916
|
+
|
917
|
+
// lib/apply-dynamic-props.ts
|
918
|
+
init_react_import();
|
919
|
+
var applyDynamicProps = (data, dynamicProps, rootData) => {
|
920
|
+
return __spreadProps(__spreadValues({}, data), {
|
921
|
+
root: __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}),
|
922
|
+
content: data.content.map((item) => {
|
923
|
+
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
924
|
+
}),
|
925
|
+
zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
|
926
|
+
return __spreadProps(__spreadValues({}, acc), {
|
927
|
+
[zoneKey]: data.zones[zoneKey].map((item) => {
|
928
|
+
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
929
|
+
})
|
930
|
+
});
|
931
|
+
}, {})
|
932
|
+
});
|
933
|
+
};
|
934
|
+
|
935
|
+
// lib/resolve-root-data.ts
|
936
|
+
init_react_import();
|
937
|
+
var cache2 = {};
|
938
|
+
function resolveRootData(data, config) {
|
939
|
+
return __async(this, null, function* () {
|
940
|
+
var _a, _b, _c, _d, _e;
|
941
|
+
if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
|
942
|
+
if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
|
943
|
+
return cache2.lastChange.resolved;
|
944
|
+
}
|
945
|
+
const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
|
946
|
+
const rootWithProps = data.root;
|
947
|
+
const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
|
948
|
+
changed,
|
949
|
+
lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {}
|
950
|
+
});
|
951
|
+
cache2.lastChange = {
|
952
|
+
original: data.root,
|
953
|
+
resolved: resolvedRoot
|
954
|
+
};
|
955
|
+
return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
|
956
|
+
props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
|
957
|
+
});
|
958
|
+
}
|
959
|
+
return data.root;
|
960
|
+
});
|
961
|
+
}
|
962
|
+
|
963
|
+
// lib/use-resolved-data.ts
|
964
|
+
var useResolvedData = (appState, config, dispatch, setComponentLoading, unsetComponentLoading, refreshPermissions) => {
|
965
|
+
const [{ resolverKey, newAppState }, setResolverState] = (0, import_react5.useState)({
|
966
|
+
resolverKey: 0,
|
967
|
+
newAppState: appState
|
968
|
+
});
|
969
|
+
const deferredSetStates = {};
|
970
|
+
const _setComponentLoading = (0, import_react5.useCallback)(
|
971
|
+
(id, loading, defer2 = 0) => {
|
972
|
+
if (deferredSetStates[id]) {
|
973
|
+
clearTimeout(deferredSetStates[id]);
|
974
|
+
delete deferredSetStates[id];
|
975
|
+
}
|
976
|
+
deferredSetStates[id] = setTimeout(() => {
|
977
|
+
if (loading) {
|
978
|
+
setComponentLoading(id);
|
979
|
+
} else {
|
980
|
+
unsetComponentLoading(id);
|
981
|
+
}
|
982
|
+
delete deferredSetStates[id];
|
983
|
+
}, defer2);
|
984
|
+
},
|
985
|
+
[]
|
986
|
+
);
|
987
|
+
const runResolvers = () => __async(void 0, null, function* () {
|
988
|
+
const newData = newAppState.data;
|
989
|
+
const flatContent = flattenData(newData).filter(
|
990
|
+
(item) => {
|
991
|
+
var _a;
|
992
|
+
return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
|
993
|
+
}
|
994
|
+
);
|
995
|
+
const applyIfChange = (dynamicDataMap, dynamicRoot) => {
|
996
|
+
const processed = applyDynamicProps(
|
997
|
+
appState.data,
|
998
|
+
dynamicDataMap,
|
999
|
+
dynamicRoot
|
1000
|
+
);
|
1001
|
+
const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
|
1002
|
+
const containsChanges = JSON.stringify(appState) !== JSON.stringify(processedAppState);
|
1003
|
+
if (containsChanges) {
|
1004
|
+
dispatch({
|
1005
|
+
type: "set",
|
1006
|
+
state: (prev) => __spreadProps(__spreadValues({}, prev), {
|
1007
|
+
data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
|
1008
|
+
ui: resolverKey > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
|
1009
|
+
}),
|
1010
|
+
recordHistory: resolverKey > 0
|
1011
|
+
});
|
1012
|
+
}
|
1013
|
+
};
|
1014
|
+
const promises = [];
|
1015
|
+
promises.push(
|
1016
|
+
(() => __async(void 0, null, function* () {
|
1017
|
+
_setComponentLoading("puck-root", true, 50);
|
1018
|
+
const dynamicRoot = yield resolveRootData(newData, config);
|
1019
|
+
applyIfChange({}, dynamicRoot);
|
1020
|
+
_setComponentLoading("puck-root", false);
|
1021
|
+
}))()
|
1022
|
+
);
|
1023
|
+
flatContent.forEach((item) => {
|
1024
|
+
promises.push(
|
1025
|
+
(() => __async(void 0, null, function* () {
|
1026
|
+
refreshPermissions({ item });
|
1027
|
+
const dynamicData = yield resolveComponentData(
|
1028
|
+
item,
|
1029
|
+
config,
|
1030
|
+
(item2) => {
|
1031
|
+
_setComponentLoading(item2.props.id, true, 50);
|
1032
|
+
},
|
1033
|
+
(item2) => {
|
1034
|
+
deferredSetStates[item2.props.id];
|
1035
|
+
_setComponentLoading(item2.props.id, false);
|
1036
|
+
}
|
1037
|
+
);
|
1038
|
+
const dynamicDataMap = { [item.props.id]: dynamicData };
|
1039
|
+
applyIfChange(dynamicDataMap);
|
1040
|
+
}))()
|
1041
|
+
);
|
1042
|
+
});
|
1043
|
+
yield Promise.all(promises);
|
1044
|
+
});
|
1045
|
+
(0, import_react5.useEffect)(() => {
|
1046
|
+
runResolvers();
|
1047
|
+
}, [resolverKey]);
|
1048
|
+
const resolveData = (0, import_react5.useCallback)((newAppState2 = appState) => {
|
1049
|
+
setResolverState((curr) => ({
|
1050
|
+
resolverKey: curr.resolverKey + 1,
|
1051
|
+
newAppState: newAppState2
|
1052
|
+
}));
|
1053
|
+
}, []);
|
1054
|
+
return {
|
1055
|
+
resolveData
|
1056
|
+
};
|
1057
|
+
};
|
1058
|
+
|
1059
|
+
// components/Puck/context.tsx
|
731
1060
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
732
1061
|
var defaultAppState = {
|
733
1062
|
data: { content: [], root: {} },
|
@@ -753,6 +1082,8 @@ var defaultContext = {
|
|
753
1082
|
dispatch: () => null,
|
754
1083
|
config: { components: {} },
|
755
1084
|
componentState: {},
|
1085
|
+
setComponentState: () => {
|
1086
|
+
},
|
756
1087
|
resolveData: () => {
|
757
1088
|
},
|
758
1089
|
plugins: [],
|
@@ -769,20 +1100,22 @@ var defaultContext = {
|
|
769
1100
|
setStatus: () => null,
|
770
1101
|
iframe: {},
|
771
1102
|
safariFallbackMode: false,
|
772
|
-
globalPermissions: {}
|
1103
|
+
globalPermissions: {},
|
1104
|
+
getPermissions: () => ({}),
|
1105
|
+
refreshPermissions: () => null
|
773
1106
|
};
|
774
|
-
var appContext = (0,
|
1107
|
+
var appContext = (0, import_react6.createContext)(defaultContext);
|
775
1108
|
var AppProvider = ({
|
776
1109
|
children,
|
777
1110
|
value
|
778
1111
|
}) => {
|
779
|
-
const [zoomConfig, setZoomConfig] = (0,
|
780
|
-
const [status, setStatus] = (0,
|
781
|
-
(0,
|
1112
|
+
const [zoomConfig, setZoomConfig] = (0, import_react6.useState)(defaultContext.zoomConfig);
|
1113
|
+
const [status, setStatus] = (0, import_react6.useState)("LOADING");
|
1114
|
+
(0, import_react6.useEffect)(() => {
|
782
1115
|
setStatus("MOUNTED");
|
783
1116
|
}, []);
|
784
|
-
const [safariFallbackMode, setSafariFallbackMode] = (0,
|
785
|
-
(0,
|
1117
|
+
const [safariFallbackMode, setSafariFallbackMode] = (0, import_react6.useState)(false);
|
1118
|
+
(0, import_react6.useEffect)(() => {
|
786
1119
|
var _a, _b, _c;
|
787
1120
|
const ua = new import_ua_parser_js.UAParser(navigator.userAgent);
|
788
1121
|
const { browser } = ua.getResult();
|
@@ -799,26 +1132,67 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
|
|
799
1132
|
setSafariFallbackMode(true);
|
800
1133
|
}
|
801
1134
|
}, []);
|
1135
|
+
const selectedItem = value.state.ui.itemSelector ? getItem(value.state.ui.itemSelector, value.state.data) : void 0;
|
1136
|
+
const [componentState, setComponentState] = (0, import_react6.useState)({});
|
1137
|
+
const setComponentLoading = (id) => {
|
1138
|
+
setComponentState((prev) => {
|
1139
|
+
var _a;
|
1140
|
+
return __spreadProps(__spreadValues({}, prev), {
|
1141
|
+
[id]: __spreadProps(__spreadValues({}, prev[id]), {
|
1142
|
+
loadingCount: (((_a = prev[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
|
1143
|
+
})
|
1144
|
+
});
|
1145
|
+
});
|
1146
|
+
};
|
1147
|
+
const unsetComponentLoading = (id) => {
|
1148
|
+
setComponentState((prev) => {
|
1149
|
+
var _a;
|
1150
|
+
return __spreadProps(__spreadValues({}, prev), {
|
1151
|
+
[id]: __spreadProps(__spreadValues({}, prev[id]), {
|
1152
|
+
loadingCount: Math.max((((_a = prev[id]) == null ? void 0 : _a.loadingCount) || 0) - 1, 0)
|
1153
|
+
})
|
1154
|
+
});
|
1155
|
+
});
|
1156
|
+
};
|
1157
|
+
const { getPermissions, refreshPermissions } = useResolvedPermissions(
|
1158
|
+
value.config,
|
1159
|
+
value.state,
|
1160
|
+
value.globalPermissions || {},
|
1161
|
+
setComponentLoading,
|
1162
|
+
unsetComponentLoading
|
1163
|
+
);
|
1164
|
+
const { resolveData } = useResolvedData(
|
1165
|
+
value.state,
|
1166
|
+
value.config,
|
1167
|
+
value.dispatch,
|
1168
|
+
setComponentLoading,
|
1169
|
+
unsetComponentLoading,
|
1170
|
+
refreshPermissions
|
1171
|
+
);
|
802
1172
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
803
1173
|
appContext.Provider,
|
804
1174
|
{
|
805
1175
|
value: __spreadProps(__spreadValues({}, value), {
|
1176
|
+
selectedItem,
|
806
1177
|
zoomConfig,
|
807
1178
|
setZoomConfig,
|
808
1179
|
status,
|
809
1180
|
setStatus,
|
810
|
-
safariFallbackMode
|
1181
|
+
safariFallbackMode,
|
1182
|
+
getPermissions,
|
1183
|
+
refreshPermissions,
|
1184
|
+
componentState,
|
1185
|
+
setComponentState,
|
1186
|
+
resolveData
|
811
1187
|
}),
|
812
1188
|
children
|
813
1189
|
}
|
814
1190
|
);
|
815
1191
|
};
|
816
1192
|
function useAppContext() {
|
817
|
-
const mainContext = (0,
|
818
|
-
const selectedItem = mainContext.state.ui.itemSelector ? getItem(mainContext.state.ui.itemSelector, mainContext.state.data) : void 0;
|
1193
|
+
const mainContext = (0, import_react6.useContext)(appContext);
|
819
1194
|
return __spreadProps(__spreadValues({}, mainContext), {
|
820
1195
|
// Helpers
|
821
|
-
selectedItem,
|
822
1196
|
setUi: (ui, recordHistory) => {
|
823
1197
|
return mainContext.dispatch({
|
824
1198
|
type: "setUi",
|
@@ -920,7 +1294,7 @@ var Draggable = ({
|
|
920
1294
|
};
|
921
1295
|
|
922
1296
|
// components/AutoField/fields/ArrayField/index.tsx
|
923
|
-
var
|
1297
|
+
var import_react7 = require("react");
|
924
1298
|
|
925
1299
|
// components/DragIcon/index.tsx
|
926
1300
|
init_react_import();
|
@@ -959,7 +1333,7 @@ var ArrayField = ({
|
|
959
1333
|
id,
|
960
1334
|
Label = (props) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", __spreadValues({}, props))
|
961
1335
|
}) => {
|
962
|
-
const { state, setUi, selectedItem } = useAppContext();
|
1336
|
+
const { state, setUi, selectedItem, getPermissions } = useAppContext();
|
963
1337
|
const readOnlyFields = (selectedItem == null ? void 0 : selectedItem.readOnly) || {};
|
964
1338
|
const value = _value;
|
965
1339
|
const arrayState = state.ui.arrayState[id] || {
|
@@ -971,11 +1345,11 @@ var ArrayField = ({
|
|
971
1345
|
}),
|
972
1346
|
openId: ""
|
973
1347
|
};
|
974
|
-
const [localState, setLocalState] = (0,
|
975
|
-
(0,
|
1348
|
+
const [localState, setLocalState] = (0, import_react7.useState)({ arrayState, value });
|
1349
|
+
(0, import_react7.useEffect)(() => {
|
976
1350
|
setLocalState({ arrayState, value });
|
977
1351
|
}, [value, state.ui.arrayState[id]]);
|
978
|
-
const mapArrayStateToUi = (0,
|
1352
|
+
const mapArrayStateToUi = (0, import_react7.useCallback)(
|
979
1353
|
(partialArrayState) => {
|
980
1354
|
return {
|
981
1355
|
arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
|
@@ -985,13 +1359,13 @@ var ArrayField = ({
|
|
985
1359
|
},
|
986
1360
|
[arrayState]
|
987
1361
|
);
|
988
|
-
const getHighestIndex = (0,
|
1362
|
+
const getHighestIndex = (0, import_react7.useCallback)(() => {
|
989
1363
|
return arrayState.items.reduce(
|
990
1364
|
(acc, item) => item._originalIndex > acc ? item._originalIndex : acc,
|
991
1365
|
-1
|
992
1366
|
);
|
993
1367
|
}, [arrayState]);
|
994
|
-
const regenerateArrayState = (0,
|
1368
|
+
const regenerateArrayState = (0, import_react7.useCallback)(
|
995
1369
|
(value2) => {
|
996
1370
|
let highestIndex = getHighestIndex();
|
997
1371
|
const newItems = Array.from(value2 || []).map((item, idx) => {
|
@@ -1010,12 +1384,13 @@ var ArrayField = ({
|
|
1010
1384
|
},
|
1011
1385
|
[arrayState]
|
1012
1386
|
);
|
1013
|
-
(0,
|
1387
|
+
(0, import_react7.useEffect)(() => {
|
1014
1388
|
if (arrayState.items.length > 0) {
|
1015
1389
|
setUi(mapArrayStateToUi(arrayState));
|
1016
1390
|
}
|
1017
1391
|
}, []);
|
1018
|
-
const [hovering, setHovering] = (0,
|
1392
|
+
const [hovering, setHovering] = (0, import_react7.useState)(false);
|
1393
|
+
const forceReadOnly = getPermissions({ item: selectedItem }).edit === false;
|
1019
1394
|
if (field.type !== "array" || !field.arrayFields) {
|
1020
1395
|
return null;
|
1021
1396
|
}
|
@@ -1146,13 +1521,14 @@ var ArrayField = ({
|
|
1146
1521
|
const subField = field.arrayFields[fieldName];
|
1147
1522
|
const subFieldName = `${name}[${i}].${fieldName}`;
|
1148
1523
|
const wildcardFieldName = `${name}[*].${fieldName}`;
|
1524
|
+
const subReadOnly = forceReadOnly ? forceReadOnly : typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName];
|
1149
1525
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
1150
1526
|
AutoFieldPrivate,
|
1151
1527
|
{
|
1152
1528
|
name: subFieldName,
|
1153
1529
|
label: subField.label || fieldName,
|
1154
1530
|
id: `${_arrayId}_${fieldName}`,
|
1155
|
-
readOnly:
|
1531
|
+
readOnly: subReadOnly,
|
1156
1532
|
field: subField,
|
1157
1533
|
value: data[fieldName],
|
1158
1534
|
onChange: (val, ui) => {
|
@@ -1252,19 +1628,19 @@ var DefaultField = ({
|
|
1252
1628
|
|
1253
1629
|
// components/AutoField/fields/ExternalField/index.tsx
|
1254
1630
|
init_react_import();
|
1255
|
-
var
|
1631
|
+
var import_react11 = require("react");
|
1256
1632
|
|
1257
1633
|
// components/ExternalInput/index.tsx
|
1258
1634
|
init_react_import();
|
1259
|
-
var
|
1635
|
+
var import_react10 = require("react");
|
1260
1636
|
|
1261
1637
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css#css-module
|
1262
1638
|
init_react_import();
|
1263
|
-
var styles_module_default6 = { "ExternalInput-actions": "_ExternalInput-
|
1639
|
+
var styles_module_default6 = { "ExternalInput-actions": "_ExternalInput-actions_wprq3_1", "ExternalInput-button": "_ExternalInput-button_wprq3_5", "ExternalInput--dataSelected": "_ExternalInput--dataSelected_wprq3_24", "ExternalInput--readOnly": "_ExternalInput--readOnly_wprq3_31", "ExternalInput-detachButton": "_ExternalInput-detachButton_wprq3_35", "ExternalInput": "_ExternalInput_wprq3_1", "ExternalInputModal": "_ExternalInputModal_wprq3_79", "ExternalInputModal-grid": "_ExternalInputModal-grid_wprq3_89", "ExternalInputModal--filtersToggled": "_ExternalInputModal--filtersToggled_wprq3_100", "ExternalInputModal-filters": "_ExternalInputModal-filters_wprq3_105", "ExternalInputModal-masthead": "_ExternalInputModal-masthead_wprq3_124", "ExternalInputModal-tableWrapper": "_ExternalInputModal-tableWrapper_wprq3_133", "ExternalInputModal-table": "_ExternalInputModal-table_wprq3_133", "ExternalInputModal-thead": "_ExternalInputModal-thead_wprq3_149", "ExternalInputModal-th": "_ExternalInputModal-th_wprq3_149", "ExternalInputModal-td": "_ExternalInputModal-td_wprq3_164", "ExternalInputModal-tr": "_ExternalInputModal-tr_wprq3_169", "ExternalInputModal-tbody": "_ExternalInputModal-tbody_wprq3_176", "ExternalInputModal--hasData": "_ExternalInputModal--hasData_wprq3_202", "ExternalInputModal-loadingBanner": "_ExternalInputModal-loadingBanner_wprq3_206", "ExternalInputModal--isLoading": "_ExternalInputModal--isLoading_wprq3_223", "ExternalInputModal-searchForm": "_ExternalInputModal-searchForm_wprq3_227", "ExternalInputModal-search": "_ExternalInputModal-search_wprq3_227", "ExternalInputModal-searchIcon": "_ExternalInputModal-searchIcon_wprq3_264", "ExternalInputModal-searchIconText": "_ExternalInputModal-searchIconText_wprq3_289", "ExternalInputModal-searchInput": "_ExternalInputModal-searchInput_wprq3_299", "ExternalInputModal-searchActions": "_ExternalInputModal-searchActions_wprq3_313", "ExternalInputModal-searchActionIcon": "_ExternalInputModal-searchActionIcon_wprq3_326", "ExternalInputModal-footer": "_ExternalInputModal-footer_wprq3_330" };
|
1264
1640
|
|
1265
1641
|
// components/Modal/index.tsx
|
1266
1642
|
init_react_import();
|
1267
|
-
var
|
1643
|
+
var import_react8 = require("react");
|
1268
1644
|
|
1269
1645
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Modal/styles.module.css#css-module
|
1270
1646
|
init_react_import();
|
@@ -1279,8 +1655,8 @@ var Modal = ({
|
|
1279
1655
|
onClose,
|
1280
1656
|
isOpen
|
1281
1657
|
}) => {
|
1282
|
-
const [rootEl, setRootEl] = (0,
|
1283
|
-
(0,
|
1658
|
+
const [rootEl, setRootEl] = (0, import_react8.useState)(null);
|
1659
|
+
(0, import_react8.useEffect)(() => {
|
1284
1660
|
setRootEl(document.getElementById("puck-portal-root"));
|
1285
1661
|
}, []);
|
1286
1662
|
if (!rootEl) {
|
@@ -1327,7 +1703,7 @@ init_react_import();
|
|
1327
1703
|
|
1328
1704
|
// components/Button/Button.tsx
|
1329
1705
|
init_react_import();
|
1330
|
-
var
|
1706
|
+
var import_react9 = require("react");
|
1331
1707
|
|
1332
1708
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Button/Button.module.css#css-module
|
1333
1709
|
init_react_import();
|
@@ -1350,8 +1726,8 @@ var Button = ({
|
|
1350
1726
|
size = "medium",
|
1351
1727
|
loading: loadingProp = false
|
1352
1728
|
}) => {
|
1353
|
-
const [loading, setLoading] = (0,
|
1354
|
-
(0,
|
1729
|
+
const [loading, setLoading] = (0, import_react9.useState)(loadingProp);
|
1730
|
+
(0, import_react9.useEffect)(() => setLoading(loadingProp), [loadingProp]);
|
1355
1731
|
const ElementType = href ? "a" : type ? "button" : "span";
|
1356
1732
|
const el = /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
1357
1733
|
ElementType,
|
@@ -1396,23 +1772,24 @@ var ExternalInput = ({
|
|
1396
1772
|
onChange,
|
1397
1773
|
value = null,
|
1398
1774
|
name,
|
1399
|
-
id
|
1775
|
+
id,
|
1776
|
+
readOnly
|
1400
1777
|
}) => {
|
1401
1778
|
const {
|
1402
1779
|
mapProp = (val) => val,
|
1403
1780
|
mapRow = (val) => val,
|
1404
1781
|
filterFields
|
1405
1782
|
} = field || {};
|
1406
|
-
const [data, setData] = (0,
|
1407
|
-
const [isOpen, setOpen] = (0,
|
1408
|
-
const [isLoading, setIsLoading] = (0,
|
1783
|
+
const [data, setData] = (0, import_react10.useState)([]);
|
1784
|
+
const [isOpen, setOpen] = (0, import_react10.useState)(false);
|
1785
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(true);
|
1409
1786
|
const hasFilterFields = !!filterFields;
|
1410
|
-
const [filters, setFilters] = (0,
|
1411
|
-
const [filtersToggled, setFiltersToggled] = (0,
|
1412
|
-
const mappedData = (0,
|
1787
|
+
const [filters, setFilters] = (0, import_react10.useState)(field.initialFilters || {});
|
1788
|
+
const [filtersToggled, setFiltersToggled] = (0, import_react10.useState)(hasFilterFields);
|
1789
|
+
const mappedData = (0, import_react10.useMemo)(() => {
|
1413
1790
|
return data.map(mapRow);
|
1414
1791
|
}, [data]);
|
1415
|
-
const keys = (0,
|
1792
|
+
const keys = (0, import_react10.useMemo)(() => {
|
1416
1793
|
const validKeys = /* @__PURE__ */ new Set();
|
1417
1794
|
for (const item of mappedData) {
|
1418
1795
|
for (const key of Object.keys(item)) {
|
@@ -1423,8 +1800,8 @@ var ExternalInput = ({
|
|
1423
1800
|
}
|
1424
1801
|
return Array.from(validKeys);
|
1425
1802
|
}, [mappedData]);
|
1426
|
-
const [searchQuery, setSearchQuery] = (0,
|
1427
|
-
const search = (0,
|
1803
|
+
const [searchQuery, setSearchQuery] = (0, import_react10.useState)(field.initialQuery || "");
|
1804
|
+
const search = (0, import_react10.useCallback)(
|
1428
1805
|
(query, filters2) => __async(void 0, null, function* () {
|
1429
1806
|
setIsLoading(true);
|
1430
1807
|
const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
|
@@ -1437,7 +1814,7 @@ var ExternalInput = ({
|
|
1437
1814
|
}),
|
1438
1815
|
[id, field]
|
1439
1816
|
);
|
1440
|
-
(0,
|
1817
|
+
(0, import_react10.useEffect)(() => {
|
1441
1818
|
search(searchQuery, filters);
|
1442
1819
|
}, []);
|
1443
1820
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
@@ -1445,7 +1822,8 @@ var ExternalInput = ({
|
|
1445
1822
|
{
|
1446
1823
|
className: getClassName10({
|
1447
1824
|
dataSelected: !!value,
|
1448
|
-
modalVisible: isOpen
|
1825
|
+
modalVisible: isOpen,
|
1826
|
+
readOnly
|
1449
1827
|
}),
|
1450
1828
|
id,
|
1451
1829
|
children: [
|
@@ -1456,6 +1834,7 @@ var ExternalInput = ({
|
|
1456
1834
|
type: "button",
|
1457
1835
|
onClick: () => setOpen(true),
|
1458
1836
|
className: getClassName10("button"),
|
1837
|
+
disabled: readOnly,
|
1459
1838
|
children: value ? field.getItemSummary ? field.getItemSummary(value) : "External item" : /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
1460
1839
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Link, { size: "16" }),
|
1461
1840
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: field.placeholder })
|
@@ -1470,6 +1849,7 @@ var ExternalInput = ({
|
|
1470
1849
|
onClick: () => {
|
1471
1850
|
onChange(null);
|
1472
1851
|
},
|
1852
|
+
disabled: readOnly,
|
1473
1853
|
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Unlock, { size: 16 })
|
1474
1854
|
}
|
1475
1855
|
)
|
@@ -1595,12 +1975,13 @@ var ExternalField = ({
|
|
1595
1975
|
name,
|
1596
1976
|
label,
|
1597
1977
|
Label,
|
1598
|
-
id
|
1978
|
+
id,
|
1979
|
+
readOnly
|
1599
1980
|
}) => {
|
1600
1981
|
var _a, _b, _c;
|
1601
1982
|
const validField = field;
|
1602
1983
|
const deprecatedField = field;
|
1603
|
-
(0,
|
1984
|
+
(0, import_react11.useEffect)(() => {
|
1604
1985
|
if (deprecatedField.adaptor) {
|
1605
1986
|
console.error(
|
1606
1987
|
"Warning: The `adaptor` API is deprecated. Please use updated APIs on the `external` field instead. This will be a breaking change in a future release."
|
@@ -1627,7 +2008,8 @@ var ExternalField = ({
|
|
1627
2008
|
}),
|
1628
2009
|
onChange,
|
1629
2010
|
value,
|
1630
|
-
id
|
2011
|
+
id,
|
2012
|
+
readOnly
|
1631
2013
|
}
|
1632
2014
|
) });
|
1633
2015
|
};
|
@@ -1808,13 +2190,14 @@ var ObjectField = ({
|
|
1808
2190
|
const subField = field.objectFields[fieldName];
|
1809
2191
|
const subFieldName = `${name}.${fieldName}`;
|
1810
2192
|
const wildcardFieldName = `${name}.${fieldName}`;
|
2193
|
+
const subReadOnly = readOnly ? readOnly : typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName];
|
1811
2194
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
1812
2195
|
AutoFieldPrivate,
|
1813
2196
|
{
|
1814
2197
|
name: subFieldName,
|
1815
2198
|
label: subField.label || fieldName,
|
1816
2199
|
id: `${id}_${fieldName}`,
|
1817
|
-
readOnly:
|
2200
|
+
readOnly: subReadOnly,
|
1818
2201
|
field: subField,
|
1819
2202
|
value: data[fieldName],
|
1820
2203
|
onChange: (val, ui) => {
|
@@ -1835,7 +2218,7 @@ var ObjectField = ({
|
|
1835
2218
|
|
1836
2219
|
// lib/use-safe-id.ts
|
1837
2220
|
init_react_import();
|
1838
|
-
var
|
2221
|
+
var import_react12 = __toESM(require("react"));
|
1839
2222
|
|
1840
2223
|
// lib/generate-id.ts
|
1841
2224
|
init_react_import();
|
@@ -1844,10 +2227,10 @@ var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, impor
|
|
1844
2227
|
|
1845
2228
|
// lib/use-safe-id.ts
|
1846
2229
|
var useSafeId = () => {
|
1847
|
-
if (typeof
|
1848
|
-
return
|
2230
|
+
if (typeof import_react12.default.useId !== "undefined") {
|
2231
|
+
return import_react12.default.useId();
|
1849
2232
|
}
|
1850
|
-
const [id] = (0,
|
2233
|
+
const [id] = (0, import_react12.useState)(generateId());
|
1851
2234
|
return id;
|
1852
2235
|
};
|
1853
2236
|
|
@@ -1880,7 +2263,7 @@ var FieldLabelInternal2 = ({
|
|
1880
2263
|
readOnly
|
1881
2264
|
}) => {
|
1882
2265
|
const { overrides } = useAppContext();
|
1883
|
-
const Wrapper = (0,
|
2266
|
+
const Wrapper = (0, import_react13.useMemo)(
|
1884
2267
|
() => overrides.fieldLabel || FieldLabel,
|
1885
2268
|
[overrides]
|
1886
2269
|
);
|
@@ -1944,7 +2327,7 @@ function AutoFieldInternal(props) {
|
|
1944
2327
|
}
|
1945
2328
|
function AutoFieldPrivate(props) {
|
1946
2329
|
const { value, onChange } = props;
|
1947
|
-
const [localValue, setLocalValue] = (0,
|
2330
|
+
const [localValue, setLocalValue] = (0, import_react13.useState)(value);
|
1948
2331
|
const onChangeDb = (0, import_use_debounce.useDebouncedCallback)(
|
1949
2332
|
(val, ui) => {
|
1950
2333
|
onChange(val, ui);
|
@@ -1952,11 +2335,11 @@ function AutoFieldPrivate(props) {
|
|
1952
2335
|
50,
|
1953
2336
|
{ leading: true }
|
1954
2337
|
);
|
1955
|
-
const onChangeLocal = (0,
|
2338
|
+
const onChangeLocal = (0, import_react13.useCallback)((val, ui) => {
|
1956
2339
|
setLocalValue(val);
|
1957
2340
|
onChangeDb(val, ui);
|
1958
2341
|
}, []);
|
1959
|
-
(0,
|
2342
|
+
(0, import_react13.useEffect)(() => {
|
1960
2343
|
setLocalValue(value);
|
1961
2344
|
}, [value]);
|
1962
2345
|
const localProps = {
|
@@ -1975,14 +2358,14 @@ init_react_import();
|
|
1975
2358
|
|
1976
2359
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Drawer/styles.module.css#css-module
|
1977
2360
|
init_react_import();
|
1978
|
-
var styles_module_default10 = { "Drawer": "
|
2361
|
+
var styles_module_default10 = { "Drawer": "_Drawer_1oa7v_1", "DrawerItem--disabled": "_DrawerItem--disabled_1oa7v_5", "DrawerItem-draggable": "_DrawerItem-draggable_1oa7v_5", "DrawerItem-default": "_DrawerItem-default_1oa7v_11", "DrawerItem-draggableWrapper": "_DrawerItem-draggableWrapper_1oa7v_11", "DrawerItem": "_DrawerItem_1oa7v_5", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_1oa7v_36", "DrawerItem-name": "_DrawerItem-name_1oa7v_54" };
|
1979
2362
|
|
1980
2363
|
// components/Drawer/index.tsx
|
1981
|
-
var
|
2364
|
+
var import_react14 = require("react");
|
1982
2365
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
1983
2366
|
var getClassName16 = get_class_name_factory_default("Drawer", styles_module_default10);
|
1984
2367
|
var getClassNameItem2 = get_class_name_factory_default("DrawerItem", styles_module_default10);
|
1985
|
-
var drawerContext = (0,
|
2368
|
+
var drawerContext = (0, import_react14.createContext)({
|
1986
2369
|
droppableId: ""
|
1987
2370
|
});
|
1988
2371
|
var DrawerDraggable = ({
|
@@ -2013,9 +2396,9 @@ var DrawerItem = ({
|
|
2013
2396
|
index,
|
2014
2397
|
isDragDisabled
|
2015
2398
|
}) => {
|
2016
|
-
const ctx = (0,
|
2399
|
+
const ctx = (0, import_react14.useContext)(drawerContext);
|
2017
2400
|
const resolvedId = `${ctx.droppableId}::${id || name}`;
|
2018
|
-
const CustomInner = (0,
|
2401
|
+
const CustomInner = (0, import_react14.useMemo)(
|
2019
2402
|
() => children || (({ children: children2, name: name2 }) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassNameItem2("default"), children: children2 })),
|
2020
2403
|
[children]
|
2021
2404
|
);
|
@@ -2056,11 +2439,11 @@ Drawer.Item = DrawerItem;
|
|
2056
2439
|
|
2057
2440
|
// components/DropZone/index.tsx
|
2058
2441
|
init_react_import();
|
2059
|
-
var
|
2442
|
+
var import_react18 = require("react");
|
2060
2443
|
|
2061
2444
|
// components/DraggableComponent/index.tsx
|
2062
2445
|
init_react_import();
|
2063
|
-
var
|
2446
|
+
var import_react16 = require("react");
|
2064
2447
|
var import_dnd4 = require("@measured/dnd");
|
2065
2448
|
|
2066
2449
|
// css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
|
@@ -2069,10 +2452,10 @@ var styles_module_default11 = { "DraggableComponent": "_DraggableComponent_1bhad
|
|
2069
2452
|
|
2070
2453
|
// lib/use-modifier-held.ts
|
2071
2454
|
init_react_import();
|
2072
|
-
var
|
2455
|
+
var import_react15 = require("react");
|
2073
2456
|
var useModifierHeld = (modifier) => {
|
2074
|
-
const [modifierHeld, setModifierHeld] = (0,
|
2075
|
-
(0,
|
2457
|
+
const [modifierHeld, setModifierHeld] = (0, import_react15.useState)(false);
|
2458
|
+
(0, import_react15.useEffect)(() => {
|
2076
2459
|
function downHandler({ key }) {
|
2077
2460
|
if (key === modifier) {
|
2078
2461
|
setModifierHeld(true);
|
@@ -2110,90 +2493,6 @@ init_react_import();
|
|
2110
2493
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
2111
2494
|
var DefaultOverride = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_jsx_runtime22.Fragment, { children });
|
2112
2495
|
|
2113
|
-
// lib/get-permissions.ts
|
2114
|
-
init_react_import();
|
2115
|
-
|
2116
|
-
// lib/get-changed.ts
|
2117
|
-
init_react_import();
|
2118
|
-
var getChanged = (newItem, oldItem) => {
|
2119
|
-
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
2120
|
-
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
2121
|
-
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
2122
|
-
return __spreadProps(__spreadValues({}, acc), {
|
2123
|
-
[item]: oldItemProps[item] !== newItemProps[item]
|
2124
|
-
});
|
2125
|
-
}, {}) : {};
|
2126
|
-
};
|
2127
|
-
|
2128
|
-
// lib/resolve-permissions.ts
|
2129
|
-
init_react_import();
|
2130
|
-
var resolvePermissions = ({
|
2131
|
-
selectedItem,
|
2132
|
-
config,
|
2133
|
-
changed,
|
2134
|
-
lastPermissions,
|
2135
|
-
initialPermissions,
|
2136
|
-
appState
|
2137
|
-
}) => {
|
2138
|
-
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
2139
|
-
if (selectedItem && (componentConfig == null ? void 0 : componentConfig.resolvePermissions)) {
|
2140
|
-
return componentConfig.resolvePermissions(selectedItem, {
|
2141
|
-
changed,
|
2142
|
-
lastPermissions,
|
2143
|
-
initialPermissions,
|
2144
|
-
appState
|
2145
|
-
});
|
2146
|
-
}
|
2147
|
-
return {};
|
2148
|
-
};
|
2149
|
-
|
2150
|
-
// lib/get-permissions.ts
|
2151
|
-
var cache = { lastPermissions: {}, lastSelected: {} };
|
2152
|
-
var getPermissions = ({
|
2153
|
-
selectedItem,
|
2154
|
-
type,
|
2155
|
-
globalPermissions,
|
2156
|
-
config,
|
2157
|
-
appState
|
2158
|
-
}) => {
|
2159
|
-
const componentType = type || selectedItem && selectedItem.type || "";
|
2160
|
-
const componentId = selectedItem && selectedItem.props.id || "";
|
2161
|
-
let componentPermissions = getInitialPermissions({
|
2162
|
-
componentType,
|
2163
|
-
config,
|
2164
|
-
globalPermissions
|
2165
|
-
});
|
2166
|
-
const changed = getChanged(selectedItem, cache.lastSelected);
|
2167
|
-
if (Object.values(changed).some((el) => el === true)) {
|
2168
|
-
const resolvedPermissions = resolvePermissions({
|
2169
|
-
selectedItem,
|
2170
|
-
config,
|
2171
|
-
changed,
|
2172
|
-
lastPermissions: cache.lastPermissions[componentId] || componentPermissions,
|
2173
|
-
initialPermissions: componentPermissions,
|
2174
|
-
appState
|
2175
|
-
});
|
2176
|
-
if (resolvedPermissions !== void 0) {
|
2177
|
-
componentPermissions = __spreadValues(__spreadValues({}, componentPermissions), resolvedPermissions);
|
2178
|
-
}
|
2179
|
-
cache.lastSelected = selectedItem;
|
2180
|
-
cache.lastPermissions[componentId] = componentPermissions;
|
2181
|
-
return componentPermissions;
|
2182
|
-
}
|
2183
|
-
if (Object.keys(componentId && cache.lastPermissions[componentId]).length !== 0) {
|
2184
|
-
componentPermissions = cache.lastPermissions[componentId];
|
2185
|
-
}
|
2186
|
-
return componentPermissions;
|
2187
|
-
};
|
2188
|
-
var getInitialPermissions = ({
|
2189
|
-
componentType,
|
2190
|
-
globalPermissions,
|
2191
|
-
config
|
2192
|
-
}) => {
|
2193
|
-
var _a;
|
2194
|
-
return __spreadValues(__spreadValues({}, globalPermissions), (_a = config.components[componentType]) == null ? void 0 : _a.permissions);
|
2195
|
-
};
|
2196
|
-
|
2197
2496
|
// components/DraggableComponent/index.tsx
|
2198
2497
|
var import_jsx_runtime23 = require("react/jsx-runtime");
|
2199
2498
|
var getClassName17 = get_class_name_factory_default("DraggableComponent", styles_module_default11);
|
@@ -2204,7 +2503,7 @@ var actionsRight = space;
|
|
2204
2503
|
var DefaultActionBar = ({
|
2205
2504
|
label,
|
2206
2505
|
children
|
2207
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ActionBar, { label, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DefaultOverride, { children }) });
|
2506
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ActionBar, { label, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ActionBar.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DefaultOverride, { children }) }) });
|
2208
2507
|
var DraggableComponent = ({
|
2209
2508
|
children,
|
2210
2509
|
id,
|
@@ -2227,34 +2526,22 @@ var DraggableComponent = ({
|
|
2227
2526
|
indicativeHover = false,
|
2228
2527
|
style
|
2229
2528
|
}) => {
|
2230
|
-
const {
|
2231
|
-
zoomConfig,
|
2232
|
-
status,
|
2233
|
-
overrides,
|
2234
|
-
plugins,
|
2235
|
-
selectedItem,
|
2236
|
-
config,
|
2237
|
-
globalPermissions,
|
2238
|
-
state
|
2239
|
-
} = useAppContext();
|
2529
|
+
const { zoomConfig, status, overrides, selectedItem, getPermissions } = useAppContext();
|
2240
2530
|
const isModifierHeld = useModifierHeld("Alt");
|
2241
2531
|
const El = status !== "LOADING" ? import_dnd4.Draggable : DefaultDraggable;
|
2242
|
-
(0,
|
2243
|
-
const [disableSecondaryAnimation, setDisableSecondaryAnimation] = (0,
|
2244
|
-
(0,
|
2532
|
+
(0, import_react16.useEffect)(onMount, []);
|
2533
|
+
const [disableSecondaryAnimation, setDisableSecondaryAnimation] = (0, import_react16.useState)(false);
|
2534
|
+
(0, import_react16.useEffect)(() => {
|
2245
2535
|
if (isIos()) {
|
2246
2536
|
setDisableSecondaryAnimation(true);
|
2247
2537
|
}
|
2248
2538
|
}, []);
|
2249
|
-
const CustomActionBar = (0,
|
2539
|
+
const CustomActionBar = (0, import_react16.useMemo)(
|
2250
2540
|
() => overrides.actionBar || DefaultActionBar,
|
2251
2541
|
[overrides.actionBar]
|
2252
2542
|
);
|
2253
|
-
const permissions =
|
2254
|
-
selectedItem
|
2255
|
-
globalPermissions: globalPermissions || {},
|
2256
|
-
config,
|
2257
|
-
appState: state
|
2543
|
+
const permissions = getPermissions({
|
2544
|
+
item: selectedItem
|
2258
2545
|
});
|
2259
2546
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
2260
2547
|
El,
|
@@ -2277,7 +2564,7 @@ var DraggableComponent = ({
|
|
2277
2564
|
indicativeHover
|
2278
2565
|
}),
|
2279
2566
|
style: __spreadProps(__spreadValues(__spreadValues({}, style), provided.draggableProps.style), {
|
2280
|
-
cursor: isModifierHeld || isDragDisabled ? "
|
2567
|
+
cursor: isModifierHeld || isDragDisabled ? "pointer" : "grab"
|
2281
2568
|
}),
|
2282
2569
|
onMouseOver,
|
2283
2570
|
onMouseOut,
|
@@ -2304,8 +2591,8 @@ var DraggableComponent = ({
|
|
2304
2591
|
right: actionsRight / zoomConfig.zoom
|
2305
2592
|
},
|
2306
2593
|
children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(CustomActionBar, { label, children: [
|
2307
|
-
permissions
|
2308
|
-
permissions
|
2594
|
+
permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Copy, { size: 16 }) }),
|
2595
|
+
permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Trash, { size: 16 }) })
|
2309
2596
|
] })
|
2310
2597
|
}
|
2311
2598
|
)
|
@@ -2327,7 +2614,7 @@ var styles_module_default12 = { "DropZone": "_DropZone_djoti_1", "DropZone-conte
|
|
2327
2614
|
|
2328
2615
|
// components/DropZone/context.tsx
|
2329
2616
|
init_react_import();
|
2330
|
-
var
|
2617
|
+
var import_react17 = require("react");
|
2331
2618
|
var import_use_debounce2 = require("use-debounce");
|
2332
2619
|
|
2333
2620
|
// lib/get-zone-id.ts
|
@@ -2344,29 +2631,29 @@ var getZoneId = (zoneCompound) => {
|
|
2344
2631
|
|
2345
2632
|
// components/DropZone/context.tsx
|
2346
2633
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
2347
|
-
var dropZoneContext = (0,
|
2634
|
+
var dropZoneContext = (0, import_react17.createContext)(null);
|
2348
2635
|
var DropZoneProvider = ({
|
2349
2636
|
children,
|
2350
2637
|
value
|
2351
2638
|
}) => {
|
2352
|
-
const [hoveringArea, setHoveringArea] = (0,
|
2353
|
-
const [hoveringZone, setHoveringZone] = (0,
|
2639
|
+
const [hoveringArea, setHoveringArea] = (0, import_react17.useState)(null);
|
2640
|
+
const [hoveringZone, setHoveringZone] = (0, import_react17.useState)(
|
2354
2641
|
rootDroppableId
|
2355
2642
|
);
|
2356
|
-
const [hoveringComponent, setHoveringComponent] = (0,
|
2643
|
+
const [hoveringComponent, setHoveringComponent] = (0, import_react17.useState)();
|
2357
2644
|
const [hoveringAreaDb] = (0, import_use_debounce2.useDebounce)(hoveringArea, 75, { leading: false });
|
2358
|
-
const [areasWithZones, setAreasWithZones] = (0,
|
2645
|
+
const [areasWithZones, setAreasWithZones] = (0, import_react17.useState)(
|
2359
2646
|
{}
|
2360
2647
|
);
|
2361
|
-
const [activeZones, setActiveZones] = (0,
|
2648
|
+
const [activeZones, setActiveZones] = (0, import_react17.useState)({});
|
2362
2649
|
const { dispatch = null } = value ? value : {};
|
2363
|
-
const registerZoneArea = (0,
|
2650
|
+
const registerZoneArea = (0, import_react17.useCallback)(
|
2364
2651
|
(area) => {
|
2365
2652
|
setAreasWithZones((latest) => __spreadProps(__spreadValues({}, latest), { [area]: true }));
|
2366
2653
|
},
|
2367
2654
|
[setAreasWithZones]
|
2368
2655
|
);
|
2369
|
-
const registerZone = (0,
|
2656
|
+
const registerZone = (0, import_react17.useCallback)(
|
2370
2657
|
(zoneCompound) => {
|
2371
2658
|
if (!dispatch) {
|
2372
2659
|
return;
|
@@ -2379,7 +2666,7 @@ var DropZoneProvider = ({
|
|
2379
2666
|
},
|
2380
2667
|
[setActiveZones, dispatch]
|
2381
2668
|
);
|
2382
|
-
const unregisterZone = (0,
|
2669
|
+
const unregisterZone = (0, import_react17.useCallback)(
|
2383
2670
|
(zoneCompound) => {
|
2384
2671
|
if (!dispatch) {
|
2385
2672
|
return;
|
@@ -2394,8 +2681,8 @@ var DropZoneProvider = ({
|
|
2394
2681
|
},
|
2395
2682
|
[setActiveZones, dispatch]
|
2396
2683
|
);
|
2397
|
-
const [pathData, setPathData] = (0,
|
2398
|
-
const registerPath = (0,
|
2684
|
+
const [pathData, setPathData] = (0, import_react17.useState)();
|
2685
|
+
const registerPath = (0, import_react17.useCallback)(
|
2399
2686
|
(selector) => {
|
2400
2687
|
if (!(value == null ? void 0 : value.data)) {
|
2401
2688
|
return;
|
@@ -2420,7 +2707,7 @@ var DropZoneProvider = ({
|
|
2420
2707
|
},
|
2421
2708
|
[value, setPathData]
|
2422
2709
|
);
|
2423
|
-
const [zoneWillDrag, setZoneWillDrag] = (0,
|
2710
|
+
const [zoneWillDrag, setZoneWillDrag] = (0, import_react17.useState)("");
|
2424
2711
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_jsx_runtime24.Fragment, { children: value && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
2425
2712
|
dropZoneContext.Provider,
|
2426
2713
|
{
|
@@ -2452,7 +2739,7 @@ var getClassName18 = get_class_name_factory_default("DropZone", styles_module_de
|
|
2452
2739
|
function DropZoneEdit({ zone, allow, disallow, style }) {
|
2453
2740
|
var _a;
|
2454
2741
|
const appContext2 = useAppContext();
|
2455
|
-
const ctx = (0,
|
2742
|
+
const ctx = (0, import_react18.useContext)(dropZoneContext);
|
2456
2743
|
const {
|
2457
2744
|
// These all need setting via context
|
2458
2745
|
data,
|
@@ -2471,12 +2758,12 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
|
|
2471
2758
|
} = ctx || {};
|
2472
2759
|
let content = data.content || [];
|
2473
2760
|
let zoneCompound = rootDroppableId;
|
2474
|
-
(0,
|
2761
|
+
(0, import_react18.useEffect)(() => {
|
2475
2762
|
if (areaId && registerZoneArea) {
|
2476
2763
|
registerZoneArea(areaId);
|
2477
2764
|
}
|
2478
2765
|
}, [areaId]);
|
2479
|
-
(0,
|
2766
|
+
(0, import_react18.useEffect)(() => {
|
2480
2767
|
if (ctx == null ? void 0 : ctx.registerZone) {
|
2481
2768
|
ctx == null ? void 0 : ctx.registerZone(zoneCompound);
|
2482
2769
|
}
|
@@ -2603,14 +2890,11 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
|
|
2603
2890
|
] });
|
2604
2891
|
const componentConfig = config.components[item.type];
|
2605
2892
|
const label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
|
2606
|
-
const canDrag = getPermissions({
|
2607
|
-
|
2893
|
+
const canDrag = appContext2.getPermissions({
|
2894
|
+
item: getItem(
|
2608
2895
|
{ index: i, zone: zoneCompound },
|
2609
2896
|
appContext2.state.data
|
2610
|
-
)
|
2611
|
-
config: appContext2.config,
|
2612
|
-
globalPermissions: appContext2.globalPermissions || {},
|
2613
|
-
appState: appContext2.state
|
2897
|
+
)
|
2614
2898
|
}).drag;
|
2615
2899
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
2616
2900
|
"div",
|
@@ -2635,7 +2919,7 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
|
|
2635
2919
|
forceHover: hoveringComponent === componentId && !userIsDragging,
|
2636
2920
|
isDragDisabled: !canDrag,
|
2637
2921
|
indicativeHover: userIsDragging && containsZone && hoveringArea === componentId,
|
2638
|
-
isLoading: (_c = appContext2.componentState[componentId]) == null ? void 0 : _c.
|
2922
|
+
isLoading: ((_c = appContext2.componentState[componentId]) == null ? void 0 : _c.loadingCount) > 0,
|
2639
2923
|
onMount: () => {
|
2640
2924
|
ctx.registerPath({
|
2641
2925
|
index: i,
|
@@ -2735,7 +3019,7 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
|
|
2735
3019
|
);
|
2736
3020
|
}
|
2737
3021
|
function DropZoneRender({ zone }) {
|
2738
|
-
const ctx = (0,
|
3022
|
+
const ctx = (0, import_react18.useContext)(dropZoneContext);
|
2739
3023
|
const { data, areaId = "root", config } = ctx || {};
|
2740
3024
|
let zoneCompound = rootDroppableId;
|
2741
3025
|
let content = (data == null ? void 0 : data.content) || [];
|
@@ -2767,7 +3051,7 @@ function DropZoneRender({ zone }) {
|
|
2767
3051
|
}) });
|
2768
3052
|
}
|
2769
3053
|
function DropZone(props) {
|
2770
|
-
const ctx = (0,
|
3054
|
+
const ctx = (0, import_react18.useContext)(dropZoneContext);
|
2771
3055
|
if ((ctx == null ? void 0 : ctx.mode) === "edit") {
|
2772
3056
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DropZoneEdit, __spreadValues({}, props));
|
2773
3057
|
}
|
@@ -2776,11 +3060,11 @@ function DropZone(props) {
|
|
2776
3060
|
|
2777
3061
|
// components/Puck/index.tsx
|
2778
3062
|
init_react_import();
|
2779
|
-
var
|
3063
|
+
var import_react32 = require("react");
|
2780
3064
|
|
2781
3065
|
// lib/use-placeholder-style.ts
|
2782
3066
|
init_react_import();
|
2783
|
-
var
|
3067
|
+
var import_react19 = require("react");
|
2784
3068
|
|
2785
3069
|
// lib/get-frame.ts
|
2786
3070
|
init_react_import();
|
@@ -2795,7 +3079,7 @@ var getFrame = () => {
|
|
2795
3079
|
// lib/use-placeholder-style.ts
|
2796
3080
|
var usePlaceholderStyle = () => {
|
2797
3081
|
const queryAttr = "data-rfd-drag-handle-draggable-id";
|
2798
|
-
const [placeholderStyle, setPlaceholderStyle] = (0,
|
3082
|
+
const [placeholderStyle, setPlaceholderStyle] = (0, import_react19.useState)();
|
2799
3083
|
const onDragStartOrUpdate = (draggedItem) => {
|
2800
3084
|
var _a;
|
2801
3085
|
const draggableId = draggedItem.draggableId;
|
@@ -2848,7 +3132,7 @@ var styles_module_default13 = { "SidebarSection": "_SidebarSection_125qe_1", "Si
|
|
2848
3132
|
|
2849
3133
|
// lib/use-breadcrumbs.ts
|
2850
3134
|
init_react_import();
|
2851
|
-
var
|
3135
|
+
var import_react20 = require("react");
|
2852
3136
|
var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
|
2853
3137
|
const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
|
2854
3138
|
const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
|
@@ -2898,8 +3182,8 @@ var useBreadcrumbs = (renderCount) => {
|
|
2898
3182
|
state: { data },
|
2899
3183
|
selectedItem
|
2900
3184
|
} = useAppContext();
|
2901
|
-
const dzContext = (0,
|
2902
|
-
return (0,
|
3185
|
+
const dzContext = (0, import_react20.useContext)(dropZoneContext);
|
3186
|
+
return (0, import_react20.useMemo)(() => {
|
2903
3187
|
const breadcrumbs = convertPathDataToBreadcrumbs(
|
2904
3188
|
selectedItem,
|
2905
3189
|
dzContext == null ? void 0 : dzContext.pathData,
|
@@ -3245,270 +3529,80 @@ function reduceData(data, action, config) {
|
|
3245
3529
|
}
|
3246
3530
|
return data;
|
3247
3531
|
}
|
3248
|
-
|
3249
|
-
// reducer/state.ts
|
3250
|
-
init_react_import();
|
3251
|
-
var reduceUi = (ui, action) => {
|
3252
|
-
if (action.type === "setUi") {
|
3253
|
-
if (typeof action.ui === "object") {
|
3254
|
-
return __spreadValues(__spreadValues({}, ui), action.ui);
|
3255
|
-
}
|
3256
|
-
return __spreadValues(__spreadValues({}, ui), action.ui(ui));
|
3257
|
-
}
|
3258
|
-
return ui;
|
3259
|
-
};
|
3260
|
-
|
3261
|
-
// reducer/actions.tsx
|
3262
|
-
init_react_import();
|
3263
|
-
|
3264
|
-
// reducer/index.ts
|
3265
|
-
function storeInterceptor(reducer, record, onAction) {
|
3266
|
-
return (state, action) => {
|
3267
|
-
const newAppState = reducer(state, action);
|
3268
|
-
const isValidType = ![
|
3269
|
-
"registerZone",
|
3270
|
-
"unregisterZone",
|
3271
|
-
"setData",
|
3272
|
-
"setUi",
|
3273
|
-
"set"
|
3274
|
-
].includes(action.type);
|
3275
|
-
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
3276
|
-
if (record) record(newAppState);
|
3277
|
-
}
|
3278
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
3279
|
-
return newAppState;
|
3280
|
-
};
|
3281
|
-
}
|
3282
|
-
var setAction = (state, action) => {
|
3283
|
-
if (typeof action.state === "object") {
|
3284
|
-
return __spreadValues(__spreadValues({}, state), action.state);
|
3285
|
-
}
|
3286
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
3287
|
-
};
|
3288
|
-
function createReducer({
|
3289
|
-
config,
|
3290
|
-
record,
|
3291
|
-
onAction
|
3292
|
-
}) {
|
3293
|
-
return storeInterceptor(
|
3294
|
-
(state, action) => {
|
3295
|
-
const data = reduceData(state.data, action, config);
|
3296
|
-
const ui = reduceUi(state.ui, action);
|
3297
|
-
if (action.type === "set") {
|
3298
|
-
return setAction(state, action);
|
3299
|
-
}
|
3300
|
-
return { data, ui };
|
3301
|
-
},
|
3302
|
-
record,
|
3303
|
-
onAction
|
3304
|
-
);
|
3305
|
-
}
|
3306
|
-
|
3307
|
-
// lib/flush-zones.ts
|
3308
|
-
init_react_import();
|
3309
|
-
var flushZones = (appState) => {
|
3310
|
-
const containsZones = typeof appState.data.zones !== "undefined";
|
3311
|
-
if (containsZones) {
|
3312
|
-
Object.keys(appState.data.zones || {}).forEach((zone) => {
|
3313
|
-
addToZoneCache(zone, appState.data.zones[zone]);
|
3314
|
-
});
|
3315
|
-
return __spreadProps(__spreadValues({}, appState), {
|
3316
|
-
data: __spreadProps(__spreadValues({}, appState.data), {
|
3317
|
-
zones: {}
|
3318
|
-
})
|
3319
|
-
});
|
3320
|
-
}
|
3321
|
-
return appState;
|
3322
|
-
};
|
3323
|
-
|
3324
|
-
// lib/use-resolved-data.ts
|
3325
|
-
init_react_import();
|
3326
|
-
var import_react19 = require("react");
|
3327
|
-
|
3328
|
-
// lib/resolve-component-data.ts
|
3329
|
-
init_react_import();
|
3330
|
-
var cache2 = { lastChange: {} };
|
3331
|
-
var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
|
3332
|
-
return yield Promise.all(
|
3333
|
-
content.map((item) => __async(void 0, null, function* () {
|
3334
|
-
return yield resolveComponentData(
|
3335
|
-
item,
|
3336
|
-
config,
|
3337
|
-
onResolveStart,
|
3338
|
-
onResolveEnd
|
3339
|
-
);
|
3340
|
-
}))
|
3341
|
-
);
|
3342
|
-
});
|
3343
|
-
var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
|
3344
|
-
const configForItem = config.components[item.type];
|
3345
|
-
if (configForItem.resolveData) {
|
3346
|
-
const { item: oldItem = {}, resolved = {} } = cache2.lastChange[item.props.id] || {};
|
3347
|
-
if (item && item === oldItem) {
|
3348
|
-
return resolved;
|
3349
|
-
}
|
3350
|
-
const changed = getChanged(item, oldItem);
|
3351
|
-
if (onResolveStart) {
|
3352
|
-
onResolveStart(item);
|
3353
|
-
}
|
3354
|
-
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed, lastData: oldItem });
|
3355
|
-
const { readOnly: existingReadOnly = {} } = item || {};
|
3356
|
-
const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
|
3357
|
-
const resolvedItem = __spreadProps(__spreadValues({}, item), {
|
3358
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
3359
|
-
});
|
3360
|
-
if (Object.keys(newReadOnly).length) {
|
3361
|
-
resolvedItem.readOnly = newReadOnly;
|
3362
|
-
}
|
3363
|
-
cache2.lastChange[item.props.id] = {
|
3364
|
-
item,
|
3365
|
-
resolved: resolvedItem
|
3366
|
-
};
|
3367
|
-
if (onResolveEnd) {
|
3368
|
-
onResolveEnd(resolvedItem);
|
3369
|
-
}
|
3370
|
-
return resolvedItem;
|
3371
|
-
}
|
3372
|
-
return item;
|
3373
|
-
});
|
3374
|
-
|
3375
|
-
// lib/apply-dynamic-props.ts
|
3376
|
-
init_react_import();
|
3377
|
-
var applyDynamicProps = (data, dynamicProps, rootData) => {
|
3378
|
-
return __spreadProps(__spreadValues({}, data), {
|
3379
|
-
root: __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}),
|
3380
|
-
content: data.content.map((item) => {
|
3381
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
3382
|
-
}),
|
3383
|
-
zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
|
3384
|
-
return __spreadProps(__spreadValues({}, acc), {
|
3385
|
-
[zoneKey]: data.zones[zoneKey].map((item) => {
|
3386
|
-
return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
|
3387
|
-
})
|
3388
|
-
});
|
3389
|
-
}, {})
|
3390
|
-
});
|
3532
|
+
|
3533
|
+
// reducer/state.ts
|
3534
|
+
init_react_import();
|
3535
|
+
var reduceUi = (ui, action) => {
|
3536
|
+
if (action.type === "setUi") {
|
3537
|
+
if (typeof action.ui === "object") {
|
3538
|
+
return __spreadValues(__spreadValues({}, ui), action.ui);
|
3539
|
+
}
|
3540
|
+
return __spreadValues(__spreadValues({}, ui), action.ui(ui));
|
3541
|
+
}
|
3542
|
+
return ui;
|
3391
3543
|
};
|
3392
3544
|
|
3393
|
-
//
|
3545
|
+
// reducer/actions.tsx
|
3394
3546
|
init_react_import();
|
3395
|
-
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
|
3400
|
-
|
3401
|
-
|
3402
|
-
|
3403
|
-
|
3404
|
-
|
3405
|
-
|
3406
|
-
|
3407
|
-
|
3408
|
-
|
3409
|
-
cache3.lastChange = {
|
3410
|
-
original: data.root,
|
3411
|
-
resolved: resolvedRoot
|
3412
|
-
};
|
3413
|
-
return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
|
3414
|
-
props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
|
3415
|
-
});
|
3547
|
+
|
3548
|
+
// reducer/index.ts
|
3549
|
+
function storeInterceptor(reducer, record, onAction) {
|
3550
|
+
return (state, action) => {
|
3551
|
+
const newAppState = reducer(state, action);
|
3552
|
+
const isValidType = ![
|
3553
|
+
"registerZone",
|
3554
|
+
"unregisterZone",
|
3555
|
+
"setData",
|
3556
|
+
"setUi",
|
3557
|
+
"set"
|
3558
|
+
].includes(action.type);
|
3559
|
+
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
3560
|
+
if (record) record(newAppState);
|
3416
3561
|
}
|
3417
|
-
|
3418
|
-
|
3562
|
+
onAction == null ? void 0 : onAction(action, newAppState, state);
|
3563
|
+
return newAppState;
|
3564
|
+
};
|
3419
3565
|
}
|
3420
|
-
|
3421
|
-
|
3422
|
-
|
3423
|
-
|
3424
|
-
|
3425
|
-
|
3426
|
-
|
3427
|
-
|
3428
|
-
|
3429
|
-
|
3430
|
-
|
3431
|
-
|
3432
|
-
|
3433
|
-
|
3566
|
+
var setAction = (state, action) => {
|
3567
|
+
if (typeof action.state === "object") {
|
3568
|
+
return __spreadValues(__spreadValues({}, state), action.state);
|
3569
|
+
}
|
3570
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
3571
|
+
};
|
3572
|
+
function createReducer({
|
3573
|
+
config,
|
3574
|
+
record,
|
3575
|
+
onAction
|
3576
|
+
}) {
|
3577
|
+
return storeInterceptor(
|
3578
|
+
(state, action) => {
|
3579
|
+
const data = reduceData(state.data, action, config);
|
3580
|
+
const ui = reduceUi(state.ui, action);
|
3581
|
+
if (action.type === "set") {
|
3582
|
+
return setAction(state, action);
|
3434
3583
|
}
|
3435
|
-
|
3436
|
-
setComponentState((prev) => __spreadProps(__spreadValues({}, prev), {
|
3437
|
-
[id]: __spreadProps(__spreadValues({}, prev[id]), { loading })
|
3438
|
-
}));
|
3439
|
-
delete deferredSetStates[id];
|
3440
|
-
}, defer2);
|
3584
|
+
return { data, ui };
|
3441
3585
|
},
|
3442
|
-
|
3586
|
+
record,
|
3587
|
+
onAction
|
3443
3588
|
);
|
3444
|
-
|
3445
|
-
|
3446
|
-
|
3447
|
-
|
3448
|
-
|
3589
|
+
}
|
3590
|
+
|
3591
|
+
// lib/flush-zones.ts
|
3592
|
+
init_react_import();
|
3593
|
+
var flushZones = (appState) => {
|
3594
|
+
const containsZones = typeof appState.data.zones !== "undefined";
|
3595
|
+
if (containsZones) {
|
3596
|
+
Object.keys(appState.data.zones || {}).forEach((zone) => {
|
3597
|
+
addToZoneCache(zone, appState.data.zones[zone]);
|
3449
3598
|
});
|
3450
|
-
|
3451
|
-
|
3452
|
-
|
3453
|
-
|
3454
|
-
dynamicRoot
|
3455
|
-
);
|
3456
|
-
const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
|
3457
|
-
const containsChanges = JSON.stringify(appState) !== JSON.stringify(processedAppState);
|
3458
|
-
if (containsChanges) {
|
3459
|
-
dispatch({
|
3460
|
-
type: "set",
|
3461
|
-
state: (prev) => __spreadProps(__spreadValues({}, prev), {
|
3462
|
-
data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
|
3463
|
-
ui: resolverKey > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
|
3464
|
-
}),
|
3465
|
-
recordHistory: resolverKey > 0
|
3466
|
-
});
|
3467
|
-
}
|
3468
|
-
};
|
3469
|
-
const promises = [];
|
3470
|
-
promises.push(
|
3471
|
-
(() => __async(void 0, null, function* () {
|
3472
|
-
setComponentLoading("puck-root", true, 50);
|
3473
|
-
const dynamicRoot = yield resolveRootData(newData, config);
|
3474
|
-
applyIfChange({}, dynamicRoot);
|
3475
|
-
setComponentLoading("puck-root", false);
|
3476
|
-
}))()
|
3477
|
-
);
|
3478
|
-
flatContent.forEach((item) => {
|
3479
|
-
promises.push(
|
3480
|
-
(() => __async(void 0, null, function* () {
|
3481
|
-
const dynamicData = yield resolveComponentData(
|
3482
|
-
item,
|
3483
|
-
config,
|
3484
|
-
(item2) => {
|
3485
|
-
setComponentLoading(item2.props.id, true, 50);
|
3486
|
-
},
|
3487
|
-
(item2) => {
|
3488
|
-
deferredSetStates[item2.props.id];
|
3489
|
-
setComponentLoading(item2.props.id, false);
|
3490
|
-
}
|
3491
|
-
);
|
3492
|
-
const dynamicDataMap = { [item.props.id]: dynamicData };
|
3493
|
-
applyIfChange(dynamicDataMap);
|
3494
|
-
}))()
|
3495
|
-
);
|
3599
|
+
return __spreadProps(__spreadValues({}, appState), {
|
3600
|
+
data: __spreadProps(__spreadValues({}, appState.data), {
|
3601
|
+
zones: {}
|
3602
|
+
})
|
3496
3603
|
});
|
3497
|
-
|
3498
|
-
|
3499
|
-
(0, import_react19.useEffect)(() => {
|
3500
|
-
runResolvers();
|
3501
|
-
}, [resolverKey]);
|
3502
|
-
const resolveData = (0, import_react19.useCallback)((newAppState2 = appState) => {
|
3503
|
-
setResolverState((curr) => ({
|
3504
|
-
resolverKey: curr.resolverKey + 1,
|
3505
|
-
newAppState: newAppState2
|
3506
|
-
}));
|
3507
|
-
}, []);
|
3508
|
-
return {
|
3509
|
-
resolveData,
|
3510
|
-
componentState
|
3511
|
-
};
|
3604
|
+
}
|
3605
|
+
return appState;
|
3512
3606
|
};
|
3513
3607
|
|
3514
3608
|
// components/MenuBar/index.tsx
|
@@ -3573,7 +3667,7 @@ init_react_import();
|
|
3573
3667
|
var styles_module_default16 = { "PuckFields": "_PuckFields_jp3lw_1", "PuckFields--isLoading": "_PuckFields--isLoading_jp3lw_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_jp3lw_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_jp3lw_25" };
|
3574
3668
|
|
3575
3669
|
// components/Puck/components/Fields/index.tsx
|
3576
|
-
var
|
3670
|
+
var import_react21 = require("react");
|
3577
3671
|
var import_jsx_runtime28 = require("react/jsx-runtime");
|
3578
3672
|
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
3579
3673
|
var defaultPageFields = {
|
@@ -3592,15 +3686,15 @@ var useResolvedFields = () => {
|
|
3592
3686
|
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
3593
3687
|
const defaultFields = selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields;
|
3594
3688
|
const rootProps = data.root.props || data.root;
|
3595
|
-
const [lastSelectedData, setLastSelectedData] = (0,
|
3596
|
-
const [resolvedFields, setResolvedFields] = (0,
|
3597
|
-
const [fieldsLoading, setFieldsLoading] = (0,
|
3689
|
+
const [lastSelectedData, setLastSelectedData] = (0, import_react21.useState)({});
|
3690
|
+
const [resolvedFields, setResolvedFields] = (0, import_react21.useState)(defaultFields || {});
|
3691
|
+
const [fieldsLoading, setFieldsLoading] = (0, import_react21.useState)(false);
|
3598
3692
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
3599
3693
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
3600
|
-
const resolveFields = (0,
|
3694
|
+
const resolveFields = (0, import_react21.useCallback)(
|
3601
3695
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
3602
3696
|
var _a2, _b, _c;
|
3603
|
-
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData :
|
3697
|
+
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
3604
3698
|
const changed = getChanged(componentData, lastData);
|
3605
3699
|
setLastSelectedData(componentData);
|
3606
3700
|
if (selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields)) {
|
@@ -3633,13 +3727,13 @@ var useResolvedFields = () => {
|
|
3633
3727
|
}),
|
3634
3728
|
[data, config, componentData, selectedItem, resolvedFields, state]
|
3635
3729
|
);
|
3636
|
-
(0,
|
3730
|
+
(0, import_react21.useEffect)(() => {
|
3637
3731
|
setFieldsLoading(true);
|
3638
3732
|
resolveFields(defaultFields).then((fields) => {
|
3639
3733
|
setResolvedFields(fields || {});
|
3640
3734
|
setFieldsLoading(false);
|
3641
3735
|
});
|
3642
|
-
}, [data, defaultFields]);
|
3736
|
+
}, [data, defaultFields, state.ui.itemSelector]);
|
3643
3737
|
return [resolvedFields, fieldsLoading];
|
3644
3738
|
};
|
3645
3739
|
var Fields = () => {
|
@@ -3651,16 +3745,16 @@ var Fields = () => {
|
|
3651
3745
|
config,
|
3652
3746
|
resolveData,
|
3653
3747
|
componentState,
|
3654
|
-
overrides
|
3655
|
-
globalPermissions
|
3748
|
+
overrides
|
3656
3749
|
} = useAppContext();
|
3657
3750
|
const { data, ui } = state;
|
3658
3751
|
const { itemSelector } = ui;
|
3659
3752
|
const [fields, fieldsResolving] = useResolvedFields();
|
3660
|
-
const
|
3753
|
+
const { getPermissions } = useAppContext();
|
3754
|
+
const componentResolving = selectedItem ? ((_a = componentState[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a.loadingCount) > 0 : ((_b = componentState["puck-root"]) == null ? void 0 : _b.loadingCount) > 0;
|
3661
3755
|
const isLoading = fieldsResolving || componentResolving;
|
3662
3756
|
const rootProps = data.root.props || data.root;
|
3663
|
-
const Wrapper = (0,
|
3757
|
+
const Wrapper = (0, import_react21.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
|
3664
3758
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
3665
3759
|
"form",
|
3666
3760
|
{
|
@@ -3737,10 +3831,7 @@ var Fields = () => {
|
|
3737
3831
|
if (selectedItem && itemSelector) {
|
3738
3832
|
const { readOnly = {} } = selectedItem;
|
3739
3833
|
const { edit } = getPermissions({
|
3740
|
-
selectedItem
|
3741
|
-
config,
|
3742
|
-
globalPermissions: globalPermissions || {},
|
3743
|
-
appState: state
|
3834
|
+
item: selectedItem
|
3744
3835
|
});
|
3745
3836
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
3746
3837
|
AutoFieldPrivate,
|
@@ -3756,13 +3847,16 @@ var Fields = () => {
|
|
3756
3847
|
);
|
3757
3848
|
} else {
|
3758
3849
|
const readOnly = data.root.readOnly || {};
|
3850
|
+
const { edit } = getPermissions({
|
3851
|
+
root: true
|
3852
|
+
});
|
3759
3853
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
3760
3854
|
AutoFieldPrivate,
|
3761
3855
|
{
|
3762
3856
|
field,
|
3763
3857
|
name: fieldName,
|
3764
3858
|
id: `root_${fieldName}`,
|
3765
|
-
readOnly: readOnly[fieldName],
|
3859
|
+
readOnly: !edit || readOnly[fieldName],
|
3766
3860
|
value: rootProps[fieldName],
|
3767
3861
|
onChange
|
3768
3862
|
},
|
@@ -3781,7 +3875,7 @@ init_react_import();
|
|
3781
3875
|
|
3782
3876
|
// lib/use-component-list.tsx
|
3783
3877
|
init_react_import();
|
3784
|
-
var
|
3878
|
+
var import_react22 = require("react");
|
3785
3879
|
|
3786
3880
|
// components/ComponentList/index.tsx
|
3787
3881
|
init_react_import();
|
@@ -3798,12 +3892,9 @@ var ComponentListItem = ({
|
|
3798
3892
|
label,
|
3799
3893
|
index
|
3800
3894
|
}) => {
|
3801
|
-
const { overrides,
|
3895
|
+
const { overrides, getPermissions } = useAppContext();
|
3802
3896
|
const canInsert = getPermissions({
|
3803
|
-
type: name
|
3804
|
-
config,
|
3805
|
-
globalPermissions: globalPermissions || {},
|
3806
|
-
appState: state
|
3897
|
+
type: name
|
3807
3898
|
}).insert;
|
3808
3899
|
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
3809
3900
|
Drawer.Item,
|
@@ -3862,8 +3953,8 @@ ComponentList.Item = ComponentListItem;
|
|
3862
3953
|
// lib/use-component-list.tsx
|
3863
3954
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
3864
3955
|
var useComponentList = (config, ui) => {
|
3865
|
-
const [componentList, setComponentList] = (0,
|
3866
|
-
(0,
|
3956
|
+
const [componentList, setComponentList] = (0, import_react22.useState)();
|
3957
|
+
(0, import_react22.useEffect)(() => {
|
3867
3958
|
var _a, _b, _c;
|
3868
3959
|
if (Object.keys(ui.componentList).length > 0) {
|
3869
3960
|
const matchedComponents = [];
|
@@ -3932,22 +4023,22 @@ var useComponentList = (config, ui) => {
|
|
3932
4023
|
};
|
3933
4024
|
|
3934
4025
|
// components/Puck/components/Components/index.tsx
|
3935
|
-
var
|
4026
|
+
var import_react23 = require("react");
|
3936
4027
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
3937
4028
|
var Components = () => {
|
3938
4029
|
const { config, state, overrides } = useAppContext();
|
3939
4030
|
const componentList = useComponentList(config, state.ui);
|
3940
|
-
const Wrapper = (0,
|
4031
|
+
const Wrapper = (0, import_react23.useMemo)(() => overrides.components || "div", [overrides]);
|
3941
4032
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ComponentList, { id: "all" }) });
|
3942
4033
|
};
|
3943
4034
|
|
3944
4035
|
// components/Puck/components/Preview/index.tsx
|
3945
4036
|
init_react_import();
|
3946
|
-
var
|
4037
|
+
var import_react25 = require("react");
|
3947
4038
|
|
3948
4039
|
// components/AutoFrame/index.tsx
|
3949
4040
|
init_react_import();
|
3950
|
-
var
|
4041
|
+
var import_react24 = require("react");
|
3951
4042
|
var import_object_hash = __toESM(require("object-hash"));
|
3952
4043
|
var import_react_dom2 = require("react-dom");
|
3953
4044
|
var import_jsx_runtime32 = require("react/jsx-runtime");
|
@@ -3993,7 +4084,7 @@ var CopyHostStyles = ({
|
|
3993
4084
|
onStylesLoaded = () => null
|
3994
4085
|
}) => {
|
3995
4086
|
const { document: doc, window: win } = useFrame();
|
3996
|
-
(0,
|
4087
|
+
(0, import_react24.useEffect)(() => {
|
3997
4088
|
if (!win || !doc) {
|
3998
4089
|
return () => {
|
3999
4090
|
};
|
@@ -4152,8 +4243,8 @@ var CopyHostStyles = ({
|
|
4152
4243
|
}, []);
|
4153
4244
|
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_jsx_runtime32.Fragment, { children });
|
4154
4245
|
};
|
4155
|
-
var autoFrameContext = (0,
|
4156
|
-
var useFrame = () => (0,
|
4246
|
+
var autoFrameContext = (0, import_react24.createContext)({});
|
4247
|
+
var useFrame = () => (0, import_react24.useContext)(autoFrameContext);
|
4157
4248
|
function AutoFrame(_a) {
|
4158
4249
|
var _b = _a, {
|
4159
4250
|
children,
|
@@ -4168,11 +4259,11 @@ function AutoFrame(_a) {
|
|
4168
4259
|
"id",
|
4169
4260
|
"onStylesLoaded"
|
4170
4261
|
]);
|
4171
|
-
const [loaded, setLoaded] = (0,
|
4172
|
-
const [ctx, setCtx] = (0,
|
4173
|
-
const ref = (0,
|
4174
|
-
const [mountTarget, setMountTarget] = (0,
|
4175
|
-
(0,
|
4262
|
+
const [loaded, setLoaded] = (0, import_react24.useState)(false);
|
4263
|
+
const [ctx, setCtx] = (0, import_react24.useState)({});
|
4264
|
+
const ref = (0, import_react24.useRef)(null);
|
4265
|
+
const [mountTarget, setMountTarget] = (0, import_react24.useState)();
|
4266
|
+
(0, import_react24.useEffect)(() => {
|
4176
4267
|
var _a2;
|
4177
4268
|
if (ref.current) {
|
4178
4269
|
setCtx({
|
@@ -4208,7 +4299,7 @@ var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
4208
4299
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
4209
4300
|
var Preview = ({ id = "puck-preview" }) => {
|
4210
4301
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
4211
|
-
const Page = (0,
|
4302
|
+
const Page = (0, import_react25.useCallback)(
|
4212
4303
|
(pageProps) => {
|
4213
4304
|
var _a, _b;
|
4214
4305
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -4217,7 +4308,7 @@ var Preview = ({ id = "puck-preview" }) => {
|
|
4217
4308
|
},
|
4218
4309
|
[config.root]
|
4219
4310
|
);
|
4220
|
-
const Frame = (0,
|
4311
|
+
const Frame = (0, import_react25.useMemo)(() => overrides.iframe, [overrides]);
|
4221
4312
|
const rootProps = state.data.root.props || state.data.root;
|
4222
4313
|
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
4223
4314
|
"div",
|
@@ -4306,7 +4397,7 @@ var scrollIntoView = (el) => {
|
|
4306
4397
|
};
|
4307
4398
|
|
4308
4399
|
// components/LayerTree/index.tsx
|
4309
|
-
var
|
4400
|
+
var import_react26 = require("react");
|
4310
4401
|
|
4311
4402
|
// lib/is-child-of-zone.ts
|
4312
4403
|
init_react_import();
|
@@ -4333,7 +4424,7 @@ var LayerTree = ({
|
|
4333
4424
|
label
|
4334
4425
|
}) => {
|
4335
4426
|
const zones = data.zones || {};
|
4336
|
-
const ctx = (0,
|
4427
|
+
const ctx = (0, import_react26.useContext)(dropZoneContext);
|
4337
4428
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
4338
4429
|
label && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName24("zoneTitle"), children: [
|
4339
4430
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Layers, { size: "16" }) }),
|
@@ -4439,13 +4530,13 @@ var LayerTree = ({
|
|
4439
4530
|
};
|
4440
4531
|
|
4441
4532
|
// components/Puck/components/Outline/index.tsx
|
4442
|
-
var
|
4533
|
+
var import_react27 = require("react");
|
4443
4534
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
4444
4535
|
var Outline = () => {
|
4445
4536
|
const { dispatch, state, overrides, config } = useAppContext();
|
4446
4537
|
const { data, ui } = state;
|
4447
4538
|
const { itemSelector } = ui;
|
4448
|
-
const setItemSelector = (0,
|
4539
|
+
const setItemSelector = (0, import_react27.useCallback)(
|
4449
4540
|
(newItemSelector) => {
|
4450
4541
|
dispatch({
|
4451
4542
|
type: "setUi",
|
@@ -4454,7 +4545,7 @@ var Outline = () => {
|
|
4454
4545
|
},
|
4455
4546
|
[]
|
4456
4547
|
);
|
4457
|
-
const Wrapper = (0,
|
4548
|
+
const Wrapper = (0, import_react27.useMemo)(() => overrides.outline || "div", [overrides]);
|
4458
4549
|
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Wrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
|
4459
4550
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
4460
4551
|
LayerTree,
|
@@ -4500,14 +4591,14 @@ function usePuckHistory({
|
|
4500
4591
|
if (historyStore.hasPast) {
|
4501
4592
|
dispatch({
|
4502
4593
|
type: "set",
|
4503
|
-
state: ((_a = historyStore.prevHistory) == null ? void 0 : _a.
|
4594
|
+
state: ((_a = historyStore.prevHistory) == null ? void 0 : _a.state) || initialAppState
|
4504
4595
|
});
|
4505
4596
|
historyStore.back();
|
4506
4597
|
}
|
4507
4598
|
};
|
4508
4599
|
const forward = () => {
|
4509
4600
|
if (historyStore.nextHistory) {
|
4510
|
-
dispatch({ type: "set", state: historyStore.nextHistory.
|
4601
|
+
dispatch({ type: "set", state: historyStore.nextHistory.state });
|
4511
4602
|
historyStore.forward();
|
4512
4603
|
}
|
4513
4604
|
};
|
@@ -4515,7 +4606,7 @@ function usePuckHistory({
|
|
4515
4606
|
var _a;
|
4516
4607
|
dispatch({
|
4517
4608
|
type: "set",
|
4518
|
-
state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.
|
4609
|
+
state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || initialAppState
|
4519
4610
|
});
|
4520
4611
|
historyStore.setHistories(histories);
|
4521
4612
|
};
|
@@ -4524,7 +4615,7 @@ function usePuckHistory({
|
|
4524
4615
|
if (historyStore.histories.length > index) {
|
4525
4616
|
dispatch({
|
4526
4617
|
type: "set",
|
4527
|
-
state: ((_a = historyStore.histories[index]) == null ? void 0 : _a.
|
4618
|
+
state: ((_a = historyStore.histories[index]) == null ? void 0 : _a.state) || initialAppState
|
4528
4619
|
});
|
4529
4620
|
historyStore.setHistoryIndex(index);
|
4530
4621
|
}
|
@@ -4543,19 +4634,19 @@ function usePuckHistory({
|
|
4543
4634
|
|
4544
4635
|
// lib/use-history-store.ts
|
4545
4636
|
init_react_import();
|
4546
|
-
var
|
4637
|
+
var import_react28 = require("react");
|
4547
4638
|
var import_use_debounce3 = require("use-debounce");
|
4548
|
-
var EMPTY_HISTORY_INDEX =
|
4639
|
+
var EMPTY_HISTORY_INDEX = 0;
|
4549
4640
|
function useHistoryStore(initialHistory) {
|
4550
4641
|
var _a, _b;
|
4551
|
-
const [histories, setHistories] = (0,
|
4642
|
+
const [histories, setHistories] = (0, import_react28.useState)(
|
4552
4643
|
(_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
|
4553
4644
|
);
|
4554
4645
|
const updateHistories = (histories2) => {
|
4555
4646
|
setHistories(histories2);
|
4556
4647
|
setIndex(histories2.length - 1);
|
4557
4648
|
};
|
4558
|
-
const [index, setIndex] = (0,
|
4649
|
+
const [index, setIndex] = (0, import_react28.useState)(
|
4559
4650
|
(_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
|
4560
4651
|
);
|
4561
4652
|
const hasPast = index > EMPTY_HISTORY_INDEX;
|
@@ -4563,9 +4654,9 @@ function useHistoryStore(initialHistory) {
|
|
4563
4654
|
const currentHistory = histories[index];
|
4564
4655
|
const nextHistory = hasFuture ? histories[index + 1] : null;
|
4565
4656
|
const prevHistory = hasPast ? histories[index - 1] : null;
|
4566
|
-
const record = (0, import_use_debounce3.useDebouncedCallback)((
|
4657
|
+
const record = (0, import_use_debounce3.useDebouncedCallback)((state) => {
|
4567
4658
|
const history = {
|
4568
|
-
|
4659
|
+
state,
|
4569
4660
|
id: generateId("history")
|
4570
4661
|
};
|
4571
4662
|
updateHistories([...histories.slice(0, index + 1), history]);
|
@@ -4715,11 +4806,11 @@ var getBox = function getBox2(el) {
|
|
4715
4806
|
};
|
4716
4807
|
|
4717
4808
|
// components/Puck/components/Canvas/index.tsx
|
4718
|
-
var
|
4809
|
+
var import_react30 = require("react");
|
4719
4810
|
|
4720
4811
|
// components/ViewportControls/index.tsx
|
4721
4812
|
init_react_import();
|
4722
|
-
var
|
4813
|
+
var import_react29 = require("react");
|
4723
4814
|
|
4724
4815
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
4725
4816
|
init_react_import();
|
@@ -4742,8 +4833,8 @@ var ViewportButton = ({
|
|
4742
4833
|
onClick
|
4743
4834
|
}) => {
|
4744
4835
|
const { state } = useAppContext();
|
4745
|
-
const [isActive, setIsActive] = (0,
|
4746
|
-
(0,
|
4836
|
+
const [isActive, setIsActive] = (0, import_react29.useState)(false);
|
4837
|
+
(0, import_react29.useEffect)(() => {
|
4747
4838
|
setIsActive(width === state.ui.viewports.current.width);
|
4748
4839
|
}, [width, state.ui.viewports.current.width]);
|
4749
4840
|
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
@@ -4779,7 +4870,7 @@ var ViewportControls = ({
|
|
4779
4870
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
4780
4871
|
(option) => option.value === autoZoom
|
4781
4872
|
);
|
4782
|
-
const zoomOptions = (0,
|
4873
|
+
const zoomOptions = (0, import_react29.useMemo)(
|
4783
4874
|
() => [
|
4784
4875
|
...defaultZoomOptions,
|
4785
4876
|
...defaultsContainAutoZoom ? [] : [
|
@@ -4862,7 +4953,7 @@ var ViewportControls = ({
|
|
4862
4953
|
|
4863
4954
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
|
4864
4955
|
init_react_import();
|
4865
|
-
var styles_module_default21 = { "PuckCanvas": "
|
4956
|
+
var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_esbg1_1", "PuckCanvas-controls": "_PuckCanvas-controls_esbg1_16", "PuckCanvas-inner": "_PuckCanvas-inner_esbg1_21", "PuckCanvas-root": "_PuckCanvas-root_esbg1_32", "PuckCanvas--ready": "_PuckCanvas--ready_esbg1_56", "PuckCanvas-loader": "_PuckCanvas-loader_esbg1_60", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_esbg1_70" };
|
4866
4957
|
|
4867
4958
|
// lib/get-zoom-config.ts
|
4868
4959
|
init_react_import();
|
@@ -4902,17 +4993,17 @@ var Canvas = () => {
|
|
4902
4993
|
const { status, iframe } = useAppContext();
|
4903
4994
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
4904
4995
|
const { ui } = state;
|
4905
|
-
const frameRef = (0,
|
4906
|
-
const [showTransition, setShowTransition] = (0,
|
4907
|
-
const defaultRender = (0,
|
4996
|
+
const frameRef = (0, import_react30.useRef)(null);
|
4997
|
+
const [showTransition, setShowTransition] = (0, import_react30.useState)(false);
|
4998
|
+
const defaultRender = (0, import_react30.useMemo)(() => {
|
4908
4999
|
const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children });
|
4909
5000
|
return PuckDefault;
|
4910
5001
|
}, []);
|
4911
|
-
const CustomPreview = (0,
|
5002
|
+
const CustomPreview = (0, import_react30.useMemo)(
|
4912
5003
|
() => overrides.preview || defaultRender,
|
4913
5004
|
[overrides]
|
4914
5005
|
);
|
4915
|
-
const getFrameDimensions = (0,
|
5006
|
+
const getFrameDimensions = (0, import_react30.useCallback)(() => {
|
4916
5007
|
if (frameRef.current) {
|
4917
5008
|
const frame = frameRef.current;
|
4918
5009
|
const box = getBox(frame);
|
@@ -4920,7 +5011,7 @@ var Canvas = () => {
|
|
4920
5011
|
}
|
4921
5012
|
return { width: 0, height: 0 };
|
4922
5013
|
}, [frameRef]);
|
4923
|
-
const resetAutoZoom = (0,
|
5014
|
+
const resetAutoZoom = (0, import_react30.useCallback)(
|
4924
5015
|
(ui2 = state.ui) => {
|
4925
5016
|
if (frameRef.current) {
|
4926
5017
|
setZoomConfig(
|
@@ -4930,11 +5021,11 @@ var Canvas = () => {
|
|
4930
5021
|
},
|
4931
5022
|
[frameRef, zoomConfig, state.ui]
|
4932
5023
|
);
|
4933
|
-
(0,
|
5024
|
+
(0, import_react30.useEffect)(() => {
|
4934
5025
|
setShowTransition(false);
|
4935
5026
|
resetAutoZoom();
|
4936
5027
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
4937
|
-
(0,
|
5028
|
+
(0, import_react30.useEffect)(() => {
|
4938
5029
|
const { height: frameHeight } = getFrameDimensions();
|
4939
5030
|
if (ui.viewports.current.height === "auto") {
|
4940
5031
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -4942,7 +5033,13 @@ var Canvas = () => {
|
|
4942
5033
|
}));
|
4943
5034
|
}
|
4944
5035
|
}, [zoomConfig.zoom]);
|
4945
|
-
(0,
|
5036
|
+
(0, import_react30.useEffect)(() => {
|
5037
|
+
if (ZOOM_ON_CHANGE) {
|
5038
|
+
setShowTransition(true);
|
5039
|
+
resetAutoZoom(ui);
|
5040
|
+
}
|
5041
|
+
}, [ui.viewports.current.width]);
|
5042
|
+
(0, import_react30.useEffect)(() => {
|
4946
5043
|
const observer = new ResizeObserver(() => {
|
4947
5044
|
setShowTransition(false);
|
4948
5045
|
resetAutoZoom();
|
@@ -4954,11 +5051,18 @@ var Canvas = () => {
|
|
4954
5051
|
observer.disconnect();
|
4955
5052
|
};
|
4956
5053
|
}, []);
|
5054
|
+
const [showLoader, setShowLoader] = (0, import_react30.useState)(false);
|
5055
|
+
(0, import_react30.useEffect)(() => {
|
5056
|
+
setTimeout(() => {
|
5057
|
+
setShowLoader(true);
|
5058
|
+
}, 500);
|
5059
|
+
}, []);
|
4957
5060
|
return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
|
4958
5061
|
"div",
|
4959
5062
|
{
|
4960
5063
|
className: getClassName26({
|
4961
|
-
ready: status === "READY" || !iframe.enabled
|
5064
|
+
ready: status === "READY" || !iframe.enabled || !iframe.waitForStyles,
|
5065
|
+
showLoader
|
4962
5066
|
}),
|
4963
5067
|
onClick: () => dispatch({
|
4964
5068
|
type: "setUi",
|
@@ -4991,21 +5095,24 @@ var Canvas = () => {
|
|
4991
5095
|
}
|
4992
5096
|
}
|
4993
5097
|
) }),
|
4994
|
-
/* @__PURE__ */ (0, import_jsx_runtime37.
|
4995
|
-
|
4996
|
-
|
4997
|
-
|
4998
|
-
|
4999
|
-
|
5000
|
-
|
5001
|
-
|
5002
|
-
|
5003
|
-
|
5004
|
-
|
5005
|
-
|
5006
|
-
|
5007
|
-
|
5008
|
-
|
5098
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: getClassName26("inner"), ref: frameRef, children: [
|
5099
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
|
5100
|
+
"div",
|
5101
|
+
{
|
5102
|
+
className: getClassName26("root"),
|
5103
|
+
style: {
|
5104
|
+
width: iframe.enabled ? ui.viewports.current.width : "100%",
|
5105
|
+
height: zoomConfig.rootHeight,
|
5106
|
+
transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
|
5107
|
+
transition: showTransition ? "width 150ms ease-out, height 150ms ease-out, transform 150ms ease-out" : "",
|
5108
|
+
overflow: iframe.enabled ? void 0 : "auto"
|
5109
|
+
},
|
5110
|
+
suppressHydrationWarning: true,
|
5111
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(CustomPreview, { children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Preview, {}) })
|
5112
|
+
}
|
5113
|
+
),
|
5114
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: getClassName26("loader"), children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Loader, { size: 24 }) })
|
5115
|
+
] })
|
5009
5116
|
]
|
5010
5117
|
}
|
5011
5118
|
);
|
@@ -5030,7 +5137,10 @@ var insertComponent = (componentType, zone, index, {
|
|
5030
5137
|
const insertedData = insertAction(state.data, insertActionData, config);
|
5031
5138
|
dispatch(__spreadProps(__spreadValues({}, insertActionData), {
|
5032
5139
|
// Dispatch insert rather set, as user's may rely on this via onAction
|
5033
|
-
|
5140
|
+
// We must always record history here so the insert is added to user history
|
5141
|
+
// If the user has defined a resolveData method, they will end up with 2 history
|
5142
|
+
// entries on insert - one for the initial insert, and one when the data resolves
|
5143
|
+
recordHistory: true
|
5034
5144
|
}));
|
5035
5145
|
const itemSelector = {
|
5036
5146
|
index,
|
@@ -5045,7 +5155,7 @@ var insertComponent = (componentType, zone, index, {
|
|
5045
5155
|
|
5046
5156
|
// lib/use-loaded-overrides.ts
|
5047
5157
|
init_react_import();
|
5048
|
-
var
|
5158
|
+
var import_react31 = require("react");
|
5049
5159
|
|
5050
5160
|
// lib/load-overrides.ts
|
5051
5161
|
init_react_import();
|
@@ -5084,7 +5194,7 @@ var useLoadedOverrides = ({
|
|
5084
5194
|
overrides,
|
5085
5195
|
plugins
|
5086
5196
|
}) => {
|
5087
|
-
return (0,
|
5197
|
+
return (0, import_react31.useMemo)(() => {
|
5088
5198
|
return loadOverrides({ overrides, plugins });
|
5089
5199
|
}, [plugins, overrides]);
|
5090
5200
|
};
|
@@ -5109,22 +5219,16 @@ function Puck({
|
|
5109
5219
|
headerTitle,
|
5110
5220
|
headerPath,
|
5111
5221
|
viewports = defaultViewports,
|
5112
|
-
iframe
|
5113
|
-
enabled: true
|
5114
|
-
},
|
5222
|
+
iframe: _iframe,
|
5115
5223
|
dnd,
|
5116
|
-
initialHistory
|
5224
|
+
initialHistory: _initialHistory
|
5117
5225
|
}) {
|
5118
5226
|
var _a;
|
5119
|
-
const
|
5120
|
-
|
5121
|
-
|
5122
|
-
|
5123
|
-
|
5124
|
-
onAction
|
5125
|
-
})
|
5126
|
-
);
|
5127
|
-
const [initialAppState] = (0, import_react31.useState)(() => {
|
5227
|
+
const iframe = __spreadValues({
|
5228
|
+
enabled: true,
|
5229
|
+
waitForStyles: true
|
5230
|
+
}, _iframe);
|
5231
|
+
const [generatedAppState] = (0, import_react32.useState)(() => {
|
5128
5232
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
5129
5233
|
const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
|
5130
5234
|
let clientUiState = {};
|
@@ -5142,14 +5246,14 @@ function Puck({
|
|
5142
5246
|
})).sort((a, b) => a.diff > b.diff ? 1 : -1);
|
5143
5247
|
const closestViewport = viewportDifferences[0].key;
|
5144
5248
|
if (iframe.enabled) {
|
5145
|
-
clientUiState = {
|
5249
|
+
clientUiState = __spreadProps(__spreadValues({}, clientUiState), {
|
5146
5250
|
viewports: __spreadProps(__spreadValues({}, initial.viewports), {
|
5147
5251
|
current: __spreadProps(__spreadValues({}, initial.viewports.current), {
|
5148
5252
|
height: ((_b = (_a2 = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _a2.current) == null ? void 0 : _b.height) || ((_c = viewports[closestViewport]) == null ? void 0 : _c.height) || "auto",
|
5149
5253
|
width: ((_e = (_d = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _d.current) == null ? void 0 : _e.width) || ((_f = viewports[closestViewport]) == null ? void 0 : _f.width)
|
5150
5254
|
})
|
5151
5255
|
})
|
5152
|
-
};
|
5256
|
+
});
|
5153
5257
|
}
|
5154
5258
|
}
|
5155
5259
|
if (Object.keys((initialData == null ? void 0 : initialData.root) || {}).length > 0 && !((_g = initialData == null ? void 0 : initialData.root) == null ? void 0 : _g.props)) {
|
@@ -5182,20 +5286,36 @@ function Puck({
|
|
5182
5286
|
})
|
5183
5287
|
});
|
5184
5288
|
});
|
5185
|
-
const
|
5289
|
+
const { appendData = true } = _initialHistory || {};
|
5290
|
+
const histories = [
|
5291
|
+
...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
|
5292
|
+
...appendData ? [{ state: generatedAppState }] : []
|
5293
|
+
].map((history2) => __spreadProps(__spreadValues({}, history2), {
|
5294
|
+
// Inject default data to enable partial history injections
|
5295
|
+
state: __spreadValues(__spreadValues({}, generatedAppState), history2.state)
|
5296
|
+
}));
|
5297
|
+
const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || histories.length - 1;
|
5298
|
+
const initialAppState = histories[initialHistoryIndex].state;
|
5299
|
+
const historyStore = useHistoryStore({
|
5300
|
+
histories,
|
5301
|
+
index: initialHistoryIndex
|
5302
|
+
});
|
5303
|
+
const [reducer] = (0, import_react32.useState)(
|
5304
|
+
() => createReducer({
|
5305
|
+
config,
|
5306
|
+
record: historyStore.record,
|
5307
|
+
onAction
|
5308
|
+
})
|
5309
|
+
);
|
5310
|
+
const [appState, dispatch] = (0, import_react32.useReducer)(
|
5186
5311
|
reducer,
|
5187
5312
|
flushZones(initialAppState)
|
5188
5313
|
);
|
5189
5314
|
const { data, ui } = appState;
|
5190
5315
|
const history = usePuckHistory({ dispatch, initialAppState, historyStore });
|
5191
|
-
const
|
5192
|
-
appState,
|
5193
|
-
config,
|
5194
|
-
dispatch
|
5195
|
-
);
|
5196
|
-
const [menuOpen, setMenuOpen] = (0, import_react31.useState)(false);
|
5316
|
+
const [menuOpen, setMenuOpen] = (0, import_react32.useState)(false);
|
5197
5317
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
5198
|
-
const setItemSelector = (0,
|
5318
|
+
const setItemSelector = (0, import_react32.useCallback)(
|
5199
5319
|
(newItemSelector) => {
|
5200
5320
|
if (newItemSelector === itemSelector) return;
|
5201
5321
|
dispatch({
|
@@ -5207,13 +5327,13 @@ function Puck({
|
|
5207
5327
|
[itemSelector]
|
5208
5328
|
);
|
5209
5329
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
5210
|
-
(0,
|
5330
|
+
(0, import_react32.useEffect)(() => {
|
5211
5331
|
if (onChange) onChange(data);
|
5212
5332
|
}, [data]);
|
5213
5333
|
const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
|
5214
|
-
const [draggedItem, setDraggedItem] = (0,
|
5334
|
+
const [draggedItem, setDraggedItem] = (0, import_react32.useState)();
|
5215
5335
|
const rootProps = data.root.props || data.root;
|
5216
|
-
const toggleSidebars = (0,
|
5336
|
+
const toggleSidebars = (0, import_react32.useCallback)(
|
5217
5337
|
(sidebar) => {
|
5218
5338
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
5219
5339
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -5227,7 +5347,7 @@ function Puck({
|
|
5227
5347
|
},
|
5228
5348
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
5229
5349
|
);
|
5230
|
-
(0,
|
5350
|
+
(0, import_react32.useEffect)(() => {
|
5231
5351
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
5232
5352
|
dispatch({
|
5233
5353
|
type: "setUi",
|
@@ -5250,7 +5370,7 @@ function Puck({
|
|
5250
5370
|
window.removeEventListener("resize", handleResize);
|
5251
5371
|
};
|
5252
5372
|
}, []);
|
5253
|
-
const defaultHeaderRender = (0,
|
5373
|
+
const defaultHeaderRender = (0, import_react32.useMemo)(() => {
|
5254
5374
|
if (renderHeader) {
|
5255
5375
|
console.warn(
|
5256
5376
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -5264,7 +5384,7 @@ function Puck({
|
|
5264
5384
|
}
|
5265
5385
|
return DefaultOverride;
|
5266
5386
|
}, [renderHeader]);
|
5267
|
-
const defaultHeaderActionsRender = (0,
|
5387
|
+
const defaultHeaderActionsRender = (0, import_react32.useMemo)(() => {
|
5268
5388
|
if (renderHeaderActions) {
|
5269
5389
|
console.warn(
|
5270
5390
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -5281,20 +5401,20 @@ function Puck({
|
|
5281
5401
|
overrides,
|
5282
5402
|
plugins
|
5283
5403
|
});
|
5284
|
-
const CustomPuck = (0,
|
5404
|
+
const CustomPuck = (0, import_react32.useMemo)(
|
5285
5405
|
() => loadedOverrides.puck || DefaultOverride,
|
5286
5406
|
[loadedOverrides]
|
5287
5407
|
);
|
5288
|
-
const CustomHeader = (0,
|
5408
|
+
const CustomHeader = (0, import_react32.useMemo)(
|
5289
5409
|
() => loadedOverrides.header || defaultHeaderRender,
|
5290
5410
|
[loadedOverrides]
|
5291
5411
|
);
|
5292
|
-
const CustomHeaderActions = (0,
|
5412
|
+
const CustomHeaderActions = (0, import_react32.useMemo)(
|
5293
5413
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
5294
5414
|
[loadedOverrides]
|
5295
5415
|
);
|
5296
|
-
const [mounted, setMounted] = (0,
|
5297
|
-
(0,
|
5416
|
+
const [mounted, setMounted] = (0, import_react32.useState)(false);
|
5417
|
+
(0, import_react32.useEffect)(() => {
|
5298
5418
|
setMounted(true);
|
5299
5419
|
}, []);
|
5300
5420
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|
@@ -5307,8 +5427,6 @@ function Puck({
|
|
5307
5427
|
state: appState,
|
5308
5428
|
dispatch,
|
5309
5429
|
config,
|
5310
|
-
componentState,
|
5311
|
-
resolveData,
|
5312
5430
|
plugins: plugins || [],
|
5313
5431
|
overrides: loadedOverrides,
|
5314
5432
|
history,
|
@@ -5320,9 +5438,11 @@ function Puck({
|
|
5320
5438
|
duplicate: true,
|
5321
5439
|
insert: true,
|
5322
5440
|
edit: true
|
5323
|
-
}, permissions)
|
5441
|
+
}, permissions),
|
5442
|
+
getPermissions: () => ({}),
|
5443
|
+
refreshPermissions: () => null
|
5324
5444
|
},
|
5325
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5445
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(appContext.Consumer, { children: ({ resolveData }) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5326
5446
|
DragDropContext,
|
5327
5447
|
{
|
5328
5448
|
autoScrollerOptions: { disabled: dnd == null ? void 0 : dnd.disableAutoScroll },
|
@@ -5412,89 +5532,115 @@ function Puck({
|
|
5412
5532
|
}
|
5413
5533
|
) }) }),
|
5414
5534
|
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("header", { className: getLayoutClassName("header"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getLayoutClassName("headerInner"), children: [
|
5415
|
-
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
|
5416
|
-
|
5417
|
-
|
5418
|
-
|
5419
|
-
|
5420
|
-
|
5421
|
-
|
5422
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5423
|
-
IconButton,
|
5535
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
|
5536
|
+
"div",
|
5537
|
+
{
|
5538
|
+
className: getLayoutClassName("headerToggle"),
|
5539
|
+
children: [
|
5540
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5541
|
+
"div",
|
5424
5542
|
{
|
5425
|
-
|
5426
|
-
|
5427
|
-
|
5428
|
-
|
5429
|
-
|
5543
|
+
className: getLayoutClassName(
|
5544
|
+
"leftSideBarToggle"
|
5545
|
+
),
|
5546
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5547
|
+
IconButton,
|
5548
|
+
{
|
5549
|
+
onClick: () => {
|
5550
|
+
toggleSidebars("left");
|
5551
|
+
},
|
5552
|
+
title: "Toggle left sidebar",
|
5553
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PanelLeft, { focusable: "false" })
|
5554
|
+
}
|
5555
|
+
)
|
5430
5556
|
}
|
5431
|
-
)
|
5432
|
-
}
|
5433
|
-
),
|
5434
|
-
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5435
|
-
"div",
|
5436
|
-
{
|
5437
|
-
className: getLayoutClassName(
|
5438
|
-
"rightSideBarToggle"
|
5439
5557
|
),
|
5440
|
-
|
5441
|
-
|
5558
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5559
|
+
"div",
|
5442
5560
|
{
|
5443
|
-
|
5444
|
-
|
5445
|
-
|
5446
|
-
|
5447
|
-
|
5561
|
+
className: getLayoutClassName(
|
5562
|
+
"rightSideBarToggle"
|
5563
|
+
),
|
5564
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5565
|
+
IconButton,
|
5566
|
+
{
|
5567
|
+
onClick: () => {
|
5568
|
+
toggleSidebars("right");
|
5569
|
+
},
|
5570
|
+
title: "Toggle right sidebar",
|
5571
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PanelRight, { focusable: "false" })
|
5572
|
+
}
|
5573
|
+
)
|
5448
5574
|
}
|
5449
5575
|
)
|
5450
|
-
|
5451
|
-
|
5452
|
-
|
5453
|
-
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5454
|
-
|
5455
|
-
|
5456
|
-
|
5457
|
-
/* @__PURE__ */ (0, import_jsx_runtime38.
|
5458
|
-
"
|
5459
|
-
{
|
5460
|
-
|
5461
|
-
|
5462
|
-
|
5463
|
-
|
5464
|
-
|
5465
|
-
|
5466
|
-
|
5467
|
-
|
5468
|
-
|
5469
|
-
|
5470
|
-
|
5471
|
-
|
5472
|
-
|
5473
|
-
|
5474
|
-
|
5475
|
-
|
5476
|
-
|
5477
|
-
|
5478
|
-
|
5479
|
-
|
5480
|
-
|
5481
|
-
dispatch,
|
5482
|
-
onPublish,
|
5483
|
-
menuOpen,
|
5484
|
-
renderHeaderActions: () => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5485
|
-
Button,
|
5576
|
+
]
|
5577
|
+
}
|
5578
|
+
),
|
5579
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5580
|
+
"div",
|
5581
|
+
{
|
5582
|
+
className: getLayoutClassName("headerTitle"),
|
5583
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(Heading, { rank: "2", size: "xs", children: [
|
5584
|
+
headerTitle || rootProps.title || "Page",
|
5585
|
+
headerPath && /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_jsx_runtime38.Fragment, { children: [
|
5586
|
+
" ",
|
5587
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5588
|
+
"code",
|
5589
|
+
{
|
5590
|
+
className: getLayoutClassName(
|
5591
|
+
"headerPath"
|
5592
|
+
),
|
5593
|
+
children: headerPath
|
5594
|
+
}
|
5595
|
+
)
|
5596
|
+
] })
|
5597
|
+
] })
|
5598
|
+
}
|
5599
|
+
),
|
5600
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
|
5601
|
+
"div",
|
5602
|
+
{
|
5603
|
+
className: getLayoutClassName("headerTools"),
|
5604
|
+
children: [
|
5605
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5606
|
+
"div",
|
5486
5607
|
{
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5608
|
+
className: getLayoutClassName("menuButton"),
|
5609
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5610
|
+
IconButton,
|
5611
|
+
{
|
5612
|
+
onClick: () => {
|
5613
|
+
return setMenuOpen(!menuOpen);
|
5614
|
+
},
|
5615
|
+
title: "Toggle menu bar",
|
5616
|
+
children: menuOpen ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ChevronDown, { focusable: "false" })
|
5617
|
+
}
|
5618
|
+
)
|
5492
5619
|
}
|
5493
|
-
)
|
5494
|
-
|
5495
|
-
|
5496
|
-
|
5497
|
-
|
5620
|
+
),
|
5621
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5622
|
+
MenuBar,
|
5623
|
+
{
|
5624
|
+
appState,
|
5625
|
+
dispatch,
|
5626
|
+
onPublish,
|
5627
|
+
menuOpen,
|
5628
|
+
renderHeaderActions: () => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
5629
|
+
Button,
|
5630
|
+
{
|
5631
|
+
onClick: () => {
|
5632
|
+
onPublish && onPublish(data);
|
5633
|
+
},
|
5634
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Globe, { size: "14px" }),
|
5635
|
+
children: "Publish"
|
5636
|
+
}
|
5637
|
+
) }),
|
5638
|
+
setMenuOpen
|
5639
|
+
}
|
5640
|
+
)
|
5641
|
+
]
|
5642
|
+
}
|
5643
|
+
)
|
5498
5644
|
] }) })
|
5499
5645
|
}
|
5500
5646
|
),
|
@@ -5519,7 +5665,7 @@ function Puck({
|
|
5519
5665
|
}
|
5520
5666
|
)
|
5521
5667
|
}
|
5522
|
-
)
|
5668
|
+
) })
|
5523
5669
|
}
|
5524
5670
|
),
|
5525
5671
|
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { id: "puck-portal-root", className: getClassName27("portal") })
|
@@ -5533,7 +5679,10 @@ Puck.Preview = Preview;
|
|
5533
5679
|
// components/Render/index.tsx
|
5534
5680
|
init_react_import();
|
5535
5681
|
var import_jsx_runtime39 = require("react/jsx-runtime");
|
5536
|
-
function Render({
|
5682
|
+
function Render({
|
5683
|
+
config,
|
5684
|
+
data
|
5685
|
+
}) {
|
5537
5686
|
var _a;
|
5538
5687
|
const defaultedData = __spreadProps(__spreadValues({}, data), {
|
5539
5688
|
root: data.root || {},
|
@@ -5665,24 +5814,15 @@ var usePuck = () => {
|
|
5665
5814
|
history,
|
5666
5815
|
dispatch,
|
5667
5816
|
selectedItem: currentItem,
|
5668
|
-
|
5817
|
+
getPermissions,
|
5818
|
+
refreshPermissions
|
5669
5819
|
} = useAppContext();
|
5670
5820
|
return {
|
5671
5821
|
appState,
|
5672
5822
|
config,
|
5673
5823
|
dispatch,
|
5674
|
-
getPermissions
|
5675
|
-
|
5676
|
-
type
|
5677
|
-
} = {}) => {
|
5678
|
-
return getPermissions({
|
5679
|
-
selectedItem: item || currentItem,
|
5680
|
-
type,
|
5681
|
-
globalPermissions: globalPermissions || {},
|
5682
|
-
config,
|
5683
|
-
appState
|
5684
|
-
});
|
5685
|
-
},
|
5824
|
+
getPermissions,
|
5825
|
+
refreshPermissions,
|
5686
5826
|
history: {
|
5687
5827
|
back: history.back,
|
5688
5828
|
forward: history.forward,
|
@@ -5709,6 +5849,7 @@ var usePuck = () => {
|
|
5709
5849
|
DropZoneProvider,
|
5710
5850
|
FieldLabel,
|
5711
5851
|
FieldLabelInternal,
|
5852
|
+
Group,
|
5712
5853
|
IconButton,
|
5713
5854
|
Puck,
|
5714
5855
|
Render,
|