@yltrcc/vditor 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +2 -2
- package/dist/index.js +48 -11
- 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 +5 -0
- package/package.json +1 -1
- package/src/ts/markdown/docLink.ts +202 -171
- package/src/ts/wysiwyg/index.ts +11 -0
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.5 - 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.5 - A markdown editor written in TypeScript.
|
|
29
29
|
*
|
|
30
30
|
* MIT License
|
|
31
31
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.5 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -1060,7 +1060,8 @@ var insertHTML = function (html, vditor) {
|
|
|
1060
1060
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1061
1061
|
/* harmony export */ BS: () => (/* binding */ renderDocLink),
|
|
1062
1062
|
/* harmony export */ handleDocLinkClick: () => (/* binding */ handleDocLinkClick),
|
|
1063
|
-
/* harmony export */ qo: () => (/* binding */ processDocLinkInWYSIWYG)
|
|
1063
|
+
/* harmony export */ qo: () => (/* binding */ processDocLinkInWYSIWYG),
|
|
1064
|
+
/* harmony export */ uN: () => (/* binding */ getDocLinkMarkdown)
|
|
1064
1065
|
/* harmony export */ });
|
|
1065
1066
|
/* unused harmony exports extractDocLinks, hasDocLink */
|
|
1066
1067
|
/**
|
|
@@ -1079,7 +1080,7 @@ var renderDocLink = function (html, vditor) {
|
|
|
1079
1080
|
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
1081
|
return html;
|
|
1081
1082
|
}
|
|
1082
|
-
return html.replace(DOCLINK_REGEX, '<span class="vditor-doclink" data-doc-id="$1" data-doc-text="$2">$2</span>');
|
|
1083
|
+
return html.replace(DOCLINK_REGEX, '<span class="vditor-doclink" data-doc-id="$1" data-doc-text="$2" data-doc-markdown="(($1 \'$2\'))">$2</span>');
|
|
1083
1084
|
};
|
|
1084
1085
|
/**
|
|
1085
1086
|
* 在 WYSIWYG 编辑器中处理文档链接的实时渲染
|
|
@@ -1110,7 +1111,8 @@ var processDocLinkInWYSIWYG = function (element, vditor) {
|
|
|
1110
1111
|
index: match.index,
|
|
1111
1112
|
length: match[0].length,
|
|
1112
1113
|
id: match[1],
|
|
1113
|
-
text: match[2]
|
|
1114
|
+
text: match[2],
|
|
1115
|
+
fullMatch: match[0]
|
|
1114
1116
|
});
|
|
1115
1117
|
}
|
|
1116
1118
|
if (matches.length === 0)
|
|
@@ -1126,19 +1128,26 @@ var processDocLinkInWYSIWYG = function (element, vditor) {
|
|
|
1126
1128
|
if (m.index > lastIndex) {
|
|
1127
1129
|
fragments.push(document.createTextNode(text.slice(lastIndex, m.index)));
|
|
1128
1130
|
}
|
|
1129
|
-
//
|
|
1131
|
+
// 创建文档链接容器 - 使用 contenteditable="false" 防止编辑时破坏结构
|
|
1132
|
+
var container = document.createElement("span");
|
|
1133
|
+
container.className = "vditor-doclink-wrapper";
|
|
1134
|
+
container.setAttribute("contenteditable", "false");
|
|
1135
|
+
container.setAttribute("data-doc-id", m.id);
|
|
1136
|
+
container.setAttribute("data-doc-text", m.text);
|
|
1137
|
+
// 存储完整的 Markdown 语法,用于复制
|
|
1138
|
+
container.setAttribute("data-doc-markdown", m.fullMatch);
|
|
1139
|
+
// 创建显示文本的元素
|
|
1130
1140
|
var span = document.createElement("span");
|
|
1131
1141
|
span.className = "vditor-doclink";
|
|
1132
|
-
span.setAttribute("data-doc-id", m.id);
|
|
1133
|
-
span.setAttribute("data-doc-text", m.text);
|
|
1134
1142
|
span.textContent = m.text;
|
|
1135
1143
|
// 绑定点击事件
|
|
1136
|
-
|
|
1144
|
+
container.onclick = function (e) {
|
|
1137
1145
|
e.preventDefault();
|
|
1138
1146
|
e.stopPropagation();
|
|
1139
1147
|
handleDocLinkClick(m.id, m.text, vditor);
|
|
1140
1148
|
};
|
|
1141
|
-
|
|
1149
|
+
container.appendChild(span);
|
|
1150
|
+
fragments.push(container);
|
|
1142
1151
|
lastIndex = m.index + m.length;
|
|
1143
1152
|
});
|
|
1144
1153
|
// 添加剩余文本
|
|
@@ -1201,6 +1210,24 @@ var extractDocLinks = function (markdown) {
|
|
|
1201
1210
|
var hasDocLink = function (text) {
|
|
1202
1211
|
return DOCLINK_REGEX.test(text);
|
|
1203
1212
|
};
|
|
1213
|
+
/**
|
|
1214
|
+
* 获取文档链接的 Markdown 语法
|
|
1215
|
+
* 用于复制操作时恢复原始语法
|
|
1216
|
+
*/
|
|
1217
|
+
var getDocLinkMarkdown = function (element) {
|
|
1218
|
+
// 优先从 data-doc-markdown 属性获取
|
|
1219
|
+
var markdown = element.getAttribute("data-doc-markdown");
|
|
1220
|
+
if (markdown) {
|
|
1221
|
+
return markdown;
|
|
1222
|
+
}
|
|
1223
|
+
// 从 data-doc-id 和 data-doc-text 重建
|
|
1224
|
+
var id = element.getAttribute("data-doc-id");
|
|
1225
|
+
var text = element.getAttribute("data-doc-text");
|
|
1226
|
+
if (id && text) {
|
|
1227
|
+
return "((".concat(id, " '").concat(text, "'))");
|
|
1228
|
+
}
|
|
1229
|
+
return null;
|
|
1230
|
+
};
|
|
1204
1231
|
|
|
1205
1232
|
|
|
1206
1233
|
/***/ },
|
|
@@ -1240,7 +1267,7 @@ var looseJsonParse = function (text) {
|
|
|
1240
1267
|
/* harmony export */ Y: () => (/* binding */ Constants),
|
|
1241
1268
|
/* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
|
|
1242
1269
|
/* harmony export */ });
|
|
1243
|
-
var _VDITOR_VERSION = "0.0.
|
|
1270
|
+
var _VDITOR_VERSION = "0.0.5";
|
|
1244
1271
|
|
|
1245
1272
|
var Constants = /** @class */ (function () {
|
|
1246
1273
|
function Constants() {
|
|
@@ -1288,7 +1315,7 @@ var Constants = /** @class */ (function () {
|
|
|
1288
1315
|
// 别名
|
|
1289
1316
|
"js", "ts", "html", "toml", "c#", "bat"
|
|
1290
1317
|
];
|
|
1291
|
-
Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.0.
|
|
1318
|
+
Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.0.5");
|
|
1292
1319
|
Constants.MARKDOWN_OPTIONS = {
|
|
1293
1320
|
autoSpace: false,
|
|
1294
1321
|
gfmAutoLink: true,
|
|
@@ -15123,6 +15150,7 @@ var Options = /** @class */ (function () {
|
|
|
15123
15150
|
|
|
15124
15151
|
|
|
15125
15152
|
|
|
15153
|
+
|
|
15126
15154
|
var WYSIWYG = /** @class */ (function () {
|
|
15127
15155
|
function WYSIWYG(vditor) {
|
|
15128
15156
|
var _this = this;
|
|
@@ -15311,6 +15339,15 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
15311
15339
|
}
|
|
15312
15340
|
var tempElement = document.createElement("div");
|
|
15313
15341
|
tempElement.appendChild(range.cloneContents());
|
|
15342
|
+
// 处理文档链接的复制 - 将渲染后的元素替换为原始 Markdown 语法
|
|
15343
|
+
var docLinkElements = tempElement.querySelectorAll(".vditor-doclink-wrapper, .vditor-doclink");
|
|
15344
|
+
docLinkElements.forEach(function (el) {
|
|
15345
|
+
var markdown = (0,docLink/* getDocLinkMarkdown */.uN)(el);
|
|
15346
|
+
if (markdown) {
|
|
15347
|
+
// 用文本节点替换元素,内容为 Markdown 语法
|
|
15348
|
+
el.replaceWith(document.createTextNode(markdown));
|
|
15349
|
+
}
|
|
15350
|
+
});
|
|
15314
15351
|
event.clipboardData.setData("text/plain", vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim());
|
|
15315
15352
|
event.clipboardData.setData("text/html", "");
|
|
15316
15353
|
};
|