multi-source-select
Version:
Multi-source select control
1,455 lines (1,452 loc) • 60.3 kB
JavaScript
import "./MultiSelect.css";
import * as w from "react";
import be from "react";
var He = { exports: {} }, Ye = {};
/**
* @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 nt;
function It() {
if (nt)
return Ye;
nt = 1;
var t = be, n = Symbol.for("react.element"), r = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, f = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, y = { key: !0, ref: !0, __self: !0, __source: !0 };
function p(d, m, _) {
var R, C = {}, B = null, N = null;
_ !== void 0 && (B = "" + _), m.key !== void 0 && (B = "" + m.key), m.ref !== void 0 && (N = m.ref);
for (R in m)
i.call(m, R) && !y.hasOwnProperty(R) && (C[R] = m[R]);
if (d && d.defaultProps)
for (R in m = d.defaultProps, m)
C[R] === void 0 && (C[R] = m[R]);
return { $$typeof: n, type: d, key: B, ref: N, props: C, _owner: f.current };
}
return Ye.Fragment = r, Ye.jsx = p, Ye.jsxs = p, Ye;
}
var Be = {};
/**
* @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 ot;
function At() {
return ot || (ot = 1, process.env.NODE_ENV !== "production" && function() {
var t = be, n = Symbol.for("react.element"), r = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), f = Symbol.for("react.strict_mode"), y = Symbol.for("react.profiler"), p = Symbol.for("react.provider"), d = Symbol.for("react.context"), m = Symbol.for("react.forward_ref"), _ = Symbol.for("react.suspense"), R = Symbol.for("react.suspense_list"), C = Symbol.for("react.memo"), B = Symbol.for("react.lazy"), N = Symbol.for("react.offscreen"), J = Symbol.iterator, L = "@@iterator";
function K(e) {
if (e === null || typeof e != "object")
return null;
var a = J && e[J] || e[L];
return typeof a == "function" ? a : null;
}
var h = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function s(e) {
{
for (var a = arguments.length, c = new Array(a > 1 ? a - 1 : 0), x = 1; x < a; x++)
c[x - 1] = arguments[x];
O("error", e, c);
}
}
function O(e, a, c) {
{
var x = h.ReactDebugCurrentFrame, A = x.getStackAddendum();
A !== "" && (a += "%s", c = c.concat([A]));
var $ = c.map(function(F) {
return String(F);
});
$.unshift("Warning: " + a), Function.prototype.apply.call(console[e], console, $);
}
}
var U = !1, P = !1, te = !1, oe = !1, X = !1, re;
re = Symbol.for("react.module.reference");
function ue(e) {
return !!(typeof e == "string" || typeof e == "function" || e === i || e === y || X || e === f || e === _ || e === R || oe || e === N || U || P || te || typeof e == "object" && e !== null && (e.$$typeof === B || e.$$typeof === C || e.$$typeof === p || e.$$typeof === d || e.$$typeof === m || // 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 === re || e.getModuleId !== void 0));
}
function ae(e, a, c) {
var x = e.displayName;
if (x)
return x;
var A = a.displayName || a.name || "";
return A !== "" ? c + "(" + A + ")" : c;
}
function Q(e) {
return e.displayName || "Context";
}
function b(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && s("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 r:
return "Portal";
case y:
return "Profiler";
case f:
return "StrictMode";
case _:
return "Suspense";
case R:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case d:
var a = e;
return Q(a) + ".Consumer";
case p:
var c = e;
return Q(c._context) + ".Provider";
case m:
return ae(e, e.render, "ForwardRef");
case C:
var x = e.displayName || null;
return x !== null ? x : b(e.type) || "Memo";
case B: {
var A = e, $ = A._payload, F = A._init;
try {
return b(F($));
} catch {
return null;
}
}
}
return null;
}
var D = Object.assign, g = 0, E, V, ie, se, Oe, I, ne;
function z() {
}
z.__reactDisabledLog = !0;
function _e() {
{
if (g === 0) {
E = console.log, V = console.info, ie = console.warn, se = console.error, Oe = console.group, I = console.groupCollapsed, ne = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: z,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
g++;
}
}
function ce() {
{
if (g--, g === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: D({}, e, {
value: E
}),
info: D({}, e, {
value: V
}),
warn: D({}, e, {
value: ie
}),
error: D({}, e, {
value: se
}),
group: D({}, e, {
value: Oe
}),
groupCollapsed: D({}, e, {
value: I
}),
groupEnd: D({}, e, {
value: ne
})
});
}
g < 0 && s("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var Ee = h.ReactCurrentDispatcher, Re;
function ge(e, a, c) {
{
if (Re === void 0)
try {
throw Error();
} catch (A) {
var x = A.stack.trim().match(/\n( *(at )?)/);
Re = x && x[1] || "";
}
return `
` + Re + e;
}
}
var Te = !1, Ce;
{
var fe = typeof WeakMap == "function" ? WeakMap : Map;
Ce = new fe();
}
function je(e, a) {
if (!e || Te)
return "";
{
var c = Ce.get(e);
if (c !== void 0)
return c;
}
var x;
Te = !0;
var A = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var $;
$ = Ee.current, Ee.current = null, _e();
try {
if (a) {
var F = function() {
throw Error();
};
if (Object.defineProperty(F.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(F, []);
} catch (xe) {
x = xe;
}
Reflect.construct(e, [], F);
} else {
try {
F.call();
} catch (xe) {
x = xe;
}
e.call(F.prototype);
}
} else {
try {
throw Error();
} catch (xe) {
x = xe;
}
e();
}
} catch (xe) {
if (xe && x && typeof xe.stack == "string") {
for (var j = xe.stack.split(`
`), ee = x.stack.split(`
`), G = j.length - 1, H = ee.length - 1; G >= 1 && H >= 0 && j[G] !== ee[H]; )
H--;
for (; G >= 1 && H >= 0; G--, H--)
if (j[G] !== ee[H]) {
if (G !== 1 || H !== 1)
do
if (G--, H--, H < 0 || j[G] !== ee[H]) {
var le = `
` + j[G].replace(" at new ", " at ");
return e.displayName && le.includes("<anonymous>") && (le = le.replace("<anonymous>", e.displayName)), typeof e == "function" && Ce.set(e, le), le;
}
while (G >= 1 && H >= 0);
break;
}
}
} finally {
Te = !1, Ee.current = $, ce(), Error.prepareStackTrace = A;
}
var Ne = e ? e.displayName || e.name : "", rt = Ne ? ge(Ne) : "";
return typeof e == "function" && Ce.set(e, rt), rt;
}
function Me(e, a, c) {
return je(e, !1);
}
function Fe(e) {
var a = e.prototype;
return !!(a && a.isReactComponent);
}
function ve(e, a, c) {
if (e == null)
return "";
if (typeof e == "function")
return je(e, Fe(e));
if (typeof e == "string")
return ge(e);
switch (e) {
case _:
return ge("Suspense");
case R:
return ge("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case m:
return Me(e.render);
case C:
return ve(e.type, a, c);
case B: {
var x = e, A = x._payload, $ = x._init;
try {
return ve($(A), a, c);
} catch {
}
}
}
return "";
}
var me = Object.prototype.hasOwnProperty, Pe = {}, Ie = h.ReactDebugCurrentFrame;
function Se(e) {
if (e) {
var a = e._owner, c = ve(e.type, e._source, a ? a.type : null);
Ie.setExtraStackFrame(c);
} else
Ie.setExtraStackFrame(null);
}
function De(e, a, c, x, A) {
{
var $ = Function.call.bind(me);
for (var F in e)
if ($(e, F)) {
var j = void 0;
try {
if (typeof e[F] != "function") {
var ee = Error((x || "React class") + ": " + c + " type `" + F + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[F] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw ee.name = "Invariant Violation", ee;
}
j = e[F](a, F, x, c, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (G) {
j = G;
}
j && !(j instanceof Error) && (Se(A), s("%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).", x || "React class", c, F, typeof j), Se(null)), j instanceof Error && !(j.message in Pe) && (Pe[j.message] = !0, Se(A), s("Failed %s type: %s", c, j.message), Se(null));
}
}
}
var Le = Array.isArray;
function we(e) {
return Le(e);
}
function Ve(e) {
{
var a = typeof Symbol == "function" && Symbol.toStringTag, c = a && e[Symbol.toStringTag] || e.constructor.name || "Object";
return c;
}
}
function Ue(e) {
try {
return Ae(e), !1;
} catch {
return !0;
}
}
function Ae(e) {
return "" + e;
}
function $e(e) {
if (Ue(e))
return s("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ve(e)), Ae(e);
}
var ye = h.ReactCurrentOwner, l = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, S, M, W;
W = {};
function q(e) {
if (me.call(e, "ref")) {
var a = Object.getOwnPropertyDescriptor(e, "ref").get;
if (a && a.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function o(e) {
if (me.call(e, "key")) {
var a = Object.getOwnPropertyDescriptor(e, "key").get;
if (a && a.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function u(e, a) {
if (typeof e.ref == "string" && ye.current && a && ye.current.stateNode !== a) {
var c = b(ye.current.type);
W[c] || (s('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', b(ye.current.type), e.ref), W[c] = !0);
}
}
function v(e, a) {
{
var c = function() {
S || (S = !0, s("%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)", a));
};
c.isReactWarning = !0, Object.defineProperty(e, "key", {
get: c,
configurable: !0
});
}
}
function T(e, a) {
{
var c = function() {
M || (M = !0, s("%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)", a));
};
c.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: c,
configurable: !0
});
}
}
var Y = function(e, a, c, x, A, $, F) {
var j = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: n,
// Built-in properties that belong on the element
type: e,
key: a,
ref: c,
props: F,
// Record the component responsible for creating this element.
_owner: $
};
return j._store = {}, Object.defineProperty(j._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(j, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: x
}), Object.defineProperty(j, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: A
}), Object.freeze && (Object.freeze(j.props), Object.freeze(j)), j;
};
function Z(e, a, c, x, A) {
{
var $, F = {}, j = null, ee = null;
c !== void 0 && ($e(c), j = "" + c), o(a) && ($e(a.key), j = "" + a.key), q(a) && (ee = a.ref, u(a, A));
for ($ in a)
me.call(a, $) && !l.hasOwnProperty($) && (F[$] = a[$]);
if (e && e.defaultProps) {
var G = e.defaultProps;
for ($ in G)
F[$] === void 0 && (F[$] = G[$]);
}
if (j || ee) {
var H = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
j && v(F, H), ee && T(F, H);
}
return Y(e, j, ee, A, x, ye.current, F);
}
}
var pe = h.ReactCurrentOwner, We = h.ReactDebugCurrentFrame;
function de(e) {
if (e) {
var a = e._owner, c = ve(e.type, e._source, a ? a.type : null);
We.setExtraStackFrame(c);
} else
We.setExtraStackFrame(null);
}
var Ke;
Ke = !1;
function ze(e) {
return typeof e == "object" && e !== null && e.$$typeof === n;
}
function Xe() {
{
if (pe.current) {
var e = b(pe.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function _t(e) {
{
if (e !== void 0) {
var a = e.fileName.replace(/^.*[\\\/]/, ""), c = e.lineNumber;
return `
Check your code at ` + a + ":" + c + ".";
}
return "";
}
}
var Ze = {};
function Rt(e) {
{
var a = Xe();
if (!a) {
var c = typeof e == "string" ? e : e.displayName || e.name;
c && (a = `
Check the top-level render call using <` + c + ">.");
}
return a;
}
}
function Qe(e, a) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var c = Rt(a);
if (Ze[c])
return;
Ze[c] = !0;
var x = "";
e && e._owner && e._owner !== pe.current && (x = " It was passed a child from " + b(e._owner.type) + "."), de(e), s('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', c, x), de(null);
}
}
function et(e, a) {
{
if (typeof e != "object")
return;
if (we(e))
for (var c = 0; c < e.length; c++) {
var x = e[c];
ze(x) && Qe(x, a);
}
else if (ze(e))
e._store && (e._store.validated = !0);
else if (e) {
var A = K(e);
if (typeof A == "function" && A !== e.entries)
for (var $ = A.call(e), F; !(F = $.next()).done; )
ze(F.value) && Qe(F.value, a);
}
}
}
function Tt(e) {
{
var a = e.type;
if (a == null || typeof a == "string")
return;
var c;
if (typeof a == "function")
c = a.propTypes;
else if (typeof a == "object" && (a.$$typeof === m || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
a.$$typeof === C))
c = a.propTypes;
else
return;
if (c) {
var x = b(a);
De(c, e.props, "prop", x, e);
} else if (a.PropTypes !== void 0 && !Ke) {
Ke = !0;
var A = b(a);
s("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", A || "Unknown");
}
typeof a.getDefaultProps == "function" && !a.getDefaultProps.isReactClassApproved && s("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function jt(e) {
{
for (var a = Object.keys(e.props), c = 0; c < a.length; c++) {
var x = a[c];
if (x !== "children" && x !== "key") {
de(e), s("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", x), de(null);
break;
}
}
e.ref !== null && (de(e), s("Invalid attribute `ref` supplied to `React.Fragment`."), de(null));
}
}
function tt(e, a, c, x, A, $) {
{
var F = ue(e);
if (!F) {
var j = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (j += " 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 ee = _t(A);
ee ? j += ee : j += Xe();
var G;
e === null ? G = "null" : we(e) ? G = "array" : e !== void 0 && e.$$typeof === n ? (G = "<" + (b(e.type) || "Unknown") + " />", j = " Did you accidentally export a JSX literal instead of a component?") : G = typeof e, s("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", G, j);
}
var H = Z(e, a, c, A, $);
if (H == null)
return H;
if (F) {
var le = a.children;
if (le !== void 0)
if (x)
if (we(le)) {
for (var Ne = 0; Ne < le.length; Ne++)
et(le[Ne], e);
Object.freeze && Object.freeze(le);
} else
s("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
et(le, e);
}
return e === i ? jt(H) : Tt(H), H;
}
}
function Pt(e, a, c) {
return tt(e, a, c, !0);
}
function Dt(e, a, c) {
return tt(e, a, c, !1);
}
var Mt = Dt, Ft = Pt;
Be.Fragment = i, Be.jsx = Mt, Be.jsxs = Ft;
}()), Be;
}
process.env.NODE_ENV === "production" ? He.exports = It() : He.exports = At();
var k = He.exports;
const cr = ["=", "!"], ur = ["=", "!", "*", "!*", "<*", ">*"], fr = ["=", ">", "<", ">=", "<=", "!"], at = "~~func~~", he = () => {
const t = (n) => {
const r = () => Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
let i = "", f = 0;
for (n = n || 1; f < n; )
i += r(), f++;
return i;
};
return `${t(2)}-${t()}-${t()}-${t()}-${t(3)}`;
}, dt = (t, n, r) => r.indexOf(t) === n, ht = (t, n) => n.valueGetter && typeof t == "object" ? n.valueGetter(t) : t.toString(), gt = (t, n) => n.textGetter && typeof t == "object" ? n.textGetter(t) : t.toString(), vt = 10, mt = w.createContext(!1), qe = w.createContext({
dataSources: [],
defaultComparison: "=",
and: "&",
or: "|",
comparisons: [],
comparisonDescriptions: [],
operators: "Complex",
defaultItemLimit: vt
}), yt = w.createContext({
matchers: [],
activeFunction: null
});
var xt = {
color: void 0,
size: void 0,
className: void 0,
style: void 0,
attr: void 0
}, it = be.createContext && be.createContext(xt), ke = globalThis && globalThis.__assign || function() {
return ke = Object.assign || function(t) {
for (var n, r = 1, i = arguments.length; r < i; r++) {
n = arguments[r];
for (var f in n)
Object.prototype.hasOwnProperty.call(n, f) && (t[f] = n[f]);
}
return t;
}, ke.apply(this, arguments);
}, $t = globalThis && globalThis.__rest || function(t, n) {
var r = {};
for (var i in t)
Object.prototype.hasOwnProperty.call(t, i) && n.indexOf(i) < 0 && (r[i] = t[i]);
if (t != null && typeof Object.getOwnPropertySymbols == "function")
for (var f = 0, i = Object.getOwnPropertySymbols(t); f < i.length; f++)
n.indexOf(i[f]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[f]) && (r[i[f]] = t[i[f]]);
return r;
};
function bt(t) {
return t && t.map(function(n, r) {
return be.createElement(n.tag, ke({
key: r
}, n.attr), bt(n.child));
});
}
function Ge(t) {
return function(n) {
return be.createElement(Nt, ke({
attr: ke({}, t.attr)
}, n), bt(t.child));
};
}
function Nt(t) {
var n = function(r) {
var i = t.attr, f = t.size, y = t.title, p = $t(t, ["attr", "size", "title"]), d = f || r.size || "1em", m;
return r.className && (m = r.className), t.className && (m = (m ? m + " " : "") + t.className), be.createElement("svg", ke({
stroke: "currentColor",
fill: "currentColor",
strokeWidth: "0"
}, r.attr, i, p, {
className: m,
style: ke(ke({
color: t.color || r.color
}, r.style), t.style),
height: d,
width: d,
xmlns: "http://www.w3.org/2000/svg"
}), y && be.createElement("title", null, y), t.children);
};
return it !== void 0 ? be.createElement(it.Consumer, null, function(r) {
return n(r);
}) : n(xt);
}
function Lt(t) {
return Ge({ tag: "svg", attr: { viewBox: "0 0 320 512" }, child: [{ tag: "path", attr: { d: "M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z" } }] })(t);
}
const Vt = ({
options: t,
activeOption: n,
onSelectOption: r,
onSelectActiveOption: i,
onSelectOperator: f,
onSelectComparison: y,
onSelectText: p,
styles: d
}) => {
const [m, _] = w.useState(null), R = w.useRef(null), C = w.useContext(qe);
w.useEffect(() => {
R.current && R.current.scrollIntoView && R.current.scrollIntoView({ block: "end", behavior: "smooth" });
}, [n]);
const B = (K, h) => {
r(h), K.stopPropagation();
}, N = () => {
let K = 0;
return t.map((h) => {
const [s, O] = h;
return /* @__PURE__ */ k.jsxs("ul", { children: [
/* @__PURE__ */ k.jsx("li", { className: "optionListCategory", style: d == null ? void 0 : d.optionCategory, children: s }),
O.map((U) => {
const P = K++;
return /* @__PURE__ */ k.jsx(
"li",
{
ref: P === n ? R : void 0,
className: P === n ? "optionListOption optionListActiveOption" : "optionListOption",
style: P === n ? d == null ? void 0 : d.activeOption : d == null ? void 0 : d.option,
onMouseEnter: () => i(P),
onClick: (te) => B(te, U),
children: U.text
},
U.value.toString()
);
})
] }, s);
});
}, J = (K) => {
const h = [];
return C.operators !== "Simple" && (h.push({ header: "Operators" }), h.push({ text: "And", value: "and", type: "operator" }), h.push({ text: "Or", value: "or", type: "operator" }), C.operators === "Complex" && (h.push({ text: "( Open bracket", value: "(", type: "operator" }), h.push({ text: ") Close bracket", value: ")", type: "operator" }))), C.operators !== "Simple" && (h.push({ header: "Comparison" }), h.push(...C.comparisonDescriptions.map((s) => ({ text: s.description === "" ? s.symbol : s.description, value: s.symbol, type: "comparison" })))), C.dataSources.forEach((s) => {
let O = null;
s.definitions.forEach((U) => {
s.hideOnShortcut || ("source" in U && U.source ? typeof U.source != "function" ? O !== s.title && (h.push({ header: s.title }), h.push(...U.source.map((P) => ({ text: gt(P, U), value: ht(P, U), type: s.name })))) : O !== s.title && h.push({ header: s.title, type: "Lookup" }) : O !== s.title && h.push({ header: s.title, type: "Expression" }), O = s.title);
});
}), /* @__PURE__ */ k.jsx(
"div",
{
style: {
maxHeight: C.maxDropDownHeight ?? 310
},
children: /* @__PURE__ */ k.jsx(
"div",
{
className: "optionStaticList",
style: {
minHeight: C.minStaticListHeight,
maxHeight: C.maxStaticListHeight ?? 300
},
children: h.map(
(s) => "header" in s ? "items" in s ? /* @__PURE__ */ k.jsxs(
"div",
{
className: "optionStaticHeaderMenu",
onMouseEnter: () => _(s.header),
onMouseLeave: () => _(null),
children: [
s.header,
/* @__PURE__ */ k.jsx(Lt, {}),
/* @__PURE__ */ k.jsx("div", { children: K === s.header && /* @__PURE__ */ k.jsx("div", { className: "subItemsList", children: s.items.map((O) => /* @__PURE__ */ k.jsx("div", { children: O.text }, s.header + "-" + O.text)) }) })
]
},
s.header
) : "type" in s ? /* @__PURE__ */ k.jsxs("div", { className: "optionStaticHeader", children: [
s.header,
" - ",
s.type
] }, s.header) : /* @__PURE__ */ k.jsx("div", { className: "optionStaticHeader", children: s.header }, s.header) : /* @__PURE__ */ k.jsx(
"div",
{
className: "optionStaticItem",
onClick: () => {
s.type === "comparison" ? y(typeof s.value == "string" ? s.value : s.value.toString()) : s.type === "operator" ? f(typeof s.value == "string" ? s.value : s.value.toString()) : p({ text: s.text, value: s.value, source: s.type });
},
children: s.text
},
s.text + "-" + s.type
)
)
}
)
}
);
}, L = {
...d == null ? void 0 : d.optionsList,
...C.maxDropDownHeight ? { maxHeight: C.maxDropDownHeight } : {}
};
return /* @__PURE__ */ k.jsx("div", { id: "option_list", className: "optionListMain", style: L, children: t.length > 0 ? N() : J(m) });
};
function Et(t) {
return Ge({ tag: "svg", attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" } }, { tag: "path", attr: { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" } }] })(t);
}
const Ut = ({
errorMessage: t,
onErrorAcknowledged: n,
style: r
}) => /* @__PURE__ */ k.jsxs("div", { id: "editError", className: "errorMessageMain", style: r, children: [
/* @__PURE__ */ k.jsx(Et, { className: "errorMessageIcon", onClick: n }),
t
] }), Ct = "Functions", St = (t, n, r) => n.length > (t.itemLimit ?? r) ? n.slice(0, t.itemLimit ?? r) : n, Wt = (t, n, r) => {
if (n.precedence) {
const i = n.precedence;
return t.findIndex((f) => {
if (f[0] === Ct)
return !1;
const y = r.find((p) => p.title === f[0]);
return i > ((y == null ? void 0 : y.precedence) ?? 0);
});
}
return -1;
}, Yt = (t, n, r) => t.map((i) => ({
source: n,
value: ht(i, r),
text: gt(i, r)
})), st = (t, n, r, i, f, y) => {
let p = Yt(t, n.name, r);
return p.length > 0 && (p = St(r, p, f), Gt(i, n, r, p, f, y)), p.length;
}, Bt = (t, n, r, i) => St(
t,
n.concat(r).filter(
(f, y, p) => p.findIndex((d) => d.value === f.value) === y
),
i
), Gt = (t, n, r, i, f, y) => {
const p = t.find((d) => d[0] === n.title);
if (p) {
p[1] = Bt(
r,
p[1],
i,
f
);
return;
}
wt(t, n, i, y);
}, wt = (t, n, r, i) => {
const f = Wt(t, n, i);
f !== -1 ? t.splice(f, 0, [n.title, r]) : t.push([n.title, r]);
}, Kt = (t, n, r) => {
const i = n.textGetter && typeof t == "object" ? n.textGetter(t) : t.toString();
return n.ignoreCase ? i.toUpperCase().includes(r.toUpperCase()) : i.includes(r);
}, zt = (t, n) => t === 0 ? 0 : n.slice(0, t).map((r) => r[1].length).reduce((r, i) => r + i), lt = (t, n, r = !0) => {
let i = 0;
const f = n.findIndex((y) => {
const [, p] = y, d = t >= i && t < i + p.length;
return i += p.length, d;
});
return zt(
r ? f < n.length - 1 ? f + 1 : 0 : f > 0 ? f - 1 : n.length - 1,
n
);
};
const Je = w.forwardRef(
(t, n) => {
const {
matcher: r,
onMatcherChanged: i,
onValidate: f,
onFocus: y,
onCancel: p,
onEditPrevious: d,
onEditNext: m,
onInsertMatcher: _,
first: R,
allowFunctions: C,
allowFreeText: B,
styles: N,
onChanging: J,
onSetActiveFunction: L,
onDeleteActiveFunction: K
} = t, h = w.useContext(qe), s = w.useRef(null), [O, U] = w.useState(
r ? `${!R && h.operators !== "Simple" ? r.operator + " " : ""}${r.comparison}${r.text}` : ""
), [P, te] = w.useState(
(r == null ? void 0 : r.comparison) ?? null
), [oe, X] = w.useState(
(r == null ? void 0 : r.operator) ?? null
), [re, ue] = w.useState(null), ae = w.useRef(""), [Q, b] = w.useState([]), [D, g] = w.useState(0), [E, V] = w.useState(null), [ie, se] = w.useState(null), [Oe, I] = w.useState(!1), ne = w.useContext(mt), z = w.useContext(yt), _e = (o = null, u = null, v = null) => {
let T = "";
o === "(" || o === ")" ? W(o) : ((o || oe) && (T = `${o ?? oe} `), (u || P) && (T = `${T}${u ?? P} `), v ? W(v) : (T = `${T}${re ?? ""}`, je(T)));
};
w.useEffect(() => {
s.current && ne && s.current.focus();
}, [ne]), w.useEffect(() => {
se(null);
}, [R]), w.useEffect(() => {
O.length === 0 && V(null);
}, [O]);
const ce = () => {
U(""), X(null), te(null), ue(null), b([]), g(0), V(null);
}, Ee = (o, u) => {
if (o.length > 2 && o.substring(0, 3) === "and")
return X("and"), u.op = "and", o.substring(3).trim();
if (o.length > 1 && o.substring(0, 2) === "or")
return X("or"), u.op = "or", o.substring(2).trim();
const v = o[0];
return v === h.and || v === h.or ? (X(v), u.op = v === h.and ? "and" : "or", o.substring(1).trim()) : o;
}, Re = (o) => {
if (o.length > 1) {
const v = o.substring(0, 2);
if (h.comparisons.includes(v))
return te(v), o.substring(2).trim();
}
const u = o[0];
if (h.operators === "Complex" && (!z.activeFunction || !z.activeFunction.noBrackets) && (u === "(" || u === ")")) {
if (r && _ && r.operator !== u) {
const v = {
key: he(),
operator: u,
comparison: u,
source: "",
value: "",
text: ""
};
_(v);
} else
W(u);
return null;
}
return h.comparisons.includes(u) ? (te(u), o.substring(1).trim()) : o;
}, ge = (o, u, v) => {
if (o.length > 0) {
let T = o.trim();
if (T.length > 0 && T[0] !== '"' && (h.operators !== "Simple" && (!z.activeFunction || !z.activeFunction.noAndOr) && (T = Ee(T, v)), T = Re(T), ue(T), T !== null && T.length > 0)) {
const Y = T;
Y.length >= (h.searchStartLength ?? 0) && (C && h.functions && Te(
Y,
h.functions,
v
), h.dataSources.forEach((Z) => {
var pe, We;
(!z.activeFunction && !Z.functional || z.activeFunction && ((pe = z.activeFunction.requiredDataSources) != null && pe.includes(
Z.name
) || (We = z.activeFunction.optionalDataSources) != null && We.includes(
Z.name
))) && Z.definitions.forEach((de) => {
"source" in de ? Ce(
Y,
Z,
de,
u,
v
) : fe(
Y,
Z,
de,
u,
v
);
});
}));
}
}
}, Te = (o, u, v) => {
const T = u.filter(
(Y) => Y.name.toUpperCase().includes(o.toUpperCase())
).map((Y) => ({
source: at,
text: Y.name,
value: Y.name
}));
T.length > 0 && (v.allOptions.push([Ct, T]), v.totalCount += T.length);
}, Ce = (o, u, v, T, Y) => {
if (o.length >= (v.searchStartLength ?? 0)) {
if (typeof v.source == "function") {
const Z = v.source;
setTimeout(() => {
T === ae.current && Z(o, Y.op, z.matchers).then((pe) => {
T === ae.current && (Y.totalCount += st(
pe,
u,
v,
Y.allOptions,
h.defaultItemLimit,
h.dataSources
), Me(Y));
});
}, h.promiseDelay ?? 1);
} else if (T === ae.current) {
const Z = v.source.filter(
(pe) => Kt(pe, v, o)
);
Z.length > 0 && (Y.totalCount += st(
Z,
u,
v,
Y.allOptions,
h.defaultItemLimit,
h.dataSources
));
}
}
}, fe = (o, u, v, T, Y) => {
if ((v.match instanceof RegExp && o.match(v.match) || typeof v.match == "function" && v.match(o)) && T === ae.current) {
const Z = v.value(o);
wt(
Y.allOptions,
u,
[{ source: u.name, value: Z, text: Z.toString() }],
h.dataSources
), Y.totalCount += 1;
}
}, je = (o) => {
X(null), te(null), ue(null), !Oe && r && (I(!0), J && J());
const u = he();
ae.current = u;
const v = {
allOptions: [],
totalCount: 0,
op: null
};
ge(o, u, v), U(o), Me(v);
}, Me = (o) => {
const { allOptions: u, totalCount: v } = o;
b(u), g(v), v > 0 && (E === null ? V(0) : E >= v && V(v - 1));
}, Fe = (o) => d && !o.shiftKey && !o.ctrlKey ? (R && K ? K() : d(!0), !0) : p ? (W(), !0) : !1, ve = () => (p && p(), !0), me = () => (W(), !0), Pe = (o) => {
var v;
const u = Q.flatMap((T) => T[1]);
if (E !== null && u.length > E) {
if (u[E].source === at) {
const T = (v = h.functions) == null ? void 0 : v.find(
(Y) => Y.name === u[E].text
);
T && L && (L(T), ce());
} else
o.shiftKey ? M(u[E]) : W(u[E]);
return !0;
}
return !1;
}, Ie = () => {
if (B) {
const o = {
key: he(),
operator: "",
comparison: '"',
source: "Free Text",
value: O.substring(1),
text: O.substring(1)
};
return i(o), ce(), !0;
}
return !1;
}, Se = () => D > 0 ? (V(D - 1), !0) : !1, De = () => D > 0 ? (V(0), !0) : !1, Le = () => D > 0 ? (V(
lt(E ?? D - 1, Q)
), !0) : !1, we = () => D > 0 ? (V(lt(E ?? 0, Q, !1)), !0) : !1, Ve = () => (E === null ? V(0) : E < D - 1 ? V(E + 1) : V(0), !0), Ue = () => (E === null ? V(D - 1) : E > 0 ? V(E - 1) : V(D - 1), !0), Ae = (o) => s.current && !o.ctrlKey && !o.shiftKey && o.currentTarget.selectionStart === o.currentTarget.value.length && m ? (m(), !0) : !1, $e = (o) => s.current && !o.ctrlKey && !o.shiftKey && o.currentTarget.selectionStart === 0 ? (d(!1), !0) : !1, ye = (o) => {
let u = !1;
switch (se(null), o.code) {
case "ArrowLeft":
u = $e(o);
break;
case "ArrowRight":
u = Ae(o);
break;
case "ArrowUp":
u = Ue();
break;
case "ArrowDown":
u = Ve();
break;
case "PageUp":
u = we();
break;
case "PageDown":
u = Le();
break;
case "Home":
u = De();
break;
case "End":
u = Se();
break;
case "Enter":
case "Tab":
O.length > 0 && O[0] === '"' ? u = Ie() : Q.length > 0 && E !== null ? u = Pe(o) : O.length === 0 && r ? u = me() : r && p && (u = ve());
break;
case "Backspace":
O.length === 0 && (u = Fe(o));
break;
}
u && (o.preventDefault(), o.stopPropagation());
}, l = (o) => {
const u = h.dataSources.find((v) => v.name === o.source);
if (u && P !== null && !u.comparisons.includes(P)) {
const v = O.indexOf(P);
return v !== -1 && s.current && (s.current.selectionStart = v, s.current.selectionEnd = v + 1), `Compairson (${P}) isn't valid for ${u.name}.`;
}
return null;
}, S = (o) => {
if (o !== "(" && o !== ")" && o) {
const v = l(o);
if (v)
return se(v), !1;
}
const u = o ? {
key: (r == null ? void 0 : r.key) ?? he(),
operator: o === ")" ? "" : oe ?? "and",
comparison: o === "(" || o === ")" ? o : P ?? h.defaultComparison,
source: typeof o == "object" ? o.source : "",
value: typeof o == "object" ? o.value : "",
text: typeof o == "object" ? o.text : ""
} : null;
if (u && f) {
const v = f(u);
if (v)
return se(v), !1;
}
return u;
}, M = (o) => {
const u = S(o);
u !== !1 && u !== null && _ && _(u);
}, W = (o) => {
const u = S(o);
u !== !1 && (i(u), ce());
}, q = () => {
y && y();
};
return /* @__PURE__ */ k.jsxs("div", { className: "matcherEditMain", style: N == null ? void 0 : N.matcherEdit, children: [
ie && /* @__PURE__ */ k.jsx(
Ut,
{
errorMessage: ie,
onErrorAcknowledged: () => se(null),
style: N == null ? void 0 : N.errorMessage
}
),
/* @__PURE__ */ k.jsx(
"input",
{
id: ((r == null ? void 0 : r.key) ?? "edit") + "_input",
style: N == null ? void 0 : N.input,
ref: (o) => {
s.current = o, typeof n == "function" ? n(o) : n && (n.current = o);
},
value: O,
onChange: (o) => je(o.target.value),
onFocus: q,
onKeyDown: ye,
autoCapitalize: "none",
autoComplete: "off",
autoCorrect: "off",
spellCheck: "false",
type: "text",
placeholder: "..."
}
),
ne && (!r || Q.length > 0) && /* @__PURE__ */ k.jsx(
Vt,
{
options: Q,
activeOption: E,
onSelectActiveOption: V,
onSelectOption: W,
styles: N,
onSelectComparison: (o) => _e(null, o),
onSelectOperator: (o) => _e(o),
onSelectText: (o) => _e(null, null, o)
}
)
] });
}
);
Je.displayName = "MatcherEdit";
function Ht(t) {
return Ge({ tag: "svg", attr: { version: "1.2", baseProfile: "tiny", viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { d: "M18 11h-12c-1.104 0-2 .896-2 2s.896 2 2 2h12c1.104 0 2-.896 2-2s-.896-2-2-2z" } }] })(t);
}
const qt = (t, n, r, i) => `${n || r || t.operator === "" || t.comparison === ")" ? "" : (t.operator === "&" || t.operator === "and" ? "and" : "or") + " "}${i === "left" ? t.source + " " : ""}${t.comparison !== '"' ? t.comparison + " " : ""}${t.text}`, Jt = (t) => `${t.source}: ${t.text}${t.value !== t.text ? "(" + t.value + ")" : ""}`, ct = "multi-select/matcher/", ut = ({
matcher: t,
onMatcherChanged: n,
onValidate: r,
onDelete: i,
onSelect: f,
onCancel: y,
onSwapMatcher: p,
onEditPrevious: d,
onEditNext: m,
onChanging: _,
onInsertMatcher: R,
selected: C,
first: B,
hideOperators: N,
showWarning: J,
showCategory: L,
categoryPosition: K,
hideToolTip: h,
allowFreeText: s,
styles: O
}) => {
var g;
const U = w.useRef(null), [P, te] = w.useState(!1), [oe, X] = w.useState(!1);
w.useEffect(() => {
C && P && te(!1);
}, [C, P]), w.useEffect(() => {
C && oe && X(!1);
}, [C, oe]);
const re = (E) => {
E ? i() : d && d();
}, ue = (E) => {
i(), E.stopPropagation();
}, ae = (E) => {
E ? n && n(E) : i();
}, Q = (E) => {
"key" in t && (E.dataTransfer.setData(
`${ct}${t.key}`,
JSON.stringify(t)
), E.dataTransfer.effectAllowed = "move");
}, b = (E) => {
"key" in t && (E.dataTransfer.types.find((V) => V.includes(t.key)) || (E.dataTransfer.dropEffect = "move", E.preventDefault()));
}, D = (E) => {
if ("key" in t) {
const V = E.dataTransfer.types.find(
(ie) => ie.includes(ct)
);
if (V) {
const ie = E.dataTransfer.getData(V);
if (ie && p) {
const se = JSON.parse(ie);
p(t, se);
}
}
}
};
return /* @__PURE__ */ k.jsxs(
"div",
{
id: "key" in t ? t.key + "_view" : "function_view",
className: "matcherViewMain",
style: {
...C ? O == null ? void 0 : O.matcherViewSelected : O == null ? void 0 : O.matcherView,
flexGrow: C ? 1 : 0
},
onClick: f,
draggable: !0,
onDragStart: Q,
onDragOver: b,
onDrop: D,
onMouseEnter: () => X(!0),
onMouseLeave: () => X(!1),
children: [
oe && !C && /* @__PURE__ */ k.jsx(Ht, { className: "deleteIcon", onClick: ue }),
C && "key" in t ? /* @__PURE__ */ k.jsx(
Je,
{
matcher: t,
onMatcherChanged: ae,
onValidate: r,
onCancel: y,
first: B ?? !1,
styles: O,
onEditNext: m,
onEditPrevious: re,
onChanging: _,
onInsertMatcher: R,
allowFreeText: s
}
) : /* @__PURE__ */ k.jsxs(k.Fragment, { children: [
!h && P && "key" in t && /* @__PURE__ */ k.jsx(
"div",
{
id: t.key + "_tool_tip",
className: "matcherViewToolTip",
style: {
top: (((g = U.current) == null ? void 0 : g.clientHeight) ?? 10) * -1 - 4,
...O == null ? void 0 : O.matcherToolTip
},
children: Jt(t)
}
),
/* @__PURE__ */ k.jsxs(
"div",
{
onMouseEnter: () => te(!0),
onMouseLeave: () => te(!1),
className: "matcherViewContainer",
style: "key" in t && t.source !== "" ? {} : {
alignSelf: "end"
},
children: [
L && "key" in t && K !== "left" && /* @__PURE__ */ k.jsx("div", { className: "matchViewCategory", children: t.source }),
/* @__PURE__ */ k.jsx(
"div",
{
ref: U,
id: "key" in t ? t.key + "_label" : "function_label",
className: J ? "matcherViewWarning" : "",
children: "key" in t ? qt(
t,
B ?? !1,
N ?? !1,
K
) : t.name
}
)
]
}
)
] })
]
}
);
}, ft = (t, n, r) => {
const i = r ? "(" : ")", f = r ? ")" : "(", y = [];
for (let p = r ? t.length - 1 : 0; !r && p < t.length || r && p >= 0; r ? p-- : p++)
if (t[p] === i) {
let d = !1;
for (let m = r ? p + 1 : p - 1; r && m < t.length || !r && m >= 0; r ? m++ : m--)
if (t[m] === f && !y.includes(m)) {
y.push(m), d = !0;
break;
}
d || n.push(p);
}
}, pt = (t, n, r, i, f, y) => {
if (r.comparison === "(" || r.comparison === ")")
return null;
if (f === "AgGrid" && (r.operator === "or" || r.operator === y)) {
const d = i ? i > 0 ? t[i - 1] : null : t.length > 0 ? t[t.length - 1] : null;
if (d && d.source !== r.source)
return "When using AgGrid style operators, or can only be used for the same field";
}
const p = n.find((d) => d.name === r.source);
return p != null && p.selectionLimit && t.filter(
(m) => r.key !== m.key && r.source === m.source
).length >= p.selectionLimit ? `Datasource (${p.name}) is limited to ${p.selectionLimit} items.` : null;
}, Xt = (t, n, r, i, f = "Individual", y = 500) => new Promise((p) => {
const d = (r == null ? void 0 : r.pasteFreeTextAction) ?? f, m = t.includes('"') ? rr(t) : t.split(" "), _ = m, R = [];
let C = "and", B = "=";
m.forEach((L, K) => {
const h = L.trim();
h === i.and || h === "and" ? C = "and" : h === i.or || h === "or" ? C = "or" : i.comparisons.includes(h) ? B = h : h !== "" && n.forEach((s) => {
var O, U;
(r && ((O = r.optionalDataSources) != null && O.includes(s.name) || (U = r.requiredDataSources) != null && U.includes(s.name)) || !r && !s.functional) && s.definitions.forEach((P) => {
"source" in P ? (!P.searchStartLength || h.length >= P.searchStartLength) && (typeof P.source == "function" ? typeof P.matchOnPaste == "function" && er(
s,
P,
P.matchOnPaste,
h,
K,
R,
_,
C,
B
) : Qt(
s,
P,
P.source,
h,
K,
_,
C,
B
)) : Zt(s, P, h, K, _, C, B);
});
});
});
const N = () => {
p(
d === "Original" ? [
{
key: he(),
operator: "",
comparison: "",
source: "Free Text",
value: t,
text: t
},
..._.filter((L) => typeof L != "string")
] : d === "Combined" ? [
tr(_, i),
..._.filter((L) => typeof L != "string")
] : _.filter((L) => typeof L != "string" || kt(L, i)).map((L) => typeof L == "string" ? {
key: he(),
operator: "",
comparison: "",
source: "Free Text",
value: L,
text: L
} : L)
);
};
let J = "running";
Promise.all(R).then(() => {
J !== "cancel" && (J = "done", N());
}), setTimeout(() => {
J !== "done" && (J = "cancel", N());
}, y);
}), Zt = (t, n, r, i, f, y, p) => {
if (n.matchOnPaste && (n.match instanceof RegExp && r.match(n.match) || typeof n.match == "function" && n.match(r))) {
const d = n.value(r);
d && (f[i] = f[i] = {
key: he(),
operator: y,
comparison: p,
source: t.name,
value: d,
text: typeof d == "string" ? d : d.toString()
});
}
}, Qt = (t, n, r, i, f, y, p, d) => {
if (n.matchOnPaste) {
const m = r.find((_) => {
const R = n.textGetter && typeof _ == "object" ? n.textGetter(_) : _.toString();
return n.ignoreCase ? R.toUpperCase() === i.toUpperCase() : R === i;
});
if (m) {
const _ = Ot(m, n, t);
_ && (y[f] = {
key: he(),
operator: p,
comparison: d,
..._
});
}
}
}, er = (t, n, r, i, f, y, p, d, m) => {
y.push(
r(i).then((_) => {
if (_) {
const R = Ot(_, n, t);
R && (p[f] = {
key: he(),
operator: d,
comparison: m,
...R
});
}
return !0;
})
);
}, kt = (t, n) => t !== "and" && t !== "or" && t !== n.and && t !== n.or && !n.comparisons.includes(t), tr = (t, n) => {
const r = t.filter((i) => typeof i == "string" && kt(i, n)).join(" ");
r