md-editor-v3 4.19.0-4 → 4.19.0-6
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 -288
- package/lib/cjs/MdEditor.cjs +38 -306
- package/lib/cjs/MdModal.cjs +1 -1
- package/lib/cjs/ModalToolbar.cjs +1 -1
- package/lib/cjs/chunks/index.cjs +4 -1
- 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 -288
- package/lib/es/MdEditor.mjs +37 -305
- package/lib/es/MdModal.mjs +1 -1
- package/lib/es/ModalToolbar.mjs +1 -1
- package/lib/es/chunks/index.mjs +4 -1
- 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/content-help.d.ts +2 -2
- 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,289 +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
|
-
const scrollElement = getScrollElement();
|
|
249
|
-
scrollElementRef.value = scrollElement;
|
|
250
|
-
eventName.bus.on(editorId, {
|
|
251
|
-
name: eventName.CATALOG_CHANGED,
|
|
252
|
-
callback: (_list) => {
|
|
253
|
-
scrollElement == null ? void 0 : scrollElement.removeEventListener("scroll", scrollHandler);
|
|
254
|
-
findActiveHeading(_list);
|
|
255
|
-
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
eventName.bus.emit(editorId, eventName.PUSH_CATALOG);
|
|
259
|
-
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
260
|
-
});
|
|
261
|
-
vue.onBeforeUnmount(() => {
|
|
262
|
-
var _a;
|
|
263
|
-
(_a = scrollElementRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
264
|
-
});
|
|
265
|
-
return () => vue.createVNode("div", {
|
|
266
|
-
"class": [`${config.prefix}-catalog${props2.theme === "dark" ? "-dark" : ""}`, `${props2.class}`],
|
|
267
|
-
"ref": catalogRef
|
|
268
|
-
}, [catalogs.value.map((item) => {
|
|
269
|
-
return vue.createVNode(CatalogLink$1, {
|
|
270
|
-
"mdHeadingId": props2.mdHeadingId,
|
|
271
|
-
"tocItem": item,
|
|
272
|
-
"key": `link-${item.level}-${item.text}`,
|
|
273
|
-
"onClick": (e, t) => {
|
|
274
|
-
if (props2.onClick) {
|
|
275
|
-
props2.onClick(e, t);
|
|
276
|
-
} else {
|
|
277
|
-
ctx.emit("onClick", e, t);
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
"scrollElementOffsetTop": props2.scrollElementOffsetTop
|
|
281
|
-
}, null);
|
|
282
|
-
})]);
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
MdCatalog.install = (app) => {
|
|
286
|
-
app.component(MdCatalog.name, MdCatalog);
|
|
287
|
-
return app;
|
|
288
|
-
};
|
|
289
|
-
module.exports = MdCatalog;
|
|
2
|
+
const MdCatalog = require("./chunks/index3.cjs");
|
|
3
|
+
module.exports = MdCatalog.MdCatalog;
|