@hankchen/canvas-editor-vue 0.5.0 → 0.6.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.
@@ -0,0 +1,464 @@
1
+ import { n as e, u as t } from "./useTransientFeedback-CTjmMmFF.js";
2
+ import { Fragment as n, computed as r, createCommentVNode as i, createElementBlock as a, createElementVNode as o, createTextVNode as s, defineComponent as c, mergeProps as l, nextTick as u, normalizeClass as d, normalizeStyle as f, onScopeDispose as p, openBlock as m, ref as h, renderList as g, renderSlot as _, shallowRef as v, toDisplayString as y, unref as b, watch as x, withModifiers as ee } from "vue";
3
+ //#region src/shared/useDropdownMenu.ts
4
+ function S(e) {
5
+ return e !== "separator" && "kind" in e && e.kind === "submenu";
6
+ }
7
+ function C(e) {
8
+ let t = h(!1);
9
+ function n(n) {
10
+ let r = e.container.value, i = n.target;
11
+ r !== null && i instanceof Node && r.contains(i) || (t.value = !1);
12
+ }
13
+ function r(e) {
14
+ e.key === "Escape" && (t.value = !1);
15
+ }
16
+ function i() {
17
+ window.removeEventListener("pointerdown", n), window.removeEventListener("keydown", r);
18
+ }
19
+ return x(t, (e) => {
20
+ e ? (window.addEventListener("pointerdown", n), window.addEventListener("keydown", r)) : i();
21
+ }), p(i, !0), {
22
+ open: t,
23
+ toggle: () => {
24
+ t.value = !t.value;
25
+ },
26
+ openMenu: () => {
27
+ t.value = !0;
28
+ },
29
+ closeMenu: () => {
30
+ t.value = !1;
31
+ }
32
+ };
33
+ }
34
+ function w(e, t, n) {
35
+ let r = e.length;
36
+ if (r === 0) return -1;
37
+ if (n === "Home" || n === "End") {
38
+ for (let t = 0; t < r; t++) {
39
+ let i = n === "Home" ? t : r - 1 - t;
40
+ if (e[i]) return i;
41
+ }
42
+ return -1;
43
+ }
44
+ let i = n === "ArrowDown" ? 1 : -1, a = t === -1 ? i === 1 ? -1 : r : t;
45
+ for (let t = 0; t < r; t++) if (a = (a + i + r) % r, e[a]) return a;
46
+ return -1;
47
+ }
48
+ function T(e, t) {
49
+ return t.type === "close" || t.target === void 0 ? null : t.type === "open" ? t.target : e === t.target ? null : t.target;
50
+ }
51
+ function te(e) {
52
+ let { anchor: t, flyoutWidth: n, flyoutHeight: r, viewportWidth: i, viewportHeight: a } = e, o = e.gap ?? 6, s = e.margin ?? 2, c = n > 0 && t.right + o + n > i - s ? "left" : "right", l = c === "right" ? t.right + o : t.left - o - n;
53
+ n > 0 && (l = Math.max(s, Math.min(l, i - s - n)));
54
+ let u = t.top;
55
+ return r > 0 && (u = Math.max(s, Math.min(u, a - s - r))), {
56
+ left: l,
57
+ top: u,
58
+ side: c
59
+ };
60
+ }
61
+ function ne(e) {
62
+ return e === "ArrowDown" || e === "ArrowUp" || e === "Home" || e === "End" ? {
63
+ type: "move",
64
+ key: e
65
+ } : e === "ArrowLeft" || e === "Escape" ? { type: "close" } : e === "Enter" || e === " " ? { type: "activate" } : e === "Tab" ? { type: "close-menu" } : { type: "none" };
66
+ }
67
+ function E(e, t) {
68
+ return e.find((e) => !e.hasAttribute("disabled")) ?? t;
69
+ }
70
+ function D(e) {
71
+ return e?.closest("[data-dropdown-submenu-host]")?.querySelector("[data-dropdown-submenu-arrow]") ?? null;
72
+ }
73
+ function O(e) {
74
+ return e;
75
+ }
76
+ //#endregion
77
+ //#region src/shared/DropdownMenu.vue?vue&type=script&setup=true&lang.ts
78
+ var re = ["aria-expanded", "title"], ie = ["aria-label"], ae = {
79
+ key: 0,
80
+ class: "cn-dropdown__separator",
81
+ role: "separator",
82
+ "data-dropdown-separator": "",
83
+ "aria-hidden": "true"
84
+ }, oe = {
85
+ key: 1,
86
+ class: "cn-dropdown__submenu-host",
87
+ "data-dropdown-submenu-host": ""
88
+ }, se = [
89
+ "disabled",
90
+ "title",
91
+ "onClick"
92
+ ], ce = { class: "cn-dropdown__item-label" }, le = {
93
+ key: 0,
94
+ class: "cn-dropdown__shortcut"
95
+ }, ue = [
96
+ "disabled",
97
+ "title",
98
+ "aria-expanded",
99
+ "onClick",
100
+ "onMouseenter"
101
+ ], de = ["aria-label"], fe = {
102
+ key: 0,
103
+ class: "cn-dropdown__separator",
104
+ role: "separator",
105
+ "data-dropdown-submenu-separator": "",
106
+ "aria-hidden": "true"
107
+ }, pe = [
108
+ "disabled",
109
+ "title",
110
+ "onClick"
111
+ ], me = { class: "cn-dropdown__item-label" }, he = {
112
+ key: 0,
113
+ class: "cn-dropdown__shortcut"
114
+ }, ge = [
115
+ "disabled",
116
+ "title",
117
+ "onClick"
118
+ ], _e = { class: "cn-dropdown__item-label" }, ve = {
119
+ key: 0,
120
+ class: "cn-dropdown__shortcut"
121
+ }, k = 6, A = 2, j = /*#__PURE__*/ t(/* @__PURE__ */ c({
122
+ __name: "DropdownMenu",
123
+ props: {
124
+ label: {},
125
+ items: {},
126
+ title: {},
127
+ direction: { default: "down" }
128
+ },
129
+ emits: ["closed"],
130
+ setup(t, { emit: r }) {
131
+ let c = t, p = r, j = h(null), M = h(null), N = h(null), { open: P, toggle: F, closeMenu: I } = C({ container: j }), L = v(null), R = h({
132
+ left: 0,
133
+ top: 0,
134
+ side: "right"
135
+ });
136
+ x(P, (e) => {
137
+ e || (L.value = null, p("closed"));
138
+ });
139
+ let z = h({
140
+ left: 0,
141
+ edge: "top",
142
+ offset: 0
143
+ });
144
+ function B() {
145
+ O(M.value)?.focus();
146
+ }
147
+ function V(e) {
148
+ M.value = e instanceof HTMLElement ? e : null;
149
+ }
150
+ async function H() {
151
+ if (await u(), !P.value) return;
152
+ let e = N.value;
153
+ e !== null && E(K(), e).focus();
154
+ }
155
+ function U() {
156
+ return c.items.filter((e) => e !== "separator");
157
+ }
158
+ function ye() {
159
+ return U().filter(S);
160
+ }
161
+ function be() {
162
+ return Array.from(N.value?.querySelectorAll("[data-dropdown-submenu-host]") ?? []);
163
+ }
164
+ function W() {
165
+ return N.value?.querySelector("[data-dropdown-submenu]") ?? null;
166
+ }
167
+ function G() {
168
+ return Array.from(W()?.querySelectorAll("[data-dropdown-submenu-item]") ?? []);
169
+ }
170
+ function K() {
171
+ return Array.from(N.value?.querySelectorAll("[data-dropdown-item]") ?? []);
172
+ }
173
+ function q(e) {
174
+ e.run(), (S(e) || e.keepsOpen !== !0) && (I(), B());
175
+ }
176
+ function xe(e) {
177
+ let t = N.value;
178
+ if (t === null) return;
179
+ let n = K(), r = w(n.map((e) => !e.hasAttribute("disabled")), document.activeElement instanceof HTMLElement ? n.indexOf(document.activeElement) : -1, e);
180
+ if (r === -1) {
181
+ t.focus();
182
+ return;
183
+ }
184
+ n[r]?.focus();
185
+ }
186
+ function Se(e) {
187
+ let t = U()[K().indexOf(e)];
188
+ t !== void 0 && !t.disabled && q(t);
189
+ }
190
+ function Ce(t) {
191
+ let n = t.key, r = t.target;
192
+ if (r instanceof HTMLElement && r.matches("[data-dropdown-submenu-item]")) {
193
+ let e = ne(n);
194
+ if (e.type === "move") {
195
+ t.preventDefault(), Y(e.key);
196
+ return;
197
+ }
198
+ if (e.type === "close") {
199
+ t.preventDefault(), J();
200
+ return;
201
+ }
202
+ if (e.type === "activate") {
203
+ t.preventDefault(), Te(r);
204
+ return;
205
+ }
206
+ if (e.type === "close-menu") {
207
+ I(), B();
208
+ return;
209
+ }
210
+ return;
211
+ }
212
+ if (n === "Escape") {
213
+ if (L.value !== null) {
214
+ J();
215
+ return;
216
+ }
217
+ I(), B();
218
+ return;
219
+ }
220
+ if (n === "Tab") {
221
+ if (r instanceof HTMLElement && !r.matches("[data-dropdown-item]") && e(r)) return;
222
+ I(), B();
223
+ return;
224
+ }
225
+ if (n === "Enter" || n === " ") {
226
+ r instanceof HTMLElement && r.matches("[data-dropdown-item]") && (t.preventDefault(), Se(r));
227
+ return;
228
+ }
229
+ if (n === "ArrowDown" || n === "ArrowUp" || n === "Home" || n === "End") {
230
+ if (r instanceof HTMLElement && !r.matches("[data-dropdown-item]") && e(r)) return;
231
+ t.preventDefault(), xe(n);
232
+ return;
233
+ }
234
+ if (n === "ArrowRight") {
235
+ let e = r instanceof HTMLElement ? r.closest("[data-dropdown-submenu-host]") : null;
236
+ if (e !== null) {
237
+ let n = ye()[be().indexOf(e)];
238
+ n !== void 0 && (t.preventDefault(), we(n, e));
239
+ }
240
+ }
241
+ }
242
+ async function we(e, t) {
243
+ if (e.disabled === !0 || (L.value = T(L.value, {
244
+ type: "open",
245
+ target: e
246
+ }), await $(t.querySelector("[data-dropdown-submenu-arrow]")), L.value !== e || !P.value)) return;
247
+ let n = W();
248
+ n !== null && E(G(), n).focus();
249
+ }
250
+ function J() {
251
+ let e = D(document.activeElement instanceof HTMLElement ? document.activeElement : null);
252
+ L.value = null, e?.focus();
253
+ }
254
+ function Y(e) {
255
+ let t = W();
256
+ if (t === null) return;
257
+ let n = G(), r = w(n.map((e) => !e.hasAttribute("disabled")), document.activeElement instanceof HTMLElement ? n.indexOf(document.activeElement) : -1, e);
258
+ if (r === -1) {
259
+ t.focus();
260
+ return;
261
+ }
262
+ n[r]?.focus();
263
+ }
264
+ function Te(e) {
265
+ let t = L.value;
266
+ if (t === null) return;
267
+ let n = Array.from(W()?.querySelectorAll("[data-dropdown-submenu-item]") ?? []), r = t.children.filter((e) => e !== "separator")[n.indexOf(e)];
268
+ r !== void 0 && !r.disabled && q(r);
269
+ }
270
+ function X(e) {
271
+ if (e.key === "ArrowDown") {
272
+ if (e.preventDefault(), !P.value) {
273
+ Z();
274
+ return;
275
+ }
276
+ H();
277
+ }
278
+ }
279
+ async function Z() {
280
+ if (!P.value) {
281
+ let e = M.value?.getBoundingClientRect();
282
+ e && (z.value = c.direction === "up" ? {
283
+ left: e.left,
284
+ edge: "bottom",
285
+ offset: window.innerHeight - e.top + k
286
+ } : {
287
+ left: e.left,
288
+ edge: "top",
289
+ offset: e.bottom + k
290
+ });
291
+ }
292
+ if (F(), !P.value) {
293
+ B();
294
+ return;
295
+ }
296
+ await u();
297
+ let e = N.value?.getBoundingClientRect();
298
+ if (!e) return;
299
+ let t = z.value;
300
+ z.value = {
301
+ left: Math.max(A, Math.min(t.left, window.innerWidth - e.width - A)),
302
+ edge: t.edge,
303
+ offset: Math.max(A, Math.min(t.offset, window.innerHeight - e.height - A))
304
+ }, H();
305
+ }
306
+ function Q(e) {
307
+ return e.currentTarget instanceof HTMLElement ? e.currentTarget : null;
308
+ }
309
+ async function $(e) {
310
+ let t = L.value;
311
+ if (t === null || e === null) return;
312
+ let n = e.getBoundingClientRect();
313
+ if (R.value = {
314
+ left: n.right + 6,
315
+ top: n.top,
316
+ side: "right"
317
+ }, await u(), L.value !== t) return;
318
+ let r = W(), i = r?.getBoundingClientRect();
319
+ r !== null && i !== void 0 && i.width !== 0 && (R.value = te({
320
+ anchor: {
321
+ top: n.top,
322
+ bottom: n.bottom,
323
+ left: n.left,
324
+ right: n.right
325
+ },
326
+ flyoutWidth: i.width,
327
+ flyoutHeight: i.height,
328
+ viewportWidth: window.innerWidth,
329
+ viewportHeight: window.innerHeight
330
+ }));
331
+ }
332
+ function Ee(e, t) {
333
+ t.disabled !== !0 && (L.value = T(L.value, {
334
+ type: "open",
335
+ target: t
336
+ }), $(Q(e)));
337
+ }
338
+ function De(e, t) {
339
+ t.disabled !== !0 && (L.value = T(L.value, {
340
+ type: "toggle",
341
+ target: t
342
+ }), $(Q(e)));
343
+ }
344
+ function Oe() {
345
+ L.value = null;
346
+ }
347
+ return (e, r) => (m(), a("div", {
348
+ ref_key: "container",
349
+ ref: j,
350
+ class: "cn-dropdown",
351
+ onMouseleave: Oe
352
+ }, [_(e.$slots, "trigger", {
353
+ open: b(P),
354
+ toggle: Z,
355
+ closeMenu: b(I),
356
+ triggerRef: V,
357
+ onKeydown: X
358
+ }, () => [o("button", {
359
+ ref: V,
360
+ type: "button",
361
+ class: "cn-dropdown__trigger",
362
+ "data-dropdown-trigger": "",
363
+ "aria-haspopup": "menu",
364
+ "aria-expanded": b(P),
365
+ title: t.title ?? t.label,
366
+ onClick: r[0] ||= (e) => Z(),
367
+ onKeydown: X
368
+ }, [s(y(t.label) + " ", 1), r[2] ||= o("span", {
369
+ class: "cn-dropdown__caret",
370
+ "aria-hidden": "true"
371
+ }, "▾", -1)], 40, re)], !0), b(P) ? (m(), a("div", {
372
+ key: 0,
373
+ ref_key: "menuEl",
374
+ ref: N,
375
+ class: "cn-dropdown__menu",
376
+ role: "menu",
377
+ "aria-label": t.label,
378
+ "data-dropdown-menu": "",
379
+ tabindex: "-1",
380
+ style: f(z.value.edge === "top" ? {
381
+ left: `${z.value.left}px`,
382
+ top: `${z.value.offset}px`
383
+ } : {
384
+ left: `${z.value.left}px`,
385
+ bottom: `${z.value.offset}px`
386
+ }),
387
+ onKeydown: r[1] ||= ee((e) => Ce(e), ["stop"])
388
+ }, [(m(!0), a(n, null, g(t.items, (e, t) => (m(), a(n, { key: t }, [e === "separator" ? (m(), a("div", ae)) : b(S)(e) ? (m(), a("div", oe, [
389
+ o("button", l({
390
+ type: "button",
391
+ role: "menuitem",
392
+ class: "cn-dropdown__item cn-dropdown__submenu-main",
393
+ "data-dropdown-item": "",
394
+ tabindex: "-1",
395
+ disabled: e.disabled,
396
+ title: e.title
397
+ }, { ref_for: !0 }, e.dataAttrs, { onClick: (t) => q(e) }), [o("span", ce, y(e.label), 1), e.shortcut ? (m(), a("span", le, y(e.shortcut), 1)) : i("", !0)], 16, se),
398
+ o("button", {
399
+ type: "button",
400
+ class: "cn-dropdown__submenu-arrow",
401
+ "data-dropdown-submenu-arrow": "",
402
+ tabindex: "-1",
403
+ disabled: e.disabled,
404
+ title: e.title,
405
+ "aria-haspopup": "menu",
406
+ "aria-expanded": L.value === e,
407
+ onClick: (t) => De(t, e),
408
+ onMouseenter: (t) => Ee(t, e)
409
+ }, [...r[3] ||= [o("span", { "aria-hidden": "true" }, "▸", -1)]], 40, ue),
410
+ L.value === e ? (m(), a("div", {
411
+ key: 0,
412
+ class: d(["cn-dropdown__submenu", { "cn-dropdown__submenu--left": R.value.side === "left" }]),
413
+ role: "menu",
414
+ "aria-label": e.label,
415
+ "data-dropdown-submenu": "",
416
+ tabindex: "-1",
417
+ style: f({
418
+ left: `${R.value.left}px`,
419
+ top: `${R.value.top}px`
420
+ })
421
+ }, [(m(!0), a(n, null, g(e.children, (e, t) => (m(), a(n, { key: t }, [e === "separator" ? (m(), a("div", fe)) : (m(), a("button", l({
422
+ key: 1,
423
+ type: "button",
424
+ role: "menuitem",
425
+ class: "cn-dropdown__item",
426
+ "data-dropdown-submenu-item": "",
427
+ tabindex: "-1",
428
+ disabled: e.disabled,
429
+ title: e.title
430
+ }, { ref_for: !0 }, e.dataAttrs, { onClick: (t) => q(e) }), [o("span", me, y(e.label), 1), e.shortcut ? (m(), a("span", he, y(e.shortcut), 1)) : i("", !0)], 16, pe))], 64))), 128))], 14, de)) : i("", !0)
431
+ ])) : (m(), a("button", l({
432
+ key: 2,
433
+ type: "button",
434
+ role: "menuitem",
435
+ class: "cn-dropdown__item",
436
+ "data-dropdown-item": "",
437
+ tabindex: "-1",
438
+ disabled: e.disabled,
439
+ title: e.title
440
+ }, { ref_for: !0 }, e.dataAttrs, { onClick: (t) => q(e) }), [o("span", _e, y(e.label), 1), e.shortcut ? (m(), a("span", ve, y(e.shortcut), 1)) : i("", !0)], 16, ge))], 64))), 128)), _(e.$slots, "body", {
441
+ open: b(P),
442
+ toggle: Z,
443
+ closeMenu: b(I),
444
+ triggerRef: V,
445
+ onKeydown: X
446
+ }, void 0, !0)], 44, ie)) : i("", !0)], 544));
447
+ }
448
+ }), [["__scopeId", "data-v-f39579b0"]]);
449
+ //#endregion
450
+ //#region src/shared/useDataSourceSchema.ts
451
+ function M(e) {
452
+ let t = v(e.store.ui.dataSourceSchema), n = e.subscribe((n) => {
453
+ n.scope === "ui" && n.branch === "dataSourceSchema" && (t.value = e.store.ui.dataSourceSchema);
454
+ });
455
+ return p(n, !0), r(() => t.value);
456
+ }
457
+ function N(e) {
458
+ let t = v(e.store.ui.dataSourceSchemaRejection), n = e.subscribe((n) => {
459
+ n.scope === "ui" && n.branch === "dataSourceSchema" && (t.value = e.store.ui.dataSourceSchemaRejection);
460
+ });
461
+ return p(n, !0), r(() => t.value);
462
+ }
463
+ //#endregion
464
+ export { C as i, N as n, j as r, M as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hankchen/canvas-editor-vue",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "license": "MIT",
5
5
  "description": "Vue 3 薄绑定:响应式桥、composables、画布表面组件、textarea 文本编辑 overlay、schema 驱动属性面板注册表",
6
6
  "type": "module",
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@lucide/vue": "^1.48.0",
61
- "@hankchen/canvas-editor": "0.6.0"
61
+ "@hankchen/canvas-editor": "0.7.1"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "vue": "^3.5.0"