@marimo-team/islands 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/{chat-ui-ChD4VvCo.js → chat-ui-ar37brtL.js} +2 -2
- package/dist/{code-visibility-B3oOX_TK.js → code-visibility-B88v1No3.js} +2 -2
- package/dist/{html-to-image-BHv7CEU_.js → html-to-image-Cp8O1OWB.js} +2126 -2109
- package/dist/main.js +5 -5
- package/dist/{process-output-BvySRgli.js → process-output-CaUUWhh8.js} +1 -1
- package/dist/{reveal-component-Dj4x14QX.js → reveal-component-CfFoUPFg.js} +2 -2
- 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/main.js
CHANGED
|
@@ -22,17 +22,17 @@ import { _ as Logger, c as Objects, g as cn, h as Events, i as NOT_SET, l as use
|
|
|
22
22
|
import { t as require_react } from "./react-DA-nE2FX.js";
|
|
23
23
|
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
24
24
|
import { n as Copy, r as toast, t as copyToClipboard } from "./copy-BuQpJEzp.js";
|
|
25
|
-
import { $ as useCellActions, An as LoaderCircle, At as DeferredRequestRegistry, B as safeExtractSetUIElementMessageBuffers, Bn as Braces, Bt as getDataTypeColor, C as AccordionContent, Cn as Trigger2, Ct as customPythonLanguageSupport, Dn as PaintRoller, Dt as Paths, E as BorderAllIcon, En as Table2, Et as PathBuilder, F as base64ToDataView, Ft as jotaiJsonStorage, Gt as convertStatsName, H as getMarimoExportContext, In as Database, J as getCellNames, Jt as useRequestClient, K as createActions, Kt as getRequestClient, L as dataViewToBase64, Ln as Columns2, Mn as Info, Nn as FileText, Nt as repl, Pn as Eye, Q as reducer, Rt as PluralWords, S as Accordion, Sn as Root2$1, St as Checkbox, T as AccordionTrigger, Tn as Trash2, U as hasTrustedExportContext, V as renderHTML, Vt as require_client, W as hasRunAnyCellAtom, X as notebookOutline, Y as notebookAtom, Yt as isUninstantiated, Z as numColumnsAtom, _n as selectAtom, a as useCellFocusActions, an as parseInitialValue, bn as Content2, bt as isInternalCellName, ct as kioskModeAtom, dn as OBJECT_ID_ATTR, dt as outputIsLoading, en as NotebookScopedLocalStorage, et as useCellIds, f as isOutputEmpty, fn as RANDOM_ID_ATTR, ft as outputIsStale, gn as atomWithStorage, hn as atomWithReducer, i as LazyAnyLanguageCodeMirror, in as parseDataset, jn as Layers, jt as generateUUID, k as ChevronDownIcon, ln as UIElementId, mt as headingToIdentifier, n as Spinner, nt as createCell, o as useLastFocusedCellId, ot as getInitialAppMode, p as useExpandedConsoleOutput, pn as jsonParseWithSpecialChar, pt as isErrorMime, qt as requestClientAtom, rn as parseAttrValue, s as maybeAddAltairImport, sn as HTMLCellId, st as initialModeAtom, un as findCellId, w as AccordionItem, wt as MarkdownLanguageAdapter, xn as Item$1, xt as normalizeName, yt as getValidName, zn as CircleAlert, zt as DATA_TYPE_ICON, __tla as __tla_0 } from "./html-to-image-
|
|
25
|
+
import { $ as useCellActions, An as LoaderCircle, At as DeferredRequestRegistry, B as safeExtractSetUIElementMessageBuffers, Bn as Braces, Bt as getDataTypeColor, C as AccordionContent, Cn as Trigger2, Ct as customPythonLanguageSupport, Dn as PaintRoller, Dt as Paths, E as BorderAllIcon, En as Table2, Et as PathBuilder, F as base64ToDataView, Ft as jotaiJsonStorage, Gt as convertStatsName, H as getMarimoExportContext, In as Database, J as getCellNames, Jt as useRequestClient, K as createActions, Kt as getRequestClient, L as dataViewToBase64, Ln as Columns2, Mn as Info, Nn as FileText, Nt as repl, Pn as Eye, Q as reducer, Rt as PluralWords, S as Accordion, Sn as Root2$1, St as Checkbox, T as AccordionTrigger, Tn as Trash2, U as hasTrustedExportContext, V as renderHTML, Vt as require_client, W as hasRunAnyCellAtom, X as notebookOutline, Y as notebookAtom, Yt as isUninstantiated, Z as numColumnsAtom, _n as selectAtom, a as useCellFocusActions, an as parseInitialValue, bn as Content2, bt as isInternalCellName, ct as kioskModeAtom, dn as OBJECT_ID_ATTR, dt as outputIsLoading, en as NotebookScopedLocalStorage, et as useCellIds, f as isOutputEmpty, fn as RANDOM_ID_ATTR, ft as outputIsStale, gn as atomWithStorage, hn as atomWithReducer, i as LazyAnyLanguageCodeMirror, in as parseDataset, jn as Layers, jt as generateUUID, k as ChevronDownIcon, ln as UIElementId, mt as headingToIdentifier, n as Spinner, nt as createCell, o as useLastFocusedCellId, ot as getInitialAppMode, p as useExpandedConsoleOutput, pn as jsonParseWithSpecialChar, pt as isErrorMime, qt as requestClientAtom, rn as parseAttrValue, s as maybeAddAltairImport, sn as HTMLCellId, st as initialModeAtom, un as findCellId, w as AccordionItem, wt as MarkdownLanguageAdapter, xn as Item$1, xt as normalizeName, yt as getValidName, zn as CircleAlert, zt as DATA_TYPE_ICON, __tla as __tla_0 } from "./html-to-image-Cp8O1OWB.js";
|
|
26
26
|
import { __tla as __tla_1 } from "./chunk-5FQGJX7Z-BNjes6Yx.js";
|
|
27
27
|
import { o as useSize, s as Root$2, u as createLucideIcon } from "./dist-C1BYNeCR.js";
|
|
28
28
|
import { A as SquareFunction, C as DEFAULT_COLOR_SCHEME, D as SCALE_TYPE_DESCRIPTIONS, E as EMPTY_VALUE$1, O as TIME_UNIT_DESCRIPTIONS, S as DEFAULT_AGGREGATION, T as DEFAULT_TIME_UNIT, _ as AGGREGATION_TYPE_DESCRIPTIONS, a as AGGREGATION_FNS$1, b as COLOR_SCHEMES, c as COLOR_BY_FIELDS, d as NONE_VALUE, f as SELECTABLE_DATA_TYPES, g as TIME_UNITS, h as STRING_AGGREGATION_FNS, i as convertDataTypeToSelectable, j as ChartColumn, k as escapeFieldName, l as COMBINED_TIME_UNITS, m as SORT_TYPES, n as createSpecWithoutData, o as BIN_AGGREGATION, p as SINGLE_TIME_UNITS, r as isFieldSet, s as CHART_TYPES, t as augmentSpecWithData, u as ChartType, v as AGGREGATION_TYPE_ICON, w as DEFAULT_MAX_BINS_FACET, x as COUNT_FIELD, y as CHART_TYPE_ICON } from "./spec-B96zNUEA.js";
|
|
29
|
-
import { $ as TableBody, $t as ChevronLeft, A as ComboboxItem, At as ChartErrorState, B as contextAwarePanelOpen, Bt as $fae977aafc393c5c$export$6b862160d295c8e, C as prettifyRowColumnCount, Ct as dateToLocalISODate, D as DatePicker, Dt as TabsContent, E as useInternalStateWithSync, Et as Tabs, F as CommandList, Ft as RenderTextWithLinks, G as slotsController, H as contextAwarePanelType, Ht as GripHorizontal, I as CommandSeparator, It as Kbd, Jt as Code, K as Toggle, Kt as Ellipsis, L as smartMatch, Lt as HtmlOutput, M as CommandEmpty, Mt as ChartLoadingState, N as CommandInput, Nt as LazyVegaEmbed, O as DateRangePicker, Ot as TabsList, P as CommandItem, Pt as useOverflowDetection, Q as Table, Qt as ChevronsDownUp, R as ContextAwarePanelItem, Rt as EmotionCacheProvider, S as downloadSizeLimitAtom, St as Maps, T as getColumnCountForDisplay, Tt as dateToLocalISOTime, U as isCellAwareAtom, Ut as Funnel, V as contextAwarePanelOwner, Vt as TextWrap, W as SlotNames, Wt as EyeOff, X as Fill, Xt as ChevronsRight, Yt as ChevronsUpDown, Z as Provider$1, Zt as ChevronsLeft, _ as downloadBlob, _t as SELECT_COLUMN_ID, at as generateColumns, b as Progress, bt as getMimeValues, c as Slide, ct as ColumnChartContext, d as JsonOutput, dt as useIntersectionObserver, en as ArrowDownWideNarrow, et as TableCell, f as OutputArea, ft as usePrevious$1, g as ADD_PRINTING_CLASS, gt as INDEX_COLUMN_NAME, h as InstallPackageButton, ht as loadTableData, it as NAMELESS_COLUMN_PREFIX, j as Command, jt as ChartInfoState, k as Combobox, kt as TabsTrigger, l as RadioGroup, lt as ColumnChartSpecModel, m as DataTable, mt as loadTableAndRawData, n as marimoVersionAtom, nt as TableHeader, o as SLIDE_TYPE_OPTIONS_BY_VALUE, ot as inferFieldTypes, p as OutputRenderer, pt as getPageIndexForRow, qt as Download, r as showCodeInRunModeAtom, rt as TableRow, st as renderCellValue, t as useNotebookCodeAvailable, tt as TableHead, u as RadioGroupItem, ut as DelayMount, v as downloadByURL, vt as TOO_MANY_ROWS, w as prettifyRowCount, wt as dateToLocalISODateTime, x as Filenames, xt as isNullishFilter, y as downloadHTMLAsImage, yt as toFieldTypes, z as PANEL_TYPES, zt as $fae977aafc393c5c$export$588937bcd60ade55, __tla as __tla_2 } from "./code-visibility-
|
|
29
|
+
import { $ as TableBody, $t as ChevronLeft, A as ComboboxItem, At as ChartErrorState, B as contextAwarePanelOpen, Bt as $fae977aafc393c5c$export$6b862160d295c8e, C as prettifyRowColumnCount, Ct as dateToLocalISODate, D as DatePicker, Dt as TabsContent, E as useInternalStateWithSync, Et as Tabs, F as CommandList, Ft as RenderTextWithLinks, G as slotsController, H as contextAwarePanelType, Ht as GripHorizontal, I as CommandSeparator, It as Kbd, Jt as Code, K as Toggle, Kt as Ellipsis, L as smartMatch, Lt as HtmlOutput, M as CommandEmpty, Mt as ChartLoadingState, N as CommandInput, Nt as LazyVegaEmbed, O as DateRangePicker, Ot as TabsList, P as CommandItem, Pt as useOverflowDetection, Q as Table, Qt as ChevronsDownUp, R as ContextAwarePanelItem, Rt as EmotionCacheProvider, S as downloadSizeLimitAtom, St as Maps, T as getColumnCountForDisplay, Tt as dateToLocalISOTime, U as isCellAwareAtom, Ut as Funnel, V as contextAwarePanelOwner, Vt as TextWrap, W as SlotNames, Wt as EyeOff, X as Fill, Xt as ChevronsRight, Yt as ChevronsUpDown, Z as Provider$1, Zt as ChevronsLeft, _ as downloadBlob, _t as SELECT_COLUMN_ID, at as generateColumns, b as Progress, bt as getMimeValues, c as Slide, ct as ColumnChartContext, d as JsonOutput, dt as useIntersectionObserver, en as ArrowDownWideNarrow, et as TableCell, f as OutputArea, ft as usePrevious$1, g as ADD_PRINTING_CLASS, gt as INDEX_COLUMN_NAME, h as InstallPackageButton, ht as loadTableData, it as NAMELESS_COLUMN_PREFIX, j as Command, jt as ChartInfoState, k as Combobox, kt as TabsTrigger, l as RadioGroup, lt as ColumnChartSpecModel, m as DataTable, mt as loadTableAndRawData, n as marimoVersionAtom, nt as TableHeader, o as SLIDE_TYPE_OPTIONS_BY_VALUE, ot as inferFieldTypes, p as OutputRenderer, pt as getPageIndexForRow, qt as Download, r as showCodeInRunModeAtom, rt as TableRow, st as renderCellValue, t as useNotebookCodeAvailable, tt as TableHead, u as RadioGroupItem, ut as DelayMount, v as downloadByURL, vt as TOO_MANY_ROWS, w as prettifyRowCount, wt as dateToLocalISODateTime, x as Filenames, xt as isNullishFilter, y as downloadHTMLAsImage, yt as toFieldTypes, z as PANEL_TYPES, zt as $fae977aafc393c5c$export$588937bcd60ade55, __tla as __tla_2 } from "./code-visibility-B88v1No3.js";
|
|
30
30
|
import { c as Calendar, i as createReducerAndAtoms, n as useOnUnmount, o as ToggleLeft, t as useOnMount } from "./useLifecycle-BBO9PIph.js";
|
|
31
31
|
import { t as Check } from "./check-DTbrK0zt.js";
|
|
32
32
|
import { A as Trigger$1, C as $a916eb452884faea$export$b7a616150fdb9f44, E as $18f2051aff69b9bf$export$a54013f0d02a8f82, F as X, L as ChevronDown, M as usePrevious$2, N as useDirection, P as createCollection, S as logNever, T as $18f2051aff69b9bf$export$43bb16f9c6d9e3f7, a as SelectGroup, c as SelectSeparator, d as NativeSelect, i as SelectContent, j as clamp$2, k as Icon, l as SelectTrigger, n as capitalize, o as SelectItem, r as Select, s as SelectLabel, t as Strings, u as SelectValue, x as assertNever } from "./strings-Bu3vlb6W.js";
|
|
33
33
|
import { I as $64fa3d84918910a7$export$29f1550f4b0d4415, K as useDebounceControlledState, L as $64fa3d84918910a7$export$4d86445c2cf5e3, Mt as $65484d02dcb7eb3e$export$457c3d6518dd4c6f, Nt as $3ef42575df84b30b$export$9d1611c77c2fe928, V as $64fa3d84918910a7$export$df3a06d6289f983e, Vt as $ff5963eb1fccf552$export$e08e3b67e392101e, a as NumberField, b as DropdownMenuTrigger, c as prettyNumber, d as DropdownMenuContent, f as DropdownMenuGroup, fn as Circle, g as DropdownMenuSeparator, i as OnBlurredInput, it as $701a24aa0da5b062$export$ea18c227d4417cc3, l as prettyScientificNumber, m as DropdownMenuLabel, n as DebouncedNumberInput, p as DropdownMenuItem, pn as ChevronRight, q as useDebouncedCallback, r as Input, rt as $f7dceffc5ad7768b$export$4e328f61c538687f, t as DebouncedInput, u as DropdownMenu, ut as $6179b936705e76d3$export$ae780daf29e6d456, vt as $458b0a5536c1a7cf$export$40bfa8c7b0832715 } from "./input-_2sjvfne.js";
|
|
34
34
|
import { _ as isWasm, c as asRemoteURL, d as isStaticNotebook, f as appendQueryParams, g as Deferred, m as require_cuid2, u as getStaticVirtualFiles, v as CircleQuestionMark } from "./toDate-x-WRDCH7.js";
|
|
35
|
-
import { a as MarimoIncomingMessageEvent, c as MarimoValueUpdateEvent, d as Square, f as File, i as PythonIcon, l as createInputEvent, n as blobToString, o as MarimoValueInputEvent, r as filesToBase64, s as MarimoValueReadyEvent, t as processOutput, u as deserializeBlob } from "./process-output-
|
|
35
|
+
import { a as MarimoIncomingMessageEvent, c as MarimoValueUpdateEvent, d as Square, f as File, i as PythonIcon, l as createInputEvent, n as blobToString, o as MarimoValueInputEvent, r as filesToBase64, s as MarimoValueReadyEvent, t as processOutput, u as deserializeBlob } from "./process-output-CaUUWhh8.js";
|
|
36
36
|
import { n as Trash, r as Pencil, t as BulkEdit } from "./types-CVvp1fKr.js";
|
|
37
37
|
import { n as require_prop_types, r as Plus, t as ErrorBoundary } from "./ErrorBoundary-rULOrC_p.js";
|
|
38
38
|
import { t as require_react_dom } from "./react-dom-BTJzcVJ9.js";
|
|
@@ -5590,7 +5590,7 @@ let __tla = Promise.all([
|
|
|
5590
5590
|
};
|
|
5591
5591
|
}
|
|
5592
5592
|
};
|
|
5593
|
-
var LazyChatbot = import_react.lazy(() => import("./chat-ui-
|
|
5593
|
+
var LazyChatbot = import_react.lazy(() => import("./chat-ui-ar37brtL.js").then((e) => ({
|
|
5594
5594
|
default: e.Chatbot
|
|
5595
5595
|
}))), messageSchema = array(object({
|
|
5596
5596
|
id: string(),
|
|
@@ -36116,7 +36116,7 @@ ${c}
|
|
|
36116
36116
|
if (l && l !== "slide") return l;
|
|
36117
36117
|
if (c == null ? void 0 : c.has(e)) return "skip";
|
|
36118
36118
|
}
|
|
36119
|
-
var LazySlidesComponent = import_react.lazy(() => import("./reveal-component-
|
|
36119
|
+
var LazySlidesComponent = import_react.lazy(() => import("./reveal-component-CfFoUPFg.js"));
|
|
36120
36120
|
const SlidesLayoutRenderer = ({ layout: e, setLayout: r, cells: c, mode: l }) => {
|
|
36121
36121
|
var _a3;
|
|
36122
36122
|
let u = useAtomValue(kioskModeAtom), d = l === "read" || u, f = useAtomValue(numColumnsAtom) > 1, [p, m] = (0, import_react.useState)(null), { slideCells: h, skippedIds: g, noOutputIds: _, slideTypes: v, startCellIndex: y } = (0, import_react.useMemo)(() => computeSlideCellsInfo(c, e), [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { s as __toESM } from "./chunk-BNovOVIE.js";
|
|
2
2
|
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
3
|
-
import { it as parseHtmlContent, rt as ansiToPlainText } from "./html-to-image-
|
|
3
|
+
import { it as parseHtmlContent, rt as ansiToPlainText } from "./html-to-image-Cp8O1OWB.js";
|
|
4
4
|
import { u as createLucideIcon } from "./dist-C1BYNeCR.js";
|
|
5
5
|
import { t as Strings } from "./strings-Bu3vlb6W.js";
|
|
6
6
|
import { t as require_jsx_runtime } from "./jsx-runtime-DebpN0FN.js";
|
|
@@ -6,10 +6,10 @@ import { s as __toESM } from "./chunk-BNovOVIE.js";
|
|
|
6
6
|
import { _ as Logger, g as cn, h as Events, l as useEventListener, t as Button } from "./button-C5K9fIPF.js";
|
|
7
7
|
import { t as require_react } from "./react-DA-nE2FX.js";
|
|
8
8
|
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
|
|
9
|
-
import { ct as kioskModeAtom } from "./html-to-image-
|
|
9
|
+
import { ct as kioskModeAtom } from "./html-to-image-Cp8O1OWB.js";
|
|
10
10
|
import "./chunk-5FQGJX7Z-BNjes6Yx.js";
|
|
11
11
|
import { u as createLucideIcon } from "./dist-C1BYNeCR.js";
|
|
12
|
-
import { Gt as Expand, J as PanelGroup, Jt as Code, Wt as EyeOff, Y as PanelResizeHandle, a as DEFAULT_SLIDE_TYPE, c as Slide, i as DEFAULT_DECK_TRANSITION, q as Panel, s as SlideSidebar, t as useNotebookCodeAvailable } from "./code-visibility-
|
|
12
|
+
import { Gt as Expand, J as PanelGroup, Jt as Code, Wt as EyeOff, Y as PanelResizeHandle, a as DEFAULT_SLIDE_TYPE, c as Slide, i as DEFAULT_DECK_TRANSITION, q as Panel, s as SlideSidebar, t as useNotebookCodeAvailable } from "./code-visibility-B88v1No3.js";
|
|
13
13
|
import { q as useDebouncedCallback } from "./input-_2sjvfne.js";
|
|
14
14
|
import "./toDate-x-WRDCH7.js";
|
|
15
15
|
import "./react-dom-BTJzcVJ9.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
|
|