@netlisian/softconfig 0.1.5 → 0.1.7

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.
@@ -1063,7 +1063,7 @@ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (op
1063
1063
  };
1064
1064
  var get_class_name_factory_default = getClassNameFactory;
1065
1065
 
1066
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1066
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1067
1067
  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
1068
 
1069
1069
  // src/puck/components/error-boundary/index.tsx
@@ -1586,21 +1586,21 @@ import { v4 as uuidv4 } from "uuid";
1586
1586
  var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
1587
1587
 
1588
1588
  // src/puck/lib/component-key.ts
1589
- var defaultToCamelCase = (value) => {
1590
- const tokens = value.trim().replace(/[^a-zA-Z0-9\s_-]/g, " ").split(/[\s_-]+/).filter(Boolean);
1591
- if (tokens.length === 0) return "";
1592
- const [first, ...rest] = tokens;
1593
- return `${first.toLowerCase()}${rest.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join("")}`;
1589
+ var toSlug = (value) => {
1590
+ 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, "");
1594
1591
  };
1595
- var createComponentKeyFromName = (displayName, overrides, context) => {
1596
- const key = overrides.componentNameToKey ? overrides.componentNameToKey(displayName, context) : defaultToCamelCase(displayName);
1592
+ var slugTolabel = (name) => {
1593
+ return name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1594
+ };
1595
+ var componentNameFromLabel = (label, overrides, context) => {
1596
+ const key = overrides.componentLabelToName ? overrides.componentLabelToName(label, context) : toSlug(label);
1597
1597
  return key.trim();
1598
1598
  };
1599
- var getComponentNameFromKey = (key, overrides) => {
1600
- if (overrides == null ? void 0 : overrides.componentKeyToName) {
1601
- return overrides.componentKeyToName(key);
1599
+ var componentLabelFromName = (name, overrides) => {
1600
+ if (overrides == null ? void 0 : overrides.componentNameToLabel) {
1601
+ return overrides.componentNameToLabel(name);
1602
1602
  }
1603
- return key;
1603
+ return slugTolabel(name);
1604
1604
  };
1605
1605
 
1606
1606
  // src/puck/lib/soft-component-to-appstate.ts
@@ -1796,7 +1796,7 @@ var softComponentToAppState = (softComponent, componentName, version, versions,
1796
1796
  mergedFieldSettings[field.name] = settings;
1797
1797
  });
1798
1798
  let rootProps = __spreadValues({
1799
- _name: displayName || getComponentNameFromKey(componentName, overrides),
1799
+ _name: displayName || componentLabelFromName(componentName, overrides),
1800
1800
  _category: category,
1801
1801
  _version: version,
1802
1802
  _versions: versions,
@@ -1999,17 +1999,14 @@ var hydrateCustomField = (fieldName, field, fieldSettings, customFields) => {
1999
1999
  label: field.label || customField.field.label || fieldName
2000
2000
  });
2001
2001
  };
2002
- var createVersionedComponentConfig = (componentName, displayName, version, allVersions, config, softComponents, defaultProps, showVersioning = true, customFields) => {
2002
+ var createVersionedComponentConfig = (componentName, displayName, version, allVersions, config, softComponents, defaultProps, showVersioning = true, customFields, overrides) => {
2003
2003
  var _a, _b;
2004
- const softConfig = config;
2005
2004
  return {
2006
2005
  label: displayName,
2007
2006
  fields: Object.fromEntries(
2008
2007
  (Object.entries(
2009
2008
  (_b = (_a = softComponents[componentName].versions) == null ? void 0 : _a[version]) == null ? void 0 : _b.fields
2010
- ) || []).filter(
2011
- ([key, field]) => field.type === "slot"
2012
- ).map(([key, field]) => [key, __spreadValues({}, field)])
2009
+ ) || []).filter(([key, field]) => field.type === "slot").map(([key, field]) => [key, __spreadValues({}, field)])
2013
2010
  ),
2014
2011
  defaultProps: __spreadProps(__spreadValues({}, defaultProps), {
2015
2012
  version
@@ -2046,7 +2043,7 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
2046
2043
  softComponentFields: versionedComponent.fields,
2047
2044
  softComponentFieldSettings: versionedComponent.fieldSettings,
2048
2045
  softSubComponent: versionedComponent.components,
2049
- configComponents: softConfig.components,
2046
+ configComponents: config.components,
2050
2047
  props
2051
2048
  }
2052
2049
  );
@@ -2172,6 +2169,61 @@ function demolishSoftComponent(componentName, data, config, softComponents) {
2172
2169
  };
2173
2170
  }
2174
2171
 
2172
+ // src/puck/lib/edit-visibility-utils.ts
2173
+ var setEditVisibility = (doc, context) => {
2174
+ if (!doc) return;
2175
+ try {
2176
+ const root = doc.documentElement;
2177
+ if (context.mode === "none") {
2178
+ root.removeAttribute("data-edit-mode");
2179
+ root.classList.remove("edit-visibility-mode");
2180
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2181
+ el.removeAttribute("data-edit-visibility");
2182
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2183
+ });
2184
+ } else {
2185
+ root.setAttribute("data-edit-mode", context.mode);
2186
+ root.classList.add("edit-visibility-mode");
2187
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2188
+ var _a;
2189
+ const id = el.getAttribute("data-puck-component");
2190
+ if (!id) return;
2191
+ const isEditable = context.editableIds.has(id);
2192
+ const isDependency = (_a = context.highlightDependencyIds) == null ? void 0 : _a.has(id);
2193
+ if (isEditable) {
2194
+ el.setAttribute("data-edit-visibility", "editable");
2195
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-dependency");
2196
+ el.classList.add("edit-visibility-editable");
2197
+ } else if (isDependency) {
2198
+ el.setAttribute("data-edit-visibility", "dependency");
2199
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable");
2200
+ el.classList.add("edit-visibility-dependency");
2201
+ } else {
2202
+ el.setAttribute("data-edit-visibility", "greyed");
2203
+ el.classList.remove("edit-visibility-editable", "edit-visibility-dependency");
2204
+ el.classList.add("edit-visibility-greyed");
2205
+ }
2206
+ });
2207
+ }
2208
+ } catch (error) {
2209
+ console.warn(`Failed to set edit visibility:`, error);
2210
+ }
2211
+ };
2212
+ var clearEditVisibility = (doc) => {
2213
+ if (!doc) return;
2214
+ try {
2215
+ const root = doc.documentElement;
2216
+ root.removeAttribute("data-edit-mode");
2217
+ root.classList.remove("edit-visibility-mode");
2218
+ doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2219
+ el.removeAttribute("data-edit-visibility");
2220
+ el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2221
+ });
2222
+ } catch (error) {
2223
+ console.warn(`Failed to clear edit visibility:`, error);
2224
+ }
2225
+ };
2226
+
2175
2227
  // src/puck/store/slices/builder.tsx
2176
2228
  var createBuildersSlice = (set, get, initialConfig) => ({
2177
2229
  build: (history, selectedItem, itemSelector, puckDispatch, name) => {
@@ -2222,6 +2274,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2222
2274
  return components;
2223
2275
  }
2224
2276
  );
2277
+ requestAnimationFrame(
2278
+ () => setEditVisibility(get().iframeDoc, {
2279
+ mode: "build",
2280
+ editableIds
2281
+ })
2282
+ );
2225
2283
  set((s) => __spreadProps(__spreadValues({}, s), {
2226
2284
  softConfig: buildConfig,
2227
2285
  storedConfig: config,
@@ -2234,15 +2292,14 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2234
2292
  editableComponentIds: editableIds,
2235
2293
  state: "building"
2236
2294
  }));
2237
- setTimeout(
2295
+ requestAnimationFrame(
2238
2296
  () => puckDispatch({
2239
2297
  type: "replaceRoot",
2240
2298
  root: {
2241
2299
  title: "Soft Component Builder",
2242
2300
  _name: name || "New Soft Component"
2243
2301
  }
2244
- }),
2245
- 100
2302
+ })
2246
2303
  );
2247
2304
  },
2248
2305
  remodel: (history, selectedItem, itemSelector, puckDispatch) => {
@@ -2330,6 +2387,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2330
2387
  }).content
2331
2388
  })
2332
2389
  });
2390
+ requestAnimationFrame(
2391
+ () => setEditVisibility(get().iframeDoc, {
2392
+ mode: "remodel",
2393
+ editableIds
2394
+ })
2395
+ );
2333
2396
  set((s) => __spreadProps(__spreadValues({}, s), {
2334
2397
  storedConfig: config,
2335
2398
  softConfig: buildConfig,
@@ -2343,7 +2406,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2343
2406
  editableComponentIds: editableIds,
2344
2407
  state: "remodeling"
2345
2408
  }));
2346
- setTimeout(
2409
+ requestAnimationFrame(
2347
2410
  () => puckDispatch({
2348
2411
  type: "replaceRoot",
2349
2412
  root: {
@@ -2351,8 +2414,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2351
2414
  _name: root.props._name,
2352
2415
  _category: root.props._category
2353
2416
  }
2354
- }),
2355
- 100
2417
+ })
2356
2418
  );
2357
2419
  },
2358
2420
  complete: (appState, setHistories, getItemBySelector) => {
@@ -2368,34 +2430,34 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2368
2430
  if (!itemSelector) {
2369
2431
  throw new Error("No item selector found for completed component.");
2370
2432
  }
2371
- const selectedItem = getItemBySelector(
2372
- itemSelector
2373
- );
2433
+ const selectedItem = getItemBySelector(itemSelector);
2374
2434
  if (!selectedItem) {
2375
2435
  throw new Error("Cannot find item being edited");
2376
2436
  }
2377
2437
  const rootCategory = (_e = (_d = appState.data.root) == null ? void 0 : _d.props) == null ? void 0 : _e._category;
2378
2438
  const rootProps = (_f = appState.data.root) == null ? void 0 : _f.props;
2379
- const componentName = createComponentKeyFromName(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2439
+ const componentName = componentNameFromLabel(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2380
2440
  existingKeys: Object.keys(get().softComponents),
2381
2441
  state: get().state
2382
2442
  }));
2383
2443
  if (!componentName) {
2384
2444
  throw new Error("Failed to generate component key from name.");
2385
2445
  }
2386
- const [newSoftComponentConfig, version] = get().builder.compose(
2446
+ const [defaultSoftComponentConfig, version] = get().builder.compose(
2387
2447
  appState,
2388
2448
  componentName,
2389
2449
  selectedItem,
2390
2450
  displayName,
2391
2451
  rootCategory
2392
2452
  ) || [];
2393
- if (!newSoftComponentConfig) {
2453
+ if (!defaultSoftComponentConfig) {
2394
2454
  throw new Error("Failed to compose new soft component config.");
2395
2455
  }
2396
2456
  const storedHistories = get().originalHistory;
2397
2457
  setHistories([...storedHistories]);
2398
2458
  const config = __spreadValues({}, get().softConfig || initialConfig);
2459
+ const mapComponentConfig = get().overrides.mapComponentConfig;
2460
+ const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
2399
2461
  set((s) => {
2400
2462
  var _a2, _b2;
2401
2463
  const nextComponents = __spreadProps(__spreadValues({}, Object.entries(config.components).reduce(
@@ -2437,10 +2499,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2437
2499
  }),
2438
2500
  storedConfig: void 0,
2439
2501
  state: "inspecting",
2440
- originalHistory: [],
2441
- editingComponent: null,
2442
- editingComponentId: null,
2443
- editableComponentIds: /* @__PURE__ */ new Set()
2502
+ originalHistory: []
2444
2503
  });
2445
2504
  });
2446
2505
  if (!version) {
@@ -2467,30 +2526,44 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2467
2526
  if ((selector == null ? void 0 : selector.index) === void 0 || !(selector == null ? void 0 : selector.zone)) {
2468
2527
  throw new Error("No selector found for last item.");
2469
2528
  }
2470
- setTimeout(() => {
2471
- puckDispatch({
2472
- type: "remove",
2473
- index: selector.index,
2474
- zone: selector.zone
2529
+ const editableComponentId = get().editingComponentId;
2530
+ requestAnimationFrame(() => {
2531
+ const config = get().softConfig;
2532
+ const newComponent = config.components[componentName];
2533
+ const reconstructedTree = (data) => walkTree3(data, config, (components) => {
2534
+ return components.map((comp) => {
2535
+ if (comp.props.id === editableComponentId) {
2536
+ return {
2537
+ type: componentName,
2538
+ props: __spreadProps(__spreadValues({}, newComponent.defaultProps), {
2539
+ id: generateId(componentName)
2540
+ })
2541
+ };
2542
+ }
2543
+ return comp;
2544
+ });
2475
2545
  });
2476
2546
  puckDispatch({
2477
- type: "insert",
2478
- destinationIndex: selector.index,
2479
- destinationZone: selector.zone,
2480
- componentType: componentName
2547
+ type: "setData",
2548
+ data: (data) => {
2549
+ return reconstructedTree(data);
2550
+ }
2481
2551
  });
2482
- }, 500);
2552
+ });
2553
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2483
2554
  set((s) => __spreadProps(__spreadValues({}, s), {
2484
2555
  state: "ready",
2485
2556
  setItemSelector: void 0,
2486
2557
  setOriginalItem: void 0,
2558
+ editingComponent: null,
2487
2559
  editingComponentId: null,
2488
2560
  editableComponentIds: /* @__PURE__ */ new Set()
2489
2561
  }));
2490
2562
  },
2491
2563
  cancel: (setHistories) => {
2492
2564
  const storedHistories = get().originalHistory;
2493
- setTimeout(() => setHistories([...storedHistories]), 100);
2565
+ requestAnimationFrame(() => setHistories([...storedHistories]));
2566
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2494
2567
  set((s) => __spreadProps(__spreadValues({}, s), {
2495
2568
  softConfig: get().storedConfig || initialConfig,
2496
2569
  storedConfig: void 0,
@@ -2780,7 +2853,8 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
2780
2853
  hydratedSoftComponents,
2781
2854
  versionedComponent.defaultProps,
2782
2855
  showVersioning,
2783
- customFields
2856
+ customFields,
2857
+ overrides
2784
2858
  );
2785
2859
  componentConfigs[name] = newSoftComponentConfig;
2786
2860
  buildingConfig.components[name] = newSoftComponentConfig;
@@ -2809,7 +2883,8 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
2809
2883
  hydratedSoftComponents,
2810
2884
  versionedComponent.defaultProps,
2811
2885
  showVersioning,
2812
- customFields
2886
+ customFields,
2887
+ overrides
2813
2888
  );
2814
2889
  componentConfigs[name] = newSoftComponentConfig;
2815
2890
  }
@@ -2817,74 +2892,12 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
2817
2892
  }
2818
2893
  }
2819
2894
 
2820
- // src/puck/lib/edit-visibility-utils.ts
2821
- var setEditVisibility = (doc, context) => {
2822
- if (!doc) return;
2823
- try {
2824
- const root = doc.documentElement;
2825
- if (context.mode === "none") {
2826
- root.removeAttribute("data-edit-mode");
2827
- root.classList.remove("edit-visibility-mode");
2828
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2829
- el.removeAttribute("data-edit-visibility");
2830
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2831
- });
2832
- } else {
2833
- root.setAttribute("data-edit-mode", context.mode);
2834
- root.classList.add("edit-visibility-mode");
2835
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2836
- var _a;
2837
- const id = el.getAttribute("data-puck-component");
2838
- if (!id) return;
2839
- const isEditable = context.editableIds.has(id);
2840
- const isDependency = (_a = context.highlightDependencyIds) == null ? void 0 : _a.has(id);
2841
- if (isEditable) {
2842
- el.setAttribute("data-edit-visibility", "editable");
2843
- el.classList.remove("edit-visibility-greyed", "edit-visibility-dependency");
2844
- el.classList.add("edit-visibility-editable");
2845
- } else if (isDependency) {
2846
- el.setAttribute("data-edit-visibility", "dependency");
2847
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable");
2848
- el.classList.add("edit-visibility-dependency");
2849
- } else {
2850
- el.setAttribute("data-edit-visibility", "greyed");
2851
- el.classList.remove("edit-visibility-editable", "edit-visibility-dependency");
2852
- el.classList.add("edit-visibility-greyed");
2853
- }
2854
- });
2855
- }
2856
- } catch (error) {
2857
- console.warn(`Failed to set edit visibility:`, error);
2858
- }
2859
- };
2860
- var clearEditVisibility = (doc) => {
2861
- if (!doc) return;
2862
- try {
2863
- const root = doc.documentElement;
2864
- root.removeAttribute("data-edit-mode");
2865
- root.classList.remove("edit-visibility-mode");
2866
- doc.querySelectorAll("[data-puck-component]").forEach((el) => {
2867
- el.removeAttribute("data-edit-visibility");
2868
- el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
2869
- });
2870
- } catch (error) {
2871
- console.warn(`Failed to clear edit visibility:`, error);
2872
- }
2873
- };
2874
-
2875
2895
  // src/puck/store/index.tsx
2876
- var createSoftConfigStore = (hardConfig = {
2877
- components: {}
2878
- }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2896
+ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2879
2897
  const normalizedSoftComponents = Object.fromEntries(
2880
- Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [
2881
- key,
2882
- __spreadProps(__spreadValues({}, value), {
2883
- name: value.name || key
2884
- })
2885
- ])
2898
+ Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
2886
2899
  );
2887
- const iframeDocRef = { current: null };
2900
+ const iframeDoc = null;
2888
2901
  const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
2889
2902
  normalizedSoftComponents,
2890
2903
  overrides.hydrateMapTransform
@@ -2893,323 +2906,369 @@ var createSoftConfigStore = (hardConfig = {
2893
2906
  hydratedSoftComponents
2894
2907
  );
2895
2908
  return create()(
2896
- subscribeWithSelector(
2897
- (set, get) => ({
2898
- state: "ready",
2899
- originalHistory: [],
2900
- overrides,
2901
- customFields,
2902
- onActions,
2903
- iframeDocRef,
2904
- showVersionFields,
2905
- editingComponent: null,
2906
- setShowVersionFields: (show) => set({ showVersionFields: show }),
2907
- getIframeDoc: () => iframeDocRef.current,
2908
- setIframeDoc: (doc) => {
2909
- iframeDocRef.current = doc;
2910
- if (!doc) {
2911
- return;
2909
+ subscribeWithSelector((set, get) => ({
2910
+ // ─── Initial State ──────────────────────────────────────────────────────
2911
+ state: "ready",
2912
+ originalHistory: [],
2913
+ overrides,
2914
+ customFields,
2915
+ onActions,
2916
+ iframeDoc,
2917
+ editingComponent: null,
2918
+ editingComponentId: null,
2919
+ editableComponentIds: /* @__PURE__ */ new Set(),
2920
+ itemSelector: null,
2921
+ originalItem: null,
2922
+ hydratedSoftComponents,
2923
+ softComponents: hydratedSoftComponents,
2924
+ dependencyGraph: initialDependencyGraph,
2925
+ showVersionFields,
2926
+ // ─── Initial softConfig ─────────────────────────────────────────────────
2927
+ softConfig: __spreadProps(__spreadValues({}, hardConfig), {
2928
+ components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
2929
+ hardConfig,
2930
+ hydratedSoftComponents,
2931
+ overrides,
2932
+ showVersionFields,
2933
+ customFields
2934
+ )),
2935
+ categories: __spreadValues({}, hardConfig.categories || {})
2936
+ }),
2937
+ // ─── UI Flags ───────────────────────────────────────────────────────────
2938
+ setShowVersionFields: (show) => set({ showVersionFields: show }),
2939
+ // ─── Iframe ─────────────────────────────────────────────────────────────
2940
+ setIframeDoc: (doc) => set({
2941
+ iframeDoc: doc
2942
+ }),
2943
+ // ─── History ────────────────────────────────────────────────────────────
2944
+ storeHistory: (history) => set({ originalHistory: history }),
2945
+ removeHistory: () => set({ originalHistory: [] }),
2946
+ // ─── Item Selection ─────────────────────────────────────────────────────
2947
+ setItemSelector: (selector) => set({ itemSelector: selector }),
2948
+ setOriginalItem: (item) => set({ originalItem: item }),
2949
+ // ─── Editing State ──────────────────────────────────────────────────────
2950
+ setEditableComponentIds: (ids) => set({ editableComponentIds: ids }),
2951
+ addEditableComponentId: (id) => set((state) => {
2952
+ const newIds = new Set(state.editableComponentIds);
2953
+ newIds.add(id);
2954
+ return { editableComponentIds: newIds };
2955
+ }),
2956
+ clearEditingState: () => set({ editingComponentId: null, editableComponentIds: /* @__PURE__ */ new Set() }),
2957
+ // ─── Action Validation ──────────────────────────────────────────────────
2958
+ undoFn: null,
2959
+ setUndoFn: (fn) => set({ undoFn: fn }),
2960
+ validateAction: (action, previousAction) => {
2961
+ var _a;
2962
+ const { state, editableComponentIds, addEditableComponentId } = get();
2963
+ if (state === "ready") return true;
2964
+ if (action.type === "replace") {
2965
+ if ((previousAction == null ? void 0 : previousAction.type) === "insert" && (previousAction == null ? void 0 : previousAction.id) === action.data.props.id) {
2966
+ return true;
2912
2967
  }
2913
- const { state, editableComponentIds } = get();
2914
- if (state === "building") {
2915
- setEditVisibility(doc, {
2916
- mode: "build",
2917
- editableIds: editableComponentIds
2918
- });
2919
- return;
2968
+ const parentId = (_a = action.destinationZone) == null ? void 0 : _a.split(":")[0];
2969
+ if (action.data.props.id && editableComponentIds.has(action.data.props.id)) {
2970
+ return true;
2920
2971
  }
2921
- if (state === "remodeling") {
2922
- setEditVisibility(doc, {
2923
- mode: "remodel",
2924
- editableIds: editableComponentIds
2925
- });
2926
- return;
2972
+ if (parentId && editableComponentIds.has(parentId)) {
2973
+ addEditableComponentId(action.data.props.id);
2974
+ return true;
2927
2975
  }
2928
- clearEditVisibility(doc);
2929
- },
2930
- storeHistory: (history) => set({ originalHistory: history }),
2931
- removeHistory: () => set({ originalHistory: [] }),
2932
- itemSelector: null,
2933
- setItemSelector: (selector) => set({ itemSelector: selector }),
2934
- originalItem: null,
2935
- setOriginalItem: (item) => set({ originalItem: item }),
2936
- hydratedSoftComponents,
2937
- softComponents: hydratedSoftComponents,
2938
- dependencyGraph: initialDependencyGraph,
2939
- softConfig: __spreadProps(__spreadValues({}, hardConfig), {
2940
- components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
2941
- hardConfig,
2942
- hydratedSoftComponents,
2943
- overrides,
2944
- showVersionFields,
2945
- customFields
2946
- )),
2947
- categories: __spreadValues({}, hardConfig.categories || {})
2948
- }),
2949
- setSoftComponent: (name, version, component) => {
2950
- if (hardConfig.components && hardConfig.components[name]) {
2951
- console.warn(`Cannot set soft component "${name}" because it conflicts with a base hardConfig component.`);
2952
- return;
2976
+ return false;
2977
+ }
2978
+ if (action.type === "insert" || action.type === "duplicate") {
2979
+ const zone = action.type === "insert" ? action.destinationZone : action.sourceZone;
2980
+ const parentId = zone == null ? void 0 : zone.split(":")[0];
2981
+ const isEditable = parentId && editableComponentIds.has(parentId);
2982
+ if (!isEditable && action.type === "duplicate") return false;
2983
+ if (action.type === "insert" && action.id && isEditable) {
2984
+ addEditableComponentId(action.id);
2953
2985
  }
2954
- const existing = get().softComponents[name];
2955
- set((state) => {
2956
- var _a, _b;
2957
- return {
2958
- softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
2959
- [name]: __spreadProps(__spreadValues({}, existing), {
2960
- name: component.name || (existing == null ? void 0 : existing.name) || name,
2961
- category: (_a = component.category) != null ? _a : existing == null ? void 0 : existing.category,
2962
- defaultVersion: version,
2963
- versions: __spreadProps(__spreadValues({}, ((_b = state.softComponents[name]) == null ? void 0 : _b.versions) || {}), {
2964
- [version]: component
2965
- })
2986
+ }
2987
+ if (action.type === "remove" || action.type === "move" || action.type === "reorder") {
2988
+ const zone = action.type === "remove" ? action.zone : action.destinationZone;
2989
+ const parentId = zone == null ? void 0 : zone.split(":")[0];
2990
+ if (parentId && !editableComponentIds.has(parentId)) return false;
2991
+ return true;
2992
+ }
2993
+ return true;
2994
+ },
2995
+ // ─── Soft Component CRUD ─────────────────────────────────────────────────
2996
+ setSoftComponent: (name, version, component) => {
2997
+ var _a;
2998
+ if ((_a = hardConfig.components) == null ? void 0 : _a[name]) {
2999
+ console.warn(
3000
+ `Cannot set soft component "${name}" because it conflicts with a hardConfig component.`
3001
+ );
3002
+ return;
3003
+ }
3004
+ const existing = get().softComponents[name];
3005
+ set((state) => {
3006
+ var _a2, _b;
3007
+ return {
3008
+ softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3009
+ [name]: __spreadProps(__spreadValues({}, existing), {
3010
+ name: component.name || (existing == null ? void 0 : existing.name) || name,
3011
+ category: (_a2 = component.category) != null ? _a2 : existing == null ? void 0 : existing.category,
3012
+ defaultVersion: version,
3013
+ versions: __spreadProps(__spreadValues({}, ((_b = state.softComponents[name]) == null ? void 0 : _b.versions) || {}), {
3014
+ [version]: component
2966
3015
  })
2967
3016
  })
2968
- };
2969
- });
2970
- },
2971
- setSoftComponents: (incomingComponents) => {
2972
- const state = get();
2973
- const nextSoftComponents = __spreadValues({}, state.softComponents);
2974
- const nextConfigComponents = __spreadValues({}, state.softConfig.components);
2975
- Object.entries(incomingComponents).forEach(([name, data]) => {
2976
- if (hardConfig.components && hardConfig.components[name]) {
2977
- return;
2978
- }
2979
- const existing = nextSoftComponents[name];
2980
- const finalComponentData = existing ? __spreadProps(__spreadValues(__spreadValues({}, existing), data), {
2981
- name: data.name || existing.name || name,
2982
- versions: __spreadValues(__spreadValues({}, existing.versions), data.versions)
2983
- }) : data;
2984
- finalComponentData.name = finalComponentData.name || name;
2985
- nextSoftComponents[name] = finalComponentData;
2986
- const activeVersion = finalComponentData.defaultVersion;
2987
- const activeVersionData = finalComponentData.versions[activeVersion];
2988
- if (activeVersionData) {
2989
- nextConfigComponents[name] = createVersionedComponentConfig(
2990
- name,
2991
- finalComponentData.name || name,
2992
- activeVersion,
2993
- Object.keys(finalComponentData.versions),
2994
- state.softConfig,
2995
- nextSoftComponents,
2996
- activeVersionData.defaultProps,
2997
- state.showVersionFields,
2998
- state.customFields
2999
- );
3000
- }
3001
- });
3002
- set({
3003
- softComponents: nextSoftComponents,
3004
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3005
- components: nextConfigComponents
3006
3017
  })
3007
- });
3008
- },
3009
- hydrateTransforms: () => {
3010
- const { overrides: overrides2, softComponents: softComponents2, softConfig } = get();
3011
- if (!(overrides2 == null ? void 0 : overrides2.hydrateMapTransform)) return;
3012
- const hydratedComponents = hydrateSoftComponentsTransforms(
3013
- softComponents2,
3014
- overrides2.hydrateMapTransform
3015
- );
3016
- const nextConfigComponents = __spreadValues({}, softConfig.components);
3017
- Object.entries(hydratedComponents).forEach(([name, componentData]) => {
3018
- const activeVersion = componentData.defaultVersion;
3019
- const activeVersionData = componentData.versions[activeVersion];
3020
- if (activeVersionData) {
3021
- nextConfigComponents[name] = createVersionedComponentConfig(
3022
- name,
3023
- componentData.name || name,
3024
- activeVersion,
3025
- Object.keys(componentData.versions),
3026
- softConfig,
3027
- hydratedComponents,
3028
- activeVersionData.defaultProps,
3029
- get().showVersionFields,
3030
- get().customFields
3031
- );
3032
- }
3033
- });
3034
- set({
3035
- softComponents: hydratedComponents,
3036
- softConfig: __spreadProps(__spreadValues({}, softConfig), {
3037
- components: nextConfigComponents
3038
- })
3039
- });
3040
- },
3041
- setSoftComponentDefaultVersion: (name, version) => {
3042
- var _a, _b, _c, _d;
3043
- const softComponent = (_b = (_a = get().softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
3044
- const allVersions = Object.keys(
3045
- ((_c = get().softComponents[name]) == null ? void 0 : _c.versions) || {}
3046
- );
3047
- const displayName = ((_d = get().softComponents[name]) == null ? void 0 : _d.name) || name;
3048
- if (!softComponent) {
3049
- throw new Error(
3050
- `Soft component "${name}" version "${version}" does not exist.`
3018
+ };
3019
+ });
3020
+ },
3021
+ setSoftComponents: (incomingComponents) => {
3022
+ const state = get();
3023
+ const nextSoftComponents = __spreadValues({}, state.softComponents);
3024
+ const nextConfigComponents = __spreadValues({}, state.softConfig.components);
3025
+ Object.entries(incomingComponents).forEach(([name, data]) => {
3026
+ var _a;
3027
+ if ((_a = hardConfig.components) == null ? void 0 : _a[name]) return;
3028
+ const existing = nextSoftComponents[name];
3029
+ const merged = existing ? __spreadProps(__spreadValues(__spreadValues({}, existing), data), {
3030
+ name: data.name || existing.name || name,
3031
+ versions: __spreadValues(__spreadValues({}, existing.versions), data.versions)
3032
+ }) : data;
3033
+ merged.name = merged.name || name;
3034
+ nextSoftComponents[name] = merged;
3035
+ const activeVersion = merged.defaultVersion;
3036
+ const activeVersionData = merged.versions[activeVersion];
3037
+ if (activeVersionData) {
3038
+ nextConfigComponents[name] = createVersionedComponentConfig(
3039
+ name,
3040
+ merged.name,
3041
+ activeVersion,
3042
+ Object.keys(merged.versions),
3043
+ state.softConfig,
3044
+ nextSoftComponents,
3045
+ activeVersionData.defaultProps,
3046
+ state.showVersionFields,
3047
+ state.customFields
3051
3048
  );
3052
3049
  }
3053
- const newSoftComponentConfig = createVersionedComponentConfig(
3054
- name,
3055
- displayName,
3056
- version,
3057
- allVersions,
3058
- get().softConfig,
3059
- get().softComponents,
3060
- softComponent.defaultProps,
3061
- get().showVersionFields,
3062
- get().customFields
3050
+ });
3051
+ set({
3052
+ softComponents: nextSoftComponents,
3053
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), { components: nextConfigComponents })
3054
+ });
3055
+ },
3056
+ hydrateTransforms: () => {
3057
+ const { overrides: overrides2, softComponents: softComponents2, softConfig } = get();
3058
+ if (!(overrides2 == null ? void 0 : overrides2.hydrateMapTransform)) return;
3059
+ const hydratedComponents = hydrateSoftComponentsTransforms(
3060
+ softComponents2,
3061
+ overrides2.hydrateMapTransform
3062
+ );
3063
+ const nextConfigComponents = __spreadValues({}, softConfig.components);
3064
+ Object.entries(hydratedComponents).forEach(([name, componentData]) => {
3065
+ const activeVersion = componentData.defaultVersion;
3066
+ const activeVersionData = componentData.versions[activeVersion];
3067
+ if (activeVersionData) {
3068
+ nextConfigComponents[name] = createVersionedComponentConfig(
3069
+ name,
3070
+ componentData.name || name,
3071
+ activeVersion,
3072
+ Object.keys(componentData.versions),
3073
+ softConfig,
3074
+ hydratedComponents,
3075
+ activeVersionData.defaultProps,
3076
+ get().showVersionFields,
3077
+ get().customFields
3078
+ );
3079
+ }
3080
+ });
3081
+ set({
3082
+ softComponents: hydratedComponents,
3083
+ softConfig: __spreadProps(__spreadValues({}, softConfig), { components: nextConfigComponents })
3084
+ });
3085
+ },
3086
+ setSoftComponentDefaultVersion: (name, version) => {
3087
+ var _a, _b, _c, _d;
3088
+ const state = get();
3089
+ const softComponent = (_b = (_a = state.softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
3090
+ if (!softComponent) {
3091
+ throw new Error(
3092
+ `Soft component "${name}" version "${version}" does not exist.`
3063
3093
  );
3064
- set((state) => ({
3065
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3066
- components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3067
- [name]: newSoftComponentConfig
3068
- })
3069
- }),
3094
+ }
3095
+ const allVersions = Object.keys(
3096
+ ((_c = state.softComponents[name]) == null ? void 0 : _c.versions) || {}
3097
+ );
3098
+ const displayName = ((_d = state.softComponents[name]) == null ? void 0 : _d.name) || name;
3099
+ const newConfig = createVersionedComponentConfig(
3100
+ name,
3101
+ displayName,
3102
+ version,
3103
+ allVersions,
3104
+ state.softConfig,
3105
+ state.softComponents,
3106
+ softComponent.defaultProps,
3107
+ state.showVersionFields,
3108
+ state.customFields
3109
+ );
3110
+ set((s) => ({
3111
+ softConfig: __spreadProps(__spreadValues({}, s.softConfig), {
3112
+ components: __spreadProps(__spreadValues({}, s.softConfig.components), { [name]: newConfig })
3113
+ }),
3114
+ softComponents: __spreadProps(__spreadValues({}, s.softComponents), {
3115
+ [name]: __spreadProps(__spreadValues({}, s.softComponents[name]), { defaultVersion: version })
3116
+ })
3117
+ }));
3118
+ },
3119
+ removeSoftComponentVersion: (key, version) => {
3120
+ set((state) => {
3121
+ const component = state.softComponents[key];
3122
+ if (!component) return {};
3123
+ const newVersions = Object.fromEntries(
3124
+ Object.entries(component.versions || {}).filter(
3125
+ ([k]) => k !== version
3126
+ )
3127
+ );
3128
+ let newDefaultVersion = component.defaultVersion;
3129
+ if (component.defaultVersion === version) {
3130
+ const versionKeys = Object.keys(newVersions);
3131
+ newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
3132
+ }
3133
+ return {
3070
3134
  softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3071
- [name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
3072
- defaultVersion: version
3135
+ [key]: __spreadProps(__spreadValues({}, component), {
3136
+ versions: newVersions,
3137
+ defaultVersion: newDefaultVersion
3073
3138
  })
3074
3139
  })
3075
- }));
3076
- },
3077
- removeSoftComponentVersion: (key, version) => {
3078
- set((state) => {
3079
- const component = state.softComponents[key];
3080
- if (!component) return {};
3081
- const newVersions = Object.fromEntries(
3082
- Object.entries(component.versions || {}).filter(
3083
- ([k, _]) => k !== version
3084
- )
3085
- );
3086
- let newDefaultVersion = component.defaultVersion;
3087
- if (component.defaultVersion === version) {
3088
- const versionKeys = Object.keys(newVersions);
3089
- newDefaultVersion = versionKeys.length > 0 ? versionKeys[versionKeys.length - 1] : "";
3090
- }
3091
- return {
3092
- softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3093
- [key]: __spreadProps(__spreadValues({}, component), {
3094
- versions: newVersions,
3095
- defaultVersion: newDefaultVersion
3096
- })
3097
- })
3098
- };
3099
- });
3100
- },
3101
- removeSoftComponent: (key) => {
3102
- set((state) => ({
3103
- softComponents: Object.fromEntries(
3104
- Object.entries(state.softComponents).filter(([k, _]) => k !== key)
3105
- )
3106
- }));
3107
- },
3108
- setSoftComponentConfig: (key, config, category) => {
3109
- set((state) => {
3110
- var _a, _b, _c;
3111
- return {
3112
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3113
- components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3114
- [key]: __spreadValues({}, config)
3115
- }),
3116
- categories: category ? __spreadProps(__spreadValues({}, state.softConfig.categories || {}), {
3117
- [category]: __spreadProps(__spreadValues({}, ((_a = state.softConfig.categories) == null ? void 0 : _a[category]) || {}), {
3118
- components: [
3119
- ...((_c = (_b = state.softConfig.categories) == null ? void 0 : _b[category]) == null ? void 0 : _c.components) || [],
3120
- key
3121
- ]
3122
- })
3123
- }) : state.softConfig.categories || {}
3124
- })
3125
- };
3126
- });
3127
- },
3128
- removeSoftComponentConfig: (key) => {
3129
- set((state) => ({
3140
+ };
3141
+ });
3142
+ },
3143
+ removeSoftComponent: (key) => set((state) => ({
3144
+ softComponents: Object.fromEntries(
3145
+ Object.entries(state.softComponents).filter(([k]) => k !== key)
3146
+ )
3147
+ })),
3148
+ setSoftComponentConfig: (key, config, category) => {
3149
+ set((state) => {
3150
+ var _a, _b, _c;
3151
+ return {
3130
3152
  softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3131
- components: Object.fromEntries(
3132
- Object.entries(state.softConfig.components).filter(
3133
- ([k, _]) => k !== key
3134
- )
3135
- )
3136
- })
3137
- }));
3138
- },
3139
- setSoftCategoryConfig: (key, category) => {
3140
- set((state) => {
3141
- var _a;
3142
- return {
3143
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3144
- categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
3145
- [key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
3153
+ components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3154
+ [key]: __spreadValues({}, config)
3155
+ }),
3156
+ categories: category ? __spreadProps(__spreadValues({}, state.softConfig.categories || {}), {
3157
+ [category]: __spreadProps(__spreadValues({}, ((_a = state.softConfig.categories) == null ? void 0 : _a[category]) || {}), {
3158
+ components: [
3159
+ ...((_c = (_b = state.softConfig.categories) == null ? void 0 : _b[category]) == null ? void 0 : _c.components) || [],
3160
+ key
3161
+ ]
3146
3162
  })
3147
- })
3148
- };
3149
- });
3150
- },
3151
- removeSoftCategoryConfig: (key) => {
3152
- set((state) => ({
3153
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3154
- categories: Object.fromEntries(
3155
- Object.entries(state.softConfig.categories || {}).filter(
3156
- ([k, _]) => k !== key
3157
- )
3158
- )
3163
+ }) : state.softConfig.categories || {}
3159
3164
  })
3160
- }));
3161
- },
3162
- builder: createBuildersSlice(set, get, hardConfig),
3163
- editingComponentId: null,
3164
- editableComponentIds: /* @__PURE__ */ new Set(),
3165
- setEditableComponentIds: (ids) => set({ editableComponentIds: ids }),
3166
- addEditableComponentId: (id) => {
3167
- set((state) => {
3168
- const newIds = new Set(state.editableComponentIds);
3169
- newIds.add(id);
3170
- return { editableComponentIds: newIds };
3171
- });
3172
- },
3173
- clearEditingState: () => set({
3174
- editingComponentId: null,
3175
- editableComponentIds: /* @__PURE__ */ new Set()
3176
- }),
3177
- rebuildDependents: (componentName, version) => {
3178
- const state = get();
3179
- const dependents = state.dependencyGraph.get(componentName) || /* @__PURE__ */ new Set();
3180
- if (dependents.size === 0) return;
3181
- const config = __spreadValues({}, state.softConfig);
3182
- const softComponents2 = state.softComponents;
3183
- const toBuild = Array.from(dependents);
3184
- for (const dependentName of toBuild) {
3185
- const dependent = softComponents2[dependentName];
3186
- const defaultVersion = dependent.defaultVersion || Object.keys(dependent.versions || {}).pop();
3187
- if (!defaultVersion) continue;
3188
- const versionedComponent = dependent.versions[defaultVersion];
3189
- const allVersions = Object.keys(dependent.versions || {});
3190
- if (!versionedComponent) continue;
3191
- const newConfig = createVersionedComponentConfig(
3192
- dependentName,
3193
- dependent.name || dependentName,
3194
- defaultVersion,
3195
- allVersions,
3196
- config,
3197
- softComponents2,
3198
- versionedComponent.defaultProps,
3199
- state.showVersionFields,
3200
- state.customFields
3201
- );
3202
- config.components[dependentName] = newConfig;
3203
- }
3204
- set((s) => __spreadProps(__spreadValues({}, s), { softConfig: config }));
3165
+ };
3166
+ });
3167
+ },
3168
+ removeSoftComponentConfig: (key) => set((state) => ({
3169
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3170
+ components: Object.fromEntries(
3171
+ Object.entries(state.softConfig.components).filter(
3172
+ ([k]) => k !== key
3173
+ )
3174
+ )
3175
+ })
3176
+ })),
3177
+ setSoftCategoryConfig: (key, category) => set((state) => {
3178
+ var _a;
3179
+ return {
3180
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3181
+ categories: __spreadProps(__spreadValues({}, state.softConfig.categories), {
3182
+ [key]: __spreadValues(__spreadValues({}, (_a = state.softConfig.categories) == null ? void 0 : _a[key]), category)
3183
+ })
3184
+ })
3185
+ };
3186
+ }),
3187
+ removeSoftCategoryConfig: (key) => set((state) => ({
3188
+ softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3189
+ categories: Object.fromEntries(
3190
+ Object.entries(state.softConfig.categories || {}).filter(
3191
+ ([k]) => k !== key
3192
+ )
3193
+ )
3194
+ })
3195
+ })),
3196
+ // ─── Builder Slice ────────────────────────────────────────────────────────
3197
+ builder: createBuildersSlice(set, get, hardConfig),
3198
+ // ─── Dependency Graph ─────────────────────────────────────────────────────
3199
+ rebuildDependents: (componentName) => {
3200
+ const state = get();
3201
+ const dependents = state.dependencyGraph.get(componentName) || /* @__PURE__ */ new Set();
3202
+ if (dependents.size === 0) return;
3203
+ const nextConfig = __spreadValues({}, state.softConfig);
3204
+ const { softComponents: softComponents2 } = state;
3205
+ for (const dependentName of Array.from(dependents)) {
3206
+ const dependent = softComponents2[dependentName];
3207
+ const defaultVersion = dependent.defaultVersion || Object.keys(dependent.versions || {}).pop();
3208
+ if (!defaultVersion) continue;
3209
+ const versionedComponent = dependent.versions[defaultVersion];
3210
+ if (!versionedComponent) continue;
3211
+ nextConfig.components[dependentName] = createVersionedComponentConfig(
3212
+ dependentName,
3213
+ dependent.name || dependentName,
3214
+ defaultVersion,
3215
+ Object.keys(dependent.versions || {}),
3216
+ nextConfig,
3217
+ softComponents2,
3218
+ versionedComponent.defaultProps,
3219
+ state.showVersionFields,
3220
+ state.customFields
3221
+ );
3205
3222
  }
3206
- })
3207
- )
3223
+ set((s) => __spreadProps(__spreadValues({}, s), { softConfig: nextConfig }));
3224
+ }
3225
+ }))
3208
3226
  );
3209
3227
  };
3210
3228
 
3211
3229
  // src/puck/context/storeProvider.tsx
3212
3230
  import { useEffect as useEffect2, useMemo as useMemo2, useState } from "react";
3231
+
3232
+ // src/puck/lib/notify.ts
3233
+ var customHandler = null;
3234
+ var defaultHandler = (message, type) => {
3235
+ if (type === "error") {
3236
+ console.error(`[Error] ${message}`);
3237
+ } else {
3238
+ console.log(`[Success] ${message}`);
3239
+ }
3240
+ };
3241
+ var setNotificationHandler = (handler) => {
3242
+ customHandler = handler;
3243
+ };
3244
+ var notify = {
3245
+ error: (message) => {
3246
+ const handler = customHandler || defaultHandler;
3247
+ handler(message, "error");
3248
+ },
3249
+ success: (message) => {
3250
+ const handler = customHandler || defaultHandler;
3251
+ handler(message, "success");
3252
+ }
3253
+ };
3254
+
3255
+ // src/puck/lib/action-callback.ts
3256
+ var createActionCallback = (validateAction, undo) => {
3257
+ return (action) => {
3258
+ if (!undo) {
3259
+ return;
3260
+ }
3261
+ const isValid = validateAction(action);
3262
+ if (!isValid) {
3263
+ notify.error(
3264
+ "Editing outside the soft component is not allowed when you are editing component definition."
3265
+ );
3266
+ requestAnimationFrame(() => undo());
3267
+ }
3268
+ };
3269
+ };
3270
+
3271
+ // src/puck/context/storeProvider.tsx
3213
3272
  import { jsx as jsx7 } from "react/jsx-runtime";
3214
3273
  var SoftConfigProvider = ({
3215
3274
  children,
@@ -3245,57 +3304,8 @@ var SoftConfigProvider = ({
3245
3304
  const [internalSoftComponents, setSoftComponents] = useState(
3246
3305
  () => store.getState().softComponents
3247
3306
  );
3248
- const storeSetIframeDoc = useMemo2(
3249
- () => store.getState().setIframeDoc,
3250
- [store]
3251
- );
3252
- const validateAction = useMemo2(
3253
- () => (action) => {
3254
- var _a;
3255
- const currentState = store.getState();
3256
- if (currentState.state === "ready") {
3257
- return true;
3258
- }
3259
- const editableIds = currentState.editableComponentIds;
3260
- if (action.type === "replace") {
3261
- const parentId = (_a = action.destinationZone) == null ? void 0 : _a.split(":")[0];
3262
- if (action.data.props.id && editableIds.has(action.data.props.id)) {
3263
- return true;
3264
- } else if (parentId && editableIds.has(parentId)) {
3265
- currentState.addEditableComponentId(action.data.props.id);
3266
- return true;
3267
- }
3268
- return false;
3269
- }
3270
- if (action.type === "insert" || action.type === "duplicate") {
3271
- const zone = action.type === "insert" ? action.destinationZone : action.sourceZone;
3272
- const parentId = zone == null ? void 0 : zone.split(":")[0];
3273
- if (parentId && !editableIds.has(parentId)) {
3274
- return false;
3275
- }
3276
- if (action.type === "insert") {
3277
- const childId = action.id;
3278
- if (childId) {
3279
- currentState.addEditableComponentId(childId);
3280
- }
3281
- }
3282
- return true;
3283
- }
3284
- if (action.type === "remove" || action.type === "move" || action.type === "reorder") {
3285
- let parentId;
3286
- if (action.type === "remove") {
3287
- parentId = action.zone.split(":")[0];
3288
- } else if (action.type === "move" || action.type === "reorder") {
3289
- parentId = action.destinationZone.split(":")[0];
3290
- }
3291
- if (parentId && !editableIds.has(parentId)) {
3292
- return false;
3293
- }
3294
- return true;
3295
- }
3296
- return true;
3297
- },
3298
- [store]
3307
+ const [actionGuard, setActionGuard] = useState(
3308
+ (action) => null
3299
3309
  );
3300
3310
  useEffect2(() => {
3301
3311
  const unsubscribe = store.subscribe(() => {
@@ -3308,59 +3318,26 @@ var SoftConfigProvider = ({
3308
3318
  }, [store]);
3309
3319
  useEffect2(() => {
3310
3320
  const unsubscribe = store.subscribe((state, prevState) => {
3311
- if (prevState && state.state === prevState.state && state.editableComponentIds === prevState.editableComponentIds) {
3312
- return;
3313
- }
3314
- const doc = store.getState().getIframeDoc();
3315
- if (!doc) return;
3316
- if (state.state === "building") {
3317
- setEditVisibility(doc, { mode: "build", editableIds: state.editableComponentIds });
3321
+ if (prevState && prevState.undoFn === state.undoFn) {
3318
3322
  return;
3319
3323
  }
3320
- if (state.state === "remodeling") {
3321
- setEditVisibility(doc, { mode: "remodel", editableIds: state.editableComponentIds });
3322
- return;
3323
- }
3324
- requestAnimationFrame(() => {
3325
- const freshDoc = store.getState().getIframeDoc();
3326
- if (freshDoc) {
3327
- clearEditVisibility(freshDoc);
3328
- }
3329
- });
3324
+ setActionGuard(
3325
+ () => createActionCallback(
3326
+ state.validateAction,
3327
+ state.undoFn
3328
+ )
3329
+ );
3330
3330
  });
3331
3331
  return () => {
3332
3332
  unsubscribe();
3333
3333
  };
3334
- }, [store]);
3335
- return /* @__PURE__ */ jsx7(appStoreContext.Provider, { value: store, children: children(softConfig, internalSoftComponents, storeSetIframeDoc, validateAction) });
3334
+ }, [store.getState().undoFn]);
3335
+ return /* @__PURE__ */ jsx7(appStoreContext.Provider, { value: store, children: children(softConfig, internalSoftComponents, actionGuard) });
3336
3336
  };
3337
3337
 
3338
3338
  // src/puck/actions/useBuild.tsx
3339
3339
  import { createUsePuck as createUsePuck2 } from "@measured/puck";
3340
3340
 
3341
- // src/puck/lib/notify.ts
3342
- var customHandler = null;
3343
- var defaultHandler = (message, type) => {
3344
- if (type === "error") {
3345
- console.error(`[Error] ${message}`);
3346
- } else {
3347
- console.log(`[Success] ${message}`);
3348
- }
3349
- };
3350
- var setNotificationHandler = (handler) => {
3351
- customHandler = handler;
3352
- };
3353
- var notify = {
3354
- error: (message) => {
3355
- const handler = customHandler || defaultHandler;
3356
- handler(message, "error");
3357
- },
3358
- success: (message) => {
3359
- const handler = customHandler || defaultHandler;
3360
- handler(message, "success");
3361
- }
3362
- };
3363
-
3364
3341
  // src/puck/hooks/useActionEvent.ts
3365
3342
  import { useCallback } from "react";
3366
3343
  var useActionEvent = () => {
@@ -3738,7 +3715,7 @@ var useSetDefaultVersion = () => {
3738
3715
  // src/puck/overrides/Header.tsx
3739
3716
  import { Button, createUsePuck as createUsePuck10 } from "@measured/puck";
3740
3717
 
3741
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Header.module.css#css-module
3718
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Header.module.css#css-module
3742
3719
  var Header_module_default = { "Header": "_Header_19oj9_1" };
3743
3720
 
3744
3721
  // src/puck/actions/usePublish.tsx
@@ -3787,7 +3764,6 @@ var Header = ({
3787
3764
  const { handleComplete, newComponent, setNewComponent } = useComplete();
3788
3765
  const { handleCancel, canCancel } = useCancel();
3789
3766
  const { handlePublish } = usePublish();
3790
- const puck = usePuck((s) => s.config);
3791
3767
  useInspect(newComponent);
3792
3768
  return /* @__PURE__ */ jsx8("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
3793
3769
  /* @__PURE__ */ jsx8(Button, { onClick: handleCancel, children: "Cancel" }),
@@ -3823,7 +3799,7 @@ import { useMemo as useMemo3 } from "react";
3823
3799
  import { ActionBar, createUsePuck as createUsePuck11 } from "@measured/puck";
3824
3800
  import { Combine, ComponentIcon, EditIcon } from "lucide-react";
3825
3801
 
3826
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
3802
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
3827
3803
  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" };
3828
3804
 
3829
3805
  // src/puck/overrides/ActionBar.tsx
@@ -3849,7 +3825,7 @@ var ActionBarOverride = (props) => {
3849
3825
  if (selectedType && softKeys.includes(selectedType)) {
3850
3826
  return selectedType;
3851
3827
  }
3852
- return createComponentKeyFromName(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3828
+ return componentNameFromLabel(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3853
3829
  existingKeys: softKeys,
3854
3830
  state: status
3855
3831
  }));
@@ -3865,17 +3841,17 @@ var ActionBarOverride = (props) => {
3865
3841
  const selectedId = (_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.id;
3866
3842
  const parentId = (_b = itemSelector == null ? void 0 : itemSelector.zone) == null ? void 0 : _b.split(":")[0];
3867
3843
  const isEditable = Boolean(selectedId && (editableIds.has(selectedId) || parentId && editableIds.has(parentId)));
3868
- const displayName = useMemo3(() => {
3844
+ const label = useMemo3(() => {
3869
3845
  var _a2;
3870
3846
  if (isSoftComponent2) {
3871
- return ((_a2 = softComponents[key]) == null ? void 0 : _a2.name) || getComponentNameFromKey(key, overrides);
3847
+ return ((_a2 = softComponents[key]) == null ? void 0 : _a2.name) || componentLabelFromName(key, overrides);
3872
3848
  }
3873
3849
  return props.label || "";
3874
3850
  }, [isSoftComponent2, key, props.label, overrides, softComponents]);
3875
3851
  return /* @__PURE__ */ jsx9("div", { className: getClassName3(), children: /* @__PURE__ */ jsxs3(ActionBar, { children: [
3876
3852
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3877
3853
  props.parentAction,
3878
- /* @__PURE__ */ jsx9(ActionBar.Label, { label: displayName })
3854
+ /* @__PURE__ */ jsx9(ActionBar.Label, { label })
3879
3855
  ] }),
3880
3856
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3881
3857
  status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(Fragment4, { children: [
@@ -3930,14 +3906,14 @@ var confirm = (message) => __async(null, null, function* () {
3930
3906
  }
3931
3907
  });
3932
3908
 
3933
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/DrawerItem.module.css#css-module
3909
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/DrawerItem.module.css#css-module
3934
3910
  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" };
3935
3911
 
3936
3912
  // src/puck/components/modal/index.tsx
3937
3913
  import { useEffect as useEffect4, useState as useState3 } from "react";
3938
3914
  import { createPortal } from "react-dom";
3939
3915
 
3940
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
3916
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
3941
3917
  var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
3942
3918
 
3943
3919
  // src/puck/components/modal/index.tsx
@@ -4172,6 +4148,7 @@ var DrawerItem = (props) => {
4172
4148
  return /* @__PURE__ */ jsxs4(
4173
4149
  "button",
4174
4150
  {
4151
+ "aria-label": target.label,
4175
4152
  type: "button",
4176
4153
  role: "radio",
4177
4154
  "aria-checked": isSelected,
@@ -4222,7 +4199,7 @@ import { useState as useState5 } from "react";
4222
4199
  import { createUsePuck as createUsePuck13, Drawer as PuckDrawer } from "@measured/puck";
4223
4200
  import { ChevronDown, ChevronUp } from "lucide-react";
4224
4201
 
4225
- // css-module:/media/manual_mount/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
4202
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
4226
4203
  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" };
4227
4204
 
4228
4205
  // src/puck/overrides/Drawer.tsx
@@ -4334,25 +4311,37 @@ var Drawer = (_props) => {
4334
4311
  ] });
4335
4312
  };
4336
4313
 
4337
- // src/puck/lib/action-callback.ts
4338
- var createActionCallback = (validateAction, undo) => {
4339
- return (action) => {
4340
- const isValid = validateAction(action);
4341
- if (!isValid) {
4342
- notify.error(
4343
- "Editing outside the soft component is not allowed when you are editing component definition."
4344
- );
4345
- if (typeof requestAnimationFrame === "function") {
4346
- requestAnimationFrame(() => {
4347
- requestAnimationFrame(() => {
4348
- undo();
4349
- });
4350
- });
4351
- } else {
4352
- setTimeout(() => undo(), 0);
4314
+ // src/puck/overrides/HeaderActions.tsx
4315
+ import { Button as Button3, createUsePuck as createUsePuck14 } from "@measured/puck";
4316
+ import { Fragment as Fragment6, jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
4317
+ var usePuck5 = createUsePuck14();
4318
+ var HeaderActions = ({ children }) => {
4319
+ const { handleComplete } = useComplete();
4320
+ const { handleCancel, canCancel } = useCancel();
4321
+ const dispatch = usePuck5((s) => s.dispatch);
4322
+ const inspect = useSoftConfig((s) => s.builder.inspect);
4323
+ return /* @__PURE__ */ jsx13(Fragment6, { children: canCancel ? /* @__PURE__ */ jsxs6(Fragment6, { children: [
4324
+ /* @__PURE__ */ jsx13(Button3, { onClick: handleCancel, children: "Cancel" }),
4325
+ /* @__PURE__ */ jsx13(
4326
+ Button3,
4327
+ {
4328
+ variant: "primary",
4329
+ onClick: () => {
4330
+ const completedComponent = handleComplete();
4331
+ if (completedComponent) {
4332
+ try {
4333
+ inspect(completedComponent.id, dispatch);
4334
+ } catch (error) {
4335
+ notify.error(
4336
+ "Failed to inspect after completion: " + (error instanceof Error ? error.message : String(error))
4337
+ );
4338
+ }
4339
+ }
4340
+ },
4341
+ children: "Complete"
4353
4342
  }
4354
- }
4355
- };
4343
+ )
4344
+ ] }) : children });
4356
4345
  };
4357
4346
 
4358
4347
  // src/puck/lib/dissolve-all-soft-components.ts
@@ -4563,6 +4552,7 @@ export {
4563
4552
  Drawer,
4564
4553
  DrawerItem,
4565
4554
  Header,
4555
+ HeaderActions,
4566
4556
  Modal,
4567
4557
  SoftConfigProvider,
4568
4558
  applyMapping,