md-editor-v3 2.5.0 → 2.6.0-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/README.md +17 -3
- package/lib/MdEditor/Editor.d.ts +30 -0
- package/lib/MdEditor/config.d.ts +1 -1
- package/lib/MdEditor/extensions/MdCatalog/CatalogLink.d.ts +13 -0
- package/lib/MdEditor/extensions/MdCatalog/index.d.ts +47 -0
- package/lib/MdEditor/index.d.ts +75 -0
- package/lib/MdEditor/type.d.ts +9 -0
- package/lib/md-editor-v3.es.js +113 -31
- package/lib/md-editor-v3.umd.js +29 -26
- package/lib/style.css +1 -1
- package/package.json +1 -1
package/lib/md-editor-v3.es.js
CHANGED
|
@@ -17,8 +17,9 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { reactive, watch, onMounted, onBeforeUnmount, provide, computed, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
|
|
20
|
+
import { reactive, watch, onMounted, onBeforeUnmount, provide, computed, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, mergeProps, isVNode } from "vue";
|
|
21
21
|
const prefix = "md-editor";
|
|
22
|
+
const defaultEditorId = "md-editor-v3";
|
|
22
23
|
const iconfontUrl = "https://at.alicdn.com/t/c/font_2605852_gymddm8qwtd.js";
|
|
23
24
|
const cdnBase = "https://cdnjs.cloudflare.com/ajax/libs";
|
|
24
25
|
const highlightUrl = `${cdnBase}/highlight.js/11.7.0/highlight.min.js`;
|
|
@@ -428,8 +429,7 @@ const base642File = (base64, fileName = "image.png") => {
|
|
|
428
429
|
while (n--) {
|
|
429
430
|
u8arr[n] = bstr.charCodeAt(n);
|
|
430
431
|
}
|
|
431
|
-
|
|
432
|
-
return file;
|
|
432
|
+
return new File([u8arr], fileName, { type: mime });
|
|
433
433
|
}
|
|
434
434
|
return null;
|
|
435
435
|
};
|
|
@@ -511,6 +511,13 @@ const getRelativeTop = (element, container) => {
|
|
|
511
511
|
const conRect = container == null ? void 0 : container.getBoundingClientRect();
|
|
512
512
|
return eleRect.top - conRect.top;
|
|
513
513
|
};
|
|
514
|
+
const omit = (obj, keys) => {
|
|
515
|
+
const omitObj = __spreadValues({}, obj);
|
|
516
|
+
keys.forEach((k) => {
|
|
517
|
+
Reflect.deleteProperty(omitObj, k);
|
|
518
|
+
});
|
|
519
|
+
return omitObj;
|
|
520
|
+
};
|
|
514
521
|
const keyMove = (trigger, moveHandler) => {
|
|
515
522
|
const triggerMouseDown = (mdown) => {
|
|
516
523
|
const parent = trigger.parentElement || document.body;
|
|
@@ -570,6 +577,7 @@ const FULL_SCREEN_CHANGED = "fullscreenChanged";
|
|
|
570
577
|
const PREVIEW_CHANGED = "previewChanged";
|
|
571
578
|
const HTML_PREVIEW_CHANGED = "htmlPreviewChanged";
|
|
572
579
|
const CATALOG_VISIBLE_CHANGED = "catalogVisibleChanged";
|
|
580
|
+
const TEXTAREA_FOCUS = "textarea_focus";
|
|
573
581
|
const useKeyBoard = (props, context) => {
|
|
574
582
|
const { editorId, noPrettier, previewOnly } = props;
|
|
575
583
|
const state = reactive({
|
|
@@ -1088,6 +1096,9 @@ const useExpose = (props, ctx, catalogVisible, setting, updateSetting) => {
|
|
|
1088
1096
|
},
|
|
1089
1097
|
insert(generate) {
|
|
1090
1098
|
bus.emit(editorId, "replace", "universal", { generate });
|
|
1099
|
+
},
|
|
1100
|
+
focus() {
|
|
1101
|
+
bus.emit(editorId, TEXTAREA_FOCUS);
|
|
1091
1102
|
}
|
|
1092
1103
|
};
|
|
1093
1104
|
ctx.expose(exposeParam);
|
|
@@ -1630,7 +1641,8 @@ var ClipModal = defineComponent({
|
|
|
1630
1641
|
"ref": uploadImgRef,
|
|
1631
1642
|
"style": {
|
|
1632
1643
|
display: "none"
|
|
1633
|
-
}
|
|
1644
|
+
},
|
|
1645
|
+
"alt": ""
|
|
1634
1646
|
}, null), createVNode("div", {
|
|
1635
1647
|
"class": `${prefix}-clip-delete`,
|
|
1636
1648
|
"onClick": reset
|
|
@@ -1736,7 +1748,7 @@ const useSreenfull = (props) => {
|
|
|
1736
1748
|
}
|
|
1737
1749
|
if (screenfull.isEnabled) {
|
|
1738
1750
|
screenfullMe.value = true;
|
|
1739
|
-
const targetStatus = status === void 0 ? !screenfull.isFullscreen :
|
|
1751
|
+
const targetStatus = status === void 0 ? !screenfull.isFullscreen : status;
|
|
1740
1752
|
if (targetStatus) {
|
|
1741
1753
|
screenfull.request();
|
|
1742
1754
|
} else {
|
|
@@ -5227,9 +5239,14 @@ const directive2flag = (direct, selectedText = "", inputArea, params) => {
|
|
|
5227
5239
|
break;
|
|
5228
5240
|
}
|
|
5229
5241
|
case "code": {
|
|
5230
|
-
|
|
5242
|
+
const text = params.text || selectedText || "";
|
|
5243
|
+
const mode = params.mode || "language";
|
|
5244
|
+
targetValue = `\`\`\`${mode}
|
|
5245
|
+
${text}
|
|
5246
|
+
\`\`\`
|
|
5247
|
+
`;
|
|
5231
5248
|
deviationStart = 3;
|
|
5232
|
-
deviationEnd =
|
|
5249
|
+
deviationEnd = 3 + mode.length - targetValue.length;
|
|
5233
5250
|
select = true;
|
|
5234
5251
|
break;
|
|
5235
5252
|
}
|
|
@@ -5502,13 +5519,12 @@ var kaTexExtensions = {
|
|
|
5502
5519
|
tokenizer(text) {
|
|
5503
5520
|
if (/^\$\$\n/.test(text) && text.split("$$").length > 2) {
|
|
5504
5521
|
const match = splitKatexValue(text, "$$");
|
|
5505
|
-
|
|
5522
|
+
return {
|
|
5506
5523
|
type: "KaTexBlockExtension",
|
|
5507
5524
|
raw: match[0],
|
|
5508
5525
|
text: match[1].trim(),
|
|
5509
5526
|
tokens: []
|
|
5510
5527
|
};
|
|
5511
|
-
return token;
|
|
5512
5528
|
}
|
|
5513
5529
|
},
|
|
5514
5530
|
renderer(token) {
|
|
@@ -5536,13 +5552,12 @@ var kaTexExtensions = {
|
|
|
5536
5552
|
tokenizer(text) {
|
|
5537
5553
|
if (/^\$[^\n]*\$/.test(text)) {
|
|
5538
5554
|
const match = splitKatexValue(text);
|
|
5539
|
-
|
|
5555
|
+
return {
|
|
5540
5556
|
type: "KaTexInlineExtension",
|
|
5541
5557
|
raw: match[0],
|
|
5542
5558
|
text: match[1].trim(),
|
|
5543
5559
|
tokens: []
|
|
5544
5560
|
};
|
|
5545
|
-
return token;
|
|
5546
5561
|
}
|
|
5547
5562
|
},
|
|
5548
5563
|
renderer(token) {
|
|
@@ -5689,13 +5704,13 @@ const useMarked = (props, mermaidData) => {
|
|
|
5689
5704
|
if (!props.noMermaid && language === "mermaid") {
|
|
5690
5705
|
const idRand = `${prefix}-mermaid-${Date.now().toString(36)}`;
|
|
5691
5706
|
try {
|
|
5692
|
-
let svgCode
|
|
5707
|
+
let svgCode;
|
|
5693
5708
|
if (mermaidIns) {
|
|
5694
|
-
svgCode = mermaidIns.
|
|
5709
|
+
svgCode = mermaidIns.render(idRand, code);
|
|
5695
5710
|
} else if (typeof window !== "undefined" && window.mermaid) {
|
|
5696
|
-
svgCode = window.mermaid.
|
|
5711
|
+
svgCode = window.mermaid.render(idRand, code);
|
|
5697
5712
|
} else {
|
|
5698
|
-
svgCode = `<p class="mermaid">${code}</p>`;
|
|
5713
|
+
svgCode = `<p class="${prefix}-mermaid-loading">${code}</p>`;
|
|
5699
5714
|
}
|
|
5700
5715
|
return `<p class="${prefix}-mermaid">${svgCode}</p>`;
|
|
5701
5716
|
} catch (error) {
|
|
@@ -5745,7 +5760,7 @@ const useMarked = (props, mermaidData) => {
|
|
|
5745
5760
|
if (highlightIns) {
|
|
5746
5761
|
marked.setOptions({
|
|
5747
5762
|
highlight: (code, language) => {
|
|
5748
|
-
let codeHtml
|
|
5763
|
+
let codeHtml;
|
|
5749
5764
|
const hljsLang = highlightIns.getLanguage(language);
|
|
5750
5765
|
if (language && hljsLang) {
|
|
5751
5766
|
codeHtml = highlightIns.highlight(code, {
|
|
@@ -5782,7 +5797,7 @@ const useMarked = (props, mermaidData) => {
|
|
|
5782
5797
|
const highlightLoad = () => {
|
|
5783
5798
|
marked.setOptions({
|
|
5784
5799
|
highlight: (code, language) => {
|
|
5785
|
-
let codeHtml
|
|
5800
|
+
let codeHtml;
|
|
5786
5801
|
const hljsLang = window.hljs.getLanguage(language);
|
|
5787
5802
|
if (language && hljsLang) {
|
|
5788
5803
|
codeHtml = window.hljs.highlight(code, {
|
|
@@ -6013,17 +6028,28 @@ const useMermaid = (props) => {
|
|
|
6013
6028
|
});
|
|
6014
6029
|
return mermaidData;
|
|
6015
6030
|
};
|
|
6016
|
-
const usePasteUpload = (textAreaRef) => {
|
|
6031
|
+
const usePasteUpload = (props, textAreaRef) => {
|
|
6017
6032
|
const editorId = inject("editorId");
|
|
6018
6033
|
const previewOnly = inject("previewOnly");
|
|
6019
6034
|
const pasteHandler = (e) => {
|
|
6020
|
-
if (e.clipboardData
|
|
6035
|
+
if (!e.clipboardData) {
|
|
6036
|
+
return;
|
|
6037
|
+
}
|
|
6038
|
+
if (e.clipboardData.files.length > 0) {
|
|
6021
6039
|
const { files } = e.clipboardData;
|
|
6022
6040
|
bus.emit(editorId, "uploadImage", Array.from(files).filter((file) => {
|
|
6023
6041
|
return /image\/.*/.test(file.type);
|
|
6024
6042
|
}));
|
|
6025
6043
|
e.preventDefault();
|
|
6026
6044
|
}
|
|
6045
|
+
if (props.autoDetectCode && e.clipboardData.types.includes("vscode-editor-data")) {
|
|
6046
|
+
const vscCoodInfo = JSON.parse(e.clipboardData.getData("vscode-editor-data"));
|
|
6047
|
+
bus.emit(editorId, "replace", "code", {
|
|
6048
|
+
mode: vscCoodInfo.mode,
|
|
6049
|
+
text: e.clipboardData.getData("text/plain")
|
|
6050
|
+
});
|
|
6051
|
+
e.preventDefault();
|
|
6052
|
+
}
|
|
6027
6053
|
};
|
|
6028
6054
|
onMounted(() => {
|
|
6029
6055
|
if (!previewOnly) {
|
|
@@ -6050,6 +6076,16 @@ const userZoom = (props, html) => {
|
|
|
6050
6076
|
onMounted(zoomHander);
|
|
6051
6077
|
watch([html, toRef(props.setting, "preview")], zoomHander);
|
|
6052
6078
|
};
|
|
6079
|
+
const useAttach = (textAreaRef) => {
|
|
6080
|
+
const editorId = inject("editorId");
|
|
6081
|
+
bus.on(editorId, {
|
|
6082
|
+
name: TEXTAREA_FOCUS,
|
|
6083
|
+
callback() {
|
|
6084
|
+
var _a;
|
|
6085
|
+
(_a = textAreaRef.value) == null ? void 0 : _a.focus();
|
|
6086
|
+
}
|
|
6087
|
+
});
|
|
6088
|
+
};
|
|
6053
6089
|
const contentProps = () => ({
|
|
6054
6090
|
value: {
|
|
6055
6091
|
type: String,
|
|
@@ -6100,6 +6136,21 @@ const contentProps = () => ({
|
|
|
6100
6136
|
formatCopiedText: {
|
|
6101
6137
|
type: Function,
|
|
6102
6138
|
default: (text) => text
|
|
6139
|
+
},
|
|
6140
|
+
autofocus: {
|
|
6141
|
+
type: Boolean
|
|
6142
|
+
},
|
|
6143
|
+
disabled: {
|
|
6144
|
+
type: Boolean
|
|
6145
|
+
},
|
|
6146
|
+
readonly: {
|
|
6147
|
+
type: Boolean
|
|
6148
|
+
},
|
|
6149
|
+
maxlength: {
|
|
6150
|
+
type: Number
|
|
6151
|
+
},
|
|
6152
|
+
autoDetectCode: {
|
|
6153
|
+
type: Boolean
|
|
6103
6154
|
}
|
|
6104
6155
|
});
|
|
6105
6156
|
var Content = defineComponent({
|
|
@@ -6121,17 +6172,18 @@ var Content = defineComponent({
|
|
|
6121
6172
|
useAutoScroll(props, html, textAreaRef, previewRef, htmlRef);
|
|
6122
6173
|
useAutoGenrator(props, textAreaRef);
|
|
6123
6174
|
useHistory(props, textAreaRef, completeStatus);
|
|
6124
|
-
usePasteUpload(textAreaRef);
|
|
6175
|
+
usePasteUpload(props, textAreaRef);
|
|
6125
6176
|
userZoom(props, html);
|
|
6177
|
+
useAttach(textAreaRef);
|
|
6126
6178
|
return () => {
|
|
6179
|
+
const attrs = omit(props, ["formatCopiedText", "markedHeadingId", "noKatex", "noMermaid", "onChange", "onGetCatalog", "onHtmlChanged", "sanitize", "scrollAuto", "setting", "autoDetectCode"]);
|
|
6127
6180
|
return createVNode(Fragment, null, [createVNode("div", {
|
|
6128
6181
|
"class": `${prefix}-content`
|
|
6129
6182
|
}, [!previewOnly && createVNode("div", {
|
|
6130
6183
|
"class": `${prefix}-input-wrapper`
|
|
6131
|
-
}, [createVNode("textarea", {
|
|
6184
|
+
}, [createVNode("textarea", mergeProps(attrs, {
|
|
6132
6185
|
"id": `${editorId}-textarea`,
|
|
6133
6186
|
"ref": textAreaRef,
|
|
6134
|
-
"value": props.value,
|
|
6135
6187
|
"onBlur": () => {
|
|
6136
6188
|
bus.emit(editorId, "selectTextChange");
|
|
6137
6189
|
},
|
|
@@ -6147,9 +6199,8 @@ var Content = defineComponent({
|
|
|
6147
6199
|
"onCompositionend": () => {
|
|
6148
6200
|
completeStatus.value = true;
|
|
6149
6201
|
},
|
|
6150
|
-
"class": [props.setting.preview || props.setting.htmlPreview ? "" : "textarea-only"]
|
|
6151
|
-
|
|
6152
|
-
}, null)]), props.setting.preview && createVNode("div", {
|
|
6202
|
+
"class": [props.setting.preview || props.setting.htmlPreview ? "" : "textarea-only"]
|
|
6203
|
+
}), null)]), props.setting.preview && createVNode("div", {
|
|
6153
6204
|
"id": `${editorId}-preview-wrapper`,
|
|
6154
6205
|
"class": `${prefix}-preview-wrapper`,
|
|
6155
6206
|
"ref": previewRef,
|
|
@@ -6327,6 +6378,10 @@ const catalogLinkProps = () => ({
|
|
|
6327
6378
|
type: Function,
|
|
6328
6379
|
default: () => () => {
|
|
6329
6380
|
}
|
|
6381
|
+
},
|
|
6382
|
+
scrollElementOffsetTop: {
|
|
6383
|
+
type: Number,
|
|
6384
|
+
default: 0
|
|
6330
6385
|
}
|
|
6331
6386
|
});
|
|
6332
6387
|
const CatalogLink = defineComponent({
|
|
@@ -6337,7 +6392,8 @@ const CatalogLink = defineComponent({
|
|
|
6337
6392
|
tocItem,
|
|
6338
6393
|
markedHeadingId: markedHeadingId2,
|
|
6339
6394
|
scrollElement,
|
|
6340
|
-
onClick
|
|
6395
|
+
onClick,
|
|
6396
|
+
scrollElementOffsetTop
|
|
6341
6397
|
} = props;
|
|
6342
6398
|
return createVNode("div", {
|
|
6343
6399
|
"class": [`${prefix}-catalog-link`, tocItem.active && `${prefix}-catalog-active`],
|
|
@@ -6357,7 +6413,7 @@ const CatalogLink = defineComponent({
|
|
|
6357
6413
|
}
|
|
6358
6414
|
}
|
|
6359
6415
|
scrollContainer == null ? void 0 : scrollContainer.scrollTo({
|
|
6360
|
-
top: offsetTop,
|
|
6416
|
+
top: offsetTop - scrollElementOffsetTop,
|
|
6361
6417
|
behavior: "smooth"
|
|
6362
6418
|
});
|
|
6363
6419
|
}
|
|
@@ -6371,7 +6427,8 @@ const CatalogLink = defineComponent({
|
|
|
6371
6427
|
"key": `${tocItem.text}-link-${item.level}-${item.text}`,
|
|
6372
6428
|
"tocItem": item,
|
|
6373
6429
|
"scrollElement": scrollElement,
|
|
6374
|
-
"onClick": onClick
|
|
6430
|
+
"onClick": onClick,
|
|
6431
|
+
"scrollElementOffsetTop": scrollElementOffsetTop
|
|
6375
6432
|
}, null))])]);
|
|
6376
6433
|
};
|
|
6377
6434
|
}
|
|
@@ -6399,6 +6456,10 @@ const mdCatalogProps = () => ({
|
|
|
6399
6456
|
offsetTop: {
|
|
6400
6457
|
type: Number,
|
|
6401
6458
|
default: 20
|
|
6459
|
+
},
|
|
6460
|
+
scrollElementOffsetTop: {
|
|
6461
|
+
type: Number,
|
|
6462
|
+
default: 0
|
|
6402
6463
|
}
|
|
6403
6464
|
});
|
|
6404
6465
|
const MdCatalog = defineComponent({
|
|
@@ -6514,7 +6575,8 @@ const MdCatalog = defineComponent({
|
|
|
6514
6575
|
"scrollElement": state.scrollElement,
|
|
6515
6576
|
"onClick": (e, t) => {
|
|
6516
6577
|
ctx.emit("onClick", e, t);
|
|
6517
|
-
}
|
|
6578
|
+
},
|
|
6579
|
+
"scrollElementOffsetTop": props.scrollElementOffsetTop
|
|
6518
6580
|
}, null);
|
|
6519
6581
|
})]);
|
|
6520
6582
|
}
|
|
@@ -6587,7 +6649,7 @@ const editorProps = () => ({
|
|
|
6587
6649
|
},
|
|
6588
6650
|
editorId: {
|
|
6589
6651
|
type: String,
|
|
6590
|
-
default:
|
|
6652
|
+
default: defaultEditorId
|
|
6591
6653
|
},
|
|
6592
6654
|
tabWidth: {
|
|
6593
6655
|
type: Number,
|
|
@@ -6667,6 +6729,21 @@ const editorProps = () => ({
|
|
|
6667
6729
|
codeStyleReverseList: {
|
|
6668
6730
|
type: Array,
|
|
6669
6731
|
default: ["default", "mk-cute"]
|
|
6732
|
+
},
|
|
6733
|
+
autoFocus: {
|
|
6734
|
+
type: Boolean
|
|
6735
|
+
},
|
|
6736
|
+
disabled: {
|
|
6737
|
+
type: Boolean
|
|
6738
|
+
},
|
|
6739
|
+
readOnly: {
|
|
6740
|
+
type: Boolean
|
|
6741
|
+
},
|
|
6742
|
+
maxLength: {
|
|
6743
|
+
type: Number
|
|
6744
|
+
},
|
|
6745
|
+
autoDetectCode: {
|
|
6746
|
+
type: Boolean
|
|
6670
6747
|
}
|
|
6671
6748
|
});
|
|
6672
6749
|
const markedHeadingId = (text) => text;
|
|
@@ -6750,7 +6827,12 @@ const Editor = defineComponent({
|
|
|
6750
6827
|
"placeholder": props.placeholder,
|
|
6751
6828
|
"noKatex": noKatex,
|
|
6752
6829
|
"scrollAuto": state.scrollAuto,
|
|
6753
|
-
"formatCopiedText": props.formatCopiedText
|
|
6830
|
+
"formatCopiedText": props.formatCopiedText,
|
|
6831
|
+
"autofocus": props.autoFocus,
|
|
6832
|
+
"disabled": props.disabled,
|
|
6833
|
+
"readonly": props.readOnly,
|
|
6834
|
+
"maxlength": props.maxLength,
|
|
6835
|
+
"autoDetectCode": props.autoDetectCode
|
|
6754
6836
|
}, null), !previewOnly && ((_a = props.footers) == null ? void 0 : _a.length) > 0 && createVNode(Footer, {
|
|
6755
6837
|
"modelValue": props.modelValue,
|
|
6756
6838
|
"footers": props.footers,
|