@8btc/mditor 0.0.17 → 0.0.19
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 +2 -2
- package/dist/index.js +96 -64
- package/dist/index.min.js +1 -1
- package/dist/method.js +25 -3
- package/dist/method.min.js +1 -1
- package/dist/ts/markdown/previewRender.d.ts +8 -0
- package/dist/ts/wysiwyg/index.d.ts +1 -0
- package/dist/types/index.d.ts +21 -9
- package/package.json +1 -1
- package/src/index.ts +8 -1
- package/src/ts/markdown/previewRender.ts +21 -0
- package/src/ts/preview/index.ts +4 -1
- package/src/ts/wysiwyg/index.ts +81 -74
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.19 - 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.
|
|
28
|
+
* Vditor v0.0.19 - 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.
|
|
2
|
+
* Vditor v0.0.19 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -2561,6 +2561,9 @@ var mergeOptions = function (options) {
|
|
|
2561
2561
|
markdown: constants/* Constants.MARKDOWN_OPTIONS */.g.MARKDOWN_OPTIONS,
|
|
2562
2562
|
math: constants/* Constants.MATH_OPTIONS */.g.MATH_OPTIONS,
|
|
2563
2563
|
mode: "light",
|
|
2564
|
+
link: {
|
|
2565
|
+
isOpen: true,
|
|
2566
|
+
},
|
|
2564
2567
|
speech: {
|
|
2565
2568
|
enable: false,
|
|
2566
2569
|
},
|
|
@@ -2620,6 +2623,14 @@ var md2html = function (mdText, options) {
|
|
|
2620
2623
|
return lute.Md2HTML(mdText);
|
|
2621
2624
|
});
|
|
2622
2625
|
};
|
|
2626
|
+
/**
|
|
2627
|
+
* 预览区域渲染入口
|
|
2628
|
+
* - 负责将 Markdown 转为 HTML 并对各类增强特性进行初始化
|
|
2629
|
+
* - 支持目录点击定位与链接点击行为配置(link.click / link.isOpen)
|
|
2630
|
+
* @param previewElement 预览容器元素
|
|
2631
|
+
* @param markdown Markdown 文本内容
|
|
2632
|
+
* @param options 预览配置项,支持 link 点击行为自定义
|
|
2633
|
+
*/
|
|
2623
2634
|
var previewRender = function (previewElement, markdown, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2624
2635
|
var mergedOptions, html, i18nScriptPrefix, i18nScriptID_1;
|
|
2625
2636
|
return __generator(this, function (_a) {
|
|
@@ -2711,6 +2722,7 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2711
2722
|
lazyLoadImageRender(previewElement);
|
|
2712
2723
|
}
|
|
2713
2724
|
previewElement.addEventListener("click", function (event) {
|
|
2725
|
+
var _a, _b;
|
|
2714
2726
|
var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
|
|
2715
2727
|
if (spanElement &&
|
|
2716
2728
|
(0,hasClosest/* hasClosestByClassName */.fb)(spanElement, "vditor-toc")) {
|
|
@@ -2720,6 +2732,16 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2720
2732
|
}
|
|
2721
2733
|
return;
|
|
2722
2734
|
}
|
|
2735
|
+
if (event.target.tagName === "A") {
|
|
2736
|
+
if ((_a = mergedOptions.link) === null || _a === void 0 ? void 0 : _a.click) {
|
|
2737
|
+
mergedOptions.link.click(event.target);
|
|
2738
|
+
}
|
|
2739
|
+
else if ((_b = mergedOptions.link) === null || _b === void 0 ? void 0 : _b.isOpen) {
|
|
2740
|
+
window.open(event.target.getAttribute("href"));
|
|
2741
|
+
}
|
|
2742
|
+
event.preventDefault();
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2723
2745
|
});
|
|
2724
2746
|
return [2 /*return*/];
|
|
2725
2747
|
}
|
|
@@ -2844,7 +2866,7 @@ var Vditor = /** @class */ (function () {
|
|
|
2844
2866
|
/* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
|
|
2845
2867
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
2846
2868
|
/* harmony export */ });
|
|
2847
|
-
var _VDITOR_VERSION = "0.0.
|
|
2869
|
+
var _VDITOR_VERSION = "0.0.19";
|
|
2848
2870
|
|
|
2849
2871
|
var Constants = /** @class */ (function () {
|
|
2850
2872
|
function Constants() {
|
|
@@ -3146,7 +3168,7 @@ var Constants = /** @class */ (function () {
|
|
|
3146
3168
|
"c#",
|
|
3147
3169
|
"bat",
|
|
3148
3170
|
];
|
|
3149
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
3171
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.19");
|
|
3150
3172
|
Constants.MARKDOWN_OPTIONS = {
|
|
3151
3173
|
autoSpace: false,
|
|
3152
3174
|
gfmAutoLink: true,
|
|
@@ -18301,7 +18323,7 @@ var wysiwyg_generator = (undefined && undefined.__generator) || function (thisAr
|
|
|
18301
18323
|
var WYSIWYG = /** @class */ (function () {
|
|
18302
18324
|
function WYSIWYG(vditor) {
|
|
18303
18325
|
var _this = this;
|
|
18304
|
-
var _a;
|
|
18326
|
+
var _a, _b, _c, _d, _e, _f;
|
|
18305
18327
|
this.composingLock = false;
|
|
18306
18328
|
this.commentIds = [];
|
|
18307
18329
|
this.vditor = vditor;
|
|
@@ -18310,7 +18332,15 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18310
18332
|
if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
|
|
18311
18333
|
divElement.classList.add("vditor--linenumber");
|
|
18312
18334
|
}
|
|
18313
|
-
|
|
18335
|
+
// 构建选择浮窗的操作按钮HTML
|
|
18336
|
+
var aiButtonHtml = ((_b = vditor.options.ai) === null || _b === void 0 ? void 0 : _b.enable)
|
|
18337
|
+
? '<button type="button" data-action="ai" aria-label="AI编辑" class="vditor-selection-popover__btn">✨ AI编辑</button>'
|
|
18338
|
+
: '';
|
|
18339
|
+
// 构建AI输入区域HTML
|
|
18340
|
+
var aiInputHtml = ((_c = vditor.options.ai) === null || _c === void 0 ? void 0 : _c.enable)
|
|
18341
|
+
? "<div class=\"vditor-selection-popover__input\">\n <textarea placeholder=\"\u8BF7\u8F93\u5165\u60A8\u60F3\u4FEE\u6539\u7684\u5185\u5BB9\"></textarea>\n <button class=\"vditor-selection-popover__send\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-sparkles-icon lucide-sparkles\"><path d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z\"/><path d=\"M20 2v4\"/><path d=\"M22 4h-4\"/><circle cx=\"4\" cy=\"20\" r=\"2\"/></svg>\n </button>\n </div>"
|
|
18342
|
+
: '';
|
|
18343
|
+
divElement.innerHTML = "<pre class=\"vditor-reset\" placeholder=\"".concat(vditor.options.placeholder, "\"\n contenteditable=\"true\" spellcheck=\"false\"></pre>\n<div class=\"vditor-panel vditor-panel--none\"></div>\n<div class=\"vditor-selection-popover\">\n <div class=\"vditor-selection-popover__actions\">\n ").concat(aiButtonHtml, "\n <button type=\"button\" data-action=\"cut\" aria-label=\"\u526A\u5207\" class=\"vditor-selection-popover__btn\">\u526A\u5207</button>\n <button type=\"button\" data-action=\"copy\" aria-label=\"\u590D\u5236\" class=\"vditor-selection-popover__btn\">\u590D\u5236</button>\n </div>\n ").concat(aiInputHtml, "\n</div>");
|
|
18314
18344
|
this.element = divElement.firstElementChild;
|
|
18315
18345
|
this.popover = divElement.firstElementChild
|
|
18316
18346
|
.nextElementSibling;
|
|
@@ -18318,13 +18348,14 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18318
18348
|
this.popoverInput = this.selectPopover.querySelector("textarea");
|
|
18319
18349
|
this.popoverSendBtn = this.selectPopover.querySelector(".vditor-selection-popover__send");
|
|
18320
18350
|
this.bindEvent(vditor);
|
|
18321
|
-
//
|
|
18322
|
-
if (this.popoverSendBtn) {
|
|
18351
|
+
// 绑定发送按钮事件(仅在AI启用时)
|
|
18352
|
+
if (this.popoverSendBtn && ((_d = vditor.options.ai) === null || _d === void 0 ? void 0 : _d.enable)) {
|
|
18323
18353
|
this.popoverSendBtn.setAttribute("disabled", "disabled");
|
|
18324
18354
|
this.popoverSendBtn.onclick = function (event) {
|
|
18355
|
+
var _a;
|
|
18325
18356
|
event.stopPropagation();
|
|
18326
|
-
if (vditor.options.ai) {
|
|
18327
|
-
vditor.options.ai({
|
|
18357
|
+
if ((_a = vditor.options.ai) === null || _a === void 0 ? void 0 : _a.callback) {
|
|
18358
|
+
vditor.options.ai.callback({
|
|
18328
18359
|
value: _this.popoverInput.value,
|
|
18329
18360
|
content: _this.selectionContent,
|
|
18330
18361
|
lines: _this.selectionLines,
|
|
@@ -18332,30 +18363,30 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18332
18363
|
}
|
|
18333
18364
|
_this.hideSelectionPopover();
|
|
18334
18365
|
};
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
|
|
18341
|
-
|
|
18342
|
-
|
|
18366
|
+
}
|
|
18367
|
+
// 阻止点击 popover 内任何区域时导致编辑器失去焦点
|
|
18368
|
+
// 但不影响 textarea 获取焦点和按钮点击
|
|
18369
|
+
this.selectPopover.addEventListener("mousedown", function (event) {
|
|
18370
|
+
var target = event.target;
|
|
18371
|
+
// 如果点击的是 textarea 或 button,允许默认行为
|
|
18372
|
+
if (target.tagName === "TEXTAREA" ||
|
|
18373
|
+
target.tagName === "BUTTON") {
|
|
18374
|
+
return;
|
|
18375
|
+
}
|
|
18376
|
+
// 其他情况阻止默认行为,防止编辑器失去焦点
|
|
18377
|
+
event.preventDefault();
|
|
18378
|
+
event.stopPropagation();
|
|
18379
|
+
});
|
|
18380
|
+
// 输入验证(仅在AI启用时)
|
|
18381
|
+
if (this.popoverInput && ((_e = vditor.options.ai) === null || _e === void 0 ? void 0 : _e.enable)) {
|
|
18382
|
+
this.popoverInput.addEventListener("input", function () {
|
|
18383
|
+
if (_this.popoverInput.value.trim().length > 0) {
|
|
18384
|
+
_this.popoverSendBtn.removeAttribute("disabled");
|
|
18385
|
+
}
|
|
18386
|
+
else {
|
|
18387
|
+
_this.popoverSendBtn.setAttribute("disabled", "disabled");
|
|
18343
18388
|
}
|
|
18344
|
-
// 其他情况阻止默认行为,防止编辑器失去焦点
|
|
18345
|
-
event.preventDefault();
|
|
18346
|
-
event.stopPropagation();
|
|
18347
18389
|
});
|
|
18348
|
-
// 输入验证
|
|
18349
|
-
if (this.popoverInput) {
|
|
18350
|
-
this.popoverInput.addEventListener("input", function () {
|
|
18351
|
-
if (_this.popoverInput.value.trim().length > 0) {
|
|
18352
|
-
_this.popoverSendBtn.removeAttribute("disabled");
|
|
18353
|
-
}
|
|
18354
|
-
else {
|
|
18355
|
-
_this.popoverSendBtn.setAttribute("disabled", "disabled");
|
|
18356
|
-
}
|
|
18357
|
-
});
|
|
18358
|
-
}
|
|
18359
18390
|
}
|
|
18360
18391
|
focusEvent(vditor, this.element);
|
|
18361
18392
|
dblclickEvent(vditor, this.element);
|
|
@@ -18365,38 +18396,28 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18365
18396
|
dropEvent(vditor, this.element);
|
|
18366
18397
|
copyEvent(vditor, this.element, this.copy);
|
|
18367
18398
|
cutEvent(vditor, this.element, this.copy);
|
|
18368
|
-
//
|
|
18369
|
-
|
|
18370
|
-
|
|
18371
|
-
|
|
18372
|
-
|
|
18373
|
-
|
|
18374
|
-
|
|
18375
|
-
|
|
18376
|
-
|
|
18377
|
-
|
|
18378
|
-
|
|
18379
|
-
|
|
18380
|
-
|
|
18381
|
-
|
|
18382
|
-
|
|
18383
|
-
|
|
18384
|
-
|
|
18385
|
-
|
|
18386
|
-
|
|
18387
|
-
|
|
18388
|
-
|
|
18389
|
-
}
|
|
18390
|
-
}
|
|
18391
|
-
var cutBtn = this.selectPopover.querySelector('[data-action="cut"]');
|
|
18392
|
-
if (cutBtn) {
|
|
18393
|
-
/**
|
|
18394
|
-
* 剪切按钮点击处理
|
|
18395
|
-
* - 将选区复制到剪贴板后删除,并接入撤销栈
|
|
18396
|
-
*/
|
|
18397
|
-
cutBtn.onclick = function () {
|
|
18398
|
-
_this.cutSelection(vditor);
|
|
18399
|
-
};
|
|
18399
|
+
// 选择浮窗按钮事件绑定(仅在AI启用时)
|
|
18400
|
+
if ((_f = vditor.options.ai) === null || _f === void 0 ? void 0 : _f.enable) {
|
|
18401
|
+
var copyBtn = this.selectPopover.querySelector('[data-action="copy"]');
|
|
18402
|
+
if (copyBtn) {
|
|
18403
|
+
/**
|
|
18404
|
+
* 复制按钮点击处理
|
|
18405
|
+
* - 优先使用 Clipboard API;降级为 execCommand('copy')
|
|
18406
|
+
*/
|
|
18407
|
+
copyBtn.onclick = function () {
|
|
18408
|
+
_this.copySelection(vditor);
|
|
18409
|
+
};
|
|
18410
|
+
}
|
|
18411
|
+
var cutBtn = this.selectPopover.querySelector('[data-action="cut"]');
|
|
18412
|
+
if (cutBtn) {
|
|
18413
|
+
/**
|
|
18414
|
+
* 剪切按钮点击处理
|
|
18415
|
+
* - 将选区复制到剪贴板后删除,并接入撤销栈
|
|
18416
|
+
*/
|
|
18417
|
+
cutBtn.onclick = function () {
|
|
18418
|
+
_this.cutSelection(vditor);
|
|
18419
|
+
};
|
|
18420
|
+
}
|
|
18400
18421
|
}
|
|
18401
18422
|
// 评论按钮仅在启用时注册(避免选择浮窗结构变化导致报错)
|
|
18402
18423
|
if (vditor.options.comment.enable) {
|
|
@@ -18540,8 +18561,14 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18540
18561
|
/**
|
|
18541
18562
|
* 显示选择浮窗(定位于选区右上)
|
|
18542
18563
|
* - 当未选中文本或选区不在编辑器内时不显示
|
|
18564
|
+
* - 当AI功能未启用时不显示
|
|
18543
18565
|
*/
|
|
18544
18566
|
WYSIWYG.prototype.showSelectionPopover = function () {
|
|
18567
|
+
var _a;
|
|
18568
|
+
// 如果AI功能未启用,不显示选择浮窗
|
|
18569
|
+
if (!((_a = this.vditor.options.ai) === null || _a === void 0 ? void 0 : _a.enable)) {
|
|
18570
|
+
return;
|
|
18571
|
+
}
|
|
18545
18572
|
if (getSelection().rangeCount === 0) {
|
|
18546
18573
|
return;
|
|
18547
18574
|
}
|
|
@@ -19431,6 +19458,11 @@ var Vditor = /** @class */ (function (_super) {
|
|
|
19431
19458
|
if (!Array.isArray(numbers)) {
|
|
19432
19459
|
return;
|
|
19433
19460
|
}
|
|
19461
|
+
// 当 highlightTimer 为 0 时,不处理高亮逻辑
|
|
19462
|
+
var highlightTimer = (_a = this.vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.highlightTimer;
|
|
19463
|
+
if (highlightTimer === 0) {
|
|
19464
|
+
return;
|
|
19465
|
+
}
|
|
19434
19466
|
var valid = numbers
|
|
19435
19467
|
.filter(function (n) { return typeof n === "number" && isFinite(n); })
|
|
19436
19468
|
.map(function (n) { return String(Math.floor(n)); });
|
|
@@ -19445,7 +19477,7 @@ var Vditor = /** @class */ (function (_super) {
|
|
|
19445
19477
|
if (nodeList.length === 0) {
|
|
19446
19478
|
return;
|
|
19447
19479
|
}
|
|
19448
|
-
var duration = Math.max(0, Number(
|
|
19480
|
+
var duration = Math.max(0, Number(highlightTimer) || 1500);
|
|
19449
19481
|
var apply = function () {
|
|
19450
19482
|
nodeList.forEach(function (el) {
|
|
19451
19483
|
var old = lineHighlightTimers.get(el);
|