@8btc/mditor 0.0.6 → 0.0.8
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 +6 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1099 -856
- package/dist/index.min.js +1 -1
- package/dist/method.d.ts +4 -0
- package/dist/method.js +527 -3
- package/dist/method.min.js +1 -1
- package/dist/ts/util/attachLineNumbers.d.ts +3 -19
- package/dist/types/index.d.ts +0 -12
- package/package.json +1 -1
- package/src/assets/less/_line-number.less +6 -1
- package/src/index.ts +50 -0
- package/src/method.ts +42 -21
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.7 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -2707,6 +2707,10 @@ var previewRender = function (previewElement, markdown, options) { return __awai
|
|
|
2707
2707
|
var preview_image = __webpack_require__(190);
|
|
2708
2708
|
// EXTERNAL MODULE: ./src/ts/ui/setCodeTheme.ts
|
|
2709
2709
|
var setCodeTheme = __webpack_require__(580);
|
|
2710
|
+
// EXTERNAL MODULE: ./src/ts/markdown/getMarkdown.ts
|
|
2711
|
+
var getMarkdown = __webpack_require__(210);
|
|
2712
|
+
// EXTERNAL MODULE: ./src/ts/util/attachLineNumbers.ts
|
|
2713
|
+
var attachLineNumbers = __webpack_require__(626);
|
|
2710
2714
|
;// CONCATENATED MODULE: ./src/method.ts
|
|
2711
2715
|
|
|
2712
2716
|
|
|
@@ -2726,12 +2730,35 @@ var setCodeTheme = __webpack_require__(580);
|
|
|
2726
2730
|
|
|
2727
2731
|
|
|
2728
2732
|
|
|
2733
|
+
|
|
2734
|
+
|
|
2729
2735
|
|
|
2730
2736
|
|
|
2731
2737
|
|
|
2732
2738
|
var Vditor = /** @class */ (function () {
|
|
2733
2739
|
function Vditor() {
|
|
2734
2740
|
}
|
|
2741
|
+
/**
|
|
2742
|
+
* 外部更新行号:传入实例并根据配置进行同步/节流更新
|
|
2743
|
+
*/
|
|
2744
|
+
Vditor.updateLineNumbers = function (instance, immediate) {
|
|
2745
|
+
var _a, _b;
|
|
2746
|
+
if (immediate === void 0) { immediate = false; }
|
|
2747
|
+
try {
|
|
2748
|
+
var v = (_a = instance === null || instance === void 0 ? void 0 : instance.vditor) !== null && _a !== void 0 ? _a : instance;
|
|
2749
|
+
if (!((_b = v === null || v === void 0 ? void 0 : v.options) === null || _b === void 0 ? void 0 : _b.lineNumber))
|
|
2750
|
+
return;
|
|
2751
|
+
var text = (0,getMarkdown/* getMarkdown */.O)(v);
|
|
2752
|
+
var root = v[v.currentMode].element;
|
|
2753
|
+
if (immediate) {
|
|
2754
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(root, text);
|
|
2755
|
+
}
|
|
2756
|
+
else {
|
|
2757
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(root, text);
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
catch (_c) { }
|
|
2761
|
+
};
|
|
2735
2762
|
/** 点击图片放大 */
|
|
2736
2763
|
Vditor.adapterRender = adapterRender;
|
|
2737
2764
|
/** 点击图片放大 */
|
|
@@ -2791,7 +2818,7 @@ var Vditor = /** @class */ (function () {
|
|
|
2791
2818
|
/* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
|
|
2792
2819
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
2793
2820
|
/* harmony export */ });
|
|
2794
|
-
var _VDITOR_VERSION = "0.0.
|
|
2821
|
+
var _VDITOR_VERSION = "0.0.7";
|
|
2795
2822
|
|
|
2796
2823
|
var Constants = /** @class */ (function () {
|
|
2797
2824
|
function Constants() {
|
|
@@ -3093,7 +3120,7 @@ var Constants = /** @class */ (function () {
|
|
|
3093
3120
|
"c#",
|
|
3094
3121
|
"bat",
|
|
3095
3122
|
];
|
|
3096
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
3123
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.7");
|
|
3097
3124
|
Constants.MARKDOWN_OPTIONS = {
|
|
3098
3125
|
autoSpace: false,
|
|
3099
3126
|
gfmAutoLink: true,
|
|
@@ -4541,6 +4568,31 @@ var flowchartRender = function (element, cdn) {
|
|
|
4541
4568
|
};
|
|
4542
4569
|
|
|
4543
4570
|
|
|
4571
|
+
/***/ }),
|
|
4572
|
+
|
|
4573
|
+
/***/ 210:
|
|
4574
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4575
|
+
|
|
4576
|
+
"use strict";
|
|
4577
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4578
|
+
/* harmony export */ "O": () => (/* binding */ getMarkdown)
|
|
4579
|
+
/* harmony export */ });
|
|
4580
|
+
/* harmony import */ var _util_code160to32__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(105);
|
|
4581
|
+
|
|
4582
|
+
var getMarkdown = function (vditor) {
|
|
4583
|
+
if (vditor.currentMode === "sv") {
|
|
4584
|
+
return (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_0__/* .code160to32 */ .X)("".concat(vditor.sv.element.textContent, "\n").replace(/\n\n$/, "\n"));
|
|
4585
|
+
}
|
|
4586
|
+
else if (vditor.currentMode === "wysiwyg") {
|
|
4587
|
+
return vditor.lute.VditorDOM2Md(vditor.wysiwyg.element.innerHTML);
|
|
4588
|
+
}
|
|
4589
|
+
else if (vditor.currentMode === "ir") {
|
|
4590
|
+
return vditor.lute.VditorIRDOM2Md(vditor.ir.element.innerHTML);
|
|
4591
|
+
}
|
|
4592
|
+
return "";
|
|
4593
|
+
};
|
|
4594
|
+
|
|
4595
|
+
|
|
4544
4596
|
/***/ }),
|
|
4545
4597
|
|
|
4546
4598
|
/***/ 483:
|
|
@@ -6142,110 +6194,584 @@ var addStyle = function (url, id) {
|
|
|
6142
6194
|
|
|
6143
6195
|
/***/ }),
|
|
6144
6196
|
|
|
6145
|
-
/***/
|
|
6146
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
6147
|
-
|
|
6148
|
-
"use strict";
|
|
6149
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
6150
|
-
/* harmony export */ "X": () => (/* binding */ code160to32)
|
|
6151
|
-
/* harmony export */ });
|
|
6152
|
-
var code160to32 = function (text) {
|
|
6153
|
-
// 非打断空格转换为空格
|
|
6154
|
-
return text.replace(/\u00a0/g, " ");
|
|
6155
|
-
};
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
/***/ }),
|
|
6159
|
-
|
|
6160
|
-
/***/ 410:
|
|
6197
|
+
/***/ 626:
|
|
6161
6198
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
6162
6199
|
|
|
6163
6200
|
"use strict";
|
|
6164
6201
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
6165
|
-
/* harmony export */ "
|
|
6166
|
-
/* harmony export */ "
|
|
6167
|
-
/* harmony export */ "pK": () => (/* binding */ accessLocalStorage),
|
|
6168
|
-
/* harmony export */ "Le": () => (/* binding */ getEventName),
|
|
6169
|
-
/* harmony export */ "yl": () => (/* binding */ isCtrl),
|
|
6170
|
-
/* harmony export */ "ns": () => (/* binding */ updateHotkeyTip),
|
|
6171
|
-
/* harmony export */ "i7": () => (/* binding */ isChrome)
|
|
6202
|
+
/* harmony export */ "t": () => (/* binding */ attachLineNumbersToBlocks),
|
|
6203
|
+
/* harmony export */ "g": () => (/* binding */ attachLineNumbersToBlocksThrottled)
|
|
6172
6204
|
/* harmony export */ });
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
catch (e) {
|
|
6184
|
-
return false;
|
|
6185
|
-
}
|
|
6186
|
-
};
|
|
6187
|
-
// 用户 iPhone 点击延迟/需要双击的处理
|
|
6188
|
-
var getEventName = function () {
|
|
6189
|
-
if (navigator.userAgent.indexOf("iPhone") > -1) {
|
|
6190
|
-
return "touchstart";
|
|
6191
|
-
}
|
|
6192
|
-
else {
|
|
6193
|
-
return "click";
|
|
6205
|
+
/**
|
|
6206
|
+
* 为编辑区域添加行号标记:
|
|
6207
|
+
* - 为所有包含 `data-block` 的块级节点写入 `data-linenumber`
|
|
6208
|
+
* - 额外为每个 `ul` 的直接 `li` 子元素写入 `data-linenumber`(不修改 `ul` 本身)
|
|
6209
|
+
* 通过解析传入的 Markdown 源文本,建立内容到源文件行号的映射,
|
|
6210
|
+
* 兼顾多行文本、嵌套列表、重复内容及空白/特殊字符,并提供基础错误保护。
|
|
6211
|
+
*/
|
|
6212
|
+
var attachLineNumbersToBlocks = function (root, sourceMarkdown) {
|
|
6213
|
+
if (!root || !sourceMarkdown) {
|
|
6214
|
+
return;
|
|
6194
6215
|
}
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6216
|
+
var ZWSP = "\u200b";
|
|
6217
|
+
var normalize = function (text) {
|
|
6218
|
+
return text
|
|
6219
|
+
.replace(/\r\n|\r/g, "\n")
|
|
6220
|
+
.replace(new RegExp(ZWSP, "g"), "")
|
|
6221
|
+
.replace(/\u00a0/g, " ")
|
|
6222
|
+
.replace(/\u2006/g, "")
|
|
6223
|
+
.replace(/[\t\f\v ]+/g, " ");
|
|
6224
|
+
};
|
|
6225
|
+
var srcNorm = normalize(sourceMarkdown);
|
|
6226
|
+
var srcLines = srcNorm.split("\n");
|
|
6227
|
+
var stripInlineMD = function (text) {
|
|
6228
|
+
return (text
|
|
6229
|
+
.replace(/\\([*_`~])/g, "$1")
|
|
6230
|
+
.replace(/\*\*|__/g, "")
|
|
6231
|
+
.replace(/\*|_/g, "")
|
|
6232
|
+
.replace(/~~/g, "")
|
|
6233
|
+
.replace(/`+/g, "")
|
|
6234
|
+
// 数学行内分隔符:保留内容,仅移除分隔符
|
|
6235
|
+
.replace(/\\\(/g, "(")
|
|
6236
|
+
.replace(/\\\)/g, ")")
|
|
6237
|
+
.replace(/\\\[/g, "[")
|
|
6238
|
+
.replace(/\\\]/g, "]")
|
|
6239
|
+
.replace(/\$/g, "")
|
|
6240
|
+
.trim());
|
|
6241
|
+
};
|
|
6242
|
+
var stripInlineForList = function (text) {
|
|
6243
|
+
return (stripInlineMD(text)
|
|
6244
|
+
// 移除 $...$(行内公式整体)
|
|
6245
|
+
.replace(/\$(?:\\.|[^$])*\$/g, "")
|
|
6246
|
+
// 移除 \(...\)、\[...\](行内/行间公式整体)
|
|
6247
|
+
.replace(/\\\([^)]*\\\)/g, "")
|
|
6248
|
+
.replace(/\\\[[^\]]*\\\]/g, "")
|
|
6249
|
+
// 去除通用 TeX 命令,如 \alpha、\mathbf 等
|
|
6250
|
+
.replace(/\\[a-zA-Z]+/g, "")
|
|
6251
|
+
// 去除多余大括号
|
|
6252
|
+
.replace(/[{}]/g, "")
|
|
6253
|
+
.trim());
|
|
6254
|
+
};
|
|
6255
|
+
var strippedLines = srcLines.map(function (l) { return stripInlineMD(l); });
|
|
6256
|
+
var lineLookup = new Map();
|
|
6257
|
+
for (var i = 0; i < strippedLines.length; i++) {
|
|
6258
|
+
var key = strippedLines[i];
|
|
6259
|
+
if (!lineLookup.has(key)) {
|
|
6260
|
+
lineLookup.set(key, [i + 1]);
|
|
6202
6261
|
}
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
else {
|
|
6206
|
-
if (!event.metaKey && event.ctrlKey) {
|
|
6207
|
-
return true;
|
|
6262
|
+
else {
|
|
6263
|
+
lineLookup.get(key).push(i + 1);
|
|
6208
6264
|
}
|
|
6209
|
-
return false;
|
|
6210
6265
|
}
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6266
|
+
var usedLines = new Set();
|
|
6267
|
+
var pickFirstUnused = function (candidates) {
|
|
6268
|
+
if (!candidates || candidates.length === 0)
|
|
6269
|
+
return -1;
|
|
6270
|
+
for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
|
|
6271
|
+
var ln = candidates_1[_i];
|
|
6272
|
+
if (!usedLines.has(ln))
|
|
6273
|
+
return ln;
|
|
6218
6274
|
}
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6275
|
+
return -1;
|
|
6276
|
+
};
|
|
6277
|
+
var findLineNumberByText = function (text) {
|
|
6278
|
+
var stripped = stripInlineMD(text);
|
|
6279
|
+
var ln = pickFirstUnused(lineLookup.get(stripped));
|
|
6280
|
+
if (ln !== -1)
|
|
6281
|
+
return ln;
|
|
6282
|
+
for (var i = 0; i < strippedLines.length; i++) {
|
|
6283
|
+
if (!usedLines.has(i + 1) &&
|
|
6284
|
+
stripped &&
|
|
6285
|
+
strippedLines[i].indexOf(stripped) !== -1) {
|
|
6286
|
+
return i + 1;
|
|
6287
|
+
}
|
|
6223
6288
|
}
|
|
6224
|
-
|
|
6225
|
-
|
|
6289
|
+
return -1;
|
|
6290
|
+
};
|
|
6291
|
+
/**
|
|
6292
|
+
* 预处理:收集 Markdown 中所有无序列表(ul)行及其去除行内标记后的内容,构建快速查找结构。
|
|
6293
|
+
* 仅匹配以 `*`、`-`、`+` 开头的条目,支持任务列表如 `- [ ]`、`* [x]`。
|
|
6294
|
+
*/
|
|
6295
|
+
var unorderedListEntries = [];
|
|
6296
|
+
var unorderedLookup = new Map();
|
|
6297
|
+
var usedUnorderedLines = new Set();
|
|
6298
|
+
for (var i = 0; i < srcLines.length; i++) {
|
|
6299
|
+
var raw = srcLines[i];
|
|
6300
|
+
var m = raw.match(/^\s*[*+-]\s+(?:\[(?: |x|X)\]\s+)?(.*)$/);
|
|
6301
|
+
if (m && typeof m[1] === "string") {
|
|
6302
|
+
var contentStripped = stripInlineForList(m[1]);
|
|
6303
|
+
unorderedListEntries.push({ ln: i + 1, content: contentStripped });
|
|
6304
|
+
if (!unorderedLookup.has(contentStripped)) {
|
|
6305
|
+
unorderedLookup.set(contentStripped, [i + 1]);
|
|
6306
|
+
}
|
|
6307
|
+
else {
|
|
6308
|
+
unorderedLookup.get(contentStripped).push(i + 1);
|
|
6309
|
+
}
|
|
6226
6310
|
}
|
|
6227
|
-
|
|
6228
|
-
|
|
6311
|
+
}
|
|
6312
|
+
/**
|
|
6313
|
+
* 从无序列表候选行中为给定文本选择一个行号。
|
|
6314
|
+
* 优先精确匹配(去标记后完全相同),否则回退到包含匹配。
|
|
6315
|
+
*/
|
|
6316
|
+
var pickFirstUnusedUnordered = function (candidates) {
|
|
6317
|
+
if (!candidates || candidates.length === 0)
|
|
6318
|
+
return -1;
|
|
6319
|
+
for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
|
|
6320
|
+
var ln = candidates_2[_i];
|
|
6321
|
+
if (!usedUnorderedLines.has(ln))
|
|
6322
|
+
return ln;
|
|
6229
6323
|
}
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6324
|
+
return -1;
|
|
6325
|
+
};
|
|
6326
|
+
var findUnorderedListLineNumber = function (text) {
|
|
6327
|
+
var stripped = stripInlineForList(text);
|
|
6328
|
+
// 先尝试精确匹配
|
|
6329
|
+
var exact = pickFirstUnusedUnordered(unorderedLookup.get(stripped));
|
|
6330
|
+
if (exact !== -1)
|
|
6331
|
+
return exact;
|
|
6332
|
+
// 回退到包含匹配
|
|
6333
|
+
for (var i = 0; i < unorderedListEntries.length; i++) {
|
|
6334
|
+
var entry = unorderedListEntries[i];
|
|
6335
|
+
if (usedUnorderedLines.has(entry.ln))
|
|
6336
|
+
continue;
|
|
6337
|
+
if (!stripped)
|
|
6338
|
+
continue;
|
|
6339
|
+
if (entry.content.indexOf(stripped) !== -1 ||
|
|
6340
|
+
stripped.indexOf(entry.content) !== -1) {
|
|
6341
|
+
return entry.ln;
|
|
6342
|
+
}
|
|
6343
|
+
}
|
|
6344
|
+
return -1;
|
|
6345
|
+
};
|
|
6346
|
+
/**
|
|
6347
|
+
* 预处理:收集 Markdown 中所有有序列表(ol)行及其内容,支持 `1.` 或 `1)` 以及任务列表前缀。
|
|
6348
|
+
*/
|
|
6349
|
+
var orderedListEntries = [];
|
|
6350
|
+
var orderedLookup = new Map();
|
|
6351
|
+
var usedOrderedLines = new Set();
|
|
6352
|
+
var ORDERED_RE = /\s*\d+(?:[.)、.。]|[\uFF0E\uFF09\u3001])\s+(?:\[(?: |x|X)\]\s+)?(.*)/;
|
|
6353
|
+
var ORDERED_FULL = new RegExp("^".concat(ORDERED_RE.source, "$"));
|
|
6354
|
+
for (var i = 0; i < srcLines.length; i++) {
|
|
6355
|
+
var raw = srcLines[i];
|
|
6356
|
+
var m = raw.match(ORDERED_FULL);
|
|
6357
|
+
if (m && typeof m[1] === "string") {
|
|
6358
|
+
var contentStripped = stripInlineForList(m[1]);
|
|
6359
|
+
orderedListEntries.push({ ln: i + 1, content: contentStripped });
|
|
6360
|
+
if (!orderedLookup.has(contentStripped)) {
|
|
6361
|
+
orderedLookup.set(contentStripped, [i + 1]);
|
|
6362
|
+
}
|
|
6363
|
+
else {
|
|
6364
|
+
orderedLookup.get(contentStripped).push(i + 1);
|
|
6365
|
+
}
|
|
6234
6366
|
}
|
|
6235
6367
|
}
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6368
|
+
console.debug("[LineNumber][ol:index]", {
|
|
6369
|
+
total: orderedListEntries.length,
|
|
6370
|
+
});
|
|
6371
|
+
var orderedGroups = [];
|
|
6372
|
+
for (var i = 0; i < srcLines.length;) {
|
|
6373
|
+
var raw = srcLines[i];
|
|
6374
|
+
if (ORDERED_FULL.test(raw)) {
|
|
6375
|
+
var group = [];
|
|
6376
|
+
while (i < srcLines.length && ORDERED_FULL.test(srcLines[i])) {
|
|
6377
|
+
group.push(i + 1);
|
|
6378
|
+
i++;
|
|
6379
|
+
}
|
|
6380
|
+
if (group.length > 0) {
|
|
6381
|
+
orderedGroups.push(group);
|
|
6382
|
+
}
|
|
6383
|
+
}
|
|
6384
|
+
else {
|
|
6385
|
+
i++;
|
|
6386
|
+
}
|
|
6387
|
+
}
|
|
6388
|
+
/**
|
|
6389
|
+
* 为给定文本在有序列表候选中选择行号,精确匹配优先,包含匹配回退。
|
|
6390
|
+
*/
|
|
6391
|
+
var pickFirstUnusedOrdered = function (candidates) {
|
|
6392
|
+
if (!candidates || candidates.length === 0)
|
|
6393
|
+
return -1;
|
|
6394
|
+
for (var _i = 0, candidates_3 = candidates; _i < candidates_3.length; _i++) {
|
|
6395
|
+
var ln = candidates_3[_i];
|
|
6396
|
+
if (!usedOrderedLines.has(ln))
|
|
6397
|
+
return ln;
|
|
6398
|
+
}
|
|
6399
|
+
return -1;
|
|
6400
|
+
};
|
|
6401
|
+
var findOrderedListLineNumber = function (text) {
|
|
6402
|
+
var stripped = stripInlineForList(text);
|
|
6403
|
+
var exact = pickFirstUnusedOrdered(orderedLookup.get(stripped));
|
|
6404
|
+
if (exact !== -1)
|
|
6405
|
+
return exact;
|
|
6406
|
+
for (var i = 0; i < orderedListEntries.length; i++) {
|
|
6407
|
+
var entry = orderedListEntries[i];
|
|
6408
|
+
if (usedOrderedLines.has(entry.ln))
|
|
6409
|
+
continue;
|
|
6410
|
+
if (!stripped)
|
|
6411
|
+
continue;
|
|
6412
|
+
if (entry.content.indexOf(stripped) !== -1 ||
|
|
6413
|
+
stripped.indexOf(entry.content) !== -1) {
|
|
6414
|
+
return entry.ln;
|
|
6415
|
+
}
|
|
6416
|
+
}
|
|
6417
|
+
return -1;
|
|
6418
|
+
};
|
|
6419
|
+
/**
|
|
6420
|
+
* 获取 `li` 的直接内容文本:仅拼接其直系子节点中的文本,排除嵌套的 `UL/OL` 列表。
|
|
6421
|
+
* 以便在嵌套列表场景下准确定位每个条目对应的源行。
|
|
6422
|
+
*/
|
|
6423
|
+
var getImmediateLiText = function (li) {
|
|
6424
|
+
var buf = "";
|
|
6425
|
+
li.childNodes.forEach(function (node) {
|
|
6426
|
+
var _a;
|
|
6427
|
+
if (node.nodeType === 3) {
|
|
6428
|
+
buf += node.data;
|
|
6429
|
+
}
|
|
6430
|
+
else if (node.tagName !== "UL" &&
|
|
6431
|
+
node.tagName !== "OL" &&
|
|
6432
|
+
!((_a = node.classList) === null || _a === void 0 ? void 0 : _a.contains("katex"))) {
|
|
6433
|
+
buf += node.textContent || "";
|
|
6434
|
+
}
|
|
6435
|
+
});
|
|
6436
|
+
return buf;
|
|
6437
|
+
};
|
|
6438
|
+
var blocks = root.querySelectorAll("[data-block]");
|
|
6439
|
+
blocks.forEach(function (el) {
|
|
6440
|
+
try {
|
|
6441
|
+
var container = el;
|
|
6442
|
+
var dataType = container.getAttribute("data-type") || "";
|
|
6443
|
+
if (dataType === "math-block" || dataType === "code-block") {
|
|
6444
|
+
return;
|
|
6445
|
+
}
|
|
6446
|
+
// 仅 li 需要行号:跳过并清理 ul/ol 自身及其内部嵌套的 p/div 等块
|
|
6447
|
+
var tagName = container.tagName;
|
|
6448
|
+
if (tagName === "UL" || tagName === "OL") {
|
|
6449
|
+
container.removeAttribute("data-linenumber");
|
|
6450
|
+
return;
|
|
6451
|
+
}
|
|
6452
|
+
var liAncestor = container.closest("li");
|
|
6453
|
+
if (liAncestor) {
|
|
6454
|
+
container.removeAttribute("data-linenumber");
|
|
6455
|
+
return;
|
|
6456
|
+
}
|
|
6457
|
+
var text = container.textContent || "";
|
|
6458
|
+
var normText = normalize(text);
|
|
6459
|
+
// 跳过纯空白块
|
|
6460
|
+
if (!normText.trim()) {
|
|
6461
|
+
container.removeAttribute("data-linenumber");
|
|
6462
|
+
return;
|
|
6463
|
+
}
|
|
6464
|
+
var lineNumber = -1;
|
|
6465
|
+
if (tagName === "BLOCKQUOTE") {
|
|
6466
|
+
var firstLine = normText.split("\n").find(function (l) { return l.trim().length > 0; }) ||
|
|
6467
|
+
normText;
|
|
6468
|
+
var stripped = stripInlineMD(firstLine);
|
|
6469
|
+
for (var i = 0; i < srcLines.length; i++) {
|
|
6470
|
+
if (usedLines.has(i + 1))
|
|
6471
|
+
continue;
|
|
6472
|
+
if (/^\s*>+\s/.test(srcLines[i])) {
|
|
6473
|
+
var content = stripInlineMD(srcLines[i].replace(/^\s*>+\s+/, ""));
|
|
6474
|
+
if (content.indexOf(stripped) !== -1) {
|
|
6475
|
+
lineNumber = i + 1;
|
|
6476
|
+
break;
|
|
6477
|
+
}
|
|
6478
|
+
}
|
|
6479
|
+
}
|
|
6480
|
+
}
|
|
6481
|
+
else {
|
|
6482
|
+
var firstLine = normText.split("\n").find(function (l) { return l.trim().length > 0; }) ||
|
|
6483
|
+
normText;
|
|
6484
|
+
lineNumber = findLineNumberByText(firstLine);
|
|
6485
|
+
}
|
|
6486
|
+
if (lineNumber !== -1) {
|
|
6487
|
+
usedLines.add(lineNumber);
|
|
6488
|
+
container.setAttribute("data-linenumber", String(lineNumber));
|
|
6489
|
+
}
|
|
6490
|
+
}
|
|
6491
|
+
catch (_a) {
|
|
6492
|
+
void 0;
|
|
6493
|
+
}
|
|
6494
|
+
});
|
|
6495
|
+
/**
|
|
6496
|
+
* 为所有 `ul` 下的每个直接 `li` 子元素追加 `data-linenumber`,不修改 `ul` 本身。
|
|
6497
|
+
* 支持多层嵌套与非文本起始节点(如加粗/行内代码)。
|
|
6498
|
+
*/
|
|
6499
|
+
var ulElements = root.querySelectorAll("ul");
|
|
6500
|
+
ulElements.forEach(function (ul) {
|
|
6501
|
+
try {
|
|
6502
|
+
var children = Array.from(ul.children);
|
|
6503
|
+
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
|
|
6504
|
+
var child = children_1[_i];
|
|
6505
|
+
if (child.tagName !== "LI")
|
|
6506
|
+
continue;
|
|
6507
|
+
var li = child;
|
|
6508
|
+
var rawText = getImmediateLiText(li);
|
|
6509
|
+
var norm = normalize(rawText);
|
|
6510
|
+
var firstLine = norm.split("\n").find(function (l) { return l.trim().length > 0; }) || norm;
|
|
6511
|
+
var ln = findUnorderedListLineNumber(firstLine);
|
|
6512
|
+
if (ln !== -1) {
|
|
6513
|
+
usedUnorderedLines.add(ln);
|
|
6514
|
+
li.setAttribute("data-linenumber", String(ln));
|
|
6515
|
+
}
|
|
6516
|
+
else {
|
|
6517
|
+
li.setAttribute("data-linenumber", "");
|
|
6518
|
+
}
|
|
6519
|
+
}
|
|
6520
|
+
}
|
|
6521
|
+
catch (_a) {
|
|
6522
|
+
void 0;
|
|
6523
|
+
}
|
|
6524
|
+
});
|
|
6525
|
+
/**
|
|
6526
|
+
* 为所有 `ol` 下的每个直接 `li` 子元素追加 `data-linenumber`,不修改 `ol` 本身。
|
|
6527
|
+
*/
|
|
6528
|
+
var olElements = root.querySelectorAll("ol");
|
|
6529
|
+
olElements.forEach(function (ol) {
|
|
6530
|
+
try {
|
|
6531
|
+
var currentGroupIdx = -1;
|
|
6532
|
+
var lastAssigned_1 = -1;
|
|
6533
|
+
var children = Array.from(ol.children);
|
|
6534
|
+
for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
|
|
6535
|
+
var child = children_2[_i];
|
|
6536
|
+
if (child.tagName !== "LI")
|
|
6537
|
+
continue;
|
|
6538
|
+
var li = child;
|
|
6539
|
+
var rawText = getImmediateLiText(li);
|
|
6540
|
+
var norm = normalize(rawText);
|
|
6541
|
+
var firstLine = norm.split("\n").find(function (l) { return l.trim().length > 0; }) || norm;
|
|
6542
|
+
var stripped0 = stripInlineForList(firstLine);
|
|
6543
|
+
var stripped = stripped0 || stripInlineMD(firstLine);
|
|
6544
|
+
var candidates = orderedLookup.get(stripped) || [];
|
|
6545
|
+
var available = candidates.filter(function (n) { return !usedOrderedLines.has(n); });
|
|
6546
|
+
var ln = findOrderedListLineNumber(firstLine);
|
|
6547
|
+
if (ln !== -1) {
|
|
6548
|
+
usedOrderedLines.add(ln);
|
|
6549
|
+
li.setAttribute("data-linenumber", String(ln));
|
|
6550
|
+
// 成功映射日志
|
|
6551
|
+
console.debug("[LineNumber][ol>li]", {
|
|
6552
|
+
text: firstLine,
|
|
6553
|
+
stripped: stripped,
|
|
6554
|
+
line: ln,
|
|
6555
|
+
});
|
|
6556
|
+
// 记录当前组
|
|
6557
|
+
for (var gi = 0; gi < orderedGroups.length; gi++) {
|
|
6558
|
+
if (orderedGroups[gi].includes(ln)) {
|
|
6559
|
+
currentGroupIdx = gi;
|
|
6560
|
+
break;
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
lastAssigned_1 = ln;
|
|
6564
|
+
}
|
|
6565
|
+
else {
|
|
6566
|
+
// 顺序回退:基于当前组或猜测组,按序分配下一未使用行
|
|
6567
|
+
var assigned = -1;
|
|
6568
|
+
var pickNextFromGroup = function (gi) {
|
|
6569
|
+
if (gi < 0 || gi >= orderedGroups.length)
|
|
6570
|
+
return -1;
|
|
6571
|
+
var lines = orderedGroups[gi];
|
|
6572
|
+
// 优先从上次分配后续查找
|
|
6573
|
+
var startIdx = 0;
|
|
6574
|
+
if (lastAssigned_1 !== -1) {
|
|
6575
|
+
var idx = lines.indexOf(lastAssigned_1);
|
|
6576
|
+
startIdx = idx >= 0 ? idx + 1 : 0;
|
|
6577
|
+
}
|
|
6578
|
+
for (var k = startIdx; k < lines.length; k++) {
|
|
6579
|
+
var cand = lines[k];
|
|
6580
|
+
if (!usedOrderedLines.has(cand))
|
|
6581
|
+
return cand;
|
|
6582
|
+
}
|
|
6583
|
+
for (var k = 0; k < startIdx; k++) {
|
|
6584
|
+
var cand = lines[k];
|
|
6585
|
+
if (!usedOrderedLines.has(cand))
|
|
6586
|
+
return cand;
|
|
6587
|
+
}
|
|
6588
|
+
return -1;
|
|
6589
|
+
};
|
|
6590
|
+
if (currentGroupIdx !== -1) {
|
|
6591
|
+
assigned = pickNextFromGroup(currentGroupIdx);
|
|
6592
|
+
}
|
|
6593
|
+
if (assigned === -1) {
|
|
6594
|
+
// 猜测组:选择拥有可用行的首个组
|
|
6595
|
+
for (var gi = 0; gi < orderedGroups.length && assigned === -1; gi++) {
|
|
6596
|
+
var cand = pickNextFromGroup(gi);
|
|
6597
|
+
if (cand !== -1) {
|
|
6598
|
+
currentGroupIdx = gi;
|
|
6599
|
+
assigned = cand;
|
|
6600
|
+
}
|
|
6601
|
+
}
|
|
6602
|
+
}
|
|
6603
|
+
if (assigned !== -1) {
|
|
6604
|
+
usedOrderedLines.add(assigned);
|
|
6605
|
+
li.setAttribute("data-linenumber", String(assigned));
|
|
6606
|
+
console.debug("[LineNumber][ol>li][fallback-seq]", {
|
|
6607
|
+
text: firstLine,
|
|
6608
|
+
stripped: stripped,
|
|
6609
|
+
line: assigned,
|
|
6610
|
+
group: currentGroupIdx,
|
|
6611
|
+
});
|
|
6612
|
+
lastAssigned_1 = assigned;
|
|
6613
|
+
}
|
|
6614
|
+
else {
|
|
6615
|
+
li.setAttribute("data-linenumber", "");
|
|
6616
|
+
// 失败诊断日志
|
|
6617
|
+
console.warn("[LineNumber][ol>li][missing]", {
|
|
6618
|
+
text: firstLine,
|
|
6619
|
+
stripped: stripped,
|
|
6620
|
+
candidates: candidates,
|
|
6621
|
+
available: available,
|
|
6622
|
+
reason: !stripped0
|
|
6623
|
+
? "empty-after-strip"
|
|
6624
|
+
: candidates.length === 0
|
|
6625
|
+
? "no-index-candidates"
|
|
6626
|
+
: available.length === 0
|
|
6627
|
+
? "all-candidates-consumed"
|
|
6628
|
+
: "fallback-no-match",
|
|
6629
|
+
});
|
|
6630
|
+
}
|
|
6631
|
+
}
|
|
6632
|
+
}
|
|
6633
|
+
}
|
|
6634
|
+
catch (_a) {
|
|
6635
|
+
void 0;
|
|
6636
|
+
}
|
|
6637
|
+
});
|
|
6638
|
+
};
|
|
6639
|
+
/**
|
|
6640
|
+
* 节流后的行号更新函数,避免频繁更新 data-linenumber
|
|
6641
|
+
*/
|
|
6642
|
+
var attachLineNumbersToBlocksThrottled = (function () {
|
|
6643
|
+
var last = 0;
|
|
6644
|
+
var timer = 0;
|
|
6645
|
+
var lastArgs = null;
|
|
6646
|
+
var wait = 500;
|
|
6647
|
+
var invoke = function () {
|
|
6648
|
+
timer = 0;
|
|
6649
|
+
last = Date.now();
|
|
6650
|
+
var args = lastArgs;
|
|
6651
|
+
lastArgs = null;
|
|
6652
|
+
if (args) {
|
|
6653
|
+
attachLineNumbersToBlocks(args[0], args[1]);
|
|
6654
|
+
}
|
|
6655
|
+
};
|
|
6656
|
+
return function (root, source) {
|
|
6657
|
+
var now = Date.now();
|
|
6658
|
+
lastArgs = [root, source];
|
|
6659
|
+
if (now - last >= wait) {
|
|
6660
|
+
invoke();
|
|
6661
|
+
}
|
|
6662
|
+
else if (!timer) {
|
|
6663
|
+
timer = window.setTimeout(invoke, wait - (now - last));
|
|
6664
|
+
}
|
|
6665
|
+
};
|
|
6666
|
+
})();
|
|
6667
|
+
|
|
6668
|
+
|
|
6669
|
+
/***/ }),
|
|
6670
|
+
|
|
6671
|
+
/***/ 105:
|
|
6672
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
6673
|
+
|
|
6674
|
+
"use strict";
|
|
6675
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
6676
|
+
/* harmony export */ "X": () => (/* binding */ code160to32)
|
|
6677
|
+
/* harmony export */ });
|
|
6678
|
+
var code160to32 = function (text) {
|
|
6679
|
+
// 非打断空格转换为空格
|
|
6680
|
+
return text.replace(/\u00a0/g, " ");
|
|
6681
|
+
};
|
|
6682
|
+
|
|
6683
|
+
|
|
6684
|
+
/***/ }),
|
|
6685
|
+
|
|
6686
|
+
/***/ 410:
|
|
6687
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
6688
|
+
|
|
6689
|
+
"use strict";
|
|
6690
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
6691
|
+
/* harmony export */ "G6": () => (/* binding */ isSafari),
|
|
6692
|
+
/* harmony export */ "vU": () => (/* binding */ isFirefox),
|
|
6693
|
+
/* harmony export */ "pK": () => (/* binding */ accessLocalStorage),
|
|
6694
|
+
/* harmony export */ "Le": () => (/* binding */ getEventName),
|
|
6695
|
+
/* harmony export */ "yl": () => (/* binding */ isCtrl),
|
|
6696
|
+
/* harmony export */ "ns": () => (/* binding */ updateHotkeyTip),
|
|
6697
|
+
/* harmony export */ "i7": () => (/* binding */ isChrome)
|
|
6698
|
+
/* harmony export */ });
|
|
6699
|
+
var isSafari = function () {
|
|
6700
|
+
return navigator.userAgent.indexOf("Safari") > -1 && navigator.userAgent.indexOf("Chrome") === -1;
|
|
6701
|
+
};
|
|
6702
|
+
var isFirefox = function () {
|
|
6703
|
+
return navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
|
6704
|
+
};
|
|
6705
|
+
var accessLocalStorage = function () {
|
|
6706
|
+
try {
|
|
6707
|
+
return typeof localStorage !== "undefined";
|
|
6708
|
+
}
|
|
6709
|
+
catch (e) {
|
|
6710
|
+
return false;
|
|
6711
|
+
}
|
|
6712
|
+
};
|
|
6713
|
+
// 用户 iPhone 点击延迟/需要双击的处理
|
|
6714
|
+
var getEventName = function () {
|
|
6715
|
+
if (navigator.userAgent.indexOf("iPhone") > -1) {
|
|
6716
|
+
return "touchstart";
|
|
6717
|
+
}
|
|
6718
|
+
else {
|
|
6719
|
+
return "click";
|
|
6720
|
+
}
|
|
6721
|
+
};
|
|
6722
|
+
// 区别 mac 上的 ctrl 和 meta
|
|
6723
|
+
var isCtrl = function (event) {
|
|
6724
|
+
if (navigator.platform.toUpperCase().indexOf("MAC") >= 0) {
|
|
6725
|
+
// mac
|
|
6726
|
+
if (event.metaKey && !event.ctrlKey) {
|
|
6727
|
+
return true;
|
|
6728
|
+
}
|
|
6729
|
+
return false;
|
|
6730
|
+
}
|
|
6731
|
+
else {
|
|
6732
|
+
if (!event.metaKey && event.ctrlKey) {
|
|
6733
|
+
return true;
|
|
6734
|
+
}
|
|
6735
|
+
return false;
|
|
6736
|
+
}
|
|
6737
|
+
};
|
|
6738
|
+
// Mac,Windows 快捷键展示
|
|
6739
|
+
var updateHotkeyTip = function (hotkey) {
|
|
6740
|
+
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
|
|
6741
|
+
if (hotkey.indexOf("⇧") > -1 && isFirefox()) {
|
|
6742
|
+
// Mac Firefox 按下 shift 后,key 同 windows 系统
|
|
6743
|
+
hotkey = hotkey.replace(";", ":").replace("=", "+").replace("-", "_");
|
|
6744
|
+
}
|
|
6745
|
+
}
|
|
6746
|
+
else {
|
|
6747
|
+
if (hotkey.startsWith("⌘")) {
|
|
6748
|
+
hotkey = hotkey.replace("⌘", "⌘+");
|
|
6749
|
+
}
|
|
6750
|
+
else if (hotkey.startsWith("⌥") && hotkey.substr(1, 1) !== "⌘") {
|
|
6751
|
+
hotkey = hotkey.replace("⌥", "⌥+");
|
|
6752
|
+
}
|
|
6753
|
+
else {
|
|
6754
|
+
hotkey = hotkey.replace("⇧⌘", "⌘+⇧+").replace("⌥⌘", "⌥+⌘+");
|
|
6755
|
+
}
|
|
6756
|
+
hotkey = hotkey.replace("⌘", "Ctrl").replace("⇧", "Shift")
|
|
6757
|
+
.replace("⌥", "Alt");
|
|
6758
|
+
if (hotkey.indexOf("Shift") > -1) {
|
|
6759
|
+
hotkey = hotkey.replace(";", ":").replace("=", "+").replace("-", "_");
|
|
6760
|
+
}
|
|
6761
|
+
}
|
|
6762
|
+
return hotkey;
|
|
6763
|
+
};
|
|
6764
|
+
var isChrome = function () {
|
|
6765
|
+
return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
|
|
6766
|
+
};
|
|
6767
|
+
|
|
6768
|
+
|
|
6769
|
+
/***/ }),
|
|
6770
|
+
|
|
6771
|
+
/***/ 494:
|
|
6772
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
6773
|
+
|
|
6774
|
+
"use strict";
|
|
6249
6775
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
6250
6776
|
/* harmony export */ "Wb": () => (/* binding */ genUUID),
|
|
6251
6777
|
/* harmony export */ "on": () => (/* binding */ getSearch),
|
|
@@ -6894,23 +7420,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
6894
7420
|
var method = __webpack_require__(408);
|
|
6895
7421
|
// EXTERNAL MODULE: ./src/ts/constants.ts
|
|
6896
7422
|
var constants = __webpack_require__(145);
|
|
6897
|
-
// EXTERNAL MODULE: ./src/ts/
|
|
6898
|
-
var
|
|
6899
|
-
;// CONCATENATED MODULE: ./src/ts/markdown/getMarkdown.ts
|
|
6900
|
-
|
|
6901
|
-
var getMarkdown = function (vditor) {
|
|
6902
|
-
if (vditor.currentMode === "sv") {
|
|
6903
|
-
return (0,code160to32/* code160to32 */.X)("".concat(vditor.sv.element.textContent, "\n").replace(/\n\n$/, "\n"));
|
|
6904
|
-
}
|
|
6905
|
-
else if (vditor.currentMode === "wysiwyg") {
|
|
6906
|
-
return vditor.lute.VditorDOM2Md(vditor.wysiwyg.element.innerHTML);
|
|
6907
|
-
}
|
|
6908
|
-
else if (vditor.currentMode === "ir") {
|
|
6909
|
-
return vditor.lute.VditorIRDOM2Md(vditor.ir.element.innerHTML);
|
|
6910
|
-
}
|
|
6911
|
-
return "";
|
|
6912
|
-
};
|
|
6913
|
-
|
|
7423
|
+
// EXTERNAL MODULE: ./src/ts/markdown/getMarkdown.ts
|
|
7424
|
+
var getMarkdown = __webpack_require__(210);
|
|
6914
7425
|
// EXTERNAL MODULE: ./src/ts/util/addScript.ts
|
|
6915
7426
|
var addScript = __webpack_require__(413);
|
|
6916
7427
|
;// CONCATENATED MODULE: ./src/ts/devtools/index.ts
|
|
@@ -6937,7 +7448,7 @@ var DevTools = /** @class */ (function () {
|
|
|
6937
7448
|
_this.ASTChart.setOption({
|
|
6938
7449
|
series: [
|
|
6939
7450
|
{
|
|
6940
|
-
data: JSON.parse(vditor.lute.RenderEChartsJSON(getMarkdown(vditor))),
|
|
7451
|
+
data: JSON.parse(vditor.lute.RenderEChartsJSON((0,getMarkdown/* getMarkdown */.O)(vditor))),
|
|
6941
7452
|
initialTreeDepth: -1,
|
|
6942
7453
|
label: {
|
|
6943
7454
|
align: "left",
|
|
@@ -7443,8 +7954,11 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7443
7954
|
if (ignoreSpace === void 0) { ignoreSpace = false; }
|
|
7444
7955
|
var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
|
|
7445
7956
|
// 前后可以输入空格
|
|
7446
|
-
if (blockElement &&
|
|
7447
|
-
|
|
7957
|
+
if (blockElement &&
|
|
7958
|
+
!ignoreSpace &&
|
|
7959
|
+
blockElement.getAttribute("data-type") !== "code-block") {
|
|
7960
|
+
if ((isHrMD(blockElement.innerHTML) &&
|
|
7961
|
+
blockElement.previousElementSibling) ||
|
|
7448
7962
|
isHeadingMD(blockElement.innerHTML)) {
|
|
7449
7963
|
return;
|
|
7450
7964
|
}
|
|
@@ -7454,7 +7968,8 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7454
7968
|
var startSpace = true;
|
|
7455
7969
|
for (var i = startOffset - 1;
|
|
7456
7970
|
// 软换行后有空格
|
|
7457
|
-
i >
|
|
7971
|
+
i >
|
|
7972
|
+
blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
|
|
7458
7973
|
if (blockElement.textContent.charAt(i) !== " " &&
|
|
7459
7974
|
// 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
|
|
7460
7975
|
blockElement.textContent.charAt(i) !== "\t") {
|
|
@@ -7468,14 +7983,15 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7468
7983
|
// 结尾可以输入空格
|
|
7469
7984
|
var endSpace = true;
|
|
7470
7985
|
for (var i = startOffset - 1; i < blockElement.textContent.length; i++) {
|
|
7471
|
-
if (blockElement.textContent.charAt(i) !== " " &&
|
|
7986
|
+
if (blockElement.textContent.charAt(i) !== " " &&
|
|
7987
|
+
blockElement.textContent.charAt(i) !== "\n") {
|
|
7472
7988
|
endSpace = false;
|
|
7473
7989
|
break;
|
|
7474
7990
|
}
|
|
7475
7991
|
}
|
|
7476
7992
|
if (startSpace) {
|
|
7477
7993
|
if (typeof vditor.options.input === "function") {
|
|
7478
|
-
vditor.options.input(getMarkdown(vditor));
|
|
7994
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
7479
7995
|
}
|
|
7480
7996
|
return;
|
|
7481
7997
|
}
|
|
@@ -7489,19 +8005,24 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7489
8005
|
// inline marker space https://github.com/Vanessa219/vditor/issues/239
|
|
7490
8006
|
}
|
|
7491
8007
|
else {
|
|
7492
|
-
var previousNode = range.startContainer
|
|
7493
|
-
|
|
8008
|
+
var previousNode = range.startContainer
|
|
8009
|
+
.previousSibling;
|
|
8010
|
+
if (previousNode &&
|
|
8011
|
+
previousNode.nodeType !== 3 &&
|
|
8012
|
+
previousNode.classList.contains("vditor-ir__node--expand")) {
|
|
7494
8013
|
// FireFox https://github.com/Vanessa219/vditor/issues/239
|
|
7495
8014
|
previousNode.classList.remove("vditor-ir__node--expand");
|
|
7496
8015
|
}
|
|
7497
8016
|
if (typeof vditor.options.input === "function") {
|
|
7498
|
-
vditor.options.input(getMarkdown(vditor));
|
|
8017
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
7499
8018
|
}
|
|
7500
8019
|
return;
|
|
7501
8020
|
}
|
|
7502
8021
|
}
|
|
7503
8022
|
}
|
|
7504
|
-
vditor.ir.element
|
|
8023
|
+
vditor.ir.element
|
|
8024
|
+
.querySelectorAll(".vditor-ir__node--expand")
|
|
8025
|
+
.forEach(function (item) {
|
|
7505
8026
|
item.classList.remove("vditor-ir__node--expand");
|
|
7506
8027
|
});
|
|
7507
8028
|
if (!blockElement) {
|
|
@@ -7537,7 +8058,9 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7537
8058
|
blockElement = topListElement;
|
|
7538
8059
|
}
|
|
7539
8060
|
// 应到引用层,否则 > --- 会解析为 front-matter;列表中有 blockquote 则解析 blockquote;blockquote 中有列表则解析列表
|
|
7540
|
-
if (blockquoteElement &&
|
|
8061
|
+
if (blockquoteElement &&
|
|
8062
|
+
(!topListElement ||
|
|
8063
|
+
(topListElement && !blockquoteElement.contains(topListElement)))) {
|
|
7541
8064
|
blockElement = blockquoteElement;
|
|
7542
8065
|
}
|
|
7543
8066
|
// 修改脚注
|
|
@@ -7549,11 +8072,15 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7549
8072
|
// 如果为列表的话,需要把上下的列表都重绘
|
|
7550
8073
|
var listPrevElement = blockElement.previousElementSibling;
|
|
7551
8074
|
var listNextElement = blockElement.nextElementSibling;
|
|
7552
|
-
if (listPrevElement &&
|
|
8075
|
+
if (listPrevElement &&
|
|
8076
|
+
(listPrevElement.tagName === "UL" ||
|
|
8077
|
+
listPrevElement.tagName === "OL")) {
|
|
7553
8078
|
html = listPrevElement.outerHTML + html;
|
|
7554
8079
|
listPrevElement.remove();
|
|
7555
8080
|
}
|
|
7556
|
-
if (listNextElement &&
|
|
8081
|
+
if (listNextElement &&
|
|
8082
|
+
(listNextElement.tagName === "UL" ||
|
|
8083
|
+
listNextElement.tagName === "OL")) {
|
|
7557
8084
|
html = html + listNextElement.outerHTML;
|
|
7558
8085
|
listNextElement.remove();
|
|
7559
8086
|
}
|
|
@@ -7562,22 +8089,29 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7562
8089
|
}
|
|
7563
8090
|
else if (blockElement.previousElementSibling &&
|
|
7564
8091
|
blockElement.previousElementSibling.textContent.replace(constants/* Constants.ZWSP */.g.ZWSP, "") !== "" &&
|
|
7565
|
-
event &&
|
|
8092
|
+
event &&
|
|
8093
|
+
event.inputType === "insertParagraph") {
|
|
7566
8094
|
// 换行时需要处理上一段落
|
|
7567
8095
|
html = blockElement.previousElementSibling.outerHTML + html;
|
|
7568
8096
|
blockElement.previousElementSibling.remove();
|
|
7569
8097
|
}
|
|
7570
8098
|
if (!blockElement.innerText.startsWith("```")) {
|
|
7571
8099
|
// 添加链接引用
|
|
7572
|
-
vditor.ir.element
|
|
7573
|
-
|
|
8100
|
+
vditor.ir.element
|
|
8101
|
+
.querySelectorAll("[data-type='link-ref-defs-block']")
|
|
8102
|
+
.forEach(function (item) {
|
|
8103
|
+
if (item &&
|
|
8104
|
+
!blockElement.isEqualNode(item)) {
|
|
7574
8105
|
html += item.outerHTML;
|
|
7575
8106
|
item.remove();
|
|
7576
8107
|
}
|
|
7577
8108
|
});
|
|
7578
8109
|
// 添加脚注
|
|
7579
|
-
vditor.ir.element
|
|
7580
|
-
|
|
8110
|
+
vditor.ir.element
|
|
8111
|
+
.querySelectorAll("[data-type='footnotes-block']")
|
|
8112
|
+
.forEach(function (item) {
|
|
8113
|
+
if (item &&
|
|
8114
|
+
!blockElement.isEqualNode(item)) {
|
|
7581
8115
|
html += item.outerHTML;
|
|
7582
8116
|
item.remove();
|
|
7583
8117
|
}
|
|
@@ -7603,7 +8137,10 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7603
8137
|
var marker = footnoteItemText.substring(1, footnoteItemText.indexOf("]:"));
|
|
7604
8138
|
var footnoteRefElement = vditor.ir.element.querySelector("sup[data-type=\"footnotes-ref\"][data-footnotes-label=\"".concat(marker, "\"]"));
|
|
7605
8139
|
if (footnoteRefElement) {
|
|
7606
|
-
footnoteRefElement.setAttribute("aria-label", footnoteItemText
|
|
8140
|
+
footnoteRefElement.setAttribute("aria-label", footnoteItemText
|
|
8141
|
+
.substr(marker.length + 3)
|
|
8142
|
+
.trim()
|
|
8143
|
+
.substr(0, 24));
|
|
7607
8144
|
}
|
|
7608
8145
|
}
|
|
7609
8146
|
}
|
|
@@ -7639,7 +8176,9 @@ var input = function (vditor, range, ignoreSpace, event) {
|
|
|
7639
8176
|
vditor.ir.element.insertAdjacentElement("beforeend", allFootnoteElement[0]);
|
|
7640
8177
|
}
|
|
7641
8178
|
(0,selection/* setRangeByWbr */.ib)(vditor.ir.element, range);
|
|
7642
|
-
vditor.ir.element
|
|
8179
|
+
vditor.ir.element
|
|
8180
|
+
.querySelectorAll(".vditor-ir__preview[data-render='2']")
|
|
8181
|
+
.forEach(function (item) {
|
|
7643
8182
|
processCodeRender(item, vditor);
|
|
7644
8183
|
});
|
|
7645
8184
|
renderToc(vditor);
|
|
@@ -8020,18 +8559,22 @@ var inputEvent = function (vditor, event) {
|
|
|
8020
8559
|
var _a;
|
|
8021
8560
|
var range = getSelection().getRangeAt(0).cloneRange();
|
|
8022
8561
|
var startContainer = range.startContainer;
|
|
8023
|
-
if (range.startContainer.nodeType !== 3 &&
|
|
8562
|
+
if (range.startContainer.nodeType !== 3 &&
|
|
8563
|
+
range.startContainer.tagName === "DIV") {
|
|
8024
8564
|
startContainer = range.startContainer.childNodes[range.startOffset - 1];
|
|
8025
8565
|
}
|
|
8026
8566
|
var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-block", "0");
|
|
8027
8567
|
// 不调用 lute 解析
|
|
8028
|
-
if (blockElement &&
|
|
8568
|
+
if (blockElement &&
|
|
8569
|
+
event &&
|
|
8570
|
+
(event.inputType === "deleteContentBackward" || event.data === " ")) {
|
|
8029
8571
|
// 开始可以输入空格
|
|
8030
8572
|
var startOffset = (0,selection/* getSelectPosition */.im)(blockElement, vditor.sv.element, range).start;
|
|
8031
8573
|
var startSpace = true;
|
|
8032
8574
|
for (var i = startOffset - 1;
|
|
8033
8575
|
// 软换行后有空格
|
|
8034
|
-
i >
|
|
8576
|
+
i >
|
|
8577
|
+
blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
|
|
8035
8578
|
if (blockElement.textContent.charAt(i) !== " " &&
|
|
8036
8579
|
// 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
|
|
8037
8580
|
blockElement.textContent.charAt(i) !== "\t") {
|
|
@@ -8051,18 +8594,22 @@ var inputEvent = function (vditor, event) {
|
|
|
8051
8594
|
var codeBlockMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-open-marker") ||
|
|
8052
8595
|
(0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-close-marker");
|
|
8053
8596
|
if (codeBlockMarkerElement) {
|
|
8054
|
-
if (codeBlockMarkerElement.getAttribute("data-type") ===
|
|
8597
|
+
if (codeBlockMarkerElement.getAttribute("data-type") ===
|
|
8598
|
+
"code-block-close-marker") {
|
|
8055
8599
|
var openMarkerElement = getSideByType(startContainer, "code-block-open-marker");
|
|
8056
8600
|
if (openMarkerElement) {
|
|
8057
|
-
openMarkerElement.textContent =
|
|
8601
|
+
openMarkerElement.textContent =
|
|
8602
|
+
codeBlockMarkerElement.textContent;
|
|
8058
8603
|
processAfterRender(vditor);
|
|
8059
8604
|
return;
|
|
8060
8605
|
}
|
|
8061
8606
|
}
|
|
8062
|
-
if (codeBlockMarkerElement.getAttribute("data-type") ===
|
|
8607
|
+
if (codeBlockMarkerElement.getAttribute("data-type") ===
|
|
8608
|
+
"code-block-open-marker") {
|
|
8063
8609
|
var openMarkerElement = getSideByType(startContainer, "code-block-close-marker", false);
|
|
8064
8610
|
if (openMarkerElement) {
|
|
8065
|
-
openMarkerElement.textContent =
|
|
8611
|
+
openMarkerElement.textContent =
|
|
8612
|
+
codeBlockMarkerElement.textContent;
|
|
8066
8613
|
processAfterRender(vditor);
|
|
8067
8614
|
return;
|
|
8068
8615
|
}
|
|
@@ -8071,37 +8618,46 @@ var inputEvent = function (vditor, event) {
|
|
|
8071
8618
|
// https://github.com/Vanessa219/vditor/issues/877 数学公式输入删除生成节点
|
|
8072
8619
|
var mathBlockMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "math-block-open-marker");
|
|
8073
8620
|
if (mathBlockMarkerElement) {
|
|
8074
|
-
var mathBlockCloseElement = mathBlockMarkerElement.nextElementSibling
|
|
8075
|
-
|
|
8621
|
+
var mathBlockCloseElement = mathBlockMarkerElement.nextElementSibling
|
|
8622
|
+
.nextElementSibling;
|
|
8623
|
+
if (mathBlockCloseElement &&
|
|
8624
|
+
mathBlockCloseElement.getAttribute("data-type") ===
|
|
8625
|
+
"math-block-close-marker") {
|
|
8076
8626
|
mathBlockCloseElement.remove();
|
|
8077
8627
|
processAfterRender(vditor);
|
|
8078
8628
|
}
|
|
8079
8629
|
return;
|
|
8080
8630
|
}
|
|
8081
|
-
blockElement
|
|
8631
|
+
blockElement
|
|
8632
|
+
.querySelectorAll('[data-type="code-block-open-marker"]')
|
|
8633
|
+
.forEach(function (item) {
|
|
8082
8634
|
if (item.textContent.length === 1) {
|
|
8083
8635
|
item.remove();
|
|
8084
8636
|
}
|
|
8085
8637
|
});
|
|
8086
|
-
blockElement
|
|
8638
|
+
blockElement
|
|
8639
|
+
.querySelectorAll('[data-type="code-block-close-marker"]')
|
|
8640
|
+
.forEach(function (item) {
|
|
8087
8641
|
if (item.textContent.length === 1) {
|
|
8088
8642
|
item.remove();
|
|
8089
8643
|
}
|
|
8090
8644
|
});
|
|
8091
8645
|
// 标题删除
|
|
8092
8646
|
var headingElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "heading-marker");
|
|
8093
|
-
if (headingElement &&
|
|
8647
|
+
if (headingElement &&
|
|
8648
|
+
headingElement.textContent.indexOf("#") === -1) {
|
|
8094
8649
|
processAfterRender(vditor);
|
|
8095
8650
|
return;
|
|
8096
8651
|
}
|
|
8097
8652
|
}
|
|
8098
8653
|
// 删除或空格不解析,否则会 format 回去
|
|
8099
|
-
if ((event.data === " " ||
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8654
|
+
if ((event.data === " " ||
|
|
8655
|
+
event.inputType === "deleteContentBackward") &&
|
|
8656
|
+
((0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "padding") || // 场景:b 前进行删除 [> 1. a\n> b]
|
|
8657
|
+
(0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "li-marker") || // 场景:删除最后一个字符 [* 1\n* ]
|
|
8658
|
+
(0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "task-marker") || // 场景:删除最后一个字符 [* [ ] ]
|
|
8659
|
+
(0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "blockquote-marker")) // 场景:删除最后一个字符 [> ]
|
|
8660
|
+
) {
|
|
8105
8661
|
processAfterRender(vditor);
|
|
8106
8662
|
return;
|
|
8107
8663
|
}
|
|
@@ -8114,7 +8670,8 @@ var inputEvent = function (vditor, event) {
|
|
|
8114
8670
|
if (!blockElement) {
|
|
8115
8671
|
blockElement = vditor.sv.element;
|
|
8116
8672
|
}
|
|
8117
|
-
if (((_a = blockElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.getAttribute("data-type")) ===
|
|
8673
|
+
if (((_a = blockElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.getAttribute("data-type")) ===
|
|
8674
|
+
"link-ref-defs-block") {
|
|
8118
8675
|
// 修改链接引用
|
|
8119
8676
|
blockElement = vditor.sv.element;
|
|
8120
8677
|
}
|
|
@@ -8129,9 +8686,11 @@ var inputEvent = function (vditor, event) {
|
|
|
8129
8686
|
}
|
|
8130
8687
|
// 清除浏览器自带的样式
|
|
8131
8688
|
blockElement.querySelectorAll("[style]").forEach(function (item) {
|
|
8689
|
+
// 不可前置,否则会影响 newline 的样式
|
|
8132
8690
|
item.removeAttribute("style");
|
|
8133
8691
|
});
|
|
8134
8692
|
blockElement.querySelectorAll("font").forEach(function (item) {
|
|
8693
|
+
// 不可前置,否则会影响光标的位置
|
|
8135
8694
|
item.outerHTML = item.innerHTML;
|
|
8136
8695
|
});
|
|
8137
8696
|
var html = blockElement.textContent;
|
|
@@ -8145,22 +8704,29 @@ var inputEvent = function (vditor, event) {
|
|
|
8145
8704
|
html = blockElement.previousElementSibling.textContent + html;
|
|
8146
8705
|
blockElement.previousElementSibling.remove();
|
|
8147
8706
|
}
|
|
8148
|
-
if (blockElement.previousElementSibling &&
|
|
8707
|
+
if (blockElement.previousElementSibling &&
|
|
8708
|
+
html.indexOf("---\n") === 0) {
|
|
8149
8709
|
// 确认 yaml-front 是否为首行
|
|
8150
8710
|
html = blockElement.previousElementSibling.textContent + html;
|
|
8151
8711
|
blockElement.previousElementSibling.remove();
|
|
8152
8712
|
}
|
|
8153
8713
|
// 添加链接引用
|
|
8154
8714
|
var footnotes_1 = "";
|
|
8155
|
-
vditor.sv.element
|
|
8156
|
-
|
|
8715
|
+
vditor.sv.element
|
|
8716
|
+
.querySelectorAll("[data-type='link-ref-defs-block']")
|
|
8717
|
+
.forEach(function (item, index) {
|
|
8718
|
+
if (item &&
|
|
8719
|
+
!blockElement.isEqualNode(item.parentElement)) {
|
|
8157
8720
|
footnotes_1 += item.parentElement.textContent + "\n";
|
|
8158
8721
|
item.parentElement.remove();
|
|
8159
8722
|
}
|
|
8160
8723
|
});
|
|
8161
8724
|
// 添加脚注到文章头,便于lute处理
|
|
8162
|
-
vditor.sv.element
|
|
8163
|
-
|
|
8725
|
+
vditor.sv.element
|
|
8726
|
+
.querySelectorAll("[data-type='footnotes-link']")
|
|
8727
|
+
.forEach(function (item, index) {
|
|
8728
|
+
if (item &&
|
|
8729
|
+
!blockElement.isEqualNode(item.parentElement)) {
|
|
8164
8730
|
footnotes_1 += item.parentElement.textContent + "\n";
|
|
8165
8731
|
item.parentElement.remove();
|
|
8166
8732
|
}
|
|
@@ -8174,7 +8740,9 @@ var inputEvent = function (vditor, event) {
|
|
|
8174
8740
|
else {
|
|
8175
8741
|
blockElement.outerHTML = html;
|
|
8176
8742
|
}
|
|
8177
|
-
vditor.sv.element
|
|
8743
|
+
vditor.sv.element
|
|
8744
|
+
.querySelectorAll("[data-type='link-ref-defs-block']")
|
|
8745
|
+
.forEach(function (item) {
|
|
8178
8746
|
vditor.sv.element.insertAdjacentElement("beforeend", item.parentElement);
|
|
8179
8747
|
});
|
|
8180
8748
|
// 合并脚注
|
|
@@ -8551,607 +9119,133 @@ var setTypewriterPosition = function (vditor) {
|
|
|
8551
9119
|
}
|
|
8552
9120
|
height = Math.min(window.innerHeight, height);
|
|
8553
9121
|
}
|
|
8554
|
-
else {
|
|
8555
|
-
height = vditor.element.clientHeight;
|
|
8556
|
-
}
|
|
8557
|
-
if (vditor.element.classList.contains("vditor--fullscreen")) {
|
|
8558
|
-
height = window.innerHeight;
|
|
8559
|
-
}
|
|
8560
|
-
// 由于 Firefox padding-bottom bug,只能使用 :after
|
|
8561
|
-
vditor[vditor.currentMode].element.style.setProperty("--editor-bottom", (height - vditor.toolbar.element.offsetHeight) / 2 + "px");
|
|
8562
|
-
};
|
|
8563
|
-
var resizeCb;
|
|
8564
|
-
// 解绑与窗口大小变化相关的监听器,避免重复绑定
|
|
8565
|
-
function UIUnbindListener() {
|
|
8566
|
-
window.removeEventListener("resize", resizeCb);
|
|
8567
|
-
}
|
|
8568
|
-
// 渲染后初始化:绑定 resize、设置打字机模式位置,并确定初始内容
|
|
8569
|
-
var afterRender = function (vditor) {
|
|
8570
|
-
setTypewriterPosition(vditor);
|
|
8571
|
-
UIUnbindListener();
|
|
8572
|
-
window.addEventListener("resize", (resizeCb = function () {
|
|
8573
|
-
setPadding(vditor);
|
|
8574
|
-
setTypewriterPosition(vditor);
|
|
8575
|
-
}));
|
|
8576
|
-
// set default value
|
|
8577
|
-
var initValue = (0,compatibility/* accessLocalStorage */.pK)() && localStorage.getItem(vditor.options.cache.id);
|
|
8578
|
-
if (!vditor.options.cache.enable || !initValue) {
|
|
8579
|
-
if (vditor.options.value) {
|
|
8580
|
-
initValue = vditor.options.value;
|
|
8581
|
-
}
|
|
8582
|
-
else if (vditor.originalInnerHTML) {
|
|
8583
|
-
initValue = vditor.lute.HTML2Md(vditor.originalInnerHTML);
|
|
8584
|
-
}
|
|
8585
|
-
else if (!vditor.options.cache.enable) {
|
|
8586
|
-
initValue = "";
|
|
8587
|
-
}
|
|
8588
|
-
}
|
|
8589
|
-
return initValue || "";
|
|
8590
|
-
};
|
|
8591
|
-
|
|
8592
|
-
;// CONCATENATED MODULE: ./src/ts/ir/highlightToolbarIR.ts
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8598
|
-
var highlightToolbarIR = function (vditor) {
|
|
8599
|
-
clearTimeout(vditor[vditor.currentMode].hlToolbarTimeoutId);
|
|
8600
|
-
vditor[vditor.currentMode].hlToolbarTimeoutId = window.setTimeout(function () {
|
|
8601
|
-
if (vditor[vditor.currentMode].element.getAttribute("contenteditable") === "false") {
|
|
8602
|
-
return;
|
|
8603
|
-
}
|
|
8604
|
-
if (!(0,selection/* selectIsEditor */.Gb)(vditor[vditor.currentMode].element)) {
|
|
8605
|
-
return;
|
|
8606
|
-
}
|
|
8607
|
-
removeCurrentToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
|
|
8608
|
-
enableToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
|
|
8609
|
-
var range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
8610
|
-
var typeElement = range.startContainer;
|
|
8611
|
-
if (range.startContainer.nodeType === 3) {
|
|
8612
|
-
typeElement = range.startContainer.parentElement;
|
|
8613
|
-
}
|
|
8614
|
-
if (typeElement.classList.contains("vditor-reset")) {
|
|
8615
|
-
typeElement = typeElement.childNodes[range.startOffset];
|
|
8616
|
-
}
|
|
8617
|
-
var headingElement = vditor.currentMode === "sv" ?
|
|
8618
|
-
(0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "heading") : (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(typeElement);
|
|
8619
|
-
if (headingElement) {
|
|
8620
|
-
setCurrentToolbar(vditor.toolbar.elements, ["headings"]);
|
|
8621
|
-
}
|
|
8622
|
-
var quoteElement = vditor.currentMode === "sv" ? (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "blockquote") :
|
|
8623
|
-
(0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "BLOCKQUOTE");
|
|
8624
|
-
if (quoteElement) {
|
|
8625
|
-
setCurrentToolbar(vditor.toolbar.elements, ["quote"]);
|
|
8626
|
-
}
|
|
8627
|
-
var strongElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "strong");
|
|
8628
|
-
if (strongElement) {
|
|
8629
|
-
setCurrentToolbar(vditor.toolbar.elements, ["bold"]);
|
|
8630
|
-
}
|
|
8631
|
-
var emElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "em");
|
|
8632
|
-
if (emElement) {
|
|
8633
|
-
setCurrentToolbar(vditor.toolbar.elements, ["italic"]);
|
|
8634
|
-
}
|
|
8635
|
-
var sElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "s");
|
|
8636
|
-
if (sElement) {
|
|
8637
|
-
setCurrentToolbar(vditor.toolbar.elements, ["strike"]);
|
|
8638
|
-
}
|
|
8639
|
-
var aElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "a");
|
|
8640
|
-
if (aElement) {
|
|
8641
|
-
setCurrentToolbar(vditor.toolbar.elements, ["link"]);
|
|
8642
|
-
}
|
|
8643
|
-
var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "LI");
|
|
8644
|
-
if (liElement) {
|
|
8645
|
-
if (liElement.classList.contains("vditor-task")) {
|
|
8646
|
-
setCurrentToolbar(vditor.toolbar.elements, ["check"]);
|
|
8647
|
-
}
|
|
8648
|
-
else if (liElement.parentElement.tagName === "OL") {
|
|
8649
|
-
setCurrentToolbar(vditor.toolbar.elements, ["ordered-list"]);
|
|
8650
|
-
}
|
|
8651
|
-
else if (liElement.parentElement.tagName === "UL") {
|
|
8652
|
-
setCurrentToolbar(vditor.toolbar.elements, ["list"]);
|
|
8653
|
-
}
|
|
8654
|
-
enableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
|
|
8655
|
-
}
|
|
8656
|
-
else {
|
|
8657
|
-
disableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
|
|
8658
|
-
}
|
|
8659
|
-
var codeBlockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "code-block");
|
|
8660
|
-
if (codeBlockElement) {
|
|
8661
|
-
disableToolbar(vditor.toolbar.elements, ["headings", "bold", "italic", "strike", "line", "quote",
|
|
8662
|
-
"list", "ordered-list", "check", "code", "inline-code", "upload", "link", "table", "record"]);
|
|
8663
|
-
setCurrentToolbar(vditor.toolbar.elements, ["code"]);
|
|
8664
|
-
}
|
|
8665
|
-
var codeElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "code");
|
|
8666
|
-
if (codeElement) {
|
|
8667
|
-
disableToolbar(vditor.toolbar.elements, ["headings", "bold", "italic", "strike", "line", "quote",
|
|
8668
|
-
"list", "ordered-list", "check", "code", "upload", "link", "table", "record"]);
|
|
8669
|
-
setCurrentToolbar(vditor.toolbar.elements, ["inline-code"]);
|
|
8670
|
-
}
|
|
8671
|
-
var tableElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "table");
|
|
8672
|
-
if (tableElement) {
|
|
8673
|
-
disableToolbar(vditor.toolbar.elements, ["headings", "list", "ordered-list", "check", "line",
|
|
8674
|
-
"quote", "code", "table"]);
|
|
8675
|
-
}
|
|
8676
|
-
}, 200);
|
|
8677
|
-
};
|
|
8678
|
-
|
|
8679
|
-
;// CONCATENATED MODULE: ./src/ts/util/attachLineNumbers.ts
|
|
8680
|
-
/**
|
|
8681
|
-
* 预处理 Markdown:构建块、无序列表、有序列表的行号索引。
|
|
8682
|
-
*/
|
|
8683
|
-
var prepareLineNumberIndex = function (sourceMarkdown) {
|
|
8684
|
-
var ZWSP = "\u200b";
|
|
8685
|
-
var normalize = function (text) {
|
|
8686
|
-
return text
|
|
8687
|
-
.replace(/\r\n|\r/g, "\n")
|
|
8688
|
-
.replace(new RegExp(ZWSP, "g"), "")
|
|
8689
|
-
.replace(/\u00a0/g, " ")
|
|
8690
|
-
.replace(/\u2006/g, "")
|
|
8691
|
-
.replace(/[\t\f\v ]+/g, " ");
|
|
8692
|
-
};
|
|
8693
|
-
var stripInlineMD = function (text) {
|
|
8694
|
-
return text
|
|
8695
|
-
.replace(/\\([*_`~])/g, "$1")
|
|
8696
|
-
.replace(/\*\*|__/g, "")
|
|
8697
|
-
.replace(/\*|_/g, "")
|
|
8698
|
-
.replace(/~~/g, "")
|
|
8699
|
-
.replace(/`+/g, "")
|
|
8700
|
-
.replace(/\\\(/g, "(")
|
|
8701
|
-
.replace(/\\\)/g, ")")
|
|
8702
|
-
.replace(/\\\[/g, "[")
|
|
8703
|
-
.replace(/\\\]/g, "]")
|
|
8704
|
-
.replace(/\$/g, "")
|
|
8705
|
-
.trim();
|
|
8706
|
-
};
|
|
8707
|
-
var stripInlineForList = function (text) {
|
|
8708
|
-
return stripInlineMD(text)
|
|
8709
|
-
.replace(/\$(?:\\.|[^$])*\$/g, "")
|
|
8710
|
-
.replace(/\\\([^)]*\\\)/g, "")
|
|
8711
|
-
.replace(/\\\[[^\]]*\\\]/g, "")
|
|
8712
|
-
.replace(/\\[a-zA-Z]+/g, "")
|
|
8713
|
-
.replace(/[{}]/g, "")
|
|
8714
|
-
.trim();
|
|
8715
|
-
};
|
|
8716
|
-
var srcLines = normalize(sourceMarkdown).split("\n");
|
|
8717
|
-
var strippedLines = srcLines.map(function (l) { return stripInlineMD(l); });
|
|
8718
|
-
var lineLookup = new Map();
|
|
8719
|
-
for (var i = 0; i < strippedLines.length; i++) {
|
|
8720
|
-
var key = strippedLines[i];
|
|
8721
|
-
if (!lineLookup.has(key)) {
|
|
8722
|
-
lineLookup.set(key, [i + 1]);
|
|
8723
|
-
}
|
|
8724
|
-
else {
|
|
8725
|
-
lineLookup.get(key).push(i + 1);
|
|
8726
|
-
}
|
|
8727
|
-
}
|
|
8728
|
-
var unorderedEntries = [];
|
|
8729
|
-
var unorderedLookup = new Map();
|
|
8730
|
-
for (var i = 0; i < srcLines.length; i++) {
|
|
8731
|
-
var raw = srcLines[i];
|
|
8732
|
-
var m = raw.match(/^\s*[*+-]\s+(?:\[(?: |x|X)\]\s+)?(.*)$/);
|
|
8733
|
-
if (m && typeof m[1] === "string") {
|
|
8734
|
-
var contentStripped = stripInlineForList(m[1]);
|
|
8735
|
-
unorderedEntries.push({ ln: i + 1, content: contentStripped });
|
|
8736
|
-
if (!unorderedLookup.has(contentStripped)) {
|
|
8737
|
-
unorderedLookup.set(contentStripped, [i + 1]);
|
|
8738
|
-
}
|
|
8739
|
-
else {
|
|
8740
|
-
unorderedLookup.get(contentStripped).push(i + 1);
|
|
8741
|
-
}
|
|
8742
|
-
}
|
|
8743
|
-
}
|
|
8744
|
-
var orderedEntries = [];
|
|
8745
|
-
var orderedLookup = new Map();
|
|
8746
|
-
var ORDERED_RE = /\s*\d+(?:[.)、.。]|[\uFF0E\uFF09\u3001])\s+(?:\[(?: |x|X)\]\s+)?(.*)/;
|
|
8747
|
-
for (var i = 0; i < srcLines.length; i++) {
|
|
8748
|
-
var raw = srcLines[i];
|
|
8749
|
-
var m = raw.match(new RegExp("^".concat(ORDERED_RE.source, "$")));
|
|
8750
|
-
if (m && typeof m[1] === "string") {
|
|
8751
|
-
var contentStripped = stripInlineForList(m[1]);
|
|
8752
|
-
orderedEntries.push({ ln: i + 1, content: contentStripped });
|
|
8753
|
-
if (!orderedLookup.has(contentStripped)) {
|
|
8754
|
-
orderedLookup.set(contentStripped, [i + 1]);
|
|
8755
|
-
}
|
|
8756
|
-
else {
|
|
8757
|
-
orderedLookup.get(contentStripped).push(i + 1);
|
|
8758
|
-
}
|
|
8759
|
-
}
|
|
9122
|
+
else {
|
|
9123
|
+
height = vditor.element.clientHeight;
|
|
8760
9124
|
}
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
9125
|
+
if (vditor.element.classList.contains("vditor--fullscreen")) {
|
|
9126
|
+
height = window.innerHeight;
|
|
9127
|
+
}
|
|
9128
|
+
// 由于 Firefox padding-bottom bug,只能使用 :after
|
|
9129
|
+
vditor[vditor.currentMode].element.style.setProperty("--editor-bottom", (height - vditor.toolbar.element.offsetHeight) / 2 + "px");
|
|
9130
|
+
};
|
|
9131
|
+
var resizeCb;
|
|
9132
|
+
// 解绑与窗口大小变化相关的监听器,避免重复绑定
|
|
9133
|
+
function UIUnbindListener() {
|
|
9134
|
+
window.removeEventListener("resize", resizeCb);
|
|
9135
|
+
}
|
|
9136
|
+
// 渲染后初始化:绑定 resize、设置打字机模式位置,并确定初始内容
|
|
9137
|
+
var afterRender = function (vditor) {
|
|
9138
|
+
setTypewriterPosition(vditor);
|
|
9139
|
+
UIUnbindListener();
|
|
9140
|
+
window.addEventListener("resize", (resizeCb = function () {
|
|
9141
|
+
setPadding(vditor);
|
|
9142
|
+
setTypewriterPosition(vditor);
|
|
9143
|
+
}));
|
|
9144
|
+
// set default value
|
|
9145
|
+
var initValue = (0,compatibility/* accessLocalStorage */.pK)() && localStorage.getItem(vditor.options.cache.id);
|
|
9146
|
+
if (!vditor.options.cache.enable || !initValue) {
|
|
9147
|
+
if (vditor.options.value) {
|
|
9148
|
+
initValue = vditor.options.value;
|
|
8774
9149
|
}
|
|
8775
|
-
else {
|
|
8776
|
-
|
|
9150
|
+
else if (vditor.originalInnerHTML) {
|
|
9151
|
+
initValue = vditor.lute.HTML2Md(vditor.originalInnerHTML);
|
|
9152
|
+
}
|
|
9153
|
+
else if (!vditor.options.cache.enable) {
|
|
9154
|
+
initValue = "";
|
|
8777
9155
|
}
|
|
8778
9156
|
}
|
|
8779
|
-
return
|
|
8780
|
-
srcLines: srcLines,
|
|
8781
|
-
strippedLines: strippedLines,
|
|
8782
|
-
lineLookup: lineLookup,
|
|
8783
|
-
unorderedEntries: unorderedEntries,
|
|
8784
|
-
unorderedLookup: unorderedLookup,
|
|
8785
|
-
orderedEntries: orderedEntries,
|
|
8786
|
-
orderedLookup: orderedLookup,
|
|
8787
|
-
orderedGroups: orderedGroups,
|
|
8788
|
-
};
|
|
9157
|
+
return initValue || "";
|
|
8789
9158
|
};
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
};
|
|
8803
|
-
var index = typeof sourceMarkdownOrIndex === "string"
|
|
8804
|
-
? prepareLineNumberIndex(sourceMarkdownOrIndex)
|
|
8805
|
-
: sourceMarkdownOrIndex;
|
|
8806
|
-
var srcLines = index.srcLines;
|
|
8807
|
-
var stripInlineMD = function (text) {
|
|
8808
|
-
return (text
|
|
8809
|
-
.replace(/\\([*_`~])/g, "$1")
|
|
8810
|
-
.replace(/\*\*|__/g, "")
|
|
8811
|
-
.replace(/\*|_/g, "")
|
|
8812
|
-
.replace(/~~/g, "")
|
|
8813
|
-
.replace(/`+/g, "")
|
|
8814
|
-
// 数学行内分隔符:保留内容,仅移除分隔符
|
|
8815
|
-
.replace(/\\\(/g, "(")
|
|
8816
|
-
.replace(/\\\)/g, ")")
|
|
8817
|
-
.replace(/\\\[/g, "[")
|
|
8818
|
-
.replace(/\\\]/g, "]")
|
|
8819
|
-
.replace(/\$/g, "")
|
|
8820
|
-
.trim());
|
|
8821
|
-
};
|
|
8822
|
-
var stripInlineForList = function (text) {
|
|
8823
|
-
return (stripInlineMD(text)
|
|
8824
|
-
// 移除 $...$(行内公式整体)
|
|
8825
|
-
.replace(/\$(?:\\.|[^$])*\$/g, "")
|
|
8826
|
-
// 移除 \(...\)、\[...\](行内/行间公式整体)
|
|
8827
|
-
.replace(/\\\([^)]*\\\)/g, "")
|
|
8828
|
-
.replace(/\\\[[^\]]*\\\]/g, "")
|
|
8829
|
-
// 去除通用 TeX 命令,如 \alpha、\mathbf 等
|
|
8830
|
-
.replace(/\\[a-zA-Z]+/g, "")
|
|
8831
|
-
// 去除多余大括号
|
|
8832
|
-
.replace(/[{}]/g, "")
|
|
8833
|
-
.trim());
|
|
8834
|
-
};
|
|
8835
|
-
var strippedLines = index.strippedLines;
|
|
8836
|
-
var lineLookup = index.lineLookup;
|
|
8837
|
-
var usedLines = new Set();
|
|
8838
|
-
var pickFirstUnused = function (candidates) {
|
|
8839
|
-
if (!candidates || candidates.length === 0)
|
|
8840
|
-
return -1;
|
|
8841
|
-
for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
|
|
8842
|
-
var ln = candidates_1[_i];
|
|
8843
|
-
if (!usedLines.has(ln))
|
|
8844
|
-
return ln;
|
|
9159
|
+
|
|
9160
|
+
;// CONCATENATED MODULE: ./src/ts/ir/highlightToolbarIR.ts
|
|
9161
|
+
|
|
9162
|
+
|
|
9163
|
+
|
|
9164
|
+
|
|
9165
|
+
|
|
9166
|
+
var highlightToolbarIR = function (vditor) {
|
|
9167
|
+
clearTimeout(vditor[vditor.currentMode].hlToolbarTimeoutId);
|
|
9168
|
+
vditor[vditor.currentMode].hlToolbarTimeoutId = window.setTimeout(function () {
|
|
9169
|
+
if (vditor[vditor.currentMode].element.getAttribute("contenteditable") === "false") {
|
|
9170
|
+
return;
|
|
8845
9171
|
}
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
var findLineNumberByText = function (text) {
|
|
8849
|
-
var stripped = stripInlineMD(text);
|
|
8850
|
-
var ln = pickFirstUnused(lineLookup.get(stripped));
|
|
8851
|
-
if (ln !== -1)
|
|
8852
|
-
return ln;
|
|
8853
|
-
for (var i = 0; i < strippedLines.length; i++) {
|
|
8854
|
-
if (!usedLines.has(i + 1) &&
|
|
8855
|
-
stripped &&
|
|
8856
|
-
strippedLines[i].indexOf(stripped) !== -1) {
|
|
8857
|
-
return i + 1;
|
|
8858
|
-
}
|
|
9172
|
+
if (!(0,selection/* selectIsEditor */.Gb)(vditor[vditor.currentMode].element)) {
|
|
9173
|
+
return;
|
|
8859
9174
|
}
|
|
8860
|
-
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
var unorderedListEntries = index.unorderedEntries;
|
|
8867
|
-
var unorderedLookup = index.unorderedLookup;
|
|
8868
|
-
/**
|
|
8869
|
-
* 从无序列表候选行中为给定文本选择一个行号。
|
|
8870
|
-
* 优先精确匹配(去标记后完全相同),否则回退到包含匹配。
|
|
8871
|
-
*/
|
|
8872
|
-
var pickFirstUnusedUnordered = function (candidates) {
|
|
8873
|
-
if (!candidates || candidates.length === 0)
|
|
8874
|
-
return -1;
|
|
8875
|
-
for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
|
|
8876
|
-
var ln = candidates_2[_i];
|
|
8877
|
-
if (!usedUnorderedLines.has(ln))
|
|
8878
|
-
return ln;
|
|
9175
|
+
removeCurrentToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
|
|
9176
|
+
enableToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
|
|
9177
|
+
var range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
9178
|
+
var typeElement = range.startContainer;
|
|
9179
|
+
if (range.startContainer.nodeType === 3) {
|
|
9180
|
+
typeElement = range.startContainer.parentElement;
|
|
8879
9181
|
}
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
var findUnorderedListLineNumber = function (text) {
|
|
8883
|
-
var stripped = stripInlineForList(text);
|
|
8884
|
-
// 先尝试精确匹配
|
|
8885
|
-
var exact = pickFirstUnusedUnordered(unorderedLookup.get(stripped));
|
|
8886
|
-
if (exact !== -1)
|
|
8887
|
-
return exact;
|
|
8888
|
-
// 回退到包含匹配
|
|
8889
|
-
for (var i = 0; i < unorderedListEntries.length; i++) {
|
|
8890
|
-
var entry = unorderedListEntries[i];
|
|
8891
|
-
if (usedUnorderedLines.has(entry.ln))
|
|
8892
|
-
continue;
|
|
8893
|
-
if (!stripped)
|
|
8894
|
-
continue;
|
|
8895
|
-
if (entry.content.indexOf(stripped) !== -1 ||
|
|
8896
|
-
stripped.indexOf(entry.content) !== -1) {
|
|
8897
|
-
return entry.ln;
|
|
8898
|
-
}
|
|
9182
|
+
if (typeElement.classList.contains("vditor-reset")) {
|
|
9183
|
+
typeElement = typeElement.childNodes[range.startOffset];
|
|
8899
9184
|
}
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
*/
|
|
8905
|
-
var usedOrderedLines = new Set();
|
|
8906
|
-
var orderedListEntries = index.orderedEntries;
|
|
8907
|
-
var orderedLookup = index.orderedLookup;
|
|
8908
|
-
var orderedGroups = index.orderedGroups;
|
|
8909
|
-
console.debug("[LineNumber][ol:index]", {
|
|
8910
|
-
total: orderedListEntries.length,
|
|
8911
|
-
});
|
|
8912
|
-
/**
|
|
8913
|
-
* 为给定文本在有序列表候选中选择行号,精确匹配优先,包含匹配回退。
|
|
8914
|
-
*/
|
|
8915
|
-
var pickFirstUnusedOrdered = function (candidates) {
|
|
8916
|
-
if (!candidates || candidates.length === 0)
|
|
8917
|
-
return -1;
|
|
8918
|
-
for (var _i = 0, candidates_3 = candidates; _i < candidates_3.length; _i++) {
|
|
8919
|
-
var ln = candidates_3[_i];
|
|
8920
|
-
if (!usedOrderedLines.has(ln))
|
|
8921
|
-
return ln;
|
|
9185
|
+
var headingElement = vditor.currentMode === "sv" ?
|
|
9186
|
+
(0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "heading") : (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(typeElement);
|
|
9187
|
+
if (headingElement) {
|
|
9188
|
+
setCurrentToolbar(vditor.toolbar.elements, ["headings"]);
|
|
8922
9189
|
}
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
var exact = pickFirstUnusedOrdered(orderedLookup.get(stripped));
|
|
8928
|
-
if (exact !== -1)
|
|
8929
|
-
return exact;
|
|
8930
|
-
for (var i = 0; i < orderedListEntries.length; i++) {
|
|
8931
|
-
var entry = orderedListEntries[i];
|
|
8932
|
-
if (usedOrderedLines.has(entry.ln))
|
|
8933
|
-
continue;
|
|
8934
|
-
if (!stripped)
|
|
8935
|
-
continue;
|
|
8936
|
-
if (entry.content.indexOf(stripped) !== -1 ||
|
|
8937
|
-
stripped.indexOf(entry.content) !== -1) {
|
|
8938
|
-
return entry.ln;
|
|
8939
|
-
}
|
|
9190
|
+
var quoteElement = vditor.currentMode === "sv" ? (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "blockquote") :
|
|
9191
|
+
(0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "BLOCKQUOTE");
|
|
9192
|
+
if (quoteElement) {
|
|
9193
|
+
setCurrentToolbar(vditor.toolbar.elements, ["quote"]);
|
|
8940
9194
|
}
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
};
|
|
8962
|
-
var blocks = root.querySelectorAll("[data-block]");
|
|
8963
|
-
blocks.forEach(function (el) {
|
|
8964
|
-
try {
|
|
8965
|
-
var container = el;
|
|
8966
|
-
var dataType = container.getAttribute("data-type") || "";
|
|
8967
|
-
if (dataType === "math-block" || dataType === "code-block") {
|
|
8968
|
-
// container.setAttribute("data-linenumber", "");
|
|
8969
|
-
return;
|
|
8970
|
-
}
|
|
8971
|
-
var text = container.textContent || "";
|
|
8972
|
-
var normText = normalize(text);
|
|
8973
|
-
// 跳过纯空白块
|
|
8974
|
-
if (!normText.trim()) {
|
|
8975
|
-
// container.setAttribute("data-linenumber", "");
|
|
8976
|
-
return;
|
|
8977
|
-
}
|
|
8978
|
-
var lineNumber = -1;
|
|
8979
|
-
var tag = container.tagName;
|
|
8980
|
-
if (tag === "BLOCKQUOTE") {
|
|
8981
|
-
var firstLine = normText.split("\n").find(function (l) { return l.trim().length > 0; }) ||
|
|
8982
|
-
normText;
|
|
8983
|
-
var stripped = stripInlineMD(firstLine);
|
|
8984
|
-
for (var i = 0; i < srcLines.length; i++) {
|
|
8985
|
-
if (usedLines.has(i + 1))
|
|
8986
|
-
continue;
|
|
8987
|
-
if (/^\s*>+\s/.test(srcLines[i])) {
|
|
8988
|
-
var content = stripInlineMD(srcLines[i].replace(/^\s*>+\s+/, ""));
|
|
8989
|
-
if (content.indexOf(stripped) !== -1) {
|
|
8990
|
-
lineNumber = i + 1;
|
|
8991
|
-
break;
|
|
8992
|
-
}
|
|
8993
|
-
}
|
|
8994
|
-
}
|
|
9195
|
+
var strongElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "strong");
|
|
9196
|
+
if (strongElement) {
|
|
9197
|
+
setCurrentToolbar(vditor.toolbar.elements, ["bold"]);
|
|
9198
|
+
}
|
|
9199
|
+
var emElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "em");
|
|
9200
|
+
if (emElement) {
|
|
9201
|
+
setCurrentToolbar(vditor.toolbar.elements, ["italic"]);
|
|
9202
|
+
}
|
|
9203
|
+
var sElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "s");
|
|
9204
|
+
if (sElement) {
|
|
9205
|
+
setCurrentToolbar(vditor.toolbar.elements, ["strike"]);
|
|
9206
|
+
}
|
|
9207
|
+
var aElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "a");
|
|
9208
|
+
if (aElement) {
|
|
9209
|
+
setCurrentToolbar(vditor.toolbar.elements, ["link"]);
|
|
9210
|
+
}
|
|
9211
|
+
var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "LI");
|
|
9212
|
+
if (liElement) {
|
|
9213
|
+
if (liElement.classList.contains("vditor-task")) {
|
|
9214
|
+
setCurrentToolbar(vditor.toolbar.elements, ["check"]);
|
|
8995
9215
|
}
|
|
8996
|
-
else {
|
|
8997
|
-
|
|
8998
|
-
normText;
|
|
8999
|
-
lineNumber = findLineNumberByText(firstLine);
|
|
9216
|
+
else if (liElement.parentElement.tagName === "OL") {
|
|
9217
|
+
setCurrentToolbar(vditor.toolbar.elements, ["ordered-list"]);
|
|
9000
9218
|
}
|
|
9001
|
-
if (
|
|
9002
|
-
|
|
9003
|
-
container.setAttribute("data-linenumber", String(lineNumber));
|
|
9219
|
+
else if (liElement.parentElement.tagName === "UL") {
|
|
9220
|
+
setCurrentToolbar(vditor.toolbar.elements, ["list"]);
|
|
9004
9221
|
}
|
|
9222
|
+
enableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
|
|
9005
9223
|
}
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
}
|
|
9009
|
-
});
|
|
9010
|
-
/**
|
|
9011
|
-
* 为所有 `ul` 下的每个直接 `li` 子元素追加 `data-linenumber`,不修改 `ul` 本身。
|
|
9012
|
-
* 支持多层嵌套与非文本起始节点(如加粗/行内代码)。
|
|
9013
|
-
*/
|
|
9014
|
-
var ulElements = root.querySelectorAll("ul");
|
|
9015
|
-
ulElements.forEach(function (ul) {
|
|
9016
|
-
try {
|
|
9017
|
-
var children = Array.from(ul.children);
|
|
9018
|
-
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
|
|
9019
|
-
var child = children_1[_i];
|
|
9020
|
-
if (child.tagName !== "LI")
|
|
9021
|
-
continue;
|
|
9022
|
-
var li = child;
|
|
9023
|
-
var rawText = getImmediateLiText(li);
|
|
9024
|
-
var norm = normalize(rawText);
|
|
9025
|
-
var firstLine = norm.split("\n").find(function (l) { return l.trim().length > 0; }) || norm;
|
|
9026
|
-
var ln = findUnorderedListLineNumber(firstLine);
|
|
9027
|
-
if (ln !== -1) {
|
|
9028
|
-
usedUnorderedLines.add(ln);
|
|
9029
|
-
li.setAttribute("data-linenumber", String(ln));
|
|
9030
|
-
}
|
|
9031
|
-
else {
|
|
9032
|
-
li.setAttribute("data-linenumber", "");
|
|
9033
|
-
}
|
|
9034
|
-
}
|
|
9224
|
+
else {
|
|
9225
|
+
disableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
|
|
9035
9226
|
}
|
|
9036
|
-
|
|
9037
|
-
|
|
9227
|
+
var codeBlockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "code-block");
|
|
9228
|
+
if (codeBlockElement) {
|
|
9229
|
+
disableToolbar(vditor.toolbar.elements, ["headings", "bold", "italic", "strike", "line", "quote",
|
|
9230
|
+
"list", "ordered-list", "check", "code", "inline-code", "upload", "link", "table", "record"]);
|
|
9231
|
+
setCurrentToolbar(vditor.toolbar.elements, ["code"]);
|
|
9038
9232
|
}
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
olElements.forEach(function (ol) {
|
|
9045
|
-
try {
|
|
9046
|
-
var currentGroupIdx = -1;
|
|
9047
|
-
var lastAssigned_1 = -1;
|
|
9048
|
-
var children = Array.from(ol.children);
|
|
9049
|
-
for (var _i = 0, children_2 = children; _i < children_2.length; _i++) {
|
|
9050
|
-
var child = children_2[_i];
|
|
9051
|
-
if (child.tagName !== "LI")
|
|
9052
|
-
continue;
|
|
9053
|
-
var li = child;
|
|
9054
|
-
var rawText = getImmediateLiText(li);
|
|
9055
|
-
var norm = normalize(rawText);
|
|
9056
|
-
var firstLine = norm.split("\n").find(function (l) { return l.trim().length > 0; }) || norm;
|
|
9057
|
-
var stripped0 = stripInlineForList(firstLine);
|
|
9058
|
-
var stripped = stripped0 || stripInlineMD(firstLine);
|
|
9059
|
-
var candidates = orderedLookup.get(stripped) || [];
|
|
9060
|
-
var available = candidates.filter(function (n) { return !usedOrderedLines.has(n); });
|
|
9061
|
-
var ln = findOrderedListLineNumber(firstLine);
|
|
9062
|
-
if (ln !== -1) {
|
|
9063
|
-
usedOrderedLines.add(ln);
|
|
9064
|
-
li.setAttribute("data-linenumber", String(ln));
|
|
9065
|
-
// 成功映射日志
|
|
9066
|
-
console.debug("[LineNumber][ol>li]", {
|
|
9067
|
-
text: firstLine,
|
|
9068
|
-
stripped: stripped,
|
|
9069
|
-
line: ln,
|
|
9070
|
-
});
|
|
9071
|
-
// 记录当前组
|
|
9072
|
-
for (var gi = 0; gi < orderedGroups.length; gi++) {
|
|
9073
|
-
if (orderedGroups[gi].includes(ln)) {
|
|
9074
|
-
currentGroupIdx = gi;
|
|
9075
|
-
break;
|
|
9076
|
-
}
|
|
9077
|
-
}
|
|
9078
|
-
lastAssigned_1 = ln;
|
|
9079
|
-
}
|
|
9080
|
-
else {
|
|
9081
|
-
// 顺序回退:基于当前组或猜测组,按序分配下一未使用行
|
|
9082
|
-
var assigned = -1;
|
|
9083
|
-
var pickNextFromGroup = function (gi) {
|
|
9084
|
-
if (gi < 0 || gi >= orderedGroups.length)
|
|
9085
|
-
return -1;
|
|
9086
|
-
var lines = orderedGroups[gi];
|
|
9087
|
-
// 优先从上次分配后续查找
|
|
9088
|
-
var startIdx = 0;
|
|
9089
|
-
if (lastAssigned_1 !== -1) {
|
|
9090
|
-
var idx = lines.indexOf(lastAssigned_1);
|
|
9091
|
-
startIdx = idx >= 0 ? idx + 1 : 0;
|
|
9092
|
-
}
|
|
9093
|
-
for (var k = startIdx; k < lines.length; k++) {
|
|
9094
|
-
var cand = lines[k];
|
|
9095
|
-
if (!usedOrderedLines.has(cand))
|
|
9096
|
-
return cand;
|
|
9097
|
-
}
|
|
9098
|
-
for (var k = 0; k < startIdx; k++) {
|
|
9099
|
-
var cand = lines[k];
|
|
9100
|
-
if (!usedOrderedLines.has(cand))
|
|
9101
|
-
return cand;
|
|
9102
|
-
}
|
|
9103
|
-
return -1;
|
|
9104
|
-
};
|
|
9105
|
-
if (currentGroupIdx !== -1) {
|
|
9106
|
-
assigned = pickNextFromGroup(currentGroupIdx);
|
|
9107
|
-
}
|
|
9108
|
-
if (assigned === -1) {
|
|
9109
|
-
// 猜测组:选择拥有可用行的首个组
|
|
9110
|
-
for (var gi = 0; gi < orderedGroups.length && assigned === -1; gi++) {
|
|
9111
|
-
var cand = pickNextFromGroup(gi);
|
|
9112
|
-
if (cand !== -1) {
|
|
9113
|
-
currentGroupIdx = gi;
|
|
9114
|
-
assigned = cand;
|
|
9115
|
-
}
|
|
9116
|
-
}
|
|
9117
|
-
}
|
|
9118
|
-
if (assigned !== -1) {
|
|
9119
|
-
usedOrderedLines.add(assigned);
|
|
9120
|
-
li.setAttribute("data-linenumber", String(assigned));
|
|
9121
|
-
console.debug("[LineNumber][ol>li][fallback-seq]", {
|
|
9122
|
-
text: firstLine,
|
|
9123
|
-
stripped: stripped,
|
|
9124
|
-
line: assigned,
|
|
9125
|
-
group: currentGroupIdx,
|
|
9126
|
-
});
|
|
9127
|
-
lastAssigned_1 = assigned;
|
|
9128
|
-
}
|
|
9129
|
-
else {
|
|
9130
|
-
li.setAttribute("data-linenumber", "");
|
|
9131
|
-
// 失败诊断日志
|
|
9132
|
-
console.warn("[LineNumber][ol>li][missing]", {
|
|
9133
|
-
text: firstLine,
|
|
9134
|
-
stripped: stripped,
|
|
9135
|
-
candidates: candidates,
|
|
9136
|
-
available: available,
|
|
9137
|
-
reason: !stripped0
|
|
9138
|
-
? "empty-after-strip"
|
|
9139
|
-
: candidates.length === 0
|
|
9140
|
-
? "no-index-candidates"
|
|
9141
|
-
: available.length === 0
|
|
9142
|
-
? "all-candidates-consumed"
|
|
9143
|
-
: "fallback-no-match",
|
|
9144
|
-
});
|
|
9145
|
-
}
|
|
9146
|
-
}
|
|
9147
|
-
}
|
|
9233
|
+
var codeElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "code");
|
|
9234
|
+
if (codeElement) {
|
|
9235
|
+
disableToolbar(vditor.toolbar.elements, ["headings", "bold", "italic", "strike", "line", "quote",
|
|
9236
|
+
"list", "ordered-list", "check", "code", "upload", "link", "table", "record"]);
|
|
9237
|
+
setCurrentToolbar(vditor.toolbar.elements, ["inline-code"]);
|
|
9148
9238
|
}
|
|
9149
|
-
|
|
9150
|
-
|
|
9239
|
+
var tableElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "table");
|
|
9240
|
+
if (tableElement) {
|
|
9241
|
+
disableToolbar(vditor.toolbar.elements, ["headings", "list", "ordered-list", "check", "line",
|
|
9242
|
+
"quote", "code", "table"]);
|
|
9151
9243
|
}
|
|
9152
|
-
});
|
|
9244
|
+
}, 200);
|
|
9153
9245
|
};
|
|
9154
9246
|
|
|
9247
|
+
// EXTERNAL MODULE: ./src/ts/util/attachLineNumbers.ts
|
|
9248
|
+
var attachLineNumbers = __webpack_require__(626);
|
|
9155
9249
|
;// CONCATENATED MODULE: ./src/ts/wysiwyg/afterRenderEvent.ts
|
|
9156
9250
|
|
|
9157
9251
|
|
|
@@ -9170,7 +9264,7 @@ var afterRenderEvent = function (vditor, options) {
|
|
|
9170
9264
|
if (vditor.wysiwyg.composingLock) {
|
|
9171
9265
|
return;
|
|
9172
9266
|
}
|
|
9173
|
-
var text = getMarkdown(vditor);
|
|
9267
|
+
var text = (0,getMarkdown/* getMarkdown */.O)(vditor);
|
|
9174
9268
|
if (typeof vditor.options.input === "function" && options.enableInput) {
|
|
9175
9269
|
vditor.options.input(text);
|
|
9176
9270
|
}
|
|
@@ -9190,8 +9284,9 @@ var afterRenderEvent = function (vditor, options) {
|
|
|
9190
9284
|
vditor.undo.addToUndoStack(vditor);
|
|
9191
9285
|
}
|
|
9192
9286
|
try {
|
|
9193
|
-
|
|
9194
|
-
|
|
9287
|
+
if (vditor.options.lineNumber) {
|
|
9288
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(vditor.wysiwyg.element, text);
|
|
9289
|
+
}
|
|
9195
9290
|
}
|
|
9196
9291
|
catch (_a) {
|
|
9197
9292
|
void 0;
|
|
@@ -9970,7 +10065,7 @@ var highlightToolbarWYSIWYG = function (vditor) {
|
|
|
9970
10065
|
}
|
|
9971
10066
|
}
|
|
9972
10067
|
if (typeof vditor.options.input === "function") {
|
|
9973
|
-
vditor.options.input(getMarkdown(vditor));
|
|
10068
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
9974
10069
|
}
|
|
9975
10070
|
};
|
|
9976
10071
|
var setAlign_1 = function (type) {
|
|
@@ -10247,7 +10342,7 @@ var highlightToolbarWYSIWYG = function (vditor) {
|
|
|
10247
10342
|
footnotesRefElement.setAttribute("data-footnotes-label", input_2.value);
|
|
10248
10343
|
}
|
|
10249
10344
|
if (typeof vditor.options.input === "function") {
|
|
10250
|
-
vditor.options.input(getMarkdown(vditor));
|
|
10345
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
10251
10346
|
}
|
|
10252
10347
|
};
|
|
10253
10348
|
input_2.onkeydown = function (event) {
|
|
@@ -10380,7 +10475,7 @@ var highlightToolbarWYSIWYG = function (vditor) {
|
|
|
10380
10475
|
input_3.oninput = function () {
|
|
10381
10476
|
headingElement.setAttribute("data-id", input_3.value);
|
|
10382
10477
|
if (typeof vditor.options.input === "function") {
|
|
10383
|
-
vditor.options.input(getMarkdown(vditor));
|
|
10478
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
10384
10479
|
}
|
|
10385
10480
|
};
|
|
10386
10481
|
input_3.onkeydown = function (event) {
|
|
@@ -10480,7 +10575,7 @@ var genLinkRefPopover = function (vditor, linkRefElement, range) {
|
|
|
10480
10575
|
linkRefElement.setAttribute("data-link-label", input1.value);
|
|
10481
10576
|
}
|
|
10482
10577
|
if (typeof vditor.options.input === "function") {
|
|
10483
|
-
vditor.options.input(getMarkdown(vditor));
|
|
10578
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
10484
10579
|
}
|
|
10485
10580
|
};
|
|
10486
10581
|
var inputWrap = document.createElement("span");
|
|
@@ -10713,7 +10808,7 @@ var genImagePopover = function (event, vditor) {
|
|
|
10713
10808
|
imgElement.setAttribute("alt", alt.value);
|
|
10714
10809
|
imgElement.setAttribute("title", title.value);
|
|
10715
10810
|
if (typeof vditor.options.input === "function") {
|
|
10716
|
-
vditor.options.input(getMarkdown(vditor));
|
|
10811
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
10717
10812
|
}
|
|
10718
10813
|
};
|
|
10719
10814
|
var inputWrap = document.createElement("span");
|
|
@@ -10797,6 +10892,7 @@ var highlightToolbar = function (vditor) {
|
|
|
10797
10892
|
;// CONCATENATED MODULE: ./src/ts/wysiwyg/renderDomByMd.ts
|
|
10798
10893
|
|
|
10799
10894
|
|
|
10895
|
+
|
|
10800
10896
|
var renderDomByMd = function (vditor, md, options) {
|
|
10801
10897
|
if (options === void 0) { options = {
|
|
10802
10898
|
enableAddUndoStack: true,
|
|
@@ -10805,10 +10901,20 @@ var renderDomByMd = function (vditor, md, options) {
|
|
|
10805
10901
|
}; }
|
|
10806
10902
|
var editorElement = vditor.wysiwyg.element;
|
|
10807
10903
|
editorElement.innerHTML = vditor.lute.Md2VditorDOM(md);
|
|
10808
|
-
editorElement
|
|
10904
|
+
editorElement
|
|
10905
|
+
.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']")
|
|
10906
|
+
.forEach(function (item) {
|
|
10809
10907
|
processCodeRender(item, vditor);
|
|
10810
10908
|
item.previousElementSibling.setAttribute("style", "display:none");
|
|
10811
10909
|
});
|
|
10910
|
+
if (vditor.options.lineNumber) {
|
|
10911
|
+
try {
|
|
10912
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(editorElement, md);
|
|
10913
|
+
}
|
|
10914
|
+
catch (_a) {
|
|
10915
|
+
void 0;
|
|
10916
|
+
}
|
|
10917
|
+
}
|
|
10812
10918
|
afterRenderEvent(vditor, options);
|
|
10813
10919
|
};
|
|
10814
10920
|
|
|
@@ -11243,7 +11349,7 @@ var setEditMode = function (vditor, type, event) {
|
|
|
11243
11349
|
if (typeof event !== "string") {
|
|
11244
11350
|
hidePanel(vditor, ["subToolbar", "hint"]);
|
|
11245
11351
|
event.preventDefault();
|
|
11246
|
-
markdownText = getMarkdown(vditor);
|
|
11352
|
+
markdownText = (0,getMarkdown/* getMarkdown */.O)(vditor);
|
|
11247
11353
|
}
|
|
11248
11354
|
else {
|
|
11249
11355
|
markdownText = event;
|
|
@@ -11429,7 +11535,7 @@ var getSelectText = function (editor, range) {
|
|
|
11429
11535
|
var focusEvent = function (vditor, editorElement) {
|
|
11430
11536
|
editorElement.addEventListener("focus", function () {
|
|
11431
11537
|
if (vditor.options.focus) {
|
|
11432
|
-
vditor.options.focus(getMarkdown(vditor));
|
|
11538
|
+
vditor.options.focus((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
11433
11539
|
}
|
|
11434
11540
|
hidePanel(vditor, ["subToolbar", "hint"]);
|
|
11435
11541
|
});
|
|
@@ -11460,7 +11566,7 @@ var blurEvent = function (vditor, editorElement) {
|
|
|
11460
11566
|
}
|
|
11461
11567
|
vditor[vditor.currentMode].range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
11462
11568
|
if (vditor.options.blur) {
|
|
11463
|
-
vditor.options.blur(getMarkdown(vditor));
|
|
11569
|
+
vditor.options.blur((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
11464
11570
|
}
|
|
11465
11571
|
});
|
|
11466
11572
|
};
|
|
@@ -11544,7 +11650,7 @@ var hotkeyEvent = function (vditor, editorElement) {
|
|
|
11544
11650
|
}
|
|
11545
11651
|
}
|
|
11546
11652
|
if (vditor.options.ctrlEnter && matchHotKey("⌘Enter", event)) {
|
|
11547
|
-
vditor.options.ctrlEnter(getMarkdown(vditor));
|
|
11653
|
+
vditor.options.ctrlEnter((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
11548
11654
|
event.preventDefault();
|
|
11549
11655
|
return;
|
|
11550
11656
|
}
|
|
@@ -11566,7 +11672,7 @@ var hotkeyEvent = function (vditor, editorElement) {
|
|
|
11566
11672
|
vditor.hint.element.style.display = "none";
|
|
11567
11673
|
}
|
|
11568
11674
|
else if (vditor.options.esc && !event.isComposing) {
|
|
11569
|
-
vditor.options.esc(getMarkdown(vditor));
|
|
11675
|
+
vditor.options.esc((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
11570
11676
|
}
|
|
11571
11677
|
event.preventDefault();
|
|
11572
11678
|
return;
|
|
@@ -11798,7 +11904,7 @@ var processAfterRender = function (vditor, options) {
|
|
|
11798
11904
|
vditor.hint.render(vditor);
|
|
11799
11905
|
}
|
|
11800
11906
|
vditor.preview.render(vditor);
|
|
11801
|
-
var text = getMarkdown(vditor);
|
|
11907
|
+
var text = (0,getMarkdown/* getMarkdown */.O)(vditor);
|
|
11802
11908
|
if (typeof vditor.options.input === "function" && options.enableInput) {
|
|
11803
11909
|
vditor.options.input(text);
|
|
11804
11910
|
}
|
|
@@ -11820,8 +11926,9 @@ var processAfterRender = function (vditor, options) {
|
|
|
11820
11926
|
vditor.undo.addToUndoStack(vditor);
|
|
11821
11927
|
}
|
|
11822
11928
|
try {
|
|
11823
|
-
|
|
11824
|
-
|
|
11929
|
+
if (vditor.options.lineNumber) {
|
|
11930
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(vditor.sv.element, text);
|
|
11931
|
+
}
|
|
11825
11932
|
}
|
|
11826
11933
|
catch (_a) {
|
|
11827
11934
|
void 0;
|
|
@@ -12261,18 +12368,19 @@ var input_input = function (vditor, range, event) {
|
|
|
12261
12368
|
// 使用顶级块元素,应使用 innerHTML
|
|
12262
12369
|
blockElement = vditor.wysiwyg.element;
|
|
12263
12370
|
}
|
|
12264
|
-
if (event &&
|
|
12265
|
-
|
|
12266
|
-
|
|
12267
|
-
|
|
12268
|
-
|
|
12269
|
-
|
|
12270
|
-
|
|
12271
|
-
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
||
|
|
12371
|
+
if ((event &&
|
|
12372
|
+
event.inputType !== "formatItalic" &&
|
|
12373
|
+
event.inputType !== "deleteByDrag" &&
|
|
12374
|
+
event.inputType !== "insertFromDrop" &&
|
|
12375
|
+
event.inputType !== "formatBold" &&
|
|
12376
|
+
event.inputType !== "formatRemove" &&
|
|
12377
|
+
event.inputType !== "formatStrikeThrough" &&
|
|
12378
|
+
event.inputType !== "insertUnorderedList" &&
|
|
12379
|
+
event.inputType !== "insertOrderedList" &&
|
|
12380
|
+
event.inputType !== "formatOutdent" &&
|
|
12381
|
+
event.inputType !== "formatIndent" &&
|
|
12382
|
+
event.inputType !== "") || // document.execCommand('unlink', false)
|
|
12383
|
+
!event) {
|
|
12276
12384
|
var previousAEmptyElement = previoueIsEmptyA(range.startContainer);
|
|
12277
12385
|
if (previousAEmptyElement) {
|
|
12278
12386
|
// 链接结尾回车不应该复制到下一行 https://github.com/Vanessa219/vditor/issues/163
|
|
@@ -12315,7 +12423,8 @@ var input_input = function (vditor, range, event) {
|
|
|
12315
12423
|
var blockquoteElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(range.startContainer, "BLOCKQUOTE");
|
|
12316
12424
|
if (blockquoteElement) {
|
|
12317
12425
|
// li 中有 blockquote 就只渲染 blockquote
|
|
12318
|
-
blockElement =
|
|
12426
|
+
blockElement =
|
|
12427
|
+
(0,hasClosest/* hasClosestBlock */.F9)(range.startContainer) || blockElement;
|
|
12319
12428
|
}
|
|
12320
12429
|
else {
|
|
12321
12430
|
blockElement = topListElement;
|
|
@@ -12326,15 +12435,20 @@ var input_input = function (vditor, range, event) {
|
|
|
12326
12435
|
blockElement = footnoteElement;
|
|
12327
12436
|
}
|
|
12328
12437
|
html_1 = blockElement.outerHTML;
|
|
12329
|
-
if (blockElement.tagName === "UL" ||
|
|
12438
|
+
if (blockElement.tagName === "UL" ||
|
|
12439
|
+
blockElement.tagName === "OL") {
|
|
12330
12440
|
// 如果为列表的话,需要把上下的列表都重绘
|
|
12331
12441
|
var listPrevElement = blockElement.previousElementSibling;
|
|
12332
12442
|
var listNextElement = blockElement.nextElementSibling;
|
|
12333
|
-
if (listPrevElement &&
|
|
12443
|
+
if (listPrevElement &&
|
|
12444
|
+
(listPrevElement.tagName === "UL" ||
|
|
12445
|
+
listPrevElement.tagName === "OL")) {
|
|
12334
12446
|
html_1 = listPrevElement.outerHTML + html_1;
|
|
12335
12447
|
listPrevElement.remove();
|
|
12336
12448
|
}
|
|
12337
|
-
if (listNextElement &&
|
|
12449
|
+
if (listNextElement &&
|
|
12450
|
+
(listNextElement.tagName === "UL" ||
|
|
12451
|
+
listNextElement.tagName === "OL")) {
|
|
12338
12452
|
html_1 = html_1 + listNextElement.outerHTML;
|
|
12339
12453
|
listNextElement.remove();
|
|
12340
12454
|
}
|
|
@@ -12343,15 +12457,21 @@ var input_input = function (vditor, range, event) {
|
|
|
12343
12457
|
}
|
|
12344
12458
|
if (!blockElement.innerText.startsWith("```")) {
|
|
12345
12459
|
// 添加链接引用
|
|
12346
|
-
vditor.wysiwyg.element
|
|
12347
|
-
|
|
12460
|
+
vditor.wysiwyg.element
|
|
12461
|
+
.querySelectorAll("[data-type='link-ref-defs-block']")
|
|
12462
|
+
.forEach(function (item) {
|
|
12463
|
+
if (item &&
|
|
12464
|
+
!blockElement.isEqualNode(item)) {
|
|
12348
12465
|
html_1 += item.outerHTML;
|
|
12349
12466
|
item.remove();
|
|
12350
12467
|
}
|
|
12351
12468
|
});
|
|
12352
12469
|
// 添加脚注
|
|
12353
|
-
vditor.wysiwyg.element
|
|
12354
|
-
|
|
12470
|
+
vditor.wysiwyg.element
|
|
12471
|
+
.querySelectorAll("[data-type='footnotes-block']")
|
|
12472
|
+
.forEach(function (item) {
|
|
12473
|
+
if (item &&
|
|
12474
|
+
!blockElement.isEqualNode(item)) {
|
|
12355
12475
|
html_1 += item.outerHTML;
|
|
12356
12476
|
item.remove();
|
|
12357
12477
|
}
|
|
@@ -12362,10 +12482,12 @@ var input_input = function (vditor, range, event) {
|
|
|
12362
12482
|
html_1 = blockElement.innerHTML;
|
|
12363
12483
|
}
|
|
12364
12484
|
// 合并多个 em, strong,s。以防止多个相同元素在一起时不满足 commonmark 规范,出现标记符
|
|
12365
|
-
html_1 = html_1
|
|
12485
|
+
html_1 = html_1
|
|
12486
|
+
.replace(/<\/(strong|b)><strong data-marker="\W{2}">/g, "")
|
|
12366
12487
|
.replace(/<\/(em|i)><em data-marker="\W{1}">/g, "")
|
|
12367
12488
|
.replace(/<\/(s|strike)><s data-marker="~{1,2}">/g, "");
|
|
12368
|
-
if (html_1 === '<p data-block="0">```<wbr></p>' &&
|
|
12489
|
+
if (html_1 === '<p data-block="0">```<wbr></p>' &&
|
|
12490
|
+
vditor.hint.recentLanguage) {
|
|
12369
12491
|
html_1 = '<p data-block="0">```<wbr></p>'.replace("```", "```" + vditor.hint.recentLanguage);
|
|
12370
12492
|
}
|
|
12371
12493
|
log("SpinVditorDOM", html_1, "argument", vditor.options.debugger);
|
|
@@ -12418,11 +12540,14 @@ var input_input = function (vditor, range, event) {
|
|
|
12418
12540
|
}
|
|
12419
12541
|
// 设置光标
|
|
12420
12542
|
(0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
|
|
12421
|
-
vditor.wysiwyg.element
|
|
12543
|
+
vditor.wysiwyg.element
|
|
12544
|
+
.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']")
|
|
12422
12545
|
.forEach(function (item) {
|
|
12423
12546
|
processCodeRender(item, vditor);
|
|
12424
12547
|
});
|
|
12425
|
-
if (event &&
|
|
12548
|
+
if (event &&
|
|
12549
|
+
(event.inputType === "deleteContentBackward" ||
|
|
12550
|
+
event.inputType === "deleteContentForward") &&
|
|
12426
12551
|
vditor.options.comment.enable) {
|
|
12427
12552
|
vditor.wysiwyg.triggerRemoveComment(vditor);
|
|
12428
12553
|
vditor.options.comment.adjustTop(vditor.wysiwyg.getComments(vditor, true));
|
|
@@ -12930,25 +13055,12 @@ var isHeadingMD = function (text) {
|
|
|
12930
13055
|
}
|
|
12931
13056
|
return false;
|
|
12932
13057
|
};
|
|
12933
|
-
|
|
12934
|
-
|
|
12935
13058
|
var execAfterRender = function (vditor, options) {
|
|
12936
13059
|
if (options === void 0) { options = {
|
|
12937
13060
|
enableAddUndoStack: true,
|
|
12938
13061
|
enableHint: false,
|
|
12939
13062
|
enableInput: true,
|
|
12940
13063
|
}; }
|
|
12941
|
-
try {
|
|
12942
|
-
var md = getMarkdown(vditor);
|
|
12943
|
-
var cached = vditor.lineNumberIndex;
|
|
12944
|
-
var same = cached &&
|
|
12945
|
-
Array.isArray(cached.srcLines) &&
|
|
12946
|
-
cached.srcLines.join("\n") === md;
|
|
12947
|
-
vditor.lineNumberIndex = same ? cached : prepareLineNumberIndex(md);
|
|
12948
|
-
}
|
|
12949
|
-
catch (_a) {
|
|
12950
|
-
vditor.lineNumberIndex = undefined;
|
|
12951
|
-
}
|
|
12952
13064
|
if (vditor.currentMode === "wysiwyg") {
|
|
12953
13065
|
afterRenderEvent(vditor, options);
|
|
12954
13066
|
}
|
|
@@ -14257,7 +14369,7 @@ var process_processAfterRender = function (vditor, options) {
|
|
|
14257
14369
|
if (vditor.ir.composingLock) {
|
|
14258
14370
|
return;
|
|
14259
14371
|
}
|
|
14260
|
-
var text = getMarkdown(vditor);
|
|
14372
|
+
var text = (0,getMarkdown/* getMarkdown */.O)(vditor);
|
|
14261
14373
|
if (typeof vditor.options.input === "function" && options.enableInput) {
|
|
14262
14374
|
vditor.options.input(text);
|
|
14263
14375
|
}
|
|
@@ -14277,8 +14389,9 @@ var process_processAfterRender = function (vditor, options) {
|
|
|
14277
14389
|
vditor.undo.addToUndoStack(vditor);
|
|
14278
14390
|
}
|
|
14279
14391
|
try {
|
|
14280
|
-
|
|
14281
|
-
|
|
14392
|
+
if (vditor.options.lineNumber) {
|
|
14393
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(vditor.ir.element, text);
|
|
14394
|
+
}
|
|
14282
14395
|
}
|
|
14283
14396
|
catch (_a) {
|
|
14284
14397
|
void 0;
|
|
@@ -14462,6 +14575,8 @@ var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
|
|
|
14462
14575
|
}
|
|
14463
14576
|
};
|
|
14464
14577
|
|
|
14578
|
+
// EXTERNAL MODULE: ./src/ts/util/code160to32.ts
|
|
14579
|
+
var code160to32 = __webpack_require__(105);
|
|
14465
14580
|
;// CONCATENATED MODULE: ./src/ts/hint/index.ts
|
|
14466
14581
|
var hint_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14467
14582
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -15020,7 +15135,7 @@ var IR = /** @class */ (function () {
|
|
|
15020
15135
|
|
|
15021
15136
|
var getHTML = function (vditor) {
|
|
15022
15137
|
if (vditor.currentMode === "sv") {
|
|
15023
|
-
return vditor.lute.Md2HTML(getMarkdown(vditor));
|
|
15138
|
+
return vditor.lute.Md2HTML((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
15024
15139
|
}
|
|
15025
15140
|
else if (vditor.currentMode === "wysiwyg") {
|
|
15026
15141
|
return vditor.lute.VditorDOM2HTML(vditor.wysiwyg.element.innerHTML);
|
|
@@ -15180,12 +15295,12 @@ var Preview = /** @class */ (function () {
|
|
|
15180
15295
|
this.previewElement.innerHTML = value;
|
|
15181
15296
|
return;
|
|
15182
15297
|
}
|
|
15183
|
-
if (getMarkdown(vditor).replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "") === "") {
|
|
15298
|
+
if ((0,getMarkdown/* getMarkdown */.O)(vditor).replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "") === "") {
|
|
15184
15299
|
this.previewElement.innerHTML = "";
|
|
15185
15300
|
return;
|
|
15186
15301
|
}
|
|
15187
15302
|
var renderStartTime = new Date().getTime();
|
|
15188
|
-
var markdownText = getMarkdown(vditor);
|
|
15303
|
+
var markdownText = (0,getMarkdown/* getMarkdown */.O)(vditor);
|
|
15189
15304
|
this.mdTimeoutId = window.setTimeout(function () {
|
|
15190
15305
|
if (vditor.options.preview.url) {
|
|
15191
15306
|
var xhr_1 = new XMLHttpRequest();
|
|
@@ -17718,7 +17833,8 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17718
17833
|
}
|
|
17719
17834
|
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-panel vditor-panel--none\">\n <button type=\"button\" aria-label=\"").concat(window.VditorI18n.comment, "\" class=\"vditor-icon vditor-tooltipped vditor-tooltipped__n\">\n <svg><use xlink:href=\"#vditor-icon-comment\"></use></svg>\n </button>\n</div>");
|
|
17720
17835
|
this.element = divElement.firstElementChild;
|
|
17721
|
-
this.popover = divElement.firstElementChild
|
|
17836
|
+
this.popover = divElement.firstElementChild
|
|
17837
|
+
.nextElementSibling;
|
|
17722
17838
|
this.selectPopover = divElement.lastElementChild;
|
|
17723
17839
|
this.bindEvent(vditor);
|
|
17724
17840
|
focusEvent(vditor, this.element);
|
|
@@ -17751,28 +17867,31 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17751
17867
|
item.setAttribute("data-cmtids", item.getAttribute("data-cmtids") + " " + id);
|
|
17752
17868
|
}
|
|
17753
17869
|
if (wrap) {
|
|
17754
|
-
if (item.nodeType !== 3 &&
|
|
17755
|
-
|
|
17756
|
-
|
|
17757
|
-
|
|
17870
|
+
if (item.nodeType !== 3 &&
|
|
17871
|
+
item.getAttribute("data-block") === "0" &&
|
|
17872
|
+
index === 0 &&
|
|
17873
|
+
rangeClone.startOffset > 0) {
|
|
17874
|
+
item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
|
|
17758
17875
|
blockStartElement = item;
|
|
17759
17876
|
}
|
|
17760
|
-
else if (item.nodeType !== 3 &&
|
|
17761
|
-
|
|
17762
|
-
|
|
17763
|
-
|
|
17764
|
-
|
|
17877
|
+
else if (item.nodeType !== 3 &&
|
|
17878
|
+
item.getAttribute("data-block") === "0" &&
|
|
17879
|
+
index === contents.childNodes.length - 1 &&
|
|
17880
|
+
rangeClone.endOffset <
|
|
17881
|
+
rangeClone.endContainer.textContent.length) {
|
|
17882
|
+
item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
|
|
17765
17883
|
blockEndElement = item;
|
|
17766
17884
|
}
|
|
17767
|
-
else if (item.nodeType !== 3 &&
|
|
17885
|
+
else if (item.nodeType !== 3 &&
|
|
17886
|
+
item.getAttribute("data-block") === "0") {
|
|
17768
17887
|
if (index === 0) {
|
|
17769
17888
|
removeStart = true;
|
|
17770
17889
|
}
|
|
17771
|
-
else if (index ===
|
|
17890
|
+
else if (index ===
|
|
17891
|
+
contents.childNodes.length - 1) {
|
|
17772
17892
|
removeEnd = true;
|
|
17773
17893
|
}
|
|
17774
|
-
item.innerHTML =
|
|
17775
|
-
"<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
|
|
17894
|
+
item.innerHTML = "<span class=\"vditor-comment\" data-cmtids=\"".concat(id, "\">").concat(item.innerHTML, "</span>");
|
|
17776
17895
|
}
|
|
17777
17896
|
else {
|
|
17778
17897
|
var commentElement = document.createElement("span");
|
|
@@ -17789,7 +17908,10 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17789
17908
|
startElement.insertAdjacentHTML("beforeend", blockStartElement.innerHTML);
|
|
17790
17909
|
blockStartElement.remove();
|
|
17791
17910
|
}
|
|
17792
|
-
else if (startElement.textContent
|
|
17911
|
+
else if (startElement.textContent
|
|
17912
|
+
.trim()
|
|
17913
|
+
.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
|
|
17914
|
+
removeStart) {
|
|
17793
17915
|
startElement.remove();
|
|
17794
17916
|
}
|
|
17795
17917
|
}
|
|
@@ -17799,7 +17921,10 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17799
17921
|
endElement.insertAdjacentHTML("afterbegin", blockEndElement.innerHTML);
|
|
17800
17922
|
blockEndElement.remove();
|
|
17801
17923
|
}
|
|
17802
|
-
else if (endElement.textContent
|
|
17924
|
+
else if (endElement.textContent
|
|
17925
|
+
.trim()
|
|
17926
|
+
.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
|
|
17927
|
+
removeEnd) {
|
|
17803
17928
|
endElement.remove();
|
|
17804
17929
|
}
|
|
17805
17930
|
}
|
|
@@ -17820,8 +17945,7 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17820
17945
|
if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
|
|
17821
17946
|
this.commentIds = [];
|
|
17822
17947
|
this.element.querySelectorAll(".vditor-comment").forEach(function (item) {
|
|
17823
|
-
_this.commentIds =
|
|
17824
|
-
_this.commentIds.concat(item.getAttribute("data-cmtids").split(" "));
|
|
17948
|
+
_this.commentIds = _this.commentIds.concat(item.getAttribute("data-cmtids").split(" "));
|
|
17825
17949
|
});
|
|
17826
17950
|
this.commentIds = Array.from(new Set(this.commentIds));
|
|
17827
17951
|
var comments_1 = [];
|
|
@@ -17844,7 +17968,9 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17844
17968
|
var s = new Set(b);
|
|
17845
17969
|
return a.filter(function (x) { return !s.has(x); });
|
|
17846
17970
|
};
|
|
17847
|
-
if (vditor.currentMode === "wysiwyg" &&
|
|
17971
|
+
if (vditor.currentMode === "wysiwyg" &&
|
|
17972
|
+
vditor.options.comment.enable &&
|
|
17973
|
+
vditor.wysiwyg.commentIds.length > 0) {
|
|
17848
17974
|
var oldIds = JSON.parse(JSON.stringify(this.commentIds));
|
|
17849
17975
|
this.getComments(vditor);
|
|
17850
17976
|
var removedIds = difference(oldIds, this.commentIds);
|
|
@@ -17878,7 +18004,9 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17878
18004
|
event.preventDefault();
|
|
17879
18005
|
var codeElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "CODE");
|
|
17880
18006
|
var codeEndElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.endContainer, "CODE");
|
|
17881
|
-
if (codeElement &&
|
|
18007
|
+
if (codeElement &&
|
|
18008
|
+
codeEndElement &&
|
|
18009
|
+
codeEndElement.isSameNode(codeElement)) {
|
|
17882
18010
|
var codeText = "";
|
|
17883
18011
|
if (codeElement.parentElement.tagName === "PRE") {
|
|
17884
18012
|
codeText = range.toString();
|
|
@@ -17908,7 +18036,10 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17908
18036
|
var first = el.firstElementChild;
|
|
17909
18037
|
return !!first && first.classList.contains("language-math");
|
|
17910
18038
|
};
|
|
17911
|
-
if (startPreview &&
|
|
18039
|
+
if (startPreview &&
|
|
18040
|
+
endPreview &&
|
|
18041
|
+
startPreview.isSameNode(endPreview) &&
|
|
18042
|
+
isMathPreview(startPreview)) {
|
|
17912
18043
|
event.clipboardData.setData("text/plain", range.toString());
|
|
17913
18044
|
event.clipboardData.setData("text/html", "");
|
|
17914
18045
|
return;
|
|
@@ -17922,14 +18053,16 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17922
18053
|
WYSIWYG.prototype.bindEvent = function (vditor) {
|
|
17923
18054
|
var _this = this;
|
|
17924
18055
|
this.unbindListener();
|
|
17925
|
-
window.addEventListener("scroll", this.scrollListener = function () {
|
|
18056
|
+
window.addEventListener("scroll", (this.scrollListener = function () {
|
|
17926
18057
|
hidePanel(vditor, ["hint"]);
|
|
17927
|
-
if (_this.popover.style.display !== "block" ||
|
|
18058
|
+
if (_this.popover.style.display !== "block" ||
|
|
18059
|
+
_this.selectPopover.style.display !== "block") {
|
|
17928
18060
|
return;
|
|
17929
18061
|
}
|
|
17930
18062
|
var top = parseInt(_this.popover.getAttribute("data-top"), 10);
|
|
17931
18063
|
if (vditor.options.height !== "auto") {
|
|
17932
|
-
if (vditor.options.toolbarConfig.pin &&
|
|
18064
|
+
if (vditor.options.toolbarConfig.pin &&
|
|
18065
|
+
vditor.toolbar.element.getBoundingClientRect().top === 0) {
|
|
17933
18066
|
var popoverTop = Math.max(window.scrollY - vditor.element.offsetTop - 8, Math.min(top - vditor.wysiwyg.element.scrollTop, _this.element.clientHeight - 21)) + "px";
|
|
17934
18067
|
if (_this.popover.style.display === "block") {
|
|
17935
18068
|
_this.popover.style.top = popoverTop;
|
|
@@ -17943,28 +18076,33 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17943
18076
|
else if (!vditor.options.toolbarConfig.pin) {
|
|
17944
18077
|
return;
|
|
17945
18078
|
}
|
|
17946
|
-
var popoverTop1 = Math.max(top,
|
|
18079
|
+
var popoverTop1 = Math.max(top, window.scrollY - vditor.element.offsetTop - 8) + "px";
|
|
17947
18080
|
if (_this.popover.style.display === "block") {
|
|
17948
18081
|
_this.popover.style.top = popoverTop1;
|
|
17949
18082
|
}
|
|
17950
18083
|
if (_this.selectPopover.style.display === "block") {
|
|
17951
18084
|
_this.selectPopover.style.top = popoverTop1;
|
|
17952
18085
|
}
|
|
17953
|
-
});
|
|
18086
|
+
}));
|
|
17954
18087
|
this.element.addEventListener("scroll", function () {
|
|
17955
18088
|
hidePanel(vditor, ["hint"]);
|
|
17956
|
-
if (vditor.options.comment &&
|
|
18089
|
+
if (vditor.options.comment &&
|
|
18090
|
+
vditor.options.comment.enable &&
|
|
18091
|
+
vditor.options.comment.scroll) {
|
|
17957
18092
|
vditor.options.comment.scroll(vditor.wysiwyg.element.scrollTop);
|
|
17958
18093
|
}
|
|
17959
18094
|
if (_this.popover.style.display !== "block") {
|
|
17960
18095
|
return;
|
|
17961
18096
|
}
|
|
17962
|
-
var top = parseInt(_this.popover.getAttribute("data-top"), 10) -
|
|
18097
|
+
var top = parseInt(_this.popover.getAttribute("data-top"), 10) -
|
|
18098
|
+
vditor.wysiwyg.element.scrollTop;
|
|
17963
18099
|
var max = -8;
|
|
17964
|
-
if (vditor.options.toolbarConfig.pin &&
|
|
18100
|
+
if (vditor.options.toolbarConfig.pin &&
|
|
18101
|
+
vditor.toolbar.element.getBoundingClientRect().top === 0) {
|
|
17965
18102
|
max = window.scrollY - vditor.element.offsetTop + max;
|
|
17966
18103
|
}
|
|
17967
|
-
var topPx = Math.max(max, Math.min(top, _this.element.clientHeight - 21)) +
|
|
18104
|
+
var topPx = Math.max(max, Math.min(top, _this.element.clientHeight - 21)) +
|
|
18105
|
+
"px";
|
|
17968
18106
|
_this.popover.style.top = topPx;
|
|
17969
18107
|
_this.selectPopover.style.top = topPx;
|
|
17970
18108
|
});
|
|
@@ -17980,7 +18118,8 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
17980
18118
|
blockElement.outerHTML = vditor.lute.SpinVditorDOM(blockElement.outerHTML);
|
|
17981
18119
|
}
|
|
17982
18120
|
else {
|
|
17983
|
-
vditor.wysiwyg.element.innerHTML =
|
|
18121
|
+
vditor.wysiwyg.element.innerHTML =
|
|
18122
|
+
vditor.lute.SpinVditorDOM(vditor.wysiwyg.element.innerHTML);
|
|
17984
18123
|
}
|
|
17985
18124
|
(0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
|
|
17986
18125
|
},
|
|
@@ -18003,7 +18142,8 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18003
18142
|
_this.composingLock = false;
|
|
18004
18143
|
});
|
|
18005
18144
|
this.element.addEventListener("input", function (event) {
|
|
18006
|
-
if (event.inputType === "deleteByDrag" ||
|
|
18145
|
+
if (event.inputType === "deleteByDrag" ||
|
|
18146
|
+
event.inputType === "insertFromDrop") {
|
|
18007
18147
|
// https://github.com/Vanessa219/vditor/issues/801 编辑器内容拖拽问题
|
|
18008
18148
|
return;
|
|
18009
18149
|
}
|
|
@@ -18012,7 +18152,10 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18012
18152
|
afterRenderEvent(vditor);
|
|
18013
18153
|
return;
|
|
18014
18154
|
}
|
|
18015
|
-
if (_this.composingLock ||
|
|
18155
|
+
if (_this.composingLock ||
|
|
18156
|
+
event.data === "‘" ||
|
|
18157
|
+
event.data === "“" ||
|
|
18158
|
+
event.data === "《") {
|
|
18016
18159
|
afterRenderEvent(vditor);
|
|
18017
18160
|
return;
|
|
18018
18161
|
}
|
|
@@ -18030,7 +18173,10 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18030
18173
|
var startOffset = (0,selection/* getSelectPosition */.im)(blockElement, vditor.wysiwyg.element, range).start;
|
|
18031
18174
|
// 开始可以输入空格
|
|
18032
18175
|
var startSpace = true;
|
|
18033
|
-
for (var i = startOffset - 1; i >
|
|
18176
|
+
for (var i = startOffset - 1; i >
|
|
18177
|
+
blockElement.textContent
|
|
18178
|
+
.substr(0, startOffset)
|
|
18179
|
+
.lastIndexOf("\n"); i--) {
|
|
18034
18180
|
if (blockElement.textContent.charAt(i) !== " " &&
|
|
18035
18181
|
// 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
|
|
18036
18182
|
blockElement.textContent.charAt(i) !== "\t") {
|
|
@@ -18044,7 +18190,8 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18044
18190
|
// 结尾可以输入空格
|
|
18045
18191
|
var endSpace = true;
|
|
18046
18192
|
for (var i = startOffset - 1; i < blockElement.textContent.length; i++) {
|
|
18047
|
-
if (blockElement.textContent.charAt(i) !== " " &&
|
|
18193
|
+
if (blockElement.textContent.charAt(i) !== " " &&
|
|
18194
|
+
blockElement.textContent.charAt(i) !== "\n") {
|
|
18048
18195
|
endSpace = false;
|
|
18049
18196
|
break;
|
|
18050
18197
|
}
|
|
@@ -18059,16 +18206,20 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18059
18206
|
renderToc(vditor);
|
|
18060
18207
|
headingElement.remove();
|
|
18061
18208
|
}
|
|
18062
|
-
if ((startSpace &&
|
|
18063
|
-
|
|
18064
|
-
|
|
18209
|
+
if ((startSpace &&
|
|
18210
|
+
blockElement.getAttribute("data-type") !== "code-block") ||
|
|
18211
|
+
endSpace ||
|
|
18212
|
+
isHeadingMD(blockElement.innerHTML) ||
|
|
18213
|
+
(isHrMD(blockElement.innerHTML) &&
|
|
18214
|
+
blockElement.previousElementSibling)) {
|
|
18065
18215
|
if (typeof vditor.options.input === "function") {
|
|
18066
|
-
vditor.options.input(getMarkdown(vditor));
|
|
18216
|
+
vditor.options.input((0,getMarkdown/* getMarkdown */.O)(vditor));
|
|
18067
18217
|
}
|
|
18068
18218
|
return;
|
|
18069
18219
|
}
|
|
18070
18220
|
// https://github.com/Vanessa219/vditor/issues/1565
|
|
18071
|
-
if (event.inputType === "insertParagraph" &&
|
|
18221
|
+
if (event.inputType === "insertParagraph" &&
|
|
18222
|
+
_this.element.innerHTML === "<p><br></p><p><br></p>") {
|
|
18072
18223
|
blockElement.previousElementSibling.remove();
|
|
18073
18224
|
}
|
|
18074
18225
|
input_input(vditor, range, event);
|
|
@@ -18113,11 +18264,15 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18113
18264
|
return;
|
|
18114
18265
|
}
|
|
18115
18266
|
var range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
18116
|
-
if (event.target.isEqualNode(_this.element) &&
|
|
18267
|
+
if (event.target.isEqualNode(_this.element) &&
|
|
18268
|
+
_this.element.lastElementChild &&
|
|
18269
|
+
range.collapsed) {
|
|
18117
18270
|
var lastRect = _this.element.lastElementChild.getBoundingClientRect();
|
|
18118
18271
|
if (event.y > lastRect.top + lastRect.height) {
|
|
18119
18272
|
if (_this.element.lastElementChild.tagName === "P" &&
|
|
18120
|
-
_this.element.lastElementChild.textContent
|
|
18273
|
+
_this.element.lastElementChild.textContent
|
|
18274
|
+
.trim()
|
|
18275
|
+
.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
|
|
18121
18276
|
range.selectNodeContents(_this.element.lastElementChild);
|
|
18122
18277
|
range.collapse(false);
|
|
18123
18278
|
}
|
|
@@ -18131,8 +18286,7 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18131
18286
|
// 点击后光标落于预览区,需展开代码块(无选区时)
|
|
18132
18287
|
var previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(event.target, "vditor-wysiwyg__preview");
|
|
18133
18288
|
if (!previewElement) {
|
|
18134
|
-
previewElement =
|
|
18135
|
-
(0,hasClosest/* hasClosestByClassName */.fb)((0,selection/* getEditorRange */.zh)(vditor).startContainer, "vditor-wysiwyg__preview");
|
|
18289
|
+
previewElement = (0,hasClosest/* hasClosestByClassName */.fb)((0,selection/* getEditorRange */.zh)(vditor).startContainer, "vditor-wysiwyg__preview");
|
|
18136
18290
|
}
|
|
18137
18291
|
if (previewElement) {
|
|
18138
18292
|
var hasSelection = getSelectText(vditor.wysiwyg.element).trim().length > 0;
|
|
@@ -18152,25 +18306,34 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18152
18306
|
scrollCenter(vditor);
|
|
18153
18307
|
}
|
|
18154
18308
|
if ((event.key === "Backspace" || event.key === "Delete") &&
|
|
18155
|
-
vditor.wysiwyg.element.innerHTML !== "" &&
|
|
18156
|
-
vditor.wysiwyg.element.
|
|
18157
|
-
|
|
18158
|
-
|
|
18309
|
+
vditor.wysiwyg.element.innerHTML !== "" &&
|
|
18310
|
+
vditor.wysiwyg.element.childNodes.length === 1 &&
|
|
18311
|
+
vditor.wysiwyg.element.firstElementChild &&
|
|
18312
|
+
vditor.wysiwyg.element.firstElementChild.tagName === "P" &&
|
|
18313
|
+
vditor.wysiwyg.element.firstElementChild
|
|
18314
|
+
.childElementCount === 0 &&
|
|
18315
|
+
(vditor.wysiwyg.element.textContent === "" ||
|
|
18316
|
+
vditor.wysiwyg.element.textContent === "\n")) {
|
|
18159
18317
|
// 为空时显示 placeholder
|
|
18160
18318
|
vditor.wysiwyg.element.innerHTML = "";
|
|
18161
18319
|
}
|
|
18162
18320
|
var range = (0,selection/* getEditorRange */.zh)(vditor);
|
|
18163
18321
|
if (event.key === "Backspace") {
|
|
18164
18322
|
// firefox headings https://github.com/Vanessa219/vditor/issues/211
|
|
18165
|
-
if ((0,compatibility/* isFirefox */.vU)() &&
|
|
18323
|
+
if ((0,compatibility/* isFirefox */.vU)() &&
|
|
18324
|
+
range.startContainer.textContent === "\n" &&
|
|
18325
|
+
range.startOffset === 1) {
|
|
18166
18326
|
range.startContainer.textContent = "";
|
|
18167
18327
|
}
|
|
18168
18328
|
}
|
|
18169
18329
|
// 没有被块元素包裹
|
|
18170
18330
|
modifyPre(vditor, range);
|
|
18171
18331
|
highlightToolbarWYSIWYG(vditor);
|
|
18172
|
-
if (event.key !== "ArrowDown" &&
|
|
18173
|
-
|
|
18332
|
+
if (event.key !== "ArrowDown" &&
|
|
18333
|
+
event.key !== "ArrowRight" &&
|
|
18334
|
+
event.key !== "Backspace" &&
|
|
18335
|
+
event.key !== "ArrowLeft" &&
|
|
18336
|
+
event.key !== "ArrowUp") {
|
|
18174
18337
|
return;
|
|
18175
18338
|
}
|
|
18176
18339
|
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
@@ -18178,11 +18341,14 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18178
18341
|
}
|
|
18179
18342
|
// 上下左右,删除遇到块预览的处理
|
|
18180
18343
|
var previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-wysiwyg__preview");
|
|
18181
|
-
if (!previewElement &&
|
|
18344
|
+
if (!previewElement &&
|
|
18345
|
+
range.startContainer.nodeType !== 3 &&
|
|
18346
|
+
range.startOffset > 0) {
|
|
18182
18347
|
// table 前删除遇到代码块
|
|
18183
18348
|
var blockRenderElement = range.startContainer;
|
|
18184
18349
|
if (blockRenderElement.classList.contains("vditor-wysiwyg__block")) {
|
|
18185
|
-
previewElement =
|
|
18350
|
+
previewElement =
|
|
18351
|
+
blockRenderElement.lastElementChild;
|
|
18186
18352
|
}
|
|
18187
18353
|
}
|
|
18188
18354
|
if (!previewElement) {
|
|
@@ -18190,7 +18356,8 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18190
18356
|
}
|
|
18191
18357
|
var previousElement = previewElement.previousElementSibling;
|
|
18192
18358
|
if (previousElement.style.display === "none") {
|
|
18193
|
-
if (event.key === "ArrowDown" ||
|
|
18359
|
+
if (event.key === "ArrowDown" ||
|
|
18360
|
+
event.key === "ArrowRight") {
|
|
18194
18361
|
showCode(previewElement, vditor);
|
|
18195
18362
|
}
|
|
18196
18363
|
else {
|
|
@@ -18216,7 +18383,8 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18216
18383
|
// 跳过渲染块,光标移动到下一个节点
|
|
18217
18384
|
if (nextNode.nodeType === 3) {
|
|
18218
18385
|
// inline
|
|
18219
|
-
while (nextNode.textContent.length === 0 &&
|
|
18386
|
+
while (nextNode.textContent.length === 0 &&
|
|
18387
|
+
nextNode.nextSibling) {
|
|
18220
18388
|
// https://github.com/Vanessa219/vditor/issues/100 2
|
|
18221
18389
|
nextNode = nextNode.nextSibling;
|
|
18222
18390
|
}
|
|
@@ -18293,6 +18461,8 @@ var src_extends = (undefined && undefined.__extends) || (function () {
|
|
|
18293
18461
|
|
|
18294
18462
|
|
|
18295
18463
|
|
|
18464
|
+
var LINE_HIGHLIGHT_CLASS = "vditor-line-highlight";
|
|
18465
|
+
var lineHighlightTimers = new WeakMap();
|
|
18296
18466
|
/**
|
|
18297
18467
|
* 设置所有 details 默认展开,并确保不影响内容展示与可访问性
|
|
18298
18468
|
*/
|
|
@@ -18411,7 +18581,74 @@ var Vditor = /** @class */ (function (_super) {
|
|
|
18411
18581
|
};
|
|
18412
18582
|
/** 获取 Markdown 内容 */
|
|
18413
18583
|
Vditor.prototype.getValue = function () {
|
|
18414
|
-
return getMarkdown(this.vditor);
|
|
18584
|
+
return (0,getMarkdown/* getMarkdown */.O)(this.vditor);
|
|
18585
|
+
};
|
|
18586
|
+
/**
|
|
18587
|
+
* 手动更新行号
|
|
18588
|
+
* - 读取当前模式下的 Markdown 文本并为对应编辑区域同步/节流写入 data-linenumber
|
|
18589
|
+
* - 依赖配置 `lineNumber: true`,关闭时直接跳过以提升性能
|
|
18590
|
+
* @param immediate 为 true 时立即更新;默认为节流更新以避免频繁调用
|
|
18591
|
+
*/
|
|
18592
|
+
Vditor.prototype.updateLineNumbers = function (immediate) {
|
|
18593
|
+
if (immediate === void 0) { immediate = false; }
|
|
18594
|
+
if (!this.vditor.options.lineNumber) {
|
|
18595
|
+
return;
|
|
18596
|
+
}
|
|
18597
|
+
var text = (0,getMarkdown/* getMarkdown */.O)(this.vditor);
|
|
18598
|
+
var root = this.vditor[this.vditor.currentMode].element;
|
|
18599
|
+
if (immediate) {
|
|
18600
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(root, text);
|
|
18601
|
+
}
|
|
18602
|
+
else {
|
|
18603
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocksThrottled */.g)(root, text);
|
|
18604
|
+
}
|
|
18605
|
+
};
|
|
18606
|
+
/**
|
|
18607
|
+
* 高亮指定行号对应的块元素
|
|
18608
|
+
* - 仅匹配拥有 `data-linenumber`/`data-lineNumber` 且值等于指定行号的元素
|
|
18609
|
+
* - 应用高亮样式并在约 500ms 后自动恢复
|
|
18610
|
+
* @param numbers 要高亮的行号数组
|
|
18611
|
+
*/
|
|
18612
|
+
Vditor.prototype.setLinehightNumbers = function (numbers) {
|
|
18613
|
+
if (!Array.isArray(numbers)) {
|
|
18614
|
+
return;
|
|
18615
|
+
}
|
|
18616
|
+
var valid = numbers
|
|
18617
|
+
.filter(function (n) { return typeof n === "number" && isFinite(n); })
|
|
18618
|
+
.map(function (n) { return String(Math.floor(n)); });
|
|
18619
|
+
if (valid.length === 0) {
|
|
18620
|
+
return;
|
|
18621
|
+
}
|
|
18622
|
+
var root = this.vditor[this.vditor.currentMode].element;
|
|
18623
|
+
var sel = valid
|
|
18624
|
+
.map(function (v) { return "[data-linenumber=\"".concat(v, "\"],[data-lineNumber=\"").concat(v, "\"]"); })
|
|
18625
|
+
.join(",");
|
|
18626
|
+
var nodeList = root.querySelectorAll(sel);
|
|
18627
|
+
if (nodeList.length === 0) {
|
|
18628
|
+
return;
|
|
18629
|
+
}
|
|
18630
|
+
var duration = 500;
|
|
18631
|
+
var apply = function () {
|
|
18632
|
+
nodeList.forEach(function (el) {
|
|
18633
|
+
var old = lineHighlightTimers.get(el);
|
|
18634
|
+
if (old) {
|
|
18635
|
+
clearTimeout(old);
|
|
18636
|
+
lineHighlightTimers.delete(el);
|
|
18637
|
+
}
|
|
18638
|
+
el.classList.remove(LINE_HIGHLIGHT_CLASS);
|
|
18639
|
+
});
|
|
18640
|
+
requestAnimationFrame(function () {
|
|
18641
|
+
nodeList.forEach(function (el) {
|
|
18642
|
+
el.classList.add(LINE_HIGHLIGHT_CLASS);
|
|
18643
|
+
var handle = window.setTimeout(function () {
|
|
18644
|
+
el.classList.remove(LINE_HIGHLIGHT_CLASS);
|
|
18645
|
+
lineHighlightTimers.delete(el);
|
|
18646
|
+
}, duration);
|
|
18647
|
+
lineHighlightTimers.set(el, handle);
|
|
18648
|
+
});
|
|
18649
|
+
});
|
|
18650
|
+
};
|
|
18651
|
+
apply();
|
|
18415
18652
|
};
|
|
18416
18653
|
/** 获取编辑器当前编辑模式 */
|
|
18417
18654
|
Vditor.prototype.getCurrentMode = function () {
|
|
@@ -18584,14 +18821,14 @@ var Vditor = /** @class */ (function (_super) {
|
|
|
18584
18821
|
Vditor.prototype.setValue = function (markdown, clearStack) {
|
|
18585
18822
|
var _this = this;
|
|
18586
18823
|
if (clearStack === void 0) { clearStack = false; }
|
|
18587
|
-
try {
|
|
18588
|
-
this.vditor.lineNumberIndex = prepareLineNumberIndex(markdown);
|
|
18589
|
-
}
|
|
18590
|
-
catch (_a) {
|
|
18591
|
-
this.vditor.lineNumberIndex = undefined;
|
|
18592
|
-
}
|
|
18593
18824
|
if (this.vditor.currentMode === "sv") {
|
|
18594
18825
|
this.vditor.sv.element.innerHTML = "<div data-block='0'>".concat(this.vditor.lute.SpinVditorSVDOM(markdown), "</div>");
|
|
18826
|
+
if (this.vditor.options.lineNumber) {
|
|
18827
|
+
try {
|
|
18828
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(this.vditor.sv.element, markdown || "");
|
|
18829
|
+
}
|
|
18830
|
+
catch (_a) { }
|
|
18831
|
+
}
|
|
18595
18832
|
processAfterRender(this.vditor, {
|
|
18596
18833
|
enableAddUndoStack: true,
|
|
18597
18834
|
enableHint: false,
|
|
@@ -18613,6 +18850,12 @@ var Vditor = /** @class */ (function (_super) {
|
|
|
18613
18850
|
.forEach(function (item) {
|
|
18614
18851
|
processCodeRender(item, _this.vditor);
|
|
18615
18852
|
});
|
|
18853
|
+
if (this.vditor.options.lineNumber) {
|
|
18854
|
+
try {
|
|
18855
|
+
(0,attachLineNumbers/* attachLineNumbersToBlocks */.t)(this.vditor.ir.element, markdown || "");
|
|
18856
|
+
}
|
|
18857
|
+
catch (_b) { }
|
|
18858
|
+
}
|
|
18616
18859
|
process_processAfterRender(this.vditor, {
|
|
18617
18860
|
enableAddUndoStack: true,
|
|
18618
18861
|
enableHint: false,
|