@8btc/mditor 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.7 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.8 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2742,11 +2742,11 @@ var Vditor = /** @class */ (function () {
2742
2742
  * 外部更新行号:传入实例并根据配置进行同步/节流更新
2743
2743
  */
2744
2744
  Vditor.updateLineNumbers = function (instance, immediate) {
2745
- var _a, _b;
2745
+ var _a, _b, _c;
2746
2746
  if (immediate === void 0) { immediate = false; }
2747
2747
  try {
2748
2748
  var v = (_a = instance === null || instance === void 0 ? void 0 : instance.vditor) !== null && _a !== void 0 ? _a : instance;
2749
- if (!((_b = v === null || v === void 0 ? void 0 : v.options) === null || _b === void 0 ? void 0 : _b.lineNumber))
2749
+ if (!((_c = (_b = v === null || v === void 0 ? void 0 : v.options) === null || _b === void 0 ? void 0 : _b.lineNumber) === null || _c === void 0 ? void 0 : _c.enable))
2750
2750
  return;
2751
2751
  var text = (0,getMarkdown/* getMarkdown */.O)(v);
2752
2752
  var root = v[v.currentMode].element;
@@ -2757,7 +2757,7 @@ var Vditor = /** @class */ (function () {
2757
2757
  (0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(root, text);
2758
2758
  }
2759
2759
  }
2760
- catch (_c) { }
2760
+ catch (_d) { }
2761
2761
  };
2762
2762
  /** 点击图片放大 */
2763
2763
  Vditor.adapterRender = adapterRender;
@@ -2818,7 +2818,7 @@ var Vditor = /** @class */ (function () {
2818
2818
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2819
2819
  /* harmony export */ "g": () => (/* binding */ Constants)
2820
2820
  /* harmony export */ });
2821
- var _VDITOR_VERSION = "0.0.7";
2821
+ var _VDITOR_VERSION = "0.0.8";
2822
2822
 
2823
2823
  var Constants = /** @class */ (function () {
2824
2824
  function Constants() {
@@ -3120,7 +3120,7 @@ var Constants = /** @class */ (function () {
3120
3120
  "c#",
3121
3121
  "bat",
3122
3122
  ];
3123
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.7");
3123
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.8");
3124
3124
  Constants.MARKDOWN_OPTIONS = {
3125
3125
  autoSpace: false,
3126
3126
  gfmAutoLink: true,
@@ -9073,13 +9073,14 @@ var initUI = function (vditor) {
9073
9073
  };
9074
9074
  // 计算并设置编辑区左右 padding,适配预览最大宽度与大纲位置
9075
9075
  var setPadding = function (vditor) {
9076
+ var _a, _b;
9076
9077
  var minPadding = window.innerWidth <= constants/* Constants.MOBILE_WIDTH */.g.MOBILE_WIDTH ? 10 : 24;
9077
9078
  if (vditor.wysiwyg.element.parentElement.style.display !== "none") {
9078
9079
  var padding = (vditor.wysiwyg.element.parentElement.clientWidth -
9079
9080
  vditor.options.preview.maxWidth) /
9080
9081
  2;
9081
9082
  var basePad = Math.max(minPadding, padding);
9082
- var leftExtra = vditor.options.lineNumber && basePad < 40 ? 20 : 0;
9083
+ var leftExtra = ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) && basePad < 40 ? 20 : 0;
9083
9084
  vditor.wysiwyg.element.style.padding = "10px ".concat(basePad, "px 10px ").concat(basePad + leftExtra, "px");
9084
9085
  }
9085
9086
  if (vditor.ir.element.parentElement.style.display !== "none") {
@@ -9087,7 +9088,7 @@ var setPadding = function (vditor) {
9087
9088
  vditor.options.preview.maxWidth) /
9088
9089
  2;
9089
9090
  var basePad = Math.max(minPadding, padding);
9090
- var leftExtra = vditor.options.lineNumber && basePad < 40 ? 20 : 0;
9091
+ var leftExtra = ((_b = vditor.options.lineNumber) === null || _b === void 0 ? void 0 : _b.enable) && basePad < 40 ? 20 : 0;
9091
9092
  vditor.ir.element.style.padding = "10px ".concat(basePad, "px 10px ").concat(basePad + leftExtra, "px");
9092
9093
  }
9093
9094
  if (vditor.preview.element.style.display !== "block") {
@@ -9261,6 +9262,7 @@ var afterRenderEvent = function (vditor, options) {
9261
9262
  }
9262
9263
  clearTimeout(vditor.wysiwyg.afterRenderTimeoutId);
9263
9264
  vditor.wysiwyg.afterRenderTimeoutId = window.setTimeout(function () {
9265
+ var _a;
9264
9266
  if (vditor.wysiwyg.composingLock) {
9265
9267
  return;
9266
9268
  }
@@ -9284,11 +9286,11 @@ var afterRenderEvent = function (vditor, options) {
9284
9286
  vditor.undo.addToUndoStack(vditor);
9285
9287
  }
9286
9288
  try {
9287
- if (vditor.options.lineNumber) {
9289
+ if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
9288
9290
  (0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(vditor.wysiwyg.element, text);
9289
9291
  }
9290
9292
  }
9291
- catch (_a) {
9293
+ catch (_b) {
9292
9294
  void 0;
9293
9295
  }
9294
9296
  }, vditor.options.undoDelay);
@@ -10894,6 +10896,7 @@ var highlightToolbar = function (vditor) {
10894
10896
 
10895
10897
 
10896
10898
  var renderDomByMd = function (vditor, md, options) {
10899
+ var _a;
10897
10900
  if (options === void 0) { options = {
10898
10901
  enableAddUndoStack: true,
10899
10902
  enableHint: false,
@@ -10907,11 +10910,11 @@ var renderDomByMd = function (vditor, md, options) {
10907
10910
  processCodeRender(item, vditor);
10908
10911
  item.previousElementSibling.setAttribute("style", "display:none");
10909
10912
  });
10910
- if (vditor.options.lineNumber) {
10913
+ if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
10911
10914
  try {
10912
10915
  (0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(editorElement, md);
10913
10916
  }
10914
- catch (_a) {
10917
+ catch (_b) {
10915
10918
  void 0;
10916
10919
  }
10917
10920
  }
@@ -11562,7 +11565,7 @@ var blurEvent = function (vditor, editorElement) {
11562
11565
  }
11563
11566
  else if (vditor.currentMode === "wysiwyg" &&
11564
11567
  !vditor.wysiwyg.selectPopover.contains(event.relatedTarget)) {
11565
- vditor.wysiwyg.hideComment();
11568
+ vditor.wysiwyg.hideSelectionPopover();
11566
11569
  }
11567
11570
  vditor[vditor.currentMode].range = (0,selection/* getEditorRange */.zh)(vditor);
11568
11571
  if (vditor.options.blur) {
@@ -11580,7 +11583,8 @@ var dropEvent = function (vditor, editorElement) {
11580
11583
  // 编辑器内选中文字拖拽
11581
11584
  execAfterRender(vditor);
11582
11585
  }
11583
- else if (event.dataTransfer.types.includes("Files") || event.dataTransfer.types.includes("text/html")) {
11586
+ else if (event.dataTransfer.types.includes("Files") ||
11587
+ event.dataTransfer.types.includes("text/html")) {
11584
11588
  // 外部文件拖入编辑器中或者编辑器内选中文字拖拽
11585
11589
  paste(vditor, event, {
11586
11590
  pasteCode: function (code) {
@@ -11591,7 +11595,9 @@ var dropEvent = function (vditor, editorElement) {
11591
11595
  });
11592
11596
  };
11593
11597
  var copyEvent = function (vditor, editorElement, copy) {
11594
- editorElement.addEventListener("copy", function (event) { return copy(event, vditor); });
11598
+ editorElement.addEventListener("copy", function (event) {
11599
+ return copy(event, vditor);
11600
+ });
11595
11601
  };
11596
11602
  var cutEvent = function (vditor, editorElement, copy) {
11597
11603
  editorElement.addEventListener("cut", function (event) {
@@ -11612,11 +11618,21 @@ var scrollCenter = function (vditor) {
11612
11618
  }
11613
11619
  var editorElement = vditor[vditor.currentMode].element;
11614
11620
  var cursorTop = (0,selection/* getCursorPosition */.Ny)(editorElement).top;
11615
- if (vditor.options.height === "auto" && !vditor.element.classList.contains("vditor--fullscreen")) {
11616
- window.scrollTo(window.scrollX, cursorTop + vditor.element.offsetTop + vditor.toolbar.element.offsetHeight - window.innerHeight / 2 + 10);
11617
- }
11618
- if (vditor.options.height !== "auto" || vditor.element.classList.contains("vditor--fullscreen")) {
11619
- editorElement.scrollTop = cursorTop + editorElement.scrollTop - editorElement.clientHeight / 2 + 10;
11621
+ if (vditor.options.height === "auto" &&
11622
+ !vditor.element.classList.contains("vditor--fullscreen")) {
11623
+ window.scrollTo(window.scrollX, cursorTop +
11624
+ vditor.element.offsetTop +
11625
+ vditor.toolbar.element.offsetHeight -
11626
+ window.innerHeight / 2 +
11627
+ 10);
11628
+ }
11629
+ if (vditor.options.height !== "auto" ||
11630
+ vditor.element.classList.contains("vditor--fullscreen")) {
11631
+ editorElement.scrollTop =
11632
+ cursorTop +
11633
+ editorElement.scrollTop -
11634
+ editorElement.clientHeight / 2 +
11635
+ 10;
11620
11636
  }
11621
11637
  };
11622
11638
  var hotkeyEvent = function (vditor, editorElement) {
@@ -11625,12 +11641,14 @@ var hotkeyEvent = function (vditor, editorElement) {
11625
11641
  vditor.options.keydown(event);
11626
11642
  }
11627
11643
  // hint: 上下选择
11628
- if ((vditor.options.hint.extend.length > 1 || vditor.toolbar.elements.emoji) &&
11644
+ if ((vditor.options.hint.extend.length > 1 ||
11645
+ vditor.toolbar.elements.emoji) &&
11629
11646
  vditor.hint.select(event, vditor)) {
11630
11647
  return;
11631
11648
  }
11632
11649
  // 重置 comment
11633
- if (vditor.options.comment.enable && vditor.currentMode === "wysiwyg" &&
11650
+ if (vditor.options.comment.enable &&
11651
+ vditor.currentMode === "wysiwyg" &&
11634
11652
  (event.key === "Backspace" || matchHotKey("⌘X", event))) {
11635
11653
  vditor.wysiwyg.getComments(vditor);
11636
11654
  }
@@ -11678,7 +11696,10 @@ var hotkeyEvent = function (vditor, editorElement) {
11678
11696
  return;
11679
11697
  }
11680
11698
  // h1 - h6 hotkey
11681
- if ((0,compatibility/* isCtrl */.yl)(event) && event.altKey && !event.shiftKey && /^Digit[1-6]$/.test(event.code)) {
11699
+ if ((0,compatibility/* isCtrl */.yl)(event) &&
11700
+ event.altKey &&
11701
+ !event.shiftKey &&
11702
+ /^Digit[1-6]$/.test(event.code)) {
11682
11703
  if (vditor.currentMode === "wysiwyg") {
11683
11704
  var tagName = event.code.replace("Digit", "H");
11684
11705
  if ((0,hasClosest/* hasClosestByMatchTag */.lG)(getSelection().getRangeAt(0).startContainer, tagName)) {
@@ -11699,7 +11720,10 @@ var hotkeyEvent = function (vditor, editorElement) {
11699
11720
  return true;
11700
11721
  }
11701
11722
  // toggle edit mode
11702
- if ((0,compatibility/* isCtrl */.yl)(event) && event.altKey && !event.shiftKey && /^Digit[7-9]$/.test(event.code)) {
11723
+ if ((0,compatibility/* isCtrl */.yl)(event) &&
11724
+ event.altKey &&
11725
+ !event.shiftKey &&
11726
+ /^Digit[7-9]$/.test(event.code)) {
11703
11727
  if (event.code === "Digit7") {
11704
11728
  setEditMode(vditor, "wysiwyg", event);
11705
11729
  }
@@ -11720,8 +11744,7 @@ var hotkeyEvent = function (vditor, editorElement) {
11720
11744
  return false;
11721
11745
  }
11722
11746
  if (matchHotKey(subMenuItem.hotkey, event)) {
11723
- vditor.toolbar.elements[subMenuItem.name].children[0]
11724
- .dispatchEvent(new CustomEvent((0,compatibility/* getEventName */.Le)()));
11747
+ vditor.toolbar.elements[subMenuItem.name].children[0].dispatchEvent(new CustomEvent((0,compatibility/* getEventName */.Le)()));
11725
11748
  event.preventDefault();
11726
11749
  return true;
11727
11750
  }
@@ -11739,41 +11762,80 @@ var hotkeyEvent = function (vditor, editorElement) {
11739
11762
  });
11740
11763
  };
11741
11764
  /**
11742
- * 选区事件处理:根据选中内容触发回调与评论按钮展示
11743
- * - 当启用评论模式且开启内联面板时,显示评论按钮面板
11765
+ * 选区事件处理(含防抖):根据选中内容显示/隐藏选择浮窗
11766
+ * - 受 options.selectionPopover.enable 控制
11767
+ * - 防抖间隔使用 options.selectionPopover.debounceDelay(默认 150ms)
11744
11768
  */
11745
11769
  var selectEvent = function (vditor, editorElement) {
11746
- editorElement.addEventListener("selectstart", function (event) {
11747
- editorElement.onmouseup = function () {
11748
- setTimeout(function () {
11749
- var _a;
11750
- var selectText = getSelectText(vditor[vditor.currentMode].element);
11751
- if (selectText.trim()) {
11752
- if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
11753
- if (!(0,hasClosest/* hasClosestByAttribute */.a1)(event.target, "data-type", "footnotes-block") &&
11754
- !(0,hasClosest/* hasClosestByAttribute */.a1)(event.target, "data-type", "link-ref-defs-block")) {
11755
- if ((_a = vditor.options.inlinePopover) === null || _a === void 0 ? void 0 : _a.enable) {
11756
- vditor.wysiwyg.showComment();
11757
- }
11758
- }
11759
- else {
11760
- vditor.wysiwyg.hideComment();
11761
- }
11762
- }
11763
- if (vditor.options.select) {
11764
- vditor.options.select(selectText);
11765
- }
11770
+ var _a, _b;
11771
+ var debounceTimer = 0;
11772
+ var delay = (_b = (_a = vditor.options.selectionPopover) === null || _a === void 0 ? void 0 : _a.debounceDelay) !== null && _b !== void 0 ? _b : 150;
11773
+ /**
11774
+ * 统一处理选择状态:根据选区内容显示/隐藏选择浮窗
11775
+ * - 鼠标拖选、键盘选择、触摸选择、系统 selectionchange
11776
+ */
11777
+ var handleSelection = function () {
11778
+ window.clearTimeout(debounceTimer);
11779
+ debounceTimer = window.setTimeout(function () {
11780
+ var _a;
11781
+ var selectText = getSelectText(vditor[vditor.currentMode].element);
11782
+ if (selectText.trim()) {
11783
+ if (vditor.currentMode === "wysiwyg" &&
11784
+ ((_a = vditor.options.selectionPopover) === null || _a === void 0 ? void 0 : _a.enable)) {
11785
+ vditor.wysiwyg.showSelectionPopover();
11766
11786
  }
11767
- else {
11768
- if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
11769
- vditor.wysiwyg.hideComment();
11770
- }
11771
- if (typeof vditor.options.unSelect === 'function') {
11772
- vditor.options.unSelect();
11787
+ if (vditor.options.select) {
11788
+ vditor.options.select(selectText);
11789
+ }
11790
+ }
11791
+ else {
11792
+ if (vditor.currentMode === "wysiwyg") {
11793
+ vditor.wysiwyg.hideSelectionPopover();
11794
+ }
11795
+ if (typeof vditor.options.unSelect === "function") {
11796
+ vditor.options.unSelect();
11797
+ }
11798
+ }
11799
+ }, delay);
11800
+ };
11801
+ // 鼠标拖选结束
11802
+ editorElement.addEventListener("mouseup", function () { return handleSelection(); });
11803
+ // 触摸选择结束(移动端)
11804
+ editorElement.addEventListener("touchend", function () { return handleSelection(); }, {
11805
+ passive: true,
11806
+ });
11807
+ // 键盘选择(Shift+方向键/Home/End 等)
11808
+ editorElement.addEventListener("keyup", function (event) {
11809
+ if (event.isComposing) {
11810
+ return;
11811
+ }
11812
+ handleSelection();
11813
+ });
11814
+ // 系统选区变化(跨端通用,仅处理编辑器内选区)
11815
+ document.addEventListener("selectionchange", function () {
11816
+ if (!(0,selection/* selectIsEditor */.Gb)(vditor[vditor.currentMode].element)) {
11817
+ return;
11818
+ }
11819
+ handleSelection();
11820
+ });
11821
+ // 点击空白区域时隐藏浮窗并清理选区
11822
+ editorElement.addEventListener("click", function () {
11823
+ var selection = window.getSelection();
11824
+ var hadSelection = !!selection && selection.toString().trim() !== "";
11825
+ window.setTimeout(function () {
11826
+ var selectText = getSelectText(vditor[vditor.currentMode].element);
11827
+ if (!selectText.trim()) {
11828
+ if (vditor.currentMode === "wysiwyg") {
11829
+ vditor.wysiwyg.hideSelectionPopover();
11830
+ }
11831
+ if (hadSelection) {
11832
+ try {
11833
+ selection.removeAllRanges();
11773
11834
  }
11835
+ catch (_a) { }
11774
11836
  }
11775
- });
11776
- };
11837
+ }
11838
+ }, 0);
11777
11839
  });
11778
11840
  };
11779
11841
 
@@ -11922,15 +11984,16 @@ var processAfterRender = function (vditor, options) {
11922
11984
  }
11923
11985
  clearTimeout(vditor.sv.processTimeoutId);
11924
11986
  vditor.sv.processTimeoutId = window.setTimeout(function () {
11987
+ var _a;
11925
11988
  if (options.enableAddUndoStack && !vditor.sv.composingLock) {
11926
11989
  vditor.undo.addToUndoStack(vditor);
11927
11990
  }
11928
11991
  try {
11929
- if (vditor.options.lineNumber) {
11992
+ if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
11930
11993
  (0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(vditor.sv.element, text);
11931
11994
  }
11932
11995
  }
11933
- catch (_a) {
11996
+ catch (_b) {
11934
11997
  void 0;
11935
11998
  }
11936
11999
  }, vditor.options.undoDelay);
@@ -14366,6 +14429,7 @@ var process_processAfterRender = function (vditor, options) {
14366
14429
  }
14367
14430
  clearTimeout(vditor.ir.processTimeoutId);
14368
14431
  vditor.ir.processTimeoutId = window.setTimeout(function () {
14432
+ var _a;
14369
14433
  if (vditor.ir.composingLock) {
14370
14434
  return;
14371
14435
  }
@@ -14389,11 +14453,11 @@ var process_processAfterRender = function (vditor, options) {
14389
14453
  vditor.undo.addToUndoStack(vditor);
14390
14454
  }
14391
14455
  try {
14392
- if (vditor.options.lineNumber) {
14456
+ if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
14393
14457
  (0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(vditor.ir.element, text);
14394
14458
  }
14395
14459
  }
14396
- catch (_a) {
14460
+ catch (_b) {
14397
14461
  void 0;
14398
14462
  }
14399
14463
  }, vditor.options.undoDelay);
@@ -14909,10 +14973,11 @@ var Hint = /** @class */ (function () {
14909
14973
 
14910
14974
  var IR = /** @class */ (function () {
14911
14975
  function IR(vditor) {
14976
+ var _a;
14912
14977
  this.composingLock = false;
14913
14978
  var divElement = document.createElement("div");
14914
14979
  divElement.className = "vditor-ir";
14915
- if (vditor.options.lineNumber) {
14980
+ if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
14916
14981
  divElement.classList.add("vditor--linenumber");
14917
14982
  }
14918
14983
  divElement.innerHTML = "<pre class=\"vditor-reset\" placeholder=\"".concat(vditor.options.placeholder, "\"\n contenteditable=\"true\" spellcheck=\"false\"></pre>");
@@ -15491,10 +15556,11 @@ var Resize = /** @class */ (function () {
15491
15556
 
15492
15557
  var Editor = /** @class */ (function () {
15493
15558
  function Editor(vditor) {
15559
+ var _a;
15494
15560
  this.composingLock = false;
15495
15561
  this.element = document.createElement("pre");
15496
15562
  this.element.className = "vditor-sv vditor-reset";
15497
- if (vditor.options.lineNumber) {
15563
+ if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
15498
15564
  this.element.classList.add("vditor--linenumber");
15499
15565
  }
15500
15566
  this.element.setAttribute("placeholder", vditor.options.placeholder);
@@ -17375,6 +17441,10 @@ var Options = /** @class */ (function () {
17375
17441
  inlinePopover: {
17376
17442
  enable: false,
17377
17443
  },
17444
+ selectionPopover: {
17445
+ enable: false,
17446
+ debounceDelay: 150,
17447
+ },
17378
17448
  cache: {
17379
17449
  enable: true,
17380
17450
  },
@@ -17484,7 +17554,10 @@ var Options = /** @class */ (function () {
17484
17554
  pin: false,
17485
17555
  },
17486
17556
  typewriterMode: false,
17487
- lineNumber: false,
17557
+ lineNumber: {
17558
+ enable: false,
17559
+ highlightTimer: 1500,
17560
+ },
17488
17561
  undoDelay: 800,
17489
17562
  upload: {
17490
17563
  extraData: {},
@@ -17805,6 +17878,42 @@ var Options = /** @class */ (function () {
17805
17878
 
17806
17879
 
17807
17880
  ;// CONCATENATED MODULE: ./src/ts/wysiwyg/index.ts
17881
+ var wysiwyg_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
17882
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
17883
+ return new (P || (P = Promise))(function (resolve, reject) {
17884
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17885
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17886
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17887
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
17888
+ });
17889
+ };
17890
+ var wysiwyg_generator = (undefined && undefined.__generator) || function (thisArg, body) {
17891
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
17892
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
17893
+ function verb(n) { return function (v) { return step([n, v]); }; }
17894
+ function step(op) {
17895
+ if (f) throw new TypeError("Generator is already executing.");
17896
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17897
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
17898
+ if (y = 0, t) op = [op[0] & 2, t.value];
17899
+ switch (op[0]) {
17900
+ case 0: case 1: t = op; break;
17901
+ case 4: _.label++; return { value: op[1], done: false };
17902
+ case 5: _.label++; y = op[1]; op = [0]; continue;
17903
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
17904
+ default:
17905
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
17906
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
17907
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
17908
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
17909
+ if (t[2]) _.ops.pop();
17910
+ _.trys.pop(); continue;
17911
+ }
17912
+ op = body.call(thisArg, _);
17913
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
17914
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
17915
+ }
17916
+ };
17808
17917
 
17809
17918
 
17810
17919
 
@@ -17824,14 +17933,15 @@ var Options = /** @class */ (function () {
17824
17933
  var WYSIWYG = /** @class */ (function () {
17825
17934
  function WYSIWYG(vditor) {
17826
17935
  var _this = this;
17936
+ var _a;
17827
17937
  this.composingLock = false;
17828
17938
  this.commentIds = [];
17829
17939
  var divElement = document.createElement("div");
17830
17940
  divElement.className = "vditor-wysiwyg";
17831
- if (vditor.options.lineNumber) {
17941
+ if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
17832
17942
  divElement.classList.add("vditor--linenumber");
17833
17943
  }
17834
- divElement.innerHTML = "<pre class=\"vditor-reset\" placeholder=\"".concat(vditor.options.placeholder, "\"\n contenteditable=\"true\" spellcheck=\"false\"></pre>\n<div class=\"vditor-panel vditor-panel--none\"></div>\n<div class=\"vditor-panel vditor-panel--none\">\n <button type=\"button\" aria-label=\"").concat(window.VditorI18n.comment, "\" class=\"vditor-icon vditor-tooltipped vditor-tooltipped__n\">\n <svg><use xlink:href=\"#vditor-icon-comment\"></use></svg>\n </button>\n</div>");
17944
+ divElement.innerHTML = "<pre class=\"vditor-reset\" placeholder=\"".concat(vditor.options.placeholder, "\"\n contenteditable=\"true\" spellcheck=\"false\"></pre>\n<div class=\"vditor-panel vditor-panel--none\"></div>\n<div class=\"vditor-selection-popover\">\n <button type=\"button\" data-action=\"ai\" aria-label=\"AI\u7F16\u8F91\" class=\"vditor-selection-popover__btn\" disabled>\u2728 AI\u7F16\u8F91</button>\n <button type=\"button\" data-action=\"cut\" aria-label=\"\u526A\u5207\" class=\"vditor-selection-popover__btn\">\u526A\u5207</button>\n <button type=\"button\" data-action=\"copy\" aria-label=\"\u590D\u5236\" class=\"vditor-selection-popover__btn\">\u590D\u5236</button>\n</div>");
17835
17945
  this.element = divElement.firstElementChild;
17836
17946
  this.popover = divElement.firstElementChild
17837
17947
  .nextElementSibling;
@@ -17845,98 +17955,134 @@ var WYSIWYG = /** @class */ (function () {
17845
17955
  dropEvent(vditor, this.element);
17846
17956
  copyEvent(vditor, this.element, this.copy);
17847
17957
  cutEvent(vditor, this.element, this.copy);
17958
+ // 选择浮窗按钮事件绑定
17959
+ var aiBtn = this.selectPopover.querySelector('[data-action="ai"]');
17960
+ if (aiBtn) {
17961
+ /**
17962
+ * AI编辑按钮占位事件
17963
+ * - 当前仅输出日志,不执行编辑逻辑
17964
+ */
17965
+ aiBtn.onclick = function () {
17966
+ console.log("[Selection AI Edit] clicked");
17967
+ };
17968
+ }
17969
+ var copyBtn = this.selectPopover.querySelector('[data-action="copy"]');
17970
+ if (copyBtn) {
17971
+ /**
17972
+ * 复制按钮点击处理
17973
+ * - 优先使用 Clipboard API;降级为 execCommand('copy')
17974
+ */
17975
+ copyBtn.onclick = function () {
17976
+ _this.copySelection(vditor);
17977
+ };
17978
+ }
17979
+ var cutBtn = this.selectPopover.querySelector('[data-action="cut"]');
17980
+ if (cutBtn) {
17981
+ /**
17982
+ * 剪切按钮点击处理
17983
+ * - 将选区复制到剪贴板后删除,并接入撤销栈
17984
+ */
17985
+ cutBtn.onclick = function () {
17986
+ _this.cutSelection(vditor);
17987
+ };
17988
+ }
17989
+ // 评论按钮仅在启用时注册(避免选择浮窗结构变化导致报错)
17848
17990
  if (vditor.options.comment.enable) {
17849
- this.selectPopover.querySelector("button").onclick = function () {
17850
- var id = Lute.NewNodeID();
17851
- var range = getSelection().getRangeAt(0);
17852
- var rangeClone = range.cloneRange();
17853
- var contents = range.extractContents();
17854
- var blockStartElement;
17855
- var blockEndElement;
17856
- var removeStart = false;
17857
- var removeEnd = false;
17858
- contents.childNodes.forEach(function (item, index) {
17859
- var wrap = false;
17860
- if (item.nodeType === 3) {
17861
- wrap = true;
17862
- }
17863
- else if (!item.classList.contains("vditor-comment")) {
17864
- wrap = true;
17865
- }
17866
- else if (item.classList.contains("vditor-comment")) {
17867
- item.setAttribute("data-cmtids", item.getAttribute("data-cmtids") + " " + id);
17868
- }
17869
- if (wrap) {
17870
- if (item.nodeType !== 3 &&
17871
- item.getAttribute("data-block") === "0" &&
17872
- index === 0 &&
17873
- rangeClone.startOffset > 0) {
17874
- item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17875
- blockStartElement = item;
17991
+ var commentBtn = this.selectPopover.querySelector('[data-action="comment"]');
17992
+ if (commentBtn) {
17993
+ commentBtn.onclick = function () {
17994
+ var id = Lute.NewNodeID();
17995
+ var range = getSelection().getRangeAt(0);
17996
+ var rangeClone = range.cloneRange();
17997
+ var contents = range.extractContents();
17998
+ var blockStartElement;
17999
+ var blockEndElement;
18000
+ var removeStart = false;
18001
+ var removeEnd = false;
18002
+ contents.childNodes.forEach(function (item, index) {
18003
+ var wrap = false;
18004
+ if (item.nodeType === 3) {
18005
+ wrap = true;
17876
18006
  }
17877
- else if (item.nodeType !== 3 &&
17878
- item.getAttribute("data-block") === "0" &&
17879
- index === contents.childNodes.length - 1 &&
17880
- rangeClone.endOffset <
17881
- rangeClone.endContainer.textContent.length) {
17882
- item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17883
- blockEndElement = item;
18007
+ else if (!item.classList.contains("vditor-comment")) {
18008
+ wrap = true;
17884
18009
  }
17885
- else if (item.nodeType !== 3 &&
17886
- item.getAttribute("data-block") === "0") {
17887
- if (index === 0) {
17888
- removeStart = true;
18010
+ else if (item.classList.contains("vditor-comment")) {
18011
+ item.setAttribute("data-cmtids", item.getAttribute("data-cmtids") + " " + id);
18012
+ }
18013
+ if (wrap) {
18014
+ if (item.nodeType !== 3 &&
18015
+ item.getAttribute("data-block") === "0" &&
18016
+ index === 0 &&
18017
+ rangeClone.startOffset > 0) {
18018
+ item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
18019
+ blockStartElement = item;
18020
+ }
18021
+ else if (item.nodeType !== 3 &&
18022
+ item.getAttribute("data-block") === "0" &&
18023
+ index === contents.childNodes.length - 1 &&
18024
+ rangeClone.endOffset <
18025
+ rangeClone.endContainer.textContent
18026
+ .length) {
18027
+ item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
18028
+ blockEndElement = item;
18029
+ }
18030
+ else if (item.nodeType !== 3 &&
18031
+ item.getAttribute("data-block") === "0") {
18032
+ if (index === 0) {
18033
+ removeStart = true;
18034
+ }
18035
+ else if (index ===
18036
+ contents.childNodes.length - 1) {
18037
+ removeEnd = true;
18038
+ }
18039
+ item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17889
18040
  }
17890
- else if (index ===
17891
- contents.childNodes.length - 1) {
17892
- removeEnd = true;
18041
+ else {
18042
+ var commentElement = document.createElement("span");
18043
+ commentElement.classList.add("vditor-comment");
18044
+ commentElement.setAttribute("data-cmtids", id);
18045
+ item.parentNode.insertBefore(commentElement, item);
18046
+ commentElement.appendChild(item);
17893
18047
  }
17894
- item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
17895
18048
  }
17896
- else {
17897
- var commentElement = document.createElement("span");
17898
- commentElement.classList.add("vditor-comment");
17899
- commentElement.setAttribute("data-cmtids", id);
17900
- item.parentNode.insertBefore(commentElement, item);
17901
- commentElement.appendChild(item);
18049
+ });
18050
+ var startElement = (0,hasClosest/* hasClosestBlock */.F9)(rangeClone.startContainer);
18051
+ if (startElement) {
18052
+ if (blockStartElement) {
18053
+ startElement.insertAdjacentHTML("beforeend", blockStartElement.innerHTML);
18054
+ blockStartElement.remove();
18055
+ }
18056
+ else if (startElement.textContent
18057
+ .trim()
18058
+ .replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
18059
+ removeStart) {
18060
+ startElement.remove();
17902
18061
  }
17903
18062
  }
17904
- });
17905
- var startElement = (0,hasClosest/* hasClosestBlock */.F9)(rangeClone.startContainer);
17906
- if (startElement) {
17907
- if (blockStartElement) {
17908
- startElement.insertAdjacentHTML("beforeend", blockStartElement.innerHTML);
17909
- blockStartElement.remove();
17910
- }
17911
- else if (startElement.textContent
17912
- .trim()
17913
- .replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
17914
- removeStart) {
17915
- startElement.remove();
17916
- }
17917
- }
17918
- var endElement = (0,hasClosest/* hasClosestBlock */.F9)(rangeClone.endContainer);
17919
- if (endElement) {
17920
- if (blockEndElement) {
17921
- endElement.insertAdjacentHTML("afterbegin", blockEndElement.innerHTML);
17922
- blockEndElement.remove();
17923
- }
17924
- else if (endElement.textContent
17925
- .trim()
17926
- .replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
17927
- removeEnd) {
17928
- endElement.remove();
18063
+ var endElement = (0,hasClosest/* hasClosestBlock */.F9)(rangeClone.endContainer);
18064
+ if (endElement) {
18065
+ if (blockEndElement) {
18066
+ endElement.insertAdjacentHTML("afterbegin", blockEndElement.innerHTML);
18067
+ blockEndElement.remove();
18068
+ }
18069
+ else if (endElement.textContent
18070
+ .trim()
18071
+ .replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
18072
+ removeEnd) {
18073
+ endElement.remove();
18074
+ }
17929
18075
  }
17930
- }
17931
- range.insertNode(contents);
17932
- vditor.options.comment.add(id, range.toString(), _this.getComments(vditor, true));
17933
- afterRenderEvent(vditor, {
17934
- enableAddUndoStack: true,
17935
- enableHint: false,
17936
- enableInput: false,
17937
- });
17938
- _this.hideComment();
17939
- };
18076
+ range.insertNode(contents);
18077
+ vditor.options.comment.add(id, range.toString(), _this.getComments(vditor, true));
18078
+ afterRenderEvent(vditor, {
18079
+ enableAddUndoStack: true,
18080
+ enableHint: false,
18081
+ enableInput: false,
18082
+ });
18083
+ _this.hideSelectionPopover();
18084
+ };
18085
+ }
17940
18086
  }
17941
18087
  }
17942
18088
  WYSIWYG.prototype.getComments = function (vditor, getData) {
@@ -17979,12 +18125,57 @@ var WYSIWYG = /** @class */ (function () {
17979
18125
  }
17980
18126
  }
17981
18127
  };
18128
+ /**
18129
+ * 显示选择浮窗(定位于选区右上)
18130
+ * - 当未选中文本或选区不在编辑器内时不显示
18131
+ */
18132
+ WYSIWYG.prototype.showSelectionPopover = function () {
18133
+ if (getSelection().rangeCount === 0) {
18134
+ return;
18135
+ }
18136
+ var range = getSelection().getRangeAt(0);
18137
+ if (range.toString().trim() === "") {
18138
+ return;
18139
+ }
18140
+ var editorRect = this.element.getBoundingClientRect();
18141
+ var rect = range.getBoundingClientRect();
18142
+ var top = Math.max(-8, rect.top - editorRect.top - 21);
18143
+ var left = Math.min(rect.right - editorRect.left - this.selectPopover.clientWidth, this.element.clientWidth - this.selectPopover.clientWidth);
18144
+ this.selectPopover.style.top = "".concat(top, "px");
18145
+ this.selectPopover.style.left = "".concat(Math.max(0, left), "px");
18146
+ this.selectPopover.style.display = "block";
18147
+ this.selectPopover.style.transition =
18148
+ "opacity 150ms cubic-bezier(0.2, 0, 0.13, 1.5), transform 150ms cubic-bezier(0.2, 0, 0.13, 1.5)";
18149
+ this.selectPopover.style.opacity = "1";
18150
+ this.selectPopover.style.transform = "scale(1)";
18151
+ this.popover.setAttribute("data-top", (rect.top - editorRect.top - 21).toString());
18152
+ this.selectPopover.setAttribute("data-top", (rect.top - editorRect.top - 21).toString());
18153
+ };
18154
+ /**
18155
+ * 隐藏选择浮窗(淡出)
18156
+ */
18157
+ WYSIWYG.prototype.hideSelectionPopover = function () {
18158
+ var _this = this;
18159
+ if (this.selectPopover.style.display !== "block") {
18160
+ return;
18161
+ }
18162
+ this.selectPopover.style.opacity = "0";
18163
+ this.selectPopover.style.transform = "scale(0.95)";
18164
+ window.setTimeout(function () {
18165
+ _this.selectPopover.setAttribute("style", "display:none");
18166
+ }, 150);
18167
+ };
18168
+ /**
18169
+ * 兼容旧接口:显示评论面板(映射为选择浮窗)
18170
+ */
17982
18171
  WYSIWYG.prototype.showComment = function () {
17983
- var position = (0,selection/* getCursorPosition */.Ny)(this.element);
17984
- this.selectPopover.setAttribute("style", "left:".concat(position.left, "px;display:block;top:").concat(Math.max(-8, position.top - 21), "px"));
18172
+ this.showSelectionPopover();
17985
18173
  };
18174
+ /**
18175
+ * 兼容旧接口:隐藏评论面板(映射为选择浮窗隐藏)
18176
+ */
17986
18177
  WYSIWYG.prototype.hideComment = function () {
17987
- this.selectPopover.setAttribute("style", "display:none");
18178
+ this.hideSelectionPopover();
17988
18179
  };
17989
18180
  WYSIWYG.prototype.unbindListener = function () {
17990
18181
  window.removeEventListener("scroll", this.scrollListener);
@@ -18048,7 +18239,159 @@ var WYSIWYG = /** @class */ (function () {
18048
18239
  var tempElement = document.createElement("div");
18049
18240
  tempElement.appendChild(range.cloneContents());
18050
18241
  event.clipboardData.setData("text/plain", vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim());
18051
- event.clipboardData.setData("text/html", "");
18242
+ event.clipboardData.setData("text/html", tempElement.innerHTML);
18243
+ };
18244
+ /**
18245
+ * 构建选区剪贴板内容(纯文本 + 富文本)
18246
+ */
18247
+ WYSIWYG.prototype.buildClipboardPayload = function (vditor) {
18248
+ var range = getSelection().getRangeAt(0);
18249
+ var codeElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "CODE");
18250
+ var codeEndElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.endContainer, "CODE");
18251
+ if (codeElement &&
18252
+ codeEndElement &&
18253
+ codeEndElement.isSameNode(codeElement)) {
18254
+ var codeText = codeElement.parentElement.tagName === "PRE"
18255
+ ? range.toString()
18256
+ : "`" + range.toString() + "`";
18257
+ return { plainText: codeText, html: "" };
18258
+ }
18259
+ var aElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "A");
18260
+ var aEndElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.endContainer, "A");
18261
+ if (aElement && aEndElement && aEndElement.isSameNode(aElement)) {
18262
+ var aTitle = aElement.getAttribute("title") || "";
18263
+ if (aTitle) {
18264
+ aTitle = " \"".concat(aTitle, "\"");
18265
+ }
18266
+ return {
18267
+ plainText: "[".concat(range.toString(), "](").concat(aElement.getAttribute("href")).concat(aTitle, ")"),
18268
+ html: "",
18269
+ };
18270
+ }
18271
+ var startPreview = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-wysiwyg__preview");
18272
+ var endPreview = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "vditor-wysiwyg__preview");
18273
+ var isMathPreview = function (el) {
18274
+ var first = el.firstElementChild;
18275
+ return !!first && first.classList.contains("language-math");
18276
+ };
18277
+ if (startPreview &&
18278
+ endPreview &&
18279
+ startPreview.isSameNode(endPreview) &&
18280
+ isMathPreview(startPreview)) {
18281
+ return { plainText: range.toString(), html: "" };
18282
+ }
18283
+ var tempElement = document.createElement("div");
18284
+ tempElement.appendChild(range.cloneContents());
18285
+ return {
18286
+ plainText: vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim(),
18287
+ html: tempElement.innerHTML,
18288
+ };
18289
+ };
18290
+ /**
18291
+ * 复制选区(按钮触发)
18292
+ * - Clipboard API 优先,降级为 execCommand('copy') 调用原有 copy 逻辑
18293
+ */
18294
+ WYSIWYG.prototype.copySelection = function (vditor) {
18295
+ var _this = this;
18296
+ var range = getSelection().getRangeAt(0);
18297
+ if (range.toString().trim() === "") {
18298
+ return;
18299
+ }
18300
+ var payload = this.buildClipboardPayload(vditor);
18301
+ var writeClipboard = function () { return wysiwyg_awaiter(_this, void 0, void 0, function () {
18302
+ var ClipboardItemCtor, navClipboard, item, _a;
18303
+ return wysiwyg_generator(this, function (_b) {
18304
+ switch (_b.label) {
18305
+ case 0:
18306
+ ClipboardItemCtor = window["ClipboardItem"];
18307
+ navClipboard = navigator.clipboard;
18308
+ if (!((navClipboard === null || navClipboard === void 0 ? void 0 : navClipboard.write) &&
18309
+ typeof ClipboardItemCtor !== "undefined")) return [3 /*break*/, 4];
18310
+ _b.label = 1;
18311
+ case 1:
18312
+ _b.trys.push([1, 3, , 4]);
18313
+ item = new ClipboardItemCtor({
18314
+ "text/plain": new Blob([payload.plainText], {
18315
+ type: "text/plain",
18316
+ }),
18317
+ "text/html": new Blob([payload.html], {
18318
+ type: "text/html",
18319
+ }),
18320
+ });
18321
+ return [4 /*yield*/, navClipboard.write([item])];
18322
+ case 2:
18323
+ _b.sent();
18324
+ return [2 /*return*/, true];
18325
+ case 3:
18326
+ _a = _b.sent();
18327
+ return [2 /*return*/, false];
18328
+ case 4: return [2 /*return*/, false];
18329
+ }
18330
+ });
18331
+ }); };
18332
+ writeClipboard().then(function (ok) {
18333
+ if (!ok) {
18334
+ document.execCommand("copy");
18335
+ }
18336
+ });
18337
+ this.hideSelectionPopover();
18338
+ };
18339
+ /**
18340
+ * 剪切选区(按钮触发)
18341
+ * - 复制到剪贴板后删除选区,并加入撤销栈
18342
+ */
18343
+ WYSIWYG.prototype.cutSelection = function (vditor) {
18344
+ var _this = this;
18345
+ var range = getSelection().getRangeAt(0);
18346
+ if (range.toString().trim() === "") {
18347
+ return;
18348
+ }
18349
+ var payload = this.buildClipboardPayload(vditor);
18350
+ var writeClipboard = function () { return wysiwyg_awaiter(_this, void 0, void 0, function () {
18351
+ var ClipboardItemCtor, navClipboard, item, _a;
18352
+ return wysiwyg_generator(this, function (_b) {
18353
+ switch (_b.label) {
18354
+ case 0:
18355
+ ClipboardItemCtor = window["ClipboardItem"];
18356
+ navClipboard = navigator.clipboard;
18357
+ if (!((navClipboard === null || navClipboard === void 0 ? void 0 : navClipboard.write) &&
18358
+ typeof ClipboardItemCtor !== "undefined")) return [3 /*break*/, 4];
18359
+ _b.label = 1;
18360
+ case 1:
18361
+ _b.trys.push([1, 3, , 4]);
18362
+ item = new ClipboardItemCtor({
18363
+ "text/plain": new Blob([payload.plainText], {
18364
+ type: "text/plain",
18365
+ }),
18366
+ "text/html": new Blob([payload.html], {
18367
+ type: "text/html",
18368
+ }),
18369
+ });
18370
+ return [4 /*yield*/, navClipboard.write([item])];
18371
+ case 2:
18372
+ _b.sent();
18373
+ return [2 /*return*/, true];
18374
+ case 3:
18375
+ _a = _b.sent();
18376
+ return [2 /*return*/, false];
18377
+ case 4: return [2 /*return*/, false];
18378
+ }
18379
+ });
18380
+ }); };
18381
+ writeClipboard().then(function (ok) {
18382
+ if (!ok) {
18383
+ document.execCommand("cut");
18384
+ }
18385
+ else {
18386
+ document.execCommand("delete");
18387
+ }
18388
+ afterRenderEvent(vditor, {
18389
+ enableAddUndoStack: true,
18390
+ enableHint: false,
18391
+ enableInput: true,
18392
+ });
18393
+ });
18394
+ this.hideSelectionPopover();
18052
18395
  };
18053
18396
  WYSIWYG.prototype.bindEvent = function (vditor) {
18054
18397
  var _this = this;
@@ -18589,9 +18932,11 @@ var Vditor = /** @class */ (function (_super) {
18589
18932
  * - 依赖配置 `lineNumber: true`,关闭时直接跳过以提升性能
18590
18933
  * @param immediate 为 true 时立即更新;默认为节流更新以避免频繁调用
18591
18934
  */
18935
+ /** 手动更新行号 */
18592
18936
  Vditor.prototype.updateLineNumbers = function (immediate) {
18937
+ var _a;
18593
18938
  if (immediate === void 0) { immediate = false; }
18594
- if (!this.vditor.options.lineNumber) {
18939
+ if (!((_a = this.vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable)) {
18595
18940
  return;
18596
18941
  }
18597
18942
  var text = (0,getMarkdown/* getMarkdown */.O)(this.vditor);
@@ -18609,7 +18954,9 @@ var Vditor = /** @class */ (function (_super) {
18609
18954
  * - 应用高亮样式并在约 500ms 后自动恢复
18610
18955
  * @param numbers 要高亮的行号数组
18611
18956
  */
18957
+ /** 高亮指定行号,时长受 `options.lineNumber.highlightTimer` 控制 */
18612
18958
  Vditor.prototype.setLinehightNumbers = function (numbers) {
18959
+ var _a;
18613
18960
  if (!Array.isArray(numbers)) {
18614
18961
  return;
18615
18962
  }
@@ -18627,7 +18974,7 @@ var Vditor = /** @class */ (function (_super) {
18627
18974
  if (nodeList.length === 0) {
18628
18975
  return;
18629
18976
  }
18630
- var duration = 500;
18977
+ var duration = Math.max(0, Number((_a = this.vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.highlightTimer) || 1500);
18631
18978
  var apply = function () {
18632
18979
  nodeList.forEach(function (el) {
18633
18980
  var old = lineHighlightTimers.get(el);
@@ -18820,14 +19167,15 @@ var Vditor = /** @class */ (function (_super) {
18820
19167
  /** 设置编辑器内容 */
18821
19168
  Vditor.prototype.setValue = function (markdown, clearStack) {
18822
19169
  var _this = this;
19170
+ var _a, _b;
18823
19171
  if (clearStack === void 0) { clearStack = false; }
18824
19172
  if (this.vditor.currentMode === "sv") {
18825
19173
  this.vditor.sv.element.innerHTML = "<div data-block='0'>".concat(this.vditor.lute.SpinVditorSVDOM(markdown), "</div>");
18826
- if (this.vditor.options.lineNumber) {
19174
+ if ((_a = this.vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
18827
19175
  try {
18828
19176
  (0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(this.vditor.sv.element, markdown || "");
18829
19177
  }
18830
- catch (_a) { }
19178
+ catch (_c) { }
18831
19179
  }
18832
19180
  processAfterRender(this.vditor, {
18833
19181
  enableAddUndoStack: true,
@@ -18850,11 +19198,11 @@ var Vditor = /** @class */ (function (_super) {
18850
19198
  .forEach(function (item) {
18851
19199
  processCodeRender(item, _this.vditor);
18852
19200
  });
18853
- if (this.vditor.options.lineNumber) {
19201
+ if ((_b = this.vditor.options.lineNumber) === null || _b === void 0 ? void 0 : _b.enable) {
18854
19202
  try {
18855
19203
  (0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(this.vditor.ir.element, markdown || "");
18856
19204
  }
18857
- catch (_b) { }
19205
+ catch (_d) { }
18858
19206
  }
18859
19207
  process_processAfterRender(this.vditor, {
18860
19208
  enableAddUndoStack: true,