md-editor-v3 2.0.0-beta.9 → 2.0.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 +59 -19
- package/lib/md-editor-v3.es.js +33 -38
- package/lib/md-editor-v3.umd.js +33 -33
- package/lib/style.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@ English \| [中文](https://github.com/imzbf/md-editor-v3/blob/dev/README-CN.md)
|
|
|
6
6
|
|
|
7
7
|
Markdown editor for vue3, developed in `jsx` and `typescript`.
|
|
8
8
|
|
|
9
|
-
- Documentation and example
|
|
9
|
+
- Documentation and example: [Go](https://imzbf.github.io/md-editor-v3)
|
|
10
10
|
|
|
11
|
-
- Use it online
|
|
11
|
+
- Use it online: [Go](https://codesandbox.io/s/epic-bird-2znqo)
|
|
12
12
|
|
|
13
|
-
- The same series editor for react
|
|
13
|
+
- The same series editor for react: [md-editor-rt](https://github.com/imzbf/md-editor-rt)
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ Markdown editor for vue3, developed in `jsx` and `typescript`.
|
|
|
21
21
|
- Multi-language, build-in Chinese and English(default: Chinese).
|
|
22
22
|
- Upload picture, paste or clip the picture and upload it.
|
|
23
23
|
- Render article directly(no editor, no event listener, only preview content).
|
|
24
|
-
- Preview themes, `defalut`, `vuepress`, `github`, `cyanosis`, `mk-cute`, `smart-blue` styles(not identical). It can be customized also(
|
|
24
|
+
- Preview themes, `defalut`, `vuepress`, `github`, `cyanosis`, `mk-cute`, `smart-blue` styles(not identical). It can be customized also(Refer to example page).
|
|
25
25
|
- `mermaid`(>=1.8.0), `katex` mathematical formula(>=1.9.0).
|
|
26
26
|
- Customize the toolbar as you like.
|
|
27
27
|
|
|
@@ -113,7 +113,7 @@ mark and emoji extensions
|
|
|
113
113
|
<details>
|
|
114
114
|
<summary>[StaticTextDefaultValue]</summary>
|
|
115
115
|
|
|
116
|
-
Expand language, you need to replace all the content here
|
|
116
|
+
Expand language, you need to replace all the content here:
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
119
|
export interface ToolbarTips {
|
|
@@ -213,15 +213,15 @@ export interface StaticTextDefaultValue {
|
|
|
213
213
|
|
|
214
214
|
| name | type | default | description |
|
|
215
215
|
| --- | --- | --- | --- |
|
|
216
|
-
| defToolbars | Array<DropdownToolbar \| NormalToolbar \| ModalToolbar> | null |
|
|
216
|
+
| defToolbars | Array<DropdownToolbar \| NormalToolbar \| ModalToolbar> | null | Custom toolbar in `DropdownToolbar`, `NormalToolbar` or `ModalToolbar` |
|
|
217
217
|
|
|
218
|
-
`NormalToolbar`
|
|
218
|
+
`NormalToolbar` example:
|
|
219
219
|
|
|
220
220
|
```vue
|
|
221
221
|
<template>
|
|
222
222
|
<md-editor>
|
|
223
223
|
<template #defToolbars>
|
|
224
|
-
<normal-toolbar title="mark" @
|
|
224
|
+
<normal-toolbar title="mark" @onClick="handler">
|
|
225
225
|
<template #trigger>
|
|
226
226
|
<svg class="md-icon" aria-hidden="true">
|
|
227
227
|
<use xlink:href="#icon-mark"></use>
|
|
@@ -258,7 +258,9 @@ const handler = () => {
|
|
|
258
258
|
|
|
259
259
|
Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
260
260
|
|
|
261
|
-
- markedRenderer: `(renderer: Renderer) => Renderer
|
|
261
|
+
- markedRenderer: `(renderer: Renderer) => Renderer`
|
|
262
|
+
|
|
263
|
+
Open target page in a new browser window:
|
|
262
264
|
|
|
263
265
|
```js
|
|
264
266
|
MdEditor.config({
|
|
@@ -286,7 +288,9 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
|
286
288
|
|
|
287
289
|
> Reference: https://marked.js.org/using_pro#extensions
|
|
288
290
|
|
|
289
|
-
- markedOptions: `marked.MarkedOptions
|
|
291
|
+
- markedOptions: `marked.MarkedOptions`
|
|
292
|
+
|
|
293
|
+
Do not render `<br>` on a single line break:
|
|
290
294
|
|
|
291
295
|
```js
|
|
292
296
|
import MdEditor from 'md-editor-v3';
|
|
@@ -298,7 +302,7 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
|
298
302
|
|
|
299
303
|
> Reference: https://marked.js.org/using_advanced#options
|
|
300
304
|
|
|
301
|
-
- editorConfig: Add more languages
|
|
305
|
+
- editorConfig: Add more languages, reset `mermaid` template or delay rendering time:
|
|
302
306
|
|
|
303
307
|
```js
|
|
304
308
|
import MdEditor from 'md-editor-v3';
|
|
@@ -371,7 +375,7 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
|
371
375
|
|
|
372
376
|
</details>
|
|
373
377
|
|
|
374
|
-
## Shortcut
|
|
378
|
+
## Shortcut Key
|
|
375
379
|
|
|
376
380
|
| key | function | description |
|
|
377
381
|
| --- | --- | --- |
|
|
@@ -448,22 +452,22 @@ They are used as attributes of the editor component, eg: `Editor.DropdownToolbar
|
|
|
448
452
|
- `modalTitle`: `string`, not necessary, title of the Modal.
|
|
449
453
|
- `visible`: `boolean`, necessary, visibility of Modal.
|
|
450
454
|
- `width`: `string`, not necessary, width of Modal, default `auto`.
|
|
451
|
-
- `height
|
|
455
|
+
- `height`: `string`, same as `width`.
|
|
452
456
|
- `showAdjust`: `boolean`, not necessary, visibility of fullscreen button.
|
|
453
457
|
- `isFullscreen`: `boolean`, necessary when `showAdjust = true`, status of fullscreen.
|
|
454
458
|
|
|
455
459
|
- **events**
|
|
456
460
|
|
|
457
461
|
- `onClick`: `() => void`, necessary.
|
|
458
|
-
- `onClose
|
|
459
|
-
- `onAdjust
|
|
462
|
+
- `onClose`: `() => void`, necessary, close event.
|
|
463
|
+
- `onAdjust`: `(val: boolean) => void`, fullscreen button click event.
|
|
460
464
|
|
|
461
465
|
- **slots**
|
|
462
466
|
|
|
463
467
|
- `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
|
|
464
468
|
- `overlay`: `string | JSX.Element`, necessary, content of Modal.
|
|
465
469
|
|
|
466
|
-
###
|
|
470
|
+
### MdCatalog
|
|
467
471
|
|
|
468
472
|
`Editor.MdCatalog`
|
|
469
473
|
|
|
@@ -477,7 +481,7 @@ They are used as attributes of the editor component, eg: `Editor.DropdownToolbar
|
|
|
477
481
|
|
|
478
482
|
## Examples
|
|
479
483
|
|
|
480
|
-
### Jsx
|
|
484
|
+
### Jsx Template
|
|
481
485
|
|
|
482
486
|
```js
|
|
483
487
|
import { defineComponent, reactive } from 'vue';
|
|
@@ -496,7 +500,7 @@ export default defineComponent({
|
|
|
496
500
|
});
|
|
497
501
|
```
|
|
498
502
|
|
|
499
|
-
###
|
|
503
|
+
### Setup Template
|
|
500
504
|
|
|
501
505
|
```vue
|
|
502
506
|
<template>
|
|
@@ -514,7 +518,7 @@ const text = ref('# Hello Editor');
|
|
|
514
518
|
|
|
515
519
|
### Upload picture
|
|
516
520
|
|
|
517
|
-
> Tips
|
|
521
|
+
> Tips: When you paste and upload GIF, it will upload a static picture. So you should upload it by file system!
|
|
518
522
|
|
|
519
523
|
<template>
|
|
520
524
|
<md-editor v-model="text" @onUploadImg="onUploadImg" />
|
|
@@ -549,3 +553,39 @@ const onUploadImg = async (files, callback) => {
|
|
|
549
553
|
callback(res.map((item) => item.data.url));
|
|
550
554
|
};
|
|
551
555
|
</script>
|
|
556
|
+
|
|
557
|
+
### Change Styles
|
|
558
|
+
|
|
559
|
+
```less
|
|
560
|
+
.css-vars(@isDark) {
|
|
561
|
+
--md-color: if(@isDark, #999, #222);
|
|
562
|
+
--md-hover-color: if(@isDark, #bbb, #000);
|
|
563
|
+
--md-bk-color: if(@isDark, #000, #fff);
|
|
564
|
+
--md-bk-color-outstand: if(@isDark, #111, #f6f6f6);
|
|
565
|
+
--md-bk-hover-color: if(@isDark, #1b1a1a, #f5f7fa);
|
|
566
|
+
--md-border-color: if(@isDark, #2d2d2d, #e6e6e6);
|
|
567
|
+
--md-border-hover-color: if(@isDark, #636262, #b9b9b9);
|
|
568
|
+
--md-border-active-color: if(@isDark, #777, #999);
|
|
569
|
+
--md-modal-mask: #00000073;
|
|
570
|
+
--md-scrollbar-bg-color: if(@isDark, #0f0f0f, #e2e2e2);
|
|
571
|
+
--md-scrollbar-thumb-color: if(@isDark, #2d2d2d, #0000004d);
|
|
572
|
+
--md-scrollbar-thumb-hover-color: if(@isDark, #3a3a3a, #00000059);
|
|
573
|
+
--md-scrollbar-thumb-avtive-color: if(@isDark, #3a3a3a, #00000061);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
.md {
|
|
577
|
+
.css-vars(false);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
.md-dark {
|
|
581
|
+
.css-vars(true);
|
|
582
|
+
}
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
Change background color in dark mode:
|
|
586
|
+
|
|
587
|
+
```css
|
|
588
|
+
.md-dark {
|
|
589
|
+
--md-bk-color: #333 !important;
|
|
590
|
+
}
|
|
591
|
+
```
|
package/lib/md-editor-v3.es.js
CHANGED
|
@@ -20,16 +20,17 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { onMounted, onBeforeUnmount, provide, computed, defineComponent, createVNode, reactive, ref, watch, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
|
|
21
21
|
const prefix = "md";
|
|
22
22
|
const iconfontUrl = "https://at.alicdn.com/t/font_2605852_pqekijay2ij.js";
|
|
23
|
-
const
|
|
23
|
+
const cdnBase = "https://cdnjs.cloudflare.com/ajax/libs";
|
|
24
|
+
const highlightUrl = `${cdnBase}/highlight.js/11.5.1/highlight.min.js`;
|
|
24
25
|
const prettierUrl = {
|
|
25
|
-
main:
|
|
26
|
-
markdown:
|
|
26
|
+
main: `${cdnBase}/prettier/2.4.0/standalone.js`,
|
|
27
|
+
markdown: `${cdnBase}/prettier/2.4.0/parser-markdown.js`
|
|
27
28
|
};
|
|
28
29
|
const cropperUrl = {
|
|
29
|
-
css:
|
|
30
|
-
js:
|
|
30
|
+
css: `${cdnBase}/cropperjs/1.5.12/cropper.min.css`,
|
|
31
|
+
js: `${cdnBase}/cropperjs/1.5.12/cropper.min.js`
|
|
31
32
|
};
|
|
32
|
-
const screenfullUrl =
|
|
33
|
+
const screenfullUrl = `${cdnBase}/screenfull.js/5.1.0/screenfull.min.js`;
|
|
33
34
|
const allToolbar = [
|
|
34
35
|
"bold",
|
|
35
36
|
"underline",
|
|
@@ -215,43 +216,43 @@ const staticTextDefault = {
|
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
218
|
};
|
|
218
|
-
const mermaidUrl =
|
|
219
|
+
const mermaidUrl = `${cdnBase}/mermaid/8.13.5/mermaid.min.js`;
|
|
219
220
|
const katexUrl = {
|
|
220
|
-
js:
|
|
221
|
-
css:
|
|
221
|
+
js: `${cdnBase}/KaTeX/0.15.1/katex.min.js`,
|
|
222
|
+
css: `${cdnBase}/KaTeX/0.15.1/katex.min.css`
|
|
222
223
|
};
|
|
223
224
|
const codeCss = {
|
|
224
225
|
a11y: {
|
|
225
|
-
light:
|
|
226
|
-
dark:
|
|
226
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/a11y-light.min.css`,
|
|
227
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/a11y-dark.min.css`
|
|
227
228
|
},
|
|
228
229
|
atom: {
|
|
229
|
-
light:
|
|
230
|
-
dark:
|
|
230
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/atom-one-light.min.css`,
|
|
231
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/atom-one-dark.min.css`
|
|
231
232
|
},
|
|
232
233
|
github: {
|
|
233
|
-
light:
|
|
234
|
-
dark:
|
|
234
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/github.min.css`,
|
|
235
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/github-dark.min.css`
|
|
235
236
|
},
|
|
236
237
|
gradient: {
|
|
237
|
-
light:
|
|
238
|
-
dark:
|
|
238
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/gradient-light.min.css`,
|
|
239
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/gradient-dark.min.css`
|
|
239
240
|
},
|
|
240
241
|
kimbie: {
|
|
241
|
-
light:
|
|
242
|
-
dark:
|
|
242
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/kimbie-light.min.css`,
|
|
243
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/kimbie-dark.min.css`
|
|
243
244
|
},
|
|
244
245
|
paraiso: {
|
|
245
|
-
light:
|
|
246
|
-
dark:
|
|
246
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/paraiso-light.min.css`,
|
|
247
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/paraiso-dark.min.css`
|
|
247
248
|
},
|
|
248
249
|
qtcreator: {
|
|
249
|
-
light:
|
|
250
|
-
dark:
|
|
250
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/qtcreator-light.min.css`,
|
|
251
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/qtcreator-dark.min.css`
|
|
251
252
|
},
|
|
252
253
|
stackoverflow: {
|
|
253
|
-
light:
|
|
254
|
-
dark:
|
|
254
|
+
light: `${cdnBase}/highlight.js/11.5.1/styles/stackoverflow-light.min.css`,
|
|
255
|
+
dark: `${cdnBase}/highlight.js/11.5.1/styles/stackoverflow-dark.min.css`
|
|
255
256
|
}
|
|
256
257
|
};
|
|
257
258
|
class Bus {
|
|
@@ -5263,6 +5264,7 @@ const useHistory = (props2, textAreaRef, completeStatus) => {
|
|
|
5263
5264
|
endPos
|
|
5264
5265
|
});
|
|
5265
5266
|
history.curr = history.list.length - 1;
|
|
5267
|
+
saveHistoryPos();
|
|
5266
5268
|
} else {
|
|
5267
5269
|
history.userUpdated = true;
|
|
5268
5270
|
}
|
|
@@ -5272,14 +5274,11 @@ const useHistory = (props2, textAreaRef, completeStatus) => {
|
|
|
5272
5274
|
var _a2, _b2;
|
|
5273
5275
|
historyPos = [(_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart, (_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd];
|
|
5274
5276
|
};
|
|
5275
|
-
watch((
|
|
5277
|
+
watch([toRef(props2, "value"), completeStatus], () => {
|
|
5276
5278
|
if (completeStatus.value) {
|
|
5277
|
-
saveHistory(
|
|
5279
|
+
saveHistory(props2.value);
|
|
5278
5280
|
}
|
|
5279
5281
|
});
|
|
5280
|
-
watch(() => completeStatus.value, () => {
|
|
5281
|
-
saveHistory(props2.value);
|
|
5282
|
-
});
|
|
5283
5282
|
onMounted(() => {
|
|
5284
5283
|
bus.on(editorId, {
|
|
5285
5284
|
name: "ctrlZ",
|
|
@@ -5293,7 +5292,6 @@ const useHistory = (props2, textAreaRef, completeStatus) => {
|
|
|
5293
5292
|
keyZCallback(history.curr + 1 === history.list.length ? history.curr : history.curr + 1);
|
|
5294
5293
|
}
|
|
5295
5294
|
});
|
|
5296
|
-
textAreaRef.value.addEventListener("keydown", saveHistoryPos);
|
|
5297
5295
|
textAreaRef.value.addEventListener("click", saveHistoryPos);
|
|
5298
5296
|
});
|
|
5299
5297
|
};
|
|
@@ -5570,15 +5568,15 @@ ${nextOrder}. `, {}));
|
|
|
5570
5568
|
});
|
|
5571
5569
|
}
|
|
5572
5570
|
});
|
|
5571
|
+
watch(() => props2.value, () => {
|
|
5572
|
+
selectedText.value = "";
|
|
5573
|
+
});
|
|
5573
5574
|
bus.on(editorId, {
|
|
5574
5575
|
name: "selectTextChange",
|
|
5575
5576
|
callback() {
|
|
5576
5577
|
selectedText.value = getSelectionText(textAreaRef.value);
|
|
5577
5578
|
}
|
|
5578
5579
|
});
|
|
5579
|
-
return {
|
|
5580
|
-
selectedText
|
|
5581
|
-
};
|
|
5582
5580
|
};
|
|
5583
5581
|
const useMermaid = (props2) => {
|
|
5584
5582
|
const theme = inject("theme");
|
|
@@ -5725,9 +5723,7 @@ var Content = defineComponent({
|
|
|
5725
5723
|
html
|
|
5726
5724
|
} = useMarked(props2, mermaidData);
|
|
5727
5725
|
useAutoScroll(props2, html, textAreaRef, previewRef, htmlRef);
|
|
5728
|
-
|
|
5729
|
-
selectedText
|
|
5730
|
-
} = useAutoGenrator(props2, textAreaRef);
|
|
5726
|
+
useAutoGenrator(props2, textAreaRef);
|
|
5731
5727
|
useHistory(props2, textAreaRef, completeStatus);
|
|
5732
5728
|
usePasteUpload(textAreaRef);
|
|
5733
5729
|
userZoom(html);
|
|
@@ -5744,7 +5740,6 @@ var Content = defineComponent({
|
|
|
5744
5740
|
completeStatus.value = false;
|
|
5745
5741
|
},
|
|
5746
5742
|
"onInput": (e) => {
|
|
5747
|
-
selectedText.value = "";
|
|
5748
5743
|
props2.onChange(e.target.value);
|
|
5749
5744
|
},
|
|
5750
5745
|
"onCompositionend": () => {
|