@toantranmei/editor 0.3.0 → 0.4.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/README.md +82 -1
- package/dist/collaboration.js +205 -19
- package/dist/collaboration.js.map +1 -1
- package/dist/{css-el97DJfy.js → css-Cf_w91Fs.js} +26 -11
- package/dist/css-Cf_w91Fs.js.map +1 -0
- package/dist/{date-utils-DW99lT2W.js → date-utils-CevhhRfQ.js} +22 -4
- package/dist/date-utils-CevhhRfQ.js.map +1 -0
- package/dist/index.js +2067 -1626
- package/dist/index.js.map +1 -1
- package/dist/nuxt.js +2 -1
- package/dist/nuxt.js.map +1 -1
- package/dist/render.js +200 -182
- package/dist/render.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/collaboration.d.ts +9 -1
- package/dist/types/components/MeiEditor.vue.d.ts +3 -2
- package/dist/types/composables/useUploadState.d.ts +10 -0
- package/dist/types/config.d.ts +5 -2
- package/dist/types/extensions/block-drop.d.ts +23 -0
- package/dist/types/extensions/file-block.d.ts +5 -2
- package/dist/types/extensions/file-drop.d.ts +65 -0
- package/dist/types/extensions/index.d.ts +1 -1
- package/dist/types/extensions/upload-attrs.d.ts +29 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/locale.d.ts +9 -0
- package/dist/types/presence.d.ts +39 -0
- package/dist/types/render/index.d.ts +18 -3
- package/dist/types/theme/css.d.ts +3 -0
- package/dist/types/theme/tokens.d.ts +4 -0
- package/package.json +1 -1
- package/dist/css-el97DJfy.js.map +0 -1
- package/dist/date-utils-DW99lT2W.js.map +0 -1
package/README.md
CHANGED
|
@@ -219,6 +219,35 @@ onBeforeUnmount(() => { local.destroy(); doc.destroy() })
|
|
|
219
219
|
</template>
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
+
### Presence (carets)
|
|
223
|
+
|
|
224
|
+
Pass a [`y-protocols`](https://github.com/yjs/y-protocols) awareness and a lookup of who each Yjs client is:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
import { presenceColor, scrollToPeer } from '@toantranmei/editor/collaboration'
|
|
228
|
+
|
|
229
|
+
const collaboration = {
|
|
230
|
+
document: doc,
|
|
231
|
+
presence: {
|
|
232
|
+
awareness: provider.awareness,
|
|
233
|
+
// Server-trusted identity; null hides that client. Never read names / colours from awareness states.
|
|
234
|
+
resolveUser: (clientId: number) => {
|
|
235
|
+
const peer = peers.get(clientId)
|
|
236
|
+
return peer ? { name: peer.name, color: presenceColor(peer.colorIndex), avatarUrl: peer.avatarUrl } : null
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
// avatar click: scrollToPeer(editor, clientId); after `resolveUser` changes its answers: refreshPresence(editor)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Remote carets show the name for 3 s after they move (and on hover), selections get a 25 % tint and the block
|
|
244
|
+
holding the caret `me-peer-block` (2px bar + 6 % tint, `--me-peer-color`). The local caret is published in the
|
|
245
|
+
awareness field `cursor`, at most every 50 ms, and never while the editor is read-only. `PRESENCE_COLORS` has 12
|
|
246
|
+
colours with ≥ 3:1 contrast on light and dark backgrounds; name labels darken the colour (`labelBackground`) so the
|
|
247
|
+
white text reaches 4.5:1. The caret stays visible while focus is elsewhere on the page (a comment box, a popover);
|
|
248
|
+
it is cleared when the editor becomes read-only, unmounts, or the tab stays hidden for over a minute (restored when
|
|
249
|
+
it is visible again). Typing re-shows your label to others even when the caret's position doesn't change.
|
|
250
|
+
|
|
222
251
|
For a headless setup use `createExtensions({ blocks, undoRedo: false })` together with
|
|
223
252
|
`collaborationExtensions({ document, field })` from `@toantranmei/editor/collaboration`.
|
|
224
253
|
The same entry has `fillDocument(doc, json, editor.schema, field?)` (seed / replace a shared document's
|
|
@@ -264,11 +293,40 @@ relative URLs (`safeUrl`), media also to `data:image|audio|video`; embeds need a
|
|
|
264
293
|
keep the editor's sandbox; HTML blocks run in `sandbox` without `allow-same-origin` (code kept in `srcdoc`).
|
|
265
294
|
|
|
266
295
|
Also exported: `renderHTML` (sync), `hasMath`, `escapeHtml`, `attr`, `safeUrl`, `highlightCode`,
|
|
267
|
-
`renderTokensStyle(
|
|
296
|
+
`renderTokensStyle(options?)` (`<style id="mei-editor-tokens">` with the default tokens, which the editor
|
|
268
297
|
otherwise injects at runtime), and `hydrateMermaid(root?)`: a browser helper that turns
|
|
269
298
|
`<pre class="mermaid">` into diagrams (loads the optional `mermaid` peer). A 1,000-block document renders in
|
|
270
299
|
~5 ms.
|
|
271
300
|
|
|
301
|
+
`renderTokensStyle` takes either token overrides (`ThemeTokens`, like `<MeiEditor :tokens>`; dark follows
|
|
302
|
+
`<html class="dark">` / `.me-dark`) or `{ light, dark }` (with a `light` key, `{}` allowed; `{ dark }` alone is the
|
|
303
|
+
overrides form): then the page also follows the OS, with the default dark
|
|
304
|
+
tokens and `dark` under `@media (prefers-color-scheme: dark)` (`.me-light` opts out). Both parts accept a token tree
|
|
305
|
+
(`{ color: { text: '#222' } }`) or a flat map (`{ 'color.text': '#222' }` / `{ '--me-color-text': '#222' }`).
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
const style = renderTokensStyle({ light: appTokens, dark: { color: { text: '#eee', bg: '#191919' } } }) // into <head>
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Heavy blocks load on first use
|
|
312
|
+
|
|
313
|
+
Blocks keep their schema in the main bundle (a document must parse before anything renders) and load their heavy
|
|
314
|
+
code the first time a page shows one, so apps don't need a wrapper:
|
|
315
|
+
|
|
316
|
+
| Block | Loaded lazily | Shown meanwhile |
|
|
317
|
+
| --- | --- | --- |
|
|
318
|
+
| `math` | KaTeX (`loadKatex()`, optional peer) | TeX source |
|
|
319
|
+
| `mermaid` | Mermaid (`loadMermaid()`, optional peer) | code |
|
|
320
|
+
| `codeBlock` | highlight.js grammar per language | plain code |
|
|
321
|
+
| `emoji` | emoji data per locale | – |
|
|
322
|
+
| `@toantranmei/database-block` | the database UI (`DatabaseView`, TanStack) | loading box at the view's last height (this session), else header + 3 rows (`database.loadingHeight`) |
|
|
323
|
+
| `@toantranmei/chart-block` | ECharts | chart frame at its height |
|
|
324
|
+
| `@toantranmei/sketch-block` | the board engine (on first interaction / preview) | preview at the block's height |
|
|
325
|
+
| collaboration | Yjs, y-tiptap, presence (`@toantranmei/editor/collaboration`) | – |
|
|
326
|
+
|
|
327
|
+
Bundlers put each in its own chunk; keep these packages external to your own vendor chunk so the split survives.
|
|
328
|
+
Static rendering (`/render` entries) never loads them.
|
|
329
|
+
|
|
272
330
|
|
|
273
331
|
## Keyboard & mouse
|
|
274
332
|
|
|
@@ -320,6 +378,29 @@ async function upload(file: File) {
|
|
|
320
378
|
</script>
|
|
321
379
|
```
|
|
322
380
|
|
|
381
|
+
### Paste and drop files
|
|
382
|
+
|
|
383
|
+
Pasting or dropping images and files anywhere in the editor inserts them at the caret / drop point (several in
|
|
384
|
+
order; a text selection is replaced): images become image blocks with an instant preview, other files file blocks
|
|
385
|
+
(audio / video / file from the mime type; needs the `file` block). Uploads go through `uploadImage` and
|
|
386
|
+
`file.configure({ upload })`, which may report progress with their optional second / third argument
|
|
387
|
+
`onProgress(fraction)`. Too large (`maxImageSize`, `file` `maxSize`), unsupported image formats and failed uploads
|
|
388
|
+
stay on the block with Retry / Delete (only in the tab that has the file; other editors see "Uploading…"). An upload
|
|
389
|
+
still running after 2 minutes with nobody holding its file (the tab closed) shows "Upload interrupted" with Delete.
|
|
390
|
+
Pastes that carry text or web images (`<img src="https://…">`) keep the regular paste; Word's local images
|
|
391
|
+
(`<img src="file:///…">`) are uploaded from the clipboard's files, in place.
|
|
392
|
+
|
|
393
|
+
Leaving the page while a file uploads: a collaborative editor that is destroyed meanwhile writes the result into
|
|
394
|
+
its Yjs document once the upload ends (an editor opened again on that document shows the upload's progress). Keep
|
|
395
|
+
the document open until then:
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
import { uploadsSettled } from '@toantranmei/editor'
|
|
399
|
+
// before the editor unmounts
|
|
400
|
+
const settled = uploadsSettled(editor)
|
|
401
|
+
settled ? settled.finally(() => provider.destroy()) : provider.destroy()
|
|
402
|
+
```
|
|
403
|
+
|
|
323
404
|
## Safe loading
|
|
324
405
|
|
|
325
406
|
Invalid content never blanks the editor (Tiptap's default, which the next save would persist):
|
package/dist/collaboration.js
CHANGED
|
@@ -1,13 +1,195 @@
|
|
|
1
1
|
import { Extension as e } from "@tiptap/core";
|
|
2
2
|
import { Plugin as t, PluginKey as n } from "@tiptap/pm/state";
|
|
3
|
-
import r from "@tiptap/
|
|
4
|
-
import
|
|
3
|
+
import { Decoration as r, DecorationSet as i } from "@tiptap/pm/view";
|
|
4
|
+
import a from "@tiptap/extension-collaboration";
|
|
5
|
+
import { absolutePositionToRelativePosition as o, prosemirrorJSONToYXmlFragment as s, relativePositionToAbsolutePosition as c, setMeta as l, ySyncPluginKey as u, yXmlFragmentToProsemirrorJSON as d } from "@tiptap/y-tiptap";
|
|
6
|
+
import * as f from "yjs";
|
|
7
|
+
// src/presence.ts
|
|
8
|
+
var p = Object.freeze([
|
|
9
|
+
"#e5484d",
|
|
10
|
+
"#3e7ee8",
|
|
11
|
+
"#3d9a50",
|
|
12
|
+
"#a855f7",
|
|
13
|
+
"#c97a0a",
|
|
14
|
+
"#0797b9",
|
|
15
|
+
"#d6409f",
|
|
16
|
+
"#5b8a00",
|
|
17
|
+
"#7c66dc",
|
|
18
|
+
"#cf5a1f",
|
|
19
|
+
"#0f9a8a",
|
|
20
|
+
"#a68a00"
|
|
21
|
+
]);
|
|
22
|
+
function m(e) {
|
|
23
|
+
let t = p.length;
|
|
24
|
+
return p[((Number.isFinite(e) ? Math.trunc(e) : 0) % t + t) % t];
|
|
25
|
+
}
|
|
26
|
+
var h = "cursor", g = 50, _ = 3e3, v = 6e4, y = 1e3, b = new n("meiPresence"), x = /^[#\w\s(),.%-]+$/, S = (e) => x.test(e) ? e : p[0], C = (e) => {
|
|
27
|
+
let t = e / 255;
|
|
28
|
+
return t <= .03928 ? t / 12.92 : ((t + .055) / 1.055) ** 2.4;
|
|
29
|
+
}, w = ([e, t, n]) => .2126 * C(e) + .7152 * C(t) + .0722 * C(n), T = (e) => `#${e.map((e) => Math.round(e).toString(16).padStart(2, "0")).join("")}`;
|
|
30
|
+
function E(e) {
|
|
31
|
+
let t = /^#([\da-f]{3}|[\da-f]{6})$/i.exec(e.trim());
|
|
32
|
+
if (!t) return e;
|
|
33
|
+
let n = t[1].length === 3 ? [...t[1]].map((e) => e + e).join("") : t[1], r = [
|
|
34
|
+
0,
|
|
35
|
+
2,
|
|
36
|
+
4
|
|
37
|
+
].map((e) => Number.parseInt(n.slice(e, e + 2), 16));
|
|
38
|
+
for (let e = 1; e > 0; e -= .02) {
|
|
39
|
+
let t = r.map((t) => t * e);
|
|
40
|
+
if (1.05 / (w(t) + .05) >= 4.5) return T(t);
|
|
41
|
+
}
|
|
42
|
+
return "#000000";
|
|
43
|
+
}
|
|
44
|
+
function D(e, t) {
|
|
45
|
+
let n = document.createElement("span");
|
|
46
|
+
n.className = "me-peer-caret", n.style.setProperty("--me-peer-color", t), n.style.setProperty("--me-peer-label-bg", E(t)), n.setAttribute("aria-hidden", "true");
|
|
47
|
+
let r = document.createElement("span");
|
|
48
|
+
return r.className = "me-peer-label", r.dataset.name = e.name, n.append(r), n;
|
|
49
|
+
}
|
|
50
|
+
function O(n) {
|
|
51
|
+
let { awareness: a, resolveUser: s } = n;
|
|
52
|
+
return e.create({
|
|
53
|
+
name: "meiPresence",
|
|
54
|
+
addProseMirrorPlugins() {
|
|
55
|
+
let e = this.editor, n = /* @__PURE__ */ new Map(), d = (e) => {
|
|
56
|
+
let t = u.getState(e), o = /* @__PURE__ */ new Map();
|
|
57
|
+
if (!t?.doc || !t.binding || t.snapshot != null || t.prevSnapshot != null || t.binding.mapping.size === 0) return {
|
|
58
|
+
decorations: i.empty,
|
|
59
|
+
heads: o
|
|
60
|
+
};
|
|
61
|
+
let l = t.doc, d = [], p = /* @__PURE__ */ new Set(), m = Math.max(e.doc.content.size - 1, 0), g = Date.now();
|
|
62
|
+
a.getStates().forEach((i, a) => {
|
|
63
|
+
if (a === l.clientID) return;
|
|
64
|
+
let u = i[h];
|
|
65
|
+
if (!u?.anchor || !u.head) return;
|
|
66
|
+
let v = s(a);
|
|
67
|
+
if (!v) return;
|
|
68
|
+
let y = (e) => {
|
|
69
|
+
try {
|
|
70
|
+
return c(l, t.type, f.createRelativePositionFromJSON(e), t.binding.mapping);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}, b = y(u.anchor), x = y(u.head);
|
|
75
|
+
if (b === null || x === null) return;
|
|
76
|
+
b = Math.min(b, m), x = Math.min(x, m), o.set(a, x);
|
|
77
|
+
let C = JSON.stringify(u), w = n.get(a), T = !w || w.cursor !== C ? {
|
|
78
|
+
cursor: C,
|
|
79
|
+
version: (w?.version ?? 0) + 1,
|
|
80
|
+
at: g
|
|
81
|
+
} : w;
|
|
82
|
+
n.set(a, T);
|
|
83
|
+
let E = S(v.color);
|
|
84
|
+
d.push(r.widget(x, () => {
|
|
85
|
+
let e = D(v, E);
|
|
86
|
+
return e.style.setProperty("--me-peer-label-delay", `${Math.max(0, _ - (Date.now() - T.at))}ms`), e;
|
|
87
|
+
}, {
|
|
88
|
+
key: `${a}:${T.version}:${v.name}:${E}`,
|
|
89
|
+
side: 10
|
|
90
|
+
})), b !== x && d.push(r.inline(Math.min(b, x), Math.max(b, x), {
|
|
91
|
+
class: "me-peer-selection",
|
|
92
|
+
style: `--me-peer-color: ${E}`
|
|
93
|
+
}, {
|
|
94
|
+
inclusiveEnd: !0,
|
|
95
|
+
inclusiveStart: !1
|
|
96
|
+
}));
|
|
97
|
+
let O = e.doc.resolve(x), k = O.depth >= 1 ? O.before(1) : x, A = e.doc.nodeAt(k);
|
|
98
|
+
A && !A.isInline && !p.has(k) && (p.add(k), d.push(r.node(k, k + A.nodeSize, {
|
|
99
|
+
class: "me-peer-block",
|
|
100
|
+
style: `--me-peer-color: ${E}`
|
|
101
|
+
})));
|
|
102
|
+
});
|
|
103
|
+
for (let e of n.keys()) o.has(e) || n.delete(e);
|
|
104
|
+
return {
|
|
105
|
+
decorations: i.create(e.doc, d),
|
|
106
|
+
heads: o
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
return [new t({
|
|
110
|
+
key: b,
|
|
111
|
+
state: {
|
|
112
|
+
init: (e, t) => d(t),
|
|
113
|
+
apply(e, t, n, r) {
|
|
114
|
+
if (u.getState(r)?.isChangeOrigin || e.getMeta(b)?.awarenessUpdated) return d(r);
|
|
115
|
+
if (!e.docChanged) return t;
|
|
116
|
+
let i = /* @__PURE__ */ new Map();
|
|
117
|
+
return t.heads.forEach((t, n) => i.set(n, e.mapping.map(t))), {
|
|
118
|
+
decorations: t.decorations.map(e.mapping, e.doc),
|
|
119
|
+
heads: i
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
props: { decorations: (e) => b.getState(e)?.decorations ?? i.empty },
|
|
124
|
+
view: (t) => {
|
|
125
|
+
let n = () => {
|
|
126
|
+
t.isDestroyed || l(t, b, { awarenessUpdated: !0 });
|
|
127
|
+
}, r = (e, t) => {
|
|
128
|
+
(t !== "local" || e.updated.length !== 1 || e.updated[0] !== a.clientID || e.added.length || e.removed.length) && n();
|
|
129
|
+
};
|
|
130
|
+
a.on("change", r);
|
|
131
|
+
let i, s = null, c = 0, d = () => {
|
|
132
|
+
if (s = null, i === void 0) return;
|
|
133
|
+
c = Date.now();
|
|
134
|
+
let e = i;
|
|
135
|
+
i = void 0, a.setLocalStateField(h, e);
|
|
136
|
+
}, p = (e) => {
|
|
137
|
+
i = e;
|
|
138
|
+
let t = g - (Date.now() - c);
|
|
139
|
+
t <= 0 ? d() : s ??= setTimeout(d, t);
|
|
140
|
+
}, m = () => a.getLocalState()?.[h] ?? null, _ = t.hasFocus(), x = !1, S = null, C = 0, w = 0, T = (t, n) => {
|
|
141
|
+
let r = u.getState(t.state);
|
|
142
|
+
if (!r?.binding || r.binding.projectionError != null) return;
|
|
143
|
+
if (t.hasFocus() && (_ = !0), !e.isEditable || x || !_) {
|
|
144
|
+
(i === void 0 ? m() : i) != null && p(null);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
n && n.doc !== t.state.doc && !r.isChangeOrigin && Date.now() - w >= y && (C++, w = Date.now());
|
|
148
|
+
let { anchor: a, head: s } = t.state.selection, c = {
|
|
149
|
+
anchor: o(a, r.type, r.binding.mapping),
|
|
150
|
+
head: o(s, r.type, r.binding.mapping),
|
|
151
|
+
activity: C
|
|
152
|
+
}, l = i === void 0 ? m() : i;
|
|
153
|
+
l?.anchor && l.head && (l.activity ?? 0) === C && f.compareRelativePositions(f.createRelativePositionFromJSON(l.anchor), c.anchor) && f.compareRelativePositions(f.createRelativePositionFromJSON(l.head), c.head) || p(c);
|
|
154
|
+
}, E = () => T(t);
|
|
155
|
+
t.dom.addEventListener("focusin", E);
|
|
156
|
+
let D = () => {
|
|
157
|
+
S && clearTimeout(S), S = null, document.visibilityState === "hidden" ? S = setTimeout(() => {
|
|
158
|
+
S = null, x = !0, t.isDestroyed || T(t);
|
|
159
|
+
}, v) : x && (x = !1, t.isDestroyed || T(t));
|
|
160
|
+
}, O = typeof document > "u" ? null : document;
|
|
161
|
+
return O?.addEventListener("visibilitychange", D), {
|
|
162
|
+
update: T,
|
|
163
|
+
destroy: () => {
|
|
164
|
+
t.dom.removeEventListener("focusin", E), O?.removeEventListener("visibilitychange", D), S && clearTimeout(S), a.off("change", r), s && clearTimeout(s), a.setLocalStateField(h, null);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
})];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function k(e) {
|
|
173
|
+
!e.isDestroyed && b.getState(e.state) && l(e.view, b, { awarenessUpdated: !0 });
|
|
174
|
+
}
|
|
175
|
+
function A(e, t) {
|
|
176
|
+
if (e.isDestroyed) return !1;
|
|
177
|
+
let n = b.getState(e.state)?.heads.get(t);
|
|
178
|
+
if (n == null) return !1;
|
|
179
|
+
let { node: r } = e.view.domAtPos(n), i = r instanceof HTMLElement ? r : r.parentElement;
|
|
180
|
+
if (!i) return !1;
|
|
181
|
+
let a = typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
182
|
+
return i.scrollIntoView({
|
|
183
|
+
block: "center",
|
|
184
|
+
behavior: a ? "auto" : "smooth"
|
|
185
|
+
}), !0;
|
|
186
|
+
}
|
|
5
187
|
// src/collaboration.ts
|
|
6
|
-
function
|
|
7
|
-
let t = e.state.plugins.find((e) => e.spec.key ===
|
|
188
|
+
function j(e) {
|
|
189
|
+
let t = e.state.plugins.find((e) => e.spec.key === u) ?? e.state.plugins.find((e) => e.key === "y-sync$"), n = (t?.spec.state?.init)?.call(t, {}, e.state)?.binding;
|
|
8
190
|
return n && typeof n._forceRerender == "function" ? n : null;
|
|
9
191
|
}
|
|
10
|
-
var
|
|
192
|
+
var M = e.create({
|
|
11
193
|
name: "meiCollaborationFirstRender",
|
|
12
194
|
addProseMirrorPlugins() {
|
|
13
195
|
let e = this.editor, r = /* @__PURE__ */ new WeakMap(), i = !1;
|
|
@@ -15,28 +197,32 @@ var c = e.create({
|
|
|
15
197
|
key: new n("meiCollaborationFirstRender"),
|
|
16
198
|
props: { editable: () => !i },
|
|
17
199
|
view: (t) => {
|
|
18
|
-
let n =
|
|
200
|
+
let n = j(t);
|
|
19
201
|
return !n || n.prosemirrorView !== t ? (i = !0, console.error("[MeiEditor] Collaboration: the Yjs sync plugin was not found (two copies of @tiptap/y-tiptap?). The editor is read-only."), queueMicrotask(() => !e.isDestroyed && e.setEditable(!1)), {}) : (r.get(n) !== t && (r.set(n, t), n._forceRerender()), {});
|
|
20
202
|
}
|
|
21
203
|
})];
|
|
22
204
|
}
|
|
23
205
|
});
|
|
24
|
-
function
|
|
25
|
-
return [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
206
|
+
function N(e) {
|
|
207
|
+
return [
|
|
208
|
+
a.configure({
|
|
209
|
+
document: e.document,
|
|
210
|
+
field: e.field ?? "default",
|
|
211
|
+
ySyncOptions: { mapping: /* @__PURE__ */ new Map() }
|
|
212
|
+
}),
|
|
213
|
+
M,
|
|
214
|
+
...e.presence ? [O(e.presence)] : []
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
function P(e, t, n, r = "default") {
|
|
218
|
+
let i = e.getXmlFragment(r);
|
|
33
219
|
e.transact(() => {
|
|
34
|
-
|
|
220
|
+
i.length && i.delete(0, i.length), s(n, t, i);
|
|
35
221
|
});
|
|
36
222
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
223
|
+
function F(e, t = "default") {
|
|
224
|
+
return d(e.getXmlFragment(t));
|
|
39
225
|
}
|
|
40
|
-
export {
|
|
226
|
+
export { p as PRESENCE_COLORS, N as collaborationExtensions, F as documentToJSON, P as fillDocument, E as labelBackground, m as presenceColor, k as refreshPresence, A as scrollToPeer };
|
|
41
227
|
|
|
42
228
|
//# sourceMappingURL=collaboration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collaboration.js","names":["Collaboration","syncBinding","plugin","view","p","ySyncPluginKey","binding","firstRender","Extension","editor","rendered","broken","Plugin","PluginKey","collaborationExtensions","options","fillDocument","fragment","document","field","prosemirrorJSONToYXmlFragment","schema","content","documentToJSON","yXmlFragmentToProsemirrorJSON"],"sources":["../src/collaboration.ts"],"sourcesContent":["import { type AnyExtension, Extension, type JSONContent } from '@tiptap/core'\nimport Collaboration from '@tiptap/extension-collaboration'\nimport type { Schema } from '@tiptap/pm/model'\nimport { type EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport { prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, ySyncPluginKey } from '@tiptap/y-tiptap'\nimport type * as Y from 'yjs'\n\n/**\n * `<MeiEditor :collaboration>`: the editor reads and writes a Yjs document instead of `v-model`.\n * Read once, at mount (like `blocks`).\n */\nexport interface MeiCollaboration {\n /** The shared document. It is the source of truth: `modelValue` is never loaded into it. */\n document: Y.Doc\n /** Name of the `Y.XmlFragment` in `document` that holds the editor content. Default `'default'`. */\n field?: string\n // Reserved: presence (`CollaborationCaret`: provider + user) will be added here.\n}\n\n/**\n * Renders the Y.Doc into the editor once, when the editor view is created.\n *\n * Without a `mapping`, y-tiptap's sync plugin re-renders the whole document (and dispatches a\n * transaction) every time plugin views are re-created, i.e. on every `editor.registerPlugin()`\n * (drag handle, bubble menus…). That dispatch runs while ProseMirror is still creating plugin\n * views, so the view re-creates them a second time: every plugin view after the sync plugin\n * exists twice. The Yjs undo plugin's view is one of them, and when both copies are destroyed\n * the undo manager loses itself from its tracked origins, so undo steps are never recorded on\n * the redo stack — redo never works (KS-BUG-10). The nested render was also overwritten by the\n * state update around it, leaving the binding's mapping pointing at stale nodes (the first local\n * edit after mount was reverted). Passing our own `mapping` turns those re-renders off; this\n * plugin does the first render instead.\n */\ninterface SyncBinding { prosemirrorView: unknown, _forceRerender: () => void }\n\n/**\n * The binding of the sync plugin in `view`. Read from the plugin itself: when the editor is\n * mounted again (`editor.unmount(); editor.mount(el)`) the plugins are re-created but the\n * state keeps the old plugin state, whose binding has no view any more.\n */\nfunction syncBinding(view: EditorView): SyncBinding | null {\n const plugin = view.state.plugins.find(p => p.spec.key === ySyncPluginKey)\n // A second copy of y-tiptap in the app has its own key object: match by name too.\n ?? view.state.plugins.find(p => (p as unknown as { key: string }).key === 'y-sync$')\n const init = plugin?.spec.state?.init as ((config: object, state: EditorState) => { binding?: SyncBinding }) | undefined\n const binding = init?.call(plugin, {}, view.state)?.binding\n return binding && typeof binding._forceRerender === 'function' ? binding : null\n}\n\nconst firstRender = Extension.create({\n name: 'meiCollaborationFirstRender',\n addProseMirrorPlugins() {\n const editor = this.editor\n // The view each binding was rendered into: render once per binding and view.\n const rendered = new WeakMap<SyncBinding, unknown>()\n // Set when the document can't be loaded. Sticky: the `editable` prop below wins over any\n // later setEditable(true) (e.g. MeiEditor's `editable` watcher).\n let broken = false\n return [new Plugin({\n key: new PluginKey('meiCollaborationFirstRender'),\n props: { editable: () => !broken },\n view: (view) => {\n const binding = syncBinding(view)\n if (!binding || binding.prosemirrorView !== view) {\n // Nothing would ever load the document, and the first edit would overwrite the shared\n // one with this empty editor: refuse to edit.\n broken = true\n console.error('[MeiEditor] Collaboration: the Yjs sync plugin was not found (two copies of @tiptap/y-tiptap?). The editor is read-only.')\n queueMicrotask(() => !editor.isDestroyed && editor.setEditable(false))\n return {}\n }\n if (rendered.get(binding) !== view) {\n rendered.set(binding, view)\n binding._forceRerender()\n }\n return {}\n },\n })]\n },\n})\n\n/**\n * Tiptap extensions for a collaborative editor: Yjs sync + Yjs undo (Mod-z / Mod-Shift-z / Mod-y).\n * Use with `createExtensions({ ..., undoRedo: false })` — the built-in history must be off.\n * Kept in its own module (`@toantranmei/editor/collaboration`) so editors without collaboration never load Yjs.\n */\nexport function collaborationExtensions(options: MeiCollaboration): AnyExtension[] {\n return [\n Collaboration.configure({\n document: options.document,\n field: options.field ?? 'default',\n ySyncOptions: { mapping: new Map() },\n }),\n firstRender,\n ]\n}\n\n/**\n * Replaces the content of `document` (its `field` fragment) with `content`, in one Yjs\n * transaction. Use it to seed a new shared document, e.g. a synced block created from\n * existing blocks. `schema` is the editor's (`editor.schema`); invalid content throws.\n */\nexport function fillDocument(document: Y.Doc, content: JSONContent, schema: Schema, field = 'default'): void {\n const fragment = document.getXmlFragment(field)\n document.transact(() => {\n if (fragment.length) fragment.delete(0, fragment.length)\n prosemirrorJSONToYXmlFragment(schema, content, fragment)\n })\n}\n\n/** The content of `document` as editor JSON (`{ type: 'doc', content }`), e.g. for `renderHTML`. */\nexport function documentToJSON(document: Y.Doc, field = 'default'): JSONContent {\n return yXmlFragmentTo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,EAAS,eAAe;EAEtB,AADIF,EAAS,UAAQA,EAAS,OAAO,GAAGA,EAAS,MAAM,GACvDG,EAA8BC,GAAQC,GAASL,CAAQ;CACzD,CAAC;AACH;AAGA,SAAgBM,EAAe,GAAiB,IAAQ,WAAwB;CAC9E,OAAOC,EAA8BN,EAAS,eAAeC,CAAK,CAAC;AACrE"}
|
|
1
|
+
{"version":3,"file":"collaboration.js","names":["Collaboration","Y","PRESENCE_COLORS","presenceColor","n","index","CURSOR_FIELD","THROTTLE_MS","LABEL_MS","HIDDEN_MS","ACTIVITY_MS","presenceKey","PluginKey","SAFE_COLOR","safeColor","color","channel","c","v","luminance","r","g","b","toHex","rgb","labelBackground","m","hex","i","f","next","caret","el","label","user","presenceExtension","presence","Extension","editor","seen","build","ystate","ySyncPluginKey","state","heads","DecorationSet","y","decorations","blocks","max","now","clientId","cursor","aw","resolveUser","toAbs","relativePositionToAbsolutePosition","json","anchor","head","key","last","entry","Decoration","$head","start","block","id","Plugin","tr","prev","pos","redraw","view","setMeta","onChange","origin","changes","awareness","pending","timer","lastSent","send","value","publish","wait","current","focused","hidden","hiddenTimer","activity","lastActivity","update","prevState","absolutePositionToRelativePosition","before","onFocus","onVisibility","doc","refreshPresence","scrollToPeer","node","reduce","syncBinding","plugin","p","binding","firstRender","rendered","broken","collaborationExtensions","options","fillDocument","fragment","document","field","prosemirrorJSONToYXmlFragment","schema","content","documentToJSON","yXmlFragmentToProsemirrorJSON"],"sources":["../src/presence.ts","../src/collaboration.ts"],"sourcesContent":["import { type Editor, Extension } from '@tiptap/core'\nimport { type EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet, type EditorView } from '@tiptap/pm/view'\nimport {\n absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, ySyncPluginKey,\n} from '@tiptap/y-tiptap'\nimport type { Awareness } from 'y-protocols/awareness'\nimport * as Y from 'yjs'\n\n/** Who a remote caret belongs to. */\nexport interface PresenceUser {\n name: string\n /** CSS colour of the caret, selection and active block (e.g. `presenceColor(i)`). */\n color: string\n avatarUrl?: string | null\n}\n\n/** `MeiCollaboration.presence`: remote carets and selections over a `y-protocols` awareness. */\nexport interface MeiPresence {\n awareness: Awareness\n /** Server-trusted identity of a remote Yjs client id; null = do not draw. */\n resolveUser: (clientId: number) => PresenceUser | null\n}\n\n/**\n * 12 caret colours, each with a contrast ≥ 3:1 against white and against the dark editor background (#191919).\n * Name labels use white text on the colour darkened to ≥ 4.5:1 (`labelBackground`). Adjacent entries differ in hue.\n */\nexport const PRESENCE_COLORS: readonly string[] = Object.freeze([\n '#e5484d', '#3e7ee8', '#3d9a50', '#a855f7', '#c97a0a', '#0797b9',\n '#d6409f', '#5b8a00', '#7c66dc', '#cf5a1f', '#0f9a8a', '#a68a00',\n])\n\n/** `PRESENCE_COLORS[index % 12]` (negative and fractional indexes are folded in). */\nexport function presenceColor(index: number): string {\n const n = PRESENCE_COLORS.length\n const i = Number.isFinite(index) ? Math.trunc(index) : 0\n return PRESENCE_COLORS[((i % n) + n) % n]!\n}\n\n/** Awareness field written by the local editor (same shape as y-tiptap's cursor plugin). */\nconst CURSOR_FIELD = 'cursor'\n/** Local cursor updates are sent at most this often. */\nconst THROTTLE_MS = 50\n/** The name label shows this long after a peer's caret moves or they type, then fades (presence.css). */\nconst LABEL_MS = 3000\n/** A page hidden this long stops publishing its caret (restored when visible again). */\nconst HIDDEN_MS = 60_000\n/** Local edits raise `activity` at most this often (the label stays LABEL_MS after each). */\nconst ACTIVITY_MS = 1000\n\n/**\n * `activity` counts local edits: typing mid-text keeps the relative position, so without it the peer's label would\n * not re-show while they type. Extra field, ignored by y-tiptap's own cursor plugin.\n */\ninterface CursorState { anchor: unknown, head: unknown, activity?: number }\ninterface PeerState {\n decorations: DecorationSet\n /** Absolute head position of every drawn peer, for `scrollToPeer`. */\n heads: Map<number, number>\n}\n\nconst presenceKey = new PluginKey<PeerState>('meiPresence')\n\n// Colours only reach a `style` attribute: refuse anything that could close the declaration.\nconst SAFE_COLOR = /^[#\\w\\s(),.%-]+$/\nconst safeColor = (color: string) => (SAFE_COLOR.test(color) ? color : PRESENCE_COLORS[0]!)\n\nconst channel = (v: number) => {\n const c = v / 255\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n}\nconst luminance = ([r, g, b]: number[]) => 0.2126 * channel(r!) + 0.7152 * channel(g!) + 0.0722 * channel(b!)\nconst toHex = (rgb: number[]) => `#${rgb.map(v => Math.round(v).toString(16).padStart(2, '0')).join('')}`\n\n/**\n * Background of a name label for caret `color`: the colour itself, darkened just enough for white text to reach\n * 4.5:1. Non-hex colours are returned unchanged.\n */\nexport function labelBackground(color: string): string {\n const m = /^#([\\da-f]{3}|[\\da-f]{6})$/i.exec(color.trim())\n if (!m) return color\n const hex = m[1]!.length === 3 ? [...m[1]!].map(c => c + c).join('') : m[1]!\n const rgb = [0, 2, 4].map(i => Number.parseInt(hex.slice(i, i + 2), 16))\n for (let f = 1; f > 0; f -= 0.02) {\n const next = rgb.map(v => v * f)\n if (1.05 / (luminance(next) + 0.05) >= 4.5) return toHex(next)\n }\n return '#000000'\n}\n\nfunction caret(user: PresenceUser, color: string): HTMLElement {\n const el = document.createElement('span')\n el.className = 'me-peer-caret'\n el.style.setProperty('--me-peer-color', color)\n el.style.setProperty('--me-peer-label-bg', labelBackground(color))\n el.setAttribute('aria-hidden', 'true')\n const label = document.createElement('span')\n label.className = 'me-peer-label'\n // The name is drawn by CSS (`content: attr(data-name)`): the widget holds no text node. With text inside it (the name,\n // or word joiners around the caret), the browser could put the local caret in that non-editable text when both\n // carets share a position (End, Ctrl+End, a click at the line end), and what was typed then was lost.\n label.dataset.name = user.name\n el.append(label)\n return el\n}\n\n/**\n * Remote carets (with name labels), selections and the active block of each peer; publishes the local selection,\n * throttled. Names and colours come only from `resolveUser`, never from the remote awareness state.\n */\nexport function presenceExtension(presence: MeiPresence) {\n const { awareness, resolveUser } = presence\n\n return Extension.create({\n name: 'meiPresence',\n\n addProseMirrorPlugins() {\n const editor = this.editor\n /** Last cursor seen per peer and a counter bumped when it moves (restarts the label's fade). */\n const seen = new Map<number, { cursor: string, version: number, at: number }>()\n\n const build = (state: EditorState): PeerState => {\n const ystate = ySyncPluginKey.getState(state)\n const heads = new Map<number, number>()\n if (!ystate?.doc || !ystate.binding || ystate.snapshot != null || ystate.prevSnapshot != null || ystate.binding.mapping.size === 0) {\n return { decorations: DecorationSet.empty, heads }\n }\n const y = ystate.doc as Y.Doc\n const decorations: Decoration[] = []\n const blocks = new Set<number>()\n const max = Math.max(state.doc.content.size - 1, 0)\n const now = Date.now()\n awareness.getStates().forEach((aw, clientId) => {\n if (clientId === y.clientID) return\n const cursor = (aw as { [CURSOR_FIELD]?: CursorState | null })[CURSOR_FIELD]\n if (!cursor?.anchor || !cursor.head) return\n const user = resolveUser(clientId)\n if (!user) return\n const toAbs = (json: unknown) => {\n try {\n return relativePositionToAbsolutePosition(y, ystate.type, Y.createRelativePositionFromJSON(json), ystate.binding.mapping)\n }\n catch {\n return null\n }\n }\n let anchor = toAbs(cursor.anchor)\n let head = toAbs(cursor.head)\n if (anchor === null || head === null) return\n anchor = Math.min(anchor, max)\n head = Math.min(head, max)\n heads.set(clientId, head)\n\n const key = JSON.stringify(cursor)\n const last = seen.get(clientId)\n const entry = !last || last.cursor !== key ? { cursor: key, version: (last?.version ?? 0) + 1, at: now } : last\n seen.set(clientId, entry)\n const color = safeColor(user.color)\n // Same key while the peer stays put: ProseMirror keeps the element and its label fade running.\n decorations.push(Decoration.widget(head, () => {\n const el = caret(user, color)\n // A caret re-created later (e.g. its paragraph re-rendered) keeps the original 3 s countdown.\n el.style.setProperty('--me-peer-label-delay', `${Math.max(0, LABEL_MS - (Date.now() - entry.at))}ms`)\n return el\n }, { key: `${clientId}:${entry.version}:${user.name}:${color}`, side: 10 }))\n if (anchor !== head) {\n decorations.push(Decoration.inline(Math.min(anchor, head), Math.max(anchor, head), {\n class: 'me-peer-selection',\n style: `--me-peer-color: ${color}`,\n }, { inclusiveEnd: true, inclusiveStart: false }))\n }\n // The top-level block holding the caret.\n const $head = state.doc.resolve(head)\n const start = $head.depth >= 1 ? $head.before(1) : head\n const block = state.doc.nodeAt(start)\n if (block && !block.isInline && !blocks.has(start)) {\n blocks.add(start)\n decorations.push(Decoration.node(start, start + block.nodeSize, { class: 'me-peer-block', style: `--me-peer-color: ${color}` }))\n }\n })\n for (const id of seen.keys()) if (!heads.has(id)) seen.delete(id)\n return { decorations: DecorationSet.create(state.doc, decorations), heads }\n }\n\n return [new Plugin<PeerState>({\n key: presenceKey,\n state: {\n init: (_, state) => build(state),\n apply(tr, prev, _old, state) {\n const ystate = ySyncPluginKey.getState(state)\n if (ystate?.isChangeOrigin || tr.getMeta(presenceKey)?.awarenessUpdated) return build(state)\n if (!tr.docChanged) return prev\n const heads = new Map<number, number>()\n prev.heads.forEach((pos, id) => heads.set(id, tr.mapping.map(pos)))\n return { decorations: prev.decorations.map(tr.mapping, tr.doc), heads }\n },\n },\n props: {\n decorations: state => presenceKey.getState(state)?.decorations ?? DecorationSet.empty,\n },\n view: (view) => {\n // --- Remote: redraw on awareness changes ---------------------------------\n const redraw = () => {\n if (!view.isDestroyed) setMeta(view, presenceKey, { awarenessUpdated: true })\n }\n const onChange = (changes: { added: number[], updated: number[], removed: number[] }, origin: unknown) => {\n // Our own cursor needs no redraw.\n if (origin === 'local' && changes.updated.length === 1 && changes.updated[0] === awareness.clientID && !changes.added.length && !changes.removed.length) return\n redraw()\n }\n awareness.on('change', onChange)\n\n // --- Local: publish the selection, throttled; read-only editors publish nothing ---\n // Kept on blur (focus in a comment composer / popover must keep you visible); cleared when read-only,\n // destroyed or hidden for HIDDEN_MS. Nothing is published before the editor was first focused.\n let pending: CursorState | null | undefined\n let timer: ReturnType<typeof setTimeout> | null = null\n let lastSent = 0\n const send = () => {\n timer = null\n if (pending === undefined) return\n lastSent = Date.now()\n const value = pending\n pending = undefined\n awareness.setLocalStateField(CURSOR_FIELD, value)\n }\n const publish = (value: CursorState | null) => {\n pending = value\n const wait = THROTTLE_MS - (Date.now() - lastSent)\n if (wait <= 0) send()\n else timer ??= setTimeout(send, wait)\n }\n const current = () => (awareness.getLocalState() as { [CURSOR_FIELD]?: CursorState | null } | null)?.[CURSOR_FIELD] ?? null\n let focused = view.hasFocus()\n let hidden = false\n let hiddenTimer: ReturnType<typeof setTimeout> | null = null\n let activity = 0\n let lastActivity = 0\n const update = (v: EditorView, prevState?: EditorState) => {\n const ystate = ySyncPluginKey.getState(v.state)\n if (!ystate?.binding || ystate.binding.projectionError != null) return\n if (v.hasFocus()) focused = true\n if (!editor.isEditable || hidden || !focused) {\n // A queued value counts: a pending null must not be overtaken by a stale \"already null\".\n if ((pending === undefined ? current() : pending) != null) publish(null)\n return\n }\n // At most one bump per ACTIVITY_MS of continuous typing: enough to keep the label shown, less churn.\n if (prevState && prevState.doc !== v.state.doc && !ystate.isChangeOrigin && Date.now() - lastActivity >= ACTIVITY_MS) {\n activity++\n lastActivity = Date.now()\n }\n const { anchor, head } = v.state.selection\n const next: CursorState = {\n anchor: absolutePositionToRelativePosition(anchor, ystate.type, ystate.binding.mapping),\n head: absolutePositionToRelativePosition(head, ystate.type, ystate.binding.mapping),\n activity,\n }\n const before = pending === undefined ? current() : pending\n if (before?.anchor && before.head && (before.activity ?? 0) === activity\n && Y.compareRelativePositions(Y.createRelativePositionFromJSON(before.anchor), next.anchor as Y.RelativePosition)\n && Y.compareRelativePositions(Y.createRelativePositionFromJSON(before.head), next.head as Y.RelativePosition)) return\n publish(next)\n }\n const onFocus = () => update(view)\n view.dom.addEventListener('focusin', onFocus)\n const onVisibility = () => {\n if (hiddenTimer) clearTimeout(hiddenTimer)\n hiddenTimer = null\n if (document.visibilityState === 'hidden') {\n hiddenTimer = setTimeout(() => {\n hiddenTimer = null\n hidden = true\n if (!view.isDestroyed) update(view)\n }, HIDDEN_MS)\n }\n else if (hidden) {\n hidden = false\n if (!view.isDestroyed) update(view)\n }\n }\n const doc = typeof document === 'undefined' ? null : document\n doc?.addEventListener('visibilitychange', onVisibility)\n\n return {\n update,\n destroy: () => {\n view.dom.removeEventListener('focusin', onFocus)\n doc?.removeEventListener('visibilitychange', onVisibility)\n if (hiddenTimer) clearTimeout(hiddenTimer)\n awareness.off('change', onChange)\n if (timer) clearTimeout(timer)\n awareness.setLocalStateField(CURSOR_FIELD, null)\n },\n }\n },\n })]\n },\n })\n}\n\n/**\n * Redraws remote carets, e.g. after `resolveUser` changed its answer (a peer's access was revoked, names arrived).\n * Awareness changes redraw on their own.\n */\nexport function refreshPresence(editor: Editor): void {\n if (!editor.isDestroyed && presenceKey.getState(editor.state)) setMeta(editor.view, presenceKey, { awarenessUpdated: true })\n}\n\n/** Scrolls the editor to a peer's caret (e.g. on avatar click). False when that peer has no caret here. */\nexport function scrollToPeer(editor: Editor, clientId: number): boolean {\n if (editor.isDestroyed) return false\n const pos = presenceKey.getState(editor.state)?.heads.get(clientId)\n if (pos == null) return false\n const { node } = editor.view.domAtPos(pos)\n const el = node instanceof HTMLElement ? node : node.parentElement\n if (!el) return false\n const reduce = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches\n el.scrollIntoView({ block: 'center', behavior: reduce ? 'auto' : 'smooth' })\n return true\n}\n","import { type AnyExtension, Extension, type JSONContent } from '@tiptap/core'\nimport Collaboration from '@tiptap/extension-collaboration'\nimport type { Schema } from '@tiptap/pm/model'\nimport { type EditorState, Plugin, PluginKey } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport { prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, ySyncPluginKey } from '@tiptap/y-tiptap'\nimport type * as Y from 'yjs'\nimport { type MeiPresence, presenceExtension } from './presence'\n\nexport {\n labelBackground, PRESENCE_COLORS, presenceColor, refreshPresence, scrollToPeer, type MeiPresence, type PresenceUser,\n} from './presence'\n\n/**\n * `<MeiEditor :collaboration>`: the editor reads and writes a Yjs document instead of `v-model`.\n * Read once, at mount (like `blocks`).\n */\nexport interface MeiCollaboration {\n /** The shared document. It is the source of truth: `modelValue` is never loaded into it. */\n document: Y.Doc\n /** Name of the `Y.XmlFragment` in `document` that holds the editor content. Default `'default'`. */\n field?: string\n /**\n * Remote carets, selections and active blocks over a `y-protocols` awareness; the local selection is published\n * to it (throttled, not when read-only). Names and colours come only from `resolveUser`.\n */\n presence?: MeiPresence\n}\n\n/**\n * Renders the Y.Doc into the editor once, when the editor view is created.\n *\n * Without a `mapping`, y-tiptap's sync plugin re-renders the whole document (and dispatches a\n * transaction) every time plugin views are re-created, i.e. on every `editor.registerPlugin()`\n * (drag handle, bubble menus…). That dispatch runs while ProseMirror is still creating plugin\n * views, so the view re-creates them a second time: every plugin view after the sync plugin\n * exists twice. The Yjs undo plugin's view is one of them, and when both copies are destroyed\n * the undo manager loses itself from its tracked origins, so undo steps are never recorded on\n * the redo stack — redo never works (KS-BUG-10). The nested render was also overwritten by the\n * state update around it, leaving the binding's mapping pointing at stale nodes (the first local\n * edit after mount was reverted). Passing our own `mapping` turns those re-renders off; this\n * plugin does the first render instead.\n */\ninterface SyncBinding { prosemirrorView: unknown, _forceRerender: () => void }\n\n/**\n * The binding of the sync plugin in `view`. Read from the plugin itself: when the editor is\n * mounted again (`editor.unmount(); editor.mount(el)`) the plugins are re-created but the\n * state keeps the old plugin state, whose binding has no view any more.\n */\nfunction syncBinding(view: EditorView): SyncBinding | null {\n const plugin = view.state.plugins.find(p => p.spec.key === ySyncPluginKey)\n // A second copy of y-tiptap in the app has its own key object: match by name too.\n ?? view.state.plugins.find(p => (p as unknown as { key: string }).key === 'y-sync$')\n const init = plugin?.spec.state?.init as ((config: object, state: EditorState) => { binding?: SyncBinding }) | undefined\n const binding = init?.call(plugin, {}, view.state)?.binding\n return binding && typeof binding._forceRerender === 'function' ? binding : null\n}\n\nconst firstRender = Extension.create({\n name: 'meiCollaborationFirstRender',\n addProseMirrorPlugins() {\n const editor = this.editor\n // The view each binding was rendered into: render once per binding and view.\n const rendered = new WeakMap<SyncBinding, unknown>()\n // Set when the document can't be loaded. Sticky: the `editable` prop below wins over any\n // later setEditable(true) (e.g. MeiEditor's `editable` watcher).\n let broken = false\n return [new Plugin({\n key: new PluginKey('meiCollaborationFirstRender'),\n props: { editable: () => !broken },\n view: (view) => {\n const binding = syncBinding(view)\n if (!binding || binding.prosemirrorView !== view) {\n // Nothing would ever load the document, and the first edit would overwrite the shared\n // one with this empty editor: refuse to edit.\n broken = true\n console.error('[MeiEditor] Collaboration: the Yjs sync plugin was not found (two copies of @tiptap/y-tiptap?). The editor is read-only.')\n queueMicrotask(() => !editor.isDestroyed && editor.setEditable(false))\n return {}\n }\n if (rendered.get(binding) !== view) {\n rendered.set(binding, view)\n binding._forceRerender()\n }\n return {}\n },\n })]\n },\n})\n\n/**\n * Tiptap extensions for a collaborative editor: Yjs sync + Yjs undo (Mod-z / Mod-Shift-z / Mod-y), and presence\n * when `options.presence` is given.\n * Use with `createExtensions({ ..., undoRedo: false })` — the built-in history must be off.\n * Kept in its own module (`@toantranmei/editor/collaboration`) so editors without collaboration never load Yjs.\n */\nexport function collaborationExtensions(options: MeiCollaboration): AnyExtension[] {\n return [\n Collaboration.configure({\n document: options.document,\n field: options.field ?? 'default',\n ySyncOptions: { mapping: new Map() },\n }),\n firstRender,\n ...(options.presence ? [presenceExtension(options.presence)] : []),\n ]\n}\n\n/**\n * Replaces the content of `document` (its `field` fragment) with `content`, in one Yjs\n * transaction. Use it to seed a new shared document, e.g. a synced block created from\n * existing blocks. `schema` is the editor's (`editor.schema`); invalid content throws.\n */\nexport function fillDocument(document: Y.Doc, content: JSONContent, schema: Schema, field = 'default'): void {\n const fragment = document.getXmlFragment(field)\n document.transact(() => {\n if (fragment.length) fragment.delete(0, fragment.length)\n prosemirrorJSONToYXmlFragment(schema, content, fragment)\n })\n}\n\n/** The content of `document` as editor JSON (`{ type: 'doc', content }`), e.g. for `renderHTML`. */\nexport function documentToJSON(document: Y.Doc, field = 'default'): JSONContent {\n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,EAAE,gBAAgB,CAACiG,EAAO;GACjC,OAAO,MAAS;IACd,IAAMH,IAAUH,EAAY9B,CAAI;IAahC,OAZI,CAACiC,KAAWA,EAAQ,oBAAoBjC,KAG1C,IAAS,IACT,QAAQ,MAAM,0HAA0H,GACxI,qBAAqB,CAACnC,EAAO,eAAeA,EAAO,YAAY,EAAK,CAAC,GAC9D,CAAC,MAENsE,EAAS,IAAIF,CAAO,MAAMjC,MAC5BmC,EAAS,IAAIF,GAASjC,CAAI,GAC1BiC,EAAQ,eAAe,IAElB,CAAC;GACV;EACF,CAAC,CAAC;CACJ;AACF,CAAC;AAQD,SAAgBI,EAAwB,GAA2C;CACjF,OAAO;EACL9G,EAAc,UAAU;GACtB,UAAU+G,EAAQ;GAClB,OAAOA,EAAQ,SAAS;GACxB,cAAc,EAAE,yBAAS,IAAI,IAAI,EAAE;EACrC,CAAC;EACDJ;EACA,GAAII,EAAQ,WAAW,CAAC5E,EAAkB4E,EAAQ,QAAQ,CAAC,IAAI,CAAC;CAClE;AACF;AAOA,SAAgBC,EAAa,GAAiB,GAAsB,GAAgB,IAAQ,WAAiB;CAC3G,IAAMC,IAAWC,EAAS,eAAeC,CAAK;CAC9C,EAAS,eAAe;EAEtB,AADIF,EAAS,UAAQA,EAAS,OAAO,GAAGA,EAAS,MAAM,GACvDG,EAA8BC,GAAQC,GAASL,CAAQ;CACzD,CAAC;AACH;AAGA,SAAgBM,EAAe,GAAiB,IAAQ,WAAwB;CAC9E,OAAOC,EAA8BN,EAAS,eAAeC,CAAK,CAAC;AACrE"}
|
|
@@ -519,6 +519,8 @@ var i = (e) => e.map(([e, t]) => `${e}:${t};`).join(""), a = [
|
|
|
519
519
|
searchWidth: "180px",
|
|
520
520
|
rowHeight: "33px",
|
|
521
521
|
headerHeight: "33px",
|
|
522
|
+
loadingHeight: "calc(var(--me-database-row-height) * 4 + 5em)",
|
|
523
|
+
loadingBodyHeight: "calc(var(--me-database-row-height) * 4)",
|
|
522
524
|
footerHeight: "33px",
|
|
523
525
|
groupHeaderHeight: "40px",
|
|
524
526
|
headerColor: n("color.textMuted"),
|
|
@@ -719,25 +721,38 @@ function h() {
|
|
|
719
721
|
"}"
|
|
720
722
|
].join("\n");
|
|
721
723
|
}
|
|
722
|
-
|
|
724
|
+
var g = /[{};<>\\]|\/\*|\*\//;
|
|
725
|
+
function _(e) {
|
|
726
|
+
let t = "";
|
|
727
|
+
for (let n of e) t ? n === t && (t = "") : (n === "\"" || n === "'") && (t = n);
|
|
728
|
+
return t !== "";
|
|
729
|
+
}
|
|
730
|
+
var v = (e) => g.test(e) || _(e), y = () => typeof process < "u" && process.env.NODE_ENV !== "production";
|
|
731
|
+
function b(e) {
|
|
732
|
+
return e.filter(([e, t]) => {
|
|
733
|
+
let n = !v(e) && !v(t);
|
|
734
|
+
return !n && y() && console.warn(`[mei-editor] token "${e}" dropped: its name or value is not safe in CSS ({ } ; < > \\ comments, unclosed quotes)`), n;
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function x(e) {
|
|
723
738
|
let { components: t, ...n } = e;
|
|
724
|
-
return [...r(n), ...r(t ?? {})];
|
|
739
|
+
return b([...r(n), ...r(t ?? {})]);
|
|
725
740
|
}
|
|
726
|
-
function
|
|
741
|
+
function S(e, t = ".me-scope") {
|
|
727
742
|
if (!e) return "";
|
|
728
|
-
let { dark: n, ...r } = e, a =
|
|
743
|
+
let { dark: n, ...r } = e, a = x(r), o = n ? x(n) : [];
|
|
729
744
|
return [a.length ? `${t}{${i(a)}}` : "", o.length ? `${m(t).join(",")}{${i(o)}}` : ""].filter(Boolean).join("\n");
|
|
730
745
|
}
|
|
731
|
-
function
|
|
746
|
+
function C(e, t) {
|
|
732
747
|
if (typeof document > "u") return;
|
|
733
748
|
let n = document.getElementById(e);
|
|
734
749
|
if (!t) return n?.remove();
|
|
735
|
-
n || (n = document.createElement("style"), n.id = e, e ===
|
|
750
|
+
n || (n = document.createElement("style"), n.id = e, e === w ? document.head.prepend(n) : document.head.appendChild(n)), n.textContent !== t && (n.textContent = t);
|
|
736
751
|
}
|
|
737
|
-
var
|
|
738
|
-
function
|
|
739
|
-
typeof document > "u" || document.getElementById(
|
|
752
|
+
var w = "mei-editor-tokens";
|
|
753
|
+
function T() {
|
|
754
|
+
typeof document > "u" || document.getElementById(w) || C(w, h());
|
|
740
755
|
}
|
|
741
|
-
export { a,
|
|
756
|
+
export { S as a, d as c, l as d, t as f, T as i, o as l, r as m, h as n, b as o, i as p, C as r, a as s, f as t, u };
|
|
742
757
|
|
|
743
|
-
//# sourceMappingURL=css-
|
|
758
|
+
//# sourceMappingURL=css-Cf_w91Fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-Cf_w91Fs.js","names":["r","kebab","s","cssVar","path","ref","flatten","tree","key","value","prefix","declarations","pairs","k","v","PALETTE_NAMES","primitive","palette","name","mode","semanticBase","semanticLight","semanticDark","component","LAYER","LAYER_ORDER","darkSelectors","scope","baseTokensCss","light","dark","tints","UNSAFE_CSS","unbalancedQuotes","open","ch","unsafeCss","isDev","safePairs","ok","overridePairs","semantic","tokens","components","overridesCss","rest","darkPairs","injectStyle","el","id","css","BASE_STYLE_ID","installBaseTokens"],"sources":["../src/theme/define.ts","../src/theme/tokens.ts","../src/theme/css.ts"],"sourcesContent":["/** Helpers to turn token objects into CSS custom properties. No values live here. */\n\nexport interface TokenTree { [key: string]: string | TokenTree }\n\nexport type DeepPartial<T> = { [K in keyof T]?: T[K] extends string ? string : DeepPartial<T[K]> }\n\n/** Loosens literal string types so token objects can be compared/overridden. */\nexport type Widen<T> = { [K in keyof T]: T[K] extends string ? string : Widen<T[K]> }\n\nconst kebab = (s: string) => s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()\n\n/** `'menu.itemHeight'` → `'--me-menu-item-height'` */\nexport const cssVar = (path: string) => `--me-${path.split('.').map(kebab).join('-')}`\n\n/** Reference another token: `ref('color.text')` → `'var(--me-color-text)'` */\nexport const ref = (path: string) => `var(${cssVar(path)})`\n\n/** Flattens a token tree into `[cssVarName, value]` pairs. */\nexport function flatten(tree: TokenTree, prefix = ''): [string, string][] {\n return Object.entries(tree).flatMap(([key, value]) => {\n const path = prefix ? `${prefix}.${key}` : key\n return typeof value === 'string' ? [[cssVar(path), value] as [string, string]] : flatten(value, path)\n })\n}\n\nexport const declarations = (pairs: [string, string][]) => pairs.map(([k, v]) => `${k}:${v};`).join('')\n","/**\n * ─────────────────────────────────────────────────────────────────────────────\n * THE single source of every visual value in @toantranmei/editor.\n * Stylesheets in src/styles only reference these tokens via var(--me-…);\n * `pnpm check:styles` fails the build if a raw value sneaks in elsewhere.\n *\n * Three tiers:\n * 1. primitive – raw values (colors, scales). Only referenced by tiers 2–3.\n * 2. semantic – meaning (text, surface, accent…). Has light + dark variants.\n * 3. component – per-part knobs (menu item height, callout padding…).\n *\n * CSS variable name = `--me-` + path in kebab-case, e.g. component.menu.itemHeight\n * → --me-menu-item-height, semantic color.textMuted → --me-color-text-muted.\n * ─────────────────────────────────────────────────────────────────────────────\n */\nimport { ref as r } from './define'\n\n// ── 1. Primitive ──────────────────────────────────────────────────────────────\n\n/** Notion's content palette. Names are what documents store (`data-text-color=\"red\"`). */\nexport const PALETTE_NAMES = ['gray', 'brown', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink', 'red'] as const\nexport type PaletteName = typeof PALETTE_NAMES[number]\n\nexport const primitive = {\n white: '#ffffff',\n black: '#000000',\n gray: {\n 50: '#f7f6f3',\n 100: '#f1f1ef',\n 200: '#e9e9e7',\n 300: '#d4d4d4',\n 400: '#9b9a97',\n 500: '#787774',\n 800: '#37352f',\n 850: '#2f2f2f',\n 900: '#252525',\n 925: '#202020',\n 950: '#191919',\n },\n azure: { 400: '#4a9ff5', 500: '#2383e2', 600: '#0077d4' },\n /** Content palette: `light`/`dark` × `text`/`bg`. */\n tint: {\n gray: { lightText: '#787774', lightBg: '#f1f1ef', darkText: '#9b9b9b', darkBg: '#2f2f2f' },\n brown: { lightText: '#9f6b53', lightBg: '#f4eeee', darkText: '#ba856f', darkBg: '#4a3228' },\n orange: { lightText: '#d9730d', lightBg: '#fbecdd', darkText: '#c77d48', darkBg: '#5c3b23' },\n yellow: { lightText: '#cb912f', lightBg: '#fbf3db', darkText: '#ca984d', darkBg: '#564328' },\n green: { lightText: '#448361', lightBg: '#edf3ec', darkText: '#529e72', darkBg: '#243d30' },\n blue: { lightText: '#337ea9', lightBg: '#e7f3f8', darkText: '#5e87c9', darkBg: '#143a4e' },\n purple: { lightText: '#9065b0', lightBg: '#f6f3f9', darkText: '#9d68d3', darkBg: '#3c2d49' },\n pink: { lightText: '#c14c8a', lightBg: '#faf1f5', darkText: '#d15796', darkBg: '#4e2c3c' },\n red: { lightText: '#d44c47', lightBg: '#fdebec', darkText: '#df5452', darkBg: '#522e2a' },\n } satisfies Record<PaletteName, Record<string, string>>,\n space: { 0: '0', 1: '2px', 2: '4px', 3: '6px', 4: '8px', 5: '12px', 6: '14px', 7: '16px', 8: '24px', 9: '32px' },\n rounded: { xs: '3px', sm: '4px', md: '6px', lg: '8px', full: '9999px' },\n fontSize: { xs: '12px', sm: '14px', md: '16px', lg: '20px' },\n fontWeight: { regular: '400', medium: '500', semibold: '600' },\n lineHeight: { tight: '1.2', snug: '1.3', normal: '1.5', relaxed: '1.6' },\n borderWidth: { thin: '1px', medium: '2px', thick: '3px', heavy: '4px' },\n duration: { fast: '120ms', normal: '150ms' },\n fontFamily: {\n sans: 'ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Helvetica, \"Apple Color Emoji\", Arial, sans-serif, \"Segoe UI Emoji\"',\n mono: '\"SFMono-Regular\", Menlo, Consolas, monospace',\n },\n}\n\n// ── 2. Semantic ───────────────────────────────────────────────────────────────\n\nconst palette = (mode: 'light' | 'dark') => Object.fromEntries(PALETTE_NAMES.map(name => [name, {\n text: r(`tint.${name}.${mode}Text`),\n bg: r(`tint.${name}.${mode}Bg`),\n}])) as Record<PaletteName, { text: string, bg: string }>\n\n/** Mode-independent semantic tokens. */\nexport const semanticBase = {\n font: {\n sans: r('fontFamily.sans'),\n mono: r('fontFamily.mono'),\n size: r('fontSize.md'),\n lineHeight: r('lineHeight.normal'),\n },\n radius: { sm: r('rounded.sm'), md: r('rounded.md'), lg: r('rounded.lg') },\n}\n\nexport const semanticLight = {\n color: {\n text: r('gray.800'),\n textMuted: r('gray.500'),\n textFaint: r('gray.400'),\n bg: r('white'),\n elevated: r('white'),\n surface: r('gray.50'),\n hover: 'rgba(55, 53, 47, 0.08)',\n border: r('gray.200'),\n accent: r('azure.500'),\n accentHover: r('azure.600'),\n onAccent: r('white'),\n selection: 'rgba(35, 131, 226, 0.28)',\n blockSelected: 'rgba(35, 131, 226, 0.14)',\n danger: r('tint.red.lightText'),\n handle: '#b9b9b7',\n inlineCodeText: '#eb5757',\n inlineCodeBg: 'rgba(135, 131, 120, 0.15)',\n overlay: 'rgba(0, 0, 0, 0.5)',\n },\n shadow: {\n popover: 'rgba(15, 15, 15, 0.05) 0 0 0 1px, rgba(15, 15, 15, 0.1) 0 3px 6px, rgba(15, 15, 15, 0.2) 0 9px 24px',\n },\n palette: palette('light'),\n syntax: {\n comment: '#8e908c',\n keyword: '#8959a8',\n string: '#718c00',\n number: '#f5871f',\n title: '#4271ae',\n variable: '#c82829',\n meta: '#3e999f',\n },\n}\n\nexport const semanticDark: typeof semanticLight = {\n color: {\n text: r('gray.300'),\n textMuted: '#9b9b9b',\n textFaint: '#7f7f7f',\n bg: r('gray.950'),\n elevated: r('gray.900'),\n surface: r('gray.925'),\n hover: 'rgba(255, 255, 255, 0.055)',\n border: r('gray.850'),\n accent: r('azure.400'),\n accentHover: r('azure.500'),\n onAccent: r('white'),\n selection: 'rgba(35, 131, 226, 0.4)',\n blockSelected: 'rgba(35, 131, 226, 0.22)',\n danger: r('tint.red.darkText'),\n handle: '#5a5a5a',\n inlineCodeText: '#ff7369',\n inlineCodeBg: 'rgba(135, 131, 120, 0.15)',\n overlay: 'rgba(255, 255, 255, 0.5)',\n },\n shadow: {\n popover: 'rgba(255, 255, 255, 0.094) 0 0 0 1px, rgba(0, 0, 0, 0.3) 0 3px 6px, rgba(0, 0, 0, 0.4) 0 9px 24px',\n },\n palette: palette('dark'),\n syntax: {\n comment: '#7f848e',\n keyword: '#c678dd',\n string: '#98c379',\n number: '#d19a66',\n title: '#61afef',\n variable: '#e06c75',\n meta: '#56b6c2',\n },\n}\n\n// ── 3. Component ──────────────────────────────────────────────────────────────\n\nexport const component = {\n /** Editor root. `bg` is transparent so it blends into the page; a forced mode paints `forcedBg`. */\n editor: { bg: 'transparent', forcedBg: r('color.bg') },\n icon: { size: r('fontSize.md'), stroke: '1.75' },\n popover: { bg: r('color.elevated'), radius: r('radius.lg'), shadow: r('shadow.popover'), padding: r('space.2'), offset: r('space.4') },\n menu: {\n itemGap: r('space.4'),\n itemPaddingX: r('space.4'),\n itemPaddingY: r('space.2'),\n itemRadius: r('radius.md'),\n itemHover: r('color.hover'),\n iconBox: '28px',\n iconRadius: r('radius.md'),\n iconBorder: r('color.border'),\n titleSize: r('fontSize.sm'),\n descriptionSize: r('fontSize.xs'),\n descriptionColor: r('color.textMuted'),\n labelSize: r('fontSize.xs'),\n labelWeight: r('fontWeight.medium'),\n labelColor: r('color.textMuted'),\n shortcutColor: r('color.textFaint'),\n width: '288px',\n submenuWidth: '224px',\n maxHeight: '320px',\n },\n toolbar: {\n buttonSize: '28px',\n buttonRadius: r('radius.sm'),\n buttonHover: r('color.hover'),\n activeColor: r('color.accent'),\n dividerColor: r('color.border'),\n linkFormWidth: '320px',\n },\n button: {\n height: '32px',\n paddingX: r('space.5'),\n radius: r('radius.md'),\n fontSize: r('fontSize.sm'),\n border: r('color.border'),\n bg: r('color.bg'),\n hoverBg: r('color.surface'),\n primaryBg: r('color.accent'),\n primaryHoverBg: r('color.accentHover'),\n primaryText: r('color.onAccent'),\n floatingBg: r('color.elevated'),\n floatingHoverBg: r('color.surface'),\n floatingShadow: r('shadow.popover'),\n disabledOpacity: '0.5',\n },\n input: {\n height: '32px',\n paddingX: r('space.4'),\n radius: r('radius.md'),\n fontSize: r('fontSize.sm'),\n border: r('color.border'),\n focusBorder: r('color.accent'),\n focusRing: 'color-mix(in srgb, var(--me-color-accent) 20%, transparent)',\n },\n handle: {\n color: r('color.handle'),\n hoverColor: r('color.textMuted'),\n hoverBg: r('color.hover'),\n /** \"+\" button (square) and the ⋮⋮ grip, like Notion. */\n buttonWidth: '24px',\n buttonHeight: '24px',\n gripWidth: '18px',\n iconSize: '18px',\n radius: r('radius.sm'),\n gap: r('space.1'),\n },\n /**\n * Block rhythm, two levels like Notion: text blocks (paragraphs, lists, quotes,\n * toggles) sit close (`gap` + `paddingY`); every boxed/media block (code, callout,\n * table, image, embed, HTML, file, math, TOC, columns) uses `boxSpacing`.\n */\n block: {\n paddingY: '3px',\n paddingX: r('space.1'),\n gap: '1px',\n boxSpacing: r('space.4'),\n radius: r('radius.sm'),\n minHeight: 'calc(var(--me-font-line-height) * 1em)',\n /** Tint over any selected block (text, boxes and media alike). */\n selectedBg: r('color.blockSelected'),\n },\n /** Shared look of boxed blocks: code, callout, file rows, upload placeholders, HTML. */\n box: {\n bg: r('color.surface'),\n border: r('color.border'),\n radius: r('radius.md'),\n padding: '12px 16px',\n paddingCompact: '6px 10px',\n /** Header row inside a box (code language + copy, HTML name + tabs). */\n barPadding: '8px 10px 0 14px',\n barColor: r('color.textMuted'),\n barFontSize: r('fontSize.xs'),\n barIconSize: r('fontSize.sm'),\n barButtonSize: '24px',\n },\n /** Underlined tabs (upload placeholders, HTML Code / Preview). */\n tabs: {\n gap: r('space.7'),\n fontSize: r('fontSize.sm'),\n color: r('color.textMuted'),\n activeColor: r('color.text'),\n indicator: r('borderWidth.medium'),\n paddingBottom: r('space.4'),\n },\n heading: {\n weight: r('fontWeight.semibold'),\n lineHeight: r('lineHeight.snug'),\n h1Size: '1.875em',\n h2Size: '1.5em',\n h3Size: '1.25em',\n h4Size: '1.1em',\n h1Margin: '1.1em',\n h2Margin: '0.9em',\n h3Margin: '0.6em',\n h4Margin: '0.5em',\n /** Space kept above a heading scrolled to from the outline/TOC (room for sticky app headers). */\n scrollMargin: '80px',\n },\n link: { underline: 'color-mix(in srgb, var(--me-color-text) 40%, transparent)', underlineHover: r('color.text') },\n inlineCode: { color: r('color.inlineCodeText'), bg: r('color.inlineCodeBg'), radius: r('radius.sm'), fontSize: '85%', padding: '0.2em 0.4em' },\n list: { indent: '1.6em' },\n todo: { checkSize: r('fontSize.md'), checkColor: r('color.accent'), doneColor: r('color.textFaint') },\n quote: { borderWidth: r('borderWidth.thick'), borderColor: 'currentColor', paddingLeft: r('space.6') },\n divider: { color: r('color.border'), spacing: r('space.6') },\n callout: {\n /** Left matches top, so the icon sits evenly from both edges; right/bottom follow `box.padding`. */\n padding: '12px 16px 12px 12px',\n gap: r('space.4'),\n iconSize: r('fontSize.lg'),\n iconBox: '28px',\n defaultBg: r('palette.gray.bg'),\n pickerWidth: '240px',\n },\n toggle: { arrowColor: r('color.text'), buttonSize: '24px', headingArrowOffset: 'calc(var(--me-block-padding-y) + 0.15em)' },\n columns: { gap: r('space.9') },\n code: { fontSize: '85%', lineHeight: r('lineHeight.relaxed') },\n table: { border: r('color.border'), headerBg: r('color.surface'), cellPadding: '6px 8px', cellMinWidth: '80px', selected: r('color.blockSelected'), resizeHandle: r('color.accent') },\n media: {\n captionColor: r('color.textMuted'),\n captionSize: r('fontSize.sm'),\n resizeHandleBg: r('color.overlay'),\n errorColor: r('color.danger'),\n },\n dropIndicator: { color: 'rgba(35, 131, 226, 0.5)', height: r('borderWidth.heavy') },\n html: {\n /** User HTML usually assumes a white page, also in dark mode. */\n frameBg: '#fff',\n editorBg: r('color.bg'),\n editorFont: r('font.mono'),\n editorFontSize: '13px',\n editorPadding: r('space.5'),\n coverBg: 'rgba(15, 15, 15, 0.08)',\n },\n /** Full-screen views (HTML block expand, image zoom). */\n modal: {\n backdrop: 'rgba(15, 15, 15, 0.6)',\n /** Image viewer: darker, so the photo stands out. */\n backdropStrong: 'rgba(15, 15, 15, 0.88)',\n inset: '4vh 4vw',\n toolbarOffset: r('space.7'),\n },\n image: {\n /** Hover toolbar inset from the image's top-right corner. */\n toolbarInset: r('space.3'),\n menuWidth: '208px',\n cropDim: 'rgba(15, 15, 15, 0.55)',\n cropBorder: r('white'),\n cropHandle: '10px',\n cropHandleBg: r('white'),\n cropHandleBorder: 'rgba(15, 15, 15, 0.35)',\n },\n outline: {\n /** Distance from the viewport's right edge and top. */\n right: r('space.7'),\n top: '30vh',\n barColor: r('color.border'),\n barActive: r('color.textMuted'),\n barHeight: r('borderWidth.medium'),\n barGap: r('space.3'),\n barWidth: '16px',\n panelWidth: '240px',\n panelMaxHeight: '60vh',\n itemColor: r('color.textMuted'),\n itemActive: r('color.accent'),\n indent: r('space.5'),\n },\n tableControls: {\n gripSize: '12px',\n gripBg: r('color.elevated'),\n gripColor: r('color.textFaint'),\n gripHoverBg: r('color.hover'),\n addSize: '18px',\n addBg: r('color.surface'),\n addHoverBg: r('color.hover'),\n radius: r('radius.sm'),\n },\n toc: { itemColor: r('color.textMuted'), itemHover: r('color.hover'), indent: r('space.7'), padding: r('space.2') },\n math: { editorWidth: '360px', emptyColor: r('color.textFaint') },\n emojiMenu: { cell: '32px', columns: '8', size: r('fontSize.lg') },\n file: { sizeColor: r('color.textFaint') },\n mention: {\n color: r('color.text'),\n bg: r('color.hover'),\n hoverBg: 'color-mix(in srgb, var(--me-color-text) 14%, transparent)',\n radius: r('radius.sm'),\n padding: '0 3px',\n pageUnderline: r('color.textFaint'),\n avatarRadius: r('rounded.full'),\n avatarSize: '1.1em',\n popoverWidth: '280px',\n },\n /** Sub-page / link-to-page rows (`@toantranmei/page-block`). */\n pageLink: {\n color: r('color.text'),\n hoverBg: r('color.hover'),\n radius: r('radius.sm'),\n padding: '3px 2px',\n gap: r('space.3'),\n fontWeight: r('fontWeight.medium'),\n iconSize: '1.2em',\n iconColor: r('color.textMuted'),\n underline: r('color.textFaint'),\n underlineHover: r('color.text'),\n mutedColor: r('color.textMuted'),\n missingColor: r('color.textFaint'),\n popoverWidth: '320px',\n },\n /** Database block (`@toantranmei/database-block`): header, tabs, toolbar, table and the other views. */\n database: {\n gap: r('space.4'),\n titleSize: '1.5em',\n titleWeight: r('fontWeight.semibold'),\n titleColor: r('color.text'),\n titlePlaceholder: r('color.textFaint'),\n fontSize: r('fontSize.sm'),\n mutedColor: r('color.textMuted'),\n faintColor: r('color.textFaint'),\n border: r('color.border'),\n radius: r('radius.sm'),\n hoverBg: r('color.hover'),\n bg: r('color.bg'),\n /** Scroll area of an inline database; a full-page one uses `fullHeight`. */\n maxHeight: '520px',\n fullHeight: '75vh',\n /** Tabs + toolbar row. */\n tabGap: r('space.1'),\n tabPadding: '4px 8px',\n tabActiveColor: r('color.text'),\n tabIndicator: r('borderWidth.medium'),\n toolbarGap: r('space.2'),\n toolbarButtonActive: r('color.accent'),\n searchWidth: '180px',\n /** Table. Row/header heights are also read by the virtualizer (px). */\n rowHeight: '33px',\n headerHeight: '33px',\n /** Space kept while a database loads (title + tabs + header + 3 rows), so the page doesn't jump. */\n loadingHeight: 'calc(var(--me-database-row-height) * 4 + 5em)',\n /** Same, below the title and tabs (views still loading). */\n loadingBodyHeight: 'calc(var(--me-database-row-height) * 4)',\n footerHeight: '33px',\n groupHeaderHeight: '40px',\n headerColor: r('color.textMuted'),\n headerBg: r('color.bg'),\n headerWeight: r('fontWeight.regular'),\n cellPaddingX: r('space.4'),\n cellMinWidth: '60px',\n cellDefaultWidth: '180px',\n selectColWidth: '32px',\n handleColWidth: '20px',\n activeRing: r('color.accent'),\n activeRingWidth: r('borderWidth.medium'),\n selectedBg: r('color.blockSelected'),\n placeholderBg: r('color.surface'),\n placeholderRadius: r('radius.sm'),\n resizeHandle: r('color.accent'),\n resizeHandleWidth: r('borderWidth.thick'),\n dropIndicator: r('color.accent'),\n dropIndicatorWidth: r('borderWidth.medium'),\n editorBg: r('color.elevated'),\n editorShadow: r('shadow.popover'),\n editorMinHeight: '120px',\n readOnlyColor: r('color.textMuted'),\n linkColor: r('color.text'),\n aggregateColor: r('color.textMuted'),\n errorColor: r('color.danger'),\n /** Select / multi-select / status / person / relation chips. */\n tagHeight: '20px',\n tagPadding: '0 6px',\n tagRadius: r('radius.sm'),\n tagGap: r('space.2'),\n tagFontSize: r('fontSize.sm'),\n defaultTagBg: r('palette.gray.bg'),\n defaultTagText: r('color.text'),\n swatchSize: r('fontSize.md'),\n avatarSize: '18px',\n avatarRadius: r('rounded.full'),\n /** Popovers: menus, filter / sort builders, property editor. */\n menuWidth: '260px',\n builderWidth: '560px',\n formulaHeight: '96px',\n dangerColor: r('color.danger'),\n warningBg: r('palette.yellow.bg'),\n warningText: r('palette.yellow.text'),\n /** Board. */\n columnWidth: '264px',\n columnGap: r('space.5'),\n columnBg: r('color.surface'),\n cardBg: r('color.elevated'),\n cardBorder: r('color.border'),\n cardRadius: r('radius.md'),\n cardPadding: '8px 10px',\n cardGap: r('space.3'),\n cardShadow: 'rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.1) 0 2px 4px',\n dropBg: 'color-mix(in srgb, var(--me-color-accent) 10%, transparent)',\n /** Calendar. */\n calendarCellHeight: '116px',\n calendarTodayBg: r('color.accent'),\n calendarTodayText: r('color.onAccent'),\n calendarOutsideBg: r('color.surface'),\n /** Timeline: width of one day at each scale (px, read by the view). */\n timelineDay: '40px',\n timelineWeek: '16px',\n timelineMonth: '5px',\n timelineRowHeight: '36px',\n timelineLabelWidth: '200px',\n barBg: 'color-mix(in srgb, var(--me-color-accent) 18%, var(--me-color-bg))',\n barBorder: r('color.accent'),\n barRadius: r('radius.md'),\n barHeight: '24px',\n todayLine: r('palette.red.text'),\n /** Gallery card widths per size, cover height. */\n gallerySmall: '180px',\n galleryMedium: '260px',\n galleryLarge: '340px',\n coverHeight: '148px',\n coverBg: r('color.surface'),\n /** Pivot. */\n pivotHeaderBg: r('color.surface'),\n pivotTotalWeight: r('fontWeight.semibold'),\n /** Full-page database link row. */\n linkIconSize: '1.2em',\n },\n /** Charts (`@toantranmei/chart-block`), also used by the database chart view. */\n chart: {\n height: '320px',\n padding: r('space.5'),\n text: r('color.textMuted'),\n title: r('color.text'),\n axis: r('color.border'),\n splitLine: r('color.border'),\n tooltipBg: r('color.elevated'),\n tooltipText: r('color.text'),\n tooltipBorder: r('color.border'),\n fontSize: r('fontSize.xs'),\n fontFamily: r('font.sans'),\n series1: r('palette.blue.text'),\n series2: r('palette.orange.text'),\n series3: r('palette.green.text'),\n series4: r('palette.purple.text'),\n series5: r('palette.red.text'),\n series6: r('palette.yellow.text'),\n series7: r('palette.pink.text'),\n series8: r('palette.brown.text'),\n series9: r('palette.gray.text'),\n /** Standalone block: data grid and config panel. */\n cellWidth: '120px',\n gridMaxHeight: '260px',\n panelGap: r('space.4'),\n emptyColor: r('color.textFaint'),\n },\n /** Comment highlights, gutter badges and the side panel (`@toantranmei/comments`). */\n comments: {\n highlight: 'color-mix(in srgb, var(--me-palette-yellow-text) 22%, transparent)',\n highlightActive: 'color-mix(in srgb, var(--me-palette-yellow-text) 45%, transparent)',\n underline: r('palette.yellow.text'),\n badgeBg: r('color.surface'),\n badgeColor: r('color.textMuted'),\n badgeActiveBg: r('palette.yellow.bg'),\n badgeActiveColor: r('palette.yellow.text'),\n badgeSize: '22px',\n badgeOffset: '-36px',\n badgeFontSize: r('fontSize.xs'),\n panelWidth: '340px',\n panelBg: r('color.bg'),\n panelBorder: r('color.border'),\n panelPadding: r('space.5'),\n threadGap: r('space.4'),\n threadRadius: r('radius.lg'),\n threadBorder: r('color.border'),\n threadActiveBorder: r('palette.yellow.text'),\n threadPadding: r('space.5'),\n quoteColor: r('color.textMuted'),\n quoteBorder: r('palette.yellow.text'),\n avatarSize: '24px',\n metaColor: r('color.textFaint'),\n metaFontSize: r('fontSize.xs'),\n bodyFontSize: r('fontSize.sm'),\n composerMinHeight: '36px',\n composerBg: r('color.surface'),\n composerPadding: '6px 8px',\n composerWidth: '320px',\n },\n /** Synced block frame (`@toantranmei/synced-block`). */\n synced: {\n border: 'color-mix(in srgb, var(--me-palette-red-text) 55%, transparent)',\n borderWidth: r('borderWidth.medium'),\n radius: r('radius.md'),\n padding: '2px 4px',\n labelColor: r('palette.red.text'),\n labelBg: r('color.bg'),\n labelFontSize: r('fontSize.xs'),\n labelPadding: '0 6px',\n labelOffset: '-10px',\n hoverBorder: r('palette.red.text'),\n emptyColor: r('color.textFaint'),\n gap: r('space.3'),\n },\n datepicker: {\n width: '264px',\n cell: '34px',\n todayColor: r('color.accent'),\n selectedBg: r('color.accent'),\n selectedText: r('color.onAccent'),\n rangeBg: 'color-mix(in srgb, var(--me-color-accent) 18%, transparent)',\n outsideColor: r('color.textFaint'),\n inputBg: r('color.surface'),\n },\n switch: { width: '28px', height: '16px', knob: '12px', off: r('color.border'), on: r('color.accent'), knobColor: r('color.bg') },\n unknown: { color: r('color.textMuted'), invalidBorder: r('palette.red.text'), invalidColor: r('palette.red.text') },\n /** Handle tooltip and toast: dark in both modes, like Notion. */\n tooltip: {\n bg: '#0f0f0f',\n text: 'rgba(255, 255, 255, 0.9)',\n hint: 'rgba(206, 205, 202, 0.6)',\n radius: r('radius.sm'),\n padding: '4px 8px',\n fontSize: r('fontSize.xs'),\n offset: r('space.3'),\n shadow: 'rgba(15, 15, 15, 0.1) 0 3px 6px',\n },\n}\n\n/** Everything a consumer can override, with autocomplete. */\nexport interface ThemeTokens {\n color?: Partial<Record<keyof typeof semanticLight.color, string>>\n shadow?: Partial<Record<keyof typeof semanticLight.shadow, string>>\n palette?: Partial<Record<PaletteName, { text?: string, bg?: string }>>\n syntax?: Partial<Record<keyof typeof semanticLight.syntax, string>>\n font?: Partial<Record<keyof typeof semanticBase.font, string>>\n radius?: Partial<Record<keyof typeof semanticBase.radius, string>>\n /** Per-part knobs, e.g. `{ menu: { itemRadius: '8px' } }`. */\n components?: { [G in keyof typeof component]?: Partial<Record<keyof typeof component[G], string>> }\n /** Overrides applied only in dark mode. */\n dark?: Pick<ThemeTokens, 'color' | 'shadow' | 'palette' | 'syntax'>\n}\n","import { declarations, flatten, type TokenTree } from './define'\nimport { component, PALETTE_NAMES, primitive, semanticBase, semanticDark, semanticLight, type ThemeTokens } from './tokens'\n\n/** CSS cascade layer for all library styles; app CSS outside layers always wins. */\nexport const LAYER = 'mei-editor'\n\n/**\n * Layer order declared wherever library CSS loads. Whichever sheet the browser sees\n * first fixes the order, so every entry point repeats it: resets (`base`, e.g.\n * Tailwind preflight) lose to the editor, while app `components`/`utilities` win.\n */\nexport const LAYER_ORDER = `@layer theme, base, ${LAYER}, components, utilities;`\n\nconst darkSelectors = (scope: string) => [\n `html.dark ${scope}:not(.me-light)`,\n `${scope}.me-dark`,\n]\n\n/** Default tokens (light + dark) plus palette mappings, generated from tokens.ts. */\nexport function baseTokensCss(): string {\n const light = [\n ...flatten(primitive as unknown as TokenTree),\n ...flatten(semanticBase),\n ...flatten(semanticLight as unknown as TokenTree),\n ...flatten(component),\n ]\n const dark = flatten(semanticDark as unknown as TokenTree)\n\n // Colors are stored by name in documents; map each name to its palette tokens.\n const tints = PALETTE_NAMES.map(name => [\n `:where(.me-scope) [data-text-color=\"${name}\"]{color:var(--me-palette-${name}-text);}`,\n `:where(.me-scope) [data-bg-color=\"${name}\"]{background-color:var(--me-palette-${name}-bg);}`,\n `:where(.me-scope) [data-color=\"${name}\"]{--me-tint-text:var(--me-palette-${name}-text);--me-tint-bg:var(--me-palette-${name}-bg);}`,\n ].join('\\n')).join('\\n')\n\n return [\n LAYER_ORDER,\n `@layer ${LAYER} {`,\n `:where(.me-scope){${declarations(light)}}`,\n `${darkSelectors('.me-scope').map(s => `:where(${s})`).join(',')}{${declarations(dark)}}`,\n tints,\n '}',\n ].join('\\n')\n}\n\n// A value or name that could leave its declaration (or the <style>) is dropped: braces, `;`, `<>`, comments\n// (`/*` could swallow the next rules) and backslash escapes (`\\7d` is a `}`).\nconst UNSAFE_CSS = /[{};<>\\\\]|\\/\\*|\\*\\//\n\n/** True when a quote is never closed (it would run a string over the closing brace). `\"it's\"` is balanced. */\nfunction unbalancedQuotes(v: string): boolean {\n let open = ''\n for (const ch of v) {\n if (open) {\n if (ch === open) open = ''\n }\n else if (ch === '\"' || ch === \"'\") open = ch\n }\n return open !== ''\n}\n\nexport const unsafeCss = (v: string) => UNSAFE_CSS.test(v) || unbalancedQuotes(v)\n\nconst isDev = () => typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production'\n\n/** Keeps the safe `[name, value]` pairs; warns in development about each dropped one. */\nexport function safePairs(pairs: [string, string][]): [string, string][] {\n return pairs.filter(([k, v]) => {\n const ok = !unsafeCss(k) && !unsafeCss(v)\n if (!ok && isDev()) console.warn(`[mei-editor] token \"${k}\" dropped: its name or value is not safe in CSS ({ } ; < > \\\\ comments, unclosed quotes)`)\n return ok\n })\n}\n\nfunction overridePairs(tokens: Omit<ThemeTokens, 'dark'>): [string, string][] {\n const { components, ...semantic } = tokens\n return safePairs([...flatten(semantic as TokenTree), ...flatten((components ?? {}) as TokenTree)])\n}\n\n/**\n * CSS that applies token overrides to every editor matching `scope`\n * (unlayered, so it beats the defaults). Returns '' when there is nothing to override.\n */\nexport function overridesCss(tokens: ThemeTokens | undefined, scope = '.me-scope'): string {\n if (!tokens) return ''\n const { dark, ...rest } = tokens\n const light = overridePairs(rest)\n const darkPairs = dark ? overridePairs(dark) : []\n return [\n light.length ? `${scope}{${declarations(light)}}` : '',\n darkPairs.length ? `${darkSelectors(scope).join(',')}{${declarations(darkPairs)}}` : '',\n ].filter(Boolean).join('\\n')\n}\n\n/** Adds or replaces a <style> tag in <head>. Pass empty css to remove it. */\nexport function injectStyle(id: string, css: string) {\n if (typeof document === 'undefined') return\n let el = document.getElementById(id) as HTMLStyleElement | null\n if (!css) return el?.remove()\n if (!el) {\n el = document.createElement('style')\n el.id = id\n // Base tokens go first so later sheets (and app CSS) can override them.\n if (id === BASE_STYLE_ID) document.head.prepend(el)\n else document.head.appendChild(el)\n }\n if (el.textContent !== css) el.textContent = css\n}\n\nconst BASE_STYLE_ID = 'mei-editor-tokens'\n\n/** Injects the default tokens once per document. */\nexport function installBaseTokens() {\n if (typeof document === 'undefined' || document.getElementById(BASE_STYLE_ID)) return\n injectStyle(BASE_STYLE_ID, baseTokensCss())\n}\n"],"mappings":";AASA,IAAMC,KAAS,MAAcC,EAAE,QAAQ,sBAAsB,OAAO,CAAC,CAAC,YAAY,GAGrEC,KAAU,MAAiB,QAAQC,EAAK,MAAM,GAAG,CAAC,CAAC,IAAIH,CAAK,CAAC,CAAC,KAAK,GAAG,KAGtEI,KAAO,MAAiB,OAAOF,EAAOC,CAAI,EAAE;AAGzD,SAAgBE,EAAQ,GAAiB,IAAS,IAAwB;CACxE,OAAO,OAAO,QAAQC,CAAI,CAAC,CAAC,SAAS,CAACC,GAAKC,OAAW;EACpD,IAAML,IAAOM,IAAS,GAAGA,EAAO,GAAGF,MAAQA;EAC3C,OAAO,OAAOC,KAAU,WAAW,CAAC,CAACN,EAAOC,CAAI,GAAGK,CAAK,CAAqB,IAAIH,EAAQG,GAAOL,CAAI;CACtG,CAAC;AACH;AAEA,IAAaO,KAAgB,MAA8BC,EAAM,KAAK,CAACC,GAAGC,OAAO,GAAGD,EAAE,GAAGC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,GCLzFC,IAAgB;CAAC;CAAQ;CAAS;CAAU;CAAU;CAAS;CAAQ;CAAU;CAAQ;AAAK,GAG9FC,IAAY;CACvB,OAAO;CACP,OAAO;CACP,MAAM;EACJ,IAAI;EACJ,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;CACP;CACA,OAAO;EAAE,KAAK;EAAW,KAAK;EAAW,KAAK;CAAU;CAExD,MAAM;EACJ,MAAM;GAAE,WAAW;GAAW,SAAS;GAAW,UAAU;GAAW,QAAQ;EAAU;EACzF,OAAO;GAAE,WAAW;GAA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