md-editor-v3 6.5.6 → 7.0.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.
@@ -1,38 +1,205 @@
1
- import { p } from "./config.mjs";
2
- const u = (t, e = "image.png") => {
3
- const r = t.split(","), n = r[0].match(/:(.*?);/);
4
- if (n) {
5
- const c = n[1], o = atob(r[1]);
6
- let s = o.length;
7
- const a = new Uint8Array(s);
8
- for (; s--; )
9
- a[s] = o.charCodeAt(s);
10
- return new File([a], e, { type: c });
1
+ import { p as d } from "./config.mjs";
2
+ const w = /^<\s*(\/?)\s*([a-zA-Z][a-zA-Z0-9:_-]*)(?:\s[\s\S]*?)?\s*(\/?)>$/, A = /* @__PURE__ */ new Set([
3
+ "area",
4
+ "base",
5
+ "br",
6
+ "col",
7
+ "embed",
8
+ "hr",
9
+ "img",
10
+ "input",
11
+ "link",
12
+ "meta",
13
+ "param",
14
+ "source",
15
+ "track",
16
+ "wbr"
17
+ ]), R = (e) => e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;"), S = (e) => {
18
+ const n = e.replace(/\r\n?/g, `
19
+ `), t = n.endsWith(`
20
+ `) ? n.slice(0, -1) : n;
21
+ return t ? t.split(`
22
+ `) : [""];
23
+ }, p = (e, n) => {
24
+ if (e.startsWith("<!--", n)) {
25
+ const s = e.indexOf("-->", n + 4);
26
+ return s === -1 ? -1 : s + 2;
27
+ }
28
+ if (e.startsWith("<![CDATA[", n)) {
29
+ const s = e.indexOf("]]>", n + 9);
30
+ return s === -1 ? -1 : s + 2;
31
+ }
32
+ let t = "";
33
+ for (let s = n + 1; s < e.length; s += 1) {
34
+ const r = e[s];
35
+ if (t) {
36
+ r === t && (t = "");
37
+ continue;
38
+ }
39
+ if (r === '"' || r === "'")
40
+ t = r;
41
+ else if (r === ">")
42
+ return s;
43
+ }
44
+ return -1;
45
+ }, x = (e) => {
46
+ const n = w.exec(e);
47
+ if (!n)
48
+ return null;
49
+ const t = n[2].toLowerCase();
50
+ return {
51
+ isClosing: n[1] === "/",
52
+ isSelfClosing: n[3] === "/" || A.has(t),
53
+ name: t,
54
+ source: e
55
+ };
56
+ }, f = (e, n) => {
57
+ const t = e.indexOf("<", n);
58
+ if (t === -1)
59
+ return null;
60
+ const s = p(e, t);
61
+ return s === -1 ? null : {
62
+ endIndex: s,
63
+ parsedTag: x(e.slice(t, s + 1)),
64
+ startIndex: t
65
+ };
66
+ }, L = (e) => e.map((n) => n.openingTag).join(""), H = (e) => [...e].reverse().map((n) => `</${n.name}>`).join(""), E = (e) => {
67
+ let n = 0;
68
+ for (; n < e.length; ) {
69
+ const t = f(e, n), s = t?.startIndex ?? e.length;
70
+ if (e.slice(n, s).trim())
71
+ return !0;
72
+ if (!t)
73
+ return !1;
74
+ n = t.endIndex + 1;
75
+ }
76
+ return !1;
77
+ }, M = (e) => {
78
+ const n = f(e, 0);
79
+ if (!n || n.startIndex !== 0 || n.parsedTag?.name !== "pre" || n.parsedTag.isClosing || n.parsedTag.isSelfClosing)
80
+ return null;
81
+ let t = 0, s = -1, r = n.endIndex + 1;
82
+ for (; r < e.length; ) {
83
+ const i = f(e, r);
84
+ if (!i)
85
+ break;
86
+ const o = i.parsedTag;
87
+ if (!o) {
88
+ r = i.endIndex + 1;
89
+ continue;
90
+ }
91
+ if (o.name === "pre" && o.isClosing && t === 0)
92
+ break;
93
+ if (o.name === "code")
94
+ if (o.isClosing) {
95
+ if (t > 0 && (t -= 1, t === 0))
96
+ return {
97
+ endIndex: i.startIndex,
98
+ startIndex: s
99
+ };
100
+ } else o.isSelfClosing || (t === 0 && (s = i.endIndex + 1), t += 1);
101
+ r = i.endIndex + 1;
102
+ }
103
+ return null;
104
+ }, k = (e) => {
105
+ const n = e.replace(/\r\n?/g, `
106
+ `), t = [""], s = [];
107
+ let r = 0, i = 0;
108
+ for (; i < n.length; ) {
109
+ const o = n[i];
110
+ if (o === "<") {
111
+ const l = p(n, i);
112
+ if (l === -1) {
113
+ t[r] += n.slice(i);
114
+ break;
115
+ }
116
+ const g = n.slice(i, l + 1), c = x(g);
117
+ if (t[r] += g, c)
118
+ if (c.isClosing) {
119
+ for (let a = s.length - 1; a >= 0; a -= 1)
120
+ if (s[a].name === c.name) {
121
+ s.splice(a, 1);
122
+ break;
123
+ }
124
+ } else c.isSelfClosing || s.push({
125
+ name: c.name,
126
+ openingTag: c.source
127
+ });
128
+ i = l + 1;
129
+ continue;
130
+ }
131
+ if (o === `
132
+ `) {
133
+ t[r] += H(s), t.push(L(s)), r += 1, i += 1;
134
+ continue;
135
+ }
136
+ t[r] += o, i += 1;
137
+ }
138
+ return t;
139
+ }, G = (e, n = "image.png") => {
140
+ const t = e.split(","), s = t[0].match(/:(.*?);/);
141
+ if (s) {
142
+ const r = s[1], i = atob(t[1]);
143
+ let o = i.length;
144
+ const l = new Uint8Array(o);
145
+ for (; o--; )
146
+ l[o] = i.charCodeAt(o);
147
+ return new File([l], n, { type: r });
11
148
  }
12
149
  return null;
13
- }, l = (t, e) => {
14
- if (!t)
15
- return t;
16
- const r = e.split(`
17
- `), n = ['<span rn-wrapper aria-hidden="true">'];
18
- return r.forEach(() => {
19
- n.push("<span></span>");
20
- }), n.push("</span>"), `<span class="${p}-code-block">${t}</span>${n.join("")}`;
21
- }, g = (t, e) => {
22
- if (!t || !e)
150
+ }, y = (e, n, t = {}) => {
151
+ const { lineHighlightRanges: s = [], showLineNumber: r = !1 } = t, i = S(n), o = k(e);
152
+ for (; o.length > i.length && !E(o[o.length - 1]); )
153
+ o.pop();
154
+ const l = o.length === i.length, g = i.map((a, h) => {
155
+ const m = l ? o[h] : R(a), u = h + 1, I = s.some(
156
+ ({ start: b, end: $ }) => u >= b && u <= $
157
+ ), C = [
158
+ `${d}-code-line`,
159
+ r ? `${d}-code-line-numbered` : "",
160
+ I ? `${d}-code-line-highlight` : ""
161
+ ].filter(Boolean).join(" "), T = r ? `<span rn-wrapper aria-hidden="true" data-line-number="${u}"></span>` : "";
162
+ return [
163
+ `<span class="${C}">`,
164
+ T,
165
+ `<span class="${d}-code-line-content">${m}</span>`,
166
+ "</span>"
167
+ ].join("");
168
+ }), c = r ? ` style="--md-code-line-number-width: ${Math.max(2, String(i.length).length) + 0.5}ch;"` : "";
169
+ return `<span class="${d}-code-block-lines"${c}>${g.join(`
170
+ `)}</span>`;
171
+ }, B = (e, n, t = {}) => {
172
+ const s = M(e);
173
+ if (!s)
174
+ return null;
175
+ const r = y(
176
+ e.slice(s.startIndex, s.endIndex),
177
+ n,
178
+ t
179
+ );
180
+ return `${e.slice(0, s.startIndex)}${r}${e.slice(s.endIndex)}`;
181
+ }, N = (e, n, t = {}) => {
182
+ const { lineHighlightRanges: s = [], showLineNumber: r = !1 } = t;
183
+ return !r && !s.length ? { html: e, shouldReturnDirectly: !0 } : e.startsWith("<pre") ? {
184
+ html: B(e, n, t) ?? e,
185
+ shouldReturnDirectly: !0
186
+ } : { html: e, shouldReturnDirectly: !1 };
187
+ }, j = (e, n) => {
188
+ if (!e || !n)
23
189
  return 0;
24
- const r = t?.getBoundingClientRect();
25
- if (e === document.documentElement)
26
- return r.top - e.clientTop;
27
- const n = e?.getBoundingClientRect();
28
- return r.top - n.top;
29
- }, m = /* @__PURE__ */ (() => {
30
- let t = 0;
31
- return () => ++t;
190
+ const t = e?.getBoundingClientRect();
191
+ if (n === document.documentElement)
192
+ return t.top - n.clientTop;
193
+ const s = n?.getBoundingClientRect();
194
+ return t.top - s.top;
195
+ }, W = /* @__PURE__ */ (() => {
196
+ let e = 0;
197
+ return () => ++e;
32
198
  })();
33
199
  export {
34
- l as a,
35
- u as b,
36
- m as c,
37
- g
200
+ y as a,
201
+ G as b,
202
+ W as c,
203
+ j as g,
204
+ N as p
38
205
  };
package/lib/preview.css CHANGED
@@ -49,7 +49,7 @@
49
49
  color: #73d13d;
50
50
  }
51
51
 
52
- .md-editor-catalog-dark {
52
+ .md-editor-catalog[data-theme=dark] {
53
53
  --md-color: #999;
54
54
  --md-hover-color: #bbb;
55
55
  --md-bk-color: #000;
@@ -177,7 +177,7 @@
177
177
  overflow: visible;
178
178
  }
179
179
 
180
- .md-editor-dark,
180
+ .md-editor[data-theme=dark],
181
181
  .md-editor-modal-container[data-theme=dark] {
182
182
  --md-color: #999;
183
183
  --md-hover-color: #bbb;
package/lib/style.css CHANGED
@@ -517,10 +517,10 @@
517
517
  padding-inline: 6px;
518
518
  }
519
519
 
520
- .md-editor-dark .md-editor-table-shape-col-default {
520
+ .md-editor[data-theme=dark] .md-editor-table-shape-col-default {
521
521
  background-color: #222;
522
522
  }
523
- .md-editor-dark .md-editor-table-shape-col-include {
523
+ .md-editor[data-theme=dark] .md-editor-table-shape-col-include {
524
524
  background-color: #555;
525
525
  }
526
526
 
@@ -730,7 +730,7 @@
730
730
  color: #73d13d;
731
731
  }
732
732
 
733
- .md-editor-catalog-dark {
733
+ .md-editor-catalog[data-theme=dark] {
734
734
  --md-color: #999;
735
735
  --md-hover-color: #bbb;
736
736
  --md-bk-color: #000;
@@ -858,7 +858,7 @@
858
858
  overflow: visible;
859
859
  }
860
860
 
861
- .md-editor-dark,
861
+ .md-editor[data-theme=dark],
862
862
  .md-editor-modal-container[data-theme=dark] {
863
863
  --md-color: #999;
864
864
  --md-hover-color: #bbb;
@@ -516,7 +516,7 @@ declare const editorProps: {
516
516
  /**
517
517
  * 输入框宽度变化事件
518
518
  */
519
- oninputBoxWidthChange: {
519
+ onInputBoxWidthChange: {
520
520
  type: PropType<(width: string) => void>;
521
521
  default: undefined;
522
522
  };
@@ -1028,10 +1028,10 @@ interface GlobalConfig {
1028
1028
  instance?: any;
1029
1029
  js?: string;
1030
1030
  /**
1031
- * 解析echarts代码块内容。
1031
+ * 解析 ECharts 代码块内容。
1032
1032
  *
1033
- * 默认实现会使用new Function以兼容官方配置中的函数写法;当内容来源不可信时,
1034
- * 业务侧应通过该方法替换为更严格的解析策略。
1033
+ * 从 v7.x 开始,默认基于 JSON5.parse 解析 JSON5 数据,并要求顶层为对象,不会执行代码块中的 JavaScript。
1034
+ * 如需函数回调等 JavaScript 配置可覆盖该方法;自定义解析器需要自行保证输入安全。
1035
1035
  */
1036
1036
  parseOption?: (code: string, options: {
1037
1037
  editorId: string;
@@ -1308,7 +1308,7 @@ interface ExposeParam {
1308
1308
  type ExposePreviewParam = Pick<ExposeParam, 'rerender'>;
1309
1309
  type EditorProps = Readonly<LooseRequired<Readonly<ExtractPropTypes<typeof editorProps>>>>;
1310
1310
  type MdPreviewProps = Readonly<LooseRequired<Readonly<ExtractPropTypes<typeof mdPreviewProps>>>>;
1311
- type EditorEmits = Array<'onChange' | 'onSave' | 'onUploadImg' | 'onHtmlChanged' | 'onGetCatalog' | 'onError' | 'update:modelValue' | 'onBlur' | 'onFocus' | 'onInput' | 'onDrop' | 'oninputBoxWidthChange' | 'onRemount'>;
1311
+ type EditorEmits = Array<'onChange' | 'onSave' | 'onUploadImg' | 'onHtmlChanged' | 'onGetCatalog' | 'onError' | 'update:modelValue' | 'onBlur' | 'onFocus' | 'onInput' | 'onDrop' | 'onInputBoxWidthChange' | 'onRemount'>;
1312
1312
  type EditorContext = SetupContext<EditorEmits>;
1313
1313
  type CustomStrIcon = {
1314
1314
  copy?: string;
@@ -1450,7 +1450,7 @@ declare const Editor: vue.DefineComponent<vue.ExtractPropTypes<{
1450
1450
  type: vue.PropType<string>;
1451
1451
  default: string;
1452
1452
  };
1453
- oninputBoxWidthChange: {
1453
+ onInputBoxWidthChange: {
1454
1454
  type: vue.PropType<(width: string) => void>;
1455
1455
  default: undefined;
1456
1456
  };
@@ -1582,7 +1582,7 @@ declare const Editor: vue.DefineComponent<vue.ExtractPropTypes<{
1582
1582
  type: vue.PropType<vue.Component>;
1583
1583
  default: undefined;
1584
1584
  };
1585
- }>, () => vue_jsx_runtime.JSX.Element, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, EditorEmits, "onChange" | "onSave" | "onUploadImg" | "onHtmlChanged" | "onGetCatalog" | "onError" | "update:modelValue" | "onBlur" | "onFocus" | "onInput" | "onDrop" | "oninputBoxWidthChange" | "onRemount", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1585
+ }>, () => vue_jsx_runtime.JSX.Element, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, EditorEmits, "onChange" | "onSave" | "onUploadImg" | "onHtmlChanged" | "onGetCatalog" | "onError" | "update:modelValue" | "onBlur" | "onFocus" | "onInput" | "onDrop" | "onInputBoxWidthChange" | "onRemount", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1586
1586
  onSave: {
1587
1587
  type: vue.PropType<SaveEvent>;
1588
1588
  default: undefined;
@@ -1703,7 +1703,7 @@ declare const Editor: vue.DefineComponent<vue.ExtractPropTypes<{
1703
1703
  type: vue.PropType<string>;
1704
1704
  default: string;
1705
1705
  };
1706
- oninputBoxWidthChange: {
1706
+ onInputBoxWidthChange: {
1707
1707
  type: vue.PropType<(width: string) => void>;
1708
1708
  default: undefined;
1709
1709
  };
@@ -1847,7 +1847,7 @@ declare const Editor: vue.DefineComponent<vue.ExtractPropTypes<{
1847
1847
  onOnFocus?: ((...args: any[]) => any) | undefined;
1848
1848
  onOnInput?: ((...args: any[]) => any) | undefined;
1849
1849
  onOnDrop?: ((...args: any[]) => any) | undefined;
1850
- onOninputBoxWidthChange?: ((...args: any[]) => any) | undefined;
1850
+ onOnInputBoxWidthChange?: ((...args: any[]) => any) | undefined;
1851
1851
  onOnRemount?: ((...args: any[]) => any) | undefined;
1852
1852
  }>, {
1853
1853
  preview: boolean;
@@ -1863,7 +1863,7 @@ declare const Editor: vue.DefineComponent<vue.ExtractPropTypes<{
1863
1863
  onFocus: (event: FocusEvent) => void;
1864
1864
  onInput: (event: Event) => void;
1865
1865
  onDrop: (event: DragEvent) => void;
1866
- oninputBoxWidthChange: (width: string) => void;
1866
+ onInputBoxWidthChange: (width: string) => void;
1867
1867
  onRemount: () => void;
1868
1868
  toolbars: ToolbarNames[];
1869
1869
  floatingToolbars: ToolbarNames[];
@@ -2800,7 +2800,7 @@ declare const MdPreview: vue.DefineComponent<{
2800
2800
  readonly editorId: string | undefined;
2801
2801
  readonly id: string | undefined;
2802
2802
  readonly previewComponent: vue.Component | undefined;
2803
- }, () => vue_jsx_runtime.JSX.Element, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, EditorEmits, "onChange" | "onSave" | "onUploadImg" | "onHtmlChanged" | "onGetCatalog" | "onError" | "update:modelValue" | "onBlur" | "onFocus" | "onInput" | "onDrop" | "oninputBoxWidthChange" | "onRemount", vue.PublicProps, Readonly<{
2803
+ }, () => vue_jsx_runtime.JSX.Element, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, EditorEmits, "onChange" | "onSave" | "onUploadImg" | "onHtmlChanged" | "onGetCatalog" | "onError" | "update:modelValue" | "onBlur" | "onFocus" | "onInput" | "onDrop" | "onInputBoxWidthChange" | "onRemount", vue.PublicProps, Readonly<{
2804
2804
  readonly modelValue: string;
2805
2805
  readonly theme: Themes;
2806
2806
  readonly class: string;
@@ -3047,7 +3047,7 @@ declare const MdPreview: vue.DefineComponent<{
3047
3047
  onOnFocus?: ((...args: any[]) => any) | undefined;
3048
3048
  onOnInput?: ((...args: any[]) => any) | undefined;
3049
3049
  onOnDrop?: ((...args: any[]) => any) | undefined;
3050
- onOninputBoxWidthChange?: ((...args: any[]) => any) | undefined;
3050
+ onOnInputBoxWidthChange?: ((...args: any[]) => any) | undefined;
3051
3051
  onOnRemount?: ((...args: any[]) => any) | undefined;
3052
3052
  }>, {
3053
3053
  onChange: ChangeEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md-editor-v3",
3
- "version": "6.5.6",
3
+ "version": "7.0.0-0",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "vue",
@@ -57,9 +57,10 @@
57
57
  "@lucide/vue": "^1.16.0",
58
58
  "@types/markdown-it": "^14.0.1",
59
59
  "@vavt/copy2clipboard": "^1.0.1",
60
- "@vavt/markdown-theme": "^5.0.2",
60
+ "@vavt/markdown-theme": "^6.0.0",
61
61
  "@vavt/util": "^2.1.2",
62
62
  "codemirror": "^6.0.2",
63
+ "json5": "^2.2.3",
63
64
  "markdown-it": "^14.0.0",
64
65
  "markdown-it-image-figures": "^2.1.1",
65
66
  "markdown-it-sub": "^2.0.0",