vditor 4.0.2-alpha.10 → 4.0.2-alpha.12
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 +1 -1
- package/dist/index.js +94 -34
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +94 -34
- package/dist/method.js +3 -3
- package/dist/method.min.js +1 -1
- package/dist/method.mjs +3 -3
- package/dist/ts/find/index.d.ts +3 -1
- package/dist/ts/util/fixBrowserBehavior.d.ts +1 -1
- package/dist/ts/util/pasteLink.d.ts +1 -0
- package/package.json +1 -1
- package/src/ts/find/index.ts +26 -15
- package/src/ts/ir/processKeydown.ts +2 -2
- package/src/ts/util/fixBrowserBehavior.ts +29 -10
- package/src/ts/util/pasteLink.ts +35 -6
- package/src/ts/wysiwyg/processKeydown.ts +2 -2
package/dist/index.css
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v4.0.2-alpha.
|
|
2
|
+
* Vditor v4.0.2-alpha.12 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -4799,7 +4799,7 @@ var Vditor = /** @class */ (function () {
|
|
|
4799
4799
|
/* harmony export */ Y: () => (/* binding */ Constants),
|
|
4800
4800
|
/* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
|
|
4801
4801
|
/* harmony export */ });
|
|
4802
|
-
var _VDITOR_VERSION = "4.0.2-alpha.
|
|
4802
|
+
var _VDITOR_VERSION = "4.0.2-alpha.12";
|
|
4803
4803
|
|
|
4804
4804
|
var Constants = /** @class */ (function () {
|
|
4805
4805
|
function Constants() {
|
|
@@ -4847,7 +4847,7 @@ var Constants = /** @class */ (function () {
|
|
|
4847
4847
|
// 别名
|
|
4848
4848
|
"js", "ts", "html", "toml", "c#", "bat"
|
|
4849
4849
|
];
|
|
4850
|
-
Constants.CDN = "https://unpkg.com/vditor@".concat("4.0.2-alpha.
|
|
4850
|
+
Constants.CDN = "https://unpkg.com/vditor@".concat("4.0.2-alpha.12");
|
|
4851
4851
|
Constants.MARKDOWN_OPTIONS = {
|
|
4852
4852
|
autoSpace: false,
|
|
4853
4853
|
callout: true,
|
|
@@ -7324,7 +7324,7 @@ var processKeydown = function (vditor, event) {
|
|
|
7324
7324
|
}
|
|
7325
7325
|
var range = (0,selection/* getEditorRange */.RN)(vditor);
|
|
7326
7326
|
var startContainer = range.startContainer;
|
|
7327
|
-
if (
|
|
7327
|
+
if (deleteEmptyHeading(event, vditor, range)) {
|
|
7328
7328
|
return true;
|
|
7329
7329
|
}
|
|
7330
7330
|
if (!fixGSKeyBackspace(event, vditor, startContainer)) {
|
|
@@ -8093,7 +8093,7 @@ var wysiwyg_processKeydown_processKeydown = function (vditor, event) {
|
|
|
8093
8093
|
}
|
|
8094
8094
|
var range = (0,selection/* getEditorRange */.RN)(vditor);
|
|
8095
8095
|
var startContainer = range.startContainer;
|
|
8096
|
-
if (
|
|
8096
|
+
if (deleteEmptyHeading(event, vditor, range)) {
|
|
8097
8097
|
return true;
|
|
8098
8098
|
}
|
|
8099
8099
|
// Android 输入法的编辑面板无法在 contenteditable 中正确处理方向键和 End
|
|
@@ -10903,6 +10903,35 @@ var containsPlainText = function (node, marker) {
|
|
|
10903
10903
|
return (node.Type === "NodeText" && !!((_a = node.Data) === null || _a === void 0 ? void 0 : _a.includes(marker))) ||
|
|
10904
10904
|
!!((_b = node.Children) === null || _b === void 0 ? void 0 : _b.some(function (child) { return containsPlainText(child, marker); }));
|
|
10905
10905
|
};
|
|
10906
|
+
// 百分号编码语法字符和实体中的非保留字符,保持查询参数分隔符和 Markdown 往返语义。
|
|
10907
|
+
var escapeDestination = function (text) {
|
|
10908
|
+
var encode = function (character) { return "%" + character.charCodeAt(0).toString(16).toUpperCase(); };
|
|
10909
|
+
return text.replace(/[\\()<>|]/g, encode).replace(/&(?:#[xX]?)?([a-zA-Z0-9])(?=[a-zA-Z0-9]*;)/g, function (match, character) { return match.slice(0, -1) + encode(character); });
|
|
10910
|
+
};
|
|
10911
|
+
var pasteUnfinishedIRLinkDestination = function (vditor, text) {
|
|
10912
|
+
if (vditor.currentMode !== "ir" || !vditor.lute.IsValidLinkDest(text)) {
|
|
10913
|
+
return false;
|
|
10914
|
+
}
|
|
10915
|
+
var range = (0,selection/* getEditorRange */.RN)(vditor);
|
|
10916
|
+
var block = (0,hasClosest/* hasClosestBlock */.pt)(range.startContainer);
|
|
10917
|
+
if (!block || !block.contains(range.endContainer) ||
|
|
10918
|
+
(0,hasClosest/* hasClosestByAttribute */.Th)(range.startContainer, "data-type", "a") ||
|
|
10919
|
+
(0,hasClosest/* hasClosestByMatchTag */._Y)(range.startContainer, "CODE")) {
|
|
10920
|
+
return false;
|
|
10921
|
+
}
|
|
10922
|
+
var prefix = range.cloneRange();
|
|
10923
|
+
prefix.selectNodeContents(block);
|
|
10924
|
+
prefix.setEnd(range.startContainer, range.startOffset);
|
|
10925
|
+
if (!/(?:^|[^\\])!?\[(?:\\.|[^[\]\\\r\n])+\]\(\s*$/.test(prefix.toString())) {
|
|
10926
|
+
return false;
|
|
10927
|
+
}
|
|
10928
|
+
var destination = document.createTextNode(escapeDestination(text));
|
|
10929
|
+
range.deleteContents();
|
|
10930
|
+
range.insertNode(destination);
|
|
10931
|
+
range.setStartAfter(destination);
|
|
10932
|
+
range.collapse(true);
|
|
10933
|
+
return true;
|
|
10934
|
+
};
|
|
10906
10935
|
var getPastedLink = function (vditor, text) {
|
|
10907
10936
|
if (!vditor.lute.IsValidLinkDest(text)) {
|
|
10908
10937
|
return text;
|
|
@@ -10930,9 +10959,7 @@ var getPastedLink = function (vditor, text) {
|
|
|
10930
10959
|
selectedText = range.toString();
|
|
10931
10960
|
}
|
|
10932
10961
|
var title = (selectedText || text).replace(/[\\`*_[\]!~^=$&<>|:]/g, "\\$&");
|
|
10933
|
-
var
|
|
10934
|
-
// 百分号编码语法字符和实体中的非保留字符,保持查询参数分隔符和 Markdown 往返语义。
|
|
10935
|
-
var destination = text.replace(/[\\()<>|]/g, encode).replace(/&(?:#[xX]?)?([a-zA-Z0-9])(?=[a-zA-Z0-9]*;)/g, function (match, character) { return match.slice(0, -1) + encode(character); });
|
|
10962
|
+
var destination = escapeDestination(text);
|
|
10936
10963
|
return "[".concat(title, "](").concat(destination, ")");
|
|
10937
10964
|
};
|
|
10938
10965
|
|
|
@@ -11009,22 +11036,37 @@ var fixGSKeyBackspace = function (event, vditor, startContainer) {
|
|
|
11009
11036
|
}
|
|
11010
11037
|
return true;
|
|
11011
11038
|
};
|
|
11012
|
-
var
|
|
11013
|
-
if (event.key !== "Backspace"
|
|
11014
|
-
event.
|
|
11039
|
+
var deleteEmptyHeading = function (event, vditor, range) {
|
|
11040
|
+
if ((event.key !== "Backspace" && (event.key !== "Delete" || range.collapsed)) ||
|
|
11041
|
+
event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || event.defaultPrevented) {
|
|
11015
11042
|
return false;
|
|
11016
11043
|
}
|
|
11017
11044
|
var heading = (0,hasClosestByHeadings/* hasClosestByHeadings */.c)(range.startContainer);
|
|
11018
|
-
if (!heading) {
|
|
11045
|
+
if (!heading || !heading.contains(range.endContainer)) {
|
|
11019
11046
|
return false;
|
|
11020
11047
|
}
|
|
11021
|
-
var
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
if (
|
|
11027
|
-
|
|
11048
|
+
var isEmpty = function (nodes) { return Array.from(nodes).every(function (node) {
|
|
11049
|
+
return (node.nodeType === Node.ELEMENT_NODE && node.getAttribute("data-type") === "heading-marker") ||
|
|
11050
|
+
node.nodeName === "BR" || node.nodeName === "WBR" ||
|
|
11051
|
+
(node.nodeType === Node.TEXT_NODE && node.textContent.split(constants/* Constants */.Y.ZWSP).join("").trim() === "");
|
|
11052
|
+
}); };
|
|
11053
|
+
if (range.collapsed) {
|
|
11054
|
+
if (!isEmpty(heading.childNodes)) {
|
|
11055
|
+
return false;
|
|
11056
|
+
}
|
|
11057
|
+
}
|
|
11058
|
+
else {
|
|
11059
|
+
var remainder = range.cloneRange();
|
|
11060
|
+
remainder.selectNodeContents(heading);
|
|
11061
|
+
remainder.setEnd(range.startContainer, range.startOffset);
|
|
11062
|
+
if (!isEmpty(remainder.cloneContents().childNodes)) {
|
|
11063
|
+
return false;
|
|
11064
|
+
}
|
|
11065
|
+
remainder.selectNodeContents(heading);
|
|
11066
|
+
remainder.setStart(range.endContainer, range.endOffset);
|
|
11067
|
+
if (!isEmpty(remainder.cloneContents().childNodes)) {
|
|
11068
|
+
return false;
|
|
11069
|
+
}
|
|
11028
11070
|
}
|
|
11029
11071
|
var paragraph = heading.ownerDocument.createElement("p");
|
|
11030
11072
|
paragraph.setAttribute("data-block", "0");
|
|
@@ -12588,6 +12630,12 @@ var paste = function (vditor, event, callback) { return fixBrowserBehavior_await
|
|
|
12588
12630
|
case 9: return [3 /*break*/, 11];
|
|
12589
12631
|
case 10:
|
|
12590
12632
|
if (textPlain.trim() !== "" && files.length === 0) {
|
|
12633
|
+
if (pasteUnfinishedIRLinkDestination(vditor, textPlain)) {
|
|
12634
|
+
// 结束括号输入后由即时渲染重新解析整条链接。
|
|
12635
|
+
vditor.wysiwyg.triggerRemoveComment(vditor);
|
|
12636
|
+
execAfterRender(vditor);
|
|
12637
|
+
return [2 /*return*/];
|
|
12638
|
+
}
|
|
12591
12639
|
textPlain = getPastedLink(vditor, textPlain);
|
|
12592
12640
|
if (pasteIntoTable(vditor, "", textPlain)) {
|
|
12593
12641
|
// 单元格填充与普通粘贴共用后续规范化和撤销记录。
|
|
@@ -17391,6 +17439,7 @@ var find_Find = /** @class */ (function () {
|
|
|
17391
17439
|
this.total = 0;
|
|
17392
17440
|
this.composing = false;
|
|
17393
17441
|
this.timer = 0;
|
|
17442
|
+
this.revealPending = false;
|
|
17394
17443
|
this.events = new AbortController();
|
|
17395
17444
|
this.highlightName = "vditor-find-".concat(++instanceCount);
|
|
17396
17445
|
var labels = {
|
|
@@ -17440,16 +17489,16 @@ var find_Find = /** @class */ (function () {
|
|
|
17440
17489
|
var signal = this.events.signal;
|
|
17441
17490
|
this.query.addEventListener("input", function () {
|
|
17442
17491
|
_this.index = 0;
|
|
17443
|
-
_this.schedule();
|
|
17492
|
+
_this.schedule(true);
|
|
17444
17493
|
}, { signal: signal });
|
|
17445
17494
|
this.sensitive.addEventListener("change", function () {
|
|
17446
17495
|
_this.index = 0;
|
|
17447
17496
|
_this.refresh();
|
|
17448
17497
|
}, { signal: signal });
|
|
17449
17498
|
this.element.addEventListener("compositionstart", function () { _this.composing = true; }, { signal: signal });
|
|
17450
|
-
this.element.addEventListener("compositionend", function () {
|
|
17499
|
+
this.element.addEventListener("compositionend", function (event) {
|
|
17451
17500
|
_this.composing = false;
|
|
17452
|
-
_this.schedule();
|
|
17501
|
+
_this.schedule(event.target === _this.query);
|
|
17453
17502
|
}, { signal: signal });
|
|
17454
17503
|
vditor.element.addEventListener("keydown", function (event) {
|
|
17455
17504
|
if (event.isComposing || _this.composing || vditor[vditor.currentMode].composingLock)
|
|
@@ -17503,16 +17552,19 @@ var find_Find = /** @class */ (function () {
|
|
|
17503
17552
|
if (focus === void 0) { focus = false; }
|
|
17504
17553
|
this.element.hidden = true;
|
|
17505
17554
|
window.clearTimeout(this.timer);
|
|
17555
|
+
this.revealPending = false;
|
|
17506
17556
|
this.clearHighlight();
|
|
17507
17557
|
if (focus)
|
|
17508
17558
|
this.vditor[this.vditor.currentMode].element.focus();
|
|
17509
17559
|
};
|
|
17510
|
-
Find.prototype.refresh = function () {
|
|
17560
|
+
Find.prototype.refresh = function (reveal) {
|
|
17511
17561
|
var _this = this;
|
|
17562
|
+
if (reveal === void 0) { reveal = true; }
|
|
17512
17563
|
if (this.element.hidden || this.composing || this.vditor[this.vditor.currentMode].composingLock)
|
|
17513
17564
|
return;
|
|
17514
17565
|
window.clearTimeout(this.timer);
|
|
17515
|
-
|
|
17566
|
+
this.revealPending = false;
|
|
17567
|
+
var result = this.findMatch(this.query.value, { caseSensitive: this.sensitive.checked, index: this.index }, reveal);
|
|
17516
17568
|
this.index = Math.max(0, result.index);
|
|
17517
17569
|
this.total = result.total;
|
|
17518
17570
|
this.count.textContent = "".concat(result.index + 1, "/").concat(result.total);
|
|
@@ -17521,13 +17573,17 @@ var find_Find = /** @class */ (function () {
|
|
|
17521
17573
|
};
|
|
17522
17574
|
Find.prototype.find = function (query, options) {
|
|
17523
17575
|
if (options === void 0) { options = {}; }
|
|
17576
|
+
return this.findMatch(query, options, true);
|
|
17577
|
+
};
|
|
17578
|
+
Find.prototype.findMatch = function (query, options, reveal) {
|
|
17524
17579
|
this.clearHighlight();
|
|
17525
17580
|
var result = findText(this.vditor[this.vditor.currentMode].element, query, !!options.caseSensitive, options.index || 0);
|
|
17526
17581
|
if (result.match && !this.vditor[this.vditor.currentMode].composingLock) {
|
|
17527
17582
|
if (this.vditor.currentMode === "sv") {
|
|
17528
17583
|
var element = this.vditor.sv.element;
|
|
17529
|
-
|
|
17530
|
-
|
|
17584
|
+
if (reveal)
|
|
17585
|
+
element.setSelectionRange(result.match.start, result.match.end);
|
|
17586
|
+
this.highlightSource(result.match, reveal);
|
|
17531
17587
|
}
|
|
17532
17588
|
else {
|
|
17533
17589
|
var range = displayRange(result.match.range);
|
|
@@ -17535,11 +17591,13 @@ var find_Find = /** @class */ (function () {
|
|
|
17535
17591
|
var HighlightClass = window.Highlight;
|
|
17536
17592
|
if ((css === null || css === void 0 ? void 0 : css.highlights) && HighlightClass)
|
|
17537
17593
|
css.highlights.set(this.highlightName, new HighlightClass(range));
|
|
17538
|
-
|
|
17539
|
-
|
|
17540
|
-
|
|
17541
|
-
|
|
17542
|
-
|
|
17594
|
+
if (reveal) {
|
|
17595
|
+
var rect = range.getBoundingClientRect();
|
|
17596
|
+
var element = this.vditor[this.vditor.currentMode].element;
|
|
17597
|
+
var viewport = element.getBoundingClientRect();
|
|
17598
|
+
if (rect.top < viewport.top || rect.bottom > viewport.bottom) {
|
|
17599
|
+
element.scrollTop += rect.top - viewport.top - element.clientHeight / 2;
|
|
17600
|
+
}
|
|
17543
17601
|
}
|
|
17544
17602
|
}
|
|
17545
17603
|
}
|
|
@@ -17616,12 +17674,15 @@ var find_Find = /** @class */ (function () {
|
|
|
17616
17674
|
this.index = this.total ? (this.index + direction + this.total) % this.total : 0;
|
|
17617
17675
|
this.refresh();
|
|
17618
17676
|
};
|
|
17619
|
-
Find.prototype.schedule = function () {
|
|
17677
|
+
Find.prototype.schedule = function (reveal) {
|
|
17620
17678
|
var _this = this;
|
|
17679
|
+
if (reveal === void 0) { reveal = false; }
|
|
17621
17680
|
if (this.element.hidden)
|
|
17622
17681
|
return;
|
|
17682
|
+
// 查询输入和正文更新共用定时器,查询框仍有焦点时才定位待显示的命中。
|
|
17683
|
+
this.revealPending || (this.revealPending = reveal);
|
|
17623
17684
|
window.clearTimeout(this.timer);
|
|
17624
|
-
this.timer = window.setTimeout(function () { return _this.refresh(); }, 120);
|
|
17685
|
+
this.timer = window.setTimeout(function () { return _this.refresh(_this.revealPending && document.activeElement === _this.query); }, 120);
|
|
17625
17686
|
};
|
|
17626
17687
|
Find.prototype.clearHighlight = function () {
|
|
17627
17688
|
var _a, _b, _c;
|
|
@@ -17647,7 +17708,6 @@ var find_Find = /** @class */ (function () {
|
|
|
17647
17708
|
return button;
|
|
17648
17709
|
};
|
|
17649
17710
|
Find.prototype.highlightSource = function (match, reveal) {
|
|
17650
|
-
if (reveal === void 0) { reveal = true; }
|
|
17651
17711
|
var element = this.vditor.sv.element;
|
|
17652
17712
|
this.sourceMatch = match;
|
|
17653
17713
|
if (!this.sourceHighlight) {
|