@marimo-team/frontend 0.23.10-dev1 → 0.23.10-dev2
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-BLWR83i_.js → CellStatus-B4qIAZip.js} +1 -1
- package/dist/assets/{JsonOutput-BJaeXQim.js → JsonOutput-sim6s58u.js} +1 -1
- package/dist/assets/{MarimoErrorOutput-B0h5OVW9.js → MarimoErrorOutput-IoNFtcZT.js} +1 -1
- package/dist/assets/{RenderHTML-ChwPJgPd.js → RenderHTML-BpmpkBqm.js} +1 -1
- package/dist/assets/{add-cell-with-ai-FxJitVGs.js → add-cell-with-ai-Da5NaDZ_.js} +1 -1
- package/dist/assets/{add-connection-dialog-EgkKupsZ.js → add-connection-dialog-qtpp-Zvj.js} +1 -1
- package/dist/assets/{agent-panel-D5uoss1C.js → agent-panel-CTXCTxgV.js} +1 -1
- package/dist/assets/{ai-model-dropdown-DxAk02Lc.js → ai-model-dropdown-CDevlJTs.js} +1 -1
- package/dist/assets/{app-config-button-BcOcIm9W.js → app-config-button-BXlR4nKW.js} +1 -1
- package/dist/assets/{cell-editor-C5CDtKML.js → cell-editor-Z3xJhFik.js} +1 -1
- package/dist/assets/{cell-link-B1pHtGWp.js → cell-link-D26yaUlf.js} +1 -1
- package/dist/assets/{cells-BsaJrRWi.js → cells-DZTFtAVj.js} +51 -51
- package/dist/assets/{chat-display-ccjE30z9.js → chat-display-BgfGVz5S.js} +1 -1
- package/dist/assets/{chat-panel-CtvtP3kb.js → chat-panel-CXxu4TZ_.js} +1 -1
- package/dist/assets/{chat-ui-DV8CD_s1.js → chat-ui-BkyiYz6q.js} +1 -1
- package/dist/assets/{column-preview-BPismotx.js → column-preview-DEY7H3Nv.js} +1 -1
- package/dist/assets/{command-palette-Cdy8eCpi.js → command-palette-DNG8Q_or.js} +1 -1
- package/dist/assets/{common-6n8M1qiK.js → common-BMiQG5NP.js} +1 -1
- package/dist/assets/{components-BzBUxUz0.js → components-DYnN18mE.js} +1 -1
- package/dist/assets/{components-CK-WtvAJ.js → components-r46WLNJG.js} +1 -1
- package/dist/assets/{datasource-DjDpJnbt.js → datasource-B7h8qmJZ.js} +1 -1
- package/dist/assets/{dependency-graph-panel-BNaXAcZr.js → dependency-graph-panel-uTlnFEz0.js} +1 -1
- package/dist/assets/{documentation-panel-5jUKZR-l.js → documentation-panel-DNberbcy.js} +1 -1
- package/dist/assets/{download-DT8gf0PL.js → download-HxGLUdmz.js} +1 -1
- package/dist/assets/{edit-page-C-qF9lwB.js → edit-page-CJPMGRxx.js} +3 -3
- package/dist/assets/{error-panel-DHcg_ER5.js → error-panel-D5hoQy8n.js} +1 -1
- package/dist/assets/{file-explorer-panel-CbOdvGyZ.js → file-explorer-panel-Dpu3jlWY.js} +1 -1
- package/dist/assets/{file-icons-BiMOJy0r.js → file-icons-BrqycRag.js} +1 -1
- package/dist/assets/{floating-outline-BN9sAcQ0.js → floating-outline-BnioYLEY.js} +1 -1
- package/dist/assets/{focus-q38vUCl-.js → focus-D3CLyF2k.js} +1 -1
- package/dist/assets/{form-BtBTvVVd.js → form-DdqAF_p5.js} +1 -1
- package/dist/assets/{home-page-lXjPDNM0.js → home-page-hvU2Ck7f.js} +1 -1
- package/dist/assets/{hooks-DP41kAWj.js → hooks-CneeLUm3.js} +1 -1
- package/dist/assets/{html-to-image-BWL3Ct4n.js → html-to-image-BoIWRm-U.js} +1 -1
- package/dist/assets/{index-CE1XkZU_.js → index-CgI7_ZFC.js} +3 -3
- package/dist/assets/{kiosk-mode-BqvqWsFx.js → kiosk-mode-CZZ1SAgt.js} +1 -1
- package/dist/assets/{layout-DXDnDtNw.js → layout-tjJkaOem.js} +3 -3
- package/dist/assets/{logs-panel-BNoBKY1q.js → logs-panel-fbUDvNKz.js} +1 -1
- package/dist/assets/{markdown-renderer-CU5Lbyax.js → markdown-renderer-BGO5zfUp.js} +1 -1
- package/dist/assets/{name-cell-input-BNc3X9qF.js → name-cell-input-IbrFfjTR.js} +1 -1
- package/dist/assets/{outline-panel-De2gw3Ro.js → outline-panel-BQ87B9Ft.js} +1 -1
- package/dist/assets/{packages-panel-C8maQt0Q.js → packages-panel-ChY1D8eZ.js} +1 -1
- package/dist/assets/{panels-BKv_j2lC.js → panels-DWrP0hzF.js} +1 -1
- package/dist/assets/{process-output-B2oklQi4.js → process-output-CW1wS2Hr.js} +1 -1
- package/dist/assets/{radio-group-DlVSuZ_1.js → radio-group-9x2A1Fsc.js} +1 -1
- package/dist/assets/{readonly-python-code-D3_kHsDx.js → readonly-python-code-CEfd-Ppu.js} +1 -1
- package/dist/assets/{reveal-component-C50CTy8h.js → reveal-component-D13HX3en.js} +1 -1
- package/dist/assets/{run-page-DeOIw0On.js → run-page-BNG5gaoM.js} +1 -1
- package/dist/assets/{scratchpad-panel-DWbD_QB3.js → scratchpad-panel-fupP7ZgK.js} +1 -1
- package/dist/assets/{session-panel-BHgL-7KC.js → session-panel-B9dcCqYr.js} +1 -1
- package/dist/assets/{snippets-panel-FY_Ezibl.js → snippets-panel-C4UEEe7X.js} +1 -1
- package/dist/assets/{state-BTTshiKq.js → state-C6hNg_X-.js} +1 -1
- package/dist/assets/{state-D-2KaAHK.js → state-D2ocm4JL.js} +1 -1
- package/dist/assets/{textarea-DwltG8V6.js → textarea-C3qk0qJ7.js} +1 -1
- package/dist/assets/{tracing-zLH-qWb2.js → tracing-B0e3S01T.js} +1 -1
- package/dist/assets/{tracing-panel-bN0O3PuU.js → tracing-panel-CmLBnJCg.js} +2 -2
- package/dist/assets/{useCellActionButton-h5LjhtEx.js → useCellActionButton-D2MPJYfm.js} +1 -1
- package/dist/assets/{useDeleteCell-BBPIhnQj.js → useDeleteCell-vHE9B5l2.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-BSkmlMqr.js → useDependencyPanelTab-DK6mAVzQ.js} +1 -1
- package/dist/assets/{useNotebookActions-B32eCmtG.js → useNotebookActions-BV5iVwE4.js} +1 -1
- package/dist/assets/{useRunCells-BiCBGyeW.js → useRunCells-Dt6DS29E.js} +1 -1
- package/dist/assets/{useSplitCell-uogO-7ac.js → useSplitCell-VdsEBWhq.js} +1 -1
- package/dist/index.html +22 -22
- package/package.json +1 -1
- package/src/core/cells/__tests__/document-changes.test.ts +201 -2
- package/src/core/cells/document-changes.ts +61 -3
package/dist/index.html
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
<marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
|
|
67
67
|
<!-- /TODO -->
|
|
68
68
|
<title>{{ title }}</title>
|
|
69
|
-
<script type="module" crossorigin src="./assets/index-
|
|
69
|
+
<script type="module" crossorigin src="./assets/index-CgI7_ZFC.js"></script>
|
|
70
70
|
<link rel="modulepreload" crossorigin href="./assets/preload-helper-BPPi7vOr.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="./assets/chunk-LvLJmgfZ.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="./assets/react-Bj1aDYRI.js">
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
<link rel="modulepreload" crossorigin href="./assets/debounce-DhnxH9Rh.js">
|
|
134
134
|
<link rel="modulepreload" crossorigin href="./assets/database-zap-kIkTfzTX.js">
|
|
135
135
|
<link rel="modulepreload" crossorigin href="./assets/main-B0OX4z33.js">
|
|
136
|
-
<link rel="modulepreload" crossorigin href="./assets/cells-
|
|
136
|
+
<link rel="modulepreload" crossorigin href="./assets/cells-DZTFtAVj.js">
|
|
137
137
|
<link rel="modulepreload" crossorigin href="./assets/ErrorBoundary-DyYDV0HI.js">
|
|
138
138
|
<link rel="modulepreload" crossorigin href="./assets/kbd-CTUAEnEx.js">
|
|
139
139
|
<link rel="modulepreload" crossorigin href="./assets/useInstallPackage-DUF4IRRI.js">
|
|
@@ -147,35 +147,35 @@
|
|
|
147
147
|
<link rel="modulepreload" crossorigin href="./assets/usePress-DQ_tAz5W.js">
|
|
148
148
|
<link rel="modulepreload" crossorigin href="./assets/input-C3Hrdlqq.js">
|
|
149
149
|
<link rel="modulepreload" crossorigin href="./assets/ImperativeModal-B3Th7k4R.js">
|
|
150
|
-
<link rel="modulepreload" crossorigin href="./assets/cell-link-
|
|
150
|
+
<link rel="modulepreload" crossorigin href="./assets/cell-link-D26yaUlf.js">
|
|
151
151
|
<link rel="modulepreload" crossorigin href="./assets/multi-map-CUuNtzHt.js">
|
|
152
152
|
<link rel="modulepreload" crossorigin href="./assets/alert-yTS3WpF4.js">
|
|
153
153
|
<link rel="modulepreload" crossorigin href="./assets/chevron-right-CG5QYXYk.js">
|
|
154
154
|
<link rel="modulepreload" crossorigin href="./assets/dropdown-menu-CR7cnzLX.js">
|
|
155
155
|
<link rel="modulepreload" crossorigin href="./assets/links-D1JoyKTt.js">
|
|
156
|
-
<link rel="modulepreload" crossorigin href="./assets/useRunCells-
|
|
156
|
+
<link rel="modulepreload" crossorigin href="./assets/useRunCells-Dt6DS29E.js">
|
|
157
157
|
<link rel="modulepreload" crossorigin href="./assets/copy-LK56fFow.js">
|
|
158
158
|
<link rel="modulepreload" crossorigin href="./assets/copy-BwrPA9zQ.js">
|
|
159
159
|
<link rel="modulepreload" crossorigin href="./assets/copy-icon-OjtDb4gO.js">
|
|
160
|
-
<link rel="modulepreload" crossorigin href="./assets/RenderHTML-
|
|
161
|
-
<link rel="modulepreload" crossorigin href="./assets/datasource-
|
|
162
|
-
<link rel="modulepreload" crossorigin href="./assets/state-
|
|
160
|
+
<link rel="modulepreload" crossorigin href="./assets/RenderHTML-BpmpkBqm.js">
|
|
161
|
+
<link rel="modulepreload" crossorigin href="./assets/datasource-B7h8qmJZ.js">
|
|
162
|
+
<link rel="modulepreload" crossorigin href="./assets/state-D2ocm4JL.js">
|
|
163
163
|
<link rel="modulepreload" crossorigin href="./assets/package-Tv6ztuzw.js">
|
|
164
164
|
<link rel="modulepreload" crossorigin href="./assets/sparkles-lWUAsPhp.js">
|
|
165
|
-
<link rel="modulepreload" crossorigin href="./assets/MarimoErrorOutput-
|
|
165
|
+
<link rel="modulepreload" crossorigin href="./assets/MarimoErrorOutput-IoNFtcZT.js">
|
|
166
166
|
<link rel="modulepreload" crossorigin href="./assets/spinner-Bhir8k53.js">
|
|
167
|
-
<link rel="modulepreload" crossorigin href="./assets/html-to-image-
|
|
168
|
-
<link rel="modulepreload" crossorigin href="./assets/focus-
|
|
167
|
+
<link rel="modulepreload" crossorigin href="./assets/html-to-image-BoIWRm-U.js">
|
|
168
|
+
<link rel="modulepreload" crossorigin href="./assets/focus-D3CLyF2k.js">
|
|
169
169
|
<link rel="modulepreload" crossorigin href="./assets/useAsyncData-bgszE9F0.js">
|
|
170
170
|
<link rel="modulepreload" crossorigin href="./assets/LazyAnyLanguageCodeMirror-BEvXb3VX.js">
|
|
171
171
|
<link rel="modulepreload" crossorigin href="./assets/micromark-factory-space-BygYYKhs.js">
|
|
172
172
|
<link rel="modulepreload" crossorigin href="./assets/chunk-5FQGJX7Z-D9iBG0F7.js">
|
|
173
|
-
<link rel="modulepreload" crossorigin href="./assets/markdown-renderer-
|
|
173
|
+
<link rel="modulepreload" crossorigin href="./assets/markdown-renderer-BGO5zfUp.js">
|
|
174
174
|
<link rel="modulepreload" crossorigin href="./assets/command-KARR7KMq.js">
|
|
175
175
|
<link rel="modulepreload" crossorigin href="./assets/field-zLmMOSA4.js">
|
|
176
176
|
<link rel="modulepreload" crossorigin href="./assets/popover-Bz_0Vkyf.js">
|
|
177
177
|
<link rel="modulepreload" crossorigin href="./assets/errors-vr57w7Ul.js">
|
|
178
|
-
<link rel="modulepreload" crossorigin href="./assets/download-
|
|
178
|
+
<link rel="modulepreload" crossorigin href="./assets/download-HxGLUdmz.js">
|
|
179
179
|
<link rel="modulepreload" crossorigin href="./assets/table-BGPSHfig.js">
|
|
180
180
|
<link rel="modulepreload" crossorigin href="./assets/useIframeCapabilities-CcI1zSdn.js">
|
|
181
181
|
<link rel="modulepreload" crossorigin href="./assets/error-banner-LdWZDbqd.js">
|
|
@@ -196,25 +196,25 @@
|
|
|
196
196
|
<link rel="modulepreload" crossorigin href="./assets/plus-BgB18UzY.js">
|
|
197
197
|
<link rel="modulepreload" crossorigin href="./assets/trash-2-rVklqqFF.js">
|
|
198
198
|
<link rel="modulepreload" crossorigin href="./assets/react-resizable-panels.browser.esm-CV8-hvjx.js">
|
|
199
|
-
<link rel="modulepreload" crossorigin href="./assets/JsonOutput-
|
|
199
|
+
<link rel="modulepreload" crossorigin href="./assets/JsonOutput-sim6s58u.js">
|
|
200
200
|
<link rel="modulepreload" crossorigin href="./assets/chart-no-axes-column-nqk474t8.js">
|
|
201
201
|
<link rel="modulepreload" crossorigin href="./assets/square-function-uY_yJr5g.js">
|
|
202
202
|
<link rel="modulepreload" crossorigin href="./assets/spec-CPQR_o92.js">
|
|
203
203
|
<link rel="modulepreload" crossorigin href="./assets/ellipsis-vertical-CkwWkOQL.js">
|
|
204
204
|
<link rel="modulepreload" crossorigin href="./assets/refresh-cw-DHwG4Mac.js">
|
|
205
205
|
<link rel="modulepreload" crossorigin href="./assets/tree-actions-BM_EJr3E.js">
|
|
206
|
-
<link rel="modulepreload" crossorigin href="./assets/components-
|
|
207
|
-
<link rel="modulepreload" crossorigin href="./assets/column-preview-
|
|
206
|
+
<link rel="modulepreload" crossorigin href="./assets/components-DYnN18mE.js">
|
|
207
|
+
<link rel="modulepreload" crossorigin href="./assets/column-preview-DEY7H3Nv.js">
|
|
208
208
|
<link rel="modulepreload" crossorigin href="./assets/icons-Ol38nIbL.js">
|
|
209
|
-
<link rel="modulepreload" crossorigin href="./assets/radio-group-
|
|
210
|
-
<link rel="modulepreload" crossorigin href="./assets/floating-outline-
|
|
209
|
+
<link rel="modulepreload" crossorigin href="./assets/radio-group-9x2A1Fsc.js">
|
|
210
|
+
<link rel="modulepreload" crossorigin href="./assets/floating-outline-BnioYLEY.js">
|
|
211
211
|
<link rel="modulepreload" crossorigin href="./assets/objectWithoutPropertiesLoose-DfWeGRFv.js">
|
|
212
212
|
<link rel="modulepreload" crossorigin href="./assets/esm-CqWdmSnV.js">
|
|
213
|
-
<link rel="modulepreload" crossorigin href="./assets/readonly-python-code-
|
|
213
|
+
<link rel="modulepreload" crossorigin href="./assets/readonly-python-code-CEfd-Ppu.js">
|
|
214
214
|
<link rel="modulepreload" crossorigin href="./assets/file-headphone-BrQspHac.js">
|
|
215
215
|
<link rel="modulepreload" crossorigin href="./assets/file-BrdxGLRX.js">
|
|
216
216
|
<link rel="modulepreload" crossorigin href="./assets/image-DQHXdEQn.js">
|
|
217
|
-
<link rel="modulepreload" crossorigin href="./assets/file-icons-
|
|
217
|
+
<link rel="modulepreload" crossorigin href="./assets/file-icons-BrqycRag.js">
|
|
218
218
|
<link rel="modulepreload" crossorigin href="./assets/switch-BiU_sAcn.js">
|
|
219
219
|
<link rel="modulepreload" crossorigin href="./assets/events-CPoJAfgx.js">
|
|
220
220
|
<link rel="modulepreload" crossorigin href="./assets/globals-7JnRMGd4.js">
|
|
@@ -223,11 +223,11 @@
|
|
|
223
223
|
<link rel="modulepreload" crossorigin href="./assets/memoize-Tp7rARFe.js">
|
|
224
224
|
<link rel="modulepreload" crossorigin href="./assets/get-C-qh_et5.js">
|
|
225
225
|
<link rel="modulepreload" crossorigin href="./assets/_baseSet-CxV9N1bc.js">
|
|
226
|
-
<link rel="modulepreload" crossorigin href="./assets/state-
|
|
226
|
+
<link rel="modulepreload" crossorigin href="./assets/state-C6hNg_X-.js">
|
|
227
227
|
<link rel="modulepreload" crossorigin href="./assets/label-xHqFtfdz.js">
|
|
228
|
-
<link rel="modulepreload" crossorigin href="./assets/textarea-
|
|
228
|
+
<link rel="modulepreload" crossorigin href="./assets/textarea-C3qk0qJ7.js">
|
|
229
229
|
<link rel="modulepreload" crossorigin href="./assets/refresh-ccw-C-n2VFP5.js">
|
|
230
|
-
<link rel="modulepreload" crossorigin href="./assets/form-
|
|
230
|
+
<link rel="modulepreload" crossorigin href="./assets/form-DdqAF_p5.js">
|
|
231
231
|
<link rel="modulepreload" crossorigin href="./assets/renderShortcut-CcFk3m01.js">
|
|
232
232
|
<link rel="modulepreload" crossorigin href="./assets/useBoolean-Bp18o6XG.js">
|
|
233
233
|
<link rel="modulepreload" crossorigin href="./assets/useDeepCompareMemoize-zUHU--0D.js">
|
package/package.json
CHANGED
|
@@ -16,14 +16,32 @@
|
|
|
16
16
|
import { python } from "@codemirror/lang-python";
|
|
17
17
|
import { EditorState } from "@codemirror/state";
|
|
18
18
|
import { EditorView } from "@codemirror/view";
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
afterAll,
|
|
21
|
+
afterEach,
|
|
22
|
+
beforeAll,
|
|
23
|
+
beforeEach,
|
|
24
|
+
describe,
|
|
25
|
+
expect,
|
|
26
|
+
it,
|
|
27
|
+
vi,
|
|
28
|
+
} from "vitest";
|
|
20
29
|
import { cellId } from "@/__tests__/branded";
|
|
21
30
|
import type { CellHandle } from "@/components/editor/notebook-cell";
|
|
22
31
|
import { adaptiveLanguageConfiguration } from "@/core/codemirror/language/extension";
|
|
23
32
|
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
|
|
33
|
+
import { requestClientAtom } from "@/core/network/requests";
|
|
34
|
+
import type { EditRequests, RunRequests } from "@/core/network/types";
|
|
35
|
+
import { store } from "@/core/state/jotai";
|
|
24
36
|
import { MultiColumn } from "@/utils/id-tree";
|
|
25
37
|
import { exportedForTesting, type NotebookState } from "../cells";
|
|
26
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
type CellAction,
|
|
40
|
+
coalesceChanges,
|
|
41
|
+
type DocumentChange,
|
|
42
|
+
exportedForTesting as middlewareExports,
|
|
43
|
+
toDocumentChanges,
|
|
44
|
+
} from "../document-changes";
|
|
27
45
|
import { CellId } from "../ids";
|
|
28
46
|
|
|
29
47
|
const { initialNotebookState, reducer } = exportedForTesting;
|
|
@@ -584,3 +602,184 @@ describe("toDocumentChanges", () => {
|
|
|
584
602
|
});
|
|
585
603
|
});
|
|
586
604
|
});
|
|
605
|
+
|
|
606
|
+
describe("coalesceChanges", () => {
|
|
607
|
+
const X = cellId("X");
|
|
608
|
+
const Y = cellId("Y");
|
|
609
|
+
const A = cellId("A");
|
|
610
|
+
const config = { column: null, disabled: false, hide_code: false };
|
|
611
|
+
|
|
612
|
+
it("drops set-code that precedes a delete of the same cell", () => {
|
|
613
|
+
const changes: DocumentChange[] = [
|
|
614
|
+
{ type: "set-code", cellId: X, code: "x = 2" },
|
|
615
|
+
{ type: "delete-cell", cellId: X },
|
|
616
|
+
];
|
|
617
|
+
expect(coalesceChanges(changes)).toEqual([
|
|
618
|
+
{ type: "delete-cell", cellId: X },
|
|
619
|
+
]);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it("keeps create+delete for a created-then-deleted cell, dropping the edit", () => {
|
|
623
|
+
const changes: DocumentChange[] = [
|
|
624
|
+
{ type: "create-cell", cellId: X, code: "", name: "_", config },
|
|
625
|
+
{ type: "set-code", cellId: X, code: "x = 1" },
|
|
626
|
+
{ type: "delete-cell", cellId: X },
|
|
627
|
+
];
|
|
628
|
+
expect(coalesceChanges(changes)).toEqual([
|
|
629
|
+
{ type: "create-cell", cellId: X, code: "", name: "_", config },
|
|
630
|
+
{ type: "delete-cell", cellId: X },
|
|
631
|
+
]);
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
it("drops set-code, set-name, set-config, and move-cell for a deleted cell", () => {
|
|
635
|
+
const changes: DocumentChange[] = [
|
|
636
|
+
{ type: "create-cell", cellId: X, code: "", name: "_", config },
|
|
637
|
+
{ type: "set-code", cellId: X, code: "x = 1" },
|
|
638
|
+
{ type: "set-name", cellId: X, name: "foo" },
|
|
639
|
+
{
|
|
640
|
+
type: "set-config",
|
|
641
|
+
cellId: X,
|
|
642
|
+
column: null,
|
|
643
|
+
disabled: true,
|
|
644
|
+
hideCode: false,
|
|
645
|
+
},
|
|
646
|
+
{ type: "move-cell", cellId: X, after: A },
|
|
647
|
+
{ type: "delete-cell", cellId: X },
|
|
648
|
+
];
|
|
649
|
+
expect(coalesceChanges(changes)).toEqual([
|
|
650
|
+
{ type: "create-cell", cellId: X, code: "", name: "_", config },
|
|
651
|
+
{ type: "delete-cell", cellId: X },
|
|
652
|
+
]);
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
it("leaves a plain delete of an unedited cell unchanged", () => {
|
|
656
|
+
const changes: DocumentChange[] = [{ type: "delete-cell", cellId: X }];
|
|
657
|
+
expect(coalesceChanges(changes)).toEqual([
|
|
658
|
+
{ type: "delete-cell", cellId: X },
|
|
659
|
+
]);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
it("does not touch set-* for cells that are not deleted, preserving order", () => {
|
|
663
|
+
const changes: DocumentChange[] = [
|
|
664
|
+
{ type: "set-code", cellId: A, code: "a = 1" },
|
|
665
|
+
{ type: "set-code", cellId: Y, code: "y = 1" },
|
|
666
|
+
{ type: "delete-cell", cellId: X },
|
|
667
|
+
];
|
|
668
|
+
expect(coalesceChanges(changes)).toEqual([
|
|
669
|
+
{ type: "set-code", cellId: A, code: "a = 1" },
|
|
670
|
+
{ type: "set-code", cellId: Y, code: "y = 1" },
|
|
671
|
+
{ type: "delete-cell", cellId: X },
|
|
672
|
+
]);
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
it("collapses repeated set-code for a surviving cell to the last value", () => {
|
|
676
|
+
const changes: DocumentChange[] = [
|
|
677
|
+
{ type: "set-code", cellId: X, code: "x = 1" },
|
|
678
|
+
{ type: "set-name", cellId: X, name: "foo" },
|
|
679
|
+
{ type: "set-code", cellId: X, code: "x = 2" },
|
|
680
|
+
];
|
|
681
|
+
expect(coalesceChanges(changes)).toEqual([
|
|
682
|
+
{ type: "set-name", cellId: X, name: "foo" },
|
|
683
|
+
{ type: "set-code", cellId: X, code: "x = 2" },
|
|
684
|
+
]);
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
it("keeps both creates so a downstream anchor stays resolvable", () => {
|
|
688
|
+
const changes: DocumentChange[] = [
|
|
689
|
+
{ type: "create-cell", cellId: X, code: "", name: "_", config, after: A },
|
|
690
|
+
{ type: "create-cell", cellId: Y, code: "", name: "_", config, after: X },
|
|
691
|
+
{ type: "delete-cell", cellId: X },
|
|
692
|
+
];
|
|
693
|
+
expect(coalesceChanges(changes)).toEqual([
|
|
694
|
+
{ type: "create-cell", cellId: X, code: "", name: "_", config, after: A },
|
|
695
|
+
{ type: "create-cell", cellId: Y, code: "", name: "_", config, after: X },
|
|
696
|
+
{ type: "delete-cell", cellId: X },
|
|
697
|
+
]);
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* End-to-end of the debounced flush path: dispatch through the real middleware
|
|
703
|
+
* reducer, let the debounce fire, and inspect the batch that reaches
|
|
704
|
+
* sendDocumentTransaction. Coalescing only matters once edits actually share a
|
|
705
|
+
* debounce window, which drainChanges-based tests can't observe.
|
|
706
|
+
*/
|
|
707
|
+
describe("flush path coalescing", () => {
|
|
708
|
+
let sent: DocumentChange[][];
|
|
709
|
+
|
|
710
|
+
beforeEach(() => {
|
|
711
|
+
vi.useFakeTimers();
|
|
712
|
+
sent = [];
|
|
713
|
+
middlewareExports.cancelPendingChanges();
|
|
714
|
+
const captureClient: Pick<
|
|
715
|
+
EditRequests & RunRequests,
|
|
716
|
+
"sendDocumentTransaction"
|
|
717
|
+
> = {
|
|
718
|
+
sendDocumentTransaction: async ({ changes }) => {
|
|
719
|
+
sent.push(changes);
|
|
720
|
+
return null;
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
store.set(
|
|
724
|
+
requestClientAtom,
|
|
725
|
+
captureClient as unknown as EditRequests & RunRequests,
|
|
726
|
+
);
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
afterEach(() => {
|
|
730
|
+
middlewareExports.cancelPendingChanges();
|
|
731
|
+
store.set(requestClientAtom, null);
|
|
732
|
+
vi.useRealTimers();
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
it("coalesces edit + delete of the same cell within one debounce window", () => {
|
|
736
|
+
setup("x = 1");
|
|
737
|
+
const [x] = state.cellIds.inOrderIds;
|
|
738
|
+
// Discard the create-cell from setup; it would flush as its own batch.
|
|
739
|
+
middlewareExports.cancelPendingChanges();
|
|
740
|
+
|
|
741
|
+
// Same window: edit the cell, then delete it, with no timer advance.
|
|
742
|
+
state = dispatch(state, {
|
|
743
|
+
type: "updateCellCode",
|
|
744
|
+
payload: { cellId: x, code: "x = 2", formattingChange: false },
|
|
745
|
+
});
|
|
746
|
+
state = dispatch(state, {
|
|
747
|
+
type: "deleteCell",
|
|
748
|
+
payload: { cellId: x },
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
// Debounced: nothing on the wire yet.
|
|
752
|
+
expect(sent).toEqual([]);
|
|
753
|
+
|
|
754
|
+
vi.advanceTimersByTime(400);
|
|
755
|
+
|
|
756
|
+
// One transaction, and it is just the delete — the conflicting set-code
|
|
757
|
+
// has been dropped, so the server never sees edit+delete of one cell.
|
|
758
|
+
expect(sent).toHaveLength(1);
|
|
759
|
+
expect(sent[0]).toEqual([{ type: "delete-cell", cellId: x }]);
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
it("sends edit and delete as separate clean transactions across windows", () => {
|
|
763
|
+
setup("x = 1");
|
|
764
|
+
const [x] = state.cellIds.inOrderIds;
|
|
765
|
+
middlewareExports.cancelPendingChanges();
|
|
766
|
+
|
|
767
|
+
state = dispatch(state, {
|
|
768
|
+
type: "updateCellCode",
|
|
769
|
+
payload: { cellId: x, code: "x = 2", formattingChange: false },
|
|
770
|
+
});
|
|
771
|
+
vi.advanceTimersByTime(400);
|
|
772
|
+
|
|
773
|
+
state = dispatch(state, {
|
|
774
|
+
type: "deleteCell",
|
|
775
|
+
payload: { cellId: x },
|
|
776
|
+
});
|
|
777
|
+
vi.advanceTimersByTime(400);
|
|
778
|
+
|
|
779
|
+
// Two separate, individually-valid transactions: neither conflicts, which
|
|
780
|
+
// is why the bug only ever surfaced when both landed in the same window.
|
|
781
|
+
expect(sent).toHaveLength(2);
|
|
782
|
+
expect(sent[0]).toEqual([{ type: "set-code", cellId: x, code: "x = 2" }]);
|
|
783
|
+
expect(sent[1]).toEqual([{ type: "delete-cell", cellId: x }]);
|
|
784
|
+
});
|
|
785
|
+
});
|
|
@@ -568,6 +568,64 @@ export function fromDocumentChanges(
|
|
|
568
568
|
return actions;
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
// ---------------------------------------------------------------------------
|
|
572
|
+
// Coalescing: reduce a buffered change sequence to its net effect
|
|
573
|
+
// ---------------------------------------------------------------------------
|
|
574
|
+
|
|
575
|
+
const COLLAPSIBLE_TYPES = new Set(["set-code", "set-name", "set-config"]);
|
|
576
|
+
const DROPPABLE_ON_DELETE = new Set([
|
|
577
|
+
"set-code",
|
|
578
|
+
"set-name",
|
|
579
|
+
"set-config",
|
|
580
|
+
"move-cell",
|
|
581
|
+
]);
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Reduce a buffered sequence of changes to an equivalent batch that reflects
|
|
585
|
+
* net effect rather than edit history. The server applies a transaction
|
|
586
|
+
* atomically and rejects internally contradictory batches (e.g. updating a
|
|
587
|
+
* cell that is also deleted in the same transaction), so a debounced sequence
|
|
588
|
+
* of edits must be reconciled before it is sent.
|
|
589
|
+
*
|
|
590
|
+
* Two reductions, both order-preserving:
|
|
591
|
+
* - For any cell deleted in the batch, drop its property/move changes. The
|
|
592
|
+
* `create-cell` and `delete-cell` are kept so anchors referencing the cell
|
|
593
|
+
* stay resolvable on the server; create+delete applies to a net no-op.
|
|
594
|
+
* - Collapse repeated `set-code`/`set-name`/`set-config` for a surviving cell
|
|
595
|
+
* to the last occurrence.
|
|
596
|
+
*/
|
|
597
|
+
export function coalesceChanges(changes: DocumentChange[]): DocumentChange[] {
|
|
598
|
+
const deletedIds = new Set<CellId>();
|
|
599
|
+
for (const change of changes) {
|
|
600
|
+
if (change.type === "delete-cell") {
|
|
601
|
+
deletedIds.add(change.cellId);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const withoutEditsToDeletedCells = changes.filter(
|
|
606
|
+
(change) =>
|
|
607
|
+
!(
|
|
608
|
+
DROPPABLE_ON_DELETE.has(change.type) &&
|
|
609
|
+
"cellId" in change &&
|
|
610
|
+
deletedIds.has(change.cellId)
|
|
611
|
+
),
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
const lastIndexByKey = new Map<string, number>();
|
|
615
|
+
withoutEditsToDeletedCells.forEach((change, index) => {
|
|
616
|
+
if (COLLAPSIBLE_TYPES.has(change.type) && "cellId" in change) {
|
|
617
|
+
lastIndexByKey.set(`${change.type}:${change.cellId}`, index);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
return withoutEditsToDeletedCells.filter((change, index) => {
|
|
622
|
+
if (COLLAPSIBLE_TYPES.has(change.type) && "cellId" in change) {
|
|
623
|
+
return lastIndexByKey.get(`${change.type}:${change.cellId}`) === index;
|
|
624
|
+
}
|
|
625
|
+
return true;
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
571
629
|
// ---------------------------------------------------------------------------
|
|
572
630
|
// Middleware: debounced change dispatch to the server
|
|
573
631
|
// ---------------------------------------------------------------------------
|
|
@@ -575,11 +633,11 @@ export function fromDocumentChanges(
|
|
|
575
633
|
let pendingChanges: DocumentChange[] = [];
|
|
576
634
|
|
|
577
635
|
const flushChanges = debounce(() => {
|
|
578
|
-
|
|
636
|
+
const changes = coalesceChanges(pendingChanges);
|
|
637
|
+
pendingChanges = [];
|
|
638
|
+
if (changes.length === 0) {
|
|
579
639
|
return;
|
|
580
640
|
}
|
|
581
|
-
const changes = pendingChanges;
|
|
582
|
-
pendingChanges = [];
|
|
583
641
|
void getRequestClient().sendDocumentTransaction({ changes });
|
|
584
642
|
}, 400);
|
|
585
643
|
|