@yltrcc/vditor 0.0.8 → 0.1.0
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 +62 -2
- package/dist/index.js +77 -16
- package/dist/index.min.js +1 -1
- package/dist/method.js +3 -3
- package/dist/method.min.js +1 -1
- package/dist/ts/wysiwyg/showCode.d.ts +12 -0
- package/package.json +1 -1
- package/src/assets/less/_wysiwyg.less +75 -0
- package/src/ts/util/processCode.ts +5 -0
- package/src/ts/wysiwyg/index.ts +12 -1
- package/src/ts/wysiwyg/input.ts +20 -1
- package/src/ts/wysiwyg/processKeydown.ts +2 -3
- package/src/ts/wysiwyg/showCode.ts +73 -32
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0
|
|
2
|
+
* Vditor v0.1.0 - 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.1.0 - A markdown editor written in TypeScript.
|
|
29
29
|
*
|
|
30
30
|
* MIT License
|
|
31
31
|
*
|
|
@@ -1396,8 +1396,12 @@
|
|
|
1396
1396
|
padding-left: 0 !important;
|
|
1397
1397
|
padding-right: 0 !important;
|
|
1398
1398
|
}
|
|
1399
|
+
.vditor-wysiwyg__block {
|
|
1400
|
+
position: relative;
|
|
1401
|
+
}
|
|
1399
1402
|
.vditor-wysiwyg__block pre:first-child {
|
|
1400
1403
|
margin-bottom: -1em;
|
|
1404
|
+
display: none;
|
|
1401
1405
|
}
|
|
1402
1406
|
.vditor-wysiwyg__block pre:first-child code {
|
|
1403
1407
|
color: var(--textarea-text-color);
|
|
@@ -1407,10 +1411,43 @@
|
|
|
1407
1411
|
.vditor-wysiwyg__block pre:last-child {
|
|
1408
1412
|
margin-bottom: 1em;
|
|
1409
1413
|
}
|
|
1414
|
+
.vditor-wysiwyg__block--editing pre:first-child {
|
|
1415
|
+
display: block;
|
|
1416
|
+
}
|
|
1417
|
+
.vditor-wysiwyg__block--editing .vditor-wysiwyg__preview {
|
|
1418
|
+
display: none;
|
|
1419
|
+
}
|
|
1410
1420
|
.vditor-wysiwyg__preview {
|
|
1411
1421
|
cursor: pointer;
|
|
1412
1422
|
white-space: initial;
|
|
1413
1423
|
min-height: 27px;
|
|
1424
|
+
display: block;
|
|
1425
|
+
}
|
|
1426
|
+
.vditor-wysiwyg__preview pre {
|
|
1427
|
+
margin: 0;
|
|
1428
|
+
padding: 1em;
|
|
1429
|
+
background-color: var(--code-background-color);
|
|
1430
|
+
border-radius: 4px;
|
|
1431
|
+
overflow-x: auto;
|
|
1432
|
+
}
|
|
1433
|
+
.vditor-wysiwyg__preview pre code {
|
|
1434
|
+
font-family: var(--code-font-family);
|
|
1435
|
+
font-size: var(--code-font-size);
|
|
1436
|
+
line-height: var(--code-line-height);
|
|
1437
|
+
}
|
|
1438
|
+
.vditor-wysiwyg__preview::before {
|
|
1439
|
+
content: attr(data-language);
|
|
1440
|
+
position: absolute;
|
|
1441
|
+
top: 0;
|
|
1442
|
+
right: 0;
|
|
1443
|
+
padding: 2px 8px;
|
|
1444
|
+
font-size: 12px;
|
|
1445
|
+
color: var(--second-color);
|
|
1446
|
+
background-color: var(--panel-background-color);
|
|
1447
|
+
border-radius: 0 4px 0 4px;
|
|
1448
|
+
}
|
|
1449
|
+
.vditor-wysiwyg__preview:hover {
|
|
1450
|
+
box-shadow: 0 0 0 2px var(--blurColor);
|
|
1414
1451
|
}
|
|
1415
1452
|
.vditor-wysiwyg > .vditor-reset > h1:before,
|
|
1416
1453
|
.vditor-wysiwyg > .vditor-reset > h2:before,
|
|
@@ -1473,6 +1510,29 @@
|
|
|
1473
1510
|
}
|
|
1474
1511
|
.vditor-wysiwyg a {
|
|
1475
1512
|
cursor: pointer;
|
|
1513
|
+
color: #4285f4;
|
|
1514
|
+
text-decoration: none;
|
|
1515
|
+
background-color: rgba(66, 133, 244, 0.1);
|
|
1516
|
+
padding: 2px 4px;
|
|
1517
|
+
border-radius: 3px;
|
|
1518
|
+
transition: background-color 0.2s ease;
|
|
1519
|
+
}
|
|
1520
|
+
.vditor-wysiwyg a:hover {
|
|
1521
|
+
background-color: rgba(66, 133, 244, 0.2);
|
|
1522
|
+
text-decoration: underline;
|
|
1523
|
+
}
|
|
1524
|
+
.vditor-wysiwyg a:visited {
|
|
1525
|
+
color: #1266f1;
|
|
1526
|
+
}
|
|
1527
|
+
.vditor-wysiwyg img {
|
|
1528
|
+
cursor: pointer;
|
|
1529
|
+
border: 2px solid transparent;
|
|
1530
|
+
border-radius: 4px;
|
|
1531
|
+
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
|
1532
|
+
}
|
|
1533
|
+
.vditor-wysiwyg img:hover {
|
|
1534
|
+
border-color: #4285f4;
|
|
1535
|
+
box-shadow: 0 0 8px rgba(66, 133, 244, 0.3);
|
|
1476
1536
|
}
|
|
1477
1537
|
.vditor-wysiwyg span[data-type="backslash"] > span {
|
|
1478
1538
|
display: none;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0
|
|
2
|
+
* Vditor v0.1.0 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -1267,7 +1267,7 @@ var looseJsonParse = function (text) {
|
|
|
1267
1267
|
/* harmony export */ Y: () => (/* binding */ Constants),
|
|
1268
1268
|
/* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
|
|
1269
1269
|
/* harmony export */ });
|
|
1270
|
-
var _VDITOR_VERSION = "0.0
|
|
1270
|
+
var _VDITOR_VERSION = "0.1.0";
|
|
1271
1271
|
|
|
1272
1272
|
var Constants = /** @class */ (function () {
|
|
1273
1273
|
function Constants() {
|
|
@@ -1315,7 +1315,7 @@ var Constants = /** @class */ (function () {
|
|
|
1315
1315
|
// 别名
|
|
1316
1316
|
"js", "ts", "html", "toml", "c#", "bat"
|
|
1317
1317
|
];
|
|
1318
|
-
Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.0
|
|
1318
|
+
Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.1.0");
|
|
1319
1319
|
Constants.MARKDOWN_OPTIONS = {
|
|
1320
1320
|
autoSpace: false,
|
|
1321
1321
|
gfmAutoLink: true,
|
|
@@ -5425,6 +5425,10 @@ var processCodeRender = function (previewPanel, vditor) {
|
|
|
5425
5425
|
return;
|
|
5426
5426
|
}
|
|
5427
5427
|
var language = previewPanel.firstElementChild.className.replace("language-", "");
|
|
5428
|
+
// 设置语言属性用于显示语言标签
|
|
5429
|
+
if (language && language !== "hljs") {
|
|
5430
|
+
previewPanel.setAttribute("data-language", language);
|
|
5431
|
+
}
|
|
5428
5432
|
if (language === "abc") {
|
|
5429
5433
|
(0,abcRender/* abcRender */.$)(previewPanel, vditor.options.cdn);
|
|
5430
5434
|
}
|
|
@@ -6996,25 +7000,37 @@ var removeHeading = function (vditor) {
|
|
|
6996
7000
|
;// ./src/ts/wysiwyg/showCode.ts
|
|
6997
7001
|
|
|
6998
7002
|
|
|
7003
|
+
/**
|
|
7004
|
+
* 显示代码编辑区域,隐藏预览区域
|
|
7005
|
+
* @param previewElement - 预览区域元素
|
|
7006
|
+
* @param vditor - Vditor 实例
|
|
7007
|
+
* @param first - 是否将光标设置在开头
|
|
7008
|
+
*/
|
|
6999
7009
|
var showCode = function (previewElement, vditor, first) {
|
|
7010
|
+
var _a;
|
|
7000
7011
|
if (first === void 0) { first = true; }
|
|
7001
|
-
var
|
|
7002
|
-
var
|
|
7003
|
-
|
|
7004
|
-
|
|
7012
|
+
var blockElement = previewElement.parentElement;
|
|
7013
|
+
var codeElement = previewElement.previousElementSibling;
|
|
7014
|
+
// 添加编辑状态类
|
|
7015
|
+
blockElement.classList.add("vditor-wysiwyg__block--editing");
|
|
7016
|
+
var range = codeElement.ownerDocument.createRange();
|
|
7017
|
+
if (codeElement.tagName === "CODE") {
|
|
7018
|
+
// 行内代码
|
|
7019
|
+
codeElement.style.display = "inline-block";
|
|
7005
7020
|
if (first) {
|
|
7006
|
-
range.setStart(
|
|
7021
|
+
range.setStart(codeElement.firstChild, 1);
|
|
7007
7022
|
}
|
|
7008
7023
|
else {
|
|
7009
|
-
range.selectNodeContents(
|
|
7024
|
+
range.selectNodeContents(codeElement);
|
|
7010
7025
|
}
|
|
7011
7026
|
}
|
|
7012
7027
|
else {
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7028
|
+
// 代码块
|
|
7029
|
+
codeElement.style.display = "block";
|
|
7030
|
+
if (!codeElement.firstChild.firstChild) {
|
|
7031
|
+
codeElement.firstChild.appendChild(document.createTextNode(""));
|
|
7016
7032
|
}
|
|
7017
|
-
range.selectNodeContents(
|
|
7033
|
+
range.selectNodeContents(codeElement.firstChild);
|
|
7018
7034
|
}
|
|
7019
7035
|
if (first) {
|
|
7020
7036
|
range.collapse(true);
|
|
@@ -7023,11 +7039,30 @@ var showCode = function (previewElement, vditor, first) {
|
|
|
7023
7039
|
range.collapse(false);
|
|
7024
7040
|
}
|
|
7025
7041
|
(0,selection/* setSelectionFocus */.jl)(range);
|
|
7026
|
-
if (previewElement.firstElementChild.classList.contains("language-mindmap")) {
|
|
7042
|
+
if ((_a = previewElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList.contains("language-mindmap")) {
|
|
7027
7043
|
return;
|
|
7028
7044
|
}
|
|
7029
7045
|
scrollCenter(vditor);
|
|
7030
7046
|
};
|
|
7047
|
+
/**
|
|
7048
|
+
* 隐藏代码编辑区域,显示预览区域
|
|
7049
|
+
* @param blockElement - 代码块容器元素
|
|
7050
|
+
* @param vditor - Vditor 实例
|
|
7051
|
+
*/
|
|
7052
|
+
var hideCode = function (blockElement, vditor) {
|
|
7053
|
+
// 移除编辑状态类
|
|
7054
|
+
blockElement.classList.remove("vditor-wysiwyg__block--editing");
|
|
7055
|
+
var codeElement = blockElement.querySelector("pre:first-child");
|
|
7056
|
+
var previewElement = blockElement.querySelector(".vditor-wysiwyg__preview");
|
|
7057
|
+
if (codeElement) {
|
|
7058
|
+
codeElement.style.display = "none";
|
|
7059
|
+
}
|
|
7060
|
+
if (previewElement) {
|
|
7061
|
+
previewElement.style.display = "block";
|
|
7062
|
+
// 重新渲染预览
|
|
7063
|
+
previewElement.setAttribute("data-render", "2");
|
|
7064
|
+
}
|
|
7065
|
+
};
|
|
7031
7066
|
|
|
7032
7067
|
;// ./src/ts/wysiwyg/processKeydown.ts
|
|
7033
7068
|
|
|
@@ -7086,8 +7121,7 @@ var wysiwyg_processKeydown_processKeydown = function (vditor, event) {
|
|
|
7086
7121
|
// esc: 退出编辑,仅展示渲染
|
|
7087
7122
|
if (event.key === "Escape" && codeRenderElement.children.length === 2) {
|
|
7088
7123
|
vditor.wysiwyg.popover.style.display = "none";
|
|
7089
|
-
codeRenderElement
|
|
7090
|
-
vditor.wysiwyg.element.blur();
|
|
7124
|
+
hideCode(codeRenderElement, vditor);
|
|
7091
7125
|
event.preventDefault();
|
|
7092
7126
|
return true;
|
|
7093
7127
|
}
|
|
@@ -9827,6 +9861,24 @@ var uploadFiles = function (vditor, files, element) { return __awaiter(void 0, v
|
|
|
9827
9861
|
|
|
9828
9862
|
var input_input = function (vditor, range, event) {
|
|
9829
9863
|
var _a;
|
|
9864
|
+
// 检查是否在代码块编辑模式中
|
|
9865
|
+
var editingBlock = (0,hasClosest/* hasClosestByClassName */.KJ)(range.startContainer, "vditor-wysiwyg__block--editing");
|
|
9866
|
+
if (editingBlock) {
|
|
9867
|
+
// 在代码块编辑模式中,只更新预览区域,不重新渲染整个代码块
|
|
9868
|
+
var previewElement = editingBlock.querySelector(".vditor-wysiwyg__preview");
|
|
9869
|
+
if (previewElement) {
|
|
9870
|
+
// 标记预览区域需要重新渲染
|
|
9871
|
+
previewElement.setAttribute("data-render", "2");
|
|
9872
|
+
}
|
|
9873
|
+
// 直接调用 afterRenderEvent,跳过 HTML 重新渲染
|
|
9874
|
+
renderToc(vditor);
|
|
9875
|
+
afterRenderEvent(vditor, {
|
|
9876
|
+
enableAddUndoStack: true,
|
|
9877
|
+
enableHint: true,
|
|
9878
|
+
enableInput: true,
|
|
9879
|
+
});
|
|
9880
|
+
return;
|
|
9881
|
+
}
|
|
9830
9882
|
var blockElement = (0,hasClosest/* hasClosestBlock */.pt)(range.startContainer);
|
|
9831
9883
|
if (!blockElement) {
|
|
9832
9884
|
// 使用顶级块元素,应使用 innerHTML
|
|
@@ -15626,6 +15678,15 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
15626
15678
|
}
|
|
15627
15679
|
}
|
|
15628
15680
|
highlightToolbarWYSIWYG(vditor);
|
|
15681
|
+
// 处理代码块的编辑/预览切换
|
|
15682
|
+
var clickedBlockElement = (0,hasClosest/* hasClosestByClassName */.KJ)(event.target, "vditor-wysiwyg__block");
|
|
15683
|
+
// 隐藏所有其他代码块的编辑区域
|
|
15684
|
+
vditor.wysiwyg.element.querySelectorAll(".vditor-wysiwyg__block--editing").forEach(function (block) {
|
|
15685
|
+
// 如果点击的不是当前正在编辑的代码块,则隐藏编辑区域
|
|
15686
|
+
if (!clickedBlockElement || !clickedBlockElement.isEqualNode(block)) {
|
|
15687
|
+
hideCode(block, vditor);
|
|
15688
|
+
}
|
|
15689
|
+
});
|
|
15629
15690
|
// 点击后光标落于预览区,需展开代码块
|
|
15630
15691
|
var previewElement = (0,hasClosest/* hasClosestByClassName */.KJ)(event.target, "vditor-wysiwyg__preview");
|
|
15631
15692
|
if (!previewElement) {
|