astro-tractstack 2.2.8 → 2.2.10

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-tractstack",
3
- "version": "2.2.8",
3
+ "version": "2.2.10",
4
4
  "description": "Astro integration for TractStack - the free web press by At Risk Media",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -132,21 +132,32 @@ const AddPaneNewPanel = ({
132
132
  insertTemplate.title = '';
133
133
  insertTemplate.slug = '';
134
134
 
135
+ let newPaneId: string | undefined | null;
136
+
135
137
  if (isContextPane) {
136
138
  insertTemplate.isContextPane = true;
137
- ctx.addContextTemplatePane(ownerId, insertTemplate);
139
+ newPaneId = ctx.addContextTemplatePane(ownerId, insertTemplate);
138
140
  } else {
139
- ctx.addTemplatePane(
141
+ newPaneId = ctx.addTemplatePane(
140
142
  ownerId,
141
143
  insertTemplate,
142
144
  nodeId,
143
145
  first ? 'before' : 'after'
144
146
  );
147
+
145
148
  const storyFragment = cloneDeep(
146
149
  ctx.allNodes.get().get(ownerId)
147
150
  ) as StoryFragmentNode;
148
151
  ctx.modifyNodes([{ ...storyFragment }]);
149
152
  }
153
+
154
+ if (newPaneId) {
155
+ const newPane = ctx.allNodes.get().get(newPaneId);
156
+ if (newPane) {
157
+ ctx.modifyNodes([{ ...newPane }]);
158
+ }
159
+ }
160
+
150
161
  ctx.notifyNode(`root`);
151
162
  setParentMode(PaneAddMode.DEFAULT, false);
152
163
  } catch (err) {
@@ -2451,8 +2451,14 @@ export class NodesContext {
2451
2451
  .get()
2452
2452
  .get(parentId) as StoryFragmentNode;
2453
2453
  if (storyFragment) {
2454
- paneIdx = storyFragment.paneIds.indexOf(targetNodeId);
2455
- storyFragment.paneIds.splice(paneIdx, 1);
2454
+ // Use modifyNodes to ensure StoryFragment is marked dirty (isChanged: true)
2455
+ // We disable history recording here because we create a specific REMOVE patch below
2456
+ const updatedFragment = cloneDeep(storyFragment);
2457
+ paneIdx = updatedFragment.paneIds.indexOf(targetNodeId);
2458
+ if (paneIdx !== -1) {
2459
+ updatedFragment.paneIds.splice(paneIdx, 1);
2460
+ this.modifyNodes([updatedFragment], { recordHistory: false });
2461
+ }
2456
2462
  }
2457
2463
  } else if (targetNode.nodeType === 'TagElement') {
2458
2464
  // mark pane as changed
@@ -2488,16 +2494,35 @@ export class NodesContext {
2488
2494
  undo: (ctx) => {
2489
2495
  ctx.addNodes(toDelete);
2490
2496
  if (targetNode.nodeType === 'Pane' && parentId !== null) {
2491
- const storyFragment = this.allNodes
2497
+ const storyFragment = ctx.allNodes
2498
+ .get()
2499
+ .get(parentId) as StoryFragmentNode;
2500
+ if (storyFragment) {
2501
+ // Use modifyNodes in Undo to correctly restore state and links
2502
+ const updatedFragment = cloneDeep(storyFragment);
2503
+ updatedFragment.paneIds.splice(paneIdx, 0, targetNodeId);
2504
+ ctx.modifyNodes([updatedFragment], { recordHistory: false });
2505
+ ctx.linkChildToParent(targetNodeId, parentId, paneIdx);
2506
+ }
2507
+ }
2508
+ },
2509
+ redo: (ctx) => {
2510
+ ctx.deleteNodes(toDelete);
2511
+ // Ensure Redo also updates the parent StoryFragment correctly
2512
+ if (targetNode.nodeType === 'Pane' && parentId !== null) {
2513
+ const storyFragment = ctx.allNodes
2492
2514
  .get()
2493
2515
  .get(parentId) as StoryFragmentNode;
2494
2516
  if (storyFragment) {
2495
- storyFragment.paneIds.splice(paneIdx, 0, targetNodeId);
2496
- this.linkChildToParent(targetNodeId, parentId, paneIdx);
2517
+ const updatedFragment = cloneDeep(storyFragment);
2518
+ const idx = updatedFragment.paneIds.indexOf(targetNodeId);
2519
+ if (idx !== -1) {
2520
+ updatedFragment.paneIds.splice(idx, 1);
2521
+ ctx.modifyNodes([updatedFragment], { recordHistory: false });
2522
+ }
2497
2523
  }
2498
2524
  }
2499
2525
  },
2500
- redo: (ctx) => ctx.deleteNodes(toDelete),
2501
2526
  });
2502
2527
  }
2503
2528
  }