@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.
@@ -611,6 +611,15 @@ var createUseSoftConfig = () => {
611
611
  };
612
612
  };
613
613
  var useSoftConfig = createUseSoftConfig();
614
+ var useSoftConfigStore = () => {
615
+ const context = useContext(appStoreContext);
616
+ if (!context) {
617
+ throw new Error(
618
+ "useSoftConfigStore must be used inside a SoftConfigProvider."
619
+ );
620
+ }
621
+ return context;
622
+ };
614
623
 
615
624
  // src/puck/lib/apply-mapping.ts
616
625
  import equal from "react-fast-compare";
@@ -1063,7 +1072,7 @@ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (op
1063
1072
  };
1064
1073
  var get_class_name_factory_default = getClassNameFactory;
1065
1074
 
1066
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1075
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1067
1076
  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" };
1068
1077
 
1069
1078
  // src/puck/components/error-boundary/index.tsx
@@ -1589,26 +1598,18 @@ var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
1589
1598
  var toSlug = (value) => {
1590
1599
  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, "");
1591
1600
  };
1592
- var defaultComponentNameToKey = (displayName, context) => {
1593
- var _a, _b;
1594
- const registry = (_b = (_a = context.registryName) != null ? _a : context.registry) != null ? _b : "default";
1595
- return `${toSlug(registry)}/${toSlug(displayName)}`;
1596
- };
1597
- var defaultComponentKeyToName = (key) => {
1598
- const slashIndex = key.indexOf("/");
1599
- const componentPart = slashIndex === -1 ? key : key.slice(slashIndex + 1);
1600
- if (!componentPart) return "";
1601
- return componentPart.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1601
+ var slugTolabel = (name) => {
1602
+ return name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1602
1603
  };
1603
- var createComponentKeyFromName = (displayName, overrides, context) => {
1604
- const key = overrides.componentNameToKey ? overrides.componentNameToKey(displayName, context) : defaultComponentNameToKey(displayName, context);
1604
+ var componentNameFromLabel = (label, overrides, context) => {
1605
+ const key = overrides.componentLabelToName ? overrides.componentLabelToName(label, context) : toSlug(label);
1605
1606
  return key.trim();
1606
1607
  };
1607
- var getComponentNameFromKey = (key, overrides) => {
1608
- if (overrides == null ? void 0 : overrides.componentKeyToName) {
1609
- return overrides.componentKeyToName(key);
1608
+ var componentLabelFromName = (name, overrides) => {
1609
+ if (overrides == null ? void 0 : overrides.componentNameToLabel) {
1610
+ return overrides.componentNameToLabel(name);
1610
1611
  }
1611
- return defaultComponentKeyToName(key);
1612
+ return slugTolabel(name);
1612
1613
  };
1613
1614
 
1614
1615
  // src/puck/lib/soft-component-to-appstate.ts
@@ -1804,7 +1805,7 @@ var softComponentToAppState = (softComponent, componentName, version, versions,
1804
1805
  mergedFieldSettings[field.name] = settings;
1805
1806
  });
1806
1807
  let rootProps = __spreadValues({
1807
- _name: displayName || getComponentNameFromKey(componentName, overrides),
1808
+ _name: displayName || componentLabelFromName(componentName, overrides),
1808
1809
  _category: category,
1809
1810
  _version: version,
1810
1811
  _versions: versions,
@@ -2009,14 +2010,12 @@ var hydrateCustomField = (fieldName, field, fieldSettings, customFields) => {
2009
2010
  };
2010
2011
  var createVersionedComponentConfig = (componentName, displayName, version, allVersions, config, softComponents, defaultProps, showVersioning = true, customFields, overrides) => {
2011
2012
  var _a, _b;
2012
- const baseConfig = {
2013
+ return {
2013
2014
  label: displayName,
2014
2015
  fields: Object.fromEntries(
2015
2016
  (Object.entries(
2016
2017
  (_b = (_a = softComponents[componentName].versions) == null ? void 0 : _a[version]) == null ? void 0 : _b.fields
2017
- ) || []).filter(
2018
- ([key, field]) => field.type === "slot"
2019
- ).map(([key, field]) => [key, __spreadValues({}, field)])
2018
+ ) || []).filter(([key, field]) => field.type === "slot").map(([key, field]) => [key, __spreadValues({}, field)])
2020
2019
  ),
2021
2020
  defaultProps: __spreadProps(__spreadValues({}, defaultProps), {
2022
2021
  version
@@ -2059,10 +2058,6 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
2059
2058
  );
2060
2059
  }
2061
2060
  };
2062
- if (overrides == null ? void 0 : overrides.mapComponentConfig) {
2063
- return __spreadValues(__spreadValues({}, baseConfig), overrides.mapComponentConfig(componentName, baseConfig));
2064
- }
2065
- return baseConfig;
2066
2061
  };
2067
2062
 
2068
2063
  // src/puck/lib/builder/sub-component-decomposer.tsx
@@ -2183,6 +2178,61 @@ function demolishSoftComponent(componentName, data, config, softComponents) {
2183
2178
  };
2184
2179
  }
2185
2180
 
2181
+ // src/puck/lib/edit-visibility-utils.ts
2182
+ var setEditVisibility = (doc, context) => {
2183
+ if (!doc) return;
2184
+ try {
2185
+ const root = doc.documentElement;
2186
+ if (context.mode === "none") {
2187
+ root.removeAttribute("data-edit-mode");
2188
+ root.classList.remove("edit-visibility-mode");
2189
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2190
+ el.removeAttribute("data-edit-visibility");
2191
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2192
+ });
2193
+ } else {
2194
+ root.setAttribute("data-edit-mode", context.mode);
2195
+ root.classList.add("edit-visibility-mode");
2196
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2197
+ var _a;
2198
+ const id = el.getAttribute("data-puck-component");
2199
+ if (!id) return;
2200
+ const isEditable = context.editableIds.has(id);
2201
+ const isDependency = (_a = context.highlightDependencyIds) == null ? void 0 : _a.has(id);
2202
+ if (isEditable) {
2203
+ el.setAttribute("data-edit-visibility", "editable");
2204
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-dependency");
2205
+ el.classList.add("edit-visibility-editable");
2206
+ } else if (isDependency) {
2207
+ el.setAttribute("data-edit-visibility", "dependency");
2208
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable");
2209
+ el.classList.add("edit-visibility-dependency");
2210
+ } else {
2211
+ el.setAttribute("data-edit-visibility", "greyed");
2212
+ el.classList.remove("edit-visibility-editable", "edit-visibility-dependency");
2213
+ el.classList.add("edit-visibility-greyed");
2214
+ }
2215
+ });
2216
+ }
2217
+ } catch (error) {
2218
+ console.warn(`Failed to set edit visibility:`, error);
2219
+ }
2220
+ };
2221
+ var clearEditVisibility = (doc) => {
2222
+ if (!doc) return;
2223
+ try {
2224
+ const root = doc.documentElement;
2225
+ root.removeAttribute("data-edit-mode");
2226
+ root.classList.remove("edit-visibility-mode");
2227
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2228
+ el.removeAttribute("data-edit-visibility");
2229
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2230
+ });
2231
+ } catch (error) {
2232
+ console.warn(`Failed to clear edit visibility:`, error);
2233
+ }
2234
+ };
2235
+
2186
2236
  // src/puck/store/slices/builder.tsx
2187
2237
  var createBuildersSlice = (set, get, initialConfig) => ({
2188
2238
  build: (history, selectedItem, itemSelector, puckDispatch, name) => {
@@ -2233,6 +2283,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2233
2283
  return components;
2234
2284
  }
2235
2285
  );
2286
+ requestAnimationFrame(
2287
+ () => setEditVisibility(get().iframeDoc, {
2288
+ mode: "build",
2289
+ editableIds
2290
+ })
2291
+ );
2236
2292
  set((s) => __spreadProps(__spreadValues({}, s), {
2237
2293
  softConfig: buildConfig,
2238
2294
  storedConfig: config,
@@ -2245,15 +2301,14 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2245
2301
  editableComponentIds: editableIds,
2246
2302
  state: "building"
2247
2303
  }));
2248
- setTimeout(
2304
+ requestAnimationFrame(
2249
2305
  () => puckDispatch({
2250
2306
  type: "replaceRoot",
2251
2307
  root: {
2252
2308
  title: "Soft Component Builder",
2253
2309
  _name: name || "New Soft Component"
2254
2310
  }
2255
- }),
2256
- 100
2311
+ })
2257
2312
  );
2258
2313
  },
2259
2314
  remodel: (history, selectedItem, itemSelector, puckDispatch) => {
@@ -2341,6 +2396,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2341
2396
  }).content
2342
2397
  })
2343
2398
  });
2399
+ requestAnimationFrame(
2400
+ () => setEditVisibility(get().iframeDoc, {
2401
+ mode: "remodel",
2402
+ editableIds
2403
+ })
2404
+ );
2344
2405
  set((s) => __spreadProps(__spreadValues({}, s), {
2345
2406
  storedConfig: config,
2346
2407
  softConfig: buildConfig,
@@ -2354,7 +2415,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2354
2415
  editableComponentIds: editableIds,
2355
2416
  state: "remodeling"
2356
2417
  }));
2357
- setTimeout(
2418
+ requestAnimationFrame(
2358
2419
  () => puckDispatch({
2359
2420
  type: "replaceRoot",
2360
2421
  root: {
@@ -2362,8 +2423,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2362
2423
  _name: root.props._name,
2363
2424
  _category: root.props._category
2364
2425
  }
2365
- }),
2366
- 100
2426
+ })
2367
2427
  );
2368
2428
  },
2369
2429
  complete: (appState, setHistories, getItemBySelector) => {
@@ -2379,34 +2439,34 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2379
2439
  if (!itemSelector) {
2380
2440
  throw new Error("No item selector found for completed component.");
2381
2441
  }
2382
- const selectedItem = getItemBySelector(
2383
- itemSelector
2384
- );
2442
+ const selectedItem = getItemBySelector(itemSelector);
2385
2443
  if (!selectedItem) {
2386
2444
  throw new Error("Cannot find item being edited");
2387
2445
  }
2388
2446
  const rootCategory = (_e = (_d = appState.data.root) == null ? void 0 : _d.props) == null ? void 0 : _e._category;
2389
2447
  const rootProps = (_f = appState.data.root) == null ? void 0 : _f.props;
2390
- const componentName = createComponentKeyFromName(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2448
+ const componentName = componentNameFromLabel(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2391
2449
  existingKeys: Object.keys(get().softComponents),
2392
2450
  state: get().state
2393
2451
  }));
2394
2452
  if (!componentName) {
2395
2453
  throw new Error("Failed to generate component key from name.");
2396
2454
  }
2397
- const [newSoftComponentConfig, version] = get().builder.compose(
2455
+ const [defaultSoftComponentConfig, version] = get().builder.compose(
2398
2456
  appState,
2399
2457
  componentName,
2400
2458
  selectedItem,
2401
2459
  displayName,
2402
2460
  rootCategory
2403
2461
  ) || [];
2404
- if (!newSoftComponentConfig) {
2462
+ if (!defaultSoftComponentConfig) {
2405
2463
  throw new Error("Failed to compose new soft component config.");
2406
2464
  }
2407
2465
  const storedHistories = get().originalHistory;
2408
2466
  setHistories([...storedHistories]);
2409
2467
  const config = __spreadValues({}, get().softConfig || initialConfig);
2468
+ const mapComponentConfig = get().overrides.mapComponentConfig;
2469
+ const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
2410
2470
  set((s) => {
2411
2471
  var _a2, _b2;
2412
2472
  const nextComponents = __spreadProps(__spreadValues({}, Object.entries(config.components).reduce(
@@ -2448,10 +2508,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2448
2508
  }),
2449
2509
  storedConfig: void 0,
2450
2510
  state: "inspecting",
2451
- originalHistory: [],
2452
- editingComponent: null,
2453
- editingComponentId: null,
2454
- editableComponentIds: /* @__PURE__ */ new Set()
2511
+ originalHistory: []
2455
2512
  });
2456
2513
  });
2457
2514
  if (!version) {
@@ -2478,30 +2535,44 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2478
2535
  if ((selector == null ? void 0 : selector.index) === void 0 || !(selector == null ? void 0 : selector.zone)) {
2479
2536
  throw new Error("No selector found for last item.");
2480
2537
  }
2481
- setTimeout(() => {
2482
- puckDispatch({
2483
- type: "remove",
2484
- index: selector.index,
2485
- zone: selector.zone
2538
+ const editableComponentId = get().editingComponentId;
2539
+ requestAnimationFrame(() => {
2540
+ const config = get().softConfig;
2541
+ const newComponent = config.components[componentName];
2542
+ const reconstructedTree = (data) => walkTree3(data, config, (components) => {
2543
+ return components.map((comp) => {
2544
+ if (comp.props.id === editableComponentId) {
2545
+ return {
2546
+ type: componentName,
2547
+ props: __spreadProps(__spreadValues({}, newComponent.defaultProps), {
2548
+ id: generateId(componentName)
2549
+ })
2550
+ };
2551
+ }
2552
+ return comp;
2553
+ });
2486
2554
  });
2487
2555
  puckDispatch({
2488
- type: "insert",
2489
- destinationIndex: selector.index,
2490
- destinationZone: selector.zone,
2491
- componentType: componentName
2556
+ type: "setData",
2557
+ data: (data) => {
2558
+ return reconstructedTree(data);
2559
+ }
2492
2560
  });
2493
- }, 500);
2561
+ });
2562
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2494
2563
  set((s) => __spreadProps(__spreadValues({}, s), {
2495
2564
  state: "ready",
2496
2565
  setItemSelector: void 0,
2497
2566
  setOriginalItem: void 0,
2567
+ editingComponent: null,
2498
2568
  editingComponentId: null,
2499
2569
  editableComponentIds: /* @__PURE__ */ new Set()
2500
2570
  }));
2501
2571
  },
2502
2572
  cancel: (setHistories) => {
2503
2573
  const storedHistories = get().originalHistory;
2504
- setTimeout(() => setHistories([...storedHistories]), 100);
2574
+ requestAnimationFrame(() => setHistories([...storedHistories]));
2575
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2505
2576
  set((s) => __spreadProps(__spreadValues({}, s), {
2506
2577
  softConfig: get().storedConfig || initialConfig,
2507
2578
  storedConfig: void 0,
@@ -2830,74 +2901,12 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
2830
2901
  }
2831
2902
  }
2832
2903
 
2833
- // src/puck/lib/edit-visibility-utils.ts
2834
- var setEditVisibility = (doc, context) => {
2835
- if (!doc) return;
2836
- try {
2837
- const root = doc.documentElement;
2838
- if (context.mode === "none") {
2839
- root.removeAttribute("data-edit-mode");
2840
- root.classList.remove("edit-visibility-mode");
2841
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2842
- el.removeAttribute("data-edit-visibility");
2843
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2844
- });
2845
- } else {
2846
- root.setAttribute("data-edit-mode", context.mode);
2847
- root.classList.add("edit-visibility-mode");
2848
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2849
- var _a;
2850
- const id = el.getAttribute("data-puck-component");
2851
- if (!id) return;
2852
- const isEditable = context.editableIds.has(id);
2853
- const isDependency = (_a = context.highlightDependencyIds) == null ? void 0 : _a.has(id);
2854
- if (isEditable) {
2855
- el.setAttribute("data-edit-visibility", "editable");
2856
- el.classList.remove("edit-visibility-greyed", "edit-visibility-dependency");
2857
- el.classList.add("edit-visibility-editable");
2858
- } else if (isDependency) {
2859
- el.setAttribute("data-edit-visibility", "dependency");
2860
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable");
2861
- el.classList.add("edit-visibility-dependency");
2862
- } else {
2863
- el.setAttribute("data-edit-visibility", "greyed");
2864
- el.classList.remove("edit-visibility-editable", "edit-visibility-dependency");
2865
- el.classList.add("edit-visibility-greyed");
2866
- }
2867
- });
2868
- }
2869
- } catch (error) {
2870
- console.warn(`Failed to set edit visibility:`, error);
2871
- }
2872
- };
2873
- var clearEditVisibility = (doc) => {
2874
- if (!doc) return;
2875
- try {
2876
- const root = doc.documentElement;
2877
- root.removeAttribute("data-edit-mode");
2878
- root.classList.remove("edit-visibility-mode");
2879
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2880
- el.removeAttribute("data-edit-visibility");
2881
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2882
- });
2883
- } catch (error) {
2884
- console.warn(`Failed to clear edit visibility:`, error);
2885
- }
2886
- };
2887
-
2888
2904
  // src/puck/store/index.tsx
2889
- var createSoftConfigStore = (hardConfig = {
2890
- components: {}
2891
- }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2905
+ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2892
2906
  const normalizedSoftComponents = Object.fromEntries(
2893
- Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [
2894
- key,
2895
- __spreadProps(__spreadValues({}, value), {
2896
- name: value.name || key
2897
- })
2898
- ])
2907
+ Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
2899
2908
  );
2900
- const iframeDocRef = { current: null };
2909
+ const iframeDoc = null;
2901
2910
  const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
2902
2911
  normalizedSoftComponents,
2903
2912
  overrides.hydrateMapTransform
@@ -2906,318 +2915,323 @@ var createSoftConfigStore = (hardConfig = {
2906
2915
  hydratedSoftComponents
2907
2916
  );
2908
2917
  return create()(
2909
- subscribeWithSelector(
2910
- (set, get) => ({
2911
- state: "ready",
2912
- originalHistory: [],
2913
- overrides,
2914
- customFields,
2915
- onActions,
2916
- iframeDocRef,
2917
- showVersionFields,
2918
- editingComponent: null,
2919
- setShowVersionFields: (show) => set({ showVersionFields: show }),
2920
- getIframeDoc: () => iframeDocRef.current,
2921
- setIframeDoc: (doc) => {
2922
- iframeDocRef.current = doc;
2923
- if (!doc) {
2924
- return;
2918
+ subscribeWithSelector((set, get) => ({
2919
+ // ─── Initial State ──────────────────────────────────────────────────────
2920
+ state: "ready",
2921
+ originalHistory: [],
2922
+ overrides,
2923
+ customFields,
2924
+ onActions,
2925
+ iframeDoc,
2926
+ editingComponent: null,
2927
+ editingComponentId: null,
2928
+ editableComponentIds: /* @__PURE__ */ new Set(),
2929
+ itemSelector: null,
2930
+ originalItem: null,
2931
+ hydratedSoftComponents,
2932
+ softComponents: hydratedSoftComponents,
2933
+ dependencyGraph: initialDependencyGraph,
2934
+ showVersionFields,
2935
+ // ─── Initial softConfig ─────────────────────────────────────────────────
2936
+ softConfig: __spreadProps(__spreadValues({}, hardConfig), {
2937
+ components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
2938
+ hardConfig,
2939
+ hydratedSoftComponents,
2940
+ overrides,
2941
+ showVersionFields,
2942
+ customFields
2943
+ )),
2944
+ categories: __spreadValues({}, hardConfig.categories || {})
2945
+ }),
2946
+ // ─── UI Flags ───────────────────────────────────────────────────────────
2947
+ setShowVersionFields: (show) => set({ showVersionFields: show }),
2948
+ // ─── Iframe ─────────────────────────────────────────────────────────────
2949
+ setIframeDoc: (doc) => set({
2950
+ iframeDoc: doc
2951
+ }),
2952
+ // ─── History ────────────────────────────────────────────────────────────
2953
+ storeHistory: (history) => set({ originalHistory: history }),
2954
+ removeHistory: () => set({ originalHistory: [] }),
2955
+ // ─── Item Selection ─────────────────────────────────────────────────────
2956
+ setItemSelector: (selector) => set({ itemSelector: selector }),
2957
+ setOriginalItem: (item) => set({ originalItem: item }),
2958
+ // ─── Editing State ──────────────────────────────────────────────────────
2959
+ setEditableComponentIds: (ids) => set({ editableComponentIds: ids }),
2960
+ addEditableComponentId: (id) => set((state) => {
2961
+ const newIds = new Set(state.editableComponentIds);
2962
+ newIds.add(id);
2963
+ return { editableComponentIds: newIds };
2964
+ }),
2965
+ clearEditingState: () => set({ editingComponentId: null, editableComponentIds: /* @__PURE__ */ new Set() }),
2966
+ // ─── Action Validation ──────────────────────────────────────────────────
2967
+ undoFn: null,
2968
+ setUndoFn: (fn) => set({ undoFn: fn }),
2969
+ validateAction: (action, previousAction) => {
2970
+ var _a;
2971
+ const { state, editableComponentIds, addEditableComponentId } = get();
2972
+ if (state === "ready") return true;
2973
+ if (action.type === "replace") {
2974
+ if ((previousAction == null ? void 0 : previousAction.type) === "insert" && (previousAction == null ? void 0 : previousAction.id) === action.data.props.id) {
2975
+ return true;
2925
2976
  }
2926
- const { state, editableComponentIds } = get();
2927
- if (state === "building") {
2928
- setEditVisibility(doc, {
2929
- mode: "build",
2930
- editableIds: editableComponentIds
2931
- });
2932
- return;
2977
+ const parentId = (_a = action.destinationZone) == null ? void 0 : _a.split(":")[0];
2978
+ if (action.data.props.id && editableComponentIds.has(action.data.props.id)) {
2979
+ return true;
2933
2980
  }
2934
- if (state === "remodeling") {
2935
- setEditVisibility(doc, {
2936
- mode: "remodel",
2937
- editableIds: editableComponentIds
2938
- });
2939
- return;
2981
+ if (parentId && editableComponentIds.has(parentId)) {
2982
+ addEditableComponentId(action.data.props.id);
2983
+ return true;
2940
2984
  }
2941
- clearEditVisibility(doc);
2942
- },
2943
- storeHistory: (history) => set({ originalHistory: history }),
2944
- removeHistory: () => set({ originalHistory: [] }),
2945
- itemSelector: null,
2946
- setItemSelector: (selector) => set({ itemSelector: selector }),
2947
- originalItem: null,
2948
- setOriginalItem: (item) => set({ originalItem: item }),
2949
- hydratedSoftComponents,
2950
- softComponents: hydratedSoftComponents,
2951
- dependencyGraph: initialDependencyGraph,
2952
- softConfig: __spreadProps(__spreadValues({}, hardConfig), {
2953
- components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
2954
- hardConfig,
2955
- hydratedSoftComponents,
2956
- overrides,
2957
- showVersionFields,
2958
- customFields
2959
- )),
2960
- categories: __spreadValues({}, hardConfig.categories || {})
2961
- }),
2962
- setSoftComponent: (name, version, component) => {
2963
- if (hardConfig.components && hardConfig.components[name]) {
2964
- console.warn(`Cannot set soft component "${name}" because it conflicts with a base hardConfig component.`);
2965
- return;
2985
+ return false;
2986
+ }
2987
+ if (action.type === "insert" || action.type === "duplicate") {
2988
+ const zone = action.type === "insert" ? action.destinationZone : action.sourceZone;
2989
+ const parentId = zone == null ? void 0 : zone.split(":")[0];
2990
+ const isEditable = parentId && editableComponentIds.has(parentId);
2991
+ if (!isEditable && action.type === "duplicate") return false;
2992
+ if (action.type === "insert" && action.id && isEditable) {
2993
+ addEditableComponentId(action.id);
2966
2994
  }
2967
- const existing = get().softComponents[name];
2968
- set((state) => {
2969
- var _a, _b;
2970
- return {
2971
- softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
2972
- [name]: __spreadProps(__spreadValues({}, existing), {
2973
- name: component.name || (existing == null ? void 0 : existing.name) || name,
2974
- category: (_a = component.category) != null ? _a : existing == null ? void 0 : existing.category,
2975
- defaultVersion: version,
2976
- versions: __spreadProps(__spreadValues({}, ((_b = state.softComponents[name]) == null ? void 0 : _b.versions) || {}), {
2977
- [version]: component
2978
- })
2995
+ }
2996
+ if (action.type === "remove" || action.type === "move" || action.type === "reorder") {
2997
+ const zone = action.type === "remove" ? action.zone : action.destinationZone;
2998
+ const parentId = zone == null ? void 0 : zone.split(":")[0];
2999
+ if (parentId && !editableComponentIds.has(parentId)) return false;
3000
+ return true;
3001
+ }
3002
+ return true;
3003
+ },
3004
+ // ─── Soft Component CRUD ─────────────────────────────────────────────────
3005
+ setSoftComponent: (name, version, component) => {
3006
+ var _a;
3007
+ if ((_a = hardConfig.components) == null ? void 0 : _a[name]) {
3008
+ console.warn(
3009
+ `Cannot set soft component "${name}" because it conflicts with a hardConfig component.`
3010
+ );
3011
+ return;
3012
+ }
3013
+ const existing = get().softComponents[name];
3014
+ set((state) => {
3015
+ var _a2, _b;
3016
+ return {
3017
+ softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3018
+ [name]: __spreadProps(__spreadValues({}, existing), {
3019
+ name: component.name || (existing == null ? void 0 : existing.name) || name,
3020
+ category: (_a2 = component.category) != null ? _a2 : existing == null ? void 0 : existing.category,
3021
+ defaultVersion: version,
3022
+ versions: __spreadProps(__spreadValues({}, ((_b = state.softComponents[name]) == null ? void 0 : _b.versions) || {}), {
3023
+ [version]: component
2979
3024
  })
2980
3025
  })
2981
- };
2982
- });
2983
- },
2984
- setSoftComponents: (incomingComponents) => {
2985
- const state = get();
2986
- const nextSoftComponents = __spreadValues({}, state.softComponents);
2987
- const nextConfigComponents = __spreadValues({}, state.softConfig.components);
2988
- Object.entries(incomingComponents).forEach(([name, data]) => {
2989
- if (hardConfig.components && hardConfig.components[name]) {
2990
- return;
2991
- }
2992
- const existing = nextSoftComponents[name];
2993
- const finalComponentData = existing ? __spreadProps(__spreadValues(__spreadValues({}, existing), data), {
2994
- name: data.name || existing.name || name,
2995
- versions: __spreadValues(__spreadValues({}, existing.versions), data.versions)
2996
- }) : data;
2997
- finalComponentData.name = finalComponentData.name || name;
2998
- nextSoftComponents[name] = finalComponentData;
2999
- const activeVersion = finalComponentData.defaultVersion;
3000
- const activeVersionData = finalComponentData.versions[activeVersion];
3001
- if (activeVersionData) {
3002
- nextConfigComponents[name] = createVersionedComponentConfig(
3003
- name,
3004
- finalComponentData.name || name,
3005
- activeVersion,
3006
- Object.keys(finalComponentData.versions),
3007
- state.softConfig,
3008
- nextSoftComponents,
3009
- activeVersionData.defaultProps,
3010
- state.showVersionFields,
3011
- state.customFields
3012
- );
3013
- }
3014
- });
3015
- set({
3016
- softComponents: nextSoftComponents,
3017
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3018
- components: nextConfigComponents
3019
- })
3020
- });
3021
- },
3022
- hydrateTransforms: () => {
3023
- const { overrides: overrides2, softComponents: softComponents2, softConfig } = get();
3024
- if (!(overrides2 == null ? void 0 : overrides2.hydrateMapTransform)) return;
3025
- const hydratedComponents = hydrateSoftComponentsTransforms(
3026
- softComponents2,
3027
- overrides2.hydrateMapTransform
3028
- );
3029
- const nextConfigComponents = __spreadValues({}, softConfig.components);
3030
- Object.entries(hydratedComponents).forEach(([name, componentData]) => {
3031
- const activeVersion = componentData.defaultVersion;
3032
- const activeVersionData = componentData.versions[activeVersion];
3033
- if (activeVersionData) {
3034
- nextConfigComponents[name] = createVersionedComponentConfig(
3035
- name,
3036
- componentData.name || name,
3037
- activeVersion,
3038
- Object.keys(componentData.versions),
3039
- softConfig,
3040
- hydratedComponents,
3041
- activeVersionData.defaultProps,
3042
- get().showVersionFields,
3043
- get().customFields
3044
- );
3045
- }
3046
- });
3047
- set({
3048
- softComponents: hydratedComponents,
3049
- softConfig: __spreadProps(__spreadValues({}, softConfig), {
3050
- components: nextConfigComponents
3051
3026
  })
3052
- });
3053
- },
3054
- setSoftComponentDefaultVersion: (name, version) => {
3055
- var _a, _b, _c, _d;
3056
- const softComponent = (_b = (_a = get().softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
3057
- const allVersions = Object.keys(
3058
- ((_c = get().softComponents[name]) == null ? void 0 : _c.versions) || {}
3059
- );
3060
- const displayName = ((_d = get().softComponents[name]) == null ? void 0 : _d.name) || name;
3061
- if (!softComponent) {
3062
- throw new Error(
3063
- `Soft component "${name}" version "${version}" does not exist.`
3027
+ };
3028
+ });
3029
+ },
3030
+ setSoftComponents: (incomingComponents) => {
3031
+ const state = get();
3032
+ const nextSoftComponents = __spreadValues({}, state.softComponents);
3033
+ const nextConfigComponents = __spreadValues({}, state.softConfig.components);
3034
+ Object.entries(incomingComponents).forEach(([name, data]) => {
3035
+ var _a;
3036
+ if ((_a = hardConfig.components) == null ? void 0 : _a[name]) return;
3037
+ const existing = nextSoftComponents[name];
3038
+ const merged = existing ? __spreadProps(__spreadValues(__spreadValues({}, existing), data), {
3039
+ name: data.name || existing.name || name,
3040
+ versions: __spreadValues(__spreadValues({}, existing.versions), data.versions)
3041
+ }) : data;
3042
+ merged.name = merged.name || name;
3043
+ nextSoftComponents[name] = merged;
3044
+ const activeVersion = merged.defaultVersion;
3045
+ const activeVersionData = merged.versions[activeVersion];
3046
+ if (activeVersionData) {
3047
+ nextConfigComponents[name] = createVersionedComponentConfig(
3048
+ name,
3049
+ merged.name,
3050
+ activeVersion,
3051
+ Object.keys(merged.versions),
3052
+ state.softConfig,
3053
+ nextSoftComponents,
3054
+ activeVersionData.defaultProps,
3055
+ state.showVersionFields,
3056
+ state.customFields
3064
3057
  );
3065
3058
  }
3066
- const newSoftComponentConfig = createVersionedComponentConfig(
3067
- name,
3068
- displayName,
3069
- version,
3070
- allVersions,
3071
- get().softConfig,
3072
- get().softComponents,
3073
- softComponent.defaultProps,
3074
- get().showVersionFields,
3075
- get().customFields
3059
+ });
3060
+ set({
3061
+ softComponents: nextSoftComponents,
3062
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), { components: nextConfigComponents })
3063
+ });
3064
+ },
3065
+ hydrateTransforms: () => {
3066
+ const { overrides: overrides2, softComponents: softComponents2, softConfig } = get();
3067
+ if (!(overrides2 == null ? void 0 : overrides2.hydrateMapTransform)) return;
3068
+ const hydratedComponents = hydrateSoftComponentsTransforms(
3069
+ softComponents2,
3070
+ overrides2.hydrateMapTransform
3071
+ );
3072
+ const nextConfigComponents = __spreadValues({}, softConfig.components);
3073
+ Object.entries(hydratedComponents).forEach(([name, componentData]) => {
3074
+ const activeVersion = componentData.defaultVersion;
3075
+ const activeVersionData = componentData.versions[activeVersion];
3076
+ if (activeVersionData) {
3077
+ nextConfigComponents[name] = createVersionedComponentConfig(
3078
+ name,
3079
+ componentData.name || name,
3080
+ activeVersion,
3081
+ Object.keys(componentData.versions),
3082
+ softConfig,
3083
+ hydratedComponents,
3084
+ activeVersionData.defaultProps,
3085
+ get().showVersionFields,
3086
+ get().customFields
3087
+ );
3088
+ }
3089
+ });
3090
+ set({
3091
+ softComponents: hydratedComponents,
3092
+ softConfig: __spreadProps(__spreadValues({}, softConfig), { components: nextConfigComponents })
3093
+ });
3094
+ },
3095
+ setSoftComponentDefaultVersion: (name, version) => {
3096
+ var _a, _b, _c, _d;
3097
+ const state = get();
3098
+ const softComponent = (_b = (_a = state.softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
3099
+ if (!softComponent) {
3100
+ throw new Error(
3101
+ `Soft component "${name}" version "${version}" does not exist.`
3076
3102
  );
3077
- set((state) => ({
3078
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3079
- components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3080
- [name]: newSoftComponentConfig
3081
- })
3082
- }),
3103
+ }
3104
+ const allVersions = Object.keys(
3105
+ ((_c = state.softComponents[name]) == null ? void 0 : _c.versions) || {}
3106
+ );
3107
+ const displayName = ((_d = state.softComponents[name]) == null ? void 0 : _d.name) || name;
3108
+ const newConfig = createVersionedComponentConfig(
3109
+ name,
3110
+ displayName,
3111
+ version,
3112
+ allVersions,
3113
+ state.softConfig,
3114
+ state.softComponents,
3115
+ softComponent.defaultProps,
3116
+ state.showVersionFields,
3117
+ state.customFields
3118
+ );
3119
+ set((s) => ({
3120
+ softConfig: __spreadProps(__spreadValues({}, s.softConfig), {
3121
+ components: __spreadProps(__spreadValues({}, s.softConfig.components), { [name]: newConfig })
3122
+ }),
3123
+ softComponents: __spreadProps(__spreadValues({}, s.softComponents), {
3124
+ [name]: __spreadProps(__spreadValues({}, s.softComponents[name]), { defaultVersion: version })
3125
+ })
3126
+ }));
3127
+ },
3128
+ removeSoftComponentVersion: (key, version) => {
3129
+ set((state) => {
3130
+ const component = state.softComponents[key];
3131
+ if (!component) return {};
3132
+ const newVersions = Object.fromEntries(
3133
+ Object.entries(component.versions || {}).filter(
3134
+ ([k]) => k !== version
3135
+ )
3136
+ );
3137
+ let newDefaultVersion = component.defaultVersion;
3138
+ if (component.defaultVersion === version) {
3139
+ const versionKeys = Object.keys(newVersions);
3140
+ newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
3141
+ }
3142
+ return {
3083
3143
  softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3084
- [name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
3085
- defaultVersion: version
3144
+ [key]: __spreadProps(__spreadValues({}, component), {
3145
+ versions: newVersions,
3146
+ defaultVersion: newDefaultVersion
3086
3147
  })
3087
3148
  })
3088
- }));
3089
- },
3090
- removeSoftComponentVersion: (key, version) => {
3091
- set((state) => {
3092
- const component = state.softComponents[key];
3093
- if (!component) return {};
3094
- const newVersions = Object.fromEntries(
3095
- Object.entries(component.versions || {}).filter(
3096
- ([k, _]) => k !== version
3097
- )
3098
- );
3099
- let newDefaultVersion = component.defaultVersion;
3100
- if (component.defaultVersion === version) {
3101
- const versionKeys = Object.keys(newVersions);
3102
- newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
3103
- }
3104
- return {
3105
- softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3106
- [key]: __spreadProps(__spreadValues({}, component), {
3107
- versions: newVersions,
3108
- defaultVersion: newDefaultVersion
3109
- })
3110
- })
3111
- };
3112
- });
3113
- },
3114
- removeSoftComponent: (key) => {
3115
- set((state) => ({
3116
- softComponents: Object.fromEntries(
3117
- Object.entries(state.softComponents).filter(([k, _]) => k !== key)
3118
- )
3119
- }));
3120
- },
3121
- setSoftComponentConfig: (key, config, category) => {
3122
- set((state) => {
3123
- var _a, _b, _c;
3124
- return {
3125
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3126
- components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3127
- [key]: __spreadValues({}, config)
3128
- }),
3129
- categories: category ? __spreadProps(__spreadValues({}, state.softConfig.categories || {}), {
3130
- [category]: __spreadProps(__spreadValues({}, ((_a = state.softConfig.categories) == null ? void 0 : _a[category]) || {}), {
3131
- components: [
3132
- ...((_c = (_b = state.softConfig.categories) == null ? void 0 : _b[category]) == null ? void 0 : _c.components) || [],
3133
- key
3134
- ]
3135
- })
3136
- }) : state.softConfig.categories || {}
3137
- })
3138
- };
3139
- });
3140
- },
3141
- removeSoftComponentConfig: (key) => {
3142
- set((state) => ({
3149
+ };
3150
+ });
3151
+ },
3152
+ removeSoftComponent: (key) => set((state) => ({
3153
+ softComponents: Object.fromEntries(
3154
+ Object.entries(state.softComponents).filter(([k]) => k !== key)
3155
+ )
3156
+ })),
3157
+ setSoftComponentConfig: (key, config, category) => {
3158
+ set((state) => {
3159
+ var _a, _b, _c;
3160
+ return {
3143
3161
  softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3144
- components: Object.fromEntries(
3145
- Object.entries(state.softConfig.components).filter(
3146
- ([k, _]) => k !== key
3147
- )
3148
- )
3149
- })
3150
- }));
3151
- },
3152
- setSoftCategoryConfig: (key, category) => {
3153
- set((state) => {
3154
- var _a;
3155
- return {
3156
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3157
- categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
3158
- [key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
3162
+ components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3163
+ [key]: __spreadValues({}, config)
3164
+ }),
3165
+ categories: category ? __spreadProps(__spreadValues({}, state.softConfig.categories || {}), {
3166
+ [category]: __spreadProps(__spreadValues({}, ((_a = state.softConfig.categories) == null ? void 0 : _a[category]) || {}), {
3167
+ components: [
3168
+ ...((_c = (_b = state.softConfig.categories) == null ? void 0 : _b[category]) == null ? void 0 : _c.components) || [],
3169
+ key
3170
+ ]
3159
3171
  })
3160
- })
3161
- };
3162
- });
3163
- },
3164
- removeSoftCategoryConfig: (key) => {
3165
- set((state) => ({
3166
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3167
- categories: Object.fromEntries(
3168
- Object.entries(state.softConfig.categories || {}).filter(
3169
- ([k, _]) => k !== key
3170
- )
3171
- )
3172
+ }) : state.softConfig.categories || {}
3172
3173
  })
3173
- }));
3174
- },
3175
- builder: createBuildersSlice(set, get, hardConfig),
3176
- editingComponentId: null,
3177
- editableComponentIds: /* @__PURE__ */ new Set(),
3178
- setEditableComponentIds: (ids) => set({ editableComponentIds: ids }),
3179
- addEditableComponentId: (id) => {
3180
- set((state) => {
3181
- const newIds = new Set(state.editableComponentIds);
3182
- newIds.add(id);
3183
- return { editableComponentIds: newIds };
3184
- });
3185
- },
3186
- clearEditingState: () => set({
3187
- editingComponentId: null,
3188
- editableComponentIds: /* @__PURE__ */ new Set()
3189
- }),
3190
- rebuildDependents: (componentName, version) => {
3191
- const state = get();
3192
- const dependents = state.dependencyGraph.get(componentName) || /* @__PURE__ */ new Set();
3193
- if (dependents.size === 0) return;
3194
- const config = __spreadValues({}, state.softConfig);
3195
- const softComponents2 = state.softComponents;
3196
- const toBuild = Array.from(dependents);
3197
- for (const dependentName of toBuild) {
3198
- const dependent = softComponents2[dependentName];
3199
- const defaultVersion = dependent.defaultVersion || Object.keys(dependent.versions || {}).pop();
3200
- if (!defaultVersion) continue;
3201
- const versionedComponent = dependent.versions[defaultVersion];
3202
- const allVersions = Object.keys(dependent.versions || {});
3203
- if (!versionedComponent) continue;
3204
- const newConfig = createVersionedComponentConfig(
3205
- dependentName,
3206
- dependent.name || dependentName,
3207
- defaultVersion,
3208
- allVersions,
3209
- config,
3210
- softComponents2,
3211
- versionedComponent.defaultProps,
3212
- state.showVersionFields,
3213
- state.customFields
3214
- );
3215
- config.components[dependentName] = newConfig;
3216
- }
3217
- set((s) => __spreadProps(__spreadValues({}, s), { softConfig: config }));
3174
+ };
3175
+ });
3176
+ },
3177
+ removeSoftComponentConfig: (key) => set((state) => ({
3178
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3179
+ components: Object.fromEntries(
3180
+ Object.entries(state.softConfig.components).filter(
3181
+ ([k]) => k !== key
3182
+ )
3183
+ )
3184
+ })
3185
+ })),
3186
+ setSoftCategoryConfig: (key, category) => set((state) => {
3187
+ var _a;
3188
+ return {
3189
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3190
+ categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
3191
+ [key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
3192
+ })
3193
+ })
3194
+ };
3195
+ }),
3196
+ removeSoftCategoryConfig: (key) => set((state) => ({
3197
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3198
+ categories: Object.fromEntries(
3199
+ Object.entries(state.softConfig.categories || {}).filter(
3200
+ ([k]) => k !== key
3201
+ )
3202
+ )
3203
+ })
3204
+ })),
3205
+ // ─── Builder Slice ────────────────────────────────────────────────────────
3206
+ builder: createBuildersSlice(set, get, hardConfig),
3207
+ // ─── Dependency Graph ─────────────────────────────────────────────────────
3208
+ rebuildDependents: (componentName) => {
3209
+ const state = get();
3210
+ const dependents = state.dependencyGraph.get(componentName) || /* @__PURE__ */ new Set();
3211
+ if (dependents.size === 0) return;
3212
+ const nextConfig = __spreadValues({}, state.softConfig);
3213
+ const { softComponents: softComponents2 } = state;
3214
+ for (const dependentName of Array.from(dependents)) {
3215
+ const dependent = softComponents2[dependentName];
3216
+ const defaultVersion = dependent.defaultVersion || Object.keys(dependent.versions || {}).pop();
3217
+ if (!defaultVersion) continue;
3218
+ const versionedComponent = dependent.versions[defaultVersion];
3219
+ if (!versionedComponent) continue;
3220
+ nextConfig.components[dependentName] = createVersionedComponentConfig(
3221
+ dependentName,
3222
+ dependent.name || dependentName,
3223
+ defaultVersion,
3224
+ Object.keys(dependent.versions || {}),
3225
+ nextConfig,
3226
+ softComponents2,
3227
+ versionedComponent.defaultProps,
3228
+ state.showVersionFields,
3229
+ state.customFields
3230
+ );
3218
3231
  }
3219
- })
3220
- )
3232
+ set((s) => __spreadProps(__spreadValues({}, s), { softConfig: nextConfig }));
3233
+ }
3234
+ }))
3221
3235
  );
3222
3236
  };
3223
3237
 
@@ -3234,8 +3248,8 @@ var SoftConfigProvider = ({
3234
3248
  onActions,
3235
3249
  useVersioning = false
3236
3250
  }) => {
3237
- const store = value != null ? value : useMemo2(
3238
- () => createSoftConfigStore(
3251
+ const store = useMemo2(
3252
+ () => value != null ? value : createSoftConfigStore(
3239
3253
  hardConfig,
3240
3254
  softComponents,
3241
3255
  overrides,
@@ -3243,109 +3257,26 @@ var SoftConfigProvider = ({
3243
3257
  useVersioning,
3244
3258
  customFields
3245
3259
  ),
3246
- [
3247
- hardConfig,
3248
- softComponents,
3249
- overrides,
3250
- onActions,
3251
- useVersioning,
3252
- customFields
3253
- ]
3260
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3261
+ [value]
3262
+ // Intentionally omitting the rest: createSoftConfigStore params are
3263
+ // treated as initialisation-time values. If callers need to react to
3264
+ // prop changes they should pass a new `value` store instead.
3254
3265
  );
3255
3266
  const [softConfig, setSoftConfig] = useState(
3256
3267
  () => store.getState().softConfig
3257
3268
  );
3258
- const [internalSoftComponents, setSoftComponents] = useState(
3259
- () => store.getState().softComponents
3260
- );
3261
- const storeSetIframeDoc = useMemo2(
3262
- () => store.getState().setIframeDoc,
3263
- [store]
3264
- );
3265
- const validateAction = useMemo2(
3266
- () => (action) => {
3267
- var _a;
3268
- const currentState = store.getState();
3269
- if (currentState.state === "ready") {
3270
- return true;
3271
- }
3272
- const editableIds = currentState.editableComponentIds;
3273
- if (action.type === "replace") {
3274
- const parentId = (_a = action.destinationZone) == null ? void 0 : _a.split(":")[0];
3275
- if (action.data.props.id && editableIds.has(action.data.props.id)) {
3276
- return true;
3277
- } else if (parentId && editableIds.has(parentId)) {
3278
- currentState.addEditableComponentId(action.data.props.id);
3279
- return true;
3280
- }
3281
- return false;
3282
- }
3283
- if (action.type === "insert" || action.type === "duplicate") {
3284
- const zone = action.type === "insert" ? action.destinationZone : action.sourceZone;
3285
- const parentId = zone == null ? void 0 : zone.split(":")[0];
3286
- if (parentId && !editableIds.has(parentId)) {
3287
- return false;
3288
- }
3289
- if (action.type === "insert") {
3290
- const childId = action.id;
3291
- if (childId) {
3292
- currentState.addEditableComponentId(childId);
3293
- }
3294
- }
3295
- return true;
3296
- }
3297
- if (action.type === "remove" || action.type === "move" || action.type === "reorder") {
3298
- let parentId;
3299
- if (action.type === "remove") {
3300
- parentId = action.zone.split(":")[0];
3301
- } else if (action.type === "move" || action.type === "reorder") {
3302
- parentId = action.destinationZone.split(":")[0];
3303
- }
3304
- if (parentId && !editableIds.has(parentId)) {
3305
- return false;
3306
- }
3307
- return true;
3308
- }
3309
- return true;
3310
- },
3311
- [store]
3312
- );
3313
- useEffect2(() => {
3314
- const unsubscribe = store.subscribe(() => {
3315
- setSoftConfig(store.getState().softConfig);
3316
- setSoftComponents(store.getState().softComponents);
3317
- });
3318
- return () => {
3319
- unsubscribe();
3320
- };
3321
- }, [store]);
3322
3269
  useEffect2(() => {
3323
- const unsubscribe = store.subscribe((state, prevState) => {
3324
- if (prevState && state.state === prevState.state && state.editableComponentIds === prevState.editableComponentIds) {
3325
- return;
3326
- }
3327
- const doc = store.getState().getIframeDoc();
3328
- if (!doc) return;
3329
- if (state.state === "building") {
3330
- setEditVisibility(doc, { mode: "build", editableIds: state.editableComponentIds });
3331
- return;
3270
+ let prev = store.getState().softConfig;
3271
+ const unsubscribe = store.subscribe((state) => {
3272
+ if (state.softConfig !== prev) {
3273
+ prev = state.softConfig;
3274
+ setSoftConfig(state.softConfig);
3332
3275
  }
3333
- if (state.state === "remodeling") {
3334
- setEditVisibility(doc, { mode: "remodel", editableIds: state.editableComponentIds });
3335
- return;
3336
- }
3337
- requestAnimationFrame(() => {
3338
- const freshDoc = store.getState().getIframeDoc();
3339
- if (freshDoc) {
3340
- clearEditVisibility(freshDoc);
3341
- }
3342
- });
3343
3276
  });
3344
- return () => {
3345
- unsubscribe();
3346
- };
3277
+ return unsubscribe;
3347
3278
  }, [store]);
3348
- return /* @__PURE__ */ jsx7(appStoreContext.Provider, { value: store, children: children(softConfig, internalSoftComponents, storeSetIframeDoc, validateAction) });
3279
+ return /* @__PURE__ */ jsx7(appStoreContext.Provider, { value: store, children: children(softConfig) });
3349
3280
  };
3350
3281
 
3351
3282
  // src/puck/actions/useBuild.tsx
@@ -3751,7 +3682,7 @@ var useSetDefaultVersion = () => {
3751
3682
  // src/puck/overrides/Header.tsx
3752
3683
  import { Button, createUsePuck as createUsePuck10 } from "@measured/puck";
3753
3684
 
3754
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Header.module.css#css-module
3685
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Header.module.css#css-module
3755
3686
  var Header_module_default = { "Header": "_Header_19oj9_1" };
3756
3687
 
3757
3688
  // src/puck/actions/usePublish.tsx
@@ -3800,7 +3731,6 @@ var Header = ({
3800
3731
  const { handleComplete, newComponent, setNewComponent } = useComplete();
3801
3732
  const { handleCancel, canCancel } = useCancel();
3802
3733
  const { handlePublish } = usePublish();
3803
- const puck = usePuck((s) => s.config);
3804
3734
  useInspect(newComponent);
3805
3735
  return /* @__PURE__ */ jsx8("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
3806
3736
  /* @__PURE__ */ jsx8(Button, { onClick: handleCancel, children: "Cancel" }),
@@ -3836,7 +3766,7 @@ import { useMemo as useMemo3 } from "react";
3836
3766
  import { ActionBar, createUsePuck as createUsePuck11 } from "@measured/puck";
3837
3767
  import { Combine, ComponentIcon, EditIcon } from "lucide-react";
3838
3768
 
3839
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
3769
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
3840
3770
  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" };
3841
3771
 
3842
3772
  // src/puck/overrides/ActionBar.tsx
@@ -3862,7 +3792,7 @@ var ActionBarOverride = (props) => {
3862
3792
  if (selectedType && softKeys.includes(selectedType)) {
3863
3793
  return selectedType;
3864
3794
  }
3865
- return createComponentKeyFromName(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3795
+ return componentNameFromLabel(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3866
3796
  existingKeys: softKeys,
3867
3797
  state: status
3868
3798
  }));
@@ -3878,17 +3808,17 @@ var ActionBarOverride = (props) => {
3878
3808
  const selectedId = (_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.id;
3879
3809
  const parentId = (_b = itemSelector == null ? void 0 : itemSelector.zone) == null ? void 0 : _b.split(":")[0];
3880
3810
  const isEditable = Boolean(selectedId && (editableIds.has(selectedId) || parentId && editableIds.has(parentId)));
3881
- const displayName = useMemo3(() => {
3811
+ const label = useMemo3(() => {
3882
3812
  var _a2;
3883
3813
  if (isSoftComponent2) {
3884
- return ((_a2 = softComponents[key]) == null ? void 0 : _a2.name) || getComponentNameFromKey(key, overrides);
3814
+ return ((_a2 = softComponents[key]) == null ? void 0 : _a2.name) || componentLabelFromName(key, overrides);
3885
3815
  }
3886
3816
  return props.label || "";
3887
3817
  }, [isSoftComponent2, key, props.label, overrides, softComponents]);
3888
3818
  return /* @__PURE__ */ jsx9("div", { className: getClassName3(), children: /* @__PURE__ */ jsxs3(ActionBar, { children: [
3889
3819
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3890
3820
  props.parentAction,
3891
- /* @__PURE__ */ jsx9(ActionBar.Label, { label: displayName })
3821
+ /* @__PURE__ */ jsx9(ActionBar.Label, { label })
3892
3822
  ] }),
3893
3823
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3894
3824
  status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(Fragment4, { children: [
@@ -3943,14 +3873,14 @@ var confirm = (message) => __async(null, null, function* () {
3943
3873
  }
3944
3874
  });
3945
3875
 
3946
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/DrawerItem.module.css#css-module
3876
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/DrawerItem.module.css#css-module
3947
3877
  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" };
3948
3878
 
3949
3879
  // src/puck/components/modal/index.tsx
3950
3880
  import { useEffect as useEffect4, useState as useState3 } from "react";
3951
3881
  import { createPortal } from "react-dom";
3952
3882
 
3953
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
3883
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
3954
3884
  var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
3955
3885
 
3956
3886
  // src/puck/components/modal/index.tsx
@@ -4185,6 +4115,7 @@ var DrawerItem = (props) => {
4185
4115
  return /* @__PURE__ */ jsxs4(
4186
4116
  "button",
4187
4117
  {
4118
+ "aria-label": target.label,
4188
4119
  type: "button",
4189
4120
  role: "radio",
4190
4121
  "aria-checked": isSelected,
@@ -4235,7 +4166,7 @@ import { useState as useState5 } from "react";
4235
4166
  import { createUsePuck as createUsePuck13, Drawer as PuckDrawer } from "@measured/puck";
4236
4167
  import { ChevronDown, ChevronUp } from "lucide-react";
4237
4168
 
4238
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
4169
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
4239
4170
  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" };
4240
4171
 
4241
4172
  // src/puck/overrides/Drawer.tsx
@@ -4347,23 +4278,51 @@ var Drawer = (_props) => {
4347
4278
  ] });
4348
4279
  };
4349
4280
 
4281
+ // src/puck/overrides/HeaderActions.tsx
4282
+ import { Button as Button3, createUsePuck as createUsePuck14 } from "@measured/puck";
4283
+ import { Fragment as Fragment6, jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
4284
+ var usePuck5 = createUsePuck14();
4285
+ var HeaderActions = ({ children }) => {
4286
+ const { handleComplete } = useComplete();
4287
+ const { handleCancel, canCancel } = useCancel();
4288
+ const dispatch = usePuck5((s) => s.dispatch);
4289
+ const inspect = useSoftConfig((s) => s.builder.inspect);
4290
+ return /* @__PURE__ */ jsx13(Fragment6, { children: canCancel ? /* @__PURE__ */ jsxs6(Fragment6, { children: [
4291
+ /* @__PURE__ */ jsx13(Button3, { onClick: handleCancel, children: "Cancel" }),
4292
+ /* @__PURE__ */ jsx13(
4293
+ Button3,
4294
+ {
4295
+ variant: "primary",
4296
+ onClick: () => {
4297
+ const completedComponent = handleComplete();
4298
+ if (completedComponent) {
4299
+ try {
4300
+ inspect(completedComponent.id, dispatch);
4301
+ } catch (error) {
4302
+ notify.error(
4303
+ "Failed to inspect after completion: " + (error instanceof Error ? error.message : String(error))
4304
+ );
4305
+ }
4306
+ }
4307
+ },
4308
+ children: "Complete"
4309
+ }
4310
+ )
4311
+ ] }) : children });
4312
+ };
4313
+
4350
4314
  // src/puck/lib/action-callback.ts
4351
4315
  var createActionCallback = (validateAction, undo) => {
4352
4316
  return (action) => {
4317
+ if (!undo) {
4318
+ return;
4319
+ }
4353
4320
  const isValid = validateAction(action);
4354
4321
  if (!isValid) {
4355
4322
  notify.error(
4356
4323
  "Editing outside the soft component is not allowed when you are editing component definition."
4357
4324
  );
4358
- if (typeof requestAnimationFrame === "function") {
4359
- requestAnimationFrame(() => {
4360
- requestAnimationFrame(() => {
4361
- undo();
4362
- });
4363
- });
4364
- } else {
4365
- setTimeout(() => undo(), 0);
4366
- }
4325
+ requestAnimationFrame(() => undo());
4367
4326
  }
4368
4327
  };
4369
4328
  };
@@ -4576,6 +4535,7 @@ export {
4576
4535
  Drawer,
4577
4536
  DrawerItem,
4578
4537
  Header,
4538
+ HeaderActions,
4579
4539
  Modal,
4580
4540
  SoftConfigProvider,
4581
4541
  applyMapping,
@@ -4600,5 +4560,6 @@ export {
4600
4560
  useInspect,
4601
4561
  useRemodel,
4602
4562
  useSetDefaultVersion,
4603
- useSoftConfig
4563
+ useSoftConfig,
4564
+ useSoftConfigStore
4604
4565
  };