@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.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 = {
|
|
@@ -883,6 +913,10 @@ var softComponentFromAppState = (appState, configComponents) => {
|
|
|
883
913
|
];
|
|
884
914
|
};
|
|
885
915
|
|
|
916
|
+
// src/puck/lib/generate-id.ts
|
|
917
|
+
import { v4 as uuidv4 } from "uuid";
|
|
918
|
+
var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
|
|
919
|
+
|
|
886
920
|
// src/puck/lib/soft-component-to-appstate.ts
|
|
887
921
|
var puckFieldsToSoftFields = (fields, slots) => {
|
|
888
922
|
const softFields = [];
|
|
@@ -949,11 +983,27 @@ var puckFieldsToSoftFields = (fields, slots) => {
|
|
|
949
983
|
};
|
|
950
984
|
var reconstructComponents = (subComponents, componentConfigs, softComponentProps) => {
|
|
951
985
|
return subComponents.map((subComponent) => {
|
|
952
|
-
|
|
986
|
+
var _a;
|
|
953
987
|
const props = __spreadValues({}, subComponent.fixedProps);
|
|
954
|
-
subComponent.map.forEach((
|
|
955
|
-
|
|
956
|
-
|
|
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;
|
|
957
1007
|
}
|
|
958
1008
|
});
|
|
959
1009
|
if (subComponent.enabledSlots.length > 0) {
|
|
@@ -979,7 +1029,7 @@ var reconstructComponents = (subComponents, componentConfigs, softComponentProps
|
|
|
979
1029
|
const componentData = {
|
|
980
1030
|
type: subComponent.type,
|
|
981
1031
|
props: __spreadValues({
|
|
982
|
-
id: props.id ||
|
|
1032
|
+
id: props.id || generateId(subComponent.type)
|
|
983
1033
|
}, props)
|
|
984
1034
|
};
|
|
985
1035
|
return componentData;
|
|
@@ -1025,7 +1075,7 @@ var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
|
1025
1075
|
|
|
1026
1076
|
// src/puck/components/soft-render/index.tsx
|
|
1027
1077
|
import { useMemo, useRef } from "react";
|
|
1028
|
-
import { v4 as
|
|
1078
|
+
import { v4 as uuidv42 } from "uuid";
|
|
1029
1079
|
import { Fragment as Fragment2, jsx as jsx5 } from "react/jsx-runtime";
|
|
1030
1080
|
function SoftRender({
|
|
1031
1081
|
softComponentFields,
|
|
@@ -1063,14 +1113,17 @@ function SoftRender({
|
|
|
1063
1113
|
if (!componentConfig) return null;
|
|
1064
1114
|
const resolvedProps = subComponent.fixedProps || {};
|
|
1065
1115
|
const stableId = useMemo(
|
|
1066
|
-
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${
|
|
1116
|
+
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-${uuidv42()}`,
|
|
1067
1117
|
[id, depth, subComponent.type]
|
|
1068
1118
|
);
|
|
1069
1119
|
if ((_a2 = subComponent.map) == null ? void 0 : _a2.length) {
|
|
1070
|
-
subComponent.map.forEach((
|
|
1120
|
+
subComponent.map.forEach((mapItem) => {
|
|
1121
|
+
const { from, to, transform } = mapItem || {};
|
|
1071
1122
|
const fromPaths = Array.isArray(from) ? from : from ? [from] : [];
|
|
1072
1123
|
const toPaths = Array.isArray(to) ? to : to ? [to] : [];
|
|
1073
1124
|
const inputValues = fromPaths.map((f) => {
|
|
1125
|
+
const propValue = getFieldSettingsByPath(props || {}, f);
|
|
1126
|
+
if (propValue !== void 0) return propValue;
|
|
1074
1127
|
const setting = getFieldSettingsByPath(
|
|
1075
1128
|
softComponentFieldSettings || {},
|
|
1076
1129
|
f
|
|
@@ -1078,12 +1131,13 @@ function SoftRender({
|
|
|
1078
1131
|
if (setting && Object.prototype.hasOwnProperty.call(setting, "defaultValue")) {
|
|
1079
1132
|
return setting.defaultValue;
|
|
1080
1133
|
}
|
|
1081
|
-
return
|
|
1134
|
+
return propValue;
|
|
1082
1135
|
});
|
|
1083
1136
|
const cacheKey = JSON.stringify(inputValues);
|
|
1084
1137
|
let result = mapCacheRef.current.get(cacheKey);
|
|
1085
1138
|
if (!result) {
|
|
1086
|
-
|
|
1139
|
+
const runner = transform;
|
|
1140
|
+
result = runner ? runner(inputValues, props) : inputValues[0];
|
|
1087
1141
|
mapCacheRef.current.set(cacheKey, result);
|
|
1088
1142
|
}
|
|
1089
1143
|
if (Array.isArray(result)) {
|
|
@@ -1193,23 +1247,30 @@ var createVersionedComponentConfig = (componentName, version, allVersions, confi
|
|
|
1193
1247
|
};
|
|
1194
1248
|
};
|
|
1195
1249
|
|
|
1196
|
-
// src/puck/lib/generate-id.ts
|
|
1197
|
-
import { v4 as uuidv42 } from "uuid";
|
|
1198
|
-
var generateId = (type) => type ? `${type}-${uuidv42()}` : uuidv42();
|
|
1199
|
-
|
|
1200
1250
|
// src/puck/lib/builder/sub-component-decomposer.tsx
|
|
1201
1251
|
var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
1252
|
+
var _a;
|
|
1202
1253
|
const resolvedProps = __spreadValues({}, softSubComponent.fixedProps);
|
|
1203
|
-
softSubComponent.map.forEach((mapItem) => {
|
|
1204
|
-
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
|
|
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);
|
|
1208
1269
|
}
|
|
1209
1270
|
});
|
|
1210
1271
|
softSubComponent.enabledSlots.forEach(({ slot, name }) => {
|
|
1211
|
-
var
|
|
1212
|
-
const referenceName = name || `${(
|
|
1272
|
+
var _a2, _b;
|
|
1273
|
+
const referenceName = name || `${(_a2 = softSubComponent.fixedProps) == null ? void 0 : _a2.id}-${slot}`;
|
|
1213
1274
|
resolvedProps[slot] = ((_b = componentRootData.props) == null ? void 0 : _b[referenceName]) || [];
|
|
1214
1275
|
});
|
|
1215
1276
|
Object.entries(softSubComponent.components).forEach(
|
|
@@ -1569,6 +1630,52 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1569
1630
|
});
|
|
1570
1631
|
|
|
1571
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
|
+
}
|
|
1572
1679
|
function extractDependencies(softComponents, componentName, version) {
|
|
1573
1680
|
var _a, _b;
|
|
1574
1681
|
const dependencies = /* @__PURE__ */ new Set();
|
|
@@ -1635,15 +1742,16 @@ function topologicalSort(softComponents, hardComponentNames) {
|
|
|
1635
1742
|
}
|
|
1636
1743
|
return sorted;
|
|
1637
1744
|
}
|
|
1638
|
-
function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
1745
|
+
function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
1639
1746
|
var _a, _b;
|
|
1640
1747
|
if (!softComponents || Object.keys(softComponents).length === 0) {
|
|
1641
1748
|
return {};
|
|
1642
1749
|
}
|
|
1750
|
+
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(softComponents, overrides.hydrateMapTransform) : softComponents;
|
|
1643
1751
|
const hardComponentNames = new Set(Object.keys(hardConfig.components || {}));
|
|
1644
1752
|
try {
|
|
1645
1753
|
const sortedComponentNames = topologicalSort(
|
|
1646
|
-
|
|
1754
|
+
hydratedSoftComponents,
|
|
1647
1755
|
hardComponentNames
|
|
1648
1756
|
);
|
|
1649
1757
|
const buildingConfig = __spreadProps(__spreadValues({}, hardConfig), {
|
|
@@ -1651,7 +1759,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1651
1759
|
});
|
|
1652
1760
|
const componentConfigs = {};
|
|
1653
1761
|
for (const name of sortedComponentNames) {
|
|
1654
|
-
const comp =
|
|
1762
|
+
const comp = hydratedSoftComponents[name];
|
|
1655
1763
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1656
1764
|
const versionedComponent = (_a = comp.versions) == null ? void 0 : _a[defaultVersion || ""];
|
|
1657
1765
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1667,7 +1775,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1667
1775
|
allVersions,
|
|
1668
1776
|
buildingConfig,
|
|
1669
1777
|
// Pass the accumulating config
|
|
1670
|
-
|
|
1778
|
+
hydratedSoftComponents,
|
|
1671
1779
|
versionedComponent.defaultProps
|
|
1672
1780
|
);
|
|
1673
1781
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1678,7 +1786,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1678
1786
|
console.error("Error building soft components:", error);
|
|
1679
1787
|
console.warn("Falling back to unordered component building");
|
|
1680
1788
|
const componentConfigs = {};
|
|
1681
|
-
for (const [name, comp] of Object.entries(
|
|
1789
|
+
for (const [name, comp] of Object.entries(hydratedSoftComponents)) {
|
|
1682
1790
|
const defaultVersion = comp.defaultVersion || Object.keys(comp.versions || {}).pop();
|
|
1683
1791
|
const versionedComponent = (_b = comp.versions) == null ? void 0 : _b[defaultVersion || ""];
|
|
1684
1792
|
const allVersions = Object.keys(comp.versions || {});
|
|
@@ -1693,7 +1801,7 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1693
1801
|
defaultVersion || "1.0.0",
|
|
1694
1802
|
allVersions,
|
|
1695
1803
|
hardConfig,
|
|
1696
|
-
|
|
1804
|
+
hydratedSoftComponents,
|
|
1697
1805
|
versionedComponent.defaultProps
|
|
1698
1806
|
);
|
|
1699
1807
|
componentConfigs[name] = newSoftComponentConfig;
|
|
@@ -1705,158 +1813,169 @@ function buildInitialSoftComponents(hardConfig, softComponents) {
|
|
|
1705
1813
|
// src/puck/store/index.tsx
|
|
1706
1814
|
var createSoftConfigStore = (hardConfig = {
|
|
1707
1815
|
components: {}
|
|
1708
|
-
}, softComponents = {}, overrides = {}) =>
|
|
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
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
name
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
get().softConfig,
|
|
1755
|
-
get().softComponents,
|
|
1756
|
-
softComponent.defaultProps
|
|
1757
|
-
);
|
|
1758
|
-
set((state) => ({
|
|
1759
|
-
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1760
|
-
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1761
|
-
[name]: newSoftComponentConfig
|
|
1762
|
-
})
|
|
1763
|
-
}),
|
|
1764
|
-
softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
|
|
1765
|
-
[name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
|
|
1766
|
-
defaultVersion: version
|
|
1767
|
-
})
|
|
1768
|
-
})
|
|
1769
|
-
}));
|
|
1770
|
-
},
|
|
1771
|
-
removeSoftComponentVersion: (key, version) => {
|
|
1772
|
-
set((state) => {
|
|
1773
|
-
const component = state.softComponents[key];
|
|
1774
|
-
if (!component) return {};
|
|
1775
|
-
const newVersions = Object.fromEntries(
|
|
1776
|
-
Object.entries(component.versions || {}).filter(
|
|
1777
|
-
([k, _]) => k !== version
|
|
1778
|
-
)
|
|
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) || {}
|
|
1779
1862
|
);
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1863
|
+
if (!softComponent) {
|
|
1864
|
+
throw new Error(
|
|
1865
|
+
`Soft component "${name}" version "${version}" does not exist.`
|
|
1866
|
+
);
|
|
1784
1867
|
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
},
|
|
1795
|
-
removeSoftComponent: (key) => {
|
|
1796
|
-
set((state) => ({
|
|
1797
|
-
softComponents: Object.fromEntries(
|
|
1798
|
-
Object.entries(state.softComponents).filter(([k, _]) => k !== key)
|
|
1799
|
-
)
|
|
1800
|
-
}));
|
|
1801
|
-
},
|
|
1802
|
-
setSoftComponentConfig: (key, config, category) => {
|
|
1803
|
-
set((state) => {
|
|
1804
|
-
var _a;
|
|
1805
|
-
return {
|
|
1868
|
+
const newSoftComponentConfig = createVersionedComponentConfig(
|
|
1869
|
+
name,
|
|
1870
|
+
version,
|
|
1871
|
+
allVersions,
|
|
1872
|
+
get().softConfig,
|
|
1873
|
+
get().softComponents,
|
|
1874
|
+
softComponent.defaultProps
|
|
1875
|
+
);
|
|
1876
|
+
set((state) => ({
|
|
1806
1877
|
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
1807
1878
|
components: __spreadProps(__spreadValues({}, state.softConfig.components), {
|
|
1808
|
-
[
|
|
1809
|
-
})
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
]
|
|
1816
|
-
})
|
|
1817
|
-
}) : 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
|
+
})
|
|
1818
1886
|
})
|
|
1819
|
-
};
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
Object.entries(
|
|
1827
|
-
([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
|
|
1828
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)
|
|
1829
1917
|
)
|
|
1830
|
-
})
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
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
|
|
1840
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
|
+
)
|
|
1841
1948
|
})
|
|
1842
|
-
};
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
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
|
+
)
|
|
1851
1970
|
)
|
|
1852
|
-
)
|
|
1853
|
-
})
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
)
|
|
1859
|
-
|
|
1971
|
+
})
|
|
1972
|
+
}));
|
|
1973
|
+
},
|
|
1974
|
+
builder: createBuildersSlice(set, get, hardConfig)
|
|
1975
|
+
}))
|
|
1976
|
+
)
|
|
1977
|
+
);
|
|
1978
|
+
};
|
|
1860
1979
|
|
|
1861
1980
|
// src/puck/context/storeProvider.tsx
|
|
1862
1981
|
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|