@8btc/mditor 0.0.15 → 0.0.16

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 v0.0.15 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.16 - 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 v0.0.15 - A markdown editor written in TypeScript.
28
+ * Vditor v0.0.16 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.15 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.16 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2564,13 +2564,13 @@ var mergeOptions = function (options) {
2564
2564
  speech: {
2565
2565
  enable: false,
2566
2566
  },
2567
- runHtml: {
2567
+ runCode: {
2568
2568
  enable: false,
2569
2569
  },
2570
2570
  render: {
2571
2571
  media: {
2572
2572
  enable: true,
2573
- }
2573
+ },
2574
2574
  },
2575
2575
  theme: constants/* Constants.THEME_OPTIONS */.g.THEME_OPTIONS,
2576
2576
  };
@@ -2635,12 +2635,27 @@ var previewRender = function (previewElement, markdown, options) { return __awai
2635
2635
  previewElement.innerHTML = html;
2636
2636
  previewElement.classList.add("vditor-reset");
2637
2637
  if (!!mergedOptions.i18n) return [3 /*break*/, 5];
2638
- if (!!["de_DE", "en_US", "es_ES", "fr_FR", "ja_JP", "ko_KR", "pt_BR", "ru_RU", "sv_SE", "vi_VN", "zh_CN", "zh_TW"].includes(mergedOptions.lang)) return [3 /*break*/, 2];
2638
+ if (!![
2639
+ "de_DE",
2640
+ "en_US",
2641
+ "es_ES",
2642
+ "fr_FR",
2643
+ "ja_JP",
2644
+ "ko_KR",
2645
+ "pt_BR",
2646
+ "ru_RU",
2647
+ "sv_SE",
2648
+ "vi_VN",
2649
+ "zh_CN",
2650
+ "zh_TW",
2651
+ ].includes(mergedOptions.lang)) return [3 /*break*/, 2];
2639
2652
  throw new Error("options.lang error, see https://ld246.com/article/1549638745630#options");
2640
2653
  case 2:
2641
2654
  i18nScriptPrefix = "vditorI18nScript";
2642
2655
  i18nScriptID_1 = i18nScriptPrefix + mergedOptions.lang;
2643
- document.querySelectorAll("head script[id^=\"".concat(i18nScriptPrefix, "\"]")).forEach(function (el) {
2656
+ document
2657
+ .querySelectorAll("head script[id^=\"".concat(i18nScriptPrefix, "\"]"))
2658
+ .forEach(function (el) {
2644
2659
  if (el.id !== i18nScriptID_1) {
2645
2660
  document.head.removeChild(el);
2646
2661
  }
@@ -2664,7 +2679,7 @@ var previewRender = function (previewElement, markdown, options) { return __awai
2664
2679
  if (mergedOptions.anchor === 1) {
2665
2680
  previewElement.classList.add("vditor-reset--anchor");
2666
2681
  }
2667
- (0,codeRender/* codeRender */.O)(previewElement, mergedOptions.hljs, mergedOptions.runHtml);
2682
+ (0,codeRender/* codeRender */.O)(previewElement, mergedOptions.hljs, mergedOptions.runCode);
2668
2683
  (0,highlightRender/* highlightRender */.s)(mergedOptions.hljs, previewElement, mergedOptions.cdn);
2669
2684
  (0,mathRender/* mathRender */.H)(previewElement, {
2670
2685
  cdn: mergedOptions.cdn,
@@ -2697,7 +2712,8 @@ var previewRender = function (previewElement, markdown, options) { return __awai
2697
2712
  }
2698
2713
  previewElement.addEventListener("click", function (event) {
2699
2714
  var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
2700
- if (spanElement && (0,hasClosest/* hasClosestByClassName */.fb)(spanElement, "vditor-toc")) {
2715
+ if (spanElement &&
2716
+ (0,hasClosest/* hasClosestByClassName */.fb)(spanElement, "vditor-toc")) {
2701
2717
  var headingElement = previewElement.querySelector("#" + spanElement.getAttribute("data-target-id"));
2702
2718
  if (headingElement) {
2703
2719
  window.scrollTo(window.scrollX, headingElement.offsetTop);
@@ -2828,7 +2844,7 @@ var Vditor = /** @class */ (function () {
2828
2844
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2829
2845
  /* harmony export */ "g": () => (/* binding */ Constants)
2830
2846
  /* harmony export */ });
2831
- var _VDITOR_VERSION = "0.0.15";
2847
+ var _VDITOR_VERSION = "0.0.16";
2832
2848
 
2833
2849
  var Constants = /** @class */ (function () {
2834
2850
  function Constants() {
@@ -3130,7 +3146,7 @@ var Constants = /** @class */ (function () {
3130
3146
  "c#",
3131
3147
  "bat",
3132
3148
  ];
3133
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.15");
3149
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.16");
3134
3150
  Constants.MARKDOWN_OPTIONS = {
3135
3151
  autoSpace: false,
3136
3152
  gfmAutoLink: true,
@@ -4491,9 +4507,9 @@ var attachEchartsContextMenu = function (el, option, chart, cdn) {
4491
4507
  /**
4492
4508
  * 为预览区域中的代码块添加辅助操作:
4493
4509
  * - 复制按钮:一键复制代码文本
4494
- * - 运行按钮:当启用 runHtml 时,向外部回调当前代码块的 HTML 字符串
4510
+ * - 运行按钮:当启用 runCode 时,向外部回调当前代码块的 HTML 字符串
4495
4511
  */
4496
- var codeRender = function (element, option, runHtml) {
4512
+ var codeRender = function (element, option, runCode) {
4497
4513
  Array.from(element.querySelectorAll("pre > code"))
4498
4514
  .filter(function (e, index) {
4499
4515
  if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
@@ -4542,14 +4558,18 @@ var codeRender = function (element, option, runHtml) {
4542
4558
  '<svg viewBox="0 0 32 32"><path d="M22.545-0h-17.455c-1.6 0-2.909 1.309-2.909 2.909v20.364h2.909v-20.364h17.455v-2.909zM26.909 5.818h-16c-1.6 0-2.909 1.309-2.909 2.909v20.364c0 1.6 1.309 2.909 2.909 2.909h16c1.6 0 2.909-1.309 2.909-2.909v-20.364c0-1.6-1.309-2.909-2.909-2.909zM26.909 29.091h-16v-20.364h16v20.364z"></path></svg>';
4543
4559
  }
4544
4560
  var playIconHTML = document.getElementById("vditorIconScript")
4545
- ? '<svg><use xlink:href="#vditor-icon-play"></use></svg>'
4561
+ ? '<svg><use xlink:href="#vditor-icon-run"></use></svg>'
4546
4562
  : '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-play-icon lucide-circle-play"><path d="M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z"/><circle cx="12" cy="12" r="10"/></svg>';
4547
4563
  var divElement = document.createElement("div");
4548
4564
  divElement.className = "vditor-copy";
4549
4565
  var textarea = document.createElement("textarea");
4550
4566
  textarea.value = (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_1__/* .code160to32 */ .X)(codeText);
4551
4567
  divElement.appendChild(textarea);
4552
- if (runHtml === null || runHtml === void 0 ? void 0 : runHtml.enable) {
4568
+ var langMatch = e.className.match(/language-([^\s]+)/);
4569
+ var lang = langMatch ? langMatch[1] : "";
4570
+ var allowRun = !!(runCode === null || runCode === void 0 ? void 0 : runCode.enable) &&
4571
+ (!runCode.items || (lang && runCode.items.includes(lang)));
4572
+ if (allowRun) {
4553
4573
  var runSpan = document.createElement("span");
4554
4574
  runSpan.setAttribute("aria-label", ((_a = window.VditorI18n) === null || _a === void 0 ? void 0 : _a.run) || "运行");
4555
4575
  runSpan.setAttribute("onmouseover", "this.setAttribute('aria-label', '".concat(((_b = window.VditorI18n) === null || _b === void 0 ? void 0 : _b.run) || "运行", "')"));
@@ -4557,10 +4577,12 @@ var codeRender = function (element, option, runHtml) {
4557
4577
  "vditor-copy__item vditor-tooltipped vditor-tooltipped__w";
4558
4578
  runSpan.innerHTML = playIconHTML;
4559
4579
  runSpan.addEventListener("click", function (evt) {
4580
+ var _a;
4560
4581
  evt.stopPropagation();
4561
- if (typeof runHtml.callback === "function") {
4562
- runHtml.callback((0,_util_code160to32__WEBPACK_IMPORTED_MODULE_1__/* .code160to32 */ .X)(codeText));
4563
- }
4582
+ (_a = runCode === null || runCode === void 0 ? void 0 : runCode.callback) === null || _a === void 0 ? void 0 : _a.call(runCode, {
4583
+ code: (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_1__/* .code160to32 */ .X)(codeText),
4584
+ lang: lang,
4585
+ });
4564
4586
  });
4565
4587
  divElement.appendChild(runSpan);
4566
4588
  }