md-editor-v3 2.4.0 → 2.4.2

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![](https://img.shields.io/github/package-json/v/imzbf/md-editor-v3) ![](https://img.shields.io/npm/dm/md-editor-v3) ![](https://img.shields.io/bundlephobia/min/md-editor-v3) ![](https://img.shields.io/github/license/imzbf/md-editor-v3) ![](https://img.shields.io/badge/ssr-%3E1.6.0-brightgreen)
4
4
 
5
- English \| [中文](https://github.com/imzbf/md-editor-v3/blob/dev/README-CN.md)
5
+ English \| [中文](https://github.com/imzbf/md-editor-v3/blob/main/README-CN.md)
6
6
 
7
7
  Markdown editor for vue3, developed in `jsx` and `typescript`.
8
8
 
@@ -292,7 +292,7 @@ const handler = () => {
292
292
  | name | param | description |
293
293
  | --- | --- | --- |
294
294
  | onChange | `value: string` | Content changed event(bind to `oninput` of `textarea`) |
295
- | onSave | `value: string` | Save content event, `ctrl+s`and click button will be triggered also |
295
+ | onSave | `value: string, html: Promise<string>` | Save content event, `ctrl+s`and click button will be triggered also |
296
296
  | onUploadImg | `files: Array<File>, callback: (urls: Array<string>) => void` | Upload picture event, when picture is uploading the modal will not close, please provide right urls to the callback function |
297
297
  | onHtmlChanged | `html: string` | Compile markdown successful event, you can use it to get the html code |
298
298
  | onGetCatalog | `list: Array<HeadList>` | Get catalog of article |
@@ -20,7 +20,7 @@ declare const Editor: import("vue").DefineComponent<{
20
20
  type: import("vue").PropType<(v: string) => void>;
21
21
  };
22
22
  onSave: {
23
- type: import("vue").PropType<(v: string) => void>;
23
+ type: import("vue").PropType<(v: string, h: Promise<string>) => void>;
24
24
  };
25
25
  onUploadImg: {
26
26
  type: import("vue").PropType<(files: File[], callBack: (urls: string[]) => void) => void>;
@@ -159,7 +159,7 @@ declare const Editor: import("vue").DefineComponent<{
159
159
  type: import("vue").PropType<(v: string) => void>;
160
160
  };
161
161
  onSave: {
162
- type: import("vue").PropType<(v: string) => void>;
162
+ type: import("vue").PropType<(v: string, h: Promise<string>) => void>;
163
163
  };
164
164
  onUploadImg: {
165
165
  type: import("vue").PropType<(files: File[], callBack: (urls: string[]) => void) => void>;
@@ -57,7 +57,7 @@ declare const _default: {
57
57
  type: import("vue").PropType<(v: string) => void>;
58
58
  };
59
59
  onSave: {
60
- type: import("vue").PropType<(v: string) => void>;
60
+ type: import("vue").PropType<(v: string, h: Promise<string>) => void>;
61
61
  };
62
62
  onUploadImg: {
63
63
  type: import("vue").PropType<(files: File[], callBack: (urls: string[]) => void) => void>;
@@ -210,7 +210,7 @@ declare const _default: {
210
210
  type: import("vue").PropType<(v: string) => void>;
211
211
  };
212
212
  onSave: {
213
- type: import("vue").PropType<(v: string) => void>;
213
+ type: import("vue").PropType<(v: string, h: Promise<string>) => void>;
214
214
  };
215
215
  onUploadImg: {
216
216
  type: import("vue").PropType<(files: File[], callBack: (urls: string[]) => void) => void>;
@@ -397,7 +397,7 @@ declare const _default: {
397
397
  type: import("vue").PropType<(v: string) => void>;
398
398
  };
399
399
  onSave: {
400
- type: import("vue").PropType<(v: string) => void>;
400
+ type: import("vue").PropType<(v: string, h: Promise<string>) => void>;
401
401
  };
402
402
  onUploadImg: {
403
403
  type: import("vue").PropType<(files: File[], callBack: (urls: string[]) => void) => void>;
@@ -540,7 +540,7 @@ declare const _default: {
540
540
  type: import("vue").PropType<(v: string) => void>;
541
541
  };
542
542
  onSave: {
543
- type: import("vue").PropType<(v: string) => void>;
543
+ type: import("vue").PropType<(v: string, h: Promise<string>) => void>;
544
544
  };
545
545
  onUploadImg: {
546
546
  type: import("vue").PropType<(files: File[], callBack: (urls: string[]) => void) => void>;
@@ -17,7 +17,7 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { onMounted, onBeforeUnmount, provide, computed, reactive, watch, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
20
+ import { reactive, watch, onMounted, onBeforeUnmount, provide, computed, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
21
21
  const prefix = "md-editor";
22
22
  const iconfontUrl = "https://at.alicdn.com/t/c/font_2605852_4cjr7o5jo0f.js";
23
23
  const cdnBase = "https://cdnjs.cloudflare.com/ajax/libs";
@@ -292,7 +292,7 @@ class Bus {
292
292
  const targetRace = this.pools[race];
293
293
  const events = targetRace && this.pools[race][name];
294
294
  if (events) {
295
- this.pools[race][name] = events.filter((item) => item === func);
295
+ this.pools[race][name] = events.filter((item) => item !== func);
296
296
  }
297
297
  }
298
298
  clear(race) {
@@ -561,7 +561,11 @@ const updateHandler = debounce((id, attr, value) => {
561
561
  }
562
562
  }, 10);
563
563
  const useKeyBoard = (props, context) => {
564
- const { editorId, noPrettier } = props;
564
+ const { editorId, noPrettier, previewOnly } = props;
565
+ const state = reactive({
566
+ buildFinished: false,
567
+ html: ""
568
+ });
565
569
  const initFunc = (name) => {
566
570
  var _a, _b;
567
571
  return ((_a = props.toolbars) == null ? void 0 : _a.includes(name)) && !((_b = props.toolbarsExclude) == null ? void 0 : _b.includes(name)) && !noPrettier;
@@ -800,30 +804,54 @@ const useKeyBoard = (props, context) => {
800
804
  }
801
805
  }
802
806
  };
807
+ watch(() => props.modelValue, () => {
808
+ state.buildFinished = false;
809
+ });
803
810
  onMounted(() => {
804
- if (!props.previewOnly) {
811
+ if (!previewOnly) {
805
812
  window.addEventListener("keydown", keyDownHandler);
813
+ bus.on(editorId, {
814
+ name: "buildFinished",
815
+ callback(html) {
816
+ state.buildFinished = true;
817
+ state.html = html;
818
+ }
819
+ });
806
820
  bus.on(editorId, {
807
821
  name: "onSave",
808
822
  callback() {
823
+ const htmlPromise = new Promise((rev) => {
824
+ if (state.buildFinished) {
825
+ rev(state.html);
826
+ } else {
827
+ const buildFinishedCallback = (html) => {
828
+ rev(html);
829
+ bus.remove(editorId, "buildFinished", buildFinishedCallback);
830
+ };
831
+ bus.on(editorId, {
832
+ name: "buildFinished",
833
+ callback: buildFinishedCallback
834
+ });
835
+ }
836
+ });
809
837
  if (props.onSave) {
810
- props.onSave(props.modelValue);
838
+ props.onSave(props.modelValue, htmlPromise);
811
839
  } else {
812
- context.emit("onSave", props.modelValue);
840
+ context.emit("onSave", props.modelValue, htmlPromise);
813
841
  }
814
842
  }
815
843
  });
816
844
  }
817
845
  });
818
846
  onBeforeUnmount(() => {
819
- if (!props.previewOnly) {
847
+ if (!previewOnly) {
820
848
  window.removeEventListener("keydown", keyDownHandler);
821
849
  }
822
850
  });
823
851
  };
824
852
  const useProvide = (props) => {
825
853
  var _a;
826
- const { editorId } = props;
854
+ const { editorId, previewOnly } = props;
827
855
  const highlightConfig = (_a = configOption == null ? void 0 : configOption.editorExtensions) == null ? void 0 : _a.highlight;
828
856
  provide("editorId", editorId);
829
857
  provide("tabWidth", props.tabWidth);
@@ -836,7 +864,7 @@ const useProvide = (props) => {
836
864
  };
837
865
  }));
838
866
  provide("historyLength", props.historyLength);
839
- provide("previewOnly", props.previewOnly);
867
+ provide("previewOnly", previewOnly);
840
868
  provide("showCodeRowNumber", props.showCodeRowNumber);
841
869
  const usedLanguageText = computed(() => {
842
870
  var _a2;
@@ -893,7 +921,7 @@ const useExpansion = (props) => {
893
921
  });
894
922
  };
895
923
  const useConfig = (props, context) => {
896
- const { editorId } = props;
924
+ const { editorId, previewOnly } = props;
897
925
  const setting = reactive({
898
926
  pageFullScreen: props.pageFullScreen,
899
927
  fullscreen: false,
@@ -918,7 +946,7 @@ const useConfig = (props, context) => {
918
946
  };
919
947
  watch(() => [setting.pageFullScreen, setting.fullscreen], adjustBody);
920
948
  onMounted(() => {
921
- if (!props.previewOnly) {
949
+ if (!previewOnly) {
922
950
  bus.on(editorId, {
923
951
  name: "uploadImage",
924
952
  callback(files, cb) {
@@ -1139,6 +1167,9 @@ const modalProps = () => ({
1139
1167
  type: Function,
1140
1168
  default: () => () => {
1141
1169
  }
1170
+ },
1171
+ class: {
1172
+ type: String
1142
1173
  }
1143
1174
  });
1144
1175
  var Modal = defineComponent({
@@ -1224,6 +1255,7 @@ var Modal = defineComponent({
1224
1255
  ctx
1225
1256
  }, "title");
1226
1257
  return createVNode("div", {
1258
+ "class": [props.class],
1227
1259
  "style": {
1228
1260
  display: modalVisible.value ? "block" : "none"
1229
1261
  }
@@ -1467,6 +1499,7 @@ var ClipModal = defineComponent({
1467
1499
  return () => {
1468
1500
  var _a2;
1469
1501
  return createVNode(Modal, {
1502
+ "class": `${prefix}-modal-clip`,
1470
1503
  "title": (_a2 = ult.value.clipModalTips) == null ? void 0 : _a2.title,
1471
1504
  "visible": props.visible,
1472
1505
  "onClose": props.onCancel,
@@ -1479,7 +1512,7 @@ var ClipModal = defineComponent({
1479
1512
  "height": "421px"
1480
1513
  }, {
1481
1514
  default: () => {
1482
- var _a3;
1515
+ var _a3, _b2;
1483
1516
  return [createVNode("div", {
1484
1517
  "class": `${prefix}-form-item ${prefix}-clip`
1485
1518
  }, [createVNode("div", {
@@ -1527,7 +1560,7 @@ var ClipModal = defineComponent({
1527
1560
  reset();
1528
1561
  }
1529
1562
  }
1530
- }, [(_a3 = ult.value.linkModalTips) == null ? void 0 : _a3.buttonOK])]), createVNode("input", {
1563
+ }, [((_a3 = ult.value.clipModalTips) == null ? void 0 : _a3.buttonUpload) || ((_b2 = ult.value.linkModalTips) == null ? void 0 : _b2.buttonOK)])]), createVNode("input", {
1531
1564
  "ref": uploadRef,
1532
1565
  "accept": "image/*",
1533
1566
  "type": "file",
@@ -5607,6 +5640,7 @@ const useMarked = (props, mermaidData) => {
5607
5640
  heads.value = [];
5608
5641
  const _html = props.sanitize(marked(props.value || "", { renderer }));
5609
5642
  html.value = _html;
5643
+ bus.emit(editorId, "buildFinished", _html);
5610
5644
  props.onHtmlChanged(_html);
5611
5645
  }, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : previewOnly ? 0 : 500);
5612
5646
  watch([
@@ -5873,7 +5907,7 @@ const usePasteUpload = (textAreaRef) => {
5873
5907
  }
5874
5908
  });
5875
5909
  };
5876
- const userZoom = (html) => {
5910
+ const userZoom = (props, html) => {
5877
5911
  const editorId = inject("editorId");
5878
5912
  const zoomHander = debounce(() => {
5879
5913
  const imgs = document.querySelectorAll(`#${editorId}-preview img[zoom]`);
@@ -5885,7 +5919,7 @@ const userZoom = (html) => {
5885
5919
  });
5886
5920
  });
5887
5921
  onMounted(zoomHander);
5888
- watch([html], zoomHander);
5922
+ watch([html, toRef(props.setting, "preview")], zoomHander);
5889
5923
  };
5890
5924
  const contentProps = () => ({
5891
5925
  value: {
@@ -5959,7 +5993,7 @@ var Content = defineComponent({
5959
5993
  useAutoGenrator(props, textAreaRef);
5960
5994
  useHistory(props, textAreaRef, completeStatus);
5961
5995
  usePasteUpload(textAreaRef);
5962
- userZoom(html);
5996
+ userZoom(props, html);
5963
5997
  return () => {
5964
5998
  return createVNode(Fragment, null, [createVNode("div", {
5965
5999
  "class": `${prefix}-content`
@@ -6502,7 +6536,8 @@ const Editor = defineComponent({
6502
6536
  emits: ["onChange", "onSave", "onUploadImg", "onHtmlChanged", "onGetCatalog", "onError", "update:modelValue"],
6503
6537
  setup(props, context) {
6504
6538
  const {
6505
- editorId
6539
+ editorId,
6540
+ previewOnly
6506
6541
  } = props;
6507
6542
  const state = reactive({
6508
6543
  scrollAuto: props.scrollAuto
@@ -6527,9 +6562,9 @@ const Editor = defineComponent({
6527
6562
  }, "defFooters");
6528
6563
  return createVNode("div", {
6529
6564
  "id": editorId,
6530
- "class": [prefix, props.class, props.theme === "dark" && `${prefix}-dark`, setting.fullscreen || setting.pageFullScreen ? `${prefix}-fullscreen` : "", props.previewOnly && `${prefix}-previewOnly`],
6565
+ "class": [prefix, props.class, props.theme === "dark" && `${prefix}-dark`, setting.fullscreen || setting.pageFullScreen ? `${prefix}-fullscreen` : "", previewOnly && `${prefix}-previewOnly`],
6531
6566
  "style": props.style
6532
- }, [!props.previewOnly && createVNode(ToolBar, {
6567
+ }, [!previewOnly && createVNode(ToolBar, {
6533
6568
  "noPrettier": props.noPrettier,
6534
6569
  "toolbars": props.toolbars,
6535
6570
  "toolbarsExclude": props.toolbarsExclude,
@@ -6571,13 +6606,13 @@ const Editor = defineComponent({
6571
6606
  "noKatex": props.noKatex,
6572
6607
  "scrollAuto": state.scrollAuto,
6573
6608
  "formatCopiedText": props.formatCopiedText
6574
- }, null), !props.previewOnly && ((_a = props.footers) == null ? void 0 : _a.length) > 0 && createVNode(Footer, {
6609
+ }, null), !previewOnly && ((_a = props.footers) == null ? void 0 : _a.length) > 0 && createVNode(Footer, {
6575
6610
  "modelValue": props.modelValue,
6576
6611
  "footers": props.footers,
6577
6612
  "defFooters": defFooters,
6578
6613
  "scrollAuto": state.scrollAuto,
6579
6614
  "onScrollAutoChange": (v) => state.scrollAuto = v
6580
- }, null), catalogShow.value && !props.previewOnly && createVNode(MdCatalog, {
6615
+ }, null), catalogShow.value && !previewOnly && createVNode(MdCatalog, {
6581
6616
  "theme": props.theme,
6582
6617
  "style": {
6583
6618
  display: catalogVisible.value ? "block" : "none"