@tempots/beatui 1.1.1 → 1.1.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.
@@ -1,373 +0,0 @@
1
- import { prop as H, WithElement as q, Fragment as v, aria as u, OneOfValue as j, OnDispose as z, on as p, Value as E, attr as s, html as D, Empty as W, computedOf as G, dataAttr as J } from "@tempots/dom";
2
- import { PopOver as Q } from "@tempots/ui";
3
- import { delayedAnimationFrame as R } from "@tempots/std";
4
- import { u as X, A as Y } from "./use-animated-toggle-C3asw_Sg.js";
5
- import { s as B } from "./session-id-3KiilioY.js";
6
- function Z(m) {
7
- const l = { fade: !0, scale: !0 };
8
- return m.startsWith("top") ? (l.slide = "down", l.transformOrigin = "bottom") : m.startsWith("bottom") ? (l.slide = "up", l.transformOrigin = "top") : m.startsWith("left") ? (l.slide = "right", l.transformOrigin = "right") : m.startsWith("right") && (l.slide = "left", l.transformOrigin = "left"), l;
9
- }
10
- function U(m) {
11
- const {
12
- content: l,
13
- placement: P = "top",
14
- showDelay: x = 250,
15
- hideDelay: C = 500,
16
- mainAxisOffset: I = 8,
17
- crossAxisOffset: M = 0,
18
- showOn: b = "hover-focus",
19
- closable: y = !0,
20
- arrow: L,
21
- role: g,
22
- hasPopup: S = "dialog"
23
- } = m;
24
- return Q((w, h) => {
25
- const o = X({
26
- initialStatus: "closed"
27
- }), T = B("flyout"), f = H(!1);
28
- let k = null, d = null, $ = !1, A;
29
- function _() {
30
- e != null && (clearTimeout(e), e = null), n != null && (clearTimeout(n), n = null), d && (d(), d = null), k && (document.removeEventListener("keydown", k), k = null), f.set(!1), $ = !1;
31
- }
32
- function K() {
33
- E.get(y) && (k = (i) => {
34
- i.key === "Escape" && a();
35
- }, document.addEventListener("keydown", k)), $ = !0, f.set(!0), w({
36
- placement: P ?? "top",
37
- mainAxisOffset: I,
38
- crossAxisOffset: M,
39
- arrow: L,
40
- content: q((i) => {
41
- o.setElement(i);
42
- const r = typeof b == "function" ? null : E.get(b);
43
- (r === "hover" || r === "hover-focus") && (i.addEventListener("mouseenter", () => t()), i.addEventListener("mouseleave", () => a())), d = R(() => {
44
- o.open(), d = null;
45
- });
46
- const c = (F) => {
47
- E.get(y) && F.key === "Escape" && (F.preventDefault(), F.stopPropagation(), a(), f.set(!1));
48
- };
49
- document.addEventListener("keydown", c, !0);
50
- let O = null;
51
- return E.get(y) && (O = (F) => {
52
- const V = F.target;
53
- !i.contains(V) && !A?.contains(V) && a();
54
- }, document.addEventListener("click", O)), v(
55
- z(() => {
56
- O && (document.removeEventListener("click", O), O = null), _(), document.removeEventListener("keydown", c, !0);
57
- }),
58
- s.class("bc-flyout-container"),
59
- Y({
60
- animation: E.map(P, Z),
61
- status: o.status
62
- }),
63
- s.id(T),
64
- s.tabindex(-1),
65
- // Make focusable for screen readers
66
- D.div(
67
- s.class("bc-flyout"),
68
- g ? s.role(g) : s.role("dialog"),
69
- // Default to dialog role
70
- l()
71
- )
72
- );
73
- })
74
- });
75
- }
76
- let e = null;
77
- function t() {
78
- if (e != null && (clearTimeout(e), e = null), n != null && (clearTimeout(n), n = null), o.isOpened.value || o.isOpening.value || o.isStartOpening.value)
79
- return;
80
- if (o.isClosing.value || o.isStartClosing.value) {
81
- o.open();
82
- return;
83
- }
84
- const i = E.get(x);
85
- e = setTimeout(() => {
86
- e = null, K();
87
- }, i);
88
- }
89
- let n = null;
90
- function a() {
91
- if (e != null && (clearTimeout(e), e = null), n != null && (clearTimeout(n), n = null), f.set(!1), d && (d(), d = null, $)) {
92
- h(), _();
93
- return;
94
- }
95
- const i = E.get(C);
96
- n = setTimeout(() => {
97
- n = null, o.close(), o.listenOnClosed(() => {
98
- h(), _();
99
- });
100
- }, i);
101
- }
102
- return q((i) => {
103
- A = i;
104
- const r = () => {
105
- t(), f.set(!0);
106
- }, c = () => {
107
- a(), f.set(!1);
108
- }, O = v(
109
- u.expanded(f),
110
- u.controls(T),
111
- u.haspopup(
112
- S
113
- )
114
- );
115
- return typeof b == "function" ? v(
116
- O,
117
- b(r, c)
118
- ) : v(
119
- O,
120
- j(b, {
121
- "hover-focus": () => v(
122
- p.mouseenter(() => r()),
123
- p.mouseleave(() => c()),
124
- p.focus(() => r()),
125
- p.blur(() => c())
126
- ),
127
- hover: () => v(
128
- p.mouseenter(() => r()),
129
- p.mouseleave(() => c())
130
- ),
131
- focus: () => v(
132
- p.focus(() => r()),
133
- p.blur(() => c())
134
- ),
135
- click: () => {
136
- function V() {
137
- document.removeEventListener("click", N);
138
- }
139
- function N() {
140
- V(), c();
141
- }
142
- return v(
143
- z(V),
144
- p.click(() => {
145
- r(), R(() => {
146
- document.addEventListener("click", N, {
147
- once: !0
148
- });
149
- });
150
- })
151
- );
152
- },
153
- never: () => null
154
- })
155
- );
156
- });
157
- });
158
- }
159
- function ae(m) {
160
- const {
161
- items: l,
162
- placement: P = "bottom-start",
163
- showDelay: x = 0,
164
- hideDelay: C = 100,
165
- mainAxisOffset: I = 4,
166
- crossAxisOffset: M = 0,
167
- showOn: b = "click",
168
- closable: y = !0,
169
- onClose: L,
170
- onAction: g,
171
- ariaLabel: S,
172
- ariaLabelledBy: w
173
- } = m, h = B("menu"), o = H(-1), T = H([]);
174
- let f = null;
175
- return U({
176
- content: () => q((k) => {
177
- f = document.activeElement;
178
- const d = (e, t, n) => {
179
- if (t.length === 0) return -1;
180
- let a = e + n, i = 0;
181
- for (; i < t.length; ) {
182
- a >= t.length && (a = 0), a < 0 && (a = t.length - 1);
183
- const r = t[a];
184
- if (r && r.getAttribute("aria-disabled") !== "true")
185
- return a;
186
- a += n, i++;
187
- }
188
- return e;
189
- }, $ = (e) => {
190
- const t = T.value, n = o.value;
191
- switch (e.key) {
192
- case "ArrowDown":
193
- e.preventDefault(), e.stopPropagation();
194
- const a = d(n, t, 1);
195
- A(a, t);
196
- break;
197
- case "ArrowUp":
198
- e.preventDefault(), e.stopPropagation();
199
- const i = d(n, t, -1);
200
- A(i, t);
201
- break;
202
- case "Enter":
203
- case " ":
204
- if (e.preventDefault(), e.stopPropagation(), n >= 0 && t[n]) {
205
- const r = t[n];
206
- if (r.getAttribute("aria-disabled") === "true")
207
- return;
208
- const c = r.getAttribute("data-key");
209
- c && g && g(c), r.click(), L?.();
210
- }
211
- break;
212
- case "Escape":
213
- L?.();
214
- break;
215
- case "Home":
216
- e.preventDefault(), e.stopPropagation(), t.length > 0 && A(0, t);
217
- break;
218
- case "End":
219
- e.preventDefault(), e.stopPropagation(), t.length > 0 && A(t.length - 1, t);
220
- break;
221
- case "ArrowRight":
222
- if (e.preventDefault(), e.stopPropagation(), n >= 0 && t[n]) {
223
- const r = t[n];
224
- r.classList.contains(
225
- "bc-menu-item--has-submenu"
226
- ) && r.dispatchEvent(new Event("mouseenter"));
227
- }
228
- break;
229
- case "ArrowLeft":
230
- e.preventDefault(), e.stopPropagation(), L?.();
231
- break;
232
- }
233
- }, A = (e, t) => {
234
- o.value >= 0 && t[o.value] && (t[o.value].classList.remove(
235
- "bc-menu-item--focused"
236
- ), t[o.value].removeAttribute("aria-selected")), e >= 0 && t[e] && (t[e].classList.add("bc-menu-item--focused"), t[e].setAttribute("aria-selected", "true"), o.set(e), typeof t[e].scrollIntoView == "function" && t[e].scrollIntoView({ block: "nearest" }));
237
- }, _ = () => {
238
- const e = Array.from(
239
- k.querySelectorAll('[role="menuitem"]')
240
- );
241
- if (T.set(e), e.length > 0) {
242
- const t = e.findIndex(
243
- (n) => n.getAttribute("aria-disabled") !== "true"
244
- );
245
- t >= 0 && A(t, e);
246
- }
247
- }, K = new MutationObserver(_);
248
- return K.observe(k, { childList: !0, subtree: !0 }), setTimeout(() => {
249
- _(), k.focus();
250
- }, 0), document.addEventListener("keydown", $, !0), v(
251
- z(() => {
252
- K.disconnect(), document.removeEventListener("keydown", $, !0), f && f.focus();
253
- }),
254
- s.class("bc-menu"),
255
- s.id(h),
256
- s.role("menu"),
257
- s.tabindex(-1),
258
- u.orientation("vertical"),
259
- S ? u.label(S) : W,
260
- w ? u.labelledby(w) : W,
261
- u.activedescendant(
262
- o.map((e) => {
263
- const t = T.value;
264
- return e >= 0 && t[e] ? t[e].id || `${h}-item-${e}` : "";
265
- })
266
- ),
267
- p.click((e) => {
268
- const n = e.target.closest('[role="menuitem"]');
269
- if (n && n.getAttribute("aria-disabled") !== "true") {
270
- const a = n.getAttribute("data-key");
271
- a && g && g(a);
272
- }
273
- }),
274
- // Live region for screen reader announcements
275
- D.div(
276
- s.class("sr-only"),
277
- u.live("polite"),
278
- u.atomic(!0),
279
- o.map((e) => {
280
- const t = T.value;
281
- if (e >= 0 && t[e]) {
282
- const n = t[e].textContent || "";
283
- return t[e].getAttribute("aria-disabled") === "true" ? `${n}, disabled` : `${n}, ${e + 1} of ${t.length}`;
284
- }
285
- return "";
286
- })
287
- ),
288
- ...l()
289
- );
290
- }),
291
- placement: P,
292
- showDelay: x,
293
- hideDelay: C,
294
- mainAxisOffset: I,
295
- crossAxisOffset: M,
296
- showOn: b,
297
- closable: y,
298
- role: "menu"
299
- });
300
- }
301
- function re(m) {
302
- const {
303
- key: l,
304
- content: P,
305
- before: x,
306
- after: C,
307
- disabled: I = !1,
308
- onClick: M,
309
- ariaLabel: b,
310
- submenu: y,
311
- submenuPlacement: L = "right-start"
312
- } = m, g = l ?? B("menu-item"), S = `menu-item-${g}`, w = y != null;
313
- return D.div(
314
- s.class(
315
- G(I)(
316
- (h) => `bc-menu-item ${h ? "bc-menu-item--disabled" : ""} ${w ? "bc-menu-item--has-submenu" : ""}`
317
- )
318
- ),
319
- s.id(S),
320
- s.role("menuitem"),
321
- s.tabindex(-1),
322
- J("key", g),
323
- u.disabled(I),
324
- u.selected(!1),
325
- // Will be updated by focus management
326
- w ? u.expanded(!1) : W,
327
- b ? u.label(b) : W,
328
- p.click((h) => {
329
- if (E.get(I)) {
330
- h.preventDefault(), h.stopPropagation();
331
- return;
332
- }
333
- M?.();
334
- }),
335
- // Before content
336
- x && D.span(s.class("bc-menu-item__start"), x),
337
- // Main content
338
- D.span(s.class("bc-menu-item__content"), P),
339
- // After content
340
- C && D.span(s.class("bc-menu-item__end"), C),
341
- // Submenu (if present)
342
- w && y ? U({
343
- content: () => v(
344
- s.class("bc-menu bc-submenu"),
345
- s.role("menu"),
346
- ...y()
347
- ),
348
- placement: L,
349
- showOn: "hover",
350
- hasPopup: "menu",
351
- showDelay: 100,
352
- hideDelay: 300,
353
- mainAxisOffset: 0,
354
- crossAxisOffset: 0,
355
- role: "menu"
356
- }) : W
357
- );
358
- }
359
- function le(m = {}) {
360
- const { label: l } = m;
361
- return D.div(
362
- s.class("bc-menu-separator"),
363
- s.role("separator"),
364
- u.orientation("horizontal"),
365
- l && D.span(s.class("bc-menu-separator__label"), l)
366
- );
367
- }
368
- export {
369
- U as F,
370
- ae as M,
371
- re as a,
372
- le as b
373
- };
@@ -1 +0,0 @@
1
- "use strict";const e=require("@tempots/dom"),q=require("@tempots/ui"),_=require("@tempots/std"),W=require("./use-animated-toggle-cKcuItmz.cjs"),C=require("./session-id-B5lJMzbB.cjs");function K(c){const l={fade:!0,scale:!0};return c.startsWith("top")?(l.slide="down",l.transformOrigin="bottom"):c.startsWith("bottom")?(l.slide="up",l.transformOrigin="top"):c.startsWith("left")?(l.slide="right",l.transformOrigin="right"):c.startsWith("right")&&(l.slide="left",l.transformOrigin="left"),l}function M(c){const{content:l,placement:I="top",showDelay:D=250,hideDelay:L=500,mainAxisOffset:E=8,crossAxisOffset:V=0,showOn:f="hover-focus",closable:g=!0,arrow:w,role:p,hasPopup:F="dialog"}=c;return q.PopOver((v,b)=>{const r=W.useAnimatedElementToggle({initialStatus:"closed"}),A=C.sessionId("flyout"),m=e.prop(!1);let h=null,d=null,T=!1,y;function P(){t!=null&&(clearTimeout(t),t=null),a!=null&&(clearTimeout(a),a=null),d&&(d(),d=null),h&&(document.removeEventListener("keydown",h),h=null),m.set(!1),T=!1}function S(){e.Value.get(g)&&(h=i=>{i.key==="Escape"&&o()},document.addEventListener("keydown",h)),T=!0,m.set(!0),v({placement:I??"top",mainAxisOffset:E,crossAxisOffset:V,arrow:w,content:e.WithElement(i=>{r.setElement(i);const s=typeof f=="function"?null:e.Value.get(f);(s==="hover"||s==="hover-focus")&&(i.addEventListener("mouseenter",()=>n()),i.addEventListener("mouseleave",()=>o())),d=_.delayedAnimationFrame(()=>{r.open(),d=null});const u=O=>{e.Value.get(g)&&O.key==="Escape"&&(O.preventDefault(),O.stopPropagation(),o(),m.set(!1))};document.addEventListener("keydown",u,!0);let k=null;return e.Value.get(g)&&(k=O=>{const x=O.target;!i.contains(x)&&!y?.contains(x)&&o()},document.addEventListener("click",k)),e.Fragment(e.OnDispose(()=>{k&&(document.removeEventListener("click",k),k=null),P(),document.removeEventListener("keydown",u,!0)}),e.attr.class("bc-flyout-container"),W.AnimatedToggleClass({animation:e.Value.map(I,K),status:r.status}),e.attr.id(A),e.attr.tabindex(-1),e.html.div(e.attr.class("bc-flyout"),p?e.attr.role(p):e.attr.role("dialog"),l()))})})}let t=null;function n(){if(t!=null&&(clearTimeout(t),t=null),a!=null&&(clearTimeout(a),a=null),r.isOpened.value||r.isOpening.value||r.isStartOpening.value)return;if(r.isClosing.value||r.isStartClosing.value){r.open();return}const i=e.Value.get(D);t=setTimeout(()=>{t=null,S()},i)}let a=null;function o(){if(t!=null&&(clearTimeout(t),t=null),a!=null&&(clearTimeout(a),a=null),m.set(!1),d&&(d(),d=null,T)){b(),P();return}const i=e.Value.get(L);a=setTimeout(()=>{a=null,r.close(),r.listenOnClosed(()=>{b(),P()})},i)}return e.WithElement(i=>{y=i;const s=()=>{n(),m.set(!0)},u=()=>{o(),m.set(!1)},k=e.Fragment(e.aria.expanded(m),e.aria.controls(A),e.aria.haspopup(F));if(typeof f=="function")return e.Fragment(k,f(s,u));const O=f;return e.Fragment(k,e.OneOfValue(O,{"hover-focus":()=>e.Fragment(e.on.mouseenter(()=>s()),e.on.mouseleave(()=>u()),e.on.focus(()=>s()),e.on.blur(()=>u())),hover:()=>e.Fragment(e.on.mouseenter(()=>s()),e.on.mouseleave(()=>u())),focus:()=>e.Fragment(e.on.focus(()=>s()),e.on.blur(()=>u())),click:()=>{function x(){document.removeEventListener("click",$)}function $(){x(),u()}return e.Fragment(e.OnDispose(x),e.on.click(()=>{s(),_.delayedAnimationFrame(()=>{document.addEventListener("click",$,{once:!0})})}))},never:()=>null}))})})}function H(c){const{items:l,placement:I="bottom-start",showDelay:D=0,hideDelay:L=100,mainAxisOffset:E=4,crossAxisOffset:V=0,showOn:f="click",closable:g=!0,onClose:w,onAction:p,ariaLabel:F,ariaLabelledBy:v}=c,b=C.sessionId("menu"),r=e.prop(-1),A=e.prop([]);let m=null;return M({content:()=>e.WithElement(h=>{m=document.activeElement;const d=(t,n,a)=>{if(n.length===0)return-1;let o=t+a,i=0;for(;i<n.length;){o>=n.length&&(o=0),o<0&&(o=n.length-1);const s=n[o];if(s&&s.getAttribute("aria-disabled")!=="true")return o;o+=a,i++}return t},T=t=>{const n=A.value,a=r.value;switch(t.key){case"ArrowDown":t.preventDefault(),t.stopPropagation();const o=d(a,n,1);y(o,n);break;case"ArrowUp":t.preventDefault(),t.stopPropagation();const i=d(a,n,-1);y(i,n);break;case"Enter":case" ":if(t.preventDefault(),t.stopPropagation(),a>=0&&n[a]){const s=n[a];if(s.getAttribute("aria-disabled")==="true")return;const u=s.getAttribute("data-key");u&&p&&p(u),s.click(),w?.()}break;case"Escape":w?.();break;case"Home":t.preventDefault(),t.stopPropagation(),n.length>0&&y(0,n);break;case"End":t.preventDefault(),t.stopPropagation(),n.length>0&&y(n.length-1,n);break;case"ArrowRight":if(t.preventDefault(),t.stopPropagation(),a>=0&&n[a]){const s=n[a];s.classList.contains("bc-menu-item--has-submenu")&&s.dispatchEvent(new Event("mouseenter"))}break;case"ArrowLeft":t.preventDefault(),t.stopPropagation(),w?.();break}},y=(t,n)=>{r.value>=0&&n[r.value]&&(n[r.value].classList.remove("bc-menu-item--focused"),n[r.value].removeAttribute("aria-selected")),t>=0&&n[t]&&(n[t].classList.add("bc-menu-item--focused"),n[t].setAttribute("aria-selected","true"),r.set(t),typeof n[t].scrollIntoView=="function"&&n[t].scrollIntoView({block:"nearest"}))},P=()=>{const t=Array.from(h.querySelectorAll('[role="menuitem"]'));if(A.set(t),t.length>0){const n=t.findIndex(a=>a.getAttribute("aria-disabled")!=="true");n>=0&&y(n,t)}},S=new MutationObserver(P);return S.observe(h,{childList:!0,subtree:!0}),setTimeout(()=>{P(),h.focus()},0),document.addEventListener("keydown",T,!0),e.Fragment(e.OnDispose(()=>{S.disconnect(),document.removeEventListener("keydown",T,!0),m&&m.focus()}),e.attr.class("bc-menu"),e.attr.id(b),e.attr.role("menu"),e.attr.tabindex(-1),e.aria.orientation("vertical"),F?e.aria.label(F):e.Empty,v?e.aria.labelledby(v):e.Empty,e.aria.activedescendant(r.map(t=>{const n=A.value;return t>=0&&n[t]?n[t].id||`${b}-item-${t}`:""})),e.on.click(t=>{const a=t.target.closest('[role="menuitem"]');if(a&&a.getAttribute("aria-disabled")!=="true"){const o=a.getAttribute("data-key");o&&p&&p(o)}}),e.html.div(e.attr.class("sr-only"),e.aria.live("polite"),e.aria.atomic(!0),r.map(t=>{const n=A.value;if(t>=0&&n[t]){const a=n[t].textContent||"";return n[t].getAttribute("aria-disabled")==="true"?`${a}, disabled`:`${a}, ${t+1} of ${n.length}`}return""})),...l())}),placement:I,showDelay:D,hideDelay:L,mainAxisOffset:E,crossAxisOffset:V,showOn:f,closable:g,role:"menu"})}function z(c){const{key:l,content:I,before:D,after:L,disabled:E=!1,onClick:V,ariaLabel:f,submenu:g,submenuPlacement:w="right-start"}=c,p=l??C.sessionId("menu-item"),F=`menu-item-${p}`,v=g!=null;return e.html.div(e.attr.class(e.computedOf(E)(b=>`bc-menu-item ${b?"bc-menu-item--disabled":""} ${v?"bc-menu-item--has-submenu":""}`)),e.attr.id(F),e.attr.role("menuitem"),e.attr.tabindex(-1),e.dataAttr("key",p),e.aria.disabled(E),e.aria.selected(!1),v?e.aria.expanded(!1):e.Empty,f?e.aria.label(f):e.Empty,e.on.click(b=>{if(e.Value.get(E)){b.preventDefault(),b.stopPropagation();return}V?.()}),D&&e.html.span(e.attr.class("bc-menu-item__start"),D),e.html.span(e.attr.class("bc-menu-item__content"),I),L&&e.html.span(e.attr.class("bc-menu-item__end"),L),v&&g?M({content:()=>e.Fragment(e.attr.class("bc-menu bc-submenu"),e.attr.role("menu"),...g()),placement:w,showOn:"hover",hasPopup:"menu",showDelay:100,hideDelay:300,mainAxisOffset:0,crossAxisOffset:0,role:"menu"}):e.Empty)}function B(c={}){const{label:l}=c;return e.html.div(e.attr.class("bc-menu-separator"),e.attr.role("separator"),e.aria.orientation("horizontal"),l&&e.html.span(e.attr.class("bc-menu-separator__label"),l))}exports.Flyout=M;exports.Menu=H;exports.MenuItem=z;exports.MenuSeparator=B;