markloom 0.5.1 → 0.6.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 (67) hide show
  1. package/PACKAGES.md +26 -0
  2. package/README.md +20 -2
  3. package/collab.md +42 -7
  4. package/dist/ai/index.cjs +4 -4
  5. package/dist/ai/index.d.cts +5 -4
  6. package/dist/ai/index.d.ts +5 -4
  7. package/dist/ai/index.js +3 -3
  8. package/dist/ai/theme.css +66 -102
  9. package/dist/{chunk-VXM7Q6P5.cjs → chunk-ACFYBYZJ.cjs} +2604 -966
  10. package/dist/chunk-CGYCJORO.js +759 -0
  11. package/dist/chunk-EADZKEU4.cjs +498 -0
  12. package/dist/chunk-EJSFZHGT.js +24 -0
  13. package/dist/{chunk-YIFOGP2D.cjs → chunk-I5VK4U7J.cjs} +103 -60
  14. package/dist/{chunk-ZMTLSFLO.js → chunk-KYZJIOOL.js} +2138 -500
  15. package/dist/chunk-QEVME6ZU.cjs +759 -0
  16. package/dist/{chunk-MFYF2A6U.js → chunk-SNFF6X45.js} +51 -1
  17. package/dist/{chunk-FCH7LZFI.js → chunk-TB2OY3D4.js} +50 -7
  18. package/dist/{chunk-4TMHVNL6.cjs → chunk-TWD5T4YC.cjs} +155 -105
  19. package/dist/{chunk-JS527FDV.cjs → chunk-U3JZDFL4.cjs} +49 -9
  20. package/dist/{chunk-RLTHVQNQ.js → chunk-VSBIMMI7.js} +45 -5
  21. package/dist/chunk-YBAT343I.js +498 -0
  22. package/dist/chunk-ZKQSQSSM.cjs +24 -0
  23. package/dist/{client-ZRZj2nkq.d.cts → client-CLYq17SW.d.ts} +63 -7
  24. package/dist/{client-6KiH4kGK.d.ts → client-DAth8pPq.d.cts} +63 -7
  25. package/dist/collab/index.cjs +16 -4
  26. package/dist/collab/index.d.cts +19 -6
  27. package/dist/collab/index.d.ts +19 -6
  28. package/dist/collab/index.js +18 -6
  29. package/dist/{controller-BNuuUM3E.d.ts → controller-6AJ36G52.d.ts} +99 -7
  30. package/dist/{controller-DQITsFhy.d.cts → controller-BIOO_XKJ.d.cts} +99 -7
  31. package/dist/index.cjs +57 -7
  32. package/dist/index.d.cts +18 -5
  33. package/dist/index.d.ts +18 -5
  34. package/dist/index.js +54 -4
  35. package/dist/io/index.cjs +1413 -0
  36. package/dist/io/index.d.cts +33 -0
  37. package/dist/io/index.d.ts +33 -0
  38. package/dist/io/index.js +1413 -0
  39. package/dist/react/index.cjs +8 -8
  40. package/dist/react/index.d.cts +5 -4
  41. package/dist/react/index.d.ts +5 -4
  42. package/dist/react/index.js +7 -7
  43. package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-DlerAcFN.d.ts} +11 -9
  44. package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-PjENQ742.d.cts} +11 -9
  45. package/dist/suggest-Bk4zLzuv.d.ts +120 -0
  46. package/dist/suggest-BkGGiPKA.d.cts +120 -0
  47. package/dist/types-COUweEav.d.cts +30 -0
  48. package/dist/types-COUweEav.d.ts +30 -0
  49. package/dist/versions-9mG1epfB.d.cts +51 -0
  50. package/dist/versions-Bubyo4pt.d.ts +51 -0
  51. package/dist/view/index.cjs +56 -12
  52. package/dist/view/index.d.cts +203 -11
  53. package/dist/view/index.d.ts +203 -11
  54. package/dist/view/index.js +52 -8
  55. package/dist/view/theme.css +1829 -1587
  56. package/io.md +38 -0
  57. package/package.json +21 -5
  58. package/dist/chunk-4JSJAHTB.js +0 -255
  59. package/dist/chunk-ALZ3A5CS.cjs +0 -255
  60. package/dist/chunk-GQ2HHRGI.cjs +0 -16
  61. package/dist/chunk-LA5SBCGQ.js +0 -16
  62. package/dist/chunk-LEYAQNJA.js +0 -220
  63. package/dist/chunk-YXQDCW4Y.cjs +0 -220
  64. package/dist/comments-DlExS6f-.d.cts +0 -43
  65. package/dist/comments-PhnR7Gkn.d.ts +0 -43
  66. package/dist/step-BrvHIK7O.d.cts +0 -65
  67. package/dist/step-BrvHIK7O.d.ts +0 -65
package/io.md ADDED
@@ -0,0 +1,38 @@
1
+ # DOCX I/O (`markloom/io`)
2
+
3
+ O(1): import the entrypoint. Not in the default editor bundle.
4
+
5
+ ```bash
6
+ npm i markloom
7
+ ```
8
+
9
+ ```ts
10
+ import { docToDocx, docToDocxBlob, docToDocxAsync, docxToDoc } from 'markloom/io'
11
+
12
+ // Export (sync: embeds data: images only)
13
+ const bytes = docToDocx(doc)
14
+ const blob = docToDocxBlob(doc) // browser download
15
+
16
+ // Export with remote images
17
+ const bytes2 = await docToDocxAsync(doc)
18
+ // or: await docToDocxAsync(doc, { resolveImage: async url => … })
19
+
20
+ // Import (store + deflate ZIP; Word-exported packages OK)
21
+ const doc2 = docxToDoc(await file.arrayBuffer())
22
+ ```
23
+
24
+ ## Coverage
25
+
26
+ | In/out | Supported |
27
+ |--------|-----------|
28
+ | Paragraphs, headings H1–H6 | yes |
29
+ | Bold / italic / strike / underline / code / highlight | yes |
30
+ | Lists, tables, code blocks | yes (list numbering simplified) |
31
+ | Images | export: `data:` sync, http(s) via async; import → `data:` image nodes |
32
+ | Callout / embed / mention | text fallbacks |
33
+
34
+ ## Notes
35
+
36
+ - Export ZIP uses **store** (uncompressed) for predictability; Word/Pages open it fine.
37
+ - Import inflates **deflate** entries via `fflate` (no Bun-only path).
38
+ - Node import uses `@xmldom/xmldom` when `DOMParser` is missing; browsers use native DOMParser.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "markloom",
3
- "version": "0.5.1",
4
- "description": "The loom for Markdown — rich text with MD isomorphism, reversible Steps, controlled editor, optional AI write + realtime collab",
3
+ "version": "0.6.0",
4
+ "description": "The loom for Markdown — rich text with MD isomorphism, reversible Steps, AI write, collab, search/versions/suggest, DOCX I/O",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -32,6 +32,11 @@
32
32
  "import": "./dist/collab/index.js",
33
33
  "require": "./dist/collab/index.cjs"
34
34
  },
35
+ "./io": {
36
+ "types": "./dist/io/index.d.ts",
37
+ "import": "./dist/io/index.js",
38
+ "require": "./dist/io/index.cjs"
39
+ },
35
40
  "./view/theme.css": "./dist/view/theme.css",
36
41
  "./ai/theme.css": "./dist/ai/theme.css"
37
42
  },
@@ -42,7 +47,9 @@
42
47
  "dist",
43
48
  "README.md",
44
49
  "ai.md",
45
- "collab.md"
50
+ "collab.md",
51
+ "io.md",
52
+ "PACKAGES.md"
46
53
  ],
47
54
  "scripts": {
48
55
  "typecheck": "tsc --noEmit",
@@ -50,7 +57,9 @@
50
57
  "dev": "vite --config lab/vite.config.ts",
51
58
  "lab": "vite --config lab/vite.config.ts",
52
59
  "test": "vitest run",
53
- "test:watch": "vitest"
60
+ "test:watch": "vitest",
61
+ "site:dev": "bunx --bun serve site -l 4178",
62
+ "deploy:site": "wrangler pages deploy site --project-name=markloom-www --branch=main --commit-dirty=true"
54
63
  },
55
64
  "devDependencies": {
56
65
  "@types/mdast": "^4.0.4",
@@ -58,10 +67,14 @@
58
67
  "@types/react-dom": "^19.2.3",
59
68
  "@vitejs/plugin-react": "4",
60
69
  "aihand": "0.1.17",
70
+ "teactjs": "file:../../teactjs",
71
+ "autoprefixer": "^10.5.4",
61
72
  "github-slugger": "^2.0.0",
73
+ "postcss": "^8.5.24",
62
74
  "react": "^19.2.7",
63
75
  "react-dom": "^19.2.7",
64
76
  "shiki": "^4.3.1",
77
+ "tailwindcss": "3.4.17",
65
78
  "tsup": "^8.4.0",
66
79
  "typescript": "~5.7.2",
67
80
  "vite": "^6",
@@ -90,7 +103,10 @@
90
103
  "mdast-util-gfm": "^3",
91
104
  "mdast-util-to-markdown": "^2",
92
105
  "micromark-extension-gfm": "^3",
106
+ "photoswipe": "^5.4.4",
93
107
  "preact": "^10.29.2",
94
- "preact-render-to-string": "^6.7.0"
108
+ "preact-render-to-string": "^6.7.0",
109
+ "@xmldom/xmldom": "^0.9.10",
110
+ "fflate": "^0.8.3"
95
111
  }
96
112
  }
@@ -1,255 +0,0 @@
1
- import {
2
- transformRemoteAgainstPending
3
- } from "./chunk-RLTHVQNQ.js";
4
-
5
- // src/collab/colors.ts
6
- var COLLAB_COLORS = [
7
- "#3370ff",
8
- "#f54a45",
9
- "#ff8800",
10
- "#00b578",
11
- "#7b61ff",
12
- "#e13edb",
13
- "#14c0ff",
14
- "#8f959e",
15
- "#d83931",
16
- "#2ea121"
17
- ];
18
- function collabColor(siteId, explicit) {
19
- if (explicit)
20
- return explicit;
21
- const i = Math.abs((siteId || 1) - 1) % COLLAB_COLORS.length;
22
- return COLLAB_COLORS[i];
23
- }
24
- function collabInitial(name, siteId) {
25
- const n = (name || "").trim();
26
- if (n) {
27
- const ch = n[0];
28
- return /[a-z]/i.test(ch) ? ch.toUpperCase() : ch;
29
- }
30
- return String(siteId ?? "?");
31
- }
32
-
33
- // src/collab/client.ts
34
- function toWsUrl(url, room) {
35
- let u = url.replace(/\/+$/, "");
36
- if (u.startsWith("https://"))
37
- u = `wss://${u.slice(8)}`;
38
- else if (u.startsWith("http://"))
39
- u = `ws://${u.slice(7)}`;
40
- return `${u}/room/${encodeURIComponent(room)}`;
41
- }
42
- function retryDelay(attempt) {
43
- const base = Math.min(1e3 * 2 ** Math.min(attempt, 5), 3e4);
44
- const jitter = base * 0.5 * Math.random();
45
- return base * 0.75 + jitter;
46
- }
47
- var CollabClient = class {
48
- cfg;
49
- handlers;
50
- ws = null;
51
- closed = false;
52
- retry = 0;
53
- reconnectTimer = null;
54
- siteId = 0;
55
- version = 0;
56
- clientSeq = 0;
57
- pending = [];
58
- peers = /* @__PURE__ */ new Map();
59
- joined = false;
60
- constructor(cfg, handlers) {
61
- this.cfg = cfg;
62
- this.handlers = handlers;
63
- this.connect();
64
- }
65
- get peersList() {
66
- return [...this.peers.values()];
67
- }
68
- connect() {
69
- if (this.closed)
70
- return;
71
- this.handlers.onStatus?.("connecting");
72
- const url = toWsUrl(this.cfg.url, this.cfg.room);
73
- let ws;
74
- try {
75
- ws = new WebSocket(url);
76
- } catch (e) {
77
- this.handlers.onError?.(e instanceof Error ? e.message : String(e));
78
- this.scheduleReconnect();
79
- return;
80
- }
81
- this.ws = ws;
82
- ws.onopen = () => {
83
- this.retry = 0;
84
- this.handlers.onStatus?.("open");
85
- this.send({
86
- type: "join",
87
- room: this.cfg.room,
88
- name: this.cfg.name,
89
- color: this.cfg.color,
90
- seed: this.cfg.seed
91
- });
92
- };
93
- ws.onclose = () => {
94
- this.joined = false;
95
- this.handlers.onStatus?.("closed");
96
- if (!this.closed)
97
- this.scheduleReconnect();
98
- };
99
- ws.onerror = () => {
100
- try {
101
- ws.close();
102
- } catch {
103
- }
104
- };
105
- ws.onmessage = (ev) => {
106
- try {
107
- const msg = JSON.parse(String(ev.data));
108
- this.onServer(msg);
109
- } catch {
110
- }
111
- };
112
- }
113
- scheduleReconnect() {
114
- if (this.reconnectTimer || this.closed)
115
- return;
116
- const delay = retryDelay(this.retry++);
117
- this.reconnectTimer = setTimeout(() => {
118
- this.reconnectTimer = null;
119
- this.connect();
120
- }, delay);
121
- }
122
- send(msg) {
123
- if (this.ws?.readyState === WebSocket.OPEN)
124
- this.ws.send(JSON.stringify(msg));
125
- }
126
- onServer(msg) {
127
- switch (msg.type) {
128
- case "welcome": {
129
- this.siteId = msg.siteId;
130
- this.version = msg.version;
131
- this.pending = [];
132
- this.joined = true;
133
- if (!this.cfg.color)
134
- this.cfg.color = collabColor(msg.siteId);
135
- this.peers.clear();
136
- for (const p of msg.peers) {
137
- this.peers.set(p.siteId, {
138
- ...p,
139
- color: collabColor(p.siteId, p.color)
140
- });
141
- }
142
- this.handlers.onWelcome?.({
143
- siteId: msg.siteId,
144
- version: msg.version,
145
- name: this.cfg.name,
146
- color: this.cfg.color
147
- });
148
- this.handlers.onDoc(msg.doc, msg.version);
149
- this.handlers.onPeers?.(this.peersList);
150
- break;
151
- }
152
- case "resync": {
153
- this.version = msg.version;
154
- this.pending = [];
155
- this.handlers.onDoc(msg.doc, msg.version);
156
- break;
157
- }
158
- case "op": {
159
- if (!this.joined)
160
- return;
161
- if (msg.siteId === this.siteId) {
162
- if (msg.clientSeq != null)
163
- this.pending = this.pending.filter((p) => p.clientSeq > msg.clientSeq);
164
- this.version = msg.version;
165
- return;
166
- }
167
- const pendingAs = this.pending.map((p) => ({ siteId: this.siteId, steps: p.steps }));
168
- const { remote, pending: nextP } = transformRemoteAgainstPending(
169
- msg.steps,
170
- msg.siteId,
171
- pendingAs,
172
- this.siteId
173
- );
174
- this.pending = this.pending.map((p, i) => ({
175
- ...p,
176
- steps: nextP[i]?.steps ?? p.steps
177
- }));
178
- this.version = msg.version;
179
- if (remote.length)
180
- this.handlers.onRemote(remote);
181
- break;
182
- }
183
- case "presence": {
184
- const cur = this.peers.get(msg.siteId) ?? { siteId: msg.siteId };
185
- this.peers.set(msg.siteId, {
186
- ...cur,
187
- name: msg.name ?? cur.name,
188
- color: collabColor(msg.siteId, msg.color ?? cur.color),
189
- sel: msg.sel === void 0 ? cur.sel : msg.sel
190
- });
191
- this.handlers.onPeers?.(this.peersList);
192
- break;
193
- }
194
- case "peer-join": {
195
- this.peers.set(msg.siteId, {
196
- siteId: msg.siteId,
197
- name: msg.name,
198
- color: collabColor(msg.siteId, msg.color)
199
- });
200
- this.handlers.onPeers?.(this.peersList);
201
- break;
202
- }
203
- case "peer-leave": {
204
- this.peers.delete(msg.siteId);
205
- this.handlers.onPeers?.(this.peersList);
206
- break;
207
- }
208
- case "error":
209
- this.handlers.onError?.(msg.message);
210
- break;
211
- case "pong":
212
- break;
213
- }
214
- }
215
- /** 本地已 apply 的 steps 推上服务器 */
216
- push(steps) {
217
- if (!steps.length || !this.joined || this.siteId <= 0)
218
- return;
219
- const clientSeq = ++this.clientSeq;
220
- const baseVersion = this.version;
221
- this.pending.push({ clientSeq, baseVersion, steps });
222
- this.send({ type: "op", baseVersion, clientSeq, steps });
223
- }
224
- presence(sel) {
225
- if (!this.joined)
226
- return;
227
- this.send({
228
- type: "presence",
229
- name: this.cfg.name,
230
- color: this.cfg.color ?? collabColor(this.siteId),
231
- sel
232
- });
233
- }
234
- close() {
235
- this.closed = true;
236
- if (this.reconnectTimer)
237
- clearTimeout(this.reconnectTimer);
238
- try {
239
- this.ws?.close();
240
- } catch {
241
- }
242
- this.ws = null;
243
- }
244
- };
245
- function connectCollab(cfg, handlers) {
246
- return new CollabClient(cfg, handlers);
247
- }
248
-
249
- export {
250
- COLLAB_COLORS,
251
- collabColor,
252
- collabInitial,
253
- CollabClient,
254
- connectCollab
255
- };
@@ -1,255 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
-
3
- var _chunkJS527FDVcjs = require('./chunk-JS527FDV.cjs');
4
-
5
- // src/collab/colors.ts
6
- var COLLAB_COLORS = [
7
- "#3370ff",
8
- "#f54a45",
9
- "#ff8800",
10
- "#00b578",
11
- "#7b61ff",
12
- "#e13edb",
13
- "#14c0ff",
14
- "#8f959e",
15
- "#d83931",
16
- "#2ea121"
17
- ];
18
- function collabColor(siteId, explicit) {
19
- if (explicit)
20
- return explicit;
21
- const i = Math.abs((siteId || 1) - 1) % COLLAB_COLORS.length;
22
- return COLLAB_COLORS[i];
23
- }
24
- function collabInitial(name, siteId) {
25
- const n = (name || "").trim();
26
- if (n) {
27
- const ch = n[0];
28
- return /[a-z]/i.test(ch) ? ch.toUpperCase() : ch;
29
- }
30
- return String(_nullishCoalesce(siteId, () => ( "?")));
31
- }
32
-
33
- // src/collab/client.ts
34
- function toWsUrl(url, room) {
35
- let u = url.replace(/\/+$/, "");
36
- if (u.startsWith("https://"))
37
- u = `wss://${u.slice(8)}`;
38
- else if (u.startsWith("http://"))
39
- u = `ws://${u.slice(7)}`;
40
- return `${u}/room/${encodeURIComponent(room)}`;
41
- }
42
- function retryDelay(attempt) {
43
- const base = Math.min(1e3 * 2 ** Math.min(attempt, 5), 3e4);
44
- const jitter = base * 0.5 * Math.random();
45
- return base * 0.75 + jitter;
46
- }
47
- var CollabClient = (_class = class {
48
-
49
-
50
- __init() {this.ws = null}
51
- __init2() {this.closed = false}
52
- __init3() {this.retry = 0}
53
- __init4() {this.reconnectTimer = null}
54
- __init5() {this.siteId = 0}
55
- __init6() {this.version = 0}
56
- __init7() {this.clientSeq = 0}
57
- __init8() {this.pending = []}
58
- __init9() {this.peers = /* @__PURE__ */ new Map()}
59
- __init10() {this.joined = false}
60
- constructor(cfg, handlers) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);_class.prototype.__init10.call(this);
61
- this.cfg = cfg;
62
- this.handlers = handlers;
63
- this.connect();
64
- }
65
- get peersList() {
66
- return [...this.peers.values()];
67
- }
68
- connect() {
69
- if (this.closed)
70
- return;
71
- _optionalChain([this, 'access', _ => _.handlers, 'access', _2 => _2.onStatus, 'optionalCall', _3 => _3("connecting")]);
72
- const url = toWsUrl(this.cfg.url, this.cfg.room);
73
- let ws;
74
- try {
75
- ws = new WebSocket(url);
76
- } catch (e) {
77
- _optionalChain([this, 'access', _4 => _4.handlers, 'access', _5 => _5.onError, 'optionalCall', _6 => _6(e instanceof Error ? e.message : String(e))]);
78
- this.scheduleReconnect();
79
- return;
80
- }
81
- this.ws = ws;
82
- ws.onopen = () => {
83
- this.retry = 0;
84
- _optionalChain([this, 'access', _7 => _7.handlers, 'access', _8 => _8.onStatus, 'optionalCall', _9 => _9("open")]);
85
- this.send({
86
- type: "join",
87
- room: this.cfg.room,
88
- name: this.cfg.name,
89
- color: this.cfg.color,
90
- seed: this.cfg.seed
91
- });
92
- };
93
- ws.onclose = () => {
94
- this.joined = false;
95
- _optionalChain([this, 'access', _10 => _10.handlers, 'access', _11 => _11.onStatus, 'optionalCall', _12 => _12("closed")]);
96
- if (!this.closed)
97
- this.scheduleReconnect();
98
- };
99
- ws.onerror = () => {
100
- try {
101
- ws.close();
102
- } catch (e2) {
103
- }
104
- };
105
- ws.onmessage = (ev) => {
106
- try {
107
- const msg = JSON.parse(String(ev.data));
108
- this.onServer(msg);
109
- } catch (e3) {
110
- }
111
- };
112
- }
113
- scheduleReconnect() {
114
- if (this.reconnectTimer || this.closed)
115
- return;
116
- const delay = retryDelay(this.retry++);
117
- this.reconnectTimer = setTimeout(() => {
118
- this.reconnectTimer = null;
119
- this.connect();
120
- }, delay);
121
- }
122
- send(msg) {
123
- if (_optionalChain([this, 'access', _13 => _13.ws, 'optionalAccess', _14 => _14.readyState]) === WebSocket.OPEN)
124
- this.ws.send(JSON.stringify(msg));
125
- }
126
- onServer(msg) {
127
- switch (msg.type) {
128
- case "welcome": {
129
- this.siteId = msg.siteId;
130
- this.version = msg.version;
131
- this.pending = [];
132
- this.joined = true;
133
- if (!this.cfg.color)
134
- this.cfg.color = collabColor(msg.siteId);
135
- this.peers.clear();
136
- for (const p of msg.peers) {
137
- this.peers.set(p.siteId, {
138
- ...p,
139
- color: collabColor(p.siteId, p.color)
140
- });
141
- }
142
- _optionalChain([this, 'access', _15 => _15.handlers, 'access', _16 => _16.onWelcome, 'optionalCall', _17 => _17({
143
- siteId: msg.siteId,
144
- version: msg.version,
145
- name: this.cfg.name,
146
- color: this.cfg.color
147
- })]);
148
- this.handlers.onDoc(msg.doc, msg.version);
149
- _optionalChain([this, 'access', _18 => _18.handlers, 'access', _19 => _19.onPeers, 'optionalCall', _20 => _20(this.peersList)]);
150
- break;
151
- }
152
- case "resync": {
153
- this.version = msg.version;
154
- this.pending = [];
155
- this.handlers.onDoc(msg.doc, msg.version);
156
- break;
157
- }
158
- case "op": {
159
- if (!this.joined)
160
- return;
161
- if (msg.siteId === this.siteId) {
162
- if (msg.clientSeq != null)
163
- this.pending = this.pending.filter((p) => p.clientSeq > msg.clientSeq);
164
- this.version = msg.version;
165
- return;
166
- }
167
- const pendingAs = this.pending.map((p) => ({ siteId: this.siteId, steps: p.steps }));
168
- const { remote, pending: nextP } = _chunkJS527FDVcjs.transformRemoteAgainstPending.call(void 0,
169
- msg.steps,
170
- msg.siteId,
171
- pendingAs,
172
- this.siteId
173
- );
174
- this.pending = this.pending.map((p, i) => ({
175
- ...p,
176
- steps: _nullishCoalesce(_optionalChain([nextP, 'access', _21 => _21[i], 'optionalAccess', _22 => _22.steps]), () => ( p.steps))
177
- }));
178
- this.version = msg.version;
179
- if (remote.length)
180
- this.handlers.onRemote(remote);
181
- break;
182
- }
183
- case "presence": {
184
- const cur = _nullishCoalesce(this.peers.get(msg.siteId), () => ( { siteId: msg.siteId }));
185
- this.peers.set(msg.siteId, {
186
- ...cur,
187
- name: _nullishCoalesce(msg.name, () => ( cur.name)),
188
- color: collabColor(msg.siteId, _nullishCoalesce(msg.color, () => ( cur.color))),
189
- sel: msg.sel === void 0 ? cur.sel : msg.sel
190
- });
191
- _optionalChain([this, 'access', _23 => _23.handlers, 'access', _24 => _24.onPeers, 'optionalCall', _25 => _25(this.peersList)]);
192
- break;
193
- }
194
- case "peer-join": {
195
- this.peers.set(msg.siteId, {
196
- siteId: msg.siteId,
197
- name: msg.name,
198
- color: collabColor(msg.siteId, msg.color)
199
- });
200
- _optionalChain([this, 'access', _26 => _26.handlers, 'access', _27 => _27.onPeers, 'optionalCall', _28 => _28(this.peersList)]);
201
- break;
202
- }
203
- case "peer-leave": {
204
- this.peers.delete(msg.siteId);
205
- _optionalChain([this, 'access', _29 => _29.handlers, 'access', _30 => _30.onPeers, 'optionalCall', _31 => _31(this.peersList)]);
206
- break;
207
- }
208
- case "error":
209
- _optionalChain([this, 'access', _32 => _32.handlers, 'access', _33 => _33.onError, 'optionalCall', _34 => _34(msg.message)]);
210
- break;
211
- case "pong":
212
- break;
213
- }
214
- }
215
- /** 本地已 apply 的 steps 推上服务器 */
216
- push(steps) {
217
- if (!steps.length || !this.joined || this.siteId <= 0)
218
- return;
219
- const clientSeq = ++this.clientSeq;
220
- const baseVersion = this.version;
221
- this.pending.push({ clientSeq, baseVersion, steps });
222
- this.send({ type: "op", baseVersion, clientSeq, steps });
223
- }
224
- presence(sel) {
225
- if (!this.joined)
226
- return;
227
- this.send({
228
- type: "presence",
229
- name: this.cfg.name,
230
- color: _nullishCoalesce(this.cfg.color, () => ( collabColor(this.siteId))),
231
- sel
232
- });
233
- }
234
- close() {
235
- this.closed = true;
236
- if (this.reconnectTimer)
237
- clearTimeout(this.reconnectTimer);
238
- try {
239
- _optionalChain([this, 'access', _35 => _35.ws, 'optionalAccess', _36 => _36.close, 'call', _37 => _37()]);
240
- } catch (e4) {
241
- }
242
- this.ws = null;
243
- }
244
- }, _class);
245
- function connectCollab(cfg, handlers) {
246
- return new CollabClient(cfg, handlers);
247
- }
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
- exports.COLLAB_COLORS = COLLAB_COLORS; exports.collabColor = collabColor; exports.collabInitial = collabInitial; exports.CollabClient = CollabClient; exports.connectCollab = connectCollab;
@@ -1,16 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/tree/types.ts
2
- function isText(n) {
3
- return "text" in n;
4
- }
5
- function isElement(n) {
6
- return "children" in n;
7
- }
8
- function isInlineAtom(n) {
9
- return isElement(n) && (n.type === "mention" || n.type === "hard_break" || n.type === "math");
10
- }
11
-
12
-
13
-
14
-
15
-
16
- exports.isText = isText; exports.isElement = isElement; exports.isInlineAtom = isInlineAtom;
@@ -1,16 +0,0 @@
1
- // src/tree/types.ts
2
- function isText(n) {
3
- return "text" in n;
4
- }
5
- function isElement(n) {
6
- return "children" in n;
7
- }
8
- function isInlineAtom(n) {
9
- return isElement(n) && (n.type === "mention" || n.type === "hard_break" || n.type === "math");
10
- }
11
-
12
- export {
13
- isText,
14
- isElement,
15
- isInlineAtom
16
- };