@netlisian/softconfig 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -53
- package/dist/puck/index.d.mts +10 -3
- package/dist/puck/index.d.ts +10 -3
- package/dist/puck/index.js +304 -185
- package/dist/puck/index.mjs +304 -185
- package/package.json +1 -1
package/dist/puck/index.js
CHANGED
|
@@ -455,7 +455,6 @@ var builderRootConfig = (config, overrides, editingComponent) => ({
|
|
|
455
455
|
const inputValues = fromPaths.map(
|
|
456
456
|
(f) => getFieldSettingsByPath(props._fieldSettings || {}, f)
|
|
457
457
|
);
|
|
458
|
-
console.log(inputValues);
|
|
459
458
|
let value = transform ? transform(
|
|
460
459
|
inputValues.map((v) => v == null ? void 0 : v.defaultValue),
|
|
461
460
|
child.props
|
|
@@ -536,7 +535,7 @@ function generateFieldOptions(fields, selectedFields, prefix = "") {
|
|
|
536
535
|
if (selectedFields.includes(path)) {
|
|
537
536
|
return;
|
|
538
537
|
}
|
|
539
|
-
opts.push({ label: path, value: path });
|
|
538
|
+
opts.push({ label: path, value: path, type: fld.type });
|
|
540
539
|
if (fld.type === "object" && fld.objectFields) {
|
|
541
540
|
recurse(fld.objectFields, path);
|
|
542
541
|
}
|
|
@@ -556,7 +555,7 @@ function generateDynamicFieldOptions(_fields, _fieldSettings, prefix = "") {
|
|
|
556
555
|
var _a;
|
|
557
556
|
const settings = fieldSettings[field.name];
|
|
558
557
|
const path = currentPrefix ? `${currentPrefix}.${field.name}` : field.name;
|
|
559
|
-
opts.push({ label: path, value: path });
|
|
558
|
+
opts.push({ label: path, value: path, type: field.type });
|
|
560
559
|
if ((_a = settings == null ? void 0 : settings.subFields) == null ? void 0 : _a.length) {
|
|
561
560
|
recurse(settings.subFields, settings.subFieldSettings || {}, path);
|
|
562
561
|
}
|
|
@@ -705,20 +704,24 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
705
704
|
const defaultFields = component.resolveFields ? yield component.resolveFields(data, params) : component.fields || {};
|
|
706
705
|
if (!fields._map) {
|
|
707
706
|
const rootProps = getRootProps(params.appState);
|
|
707
|
+
const fromOptions = generateDynamicFieldOptions(
|
|
708
|
+
(rootProps == null ? void 0 : rootProps._fields) || [],
|
|
709
|
+
(rootProps == null ? void 0 : rootProps._fieldSettings) || {}
|
|
710
|
+
);
|
|
711
|
+
const toOptions = generateFieldOptions(defaultFields, []);
|
|
708
712
|
fields._map = overrides.map ? {
|
|
709
713
|
type: "custom",
|
|
710
714
|
render: ({ value, onChange, id }) => {
|
|
715
|
+
const toOptions2 = generateFieldOptions(defaultFields, []);
|
|
716
|
+
const rootProps2 = getRootProps(params.appState);
|
|
711
717
|
return overrides.map({
|
|
712
|
-
rootProps,
|
|
718
|
+
rootProps: rootProps2,
|
|
713
719
|
value,
|
|
714
720
|
onChange,
|
|
715
721
|
id,
|
|
716
722
|
props: data.props || {},
|
|
717
|
-
fromOptions
|
|
718
|
-
|
|
719
|
-
(rootProps == null ? void 0 : rootProps._fieldSettings) || {}
|
|
720
|
-
),
|
|
721
|
-
toOptions: generateFieldOptions(defaultFields, [])
|
|
723
|
+
fromOptions,
|
|
724
|
+
toOptions: toOptions2
|
|
722
725
|
});
|
|
723
726
|
}
|
|
724
727
|
} : {
|
|
@@ -730,10 +733,10 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
730
733
|
label: "From",
|
|
731
734
|
options: [
|
|
732
735
|
{ label: "Select a field", value: "" },
|
|
733
|
-
...
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
)
|
|
736
|
+
...fromOptions.map(({ label, value }) => ({
|
|
737
|
+
label,
|
|
738
|
+
value
|
|
739
|
+
}))
|
|
737
740
|
]
|
|
738
741
|
},
|
|
739
742
|
to: {
|
|
@@ -741,7 +744,10 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
741
744
|
label: "To",
|
|
742
745
|
options: [
|
|
743
746
|
{ label: "Select a field", value: "" },
|
|
744
|
-
...
|
|
747
|
+
...toOptions.map(({ label, value }) => ({
|
|
748
|
+
label,
|
|
749
|
+
value
|
|
750
|
+
}))
|
|
745
751
|
]
|
|
746
752
|
}
|
|
747
753
|
}
|
|
@@ -800,6 +806,25 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
800
806
|
)
|
|
801
807
|
});
|
|
802
808
|
|
|
809
|
+
// src/puck/lib/strip-id.ts
|
|
810
|
+
var stripIdFromProps = (components, allowedTypes) => {
|
|
811
|
+
return components.map((component) => sanitizeComponent(component, allowedTypes));
|
|
812
|
+
};
|
|
813
|
+
var sanitizeComponent = (component, allowedTypes) => {
|
|
814
|
+
const cleanProps = {};
|
|
815
|
+
for (const [key, value] of Object.entries(component.props)) {
|
|
816
|
+
if (key === "id") continue;
|
|
817
|
+
if (value && typeof value === "object" && "type" in value && allowedTypes.includes(value.type)) {
|
|
818
|
+
cleanProps[key] = sanitizeComponent(value, allowedTypes);
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
cleanProps[key] = value;
|
|
822
|
+
}
|
|
823
|
+
return __spreadProps(__spreadValues({}, component), {
|
|
824
|
+
props: cleanProps
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
|
|
803
828
|
// src/puck/lib/soft-component-from-appstate.ts
|
|
804
829
|
var getSubComponents = (content, componentConfigs, fieldSettings, slots) => {
|
|
805
830
|
if (!content || !Array.isArray(content)) return [];
|
|
@@ -829,8 +854,13 @@ var getSubComponents = (content, componentConfigs, fieldSettings, slots) => {
|
|
|
829
854
|
(componentProps.props._slot || []).forEach(
|
|
830
855
|
(s) => {
|
|
831
856
|
var _a2;
|
|
832
|
-
if (s.slot)
|
|
833
|
-
|
|
857
|
+
if (s.slot) {
|
|
858
|
+
const slotComponentProps = componentProps.props[s.slot] || ((_a2 = componentConfig == null ? void 0 : componentConfig.defaultProps) == null ? void 0 : _a2[s.slot]);
|
|
859
|
+
slots[s.name || `${componentProps.props.id}-${s.slot}`] = stripIdFromProps(
|
|
860
|
+
slotComponentProps,
|
|
861
|
+
Object.keys(componentConfigs)
|
|
862
|
+
);
|
|
863
|
+
}
|
|
834
864
|
}
|
|
835
865
|
);
|
|
836
866
|
const subComponent = {
|
|
@@ -933,6 +963,10 @@ var softComponentFromAppState = (appState, configComponents) => {
|
|
|
933
963
|
];
|
|
934
964
|
};
|
|
935
965
|
|
|
966
|
+
// src/puck/lib/generate-id.ts
|
|
967
|
+
var import_uuid = require("uuid");
|
|
968
|
+
var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
|
|
969
|
+
|
|
936
970
|
// src/puck/lib/soft-component-to-appstate.ts
|
|
937
971
|
var puckFieldsToSoftFields = (fields, slots) => {
|
|
938
972
|
const softFields = [];
|
|
@@ -999,11 +1033,27 @@ var puckFieldsToSoftFields = (fields, slots) => {
|
|
|
999
1033
|
};
|
|
1000
1034
|
var reconstructComponents = (subComponents, componentConfigs, softComponentProps) => {
|
|
1001
1035
|
return subComponents.map((subComponent) => {
|
|
1002
|
-
|
|
1036
|
+
var _a;
|
|
1003
1037
|
const props = __spreadValues({}, subComponent.fixedProps);
|
|
1004
|
-
subComponent.map.forEach((
|
|
1005
|
-
|
|
1006
|
-
|
|
1038
|
+
(_a = subComponent.map) == null ? void 0 : _a.forEach((mapItem, i) => {
|
|
1039
|
+
var _a2;
|
|
1040
|
+
const { from, to, transform } = mapItem || {};
|
|
1041
|
+
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
1042
|
+
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
1043
|
+
const inputs = fromPaths.map(
|
|
1044
|
+
(path) => getFieldSettingsByPath(softComponentProps || {}, path)
|
|
1045
|
+
);
|
|
1046
|
+
const runner = transform;
|
|
1047
|
+
const result = runner ? runner(inputs, softComponentProps) : inputs[0];
|
|
1048
|
+
if (Array.isArray(result)) {
|
|
1049
|
+
result.forEach((val, idx) => {
|
|
1050
|
+
if (toPaths[idx]) setPropertyByPath(props, toPaths[idx], val);
|
|
1051
|
+
});
|
|
1052
|
+
} else {
|
|
1053
|
+
toPaths.forEach((toPath) => setPropertyByPath(props, toPath, result));
|
|
1054
|
+
}
|
|
1055
|
+
if (transform && ((_a2 = props._map) == null ? void 0 : _a2[i])) {
|
|
1056
|
+
props._map[i].transform = transform;
|
|
1007
1057
|
}
|
|
1008
1058
|
});
|
|
1009
1059
|
if (subComponent.enabledSlots.length > 0) {
|
|
@@ -1029,7 +1079,7 @@ var reconstructComponents = (subComponents, componentConfigs, softComponentProps
|
|
|
1029
1079
|
const componentData = {
|
|
1030
1080
|
type: subComponent.type,
|
|
1031
1081
|
props: __spreadValues({
|
|
1032
|
-
id: props.id ||
|
|
1082
|
+
id: props.id || generateId(subComponent.type)
|
|
1033
1083
|
}, props)
|
|
1034
1084
|
};
|
|
1035
1085
|
return componentData;
|
|
@@ -1075,7 +1125,7 @@ var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
|
1075
1125
|
|
|
1076
1126
|
// src/puck/components/soft-render/index.tsx
|
|
1077
1127
|
var import_react4 = require("react");
|
|
1078
|
-
var
|
|
1128
|
+
var import_uuid2 = require("uuid");
|
|
1079
1129
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1080
1130
|
function SoftRender({
|
|
1081
1131
|
softComponentFields,
|
|
@@ -1113,14 +1163,17 @@ function SoftRender({
|
|
|
1113
1163
|
if (!componentConfig) return null;
|
|
1114
1164
|
const resolvedProps = subComponent.fixedProps || {};
|
|
1115
1165
|
const stableId = (0, import_react4.useMemo)(
|
|
1116
|
-
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${(0,
|
|
1166
|
+
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${(0, import_uuid2.v4)()}`,
|
|
1117
1167
|
[id, depth, subComponent.type]
|
|
1118
1168
|
);
|
|
1119
1169
|
if ((_a2 = subComponent.map) == null ? void 0 : _a2.length) {
|
|
1120
|
-
subComponent.map.forEach((
|
|
1170
|
+
subComponent.map.forEach((mapItem) => {
|
|
1171
|
+
const { from, to, transform } = mapItem || {};
|
|
1121
1172
|
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
1122
1173
|
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
1123
1174
|
const inputValues = fromPaths.map((f) => {
|
|
1175
|
+
const propValue = getFieldSettingsByPath(props || {}, f);
|
|
1176
|
+
if (propValue !== void 0) return propValue;
|
|
1124
1177
|
const setting = getFieldSettingsByPath(
|
|
1125
1178
|
softComponentFieldSettings || {},
|
|
1126
1179
|
f
|
|
@@ -1128,12 +1181,13 @@ function SoftRender({
|
|
|
1128
1181
|
if (setting && Object.prototype.hasOwnProperty.call(setting, "defaultValue")) {
|
|
1129
1182
|
return setting.defaultValue;
|
|
1130
1183
|
}
|
|
1131
|
-
return
|
|
1184
|
+
return propValue;
|
|
1132
1185
|
});
|
|
1133
1186
|
const cacheKey = JSON.stringify(inputValues);
|
|
1134
1187
|
let result = mapCacheRef.current.get(cacheKey);
|
|
1135
1188
|
if (!result) {
|
|
1136
|
-
|
|
1189
|
+
const runner = transform;
|
|
1190
|
+
result = runner ? runner(inputValues, props) : inputValues[0];
|
|
1137
1191
|
mapCacheRef.current.set(cacheKey, result);
|
|
1138
1192
|
}
|
|
1139
1193
|
if (Array.isArray(result)) {
|
|
@@ -1243,23 +1297,30 @@ var createVersionedComponentConfig = (componentName, version, allVersions, confi
|
|
|
1243
1297
|
};
|
|
1244
1298
|
};
|
|
1245
1299
|
|
|
1246
|
-
// src/puck/lib/generate-id.ts
|
|
1247
|
-
var import_uuid2 = require("uuid");
|
|
1248
|
-
var generateId = (type) => type ? `${type}-${(0, import_uuid2.v4)()}` : (0, import_uuid2.v4)();
|
|
1249
|
-
|
|
1250
1300
|
// src/puck/lib/builder/sub-component-decomposer.tsx
|
|
1251
1301
|
var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
1302
|
+
var _a;
|
|
1252
1303
|
const resolvedProps = __spreadValues({}, softSubComponent.fixedProps);
|
|
1253
|
-
softSubComponent.map.forEach((mapItem) => {
|
|
1254
|
-
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1304
|
+
(_a = softSubComponent.map) == null ? void 0 : _a.forEach((mapItem) => {
|
|
1305
|
+
const { from, to, transform } = mapItem || {};
|
|
1306
|
+
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
1307
|
+
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
1308
|
+
const inputs = fromPaths.map(
|
|
1309
|
+
(path) => getFieldSettingsByPath(componentRootData.props || {}, path)
|
|
1310
|
+
);
|
|
1311
|
+
const runner = transform;
|
|
1312
|
+
const result = runner ? runner(inputs, componentRootData.props) : inputs[0];
|
|
1313
|
+
if (Array.isArray(result)) {
|
|
1314
|
+
result.forEach((val, idx) => {
|
|
1315
|
+
if (toPaths[idx]) setPropertyByPath(resolvedProps, toPaths[idx], val);
|
|
1316
|
+
});
|
|
1317
|
+
} else if (toPaths[0]) {
|
|
1318
|
+
setPropertyByPath(resolvedProps, toPaths[0], result);
|
|
1258
1319
|
}
|
|
1259
1320
|
});
|
|
1260
1321
|
softSubComponent.enabledSlots.forEach(({ slot, name }) => {
|
|
1261
|
-
var
|
|
1262
|
-
const referenceName = name || `${(
|
|
1322
|
+
var _a2, _b;
|
|
1323
|
+
const referenceName = name || `${(_a2 = softSubComponent.fixedProps) == null ? void 0 : _a2.id}-${slot}`;
|
|
1263
1324
|
resolvedProps[slot] = ((_b = componentRootData.props) == null ? void 0 : _b[referenceName]) || [];
|
|
1264
1325
|
});
|
|
1265
1326
|
Object.entries(softSubComponent.components).forEach(
|
|
@@ -1619,6 +1680,52 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1619
1680
|
});
|
|
1620
1681
|
|
|
1621
1682
|
// src/puck/lib/build-initial-soft-components.ts
|
|
1683
|
+
function hydrateSubComponentsTransforms(subComponents, hydrator, context) {
|
|
1684
|
+
return subComponents.map((subComponent, idx) => {
|
|
1685
|
+
var _a;
|
|
1686
|
+
const path = [...context.subComponentPath, `${subComponent.type}:${idx}`];
|
|
1687
|
+
const mapped = (_a = subComponent.map) == null ? void 0 : _a.map((mapItem) => {
|
|
1688
|
+
if (mapItem == null ? void 0 : mapItem.transform) return mapItem;
|
|
1689
|
+
const transform = hydrator(mapItem, __spreadProps(__spreadValues({}, context), {
|
|
1690
|
+
subComponentPath: path
|
|
1691
|
+
}));
|
|
1692
|
+
return transform ? __spreadProps(__spreadValues({}, mapItem), { transform }) : mapItem;
|
|
1693
|
+
});
|
|
1694
|
+
const nestedComponents = Object.fromEntries(
|
|
1695
|
+
Object.entries(subComponent.components || {}).map(([slotKey, children]) => [
|
|
1696
|
+
slotKey,
|
|
1697
|
+
hydrateSubComponentsTransforms(children, hydrator, __spreadProps(__spreadValues({}, context), {
|
|
1698
|
+
subComponentPath: [...path, slotKey]
|
|
1699
|
+
}))
|
|
1700
|
+
])
|
|
1701
|
+
);
|
|
1702
|
+
return __spreadProps(__spreadValues({}, subComponent), {
|
|
1703
|
+
map: mapped,
|
|
1704
|
+
components: nestedComponents
|
|
1705
|
+
});
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
function hydrateSoftComponentsTransforms(softComponents, hydrator) {
|
|
1709
|
+
const hydrated = {};
|
|
1710
|
+
Object.entries(softComponents || {}).forEach(([name, comp]) => {
|
|
1711
|
+
const versions = {};
|
|
1712
|
+
Object.entries(comp.versions || {}).forEach(([version, softComponent]) => {
|
|
1713
|
+
versions[version] = __spreadProps(__spreadValues({}, softComponent), {
|
|
1714
|
+
components: hydrateSubComponentsTransforms(softComponent.components, hydrator, {
|
|
1715
|
+
componentName: name,
|
|
1716
|
+
version,
|
|
1717
|
+
subComponentPath: [],
|
|
1718
|
+
softComponent
|
|
1719
|
+
})
|
|
1720
|
+
});
|
|
1721
|
+
});
|
|
1722
|
+
hydrated[name] = {
|
|
1723
|
+
defaultVersion: comp.defaultVersion,
|
|
1724
|
+
versions
|
|
1725
|
+
};
|
|
1726
|
+
});
|
|
1727
|
+
return hydrated;
|
|
1728
|
+
}
|
|
1622
1729
|
function extractDependencies(softComponents, componentName, version) {
|
|
1623
1730
|
var _a, _b;
|
|
1624
1731
|
const dependencies = /* @__PURE__ */ new Set();
|
|
@@ -1685,15 +1792,16 @@ function topologicalSort(softComponents, hardComponentNames) {
|
|
|
1685
1792
|
}
|
|
1686
1793
|
return sorted;
|
|
1687
1794
|
}
|
|
1688
|
-
function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
1795
|
+
function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
1689
1796
|
var _a, _b;
|
|
1690
1797
|
if (!softComponents || Object.keys(softComponents).length === 0) {
|
|
1691
1798
|
return {};
|
|
1692
1799
|
}
|
|
1800
|
+
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(softComponents, overrides.hydrateMapTransform) : softComponents;
|
|
1693
1801
|
const hardComponentNames = new Set(Object.keys(hardConfig.components || {}));
|
|
1694
1802
|
try {
|
|
1695
1803
|
const sortedComponentNames = topologicalSort(
|
|
1696
|
-
|
|
1804
|
+
hydratedSoftComponents,
|
|
1697
1805
|
hardComponentNames
|
|
1698
1806
|
);
|
|
1699
1807
|
const buildingConfig = __spreadProps(__spreadValues({}, hardConfig), {
|
|
@@ -1701,7 +1809,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1701
1809
|
});
|
|
1702
1810
|
const componentConfigs = {};
|
|
1703
1811
|
for (const name of sortedComponentNames) {
|
|
1704
|
-
const comp =
|
|
1812
|
+
const comp = hydratedSoftComponents[name];
|
|
1705
1813
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1706
1814
|
const versionedComponent = (_a = comp.versions) == null ? void 0 : _a[defaultVersion || ""];
|
|
1707
1815
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1717,7 +1825,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1717
1825
|
allVersions,
|
|
1718
1826
|
buildingConfig,
|
|
1719
1827
|
// Pass the accumulating config
|
|
1720
|
-
|
|
1828
|
+
hydratedSoftComponents,
|
|
1721
1829
|
versionedComponent.defaultProps
|
|
1722
1830
|
);
|
|
1723
1831
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1728,7 +1836,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1728
1836
|
console.error("Error building soft components:", error);
|
|
1729
1837
|
console.warn("Falling back to unordered component building");
|
|
1730
1838
|
const componentConfigs = {};
|
|
1731
|
-
for (const [name, comp] of Object.entries(
|
|
1839
|
+
for (const [name, comp] of Object.entries(hydratedSoftComponents)) {
|
|
1732
1840
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1733
1841
|
const versionedComponent = (_b = comp.versions) == null ? void 0 : _b[defaultVersion || ""];
|
|
1734
1842
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1743,7 +1851,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1743
1851
|
defaultVersion || "1.0.0",
|
|
1744
1852
|
allVersions,
|
|
1745
1853
|
hardConfig,
|
|
1746
|
-
|
|
1854
|
+
hydratedSoftComponents,
|
|
1747
1855
|
versionedComponent.defaultProps
|
|
1748
1856
|
);
|
|
1749
1857
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1755,158 +1863,169 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1755
1863
|
// src/puck/store/index.tsx
|
|
1756
1864
|
var createSoftConfigStore = (hardConfig = {
|
|
1757
1865
|
components: {}
|
|
1758
|
-
}, softComponents = {}, overrides = {}) =>
|
|
1759
|
-
(0
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
name
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
get().softConfig,
|
|
1805
|
-
get().softComponents,
|
|
1806
|
-
softComponent.defaultProps
|
|
1807
|
-
);
|
|
1808
|
-
set((state) => ({
|
|
1809
|
-
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1810
|
-
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1811
|
-
[name]: newSoftComponentConfig
|
|
1812
|
-
})
|
|
1813
|
-
}),
|
|
1814
|
-
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1815
|
-
[name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
|
|
1816
|
-
defaultVersion: version
|
|
1817
|
-
})
|
|
1818
|
-
})
|
|
1819
|
-
}));
|
|
1820
|
-
},
|
|
1821
|
-
removeSoftComponentVersion: (key, version) => {
|
|
1822
|
-
set((state) => {
|
|
1823
|
-
const component = state.softComponents[key];
|
|
1824
|
-
if (!component) return {};
|
|
1825
|
-
const newVersions = Object.fromEntries(
|
|
1826
|
-
Object.entries(component.versions || {}).filter(
|
|
1827
|
-
([k, _]) => k !== version
|
|
1828
|
-
)
|
|
1866
|
+
}, softComponents = {}, overrides = {}) => {
|
|
1867
|
+
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
|
|
1868
|
+
softComponents,
|
|
1869
|
+
overrides.hydrateMapTransform
|
|
1870
|
+
) : softComponents;
|
|
1871
|
+
return (0, import_zustand2.create)()(
|
|
1872
|
+
(0, import_middleware.subscribeWithSelector)(
|
|
1873
|
+
(0, import_middleware.devtools)((set, get) => ({
|
|
1874
|
+
state: "ready",
|
|
1875
|
+
originalHistory: [],
|
|
1876
|
+
overrides,
|
|
1877
|
+
storeHistory: (history) => set({ originalHistory: history }),
|
|
1878
|
+
removeHistory: () => set({ originalHistory: [] }),
|
|
1879
|
+
itemSelector: null,
|
|
1880
|
+
setItemSelector: (selector) => set({ itemSelector: selector }),
|
|
1881
|
+
originalItem: null,
|
|
1882
|
+
setOriginalItem: (item) => set({ originalItem: item }),
|
|
1883
|
+
hydratedSoftComponents,
|
|
1884
|
+
softComponents: hydratedSoftComponents,
|
|
1885
|
+
softConfig: __spreadProps(__spreadValues({}, hardConfig), {
|
|
1886
|
+
components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
|
|
1887
|
+
hardConfig,
|
|
1888
|
+
hydratedSoftComponents,
|
|
1889
|
+
overrides
|
|
1890
|
+
))
|
|
1891
|
+
}),
|
|
1892
|
+
setSoftComponent: (name, version, component) => {
|
|
1893
|
+
set((state) => {
|
|
1894
|
+
var _a;
|
|
1895
|
+
return {
|
|
1896
|
+
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1897
|
+
[name]: {
|
|
1898
|
+
defaultVersion: version,
|
|
1899
|
+
versions: __spreadProps(__spreadValues({}, ((_a = state.softComponents[name]) == null ? void 0 : _a.versions) || {}), {
|
|
1900
|
+
[version]: component
|
|
1901
|
+
})
|
|
1902
|
+
}
|
|
1903
|
+
})
|
|
1904
|
+
};
|
|
1905
|
+
});
|
|
1906
|
+
},
|
|
1907
|
+
setSoftComponentDefaultVersion: (name, version) => {
|
|
1908
|
+
var _a, _b, _c;
|
|
1909
|
+
const softComponent = (_b = (_a = get().softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
|
|
1910
|
+
const allVersions = Object.keys(
|
|
1911
|
+
((_c = get().softComponents[name]) == null ? void 0 : _c.versions) || {}
|
|
1829
1912
|
);
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1913
|
+
if (!softComponent) {
|
|
1914
|
+
throw new Error(
|
|
1915
|
+
`Soft component "${name}" version "${version}" does not exist.`
|
|
1916
|
+
);
|
|
1834
1917
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
},
|
|
1845
|
-
removeSoftComponent: (key) => {
|
|
1846
|
-
set((state) => ({
|
|
1847
|
-
softComponents: Object.fromEntries(
|
|
1848
|
-
Object.entries(state.softComponents).filter(([k, _]) => k !== key)
|
|
1849
|
-
)
|
|
1850
|
-
}));
|
|
1851
|
-
},
|
|
1852
|
-
setSoftComponentConfig: (key, config, category) => {
|
|
1853
|
-
set((state) => {
|
|
1854
|
-
var _a;
|
|
1855
|
-
return {
|
|
1918
|
+
const newSoftComponentConfig = createVersionedComponentConfig(
|
|
1919
|
+
name,
|
|
1920
|
+
version,
|
|
1921
|
+
allVersions,
|
|
1922
|
+
get().softConfig,
|
|
1923
|
+
get().softComponents,
|
|
1924
|
+
softComponent.defaultProps
|
|
1925
|
+
);
|
|
1926
|
+
set((state) => ({
|
|
1856
1927
|
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1857
1928
|
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1858
|
-
[
|
|
1859
|
-
})
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
]
|
|
1866
|
-
})
|
|
1867
|
-
}) : state.softConfig.categories
|
|
1929
|
+
[name]: newSoftComponentConfig
|
|
1930
|
+
})
|
|
1931
|
+
}),
|
|
1932
|
+
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1933
|
+
[name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
|
|
1934
|
+
defaultVersion: version
|
|
1935
|
+
})
|
|
1868
1936
|
})
|
|
1869
|
-
};
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
Object.entries(
|
|
1877
|
-
([k, _]) => k !==
|
|
1937
|
+
}));
|
|
1938
|
+
},
|
|
1939
|
+
removeSoftComponentVersion: (key, version) => {
|
|
1940
|
+
set((state) => {
|
|
1941
|
+
const component = state.softComponents[key];
|
|
1942
|
+
if (!component) return {};
|
|
1943
|
+
const newVersions = Object.fromEntries(
|
|
1944
|
+
Object.entries(component.versions || {}).filter(
|
|
1945
|
+
([k, _]) => k !== version
|
|
1878
1946
|
)
|
|
1947
|
+
);
|
|
1948
|
+
let newDefaultVersion = component.defaultVersion;
|
|
1949
|
+
if (component.defaultVersion === version) {
|
|
1950
|
+
const versionKeys = Object.keys(newVersions);
|
|
1951
|
+
newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
|
|
1952
|
+
}
|
|
1953
|
+
return {
|
|
1954
|
+
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1955
|
+
[key]: __spreadProps(__spreadValues({}, component), {
|
|
1956
|
+
versions: newVersions,
|
|
1957
|
+
defaultVersion: newDefaultVersion
|
|
1958
|
+
})
|
|
1959
|
+
})
|
|
1960
|
+
};
|
|
1961
|
+
});
|
|
1962
|
+
},
|
|
1963
|
+
removeSoftComponent: (key) => {
|
|
1964
|
+
set((state) => ({
|
|
1965
|
+
softComponents: Object.fromEntries(
|
|
1966
|
+
Object.entries(state.softComponents).filter(([k, _]) => k !== key)
|
|
1879
1967
|
)
|
|
1880
|
-
})
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1968
|
+
}));
|
|
1969
|
+
},
|
|
1970
|
+
setSoftComponentConfig: (key, config, category) => {
|
|
1971
|
+
set((state) => {
|
|
1972
|
+
var _a;
|
|
1973
|
+
return {
|
|
1974
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1975
|
+
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1976
|
+
[key]: __spreadValues({}, config)
|
|
1977
|
+
}),
|
|
1978
|
+
categories: category && state.softConfig.categories ? __spreadProps(__spreadValues({}, state.softConfig.categories), {
|
|
1979
|
+
[category]: __spreadProps(__spreadValues({}, state.softConfig.categories[category]), {
|
|
1980
|
+
components: [
|
|
1981
|
+
...((_a = state.softConfig.categories[category]) == null ? void 0 : _a.components) || [],
|
|
1982
|
+
key
|
|
1983
|
+
]
|
|
1984
|
+
})
|
|
1985
|
+
}) : state.softConfig.categories
|
|
1890
1986
|
})
|
|
1987
|
+
};
|
|
1988
|
+
});
|
|
1989
|
+
},
|
|
1990
|
+
removeSoftComponentConfig: (key) => {
|
|
1991
|
+
set((state) => ({
|
|
1992
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1993
|
+
components: Object.fromEntries(
|
|
1994
|
+
Object.entries(state.softConfig.components).filter(
|
|
1995
|
+
([k, _]) => k !== key
|
|
1996
|
+
)
|
|
1997
|
+
)
|
|
1891
1998
|
})
|
|
1892
|
-
};
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1999
|
+
}));
|
|
2000
|
+
},
|
|
2001
|
+
setSoftCategoryConfig: (key, category) => {
|
|
2002
|
+
set((state) => {
|
|
2003
|
+
var _a;
|
|
2004
|
+
return {
|
|
2005
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
2006
|
+
categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
|
|
2007
|
+
[key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
|
|
2008
|
+
})
|
|
2009
|
+
})
|
|
2010
|
+
};
|
|
2011
|
+
});
|
|
2012
|
+
},
|
|
2013
|
+
removeSoftCategoryConfig: (key) => {
|
|
2014
|
+
set((state) => ({
|
|
2015
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
2016
|
+
categories: Object.fromEntries(
|
|
2017
|
+
Object.entries(state.softConfig.categories || {}).filter(
|
|
2018
|
+
([k, _]) => k !== key
|
|
2019
|
+
)
|
|
1901
2020
|
)
|
|
1902
|
-
)
|
|
1903
|
-
})
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
)
|
|
1909
|
-
|
|
2021
|
+
})
|
|
2022
|
+
}));
|
|
2023
|
+
},
|
|
2024
|
+
builder: createBuildersSlice(set, get, hardConfig)
|
|
2025
|
+
}))
|
|
2026
|
+
)
|
|
2027
|
+
);
|
|
2028
|
+
};
|
|
1910
2029
|
|
|
1911
2030
|
// src/puck/context/storeProvider.tsx
|
|
1912
2031
|
var import_react5 = require("react");
|