@8btc/mditor 0.0.24 → 0.0.26
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/css/content-theme/dark.css +10 -0
- package/dist/css/content-theme/light.css +10 -0
- package/dist/index.css +58 -2
- package/dist/index.js +371 -32
- package/dist/index.min.js +1 -1
- package/dist/js/lute/lute.min.js +29 -1
- package/dist/method.js +267 -4
- package/dist/method.min.js +1 -1
- package/dist/ts/ir/index.d.ts +2 -0
- package/dist/ts/markdown/customRender.d.ts +73 -0
- package/dist/ts/preview/index.d.ts +2 -0
- package/dist/ts/sv/index.d.ts +2 -0
- package/dist/ts/util/mathSelection.d.ts +14 -0
- package/dist/ts/wysiwyg/index.d.ts +2 -1
- package/dist/types/index.d.ts +16 -0
- package/package.json +1 -1
- package/src/assets/less/_content.less +12 -0
- package/src/assets/less/_ir.less +12 -0
- package/src/assets/less/_sv.less +12 -0
- package/src/assets/less/_wysiwyg.less +12 -0
- package/src/assets/less/index.less +5 -0
- package/src/ts/ir/index.ts +43 -0
- package/src/ts/markdown/customRender.ts +203 -0
- package/src/ts/markdown/previewRender.ts +82 -0
- package/src/ts/preview/index.ts +14 -0
- package/src/ts/sv/index.ts +12 -0
- package/src/ts/util/Options.ts +1 -0
- package/src/ts/util/hasClosest.ts +29 -8
- package/src/ts/util/mathSelection.ts +59 -0
- package/src/ts/wysiwyg/index.ts +61 -33
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.26 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -2261,7 +2261,7 @@ module.exports.DIFF_EQUAL = DIFF_EQUAL;
|
|
|
2261
2261
|
|
|
2262
2262
|
/***/ }),
|
|
2263
2263
|
|
|
2264
|
-
/***/
|
|
2264
|
+
/***/ 242:
|
|
2265
2265
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2266
2266
|
|
|
2267
2267
|
"use strict";
|
|
@@ -2488,6 +2488,150 @@ var speechRender = function (element, lang) {
|
|
|
2488
2488
|
|
|
2489
2489
|
// EXTERNAL MODULE: ./src/ts/markdown/selectionRender.ts
|
|
2490
2490
|
var selectionRender = __webpack_require__(616);
|
|
2491
|
+
// EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
|
|
2492
|
+
var mathSelection = __webpack_require__(35);
|
|
2493
|
+
;// CONCATENATED MODULE: ./src/ts/markdown/customRender.ts
|
|
2494
|
+
/**
|
|
2495
|
+
* 自定义组件渲染模块
|
|
2496
|
+
* 支持将 HTML 标签(如 <read-button label="文献解读">)转换为自定义 HTML
|
|
2497
|
+
*/
|
|
2498
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
2499
|
+
__assign = Object.assign || function(t) {
|
|
2500
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2501
|
+
s = arguments[i];
|
|
2502
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
2503
|
+
t[p] = s[p];
|
|
2504
|
+
}
|
|
2505
|
+
return t;
|
|
2506
|
+
};
|
|
2507
|
+
return __assign.apply(this, arguments);
|
|
2508
|
+
};
|
|
2509
|
+
/**
|
|
2510
|
+
* 解析 HTML 属性字符串
|
|
2511
|
+
* @param str 属性字符串,如 'label="文献解读" id="test"'
|
|
2512
|
+
* @returns 属性对象
|
|
2513
|
+
*/
|
|
2514
|
+
function parseAttributes(str) {
|
|
2515
|
+
var attributes = {};
|
|
2516
|
+
if (!str)
|
|
2517
|
+
return attributes;
|
|
2518
|
+
var attrRegex = /(\w+)="([^"]*)"/g;
|
|
2519
|
+
var match;
|
|
2520
|
+
while ((match = attrRegex.exec(str)) !== null) {
|
|
2521
|
+
attributes[match[1]] = match[2];
|
|
2522
|
+
}
|
|
2523
|
+
return attributes;
|
|
2524
|
+
}
|
|
2525
|
+
/**
|
|
2526
|
+
* 从 HTML 字符串中提取自定义标签
|
|
2527
|
+
* @param html HTML 字符串
|
|
2528
|
+
* @param tagName 标签名称,如 'read-button'
|
|
2529
|
+
* @returns 匹配的标签信息数组
|
|
2530
|
+
*/
|
|
2531
|
+
function extractCustomTags(html, tagName) {
|
|
2532
|
+
var results = [];
|
|
2533
|
+
// 匹配自闭合标签和非自闭合标签
|
|
2534
|
+
var selfClosingRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)\\s*/>"), "g");
|
|
2535
|
+
var openCloseRegex = new RegExp("<".concat(tagName, "\\s+([^>]*)>([^<]*)</").concat(tagName, ">"), "g");
|
|
2536
|
+
var match;
|
|
2537
|
+
// 处理自闭合标签
|
|
2538
|
+
while ((match = selfClosingRegex.exec(html)) !== null) {
|
|
2539
|
+
results.push({
|
|
2540
|
+
fullTag: match[0],
|
|
2541
|
+
attributes: parseAttributes(match[1]),
|
|
2542
|
+
content: "",
|
|
2543
|
+
});
|
|
2544
|
+
}
|
|
2545
|
+
// 处理开闭合标签
|
|
2546
|
+
while ((match = openCloseRegex.exec(html)) !== null) {
|
|
2547
|
+
results.push({
|
|
2548
|
+
fullTag: match[0],
|
|
2549
|
+
attributes: parseAttributes(match[1]),
|
|
2550
|
+
content: match[2],
|
|
2551
|
+
});
|
|
2552
|
+
}
|
|
2553
|
+
return results;
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* 使用 HTML 字符串渲染自定义标签
|
|
2557
|
+
* @param html HTML 字符串
|
|
2558
|
+
* @param tagName 标签名称
|
|
2559
|
+
* @param component 自定义组件配置
|
|
2560
|
+
* @returns 修改后的 HTML 字符串
|
|
2561
|
+
*/
|
|
2562
|
+
function renderCustomComponentHTML(html, tagName, component) {
|
|
2563
|
+
var tags = extractCustomTags(html, tagName);
|
|
2564
|
+
var result = html;
|
|
2565
|
+
// 反向遍历以保持位置正确性
|
|
2566
|
+
for (var i = tags.length - 1; i >= 0; i--) {
|
|
2567
|
+
var tag = tags[i];
|
|
2568
|
+
var htmlString = component.renderHTML(tag.attributes);
|
|
2569
|
+
result = result.replace(tag.fullTag, htmlString);
|
|
2570
|
+
}
|
|
2571
|
+
return result;
|
|
2572
|
+
}
|
|
2573
|
+
/**
|
|
2574
|
+
* 在 DOM 元素中查找并渲染自定义组件
|
|
2575
|
+
* @param element DOM 元素
|
|
2576
|
+
* @param customComponents 自定义组件集合
|
|
2577
|
+
*/
|
|
2578
|
+
function renderCustomComponents(element, customComponents) {
|
|
2579
|
+
Object.keys(customComponents).forEach(function (tagName) {
|
|
2580
|
+
var component = customComponents[tagName];
|
|
2581
|
+
var customElements = element.querySelectorAll(tagName);
|
|
2582
|
+
console.log(element, customComponents, "customComponents");
|
|
2583
|
+
// 反向遍历以避免 DOM 修改时的索引问题
|
|
2584
|
+
Array.from(customElements)
|
|
2585
|
+
.reverse()
|
|
2586
|
+
.forEach(function (el) {
|
|
2587
|
+
var attributes = {};
|
|
2588
|
+
el.getAttributeNames().forEach(function (name) {
|
|
2589
|
+
attributes[name] = el.getAttribute(name) || "";
|
|
2590
|
+
});
|
|
2591
|
+
// 使用 innerHTML 保留内部 HTML 内容,而不仅仅是纯文本
|
|
2592
|
+
var content = el.innerHTML || "";
|
|
2593
|
+
// 使用 HTML 渲染
|
|
2594
|
+
var htmlString = component.renderHTML(__assign(__assign({}, attributes), { children: content }));
|
|
2595
|
+
el.outerHTML = htmlString;
|
|
2596
|
+
});
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
/**
|
|
2600
|
+
* 批量处理自定义组件 - 用于预处理 HTML 字符串
|
|
2601
|
+
* @param html HTML 字符串
|
|
2602
|
+
* @param customComponents 自定义组件集合
|
|
2603
|
+
* @returns 处理后的 HTML 字符串
|
|
2604
|
+
*/
|
|
2605
|
+
function processCustomComponents(html, customComponents) {
|
|
2606
|
+
var result = html;
|
|
2607
|
+
Object.keys(customComponents).forEach(function (tagName) {
|
|
2608
|
+
var component = customComponents[tagName];
|
|
2609
|
+
result = renderCustomComponentHTML(result, tagName, component);
|
|
2610
|
+
});
|
|
2611
|
+
return result;
|
|
2612
|
+
}
|
|
2613
|
+
/**
|
|
2614
|
+
* 处理 markdown 中的自定义组件
|
|
2615
|
+
* 将 markdown 中的自定义标签转换为对应的 HTML
|
|
2616
|
+
* @param markdown markdown 字符串
|
|
2617
|
+
* @param customComponents 自定义组件集合
|
|
2618
|
+
* @returns 处理后的 markdown 字符串
|
|
2619
|
+
*/
|
|
2620
|
+
function processMarkdownCustomComponents(markdown, customComponents) {
|
|
2621
|
+
var result = markdown;
|
|
2622
|
+
Object.keys(customComponents).forEach(function (tagName) {
|
|
2623
|
+
var component = customComponents[tagName];
|
|
2624
|
+
result = renderCustomComponentHTML(result, tagName, component);
|
|
2625
|
+
});
|
|
2626
|
+
return result;
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
2629
|
+
* 导出默认函数和其他公共 API
|
|
2630
|
+
*/
|
|
2631
|
+
function customRender(element, customComponents) {
|
|
2632
|
+
renderCustomComponents(element, customComponents);
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2491
2635
|
;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
|
|
2492
2636
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2493
2637
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -2545,6 +2689,8 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
2545
2689
|
|
|
2546
2690
|
|
|
2547
2691
|
|
|
2692
|
+
|
|
2693
|
+
|
|
2548
2694
|
|
|
2549
2695
|
|
|
2550
2696
|
|
|
@@ -2686,6 +2832,8 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2686
2832
|
_a.sent();
|
|
2687
2833
|
_a.label = 8;
|
|
2688
2834
|
case 8:
|
|
2835
|
+
console.log(previewElement, "previewElement");
|
|
2836
|
+
customRender(previewElement, mergedOptions.customComponents || {});
|
|
2689
2837
|
(0,setContentTheme/* setContentTheme */.Z)(mergedOptions.theme.current, mergedOptions.theme.path);
|
|
2690
2838
|
if (mergedOptions.anchor === 1) {
|
|
2691
2839
|
previewElement.classList.add("vditor-reset--anchor");
|
|
@@ -2721,6 +2869,61 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2721
2869
|
if (mergedOptions.lazyLoadImage) {
|
|
2722
2870
|
lazyLoadImageRender(previewElement);
|
|
2723
2871
|
}
|
|
2872
|
+
// 绑定数学公式选中高亮监听
|
|
2873
|
+
(0,mathSelection/* bindMathSelectionListener */.I)(previewElement);
|
|
2874
|
+
// 绑定复制事件,处理数学公式源码复制
|
|
2875
|
+
previewElement.addEventListener("copy", function (event) {
|
|
2876
|
+
var selection = window.getSelection();
|
|
2877
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
var range = selection.getRangeAt(0);
|
|
2881
|
+
// 检查选区是否只包含单个数学公式
|
|
2882
|
+
var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
|
|
2883
|
+
var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
|
|
2884
|
+
// 如果选区的起点和终点都在同一个数学公式元素内,复制源码
|
|
2885
|
+
if (mathElement &&
|
|
2886
|
+
mathEndElement &&
|
|
2887
|
+
mathElement.isSameNode(mathEndElement)) {
|
|
2888
|
+
event.stopPropagation();
|
|
2889
|
+
event.preventDefault();
|
|
2890
|
+
var mathSource = mathElement.getAttribute("data-math") || range.toString();
|
|
2891
|
+
event.clipboardData.setData("text/plain", mathSource);
|
|
2892
|
+
event.clipboardData.setData("text/html", "");
|
|
2893
|
+
return;
|
|
2894
|
+
}
|
|
2895
|
+
// 处理包含多个公式的混合内容
|
|
2896
|
+
var fragment = range.cloneContents();
|
|
2897
|
+
var mathElements = fragment.querySelectorAll(".language-math");
|
|
2898
|
+
if (mathElements.length > 0) {
|
|
2899
|
+
event.stopPropagation();
|
|
2900
|
+
event.preventDefault();
|
|
2901
|
+
// 创建临时容器来处理内容
|
|
2902
|
+
var tempDiv = document.createElement("div");
|
|
2903
|
+
tempDiv.appendChild(fragment);
|
|
2904
|
+
// 替换所有数学公式为源码
|
|
2905
|
+
tempDiv
|
|
2906
|
+
.querySelectorAll(".language-math")
|
|
2907
|
+
.forEach(function (mathEl) {
|
|
2908
|
+
var mathSource = mathEl.getAttribute("data-math");
|
|
2909
|
+
console.log(mathEl.tagName, "mathEl");
|
|
2910
|
+
if (mathSource) {
|
|
2911
|
+
if (mathEl.tagName === "SPAN") {
|
|
2912
|
+
var textNode = document.createTextNode("$".concat(mathSource, "$"));
|
|
2913
|
+
mathEl.parentNode.replaceChild(textNode, mathEl);
|
|
2914
|
+
}
|
|
2915
|
+
else {
|
|
2916
|
+
var textNode = document.createTextNode("$$".concat(mathSource, "$$"));
|
|
2917
|
+
mathEl.parentNode.replaceChild(textNode, mathEl);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
});
|
|
2921
|
+
// 获取纯文本内容
|
|
2922
|
+
var plainText = tempDiv.textContent || tempDiv.innerText || "";
|
|
2923
|
+
event.clipboardData.setData("text/plain", plainText);
|
|
2924
|
+
event.clipboardData.setData("text/html", "");
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2724
2927
|
previewElement.addEventListener("click", function (event) {
|
|
2725
2928
|
var _a, _b;
|
|
2726
2929
|
var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
|
|
@@ -2866,7 +3069,7 @@ var Vditor = /** @class */ (function () {
|
|
|
2866
3069
|
/* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
|
|
2867
3070
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
2868
3071
|
/* harmony export */ });
|
|
2869
|
-
var _VDITOR_VERSION = "0.0.
|
|
3072
|
+
var _VDITOR_VERSION = "0.0.26";
|
|
2870
3073
|
|
|
2871
3074
|
var Constants = /** @class */ (function () {
|
|
2872
3075
|
function Constants() {
|
|
@@ -3168,7 +3371,7 @@ var Constants = /** @class */ (function () {
|
|
|
3168
3371
|
"c#",
|
|
3169
3372
|
"bat",
|
|
3170
3373
|
];
|
|
3171
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
3374
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.26");
|
|
3172
3375
|
Constants.MARKDOWN_OPTIONS = {
|
|
3173
3376
|
autoSpace: false,
|
|
3174
3377
|
gfmAutoLink: true,
|
|
@@ -7256,7 +7459,8 @@ var getTopList = function (element) {
|
|
|
7256
7459
|
var topUlElement = hasTopClosestByTag(element, "UL");
|
|
7257
7460
|
var topOlElement = hasTopClosestByTag(element, "OL");
|
|
7258
7461
|
var topListElement = topUlElement;
|
|
7259
|
-
if (topOlElement &&
|
|
7462
|
+
if (topOlElement &&
|
|
7463
|
+
(!topUlElement || (topUlElement && topOlElement.contains(topUlElement)))) {
|
|
7260
7464
|
topListElement = topOlElement;
|
|
7261
7465
|
}
|
|
7262
7466
|
return topListElement;
|
|
@@ -7397,6 +7601,66 @@ var hasClosestByHeadings = function (element) {
|
|
|
7397
7601
|
};
|
|
7398
7602
|
|
|
7399
7603
|
|
|
7604
|
+
/***/ }),
|
|
7605
|
+
|
|
7606
|
+
/***/ 35:
|
|
7607
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
7608
|
+
|
|
7609
|
+
"use strict";
|
|
7610
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
7611
|
+
/* harmony export */ "I": () => (/* binding */ bindMathSelectionListener)
|
|
7612
|
+
/* harmony export */ });
|
|
7613
|
+
/* unused harmony export updateMathSelection */
|
|
7614
|
+
/**
|
|
7615
|
+
* 数学公式选中高亮工具
|
|
7616
|
+
* 监听选区变化,为选中的数学公式添加高亮样式
|
|
7617
|
+
*/
|
|
7618
|
+
var MATH_SELECTED_CLASS = "vditor-math--selected";
|
|
7619
|
+
/**
|
|
7620
|
+
* 检查并更新数学公式的选中高亮状态
|
|
7621
|
+
* @param container 容器元素(编辑器或预览区域)
|
|
7622
|
+
*/
|
|
7623
|
+
var updateMathSelection = function (container) {
|
|
7624
|
+
var selection = window.getSelection();
|
|
7625
|
+
// 获取所有数学公式元素
|
|
7626
|
+
var mathElements = container.querySelectorAll(".language-math");
|
|
7627
|
+
// 移除所有旧的高亮
|
|
7628
|
+
mathElements.forEach(function (el) { return el.classList.remove(MATH_SELECTED_CLASS); });
|
|
7629
|
+
// 无选中内容则返回
|
|
7630
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
|
|
7631
|
+
return;
|
|
7632
|
+
}
|
|
7633
|
+
// 检测选中的公式节点并添加高亮
|
|
7634
|
+
mathElements.forEach(function (element) {
|
|
7635
|
+
if (selection.containsNode(element, true)) {
|
|
7636
|
+
element.classList.add(MATH_SELECTED_CLASS);
|
|
7637
|
+
}
|
|
7638
|
+
});
|
|
7639
|
+
};
|
|
7640
|
+
/**
|
|
7641
|
+
* 为容器绑定数学公式选中高亮监听
|
|
7642
|
+
* @param container 容器元素(编辑器或预览区域)
|
|
7643
|
+
*/
|
|
7644
|
+
var bindMathSelectionListener = function (container) {
|
|
7645
|
+
var updateHandler = function () { return updateMathSelection(container); };
|
|
7646
|
+
// 监听选区变化
|
|
7647
|
+
document.addEventListener("selectionchange", updateHandler);
|
|
7648
|
+
// 监听鼠标抬起(处理拖拽选择)
|
|
7649
|
+
container.addEventListener("mouseup", updateHandler);
|
|
7650
|
+
// 监听键盘选择(Shift + 方向键)
|
|
7651
|
+
container.addEventListener("keyup", function (e) {
|
|
7652
|
+
if (e.shiftKey && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
7653
|
+
updateHandler();
|
|
7654
|
+
}
|
|
7655
|
+
});
|
|
7656
|
+
// 返回清理函数
|
|
7657
|
+
return function () {
|
|
7658
|
+
document.removeEventListener("selectionchange", updateHandler);
|
|
7659
|
+
container.removeEventListener("mouseup", updateHandler);
|
|
7660
|
+
};
|
|
7661
|
+
};
|
|
7662
|
+
|
|
7663
|
+
|
|
7400
7664
|
/***/ }),
|
|
7401
7665
|
|
|
7402
7666
|
/***/ 673:
|
|
@@ -7811,8 +8075,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
7811
8075
|
"default": () => (/* binding */ src)
|
|
7812
8076
|
});
|
|
7813
8077
|
|
|
7814
|
-
// EXTERNAL MODULE: ./src/method.ts +
|
|
7815
|
-
var method = __webpack_require__(
|
|
8078
|
+
// EXTERNAL MODULE: ./src/method.ts + 5 modules
|
|
8079
|
+
var method = __webpack_require__(242);
|
|
7816
8080
|
// EXTERNAL MODULE: ./src/ts/constants.ts
|
|
7817
8081
|
var constants = __webpack_require__(145);
|
|
7818
8082
|
// EXTERNAL MODULE: ./src/ts/markdown/getMarkdown.ts
|
|
@@ -15342,6 +15606,8 @@ var Hint = /** @class */ (function () {
|
|
|
15342
15606
|
}());
|
|
15343
15607
|
|
|
15344
15608
|
|
|
15609
|
+
// EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
|
|
15610
|
+
var mathSelection = __webpack_require__(35);
|
|
15345
15611
|
;// CONCATENATED MODULE: ./src/ts/ir/index.ts
|
|
15346
15612
|
|
|
15347
15613
|
|
|
@@ -15355,6 +15621,7 @@ var Hint = /** @class */ (function () {
|
|
|
15355
15621
|
|
|
15356
15622
|
|
|
15357
15623
|
|
|
15624
|
+
|
|
15358
15625
|
var IR = /** @class */ (function () {
|
|
15359
15626
|
function IR(vditor) {
|
|
15360
15627
|
var _a;
|
|
@@ -15375,7 +15642,15 @@ var IR = /** @class */ (function () {
|
|
|
15375
15642
|
dropEvent(vditor, this.element);
|
|
15376
15643
|
copyEvent(vditor, this.element, this.copy);
|
|
15377
15644
|
cutEvent(vditor, this.element, this.copy);
|
|
15645
|
+
// 绑定数学公式选中高亮监听
|
|
15646
|
+
this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.element);
|
|
15378
15647
|
}
|
|
15648
|
+
IR.prototype.unbindListener = function () {
|
|
15649
|
+
// 清理数学公式选中监听
|
|
15650
|
+
if (this.mathSelectionCleanup) {
|
|
15651
|
+
this.mathSelectionCleanup();
|
|
15652
|
+
}
|
|
15653
|
+
};
|
|
15379
15654
|
IR.prototype.copy = function (event, vditor) {
|
|
15380
15655
|
var range = getSelection().getRangeAt(0);
|
|
15381
15656
|
if (range.toString() === "") {
|
|
@@ -15383,8 +15658,30 @@ var IR = /** @class */ (function () {
|
|
|
15383
15658
|
}
|
|
15384
15659
|
event.stopPropagation();
|
|
15385
15660
|
event.preventDefault();
|
|
15661
|
+
// 检查选区是否在数学公式元素内
|
|
15662
|
+
var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
|
|
15663
|
+
var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
|
|
15664
|
+
// 如果选区的起点和终点都在同一个数学公式元素内,复制源码
|
|
15665
|
+
if (mathElement && mathEndElement && mathElement.isSameNode(mathEndElement)) {
|
|
15666
|
+
var mathSource = mathElement.getAttribute("data-math") || range.toString();
|
|
15667
|
+
event.clipboardData.setData("text/plain", mathSource);
|
|
15668
|
+
event.clipboardData.setData("text/html", "");
|
|
15669
|
+
return;
|
|
15670
|
+
}
|
|
15671
|
+
// 处理包含多个公式的混合内容
|
|
15386
15672
|
var tempElement = document.createElement("div");
|
|
15387
15673
|
tempElement.appendChild(range.cloneContents());
|
|
15674
|
+
var mathElements = tempElement.querySelectorAll(".language-math");
|
|
15675
|
+
if (mathElements.length > 0) {
|
|
15676
|
+
// 替换所有数学公式为源码
|
|
15677
|
+
mathElements.forEach(function (mathEl) {
|
|
15678
|
+
var mathSource = mathEl.getAttribute("data-math");
|
|
15679
|
+
if (mathSource) {
|
|
15680
|
+
var textNode = document.createTextNode(mathSource);
|
|
15681
|
+
mathEl.parentNode.replaceChild(textNode, mathEl);
|
|
15682
|
+
}
|
|
15683
|
+
});
|
|
15684
|
+
}
|
|
15388
15685
|
event.clipboardData.setData("text/plain", vditor.lute.VditorIRDOM2Md(tempElement.innerHTML).trim());
|
|
15389
15686
|
event.clipboardData.setData("text/html", "");
|
|
15390
15687
|
};
|
|
@@ -15668,6 +15965,7 @@ var selectionRender = __webpack_require__(616);
|
|
|
15668
15965
|
|
|
15669
15966
|
|
|
15670
15967
|
|
|
15968
|
+
|
|
15671
15969
|
var Preview = /** @class */ (function () {
|
|
15672
15970
|
/**
|
|
15673
15971
|
* 构造预览区域容器,注册复制与点击事件。
|
|
@@ -15728,7 +16026,15 @@ var Preview = /** @class */ (function () {
|
|
|
15728
16026
|
}
|
|
15729
16027
|
});
|
|
15730
16028
|
this.element.appendChild(this.previewElement);
|
|
16029
|
+
// 绑定数学公式选中高亮监听
|
|
16030
|
+
this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.previewElement);
|
|
15731
16031
|
}
|
|
16032
|
+
Preview.prototype.unbindListener = function () {
|
|
16033
|
+
// 清理数学公式选中监听
|
|
16034
|
+
if (this.mathSelectionCleanup) {
|
|
16035
|
+
this.mathSelectionCleanup();
|
|
16036
|
+
}
|
|
16037
|
+
};
|
|
15732
16038
|
/**
|
|
15733
16039
|
* 渲染预览内容。
|
|
15734
16040
|
* - 优先使用远程接口(options.preview.url);失败则使用 Lute 本地渲染。
|
|
@@ -15944,6 +16250,7 @@ var Resize = /** @class */ (function () {
|
|
|
15944
16250
|
|
|
15945
16251
|
|
|
15946
16252
|
|
|
16253
|
+
|
|
15947
16254
|
var Editor = /** @class */ (function () {
|
|
15948
16255
|
function Editor(vditor) {
|
|
15949
16256
|
var _a;
|
|
@@ -15964,7 +16271,15 @@ var Editor = /** @class */ (function () {
|
|
|
15964
16271
|
dropEvent(vditor, this.element);
|
|
15965
16272
|
copyEvent(vditor, this.element, this.copy);
|
|
15966
16273
|
cutEvent(vditor, this.element, this.copy);
|
|
16274
|
+
// 绑定数学公式选中高亮监听
|
|
16275
|
+
this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.element);
|
|
15967
16276
|
}
|
|
16277
|
+
Editor.prototype.unbindListener = function () {
|
|
16278
|
+
// 清理数学公式选中监听
|
|
16279
|
+
if (this.mathSelectionCleanup) {
|
|
16280
|
+
this.mathSelectionCleanup();
|
|
16281
|
+
}
|
|
16282
|
+
};
|
|
15968
16283
|
Editor.prototype.copy = function (event, vditor) {
|
|
15969
16284
|
event.stopPropagation();
|
|
15970
16285
|
event.preventDefault();
|
|
@@ -17850,6 +18165,7 @@ var Options = /** @class */ (function () {
|
|
|
17850
18165
|
type: "markdown",
|
|
17851
18166
|
},
|
|
17852
18167
|
customRenders: [],
|
|
18168
|
+
customComponents: {},
|
|
17853
18169
|
debugger: false,
|
|
17854
18170
|
fullscreen: {
|
|
17855
18171
|
index: 90,
|
|
@@ -18320,6 +18636,7 @@ var wysiwyg_generator = (undefined && undefined.__generator) || function (thisAr
|
|
|
18320
18636
|
|
|
18321
18637
|
|
|
18322
18638
|
|
|
18639
|
+
|
|
18323
18640
|
var WYSIWYG = /** @class */ (function () {
|
|
18324
18641
|
function WYSIWYG(vditor) {
|
|
18325
18642
|
var _this = this;
|
|
@@ -18517,6 +18834,8 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18517
18834
|
};
|
|
18518
18835
|
}
|
|
18519
18836
|
}
|
|
18837
|
+
// 绑定数学公式选中高亮监听
|
|
18838
|
+
this.mathSelectionCleanup = (0,mathSelection/* bindMathSelectionListener */.I)(this.element);
|
|
18520
18839
|
}
|
|
18521
18840
|
WYSIWYG.prototype.getComments = function (vditor, getData) {
|
|
18522
18841
|
var _this = this;
|
|
@@ -18677,11 +18996,15 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18677
18996
|
};
|
|
18678
18997
|
WYSIWYG.prototype.unbindListener = function () {
|
|
18679
18998
|
window.removeEventListener("scroll", this.scrollListener);
|
|
18999
|
+
// 清理数学公式选中监听
|
|
19000
|
+
if (this.mathSelectionCleanup) {
|
|
19001
|
+
this.mathSelectionCleanup();
|
|
19002
|
+
}
|
|
18680
19003
|
};
|
|
18681
19004
|
/**
|
|
18682
19005
|
* 复制事件处理
|
|
18683
19006
|
* - 代码块与链接:按原有规则格式化复制
|
|
18684
|
-
* -
|
|
19007
|
+
* - 数学公式选区:复制公式源码(与 sv 模式一致)
|
|
18685
19008
|
* - 其他内容:转换为 Markdown 文本复制
|
|
18686
19009
|
*/
|
|
18687
19010
|
WYSIWYG.prototype.copy = function (event, vditor) {
|
|
@@ -18718,24 +19041,32 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18718
19041
|
event.clipboardData.setData("text/html", "");
|
|
18719
19042
|
return;
|
|
18720
19043
|
}
|
|
18721
|
-
//
|
|
18722
|
-
|
|
18723
|
-
var
|
|
18724
|
-
var
|
|
18725
|
-
|
|
18726
|
-
|
|
18727
|
-
|
|
18728
|
-
|
|
18729
|
-
endPreview &&
|
|
18730
|
-
startPreview.isSameNode(endPreview) &&
|
|
18731
|
-
isMathPreview(startPreview)) {
|
|
18732
|
-
event.clipboardData.setData("text/plain", range.toString());
|
|
19044
|
+
// 数学公式选区:复制公式源码
|
|
19045
|
+
// 检查选区是否在数学公式元素内
|
|
19046
|
+
var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
|
|
19047
|
+
var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
|
|
19048
|
+
// 如果选区的起点和终点都在同一个数学公式元素内
|
|
19049
|
+
if (mathElement && mathEndElement && mathElement.isSameNode(mathEndElement)) {
|
|
19050
|
+
var mathSource = mathElement.getAttribute("data-math") || range.toString();
|
|
19051
|
+
event.clipboardData.setData("text/plain", mathSource);
|
|
18733
19052
|
event.clipboardData.setData("text/html", "");
|
|
18734
19053
|
return;
|
|
18735
19054
|
}
|
|
18736
|
-
//
|
|
19055
|
+
// 处理包含多个公式的混合内容
|
|
18737
19056
|
var tempElement = document.createElement("div");
|
|
18738
19057
|
tempElement.appendChild(range.cloneContents());
|
|
19058
|
+
var mathElements = tempElement.querySelectorAll(".language-math");
|
|
19059
|
+
if (mathElements.length > 0) {
|
|
19060
|
+
// 替换所有数学公式为源码
|
|
19061
|
+
mathElements.forEach(function (mathEl) {
|
|
19062
|
+
var mathSource = mathEl.getAttribute("data-math");
|
|
19063
|
+
if (mathSource) {
|
|
19064
|
+
var textNode = document.createTextNode(mathSource);
|
|
19065
|
+
mathEl.parentNode.replaceChild(textNode, mathEl);
|
|
19066
|
+
}
|
|
19067
|
+
});
|
|
19068
|
+
}
|
|
19069
|
+
// 默认:转换为 Markdown 文本
|
|
18739
19070
|
event.clipboardData.setData("text/plain", vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim());
|
|
18740
19071
|
event.clipboardData.setData("text/html", tempElement.innerHTML);
|
|
18741
19072
|
};
|
|
@@ -18766,20 +19097,28 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18766
19097
|
html: "",
|
|
18767
19098
|
};
|
|
18768
19099
|
}
|
|
18769
|
-
|
|
18770
|
-
var
|
|
18771
|
-
var
|
|
18772
|
-
|
|
18773
|
-
|
|
18774
|
-
|
|
18775
|
-
|
|
18776
|
-
endPreview &&
|
|
18777
|
-
startPreview.isSameNode(endPreview) &&
|
|
18778
|
-
isMathPreview(startPreview)) {
|
|
18779
|
-
return { plainText: range.toString(), html: "" };
|
|
19100
|
+
// 检查选区是否在数学公式元素内
|
|
19101
|
+
var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
|
|
19102
|
+
var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
|
|
19103
|
+
// 如果选区的起点和终点都在同一个数学公式元素内
|
|
19104
|
+
if (mathElement && mathEndElement && mathElement.isSameNode(mathEndElement)) {
|
|
19105
|
+
var mathSource = mathElement.getAttribute("data-math") || range.toString();
|
|
19106
|
+
return { plainText: mathSource, html: "" };
|
|
18780
19107
|
}
|
|
19108
|
+
// 处理包含多个公式的混合内容
|
|
18781
19109
|
var tempElement = document.createElement("div");
|
|
18782
19110
|
tempElement.appendChild(range.cloneContents());
|
|
19111
|
+
var mathElements = tempElement.querySelectorAll(".language-math");
|
|
19112
|
+
if (mathElements.length > 0) {
|
|
19113
|
+
// 替换所有数学公式为源码
|
|
19114
|
+
mathElements.forEach(function (mathEl) {
|
|
19115
|
+
var mathSource = mathEl.getAttribute("data-math");
|
|
19116
|
+
if (mathSource) {
|
|
19117
|
+
var textNode = document.createTextNode(mathSource);
|
|
19118
|
+
mathEl.parentNode.replaceChild(textNode, mathEl);
|
|
19119
|
+
}
|
|
19120
|
+
});
|
|
19121
|
+
}
|
|
18783
19122
|
return {
|
|
18784
19123
|
plainText: vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim(),
|
|
18785
19124
|
html: tempElement.innerHTML,
|