simple-search-dropdown
Advanced tools
Comparing version 0.1.3 to 0.1.4
import { jsxs as ne, jsx as B } from "react/jsx-runtime"; | ||
import * as l from "react"; | ||
import ae, { useState as L, useRef as H, useEffect as z } from "react"; | ||
import ae, { useState as x, useRef as H, useEffect as z } from "react"; | ||
var E = function() { | ||
@@ -31,3 +31,3 @@ return E = Object.assign || function(t) { | ||
function le(e, t) { | ||
var n = L(function() { | ||
var n = x(function() { | ||
return { | ||
@@ -112,7 +112,7 @@ // value | ||
} | ||
var g = function() { | ||
var m = function() { | ||
var d = u; | ||
u = [], d.forEach(c); | ||
}, b = function() { | ||
return Promise.resolve().then(g); | ||
return Promise.resolve().then(m); | ||
}; | ||
@@ -155,8 +155,8 @@ b(), n = { | ||
onTouchMoveCapture: V | ||
}), a = r[0], c = r[1], u = e.forwardProps, o = e.children, g = e.className, b = e.removeScrollBar, d = e.enabled, y = e.shards, S = e.sideCar, h = e.noIsolation, w = e.inert, i = e.allowPinchZoom, s = e.as, f = s === void 0 ? "div" : s, v = e.gapMode, p = U(e, ["forwardProps", "children", "className", "removeScrollBar", "enabled", "shards", "sideCar", "noIsolation", "inert", "allowPinchZoom", "as", "gapMode"]), C = S, m = se([n, t]), R = E(E({}, p), a); | ||
}), a = r[0], c = r[1], u = e.forwardProps, o = e.children, m = e.className, b = e.removeScrollBar, d = e.enabled, y = e.shards, S = e.sideCar, g = e.noIsolation, C = e.inert, i = e.allowPinchZoom, s = e.as, f = s === void 0 ? "div" : s, v = e.gapMode, p = U(e, ["forwardProps", "children", "className", "removeScrollBar", "enabled", "shards", "sideCar", "noIsolation", "inert", "allowPinchZoom", "as", "gapMode"]), w = S, h = se([n, t]), R = E(E({}, p), a); | ||
return l.createElement( | ||
l.Fragment, | ||
null, | ||
d && l.createElement(C, { sideCar: q, removeScrollBar: b, shards: y, noIsolation: h, inert: w, setCallbacks: c, allowPinchZoom: !!i, lockRef: n, gapMode: v }), | ||
u ? l.cloneElement(l.Children.only(o), E(E({}, R), { ref: m })) : l.createElement(f, E({}, R, { className: g, ref: m }), o) | ||
d && l.createElement(w, { sideCar: q, removeScrollBar: b, shards: y, noIsolation: g, inert: C, setCallbacks: c, allowPinchZoom: !!i, lockRef: n, gapMode: v }), | ||
u ? l.cloneElement(l.Children.only(o), E(E({}, R), { ref: h })) : l.createElement(f, E({}, R, { className: m, ref: h }), o) | ||
); | ||
@@ -237,3 +237,3 @@ }); | ||
}; | ||
}, Re = J(), x = "data-scroll-locked", ke = function(e, t, n, r) { | ||
}, Re = J(), N = "data-scroll-locked", ke = function(e, t, n, r) { | ||
var a = e.left, c = e.top, u = e.right, o = e.gap; | ||
@@ -245,3 +245,3 @@ return n === void 0 && (n = "margin"), ` | ||
} | ||
body[`).concat(x, `] { | ||
body[`).concat(N, `] { | ||
overflow: hidden `).concat(r, `; | ||
@@ -279,3 +279,3 @@ overscroll-behavior: contain; | ||
body[`).concat(x, `] { | ||
body[`).concat(N, `] { | ||
`).concat(ie, ": ").concat(o, `px; | ||
@@ -285,9 +285,9 @@ } | ||
}, _ = function() { | ||
var e = parseInt(document.body.getAttribute(x) || "0", 10); | ||
var e = parseInt(document.body.getAttribute(N) || "0", 10); | ||
return isFinite(e) ? e : 0; | ||
}, Pe = function() { | ||
l.useEffect(function() { | ||
return document.body.setAttribute(x, (_() + 1).toString()), function() { | ||
return document.body.setAttribute(N, (_() + 1).toString()), function() { | ||
var e = _() - 1; | ||
e <= 0 ? document.body.removeAttribute(x) : document.body.setAttribute(x, e.toString()); | ||
e <= 0 ? document.body.removeAttribute(N) : document.body.setAttribute(N, e.toString()); | ||
}; | ||
@@ -314,3 +314,3 @@ }, []); | ||
} | ||
var k = Y ? { passive: !1 } : !1, xe = function(e) { | ||
var P = Y ? { passive: !1 } : !1, xe = function(e) { | ||
return e.tagName === "TEXTAREA"; | ||
@@ -364,10 +364,10 @@ }, K = function(e, t) { | ||
}, Ie = function(e, t, n, r, a) { | ||
var c = Oe(e, window.getComputedStyle(t).direction), u = c * r, o = n.target, g = t.contains(o), b = !1, d = u > 0, y = 0, S = 0; | ||
var c = Oe(e, window.getComputedStyle(t).direction), u = c * r, o = n.target, m = t.contains(o), b = !1, d = u > 0, y = 0, S = 0; | ||
do { | ||
var h = te(e, o), w = h[0], i = h[1], s = h[2], f = i - s - c * w; | ||
(w || f) && ee(e, o) && (y += f, S += w), o instanceof ShadowRoot ? o = o.host : o = o.parentNode; | ||
var g = te(e, o), C = g[0], i = g[1], s = g[2], f = i - s - c * C; | ||
(C || f) && ee(e, o) && (y += f, S += C), o instanceof ShadowRoot ? o = o.host : o = o.parentNode; | ||
} while ( | ||
// portaled content | ||
!g && o !== document.body || // self content | ||
g && (t.contains(o) || t === o) | ||
!m && o !== document.body || // self content | ||
m && (t.contains(o) || t === o) | ||
); | ||
@@ -388,3 +388,3 @@ return (d && (Math.abs(y) < 1 || !a) || !d && (Math.abs(S) < 1 || !a)) && (b = !0), b; | ||
`); | ||
}, je = 0, P = []; | ||
}, je = 0, L = []; | ||
function Ve(e) { | ||
@@ -410,19 +410,19 @@ var t = l.useRef([]), n = l.useRef([0, 0]), r = l.useRef(), a = l.useState(je++)[0], c = l.useState(J)[0], u = l.useRef(e); | ||
return !u.current.allowPinchZoom; | ||
var f = O(i), v = n.current, p = "deltaX" in i ? i.deltaX : v[0] - f[0], C = "deltaY" in i ? i.deltaY : v[1] - f[1], m, R = i.target, N = Math.abs(p) > Math.abs(C) ? "h" : "v"; | ||
if ("touches" in i && N === "h" && R.type === "range") | ||
var f = O(i), v = n.current, p = "deltaX" in i ? i.deltaX : v[0] - f[0], w = "deltaY" in i ? i.deltaY : v[1] - f[1], h, R = i.target, k = Math.abs(p) > Math.abs(w) ? "h" : "v"; | ||
if ("touches" in i && k === "h" && R.type === "range") | ||
return !1; | ||
var M = Z(N, R); | ||
var M = Z(k, R); | ||
if (!M) | ||
return !0; | ||
if (M ? m = N : (m = N === "v" ? "h" : "v", M = Z(N, R)), !M) | ||
if (M ? h = k : (h = k === "v" ? "h" : "v", M = Z(k, R)), !M) | ||
return !1; | ||
if (!r.current && "changedTouches" in i && (p || C) && (r.current = m), !m) | ||
if (!r.current && "changedTouches" in i && (p || w) && (r.current = h), !h) | ||
return !0; | ||
var D = r.current || m; | ||
return Ie(D, s, i, D === "h" ? p : C, !0); | ||
}, []), g = l.useCallback(function(i) { | ||
var D = r.current || h; | ||
return Ie(D, s, i, D === "h" ? p : w, !0); | ||
}, []), m = l.useCallback(function(i) { | ||
var s = i; | ||
if (!(!P.length || P[P.length - 1] !== c)) { | ||
var f = "deltaY" in s ? Q(s) : O(s), v = t.current.filter(function(m) { | ||
return m.name === s.type && (m.target === s.target || s.target === m.shadowParent) && Ae(m.delta, f); | ||
if (!(!L.length || L[L.length - 1] !== c)) { | ||
var f = "deltaY" in s ? Q(s) : O(s), v = t.current.filter(function(h) { | ||
return h.name === s.type && (h.target === s.target || s.target === h.shadowParent) && Ae(h.delta, f); | ||
})[0]; | ||
@@ -434,6 +434,6 @@ if (v && v.should) { | ||
if (!v) { | ||
var p = (u.current.shards || []).map(G).filter(Boolean).filter(function(m) { | ||
return m.contains(s.target); | ||
}), C = p.length > 0 ? o(s, p[0]) : !u.current.noIsolation; | ||
C && s.cancelable && s.preventDefault(); | ||
var p = (u.current.shards || []).map(G).filter(Boolean).filter(function(h) { | ||
return h.contains(s.target); | ||
}), w = p.length > 0 ? o(s, p[0]) : !u.current.noIsolation; | ||
w && s.cancelable && s.preventDefault(); | ||
} | ||
@@ -444,4 +444,4 @@ } | ||
t.current.push(p), setTimeout(function() { | ||
t.current = t.current.filter(function(C) { | ||
return C !== p; | ||
t.current = t.current.filter(function(w) { | ||
return w !== p; | ||
}); | ||
@@ -457,18 +457,18 @@ }, 1); | ||
l.useEffect(function() { | ||
return P.push(c), e.setCallbacks({ | ||
return L.push(c), e.setCallbacks({ | ||
onScrollCapture: y, | ||
onWheelCapture: y, | ||
onTouchMoveCapture: S | ||
}), document.addEventListener("wheel", g, k), document.addEventListener("touchmove", g, k), document.addEventListener("touchstart", d, k), function() { | ||
P = P.filter(function(i) { | ||
}), document.addEventListener("wheel", m, P), document.addEventListener("touchmove", m, P), document.addEventListener("touchstart", d, P), function() { | ||
L = L.filter(function(i) { | ||
return i !== c; | ||
}), document.removeEventListener("wheel", g, k), document.removeEventListener("touchmove", g, k), document.removeEventListener("touchstart", d, k); | ||
}), document.removeEventListener("wheel", m, P), document.removeEventListener("touchmove", m, P), document.removeEventListener("touchstart", d, P); | ||
}; | ||
}, []); | ||
var h = e.removeScrollBar, w = e.inert; | ||
var g = e.removeScrollBar, C = e.inert; | ||
return l.createElement( | ||
l.Fragment, | ||
null, | ||
w ? l.createElement(c, { styles: We(a) }) : null, | ||
h ? l.createElement(Le, { gapMode: e.gapMode }) : null | ||
C ? l.createElement(c, { styles: We(a) }) : null, | ||
g ? l.createElement(Le, { gapMode: e.gapMode }) : null | ||
); | ||
@@ -487,3 +487,3 @@ } | ||
const ze = ae.forwardRef((e, t) => { | ||
const [n, r] = L(!1), [a, c] = L(!1), [u, o] = L({ label: "", value: "" }), [g, b] = L(""), [d, y] = L(), { data: S, ...h } = e, w = H(null), i = H(null); | ||
const [n, r] = x(!1), [a, c] = x(!1), [u, o] = x({ label: "", value: "" }), [m, b] = x(""), [d, y] = x(), { data: S, ...g } = e, C = H(null), i = H(null); | ||
z(() => { | ||
@@ -494,4 +494,4 @@ if (a) { | ||
} | ||
if (d != null && d.length && g && y(void 0), S && typeof S == "function") { | ||
const f = S(g); | ||
if (d != null && d.length && m && y(void 0), S && typeof S == "function") { | ||
const f = S(m); | ||
if (f instanceof Promise) { | ||
@@ -508,3 +508,3 @@ f.then((v) => { | ||
const v = f.target; | ||
w.current && !w.current.contains(v) && i.current && !i.current.contains(v) && r(!1); | ||
C.current && !C.current.contains(v) && i.current && !i.current.contains(v) && r(!1); | ||
}; | ||
@@ -517,3 +517,3 @@ return z(() => (document.addEventListener("mousedown", s), () => { | ||
{ | ||
ref: w, | ||
ref: C, | ||
onFocus: () => r(!0), | ||
@@ -524,8 +524,11 @@ className: "p-2 bg-gray-200 cursor-pointer focus:cursor-text", | ||
onChange: (f) => { | ||
var p; | ||
const v = ((p = d == null ? void 0 : d.find((C) => C.value.toLowerCase() === f.target.value.toLowerCase())) == null ? void 0 : p.value) ?? u.value; | ||
b(f.target.value.toLowerCase()), o({ label: f.target.value, value: v }), c(!0), h.onChange && h.onChange(f); | ||
var p, w; | ||
const v = ((p = d == null ? void 0 : d.find((h) => { | ||
var R, k; | ||
return ((R = h.value) == null ? void 0 : R.toLowerCase()) === ((k = f.target.value) == null ? void 0 : k.toLowerCase()); | ||
})) == null ? void 0 : p.value) ?? u.value; | ||
b((w = f.target.value) == null ? void 0 : w.toLowerCase()), o({ label: f.target.value ?? "", value: v }), c(!0), g.onChange && g.onChange(f); | ||
}, | ||
placeholder: h.placeholder, | ||
disabled: h.disabled | ||
placeholder: g.placeholder, | ||
disabled: g.disabled | ||
} | ||
@@ -536,6 +539,6 @@ ), | ||
{ | ||
id: h.name, | ||
name: h.name, | ||
onChange: h.onChange, | ||
onBlur: h.onBlur, | ||
id: g.name, | ||
name: g.name, | ||
onChange: g.onChange, | ||
onBlur: g.onBlur, | ||
ref: t, | ||
@@ -548,3 +551,3 @@ disabled: !0, | ||
), | ||
n && d && d.length > 0 && /* @__PURE__ */ B(re, { children: /* @__PURE__ */ B("div", { ref: i, className: "absolute z-10 w-full bg-white border border-gray-300 rounded mt-1", children: d.filter((f) => f.label.toLowerCase().indexOf(g ?? "") > -1).map((f, v) => /* @__PURE__ */ B("div", { className: "p-2 cursor-pointer hover:bg-gray-100", onClick: () => { | ||
n && d && d.length > 0 && /* @__PURE__ */ B(re, { children: /* @__PURE__ */ B("div", { ref: i, className: "absolute z-10 w-full bg-white border border-gray-300 rounded mt-1", children: d.filter((f) => f.label.toLowerCase().indexOf(m ?? "") > -1).map((f, v) => /* @__PURE__ */ B("div", { className: "p-2 cursor-pointer hover:bg-gray-100", onClick: () => { | ||
o(f), r(!1); | ||
@@ -551,0 +554,0 @@ }, children: f.label }, v)) }) }) |
@@ -1,2 +0,2 @@ | ||
(function(x,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],k):(x=typeof globalThis<"u"?globalThis:x||self,k(x["simple-search-dropdown"]={},x["react/jsx-runtime"],x.React))})(this,function(x,k,y){"use strict";function re(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const l=re(y);var P=function(){return P=Object.assign||function(t){for(var n,r=1,a=arguments.length;r<a;r++){n=arguments[r];for(var c in n)Object.prototype.hasOwnProperty.call(n,c)&&(t[c]=n[c])}return t},P.apply(this,arguments)};function z(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(n[r[a]]=e[r[a]]);return n}function ne(e,t,n){if(n||arguments.length===2)for(var r=0,a=t.length,c;r<a;r++)(c||!(r in t))&&(c||(c=Array.prototype.slice.call(t,0,r)),c[r]=t[r]);return e.concat(c||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var M="right-scroll-bar-position",B="width-before-scroll-bar",ae="with-scroll-bars-hidden",oe="--removed-body-scroll-bar-size";function D(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function ce(e,t){var n=y.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=t,n.facade}var ie=typeof window<"u"?l.useLayoutEffect:l.useEffect,H=new WeakMap;function le(e,t){var n=ce(null,function(r){return e.forEach(function(a){return D(a,r)})});return ie(function(){var r=H.get(n);if(r){var a=new Set(r),c=new Set(e),u=n.current;a.forEach(function(o){c.has(o)||D(o,null)}),c.forEach(function(o){a.has(o)||D(o,u)})}H.set(n,e)},[e]),n}function ue(e){return e}function se(e,t){t===void 0&&(t=ue);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(c){var u=t(c,r);return n.push(u),function(){n=n.filter(function(o){return o!==u})}},assignSyncMedium:function(c){for(r=!0;n.length;){var u=n;n=[],u.forEach(c)}n={push:function(o){return c(o)},filter:function(){return n}}},assignMedium:function(c){r=!0;var u=[];if(n.length){var o=n;n=[],o.forEach(c),u=n}var g=function(){var d=u;u=[],d.forEach(c)},b=function(){return Promise.resolve().then(g)};b(),n={push:function(d){u.push(d),b()},filter:function(d){return u=u.filter(d),n}}}};return a}function fe(e){e===void 0&&(e={});var t=se(null);return t.options=P({async:!0,ssr:!1},e),t}var _=function(e){var t=e.sideCar,n=z(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return l.createElement(r,P({},n))};_.isSideCarExport=!0;function de(e,t){return e.useMedium(t),_}var F=fe(),V=function(){},j=l.forwardRef(function(e,t){var n=l.useRef(null),r=l.useState({onScrollCapture:V,onWheelCapture:V,onTouchMoveCapture:V}),a=r[0],c=r[1],u=e.forwardProps,o=e.children,g=e.className,b=e.removeScrollBar,d=e.enabled,S=e.shards,w=e.sideCar,h=e.noIsolation,C=e.inert,i=e.allowPinchZoom,s=e.as,f=s===void 0?"div":s,v=e.gapMode,p=z(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=w,m=le([n,t]),N=P(P({},p),a);return l.createElement(l.Fragment,null,d&&l.createElement(E,{sideCar:F,removeScrollBar:b,shards:S,noIsolation:h,inert:C,setCallbacks:c,allowPinchZoom:!!i,lockRef:n,gapMode:v}),u?l.cloneElement(l.Children.only(o),P(P({},N),{ref:m})):l.createElement(f,P({},N,{className:g,ref:m}),o))});j.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},j.classNames={fullWidth:B,zeroRight:M};var ve=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function he(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ve();return t&&e.setAttribute("nonce",t),e}function ge(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function me(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var pe=function(){var e=0,t=null;return{add:function(n){e==0&&(t=he())&&(ge(t,n),me(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},be=function(){var e=pe();return function(t,n){l.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Z=function(){var e=be(),t=function(n){var r=n.styles,a=n.dynamic;return e(r,a),null};return t},ye={left:0,top:0,right:0,gap:0},X=function(e){return parseInt(e||"",10)||0},Se=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[X(n),X(r),X(a)]},we=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return ye;var t=Se(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Ce=Z(),L="data-scroll-locked",Ee=function(e,t,n,r){var a=e.left,c=e.top,u=e.right,o=e.gap;return n===void 0&&(n="margin"),` | ||
(function(L,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],k):(L=typeof globalThis<"u"?globalThis:L||self,k(L["simple-search-dropdown"]={},L["react/jsx-runtime"],L.React))})(this,function(L,k,y){"use strict";function re(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const l=re(y);var P=function(){return P=Object.assign||function(t){for(var n,r=1,a=arguments.length;r<a;r++){n=arguments[r];for(var c in n)Object.prototype.hasOwnProperty.call(n,c)&&(t[c]=n[c])}return t},P.apply(this,arguments)};function z(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(n[r[a]]=e[r[a]]);return n}function ne(e,t,n){if(n||arguments.length===2)for(var r=0,a=t.length,c;r<a;r++)(c||!(r in t))&&(c||(c=Array.prototype.slice.call(t,0,r)),c[r]=t[r]);return e.concat(c||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var M="right-scroll-bar-position",B="width-before-scroll-bar",ae="with-scroll-bars-hidden",oe="--removed-body-scroll-bar-size";function D(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function ce(e,t){var n=y.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=t,n.facade}var ie=typeof window<"u"?l.useLayoutEffect:l.useEffect,H=new WeakMap;function le(e,t){var n=ce(null,function(r){return e.forEach(function(a){return D(a,r)})});return ie(function(){var r=H.get(n);if(r){var a=new Set(r),c=new Set(e),u=n.current;a.forEach(function(o){c.has(o)||D(o,null)}),c.forEach(function(o){a.has(o)||D(o,u)})}H.set(n,e)},[e]),n}function ue(e){return e}function se(e,t){t===void 0&&(t=ue);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(c){var u=t(c,r);return n.push(u),function(){n=n.filter(function(o){return o!==u})}},assignSyncMedium:function(c){for(r=!0;n.length;){var u=n;n=[],u.forEach(c)}n={push:function(o){return c(o)},filter:function(){return n}}},assignMedium:function(c){r=!0;var u=[];if(n.length){var o=n;n=[],o.forEach(c),u=n}var m=function(){var d=u;u=[],d.forEach(c)},b=function(){return Promise.resolve().then(m)};b(),n={push:function(d){u.push(d),b()},filter:function(d){return u=u.filter(d),n}}}};return a}function fe(e){e===void 0&&(e={});var t=se(null);return t.options=P({async:!0,ssr:!1},e),t}var _=function(e){var t=e.sideCar,n=z(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return l.createElement(r,P({},n))};_.isSideCarExport=!0;function de(e,t){return e.useMedium(t),_}var F=fe(),V=function(){},j=l.forwardRef(function(e,t){var n=l.useRef(null),r=l.useState({onScrollCapture:V,onWheelCapture:V,onTouchMoveCapture:V}),a=r[0],c=r[1],u=e.forwardProps,o=e.children,m=e.className,b=e.removeScrollBar,d=e.enabled,S=e.shards,w=e.sideCar,g=e.noIsolation,E=e.inert,i=e.allowPinchZoom,s=e.as,f=s===void 0?"div":s,v=e.gapMode,p=z(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=w,h=le([n,t]),x=P(P({},p),a);return l.createElement(l.Fragment,null,d&&l.createElement(C,{sideCar:F,removeScrollBar:b,shards:S,noIsolation:g,inert:E,setCallbacks:c,allowPinchZoom:!!i,lockRef:n,gapMode:v}),u?l.cloneElement(l.Children.only(o),P(P({},x),{ref:h})):l.createElement(f,P({},x,{className:m,ref:h}),o))});j.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},j.classNames={fullWidth:B,zeroRight:M};var ve=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function he(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ve();return t&&e.setAttribute("nonce",t),e}function ge(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function me(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var pe=function(){var e=0,t=null;return{add:function(n){e==0&&(t=he())&&(ge(t,n),me(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},be=function(){var e=pe();return function(t,n){l.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Z=function(){var e=be(),t=function(n){var r=n.styles,a=n.dynamic;return e(r,a),null};return t},ye={left:0,top:0,right:0,gap:0},X=function(e){return parseInt(e||"",10)||0},Se=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[X(n),X(r),X(a)]},we=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return ye;var t=Se(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Ce=Z(),T="data-scroll-locked",Ee=function(e,t,n,r){var a=e.left,c=e.top,u=e.right,o=e.gap;return n===void 0&&(n="margin"),` | ||
.`.concat(ae,` { | ||
@@ -6,3 +6,3 @@ overflow: hidden `).concat(r,`; | ||
} | ||
body[`).concat(L,`] { | ||
body[`).concat(T,`] { | ||
overflow: hidden `).concat(r,`; | ||
@@ -36,8 +36,8 @@ overscroll-behavior: contain; | ||
body[`).concat(L,`] { | ||
body[`).concat(T,`] { | ||
`).concat(oe,": ").concat(o,`px; | ||
} | ||
`)},Q=function(){var e=parseInt(document.body.getAttribute(L)||"0",10);return isFinite(e)?e:0},ke=function(){l.useEffect(function(){return document.body.setAttribute(L,(Q()+1).toString()),function(){var e=Q()-1;e<=0?document.body.removeAttribute(L):document.body.setAttribute(L,e.toString())}},[])},Pe=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;ke();var c=l.useMemo(function(){return we(a)},[a]);return l.createElement(Ce,{styles:Ee(c,!t,a,n?"":"!important")})},Y=!1;if(typeof window<"u")try{var I=Object.defineProperty({},"passive",{get:function(){return Y=!0,!0}});window.addEventListener("test",I,I),window.removeEventListener("test",I,I)}catch{Y=!1}var R=Y?{passive:!1}:!1,xe=function(e){return e.tagName==="TEXTAREA"},q=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!xe(e)&&n[t]==="visible")},Le=function(e){return q(e,"overflowY")},Re=function(e){return q(e,"overflowX")},G=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=U(e,r);if(a){var c=$(e,r),u=c[1],o=c[2];if(u>o)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Te=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Ne=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},U=function(e,t){return e==="v"?Le(t):Re(t)},$=function(e,t){return e==="v"?Te(t):Ne(t)},Oe=function(e,t){return e==="h"&&t==="rtl"?-1:1},Me=function(e,t,n,r,a){var c=Oe(e,window.getComputedStyle(t).direction),u=c*r,o=n.target,g=t.contains(o),b=!1,d=u>0,S=0,w=0;do{var h=$(e,o),C=h[0],i=h[1],s=h[2],f=i-s-c*C;(C||f)&&U(e,o)&&(S+=f,w+=C),o instanceof ShadowRoot?o=o.host:o=o.parentNode}while(!g&&o!==document.body||g&&(t.contains(o)||t===o));return(d&&(Math.abs(S)<1||!a)||!d&&(Math.abs(w)<1||!a))&&(b=!0),b},A=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},J=function(e){return[e.deltaX,e.deltaY]},K=function(e){return e&&"current"in e?e.current:e},Be=function(e,t){return e[0]===t[0]&&e[1]===t[1]},je=function(e){return` | ||
`)},Q=function(){var e=parseInt(document.body.getAttribute(T)||"0",10);return isFinite(e)?e:0},ke=function(){l.useEffect(function(){return document.body.setAttribute(T,(Q()+1).toString()),function(){var e=Q()-1;e<=0?document.body.removeAttribute(T):document.body.setAttribute(T,e.toString())}},[])},Pe=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;ke();var c=l.useMemo(function(){return we(a)},[a]);return l.createElement(Ce,{styles:Ee(c,!t,a,n?"":"!important")})},Y=!1;if(typeof window<"u")try{var I=Object.defineProperty({},"passive",{get:function(){return Y=!0,!0}});window.addEventListener("test",I,I),window.removeEventListener("test",I,I)}catch{Y=!1}var N=Y?{passive:!1}:!1,xe=function(e){return e.tagName==="TEXTAREA"},q=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!xe(e)&&n[t]==="visible")},Le=function(e){return q(e,"overflowY")},Re=function(e){return q(e,"overflowX")},G=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=U(e,r);if(a){var c=$(e,r),u=c[1],o=c[2];if(u>o)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Te=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Ne=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},U=function(e,t){return e==="v"?Le(t):Re(t)},$=function(e,t){return e==="v"?Te(t):Ne(t)},Oe=function(e,t){return e==="h"&&t==="rtl"?-1:1},Me=function(e,t,n,r,a){var c=Oe(e,window.getComputedStyle(t).direction),u=c*r,o=n.target,m=t.contains(o),b=!1,d=u>0,S=0,w=0;do{var g=$(e,o),E=g[0],i=g[1],s=g[2],f=i-s-c*E;(E||f)&&U(e,o)&&(S+=f,w+=E),o instanceof ShadowRoot?o=o.host:o=o.parentNode}while(!m&&o!==document.body||m&&(t.contains(o)||t===o));return(d&&(Math.abs(S)<1||!a)||!d&&(Math.abs(w)<1||!a))&&(b=!0),b},A=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},J=function(e){return[e.deltaX,e.deltaY]},K=function(e){return e&&"current"in e?e.current:e},Be=function(e,t){return e[0]===t[0]&&e[1]===t[1]},je=function(e){return` | ||
.block-interactivity-`.concat(e,` {pointer-events: none;} | ||
.allow-interactivity-`).concat(e,` {pointer-events: all;} | ||
`)},Ie=0,T=[];function Ae(e){var t=l.useRef([]),n=l.useRef([0,0]),r=l.useRef(),a=l.useState(Ie++)[0],c=l.useState(Z)[0],u=l.useRef(e);l.useEffect(function(){u.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var i=ne([e.lockRef.current],(e.shards||[]).map(K),!0).filter(Boolean);return i.forEach(function(s){return s.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),i.forEach(function(s){return s.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var o=l.useCallback(function(i,s){if("touches"in i&&i.touches.length===2)return!u.current.allowPinchZoom;var f=A(i),v=n.current,p="deltaX"in i?i.deltaX:v[0]-f[0],E="deltaY"in i?i.deltaY:v[1]-f[1],m,N=i.target,O=Math.abs(p)>Math.abs(E)?"h":"v";if("touches"in i&&O==="h"&&N.type==="range")return!1;var W=G(O,N);if(!W)return!0;if(W?m=O:(m=O==="v"?"h":"v",W=G(O,N)),!W)return!1;if(!r.current&&"changedTouches"in i&&(p||E)&&(r.current=m),!m)return!0;var te=r.current||m;return Me(te,s,i,te==="h"?p:E,!0)},[]),g=l.useCallback(function(i){var s=i;if(!(!T.length||T[T.length-1]!==c)){var f="deltaY"in s?J(s):A(s),v=t.current.filter(function(m){return m.name===s.type&&(m.target===s.target||s.target===m.shadowParent)&&Be(m.delta,f)})[0];if(v&&v.should){s.cancelable&&s.preventDefault();return}if(!v){var p=(u.current.shards||[]).map(K).filter(Boolean).filter(function(m){return m.contains(s.target)}),E=p.length>0?o(s,p[0]):!u.current.noIsolation;E&&s.cancelable&&s.preventDefault()}}},[]),b=l.useCallback(function(i,s,f,v){var p={name:i,delta:s,target:f,should:v,shadowParent:We(f)};t.current.push(p),setTimeout(function(){t.current=t.current.filter(function(E){return E!==p})},1)},[]),d=l.useCallback(function(i){n.current=A(i),r.current=void 0},[]),S=l.useCallback(function(i){b(i.type,J(i),i.target,o(i,e.lockRef.current))},[]),w=l.useCallback(function(i){b(i.type,A(i),i.target,o(i,e.lockRef.current))},[]);l.useEffect(function(){return T.push(c),e.setCallbacks({onScrollCapture:S,onWheelCapture:S,onTouchMoveCapture:w}),document.addEventListener("wheel",g,R),document.addEventListener("touchmove",g,R),document.addEventListener("touchstart",d,R),function(){T=T.filter(function(i){return i!==c}),document.removeEventListener("wheel",g,R),document.removeEventListener("touchmove",g,R),document.removeEventListener("touchstart",d,R)}},[]);var h=e.removeScrollBar,C=e.inert;return l.createElement(l.Fragment,null,C?l.createElement(c,{styles:je(a)}):null,h?l.createElement(Pe,{gapMode:e.gapMode}):null)}function We(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const De=de(F,Ae);var ee=l.forwardRef(function(e,t){return l.createElement(j,P({},e,{ref:t,sideCar:De}))});ee.classNames=j.classNames;const Ve=y.forwardRef((e,t)=>{const[n,r]=y.useState(!1),[a,c]=y.useState(!1),[u,o]=y.useState({label:"",value:""}),[g,b]=y.useState(""),[d,S]=y.useState(),{data:w,...h}=e,C=y.useRef(null),i=y.useRef(null);y.useEffect(()=>{if(a){c(!1);return}if(d!=null&&d.length&&g&&S(void 0),w&&typeof w=="function"){const f=w(g);if(f instanceof Promise){f.then(v=>{S(v)});return}S(f)}else w&&S(w)},[a]);const s=f=>{const v=f.target;C.current&&!C.current.contains(v)&&i.current&&!i.current.contains(v)&&r(!1)};return y.useEffect(()=>(document.addEventListener("mousedown",s),()=>{document.removeEventListener("mousedown",s)}),[]),k.jsxs("div",{children:[k.jsx("input",{ref:C,onFocus:()=>r(!0),className:"p-2 bg-gray-200 cursor-pointer focus:cursor-text",type:"text",value:u.label,onChange:f=>{var p;const v=((p=d==null?void 0:d.find(E=>E.value.toLowerCase()===f.target.value.toLowerCase()))==null?void 0:p.value)??u.value;b(f.target.value.toLowerCase()),o({label:f.target.value,value:v}),c(!0),h.onChange&&h.onChange(f)},placeholder:h.placeholder,disabled:h.disabled}),k.jsx("input",{id:h.name,name:h.name,onChange:h.onChange,onBlur:h.onBlur,ref:t,disabled:!0,className:"hidden",type:"text",value:u.value}),n&&d&&d.length>0&&k.jsx(ee,{children:k.jsx("div",{ref:i,className:"absolute z-10 w-full bg-white border border-gray-300 rounded mt-1",children:d.filter(f=>f.label.toLowerCase().indexOf(g??"")>-1).map((f,v)=>k.jsx("div",{className:"p-2 cursor-pointer hover:bg-gray-100",onClick:()=>{o(f),r(!1)},children:f.label},v))})})]})});x.SearchSelect=Ve,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}); | ||
`)},Ie=0,O=[];function Ae(e){var t=l.useRef([]),n=l.useRef([0,0]),r=l.useRef(),a=l.useState(Ie++)[0],c=l.useState(Z)[0],u=l.useRef(e);l.useEffect(function(){u.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var i=ne([e.lockRef.current],(e.shards||[]).map(K),!0).filter(Boolean);return i.forEach(function(s){return s.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),i.forEach(function(s){return s.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var o=l.useCallback(function(i,s){if("touches"in i&&i.touches.length===2)return!u.current.allowPinchZoom;var f=A(i),v=n.current,p="deltaX"in i?i.deltaX:v[0]-f[0],C="deltaY"in i?i.deltaY:v[1]-f[1],h,x=i.target,R=Math.abs(p)>Math.abs(C)?"h":"v";if("touches"in i&&R==="h"&&x.type==="range")return!1;var W=G(R,x);if(!W)return!0;if(W?h=R:(h=R==="v"?"h":"v",W=G(R,x)),!W)return!1;if(!r.current&&"changedTouches"in i&&(p||C)&&(r.current=h),!h)return!0;var te=r.current||h;return Me(te,s,i,te==="h"?p:C,!0)},[]),m=l.useCallback(function(i){var s=i;if(!(!O.length||O[O.length-1]!==c)){var f="deltaY"in s?J(s):A(s),v=t.current.filter(function(h){return h.name===s.type&&(h.target===s.target||s.target===h.shadowParent)&&Be(h.delta,f)})[0];if(v&&v.should){s.cancelable&&s.preventDefault();return}if(!v){var p=(u.current.shards||[]).map(K).filter(Boolean).filter(function(h){return h.contains(s.target)}),C=p.length>0?o(s,p[0]):!u.current.noIsolation;C&&s.cancelable&&s.preventDefault()}}},[]),b=l.useCallback(function(i,s,f,v){var p={name:i,delta:s,target:f,should:v,shadowParent:We(f)};t.current.push(p),setTimeout(function(){t.current=t.current.filter(function(C){return C!==p})},1)},[]),d=l.useCallback(function(i){n.current=A(i),r.current=void 0},[]),S=l.useCallback(function(i){b(i.type,J(i),i.target,o(i,e.lockRef.current))},[]),w=l.useCallback(function(i){b(i.type,A(i),i.target,o(i,e.lockRef.current))},[]);l.useEffect(function(){return O.push(c),e.setCallbacks({onScrollCapture:S,onWheelCapture:S,onTouchMoveCapture:w}),document.addEventListener("wheel",m,N),document.addEventListener("touchmove",m,N),document.addEventListener("touchstart",d,N),function(){O=O.filter(function(i){return i!==c}),document.removeEventListener("wheel",m,N),document.removeEventListener("touchmove",m,N),document.removeEventListener("touchstart",d,N)}},[]);var g=e.removeScrollBar,E=e.inert;return l.createElement(l.Fragment,null,E?l.createElement(c,{styles:je(a)}):null,g?l.createElement(Pe,{gapMode:e.gapMode}):null)}function We(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const De=de(F,Ae);var ee=l.forwardRef(function(e,t){return l.createElement(j,P({},e,{ref:t,sideCar:De}))});ee.classNames=j.classNames;const Ve=y.forwardRef((e,t)=>{const[n,r]=y.useState(!1),[a,c]=y.useState(!1),[u,o]=y.useState({label:"",value:""}),[m,b]=y.useState(""),[d,S]=y.useState(),{data:w,...g}=e,E=y.useRef(null),i=y.useRef(null);y.useEffect(()=>{if(a){c(!1);return}if(d!=null&&d.length&&m&&S(void 0),w&&typeof w=="function"){const f=w(m);if(f instanceof Promise){f.then(v=>{S(v)});return}S(f)}else w&&S(w)},[a]);const s=f=>{const v=f.target;E.current&&!E.current.contains(v)&&i.current&&!i.current.contains(v)&&r(!1)};return y.useEffect(()=>(document.addEventListener("mousedown",s),()=>{document.removeEventListener("mousedown",s)}),[]),k.jsxs("div",{children:[k.jsx("input",{ref:E,onFocus:()=>r(!0),className:"p-2 bg-gray-200 cursor-pointer focus:cursor-text",type:"text",value:u.label,onChange:f=>{var p,C;const v=((p=d==null?void 0:d.find(h=>{var x,R;return((x=h.value)==null?void 0:x.toLowerCase())===((R=f.target.value)==null?void 0:R.toLowerCase())}))==null?void 0:p.value)??u.value;b((C=f.target.value)==null?void 0:C.toLowerCase()),o({label:f.target.value??"",value:v}),c(!0),g.onChange&&g.onChange(f)},placeholder:g.placeholder,disabled:g.disabled}),k.jsx("input",{id:g.name,name:g.name,onChange:g.onChange,onBlur:g.onBlur,ref:t,disabled:!0,className:"hidden",type:"text",value:u.value}),n&&d&&d.length>0&&k.jsx(ee,{children:k.jsx("div",{ref:i,className:"absolute z-10 w-full bg-white border border-gray-300 rounded mt-1",children:d.filter(f=>f.label.toLowerCase().indexOf(m??"")>-1).map((f,v)=>k.jsx("div",{className:"p-2 cursor-pointer hover:bg-gray-100",onClick:()=>{o(f),r(!1)},children:f.label},v))})})]})});L.SearchSelect=Ve,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "simple-search-dropdown", | ||
"private": false, | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "./dist/index.umd.js", | ||
@@ -6,0 +6,0 @@ "module": "./dist/index.es.js", |
38447
650