@netlisian/softconfig 0.1.6 → 0.1.8

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.
@@ -74,6 +74,7 @@ __export(puck_exports, {
74
74
  Drawer: () => Drawer,
75
75
  DrawerItem: () => DrawerItem,
76
76
  Header: () => Header,
77
+ HeaderActions: () => HeaderActions,
77
78
  Modal: () => Modal,
78
79
  SoftConfigProvider: () => SoftConfigProvider,
79
80
  applyMapping: () => applyMapping,
@@ -98,7 +99,8 @@ __export(puck_exports, {
98
99
  useInspect: () => useInspect,
99
100
  useRemodel: () => useRemodel,
100
101
  useSetDefaultVersion: () => useSetDefaultVersion,
101
- useSoftConfig: () => useSoftConfig
102
+ useSoftConfig: () => useSoftConfig,
103
+ useSoftConfigStore: () => useSoftConfigStore
102
104
  });
103
105
  module.exports = __toCommonJS(puck_exports);
104
106
 
@@ -669,6 +671,15 @@ var createUseSoftConfig = () => {
669
671
  };
670
672
  };
671
673
  var useSoftConfig = createUseSoftConfig();
674
+ var useSoftConfigStore = () => {
675
+ const context = (0, import_react.useContext)(appStoreContext);
676
+ if (!context) {
677
+ throw new Error(
678
+ "useSoftConfigStore must be used inside a SoftConfigProvider."
679
+ );
680
+ }
681
+ return context;
682
+ };
672
683
 
673
684
  // src/puck/lib/apply-mapping.ts
674
685
  var import_react_fast_compare = __toESM(require("react-fast-compare"));
@@ -1121,7 +1132,7 @@ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (op
1121
1132
  };
1122
1133
  var get_class_name_factory_default = getClassNameFactory;
1123
1134
 
1124
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1135
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1125
1136
  var styles_module_default = { "ErrorBoundary": "_ErrorBoundary_1xl05_5", "ErrorBoundary-title": "_ErrorBoundary-title_1xl05_21", "ErrorBoundary-details": "_ErrorBoundary-details_1xl05_31", "ErrorBoundary-button": "_ErrorBoundary-button_1xl05_39" };
1126
1137
 
1127
1138
  // src/puck/components/error-boundary/index.tsx
@@ -1647,26 +1658,18 @@ var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, impor
1647
1658
  var toSlug = (value) => {
1648
1659
  return value.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "");
1649
1660
  };
1650
- var defaultComponentNameToKey = (displayName, context) => {
1651
- var _a, _b;
1652
- const registry = (_b = (_a = context.registryName) != null ? _a : context.registry) != null ? _b : "default";
1653
- return `${toSlug(registry)}/${toSlug(displayName)}`;
1654
- };
1655
- var defaultComponentKeyToName = (key) => {
1656
- const slashIndex = key.indexOf("/");
1657
- const componentPart = slashIndex === -1 ? key : key.slice(slashIndex + 1);
1658
- if (!componentPart) return "";
1659
- return componentPart.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1661
+ var slugTolabel = (name) => {
1662
+ return name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1660
1663
  };
1661
- var createComponentKeyFromName = (displayName, overrides, context) => {
1662
- const key = overrides.componentNameToKey ? overrides.componentNameToKey(displayName, context) : defaultComponentNameToKey(displayName, context);
1664
+ var componentNameFromLabel = (label, overrides, context) => {
1665
+ const key = overrides.componentLabelToName ? overrides.componentLabelToName(label, context) : toSlug(label);
1663
1666
  return key.trim();
1664
1667
  };
1665
- var getComponentNameFromKey = (key, overrides) => {
1666
- if (overrides == null ? void 0 : overrides.componentKeyToName) {
1667
- return overrides.componentKeyToName(key);
1668
+ var componentLabelFromName = (name, overrides) => {
1669
+ if (overrides == null ? void 0 : overrides.componentNameToLabel) {
1670
+ return overrides.componentNameToLabel(name);
1668
1671
  }
1669
- return defaultComponentKeyToName(key);
1672
+ return slugTolabel(name);
1670
1673
  };
1671
1674
 
1672
1675
  // src/puck/lib/soft-component-to-appstate.ts
@@ -1862,7 +1865,7 @@ var softComponentToAppState = (softComponent, componentName, version, versions,
1862
1865
  mergedFieldSettings[field.name] = settings;
1863
1866
  });
1864
1867
  let rootProps = __spreadValues({
1865
- _name: displayName || getComponentNameFromKey(componentName, overrides),
1868
+ _name: displayName || componentLabelFromName(componentName, overrides),
1866
1869
  _category: category,
1867
1870
  _version: version,
1868
1871
  _versions: versions,
@@ -2067,14 +2070,12 @@ var hydrateCustomField = (fieldName, field, fieldSettings, customFields) => {
2067
2070
  };
2068
2071
  var createVersionedComponentConfig = (componentName, displayName, version, allVersions, config, softComponents, defaultProps, showVersioning = true, customFields, overrides) => {
2069
2072
  var _a, _b;
2070
- const baseConfig = {
2073
+ return {
2071
2074
  label: displayName,
2072
2075
  fields: Object.fromEntries(
2073
2076
  (Object.entries(
2074
2077
  (_b = (_a = softComponents[componentName].versions) == null ? void 0 : _a[version]) == null ? void 0 : _b.fields
2075
- ) || []).filter(
2076
- ([key, field]) => field.type === "slot"
2077
- ).map(([key, field]) => [key, __spreadValues({}, field)])
2078
+ ) || []).filter(([key, field]) => field.type === "slot").map(([key, field]) => [key, __spreadValues({}, field)])
2078
2079
  ),
2079
2080
  defaultProps: __spreadProps(__spreadValues({}, defaultProps), {
2080
2081
  version
@@ -2117,10 +2118,6 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
2117
2118
  );
2118
2119
  }
2119
2120
  };
2120
- if (overrides == null ? void 0 : overrides.mapComponentConfig) {
2121
- return __spreadValues(__spreadValues({}, baseConfig), overrides.mapComponentConfig(componentName, baseConfig));
2122
- }
2123
- return baseConfig;
2124
2121
  };
2125
2122
 
2126
2123
  // src/puck/lib/builder/sub-component-decomposer.tsx
@@ -2241,6 +2238,61 @@ function demolishSoftComponent(componentName, data, config, softComponents) {
2241
2238
  };
2242
2239
  }
2243
2240
 
2241
+ // src/puck/lib/edit-visibility-utils.ts
2242
+ var setEditVisibility = (doc, context) => {
2243
+ if (!doc) return;
2244
+ try {
2245
+ const root = doc.documentElement;
2246
+ if (context.mode === "none") {
2247
+ root.removeAttribute("data-edit-mode");
2248
+ root.classList.remove("edit-visibility-mode");
2249
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2250
+ el.removeAttribute("data-edit-visibility");
2251
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2252
+ });
2253
+ } else {
2254
+ root.setAttribute("data-edit-mode", context.mode);
2255
+ root.classList.add("edit-visibility-mode");
2256
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2257
+ var _a;
2258
+ const id = el.getAttribute("data-puck-component");
2259
+ if (!id) return;
2260
+ const isEditable = context.editableIds.has(id);
2261
+ const isDependency = (_a = context.highlightDependencyIds) == null ? void 0 : _a.has(id);
2262
+ if (isEditable) {
2263
+ el.setAttribute("data-edit-visibility", "editable");
2264
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-dependency");
2265
+ el.classList.add("edit-visibility-editable");
2266
+ } else if (isDependency) {
2267
+ el.setAttribute("data-edit-visibility", "dependency");
2268
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable");
2269
+ el.classList.add("edit-visibility-dependency");
2270
+ } else {
2271
+ el.setAttribute("data-edit-visibility", "greyed");
2272
+ el.classList.remove("edit-visibility-editable", "edit-visibility-dependency");
2273
+ el.classList.add("edit-visibility-greyed");
2274
+ }
2275
+ });
2276
+ }
2277
+ } catch (error) {
2278
+ console.warn(`Failed to set edit visibility:`, error);
2279
+ }
2280
+ };
2281
+ var clearEditVisibility = (doc) => {
2282
+ if (!doc) return;
2283
+ try {
2284
+ const root = doc.documentElement;
2285
+ root.removeAttribute("data-edit-mode");
2286
+ root.classList.remove("edit-visibility-mode");
2287
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2288
+ el.removeAttribute("data-edit-visibility");
2289
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2290
+ });
2291
+ } catch (error) {
2292
+ console.warn(`Failed to clear edit visibility:`, error);
2293
+ }
2294
+ };
2295
+
2244
2296
  // src/puck/store/slices/builder.tsx
2245
2297
  var createBuildersSlice = (set, get, initialConfig) => ({
2246
2298
  build: (history, selectedItem, itemSelector, puckDispatch, name) => {
@@ -2291,6 +2343,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2291
2343
  return components;
2292
2344
  }
2293
2345
  );
2346
+ requestAnimationFrame(
2347
+ () => setEditVisibility(get().iframeDoc, {
2348
+ mode: "build",
2349
+ editableIds
2350
+ })
2351
+ );
2294
2352
  set((s) => __spreadProps(__spreadValues({}, s), {
2295
2353
  softConfig: buildConfig,
2296
2354
  storedConfig: config,
@@ -2303,15 +2361,14 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2303
2361
  editableComponentIds: editableIds,
2304
2362
  state: "building"
2305
2363
  }));
2306
- setTimeout(
2364
+ requestAnimationFrame(
2307
2365
  () => puckDispatch({
2308
2366
  type: "replaceRoot",
2309
2367
  root: {
2310
2368
  title: "Soft Component Builder",
2311
2369
  _name: name || "New Soft Component"
2312
2370
  }
2313
- }),
2314
- 100
2371
+ })
2315
2372
  );
2316
2373
  },
2317
2374
  remodel: (history, selectedItem, itemSelector, puckDispatch) => {
@@ -2399,6 +2456,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2399
2456
  }).content
2400
2457
  })
2401
2458
  });
2459
+ requestAnimationFrame(
2460
+ () => setEditVisibility(get().iframeDoc, {
2461
+ mode: "remodel",
2462
+ editableIds
2463
+ })
2464
+ );
2402
2465
  set((s) => __spreadProps(__spreadValues({}, s), {
2403
2466
  storedConfig: config,
2404
2467
  softConfig: buildConfig,
@@ -2412,7 +2475,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2412
2475
  editableComponentIds: editableIds,
2413
2476
  state: "remodeling"
2414
2477
  }));
2415
- setTimeout(
2478
+ requestAnimationFrame(
2416
2479
  () => puckDispatch({
2417
2480
  type: "replaceRoot",
2418
2481
  root: {
@@ -2420,8 +2483,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2420
2483
  _name: root.props._name,
2421
2484
  _category: root.props._category
2422
2485
  }
2423
- }),
2424
- 100
2486
+ })
2425
2487
  );
2426
2488
  },
2427
2489
  complete: (appState, setHistories, getItemBySelector) => {
@@ -2437,34 +2499,34 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2437
2499
  if (!itemSelector) {
2438
2500
  throw new Error("No item selector found for completed component.");
2439
2501
  }
2440
- const selectedItem = getItemBySelector(
2441
- itemSelector
2442
- );
2502
+ const selectedItem = getItemBySelector(itemSelector);
2443
2503
  if (!selectedItem) {
2444
2504
  throw new Error("Cannot find item being edited");
2445
2505
  }
2446
2506
  const rootCategory = (_e = (_d = appState.data.root) == null ? void 0 : _d.props) == null ? void 0 : _e._category;
2447
2507
  const rootProps = (_f = appState.data.root) == null ? void 0 : _f.props;
2448
- const componentName = createComponentKeyFromName(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2508
+ const componentName = componentNameFromLabel(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2449
2509
  existingKeys: Object.keys(get().softComponents),
2450
2510
  state: get().state
2451
2511
  }));
2452
2512
  if (!componentName) {
2453
2513
  throw new Error("Failed to generate component key from name.");
2454
2514
  }
2455
- const [newSoftComponentConfig, version] = get().builder.compose(
2515
+ const [defaultSoftComponentConfig, version] = get().builder.compose(
2456
2516
  appState,
2457
2517
  componentName,
2458
2518
  selectedItem,
2459
2519
  displayName,
2460
2520
  rootCategory
2461
2521
  ) || [];
2462
- if (!newSoftComponentConfig) {
2522
+ if (!defaultSoftComponentConfig) {
2463
2523
  throw new Error("Failed to compose new soft component config.");
2464
2524
  }
2465
2525
  const storedHistories = get().originalHistory;
2466
2526
  setHistories([...storedHistories]);
2467
2527
  const config = __spreadValues({}, get().softConfig || initialConfig);
2528
+ const mapComponentConfig = get().overrides.mapComponentConfig;
2529
+ const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
2468
2530
  set((s) => {
2469
2531
  var _a2, _b2;
2470
2532
  const nextComponents = __spreadProps(__spreadValues({}, Object.entries(config.components).reduce(
@@ -2506,10 +2568,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2506
2568
  }),
2507
2569
  storedConfig: void 0,
2508
2570
  state: "inspecting",
2509
- originalHistory: [],
2510
- editingComponent: null,
2511
- editingComponentId: null,
2512
- editableComponentIds: /* @__PURE__ */ new Set()
2571
+ originalHistory: []
2513
2572
  });
2514
2573
  });
2515
2574
  if (!version) {
@@ -2536,30 +2595,44 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2536
2595
  if ((selector == null ? void 0 : selector.index) === void 0 || !(selector == null ? void 0 : selector.zone)) {
2537
2596
  throw new Error("No selector found for last item.");
2538
2597
  }
2539
- setTimeout(() => {
2540
- puckDispatch({
2541
- type: "remove",
2542
- index: selector.index,
2543
- zone: selector.zone
2598
+ const editableComponentId = get().editingComponentId;
2599
+ requestAnimationFrame(() => {
2600
+ const config = get().softConfig;
2601
+ const newComponent = config.components[componentName];
2602
+ const reconstructedTree = (data) => (0, import_puck4.walkTree)(data, config, (components) => {
2603
+ return components.map((comp) => {
2604
+ if (comp.props.id === editableComponentId) {
2605
+ return {
2606
+ type: componentName,
2607
+ props: __spreadProps(__spreadValues({}, newComponent.defaultProps), {
2608
+ id: generateId(componentName)
2609
+ })
2610
+ };
2611
+ }
2612
+ return comp;
2613
+ });
2544
2614
  });
2545
2615
  puckDispatch({
2546
- type: "insert",
2547
- destinationIndex: selector.index,
2548
- destinationZone: selector.zone,
2549
- componentType: componentName
2616
+ type: "setData",
2617
+ data: (data) => {
2618
+ return reconstructedTree(data);
2619
+ }
2550
2620
  });
2551
- }, 500);
2621
+ });
2622
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2552
2623
  set((s) => __spreadProps(__spreadValues({}, s), {
2553
2624
  state: "ready",
2554
2625
  setItemSelector: void 0,
2555
2626
  setOriginalItem: void 0,
2627
+ editingComponent: null,
2556
2628
  editingComponentId: null,
2557
2629
  editableComponentIds: /* @__PURE__ */ new Set()
2558
2630
  }));
2559
2631
  },
2560
2632
  cancel: (setHistories) => {
2561
2633
  const storedHistories = get().originalHistory;
2562
- setTimeout(() => setHistories([...storedHistories]), 100);
2634
+ requestAnimationFrame(() => setHistories([...storedHistories]));
2635
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2563
2636
  set((s) => __spreadProps(__spreadValues({}, s), {
2564
2637
  softConfig: get().storedConfig || initialConfig,
2565
2638
  storedConfig: void 0,
@@ -2888,74 +2961,12 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
2888
2961
  }
2889
2962
  }
2890
2963
 
2891
- // src/puck/lib/edit-visibility-utils.ts
2892
- var setEditVisibility = (doc, context) => {
2893
- if (!doc) return;
2894
- try {
2895
- const root = doc.documentElement;
2896
- if (context.mode === "none") {
2897
- root.removeAttribute("data-edit-mode");
2898
- root.classList.remove("edit-visibility-mode");
2899
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2900
- el.removeAttribute("data-edit-visibility");
2901
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2902
- });
2903
- } else {
2904
- root.setAttribute("data-edit-mode", context.mode);
2905
- root.classList.add("edit-visibility-mode");
2906
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2907
- var _a;
2908
- const id = el.getAttribute("data-puck-component");
2909
- if (!id) return;
2910
- const isEditable = context.editableIds.has(id);
2911
- const isDependency = (_a = context.highlightDependencyIds) == null ? void 0 : _a.has(id);
2912
- if (isEditable) {
2913
- el.setAttribute("data-edit-visibility", "editable");
2914
- el.classList.remove("edit-visibility-greyed", "edit-visibility-dependency");
2915
- el.classList.add("edit-visibility-editable");
2916
- } else if (isDependency) {
2917
- el.setAttribute("data-edit-visibility", "dependency");
2918
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable");
2919
- el.classList.add("edit-visibility-dependency");
2920
- } else {
2921
- el.setAttribute("data-edit-visibility", "greyed");
2922
- el.classList.remove("edit-visibility-editable", "edit-visibility-dependency");
2923
- el.classList.add("edit-visibility-greyed");
2924
- }
2925
- });
2926
- }
2927
- } catch (error) {
2928
- console.warn(`Failed to set edit visibility:`, error);
2929
- }
2930
- };
2931
- var clearEditVisibility = (doc) => {
2932
- if (!doc) return;
2933
- try {
2934
- const root = doc.documentElement;
2935
- root.removeAttribute("data-edit-mode");
2936
- root.classList.remove("edit-visibility-mode");
2937
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2938
- el.removeAttribute("data-edit-visibility");
2939
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2940
- });
2941
- } catch (error) {
2942
- console.warn(`Failed to clear edit visibility:`, error);
2943
- }
2944
- };
2945
-
2946
2964
  // src/puck/store/index.tsx
2947
- var createSoftConfigStore = (hardConfig = {
2948
- components: {}
2949
- }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2965
+ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2950
2966
  const normalizedSoftComponents = Object.fromEntries(
2951
- Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [
2952
- key,
2953
- __spreadProps(__spreadValues({}, value), {
2954
- name: value.name || key
2955
- })
2956
- ])
2967
+ Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
2957
2968
  );
2958
- const iframeDocRef = { current: null };
2969
+ const iframeDoc = null;
2959
2970
  const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
2960
2971
  normalizedSoftComponents,
2961
2972
  overrides.hydrateMapTransform
@@ -2964,318 +2975,323 @@ var createSoftConfigStore = (hardConfig = {
2964
2975
  hydratedSoftComponents
2965
2976
  );
2966
2977
  return (0, import_zustand2.create)()(
2967
- (0, import_middleware.subscribeWithSelector)(
2968
- (set, get) => ({
2969
- state: "ready",
2970
- originalHistory: [],
2971
- overrides,
2972
- customFields,
2973
- onActions,
2974
- iframeDocRef,
2975
- showVersionFields,
2976
- editingComponent: null,
2977
- setShowVersionFields: (show) => set({ showVersionFields: show }),
2978
- getIframeDoc: () => iframeDocRef.current,
2979
- setIframeDoc: (doc) => {
2980
- iframeDocRef.current = doc;
2981
- if (!doc) {
2982
- return;
2978
+ (0, import_middleware.subscribeWithSelector)((set, get) => ({
2979
+ // ─── Initial State ──────────────────────────────────────────────────────
2980
+ state: "ready",
2981
+ originalHistory: [],
2982
+ overrides,
2983
+ customFields,
2984
+ onActions,
2985
+ iframeDoc,
2986
+ editingComponent: null,
2987
+ editingComponentId: null,
2988
+ editableComponentIds: /* @__PURE__ */ new Set(),
2989
+ itemSelector: null,
2990
+ originalItem: null,
2991
+ hydratedSoftComponents,
2992
+ softComponents: hydratedSoftComponents,
2993
+ dependencyGraph: initialDependencyGraph,
2994
+ showVersionFields,
2995
+ // ─── Initial softConfig ─────────────────────────────────────────────────
2996
+ softConfig: __spreadProps(__spreadValues({}, hardConfig), {
2997
+ components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
2998
+ hardConfig,
2999
+ hydratedSoftComponents,
3000
+ overrides,
3001
+ showVersionFields,
3002
+ customFields
3003
+ )),
3004
+ categories: __spreadValues({}, hardConfig.categories || {})
3005
+ }),
3006
+ // ─── UI Flags ───────────────────────────────────────────────────────────
3007
+ setShowVersionFields: (show) => set({ showVersionFields: show }),
3008
+ // ─── Iframe ─────────────────────────────────────────────────────────────
3009
+ setIframeDoc: (doc) => set({
3010
+ iframeDoc: doc
3011
+ }),
3012
+ // ─── History ────────────────────────────────────────────────────────────
3013
+ storeHistory: (history) => set({ originalHistory: history }),
3014
+ removeHistory: () => set({ originalHistory: [] }),
3015
+ // ─── Item Selection ─────────────────────────────────────────────────────
3016
+ setItemSelector: (selector) => set({ itemSelector: selector }),
3017
+ setOriginalItem: (item) => set({ originalItem: item }),
3018
+ // ─── Editing State ──────────────────────────────────────────────────────
3019
+ setEditableComponentIds: (ids) => set({ editableComponentIds: ids }),
3020
+ addEditableComponentId: (id) => set((state) => {
3021
+ const newIds = new Set(state.editableComponentIds);
3022
+ newIds.add(id);
3023
+ return { editableComponentIds: newIds };
3024
+ }),
3025
+ clearEditingState: () => set({ editingComponentId: null, editableComponentIds: /* @__PURE__ */ new Set() }),
3026
+ // ─── Action Validation ──────────────────────────────────────────────────
3027
+ undoFn: null,
3028
+ setUndoFn: (fn) => set({ undoFn: fn }),
3029
+ validateAction: (action, previousAction) => {
3030
+ var _a;
3031
+ const { state, editableComponentIds, addEditableComponentId } = get();
3032
+ if (state === "ready") return true;
3033
+ if (action.type === "replace") {
3034
+ if ((previousAction == null ? void 0 : previousAction.type) === "insert" && (previousAction == null ? void 0 : previousAction.id) === action.data.props.id) {
3035
+ return true;
2983
3036
  }
2984
- const { state, editableComponentIds } = get();
2985
- if (state === "building") {
2986
- setEditVisibility(doc, {
2987
- mode: "build",
2988
- editableIds: editableComponentIds
2989
- });
2990
- return;
3037
+ const parentId = (_a = action.destinationZone) == null ? void 0 : _a.split(":")[0];
3038
+ if (action.data.props.id && editableComponentIds.has(action.data.props.id)) {
3039
+ return true;
2991
3040
  }
2992
- if (state === "remodeling") {
2993
- setEditVisibility(doc, {
2994
- mode: "remodel",
2995
- editableIds: editableComponentIds
2996
- });
2997
- return;
3041
+ if (parentId && editableComponentIds.has(parentId)) {
3042
+ addEditableComponentId(action.data.props.id);
3043
+ return true;
2998
3044
  }
2999
- clearEditVisibility(doc);
3000
- },
3001
- storeHistory: (history) => set({ originalHistory: history }),
3002
- removeHistory: () => set({ originalHistory: [] }),
3003
- itemSelector: null,
3004
- setItemSelector: (selector) => set({ itemSelector: selector }),
3005
- originalItem: null,
3006
- setOriginalItem: (item) => set({ originalItem: item }),
3007
- hydratedSoftComponents,
3008
- softComponents: hydratedSoftComponents,
3009
- dependencyGraph: initialDependencyGraph,
3010
- softConfig: __spreadProps(__spreadValues({}, hardConfig), {
3011
- components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
3012
- hardConfig,
3013
- hydratedSoftComponents,
3014
- overrides,
3015
- showVersionFields,
3016
- customFields
3017
- )),
3018
- categories: __spreadValues({}, hardConfig.categories || {})
3019
- }),
3020
- setSoftComponent: (name, version, component) => {
3021
- if (hardConfig.components && hardConfig.components[name]) {
3022
- console.warn(`Cannot set soft component "${name}" because it conflicts with a base hardConfig component.`);
3023
- return;
3045
+ return false;
3046
+ }
3047
+ if (action.type === "insert" || action.type === "duplicate") {
3048
+ const zone = action.type === "insert" ? action.destinationZone : action.sourceZone;
3049
+ const parentId = zone == null ? void 0 : zone.split(":")[0];
3050
+ const isEditable = parentId && editableComponentIds.has(parentId);
3051
+ if (!isEditable && action.type === "duplicate") return false;
3052
+ if (action.type === "insert" && action.id && isEditable) {
3053
+ addEditableComponentId(action.id);
3024
3054
  }
3025
- const existing = get().softComponents[name];
3026
- set((state) => {
3027
- var _a, _b;
3028
- return {
3029
- softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3030
- [name]: __spreadProps(__spreadValues({}, existing), {
3031
- name: component.name || (existing == null ? void 0 : existing.name) || name,
3032
- category: (_a = component.category) != null ? _a : existing == null ? void 0 : existing.category,
3033
- defaultVersion: version,
3034
- versions: __spreadProps(__spreadValues({}, ((_b = state.softComponents[name]) == null ? void 0 : _b.versions) || {}), {
3035
- [version]: component
3036
- })
3055
+ }
3056
+ if (action.type === "remove" || action.type === "move" || action.type === "reorder") {
3057
+ const zone = action.type === "remove" ? action.zone : action.destinationZone;
3058
+ const parentId = zone == null ? void 0 : zone.split(":")[0];
3059
+ if (parentId && !editableComponentIds.has(parentId)) return false;
3060
+ return true;
3061
+ }
3062
+ return true;
3063
+ },
3064
+ // ─── Soft Component CRUD ─────────────────────────────────────────────────
3065
+ setSoftComponent: (name, version, component) => {
3066
+ var _a;
3067
+ if ((_a = hardConfig.components) == null ? void 0 : _a[name]) {
3068
+ console.warn(
3069
+ `Cannot set soft component "${name}" because it conflicts with a hardConfig component.`
3070
+ );
3071
+ return;
3072
+ }
3073
+ const existing = get().softComponents[name];
3074
+ set((state) => {
3075
+ var _a2, _b;
3076
+ return {
3077
+ softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3078
+ [name]: __spreadProps(__spreadValues({}, existing), {
3079
+ name: component.name || (existing == null ? void 0 : existing.name) || name,
3080
+ category: (_a2 = component.category) != null ? _a2 : existing == null ? void 0 : existing.category,
3081
+ defaultVersion: version,
3082
+ versions: __spreadProps(__spreadValues({}, ((_b = state.softComponents[name]) == null ? void 0 : _b.versions) || {}), {
3083
+ [version]: component
3037
3084
  })
3038
3085
  })
3039
- };
3040
- });
3041
- },
3042
- setSoftComponents: (incomingComponents) => {
3043
- const state = get();
3044
- const nextSoftComponents = __spreadValues({}, state.softComponents);
3045
- const nextConfigComponents = __spreadValues({}, state.softConfig.components);
3046
- Object.entries(incomingComponents).forEach(([name, data]) => {
3047
- if (hardConfig.components && hardConfig.components[name]) {
3048
- return;
3049
- }
3050
- const existing = nextSoftComponents[name];
3051
- const finalComponentData = existing ? __spreadProps(__spreadValues(__spreadValues({}, existing), data), {
3052
- name: data.name || existing.name || name,
3053
- versions: __spreadValues(__spreadValues({}, existing.versions), data.versions)
3054
- }) : data;
3055
- finalComponentData.name = finalComponentData.name || name;
3056
- nextSoftComponents[name] = finalComponentData;
3057
- const activeVersion = finalComponentData.defaultVersion;
3058
- const activeVersionData = finalComponentData.versions[activeVersion];
3059
- if (activeVersionData) {
3060
- nextConfigComponents[name] = createVersionedComponentConfig(
3061
- name,
3062
- finalComponentData.name || name,
3063
- activeVersion,
3064
- Object.keys(finalComponentData.versions),
3065
- state.softConfig,
3066
- nextSoftComponents,
3067
- activeVersionData.defaultProps,
3068
- state.showVersionFields,
3069
- state.customFields
3070
- );
3071
- }
3072
- });
3073
- set({
3074
- softComponents: nextSoftComponents,
3075
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3076
- components: nextConfigComponents
3077
- })
3078
- });
3079
- },
3080
- hydrateTransforms: () => {
3081
- const { overrides: overrides2, softComponents: softComponents2, softConfig } = get();
3082
- if (!(overrides2 == null ? void 0 : overrides2.hydrateMapTransform)) return;
3083
- const hydratedComponents = hydrateSoftComponentsTransforms(
3084
- softComponents2,
3085
- overrides2.hydrateMapTransform
3086
- );
3087
- const nextConfigComponents = __spreadValues({}, softConfig.components);
3088
- Object.entries(hydratedComponents).forEach(([name, componentData]) => {
3089
- const activeVersion = componentData.defaultVersion;
3090
- const activeVersionData = componentData.versions[activeVersion];
3091
- if (activeVersionData) {
3092
- nextConfigComponents[name] = createVersionedComponentConfig(
3093
- name,
3094
- componentData.name || name,
3095
- activeVersion,
3096
- Object.keys(componentData.versions),
3097
- softConfig,
3098
- hydratedComponents,
3099
- activeVersionData.defaultProps,
3100
- get().showVersionFields,
3101
- get().customFields
3102
- );
3103
- }
3104
- });
3105
- set({
3106
- softComponents: hydratedComponents,
3107
- softConfig: __spreadProps(__spreadValues({}, softConfig), {
3108
- components: nextConfigComponents
3109
3086
  })
3110
- });
3111
- },
3112
- setSoftComponentDefaultVersion: (name, version) => {
3113
- var _a, _b, _c, _d;
3114
- const softComponent = (_b = (_a = get().softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
3115
- const allVersions = Object.keys(
3116
- ((_c = get().softComponents[name]) == null ? void 0 : _c.versions) || {}
3117
- );
3118
- const displayName = ((_d = get().softComponents[name]) == null ? void 0 : _d.name) || name;
3119
- if (!softComponent) {
3120
- throw new Error(
3121
- `Soft component "${name}" version "${version}" does not exist.`
3087
+ };
3088
+ });
3089
+ },
3090
+ setSoftComponents: (incomingComponents) => {
3091
+ const state = get();
3092
+ const nextSoftComponents = __spreadValues({}, state.softComponents);
3093
+ const nextConfigComponents = __spreadValues({}, state.softConfig.components);
3094
+ Object.entries(incomingComponents).forEach(([name, data]) => {
3095
+ var _a;
3096
+ if ((_a = hardConfig.components) == null ? void 0 : _a[name]) return;
3097
+ const existing = nextSoftComponents[name];
3098
+ const merged = existing ? __spreadProps(__spreadValues(__spreadValues({}, existing), data), {
3099
+ name: data.name || existing.name || name,
3100
+ versions: __spreadValues(__spreadValues({}, existing.versions), data.versions)
3101
+ }) : data;
3102
+ merged.name = merged.name || name;
3103
+ nextSoftComponents[name] = merged;
3104
+ const activeVersion = merged.defaultVersion;
3105
+ const activeVersionData = merged.versions[activeVersion];
3106
+ if (activeVersionData) {
3107
+ nextConfigComponents[name] = createVersionedComponentConfig(
3108
+ name,
3109
+ merged.name,
3110
+ activeVersion,
3111
+ Object.keys(merged.versions),
3112
+ state.softConfig,
3113
+ nextSoftComponents,
3114
+ activeVersionData.defaultProps,
3115
+ state.showVersionFields,
3116
+ state.customFields
3122
3117
  );
3123
3118
  }
3124
- const newSoftComponentConfig = createVersionedComponentConfig(
3125
- name,
3126
- displayName,
3127
- version,
3128
- allVersions,
3129
- get().softConfig,
3130
- get().softComponents,
3131
- softComponent.defaultProps,
3132
- get().showVersionFields,
3133
- get().customFields
3119
+ });
3120
+ set({
3121
+ softComponents: nextSoftComponents,
3122
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), { components: nextConfigComponents })
3123
+ });
3124
+ },
3125
+ hydrateTransforms: () => {
3126
+ const { overrides: overrides2, softComponents: softComponents2, softConfig } = get();
3127
+ if (!(overrides2 == null ? void 0 : overrides2.hydrateMapTransform)) return;
3128
+ const hydratedComponents = hydrateSoftComponentsTransforms(
3129
+ softComponents2,
3130
+ overrides2.hydrateMapTransform
3131
+ );
3132
+ const nextConfigComponents = __spreadValues({}, softConfig.components);
3133
+ Object.entries(hydratedComponents).forEach(([name, componentData]) => {
3134
+ const activeVersion = componentData.defaultVersion;
3135
+ const activeVersionData = componentData.versions[activeVersion];
3136
+ if (activeVersionData) {
3137
+ nextConfigComponents[name] = createVersionedComponentConfig(
3138
+ name,
3139
+ componentData.name || name,
3140
+ activeVersion,
3141
+ Object.keys(componentData.versions),
3142
+ softConfig,
3143
+ hydratedComponents,
3144
+ activeVersionData.defaultProps,
3145
+ get().showVersionFields,
3146
+ get().customFields
3147
+ );
3148
+ }
3149
+ });
3150
+ set({
3151
+ softComponents: hydratedComponents,
3152
+ softConfig: __spreadProps(__spreadValues({}, softConfig), { components: nextConfigComponents })
3153
+ });
3154
+ },
3155
+ setSoftComponentDefaultVersion: (name, version) => {
3156
+ var _a, _b, _c, _d;
3157
+ const state = get();
3158
+ const softComponent = (_b = (_a = state.softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
3159
+ if (!softComponent) {
3160
+ throw new Error(
3161
+ `Soft component "${name}" version "${version}" does not exist.`
3134
3162
  );
3135
- set((state) => ({
3136
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3137
- components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3138
- [name]: newSoftComponentConfig
3139
- })
3140
- }),
3163
+ }
3164
+ const allVersions = Object.keys(
3165
+ ((_c = state.softComponents[name]) == null ? void 0 : _c.versions) || {}
3166
+ );
3167
+ const displayName = ((_d = state.softComponents[name]) == null ? void 0 : _d.name) || name;
3168
+ const newConfig = createVersionedComponentConfig(
3169
+ name,
3170
+ displayName,
3171
+ version,
3172
+ allVersions,
3173
+ state.softConfig,
3174
+ state.softComponents,
3175
+ softComponent.defaultProps,
3176
+ state.showVersionFields,
3177
+ state.customFields
3178
+ );
3179
+ set((s) => ({
3180
+ softConfig: __spreadProps(__spreadValues({}, s.softConfig), {
3181
+ components: __spreadProps(__spreadValues({}, s.softConfig.components), { [name]: newConfig })
3182
+ }),
3183
+ softComponents: __spreadProps(__spreadValues({}, s.softComponents), {
3184
+ [name]: __spreadProps(__spreadValues({}, s.softComponents[name]), { defaultVersion: version })
3185
+ })
3186
+ }));
3187
+ },
3188
+ removeSoftComponentVersion: (key, version) => {
3189
+ set((state) => {
3190
+ const component = state.softComponents[key];
3191
+ if (!component) return {};
3192
+ const newVersions = Object.fromEntries(
3193
+ Object.entries(component.versions || {}).filter(
3194
+ ([k]) => k !== version
3195
+ )
3196
+ );
3197
+ let newDefaultVersion = component.defaultVersion;
3198
+ if (component.defaultVersion === version) {
3199
+ const versionKeys = Object.keys(newVersions);
3200
+ newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
3201
+ }
3202
+ return {
3141
3203
  softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3142
- [name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
3143
- defaultVersion: version
3204
+ [key]: __spreadProps(__spreadValues({}, component), {
3205
+ versions: newVersions,
3206
+ defaultVersion: newDefaultVersion
3144
3207
  })
3145
3208
  })
3146
- }));
3147
- },
3148
- removeSoftComponentVersion: (key, version) => {
3149
- set((state) => {
3150
- const component = state.softComponents[key];
3151
- if (!component) return {};
3152
- const newVersions = Object.fromEntries(
3153
- Object.entries(component.versions || {}).filter(
3154
- ([k, _]) => k !== version
3155
- )
3156
- );
3157
- let newDefaultVersion = component.defaultVersion;
3158
- if (component.defaultVersion === version) {
3159
- const versionKeys = Object.keys(newVersions);
3160
- newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
3161
- }
3162
- return {
3163
- softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3164
- [key]: __spreadProps(__spreadValues({}, component), {
3165
- versions: newVersions,
3166
- defaultVersion: newDefaultVersion
3167
- })
3168
- })
3169
- };
3170
- });
3171
- },
3172
- removeSoftComponent: (key) => {
3173
- set((state) => ({
3174
- softComponents: Object.fromEntries(
3175
- Object.entries(state.softComponents).filter(([k, _]) => k !== key)
3176
- )
3177
- }));
3178
- },
3179
- setSoftComponentConfig: (key, config, category) => {
3180
- set((state) => {
3181
- var _a, _b, _c;
3182
- return {
3183
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3184
- components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3185
- [key]: __spreadValues({}, config)
3186
- }),
3187
- categories: category ? __spreadProps(__spreadValues({}, state.softConfig.categories || {}), {
3188
- [category]: __spreadProps(__spreadValues({}, ((_a = state.softConfig.categories) == null ? void 0 : _a[category]) || {}), {
3189
- components: [
3190
- ...((_c = (_b = state.softConfig.categories) == null ? void 0 : _b[category]) == null ? void 0 : _c.components) || [],
3191
- key
3192
- ]
3193
- })
3194
- }) : state.softConfig.categories || {}
3195
- })
3196
- };
3197
- });
3198
- },
3199
- removeSoftComponentConfig: (key) => {
3200
- set((state) => ({
3209
+ };
3210
+ });
3211
+ },
3212
+ removeSoftComponent: (key) => set((state) => ({
3213
+ softComponents: Object.fromEntries(
3214
+ Object.entries(state.softComponents).filter(([k]) => k !== key)
3215
+ )
3216
+ })),
3217
+ setSoftComponentConfig: (key, config, category) => {
3218
+ set((state) => {
3219
+ var _a, _b, _c;
3220
+ return {
3201
3221
  softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3202
- components: Object.fromEntries(
3203
- Object.entries(state.softConfig.components).filter(
3204
- ([k, _]) => k !== key
3205
- )
3206
- )
3207
- })
3208
- }));
3209
- },
3210
- setSoftCategoryConfig: (key, category) => {
3211
- set((state) => {
3212
- var _a;
3213
- return {
3214
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3215
- categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
3216
- [key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
3222
+ components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3223
+ [key]: __spreadValues({}, config)
3224
+ }),
3225
+ categories: category ? __spreadProps(__spreadValues({}, state.softConfig.categories || {}), {
3226
+ [category]: __spreadProps(__spreadValues({}, ((_a = state.softConfig.categories) == null ? void 0 : _a[category]) || {}), {
3227
+ components: [
3228
+ ...((_c = (_b = state.softConfig.categories) == null ? void 0 : _b[category]) == null ? void 0 : _c.components) || [],
3229
+ key
3230
+ ]
3217
3231
  })
3218
- })
3219
- };
3220
- });
3221
- },
3222
- removeSoftCategoryConfig: (key) => {
3223
- set((state) => ({
3224
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3225
- categories: Object.fromEntries(
3226
- Object.entries(state.softConfig.categories || {}).filter(
3227
- ([k, _]) => k !== key
3228
- )
3229
- )
3232
+ }) : state.softConfig.categories || {}
3230
3233
  })
3231
- }));
3232
- },
3233
- builder: createBuildersSlice(set, get, hardConfig),
3234
- editingComponentId: null,
3235
- editableComponentIds: /* @__PURE__ */ new Set(),
3236
- setEditableComponentIds: (ids) => set({ editableComponentIds: ids }),
3237
- addEditableComponentId: (id) => {
3238
- set((state) => {
3239
- const newIds = new Set(state.editableComponentIds);
3240
- newIds.add(id);
3241
- return { editableComponentIds: newIds };
3242
- });
3243
- },
3244
- clearEditingState: () => set({
3245
- editingComponentId: null,
3246
- editableComponentIds: /* @__PURE__ */ new Set()
3247
- }),
3248
- rebuildDependents: (componentName, version) => {
3249
- const state = get();
3250
- const dependents = state.dependencyGraph.get(componentName) || /* @__PURE__ */ new Set();
3251
- if (dependents.size === 0) return;
3252
- const config = __spreadValues({}, state.softConfig);
3253
- const softComponents2 = state.softComponents;
3254
- const toBuild = Array.from(dependents);
3255
- for (const dependentName of toBuild) {
3256
- const dependent = softComponents2[dependentName];
3257
- const defaultVersion = dependent.defaultVersion || Object.keys(dependent.versions || {}).pop();
3258
- if (!defaultVersion) continue;
3259
- const versionedComponent = dependent.versions[defaultVersion];
3260
- const allVersions = Object.keys(dependent.versions || {});
3261
- if (!versionedComponent) continue;
3262
- const newConfig = createVersionedComponentConfig(
3263
- dependentName,
3264
- dependent.name || dependentName,
3265
- defaultVersion,
3266
- allVersions,
3267
- config,
3268
- softComponents2,
3269
- versionedComponent.defaultProps,
3270
- state.showVersionFields,
3271
- state.customFields
3272
- );
3273
- config.components[dependentName] = newConfig;
3274
- }
3275
- set((s) => __spreadProps(__spreadValues({}, s), { softConfig: config }));
3234
+ };
3235
+ });
3236
+ },
3237
+ removeSoftComponentConfig: (key) => set((state) => ({
3238
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3239
+ components: Object.fromEntries(
3240
+ Object.entries(state.softConfig.components).filter(
3241
+ ([k]) => k !== key
3242
+ )
3243
+ )
3244
+ })
3245
+ })),
3246
+ setSoftCategoryConfig: (key, category) => set((state) => {
3247
+ var _a;
3248
+ return {
3249
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3250
+ categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
3251
+ [key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
3252
+ })
3253
+ })
3254
+ };
3255
+ }),
3256
+ removeSoftCategoryConfig: (key) => set((state) => ({
3257
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3258
+ categories: Object.fromEntries(
3259
+ Object.entries(state.softConfig.categories || {}).filter(
3260
+ ([k]) => k !== key
3261
+ )
3262
+ )
3263
+ })
3264
+ })),
3265
+ // ─── Builder Slice ────────────────────────────────────────────────────────
3266
+ builder: createBuildersSlice(set, get, hardConfig),
3267
+ // ─── Dependency Graph ─────────────────────────────────────────────────────
3268
+ rebuildDependents: (componentName) => {
3269
+ const state = get();
3270
+ const dependents = state.dependencyGraph.get(componentName) || /* @__PURE__ */ new Set();
3271
+ if (dependents.size === 0) return;
3272
+ const nextConfig = __spreadValues({}, state.softConfig);
3273
+ const { softComponents: softComponents2 } = state;
3274
+ for (const dependentName of Array.from(dependents)) {
3275
+ const dependent = softComponents2[dependentName];
3276
+ const defaultVersion = dependent.defaultVersion || Object.keys(dependent.versions || {}).pop();
3277
+ if (!defaultVersion) continue;
3278
+ const versionedComponent = dependent.versions[defaultVersion];
3279
+ if (!versionedComponent) continue;
3280
+ nextConfig.components[dependentName] = createVersionedComponentConfig(
3281
+ dependentName,
3282
+ dependent.name || dependentName,
3283
+ defaultVersion,
3284
+ Object.keys(dependent.versions || {}),
3285
+ nextConfig,
3286
+ softComponents2,
3287
+ versionedComponent.defaultProps,
3288
+ state.showVersionFields,
3289
+ state.customFields
3290
+ );
3276
3291
  }
3277
- })
3278
- )
3292
+ set((s) => __spreadProps(__spreadValues({}, s), { softConfig: nextConfig }));
3293
+ }
3294
+ }))
3279
3295
  );
3280
3296
  };
3281
3297
 
@@ -3292,8 +3308,8 @@ var SoftConfigProvider = ({
3292
3308
  onActions,
3293
3309
  useVersioning = false
3294
3310
  }) => {
3295
- const store = value != null ? value : (0, import_react5.useMemo)(
3296
- () => createSoftConfigStore(
3311
+ const store = (0, import_react5.useMemo)(
3312
+ () => value != null ? value : createSoftConfigStore(
3297
3313
  hardConfig,
3298
3314
  softComponents,
3299
3315
  overrides,
@@ -3301,109 +3317,26 @@ var SoftConfigProvider = ({
3301
3317
  useVersioning,
3302
3318
  customFields
3303
3319
  ),
3304
- [
3305
- hardConfig,
3306
- softComponents,
3307
- overrides,
3308
- onActions,
3309
- useVersioning,
3310
- customFields
3311
- ]
3320
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3321
+ [value]
3322
+ // Intentionally omitting the rest: createSoftConfigStore params are
3323
+ // treated as initialisation-time values. If callers need to react to
3324
+ // prop changes they should pass a new `value` store instead.
3312
3325
  );
3313
3326
  const [softConfig, setSoftConfig] = (0, import_react5.useState)(
3314
3327
  () => store.getState().softConfig
3315
3328
  );
3316
- const [internalSoftComponents, setSoftComponents] = (0, import_react5.useState)(
3317
- () => store.getState().softComponents
3318
- );
3319
- const storeSetIframeDoc = (0, import_react5.useMemo)(
3320
- () => store.getState().setIframeDoc,
3321
- [store]
3322
- );
3323
- const validateAction = (0, import_react5.useMemo)(
3324
- () => (action) => {
3325
- var _a;
3326
- const currentState = store.getState();
3327
- if (currentState.state === "ready") {
3328
- return true;
3329
- }
3330
- const editableIds = currentState.editableComponentIds;
3331
- if (action.type === "replace") {
3332
- const parentId = (_a = action.destinationZone) == null ? void 0 : _a.split(":")[0];
3333
- if (action.data.props.id && editableIds.has(action.data.props.id)) {
3334
- return true;
3335
- } else if (parentId && editableIds.has(parentId)) {
3336
- currentState.addEditableComponentId(action.data.props.id);
3337
- return true;
3338
- }
3339
- return false;
3340
- }
3341
- if (action.type === "insert" || action.type === "duplicate") {
3342
- const zone = action.type === "insert" ? action.destinationZone : action.sourceZone;
3343
- const parentId = zone == null ? void 0 : zone.split(":")[0];
3344
- if (parentId && !editableIds.has(parentId)) {
3345
- return false;
3346
- }
3347
- if (action.type === "insert") {
3348
- const childId = action.id;
3349
- if (childId) {
3350
- currentState.addEditableComponentId(childId);
3351
- }
3352
- }
3353
- return true;
3354
- }
3355
- if (action.type === "remove" || action.type === "move" || action.type === "reorder") {
3356
- let parentId;
3357
- if (action.type === "remove") {
3358
- parentId = action.zone.split(":")[0];
3359
- } else if (action.type === "move" || action.type === "reorder") {
3360
- parentId = action.destinationZone.split(":")[0];
3361
- }
3362
- if (parentId && !editableIds.has(parentId)) {
3363
- return false;
3364
- }
3365
- return true;
3366
- }
3367
- return true;
3368
- },
3369
- [store]
3370
- );
3371
- (0, import_react5.useEffect)(() => {
3372
- const unsubscribe = store.subscribe(() => {
3373
- setSoftConfig(store.getState().softConfig);
3374
- setSoftComponents(store.getState().softComponents);
3375
- });
3376
- return () => {
3377
- unsubscribe();
3378
- };
3379
- }, [store]);
3380
3329
  (0, import_react5.useEffect)(() => {
3381
- const unsubscribe = store.subscribe((state, prevState) => {
3382
- if (prevState && state.state === prevState.state && state.editableComponentIds === prevState.editableComponentIds) {
3383
- return;
3384
- }
3385
- const doc = store.getState().getIframeDoc();
3386
- if (!doc) return;
3387
- if (state.state === "building") {
3388
- setEditVisibility(doc, { mode: "build", editableIds: state.editableComponentIds });
3389
- return;
3330
+ let prev = store.getState().softConfig;
3331
+ const unsubscribe = store.subscribe((state) => {
3332
+ if (state.softConfig !== prev) {
3333
+ prev = state.softConfig;
3334
+ setSoftConfig(state.softConfig);
3390
3335
  }
3391
- if (state.state === "remodeling") {
3392
- setEditVisibility(doc, { mode: "remodel", editableIds: state.editableComponentIds });
3393
- return;
3394
- }
3395
- requestAnimationFrame(() => {
3396
- const freshDoc = store.getState().getIframeDoc();
3397
- if (freshDoc) {
3398
- clearEditVisibility(freshDoc);
3399
- }
3400
- });
3401
3336
  });
3402
- return () => {
3403
- unsubscribe();
3404
- };
3337
+ return unsubscribe;
3405
3338
  }, [store]);
3406
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(appStoreContext.Provider, { value: store, children: children(softConfig, internalSoftComponents, storeSetIframeDoc, validateAction) });
3339
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(appStoreContext.Provider, { value: store, children: children(softConfig) });
3407
3340
  };
3408
3341
 
3409
3342
  // src/puck/actions/useBuild.tsx
@@ -3809,7 +3742,7 @@ var useSetDefaultVersion = () => {
3809
3742
  // src/puck/overrides/Header.tsx
3810
3743
  var import_puck13 = require("@measured/puck");
3811
3744
 
3812
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Header.module.css#css-module
3745
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Header.module.css#css-module
3813
3746
  var Header_module_default = { "Header": "_Header_19oj9_1" };
3814
3747
 
3815
3748
  // src/puck/actions/usePublish.tsx
@@ -3858,7 +3791,6 @@ var Header = ({
3858
3791
  const { handleComplete, newComponent, setNewComponent } = useComplete();
3859
3792
  const { handleCancel, canCancel } = useCancel();
3860
3793
  const { handlePublish } = usePublish();
3861
- const puck = usePuck((s) => s.config);
3862
3794
  useInspect(newComponent);
3863
3795
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
3864
3796
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_puck13.Button, { onClick: handleCancel, children: "Cancel" }),
@@ -3894,7 +3826,7 @@ var import_react9 = require("react");
3894
3826
  var import_puck14 = require("@measured/puck");
3895
3827
  var import_lucide_react = require("lucide-react");
3896
3828
 
3897
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
3829
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
3898
3830
  var ActionBar_module_default = { "ActionBar": "_ActionBar_pvuie_5", "ActionBar-label": "_ActionBar-label_pvuie_39", "ActionBar-action": "_ActionBar-action_pvuie_63", "ActionBar-group": "_ActionBar-group_pvuie_79" };
3899
3831
 
3900
3832
  // src/puck/overrides/ActionBar.tsx
@@ -3920,7 +3852,7 @@ var ActionBarOverride = (props) => {
3920
3852
  if (selectedType && softKeys.includes(selectedType)) {
3921
3853
  return selectedType;
3922
3854
  }
3923
- return createComponentKeyFromName(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3855
+ return componentNameFromLabel(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3924
3856
  existingKeys: softKeys,
3925
3857
  state: status
3926
3858
  }));
@@ -3936,17 +3868,17 @@ var ActionBarOverride = (props) => {
3936
3868
  const selectedId = (_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.id;
3937
3869
  const parentId = (_b = itemSelector == null ? void 0 : itemSelector.zone) == null ? void 0 : _b.split(":")[0];
3938
3870
  const isEditable = Boolean(selectedId && (editableIds.has(selectedId) || parentId && editableIds.has(parentId)));
3939
- const displayName = (0, import_react9.useMemo)(() => {
3871
+ const label = (0, import_react9.useMemo)(() => {
3940
3872
  var _a2;
3941
3873
  if (isSoftComponent2) {
3942
- return ((_a2 = softComponents[key]) == null ? void 0 : _a2.name) || getComponentNameFromKey(key, overrides);
3874
+ return ((_a2 = softComponents[key]) == null ? void 0 : _a2.name) || componentLabelFromName(key, overrides);
3943
3875
  }
3944
3876
  return props.label || "";
3945
3877
  }, [isSoftComponent2, key, props.label, overrides, softComponents]);
3946
3878
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassName3(), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck14.ActionBar, { children: [
3947
3879
  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck14.ActionBar.Group, { children: [
3948
3880
  props.parentAction,
3949
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_puck14.ActionBar.Label, { label: displayName })
3881
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_puck14.ActionBar.Label, { label })
3950
3882
  ] }),
3951
3883
  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck14.ActionBar.Group, { children: [
3952
3884
  status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
@@ -4001,14 +3933,14 @@ var confirm = (message) => __async(null, null, function* () {
4001
3933
  }
4002
3934
  });
4003
3935
 
4004
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/DrawerItem.module.css#css-module
3936
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/DrawerItem.module.css#css-module
4005
3937
  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" };
4006
3938
 
4007
3939
  // src/puck/components/modal/index.tsx
4008
3940
  var import_react10 = require("react");
4009
3941
  var import_react_dom = require("react-dom");
4010
3942
 
4011
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
3943
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
4012
3944
  var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
4013
3945
 
4014
3946
  // src/puck/components/modal/index.tsx
@@ -4243,6 +4175,7 @@ var DrawerItem = (props) => {
4243
4175
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
4244
4176
  "button",
4245
4177
  {
4178
+ "aria-label": target.label,
4246
4179
  type: "button",
4247
4180
  role: "radio",
4248
4181
  "aria-checked": isSelected,
@@ -4293,7 +4226,7 @@ var import_react12 = require("react");
4293
4226
  var import_puck16 = require("@measured/puck");
4294
4227
  var import_lucide_react3 = require("lucide-react");
4295
4228
 
4296
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
4229
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
4297
4230
  var Drawer_module_default = { "Drawer": "_Drawer_12zq5_1", "Drawer-category": "_Drawer-category_12zq5_7", "Drawer-category--isExpanded": "_Drawer-category--isExpanded_12zq5_15", "Drawer-categoryContent": "_Drawer-categoryContent_12zq5_19", "Drawer-categoryTitle": "_Drawer-categoryTitle_12zq5_27", "Drawer-categoryTitleIcon": "_Drawer-categoryTitleIcon_12zq5_63" };
4298
4231
 
4299
4232
  // src/puck/overrides/Drawer.tsx
@@ -4405,23 +4338,51 @@ var Drawer = (_props) => {
4405
4338
  ] });
4406
4339
  };
4407
4340
 
4341
+ // src/puck/overrides/HeaderActions.tsx
4342
+ var import_puck17 = require("@measured/puck");
4343
+ var import_jsx_runtime13 = require("react/jsx-runtime");
4344
+ var usePuck5 = (0, import_puck17.createUsePuck)();
4345
+ var HeaderActions = ({ children }) => {
4346
+ const { handleComplete } = useComplete();
4347
+ const { handleCancel, canCancel } = useCancel();
4348
+ const dispatch = usePuck5((s) => s.dispatch);
4349
+ const inspect = useSoftConfig((s) => s.builder.inspect);
4350
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children: canCancel ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
4351
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_puck17.Button, { onClick: handleCancel, children: "Cancel" }),
4352
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4353
+ import_puck17.Button,
4354
+ {
4355
+ variant: "primary",
4356
+ onClick: () => {
4357
+ const completedComponent = handleComplete();
4358
+ if (completedComponent) {
4359
+ try {
4360
+ inspect(completedComponent.id, dispatch);
4361
+ } catch (error) {
4362
+ notify.error(
4363
+ "Failed to inspect after completion: " + (error instanceof Error ? error.message : String(error))
4364
+ );
4365
+ }
4366
+ }
4367
+ },
4368
+ children: "Complete"
4369
+ }
4370
+ )
4371
+ ] }) : children });
4372
+ };
4373
+
4408
4374
  // src/puck/lib/action-callback.ts
4409
4375
  var createActionCallback = (validateAction, undo) => {
4410
4376
  return (action) => {
4377
+ if (!undo) {
4378
+ return;
4379
+ }
4411
4380
  const isValid = validateAction(action);
4412
4381
  if (!isValid) {
4413
4382
  notify.error(
4414
4383
  "Editing outside the soft component is not allowed when you are editing component definition."
4415
4384
  );
4416
- if (typeof requestAnimationFrame === "function") {
4417
- requestAnimationFrame(() => {
4418
- requestAnimationFrame(() => {
4419
- undo();
4420
- });
4421
- });
4422
- } else {
4423
- setTimeout(() => undo(), 0);
4424
- }
4385
+ requestAnimationFrame(() => undo());
4425
4386
  }
4426
4387
  };
4427
4388
  };
@@ -4635,6 +4596,7 @@ var resolveSoftConfig = (data, softComponents, config) => {
4635
4596
  Drawer,
4636
4597
  DrawerItem,
4637
4598
  Header,
4599
+ HeaderActions,
4638
4600
  Modal,
4639
4601
  SoftConfigProvider,
4640
4602
  applyMapping,
@@ -4659,5 +4621,6 @@ var resolveSoftConfig = (data, softComponents, config) => {
4659
4621
  useInspect,
4660
4622
  useRemodel,
4661
4623
  useSetDefaultVersion,
4662
- useSoftConfig
4624
+ useSoftConfig,
4625
+ useSoftConfigStore
4663
4626
  });