vditor 3.8.7 → 3.8.8

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/CHANGELOG.md CHANGED
@@ -95,7 +95,22 @@
95
95
 
96
96
  * [open issues](https://github.com/Vanessa219/vditor/issues)
97
97
 
98
- ### v3.8.8 / 2021-10-xx
98
+ ### v3.8.9 / 2022-01-xx
99
+
100
+ ### v3.8.8 / 2021-12-05
101
+
102
+ * [1129](https://github.com/Vanessa219/vditor/pull/1129) WYSIWYG 下,点击语言后光标切换到代码输入框中 `改进功能`
103
+ * [1122](https://github.com/Vanessa219/vditor/pull/1122) 预览中退出全屏后,工具栏布局错误 `修复缺陷`
104
+ * [1123](https://github.com/Vanessa219/vditor/pull/1123) 预览模式下,工具栏不自动隐藏 `改进功能`
105
+ * [1124](https://github.com/Vanessa219/vditor/pull/1124) 在焦点更改后,代码选择列表不自动隐藏 `改进功能`
106
+ * [1121](https://github.com/Vanessa219/vditor/pull/1121) WYSIWYG 下,Enter 也可以切换到代码输入框中 `改进功能`
107
+ * [1103](https://github.com/Vanessa219/vditor/pull/1103) 支持多语言切换 `改进功能`
108
+ * [1105](https://github.com/Vanessa219/vditor/pull/1105) 兼容 Firefox 中的代码语言选择 `修复缺陷`
109
+ * [1098](https://github.com/Vanessa219/vditor/pull/1098) 兼容 Firefox 中的文件拖拽 `修复缺陷`
110
+ * [1097](https://github.com/Vanessa219/vditor/pull/1097) options.hint.extend[].hint 支持异步 `改进功能`
111
+ * [1101](https://github.com/Vanessa219/vditor/pull/1101) 支持 options.upload.handler 异步 `改进功能`
112
+ * [1089](https://github.com/Vanessa219/vditor/pull/1089) 解决内存泄漏问题 `开发重构`
113
+ * [158](https://github.com/88250/lute/issues/158) Table 紧跟的上一行不是空行时,SpinVditorSVDOM 会将整个表格过滤掉 `修复缺陷`
99
114
 
100
115
  ### v3.8.7 / 2021-09-21
101
116
 
package/README.md CHANGED
@@ -6,9 +6,8 @@
6
6
  <br><br>
7
7
  <a title="MIT" target="_blank" href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square"></a>
8
8
  <a title="npm bundle size" target="_blank" href="https://www.npmjs.com/package/vditor"><img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/vditor?style=flat-square&color=blueviolet"></a>
9
- <a title="Dependencies" target="_blank" href="https://github.com/Vanessa219/vditor"><img src="https://img.shields.io/david/Vanessa219/vditor.svg?style=flat-square&color=ff96b4"></a> <br>
10
- <a title="Version" target="_blank" href="https://www.npmjs.com/package/vditor"><img src="https://img.shields.io/npm/v/vditor.svg?style=flat-square"></a>
11
- <a title="Downloads" target="_blank" href="https://www.npmjs.com/package/vditor"><img src="https://img.shields.io/npm/dt/vditor.svg?style=flat-square&color=97ca00"></a><br>
9
+ <a title="Version" target="_blank" href="https://www.npmjs.com/package/vditor"><img src="https://img.shields.io/npm/v/vditor.svg?style=flat-square"></a><br>
10
+ <a title="Downloads" target="_blank" href="https://www.npmjs.com/package/vditor"><img src="https://img.shields.io/npm/dt/vditor.svg?style=flat-square&color=97ca00"></a>
12
11
  <a title="jsdelivr" target="_blank" href="https://www.jsdelivr.com/package/npm/vditor"><img src="https://data.jsdelivr.com/v1/package/npm/vditor/badge"/></a>
13
12
  <a title="Hits" target="_blank" href="https://github.com/88250/hits"><img src="https://hits.b3log.org/Vanessa219/vditor.svg"></a> <br><br>
14
13
  <a title="GitHub Watchers" target="_blank" href="https://github.com/Vanessa219/vditor/watchers"><img src="https://img.shields.io/github/watchers/Vanessa219/vditor.svg?label=Watchers&style=social"></a>
@@ -23,7 +22,7 @@
23
22
 
24
23
  ## 💡 简介
25
24
 
26
- [Vditor](https://b3log.org/vditor) 是一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。它使用 TypeScript 实现,支持原生 JavaScript、Vue、React、Angular、Svelte,提供[桌面版](https://b3log.org/siyuan)。
25
+ [Vditor](https://b3log.org/vditor) 是一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。它使用 TypeScript 实现,支持原生 JavaScript 以及 Vue、React、Angular 和 Svelte 等框架。
27
26
 
28
27
  欢迎到 [Vditor 官方讨论区](https://ld246.com/tag/vditor)了解更多。同时也欢迎关注 B3log 开源社区微信公众号 `B3log开源`:
29
28
 
@@ -115,7 +114,6 @@ Vditor 在这些方面做了努力,希望能为现代化的通用 Markdown 编
115
114
 
116
115
  * [Sym](https://github.com/88250/symphony) 一款用 Java 实现的现代化社区(论坛/BBS/社交网络/博客)平台
117
116
  * [Solo](https://github.com/88250/solo) & [Pipe](https://github.com/88250/pipe) B3log 分布式社区的博客端节点,欢迎加入下一代社区网络
118
- * [思源笔记](https://b3log.org/siyuan) 一款 Markdown 块级引用和双向链接的网状笔记应用
119
117
  * [Arya](https://github.com/nicejade/markdown-online-editor) 基于 Vue、Vditor,所构建的在线 Markdown 编辑器
120
118
  * [更多案例](https://github.com/Vanessa219/vditor/network/dependents?package_id=UGFja2FnZS0zMTY2Mzg4MzE%3D)
121
119
 
@@ -365,13 +363,15 @@ new Vditor('vditor', {
365
363
  | extend: IHintExtend[] | 对 @/话题等关键字自动补全的扩展 | [] |
366
364
 
367
365
  ```ts
366
+ interface IHintData {
367
+ html: string;
368
+ value: string;
369
+ }
370
+
368
371
  interface IHintExtend {
369
372
  key: string;
370
373
 
371
- hint?(value: string): Array<{
372
- html: string;
373
- value: string;
374
- }>;
374
+ hint?(value: string): IHintData[] | Promise<IHintData[]>;
375
375
  }
376
376
  ```
377
377
 
@@ -449,9 +449,9 @@ if (xhr.status === 200) {
449
449
  | filename(name: string): string | 文件名安全处理 | name => name.replace(/\W/g, '') |
450
450
  | accept | 文件上传类型,同[input accept](https://www.w3schools.com/tags/att_input_accept.asp) | - |
451
451
  | validate(files: File[]) => string \| boolean | 校验,成功时返回 true 否则返回错误信息 | - |
452
- | handler(files: File[]) => string \| null | 自定义上传,当发生错误时返回错误信息 | - |
452
+ | handler(files: File[]) => string \| null \| Promise<string> \| Promise<null> | 自定义上传,当发生错误时返回错误信息 | - |
453
453
  | format(files: File[], responseText: string): string | 对服务端返回的数据进行转换,以满足内置的数据结构 | - |
454
- | file(files: File[]): File[] | 将上传的文件处理后再返回 | - |
454
+ | file(files: File[]): File[] \| Promise<File[]> | 将上传的文件处理后再返回 | - |
455
455
  | setHeaders(): { [key: string]: string } | 上传前使用返回值设置头 | - |
456
456
  | extraData: { [key: string]: string \| Blob } | 为 FormData 添加额外的参数 | - |
457
457
  | multiple | 上传文件是否为多个 | true |
package/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v3.8.7 - A markdown editor written in TypeScript.
2
+ * Vditor v3.8.8 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v3.8.7 - A markdown editor written in TypeScript.
2
+ * Vditor v3.8.8 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2722,7 +2722,7 @@ var md2html = function (mdText, options) {
2722
2722
  });
2723
2723
  };
2724
2724
  var previewRender = function (previewElement, markdown, options) { return __awaiter(void 0, void 0, void 0, function () {
2725
- var mergedOptions, html;
2725
+ var mergedOptions, html, i18nScriptPrefix, i18nScriptID_1;
2726
2726
  return __generator(this, function (_a) {
2727
2727
  switch (_a.label) {
2728
2728
  case 0:
@@ -2740,7 +2740,14 @@ var previewRender = function (previewElement, markdown, options) { return __awai
2740
2740
  throw new Error("options.lang error, see https://ld246.com/article/1549638745630#options");
2741
2741
  }
2742
2742
  else {
2743
- (0,addScript/* addScriptSync */.J)(mergedOptions.cdn + "/dist/js/i18n/" + mergedOptions.lang + ".js", "vditorI18nScript");
2743
+ i18nScriptPrefix = "vditorI18nScript";
2744
+ i18nScriptID_1 = i18nScriptPrefix + mergedOptions.lang;
2745
+ document.querySelectorAll("head script[id^=\"" + i18nScriptPrefix + "\"]").forEach(function (el) {
2746
+ if (el.id !== i18nScriptID_1) {
2747
+ document.head.removeChild(el);
2748
+ }
2749
+ });
2750
+ (0,addScript/* addScript */.G)(mergedOptions.cdn + "/dist/js/i18n/" + mergedOptions.lang + ".js", i18nScriptID_1);
2744
2751
  }
2745
2752
  }
2746
2753
  else {
@@ -2876,7 +2883,7 @@ var Vditor = /** @class */ (function () {
2876
2883
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2877
2884
  /* harmony export */ "g": () => (/* binding */ Constants)
2878
2885
  /* harmony export */ });
2879
- var _VDITOR_VERSION = "3.8.7";
2886
+ var _VDITOR_VERSION = "3.8.8";
2880
2887
 
2881
2888
  var Constants = /** @class */ (function () {
2882
2889
  function Constants() {
@@ -2902,7 +2909,7 @@ var Constants = /** @class */ (function () {
2902
2909
  "swift", "ini", "typescript", "vbnet", "yaml",
2903
2910
  "ada", "clojure", "dart", "erb", "fortran", "gradle", "haskell", "julia", "julia-repl", "lisp", "matlab",
2904
2911
  "pgsql", "powershell", "sql_more", "stata", "cmake", "mathematica"];
2905
- Constants.CDN = "https://cdn.jsdelivr.net/npm/vditor@" + "3.8.7";
2912
+ Constants.CDN = "https://cdn.jsdelivr.net/npm/vditor@" + "3.8.8";
2906
2913
  Constants.MARKDOWN_OPTIONS = {
2907
2914
  autoSpace: false,
2908
2915
  codeBlockPreview: true,
@@ -6227,6 +6234,7 @@ var setTheme = function (vditor) {
6227
6234
 
6228
6235
 
6229
6236
 
6237
+
6230
6238
  var initUI = function (vditor) {
6231
6239
  vditor.element.innerHTML = "";
6232
6240
  vditor.element.classList.add("vditor");
@@ -6270,11 +6278,14 @@ var initUI = function (vditor) {
6270
6278
  contentElement.appendChild(vditor.hint.element);
6271
6279
  contentElement.appendChild(vditor.tip.element);
6272
6280
  vditor.element.appendChild(contentElement);
6281
+ contentElement.addEventListener("click", function () {
6282
+ hidePanel(vditor, ["subToolbar"]);
6283
+ });
6273
6284
  if (vditor.toolbar.elements.export) {
6274
6285
  // for export pdf
6275
6286
  vditor.element.insertAdjacentHTML("beforeend", '<iframe style="width: 100%;height: 0;border: 0"></iframe>');
6276
6287
  }
6277
- setEditMode(vditor, vditor.options.mode, afterRender(vditor, contentElement));
6288
+ setEditMode(vditor, vditor.options.mode, afterRender(vditor));
6278
6289
  document.execCommand("DefaultParagraphSeparator", false, "p");
6279
6290
  if (navigator.userAgent.indexOf("iPhone") > -1 && typeof window.visualViewport !== "undefined") {
6280
6291
  // https://github.com/Vanessa219/vditor/issues/379
@@ -6309,10 +6320,14 @@ var setPadding = function (vditor) {
6309
6320
  - vditor.options.preview.maxWidth) / 2;
6310
6321
  vditor.ir.element.style.padding = "10px " + Math.max(minPadding, padding) + "px";
6311
6322
  }
6312
- if (vditor.preview.element.style.display !== "block" || vditor.currentMode === "sv") {
6323
+ if (vditor.preview.element.style.display !== "block") {
6313
6324
  vditor.toolbar.element.style.paddingLeft = Math.max(5, parseInt(vditor[vditor.currentMode].element.style.paddingLeft || "0", 10) +
6314
6325
  (vditor.options.outline.position === "left" ? vditor.outline.element.offsetWidth : 0)) + "px";
6315
6326
  }
6327
+ else {
6328
+ vditor.toolbar.element.style.paddingLeft = (5 +
6329
+ (vditor.options.outline.position === "left" ? vditor.outline.element.offsetWidth : 0)) + "px";
6330
+ }
6316
6331
  };
6317
6332
  var setTypewriterPosition = function (vditor) {
6318
6333
  if (!vditor.options.typewriterMode) {
@@ -6332,9 +6347,14 @@ var setTypewriterPosition = function (vditor) {
6332
6347
  // 由于 Firefox padding-bottom bug,只能使用 :after
6333
6348
  vditor[vditor.currentMode].element.style.setProperty("--editor-bottom", ((height - vditor.toolbar.element.offsetHeight) / 2) + "px");
6334
6349
  };
6335
- var afterRender = function (vditor, contentElement) {
6350
+ var resizeCb;
6351
+ function UIUnbindListener() {
6352
+ window.removeEventListener("resize", resizeCb);
6353
+ }
6354
+ var afterRender = function (vditor) {
6336
6355
  setTypewriterPosition(vditor);
6337
- window.addEventListener("resize", function () {
6356
+ UIUnbindListener();
6357
+ window.addEventListener("resize", resizeCb = function () {
6338
6358
  setPadding(vditor);
6339
6359
  setTypewriterPosition(vditor);
6340
6360
  });
@@ -7546,7 +7566,7 @@ var highlightToolbarWYSIWYG = function (vditor) {
7546
7566
  codeElement_1.className.indexOf("language-") > -1
7547
7567
  ? codeElement_1.className.split("-")[1].split(" ")[0]
7548
7568
  : "";
7549
- language_1.oninput = function () {
7569
+ language_1.oninput = function (e) {
7550
7570
  if (language_1.value.trim() !== "") {
7551
7571
  codeElement_1.className = "language-" + language_1.value;
7552
7572
  }
@@ -7560,6 +7580,13 @@ var highlightToolbarWYSIWYG = function (vditor) {
7560
7580
  processCodeRender(blockRenderElement.lastElementChild, vditor);
7561
7581
  }
7562
7582
  afterRenderEvent(vditor);
7583
+ // 当鼠标点选语言时,触发自定义input事件
7584
+ if (e.detail === 1) {
7585
+ // 选择语言后,输入焦点切换到代码输入框
7586
+ range.setStart(codeElement_1.firstChild, 0);
7587
+ range.collapse(true);
7588
+ (0,selection/* setSelectionFocus */.Hc)(range);
7589
+ }
7563
7590
  };
7564
7591
  language_1.onkeydown = function (event) {
7565
7592
  if (event.isComposing) {
@@ -7574,15 +7601,16 @@ var highlightToolbarWYSIWYG = function (vditor) {
7574
7601
  event.preventDefault();
7575
7602
  return;
7576
7603
  }
7604
+ vditor.hint.select(event, vditor);
7577
7605
  if (!(0,compatibility/* isCtrl */.yl)(event) &&
7578
7606
  !event.shiftKey &&
7579
- event.altKey &&
7580
7607
  event.key === "Enter") {
7581
7608
  range.setStart(codeElement_1.firstChild, 0);
7582
7609
  range.collapse(true);
7583
7610
  (0,selection/* setSelectionFocus */.Hc)(range);
7611
+ event.preventDefault();
7612
+ event.stopPropagation();
7584
7613
  }
7585
- vditor.hint.select(event, vditor);
7586
7614
  };
7587
7615
  language_1.onkeyup = function (event) {
7588
7616
  if (event.isComposing ||
@@ -8627,7 +8655,7 @@ var focusEvent = function (vditor, editorElement) {
8627
8655
  if (vditor.options.focus) {
8628
8656
  vditor.options.focus(getMarkdown(vditor));
8629
8657
  }
8630
- hidePanel(vditor, ["subToolbar"]);
8658
+ hidePanel(vditor, ["subToolbar", "hint"]);
8631
8659
  });
8632
8660
  };
8633
8661
  var dblclickEvent = function (vditor, editorElement) {
@@ -8665,7 +8693,7 @@ var dropEvent = function (vditor, editorElement) {
8665
8693
  // 编辑器内选中文字拖拽
8666
8694
  execAfterRender(vditor);
8667
8695
  }
8668
- else if (event.dataTransfer.types[0] === "Files" || event.dataTransfer.types.includes("text/html")) {
8696
+ else if (event.dataTransfer.types.includes("Files") || event.dataTransfer.types.includes("text/html")) {
8669
8697
  // 外部文件拖入编辑器中或者编辑器内选中文字拖拽
8670
8698
  paste(vditor, event, {
8671
8699
  pasteCode: function (code) {
@@ -9268,14 +9296,16 @@ var uploadFiles = function (vditor, files, element) { return __awaiter(void 0, v
9268
9296
  }
9269
9297
  fileList.push(fileItem);
9270
9298
  }
9271
- if (vditor.options.upload.handler) {
9272
- isValidate = vditor.options.upload.handler(fileList);
9273
- if (typeof isValidate === "string") {
9274
- vditor.tip.show(isValidate);
9275
- return [2 /*return*/];
9276
- }
9299
+ if (!vditor.options.upload.handler) return [3 /*break*/, 2];
9300
+ return [4 /*yield*/, vditor.options.upload.handler(fileList)];
9301
+ case 1:
9302
+ isValidate = _b.sent();
9303
+ if (typeof isValidate === "string") {
9304
+ vditor.tip.show(isValidate);
9277
9305
  return [2 /*return*/];
9278
9306
  }
9307
+ return [2 /*return*/];
9308
+ case 2:
9279
9309
  if (!vditor.options.upload.url || !vditor.upload) {
9280
9310
  if (element) {
9281
9311
  element.value = "";
@@ -9283,12 +9313,12 @@ var uploadFiles = function (vditor, files, element) { return __awaiter(void 0, v
9283
9313
  vditor.tip.show("please config: options.upload.url");
9284
9314
  return [2 /*return*/];
9285
9315
  }
9286
- if (!vditor.options.upload.file) return [3 /*break*/, 2];
9316
+ if (!vditor.options.upload.file) return [3 /*break*/, 4];
9287
9317
  return [4 /*yield*/, vditor.options.upload.file(fileList)];
9288
- case 1:
9318
+ case 3:
9289
9319
  fileList = _b.sent();
9290
- _b.label = 2;
9291
- case 2:
9320
+ _b.label = 4;
9321
+ case 4:
9292
9322
  if (vditor.options.upload.validate) {
9293
9323
  isValidate = vditor.options.upload.validate(fileList);
9294
9324
  if (typeof isValidate === "string") {
@@ -10814,7 +10844,7 @@ var paste = function (vditor, event, callback) { return fixBrowserBehavior_await
10814
10844
  else {
10815
10845
  textHTML = event.dataTransfer.getData("text/html");
10816
10846
  textPlain = event.dataTransfer.getData("text/plain");
10817
- if (event.dataTransfer.types[0] === "Files") {
10847
+ if (event.dataTransfer.types.includes("Files")) {
10818
10848
  files = event.dataTransfer.items;
10819
10849
  }
10820
10850
  }
@@ -10957,7 +10987,7 @@ var paste = function (vditor, event, callback) { return fixBrowserBehavior_await
10957
10987
  vditor.outline.render(vditor);
10958
10988
  return [3 /*break*/, 6];
10959
10989
  case 3:
10960
- if (!(files.length > 0 && vditor.options.upload.url)) return [3 /*break*/, 5];
10990
+ if (!(files.length > 0 && (vditor.options.upload.url || vditor.options.upload.handler))) return [3 /*break*/, 5];
10961
10991
  return [4 /*yield*/, uploadFiles(vditor, files)];
10962
10992
  case 4:
10963
10993
  _b.sent();
@@ -11245,6 +11275,42 @@ var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
11245
11275
  };
11246
11276
 
11247
11277
  ;// CONCATENATED MODULE: ./src/ts/hint/index.ts
11278
+ var hint_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
11279
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11280
+ return new (P || (P = Promise))(function (resolve, reject) {
11281
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11282
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11283
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11284
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11285
+ });
11286
+ };
11287
+ var hint_generator = (undefined && undefined.__generator) || function (thisArg, body) {
11288
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
11289
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
11290
+ function verb(n) { return function (v) { return step([n, v]); }; }
11291
+ function step(op) {
11292
+ if (f) throw new TypeError("Generator is already executing.");
11293
+ while (_) try {
11294
+ 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;
11295
+ if (y = 0, t) op = [op[0] & 2, t.value];
11296
+ switch (op[0]) {
11297
+ case 0: case 1: t = op; break;
11298
+ case 4: _.label++; return { value: op[1], done: false };
11299
+ case 5: _.label++; y = op[1]; op = [0]; continue;
11300
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
11301
+ default:
11302
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
11303
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
11304
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
11305
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
11306
+ if (t[2]) _.ops.pop();
11307
+ _.trys.pop(); continue;
11308
+ }
11309
+ op = body.call(thisArg, _);
11310
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
11311
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
11312
+ }
11313
+ };
11248
11314
 
11249
11315
 
11250
11316
 
@@ -11278,15 +11344,25 @@ var Hint = /** @class */ (function () {
11278
11344
  return;
11279
11345
  }
11280
11346
  }
11281
- if (vditor.currentMode === "wysiwyg" && range.startContainer.nodeType !== 3 &&
11282
- range.startContainer.firstElementChild.classList.contains("vditor-input")) {
11283
- var inputElement = range.startContainer.firstElementChild;
11284
- inputElement.value = value.trimRight();
11285
- range.selectNodeContents(inputElement);
11286
- range.collapse(false);
11287
- inputElement.dispatchEvent(new CustomEvent("input"));
11288
- _this.recentLanguage = value.trimRight();
11289
- return;
11347
+ if (vditor.currentMode === "wysiwyg" && range.startContainer.nodeType !== 3) {
11348
+ var startContainer = range.startContainer;
11349
+ var inputElement = void 0;
11350
+ if (startContainer.classList.contains("vditor-input")) {
11351
+ inputElement = startContainer;
11352
+ }
11353
+ else {
11354
+ inputElement = startContainer.firstElementChild;
11355
+ }
11356
+ if (inputElement && inputElement.classList.contains("vditor-input")) {
11357
+ inputElement.value = value.trimRight();
11358
+ range.selectNodeContents(inputElement);
11359
+ range.collapse(false);
11360
+ // {detail: 1}用于标识这个自定义事件是在编程语言选择后触发的
11361
+ // 用于在鼠标选择语言后,自动聚焦到代码输入框
11362
+ inputElement.dispatchEvent(new CustomEvent("input", { detail: 1 }));
11363
+ _this.recentLanguage = value.trimRight();
11364
+ return;
11365
+ }
11290
11366
  }
11291
11367
  range.setStart(range.startContainer, _this.lastIndex);
11292
11368
  range.deleteContents();
@@ -11370,9 +11446,19 @@ var Hint = /** @class */ (function () {
11370
11446
  vditor.options.hint.extend.forEach(function (item) {
11371
11447
  if (item.key === _this.splitChar) {
11372
11448
  clearTimeout(_this.timeId);
11373
- _this.timeId = window.setTimeout(function () {
11374
- _this.genHTML(item.hint(key), key, vditor);
11375
- }, vditor.options.hint.delay);
11449
+ _this.timeId = window.setTimeout(function () { return hint_awaiter(_this, void 0, void 0, function () {
11450
+ var _a;
11451
+ return hint_generator(this, function (_b) {
11452
+ switch (_b.label) {
11453
+ case 0:
11454
+ _a = this.genHTML;
11455
+ return [4 /*yield*/, item.hint(key)];
11456
+ case 1:
11457
+ _a.apply(this, [_b.sent(), key, vditor]);
11458
+ return [2 /*return*/];
11459
+ }
11460
+ });
11461
+ }); }, vditor.options.hint.delay);
11376
11462
  }
11377
11463
  });
11378
11464
  }
@@ -12973,7 +13059,7 @@ var Info = /** @class */ (function (_super) {
12973
13059
  var _this = _super.call(this, vditor, menuItem) || this;
12974
13060
  _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
12975
13061
  event.preventDefault();
12976
- vditor.tip.show("<div style=\"max-width: 520px; font-size: 14px;line-height: 22px;margin-bottom: 14px;\">\n<p style=\"text-align: center;margin: 14px 0\">\n <em>\u4E0B\u4E00\u4EE3\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u4E3A\u672A\u6765\u800C\u6784\u5EFA</em>\n</p>\n<div style=\"display: flex;margin-bottom: 14px;flex-wrap: wrap;align-items: center\">\n <img src=\"https://cdn.jsdelivr.net/npm/vditor/src/assets/images/logo.png\" style=\"margin: 0 auto;height: 68px\"/>\n <div>&nbsp;&nbsp;</div>\n <div style=\"flex: 1;min-width: 250px\">\n Vditor \u662F\u4E00\u6B3E\u6D4F\u89C8\u5668\u7AEF\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u652F\u6301\u6240\u89C1\u5373\u6240\u5F97\u3001\u5373\u65F6\u6E32\u67D3\uFF08\u7C7B\u4F3C Typora\uFF09\u548C\u5206\u5C4F\u9884\u89C8\u6A21\u5F0F\u3002\n \u5B83\u4F7F\u7528 TypeScript \u5B9E\u73B0\uFF0C\u652F\u6301\u539F\u751F JavaScript\u3001Vue\u3001React\u3001Angular\uFF0C\u63D0\u4F9B<a target=\"_blank\" href=\"https://b3log.org/siyuan\">\u684C\u9762\u7248</a>\u3002\n </div>\n</div>\n<div style=\"display: flex;flex-wrap: wrap;\">\n <ul style=\"list-style: none;flex: 1;min-width:148px\">\n <li>\n \u9879\u76EE\u5730\u5740\uFF1A<a href=\"https://b3log.org/vditor\" target=\"_blank\">b3log.org/vditor</a>\n </li>\n <li>\n \u5F00\u6E90\u534F\u8BAE\uFF1AMIT\n </li>\n </ul>\n <ul style=\"list-style: none;margin-right: 18px\">\n <li>\n \u7EC4\u4EF6\u7248\u672C\uFF1AVditor v" + constants/* VDITOR_VERSION */.H + " / Lute v" + Lute.Version + "\n </li>\n <li>\n \u8D5E\u52A9\u6350\u8D60\uFF1A<a href=\"https://ld246.com/sponsor\" target=\"_blank\">https://ld246.com/sponsor</a>\n </li>\n </ul>\n</div>\n</div>", 0);
13062
+ vditor.tip.show("<div style=\"max-width: 520px; font-size: 14px;line-height: 22px;margin-bottom: 14px;\">\n<p style=\"text-align: center;margin: 14px 0\">\n <em>\u4E0B\u4E00\u4EE3\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u4E3A\u672A\u6765\u800C\u6784\u5EFA</em>\n</p>\n<div style=\"display: flex;margin-bottom: 14px;flex-wrap: wrap;align-items: center\">\n <img src=\"https://cdn.jsdelivr.net/npm/vditor/src/assets/images/logo.png\" style=\"margin: 0 auto;height: 68px\"/>\n <div>&nbsp;&nbsp;</div>\n <div style=\"flex: 1;min-width: 250px\">\n Vditor \u662F\u4E00\u6B3E\u6D4F\u89C8\u5668\u7AEF\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u652F\u6301\u6240\u89C1\u5373\u6240\u5F97\u3001\u5373\u65F6\u6E32\u67D3\uFF08\u7C7B\u4F3C Typora\uFF09\u548C\u5206\u5C4F\u9884\u89C8\u6A21\u5F0F\u3002\n \u5B83\u4F7F\u7528 TypeScript \u5B9E\u73B0\uFF0C\u652F\u6301\u539F\u751F JavaScript \u4EE5\u53CA Vue\u3001React\u3001Angular \u548C Svelte \u7B49\u6846\u67B6\u3002\n </div>\n</div>\n<div style=\"display: flex;flex-wrap: wrap;\">\n <ul style=\"list-style: none;flex: 1;min-width:148px\">\n <li>\n \u9879\u76EE\u5730\u5740\uFF1A<a href=\"https://b3log.org/vditor\" target=\"_blank\">b3log.org/vditor</a>\n </li>\n <li>\n \u5F00\u6E90\u534F\u8BAE\uFF1AMIT\n </li>\n </ul>\n <ul style=\"list-style: none;margin-right: 18px\">\n <li>\n \u7EC4\u4EF6\u7248\u672C\uFF1AVditor v" + constants/* VDITOR_VERSION */.H + " / Lute v" + Lute.Version + "\n </li>\n <li>\n \u8D5E\u52A9\u6350\u8D60\uFF1A<a href=\"https://ld246.com/sponsor\" target=\"_blank\">https://ld246.com/sponsor</a>\n </li>\n </ul>\n</div>\n</div>", 0);
12977
13063
  });
12978
13064
  return _this;
12979
13065
  }
@@ -14547,6 +14633,9 @@ var WYSIWYG = /** @class */ (function () {
14547
14633
  WYSIWYG.prototype.hideComment = function () {
14548
14634
  this.selectPopover.setAttribute("style", "display:none");
14549
14635
  };
14636
+ WYSIWYG.prototype.unbindListener = function () {
14637
+ window.removeEventListener("scroll", this.scrollListener);
14638
+ };
14550
14639
  WYSIWYG.prototype.copy = function (event, vditor) {
14551
14640
  var range = getSelection().getRangeAt(0);
14552
14641
  if (range.toString() === "") {
@@ -14586,7 +14675,8 @@ var WYSIWYG = /** @class */ (function () {
14586
14675
  };
14587
14676
  WYSIWYG.prototype.bindEvent = function (vditor) {
14588
14677
  var _this = this;
14589
- window.addEventListener("scroll", function () {
14678
+ this.unbindListener();
14679
+ window.addEventListener("scroll", this.scrollListener = function () {
14590
14680
  hidePanel(vditor, ["hint"]);
14591
14681
  if (_this.popover.style.display !== "block" || _this.selectPopover.style.display !== "block") {
14592
14682
  return;
@@ -14958,7 +15048,14 @@ var Vditor = /** @class */ (function (_super) {
14958
15048
  throw new Error("options.lang error, see https://ld246.com/article/1549638745630#options");
14959
15049
  }
14960
15050
  else {
14961
- (0,addScript/* addScript */.G)(mergedOptions.cdn + "/dist/js/i18n/" + mergedOptions.lang + ".js", "vditorI18nScript").then(function () {
15051
+ var i18nScriptPrefix = "vditorI18nScript";
15052
+ var i18nScriptID_1 = i18nScriptPrefix + mergedOptions.lang;
15053
+ document.querySelectorAll("head script[id^=\"" + i18nScriptPrefix + "\"]").forEach(function (el) {
15054
+ if (el.id !== i18nScriptID_1) {
15055
+ document.head.removeChild(el);
15056
+ }
15057
+ });
15058
+ (0,addScript/* addScript */.G)(mergedOptions.cdn + "/dist/js/i18n/" + mergedOptions.lang + ".js", i18nScriptID_1).then(function () {
14962
15059
  _this.init(id, mergedOptions);
14963
15060
  });
14964
15061
  }
@@ -15179,6 +15276,8 @@ var Vditor = /** @class */ (function (_super) {
15179
15276
  this.vditor.element.removeAttribute("style");
15180
15277
  document.getElementById("vditorIconScript").remove();
15181
15278
  this.clearCache();
15279
+ UIUnbindListener();
15280
+ this.vditor.wysiwyg.unbindListener();
15182
15281
  };
15183
15282
  /** 获取评论 ID */
15184
15283
  Vditor.prototype.getCommentIds = function () {
package/dist/js/.DS_Store CHANGED
Binary file
@@ -24,7 +24,7 @@ window.VditorI18n = {
24
24
  'edit-mode': '切换编辑模式',
25
25
  'emoji': '表情',
26
26
  'export': '导出',
27
- 'fileTypeError': '文件类型不允许上传',
27
+ 'fileTypeError': '文件类型不允许上传,请压缩后再试',
28
28
  'footnoteRef': '脚注标识',
29
29
  'fullscreen': '全屏切换',
30
30
  'generate': '生成中',