@netlisian/softconfig 0.1.2 → 0.1.3

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.
@@ -372,7 +372,7 @@ var builderRootConfig = (config, overrides, editingComponent, showVersionFields
372
372
  )
373
373
  };
374
374
  else delete fields._fieldSettings;
375
- if (showVersionFields && ((_b = data == null ? void 0 : data._versions) == null ? void 0 : _b.length) && (!(data == null ? void 0 : data._version) || changed._version || changed._fieldSettings)) {
375
+ if (showVersionFields && ((_b = data == null ? void 0 : data._versions) == null ? void 0 : _b.length)) {
376
376
  const latestVersion = data._versions[data._versions.length - 1] || "1.0.0";
377
377
  delete fields._version;
378
378
  fields._version = {
@@ -1557,7 +1557,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
1557
1557
  );
1558
1558
  },
1559
1559
  complete: (appState, setHistories, getItemBySelector) => {
1560
- var _a, _b, _c, _d, _e;
1560
+ var _a, _b, _c, _d, _e, _f;
1561
1561
  if (get().state === "ready") {
1562
1562
  throw new Error("Not building or remodeling a component.");
1563
1563
  }
@@ -1642,8 +1642,21 @@ var createBuildersSlice = (set, get, initialConfig) => ({
1642
1642
  editableComponentIds: /* @__PURE__ */ new Set()
1643
1643
  });
1644
1644
  });
1645
+ if (!version) {
1646
+ throw new Error("Failed to resolve completed component version.");
1647
+ }
1648
+ const completedSoftComponent = (_f = get().softComponents[componentName]) == null ? void 0 : _f.versions[version];
1649
+ if (!completedSoftComponent) {
1650
+ throw new Error(
1651
+ `Completed soft component "${componentName}" version "${version}" not found.`
1652
+ );
1653
+ }
1645
1654
  get().rebuildDependents(componentName, version);
1646
- return componentName;
1655
+ return {
1656
+ id: componentName,
1657
+ version,
1658
+ softComponent: completedSoftComponent
1659
+ };
1647
1660
  },
1648
1661
  inspect: (componentName, puckDispatch) => {
1649
1662
  if (get().state !== "inspecting") {
@@ -2573,28 +2586,42 @@ var useRemodel = () => {
2573
2586
  const refreshPermissions = useCustomPuck3((s) => s.refreshPermissions);
2574
2587
  const { triggerAction } = useActionEvent();
2575
2588
  const handleRemodel = (componentName) => {
2589
+ var _a, _b, _c;
2576
2590
  if (status !== "ready") {
2577
2591
  notify.error("Can only remodel when in ready state.");
2578
- return;
2592
+ return null;
2579
2593
  }
2580
2594
  const name = componentName || (selectedItem == null ? void 0 : selectedItem.type);
2581
2595
  if (!name || !Object.keys(softComponents).includes(name)) {
2582
2596
  notify.error("Selected component is not a soft component.");
2583
- return;
2597
+ return null;
2584
2598
  }
2599
+ const selectedVersion = ((_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.version) || ((_b = softComponents[name]) == null ? void 0 : _b.defaultVersion);
2600
+ const selectedSoftComponent = selectedVersion ? (_c = softComponents[name]) == null ? void 0 : _c.versions[selectedVersion] : void 0;
2585
2601
  try {
2586
2602
  remodel(history, selectedItem, itemSelector, dispatch, refreshPermissions);
2587
2603
  void triggerAction({
2588
2604
  type: "remodel",
2589
2605
  payload: {
2590
- id: name
2606
+ id: name,
2607
+ version: selectedVersion,
2608
+ softComponent: selectedSoftComponent
2591
2609
  }
2592
2610
  });
2611
+ if (selectedVersion && selectedSoftComponent) {
2612
+ return {
2613
+ id: name,
2614
+ version: selectedVersion,
2615
+ softComponent: selectedSoftComponent
2616
+ };
2617
+ }
2618
+ return { id: name, version: selectedVersion };
2593
2619
  } catch (error) {
2594
2620
  console.error("Failed to remodel:", error);
2595
2621
  notify.error(
2596
2622
  "Failed to remodel: " + (error instanceof Error ? error.message : String(error))
2597
2623
  );
2624
+ return null;
2598
2625
  }
2599
2626
  };
2600
2627
  const canRemodel = (componentName) => {
@@ -2614,31 +2641,29 @@ var useComplete = () => {
2614
2641
  const setHistories = useCustomPuck4((s) => s.history.setHistories);
2615
2642
  const getItemBySelector = useCustomPuck4((s) => s.getItemBySelector);
2616
2643
  const status = useSoftConfig((s) => s.state);
2617
- const softComponents = useSoftConfig((s) => s.softComponents);
2618
2644
  const [newComponent, setNewComponent] = useState3(null);
2619
2645
  const { triggerAction } = useActionEvent();
2620
2646
  const handleComplete = useCallback2(() => {
2621
- var _a, _b;
2622
2647
  if (status === "ready") {
2623
2648
  notify.error("Not building or remodeling a component.");
2624
2649
  return null;
2625
2650
  }
2626
2651
  try {
2627
- const componentName = complete(appState, setHistories, getItemBySelector);
2628
- setNewComponent(componentName);
2652
+ const completedComponent = complete(appState, setHistories, getItemBySelector);
2653
+ setNewComponent(completedComponent);
2629
2654
  const componentData = appState.data.root;
2630
- const softComponent = (_b = softComponents[componentName]) == null ? void 0 : _b.versions[(_a = softComponents[componentName]) == null ? void 0 : _a.defaultVersion];
2631
- if (softComponent && componentData) {
2655
+ if (componentData) {
2632
2656
  void triggerAction({
2633
2657
  type: "complete",
2634
2658
  payload: {
2635
- id: componentName,
2659
+ id: completedComponent.id,
2660
+ version: completedComponent.version,
2636
2661
  componentData,
2637
- softComponent
2662
+ softComponent: completedComponent.softComponent
2638
2663
  }
2639
2664
  });
2640
2665
  }
2641
- return componentName;
2666
+ return completedComponent;
2642
2667
  } catch (error) {
2643
2668
  console.error("Failed to complete:", error);
2644
2669
  notify.error(
@@ -2646,7 +2671,7 @@ var useComplete = () => {
2646
2671
  );
2647
2672
  return null;
2648
2673
  }
2649
- }, [complete, appState, setHistories, status, softComponents, triggerAction, getItemBySelector]);
2674
+ }, [complete, appState, setHistories, status, triggerAction, getItemBySelector]);
2650
2675
  const canComplete = status === "building" || status === "remodeling";
2651
2676
  return { handleComplete, canComplete, newComponent, setNewComponent };
2652
2677
  };
@@ -2685,23 +2710,25 @@ var useCancel = () => {
2685
2710
  import { createUsePuck as createUsePuck6 } from "@measured/puck";
2686
2711
  import { useEffect as useEffect3 } from "react";
2687
2712
  var useCustomPuck6 = createUsePuck6();
2688
- var useInspect = (componentName) => {
2713
+ var useInspect = (component) => {
2689
2714
  const inspect = useSoftConfig((s) => s.builder.inspect);
2690
2715
  const dispatch = useCustomPuck6((s) => s.dispatch);
2691
2716
  const status = useSoftConfig((s) => s.state);
2692
2717
  const { triggerAction } = useActionEvent();
2693
2718
  useEffect3(() => {
2694
2719
  if (status !== "inspecting") return;
2695
- if (!componentName) {
2720
+ if (!component) {
2696
2721
  notify.error("No component to inspect.");
2697
2722
  return;
2698
2723
  }
2699
2724
  try {
2700
- inspect(componentName, dispatch);
2725
+ inspect(component.id, dispatch);
2701
2726
  void triggerAction({
2702
2727
  type: "inspect",
2703
2728
  payload: {
2704
- id: componentName
2729
+ id: component.id,
2730
+ version: component.version,
2731
+ softComponent: component.softComponent
2705
2732
  }
2706
2733
  });
2707
2734
  } catch (error) {
@@ -2710,7 +2737,7 @@ var useInspect = (componentName) => {
2710
2737
  "Failed to inspect: " + (error instanceof Error ? error.message : String(error))
2711
2738
  );
2712
2739
  }
2713
- }, [status, componentName, inspect, dispatch, triggerAction]);
2740
+ }, [status, component, inspect, dispatch, triggerAction]);
2714
2741
  };
2715
2742
 
2716
2743
  // src/puck/actions/useDecompose.tsx
@@ -2926,9 +2953,9 @@ var Header = ({
2926
2953
  {
2927
2954
  variant: "primary",
2928
2955
  onClick: () => {
2929
- const name = handleComplete();
2930
- if (name) {
2931
- setNewComponent(name);
2956
+ const completedComponent = handleComplete();
2957
+ if (completedComponent) {
2958
+ setNewComponent(completedComponent);
2932
2959
  }
2933
2960
  },
2934
2961
  children: "Complete"
@@ -3043,14 +3070,14 @@ var confirm = (message) => __async(null, null, function* () {
3043
3070
  });
3044
3071
 
3045
3072
  // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/DrawerItem.module.css#css-module
3046
- var DrawerItem_module_default = { "DrawerItem": "_DrawerItem_29z19_1", "DrawerItem--insertDisabled": "_DrawerItem--insertDisabled_29z19_14", "DrawerItem-content": "_DrawerItem-content_29z19_21", "DrawerItem-name": "_DrawerItem-name_29z19_31", "DrawerItem-version": "_DrawerItem-version_29z19_35", "DrawerItem-actions": "_DrawerItem-actions_29z19_40", "DrawerItem-settingsButton": "_DrawerItem-settingsButton_29z19_46", "DrawerItem-grip": "_DrawerItem-grip_29z19_56", "DrawerItem-modal": "_DrawerItem-modal_29z19_63", "DrawerItem-modalHeader": "_DrawerItem-modalHeader_29z19_70", "DrawerItem-modalTitle": "_DrawerItem-modalTitle_29z19_75", "DrawerItem-modalSubtitle": "_DrawerItem-modalSubtitle_29z19_82", "DrawerItem-modalBody": "_DrawerItem-modalBody_29z19_88", "DrawerItem-section": "_DrawerItem-section_29z19_97", "DrawerItem-sectionTitle": "_DrawerItem-sectionTitle_29z19_103", "DrawerItem-sectionDescription": "_DrawerItem-sectionDescription_29z19_110", "DrawerItem-versionList": "_DrawerItem-versionList_29z19_116", "DrawerItem-versionRow": "_DrawerItem-versionRow_29z19_122", "DrawerItem-versionRow--isDefault": "_DrawerItem-versionRow--isDefault_29z19_133", "DrawerItem-versionRow--isMarkedForDeletion": "_DrawerItem-versionRow--isMarkedForDeletion_29z19_138", "DrawerItem-versionInfo": "_DrawerItem-versionInfo_29z19_143", "DrawerItem-versionNumber": "_DrawerItem-versionNumber_29z19_150", "DrawerItem-defaultBadge": "_DrawerItem-defaultBadge_29z19_156", "DrawerItem-deleteBadge": "_DrawerItem-deleteBadge_29z19_167", "DrawerItem-versionActions": "_DrawerItem-versionActions_29z19_178", "DrawerItem-migrationOptions": "_DrawerItem-migrationOptions_29z19_184", "DrawerItem-select": "_DrawerItem-select_29z19_188", "DrawerItem-modalFooter": "_DrawerItem-modalFooter_29z19_209", "DrawerItem-footerLeft": "_DrawerItem-footerLeft_29z19_218", "DrawerItem-footerRight": "_DrawerItem-footerRight_29z19_223" };
3073
+ var DrawerItem_module_default = { "DrawerItem": "_DrawerItem_182aj_1", "DrawerItem--insertDisabled": "_DrawerItem--insertDisabled_182aj_14", "DrawerItem-content": "_DrawerItem-content_182aj_21", "DrawerItem-name": "_DrawerItem-name_182aj_31", "DrawerItem-version": "_DrawerItem-version_182aj_35", "DrawerItem-actions": "_DrawerItem-actions_182aj_40", "DrawerItem-settingsButton": "_DrawerItem-settingsButton_182aj_46", "DrawerItem-grip": "_DrawerItem-grip_182aj_56", "DrawerItem-modal": "_DrawerItem-modal_182aj_63", "DrawerItem-modalHeader": "_DrawerItem-modalHeader_182aj_71", "DrawerItem-modalTitle": "_DrawerItem-modalTitle_182aj_77", "DrawerItem-modalSubtitle": "_DrawerItem-modalSubtitle_182aj_84", "DrawerItem-modalBody": "_DrawerItem-modalBody_182aj_90", "DrawerItem-section": "_DrawerItem-section_182aj_100", "DrawerItem-sectionTitle": "_DrawerItem-sectionTitle_182aj_106", "DrawerItem-sectionDescription": "_DrawerItem-sectionDescription_182aj_113", "DrawerItem-versionList": "_DrawerItem-versionList_182aj_119", "DrawerItem-versionRow": "_DrawerItem-versionRow_182aj_125", "DrawerItem-versionRow--isDefault": "_DrawerItem-versionRow--isDefault_182aj_136", "DrawerItem-versionRow--isMarkedForDeletion": "_DrawerItem-versionRow--isMarkedForDeletion_182aj_141", "DrawerItem-versionInfo": "_DrawerItem-versionInfo_182aj_146", "DrawerItem-versionNumber": "_DrawerItem-versionNumber_182aj_153", "DrawerItem-defaultBadge": "_DrawerItem-defaultBadge_182aj_159", "DrawerItem-deleteBadge": "_DrawerItem-deleteBadge_182aj_170", "DrawerItem-versionActions": "_DrawerItem-versionActions_182aj_181", "DrawerItem-migrationOptions": "_DrawerItem-migrationOptions_182aj_187", "DrawerItem-migrationList": "_DrawerItem-migrationList_182aj_191", "DrawerItem-migrationOption": "_DrawerItem-migrationOption_182aj_187", "DrawerItem-migrationOption--isSelected": "_DrawerItem-migrationOption--isSelected_182aj_229", "DrawerItem-migrationOptionLabel": "_DrawerItem-migrationOptionLabel_182aj_234", "DrawerItem-modalFooter": "_DrawerItem-modalFooter_182aj_240", "DrawerItem-footerLeft": "_DrawerItem-footerLeft_182aj_250", "DrawerItem-footerRight": "_DrawerItem-footerRight_182aj_255" };
3047
3074
 
3048
3075
  // src/puck/components/modal/index.tsx
3049
3076
  import { useEffect as useEffect4, useState as useState4 } from "react";
3050
3077
  import { createPortal } from "react-dom";
3051
3078
 
3052
3079
  // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
3053
- var styles_module_default2 = { "Modal": "_Modal_pvj02_1", "Modal--isOpen": "_Modal--isOpen_pvj02_29", "Modal-inner": "_Modal-inner_pvj02_37" };
3080
+ var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
3054
3081
 
3055
3082
  // src/puck/components/modal/index.tsx
3056
3083
  import { jsx as jsx10 } from "react/jsx-runtime";
@@ -3064,18 +3091,43 @@ var Modal = ({
3064
3091
  useEffect4(() => {
3065
3092
  setRootEl(document.getElementById("puck-portal-root"));
3066
3093
  }, []);
3094
+ useEffect4(() => {
3095
+ if (!isOpen) {
3096
+ return;
3097
+ }
3098
+ const handleEscape = (event) => {
3099
+ if (event.key === "Escape") {
3100
+ onClose();
3101
+ }
3102
+ };
3103
+ document.addEventListener("keydown", handleEscape);
3104
+ return () => document.removeEventListener("keydown", handleEscape);
3105
+ }, [isOpen, onClose]);
3067
3106
  if (!rootEl) {
3068
3107
  return /* @__PURE__ */ jsx10("div", {});
3069
3108
  }
3070
3109
  return createPortal(
3071
- /* @__PURE__ */ jsx10("div", { className: getClassName4({ isOpen }), onClick: onClose, children: /* @__PURE__ */ jsx10(
3110
+ /* @__PURE__ */ jsx10(
3072
3111
  "div",
3073
3112
  {
3074
- className: getClassName4("inner"),
3075
- onClick: (e) => e.stopPropagation(),
3076
- children
3113
+ className: getClassName4({ isOpen }),
3114
+ onClick: (event) => {
3115
+ if (event.target === event.currentTarget) {
3116
+ onClose();
3117
+ }
3118
+ },
3119
+ children: /* @__PURE__ */ jsx10(
3120
+ "div",
3121
+ {
3122
+ className: getClassName4("inner"),
3123
+ role: "dialog",
3124
+ "aria-modal": "true",
3125
+ onClick: (e) => e.stopPropagation(),
3126
+ children
3127
+ }
3128
+ )
3077
3129
  }
3078
- ) }),
3130
+ ),
3079
3131
  rootEl
3080
3132
  );
3081
3133
  };
@@ -3098,13 +3150,14 @@ var DrawerItem = (props) => {
3098
3150
  );
3099
3151
  const { handleDemolish } = useDemolish();
3100
3152
  const { handleSetDefaultVersion, getVersions, getDefaultVersion } = useSetDefaultVersion();
3153
+ const { triggerAction } = useActionEvent();
3101
3154
  const [isEditing, setIsEditing] = useState5(false);
3102
3155
  const [isHovering, setIsHovering] = useState5(false);
3103
3156
  const [selectedVersion, setSelectedVersion] = useState5("");
3104
3157
  const [versionsToDelete, setVersionsToDelete] = useState5(
3105
3158
  /* @__PURE__ */ new Set()
3106
3159
  );
3107
- const [migrateVersionMap, setMigrateVersionMap] = useState5({});
3160
+ const [migrationTarget, setMigrationTarget] = useState5("decompose");
3108
3161
  const useVersioning = useSoftConfig((s) => s.showVersionFields);
3109
3162
  const versions = getVersions(props.name);
3110
3163
  const defaultVersion = getDefaultVersion(props.name);
@@ -3125,19 +3178,27 @@ var DrawerItem = (props) => {
3125
3178
  break;
3126
3179
  } else {
3127
3180
  removeSoftComponentVersion(props.name, version);
3181
+ void triggerAction({
3182
+ type: "deleteVersion",
3183
+ payload: {
3184
+ id: props.name,
3185
+ version,
3186
+ migrateToVersion: migrationTarget
3187
+ }
3188
+ });
3128
3189
  }
3129
3190
  }
3130
3191
  }
3131
3192
  setIsEditing(false);
3132
3193
  setSelectedVersion("");
3133
3194
  setVersionsToDelete(/* @__PURE__ */ new Set());
3134
- setMigrateVersionMap({});
3195
+ setMigrationTarget("decompose");
3135
3196
  });
3136
3197
  const handleCancel = () => {
3137
3198
  setIsEditing(false);
3138
3199
  setSelectedVersion("");
3139
3200
  setVersionsToDelete(/* @__PURE__ */ new Set());
3140
- setMigrateVersionMap({});
3201
+ setMigrationTarget("decompose");
3141
3202
  };
3142
3203
  const toggleVersionForDeletion = (version) => {
3143
3204
  const newSet = new Set(versionsToDelete);
@@ -3159,6 +3220,13 @@ var DrawerItem = (props) => {
3159
3220
  });
3160
3221
  if (softComponents.has(props.name)) {
3161
3222
  const availableVersions = versions.filter((v) => !versionsToDelete.has(v));
3223
+ const migrationTargets = [
3224
+ { value: "decompose", label: "Decompose to basic elements" },
3225
+ ...availableVersions.map((version) => ({
3226
+ value: version,
3227
+ label: `Migrate to Version ${version}`
3228
+ }))
3229
+ ];
3162
3230
  return /* @__PURE__ */ jsxs4(Fragment5, { children: [
3163
3231
  /* @__PURE__ */ jsxs4(
3164
3232
  "div",
@@ -3229,30 +3297,35 @@ var DrawerItem = (props) => {
3229
3297
  ] }, version);
3230
3298
  }) })
3231
3299
  ] }),
3232
- versionsToDelete.size > 0 && availableVersions.length > 0 && /* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
3300
+ versionsToDelete.size > 0 && /* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
3233
3301
  /* @__PURE__ */ jsx11("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
3234
- /* @__PURE__ */ jsx11("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ jsxs4(
3235
- "select",
3302
+ /* @__PURE__ */ jsx11("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ jsx11(
3303
+ "div",
3236
3304
  {
3237
- title: "Select migration version",
3238
- className: getClassName5("select"),
3239
- value: migrateVersionMap[Array.from(versionsToDelete)[0]] || "decompose",
3240
- onChange: (e) => {
3241
- const newMap = __spreadValues({}, migrateVersionMap);
3242
- versionsToDelete.forEach((v) => {
3243
- newMap[v] = e.target.value;
3244
- });
3245
- setMigrateVersionMap(newMap);
3246
- },
3247
- children: [
3248
- /* @__PURE__ */ jsx11("option", { value: "decompose", children: "Decompose to basic elements" }),
3249
- availableVersions.map((v) => /* @__PURE__ */ jsxs4("option", { value: v, children: [
3250
- "Migrate to Version ",
3251
- v
3252
- ] }, v))
3253
- ]
3305
+ className: getClassName5("migrationList"),
3306
+ role: "radiogroup",
3307
+ "aria-label": "Migration target",
3308
+ children: migrationTargets.map((target) => {
3309
+ const isSelected = migrationTarget === target.value;
3310
+ return /* @__PURE__ */ jsxs4(
3311
+ "button",
3312
+ {
3313
+ type: "button",
3314
+ role: "radio",
3315
+ "aria-checked": isSelected,
3316
+ className: `${getClassName5("migrationOption")} ${isSelected ? getClassName5("migrationOption--isSelected") : ""}`,
3317
+ onClick: () => setMigrationTarget(target.value),
3318
+ children: [
3319
+ /* @__PURE__ */ jsx11("span", { className: getClassName5("migrationOptionLabel"), children: target.label }),
3320
+ isSelected && /* @__PURE__ */ jsx11(Check, { size: 14 })
3321
+ ]
3322
+ },
3323
+ target.value
3324
+ );
3325
+ })
3254
3326
  }
3255
- ) })
3327
+ ) }),
3328
+ /* @__PURE__ */ jsx11("p", { className: getClassName5("helpText"), children: "Choose where to move existing instances of the deleted versions." })
3256
3329
  ] })
3257
3330
  ] }) : /* @__PURE__ */ jsx11("div", { className: getClassName5("section"), children: /* @__PURE__ */ jsxs4("p", { children: [
3258
3331
  "Manage high-level settings for the ",
@@ -3362,11 +3435,6 @@ var Drawer = (_props) => {
3362
3435
  key
3363
3436
  )) });
3364
3437
  }
3365
- console.log(
3366
- getClassName6(),
3367
- getCategoryClassName(),
3368
- getCategoryClassName({ isExpanded: true })
3369
- );
3370
3438
  return /* @__PURE__ */ jsxs5("div", { className: getClassName6(), children: [
3371
3439
  categoryEntries.map(([id, cat]) => {
3372
3440
  var _a2, _b2, _c;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlisian/softconfig",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",