@acrool/react-picker
Version:
This is a react method to quickly combine buttons with Picker
1,086 lines (1,082 loc) • 36 kB
JavaScript
import Fe, { createContext as $r, useContext as Wr, useEffect as X, forwardRef as he, useRef as G, useCallback as N, useState as pe } from "react";
import Ir from "react-dom";
import { motion as ge, AnimatePresence as Lr } from "framer-motion";
var W = /* @__PURE__ */ ((t) => (t.bottom = "bottom", t.top = "top", t))(W || {}), te = /* @__PURE__ */ ((t) => (t.left = "left", t.right = "right", t))(te || {});
const ae = [
"color: #fff",
"display: inline-block",
"font-size: 11px",
"line-height: 20px",
"padding-right: 8px",
"border-radius: 4px"
], ie = {
primary: "#0055a9",
success: "#009422",
info: "#17a2b8",
warning: "#d7a000",
danger: "#ec2127"
};
function oe(t, a, ...n) {
console.log(`%c ${t}`, a, ...n);
}
function Vr(t, ...a) {
const n = ae.concat([
`background-color: ${ie.primary}`
]).join(";");
oe(t, n, ...a);
}
function Yr(t, ...a) {
const n = ae.concat([
`background-color: ${ie.success}`
]).join(";");
oe(t, n, ...a);
}
function Ur(t, ...a) {
const n = ae.concat([
`background-color: ${ie.info}`
]).join(";");
oe(t, n, ...a);
}
function Hr(t, ...a) {
const n = ae.concat([
`background-color: ${ie.warning}`
]).join(";");
oe(t, n, ...a);
}
function Br(t, ...a) {
const n = ae.concat([
`background-color: ${ie.danger}`
]).join(";");
oe(t, n, ...a);
}
const V = {
primary: Vr,
success: Yr,
info: Ur,
warning: Hr,
danger: Br
}, Ne = $r({
hide: () => V.warning("No hide method detected, did you embed your app with Acrool/PickerPortal?"),
show: () => V.warning("No show method detected, did you embed your app with Acrool/PickerPortal?"),
toggle: () => V.warning("No toggle method detected, did you embed your app with Acrool/PickerPortal?"),
isVisible: !1,
inputFocus: () => V.warning("No focus method detected, did you embed your app with Acrool/PickerPortal?"),
inputBlur: () => V.warning("No blur method detected, did you embed your app with Acrool/PickerPortal?"),
isInputFocus: !1,
onChange: () => V.warning("No onChange method detected, did you embed your app with Acrool/PickerPortal?"),
vertical: W.bottom,
setVertical: () => V.warning("No onChange method detected, did you embed your app with Acrool/PickerPortal?")
}), wt = Ne.Consumer, Jr = () => Wr(Ne);
var Ae = { exports: {} }, ee = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var nr;
function qr() {
if (nr)
return ee;
nr = 1;
var t = Fe, a = Symbol.for("react.element"), n = Symbol.for("react.fragment"), v = Object.prototype.hasOwnProperty, E = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, d = { key: !0, ref: !0, __self: !0, __source: !0 };
function _(u, l, R) {
var g, x = {}, j = null, C = null;
R !== void 0 && (j = "" + R), l.key !== void 0 && (j = "" + l.key), l.ref !== void 0 && (C = l.ref);
for (g in l)
v.call(l, g) && !d.hasOwnProperty(g) && (x[g] = l[g]);
if (u && u.defaultProps)
for (g in l = u.defaultProps, l)
x[g] === void 0 && (x[g] = l[g]);
return { $$typeof: a, type: u, key: j, ref: C, props: x, _owner: E.current };
}
return ee.Fragment = n, ee.jsx = _, ee.jsxs = _, ee;
}
var re = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ar;
function zr() {
return ar || (ar = 1, process.env.NODE_ENV !== "production" && function() {
var t = Fe, a = Symbol.for("react.element"), n = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), E = Symbol.for("react.strict_mode"), d = Symbol.for("react.profiler"), _ = Symbol.for("react.provider"), u = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), R = Symbol.for("react.suspense"), g = Symbol.for("react.suspense_list"), x = Symbol.for("react.memo"), j = Symbol.for("react.lazy"), C = Symbol.for("react.offscreen"), M = Symbol.iterator, O = "@@iterator";
function F(e) {
if (e === null || typeof e != "object")
return null;
var r = M && e[M] || e[O];
return typeof r == "function" ? r : null;
}
var k = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function m(e) {
{
for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), o = 1; o < r; o++)
i[o - 1] = arguments[o];
J("error", e, i);
}
}
function J(e, r, i) {
{
var o = k.ReactDebugCurrentFrame, f = o.getStackAddendum();
f !== "" && (r += "%s", i = i.concat([f]));
var p = i.map(function(s) {
return String(s);
});
p.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, p);
}
}
var I = !1, Y = !1, Z = !1, ye = !1, we = !1, ce;
ce = Symbol.for("react.module.reference");
function Ee(e) {
return !!(typeof e == "string" || typeof e == "function" || e === v || e === d || we || e === E || e === R || e === g || ye || e === C || I || Y || Z || typeof e == "object" && e !== null && (e.$$typeof === j || e.$$typeof === x || e.$$typeof === _ || e.$$typeof === u || e.$$typeof === l || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === ce || e.getModuleId !== void 0));
}
function _e(e, r, i) {
var o = e.displayName;
if (o)
return o;
var f = r.displayName || r.name || "";
return f !== "" ? i + "(" + f + ")" : i;
}
function se(e) {
return e.displayName || "Context";
}
function A(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && m("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case v:
return "Fragment";
case n:
return "Portal";
case d:
return "Profiler";
case E:
return "StrictMode";
case R:
return "Suspense";
case g:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case u:
var r = e;
return se(r) + ".Consumer";
case _:
var i = e;
return se(i._context) + ".Provider";
case l:
return _e(e, e.render, "ForwardRef");
case x:
var o = e.displayName || null;
return o !== null ? o : A(e.type) || "Memo";
case j: {
var f = e, p = f._payload, s = f._init;
try {
return A(s(p));
} catch {
return null;
}
}
}
return null;
}
var $ = Object.assign, U = 0, h, S, L, We, Ie, Le, Ve;
function Ye() {
}
Ye.__reactDisabledLog = !0;
function lr() {
{
if (U === 0) {
h = console.log, S = console.info, L = console.warn, We = console.error, Ie = console.group, Le = console.groupCollapsed, Ve = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: Ye,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
U++;
}
}
function fr() {
{
if (U--, U === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: $({}, e, {
value: h
}),
info: $({}, e, {
value: S
}),
warn: $({}, e, {
value: L
}),
error: $({}, e, {
value: We
}),
group: $({}, e, {
value: Ie
}),
groupCollapsed: $({}, e, {
value: Le
}),
groupEnd: $({}, e, {
value: Ve
})
});
}
U < 0 && m("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var ke = k.ReactCurrentDispatcher, Re;
function ue(e, r, i) {
{
if (Re === void 0)
try {
throw Error();
} catch (f) {
var o = f.stack.trim().match(/\n( *(at )?)/);
Re = o && o[1] || "";
}
return `
` + Re + e;
}
}
var Pe = !1, le;
{
var dr = typeof WeakMap == "function" ? WeakMap : Map;
le = new dr();
}
function Ue(e, r) {
if (!e || Pe)
return "";
{
var i = le.get(e);
if (i !== void 0)
return i;
}
var o;
Pe = !0;
var f = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var p;
p = ke.current, ke.current = null, lr();
try {
if (r) {
var s = function() {
throw Error();
};
if (Object.defineProperty(s.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(s, []);
} catch (T) {
o = T;
}
Reflect.construct(e, [], s);
} else {
try {
s.call();
} catch (T) {
o = T;
}
e.call(s.prototype);
}
} else {
try {
throw Error();
} catch (T) {
o = T;
}
e();
}
} catch (T) {
if (T && o && typeof T.stack == "string") {
for (var c = T.stack.split(`
`), P = o.stack.split(`
`), y = c.length - 1, w = P.length - 1; y >= 1 && w >= 0 && c[y] !== P[w]; )
w--;
for (; y >= 1 && w >= 0; y--, w--)
if (c[y] !== P[w]) {
if (y !== 1 || w !== 1)
do
if (y--, w--, w < 0 || c[y] !== P[w]) {
var D = `
` + c[y].replace(" at new ", " at ");
return e.displayName && D.includes("<anonymous>") && (D = D.replace("<anonymous>", e.displayName)), typeof e == "function" && le.set(e, D), D;
}
while (y >= 1 && w >= 0);
break;
}
}
} finally {
Pe = !1, ke.current = p, fr(), Error.prepareStackTrace = f;
}
var z = e ? e.displayName || e.name : "", H = z ? ue(z) : "";
return typeof e == "function" && le.set(e, H), H;
}
function pr(e, r, i) {
return Ue(e, !1);
}
function vr(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function fe(e, r, i) {
if (e == null)
return "";
if (typeof e == "function")
return Ue(e, vr(e));
if (typeof e == "string")
return ue(e);
switch (e) {
case R:
return ue("Suspense");
case g:
return ue("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case l:
return pr(e.render);
case x:
return fe(e.type, r, i);
case j: {
var o = e, f = o._payload, p = o._init;
try {
return fe(p(f), r, i);
} catch {
}
}
}
return "";
}
var Q = Object.prototype.hasOwnProperty, He = {}, Be = k.ReactDebugCurrentFrame;
function de(e) {
if (e) {
var r = e._owner, i = fe(e.type, e._source, r ? r.type : null);
Be.setExtraStackFrame(i);
} else
Be.setExtraStackFrame(null);
}
function mr(e, r, i, o, f) {
{
var p = Function.call.bind(Q);
for (var s in e)
if (p(e, s)) {
var c = void 0;
try {
if (typeof e[s] != "function") {
var P = Error((o || "React class") + ": " + i + " type `" + s + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[s] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw P.name = "Invariant Violation", P;
}
c = e[s](r, s, o, i, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (y) {
c = y;
}
c && !(c instanceof Error) && (de(f), m("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", o || "React class", i, s, typeof c), de(null)), c instanceof Error && !(c.message in He) && (He[c.message] = !0, de(f), m("Failed %s type: %s", i, c.message), de(null));
}
}
}
var hr = Array.isArray;
function xe(e) {
return hr(e);
}
function gr(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, i = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return i;
}
}
function br(e) {
try {
return Je(e), !1;
} catch {
return !0;
}
}
function Je(e) {
return "" + e;
}
function qe(e) {
if (br(e))
return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", gr(e)), Je(e);
}
var K = k.ReactCurrentOwner, yr = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, ze, Ge, Ce;
Ce = {};
function wr(e) {
if (Q.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function Er(e) {
if (Q.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function _r(e, r) {
if (typeof e.ref == "string" && K.current && r && K.current.stateNode !== r) {
var i = A(K.current.type);
Ce[i] || (m('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', A(K.current.type), e.ref), Ce[i] = !0);
}
}
function kr(e, r) {
{
var i = function() {
ze || (ze = !0, m("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
i.isReactWarning = !0, Object.defineProperty(e, "key", {
get: i,
configurable: !0
});
}
}
function Rr(e, r) {
{
var i = function() {
Ge || (Ge = !0, m("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
i.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: i,
configurable: !0
});
}
}
var Pr = function(e, r, i, o, f, p, s) {
var c = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: a,
// Built-in properties that belong on the element
type: e,
key: r,
ref: i,
props: s,
// Record the component responsible for creating this element.
_owner: p
};
return c._store = {}, Object.defineProperty(c._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(c, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: o
}), Object.defineProperty(c, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: f
}), Object.freeze && (Object.freeze(c.props), Object.freeze(c)), c;
};
function xr(e, r, i, o, f) {
{
var p, s = {}, c = null, P = null;
i !== void 0 && (qe(i), c = "" + i), Er(r) && (qe(r.key), c = "" + r.key), wr(r) && (P = r.ref, _r(r, f));
for (p in r)
Q.call(r, p) && !yr.hasOwnProperty(p) && (s[p] = r[p]);
if (e && e.defaultProps) {
var y = e.defaultProps;
for (p in y)
s[p] === void 0 && (s[p] = y[p]);
}
if (c || P) {
var w = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
c && kr(s, w), P && Rr(s, w);
}
return Pr(e, c, P, f, o, K.current, s);
}
}
var Se = k.ReactCurrentOwner, Xe = k.ReactDebugCurrentFrame;
function q(e) {
if (e) {
var r = e._owner, i = fe(e.type, e._source, r ? r.type : null);
Xe.setExtraStackFrame(i);
} else
Xe.setExtraStackFrame(null);
}
var Te;
Te = !1;
function je(e) {
return typeof e == "object" && e !== null && e.$$typeof === a;
}
function Ze() {
{
if (Se.current) {
var e = A(Se.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function Cr(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), i = e.lineNumber;
return `
Check your code at ` + r + ":" + i + ".";
}
return "";
}
}
var Qe = {};
function Sr(e) {
{
var r = Ze();
if (!r) {
var i = typeof e == "string" ? e : e.displayName || e.name;
i && (r = `
Check the top-level render call using <` + i + ">.");
}
return r;
}
}
function Ke(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var i = Sr(r);
if (Qe[i])
return;
Qe[i] = !0;
var o = "";
e && e._owner && e._owner !== Se.current && (o = " It was passed a child from " + A(e._owner.type) + "."), q(e), m('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', i, o), q(null);
}
}
function er(e, r) {
{
if (typeof e != "object")
return;
if (xe(e))
for (var i = 0; i < e.length; i++) {
var o = e[i];
je(o) && Ke(o, r);
}
else if (je(e))
e._store && (e._store.validated = !0);
else if (e) {
var f = F(e);
if (typeof f == "function" && f !== e.entries)
for (var p = f.call(e), s; !(s = p.next()).done; )
je(s.value) && Ke(s.value, r);
}
}
}
function Tr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var i;
if (typeof r == "function")
i = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === l || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === x))
i = r.propTypes;
else
return;
if (i) {
var o = A(r);
mr(i, e.props, "prop", o, e);
} else if (r.PropTypes !== void 0 && !Te) {
Te = !0;
var f = A(r);
m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", f || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function jr(e) {
{
for (var r = Object.keys(e.props), i = 0; i < r.length; i++) {
var o = r[i];
if (o !== "children" && o !== "key") {
q(e), m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", o), q(null);
break;
}
}
e.ref !== null && (q(e), m("Invalid attribute `ref` supplied to `React.Fragment`."), q(null));
}
}
var rr = {};
function tr(e, r, i, o, f, p) {
{
var s = Ee(e);
if (!s) {
var c = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (c += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var P = Cr(f);
P ? c += P : c += Ze();
var y;
e === null ? y = "null" : xe(e) ? y = "array" : e !== void 0 && e.$$typeof === a ? (y = "<" + (A(e.type) || "Unknown") + " />", c = " Did you accidentally export a JSX literal instead of a component?") : y = typeof e, m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", y, c);
}
var w = xr(e, r, i, f, p);
if (w == null)
return w;
if (s) {
var D = r.children;
if (D !== void 0)
if (o)
if (xe(D)) {
for (var z = 0; z < D.length; z++)
er(D[z], e);
Object.freeze && Object.freeze(D);
} else
m("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
er(D, e);
}
if (Q.call(r, "key")) {
var H = A(e), T = Object.keys(r).filter(function(Mr) {
return Mr !== "key";
}), Oe = T.length > 0 ? "{key: someKey, " + T.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!rr[H + Oe]) {
var Nr = T.length > 0 ? "{" + T.join(": ..., ") + ": ...}" : "{}";
m(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, Oe, H, Nr, H), rr[H + Oe] = !0;
}
}
return e === v ? jr(w) : Tr(w), w;
}
}
function Or(e, r, i) {
return tr(e, r, i, !0);
}
function Ar(e, r, i) {
return tr(e, r, i, !1);
}
var Dr = Ar, Fr = Or;
re.Fragment = v, re.jsx = Dr, re.jsxs = Fr;
}()), re;
}
process.env.NODE_ENV === "production" ? Ae.exports = qr() : Ae.exports = zr();
var b = Ae.exports, Gr = Object.defineProperty, Xr = (t, a, n) => a in t ? Gr(t, a, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[a] = n, De = (t, a, n) => (Xr(t, typeof a != "symbol" ? a + "" : a, n), n);
class sr extends Fe.Component {
constructor(a) {
super(a), De(this, "_el"), De(this, "renderPortal", () => Ir.createPortal(
this.props.children,
this._el
));
const n = document.createElement("div");
n.id = a.id, a.className && (n.className = a.className), this._el = n;
}
get typeProps() {
return this.props;
}
componentDidMount() {
const a = this.typeProps.containerSelector();
a == null || a.appendChild(this._el);
}
componentWillUnmount() {
const a = this.typeProps.containerSelector();
a == null || a.removeChild(this._el);
}
render() {
return this.renderPortal();
}
}
De(sr, "defaultProps", {
containerSelector: () => document.body
});
function me(t) {
var a = new Error(t);
return a.source = "ulid", a;
}
var Me = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", ne = Me.length, ir = Math.pow(2, 48) - 1, Zr = 10, Qr = 16;
function Kr(t) {
var a = Math.floor(t() * ne);
return a === ne && (a = ne - 1), Me.charAt(a);
}
function et(t, a) {
if (isNaN(t))
throw new Error(t + " must be a number");
if (t > ir)
throw me("cannot encode time greater than " + ir);
if (t < 0)
throw me("time must be positive");
if (Number.isInteger(t) === !1)
throw me("time must be an integer");
for (var n = void 0, v = ""; a > 0; a--)
n = t % ne, v = Me.charAt(n) + v, t = (t - n) / ne;
return v;
}
function rt(t, a) {
for (var n = ""; t > 0; t--)
n = Kr(a) + n;
return n;
}
function tt() {
var t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : !1, a = arguments[1];
a || (a = typeof window < "u" ? window : null);
var n = a && (a.crypto || a.msCrypto);
if (n)
return function() {
var E = new Uint8Array(1);
return n.getRandomValues(E), E[0] / 255;
};
try {
var v = require("crypto");
return function() {
return v.randomBytes(1).readUInt8() / 255;
};
} catch {
}
if (t) {
try {
console.error("secure crypto unusable, falling back to insecure Math.random()!");
} catch {
}
return function() {
return Math.random();
};
}
throw me("secure crypto unusable, insecure Math.random not allowed");
}
function nt(t) {
return t || (t = tt()), function(n) {
return isNaN(n) && (n = Date.now()), et(n, Zr) + rt(Qr, t);
};
}
var at = nt(), B = /* @__PURE__ */ ((t) => (t.Escape = "Escape", t.Enter = "Enter", t.Space = "Space", t.Tab = "Tab", t.ShiftAndTab = "Shift+Tab", t.ArrowUp = "ArrowUp", t.ArrowDown = "ArrowDown", t.ArrowLeft = "ArrowLeft", t.ArrowRight = "ArrowRight", t))(B || {});
const or = ({
onMousedown: t
}) => (X(() => (document.addEventListener("mousedown", t), () => {
document.removeEventListener("mousedown", t);
}), []), null), it = ({
onPickerHide: t
}) => (X(() => () => {
t();
}, []), null), ot = "acrool-react-picker__main-el", ct = "acrool-react-picker__picker-el", cr = {
"main-el": "acrool-react-picker__main-el",
mainEl: ot,
"picker-el": "acrool-react-picker__picker-el",
pickerEl: ct
}, $e = (t, a) => (n) => {
a.current = n, t && (typeof t == "function" ? t(n) : t && (t.current = n));
}, ur = {
variants: {
initial: { opacity: 0, transition: { type: "spring" } },
animate: { opacity: 1, transition: { type: "just" } },
exit: { opacity: 0, transition: { type: "just", duration: 0.1 } }
},
transition: {
duration: 0.3
}
}, st = {
variants: {
initial: { position: "absolute", zIndex: 999, opacity: 0.5 },
animate: { opacity: 1 },
exit: { opacity: 0, scale: 0.95, transition: { type: "just", duration: 0.1 } }
},
transition: {
type: "just",
duration: 0.2
}
}, ut = "acrool-react-picker__motion-animation-wrapper", lt = "acrool-react-picker__motion-mask-wrapper", be = {
"motion-animation-wrapper": "acrool-react-picker__motion-animation-wrapper",
motionAnimationWrapper: ut,
"motion-mask-wrapper": "acrool-react-picker__motion-mask-wrapper",
motionMaskWrapper: lt
}, ve = /* @__PURE__ */ new WeakMap();
function ft(t) {
if (ve.has(t))
return ve.get(t);
let a = t.parentElement;
for (; a; ) {
const { overflowY: n, position: v } = window.getComputedStyle(a);
if ((n === "auto" || n === "scroll") && a.scrollHeight > a.clientHeight)
return ve.set(t, a), a;
a = a.parentElement;
}
return ve.set(t, window), window;
}
const dt = (t, a, n, v) => {
var Y;
const E = (Y = t.current) == null ? void 0 : Y.firstChild, d = a.current;
if (!E || !d)
return;
const _ = d.getBoundingClientRect(), u = E.getBoundingClientRect(), l = window.innerHeight, R = window.innerWidth, g = window.pageYOffset || document.documentElement.scrollTop, x = window.pageXOffset || document.documentElement.scrollLeft, j = 8, C = u.top - j, M = l - u.bottom - j;
let O = (v == null ? void 0 : v.vertical) ?? (M >= C ? W.bottom : W.top), F = O === W.bottom ? M : C;
const k = _.width, m = u.left + k < R, J = u.right - k > 0;
let I = (v == null ? void 0 : v.horizontal) ?? te.left;
!m && J ? I = te.right : !m && !J && (I = te.left), n(O), d.style.top = O === W.bottom ? `${u.bottom + g}px` : `${u.top + g - F}px`, d.style.left = I === te.left ? `${u.left + x}px` : `${u.right + x - k}px`, d.style.minWidth = `${u.width}px`, d.style.height = `${F}px`, d.style.transformOrigin = O === W.bottom ? "top" : "bottom", d.style.flexDirection = O === W.bottom ? "column" : "column-reverse";
}, pt = ({
children: t,
isDebug: a = !1,
anchorRef: n,
onKeyDown: v,
isVisibleMask: E
}, d) => {
const _ = G(null), u = Jr(), l = N(() => {
dt(
n,
_,
u.setVertical,
u.importantPosition
);
}, [u.setVertical, u.importantPosition]);
return X(() => {
if (u.isVisible && n.current && _.current) {
const R = ft(n.current);
return R && (R.addEventListener("scroll", l), window.addEventListener("resize", l)), window.requestAnimationFrame(() => {
_.current && (_.current.style.display = "flex", l());
}), () => {
R && (R.removeEventListener("scroll", l), window.removeEventListener("resize", l));
};
}
}, [u.isVisible]), /* @__PURE__ */ b.jsxs(b.Fragment, { children: [
E && /* @__PURE__ */ b.jsx(
ge.div,
{
className: be.motionMaskWrapper,
initial: "initial",
animate: "animate",
exit: "exit",
...ur
},
"mask"
),
/* @__PURE__ */ b.jsx(
ge.div,
{
ref: $e(d, _),
style: { display: "none" },
className: be.motionAnimationWrapper,
initial: "initial",
animate: "animate",
exit: "exit",
tabIndex: 0,
...st,
onKeyDown: v,
"data-debug": a ? "" : void 0,
children: t
},
"main"
)
] });
}, vt = he(pt), mt = ({
children: t,
isDebug: a = !1,
onKeyDown: n,
isVisibleMask: v,
motionProps: E
}, d) => {
const _ = G(null);
return /* @__PURE__ */ b.jsxs(b.Fragment, { children: [
v && /* @__PURE__ */ b.jsx(
ge.div,
{
className: be.motionMaskWrapper,
initial: "initial",
animate: "animate",
exit: "exit",
...ur
},
"mask"
),
/* @__PURE__ */ b.jsx(
ge.div,
{
ref: $e(d, _),
className: be.motionAnimationWrapper,
onKeyDown: n,
"data-debug": a ? "" : void 0,
...E,
initial: "initial",
animate: "animate",
exit: "exit",
children: t
},
"main"
)
] });
}, ht = he(mt);
function Et(t, a, n) {
const v = he(t);
return he((d, _) => {
const [u, l] = pe(!1), [R, g] = pe(!1), [x, j] = pe(W.bottom), [C, M] = pe(), O = G(null), F = G(null), k = G(null), m = G(C), J = (n == null ? void 0 : n.isEnableClickOutSiteHidden) !== !1, I = (n == null ? void 0 : n.isEnableHideSave) !== !1, Y = n == null ? void 0 : n.isVisibleMask;
X(() => {
M(d.value);
}, [JSON.stringify(d.value)]), X(() => {
m.current = C;
}, [C]), X(() => {
u && M(d.value);
}, [u, d.value]);
const Z = N((h) => {
switch (h.key) {
case B.Escape:
ye(u)(h);
break;
case B.Tab:
case B.ShiftAndTab:
we(h);
break;
case B.ArrowUp:
case B.ArrowDown:
case B.Space:
ce(h);
break;
}
}, [u]), ye = N((h) => (S) => {
var L;
h && (S.stopPropagation(), S.preventDefault(), (L = F.current) == null || L.focus(), l(!1));
}, []), we = N((h) => {
var S;
(S = F.current) == null || S.focus(), l(!1), g(!1);
}, []), ce = N((h) => {
h.preventDefault(), l(!0);
}, []), Ee = N(() => {
requestAnimationFrame(() => {
var h;
n != null && n.isDisabledHideAutoFocus ? g(!1) : (h = F.current) == null || h.focus(), l(!1);
});
}, [n == null ? void 0 : n.isDisabledHideAutoFocus]), _e = N(() => {
l((h) => (h && requestAnimationFrame(() => {
var S;
(S = F.current) == null || S.focus();
}), !h));
}, []), se = N((h) => {
!O.current && k.current && !k.current.contains(h.target) && g(!1);
}, []), A = N((h) => {
var L;
const S = (L = O.current) == null ? void 0 : L.firstChild;
S && !S.contains(h.target) && k.current && !k.current.contains(h.target) && (l(!1), g(!1));
}, []), $ = N(() => {
if (typeof (d == null ? void 0 : d.onChange) > "u") {
V.warning("@acrool/react-picker", "createPicker component props onChange is undefined, is no call");
return;
}
typeof m.current < "u" && I && JSON.stringify(C) !== JSON.stringify(m.current) && d.onChange(m.current);
}, [C, d.onChange, I]), U = () => n != null && n.isDisabledAutoPosition ? /* @__PURE__ */ b.jsx(
ht,
{
ref: O,
isDebug: n == null ? void 0 : n.isDebug,
onKeyDown: Z,
isVisibleMask: Y,
motionProps: n == null ? void 0 : n.motionProps,
children: /* @__PURE__ */ b.jsx(a, { ...d })
}
) : /* @__PURE__ */ b.jsx(
vt,
{
ref: O,
anchorRef: k,
isDebug: n == null ? void 0 : n.isDebug,
onKeyDown: Z,
isVisibleMask: Y,
children: /* @__PURE__ */ b.jsx(a, { ...d })
}
);
return /* @__PURE__ */ b.jsx(
Ne.Provider,
{
value: {
hide: Ee,
show: () => l(!0),
toggle: _e,
isVisible: u,
inputFocus: () => g(!0),
inputBlur: () => g(!1),
isInputFocus: R,
value: C,
onChange: M,
importantPosition: n == null ? void 0 : n.importantPosition,
vertical: x,
setVertical: j
},
children: /* @__PURE__ */ b.jsxs(b.Fragment, { children: [
/* @__PURE__ */ b.jsx(
"div",
{
ref: k,
className: cr.mainEl,
onKeyDown: Z,
children: /* @__PURE__ */ b.jsx(
v,
{
...d,
ref: $e(_, F)
}
)
}
),
/* @__PURE__ */ b.jsx(Lr, { children: u && /* @__PURE__ */ b.jsx(
sr,
{
id: `acrool-react-picker-${at().toLowerCase()}`,
className: cr.pickerEl,
children: U()
}
) }),
u && /* @__PURE__ */ b.jsx(it, { onPickerHide: $ }),
J && u && /* @__PURE__ */ b.jsx(or, { onMousedown: A }),
R && /* @__PURE__ */ b.jsx(or, { onMousedown: se })
] })
}
);
});
}
export {
te as EHorizontal,
W as EVertical,
wt as PickerProviderConsumer,
Ne as PickerProviderContext,
Et as createPicker,
Jr as usePicker
};