vditor 4.0.2-alpha.5 → 4.0.2-alpha.7

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 v4.0.2-alpha.5 - A markdown editor written in TypeScript.
2
+ * Vditor v4.0.2-alpha.7 - 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 v4.0.2-alpha.5 - A markdown editor written in TypeScript.
28
+ * Vditor v4.0.2-alpha.7 - 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 v4.0.2-alpha.5 - A markdown editor written in TypeScript.
2
+ * Vditor v4.0.2-alpha.7 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2121,8 +2121,8 @@ var abcRender = __webpack_require__(135);
2121
2121
  var adapterRender = __webpack_require__(840);
2122
2122
  // EXTERNAL MODULE: ./src/ts/markdown/chartRender.ts
2123
2123
  var chartRender = __webpack_require__(775);
2124
- // EXTERNAL MODULE: ./src/ts/markdown/codeRender.ts
2125
- var codeRender = __webpack_require__(428);
2124
+ // EXTERNAL MODULE: ./src/ts/markdown/codeRender.ts + 1 modules
2125
+ var codeRender = __webpack_require__(631);
2126
2126
  // EXTERNAL MODULE: ./src/ts/markdown/flowchartRender.ts
2127
2127
  var flowchartRender = __webpack_require__(325);
2128
2128
  // EXTERNAL MODULE: ./src/ts/markdown/graphvizRender.ts
@@ -2647,7 +2647,7 @@ var Vditor = /** @class */ (function () {
2647
2647
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2648
2648
  /* harmony export */ "g": () => (/* binding */ Constants)
2649
2649
  /* harmony export */ });
2650
- var _VDITOR_VERSION = "4.0.2-alpha.5";
2650
+ var _VDITOR_VERSION = "4.0.2-alpha.7";
2651
2651
 
2652
2652
  var Constants = /** @class */ (function () {
2653
2653
  function Constants() {
@@ -2695,7 +2695,7 @@ var Constants = /** @class */ (function () {
2695
2695
  // 别名
2696
2696
  "js", "ts", "html", "toml", "c#", "bat"
2697
2697
  ];
2698
- Constants.CDN = "https://unpkg.com/vditor@".concat("4.0.2-alpha.5");
2698
+ Constants.CDN = "https://unpkg.com/vditor@".concat("4.0.2-alpha.7");
2699
2699
  Constants.MARKDOWN_OPTIONS = {
2700
2700
  autoSpace: false,
2701
2701
  callout: true,
@@ -2986,17 +2986,73 @@ var chartRender = function (element, cdn, theme) {
2986
2986
 
2987
2987
  /***/ }),
2988
2988
 
2989
- /***/ 428:
2989
+ /***/ 631:
2990
2990
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2991
2991
 
2992
2992
  "use strict";
2993
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2994
- /* harmony export */ "O": () => (/* binding */ codeRender)
2995
- /* harmony export */ });
2996
- /* harmony import */ var _util_code160to32__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(105);
2997
- /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(145);
2998
2993
 
2994
+ // EXPORTS
2995
+ __webpack_require__.d(__webpack_exports__, {
2996
+ "O": () => (/* binding */ codeRender)
2997
+ });
2999
2998
 
2999
+ // EXTERNAL MODULE: ./src/ts/util/code160to32.ts
3000
+ var code160to32 = __webpack_require__(105);
3001
+ ;// CONCATENATED MODULE: ./src/ts/markdown/codeCopy.ts
3002
+ // Bind outside HTML attributes so strict CSP and restored undo snapshots work alike.
3003
+ var bindCodeCopy = function (menu, textarea, button) {
3004
+ var _a;
3005
+ var doc = menu.ownerDocument;
3006
+ var label = ((_a = window.VditorI18n) === null || _a === void 0 ? void 0 : _a.copy) || "复制";
3007
+ button.setAttribute("aria-label", label);
3008
+ button.setAttribute("role", "button");
3009
+ button.tabIndex = 0;
3010
+ button.addEventListener("mouseover", function () { return button.setAttribute("aria-label", label); });
3011
+ var copy = function (event) {
3012
+ var _a;
3013
+ event.preventDefault();
3014
+ event.stopPropagation();
3015
+ var active = doc.activeElement;
3016
+ var input = active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement ? active : undefined;
3017
+ var inputSelection = input && input.selectionStart !== null ?
3018
+ { start: input.selectionStart, end: input.selectionEnd, direction: input.selectionDirection } : undefined;
3019
+ var selection = doc.getSelection();
3020
+ var ranges = Array.from({ length: (selection === null || selection === void 0 ? void 0 : selection.rangeCount) || 0 }, function (_, index) { return selection.getRangeAt(index).cloneRange(); });
3021
+ button.setAttribute("aria-label", label);
3022
+ var copied = false;
3023
+ try {
3024
+ textarea.select();
3025
+ copied = doc.execCommand("copy");
3026
+ }
3027
+ finally {
3028
+ textarea.blur();
3029
+ if (active instanceof HTMLElement && active.isConnected)
3030
+ active.focus({ preventScroll: true });
3031
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
3032
+ ranges.forEach(function (range) { return selection === null || selection === void 0 ? void 0 : selection.addRange(range); });
3033
+ if (inputSelection && input.isConnected) {
3034
+ input.setSelectionRange(inputSelection.start, inputSelection.end, inputSelection.direction);
3035
+ }
3036
+ }
3037
+ if (copied) {
3038
+ button.setAttribute("aria-label", ((_a = window.VditorI18n) === null || _a === void 0 ? void 0 : _a.copied) || "已复制");
3039
+ button.dispatchEvent(new CustomEvent("vditor-copy-success", { bubbles: true, detail: { label: label } }));
3040
+ }
3041
+ };
3042
+ button.addEventListener("click", copy);
3043
+ button.addEventListener("keydown", function (event) {
3044
+ if (event.key === "Enter" || event.key === " ")
3045
+ copy(event);
3046
+ });
3047
+ };
3048
+
3049
+ // EXTERNAL MODULE: ./src/ts/constants.ts
3050
+ var constants = __webpack_require__(145);
3051
+ ;// CONCATENATED MODULE: ./src/ts/markdown/codeRender.ts
3052
+
3053
+
3054
+
3055
+ var initializedMenus = new WeakSet();
3000
3056
  var codeRender = function (element, option) {
3001
3057
  Array.from(element.querySelectorAll("pre > code")).filter(function (e, index) {
3002
3058
  if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
@@ -3010,16 +3066,19 @@ var codeRender = function (element, option) {
3010
3066
  e.classList.contains("language-math") || e.classList.contains("language-smiles")) {
3011
3067
  return false;
3012
3068
  }
3013
- if (e.style.maxHeight.indexOf("px") > -1) {
3014
- return false;
3015
- }
3016
3069
  // 避免预览区在渲染后由于代码块过多产生性能问题 https://github.com/b3log/vditor/issues/67
3017
3070
  if (element.classList.contains("vditor-preview") && index > 5) {
3018
3071
  return false;
3019
3072
  }
3020
3073
  return true;
3021
3074
  }).forEach(function (e) {
3022
- var _a, _b, _c;
3075
+ var _a;
3076
+ var previous = e.previousElementSibling;
3077
+ if (previous === null || previous === void 0 ? void 0 : previous.classList.contains("vditor-copy")) {
3078
+ if (initializedMenus.has(previous))
3079
+ return;
3080
+ previous.remove();
3081
+ }
3023
3082
  var codeText = e.innerText;
3024
3083
  if (e.classList.contains("highlight-chroma")) {
3025
3084
  var codeElement = e.cloneNode(true);
@@ -3037,17 +3096,25 @@ var codeRender = function (element, option) {
3037
3096
  }
3038
3097
  var divElement = document.createElement("div");
3039
3098
  divElement.className = "vditor-copy";
3040
- divElement.innerHTML = "<span aria-label=\"".concat(((_a = window.VditorI18n) === null || _a === void 0 ? void 0 : _a.copy) || "复制", "\"\nonmouseover=\"this.setAttribute('aria-label', '").concat(((_b = window.VditorI18n) === null || _b === void 0 ? void 0 : _b.copy) || "复制", "')\"\nclass=\"vditor-tooltipped vditor-tooltipped__w\"\nonclick=\"event.stopPropagation();this.previousElementSibling.select();document.execCommand('copy');this.setAttribute('aria-label', '").concat(((_c = window.VditorI18n) === null || _c === void 0 ? void 0 : _c.copied) || "已复制", "');this.previousElementSibling.blur()\">").concat(iconHTML, "</span>");
3099
+ var button = document.createElement("span");
3100
+ button.className = "vditor-tooltipped vditor-tooltipped__w";
3101
+ button.innerHTML = iconHTML;
3102
+ divElement.appendChild(button);
3041
3103
  var textarea = document.createElement("textarea");
3042
- textarea.value = (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_1__/* .code160to32 */ .X)(codeText);
3104
+ textarea.value = (0,code160to32/* code160to32 */.X)(codeText);
3043
3105
  divElement.insertAdjacentElement("afterbegin", textarea);
3106
+ bindCodeCopy(divElement, textarea, button);
3107
+ initializedMenus.add(divElement);
3044
3108
  if (option && option.renderMenu) {
3045
3109
  option.renderMenu(e, divElement);
3046
3110
  }
3047
3111
  e.before(divElement);
3048
3112
  e.style.maxHeight = (window.outerHeight - 40) + "px";
3049
3113
  // https://github.com/Vanessa219/vditor/issues/1356
3050
- e.insertAdjacentHTML("afterend", "<span style=\"position: absolute\">".concat(_constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.ZWSP */ .g.ZWSP, "</span>"));
3114
+ if (!(((_a = e.nextElementSibling) === null || _a === void 0 ? void 0 : _a.textContent) === constants/* Constants.ZWSP */.g.ZWSP &&
3115
+ e.nextElementSibling.style.position === "absolute")) {
3116
+ e.insertAdjacentHTML("afterend", "<span style=\"position: absolute\">".concat(constants/* Constants.ZWSP */.g.ZWSP, "</span>"));
3117
+ }
3051
3118
  });
3052
3119
  };
3053
3120
 
@@ -5524,8 +5591,8 @@ var log = function (method, content, type, print) {
5524
5591
  var abcRender = __webpack_require__(135);
5525
5592
  // EXTERNAL MODULE: ./src/ts/markdown/chartRender.ts
5526
5593
  var chartRender = __webpack_require__(775);
5527
- // EXTERNAL MODULE: ./src/ts/markdown/codeRender.ts
5528
- var codeRender = __webpack_require__(428);
5594
+ // EXTERNAL MODULE: ./src/ts/markdown/codeRender.ts + 1 modules
5595
+ var codeRender = __webpack_require__(631);
5529
5596
  // EXTERNAL MODULE: ./src/ts/markdown/flowchartRender.ts
5530
5597
  var flowchartRender = __webpack_require__(325);
5531
5598
  // EXTERNAL MODULE: ./src/ts/markdown/graphvizRender.ts
@@ -14734,6 +14801,7 @@ var codeDOM = __webpack_require__(787);
14734
14801
 
14735
14802
 
14736
14803
 
14804
+
14737
14805
  var undo_Undo = /** @class */ (function () {
14738
14806
  function Undo() {
14739
14807
  this.stackSize = 50;
@@ -14917,6 +14985,7 @@ var undo_Undo = /** @class */ (function () {
14917
14985
  vditor[vditor.currentMode].element.querySelectorAll(".vditor-code__preview")
14918
14986
  .forEach(function (item) {
14919
14987
  highlightEditableCode(item, vditor);
14988
+ (0,codeRender/* codeRender */.O)(item, vditor.options.preview.hljs);
14920
14989
  // 快照可能早于异步高亮完成,普通预览需补齐其渲染结果。
14921
14990
  if (!item.querySelector("code.hljs")) {
14922
14991
  (0,highlightRender/* highlightRender */.s)(vditor.options.preview.hljs, item, vditor.options.cdn);