@marimo-team/islands 0.23.7-dev16 → 0.23.7-dev17

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.
Files changed (56) hide show
  1. package/dist/{ConnectedDataExplorerComponent-DnRhpPMJ.js → ConnectedDataExplorerComponent-2lBNiUv6.js} +13 -13
  2. package/dist/{ErrorBoundary-Da4UeYxT.js → ErrorBoundary-D3wrPNma.js} +1 -1
  3. package/dist/{any-language-editor-DDubl8YH.js → any-language-editor-VWs_7v27.js} +5 -5
  4. package/dist/{button-CA5pI2YF.js → button-Dj4BTre0.js} +5 -0
  5. package/dist/{capabilities-6laDasij.js → capabilities-C9rrYCzf.js} +1 -1
  6. package/dist/{chat-ui-BmWZZ3mE.js → chat-ui-Cf4tuQ8s.js} +16 -16
  7. package/dist/{check-CFM2mVDr.js → check-BcUIXnUT.js} +1 -1
  8. package/dist/{code-visibility-BTdq0PKn.js → code-visibility-god-8ESC.js} +21 -21
  9. package/dist/{copy-TGGAUEWp.js → copy-DLf4aN7I.js} +2 -2
  10. package/dist/{dist-ESg7xyoD.js → dist-D3ZI9nhS.js} +2 -2
  11. package/dist/{error-banner-DnBPzEWg.js → error-banner-CVkfBUT3.js} +2 -2
  12. package/dist/{esm-Dd1z1auZ.js → esm-CWp0KQeK.js} +1 -1
  13. package/dist/{extends-CzJgxo2J.js → extends-vAi97cpa.js} +4 -4
  14. package/dist/{formats-CgaK7Gmx.js → formats-CpgZM9BM.js} +3 -3
  15. package/dist/{glide-data-editor-B-3A3G02.js → glide-data-editor-BK9s_dqy.js} +9 -9
  16. package/dist/{html-to-image-BwZL1Pkk.js → html-to-image-q0T1ijn_.js} +2213 -2143
  17. package/dist/{input-BAOe64zx.js → input-Cc1Vvw9A.js} +6 -6
  18. package/dist/{label-BCWi-Oqu.js → label-BLqV33b1.js} +2 -2
  19. package/dist/{loader-BvW0-YWZ.js → loader-Dr8Qem8p.js} +1 -1
  20. package/dist/main.js +33 -33
  21. package/dist/{mermaid-cXSZ1pfD.js → mermaid-DO-Daq7u.js} +5 -5
  22. package/dist/{process-output-lpVrk7d5.js → process-output-DTKS9bKk.js} +3 -3
  23. package/dist/{reveal-component-CMK1wxUM.js → reveal-component-vPlC5Eve.js} +9 -9
  24. package/dist/{spec-DSIuqd3f.js → spec-hVaaZsY5.js} +4 -4
  25. package/dist/{strings-B_FOH6eV.js → strings-BiIhGaI8.js} +4 -4
  26. package/dist/{swiper-component-BHs0PWwp.js → swiper-component-DlD2GU2g.js} +2 -2
  27. package/dist/{toDate-CHtl9vts.js → toDate-CJWlVNGD.js} +3 -3
  28. package/dist/{tooltip-B0mtKTXm.js → tooltip-DRaMBu06.js} +3 -3
  29. package/dist/{types-DBtDeUKD.js → types-Dzuoc3LN.js} +1 -1
  30. package/dist/{useAsyncData-B6hCGywC.js → useAsyncData-C56Khv_R.js} +1 -1
  31. package/dist/{useDateFormatter-B3mCQMP3.js → useDateFormatter-B_9k85Ex.js} +2 -2
  32. package/dist/{useDeepCompareMemoize-CmwDuYUH.js → useDeepCompareMemoize-Dt98v2ua.js} +1 -1
  33. package/dist/{useIframeCapabilities-DbdLoEDm.js → useIframeCapabilities-BkYHTrss.js} +1 -1
  34. package/dist/{useLifecycle-CjMjllqy.js → useLifecycle-BF6-z62y.js} +3 -3
  35. package/dist/{useTheme-CByZUW0p.js → useTheme-DykuNHR2.js} +2 -2
  36. package/dist/{vega-component-C2BYPkfd.js → vega-component-BtvQ-Kc4.js} +10 -10
  37. package/dist/{zod-BxdsqRPd.js → zod-BWkcDORu.js} +1 -1
  38. package/package.json +1 -1
  39. package/src/components/editor/actions/useNotebookActions.tsx +3 -1
  40. package/src/components/editor/controls/Controls.tsx +3 -1
  41. package/src/components/editor/navigation/__tests__/clipboard.test.ts +107 -0
  42. package/src/components/editor/navigation/__tests__/navigation.test.ts +70 -0
  43. package/src/components/editor/navigation/clipboard.ts +101 -23
  44. package/src/components/editor/navigation/navigation.ts +15 -1
  45. package/src/components/editor/notebook-cell.tsx +3 -0
  46. package/src/core/cells/__tests__/cells.test.ts +187 -0
  47. package/src/core/cells/__tests__/pending-cut-service.test.tsx +145 -0
  48. package/src/core/cells/cells.ts +102 -17
  49. package/src/core/cells/document-changes.ts +6 -1
  50. package/src/core/cells/pending-cut-service.ts +64 -0
  51. package/src/core/cells/utils.ts +11 -0
  52. package/src/core/codemirror/cells/extensions.ts +10 -0
  53. package/src/core/hotkeys/hotkeys.ts +5 -0
  54. package/src/css/app/Cell.css +13 -0
  55. package/src/utils/__tests__/id-tree.test.ts +71 -0
  56. package/src/utils/id-tree.tsx +89 -0
@@ -20,6 +20,18 @@ vi.mock("@/utils/Logger", () => ({
20
20
  Logger: Mocks.quietLogger(),
21
21
  }));
22
22
 
23
+ const mockClearPendingCut = vi.hoisted(() => vi.fn());
24
+ vi.mock("@/core/cells/pending-cut-service", () => ({
25
+ usePendingCutActions: () => ({
26
+ markForCut: vi.fn(),
27
+ clear: mockClearPendingCut,
28
+ }),
29
+ usePendingCutState: () => ({
30
+ cellIds: new Set(),
31
+ clipboardData: null,
32
+ }),
33
+ }));
34
+
23
35
  import { MockNotebook } from "@/__mocks__/notebook";
24
36
  import { toast } from "@/components/ui/use-toast";
25
37
  import { getNotebook, useCellActions } from "@/core/cells/cells";
@@ -198,6 +210,101 @@ describe("useCellClipboard", () => {
198
210
  description: "Cell has been copied to clipboard.",
199
211
  });
200
212
  });
213
+
214
+ it("should clear pending cut when copy succeeds", async () => {
215
+ const { result } = renderHook(() => useCellClipboard());
216
+
217
+ await act(async () => {
218
+ await result.current.copyCells([mockCellId1]);
219
+ });
220
+
221
+ expect(mockClearPendingCut).toHaveBeenCalled();
222
+ });
223
+
224
+ it("should clear pending cut when copy falls back to writeText", async () => {
225
+ mockClipboard.write.mockRejectedValue(new Error("Write failed"));
226
+ mockClipboard.writeText.mockResolvedValue(undefined);
227
+
228
+ const { result } = renderHook(() => useCellClipboard());
229
+
230
+ await act(async () => {
231
+ await result.current.copyCells([mockCellId1]);
232
+ });
233
+
234
+ expect(mockClearPendingCut).toHaveBeenCalled();
235
+ });
236
+ });
237
+
238
+ describe("cutCells", () => {
239
+ it("should cut single cell to clipboard with custom mimetype and plain text", async () => {
240
+ const { result } = renderHook(() => useCellClipboard());
241
+
242
+ await act(async () => {
243
+ await result.current.cutCells([mockCellId1]);
244
+ });
245
+
246
+ expect(mockClipboard.write).toHaveBeenCalledWith([
247
+ expect.objectContaining({
248
+ types: ["web application/x-marimo-cell", "text/plain"],
249
+ }),
250
+ ]);
251
+ });
252
+
253
+ it("should cut multiple cells to clipboard with custom mimetype and plain text", async () => {
254
+ const { result } = renderHook(() => useCellClipboard());
255
+
256
+ await act(async () => {
257
+ await result.current.cutCells([mockCellId1, mockCellId2]);
258
+ });
259
+
260
+ expect(mockClipboard.write).toHaveBeenCalledWith([
261
+ expect.objectContaining({
262
+ types: ["web application/x-marimo-cell", "text/plain"],
263
+ }),
264
+ ]);
265
+ });
266
+
267
+ it("should not write when no cells found", async () => {
268
+ asMock(getNotebook).mockReturnValue(MockNotebook.notebookState());
269
+
270
+ const { result } = renderHook(() => useCellClipboard());
271
+
272
+ await act(async () => {
273
+ await result.current.cutCells([mockCellId1]);
274
+ });
275
+
276
+ expect(mockClipboard.write).not.toHaveBeenCalled();
277
+ });
278
+
279
+ it("should fallback to writeText when clipboard.write fails", async () => {
280
+ mockClipboard.write.mockRejectedValue(new Error("Write failed"));
281
+ mockClipboard.writeText.mockResolvedValue(undefined);
282
+
283
+ const { result } = renderHook(() => useCellClipboard());
284
+
285
+ await act(async () => {
286
+ await result.current.cutCells([mockCellId1]);
287
+ });
288
+
289
+ expect(mockClipboard.write).toHaveBeenCalled();
290
+ expect(mockClipboard.writeText).toHaveBeenCalledWith(mockCellCode1);
291
+ });
292
+
293
+ it("should show error toast when both clipboard methods fail", async () => {
294
+ mockClipboard.write.mockRejectedValue(new Error("Write failed"));
295
+ mockClipboard.writeText.mockRejectedValue(new Error("WriteText failed"));
296
+
297
+ const { result } = renderHook(() => useCellClipboard());
298
+
299
+ await act(async () => {
300
+ await result.current.cutCells([mockCellId1]);
301
+ });
302
+
303
+ expect(Logger.error).toHaveBeenCalledWith(
304
+ "Failed to cut cells to clipboard",
305
+ expect.any(Error),
306
+ );
307
+ });
201
308
  });
202
309
 
203
310
  describe("pasteCell", () => {
@@ -44,6 +44,11 @@ vi.mock("../../cell/useRunCells", () => ({
44
44
  useRunCells: vi.fn(),
45
45
  }));
46
46
 
47
+ vi.mock("../../cell/useDeleteCell", () => ({
48
+ useDeleteCellCallback: vi.fn(),
49
+ useDeleteManyCellsCallback: vi.fn(),
50
+ }));
51
+
47
52
  vi.mock("../clipboard", () => ({
48
53
  useCellClipboard: vi.fn(),
49
54
  }));
@@ -112,6 +117,7 @@ const mockSaveIfNotebookIsPersistent = vi.fn();
112
117
  const mockSaveNotebook = vi.fn();
113
118
  const mockRunCell = vi.fn();
114
119
  const mockCopyCell = vi.fn();
120
+ const mockCutCell = vi.fn().mockResolvedValue(undefined);
115
121
  const mockPasteCell = vi.fn();
116
122
 
117
123
  const mockCellActions = MockNotebook.cellActions({
@@ -165,7 +171,9 @@ describe("useCellNavigationProps", () => {
165
171
  mockUseRunCells.mockReturnValue(mockRunCell);
166
172
  mockUseCellClipboard.mockReturnValue({
167
173
  copyCells: mockCopyCell,
174
+ cutCells: mockCutCell,
168
175
  pasteAtCell: mockPasteCell,
176
+ clearPendingCut: vi.fn(),
169
177
  });
170
178
 
171
179
  // Setup default config in store
@@ -237,6 +245,45 @@ describe("useCellNavigationProps", () => {
237
245
  expect(mockEvent.preventDefault).toHaveBeenCalled();
238
246
  });
239
247
 
248
+ it("should cut cell when 'x' key is pressed", async () => {
249
+ const { result } = renderWithProvider(() =>
250
+ useCellNavigationProps(mockCellId, options),
251
+ );
252
+
253
+ const mockEvent = Mocks.keyboardEvent({ key: "x" });
254
+
255
+ await act(async () => {
256
+ result.current.onKeyDown?.(mockEvent);
257
+ await Promise.resolve();
258
+ });
259
+
260
+ expect(mockCutCell).toHaveBeenCalledWith([mockCellId]);
261
+ expect(mockEvent.preventDefault).toHaveBeenCalled();
262
+ });
263
+
264
+ it("should cut multiple selected cells when 'x' key is pressed", async () => {
265
+ const selectionActions = setupSelection();
266
+ selectionActions.select({ cellId: cellId1 });
267
+ selectionActions.extend({
268
+ cellId: cellId2,
269
+ allCellIds: store.get(notebookAtom).cellIds,
270
+ });
271
+
272
+ const { result } = renderWithProvider(() =>
273
+ useCellNavigationProps(cellId1, options),
274
+ );
275
+
276
+ const mockEvent = Mocks.keyboardEvent({ key: "x" });
277
+
278
+ await act(async () => {
279
+ result.current.onKeyDown?.(mockEvent);
280
+ await Promise.resolve();
281
+ });
282
+
283
+ expect(mockCutCell).toHaveBeenCalledWith([cellId1, cellId2]);
284
+ expect(mockEvent.preventDefault).toHaveBeenCalled();
285
+ });
286
+
240
287
  it("should paste cell when 'v' key is pressed", () => {
241
288
  const { result } = renderWithProvider(() =>
242
289
  useCellNavigationProps(mockCellId, options),
@@ -775,6 +822,29 @@ describe("useCellNavigationProps", () => {
775
822
  expect(mockEvent.preventDefault).toHaveBeenCalled();
776
823
  });
777
824
 
825
+ it("should cut multiple cells when multiple cells selected", () => {
826
+ // Set up selection of multiple cells
827
+ const selectionActions = setupSelection();
828
+ selectionActions.select({ cellId: cellId1 });
829
+ selectionActions.extend({
830
+ cellId: cellId3,
831
+ allCellIds: store.get(notebookAtom).cellIds,
832
+ });
833
+
834
+ const { result } = renderWithProvider(() =>
835
+ useCellNavigationProps(cellId2, options),
836
+ );
837
+
838
+ const mockEvent = Mocks.keyboardEvent({ key: "x" });
839
+
840
+ act(() => {
841
+ result.current.onKeyDown?.(mockEvent);
842
+ });
843
+
844
+ expect(mockCutCell).toHaveBeenCalledWith([cellId1, cellId2, cellId3]);
845
+ expect(mockEvent.preventDefault).toHaveBeenCalled();
846
+ });
847
+
778
848
  it("should move multiple cells up when multiple cells selected", () => {
779
849
  // Set up selection of multiple cells
780
850
  const selectionActions = setupSelection();
@@ -5,15 +5,22 @@ import { z } from "zod";
5
5
  import { toast } from "@/components/ui/use-toast";
6
6
  import { getNotebook, useCellActions } from "@/core/cells/cells";
7
7
  import type { CellId } from "@/core/cells/ids";
8
+ import {
9
+ usePendingCutActions,
10
+ usePendingCutState,
11
+ } from "@/core/cells/pending-cut-service";
12
+ import type { CellConfig } from "@/core/network/types";
8
13
  import { copyToClipboard } from "@/utils/copy";
9
14
  import { Logger } from "@/utils/Logger";
10
15
 
11
16
  // According to MDN, custom mimetypes should start with "web "
12
17
  const MARIMO_CELL_MIMETYPE = "web application/x-marimo-cell";
13
18
 
14
- interface ClipboardCellData {
19
+ export interface ClipboardCellData {
15
20
  cells: {
16
21
  code: string;
22
+ name?: string;
23
+ config?: CellConfig;
17
24
  }[];
18
25
  version: "1.0";
19
26
  }
@@ -22,19 +29,49 @@ const ClipboardCellDataSchema = z.object({
22
29
  cells: z.array(
23
30
  z.object({
24
31
  code: z.string(),
32
+ name: z.string().optional(),
33
+ config: z
34
+ .object({
35
+ column: z.union([z.number(), z.null()]).optional(),
36
+ disabled: z.boolean().optional(),
37
+ hide_code: z.boolean().optional(),
38
+ })
39
+ .optional(),
25
40
  }),
26
41
  ),
27
42
  version: z.literal("1.0"),
28
43
  });
29
44
 
30
- // NOTE: We don't support Cut yet. We can wait for feedback before implementing.
31
- // It is a bit more complex as will need to:
32
- // - include id, outputs, and name
33
- // - delete the existing cell, but don't place on the undo stack
34
- // - don't want to invalidate downstream cells
45
+ function buildClipboardPayload(
46
+ cells: Array<{ code: string; name?: string; config?: CellConfig }>,
47
+ ): { clipboardData: ClipboardCellData; plainText: string } {
48
+ const clipboardData: ClipboardCellData = {
49
+ cells: cells.map((cell) => ({
50
+ code: cell.code,
51
+ name: cell.name,
52
+ config: cell.config,
53
+ })),
54
+ version: "1.0",
55
+ };
56
+ const plainText = cells.map((cell) => cell.code).join("\n\n");
57
+ return { clipboardData, plainText };
58
+ }
59
+
60
+ async function writeCellsToClipboard(
61
+ clipboardData: ClipboardCellData,
62
+ plainText: string,
63
+ ): Promise<void> {
64
+ const clipboardItem = new ClipboardItemBuilder()
65
+ .add(MARIMO_CELL_MIMETYPE, clipboardData)
66
+ .add("text/plain", plainText)
67
+ .build();
68
+ await navigator.clipboard.write([clipboardItem]);
69
+ }
35
70
 
36
71
  export function useCellClipboard() {
37
72
  const actions = useCellActions();
73
+ const pendingCutActions = usePendingCutActions();
74
+ const pendingCutState = usePendingCutState();
38
75
 
39
76
  const copyCells = useEvent(async (cellIds: CellId[]) => {
40
77
  const notebook = getNotebook();
@@ -47,31 +84,19 @@ export function useCellClipboard() {
47
84
  return;
48
85
  }
49
86
 
50
- try {
51
- const clipboardData: ClipboardCellData = {
52
- cells: cells.map((cell) => ({ code: cell.code })),
53
- version: "1.0",
54
- };
55
-
56
- // Create plain text representation (joined by newlines)
57
- const plainText = cells.map((cell) => cell.code).join("\n\n");
58
-
59
- // Create clipboard item with both custom mimetype and plain text
60
- const clipboardItem = new ClipboardItemBuilder()
61
- .add(MARIMO_CELL_MIMETYPE, clipboardData)
62
- .add("text/plain", plainText)
63
- .build();
64
-
65
- await navigator.clipboard.write([clipboardItem]);
87
+ const { clipboardData, plainText } = buildClipboardPayload(cells);
66
88
 
89
+ try {
90
+ await writeCellsToClipboard(clipboardData, plainText);
91
+ pendingCutActions.clear();
67
92
  toastSuccess(cells.length);
68
93
  } catch (error) {
69
94
  Logger.error("Failed to copy cells to clipboard", error);
70
95
 
71
96
  // Fallback to simple text copy
72
97
  try {
73
- const plainText = cells.map((cell) => cell.code).join("\n\n");
74
98
  await copyToClipboard(plainText);
99
+ pendingCutActions.clear();
75
100
  toastSuccess(cells.length);
76
101
  } catch {
77
102
  toastError();
@@ -79,12 +104,60 @@ export function useCellClipboard() {
79
104
  }
80
105
  });
81
106
 
107
+ const cutCells = useEvent(async (cellIds: CellId[]) => {
108
+ const notebook = getNotebook();
109
+ const validCellIds = cellIds.filter((cellId) => notebook.cellData[cellId]);
110
+ const cells = validCellIds.map((cellId) => notebook.cellData[cellId]);
111
+
112
+ if (cells.length === 0) {
113
+ // No cells to cut
114
+ return;
115
+ }
116
+
117
+ const { clipboardData, plainText } = buildClipboardPayload(cells);
118
+
119
+ try {
120
+ await writeCellsToClipboard(clipboardData, plainText);
121
+ pendingCutActions.markForCut({ cellIds: validCellIds, clipboardData });
122
+ } catch (error) {
123
+ Logger.error("Failed to cut cells to clipboard", error);
124
+ try {
125
+ await copyToClipboard(plainText);
126
+ // Mark cells as pending cut instead of deleting immediately
127
+ pendingCutActions.markForCut({ cellIds: validCellIds, clipboardData });
128
+ } catch {
129
+ toastError();
130
+ }
131
+ }
132
+ });
133
+
82
134
  interface PasteOptions {
83
135
  before?: boolean;
84
136
  }
85
137
 
86
138
  const pasteAtCell = useEvent(async (cellId: CellId, opts?: PasteOptions) => {
87
139
  const { before = false } = opts ?? {};
140
+
141
+ // Check if we have pending cut cells (internal move)
142
+ if (pendingCutState.cellIds.size > 0) {
143
+ const pendingCellIds = [...pendingCutState.cellIds];
144
+ const notebook = getNotebook();
145
+ const previousPlacements = pendingCellIds.map((id) => {
146
+ const column = notebook.cellIds.findWithId(id);
147
+ return { columnId: column.id, index: column.indexOfOrThrow(id) };
148
+ });
149
+
150
+ actions.moveCellsRelativeTo({
151
+ cellIds: pendingCellIds,
152
+ targetCellId: cellId,
153
+ position: before ? "before" : "after",
154
+ previousPlacements,
155
+ });
156
+
157
+ pendingCutActions.clear();
158
+ return;
159
+ }
160
+
88
161
  try {
89
162
  const clipboardItems = await navigator.clipboard.read();
90
163
 
@@ -112,6 +185,9 @@ export function useCellClipboard() {
112
185
  cellId: currentCellId,
113
186
  before,
114
187
  code: cell.code,
188
+ name: cell.name,
189
+ config: cell.config,
190
+ hideCode: cell.config?.hide_code,
115
191
  autoFocus: true,
116
192
  });
117
193
  }
@@ -143,7 +219,9 @@ export function useCellClipboard() {
143
219
 
144
220
  return {
145
221
  copyCells,
222
+ cutCells,
146
223
  pasteAtCell,
224
+ clearPendingCut: pendingCutActions.clear,
147
225
  };
148
226
  }
149
227
 
@@ -16,6 +16,10 @@ import { cellIdsAtom, notebookAtom, useCellActions } from "@/core/cells/cells";
16
16
  import { useCellFocusActions } from "@/core/cells/focus";
17
17
  import type { CellId } from "@/core/cells/ids";
18
18
  import { HTMLCellId } from "@/core/cells/ids";
19
+ import {
20
+ clearPendingCutAtom,
21
+ pendingCutCellIdsAtom,
22
+ } from "@/core/cells/pending-cut-service";
19
23
  import { usePendingDeleteService } from "@/core/cells/pending-delete-service";
20
24
  import { scrollCellIntoView } from "@/core/cells/scrollCellIntoView";
21
25
  import {
@@ -185,7 +189,7 @@ export function useCellNavigationProps(
185
189
  const temporarilyShownCodeActions = useTemporarilyShownCodeActions();
186
190
  const runCells = useRunCells();
187
191
  const keymapPreset = useAtomValue(keymapPresetAtom);
188
- const { copyCells, pasteAtCell } = useCellClipboard();
192
+ const { copyCells, pasteAtCell, cutCells } = useCellClipboard();
189
193
  const rawSelectionActions = useCellSelectionActions();
190
194
  const isSelected = useIsCellSelected(cellId);
191
195
  const pendingDeleteService = usePendingDeleteService();
@@ -317,6 +321,12 @@ export function useCellNavigationProps(
317
321
  },
318
322
  // Clear selection
319
323
  Escape: () => {
324
+ // Clear pending cut state if any
325
+ const pendingCutCellIds = store.get(pendingCutCellIdsAtom);
326
+ if (pendingCutCellIds.size > 0) {
327
+ store.set(clearPendingCutAtom);
328
+ return true;
329
+ }
320
330
  if (isSelected) {
321
331
  selectionActions.clear();
322
332
  return true;
@@ -510,6 +520,10 @@ export function useCellNavigationProps(
510
520
  copyCells(cellIds);
511
521
  return true;
512
522
  }),
523
+ "command.cutCell": addSingleHandler((cellIds) => {
524
+ cutCells(cellIds);
525
+ return true;
526
+ }),
513
527
  "command.pasteCell": (cellIds) => {
514
528
  pasteAtCell(cellIds);
515
529
  return true;
@@ -27,6 +27,7 @@ import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
27
27
  import { aiCompletionCellAtom } from "@/core/ai/state";
28
28
  import { outputIsLoading, outputIsStale } from "@/core/cells/cell";
29
29
  import { isOutputEmpty } from "@/core/cells/outputs";
30
+ import { useIsPendingCut } from "@/core/cells/pending-cut-service";
30
31
  import { autocompletionKeymap } from "@/core/codemirror/cm";
31
32
  import type { LanguageAdapterType } from "@/core/codemirror/language/types";
32
33
  import { CSSClasses } from "@/core/constants";
@@ -391,6 +392,7 @@ const EditableCellComponent = ({
391
392
  const deleteCell = useDeleteCellCallback();
392
393
  const runCell = useRunCell(cellId);
393
394
  const { sendStdin } = useRequestClient();
395
+ const isPendingCut = useIsPendingCut(cellId);
394
396
 
395
397
  const [languageAdapter, setLanguageAdapter] = useState<LanguageAdapterType>();
396
398
 
@@ -545,6 +547,7 @@ const EditableCellComponent = ({
545
547
  }),
546
548
  borderless:
547
549
  isMarkdownCodeHidden && hasOutput && !navigationProps["data-selected"],
550
+ "pending-cut": isPendingCut,
548
551
  });
549
552
 
550
553
  const handleRefactorWithAI: OnRefactorWithAI = useEvent(
@@ -212,6 +212,20 @@ describe("cell reducer", () => {
212
212
  `);
213
213
  });
214
214
 
215
+ it("can add a cell with name and config", () => {
216
+ actions.createNewCell({
217
+ cellId: firstCellId,
218
+ before: false,
219
+ code: "x = 1",
220
+ name: "My Cell",
221
+ config: { hide_code: true, disabled: false },
222
+ });
223
+ const newCellId = state.cellIds.inOrderIds[1];
224
+ expect(state.cellData[newCellId].name).toBe("My Cell");
225
+ expect(state.cellData[newCellId].config.hide_code).toBe(true);
226
+ expect(state.cellData[newCellId].config.disabled).toBe(false);
227
+ });
228
+
215
229
  it("can delete a Python cell and undo delete", () => {
216
230
  actions.createNewCell({
217
231
  cellId: firstCellId,
@@ -602,6 +616,179 @@ describe("cell reducer", () => {
602
616
  expect(formatCells(state)).toBe(before);
603
617
  });
604
618
 
619
+ it("can move multiple cells relative to target", () => {
620
+ actions.createNewCell({
621
+ cellId: firstCellId,
622
+ before: false,
623
+ });
624
+ actions.createNewCell({
625
+ cellId: "1" as CellId,
626
+ before: false,
627
+ });
628
+ expect(formatCells(state)).toMatchInlineSnapshot(`
629
+ "
630
+ [0] ''
631
+
632
+ [1] ''
633
+
634
+ [2] ''
635
+ "
636
+ `);
637
+
638
+ // Move first two cells after the third
639
+ actions.moveCellsRelativeTo({
640
+ cellIds: [firstCellId, "1" as CellId],
641
+ targetCellId: "2" as CellId,
642
+ position: "after",
643
+ });
644
+ expect(formatCells(state)).toMatchInlineSnapshot(`
645
+ "
646
+ [2] ''
647
+
648
+ [0] ''
649
+
650
+ [1] ''
651
+ "
652
+ `);
653
+ });
654
+
655
+ it("can undo cut-paste (move with previousPlacements)", () => {
656
+ actions.createNewCell({
657
+ cellId: firstCellId,
658
+ before: false,
659
+ });
660
+ actions.createNewCell({
661
+ cellId: "1" as CellId,
662
+ before: false,
663
+ });
664
+ expect(formatCells(state)).toMatchInlineSnapshot(`
665
+ "
666
+ [0] ''
667
+
668
+ [1] ''
669
+
670
+ [2] ''
671
+ "
672
+ `);
673
+
674
+ const col = state.cellIds.findWithId(firstCellId);
675
+ const previousPlacements = [
676
+ {
677
+ columnId: col.id,
678
+ index: col.indexOfOrThrow(
679
+ firstCellId,
680
+ ) as import("@/utils/id-tree").CellIndex,
681
+ },
682
+ {
683
+ columnId: col.id,
684
+ index: col.indexOfOrThrow(
685
+ "1" as CellId,
686
+ ) as import("@/utils/id-tree").CellIndex,
687
+ },
688
+ ];
689
+
690
+ actions.moveCellsRelativeTo({
691
+ cellIds: [firstCellId, "1" as CellId],
692
+ targetCellId: "2" as CellId,
693
+ position: "after",
694
+ previousPlacements,
695
+ });
696
+ expect(formatCells(state)).toMatchInlineSnapshot(`
697
+ "
698
+ [2] ''
699
+
700
+ [0] ''
701
+
702
+ [1] ''
703
+ "
704
+ `);
705
+
706
+ actions.undoDeleteCell();
707
+ expect(formatCells(state)).toMatchInlineSnapshot(`
708
+ "
709
+ [0] ''
710
+
711
+ [1] ''
712
+
713
+ [2] ''
714
+ "
715
+ `);
716
+ });
717
+
718
+ it("undo order: cut-paste then delete — first undo restores delete, second undo undoes move", () => {
719
+ actions.createNewCell({
720
+ cellId: firstCellId,
721
+ before: false,
722
+ });
723
+ actions.createNewCell({
724
+ cellId: "1" as CellId,
725
+ before: false,
726
+ });
727
+
728
+ const col = state.cellIds.findWithId(firstCellId);
729
+ const previousPlacements = [
730
+ {
731
+ columnId: col.id,
732
+ index: col.indexOfOrThrow(
733
+ firstCellId,
734
+ ) as import("@/utils/id-tree").CellIndex,
735
+ },
736
+ {
737
+ columnId: col.id,
738
+ index: col.indexOfOrThrow(
739
+ "1" as CellId,
740
+ ) as import("@/utils/id-tree").CellIndex,
741
+ },
742
+ ];
743
+
744
+ actions.moveCellsRelativeTo({
745
+ cellIds: [firstCellId, "1" as CellId],
746
+ targetCellId: "2" as CellId,
747
+ position: "after",
748
+ previousPlacements,
749
+ });
750
+ expect(formatCells(state)).toMatchInlineSnapshot(`
751
+ "
752
+ [2] ''
753
+
754
+ [0] ''
755
+
756
+ [1] ''
757
+ "
758
+ `);
759
+
760
+ actions.deleteCell({ cellId: "2" as CellId });
761
+ expect(formatCells(state)).toMatchInlineSnapshot(`
762
+ "
763
+ [0] ''
764
+
765
+ [1] ''
766
+ "
767
+ `);
768
+
769
+ actions.undoDeleteCell();
770
+ expect(formatCells(state)).toMatchInlineSnapshot(`
771
+ "
772
+ [3] ''
773
+
774
+ [0] ''
775
+
776
+ [1] ''
777
+ "
778
+ `);
779
+
780
+ actions.undoDeleteCell();
781
+ expect(formatCells(state)).toMatchInlineSnapshot(`
782
+ "
783
+ [0] ''
784
+
785
+ [1] ''
786
+
787
+ [3] ''
788
+ "
789
+ `);
790
+ });
791
+
605
792
  it("can run cell and receive cell messages", () => {
606
793
  // HAPPY PATH
607
794
  /////////////////