@marimo-team/frontend 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.
- package/dist/assets/{CellStatus-CN4mKUXv.js → CellStatus-Cb08qBNj.js} +1 -1
- package/dist/assets/{ConnectedDataExplorerComponent-DeBM0cl9.js → ConnectedDataExplorerComponent-BEDxXsa0.js} +1 -1
- package/dist/assets/{ErrorBoundary-DzYV_VeY.js → ErrorBoundary-DyYDV0HI.js} +1 -1
- package/dist/assets/{ImperativeModal-D7lQ0Q7_.js → ImperativeModal-CvOOClOZ.js} +1 -1
- package/dist/assets/{JsonOutput-B0sjIMBK.js → JsonOutput-BqavrgK2.js} +11 -11
- package/dist/assets/{LazyAnyLanguageCodeMirror-pAFdCqyC.js → LazyAnyLanguageCodeMirror-CXbgDeVw.js} +2 -2
- package/dist/assets/{MarimoErrorOutput-ClA7EZGX.js → MarimoErrorOutput-DyaTrW3L.js} +2 -2
- package/dist/assets/{RSPContexts-CINae4Gg.js → RSPContexts-eRifaAal.js} +1 -1
- package/dist/assets/{RenderHTML-CruxVneu.js → RenderHTML-CvnUbELu.js} +1 -1
- package/dist/assets/{RunButton-CJsJsGj-.js → RunButton-Cw4OpYze.js} +1 -1
- package/dist/assets/{add-cell-with-ai-C7f_bUyB.js → add-cell-with-ai-CsUwlDQR.js} +16 -16
- package/dist/assets/{add-connection-dialog-DSOgwTlO.js → add-connection-dialog-B00bTtAj.js} +1 -1
- package/dist/assets/{agent-panel-CeDyKw1_.js → agent-panel-vnhI1dDS.js} +3 -3
- package/dist/assets/{ai-model-dropdown-kQdQhWyz.js → ai-model-dropdown-E3o7Xd1q.js} +4 -4
- package/dist/assets/{alert-dialog-BGBdrcqJ.js → alert-dialog-BqFLkbUc.js} +1 -1
- package/dist/assets/{any-language-editor-CwwS-naY.js → any-language-editor-Bu4hSl-d.js} +1 -1
- package/dist/assets/{app-config-button-dnmk7p6n.js → app-config-button-DTjn2zGb.js} +1 -1
- package/dist/assets/{button-D9nb17Rw.js → button-BbCh-29a.js} +1 -1
- package/dist/assets/{cache-panel-DDJqyuAl.js → cache-panel-VFeeaT52.js} +1 -1
- package/dist/assets/{capabilities-C_FLIcjP.js → capabilities-A_KhFcGV.js} +1 -1
- package/dist/assets/cell-editor-C41pv5M8.js +20 -0
- package/dist/assets/cell-link-sLKimSIQ.js +1 -0
- package/dist/assets/{cells-BBDzmUIS.js → cells-Vnv1zw09.js} +71 -71
- package/dist/assets/{chat-display-Ct3Me0kL.js → chat-display-sbJsmezM.js} +1 -1
- package/dist/assets/{chat-panel-CXvtUFUU.js → chat-panel-DFLJ558d.js} +1 -1
- package/dist/assets/{chat-ui-UFERs8Gx.js → chat-ui-BWV8p_Y-.js} +1 -1
- package/dist/assets/{column-preview-Xuel1zsI.js → column-preview-DYtdLerF.js} +1 -1
- package/dist/assets/{command-CBCkexpx.js → command-OHlV5HHD.js} +1 -1
- package/dist/assets/{command-palette-DuPUk7of.js → command-palette-CvoYeZJD.js} +1 -1
- package/dist/assets/{common-Dk5VdfJt.js → common-BhQv6499.js} +1 -1
- package/dist/assets/{components-CTKNCmC_.js → components-BA-LgiMU.js} +1 -1
- package/dist/assets/{components-DsoH1pO3.js → components-c7ywwQgj.js} +1 -1
- package/dist/assets/{config-CPqw1wUv.js → config-CeTe6Mau.js} +1 -1
- package/dist/assets/{copy-BCF-tANo.js → copy-DqHGjTAN.js} +1 -1
- package/dist/assets/{copy-icon-BYNydU7b.js → copy-icon-8abB4Lgh.js} +1 -1
- package/dist/assets/{createReducer-1ePoj7v6.js → createReducer-CI9qeK_X.js} +1 -1
- package/dist/assets/{datasource-CmTCEk66.js → datasource-BGeucDqU.js} +2 -2
- package/dist/assets/{dates-CAlnO9QB.js → dates-orWokFRU.js} +1 -1
- package/dist/assets/{dependency-graph-panel-0u1-ZaOT.js → dependency-graph-panel-Dm8aJtqe.js} +4 -4
- package/dist/assets/{dialog-Dj0qTFnG.js → dialog-DBzaWZPw.js} +1 -1
- package/dist/assets/{dist-BoOh2kN5.js → dist-BdyjRhEt.js} +1 -1
- package/dist/assets/documentation-panel-BmTIHvGw.js +1 -0
- package/dist/assets/{download-QGh9oR1D.js → download-CHV3J2Ib.js} +4 -4
- package/dist/assets/{dropdown-menu-D1A3cFC8.js → dropdown-menu-CR7cnzLX.js} +1 -1
- package/dist/assets/{edit-page-hJAbnd__.js → edit-page-Dvj9-hG8.js} +6 -6
- package/dist/assets/{error-banner-C10O4l3y.js → error-banner-JKAA0BVv.js} +1 -1
- package/dist/assets/{error-panel-ChlzbfWg.js → error-panel-yG2LOaXm.js} +1 -1
- package/dist/assets/{es-DaYh1PsD.js → es-CaLpD1T5.js} +1 -1
- package/dist/assets/{field-BrLPDxsA.js → field-CD7Io4xo.js} +1 -1
- package/dist/assets/{file-explorer-panel-8dWLD2PY.js → file-explorer-panel-Bsp9TexR.js} +3 -3
- package/dist/assets/{file-icons-Cs4oXsAy.js → file-icons-Cisq31t9.js} +1 -1
- package/dist/assets/{file-name-input-g7pBBCjk.js → file-name-input-Dti85i-l.js} +1 -1
- package/dist/assets/{floating-outline-CFUSr2du.js → floating-outline-CnVsBFJf.js} +1 -1
- package/dist/assets/{focus-J47a1GCq.js → focus-bWAnl_NC.js} +1 -1
- package/dist/assets/{form-CdFqEqTA.js → form-iTIO7T75.js} +2 -2
- package/dist/assets/{formats-Dsc8AdCp.js → formats-D4Sso5bX.js} +1 -1
- package/dist/assets/{formatting-Chn6WhRe.js → formatting-BDxRugYY.js} +1 -1
- package/dist/assets/{fullscreen-BDxedMYP.js → fullscreen-eipL3i3Y.js} +1 -1
- package/dist/assets/{gallery-page-TIWZFnOT.js → gallery-page-DDCU0YEU.js} +1 -1
- package/dist/assets/{glide-data-editor-ChlIFl33.js → glide-data-editor-BELaKoS9.js} +1 -1
- package/dist/assets/{globals-DUw71mRV.js → globals-B64vMQ0L.js} +1 -1
- package/dist/assets/{home-page-HhJfA35e.js → home-page-CSSZCATB.js} +1 -1
- package/dist/assets/{hooks-DbPDczTe.js → hooks-CxyxjDM-.js} +1 -1
- package/dist/assets/{html-to-image-CAiN3VHj.js → html-to-image-WbbYaIba.js} +2 -2
- package/dist/assets/{index-BbBhLC0d.css → index-BcFmKehD.css} +1 -1
- package/dist/assets/{index-DLZItUgg.js → index-BmG6rFrZ.js} +7 -7
- package/dist/assets/{input-BX98vgAu.js → input-DW6LU13i.js} +1 -1
- package/dist/assets/kiosk-mode-DPxzN-M0.js +1 -0
- package/dist/assets/{label-DTR8T0AE.js → label-xHqFtfdz.js} +1 -1
- package/dist/assets/{layout-C1dvirgi.js → layout-B3ilKFRj.js} +5 -5
- package/dist/assets/{links-BhX7oUFH.js → links-Bi_gi3iZ.js} +1 -1
- package/dist/assets/{logs-panel-B2tW94um.js → logs-panel-7jkC5Vwq.js} +1 -1
- package/dist/assets/{maps-C48Oksn0.js → maps-BS8Ra-JU.js} +1 -1
- package/dist/assets/{markdown-renderer-CVd_mMPt.js → markdown-renderer-CXVa5ubo.js} +2 -2
- package/dist/assets/{menu-items-CwUpDHG7.js → menu-items-DcP01QzW.js} +1 -1
- package/dist/assets/{mermaid-ByDNZESx.js → mermaid-B6II7_1_.js} +1 -1
- package/dist/assets/{multi-map-rafH3cg3.js → multi-map-CUuNtzHt.js} +1 -1
- package/dist/assets/{name-cell-input-DDQOQSsh.js → name-cell-input-DP5q5hou.js} +1 -1
- package/dist/assets/{numbers-CAW8yjzj.js → numbers-etj36G80.js} +1 -1
- package/dist/assets/{outline-panel-BuTQis3o.js → outline-panel-CAMKZApa.js} +1 -1
- package/dist/assets/{packages-panel-CVu8Cpkz.js → packages-panel-BqWdwyLN.js} +1 -1
- package/dist/assets/{panels-Z5fVmDRY.js → panels-BaOloRiT.js} +1 -1
- package/dist/assets/{popover-UExmgBsf.js → popover-Bz_0Vkyf.js} +1 -1
- package/dist/assets/process-output-3R47GJ28.js +1 -0
- package/dist/assets/{radio-group-CpHTexlq.js → radio-group-BdIsm_qJ.js} +1 -1
- package/dist/assets/{readonly-python-code-DOXF2p8K.js → readonly-python-code-Dz8x4isw.js} +1 -1
- package/dist/assets/{renderShortcut-Bfk4NjRL.js → renderShortcut-D_8sQXCD.js} +1 -1
- package/dist/assets/{reveal-component-DLRiYfBj.js → reveal-component-BomJwrt3.js} +2 -2
- package/dist/assets/{run-page-DBSf1bOm.js → run-page-DOVpxgC2.js} +1 -1
- package/dist/assets/{runs-DRld30N_.js → runs-D87fZMlB.js} +1 -1
- package/dist/assets/scratchpad-panel-CK721GBB.js +1 -0
- package/dist/assets/{secrets-panel-B8CbRNMo.js → secrets-panel-DgXG36fa.js} +1 -1
- package/dist/assets/{select-5i7URBEn.js → select-DZcFyKFQ.js} +1 -1
- package/dist/assets/{session-VtovaFBS.js → session-gB-8RZAq.js} +1 -1
- package/dist/assets/{session-panel-DHfR6tDv.js → session-panel-_DOPOxmi.js} +1 -1
- package/dist/assets/{share-CqnSBwZy.js → share-DdpVbvDN.js} +1 -1
- package/dist/assets/{snippets-panel-CGs_ME5h.js → snippets-panel-CtEyZp6T.js} +1 -1
- package/dist/assets/{spec-Cq8FVoTf.js → spec-ByOlaO3e.js} +1 -1
- package/dist/assets/{state-B34hXjp9.js → state-BNbY1nER.js} +1 -1
- package/dist/assets/{state-BV_qjCwT.js → state-BmNumiqM.js} +1 -1
- package/dist/assets/{state-xEqF8Q3P.js → state-CZ60VH86.js} +3 -3
- package/dist/assets/{state-DzJiyfWW.js → state-DujssAPg.js} +1 -1
- package/dist/assets/{strings-md4mFbOQ.js → strings-wdPMRf6Z.js} +1 -1
- package/dist/assets/{swiper-component-CBSZ9l9W.js → swiper-component-B1e0X8Wt.js} +1 -1
- package/dist/assets/{switch-BvybnC9P.js → switch-BT9Ki10B.js} +1 -1
- package/dist/assets/{terminal-bb566dQu.js → terminal-G4Y2HQik.js} +1 -1
- package/dist/assets/{textarea-bAp21zYj.js → textarea-CUCKX5FP.js} +1 -1
- package/dist/assets/{tooltip-Gcwqb_SK.js → tooltip-DTV9tlSr.js} +1 -1
- package/dist/assets/{tracing-HakOQiQR.js → tracing-B84tRfOs.js} +1 -1
- package/dist/assets/{tracing-panel-eas_Nc-b.js → tracing-panel-Cv--myyS.js} +2 -2
- package/dist/assets/{tree-actions-Ci3CV3hN.js → tree-actions-Bzr5XDGx.js} +1 -1
- package/dist/assets/{useBoolean-xXcxYCaI.js → useBoolean-BYUGB06y.js} +1 -1
- package/dist/assets/useCellActionButton-Mkc0xJ7L.js +1 -0
- package/dist/assets/{useDeleteCell-GFhvGBJ7.js → useDeleteCell-C67FKMcv.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-DHd7_0b9.js → useDependencyPanelTab-BdgKnqQ5.js} +1 -1
- package/dist/assets/{useEventListener-BR0C1MaI.js → useEventListener-DvoEXWke.js} +1 -1
- package/dist/assets/{useHotkey-DccKPSPx.js → useHotkey-3DXVR1KZ.js} +1 -1
- package/dist/assets/{useIframeCapabilities-BvE4n6hj.js → useIframeCapabilities-BfimgBBe.js} +1 -1
- package/dist/assets/{useInstallPackage-D0NLybAx.js → useInstallPackage-CScpUItd.js} +1 -1
- package/dist/assets/{useInterval-CvFz96h2.js → useInterval-CAy_JAzY.js} +1 -1
- package/dist/assets/useNotebookActions-C_PqW3GC.js +1 -0
- package/dist/assets/useRunCells-C991pS4a.js +1 -0
- package/dist/assets/useSplitCell-FJGXiUyn.js +1 -0
- package/dist/assets/{useTheme-DFXuDFj9.js → useTheme-DyLIIrGi.js} +1 -1
- package/dist/assets/{utils-CGtUbqcR.js → utils-441jgnV8.js} +1 -1
- package/dist/assets/{utils-BrXijSdZ.js → utils-Wvjk_Y4h.js} +1 -1
- package/dist/assets/{vega-component-Bq0lrkG7.js → vega-component-2S2ePGs4.js} +1 -1
- package/dist/assets/{write-secret-modal-D8Sww7eA.js → write-secret-modal-BcEaI0rD.js} +1 -1
- package/dist/index.html +68 -68
- package/package.json +1 -1
- package/src/components/editor/actions/useNotebookActions.tsx +3 -1
- package/src/components/editor/controls/Controls.tsx +3 -1
- package/src/components/editor/navigation/__tests__/clipboard.test.ts +107 -0
- package/src/components/editor/navigation/__tests__/navigation.test.ts +70 -0
- package/src/components/editor/navigation/clipboard.ts +101 -23
- package/src/components/editor/navigation/navigation.ts +15 -1
- package/src/components/editor/notebook-cell.tsx +3 -0
- package/src/core/cells/__tests__/cells.test.ts +187 -0
- package/src/core/cells/__tests__/pending-cut-service.test.tsx +145 -0
- package/src/core/cells/cells.ts +102 -17
- package/src/core/cells/document-changes.ts +6 -1
- package/src/core/cells/pending-cut-service.ts +64 -0
- package/src/core/cells/utils.ts +11 -0
- package/src/core/codemirror/cells/extensions.ts +10 -0
- package/src/core/hotkeys/hotkeys.ts +5 -0
- package/src/css/app/Cell.css +13 -0
- package/src/utils/__tests__/id-tree.test.ts +71 -0
- package/src/utils/id-tree.tsx +89 -0
- package/dist/assets/cell-editor-BN3D1_w1.js +0 -22
- package/dist/assets/cell-link-DqiCeeeS.js +0 -1
- package/dist/assets/documentation-panel-CcE7aGO9.js +0 -1
- package/dist/assets/kiosk-mode-Cr9yyT7A.js +0 -1
- package/dist/assets/process-output-DSqjZYr-.js +0 -1
- package/dist/assets/scratchpad-panel-CUMSD7sH.js +0 -1
- package/dist/assets/useCellActionButton-CHLJURZ7.js +0 -1
- package/dist/assets/useNotebookActions-CZ7s2FNR.js +0 -1
- package/dist/assets/useRunCells-RJeImyCn.js +0 -1
- package/dist/assets/useSplitCell-BRZ3fmLD.js +0 -1
|
@@ -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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
/////////////////
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { act, renderHook } from "@testing-library/react";
|
|
4
|
+
import { createStore, Provider } from "jotai";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import type { CellId } from "@/core/cells/ids";
|
|
7
|
+
import {
|
|
8
|
+
pendingCutStateAtom,
|
|
9
|
+
useHasPendingCut,
|
|
10
|
+
useIsPendingCut,
|
|
11
|
+
usePendingCutActions,
|
|
12
|
+
usePendingCutState,
|
|
13
|
+
} from "../pending-cut-service";
|
|
14
|
+
|
|
15
|
+
function createTestWrapper() {
|
|
16
|
+
const store = createStore();
|
|
17
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
18
|
+
<Provider store={store}>{children}</Provider>
|
|
19
|
+
);
|
|
20
|
+
return { wrapper, store };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const mockClipboardData = {
|
|
24
|
+
cells: [{ code: "x = 1", name: "cell1" }],
|
|
25
|
+
version: "1.0" as const,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe("pending-cut-service", () => {
|
|
29
|
+
it("markForCut sets cellIds and clipboardData", () => {
|
|
30
|
+
const { wrapper, store } = createTestWrapper();
|
|
31
|
+
const cellIds: CellId[] = ["cell-1" as CellId, "cell-2" as CellId];
|
|
32
|
+
|
|
33
|
+
const { result } = renderHook(
|
|
34
|
+
() => ({
|
|
35
|
+
actions: usePendingCutActions(),
|
|
36
|
+
state: usePendingCutState(),
|
|
37
|
+
}),
|
|
38
|
+
{ wrapper },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
act(() => {
|
|
42
|
+
result.current.actions.markForCut({
|
|
43
|
+
cellIds,
|
|
44
|
+
clipboardData: mockClipboardData,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const state = store.get(pendingCutStateAtom);
|
|
49
|
+
expect(state.cellIds).toEqual(new Set(cellIds));
|
|
50
|
+
expect(state.clipboardData).toEqual(mockClipboardData);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("clear resets to initial state", () => {
|
|
54
|
+
const { wrapper, store } = createTestWrapper();
|
|
55
|
+
const cellIds: CellId[] = ["cell-1" as CellId];
|
|
56
|
+
|
|
57
|
+
const { result } = renderHook(
|
|
58
|
+
() => ({
|
|
59
|
+
actions: usePendingCutActions(),
|
|
60
|
+
state: usePendingCutState(),
|
|
61
|
+
}),
|
|
62
|
+
{ wrapper },
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
act(() => {
|
|
66
|
+
result.current.actions.markForCut({
|
|
67
|
+
cellIds,
|
|
68
|
+
clipboardData: mockClipboardData,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
expect(store.get(pendingCutStateAtom).cellIds.size).toBe(1);
|
|
72
|
+
|
|
73
|
+
act(() => {
|
|
74
|
+
result.current.actions.clear();
|
|
75
|
+
});
|
|
76
|
+
const state = store.get(pendingCutStateAtom);
|
|
77
|
+
expect(state.cellIds.size).toBe(0);
|
|
78
|
+
expect(state.clipboardData).toBeNull();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("useIsPendingCut returns true when cellId is marked for cut", () => {
|
|
82
|
+
const { wrapper } = createTestWrapper();
|
|
83
|
+
const cellId = "cell-1" as CellId;
|
|
84
|
+
|
|
85
|
+
const { result: actionsResult } = renderHook(() => usePendingCutActions(), {
|
|
86
|
+
wrapper,
|
|
87
|
+
});
|
|
88
|
+
const { result: isPendingResult } = renderHook(
|
|
89
|
+
() => useIsPendingCut(cellId),
|
|
90
|
+
{ wrapper },
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(isPendingResult.current).toBe(false);
|
|
94
|
+
|
|
95
|
+
act(() => {
|
|
96
|
+
actionsResult.current.markForCut({
|
|
97
|
+
cellIds: [cellId],
|
|
98
|
+
clipboardData: mockClipboardData,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(isPendingResult.current).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("useIsPendingCut returns false when cellId is not marked for cut", () => {
|
|
106
|
+
const { wrapper } = createTestWrapper();
|
|
107
|
+
const { result } = renderHook(
|
|
108
|
+
() => useIsPendingCut("other-cell" as CellId),
|
|
109
|
+
{ wrapper },
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const { result: actionsResult } = renderHook(() => usePendingCutActions(), {
|
|
113
|
+
wrapper,
|
|
114
|
+
});
|
|
115
|
+
act(() => {
|
|
116
|
+
actionsResult.current.markForCut({
|
|
117
|
+
cellIds: ["cell-1" as CellId],
|
|
118
|
+
clipboardData: mockClipboardData,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(result.current).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("useHasPendingCut returns true when any cells are marked for cut", () => {
|
|
126
|
+
const { wrapper } = createTestWrapper();
|
|
127
|
+
const { result: hasPendingResult } = renderHook(() => useHasPendingCut(), {
|
|
128
|
+
wrapper,
|
|
129
|
+
});
|
|
130
|
+
const { result: actionsResult } = renderHook(() => usePendingCutActions(), {
|
|
131
|
+
wrapper,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(hasPendingResult.current).toBe(false);
|
|
135
|
+
|
|
136
|
+
act(() => {
|
|
137
|
+
actionsResult.current.markForCut({
|
|
138
|
+
cellIds: ["cell-1" as CellId],
|
|
139
|
+
clipboardData: mockClipboardData,
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(hasPendingResult.current).toBe(true);
|
|
144
|
+
});
|
|
145
|
+
});
|