@orion-studios/payload-studio 0.6.0-beta.122 → 0.6.0-beta.124

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.
@@ -828,6 +828,15 @@ var snapshotModel = (model, emptyListAttr) => {
828
828
  if (emptyListAttr && !attributes[emptyListAttr]) {
829
829
  attributes[emptyListAttr] = "[]";
830
830
  }
831
+ if (emptyListAttr === "data-orion-items-json") {
832
+ const block = parseJsonRecord(attributes["data-orion-block"]);
833
+ if (Object.keys(block).length > 0) {
834
+ attributes["data-orion-block"] = serializeJsonRecord({
835
+ ...block,
836
+ items: parseJsonArray(attributes[emptyListAttr])
837
+ });
838
+ }
839
+ }
831
840
  return {
832
841
  attributes,
833
842
  style: { ...model.getStyle?.() || {} }
@@ -2177,16 +2186,28 @@ function GrapesPageEditor({
2177
2186
  const currentItems = parseItemsJson(attrs["data-orion-items-json"]);
2178
2187
  const nextItems = updater(currentItems);
2179
2188
  const block = parseOrionBlockAttribute(attrs["data-orion-block"]);
2180
- component.addAttributes?.({
2181
- "data-orion-items-json": JSON.stringify(nextItems),
2182
- ...Object.keys(block).length > 0 ? {
2183
- "data-orion-block": serializeOrionBlockAttribute({
2189
+ const before = snapshotComponent(component);
2190
+ if (before && currentItems.length === 0) {
2191
+ before.attributes["data-orion-items-json"] = "[]";
2192
+ if (Object.keys(block).length > 0) {
2193
+ before.attributes["data-orion-block"] = serializeOrionBlockAttribute({
2184
2194
  ...block,
2185
- items: nextItems
2186
- })
2187
- } : {}
2195
+ items: []
2196
+ });
2197
+ }
2198
+ }
2199
+ withoutUndoTracking2(() => {
2200
+ component.addAttributes?.({
2201
+ "data-orion-items-json": JSON.stringify(nextItems),
2202
+ ...Object.keys(block).length > 0 ? {
2203
+ "data-orion-block": serializeOrionBlockAttribute({
2204
+ ...block,
2205
+ items: nextItems
2206
+ })
2207
+ } : {}
2208
+ });
2188
2209
  });
2189
- rememberComponentSnapshot(component);
2210
+ pushCustomHistoryEntry(before, snapshotComponent(component));
2190
2211
  setSelectionSummary(summarizeSelectedComponent(component));
2191
2212
  };
2192
2213
  const refreshSelectedState = (component) => {
@@ -2623,6 +2644,23 @@ function GrapesPageEditor({
2623
2644
  return snapshot;
2624
2645
  };
2625
2646
  const getPreviousComponentSnapshot = (component) => component ? lastComponentSnapshotRef.current.get(component) || snapshotComponent(component) : null;
2647
+ const withoutUndoTracking2 = (callback) => {
2648
+ const undoManager = editorRef.current?.UndoManager;
2649
+ if (typeof undoManager?.skip === "function") {
2650
+ undoManager.skip(callback);
2651
+ return;
2652
+ }
2653
+ if (typeof undoManager?.stop === "function" && typeof undoManager?.start === "function") {
2654
+ undoManager.stop();
2655
+ try {
2656
+ callback();
2657
+ } finally {
2658
+ undoManager.start();
2659
+ }
2660
+ return;
2661
+ }
2662
+ callback();
2663
+ };
2626
2664
  const isComponentAttached = (component) => Boolean(component.parent?.());
2627
2665
  const addComponentFromSnapshot = (snapshot) => {
2628
2666
  const parent = snapshot.parent;
@@ -704,6 +704,15 @@ var snapshotModel = (model, emptyListAttr) => {
704
704
  if (emptyListAttr && !attributes[emptyListAttr]) {
705
705
  attributes[emptyListAttr] = "[]";
706
706
  }
707
+ if (emptyListAttr === "data-orion-items-json") {
708
+ const block = parseJsonRecord(attributes["data-orion-block"]);
709
+ if (Object.keys(block).length > 0) {
710
+ attributes["data-orion-block"] = serializeJsonRecord({
711
+ ...block,
712
+ items: parseJsonArray(attributes[emptyListAttr])
713
+ });
714
+ }
715
+ }
707
716
  return {
708
717
  attributes,
709
718
  style: { ...model.getStyle?.() || {} }
@@ -2053,16 +2062,28 @@ function GrapesPageEditor({
2053
2062
  const currentItems = parseItemsJson(attrs["data-orion-items-json"]);
2054
2063
  const nextItems = updater(currentItems);
2055
2064
  const block = parseOrionBlockAttribute(attrs["data-orion-block"]);
2056
- component.addAttributes?.({
2057
- "data-orion-items-json": JSON.stringify(nextItems),
2058
- ...Object.keys(block).length > 0 ? {
2059
- "data-orion-block": serializeOrionBlockAttribute({
2065
+ const before = snapshotComponent(component);
2066
+ if (before && currentItems.length === 0) {
2067
+ before.attributes["data-orion-items-json"] = "[]";
2068
+ if (Object.keys(block).length > 0) {
2069
+ before.attributes["data-orion-block"] = serializeOrionBlockAttribute({
2060
2070
  ...block,
2061
- items: nextItems
2062
- })
2063
- } : {}
2071
+ items: []
2072
+ });
2073
+ }
2074
+ }
2075
+ withoutUndoTracking2(() => {
2076
+ component.addAttributes?.({
2077
+ "data-orion-items-json": JSON.stringify(nextItems),
2078
+ ...Object.keys(block).length > 0 ? {
2079
+ "data-orion-block": serializeOrionBlockAttribute({
2080
+ ...block,
2081
+ items: nextItems
2082
+ })
2083
+ } : {}
2084
+ });
2064
2085
  });
2065
- rememberComponentSnapshot(component);
2086
+ pushCustomHistoryEntry(before, snapshotComponent(component));
2066
2087
  setSelectionSummary(summarizeSelectedComponent(component));
2067
2088
  };
2068
2089
  const refreshSelectedState = (component) => {
@@ -2499,6 +2520,23 @@ function GrapesPageEditor({
2499
2520
  return snapshot;
2500
2521
  };
2501
2522
  const getPreviousComponentSnapshot = (component) => component ? lastComponentSnapshotRef.current.get(component) || snapshotComponent(component) : null;
2523
+ const withoutUndoTracking2 = (callback) => {
2524
+ const undoManager = editorRef.current?.UndoManager;
2525
+ if (typeof undoManager?.skip === "function") {
2526
+ undoManager.skip(callback);
2527
+ return;
2528
+ }
2529
+ if (typeof undoManager?.stop === "function" && typeof undoManager?.start === "function") {
2530
+ undoManager.stop();
2531
+ try {
2532
+ callback();
2533
+ } finally {
2534
+ undoManager.start();
2535
+ }
2536
+ return;
2537
+ }
2538
+ callback();
2539
+ };
2502
2540
  const isComponentAttached = (component) => Boolean(component.parent?.());
2503
2541
  const addComponentFromSnapshot = (snapshot) => {
2504
2542
  const parent = snapshot.parent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-studios/payload-studio",
3
- "version": "0.6.0-beta.122",
3
+ "version": "0.6.0-beta.124",
4
4
  "description": "Base CMS, builder, and custom admin toolkit for Orion Studios websites",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",