md-editor-v3 5.7.0 → 5.8.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/DropdownToolbar.cjs +1 -1
- package/lib/cjs/MdCatalog.cjs +1 -1
- package/lib/cjs/MdEditor.cjs +7 -6
- package/lib/cjs/MdModal.cjs +1 -1
- package/lib/cjs/MdPreview.cjs +1 -1
- package/lib/cjs/ModalToolbar.cjs +1 -1
- package/lib/cjs/chunks/index.cjs +186 -2398
- package/lib/cjs/chunks/index2.cjs +285 -198
- package/lib/cjs/chunks/index3.cjs +2333 -525
- package/lib/cjs/chunks/index4.cjs +598 -281
- package/lib/cjs/index.cjs +6 -6
- package/lib/es/DropdownToolbar.mjs +1 -1
- package/lib/es/MdCatalog.mjs +1 -1
- package/lib/es/MdEditor.mjs +7 -6
- package/lib/es/MdModal.mjs +1 -1
- package/lib/es/MdPreview.mjs +1 -1
- package/lib/es/ModalToolbar.mjs +1 -1
- package/lib/es/chunks/index.mjs +188 -2400
- package/lib/es/chunks/index2.mjs +287 -200
- package/lib/es/chunks/index3.mjs +2337 -529
- package/lib/es/chunks/index4.mjs +601 -284
- package/lib/es/index.mjs +8 -8
- package/lib/style.css +2 -2
- package/lib/types/config.d.ts +2 -2
- package/lib/types/index.d.ts +1 -6
- package/lib/types/preview.d.ts +6 -0
- package/lib/umd/index.js +2 -2
- package/lib/umd/preview.js +83 -0
- package/package.json +1 -1
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -1,2454 +1,242 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const vue = require("vue");
|
|
3
3
|
const config = require("./config.cjs");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const mdit = require("markdown-it");
|
|
10
|
-
const ImageFiguresPlugin = require("markdown-it-image-figures");
|
|
11
|
-
const SubPlugin = require("markdown-it-sub");
|
|
12
|
-
const SupPlugin = require("markdown-it-sup");
|
|
13
|
-
const index = require("./index5.cjs");
|
|
14
|
-
const lruCache = require("lru-cache");
|
|
15
|
-
const CDN_IDS = {
|
|
16
|
-
hljs: `${config.prefix}-hljs`,
|
|
17
|
-
hlcss: `${config.prefix}-hlCss`,
|
|
18
|
-
prettier: `${config.prefix}-prettier`,
|
|
19
|
-
prettierMD: `${config.prefix}-prettierMD`,
|
|
20
|
-
cropperjs: `${config.prefix}-cropper`,
|
|
21
|
-
croppercss: `${config.prefix}-cropperCss`,
|
|
22
|
-
screenfull: `${config.prefix}-screenfull`,
|
|
23
|
-
mermaidM: `${config.prefix}-mermaid-m`,
|
|
24
|
-
mermaid: `${config.prefix}-mermaid`,
|
|
25
|
-
katexjs: `${config.prefix}-katex`,
|
|
26
|
-
katexcss: `${config.prefix}-katexCss`
|
|
27
|
-
};
|
|
28
|
-
const userZoom = (props, html) => {
|
|
29
|
-
const editorId = vue.inject("editorId");
|
|
30
|
-
const { noImgZoomIn } = props;
|
|
31
|
-
const zoomHander = util.debounce(() => {
|
|
32
|
-
const imgs = document.querySelectorAll(
|
|
33
|
-
`#${editorId}-preview img:not(.not-zoom):not(.medium-zoom-image)`
|
|
34
|
-
);
|
|
35
|
-
if (imgs.length === 0) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
mediumZoom(imgs, {
|
|
39
|
-
background: "#00000073"
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
vue.onMounted(() => {
|
|
43
|
-
if (!noImgZoomIn && props.setting.preview) {
|
|
44
|
-
zoomHander();
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
vue.watch([html, vue.toRef(props.setting, "preview")], () => {
|
|
48
|
-
if (!noImgZoomIn && props.setting.preview) {
|
|
49
|
-
zoomHander();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
const useCopyCode = (props, html, key) => {
|
|
54
|
-
const editorId = vue.inject("editorId");
|
|
55
|
-
const rootRef = vue.inject("rootRef");
|
|
56
|
-
const ult = vue.inject("usedLanguageText");
|
|
57
|
-
const initCopyEntry = () => {
|
|
58
|
-
rootRef.value.querySelectorAll(`#${editorId} .${config.prefix}-preview .${config.prefix}-code`).forEach((codeBlock) => {
|
|
59
|
-
let clearTimer = -1;
|
|
60
|
-
const copyButton = codeBlock.querySelector(
|
|
61
|
-
`.${config.prefix}-copy-button`
|
|
62
|
-
);
|
|
63
|
-
if (copyButton)
|
|
64
|
-
copyButton.onclick = (e) => {
|
|
65
|
-
e.preventDefault();
|
|
66
|
-
clearTimeout(clearTimer);
|
|
67
|
-
const activeCode = codeBlock.querySelector("input:checked + pre code") || codeBlock.querySelector("pre code");
|
|
68
|
-
const codeText = activeCode.textContent;
|
|
69
|
-
const { text, successTips, failTips } = ult.value.copyCode;
|
|
70
|
-
let msg = successTips;
|
|
71
|
-
copy2clipboard(props.formatCopiedText(codeText)).catch(() => {
|
|
72
|
-
msg = failTips;
|
|
73
|
-
}).finally(() => {
|
|
74
|
-
if (copyButton.dataset.isIcon) {
|
|
75
|
-
copyButton.dataset.tips = msg;
|
|
76
|
-
} else {
|
|
77
|
-
copyButton.innerHTML = msg;
|
|
78
|
-
}
|
|
79
|
-
clearTimer = window.setTimeout(() => {
|
|
80
|
-
if (copyButton.dataset.isIcon) {
|
|
81
|
-
copyButton.dataset.tips = text;
|
|
82
|
-
} else {
|
|
83
|
-
copyButton.innerHTML = text;
|
|
84
|
-
}
|
|
85
|
-
}, 1500);
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
const htmlChanged = () => {
|
|
91
|
-
vue.nextTick(initCopyEntry);
|
|
92
|
-
};
|
|
93
|
-
const settingPreviewChanged = (nVal) => {
|
|
94
|
-
if (nVal) {
|
|
95
|
-
vue.nextTick(initCopyEntry);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
vue.watch([html, key], htmlChanged);
|
|
99
|
-
vue.watch(() => props.setting.preview, settingPreviewChanged);
|
|
100
|
-
vue.watch(() => props.setting.htmlPreview, settingPreviewChanged);
|
|
101
|
-
vue.onMounted(initCopyEntry);
|
|
102
|
-
};
|
|
103
|
-
const useHighlight = (props) => {
|
|
104
|
-
const highlight = vue.inject("highlight");
|
|
105
|
-
const hljsRef = vue.shallowRef(config.globalConfig.editorExtensions.highlight.instance);
|
|
106
|
-
vue.onMounted(() => {
|
|
107
|
-
if (props.noHighlight || hljsRef.value) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
dom.appendHandler("link", {
|
|
111
|
-
...highlight.value.css,
|
|
112
|
-
rel: "stylesheet",
|
|
113
|
-
id: CDN_IDS.hlcss
|
|
114
|
-
});
|
|
115
|
-
dom.appendHandler(
|
|
116
|
-
"script",
|
|
117
|
-
{
|
|
118
|
-
...highlight.value.js,
|
|
119
|
-
id: CDN_IDS.hljs,
|
|
120
|
-
onload() {
|
|
121
|
-
hljsRef.value = window.hljs;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
"hljs"
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
vue.watch(
|
|
128
|
-
() => highlight.value.css,
|
|
129
|
-
() => {
|
|
130
|
-
if (props.noHighlight || config.globalConfig.editorExtensions.highlight.instance) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
dom.updateHandler("link", {
|
|
134
|
-
...highlight.value.css,
|
|
135
|
-
rel: "stylesheet",
|
|
136
|
-
id: CDN_IDS.hlcss
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
return hljsRef;
|
|
141
|
-
};
|
|
142
|
-
const mermaidCache = new lruCache.LRUCache({
|
|
143
|
-
max: 1e3,
|
|
144
|
-
// 缓存10分钟
|
|
145
|
-
ttl: 6e5
|
|
146
|
-
});
|
|
147
|
-
const useMermaid = (props) => {
|
|
148
|
-
const editorId = vue.inject("editorId");
|
|
149
|
-
const theme = vue.inject("theme");
|
|
150
|
-
const rootRef = vue.inject("rootRef");
|
|
151
|
-
const { editorExtensions, editorExtensionsAttrs, mermaidConfig } = config.globalConfig;
|
|
152
|
-
let mermaid = editorExtensions.mermaid.instance;
|
|
153
|
-
const reRenderRef = vue.shallowRef(-1);
|
|
154
|
-
const configMermaid = () => {
|
|
155
|
-
if (!props.noMermaid && mermaid) {
|
|
156
|
-
mermaid.initialize(
|
|
157
|
-
mermaidConfig({
|
|
158
|
-
startOnLoad: false,
|
|
159
|
-
theme: theme.value === "dark" ? "dark" : "default"
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
reRenderRef.value = reRenderRef.value + 1;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
vue.watch(
|
|
166
|
-
() => theme.value,
|
|
167
|
-
() => {
|
|
168
|
-
mermaidCache.clear();
|
|
169
|
-
configMermaid();
|
|
170
|
-
}
|
|
171
|
-
);
|
|
172
|
-
vue.onMounted(() => {
|
|
173
|
-
var _a, _b;
|
|
174
|
-
if (props.noMermaid || mermaid) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const jsSrc = editorExtensions.mermaid.js;
|
|
178
|
-
if (/\.mjs/.test(jsSrc)) {
|
|
179
|
-
dom.appendHandler("link", {
|
|
180
|
-
...(_a = editorExtensionsAttrs.mermaid) == null ? void 0 : _a.js,
|
|
181
|
-
rel: "modulepreload",
|
|
182
|
-
href: jsSrc,
|
|
183
|
-
id: CDN_IDS.mermaidM
|
|
184
|
-
});
|
|
185
|
-
import(
|
|
186
|
-
/* @vite-ignore */
|
|
187
|
-
/* webpackIgnore: true */
|
|
188
|
-
jsSrc
|
|
189
|
-
).then((module2) => {
|
|
190
|
-
mermaid = module2.default;
|
|
191
|
-
configMermaid();
|
|
192
|
-
});
|
|
193
|
-
} else {
|
|
194
|
-
dom.appendHandler(
|
|
195
|
-
"script",
|
|
196
|
-
{
|
|
197
|
-
...(_b = editorExtensionsAttrs.mermaid) == null ? void 0 : _b.js,
|
|
198
|
-
src: jsSrc,
|
|
199
|
-
id: CDN_IDS.mermaid,
|
|
200
|
-
onload() {
|
|
201
|
-
mermaid = window.mermaid;
|
|
202
|
-
configMermaid();
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
"mermaid"
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
const replaceMermaid = async () => {
|
|
210
|
-
if (!props.noMermaid && mermaid) {
|
|
211
|
-
const mermaidSourceEles = rootRef.value.querySelectorAll(
|
|
212
|
-
`div.${config.prefix}-mermaid`
|
|
213
|
-
);
|
|
214
|
-
const svgContainingElement = document.createElement("div");
|
|
215
|
-
const sceWidth = document.body.offsetWidth > 1366 ? document.body.offsetWidth : 1366;
|
|
216
|
-
const sceHeight = document.body.offsetHeight > 768 ? document.body.offsetHeight : 768;
|
|
217
|
-
svgContainingElement.style.width = sceWidth + "px";
|
|
218
|
-
svgContainingElement.style.height = sceHeight + "px";
|
|
219
|
-
svgContainingElement.style.position = "fixed";
|
|
220
|
-
svgContainingElement.style.zIndex = "-10000";
|
|
221
|
-
svgContainingElement.style.top = "-10000";
|
|
222
|
-
let count = mermaidSourceEles.length;
|
|
223
|
-
if (count > 0) {
|
|
224
|
-
document.body.appendChild(svgContainingElement);
|
|
225
|
-
}
|
|
226
|
-
await Promise.allSettled(
|
|
227
|
-
Array.from(mermaidSourceEles).map((ele) => {
|
|
228
|
-
const handler = async (item) => {
|
|
229
|
-
var _a;
|
|
230
|
-
const code = item.innerText;
|
|
231
|
-
let mermaidHtml = mermaidCache.get(code);
|
|
232
|
-
if (!mermaidHtml) {
|
|
233
|
-
const idRand = util.randomId();
|
|
234
|
-
let result = { svg: "" };
|
|
235
|
-
try {
|
|
236
|
-
result = await mermaid.render(idRand, code, svgContainingElement);
|
|
237
|
-
mermaidHtml = await props.sanitizeMermaid(result.svg);
|
|
238
|
-
const p = document.createElement("p");
|
|
239
|
-
p.className = `${config.prefix}-mermaid`;
|
|
240
|
-
p.setAttribute("data-processed", "");
|
|
241
|
-
p.innerHTML = mermaidHtml;
|
|
242
|
-
(_a = p.children[0]) == null ? void 0 : _a.removeAttribute("height");
|
|
243
|
-
mermaidCache.set(code, p.innerHTML);
|
|
244
|
-
if (item.dataset.line !== void 0) {
|
|
245
|
-
p.dataset.line = item.dataset.line;
|
|
246
|
-
}
|
|
247
|
-
item.replaceWith(p);
|
|
248
|
-
} catch (error) {
|
|
249
|
-
eventName.bus.emit(editorId, eventName.ERROR_CATCHER, {
|
|
250
|
-
name: "mermaid",
|
|
251
|
-
message: error.message,
|
|
252
|
-
error
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
if (--count === 0) {
|
|
256
|
-
svgContainingElement.remove();
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
return handler(ele);
|
|
261
|
-
})
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
return { reRenderRef, replaceMermaid };
|
|
266
|
-
};
|
|
267
|
-
const useKatex = (props) => {
|
|
268
|
-
const katex = vue.shallowRef(config.globalConfig.editorExtensions.katex.instance);
|
|
269
|
-
vue.onMounted(() => {
|
|
270
|
-
if (props.noKatex || katex.value) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const { editorExtensions } = config.globalConfig;
|
|
274
|
-
dom.appendHandler(
|
|
275
|
-
"script",
|
|
276
|
-
{
|
|
277
|
-
src: editorExtensions.katex.js,
|
|
278
|
-
id: CDN_IDS.katexjs,
|
|
279
|
-
onload() {
|
|
280
|
-
katex.value = window.katex;
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
"katex"
|
|
284
|
-
);
|
|
285
|
-
dom.appendHandler("link", {
|
|
286
|
-
rel: "stylesheet",
|
|
287
|
-
href: editorExtensions.katex.css,
|
|
288
|
-
id: CDN_IDS.katexcss
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
return katex;
|
|
292
|
-
};
|
|
293
|
-
const MermaidPlugin = (md, options) => {
|
|
294
|
-
const temp = md.renderer.rules.fence.bind(md.renderer.rules);
|
|
295
|
-
md.renderer.rules.fence = (tokens, idx, ops, env, slf) => {
|
|
296
|
-
const token = tokens[idx];
|
|
297
|
-
const code = token.content.trim();
|
|
298
|
-
if (token.info === "mermaid") {
|
|
299
|
-
let line;
|
|
300
|
-
if (tokens[idx].map && tokens[idx].level === 0) {
|
|
301
|
-
line = tokens[idx].map[0];
|
|
302
|
-
tokens[idx].attrSet("data-line", String(line));
|
|
303
|
-
}
|
|
304
|
-
const mermaidHtml = mermaidCache.get(code);
|
|
305
|
-
if (mermaidHtml) {
|
|
306
|
-
return `<p class="${config.prefix}-mermaid" ${line !== void 0 ? "data-line=" + line : ""} data-processed>${mermaidHtml}</p>`;
|
|
307
|
-
}
|
|
308
|
-
return `<div class="${config.prefix}-mermaid" ${line !== void 0 ? "data-line=" + line : ""} data-mermaid-theme=${options.themeRef.value}">${md.utils.escapeHtml(code)}</div>`;
|
|
309
|
-
}
|
|
310
|
-
return temp(tokens, idx, ops, env, slf);
|
|
311
|
-
};
|
|
312
|
-
};
|
|
313
|
-
const mergeAttrs = (token, addAttrs) => {
|
|
314
|
-
const tmpAttrs = token.attrs ? token.attrs.slice() : [];
|
|
315
|
-
addAttrs.forEach((addAttr) => {
|
|
316
|
-
const i = token.attrIndex(addAttr[0]);
|
|
317
|
-
if (i < 0) {
|
|
318
|
-
tmpAttrs.push(addAttr);
|
|
319
|
-
} else {
|
|
320
|
-
tmpAttrs[i] = tmpAttrs[i].slice();
|
|
321
|
-
tmpAttrs[i][1] += ` ${addAttr[1]}`;
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
return tmpAttrs;
|
|
325
|
-
};
|
|
326
|
-
const delimiters = {
|
|
327
|
-
block: [
|
|
328
|
-
{ open: "$$", close: "$$" },
|
|
329
|
-
{ open: "\\[", close: "\\]" }
|
|
330
|
-
],
|
|
331
|
-
inline: [
|
|
332
|
-
{ open: "$$", close: "$$" },
|
|
333
|
-
{ open: "$", close: "$" },
|
|
334
|
-
{ open: "\\[", close: "\\]" },
|
|
335
|
-
{ open: "\\(", close: "\\)" }
|
|
336
|
-
]
|
|
337
|
-
};
|
|
338
|
-
const create_math_inline = (options) => (state, silent) => {
|
|
339
|
-
const delimiters2 = options.delimiters;
|
|
340
|
-
let match, token, pos;
|
|
341
|
-
for (const delim of delimiters2) {
|
|
342
|
-
if (state.src.startsWith(delim.open, state.pos)) {
|
|
343
|
-
const start = state.pos + delim.open.length;
|
|
344
|
-
match = start;
|
|
345
|
-
while ((match = state.src.indexOf(delim.close, match)) !== -1) {
|
|
346
|
-
pos = match - 1;
|
|
347
|
-
while (state.src[pos] === "\\") {
|
|
348
|
-
pos -= 1;
|
|
349
|
-
}
|
|
350
|
-
if ((match - pos) % 2 === 1) {
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
match += delim.close.length;
|
|
354
|
-
}
|
|
355
|
-
if (match === -1) {
|
|
356
|
-
if (!silent) {
|
|
357
|
-
state.pending += delim.open;
|
|
358
|
-
}
|
|
359
|
-
state.pos = start;
|
|
360
|
-
return true;
|
|
361
|
-
}
|
|
362
|
-
if (match - start === 0) {
|
|
363
|
-
if (!silent) {
|
|
364
|
-
state.pending += delim.open + delim.close;
|
|
365
|
-
}
|
|
366
|
-
state.pos = start + delim.close.length;
|
|
367
|
-
return true;
|
|
368
|
-
}
|
|
369
|
-
if (!silent) {
|
|
370
|
-
const inlineContent = state.src.slice(start, match);
|
|
371
|
-
token = state.push("math_inline", "math", 0);
|
|
372
|
-
token.markup = delim.open;
|
|
373
|
-
token.content = inlineContent;
|
|
374
|
-
}
|
|
375
|
-
state.pos = match + delim.close.length;
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return false;
|
|
380
|
-
};
|
|
381
|
-
const create_math_block = (options) => (state, start, end, silent) => {
|
|
382
|
-
const delimiters2 = options.delimiters;
|
|
383
|
-
let firstLine, lastLine, next, lastPos, found = false;
|
|
384
|
-
let pos = state.bMarks[start] + state.tShift[start];
|
|
385
|
-
let max = state.eMarks[start];
|
|
386
|
-
for (const delim of delimiters2) {
|
|
387
|
-
if (state.src.slice(pos, pos + delim.open.length) === delim.open && state.src.slice(max - delim.close.length, max) === delim.close) {
|
|
388
|
-
pos += delim.open.length;
|
|
389
|
-
firstLine = state.src.slice(pos, max);
|
|
390
|
-
if (silent) {
|
|
391
|
-
return true;
|
|
392
|
-
}
|
|
393
|
-
if (firstLine.trim().slice(-delim.close.length) === delim.close) {
|
|
394
|
-
firstLine = firstLine.trim().slice(0, -delim.close.length);
|
|
395
|
-
found = true;
|
|
396
|
-
}
|
|
397
|
-
for (next = start; !found; ) {
|
|
398
|
-
next++;
|
|
399
|
-
if (next >= end) {
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
pos = state.bMarks[next] + state.tShift[next];
|
|
403
|
-
max = state.eMarks[next];
|
|
404
|
-
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
if (state.src.slice(pos, max).trim().slice(-delim.close.length) === delim.close) {
|
|
408
|
-
lastPos = state.src.slice(0, max).lastIndexOf(delim.close);
|
|
409
|
-
lastLine = state.src.slice(pos, lastPos);
|
|
410
|
-
found = true;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
state.line = next + 1;
|
|
414
|
-
const token = state.push("math_block", "math", 0);
|
|
415
|
-
token.block = true;
|
|
416
|
-
token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
|
|
417
|
-
token.map = [start, state.line];
|
|
418
|
-
token.markup = delim.open;
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return false;
|
|
423
|
-
};
|
|
424
|
-
const KatexPlugin = (md, { katexRef, inlineDelimiters, blockDelimiters }) => {
|
|
425
|
-
const katexInline = (tokens, idx, options, env, slf) => {
|
|
426
|
-
const token = tokens[idx];
|
|
427
|
-
const tmpToken = {
|
|
428
|
-
attrs: mergeAttrs(token, [["class", `${config.prefix}-katex-inline`]])
|
|
429
|
-
};
|
|
430
|
-
if (katexRef.value) {
|
|
431
|
-
const html = katexRef.value.renderToString(
|
|
432
|
-
token.content,
|
|
433
|
-
config.globalConfig.katexConfig({
|
|
434
|
-
throwOnError: false
|
|
435
|
-
})
|
|
436
|
-
);
|
|
437
|
-
return `<span ${slf.renderAttrs(tmpToken)} data-processed>${html}</span>`;
|
|
438
|
-
} else {
|
|
439
|
-
return `<span ${slf.renderAttrs(tmpToken)}>${token.content}</span>`;
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
const katexBlock = (tokens, idx, options, env, slf) => {
|
|
443
|
-
const token = tokens[idx];
|
|
444
|
-
const tmpToken = {
|
|
445
|
-
attrs: mergeAttrs(token, [["class", `${config.prefix}-katex-block`]])
|
|
446
|
-
};
|
|
447
|
-
if (katexRef.value) {
|
|
448
|
-
const html = katexRef.value.renderToString(
|
|
449
|
-
token.content,
|
|
450
|
-
config.globalConfig.katexConfig({
|
|
451
|
-
throwOnError: false,
|
|
452
|
-
displayMode: true
|
|
453
|
-
})
|
|
454
|
-
);
|
|
455
|
-
return `<p ${slf.renderAttrs(tmpToken)} data-processed>${html}</p>`;
|
|
456
|
-
} else {
|
|
457
|
-
return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
md.inline.ruler.before(
|
|
461
|
-
"escape",
|
|
462
|
-
"math_inline",
|
|
463
|
-
create_math_inline({
|
|
464
|
-
delimiters: inlineDelimiters || delimiters.inline
|
|
465
|
-
})
|
|
466
|
-
);
|
|
467
|
-
md.block.ruler.after(
|
|
468
|
-
"blockquote",
|
|
469
|
-
"math_block",
|
|
470
|
-
create_math_block({
|
|
471
|
-
delimiters: blockDelimiters || delimiters.block
|
|
472
|
-
}),
|
|
473
|
-
{
|
|
474
|
-
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
475
|
-
}
|
|
476
|
-
);
|
|
477
|
-
md.renderer.rules.math_inline = katexInline;
|
|
478
|
-
md.renderer.rules.math_block = katexBlock;
|
|
479
|
-
};
|
|
480
|
-
const AdmonitionPlugin = (md, options) => {
|
|
481
|
-
options = options || {};
|
|
482
|
-
const markers = 3, markerStr = options.marker || "!", markerChar = markerStr.charCodeAt(0), markerLen = markerStr.length;
|
|
483
|
-
let type = "", title = "";
|
|
484
|
-
const render = (tokens, idx, _options, _env, self) => {
|
|
485
|
-
const token = tokens[idx];
|
|
486
|
-
if (token.type === "admonition_open") {
|
|
487
|
-
tokens[idx].attrPush([
|
|
488
|
-
"class",
|
|
489
|
-
`${config.prefix}-admonition ${config.prefix}-admonition-${token.info}`
|
|
490
|
-
]);
|
|
491
|
-
} else if (token.type === "admonition_title_open") {
|
|
492
|
-
tokens[idx].attrPush(["class", `${config.prefix}-admonition-title`]);
|
|
493
|
-
}
|
|
494
|
-
return self.renderToken(tokens, idx, _options);
|
|
495
|
-
};
|
|
496
|
-
const validate = (params) => {
|
|
497
|
-
const array = params.trim().split(" ", 2);
|
|
498
|
-
title = "";
|
|
499
|
-
type = array[0];
|
|
500
|
-
if (array.length > 1) {
|
|
501
|
-
title = params.substring(type.length + 2);
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
md.block.ruler.before(
|
|
505
|
-
"code",
|
|
506
|
-
"admonition",
|
|
507
|
-
(state, startLine, endLine, silent) => {
|
|
508
|
-
let pos, nextLine, token, autoClosed = false, start = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
|
|
509
|
-
if (markerChar !== state.src.charCodeAt(start)) {
|
|
510
|
-
return false;
|
|
511
|
-
}
|
|
512
|
-
for (pos = start + 1; pos <= max; pos++) {
|
|
513
|
-
if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
|
|
514
|
-
break;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
const markerCount = Math.floor((pos - start) / markerLen);
|
|
518
|
-
if (markerCount !== markers) {
|
|
519
|
-
return false;
|
|
520
|
-
}
|
|
521
|
-
pos -= (pos - start) % markerLen;
|
|
522
|
-
const markup = state.src.slice(start, pos);
|
|
523
|
-
const params = state.src.slice(pos, max);
|
|
524
|
-
validate(params);
|
|
525
|
-
if (silent) {
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
nextLine = startLine;
|
|
529
|
-
for (; ; ) {
|
|
530
|
-
nextLine++;
|
|
531
|
-
if (nextLine >= endLine) {
|
|
532
|
-
break;
|
|
533
|
-
}
|
|
534
|
-
start = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
535
|
-
max = state.eMarks[nextLine];
|
|
536
|
-
if (start < max && state.sCount[nextLine] < state.blkIndent) {
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
if (markerChar !== state.src.charCodeAt(start)) {
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
for (pos = start + 1; pos <= max; pos++) {
|
|
546
|
-
if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
|
|
547
|
-
break;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
if (Math.floor((pos - start) / markerLen) < markerCount) {
|
|
551
|
-
continue;
|
|
552
|
-
}
|
|
553
|
-
pos -= (pos - start) % markerLen;
|
|
554
|
-
pos = state.skipSpaces(pos);
|
|
555
|
-
if (pos < max) {
|
|
556
|
-
continue;
|
|
557
|
-
}
|
|
558
|
-
autoClosed = true;
|
|
559
|
-
break;
|
|
560
|
-
}
|
|
561
|
-
const oldParent = state.parentType;
|
|
562
|
-
const oldLineMax = state.lineMax;
|
|
563
|
-
state.parentType = "root";
|
|
564
|
-
state.lineMax = nextLine;
|
|
565
|
-
token = state.push("admonition_open", "div", 1);
|
|
566
|
-
token.markup = markup;
|
|
567
|
-
token.block = true;
|
|
568
|
-
token.info = type;
|
|
569
|
-
token.map = [startLine, nextLine];
|
|
570
|
-
if (title) {
|
|
571
|
-
token = state.push("admonition_title_open", "p", 1);
|
|
572
|
-
token.markup = markup + " " + type;
|
|
573
|
-
token.map = [startLine, nextLine];
|
|
574
|
-
token = state.push("inline", "", 0);
|
|
575
|
-
token.content = title;
|
|
576
|
-
token.map = [startLine, state.line - 1];
|
|
577
|
-
token.children = [];
|
|
578
|
-
token = state.push("admonition_title_close", "p", -1);
|
|
579
|
-
token.markup = markup + " " + type;
|
|
580
|
-
}
|
|
581
|
-
state.md.block.tokenize(state, startLine + 1, nextLine);
|
|
582
|
-
token = state.push("admonition_close", "div", -1);
|
|
583
|
-
token.markup = state.src.slice(start, pos);
|
|
584
|
-
token.block = true;
|
|
585
|
-
state.parentType = oldParent;
|
|
586
|
-
state.lineMax = oldLineMax;
|
|
587
|
-
state.line = nextLine + (autoClosed ? 1 : 0);
|
|
588
|
-
return true;
|
|
589
|
-
},
|
|
590
|
-
{
|
|
591
|
-
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
592
|
-
}
|
|
593
|
-
);
|
|
594
|
-
md.renderer.rules["admonition_open"] = render;
|
|
595
|
-
md.renderer.rules["admonition_title_open"] = render;
|
|
596
|
-
md.renderer.rules["admonition_title_close"] = render;
|
|
597
|
-
md.renderer.rules["admonition_close"] = render;
|
|
598
|
-
};
|
|
599
|
-
const HeadingPlugin = (md, options) => {
|
|
600
|
-
md.renderer.rules.heading_open = (tokens, idx) => {
|
|
601
|
-
var _a;
|
|
602
|
-
const token = tokens[idx];
|
|
603
|
-
const text = ((_a = tokens[idx + 1].children) == null ? void 0 : _a.reduce((p, c) => {
|
|
604
|
-
return p + (["text", "code_inline", "math_inline"].includes(c.type) ? c.content || "" : "");
|
|
605
|
-
}, "")) || "";
|
|
606
|
-
const level = token.markup.length;
|
|
607
|
-
options.headsRef.value.push({
|
|
608
|
-
text,
|
|
609
|
-
level,
|
|
610
|
-
line: token.map[0]
|
|
611
|
-
});
|
|
612
|
-
if (token.map && token.level === 0) {
|
|
613
|
-
token.attrSet(
|
|
614
|
-
"id",
|
|
615
|
-
options.mdHeadingId(text, level, options.headsRef.value.length)
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
return md.renderer.renderToken(tokens, idx, options);
|
|
619
|
-
};
|
|
620
|
-
md.renderer.rules.heading_close = (tokens, idx, opts, _env, self) => {
|
|
621
|
-
return self.renderToken(tokens, idx, opts);
|
|
622
|
-
};
|
|
623
|
-
};
|
|
624
|
-
const codetabs = (md, _opts) => {
|
|
625
|
-
const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/, mandatoryRe = /::(open|close)/;
|
|
626
|
-
const getInfo = (token) => {
|
|
627
|
-
return token.info ? unescapeAll(token.info).trim() : "";
|
|
628
|
-
};
|
|
629
|
-
const getGroupAndTab = (token) => {
|
|
630
|
-
const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
|
|
631
|
-
return [group, tab];
|
|
632
|
-
};
|
|
633
|
-
const getLangName = (token) => {
|
|
634
|
-
const info = getInfo(token);
|
|
635
|
-
return info ? info.split(/(\s+)/g)[0] : "";
|
|
636
|
-
};
|
|
637
|
-
const getTagType = (token) => {
|
|
638
|
-
const mandatory = token.info.match(mandatoryRe) || [];
|
|
639
|
-
const open = mandatory[1] === "open" || mandatory[1] !== "close" && _opts.codeFoldable && token.content.trim().split("\n").length < _opts.autoFoldThreshold;
|
|
640
|
-
const tagContainer = mandatory[1] || _opts.codeFoldable ? "details" : "div", tagHeader = mandatory[1] || _opts.codeFoldable ? "summary" : "div";
|
|
641
|
-
return { open, tagContainer, tagHeader };
|
|
642
|
-
};
|
|
643
|
-
const fenceGroup = (tokens, idx, options, env, slf) => {
|
|
644
|
-
var _a;
|
|
645
|
-
if (tokens[idx].hidden) {
|
|
646
|
-
return "";
|
|
647
|
-
}
|
|
648
|
-
const codeCodeText = (_a = _opts.usedLanguageTextRef.value) == null ? void 0 : _a.copyCode.text;
|
|
649
|
-
const copyBtnHtml = _opts.customIconRef.value.copy || codeCodeText;
|
|
650
|
-
const isIcon = !!_opts.customIconRef.value.copy;
|
|
651
|
-
const collapseTips = `<span class="${config.prefix}-collapse-tips">${dom.StrIcon("collapse-tips", _opts.customIconRef.value)}</span>`;
|
|
652
|
-
const [GROUP] = getGroupAndTab(tokens[idx]);
|
|
653
|
-
if (GROUP === null) {
|
|
654
|
-
const { open: open2, tagContainer: tagContainer2, tagHeader: tagHeader2 } = getTagType(tokens[idx]);
|
|
655
|
-
const addAttrs2 = [["class", `${config.prefix}-code`]];
|
|
656
|
-
if (open2) addAttrs2.push(["open", ""]);
|
|
657
|
-
const tmpToken2 = {
|
|
658
|
-
attrs: mergeAttrs(tokens[idx], addAttrs2)
|
|
659
|
-
};
|
|
660
|
-
tokens[idx].info = tokens[idx].info.replace(mandatoryRe, "");
|
|
661
|
-
const codeRendered = defaultRender(tokens, idx, options, env, slf);
|
|
662
|
-
return `
|
|
663
|
-
<${tagContainer2} ${slf.renderAttrs(tmpToken2)}>
|
|
664
|
-
<${tagHeader2} class="${config.prefix}-code-head">
|
|
665
|
-
<div class="${config.prefix}-code-flag"><span></span><span></span><span></span></div>
|
|
666
|
-
<div class="${config.prefix}-code-action">
|
|
667
|
-
<span class="${config.prefix}-code-lang">${tokens[idx].info.trim()}</span>
|
|
668
|
-
<span class="${config.prefix}-copy-button" data-tips="${codeCodeText}"${isIcon ? " data-is-icon=true" : ""}>${copyBtnHtml}</span>
|
|
669
|
-
${_opts.extraTools instanceof Function ? _opts.extraTools({ lang: tokens[idx].info.trim() }) : _opts.extraTools || ""}
|
|
670
|
-
${tagContainer2 === "details" ? collapseTips : ""}
|
|
671
|
-
</div>
|
|
672
|
-
</${tagHeader2}>
|
|
673
|
-
${codeRendered}
|
|
674
|
-
</${tagContainer2}>
|
|
675
|
-
`;
|
|
676
|
-
}
|
|
677
|
-
let token, group, tab, checked, labels = "", pres = "", langs = "";
|
|
678
|
-
const { open, tagContainer, tagHeader } = getTagType(tokens[idx]);
|
|
679
|
-
const addAttrs = [["class", `${config.prefix}-code`]];
|
|
680
|
-
if (open) addAttrs.push(["open", ""]);
|
|
681
|
-
const tmpToken = {
|
|
682
|
-
attrs: mergeAttrs(tokens[idx], addAttrs)
|
|
683
|
-
};
|
|
684
|
-
for (let i = idx; i < tokens.length; i++) {
|
|
685
|
-
token = tokens[i];
|
|
686
|
-
[group, tab] = getGroupAndTab(token);
|
|
687
|
-
if (group !== GROUP) {
|
|
688
|
-
break;
|
|
689
|
-
}
|
|
690
|
-
token.info = token.info.replace(re, "").replace(mandatoryRe, "");
|
|
691
|
-
token.hidden = true;
|
|
692
|
-
const className = `${config.prefix}-codetab-${_opts.editorId}-${idx}-${i - idx}`;
|
|
693
|
-
checked = i - idx > 0 ? "" : "checked";
|
|
694
|
-
labels += `
|
|
695
|
-
<li>
|
|
696
|
-
<input
|
|
697
|
-
type="radio"
|
|
698
|
-
id="label-${config.prefix}-codetab-label-1-${_opts.editorId}-${idx}-${i - idx}"
|
|
699
|
-
name="${config.prefix}-codetab-label-${_opts.editorId}-${idx}"
|
|
700
|
-
class="${className}"
|
|
701
|
-
${checked}
|
|
702
|
-
>
|
|
703
|
-
<label
|
|
704
|
-
for="label-${config.prefix}-codetab-label-1-${_opts.editorId}-${idx}-${i - idx}"
|
|
705
|
-
onclick="this.getRootNode().querySelectorAll('.${className}').forEach(e => e.click())"
|
|
706
|
-
>
|
|
707
|
-
${tab || getLangName(token)}
|
|
708
|
-
</label>
|
|
709
|
-
</li>`;
|
|
710
|
-
pres += `
|
|
711
|
-
<div role="tabpanel">
|
|
712
|
-
<input
|
|
713
|
-
type="radio"
|
|
714
|
-
name="${config.prefix}-codetab-pre-${_opts.editorId}-${idx}"
|
|
715
|
-
class="${className}"
|
|
716
|
-
${checked}
|
|
717
|
-
role="presentation">
|
|
718
|
-
${defaultRender(tokens, i, options, env, slf)}
|
|
719
|
-
</div>`;
|
|
720
|
-
langs += `
|
|
721
|
-
<input
|
|
722
|
-
type="radio"
|
|
723
|
-
name="${config.prefix}-codetab-lang-${_opts.editorId}-${idx}"
|
|
724
|
-
class="${className}"
|
|
725
|
-
${checked}
|
|
726
|
-
role="presentation">
|
|
727
|
-
<span class=${config.prefix}-code-lang role="note">${getLangName(token)}</span>`;
|
|
728
|
-
}
|
|
729
|
-
return `
|
|
730
|
-
<${tagContainer} ${slf.renderAttrs(tmpToken)}>
|
|
731
|
-
<${tagHeader} class="${config.prefix}-code-head">
|
|
732
|
-
<div class="${config.prefix}-code-flag">
|
|
733
|
-
<ul class="${config.prefix}-codetab-label" role="tablist">${labels}</ul>
|
|
734
|
-
</div>
|
|
735
|
-
<div class="${config.prefix}-code-action">
|
|
736
|
-
<span class="${config.prefix}-codetab-lang">${langs}</span>
|
|
737
|
-
<span class="${config.prefix}-copy-button" data-tips="${codeCodeText}"${isIcon ? " data-is-icon=true" : ""}>${copyBtnHtml}</span>
|
|
738
|
-
${_opts.extraTools instanceof Function ? _opts.extraTools({ lang: tokens[idx].info.trim() }) : _opts.extraTools || ""}
|
|
739
|
-
${tagContainer === "details" ? collapseTips : ""}
|
|
740
|
-
</div>
|
|
741
|
-
</${tagHeader}>
|
|
742
|
-
${pres}
|
|
743
|
-
</${tagContainer}>
|
|
744
|
-
`;
|
|
745
|
-
};
|
|
746
|
-
md.renderer.rules.fence = fenceGroup;
|
|
747
|
-
md.renderer.rules.code_block = fenceGroup;
|
|
748
|
-
};
|
|
749
|
-
const attrSet = (token, name, value) => {
|
|
750
|
-
const index2 = token.attrIndex(name);
|
|
751
|
-
const attr = [name, value];
|
|
752
|
-
if (index2 < 0) {
|
|
753
|
-
token.attrPush(attr);
|
|
754
|
-
} else {
|
|
755
|
-
token.attrs = token.attrs || [];
|
|
756
|
-
token.attrs[index2] = attr;
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
const isInline = (token) => {
|
|
760
|
-
return token.type === "inline";
|
|
761
|
-
};
|
|
762
|
-
const isParagraph = (token) => {
|
|
763
|
-
return token.type === "paragraph_open";
|
|
764
|
-
};
|
|
765
|
-
const isListItem = (token) => {
|
|
766
|
-
return token.type === "list_item_open";
|
|
767
|
-
};
|
|
768
|
-
const startsWithTodoMarkdown = (token) => {
|
|
769
|
-
return token.content.indexOf("[ ] ") === 0 || token.content.indexOf("[x] ") === 0 || token.content.indexOf("[X] ") === 0;
|
|
770
|
-
};
|
|
771
|
-
const isTodoItem = (tokens, index2) => {
|
|
772
|
-
return isInline(tokens[index2]) && isParagraph(tokens[index2 - 1]) && isListItem(tokens[index2 - 2]) && startsWithTodoMarkdown(tokens[index2]);
|
|
773
|
-
};
|
|
774
|
-
const parentToken = (tokens, index2) => {
|
|
775
|
-
const targetLevel = tokens[index2].level - 1;
|
|
776
|
-
for (let i = index2 - 1; i >= 0; i--) {
|
|
777
|
-
if (tokens[i].level === targetLevel) {
|
|
778
|
-
return i;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return -1;
|
|
782
|
-
};
|
|
783
|
-
const beginLabel = (TokenConstructor) => {
|
|
784
|
-
const token = new TokenConstructor("html_inline", "", 0);
|
|
785
|
-
token.content = "<label>";
|
|
786
|
-
return token;
|
|
787
|
-
};
|
|
788
|
-
const endLabel = (TokenConstructor) => {
|
|
789
|
-
const token = new TokenConstructor("html_inline", "", 0);
|
|
790
|
-
token.content = "</label>";
|
|
791
|
-
return token;
|
|
792
|
-
};
|
|
793
|
-
const afterLabel = (content, id, TokenConstructor) => {
|
|
794
|
-
const token = new TokenConstructor("html_inline", "", 0);
|
|
795
|
-
token.content = '<label class="task-list-item-label" for="' + id + '">' + content + "</label>";
|
|
796
|
-
token.attrs = [{ for: id }];
|
|
797
|
-
return token;
|
|
798
|
-
};
|
|
799
|
-
const makeCheckbox = (token, TokenConstructor, options) => {
|
|
800
|
-
const checkbox = new TokenConstructor("html_inline", "", 0);
|
|
801
|
-
const disabledAttr = !options.enabled ? ' disabled="" ' : " ";
|
|
802
|
-
if (token.content.indexOf("[ ] ") === 0) {
|
|
803
|
-
checkbox.content = '<input class="task-list-item-checkbox"' + disabledAttr + 'type="checkbox">';
|
|
804
|
-
} else if (token.content.indexOf("[x] ") === 0 || token.content.indexOf("[X] ") === 0) {
|
|
805
|
-
checkbox.content = '<input class="task-list-item-checkbox" checked=""' + disabledAttr + 'type="checkbox">';
|
|
806
|
-
}
|
|
807
|
-
return checkbox;
|
|
808
|
-
};
|
|
809
|
-
const todoify = (token, TokenConstructor, options) => {
|
|
810
|
-
token.children = token.children || [];
|
|
811
|
-
token.children.unshift(makeCheckbox(token, TokenConstructor, options));
|
|
812
|
-
token.children[1].content = token.children[1].content.slice(3);
|
|
813
|
-
token.content = token.content.slice(3);
|
|
814
|
-
if (options.label) {
|
|
815
|
-
if (options.labelAfter) {
|
|
816
|
-
token.children.pop();
|
|
817
|
-
const id = "task-item-" + Math.ceil(Math.random() * (1e4 * 1e3) - 1e3);
|
|
818
|
-
token.children[0].content = token.children[0].content.slice(0, -1) + ' id="' + id + '">';
|
|
819
|
-
token.children.push(afterLabel(token.content, id, TokenConstructor));
|
|
820
|
-
} else {
|
|
821
|
-
token.children.unshift(beginLabel(TokenConstructor));
|
|
822
|
-
token.children.push(endLabel(TokenConstructor));
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
};
|
|
826
|
-
const githubTaskLists = (md, options = {}) => {
|
|
827
|
-
md.core.ruler.after("inline", "github-task-lists", (state) => {
|
|
828
|
-
const tokens = state.tokens;
|
|
829
|
-
for (let i = 2; i < tokens.length; i++) {
|
|
830
|
-
if (isTodoItem(tokens, i)) {
|
|
831
|
-
todoify(tokens[i], state.Token, options);
|
|
832
|
-
attrSet(
|
|
833
|
-
tokens[i - 2],
|
|
834
|
-
"class",
|
|
835
|
-
"task-list-item" + (options.enabled ? " enabled" : " ")
|
|
836
|
-
);
|
|
837
|
-
attrSet(tokens[parentToken(tokens, i - 2)], "class", "contains-task-list");
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
});
|
|
841
|
-
};
|
|
842
|
-
const initLineNumber = (md) => {
|
|
843
|
-
md.core.ruler.push("init-line-number", (state) => {
|
|
844
|
-
state.tokens.forEach((token) => {
|
|
845
|
-
if (token.map) {
|
|
846
|
-
if (!token.attrs) {
|
|
847
|
-
token.attrs = [];
|
|
848
|
-
}
|
|
849
|
-
token.attrs.push(["data-line", token.map[0].toString()]);
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
return true;
|
|
853
|
-
});
|
|
854
|
-
};
|
|
855
|
-
const useMarkdownIt = (props, previewOnly) => {
|
|
856
|
-
const { editorConfig, markdownItConfig, markdownItPlugins, editorExtensions } = config.globalConfig;
|
|
857
|
-
const editorId = vue.inject("editorId");
|
|
858
|
-
const languageRef = vue.inject("language");
|
|
859
|
-
const usedLanguageTextRef = vue.inject(
|
|
860
|
-
"usedLanguageText"
|
|
861
|
-
);
|
|
862
|
-
const showCodeRowNumber = vue.inject("showCodeRowNumber");
|
|
863
|
-
const themeRef = vue.inject("theme");
|
|
864
|
-
const customIconRef = vue.inject("customIcon");
|
|
865
|
-
const rootRef = vue.inject("rootRef");
|
|
866
|
-
const headsRef = vue.ref([]);
|
|
867
|
-
let clearMermaidEvents = () => {
|
|
868
|
-
};
|
|
869
|
-
const hljsRef = useHighlight(props);
|
|
870
|
-
const katexRef = useKatex(props);
|
|
871
|
-
const { reRenderRef, replaceMermaid } = useMermaid(props);
|
|
872
|
-
const md = mdit({
|
|
873
|
-
html: true,
|
|
874
|
-
breaks: true,
|
|
875
|
-
linkify: true
|
|
876
|
-
});
|
|
877
|
-
markdownItConfig(md, {
|
|
878
|
-
editorId
|
|
879
|
-
});
|
|
880
|
-
const plugins = [
|
|
881
|
-
{
|
|
882
|
-
type: "image",
|
|
883
|
-
plugin: ImageFiguresPlugin,
|
|
884
|
-
options: { figcaption: true, classes: "md-zoom" }
|
|
885
|
-
},
|
|
886
|
-
{
|
|
887
|
-
type: "admonition",
|
|
888
|
-
plugin: AdmonitionPlugin,
|
|
889
|
-
options: {}
|
|
890
|
-
},
|
|
891
|
-
{
|
|
892
|
-
type: "taskList",
|
|
893
|
-
plugin: githubTaskLists,
|
|
894
|
-
options: {}
|
|
895
|
-
},
|
|
896
|
-
{
|
|
897
|
-
type: "heading",
|
|
898
|
-
plugin: HeadingPlugin,
|
|
899
|
-
options: { mdHeadingId: props.mdHeadingId, headsRef }
|
|
900
|
-
},
|
|
901
|
-
{
|
|
902
|
-
type: "code",
|
|
903
|
-
plugin: codetabs,
|
|
904
|
-
options: {
|
|
905
|
-
editorId,
|
|
906
|
-
usedLanguageTextRef,
|
|
907
|
-
// showCodeRowNumber,
|
|
908
|
-
codeFoldable: props.codeFoldable,
|
|
909
|
-
autoFoldThreshold: props.autoFoldThreshold,
|
|
910
|
-
customIconRef
|
|
911
|
-
}
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
type: "sub",
|
|
915
|
-
plugin: SubPlugin,
|
|
916
|
-
options: {}
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
type: "sup",
|
|
920
|
-
plugin: SupPlugin,
|
|
921
|
-
options: {}
|
|
922
|
-
}
|
|
923
|
-
];
|
|
924
|
-
if (!props.noKatex) {
|
|
925
|
-
plugins.push({
|
|
926
|
-
type: "katex",
|
|
927
|
-
plugin: KatexPlugin,
|
|
928
|
-
options: { katexRef }
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
if (!props.noMermaid) {
|
|
932
|
-
plugins.push({
|
|
933
|
-
type: "mermaid",
|
|
934
|
-
plugin: MermaidPlugin,
|
|
935
|
-
options: { themeRef }
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
markdownItPlugins(plugins, {
|
|
939
|
-
editorId
|
|
940
|
-
}).forEach((item) => {
|
|
941
|
-
md.use(item.plugin, item.options);
|
|
942
|
-
});
|
|
943
|
-
const userDefHighlight = md.options.highlight;
|
|
944
|
-
md.set({
|
|
945
|
-
highlight: (str, language, attrs) => {
|
|
946
|
-
if (userDefHighlight) {
|
|
947
|
-
const result = userDefHighlight(str, language, attrs);
|
|
948
|
-
if (result) {
|
|
949
|
-
return result;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
let codeHtml;
|
|
953
|
-
if (!props.noHighlight && hljsRef.value) {
|
|
954
|
-
const hljsLang = hljsRef.value.getLanguage(language);
|
|
955
|
-
if (hljsLang) {
|
|
956
|
-
codeHtml = hljsRef.value.highlight(str, {
|
|
957
|
-
language,
|
|
958
|
-
ignoreIllegals: true
|
|
959
|
-
}).value;
|
|
960
|
-
} else {
|
|
961
|
-
codeHtml = hljsRef.value.highlightAuto(str).value;
|
|
962
|
-
}
|
|
963
|
-
} else {
|
|
964
|
-
codeHtml = md.utils.escapeHtml(str);
|
|
965
|
-
}
|
|
966
|
-
const codeSpan = showCodeRowNumber ? index.generateCodeRowNumber(
|
|
967
|
-
codeHtml.replace(/^\n+|\n+$/g, ""),
|
|
968
|
-
str.replace(/^\n+|\n+$/g, "")
|
|
969
|
-
) : `<span class="${config.prefix}-code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
|
|
970
|
-
return `<pre><code class="language-${language}" language=${language}>${codeSpan}</code></pre>`;
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
initLineNumber(md);
|
|
974
|
-
const key = vue.ref(`_article-key_${util.randomId()}`);
|
|
975
|
-
const html = vue.ref(props.sanitize(md.render(props.modelValue)));
|
|
976
|
-
const updatedTodo = () => {
|
|
977
|
-
eventName.bus.emit(editorId, eventName.BUILD_FINISHED, html.value);
|
|
978
|
-
props.onHtmlChanged(html.value);
|
|
979
|
-
props.onGetCatalog(headsRef.value);
|
|
980
|
-
eventName.bus.emit(editorId, eventName.CATALOG_CHANGED, headsRef.value);
|
|
981
|
-
vue.nextTick(() => {
|
|
982
|
-
replaceMermaid().then(() => {
|
|
983
|
-
var _a, _b;
|
|
984
|
-
if ((_a = editorExtensions.mermaid) == null ? void 0 : _a.enableZoom) {
|
|
985
|
-
clearMermaidEvents();
|
|
986
|
-
clearMermaidEvents = dom.zoomMermaid(
|
|
987
|
-
(_b = rootRef.value) == null ? void 0 : _b.querySelectorAll(`#${editorId} p.${config.prefix}-mermaid`),
|
|
988
|
-
{
|
|
989
|
-
customIcon: customIconRef.value
|
|
990
|
-
}
|
|
991
|
-
);
|
|
992
|
-
}
|
|
993
|
-
});
|
|
994
|
-
});
|
|
995
|
-
};
|
|
996
|
-
const markHtml = () => {
|
|
997
|
-
headsRef.value = [];
|
|
998
|
-
html.value = props.sanitize(md.render(props.modelValue));
|
|
999
|
-
updatedTodo();
|
|
1000
|
-
};
|
|
1001
|
-
const needReRender = vue.computed(() => {
|
|
1002
|
-
return (props.noKatex || katexRef.value) && (props.noHighlight || hljsRef.value);
|
|
1003
|
-
});
|
|
1004
|
-
let timer = -1;
|
|
1005
|
-
vue.watch([vue.toRef(props, "modelValue"), needReRender, reRenderRef, languageRef], () => {
|
|
1006
|
-
timer = window.setTimeout(
|
|
1007
|
-
() => {
|
|
1008
|
-
markHtml();
|
|
1009
|
-
},
|
|
1010
|
-
previewOnly ? 0 : editorConfig.renderDelay
|
|
1011
|
-
);
|
|
1012
|
-
});
|
|
1013
|
-
vue.watch(
|
|
1014
|
-
() => props.setting.preview,
|
|
1015
|
-
() => {
|
|
1016
|
-
if (props.setting.preview) {
|
|
1017
|
-
vue.nextTick(() => {
|
|
1018
|
-
replaceMermaid().then(() => {
|
|
1019
|
-
var _a, _b;
|
|
1020
|
-
if ((_a = editorExtensions.mermaid) == null ? void 0 : _a.enableZoom) {
|
|
1021
|
-
clearMermaidEvents();
|
|
1022
|
-
clearMermaidEvents = dom.zoomMermaid(
|
|
1023
|
-
(_b = rootRef.value) == null ? void 0 : _b.querySelectorAll(`#${editorId} p.${config.prefix}-mermaid`),
|
|
1024
|
-
{
|
|
1025
|
-
customIcon: customIconRef.value
|
|
1026
|
-
}
|
|
1027
|
-
);
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
1030
|
-
eventName.bus.emit(editorId, eventName.CATALOG_CHANGED, headsRef.value);
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
);
|
|
1035
|
-
vue.onMounted(updatedTodo);
|
|
1036
|
-
vue.onMounted(() => {
|
|
1037
|
-
eventName.bus.on(editorId, {
|
|
1038
|
-
name: eventName.PUSH_CATALOG,
|
|
1039
|
-
callback() {
|
|
1040
|
-
eventName.bus.emit(editorId, eventName.CATALOG_CHANGED, headsRef.value);
|
|
1041
|
-
}
|
|
1042
|
-
});
|
|
1043
|
-
eventName.bus.on(editorId, {
|
|
1044
|
-
name: eventName.RERENDER,
|
|
1045
|
-
callback: () => {
|
|
1046
|
-
key.value = `_article-key_${util.randomId()}`;
|
|
1047
|
-
markHtml();
|
|
1048
|
-
}
|
|
1049
|
-
});
|
|
1050
|
-
});
|
|
1051
|
-
vue.onBeforeUnmount(() => {
|
|
1052
|
-
clearMermaidEvents();
|
|
1053
|
-
clearTimeout(timer);
|
|
1054
|
-
});
|
|
1055
|
-
return { html, key };
|
|
1056
|
-
};
|
|
1057
|
-
const template = {
|
|
1058
|
-
checked: {
|
|
1059
|
-
regexp: /- \[x\]/,
|
|
1060
|
-
value: "- [ ]"
|
|
1061
|
-
},
|
|
1062
|
-
unChecked: {
|
|
1063
|
-
regexp: /- \[\s\]/,
|
|
1064
|
-
value: "- [x]"
|
|
1065
|
-
}
|
|
1066
|
-
};
|
|
1067
|
-
const useTaskState = (props, html) => {
|
|
1068
|
-
const editorId = vue.inject("editorId");
|
|
1069
|
-
const rootRef = vue.inject("rootRef");
|
|
1070
|
-
let removeListener = () => {
|
|
1071
|
-
};
|
|
1072
|
-
const addListener = () => {
|
|
1073
|
-
if (!rootRef.value) {
|
|
1074
|
-
return false;
|
|
1075
|
-
}
|
|
1076
|
-
const tasks = rootRef.value.querySelectorAll(".task-list-item.enabled");
|
|
1077
|
-
const listener = (e) => {
|
|
1078
|
-
var _a;
|
|
1079
|
-
e.preventDefault();
|
|
1080
|
-
const nextValue = e.target.checked ? "unChecked" : "checked";
|
|
1081
|
-
const line = (_a = e.target.parentElement) == null ? void 0 : _a.dataset.line;
|
|
1082
|
-
if (!line) {
|
|
1083
|
-
return;
|
|
1084
|
-
}
|
|
1085
|
-
const lineNumber = Number(line);
|
|
1086
|
-
const lines = props.modelValue.split("\n");
|
|
1087
|
-
const targetValue = lines[Number(lineNumber)].replace(
|
|
1088
|
-
template[nextValue].regexp,
|
|
1089
|
-
template[nextValue].value
|
|
1090
|
-
);
|
|
1091
|
-
if (props.previewOnly) {
|
|
1092
|
-
lines[Number(lineNumber)] = targetValue;
|
|
1093
|
-
props.onChange(lines.join("\n"));
|
|
1094
|
-
} else {
|
|
1095
|
-
eventName.bus.emit(editorId, eventName.TASK_STATE_CHANGED, lineNumber + 1, targetValue);
|
|
1096
|
-
}
|
|
1097
|
-
};
|
|
1098
|
-
tasks.forEach((item) => {
|
|
1099
|
-
item.addEventListener("click", listener);
|
|
1100
|
-
});
|
|
1101
|
-
removeListener = () => {
|
|
1102
|
-
tasks.forEach((item) => {
|
|
1103
|
-
item.removeEventListener("click", listener);
|
|
1104
|
-
});
|
|
1105
|
-
};
|
|
1106
|
-
};
|
|
1107
|
-
vue.onBeforeUnmount(() => {
|
|
1108
|
-
removeListener();
|
|
1109
|
-
});
|
|
1110
|
-
vue.watch(
|
|
1111
|
-
[html],
|
|
1112
|
-
() => {
|
|
1113
|
-
removeListener();
|
|
1114
|
-
vue.nextTick(addListener);
|
|
1115
|
-
},
|
|
1116
|
-
{
|
|
1117
|
-
immediate: true
|
|
1118
|
-
}
|
|
1119
|
-
);
|
|
1120
|
-
};
|
|
1121
|
-
const useRemount = (props, html, key) => {
|
|
1122
|
-
const handler = () => {
|
|
1123
|
-
vue.nextTick(() => {
|
|
1124
|
-
var _a;
|
|
1125
|
-
(_a = props.onRemount) == null ? void 0 : _a.call(props);
|
|
1126
|
-
});
|
|
1127
|
-
};
|
|
1128
|
-
const settingPreviewChanged = (nVal) => {
|
|
1129
|
-
if (nVal) {
|
|
1130
|
-
handler();
|
|
1131
|
-
}
|
|
1132
|
-
};
|
|
1133
|
-
vue.watch([html, key], handler);
|
|
1134
|
-
vue.watch(() => props.setting.preview, settingPreviewChanged);
|
|
1135
|
-
vue.watch(() => props.setting.htmlPreview, settingPreviewChanged);
|
|
1136
|
-
vue.onMounted(handler);
|
|
1137
|
-
};
|
|
1138
|
-
const contentPreviewProps = {
|
|
1139
|
-
modelValue: {
|
|
1140
|
-
type: String,
|
|
1141
|
-
default: ""
|
|
1142
|
-
},
|
|
1143
|
-
onChange: {
|
|
1144
|
-
type: Function,
|
|
1145
|
-
default: () => {
|
|
1146
|
-
}
|
|
1147
|
-
},
|
|
1148
|
-
setting: {
|
|
1149
|
-
type: Object,
|
|
1150
|
-
default: () => ({ preview: true })
|
|
1151
|
-
},
|
|
1152
|
-
onHtmlChanged: {
|
|
1153
|
-
type: Function,
|
|
1154
|
-
default: () => {
|
|
1155
|
-
}
|
|
1156
|
-
},
|
|
1157
|
-
onGetCatalog: {
|
|
1158
|
-
type: Function,
|
|
1159
|
-
default: () => {
|
|
1160
|
-
}
|
|
1161
|
-
},
|
|
1162
|
-
mdHeadingId: {
|
|
1163
|
-
type: Function,
|
|
1164
|
-
default: () => ""
|
|
1165
|
-
},
|
|
1166
|
-
noMermaid: {
|
|
1167
|
-
type: Boolean,
|
|
1168
|
-
default: false
|
|
1169
|
-
},
|
|
1170
|
-
sanitize: {
|
|
1171
|
-
type: Function,
|
|
1172
|
-
default: (html) => html
|
|
1173
|
-
},
|
|
1174
|
-
// 不使用该函数功能
|
|
1175
|
-
noKatex: {
|
|
1176
|
-
type: Boolean,
|
|
1177
|
-
default: false
|
|
1178
|
-
},
|
|
1179
|
-
formatCopiedText: {
|
|
1180
|
-
type: Function,
|
|
1181
|
-
default: (text) => text
|
|
1182
|
-
},
|
|
1183
|
-
noHighlight: {
|
|
1184
|
-
type: Boolean,
|
|
1185
|
-
default: false
|
|
1186
|
-
},
|
|
1187
|
-
previewOnly: {
|
|
1188
|
-
type: Boolean,
|
|
1189
|
-
default: false
|
|
1190
|
-
},
|
|
1191
|
-
noImgZoomIn: {
|
|
1192
|
-
type: Boolean
|
|
1193
|
-
},
|
|
1194
|
-
sanitizeMermaid: {
|
|
1195
|
-
type: Function
|
|
1196
|
-
},
|
|
1197
|
-
codeFoldable: {
|
|
1198
|
-
type: Boolean
|
|
1199
|
-
},
|
|
1200
|
-
autoFoldThreshold: {
|
|
1201
|
-
type: Number
|
|
1202
|
-
},
|
|
1203
|
-
onRemount: {
|
|
1204
|
-
type: Function
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
const contentProps = {
|
|
1208
|
-
...contentPreviewProps,
|
|
1209
|
-
updateModelValue: {
|
|
1210
|
-
type: Function,
|
|
1211
|
-
default: () => {
|
|
1212
|
-
}
|
|
1213
|
-
},
|
|
1214
|
-
placeholder: {
|
|
1215
|
-
type: String,
|
|
1216
|
-
default: ""
|
|
1217
|
-
},
|
|
1218
|
-
scrollAuto: {
|
|
1219
|
-
type: Boolean
|
|
1220
|
-
},
|
|
1221
|
-
autofocus: {
|
|
1222
|
-
type: Boolean
|
|
1223
|
-
},
|
|
1224
|
-
disabled: {
|
|
1225
|
-
type: Boolean
|
|
1226
|
-
},
|
|
1227
|
-
readonly: {
|
|
1228
|
-
type: Boolean
|
|
1229
|
-
},
|
|
1230
|
-
maxlength: {
|
|
1231
|
-
type: Number
|
|
1232
|
-
},
|
|
1233
|
-
autoDetectCode: {
|
|
1234
|
-
type: Boolean
|
|
1235
|
-
},
|
|
1236
|
-
/**
|
|
1237
|
-
* 输入框失去焦点时触发事件
|
|
1238
|
-
*/
|
|
1239
|
-
onBlur: {
|
|
1240
|
-
type: Function,
|
|
1241
|
-
default: () => {
|
|
1242
|
-
}
|
|
1243
|
-
},
|
|
1244
|
-
/**
|
|
1245
|
-
* 输入框获得焦点时触发事件
|
|
1246
|
-
*/
|
|
1247
|
-
onFocus: {
|
|
1248
|
-
type: Function,
|
|
1249
|
-
default: () => {
|
|
1250
|
-
}
|
|
1251
|
-
},
|
|
1252
|
-
noPrettier: {
|
|
1253
|
-
type: Boolean
|
|
1254
|
-
},
|
|
1255
|
-
completions: {
|
|
1256
|
-
type: Array
|
|
1257
|
-
},
|
|
1258
|
-
catalogVisible: {
|
|
1259
|
-
type: Boolean
|
|
1260
|
-
},
|
|
1261
|
-
theme: {
|
|
1262
|
-
type: String,
|
|
1263
|
-
default: "light"
|
|
1264
|
-
},
|
|
1265
|
-
onInput: {
|
|
1266
|
-
type: Function
|
|
1267
|
-
},
|
|
1268
|
-
onDrop: {
|
|
1269
|
-
type: Function,
|
|
1270
|
-
default: () => {
|
|
1271
|
-
}
|
|
1272
|
-
},
|
|
1273
|
-
inputBoxWidth: {
|
|
1274
|
-
type: String
|
|
1275
|
-
},
|
|
1276
|
-
oninputBoxWidthChange: {
|
|
1277
|
-
type: Function
|
|
1278
|
-
},
|
|
1279
|
-
transformImgUrl: {
|
|
1280
|
-
type: Function,
|
|
1281
|
-
default: (t) => t
|
|
1282
|
-
},
|
|
1283
|
-
catalogLayout: {
|
|
1284
|
-
type: String
|
|
1285
|
-
},
|
|
1286
|
-
catalogMaxDepth: {
|
|
1287
|
-
type: Number
|
|
1288
|
-
}
|
|
1289
|
-
};
|
|
1290
|
-
const splitNodes = (html) => {
|
|
1291
|
-
const parser = new DOMParser();
|
|
1292
|
-
const doc = parser.parseFromString(html, "text/html");
|
|
1293
|
-
return Array.from(doc.body.childNodes);
|
|
1294
|
-
};
|
|
1295
|
-
const compareHtml = (newNodes, currentNodes) => {
|
|
1296
|
-
const updates = [];
|
|
1297
|
-
const deletes = [];
|
|
1298
|
-
newNodes.forEach((newNode, index2) => {
|
|
1299
|
-
const currentNode = currentNodes[index2];
|
|
1300
|
-
if (!currentNode) {
|
|
1301
|
-
updates.push({
|
|
1302
|
-
index: index2,
|
|
1303
|
-
newNode
|
|
1304
|
-
});
|
|
1305
|
-
return;
|
|
1306
|
-
}
|
|
1307
|
-
if (newNode.nodeType !== currentNode.nodeType || newNode.textContent !== currentNode.textContent || newNode.nodeType === 1 && newNode.outerHTML !== currentNode.outerHTML) {
|
|
1308
|
-
updates.push({
|
|
1309
|
-
index: index2,
|
|
1310
|
-
newNode
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
});
|
|
1314
|
-
if (currentNodes.length > newNodes.length) {
|
|
1315
|
-
for (let i = newNodes.length; i < currentNodes.length; i++) {
|
|
1316
|
-
deletes.push(currentNodes[i]);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
return {
|
|
1320
|
-
updates,
|
|
1321
|
-
deletes
|
|
1322
|
-
};
|
|
1323
|
-
};
|
|
1324
|
-
const UpdateOnDemand = /* @__PURE__ */ vue.defineComponent({
|
|
1325
|
-
name: "UpdateOnDemand",
|
|
1326
|
-
props: {
|
|
1327
|
-
html: {
|
|
1328
|
-
type: String,
|
|
1329
|
-
required: true
|
|
1330
|
-
}
|
|
1331
|
-
},
|
|
1332
|
-
setup(props) {
|
|
1333
|
-
const editorId = vue.inject("editorId");
|
|
1334
|
-
const previewTheme = vue.inject("previewTheme");
|
|
1335
|
-
const showCodeRowNumber = vue.inject("showCodeRowNumber");
|
|
1336
|
-
const htmlContainer = vue.ref();
|
|
1337
|
-
const firstHtml = props.html;
|
|
1338
|
-
const updateHtmlContent = (updates, deletes) => {
|
|
1339
|
-
if (!htmlContainer.value) return;
|
|
1340
|
-
deletes.forEach((node) => {
|
|
1341
|
-
node.remove();
|
|
1342
|
-
});
|
|
1343
|
-
updates.forEach(({
|
|
1344
|
-
index: index2,
|
|
1345
|
-
newNode
|
|
1346
|
-
}) => {
|
|
1347
|
-
var _a, _b, _c;
|
|
1348
|
-
const targetNode = (_a = htmlContainer.value) == null ? void 0 : _a.childNodes[index2];
|
|
1349
|
-
if (!targetNode) {
|
|
1350
|
-
(_b = htmlContainer.value) == null ? void 0 : _b.appendChild(newNode.cloneNode(true));
|
|
1351
|
-
} else {
|
|
1352
|
-
(_c = htmlContainer.value) == null ? void 0 : _c.replaceChild(newNode.cloneNode(true), targetNode);
|
|
1353
|
-
}
|
|
1354
|
-
});
|
|
1355
|
-
};
|
|
1356
|
-
vue.watch(() => props.html, (newHtml) => {
|
|
1357
|
-
var _a;
|
|
1358
|
-
const newNodes = splitNodes(newHtml);
|
|
1359
|
-
const currentNodes = Array.from(((_a = htmlContainer.value) == null ? void 0 : _a.childNodes) || []);
|
|
1360
|
-
const {
|
|
1361
|
-
updates,
|
|
1362
|
-
deletes
|
|
1363
|
-
} = compareHtml(newNodes, currentNodes);
|
|
1364
|
-
updateHtmlContent(updates, deletes);
|
|
1365
|
-
});
|
|
1366
|
-
return () => vue.createVNode("div", {
|
|
1367
|
-
"id": `${editorId}-preview`,
|
|
1368
|
-
"class": [`${config.prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${config.prefix}-scrn`],
|
|
1369
|
-
"innerHTML": firstHtml,
|
|
1370
|
-
"ref": htmlContainer
|
|
1371
|
-
}, null);
|
|
1372
|
-
}
|
|
1373
|
-
});
|
|
1374
|
-
const ContentPreview = /* @__PURE__ */ vue.defineComponent({
|
|
1375
|
-
name: "ContentPreview",
|
|
1376
|
-
props: contentPreviewProps,
|
|
1377
|
-
setup(props) {
|
|
1378
|
-
const editorId = vue.inject("editorId");
|
|
1379
|
-
const {
|
|
1380
|
-
html,
|
|
1381
|
-
key
|
|
1382
|
-
} = useMarkdownIt(props, props.previewOnly);
|
|
1383
|
-
useCopyCode(props, html, key);
|
|
1384
|
-
userZoom(props, html);
|
|
1385
|
-
useTaskState(props, html);
|
|
1386
|
-
useRemount(props, html, key);
|
|
1387
|
-
return () => {
|
|
1388
|
-
return vue.createVNode(vue.Fragment, null, [props.setting.preview && vue.createVNode("div", {
|
|
1389
|
-
"id": `${editorId}-preview-wrapper`,
|
|
1390
|
-
"class": `${config.prefix}-preview-wrapper`,
|
|
1391
|
-
"key": "content-preview-wrapper"
|
|
1392
|
-
}, [vue.createVNode(UpdateOnDemand, {
|
|
1393
|
-
"key": key.value,
|
|
1394
|
-
"html": html.value
|
|
1395
|
-
}, null)]), !props.previewOnly && props.setting.htmlPreview && vue.createVNode("div", {
|
|
1396
|
-
"id": `${editorId}-html-wrapper`,
|
|
1397
|
-
"class": `${config.prefix}-preview-wrapper`,
|
|
1398
|
-
"key": "html-preview-wrapper"
|
|
1399
|
-
}, [vue.createVNode("div", {
|
|
1400
|
-
"class": `${config.prefix}-html`
|
|
1401
|
-
}, [html.value])])]);
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
});
|
|
1405
|
-
const useOnSave = (props, context, options) => {
|
|
1406
|
-
const { editorId } = options;
|
|
1407
|
-
const state = vue.reactive({
|
|
1408
|
-
// 是否已编译成html
|
|
1409
|
-
buildFinished: false,
|
|
1410
|
-
// 存储当前最新的html
|
|
1411
|
-
html: ""
|
|
1412
|
-
});
|
|
1413
|
-
vue.watch(
|
|
1414
|
-
() => props.modelValue,
|
|
1415
|
-
() => {
|
|
1416
|
-
state.buildFinished = false;
|
|
1417
|
-
}
|
|
1418
|
-
);
|
|
1419
|
-
vue.onMounted(() => {
|
|
1420
|
-
eventName.bus.on(editorId, {
|
|
1421
|
-
name: eventName.BUILD_FINISHED,
|
|
1422
|
-
callback(html) {
|
|
1423
|
-
state.buildFinished = true;
|
|
1424
|
-
state.html = html;
|
|
1425
|
-
}
|
|
1426
|
-
});
|
|
1427
|
-
eventName.bus.on(editorId, {
|
|
1428
|
-
name: eventName.ON_SAVE,
|
|
1429
|
-
callback() {
|
|
1430
|
-
const htmlPromise = new Promise((rev) => {
|
|
1431
|
-
if (state.buildFinished) {
|
|
1432
|
-
rev(state.html);
|
|
1433
|
-
} else {
|
|
1434
|
-
const buildFinishedCallback = (html) => {
|
|
1435
|
-
rev(html);
|
|
1436
|
-
eventName.bus.remove(editorId, eventName.BUILD_FINISHED, buildFinishedCallback);
|
|
1437
|
-
};
|
|
1438
|
-
eventName.bus.on(editorId, {
|
|
1439
|
-
name: eventName.BUILD_FINISHED,
|
|
1440
|
-
callback: buildFinishedCallback
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
|
-
});
|
|
1444
|
-
if (props.onSave) {
|
|
1445
|
-
props.onSave(props.modelValue, htmlPromise);
|
|
1446
|
-
} else {
|
|
1447
|
-
context.emit("onSave", props.modelValue, htmlPromise);
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1451
|
-
});
|
|
1452
|
-
};
|
|
1453
|
-
const useProvidePreview = (props, rootRef) => {
|
|
1454
|
-
const hljsUrls = config.globalConfig.editorExtensions.highlight;
|
|
1455
|
-
const hljsAttrs = config.globalConfig.editorExtensionsAttrs.highlight;
|
|
1456
|
-
const editorId = useEditorId(props);
|
|
1457
|
-
vue.provide("editorId", editorId);
|
|
1458
|
-
vue.provide("rootRef", rootRef);
|
|
1459
|
-
vue.provide(
|
|
1460
|
-
"theme",
|
|
1461
|
-
vue.computed(() => props.theme)
|
|
1462
|
-
);
|
|
1463
|
-
vue.provide(
|
|
1464
|
-
"language",
|
|
1465
|
-
vue.computed(() => props.language)
|
|
1466
|
-
);
|
|
1467
|
-
vue.provide(
|
|
1468
|
-
"highlight",
|
|
1469
|
-
vue.computed(() => {
|
|
1470
|
-
const { js: jsUrl } = hljsUrls;
|
|
1471
|
-
const cssList = {
|
|
1472
|
-
...config.codeCss,
|
|
1473
|
-
...hljsUrls.css
|
|
1474
|
-
};
|
|
1475
|
-
const { js: jsAttrs, css: cssAttrs = {} } = hljsAttrs || {};
|
|
1476
|
-
const _theme = props.codeStyleReverse && props.codeStyleReverseList.includes(props.previewTheme) ? "dark" : props.theme;
|
|
1477
|
-
const codeCssHref = cssList[props.codeTheme] ? cssList[props.codeTheme][_theme] : config.codeCss.atom[_theme];
|
|
1478
|
-
const codeCssAttrs = cssList[props.codeTheme] && cssAttrs[props.codeTheme] ? cssAttrs[props.codeTheme][_theme] : cssAttrs["atom"] ? cssAttrs["atom"][_theme] : {};
|
|
1479
|
-
return {
|
|
1480
|
-
js: {
|
|
1481
|
-
src: jsUrl,
|
|
1482
|
-
...jsAttrs
|
|
1483
|
-
},
|
|
1484
|
-
css: {
|
|
1485
|
-
href: codeCssHref,
|
|
1486
|
-
...codeCssAttrs
|
|
1487
|
-
}
|
|
1488
|
-
};
|
|
1489
|
-
})
|
|
1490
|
-
);
|
|
1491
|
-
vue.provide("showCodeRowNumber", props.showCodeRowNumber);
|
|
1492
|
-
const usedLanguageText = vue.computed(() => {
|
|
1493
|
-
const allText = {
|
|
1494
|
-
...config.staticTextDefault,
|
|
1495
|
-
...config.globalConfig.editorConfig.languageUserDefined
|
|
1496
|
-
};
|
|
1497
|
-
return util.deepMerge(
|
|
1498
|
-
util.deepClone(config.staticTextDefault["en-US"]),
|
|
1499
|
-
allText[props.language] || {}
|
|
1500
|
-
);
|
|
1501
|
-
});
|
|
1502
|
-
vue.provide("usedLanguageText", usedLanguageText);
|
|
1503
|
-
vue.provide(
|
|
1504
|
-
"previewTheme",
|
|
1505
|
-
vue.computed(() => props.previewTheme)
|
|
1506
|
-
);
|
|
1507
|
-
vue.provide(
|
|
1508
|
-
"customIcon",
|
|
1509
|
-
vue.computed(() => props.customIcon)
|
|
1510
|
-
);
|
|
1511
|
-
return { editorId };
|
|
1512
|
-
};
|
|
1513
|
-
const useProvide = (props, rootRef) => {
|
|
1514
|
-
vue.provide("tabWidth", props.tabWidth);
|
|
1515
|
-
vue.provide(
|
|
1516
|
-
"disabled",
|
|
1517
|
-
vue.computed(() => props.disabled)
|
|
1518
|
-
);
|
|
1519
|
-
return useProvidePreview(props, rootRef);
|
|
1520
|
-
};
|
|
1521
|
-
const useExpansion = (props) => {
|
|
1522
|
-
const { noPrettier, noUploadImg } = props;
|
|
1523
|
-
const { editorExtensions, editorExtensionsAttrs } = config.globalConfig;
|
|
1524
|
-
const noPrettierScript = noPrettier || editorExtensions.prettier.prettierInstance;
|
|
1525
|
-
const noParserMarkdownScript = noPrettier || editorExtensions.prettier.parserMarkdownInstance;
|
|
1526
|
-
const noCropperScript = noUploadImg || editorExtensions.cropper.instance;
|
|
1527
|
-
vue.onMounted(() => {
|
|
1528
|
-
if (!noCropperScript) {
|
|
1529
|
-
const { js = {}, css = {} } = editorExtensionsAttrs.cropper || {};
|
|
1530
|
-
dom.appendHandler("link", {
|
|
1531
|
-
...css,
|
|
1532
|
-
rel: "stylesheet",
|
|
1533
|
-
href: editorExtensions.cropper.css,
|
|
1534
|
-
id: CDN_IDS.croppercss
|
|
1535
|
-
});
|
|
1536
|
-
dom.appendHandler("script", {
|
|
1537
|
-
...js,
|
|
1538
|
-
src: editorExtensions.cropper.js,
|
|
1539
|
-
id: CDN_IDS.cropperjs
|
|
1540
|
-
});
|
|
1541
|
-
}
|
|
1542
|
-
if (!noPrettierScript) {
|
|
1543
|
-
const { standaloneJs = {} } = editorExtensionsAttrs.prettier || {};
|
|
1544
|
-
dom.appendHandler("script", {
|
|
1545
|
-
...standaloneJs,
|
|
1546
|
-
src: editorExtensions.prettier.standaloneJs,
|
|
1547
|
-
id: CDN_IDS.prettier
|
|
1548
|
-
});
|
|
1549
|
-
}
|
|
1550
|
-
if (!noParserMarkdownScript) {
|
|
1551
|
-
const { parserMarkdownJs = {} } = editorExtensionsAttrs.prettier || {};
|
|
1552
|
-
dom.appendHandler("script", {
|
|
1553
|
-
...parserMarkdownJs,
|
|
1554
|
-
src: editorExtensions.prettier.parserMarkdownJs,
|
|
1555
|
-
id: CDN_IDS.prettierMD
|
|
1556
|
-
});
|
|
1557
|
-
}
|
|
1558
|
-
});
|
|
1559
|
-
};
|
|
1560
|
-
const useErrorCatcher = (props, context, options) => {
|
|
1561
|
-
const { editorId } = options;
|
|
1562
|
-
vue.onMounted(() => {
|
|
1563
|
-
eventName.bus.on(editorId, {
|
|
1564
|
-
name: eventName.ERROR_CATCHER,
|
|
1565
|
-
callback: (err) => {
|
|
1566
|
-
var _a;
|
|
1567
|
-
(_a = props.onError) == null ? void 0 : _a.call(props, err);
|
|
1568
|
-
context.emit("onError", err);
|
|
1569
|
-
}
|
|
1570
|
-
});
|
|
1571
|
-
});
|
|
1572
|
-
};
|
|
1573
|
-
const useConfig = (props, context, options) => {
|
|
1574
|
-
const { editorId } = options;
|
|
1575
|
-
const setting = vue.reactive({
|
|
1576
|
-
pageFullscreen: props.pageFullscreen,
|
|
1577
|
-
fullscreen: false,
|
|
1578
|
-
preview: props.preview,
|
|
1579
|
-
htmlPreview: props.preview ? false : props.htmlPreview,
|
|
1580
|
-
previewOnly: false
|
|
1581
|
-
});
|
|
1582
|
-
const cacheSetting = vue.reactive({ ...setting });
|
|
1583
|
-
const updateSetting = (k, v) => {
|
|
1584
|
-
const realValue = v === void 0 ? !setting[k] : v;
|
|
1585
|
-
switch (k) {
|
|
1586
|
-
case "preview": {
|
|
1587
|
-
setting.htmlPreview = false;
|
|
1588
|
-
setting.previewOnly = false;
|
|
1589
|
-
break;
|
|
1590
|
-
}
|
|
1591
|
-
case "htmlPreview": {
|
|
1592
|
-
setting.preview = false;
|
|
1593
|
-
setting.previewOnly = false;
|
|
1594
|
-
break;
|
|
1595
|
-
}
|
|
1596
|
-
case "previewOnly": {
|
|
1597
|
-
if (realValue) {
|
|
1598
|
-
if (!setting.preview && !setting.htmlPreview) {
|
|
1599
|
-
setting.preview = true;
|
|
1600
|
-
}
|
|
1601
|
-
} else {
|
|
1602
|
-
if (!cacheSetting.preview) {
|
|
1603
|
-
setting.preview = false;
|
|
1604
|
-
}
|
|
1605
|
-
if (!cacheSetting.htmlPreview) {
|
|
1606
|
-
setting.htmlPreview = false;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
break;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
cacheSetting[k] = realValue;
|
|
1613
|
-
setting[k] = realValue;
|
|
1614
|
-
};
|
|
1615
|
-
let bodyOverflowHistory = "";
|
|
1616
|
-
const adjustBody = () => {
|
|
1617
|
-
if (setting.pageFullscreen || setting.fullscreen) {
|
|
1618
|
-
document.body.style.overflow = "hidden";
|
|
1619
|
-
} else {
|
|
1620
|
-
document.body.style.overflow = bodyOverflowHistory;
|
|
1621
|
-
}
|
|
1622
|
-
};
|
|
1623
|
-
vue.watch(() => [setting.pageFullscreen, setting.fullscreen], adjustBody);
|
|
1624
|
-
vue.onMounted(() => {
|
|
1625
|
-
eventName.bus.on(editorId, {
|
|
1626
|
-
name: eventName.UPLOAD_IMAGE,
|
|
1627
|
-
callback(files, cb) {
|
|
1628
|
-
const insertHanlder = (urls) => {
|
|
1629
|
-
eventName.bus.emit(editorId, eventName.REPLACE, "image", {
|
|
1630
|
-
desc: "",
|
|
1631
|
-
urls
|
|
1632
|
-
});
|
|
1633
|
-
cb == null ? void 0 : cb();
|
|
1634
|
-
};
|
|
1635
|
-
if (props.onUploadImg) {
|
|
1636
|
-
props.onUploadImg(files, insertHanlder);
|
|
1637
|
-
} else {
|
|
1638
|
-
context.emit("onUploadImg", files, insertHanlder);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
bodyOverflowHistory = document.body.style.overflow;
|
|
1643
|
-
adjustBody();
|
|
1644
|
-
});
|
|
1645
|
-
return [setting, updateSetting];
|
|
1646
|
-
};
|
|
1647
|
-
const useCatalog = (_props, options) => {
|
|
1648
|
-
const { editorId } = options;
|
|
1649
|
-
const catalogShow = vue.ref(false);
|
|
1650
|
-
vue.onMounted(() => {
|
|
1651
|
-
eventName.bus.on(editorId, {
|
|
1652
|
-
name: eventName.CHANGE_CATALOG_VISIBLE,
|
|
1653
|
-
callback: (v) => {
|
|
1654
|
-
if (v === void 0) {
|
|
1655
|
-
catalogShow.value = !catalogShow.value;
|
|
1656
|
-
} else {
|
|
1657
|
-
catalogShow.value = v;
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
});
|
|
1661
|
-
});
|
|
1662
|
-
return catalogShow;
|
|
1663
|
-
};
|
|
1664
|
-
const useExpose$1 = (props, ctx, options) => {
|
|
1665
|
-
const { editorId, catalogVisible, setting, updateSetting, codeRef } = options;
|
|
1666
|
-
vue.watch(
|
|
1667
|
-
() => setting.pageFullscreen,
|
|
1668
|
-
(newVal) => {
|
|
1669
|
-
eventName.bus.emit(editorId, eventName.PAGE_FULL_SCREEN_CHANGED, newVal);
|
|
1670
|
-
}
|
|
1671
|
-
);
|
|
1672
|
-
vue.watch(
|
|
1673
|
-
() => setting.fullscreen,
|
|
1674
|
-
(newVal) => {
|
|
1675
|
-
eventName.bus.emit(editorId, eventName.FULL_SCREEN_CHANGED, newVal);
|
|
1676
|
-
}
|
|
1677
|
-
);
|
|
1678
|
-
vue.watch(
|
|
1679
|
-
() => setting.preview,
|
|
1680
|
-
(newVal) => {
|
|
1681
|
-
eventName.bus.emit(editorId, eventName.PREVIEW_CHANGED, newVal);
|
|
1682
|
-
}
|
|
1683
|
-
);
|
|
1684
|
-
vue.watch(
|
|
1685
|
-
() => setting.previewOnly,
|
|
1686
|
-
(newVal) => {
|
|
1687
|
-
eventName.bus.emit(editorId, eventName.PREVIEW_ONLY_CHANGED, newVal);
|
|
1688
|
-
}
|
|
1689
|
-
);
|
|
1690
|
-
vue.watch(
|
|
1691
|
-
() => setting.htmlPreview,
|
|
1692
|
-
(newVal) => {
|
|
1693
|
-
eventName.bus.emit(editorId, eventName.HTML_PREVIEW_CHANGED, newVal);
|
|
1694
|
-
}
|
|
1695
|
-
);
|
|
1696
|
-
vue.watch(catalogVisible, (newVal) => {
|
|
1697
|
-
eventName.bus.emit(editorId, eventName.CATALOG_VISIBLE_CHANGED, newVal);
|
|
1698
|
-
});
|
|
1699
|
-
const exposeParam = {
|
|
1700
|
-
on(eventName$1, callBack) {
|
|
1701
|
-
switch (eventName$1) {
|
|
1702
|
-
case "pageFullscreen": {
|
|
1703
|
-
eventName.bus.on(editorId, {
|
|
1704
|
-
name: eventName.PAGE_FULL_SCREEN_CHANGED,
|
|
1705
|
-
callback(status) {
|
|
1706
|
-
callBack(status);
|
|
1707
|
-
}
|
|
1708
|
-
});
|
|
1709
|
-
break;
|
|
1710
|
-
}
|
|
1711
|
-
case "fullscreen": {
|
|
1712
|
-
eventName.bus.on(editorId, {
|
|
1713
|
-
name: eventName.FULL_SCREEN_CHANGED,
|
|
1714
|
-
callback(status) {
|
|
1715
|
-
callBack(status);
|
|
1716
|
-
}
|
|
1717
|
-
});
|
|
1718
|
-
break;
|
|
1719
|
-
}
|
|
1720
|
-
case "preview": {
|
|
1721
|
-
eventName.bus.on(editorId, {
|
|
1722
|
-
name: eventName.PREVIEW_CHANGED,
|
|
1723
|
-
callback(status) {
|
|
1724
|
-
callBack(status);
|
|
1725
|
-
}
|
|
1726
|
-
});
|
|
1727
|
-
break;
|
|
1728
|
-
}
|
|
1729
|
-
case "previewOnly": {
|
|
1730
|
-
eventName.bus.on(editorId, {
|
|
1731
|
-
name: eventName.PREVIEW_ONLY_CHANGED,
|
|
1732
|
-
callback(status) {
|
|
1733
|
-
callBack(status);
|
|
1734
|
-
}
|
|
1735
|
-
});
|
|
1736
|
-
break;
|
|
1737
|
-
}
|
|
1738
|
-
case "htmlPreview": {
|
|
1739
|
-
eventName.bus.on(editorId, {
|
|
1740
|
-
name: eventName.HTML_PREVIEW_CHANGED,
|
|
1741
|
-
callback(status) {
|
|
1742
|
-
callBack(status);
|
|
1743
|
-
}
|
|
1744
|
-
});
|
|
1745
|
-
break;
|
|
1746
|
-
}
|
|
1747
|
-
case "catalog": {
|
|
1748
|
-
eventName.bus.on(editorId, {
|
|
1749
|
-
name: eventName.CATALOG_VISIBLE_CHANGED,
|
|
1750
|
-
callback(status) {
|
|
1751
|
-
callBack(status);
|
|
1752
|
-
}
|
|
1753
|
-
});
|
|
1754
|
-
break;
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
},
|
|
1758
|
-
togglePageFullscreen(status) {
|
|
1759
|
-
updateSetting("pageFullscreen", status);
|
|
1760
|
-
},
|
|
1761
|
-
toggleFullscreen(status) {
|
|
1762
|
-
eventName.bus.emit(editorId, eventName.CHANGE_FULL_SCREEN, status);
|
|
1763
|
-
},
|
|
1764
|
-
togglePreview(status) {
|
|
1765
|
-
updateSetting("preview", status);
|
|
1766
|
-
},
|
|
1767
|
-
togglePreviewOnly(status) {
|
|
1768
|
-
updateSetting("previewOnly", status);
|
|
1769
|
-
},
|
|
1770
|
-
toggleHtmlPreview(status) {
|
|
1771
|
-
updateSetting("htmlPreview", status);
|
|
1772
|
-
},
|
|
1773
|
-
toggleCatalog(status) {
|
|
1774
|
-
eventName.bus.emit(editorId, eventName.CHANGE_CATALOG_VISIBLE, status);
|
|
1775
|
-
},
|
|
1776
|
-
triggerSave() {
|
|
1777
|
-
eventName.bus.emit(editorId, eventName.ON_SAVE);
|
|
1778
|
-
},
|
|
1779
|
-
insert(generate) {
|
|
1780
|
-
eventName.bus.emit(editorId, eventName.REPLACE, "universal", { generate });
|
|
1781
|
-
},
|
|
1782
|
-
focus(options2) {
|
|
1783
|
-
var _a;
|
|
1784
|
-
(_a = codeRef.value) == null ? void 0 : _a.focus(options2);
|
|
1785
|
-
},
|
|
1786
|
-
rerender() {
|
|
1787
|
-
eventName.bus.emit(editorId, eventName.RERENDER);
|
|
1788
|
-
},
|
|
1789
|
-
getSelectedText() {
|
|
1790
|
-
var _a;
|
|
1791
|
-
return (_a = codeRef.value) == null ? void 0 : _a.getSelectedText();
|
|
1792
|
-
},
|
|
1793
|
-
resetHistory() {
|
|
1794
|
-
var _a;
|
|
1795
|
-
(_a = codeRef.value) == null ? void 0 : _a.resetHistory();
|
|
1796
|
-
},
|
|
1797
|
-
domEventHandlers(handlers) {
|
|
1798
|
-
eventName.bus.emit(editorId, eventName.EVENT_LISTENER, handlers);
|
|
1799
|
-
},
|
|
1800
|
-
execCommand(direct) {
|
|
1801
|
-
eventName.bus.emit(editorId, eventName.REPLACE, direct);
|
|
1802
|
-
},
|
|
1803
|
-
getEditorView() {
|
|
1804
|
-
var _a;
|
|
1805
|
-
return (_a = codeRef.value) == null ? void 0 : _a.getEditorView();
|
|
1806
|
-
}
|
|
1807
|
-
};
|
|
1808
|
-
ctx.expose(exposeParam);
|
|
1809
|
-
};
|
|
1810
|
-
const useEditorId = (props) => {
|
|
1811
|
-
const defaultId = vue.useId();
|
|
1812
|
-
return props.id || props.editorId || `${config.prefix}-${defaultId}`;
|
|
1813
|
-
};
|
|
1814
|
-
const mdHeadingId = (text) => text;
|
|
1815
|
-
const mdPreviewProps = {
|
|
1816
|
-
/**
|
|
1817
|
-
* markdown content.
|
|
1818
|
-
*
|
|
1819
|
-
* @default ''
|
|
1820
|
-
*/
|
|
1821
|
-
modelValue: {
|
|
1822
|
-
type: String,
|
|
1823
|
-
default: ""
|
|
1824
|
-
},
|
|
1825
|
-
/**
|
|
1826
|
-
* input回调事件
|
|
1827
|
-
*/
|
|
1828
|
-
onChange: {
|
|
1829
|
-
type: Function,
|
|
1830
|
-
default: void 0
|
|
1831
|
-
},
|
|
1832
|
-
/**
|
|
1833
|
-
* 主题,支持light和dark
|
|
1834
|
-
*
|
|
1835
|
-
* @default 'light'
|
|
1836
|
-
*/
|
|
1837
|
-
theme: {
|
|
1838
|
-
type: String,
|
|
1839
|
-
default: "light"
|
|
1840
|
-
},
|
|
1841
|
-
/**
|
|
1842
|
-
* 外层类名
|
|
1843
|
-
*
|
|
1844
|
-
* @default ''
|
|
1845
|
-
*/
|
|
1846
|
-
class: {
|
|
1847
|
-
type: String,
|
|
1848
|
-
default: ""
|
|
1849
|
-
},
|
|
1850
|
-
/**
|
|
1851
|
-
* 预设语言名称
|
|
1852
|
-
*
|
|
1853
|
-
* @default 'zh-CN'
|
|
1854
|
-
*/
|
|
1855
|
-
language: {
|
|
1856
|
-
type: String,
|
|
1857
|
-
default: "zh-CN"
|
|
1858
|
-
},
|
|
1859
|
-
/**
|
|
1860
|
-
* html变化事件
|
|
1861
|
-
*/
|
|
1862
|
-
onHtmlChanged: {
|
|
1863
|
-
type: Function,
|
|
1864
|
-
default: void 0
|
|
1865
|
-
},
|
|
1866
|
-
/**
|
|
1867
|
-
* 获取目录结构
|
|
1868
|
-
*/
|
|
1869
|
-
onGetCatalog: {
|
|
1870
|
-
type: Function,
|
|
1871
|
-
default: void 0
|
|
1872
|
-
},
|
|
1873
|
-
/**
|
|
1874
|
-
* 编辑器唯一标识
|
|
1875
|
-
*
|
|
1876
|
-
* @default 'md-editor-v3'
|
|
1877
|
-
* @deprecated 5.x版本开始使用 id 替换
|
|
1878
|
-
*/
|
|
1879
|
-
editorId: {
|
|
1880
|
-
type: String,
|
|
1881
|
-
default: void 0
|
|
1882
|
-
},
|
|
1883
|
-
/**
|
|
1884
|
-
* 5.x版本开始 editorId 的替换
|
|
1885
|
-
*
|
|
1886
|
-
* @default 'md-editor-v3'
|
|
1887
|
-
*/
|
|
1888
|
-
id: {
|
|
1889
|
-
type: String,
|
|
1890
|
-
default: void 0
|
|
1891
|
-
},
|
|
1892
|
-
/**
|
|
1893
|
-
* 预览中代码是否显示行号
|
|
1894
|
-
*
|
|
1895
|
-
* @default true
|
|
1896
|
-
*/
|
|
1897
|
-
showCodeRowNumber: {
|
|
1898
|
-
type: Boolean,
|
|
1899
|
-
default: true
|
|
1900
|
-
},
|
|
1901
|
-
/**
|
|
1902
|
-
* 预览内容样式
|
|
1903
|
-
*
|
|
1904
|
-
* @default 'default'
|
|
1905
|
-
*/
|
|
1906
|
-
previewTheme: {
|
|
1907
|
-
type: String,
|
|
1908
|
-
default: "default"
|
|
1909
|
-
},
|
|
1910
|
-
/**
|
|
1911
|
-
* 编辑器样式
|
|
1912
|
-
*/
|
|
1913
|
-
style: {
|
|
1914
|
-
type: Object,
|
|
1915
|
-
default: () => ({})
|
|
1916
|
-
},
|
|
1917
|
-
/**
|
|
1918
|
-
* 标题的id生成方式
|
|
1919
|
-
*
|
|
1920
|
-
* @default (text: string) => text
|
|
1921
|
-
*/
|
|
1922
|
-
mdHeadingId: {
|
|
1923
|
-
type: Function,
|
|
1924
|
-
default: mdHeadingId
|
|
1925
|
-
},
|
|
1926
|
-
/**
|
|
1927
|
-
*
|
|
1928
|
-
* 不能保证文本正确的情况,在marked编译md文本后通过该方法处理
|
|
1929
|
-
* 推荐DOMPurify、sanitize-html
|
|
1930
|
-
*
|
|
1931
|
-
* @default (text: string) => text
|
|
1932
|
-
*/
|
|
1933
|
-
sanitize: {
|
|
1934
|
-
type: Function,
|
|
1935
|
-
default: (html) => html
|
|
1936
|
-
},
|
|
1937
|
-
/**
|
|
1938
|
-
* 不使用该mermaid
|
|
1939
|
-
*
|
|
1940
|
-
* @default false
|
|
1941
|
-
*/
|
|
1942
|
-
noMermaid: {
|
|
1943
|
-
type: Boolean,
|
|
1944
|
-
default: false
|
|
4
|
+
const vueTsx = require("./vue-tsx.cjs");
|
|
5
|
+
const props$1 = {
|
|
6
|
+
overlay: {
|
|
7
|
+
type: [String, Object],
|
|
8
|
+
default: ""
|
|
1945
9
|
},
|
|
1946
|
-
|
|
1947
|
-
* 不使用katex
|
|
1948
|
-
*
|
|
1949
|
-
* @default false
|
|
1950
|
-
*/
|
|
1951
|
-
noKatex: {
|
|
10
|
+
visible: {
|
|
1952
11
|
type: Boolean,
|
|
1953
12
|
default: false
|
|
1954
13
|
},
|
|
1955
|
-
|
|
1956
|
-
* 代码主题
|
|
1957
|
-
*
|
|
1958
|
-
* @default 'atom'
|
|
1959
|
-
*/
|
|
1960
|
-
codeTheme: {
|
|
1961
|
-
type: String,
|
|
1962
|
-
default: "atom"
|
|
1963
|
-
},
|
|
1964
|
-
/**
|
|
1965
|
-
* 复制代码格式化方法
|
|
1966
|
-
*
|
|
1967
|
-
* @default (text) => text
|
|
1968
|
-
*/
|
|
1969
|
-
formatCopiedText: {
|
|
14
|
+
onChange: {
|
|
1970
15
|
type: Function,
|
|
1971
|
-
default: (
|
|
1972
|
-
|
|
1973
|
-
/**
|
|
1974
|
-
* 某些预览主题的代码模块背景是暗色系
|
|
1975
|
-
* 将这个属性设置为true,会自动在该主题下的light模式下使用暗色系的代码风格
|
|
1976
|
-
*
|
|
1977
|
-
* @default true
|
|
1978
|
-
*/
|
|
1979
|
-
codeStyleReverse: {
|
|
1980
|
-
type: Boolean,
|
|
1981
|
-
default: true
|
|
1982
|
-
},
|
|
1983
|
-
/**
|
|
1984
|
-
* 需要自动调整的预览主题
|
|
1985
|
-
*
|
|
1986
|
-
* @default ['default', 'mk-cute']
|
|
1987
|
-
*/
|
|
1988
|
-
codeStyleReverseList: {
|
|
1989
|
-
type: Array,
|
|
1990
|
-
default: ["default", "mk-cute"]
|
|
1991
|
-
},
|
|
1992
|
-
noHighlight: {
|
|
1993
|
-
type: Boolean,
|
|
1994
|
-
default: false
|
|
1995
|
-
},
|
|
1996
|
-
/**
|
|
1997
|
-
* 是否关闭编辑器默认的放大缩小功能
|
|
1998
|
-
*/
|
|
1999
|
-
noImgZoomIn: {
|
|
2000
|
-
type: Boolean,
|
|
2001
|
-
default: false
|
|
2002
|
-
},
|
|
2003
|
-
/**
|
|
2004
|
-
* 自定义的图标
|
|
2005
|
-
*/
|
|
2006
|
-
customIcon: {
|
|
2007
|
-
type: Object,
|
|
2008
|
-
default: {}
|
|
16
|
+
default: () => {
|
|
17
|
+
}
|
|
2009
18
|
},
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
19
|
+
// 相对滚动的元素选择器
|
|
20
|
+
relative: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: "html"
|
|
2013
23
|
},
|
|
2014
|
-
|
|
2015
|
-
* 是否开启折叠代码功能
|
|
2016
|
-
* 不开启会使用div标签替代details标签
|
|
2017
|
-
*
|
|
2018
|
-
* @default true
|
|
2019
|
-
*/
|
|
2020
|
-
codeFoldable: {
|
|
24
|
+
disabled: {
|
|
2021
25
|
type: Boolean,
|
|
2022
|
-
default: true
|
|
2023
|
-
},
|
|
2024
|
-
/**
|
|
2025
|
-
* 触发自动折叠代码的行数阈值
|
|
2026
|
-
*
|
|
2027
|
-
* @default 30
|
|
2028
|
-
*/
|
|
2029
|
-
autoFoldThreshold: {
|
|
2030
|
-
type: Number,
|
|
2031
|
-
default: 30
|
|
2032
|
-
},
|
|
2033
|
-
/**
|
|
2034
|
-
* 内容重新挂载事件
|
|
2035
|
-
*
|
|
2036
|
-
* 相比起onHtmlChanged,onRemount会在重新挂载后触发
|
|
2037
|
-
*/
|
|
2038
|
-
onRemount: {
|
|
2039
|
-
type: Function,
|
|
2040
26
|
default: void 0
|
|
2041
27
|
}
|
|
2042
28
|
};
|
|
2043
|
-
const
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
29
|
+
const Dropdown = /* @__PURE__ */ vue.defineComponent({
|
|
30
|
+
name: `${config.prefix}-dropdown`,
|
|
31
|
+
props: props$1,
|
|
32
|
+
setup(props2, ctx) {
|
|
33
|
+
const HIDDEN_CLASS = `${config.prefix}-dropdown-hidden`;
|
|
34
|
+
const ctl = vue.reactive({
|
|
35
|
+
overlayClass: [HIDDEN_CLASS],
|
|
36
|
+
overlayStyle: {},
|
|
37
|
+
triggerHover: false,
|
|
38
|
+
overlayHover: false
|
|
39
|
+
});
|
|
40
|
+
const triggerRef = vue.ref();
|
|
41
|
+
const overlayRef = vue.ref();
|
|
42
|
+
const triggerHandler = () => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
if (props2.disabled) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
ctl.triggerHover = true;
|
|
48
|
+
const triggerEle = triggerRef.value;
|
|
49
|
+
const overlayEle = overlayRef.value;
|
|
50
|
+
if (!triggerEle || !overlayEle) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const triggerInfo = triggerEle.getBoundingClientRect();
|
|
54
|
+
const triggerTop = triggerEle.offsetTop;
|
|
55
|
+
const triggerLeft = triggerEle.offsetLeft;
|
|
56
|
+
const triggerHeight = triggerInfo.height;
|
|
57
|
+
const triggerWidth = triggerInfo.width;
|
|
58
|
+
const rootNode = triggerEle.getRootNode();
|
|
59
|
+
const relativecrollLeft = ((_a = rootNode.querySelector(props2.relative)) == null ? void 0 : _a.scrollLeft) || 0;
|
|
60
|
+
const relativeWidth = ((_b = rootNode.querySelector(props2.relative)) == null ? void 0 : _b.clientWidth) || 0;
|
|
61
|
+
let left = triggerLeft - overlayEle.offsetWidth / 2 + triggerWidth / 2 - relativecrollLeft;
|
|
62
|
+
if (left + overlayEle.offsetWidth > relativecrollLeft + relativeWidth) {
|
|
63
|
+
left = relativecrollLeft + relativeWidth - overlayEle.offsetWidth;
|
|
64
|
+
}
|
|
65
|
+
if (left < 0) {
|
|
66
|
+
left = 0;
|
|
67
|
+
}
|
|
68
|
+
ctl.overlayStyle = {
|
|
69
|
+
...ctl.overlayStyle,
|
|
70
|
+
top: triggerTop + triggerHeight + "px",
|
|
71
|
+
left: left + "px"
|
|
72
|
+
};
|
|
73
|
+
props2.onChange(true);
|
|
74
|
+
};
|
|
75
|
+
const overlayHandler = () => {
|
|
76
|
+
if (props2.disabled) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
ctl.overlayHover = true;
|
|
80
|
+
};
|
|
81
|
+
vue.watch(() => props2.visible, (newV) => {
|
|
82
|
+
if (newV) {
|
|
83
|
+
ctl.overlayClass = ctl.overlayClass.filter((classItem) => classItem !== HIDDEN_CLASS);
|
|
84
|
+
} else {
|
|
85
|
+
ctl.overlayClass.push(HIDDEN_CLASS);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
let hiddenTimer = -1;
|
|
89
|
+
const leaveHidden = (e) => {
|
|
90
|
+
if (triggerRef.value === e.target) {
|
|
91
|
+
ctl.triggerHover = false;
|
|
92
|
+
} else {
|
|
93
|
+
ctl.overlayHover = false;
|
|
94
|
+
}
|
|
95
|
+
clearTimeout(hiddenTimer);
|
|
96
|
+
hiddenTimer = window.setTimeout(() => {
|
|
97
|
+
if (!ctl.overlayHover && !ctl.triggerHover) {
|
|
98
|
+
props2.onChange(false);
|
|
99
|
+
}
|
|
100
|
+
}, 10);
|
|
101
|
+
};
|
|
102
|
+
vue.onMounted(() => {
|
|
103
|
+
triggerRef.value.addEventListener("mouseenter", triggerHandler);
|
|
104
|
+
triggerRef.value.addEventListener("mouseleave", leaveHidden);
|
|
105
|
+
overlayRef.value.addEventListener("mouseenter", overlayHandler);
|
|
106
|
+
overlayRef.value.addEventListener("mouseleave", leaveHidden);
|
|
107
|
+
});
|
|
108
|
+
vue.onBeforeUnmount(() => {
|
|
109
|
+
triggerRef.value.removeEventListener("mouseenter", triggerHandler);
|
|
110
|
+
triggerRef.value.removeEventListener("mouseleave", leaveHidden);
|
|
111
|
+
overlayRef.value.removeEventListener("mouseenter", overlayHandler);
|
|
112
|
+
overlayRef.value.removeEventListener("mouseleave", leaveHidden);
|
|
113
|
+
});
|
|
114
|
+
return () => {
|
|
115
|
+
const slotDefault = vueTsx.getSlot({
|
|
116
|
+
ctx
|
|
117
|
+
});
|
|
118
|
+
const slotOverlay = vueTsx.getSlot({
|
|
119
|
+
props: props2,
|
|
120
|
+
ctx
|
|
121
|
+
}, "overlay");
|
|
122
|
+
const trigger = vue.cloneVNode(slotDefault instanceof Array ? slotDefault[0] : slotDefault, {
|
|
123
|
+
ref: triggerRef,
|
|
124
|
+
key: "cloned-dropdown-trigger"
|
|
125
|
+
});
|
|
126
|
+
const overlay = vue.createVNode("div", {
|
|
127
|
+
"class": [`${config.prefix}-dropdown`, ctl.overlayClass],
|
|
128
|
+
"style": ctl.overlayStyle,
|
|
129
|
+
"ref": overlayRef
|
|
130
|
+
}, [vue.createVNode("div", {
|
|
131
|
+
"class": `${config.prefix}-dropdown-overlay`
|
|
132
|
+
}, [slotOverlay instanceof Array ? slotOverlay[0] : slotOverlay])]);
|
|
133
|
+
return [trigger, overlay];
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const props = {
|
|
138
|
+
title: {
|
|
2150
139
|
type: String,
|
|
2151
140
|
default: ""
|
|
2152
141
|
},
|
|
2153
|
-
|
|
2154
|
-
* 自定义的工具栏列表
|
|
2155
|
-
*/
|
|
2156
|
-
defToolbars: {
|
|
2157
|
-
type: [String, Object],
|
|
2158
|
-
default: void 0
|
|
2159
|
-
},
|
|
2160
|
-
/**
|
|
2161
|
-
* 内部错误捕获
|
|
2162
|
-
*/
|
|
2163
|
-
onError: {
|
|
2164
|
-
type: Function,
|
|
2165
|
-
default: void 0
|
|
2166
|
-
},
|
|
2167
|
-
/**
|
|
2168
|
-
* 页脚列表显示顺序
|
|
2169
|
-
*/
|
|
2170
|
-
footers: {
|
|
2171
|
-
type: Array,
|
|
2172
|
-
default: config.allFooter
|
|
2173
|
-
},
|
|
2174
|
-
/**
|
|
2175
|
-
* 是否默认激活输入框和预览框同步滚动
|
|
2176
|
-
*
|
|
2177
|
-
* @default true
|
|
2178
|
-
*/
|
|
2179
|
-
scrollAuto: {
|
|
2180
|
-
type: Boolean,
|
|
2181
|
-
default: true
|
|
2182
|
-
},
|
|
2183
|
-
/**
|
|
2184
|
-
* 自定义的也叫工具组件列表
|
|
2185
|
-
*/
|
|
2186
|
-
defFooters: {
|
|
2187
|
-
type: [String, Object],
|
|
2188
|
-
default: void 0
|
|
2189
|
-
},
|
|
2190
|
-
/**
|
|
2191
|
-
* 是否禁用上传图片
|
|
2192
|
-
*
|
|
2193
|
-
* @default false
|
|
2194
|
-
*/
|
|
2195
|
-
noUploadImg: {
|
|
2196
|
-
type: Boolean,
|
|
2197
|
-
default: false
|
|
2198
|
-
},
|
|
2199
|
-
/**
|
|
2200
|
-
* 文本区域自动获得焦点
|
|
2201
|
-
*
|
|
2202
|
-
* @default false
|
|
2203
|
-
*/
|
|
2204
|
-
autoFocus: {
|
|
2205
|
-
type: Boolean,
|
|
2206
|
-
default: false
|
|
2207
|
-
},
|
|
2208
|
-
/**
|
|
2209
|
-
* 禁用文本区域
|
|
2210
|
-
*
|
|
2211
|
-
* @default false
|
|
2212
|
-
*/
|
|
2213
|
-
disabled: {
|
|
2214
|
-
type: Boolean,
|
|
2215
|
-
default: false
|
|
2216
|
-
},
|
|
2217
|
-
/**
|
|
2218
|
-
* 文本区域为只读
|
|
2219
|
-
*
|
|
2220
|
-
* @default false
|
|
2221
|
-
*/
|
|
2222
|
-
readOnly: {
|
|
142
|
+
visible: {
|
|
2223
143
|
type: Boolean,
|
|
2224
|
-
default: false
|
|
2225
|
-
},
|
|
2226
|
-
/**
|
|
2227
|
-
* 文本区域允许的最大字符数
|
|
2228
|
-
*/
|
|
2229
|
-
maxLength: {
|
|
2230
|
-
type: Number,
|
|
2231
144
|
default: void 0
|
|
2232
145
|
},
|
|
2233
146
|
/**
|
|
2234
|
-
*
|
|
2235
|
-
* 目前支持 vscode 复制的代码识别
|
|
147
|
+
* 展示在工具栏的内容,通常是个图标
|
|
2236
148
|
*
|
|
2237
|
-
* @
|
|
149
|
+
* @deprecated 使用默认插槽代替
|
|
2238
150
|
*/
|
|
2239
|
-
|
|
2240
|
-
type:
|
|
2241
|
-
default: false
|
|
2242
|
-
},
|
|
2243
|
-
/**
|
|
2244
|
-
* 输入框失去焦点时触发事件
|
|
2245
|
-
*/
|
|
2246
|
-
onBlur: {
|
|
2247
|
-
type: Function,
|
|
151
|
+
trigger: {
|
|
152
|
+
type: [String, Object],
|
|
2248
153
|
default: void 0
|
|
2249
154
|
},
|
|
2250
|
-
|
|
2251
|
-
* 输入框获得焦点时触发事件
|
|
2252
|
-
*/
|
|
2253
|
-
onFocus: {
|
|
155
|
+
onChange: {
|
|
2254
156
|
type: Function,
|
|
2255
157
|
default: void 0
|
|
2256
158
|
},
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
* 它会被像下面这样嵌入编辑器
|
|
2261
|
-
*
|
|
2262
|
-
* import { autocompletion } from '@codemirror/autocomplete';
|
|
2263
|
-
* autocompletion({
|
|
2264
|
-
* override: [...completions]
|
|
2265
|
-
* })
|
|
2266
|
-
*/
|
|
2267
|
-
completions: {
|
|
2268
|
-
type: Array,
|
|
159
|
+
// 下拉框中的内容
|
|
160
|
+
overlay: {
|
|
161
|
+
type: [String, Object],
|
|
2269
162
|
default: void 0
|
|
2270
163
|
},
|
|
2271
164
|
/**
|
|
2272
|
-
*
|
|
2273
|
-
*
|
|
2274
|
-
* @default false
|
|
2275
|
-
*/
|
|
2276
|
-
showToolbarName: {
|
|
2277
|
-
type: Boolean,
|
|
2278
|
-
default: false
|
|
2279
|
-
},
|
|
2280
|
-
/**
|
|
2281
|
-
* 字符输入事件
|
|
165
|
+
* ==没有意义,仅用于规避克隆组件自动嵌入insert方法时,传入的是该组件而产生的waring
|
|
2282
166
|
*/
|
|
2283
|
-
|
|
167
|
+
insert: {
|
|
2284
168
|
type: Function,
|
|
2285
169
|
default: void 0
|
|
2286
170
|
},
|
|
2287
|
-
|
|
2288
|
-
type:
|
|
171
|
+
language: {
|
|
172
|
+
type: String,
|
|
2289
173
|
default: void 0
|
|
2290
174
|
},
|
|
2291
|
-
|
|
2292
|
-
* 输入框的默认宽度
|
|
2293
|
-
*
|
|
2294
|
-
* @example '100px'/'50%'
|
|
2295
|
-
* @default '50%
|
|
2296
|
-
*/
|
|
2297
|
-
inputBoxWidth: {
|
|
175
|
+
theme: {
|
|
2298
176
|
type: String,
|
|
2299
|
-
default: "50%"
|
|
2300
|
-
},
|
|
2301
|
-
/**
|
|
2302
|
-
* 输入框宽度变化事件
|
|
2303
|
-
*/
|
|
2304
|
-
oninputBoxWidthChange: {
|
|
2305
|
-
type: Function,
|
|
2306
177
|
default: void 0
|
|
2307
178
|
},
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
* @param t 图片链接
|
|
2312
|
-
* @returns
|
|
2313
|
-
*/
|
|
2314
|
-
transformImgUrl: {
|
|
2315
|
-
type: Function,
|
|
2316
|
-
default: (t) => t
|
|
179
|
+
previewTheme: {
|
|
180
|
+
type: String,
|
|
181
|
+
default: void 0
|
|
2317
182
|
},
|
|
2318
|
-
|
|
2319
|
-
* 内置的目录显示的状态
|
|
2320
|
-
*
|
|
2321
|
-
* 'fixed': 悬浮在内容上方
|
|
2322
|
-
* 'flat': 展示在右侧
|
|
2323
|
-
*
|
|
2324
|
-
* \>=5.3.0
|
|
2325
|
-
*
|
|
2326
|
-
* @default 'fixed'
|
|
2327
|
-
*/
|
|
2328
|
-
catalogLayout: {
|
|
183
|
+
codeTheme: {
|
|
2329
184
|
type: String,
|
|
2330
|
-
default:
|
|
185
|
+
default: void 0
|
|
2331
186
|
},
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
*/
|
|
2335
|
-
catalogMaxDepth: {
|
|
2336
|
-
type: Number,
|
|
187
|
+
disabled: {
|
|
188
|
+
type: Boolean,
|
|
2337
189
|
default: void 0
|
|
2338
190
|
},
|
|
2339
|
-
|
|
2340
|
-
* 工具栏直接插入内容到输入框
|
|
2341
|
-
*/
|
|
2342
|
-
insertLinkDirect: {
|
|
191
|
+
showToolbarName: {
|
|
2343
192
|
type: Boolean,
|
|
2344
|
-
default:
|
|
193
|
+
default: void 0
|
|
2345
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* ==结束
|
|
197
|
+
*/
|
|
2346
198
|
};
|
|
2347
|
-
const
|
|
2348
|
-
"
|
|
2349
|
-
|
|
2350
|
-
"onChange",
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
];
|
|
2354
|
-
const editorEmits = [
|
|
2355
|
-
...mdPreviewEmits,
|
|
2356
|
-
"onSave",
|
|
2357
|
-
"onUploadImg",
|
|
2358
|
-
"onError",
|
|
2359
|
-
"onBlur",
|
|
2360
|
-
"onFocus",
|
|
2361
|
-
"onInput",
|
|
2362
|
-
"onDrop",
|
|
2363
|
-
"oninputBoxWidthChange"
|
|
2364
|
-
];
|
|
2365
|
-
const useExpose = (props, ctx, options) => {
|
|
2366
|
-
const { editorId } = options;
|
|
2367
|
-
const exposeParam = {
|
|
2368
|
-
rerender() {
|
|
2369
|
-
eventName.bus.emit(editorId, eventName.RERENDER);
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
ctx.expose(exposeParam);
|
|
2373
|
-
};
|
|
2374
|
-
const MdPreview = /* @__PURE__ */ vue.defineComponent({
|
|
2375
|
-
name: "MdPreview",
|
|
2376
|
-
props: mdPreviewProps,
|
|
2377
|
-
emits: mdPreviewEmits,
|
|
2378
|
-
setup(props, ctx) {
|
|
2379
|
-
const {
|
|
2380
|
-
noKatex,
|
|
2381
|
-
noMermaid,
|
|
2382
|
-
noHighlight
|
|
2383
|
-
} = props;
|
|
2384
|
-
const rootRef = vue.ref();
|
|
2385
|
-
const {
|
|
2386
|
-
editorId
|
|
2387
|
-
} = useProvidePreview(props, rootRef);
|
|
2388
|
-
useExpose(props, ctx, {
|
|
2389
|
-
editorId
|
|
2390
|
-
});
|
|
2391
|
-
vue.onBeforeUnmount(() => {
|
|
2392
|
-
eventName.bus.clear(editorId);
|
|
2393
|
-
});
|
|
199
|
+
const DropdownToolbar = /* @__PURE__ */ vue.defineComponent({
|
|
200
|
+
name: "DropdownToolbar",
|
|
201
|
+
props,
|
|
202
|
+
emits: ["onChange"],
|
|
203
|
+
setup(props2, ctx) {
|
|
204
|
+
const editorId = vue.inject("editorId");
|
|
2394
205
|
return () => {
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
"
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
ctx.emit("onHtmlChanged", html);
|
|
2412
|
-
},
|
|
2413
|
-
"onGetCatalog": (list) => {
|
|
206
|
+
const Trigger = vueTsx.getSlot({
|
|
207
|
+
props: props2,
|
|
208
|
+
ctx
|
|
209
|
+
}, "trigger");
|
|
210
|
+
const Overlay = vueTsx.getSlot({
|
|
211
|
+
props: props2,
|
|
212
|
+
ctx
|
|
213
|
+
}, "overlay");
|
|
214
|
+
const Default = vueTsx.getSlot({
|
|
215
|
+
props: props2,
|
|
216
|
+
ctx
|
|
217
|
+
});
|
|
218
|
+
return vue.createVNode(Dropdown, {
|
|
219
|
+
"relative": `#${editorId}-toolbar-wrapper`,
|
|
220
|
+
"visible": props2.visible,
|
|
221
|
+
"onChange": (v) => {
|
|
2414
222
|
var _a;
|
|
2415
|
-
(_a =
|
|
2416
|
-
ctx.emit("
|
|
223
|
+
(_a = props2.onChange) == null ? void 0 : _a.call(props2, v);
|
|
224
|
+
ctx.emit("onChange", v);
|
|
2417
225
|
},
|
|
2418
|
-
"
|
|
2419
|
-
"
|
|
2420
|
-
|
|
2421
|
-
"
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
"sanitizeMermaid": props.sanitizeMermaid,
|
|
2427
|
-
"codeFoldable": props.codeFoldable,
|
|
2428
|
-
"autoFoldThreshold": props.autoFoldThreshold,
|
|
2429
|
-
"onRemount": () => {
|
|
2430
|
-
var _a;
|
|
2431
|
-
(_a = props.onRemount) == null ? void 0 : _a.call(props);
|
|
2432
|
-
ctx.emit("onRemount");
|
|
2433
|
-
}
|
|
2434
|
-
}, null)]);
|
|
226
|
+
"overlay": Overlay,
|
|
227
|
+
"disabled": props2.disabled
|
|
228
|
+
}, {
|
|
229
|
+
default: () => [vue.createVNode("div", {
|
|
230
|
+
"class": [`${config.prefix}-toolbar-item`, props2.disabled && `${config.prefix}-disabled`],
|
|
231
|
+
"title": props2.title || ""
|
|
232
|
+
}, [Default || Trigger])]
|
|
233
|
+
});
|
|
2435
234
|
};
|
|
2436
235
|
}
|
|
2437
236
|
});
|
|
2438
|
-
|
|
2439
|
-
app.component(
|
|
237
|
+
DropdownToolbar.install = (app) => {
|
|
238
|
+
app.component(DropdownToolbar.name, DropdownToolbar);
|
|
2440
239
|
return app;
|
|
2441
240
|
};
|
|
2442
|
-
exports.
|
|
2443
|
-
exports.
|
|
2444
|
-
exports.MdPreview = MdPreview;
|
|
2445
|
-
exports.contentProps = contentProps;
|
|
2446
|
-
exports.editorEmits = editorEmits;
|
|
2447
|
-
exports.editorProps = editorProps;
|
|
2448
|
-
exports.useCatalog = useCatalog;
|
|
2449
|
-
exports.useConfig = useConfig;
|
|
2450
|
-
exports.useErrorCatcher = useErrorCatcher;
|
|
2451
|
-
exports.useExpansion = useExpansion;
|
|
2452
|
-
exports.useExpose = useExpose$1;
|
|
2453
|
-
exports.useOnSave = useOnSave;
|
|
2454
|
-
exports.useProvide = useProvide;
|
|
241
|
+
exports.Dropdown = Dropdown;
|
|
242
|
+
exports.DropdownToolbar = DropdownToolbar;
|