md-editor-v3 4.19.0-5 → 4.19.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/lib/cjs/MdCatalog.cjs +2 -290
- package/lib/cjs/MdEditor.cjs +6 -277
- package/lib/cjs/MdModal.cjs +1 -1
- package/lib/cjs/ModalToolbar.cjs +1 -1
- package/lib/cjs/chunks/index.cjs +2 -2
- package/lib/cjs/chunks/index3.cjs +524 -238
- package/lib/cjs/chunks/index4.cjs +276 -49
- package/lib/cjs/chunks/index5.cjs +57 -0
- package/lib/cjs/index.cjs +3 -3
- package/lib/es/MdCatalog.mjs +2 -290
- package/lib/es/MdEditor.mjs +4 -275
- package/lib/es/MdModal.mjs +1 -1
- package/lib/es/ModalToolbar.mjs +1 -1
- package/lib/es/chunks/index.mjs +2 -2
- package/lib/es/chunks/index3.mjs +526 -240
- package/lib/es/chunks/index4.mjs +277 -50
- package/lib/es/chunks/index5.mjs +58 -0
- package/lib/es/index.mjs +3 -3
- package/lib/types/MdEditor/utils/scroll-auto.d.ts +1 -0
- package/lib/umd/index.js +26 -26
- package/package.json +1 -1
package/lib/cjs/MdCatalog.cjs
CHANGED
|
@@ -1,291 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const index = require("./chunks/index4.cjs");
|
|
5
|
-
const eventName = require("./chunks/event-name.cjs");
|
|
6
|
-
const props$1 = {
|
|
7
|
-
tocItem: {
|
|
8
|
-
type: Object,
|
|
9
|
-
default: () => ({})
|
|
10
|
-
},
|
|
11
|
-
mdHeadingId: {
|
|
12
|
-
type: Function,
|
|
13
|
-
default: () => {
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
onClick: {
|
|
17
|
-
type: Function,
|
|
18
|
-
default: () => {
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
scrollElementOffsetTop: {
|
|
22
|
-
type: Number,
|
|
23
|
-
default: 0
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
const CatalogLink = /* @__PURE__ */ vue.defineComponent({
|
|
27
|
-
props: props$1,
|
|
28
|
-
setup(props2) {
|
|
29
|
-
const scrollElementRef = vue.inject("scrollElementRef");
|
|
30
|
-
const rootNodeRef = vue.inject("roorNodeRef");
|
|
31
|
-
return () => {
|
|
32
|
-
const {
|
|
33
|
-
tocItem,
|
|
34
|
-
mdHeadingId,
|
|
35
|
-
onClick,
|
|
36
|
-
scrollElementOffsetTop
|
|
37
|
-
} = props2;
|
|
38
|
-
return vue.createVNode("div", {
|
|
39
|
-
"class": [`${config.prefix}-catalog-link`, tocItem.active && `${config.prefix}-catalog-active`],
|
|
40
|
-
"onClick": (e) => {
|
|
41
|
-
onClick(e, tocItem);
|
|
42
|
-
e.stopPropagation();
|
|
43
|
-
const id = mdHeadingId(tocItem.text, tocItem.level, tocItem.index);
|
|
44
|
-
const targetHeadEle = rootNodeRef.value.getElementById(id);
|
|
45
|
-
const scrollContainer = scrollElementRef.value;
|
|
46
|
-
if (targetHeadEle && scrollContainer) {
|
|
47
|
-
let par = targetHeadEle.offsetParent;
|
|
48
|
-
let offsetTop = targetHeadEle.offsetTop;
|
|
49
|
-
if (scrollContainer.contains(par)) {
|
|
50
|
-
while (par && scrollContainer != par) {
|
|
51
|
-
offsetTop += par == null ? void 0 : par.offsetTop;
|
|
52
|
-
par = par == null ? void 0 : par.offsetParent;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
scrollContainer == null ? void 0 : scrollContainer.scrollTo({
|
|
56
|
-
top: offsetTop - scrollElementOffsetTop,
|
|
57
|
-
behavior: "smooth"
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, [vue.createVNode("span", {
|
|
62
|
-
"title": tocItem.text
|
|
63
|
-
}, [tocItem.text]), vue.createVNode("div", {
|
|
64
|
-
"class": `${config.prefix}-catalog-wrapper`
|
|
65
|
-
}, [tocItem.children && tocItem.children.map((item) => vue.createVNode(CatalogLink, {
|
|
66
|
-
"mdHeadingId": mdHeadingId,
|
|
67
|
-
"key": `${tocItem.text}-link-${item.level}-${item.text}`,
|
|
68
|
-
"tocItem": item,
|
|
69
|
-
"onClick": onClick,
|
|
70
|
-
"scrollElementOffsetTop": scrollElementOffsetTop
|
|
71
|
-
}, null))])]);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
const CatalogLink$1 = CatalogLink;
|
|
76
|
-
const props = {
|
|
77
|
-
/**
|
|
78
|
-
* 编辑器的Id,务必与需要绑定的编辑器Id相同
|
|
79
|
-
*/
|
|
80
|
-
editorId: {
|
|
81
|
-
type: String
|
|
82
|
-
},
|
|
83
|
-
class: {
|
|
84
|
-
type: String,
|
|
85
|
-
default: ""
|
|
86
|
-
},
|
|
87
|
-
mdHeadingId: {
|
|
88
|
-
type: Function,
|
|
89
|
-
default: (text) => text
|
|
90
|
-
},
|
|
91
|
-
/**
|
|
92
|
-
* 指定滚动的容器,选择器需带上对应的符号,默认预览框
|
|
93
|
-
* 元素必须定位!!!!!!
|
|
94
|
-
*
|
|
95
|
-
* 默认:#md-editor-preview-wrapper
|
|
96
|
-
*/
|
|
97
|
-
scrollElement: {
|
|
98
|
-
type: [String, Object]
|
|
99
|
-
},
|
|
100
|
-
theme: {
|
|
101
|
-
type: String,
|
|
102
|
-
default: "light"
|
|
103
|
-
},
|
|
104
|
-
/**
|
|
105
|
-
* 高亮标题相对滚动容器顶部偏移量,即距离该值时,高亮当前目录菜单项
|
|
106
|
-
*
|
|
107
|
-
* 默认:20px
|
|
108
|
-
*/
|
|
109
|
-
offsetTop: {
|
|
110
|
-
type: Number,
|
|
111
|
-
default: 20
|
|
112
|
-
},
|
|
113
|
-
/**
|
|
114
|
-
* 滚动区域的固定顶部高度
|
|
115
|
-
*
|
|
116
|
-
* 默认:0
|
|
117
|
-
*/
|
|
118
|
-
scrollElementOffsetTop: {
|
|
119
|
-
type: Number,
|
|
120
|
-
default: 0
|
|
121
|
-
},
|
|
122
|
-
onClick: {
|
|
123
|
-
type: Function
|
|
124
|
-
},
|
|
125
|
-
onActive: {
|
|
126
|
-
type: Function
|
|
127
|
-
},
|
|
128
|
-
/**
|
|
129
|
-
* 滚动容器是否在web component中,默认不在
|
|
130
|
-
*
|
|
131
|
-
* 在其中的话通过document查询不到
|
|
132
|
-
*/
|
|
133
|
-
isScrollElementInShadow: {
|
|
134
|
-
type: Boolean,
|
|
135
|
-
default: false
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const MdCatalog = /* @__PURE__ */ vue.defineComponent({
|
|
139
|
-
name: "MdCatalog",
|
|
140
|
-
props,
|
|
141
|
-
emits: ["onClick", "onActive"],
|
|
142
|
-
setup(props2, ctx) {
|
|
143
|
-
const editorId = props2.editorId;
|
|
144
|
-
const defaultScrollElement = `#${editorId}-preview-wrapper`;
|
|
145
|
-
const state = vue.reactive({
|
|
146
|
-
list: [],
|
|
147
|
-
show: false,
|
|
148
|
-
scrollElement: props2.scrollElement || defaultScrollElement
|
|
149
|
-
});
|
|
150
|
-
const activeItem = vue.shallowRef();
|
|
151
|
-
const catalogRef = vue.ref();
|
|
152
|
-
const scrollElementRef = vue.ref();
|
|
153
|
-
const rootNodeRef = vue.ref();
|
|
154
|
-
vue.provide("scrollElementRef", scrollElementRef);
|
|
155
|
-
vue.provide("roorNodeRef", rootNodeRef);
|
|
156
|
-
const catalogs = vue.computed(() => {
|
|
157
|
-
const tocItems = [];
|
|
158
|
-
state.list.forEach((listItem, index2) => {
|
|
159
|
-
const {
|
|
160
|
-
text,
|
|
161
|
-
level
|
|
162
|
-
} = listItem;
|
|
163
|
-
const item = {
|
|
164
|
-
level,
|
|
165
|
-
text,
|
|
166
|
-
index: index2 + 1,
|
|
167
|
-
active: activeItem.value === listItem
|
|
168
|
-
};
|
|
169
|
-
if (tocItems.length === 0) {
|
|
170
|
-
tocItems.push(item);
|
|
171
|
-
} else {
|
|
172
|
-
let lastItem = tocItems[tocItems.length - 1];
|
|
173
|
-
if (item.level > lastItem.level) {
|
|
174
|
-
for (let i = lastItem.level + 1; i <= 6; i++) {
|
|
175
|
-
const {
|
|
176
|
-
children
|
|
177
|
-
} = lastItem;
|
|
178
|
-
if (!children) {
|
|
179
|
-
lastItem.children = [item];
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
lastItem = children[children.length - 1];
|
|
183
|
-
if (item.level <= lastItem.level) {
|
|
184
|
-
children.push(item);
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
tocItems.push(item);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
return tocItems;
|
|
194
|
-
});
|
|
195
|
-
const getScrollElement = () => {
|
|
196
|
-
var _a;
|
|
197
|
-
if (state.scrollElement instanceof HTMLElement) {
|
|
198
|
-
return state.scrollElement;
|
|
199
|
-
}
|
|
200
|
-
let scrollRoot = document;
|
|
201
|
-
if (state.scrollElement === defaultScrollElement || props2.isScrollElementInShadow) {
|
|
202
|
-
scrollRoot = (_a = catalogRef.value) == null ? void 0 : _a.getRootNode();
|
|
203
|
-
}
|
|
204
|
-
return scrollRoot.querySelector(state.scrollElement);
|
|
205
|
-
};
|
|
206
|
-
const findActiveHeading = (list) => {
|
|
207
|
-
if (list.length === 0) {
|
|
208
|
-
state.list = [];
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
const {
|
|
212
|
-
activeHead
|
|
213
|
-
} = list.reduce((activeData, link, index$1) => {
|
|
214
|
-
var _a;
|
|
215
|
-
const linkEle = (_a = rootNodeRef.value) == null ? void 0 : _a.getElementById(props2.mdHeadingId(link.text, link.level, index$1 + 1));
|
|
216
|
-
if (linkEle instanceof HTMLElement) {
|
|
217
|
-
const relativeTop = index.getRelativeTop(linkEle, scrollElementRef.value);
|
|
218
|
-
if (relativeTop < props2.offsetTop && relativeTop > activeData.minTop) {
|
|
219
|
-
return {
|
|
220
|
-
activeHead: link,
|
|
221
|
-
minTop: relativeTop
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return activeData;
|
|
226
|
-
}, {
|
|
227
|
-
activeHead: list[0],
|
|
228
|
-
minTop: Number.MIN_SAFE_INTEGER
|
|
229
|
-
});
|
|
230
|
-
activeItem.value = activeHead;
|
|
231
|
-
state.list = list;
|
|
232
|
-
};
|
|
233
|
-
const scrollHandler = () => {
|
|
234
|
-
findActiveHeading(state.list);
|
|
235
|
-
};
|
|
236
|
-
vue.watch(() => activeItem.value, (nVal) => {
|
|
237
|
-
const activeHeading = nVal ? {
|
|
238
|
-
...nVal
|
|
239
|
-
} : void 0;
|
|
240
|
-
if (props2.onActive) {
|
|
241
|
-
props2.onActive(activeHeading);
|
|
242
|
-
} else {
|
|
243
|
-
ctx.emit("onActive", activeHeading);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
vue.onMounted(() => {
|
|
247
|
-
rootNodeRef.value = catalogRef.value.getRootNode();
|
|
248
|
-
let scrollElement = getScrollElement();
|
|
249
|
-
scrollElementRef.value = scrollElement;
|
|
250
|
-
eventName.bus.on(editorId, {
|
|
251
|
-
name: eventName.CATALOG_CHANGED,
|
|
252
|
-
callback: (_list) => {
|
|
253
|
-
scrollElement = getScrollElement();
|
|
254
|
-
scrollElementRef.value = scrollElement;
|
|
255
|
-
scrollElement == null ? void 0 : scrollElement.removeEventListener("scroll", scrollHandler);
|
|
256
|
-
findActiveHeading(_list);
|
|
257
|
-
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
eventName.bus.emit(editorId, eventName.PUSH_CATALOG);
|
|
261
|
-
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
262
|
-
});
|
|
263
|
-
vue.onBeforeUnmount(() => {
|
|
264
|
-
var _a;
|
|
265
|
-
(_a = scrollElementRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
266
|
-
});
|
|
267
|
-
return () => vue.createVNode("div", {
|
|
268
|
-
"class": [`${config.prefix}-catalog${props2.theme === "dark" ? "-dark" : ""}`, `${props2.class}`],
|
|
269
|
-
"ref": catalogRef
|
|
270
|
-
}, [catalogs.value.map((item) => {
|
|
271
|
-
return vue.createVNode(CatalogLink$1, {
|
|
272
|
-
"mdHeadingId": props2.mdHeadingId,
|
|
273
|
-
"tocItem": item,
|
|
274
|
-
"key": `link-${item.level}-${item.text}`,
|
|
275
|
-
"onClick": (e, t) => {
|
|
276
|
-
if (props2.onClick) {
|
|
277
|
-
props2.onClick(e, t);
|
|
278
|
-
} else {
|
|
279
|
-
ctx.emit("onClick", e, t);
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
"scrollElementOffsetTop": props2.scrollElementOffsetTop
|
|
283
|
-
}, null);
|
|
284
|
-
})]);
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
MdCatalog.install = (app) => {
|
|
288
|
-
app.component(MdCatalog.name, MdCatalog);
|
|
289
|
-
return app;
|
|
290
|
-
};
|
|
291
|
-
module.exports = MdCatalog;
|
|
2
|
+
const MdCatalog = require("./chunks/index3.cjs");
|
|
3
|
+
module.exports = MdCatalog.MdCatalog;
|
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -11,8 +11,9 @@ const util = require("@vavt/util");
|
|
|
11
11
|
const DropdownToolbar = require("./chunks/index2.cjs");
|
|
12
12
|
const eventName = require("./chunks/event-name.cjs");
|
|
13
13
|
const dom = require("./chunks/dom.cjs");
|
|
14
|
-
const MdModal = require("./chunks/
|
|
15
|
-
const index = require("./chunks/
|
|
14
|
+
const MdModal = require("./chunks/index4.cjs");
|
|
15
|
+
const index = require("./chunks/index5.cjs");
|
|
16
|
+
const MdCatalog = require("./chunks/index3.cjs");
|
|
16
17
|
const codemirror = require("codemirror");
|
|
17
18
|
const view = require("@codemirror/view");
|
|
18
19
|
const languageData = require("@codemirror/language-data");
|
|
@@ -24,7 +25,6 @@ const highlight = require("@lezer/highlight");
|
|
|
24
25
|
const autocomplete = require("@codemirror/autocomplete");
|
|
25
26
|
const search = require("@codemirror/search");
|
|
26
27
|
const MdPreview = require("./chunks/index.cjs");
|
|
27
|
-
const MdCatalog = require("./MdCatalog.cjs");
|
|
28
28
|
const vueTsx = require("./chunks/vue-tsx.cjs");
|
|
29
29
|
const NormalToolbar = require("./NormalToolbar.cjs");
|
|
30
30
|
const ModalToolbar = require("./ModalToolbar.cjs");
|
|
@@ -1235,277 +1235,6 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
|
|
|
1235
1235
|
};
|
|
1236
1236
|
}
|
|
1237
1237
|
});
|
|
1238
|
-
const DATA_LINE_SELECTOR = `.${config.prefix}-preview > [data-line]`;
|
|
1239
|
-
const getComputedStyleNum = (ele, key) => {
|
|
1240
|
-
return +getComputedStyle(ele).getPropertyValue(key).replace("px", "");
|
|
1241
|
-
};
|
|
1242
|
-
const scrollAutoWithScale = (pEle, cEle) => {
|
|
1243
|
-
const addEvent = util.debounce(() => {
|
|
1244
|
-
pEle.removeEventListener("scroll", scrollHandler);
|
|
1245
|
-
pEle.addEventListener("scroll", scrollHandler);
|
|
1246
|
-
cEle.removeEventListener("scroll", scrollHandler);
|
|
1247
|
-
cEle.addEventListener("scroll", scrollHandler);
|
|
1248
|
-
}, 50);
|
|
1249
|
-
const scrollHandler = (e) => {
|
|
1250
|
-
const pHeight = pEle.clientHeight;
|
|
1251
|
-
const cHeight = cEle.clientHeight;
|
|
1252
|
-
const pScrollHeight = pEle.scrollHeight;
|
|
1253
|
-
const cScrollHeight = cEle.scrollHeight;
|
|
1254
|
-
const scale = (pScrollHeight - pHeight) / (cScrollHeight - cHeight);
|
|
1255
|
-
if (e.target === pEle) {
|
|
1256
|
-
cEle.removeEventListener("scroll", scrollHandler);
|
|
1257
|
-
cEle.scrollTo({
|
|
1258
|
-
top: pEle.scrollTop / scale
|
|
1259
|
-
// behavior: 'smooth'
|
|
1260
|
-
});
|
|
1261
|
-
addEvent();
|
|
1262
|
-
} else {
|
|
1263
|
-
pEle.removeEventListener("scroll", scrollHandler);
|
|
1264
|
-
pEle.scrollTo({
|
|
1265
|
-
top: cEle.scrollTop * scale
|
|
1266
|
-
// behavior: 'smooth'
|
|
1267
|
-
});
|
|
1268
|
-
addEvent();
|
|
1269
|
-
}
|
|
1270
|
-
};
|
|
1271
|
-
return [
|
|
1272
|
-
() => {
|
|
1273
|
-
addEvent().finally(() => {
|
|
1274
|
-
pEle.dispatchEvent(new Event("scroll"));
|
|
1275
|
-
});
|
|
1276
|
-
},
|
|
1277
|
-
() => {
|
|
1278
|
-
pEle.removeEventListener("scroll", scrollHandler);
|
|
1279
|
-
cEle.removeEventListener("scroll", scrollHandler);
|
|
1280
|
-
}
|
|
1281
|
-
];
|
|
1282
|
-
};
|
|
1283
|
-
const scrollAuto = (pEle, cEle, codeMirrorUt) => {
|
|
1284
|
-
const { view: view2 } = codeMirrorUt;
|
|
1285
|
-
const smoothScroll = util.createSmoothScroll();
|
|
1286
|
-
const getTopByLine = (line) => {
|
|
1287
|
-
return view2.lineBlockAt(view2.state.doc.line(line + 1).from).top;
|
|
1288
|
-
};
|
|
1289
|
-
const getBottomByLine = (line) => {
|
|
1290
|
-
return view2.lineBlockAt(view2.state.doc.line(line + 1).from).bottom;
|
|
1291
|
-
};
|
|
1292
|
-
let blockMap = [];
|
|
1293
|
-
let elesHasLineNumber = [];
|
|
1294
|
-
let startLines = [];
|
|
1295
|
-
const buildMap = () => {
|
|
1296
|
-
blockMap = [];
|
|
1297
|
-
elesHasLineNumber = Array.from(
|
|
1298
|
-
cEle.querySelectorAll(DATA_LINE_SELECTOR)
|
|
1299
|
-
);
|
|
1300
|
-
startLines = elesHasLineNumber.map((item) => Number(item.dataset.line));
|
|
1301
|
-
const tempStartLines = [...startLines];
|
|
1302
|
-
const { lines } = view2.state.doc;
|
|
1303
|
-
let start = tempStartLines.shift() || 0;
|
|
1304
|
-
let end = tempStartLines.shift() || lines;
|
|
1305
|
-
for (let i = 0; i < lines; i++) {
|
|
1306
|
-
if (i === end) {
|
|
1307
|
-
start = i;
|
|
1308
|
-
end = tempStartLines.shift() || lines;
|
|
1309
|
-
}
|
|
1310
|
-
blockMap.push({
|
|
1311
|
-
start,
|
|
1312
|
-
end: end - 1
|
|
1313
|
-
});
|
|
1314
|
-
}
|
|
1315
|
-
};
|
|
1316
|
-
const getLineNumber = (pMaxScrollLength, cMaxScrollLength) => {
|
|
1317
|
-
let lineNumer = 1;
|
|
1318
|
-
for (let i = elesHasLineNumber.length - 1; i - 1 >= 0; i--) {
|
|
1319
|
-
const curr = elesHasLineNumber[i];
|
|
1320
|
-
const sibling = elesHasLineNumber[i - 1];
|
|
1321
|
-
if (curr.offsetTop + curr.offsetHeight > cMaxScrollLength && sibling.offsetTop < cMaxScrollLength) {
|
|
1322
|
-
lineNumer = Number(sibling.dataset.line);
|
|
1323
|
-
break;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
for (let i = blockMap.length - 1; i >= 0; i--) {
|
|
1327
|
-
const itemBottom = getBottomByLine(blockMap[i].end);
|
|
1328
|
-
const itemTop = getTopByLine(blockMap[i].start);
|
|
1329
|
-
if (itemBottom > pMaxScrollLength && itemTop <= pMaxScrollLength) {
|
|
1330
|
-
lineNumer = lineNumer < blockMap[i].start ? lineNumer : blockMap[i].start;
|
|
1331
|
-
break;
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
return lineNumer;
|
|
1335
|
-
};
|
|
1336
|
-
let pLock = 0;
|
|
1337
|
-
let cLock = 0;
|
|
1338
|
-
const pEleHandler = () => {
|
|
1339
|
-
var _a, _b, _c;
|
|
1340
|
-
if (cLock !== 0) {
|
|
1341
|
-
return false;
|
|
1342
|
-
}
|
|
1343
|
-
pLock++;
|
|
1344
|
-
const { scrollDOM, contentHeight } = view2;
|
|
1345
|
-
let cElePaddingTop = getComputedStyleNum(cEle, "padding-top");
|
|
1346
|
-
const blockInfo = view2.lineBlockAtHeight(scrollDOM.scrollTop);
|
|
1347
|
-
const { number: currLine } = view2.state.doc.lineAt(blockInfo.from);
|
|
1348
|
-
const blockData = blockMap[currLine - 1];
|
|
1349
|
-
if (!blockData) {
|
|
1350
|
-
return false;
|
|
1351
|
-
}
|
|
1352
|
-
let scale = 1;
|
|
1353
|
-
const startEle = cEle.querySelector(`[data-line="${blockData.start}"]`) || ((_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild);
|
|
1354
|
-
const endEle = cEle.querySelector(`[data-line="${blockData.end + 1}"]`) || ((_b = cEle.lastElementChild) == null ? void 0 : _b.lastElementChild);
|
|
1355
|
-
const pMaxScrollLength = scrollDOM.scrollHeight - scrollDOM.clientHeight;
|
|
1356
|
-
const cMaxScrollLength = cEle.scrollHeight - cEle.clientHeight;
|
|
1357
|
-
let startTop = getTopByLine(blockData.start);
|
|
1358
|
-
let endBottom = getBottomByLine(blockData.end);
|
|
1359
|
-
let startEleOffetTop = startEle.offsetTop;
|
|
1360
|
-
let blockHeight = endEle.offsetTop - startEleOffetTop;
|
|
1361
|
-
if (startTop === 0) {
|
|
1362
|
-
startEleOffetTop = 0;
|
|
1363
|
-
if (startEle === endEle) {
|
|
1364
|
-
cElePaddingTop = 0;
|
|
1365
|
-
endBottom = contentHeight - scrollDOM.offsetHeight;
|
|
1366
|
-
blockHeight = cMaxScrollLength;
|
|
1367
|
-
} else {
|
|
1368
|
-
blockHeight = endEle.offsetTop;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
scale = (scrollDOM.scrollTop - startTop) / (endBottom - startTop);
|
|
1372
|
-
const endElePos = endEle == ((_c = cEle.lastElementChild) == null ? void 0 : _c.lastElementChild) ? endEle.offsetTop + endEle.clientHeight : endEle.offsetTop;
|
|
1373
|
-
if (endBottom >= pMaxScrollLength || endElePos > cMaxScrollLength) {
|
|
1374
|
-
const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
|
|
1375
|
-
startTop = getTopByLine(lineNumer);
|
|
1376
|
-
scale = (scrollDOM.scrollTop - startTop) / (pMaxScrollLength - startTop);
|
|
1377
|
-
const _startEle = cEle.querySelector(`[data-line="${lineNumer}"]`);
|
|
1378
|
-
if (startTop > 0 && _startEle) {
|
|
1379
|
-
startEleOffetTop = _startEle.offsetTop;
|
|
1380
|
-
}
|
|
1381
|
-
blockHeight = cMaxScrollLength - startEleOffetTop + getComputedStyleNum(cEle, "padding-top");
|
|
1382
|
-
}
|
|
1383
|
-
const scrollToTop = startEleOffetTop - cElePaddingTop + blockHeight * scale;
|
|
1384
|
-
smoothScroll(cEle, scrollToTop, () => {
|
|
1385
|
-
pLock--;
|
|
1386
|
-
});
|
|
1387
|
-
};
|
|
1388
|
-
const cEleHandler = () => {
|
|
1389
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1390
|
-
if (pLock !== 0) {
|
|
1391
|
-
return;
|
|
1392
|
-
}
|
|
1393
|
-
cLock++;
|
|
1394
|
-
const { scrollDOM } = view2;
|
|
1395
|
-
const cScrollTop = cEle.scrollTop;
|
|
1396
|
-
const cScrollHeight = cEle.scrollHeight;
|
|
1397
|
-
const pMaxScrollLength = scrollDOM.scrollHeight - scrollDOM.clientHeight;
|
|
1398
|
-
const cMaxScrollLength = cEle.scrollHeight - cEle.clientHeight;
|
|
1399
|
-
let realEleStart = (_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild;
|
|
1400
|
-
let realEleEnd = (_b = cEle.firstElementChild) == null ? void 0 : _b.lastElementChild;
|
|
1401
|
-
if (startLines.length > 0) {
|
|
1402
|
-
let virtualLine = Math.ceil(
|
|
1403
|
-
startLines[startLines.length - 1] * (cScrollTop / cScrollHeight)
|
|
1404
|
-
);
|
|
1405
|
-
let startLineIndex = startLines.findLastIndex((value) => value <= virtualLine);
|
|
1406
|
-
startLineIndex = startLineIndex === -1 ? 0 : startLineIndex;
|
|
1407
|
-
virtualLine = startLines[startLineIndex];
|
|
1408
|
-
for (let i = startLineIndex; i >= 0 && i < startLines.length; ) {
|
|
1409
|
-
const currentElementTop = elesHasLineNumber[i].offsetTop;
|
|
1410
|
-
if (currentElementTop > cScrollTop) {
|
|
1411
|
-
if (i - 1 >= 0) {
|
|
1412
|
-
i--;
|
|
1413
|
-
continue;
|
|
1414
|
-
}
|
|
1415
|
-
virtualLine = -1;
|
|
1416
|
-
startLineIndex = i;
|
|
1417
|
-
break;
|
|
1418
|
-
} else {
|
|
1419
|
-
if (i + 1 < startLines.length && elesHasLineNumber[i + 1].offsetTop < cScrollTop) {
|
|
1420
|
-
i++;
|
|
1421
|
-
continue;
|
|
1422
|
-
}
|
|
1423
|
-
virtualLine = startLines[i];
|
|
1424
|
-
startLineIndex = i;
|
|
1425
|
-
break;
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
switch (startLineIndex) {
|
|
1429
|
-
case -1: {
|
|
1430
|
-
realEleStart = (_c = cEle.firstElementChild) == null ? void 0 : _c.firstElementChild;
|
|
1431
|
-
realEleEnd = elesHasLineNumber[startLineIndex];
|
|
1432
|
-
break;
|
|
1433
|
-
}
|
|
1434
|
-
case startLines.length - 1: {
|
|
1435
|
-
realEleStart = elesHasLineNumber[startLineIndex];
|
|
1436
|
-
realEleEnd = (_d = cEle.firstElementChild) == null ? void 0 : _d.lastElementChild;
|
|
1437
|
-
break;
|
|
1438
|
-
}
|
|
1439
|
-
default: {
|
|
1440
|
-
realEleStart = elesHasLineNumber[startLineIndex];
|
|
1441
|
-
realEleEnd = elesHasLineNumber[startLineIndex + 1 === elesHasLineNumber.length ? startLineIndex : startLineIndex + 1];
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
let eleStartOffsetTop = realEleStart === ((_e = cEle.firstElementChild) == null ? void 0 : _e.firstElementChild) ? 0 : realEleStart.offsetTop - getComputedStyleNum(realEleStart, "margin-top");
|
|
1446
|
-
let eleEndOffsetTop = realEleEnd.offsetTop;
|
|
1447
|
-
let scale = 0;
|
|
1448
|
-
const { start, end } = blockMap[Number(realEleStart.dataset.line || 0)];
|
|
1449
|
-
let firstLineScrollTop = getTopByLine(start);
|
|
1450
|
-
const endLineScrollTop = getTopByLine(
|
|
1451
|
-
end + 1 === view2.state.doc.lines ? end : end + 1
|
|
1452
|
-
);
|
|
1453
|
-
let blockHeight = 0;
|
|
1454
|
-
if (endLineScrollTop > pMaxScrollLength || realEleEnd.offsetTop + realEleEnd.offsetHeight > cMaxScrollLength) {
|
|
1455
|
-
const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
|
|
1456
|
-
const _startEle = cEle.querySelector(`[data-line="${lineNumer}"]`);
|
|
1457
|
-
eleStartOffsetTop = _startEle ? _startEle.offsetTop - getComputedStyleNum(_startEle, "margin-top") : eleStartOffsetTop;
|
|
1458
|
-
firstLineScrollTop = getTopByLine(lineNumer);
|
|
1459
|
-
scale = (cScrollTop - eleStartOffsetTop) / (cMaxScrollLength - eleStartOffsetTop);
|
|
1460
|
-
blockHeight = pMaxScrollLength - firstLineScrollTop;
|
|
1461
|
-
} else if (realEleStart === ((_f = cEle.firstElementChild) == null ? void 0 : _f.firstElementChild)) {
|
|
1462
|
-
if (realEleStart === realEleEnd) {
|
|
1463
|
-
eleEndOffsetTop = realEleEnd.offsetTop + realEleEnd.offsetHeight + +getComputedStyle(realEleEnd).marginBottom.replace("px", "");
|
|
1464
|
-
blockHeight = endLineScrollTop;
|
|
1465
|
-
} else {
|
|
1466
|
-
blockHeight = endLineScrollTop;
|
|
1467
|
-
}
|
|
1468
|
-
scale = Math.max(cScrollTop / eleEndOffsetTop, 0);
|
|
1469
|
-
} else {
|
|
1470
|
-
scale = Math.max(
|
|
1471
|
-
(cScrollTop - eleStartOffsetTop) / (eleEndOffsetTop - eleStartOffsetTop),
|
|
1472
|
-
0
|
|
1473
|
-
);
|
|
1474
|
-
blockHeight = endLineScrollTop - firstLineScrollTop;
|
|
1475
|
-
}
|
|
1476
|
-
smoothScroll(pEle, firstLineScrollTop + blockHeight * scale, () => {
|
|
1477
|
-
cLock--;
|
|
1478
|
-
});
|
|
1479
|
-
};
|
|
1480
|
-
const scrollHandler = (e) => {
|
|
1481
|
-
var _a;
|
|
1482
|
-
const { scrollDOM, contentHeight } = view2;
|
|
1483
|
-
const scrollDomHeight = scrollDOM.clientHeight;
|
|
1484
|
-
if (contentHeight <= scrollDomHeight || cEle.firstElementChild.clientHeight <= cEle.clientHeight) {
|
|
1485
|
-
return false;
|
|
1486
|
-
}
|
|
1487
|
-
if (view2.state.doc.lines <= ((_a = blockMap[blockMap.length - 1]) == null ? void 0 : _a.end)) {
|
|
1488
|
-
return false;
|
|
1489
|
-
}
|
|
1490
|
-
if (e.target === pEle) {
|
|
1491
|
-
pEleHandler();
|
|
1492
|
-
} else {
|
|
1493
|
-
cEleHandler();
|
|
1494
|
-
}
|
|
1495
|
-
};
|
|
1496
|
-
return [
|
|
1497
|
-
() => {
|
|
1498
|
-
buildMap();
|
|
1499
|
-
pEle.addEventListener("scroll", scrollHandler);
|
|
1500
|
-
cEle.addEventListener("scroll", scrollHandler);
|
|
1501
|
-
pEle.dispatchEvent(new Event("scroll"));
|
|
1502
|
-
},
|
|
1503
|
-
() => {
|
|
1504
|
-
pEle.removeEventListener("scroll", scrollHandler);
|
|
1505
|
-
cEle.removeEventListener("scroll", scrollHandler);
|
|
1506
|
-
}
|
|
1507
|
-
];
|
|
1508
|
-
};
|
|
1509
1238
|
const useAutoScroll = (props2, html, codeMirrorUt) => {
|
|
1510
1239
|
const editorId = vue.inject("editorId");
|
|
1511
1240
|
let clearScrollAuto = () => {
|
|
@@ -1526,7 +1255,7 @@ const useAutoScroll = (props2, html, codeMirrorUt) => {
|
|
|
1526
1255
|
`[id="${editorId}-html-wrapper"]`
|
|
1527
1256
|
);
|
|
1528
1257
|
if (previewEle || htmlEle) {
|
|
1529
|
-
const scrollHandler = previewEle ? scrollAuto : scrollAutoWithScale;
|
|
1258
|
+
const scrollHandler = previewEle ? MdCatalog.scrollAuto : MdCatalog.scrollAutoWithScale;
|
|
1530
1259
|
const cEle = previewEle || htmlEle;
|
|
1531
1260
|
[initScrollAuto, clearScrollAuto] = scrollHandler(
|
|
1532
1261
|
cmScroller,
|
|
@@ -3019,7 +2748,7 @@ const Content = /* @__PURE__ */ vue.defineComponent({
|
|
|
3019
2748
|
"sanitizeMermaid": props2.sanitizeMermaid,
|
|
3020
2749
|
"codeFoldable": props2.codeFoldable,
|
|
3021
2750
|
"autoFoldThreshold": props2.autoFoldThreshold
|
|
3022
|
-
}, null), props2.catalogVisible && vue.createVNode(MdCatalog, {
|
|
2751
|
+
}, null), props2.catalogVisible && vue.createVNode(MdCatalog.MdCatalog, {
|
|
3023
2752
|
"theme": props2.theme,
|
|
3024
2753
|
"class": `${config.prefix}-catalog-editor`,
|
|
3025
2754
|
"editorId": editorId,
|
|
@@ -3313,7 +3042,7 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
|
|
|
3313
3042
|
});
|
|
3314
3043
|
Editor.install = (app) => {
|
|
3315
3044
|
app.component(Editor.name, Editor);
|
|
3316
|
-
app.use(NormalToolbar).use(DropdownToolbar.DropdownToolbar).use(ModalToolbar).use(MdCatalog).use(MdPreview.MdPreview);
|
|
3045
|
+
app.use(NormalToolbar).use(DropdownToolbar.DropdownToolbar).use(ModalToolbar).use(MdCatalog.MdCatalog).use(MdPreview.MdPreview);
|
|
3317
3046
|
return app;
|
|
3318
3047
|
};
|
|
3319
3048
|
module.exports = Editor;
|
package/lib/cjs/MdModal.cjs
CHANGED
package/lib/cjs/ModalToolbar.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const vue = require("vue");
|
|
3
3
|
const config = require("./chunks/config.cjs");
|
|
4
4
|
const vueTsx = require("./chunks/vue-tsx.cjs");
|
|
5
|
-
const MdModal = require("./chunks/
|
|
5
|
+
const MdModal = require("./chunks/index4.cjs");
|
|
6
6
|
function _isSlot(s) {
|
|
7
7
|
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
|
|
8
8
|
}
|
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ const mediumZoom = require("medium-zoom");
|
|
|
8
8
|
const copy = require("copy-to-clipboard");
|
|
9
9
|
const mdit = require("markdown-it");
|
|
10
10
|
const ImageFiguresPlugin = require("markdown-it-image-figures");
|
|
11
|
-
const index$1 = require("./
|
|
11
|
+
const index$1 = require("./index5.cjs");
|
|
12
12
|
const lruCache = require("lru-cache");
|
|
13
13
|
function _mergeNamespaces(n, m) {
|
|
14
14
|
for (var i = 0; i < m.length; i++) {
|
|
@@ -129,7 +129,7 @@ const useHighlight = (props) => {
|
|
|
129
129
|
vue.watch(
|
|
130
130
|
() => highlight.value.css,
|
|
131
131
|
() => {
|
|
132
|
-
if (props.noHighlight) {
|
|
132
|
+
if (props.noHighlight || hljsRef.value) {
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
135
|
dom.updateHandler("link", {
|