@yltrcc/vditor 0.0.1 → 0.0.3
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 +15 -2
- package/dist/index.js +183 -4
- package/dist/index.min.js +1 -1
- package/dist/method.js +3 -3
- package/dist/method.min.js +1 -1
- package/dist/ts/markdown/docLink.d.ts +33 -0
- package/dist/types/index.d.ts +13 -0
- package/package.json +3 -3
- package/src/assets/less/_content.less +16 -0
- package/src/ts/constants.ts +1 -1
- package/src/ts/markdown/docLink.ts +171 -0
- package/src/ts/preview/index.ts +7 -0
- package/src/ts/toolbar/Info.ts +2 -2
- package/src/ts/undo/index.ts +270 -270
- package/src/ts/wysiwyg/afterRenderEvent.ts +6 -0
- package/src/ts/wysiwyg/index.ts +14 -0
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.3 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
/*!
|
|
28
|
-
* Vditor v0.0.
|
|
28
|
+
* Vditor v0.0.3 - A markdown editor written in TypeScript.
|
|
29
29
|
*
|
|
30
30
|
* MIT License
|
|
31
31
|
*
|
|
@@ -700,6 +700,19 @@
|
|
|
700
700
|
.vditor-tip__close:hover {
|
|
701
701
|
color: var(--toolbar-icon-hover-color);
|
|
702
702
|
}
|
|
703
|
+
.vditor-doclink {
|
|
704
|
+
color: #4285f4;
|
|
705
|
+
cursor: pointer;
|
|
706
|
+
text-decoration: underline;
|
|
707
|
+
background-color: rgba(66, 133, 244, 0.1);
|
|
708
|
+
padding: 2px 6px;
|
|
709
|
+
border-radius: 3px;
|
|
710
|
+
transition: all 0.15s ease-in-out;
|
|
711
|
+
}
|
|
712
|
+
.vditor-doclink:hover {
|
|
713
|
+
background-color: rgba(66, 133, 244, 0.2);
|
|
714
|
+
color: #1266f1;
|
|
715
|
+
}
|
|
703
716
|
.vditor-img {
|
|
704
717
|
position: fixed;
|
|
705
718
|
top: 0;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.3 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -1051,6 +1051,158 @@ var insertHTML = function (html, vditor) {
|
|
|
1051
1051
|
};
|
|
1052
1052
|
|
|
1053
1053
|
|
|
1054
|
+
/***/ },
|
|
1055
|
+
|
|
1056
|
+
/***/ 234
|
|
1057
|
+
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1058
|
+
|
|
1059
|
+
"use strict";
|
|
1060
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1061
|
+
/* harmony export */ BS: () => (/* binding */ renderDocLink),
|
|
1062
|
+
/* harmony export */ handleDocLinkClick: () => (/* binding */ handleDocLinkClick),
|
|
1063
|
+
/* harmony export */ qo: () => (/* binding */ processDocLinkInWYSIWYG)
|
|
1064
|
+
/* harmony export */ });
|
|
1065
|
+
/* unused harmony exports extractDocLinks, hasDocLink */
|
|
1066
|
+
/**
|
|
1067
|
+
* 文档链接支持
|
|
1068
|
+
* 将 ((文档ID '显示文本')) 语法渲染为可点击的文档链接
|
|
1069
|
+
*/
|
|
1070
|
+
// 文档链接正则表达式
|
|
1071
|
+
var DOCLINK_REGEX = /\(\((\d+)\s+'([^']+)'\)\)/g;
|
|
1072
|
+
/**
|
|
1073
|
+
* 在 HTML 中渲染文档链接
|
|
1074
|
+
* 将 ((id 'text')) 转换为可点击的 span 元素
|
|
1075
|
+
*/
|
|
1076
|
+
var renderDocLink = function (html, vditor) {
|
|
1077
|
+
var _a, _b;
|
|
1078
|
+
// 如果禁用了 citation,直接返回原文
|
|
1079
|
+
if (((_b = (_a = vditor === null || vditor === void 0 ? void 0 : vditor.options) === null || _a === void 0 ? void 0 : _a.citation) === null || _b === void 0 ? void 0 : _b.enable) === false) {
|
|
1080
|
+
return html;
|
|
1081
|
+
}
|
|
1082
|
+
return html.replace(DOCLINK_REGEX, '<span class="vditor-doclink" data-doc-id="$1" data-doc-text="$2">$2</span>');
|
|
1083
|
+
};
|
|
1084
|
+
/**
|
|
1085
|
+
* 在 WYSIWYG 编辑器中处理文档链接的实时渲染
|
|
1086
|
+
*/
|
|
1087
|
+
var processDocLinkInWYSIWYG = function (element, vditor) {
|
|
1088
|
+
var _a, _b, _c;
|
|
1089
|
+
// 如果禁用了 citation,不处理
|
|
1090
|
+
if (((_b = (_a = vditor === null || vditor === void 0 ? void 0 : vditor.options) === null || _a === void 0 ? void 0 : _a.citation) === null || _b === void 0 ? void 0 : _b.enable) === false) {
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
var walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null);
|
|
1094
|
+
var textNodes = [];
|
|
1095
|
+
var node;
|
|
1096
|
+
while ((node = walker.nextNode())) {
|
|
1097
|
+
// 排除已经在 vditor-doclink 中的文本节点
|
|
1098
|
+
if (!((_c = node.parentElement) === null || _c === void 0 ? void 0 : _c.classList.contains("vditor-doclink"))) {
|
|
1099
|
+
textNodes.push(node);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
textNodes.forEach(function (textNode) {
|
|
1103
|
+
var text = textNode.textContent || "";
|
|
1104
|
+
var matches = [];
|
|
1105
|
+
// 查找所有匹配
|
|
1106
|
+
var match;
|
|
1107
|
+
var regex = new RegExp(DOCLINK_REGEX.source, "g");
|
|
1108
|
+
while ((match = regex.exec(text)) !== null) {
|
|
1109
|
+
matches.push({
|
|
1110
|
+
index: match.index,
|
|
1111
|
+
length: match[0].length,
|
|
1112
|
+
id: match[1],
|
|
1113
|
+
text: match[2]
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
if (matches.length === 0)
|
|
1117
|
+
return;
|
|
1118
|
+
var parent = textNode.parentNode;
|
|
1119
|
+
if (!parent)
|
|
1120
|
+
return;
|
|
1121
|
+
// 构建新的节点列表
|
|
1122
|
+
var lastIndex = 0;
|
|
1123
|
+
var fragments = [];
|
|
1124
|
+
matches.forEach(function (m) {
|
|
1125
|
+
// 添加匹配前的文本
|
|
1126
|
+
if (m.index > lastIndex) {
|
|
1127
|
+
fragments.push(document.createTextNode(text.slice(lastIndex, m.index)));
|
|
1128
|
+
}
|
|
1129
|
+
// 创建文档链接元素
|
|
1130
|
+
var span = document.createElement("span");
|
|
1131
|
+
span.className = "vditor-doclink";
|
|
1132
|
+
span.setAttribute("data-doc-id", m.id);
|
|
1133
|
+
span.setAttribute("data-doc-text", m.text);
|
|
1134
|
+
span.textContent = m.text;
|
|
1135
|
+
// 绑定点击事件
|
|
1136
|
+
span.onclick = function (e) {
|
|
1137
|
+
e.preventDefault();
|
|
1138
|
+
e.stopPropagation();
|
|
1139
|
+
handleDocLinkClick(m.id, m.text, vditor);
|
|
1140
|
+
};
|
|
1141
|
+
fragments.push(span);
|
|
1142
|
+
lastIndex = m.index + m.length;
|
|
1143
|
+
});
|
|
1144
|
+
// 添加剩余文本
|
|
1145
|
+
if (lastIndex < text.length) {
|
|
1146
|
+
fragments.push(document.createTextNode(text.slice(lastIndex)));
|
|
1147
|
+
}
|
|
1148
|
+
// 替换原节点
|
|
1149
|
+
fragments.forEach(function (frag) {
|
|
1150
|
+
parent.insertBefore(frag, textNode);
|
|
1151
|
+
});
|
|
1152
|
+
parent.removeChild(textNode);
|
|
1153
|
+
});
|
|
1154
|
+
};
|
|
1155
|
+
/**
|
|
1156
|
+
* 处理文档链接点击事件
|
|
1157
|
+
*/
|
|
1158
|
+
var handleDocLinkClick = function (docId, text, vditor) {
|
|
1159
|
+
var _a, _b, _c, _d;
|
|
1160
|
+
// 优先使用配置中的 click 回调
|
|
1161
|
+
if ((_b = (_a = vditor === null || vditor === void 0 ? void 0 : vditor.options) === null || _a === void 0 ? void 0 : _a.citation) === null || _b === void 0 ? void 0 : _b.click) {
|
|
1162
|
+
vditor.options.citation.click(docId, text);
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
// 使用全局回调(兼容旧版本)
|
|
1166
|
+
if (window.handleDocLinkClick) {
|
|
1167
|
+
window.handleDocLinkClick(docId);
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
// 配置了 URL,自动请求
|
|
1171
|
+
var url = (_d = (_c = vditor === null || vditor === void 0 ? void 0 : vditor.options) === null || _c === void 0 ? void 0 : _c.citation) === null || _d === void 0 ? void 0 : _d.url;
|
|
1172
|
+
if (url) {
|
|
1173
|
+
fetch("".concat(url, "/").concat(docId))
|
|
1174
|
+
.then(function (r) { return r.json(); })
|
|
1175
|
+
.then(function (data) {
|
|
1176
|
+
console.log('Citation data:', data);
|
|
1177
|
+
})
|
|
1178
|
+
.catch(function (err) {
|
|
1179
|
+
console.error('Failed to fetch citation:', err);
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
/**
|
|
1184
|
+
* 从 Markdown 文本中提取文档链接
|
|
1185
|
+
*/
|
|
1186
|
+
var extractDocLinks = function (markdown) {
|
|
1187
|
+
var links = [];
|
|
1188
|
+
var regex = new RegExp(DOCLINK_REGEX.source, "g");
|
|
1189
|
+
var match;
|
|
1190
|
+
while ((match = regex.exec(markdown)) !== null) {
|
|
1191
|
+
links.push({
|
|
1192
|
+
id: match[1],
|
|
1193
|
+
text: match[2]
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
return links;
|
|
1197
|
+
};
|
|
1198
|
+
/**
|
|
1199
|
+
* 检查文本是否包含文档链接语法
|
|
1200
|
+
*/
|
|
1201
|
+
var hasDocLink = function (text) {
|
|
1202
|
+
return DOCLINK_REGEX.test(text);
|
|
1203
|
+
};
|
|
1204
|
+
|
|
1205
|
+
|
|
1054
1206
|
/***/ },
|
|
1055
1207
|
|
|
1056
1208
|
/***/ 249
|
|
@@ -1088,7 +1240,7 @@ var looseJsonParse = function (text) {
|
|
|
1088
1240
|
/* harmony export */ Y: () => (/* binding */ Constants),
|
|
1089
1241
|
/* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
|
|
1090
1242
|
/* harmony export */ });
|
|
1091
|
-
var _VDITOR_VERSION = "0.0.
|
|
1243
|
+
var _VDITOR_VERSION = "0.0.3";
|
|
1092
1244
|
|
|
1093
1245
|
var Constants = /** @class */ (function () {
|
|
1094
1246
|
function Constants() {
|
|
@@ -1136,7 +1288,7 @@ var Constants = /** @class */ (function () {
|
|
|
1136
1288
|
// 别名
|
|
1137
1289
|
"js", "ts", "html", "toml", "c#", "bat"
|
|
1138
1290
|
];
|
|
1139
|
-
Constants.CDN = "https://unpkg.com/vditor@".concat("0.0.
|
|
1291
|
+
Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.0.3");
|
|
1140
1292
|
Constants.MARKDOWN_OPTIONS = {
|
|
1141
1293
|
autoSpace: false,
|
|
1142
1294
|
gfmAutoLink: true,
|
|
@@ -6548,9 +6700,12 @@ var highlightToolbarIR = function (vditor) {
|
|
|
6548
6700
|
}, 200);
|
|
6549
6701
|
};
|
|
6550
6702
|
|
|
6703
|
+
// EXTERNAL MODULE: ./src/ts/markdown/docLink.ts
|
|
6704
|
+
var docLink = __webpack_require__(234);
|
|
6551
6705
|
;// ./src/ts/wysiwyg/afterRenderEvent.ts
|
|
6552
6706
|
|
|
6553
6707
|
|
|
6708
|
+
|
|
6554
6709
|
var afterRenderEvent = function (vditor, options) {
|
|
6555
6710
|
if (options === void 0) { options = {
|
|
6556
6711
|
enableAddUndoStack: true,
|
|
@@ -6584,6 +6739,10 @@ var afterRenderEvent = function (vditor, options) {
|
|
|
6584
6739
|
if (options.enableAddUndoStack) {
|
|
6585
6740
|
vditor.undo.addToUndoStack(vditor);
|
|
6586
6741
|
}
|
|
6742
|
+
// 处理文档链接渲染
|
|
6743
|
+
if (vditor.wysiwyg.element) {
|
|
6744
|
+
(0,docLink/* processDocLinkInWYSIWYG */.qo)(vditor.wysiwyg.element, vditor);
|
|
6745
|
+
}
|
|
6587
6746
|
}, vditor.options.undoDelay);
|
|
6588
6747
|
};
|
|
6589
6748
|
|
|
@@ -12218,6 +12377,7 @@ var mediaRender = __webpack_require__(924);
|
|
|
12218
12377
|
|
|
12219
12378
|
|
|
12220
12379
|
|
|
12380
|
+
|
|
12221
12381
|
var Preview = /** @class */ (function () {
|
|
12222
12382
|
function Preview(vditor) {
|
|
12223
12383
|
var _this = this;
|
|
@@ -12372,11 +12532,15 @@ var Preview = /** @class */ (function () {
|
|
|
12372
12532
|
if (vditor.options.preview.transform) {
|
|
12373
12533
|
responseJSON.data = vditor.options.preview.transform(responseJSON.data);
|
|
12374
12534
|
}
|
|
12535
|
+
// 渲染文档链接
|
|
12536
|
+
responseJSON.data = (0,docLink/* renderDocLink */.BS)(responseJSON.data, vditor);
|
|
12375
12537
|
_this.previewElement.innerHTML = responseJSON.data;
|
|
12376
12538
|
_this.afterRender(vditor, renderStartTime);
|
|
12377
12539
|
}
|
|
12378
12540
|
else {
|
|
12379
12541
|
var html = vditor.lute.Md2HTML(markdownText);
|
|
12542
|
+
// 渲染文档链接
|
|
12543
|
+
html = (0,docLink/* renderDocLink */.BS)(html, vditor);
|
|
12380
12544
|
if (vditor.options.preview.transform) {
|
|
12381
12545
|
html = vditor.options.preview.transform(html);
|
|
12382
12546
|
}
|
|
@@ -12389,6 +12553,8 @@ var Preview = /** @class */ (function () {
|
|
|
12389
12553
|
}
|
|
12390
12554
|
else {
|
|
12391
12555
|
var html = vditor.lute.Md2HTML(markdownText);
|
|
12556
|
+
// 渲染文档链接
|
|
12557
|
+
html = (0,docLink/* renderDocLink */.BS)(html, vditor);
|
|
12392
12558
|
if (vditor.options.preview.transform) {
|
|
12393
12559
|
html = vditor.options.preview.transform(html);
|
|
12394
12560
|
}
|
|
@@ -13457,7 +13623,7 @@ var Info = /** @class */ (function (_super) {
|
|
|
13457
13623
|
var _this = _super.call(this, vditor, menuItem) || this;
|
|
13458
13624
|
_this.element.children[0].addEventListener((0,compatibility/* getEventName */.y3)(), function (event) {
|
|
13459
13625
|
event.preventDefault();
|
|
13460
|
-
vditor.tip.show("<div style=\"max-width: 520px; font-size: 14px;line-height: 22px;margin-bottom: 14px;\">\n<p style=\"text-align: center;margin: 14px 0\">\n <em>\u4E0B\u4E00\u4EE3\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u4E3A\u672A\u6765\u800C\u6784\u5EFA</em>\n</p>\n<div style=\"display: flex;margin-bottom: 14px;flex-wrap: wrap;align-items: center\">\n <img src=\"
|
|
13626
|
+
vditor.tip.show("<div style=\"max-width: 520px; font-size: 14px;line-height: 22px;margin-bottom: 14px;\">\n<p style=\"text-align: center;margin: 14px 0\">\n <em>\u4E0B\u4E00\u4EE3\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u4E3A\u672A\u6765\u800C\u6784\u5EFA</em>\n</p>\n<div style=\"display: flex;margin-bottom: 14px;flex-wrap: wrap;align-items: center\">\n <img src=\"".concat(constants/* Constants */.Y.CDN, "/dist/images/logo.png\" style=\"margin: 0 auto;height: 68px\"/>\n <div> </div>\n <div style=\"flex: 1;min-width: 250px\">\n Vditor \u662F\u4E00\u6B3E\u6D4F\u89C8\u5668\u7AEF\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u652F\u6301\u6240\u89C1\u5373\u6240\u5F97\u3001\u5373\u65F6\u6E32\u67D3\uFF08\u7C7B\u4F3C Typora\uFF09\u548C\u5206\u5C4F\u9884\u89C8\u6A21\u5F0F\u3002\n \u5B83\u4F7F\u7528 TypeScript \u5B9E\u73B0\uFF0C\u652F\u6301\u539F\u751F JavaScript \u4EE5\u53CA Vue\u3001React\u3001Angular \u548C Svelte \u7B49\u6846\u67B6\u3002\n </div>\n</div>\n<div style=\"display: flex;flex-wrap: wrap;\">\n <ul style=\"list-style: none;flex: 1;min-width:148px\">\n <li>\n \u9879\u76EE\u5730\u5740\uFF1A<a href=\"https://b3log.org/vditor\" target=\"_blank\">b3log.org/vditor</a>\n </li>\n <li>\n \u5F00\u6E90\u534F\u8BAE\uFF1AMIT\n </li>\n </ul>\n <ul style=\"list-style: none;margin-right: 18px\">\n <li>\n \u7EC4\u4EF6\u7248\u672C\uFF1AVditor v").concat(constants/* VDITOR_VERSION */.g, " / Lute v").concat(Lute.Version, "\n </li>\n <li>\n \u8D5E\u52A9\u6350\u8D60\uFF1A<a href=\"https://ld246.com/sponsor\" target=\"_blank\">https://ld246.com/sponsor</a>\n </li>\n </ul>\n</div>\n</div>"), 0);
|
|
13461
13627
|
});
|
|
13462
13628
|
return _this;
|
|
13463
13629
|
}
|
|
@@ -15341,6 +15507,19 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
15341
15507
|
event.preventDefault();
|
|
15342
15508
|
return;
|
|
15343
15509
|
}
|
|
15510
|
+
// 处理文档链接点击
|
|
15511
|
+
var docLink = (0,hasClosest/* hasClosestByClassName */.KJ)(event.target, "vditor-doclink");
|
|
15512
|
+
if (docLink) {
|
|
15513
|
+
var docId_1 = docLink.getAttribute("data-doc-id");
|
|
15514
|
+
var docText_1 = docLink.getAttribute("data-doc-text") || '';
|
|
15515
|
+
if (docId_1) {
|
|
15516
|
+
Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 234)).then(function (docLinkModule) {
|
|
15517
|
+
docLinkModule.handleDocLinkClick(docId_1, docText_1, vditor);
|
|
15518
|
+
});
|
|
15519
|
+
}
|
|
15520
|
+
event.preventDefault();
|
|
15521
|
+
return;
|
|
15522
|
+
}
|
|
15344
15523
|
var range = (0,selection/* getEditorRange */.RN)(vditor);
|
|
15345
15524
|
if (event.target.isEqualNode(_this.element) && _this.element.lastElementChild && range.collapsed) {
|
|
15346
15525
|
var lastRect = _this.element.lastElementChild.getBoundingClientRect();
|