@8btc/mditor 0.0.15 → 0.0.17

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.
@@ -196,3 +196,21 @@
196
196
  color: #0a0a0a !important;
197
197
  }
198
198
  }
199
+
200
+ .vditor-reset .mermaid-error {
201
+ border: 1px dashed rgba(255, 255, 255, 0.2);
202
+ }
203
+
204
+ .vditor-reset .mermaid-error .mermaid-error-icon {
205
+ border: 1px solid rgba(255, 255, 255, 0.2);
206
+ }
207
+
208
+ .vditor-reset .mermaid-error .mermaid-error-title {
209
+ color: rgba(252, 252, 252, 0.9);
210
+ }
211
+ .vditor-reset .mermaid-error .mermaid-error-message {
212
+ color: #a3a3a3;
213
+ }
214
+ .vditor-reset .mermaid-error .mermaid-error-icon {
215
+ color: rgba(252, 252, 252, 0.9);
216
+ }
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.17 - 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.17 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
@@ -115,7 +115,7 @@
115
115
  }
116
116
  }
117
117
  .vditor-tooltipped {
118
- position: relative;
118
+ position: relative !important;
119
119
  cursor: pointer;
120
120
  }
121
121
  .vditor-tooltipped::after {
@@ -2124,6 +2124,37 @@
2124
2124
  .vditor--dark .vditor-reset .vditor-selection-tag .vditor-selection-tag__lines {
2125
2125
  color: #b9b9b9;
2126
2126
  }
2127
+ .mermaid-error {
2128
+ border: 1px dashed #E5E5E5;
2129
+ border-radius: 0.625rem;
2130
+ padding: 3rem 1.5rem;
2131
+ text-align: center;
2132
+ }
2133
+ .mermaid-error .mermaid-error-icon {
2134
+ display: inline-block;
2135
+ color: #0A0A0A;
2136
+ padding: 0.5rem;
2137
+ border-radius: 0.5rem;
2138
+ margin-bottom: 1.5rem;
2139
+ border: 1px solid #E5E5E5;
2140
+ line-height: 1;
2141
+ }
2142
+ .mermaid-error .mermaid-error-icon > svg {
2143
+ display: block;
2144
+ stroke-width: 2;
2145
+ }
2146
+ .mermaid-error .mermaid-error-title {
2147
+ font-size: 1.25rem;
2148
+ color: #0A0A0A;
2149
+ font-weight: 700;
2150
+ line-height: 140%;
2151
+ margin-bottom: 0.5rem;
2152
+ }
2153
+ .mermaid-error .mermaid-error-message {
2154
+ font-size: 0.875rem;
2155
+ line-height: 140%;
2156
+ color: #737373;
2157
+ }
2127
2158
  details > summary {
2128
2159
  list-style: none;
2129
2160
  }
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.17 - 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.17";
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.17");
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
  }
@@ -5726,19 +5748,19 @@ var mermaidRender = function (element, cdn, theme) {
5726
5748
  startOnLoad: false,
5727
5749
  flowchart: {
5728
5750
  htmlLabels: true,
5729
- useMaxWidth: !0
5751
+ useMaxWidth: !0,
5730
5752
  },
5731
5753
  sequence: {
5732
5754
  useMaxWidth: true,
5733
5755
  diagramMarginX: 8,
5734
5756
  diagramMarginY: 8,
5735
5757
  boxMargin: 8,
5736
- showSequenceNumbers: true // Mermaid 时序图增加序号 https://github.com/siyuan-note/siyuan/pull/6992 https://mermaid.js.org/syntax/sequenceDiagram.html#sequencenumbers
5758
+ showSequenceNumbers: true, // Mermaid 时序图增加序号 https://github.com/siyuan-note/siyuan/pull/6992 https://mermaid.js.org/syntax/sequenceDiagram.html#sequencenumbers
5737
5759
  },
5738
5760
  gantt: {
5739
5761
  leftPadding: 75,
5740
- rightPadding: 20
5741
- }
5762
+ rightPadding: 20,
5763
+ },
5742
5764
  };
5743
5765
  if (theme === "dark") {
5744
5766
  config.theme = "dark";
@@ -5750,7 +5772,8 @@ var mermaidRender = function (element, cdn, theme) {
5750
5772
  switch (_a.label) {
5751
5773
  case 0:
5752
5774
  code = _adapterRender__WEBPACK_IMPORTED_MODULE_1__.mermaidRenderAdapter.getCode(item);
5753
- if (item.getAttribute("data-processed") === "true" || code.trim() === "") {
5775
+ if (item.getAttribute("data-processed") === "true" ||
5776
+ code.trim() === "") {
5754
5777
  return [2 /*return*/];
5755
5778
  }
5756
5779
  id = "mermaid" + (0,_util_function__WEBPACK_IMPORTED_MODULE_3__/* .genUUID */ .Wb)();
@@ -5765,7 +5788,7 @@ var mermaidRender = function (element, cdn, theme) {
5765
5788
  case 3:
5766
5789
  e_1 = _a.sent();
5767
5790
  errorElement = document.querySelector("#" + id);
5768
- item.innerHTML = "".concat(errorElement.outerHTML, "<br>\n<div style=\"text-align: left\"><small>").concat(e_1.message.replace(/\n/, "<br>"), "</small></div>");
5791
+ item.innerHTML = "\n<div class=\"mermaid-error\">\n<div class=\"mermaid-error-icon\"><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-bug-icon lucide-bug\"><path d=\"M12 20v-9\"/><path d=\"M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z\"/><path d=\"M14.12 3.88 16 2\"/><path d=\"M21 21a4 4 0 0 0-3.81-4\"/><path d=\"M21 5a4 4 0 0 1-3.55 3.97\"/><path d=\"M22 13h-4\"/><path d=\"M3 21a4 4 0 0 1 3.81-4\"/><path d=\"M3 5a4 4 0 0 0 3.55 3.97\"/><path d=\"M6 13H2\"/><path d=\"m8 2 1.88 1.88\"/><path d=\"M9 7.13V6a3 3 0 1 1 6 0v1.13\"/></svg></div>\n<div class=\"mermaid-error-title\">\u56FE\u8868\u52A0\u8F7D\u5931\u8D25</div>\n<div class=\"mermaid-error-message\">".concat(e_1.message.replace(/\n/, "<br>"), "</div>\n</div>");
5769
5792
  errorElement.parentElement.remove();
5770
5793
  return [3 /*break*/, 4];
5771
5794
  case 4: