md-editor-v3 2.1.2-beta.2 → 2.2.0-beta.1

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
@@ -67,6 +67,7 @@ mark and emoji extensions
67
67
  | sanitize | (html: string) => string | (html) => html | Sanitize the html, prevent XSS |
68
68
  | footers | Array<'markdownTotal' \| '=' \| 'scrollSwitch' \| number> | ['markdownTotal', '=', 'scrollSwitch'] | Show contents of footer, they are divided by `'='`. Set it to `[]` to hidden footer |
69
69
  | scrollAuto | boolean | true | Scroll default setting |
70
+ | noIconfont | boolean | false | Not append iconfont script, [download](https://at.alicdn.com/t/font_2605852_pqekijay2ij.js) and import it by yourself |
70
71
 
71
72
  <details>
72
73
  <summary>[toolbars]</summary>
@@ -317,7 +318,7 @@ Use `MdEditor.config(option: ConfigOption)` to reconfigure `renderer`.
317
318
  flow: `flow tempalte`,
318
319
  ...more
319
320
  },
320
- // ms
321
+ // Default 500ms. It is set to 0ms when preview only and not set.
321
322
  renderDelay: 500
322
323
  }
323
324
  });
@@ -482,6 +483,10 @@ They are used as attributes of the editor component, eg: `Editor.DropdownToolbar
482
483
  - `scrollElement`: `string | HTMLElement`, not necessary, it is an element selector when its type is string. When `previewOnly` eq `true`, it is usually set to `document.documentElement`.
483
484
  - `theme`: `'light' | 'dark'`, not necessary, provide it when you want to change theme online, it is the same as Editor `theme`.
484
485
 
486
+ - **events**
487
+
488
+ - `onClick`: `(e: MouseEvent, t: TocItem) => void`, not necessary.
489
+
485
490
  ## Examples
486
491
 
487
492
  ### Jsx Template
@@ -130,6 +130,9 @@ declare const Editor: import("vue").DefineComponent<{
130
130
  defFooters: {
131
131
  type: PropType<string | JSX.Element>;
132
132
  };
133
+ noIconfont: {
134
+ type: PropType<boolean>;
135
+ };
133
136
  }, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, "onSave" | "onError" | "onUploadImg" | "onChange" | "onHtmlChanged" | "onGetCatalog" | "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
134
137
  modelValue: {
135
138
  type: PropType<string>;
@@ -259,6 +262,9 @@ declare const Editor: import("vue").DefineComponent<{
259
262
  defFooters: {
260
263
  type: PropType<string | JSX.Element>;
261
264
  };
265
+ noIconfont: {
266
+ type: PropType<boolean>;
267
+ };
262
268
  }>>, {
263
269
  pageFullScreen: boolean;
264
270
  preview: boolean;
@@ -274,6 +280,7 @@ declare const Editor: import("vue").DefineComponent<{
274
280
  style: string | CSSProperties;
275
281
  class: string;
276
282
  scrollAuto: boolean;
283
+ sanitize: (html: string) => string;
277
284
  modelValue: string;
278
285
  language: string;
279
286
  toolbars: ToolbarNames[];
@@ -281,7 +288,6 @@ declare const Editor: import("vue").DefineComponent<{
281
288
  markedHeadingId: MarkedHeadingId;
282
289
  tableShape: number[];
283
290
  noMermaid: boolean;
284
- sanitize: (html: string) => string;
285
291
  placeholder: string;
286
292
  noKatex: boolean;
287
293
  codeTheme: string;
@@ -0,0 +1,26 @@
1
+ import { CodeCss, Config, ConfigOption, Footers, StaticTextDefault } from './type';
2
+ export declare const prefix = "md";
3
+ export declare const iconScriptId = "md-editor-v3";
4
+ export declare const iconfontUrl = "https://at.alicdn.com/t/font_2605852_pqekijay2ij.js";
5
+ export declare const cdnBase = "https://cdnjs.cloudflare.com/ajax/libs";
6
+ export declare const highlightUrl: string;
7
+ export declare const prettierUrl: {
8
+ main: string;
9
+ markdown: string;
10
+ };
11
+ export declare const cropperUrl: {
12
+ css: string;
13
+ js: string;
14
+ };
15
+ export declare const screenfullUrl: string;
16
+ export declare const allToolbar: string[];
17
+ export declare const allFooter: Array<Footers>;
18
+ export declare const staticTextDefault: StaticTextDefault;
19
+ export declare const mermaidUrl: string;
20
+ export declare const katexUrl: {
21
+ js: string;
22
+ css: string;
23
+ };
24
+ export declare const codeCss: CodeCss;
25
+ export declare const configOption: ConfigOption;
26
+ export declare const config: Config;
@@ -18,6 +18,10 @@ declare const CatalogLink: import("vue").DefineComponent<{
18
18
  type: PropType<string | Element>;
19
19
  default: string;
20
20
  };
21
+ onClick: {
22
+ type: PropType<(e: MouseEvent, t: TocItem) => void>;
23
+ default: () => void;
24
+ };
21
25
  }, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
22
26
  tocItem: {
23
27
  type: PropType<TocItem>;
@@ -31,8 +35,13 @@ declare const CatalogLink: import("vue").DefineComponent<{
31
35
  type: PropType<string | Element>;
32
36
  default: string;
33
37
  };
38
+ onClick: {
39
+ type: PropType<(e: MouseEvent, t: TocItem) => void>;
40
+ default: () => void;
41
+ };
34
42
  }>>, {
35
43
  markedHeadingId: MarkedHeadingId;
44
+ onClick: (e: MouseEvent, t: TocItem) => void;
36
45
  scrollElement: string | Element;
37
46
  tocItem: TocItem;
38
47
  }>;
@@ -25,7 +25,7 @@ declare const MdCatalog: import("vue").DefineComponent<{
25
25
  type: PropType<Themes>;
26
26
  default: string;
27
27
  };
28
- }, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
28
+ }, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "onClick"[], "onClick", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
29
29
  editorId: {
30
30
  type: PropType<string>;
31
31
  };
@@ -44,7 +44,9 @@ declare const MdCatalog: import("vue").DefineComponent<{
44
44
  type: PropType<Themes>;
45
45
  default: string;
46
46
  };
47
- }>>, {
47
+ }>> & {
48
+ onOnClick?: ((...args: any[]) => any) | undefined;
49
+ }, {
48
50
  theme: Themes;
49
51
  class: string;
50
52
  markedHeadingId: MarkedHeadingId;
@@ -3,7 +3,7 @@ import NormalToolbar from './extensions/NormalToolbar';
3
3
  import DropdownToolbar from './extensions/DropdownToolbar';
4
4
  import MdCatalog from './extensions/MdCatalog';
5
5
  import ModalToolbar from './extensions/ModalToolbar';
6
- import configFn from './utils/config';
6
+ import { config } from './config';
7
7
  declare const _default: {
8
8
  new (...args: any[]): {
9
9
  $: import("vue").ComponentInternalInstance;
@@ -23,6 +23,7 @@ declare const _default: {
23
23
  style: string | import("vue").CSSProperties;
24
24
  class: string;
25
25
  scrollAuto: boolean;
26
+ sanitize: (html: string) => string;
26
27
  modelValue: string;
27
28
  language: string;
28
29
  toolbars: import("./type").ToolbarNames[];
@@ -30,7 +31,6 @@ declare const _default: {
30
31
  markedHeadingId: import("./type").MarkedHeadingId;
31
32
  tableShape: number[];
32
33
  noMermaid: boolean;
33
- sanitize: (html: string) => string;
34
34
  placeholder: string;
35
35
  noKatex: boolean;
36
36
  codeTheme: string;
@@ -164,7 +164,10 @@ declare const _default: {
164
164
  defFooters: {
165
165
  type: import("vue").PropType<string | JSX.Element>;
166
166
  };
167
- }>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "pageFullScreen" | "preview" | "htmlPreview" | "editorId" | "noPrettier" | "tabWidth" | "theme" | "historyLength" | "previewOnly" | "showCodeRowNumber" | "previewTheme" | "style" | "class" | "scrollAuto" | "modelValue" | "language" | "toolbars" | "toolbarsExclude" | "markedHeadingId" | "tableShape" | "noMermaid" | "sanitize" | "placeholder" | "noKatex" | "codeTheme" | "footers">;
167
+ noIconfont: {
168
+ type: import("vue").PropType<boolean>;
169
+ };
170
+ }>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "pageFullScreen" | "preview" | "htmlPreview" | "editorId" | "noPrettier" | "tabWidth" | "theme" | "historyLength" | "previewOnly" | "showCodeRowNumber" | "previewTheme" | "style" | "class" | "scrollAuto" | "sanitize" | "modelValue" | "language" | "toolbars" | "toolbarsExclude" | "markedHeadingId" | "tableShape" | "noMermaid" | "placeholder" | "noKatex" | "codeTheme" | "footers">;
168
171
  $attrs: {
169
172
  [x: string]: unknown;
170
173
  };
@@ -307,6 +310,9 @@ declare const _default: {
307
310
  defFooters: {
308
311
  type: import("vue").PropType<string | JSX.Element>;
309
312
  };
313
+ noIconfont: {
314
+ type: import("vue").PropType<boolean>;
315
+ };
310
316
  }>>, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, {
311
317
  pageFullScreen: boolean;
312
318
  preview: boolean;
@@ -322,6 +328,7 @@ declare const _default: {
322
328
  style: string | import("vue").CSSProperties;
323
329
  class: string;
324
330
  scrollAuto: boolean;
331
+ sanitize: (html: string) => string;
325
332
  modelValue: string;
326
333
  language: string;
327
334
  toolbars: import("./type").ToolbarNames[];
@@ -329,7 +336,6 @@ declare const _default: {
329
336
  markedHeadingId: import("./type").MarkedHeadingId;
330
337
  tableShape: number[];
331
338
  noMermaid: boolean;
332
- sanitize: (html: string) => string;
333
339
  placeholder: string;
334
340
  noKatex: boolean;
335
341
  codeTheme: string;
@@ -483,6 +489,9 @@ declare const _default: {
483
489
  defFooters: {
484
490
  type: import("vue").PropType<string | JSX.Element>;
485
491
  };
492
+ noIconfont: {
493
+ type: import("vue").PropType<boolean>;
494
+ };
486
495
  }>> & import("vue").ShallowUnwrapRef<() => JSX.Element> & {} & {} & import("vue").ComponentCustomProperties;
487
496
  __isFragment?: undefined;
488
497
  __isTeleport?: undefined;
@@ -616,6 +625,9 @@ declare const _default: {
616
625
  defFooters: {
617
626
  type: import("vue").PropType<string | JSX.Element>;
618
627
  };
628
+ noIconfont: {
629
+ type: import("vue").PropType<boolean>;
630
+ };
619
631
  }>>, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, "onSave" | "onError" | "onUploadImg" | "onChange" | "onHtmlChanged" | "onGetCatalog" | "update:modelValue", {
620
632
  pageFullScreen: boolean;
621
633
  preview: boolean;
@@ -631,6 +643,7 @@ declare const _default: {
631
643
  style: string | import("vue").CSSProperties;
632
644
  class: string;
633
645
  scrollAuto: boolean;
646
+ sanitize: (html: string) => string;
634
647
  modelValue: string;
635
648
  language: string;
636
649
  toolbars: import("./type").ToolbarNames[];
@@ -638,7 +651,6 @@ declare const _default: {
638
651
  markedHeadingId: import("./type").MarkedHeadingId;
639
652
  tableShape: number[];
640
653
  noMermaid: boolean;
641
- sanitize: (html: string) => string;
642
654
  placeholder: string;
643
655
  noKatex: boolean;
644
656
  codeTheme: string;
@@ -648,7 +660,7 @@ declare const _default: {
648
660
  readonly DropdownToolbar: typeof DropdownToolbar;
649
661
  readonly MdCatalog: typeof MdCatalog;
650
662
  readonly ModalToolbar: typeof ModalToolbar;
651
- readonly config: typeof configFn;
663
+ readonly config: typeof config;
652
664
  install: (app: App) => App;
653
665
  };
654
666
  export default _default;
@@ -172,6 +172,8 @@ export interface ConfigOption {
172
172
  css?: CodeCss;
173
173
  };
174
174
  prettier?: {
175
+ prettierInstance?: any;
176
+ parserMarkdownInstance?: any;
175
177
  standaloneJs?: string;
176
178
  parserMarkdownJs?: string;
177
179
  };
@@ -264,6 +264,23 @@ const codeCss = {
264
264
  dark: `${cdnBase}/highlight.js/11.5.1/styles/stackoverflow-dark.min.css`
265
265
  }
266
266
  };
267
+ const configOption = {
268
+ markedRenderer: (r) => r,
269
+ markedExtensions: [],
270
+ markedOptions: {},
271
+ editorExtensions: {},
272
+ editorConfig: {}
273
+ };
274
+ const config = (option) => {
275
+ if (option) {
276
+ for (const key in option) {
277
+ const optionItem = option[key];
278
+ if (optionItem) {
279
+ configOption[key] = optionItem;
280
+ }
281
+ }
282
+ }
283
+ };
267
284
  class Bus {
268
285
  constructor() {
269
286
  this.pools = {};
@@ -771,10 +788,10 @@ const useKeyBoard = (props2, context) => {
771
788
  }
772
789
  });
773
790
  };
774
- const useProvide = (props2, extension) => {
791
+ const useProvide = (props2) => {
775
792
  var _a;
776
793
  const { editorId } = props2;
777
- const highlightConfig = (_a = extension == null ? void 0 : extension.editorExtensions) == null ? void 0 : _a.highlight;
794
+ const highlightConfig = (_a = configOption == null ? void 0 : configOption.editorExtensions) == null ? void 0 : _a.highlight;
778
795
  provide("editorId", editorId);
779
796
  provide("tabWidth", props2.tabWidth);
780
797
  provide("theme", computed(() => props2.theme));
@@ -790,7 +807,7 @@ const useProvide = (props2, extension) => {
790
807
  provide("showCodeRowNumber", props2.showCodeRowNumber);
791
808
  const usedLanguageText = computed(() => {
792
809
  var _a2;
793
- const allText = __spreadValues(__spreadValues({}, staticTextDefault), (_a2 = extension == null ? void 0 : extension.editorConfig) == null ? void 0 : _a2.languageUserDefined);
810
+ const allText = __spreadValues(__spreadValues({}, staticTextDefault), (_a2 = configOption == null ? void 0 : configOption.editorConfig) == null ? void 0 : _a2.languageUserDefined);
794
811
  if (allText[props2.language]) {
795
812
  return allText[props2.language];
796
813
  } else {
@@ -799,39 +816,44 @@ const useProvide = (props2, extension) => {
799
816
  });
800
817
  provide("usedLanguageText", usedLanguageText);
801
818
  provide("previewTheme", computed(() => props2.previewTheme));
802
- provide("extension", extension);
803
819
  };
804
- const useExpansion = (props2, extension) => {
805
- const {
806
- noPrettier,
807
- previewOnly
808
- } = props2;
820
+ const useExpansion = (props2) => {
821
+ var _a, _b, _c, _d, _e, _f;
822
+ const { noPrettier, previewOnly, noIconfont } = props2;
823
+ const { editorExtensions } = configOption;
824
+ const noPrettierScript = noPrettier || !!((_b = (_a = configOption.editorExtensions) == null ? void 0 : _a.prettier) == null ? void 0 : _b.prettierInstance);
825
+ const noParserMarkdownScript = noPrettier || !!((_d = (_c = configOption.editorExtensions) == null ? void 0 : _c.prettier) == null ? void 0 : _d.parserMarkdownInstance);
826
+ const noCropperScript = !!((_f = (_e = configOption.editorExtensions) == null ? void 0 : _e.cropper) == null ? void 0 : _f.instance);
809
827
  onMounted(() => {
810
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
828
+ var _a2, _b2, _c2, _d2;
811
829
  const iconfontScript = document.createElement("script");
812
- iconfontScript.src = ((_a = extension.editorExtensions) == null ? void 0 : _a.iconfont) || iconfontUrl;
830
+ iconfontScript.src = (editorExtensions == null ? void 0 : editorExtensions.iconfont) || iconfontUrl;
813
831
  iconfontScript.id = `${prefix}-icon`;
814
832
  const prettierScript = document.createElement("script");
815
833
  const prettierMDScript = document.createElement("script");
816
- prettierScript.src = ((_c = (_b = extension.editorExtensions) == null ? void 0 : _b.prettier) == null ? void 0 : _c.standaloneJs) || prettierUrl.main;
834
+ prettierScript.src = ((_a2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _a2.standaloneJs) || prettierUrl.main;
817
835
  prettierScript.id = `${prefix}-prettier`;
818
- prettierMDScript.src = ((_e = (_d = extension.editorExtensions) == null ? void 0 : _d.prettier) == null ? void 0 : _e.parserMarkdownJs) || prettierUrl.markdown;
836
+ prettierMDScript.src = ((_b2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _b2.parserMarkdownJs) || prettierUrl.markdown;
819
837
  prettierMDScript.id = `${prefix}-prettierMD`;
820
838
  const cropperLink = document.createElement("link");
821
839
  cropperLink.rel = "stylesheet";
822
- cropperLink.href = ((_g = (_f = extension.editorExtensions) == null ? void 0 : _f.cropper) == null ? void 0 : _g.css) || cropperUrl.css;
840
+ cropperLink.href = ((_c2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _c2.css) || cropperUrl.css;
823
841
  cropperLink.id = `${prefix}-cropperCss`;
824
842
  const cropperScript = document.createElement("script");
825
- cropperScript.src = ((_i = (_h = extension.editorExtensions) == null ? void 0 : _h.cropper) == null ? void 0 : _i.js) || cropperUrl.js;
843
+ cropperScript.src = ((_d2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _d2.js) || cropperUrl.js;
826
844
  cropperScript.id = `${prefix}-cropper`;
827
845
  if (!previewOnly) {
828
- appendHandler(iconfontScript);
829
- if (!((_k = (_j = extension.editorExtensions) == null ? void 0 : _j.cropper) == null ? void 0 : _k.instance)) {
846
+ if (!noIconfont) {
847
+ appendHandler(iconfontScript);
848
+ }
849
+ if (!noCropperScript) {
830
850
  appendHandler(cropperLink);
831
851
  appendHandler(cropperScript);
832
852
  }
833
- if (!noPrettier) {
853
+ if (!noPrettierScript) {
834
854
  appendHandler(prettierScript);
855
+ }
856
+ if (!noParserMarkdownScript) {
835
857
  appendHandler(prettierMDScript);
836
858
  }
837
859
  }
@@ -1343,8 +1365,7 @@ var ClipModal = defineComponent({
1343
1365
  var _a, _b;
1344
1366
  const ult = inject("usedLanguageText");
1345
1367
  const editorId = inject("editorId");
1346
- const extension = inject("extension");
1347
- let Cropper = (_b = (_a = extension == null ? void 0 : extension.editorExtensions) == null ? void 0 : _a.cropper) == null ? void 0 : _b.instance;
1368
+ let Cropper = (_b = (_a = configOption == null ? void 0 : configOption.editorExtensions) == null ? void 0 : _a.cropper) == null ? void 0 : _b.instance;
1348
1369
  const uploadRef = ref();
1349
1370
  const uploadImgRef = ref();
1350
1371
  const previewTargetRef = ref();
@@ -1521,9 +1542,8 @@ const useSreenfull = (props2) => {
1521
1542
  var _a, _b, _c, _d;
1522
1543
  const editorId = inject("editorId");
1523
1544
  const previewOnly = inject("previewOnly");
1524
- const extension = inject("extension");
1525
- let screenfull = (_b = (_a = extension.editorExtensions) == null ? void 0 : _a.screenfull) == null ? void 0 : _b.instance;
1526
- const screenfullJs = (_d = (_c = extension.editorExtensions) == null ? void 0 : _c.screenfull) == null ? void 0 : _d.js;
1545
+ let screenfull = (_b = (_a = configOption.editorExtensions) == null ? void 0 : _a.screenfull) == null ? void 0 : _b.instance;
1546
+ const screenfullJs = (_d = (_c = configOption.editorExtensions) == null ? void 0 : _c.screenfull) == null ? void 0 : _d.js;
1527
1547
  const screenfullMe = ref(false);
1528
1548
  const fullScreenHandler = () => {
1529
1549
  if (!screenfull) {
@@ -4875,13 +4895,14 @@ const splitHelp = (textarea) => {
4875
4895
  };
4876
4896
  };
4877
4897
  const directive2flag = (direct, selectedText = "", inputArea, params) => {
4898
+ var _a, _b, _c, _d, _e;
4878
4899
  let targetValue = "";
4879
4900
  let deviationStart = 0;
4880
4901
  let deviationEnd = 0;
4881
4902
  let select = false;
4882
4903
  let prefixVal;
4883
4904
  let subfixVal;
4884
- const mermaidTemplate = params == null ? void 0 : params.mermaidTemplate;
4905
+ const mermaidTemplate = (_a = configOption.editorConfig) == null ? void 0 : _a.mermaidTemplate;
4885
4906
  if (/^h[1-6]{1}$/.test(direct)) {
4886
4907
  const pix = direct.replace(/^h(\d)/, (_, num) => {
4887
4908
  return new Array(Number(num)).fill("#", 0, num).join("");
@@ -4889,16 +4910,20 @@ const directive2flag = (direct, selectedText = "", inputArea, params) => {
4889
4910
  targetValue = `${pix} ${selectedText}`;
4890
4911
  deviationStart = pix.length + 1;
4891
4912
  } else if (direct === "prettier") {
4892
- if (!window.prettier) {
4913
+ const prettier = window.prettier || ((_c = (_b = configOption.editorExtensions) == null ? void 0 : _b.prettier) == null ? void 0 : _c.prettierInstance);
4914
+ const prettierPlugins = window.prettierPlugins || [
4915
+ (_e = (_d = configOption.editorExtensions) == null ? void 0 : _d.prettier) == null ? void 0 : _e.parserMarkdownInstance
4916
+ ];
4917
+ if (!prettier || prettierPlugins[0] === void 0) {
4893
4918
  bus.emit(params.editorId, "errorCatcher", {
4894
4919
  name: "prettier",
4895
4920
  message: "prettier is undefined"
4896
4921
  });
4897
4922
  return inputArea.value;
4898
4923
  }
4899
- return window.prettier.format(inputArea.value, {
4924
+ return prettier.format(inputArea.value, {
4900
4925
  parser: "markdown",
4901
- plugins: window.prettierPlugins
4926
+ plugins: prettierPlugins
4902
4927
  });
4903
4928
  } else {
4904
4929
  switch (direct) {
@@ -5353,9 +5378,9 @@ const useHistory = (props2, textAreaRef, completeStatus) => {
5353
5378
  }
5354
5379
  }, 150);
5355
5380
  };
5356
- const saveHistoryPos = () => {
5381
+ const saveHistoryPos = (force) => {
5357
5382
  var _a2, _b2;
5358
- if (historyPos === POSITION_START) {
5383
+ if (historyPos === POSITION_START || force) {
5359
5384
  historyPos = [(_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart, (_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd];
5360
5385
  }
5361
5386
  };
@@ -5396,10 +5421,11 @@ const useMarked = (props2, mermaidData) => {
5396
5421
  markedOptions,
5397
5422
  editorExtensions,
5398
5423
  editorConfig
5399
- } = inject("extension");
5424
+ } = configOption;
5400
5425
  const showCodeRowNumber = inject("showCodeRowNumber");
5401
5426
  const editorId = inject("editorId");
5402
5427
  const highlightUrl2 = inject("highlight");
5428
+ const previewOnly = inject("previewOnly");
5403
5429
  const highlightIns = (_a = editorExtensions == null ? void 0 : editorExtensions.highlight) == null ? void 0 : _a.instance;
5404
5430
  const mermaidIns = (_b = editorExtensions == null ? void 0 : editorExtensions.mermaid) == null ? void 0 : _b.instance;
5405
5431
  const katexIns = (_c = editorExtensions == null ? void 0 : editorExtensions.katex) == null ? void 0 : _c.instance;
@@ -5437,8 +5463,8 @@ const useMarked = (props2, mermaidData) => {
5437
5463
  }
5438
5464
  return markedCode.call(renderer, code, language, isEscaped);
5439
5465
  };
5440
- renderer.image = (href, title = "", desc = "") => {
5441
- return `<span class="figure"><img src="${href}" title="${title}" alt="${desc}" zoom><span class="figcaption">${desc}</span></span>`;
5466
+ renderer.image = (href, title, desc) => {
5467
+ return `<span class="figure"><img src="${href}" title="${title || ""}" alt="${desc || ""}" zoom><span class="figcaption">${desc || ""}</span></span>`;
5442
5468
  };
5443
5469
  renderer.listitem = (text, task) => {
5444
5470
  if (task) {
@@ -5482,7 +5508,7 @@ const useMarked = (props2, mermaidData) => {
5482
5508
  const hljsLang = highlightIns.getLanguage(language);
5483
5509
  if (language && hljsLang) {
5484
5510
  codeHtml = highlightIns.highlight(code, {
5485
- language: hljsLang.name.split(/,|\s/)[0],
5511
+ language,
5486
5512
  ignoreIllegals: true
5487
5513
  }).value;
5488
5514
  } else {
@@ -5503,7 +5529,7 @@ const useMarked = (props2, mermaidData) => {
5503
5529
  const _html = props2.sanitize(marked(props2.value || "", { renderer }));
5504
5530
  html.value = _html;
5505
5531
  props2.onHtmlChanged(_html);
5506
- }, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : 500);
5532
+ }, (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : previewOnly ? 0 : 500);
5507
5533
  watch([
5508
5534
  highlightInited,
5509
5535
  toRef(mermaidData, "reRender"),
@@ -5518,7 +5544,7 @@ const useMarked = (props2, mermaidData) => {
5518
5544
  const hljsLang = window.hljs.getLanguage(language);
5519
5545
  if (language && hljsLang) {
5520
5546
  codeHtml = window.hljs.highlight(code, {
5521
- language: hljsLang.name.split(/,|\s/)[0],
5547
+ language,
5522
5548
  ignoreIllegals: true
5523
5549
  }).value;
5524
5550
  } else {
@@ -5634,9 +5660,12 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
5634
5660
  });
5635
5661
  onMounted(() => {
5636
5662
  initCopyEntry();
5637
- if (!previewOnly && props2.scrollAuto && (previewRef.value || htmlRef.value)) {
5663
+ if (!previewOnly && (previewRef.value || htmlRef.value)) {
5638
5664
  [initScrollAuto, clearScrollAuto] = scrollAuto(textAreaRef.value, previewRef.value || htmlRef.value);
5639
5665
  }
5666
+ if (props2.scrollAuto) {
5667
+ initScrollAuto();
5668
+ }
5640
5669
  });
5641
5670
  };
5642
5671
  const useAutoGenrator = (props2, textAreaRef) => {
@@ -5679,7 +5708,6 @@ ${nextOrder}. `, {}));
5679
5708
  callback(direct, params = {}) {
5680
5709
  props2.onChange(directive2flag(direct, selectedText.value, textAreaRef.value, __spreadProps(__spreadValues({}, params), {
5681
5710
  tabWidth,
5682
- mermaidTemplate: props2.mermaidTemplate,
5683
5711
  editorId
5684
5712
  })));
5685
5713
  }
@@ -5698,7 +5726,7 @@ ${nextOrder}. `, {}));
5698
5726
  };
5699
5727
  const useMermaid = (props2) => {
5700
5728
  const theme = inject("theme");
5701
- const { editorExtensions } = inject("extension");
5729
+ const { editorExtensions } = configOption;
5702
5730
  const mermaidConf = editorExtensions == null ? void 0 : editorExtensions.mermaid;
5703
5731
  const mermaidData = reactive({
5704
5732
  reRender: false,
@@ -5822,10 +5850,6 @@ var Content = defineComponent({
5822
5850
  type: Boolean,
5823
5851
  default: false
5824
5852
  },
5825
- mermaidTemplate: {
5826
- type: Object,
5827
- default: () => ({})
5828
- },
5829
5853
  scrollAuto: {
5830
5854
  type: Boolean
5831
5855
  }
@@ -5858,7 +5882,7 @@ var Content = defineComponent({
5858
5882
  "ref": textAreaRef,
5859
5883
  "value": props2.value,
5860
5884
  "onKeydown": () => {
5861
- bus.emit(editorId, "saveHistoryPos");
5885
+ bus.emit(editorId, "saveHistoryPos", true);
5862
5886
  },
5863
5887
  "onCompositionstart": () => {
5864
5888
  completeStatus.value = false;
@@ -6042,16 +6066,23 @@ const CatalogLink = defineComponent({
6042
6066
  scrollElement: {
6043
6067
  type: [String, Object],
6044
6068
  default: ""
6069
+ },
6070
+ onClick: {
6071
+ type: Function,
6072
+ default: () => {
6073
+ }
6045
6074
  }
6046
6075
  },
6047
6076
  setup({
6048
6077
  tocItem,
6049
6078
  markedHeadingId: markedHeadingId2,
6050
- scrollElement
6079
+ scrollElement,
6080
+ onClick
6051
6081
  }) {
6052
6082
  return () => createVNode("div", {
6053
6083
  "class": `${prefix}-catalog-link`,
6054
6084
  "onClick": (e) => {
6085
+ onClick(e, tocItem);
6055
6086
  e.stopPropagation();
6056
6087
  const id = markedHeadingId2(tocItem.text, tocItem.level, tocItem.index);
6057
6088
  const targetHeadEle = document.getElementById(id);
@@ -6079,7 +6110,8 @@ const CatalogLink = defineComponent({
6079
6110
  "markedHeadingId": markedHeadingId2,
6080
6111
  "key": item.text,
6081
6112
  "tocItem": item,
6082
- "scrollElement": scrollElement
6113
+ "scrollElement": scrollElement,
6114
+ "onClick": onClick
6083
6115
  }, null))])]);
6084
6116
  }
6085
6117
  });
@@ -6106,7 +6138,8 @@ const MdCatalog = defineComponent({
6106
6138
  default: "light"
6107
6139
  }
6108
6140
  },
6109
- setup(props2) {
6141
+ emits: ["onClick"],
6142
+ setup(props2, ctx) {
6110
6143
  const editorId = props2.editorId;
6111
6144
  const state = reactive({
6112
6145
  list: [],
@@ -6166,7 +6199,10 @@ const MdCatalog = defineComponent({
6166
6199
  "markedHeadingId": props2.markedHeadingId,
6167
6200
  "tocItem": item,
6168
6201
  "key": item.text,
6169
- "scrollElement": state.scrollElement
6202
+ "scrollElement": state.scrollElement,
6203
+ "onClick": (e, t) => {
6204
+ ctx.emit("onClick", e, t);
6205
+ }
6170
6206
  }, null);
6171
6207
  })]);
6172
6208
  }
@@ -6302,6 +6338,9 @@ const props = {
6302
6338
  },
6303
6339
  defFooters: {
6304
6340
  type: [String, Object]
6341
+ },
6342
+ noIconfont: {
6343
+ type: Boolean
6305
6344
  }
6306
6345
  };
6307
6346
  const Editor = defineComponent({
@@ -6312,20 +6351,19 @@ const Editor = defineComponent({
6312
6351
  const {
6313
6352
  editorId
6314
6353
  } = props2;
6315
- const extension = Editor.extension || {};
6316
6354
  const state = reactive({
6317
6355
  scrollAuto: props2.scrollAuto
6318
6356
  });
6319
6357
  useKeyBoard(props2, context);
6320
- useProvide(props2, extension);
6321
- useExpansion(props2, extension);
6358
+ useProvide(props2);
6359
+ useExpansion(props2);
6322
6360
  const [setting, updateSetting] = useConfig(props2, context);
6323
6361
  const [catalogVisible, catalogShow] = useCatalog(props2);
6324
6362
  onBeforeUnmount(() => {
6325
6363
  bus.clear(editorId);
6326
6364
  });
6327
6365
  return () => {
6328
- var _a, _b;
6366
+ var _a;
6329
6367
  const defToolbars = getSlot({
6330
6368
  props: props2,
6331
6369
  ctx: context
@@ -6377,9 +6415,8 @@ const Editor = defineComponent({
6377
6415
  "sanitize": props2.sanitize,
6378
6416
  "placeholder": props2.placeholder,
6379
6417
  "noKatex": props2.noKatex,
6380
- "mermaidTemplate": (_a = extension == null ? void 0 : extension.editorConfig) == null ? void 0 : _a.mermaidTemplate,
6381
6418
  "scrollAuto": state.scrollAuto
6382
- }, null), !props2.previewOnly && ((_b = props2.footers) == null ? void 0 : _b.length) > 0 && createVNode(Footer, {
6419
+ }, null), !props2.previewOnly && ((_a = props2.footers) == null ? void 0 : _a.length) > 0 && createVNode(Footer, {
6383
6420
  "modelValue": props2.modelValue,
6384
6421
  "footers": props2.footers,
6385
6422
  "defFooters": defFooters,
@@ -6578,17 +6615,6 @@ var ModalToolbar = defineComponent({
6578
6615
  };
6579
6616
  }
6580
6617
  });
6581
- const config = function(option = {
6582
- markedRenderer: (r) => r,
6583
- markedExtensions: [],
6584
- markedOptions: {},
6585
- editorExtensions: {}
6586
- }) {
6587
- Reflect.defineProperty(this, "extension", {
6588
- value: option,
6589
- enumerable: true
6590
- });
6591
- };
6592
6618
  Editor.install = (app) => {
6593
6619
  app.component(Editor.name, Editor);
6594
6620
  app.component(NormalToolbar.name, NormalToolbar);