md-editor-v3 4.19.2-0 → 4.20.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 +18 -46
- package/lib/cjs/MdEditor.cjs +36 -22
- package/lib/cjs/chunks/dom.cjs +12 -18
- package/lib/cjs/chunks/event-name.cjs +1 -4
- package/lib/cjs/chunks/index.cjs +103 -128
- package/lib/cjs/chunks/index3.cjs +1 -2
- package/lib/es/MdEditor.mjs +37 -23
- package/lib/es/chunks/dom.mjs +12 -18
- package/lib/es/chunks/event-name.mjs +1 -4
- package/lib/es/chunks/index.mjs +103 -128
- package/lib/es/chunks/index3.mjs +1 -2
- package/lib/preview.css +1 -1
- package/lib/style.css +1 -1
- package/lib/types/MdEditor/layouts/Content/composition/useResize.d.ts +1 -0
- package/lib/types/MdEditor/layouts/Content/type.d.ts +2 -0
- package/lib/types/MdEditor/type.d.ts +7 -1
- package/lib/umd/index.js +54 -53
- package/package.json +4 -2
package/lib/es/MdEditor.mjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
4
|
import { defineComponent, createVNode, inject, ref, onMounted, reactive, computed, watch, toRef, nextTick, Fragment, cloneVNode, shallowRef, onBeforeUnmount } from "vue";
|
|
8
5
|
import { p as prefix, f as configOption, b as allToolbar, M as MinInputBoxWidth, d as allFooter } from "./chunks/config.mjs";
|
|
9
6
|
import { draggingScroll, linkTo, throttle } from "@vavt/util";
|
|
@@ -18,7 +15,7 @@ import { EditorView, placeholder, keymap, drawSelection } from "@codemirror/view
|
|
|
18
15
|
import { languages } from "@codemirror/language-data";
|
|
19
16
|
import { markdown } from "@codemirror/lang-markdown";
|
|
20
17
|
import { EditorSelection, EditorState, Compartment, StateEffect } from "@codemirror/state";
|
|
21
|
-
import { deleteLine,
|
|
18
|
+
import { deleteLine, history, undo, redo, defaultKeymap, historyKeymap, indentWithTab } from "@codemirror/commands";
|
|
22
19
|
import { HighlightStyle, syntaxHighlighting, indentUnit } from "@codemirror/language";
|
|
23
20
|
import { tags } from "@lezer/highlight";
|
|
24
21
|
import { autocompletion } from "@codemirror/autocomplete";
|
|
@@ -221,7 +218,6 @@ const TableShape = /* @__PURE__ */ defineComponent({
|
|
|
221
218
|
}, null)]))]))]);
|
|
222
219
|
}
|
|
223
220
|
});
|
|
224
|
-
const TableShape$1 = TableShape;
|
|
225
221
|
const props$5 = {
|
|
226
222
|
type: {
|
|
227
223
|
type: String,
|
|
@@ -873,7 +869,7 @@ const ToolBar = /* @__PURE__ */ defineComponent({
|
|
|
873
869
|
visible.table = v;
|
|
874
870
|
},
|
|
875
871
|
"key": "bar-table",
|
|
876
|
-
"overlay": createVNode(TableShape
|
|
872
|
+
"overlay": createVNode(TableShape, {
|
|
877
873
|
"tableShape": props2.tableShape,
|
|
878
874
|
"onSelected": (selectedShape) => {
|
|
879
875
|
emitHandler("table", {
|
|
@@ -1361,15 +1357,15 @@ const directive2flag = async (direct, codeMirrorUt, params) => {
|
|
|
1361
1357
|
break;
|
|
1362
1358
|
}
|
|
1363
1359
|
case "sub": {
|
|
1364
|
-
targetValue =
|
|
1365
|
-
deviationStart =
|
|
1366
|
-
deviationEnd = -
|
|
1360
|
+
targetValue = `~${selectedText}~`;
|
|
1361
|
+
deviationStart = 1;
|
|
1362
|
+
deviationEnd = -1;
|
|
1367
1363
|
break;
|
|
1368
1364
|
}
|
|
1369
1365
|
case "sup": {
|
|
1370
|
-
targetValue =
|
|
1371
|
-
deviationStart =
|
|
1372
|
-
deviationEnd = -
|
|
1366
|
+
targetValue = `^${selectedText}^`;
|
|
1367
|
+
deviationStart = 1;
|
|
1368
|
+
deviationEnd = -1;
|
|
1373
1369
|
break;
|
|
1374
1370
|
}
|
|
1375
1371
|
case "codeRow": {
|
|
@@ -2363,9 +2359,15 @@ const useCodeMirror = (props2) => {
|
|
|
2363
2359
|
const theme = inject("theme");
|
|
2364
2360
|
const inputWrapperRef = ref();
|
|
2365
2361
|
const codeMirrorUt = shallowRef();
|
|
2362
|
+
const spelling = ref(false);
|
|
2366
2363
|
const languageComp = new Compartment(), themeComp = new Compartment(), autocompletionComp = new Compartment(), historyComp = new Compartment(), eventComp = new Compartment();
|
|
2367
2364
|
const mdEditorCommands = createCommands(editorId, props2);
|
|
2368
|
-
const
|
|
2365
|
+
const getDefaultKeymaps = () => [
|
|
2366
|
+
...defaultKeymap,
|
|
2367
|
+
...historyKeymap,
|
|
2368
|
+
...mdEditorCommands,
|
|
2369
|
+
indentWithTab
|
|
2370
|
+
];
|
|
2369
2371
|
const pasteHandler = usePasteUpload(props2, codeMirrorUt);
|
|
2370
2372
|
const domEventHandlers = {
|
|
2371
2373
|
paste: pasteHandler,
|
|
@@ -2394,7 +2396,7 @@ const useCodeMirror = (props2) => {
|
|
|
2394
2396
|
}
|
|
2395
2397
|
};
|
|
2396
2398
|
const defaultExtensions = [
|
|
2397
|
-
keymap.of(
|
|
2399
|
+
keymap.of(getDefaultKeymaps()),
|
|
2398
2400
|
historyComp.of(history()),
|
|
2399
2401
|
languageComp.of(markdown({ codeLanguages: languages })),
|
|
2400
2402
|
// 横向换行
|
|
@@ -2417,9 +2419,12 @@ const useCodeMirror = (props2) => {
|
|
|
2417
2419
|
themeComp.of(theme.value === "light" ? oneLight : oneDark),
|
|
2418
2420
|
autocompletionComp.of(createAutocompletion(props2.completions))
|
|
2419
2421
|
];
|
|
2420
|
-
return configOption.codeMirrorExtensions(
|
|
2421
|
-
|
|
2422
|
-
|
|
2422
|
+
return configOption.codeMirrorExtensions(
|
|
2423
|
+
theme.value,
|
|
2424
|
+
extensions,
|
|
2425
|
+
getDefaultKeymaps(),
|
|
2426
|
+
{ editorId }
|
|
2427
|
+
);
|
|
2423
2428
|
};
|
|
2424
2429
|
onMounted(() => {
|
|
2425
2430
|
const view = new EditorView$1({
|
|
@@ -2615,6 +2620,7 @@ const useResize = (props2, contentRef, resizeRef) => {
|
|
|
2615
2620
|
left: props2.inputBoxWitdh,
|
|
2616
2621
|
display: "initial"
|
|
2617
2622
|
});
|
|
2623
|
+
const showPreviewWrapper = ref(props2.setting.preview || props2.setting.htmlPreview);
|
|
2618
2624
|
const resizeMousemove = (e) => {
|
|
2619
2625
|
var _a, _b, _c;
|
|
2620
2626
|
const maxWidth = ((_a = contentRef.value) == null ? void 0 : _a.offsetWidth) || 0;
|
|
@@ -2673,19 +2679,22 @@ const useResize = (props2, contentRef, resizeRef) => {
|
|
|
2673
2679
|
if (props2.setting.previewOnly) {
|
|
2674
2680
|
inputWrapperStyle.width = "0%";
|
|
2675
2681
|
resizeOperateStyle.display = "none";
|
|
2682
|
+
showPreviewWrapper.value = true;
|
|
2676
2683
|
} else if (!props2.setting.htmlPreview && !props2.setting.preview) {
|
|
2677
2684
|
inputWrapperStyle.width = "100%";
|
|
2678
2685
|
resizeOperateStyle.display = "none";
|
|
2686
|
+
showPreviewWrapper.value = false;
|
|
2679
2687
|
} else {
|
|
2680
2688
|
inputWrapperStyle.width = state.resizedWidth;
|
|
2681
2689
|
resizeOperateStyle.display = "initial";
|
|
2690
|
+
showPreviewWrapper.value = true;
|
|
2682
2691
|
}
|
|
2683
2692
|
},
|
|
2684
2693
|
{
|
|
2685
2694
|
immediate: true
|
|
2686
2695
|
}
|
|
2687
2696
|
);
|
|
2688
|
-
return { inputWrapperStyle, resizeOperateStyle };
|
|
2697
|
+
return { inputWrapperStyle, resizeOperateStyle, showPreviewWrapper };
|
|
2689
2698
|
};
|
|
2690
2699
|
const Content = /* @__PURE__ */ defineComponent({
|
|
2691
2700
|
name: "MDEditorContent",
|
|
@@ -2702,7 +2711,8 @@ const Content = /* @__PURE__ */ defineComponent({
|
|
|
2702
2711
|
} = useCodeMirror(props2);
|
|
2703
2712
|
const {
|
|
2704
2713
|
inputWrapperStyle,
|
|
2705
|
-
resizeOperateStyle
|
|
2714
|
+
resizeOperateStyle,
|
|
2715
|
+
showPreviewWrapper
|
|
2706
2716
|
} = useResize(props2, contentRef, resizeRef);
|
|
2707
2717
|
useAutoScroll(props2, html, codeMirrorUt);
|
|
2708
2718
|
ctx.expose({
|
|
@@ -2714,11 +2724,15 @@ const Content = /* @__PURE__ */ defineComponent({
|
|
|
2714
2724
|
var _a;
|
|
2715
2725
|
(_a = codeMirrorUt.value) == null ? void 0 : _a.focus(options);
|
|
2716
2726
|
},
|
|
2717
|
-
resetHistory
|
|
2727
|
+
resetHistory,
|
|
2728
|
+
getEditorView() {
|
|
2729
|
+
var _a;
|
|
2730
|
+
return (_a = codeMirrorUt.value) == null ? void 0 : _a.view;
|
|
2731
|
+
}
|
|
2718
2732
|
});
|
|
2719
2733
|
return () => {
|
|
2720
2734
|
return createVNode("div", {
|
|
2721
|
-
"class": `${prefix}-content${
|
|
2735
|
+
"class": `${prefix}-content${showPreviewWrapper.value ? " has-preview" : ""}`,
|
|
2722
2736
|
"ref": contentRef
|
|
2723
2737
|
}, [createVNode("div", {
|
|
2724
2738
|
"class": `${prefix}-input-wrapper`,
|
|
@@ -2728,7 +2742,7 @@ const Content = /* @__PURE__ */ defineComponent({
|
|
|
2728
2742
|
"class": `${prefix}-resize-operate`,
|
|
2729
2743
|
"style": resizeOperateStyle,
|
|
2730
2744
|
"ref": resizeRef
|
|
2731
|
-
}, null), createVNode(ContentPreview, {
|
|
2745
|
+
}, null), showPreviewWrapper.value && createVNode(ContentPreview, {
|
|
2732
2746
|
"modelValue": props2.modelValue,
|
|
2733
2747
|
"onChange": props2.onChange,
|
|
2734
2748
|
"setting": props2.setting,
|
package/lib/es/chunks/dom.mjs
CHANGED
|
@@ -72,18 +72,16 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
72
72
|
let posY = 0;
|
|
73
73
|
let isDragging = false;
|
|
74
74
|
let startX, startY;
|
|
75
|
-
let initialDistance
|
|
75
|
+
let initialDistance;
|
|
76
76
|
let initialScale = 1;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
77
|
+
const updateTransform = () => {
|
|
78
|
+
content.style.transform = `translate(${posX}px, ${posY}px) scale(${scale})`;
|
|
79
|
+
};
|
|
81
80
|
container.addEventListener("touchstart", (event) => {
|
|
82
81
|
if (event.touches.length === 1) {
|
|
83
82
|
isDragging = true;
|
|
84
83
|
startX = event.touches[0].clientX - posX;
|
|
85
84
|
startY = event.touches[0].clientY - posY;
|
|
86
|
-
container.style.cursor = "grabbing";
|
|
87
85
|
} else if (event.touches.length === 2) {
|
|
88
86
|
initialDistance = Math.hypot(
|
|
89
87
|
event.touches[0].clientX - event.touches[1].clientX,
|
|
@@ -104,21 +102,20 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
104
102
|
event.touches[0].clientY - event.touches[1].clientY
|
|
105
103
|
);
|
|
106
104
|
const scaleChange = newDistance / initialDistance;
|
|
107
|
-
|
|
105
|
+
const previousScale = scale;
|
|
106
|
+
scale = initialScale * (1 + (scaleChange - 1));
|
|
108
107
|
const centerX = (event.touches[0].clientX + event.touches[1].clientX) / 2;
|
|
109
108
|
const centerY = (event.touches[0].clientY + event.touches[1].clientY) / 2;
|
|
110
109
|
const rect = content.getBoundingClientRect();
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
posX -=
|
|
114
|
-
posY -=
|
|
110
|
+
const relativeX = (centerX - rect.left) / previousScale;
|
|
111
|
+
const relativeY = (centerY - rect.top) / previousScale;
|
|
112
|
+
posX -= relativeX * (scale - previousScale);
|
|
113
|
+
posY -= relativeY * (scale - previousScale);
|
|
115
114
|
updateTransform();
|
|
116
115
|
}
|
|
117
116
|
});
|
|
118
117
|
container.addEventListener("touchend", () => {
|
|
119
118
|
isDragging = false;
|
|
120
|
-
container.style.cursor = "grab";
|
|
121
|
-
initialDistance = -1;
|
|
122
119
|
});
|
|
123
120
|
container.addEventListener("wheel", (event) => {
|
|
124
121
|
event.preventDefault();
|
|
@@ -132,15 +129,14 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
132
129
|
const rect = content.getBoundingClientRect();
|
|
133
130
|
const mouseX = event.clientX - rect.left;
|
|
134
131
|
const mouseY = event.clientY - rect.top;
|
|
135
|
-
posX -= mouseX * (scale - previousScale);
|
|
136
|
-
posY -= mouseY * (scale - previousScale);
|
|
132
|
+
posX -= mouseX / previousScale * (scale - previousScale);
|
|
133
|
+
posY -= mouseY / previousScale * (scale - previousScale);
|
|
137
134
|
updateTransform();
|
|
138
135
|
});
|
|
139
136
|
container.addEventListener("mousedown", (event) => {
|
|
140
137
|
isDragging = true;
|
|
141
138
|
startX = event.clientX - posX;
|
|
142
139
|
startY = event.clientY - posY;
|
|
143
|
-
container.style.cursor = "grabbing";
|
|
144
140
|
});
|
|
145
141
|
container.addEventListener("mousemove", (event) => {
|
|
146
142
|
if (isDragging) {
|
|
@@ -151,11 +147,9 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
151
147
|
});
|
|
152
148
|
container.addEventListener("mouseup", () => {
|
|
153
149
|
isDragging = false;
|
|
154
|
-
container.style.cursor = "grab";
|
|
155
150
|
});
|
|
156
151
|
container.addEventListener("mouseleave", () => {
|
|
157
152
|
isDragging = false;
|
|
158
|
-
container.style.cursor = "grab";
|
|
159
153
|
});
|
|
160
154
|
};
|
|
161
155
|
const handler = (containers) => {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
4
|
class Bus {
|
|
8
5
|
constructor() {
|
|
9
6
|
// 事件池
|