markloom 0.5.0 → 0.5.1

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.
@@ -660,7 +660,7 @@ var MarkloomAi = (_class = class {
660
660
  this.txOpen = false;
661
661
  this.txBlockId = null;
662
662
  }
663
- /** 整笔撤回事务(= undo) */
663
+ /** 整笔撤回事务(= undo);务必不留 aiDraft 孤儿段 */
664
664
  discard(blockId) {
665
665
  if (this.streamingId === blockId) {
666
666
  _optionalChain([this, 'access', _61 => _61.abort, 'optionalAccess', _62 => _62.abort, 'call', _63 => _63()]);
@@ -672,16 +672,21 @@ var MarkloomAi = (_class = class {
672
672
  }
673
673
  if (this.txOpen && (this.txBlockId === blockId || !this.txBlockId)) {
674
674
  this.rollback();
675
+ this.purgeDrafts(blockId);
675
676
  return;
676
677
  }
678
+ this.purgeDrafts(blockId, true);
679
+ }
680
+ /**
681
+ * 清掉 aiFrom=blockId 的顶层 draft;shell=true 时把 ai 壳也换成空段。
682
+ * discard / 异常恢复共用。
683
+ */
684
+ purgeDrafts(blockId, shell = false) {
677
685
  const ed = this.getEditor();
678
686
  if (!ed)
679
687
  return;
680
- const found = this.findAi(ed, blockId);
681
- if (!found)
682
- return;
683
- const steps = [];
684
688
  const doc = ed.doc;
689
+ const steps = [];
685
690
  const idxs = draftIndices(doc, blockId);
686
691
  for (let i = idxs.length - 1; i >= 0; i--)
687
692
  steps.push({ kind: "spliceChildren", path: [], at: idxs[i], remove: 1, insert: [] });
@@ -692,19 +697,20 @@ var MarkloomAi = (_class = class {
692
697
  shift++;
693
698
  }
694
699
  aiIdx -= shift;
695
- if (aiIdx >= 0) {
700
+ if (shell && aiIdx >= 0) {
696
701
  steps.push({
697
702
  kind: "replaceNode",
698
703
  path: [aiIdx],
699
- node: { type: "paragraph", id: found.node.id, children: [{ text: "" }] }
700
- });
701
- }
702
- if (steps.length) {
703
- ed.dispatch(steps, {
704
- anchor: { path: [Math.max(0, aiIdx), 0, 0] },
705
- head: { path: [Math.max(0, aiIdx), 0, 0] }
704
+ node: { type: "paragraph", id: blockId, children: [{ text: "" }] }
706
705
  });
707
706
  }
707
+ if (!steps.length)
708
+ return;
709
+ const caretAt = Math.max(0, aiIdx >= 0 ? aiIdx : _nullishCoalesce(idxs[0], () => ( 0)));
710
+ ed.dispatch(steps, {
711
+ anchor: { path: [caretAt, 0, 0] },
712
+ head: { path: [caretAt, 0, 0] }
713
+ });
708
714
  }
709
715
  act(blockId, action) {
710
716
  if (action === "accept")
@@ -18,7 +18,7 @@ import {
18
18
  rootEl,
19
19
  startAiWrite,
20
20
  writeSelection
21
- } from "./chunk-JMOJU5EU.js";
21
+ } from "./chunk-FCH7LZFI.js";
22
22
  import {
23
23
  applyAll,
24
24
  arrowCell,
@@ -55,8 +55,10 @@ import {
55
55
  tableColWidths
56
56
  } from "./chunk-MFYF2A6U.js";
57
57
  import {
58
+ collabColor,
59
+ collabInitial,
58
60
  connectCollab
59
- } from "./chunk-6DCI7AL3.js";
61
+ } from "./chunk-4JSJAHTB.js";
60
62
  import {
61
63
  isElement,
62
64
  isInlineAtom,
@@ -1228,11 +1230,32 @@ function mapInput(doc, intent, data, sel, newId4, rules = [], pendingMarks) {
1228
1230
  return { steps: [{ kind: "deleteText", path: leafPath, offset: from - 1, length: 1 }], selection: caret(leafPath.concat(from - 1)) };
1229
1231
  {
1230
1232
  const aiParent = parentPath.length ? nodeAt(doc, parentPath) : null;
1231
- if (aiParent && aiParent.type === "ai" && isEmptyBlock(block) && leafIdx === 0) {
1232
- const node = { type: "paragraph", id: aiParent.id, children: [{ text: "" }] };
1233
+ if (aiParent && aiParent.type === "ai" && aiParent.id && isEmptyBlock(block) && leafIdx === 0) {
1234
+ const aiId = aiParent.id;
1235
+ const steps = [];
1236
+ const draftAt = [];
1237
+ for (let i = 0; i < doc.children.length; i++) {
1238
+ const c = doc.children[i];
1239
+ if (!isText(c) && c.attrs?.aiFrom === aiId)
1240
+ draftAt.push(i);
1241
+ }
1242
+ for (let i = draftAt.length - 1; i >= 0; i--)
1243
+ steps.push({ kind: "spliceChildren", path: [], at: draftAt[i], remove: 1, insert: [] });
1244
+ let aiIdx = parentPath[0] ?? 0;
1245
+ let shift3 = 0;
1246
+ for (const i of draftAt) {
1247
+ if (i < aiIdx)
1248
+ shift3++;
1249
+ }
1250
+ aiIdx -= shift3;
1251
+ steps.push({
1252
+ kind: "replaceNode",
1253
+ path: [aiIdx],
1254
+ node: { type: "paragraph", id: aiId, children: [{ text: "" }] }
1255
+ });
1233
1256
  return {
1234
- steps: [{ kind: "replaceNode", path: parentPath, node }],
1235
- selection: caret([...parentPath, 0, 0])
1257
+ steps,
1258
+ selection: caret([Math.max(0, aiIdx), 0, 0])
1236
1259
  };
1237
1260
  }
1238
1261
  }
@@ -6322,6 +6345,201 @@ function isToday(y, m, day) {
6322
6345
  // src/view/editor.ts
6323
6346
  import { render as render11 } from "preact";
6324
6347
 
6348
+ // src/view/collab-presence.ts
6349
+ function wireOf(sel) {
6350
+ const split2 = (p) => {
6351
+ const path = p.path;
6352
+ if (path.length < 1)
6353
+ return { path: [], offset: 0 };
6354
+ return { path: path.slice(0, -1), offset: path[path.length - 1] };
6355
+ };
6356
+ return { anchor: split2(sel.anchor), head: split2(sel.head) };
6357
+ }
6358
+ function posOf(w) {
6359
+ return { path: w.path.concat(w.offset) };
6360
+ }
6361
+ var CollabPresence = class {
6362
+ host;
6363
+ rail;
6364
+ avatars;
6365
+ carets;
6366
+ peers = [];
6367
+ self = null;
6368
+ presenceTimer = null;
6369
+ lastWire = "";
6370
+ onSel = () => this.schedulePresence();
6371
+ onScroll = () => this.paintCarets();
6372
+ onResize = () => this.paintCarets();
6373
+ destroyed = false;
6374
+ constructor(host) {
6375
+ this.host = host;
6376
+ const root = host.root;
6377
+ if (getComputedStyle(root).position === "static")
6378
+ root.style.position = "relative";
6379
+ this.rail = document.createElement("div");
6380
+ this.rail.className = "markloom-collab-rail";
6381
+ this.rail.setAttribute("contenteditable", "false");
6382
+ this.avatars = document.createElement("div");
6383
+ this.avatars.className = "markloom-collab-avatars";
6384
+ this.rail.appendChild(this.avatars);
6385
+ this.carets = document.createElement("div");
6386
+ this.carets.className = "markloom-collab-carets";
6387
+ this.carets.setAttribute("contenteditable", "false");
6388
+ root.appendChild(this.rail);
6389
+ root.appendChild(this.carets);
6390
+ document.addEventListener("selectionchange", this.onSel);
6391
+ window.addEventListener("scroll", this.onScroll, true);
6392
+ window.addEventListener("resize", this.onResize);
6393
+ }
6394
+ /** welcome 后设本人;peers 更新时刷新 */
6395
+ setSelf(siteId, name, color) {
6396
+ this.self = { siteId, name, color: collabColor(siteId, color) };
6397
+ this.paintAvatars();
6398
+ }
6399
+ setPeers(peers) {
6400
+ this.peers = peers.map((p) => ({
6401
+ ...p,
6402
+ color: collabColor(p.siteId, p.color)
6403
+ }));
6404
+ this.paintAvatars();
6405
+ this.paintCarets();
6406
+ }
6407
+ /** model 重绘后光标 DOM 位可能变 */
6408
+ onRedraw() {
6409
+ this.paintCarets();
6410
+ }
6411
+ destroy() {
6412
+ this.destroyed = true;
6413
+ document.removeEventListener("selectionchange", this.onSel);
6414
+ window.removeEventListener("scroll", this.onScroll, true);
6415
+ window.removeEventListener("resize", this.onResize);
6416
+ if (this.presenceTimer)
6417
+ clearTimeout(this.presenceTimer);
6418
+ this.rail.remove();
6419
+ this.carets.remove();
6420
+ }
6421
+ schedulePresence() {
6422
+ if (this.presenceTimer)
6423
+ clearTimeout(this.presenceTimer);
6424
+ this.presenceTimer = setTimeout(() => {
6425
+ this.presenceTimer = null;
6426
+ this.sendPresence();
6427
+ }, 80);
6428
+ }
6429
+ sendPresence() {
6430
+ const c = this.host.collab();
6431
+ if (!c || this.destroyed)
6432
+ return;
6433
+ const sel = readSelection(this.host.root, this.host.doc());
6434
+ if (!sel) {
6435
+ c.presence(null);
6436
+ return;
6437
+ }
6438
+ const w = wireOf(sel);
6439
+ const key = JSON.stringify(w);
6440
+ if (key === this.lastWire)
6441
+ return;
6442
+ this.lastWire = key;
6443
+ c.presence(w);
6444
+ }
6445
+ paintAvatars() {
6446
+ const list = [];
6447
+ if (this.self) {
6448
+ list.push({
6449
+ siteId: this.self.siteId,
6450
+ name: this.self.name,
6451
+ color: this.self.color
6452
+ });
6453
+ }
6454
+ for (const p of this.peers) {
6455
+ if (this.self && p.siteId === this.self.siteId)
6456
+ continue;
6457
+ list.push(p);
6458
+ }
6459
+ list.sort((a, b) => {
6460
+ if (this.self) {
6461
+ if (a.siteId === this.self.siteId)
6462
+ return 1;
6463
+ if (b.siteId === this.self.siteId)
6464
+ return -1;
6465
+ }
6466
+ return a.siteId - b.siteId;
6467
+ });
6468
+ this.avatars.replaceChildren();
6469
+ if (list.length === 0) {
6470
+ this.rail.hidden = true;
6471
+ return;
6472
+ }
6473
+ this.rail.hidden = false;
6474
+ for (const p of list) {
6475
+ const el = document.createElement("div");
6476
+ el.className = "markloom-collab-avatar";
6477
+ if (this.self && p.siteId === this.self.siteId)
6478
+ el.classList.add("is-self");
6479
+ el.style.setProperty("--collab-c", p.color || collabColor(p.siteId));
6480
+ el.textContent = collabInitial(p.name, p.siteId);
6481
+ el.title = p.name || `\u7528\u6237 ${p.siteId}`;
6482
+ this.avatars.appendChild(el);
6483
+ }
6484
+ }
6485
+ paintCarets() {
6486
+ this.carets.replaceChildren();
6487
+ const root = this.host.root;
6488
+ const doc = this.host.doc();
6489
+ const rootRect = root.getBoundingClientRect();
6490
+ const scrollX = root.scrollLeft;
6491
+ const scrollY = root.scrollTop;
6492
+ for (const p of this.peers) {
6493
+ if (this.self && p.siteId === this.self.siteId)
6494
+ continue;
6495
+ if (!p.sel?.head)
6496
+ continue;
6497
+ const pos = posOf(p.sel.head);
6498
+ const dom = pointToDom(root, doc, pos);
6499
+ if (!dom)
6500
+ continue;
6501
+ const range = document.createRange();
6502
+ try {
6503
+ const n = dom.node;
6504
+ const max2 = n.nodeType === 3 ? n.textContent?.length ?? 0 : 0;
6505
+ const off = Math.max(0, Math.min(dom.offset, max2));
6506
+ range.setStart(n, off);
6507
+ range.setEnd(n, off);
6508
+ } catch {
6509
+ continue;
6510
+ }
6511
+ const rects = range.getClientRects();
6512
+ const rect = rects[0] ?? range.getBoundingClientRect();
6513
+ if (!rect || rect.width === 0 && rect.height === 0 && rect.top === 0) {
6514
+ const leaf = dom.node.parentElement;
6515
+ if (!leaf)
6516
+ continue;
6517
+ const r = leaf.getBoundingClientRect();
6518
+ this.addCaret(p, r, rootRect, scrollX, scrollY);
6519
+ continue;
6520
+ }
6521
+ this.addCaret(p, rect, rootRect, scrollX, scrollY);
6522
+ }
6523
+ }
6524
+ addCaret(p, rect, rootRect, scrollX, scrollY) {
6525
+ const color = p.color || collabColor(p.siteId);
6526
+ const el = document.createElement("div");
6527
+ el.className = "markloom-collab-caret";
6528
+ el.style.setProperty("--collab-c", color);
6529
+ const left = rect.left - rootRect.left + scrollX;
6530
+ const top = rect.top - rootRect.top + scrollY;
6531
+ const h13 = Math.max(rect.height || 16, 14);
6532
+ el.style.left = `${left}px`;
6533
+ el.style.top = `${top}px`;
6534
+ el.style.height = `${h13}px`;
6535
+ const lab = document.createElement("div");
6536
+ lab.className = "markloom-collab-caret-lab";
6537
+ lab.textContent = p.name || `\u7528\u6237${p.siteId}`;
6538
+ el.appendChild(lab);
6539
+ this.carets.appendChild(el);
6540
+ }
6541
+ };
6542
+
6325
6543
  // src/view/image-controls.ts
6326
6544
  import { h as h11, render as render9 } from "preact";
6327
6545
  var DRAG_THRESHOLD = 4;
@@ -7404,6 +7622,7 @@ var Editor = class {
7404
7622
  aiCtl = null;
7405
7623
  /** 协作会话;applyingRemote 期间本地 steps 不上行 */
7406
7624
  collabCtl = null;
7625
+ collabUi = null;
7407
7626
  applyingRemote = false;
7408
7627
  constructor(root, doc, opts = {}) {
7409
7628
  this.root = root;
@@ -7470,11 +7689,18 @@ var Editor = class {
7470
7689
  });
7471
7690
  }
7472
7691
  if (opts.collab) {
7692
+ this.collabUi = new CollabPresence({
7693
+ root,
7694
+ doc: () => this.history.doc,
7695
+ collab: () => this.collabCtl
7696
+ });
7473
7697
  this.collabCtl = connectCollab(
7474
7698
  { ...opts.collab, seed: opts.collab.seed ?? doc },
7475
7699
  {
7476
7700
  onDoc: (d) => this.replaceDoc(d),
7477
7701
  onRemote: (steps) => this.applyRemote(steps),
7702
+ onWelcome: (info) => this.collabUi?.setSelf(info.siteId, info.name, info.color),
7703
+ onPeers: (peers) => this.collabUi?.setPeers(peers),
7478
7704
  onError: (msg) => {
7479
7705
  if (typeof console !== "undefined")
7480
7706
  console.warn("[markloom collab]", msg);
@@ -7547,6 +7773,8 @@ var Editor = class {
7547
7773
  this.commentPanel?.destroy();
7548
7774
  this.tocPanel?.destroy();
7549
7775
  this.aiCtl?.destroy();
7776
+ this.collabUi?.destroy();
7777
+ this.collabUi = null;
7550
7778
  this.collabCtl?.close();
7551
7779
  this.collabCtl = null;
7552
7780
  this.aiCtl = null;
@@ -7615,6 +7843,7 @@ var Editor = class {
7615
7843
  writeSelection(this.root, this.history.doc, restore);
7616
7844
  this.root.dispatchEvent(new Event("markloom-redraw", { bubbles: true }));
7617
7845
  this.syncPlaceholder();
7846
+ this.collabUi?.onRedraw();
7618
7847
  }
7619
7848
  // 空块提示(不进 model):空 paragraph → opts.placeholder(slash 引导);
7620
7849
  // 空 heading → 类型名 H1…H6(飞书/Notion 式)。空文档常显;光标落空块时也显。
@@ -7952,15 +8181,23 @@ var Editor = class {
7952
8181
  return top;
7953
8182
  }
7954
8183
  // AI 输入守卫:
7955
- // · 顶层 draft 段(attrs.aiDraft)只读
7956
- // · ai 块内:Enter 生成/确认;loading 锁输入
8184
+ // · 顶层 draft(attrs.aiDraft)且对应 ai 壳仍在 → 只读(确认前淡化)
8185
+ // · 孤儿 draft(壳已丢)→ 当场解锁可编辑,避免「虚区域无法输入」
8186
+ // · ai 块内:Enter 生成/确认;loading 锁输入;空指令块首退格 → discard
7957
8187
  aiBlockGuard(intent, sel, e) {
7958
8188
  if (!this.aiCtl)
7959
8189
  return false;
7960
8190
  const top = this.history.doc.children[sel.head.path[0]];
7961
- if (top && !isText(top) && top.type === "paragraph" && top.attrs?.aiDraft) {
7962
- e.preventDefault();
7963
- return true;
8191
+ if (top && !isText(top) && top.attrs?.aiDraft) {
8192
+ const from = typeof top.attrs.aiFrom === "string" ? top.attrs.aiFrom : "";
8193
+ const live = !!from && this.history.doc.children.some(
8194
+ (c) => !isText(c) && c.type === "ai" && c.id === from
8195
+ );
8196
+ if (live) {
8197
+ e.preventDefault();
8198
+ return true;
8199
+ }
8200
+ this.promoteOrphanAiDrafts();
7964
8201
  }
7965
8202
  const ai = this.aiBlockAt(sel);
7966
8203
  if (!ai || !ai.id)
@@ -7970,6 +8207,16 @@ var Editor = class {
7970
8207
  e.preventDefault();
7971
8208
  return true;
7972
8209
  }
8210
+ if (intent === "deleteBackward") {
8211
+ const prompt = ai.children[0];
8212
+ const empty = !prompt || isText(prompt) || !isText(prompt) && prompt.type === "paragraph" && prompt.children.every((c) => isText(c) && c.text === "");
8213
+ const atPromptStart = sel.head.path.length >= 4 && sel.head.path[1] === 0 && sel.head.path[sel.head.path.length - 1] === 0;
8214
+ if (empty && atPromptStart) {
8215
+ e.preventDefault();
8216
+ this.aiCtl.discard(ai.id);
8217
+ return true;
8218
+ }
8219
+ }
7973
8220
  if (intent === "insertParagraph") {
7974
8221
  e.preventDefault();
7975
8222
  if (status === "preview")
@@ -7980,6 +8227,35 @@ var Editor = class {
7980
8227
  }
7981
8228
  return false;
7982
8229
  }
8230
+ /** 壳已不在的 aiDraft 顶层块 → 剥事务标记,恢复可编辑 */
8231
+ promoteOrphanAiDrafts() {
8232
+ const doc = this.history.doc;
8233
+ const liveAi = /* @__PURE__ */ new Set();
8234
+ for (const c of doc.children) {
8235
+ if (!isText(c) && c.type === "ai" && c.id)
8236
+ liveAi.add(c.id);
8237
+ }
8238
+ const steps = [];
8239
+ for (let i = 0; i < doc.children.length; i++) {
8240
+ const c = doc.children[i];
8241
+ if (isText(c) || !c.attrs?.aiDraft)
8242
+ continue;
8243
+ const from = typeof c.attrs.aiFrom === "string" ? c.attrs.aiFrom : "";
8244
+ if (from && liveAi.has(from))
8245
+ continue;
8246
+ const attrs = { ...c.attrs };
8247
+ delete attrs.aiDraft;
8248
+ delete attrs.aiFrom;
8249
+ delete attrs.aiStream;
8250
+ const clean = Object.keys(attrs).length ? attrs : void 0;
8251
+ const next = { type: c.type, id: c.id, children: c.children };
8252
+ if (clean)
8253
+ next.attrs = clean;
8254
+ steps.push({ kind: "replaceNode", path: [i], node: next });
8255
+ }
8256
+ if (steps.length)
8257
+ this.dispatch(steps);
8258
+ }
7983
8259
  // 塌缩 caret 落在**非空** code 块的边界时,给出它在首/尾。否则返 null(不在 code / 非塌缩 / 空块 → 放行给 mapInput)。
7984
8260
  // 「code 内首尾删会与相邻块并块、破坏『单文本叶』不变量」是 codeBlockGuard 与 codeBoundaryDelete 共守的同一判定,
7985
8261
  // 抽成单一真相:collapsed/off/len/边界只算一处,两处消费,口径不漂。空块(len===0)无内容可护,放行删空块。
@@ -100,6 +100,13 @@ type CollabHandlers = {
100
100
  onDoc: (doc: ElementNode, version: number) => void;
101
101
  /** 已变换的远端 steps,应 applyRemote */
102
102
  onRemote: (steps: Step[]) => void;
103
+ /** 进房成功(分配 siteId,可画本人头像) */
104
+ onWelcome?: (info: {
105
+ siteId: number;
106
+ version: number;
107
+ name?: string;
108
+ color?: string;
109
+ }) => void;
103
110
  onPeers?: (peers: PeerInfo[]) => void;
104
111
  onStatus?: (s: 'connecting' | 'open' | 'closed') => void;
105
112
  onError?: (message: string) => void;
@@ -100,6 +100,13 @@ type CollabHandlers = {
100
100
  onDoc: (doc: ElementNode, version: number) => void;
101
101
  /** 已变换的远端 steps,应 applyRemote */
102
102
  onRemote: (steps: Step[]) => void;
103
+ /** 进房成功(分配 siteId,可画本人头像) */
104
+ onWelcome?: (info: {
105
+ siteId: number;
106
+ version: number;
107
+ name?: string;
108
+ color?: string;
109
+ }) => void;
103
110
  onPeers?: (peers: PeerInfo[]) => void;
104
111
  onStatus?: (s: 'connecting' | 'open' | 'closed') => void;
105
112
  onError?: (message: string) => void;
@@ -1,7 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkAC5E42NHcjs = require('../chunk-AC5E42NH.cjs');
4
+
5
+
6
+
7
+ var _chunkALZ3A5CScjs = require('../chunk-ALZ3A5CS.cjs');
5
8
 
6
9
 
7
10
 
@@ -16,4 +19,7 @@ require('../chunk-GQ2HHRGI.cjs');
16
19
 
17
20
 
18
21
 
19
- exports.CollabClient = _chunkAC5E42NHcjs.CollabClient; exports.connectCollab = _chunkAC5E42NHcjs.connectCollab; exports.rebaseBatchOver = _chunkJS527FDVcjs.rebaseBatchOver; exports.rebaseOne = _chunkJS527FDVcjs.rebaseOne; exports.rebaseStepsThrough = _chunkJS527FDVcjs.rebaseStepsThrough; exports.transformRemoteAgainstPending = _chunkJS527FDVcjs.transformRemoteAgainstPending;
22
+
23
+
24
+
25
+ exports.COLLAB_COLORS = _chunkALZ3A5CScjs.COLLAB_COLORS; exports.CollabClient = _chunkALZ3A5CScjs.CollabClient; exports.collabColor = _chunkALZ3A5CScjs.collabColor; exports.collabInitial = _chunkALZ3A5CScjs.collabInitial; exports.connectCollab = _chunkALZ3A5CScjs.connectCollab; exports.rebaseBatchOver = _chunkJS527FDVcjs.rebaseBatchOver; exports.rebaseOne = _chunkJS527FDVcjs.rebaseOne; exports.rebaseStepsThrough = _chunkJS527FDVcjs.rebaseStepsThrough; exports.transformRemoteAgainstPending = _chunkJS527FDVcjs.transformRemoteAgainstPending;
@@ -1,3 +1,11 @@
1
- export { C as ClientJoin, a as ClientMsg, b as ClientOp, c as CollabClient, d as CollabConfig, e as CollabHandlers, P as PeerInfo, S as ServerMsg, f as ServerOp, g as ServerWelcome, W as WireSel, h as connectCollab } from '../client-BNams4wv.cjs';
1
+ export { C as ClientJoin, a as ClientMsg, b as ClientOp, c as CollabClient, d as CollabConfig, e as CollabHandlers, P as PeerInfo, S as ServerMsg, f as ServerOp, g as ServerWelcome, W as WireSel, h as connectCollab } from '../client-ZRZj2nkq.cjs';
2
2
  export { r as rebaseBatchOver, a as rebaseOne, b as rebaseStepsThrough, t as transformRemoteAgainstPending } from '../rebase-batch-bYnBJpRO.cjs';
3
3
  import '../step-BrvHIK7O.cjs';
4
+
5
+ /** 协作用户色板(飞书/Notion 式高饱和,互不撞) */
6
+ declare const COLLAB_COLORS: readonly ["#3370ff", "#f54a45", "#ff8800", "#00b578", "#7b61ff", "#e13edb", "#14c0ff", "#8f959e", "#d83931", "#2ea121"];
7
+ declare function collabColor(siteId: number, explicit?: string): string;
8
+ /** 头像一字:优先首字/首字母 */
9
+ declare function collabInitial(name?: string, siteId?: number): string;
10
+
11
+ export { COLLAB_COLORS, collabColor, collabInitial };
@@ -1,3 +1,11 @@
1
- export { C as ClientJoin, a as ClientMsg, b as ClientOp, c as CollabClient, d as CollabConfig, e as CollabHandlers, P as PeerInfo, S as ServerMsg, f as ServerOp, g as ServerWelcome, W as WireSel, h as connectCollab } from '../client-A0ZQJnyR.js';
1
+ export { C as ClientJoin, a as ClientMsg, b as ClientOp, c as CollabClient, d as CollabConfig, e as CollabHandlers, P as PeerInfo, S as ServerMsg, f as ServerOp, g as ServerWelcome, W as WireSel, h as connectCollab } from '../client-6KiH4kGK.js';
2
2
  export { r as rebaseBatchOver, a as rebaseOne, b as rebaseStepsThrough, t as transformRemoteAgainstPending } from '../rebase-batch-8rL_aXEE.js';
3
3
  import '../step-BrvHIK7O.js';
4
+
5
+ /** 协作用户色板(飞书/Notion 式高饱和,互不撞) */
6
+ declare const COLLAB_COLORS: readonly ["#3370ff", "#f54a45", "#ff8800", "#00b578", "#7b61ff", "#e13edb", "#14c0ff", "#8f959e", "#d83931", "#2ea121"];
7
+ declare function collabColor(siteId: number, explicit?: string): string;
8
+ /** 头像一字:优先首字/首字母 */
9
+ declare function collabInitial(name?: string, siteId?: number): string;
10
+
11
+ export { COLLAB_COLORS, collabColor, collabInitial };
@@ -1,7 +1,10 @@
1
1
  import {
2
+ COLLAB_COLORS,
2
3
  CollabClient,
4
+ collabColor,
5
+ collabInitial,
3
6
  connectCollab
4
- } from "../chunk-6DCI7AL3.js";
7
+ } from "../chunk-4JSJAHTB.js";
5
8
  import {
6
9
  rebaseBatchOver,
7
10
  rebaseOne,
@@ -10,7 +13,10 @@ import {
10
13
  } from "../chunk-RLTHVQNQ.js";
11
14
  import "../chunk-LA5SBCGQ.js";
12
15
  export {
16
+ COLLAB_COLORS,
13
17
  CollabClient,
18
+ collabColor,
19
+ collabInitial,
14
20
  connectCollab,
15
21
  rebaseBatchOver,
16
22
  rebaseOne,
@@ -2,7 +2,7 @@ import { E as ElementNode, S as Step, c as Selection, M as Mark, P as Path, N as
2
2
  import * as preact from 'preact';
3
3
  import { ComponentChild } from 'preact';
4
4
  import { H as History, c as CommentThread, C as CommentAuthor } from './comments-PhnR7Gkn.js';
5
- import { d as CollabConfig, c as CollabClient } from './client-A0ZQJnyR.js';
5
+ import { d as CollabConfig, c as CollabClient } from './client-6KiH4kGK.js';
6
6
 
7
7
  interface MentionCandidate {
8
8
  id: string;
@@ -363,6 +363,7 @@ declare class Editor {
363
363
  private aiCtl;
364
364
  /** 协作会话;applyingRemote 期间本地 steps 不上行 */
365
365
  private collabCtl;
366
+ private collabUi;
366
367
  private applyingRemote;
367
368
  constructor(root: HTMLElement, doc: ElementNode, opts?: EditorOptions);
368
369
  destroy(): void;
@@ -403,6 +404,8 @@ declare class Editor {
403
404
  /** caret 是否在 type=ai 块内;是则返该块,否则 null */
404
405
  private aiBlockAt;
405
406
  private aiBlockGuard;
407
+ /** 壳已不在的 aiDraft 顶层块 → 剥事务标记,恢复可编辑 */
408
+ private promoteOrphanAiDrafts;
406
409
  private codeEdge;
407
410
  private codeBlockGuard;
408
411
  private atomControls;
@@ -506,8 +509,13 @@ declare class MarkloomAi {
506
509
  * 走 amend,与 begin/stream 同一笔 undo。
507
510
  */
508
511
  accept(blockId: string): void;
509
- /** 整笔撤回事务(= undo) */
512
+ /** 整笔撤回事务(= undo);务必不留 aiDraft 孤儿段 */
510
513
  discard(blockId: string): void;
514
+ /**
515
+ * 清掉 aiFrom=blockId 的顶层 draft;shell=true 时把 ai 壳也换成空段。
516
+ * discard / 异常恢复共用。
517
+ */
518
+ private purgeDrafts;
511
519
  act(blockId: string, action: string): void;
512
520
  private rollback;
513
521
  private findAi;
@@ -2,7 +2,7 @@ import { E as ElementNode, S as Step, c as Selection, M as Mark, P as Path, N as
2
2
  import * as preact from 'preact';
3
3
  import { ComponentChild } from 'preact';
4
4
  import { H as History, c as CommentThread, C as CommentAuthor } from './comments-DlExS6f-.cjs';
5
- import { d as CollabConfig, c as CollabClient } from './client-BNams4wv.cjs';
5
+ import { d as CollabConfig, c as CollabClient } from './client-ZRZj2nkq.cjs';
6
6
 
7
7
  interface MentionCandidate {
8
8
  id: string;
@@ -363,6 +363,7 @@ declare class Editor {
363
363
  private aiCtl;
364
364
  /** 协作会话;applyingRemote 期间本地 steps 不上行 */
365
365
  private collabCtl;
366
+ private collabUi;
366
367
  private applyingRemote;
367
368
  constructor(root: HTMLElement, doc: ElementNode, opts?: EditorOptions);
368
369
  destroy(): void;
@@ -403,6 +404,8 @@ declare class Editor {
403
404
  /** caret 是否在 type=ai 块内;是则返该块,否则 null */
404
405
  private aiBlockAt;
405
406
  private aiBlockGuard;
407
+ /** 壳已不在的 aiDraft 顶层块 → 剥事务标记,恢复可编辑 */
408
+ private promoteOrphanAiDrafts;
406
409
  private codeEdge;
407
410
  private codeBlockGuard;
408
411
  private atomControls;
@@ -506,8 +509,13 @@ declare class MarkloomAi {
506
509
  * 走 amend,与 begin/stream 同一笔 undo。
507
510
  */
508
511
  accept(blockId: string): void;
509
- /** 整笔撤回事务(= undo) */
512
+ /** 整笔撤回事务(= undo);务必不留 aiDraft 孤儿段 */
510
513
  discard(blockId: string): void;
514
+ /**
515
+ * 清掉 aiFrom=blockId 的顶层 draft;shell=true 时把 ai 壳也换成空段。
516
+ * discard / 异常恢复共用。
517
+ */
518
+ private purgeDrafts;
511
519
  act(blockId: string, action: string): void;
512
520
  private rollback;
513
521
  private findAi;
@@ -1,10 +1,10 @@
1
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; }
2
2
 
3
- var _chunkYJAWPRJWcjs = require('../chunk-YJAWPRJW.cjs');
3
+ var _chunkVXM7Q6P5cjs = require('../chunk-VXM7Q6P5.cjs');
4
4
  require('../chunk-YXQDCW4Y.cjs');
5
- require('../chunk-SLRD6FMP.cjs');
5
+ require('../chunk-YIFOGP2D.cjs');
6
6
  require('../chunk-4TMHVNL6.cjs');
7
- require('../chunk-AC5E42NH.cjs');
7
+ require('../chunk-ALZ3A5CS.cjs');
8
8
  require('../chunk-JS527FDV.cjs');
9
9
  require('../chunk-GQ2HHRGI.cjs');
10
10
 
@@ -20,7 +20,7 @@ function useMarkloom(initialDoc, opts = {}) {
20
20
  const host = ref.current;
21
21
  if (!host)
22
22
  return;
23
- const ed = new (0, _chunkYJAWPRJWcjs.Editor)(host, initialDoc, {
23
+ const ed = new (0, _chunkVXM7Q6P5cjs.Editor)(host, initialDoc, {
24
24
  ...optsRef.current,
25
25
  onChange: (d) => {
26
26
  setDoc(d);
@@ -1,10 +1,10 @@
1
1
  import * as react from 'react';
2
2
  import { MutableRefObject } from 'react';
3
3
  import { E as ElementNode } from '../step-BrvHIK7O.cjs';
4
- import { E as EditorOptions, k as Editor } from '../controller-CVIZI--A.cjs';
4
+ import { E as EditorOptions, k as Editor } from '../controller-DQITsFhy.cjs';
5
5
  import 'preact';
6
6
  import '../comments-DlExS6f-.cjs';
7
- import '../client-BNams4wv.cjs';
7
+ import '../client-ZRZj2nkq.cjs';
8
8
 
9
9
  declare function useMarkloom(initialDoc: ElementNode, opts?: EditorOptions): {
10
10
  ref: react.RefObject<HTMLDivElement | null>;