@netlisian/softconfig 0.1.6 → 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
@@ -1589,26 +1589,18 @@ var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
1589
1589
  var toSlug = (value) => {
1590
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, "");
1591
1591
  };
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(" ");
1592
+ var slugTolabel = (name) => {
1593
+ return name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1602
1594
  };
1603
- var createComponentKeyFromName = (displayName, overrides, context) => {
1604
- const key = overrides.componentNameToKey ? overrides.componentNameToKey(displayName, context) : defaultComponentNameToKey(displayName, context);
1595
+ var componentNameFromLabel = (label, overrides, context) => {
1596
+ const key = overrides.componentLabelToName ? overrides.componentLabelToName(label, context) : toSlug(label);
1605
1597
  return key.trim();
1606
1598
  };
1607
- var getComponentNameFromKey = (key, overrides) => {
1608
- if (overrides == null ? void 0 : overrides.componentKeyToName) {
1609
- return overrides.componentKeyToName(key);
1599
+ var componentLabelFromName = (name, overrides) => {
1600
+ if (overrides == null ? void 0 : overrides.componentNameToLabel) {
1601
+ return overrides.componentNameToLabel(name);
1610
1602
  }
1611
- return defaultComponentKeyToName(key);
1603
+ return slugTolabel(name);
1612
1604
  };
1613
1605
 
1614
1606
  // src/puck/lib/soft-component-to-appstate.ts
@@ -1804,7 +1796,7 @@ var softComponentToAppState = (softComponent, componentName, version, versions,
1804
1796
  mergedFieldSettings[field.name] = settings;
1805
1797
  });
1806
1798
  let rootProps = __spreadValues({
1807
- _name: displayName || getComponentNameFromKey(componentName, overrides),
1799
+ _name: displayName || componentLabelFromName(componentName, overrides),
1808
1800
  _category: category,
1809
1801
  _version: version,
1810
1802
  _versions: versions,
@@ -2009,14 +2001,12 @@ var hydrateCustomField = (fieldName, field, fieldSettings, customFields) => {
2009
2001
  };
2010
2002
  var createVersionedComponentConfig = (componentName, displayName, version, allVersions, config, softComponents, defaultProps, showVersioning = true, customFields, overrides) => {
2011
2003
  var _a, _b;
2012
- const baseConfig = {
2004
+ return {
2013
2005
  label: displayName,
2014
2006
  fields: Object.fromEntries(
2015
2007
  (Object.entries(
2016
2008
  (_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)])
2009
+ ) || []).filter(([key, field]) => field.type === "slot").map(([key, field]) => [key, __spreadValues({}, field)])
2020
2010
  ),
2021
2011
  defaultProps: __spreadProps(__spreadValues({}, defaultProps), {
2022
2012
  version
@@ -2059,10 +2049,6 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
2059
2049
  );
2060
2050
  }
2061
2051
  };
2062
- if (overrides == null ? void 0 : overrides.mapComponentConfig) {
2063
- return __spreadValues(__spreadValues({}, baseConfig), overrides.mapComponentConfig(componentName, baseConfig));
2064
- }
2065
- return baseConfig;
2066
2052
  };
2067
2053
 
2068
2054
  // src/puck/lib/builder/sub-component-decomposer.tsx
@@ -2183,6 +2169,61 @@ function demolishSoftComponent(componentName, data, config, softComponents) {
2183
2169
  };
2184
2170
  }
2185
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
+
2186
2227
  // src/puck/store/slices/builder.tsx
2187
2228
  var createBuildersSlice = (set, get, initialConfig) => ({
2188
2229
  build: (history, selectedItem, itemSelector, puckDispatch, name) => {
@@ -2233,6 +2274,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2233
2274
  return components;
2234
2275
  }
2235
2276
  );
2277
+ requestAnimationFrame(
2278
+ () => setEditVisibility(get().iframeDoc, {
2279
+ mode: "build",
2280
+ editableIds
2281
+ })
2282
+ );
2236
2283
  set((s) => __spreadProps(__spreadValues({}, s), {
2237
2284
  softConfig: buildConfig,
2238
2285
  storedConfig: config,
@@ -2245,15 +2292,14 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2245
2292
  editableComponentIds: editableIds,
2246
2293
  state: "building"
2247
2294
  }));
2248
- setTimeout(
2295
+ requestAnimationFrame(
2249
2296
  () => puckDispatch({
2250
2297
  type: "replaceRoot",
2251
2298
  root: {
2252
2299
  title: "Soft Component Builder",
2253
2300
  _name: name || "New Soft Component"
2254
2301
  }
2255
- }),
2256
- 100
2302
+ })
2257
2303
  );
2258
2304
  },
2259
2305
  remodel: (history, selectedItem, itemSelector, puckDispatch) => {
@@ -2341,6 +2387,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2341
2387
  }).content
2342
2388
  })
2343
2389
  });
2390
+ requestAnimationFrame(
2391
+ () => setEditVisibility(get().iframeDoc, {
2392
+ mode: "remodel",
2393
+ editableIds
2394
+ })
2395
+ );
2344
2396
  set((s) => __spreadProps(__spreadValues({}, s), {
2345
2397
  storedConfig: config,
2346
2398
  softConfig: buildConfig,
@@ -2354,7 +2406,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2354
2406
  editableComponentIds: editableIds,
2355
2407
  state: "remodeling"
2356
2408
  }));
2357
- setTimeout(
2409
+ requestAnimationFrame(
2358
2410
  () => puckDispatch({
2359
2411
  type: "replaceRoot",
2360
2412
  root: {
@@ -2362,8 +2414,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2362
2414
  _name: root.props._name,
2363
2415
  _category: root.props._category
2364
2416
  }
2365
- }),
2366
- 100
2417
+ })
2367
2418
  );
2368
2419
  },
2369
2420
  complete: (appState, setHistories, getItemBySelector) => {
@@ -2379,34 +2430,34 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2379
2430
  if (!itemSelector) {
2380
2431
  throw new Error("No item selector found for completed component.");
2381
2432
  }
2382
- const selectedItem = getItemBySelector(
2383
- itemSelector
2384
- );
2433
+ const selectedItem = getItemBySelector(itemSelector);
2385
2434
  if (!selectedItem) {
2386
2435
  throw new Error("Cannot find item being edited");
2387
2436
  }
2388
2437
  const rootCategory = (_e = (_d = appState.data.root) == null ? void 0 : _d.props) == null ? void 0 : _e._category;
2389
2438
  const rootProps = (_f = appState.data.root) == null ? void 0 : _f.props;
2390
- const componentName = createComponentKeyFromName(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2439
+ const componentName = componentNameFromLabel(displayName, get().overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
2391
2440
  existingKeys: Object.keys(get().softComponents),
2392
2441
  state: get().state
2393
2442
  }));
2394
2443
  if (!componentName) {
2395
2444
  throw new Error("Failed to generate component key from name.");
2396
2445
  }
2397
- const [newSoftComponentConfig, version] = get().builder.compose(
2446
+ const [defaultSoftComponentConfig, version] = get().builder.compose(
2398
2447
  appState,
2399
2448
  componentName,
2400
2449
  selectedItem,
2401
2450
  displayName,
2402
2451
  rootCategory
2403
2452
  ) || [];
2404
- if (!newSoftComponentConfig) {
2453
+ if (!defaultSoftComponentConfig) {
2405
2454
  throw new Error("Failed to compose new soft component config.");
2406
2455
  }
2407
2456
  const storedHistories = get().originalHistory;
2408
2457
  setHistories([...storedHistories]);
2409
2458
  const config = __spreadValues({}, get().softConfig || initialConfig);
2459
+ const mapComponentConfig = get().overrides.mapComponentConfig;
2460
+ const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
2410
2461
  set((s) => {
2411
2462
  var _a2, _b2;
2412
2463
  const nextComponents = __spreadProps(__spreadValues({}, Object.entries(config.components).reduce(
@@ -2448,10 +2499,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2448
2499
  }),
2449
2500
  storedConfig: void 0,
2450
2501
  state: "inspecting",
2451
- originalHistory: [],
2452
- editingComponent: null,
2453
- editingComponentId: null,
2454
- editableComponentIds: /* @__PURE__ */ new Set()
2502
+ originalHistory: []
2455
2503
  });
2456
2504
  });
2457
2505
  if (!version) {
@@ -2478,30 +2526,44 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2478
2526
  if ((selector == null ? void 0 : selector.index) === void 0 || !(selector == null ? void 0 : selector.zone)) {
2479
2527
  throw new Error("No selector found for last item.");
2480
2528
  }
2481
- setTimeout(() => {
2482
- puckDispatch({
2483
- type: "remove",
2484
- index: selector.index,
2485
- 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
+ });
2486
2545
  });
2487
2546
  puckDispatch({
2488
- type: "insert",
2489
- destinationIndex: selector.index,
2490
- destinationZone: selector.zone,
2491
- componentType: componentName
2547
+ type: "setData",
2548
+ data: (data) => {
2549
+ return reconstructedTree(data);
2550
+ }
2492
2551
  });
2493
- }, 500);
2552
+ });
2553
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2494
2554
  set((s) => __spreadProps(__spreadValues({}, s), {
2495
2555
  state: "ready",
2496
2556
  setItemSelector: void 0,
2497
2557
  setOriginalItem: void 0,
2558
+ editingComponent: null,
2498
2559
  editingComponentId: null,
2499
2560
  editableComponentIds: /* @__PURE__ */ new Set()
2500
2561
  }));
2501
2562
  },
2502
2563
  cancel: (setHistories) => {
2503
2564
  const storedHistories = get().originalHistory;
2504
- setTimeout(() => setHistories([...storedHistories]), 100);
2565
+ requestAnimationFrame(() => setHistories([...storedHistories]));
2566
+ requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
2505
2567
  set((s) => __spreadProps(__spreadValues({}, s), {
2506
2568
  softConfig: get().storedConfig || initialConfig,
2507
2569
  storedConfig: void 0,
@@ -2830,74 +2892,12 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
2830
2892
  }
2831
2893
  }
2832
2894
 
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
2895
  // src/puck/store/index.tsx
2889
- var createSoftConfigStore = (hardConfig = {
2890
- components: {}
2891
- }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2896
+ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2892
2897
  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
- ])
2898
+ Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
2899
2899
  );
2900
- const iframeDocRef = { current: null };
2900
+ const iframeDoc = null;
2901
2901
  const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
2902
2902
  normalizedSoftComponents,
2903
2903
  overrides.hydrateMapTransform
@@ -2906,323 +2906,369 @@ var createSoftConfigStore = (hardConfig = {
2906
2906
  hydratedSoftComponents
2907
2907
  );
2908
2908
  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;
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;
2925
2967
  }
2926
- const { state, editableComponentIds } = get();
2927
- if (state === "building") {
2928
- setEditVisibility(doc, {
2929
- mode: "build",
2930
- editableIds: editableComponentIds
2931
- });
2932
- 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;
2933
2971
  }
2934
- if (state === "remodeling") {
2935
- setEditVisibility(doc, {
2936
- mode: "remodel",
2937
- editableIds: editableComponentIds
2938
- });
2939
- return;
2972
+ if (parentId && editableComponentIds.has(parentId)) {
2973
+ addEditableComponentId(action.data.props.id);
2974
+ return true;
2940
2975
  }
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;
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);
2966
2985
  }
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
- })
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
2979
3015
  })
2980
3016
  })
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
3017
  })
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
- })
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.`
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
3048
+ );
3049
+ }
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
3064
3078
  );
3065
3079
  }
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
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.`
3076
3093
  );
3077
- set((state) => ({
3078
- softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
3079
- components: __spreadProps(__spreadValues({}, state.softConfig.components), {
3080
- [name]: newSoftComponentConfig
3081
- })
3082
- }),
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 {
3083
3134
  softComponents: __spreadProps(__spreadValues({}, state.softComponents), {
3084
- [name]: __spreadProps(__spreadValues({}, state.softComponents[name]), {
3085
- defaultVersion: version
3135
+ [key]: __spreadProps(__spreadValues({}, component), {
3136
+ versions: newVersions,
3137
+ defaultVersion: newDefaultVersion
3086
3138
  })
3087
3139
  })
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) => ({
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 {
3143
3152
  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)
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
+ ]
3159
3162
  })
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
- )
3163
+ }) : state.softConfig.categories || {}
3172
3164
  })
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 }));
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
+ );
3218
3222
  }
3219
- })
3220
- )
3223
+ set((s) => __spreadProps(__spreadValues({}, s), { softConfig: nextConfig }));
3224
+ }
3225
+ }))
3221
3226
  );
3222
3227
  };
3223
3228
 
3224
3229
  // src/puck/context/storeProvider.tsx
3225
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
3226
3272
  import { jsx as jsx7 } from "react/jsx-runtime";
3227
3273
  var SoftConfigProvider = ({
3228
3274
  children,
@@ -3258,57 +3304,8 @@ var SoftConfigProvider = ({
3258
3304
  const [internalSoftComponents, setSoftComponents] = useState(
3259
3305
  () => store.getState().softComponents
3260
3306
  );
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]
3307
+ const [actionGuard, setActionGuard] = useState(
3308
+ (action) => null
3312
3309
  );
3313
3310
  useEffect2(() => {
3314
3311
  const unsubscribe = store.subscribe(() => {
@@ -3321,59 +3318,26 @@ var SoftConfigProvider = ({
3321
3318
  }, [store]);
3322
3319
  useEffect2(() => {
3323
3320
  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 });
3321
+ if (prevState && prevState.undoFn === state.undoFn) {
3331
3322
  return;
3332
3323
  }
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
- });
3324
+ setActionGuard(
3325
+ () => createActionCallback(
3326
+ state.validateAction,
3327
+ state.undoFn
3328
+ )
3329
+ );
3343
3330
  });
3344
3331
  return () => {
3345
3332
  unsubscribe();
3346
3333
  };
3347
- }, [store]);
3348
- 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) });
3349
3336
  };
3350
3337
 
3351
3338
  // src/puck/actions/useBuild.tsx
3352
3339
  import { createUsePuck as createUsePuck2 } from "@measured/puck";
3353
3340
 
3354
- // src/puck/lib/notify.ts
3355
- var customHandler = null;
3356
- var defaultHandler = (message, type) => {
3357
- if (type === "error") {
3358
- console.error(`[Error] ${message}`);
3359
- } else {
3360
- console.log(`[Success] ${message}`);
3361
- }
3362
- };
3363
- var setNotificationHandler = (handler) => {
3364
- customHandler = handler;
3365
- };
3366
- var notify = {
3367
- error: (message) => {
3368
- const handler = customHandler || defaultHandler;
3369
- handler(message, "error");
3370
- },
3371
- success: (message) => {
3372
- const handler = customHandler || defaultHandler;
3373
- handler(message, "success");
3374
- }
3375
- };
3376
-
3377
3341
  // src/puck/hooks/useActionEvent.ts
3378
3342
  import { useCallback } from "react";
3379
3343
  var useActionEvent = () => {
@@ -3751,7 +3715,7 @@ var useSetDefaultVersion = () => {
3751
3715
  // src/puck/overrides/Header.tsx
3752
3716
  import { Button, createUsePuck as createUsePuck10 } from "@measured/puck";
3753
3717
 
3754
- // 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
3755
3719
  var Header_module_default = { "Header": "_Header_19oj9_1" };
3756
3720
 
3757
3721
  // src/puck/actions/usePublish.tsx
@@ -3800,7 +3764,6 @@ var Header = ({
3800
3764
  const { handleComplete, newComponent, setNewComponent } = useComplete();
3801
3765
  const { handleCancel, canCancel } = useCancel();
3802
3766
  const { handlePublish } = usePublish();
3803
- const puck = usePuck((s) => s.config);
3804
3767
  useInspect(newComponent);
3805
3768
  return /* @__PURE__ */ jsx8("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
3806
3769
  /* @__PURE__ */ jsx8(Button, { onClick: handleCancel, children: "Cancel" }),
@@ -3836,7 +3799,7 @@ import { useMemo as useMemo3 } from "react";
3836
3799
  import { ActionBar, createUsePuck as createUsePuck11 } from "@measured/puck";
3837
3800
  import { Combine, ComponentIcon, EditIcon } from "lucide-react";
3838
3801
 
3839
- // 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
3840
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" };
3841
3804
 
3842
3805
  // src/puck/overrides/ActionBar.tsx
@@ -3862,7 +3825,7 @@ var ActionBarOverride = (props) => {
3862
3825
  if (selectedType && softKeys.includes(selectedType)) {
3863
3826
  return selectedType;
3864
3827
  }
3865
- return createComponentKeyFromName(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3828
+ return componentNameFromLabel(props.label || "", overrides, __spreadProps(__spreadValues({}, rootProps || {}), {
3866
3829
  existingKeys: softKeys,
3867
3830
  state: status
3868
3831
  }));
@@ -3878,17 +3841,17 @@ var ActionBarOverride = (props) => {
3878
3841
  const selectedId = (_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.id;
3879
3842
  const parentId = (_b = itemSelector == null ? void 0 : itemSelector.zone) == null ? void 0 : _b.split(":")[0];
3880
3843
  const isEditable = Boolean(selectedId && (editableIds.has(selectedId) || parentId && editableIds.has(parentId)));
3881
- const displayName = useMemo3(() => {
3844
+ const label = useMemo3(() => {
3882
3845
  var _a2;
3883
3846
  if (isSoftComponent2) {
3884
- 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);
3885
3848
  }
3886
3849
  return props.label || "";
3887
3850
  }, [isSoftComponent2, key, props.label, overrides, softComponents]);
3888
3851
  return /* @__PURE__ */ jsx9("div", { className: getClassName3(), children: /* @__PURE__ */ jsxs3(ActionBar, { children: [
3889
3852
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3890
3853
  props.parentAction,
3891
- /* @__PURE__ */ jsx9(ActionBar.Label, { label: displayName })
3854
+ /* @__PURE__ */ jsx9(ActionBar.Label, { label })
3892
3855
  ] }),
3893
3856
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3894
3857
  status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(Fragment4, { children: [
@@ -3943,14 +3906,14 @@ var confirm = (message) => __async(null, null, function* () {
3943
3906
  }
3944
3907
  });
3945
3908
 
3946
- // 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
3947
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" };
3948
3911
 
3949
3912
  // src/puck/components/modal/index.tsx
3950
3913
  import { useEffect as useEffect4, useState as useState3 } from "react";
3951
3914
  import { createPortal } from "react-dom";
3952
3915
 
3953
- // 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
3954
3917
  var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
3955
3918
 
3956
3919
  // src/puck/components/modal/index.tsx
@@ -4185,6 +4148,7 @@ var DrawerItem = (props) => {
4185
4148
  return /* @__PURE__ */ jsxs4(
4186
4149
  "button",
4187
4150
  {
4151
+ "aria-label": target.label,
4188
4152
  type: "button",
4189
4153
  role: "radio",
4190
4154
  "aria-checked": isSelected,
@@ -4235,7 +4199,7 @@ import { useState as useState5 } from "react";
4235
4199
  import { createUsePuck as createUsePuck13, Drawer as PuckDrawer } from "@measured/puck";
4236
4200
  import { ChevronDown, ChevronUp } from "lucide-react";
4237
4201
 
4238
- // 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
4239
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" };
4240
4204
 
4241
4205
  // src/puck/overrides/Drawer.tsx
@@ -4347,25 +4311,37 @@ var Drawer = (_props) => {
4347
4311
  ] });
4348
4312
  };
4349
4313
 
4350
- // src/puck/lib/action-callback.ts
4351
- var createActionCallback = (validateAction, undo) => {
4352
- return (action) => {
4353
- const isValid = validateAction(action);
4354
- if (!isValid) {
4355
- notify.error(
4356
- "Editing outside the soft component is not allowed when you are editing component definition."
4357
- );
4358
- if (typeof requestAnimationFrame === "function") {
4359
- requestAnimationFrame(() => {
4360
- requestAnimationFrame(() => {
4361
- undo();
4362
- });
4363
- });
4364
- } else {
4365
- 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"
4366
4342
  }
4367
- }
4368
- };
4343
+ )
4344
+ ] }) : children });
4369
4345
  };
4370
4346
 
4371
4347
  // src/puck/lib/dissolve-all-soft-components.ts
@@ -4576,6 +4552,7 @@ export {
4576
4552
  Drawer,
4577
4553
  DrawerItem,
4578
4554
  Header,
4555
+ HeaderActions,
4579
4556
  Modal,
4580
4557
  SoftConfigProvider,
4581
4558
  applyMapping,