md-editor-v3 7.1.0 → 7.1.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.
@@ -1,7 +1,8 @@
1
- import { defineComponent as H, reactive as B, ref as w, watch as D, onMounted as $, onBeforeUnmount as N, cloneVNode as W, createVNode as c, inject as I } from "vue";
2
- import { p as i } from "./config.mjs";
3
- import { g as f } from "./vue-tsx.mjs";
4
- const O = {
1
+ import { defineComponent as N, computed as F, useId as O, ref as S, watchPostEffect as R, cloneVNode as $, createVNode as w, mergeProps as B, inject as L } from "vue";
2
+ import { p as g } from "./config.mjs";
3
+ import { g as K } from "./dom.mjs";
4
+ import { g as v } from "./vue-tsx.mjs";
5
+ const U = {
5
6
  overlay: {
6
7
  type: [String, Object],
7
8
  default: ""
@@ -24,67 +25,160 @@ const O = {
24
25
  type: Boolean,
25
26
  default: void 0
26
27
  }
27
- }, j = /* @__PURE__ */ H({
28
- name: `${i}-dropdown`,
29
- props: O,
30
- setup(e, a) {
31
- const d = `${i}-dropdown-hidden`, t = B({
32
- overlayClass: [d],
33
- overlayStyle: {},
34
- triggerHover: !1,
35
- overlayHover: !1
36
- }), o = w(), l = w(), u = () => {
37
- if (e.disabled)
38
- return !1;
39
- t.triggerHover = !0;
40
- const n = o.value, r = l.value;
41
- if (!n || !r)
28
+ }, j = `${g}-dropdown-hidden`, p = '[role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]', I = (t) => Array.from(t.querySelectorAll(p)).filter((l) => !l.matches(':disabled, [aria-disabled="true"]') && !l.closest('[hidden], [inert], [aria-hidden="true"]') && l.getClientRects().length > 0 && getComputedStyle(l).visibility === "visible"), H = /* @__PURE__ */ N({
29
+ name: `${g}-dropdown`,
30
+ props: U,
31
+ setup(t, l) {
32
+ const d = F(() => t.visible && !t.disabled), b = O(), c = S({}), i = S(), s = S();
33
+ let y = null, m = -1;
34
+ const T = (e) => {
35
+ const n = s.value, o = I(n), a = e === "last" ? o.at(-1) : o[0];
36
+ a && (a.tabIndex = -1), (a || K(n)[0] || n).focus({
37
+ preventScroll: !0
38
+ });
39
+ }, h = (e) => {
40
+ if (t.disabled) return;
41
+ if (clearTimeout(m), d.value && e) {
42
+ T(e);
42
43
  return;
43
- const g = n.getBoundingClientRect(), y = n.offsetTop, L = n.offsetLeft, E = g.height, T = g.width, p = n.getRootNode(), m = p.querySelector(e.relative)?.scrollLeft || 0, C = p.querySelector(e.relative)?.clientWidth || 0;
44
- let s = L - r.offsetWidth / 2 + T / 2 - m;
45
- s + r.offsetWidth > m + C && (s = m + C - r.offsetWidth), s < 0 && (s = 0), t.overlayStyle = {
46
- ...t.overlayStyle,
47
- insetBlockStart: y + E + "px",
48
- insetInlineStart: s + "px"
49
- }, e.onChange(!0);
50
- }, b = () => {
51
- if (e.disabled)
52
- return !1;
53
- t.overlayHover = !0;
44
+ }
45
+ const n = i.value, o = s.value;
46
+ if (!n || !o) return;
47
+ const {
48
+ width: a,
49
+ height: r
50
+ } = n.getBoundingClientRect(), f = n.getRootNode().querySelector(t.relative), x = f?.scrollLeft || 0, A = o.offsetWidth, M = n.offsetLeft + (a - A) / 2 - x, P = x + (f?.clientWidth || 0) - A;
51
+ c.value = {
52
+ insetBlockStart: n.offsetTop + r + "px",
53
+ insetInlineStart: Math.max(0, Math.min(M, P)) + "px"
54
+ }, y = e || null, t.onChange(!0);
55
+ }, k = () => {
56
+ d.value && (clearTimeout(m), m = window.setTimeout(() => {
57
+ const n = i.value?.getRootNode()?.activeElement || null;
58
+ !i.value?.contains(n) && !s.value?.contains(n) && t.onChange(!1);
59
+ }, 10));
60
+ }, E = (e) => {
61
+ const n = e.relatedTarget;
62
+ d.value && !i.value?.contains(n) && !s.value?.contains(n) && t.onChange(!1);
54
63
  };
55
- D(() => e.visible, (n) => {
56
- n ? t.overlayClass = t.overlayClass.filter((r) => r !== d) : t.overlayClass.push(d);
64
+ R((e) => {
65
+ e(() => clearTimeout(m));
66
+ const n = s.value;
67
+ if (n)
68
+ if (d.value)
69
+ n.querySelectorAll(p).forEach((o) => {
70
+ o.tabIndex = -1;
71
+ }), y && (T(y), y = null);
72
+ else {
73
+ y = null;
74
+ const o = n.getRootNode();
75
+ n.contains(o.activeElement) && i.value?.focus({
76
+ preventScroll: !0
77
+ }), t.disabled && t.visible && t.onChange(!1);
78
+ }
57
79
  });
58
- let S = -1;
59
- const v = (n) => {
60
- o.value === n.target ? t.triggerHover = !1 : t.overlayHover = !1, clearTimeout(S), S = window.setTimeout(() => {
61
- !t.overlayHover && !t.triggerHover && e.onChange(!1);
62
- }, 10);
80
+ const D = (e) => {
81
+ if (t.disabled || e.defaultPrevented || e.isComposing || e.ctrlKey || e.metaKey || e.altKey && e.key !== "Tab") return;
82
+ const n = e.currentTarget === i.value;
83
+ if (n && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
84
+ e.preventDefault(), h(e.key === "ArrowUp" ? "last" : "first");
85
+ return;
86
+ }
87
+ if (!d.value) return;
88
+ if (e.key === "Escape") {
89
+ e.preventDefault(), e.stopPropagation(), i.value?.focus({
90
+ preventScroll: !0
91
+ }), t.onChange(!1);
92
+ return;
93
+ }
94
+ const o = e.target;
95
+ if (!n && !o.matches(p)) return;
96
+ if (e.key === "Tab") {
97
+ i.value?.focus({
98
+ preventScroll: !0
99
+ }), t.onChange(!1);
100
+ return;
101
+ }
102
+ if (n) return;
103
+ if (e.key === "Enter" || e.key === " ") {
104
+ e.preventDefault(), e.stopPropagation(), e.repeat || o.click();
105
+ return;
106
+ }
107
+ if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(e.key)) return;
108
+ const a = I(e.currentTarget), r = a.indexOf(o);
109
+ let u;
110
+ switch (e.key) {
111
+ case "ArrowDown":
112
+ u = (r + 1) % a.length;
113
+ break;
114
+ case "ArrowUp":
115
+ u = (r - 1 + a.length) % a.length;
116
+ break;
117
+ case "Home":
118
+ u = 0;
119
+ break;
120
+ default:
121
+ u = a.length - 1;
122
+ }
123
+ e.preventDefault(), e.stopPropagation();
124
+ const f = a[u];
125
+ f && (f.tabIndex = -1, f.focus({
126
+ preventScroll: !0
127
+ }));
63
128
  };
64
- return $(() => {
65
- o.value.addEventListener("mouseenter", u), o.value.addEventListener("mouseleave", v), l.value.addEventListener("mouseenter", b), l.value.addEventListener("mouseleave", v);
66
- }), N(() => {
67
- o.value.removeEventListener("mouseenter", u), o.value.removeEventListener("mouseleave", v), l.value.removeEventListener("mouseenter", b), l.value.removeEventListener("mouseleave", v);
68
- }), () => {
69
- const n = f({
70
- ctx: a
71
- }), r = f({
72
- props: e,
73
- ctx: a
74
- }, "overlay"), g = W(n instanceof Array ? n[0] : n, {
75
- ref: o,
76
- key: "cloned-dropdown-trigger"
77
- }), y = c("div", {
78
- class: [`${i}-dropdown`, t.overlayClass],
79
- style: t.overlayStyle,
80
- ref: l
81
- }, [c("div", {
82
- class: `${i}-dropdown-overlay`
83
- }, [r instanceof Array ? r[0] : r])]);
84
- return [g, y];
129
+ return () => {
130
+ const e = v({
131
+ ctx: l
132
+ }), n = v({
133
+ props: t,
134
+ ctx: l
135
+ }, "overlay"), o = $(e instanceof Array ? e[0] : e, {
136
+ ref: i,
137
+ key: "cloned-dropdown-trigger",
138
+ "aria-haspopup": "menu",
139
+ "aria-expanded": d.value,
140
+ "aria-controls": b,
141
+ onMouseenter: (r) => {
142
+ r.defaultPrevented || h();
143
+ },
144
+ onMouseleave: k,
145
+ // Vue 使用原生 focusout 接收子控件的失焦冒泡。
146
+ onFocusout: E,
147
+ onKeydown: D,
148
+ onClick: (r) => {
149
+ r.defaultPrevented || (r.detail === 0 ? h("first") : d.value || h());
150
+ }
151
+ }, !0), a = w("div", B({
152
+ id: b,
153
+ class: [`${g}-dropdown`, !d.value && j],
154
+ style: c.value,
155
+ ref: s,
156
+ tabindex: -1,
157
+ "aria-hidden": !d.value,
158
+ onMouseenter: () => clearTimeout(m),
159
+ onMouseleave: k,
160
+ onFocusout: E,
161
+ onKeydown: D
162
+ }, {
163
+ onClickCapture: (r) => {
164
+ const u = r.target.closest(p);
165
+ if (!(!u || !r.currentTarget.contains(u))) {
166
+ if (t.disabled || u.matches(':disabled, [aria-disabled="true"]')) {
167
+ r.preventDefault(), r.stopPropagation();
168
+ return;
169
+ }
170
+ i.value?.focus({
171
+ preventScroll: !0
172
+ }), t.onChange(!1);
173
+ }
174
+ }
175
+ }), [w("div", {
176
+ class: `${g}-dropdown-overlay`
177
+ }, [n instanceof Array ? n[0] : n])]);
178
+ return [o, a];
85
179
  };
86
180
  }
87
- }), R = {
181
+ }), q = {
88
182
  title: {
89
183
  type: String,
90
184
  default: ""
@@ -145,44 +239,44 @@ const O = {
145
239
  /**
146
240
  * ==结束
147
241
  */
148
- }, h = /* @__PURE__ */ H({
242
+ }, C = /* @__PURE__ */ N({
149
243
  name: "DropdownToolbar",
150
- props: R,
244
+ props: q,
151
245
  emits: ["onChange"],
152
- setup(e, a) {
153
- const d = I("editorId"), t = (o) => {
154
- e.onChange?.(o), a.emit("onChange", o);
246
+ setup(t, l) {
247
+ const d = L("editorId"), b = (c) => {
248
+ t.onChange?.(c), l.emit("onChange", c);
155
249
  };
156
250
  return () => {
157
- const o = f({
158
- props: e,
159
- ctx: a
160
- }, "trigger"), l = f({
161
- props: e,
162
- ctx: a
163
- }, "overlay"), u = f({
164
- props: e,
165
- ctx: a
251
+ const c = v({
252
+ props: t,
253
+ ctx: l
254
+ }, "trigger"), i = v({
255
+ props: t,
256
+ ctx: l
257
+ }, "overlay"), s = v({
258
+ props: t,
259
+ ctx: l
166
260
  });
167
- return c(j, {
261
+ return w(H, {
168
262
  relative: `#${d}-toolbar-wrapper`,
169
- visible: e.visible,
170
- onChange: t,
171
- overlay: l,
172
- disabled: e.disabled
263
+ visible: t.visible,
264
+ onChange: b,
265
+ overlay: i,
266
+ disabled: t.disabled
173
267
  }, {
174
- default: () => [c("button", {
175
- class: [`${i}-toolbar-item`, e.disabled && `${i}-disabled`],
176
- title: e.title || "",
177
- disabled: e.disabled,
268
+ default: () => [w("button", {
269
+ class: [`${g}-toolbar-item`, t.disabled && `${g}-disabled`],
270
+ title: t.title || "",
271
+ disabled: t.disabled,
178
272
  type: "button"
179
- }, [u || o])]
273
+ }, [s || c])]
180
274
  });
181
275
  };
182
276
  }
183
277
  });
184
- h.install = (e) => (e.component(h.name, h), e);
278
+ C.install = (t) => (t.component(C.name, C), t);
185
279
  export {
186
- h as D,
187
- j as a
280
+ C as D,
281
+ H as a
188
282
  };