react-select-items
Version:
React library for selecting multiple items
946 lines (943 loc) • 29.6 kB
JavaScript
import te, { createContext as Er, useMemo as Sr, useContext as Rr, useRef as q, useState as de, useCallback as L, useEffect as G } from "react";
var ve = { exports: {} }, X = {};
/**
* @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 Be;
function _r() {
if (Be) return X;
Be = 1;
var n = te, o = Symbol.for("react.element"), d = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, l = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, x = { key: !0, ref: !0, __self: !0, __source: !0 };
function R(m, v, h) {
var u, p = {}, O = null, b = null;
h !== void 0 && (O = "" + h), v.key !== void 0 && (O = "" + v.key), v.ref !== void 0 && (b = v.ref);
for (u in v) i.call(v, u) && !x.hasOwnProperty(u) && (p[u] = v[u]);
if (m && m.defaultProps) for (u in v = m.defaultProps, v) p[u] === void 0 && (p[u] = v[u]);
return { $$typeof: o, type: m, key: O, ref: b, props: p, _owner: l.current };
}
return X.Fragment = d, X.jsx = R, X.jsxs = R, X;
}
var J = {};
/**
* @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 Ye;
function wr() {
return Ye || (Ye = 1, process.env.NODE_ENV !== "production" && function() {
var n = te, o = Symbol.for("react.element"), d = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), l = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), R = Symbol.for("react.provider"), m = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), h = Symbol.for("react.suspense"), u = Symbol.for("react.suspense_list"), p = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), b = Symbol.for("react.offscreen"), P = Symbol.iterator, T = "@@iterator";
function w(e) {
if (e === null || typeof e != "object")
return null;
var r = P && e[P] || e[T];
return typeof r == "function" ? r : null;
}
var D = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function y(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), a = 1; a < r; a++)
t[a - 1] = arguments[a];
E("error", e, t);
}
}
function E(e, r, t) {
{
var a = D.ReactDebugCurrentFrame, f = a.getStackAddendum();
f !== "" && (r += "%s", t = t.concat([f]));
var g = t.map(function(c) {
return String(c);
});
g.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, g);
}
}
var Y = !1, M = !1, W = !1, H = !1, Ne = !1, pe;
pe = Symbol.for("react.module.reference");
function Ke(e) {
return !!(typeof e == "string" || typeof e == "function" || e === i || e === x || Ne || e === l || e === h || e === u || H || e === b || Y || M || W || typeof e == "object" && e !== null && (e.$$typeof === O || e.$$typeof === p || e.$$typeof === R || e.$$typeof === m || e.$$typeof === v || // 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 === pe || e.getModuleId !== void 0));
}
function ze(e, r, t) {
var a = e.displayName;
if (a)
return a;
var f = r.displayName || r.name || "";
return f !== "" ? t + "(" + f + ")" : t;
}
function ge(e) {
return e.displayName || "Context";
}
function k(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && y("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 i:
return "Fragment";
case d:
return "Portal";
case x:
return "Profiler";
case l:
return "StrictMode";
case h:
return "Suspense";
case u:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case m:
var r = e;
return ge(r) + ".Consumer";
case R:
var t = e;
return ge(t._context) + ".Provider";
case v:
return ze(e, e.render, "ForwardRef");
case p:
var a = e.displayName || null;
return a !== null ? a : k(e.type) || "Memo";
case O: {
var f = e, g = f._payload, c = f._init;
try {
return k(c(g));
} catch {
return null;
}
}
}
return null;
}
var A = Object.assign, N = 0, he, me, ye, be, Ee, Se, Re;
function _e() {
}
_e.__reactDisabledLog = !0;
function Xe() {
{
if (N === 0) {
he = console.log, me = console.info, ye = console.warn, be = console.error, Ee = console.group, Se = console.groupCollapsed, Re = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: _e,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
N++;
}
}
function Je() {
{
if (N--, N === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: A({}, e, {
value: he
}),
info: A({}, e, {
value: me
}),
warn: A({}, e, {
value: ye
}),
error: A({}, e, {
value: be
}),
group: A({}, e, {
value: Ee
}),
groupCollapsed: A({}, e, {
value: Se
}),
groupEnd: A({}, e, {
value: Re
})
});
}
N < 0 && y("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var ne = D.ReactCurrentDispatcher, oe;
function Z(e, r, t) {
{
if (oe === void 0)
try {
throw Error();
} catch (f) {
var a = f.stack.trim().match(/\n( *(at )?)/);
oe = a && a[1] || "";
}
return `
` + oe + e;
}
}
var ae = !1, Q;
{
var qe = typeof WeakMap == "function" ? WeakMap : Map;
Q = new qe();
}
function we(e, r) {
if (!e || ae)
return "";
{
var t = Q.get(e);
if (t !== void 0)
return t;
}
var a;
ae = !0;
var f = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var g;
g = ne.current, ne.current = null, Xe();
try {
if (r) {
var c = function() {
throw Error();
};
if (Object.defineProperty(c.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(c, []);
} catch (j) {
a = j;
}
Reflect.construct(e, [], c);
} else {
try {
c.call();
} catch (j) {
a = j;
}
e.call(c.prototype);
}
} else {
try {
throw Error();
} catch (j) {
a = j;
}
e();
}
} catch (j) {
if (j && a && typeof j.stack == "string") {
for (var s = j.stack.split(`
`), C = a.stack.split(`
`), S = s.length - 1, _ = C.length - 1; S >= 1 && _ >= 0 && s[S] !== C[_]; )
_--;
for (; S >= 1 && _ >= 0; S--, _--)
if (s[S] !== C[_]) {
if (S !== 1 || _ !== 1)
do
if (S--, _--, _ < 0 || s[S] !== C[_]) {
var I = `
` + s[S].replace(" at new ", " at ");
return e.displayName && I.includes("<anonymous>") && (I = I.replace("<anonymous>", e.displayName)), typeof e == "function" && Q.set(e, I), I;
}
while (S >= 1 && _ >= 0);
break;
}
}
} finally {
ae = !1, ne.current = g, Je(), Error.prepareStackTrace = f;
}
var U = e ? e.displayName || e.name : "", F = U ? Z(U) : "";
return typeof e == "function" && Q.set(e, F), F;
}
function Ge(e, r, t) {
return we(e, !1);
}
function He(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function ee(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return we(e, He(e));
if (typeof e == "string")
return Z(e);
switch (e) {
case h:
return Z("Suspense");
case u:
return Z("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case v:
return Ge(e.render);
case p:
return ee(e.type, r, t);
case O: {
var a = e, f = a._payload, g = a._init;
try {
return ee(g(f), r, t);
} catch {
}
}
}
return "";
}
var K = Object.prototype.hasOwnProperty, xe = {}, Oe = D.ReactDebugCurrentFrame;
function re(e) {
if (e) {
var r = e._owner, t = ee(e.type, e._source, r ? r.type : null);
Oe.setExtraStackFrame(t);
} else
Oe.setExtraStackFrame(null);
}
function Ze(e, r, t, a, f) {
{
var g = Function.call.bind(K);
for (var c in e)
if (g(e, c)) {
var s = void 0;
try {
if (typeof e[c] != "function") {
var C = Error((a || "React class") + ": " + t + " type `" + c + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[c] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw C.name = "Invariant Violation", C;
}
s = e[c](r, c, a, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (S) {
s = S;
}
s && !(s instanceof Error) && (re(f), y("%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).", a || "React class", t, c, typeof s), re(null)), s instanceof Error && !(s.message in xe) && (xe[s.message] = !0, re(f), y("Failed %s type: %s", t, s.message), re(null));
}
}
}
var Qe = Array.isArray;
function ie(e) {
return Qe(e);
}
function er(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function rr(e) {
try {
return Te(e), !1;
} catch {
return !0;
}
}
function Te(e) {
return "" + e;
}
function Ce(e) {
if (rr(e))
return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", er(e)), Te(e);
}
var z = D.ReactCurrentOwner, tr = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Pe, je, se;
se = {};
function nr(e) {
if (K.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function or(e) {
if (K.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function ar(e, r) {
if (typeof e.ref == "string" && z.current && r && z.current.stateNode !== r) {
var t = k(z.current.type);
se[t] || (y('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', k(z.current.type), e.ref), se[t] = !0);
}
}
function ir(e, r) {
{
var t = function() {
Pe || (Pe = !0, y("%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));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function sr(e, r) {
{
var t = function() {
je || (je = !0, y("%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));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var ur = function(e, r, t, a, f, g, c) {
var s = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: o,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: c,
// Record the component responsible for creating this element.
_owner: g
};
return s._store = {}, Object.defineProperty(s._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(s, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: a
}), Object.defineProperty(s, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: f
}), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
};
function cr(e, r, t, a, f) {
{
var g, c = {}, s = null, C = null;
t !== void 0 && (Ce(t), s = "" + t), or(r) && (Ce(r.key), s = "" + r.key), nr(r) && (C = r.ref, ar(r, f));
for (g in r)
K.call(r, g) && !tr.hasOwnProperty(g) && (c[g] = r[g]);
if (e && e.defaultProps) {
var S = e.defaultProps;
for (g in S)
c[g] === void 0 && (c[g] = S[g]);
}
if (s || C) {
var _ = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
s && ir(c, _), C && sr(c, _);
}
return ur(e, s, C, f, a, z.current, c);
}
}
var ue = D.ReactCurrentOwner, De = D.ReactDebugCurrentFrame;
function $(e) {
if (e) {
var r = e._owner, t = ee(e.type, e._source, r ? r.type : null);
De.setExtraStackFrame(t);
} else
De.setExtraStackFrame(null);
}
var ce;
ce = !1;
function le(e) {
return typeof e == "object" && e !== null && e.$$typeof === o;
}
function Ie() {
{
if (ue.current) {
var e = k(ue.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function lr(e) {
return "";
}
var ke = {};
function fr(e) {
{
var r = Ie();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function Me(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = fr(r);
if (ke[t])
return;
ke[t] = !0;
var a = "";
e && e._owner && e._owner !== ue.current && (a = " It was passed a child from " + k(e._owner.type) + "."), $(e), y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, a), $(null);
}
}
function Ae(e, r) {
{
if (typeof e != "object")
return;
if (ie(e))
for (var t = 0; t < e.length; t++) {
var a = e[t];
le(a) && Me(a, r);
}
else if (le(e))
e._store && (e._store.validated = !0);
else if (e) {
var f = w(e);
if (typeof f == "function" && f !== e.entries)
for (var g = f.call(e), c; !(c = g.next()).done; )
le(c.value) && Me(c.value, r);
}
}
}
function dr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === v || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === p))
t = r.propTypes;
else
return;
if (t) {
var a = k(r);
Ze(t, e.props, "prop", a, e);
} else if (r.PropTypes !== void 0 && !ce) {
ce = !0;
var f = k(r);
y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", f || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function vr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var a = r[t];
if (a !== "children" && a !== "key") {
$(e), y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", a), $(null);
break;
}
}
e.ref !== null && ($(e), y("Invalid attribute `ref` supplied to `React.Fragment`."), $(null));
}
}
var Fe = {};
function Le(e, r, t, a, f, g) {
{
var c = Ke(e);
if (!c) {
var s = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (s += " 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 C = lr();
C ? s += C : s += Ie();
var S;
e === null ? S = "null" : ie(e) ? S = "array" : e !== void 0 && e.$$typeof === o ? (S = "<" + (k(e.type) || "Unknown") + " />", s = " Did you accidentally export a JSX literal instead of a component?") : S = typeof e, y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", S, s);
}
var _ = cr(e, r, t, f, g);
if (_ == null)
return _;
if (c) {
var I = r.children;
if (I !== void 0)
if (a)
if (ie(I)) {
for (var U = 0; U < I.length; U++)
Ae(I[U], e);
Object.freeze && Object.freeze(I);
} else
y("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
Ae(I, e);
}
if (K.call(r, "key")) {
var F = k(e), j = Object.keys(r).filter(function(br) {
return br !== "key";
}), fe = j.length > 0 ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!Fe[F + fe]) {
var yr = j.length > 0 ? "{" + j.join(": ..., ") + ": ...}" : "{}";
y(`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} />`, fe, F, yr, F), Fe[F + fe] = !0;
}
}
return e === i ? vr(_) : dr(_), _;
}
}
function pr(e, r, t) {
return Le(e, r, t, !0);
}
function gr(e, r, t) {
return Le(e, r, t, !1);
}
var hr = gr, mr = pr;
J.Fragment = i, J.jsx = hr, J.jsxs = mr;
}()), J;
}
process.env.NODE_ENV === "production" ? ve.exports = _r() : ve.exports = wr();
var B = ve.exports;
const We = (n) => {
let o;
const d = /* @__PURE__ */ new Set(), i = (h, u) => {
const p = typeof h == "function" ? h(o) : h;
if (!Object.is(p, o)) {
const O = o;
o = u ?? (typeof p != "object" || p === null) ? p : Object.assign({}, o, p), d.forEach((b) => b(o, O));
}
}, l = () => o, m = { setState: i, getState: l, getInitialState: () => v, subscribe: (h) => (d.add(h), () => d.delete(h)) }, v = o = n(i, l, m);
return m;
}, xr = (n) => n ? We(n) : We, Or = (n) => n;
function Tr(n, o = Or) {
const d = te.useSyncExternalStore(
n.subscribe,
() => o(n.getState()),
() => o(n.getInitialState())
);
return te.useDebugValue(d), d;
}
const $e = (n) => {
const o = xr(n), d = (i) => Tr(o, i);
return Object.assign(d, o), d;
}, Cr = (n) => n ? $e(n) : $e, Ue = Er(null), Pr = ({ children: n }) => {
const d = Sr(
() => Cr((i) => ({
selectedIndexes: /* @__PURE__ */ new Set(),
setSelectedIndexes: (l) => i({ selectedIndexes: l }),
focusedIndex: 0,
setFocusedIndex: (l) => i({ focusedIndex: l }),
selectionOptions: {
useCtrl: !0,
useShift: !0,
useCtrlShift: !0,
useDrag: !0,
useShiftToDrag: !1
},
setSelectionOptions: (l) => i((x) => ({
selectionOptions: {
...x.selectionOptions,
...l
}
})),
dragBoxElement: null,
setDragBoxElement: (l) => i({ dragBoxElement: l }),
isDragging: !1,
setIsDragging: (l) => i({ isDragging: l })
})),
[]
)();
return /* @__PURE__ */ B.jsx(Ue.Provider, { value: d, children: n });
}, V = () => {
const n = Rr(Ue);
if (!n)
throw new Error("useSelectStore must be used within a SelectProvider");
return n;
}, jr = "react-select-items-drag-box";
function Dr({ position: n, size: o, className: d }) {
const { setDragBoxElement: i } = V();
return /* @__PURE__ */ B.jsx(
"div",
{
ref: i,
className: d ?? jr,
style: {
position: "fixed",
border: "1px dashed gray",
left: n.x,
top: n.y,
width: o.width,
height: o.height
}
}
);
}
function Ir({ useShift: n }) {
const o = q(null), { setIsDragging: d } = V(), [i, l] = de(null), [x, R] = de(null), [m, v] = de(null), h = q(null), u = q(null), p = L(
(b) => {
var T, w;
if (!o.current || n && !b.shiftKey || ((T = o.current) == null ? void 0 : T.x) === b.clientX && ((w = o.current) == null ? void 0 : w.y) === b.clientY || (d(!0), !i || !u.current)) return;
const P = {
x: Math.max(
u.current.left,
Math.min(b.clientX, u.current.right)
),
y: Math.max(
u.current.top,
Math.min(b.clientY, u.current.bottom)
)
};
R(
kr({
dragStartPoint: i,
dragEndPoint: P
})
), v(
Mr({
dragStartPoint: i,
dragEndPoint: P
})
);
},
[i, d, n]
), O = L(() => {
l(null), R(null), v(null), o.current = null;
}, []);
return G(() => {
const b = h.current;
if (!b) return;
const P = (T) => {
o.current = { x: T.clientX, y: T.clientY };
const w = b.getBoundingClientRect();
u.current = w;
const D = {
x: Math.max(w.left, Math.min(T.clientX, w.right)),
y: Math.max(w.top, Math.min(T.clientY, w.bottom))
};
l(D);
};
return b.addEventListener("mousedown", P), window.addEventListener("mousemove", p), window.addEventListener("mouseup", O), () => {
b.removeEventListener("mousedown", P), window.removeEventListener("mousemove", p), window.removeEventListener("mouseup", O);
};
}, [p, O]), {
wrapperRef: h,
dragBoxPosition: x,
dragBoxSize: m
};
}
function kr({
dragStartPoint: n,
dragEndPoint: o
}) {
return {
x: Math.min(n.x, o.x),
y: Math.min(n.y, o.y)
};
}
function Mr({
dragStartPoint: n,
dragEndPoint: o
}) {
return {
width: Math.abs(o.x - n.x),
height: Math.abs(o.y - n.y)
};
}
function Ve() {
const { selectedIndexes: n, setSelectedIndexes: o } = V(), d = L(
(m) => {
o(/* @__PURE__ */ new Set([m]));
},
[o]
), i = L(
(m) => {
o(/* @__PURE__ */ new Set([...n, m]));
},
[n, o]
), l = L(
(m) => {
o(
new Set(
[...n].filter((v) => v !== m)
)
);
},
[n, o]
), x = L(
({
startIndex: m,
endIndex: v,
append: h
}) => {
const u = h ? /* @__PURE__ */ new Set([...n]) : /* @__PURE__ */ new Set();
for (let p = m; p <= v; p++)
u.add(p);
o(u);
},
[n, o]
), R = L(() => {
o(/* @__PURE__ */ new Set());
}, [o]);
return { selectOnlyOne: d, select: i, unselect: l, selectRange: x, unselectAll: R };
}
function Ar({
onSelect: n,
onUnselect: o,
onFocus: d,
options: i,
dragBoxClassName: l,
children: x
}) {
const {
selectedIndexes: R,
focusedIndex: m,
isDragging: v,
setIsDragging: h,
setSelectionOptions: u
} = V(), p = q(R), { selectionOptions: O } = V(), { wrapperRef: b, dragBoxPosition: P, dragBoxSize: T } = Ir({
useShift: O.useShiftToDrag
}), { unselectAll: w } = Ve();
G(() => {
i && u(i);
}, [i, u]), G(() => {
const y = p.current;
R.forEach((E) => {
y.has(E) || n(E);
}), y.forEach((E) => {
R.has(E) || o(E);
}), d(m), p.current = R;
}, [R, m]), G(() => {
if (!b.current) return;
const E = () => {
h(!1);
};
return window.addEventListener("mouseup", E), () => {
window.removeEventListener("mouseup", E);
};
}, [h, b]);
const D = (y) => {
y.target instanceof HTMLElement && !y.target.closest(".temp") && !v && w(), h(!1);
};
return /* @__PURE__ */ B.jsxs(
"div",
{
ref: b,
onMouseUp: D,
style: { width: "100%", height: "100%" },
children: [
P && T && /* @__PURE__ */ B.jsx(
Dr,
{
position: { x: P.x, y: P.y },
size: { width: T.width, height: T.height },
className: l
}
),
x
]
}
);
}
function Lr({
onSelect: n = () => {
},
onUnselect: o = () => {
},
onFocus: d = () => {
},
options: i,
dragBoxClassName: l,
children: x
}) {
return /* @__PURE__ */ B.jsx(Pr, { children: /* @__PURE__ */ B.jsx(
Ar,
{
onSelect: n,
onUnselect: o,
onFocus: d,
options: i,
dragBoxClassName: l,
children: x
}
) });
}
function Br({ index: n, children: o }) {
const { selectOnlyOne: d, select: i, unselect: l, selectRange: x } = Ve(), {
focusedIndex: R,
setFocusedIndex: m,
selectionOptions: v,
selectedIndexes: h,
dragBoxElement: u,
setIsDragging: p
} = V(), { useCtrl: O, useShift: b, useCtrlShift: P } = v, T = q(null), w = h.has(n), D = (E) => {
if (p(!1), m(n), O && E.ctrlKey && !E.shiftKey)
w ? l(n) : i(n);
else if (b && E.shiftKey) {
const Y = Math.min(R, n), M = Math.max(R, n);
x({
startIndex: Y,
endIndex: M,
append: !!P && E.ctrlKey
});
} else {
if (h.size > 1 && w)
return;
d(n);
}
}, y = (E) => {
h.size > 1 && w && !E.ctrlKey && !E.shiftKey && d(n);
};
return G(() => {
const E = T.current, Y = () => {
if (!u || !E)
return;
const M = u.getBoundingClientRect(), W = E.getBoundingClientRect(), H = !(M.right < W.left || M.left > W.right || M.bottom < W.top || M.top > W.bottom);
H && !w ? i(n) : !H && w && l(n);
};
return u && window.addEventListener("mousemove", Y), () => {
window.removeEventListener("mousemove", Y);
};
}, [u, n, w, i, l]), /* @__PURE__ */ B.jsx(
"div",
{
ref: T,
onMouseDown: D,
onMouseUp: y,
className: "temp",
children: o
}
);
}
export {
Lr as SelectArea,
Br as Selectable
};