vditor 3.10.5 → 3.10.6

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.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v3.10.5 - A markdown editor written in TypeScript.
2
+ * Vditor v3.10.6 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -25,7 +25,7 @@
25
25
  *
26
26
  */
27
27
  /*!
28
- * Vditor v3.10.5 - A markdown editor written in TypeScript.
28
+ * Vditor v3.10.6 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
package/dist/index.d.ts CHANGED
@@ -58,6 +58,8 @@ declare class Vditor extends VditorMethod {
58
58
  updateValue(value: string): void;
59
59
  /** 在焦点处插入内容,并默认进行 Markdown 渲染 */
60
60
  insertValue(value: string, render?: boolean): void;
61
+ /** 在焦点处插入 Markdown */
62
+ insertMD(md: string): void;
61
63
  /** 设置编辑器内容 */
62
64
  setValue(markdown: string, clearStack?: boolean): void;
63
65
  /** 清空 undo & redo 栈 */
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v3.10.5 - A markdown editor written in TypeScript.
2
+ * Vditor v3.10.6 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2626,7 +2626,7 @@ var Vditor = /** @class */ (function () {
2626
2626
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2627
2627
  /* harmony export */ "g": () => (/* binding */ Constants)
2628
2628
  /* harmony export */ });
2629
- var _VDITOR_VERSION = "3.10.5";
2629
+ var _VDITOR_VERSION = "3.10.6";
2630
2630
 
2631
2631
  var Constants = /** @class */ (function () {
2632
2632
  function Constants() {
@@ -2655,7 +2655,7 @@ var Constants = /** @class */ (function () {
2655
2655
  // ext
2656
2656
  "solidity", "yul"
2657
2657
  ];
2658
- Constants.CDN = "https://unpkg.com/vditor@".concat("3.10.5");
2658
+ Constants.CDN = "https://unpkg.com/vditor@".concat("3.10.6");
2659
2659
  Constants.MARKDOWN_OPTIONS = {
2660
2660
  autoSpace: false,
2661
2661
  gfmAutoLink: true,
@@ -2804,6 +2804,44 @@ var plantumlRenderAdapter = {
2804
2804
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(793);
2805
2805
  /* harmony import */ var _util_addScript__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(998);
2806
2806
  /* harmony import */ var _adapterRender__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(781);
2807
+ /* harmony import */ var _util_function__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(446);
2808
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2809
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2810
+ return new (P || (P = Promise))(function (resolve, reject) {
2811
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2812
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2813
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2814
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2815
+ });
2816
+ };
2817
+ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
2818
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2819
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2820
+ function verb(n) { return function (v) { return step([n, v]); }; }
2821
+ function step(op) {
2822
+ if (f) throw new TypeError("Generator is already executing.");
2823
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
2824
+ 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;
2825
+ if (y = 0, t) op = [op[0] & 2, t.value];
2826
+ switch (op[0]) {
2827
+ case 0: case 1: t = op; break;
2828
+ case 4: _.label++; return { value: op[1], done: false };
2829
+ case 5: _.label++; y = op[1]; op = [0]; continue;
2830
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
2831
+ default:
2832
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2833
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2834
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2835
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2836
+ if (t[2]) _.ops.pop();
2837
+ _.trys.pop(); continue;
2838
+ }
2839
+ op = body.call(thisArg, _);
2840
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2841
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2842
+ }
2843
+ };
2844
+
2807
2845
 
2808
2846
 
2809
2847
 
@@ -2812,29 +2850,41 @@ var chartRender = function (element, cdn, theme) {
2812
2850
  if (cdn === void 0) { cdn = _constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.CDN */ .g.CDN; }
2813
2851
  var echartsElements = _adapterRender__WEBPACK_IMPORTED_MODULE_1__.chartRenderAdapter.getElements(element);
2814
2852
  if (echartsElements.length > 0) {
2815
- (0,_util_addScript__WEBPACK_IMPORTED_MODULE_2__/* .addScript */ .G)("".concat(cdn, "/dist/js/echarts/echarts.min.js"), "vditorEchartsScript").then(function () {
2816
- echartsElements.forEach(function (e) {
2817
- if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
2818
- e.parentElement.classList.contains("vditor-ir__marker--pre")) {
2819
- return;
2820
- }
2821
- var text = _adapterRender__WEBPACK_IMPORTED_MODULE_1__.chartRenderAdapter.getCode(e).trim();
2822
- if (!text) {
2823
- return;
2824
- }
2825
- try {
2826
- if (e.getAttribute("data-processed") === "true") {
2827
- return;
2853
+ (0,_util_addScript__WEBPACK_IMPORTED_MODULE_2__/* .addScript */ .G)("".concat(cdn, "/dist/js/echarts/echarts.min.js?v=5.5.1"), "vditorEchartsScript").then(function () {
2854
+ echartsElements.forEach(function (e) { return __awaiter(void 0, void 0, void 0, function () {
2855
+ var text, option, error_1;
2856
+ return __generator(this, function (_a) {
2857
+ switch (_a.label) {
2858
+ case 0:
2859
+ if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
2860
+ e.parentElement.classList.contains("vditor-ir__marker--pre")) {
2861
+ return [2 /*return*/];
2862
+ }
2863
+ text = _adapterRender__WEBPACK_IMPORTED_MODULE_1__.chartRenderAdapter.getCode(e).trim();
2864
+ if (!text) {
2865
+ return [2 /*return*/];
2866
+ }
2867
+ _a.label = 1;
2868
+ case 1:
2869
+ _a.trys.push([1, 3, , 4]);
2870
+ if (e.getAttribute("data-processed") === "true") {
2871
+ return [2 /*return*/];
2872
+ }
2873
+ return [4 /*yield*/, (0,_util_function__WEBPACK_IMPORTED_MODULE_3__/* .looseJsonParse */ .Qf)(text)];
2874
+ case 2:
2875
+ option = _a.sent();
2876
+ echarts.init(e, theme === "dark" ? "dark" : undefined).setOption(option);
2877
+ e.setAttribute("data-processed", "true");
2878
+ return [3 /*break*/, 4];
2879
+ case 3:
2880
+ error_1 = _a.sent();
2881
+ e.className = "vditor-reset--error";
2882
+ e.innerHTML = "echarts render error: <br>".concat(error_1);
2883
+ return [3 /*break*/, 4];
2884
+ case 4: return [2 /*return*/];
2828
2885
  }
2829
- var option = JSON.parse(text);
2830
- echarts.init(e, theme === "dark" ? "dark" : undefined).setOption(option);
2831
- e.setAttribute("data-processed", "true");
2832
- }
2833
- catch (error) {
2834
- e.className = "vditor-reset--error";
2835
- e.innerHTML = "echarts render error: <br>".concat(error);
2836
- }
2837
- });
2886
+ });
2887
+ }); });
2838
2888
  });
2839
2889
  }
2840
2890
  };
@@ -3357,7 +3407,7 @@ var iframeRender = function (element, url) {
3357
3407
  }
3358
3408
  else if (url.indexOf("bilibili.com") > -1 && (url.indexOf("bvid=") > -1 || (bilibiliMatch && bilibiliMatch[1]))) {
3359
3409
  var params_1 = {
3360
- bvid: (0,_util_function__WEBPACK_IMPORTED_MODULE_0__/* .getSearch */ .o)("bvid", url) || (bilibiliMatch && bilibiliMatch[1]),
3410
+ bvid: (0,_util_function__WEBPACK_IMPORTED_MODULE_0__/* .getSearch */ .on)("bvid", url) || (bilibiliMatch && bilibiliMatch[1]),
3361
3411
  page: "1",
3362
3412
  high_quality: "1",
3363
3413
  as_wide: "1",
@@ -3506,7 +3556,7 @@ var mermaidRender = function (element, cdn, theme) {
3506
3556
  if (item.getAttribute("data-processed") === "true" || code.trim() === "") {
3507
3557
  return [2 /*return*/];
3508
3558
  }
3509
- id = "mermaid" + (0,_util_function__WEBPACK_IMPORTED_MODULE_3__/* .genUUID */ .W)();
3559
+ id = "mermaid" + (0,_util_function__WEBPACK_IMPORTED_MODULE_3__/* .genUUID */ .Wb)();
3510
3560
  _a.label = 1;
3511
3561
  case 1:
3512
3562
  _a.trys.push([1, 3, , 4]);
@@ -3551,7 +3601,7 @@ var mindmapRender = function (element, cdn, theme) {
3551
3601
  if (cdn === void 0) { cdn = _constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.CDN */ .g.CDN; }
3552
3602
  var mindmapElements = _adapterRender__WEBPACK_IMPORTED_MODULE_1__.mindmapRenderAdapter.getElements(element);
3553
3603
  if (mindmapElements.length > 0) {
3554
- (0,_util_addScript__WEBPACK_IMPORTED_MODULE_2__/* .addScript */ .G)("".concat(cdn, "/dist/js/echarts/echarts.min.js"), "vditorEchartsScript").then(function () {
3604
+ (0,_util_addScript__WEBPACK_IMPORTED_MODULE_2__/* .addScript */ .G)("".concat(cdn, "/dist/js/echarts/echarts.min.js?v=5.5.1"), "vditorEchartsScript").then(function () {
3555
3605
  mindmapElements.forEach(function (e) {
3556
3606
  if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
3557
3607
  e.parentElement.classList.contains("vditor-ir__marker--pre")) {
@@ -4110,8 +4160,9 @@ var isChrome = function () {
4110
4160
 
4111
4161
  "use strict";
4112
4162
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4113
- /* harmony export */ "W": () => (/* binding */ genUUID),
4114
- /* harmony export */ "o": () => (/* binding */ getSearch)
4163
+ /* harmony export */ "Qf": () => (/* binding */ looseJsonParse),
4164
+ /* harmony export */ "Wb": () => (/* binding */ genUUID),
4165
+ /* harmony export */ "on": () => (/* binding */ getSearch)
4115
4166
  /* harmony export */ });
4116
4167
  var genUUID = function () { return ([1e7].toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
4117
4168
  return (parseInt(c, 10) ^ (window.crypto.getRandomValues(new Uint32Array(1))[0] & (15 >> (parseInt(c, 10) / 4)))).toString(16);
@@ -4124,6 +4175,9 @@ var getSearch = function (key, link) {
4124
4175
  var urlSearchParams = new URLSearchParams(params.substring(0, hashIndex >= 0 ? hashIndex : undefined));
4125
4176
  return urlSearchParams.get(key);
4126
4177
  };
4178
+ var looseJsonParse = function (text) {
4179
+ return Function("\"use strict\";return (".concat(text, ")"))();
4180
+ };
4127
4181
 
4128
4182
 
4129
4183
  /***/ }),
@@ -4771,7 +4825,7 @@ var DevTools = /** @class */ (function () {
4771
4825
  if (vditor.devtools.element.style.display !== "block") {
4772
4826
  return;
4773
4827
  }
4774
- (0,addScript/* addScript */.G)("".concat(vditor.options.cdn, "/dist/js/echarts/echarts.min.js"), "vditorEchartsScript").then(function () {
4828
+ (0,addScript/* addScript */.G)("".concat(vditor.options.cdn, "/dist/js/echarts/echarts.min.js?v=5.5.1"), "vditorEchartsScript").then(function () {
4775
4829
  if (!_this.ASTChart) {
4776
4830
  _this.ASTChart = echarts.init(vditor.devtools.element.lastElementChild);
4777
4831
  }
@@ -5230,6 +5284,10 @@ var input = function (vditor, range, ignoreSpace, event) {
5230
5284
  }
5231
5285
  return;
5232
5286
  }
5287
+ // https://github.com/Vanessa219/vditor/issues/729
5288
+ if (endSpace && /^#{1,6} $/.test(blockElement.textContent)) {
5289
+ endSpace = false;
5290
+ }
5233
5291
  if (endSpace) {
5234
5292
  var markerElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-ir__marker");
5235
5293
  if (markerElement) {
@@ -5697,7 +5755,7 @@ var processKeydown = function (vditor, event) {
5697
5755
  // 光标位于标题前,marker 后
5698
5756
  if (headingElement) {
5699
5757
  var headingLength = headingElement.firstElementChild.textContent.length;
5700
- if ((0,selection/* getSelectPosition */.im)(headingElement, vditor.ir.element).start === headingLength) {
5758
+ if ((0,selection/* getSelectPosition */.im)(headingElement, vditor.ir.element).start === headingLength && headingLength !== 0) {
5701
5759
  range.setStart(headingElement.firstElementChild.firstChild, headingLength - 1);
5702
5760
  range.collapse(true);
5703
5761
  (0,selection/* setSelectionFocus */.Hc)(range);
@@ -14985,6 +15043,10 @@ var WYSIWYG = /** @class */ (function () {
14985
15043
  break;
14986
15044
  }
14987
15045
  }
15046
+ // https://github.com/Vanessa219/vditor/issues/729
15047
+ if (endSpace && /^#{1,6} $/.test(blockElement.textContent)) {
15048
+ endSpace = false;
15049
+ }
14988
15050
  var headingElement = (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(getSelection().getRangeAt(0).startContainer);
14989
15051
  if (headingElement && headingElement.textContent === "") {
14990
15052
  // heading 为空删除 https://github.com/Vanessa219/vditor/issues/150
@@ -15213,6 +15275,8 @@ var src_extends = (undefined && undefined.__extends) || (function () {
15213
15275
 
15214
15276
 
15215
15277
 
15278
+
15279
+
15216
15280
 
15217
15281
 
15218
15282
 
@@ -15364,7 +15428,9 @@ var Vditor = /** @class */ (function (_super) {
15364
15428
  };
15365
15429
  /** 清除缓存 */
15366
15430
  Vditor.prototype.clearCache = function () {
15367
- localStorage.removeItem(this.vditor.options.cache.id);
15431
+ if (this.vditor.options.cache.enable && (0,compatibility/* accessLocalStorage */.pK)()) {
15432
+ localStorage.removeItem(this.vditor.options.cache.id);
15433
+ }
15368
15434
  };
15369
15435
  /** 禁用缓存 */
15370
15436
  Vditor.prototype.disabledCache = function () {
@@ -15413,6 +15479,8 @@ var Vditor = /** @class */ (function (_super) {
15413
15479
  if (render === void 0) { render = true; }
15414
15480
  var range = (0,selection/* getEditorRange */.zh)(this.vditor);
15415
15481
  range.collapse(true);
15482
+ // https://github.com/Vanessa219/vditor/issues/716
15483
+ // https://github.com/Vanessa219/vditor/issues/917
15416
15484
  var tmpElement = document.createElement("template");
15417
15485
  tmpElement.innerHTML = value;
15418
15486
  range.insertNode(tmpElement.content.cloneNode(true));
@@ -15436,6 +15504,21 @@ var Vditor = /** @class */ (function (_super) {
15436
15504
  }
15437
15505
  }
15438
15506
  };
15507
+ /** 在焦点处插入 Markdown */
15508
+ Vditor.prototype.insertMD = function (md) {
15509
+ // https://github.com/Vanessa219/vditor/issues/1640
15510
+ if (this.vditor.currentMode === "ir") {
15511
+ (0,selection/* insertHTML */.oC)(this.vditor.lute.Md2VditorIRDOM(md), this.vditor);
15512
+ }
15513
+ else if (this.vditor.currentMode === "wysiwyg") {
15514
+ (0,selection/* insertHTML */.oC)(this.vditor.lute.Md2VditorDOM(md), this.vditor);
15515
+ }
15516
+ else {
15517
+ processPaste(this.vditor, md);
15518
+ }
15519
+ this.vditor.outline.render(this.vditor);
15520
+ execAfterRender(this.vditor);
15521
+ };
15439
15522
  /** 设置编辑器内容 */
15440
15523
  Vditor.prototype.setValue = function (markdown, clearStack) {
15441
15524
  var _this = this;