UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

693 lines (687 loc) 22.9 kB
import * as u from "react"; import { useState as be } from "react"; import { u as Ee } from "./index-DLcqcWxM.es.js"; import { P as ue } from "./index-BVqmUhu5.es.js"; import { u as q } from "./index-DwYXX2sM.es.js"; import { jsx as ie } from "react/jsx-runtime"; import Se from "react-dom"; import { u as we } from "./index-Dt3MSLsk.es.js"; var U = "focusScope.autoFocusOnMount", j = "focusScope.autoFocusOnUnmount", Q = { bubbles: !1, cancelable: !0 }, Ce = "FocusScope", Re = u.forwardRef((e, t) => { const { loop: r = !1, trapped: n = !1, onMountAutoFocus: c, onUnmountAutoFocus: i, ...l } = e, [a, S] = u.useState(null), b = q(c), g = q(i), f = u.useRef(null), v = Ee(t, (o) => S(o)), h = u.useRef({ paused: !1, pause() { this.paused = !0; }, resume() { this.paused = !1; } }).current; u.useEffect(() => { if (n) { let o = function(p) { if (h.paused || !a) return; const y = p.target; a.contains(y) ? f.current = y : T(f.current, { select: !0 }); }, s = function(p) { if (h.paused || !a) return; const y = p.relatedTarget; y !== null && (a.contains(y) || T(f.current, { select: !0 })); }, d = function(p) { if (document.activeElement === document.body) for (const E of p) E.removedNodes.length > 0 && T(a); }; document.addEventListener("focusin", o), document.addEventListener("focusout", s); const m = new MutationObserver(d); return a && m.observe(a, { childList: !0, subtree: !0 }), () => { document.removeEventListener("focusin", o), document.removeEventListener("focusout", s), m.disconnect(); }; } }, [n, a, h.paused]), u.useEffect(() => { if (a) { J.add(h); const o = document.activeElement; if (!a.contains(o)) { const d = new CustomEvent(U, Q); a.addEventListener(U, b), a.dispatchEvent(d), d.defaultPrevented || (Ae(Me(le(a)), { select: !0 }), document.activeElement === o && T(a)); } return () => { a.removeEventListener(U, b), setTimeout(() => { const d = new CustomEvent(j, Q); a.addEventListener(j, g), a.dispatchEvent(d), d.defaultPrevented || T(o ?? document.body, { select: !0 }), a.removeEventListener(j, g), J.remove(h); }, 0); }; } }, [a, b, g, h]); const w = u.useCallback( (o) => { if (!r && !n || h.paused) return; const s = o.key === "Tab" && !o.altKey && !o.ctrlKey && !o.metaKey, d = document.activeElement; if (s && d) { const m = o.currentTarget, [p, y] = Te(m); p && y ? !o.shiftKey && d === y ? (o.preventDefault(), r && T(p, { select: !0 })) : o.shiftKey && d === p && (o.preventDefault(), r && T(y, { select: !0 })) : d === m && o.preventDefault(); } }, [r, n, h.paused] ); return /* @__PURE__ */ ie(ue.div, { tabIndex: -1, ...l, ref: v, onKeyDown: w }); }); Re.displayName = Ce; function Ae(e, { select: t = !1 } = {}) { const r = document.activeElement; for (const n of e) if (T(n, { select: t }), document.activeElement !== r) return; } function Te(e) { const t = le(e), r = $(t, e), n = $(t.reverse(), e); return [r, n]; } function le(e) { const t = [], r = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, { acceptNode: (n) => { const c = n.tagName === "INPUT" && n.type === "hidden"; return n.disabled || n.hidden || c ? NodeFilter.FILTER_SKIP : n.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP; } }); for (; r.nextNode(); ) t.push(r.currentNode); return t; } function $(e, t) { for (const r of e) if (!ke(r, { upTo: t })) return r; } function ke(e, { upTo: t }) { if (getComputedStyle(e).visibility === "hidden") return !0; for (; e; ) { if (t !== void 0 && e === t) return !1; if (getComputedStyle(e).display === "none") return !0; e = e.parentElement; } return !1; } function Pe(e) { return e instanceof HTMLInputElement && "select" in e; } function T(e, { select: t = !1 } = {}) { if (e && e.focus) { const r = document.activeElement; e.focus({ preventScroll: !0 }), e !== r && Pe(e) && t && e.select(); } } var J = Ne(); function Ne() { let e = []; return { add(t) { const r = e[0]; t !== r && (r == null || r.pause()), e = ee(e, t), e.unshift(t); }, remove(t) { var r; e = ee(e, t), (r = e[0]) == null || r.resume(); } }; } function ee(e, t) { const r = [...e], n = r.indexOf(t); return n !== -1 && r.splice(n, 1), r; } function Me(e) { return e.filter((t) => t.tagName !== "A"); } var Oe = "Portal", Fe = u.forwardRef((e, t) => { var a; const { container: r, ...n } = e, [c, i] = u.useState(!1); we(() => i(!0), []); const l = r || c && ((a = globalThis == null ? void 0 : globalThis.document) == null ? void 0 : a.body); return l ? Se.createPortal(/* @__PURE__ */ ie(ue.div, { ...n, ref: t }), l) : null; }); Fe.displayName = Oe; var K = 0; function Tt() { u.useEffect(() => { const e = document.querySelectorAll("[data-radix-focus-guard]"); return document.body.insertAdjacentElement("afterbegin", e[0] ?? te()), document.body.insertAdjacentElement("beforeend", e[1] ?? te()), K++, () => { K === 1 && document.querySelectorAll("[data-radix-focus-guard]").forEach((t) => t.remove()), K--; }; }, []); } function te() { const e = document.createElement("span"); return e.setAttribute("data-radix-focus-guard", ""), e.tabIndex = 0, e.style.outline = "none", e.style.opacity = "0", e.style.position = "fixed", e.style.pointerEvents = "none", e; } var C = function() { return C = Object.assign || function(t) { for (var r, n = 1, c = arguments.length; n < c; n++) { r = arguments[n]; for (var i in r) Object.prototype.hasOwnProperty.call(r, i) && (t[i] = r[i]); } return t; }, C.apply(this, arguments); }; function se(e, t) { var r = {}; for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]); if (e != null && typeof Object.getOwnPropertySymbols == "function") for (var c = 0, n = Object.getOwnPropertySymbols(e); c < n.length; c++) t.indexOf(n[c]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[c]) && (r[n[c]] = e[n[c]]); return r; } function Le(e, t, r) { if (r || arguments.length === 2) for (var n = 0, c = t.length, i; n < c; n++) (i || !(n in t)) && (i || (i = Array.prototype.slice.call(t, 0, n)), i[n] = t[n]); return e.concat(i || Array.prototype.slice.call(t)); } var W = "right-scroll-bar-position", B = "width-before-scroll-bar", Ie = "with-scroll-bars-hidden", xe = "--removed-body-scroll-bar-size"; function H(e, t) { return typeof e == "function" ? e(t) : e && (e.current = t), e; } function We(e, t) { var r = be(function() { return { // value value: e, // last callback callback: t, // "memoized" public interface facade: { get current() { return r.value; }, set current(n) { var c = r.value; c !== n && (r.value = n, r.callback(n, c)); } } }; })[0]; return r.callback = t, r.facade; } var Be = typeof window < "u" ? u.useLayoutEffect : u.useEffect, re = /* @__PURE__ */ new WeakMap(); function De(e, t) { var r = We(null, function(n) { return e.forEach(function(c) { return H(c, n); }); }); return Be(function() { var n = re.get(r); if (n) { var c = new Set(n), i = new Set(e), l = r.current; c.forEach(function(a) { i.has(a) || H(a, null); }), i.forEach(function(a) { c.has(a) || H(a, l); }); } re.set(r, e); }, [e]), r; } function _e(e) { return e; } function Ue(e, t) { t === void 0 && (t = _e); var r = [], n = !1, c = { read: function() { if (n) throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`."); return r.length ? r[r.length - 1] : e; }, useMedium: function(i) { var l = t(i, n); return r.push(l), function() { r = r.filter(function(a) { return a !== l; }); }; }, assignSyncMedium: function(i) { for (n = !0; r.length; ) { var l = r; r = [], l.forEach(i); } r = { push: function(a) { return i(a); }, filter: function() { return r; } }; }, assignMedium: function(i) { n = !0; var l = []; if (r.length) { var a = r; r = [], a.forEach(i), l = r; } var S = function() { var g = l; l = [], g.forEach(i); }, b = function() { return Promise.resolve().then(S); }; b(), r = { push: function(g) { l.push(g), b(); }, filter: function(g) { return l = l.filter(g), r; } }; } }; return c; } function je(e) { e === void 0 && (e = {}); var t = Ue(null); return t.options = C({ async: !0, ssr: !1 }, e), t; } var fe = function(e) { var t = e.sideCar, r = se(e, ["sideCar"]); if (!t) throw new Error("Sidecar: please provide `sideCar` property to import the right car"); var n = t.read(); if (!n) throw new Error("Sidecar medium not found"); return u.createElement(n, C({}, r)); }; fe.isSideCarExport = !0; function Ke(e, t) { return e.useMedium(t), fe; } var de = je(), V = function() { }, D = u.forwardRef(function(e, t) { var r = u.useRef(null), n = u.useState({ onScrollCapture: V, onWheelCapture: V, onTouchMoveCapture: V }), c = n[0], i = n[1], l = e.forwardProps, a = e.children, S = e.className, b = e.removeScrollBar, g = e.enabled, f = e.shards, v = e.sideCar, h = e.noRelative, w = e.noIsolation, o = e.inert, s = e.allowPinchZoom, d = e.as, m = d === void 0 ? "div" : d, p = e.gapMode, y = se(e, ["forwardProps", "children", "className", "removeScrollBar", "enabled", "shards", "sideCar", "noRelative", "noIsolation", "inert", "allowPinchZoom", "as", "gapMode"]), E = v, R = De([r, t]), A = C(C({}, y), c); return u.createElement( u.Fragment, null, g && u.createElement(E, { sideCar: de, removeScrollBar: b, shards: f, noRelative: h, noIsolation: w, inert: o, setCallbacks: i, allowPinchZoom: !!s, lockRef: r, gapMode: p }), l ? u.cloneElement(u.Children.only(a), C(C({}, A), { ref: R })) : u.createElement(m, C({}, A, { className: S, ref: R }), a) ); }); D.defaultProps = { enabled: !0, removeScrollBar: !0, inert: !1 }; D.classNames = { fullWidth: B, zeroRight: W }; var He = function() { if (typeof __webpack_nonce__ < "u") return __webpack_nonce__; }; function Ve() { if (!document) return null; var e = document.createElement("style"); e.type = "text/css"; var t = He(); return t && e.setAttribute("nonce", t), e; } function Xe(e, t) { e.styleSheet ? e.styleSheet.cssText = t : e.appendChild(document.createTextNode(t)); } function Ye(e) { var t = document.head || document.getElementsByTagName("head")[0]; t.appendChild(e); } var Ge = function() { var e = 0, t = null; return { add: function(r) { e == 0 && (t = Ve()) && (Xe(t, r), Ye(t)), e++; }, remove: function() { e--, !e && t && (t.parentNode && t.parentNode.removeChild(t), t = null); } }; }, ze = function() { var e = Ge(); return function(t, r) { u.useEffect(function() { return e.add(t), function() { e.remove(); }; }, [t && r]); }; }, ve = function() { var e = ze(), t = function(r) { var n = r.styles, c = r.dynamic; return e(n, c), null; }; return t; }, Ze = { left: 0, top: 0, right: 0, gap: 0 }, X = function(e) { return parseInt(e || "", 10) || 0; }, qe = function(e) { var t = window.getComputedStyle(document.body), r = t[e === "padding" ? "paddingLeft" : "marginLeft"], n = t[e === "padding" ? "paddingTop" : "marginTop"], c = t[e === "padding" ? "paddingRight" : "marginRight"]; return [X(r), X(n), X(c)]; }, Qe = function(e) { if (e === void 0 && (e = "margin"), typeof window > "u") return Ze; var t = qe(e), r = document.documentElement.clientWidth, n = window.innerWidth; return { left: t[0], top: t[1], right: t[2], gap: Math.max(0, n - r + t[2] - t[0]) }; }, $e = ve(), M = "data-scroll-locked", Je = function(e, t, r, n) { var c = e.left, i = e.top, l = e.right, a = e.gap; return r === void 0 && (r = "margin"), ` .`.concat(Ie, ` { overflow: hidden `).concat(n, `; padding-right: `).concat(a, "px ").concat(n, `; } body[`).concat(M, `] { overflow: hidden `).concat(n, `; overscroll-behavior: contain; `).concat([ t && "position: relative ".concat(n, ";"), r === "margin" && ` padding-left: `.concat(c, `px; padding-top: `).concat(i, `px; padding-right: `).concat(l, `px; margin-left:0; margin-top:0; margin-right: `).concat(a, "px ").concat(n, `; `), r === "padding" && "padding-right: ".concat(a, "px ").concat(n, ";") ].filter(Boolean).join(""), ` } .`).concat(W, ` { right: `).concat(a, "px ").concat(n, `; } .`).concat(B, ` { margin-right: `).concat(a, "px ").concat(n, `; } .`).concat(W, " .").concat(W, ` { right: 0 `).concat(n, `; } .`).concat(B, " .").concat(B, ` { margin-right: 0 `).concat(n, `; } body[`).concat(M, `] { `).concat(xe, ": ").concat(a, `px; } `); }, ne = function() { var e = parseInt(document.body.getAttribute(M) || "0", 10); return isFinite(e) ? e : 0; }, et = function() { u.useEffect(function() { return document.body.setAttribute(M, (ne() + 1).toString()), function() { var e = ne() - 1; e <= 0 ? document.body.removeAttribute(M) : document.body.setAttribute(M, e.toString()); }; }, []); }, tt = function(e) { var t = e.noRelative, r = e.noImportant, n = e.gapMode, c = n === void 0 ? "margin" : n; et(); var i = u.useMemo(function() { return Qe(c); }, [c]); return u.createElement($e, { styles: Je(i, !t, c, r ? "" : "!important") }); }, G = !1; if (typeof window < "u") try { var F = Object.defineProperty({}, "passive", { get: function() { return G = !0, !0; } }); window.addEventListener("test", F, F), window.removeEventListener("test", F, F); } catch { G = !1; } var k = G ? { passive: !1 } : !1, rt = function(e) { return e.tagName === "TEXTAREA"; }, he = function(e, t) { if (!(e instanceof Element)) return !1; var r = window.getComputedStyle(e); return ( // not-not-scrollable r[t] !== "hidden" && // contains scroll inside self !(r.overflowY === r.overflowX && !rt(e) && r[t] === "visible") ); }, nt = function(e) { return he(e, "overflowY"); }, at = function(e) { return he(e, "overflowX"); }, ae = function(e, t) { var r = t.ownerDocument, n = t; do { typeof ShadowRoot < "u" && n instanceof ShadowRoot && (n = n.host); var c = me(e, n); if (c) { var i = pe(e, n), l = i[1], a = i[2]; if (l > a) return !0; } n = n.parentNode; } while (n && n !== r.body); return !1; }, ot = function(e) { var t = e.scrollTop, r = e.scrollHeight, n = e.clientHeight; return [ t, r, n ]; }, ct = function(e) { var t = e.scrollLeft, r = e.scrollWidth, n = e.clientWidth; return [ t, r, n ]; }, me = function(e, t) { return e === "v" ? nt(t) : at(t); }, pe = function(e, t) { return e === "v" ? ot(t) : ct(t); }, ut = function(e, t) { return e === "h" && t === "rtl" ? -1 : 1; }, it = function(e, t, r, n, c) { var i = ut(e, window.getComputedStyle(t).direction), l = i * n, a = r.target, S = t.contains(a), b = !1, g = l > 0, f = 0, v = 0; do { if (!a) break; var h = pe(e, a), w = h[0], o = h[1], s = h[2], d = o - s - i * w; (w || d) && me(e, a) && (f += d, v += w); var m = a.parentNode; a = m && m.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? m.host : m; } while ( // portaled content !S && a !== document.body || // self content S && (t.contains(a) || t === a) ); return (g && Math.abs(f) < 1 || !g && Math.abs(v) < 1) && (b = !0), b; }, L = function(e) { return "changedTouches" in e ? [e.changedTouches[0].clientX, e.changedTouches[0].clientY] : [0, 0]; }, oe = function(e) { return [e.deltaX, e.deltaY]; }, ce = function(e) { return e && "current" in e ? e.current : e; }, lt = function(e, t) { return e[0] === t[0] && e[1] === t[1]; }, st = function(e) { return ` .block-interactivity-`.concat(e, ` {pointer-events: none;} .allow-interactivity-`).concat(e, ` {pointer-events: all;} `); }, ft = 0, P = []; function dt(e) { var t = u.useRef([]), r = u.useRef([0, 0]), n = u.useRef(), c = u.useState(ft++)[0], i = u.useState(ve)[0], l = u.useRef(e); u.useEffect(function() { l.current = e; }, [e]), u.useEffect(function() { if (e.inert) { document.body.classList.add("block-interactivity-".concat(c)); var o = Le([e.lockRef.current], (e.shards || []).map(ce), !0).filter(Boolean); return o.forEach(function(s) { return s.classList.add("allow-interactivity-".concat(c)); }), function() { document.body.classList.remove("block-interactivity-".concat(c)), o.forEach(function(s) { return s.classList.remove("allow-interactivity-".concat(c)); }); }; } }, [e.inert, e.lockRef.current, e.shards]); var a = u.useCallback(function(o, s) { if ("touches" in o && o.touches.length === 2 || o.type === "wheel" && o.ctrlKey) return !l.current.allowPinchZoom; var d = L(o), m = r.current, p = "deltaX" in o ? o.deltaX : m[0] - d[0], y = "deltaY" in o ? o.deltaY : m[1] - d[1], E, R = o.target, A = Math.abs(p) > Math.abs(y) ? "h" : "v"; if ("touches" in o && A === "h" && R.type === "range") return !1; var z = window.getSelection(), _ = z && z.anchorNode, ye = _ ? _ === R || _.contains(R) : !1; if (ye) return !1; var O = ae(A, R); if (!O) return !0; if (O ? E = A : (E = A === "v" ? "h" : "v", O = ae(A, R)), !O) return !1; if (!n.current && "changedTouches" in o && (p || y) && (n.current = E), !E) return !0; var Z = n.current || E; return it(Z, s, o, Z === "h" ? p : y); }, []), S = u.useCallback(function(o) { var s = o; if (!(!P.length || P[P.length - 1] !== i)) { var d = "deltaY" in s ? oe(s) : L(s), m = t.current.filter(function(E) { return E.name === s.type && (E.target === s.target || s.target === E.shadowParent) && lt(E.delta, d); })[0]; if (m && m.should) { s.cancelable && s.preventDefault(); return; } if (!m) { var p = (l.current.shards || []).map(ce).filter(Boolean).filter(function(E) { return E.contains(s.target); }), y = p.length > 0 ? a(s, p[0]) : !l.current.noIsolation; y && s.cancelable && s.preventDefault(); } } }, []), b = u.useCallback(function(o, s, d, m) { var p = { name: o, delta: s, target: d, should: m, shadowParent: vt(d) }; t.current.push(p), setTimeout(function() { t.current = t.current.filter(function(y) { return y !== p; }); }, 1); }, []), g = u.useCallback(function(o) { r.current = L(o), n.current = void 0; }, []), f = u.useCallback(function(o) { b(o.type, oe(o), o.target, a(o, e.lockRef.current)); }, []), v = u.useCallback(function(o) { b(o.type, L(o), o.target, a(o, e.lockRef.current)); }, []); u.useEffect(function() { return P.push(i), e.setCallbacks({ onScrollCapture: f, onWheelCapture: f, onTouchMoveCapture: v }), document.addEventListener("wheel", S, k), document.addEventListener("touchmove", S, k), document.addEventListener("touchstart", g, k), function() { P = P.filter(function(o) { return o !== i; }), document.removeEventListener("wheel", S, k), document.removeEventListener("touchmove", S, k), document.removeEventListener("touchstart", g, k); }; }, []); var h = e.removeScrollBar, w = e.inert; return u.createElement( u.Fragment, null, w ? u.createElement(i, { styles: st(c) }) : null, h ? u.createElement(tt, { noRelative: e.noRelative, gapMode: e.gapMode }) : null ); } function vt(e) { for (var t = null; e !== null; ) e instanceof ShadowRoot && (t = e.host, e = e.host), e = e.parentNode; return t; } const ht = Ke(de, dt); var mt = u.forwardRef(function(e, t) { return u.createElement(D, C({}, e, { ref: t, sideCar: ht })); }); mt.classNames = D.classNames; var pt = function(e) { if (typeof document > "u") return null; var t = Array.isArray(e) ? e[0] : e; return t.ownerDocument.body; }, N = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), x = {}, Y = 0, ge = function(e) { return e && (e.host || ge(e.parentNode)); }, gt = function(e, t) { return t.map(function(r) { if (e.contains(r)) return r; var n = ge(r); return n && e.contains(n) ? n : (console.error("aria-hidden", r, "in not contained inside", e, ". Doing nothing"), null); }).filter(function(r) { return !!r; }); }, yt = function(e, t, r, n) { var c = gt(t, Array.isArray(e) ? e : [e]); x[r] || (x[r] = /* @__PURE__ */ new WeakMap()); var i = x[r], l = [], a = /* @__PURE__ */ new Set(), S = new Set(c), b = function(f) { !f || a.has(f) || (a.add(f), b(f.parentNode)); }; c.forEach(b); var g = function(f) { !f || S.has(f) || Array.prototype.forEach.call(f.children, function(v) { if (a.has(v)) g(v); else try { var h = v.getAttribute(n), w = h !== null && h !== "false", o = (N.get(v) || 0) + 1, s = (i.get(v) || 0) + 1; N.set(v, o), i.set(v, s), l.push(v), o === 1 && w && I.set(v, !0), s === 1 && v.setAttribute(r, "true"), w || v.setAttribute(n, "true"); } catch (d) { console.error("aria-hidden: cannot operate on ", v, d); } }); }; return g(t), a.clear(), Y++, function() { l.forEach(function(f) { var v = N.get(f) - 1, h = i.get(f) - 1; N.set(f, v), i.set(f, h), v || (I.has(f) || f.removeAttribute(n), I.delete(f)), h || f.removeAttribute(r); }), Y--, Y || (N = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), x = {}); }; }, kt = function(e, t, r) { r === void 0 && (r = "data-aria-hidden"); var n = Array.from(Array.isArray(e) ? e : [e]), c = pt(e); return c ? (n.push.apply(n, Array.from(c.querySelectorAll("[aria-live], script"))), yt(n, c, r, "aria-hidden")) : function() { return null; }; }; export { Re as F, Fe as P, mt as R, C as _, Le as a, kt as h, Tt as u }; //# sourceMappingURL=index-BKZjW6I1.es.js.map