markloom 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/collab.md +25 -13
  2. package/dist/ai/index.cjs +5 -4
  3. package/dist/ai/index.d.cts +5 -5
  4. package/dist/ai/index.d.ts +5 -5
  5. package/dist/ai/index.js +4 -3
  6. package/dist/{chunk-KYZJIOOL.js → chunk-4Q7PAR2T.js} +3671 -904
  7. package/dist/chunk-75EJ4ARB.cjs +642 -0
  8. package/dist/{chunk-U3JZDFL4.cjs → chunk-BMPCVT3B.cjs} +2 -34
  9. package/dist/{chunk-VSBIMMI7.js → chunk-EFYT2223.js} +3 -35
  10. package/dist/chunk-HXABDVLZ.cjs +297 -0
  11. package/dist/{chunk-I5VK4U7J.cjs → chunk-I2LDEVLA.cjs} +434 -80
  12. package/dist/{chunk-YBAT343I.js → chunk-MQLRZQZL.js} +263 -119
  13. package/dist/chunk-OVHASRID.cjs +4279 -0
  14. package/dist/chunk-PCSVBPOR.cjs +40 -0
  15. package/dist/{chunk-TB2OY3D4.js → chunk-PSAXWBNM.js} +413 -59
  16. package/dist/{chunk-QEVME6ZU.cjs → chunk-PZRWTLLB.cjs} +260 -161
  17. package/dist/chunk-QO7JEZDB.js +4279 -0
  18. package/dist/{chunk-EJSFZHGT.js → chunk-WSJUXPAG.js} +18 -2
  19. package/dist/{chunk-ACFYBYZJ.cjs → chunk-Y4IXQFWL.cjs} +4212 -1445
  20. package/dist/{chunk-CGYCJORO.js → chunk-YLVSMDIO.js} +220 -121
  21. package/dist/chunk-ZL6WT6OY.js +297 -0
  22. package/dist/{client-CLYq17SW.d.ts → client-BvvyHjhh.d.ts} +57 -7
  23. package/dist/{client-DAth8pPq.d.cts → client-Ciy7Fa_k.d.cts} +57 -7
  24. package/dist/collab/index.cjs +5 -4
  25. package/dist/collab/index.d.cts +13 -15
  26. package/dist/collab/index.d.ts +13 -15
  27. package/dist/collab/index.js +4 -3
  28. package/dist/{controller-BIOO_XKJ.d.cts → controller-CHznEhAR.d.cts} +186 -27
  29. package/dist/{controller-6AJ36G52.d.ts → controller-DLqI8_jm.d.ts} +186 -27
  30. package/dist/index.cjs +69 -7
  31. package/dist/index.d.cts +127 -8
  32. package/dist/index.d.ts +127 -8
  33. package/dist/index.js +80 -18
  34. package/dist/io/index.cjs +58 -59
  35. package/dist/io/index.d.cts +1 -1
  36. package/dist/io/index.d.ts +1 -1
  37. package/dist/io/index.js +15 -16
  38. package/dist/react/index.cjs +9 -8
  39. package/dist/react/index.d.cts +5 -5
  40. package/dist/react/index.d.ts +5 -5
  41. package/dist/react/index.js +8 -7
  42. package/dist/{rebase-batch-DlerAcFN.d.ts → rebase-batch-CSnv8FKp.d.ts} +1 -1
  43. package/dist/{rebase-batch-PjENQ742.d.cts → rebase-batch-DO1ygkx9.d.cts} +1 -1
  44. package/dist/{types-COUweEav.d.cts → types-BkHlmUFL.d.cts} +5 -1
  45. package/dist/{types-COUweEav.d.ts → types-BkHlmUFL.d.ts} +5 -1
  46. package/dist/{versions-9mG1epfB.d.cts → versions-DNFf8zVz.d.cts} +1 -1
  47. package/dist/{versions-Bubyo4pt.d.ts → versions-DOkOyh2J.d.ts} +1 -1
  48. package/dist/view/index.cjs +215 -17
  49. package/dist/view/index.d.cts +82 -9
  50. package/dist/view/index.d.ts +82 -9
  51. package/dist/view/index.js +212 -14
  52. package/dist/view/theme.css +349 -75
  53. package/dist/{suggest-Bk4zLzuv.d.ts → word-count-BPw9G2Bg.d.ts} +15 -5
  54. package/dist/{suggest-BkGGiPKA.d.cts → word-count-DNLn1h_t.d.cts} +15 -5
  55. package/package.json +11 -6
  56. package/dist/chunk-EADZKEU4.cjs +0 -498
  57. package/dist/chunk-SNFF6X45.js +0 -2347
  58. package/dist/chunk-TWD5T4YC.cjs +0 -2347
  59. package/dist/chunk-ZKQSQSSM.cjs +0 -24
package/collab.md CHANGED
@@ -1,6 +1,6 @@
1
- # Collaboration
1
+ # Local-first collaboration
2
2
 
3
- Real-time multiplayer via **centralized OT** (markloom `rebase` / `makeBias`) and a **Cloudflare Worker** Durable Object room (same WebSocket pattern as the chat repo: `acceptWebSocket` + fan-out).
3
+ The local document is primary. WebSocket synchronization is optional transport: editing never waits for a connection, unacknowledged Steps stay in the local replica, and reconnect replays them through the server's persisted OT log.
4
4
 
5
5
  ## Client (copy-paste)
6
6
 
@@ -13,20 +13,28 @@ npm i markloom
13
13
  import { Editor } from 'markloom/view'
14
14
  import 'markloom/view/theme.css'
15
15
 
16
- new Editor(el, doc, {
16
+ const ed = new Editor(el, loaded?.doc ?? doc, {
17
17
  collab: {
18
18
  url: 'ws://127.0.0.1:8787', // or wss://your-worker.workers.dev
19
19
  room: 'demo-room',
20
20
  name: 'Alice',
21
+ replica: loaded?.replica,
22
+ // bootstrap: 'remote', // 仅“把已有远端房间导入新本地副本”时显式开启
23
+ onState: state => save(state), // one atomic record: { doc, replica }
21
24
  // token: 'secret', // when worker COLLAB_TOKEN is set
22
25
  // token: () => fetchToken(), // async ok
23
- // onStatus: s => …, // connecting | open | closed | resyncing | auth-error
26
+ // onStatus: s => …, // connecting | open | closed | resyncing | conflict | auth-error
24
27
  // onResync: v => …, // server forced snapshot
28
+ // onConflict: c => …, // c.remote is never applied implicitly
25
29
  },
26
30
  })
27
31
  ```
28
32
 
29
- That is enough: local edits upload as Steps; remote Steps apply through OT. No extension list.
33
+ Persist the value delivered by `onState` as one atomic record. It fires only after both the document and replica transition are complete, including local edits, remote ops, acknowledgements, reconnects, and resyncs. `replica` contains the stable client identity, confirmed server version, monotonic sequence, and every unacknowledged Step. A fresh document may omit it; a restored local document must pass it back.
34
+
35
+ Remote state is never the implicit authority. Joining an existing room without replica metadata enters `conflict`; set `bootstrap: 'remote'` only for the explicit “import this remote room as a new local replica” action. A newly created room is seeded from the local document without this flag.
36
+
37
+ Local edits always commit and enter `replica.pending`, including while connecting, disconnected, in an auth failure, or in a sync conflict. The client sends one pending batch at a time and removes it only after an explicit acknowledgement.
30
38
 
31
39
  **Presence (built-in, Feishu-style):** status dot + top-right avatar stack (self + peers) and colored remote carets with name labels. Colors auto-assign by `siteId` unless you set `color`. No extra config.
32
40
 
@@ -35,8 +43,11 @@ That is enough: local edits upload as Steps; remote Steps apply through OT. No e
35
43
  | Field | Role |
36
44
  |-------|------|
37
45
  | `token` / `() => token` | Join auth; worker rejects if `COLLAB_TOKEN` set and mismatch → `auth-error` (no reconnect storm) |
38
- | `onStatus` | `connecting` · `open` · `closed` · `resyncing` · `auth-error` |
39
- | `onResync` | Stale base / rebase fail → server snapshot; client clears pending |
46
+ | `replica` / `onState` | Restore and atomically persist `{ doc, replica }` |
47
+ | `bootstrap: 'remote'` | Explicit one-time import of an existing remote room into a new local replica |
48
+ | `onStatus` | `connecting` · `open` · `closed` · `resyncing` · `conflict` · `auth-error` |
49
+ | `onResync` | Snapshot applies only with no pending local changes; otherwise status becomes `conflict` |
50
+ | `onConflict` | Inspect the reason and complete remote snapshot; call `ed.collab.acceptRemote()` only for an explicit discard-local action |
40
51
  | heartbeat | Client ping 20s; no pong 45s → reconnect |
41
52
 
42
53
  Optional: `color`, `name`, `seed` (empty room init; default = constructor `doc`).
@@ -52,7 +63,7 @@ bun run dev # wrangler dev → ws://127.0.0.1:8787
52
63
  ```
53
64
 
54
65
  - `GET /room/:id` + WebSocket upgrade → one Durable Object per room name
55
- - Snapshot persisted in DO storage; op log in memory (stale base → `resync`)
66
+ - Snapshot, complete op log, and last acknowledged sequence per client are persisted in DO storage; joins and rebases range-read only the log suffix after their base version
56
67
 
57
68
  Deploy: `bun run deploy` (Cloudflare account + `wrangler login`).
58
69
 
@@ -60,8 +71,8 @@ Deploy: `bun run deploy` (Cloudflare account + `wrangler login`).
60
71
 
61
72
  | Direction | Types |
62
73
  |-----------|--------|
63
- | C→S | `join`, `op`, `presence`, `ping`, `version-save`, `version-remove` |
64
- | S→C | `welcome` (+`versions?`), `op`, `presence`, `peer-join` / `peer-leave`, `resync`, `error`, `versions` |
74
+ | C→S | `join` (`clientId`, confirmed `version`), `op` (`clientId`, `clientSeq`), `presence`, `ping`, `version-save`, `version-remove` |
75
+ | S→C | `welcome` (incremental `ops`, `ackedSeq`, `versions?`), `op`, `presence`, `peer-join` / `peer-leave`, `resync`, structured `error` (`code`, `message`), `versions` |
65
76
 
66
77
  Named versions are a **side channel** (not OT steps): save/remove broadcast the full room list; `welcome` seeds late joiners. Enable with `versions: true` on the Editor — collab auto-uploads on save.
67
78
 
@@ -73,7 +84,7 @@ Exactly **two** ways the doc changes under collab:
73
84
 
74
85
  | Path | API | Undo stack | Network |
75
86
  |------|-----|------------|---------|
76
- | **local** | `dispatch` / `dispatchStream` / `undo` / `redo` | `commit` / `amend` / pop | `push` |
87
+ | **local** | `dispatch` / `dispatchStream` / `undo` / `redo` | `commit` / `amend` / pop | append pending; send when online |
77
88
  | **foreign** | `applyRemote` → `applyForeign` | OT-map only, **never push** | inbound `op` |
78
89
 
79
90
  Decorations (slash, table, bubble, …) only call `host.dispatch` → local.
@@ -88,8 +99,9 @@ No third path mutates `history.doc`.
88
99
 
89
100
  ## Limits (honest)
90
101
 
91
- - **TP2** (reordered remote undo chains) not proven; server serializes commits so common concurrent typing is covered by TP1 + central order.
92
- Strategy: pathological OT → **resync to authority** (not silent corruption). Prefer resync over inventing unproven multi-way undo transforms.
102
+ - **TP2** (reordered remote undo chains) not proven; server serializes commits so common concurrent typing is covered by TP1 + central order.
103
+ - A rebase/apply failure with local pending becomes an explicit `conflict`. The local document and pending queue are retained; a snapshot never silently overwrites them.
104
+ - A conflict exposes its complete remote snapshot at `ed.collab.conflict`. `acceptRemote()` is the explicit destructive resolution; keeping local means closing this client and opening a new room, while manual merge starts from the two exposed documents.
93
105
  - Pathological OT corner cases may still `resync`; room id alone is weak capability — set `COLLAB_TOKEN` + client `token` for shared-secret auth.
94
106
  - Presence multi-caret chrome is built-in; further product UI is optional.
95
107
 
package/dist/ai/index.cjs CHANGED
@@ -6,9 +6,10 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkI5VK4U7Jcjs = require('../chunk-I5VK4U7J.cjs');
10
- require('../chunk-TWD5T4YC.cjs');
11
- require('../chunk-ZKQSQSSM.cjs');
9
+ var _chunkI2LDEVLAcjs = require('../chunk-I2LDEVLA.cjs');
10
+ require('../chunk-OVHASRID.cjs');
11
+ require('../chunk-HXABDVLZ.cjs');
12
+ require('../chunk-PCSVBPOR.cjs');
12
13
 
13
14
 
14
15
 
@@ -17,4 +18,4 @@ require('../chunk-ZKQSQSSM.cjs');
17
18
 
18
19
 
19
20
 
20
- exports.MarkloomAi = _chunkI5VK4U7Jcjs.MarkloomAi; exports.aiInstructionFromQuery = _chunkI5VK4U7Jcjs.aiInstructionFromQuery; exports.blockPlainText = _chunkI5VK4U7Jcjs.blockPlainText; exports.createAiStream = _chunkI5VK4U7Jcjs.createAiStream; exports.focusBlockId = _chunkI5VK4U7Jcjs.focusBlockId; exports.precedingPlainText = _chunkI5VK4U7Jcjs.precedingPlainText; exports.startAiWrite = _chunkI5VK4U7Jcjs.startAiWrite;
21
+ exports.MarkloomAi = _chunkI2LDEVLAcjs.MarkloomAi; exports.aiInstructionFromQuery = _chunkI2LDEVLAcjs.aiInstructionFromQuery; exports.blockPlainText = _chunkI2LDEVLAcjs.blockPlainText; exports.createAiStream = _chunkI2LDEVLAcjs.createAiStream; exports.focusBlockId = _chunkI2LDEVLAcjs.focusBlockId; exports.precedingPlainText = _chunkI2LDEVLAcjs.precedingPlainText; exports.startAiWrite = _chunkI2LDEVLAcjs.startAiWrite;
@@ -1,9 +1,9 @@
1
- export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-BIOO_XKJ.cjs';
2
- import { E as ElementNode } from '../types-COUweEav.cjs';
3
- import '../versions-9mG1epfB.cjs';
1
+ export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-CHznEhAR.cjs';
2
+ import { E as ElementNode } from '../types-BkHlmUFL.cjs';
3
+ import '../versions-DNFf8zVz.cjs';
4
4
  import 'preact';
5
- import '../suggest-BkGGiPKA.cjs';
6
- import '../client-DAth8pPq.cjs';
5
+ import '../word-count-DNLn1h_t.cjs';
6
+ import '../client-Ciy7Fa_k.cjs';
7
7
 
8
8
  /** 顶层块 [0, blockIdx) 纯文本拼接(作 /ai 上下文) */
9
9
  declare function precedingPlainText(doc: ElementNode, blockIdx: number): string;
@@ -1,9 +1,9 @@
1
- export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-6AJ36G52.js';
2
- import { E as ElementNode } from '../types-COUweEav.js';
3
- import '../versions-Bubyo4pt.js';
1
+ export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-DLqI8_jm.js';
2
+ import { E as ElementNode } from '../types-BkHlmUFL.js';
3
+ import '../versions-DOkOyh2J.js';
4
4
  import 'preact';
5
- import '../suggest-Bk4zLzuv.js';
6
- import '../client-CLYq17SW.js';
5
+ import '../word-count-BPw9G2Bg.js';
6
+ import '../client-BvvyHjhh.js';
7
7
 
8
8
  /** 顶层块 [0, blockIdx) 纯文本拼接(作 /ai 上下文) */
9
9
  declare function precedingPlainText(doc: ElementNode, blockIdx: number): string;
package/dist/ai/index.js CHANGED
@@ -6,9 +6,10 @@ import {
6
6
  focusBlockId,
7
7
  precedingPlainText,
8
8
  startAiWrite
9
- } from "../chunk-TB2OY3D4.js";
10
- import "../chunk-SNFF6X45.js";
11
- import "../chunk-EJSFZHGT.js";
9
+ } from "../chunk-PSAXWBNM.js";
10
+ import "../chunk-QO7JEZDB.js";
11
+ import "../chunk-ZL6WT6OY.js";
12
+ import "../chunk-WSJUXPAG.js";
12
13
  export {
13
14
  MarkloomAi,
14
15
  aiInstructionFromQuery,