markloom 0.5.0 → 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.
- package/PACKAGES.md +26 -0
- package/README.md +20 -2
- package/collab.md +44 -7
- package/dist/ai/index.cjs +4 -4
- package/dist/ai/index.d.cts +5 -4
- package/dist/ai/index.d.ts +5 -4
- package/dist/ai/index.js +3 -3
- package/dist/ai/theme.css +66 -102
- package/dist/{chunk-YJAWPRJW.cjs → chunk-ACFYBYZJ.cjs} +2817 -903
- package/dist/chunk-CGYCJORO.js +759 -0
- package/dist/chunk-EADZKEU4.cjs +498 -0
- package/dist/chunk-EJSFZHGT.js +24 -0
- package/dist/{chunk-SLRD6FMP.cjs → chunk-I5VK4U7J.cjs} +122 -73
- package/dist/{chunk-WUHTCCAE.js → chunk-KYZJIOOL.js} +2403 -489
- package/dist/chunk-QEVME6ZU.cjs +759 -0
- package/dist/{chunk-MFYF2A6U.js → chunk-SNFF6X45.js} +51 -1
- package/dist/{chunk-JMOJU5EU.js → chunk-TB2OY3D4.js} +69 -20
- package/dist/{chunk-4TMHVNL6.cjs → chunk-TWD5T4YC.cjs} +155 -105
- package/dist/{chunk-JS527FDV.cjs → chunk-U3JZDFL4.cjs} +49 -9
- package/dist/{chunk-RLTHVQNQ.js → chunk-VSBIMMI7.js} +45 -5
- package/dist/chunk-YBAT343I.js +498 -0
- package/dist/chunk-ZKQSQSSM.cjs +24 -0
- package/dist/{client-BNams4wv.d.cts → client-CLYq17SW.d.ts} +70 -7
- package/dist/{client-A0ZQJnyR.d.ts → client-DAth8pPq.d.cts} +70 -7
- package/dist/collab/index.cjs +22 -4
- package/dist/collab/index.d.cts +24 -3
- package/dist/collab/index.d.ts +24 -3
- package/dist/collab/index.js +24 -6
- package/dist/{controller-BkY1VPzc.d.ts → controller-6AJ36G52.d.ts} +108 -8
- package/dist/{controller-CVIZI--A.d.cts → controller-BIOO_XKJ.d.cts} +108 -8
- package/dist/index.cjs +57 -7
- package/dist/index.d.cts +18 -5
- package/dist/index.d.ts +18 -5
- package/dist/index.js +54 -4
- package/dist/io/index.cjs +1413 -0
- package/dist/io/index.d.cts +33 -0
- package/dist/io/index.d.ts +33 -0
- package/dist/io/index.js +1413 -0
- package/dist/react/index.cjs +8 -8
- package/dist/react/index.d.cts +5 -4
- package/dist/react/index.d.ts +5 -4
- package/dist/react/index.js +7 -7
- package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-DlerAcFN.d.ts} +11 -9
- package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-PjENQ742.d.cts} +11 -9
- package/dist/suggest-Bk4zLzuv.d.ts +120 -0
- package/dist/suggest-BkGGiPKA.d.cts +120 -0
- package/dist/types-COUweEav.d.cts +30 -0
- package/dist/types-COUweEav.d.ts +30 -0
- package/dist/versions-9mG1epfB.d.cts +51 -0
- package/dist/versions-Bubyo4pt.d.ts +51 -0
- package/dist/view/index.cjs +56 -12
- package/dist/view/index.d.cts +203 -11
- package/dist/view/index.d.ts +203 -11
- package/dist/view/index.js +52 -8
- package/dist/view/theme.css +1840 -1526
- package/io.md +38 -0
- package/package.json +21 -5
- package/dist/chunk-6DCI7AL3.js +0 -208
- package/dist/chunk-AC5E42NH.cjs +0 -208
- package/dist/chunk-GQ2HHRGI.cjs +0 -16
- package/dist/chunk-LA5SBCGQ.js +0 -16
- package/dist/chunk-LEYAQNJA.js +0 -220
- package/dist/chunk-YXQDCW4Y.cjs +0 -220
- package/dist/comments-DlExS6f-.d.cts +0 -43
- package/dist/comments-PhnR7Gkn.d.ts +0 -43
- package/dist/step-BrvHIK7O.d.cts +0 -65
- 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.
|
|
4
|
-
"description": "The loom for Markdown — rich text with MD isomorphism, reversible Steps,
|
|
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
|
}
|
package/dist/chunk-6DCI7AL3.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
transformRemoteAgainstPending
|
|
3
|
-
} from "./chunk-RLTHVQNQ.js";
|
|
4
|
-
|
|
5
|
-
// src/collab/client.ts
|
|
6
|
-
function toWsUrl(url, room) {
|
|
7
|
-
let u = url.replace(/\/+$/, "");
|
|
8
|
-
if (u.startsWith("https://"))
|
|
9
|
-
u = `wss://${u.slice(8)}`;
|
|
10
|
-
else if (u.startsWith("http://"))
|
|
11
|
-
u = `ws://${u.slice(7)}`;
|
|
12
|
-
return `${u}/room/${encodeURIComponent(room)}`;
|
|
13
|
-
}
|
|
14
|
-
function retryDelay(attempt) {
|
|
15
|
-
const base = Math.min(1e3 * 2 ** Math.min(attempt, 5), 3e4);
|
|
16
|
-
const jitter = base * 0.5 * Math.random();
|
|
17
|
-
return base * 0.75 + jitter;
|
|
18
|
-
}
|
|
19
|
-
var CollabClient = class {
|
|
20
|
-
cfg;
|
|
21
|
-
handlers;
|
|
22
|
-
ws = null;
|
|
23
|
-
closed = false;
|
|
24
|
-
retry = 0;
|
|
25
|
-
reconnectTimer = null;
|
|
26
|
-
siteId = 0;
|
|
27
|
-
version = 0;
|
|
28
|
-
clientSeq = 0;
|
|
29
|
-
pending = [];
|
|
30
|
-
peers = /* @__PURE__ */ new Map();
|
|
31
|
-
joined = false;
|
|
32
|
-
constructor(cfg, handlers) {
|
|
33
|
-
this.cfg = cfg;
|
|
34
|
-
this.handlers = handlers;
|
|
35
|
-
this.connect();
|
|
36
|
-
}
|
|
37
|
-
get peersList() {
|
|
38
|
-
return [...this.peers.values()];
|
|
39
|
-
}
|
|
40
|
-
connect() {
|
|
41
|
-
if (this.closed)
|
|
42
|
-
return;
|
|
43
|
-
this.handlers.onStatus?.("connecting");
|
|
44
|
-
const url = toWsUrl(this.cfg.url, this.cfg.room);
|
|
45
|
-
let ws;
|
|
46
|
-
try {
|
|
47
|
-
ws = new WebSocket(url);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
this.handlers.onError?.(e instanceof Error ? e.message : String(e));
|
|
50
|
-
this.scheduleReconnect();
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.ws = ws;
|
|
54
|
-
ws.onopen = () => {
|
|
55
|
-
this.retry = 0;
|
|
56
|
-
this.handlers.onStatus?.("open");
|
|
57
|
-
this.send({
|
|
58
|
-
type: "join",
|
|
59
|
-
room: this.cfg.room,
|
|
60
|
-
name: this.cfg.name,
|
|
61
|
-
color: this.cfg.color,
|
|
62
|
-
seed: this.cfg.seed
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
ws.onclose = () => {
|
|
66
|
-
this.joined = false;
|
|
67
|
-
this.handlers.onStatus?.("closed");
|
|
68
|
-
if (!this.closed)
|
|
69
|
-
this.scheduleReconnect();
|
|
70
|
-
};
|
|
71
|
-
ws.onerror = () => {
|
|
72
|
-
try {
|
|
73
|
-
ws.close();
|
|
74
|
-
} catch {
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
ws.onmessage = (ev) => {
|
|
78
|
-
try {
|
|
79
|
-
const msg = JSON.parse(String(ev.data));
|
|
80
|
-
this.onServer(msg);
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
scheduleReconnect() {
|
|
86
|
-
if (this.reconnectTimer || this.closed)
|
|
87
|
-
return;
|
|
88
|
-
const delay = retryDelay(this.retry++);
|
|
89
|
-
this.reconnectTimer = setTimeout(() => {
|
|
90
|
-
this.reconnectTimer = null;
|
|
91
|
-
this.connect();
|
|
92
|
-
}, delay);
|
|
93
|
-
}
|
|
94
|
-
send(msg) {
|
|
95
|
-
if (this.ws?.readyState === WebSocket.OPEN)
|
|
96
|
-
this.ws.send(JSON.stringify(msg));
|
|
97
|
-
}
|
|
98
|
-
onServer(msg) {
|
|
99
|
-
switch (msg.type) {
|
|
100
|
-
case "welcome": {
|
|
101
|
-
this.siteId = msg.siteId;
|
|
102
|
-
this.version = msg.version;
|
|
103
|
-
this.pending = [];
|
|
104
|
-
this.joined = true;
|
|
105
|
-
this.peers.clear();
|
|
106
|
-
for (const p of msg.peers)
|
|
107
|
-
this.peers.set(p.siteId, p);
|
|
108
|
-
this.handlers.onDoc(msg.doc, msg.version);
|
|
109
|
-
this.handlers.onPeers?.(this.peersList);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
case "resync": {
|
|
113
|
-
this.version = msg.version;
|
|
114
|
-
this.pending = [];
|
|
115
|
-
this.handlers.onDoc(msg.doc, msg.version);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "op": {
|
|
119
|
-
if (!this.joined)
|
|
120
|
-
return;
|
|
121
|
-
if (msg.siteId === this.siteId) {
|
|
122
|
-
if (msg.clientSeq != null)
|
|
123
|
-
this.pending = this.pending.filter((p) => p.clientSeq > msg.clientSeq);
|
|
124
|
-
this.version = msg.version;
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const pendingAs = this.pending.map((p) => ({ siteId: this.siteId, steps: p.steps }));
|
|
128
|
-
const { remote, pending: nextP } = transformRemoteAgainstPending(
|
|
129
|
-
msg.steps,
|
|
130
|
-
msg.siteId,
|
|
131
|
-
pendingAs,
|
|
132
|
-
this.siteId
|
|
133
|
-
);
|
|
134
|
-
this.pending = this.pending.map((p, i) => ({
|
|
135
|
-
...p,
|
|
136
|
-
steps: nextP[i]?.steps ?? p.steps
|
|
137
|
-
}));
|
|
138
|
-
this.version = msg.version;
|
|
139
|
-
if (remote.length)
|
|
140
|
-
this.handlers.onRemote(remote);
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
case "presence": {
|
|
144
|
-
const cur = this.peers.get(msg.siteId) ?? { siteId: msg.siteId };
|
|
145
|
-
this.peers.set(msg.siteId, {
|
|
146
|
-
...cur,
|
|
147
|
-
name: msg.name ?? cur.name,
|
|
148
|
-
color: msg.color ?? cur.color,
|
|
149
|
-
sel: msg.sel === void 0 ? cur.sel : msg.sel
|
|
150
|
-
});
|
|
151
|
-
this.handlers.onPeers?.(this.peersList);
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case "peer-join": {
|
|
155
|
-
this.peers.set(msg.siteId, { siteId: msg.siteId, name: msg.name, color: msg.color });
|
|
156
|
-
this.handlers.onPeers?.(this.peersList);
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
case "peer-leave": {
|
|
160
|
-
this.peers.delete(msg.siteId);
|
|
161
|
-
this.handlers.onPeers?.(this.peersList);
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "error":
|
|
165
|
-
this.handlers.onError?.(msg.message);
|
|
166
|
-
break;
|
|
167
|
-
case "pong":
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/** 本地已 apply 的 steps 推上服务器 */
|
|
172
|
-
push(steps) {
|
|
173
|
-
if (!steps.length || !this.joined || this.siteId <= 0)
|
|
174
|
-
return;
|
|
175
|
-
const clientSeq = ++this.clientSeq;
|
|
176
|
-
const baseVersion = this.version;
|
|
177
|
-
this.pending.push({ clientSeq, baseVersion, steps });
|
|
178
|
-
this.send({ type: "op", baseVersion, clientSeq, steps });
|
|
179
|
-
}
|
|
180
|
-
presence(sel) {
|
|
181
|
-
if (!this.joined)
|
|
182
|
-
return;
|
|
183
|
-
this.send({
|
|
184
|
-
type: "presence",
|
|
185
|
-
name: this.cfg.name,
|
|
186
|
-
color: this.cfg.color,
|
|
187
|
-
sel
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
close() {
|
|
191
|
-
this.closed = true;
|
|
192
|
-
if (this.reconnectTimer)
|
|
193
|
-
clearTimeout(this.reconnectTimer);
|
|
194
|
-
try {
|
|
195
|
-
this.ws?.close();
|
|
196
|
-
} catch {
|
|
197
|
-
}
|
|
198
|
-
this.ws = null;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
function connectCollab(cfg, handlers) {
|
|
202
|
-
return new CollabClient(cfg, handlers);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export {
|
|
206
|
-
CollabClient,
|
|
207
|
-
connectCollab
|
|
208
|
-
};
|
package/dist/chunk-AC5E42NH.cjs
DELETED
|
@@ -1,208 +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/client.ts
|
|
6
|
-
function toWsUrl(url, room) {
|
|
7
|
-
let u = url.replace(/\/+$/, "");
|
|
8
|
-
if (u.startsWith("https://"))
|
|
9
|
-
u = `wss://${u.slice(8)}`;
|
|
10
|
-
else if (u.startsWith("http://"))
|
|
11
|
-
u = `ws://${u.slice(7)}`;
|
|
12
|
-
return `${u}/room/${encodeURIComponent(room)}`;
|
|
13
|
-
}
|
|
14
|
-
function retryDelay(attempt) {
|
|
15
|
-
const base = Math.min(1e3 * 2 ** Math.min(attempt, 5), 3e4);
|
|
16
|
-
const jitter = base * 0.5 * Math.random();
|
|
17
|
-
return base * 0.75 + jitter;
|
|
18
|
-
}
|
|
19
|
-
var CollabClient = (_class = class {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
__init() {this.ws = null}
|
|
23
|
-
__init2() {this.closed = false}
|
|
24
|
-
__init3() {this.retry = 0}
|
|
25
|
-
__init4() {this.reconnectTimer = null}
|
|
26
|
-
__init5() {this.siteId = 0}
|
|
27
|
-
__init6() {this.version = 0}
|
|
28
|
-
__init7() {this.clientSeq = 0}
|
|
29
|
-
__init8() {this.pending = []}
|
|
30
|
-
__init9() {this.peers = /* @__PURE__ */ new Map()}
|
|
31
|
-
__init10() {this.joined = false}
|
|
32
|
-
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);
|
|
33
|
-
this.cfg = cfg;
|
|
34
|
-
this.handlers = handlers;
|
|
35
|
-
this.connect();
|
|
36
|
-
}
|
|
37
|
-
get peersList() {
|
|
38
|
-
return [...this.peers.values()];
|
|
39
|
-
}
|
|
40
|
-
connect() {
|
|
41
|
-
if (this.closed)
|
|
42
|
-
return;
|
|
43
|
-
_optionalChain([this, 'access', _ => _.handlers, 'access', _2 => _2.onStatus, 'optionalCall', _3 => _3("connecting")]);
|
|
44
|
-
const url = toWsUrl(this.cfg.url, this.cfg.room);
|
|
45
|
-
let ws;
|
|
46
|
-
try {
|
|
47
|
-
ws = new WebSocket(url);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
_optionalChain([this, 'access', _4 => _4.handlers, 'access', _5 => _5.onError, 'optionalCall', _6 => _6(e instanceof Error ? e.message : String(e))]);
|
|
50
|
-
this.scheduleReconnect();
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.ws = ws;
|
|
54
|
-
ws.onopen = () => {
|
|
55
|
-
this.retry = 0;
|
|
56
|
-
_optionalChain([this, 'access', _7 => _7.handlers, 'access', _8 => _8.onStatus, 'optionalCall', _9 => _9("open")]);
|
|
57
|
-
this.send({
|
|
58
|
-
type: "join",
|
|
59
|
-
room: this.cfg.room,
|
|
60
|
-
name: this.cfg.name,
|
|
61
|
-
color: this.cfg.color,
|
|
62
|
-
seed: this.cfg.seed
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
ws.onclose = () => {
|
|
66
|
-
this.joined = false;
|
|
67
|
-
_optionalChain([this, 'access', _10 => _10.handlers, 'access', _11 => _11.onStatus, 'optionalCall', _12 => _12("closed")]);
|
|
68
|
-
if (!this.closed)
|
|
69
|
-
this.scheduleReconnect();
|
|
70
|
-
};
|
|
71
|
-
ws.onerror = () => {
|
|
72
|
-
try {
|
|
73
|
-
ws.close();
|
|
74
|
-
} catch (e2) {
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
ws.onmessage = (ev) => {
|
|
78
|
-
try {
|
|
79
|
-
const msg = JSON.parse(String(ev.data));
|
|
80
|
-
this.onServer(msg);
|
|
81
|
-
} catch (e3) {
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
scheduleReconnect() {
|
|
86
|
-
if (this.reconnectTimer || this.closed)
|
|
87
|
-
return;
|
|
88
|
-
const delay = retryDelay(this.retry++);
|
|
89
|
-
this.reconnectTimer = setTimeout(() => {
|
|
90
|
-
this.reconnectTimer = null;
|
|
91
|
-
this.connect();
|
|
92
|
-
}, delay);
|
|
93
|
-
}
|
|
94
|
-
send(msg) {
|
|
95
|
-
if (_optionalChain([this, 'access', _13 => _13.ws, 'optionalAccess', _14 => _14.readyState]) === WebSocket.OPEN)
|
|
96
|
-
this.ws.send(JSON.stringify(msg));
|
|
97
|
-
}
|
|
98
|
-
onServer(msg) {
|
|
99
|
-
switch (msg.type) {
|
|
100
|
-
case "welcome": {
|
|
101
|
-
this.siteId = msg.siteId;
|
|
102
|
-
this.version = msg.version;
|
|
103
|
-
this.pending = [];
|
|
104
|
-
this.joined = true;
|
|
105
|
-
this.peers.clear();
|
|
106
|
-
for (const p of msg.peers)
|
|
107
|
-
this.peers.set(p.siteId, p);
|
|
108
|
-
this.handlers.onDoc(msg.doc, msg.version);
|
|
109
|
-
_optionalChain([this, 'access', _15 => _15.handlers, 'access', _16 => _16.onPeers, 'optionalCall', _17 => _17(this.peersList)]);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
case "resync": {
|
|
113
|
-
this.version = msg.version;
|
|
114
|
-
this.pending = [];
|
|
115
|
-
this.handlers.onDoc(msg.doc, msg.version);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "op": {
|
|
119
|
-
if (!this.joined)
|
|
120
|
-
return;
|
|
121
|
-
if (msg.siteId === this.siteId) {
|
|
122
|
-
if (msg.clientSeq != null)
|
|
123
|
-
this.pending = this.pending.filter((p) => p.clientSeq > msg.clientSeq);
|
|
124
|
-
this.version = msg.version;
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const pendingAs = this.pending.map((p) => ({ siteId: this.siteId, steps: p.steps }));
|
|
128
|
-
const { remote, pending: nextP } = _chunkJS527FDVcjs.transformRemoteAgainstPending.call(void 0,
|
|
129
|
-
msg.steps,
|
|
130
|
-
msg.siteId,
|
|
131
|
-
pendingAs,
|
|
132
|
-
this.siteId
|
|
133
|
-
);
|
|
134
|
-
this.pending = this.pending.map((p, i) => ({
|
|
135
|
-
...p,
|
|
136
|
-
steps: _nullishCoalesce(_optionalChain([nextP, 'access', _18 => _18[i], 'optionalAccess', _19 => _19.steps]), () => ( p.steps))
|
|
137
|
-
}));
|
|
138
|
-
this.version = msg.version;
|
|
139
|
-
if (remote.length)
|
|
140
|
-
this.handlers.onRemote(remote);
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
case "presence": {
|
|
144
|
-
const cur = _nullishCoalesce(this.peers.get(msg.siteId), () => ( { siteId: msg.siteId }));
|
|
145
|
-
this.peers.set(msg.siteId, {
|
|
146
|
-
...cur,
|
|
147
|
-
name: _nullishCoalesce(msg.name, () => ( cur.name)),
|
|
148
|
-
color: _nullishCoalesce(msg.color, () => ( cur.color)),
|
|
149
|
-
sel: msg.sel === void 0 ? cur.sel : msg.sel
|
|
150
|
-
});
|
|
151
|
-
_optionalChain([this, 'access', _20 => _20.handlers, 'access', _21 => _21.onPeers, 'optionalCall', _22 => _22(this.peersList)]);
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case "peer-join": {
|
|
155
|
-
this.peers.set(msg.siteId, { siteId: msg.siteId, name: msg.name, color: msg.color });
|
|
156
|
-
_optionalChain([this, 'access', _23 => _23.handlers, 'access', _24 => _24.onPeers, 'optionalCall', _25 => _25(this.peersList)]);
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
case "peer-leave": {
|
|
160
|
-
this.peers.delete(msg.siteId);
|
|
161
|
-
_optionalChain([this, 'access', _26 => _26.handlers, 'access', _27 => _27.onPeers, 'optionalCall', _28 => _28(this.peersList)]);
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "error":
|
|
165
|
-
_optionalChain([this, 'access', _29 => _29.handlers, 'access', _30 => _30.onError, 'optionalCall', _31 => _31(msg.message)]);
|
|
166
|
-
break;
|
|
167
|
-
case "pong":
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/** 本地已 apply 的 steps 推上服务器 */
|
|
172
|
-
push(steps) {
|
|
173
|
-
if (!steps.length || !this.joined || this.siteId <= 0)
|
|
174
|
-
return;
|
|
175
|
-
const clientSeq = ++this.clientSeq;
|
|
176
|
-
const baseVersion = this.version;
|
|
177
|
-
this.pending.push({ clientSeq, baseVersion, steps });
|
|
178
|
-
this.send({ type: "op", baseVersion, clientSeq, steps });
|
|
179
|
-
}
|
|
180
|
-
presence(sel) {
|
|
181
|
-
if (!this.joined)
|
|
182
|
-
return;
|
|
183
|
-
this.send({
|
|
184
|
-
type: "presence",
|
|
185
|
-
name: this.cfg.name,
|
|
186
|
-
color: this.cfg.color,
|
|
187
|
-
sel
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
close() {
|
|
191
|
-
this.closed = true;
|
|
192
|
-
if (this.reconnectTimer)
|
|
193
|
-
clearTimeout(this.reconnectTimer);
|
|
194
|
-
try {
|
|
195
|
-
_optionalChain([this, 'access', _32 => _32.ws, 'optionalAccess', _33 => _33.close, 'call', _34 => _34()]);
|
|
196
|
-
} catch (e4) {
|
|
197
|
-
}
|
|
198
|
-
this.ws = null;
|
|
199
|
-
}
|
|
200
|
-
}, _class);
|
|
201
|
-
function connectCollab(cfg, handlers) {
|
|
202
|
-
return new CollabClient(cfg, handlers);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
exports.CollabClient = CollabClient; exports.connectCollab = connectCollab;
|
package/dist/chunk-GQ2HHRGI.cjs
DELETED
|
@@ -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;
|
package/dist/chunk-LA5SBCGQ.js
DELETED
|
@@ -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
|
-
};
|