@8btc/mditor 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +112 -4
- package/dist/index.js +165 -58
- package/dist/index.min.js +1 -1
- package/dist/method.js +3 -3
- package/dist/method.min.js +1 -1
- package/dist/ts/markdown/selectionRender.d.ts +4 -0
- package/dist/ts/wysiwyg/index.d.ts +5 -0
- package/dist/types/index.d.ts +10 -1
- package/package.json +1 -1
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.12 - 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.12 - A markdown editor written in TypeScript.
|
|
29
29
|
*
|
|
30
30
|
* MIT License
|
|
31
31
|
*
|
|
@@ -1921,7 +1921,7 @@
|
|
|
1921
1921
|
z-index: 4;
|
|
1922
1922
|
display: none;
|
|
1923
1923
|
padding: 0;
|
|
1924
|
-
border-radius:
|
|
1924
|
+
border-radius: 8px;
|
|
1925
1925
|
background-color: var(--panel-background-color);
|
|
1926
1926
|
box-shadow: var(--panel-shadow);
|
|
1927
1927
|
border: 1px solid var(--border-color);
|
|
@@ -1930,9 +1930,87 @@
|
|
|
1930
1930
|
user-select: none;
|
|
1931
1931
|
white-space: nowrap;
|
|
1932
1932
|
transform-origin: top left;
|
|
1933
|
+
opacity: 0;
|
|
1933
1934
|
transition: opacity 150ms cubic-bezier(0.2, 0, 0.13, 1.5), transform 150ms cubic-bezier(0.2, 0, 0.13, 1.5);
|
|
1935
|
+
flex-direction: column;
|
|
1936
|
+
flex-wrap: nowrap;
|
|
1937
|
+
}
|
|
1938
|
+
.vditor-selection-popover__actions {
|
|
1939
|
+
display: flex;
|
|
1940
|
+
flex-direction: row;
|
|
1941
|
+
align-items: center;
|
|
1942
|
+
width: 100%;
|
|
1943
|
+
border-bottom: 1px solid var(--border-color);
|
|
1944
|
+
}
|
|
1945
|
+
.vditor-selection-popover__input {
|
|
1946
|
+
display: flex;
|
|
1947
|
+
flex-direction: column;
|
|
1948
|
+
width: 327px;
|
|
1949
|
+
padding: 12px;
|
|
1950
|
+
gap: 8px;
|
|
1951
|
+
align-items: flex-end;
|
|
1952
|
+
box-sizing: border-box;
|
|
1953
|
+
}
|
|
1954
|
+
.vditor-selection-popover__input textarea {
|
|
1955
|
+
flex: 1;
|
|
1956
|
+
width: 100%;
|
|
1957
|
+
height: 60px;
|
|
1958
|
+
background: transparent;
|
|
1959
|
+
border: none;
|
|
1960
|
+
resize: none;
|
|
1961
|
+
outline: none;
|
|
1962
|
+
color: var(--textarea-text-color);
|
|
1963
|
+
font-size: 14px;
|
|
1964
|
+
line-height: 20px;
|
|
1965
|
+
padding: 0;
|
|
1966
|
+
margin: 0;
|
|
1967
|
+
}
|
|
1968
|
+
.vditor-selection-popover__input textarea::-moz-placeholder {
|
|
1969
|
+
color: #585a5a;
|
|
1970
|
+
}
|
|
1971
|
+
.vditor-selection-popover__input textarea::placeholder {
|
|
1972
|
+
color: #585a5a;
|
|
1973
|
+
}
|
|
1974
|
+
.vditor-selection-popover__input .vditor-selection-popover__send {
|
|
1934
1975
|
display: flex;
|
|
1935
1976
|
align-items: center;
|
|
1977
|
+
justify-content: center;
|
|
1978
|
+
width: 32px;
|
|
1979
|
+
height: 32px;
|
|
1980
|
+
border: none;
|
|
1981
|
+
background: var(--toolbar-icon-hover-color);
|
|
1982
|
+
border-radius: 8px;
|
|
1983
|
+
color: #fff;
|
|
1984
|
+
cursor: pointer;
|
|
1985
|
+
padding: 0;
|
|
1986
|
+
transition: opacity 0.2s;
|
|
1987
|
+
}
|
|
1988
|
+
.vditor-selection-popover__input .vditor-selection-popover__send:hover {
|
|
1989
|
+
opacity: 0.8;
|
|
1990
|
+
}
|
|
1991
|
+
.vditor-selection-popover__input .vditor-selection-popover__send[disabled] {
|
|
1992
|
+
opacity: 0.5;
|
|
1993
|
+
cursor: not-allowed;
|
|
1994
|
+
pointer-events: none;
|
|
1995
|
+
}
|
|
1996
|
+
.vditor-selection-popover__input .vditor-selection-popover__send--loading {
|
|
1997
|
+
pointer-events: none;
|
|
1998
|
+
opacity: 0.8;
|
|
1999
|
+
}
|
|
2000
|
+
.vditor-selection-popover__input .vditor-selection-popover__send--loading svg {
|
|
2001
|
+
animation: vditor-rotate 1s linear infinite;
|
|
2002
|
+
}
|
|
2003
|
+
.vditor-selection-popover__input .vditor-selection-popover__send svg {
|
|
2004
|
+
width: 16px;
|
|
2005
|
+
height: 16px;
|
|
2006
|
+
}
|
|
2007
|
+
@keyframes vditor-rotate {
|
|
2008
|
+
from {
|
|
2009
|
+
transform: rotate(0deg);
|
|
2010
|
+
}
|
|
2011
|
+
to {
|
|
2012
|
+
transform: rotate(360deg);
|
|
2013
|
+
}
|
|
1936
2014
|
}
|
|
1937
2015
|
.vditor-selection-popover__btn {
|
|
1938
2016
|
display: flex;
|
|
@@ -1948,7 +2026,6 @@
|
|
|
1948
2026
|
background: transparent;
|
|
1949
2027
|
color: var(--textarea-text-color);
|
|
1950
2028
|
cursor: pointer;
|
|
1951
|
-
border-radius: 8px;
|
|
1952
2029
|
outline: none;
|
|
1953
2030
|
font-size: 14px;
|
|
1954
2031
|
font-weight: 500;
|
|
@@ -1966,6 +2043,37 @@
|
|
|
1966
2043
|
.vditor-selection-popover__btn + .vditor-selection-popover__btn {
|
|
1967
2044
|
border-left: 1px solid var(--border-color);
|
|
1968
2045
|
}
|
|
2046
|
+
.vditor-reset .vditor-selection-tag {
|
|
2047
|
+
display: inline-flex;
|
|
2048
|
+
align-items: center;
|
|
2049
|
+
gap: 0.31rem;
|
|
2050
|
+
padding: 0.25rem 0.5rem;
|
|
2051
|
+
background-color: #f6f8fa;
|
|
2052
|
+
border: 1px solid #d1d5da;
|
|
2053
|
+
border-radius: 0.25rem;
|
|
2054
|
+
font-size: 0.875rem;
|
|
2055
|
+
line-height: 1.25rem;
|
|
2056
|
+
color: #0a0a0a;
|
|
2057
|
+
font-family: mononoki, Consolas, "Liberation Mono", Menlo, Courier, monospace, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols", "JetBrains Mono", "Fira Code", "Source Code Pro", monospace;
|
|
2058
|
+
margin: 0.25rem 0.25rem 0.25rem 0;
|
|
2059
|
+
}
|
|
2060
|
+
.vditor-reset .vditor-selection-tag__file {
|
|
2061
|
+
color: #0a0a0a;
|
|
2062
|
+
font-weight: 500;
|
|
2063
|
+
}
|
|
2064
|
+
.vditor-reset .vditor-selection-tag__lines {
|
|
2065
|
+
color: #586069;
|
|
2066
|
+
}
|
|
2067
|
+
.vditor--dark .vditor-reset .vditor-selection-tag {
|
|
2068
|
+
background-color: #2f363d;
|
|
2069
|
+
border-color: #141414;
|
|
2070
|
+
}
|
|
2071
|
+
.vditor--dark .vditor-reset .vditor-selection-tag .vditor-selection-tag__file {
|
|
2072
|
+
color: #fafafa;
|
|
2073
|
+
}
|
|
2074
|
+
.vditor--dark .vditor-reset .vditor-selection-tag .vditor-selection-tag__lines {
|
|
2075
|
+
color: #b9b9b9;
|
|
2076
|
+
}
|
|
1969
2077
|
details > summary {
|
|
1970
2078
|
list-style: none;
|
|
1971
2079
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.12 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -2818,7 +2818,7 @@ var Vditor = /** @class */ (function () {
|
|
|
2818
2818
|
/* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
|
|
2819
2819
|
/* harmony export */ "g": () => (/* binding */ Constants)
|
|
2820
2820
|
/* harmony export */ });
|
|
2821
|
-
var _VDITOR_VERSION = "0.0.
|
|
2821
|
+
var _VDITOR_VERSION = "0.0.12";
|
|
2822
2822
|
|
|
2823
2823
|
var Constants = /** @class */ (function () {
|
|
2824
2824
|
function Constants() {
|
|
@@ -3120,7 +3120,7 @@ var Constants = /** @class */ (function () {
|
|
|
3120
3120
|
"c#",
|
|
3121
3121
|
"bat",
|
|
3122
3122
|
];
|
|
3123
|
-
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.
|
|
3123
|
+
Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.12");
|
|
3124
3124
|
Constants.MARKDOWN_OPTIONS = {
|
|
3125
3125
|
autoSpace: false,
|
|
3126
3126
|
gfmAutoLink: true,
|
|
@@ -7836,6 +7836,22 @@ var processCodeRender = function (previewPanel, vditor) {
|
|
|
7836
7836
|
math: vditor.options.preview.math,
|
|
7837
7837
|
});
|
|
7838
7838
|
}
|
|
7839
|
+
else if (language === "selection") {
|
|
7840
|
+
// 渲染文件选择标签
|
|
7841
|
+
var content = previewPanel.textContent.trim();
|
|
7842
|
+
var lines = content.split('\n');
|
|
7843
|
+
var tags = lines.map(function (line) {
|
|
7844
|
+
var match = line.trim().match(/^(.+?)\s+(\d+-\d+)$/);
|
|
7845
|
+
if (match) {
|
|
7846
|
+
var filename = match[1], lineRange = match[2];
|
|
7847
|
+
return "<div class=\"vditor-selection-tag\">\n <span class=\"vditor-selection-tag__file\">".concat(filename, "</span>\n <span class=\"vditor-selection-tag__lines\">").concat(lineRange, "</span>\n </div>");
|
|
7848
|
+
}
|
|
7849
|
+
return '';
|
|
7850
|
+
}).filter(function (tag) { return tag; }).join('');
|
|
7851
|
+
if (tags) {
|
|
7852
|
+
previewPanel.innerHTML = tags;
|
|
7853
|
+
}
|
|
7854
|
+
}
|
|
7839
7855
|
else {
|
|
7840
7856
|
var cRender = vditor.options.customRenders.find(function (item) {
|
|
7841
7857
|
if (item.language === language) {
|
|
@@ -11767,15 +11783,11 @@ var hotkeyEvent = function (vditor, editorElement) {
|
|
|
11767
11783
|
* - 防抖间隔使用 options.selectionPopover.debounceDelay(默认 150ms)
|
|
11768
11784
|
*/
|
|
11769
11785
|
var selectEvent = function (vditor, editorElement) {
|
|
11770
|
-
var _a, _b;
|
|
11771
11786
|
var debounceTimer = 0;
|
|
11772
|
-
var delay = (_b = (_a = vditor.options.selectionPopover) === null || _a === void 0 ? void 0 : _a.debounceDelay) !== null && _b !== void 0 ? _b : 150;
|
|
11773
|
-
/**
|
|
11774
|
-
* 统一处理选择状态:根据选区内容显示/隐藏选择浮窗
|
|
11775
|
-
* - 鼠标拖选、键盘选择、触摸选择、系统 selectionchange
|
|
11776
|
-
*/
|
|
11777
11787
|
var handleSelection = function () {
|
|
11788
|
+
var _a, _b;
|
|
11778
11789
|
window.clearTimeout(debounceTimer);
|
|
11790
|
+
var delay = (_b = (_a = vditor.options.selectionPopover) === null || _a === void 0 ? void 0 : _a.debounceDelay) !== null && _b !== void 0 ? _b : 150;
|
|
11779
11791
|
debounceTimer = window.setTimeout(function () {
|
|
11780
11792
|
var _a;
|
|
11781
11793
|
var selectText = getSelectText(vditor[vditor.currentMode].element);
|
|
@@ -11798,44 +11810,17 @@ var selectEvent = function (vditor, editorElement) {
|
|
|
11798
11810
|
}
|
|
11799
11811
|
}, delay);
|
|
11800
11812
|
};
|
|
11801
|
-
|
|
11802
|
-
|
|
11803
|
-
// 触摸选择结束(移动端)
|
|
11804
|
-
editorElement.addEventListener("touchend", function () { return handleSelection(); }, {
|
|
11805
|
-
passive: true,
|
|
11813
|
+
editorElement.addEventListener("selectstart", function (event) {
|
|
11814
|
+
editorElement.onmouseup = handleSelection;
|
|
11806
11815
|
});
|
|
11807
|
-
// 键盘选择(Shift+方向键/Home/End 等)
|
|
11808
11816
|
editorElement.addEventListener("keyup", function (event) {
|
|
11809
|
-
if (event.
|
|
11810
|
-
|
|
11817
|
+
if (event.shiftKey && (event.key.startsWith("Arrow") || event.key === "Home" || event.key === "End")) {
|
|
11818
|
+
handleSelection();
|
|
11811
11819
|
}
|
|
11812
|
-
|
|
11813
|
-
|
|
11814
|
-
|
|
11815
|
-
document.addEventListener("selectionchange", function () {
|
|
11816
|
-
if (!(0,selection/* selectIsEditor */.Gb)(vditor[vditor.currentMode].element)) {
|
|
11817
|
-
return;
|
|
11820
|
+
else if (!event.shiftKey && (event.key.startsWith("Arrow") || event.key === "Escape")) {
|
|
11821
|
+
// Cancel selection or move cursor without selection
|
|
11822
|
+
handleSelection();
|
|
11818
11823
|
}
|
|
11819
|
-
handleSelection();
|
|
11820
|
-
});
|
|
11821
|
-
// 点击空白区域时隐藏浮窗并清理选区
|
|
11822
|
-
editorElement.addEventListener("click", function () {
|
|
11823
|
-
var selection = window.getSelection();
|
|
11824
|
-
var hadSelection = !!selection && selection.toString().trim() !== "";
|
|
11825
|
-
window.setTimeout(function () {
|
|
11826
|
-
var selectText = getSelectText(vditor[vditor.currentMode].element);
|
|
11827
|
-
if (!selectText.trim()) {
|
|
11828
|
-
if (vditor.currentMode === "wysiwyg") {
|
|
11829
|
-
vditor.wysiwyg.hideSelectionPopover();
|
|
11830
|
-
}
|
|
11831
|
-
if (hadSelection) {
|
|
11832
|
-
try {
|
|
11833
|
-
selection.removeAllRanges();
|
|
11834
|
-
}
|
|
11835
|
-
catch (_a) { }
|
|
11836
|
-
}
|
|
11837
|
-
}
|
|
11838
|
-
}, 0);
|
|
11839
11824
|
});
|
|
11840
11825
|
};
|
|
11841
11826
|
|
|
@@ -15263,6 +15248,31 @@ var Outline = /** @class */ (function () {
|
|
|
15263
15248
|
|
|
15264
15249
|
// EXTERNAL MODULE: ./src/ts/markdown/mediaRender.ts
|
|
15265
15250
|
var mediaRender = __webpack_require__(280);
|
|
15251
|
+
;// CONCATENATED MODULE: ./src/ts/markdown/selectionRender.ts
|
|
15252
|
+
/**
|
|
15253
|
+
* 渲染 selection 代码块为文件选择标签
|
|
15254
|
+
*/
|
|
15255
|
+
var selectionRender = function (element) {
|
|
15256
|
+
element.querySelectorAll("pre > code.language-selection").forEach(function (codeElement) {
|
|
15257
|
+
var preElement = codeElement.parentElement;
|
|
15258
|
+
var content = codeElement.textContent.trim();
|
|
15259
|
+
var lines = content.split('\n');
|
|
15260
|
+
var tags = lines.map(function (line) {
|
|
15261
|
+
var match = line.trim().match(/^(.+?)\s+(\d+-\d+)$/);
|
|
15262
|
+
if (match) {
|
|
15263
|
+
var filename = match[1], lineRange = match[2];
|
|
15264
|
+
return "<div class=\"vditor-selection-tag\">\n <span class=\"vditor-selection-tag__file\">".concat(filename, "</span>\n <span class=\"vditor-selection-tag__lines\">").concat(lineRange, "</span>\n </div>");
|
|
15265
|
+
}
|
|
15266
|
+
return '';
|
|
15267
|
+
}).filter(function (tag) { return tag; }).join('');
|
|
15268
|
+
if (tags) {
|
|
15269
|
+
var container = document.createElement('div');
|
|
15270
|
+
container.innerHTML = tags;
|
|
15271
|
+
preElement.parentNode.replaceChild(container, preElement);
|
|
15272
|
+
}
|
|
15273
|
+
});
|
|
15274
|
+
};
|
|
15275
|
+
|
|
15266
15276
|
;// CONCATENATED MODULE: ./src/ts/preview/index.ts
|
|
15267
15277
|
|
|
15268
15278
|
|
|
@@ -15281,6 +15291,7 @@ var mediaRender = __webpack_require__(280);
|
|
|
15281
15291
|
|
|
15282
15292
|
|
|
15283
15293
|
|
|
15294
|
+
|
|
15284
15295
|
var Preview = /** @class */ (function () {
|
|
15285
15296
|
/**
|
|
15286
15297
|
* 构造预览区域容器,注册复制与点击事件。
|
|
@@ -15444,8 +15455,11 @@ var Preview = /** @class */ (function () {
|
|
|
15444
15455
|
if (vditor.options.preview.render.media.enable) {
|
|
15445
15456
|
(0,mediaRender/* mediaRender */.Y)(vditor.preview.previewElement);
|
|
15446
15457
|
}
|
|
15458
|
+
selectionRender(vditor.preview.previewElement);
|
|
15447
15459
|
vditor.options.customRenders.forEach(function (item) {
|
|
15448
|
-
|
|
15460
|
+
{
|
|
15461
|
+
item.render(vditor.preview.previewElement, vditor);
|
|
15462
|
+
}
|
|
15449
15463
|
});
|
|
15450
15464
|
// toc render
|
|
15451
15465
|
var editorElement = vditor.preview.element;
|
|
@@ -17933,20 +17947,54 @@ var wysiwyg_generator = (undefined && undefined.__generator) || function (thisAr
|
|
|
17933
17947
|
var WYSIWYG = /** @class */ (function () {
|
|
17934
17948
|
function WYSIWYG(vditor) {
|
|
17935
17949
|
var _this = this;
|
|
17936
|
-
var _a;
|
|
17950
|
+
var _a, _b;
|
|
17937
17951
|
this.composingLock = false;
|
|
17938
17952
|
this.commentIds = [];
|
|
17953
|
+
this.vditor = vditor;
|
|
17939
17954
|
var divElement = document.createElement("div");
|
|
17940
17955
|
divElement.className = "vditor-wysiwyg";
|
|
17941
17956
|
if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
|
|
17942
17957
|
divElement.classList.add("vditor--linenumber");
|
|
17943
17958
|
}
|
|
17944
|
-
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-selection-popover\">\n <button type=\"button\" data-action=\"ai\" aria-label=\"AI\u7F16\u8F91\" class=\"vditor-selection-popover__btn\" disabled>\u2728 AI\u7F16\u8F91</button>\n
|
|
17959
|
+
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-selection-popover\">\n <div class=\"vditor-selection-popover__actions\">\n <button type=\"button\" data-action=\"ai\" aria-label=\"AI\u7F16\u8F91\" class=\"vditor-selection-popover__btn\" disabled>\u2728 AI\u7F16\u8F91</button>\n <button type=\"button\" data-action=\"cut\" aria-label=\"\u526A\u5207\" class=\"vditor-selection-popover__btn\">\u526A\u5207</button>\n <button type=\"button\" data-action=\"copy\" aria-label=\"\u590D\u5236\" class=\"vditor-selection-popover__btn\">\u590D\u5236</button>\n </div>\n <div class=\"vditor-selection-popover__input\">\n <textarea placeholder=\"\u8BF7\u8F93\u5165\u60A8\u60F3\u4FEE\u6539\u7684\u5185\u5BB9\"></textarea>\n <button class=\"vditor-selection-popover__send\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-sparkles-icon lucide-sparkles\"><path d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z\"/><path d=\"M20 2v4\"/><path d=\"M22 4h-4\"/><circle cx=\"4\" cy=\"20\" r=\"2\"/></svg>\n </button>\n </div>\n</div>");
|
|
17945
17960
|
this.element = divElement.firstElementChild;
|
|
17946
17961
|
this.popover = divElement.firstElementChild
|
|
17947
17962
|
.nextElementSibling;
|
|
17948
17963
|
this.selectPopover = divElement.lastElementChild;
|
|
17964
|
+
this.popoverInput = this.selectPopover.querySelector("textarea");
|
|
17965
|
+
this.popoverSendBtn = this.selectPopover.querySelector(".vditor-selection-popover__send");
|
|
17949
17966
|
this.bindEvent(vditor);
|
|
17967
|
+
// 绑定发送按钮事件
|
|
17968
|
+
if (this.popoverSendBtn) {
|
|
17969
|
+
this.popoverSendBtn.setAttribute("disabled", "disabled");
|
|
17970
|
+
this.popoverSendBtn.onclick = function (event) {
|
|
17971
|
+
event.stopPropagation();
|
|
17972
|
+
if (vditor.options.ai) {
|
|
17973
|
+
vditor.options.ai({
|
|
17974
|
+
value: _this.popoverInput.value,
|
|
17975
|
+
content: _this.selectionContent,
|
|
17976
|
+
lines: _this.selectionLines,
|
|
17977
|
+
});
|
|
17978
|
+
}
|
|
17979
|
+
_this.hideSelectionPopover();
|
|
17980
|
+
};
|
|
17981
|
+
// 阻止点击输入区域时清除选区
|
|
17982
|
+
(_b = this.selectPopover
|
|
17983
|
+
.querySelector(".vditor-selection-popover__input")) === null || _b === void 0 ? void 0 : _b.addEventListener("mousedown", function (event) {
|
|
17984
|
+
event.stopPropagation();
|
|
17985
|
+
});
|
|
17986
|
+
// 输入验证
|
|
17987
|
+
if (this.popoverInput) {
|
|
17988
|
+
this.popoverInput.addEventListener("input", function () {
|
|
17989
|
+
if (_this.popoverInput.value.trim().length > 0) {
|
|
17990
|
+
_this.popoverSendBtn.removeAttribute("disabled");
|
|
17991
|
+
}
|
|
17992
|
+
else {
|
|
17993
|
+
_this.popoverSendBtn.setAttribute("disabled", "disabled");
|
|
17994
|
+
}
|
|
17995
|
+
});
|
|
17996
|
+
}
|
|
17997
|
+
}
|
|
17950
17998
|
focusEvent(vditor, this.element);
|
|
17951
17999
|
dblclickEvent(vditor, this.element);
|
|
17952
18000
|
blurEvent(vditor, this.element);
|
|
@@ -18137,32 +18185,91 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18137
18185
|
if (range.toString().trim() === "") {
|
|
18138
18186
|
return;
|
|
18139
18187
|
}
|
|
18188
|
+
// 捕获选区内容(在选区丢失前)
|
|
18189
|
+
var fragment = range.cloneContents();
|
|
18190
|
+
var tempContainer = document.createElement("div");
|
|
18191
|
+
tempContainer.appendChild(fragment);
|
|
18192
|
+
this.selectionContent = this.vditor.lute
|
|
18193
|
+
.VditorDOM2Md(tempContainer.innerHTML)
|
|
18194
|
+
.trim();
|
|
18195
|
+
if (!this.selectionContent) {
|
|
18196
|
+
this.selectionContent = range.toString().trim();
|
|
18197
|
+
}
|
|
18198
|
+
// 捕获行号
|
|
18199
|
+
var getBlockIndex = function (node, editor) {
|
|
18200
|
+
var target = node;
|
|
18201
|
+
var directChild = null;
|
|
18202
|
+
// 向上遍历查找行号或直接子元素
|
|
18203
|
+
while (target && target.parentElement !== editor) {
|
|
18204
|
+
if (target instanceof Element &&
|
|
18205
|
+
target.hasAttribute("data-linenumber")) {
|
|
18206
|
+
return parseInt(target.getAttribute("data-linenumber"), 10);
|
|
18207
|
+
}
|
|
18208
|
+
target = target.parentNode;
|
|
18209
|
+
if (target && target.parentElement === editor) {
|
|
18210
|
+
directChild = target;
|
|
18211
|
+
}
|
|
18212
|
+
}
|
|
18213
|
+
// 检查直接子元素
|
|
18214
|
+
if (directChild && directChild.hasAttribute("data-linenumber")) {
|
|
18215
|
+
return parseInt(directChild.getAttribute("data-linenumber"), 10);
|
|
18216
|
+
}
|
|
18217
|
+
// 回退到使用子元素索引
|
|
18218
|
+
if (directChild) {
|
|
18219
|
+
return Array.from(editor.children).indexOf(directChild) + 1;
|
|
18220
|
+
}
|
|
18221
|
+
return 0;
|
|
18222
|
+
};
|
|
18223
|
+
var startLine = getBlockIndex(range.startContainer, this.element);
|
|
18224
|
+
var endLine = getBlockIndex(range.endContainer, this.element);
|
|
18225
|
+
this.selectionLines = [startLine, endLine];
|
|
18140
18226
|
var editorRect = this.element.getBoundingClientRect();
|
|
18141
18227
|
var rect = range.getBoundingClientRect();
|
|
18142
|
-
|
|
18143
|
-
|
|
18228
|
+
// 计算浮窗尺寸
|
|
18229
|
+
this.selectPopover.style.display = "flex";
|
|
18230
|
+
this.selectPopover.style.opacity = "0";
|
|
18231
|
+
var popoverHeight = this.selectPopover.offsetHeight;
|
|
18232
|
+
var popoverWidth = this.selectPopover.offsetWidth;
|
|
18233
|
+
// 理想位置:选区上方居中
|
|
18234
|
+
var top = rect.top - editorRect.top - popoverHeight - 8;
|
|
18235
|
+
var left = rect.left - editorRect.left + rect.width / 2 - popoverWidth / 2;
|
|
18236
|
+
// 边界检查:顶部超出则翻转到底部
|
|
18237
|
+
if (top < 0) {
|
|
18238
|
+
top = rect.bottom - editorRect.top + 8;
|
|
18239
|
+
}
|
|
18240
|
+
// 边界检查:左右限制
|
|
18241
|
+
var maxLeft = this.element.clientWidth - popoverWidth;
|
|
18242
|
+
left = Math.max(0, Math.min(left, maxLeft));
|
|
18144
18243
|
this.selectPopover.style.top = "".concat(top, "px");
|
|
18145
|
-
this.selectPopover.style.left = "".concat(
|
|
18146
|
-
|
|
18147
|
-
|
|
18148
|
-
|
|
18244
|
+
this.selectPopover.style.left = "".concat(left, "px");
|
|
18245
|
+
// 强制重排以触发过渡动画
|
|
18246
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
18247
|
+
this.selectPopover.offsetHeight;
|
|
18149
18248
|
this.selectPopover.style.opacity = "1";
|
|
18150
18249
|
this.selectPopover.style.transform = "scale(1)";
|
|
18151
|
-
this.popover.setAttribute("data-top",
|
|
18152
|
-
this.selectPopover.setAttribute("data-top",
|
|
18250
|
+
this.popover.setAttribute("data-top", top.toString());
|
|
18251
|
+
this.selectPopover.setAttribute("data-top", top.toString());
|
|
18153
18252
|
};
|
|
18154
18253
|
/**
|
|
18155
18254
|
* 隐藏选择浮窗(淡出)
|
|
18156
18255
|
*/
|
|
18157
18256
|
WYSIWYG.prototype.hideSelectionPopover = function () {
|
|
18158
18257
|
var _this = this;
|
|
18159
|
-
if (this.selectPopover.style.display !== "
|
|
18258
|
+
if (this.selectPopover.style.display !== "flex") {
|
|
18160
18259
|
return;
|
|
18161
18260
|
}
|
|
18162
18261
|
this.selectPopover.style.opacity = "0";
|
|
18163
18262
|
this.selectPopover.style.transform = "scale(0.95)";
|
|
18164
18263
|
window.setTimeout(function () {
|
|
18165
18264
|
_this.selectPopover.setAttribute("style", "display:none");
|
|
18265
|
+
// Reset state
|
|
18266
|
+
if (_this.popoverInput) {
|
|
18267
|
+
_this.popoverInput.value = "";
|
|
18268
|
+
}
|
|
18269
|
+
if (_this.popoverSendBtn) {
|
|
18270
|
+
_this.popoverSendBtn.classList.remove("vditor-selection-popover__send--loading");
|
|
18271
|
+
_this.popoverSendBtn.setAttribute("disabled", "disabled");
|
|
18272
|
+
}
|
|
18166
18273
|
}, 150);
|
|
18167
18274
|
};
|
|
18168
18275
|
/**
|
|
@@ -18399,7 +18506,7 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18399
18506
|
window.addEventListener("scroll", (this.scrollListener = function () {
|
|
18400
18507
|
hidePanel(vditor, ["hint"]);
|
|
18401
18508
|
if (_this.popover.style.display !== "block" ||
|
|
18402
|
-
_this.selectPopover.style.display !== "
|
|
18509
|
+
_this.selectPopover.style.display !== "flex") {
|
|
18403
18510
|
return;
|
|
18404
18511
|
}
|
|
18405
18512
|
var top = parseInt(_this.popover.getAttribute("data-top"), 10);
|
|
@@ -18410,7 +18517,7 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18410
18517
|
if (_this.popover.style.display === "block") {
|
|
18411
18518
|
_this.popover.style.top = popoverTop;
|
|
18412
18519
|
}
|
|
18413
|
-
if (_this.selectPopover.style.display === "
|
|
18520
|
+
if (_this.selectPopover.style.display === "flex") {
|
|
18414
18521
|
_this.selectPopover.style.top = popoverTop;
|
|
18415
18522
|
}
|
|
18416
18523
|
}
|
|
@@ -18423,7 +18530,7 @@ var WYSIWYG = /** @class */ (function () {
|
|
|
18423
18530
|
if (_this.popover.style.display === "block") {
|
|
18424
18531
|
_this.popover.style.top = popoverTop1;
|
|
18425
18532
|
}
|
|
18426
|
-
if (_this.selectPopover.style.display === "
|
|
18533
|
+
if (_this.selectPopover.style.display === "flex") {
|
|
18427
18534
|
_this.selectPopover.style.top = popoverTop1;
|
|
18428
18535
|
}
|
|
18429
18536
|
}));
|