md-editor-v3 4.13.0-beta.0 → 4.13.1
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 +1 -0
- package/lib/cjs/MdEditor.cjs +81 -14
- package/lib/cjs/chunks/index.cjs +14 -0
- package/lib/es/MdEditor.mjs +81 -14
- package/lib/es/chunks/index.mjs +14 -0
- package/lib/style.css +58 -0
- package/lib/types/MdEditor/Editor.d.ts +9 -0
- package/lib/types/MdEditor/index.d.ts +20 -1
- package/lib/types/MdEditor/layouts/Content/composition/usePasteUpload.d.ts +3 -1
- package/lib/types/MdEditor/layouts/Content/index.d.ts +9 -0
- package/lib/types/MdEditor/layouts/Content/props.d.ts +4 -0
- package/lib/types/MdEditor/props.d.ts +10 -0
- package/lib/umd/index.js +40 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,6 +151,7 @@ Except for the same as `MdPreview`:
|
|
|
151
151
|
| completions | `Array<CompletionSource>` | [] | `@codemirror/autocomplete` List of function to match keywords |
|
|
152
152
|
| showToolbarName | `boolean` | false | Show toolbar name or not |
|
|
153
153
|
| inputBoxWitdh | `string` | '50%' | Default width of input box |
|
|
154
|
+
| transformImgUrl | `(imgUrl: string) => string \| Promise<string>` | t => t | Transform image links |
|
|
154
155
|
|
|
155
156
|
<details>
|
|
156
157
|
<summary>『toolbars』</summary>
|
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -21,6 +21,7 @@ const commands = require("@codemirror/commands");
|
|
|
21
21
|
const language = require("@codemirror/language");
|
|
22
22
|
const highlight = require("@lezer/highlight");
|
|
23
23
|
const autocomplete = require("@codemirror/autocomplete");
|
|
24
|
+
const search = require("@codemirror/search");
|
|
24
25
|
const MdPreview = require("./chunks/index.cjs");
|
|
25
26
|
const MdCatalog = require("./MdCatalog.cjs");
|
|
26
27
|
const vueTsx = require("./chunks/vue-tsx.cjs");
|
|
@@ -1188,7 +1189,8 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
|
|
|
1188
1189
|
if (data) {
|
|
1189
1190
|
emitHandler(modalData.type, {
|
|
1190
1191
|
desc: data.desc,
|
|
1191
|
-
url: data.url
|
|
1192
|
+
url: data.url,
|
|
1193
|
+
transform: modalData.type === "image"
|
|
1192
1194
|
});
|
|
1193
1195
|
}
|
|
1194
1196
|
modalData.linkVisible = false;
|
|
@@ -1779,8 +1781,8 @@ const oneDarkTheme = view.EditorView.theme(
|
|
|
1779
1781
|
".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor$1 },
|
|
1780
1782
|
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection$1 },
|
|
1781
1783
|
".cm-panels": { backgroundColor: darkBackground$1, color: ivory$1 },
|
|
1782
|
-
".cm-panels.cm-panels-top": { borderBottom: "
|
|
1783
|
-
".cm-panels.cm-panels-bottom": { borderTop: "
|
|
1784
|
+
".cm-panels.cm-panels-top": { borderBottom: "1px solid var(--md-border-color)" },
|
|
1785
|
+
".cm-panels.cm-panels-bottom": { borderTop: "1px solid var(--md-border-color)" },
|
|
1784
1786
|
".cm-searchMatch": {
|
|
1785
1787
|
backgroundColor: "#72a1ff59",
|
|
1786
1788
|
outline: "1px solid #457dff"
|
|
@@ -1872,7 +1874,7 @@ const oneDark = [
|
|
|
1872
1874
|
oneDarkTheme,
|
|
1873
1875
|
language.syntaxHighlighting(oneDarkHighlightStyle)
|
|
1874
1876
|
];
|
|
1875
|
-
const chalky = "#e5c07b", coral = "#3f4a54", cyan = "#56b6c2", invalid = "#fff", ivory = "#3f4a54", stone = "#2d8cf0", malibu = "#2d8cf0", sage = "#3f4a54", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#
|
|
1877
|
+
const chalky = "#e5c07b", coral = "#3f4a54", cyan = "#56b6c2", invalid = "#fff", ivory = "#3f4a54", stone = "#2d8cf0", malibu = "#2d8cf0", sage = "#3f4a54", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#f6f6f6", highlightBackground = "#ceedfa33", background = "var(--md-bk-color)", tooltipBackground = "var(--md-bk-color)", selection = "#bad5fa", cursor = "#3f4a54";
|
|
1876
1878
|
const oneLightTheme = view.EditorView.theme(
|
|
1877
1879
|
{
|
|
1878
1880
|
"&": {
|
|
@@ -1885,8 +1887,8 @@ const oneLightTheme = view.EditorView.theme(
|
|
|
1885
1887
|
".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor },
|
|
1886
1888
|
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection },
|
|
1887
1889
|
".cm-panels": { backgroundColor: darkBackground, color: ivory },
|
|
1888
|
-
".cm-panels.cm-panels-top": { borderBottom: "
|
|
1889
|
-
".cm-panels.cm-panels-bottom": { borderTop: "
|
|
1890
|
+
".cm-panels.cm-panels-top": { borderBottom: "1px solid var(--md-border-color)" },
|
|
1891
|
+
".cm-panels.cm-panels-bottom": { borderTop: "1px solid var(--md-border-color)" },
|
|
1890
1892
|
".cm-searchMatch": {
|
|
1891
1893
|
backgroundColor: "#72a1ff59",
|
|
1892
1894
|
outline: "1px solid #457dff"
|
|
@@ -2282,9 +2284,33 @@ class CodeMirrorUt {
|
|
|
2282
2284
|
]);
|
|
2283
2285
|
}
|
|
2284
2286
|
}
|
|
2285
|
-
const usePasteUpload = (props2) => {
|
|
2287
|
+
const usePasteUpload = (props2, codeMirrorUt) => {
|
|
2286
2288
|
const editorId = vue.inject("editorId");
|
|
2289
|
+
const imgInsert = (tv) => {
|
|
2290
|
+
if (tv instanceof Promise) {
|
|
2291
|
+
tv.then((targetValue) => {
|
|
2292
|
+
index.bus.emit(editorId, index.REPLACE, "universal", {
|
|
2293
|
+
generate() {
|
|
2294
|
+
return {
|
|
2295
|
+
targetValue
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
});
|
|
2299
|
+
}).catch((err) => {
|
|
2300
|
+
console.error(err);
|
|
2301
|
+
});
|
|
2302
|
+
} else {
|
|
2303
|
+
index.bus.emit(editorId, index.REPLACE, "universal", {
|
|
2304
|
+
generate() {
|
|
2305
|
+
return {
|
|
2306
|
+
targetValue: tv
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2287
2312
|
const pasteHandler = (e) => {
|
|
2313
|
+
var _a, _b, _c;
|
|
2288
2314
|
if (!e.clipboardData) {
|
|
2289
2315
|
return;
|
|
2290
2316
|
}
|
|
@@ -2300,6 +2326,24 @@ const usePasteUpload = (props2) => {
|
|
|
2300
2326
|
e.preventDefault();
|
|
2301
2327
|
return;
|
|
2302
2328
|
}
|
|
2329
|
+
const targetValue = e.clipboardData.getData("text/plain");
|
|
2330
|
+
const to = ((_a = codeMirrorUt.value) == null ? void 0 : _a.view.state.selection.main.to) || 0;
|
|
2331
|
+
const from = ((_b = codeMirrorUt.value) == null ? void 0 : _b.view.state.doc.lineAt(to).from) || 0;
|
|
2332
|
+
const lineStart = ((_c = codeMirrorUt.value) == null ? void 0 : _c.view.state.doc.sliceString(from, to)) || "";
|
|
2333
|
+
const templateStart = /!\[.*\]\(\s*$/.test(lineStart);
|
|
2334
|
+
const templateIn = /!\[.*\]\((.*)\s?.*\)/.test(targetValue);
|
|
2335
|
+
if (templateStart) {
|
|
2336
|
+
const tv = props2.transformImgUrl(targetValue);
|
|
2337
|
+
imgInsert(tv);
|
|
2338
|
+
e.preventDefault();
|
|
2339
|
+
return;
|
|
2340
|
+
} else if (templateIn) {
|
|
2341
|
+
const matchArr = targetValue.match(new RegExp(`(?<=!\\[.*\\]\\()\\S+(?=\\s?["']?.*["']?\\))`));
|
|
2342
|
+
const tv = matchArr ? props2.transformImgUrl(matchArr[0]) : targetValue;
|
|
2343
|
+
imgInsert(tv);
|
|
2344
|
+
e.preventDefault();
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2303
2347
|
if (props2.autoDetectCode && e.clipboardData.types.includes("vscode-editor-data")) {
|
|
2304
2348
|
const vscCoodInfo = JSON.parse(e.clipboardData.getData("vscode-editor-data"));
|
|
2305
2349
|
index.bus.emit(editorId, index.REPLACE, "code", {
|
|
@@ -2309,7 +2353,6 @@ const usePasteUpload = (props2) => {
|
|
|
2309
2353
|
e.preventDefault();
|
|
2310
2354
|
return;
|
|
2311
2355
|
}
|
|
2312
|
-
const targetValue = e.clipboardData.getData("text/plain");
|
|
2313
2356
|
if (props2.maxlength && targetValue.length + props2.modelValue.length > props2.maxlength) {
|
|
2314
2357
|
index.bus.emit(editorId, index.ERROR_CATCHER, {
|
|
2315
2358
|
name: "overlength",
|
|
@@ -2504,7 +2547,8 @@ const createCommands = (id, contentProps) => {
|
|
|
2504
2547
|
CtrlC,
|
|
2505
2548
|
CtrlL,
|
|
2506
2549
|
CtrlF,
|
|
2507
|
-
CtrlT
|
|
2550
|
+
CtrlT,
|
|
2551
|
+
...search.searchKeymap
|
|
2508
2552
|
];
|
|
2509
2553
|
};
|
|
2510
2554
|
const useCodeMirror = (props2) => {
|
|
@@ -2516,7 +2560,7 @@ const useCodeMirror = (props2) => {
|
|
|
2516
2560
|
const languageComp = new state.Compartment(), themeComp = new state.Compartment(), autocompletionComp = new state.Compartment(), historyComp = new state.Compartment(), eventComp = new state.Compartment();
|
|
2517
2561
|
const mdEditorCommands = createCommands(editorId, props2);
|
|
2518
2562
|
const spelling = vue.ref(false);
|
|
2519
|
-
const pasteHandler = usePasteUpload(props2);
|
|
2563
|
+
const pasteHandler = usePasteUpload(props2, codeMirrorUt);
|
|
2520
2564
|
const domEventHandlers = {
|
|
2521
2565
|
paste: pasteHandler,
|
|
2522
2566
|
blur: props2.onBlur,
|
|
@@ -2600,9 +2644,31 @@ const useCodeMirror = (props2) => {
|
|
|
2600
2644
|
index.bus.on(editorId, {
|
|
2601
2645
|
name: index.REPLACE,
|
|
2602
2646
|
callback(direct, params = {}) {
|
|
2603
|
-
var _a;
|
|
2604
|
-
|
|
2605
|
-
|
|
2647
|
+
var _a, _b;
|
|
2648
|
+
if (direct === "image" && params.transform) {
|
|
2649
|
+
const tv = props2.transformImgUrl(params.url);
|
|
2650
|
+
if (tv instanceof Promise) {
|
|
2651
|
+
tv.then((url) => {
|
|
2652
|
+
var _a2;
|
|
2653
|
+
const { text, options } = directive2flag(direct, codeMirrorUt.value, {
|
|
2654
|
+
...params,
|
|
2655
|
+
url
|
|
2656
|
+
});
|
|
2657
|
+
(_a2 = codeMirrorUt.value) == null ? void 0 : _a2.replaceSelectedText(text, options, editorId);
|
|
2658
|
+
}).catch((err) => {
|
|
2659
|
+
console.error(err);
|
|
2660
|
+
});
|
|
2661
|
+
} else {
|
|
2662
|
+
const { text, options } = directive2flag(direct, codeMirrorUt.value, {
|
|
2663
|
+
...params,
|
|
2664
|
+
url: tv
|
|
2665
|
+
});
|
|
2666
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
|
|
2667
|
+
}
|
|
2668
|
+
} else {
|
|
2669
|
+
const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
|
|
2670
|
+
(_b = codeMirrorUt.value) == null ? void 0 : _b.replaceSelectedText(text, options, editorId);
|
|
2671
|
+
}
|
|
2606
2672
|
}
|
|
2607
2673
|
});
|
|
2608
2674
|
index.bus.on(editorId, {
|
|
@@ -3124,7 +3190,8 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
|
|
|
3124
3190
|
}
|
|
3125
3191
|
ctx.emit("onInputBoxWitdhChange", width);
|
|
3126
3192
|
},
|
|
3127
|
-
"sanitizeMermaid": props2.sanitizeMermaid
|
|
3193
|
+
"sanitizeMermaid": props2.sanitizeMermaid,
|
|
3194
|
+
"transformImgUrl": props2.transformImgUrl
|
|
3128
3195
|
}, null), ((_a = props2.footers) == null ? void 0 : _a.length) > 0 && vue.createVNode(Footer, {
|
|
3129
3196
|
"modelValue": props2.modelValue,
|
|
3130
3197
|
"footers": props2.footers,
|
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -933,6 +933,10 @@ const contentProps = {
|
|
|
933
933
|
},
|
|
934
934
|
onInputBoxWitdhChange: {
|
|
935
935
|
type: Function
|
|
936
|
+
},
|
|
937
|
+
transformImgUrl: {
|
|
938
|
+
type: Function,
|
|
939
|
+
default: (t) => t
|
|
936
940
|
}
|
|
937
941
|
};
|
|
938
942
|
const ContentPreview = /* @__PURE__ */ vue.defineComponent({
|
|
@@ -1794,6 +1798,16 @@ const editorProps = {
|
|
|
1794
1798
|
*/
|
|
1795
1799
|
onInputBoxWitdhChange: {
|
|
1796
1800
|
type: Function
|
|
1801
|
+
},
|
|
1802
|
+
/**
|
|
1803
|
+
* 替换粘贴的图片链接
|
|
1804
|
+
*
|
|
1805
|
+
* @param t 图片链接
|
|
1806
|
+
* @returns
|
|
1807
|
+
*/
|
|
1808
|
+
transformImgUrl: {
|
|
1809
|
+
type: Function,
|
|
1810
|
+
default: (t) => t
|
|
1797
1811
|
}
|
|
1798
1812
|
};
|
|
1799
1813
|
const mdPreviewEmits = ["onHtmlChanged", "onGetCatalog"];
|
package/lib/es/MdEditor.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { deleteLine, defaultKeymap, historyKeymap, indentWithTab, history, undo,
|
|
|
20
20
|
import { HighlightStyle, syntaxHighlighting, indentUnit } from "@codemirror/language";
|
|
21
21
|
import { tags } from "@lezer/highlight";
|
|
22
22
|
import { autocompletion } from "@codemirror/autocomplete";
|
|
23
|
+
import { searchKeymap } from "@codemirror/search";
|
|
23
24
|
import { c as contentProps, C as ContentPreview, e as editorProps, a as editorEmits, u as useOnSave, b as useProvide, d as useExpansion, f as useErrorCatcher, g as useConfig, h as useCatalog, i as useExpose, M as MdPreview } from "./chunks/index.mjs";
|
|
24
25
|
import MdCatalog from "./MdCatalog.mjs";
|
|
25
26
|
import { g as getSlot } from "./chunks/vue-tsx.mjs";
|
|
@@ -1187,7 +1188,8 @@ const ToolBar = /* @__PURE__ */ defineComponent({
|
|
|
1187
1188
|
if (data) {
|
|
1188
1189
|
emitHandler(modalData.type, {
|
|
1189
1190
|
desc: data.desc,
|
|
1190
|
-
url: data.url
|
|
1191
|
+
url: data.url,
|
|
1192
|
+
transform: modalData.type === "image"
|
|
1191
1193
|
});
|
|
1192
1194
|
}
|
|
1193
1195
|
modalData.linkVisible = false;
|
|
@@ -1778,8 +1780,8 @@ const oneDarkTheme = EditorView.theme(
|
|
|
1778
1780
|
".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor$1 },
|
|
1779
1781
|
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection$1 },
|
|
1780
1782
|
".cm-panels": { backgroundColor: darkBackground$1, color: ivory$1 },
|
|
1781
|
-
".cm-panels.cm-panels-top": { borderBottom: "
|
|
1782
|
-
".cm-panels.cm-panels-bottom": { borderTop: "
|
|
1783
|
+
".cm-panels.cm-panels-top": { borderBottom: "1px solid var(--md-border-color)" },
|
|
1784
|
+
".cm-panels.cm-panels-bottom": { borderTop: "1px solid var(--md-border-color)" },
|
|
1783
1785
|
".cm-searchMatch": {
|
|
1784
1786
|
backgroundColor: "#72a1ff59",
|
|
1785
1787
|
outline: "1px solid #457dff"
|
|
@@ -1871,7 +1873,7 @@ const oneDark = [
|
|
|
1871
1873
|
oneDarkTheme,
|
|
1872
1874
|
syntaxHighlighting(oneDarkHighlightStyle)
|
|
1873
1875
|
];
|
|
1874
|
-
const chalky = "#e5c07b", coral = "#3f4a54", cyan = "#56b6c2", invalid = "#fff", ivory = "#3f4a54", stone = "#2d8cf0", malibu = "#2d8cf0", sage = "#3f4a54", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#
|
|
1876
|
+
const chalky = "#e5c07b", coral = "#3f4a54", cyan = "#56b6c2", invalid = "#fff", ivory = "#3f4a54", stone = "#2d8cf0", malibu = "#2d8cf0", sage = "#3f4a54", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#f6f6f6", highlightBackground = "#ceedfa33", background = "var(--md-bk-color)", tooltipBackground = "var(--md-bk-color)", selection = "#bad5fa", cursor = "#3f4a54";
|
|
1875
1877
|
const oneLightTheme = EditorView.theme(
|
|
1876
1878
|
{
|
|
1877
1879
|
"&": {
|
|
@@ -1884,8 +1886,8 @@ const oneLightTheme = EditorView.theme(
|
|
|
1884
1886
|
".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor },
|
|
1885
1887
|
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection },
|
|
1886
1888
|
".cm-panels": { backgroundColor: darkBackground, color: ivory },
|
|
1887
|
-
".cm-panels.cm-panels-top": { borderBottom: "
|
|
1888
|
-
".cm-panels.cm-panels-bottom": { borderTop: "
|
|
1889
|
+
".cm-panels.cm-panels-top": { borderBottom: "1px solid var(--md-border-color)" },
|
|
1890
|
+
".cm-panels.cm-panels-bottom": { borderTop: "1px solid var(--md-border-color)" },
|
|
1889
1891
|
".cm-searchMatch": {
|
|
1890
1892
|
backgroundColor: "#72a1ff59",
|
|
1891
1893
|
outline: "1px solid #457dff"
|
|
@@ -2281,9 +2283,33 @@ class CodeMirrorUt {
|
|
|
2281
2283
|
]);
|
|
2282
2284
|
}
|
|
2283
2285
|
}
|
|
2284
|
-
const usePasteUpload = (props2) => {
|
|
2286
|
+
const usePasteUpload = (props2, codeMirrorUt) => {
|
|
2285
2287
|
const editorId = inject("editorId");
|
|
2288
|
+
const imgInsert = (tv) => {
|
|
2289
|
+
if (tv instanceof Promise) {
|
|
2290
|
+
tv.then((targetValue) => {
|
|
2291
|
+
bus.emit(editorId, REPLACE, "universal", {
|
|
2292
|
+
generate() {
|
|
2293
|
+
return {
|
|
2294
|
+
targetValue
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
}).catch((err) => {
|
|
2299
|
+
console.error(err);
|
|
2300
|
+
});
|
|
2301
|
+
} else {
|
|
2302
|
+
bus.emit(editorId, REPLACE, "universal", {
|
|
2303
|
+
generate() {
|
|
2304
|
+
return {
|
|
2305
|
+
targetValue: tv
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
};
|
|
2286
2311
|
const pasteHandler = (e) => {
|
|
2312
|
+
var _a, _b, _c;
|
|
2287
2313
|
if (!e.clipboardData) {
|
|
2288
2314
|
return;
|
|
2289
2315
|
}
|
|
@@ -2299,6 +2325,24 @@ const usePasteUpload = (props2) => {
|
|
|
2299
2325
|
e.preventDefault();
|
|
2300
2326
|
return;
|
|
2301
2327
|
}
|
|
2328
|
+
const targetValue = e.clipboardData.getData("text/plain");
|
|
2329
|
+
const to = ((_a = codeMirrorUt.value) == null ? void 0 : _a.view.state.selection.main.to) || 0;
|
|
2330
|
+
const from = ((_b = codeMirrorUt.value) == null ? void 0 : _b.view.state.doc.lineAt(to).from) || 0;
|
|
2331
|
+
const lineStart = ((_c = codeMirrorUt.value) == null ? void 0 : _c.view.state.doc.sliceString(from, to)) || "";
|
|
2332
|
+
const templateStart = /!\[.*\]\(\s*$/.test(lineStart);
|
|
2333
|
+
const templateIn = /!\[.*\]\((.*)\s?.*\)/.test(targetValue);
|
|
2334
|
+
if (templateStart) {
|
|
2335
|
+
const tv = props2.transformImgUrl(targetValue);
|
|
2336
|
+
imgInsert(tv);
|
|
2337
|
+
e.preventDefault();
|
|
2338
|
+
return;
|
|
2339
|
+
} else if (templateIn) {
|
|
2340
|
+
const matchArr = targetValue.match(new RegExp(`(?<=!\\[.*\\]\\()\\S+(?=\\s?["']?.*["']?\\))`));
|
|
2341
|
+
const tv = matchArr ? props2.transformImgUrl(matchArr[0]) : targetValue;
|
|
2342
|
+
imgInsert(tv);
|
|
2343
|
+
e.preventDefault();
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2302
2346
|
if (props2.autoDetectCode && e.clipboardData.types.includes("vscode-editor-data")) {
|
|
2303
2347
|
const vscCoodInfo = JSON.parse(e.clipboardData.getData("vscode-editor-data"));
|
|
2304
2348
|
bus.emit(editorId, REPLACE, "code", {
|
|
@@ -2308,7 +2352,6 @@ const usePasteUpload = (props2) => {
|
|
|
2308
2352
|
e.preventDefault();
|
|
2309
2353
|
return;
|
|
2310
2354
|
}
|
|
2311
|
-
const targetValue = e.clipboardData.getData("text/plain");
|
|
2312
2355
|
if (props2.maxlength && targetValue.length + props2.modelValue.length > props2.maxlength) {
|
|
2313
2356
|
bus.emit(editorId, ERROR_CATCHER, {
|
|
2314
2357
|
name: "overlength",
|
|
@@ -2503,7 +2546,8 @@ const createCommands = (id, contentProps2) => {
|
|
|
2503
2546
|
CtrlC,
|
|
2504
2547
|
CtrlL,
|
|
2505
2548
|
CtrlF,
|
|
2506
|
-
CtrlT
|
|
2549
|
+
CtrlT,
|
|
2550
|
+
...searchKeymap
|
|
2507
2551
|
];
|
|
2508
2552
|
};
|
|
2509
2553
|
const useCodeMirror = (props2) => {
|
|
@@ -2515,7 +2559,7 @@ const useCodeMirror = (props2) => {
|
|
|
2515
2559
|
const languageComp = new Compartment(), themeComp = new Compartment(), autocompletionComp = new Compartment(), historyComp = new Compartment(), eventComp = new Compartment();
|
|
2516
2560
|
const mdEditorCommands = createCommands(editorId, props2);
|
|
2517
2561
|
const spelling = ref(false);
|
|
2518
|
-
const pasteHandler = usePasteUpload(props2);
|
|
2562
|
+
const pasteHandler = usePasteUpload(props2, codeMirrorUt);
|
|
2519
2563
|
const domEventHandlers = {
|
|
2520
2564
|
paste: pasteHandler,
|
|
2521
2565
|
blur: props2.onBlur,
|
|
@@ -2599,9 +2643,31 @@ const useCodeMirror = (props2) => {
|
|
|
2599
2643
|
bus.on(editorId, {
|
|
2600
2644
|
name: REPLACE,
|
|
2601
2645
|
callback(direct, params = {}) {
|
|
2602
|
-
var _a;
|
|
2603
|
-
|
|
2604
|
-
|
|
2646
|
+
var _a, _b;
|
|
2647
|
+
if (direct === "image" && params.transform) {
|
|
2648
|
+
const tv = props2.transformImgUrl(params.url);
|
|
2649
|
+
if (tv instanceof Promise) {
|
|
2650
|
+
tv.then((url) => {
|
|
2651
|
+
var _a2;
|
|
2652
|
+
const { text, options } = directive2flag(direct, codeMirrorUt.value, {
|
|
2653
|
+
...params,
|
|
2654
|
+
url
|
|
2655
|
+
});
|
|
2656
|
+
(_a2 = codeMirrorUt.value) == null ? void 0 : _a2.replaceSelectedText(text, options, editorId);
|
|
2657
|
+
}).catch((err) => {
|
|
2658
|
+
console.error(err);
|
|
2659
|
+
});
|
|
2660
|
+
} else {
|
|
2661
|
+
const { text, options } = directive2flag(direct, codeMirrorUt.value, {
|
|
2662
|
+
...params,
|
|
2663
|
+
url: tv
|
|
2664
|
+
});
|
|
2665
|
+
(_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
|
|
2666
|
+
}
|
|
2667
|
+
} else {
|
|
2668
|
+
const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
|
|
2669
|
+
(_b = codeMirrorUt.value) == null ? void 0 : _b.replaceSelectedText(text, options, editorId);
|
|
2670
|
+
}
|
|
2605
2671
|
}
|
|
2606
2672
|
});
|
|
2607
2673
|
bus.on(editorId, {
|
|
@@ -3123,7 +3189,8 @@ const Editor = /* @__PURE__ */ defineComponent({
|
|
|
3123
3189
|
}
|
|
3124
3190
|
ctx.emit("onInputBoxWitdhChange", width);
|
|
3125
3191
|
},
|
|
3126
|
-
"sanitizeMermaid": props2.sanitizeMermaid
|
|
3192
|
+
"sanitizeMermaid": props2.sanitizeMermaid,
|
|
3193
|
+
"transformImgUrl": props2.transformImgUrl
|
|
3127
3194
|
}, null), ((_a = props2.footers) == null ? void 0 : _a.length) > 0 && createVNode(Footer, {
|
|
3128
3195
|
"modelValue": props2.modelValue,
|
|
3129
3196
|
"footers": props2.footers,
|
package/lib/es/chunks/index.mjs
CHANGED
|
@@ -932,6 +932,10 @@ const contentProps = {
|
|
|
932
932
|
},
|
|
933
933
|
onInputBoxWitdhChange: {
|
|
934
934
|
type: Function
|
|
935
|
+
},
|
|
936
|
+
transformImgUrl: {
|
|
937
|
+
type: Function,
|
|
938
|
+
default: (t) => t
|
|
935
939
|
}
|
|
936
940
|
};
|
|
937
941
|
const ContentPreview = /* @__PURE__ */ defineComponent({
|
|
@@ -1793,6 +1797,16 @@ const editorProps = {
|
|
|
1793
1797
|
*/
|
|
1794
1798
|
onInputBoxWitdhChange: {
|
|
1795
1799
|
type: Function
|
|
1800
|
+
},
|
|
1801
|
+
/**
|
|
1802
|
+
* 替换粘贴的图片链接
|
|
1803
|
+
*
|
|
1804
|
+
* @param t 图片链接
|
|
1805
|
+
* @returns
|
|
1806
|
+
*/
|
|
1807
|
+
transformImgUrl: {
|
|
1808
|
+
type: Function,
|
|
1809
|
+
default: (t) => t
|
|
1796
1810
|
}
|
|
1797
1811
|
};
|
|
1798
1812
|
const mdPreviewEmits = ["onHtmlChanged", "onGetCatalog"];
|
package/lib/style.css
CHANGED
|
@@ -381,6 +381,64 @@
|
|
|
381
381
|
}.ͼ1 .cm-scroller {
|
|
382
382
|
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
|
|
383
383
|
line-height: 20px;
|
|
384
|
+
}.cm-search .cm-textfield {
|
|
385
|
+
border-radius: 4px;
|
|
386
|
+
padding: 4px 11px;
|
|
387
|
+
color: var(--md-color);
|
|
388
|
+
font-size: 10px;
|
|
389
|
+
background-image: none;
|
|
390
|
+
border: 1px solid var(--md-border-color);
|
|
391
|
+
transition: all 0.2s;
|
|
392
|
+
}.cm-search .cm-textfield:focus,
|
|
393
|
+
.cm-search .cm-textfield:hover {
|
|
394
|
+
border-color: var(--md-border-hover-color);
|
|
395
|
+
outline: 0;
|
|
396
|
+
}.cm-search .cm-textfield:focus {
|
|
397
|
+
border-color: var(--md-border-active-color);
|
|
398
|
+
}.cm-search .cm-button {
|
|
399
|
+
font-weight: 400;
|
|
400
|
+
text-align: center;
|
|
401
|
+
vertical-align: middle;
|
|
402
|
+
cursor: pointer;
|
|
403
|
+
border: 1px solid var(--md-border-color);
|
|
404
|
+
white-space: nowrap;
|
|
405
|
+
user-select: none;
|
|
406
|
+
height: 20px;
|
|
407
|
+
padding: 0 15px;
|
|
408
|
+
font-size: 10px;
|
|
409
|
+
border-radius: 4px;
|
|
410
|
+
transition: all 0.2s linear;
|
|
411
|
+
color: var(--md-color);
|
|
412
|
+
background-color: inherit;
|
|
413
|
+
background-image: none;
|
|
414
|
+
border-color: var(--md-border-color);
|
|
415
|
+
}.cm-search .cm-button:first-of-type {
|
|
416
|
+
margin-left: 0;
|
|
417
|
+
}.cm-search .cm-button:hover {
|
|
418
|
+
color: var(--md-hover-color);
|
|
419
|
+
background-color: inherit;
|
|
420
|
+
border-color: var(--md-border-hover-color);
|
|
421
|
+
}.cm-search input[type='checkbox'] {
|
|
422
|
+
vertical-align: sub;
|
|
423
|
+
}.cm-search input[type='checkbox']::after {
|
|
424
|
+
display: block;
|
|
425
|
+
content: '';
|
|
426
|
+
font-weight: bold;
|
|
427
|
+
cursor: pointer;
|
|
428
|
+
width: 12px;
|
|
429
|
+
height: 12px;
|
|
430
|
+
border: 1px solid var(--md-border-color);
|
|
431
|
+
background-color: var(--md-bk-color-outstand);
|
|
432
|
+
border-radius: 2px;
|
|
433
|
+
line-height: 1;
|
|
434
|
+
text-align: center;
|
|
435
|
+
}.cm-search input[type='checkbox']:checked::after {
|
|
436
|
+
content: '✓';
|
|
437
|
+
color: var(--md-color);
|
|
438
|
+
}.cm-search button[name='close'] {
|
|
439
|
+
color: inherit;
|
|
440
|
+
cursor: pointer;
|
|
441
|
+
right: 6px;
|
|
384
442
|
}.md-editor-catalog-editor {
|
|
385
443
|
--md-color: #3f4a54;
|
|
386
444
|
--md-hover-color: #000;
|
|
@@ -105,6 +105,10 @@ declare const Editor: import('vue').DefineComponent<{
|
|
|
105
105
|
onInputBoxWitdhChange: {
|
|
106
106
|
type: import("vue").PropType<(width: string) => void>;
|
|
107
107
|
};
|
|
108
|
+
transformImgUrl: {
|
|
109
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
110
|
+
default: (t: string) => string;
|
|
111
|
+
};
|
|
108
112
|
modelValue: {
|
|
109
113
|
type: import("vue").PropType<string>;
|
|
110
114
|
default: string;
|
|
@@ -301,6 +305,10 @@ declare const Editor: import('vue').DefineComponent<{
|
|
|
301
305
|
onInputBoxWitdhChange: {
|
|
302
306
|
type: import("vue").PropType<(width: string) => void>;
|
|
303
307
|
};
|
|
308
|
+
transformImgUrl: {
|
|
309
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
310
|
+
default: (t: string) => string;
|
|
311
|
+
};
|
|
304
312
|
modelValue: {
|
|
305
313
|
type: import("vue").PropType<string>;
|
|
306
314
|
default: string;
|
|
@@ -420,6 +428,7 @@ declare const Editor: import('vue').DefineComponent<{
|
|
|
420
428
|
scrollAuto: boolean;
|
|
421
429
|
showToolbarName: boolean;
|
|
422
430
|
inputBoxWitdh: string;
|
|
431
|
+
transformImgUrl: (t: string) => string | Promise<string>;
|
|
423
432
|
modelValue: string;
|
|
424
433
|
theme: import("~/type").Themes;
|
|
425
434
|
editorId: string;
|
|
@@ -21,6 +21,7 @@ declare const _default: {
|
|
|
21
21
|
scrollAuto: boolean;
|
|
22
22
|
showToolbarName: boolean;
|
|
23
23
|
inputBoxWitdh: string;
|
|
24
|
+
transformImgUrl: (t: string) => string | Promise<string>;
|
|
24
25
|
modelValue: string;
|
|
25
26
|
theme: import('./type').Themes;
|
|
26
27
|
editorId: string;
|
|
@@ -145,6 +146,10 @@ declare const _default: {
|
|
|
145
146
|
onInputBoxWitdhChange: {
|
|
146
147
|
type: import("vue").PropType<(width: string) => void>;
|
|
147
148
|
};
|
|
149
|
+
transformImgUrl: {
|
|
150
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
151
|
+
default: (t: string) => string;
|
|
152
|
+
};
|
|
148
153
|
modelValue: {
|
|
149
154
|
type: import("vue").PropType<string>;
|
|
150
155
|
default: string;
|
|
@@ -247,7 +252,7 @@ declare const _default: {
|
|
|
247
252
|
onOnInput?: ((...args: any[]) => any) | undefined;
|
|
248
253
|
onOnDrop?: ((...args: any[]) => any) | undefined;
|
|
249
254
|
onOnInputBoxWitdhChange?: ((...args: any[]) => any) | undefined;
|
|
250
|
-
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, "preview" | "pageFullscreen" | "htmlPreview" | "class" | "style" | "language" | "toolbars" | "toolbarsExclude" | "noPrettier" | "tabWidth" | "tableShape" | "placeholder" | "footers" | "scrollAuto" | "showToolbarName" | "inputBoxWitdh" | "modelValue" | "theme" | "editorId" | "showCodeRowNumber" | "previewTheme" | "mdHeadingId" | "sanitize" | "noMermaid" | "noKatex" | "codeTheme" | "formatCopiedText" | "codeStyleReverse" | "codeStyleReverseList" | "noHighlight" | "noImgZoomIn" | "customIcon" | "sanitizeMermaid">;
|
|
255
|
+
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, "preview" | "pageFullscreen" | "htmlPreview" | "class" | "style" | "language" | "toolbars" | "toolbarsExclude" | "noPrettier" | "tabWidth" | "tableShape" | "placeholder" | "footers" | "scrollAuto" | "showToolbarName" | "inputBoxWitdh" | "transformImgUrl" | "modelValue" | "theme" | "editorId" | "showCodeRowNumber" | "previewTheme" | "mdHeadingId" | "sanitize" | "noMermaid" | "noKatex" | "codeTheme" | "formatCopiedText" | "codeStyleReverse" | "codeStyleReverseList" | "noHighlight" | "noImgZoomIn" | "customIcon" | "sanitizeMermaid">;
|
|
251
256
|
$attrs: {
|
|
252
257
|
[x: string]: unknown;
|
|
253
258
|
};
|
|
@@ -368,6 +373,10 @@ declare const _default: {
|
|
|
368
373
|
onInputBoxWitdhChange: {
|
|
369
374
|
type: import("vue").PropType<(width: string) => void>;
|
|
370
375
|
};
|
|
376
|
+
transformImgUrl: {
|
|
377
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
378
|
+
default: (t: string) => string;
|
|
379
|
+
};
|
|
371
380
|
modelValue: {
|
|
372
381
|
type: import("vue").PropType<string>;
|
|
373
382
|
default: string;
|
|
@@ -487,6 +496,7 @@ declare const _default: {
|
|
|
487
496
|
scrollAuto: boolean;
|
|
488
497
|
showToolbarName: boolean;
|
|
489
498
|
inputBoxWitdh: string;
|
|
499
|
+
transformImgUrl: (t: string) => string | Promise<string>;
|
|
490
500
|
modelValue: string;
|
|
491
501
|
theme: import("./type").Themes;
|
|
492
502
|
editorId: string;
|
|
@@ -631,6 +641,10 @@ declare const _default: {
|
|
|
631
641
|
onInputBoxWitdhChange: {
|
|
632
642
|
type: import("vue").PropType<(width: string) => void>;
|
|
633
643
|
};
|
|
644
|
+
transformImgUrl: {
|
|
645
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
646
|
+
default: (t: string) => string;
|
|
647
|
+
};
|
|
634
648
|
modelValue: {
|
|
635
649
|
type: import("vue").PropType<string>;
|
|
636
650
|
default: string;
|
|
@@ -844,6 +858,10 @@ declare const _default: {
|
|
|
844
858
|
onInputBoxWitdhChange: {
|
|
845
859
|
type: import("vue").PropType<(width: string) => void>;
|
|
846
860
|
};
|
|
861
|
+
transformImgUrl: {
|
|
862
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
863
|
+
default: (t: string) => string;
|
|
864
|
+
};
|
|
847
865
|
modelValue: {
|
|
848
866
|
type: import("vue").PropType<string>;
|
|
849
867
|
default: string;
|
|
@@ -963,6 +981,7 @@ declare const _default: {
|
|
|
963
981
|
scrollAuto: boolean;
|
|
964
982
|
showToolbarName: boolean;
|
|
965
983
|
inputBoxWitdh: string;
|
|
984
|
+
transformImgUrl: (t: string) => string | Promise<string>;
|
|
966
985
|
modelValue: string;
|
|
967
986
|
theme: import("./type").Themes;
|
|
968
987
|
editorId: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { default as CodeMirrorUt } from '../codemirror';
|
|
1
2
|
import { ContentProps } from '../props';
|
|
3
|
+
import { ShallowRef } from 'vue';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* 处理粘贴板
|
|
5
7
|
*/
|
|
6
|
-
declare const usePasteUpload: (props: ContentProps) => (e: ClipboardEvent) => void;
|
|
8
|
+
declare const usePasteUpload: (props: ContentProps, codeMirrorUt: ShallowRef<CodeMirrorUt | undefined>) => (e: ClipboardEvent) => void;
|
|
7
9
|
export default usePasteUpload;
|
|
@@ -63,6 +63,10 @@ declare const _default: import('vue').DefineComponent<{
|
|
|
63
63
|
onInputBoxWitdhChange: {
|
|
64
64
|
type: import("vue").PropType<(width: string) => void>;
|
|
65
65
|
};
|
|
66
|
+
transformImgUrl: {
|
|
67
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
68
|
+
default: (t: string) => string;
|
|
69
|
+
};
|
|
66
70
|
modelValue: {
|
|
67
71
|
type: import("vue").PropType<string>;
|
|
68
72
|
default: string;
|
|
@@ -180,6 +184,10 @@ declare const _default: import('vue').DefineComponent<{
|
|
|
180
184
|
onInputBoxWitdhChange: {
|
|
181
185
|
type: import("vue").PropType<(width: string) => void>;
|
|
182
186
|
};
|
|
187
|
+
transformImgUrl: {
|
|
188
|
+
type: import("vue").PropType<(t: string) => string | Promise<string>>;
|
|
189
|
+
default: (t: string) => string;
|
|
190
|
+
};
|
|
183
191
|
modelValue: {
|
|
184
192
|
type: import("vue").PropType<string>;
|
|
185
193
|
default: string;
|
|
@@ -241,6 +249,7 @@ declare const _default: import('vue').DefineComponent<{
|
|
|
241
249
|
onFocus: (event: FocusEvent) => void;
|
|
242
250
|
onDrop: (event: DragEvent) => void;
|
|
243
251
|
placeholder: string;
|
|
252
|
+
transformImgUrl: (t: string) => string | Promise<string>;
|
|
244
253
|
modelValue: string;
|
|
245
254
|
theme: import("~/type").Themes;
|
|
246
255
|
mdHeadingId: import("~/type").MdHeadingId;
|
|
@@ -128,6 +128,10 @@ export declare const contentProps: {
|
|
|
128
128
|
onInputBoxWitdhChange: {
|
|
129
129
|
type: PropType<(width: string) => void>;
|
|
130
130
|
};
|
|
131
|
+
transformImgUrl: {
|
|
132
|
+
type: PropType<(t: string) => string | Promise<string>>;
|
|
133
|
+
default: (t: string) => string;
|
|
134
|
+
};
|
|
131
135
|
modelValue: {
|
|
132
136
|
type: PropType<string>;
|
|
133
137
|
default: string;
|
|
@@ -439,6 +439,16 @@ export declare const editorProps: {
|
|
|
439
439
|
onInputBoxWitdhChange: {
|
|
440
440
|
type: PropType<(width: string) => void>;
|
|
441
441
|
};
|
|
442
|
+
/**
|
|
443
|
+
* 替换粘贴的图片链接
|
|
444
|
+
*
|
|
445
|
+
* @param t 图片链接
|
|
446
|
+
* @returns
|
|
447
|
+
*/
|
|
448
|
+
transformImgUrl: {
|
|
449
|
+
type: PropType<(t: string) => string | Promise<string>>;
|
|
450
|
+
default: (t: string) => string;
|
|
451
|
+
};
|
|
442
452
|
/**
|
|
443
453
|
* markdown content.
|
|
444
454
|
*
|