@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.mjs
CHANGED
|
@@ -405,7 +405,6 @@ var builderRootConfig = (config, overrides, editingComponent) => ({
|
|
|
405
405
|
const inputValues = fromPaths.map(
|
|
406
406
|
(f) => getFieldSettingsByPath(props._fieldSettings || {}, f)
|
|
407
407
|
);
|
|
408
|
-
console.log(inputValues);
|
|
409
408
|
let value = transform ? transform(
|
|
410
409
|
inputValues.map((v) => v == null ? void 0 : v.defaultValue),
|
|
411
410
|
child.props
|
|
@@ -486,7 +485,7 @@ function generateFieldOptions(fields, selectedFields, prefix = "") {
|
|
|
486
485
|
if (selectedFields.includes(path)) {
|
|
487
486
|
return;
|
|
488
487
|
}
|
|
489
|
-
opts.push({ label: path, value: path });
|
|
488
|
+
opts.push({ label: path, value: path, type: fld.type });
|
|
490
489
|
if (fld.type === "object" && fld.objectFields) {
|
|
491
490
|
recurse(fld.objectFields, path);
|
|
492
491
|
}
|
|
@@ -506,7 +505,7 @@ function generateDynamicFieldOptions(_fields, _fieldSettings, prefix = "") {
|
|
|
506
505
|
var _a;
|
|
507
506
|
const settings = fieldSettings[field.name];
|
|
508
507
|
const path = currentPrefix ? `${currentPrefix}.${field.name}` : field.name;
|
|
509
|
-
opts.push({ label: path, value: path });
|
|
508
|
+
opts.push({ label: path, value: path, type: field.type });
|
|
510
509
|
if ((_a = settings == null ? void 0 : settings.subFields) == null ? void 0 : _a.length) {
|
|
511
510
|
recurse(settings.subFields, settings.subFieldSettings || {}, path);
|
|
512
511
|
}
|
|
@@ -655,20 +654,24 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
655
654
|
const defaultFields = component.resolveFields ? yield component.resolveFields(data, params) : component.fields || {};
|
|
656
655
|
if (!fields._map) {
|
|
657
656
|
const rootProps = getRootProps(params.appState);
|
|
657
|
+
const fromOptions = generateDynamicFieldOptions(
|
|
658
|
+
(rootProps == null ? void 0 : rootProps._fields) || [],
|
|
659
|
+
(rootProps == null ? void 0 : rootProps._fieldSettings) || {}
|
|
660
|
+
);
|
|
661
|
+
const toOptions = generateFieldOptions(defaultFields, []);
|
|
658
662
|
fields._map = overrides.map ? {
|
|
659
663
|
type: "custom",
|
|
660
664
|
render: ({ value, onChange, id }) => {
|
|
665
|
+
const toOptions2 = generateFieldOptions(defaultFields, []);
|
|
666
|
+
const rootProps2 = getRootProps(params.appState);
|
|
661
667
|
return overrides.map({
|
|
662
|
-
rootProps,
|
|
668
|
+
rootProps: rootProps2,
|
|
663
669
|
value,
|
|
664
670
|
onChange,
|
|
665
671
|
id,
|
|
666
672
|
props: data.props || {},
|
|
667
|
-
fromOptions
|
|
668
|
-
|
|
669
|
-
(rootProps == null ? void 0 : rootProps._fieldSettings) || {}
|
|
670
|
-
),
|
|
671
|
-
toOptions: generateFieldOptions(defaultFields, [])
|
|
673
|
+
fromOptions,
|
|
674
|
+
toOptions: toOptions2
|
|
672
675
|
});
|
|
673
676
|
}
|
|
674
677
|
} : {
|
|
@@ -680,10 +683,10 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
680
683
|
label: "From",
|
|
681
684
|
options: [
|
|
682
685
|
{ label: "Select a field", value: "" },
|
|
683
|
-
...
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
)
|
|
686
|
+
...fromOptions.map(({ label, value }) => ({
|
|
687
|
+
label,
|
|
688
|
+
value
|
|
689
|
+
}))
|
|
687
690
|
]
|
|
688
691
|
},
|
|
689
692
|
to: {
|
|
@@ -691,7 +694,10 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
691
694
|
label: "To",
|
|
692
695
|
options: [
|
|
693
696
|
{ label: "Select a field", value: "" },
|
|
694
|
-
...
|
|
697
|
+
...toOptions.map(({ label, value }) => ({
|
|
698
|
+
label,
|
|
699
|
+
value
|
|
700
|
+
}))
|
|
695
701
|
]
|
|
696
702
|
}
|
|
697
703
|
}
|
|
@@ -750,6 +756,25 @@ var builderConfig = (config, overrides, editingComponent) => ({
|
|
|
750
756
|
)
|
|
751
757
|
});
|
|
752
758
|
|
|
759
|
+
// src/puck/lib/strip-id.ts
|
|
760
|
+
var stripIdFromProps = (components, allowedTypes) => {
|
|
761
|
+
return components.map((component) => sanitizeComponent(component, allowedTypes));
|
|
762
|
+
};
|
|
763
|
+
var sanitizeComponent = (component, allowedTypes) => {
|
|
764
|
+
const cleanProps = {};
|
|
765
|
+
for (const [key, value] of Object.entries(component.props)) {
|
|
766
|
+
if (key === "id") continue;
|
|
767
|
+
if (value && typeof value === "object" && "type" in value && allowedTypes.includes(value.type)) {
|
|
768
|
+
cleanProps[key] = sanitizeComponent(value, allowedTypes);
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
cleanProps[key] = value;
|
|
772
|
+
}
|
|
773
|
+
return __spreadProps(__spreadValues({}, component), {
|
|
774
|
+
props: cleanProps
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
|
|
753
778
|
// src/puck/lib/soft-component-from-appstate.ts
|
|
754
779
|
var getSubComponents = (content, componentConfigs, fieldSettings, slots) => {
|
|
755
780
|
if (!content || !Array.isArray(content)) return [];
|
|
@@ -779,8 +804,13 @@ var getSubComponents = (content, componentConfigs, fieldSettings, slots) => {
|
|
|
779
804
|
(componentProps.props._slot || []).forEach(
|
|
780
805
|
(s) => {
|
|
781
806
|
var _a2;
|
|
782
|
-
if (s.slot)
|
|
783
|
-
|
|
807
|
+
if (s.slot) {
|
|
808
|
+
const slotComponentProps = componentProps.props[s.slot] || ((_a2 = componentConfig == null ? void 0 : componentConfig.defaultProps) == null ? void 0 : _a2[s.slot]);
|
|
809
|
+
slots[s.name || `${componentProps.props.id}-${s.slot}`] = stripIdFromProps(
|
|
810
|
+
slotComponentProps,
|
|
811
|
+
Object.keys(componentConfigs)
|
|
812
|
+
);
|
|
813
|
+
}
|
|
784
814
|
}
|
|
785
815
|
);
|
|
786
816
|
const subComponent = {
|
|
@@ -874,6 +904,7 @@ var softComponentFromAppState = (appState, configComponents) => {
|
|
|
874
904
|
acc[slot] = { type: "slot", label: slot };
|
|
875
905
|
return acc;
|
|
876
906
|
}, {})),
|
|
907
|
+
fieldSettings: field_settings,
|
|
877
908
|
defaultProps,
|
|
878
909
|
components,
|
|
879
910
|
slots
|
|
@@ -882,6 +913,10 @@ var softComponentFromAppState = (appState, configComponents) => {
|
|
|
882
913
|
];
|
|
883
914
|
};
|
|
884
915
|
|
|
916
|
+
// src/puck/lib/generate-id.ts
|
|
917
|
+
import { v4 as uuidv4 } from "uuid";
|
|
918
|
+
var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
|
|
919
|
+
|
|
885
920
|
// src/puck/lib/soft-component-to-appstate.ts
|
|
886
921
|
var puckFieldsToSoftFields = (fields, slots) => {
|
|
887
922
|
const softFields = [];
|
|
@@ -948,11 +983,27 @@ var puckFieldsToSoftFields = (fields, slots) => {
|
|
|
948
983
|
};
|
|
949
984
|
var reconstructComponents = (subComponents, componentConfigs, softComponentProps) => {
|
|
950
985
|
return subComponents.map((subComponent) => {
|
|
951
|
-
|
|
986
|
+
var _a;
|
|
952
987
|
const props = __spreadValues({}, subComponent.fixedProps);
|
|
953
|
-
subComponent.map.forEach((
|
|
954
|
-
|
|
955
|
-
|
|
988
|
+
(_a = subComponent.map) == null ? void 0 : _a.forEach((mapItem, i) => {
|
|
989
|
+
var _a2;
|
|
990
|
+
const { from, to, transform } = mapItem || {};
|
|
991
|
+
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
992
|
+
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
993
|
+
const inputs = fromPaths.map(
|
|
994
|
+
(path) => getFieldSettingsByPath(softComponentProps || {}, path)
|
|
995
|
+
);
|
|
996
|
+
const runner = transform;
|
|
997
|
+
const result = runner ? runner(inputs, softComponentProps) : inputs[0];
|
|
998
|
+
if (Array.isArray(result)) {
|
|
999
|
+
result.forEach((val, idx) => {
|
|
1000
|
+
if (toPaths[idx]) setPropertyByPath(props, toPaths[idx], val);
|
|
1001
|
+
});
|
|
1002
|
+
} else {
|
|
1003
|
+
toPaths.forEach((toPath) => setPropertyByPath(props, toPath, result));
|
|
1004
|
+
}
|
|
1005
|
+
if (transform && ((_a2 = props._map) == null ? void 0 : _a2[i])) {
|
|
1006
|
+
props._map[i].transform = transform;
|
|
956
1007
|
}
|
|
957
1008
|
});
|
|
958
1009
|
if (subComponent.enabledSlots.length > 0) {
|
|
@@ -978,7 +1029,7 @@ var reconstructComponents = (subComponents, componentConfigs, softComponentProps
|
|
|
978
1029
|
const componentData = {
|
|
979
1030
|
type: subComponent.type,
|
|
980
1031
|
props: __spreadValues({
|
|
981
|
-
id: props.id ||
|
|
1032
|
+
id: props.id || generateId(subComponent.type)
|
|
982
1033
|
}, props)
|
|
983
1034
|
};
|
|
984
1035
|
return componentData;
|
|
@@ -1024,10 +1075,11 @@ var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
|
1024
1075
|
|
|
1025
1076
|
// src/puck/components/soft-render/index.tsx
|
|
1026
1077
|
import { useMemo, useRef } from "react";
|
|
1027
|
-
import { v4 as
|
|
1078
|
+
import { v4 as uuidv42 } from "uuid";
|
|
1028
1079
|
import { Fragment as Fragment2, jsx as jsx5 } from "react/jsx-runtime";
|
|
1029
1080
|
function SoftRender({
|
|
1030
1081
|
softComponentFields,
|
|
1082
|
+
softComponentFieldSettings,
|
|
1031
1083
|
softSubComponent,
|
|
1032
1084
|
configComponents,
|
|
1033
1085
|
props,
|
|
@@ -1061,20 +1113,31 @@ function SoftRender({
|
|
|
1061
1113
|
if (!componentConfig) return null;
|
|
1062
1114
|
const resolvedProps = subComponent.fixedProps || {};
|
|
1063
1115
|
const stableId = useMemo(
|
|
1064
|
-
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${
|
|
1116
|
+
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${uuidv42()}`,
|
|
1065
1117
|
[id, depth, subComponent.type]
|
|
1066
1118
|
);
|
|
1067
1119
|
if ((_a2 = subComponent.map) == null ? void 0 : _a2.length) {
|
|
1068
|
-
subComponent.map.forEach((
|
|
1120
|
+
subComponent.map.forEach((mapItem) => {
|
|
1121
|
+
const { from, to, transform } = mapItem || {};
|
|
1069
1122
|
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
1070
1123
|
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
1071
|
-
const inputValues = fromPaths.map(
|
|
1072
|
-
|
|
1073
|
-
|
|
1124
|
+
const inputValues = fromPaths.map((f) => {
|
|
1125
|
+
const propValue = getFieldSettingsByPath(props || {}, f);
|
|
1126
|
+
if (propValue !== void 0) return propValue;
|
|
1127
|
+
const setting = getFieldSettingsByPath(
|
|
1128
|
+
softComponentFieldSettings || {},
|
|
1129
|
+
f
|
|
1130
|
+
);
|
|
1131
|
+
if (setting && Object.prototype.hasOwnProperty.call(setting, "defaultValue")) {
|
|
1132
|
+
return setting.defaultValue;
|
|
1133
|
+
}
|
|
1134
|
+
return propValue;
|
|
1135
|
+
});
|
|
1074
1136
|
const cacheKey = JSON.stringify(inputValues);
|
|
1075
1137
|
let result = mapCacheRef.current.get(cacheKey);
|
|
1076
1138
|
if (!result) {
|
|
1077
|
-
|
|
1139
|
+
const runner = transform;
|
|
1140
|
+
result = runner ? runner(inputValues, props) : inputValues[0];
|
|
1078
1141
|
mapCacheRef.current.set(cacheKey, result);
|
|
1079
1142
|
}
|
|
1080
1143
|
if (Array.isArray(result)) {
|
|
@@ -1174,6 +1237,7 @@ var createVersionedComponentConfig = (componentName, version, allVersions, confi
|
|
|
1174
1237
|
SoftRender,
|
|
1175
1238
|
{
|
|
1176
1239
|
softComponentFields: versionedComponent.fields,
|
|
1240
|
+
softComponentFieldSettings: versionedComponent.fieldSettings,
|
|
1177
1241
|
softSubComponent: versionedComponent.components,
|
|
1178
1242
|
configComponents: softConfig.components,
|
|
1179
1243
|
props
|
|
@@ -1183,23 +1247,30 @@ var createVersionedComponentConfig = (componentName, version, allVersions, confi
|
|
|
1183
1247
|
};
|
|
1184
1248
|
};
|
|
1185
1249
|
|
|
1186
|
-
// src/puck/lib/generate-id.ts
|
|
1187
|
-
import { v4 as uuidv42 } from "uuid";
|
|
1188
|
-
var generateId = (type) => type ? `${type}-${uuidv42()}` : uuidv42();
|
|
1189
|
-
|
|
1190
1250
|
// src/puck/lib/builder/sub-component-decomposer.tsx
|
|
1191
1251
|
var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
1252
|
+
var _a;
|
|
1192
1253
|
const resolvedProps = __spreadValues({}, softSubComponent.fixedProps);
|
|
1193
|
-
softSubComponent.map.forEach((mapItem) => {
|
|
1194
|
-
|
|
1195
|
-
const
|
|
1196
|
-
|
|
1197
|
-
|
|
1254
|
+
(_a = softSubComponent.map) == null ? void 0 : _a.forEach((mapItem) => {
|
|
1255
|
+
const { from, to, transform } = mapItem || {};
|
|
1256
|
+
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
1257
|
+
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
1258
|
+
const inputs = fromPaths.map(
|
|
1259
|
+
(path) => getFieldSettingsByPath(componentRootData.props || {}, path)
|
|
1260
|
+
);
|
|
1261
|
+
const runner = transform;
|
|
1262
|
+
const result = runner ? runner(inputs, componentRootData.props) : inputs[0];
|
|
1263
|
+
if (Array.isArray(result)) {
|
|
1264
|
+
result.forEach((val, idx) => {
|
|
1265
|
+
if (toPaths[idx]) setPropertyByPath(resolvedProps, toPaths[idx], val);
|
|
1266
|
+
});
|
|
1267
|
+
} else if (toPaths[0]) {
|
|
1268
|
+
setPropertyByPath(resolvedProps, toPaths[0], result);
|
|
1198
1269
|
}
|
|
1199
1270
|
});
|
|
1200
1271
|
softSubComponent.enabledSlots.forEach(({ slot, name }) => {
|
|
1201
|
-
var
|
|
1202
|
-
const referenceName = name || `${(
|
|
1272
|
+
var _a2, _b;
|
|
1273
|
+
const referenceName = name || `${(_a2 = softSubComponent.fixedProps) == null ? void 0 : _a2.id}-${slot}`;
|
|
1203
1274
|
resolvedProps[slot] = ((_b = componentRootData.props) == null ? void 0 : _b[referenceName]) || [];
|
|
1204
1275
|
});
|
|
1205
1276
|
Object.entries(softSubComponent.components).forEach(
|
|
@@ -1559,6 +1630,52 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1559
1630
|
});
|
|
1560
1631
|
|
|
1561
1632
|
// src/puck/lib/build-initial-soft-components.ts
|
|
1633
|
+
function hydrateSubComponentsTransforms(subComponents, hydrator, context) {
|
|
1634
|
+
return subComponents.map((subComponent, idx) => {
|
|
1635
|
+
var _a;
|
|
1636
|
+
const path = [...context.subComponentPath, `${subComponent.type}:${idx}`];
|
|
1637
|
+
const mapped = (_a = subComponent.map) == null ? void 0 : _a.map((mapItem) => {
|
|
1638
|
+
if (mapItem == null ? void 0 : mapItem.transform) return mapItem;
|
|
1639
|
+
const transform = hydrator(mapItem, __spreadProps(__spreadValues({}, context), {
|
|
1640
|
+
subComponentPath: path
|
|
1641
|
+
}));
|
|
1642
|
+
return transform ? __spreadProps(__spreadValues({}, mapItem), { transform }) : mapItem;
|
|
1643
|
+
});
|
|
1644
|
+
const nestedComponents = Object.fromEntries(
|
|
1645
|
+
Object.entries(subComponent.components || {}).map(([slotKey, children]) => [
|
|
1646
|
+
slotKey,
|
|
1647
|
+
hydrateSubComponentsTransforms(children, hydrator, __spreadProps(__spreadValues({}, context), {
|
|
1648
|
+
subComponentPath: [...path, slotKey]
|
|
1649
|
+
}))
|
|
1650
|
+
])
|
|
1651
|
+
);
|
|
1652
|
+
return __spreadProps(__spreadValues({}, subComponent), {
|
|
1653
|
+
map: mapped,
|
|
1654
|
+
components: nestedComponents
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
function hydrateSoftComponentsTransforms(softComponents, hydrator) {
|
|
1659
|
+
const hydrated = {};
|
|
1660
|
+
Object.entries(softComponents || {}).forEach(([name, comp]) => {
|
|
1661
|
+
const versions = {};
|
|
1662
|
+
Object.entries(comp.versions || {}).forEach(([version, softComponent]) => {
|
|
1663
|
+
versions[version] = __spreadProps(__spreadValues({}, softComponent), {
|
|
1664
|
+
components: hydrateSubComponentsTransforms(softComponent.components, hydrator, {
|
|
1665
|
+
componentName: name,
|
|
1666
|
+
version,
|
|
1667
|
+
subComponentPath: [],
|
|
1668
|
+
softComponent
|
|
1669
|
+
})
|
|
1670
|
+
});
|
|
1671
|
+
});
|
|
1672
|
+
hydrated[name] = {
|
|
1673
|
+
defaultVersion: comp.defaultVersion,
|
|
1674
|
+
versions
|
|
1675
|
+
};
|
|
1676
|
+
});
|
|
1677
|
+
return hydrated;
|
|
1678
|
+
}
|
|
1562
1679
|
function extractDependencies(softComponents, componentName, version) {
|
|
1563
1680
|
var _a, _b;
|
|
1564
1681
|
const dependencies = /* @__PURE__ */ new Set();
|
|
@@ -1625,15 +1742,16 @@ function topologicalSort(softComponents, hardComponentNames) {
|
|
|
1625
1742
|
}
|
|
1626
1743
|
return sorted;
|
|
1627
1744
|
}
|
|
1628
|
-
function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
1745
|
+
function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
1629
1746
|
var _a, _b;
|
|
1630
1747
|
if (!softComponents || Object.keys(softComponents).length === 0) {
|
|
1631
1748
|
return {};
|
|
1632
1749
|
}
|
|
1750
|
+
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(softComponents, overrides.hydrateMapTransform) : softComponents;
|
|
1633
1751
|
const hardComponentNames = new Set(Object.keys(hardConfig.components || {}));
|
|
1634
1752
|
try {
|
|
1635
1753
|
const sortedComponentNames = topologicalSort(
|
|
1636
|
-
|
|
1754
|
+
hydratedSoftComponents,
|
|
1637
1755
|
hardComponentNames
|
|
1638
1756
|
);
|
|
1639
1757
|
const buildingConfig = __spreadProps(__spreadValues({}, hardConfig), {
|
|
@@ -1641,7 +1759,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1641
1759
|
});
|
|
1642
1760
|
const componentConfigs = {};
|
|
1643
1761
|
for (const name of sortedComponentNames) {
|
|
1644
|
-
const comp =
|
|
1762
|
+
const comp = hydratedSoftComponents[name];
|
|
1645
1763
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1646
1764
|
const versionedComponent = (_a = comp.versions) == null ? void 0 : _a[defaultVersion || ""];
|
|
1647
1765
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1657,7 +1775,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1657
1775
|
allVersions,
|
|
1658
1776
|
buildingConfig,
|
|
1659
1777
|
// Pass the accumulating config
|
|
1660
|
-
|
|
1778
|
+
hydratedSoftComponents,
|
|
1661
1779
|
versionedComponent.defaultProps
|
|
1662
1780
|
);
|
|
1663
1781
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1668,7 +1786,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1668
1786
|
console.error("Error building soft components:", error);
|
|
1669
1787
|
console.warn("Falling back to unordered component building");
|
|
1670
1788
|
const componentConfigs = {};
|
|
1671
|
-
for (const [name, comp] of Object.entries(
|
|
1789
|
+
for (const [name, comp] of Object.entries(hydratedSoftComponents)) {
|
|
1672
1790
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1673
1791
|
const versionedComponent = (_b = comp.versions) == null ? void 0 : _b[defaultVersion || ""];
|
|
1674
1792
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1683,7 +1801,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1683
1801
|
defaultVersion || "1.0.0",
|
|
1684
1802
|
allVersions,
|
|
1685
1803
|
hardConfig,
|
|
1686
|
-
|
|
1804
|
+
hydratedSoftComponents,
|
|
1687
1805
|
versionedComponent.defaultProps
|
|
1688
1806
|
);
|
|
1689
1807
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1695,158 +1813,169 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1695
1813
|
// src/puck/store/index.tsx
|
|
1696
1814
|
var createSoftConfigStore = (hardConfig = {
|
|
1697
1815
|
components: {}
|
|
1698
|
-
}, softComponents = {}, overrides = {}) =>
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
name
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
get().softConfig,
|
|
1745
|
-
get().softComponents,
|
|
1746
|
-
softComponent.defaultProps
|
|
1747
|
-
);
|
|
1748
|
-
set((state) => ({
|
|
1749
|
-
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1750
|
-
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1751
|
-
[name]: newSoftComponentConfig
|
|
1752
|
-
})
|
|
1753
|
-
}),
|
|
1754
|
-
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1755
|
-
[name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
|
|
1756
|
-
defaultVersion: version
|
|
1757
|
-
})
|
|
1758
|
-
})
|
|
1759
|
-
}));
|
|
1760
|
-
},
|
|
1761
|
-
removeSoftComponentVersion: (key, version) => {
|
|
1762
|
-
set((state) => {
|
|
1763
|
-
const component = state.softComponents[key];
|
|
1764
|
-
if (!component) return {};
|
|
1765
|
-
const newVersions = Object.fromEntries(
|
|
1766
|
-
Object.entries(component.versions || {}).filter(
|
|
1767
|
-
([k, _]) => k !== version
|
|
1768
|
-
)
|
|
1816
|
+
}, softComponents = {}, overrides = {}) => {
|
|
1817
|
+
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
|
|
1818
|
+
softComponents,
|
|
1819
|
+
overrides.hydrateMapTransform
|
|
1820
|
+
) : softComponents;
|
|
1821
|
+
return create()(
|
|
1822
|
+
subscribeWithSelector(
|
|
1823
|
+
devtools((set, get) => ({
|
|
1824
|
+
state: "ready",
|
|
1825
|
+
originalHistory: [],
|
|
1826
|
+
overrides,
|
|
1827
|
+
storeHistory: (history) => set({ originalHistory: history }),
|
|
1828
|
+
removeHistory: () => set({ originalHistory: [] }),
|
|
1829
|
+
itemSelector: null,
|
|
1830
|
+
setItemSelector: (selector) => set({ itemSelector: selector }),
|
|
1831
|
+
originalItem: null,
|
|
1832
|
+
setOriginalItem: (item) => set({ originalItem: item }),
|
|
1833
|
+
hydratedSoftComponents,
|
|
1834
|
+
softComponents: hydratedSoftComponents,
|
|
1835
|
+
softConfig: __spreadProps(__spreadValues({}, hardConfig), {
|
|
1836
|
+
components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
|
|
1837
|
+
hardConfig,
|
|
1838
|
+
hydratedSoftComponents,
|
|
1839
|
+
overrides
|
|
1840
|
+
))
|
|
1841
|
+
}),
|
|
1842
|
+
setSoftComponent: (name, version, component) => {
|
|
1843
|
+
set((state) => {
|
|
1844
|
+
var _a;
|
|
1845
|
+
return {
|
|
1846
|
+
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1847
|
+
[name]: {
|
|
1848
|
+
defaultVersion: version,
|
|
1849
|
+
versions: __spreadProps(__spreadValues({}, ((_a = state.softComponents[name]) == null ? void 0 : _a.versions) || {}), {
|
|
1850
|
+
[version]: component
|
|
1851
|
+
})
|
|
1852
|
+
}
|
|
1853
|
+
})
|
|
1854
|
+
};
|
|
1855
|
+
});
|
|
1856
|
+
},
|
|
1857
|
+
setSoftComponentDefaultVersion: (name, version) => {
|
|
1858
|
+
var _a, _b, _c;
|
|
1859
|
+
const softComponent = (_b = (_a = get().softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
|
|
1860
|
+
const allVersions = Object.keys(
|
|
1861
|
+
((_c = get().softComponents[name]) == null ? void 0 : _c.versions) || {}
|
|
1769
1862
|
);
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1863
|
+
if (!softComponent) {
|
|
1864
|
+
throw new Error(
|
|
1865
|
+
`Soft component "${name}" version "${version}" does not exist.`
|
|
1866
|
+
);
|
|
1774
1867
|
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
},
|
|
1785
|
-
removeSoftComponent: (key) => {
|
|
1786
|
-
set((state) => ({
|
|
1787
|
-
softComponents: Object.fromEntries(
|
|
1788
|
-
Object.entries(state.softComponents).filter(([k, _]) => k !== key)
|
|
1789
|
-
)
|
|
1790
|
-
}));
|
|
1791
|
-
},
|
|
1792
|
-
setSoftComponentConfig: (key, config, category) => {
|
|
1793
|
-
set((state) => {
|
|
1794
|
-
var _a;
|
|
1795
|
-
return {
|
|
1868
|
+
const newSoftComponentConfig = createVersionedComponentConfig(
|
|
1869
|
+
name,
|
|
1870
|
+
version,
|
|
1871
|
+
allVersions,
|
|
1872
|
+
get().softConfig,
|
|
1873
|
+
get().softComponents,
|
|
1874
|
+
softComponent.defaultProps
|
|
1875
|
+
);
|
|
1876
|
+
set((state) => ({
|
|
1796
1877
|
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1797
1878
|
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1798
|
-
[
|
|
1799
|
-
})
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
]
|
|
1806
|
-
})
|
|
1807
|
-
}) : state.softConfig.categories
|
|
1879
|
+
[name]: newSoftComponentConfig
|
|
1880
|
+
})
|
|
1881
|
+
}),
|
|
1882
|
+
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1883
|
+
[name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
|
|
1884
|
+
defaultVersion: version
|
|
1885
|
+
})
|
|
1808
1886
|
})
|
|
1809
|
-
};
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
Object.entries(
|
|
1817
|
-
([k, _]) => k !==
|
|
1887
|
+
}));
|
|
1888
|
+
},
|
|
1889
|
+
removeSoftComponentVersion: (key, version) => {
|
|
1890
|
+
set((state) => {
|
|
1891
|
+
const component = state.softComponents[key];
|
|
1892
|
+
if (!component) return {};
|
|
1893
|
+
const newVersions = Object.fromEntries(
|
|
1894
|
+
Object.entries(component.versions || {}).filter(
|
|
1895
|
+
([k, _]) => k !== version
|
|
1818
1896
|
)
|
|
1897
|
+
);
|
|
1898
|
+
let newDefaultVersion = component.defaultVersion;
|
|
1899
|
+
if (component.defaultVersion === version) {
|
|
1900
|
+
const versionKeys = Object.keys(newVersions);
|
|
1901
|
+
newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
|
|
1902
|
+
}
|
|
1903
|
+
return {
|
|
1904
|
+
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1905
|
+
[key]: __spreadProps(__spreadValues({}, component), {
|
|
1906
|
+
versions: newVersions,
|
|
1907
|
+
defaultVersion: newDefaultVersion
|
|
1908
|
+
})
|
|
1909
|
+
})
|
|
1910
|
+
};
|
|
1911
|
+
});
|
|
1912
|
+
},
|
|
1913
|
+
removeSoftComponent: (key) => {
|
|
1914
|
+
set((state) => ({
|
|
1915
|
+
softComponents: Object.fromEntries(
|
|
1916
|
+
Object.entries(state.softComponents).filter(([k, _]) => k !== key)
|
|
1819
1917
|
)
|
|
1820
|
-
})
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1918
|
+
}));
|
|
1919
|
+
},
|
|
1920
|
+
setSoftComponentConfig: (key, config, category) => {
|
|
1921
|
+
set((state) => {
|
|
1922
|
+
var _a;
|
|
1923
|
+
return {
|
|
1924
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1925
|
+
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1926
|
+
[key]: __spreadValues({}, config)
|
|
1927
|
+
}),
|
|
1928
|
+
categories: category && state.softConfig.categories ? __spreadProps(__spreadValues({}, state.softConfig.categories), {
|
|
1929
|
+
[category]: __spreadProps(__spreadValues({}, state.softConfig.categories[category]), {
|
|
1930
|
+
components: [
|
|
1931
|
+
...((_a = state.softConfig.categories[category]) == null ? void 0 : _a.components) || [],
|
|
1932
|
+
key
|
|
1933
|
+
]
|
|
1934
|
+
})
|
|
1935
|
+
}) : state.softConfig.categories
|
|
1830
1936
|
})
|
|
1937
|
+
};
|
|
1938
|
+
});
|
|
1939
|
+
},
|
|
1940
|
+
removeSoftComponentConfig: (key) => {
|
|
1941
|
+
set((state) => ({
|
|
1942
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1943
|
+
components: Object.fromEntries(
|
|
1944
|
+
Object.entries(state.softConfig.components).filter(
|
|
1945
|
+
([k, _]) => k !== key
|
|
1946
|
+
)
|
|
1947
|
+
)
|
|
1831
1948
|
})
|
|
1832
|
-
};
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1949
|
+
}));
|
|
1950
|
+
},
|
|
1951
|
+
setSoftCategoryConfig: (key, category) => {
|
|
1952
|
+
set((state) => {
|
|
1953
|
+
var _a;
|
|
1954
|
+
return {
|
|
1955
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1956
|
+
categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
|
|
1957
|
+
[key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
|
|
1958
|
+
})
|
|
1959
|
+
})
|
|
1960
|
+
};
|
|
1961
|
+
});
|
|
1962
|
+
},
|
|
1963
|
+
removeSoftCategoryConfig: (key) => {
|
|
1964
|
+
set((state) => ({
|
|
1965
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1966
|
+
categories: Object.fromEntries(
|
|
1967
|
+
Object.entries(state.softConfig.categories || {}).filter(
|
|
1968
|
+
([k, _]) => k !== key
|
|
1969
|
+
)
|
|
1841
1970
|
)
|
|
1842
|
-
)
|
|
1843
|
-
})
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
)
|
|
1849
|
-
|
|
1971
|
+
})
|
|
1972
|
+
}));
|
|
1973
|
+
},
|
|
1974
|
+
builder: createBuildersSlice(set, get, hardConfig)
|
|
1975
|
+
}))
|
|
1976
|
+
)
|
|
1977
|
+
);
|
|
1978
|
+
};
|
|
1850
1979
|
|
|
1851
1980
|
// src/puck/context/storeProvider.tsx
|
|
1852
1981
|
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|