@netlisian/softconfig 0.0.4 → 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 +14 -8
- package/dist/puck/index.d.ts +14 -8
- package/dist/puck/index.js +316 -187
- package/dist/puck/index.mjs +316 -187
- package/package.json +11 -11
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 = {
|
|
@@ -924,6 +954,7 @@ var softComponentFromAppState = (appState, configComponents) => {
|
|
|
924
954
|
acc[slot] = { type: "slot", label: slot };
|
|
925
955
|
return acc;
|
|
926
956
|
}, {})),
|
|
957
|
+
fieldSettings: field_settings,
|
|
927
958
|
defaultProps,
|
|
928
959
|
components,
|
|
929
960
|
slots
|
|
@@ -932,6 +963,10 @@ var softComponentFromAppState = (appState, configComponents) => {
|
|
|
932
963
|
];
|
|
933
964
|
};
|
|
934
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
|
+
|
|
935
970
|
// src/puck/lib/soft-component-to-appstate.ts
|
|
936
971
|
var puckFieldsToSoftFields = (fields, slots) => {
|
|
937
972
|
const softFields = [];
|
|
@@ -998,11 +1033,27 @@ var puckFieldsToSoftFields = (fields, slots) => {
|
|
|
998
1033
|
};
|
|
999
1034
|
var reconstructComponents = (subComponents, componentConfigs, softComponentProps) => {
|
|
1000
1035
|
return subComponents.map((subComponent) => {
|
|
1001
|
-
|
|
1036
|
+
var _a;
|
|
1002
1037
|
const props = __spreadValues({}, subComponent.fixedProps);
|
|
1003
|
-
subComponent.map.forEach((
|
|
1004
|
-
|
|
1005
|
-
|
|
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;
|
|
1006
1057
|
}
|
|
1007
1058
|
});
|
|
1008
1059
|
if (subComponent.enabledSlots.length > 0) {
|
|
@@ -1028,7 +1079,7 @@ var reconstructComponents = (subComponents, componentConfigs, softComponentProps
|
|
|
1028
1079
|
const componentData = {
|
|
1029
1080
|
type: subComponent.type,
|
|
1030
1081
|
props: __spreadValues({
|
|
1031
|
-
id: props.id ||
|
|
1082
|
+
id: props.id || generateId(subComponent.type)
|
|
1032
1083
|
}, props)
|
|
1033
1084
|
};
|
|
1034
1085
|
return componentData;
|
|
@@ -1074,10 +1125,11 @@ var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
|
1074
1125
|
|
|
1075
1126
|
// src/puck/components/soft-render/index.tsx
|
|
1076
1127
|
var import_react4 = require("react");
|
|
1077
|
-
var
|
|
1128
|
+
var import_uuid2 = require("uuid");
|
|
1078
1129
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1079
1130
|
function SoftRender({
|
|
1080
1131
|
softComponentFields,
|
|
1132
|
+
softComponentFieldSettings,
|
|
1081
1133
|
softSubComponent,
|
|
1082
1134
|
configComponents,
|
|
1083
1135
|
props,
|
|
@@ -1111,20 +1163,31 @@ function SoftRender({
|
|
|
1111
1163
|
if (!componentConfig) return null;
|
|
1112
1164
|
const resolvedProps = subComponent.fixedProps || {};
|
|
1113
1165
|
const stableId = (0, import_react4.useMemo)(
|
|
1114
|
-
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${(0,
|
|
1166
|
+
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${(0, import_uuid2.v4)()}`,
|
|
1115
1167
|
[id, depth, subComponent.type]
|
|
1116
1168
|
);
|
|
1117
1169
|
if ((_a2 = subComponent.map) == null ? void 0 : _a2.length) {
|
|
1118
|
-
subComponent.map.forEach((
|
|
1170
|
+
subComponent.map.forEach((mapItem) => {
|
|
1171
|
+
const { from, to, transform } = mapItem || {};
|
|
1119
1172
|
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
1120
1173
|
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
1121
|
-
const inputValues = fromPaths.map(
|
|
1122
|
-
|
|
1123
|
-
|
|
1174
|
+
const inputValues = fromPaths.map((f) => {
|
|
1175
|
+
const propValue = getFieldSettingsByPath(props || {}, f);
|
|
1176
|
+
if (propValue !== void 0) return propValue;
|
|
1177
|
+
const setting = getFieldSettingsByPath(
|
|
1178
|
+
softComponentFieldSettings || {},
|
|
1179
|
+
f
|
|
1180
|
+
);
|
|
1181
|
+
if (setting && Object.prototype.hasOwnProperty.call(setting, "defaultValue")) {
|
|
1182
|
+
return setting.defaultValue;
|
|
1183
|
+
}
|
|
1184
|
+
return propValue;
|
|
1185
|
+
});
|
|
1124
1186
|
const cacheKey = JSON.stringify(inputValues);
|
|
1125
1187
|
let result = mapCacheRef.current.get(cacheKey);
|
|
1126
1188
|
if (!result) {
|
|
1127
|
-
|
|
1189
|
+
const runner = transform;
|
|
1190
|
+
result = runner ? runner(inputValues, props) : inputValues[0];
|
|
1128
1191
|
mapCacheRef.current.set(cacheKey, result);
|
|
1129
1192
|
}
|
|
1130
1193
|
if (Array.isArray(result)) {
|
|
@@ -1224,6 +1287,7 @@ var createVersionedComponentConfig = (componentName, version, allVersions, confi
|
|
|
1224
1287
|
SoftRender,
|
|
1225
1288
|
{
|
|
1226
1289
|
softComponentFields: versionedComponent.fields,
|
|
1290
|
+
softComponentFieldSettings: versionedComponent.fieldSettings,
|
|
1227
1291
|
softSubComponent: versionedComponent.components,
|
|
1228
1292
|
configComponents: softConfig.components,
|
|
1229
1293
|
props
|
|
@@ -1233,23 +1297,30 @@ var createVersionedComponentConfig = (componentName, version, allVersions, confi
|
|
|
1233
1297
|
};
|
|
1234
1298
|
};
|
|
1235
1299
|
|
|
1236
|
-
// src/puck/lib/generate-id.ts
|
|
1237
|
-
var import_uuid2 = require("uuid");
|
|
1238
|
-
var generateId = (type) => type ? `${type}-${(0, import_uuid2.v4)()}` : (0, import_uuid2.v4)();
|
|
1239
|
-
|
|
1240
1300
|
// src/puck/lib/builder/sub-component-decomposer.tsx
|
|
1241
1301
|
var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
1302
|
+
var _a;
|
|
1242
1303
|
const resolvedProps = __spreadValues({}, softSubComponent.fixedProps);
|
|
1243
|
-
softSubComponent.map.forEach((mapItem) => {
|
|
1244
|
-
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1247
|
-
|
|
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);
|
|
1248
1319
|
}
|
|
1249
1320
|
});
|
|
1250
1321
|
softSubComponent.enabledSlots.forEach(({ slot, name }) => {
|
|
1251
|
-
var
|
|
1252
|
-
const referenceName = name || `${(
|
|
1322
|
+
var _a2, _b;
|
|
1323
|
+
const referenceName = name || `${(_a2 = softSubComponent.fixedProps) == null ? void 0 : _a2.id}-${slot}`;
|
|
1253
1324
|
resolvedProps[slot] = ((_b = componentRootData.props) == null ? void 0 : _b[referenceName]) || [];
|
|
1254
1325
|
});
|
|
1255
1326
|
Object.entries(softSubComponent.components).forEach(
|
|
@@ -1609,6 +1680,52 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1609
1680
|
});
|
|
1610
1681
|
|
|
1611
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
|
+
}
|
|
1612
1729
|
function extractDependencies(softComponents, componentName, version) {
|
|
1613
1730
|
var _a, _b;
|
|
1614
1731
|
const dependencies = /* @__PURE__ */ new Set();
|
|
@@ -1675,15 +1792,16 @@ function topologicalSort(softComponents, hardComponentNames) {
|
|
|
1675
1792
|
}
|
|
1676
1793
|
return sorted;
|
|
1677
1794
|
}
|
|
1678
|
-
function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
1795
|
+
function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
1679
1796
|
var _a, _b;
|
|
1680
1797
|
if (!softComponents || Object.keys(softComponents).length === 0) {
|
|
1681
1798
|
return {};
|
|
1682
1799
|
}
|
|
1800
|
+
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(softComponents, overrides.hydrateMapTransform) : softComponents;
|
|
1683
1801
|
const hardComponentNames = new Set(Object.keys(hardConfig.components || {}));
|
|
1684
1802
|
try {
|
|
1685
1803
|
const sortedComponentNames = topologicalSort(
|
|
1686
|
-
|
|
1804
|
+
hydratedSoftComponents,
|
|
1687
1805
|
hardComponentNames
|
|
1688
1806
|
);
|
|
1689
1807
|
const buildingConfig = __spreadProps(__spreadValues({}, hardConfig), {
|
|
@@ -1691,7 +1809,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1691
1809
|
});
|
|
1692
1810
|
const componentConfigs = {};
|
|
1693
1811
|
for (const name of sortedComponentNames) {
|
|
1694
|
-
const comp =
|
|
1812
|
+
const comp = hydratedSoftComponents[name];
|
|
1695
1813
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1696
1814
|
const versionedComponent = (_a = comp.versions) == null ? void 0 : _a[defaultVersion || ""];
|
|
1697
1815
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1707,7 +1825,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1707
1825
|
allVersions,
|
|
1708
1826
|
buildingConfig,
|
|
1709
1827
|
// Pass the accumulating config
|
|
1710
|
-
|
|
1828
|
+
hydratedSoftComponents,
|
|
1711
1829
|
versionedComponent.defaultProps
|
|
1712
1830
|
);
|
|
1713
1831
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1718,7 +1836,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1718
1836
|
console.error("Error building soft components:", error);
|
|
1719
1837
|
console.warn("Falling back to unordered component building");
|
|
1720
1838
|
const componentConfigs = {};
|
|
1721
|
-
for (const [name, comp] of Object.entries(
|
|
1839
|
+
for (const [name, comp] of Object.entries(hydratedSoftComponents)) {
|
|
1722
1840
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1723
1841
|
const versionedComponent = (_b = comp.versions) == null ? void 0 : _b[defaultVersion || ""];
|
|
1724
1842
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1733,7 +1851,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1733
1851
|
defaultVersion || "1.0.0",
|
|
1734
1852
|
allVersions,
|
|
1735
1853
|
hardConfig,
|
|
1736
|
-
|
|
1854
|
+
hydratedSoftComponents,
|
|
1737
1855
|
versionedComponent.defaultProps
|
|
1738
1856
|
);
|
|
1739
1857
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1745,158 +1863,169 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1745
1863
|
// src/puck/store/index.tsx
|
|
1746
1864
|
var createSoftConfigStore = (hardConfig = {
|
|
1747
1865
|
components: {}
|
|
1748
|
-
}, softComponents = {}, overrides = {}) =>
|
|
1749
|
-
(0
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
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
|
-
name
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
get().softConfig,
|
|
1795
|
-
get().softComponents,
|
|
1796
|
-
softComponent.defaultProps
|
|
1797
|
-
);
|
|
1798
|
-
set((state) => ({
|
|
1799
|
-
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1800
|
-
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1801
|
-
[name]: newSoftComponentConfig
|
|
1802
|
-
})
|
|
1803
|
-
}),
|
|
1804
|
-
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1805
|
-
[name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
|
|
1806
|
-
defaultVersion: version
|
|
1807
|
-
})
|
|
1808
|
-
})
|
|
1809
|
-
}));
|
|
1810
|
-
},
|
|
1811
|
-
removeSoftComponentVersion: (key, version) => {
|
|
1812
|
-
set((state) => {
|
|
1813
|
-
const component = state.softComponents[key];
|
|
1814
|
-
if (!component) return {};
|
|
1815
|
-
const newVersions = Object.fromEntries(
|
|
1816
|
-
Object.entries(component.versions || {}).filter(
|
|
1817
|
-
([k, _]) => k !== version
|
|
1818
|
-
)
|
|
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) || {}
|
|
1819
1912
|
);
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1913
|
+
if (!softComponent) {
|
|
1914
|
+
throw new Error(
|
|
1915
|
+
`Soft component "${name}" version "${version}" does not exist.`
|
|
1916
|
+
);
|
|
1824
1917
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
},
|
|
1835
|
-
removeSoftComponent: (key) => {
|
|
1836
|
-
set((state) => ({
|
|
1837
|
-
softComponents: Object.fromEntries(
|
|
1838
|
-
Object.entries(state.softComponents).filter(([k, _]) => k !== key)
|
|
1839
|
-
)
|
|
1840
|
-
}));
|
|
1841
|
-
},
|
|
1842
|
-
setSoftComponentConfig: (key, config, category) => {
|
|
1843
|
-
set((state) => {
|
|
1844
|
-
var _a;
|
|
1845
|
-
return {
|
|
1918
|
+
const newSoftComponentConfig = createVersionedComponentConfig(
|
|
1919
|
+
name,
|
|
1920
|
+
version,
|
|
1921
|
+
allVersions,
|
|
1922
|
+
get().softConfig,
|
|
1923
|
+
get().softComponents,
|
|
1924
|
+
softComponent.defaultProps
|
|
1925
|
+
);
|
|
1926
|
+
set((state) => ({
|
|
1846
1927
|
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1847
1928
|
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1848
|
-
[
|
|
1849
|
-
})
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
]
|
|
1856
|
-
})
|
|
1857
|
-
}) : 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
|
+
})
|
|
1858
1936
|
})
|
|
1859
|
-
};
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
Object.entries(
|
|
1867
|
-
([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
|
|
1868
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)
|
|
1869
1967
|
)
|
|
1870
|
-
})
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
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
|
|
1880
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
|
+
)
|
|
1881
1998
|
})
|
|
1882
|
-
};
|
|
1883
|
-
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
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
|
+
)
|
|
1891
2020
|
)
|
|
1892
|
-
)
|
|
1893
|
-
})
|
|
1894
|
-
}
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
)
|
|
1899
|
-
|
|
2021
|
+
})
|
|
2022
|
+
}));
|
|
2023
|
+
},
|
|
2024
|
+
builder: createBuildersSlice(set, get, hardConfig)
|
|
2025
|
+
}))
|
|
2026
|
+
)
|
|
2027
|
+
);
|
|
2028
|
+
};
|
|
1900
2029
|
|
|
1901
2030
|
// src/puck/context/storeProvider.tsx
|
|
1902
2031
|
var import_react5 = require("react");
|