md-editor-v3 2.0.0-beta.8 → 2.0.0-beta.9

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 CHANGED
@@ -183,7 +183,8 @@ export interface StaticTextDefaultValue {
183
183
  // Copy code tips, v1.1.4
184
184
  copyCode?: {
185
185
  text?: string;
186
- tips?: string;
186
+ successTips?: string;
187
+ failTips?: string;
187
188
  };
188
189
  // 1.8.0
189
190
  mermaid?: {
@@ -216,7 +217,7 @@ export interface StaticTextDefaultValue {
216
217
 
217
218
  `NormalToolbar` component example:
218
219
 
219
- ```js
220
+ ```vue
220
221
  <template>
221
222
  <md-editor>
222
223
  <template #defToolbars>
@@ -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 = () => { console.log('NormalToolbar clicked!') }
240
+ const handler = () => {
241
+ console.log('NormalToolbar clicked!');
242
+ };
239
243
  </script>
240
244
  ```
241
245
 
@@ -300,12 +304,14 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
300
304
  import MdEditor from 'md-editor-v3';
301
305
 
302
306
  MdEditor.config({
303
- markedOptions: {
304
- languageUserDefined: { 'lang': StaticTextDefaultValue };
307
+ editorConfig: {
308
+ languageUserDefined: { lang: StaticTextDefaultValue },
305
309
  mermaidTemplate: {
306
- flow: `flow tempalte`;
310
+ flow: `flow tempalte`,
307
311
  ...more
308
- };
312
+ },
313
+ // ms
314
+ renderDelay: 500
309
315
  }
310
316
  });
311
317
  ```
@@ -492,9 +498,9 @@ export default defineComponent({
492
498
 
493
499
  ### Vue template
494
500
 
495
- ```js
501
+ ```vue
496
502
  <template>
497
- <md-editor v-model="text" pageFullScreen></md-editor>
503
+ <md-editor v-model="text" preview-only />
498
504
  </template>
499
505
 
500
506
  <script setup>
@@ -502,7 +508,7 @@ import { ref } from 'vue';
502
508
  import MdEditor from 'md-editor-v3';
503
509
  import 'md-editor-v3/lib/style.css';
504
510
 
505
- const text = ref('# Hello Editor')
511
+ const text = ref('# Hello Editor');
506
512
  </script>
507
513
  ```
508
514
 
@@ -510,8 +516,18 @@ const text = ref('# Hello Editor')
510
516
 
511
517
  > Tips:When you paste and upload GIF, it will upload a static picture. So you should upload it by file system!
512
518
 
513
- ```js
514
- async onUploadImg(files: Array<File>, callback: (urls: string[]) => void) {
519
+ <template>
520
+ <md-editor v-model="text" @onUploadImg="onUploadImg" />
521
+ </template>
522
+
523
+ <script setup>
524
+ import { ref } from 'vue';
525
+ import MdEditor from 'md-editor-v3';
526
+ import 'md-editor-v3/lib/style.css';
527
+
528
+ const text = ref('# Hello Editor');
529
+
530
+ const onUploadImg = async (files, callback) => {
515
531
  const res = await Promise.all(
516
532
  files.map((file) => {
517
533
  return new Promise((rev, rej) => {
@@ -530,6 +546,6 @@ async onUploadImg(files: Array<File>, callback: (urls: string[]) => void) {
530
546
  })
531
547
  );
532
548
 
533
- callback(res.map((item: any) => item.data.url));
534
- }
535
- ```
549
+ callback(res.map((item) => item.data.url));
550
+ };
551
+ </script>
@@ -70,7 +70,8 @@ export interface StaticTextDefaultValue {
70
70
  };
71
71
  copyCode?: {
72
72
  text?: string;
73
- tips?: string;
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
  /**
@@ -121,7 +121,8 @@ const staticTextDefault = {
121
121
  },
122
122
  copyCode: {
123
123
  text: "\u590D\u5236\u4EE3\u7801",
124
- tips: "\u5DF2\u590D\u5236\uFF01"
124
+ successTips: "\u5DF2\u590D\u5236\uFF01",
125
+ failTips: "\u590D\u5236\u5931\u8D25\uFF01"
125
126
  },
126
127
  mermaid: {
127
128
  flow: "\u6D41\u7A0B\u56FE",
@@ -195,7 +196,8 @@ const staticTextDefault = {
195
196
  },
196
197
  copyCode: {
197
198
  text: "Copy",
198
- tips: "Copied!"
199
+ successTips: "Copied!",
200
+ failTips: "Copy failed!"
199
201
  },
200
202
  mermaid: {
201
203
  flow: "flow",
@@ -5202,7 +5204,7 @@ var kaTexExtensions = {
5202
5204
  };
5203
5205
  }
5204
5206
  };
5205
- const useHistory = (props2, textAreaRef) => {
5207
+ const useHistory = (props2, textAreaRef, completeStatus) => {
5206
5208
  var _a, _b;
5207
5209
  const previewOnly = inject("previewOnly");
5208
5210
  const historyLength = inject("historyLength");
@@ -5222,6 +5224,7 @@ const useHistory = (props2, textAreaRef) => {
5222
5224
  userUpdated: true,
5223
5225
  curr: 0
5224
5226
  };
5227
+ let historyPos = [0, 0];
5225
5228
  const keyZCallback = (curr) => {
5226
5229
  var _a2, _b2;
5227
5230
  const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
@@ -5234,41 +5237,48 @@ const useHistory = (props2, textAreaRef) => {
5234
5237
  props2.onChange(currHistory.content);
5235
5238
  setPosition(textAreaRef.value, currHistory.startPos, currHistory.endPos);
5236
5239
  };
5237
- onMounted(() => {
5238
- bus.on(editorId, {
5239
- name: "saveHistory",
5240
- callback(content) {
5241
- var _a2, _b2;
5242
- clearTimeout(saveHistoryId);
5243
- const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
5244
- const endPos = ((_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd) || 0;
5245
- saveHistoryId = setTimeout(() => {
5246
- if (history.userUpdated) {
5247
- if (history.curr < history.list.length - 1) {
5248
- history.list = history.list.slice(0, history.curr + 1);
5249
- }
5250
- if (history.list.length > historyLength) {
5251
- history.list.shift();
5252
- }
5253
- const lastStep = history.list.pop() || {
5254
- startPos: 0,
5255
- endPos: 0,
5256
- content
5257
- };
5258
- lastStep.startPos = startPos;
5259
- lastStep.endPos = endPos;
5260
- Array.prototype.push.call(history.list, lastStep, {
5261
- content,
5262
- startPos,
5263
- endPos
5264
- });
5265
- history.curr = history.list.length - 1;
5266
- } else {
5267
- history.userUpdated = true;
5268
- }
5269
- }, 150);
5240
+ const saveHistory = (content) => {
5241
+ var _a2, _b2;
5242
+ clearTimeout(saveHistoryId);
5243
+ const startPos = ((_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart) || 0;
5244
+ const endPos = ((_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd) || 0;
5245
+ saveHistoryId = setTimeout(() => {
5246
+ if (history.userUpdated) {
5247
+ if (history.curr < history.list.length - 1) {
5248
+ history.list = history.list.slice(0, history.curr + 1);
5249
+ }
5250
+ if (history.list.length > historyLength) {
5251
+ history.list.shift();
5252
+ }
5253
+ const lastStep = history.list.pop() || {
5254
+ startPos: 0,
5255
+ endPos: 0,
5256
+ content
5257
+ };
5258
+ lastStep.startPos = historyPos[0];
5259
+ lastStep.endPos = historyPos[1];
5260
+ Array.prototype.push.call(history.list, lastStep, {
5261
+ content,
5262
+ startPos,
5263
+ endPos
5264
+ });
5265
+ history.curr = history.list.length - 1;
5266
+ } else {
5267
+ history.userUpdated = true;
5270
5268
  }
5271
- });
5269
+ }, 150);
5270
+ };
5271
+ const saveHistoryPos = () => {
5272
+ var _a2, _b2;
5273
+ historyPos = [(_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart, (_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd];
5274
+ };
5275
+ watch(() => props2.value, (val) => {
5276
+ if (completeStatus.value) {
5277
+ saveHistory(val);
5278
+ }
5279
+ });
5280
+ watch(() => completeStatus.value, () => {
5281
+ saveHistory(props2.value);
5272
5282
  });
5273
5283
  onMounted(() => {
5274
5284
  bus.on(editorId, {
@@ -5283,11 +5293,19 @@ const useHistory = (props2, textAreaRef) => {
5283
5293
  keyZCallback(history.curr + 1 === history.list.length ? history.curr : history.curr + 1);
5284
5294
  }
5285
5295
  });
5296
+ textAreaRef.value.addEventListener("keydown", saveHistoryPos);
5297
+ textAreaRef.value.addEventListener("click", saveHistoryPos);
5286
5298
  });
5287
5299
  };
5288
5300
  const useMarked = (props2, mermaidData) => {
5289
5301
  var _a, _b, _c;
5290
- const { markedRenderer, markedExtensions, markedOptions, editorExtensions } = inject("extension");
5302
+ const {
5303
+ markedRenderer,
5304
+ markedExtensions,
5305
+ markedOptions,
5306
+ editorExtensions,
5307
+ editorConfig
5308
+ } = inject("extension");
5291
5309
  const showCodeRowNumber = inject("showCodeRowNumber");
5292
5310
  const editorId = inject("editorId");
5293
5311
  const highlightUrl2 = inject("highlight");
@@ -5385,7 +5403,7 @@ const useMarked = (props2, mermaidData) => {
5385
5403
  const _html = props2.sanitize(marked(props2.value || "", { renderer }));
5386
5404
  html.value = _html;
5387
5405
  props2.onHtmlChanged(_html);
5388
- }, 500);
5406
+ }, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : 500);
5389
5407
  watch([
5390
5408
  highlightInited,
5391
5409
  toRef(mermaidData, "reRender"),
@@ -5460,16 +5478,18 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
5460
5478
  const initCopyEntry = () => {
5461
5479
  document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
5462
5480
  var _a;
5481
+ const copyBtnText = ((_a = ult.value.copyCode) == null ? void 0 : _a.text) || "\u590D\u5236\u4EE3\u7801";
5463
5482
  const copyButton = document.createElement("span");
5464
5483
  copyButton.setAttribute("class", "copy-button");
5465
- copyButton.innerText = ((_a = ult.value.copyCode) == null ? void 0 : _a.text) || "\u590D\u5236\u4EE3\u7801";
5484
+ copyButton.innerText = copyBtnText;
5466
5485
  copyButton.addEventListener("click", () => {
5467
- var _a2;
5468
- copyToClipboard(pre.querySelector("code").innerText);
5469
- copyButton.innerText = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.tips) || "\u5DF2\u590D\u5236\uFF01";
5486
+ var _a2, _b;
5487
+ const success = copyToClipboard(pre.querySelector("code").innerText);
5488
+ const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "\u5DF2\u590D\u5236\uFF01";
5489
+ const failTip = ((_b = ult.value.copyCode) == null ? void 0 : _b.failTips) || "\u5DF2\u590D\u5236\uFF01";
5490
+ copyButton.innerText = success ? succssTip : failTip;
5470
5491
  setTimeout(() => {
5471
- var _a3;
5472
- copyButton.innerText = ((_a3 = ult.value.copyCode) == null ? void 0 : _a3.text) || "\u590D\u5236\u4EE3\u7801";
5492
+ copyButton.innerText = copyBtnText;
5473
5493
  }, 1500);
5474
5494
  });
5475
5495
  pre.appendChild(copyButton);
@@ -5708,7 +5728,7 @@ var Content = defineComponent({
5708
5728
  const {
5709
5729
  selectedText
5710
5730
  } = useAutoGenrator(props2, textAreaRef);
5711
- useHistory(props2, textAreaRef);
5731
+ useHistory(props2, textAreaRef, completeStatus);
5712
5732
  usePasteUpload(textAreaRef);
5713
5733
  userZoom(html);
5714
5734
  return () => {
@@ -5725,10 +5745,9 @@ var Content = defineComponent({
5725
5745
  },
5726
5746
  "onInput": (e) => {
5727
5747
  selectedText.value = "";
5728
- props2.onChange(e.target.value, completeStatus.value);
5748
+ props2.onChange(e.target.value);
5729
5749
  },
5730
- "onCompositionend": (e) => {
5731
- bus.emit(editorId, "saveHistory", e.target.value);
5750
+ "onCompositionend": () => {
5732
5751
  completeStatus.value = true;
5733
5752
  },
5734
5753
  "class": [props2.setting.preview || props2.setting.htmlPreview ? "" : "textarea-only"],
@@ -6117,10 +6136,7 @@ const Editor = defineComponent({
6117
6136
  "defToolbars": defToolbars
6118
6137
  }, null), createVNode(Content, {
6119
6138
  "value": props2.modelValue,
6120
- "onChange": (value, completeStatus = true) => {
6121
- if (completeStatus) {
6122
- bus.emit(editorId, "saveHistory", value);
6123
- }
6139
+ "onChange": (value) => {
6124
6140
  if (props2.onChange) {
6125
6141
  props2.onChange(value);
6126
6142
  } else {