md-editor-v3 4.3.0-beta.1 → 4.3.0-beta.3

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.
Files changed (37) hide show
  1. package/README.md +60 -8
  2. package/lib/cjs/MdCatalog.cjs +1 -1
  3. package/lib/cjs/MdEditor.cjs +25 -25
  4. package/lib/cjs/MdModal.cjs +1 -0
  5. package/lib/cjs/MdPreview.cjs +1 -1
  6. package/lib/cjs/ModalToolbar.cjs +1 -1
  7. package/lib/cjs/chunks/config.cjs +1 -1
  8. package/lib/cjs/chunks/index.cjs +7 -7
  9. package/lib/cjs/chunks/index2.cjs +1 -1
  10. package/lib/cjs/chunks/index3.cjs +2 -1
  11. package/lib/cjs/index.cjs +1 -1
  12. package/lib/es/MdCatalog.mjs +1 -1
  13. package/lib/es/MdEditor.mjs +1046 -971
  14. package/lib/es/MdModal.mjs +141 -0
  15. package/lib/es/MdPreview.mjs +1 -1
  16. package/lib/es/ModalToolbar.mjs +97 -5
  17. package/lib/es/chunks/config.mjs +2 -1
  18. package/lib/es/chunks/index.mjs +369 -321
  19. package/lib/es/chunks/index2.mjs +46 -40
  20. package/lib/es/chunks/index3.mjs +61 -227
  21. package/lib/es/index.mjs +4 -2
  22. package/lib/style.css +1 -1
  23. package/lib/types/DropdownToolbar/DropdownToolbar.d.ts +6 -0
  24. package/lib/types/DropdownToolbar/index.d.ts +12 -0
  25. package/lib/types/MdEditor/Editor.d.ts +9 -0
  26. package/lib/types/MdEditor/components/Modal/Modal.d.ts +78 -0
  27. package/lib/types/MdEditor/components/Modal/index.d.ts +173 -51
  28. package/lib/types/MdEditor/index.d.ts +20 -1
  29. package/lib/types/MdEditor/layouts/Toolbar/index.d.ts +6 -0
  30. package/lib/types/MdEditor/layouts/Toolbar/props.d.ts +8 -0
  31. package/lib/types/MdEditor/props.d.ts +9 -0
  32. package/lib/types/MdEditor/type.d.ts +13 -0
  33. package/lib/types/index.d.ts +1 -0
  34. package/lib/umd/index.js +42 -42
  35. package/package.json +2 -2
  36. package/lib/cjs/chunks/index4.cjs +0 -2
  37. package/lib/es/chunks/index4.mjs +0 -69
@@ -1,6 +1,6 @@
1
- import { defineComponent as H, reactive as E, ref as C, watch as T, onMounted as D, onBeforeUnmount as $, cloneVNode as O, createVNode as c, inject as j } from "vue";
2
- import { p as g } from "./config.mjs";
3
- import { g as u } from "./vue-tsx.mjs";
1
+ import { defineComponent as S, reactive as E, ref as C, watch as T, onMounted as D, onBeforeUnmount as O, cloneVNode as $, createVNode as u, inject as j } from "vue";
2
+ import { p as d } from "./config.mjs";
3
+ import { g as v } from "./vue-tsx.mjs";
4
4
  const B = {
5
5
  overlay: {
6
6
  type: [String, Object],
@@ -20,58 +20,58 @@ const B = {
20
20
  type: String,
21
21
  default: "html"
22
22
  }
23
- }, F = /* @__PURE__ */ H({
23
+ }, F = /* @__PURE__ */ S({
24
24
  props: B,
25
25
  setup(e, a) {
26
- const i = `${g}-dropdown-hidden`, t = E({
26
+ const i = `${d}-dropdown-hidden`, t = E({
27
27
  overlayClass: [i],
28
28
  overlayStyle: {},
29
29
  triggerHover: !1,
30
30
  overlayHover: !1
31
- }), r = C(), n = C(), y = () => {
31
+ }), o = C(), n = C(), s = () => {
32
32
  var p;
33
33
  t.triggerHover = !0;
34
- const o = r.value, l = n.value;
35
- if (!o || !l)
34
+ const r = o.value, l = n.value;
35
+ if (!r || !l)
36
36
  return;
37
- const v = o.getBoundingClientRect(), d = o.offsetTop, L = o.offsetLeft, S = v.height, b = v.width, w = ((p = document.querySelector(e.relative)) == null ? void 0 : p.scrollLeft) || 0;
37
+ const c = r.getBoundingClientRect(), f = r.offsetTop, b = r.offsetLeft, H = c.height, L = c.width, w = ((p = document.querySelector(e.relative)) == null ? void 0 : p.scrollLeft) || 0;
38
38
  t.overlayStyle = {
39
39
  ...t.overlayStyle,
40
- top: d + S + "px",
41
- left: L - l.offsetWidth / 2 + b / 2 - w + "px"
40
+ top: f + H + "px",
41
+ left: b - l.offsetWidth / 2 + L / 2 - w + "px"
42
42
  }, e.onChange(!0);
43
43
  }, m = () => {
44
44
  t.overlayHover = !0;
45
45
  };
46
- T(() => e.visible, (o) => {
47
- o ? t.overlayClass = t.overlayClass.filter((l) => l !== i) : t.overlayClass.push(i);
46
+ T(() => e.visible, (r) => {
47
+ r ? t.overlayClass = t.overlayClass.filter((l) => l !== i) : t.overlayClass.push(i);
48
48
  });
49
49
  let h = -1;
50
- const s = (o) => {
51
- r.value === o.target ? t.triggerHover = !1 : t.overlayHover = !1, clearTimeout(h), h = window.setTimeout(() => {
50
+ const g = (r) => {
51
+ o.value === r.target ? t.triggerHover = !1 : t.overlayHover = !1, clearTimeout(h), h = window.setTimeout(() => {
52
52
  !t.overlayHover && !t.triggerHover && e.onChange(!1);
53
53
  }, 10);
54
54
  };
55
55
  return D(() => {
56
- r.value.addEventListener("mouseenter", y), r.value.addEventListener("mouseleave", s), n.value.addEventListener("mouseenter", m), n.value.addEventListener("mouseleave", s);
57
- }), $(() => {
58
- r.value.removeEventListener("mouseenter", y), r.value.removeEventListener("mouseleave", s), n.value.removeEventListener("mouseenter", m), n.value.removeEventListener("mouseleave", s);
56
+ o.value.addEventListener("mouseenter", s), o.value.addEventListener("mouseleave", g), n.value.addEventListener("mouseenter", m), n.value.addEventListener("mouseleave", g);
57
+ }), O(() => {
58
+ o.value.removeEventListener("mouseenter", s), o.value.removeEventListener("mouseleave", g), n.value.removeEventListener("mouseenter", m), n.value.removeEventListener("mouseleave", g);
59
59
  }), () => {
60
- const o = u({
60
+ const r = v({
61
61
  ctx: a
62
- }), l = u({
62
+ }), l = v({
63
63
  props: e,
64
64
  ctx: a
65
- }, "overlay"), v = O(o instanceof Array ? o[0] : o, {
66
- ref: r
67
- }), d = c("div", {
68
- class: [`${g}-dropdown`, t.overlayClass],
65
+ }, "overlay"), c = $(r instanceof Array ? r[0] : r, {
66
+ ref: o
67
+ }), f = u("div", {
68
+ class: [`${d}-dropdown`, t.overlayClass],
69
69
  style: t.overlayStyle,
70
70
  ref: n
71
- }, [c("div", {
72
- class: `${g}-dropdown-overlay`
71
+ }, [u("div", {
72
+ class: `${d}-dropdown-overlay`
73
73
  }, [l instanceof Array ? l[0] : l])]);
74
- return [v, d];
74
+ return [c, f];
75
75
  };
76
76
  }
77
77
  }), I = {
@@ -98,39 +98,45 @@ const B = {
98
98
  */
99
99
  insert: {
100
100
  type: Function
101
+ },
102
+ children: {
103
+ type: [String, Object]
101
104
  }
102
- }, f = /* @__PURE__ */ H({
105
+ }, y = /* @__PURE__ */ S({
103
106
  name: "DropdownToolbar",
104
107
  props: I,
105
108
  emits: ["onChange"],
106
109
  setup(e, a) {
107
110
  const i = j("editorId");
108
111
  return () => {
109
- const t = u({
112
+ const t = v({
110
113
  props: e,
111
114
  ctx: a
112
- }, "trigger"), r = u({
115
+ }, "trigger"), o = v({
113
116
  props: e,
114
117
  ctx: a
115
- }, "overlay");
116
- return c(F, {
118
+ }, "overlay"), n = v({
119
+ props: e,
120
+ ctx: a
121
+ });
122
+ return u(F, {
117
123
  relative: `#${i}-toolbar-wrapper`,
118
124
  visible: e.visible,
119
- onChange: (n) => {
120
- e.onChange instanceof Function ? e.onChange(n) : a.emit("onChange", n);
125
+ onChange: (s) => {
126
+ e.onChange instanceof Function ? e.onChange(s) : a.emit("onChange", s);
121
127
  },
122
- overlay: r
128
+ overlay: o
123
129
  }, {
124
- default: () => [c("div", {
125
- class: `${g}-toolbar-item`,
130
+ default: () => [u("div", {
131
+ class: `${d}-toolbar-item`,
126
132
  title: e.title || ""
127
- }, [t])]
133
+ }, [t, n])]
128
134
  });
129
135
  };
130
136
  }
131
137
  });
132
- f.install = (e) => (e.component(f.name, f), e);
138
+ y.install = (e) => (e.component(y.name, y), e);
133
139
  export {
134
- f as D,
140
+ y as D,
135
141
  F as a
136
142
  };
@@ -1,235 +1,69 @@
1
- import { defineComponent as C, ref as r, reactive as b, computed as P, onMounted as w, onBeforeUnmount as A, watch as v, nextTick as S, createVNode as t, Fragment as $, isVNode as x } from "vue";
2
- import { p as n } from "./config.mjs";
3
- import { g as h } from "./vue-tsx.mjs";
4
- import { k as y } from "./dom.mjs";
5
- const T = {
6
- title: {
7
- type: String,
8
- default: ""
9
- },
10
- visible: {
11
- type: Boolean,
12
- default: !1
13
- },
14
- width: {
15
- type: String,
16
- default: "auto"
17
- },
18
- height: {
19
- type: String,
20
- default: "auto"
21
- },
22
- onClose: {
23
- type: Function,
24
- default: () => {
25
- }
26
- },
27
- showAdjust: {
28
- type: Boolean,
29
- default: !1
30
- },
31
- isFullscreen: {
32
- type: Boolean,
33
- default: !1
34
- },
35
- onAdjust: {
36
- type: Function,
37
- default: () => {
38
- }
39
- },
40
- class: {
41
- type: String
1
+ var a = Object.defineProperty;
2
+ var c = (o, t, s) => t in o ? a(o, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[t] = s;
3
+ var p = (o, t, s) => (c(o, typeof t != "symbol" ? t + "" : t, s), s);
4
+ class u {
5
+ constructor() {
6
+ // 事件池
7
+ p(this, "pools", {});
42
8
  }
43
- }, B = /* @__PURE__ */ C({
44
- props: T,
45
- setup(e, a) {
46
- const c = r(e.visible), o = r([`${n}-modal`]), d = r(), m = r();
47
- let f = () => {
48
- };
49
- const l = b({
50
- initPos: {
51
- left: "0px",
52
- top: "0px"
53
- },
54
- historyPos: {
55
- left: "0px",
56
- top: "0px"
9
+ // 移除事件监听
10
+ remove(t, s, n) {
11
+ const i = this.pools[t] && this.pools[t][s];
12
+ i && (this.pools[t][s] = i.filter((r) => r !== n));
13
+ }
14
+ // 清空全部事件,由于单一实例,多次注册会被共享内容
15
+ clear(t) {
16
+ this.pools[t] = {};
17
+ }
18
+ // 注册事件监听
19
+ on(t, s) {
20
+ return this.pools[t] || (this.pools[t] = {}), this.pools[t][s.name] || (this.pools[t][s.name] = []), this.pools[t][s.name].push(s.callback), this.pools[t][s.name].includes(s.callback);
21
+ }
22
+ // 触发事件
23
+ emit(t, s, ...n) {
24
+ this.pools[t] || (this.pools[t] = {});
25
+ const i = this.pools[t][s];
26
+ i && i.forEach((r) => {
27
+ try {
28
+ r(...n);
29
+ } catch (l) {
30
+ console.error(`${s} monitor event exception!`, l);
57
31
  }
58
- }), F = P(() => e.isFullscreen ? {
59
- width: "100%",
60
- height: "100%"
61
- } : {
62
- width: e.width,
63
- height: e.height
64
32
  });
65
- return w(() => {
66
- f = y(m.value, (s, i) => {
67
- l.initPos.left = s + "px", l.initPos.top = i + "px";
68
- });
69
- }), A(() => {
70
- f();
71
- }), v(() => e.isFullscreen, (s) => {
72
- s ? f() : f = y(m.value, (i, u) => {
73
- l.initPos.left = i + "px", l.initPos.top = u + "px";
74
- });
75
- }), v(() => e.visible, (s) => {
76
- s ? (o.value.push("zoom-in"), c.value = s, S(() => {
77
- const i = d.value.offsetWidth / 2, u = d.value.offsetHeight / 2, j = document.documentElement.clientWidth / 2, k = document.documentElement.clientHeight / 2;
78
- l.initPos.left = j - i + "px", l.initPos.top = k - u + "px";
79
- }), setTimeout(() => {
80
- o.value = o.value.filter((i) => i !== "zoom-in");
81
- }, 140)) : (o.value.push("zoom-out"), setTimeout(() => {
82
- o.value = o.value.filter((i) => i !== "zoom-out"), c.value = s;
83
- }, 130));
84
- }), () => {
85
- const s = h({
86
- ctx: a
87
- }), i = h({
88
- props: e,
89
- ctx: a
90
- }, "title");
91
- return t("div", {
92
- class: [e.class],
93
- style: {
94
- display: c.value ? "block" : "none"
95
- }
96
- }, [t("div", {
97
- class: `${n}-modal-mask`,
98
- onClick: e.onClose
99
- }, null), t("div", {
100
- class: o.value,
101
- style: {
102
- ...l.initPos,
103
- ...F.value
104
- },
105
- ref: d
106
- }, [t("div", {
107
- class: `${n}-modal-header`,
108
- ref: m
109
- }, [i || ""]), t("div", {
110
- class: `${n}-modal-body`
111
- }, [s]), t("div", {
112
- class: `${n}-modal-func`
113
- }, [e.showAdjust && t("div", {
114
- class: `${n}-modal-adjust`,
115
- onClick: (u) => {
116
- u.stopPropagation(), e.isFullscreen ? l.initPos = l.historyPos : (l.historyPos = l.initPos, l.initPos = {
117
- left: "0",
118
- top: "0"
119
- }), e.onAdjust(!e.isFullscreen);
120
- }
121
- }, [t("svg", {
122
- class: `${n}-icon`,
123
- "aria-hidden": "true"
124
- }, [t("use", {
125
- "xlink:href": `#md-editor-icon-${e.isFullscreen ? "suoxiao" : "fangda"}`
126
- }, null)])]), t("div", {
127
- class: `${n}-modal-close`,
128
- onClick: (u) => {
129
- u.stopPropagation(), e.onClose && e.onClose();
130
- }
131
- }, [t("svg", {
132
- class: `${n}-icon`,
133
- "aria-hidden": "true"
134
- }, [t("use", {
135
- "xlink:href": "#md-editor-icon-close"
136
- }, null)])])])])]);
137
- };
138
33
  }
139
- });
140
- function M(e) {
141
- return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !x(e);
142
34
  }
143
- const p = {
144
- title: {
145
- type: String,
146
- default: ""
147
- },
148
- modalTitle: {
149
- type: String,
150
- default: ""
151
- },
152
- visible: {
153
- type: Boolean
154
- },
155
- width: {
156
- type: String,
157
- default: "auto"
158
- },
159
- height: {
160
- type: String,
161
- default: "auto"
162
- },
163
- // 展示在工具栏的内容,通常是个图标
164
- trigger: {
165
- type: [String, Object]
166
- },
167
- onClick: {
168
- type: Function
169
- },
170
- onClose: {
171
- type: Function
172
- },
173
- /**
174
- * 显示全屏按钮
175
- */
176
- showAdjust: {
177
- type: Boolean,
178
- default: !1
179
- },
180
- isFullscreen: {
181
- type: Boolean,
182
- default: !1
183
- },
184
- onAdjust: {
185
- type: Function
186
- },
187
- /**
188
- * 没有意义,仅用于规避克隆组件自动嵌入insert方法时,传入的是该组件而产生的waring
189
- */
190
- insert: {
191
- type: Function
192
- }
193
- }, g = /* @__PURE__ */ C({
194
- name: "ModalToolbar",
195
- props: p,
196
- emits: ["onClick", "onClose", "onAdjust"],
197
- setup(e, a) {
198
- return () => {
199
- const c = h({
200
- props: e,
201
- ctx: a
202
- }, "trigger"), o = h({
203
- props: e,
204
- ctx: a
205
- }, "default");
206
- return t($, null, [t("div", {
207
- class: `${n}-toolbar-item`,
208
- title: e.title,
209
- onClick: () => {
210
- e.onClick instanceof Function ? e.onClick() : a.emit("onClick");
211
- }
212
- }, [c]), t(B, {
213
- width: e.width,
214
- height: e.height,
215
- title: e.modalTitle,
216
- visible: e.visible,
217
- onClose: () => {
218
- e.onClose instanceof Function ? e.onClose() : a.emit("onClose");
219
- },
220
- showAdjust: e.showAdjust,
221
- isFullscreen: e.isFullscreen,
222
- onAdjust: (d) => {
223
- e.onAdjust instanceof Function ? e.onAdjust(d) : a.emit("onAdjust", d);
224
- }
225
- }, M(o) ? o : {
226
- default: () => [o]
227
- })]);
228
- };
35
+ const g = new u(), f = (o, t = "image.png") => {
36
+ const s = o.split(","), n = s[0].match(/:(.*?);/);
37
+ if (n) {
38
+ const e = n[1], i = atob(s[1]);
39
+ let r = i.length;
40
+ const l = new Uint8Array(r);
41
+ for (; r--; )
42
+ l[r] = i.charCodeAt(r);
43
+ return new File([l], t, { type: e });
229
44
  }
230
- });
231
- g.install = (e) => (e.component(g.name, g), e);
45
+ return null;
46
+ }, b = (o) => {
47
+ if (!o)
48
+ return o;
49
+ const t = o.split(`
50
+ `), s = ['<span rn-wrapper aria-hidden="true">'];
51
+ return t.forEach(() => {
52
+ s.push("<span></span>");
53
+ }), s.push("</span>"), `<span class="code-block">${o}</span>${s.join("")}`;
54
+ }, R = (o, t) => {
55
+ if (!o || !t)
56
+ return 0;
57
+ const s = o == null ? void 0 : o.getBoundingClientRect();
58
+ if (t === document.documentElement)
59
+ return s.top - t.clientTop;
60
+ const n = t == null ? void 0 : t.getBoundingClientRect();
61
+ return s.top - n.top;
62
+ }, m = () => `${Date.now().toString(36)}${Math.random().toString(36).substring(2)}`;
232
63
  export {
233
- g as M,
234
- B as a
64
+ f as a,
65
+ g as b,
66
+ R as c,
67
+ b as g,
68
+ m as u
235
69
  };
package/lib/es/index.mjs CHANGED
@@ -2,12 +2,13 @@ import { default as C } from "./MdEditor.mjs";
2
2
  import { M as N } from "./chunks/index.mjs";
3
3
  import { default as h } from "./NormalToolbar.mjs";
4
4
  import { D as k } from "./chunks/index2.mjs";
5
- import { M as y } from "./chunks/index3.mjs";
5
+ import { default as y } from "./ModalToolbar.mjs";
6
6
  import { default as A } from "./MdCatalog.mjs";
7
7
  import { c as F } from "./chunks/config.mjs";
8
+ import { default as H } from "./MdModal.mjs";
8
9
  import "vue";
9
- import "./chunks/index4.mjs";
10
10
  import "@vavt/util";
11
+ import "./chunks/index3.mjs";
11
12
  import "./chunks/dom.mjs";
12
13
  import "codemirror";
13
14
  import "@codemirror/view";
@@ -30,6 +31,7 @@ export {
30
31
  k as DropdownToolbar,
31
32
  A as MdCatalog,
32
33
  C as MdEditor,
34
+ H as MdModal,
33
35
  N as MdPreview,
34
36
  y as ModalToolbar,
35
37
  h as NormalToolbar,