@marimo-team/islands 0.25.3-dev479 → 0.25.3-dev480
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/{ErrorBoundary-CLARdSzQ.js → ErrorBoundary-BnOxQSCn.js} +1 -1
- package/dist/{code-visibility-CStA-vv8.js → code-visibility-BO3A1_H1.js} +1 -1
- package/dist/{common-Bb7h6oRY.js → common-Dtqhi8XU.js} +1 -1
- package/dist/{data-grid-overlay-editor-Bw1x8hD7.js → data-grid-overlay-editor-w3KsxMmx.js} +1 -1
- package/dist/{feedback-button-kCWPaljb.js → feedback-button-j_zQSzAX.js} +2 -2
- package/dist/{glide-data-editor-CVFpoLXX.js → glide-data-editor-CT7Njdo9.js} +3 -3
- package/dist/{globals-3MEUeM07.js → globals-Dz81RTXf.js} +1 -1
- package/dist/main.js +4129 -4129
- package/dist/{number-overlay-editor-D3is5twx.js → number-overlay-editor-CjGPCtN3.js} +1 -1
- package/dist/{reveal-component-DgaqXs6t.js → reveal-component-DbZM06U2.js} +2 -2
- package/package.json +1 -1
- package/src/core/notebook/document/__tests__/draft.test.ts +34 -35
- package/src/core/notebook/document/__tests__/recovery-scenarios.test.ts +29 -0
- package/src/core/notebook/document/__tests__/state.test.ts +5 -7
- package/src/core/notebook/document/__tests__/submission.test.ts +3 -3
- package/src/core/notebook/document/__tests__/test-host.test.ts +2 -2
- package/src/core/notebook/document/__tests__/test-host.ts +4 -24
- package/src/core/notebook/document/__tests__/test-notebook.ts +2 -2
- package/src/core/notebook/document/__tests__/user.ts +3 -2
- package/src/core/notebook/document/draft.ts +17 -24
- package/src/core/notebook/document/state.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
|
|
2
2
|
import { t } from "./react-Bgs_wQh3.js";
|
|
3
|
-
import { a as n } from "./glide-data-editor-
|
|
3
|
+
import { a as n } from "./glide-data-editor-CT7Njdo9.js";
|
|
4
4
|
//#region ../node_modules/.pnpm/@glideapps+glide-data-grid@6.0.4-alpha24_lodash@4.17.21_marked@15.0.12_react-dom@19.3.1_57c124ac5a994dbbf13fd11838cf9ba9/node_modules/@glideapps/glide-data-grid/dist/esm/internal/data-grid-overlay-editor/private/number-overlay-editor-style.js
|
|
5
5
|
var r = /* @__PURE__ */ e(t()), i = /*#__PURE__*/ n("div")({
|
|
6
6
|
name: "NumberOverlayEditorStyle",
|
|
@@ -3,14 +3,14 @@ import { g as t, h as n, i as r, m as i, t as a } from "./button-qQhINE7z.js";
|
|
|
3
3
|
import { t as o } from "./react-Bgs_wQh3.js";
|
|
4
4
|
import { t as s } from "./compiler-runtime-C5KHtL5D.js";
|
|
5
5
|
import { h as c, t as l } from "./tooltip-CiJ919pg.js";
|
|
6
|
-
import { Cn as u, En as d, Sn as f, dn as p, et as m, f as h, i as g, l as _, n as v, nt as y, r as b, t as x, tt as S, u as C } from "./common-
|
|
6
|
+
import { Cn as u, En as d, Sn as f, dn as p, et as m, f as h, i as g, l as _, n as v, nt as y, r as b, t as x, tt as S, u as C } from "./common-Dtqhi8XU.js";
|
|
7
7
|
import { M as w } from "./select-PQHWLm64.js";
|
|
8
8
|
import { X as T } from "./dropdown-menu-B12Nf3Zf.js";
|
|
9
9
|
import { t as E } from "./jsx-runtime-D8btoEHk.js";
|
|
10
10
|
import { Rt as D, Vt as O, f as k, i as ee } from "./use-restore-focus-BLj45Ibw.js";
|
|
11
11
|
import { t as A } from "./useEvent-BoN7U38T.js";
|
|
12
12
|
import { o as te } from "./static-state-CWXd6dYX.js";
|
|
13
|
-
import { n as ne, t as re } from "./code-visibility-
|
|
13
|
+
import { n as ne, t as re } from "./code-visibility-BO3A1_H1.js";
|
|
14
14
|
/* empty css */
|
|
15
15
|
var j = c("sticky-note", [["path", {
|
|
16
16
|
d: "M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z",
|
package/package.json
CHANGED
|
@@ -105,7 +105,7 @@ describe("createCell and deleteCell", () => {
|
|
|
105
105
|
const deleted = deleteCell(EMPTY_DRAFT, "c1");
|
|
106
106
|
const back = { id: "c1", code: "back" };
|
|
107
107
|
const put = {
|
|
108
|
-
kind: "
|
|
108
|
+
kind: "replace_cell",
|
|
109
109
|
base_etag: "c1-etag",
|
|
110
110
|
cell: { ...back, name: "_", config: CONFIG },
|
|
111
111
|
};
|
|
@@ -133,10 +133,13 @@ describe("createCell and deleteCell", () => {
|
|
|
133
133
|
expect(viewDocument(removed, settled).order).toEqual(["c1", "c2"]);
|
|
134
134
|
expect(toChanges(removed, settled)).toEqual([
|
|
135
135
|
{
|
|
136
|
-
kind: "
|
|
137
|
-
base_etag: null,
|
|
136
|
+
kind: "create_cell",
|
|
138
137
|
cell: { ...back, name: "_", config: CONFIG },
|
|
139
|
-
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
kind: "set_order",
|
|
141
|
+
base_etag: removed.revision.order_etag,
|
|
142
|
+
order: ["c1", "c2"],
|
|
140
143
|
},
|
|
141
144
|
]);
|
|
142
145
|
});
|
|
@@ -215,7 +218,7 @@ describe("toChanges", () => {
|
|
|
215
218
|
});
|
|
216
219
|
expect(toChanges(hidden, draft)).toEqual([
|
|
217
220
|
{
|
|
218
|
-
kind: "
|
|
221
|
+
kind: "replace_cell",
|
|
219
222
|
base_etag: "c1-etag",
|
|
220
223
|
cell: { id: "c1", code, name: "renamed", config: CONFIG },
|
|
221
224
|
},
|
|
@@ -236,58 +239,56 @@ describe("toChanges", () => {
|
|
|
236
239
|
]);
|
|
237
240
|
});
|
|
238
241
|
|
|
239
|
-
it("is empty for an empty draft and omits
|
|
242
|
+
it("is empty for an empty draft and omits unchanged cells", () => {
|
|
240
243
|
expect(toChanges(confirmed, EMPTY_DRAFT)).toEqual([]);
|
|
241
244
|
expect(
|
|
242
245
|
toChanges(confirmed, edits({ code: "local" }, { code: "x = 1" })),
|
|
243
246
|
).toEqual([]);
|
|
244
247
|
});
|
|
245
248
|
|
|
246
|
-
it("
|
|
249
|
+
it("replaces the merged cell using the confirmed etag", () => {
|
|
247
250
|
const draft = edits({ code: "local" });
|
|
248
251
|
const remote = withCells(confirmed, {
|
|
249
252
|
c1: cell("c1", "remote", { name: "renamed", etag: "c1-etag-2" }),
|
|
250
253
|
});
|
|
251
254
|
expect(toChanges(remote, draft)).toEqual([
|
|
252
255
|
{
|
|
253
|
-
kind: "
|
|
256
|
+
kind: "replace_cell",
|
|
254
257
|
base_etag: "c1-etag-2",
|
|
255
258
|
cell: { id: "c1", code: "local", name: "renamed", config: CONFIG },
|
|
256
259
|
},
|
|
257
260
|
]);
|
|
258
261
|
});
|
|
259
262
|
|
|
260
|
-
it
|
|
261
|
-
|
|
262
|
-
(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
{
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
);
|
|
263
|
+
it("places a cell before another creation with one order change", () => {
|
|
264
|
+
let draft = createCell(EMPTY_DRAFT, { id: "c3", code: "3" });
|
|
265
|
+
draft = createCell(draft, { id: "c4", code: "4" }, { before: "c3" });
|
|
266
|
+
expect(toChanges(confirmed, draft)).toEqual([
|
|
267
|
+
{
|
|
268
|
+
kind: "create_cell",
|
|
269
|
+
cell: { id: "c3", code: "3", name: "_", config: CONFIG },
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
kind: "create_cell",
|
|
273
|
+
cell: { id: "c4", code: "4", name: "_", config: CONFIG },
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
kind: "set_order",
|
|
277
|
+
base_etag: "order-1",
|
|
278
|
+
order: ["c1", "c2", "c4", "c3"],
|
|
279
|
+
},
|
|
280
|
+
]);
|
|
281
|
+
});
|
|
280
282
|
|
|
281
283
|
it.each([{ after: "c2" }, { before: "c2" }])(
|
|
282
|
-
"
|
|
284
|
+
"appends when the placement anchor was deleted earlier in the request: %o",
|
|
283
285
|
(placement) => {
|
|
284
286
|
let draft = deleteCell(EMPTY_DRAFT, "c2");
|
|
285
287
|
draft = createCell(draft, { id: "c3", code: "3" }, placement);
|
|
286
288
|
expect(toChanges(confirmed, draft)).toEqual([
|
|
287
289
|
{ kind: "delete_cell", id: "c2", base_etag: "c2-etag" },
|
|
288
290
|
{
|
|
289
|
-
kind: "
|
|
290
|
-
base_etag: null,
|
|
291
|
+
kind: "create_cell",
|
|
291
292
|
cell: { id: "c3", code: "3", name: "_", config: CONFIG },
|
|
292
293
|
},
|
|
293
294
|
]);
|
|
@@ -300,10 +301,8 @@ describe("toChanges", () => {
|
|
|
300
301
|
draft = deleteCell(draft, "c1");
|
|
301
302
|
expect(toChanges(confirmed, draft)).toEqual([
|
|
302
303
|
{
|
|
303
|
-
kind: "
|
|
304
|
-
base_etag: null,
|
|
304
|
+
kind: "create_cell",
|
|
305
305
|
cell: { id: "c3", code: "3", name: "_", config: CONFIG },
|
|
306
|
-
after: "c2",
|
|
307
306
|
},
|
|
308
307
|
{ kind: "delete_cell", id: "c1", base_etag: "c1-etag" },
|
|
309
308
|
{ kind: "set_order", base_etag: "order-1", order: ["c2", "c3"] },
|
|
@@ -340,7 +339,7 @@ describe("acknowledge", () => {
|
|
|
340
339
|
const remote = withCells(confirmed, { c3: cell("c3", "remote code") });
|
|
341
340
|
expect(toChanges(remote, acknowledge(later, sent))).toEqual([
|
|
342
341
|
{
|
|
343
|
-
kind: "
|
|
342
|
+
kind: "replace_cell",
|
|
344
343
|
base_etag: "c3-etag",
|
|
345
344
|
cell: { id: "c3", code: "remote code", name: "named", config: CONFIG },
|
|
346
345
|
},
|
|
@@ -3,6 +3,35 @@
|
|
|
3
3
|
import { vi } from "vitest";
|
|
4
4
|
import { test } from "./scenario-fixture";
|
|
5
5
|
|
|
6
|
+
test("keeps a split of the last cell together across a concurrent append", async ({
|
|
7
|
+
expect,
|
|
8
|
+
session: { user, host },
|
|
9
|
+
}) => {
|
|
10
|
+
user.changeCode("k7f2", "y = x");
|
|
11
|
+
user.createCell({ id: "split", code: "y *= 2" }, { after: "k7f2" });
|
|
12
|
+
const synced = user.sync();
|
|
13
|
+
const request = await host.nextRequest();
|
|
14
|
+
|
|
15
|
+
host.createCell({ id: "remote", code: "z = 0" });
|
|
16
|
+
const remote = host.document();
|
|
17
|
+
request.process();
|
|
18
|
+
expect(host.document()).toEqual(remote);
|
|
19
|
+
host.deliverDocument();
|
|
20
|
+
request.deliverResponse();
|
|
21
|
+
await expect(synced).rejects.toThrow("conflict");
|
|
22
|
+
|
|
23
|
+
const retried = user.retry();
|
|
24
|
+
const retry = await host.nextRequest();
|
|
25
|
+
retry.process();
|
|
26
|
+
retry.deliverResponse();
|
|
27
|
+
host.deliverDocument();
|
|
28
|
+
const { cells, revision } = host.document();
|
|
29
|
+
await expect(retried).resolves.toEqual(revision);
|
|
30
|
+
expect(revision.order).toEqual(["c1", "c3", "k7f2", "split", "remote"]);
|
|
31
|
+
expect(cells.get("k7f2")?.code).toBe("y = x");
|
|
32
|
+
expect(cells.get("split")?.code).toBe("y *= 2");
|
|
33
|
+
});
|
|
34
|
+
|
|
6
35
|
test.for(["response", "document"] as const)(
|
|
7
36
|
"keeps a conflicting batch intact and retries explicitly with %s first",
|
|
8
37
|
async (first, { expect, session: { user, host, notebook } }) => {
|
|
@@ -72,7 +72,7 @@ describe("document model", () => {
|
|
|
72
72
|
);
|
|
73
73
|
expect(store.get(changesAtom)).toEqual([
|
|
74
74
|
{
|
|
75
|
-
kind: "
|
|
75
|
+
kind: "replace_cell",
|
|
76
76
|
base_etag: "latest",
|
|
77
77
|
cell: {
|
|
78
78
|
id: "c1",
|
|
@@ -112,8 +112,7 @@ describe("document model", () => {
|
|
|
112
112
|
expect(store.get(orderAtom)).toEqual(["c2", "c3"]);
|
|
113
113
|
expect(store.get(changesAtom)).toEqual([
|
|
114
114
|
{
|
|
115
|
-
kind: "
|
|
116
|
-
base_etag: null,
|
|
115
|
+
kind: "create_cell",
|
|
117
116
|
cell: {
|
|
118
117
|
id: "c3",
|
|
119
118
|
code: "",
|
|
@@ -133,7 +132,7 @@ describe("document model", () => {
|
|
|
133
132
|
expect(store.get(orderAtom)).toEqual(["c2", "c1"]);
|
|
134
133
|
expect(store.get(changesAtom)).toEqual([
|
|
135
134
|
{
|
|
136
|
-
kind: "
|
|
135
|
+
kind: "replace_cell",
|
|
137
136
|
base_etag: "c1-etag",
|
|
138
137
|
cell: {
|
|
139
138
|
id: "c1",
|
|
@@ -157,8 +156,7 @@ describe("document model", () => {
|
|
|
157
156
|
expect(store.get(changesAtom)).toEqual([
|
|
158
157
|
{ kind: "delete_cell", id: "c1", base_etag: "c1-etag" },
|
|
159
158
|
{
|
|
160
|
-
kind: "
|
|
161
|
-
base_etag: null,
|
|
159
|
+
kind: "create_cell",
|
|
162
160
|
cell: { id: "c3", code: "", name: "_", config: cell("c3", "").config },
|
|
163
161
|
},
|
|
164
162
|
{ kind: "set_order", base_etag: "order-1", order: ["c3", "c2"] },
|
|
@@ -204,7 +202,7 @@ describe("document model", () => {
|
|
|
204
202
|
expect(store.get(cellAtom("c2"))?.code).toBe("keep this draft");
|
|
205
203
|
expect(store.get(changesAtom)).toEqual([
|
|
206
204
|
{
|
|
207
|
-
kind: "
|
|
205
|
+
kind: "replace_cell",
|
|
208
206
|
base_etag: "c2-etag",
|
|
209
207
|
cell: {
|
|
210
208
|
id: "c2",
|
|
@@ -75,7 +75,7 @@ describe("document submissions", () => {
|
|
|
75
75
|
const sent = submit();
|
|
76
76
|
expect(sent.changes).toEqual([
|
|
77
77
|
{
|
|
78
|
-
kind: "
|
|
78
|
+
kind: "replace_cell",
|
|
79
79
|
base_etag: "c2-etag",
|
|
80
80
|
cell: {
|
|
81
81
|
id: "c2",
|
|
@@ -85,7 +85,7 @@ describe("document submissions", () => {
|
|
|
85
85
|
},
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
|
-
kind: "
|
|
88
|
+
kind: "replace_cell",
|
|
89
89
|
base_etag: "c1-etag",
|
|
90
90
|
cell: {
|
|
91
91
|
id: "c1",
|
|
@@ -188,7 +188,7 @@ describe("document submissions", () => {
|
|
|
188
188
|
const retry = submit();
|
|
189
189
|
expect(retry.changes).toEqual([
|
|
190
190
|
{
|
|
191
|
-
kind: "
|
|
191
|
+
kind: "replace_cell",
|
|
192
192
|
base_etag: "fresh",
|
|
193
193
|
cell: {
|
|
194
194
|
id: "c1",
|
|
@@ -44,7 +44,7 @@ it("rejects an entire batch when a later precondition is stale", () => {
|
|
|
44
44
|
const initial = initialDocument();
|
|
45
45
|
const host = createTestHost(initial);
|
|
46
46
|
const result = host.apply([
|
|
47
|
-
{ kind: "
|
|
47
|
+
{ kind: "create_cell", cell: { id: "created", code: "new" } },
|
|
48
48
|
{ kind: "delete_cell", id: "c3", base_etag: "stale" },
|
|
49
49
|
]);
|
|
50
50
|
expect(result).toMatchObject({
|
|
@@ -72,7 +72,7 @@ it("keeps successful and rejected receipts tied to their original payload and re
|
|
|
72
72
|
};
|
|
73
73
|
const rejected = host.process(stale);
|
|
74
74
|
host.apply([
|
|
75
|
-
{ kind: "
|
|
75
|
+
{ kind: "replace_cell", base_etag: "*", cell: { id: "c3", code: "later" } },
|
|
76
76
|
]);
|
|
77
77
|
const latest = host.document();
|
|
78
78
|
expect(host.process(request)).toEqual({ result: accepted.result });
|
|
@@ -88,34 +88,14 @@ export function createTestHost(initial: Document) {
|
|
|
88
88
|
|
|
89
89
|
for (const [index, change] of changes.entries()) {
|
|
90
90
|
switch (change.kind) {
|
|
91
|
-
case "
|
|
91
|
+
case "create_cell":
|
|
92
|
+
case "replace_cell": {
|
|
92
93
|
const { id } = change.cell;
|
|
93
|
-
if (change.
|
|
94
|
+
if (change.kind === "create_cell") {
|
|
94
95
|
if (current.cells.has(id) || cells.has(id)) {
|
|
95
96
|
return conflict(index, id);
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
return rejected({
|
|
99
|
-
type: "urn:marimo:problem:invalid-request",
|
|
100
|
-
title: "Invalid request",
|
|
101
|
-
status: 400,
|
|
102
|
-
detail: "A cell cannot name both before and after",
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
const anchor = change.after ?? change.before;
|
|
106
|
-
if (anchor !== undefined && !order.includes(anchor)) {
|
|
107
|
-
return rejected({
|
|
108
|
-
type: "urn:marimo:problem:invalid-request",
|
|
109
|
-
title: "Invalid request",
|
|
110
|
-
status: 400,
|
|
111
|
-
detail: "The placement anchor does not exist",
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
const position =
|
|
115
|
-
anchor === undefined
|
|
116
|
-
? order.length
|
|
117
|
-
: order.indexOf(anchor) + (change.after === undefined ? 0 : 1);
|
|
118
|
-
order.splice(position, 0, id);
|
|
98
|
+
order.push(id);
|
|
119
99
|
} else if (!cells.has(id) || !matches(id, change.base_etag)) {
|
|
120
100
|
return conflict(index, id);
|
|
121
101
|
}
|
|
@@ -116,7 +116,7 @@ export function createTestNotebook(
|
|
|
116
116
|
);
|
|
117
117
|
apply([
|
|
118
118
|
{
|
|
119
|
-
kind: "
|
|
119
|
+
kind: "replace_cell",
|
|
120
120
|
base_etag: cell.etag,
|
|
121
121
|
cell: {
|
|
122
122
|
id,
|
|
@@ -129,7 +129,7 @@ export function createTestNotebook(
|
|
|
129
129
|
]);
|
|
130
130
|
},
|
|
131
131
|
createCell(cell: Protocol.CellInput) {
|
|
132
|
-
apply([{ kind: "
|
|
132
|
+
apply([{ kind: "create_cell", cell }]);
|
|
133
133
|
},
|
|
134
134
|
deleteCell(id: Protocol.CellId) {
|
|
135
135
|
const cell = host.document().cells.get(id);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type * as Protocol from "@marimo-team/client/protocol";
|
|
4
4
|
import type { createStore } from "jotai/vanilla";
|
|
5
|
+
import type { Placement } from "../draft";
|
|
5
6
|
import type { DocumentModel } from "../model";
|
|
6
7
|
|
|
7
8
|
/** Translate user actions and observations without keeping any expected state. */
|
|
@@ -36,8 +37,8 @@ export function createUser(
|
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
},
|
|
39
|
-
createCell(cell: Protocol.CellInput) {
|
|
40
|
-
store.set(model.editAtom, (tx) => tx.createCell(cell));
|
|
40
|
+
createCell(cell: Protocol.CellInput, placement?: Placement) {
|
|
41
|
+
store.set(model.editAtom, (tx) => tx.createCell(cell, placement));
|
|
41
42
|
},
|
|
42
43
|
deleteCell(id: Protocol.CellId) {
|
|
43
44
|
store.set(model.editAtom, (tx) => tx.deleteCell(id));
|
|
@@ -47,8 +47,8 @@ type CellDraft =
|
|
|
47
47
|
* This client's changes, layered over a confirmed document.
|
|
48
48
|
*
|
|
49
49
|
* A draft is a document delta in the terms of the host's edit request:
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* cell creations, replacements, deletions, and optionally the full order.
|
|
51
|
+
* The editable view and the request that synchronizes it both derive from it.
|
|
52
52
|
*/
|
|
53
53
|
export interface Draft {
|
|
54
54
|
readonly cells: ReadonlyMap<Protocol.CellId, CellDraft>;
|
|
@@ -436,39 +436,32 @@ export function viewDocument(
|
|
|
436
436
|
/**
|
|
437
437
|
* The edit request that would make the host match the view.
|
|
438
438
|
*
|
|
439
|
-
* Preconditions
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
* keeping the draft atomic and retaining local intent for recovery.
|
|
439
|
+
* Preconditions use the confirmed etags. Unchanged cells are omitted.
|
|
440
|
+
* Creates append before a final order change places them. A missing cell or
|
|
441
|
+
* missing source blocks replacement, keeping the draft atomic for recovery.
|
|
443
442
|
*/
|
|
444
443
|
export function toChanges(
|
|
445
444
|
confirmed: Document,
|
|
446
445
|
draft: Draft,
|
|
447
446
|
): Protocol.Change[] | null {
|
|
448
447
|
const changes: Protocol.Change[] = [];
|
|
449
|
-
|
|
450
|
-
const
|
|
448
|
+
const stagedOrder = new Set(confirmed.revision.order);
|
|
449
|
+
const { cells, order } = viewDocument(confirmed, draft);
|
|
450
|
+
let hasAnchoredCreate = false;
|
|
451
451
|
for (const [id, local] of draft.cells) {
|
|
452
452
|
const base = confirmed.cells.get(id);
|
|
453
453
|
if (local.kind === "delete") {
|
|
454
454
|
if (base !== undefined) {
|
|
455
455
|
changes.push({ kind: "delete_cell", id, base_etag: base.etag });
|
|
456
|
-
stagedOrder
|
|
457
|
-
stagedIds.delete(id);
|
|
456
|
+
stagedOrder.delete(id);
|
|
458
457
|
}
|
|
459
458
|
} else if (local.kind === "create") {
|
|
459
|
+
changes.push({ kind: "create_cell", cell: local.cell });
|
|
460
|
+
stagedOrder.add(id);
|
|
460
461
|
const anchor = local.placement.after ?? local.placement.before;
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
kind: "put_cell",
|
|
465
|
-
base_etag: null,
|
|
466
|
-
cell: local.cell,
|
|
467
|
-
...placement,
|
|
468
|
-
});
|
|
469
|
-
if (base === undefined) {
|
|
470
|
-
stagedOrder = insertAt(stagedOrder, id, placement);
|
|
471
|
-
stagedIds.add(id);
|
|
462
|
+
if (anchor !== undefined && cells.has(anchor)) {
|
|
463
|
+
// A concurrent append can separate a new cell from its anchor.
|
|
464
|
+
hasAnchoredCreate = true;
|
|
472
465
|
}
|
|
473
466
|
} else if (base !== undefined) {
|
|
474
467
|
const cell = applyEdit(base, local.edit);
|
|
@@ -478,7 +471,7 @@ export function toChanges(
|
|
|
478
471
|
return null;
|
|
479
472
|
}
|
|
480
473
|
changes.push({
|
|
481
|
-
kind: "
|
|
474
|
+
kind: "replace_cell",
|
|
482
475
|
base_etag: base.etag,
|
|
483
476
|
cell: { ...cell, code },
|
|
484
477
|
});
|
|
@@ -487,10 +480,10 @@ export function toChanges(
|
|
|
487
480
|
return null;
|
|
488
481
|
}
|
|
489
482
|
}
|
|
490
|
-
const { order } = viewDocument(confirmed, draft);
|
|
491
483
|
if (
|
|
484
|
+
hasAnchoredCreate ||
|
|
492
485
|
(draft.order !== null && !sameOrder(order, confirmed.revision.order)) ||
|
|
493
|
-
!sameOrder(order, stagedOrder)
|
|
486
|
+
!sameOrder(order, [...stagedOrder])
|
|
494
487
|
) {
|
|
495
488
|
changes.push({
|
|
496
489
|
kind: "set_order",
|
|
@@ -75,7 +75,7 @@ interface ModelState {
|
|
|
75
75
|
export interface DocumentState {
|
|
76
76
|
/** Shown host state with local drafts applied, null while unavailable. */
|
|
77
77
|
readonly documentAtom: Atom<EditableDocument | null>;
|
|
78
|
-
/** Null when the document or source needed by
|
|
78
|
+
/** Null when the document or source needed by an edit is unavailable. */
|
|
79
79
|
readonly changesAtom: Atom<readonly Protocol.Change[] | null>;
|
|
80
80
|
/** Remains pending until both the response and its streamed revision arrive. */
|
|
81
81
|
readonly pendingAtom: Atom<DocumentSubmission | null>;
|