md-editor-v3 2.0.0-beta.1 → 2.0.0-beta.10
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 +21 -21
- package/README.md +551 -530
- package/lib/MdEditor/Editor.d.ts +4 -7
- package/lib/MdEditor/extensions/DropdownToolbar.d.ts +1 -4
- package/lib/MdEditor/extensions/{Catalog → MdCatalog}/CatalogLink.d.ts +0 -0
- package/lib/MdEditor/extensions/{Catalog → MdCatalog}/index.d.ts +2 -2
- package/lib/MdEditor/extensions/ModalToolbar.d.ts +1 -10
- package/lib/MdEditor/extensions/NormalToolbar.d.ts +1 -4
- package/lib/MdEditor/index.d.ts +15 -20
- package/lib/MdEditor/type.d.ts +6 -1
- package/lib/md-editor-v3.es.js +107 -97
- package/lib/md-editor-v3.umd.js +39 -39
- package/lib/style.css +1 -1
- package/package.json +132 -132
package/lib/md-editor-v3.es.js
CHANGED
|
@@ -121,7 +121,8 @@ const staticTextDefault = {
|
|
|
121
121
|
},
|
|
122
122
|
copyCode: {
|
|
123
123
|
text: "\u590D\u5236\u4EE3\u7801",
|
|
124
|
-
|
|
124
|
+
successTips: "\u5DF2\u590D\u5236\uFF01",
|
|
125
|
+
failTips: "\u590D\u5236\u5931\u8D25\uFF01"
|
|
125
126
|
},
|
|
126
127
|
mermaid: {
|
|
127
128
|
flow: "\u6D41\u7A0B\u56FE",
|
|
@@ -195,7 +196,8 @@ const staticTextDefault = {
|
|
|
195
196
|
},
|
|
196
197
|
copyCode: {
|
|
197
198
|
text: "Copy",
|
|
198
|
-
|
|
199
|
+
successTips: "Copied!",
|
|
200
|
+
failTips: "Copy failed!"
|
|
199
201
|
},
|
|
200
202
|
mermaid: {
|
|
201
203
|
flow: "flow",
|
|
@@ -766,7 +768,7 @@ const useProvide = (props2, extension) => {
|
|
|
766
768
|
const cssList = __spreadValues(__spreadValues({}, codeCss), highlightConfig == null ? void 0 : highlightConfig.css);
|
|
767
769
|
return {
|
|
768
770
|
js: (highlightConfig == null ? void 0 : highlightConfig.js) || highlightUrl,
|
|
769
|
-
css: cssList[props2.
|
|
771
|
+
css: cssList[props2.codeTheme] ? cssList[props2.codeTheme][props2.theme] : codeCss.atom[props2.theme]
|
|
770
772
|
};
|
|
771
773
|
}));
|
|
772
774
|
provide("historyLength", props2.historyLength);
|
|
@@ -5202,7 +5204,7 @@ var kaTexExtensions = {
|
|
|
5202
5204
|
};
|
|
5203
5205
|
}
|
|
5204
5206
|
};
|
|
5205
|
-
const useHistory = (props2, textAreaRef) => {
|
|
5207
|
+
const useHistory = (props2, textAreaRef, completeStatus) => {
|
|
5206
5208
|
var _a, _b;
|
|
5207
5209
|
const previewOnly = inject("previewOnly");
|
|
5208
5210
|
const historyLength = inject("historyLength");
|
|
@@ -5222,68 +5224,85 @@ const useHistory = (props2, textAreaRef) => {
|
|
|
5222
5224
|
userUpdated: true,
|
|
5223
5225
|
curr: 0
|
|
5224
5226
|
};
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5227
|
+
let historyPos = [0, 0];
|
|
5228
|
+
const keyZCallback = (curr) => {
|
|
5229
|
+
var _a2, _b2;
|
|
5230
|
+
const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
|
|
5231
|
+
const endPos = ((_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd) || 0;
|
|
5232
|
+
history.list[history.curr].startPos = startPos;
|
|
5233
|
+
history.list[history.curr].endPos = endPos;
|
|
5234
|
+
history.userUpdated = false;
|
|
5235
|
+
history.curr = curr;
|
|
5236
|
+
const currHistory = history.list[history.curr];
|
|
5237
|
+
props2.onChange(currHistory.content);
|
|
5238
|
+
setPosition(textAreaRef.value, currHistory.startPos, currHistory.endPos);
|
|
5239
|
+
};
|
|
5240
|
+
const saveHistory = (content) => {
|
|
5241
|
+
var _a2, _b2;
|
|
5242
|
+
clearTimeout(saveHistoryId);
|
|
5243
|
+
const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
|
|
5244
|
+
const endPos = ((_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd) || 0;
|
|
5245
|
+
saveHistoryId = setTimeout(() => {
|
|
5246
|
+
if (history.userUpdated) {
|
|
5247
|
+
if (history.curr < history.list.length - 1) {
|
|
5248
|
+
history.list = history.list.slice(0, history.curr + 1);
|
|
5249
|
+
}
|
|
5250
|
+
if (history.list.length > historyLength) {
|
|
5251
|
+
history.list.shift();
|
|
5252
|
+
}
|
|
5253
|
+
const lastStep = history.list.pop() || {
|
|
5254
|
+
startPos: 0,
|
|
5255
|
+
endPos: 0,
|
|
5256
|
+
content
|
|
5257
|
+
};
|
|
5258
|
+
lastStep.startPos = historyPos[0];
|
|
5259
|
+
lastStep.endPos = historyPos[1];
|
|
5260
|
+
Array.prototype.push.call(history.list, lastStep, {
|
|
5261
|
+
content,
|
|
5262
|
+
startPos,
|
|
5263
|
+
endPos
|
|
5264
|
+
});
|
|
5265
|
+
history.curr = history.list.length - 1;
|
|
5266
|
+
saveHistoryPos();
|
|
5267
|
+
} else {
|
|
5268
|
+
history.userUpdated = true;
|
|
5258
5269
|
}
|
|
5259
|
-
});
|
|
5270
|
+
}, 150);
|
|
5271
|
+
};
|
|
5272
|
+
const saveHistoryPos = () => {
|
|
5273
|
+
var _a2, _b2;
|
|
5274
|
+
historyPos = [(_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart, (_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd];
|
|
5275
|
+
};
|
|
5276
|
+
watch([toRef(props2, "value"), completeStatus], () => {
|
|
5277
|
+
if (completeStatus.value) {
|
|
5278
|
+
saveHistory(props2.value);
|
|
5279
|
+
}
|
|
5260
5280
|
});
|
|
5261
5281
|
onMounted(() => {
|
|
5262
5282
|
bus.on(editorId, {
|
|
5263
5283
|
name: "ctrlZ",
|
|
5264
5284
|
callback() {
|
|
5265
|
-
history.
|
|
5266
|
-
history.curr = history.curr - 1 < 0 ? 0 : history.curr - 1;
|
|
5267
|
-
const currHistory = history.list[history.curr];
|
|
5268
|
-
props2.onChange(currHistory.content);
|
|
5269
|
-
setPosition(textAreaRef.value, currHistory.startPos, currHistory.endPos);
|
|
5285
|
+
keyZCallback(history.curr - 1 < 0 ? 0 : history.curr - 1);
|
|
5270
5286
|
}
|
|
5271
5287
|
});
|
|
5272
5288
|
bus.on(editorId, {
|
|
5273
5289
|
name: "ctrlShiftZ",
|
|
5274
5290
|
callback() {
|
|
5275
|
-
history.
|
|
5276
|
-
history.curr = history.curr + 1 === history.list.length ? history.curr : history.curr + 1;
|
|
5277
|
-
const currHistory = history.list[history.curr];
|
|
5278
|
-
props2.onChange(currHistory.content);
|
|
5279
|
-
setPosition(textAreaRef.value, currHistory.startPos, currHistory.endPos);
|
|
5291
|
+
keyZCallback(history.curr + 1 === history.list.length ? history.curr : history.curr + 1);
|
|
5280
5292
|
}
|
|
5281
5293
|
});
|
|
5294
|
+
textAreaRef.value.addEventListener("click", saveHistoryPos);
|
|
5282
5295
|
});
|
|
5283
5296
|
};
|
|
5284
5297
|
const useMarked = (props2, mermaidData) => {
|
|
5285
5298
|
var _a, _b, _c;
|
|
5286
|
-
const {
|
|
5299
|
+
const {
|
|
5300
|
+
markedRenderer,
|
|
5301
|
+
markedExtensions,
|
|
5302
|
+
markedOptions,
|
|
5303
|
+
editorExtensions,
|
|
5304
|
+
editorConfig
|
|
5305
|
+
} = inject("extension");
|
|
5287
5306
|
const showCodeRowNumber = inject("showCodeRowNumber");
|
|
5288
5307
|
const editorId = inject("editorId");
|
|
5289
5308
|
const highlightUrl2 = inject("highlight");
|
|
@@ -5381,7 +5400,7 @@ const useMarked = (props2, mermaidData) => {
|
|
|
5381
5400
|
const _html = props2.sanitize(marked(props2.value || "", { renderer }));
|
|
5382
5401
|
html.value = _html;
|
|
5383
5402
|
props2.onHtmlChanged(_html);
|
|
5384
|
-
}, 500);
|
|
5403
|
+
}, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : 500);
|
|
5385
5404
|
watch([
|
|
5386
5405
|
highlightInited,
|
|
5387
5406
|
toRef(mermaidData, "reRender"),
|
|
@@ -5454,18 +5473,20 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
|
|
|
5454
5473
|
let initScrollAuto = () => {
|
|
5455
5474
|
};
|
|
5456
5475
|
const initCopyEntry = () => {
|
|
5457
|
-
document.querySelectorAll(`#${editorId}
|
|
5476
|
+
document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
|
|
5458
5477
|
var _a;
|
|
5478
|
+
const copyBtnText = ((_a = ult.value.copyCode) == null ? void 0 : _a.text) || "\u590D\u5236\u4EE3\u7801";
|
|
5459
5479
|
const copyButton = document.createElement("span");
|
|
5460
5480
|
copyButton.setAttribute("class", "copy-button");
|
|
5461
|
-
copyButton.innerText =
|
|
5481
|
+
copyButton.innerText = copyBtnText;
|
|
5462
5482
|
copyButton.addEventListener("click", () => {
|
|
5463
|
-
var _a2;
|
|
5464
|
-
copyToClipboard(pre.querySelector("code").innerText);
|
|
5465
|
-
|
|
5483
|
+
var _a2, _b;
|
|
5484
|
+
const success = copyToClipboard(pre.querySelector("code").innerText);
|
|
5485
|
+
const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "\u5DF2\u590D\u5236\uFF01";
|
|
5486
|
+
const failTip = ((_b = ult.value.copyCode) == null ? void 0 : _b.failTips) || "\u5DF2\u590D\u5236\uFF01";
|
|
5487
|
+
copyButton.innerText = success ? succssTip : failTip;
|
|
5466
5488
|
setTimeout(() => {
|
|
5467
|
-
|
|
5468
|
-
copyButton.innerText = ((_a3 = ult.value.copyCode) == null ? void 0 : _a3.text) || "\u590D\u5236\u4EE3\u7801";
|
|
5489
|
+
copyButton.innerText = copyBtnText;
|
|
5469
5490
|
}, 1500);
|
|
5470
5491
|
});
|
|
5471
5492
|
pre.appendChild(copyButton);
|
|
@@ -5546,15 +5567,15 @@ ${nextOrder}. `, {}));
|
|
|
5546
5567
|
});
|
|
5547
5568
|
}
|
|
5548
5569
|
});
|
|
5570
|
+
watch(() => props2.value, () => {
|
|
5571
|
+
selectedText.value = "";
|
|
5572
|
+
});
|
|
5549
5573
|
bus.on(editorId, {
|
|
5550
5574
|
name: "selectTextChange",
|
|
5551
5575
|
callback() {
|
|
5552
5576
|
selectedText.value = getSelectionText(textAreaRef.value);
|
|
5553
5577
|
}
|
|
5554
5578
|
});
|
|
5555
|
-
return {
|
|
5556
|
-
selectedText
|
|
5557
|
-
};
|
|
5558
5579
|
};
|
|
5559
5580
|
const useMermaid = (props2) => {
|
|
5560
5581
|
const theme = inject("theme");
|
|
@@ -5701,10 +5722,8 @@ var Content = defineComponent({
|
|
|
5701
5722
|
html
|
|
5702
5723
|
} = useMarked(props2, mermaidData);
|
|
5703
5724
|
useAutoScroll(props2, html, textAreaRef, previewRef, htmlRef);
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
} = useAutoGenrator(props2, textAreaRef);
|
|
5707
|
-
useHistory(props2, textAreaRef);
|
|
5725
|
+
useAutoGenrator(props2, textAreaRef);
|
|
5726
|
+
useHistory(props2, textAreaRef, completeStatus);
|
|
5708
5727
|
usePasteUpload(textAreaRef);
|
|
5709
5728
|
userZoom(html);
|
|
5710
5729
|
return () => {
|
|
@@ -5720,11 +5739,9 @@ var Content = defineComponent({
|
|
|
5720
5739
|
completeStatus.value = false;
|
|
5721
5740
|
},
|
|
5722
5741
|
"onInput": (e) => {
|
|
5723
|
-
|
|
5724
|
-
props2.onChange(e.target.value, completeStatus.value);
|
|
5742
|
+
props2.onChange(e.target.value);
|
|
5725
5743
|
},
|
|
5726
|
-
"onCompositionend": (
|
|
5727
|
-
bus.emit(editorId, "saveHistory", e.target.value);
|
|
5744
|
+
"onCompositionend": () => {
|
|
5728
5745
|
completeStatus.value = true;
|
|
5729
5746
|
},
|
|
5730
5747
|
"class": [props2.setting.preview || props2.setting.htmlPreview ? "" : "textarea-only"],
|
|
@@ -5800,8 +5817,8 @@ const CatalogLink = defineComponent({
|
|
|
5800
5817
|
}
|
|
5801
5818
|
});
|
|
5802
5819
|
var style = "";
|
|
5803
|
-
const
|
|
5804
|
-
name: "
|
|
5820
|
+
const MdCatalog = defineComponent({
|
|
5821
|
+
name: "MdCatalog",
|
|
5805
5822
|
props: {
|
|
5806
5823
|
editorId: {
|
|
5807
5824
|
type: String
|
|
@@ -6001,11 +6018,9 @@ const props = {
|
|
|
6001
6018
|
type: [String, Object]
|
|
6002
6019
|
},
|
|
6003
6020
|
onError: {
|
|
6004
|
-
type: Function
|
|
6005
|
-
default: () => () => {
|
|
6006
|
-
}
|
|
6021
|
+
type: Function
|
|
6007
6022
|
},
|
|
6008
|
-
|
|
6023
|
+
codeTheme: {
|
|
6009
6024
|
type: String,
|
|
6010
6025
|
default: "atom"
|
|
6011
6026
|
}
|
|
@@ -6013,6 +6028,7 @@ const props = {
|
|
|
6013
6028
|
const Editor = defineComponent({
|
|
6014
6029
|
name: "MdEditorV3",
|
|
6015
6030
|
props,
|
|
6031
|
+
emits: ["onChange", "onSave", "onUploadImg", "onHtmlChanged", "onGetCatalog", "onError"],
|
|
6016
6032
|
setup(props2, context) {
|
|
6017
6033
|
const {
|
|
6018
6034
|
editorId
|
|
@@ -6086,7 +6102,11 @@ const Editor = defineComponent({
|
|
|
6086
6102
|
bus.on(editorId, {
|
|
6087
6103
|
name: "errorCatcher",
|
|
6088
6104
|
callback: (err) => {
|
|
6089
|
-
props2.onError
|
|
6105
|
+
if (props2.onError instanceof Function) {
|
|
6106
|
+
props2.onError(err);
|
|
6107
|
+
} else {
|
|
6108
|
+
context.emit("onError", err);
|
|
6109
|
+
}
|
|
6090
6110
|
}
|
|
6091
6111
|
});
|
|
6092
6112
|
});
|
|
@@ -6110,10 +6130,7 @@ const Editor = defineComponent({
|
|
|
6110
6130
|
"defToolbars": defToolbars
|
|
6111
6131
|
}, null), createVNode(Content, {
|
|
6112
6132
|
"value": props2.modelValue,
|
|
6113
|
-
"onChange": (value
|
|
6114
|
-
if (completeStatus) {
|
|
6115
|
-
bus.emit(editorId, "saveHistory", value);
|
|
6116
|
-
}
|
|
6133
|
+
"onChange": (value) => {
|
|
6117
6134
|
if (props2.onChange) {
|
|
6118
6135
|
props2.onChange(value);
|
|
6119
6136
|
} else {
|
|
@@ -6142,7 +6159,7 @@ const Editor = defineComponent({
|
|
|
6142
6159
|
"placeholder": props2.placeholder,
|
|
6143
6160
|
"noKatex": props2.noKatex,
|
|
6144
6161
|
"mermaidTemplate": (_a = extension == null ? void 0 : extension.editorConfig) == null ? void 0 : _a.mermaidTemplate
|
|
6145
|
-
}, null), catalogShow.value && createVNode(
|
|
6162
|
+
}, null), catalogShow.value && createVNode(MdCatalog, {
|
|
6146
6163
|
"theme": props2.theme,
|
|
6147
6164
|
"style": {
|
|
6148
6165
|
display: state.catalogVisible ? "block" : "none"
|
|
@@ -6165,11 +6182,10 @@ var NormalToolbar = defineComponent({
|
|
|
6165
6182
|
type: [String, Object]
|
|
6166
6183
|
},
|
|
6167
6184
|
onClick: {
|
|
6168
|
-
type: Function
|
|
6169
|
-
default: () => () => {
|
|
6170
|
-
}
|
|
6185
|
+
type: Function
|
|
6171
6186
|
}
|
|
6172
6187
|
},
|
|
6188
|
+
emits: ["onClick"],
|
|
6173
6189
|
setup(props2, ctx) {
|
|
6174
6190
|
return () => {
|
|
6175
6191
|
const Trigger = getSlot({
|
|
@@ -6204,14 +6220,13 @@ var DropdownToolbar = defineComponent({
|
|
|
6204
6220
|
type: [String, Object]
|
|
6205
6221
|
},
|
|
6206
6222
|
onChange: {
|
|
6207
|
-
type: Function
|
|
6208
|
-
default: () => () => {
|
|
6209
|
-
}
|
|
6223
|
+
type: Function
|
|
6210
6224
|
},
|
|
6211
6225
|
overlay: {
|
|
6212
6226
|
type: [String, Object]
|
|
6213
6227
|
}
|
|
6214
6228
|
},
|
|
6229
|
+
emits: ["onChange"],
|
|
6215
6230
|
setup(props2, ctx) {
|
|
6216
6231
|
const editorId = inject("editorId");
|
|
6217
6232
|
return () => {
|
|
@@ -6272,14 +6287,10 @@ var ModalToolbar = defineComponent({
|
|
|
6272
6287
|
type: [String, Object]
|
|
6273
6288
|
},
|
|
6274
6289
|
onClick: {
|
|
6275
|
-
type: Function
|
|
6276
|
-
default: () => () => {
|
|
6277
|
-
}
|
|
6290
|
+
type: Function
|
|
6278
6291
|
},
|
|
6279
6292
|
onClose: {
|
|
6280
|
-
type: Function
|
|
6281
|
-
default: () => () => {
|
|
6282
|
-
}
|
|
6293
|
+
type: Function
|
|
6283
6294
|
},
|
|
6284
6295
|
showAdjust: {
|
|
6285
6296
|
type: Boolean,
|
|
@@ -6290,11 +6301,10 @@ var ModalToolbar = defineComponent({
|
|
|
6290
6301
|
default: false
|
|
6291
6302
|
},
|
|
6292
6303
|
onAdjust: {
|
|
6293
|
-
type: Function
|
|
6294
|
-
default: () => () => {
|
|
6295
|
-
}
|
|
6304
|
+
type: Function
|
|
6296
6305
|
}
|
|
6297
6306
|
},
|
|
6307
|
+
emits: ["onClick", "onClose", "onAdjust"],
|
|
6298
6308
|
setup(props2, ctx) {
|
|
6299
6309
|
return () => {
|
|
6300
6310
|
const Trigger = getSlot({
|
|
@@ -6357,13 +6367,13 @@ Editor.install = (app) => {
|
|
|
6357
6367
|
app.component(Editor.name, Editor);
|
|
6358
6368
|
app.component(NormalToolbar.name, NormalToolbar);
|
|
6359
6369
|
app.component(DropdownToolbar.name, DropdownToolbar);
|
|
6360
|
-
app.component(
|
|
6370
|
+
app.component(MdCatalog.name, MdCatalog);
|
|
6361
6371
|
app.component(ModalToolbar.name, ModalToolbar);
|
|
6362
6372
|
return app;
|
|
6363
6373
|
};
|
|
6364
6374
|
Editor.NormalToolbar = NormalToolbar;
|
|
6365
6375
|
Editor.DropdownToolbar = DropdownToolbar;
|
|
6366
|
-
Editor.
|
|
6376
|
+
Editor.MdCatalog = MdCatalog;
|
|
6367
6377
|
Editor.ModalToolbar = ModalToolbar;
|
|
6368
6378
|
Editor.config = config;
|
|
6369
6379
|
export { Editor as default };
|