md-editor-v3 2.0.0-beta.7 → 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 +88 -32
- package/lib/MdEditor/type.d.ts +6 -1
- package/lib/md-editor-v3.es.js +110 -95
- package/lib/md-editor-v3.umd.js +35 -35
- 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 {
|
|
@@ -183,7 +183,8 @@ export interface StaticTextDefaultValue {
|
|
|
183
183
|
// Copy code tips, v1.1.4
|
|
184
184
|
copyCode?: {
|
|
185
185
|
text?: string;
|
|
186
|
-
|
|
186
|
+
successTips?: string;
|
|
187
|
+
failTips?: string;
|
|
187
188
|
};
|
|
188
189
|
// 1.8.0
|
|
189
190
|
mermaid?: {
|
|
@@ -212,15 +213,15 @@ export interface StaticTextDefaultValue {
|
|
|
212
213
|
|
|
213
214
|
| name | type | default | description |
|
|
214
215
|
| --- | --- | --- | --- |
|
|
215
|
-
| defToolbars | Array<DropdownToolbar \| NormalToolbar \| ModalToolbar> | null |
|
|
216
|
+
| defToolbars | Array<DropdownToolbar \| NormalToolbar \| ModalToolbar> | null | Custom toolbar in `DropdownToolbar`, `NormalToolbar` or `ModalToolbar` |
|
|
216
217
|
|
|
217
|
-
`NormalToolbar`
|
|
218
|
+
`NormalToolbar` example:
|
|
218
219
|
|
|
219
|
-
```
|
|
220
|
+
```vue
|
|
220
221
|
<template>
|
|
221
222
|
<md-editor>
|
|
222
223
|
<template #defToolbars>
|
|
223
|
-
<normal-toolbar title="mark" @
|
|
224
|
+
<normal-toolbar title="mark" @onClick="handler">
|
|
224
225
|
<template #trigger>
|
|
225
226
|
<svg class="md-icon" aria-hidden="true">
|
|
226
227
|
<use xlink:href="#icon-mark"></use>
|
|
@@ -230,12 +231,15 @@ export interface StaticTextDefaultValue {
|
|
|
230
231
|
</template>
|
|
231
232
|
</md-editor>
|
|
232
233
|
</template>
|
|
234
|
+
|
|
233
235
|
<script setup>
|
|
234
236
|
import MdEditor from 'md-editor-v3';
|
|
235
237
|
|
|
236
238
|
const NormalToolbar = MdEditor.NormalToolbar;
|
|
237
239
|
|
|
238
|
-
const handler = () => {
|
|
240
|
+
const handler = () => {
|
|
241
|
+
console.log('NormalToolbar clicked!');
|
|
242
|
+
};
|
|
239
243
|
</script>
|
|
240
244
|
```
|
|
241
245
|
|
|
@@ -254,7 +258,9 @@ const handler = () => { console.log('NormalToolbar clicked!') }
|
|
|
254
258
|
|
|
255
259
|
Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
256
260
|
|
|
257
|
-
- markedRenderer: `(renderer: Renderer) => Renderer
|
|
261
|
+
- markedRenderer: `(renderer: Renderer) => Renderer`
|
|
262
|
+
|
|
263
|
+
Open target page in a new browser window:
|
|
258
264
|
|
|
259
265
|
```js
|
|
260
266
|
MdEditor.config({
|
|
@@ -282,7 +288,9 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
|
282
288
|
|
|
283
289
|
> Reference: https://marked.js.org/using_pro#extensions
|
|
284
290
|
|
|
285
|
-
- markedOptions: `marked.MarkedOptions
|
|
291
|
+
- markedOptions: `marked.MarkedOptions`
|
|
292
|
+
|
|
293
|
+
Do not render `<br>` on a single line break:
|
|
286
294
|
|
|
287
295
|
```js
|
|
288
296
|
import MdEditor from 'md-editor-v3';
|
|
@@ -294,18 +302,20 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
|
294
302
|
|
|
295
303
|
> Reference: https://marked.js.org/using_advanced#options
|
|
296
304
|
|
|
297
|
-
- editorConfig: Add more languages
|
|
305
|
+
- editorConfig: Add more languages, reset `mermaid` template or delay rendering time:
|
|
298
306
|
|
|
299
307
|
```js
|
|
300
308
|
import MdEditor from 'md-editor-v3';
|
|
301
309
|
|
|
302
310
|
MdEditor.config({
|
|
303
|
-
|
|
304
|
-
languageUserDefined: {
|
|
311
|
+
editorConfig: {
|
|
312
|
+
languageUserDefined: { lang: StaticTextDefaultValue },
|
|
305
313
|
mermaidTemplate: {
|
|
306
|
-
flow: `flow tempalte
|
|
314
|
+
flow: `flow tempalte`,
|
|
307
315
|
...more
|
|
308
|
-
}
|
|
316
|
+
},
|
|
317
|
+
// ms
|
|
318
|
+
renderDelay: 500
|
|
309
319
|
}
|
|
310
320
|
});
|
|
311
321
|
```
|
|
@@ -365,7 +375,7 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
|
|
|
365
375
|
|
|
366
376
|
</details>
|
|
367
377
|
|
|
368
|
-
## Shortcut
|
|
378
|
+
## Shortcut Key
|
|
369
379
|
|
|
370
380
|
| key | function | description |
|
|
371
381
|
| --- | --- | --- |
|
|
@@ -442,22 +452,22 @@ They are used as attributes of the editor component, eg: `Editor.DropdownToolbar
|
|
|
442
452
|
- `modalTitle`: `string`, not necessary, title of the Modal.
|
|
443
453
|
- `visible`: `boolean`, necessary, visibility of Modal.
|
|
444
454
|
- `width`: `string`, not necessary, width of Modal, default `auto`.
|
|
445
|
-
- `height
|
|
455
|
+
- `height`: `string`, same as `width`.
|
|
446
456
|
- `showAdjust`: `boolean`, not necessary, visibility of fullscreen button.
|
|
447
457
|
- `isFullscreen`: `boolean`, necessary when `showAdjust = true`, status of fullscreen.
|
|
448
458
|
|
|
449
459
|
- **events**
|
|
450
460
|
|
|
451
461
|
- `onClick`: `() => void`, necessary.
|
|
452
|
-
- `onClose
|
|
453
|
-
- `onAdjust
|
|
462
|
+
- `onClose`: `() => void`, necessary, close event.
|
|
463
|
+
- `onAdjust`: `(val: boolean) => void`, fullscreen button click event.
|
|
454
464
|
|
|
455
465
|
- **slots**
|
|
456
466
|
|
|
457
467
|
- `trigger`: `string | JSX.Element`, necessary, it is usually an icon, which is displayed on the toolbar.
|
|
458
468
|
- `overlay`: `string | JSX.Element`, necessary, content of Modal.
|
|
459
469
|
|
|
460
|
-
###
|
|
470
|
+
### MdCatalog
|
|
461
471
|
|
|
462
472
|
`Editor.MdCatalog`
|
|
463
473
|
|
|
@@ -471,7 +481,7 @@ They are used as attributes of the editor component, eg: `Editor.DropdownToolbar
|
|
|
471
481
|
|
|
472
482
|
## Examples
|
|
473
483
|
|
|
474
|
-
### Jsx
|
|
484
|
+
### Jsx Template
|
|
475
485
|
|
|
476
486
|
```js
|
|
477
487
|
import { defineComponent, reactive } from 'vue';
|
|
@@ -490,11 +500,11 @@ export default defineComponent({
|
|
|
490
500
|
});
|
|
491
501
|
```
|
|
492
502
|
|
|
493
|
-
###
|
|
503
|
+
### Setup Template
|
|
494
504
|
|
|
495
|
-
```
|
|
505
|
+
```vue
|
|
496
506
|
<template>
|
|
497
|
-
<md-editor v-model="text"
|
|
507
|
+
<md-editor v-model="text" preview-only />
|
|
498
508
|
</template>
|
|
499
509
|
|
|
500
510
|
<script setup>
|
|
@@ -502,16 +512,26 @@ import { ref } from 'vue';
|
|
|
502
512
|
import MdEditor from 'md-editor-v3';
|
|
503
513
|
import 'md-editor-v3/lib/style.css';
|
|
504
514
|
|
|
505
|
-
const text = ref('# Hello Editor')
|
|
515
|
+
const text = ref('# Hello Editor');
|
|
506
516
|
</script>
|
|
507
517
|
```
|
|
508
518
|
|
|
509
519
|
### Upload picture
|
|
510
520
|
|
|
511
|
-
> Tips
|
|
521
|
+
> Tips: When you paste and upload GIF, it will upload a static picture. So you should upload it by file system!
|
|
512
522
|
|
|
513
|
-
|
|
514
|
-
|
|
523
|
+
<template>
|
|
524
|
+
<md-editor v-model="text" @onUploadImg="onUploadImg" />
|
|
525
|
+
</template>
|
|
526
|
+
|
|
527
|
+
<script setup>
|
|
528
|
+
import { ref } from 'vue';
|
|
529
|
+
import MdEditor from 'md-editor-v3';
|
|
530
|
+
import 'md-editor-v3/lib/style.css';
|
|
531
|
+
|
|
532
|
+
const text = ref('# Hello Editor');
|
|
533
|
+
|
|
534
|
+
const onUploadImg = async (files, callback) => {
|
|
515
535
|
const res = await Promise.all(
|
|
516
536
|
files.map((file) => {
|
|
517
537
|
return new Promise((rev, rej) => {
|
|
@@ -530,6 +550,42 @@ async onUploadImg(files: Array<File>, callback: (urls: string[]) => void) {
|
|
|
530
550
|
})
|
|
531
551
|
);
|
|
532
552
|
|
|
533
|
-
callback(res.map((item
|
|
553
|
+
callback(res.map((item) => item.data.url));
|
|
554
|
+
};
|
|
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;
|
|
534
590
|
}
|
|
535
591
|
```
|
package/lib/MdEditor/type.d.ts
CHANGED
|
@@ -70,7 +70,8 @@ export interface StaticTextDefaultValue {
|
|
|
70
70
|
};
|
|
71
71
|
copyCode?: {
|
|
72
72
|
text?: string;
|
|
73
|
-
|
|
73
|
+
successTips?: string;
|
|
74
|
+
failTips?: string;
|
|
74
75
|
};
|
|
75
76
|
mermaid?: {
|
|
76
77
|
flow?: string;
|
|
@@ -200,6 +201,10 @@ export interface ConfigOption {
|
|
|
200
201
|
* 自定义内部mermaid模块
|
|
201
202
|
*/
|
|
202
203
|
mermaidTemplate?: MermaidTemplate;
|
|
204
|
+
/**
|
|
205
|
+
* 输入渲染延迟(ms)
|
|
206
|
+
*/
|
|
207
|
+
renderDelay?: number;
|
|
203
208
|
};
|
|
204
209
|
}
|
|
205
210
|
/**
|
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",
|
|
@@ -121,7 +122,8 @@ const staticTextDefault = {
|
|
|
121
122
|
},
|
|
122
123
|
copyCode: {
|
|
123
124
|
text: "\u590D\u5236\u4EE3\u7801",
|
|
124
|
-
|
|
125
|
+
successTips: "\u5DF2\u590D\u5236\uFF01",
|
|
126
|
+
failTips: "\u590D\u5236\u5931\u8D25\uFF01"
|
|
125
127
|
},
|
|
126
128
|
mermaid: {
|
|
127
129
|
flow: "\u6D41\u7A0B\u56FE",
|
|
@@ -195,7 +197,8 @@ const staticTextDefault = {
|
|
|
195
197
|
},
|
|
196
198
|
copyCode: {
|
|
197
199
|
text: "Copy",
|
|
198
|
-
|
|
200
|
+
successTips: "Copied!",
|
|
201
|
+
failTips: "Copy failed!"
|
|
199
202
|
},
|
|
200
203
|
mermaid: {
|
|
201
204
|
flow: "flow",
|
|
@@ -213,43 +216,43 @@ const staticTextDefault = {
|
|
|
213
216
|
}
|
|
214
217
|
}
|
|
215
218
|
};
|
|
216
|
-
const mermaidUrl =
|
|
219
|
+
const mermaidUrl = `${cdnBase}/mermaid/8.13.5/mermaid.min.js`;
|
|
217
220
|
const katexUrl = {
|
|
218
|
-
js:
|
|
219
|
-
css:
|
|
221
|
+
js: `${cdnBase}/KaTeX/0.15.1/katex.min.js`,
|
|
222
|
+
css: `${cdnBase}/KaTeX/0.15.1/katex.min.css`
|
|
220
223
|
};
|
|
221
224
|
const codeCss = {
|
|
222
225
|
a11y: {
|
|
223
|
-
light:
|
|
224
|
-
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`
|
|
225
228
|
},
|
|
226
229
|
atom: {
|
|
227
|
-
light:
|
|
228
|
-
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`
|
|
229
232
|
},
|
|
230
233
|
github: {
|
|
231
|
-
light:
|
|
232
|
-
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`
|
|
233
236
|
},
|
|
234
237
|
gradient: {
|
|
235
|
-
light:
|
|
236
|
-
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`
|
|
237
240
|
},
|
|
238
241
|
kimbie: {
|
|
239
|
-
light:
|
|
240
|
-
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`
|
|
241
244
|
},
|
|
242
245
|
paraiso: {
|
|
243
|
-
light:
|
|
244
|
-
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`
|
|
245
248
|
},
|
|
246
249
|
qtcreator: {
|
|
247
|
-
light:
|
|
248
|
-
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`
|
|
249
252
|
},
|
|
250
253
|
stackoverflow: {
|
|
251
|
-
light:
|
|
252
|
-
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`
|
|
253
256
|
}
|
|
254
257
|
};
|
|
255
258
|
class Bus {
|
|
@@ -5202,7 +5205,7 @@ var kaTexExtensions = {
|
|
|
5202
5205
|
};
|
|
5203
5206
|
}
|
|
5204
5207
|
};
|
|
5205
|
-
const useHistory = (props2, textAreaRef) => {
|
|
5208
|
+
const useHistory = (props2, textAreaRef, completeStatus) => {
|
|
5206
5209
|
var _a, _b;
|
|
5207
5210
|
const previewOnly = inject("previewOnly");
|
|
5208
5211
|
const historyLength = inject("historyLength");
|
|
@@ -5222,68 +5225,85 @@ const useHistory = (props2, textAreaRef) => {
|
|
|
5222
5225
|
userUpdated: true,
|
|
5223
5226
|
curr: 0
|
|
5224
5227
|
};
|
|
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
|
-
|
|
5228
|
+
let historyPos = [0, 0];
|
|
5229
|
+
const keyZCallback = (curr) => {
|
|
5230
|
+
var _a2, _b2;
|
|
5231
|
+
const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
|
|
5232
|
+
const endPos = ((_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd) || 0;
|
|
5233
|
+
history.list[history.curr].startPos = startPos;
|
|
5234
|
+
history.list[history.curr].endPos = endPos;
|
|
5235
|
+
history.userUpdated = false;
|
|
5236
|
+
history.curr = curr;
|
|
5237
|
+
const currHistory = history.list[history.curr];
|
|
5238
|
+
props2.onChange(currHistory.content);
|
|
5239
|
+
setPosition(textAreaRef.value, currHistory.startPos, currHistory.endPos);
|
|
5240
|
+
};
|
|
5241
|
+
const saveHistory = (content) => {
|
|
5242
|
+
var _a2, _b2;
|
|
5243
|
+
clearTimeout(saveHistoryId);
|
|
5244
|
+
const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
|
|
5245
|
+
const endPos = ((_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd) || 0;
|
|
5246
|
+
saveHistoryId = setTimeout(() => {
|
|
5247
|
+
if (history.userUpdated) {
|
|
5248
|
+
if (history.curr < history.list.length - 1) {
|
|
5249
|
+
history.list = history.list.slice(0, history.curr + 1);
|
|
5250
|
+
}
|
|
5251
|
+
if (history.list.length > historyLength) {
|
|
5252
|
+
history.list.shift();
|
|
5253
|
+
}
|
|
5254
|
+
const lastStep = history.list.pop() || {
|
|
5255
|
+
startPos: 0,
|
|
5256
|
+
endPos: 0,
|
|
5257
|
+
content
|
|
5258
|
+
};
|
|
5259
|
+
lastStep.startPos = historyPos[0];
|
|
5260
|
+
lastStep.endPos = historyPos[1];
|
|
5261
|
+
Array.prototype.push.call(history.list, lastStep, {
|
|
5262
|
+
content,
|
|
5263
|
+
startPos,
|
|
5264
|
+
endPos
|
|
5265
|
+
});
|
|
5266
|
+
history.curr = history.list.length - 1;
|
|
5267
|
+
saveHistoryPos();
|
|
5268
|
+
} else {
|
|
5269
|
+
history.userUpdated = true;
|
|
5258
5270
|
}
|
|
5259
|
-
});
|
|
5271
|
+
}, 150);
|
|
5272
|
+
};
|
|
5273
|
+
const saveHistoryPos = () => {
|
|
5274
|
+
var _a2, _b2;
|
|
5275
|
+
historyPos = [(_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart, (_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd];
|
|
5276
|
+
};
|
|
5277
|
+
watch([toRef(props2, "value"), completeStatus], () => {
|
|
5278
|
+
if (completeStatus.value) {
|
|
5279
|
+
saveHistory(props2.value);
|
|
5280
|
+
}
|
|
5260
5281
|
});
|
|
5261
5282
|
onMounted(() => {
|
|
5262
5283
|
bus.on(editorId, {
|
|
5263
5284
|
name: "ctrlZ",
|
|
5264
5285
|
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);
|
|
5286
|
+
keyZCallback(history.curr - 1 < 0 ? 0 : history.curr - 1);
|
|
5270
5287
|
}
|
|
5271
5288
|
});
|
|
5272
5289
|
bus.on(editorId, {
|
|
5273
5290
|
name: "ctrlShiftZ",
|
|
5274
5291
|
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);
|
|
5292
|
+
keyZCallback(history.curr + 1 === history.list.length ? history.curr : history.curr + 1);
|
|
5280
5293
|
}
|
|
5281
5294
|
});
|
|
5295
|
+
textAreaRef.value.addEventListener("click", saveHistoryPos);
|
|
5282
5296
|
});
|
|
5283
5297
|
};
|
|
5284
5298
|
const useMarked = (props2, mermaidData) => {
|
|
5285
5299
|
var _a, _b, _c;
|
|
5286
|
-
const {
|
|
5300
|
+
const {
|
|
5301
|
+
markedRenderer,
|
|
5302
|
+
markedExtensions,
|
|
5303
|
+
markedOptions,
|
|
5304
|
+
editorExtensions,
|
|
5305
|
+
editorConfig
|
|
5306
|
+
} = inject("extension");
|
|
5287
5307
|
const showCodeRowNumber = inject("showCodeRowNumber");
|
|
5288
5308
|
const editorId = inject("editorId");
|
|
5289
5309
|
const highlightUrl2 = inject("highlight");
|
|
@@ -5381,7 +5401,7 @@ const useMarked = (props2, mermaidData) => {
|
|
|
5381
5401
|
const _html = props2.sanitize(marked(props2.value || "", { renderer }));
|
|
5382
5402
|
html.value = _html;
|
|
5383
5403
|
props2.onHtmlChanged(_html);
|
|
5384
|
-
}, 500);
|
|
5404
|
+
}, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : 500);
|
|
5385
5405
|
watch([
|
|
5386
5406
|
highlightInited,
|
|
5387
5407
|
toRef(mermaidData, "reRender"),
|
|
@@ -5456,16 +5476,18 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
|
|
|
5456
5476
|
const initCopyEntry = () => {
|
|
5457
5477
|
document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
|
|
5458
5478
|
var _a;
|
|
5479
|
+
const copyBtnText = ((_a = ult.value.copyCode) == null ? void 0 : _a.text) || "\u590D\u5236\u4EE3\u7801";
|
|
5459
5480
|
const copyButton = document.createElement("span");
|
|
5460
5481
|
copyButton.setAttribute("class", "copy-button");
|
|
5461
|
-
copyButton.innerText =
|
|
5482
|
+
copyButton.innerText = copyBtnText;
|
|
5462
5483
|
copyButton.addEventListener("click", () => {
|
|
5463
|
-
var _a2;
|
|
5464
|
-
copyToClipboard(pre.querySelector("code").innerText);
|
|
5465
|
-
|
|
5484
|
+
var _a2, _b;
|
|
5485
|
+
const success = copyToClipboard(pre.querySelector("code").innerText);
|
|
5486
|
+
const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "\u5DF2\u590D\u5236\uFF01";
|
|
5487
|
+
const failTip = ((_b = ult.value.copyCode) == null ? void 0 : _b.failTips) || "\u5DF2\u590D\u5236\uFF01";
|
|
5488
|
+
copyButton.innerText = success ? succssTip : failTip;
|
|
5466
5489
|
setTimeout(() => {
|
|
5467
|
-
|
|
5468
|
-
copyButton.innerText = ((_a3 = ult.value.copyCode) == null ? void 0 : _a3.text) || "\u590D\u5236\u4EE3\u7801";
|
|
5490
|
+
copyButton.innerText = copyBtnText;
|
|
5469
5491
|
}, 1500);
|
|
5470
5492
|
});
|
|
5471
5493
|
pre.appendChild(copyButton);
|
|
@@ -5546,15 +5568,15 @@ ${nextOrder}. `, {}));
|
|
|
5546
5568
|
});
|
|
5547
5569
|
}
|
|
5548
5570
|
});
|
|
5571
|
+
watch(() => props2.value, () => {
|
|
5572
|
+
selectedText.value = "";
|
|
5573
|
+
});
|
|
5549
5574
|
bus.on(editorId, {
|
|
5550
5575
|
name: "selectTextChange",
|
|
5551
5576
|
callback() {
|
|
5552
5577
|
selectedText.value = getSelectionText(textAreaRef.value);
|
|
5553
5578
|
}
|
|
5554
5579
|
});
|
|
5555
|
-
return {
|
|
5556
|
-
selectedText
|
|
5557
|
-
};
|
|
5558
5580
|
};
|
|
5559
5581
|
const useMermaid = (props2) => {
|
|
5560
5582
|
const theme = inject("theme");
|
|
@@ -5701,10 +5723,8 @@ var Content = defineComponent({
|
|
|
5701
5723
|
html
|
|
5702
5724
|
} = useMarked(props2, mermaidData);
|
|
5703
5725
|
useAutoScroll(props2, html, textAreaRef, previewRef, htmlRef);
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
} = useAutoGenrator(props2, textAreaRef);
|
|
5707
|
-
useHistory(props2, textAreaRef);
|
|
5726
|
+
useAutoGenrator(props2, textAreaRef);
|
|
5727
|
+
useHistory(props2, textAreaRef, completeStatus);
|
|
5708
5728
|
usePasteUpload(textAreaRef);
|
|
5709
5729
|
userZoom(html);
|
|
5710
5730
|
return () => {
|
|
@@ -5720,11 +5740,9 @@ var Content = defineComponent({
|
|
|
5720
5740
|
completeStatus.value = false;
|
|
5721
5741
|
},
|
|
5722
5742
|
"onInput": (e) => {
|
|
5723
|
-
|
|
5724
|
-
props2.onChange(e.target.value, completeStatus.value);
|
|
5743
|
+
props2.onChange(e.target.value);
|
|
5725
5744
|
},
|
|
5726
|
-
"onCompositionend": (
|
|
5727
|
-
bus.emit(editorId, "saveHistory", e.target.value);
|
|
5745
|
+
"onCompositionend": () => {
|
|
5728
5746
|
completeStatus.value = true;
|
|
5729
5747
|
},
|
|
5730
5748
|
"class": [props2.setting.preview || props2.setting.htmlPreview ? "" : "textarea-only"],
|
|
@@ -6113,10 +6131,7 @@ const Editor = defineComponent({
|
|
|
6113
6131
|
"defToolbars": defToolbars
|
|
6114
6132
|
}, null), createVNode(Content, {
|
|
6115
6133
|
"value": props2.modelValue,
|
|
6116
|
-
"onChange": (value
|
|
6117
|
-
if (completeStatus) {
|
|
6118
|
-
bus.emit(editorId, "saveHistory", value);
|
|
6119
|
-
}
|
|
6134
|
+
"onChange": (value) => {
|
|
6120
6135
|
if (props2.onChange) {
|
|
6121
6136
|
props2.onChange(value);
|
|
6122
6137
|
} else {
|