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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12;
2
2
 
3
3
 
4
4
 
@@ -18,7 +18,7 @@ var _chunkYXQDCW4Ycjs = require('./chunk-YXQDCW4Y.cjs');
18
18
 
19
19
 
20
20
 
21
- var _chunkSLRD6FMPcjs = require('./chunk-SLRD6FMP.cjs');
21
+ var _chunkYIFOGP2Dcjs = require('./chunk-YIFOGP2D.cjs');
22
22
 
23
23
 
24
24
 
@@ -56,7 +56,9 @@ var _chunkSLRD6FMPcjs = require('./chunk-SLRD6FMP.cjs');
56
56
  var _chunk4TMHVNL6cjs = require('./chunk-4TMHVNL6.cjs');
57
57
 
58
58
 
59
- var _chunkAC5E42NHcjs = require('./chunk-AC5E42NH.cjs');
59
+
60
+
61
+ var _chunkALZ3A5CScjs = require('./chunk-ALZ3A5CS.cjs');
60
62
 
61
63
 
62
64
 
@@ -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 ? _chunk4TMHVNL6cjs.nodeAt.call(void 0, 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 (!_chunkGQ2HHRGIcjs.isText.call(void 0, c) && _optionalChain([c, 'access', _73 => _73.attrs, 'optionalAccess', _74 => _74.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 = _nullishCoalesce(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
  }
@@ -1307,7 +1330,7 @@ function mapInput(doc, intent, data, sel, newId4, rules = [], pendingMarks) {
1307
1330
  function wrapList(block, blockIdx, newId4, rest, tail, ordered, start) {
1308
1331
  const para = { type: "paragraph", id: newId4(), children: [{ text: rest }, ...tail] };
1309
1332
  const item = { type: "list_item", id: newId4(), children: [para] };
1310
- const span = _optionalChain([block, 'access', _73 => _73.attrs, 'optionalAccess', _74 => _74.span]);
1333
+ const span = _optionalChain([block, 'access', _75 => _75.attrs, 'optionalAccess', _76 => _76.span]);
1311
1334
  const attrs = ordered ? { span, ordered: true, start: start === 1 ? void 0 : start } : { span, ordered: false };
1312
1335
  const list = { ...block, type: "list", attrs, children: [item] };
1313
1336
  return { steps: [{ kind: "replaceNode", path: [blockIdx], node: list }], selection: caret([blockIdx, 0, 0, 0, 0]) };
@@ -1326,7 +1349,7 @@ function calloutVariantFromQuery(q) {
1326
1349
  function blockTransform(block, blockIdx, kind, newId4, extra) {
1327
1350
  const kids = block.type === "quote" || block.type === "list" ? [{ text: "" }] : block.children;
1328
1351
  const bp = [blockIdx];
1329
- const span = _optionalChain([block, 'access', _75 => _75.attrs, 'optionalAccess', _76 => _76.span]);
1352
+ const span = _optionalChain([block, 'access', _77 => _77.attrs, 'optionalAccess', _78 => _78.span]);
1330
1353
  switch (kind) {
1331
1354
  case "heading1":
1332
1355
  case "heading2":
@@ -1340,7 +1363,7 @@ function blockTransform(block, blockIdx, kind, newId4, extra) {
1340
1363
  }
1341
1364
  case "callout": {
1342
1365
  const inner = { type: "paragraph", id: newId4(), children: kids };
1343
- const variant = _nullishCoalesce(_optionalChain([extra, 'optionalAccess', _77 => _77.variant]), () => ( "info"));
1366
+ const variant = _nullishCoalesce(_optionalChain([extra, 'optionalAccess', _79 => _79.variant]), () => ( "info"));
1344
1367
  return { steps: [{ kind: "replaceNode", path: bp, node: { type: "callout", id: block.id, attrs: { span, variant }, children: [inner] } }], selection: caret([blockIdx, 0, 0, 0]) };
1345
1368
  }
1346
1369
  case "bullet":
@@ -1362,7 +1385,7 @@ function setCalloutVariant(doc, path, variant) {
1362
1385
  const node = _chunk4TMHVNL6cjs.nodeAt.call(void 0, doc, path);
1363
1386
  if (!node || _chunkGQ2HHRGIcjs.isText.call(void 0, node) || node.type !== "callout")
1364
1387
  return null;
1365
- if (_optionalChain([node, 'access', _78 => _78.attrs, 'optionalAccess', _79 => _79.variant]) === variant)
1388
+ if (_optionalChain([node, 'access', _80 => _80.attrs, 'optionalAccess', _81 => _81.variant]) === variant)
1366
1389
  return null;
1367
1390
  return {
1368
1391
  steps: [{ kind: "replaceNode", path, node: { ...node, attrs: { ...node.attrs, variant } } }],
@@ -1373,7 +1396,7 @@ function cycleCalloutVariant(doc, path) {
1373
1396
  const node = _chunk4TMHVNL6cjs.nodeAt.call(void 0, doc, path);
1374
1397
  if (!node || _chunkGQ2HHRGIcjs.isText.call(void 0, node) || node.type !== "callout")
1375
1398
  return null;
1376
- const cur = String(_nullishCoalesce(_optionalChain([node, 'access', _80 => _80.attrs, 'optionalAccess', _81 => _81.variant]), () => ( "info")));
1399
+ const cur = String(_nullishCoalesce(_optionalChain([node, 'access', _82 => _82.attrs, 'optionalAccess', _83 => _83.variant]), () => ( "info")));
1377
1400
  const i = CALLOUT_VARIANTS.indexOf(cur);
1378
1401
  const next = CALLOUT_VARIANTS[(i >= 0 ? i + 1 : 1) % CALLOUT_VARIANTS.length];
1379
1402
  return setCalloutVariant(doc, path, next);
@@ -1526,8 +1549,8 @@ function mergeTextStyleAttrs(attrs, patch) {
1526
1549
  return Object.keys(out).length ? out : null;
1527
1550
  }
1528
1551
  function applyTextStyleLeaf(leaf, patch) {
1529
- const cur = _optionalChain([leaf, 'access', _82 => _82.marks, 'optionalAccess', _83 => _83.find, 'call', _84 => _84((m) => m.name === "textStyle")]);
1530
- const merged = mergeTextStyleAttrs(_optionalChain([cur, 'optionalAccess', _85 => _85.attrs]), patch);
1552
+ const cur = _optionalChain([leaf, 'access', _84 => _84.marks, 'optionalAccess', _85 => _85.find, 'call', _86 => _86((m) => m.name === "textStyle")]);
1553
+ const merged = mergeTextStyleAttrs(_optionalChain([cur, 'optionalAccess', _87 => _87.attrs]), patch);
1531
1554
  const rest = (_nullishCoalesce(leaf.marks, () => ( []))).filter((m) => m.name !== "textStyle");
1532
1555
  if (!merged)
1533
1556
  return { ...leaf, marks: rest.length ? rest : void 0 };
@@ -1615,10 +1638,10 @@ function insertMarked(block, blockPath, leafIdx, from, to, text, marks) {
1615
1638
  };
1616
1639
  }
1617
1640
  function hasMark(marks, name) {
1618
- return !!_optionalChain([marks, 'optionalAccess', _86 => _86.some, 'call', _87 => _87((m) => m.name === name)]);
1641
+ return !!_optionalChain([marks, 'optionalAccess', _88 => _88.some, 'call', _89 => _89((m) => m.name === name)]);
1619
1642
  }
1620
1643
  function hasMarkEq(marks, name, attrs) {
1621
- return !!_optionalChain([marks, 'optionalAccess', _88 => _88.some, 'call', _89 => _89((m) => m.name === name && attrsEq(m.attrs, attrs))]);
1644
+ return !!_optionalChain([marks, 'optionalAccess', _90 => _90.some, 'call', _91 => _91((m) => m.name === name && attrsEq(m.attrs, attrs))]);
1622
1645
  }
1623
1646
  function setMark(leaf, name, on, attrs) {
1624
1647
  if (on) {
@@ -1715,7 +1738,7 @@ function textLen(ns) {
1715
1738
  return ns.reduce((a, n) => a + (_chunkGQ2HHRGIcjs.isText.call(void 0, n) ? n.text.length : 1), 0);
1716
1739
  }
1717
1740
  function stripSpan(b) {
1718
- return _optionalChain([b, 'access', _90 => _90.attrs, 'optionalAccess', _91 => _91.span]) ? { ...b, attrs: { ...b.attrs, span: void 0 } } : b;
1741
+ return _optionalChain([b, 'access', _92 => _92.attrs, 'optionalAccess', _93 => _93.span]) ? { ...b, attrs: { ...b.attrs, span: void 0 } } : b;
1719
1742
  }
1720
1743
  function sliceDoc(doc, p1, p2) {
1721
1744
  const [lo, hi] = cmpPath(p1, p2) <= 0 ? [p1, p2] : [p2, p1];
@@ -3237,7 +3260,7 @@ function askInput(opts) {
3237
3260
  let value = _nullishCoalesce(opts.defaultValue, () => ( ""));
3238
3261
  let error = null;
3239
3262
  const finish = (v) => {
3240
- if (_optionalChain([active, 'optionalAccess', _92 => _92.root]) !== root)
3263
+ if (_optionalChain([active, 'optionalAccess', _94 => _94.root]) !== root)
3241
3264
  return;
3242
3265
  dismissActive(v);
3243
3266
  };
@@ -3329,8 +3352,8 @@ function askInput(opts) {
3329
3352
  );
3330
3353
  queueMicrotask(() => {
3331
3354
  const el = root.querySelector("input, textarea");
3332
- _optionalChain([el, 'optionalAccess', _93 => _93.focus, 'call', _94 => _94()]);
3333
- _optionalChain([el, 'optionalAccess', _95 => _95.select, 'call', _96 => _96()]);
3355
+ _optionalChain([el, 'optionalAccess', _95 => _95.focus, 'call', _96 => _96()]);
3356
+ _optionalChain([el, 'optionalAccess', _97 => _97.select, 'call', _98 => _98()]);
3334
3357
  });
3335
3358
  };
3336
3359
  active = { resolve: resolve2, root, onKey };
@@ -3358,7 +3381,7 @@ function askLinkPopover(opts) {
3358
3381
  let value = _nullishCoalesce(opts.defaultValue, () => ( ""));
3359
3382
  let placed = false;
3360
3383
  const finish = (v) => {
3361
- if (_optionalChain([active, 'optionalAccess', _97 => _97.root]) !== root)
3384
+ if (_optionalChain([active, 'optionalAccess', _99 => _99.root]) !== root)
3362
3385
  return;
3363
3386
  dismissActive(v);
3364
3387
  };
@@ -3382,7 +3405,7 @@ function askLinkPopover(opts) {
3382
3405
  finish(null);
3383
3406
  };
3384
3407
  queueMicrotask(() => {
3385
- if (_optionalChain([active, 'optionalAccess', _98 => _98.root]) === root)
3408
+ if (_optionalChain([active, 'optionalAccess', _100 => _100.root]) === root)
3386
3409
  document.addEventListener("pointerdown", onDocDown, true);
3387
3410
  });
3388
3411
  const paint = (focus = false) => {
@@ -3440,9 +3463,9 @@ function askLinkPopover(opts) {
3440
3463
  if (focus) {
3441
3464
  queueMicrotask(() => {
3442
3465
  const input = root.querySelector("input");
3443
- _optionalChain([input, 'optionalAccess', _99 => _99.focus, 'call', _100 => _100()]);
3466
+ _optionalChain([input, 'optionalAccess', _101 => _101.focus, 'call', _102 => _102()]);
3444
3467
  if (opts.defaultValue)
3445
- _optionalChain([input, 'optionalAccess', _101 => _101.select, 'call', _102 => _102()]);
3468
+ _optionalChain([input, 'optionalAccess', _103 => _103.select, 'call', _104 => _104()]);
3446
3469
  });
3447
3470
  }
3448
3471
  };
@@ -3485,7 +3508,7 @@ var MentionMenu = (_class = class {
3485
3508
  }
3486
3509
  // 光标落点变化后重判:段落/标题文本叶,光标前的文本在词边界有 `@` 起头的连续非空白段 → 开菜单。
3487
3510
  __init6() {this.reevaluate = () => {
3488
- const source = _optionalChain([this, 'access', _106 => _106.host, 'access', _107 => _107.mentionSource, 'optionalCall', _108 => _108()]);
3511
+ const source = _optionalChain([this, 'access', _108 => _108.host, 'access', _109 => _109.mentionSource, 'optionalCall', _110 => _110()]);
3489
3512
  if (!source) {
3490
3513
  this.close();
3491
3514
  return;
@@ -3596,7 +3619,7 @@ var MentionMenu = (_class = class {
3596
3619
  paint() {
3597
3620
  const dom = document.getSelection();
3598
3621
  const range = dom && dom.rangeCount ? dom.getRangeAt(0) : null;
3599
- const rect = _optionalChain([range, 'optionalAccess', _109 => _109.getBoundingClientRect]) ? range.getBoundingClientRect() : { left: 0, bottom: 0 };
3622
+ const rect = _optionalChain([range, 'optionalAccess', _111 => _111.getBoundingClientRect]) ? range.getBoundingClientRect() : { left: 0, bottom: 0 };
3600
3623
  _preact.render.call(void 0,
3601
3624
  _preact.h.call(void 0,
3602
3625
  "div",
@@ -3647,7 +3670,7 @@ function nodeAt2(doc, path) {
3647
3670
  var SHOW_MS = 300;
3648
3671
  var MENU_OPEN_MS = 300;
3649
3672
  var MENU_CLOSE_MS = 120;
3650
- var nid = () => _nullishCoalesce(_optionalChain([crypto, 'access', _110 => _110.randomUUID, 'optionalCall', _111 => _111()]), () => ( `n${Math.random().toString(36).slice(2)}`));
3673
+ var nid = () => _nullishCoalesce(_optionalChain([crypto, 'access', _112 => _112.randomUUID, 'optionalCall', _113 => _113()]), () => ( `n${Math.random().toString(36).slice(2)}`));
3651
3674
  var isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
3652
3675
  var mod = isMac ? "\u2318" : "Ctrl";
3653
3676
  var BLOCK_ITEMS = [
@@ -3712,12 +3735,12 @@ function currentBlockKind(doc, sel) {
3712
3735
  if (!block || _chunkGQ2HHRGIcjs.isText.call(void 0, block))
3713
3736
  return "paragraph";
3714
3737
  if (block.type === "heading")
3715
- return `heading${Number(_nullishCoalesce(_optionalChain([block, 'access', _112 => _112.attrs, 'optionalAccess', _113 => _113.depth]), () => ( 1)))}`;
3738
+ return `heading${Number(_nullishCoalesce(_optionalChain([block, 'access', _114 => _114.attrs, 'optionalAccess', _115 => _115.depth]), () => ( 1)))}`;
3716
3739
  if (block.type === "list") {
3717
3740
  const item = block.children[0];
3718
3741
  if (item && !_chunkGQ2HHRGIcjs.isText.call(void 0, item) && item.attrs && "checked" in item.attrs)
3719
3742
  return "task";
3720
- return _optionalChain([block, 'access', _114 => _114.attrs, 'optionalAccess', _115 => _115.ordered]) ? "ordered" : "bullet";
3743
+ return _optionalChain([block, 'access', _116 => _116.attrs, 'optionalAccess', _117 => _117.ordered]) ? "ordered" : "bullet";
3721
3744
  }
3722
3745
  return block.type;
3723
3746
  }
@@ -3941,21 +3964,21 @@ var BubbleMenu = (_class2 = class {
3941
3964
  }
3942
3965
  activeAlign(sel) {
3943
3966
  const block = this.host.doc().children[sel.head.path[0]];
3944
- return !block || _chunkGQ2HHRGIcjs.isText.call(void 0, block) ? "left" : _nullishCoalesce(_optionalChain([block, 'access', _116 => _116.attrs, 'optionalAccess', _117 => _117.align]), () => ( "left"));
3967
+ return !block || _chunkGQ2HHRGIcjs.isText.call(void 0, block) ? "left" : _nullishCoalesce(_optionalChain([block, 'access', _118 => _118.attrs, 'optionalAccess', _119 => _119.align]), () => ( "left"));
3945
3968
  }
3946
3969
  styleAttrs(sel) {
3947
3970
  const leaf = _chunk4TMHVNL6cjs.nodeAt.call(void 0, this.host.doc(), sel.head.path.slice(0, -1));
3948
3971
  if (!_chunkGQ2HHRGIcjs.isText.call(void 0, leaf))
3949
3972
  return null;
3950
3973
  const m = (_nullishCoalesce(leaf.marks, () => ( []))).find((x) => x.name === "textStyle");
3951
- return _nullishCoalesce(_optionalChain([m, 'optionalAccess', _118 => _118.attrs]), () => ( null));
3974
+ return _nullishCoalesce(_optionalChain([m, 'optionalAccess', _120 => _120.attrs]), () => ( null));
3952
3975
  }
3953
3976
  activeColor(sel) {
3954
- const c = _optionalChain([this, 'access', _119 => _119.styleAttrs, 'call', _120 => _120(sel), 'optionalAccess', _121 => _121.color]);
3977
+ const c = _optionalChain([this, 'access', _121 => _121.styleAttrs, 'call', _122 => _122(sel), 'optionalAccess', _123 => _123.color]);
3955
3978
  return typeof c === "string" ? c : null;
3956
3979
  }
3957
3980
  activeBg(sel) {
3958
- const c = _optionalChain([this, 'access', _122 => _122.styleAttrs, 'call', _123 => _123(sel), 'optionalAccess', _124 => _124.backgroundColor]);
3981
+ const c = _optionalChain([this, 'access', _124 => _124.styleAttrs, 'call', _125 => _125(sel), 'optionalAccess', _126 => _126.backgroundColor]);
3959
3982
  return typeof c === "string" ? c : null;
3960
3983
  }
3961
3984
  applyBlock(kind) {
@@ -4166,7 +4189,7 @@ var BubbleMenu = (_class2 = class {
4166
4189
  }
4167
4190
  const rect2 = _nullishCoalesce(_nullishCoalesce(this.lastRect, () => ( (() => {
4168
4191
  try {
4169
- return _optionalChain([document, 'access', _125 => _125.getSelection, 'call', _126 => _126(), 'optionalAccess', _127 => _127.getRangeAt, 'call', _128 => _128(0), 'optionalAccess', _129 => _129.getBoundingClientRect, 'call', _130 => _130()]);
4192
+ return _optionalChain([document, 'access', _127 => _127.getSelection, 'call', _128 => _128(), 'optionalAccess', _129 => _129.getRangeAt, 'call', _130 => _130(0), 'optionalAccess', _131 => _131.getBoundingClientRect, 'call', _132 => _132()]);
4170
4193
  } catch (e8) {
4171
4194
  return null;
4172
4195
  }
@@ -4297,7 +4320,7 @@ var BubbleMenu = (_class2 = class {
4297
4320
  "title": "AI \u7EED\u5199",
4298
4321
  "onMouseDown": (e) => {
4299
4322
  e.preventDefault();
4300
- _optionalChain([this, 'access', _131 => _131.host, 'access', _132 => _132.openAi, 'optionalCall', _133 => _133("continue")]);
4323
+ _optionalChain([this, 'access', _133 => _133.host, 'access', _134 => _134.openAi, 'optionalCall', _135 => _135("continue")]);
4301
4324
  }
4302
4325
  }, [icon("sparkles", 16), _preact.h.call(void 0, "span", { class: "markloom-bb-ai-lab", key: "l" }, "\u7EED\u5199"), tipNode("AI \u7EED\u5199")]) : null;
4303
4326
  const aiRewriteBtn = this.host.openAi ? _preact.h.call(void 0, "button", {
@@ -4308,7 +4331,7 @@ var BubbleMenu = (_class2 = class {
4308
4331
  "title": "AI \u6539\u5199",
4309
4332
  "onMouseDown": (e) => {
4310
4333
  e.preventDefault();
4311
- _optionalChain([this, 'access', _134 => _134.host, 'access', _135 => _135.openAi, 'optionalCall', _136 => _136("rewrite")]);
4334
+ _optionalChain([this, 'access', _136 => _136.host, 'access', _137 => _137.openAi, 'optionalCall', _138 => _138("rewrite")]);
4312
4335
  }
4313
4336
  }, [icon("pen-line", 16), _preact.h.call(void 0, "span", { class: "markloom-bb-ai-lab", key: "l" }, "\u6539\u5199"), tipNode("AI \u6539\u5199")]) : null;
4314
4337
  const commentBtn = this.host.beginComment ? _preact.h.call(void 0, "button", {
@@ -4318,7 +4341,7 @@ var BubbleMenu = (_class2 = class {
4318
4341
  "data-mark": "comment",
4319
4342
  "onMouseDown": (e) => {
4320
4343
  e.preventDefault();
4321
- _optionalChain([this, 'access', _137 => _137.host, 'access', _138 => _138.beginComment, 'optionalCall', _139 => _139()]);
4344
+ _optionalChain([this, 'access', _139 => _139.host, 'access', _140 => _140.beginComment, 'optionalCall', _141 => _141()]);
4322
4345
  }
4323
4346
  }, [icon("message-circle", 16), tipNode("\u8BC4\u8BBA")]) : null;
4324
4347
  _preact.render.call(void 0,
@@ -4378,7 +4401,7 @@ var CodeControls = (_class3 = class {
4378
4401
  this.closeMenu();
4379
4402
  }
4380
4403
  __init25() {this.closeMenu = () => {
4381
- _optionalChain([this, 'access', _150 => _150.menu, 'optionalAccess', _151 => _151.remove, 'call', _152 => _152()]);
4404
+ _optionalChain([this, 'access', _152 => _152.menu, 'optionalAccess', _153 => _153.remove, 'call', _154 => _154()]);
4382
4405
  this.menu = null;
4383
4406
  }}
4384
4407
  __init26() {this.onDown = (e) => {
@@ -4388,7 +4411,7 @@ var CodeControls = (_class3 = class {
4388
4411
  e.preventDefault();
4389
4412
  e.stopPropagation();
4390
4413
  const box = copyBtn.closest("[data-code-block]");
4391
- const text = _nullishCoalesce(_optionalChain([(_nullishCoalesce(_optionalChain([box, 'optionalAccess', _153 => _153.querySelector, 'call', _154 => _154("[data-code-hl]")]), () => ( box))), 'optionalAccess', _155 => _155.textContent]), () => ( ""));
4414
+ const text = _nullishCoalesce(_optionalChain([(_nullishCoalesce(_optionalChain([box, 'optionalAccess', _155 => _155.querySelector, 'call', _156 => _156("[data-code-hl]")]), () => ( box))), 'optionalAccess', _157 => _157.textContent]), () => ( ""));
4392
4415
  navigator.clipboard.writeText(text.trimEnd()).then(() => {
4393
4416
  copyBtn.dataset.copied = "";
4394
4417
  setTimeout(() => {
@@ -4404,7 +4427,7 @@ var CodeControls = (_class3 = class {
4404
4427
  }
4405
4428
  e.preventDefault();
4406
4429
  e.stopPropagation();
4407
- const blockId = _optionalChain([langBtn, 'access', _156 => _156.closest, 'call', _157 => _157("[data-code-block]"), 'optionalAccess', _158 => _158.dataset, 'access', _159 => _159.blockId]);
4430
+ const blockId = _optionalChain([langBtn, 'access', _158 => _158.closest, 'call', _159 => _159("[data-code-block]"), 'optionalAccess', _160 => _160.dataset, 'access', _161 => _161.blockId]);
4408
4431
  if (!blockId) {
4409
4432
  this.closeMenu();
4410
4433
  return;
@@ -4472,7 +4495,7 @@ var COLORS = [
4472
4495
  { value: "#2563eb", title: "\u84DD", swatch: "#2563eb" },
4473
4496
  { value: "#7c3aed", title: "\u7D2B", swatch: "#7c3aed" }
4474
4497
  ];
4475
- var newId = () => _nullishCoalesce(_optionalChain([crypto, 'optionalAccess', _160 => _160.randomUUID, 'optionalCall', _161 => _161()]), () => ( `b${Math.random().toString(36).slice(2)}`));
4498
+ var newId = () => _nullishCoalesce(_optionalChain([crypto, 'optionalAccess', _162 => _162.randomUUID, 'optionalCall', _163 => _163()]), () => ( `b${Math.random().toString(36).slice(2)}`));
4476
4499
  var DragHandle = (_class4 = class {
4477
4500
 
4478
4501
 
@@ -4500,7 +4523,7 @@ var DragHandle = (_class4 = class {
4500
4523
  this.overlay.remove();
4501
4524
  }
4502
4525
  blocks() {
4503
- return _chunkSLRD6FMPcjs.elementChildren.call(void 0, _chunkSLRD6FMPcjs.rootEl.call(void 0, this.root));
4526
+ return _chunkYIFOGP2Dcjs.elementChildren.call(void 0, _chunkYIFOGP2Dcjs.rootEl.call(void 0, this.root));
4504
4527
  }
4505
4528
  clearLeave() {
4506
4529
  if (this.leaveTimer != null) {
@@ -4616,7 +4639,7 @@ var DragHandle = (_class4 = class {
4616
4639
  this.host.dispatch([{
4617
4640
  kind: "replaceNode",
4618
4641
  path: [blockIdx],
4619
- node: { ...node, attrs: { ...node.attrs, collapsed: !_optionalChain([node, 'access', _162 => _162.attrs, 'optionalAccess', _163 => _163.collapsed]) } }
4642
+ node: { ...node, attrs: { ...node.attrs, collapsed: !_optionalChain([node, 'access', _164 => _164.attrs, 'optionalAccess', _165 => _165.collapsed]) } }
4620
4643
  }]);
4621
4644
  }
4622
4645
  /** 整块文本选区(paragraph/heading 顶层叶),供手柄菜单套 mark */
@@ -4689,10 +4712,10 @@ var DragHandle = (_class4 = class {
4689
4712
  dropLine() {
4690
4713
  if (!this.drag)
4691
4714
  return null;
4692
- const docEl = _chunkSLRD6FMPcjs.rootEl.call(void 0, this.root);
4715
+ const docEl = _chunkYIFOGP2Dcjs.rootEl.call(void 0, this.root);
4693
4716
  const blocks = this.blocks();
4694
4717
  const gap = this.drag.gap;
4695
- const y = gap === 0 ? _nullishCoalesce(_optionalChain([blocks, 'access', _164 => _164[0], 'optionalAccess', _165 => _165.getBoundingClientRect, 'call', _166 => _166(), 'access', _167 => _167.top]), () => ( 0)) : _nullishCoalesce(_optionalChain([blocks, 'access', _168 => _168[gap - 1], 'optionalAccess', _169 => _169.getBoundingClientRect, 'call', _170 => _170(), 'access', _171 => _171.bottom]), () => ( 0));
4718
+ const y = gap === 0 ? _nullishCoalesce(_optionalChain([blocks, 'access', _166 => _166[0], 'optionalAccess', _167 => _167.getBoundingClientRect, 'call', _168 => _168(), 'access', _169 => _169.top]), () => ( 0)) : _nullishCoalesce(_optionalChain([blocks, 'access', _170 => _170[gap - 1], 'optionalAccess', _171 => _171.getBoundingClientRect, 'call', _172 => _172(), 'access', _173 => _173.bottom]), () => ( 0));
4696
4719
  const box = docEl.getBoundingClientRect();
4697
4720
  return _preact.h.call(void 0, "div", { key: "drop", class: "markloom-drag-drop", style: `top:${y}px;left:${box.left}px;width:${box.width}px` });
4698
4721
  }
@@ -4716,9 +4739,9 @@ var DragHandle = (_class4 = class {
4716
4739
  }
4717
4740
  currentKind(block) {
4718
4741
  if (block.type === "heading")
4719
- return `heading${Math.min(Number(_nullishCoalesce(_optionalChain([block, 'access', _172 => _172.attrs, 'optionalAccess', _173 => _173.depth]), () => ( 1))), 3)}`;
4742
+ return `heading${Math.min(Number(_nullishCoalesce(_optionalChain([block, 'access', _174 => _174.attrs, 'optionalAccess', _175 => _175.depth]), () => ( 1))), 3)}`;
4720
4743
  if (block.type === "list")
4721
- return _optionalChain([block, 'access', _174 => _174.attrs, 'optionalAccess', _175 => _175.ordered]) ? "ordered" : "bullet";
4744
+ return _optionalChain([block, 'access', _176 => _176.attrs, 'optionalAccess', _177 => _177.ordered]) ? "ordered" : "bullet";
4722
4745
  if (block.type === "quote" || block.type === "code" || block.type === "paragraph")
4723
4746
  return block.type;
4724
4747
  return "";
@@ -4982,7 +5005,7 @@ var SlashMenu = (_class5 = class {
4982
5005
  }
4983
5006
  allItems() {
4984
5007
  const base = ITEMS.filter((it) => !("ai" in it) || !!this.host.openAiSlash);
4985
- const extra = (_nullishCoalesce(_optionalChain([this, 'access', _176 => _176.host, 'access', _177 => _177.slashCommands, 'optionalCall', _178 => _178()]), () => ( []))).map((cmd) => ({
5008
+ const extra = (_nullishCoalesce(_optionalChain([this, 'access', _178 => _178.host, 'access', _179 => _179.slashCommands, 'optionalCall', _180 => _180()]), () => ( []))).map((cmd) => ({
4986
5009
  label: cmd.label,
4987
5010
  hint: cmd.hint,
4988
5011
  section: _nullishCoalesce(cmd.section, () => ( "AI")),
@@ -5065,7 +5088,7 @@ var SlashMenu = (_class5 = class {
5065
5088
  const query = this.query;
5066
5089
  this.close();
5067
5090
  if ("ai" in item) {
5068
- _optionalChain([this, 'access', _179 => _179.host, 'access', _180 => _180.openAiSlash, 'optionalCall', _181 => _181({ blockIdx, query })]);
5091
+ _optionalChain([this, 'access', _181 => _181.host, 'access', _182 => _182.openAiSlash, 'optionalCall', _183 => _183({ blockIdx, query })]);
5069
5092
  return;
5070
5093
  }
5071
5094
  if ("cmd" in item) {
@@ -5083,11 +5106,11 @@ var SlashMenu = (_class5 = class {
5083
5106
  return;
5084
5107
  }
5085
5108
  if (item.insert === "math") {
5086
- _optionalChain([this, 'access', _182 => _182.host, 'access', _183 => _183.insertMath, 'optionalCall', _184 => _184(blockIdx)]);
5109
+ _optionalChain([this, 'access', _184 => _184.host, 'access', _185 => _185.insertMath, 'optionalCall', _186 => _186(blockIdx)]);
5087
5110
  return;
5088
5111
  }
5089
5112
  if (item.insert === "youtube" || item.insert === "twitch" || item.insert === "audio" || item.insert === "file") {
5090
- _optionalChain([this, 'access', _185 => _185.host, 'access', _186 => _186.insertEmbed, 'optionalCall', _187 => _187(blockIdx, item.insert)]);
5113
+ _optionalChain([this, 'access', _187 => _187.host, 'access', _188 => _188.insertEmbed, 'optionalCall', _189 => _189(blockIdx, item.insert)]);
5091
5114
  return;
5092
5115
  }
5093
5116
  const node = item.insert === "table" ? _chunk4TMHVNL6cjs.makeTable.call(void 0, newId2(), 3, 3) : { type: "raw", id: newId2(), attrs: { mdType: "thematicBreak" }, children: [{ text: "" }] };
@@ -5117,7 +5140,7 @@ var SlashMenu = (_class5 = class {
5117
5140
  this.active = Math.min(this.active, list.length - 1);
5118
5141
  const dom = document.getSelection();
5119
5142
  const range = dom && dom.rangeCount ? dom.getRangeAt(0) : null;
5120
- const rect = _optionalChain([range, 'optionalAccess', _188 => _188.getBoundingClientRect]) ? range.getBoundingClientRect() : { left: 0, bottom: 0 };
5143
+ const rect = _optionalChain([range, 'optionalAccess', _190 => _190.getBoundingClientRect]) ? range.getBoundingClientRect() : { left: 0, bottom: 0 };
5121
5144
  const rows = [];
5122
5145
  let prev = null;
5123
5146
  list.forEach((it, i) => {
@@ -5144,7 +5167,7 @@ var SlashMenu = (_class5 = class {
5144
5167
  void place(rectRef(rect), el, { placement: "bottom-start", gap: 6 });
5145
5168
  }
5146
5169
  }, _class5);
5147
- var newId2 = () => _nullishCoalesce(_optionalChain([crypto, 'optionalAccess', _189 => _189.randomUUID, 'optionalCall', _190 => _190()]), () => ( `s${Math.random().toString(36).slice(2)}`));
5170
+ var newId2 = () => _nullishCoalesce(_optionalChain([crypto, 'optionalAccess', _191 => _191.randomUUID, 'optionalCall', _192 => _192()]), () => ( `s${Math.random().toString(36).slice(2)}`));
5148
5171
 
5149
5172
  // src/view/extensions/decorations.ts
5150
5173
  var codeControls = { name: "codeControls", decorations: [(host) => new CodeControls(host.root, host)] };
@@ -5331,7 +5354,7 @@ var linkMark = {
5331
5354
  name: "link",
5332
5355
  tag: "a",
5333
5356
  props: (mark) => {
5334
- if (!_optionalChain([mark, 'access', _191 => _191.attrs, 'optionalAccess', _192 => _192.url]))
5357
+ if (!_optionalChain([mark, 'access', _193 => _193.attrs, 'optionalAccess', _194 => _194.url]))
5335
5358
  return { "data-mark": "link", class: "markloom-link" };
5336
5359
  const url = String(mark.attrs.url);
5337
5360
  return {
@@ -5466,10 +5489,10 @@ var CommentPanel = (_class6 = class {
5466
5489
  }
5467
5490
  commitThreads(next) {
5468
5491
  this.threads = next;
5469
- _optionalChain([this, 'access', _196 => _196.host, 'access', _197 => _197.onChange, 'optionalCall', _198 => _198(this.threads)]);
5492
+ _optionalChain([this, 'access', _198 => _198.host, 'access', _199 => _199.onChange, 'optionalCall', _200 => _200(this.threads)]);
5470
5493
  }
5471
5494
  __init45() {this.onRootClick = (e) => {
5472
- const el = _optionalChain([e, 'access', _199 => _199.target, 'optionalAccess', _200 => _200.closest, 'optionalCall', _201 => _201("[data-comment-id]")]);
5495
+ const el = _optionalChain([e, 'access', _201 => _201.target, 'optionalAccess', _202 => _202.closest, 'optionalCall', _203 => _203("[data-comment-id]")]);
5473
5496
  if (!el || !this.host.root.contains(el))
5474
5497
  return;
5475
5498
  const id = el.getAttribute("data-comment-id");
@@ -5495,7 +5518,7 @@ var CommentPanel = (_class6 = class {
5495
5518
  if (this.mode.kind !== "compose")
5496
5519
  return;
5497
5520
  const ta = this.overlay.querySelector('[data-comment-ui="compose"] textarea');
5498
- const body = (_nullishCoalesce(_optionalChain([ta, 'optionalAccess', _202 => _202.value]), () => ( this.mode.body))).trim();
5521
+ const body = (_nullishCoalesce(_optionalChain([ta, 'optionalAccess', _204 => _204.value]), () => ( this.mode.body))).trim();
5499
5522
  if (!body)
5500
5523
  return;
5501
5524
  const id = this.host.newId();
@@ -5521,7 +5544,7 @@ var CommentPanel = (_class6 = class {
5521
5544
  if (this.mode.kind !== "view")
5522
5545
  return;
5523
5546
  const ta = this.overlay.querySelector(`[data-thread="${cssEscape(this.mode.id)}"] .markloom-comment-reply textarea`);
5524
- const body = (_nullishCoalesce(_optionalChain([ta, 'optionalAccess', _203 => _203.value]), () => ( this.mode.reply))).trim();
5547
+ const body = (_nullishCoalesce(_optionalChain([ta, 'optionalAccess', _205 => _205.value]), () => ( this.mode.reply))).trim();
5525
5548
  if (!body)
5526
5549
  return;
5527
5550
  const id = this.mode.id;
@@ -5563,7 +5586,7 @@ var CommentPanel = (_class6 = class {
5563
5586
  /** 卡片 top(相对 rail-body)。正文与栏共滚 → viewport 差即内容坐标。 */
5564
5587
  cardTops(ids, composeTop) {
5565
5588
  const body = this.overlay.querySelector(".markloom-comment-rail-body");
5566
- const bodyTop = _nullishCoalesce(_optionalChain([body, 'optionalAccess', _204 => _204.getBoundingClientRect, 'call', _205 => _205(), 'access', _206 => _206.top]), () => ( 0));
5589
+ const bodyTop = _nullishCoalesce(_optionalChain([body, 'optionalAccess', _206 => _206.getBoundingClientRect, 'call', _207 => _207(), 'access', _208 => _208.top]), () => ( 0));
5567
5590
  const raw = ids.map((id) => {
5568
5591
  const el = this.host.root.querySelector(`[data-comment-id="${cssEscape(id)}"]`);
5569
5592
  const y = el ? el.getBoundingClientRect().top - bodyTop : 0;
@@ -5602,7 +5625,7 @@ var CommentPanel = (_class6 = class {
5602
5625
  if (rail) {
5603
5626
  const sp = this.scrollRoot;
5604
5627
  const hd = rail.querySelector(".markloom-comment-rail-hd");
5605
- const hdH = _nullishCoalesce(_optionalChain([hd, 'optionalAccess', _207 => _207.offsetHeight]), () => ( 52));
5628
+ const hdH = _nullishCoalesce(_optionalChain([hd, 'optionalAccess', _209 => _209.offsetHeight]), () => ( 52));
5606
5629
  const need = Math.max(sp.scrollHeight, sp.clientHeight, maxBottom + hdH + RAIL_PAD);
5607
5630
  rail.style.minHeight = `${need}px`;
5608
5631
  }
@@ -5722,7 +5745,7 @@ var CommentPanel = (_class6 = class {
5722
5745
  this.reflowAfterPaint();
5723
5746
  if (composing) {
5724
5747
  const ta = this.overlay.querySelector('[data-comment-ui="compose"] textarea');
5725
- _optionalChain([ta, 'optionalAccess', _208 => _208.focus, 'call', _209 => _209()]);
5748
+ _optionalChain([ta, 'optionalAccess', _210 => _210.focus, 'call', _211 => _211()]);
5726
5749
  }
5727
5750
  });
5728
5751
  }
@@ -5837,7 +5860,7 @@ function markQuote(root, id) {
5837
5860
  }
5838
5861
  function markTop(root, id) {
5839
5862
  const el = root.querySelector(`[data-comment-id="${cssEscape(id)}"]`);
5840
- return _nullishCoalesce(_optionalChain([el, 'optionalAccess', _210 => _210.getBoundingClientRect, 'call', _211 => _211(), 'access', _212 => _212.top]), () => ( 1e9));
5863
+ return _nullishCoalesce(_optionalChain([el, 'optionalAccess', _212 => _212.getBoundingClientRect, 'call', _213 => _213(), 'access', _214 => _214.top]), () => ( 1e9));
5841
5864
  }
5842
5865
  function fmtTime(ts) {
5843
5866
  const d = new Date(ts);
@@ -6080,7 +6103,7 @@ var MentionPopovers = (_class8 = class {
6080
6103
  const t = e.target;
6081
6104
  if (this.overlay.contains(t))
6082
6105
  return;
6083
- if (_optionalChain([t, 'access', _215 => _215.closest, 'optionalCall', _216 => _216('[data-atom="mention"]')]))
6106
+ if (_optionalChain([t, 'access', _217 => _217.closest, 'optionalCall', _218 => _218('[data-atom="mention"]')]))
6084
6107
  return;
6085
6108
  this.close();
6086
6109
  }}
@@ -6159,7 +6182,7 @@ var MentionPopovers = (_class8 = class {
6159
6182
  this.paint();
6160
6183
  };
6161
6184
  const apply = () => {
6162
- _optionalChain([this, 'access', _217 => _217.host, 'access', _218 => _218.onDateChange, 'optionalCall', _219 => _219(mode.path, toIso(draft))]);
6185
+ _optionalChain([this, 'access', _219 => _219.host, 'access', _220 => _220.onDateChange, 'optionalCall', _221 => _221(mode.path, toIso(draft))]);
6163
6186
  this.close();
6164
6187
  };
6165
6188
  const spin = (key, max2, label) => _preact.h.call(void 0, "label", { class: "markloom-time-field", key }, [
@@ -6322,6 +6345,201 @@ function isToday(y, m, day) {
6322
6345
  // src/view/editor.ts
6323
6346
 
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 = (_class9 = class {
6362
+
6363
+
6364
+
6365
+
6366
+ __init58() {this.peers = []}
6367
+ __init59() {this.self = null}
6368
+ __init60() {this.presenceTimer = null}
6369
+ __init61() {this.lastWire = ""}
6370
+ __init62() {this.onSel = () => this.schedulePresence()}
6371
+ __init63() {this.onScroll = () => this.paintCarets()}
6372
+ __init64() {this.onResize = () => this.paintCarets()}
6373
+ __init65() {this.destroyed = false}
6374
+ constructor(host) {;_class9.prototype.__init58.call(this);_class9.prototype.__init59.call(this);_class9.prototype.__init60.call(this);_class9.prototype.__init61.call(this);_class9.prototype.__init62.call(this);_class9.prototype.__init63.call(this);_class9.prototype.__init64.call(this);_class9.prototype.__init65.call(this);
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: _chunkALZ3A5CScjs.collabColor.call(void 0, siteId, color) };
6397
+ this.paintAvatars();
6398
+ }
6399
+ setPeers(peers) {
6400
+ this.peers = peers.map((p) => ({
6401
+ ...p,
6402
+ color: _chunkALZ3A5CScjs.collabColor.call(void 0, 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 = _chunkYIFOGP2Dcjs.readSelection.call(void 0, 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 || _chunkALZ3A5CScjs.collabColor.call(void 0, p.siteId));
6480
+ el.textContent = _chunkALZ3A5CScjs.collabInitial.call(void 0, 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 (!_optionalChain([p, 'access', _222 => _222.sel, 'optionalAccess', _223 => _223.head]))
6496
+ continue;
6497
+ const pos = posOf(p.sel.head);
6498
+ const dom = _chunkYIFOGP2Dcjs.pointToDom.call(void 0, 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 ? _nullishCoalesce(_optionalChain([n, 'access', _224 => _224.textContent, 'optionalAccess', _225 => _225.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 (e9) {
6509
+ continue;
6510
+ }
6511
+ const rects = range.getClientRects();
6512
+ const rect = _nullishCoalesce(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 || _chunkALZ3A5CScjs.collabColor.call(void 0, 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
+ }, _class9);
6542
+
6325
6543
  // src/view/image-controls.ts
6326
6544
 
6327
6545
  var DRAG_THRESHOLD = 4;
@@ -6348,17 +6566,17 @@ function atomIdsInSelection(doc, sel) {
6348
6566
  }
6349
6567
  return out;
6350
6568
  }
6351
- var ImageControls = (_class9 = class {
6569
+ var ImageControls = (_class10 = class {
6352
6570
 
6353
6571
 
6354
6572
 
6355
6573
  /** 点选 exclusive 块 id(全套柄);与 range 互斥 */
6356
- __init58() {this.exclusiveId = null}
6357
- __init59() {this.rangeIds = /* @__PURE__ */ new Set()}
6358
- __init60() {this.lightbox = null}
6359
- __init61() {this.editingCaption = false}
6360
- __init62() {this.ctxKey = ""}
6361
- constructor(root, host) {;_class9.prototype.__init58.call(this);_class9.prototype.__init59.call(this);_class9.prototype.__init60.call(this);_class9.prototype.__init61.call(this);_class9.prototype.__init62.call(this);_class9.prototype.__init63.call(this);_class9.prototype.__init64.call(this);_class9.prototype.__init65.call(this);_class9.prototype.__init66.call(this);
6574
+ __init66() {this.exclusiveId = null}
6575
+ __init67() {this.rangeIds = /* @__PURE__ */ new Set()}
6576
+ __init68() {this.lightbox = null}
6577
+ __init69() {this.editingCaption = false}
6578
+ __init70() {this.ctxKey = ""}
6579
+ constructor(root, host) {;_class10.prototype.__init66.call(this);_class10.prototype.__init67.call(this);_class10.prototype.__init68.call(this);_class10.prototype.__init69.call(this);_class10.prototype.__init70.call(this);_class10.prototype.__init71.call(this);_class10.prototype.__init72.call(this);_class10.prototype.__init73.call(this);_class10.prototype.__init74.call(this);
6362
6580
  this.root = root;
6363
6581
  this.host = host;
6364
6582
  this.overlay = document.createElement("div");
@@ -6399,7 +6617,7 @@ var ImageControls = (_class9 = class {
6399
6617
  this.host.onAtomSelectChange();
6400
6618
  this.paint();
6401
6619
  }
6402
- __init63() {this.onSelChange = () => {
6620
+ __init71() {this.onSelChange = () => {
6403
6621
  if (this.lightbox)
6404
6622
  return;
6405
6623
  const sel = this.host.sel();
@@ -6410,14 +6628,14 @@ var ImageControls = (_class9 = class {
6410
6628
  this.rangeIds = nextRange;
6411
6629
  this.publishCtx();
6412
6630
  }}
6413
- __init64() {this.onDocDown = (e) => {
6631
+ __init72() {this.onDocDown = (e) => {
6414
6632
  const el = e.target instanceof HTMLElement ? e.target : null;
6415
- if (_optionalChain([el, 'optionalAccess', _228 => _228.closest, 'call', _229 => _229(".markloom-image-overlay")]) || _optionalChain([el, 'optionalAccess', _230 => _230.closest, 'call', _231 => _231(".markloom-lightbox")]))
6633
+ if (_optionalChain([el, 'optionalAccess', _234 => _234.closest, 'call', _235 => _235(".markloom-image-overlay")]) || _optionalChain([el, 'optionalAccess', _236 => _236.closest, 'call', _237 => _237(".markloom-lightbox")]))
6416
6634
  return;
6417
- const atom = _optionalChain([el, 'optionalAccess', _232 => _232.closest, 'call', _233 => _233('[data-atom="image"], [data-atom="embed"]')]);
6635
+ const atom = _optionalChain([el, 'optionalAccess', _238 => _238.closest, 'call', _239 => _239('[data-atom="image"], [data-atom="embed"]')]);
6418
6636
  if (atom && this.root.contains(atom)) {
6419
6637
  const host = atom.dataset.blockId ? atom : atom.closest("[data-block-id]");
6420
- const id = _nullishCoalesce(_nullishCoalesce(_optionalChain([host, 'optionalAccess', _234 => _234.dataset, 'access', _235 => _235.blockId]), () => ( atom.dataset.blockId)), () => ( null));
6638
+ const id = _nullishCoalesce(_nullishCoalesce(_optionalChain([host, 'optionalAccess', _240 => _240.dataset, 'access', _241 => _241.blockId]), () => ( atom.dataset.blockId)), () => ( null));
6421
6639
  if (id && id === this.exclusiveId) {
6422
6640
  if ((_nullishCoalesce(host, () => ( atom))).getAttribute("data-atom") === "image" || atom.closest('[data-atom="image"]'))
6423
6641
  this.lightbox = imgSrc(_nullishCoalesce(host, () => ( atom)));
@@ -6431,11 +6649,11 @@ var ImageControls = (_class9 = class {
6431
6649
  if (this.exclusiveId || this.lightbox || this.rangeIds.size)
6432
6650
  this.clearSelected();
6433
6651
  }}
6434
- __init65() {this.onKeyDown = (e) => {
6652
+ __init73() {this.onKeyDown = (e) => {
6435
6653
  if (e.key === "Escape" && (this.lightbox || this.exclusiveId))
6436
6654
  this.clearSelected();
6437
6655
  }}
6438
- __init66() {this.onReflow = () => {
6656
+ __init74() {this.onReflow = () => {
6439
6657
  if (this.exclusiveId || this.rangeIds.size || this.lightbox)
6440
6658
  this.paint();
6441
6659
  }}
@@ -6540,8 +6758,8 @@ var ImageControls = (_class9 = class {
6540
6758
  _preact.render.call(void 0, kids.length ? _preact.h.call(void 0, "div", { class: "markloom-ic" }, kids) : null, this.overlay);
6541
6759
  }
6542
6760
  toolbar(r) {
6543
- const cur = _nullishCoalesce(_optionalChain([this, 'access', _236 => _236.blockNode, 'call', _237 => _237(), 'optionalAccess', _238 => _238.node, 'access', _239 => _239.attrs, 'optionalAccess', _240 => _240.align]), () => ( "left"));
6544
- const cap = String(_nullishCoalesce(_optionalChain([this, 'access', _241 => _241.blockNode, 'call', _242 => _242(), 'optionalAccess', _243 => _243.node, 'access', _244 => _244.attrs, 'optionalAccess', _245 => _245.caption]), () => ( "")));
6761
+ const cur = _nullishCoalesce(_optionalChain([this, 'access', _242 => _242.blockNode, 'call', _243 => _243(), 'optionalAccess', _244 => _244.node, 'access', _245 => _245.attrs, 'optionalAccess', _246 => _246.align]), () => ( "left"));
6762
+ const cap = String(_nullishCoalesce(_optionalChain([this, 'access', _247 => _247.blockNode, 'call', _248 => _248(), 'optionalAccess', _249 => _249.node, 'access', _250 => _250.attrs, 'optionalAccess', _251 => _251.caption]), () => ( "")));
6545
6763
  const aligns = [
6546
6764
  { value: "left", ico: "align-left", title: "\u5DE6\u5BF9\u9F50" },
6547
6765
  { value: "center", ico: "align-center", title: "\u5C45\u4E2D" },
@@ -6587,7 +6805,7 @@ var ImageControls = (_class9 = class {
6587
6805
  down.preventDefault();
6588
6806
  down.stopPropagation();
6589
6807
  const el = this.exclusiveId ? this.atomEl(this.exclusiveId) : null;
6590
- const img = _optionalChain([el, 'optionalAccess', _246 => _246.matches, 'call', _247 => _247("img")]) ? el : _optionalChain([el, 'optionalAccess', _248 => _248.querySelector, 'call', _249 => _249("img")]);
6808
+ const img = _optionalChain([el, 'optionalAccess', _252 => _252.matches, 'call', _253 => _253("img")]) ? el : _optionalChain([el, 'optionalAccess', _254 => _254.querySelector, 'call', _255 => _255("img")]);
6591
6809
  if (!img)
6592
6810
  return;
6593
6811
  const r = img.getBoundingClientRect();
@@ -6627,10 +6845,10 @@ var ImageControls = (_class9 = class {
6627
6845
  this.exclusiveId = null;
6628
6846
  this.publishCtx();
6629
6847
  }
6630
- }, _class9);
6848
+ }, _class10);
6631
6849
  function imgSrc(atom) {
6632
6850
  const img = atom.matches("img") ? atom : atom.querySelector("img");
6633
- return _nullishCoalesce(_optionalChain([img, 'optionalAccess', _250 => _250.getAttribute, 'call', _251 => _251("src")]), () => ( null));
6851
+ return _nullishCoalesce(_optionalChain([img, 'optionalAccess', _256 => _256.getAttribute, 'call', _257 => _257("src")]), () => ( null));
6634
6852
  }
6635
6853
  function cssEscape3(s) {
6636
6854
  if (typeof CSS !== "undefined" && typeof CSS.escape === "function")
@@ -6647,23 +6865,23 @@ var DRAG_THRESHOLD2 = 4;
6647
6865
  function normRect(r1, c1, r2, c2) {
6648
6866
  return { r1: Math.min(r1, r2), c1: Math.min(c1, c2), r2: Math.max(r1, r2), c2: Math.max(c1, c2) };
6649
6867
  }
6650
- var TableControls = (_class10 = class {
6868
+ var TableControls = (_class11 = class {
6651
6869
 
6652
6870
 
6653
6871
 
6654
- __init67() {this.active = null}
6872
+ __init75() {this.active = null}
6655
6873
  // 当前显示控制柄的表格
6656
- __init68() {this.selectedBlock = null}
6874
+ __init76() {this.selectedBlock = null}
6657
6875
  // 整表被选中(两段删第一段);与 active/sel 正交
6658
- __init69() {this.sel = null}
6659
- __init70() {this.drag = null}
6660
- __init71() {this.resize = null}
6661
- __init72() {this.menu = null}
6662
- __init73() {this.rectDrag = false}
6876
+ __init77() {this.sel = null}
6877
+ __init78() {this.drag = null}
6878
+ __init79() {this.resize = null}
6879
+ __init80() {this.menu = null}
6880
+ __init81() {this.rectDrag = false}
6663
6881
  // 正在拖拽画矩形选区(guard 焦点变动别收起控制柄)
6664
- __init74() {this.blockDrag = null}
6882
+ __init82() {this.blockDrag = null}
6665
6883
  // 整表选中态拖拽移动:落点缝下标(0..n)
6666
- constructor(root, host) {;_class10.prototype.__init67.call(this);_class10.prototype.__init68.call(this);_class10.prototype.__init69.call(this);_class10.prototype.__init70.call(this);_class10.prototype.__init71.call(this);_class10.prototype.__init72.call(this);_class10.prototype.__init73.call(this);_class10.prototype.__init74.call(this);_class10.prototype.__init75.call(this);_class10.prototype.__init76.call(this);_class10.prototype.__init77.call(this);_class10.prototype.__init78.call(this);
6884
+ constructor(root, host) {;_class11.prototype.__init75.call(this);_class11.prototype.__init76.call(this);_class11.prototype.__init77.call(this);_class11.prototype.__init78.call(this);_class11.prototype.__init79.call(this);_class11.prototype.__init80.call(this);_class11.prototype.__init81.call(this);_class11.prototype.__init82.call(this);_class11.prototype.__init83.call(this);_class11.prototype.__init84.call(this);_class11.prototype.__init85.call(this);_class11.prototype.__init86.call(this);
6667
6885
  this.root = root;
6668
6886
  this.host = host;
6669
6887
  this.overlay = document.createElement("div");
@@ -6691,7 +6909,7 @@ var TableControls = (_class10 = class {
6691
6909
  }
6692
6910
  // 选中表的 model 块路径(供 atomBlockGuard 拿定位)。无选中 / 无 id → null。
6693
6911
  selectedBlockPath() {
6694
- const id = _optionalChain([this, 'access', _256 => _256.selectedBlock, 'optionalAccess', _257 => _257.getAttribute, 'call', _258 => _258("data-block-id")]);
6912
+ const id = _optionalChain([this, 'access', _262 => _262.selectedBlock, 'optionalAccess', _263 => _263.getAttribute, 'call', _264 => _264("data-block-id")]);
6695
6913
  return id ? _chunk4TMHVNL6cjs.pathOfId.call(void 0, this.host.doc(), id) : null;
6696
6914
  }
6697
6915
  // 按 model 块 id 选中对应表格(供 atomSelectGuard:光标逼近表 → 先选中而非直删)。选中成功返 true。
@@ -6720,7 +6938,7 @@ var TableControls = (_class10 = class {
6720
6938
  this.paint();
6721
6939
  }
6722
6940
  clearSelected() {
6723
- _optionalChain([this, 'access', _259 => _259.selectedBlock, 'optionalAccess', _260 => _260.removeAttribute, 'call', _261 => _261("data-block-selected")]);
6941
+ _optionalChain([this, 'access', _265 => _265.selectedBlock, 'optionalAccess', _266 => _266.removeAttribute, 'call', _267 => _267("data-block-selected")]);
6724
6942
  this.selectedBlock = null;
6725
6943
  this.paint();
6726
6944
  }
@@ -6786,7 +7004,7 @@ var TableControls = (_class10 = class {
6786
7004
  }
6787
7005
  // 焦点驱动:caret 落在某表格的 cell 内 → 该表控制柄常驻显示;焦点移出表格 → 收起。
6788
7006
  // 不随鼠标 hover 进出闪现(飞书式:聚焦即常驻)。选中/菜单/拖拽进行中不因选区变动收起(柄操作会短暂夺焦)。
6789
- __init75() {this.onSelChange = () => {
7007
+ __init83() {this.onSelChange = () => {
6790
7008
  if (this.selectedBlock)
6791
7009
  return;
6792
7010
  if (this.sel || this.menu || this.drag || this.resize || this.rectDrag)
@@ -6805,18 +7023,18 @@ var TableControls = (_class10 = class {
6805
7023
  // 当前 caret/选区落在哪个表格内(锚点 DOM 往上找 .markloom-table,且在本编辑器根内)。
6806
7024
  focusedTable() {
6807
7025
  const sel = document.getSelection();
6808
- const node = _optionalChain([sel, 'optionalAccess', _262 => _262.anchorNode]);
7026
+ const node = _optionalChain([sel, 'optionalAccess', _268 => _268.anchorNode]);
6809
7027
  if (!node)
6810
7028
  return null;
6811
7029
  const el = node instanceof HTMLElement ? node : node.parentElement;
6812
- const table = _optionalChain([el, 'optionalAccess', _263 => _263.closest, 'call', _264 => _264(".markloom-table")]);
7030
+ const table = _optionalChain([el, 'optionalAccess', _269 => _269.closest, 'call', _270 => _270(".markloom-table")]);
6813
7031
  return table && this.root.contains(table) ? table : null;
6814
7032
  }
6815
- __init76() {this.onReflow = () => {
7033
+ __init84() {this.onReflow = () => {
6816
7034
  if (this.active || this.selectedBlock)
6817
7035
  this.paint();
6818
7036
  }}
6819
- __init77() {this.onKeyDown = (e) => {
7037
+ __init85() {this.onKeyDown = (e) => {
6820
7038
  if (e.key === "Escape" && this.selectedBlock)
6821
7039
  this.clearSelected();
6822
7040
  if ((e.key === "Backspace" || e.key === "Delete") && this.sel && this.active) {
@@ -6854,13 +7072,13 @@ var TableControls = (_class10 = class {
6854
7072
  }
6855
7073
  // 点在控制柄/菜单之外:清选中 + 关菜单。capture 阶段抢在编辑器聚焦前判定。
6856
7074
  // 点在 active 表格某格内 + 拖动 → 画矩形选区(拖过 >1 格时抑制默认光标选择,松手出合并菜单)。
6857
- __init78() {this.onDocDown = (e) => {
7075
+ __init86() {this.onDocDown = (e) => {
6858
7076
  const el = e.target instanceof HTMLElement ? e.target : null;
6859
- if (_optionalChain([el, 'optionalAccess', _265 => _265.closest, 'call', _266 => _266(".markloom-table-overlay")]))
7077
+ if (_optionalChain([el, 'optionalAccess', _271 => _271.closest, 'call', _272 => _272(".markloom-table-overlay")]))
6860
7078
  return;
6861
7079
  if (this.selectedBlock)
6862
7080
  this.clearSelected();
6863
- const cellEl = _optionalChain([el, 'optionalAccess', _267 => _267.closest, 'call', _268 => _268(".markloom-cell")]);
7081
+ const cellEl = _optionalChain([el, 'optionalAccess', _273 => _273.closest, 'call', _274 => _274(".markloom-cell")]);
6864
7082
  const inActive = cellEl && this.active && this.active.contains(cellEl);
6865
7083
  if (inActive) {
6866
7084
  if (this.sel && this.sel.kind !== "rect") {
@@ -6908,7 +7126,7 @@ var TableControls = (_class10 = class {
6908
7126
  const up = () => {
6909
7127
  document.removeEventListener("pointermove", move);
6910
7128
  document.removeEventListener("pointerup", up);
6911
- if (active2 && _optionalChain([this, 'access', _269 => _269.sel, 'optionalAccess', _270 => _270.kind]) === "rect") {
7129
+ if (active2 && _optionalChain([this, 'access', _275 => _275.sel, 'optionalAccess', _276 => _276.kind]) === "rect") {
6912
7130
  const rr = normRect(this.sel.r1, this.sel.c1, this.sel.r2, this.sel.c2);
6913
7131
  if (rr.r1 !== rr.r2 || rr.c1 !== rr.c2)
6914
7132
  this.menu = { kind: "rect" };
@@ -6916,7 +7134,7 @@ var TableControls = (_class10 = class {
6916
7134
  this.sel = null;
6917
7135
  this.applySelClasses();
6918
7136
  this.paint();
6919
- } else if (!active2 && _optionalChain([this, 'access', _271 => _271.sel, 'optionalAccess', _272 => _272.kind]) === "rect") {
7137
+ } else if (!active2 && _optionalChain([this, 'access', _277 => _277.sel, 'optionalAccess', _278 => _278.kind]) === "rect") {
6920
7138
  this.sel = null;
6921
7139
  this.menu = null;
6922
7140
  this.applySelClasses();
@@ -6949,7 +7167,7 @@ var TableControls = (_class10 = class {
6949
7167
  // 整表选中态拖拽移动:按下抓柄超阈值 → 进块拖拽,实时算落点缝(gapAtY)+ 画落点线;松手 dispatch moveBlock。
6950
7168
  // 未超阈值(纯点击)→ 保持选中(selectWhole 已在抓柄 onPointerDown 里做过)。
6951
7169
  beginBlockDrag(tableEl, down) {
6952
- const fromIdx = _optionalChain([this, 'access', _273 => _273.tablePath, 'call', _274 => _274(tableEl), 'optionalAccess', _275 => _275[0]]);
7170
+ const fromIdx = _optionalChain([this, 'access', _279 => _279.tablePath, 'call', _280 => _280(tableEl), 'optionalAccess', _281 => _281[0]]);
6953
7171
  if (fromIdx == null)
6954
7172
  return;
6955
7173
  const startX = down.clientX;
@@ -6982,7 +7200,7 @@ var TableControls = (_class10 = class {
6982
7200
  }
6983
7201
  // 鼠标 y → 顶层块间缝下标(0..n)。遍历 .markloom-doc 结构子(elementChildren 穿透布局层),y 落某块上半 → 该块前缝,下半 → 后缝。
6984
7202
  gapAtY(y) {
6985
- const blocks = _chunkSLRD6FMPcjs.elementChildren.call(void 0, _chunkSLRD6FMPcjs.rootEl.call(void 0, this.root));
7203
+ const blocks = _chunkYIFOGP2Dcjs.elementChildren.call(void 0, _chunkYIFOGP2Dcjs.rootEl.call(void 0, this.root));
6986
7204
  for (let i = 0; i < blocks.length; i++) {
6987
7205
  const r = blocks[i].getBoundingClientRect();
6988
7206
  if (y < (r.top + r.bottom) / 2)
@@ -6994,10 +7212,10 @@ var TableControls = (_class10 = class {
6994
7212
  blockDropLine() {
6995
7213
  if (!this.blockDrag)
6996
7214
  return null;
6997
- const docEl = _chunkSLRD6FMPcjs.rootEl.call(void 0, this.root);
6998
- const blocks = _chunkSLRD6FMPcjs.elementChildren.call(void 0, docEl);
7215
+ const docEl = _chunkYIFOGP2Dcjs.rootEl.call(void 0, this.root);
7216
+ const blocks = _chunkYIFOGP2Dcjs.elementChildren.call(void 0, docEl);
6999
7217
  const gap = this.blockDrag.gap;
7000
- const y = gap === 0 ? _nullishCoalesce(_optionalChain([blocks, 'access', _276 => _276[0], 'optionalAccess', _277 => _277.getBoundingClientRect, 'call', _278 => _278(), 'access', _279 => _279.top]), () => ( 0)) : _nullishCoalesce(_optionalChain([blocks, 'access', _280 => _280[gap - 1], 'optionalAccess', _281 => _281.getBoundingClientRect, 'call', _282 => _282(), 'access', _283 => _283.bottom]), () => ( 0));
7218
+ const y = gap === 0 ? _nullishCoalesce(_optionalChain([blocks, 'access', _282 => _282[0], 'optionalAccess', _283 => _283.getBoundingClientRect, 'call', _284 => _284(), 'access', _285 => _285.top]), () => ( 0)) : _nullishCoalesce(_optionalChain([blocks, 'access', _286 => _286[gap - 1], 'optionalAccess', _287 => _287.getBoundingClientRect, 'call', _288 => _288(), 'access', _289 => _289.bottom]), () => ( 0));
7001
7219
  const box = docEl.getBoundingClientRect();
7002
7220
  return _preact.h.call(void 0, "div", { key: "drop", class: "markloom-tc-drop markloom-tc-drop-row", style: `top:${y}px;left:${box.left}px;width:${box.width}px` });
7003
7221
  }
@@ -7013,10 +7231,10 @@ var TableControls = (_class10 = class {
7013
7231
  const grid = _chunk4TMHVNL6cjs.buildGrid.call(void 0, table);
7014
7232
  if (cells.length !== grid.anchors.length)
7015
7233
  return;
7016
- const rect = _optionalChain([this, 'access', _284 => _284.sel, 'optionalAccess', _285 => _285.kind]) === "rect" ? normRect(this.sel.r1, this.sel.c1, this.sel.r2, this.sel.c2) : null;
7234
+ const rect = _optionalChain([this, 'access', _290 => _290.sel, 'optionalAccess', _291 => _291.kind]) === "rect" ? normRect(this.sel.r1, this.sel.c1, this.sel.r2, this.sel.c2) : null;
7017
7235
  cells.forEach((el, i) => {
7018
7236
  const m = grid.cellOf(grid.anchors[i]);
7019
- const on = _optionalChain([this, 'access', _286 => _286.sel, 'optionalAccess', _287 => _287.kind]) === "all" || _optionalChain([this, 'access', _288 => _288.sel, 'optionalAccess', _289 => _289.kind]) === "row" && m.r <= this.sel.index && this.sel.index < m.r + m.rowspan || _optionalChain([this, 'access', _290 => _290.sel, 'optionalAccess', _291 => _291.kind]) === "col" && m.c <= this.sel.index && this.sel.index < m.c + m.colspan || rect && m.r <= rect.r2 && m.r + m.rowspan - 1 >= rect.r1 && m.c <= rect.c2 && m.c + m.colspan - 1 >= rect.c1;
7237
+ const on = _optionalChain([this, 'access', _292 => _292.sel, 'optionalAccess', _293 => _293.kind]) === "all" || _optionalChain([this, 'access', _294 => _294.sel, 'optionalAccess', _295 => _295.kind]) === "row" && m.r <= this.sel.index && this.sel.index < m.r + m.rowspan || _optionalChain([this, 'access', _296 => _296.sel, 'optionalAccess', _297 => _297.kind]) === "col" && m.c <= this.sel.index && this.sel.index < m.c + m.colspan || rect && m.r <= rect.r2 && m.r + m.rowspan - 1 >= rect.r1 && m.c <= rect.c2 && m.c + m.colspan - 1 >= rect.c1;
7020
7238
  el.toggleAttribute("data-selected", !!on);
7021
7239
  });
7022
7240
  }
@@ -7076,7 +7294,7 @@ var TableControls = (_class10 = class {
7076
7294
  for (let c = 0; c < g.cols; c++) {
7077
7295
  const left = g.colX[c];
7078
7296
  const w = g.colX[c + 1] - g.colX[c];
7079
- const selected = _optionalChain([this, 'access', _292 => _292.sel, 'optionalAccess', _293 => _293.kind]) === "col" && this.sel.index === c;
7297
+ const selected = _optionalChain([this, 'access', _298 => _298.sel, 'optionalAccess', _299 => _299.kind]) === "col" && this.sel.index === c;
7080
7298
  const edge = c === 0 ? " is-first" : c === g.cols - 1 ? " is-last" : "";
7081
7299
  out.push(_preact.h.call(void 0, "div", {
7082
7300
  key: `ch${c}`,
@@ -7092,7 +7310,7 @@ var TableControls = (_class10 = class {
7092
7310
  for (let r = 0; r < g.rows; r++) {
7093
7311
  const top = g.rowY[r];
7094
7312
  const ht = g.rowY[r + 1] - g.rowY[r];
7095
- const selected = _optionalChain([this, 'access', _294 => _294.sel, 'optionalAccess', _295 => _295.kind]) === "row" && this.sel.index === r;
7313
+ const selected = _optionalChain([this, 'access', _300 => _300.sel, 'optionalAccess', _301 => _301.kind]) === "row" && this.sel.index === r;
7096
7314
  const edge = r === 0 ? " is-first" : r === g.rows - 1 ? " is-last" : "";
7097
7315
  out.push(_preact.h.call(void 0, "div", {
7098
7316
  key: `rh${r}`,
@@ -7103,7 +7321,7 @@ var TableControls = (_class10 = class {
7103
7321
  }
7104
7322
  out.push(_preact.h.call(void 0, "div", {
7105
7323
  key: "all",
7106
- class: `markloom-tc-handle markloom-tc-all${_optionalChain([this, 'access', _296 => _296.sel, 'optionalAccess', _297 => _297.kind]) === "all" ? " is-selected" : ""}`,
7324
+ class: `markloom-tc-handle markloom-tc-all${_optionalChain([this, 'access', _302 => _302.sel, 'optionalAccess', _303 => _303.kind]) === "all" ? " is-selected" : ""}`,
7107
7325
  style: `top:${g.rect.top - BAR}px;left:${g.rect.left - BAR}px;width:${BAR}px;height:${BAR}px`,
7108
7326
  onPointerDown: (e) => this.selectAll(e)
7109
7327
  }));
@@ -7112,7 +7330,7 @@ var TableControls = (_class10 = class {
7112
7330
  selectAll(e) {
7113
7331
  e.preventDefault();
7114
7332
  e.stopPropagation();
7115
- if (_optionalChain([this, 'access', _298 => _298.sel, 'optionalAccess', _299 => _299.kind]) === "all")
7333
+ if (_optionalChain([this, 'access', _304 => _304.sel, 'optionalAccess', _305 => _305.kind]) === "all")
7116
7334
  this.menu = { kind: "all", index: 0 };
7117
7335
  else
7118
7336
  this.sel = { kind: "all" };
@@ -7194,7 +7412,7 @@ var TableControls = (_class10 = class {
7194
7412
  const m = this.menu;
7195
7413
  if (!m)
7196
7414
  return null;
7197
- const rect = _optionalChain([this, 'access', _300 => _300.sel, 'optionalAccess', _301 => _301.kind]) === "rect" ? normRect(this.sel.r1, this.sel.c1, this.sel.r2, this.sel.c2) : null;
7415
+ const rect = _optionalChain([this, 'access', _306 => _306.sel, 'optionalAccess', _307 => _307.kind]) === "rect" ? normRect(this.sel.r1, this.sel.c1, this.sel.r2, this.sel.c2) : null;
7198
7416
  const x = m.kind === "col" ? g.colX[m.index] : m.kind === "rect" ? g.colX[rect ? rect.c1 : 0] : g.rect.left - BAR;
7199
7417
  const y = m.kind === "col" ? g.rect.top - BAR : m.kind === "rect" ? g.rowY[rect ? rect.r2 + 1 : 0] : g.rowY[m.index];
7200
7418
  const labels = this.menuLabels(m);
@@ -7253,7 +7471,7 @@ var TableControls = (_class10 = class {
7253
7471
  }
7254
7472
  // 矩形菜单:合并 / 拆分左上格 / 设背景·边框 / 清除。背景色·边框色用 prompt 取值(装饰,非命脉,不做取色器)。
7255
7473
  runRectMenu(g, i) {
7256
- if (_optionalChain([this, 'access', _302 => _302.sel, 'optionalAccess', _303 => _303.kind]) !== "rect")
7474
+ if (_optionalChain([this, 'access', _308 => _308.sel, 'optionalAccess', _309 => _309.kind]) !== "rect")
7257
7475
  return;
7258
7476
  const rr = normRect(this.sel.r1, this.sel.c1, this.sel.r2, this.sel.c2);
7259
7477
  if (i === 0)
@@ -7320,7 +7538,7 @@ var TableControls = (_class10 = class {
7320
7538
  this.drag = null;
7321
7539
  this.paint();
7322
7540
  } else {
7323
- if (_optionalChain([this, 'access', _304 => _304.sel, 'optionalAccess', _305 => _305.kind]) === kind && this.sel.index === index)
7541
+ if (_optionalChain([this, 'access', _310 => _310.sel, 'optionalAccess', _311 => _311.kind]) === kind && this.sel.index === index)
7324
7542
  this.menu = { kind, index };
7325
7543
  else
7326
7544
  this.sel = { kind, index };
@@ -7375,39 +7593,40 @@ var TableControls = (_class10 = class {
7375
7593
  out.push(g.colX[c + 1] - g.colX[c]);
7376
7594
  return out;
7377
7595
  }
7378
- }, _class10);
7596
+ }, _class11);
7379
7597
 
7380
7598
  // src/view/editor.ts
7381
- var Editor = (_class11 = class {
7599
+ var Editor = (_class12 = class {
7382
7600
 
7383
7601
 
7384
- __init79() {this.composing = false}
7385
- __init80() {this.composeBase = null}
7602
+ __init87() {this.composing = false}
7603
+ __init88() {this.composeBase = null}
7386
7604
  // pending marks(对齐 PM storedMarks):塌缩光标 Cmd+B 等切换后,下一次 insertText 带这套 marks。
7387
7605
  // null = 继承所在叶;Mark[] = 强制(可空=明确无 mark)。移光标/点选清空;连续打字保持。
7388
- __init81() {this.pendingMarks = null}
7606
+ __init89() {this.pendingMarks = null}
7389
7607
 
7390
7608
 
7391
7609
  // 显隐符开关(纯投影,不进 model)。setInvisibleCharacters 运行时切。
7392
- __init82() {this.invisible = false}
7610
+ __init90() {this.invisible = false}
7393
7611
  // atom 选中态属内核(方向键选中/atomBlockGuard 直接引用),故 typed 字段;纯浮层走 decorations 循环。
7394
7612
 
7395
7613
 
7396
7614
  // 评论:与 renderState 紧耦合(active/resolved class),typed 字段;装 comments extension 或传 comments option 即开。
7397
- __init83() {this.commentPanel = null}
7615
+ __init91() {this.commentPanel = null}
7398
7616
  // 左侧目录(飞书式 H1–H6 索引)
7399
- __init84() {this.tocPanel = null}
7617
+ __init92() {this.tocPanel = null}
7400
7618
  // mention 点击浮层:person 名片 / date 选择器
7401
7619
 
7402
7620
 
7403
7621
  /** AI 一等公民(opts.ai):斜杠 / 格式栏 / 卡片全内置 */
7404
- __init85() {this.aiCtl = null}
7622
+ __init93() {this.aiCtl = null}
7405
7623
  /** 协作会话;applyingRemote 期间本地 steps 不上行 */
7406
- __init86() {this.collabCtl = null}
7407
- __init87() {this.applyingRemote = false}
7408
- constructor(root, doc, opts = {}) {;_class11.prototype.__init79.call(this);_class11.prototype.__init80.call(this);_class11.prototype.__init81.call(this);_class11.prototype.__init82.call(this);_class11.prototype.__init83.call(this);_class11.prototype.__init84.call(this);_class11.prototype.__init85.call(this);_class11.prototype.__init86.call(this);_class11.prototype.__init87.call(this);_class11.prototype.__init88.call(this);_class11.prototype.__init89.call(this);_class11.prototype.__init90.call(this);_class11.prototype.__init91.call(this);_class11.prototype.__init92.call(this);_class11.prototype.__init93.call(this);_class11.prototype.__init94.call(this);_class11.prototype.__init95.call(this);_class11.prototype.__init96.call(this);_class11.prototype.__init97.call(this);_class11.prototype.__init98.call(this);_class11.prototype.__init99.call(this);_class11.prototype.__init100.call(this);_class11.prototype.__init101.call(this);_class11.prototype.__init102.call(this);_class11.prototype.__init103.call(this);
7624
+ __init94() {this.collabCtl = null}
7625
+ __init95() {this.collabUi = null}
7626
+ __init96() {this.applyingRemote = false}
7627
+ constructor(root, doc, opts = {}) {;_class12.prototype.__init87.call(this);_class12.prototype.__init88.call(this);_class12.prototype.__init89.call(this);_class12.prototype.__init90.call(this);_class12.prototype.__init91.call(this);_class12.prototype.__init92.call(this);_class12.prototype.__init93.call(this);_class12.prototype.__init94.call(this);_class12.prototype.__init95.call(this);_class12.prototype.__init96.call(this);_class12.prototype.__init97.call(this);_class12.prototype.__init98.call(this);_class12.prototype.__init99.call(this);_class12.prototype.__init100.call(this);_class12.prototype.__init101.call(this);_class12.prototype.__init102.call(this);_class12.prototype.__init103.call(this);_class12.prototype.__init104.call(this);_class12.prototype.__init105.call(this);_class12.prototype.__init106.call(this);_class12.prototype.__init107.call(this);_class12.prototype.__init108.call(this);_class12.prototype.__init109.call(this);_class12.prototype.__init110.call(this);_class12.prototype.__init111.call(this);_class12.prototype.__init112.call(this);
7409
7628
  this.root = root;
7410
- const dev = typeof process !== "undefined" && _optionalChain([process, 'access', _371 => _371.env, 'optionalAccess', _372 => _372.NODE_ENV]) !== "production";
7629
+ const dev = typeof process !== "undefined" && _optionalChain([process, 'access', _377 => _377.env, 'optionalAccess', _378 => _378.NODE_ENV]) !== "production";
7411
7630
  this.history = _chunkYXQDCW4Ycjs.init.call(void 0, ensureGaps(doc), dev ? (d) => _chunkYXQDCW4Ycjs.firstViolation.call(void 0, _chunkYXQDCW4Ycjs.invariants.call(void 0, _chunk4TMHVNL6cjs.basicSchema, d)) : void 0);
7412
7631
  this.opts = opts;
7413
7632
  const exts = _nullishCoalesce(opts.extensions, () => ( markloomKit()));
@@ -7430,13 +7649,13 @@ var Editor = (_class11 = class {
7430
7649
  this.imageControls = new ImageControls(root, {
7431
7650
  doc: () => this.history.doc,
7432
7651
  dispatch: (steps) => this.dispatch(steps),
7433
- sel: () => _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc),
7652
+ sel: () => _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc),
7434
7653
  // atomSelect 变 → 重投影 data-selected(与 commentState 同构传 render)
7435
- onAtomSelectChange: () => this.draw(_nullishCoalesce(_chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc), () => ( void 0)))
7654
+ onAtomSelectChange: () => this.draw(_nullishCoalesce(_chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc), () => ( void 0)))
7436
7655
  });
7437
7656
  this.mentionPops = new MentionPopovers({
7438
7657
  root,
7439
- profile: (id) => _optionalChain([this, 'access', _373 => _373.opts, 'access', _374 => _374.mentionProfile, 'optionalCall', _375 => _375(id)]),
7658
+ profile: (id) => _optionalChain([this, 'access', _379 => _379.opts, 'access', _380 => _380.mentionProfile, 'optionalCall', _381 => _381(id)]),
7440
7659
  onDateChange: (path, iso) => this.setMentionDate(path, iso)
7441
7660
  });
7442
7661
  const commentsOn = opts.comments !== void 0 || exts.some((e) => e.name === "comments");
@@ -7446,12 +7665,12 @@ var Editor = (_class11 = class {
7446
7665
  doc: () => this.history.doc,
7447
7666
  dispatch: (steps, sel) => this.dispatch(steps, sel),
7448
7667
  markSel: () => this.markSel(),
7449
- author: _nullishCoalesce(_optionalChain([opts, 'access', _376 => _376.comments, 'optionalAccess', _377 => _377.author]), () => ( (() => ({ id: "me", name: "\u6211" })))),
7668
+ author: _nullishCoalesce(_optionalChain([opts, 'access', _382 => _382.comments, 'optionalAccess', _383 => _383.author]), () => ( (() => ({ id: "me", name: "\u6211" })))),
7450
7669
  newId: newId3,
7451
- redraw: () => this.draw(_nullishCoalesce(_chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc), () => ( void 0))),
7452
- onChange: _optionalChain([opts, 'access', _378 => _378.comments, 'optionalAccess', _379 => _379.onChange]),
7670
+ redraw: () => this.draw(_nullishCoalesce(_chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc), () => ( void 0))),
7671
+ onChange: _optionalChain([opts, 'access', _384 => _384.comments, 'optionalAccess', _385 => _385.onChange]),
7453
7672
  readonly: () => this.readonly
7454
- }, _nullishCoalesce(_optionalChain([opts, 'access', _380 => _380.comments, 'optionalAccess', _381 => _381.threads]), () => ( [])));
7673
+ }, _nullishCoalesce(_optionalChain([opts, 'access', _386 => _386.comments, 'optionalAccess', _387 => _387.threads]), () => ( [])));
7455
7674
  }
7456
7675
  if (opts.toc) {
7457
7676
  this.tocPanel = new TocPanel({ root, doc: () => this.history.doc });
@@ -7460,8 +7679,8 @@ var Editor = (_class11 = class {
7460
7679
  }
7461
7680
  if (opts.ai) {
7462
7681
  const cfg = typeof opts.ai === "object" ? opts.ai : {};
7463
- this.aiCtl = new (0, _chunkSLRD6FMPcjs.MarkloomAi)(() => this, {
7464
- stream: _chunkSLRD6FMPcjs.createAiStream.call(void 0, cfg),
7682
+ this.aiCtl = new (0, _chunkYIFOGP2Dcjs.MarkloomAi)(() => this, {
7683
+ stream: _chunkYIFOGP2Dcjs.createAiStream.call(void 0, cfg),
7465
7684
  onError: _nullishCoalesce(cfg.onError, () => ( ((msg) => {
7466
7685
  if (typeof window !== "undefined")
7467
7686
  window.alert(msg);
@@ -7470,11 +7689,18 @@ var Editor = (_class11 = class {
7470
7689
  });
7471
7690
  }
7472
7691
  if (opts.collab) {
7473
- this.collabCtl = _chunkAC5E42NHcjs.connectCollab.call(void 0,
7692
+ this.collabUi = new CollabPresence({
7693
+ root,
7694
+ doc: () => this.history.doc,
7695
+ collab: () => this.collabCtl
7696
+ });
7697
+ this.collabCtl = _chunkALZ3A5CScjs.connectCollab.call(void 0,
7474
7698
  { ...opts.collab, seed: _nullishCoalesce(opts.collab.seed, () => ( doc)) },
7475
7699
  {
7476
7700
  onDoc: (d) => this.replaceDoc(d),
7477
7701
  onRemote: (steps) => this.applyRemote(steps),
7702
+ onWelcome: (info) => _optionalChain([this, 'access', _388 => _388.collabUi, 'optionalAccess', _389 => _389.setSelf, 'call', _390 => _390(info.siteId, info.name, info.color)]),
7703
+ onPeers: (peers) => _optionalChain([this, 'access', _391 => _391.collabUi, 'optionalAccess', _392 => _392.setPeers, 'call', _393 => _393(peers)]),
7478
7704
  onError: (msg) => {
7479
7705
  if (typeof console !== "undefined")
7480
7706
  console.warn("[markloom collab]", msg);
@@ -7486,13 +7712,13 @@ var Editor = (_class11 = class {
7486
7712
  root,
7487
7713
  doc: () => this.history.doc,
7488
7714
  dispatch: (steps, sel) => this.dispatch(steps, sel),
7489
- sel: () => _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc),
7715
+ sel: () => _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc),
7490
7716
  markSel: () => this.markSel(),
7491
7717
  insertImage: (idx) => this.slashInsertImage(idx),
7492
7718
  insertMath: (idx) => this.slashInsertMath(idx),
7493
7719
  insertEmbed: (idx, kind) => this.slashInsertEmbed(idx, kind),
7494
7720
  insertBelow: (idx) => this.insertBelow(idx),
7495
- langs: () => _nullishCoalesce(_optionalChain([this, 'access', _382 => _382.opts, 'access', _383 => _383.nodeViews, 'optionalAccess', _384 => _384.code, 'optionalAccess', _385 => _385.langs, 'optionalCall', _386 => _386()]), () => ( [])),
7721
+ langs: () => _nullishCoalesce(_optionalChain([this, 'access', _394 => _394.opts, 'access', _395 => _395.nodeViews, 'optionalAccess', _396 => _396.code, 'optionalAccess', _397 => _397.langs, 'optionalCall', _398 => _398()]), () => ( [])),
7496
7722
  mentionSource: () => this.opts.mentionSource,
7497
7723
  // 气泡/Cmd+K:host 注入同步取 URL;未注入时气泡与下方 onKeyDown 走 askInput。
7498
7724
  promptLink: this.opts.promptLink ? () => this.opts.promptLink() : void 0,
@@ -7510,7 +7736,7 @@ var Editor = (_class11 = class {
7510
7736
  if (!this.aiCtl)
7511
7737
  return void 0;
7512
7738
  return (mode) => {
7513
- _optionalChain([this, 'access', _387 => _387.aiCtl, 'optionalAccess', _388 => _388.openAtFocus, 'call', _389 => _389(mode)]);
7739
+ _optionalChain([this, 'access', _399 => _399.aiCtl, 'optionalAccess', _400 => _400.openAtFocus, 'call', _401 => _401(mode)]);
7514
7740
  };
7515
7741
  }
7516
7742
  });
@@ -7521,7 +7747,7 @@ var Editor = (_class11 = class {
7521
7747
  if (!this.aiCtl)
7522
7748
  return void 0;
7523
7749
  return (ctx) => {
7524
- _optionalChain([this, 'access', _390 => _390.aiCtl, 'optionalAccess', _391 => _391.openFromSlash, 'call', _392 => _392(ctx.blockIdx, ctx.query)]);
7750
+ _optionalChain([this, 'access', _402 => _402.aiCtl, 'optionalAccess', _403 => _403.openFromSlash, 'call', _404 => _404(ctx.blockIdx, ctx.query)]);
7525
7751
  };
7526
7752
  }
7527
7753
  });
@@ -7544,10 +7770,12 @@ var Editor = (_class11 = class {
7544
7770
  this.tableControls.destroy();
7545
7771
  this.imageControls.destroy();
7546
7772
  this.mentionPops.destroy();
7547
- _optionalChain([this, 'access', _393 => _393.commentPanel, 'optionalAccess', _394 => _394.destroy, 'call', _395 => _395()]);
7548
- _optionalChain([this, 'access', _396 => _396.tocPanel, 'optionalAccess', _397 => _397.destroy, 'call', _398 => _398()]);
7549
- _optionalChain([this, 'access', _399 => _399.aiCtl, 'optionalAccess', _400 => _400.destroy, 'call', _401 => _401()]);
7550
- _optionalChain([this, 'access', _402 => _402.collabCtl, 'optionalAccess', _403 => _403.close, 'call', _404 => _404()]);
7773
+ _optionalChain([this, 'access', _405 => _405.commentPanel, 'optionalAccess', _406 => _406.destroy, 'call', _407 => _407()]);
7774
+ _optionalChain([this, 'access', _408 => _408.tocPanel, 'optionalAccess', _409 => _409.destroy, 'call', _410 => _410()]);
7775
+ _optionalChain([this, 'access', _411 => _411.aiCtl, 'optionalAccess', _412 => _412.destroy, 'call', _413 => _413()]);
7776
+ _optionalChain([this, 'access', _414 => _414.collabUi, 'optionalAccess', _415 => _415.destroy, 'call', _416 => _416()]);
7777
+ this.collabUi = null;
7778
+ _optionalChain([this, 'access', _417 => _417.collabCtl, 'optionalAccess', _418 => _418.close, 'call', _419 => _419()]);
7551
7779
  this.collabCtl = null;
7552
7780
  this.aiCtl = null;
7553
7781
  for (const d of this.decorations)
@@ -7563,10 +7791,10 @@ var Editor = (_class11 = class {
7563
7791
  return this.collabCtl;
7564
7792
  }
7565
7793
  openAi(mode) {
7566
- _optionalChain([this, 'access', _405 => _405.aiCtl, 'optionalAccess', _406 => _406.openAtFocus, 'call', _407 => _407(mode)]);
7794
+ _optionalChain([this, 'access', _420 => _420.aiCtl, 'optionalAccess', _421 => _421.openAtFocus, 'call', _422 => _422(mode)]);
7567
7795
  }
7568
7796
  stopAi() {
7569
- _optionalChain([this, 'access', _408 => _408.aiCtl, 'optionalAccess', _409 => _409.stop, 'call', _410 => _410()]);
7797
+ _optionalChain([this, 'access', _423 => _423.aiCtl, 'optionalAccess', _424 => _424.stop, 'call', _425 => _425()]);
7570
7798
  }
7571
7799
  get doc() {
7572
7800
  return this.history.doc;
@@ -7579,17 +7807,17 @@ var Editor = (_class11 = class {
7579
7807
  // 运行时切显隐符(tiptap show/hide/toggleInvisibleCharacters 对位)。纯重绘,model 不动。
7580
7808
  setInvisibleCharacters(visible) {
7581
7809
  this.invisible = visible;
7582
- this.draw(_nullishCoalesce(_chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc), () => ( void 0)));
7810
+ this.draw(_nullishCoalesce(_chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc), () => ( void 0)));
7583
7811
  }
7584
7812
  get invisibleCharacters() {
7585
7813
  return this.invisible;
7586
7814
  }
7587
7815
  // 当前评论线程(侧信道);未启用评论时空数组。
7588
7816
  get comments() {
7589
- return _nullishCoalesce(_optionalChain([this, 'access', _411 => _411.commentPanel, 'optionalAccess', _412 => _412.getThreads, 'call', _413 => _413()]), () => ( []));
7817
+ return _nullishCoalesce(_optionalChain([this, 'access', _426 => _426.commentPanel, 'optionalAccess', _427 => _427.getThreads, 'call', _428 => _428()]), () => ( []));
7590
7818
  }
7591
7819
  setComments(threads) {
7592
- _optionalChain([this, 'access', _414 => _414.commentPanel, 'optionalAccess', _415 => _415.setThreads, 'call', _416 => _416(threads)]);
7820
+ _optionalChain([this, 'access', _429 => _429.commentPanel, 'optionalAccess', _430 => _430.setThreads, 'call', _431 => _431(threads)]);
7593
7821
  }
7594
7822
  get readonly() {
7595
7823
  return this.opts.editable === false;
@@ -7607,28 +7835,29 @@ var Editor = (_class11 = class {
7607
7835
  blockRenderers: this.resolved.blockRenderers,
7608
7836
  renderMath: this.opts.renderMath,
7609
7837
  invisibleCharacters: this.invisible,
7610
- commentState: _optionalChain([this, 'access', _417 => _417.commentPanel, 'optionalAccess', _418 => _418.renderState, 'call', _419 => _419()]),
7838
+ commentState: _optionalChain([this, 'access', _432 => _432.commentPanel, 'optionalAccess', _433 => _433.renderState, 'call', _434 => _434()]),
7611
7839
  atomSelect: this.imageControls.selectCtx()
7612
7840
  }), this.root);
7613
7841
  stripStrayNodes(this.root.querySelector(".markloom-doc"));
7614
7842
  if (restore)
7615
- _chunkSLRD6FMPcjs.writeSelection.call(void 0, this.root, this.history.doc, restore);
7843
+ _chunkYIFOGP2Dcjs.writeSelection.call(void 0, this.root, this.history.doc, restore);
7616
7844
  this.root.dispatchEvent(new Event("markloom-redraw", { bubbles: true }));
7617
7845
  this.syncPlaceholder();
7846
+ _optionalChain([this, 'access', _435 => _435.collabUi, 'optionalAccess', _436 => _436.onRedraw, 'call', _437 => _437()]);
7618
7847
  }
7619
7848
  // 空块提示(不进 model):空 paragraph → opts.placeholder(slash 引导);
7620
7849
  // 空 heading → 类型名 H1…H6(飞书/Notion 式)。空文档常显;光标落空块时也显。
7621
- __init88() {this.syncPlaceholder = () => {
7850
+ __init97() {this.syncPlaceholder = () => {
7622
7851
  if (this.composing || this.readonly)
7623
7852
  return;
7624
- const docEl = _chunkSLRD6FMPcjs.rootEl.call(void 0, this.root);
7853
+ const docEl = _chunkYIFOGP2Dcjs.rootEl.call(void 0, this.root);
7625
7854
  for (const el2 of docEl.querySelectorAll("[data-placeholder]"))
7626
7855
  el2.removeAttribute("data-placeholder");
7627
7856
  const kids = this.history.doc.children;
7628
7857
  const isEmptyLeafBlock = (n, type) => !_chunkGQ2HHRGIcjs.isText.call(void 0, n) && n.type === type && n.children.length > 0 && n.children.every((c) => _chunkGQ2HHRGIcjs.isText.call(void 0, c) && c.text === "");
7629
7858
  const labelOf = (n) => {
7630
7859
  if (n.type === "heading") {
7631
- const d = Math.min(Math.max(Number(_nullishCoalesce(_optionalChain([n, 'access', _420 => _420.attrs, 'optionalAccess', _421 => _421.depth]), () => ( 1))), 1), 6);
7860
+ const d = Math.min(Math.max(Number(_nullishCoalesce(_optionalChain([n, 'access', _438 => _438.attrs, 'optionalAccess', _439 => _439.depth]), () => ( 1))), 1), 6);
7632
7861
  return `H${d}`;
7633
7862
  }
7634
7863
  if (n.type === "paragraph" && this.opts.placeholder)
@@ -7645,7 +7874,7 @@ var Editor = (_class11 = class {
7645
7874
  }
7646
7875
  }
7647
7876
  if (idx == null) {
7648
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
7877
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
7649
7878
  if (sel) {
7650
7879
  const a = sel.anchor.path;
7651
7880
  const h13 = sel.head.path;
@@ -7665,7 +7894,7 @@ var Editor = (_class11 = class {
7665
7894
  }
7666
7895
  if (idx == null || text == null)
7667
7896
  return;
7668
- const el = _chunkSLRD6FMPcjs.elementChildren.call(void 0, docEl)[idx];
7897
+ const el = _chunkYIFOGP2Dcjs.elementChildren.call(void 0, docEl)[idx];
7669
7898
  if (el)
7670
7899
  el.setAttribute("data-placeholder", text);
7671
7900
  }}
@@ -7676,9 +7905,9 @@ var Editor = (_class11 = class {
7676
7905
  const batch = steps.concat(gapSteps(after));
7677
7906
  this.history = _chunkYXQDCW4Ycjs.commit.call(void 0, this.history, batch);
7678
7907
  this.draw(selectionAfter);
7679
- _optionalChain([this, 'access', _422 => _422.opts, 'access', _423 => _423.onChange, 'optionalCall', _424 => _424(this.history.doc)]);
7908
+ _optionalChain([this, 'access', _440 => _440.opts, 'access', _441 => _441.onChange, 'optionalCall', _442 => _442(this.history.doc)]);
7680
7909
  if (!this.applyingRemote)
7681
- _optionalChain([this, 'access', _425 => _425.collabCtl, 'optionalAccess', _426 => _426.push, 'call', _427 => _427(batch)]);
7910
+ _optionalChain([this, 'access', _443 => _443.collabCtl, 'optionalAccess', _444 => _444.push, 'call', _445 => _445(batch)]);
7682
7911
  }
7683
7912
  // AI 流式 / 事务内续写:并入 past 最后一条,一次 undo 回退整笔事务。
7684
7913
  dispatchStream(steps, selectionAfter) {
@@ -7688,9 +7917,9 @@ var Editor = (_class11 = class {
7688
7917
  const batch = steps.concat(gapSteps(after));
7689
7918
  this.history = _chunkYXQDCW4Ycjs.amend.call(void 0, this.history, batch);
7690
7919
  this.draw(selectionAfter);
7691
- _optionalChain([this, 'access', _428 => _428.opts, 'access', _429 => _429.onChange, 'optionalCall', _430 => _430(this.history.doc)]);
7920
+ _optionalChain([this, 'access', _446 => _446.opts, 'access', _447 => _447.onChange, 'optionalCall', _448 => _448(this.history.doc)]);
7692
7921
  if (!this.applyingRemote)
7693
- _optionalChain([this, 'access', _431 => _431.collabCtl, 'optionalAccess', _432 => _432.push, 'call', _433 => _433(batch)]);
7922
+ _optionalChain([this, 'access', _449 => _449.collabCtl, 'optionalAccess', _450 => _450.push, 'call', _451 => _451(batch)]);
7694
7923
  }
7695
7924
  /** 远端协作 op:写入 model 但不上行 */
7696
7925
  applyRemote(steps, selectionAfter) {
@@ -7702,17 +7931,17 @@ var Editor = (_class11 = class {
7702
7931
  const batch = steps.concat(gapSteps(after));
7703
7932
  this.history = _chunkYXQDCW4Ycjs.commit.call(void 0, this.history, batch);
7704
7933
  this.draw(selectionAfter);
7705
- _optionalChain([this, 'access', _434 => _434.opts, 'access', _435 => _435.onChange, 'optionalCall', _436 => _436(this.history.doc)]);
7934
+ _optionalChain([this, 'access', _452 => _452.opts, 'access', _453 => _453.onChange, 'optionalCall', _454 => _454(this.history.doc)]);
7706
7935
  } finally {
7707
7936
  this.applyingRemote = false;
7708
7937
  }
7709
7938
  }
7710
7939
  /** 权威快照替换(welcome/resync);清空本地 undo 栈 */
7711
7940
  replaceDoc(doc) {
7712
- const dev = typeof process !== "undefined" && _optionalChain([process, 'access', _437 => _437.env, 'optionalAccess', _438 => _438.NODE_ENV]) !== "production";
7941
+ const dev = typeof process !== "undefined" && _optionalChain([process, 'access', _455 => _455.env, 'optionalAccess', _456 => _456.NODE_ENV]) !== "production";
7713
7942
  this.history = _chunkYXQDCW4Ycjs.init.call(void 0, ensureGaps(doc), dev ? (d) => _chunkYXQDCW4Ycjs.firstViolation.call(void 0, _chunkYXQDCW4Ycjs.invariants.call(void 0, _chunk4TMHVNL6cjs.basicSchema, d)) : void 0);
7714
7943
  this.draw();
7715
- _optionalChain([this, 'access', _439 => _439.opts, 'access', _440 => _440.onChange, 'optionalCall', _441 => _441(this.history.doc)]);
7944
+ _optionalChain([this, 'access', _457 => _457.opts, 'access', _458 => _458.onChange, 'optionalCall', _459 => _459(this.history.doc)]);
7716
7945
  }
7717
7946
  /** 回退一笔 history(AI 事务 discard = undo 整笔) */
7718
7947
  undo() {
@@ -7722,9 +7951,9 @@ var Editor = (_class11 = class {
7722
7951
  return false;
7723
7952
  this.history = next;
7724
7953
  this.draw();
7725
- _optionalChain([this, 'access', _442 => _442.opts, 'access', _443 => _443.onChange, 'optionalCall', _444 => _444(this.history.doc)]);
7954
+ _optionalChain([this, 'access', _460 => _460.opts, 'access', _461 => _461.onChange, 'optionalCall', _462 => _462(this.history.doc)]);
7726
7955
  if (!this.applyingRemote && last)
7727
- _optionalChain([this, 'access', _445 => _445.collabCtl, 'optionalAccess', _446 => _446.push, 'call', _447 => _447(last.inverse)]);
7956
+ _optionalChain([this, 'access', _463 => _463.collabCtl, 'optionalAccess', _464 => _464.push, 'call', _465 => _465(last.inverse)]);
7728
7957
  return true;
7729
7958
  }
7730
7959
  redo() {
@@ -7734,24 +7963,24 @@ var Editor = (_class11 = class {
7734
7963
  return false;
7735
7964
  this.history = next;
7736
7965
  this.draw();
7737
- _optionalChain([this, 'access', _448 => _448.opts, 'access', _449 => _449.onChange, 'optionalCall', _450 => _450(this.history.doc)]);
7966
+ _optionalChain([this, 'access', _466 => _466.opts, 'access', _467 => _467.onChange, 'optionalCall', _468 => _468(this.history.doc)]);
7738
7967
  if (!this.applyingRemote && fut)
7739
- _optionalChain([this, 'access', _451 => _451.collabCtl, 'optionalAccess', _452 => _452.push, 'call', _453 => _453(fut.steps)]);
7968
+ _optionalChain([this, 'access', _469 => _469.collabCtl, 'optionalAccess', _470 => _470.push, 'call', _471 => _471(fut.steps)]);
7740
7969
  return true;
7741
7970
  }
7742
7971
  /** 续写:当前块后插空段并流式灌入 */
7743
7972
  aiContinue(blockId) {
7744
- return _chunkSLRD6FMPcjs.startAiWrite.call(void 0, this, "continue", blockId);
7973
+ return _chunkYIFOGP2Dcjs.startAiWrite.call(void 0, this, "continue", blockId);
7745
7974
  }
7746
7975
  /** 改写:清空当前块再流式回填 */
7747
7976
  aiRewrite(blockId) {
7748
- return _chunkSLRD6FMPcjs.startAiWrite.call(void 0, this, "rewrite", blockId);
7977
+ return _chunkYIFOGP2Dcjs.startAiWrite.call(void 0, this, "rewrite", blockId);
7749
7978
  }
7750
7979
  // 组字开始:快照「这一刻的叶文本」作为 3-way merge 的 base。
7751
7980
  // IME 改动 = diff(base, DOM落定文本);AI 并发改动 = diff(base, model现态)。两者都相对 base。
7752
- __init89() {this.onCompositionStart = () => {
7981
+ __init98() {this.onCompositionStart = () => {
7753
7982
  this.composing = true;
7754
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
7983
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
7755
7984
  if (!sel) {
7756
7985
  this.composeBase = null;
7757
7986
  return;
@@ -7761,11 +7990,11 @@ var Editor = (_class11 = class {
7761
7990
  this.composeBase = { leafPath, text: _chunkGQ2HHRGIcjs.isText.call(void 0, leaf) ? leaf.text : "" };
7762
7991
  }}
7763
7992
  // task 勾选:独立 capture 处理器(见 onTaskCheck)。此处:链接打开 + callout/math/mention。
7764
- __init90() {this.onClick = (e) => {
7993
+ __init99() {this.onClick = (e) => {
7765
7994
  const target = e.target;
7766
- if (_optionalChain([target, 'optionalAccess', _454 => _454.closest, 'optionalCall', _455 => _455("[data-task-check]")]))
7995
+ if (_optionalChain([target, 'optionalAccess', _472 => _472.closest, 'optionalCall', _473 => _473("[data-task-check]")]))
7767
7996
  return;
7768
- const a = _optionalChain([target, 'optionalAccess', _456 => _456.closest, 'optionalCall', _457 => _457('a[data-mark="link"]')]);
7997
+ const a = _optionalChain([target, 'optionalAccess', _474 => _474.closest, 'optionalCall', _475 => _475('a[data-mark="link"]')]);
7769
7998
  if (a && this.root.contains(a)) {
7770
7999
  const href = a.getAttribute("href");
7771
8000
  if (href) {
@@ -7780,10 +8009,10 @@ var Editor = (_class11 = class {
7780
8009
  }
7781
8010
  if (this.readonly)
7782
8011
  return;
7783
- const aiAct = _optionalChain([target, 'optionalAccess', _458 => _458.closest, 'optionalCall', _459 => _459("[data-ai-act]")]);
8012
+ const aiAct = _optionalChain([target, 'optionalAccess', _476 => _476.closest, 'optionalCall', _477 => _477("[data-ai-act]")]);
7784
8013
  if (aiAct && this.root.contains(aiAct) && this.aiCtl) {
7785
8014
  const blockEl = aiAct.closest("[data-ai-block][data-block-id]");
7786
- const id2 = _optionalChain([blockEl, 'optionalAccess', _460 => _460.getAttribute, 'call', _461 => _461("data-block-id")]);
8015
+ const id2 = _optionalChain([blockEl, 'optionalAccess', _478 => _478.getAttribute, 'call', _479 => _479("data-block-id")]);
7787
8016
  const act = aiAct.getAttribute("data-ai-act");
7788
8017
  if (id2 && act) {
7789
8018
  e.preventDefault();
@@ -7792,9 +8021,9 @@ var Editor = (_class11 = class {
7792
8021
  return;
7793
8022
  }
7794
8023
  }
7795
- const chip = _optionalChain([target, 'optionalAccess', _462 => _462.closest, 'optionalCall', _463 => _463("[data-callout-variant]")]);
7796
- const mathEl = _optionalChain([target, 'optionalAccess', _464 => _464.closest, 'optionalCall', _465 => _465('[data-atom="math"]')]);
7797
- const menEl = _optionalChain([target, 'optionalAccess', _466 => _466.closest, 'optionalCall', _467 => _467('[data-atom="mention"]')]);
8024
+ const chip = _optionalChain([target, 'optionalAccess', _480 => _480.closest, 'optionalCall', _481 => _481("[data-callout-variant]")]);
8025
+ const mathEl = _optionalChain([target, 'optionalAccess', _482 => _482.closest, 'optionalCall', _483 => _483('[data-atom="math"]')]);
8026
+ const menEl = _optionalChain([target, 'optionalAccess', _484 => _484.closest, 'optionalCall', _485 => _485('[data-atom="mention"]')]);
7798
8027
  const hit = _nullishCoalesce(_nullishCoalesce(chip, () => ( mathEl)), () => ( menEl));
7799
8028
  if (!hit) {
7800
8029
  this.pendingMarks = null;
@@ -7810,7 +8039,7 @@ var Editor = (_class11 = class {
7810
8039
  this.openMentionPop(menEl);
7811
8040
  return;
7812
8041
  }
7813
- const id = _optionalChain([hit, 'access', _468 => _468.closest, 'call', _469 => _469("[data-block-id]"), 'optionalAccess', _470 => _470.getAttribute, 'call', _471 => _471("data-block-id")]);
8042
+ const id = _optionalChain([hit, 'access', _486 => _486.closest, 'call', _487 => _487("[data-block-id]"), 'optionalAccess', _488 => _488.getAttribute, 'call', _489 => _489("data-block-id")]);
7814
8043
  if (!id)
7815
8044
  return;
7816
8045
  const path = _chunk4TMHVNL6cjs.pathOfId.call(void 0, this.history.doc, id);
@@ -7827,7 +8056,7 @@ var Editor = (_class11 = class {
7827
8056
  }
7828
8057
  }}
7829
8058
  // 任务 checkbox:capture 阶段处理;li[data-task] 定位 list_item,乐观更新 UI 再 commit model。
7830
- __init91() {this.onTaskCheck = (e) => {
8059
+ __init100() {this.onTaskCheck = (e) => {
7831
8060
  if (this.readonly)
7832
8061
  return;
7833
8062
  const t = e.target;
@@ -7845,7 +8074,7 @@ var Editor = (_class11 = class {
7845
8074
  if (!path)
7846
8075
  return;
7847
8076
  const node = _chunk4TMHVNL6cjs.nodeAt.call(void 0, this.history.doc, path);
7848
- if (!node || _chunkGQ2HHRGIcjs.isText.call(void 0, node) || node.type !== "list_item" || _optionalChain([node, 'access', _472 => _472.attrs, 'optionalAccess', _473 => _473.checked]) == null)
8077
+ if (!node || _chunkGQ2HHRGIcjs.isText.call(void 0, node) || node.type !== "list_item" || _optionalChain([node, 'access', _490 => _490.attrs, 'optionalAccess', _491 => _491.checked]) == null)
7849
8078
  return;
7850
8079
  const next = !node.attrs.checked;
7851
8080
  box.checked = next;
@@ -7858,7 +8087,7 @@ var Editor = (_class11 = class {
7858
8087
  }}
7859
8088
  openMentionPop(el) {
7860
8089
  const blockEl = el.closest("[data-block-id]");
7861
- const bid = _optionalChain([blockEl, 'optionalAccess', _474 => _474.getAttribute, 'call', _475 => _475("data-block-id")]);
8090
+ const bid = _optionalChain([blockEl, 'optionalAccess', _492 => _492.getAttribute, 'call', _493 => _493("data-block-id")]);
7862
8091
  if (!bid)
7863
8092
  return;
7864
8093
  const blockPath = _chunk4TMHVNL6cjs.pathOfId.call(void 0, this.history.doc, bid);
@@ -7883,7 +8112,7 @@ var Editor = (_class11 = class {
7883
8112
  return;
7884
8113
  }
7885
8114
  const id = String(_nullishCoalesce(a.id, () => ( "")));
7886
- const fromHost = _optionalChain([this, 'access', _476 => _476.opts, 'access', _477 => _477.mentionProfile, 'optionalCall', _478 => _478(id)]);
8115
+ const fromHost = _optionalChain([this, 'access', _494 => _494.opts, 'access', _495 => _495.mentionProfile, 'optionalCall', _496 => _496(id)]);
7887
8116
  const profile = _nullishCoalesce(fromHost, () => ( {
7888
8117
  id,
7889
8118
  name: typeof a.label === "string" ? a.label : id
@@ -7909,7 +8138,7 @@ var Editor = (_class11 = class {
7909
8138
  };
7910
8139
  this.dispatch([{ kind: "replaceNode", path: blockPath, node: { ...block, children } }]);
7911
8140
  }
7912
- __init92() {this.onBeforeInput = (e) => {
8141
+ __init101() {this.onBeforeInput = (e) => {
7913
8142
  if (this.readonly || this.composing)
7914
8143
  return;
7915
8144
  const intent = intentOf(e.inputType);
@@ -7924,7 +8153,7 @@ var Editor = (_class11 = class {
7924
8153
  }
7925
8154
  if (this.atomBlockGuard(intent, _nullishCoalesce(e.data, () => ( "")), e))
7926
8155
  return;
7927
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8156
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
7928
8157
  if (!sel) {
7929
8158
  e.preventDefault();
7930
8159
  return;
@@ -7952,24 +8181,42 @@ var Editor = (_class11 = 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 && !_chunkGQ2HHRGIcjs.isText.call(void 0, top) && top.type === "paragraph" && _optionalChain([top, 'access', _479 => _479.attrs, 'optionalAccess', _480 => _480.aiDraft])) {
7962
- e.preventDefault();
7963
- return true;
8191
+ if (top && !_chunkGQ2HHRGIcjs.isText.call(void 0, top) && _optionalChain([top, 'access', _497 => _497.attrs, 'optionalAccess', _498 => _498.aiDraft])) {
8192
+ const from = typeof top.attrs.aiFrom === "string" ? top.attrs.aiFrom : "";
8193
+ const live = !!from && this.history.doc.children.some(
8194
+ (c) => !_chunkGQ2HHRGIcjs.isText.call(void 0, 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)
7967
8204
  return false;
7968
- const status = typeof _optionalChain([ai, 'access', _481 => _481.attrs, 'optionalAccess', _482 => _482.status]) === "string" ? ai.attrs.status : "compose";
8205
+ const status = typeof _optionalChain([ai, 'access', _499 => _499.attrs, 'optionalAccess', _500 => _500.status]) === "string" ? ai.attrs.status : "compose";
7969
8206
  if (status === "loading") {
7970
8207
  e.preventDefault();
7971
8208
  return true;
7972
8209
  }
8210
+ if (intent === "deleteBackward") {
8211
+ const prompt = ai.children[0];
8212
+ const empty = !prompt || _chunkGQ2HHRGIcjs.isText.call(void 0, prompt) || !_chunkGQ2HHRGIcjs.isText.call(void 0, prompt) && prompt.type === "paragraph" && prompt.children.every((c) => _chunkGQ2HHRGIcjs.isText.call(void 0, 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 = (_class11 = 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 (!_chunkGQ2HHRGIcjs.isText.call(void 0, 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 (_chunkGQ2HHRGIcjs.isText.call(void 0, c) || !_optionalChain([c, 'access', _501 => _501.attrs, 'optionalAccess', _502 => _502.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)无内容可护,放行删空块。
@@ -8058,7 +8334,7 @@ var Editor = (_class11 = class {
8058
8334
  const caret3 = range.getBoundingClientRect();
8059
8335
  if (caret3.width === 0 && caret3.height === 0)
8060
8336
  return false;
8061
- const blockEl = _chunkSLRD6FMPcjs.elementChildren.call(void 0, _chunkSLRD6FMPcjs.rootEl.call(void 0, this.root))[topIdx];
8337
+ const blockEl = _chunkYIFOGP2Dcjs.elementChildren.call(void 0, _chunkYIFOGP2Dcjs.rootEl.call(void 0, this.root))[topIdx];
8062
8338
  if (!blockEl)
8063
8339
  return false;
8064
8340
  const box = blockEl.getBoundingClientRect();
@@ -8186,7 +8462,7 @@ var Editor = (_class11 = class {
8186
8462
  // intentOf 不认的删变体(word/line 删)在代码块边界的守卫:跨块涉码 / 塌缩在 code 对应边 → preventDefault(挡浏览器并块)。
8187
8463
  // 非边界(代码块中段)不接管,放行——与 codeBlockGuard 的「只收边界、放行叶内」一致,不过度拦。
8188
8464
  codeBoundaryDelete(dir, e) {
8189
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8465
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8190
8466
  if (!sel)
8191
8467
  return;
8192
8468
  if (this.straddlesAtom(sel)) {
@@ -8209,7 +8485,7 @@ var Editor = (_class11 = class {
8209
8485
  // 到 cell/文档真边界 mapInput 才返 null)——「删空本行/本段后再删能退上去」的语义由此路径提供。
8210
8486
  // 一律 preventDefault(否则浏览器原生删破 DOM≡doc,后续 readSelection 读脏 DOM 返 null → 打字被吞)。
8211
8487
  wordLineDelete(dir, inputType, e) {
8212
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8488
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8213
8489
  if (!sel) {
8214
8490
  e.preventDefault();
8215
8491
  return;
@@ -8235,18 +8511,18 @@ var Editor = (_class11 = class {
8235
8511
  // 正解是 3-way merge:base=组字前叶文本快照。IME 改动 = diff(base, DOM 落定文本)——
8236
8512
  // 这是「相对 base 的纯 IME 局部编辑」,不含 AI 的并发改动。把它作为 Step 施加到 model 当前态,
8237
8513
  // AI 在同段别处的改动得以保留(diff(model,DOM) 会把 AI 改动误当删除——那是错的)。
8238
- __init93() {this.onCompositionEnd = () => {
8514
+ __init102() {this.onCompositionEnd = () => {
8239
8515
  this.composing = false;
8240
8516
  const base = this.composeBase;
8241
8517
  this.composeBase = null;
8242
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8518
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8243
8519
  if (!sel || !base) {
8244
8520
  this.draw();
8245
8521
  return;
8246
8522
  }
8247
8523
  const leafPath = base.leafPath;
8248
- const dom = _chunkSLRD6FMPcjs.pointToDom.call(void 0, this.root, this.history.doc, { path: leafPath.concat(0) });
8249
- const domText = (_optionalChain([dom, 'optionalAccess', _483 => _483.node]) && isDomText(dom.node) ? _nullishCoalesce(dom.node.textContent, () => ( "")) : "").replaceAll("\u200B", "");
8524
+ const dom = _chunkYIFOGP2Dcjs.pointToDom.call(void 0, this.root, this.history.doc, { path: leafPath.concat(0) });
8525
+ const domText = (_optionalChain([dom, 'optionalAccess', _503 => _503.node]) && isDomText(dom.node) ? _nullishCoalesce(dom.node.textContent, () => ( "")) : "").replaceAll("\u200B", "");
8250
8526
  const edit = diffSpan(base.text, domText);
8251
8527
  if (!edit) {
8252
8528
  this.draw();
@@ -8263,7 +8539,7 @@ var Editor = (_class11 = class {
8263
8539
  }
8264
8540
  this.dispatch(steps, caretAfter(leafPath, edit.at + edit.insert.length));
8265
8541
  }}
8266
- __init94() {this.onKeyDown = (e) => {
8542
+ __init103() {this.onKeyDown = (e) => {
8267
8543
  if (this.readonly)
8268
8544
  return;
8269
8545
  const mod2 = e.metaKey || e.ctrlKey;
@@ -8301,7 +8577,7 @@ var Editor = (_class11 = class {
8301
8577
  }
8302
8578
  selCtrl.clearSelected();
8303
8579
  const target = exitBack ? [nbrIdx, ..._chunk4TMHVNL6cjs.lastLeafEnd.call(void 0, nbr)] : [nbrIdx, ..._chunk4TMHVNL6cjs.firstLeafPath.call(void 0, nbr), 0];
8304
- _chunkSLRD6FMPcjs.writeSelection.call(void 0, this.root, doc, { anchor: { path: target }, head: { path: target } });
8580
+ _chunkYIFOGP2Dcjs.writeSelection.call(void 0, this.root, doc, { anchor: { path: target }, head: { path: target } });
8305
8581
  return;
8306
8582
  }
8307
8583
  selCtrl.clearSelected();
@@ -8309,7 +8585,7 @@ var Editor = (_class11 = class {
8309
8585
  }
8310
8586
  }
8311
8587
  if ((exitBack || exitFwd) && !mod2 && !e.shiftKey && !selCtrl) {
8312
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8588
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8313
8589
  if (sel) {
8314
8590
  const dir = exitBack ? "back" : "fwd";
8315
8591
  const hit = _nullishCoalesce(this.atomAtEdge(sel, dir), () => ( (e.key === "ArrowUp" || e.key === "ArrowDown" ? this.atomAtEdgeVertical(sel, dir) : null)));
@@ -8329,7 +8605,7 @@ var Editor = (_class11 = class {
8329
8605
  return;
8330
8606
  }
8331
8607
  if (e.key === "Tab" && !e.shiftKey && !mod2) {
8332
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8608
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8333
8609
  if (sel && this.isCodeBlock(sel.head.path.slice(0, -2))) {
8334
8610
  const result = mapInput(this.history.doc, "insertText", " ", sel, newId3);
8335
8611
  if (result) {
@@ -8347,8 +8623,8 @@ var Editor = (_class11 = class {
8347
8623
  }
8348
8624
  }
8349
8625
  if (e.key === "Tab" && e.shiftKey && !mod2) {
8350
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8351
- const blockPath = _optionalChain([sel, 'optionalAccess', _484 => _484.head, 'access', _485 => _485.path, 'access', _486 => _486.slice, 'call', _487 => _487(0, -2)]);
8626
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8627
+ const blockPath = _optionalChain([sel, 'optionalAccess', _504 => _504.head, 'access', _505 => _505.path, 'access', _506 => _506.slice, 'call', _507 => _507(0, -2)]);
8352
8628
  if (sel && blockPath && this.isCodeBlock(blockPath)) {
8353
8629
  e.preventDefault();
8354
8630
  const leafPath = sel.head.path.slice(0, -1);
@@ -8384,10 +8660,10 @@ var Editor = (_class11 = class {
8384
8660
  e.preventDefault();
8385
8661
  let rect = new DOMRect(0, 0, 0, 0);
8386
8662
  try {
8387
- const r = _optionalChain([document, 'access', _488 => _488.getSelection, 'call', _489 => _489(), 'optionalAccess', _490 => _490.getRangeAt, 'call', _491 => _491(0), 'optionalAccess', _492 => _492.getBoundingClientRect, 'call', _493 => _493()]);
8663
+ const r = _optionalChain([document, 'access', _508 => _508.getSelection, 'call', _509 => _509(), 'optionalAccess', _510 => _510.getRangeAt, 'call', _511 => _511(0), 'optionalAccess', _512 => _512.getBoundingClientRect, 'call', _513 => _513()]);
8388
8664
  if (r && (r.width || r.height))
8389
8665
  rect = r;
8390
- } catch (e10) {
8666
+ } catch (e11) {
8391
8667
  }
8392
8668
  void askLinkPopover({ anchor: rect }).then((url) => {
8393
8669
  if (!url)
@@ -8400,7 +8676,7 @@ var Editor = (_class11 = class {
8400
8676
  }
8401
8677
  const cmd = mod2 ? this.resolved.keymap[chord(e)] : void 0;
8402
8678
  if (cmd) {
8403
- const r = cmd({ doc: this.history.doc, sel: _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc), markSel: this.markSel(), promptLink: this.opts.promptLink });
8679
+ const r = cmd({ doc: this.history.doc, sel: _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc), markSel: this.markSel(), promptLink: this.opts.promptLink });
8404
8680
  if (!r)
8405
8681
  return;
8406
8682
  e.preventDefault();
@@ -8408,7 +8684,7 @@ var Editor = (_class11 = class {
8408
8684
  this.pendingMarks = null;
8409
8685
  this.history = r.history === "undo" ? _chunkYXQDCW4Ycjs.undo.call(void 0, this.history) : _chunkYXQDCW4Ycjs.redo.call(void 0, this.history);
8410
8686
  this.draw();
8411
- _optionalChain([this, 'access', _494 => _494.opts, 'access', _495 => _495.onChange, 'optionalCall', _496 => _496(this.history.doc)]);
8687
+ _optionalChain([this, 'access', _514 => _514.opts, 'access', _515 => _515.onChange, 'optionalCall', _516 => _516(this.history.doc)]);
8412
8688
  return;
8413
8689
  }
8414
8690
  if ("pendingToggle" in r) {
@@ -8424,7 +8700,7 @@ var Editor = (_class11 = class {
8424
8700
  return;
8425
8701
  }
8426
8702
  if (mod2 && !e.shiftKey && (e.key === "a" || e.key === "A")) {
8427
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8703
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8428
8704
  if (!sel)
8429
8705
  return;
8430
8706
  const blockPath = sel.head.path.slice(0, -2);
@@ -8432,7 +8708,7 @@ var Editor = (_class11 = class {
8432
8708
  return;
8433
8709
  e.preventDefault();
8434
8710
  const len = leafText2(this.history.doc, [...blockPath, 0]).length;
8435
- _chunkSLRD6FMPcjs.writeSelection.call(void 0,
8711
+ _chunkYIFOGP2Dcjs.writeSelection.call(void 0,
8436
8712
  this.root,
8437
8713
  this.history.doc,
8438
8714
  { anchor: { path: [...blockPath, 0, 0] }, head: { path: [...blockPath, 0, len] } }
@@ -8443,7 +8719,7 @@ var Editor = (_class11 = class {
8443
8719
  // 代码块 model 是单纯文本叶,docToMd 只读首叶裸 text——加 mark 轻则渲幽灵 strong/save 后消失,
8444
8720
  // 重则 toggleMark 把单叶按区间切成多叶,leaves(n)[0] 只取首叶 → 存盘丢码。marks 在代码块无语义,直接挡。
8445
8721
  markSel() {
8446
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8722
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8447
8723
  if (!sel)
8448
8724
  return null;
8449
8725
  if (this.isCodeBlock(sel.anchor.path.slice(0, -2)) || this.isCodeBlock(sel.head.path.slice(0, -2)))
@@ -8451,37 +8727,37 @@ var Editor = (_class11 = class {
8451
8727
  return sel;
8452
8728
  }
8453
8729
  // 复制/剪切/粘贴:选区 ⟷ markdown。md 是 markloom 的唯一真值,剪贴板也走 md,跨编辑器/外部可读。
8454
- __init95() {this.onCopy = (e) => {
8455
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8730
+ __init104() {this.onCopy = (e) => {
8731
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8456
8732
  if (!sel)
8457
8733
  return;
8458
8734
  const md = serializeSelection(this.history.doc, sel);
8459
8735
  if (!md)
8460
8736
  return;
8461
8737
  e.preventDefault();
8462
- _optionalChain([e, 'access', _497 => _497.clipboardData, 'optionalAccess', _498 => _498.setData, 'call', _499 => _499("text/plain", md)]);
8738
+ _optionalChain([e, 'access', _517 => _517.clipboardData, 'optionalAccess', _518 => _518.setData, 'call', _519 => _519("text/plain", md)]);
8463
8739
  }}
8464
- __init96() {this.onCut = (e) => {
8740
+ __init105() {this.onCut = (e) => {
8465
8741
  if (this.readonly) {
8466
8742
  e.preventDefault();
8467
8743
  return;
8468
8744
  }
8469
8745
  e.preventDefault();
8470
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8746
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8471
8747
  if (!sel)
8472
8748
  return;
8473
8749
  const md = serializeSelection(this.history.doc, sel);
8474
8750
  if (!md)
8475
8751
  return;
8476
- _optionalChain([e, 'access', _500 => _500.clipboardData, 'optionalAccess', _501 => _501.setData, 'call', _502 => _502("text/plain", md)]);
8752
+ _optionalChain([e, 'access', _520 => _520.clipboardData, 'optionalAccess', _521 => _521.setData, 'call', _522 => _522("text/plain", md)]);
8477
8753
  const del = mapInput(this.history.doc, "deleteForward", "", sel, newId3);
8478
8754
  if (del)
8479
8755
  this.dispatch(del.steps, del.selection);
8480
8756
  }}
8481
- __init97() {this.onPaste = (e) => {
8757
+ __init106() {this.onPaste = (e) => {
8482
8758
  if (this.readonly || this.composing)
8483
8759
  return;
8484
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
8760
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8485
8761
  if (!sel)
8486
8762
  return;
8487
8763
  const inCode = this.isCodeBlock(sel.head.path.slice(0, -2));
@@ -8492,15 +8768,15 @@ var Editor = (_class11 = class {
8492
8768
  this.insertImageFile(file, sel);
8493
8769
  return;
8494
8770
  }
8495
- const htmlUrl = imgSrcFromHtml(_optionalChain([e, 'access', _503 => _503.clipboardData, 'optionalAccess', _504 => _504.getData, 'call', _505 => _505("text/html")]));
8496
- if (htmlUrl && !_optionalChain([e, 'access', _506 => _506.clipboardData, 'optionalAccess', _507 => _507.getData, 'call', _508 => _508("text/plain")])) {
8771
+ const htmlUrl = imgSrcFromHtml(_optionalChain([e, 'access', _523 => _523.clipboardData, 'optionalAccess', _524 => _524.getData, 'call', _525 => _525("text/html")]));
8772
+ if (htmlUrl && !_optionalChain([e, 'access', _526 => _526.clipboardData, 'optionalAccess', _527 => _527.getData, 'call', _528 => _528("text/plain")])) {
8497
8773
  e.preventDefault();
8498
8774
  this.insertImageUrl(htmlUrl, sel);
8499
8775
  return;
8500
8776
  }
8501
8777
  }
8502
- const raw = _nullishCoalesce(_optionalChain([e, 'access', _509 => _509.clipboardData, 'optionalAccess', _510 => _510.getData, 'call', _511 => _511("text/plain")]), () => ( ""));
8503
- const html = _nullishCoalesce(_optionalChain([e, 'access', _512 => _512.clipboardData, 'optionalAccess', _513 => _513.getData, 'call', _514 => _514("text/html")]), () => ( ""));
8778
+ const raw = _nullishCoalesce(_optionalChain([e, 'access', _529 => _529.clipboardData, 'optionalAccess', _530 => _530.getData, 'call', _531 => _531("text/plain")]), () => ( ""));
8779
+ const html = _nullishCoalesce(_optionalChain([e, 'access', _532 => _532.clipboardData, 'optionalAccess', _533 => _533.getData, 'call', _534 => _534("text/html")]), () => ( ""));
8504
8780
  if (inCode) {
8505
8781
  if (!raw && !html)
8506
8782
  return;
@@ -8567,12 +8843,12 @@ var Editor = (_class11 = class {
8567
8843
  }
8568
8844
  // 斜杠 /image:开原生文件选择,选中后把触发段(blockIdx,含 `/image`)整块替换成 image atom。
8569
8845
  // 复用 onImage 上传钩子(未注入退回 data: URL)。取消选择 → 不动 model。
8570
- __init98() {this.slashInsertImage = (blockIdx) => {
8846
+ __init107() {this.slashInsertImage = (blockIdx) => {
8571
8847
  const input = this.root.ownerDocument.createElement("input");
8572
8848
  input.type = "file";
8573
8849
  input.accept = "image/*";
8574
8850
  input.onchange = () => {
8575
- const file = _optionalChain([input, 'access', _515 => _515.files, 'optionalAccess', _516 => _516[0]]);
8851
+ const file = _optionalChain([input, 'access', _535 => _535.files, 'optionalAccess', _536 => _536[0]]);
8576
8852
  if (!file)
8577
8853
  return;
8578
8854
  const to = this.opts.onImage ? this.opts.onImage(file) : new Promise((resolve2, reject) => {
@@ -8590,7 +8866,7 @@ var Editor = (_class11 = class {
8590
8866
  input.click();
8591
8867
  }}
8592
8868
  // 斜杠 /math → 当前段换成含 math atom 的段(display block)。
8593
- __init99() {this.slashInsertMath = (blockIdx) => {
8869
+ __init108() {this.slashInsertMath = (blockIdx) => {
8594
8870
  void askInput({
8595
8871
  title: "\u63D2\u5165\u516C\u5F0F",
8596
8872
  description: "\u8F93\u5165 LaTeX\uFF0C\u4F8B\u5982 E=mc^2 \u6216 \\frac{a}{b}",
@@ -8608,13 +8884,13 @@ var Editor = (_class11 = class {
8608
8884
  });
8609
8885
  }}
8610
8886
  // 斜杠 /youtube|/twitch|/audio|/file → embed 块。file/audio 走文件选择;yt/twitch 弹 URL。
8611
- __init100() {this.slashInsertEmbed = (blockIdx, kind) => {
8887
+ __init109() {this.slashInsertEmbed = (blockIdx, kind) => {
8612
8888
  if (kind === "file" || kind === "audio") {
8613
8889
  const input = this.root.ownerDocument.createElement("input");
8614
8890
  input.type = "file";
8615
8891
  input.accept = kind === "audio" ? "audio/*" : "*/*";
8616
8892
  input.onchange = () => {
8617
- const file = _optionalChain([input, 'access', _517 => _517.files, 'optionalAccess', _518 => _518[0]]);
8893
+ const file = _optionalChain([input, 'access', _537 => _537.files, 'optionalAccess', _538 => _538[0]]);
8618
8894
  if (!file)
8619
8895
  return;
8620
8896
  const to = this.opts.onImage ? this.opts.onImage(file) : new Promise((resolve2, reject) => {
@@ -8662,7 +8938,7 @@ var Editor = (_class11 = class {
8662
8938
  // 点 math atom → 弹层改 latex。叶路径:块 data-block-id + data-leaf 下标。
8663
8939
  editMathAtom(mathEl) {
8664
8940
  const blockEl = mathEl.closest("[data-block-id]");
8665
- const id = _optionalChain([blockEl, 'optionalAccess', _519 => _519.getAttribute, 'call', _520 => _520("data-block-id")]);
8941
+ const id = _optionalChain([blockEl, 'optionalAccess', _539 => _539.getAttribute, 'call', _540 => _540("data-block-id")]);
8666
8942
  if (!id)
8667
8943
  return;
8668
8944
  const blockPath = _chunk4TMHVNL6cjs.pathOfId.call(void 0, this.history.doc, id);
@@ -8678,7 +8954,7 @@ var Editor = (_class11 = class {
8678
8954
  const atom = block.children[leafIdx];
8679
8955
  if (_chunkGQ2HHRGIcjs.isText.call(void 0, atom) || atom.type !== "math")
8680
8956
  return;
8681
- const cur = String(_nullishCoalesce(_optionalChain([atom, 'access', _521 => _521.attrs, 'optionalAccess', _522 => _522.latex]), () => ( "")));
8957
+ const cur = String(_nullishCoalesce(_optionalChain([atom, 'access', _541 => _541.attrs, 'optionalAccess', _542 => _542.latex]), () => ( "")));
8682
8958
  void askInput({
8683
8959
  title: "\u7F16\u8F91\u516C\u5F0F",
8684
8960
  description: "\u4FEE\u6539 LaTeX \u6E90\u7801",
@@ -8711,7 +8987,7 @@ var Editor = (_class11 = class {
8711
8987
  }
8712
8988
  // floating menu(+ 柄):在 blockIdx 下方插一个只含 `/` 的空段,光标落 `/` 之后,派 input 事件唤起斜杠菜单。
8713
8989
  // 复用 SlashMenu 的 onInput 触发路径(菜单只认「行首 `/`」),FloatingMenu 不需自己造菜单——+ 只是「打 /」的快捷。
8714
- __init101() {this.insertBelow = (blockIdx) => {
8990
+ __init110() {this.insertBelow = (blockIdx) => {
8715
8991
  if (this.readonly)
8716
8992
  return;
8717
8993
  const id = newId3();
@@ -8742,7 +9018,7 @@ var Editor = (_class11 = class {
8742
9018
  // 找到 head 路径上的 table 祖先 → 当前 (r,c) → nextCell → 把光标写到目标格首段首叶。
8743
9019
  // caret 落在哪个表格的哪一格。沿 head 找第一个 type==='table' 祖先块 → {tablePath, table, r, c}。
8744
9020
  tableCaret() {
8745
- const sel = _chunkSLRD6FMPcjs.readSelection.call(void 0, this.root, this.history.doc);
9021
+ const sel = _chunkYIFOGP2Dcjs.readSelection.call(void 0, this.root, this.history.doc);
8746
9022
  if (!sel)
8747
9023
  return null;
8748
9024
  const head = sel.head.path;
@@ -8803,11 +9079,11 @@ var Editor = (_class11 = class {
8803
9079
  // 飞书式行列高亮:焦点落入某 cell → 同行同列所有 cell 加标记属性(主题给浅色背景)。
8804
9080
  // 纯 DOM 投影,不碰 model:语义表格里 td 嵌在 tbody>tr 下,用后代选择器收(文档序即行优先);
8805
9081
  // 列数从 tr 的 cell 数读(每行等列)。同表换格时 focusout 先清 focusin 再标,同帧内同步完成不闪。
8806
- __init102() {this.onFocusIn = (e) => {
9082
+ __init111() {this.onFocusIn = (e) => {
8807
9083
  if (!(e.target instanceof HTMLElement))
8808
9084
  return;
8809
9085
  const cell = e.target.closest(".markloom-cell");
8810
- const table = _optionalChain([cell, 'optionalAccess', _523 => _523.closest, 'call', _524 => _524(".markloom-table")]);
9086
+ const table = _optionalChain([cell, 'optionalAccess', _543 => _543.closest, 'call', _544 => _544(".markloom-table")]);
8811
9087
  if (!cell || !table)
8812
9088
  return;
8813
9089
  const id = table.getAttribute("data-block-id");
@@ -8828,10 +9104,10 @@ var Editor = (_class11 = class {
8828
9104
  el.toggleAttribute("data-highlight-col", sameCol);
8829
9105
  });
8830
9106
  }}
8831
- __init103() {this.onFocusOut = (e) => {
9107
+ __init112() {this.onFocusOut = (e) => {
8832
9108
  if (!(e.target instanceof HTMLElement))
8833
9109
  return;
8834
- const table = _optionalChain([e, 'access', _525 => _525.target, 'access', _526 => _526.closest, 'call', _527 => _527(".markloom-cell"), 'optionalAccess', _528 => _528.closest, 'call', _529 => _529(".markloom-table")]);
9110
+ const table = _optionalChain([e, 'access', _545 => _545.target, 'access', _546 => _546.closest, 'call', _547 => _547(".markloom-cell"), 'optionalAccess', _548 => _548.closest, 'call', _549 => _549(".markloom-table")]);
8835
9111
  if (!table)
8836
9112
  return;
8837
9113
  table.querySelectorAll(".markloom-cell").forEach((el) => {
@@ -8839,7 +9115,7 @@ var Editor = (_class11 = class {
8839
9115
  el.removeAttribute("data-highlight-col");
8840
9116
  });
8841
9117
  }}
8842
- }, _class11);
9118
+ }, _class12);
8843
9119
  function chord(e) {
8844
9120
  const key = e.key.length === 1 ? e.key.toLowerCase() : e.key;
8845
9121
  return `Mod-${e.shiftKey ? "Shift-" : ""}${key}`;
@@ -8869,7 +9145,7 @@ function intentOf(inputType) {
8869
9145
  }
8870
9146
  }
8871
9147
  function newId3() {
8872
- return _nullishCoalesce(_optionalChain([globalThis, 'access', _530 => _530.crypto, 'optionalAccess', _531 => _531.randomUUID, 'optionalCall', _532 => _532()]), () => ( `b-${Math.random().toString(36).slice(2)}`));
9148
+ return _nullishCoalesce(_optionalChain([globalThis, 'access', _550 => _550.crypto, 'optionalAccess', _551 => _551.randomUUID, 'optionalCall', _552 => _552()]), () => ( `b-${Math.random().toString(36).slice(2)}`));
8873
9149
  }
8874
9150
  function pathOfTaskItem(doc, root, li) {
8875
9151
  const id = li.getAttribute("data-block-id");
@@ -8888,7 +9164,7 @@ function pathOfTaskItem(doc, root, li) {
8888
9164
  const list = _chunk4TMHVNL6cjs.nodeAt.call(void 0, doc, listPath);
8889
9165
  if (!list || _chunkGQ2HHRGIcjs.isText.call(void 0, list) || list.type !== "list")
8890
9166
  return null;
8891
- const items = _chunkSLRD6FMPcjs.elementChildren.call(void 0, listEl);
9167
+ const items = _chunkYIFOGP2Dcjs.elementChildren.call(void 0, listEl);
8892
9168
  const idx = items.indexOf(li);
8893
9169
  if (idx < 0 || idx >= list.children.length)
8894
9170
  return null;
@@ -8963,7 +9239,7 @@ function imgSrcFromHtml(html) {
8963
9239
  return null;
8964
9240
  const body = new DOMParser().parseFromString(html, "text/html").body;
8965
9241
  const imgs = body.querySelectorAll("img");
8966
- if (imgs.length !== 1 || _optionalChain([body, 'access', _533 => _533.textContent, 'optionalAccess', _534 => _534.trim, 'call', _535 => _535()]))
9242
+ if (imgs.length !== 1 || _optionalChain([body, 'access', _553 => _553.textContent, 'optionalAccess', _554 => _554.trim, 'call', _555 => _555()]))
8967
9243
  return null;
8968
9244
  return imgs[0].getAttribute("src");
8969
9245
  }