md-editor-v3 2.0.0-beta.8 → 2.0.1-beta.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/LICENSE +1 -1
- package/README.md +92 -34
- package/lib/MdEditor/Editor.d.ts +4 -4
- package/lib/MdEditor/index.d.ts +11 -11
- package/lib/MdEditor/type.d.ts +6 -1
- package/lib/md-editor-v3.es.js +171 -162
- package/lib/md-editor-v3.umd.js +59 -59
- package/lib/style.css +1 -1
- package/package.json +3 -3
package/lib/md-editor-v3.es.js
CHANGED
|
@@ -17,19 +17,20 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { onMounted, onBeforeUnmount, provide, computed,
|
|
20
|
+
import { onMounted, onBeforeUnmount, provide, computed, reactive, watch, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
|
|
21
21
|
const prefix = "md";
|
|
22
22
|
const iconfontUrl = "https://at.alicdn.com/t/font_2605852_pqekijay2ij.js";
|
|
23
|
-
const
|
|
23
|
+
const cdnBase = "https://cdnjs.cloudflare.com/ajax/libs";
|
|
24
|
+
const highlightUrl = `${cdnBase}/highlight.js/11.5.1/highlight.min.js`;
|
|
24
25
|
const prettierUrl = {
|
|
25
|
-
main:
|
|
26
|
-
markdown:
|
|
26
|
+
main: `${cdnBase}/prettier/2.4.0/standalone.js`,
|
|
27
|
+
markdown: `${cdnBase}/prettier/2.4.0/parser-markdown.js`
|
|
27
28
|
};
|
|
28
29
|
const cropperUrl = {
|
|
29
|
-
css:
|
|
30
|
-
js:
|
|
30
|
+
css: `${cdnBase}/cropperjs/1.5.12/cropper.min.css`,
|
|
31
|
+
js: `${cdnBase}/cropperjs/1.5.12/cropper.min.js`
|
|
31
32
|
};
|
|
32
|
-
const screenfullUrl =
|
|
33
|
+
const screenfullUrl = `${cdnBase}/screenfull.js/5.1.0/screenfull.min.js`;
|
|
33
34
|
const allToolbar = [
|
|
34
35
|
"bold",
|
|
35
36
|
"underline",
|
|
@@ -121,7 +122,8 @@ const staticTextDefault = {
|
|
|
121
122
|
},
|
|
122
123
|
copyCode: {
|
|
123
124
|
text: "\u590D\u5236\u4EE3\u7801",
|
|
124
|
-
|
|
125
|
+
successTips: "\u5DF2\u590D\u5236\uFF01",
|
|
126
|
+
failTips: "\u590D\u5236\u5931\u8D25\uFF01"
|
|
125
127
|
},
|
|
126
128
|
mermaid: {
|
|
127
129
|
flow: "\u6D41\u7A0B\u56FE",
|
|
@@ -195,7 +197,8 @@ const staticTextDefault = {
|
|
|
195
197
|
},
|
|
196
198
|
copyCode: {
|
|
197
199
|
text: "Copy",
|
|
198
|
-
|
|
200
|
+
successTips: "Copied!",
|
|
201
|
+
failTips: "Copy failed!"
|
|
199
202
|
},
|
|
200
203
|
mermaid: {
|
|
201
204
|
flow: "flow",
|
|
@@ -213,43 +216,43 @@ const staticTextDefault = {
|
|
|
213
216
|
}
|
|
214
217
|
}
|
|
215
218
|
};
|
|
216
|
-
const mermaidUrl =
|
|
219
|
+
const mermaidUrl = `${cdnBase}/mermaid/8.13.5/mermaid.min.js`;
|
|
217
220
|
const katexUrl = {
|
|
218
|
-
js:
|
|
219
|
-
css:
|
|
221
|
+
js: `${cdnBase}/KaTeX/0.15.1/katex.min.js`,
|
|
222
|
+
css: `${cdnBase}/KaTeX/0.15.1/katex.min.css`
|
|
220
223
|
};
|
|
221
224
|
const codeCss = {
|
|
222
225
|
a11y: {
|
|
223
|
-
light:
|
|
224
|
-
dark:
|
|
226
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/a11y-light.min.css`,
|
|
227
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/a11y-dark.min.css`
|
|
225
228
|
},
|
|
226
229
|
atom: {
|
|
227
|
-
light:
|
|
228
|
-
dark:
|
|
230
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/atom-one-light.min.css`,
|
|
231
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/atom-one-dark.min.css`
|
|
229
232
|
},
|
|
230
233
|
github: {
|
|
231
|
-
light:
|
|
232
|
-
dark:
|
|
234
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/github.min.css`,
|
|
235
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/github-dark.min.css`
|
|
233
236
|
},
|
|
234
237
|
gradient: {
|
|
235
|
-
light:
|
|
236
|
-
dark:
|
|
238
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/gradient-light.min.css`,
|
|
239
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/gradient-dark.min.css`
|
|
237
240
|
},
|
|
238
241
|
kimbie: {
|
|
239
|
-
light:
|
|
240
|
-
dark:
|
|
242
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/kimbie-light.min.css`,
|
|
243
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/kimbie-dark.min.css`
|
|
241
244
|
},
|
|
242
245
|
paraiso: {
|
|
243
|
-
light:
|
|
244
|
-
dark:
|
|
246
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/paraiso-light.min.css`,
|
|
247
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/paraiso-dark.min.css`
|
|
245
248
|
},
|
|
246
249
|
qtcreator: {
|
|
247
|
-
light:
|
|
248
|
-
dark:
|
|
250
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/qtcreator-light.min.css`,
|
|
251
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/qtcreator-dark.min.css`
|
|
249
252
|
},
|
|
250
253
|
stackoverflow: {
|
|
251
|
-
light:
|
|
252
|
-
dark:
|
|
254
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/stackoverflow-light.min.css`,
|
|
255
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/stackoverflow-dark.min.css`
|
|
253
256
|
}
|
|
254
257
|
};
|
|
255
258
|
class Bus {
|
|
@@ -495,10 +498,10 @@ const updateHandler = debounce((id, attr, value) => {
|
|
|
495
498
|
}
|
|
496
499
|
}, 10);
|
|
497
500
|
const useKeyBoard = (props2, context) => {
|
|
498
|
-
const { editorId } = props2;
|
|
501
|
+
const { editorId, noPrettier } = props2;
|
|
499
502
|
const initFunc = (name) => {
|
|
500
503
|
var _a, _b;
|
|
501
|
-
return ((_a = props2.toolbars) == null ? void 0 : _a.includes(name)) && !((_b = props2.toolbarsExclude) == null ? void 0 : _b.includes(name));
|
|
504
|
+
return ((_a = props2.toolbars) == null ? void 0 : _a.includes(name)) && !((_b = props2.toolbarsExclude) == null ? void 0 : _b.includes(name)) && !noPrettier;
|
|
502
505
|
};
|
|
503
506
|
const keyDownHandler = (event) => {
|
|
504
507
|
if (event.target !== document.querySelector(`#${props2.editorId}-textarea`)) {
|
|
@@ -821,6 +824,72 @@ const useExpansion = (props2, extension) => {
|
|
|
821
824
|
}
|
|
822
825
|
});
|
|
823
826
|
};
|
|
827
|
+
const useConfig = (props2, context) => {
|
|
828
|
+
const { editorId } = props2;
|
|
829
|
+
const setting = reactive({
|
|
830
|
+
pageFullScreen: props2.pageFullScreen,
|
|
831
|
+
fullscreen: false,
|
|
832
|
+
preview: props2.preview,
|
|
833
|
+
htmlPreview: props2.preview ? false : props2.htmlPreview
|
|
834
|
+
});
|
|
835
|
+
const updateSetting = (v, k) => {
|
|
836
|
+
setting[k] = v;
|
|
837
|
+
if (k === "preview" && setting.preview) {
|
|
838
|
+
setting.htmlPreview = false;
|
|
839
|
+
} else if (k === "htmlPreview" && setting.htmlPreview) {
|
|
840
|
+
setting.preview = false;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
let bodyOverflowHistory = "";
|
|
844
|
+
const adjustBody = () => {
|
|
845
|
+
if (setting.pageFullScreen || setting.fullscreen) {
|
|
846
|
+
document.body.style.overflow = "hidden";
|
|
847
|
+
} else {
|
|
848
|
+
document.body.style.overflow = bodyOverflowHistory;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
watch(() => [setting.pageFullScreen, setting.fullscreen], adjustBody);
|
|
852
|
+
onMounted(() => {
|
|
853
|
+
if (!props2.previewOnly) {
|
|
854
|
+
bus.on(editorId, {
|
|
855
|
+
name: "uploadImage",
|
|
856
|
+
callback(files, cb) {
|
|
857
|
+
const insertHanlder = (urls) => {
|
|
858
|
+
bus.emit(editorId, "replace", "image", {
|
|
859
|
+
desc: "",
|
|
860
|
+
urls
|
|
861
|
+
});
|
|
862
|
+
cb && cb();
|
|
863
|
+
};
|
|
864
|
+
if (props2.onUploadImg) {
|
|
865
|
+
props2.onUploadImg(files, insertHanlder);
|
|
866
|
+
} else {
|
|
867
|
+
context.emit("onUploadImg", files, insertHanlder);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
bodyOverflowHistory = document.body.style.overflow;
|
|
873
|
+
adjustBody();
|
|
874
|
+
});
|
|
875
|
+
return [setting, updateSetting];
|
|
876
|
+
};
|
|
877
|
+
const useCatalog = (props2) => {
|
|
878
|
+
const { editorId } = props2;
|
|
879
|
+
const catalogVisible = ref(false);
|
|
880
|
+
onMounted(() => {
|
|
881
|
+
bus.on(editorId, {
|
|
882
|
+
name: "catalogShow",
|
|
883
|
+
callback: () => {
|
|
884
|
+
catalogVisible.value = !catalogVisible.value;
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
});
|
|
888
|
+
const catalogShow = computed(() => {
|
|
889
|
+
return !props2.toolbarsExclude.includes("catalog") && props2.toolbars.includes("catalog");
|
|
890
|
+
});
|
|
891
|
+
return [catalogVisible, catalogShow];
|
|
892
|
+
};
|
|
824
893
|
var index$1 = "";
|
|
825
894
|
var Divider = defineComponent({
|
|
826
895
|
setup() {
|
|
@@ -5202,7 +5271,7 @@ var kaTexExtensions = {
|
|
|
5202
5271
|
};
|
|
5203
5272
|
}
|
|
5204
5273
|
};
|
|
5205
|
-
const useHistory = (props2, textAreaRef) => {
|
|
5274
|
+
const useHistory = (props2, textAreaRef, completeStatus) => {
|
|
5206
5275
|
var _a, _b;
|
|
5207
5276
|
const previewOnly = inject("previewOnly");
|
|
5208
5277
|
const historyLength = inject("historyLength");
|
|
@@ -5222,6 +5291,7 @@ const useHistory = (props2, textAreaRef) => {
|
|
|
5222
5291
|
userUpdated: true,
|
|
5223
5292
|
curr: 0
|
|
5224
5293
|
};
|
|
5294
|
+
let historyPos = [0, 0];
|
|
5225
5295
|
const keyZCallback = (curr) => {
|
|
5226
5296
|
var _a2, _b2;
|
|
5227
5297
|
const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
|
|
@@ -5234,41 +5304,46 @@ const useHistory = (props2, textAreaRef) => {
|
|
|
5234
5304
|
props2.onChange(currHistory.content);
|
|
5235
5305
|
setPosition(textAreaRef.value, currHistory.startPos, currHistory.endPos);
|
|
5236
5306
|
};
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
} else {
|
|
5267
|
-
history.userUpdated = true;
|
|
5268
|
-
}
|
|
5269
|
-
}, 150);
|
|
5307
|
+
const saveHistory = (content) => {
|
|
5308
|
+
var _a2, _b2;
|
|
5309
|
+
clearTimeout(saveHistoryId);
|
|
5310
|
+
const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
|
|
5311
|
+
const endPos = ((_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd) || 0;
|
|
5312
|
+
saveHistoryId = setTimeout(() => {
|
|
5313
|
+
if (history.userUpdated) {
|
|
5314
|
+
if (history.curr < history.list.length - 1) {
|
|
5315
|
+
history.list = history.list.slice(0, history.curr + 1);
|
|
5316
|
+
}
|
|
5317
|
+
if (history.list.length > historyLength) {
|
|
5318
|
+
history.list.shift();
|
|
5319
|
+
}
|
|
5320
|
+
const lastStep = history.list.pop() || {
|
|
5321
|
+
startPos: 0,
|
|
5322
|
+
endPos: 0,
|
|
5323
|
+
content
|
|
5324
|
+
};
|
|
5325
|
+
lastStep.startPos = historyPos[0];
|
|
5326
|
+
lastStep.endPos = historyPos[1];
|
|
5327
|
+
Array.prototype.push.call(history.list, lastStep, {
|
|
5328
|
+
content,
|
|
5329
|
+
startPos,
|
|
5330
|
+
endPos
|
|
5331
|
+
});
|
|
5332
|
+
history.curr = history.list.length - 1;
|
|
5333
|
+
saveHistoryPos();
|
|
5334
|
+
} else {
|
|
5335
|
+
history.userUpdated = true;
|
|
5270
5336
|
}
|
|
5271
|
-
});
|
|
5337
|
+
}, 150);
|
|
5338
|
+
};
|
|
5339
|
+
const saveHistoryPos = () => {
|
|
5340
|
+
var _a2, _b2;
|
|
5341
|
+
historyPos = [(_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart, (_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd];
|
|
5342
|
+
};
|
|
5343
|
+
watch([toRef(props2, "value"), completeStatus], () => {
|
|
5344
|
+
if (completeStatus.value) {
|
|
5345
|
+
saveHistory(props2.value);
|
|
5346
|
+
}
|
|
5272
5347
|
});
|
|
5273
5348
|
onMounted(() => {
|
|
5274
5349
|
bus.on(editorId, {
|
|
@@ -5283,11 +5358,18 @@ const useHistory = (props2, textAreaRef) => {
|
|
|
5283
5358
|
keyZCallback(history.curr + 1 === history.list.length ? history.curr : history.curr + 1);
|
|
5284
5359
|
}
|
|
5285
5360
|
});
|
|
5361
|
+
textAreaRef.value.addEventListener("click", saveHistoryPos);
|
|
5286
5362
|
});
|
|
5287
5363
|
};
|
|
5288
5364
|
const useMarked = (props2, mermaidData) => {
|
|
5289
5365
|
var _a, _b, _c;
|
|
5290
|
-
const {
|
|
5366
|
+
const {
|
|
5367
|
+
markedRenderer,
|
|
5368
|
+
markedExtensions,
|
|
5369
|
+
markedOptions,
|
|
5370
|
+
editorExtensions,
|
|
5371
|
+
editorConfig
|
|
5372
|
+
} = inject("extension");
|
|
5291
5373
|
const showCodeRowNumber = inject("showCodeRowNumber");
|
|
5292
5374
|
const editorId = inject("editorId");
|
|
5293
5375
|
const highlightUrl2 = inject("highlight");
|
|
@@ -5328,7 +5410,7 @@ const useMarked = (props2, mermaidData) => {
|
|
|
5328
5410
|
}
|
|
5329
5411
|
return markedCode.call(renderer, code, language, isEscaped);
|
|
5330
5412
|
};
|
|
5331
|
-
renderer.image = (href, title, desc) => {
|
|
5413
|
+
renderer.image = (href, title = "", desc = "") => {
|
|
5332
5414
|
return `<span class="figure"><img src="${href}" title="${title}" alt="${desc}"><span class="figcaption">${desc}</span></span>`;
|
|
5333
5415
|
};
|
|
5334
5416
|
renderer.listitem = (text, task) => {
|
|
@@ -5385,7 +5467,7 @@ const useMarked = (props2, mermaidData) => {
|
|
|
5385
5467
|
const _html = props2.sanitize(marked(props2.value || "", { renderer }));
|
|
5386
5468
|
html.value = _html;
|
|
5387
5469
|
props2.onHtmlChanged(_html);
|
|
5388
|
-
}, 500);
|
|
5470
|
+
}, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : 500);
|
|
5389
5471
|
watch([
|
|
5390
5472
|
highlightInited,
|
|
5391
5473
|
toRef(mermaidData, "reRender"),
|
|
@@ -5460,16 +5542,18 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
|
|
|
5460
5542
|
const initCopyEntry = () => {
|
|
5461
5543
|
document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
|
|
5462
5544
|
var _a;
|
|
5545
|
+
const copyBtnText = ((_a = ult.value.copyCode) == null ? void 0 : _a.text) || "\u590D\u5236\u4EE3\u7801";
|
|
5463
5546
|
const copyButton = document.createElement("span");
|
|
5464
5547
|
copyButton.setAttribute("class", "copy-button");
|
|
5465
|
-
copyButton.innerText =
|
|
5548
|
+
copyButton.innerText = copyBtnText;
|
|
5466
5549
|
copyButton.addEventListener("click", () => {
|
|
5467
|
-
var _a2;
|
|
5468
|
-
copyToClipboard(pre.querySelector("code").innerText);
|
|
5469
|
-
|
|
5550
|
+
var _a2, _b;
|
|
5551
|
+
const success = copyToClipboard(pre.querySelector("code").innerText);
|
|
5552
|
+
const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "\u5DF2\u590D\u5236\uFF01";
|
|
5553
|
+
const failTip = ((_b = ult.value.copyCode) == null ? void 0 : _b.failTips) || "\u5DF2\u590D\u5236\uFF01";
|
|
5554
|
+
copyButton.innerText = success ? succssTip : failTip;
|
|
5470
5555
|
setTimeout(() => {
|
|
5471
|
-
|
|
5472
|
-
copyButton.innerText = ((_a3 = ult.value.copyCode) == null ? void 0 : _a3.text) || "\u590D\u5236\u4EE3\u7801";
|
|
5556
|
+
copyButton.innerText = copyBtnText;
|
|
5473
5557
|
}, 1500);
|
|
5474
5558
|
});
|
|
5475
5559
|
pre.appendChild(copyButton);
|
|
@@ -5550,15 +5634,15 @@ ${nextOrder}. `, {}));
|
|
|
5550
5634
|
});
|
|
5551
5635
|
}
|
|
5552
5636
|
});
|
|
5637
|
+
watch(() => props2.value, () => {
|
|
5638
|
+
selectedText.value = "";
|
|
5639
|
+
});
|
|
5553
5640
|
bus.on(editorId, {
|
|
5554
5641
|
name: "selectTextChange",
|
|
5555
5642
|
callback() {
|
|
5556
5643
|
selectedText.value = getSelectionText(textAreaRef.value);
|
|
5557
5644
|
}
|
|
5558
5645
|
});
|
|
5559
|
-
return {
|
|
5560
|
-
selectedText
|
|
5561
|
-
};
|
|
5562
5646
|
};
|
|
5563
5647
|
const useMermaid = (props2) => {
|
|
5564
5648
|
const theme = inject("theme");
|
|
@@ -5705,15 +5789,13 @@ var Content = defineComponent({
|
|
|
5705
5789
|
html
|
|
5706
5790
|
} = useMarked(props2, mermaidData);
|
|
5707
5791
|
useAutoScroll(props2, html, textAreaRef, previewRef, htmlRef);
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
} = useAutoGenrator(props2, textAreaRef);
|
|
5711
|
-
useHistory(props2, textAreaRef);
|
|
5792
|
+
useAutoGenrator(props2, textAreaRef);
|
|
5793
|
+
useHistory(props2, textAreaRef, completeStatus);
|
|
5712
5794
|
usePasteUpload(textAreaRef);
|
|
5713
5795
|
userZoom(html);
|
|
5714
5796
|
return () => {
|
|
5715
5797
|
return createVNode(Fragment, null, [createVNode("div", {
|
|
5716
|
-
"class":
|
|
5798
|
+
"class": `${prefix}-content`
|
|
5717
5799
|
}, [!previewOnly && createVNode("div", {
|
|
5718
5800
|
"class": `${prefix}-input-wrapper`
|
|
5719
5801
|
}, [createVNode("textarea", {
|
|
@@ -5724,11 +5806,9 @@ var Content = defineComponent({
|
|
|
5724
5806
|
completeStatus.value = false;
|
|
5725
5807
|
},
|
|
5726
5808
|
"onInput": (e) => {
|
|
5727
|
-
|
|
5728
|
-
props2.onChange(e.target.value, completeStatus.value);
|
|
5809
|
+
props2.onChange(e.target.value);
|
|
5729
5810
|
},
|
|
5730
|
-
"onCompositionend": (
|
|
5731
|
-
bus.emit(editorId, "saveHistory", e.target.value);
|
|
5811
|
+
"onCompositionend": () => {
|
|
5732
5812
|
completeStatus.value = true;
|
|
5733
5813
|
},
|
|
5734
5814
|
"class": [props2.setting.preview || props2.setting.htmlPreview ? "" : "textarea-only"],
|
|
@@ -6015,7 +6095,7 @@ const props = {
|
|
|
6015
6095
|
const Editor = defineComponent({
|
|
6016
6096
|
name: "MdEditorV3",
|
|
6017
6097
|
props,
|
|
6018
|
-
emits: ["onChange", "onSave", "onUploadImg", "onHtmlChanged", "onGetCatalog", "onError"],
|
|
6098
|
+
emits: ["onChange", "onSave", "onUploadImg", "onHtmlChanged", "onGetCatalog", "onError", "update:modelValue"],
|
|
6019
6099
|
setup(props2, context) {
|
|
6020
6100
|
const {
|
|
6021
6101
|
editorId
|
|
@@ -6024,79 +6104,11 @@ const Editor = defineComponent({
|
|
|
6024
6104
|
useKeyBoard(props2, context);
|
|
6025
6105
|
useProvide(props2, extension);
|
|
6026
6106
|
useExpansion(props2, extension);
|
|
6027
|
-
const
|
|
6028
|
-
|
|
6029
|
-
});
|
|
6030
|
-
const setting = reactive({
|
|
6031
|
-
pageFullScreen: props2.pageFullScreen,
|
|
6032
|
-
fullscreen: false,
|
|
6033
|
-
preview: props2.preview,
|
|
6034
|
-
htmlPreview: props2.preview ? false : props2.htmlPreview
|
|
6035
|
-
});
|
|
6036
|
-
const updateSetting = (v, k) => {
|
|
6037
|
-
setting[k] = v;
|
|
6038
|
-
if (k === "preview" && setting.preview) {
|
|
6039
|
-
setting.htmlPreview = false;
|
|
6040
|
-
} else if (k === "htmlPreview" && setting.htmlPreview) {
|
|
6041
|
-
setting.preview = false;
|
|
6042
|
-
}
|
|
6043
|
-
};
|
|
6044
|
-
let bodyOverflowHistory = "";
|
|
6045
|
-
const adjustBody = () => {
|
|
6046
|
-
if (setting.pageFullScreen || setting.fullscreen) {
|
|
6047
|
-
document.body.style.overflow = "hidden";
|
|
6048
|
-
} else {
|
|
6049
|
-
document.body.style.overflow = bodyOverflowHistory;
|
|
6050
|
-
}
|
|
6051
|
-
};
|
|
6052
|
-
watch(() => [setting.pageFullScreen, setting.fullscreen], adjustBody);
|
|
6053
|
-
onMounted(() => {
|
|
6054
|
-
if (!props2.previewOnly) {
|
|
6055
|
-
bus.on(editorId, {
|
|
6056
|
-
name: "uploadImage",
|
|
6057
|
-
callback(files, cb) {
|
|
6058
|
-
const insertHanlder = (urls) => {
|
|
6059
|
-
bus.emit(editorId, "replace", "image", {
|
|
6060
|
-
desc: "",
|
|
6061
|
-
urls
|
|
6062
|
-
});
|
|
6063
|
-
cb && cb();
|
|
6064
|
-
};
|
|
6065
|
-
if (props2.onUploadImg) {
|
|
6066
|
-
props2.onUploadImg(files, insertHanlder);
|
|
6067
|
-
} else {
|
|
6068
|
-
context.emit("onUploadImg", files, insertHanlder);
|
|
6069
|
-
}
|
|
6070
|
-
}
|
|
6071
|
-
});
|
|
6072
|
-
}
|
|
6073
|
-
bodyOverflowHistory = document.body.style.overflow;
|
|
6074
|
-
adjustBody();
|
|
6075
|
-
bus.on(editorId, {
|
|
6076
|
-
name: "catalogShow",
|
|
6077
|
-
callback: () => {
|
|
6078
|
-
state.catalogVisible = !state.catalogVisible;
|
|
6079
|
-
}
|
|
6080
|
-
});
|
|
6081
|
-
});
|
|
6107
|
+
const [setting, updateSetting] = useConfig(props2, context);
|
|
6108
|
+
const [catalogVisible, catalogShow] = useCatalog(props2);
|
|
6082
6109
|
onBeforeUnmount(() => {
|
|
6083
6110
|
bus.clear(editorId);
|
|
6084
6111
|
});
|
|
6085
|
-
const catalogShow = computed(() => {
|
|
6086
|
-
return !props2.toolbarsExclude.includes("catalog") && props2.toolbars.includes("catalog");
|
|
6087
|
-
});
|
|
6088
|
-
onMounted(() => {
|
|
6089
|
-
bus.on(editorId, {
|
|
6090
|
-
name: "errorCatcher",
|
|
6091
|
-
callback: (err) => {
|
|
6092
|
-
if (props2.onError instanceof Function) {
|
|
6093
|
-
props2.onError(err);
|
|
6094
|
-
} else {
|
|
6095
|
-
context.emit("onError", err);
|
|
6096
|
-
}
|
|
6097
|
-
}
|
|
6098
|
-
});
|
|
6099
|
-
});
|
|
6100
6112
|
return () => {
|
|
6101
6113
|
var _a;
|
|
6102
6114
|
const defToolbars = getSlot({
|
|
@@ -6117,10 +6129,7 @@ const Editor = defineComponent({
|
|
|
6117
6129
|
"defToolbars": defToolbars
|
|
6118
6130
|
}, null), createVNode(Content, {
|
|
6119
6131
|
"value": props2.modelValue,
|
|
6120
|
-
"onChange": (value
|
|
6121
|
-
if (completeStatus) {
|
|
6122
|
-
bus.emit(editorId, "saveHistory", value);
|
|
6123
|
-
}
|
|
6132
|
+
"onChange": (value) => {
|
|
6124
6133
|
if (props2.onChange) {
|
|
6125
6134
|
props2.onChange(value);
|
|
6126
6135
|
} else {
|
|
@@ -6152,7 +6161,7 @@ const Editor = defineComponent({
|
|
|
6152
6161
|
}, null), catalogShow.value && createVNode(MdCatalog, {
|
|
6153
6162
|
"theme": props2.theme,
|
|
6154
6163
|
"style": {
|
|
6155
|
-
display:
|
|
6164
|
+
display: catalogVisible.value ? "block" : "none"
|
|
6156
6165
|
},
|
|
6157
6166
|
"class": `${prefix}-catalog-editor`,
|
|
6158
6167
|
"editorId": editorId,
|