md-editor-v3 4.13.0 → 4.13.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
@@ -151,7 +151,7 @@ Except for the same as `MdPreview`:
151
151
  | completions | `Array<CompletionSource>` | [] | `@codemirror/autocomplete` List of function to match keywords |
152
152
  | showToolbarName | `boolean` | false | Show toolbar name or not |
153
153
  | inputBoxWitdh | `string` | '50%' | Default width of input box |
154
- | transformImgUrl | `(imgUrl: string) => string` | t => t | Transform image links |
154
+ | transformImgUrl | `(imgUrl: string) => string \| Promise<string>` | t => t | Transform image links |
155
155
 
156
156
  <details>
157
157
  <summary>『toolbars』</summary>
@@ -1189,7 +1189,8 @@ const ToolBar = /* @__PURE__ */ vue.defineComponent({
1189
1189
  if (data) {
1190
1190
  emitHandler(modalData.type, {
1191
1191
  desc: data.desc,
1192
- url: data.url
1192
+ url: data.url,
1193
+ transform: modalData.type === "image"
1193
1194
  });
1194
1195
  }
1195
1196
  modalData.linkVisible = false;
@@ -2285,6 +2286,29 @@ class CodeMirrorUt {
2285
2286
  }
2286
2287
  const usePasteUpload = (props2, codeMirrorUt) => {
2287
2288
  const editorId = vue.inject("editorId");
2289
+ const imgInsert = (tv) => {
2290
+ if (tv instanceof Promise) {
2291
+ tv.then((targetValue) => {
2292
+ index.bus.emit(editorId, index.REPLACE, "universal", {
2293
+ generate() {
2294
+ return {
2295
+ targetValue
2296
+ };
2297
+ }
2298
+ });
2299
+ }).catch((err) => {
2300
+ console.error(err);
2301
+ });
2302
+ } else {
2303
+ index.bus.emit(editorId, index.REPLACE, "universal", {
2304
+ generate() {
2305
+ return {
2306
+ targetValue: tv
2307
+ };
2308
+ }
2309
+ });
2310
+ }
2311
+ };
2288
2312
  const pasteHandler = (e) => {
2289
2313
  var _a, _b, _c;
2290
2314
  if (!e.clipboardData) {
@@ -2307,26 +2331,16 @@ const usePasteUpload = (props2, codeMirrorUt) => {
2307
2331
  const from = ((_b = codeMirrorUt.value) == null ? void 0 : _b.view.state.doc.lineAt(to).from) || 0;
2308
2332
  const lineStart = ((_c = codeMirrorUt.value) == null ? void 0 : _c.view.state.doc.sliceString(from, to)) || "";
2309
2333
  const templateStart = /!\[.*\]\(\s*$/.test(lineStart);
2310
- const templateIn = /!\[.*\]\((.*)\s?.*\)/.test(targetValue);
2334
+ const templateIn = /^!\[.*\]\((.*)\s?.*\)$/.test(targetValue);
2311
2335
  if (templateStart) {
2312
- index.bus.emit(editorId, index.REPLACE, "universal", {
2313
- generate() {
2314
- return {
2315
- targetValue: props2.transformImgUrl(targetValue)
2316
- };
2317
- }
2318
- });
2336
+ const tv = props2.transformImgUrl(targetValue);
2337
+ imgInsert(tv);
2319
2338
  e.preventDefault();
2320
2339
  return;
2321
2340
  } else if (templateIn) {
2322
2341
  const matchArr = targetValue.match(new RegExp(`(?<=!\\[.*\\]\\()\\S+(?=\\s?["']?.*["']?\\))`));
2323
- index.bus.emit(editorId, index.REPLACE, "universal", {
2324
- generate() {
2325
- return {
2326
- targetValue: matchArr ? targetValue.replace(matchArr[0], props2.transformImgUrl(matchArr[0])) : targetValue
2327
- };
2328
- }
2329
- });
2342
+ const tv = matchArr ? props2.transformImgUrl(matchArr[0]) : targetValue;
2343
+ imgInsert(tv);
2330
2344
  e.preventDefault();
2331
2345
  return;
2332
2346
  }
@@ -2630,9 +2644,31 @@ const useCodeMirror = (props2) => {
2630
2644
  index.bus.on(editorId, {
2631
2645
  name: index.REPLACE,
2632
2646
  callback(direct, params = {}) {
2633
- var _a;
2634
- const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
2635
- (_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
2647
+ var _a, _b;
2648
+ if (direct === "image" && params.transform) {
2649
+ const tv = props2.transformImgUrl(params.url);
2650
+ if (tv instanceof Promise) {
2651
+ tv.then((url) => {
2652
+ var _a2;
2653
+ const { text, options } = directive2flag(direct, codeMirrorUt.value, {
2654
+ ...params,
2655
+ url
2656
+ });
2657
+ (_a2 = codeMirrorUt.value) == null ? void 0 : _a2.replaceSelectedText(text, options, editorId);
2658
+ }).catch((err) => {
2659
+ console.error(err);
2660
+ });
2661
+ } else {
2662
+ const { text, options } = directive2flag(direct, codeMirrorUt.value, {
2663
+ ...params,
2664
+ url: tv
2665
+ });
2666
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
2667
+ }
2668
+ } else {
2669
+ const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
2670
+ (_b = codeMirrorUt.value) == null ? void 0 : _b.replaceSelectedText(text, options, editorId);
2671
+ }
2636
2672
  }
2637
2673
  });
2638
2674
  index.bus.on(editorId, {
@@ -1188,7 +1188,8 @@ const ToolBar = /* @__PURE__ */ defineComponent({
1188
1188
  if (data) {
1189
1189
  emitHandler(modalData.type, {
1190
1190
  desc: data.desc,
1191
- url: data.url
1191
+ url: data.url,
1192
+ transform: modalData.type === "image"
1192
1193
  });
1193
1194
  }
1194
1195
  modalData.linkVisible = false;
@@ -2284,6 +2285,29 @@ class CodeMirrorUt {
2284
2285
  }
2285
2286
  const usePasteUpload = (props2, codeMirrorUt) => {
2286
2287
  const editorId = inject("editorId");
2288
+ const imgInsert = (tv) => {
2289
+ if (tv instanceof Promise) {
2290
+ tv.then((targetValue) => {
2291
+ bus.emit(editorId, REPLACE, "universal", {
2292
+ generate() {
2293
+ return {
2294
+ targetValue
2295
+ };
2296
+ }
2297
+ });
2298
+ }).catch((err) => {
2299
+ console.error(err);
2300
+ });
2301
+ } else {
2302
+ bus.emit(editorId, REPLACE, "universal", {
2303
+ generate() {
2304
+ return {
2305
+ targetValue: tv
2306
+ };
2307
+ }
2308
+ });
2309
+ }
2310
+ };
2287
2311
  const pasteHandler = (e) => {
2288
2312
  var _a, _b, _c;
2289
2313
  if (!e.clipboardData) {
@@ -2306,26 +2330,16 @@ const usePasteUpload = (props2, codeMirrorUt) => {
2306
2330
  const from = ((_b = codeMirrorUt.value) == null ? void 0 : _b.view.state.doc.lineAt(to).from) || 0;
2307
2331
  const lineStart = ((_c = codeMirrorUt.value) == null ? void 0 : _c.view.state.doc.sliceString(from, to)) || "";
2308
2332
  const templateStart = /!\[.*\]\(\s*$/.test(lineStart);
2309
- const templateIn = /!\[.*\]\((.*)\s?.*\)/.test(targetValue);
2333
+ const templateIn = /^!\[.*\]\((.*)\s?.*\)$/.test(targetValue);
2310
2334
  if (templateStart) {
2311
- bus.emit(editorId, REPLACE, "universal", {
2312
- generate() {
2313
- return {
2314
- targetValue: props2.transformImgUrl(targetValue)
2315
- };
2316
- }
2317
- });
2335
+ const tv = props2.transformImgUrl(targetValue);
2336
+ imgInsert(tv);
2318
2337
  e.preventDefault();
2319
2338
  return;
2320
2339
  } else if (templateIn) {
2321
2340
  const matchArr = targetValue.match(new RegExp(`(?<=!\\[.*\\]\\()\\S+(?=\\s?["']?.*["']?\\))`));
2322
- bus.emit(editorId, REPLACE, "universal", {
2323
- generate() {
2324
- return {
2325
- targetValue: matchArr ? targetValue.replace(matchArr[0], props2.transformImgUrl(matchArr[0])) : targetValue
2326
- };
2327
- }
2328
- });
2341
+ const tv = matchArr ? props2.transformImgUrl(matchArr[0]) : targetValue;
2342
+ imgInsert(tv);
2329
2343
  e.preventDefault();
2330
2344
  return;
2331
2345
  }
@@ -2629,9 +2643,31 @@ const useCodeMirror = (props2) => {
2629
2643
  bus.on(editorId, {
2630
2644
  name: REPLACE,
2631
2645
  callback(direct, params = {}) {
2632
- var _a;
2633
- const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
2634
- (_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
2646
+ var _a, _b;
2647
+ if (direct === "image" && params.transform) {
2648
+ const tv = props2.transformImgUrl(params.url);
2649
+ if (tv instanceof Promise) {
2650
+ tv.then((url) => {
2651
+ var _a2;
2652
+ const { text, options } = directive2flag(direct, codeMirrorUt.value, {
2653
+ ...params,
2654
+ url
2655
+ });
2656
+ (_a2 = codeMirrorUt.value) == null ? void 0 : _a2.replaceSelectedText(text, options, editorId);
2657
+ }).catch((err) => {
2658
+ console.error(err);
2659
+ });
2660
+ } else {
2661
+ const { text, options } = directive2flag(direct, codeMirrorUt.value, {
2662
+ ...params,
2663
+ url: tv
2664
+ });
2665
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
2666
+ }
2667
+ } else {
2668
+ const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
2669
+ (_b = codeMirrorUt.value) == null ? void 0 : _b.replaceSelectedText(text, options, editorId);
2670
+ }
2635
2671
  }
2636
2672
  });
2637
2673
  bus.on(editorId, {
@@ -106,7 +106,7 @@ declare const Editor: import('vue').DefineComponent<{
106
106
  type: import("vue").PropType<(width: string) => void>;
107
107
  };
108
108
  transformImgUrl: {
109
- type: import("vue").PropType<(t: string) => string>;
109
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
110
110
  default: (t: string) => string;
111
111
  };
112
112
  modelValue: {
@@ -306,7 +306,7 @@ declare const Editor: import('vue').DefineComponent<{
306
306
  type: import("vue").PropType<(width: string) => void>;
307
307
  };
308
308
  transformImgUrl: {
309
- type: import("vue").PropType<(t: string) => string>;
309
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
310
310
  default: (t: string) => string;
311
311
  };
312
312
  modelValue: {
@@ -428,7 +428,7 @@ declare const Editor: import('vue').DefineComponent<{
428
428
  scrollAuto: boolean;
429
429
  showToolbarName: boolean;
430
430
  inputBoxWitdh: string;
431
- transformImgUrl: (t: string) => string;
431
+ transformImgUrl: (t: string) => string | Promise<string>;
432
432
  modelValue: string;
433
433
  theme: import("~/type").Themes;
434
434
  editorId: string;
@@ -21,7 +21,7 @@ declare const _default: {
21
21
  scrollAuto: boolean;
22
22
  showToolbarName: boolean;
23
23
  inputBoxWitdh: string;
24
- transformImgUrl: (t: string) => string;
24
+ transformImgUrl: (t: string) => string | Promise<string>;
25
25
  modelValue: string;
26
26
  theme: import('./type').Themes;
27
27
  editorId: string;
@@ -147,7 +147,7 @@ declare const _default: {
147
147
  type: import("vue").PropType<(width: string) => void>;
148
148
  };
149
149
  transformImgUrl: {
150
- type: import("vue").PropType<(t: string) => string>;
150
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
151
151
  default: (t: string) => string;
152
152
  };
153
153
  modelValue: {
@@ -374,7 +374,7 @@ declare const _default: {
374
374
  type: import("vue").PropType<(width: string) => void>;
375
375
  };
376
376
  transformImgUrl: {
377
- type: import("vue").PropType<(t: string) => string>;
377
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
378
378
  default: (t: string) => string;
379
379
  };
380
380
  modelValue: {
@@ -496,7 +496,7 @@ declare const _default: {
496
496
  scrollAuto: boolean;
497
497
  showToolbarName: boolean;
498
498
  inputBoxWitdh: string;
499
- transformImgUrl: (t: string) => string;
499
+ transformImgUrl: (t: string) => string | Promise<string>;
500
500
  modelValue: string;
501
501
  theme: import("./type").Themes;
502
502
  editorId: string;
@@ -642,7 +642,7 @@ declare const _default: {
642
642
  type: import("vue").PropType<(width: string) => void>;
643
643
  };
644
644
  transformImgUrl: {
645
- type: import("vue").PropType<(t: string) => string>;
645
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
646
646
  default: (t: string) => string;
647
647
  };
648
648
  modelValue: {
@@ -859,7 +859,7 @@ declare const _default: {
859
859
  type: import("vue").PropType<(width: string) => void>;
860
860
  };
861
861
  transformImgUrl: {
862
- type: import("vue").PropType<(t: string) => string>;
862
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
863
863
  default: (t: string) => string;
864
864
  };
865
865
  modelValue: {
@@ -981,7 +981,7 @@ declare const _default: {
981
981
  scrollAuto: boolean;
982
982
  showToolbarName: boolean;
983
983
  inputBoxWitdh: string;
984
- transformImgUrl: (t: string) => string;
984
+ transformImgUrl: (t: string) => string | Promise<string>;
985
985
  modelValue: string;
986
986
  theme: import("./type").Themes;
987
987
  editorId: string;
@@ -64,7 +64,7 @@ declare const _default: import('vue').DefineComponent<{
64
64
  type: import("vue").PropType<(width: string) => void>;
65
65
  };
66
66
  transformImgUrl: {
67
- type: import("vue").PropType<(t: string) => string>;
67
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
68
68
  default: (t: string) => string;
69
69
  };
70
70
  modelValue: {
@@ -185,7 +185,7 @@ declare const _default: import('vue').DefineComponent<{
185
185
  type: import("vue").PropType<(width: string) => void>;
186
186
  };
187
187
  transformImgUrl: {
188
- type: import("vue").PropType<(t: string) => string>;
188
+ type: import("vue").PropType<(t: string) => string | Promise<string>>;
189
189
  default: (t: string) => string;
190
190
  };
191
191
  modelValue: {
@@ -249,7 +249,7 @@ declare const _default: import('vue').DefineComponent<{
249
249
  onFocus: (event: FocusEvent) => void;
250
250
  onDrop: (event: DragEvent) => void;
251
251
  placeholder: string;
252
- transformImgUrl: (t: string) => string;
252
+ transformImgUrl: (t: string) => string | Promise<string>;
253
253
  modelValue: string;
254
254
  theme: import("~/type").Themes;
255
255
  mdHeadingId: import("~/type").MdHeadingId;
@@ -129,7 +129,7 @@ export declare const contentProps: {
129
129
  type: PropType<(width: string) => void>;
130
130
  };
131
131
  transformImgUrl: {
132
- type: PropType<(t: string) => string>;
132
+ type: PropType<(t: string) => string | Promise<string>>;
133
133
  default: (t: string) => string;
134
134
  };
135
135
  modelValue: {
@@ -446,7 +446,7 @@ export declare const editorProps: {
446
446
  * @returns
447
447
  */
448
448
  transformImgUrl: {
449
- type: PropType<(t: string) => string>;
449
+ type: PropType<(t: string) => string | Promise<string>>;
450
450
  default: (t: string) => string;
451
451
  };
452
452
  /**