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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# π md-editor-v3
|
|
2
2
|
|
|
3
|
-
   
|
|
3
|
+
    
|
|
4
4
|
|
|
5
5
|
English \| [δΈζ](https://github.com/imzbf/md-editor-v3/blob/develop/README-CN.md)
|
|
6
6
|
|
|
@@ -392,41 +392,19 @@ onMounted(() => {
|
|
|
392
392
|
|
|
393
393
|
Get the internal state of the editor, including pageFullscreen, fullscreen, preview, htmlPreview, catalog, etc.
|
|
394
394
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
editorRef.value?.on('fullscreen', (status) => console.log(status));
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
- preview
|
|
408
|
-
|
|
409
|
-
```js
|
|
410
|
-
editorRef.value?.on('preview', (status) => console.log(status));
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
- previewOnly
|
|
414
|
-
|
|
415
|
-
```js
|
|
416
|
-
editorRef.value?.on('previewOnly', (status) => console.log(status));
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
- htmlPreview
|
|
420
|
-
|
|
421
|
-
```js
|
|
422
|
-
editorRef.value?.on('htmlPreview', (status) => console.log(status));
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
- catalog
|
|
395
|
+
```ts
|
|
396
|
+
type Keys =
|
|
397
|
+
| 'pageFullscreen'
|
|
398
|
+
| 'fullscreen'
|
|
399
|
+
| 'preview'
|
|
400
|
+
| 'previewOnly'
|
|
401
|
+
| 'htmlPreview'
|
|
402
|
+
| 'catalog';
|
|
403
|
+
```
|
|
426
404
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
405
|
+
```js
|
|
406
|
+
editorRef.value?.on('pageFullscreen', (status) => console.log(status));
|
|
407
|
+
```
|
|
430
408
|
|
|
431
409
|
### π» togglePageFullscreen
|
|
432
410
|
|
|
@@ -478,9 +456,7 @@ editorRef.value?.toggleCatalog(true);
|
|
|
478
456
|
|
|
479
457
|
### πΎ triggerSave
|
|
480
458
|
|
|
481
|
-
|
|
482
|
-
editorRef.value?.triggerSave();
|
|
483
|
-
```
|
|
459
|
+
Save actions will be triggered.
|
|
484
460
|
|
|
485
461
|
### π insert
|
|
486
462
|
|
|
@@ -525,18 +501,10 @@ editorRef.value?.focus(option);
|
|
|
525
501
|
|
|
526
502
|
Re render the content.
|
|
527
503
|
|
|
528
|
-
```js
|
|
529
|
-
editorRef.value?.rerender();
|
|
530
|
-
```
|
|
531
|
-
|
|
532
504
|
### π getSelectedText
|
|
533
505
|
|
|
534
506
|
Get the currently selected text.
|
|
535
507
|
|
|
536
|
-
```js
|
|
537
|
-
console.log(editorRef.value?.getSelectedText());
|
|
538
|
-
```
|
|
539
|
-
|
|
540
508
|
### π resetHistory
|
|
541
509
|
|
|
542
510
|
Clear current history.
|
|
@@ -561,6 +529,10 @@ Insert content into the editor via trigger.
|
|
|
561
529
|
editorRef.value?.execCommand('bold');
|
|
562
530
|
```
|
|
563
531
|
|
|
532
|
+
### π getEditorView
|
|
533
|
+
|
|
534
|
+
Get codemirror instance.
|
|
535
|
+
|
|
564
536
|
## π΄ Config Editor
|
|
565
537
|
|
|
566
538
|
Use `config(option: ConfigOption)` to reconfigure `markdown-it` and so on.
|
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) =>
|
|
5
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
5
|
const vue = require("vue");
|
|
9
6
|
const config = require("./chunks/config.cjs");
|
|
10
7
|
const util = require("@vavt/util");
|
|
@@ -222,7 +219,6 @@ const TableShape = /* @__PURE__ */ vue.defineComponent({
|
|
|
222
219
|
}, null)]))]))]);
|
|
223
220
|
}
|
|
224
221
|
});
|
|
225
|
-
const TableShape$1 = TableShape;
|
|
226
222
|
const props$5 = {
|
|
227
223
|
type: {
|
|
228
224
|
type: String,
|
|
@@ -874,7 +870,7 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
|
|
|
874
870
|
visible.table = v;
|
|
875
871
|
},
|
|
876
872
|
"key": "bar-table",
|
|
877
|
-
"overlay": vue.createVNode(TableShape
|
|
873
|
+
"overlay": vue.createVNode(TableShape, {
|
|
878
874
|
"tableShape": props2.tableShape,
|
|
879
875
|
"onSelected": (selectedShape) => {
|
|
880
876
|
emitHandler("table", {
|
|
@@ -1362,15 +1358,15 @@ const directive2flag = async (direct, codeMirrorUt, params) => {
|
|
|
1362
1358
|
break;
|
|
1363
1359
|
}
|
|
1364
1360
|
case "sub": {
|
|
1365
|
-
targetValue =
|
|
1366
|
-
deviationStart =
|
|
1367
|
-
deviationEnd = -
|
|
1361
|
+
targetValue = `~${selectedText}~`;
|
|
1362
|
+
deviationStart = 1;
|
|
1363
|
+
deviationEnd = -1;
|
|
1368
1364
|
break;
|
|
1369
1365
|
}
|
|
1370
1366
|
case "sup": {
|
|
1371
|
-
targetValue =
|
|
1372
|
-
deviationStart =
|
|
1373
|
-
deviationEnd = -
|
|
1367
|
+
targetValue = `^${selectedText}^`;
|
|
1368
|
+
deviationStart = 1;
|
|
1369
|
+
deviationEnd = -1;
|
|
1374
1370
|
break;
|
|
1375
1371
|
}
|
|
1376
1372
|
case "codeRow": {
|
|
@@ -2364,9 +2360,15 @@ const useCodeMirror = (props2) => {
|
|
|
2364
2360
|
const theme = vue.inject("theme");
|
|
2365
2361
|
const inputWrapperRef = vue.ref();
|
|
2366
2362
|
const codeMirrorUt = vue.shallowRef();
|
|
2363
|
+
const spelling = vue.ref(false);
|
|
2367
2364
|
const languageComp = new state.Compartment(), themeComp = new state.Compartment(), autocompletionComp = new state.Compartment(), historyComp = new state.Compartment(), eventComp = new state.Compartment();
|
|
2368
2365
|
const mdEditorCommands = createCommands(editorId, props2);
|
|
2369
|
-
const
|
|
2366
|
+
const getDefaultKeymaps = () => [
|
|
2367
|
+
...commands.defaultKeymap,
|
|
2368
|
+
...commands.historyKeymap,
|
|
2369
|
+
...mdEditorCommands,
|
|
2370
|
+
commands.indentWithTab
|
|
2371
|
+
];
|
|
2370
2372
|
const pasteHandler = usePasteUpload(props2, codeMirrorUt);
|
|
2371
2373
|
const domEventHandlers = {
|
|
2372
2374
|
paste: pasteHandler,
|
|
@@ -2395,7 +2397,7 @@ const useCodeMirror = (props2) => {
|
|
|
2395
2397
|
}
|
|
2396
2398
|
};
|
|
2397
2399
|
const defaultExtensions = [
|
|
2398
|
-
view.keymap.of(
|
|
2400
|
+
view.keymap.of(getDefaultKeymaps()),
|
|
2399
2401
|
historyComp.of(commands.history()),
|
|
2400
2402
|
languageComp.of(langMarkdown.markdown({ codeLanguages: languageData.languages })),
|
|
2401
2403
|
// ζ¨ͺεζ’θ‘
|
|
@@ -2418,9 +2420,12 @@ const useCodeMirror = (props2) => {
|
|
|
2418
2420
|
themeComp.of(theme.value === "light" ? oneLight : oneDark),
|
|
2419
2421
|
autocompletionComp.of(createAutocompletion(props2.completions))
|
|
2420
2422
|
];
|
|
2421
|
-
return config.configOption.codeMirrorExtensions(
|
|
2422
|
-
|
|
2423
|
-
|
|
2423
|
+
return config.configOption.codeMirrorExtensions(
|
|
2424
|
+
theme.value,
|
|
2425
|
+
extensions,
|
|
2426
|
+
getDefaultKeymaps(),
|
|
2427
|
+
{ editorId }
|
|
2428
|
+
);
|
|
2424
2429
|
};
|
|
2425
2430
|
vue.onMounted(() => {
|
|
2426
2431
|
const view2 = new codemirror.EditorView({
|
|
@@ -2616,6 +2621,7 @@ const useResize = (props2, contentRef, resizeRef) => {
|
|
|
2616
2621
|
left: props2.inputBoxWitdh,
|
|
2617
2622
|
display: "initial"
|
|
2618
2623
|
});
|
|
2624
|
+
const showPreviewWrapper = vue.ref(props2.setting.preview || props2.setting.htmlPreview);
|
|
2619
2625
|
const resizeMousemove = (e) => {
|
|
2620
2626
|
var _a, _b, _c;
|
|
2621
2627
|
const maxWidth = ((_a = contentRef.value) == null ? void 0 : _a.offsetWidth) || 0;
|
|
@@ -2674,19 +2680,22 @@ const useResize = (props2, contentRef, resizeRef) => {
|
|
|
2674
2680
|
if (props2.setting.previewOnly) {
|
|
2675
2681
|
inputWrapperStyle.width = "0%";
|
|
2676
2682
|
resizeOperateStyle.display = "none";
|
|
2683
|
+
showPreviewWrapper.value = true;
|
|
2677
2684
|
} else if (!props2.setting.htmlPreview && !props2.setting.preview) {
|
|
2678
2685
|
inputWrapperStyle.width = "100%";
|
|
2679
2686
|
resizeOperateStyle.display = "none";
|
|
2687
|
+
showPreviewWrapper.value = false;
|
|
2680
2688
|
} else {
|
|
2681
2689
|
inputWrapperStyle.width = state2.resizedWidth;
|
|
2682
2690
|
resizeOperateStyle.display = "initial";
|
|
2691
|
+
showPreviewWrapper.value = true;
|
|
2683
2692
|
}
|
|
2684
2693
|
},
|
|
2685
2694
|
{
|
|
2686
2695
|
immediate: true
|
|
2687
2696
|
}
|
|
2688
2697
|
);
|
|
2689
|
-
return { inputWrapperStyle, resizeOperateStyle };
|
|
2698
|
+
return { inputWrapperStyle, resizeOperateStyle, showPreviewWrapper };
|
|
2690
2699
|
};
|
|
2691
2700
|
const Content = /* @__PURE__ */ vue.defineComponent({
|
|
2692
2701
|
name: "MDEditorContent",
|
|
@@ -2703,7 +2712,8 @@ const Content = /* @__PURE__ */ vue.defineComponent({
|
|
|
2703
2712
|
} = useCodeMirror(props2);
|
|
2704
2713
|
const {
|
|
2705
2714
|
inputWrapperStyle,
|
|
2706
|
-
resizeOperateStyle
|
|
2715
|
+
resizeOperateStyle,
|
|
2716
|
+
showPreviewWrapper
|
|
2707
2717
|
} = useResize(props2, contentRef, resizeRef);
|
|
2708
2718
|
useAutoScroll(props2, html, codeMirrorUt);
|
|
2709
2719
|
ctx.expose({
|
|
@@ -2715,11 +2725,15 @@ const Content = /* @__PURE__ */ vue.defineComponent({
|
|
|
2715
2725
|
var _a;
|
|
2716
2726
|
(_a = codeMirrorUt.value) == null ? void 0 : _a.focus(options);
|
|
2717
2727
|
},
|
|
2718
|
-
resetHistory
|
|
2728
|
+
resetHistory,
|
|
2729
|
+
getEditorView() {
|
|
2730
|
+
var _a;
|
|
2731
|
+
return (_a = codeMirrorUt.value) == null ? void 0 : _a.view;
|
|
2732
|
+
}
|
|
2719
2733
|
});
|
|
2720
2734
|
return () => {
|
|
2721
2735
|
return vue.createVNode("div", {
|
|
2722
|
-
"class": `${config.prefix}-content${
|
|
2736
|
+
"class": `${config.prefix}-content${showPreviewWrapper.value ? " has-preview" : ""}`,
|
|
2723
2737
|
"ref": contentRef
|
|
2724
2738
|
}, [vue.createVNode("div", {
|
|
2725
2739
|
"class": `${config.prefix}-input-wrapper`,
|
|
@@ -2729,7 +2743,7 @@ const Content = /* @__PURE__ */ vue.defineComponent({
|
|
|
2729
2743
|
"class": `${config.prefix}-resize-operate`,
|
|
2730
2744
|
"style": resizeOperateStyle,
|
|
2731
2745
|
"ref": resizeRef
|
|
2732
|
-
}, null), vue.createVNode(MdPreview.ContentPreview, {
|
|
2746
|
+
}, null), showPreviewWrapper.value && vue.createVNode(MdPreview.ContentPreview, {
|
|
2733
2747
|
"modelValue": props2.modelValue,
|
|
2734
2748
|
"onChange": props2.onChange,
|
|
2735
2749
|
"setting": props2.setting,
|
package/lib/cjs/chunks/dom.cjs
CHANGED
|
@@ -73,18 +73,16 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
73
73
|
let posY = 0;
|
|
74
74
|
let isDragging = false;
|
|
75
75
|
let startX, startY;
|
|
76
|
-
let initialDistance
|
|
76
|
+
let initialDistance;
|
|
77
77
|
let initialScale = 1;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
78
|
+
const updateTransform = () => {
|
|
79
|
+
content.style.transform = `translate(${posX}px, ${posY}px) scale(${scale})`;
|
|
80
|
+
};
|
|
82
81
|
container.addEventListener("touchstart", (event) => {
|
|
83
82
|
if (event.touches.length === 1) {
|
|
84
83
|
isDragging = true;
|
|
85
84
|
startX = event.touches[0].clientX - posX;
|
|
86
85
|
startY = event.touches[0].clientY - posY;
|
|
87
|
-
container.style.cursor = "grabbing";
|
|
88
86
|
} else if (event.touches.length === 2) {
|
|
89
87
|
initialDistance = Math.hypot(
|
|
90
88
|
event.touches[0].clientX - event.touches[1].clientX,
|
|
@@ -105,21 +103,20 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
105
103
|
event.touches[0].clientY - event.touches[1].clientY
|
|
106
104
|
);
|
|
107
105
|
const scaleChange = newDistance / initialDistance;
|
|
108
|
-
|
|
106
|
+
const previousScale = scale;
|
|
107
|
+
scale = initialScale * (1 + (scaleChange - 1));
|
|
109
108
|
const centerX = (event.touches[0].clientX + event.touches[1].clientX) / 2;
|
|
110
109
|
const centerY = (event.touches[0].clientY + event.touches[1].clientY) / 2;
|
|
111
110
|
const rect = content.getBoundingClientRect();
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
posX -=
|
|
115
|
-
posY -=
|
|
111
|
+
const relativeX = (centerX - rect.left) / previousScale;
|
|
112
|
+
const relativeY = (centerY - rect.top) / previousScale;
|
|
113
|
+
posX -= relativeX * (scale - previousScale);
|
|
114
|
+
posY -= relativeY * (scale - previousScale);
|
|
116
115
|
updateTransform();
|
|
117
116
|
}
|
|
118
117
|
});
|
|
119
118
|
container.addEventListener("touchend", () => {
|
|
120
119
|
isDragging = false;
|
|
121
|
-
container.style.cursor = "grab";
|
|
122
|
-
initialDistance = -1;
|
|
123
120
|
});
|
|
124
121
|
container.addEventListener("wheel", (event) => {
|
|
125
122
|
event.preventDefault();
|
|
@@ -133,15 +130,14 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
133
130
|
const rect = content.getBoundingClientRect();
|
|
134
131
|
const mouseX = event.clientX - rect.left;
|
|
135
132
|
const mouseY = event.clientY - rect.top;
|
|
136
|
-
posX -= mouseX * (scale - previousScale);
|
|
137
|
-
posY -= mouseY * (scale - previousScale);
|
|
133
|
+
posX -= mouseX / previousScale * (scale - previousScale);
|
|
134
|
+
posY -= mouseY / previousScale * (scale - previousScale);
|
|
138
135
|
updateTransform();
|
|
139
136
|
});
|
|
140
137
|
container.addEventListener("mousedown", (event) => {
|
|
141
138
|
isDragging = true;
|
|
142
139
|
startX = event.clientX - posX;
|
|
143
140
|
startY = event.clientY - posY;
|
|
144
|
-
container.style.cursor = "grabbing";
|
|
145
141
|
});
|
|
146
142
|
container.addEventListener("mousemove", (event) => {
|
|
147
143
|
if (isDragging) {
|
|
@@ -152,11 +148,9 @@ const zoomMermaid = /* @__PURE__ */ (() => {
|
|
|
152
148
|
});
|
|
153
149
|
container.addEventListener("mouseup", () => {
|
|
154
150
|
isDragging = false;
|
|
155
|
-
container.style.cursor = "grab";
|
|
156
151
|
});
|
|
157
152
|
container.addEventListener("mouseleave", () => {
|
|
158
153
|
isDragging = false;
|
|
159
|
-
container.style.cursor = "grab";
|
|
160
154
|
});
|
|
161
155
|
};
|
|
162
156
|
const handler = (containers) => {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) =>
|
|
5
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
5
|
class Bus {
|
|
9
6
|
constructor() {
|
|
10
7
|
// δΊδ»Άζ±
|