@8btc/mditor 0.0.24 → 0.0.25
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 +222 -29
- package/dist/index.min.js +1 -1
- package/dist/method.js +122 -4
- package/dist/method.min.js +1 -1
- package/dist/ts/ir/index.d.ts +2 -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/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/previewRender.ts +77 -0
- package/src/ts/preview/index.ts +12 -0
- package/src/ts/sv/index.ts +12 -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/method.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.25 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -45,7 +45,7 @@ return /******/ (() => { // webpackBootstrap
|
|
|
45
45
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
46
46
|
/* harmony export */ });
|
|
47
47
|
/* unused harmony export VDITOR_VERSION */
|
|
48
|
-
var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.
|
|
48
|
+
var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.25"));
|
|
49
49
|
|
|
50
50
|
var Constants = /** @class */ (function () {
|
|
51
51
|
function Constants() {
|
|
@@ -347,7 +347,7 @@ var Constants = /** @class */ (function () {
|
|
|
347
347
|
"c#",
|
|
348
348
|
"bat",
|
|
349
349
|
];
|
|
350
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
350
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.25");
|
|
351
351
|
Constants.MARKDOWN_OPTIONS = {
|
|
352
352
|
autoSpace: false,
|
|
353
353
|
gfmAutoLink: true,
|
|
@@ -4314,7 +4314,8 @@ var getTopList = function (element) {
|
|
|
4314
4314
|
var topUlElement = hasTopClosestByTag(element, "UL");
|
|
4315
4315
|
var topOlElement = hasTopClosestByTag(element, "OL");
|
|
4316
4316
|
var topListElement = topUlElement;
|
|
4317
|
-
if (topOlElement &&
|
|
4317
|
+
if (topOlElement &&
|
|
4318
|
+
(!topUlElement || (topUlElement && topOlElement.contains(topUlElement)))) {
|
|
4318
4319
|
topListElement = topOlElement;
|
|
4319
4320
|
}
|
|
4320
4321
|
return topListElement;
|
|
@@ -4454,6 +4455,65 @@ var hasClosestByHeadings = function (element) {
|
|
|
4454
4455
|
};
|
|
4455
4456
|
|
|
4456
4457
|
|
|
4458
|
+
/***/ }),
|
|
4459
|
+
|
|
4460
|
+
/***/ 35:
|
|
4461
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4462
|
+
|
|
4463
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4464
|
+
/* harmony export */ "I": () => (/* binding */ bindMathSelectionListener)
|
|
4465
|
+
/* harmony export */ });
|
|
4466
|
+
/* unused harmony export updateMathSelection */
|
|
4467
|
+
/**
|
|
4468
|
+
* 数学公式选中高亮工具
|
|
4469
|
+
* 监听选区变化,为选中的数学公式添加高亮样式
|
|
4470
|
+
*/
|
|
4471
|
+
var MATH_SELECTED_CLASS = "vditor-math--selected";
|
|
4472
|
+
/**
|
|
4473
|
+
* 检查并更新数学公式的选中高亮状态
|
|
4474
|
+
* @param container 容器元素(编辑器或预览区域)
|
|
4475
|
+
*/
|
|
4476
|
+
var updateMathSelection = function (container) {
|
|
4477
|
+
var selection = window.getSelection();
|
|
4478
|
+
// 获取所有数学公式元素
|
|
4479
|
+
var mathElements = container.querySelectorAll(".language-math");
|
|
4480
|
+
// 移除所有旧的高亮
|
|
4481
|
+
mathElements.forEach(function (el) { return el.classList.remove(MATH_SELECTED_CLASS); });
|
|
4482
|
+
// 无选中内容则返回
|
|
4483
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
|
|
4484
|
+
return;
|
|
4485
|
+
}
|
|
4486
|
+
// 检测选中的公式节点并添加高亮
|
|
4487
|
+
mathElements.forEach(function (element) {
|
|
4488
|
+
if (selection.containsNode(element, true)) {
|
|
4489
|
+
element.classList.add(MATH_SELECTED_CLASS);
|
|
4490
|
+
}
|
|
4491
|
+
});
|
|
4492
|
+
};
|
|
4493
|
+
/**
|
|
4494
|
+
* 为容器绑定数学公式选中高亮监听
|
|
4495
|
+
* @param container 容器元素(编辑器或预览区域)
|
|
4496
|
+
*/
|
|
4497
|
+
var bindMathSelectionListener = function (container) {
|
|
4498
|
+
var updateHandler = function () { return updateMathSelection(container); };
|
|
4499
|
+
// 监听选区变化
|
|
4500
|
+
document.addEventListener("selectionchange", updateHandler);
|
|
4501
|
+
// 监听鼠标抬起(处理拖拽选择)
|
|
4502
|
+
container.addEventListener("mouseup", updateHandler);
|
|
4503
|
+
// 监听键盘选择(Shift + 方向键)
|
|
4504
|
+
container.addEventListener("keyup", function (e) {
|
|
4505
|
+
if (e.shiftKey && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
4506
|
+
updateHandler();
|
|
4507
|
+
}
|
|
4508
|
+
});
|
|
4509
|
+
// 返回清理函数
|
|
4510
|
+
return function () {
|
|
4511
|
+
document.removeEventListener("selectionchange", updateHandler);
|
|
4512
|
+
container.removeEventListener("mouseup", updateHandler);
|
|
4513
|
+
};
|
|
4514
|
+
};
|
|
4515
|
+
|
|
4516
|
+
|
|
4457
4517
|
/***/ }),
|
|
4458
4518
|
|
|
4459
4519
|
/***/ 673:
|
|
@@ -5074,6 +5134,8 @@ var speechRender = function (element, lang) {
|
|
|
5074
5134
|
|
|
5075
5135
|
// EXTERNAL MODULE: ./src/ts/markdown/selectionRender.ts
|
|
5076
5136
|
var selectionRender = __webpack_require__(616);
|
|
5137
|
+
// EXTERNAL MODULE: ./src/ts/util/mathSelection.ts
|
|
5138
|
+
var mathSelection = __webpack_require__(35);
|
|
5077
5139
|
;// CONCATENATED MODULE: ./src/ts/markdown/previewRender.ts
|
|
5078
5140
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5079
5141
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -5132,6 +5194,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
5132
5194
|
|
|
5133
5195
|
|
|
5134
5196
|
|
|
5197
|
+
|
|
5135
5198
|
|
|
5136
5199
|
|
|
5137
5200
|
var mergeOptions = function (options) {
|
|
@@ -5307,6 +5370,61 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
5307
5370
|
if (mergedOptions.lazyLoadImage) {
|
|
5308
5371
|
lazyLoadImageRender(previewElement);
|
|
5309
5372
|
}
|
|
5373
|
+
// 绑定数学公式选中高亮监听
|
|
5374
|
+
(0,mathSelection/* bindMathSelectionListener */.I)(previewElement);
|
|
5375
|
+
// 绑定复制事件,处理数学公式源码复制
|
|
5376
|
+
previewElement.addEventListener("copy", function (event) {
|
|
5377
|
+
var selection = window.getSelection();
|
|
5378
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
|
|
5379
|
+
return;
|
|
5380
|
+
}
|
|
5381
|
+
var range = selection.getRangeAt(0);
|
|
5382
|
+
// 检查选区是否只包含单个数学公式
|
|
5383
|
+
var mathElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "language-math");
|
|
5384
|
+
var mathEndElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.endContainer, "language-math");
|
|
5385
|
+
// 如果选区的起点和终点都在同一个数学公式元素内,复制源码
|
|
5386
|
+
if (mathElement &&
|
|
5387
|
+
mathEndElement &&
|
|
5388
|
+
mathElement.isSameNode(mathEndElement)) {
|
|
5389
|
+
event.stopPropagation();
|
|
5390
|
+
event.preventDefault();
|
|
5391
|
+
var mathSource = mathElement.getAttribute("data-math") || range.toString();
|
|
5392
|
+
event.clipboardData.setData("text/plain", mathSource);
|
|
5393
|
+
event.clipboardData.setData("text/html", "");
|
|
5394
|
+
return;
|
|
5395
|
+
}
|
|
5396
|
+
// 处理包含多个公式的混合内容
|
|
5397
|
+
var fragment = range.cloneContents();
|
|
5398
|
+
var mathElements = fragment.querySelectorAll(".language-math");
|
|
5399
|
+
if (mathElements.length > 0) {
|
|
5400
|
+
event.stopPropagation();
|
|
5401
|
+
event.preventDefault();
|
|
5402
|
+
// 创建临时容器来处理内容
|
|
5403
|
+
var tempDiv = document.createElement("div");
|
|
5404
|
+
tempDiv.appendChild(fragment);
|
|
5405
|
+
// 替换所有数学公式为源码
|
|
5406
|
+
tempDiv
|
|
5407
|
+
.querySelectorAll(".language-math")
|
|
5408
|
+
.forEach(function (mathEl) {
|
|
5409
|
+
var mathSource = mathEl.getAttribute("data-math");
|
|
5410
|
+
console.log(mathEl.tagName, "mathEl");
|
|
5411
|
+
if (mathSource) {
|
|
5412
|
+
if (mathEl.tagName === "SPAN") {
|
|
5413
|
+
var textNode = document.createTextNode("$".concat(mathSource, "$"));
|
|
5414
|
+
mathEl.parentNode.replaceChild(textNode, mathEl);
|
|
5415
|
+
}
|
|
5416
|
+
else {
|
|
5417
|
+
var textNode = document.createTextNode("$$".concat(mathSource, "$$"));
|
|
5418
|
+
mathEl.parentNode.replaceChild(textNode, mathEl);
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
});
|
|
5422
|
+
// 获取纯文本内容
|
|
5423
|
+
var plainText = tempDiv.textContent || tempDiv.innerText || "";
|
|
5424
|
+
event.clipboardData.setData("text/plain", plainText);
|
|
5425
|
+
event.clipboardData.setData("text/html", "");
|
|
5426
|
+
}
|
|
5427
|
+
});
|
|
5310
5428
|
previewElement.addEventListener("click", function (event) {
|
|
5311
5429
|
var _a, _b;
|
|
5312
5430
|
var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
|