md-editor-v3 4.3.0-beta.0 → 4.3.0-beta.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.
@@ -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,