simple-search-dropdown
Advanced tools
Comparing version 0.0.9 to 0.1.0
import { jsxs as ne, jsx as M } from "react/jsx-runtime"; | ||
import * as l from "react"; | ||
import ae, { useState as x, useRef as H, useEffect as z } from "react"; | ||
import ae, { useState as L, useRef as H, useEffect as z } from "react"; | ||
var w = function() { | ||
@@ -31,3 +31,3 @@ return w = Object.assign || function(t) { | ||
function le(e, t) { | ||
var n = x(function() { | ||
var n = L(function() { | ||
return { | ||
@@ -235,3 +235,3 @@ // value | ||
}; | ||
}, Re = J(), L = "data-scroll-locked", ke = function(e, t, n, r) { | ||
}, Re = J(), x = "data-scroll-locked", ke = function(e, t, n, r) { | ||
var a = e.left, c = e.top, u = e.right, o = e.gap; | ||
@@ -243,3 +243,3 @@ return n === void 0 && (n = "margin"), ` | ||
} | ||
body[`).concat(L, `] { | ||
body[`).concat(x, `] { | ||
overflow: hidden `).concat(r, `; | ||
@@ -277,3 +277,3 @@ overscroll-behavior: contain; | ||
body[`).concat(L, `] { | ||
body[`).concat(x, `] { | ||
`).concat(ie, ": ").concat(o, `px; | ||
@@ -283,12 +283,12 @@ } | ||
}, _ = function() { | ||
var e = parseInt(document.body.getAttribute(L) || "0", 10); | ||
var e = parseInt(document.body.getAttribute(x) || "0", 10); | ||
return isFinite(e) ? e : 0; | ||
}, Pe = function() { | ||
l.useEffect(function() { | ||
return document.body.setAttribute(L, (_() + 1).toString()), function() { | ||
return document.body.setAttribute(x, (_() + 1).toString()), function() { | ||
var e = _() - 1; | ||
e <= 0 ? document.body.removeAttribute(L) : document.body.setAttribute(L, e.toString()); | ||
e <= 0 ? document.body.removeAttribute(x) : document.body.setAttribute(x, e.toString()); | ||
}; | ||
}, []); | ||
}, xe = function(e) { | ||
}, Le = function(e) { | ||
var t = e.noRelative, n = e.noImportant, r = e.gapMode, a = r === void 0 ? "margin" : r; | ||
@@ -312,3 +312,3 @@ Pe(); | ||
} | ||
var k = Y ? { passive: !1 } : !1, Le = function(e) { | ||
var k = Y ? { passive: !1 } : !1, xe = function(e) { | ||
return e.tagName === "TEXTAREA"; | ||
@@ -322,3 +322,3 @@ }, K = function(e, t) { | ||
n[t] !== "hidden" && // contains scroll inside self | ||
!(n.overflowY === n.overflowX && !Le(e) && n[t] === "visible") | ||
!(n.overflowY === n.overflowX && !xe(e) && n[t] === "visible") | ||
); | ||
@@ -466,3 +466,3 @@ }, Ne = function(e) { | ||
p ? l.createElement(c, { styles: We(a) }) : null, | ||
C ? l.createElement(xe, { gapMode: e.gapMode }) : null | ||
C ? l.createElement(Le, { gapMode: e.gapMode }) : null | ||
); | ||
@@ -481,3 +481,3 @@ } | ||
const ze = ae.forwardRef((e, t) => { | ||
const [n, r] = x(!1), [a, c] = x(!1), [u, o] = x(), [h, g] = x(""), [d, y] = x(), { data: b, ...C } = e, p = H(null), i = H(null); | ||
const [n, r] = L(!1), [a, c] = L(!1), [u, o] = L(), [h, g] = L(""), [d, y] = L(), { data: b, ...C } = e, p = H(null), i = H(null); | ||
z(() => { | ||
@@ -489,3 +489,3 @@ if (a) { | ||
if (d != null && d.length && h && y(void 0), b && typeof b == "function") { | ||
const f = b(h); | ||
const f = b(h.toLowerCase()); | ||
if (f instanceof Promise) { | ||
@@ -516,10 +516,11 @@ f.then((v) => { | ||
onChange: (f) => { | ||
g(f.target.value.toLowerCase()), c(!0); | ||
g(f.target.value), c(!0); | ||
}, | ||
placeholder: e.placeholder, | ||
disabled: e.disabled | ||
disabled: e.disabled, | ||
...C | ||
} | ||
), | ||
/* @__PURE__ */ M("input", { ref: t, ...C, disabled: !0, className: "hidden", type: "text", value: (u == null ? void 0 : u.value) ?? "" }), | ||
n && d && d.length > 0 && /* @__PURE__ */ M(re, { children: /* @__PURE__ */ M("div", { ref: i, className: "absolute z-10 w-full bg-white border border-gray-300 rounded mt-1", children: d.filter((f) => String(f.label).toLowerCase().indexOf(h ?? "") > -1).map((f, v) => /* @__PURE__ */ M("div", { className: "p-2 cursor-pointer hover:bg-gray-100", onClick: () => { | ||
/* @__PURE__ */ M("input", { ref: t, disabled: !0, className: "hidden", type: "text", value: (u == null ? void 0 : u.value) ?? "" }), | ||
n && d && d.length > 0 && /* @__PURE__ */ M(re, { children: /* @__PURE__ */ M("div", { ref: i, className: "absolute z-10 w-full bg-white border border-gray-300 rounded mt-1", children: d.filter((f) => String(f.label).toLowerCase().indexOf(h.toLowerCase() ?? "") > -1).map((f, v) => /* @__PURE__ */ M("div", { className: "p-2 cursor-pointer hover:bg-gray-100", onClick: () => { | ||
o(f), r(!1); | ||
@@ -526,0 +527,0 @@ }, children: f.label }, v)) }) }) |
@@ -41,2 +41,2 @@ (function(x,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],C):(x=typeof globalThis<"u"?globalThis:x||self,C(x["simple-search-dropdown"]={},x["react/jsx-runtime"],x.React))})(this,function(x,C,p){"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 u=re(p);var E=function(){return E=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},E.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",j="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=p.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"?u.useLayoutEffect:u.useEffect,H=new WeakMap;function ue(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),l=n.current;a.forEach(function(o){c.has(o)||D(o,null)}),c.forEach(function(o){a.has(o)||D(o,l)})}H.set(n,e)},[e]),n}function le(e){return e}function se(e,t){t===void 0&&(t=le);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 l=t(c,r);return n.push(l),function(){n=n.filter(function(o){return o!==l})}},assignSyncMedium:function(c){for(r=!0;n.length;){var l=n;n=[],l.forEach(c)}n={push:function(o){return c(o)},filter:function(){return n}}},assignMedium:function(c){r=!0;var l=[];if(n.length){var o=n;n=[],o.forEach(c),l=n}var h=function(){var d=l;l=[],d.forEach(c)},m=function(){return Promise.resolve().then(h)};m(),n={push:function(d){l.push(d),m()},filter:function(d){return l=l.filter(d),n}}}};return a}function fe(e){e===void 0&&(e={});var t=se(null);return t.options=E({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 u.createElement(r,E({},n))};_.isSideCarExport=!0;function de(e,t){return e.useMedium(t),_}var F=fe(),V=function(){},B=u.forwardRef(function(e,t){var n=u.useRef(null),r=u.useState({onScrollCapture:V,onWheelCapture:V,onTouchMoveCapture:V}),a=r[0],c=r[1],l=e.forwardProps,o=e.children,h=e.className,m=e.removeScrollBar,d=e.enabled,y=e.shards,S=e.sideCar,k=e.noIsolation,b=e.inert,i=e.allowPinchZoom,s=e.as,f=s===void 0?"div":s,v=e.gapMode,w=z(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),P=S,g=ue([n,t]),N=E(E({},w),a);return u.createElement(u.Fragment,null,d&&u.createElement(P,{sideCar:F,removeScrollBar:m,shards:y,noIsolation:k,inert:b,setCallbacks:c,allowPinchZoom:!!i,lockRef:n,gapMode:v}),l?u.cloneElement(u.Children.only(o),E(E({},N),{ref:g})):u.createElement(f,E({},N,{className:h,ref:g}),o))});B.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},B.classNames={fullWidth:j,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)}}},ye=function(){var e=pe();return function(t,n){u.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Z=function(){var e=ye(),t=function(n){var r=n.styles,a=n.dynamic;return e(r,a),null};return t},Se={left:0,top:0,right:0,gap:0},X=function(e){return parseInt(e||"",10)||0},be=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 Se;var t=be(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,l=e.right,o=e.gap;return n===void 0&&(n="margin"),` | ||
.allow-interactivity-`).concat(e,` {pointer-events: all;} | ||
`)},Ie=0,T=[];function Ae(e){var t=u.useRef([]),n=u.useRef([0,0]),r=u.useRef(),a=u.useState(Ie++)[0],c=u.useState(Z)[0],l=u.useRef(e);u.useEffect(function(){l.current=e},[e]),u.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(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=u.useCallback(function(i,s){if("touches"in i&&i.touches.length===2)return!l.current.allowPinchZoom;var f=A(i),v=n.current,w="deltaX"in i?i.deltaX:v[0]-f[0],P="deltaY"in i?i.deltaY:v[1]-f[1],g,N=i.target,O=Math.abs(w)>Math.abs(P)?"h":"v";if("touches"in i&&O==="h"&&N.type==="range")return!1;var W=G(O,N);if(!W)return!0;if(W?g=O:(g=O==="v"?"h":"v",W=G(O,N)),!W)return!1;if(!r.current&&"changedTouches"in i&&(w||P)&&(r.current=g),!g)return!0;var te=r.current||g;return Me(te,s,i,te==="h"?w:P,!0)},[]),h=u.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(g){return g.name===s.type&&(g.target===s.target||s.target===g.shadowParent)&&je(g.delta,f)})[0];if(v&&v.should){s.cancelable&&s.preventDefault();return}if(!v){var w=(l.current.shards||[]).map(K).filter(Boolean).filter(function(g){return g.contains(s.target)}),P=w.length>0?o(s,w[0]):!l.current.noIsolation;P&&s.cancelable&&s.preventDefault()}}},[]),m=u.useCallback(function(i,s,f,v){var w={name:i,delta:s,target:f,should:v,shadowParent:We(f)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(P){return P!==w})},1)},[]),d=u.useCallback(function(i){n.current=A(i),r.current=void 0},[]),y=u.useCallback(function(i){m(i.type,J(i),i.target,o(i,e.lockRef.current))},[]),S=u.useCallback(function(i){m(i.type,A(i),i.target,o(i,e.lockRef.current))},[]);u.useEffect(function(){return T.push(c),e.setCallbacks({onScrollCapture:y,onWheelCapture:y,onTouchMoveCapture:S}),document.addEventListener("wheel",h,R),document.addEventListener("touchmove",h,R),document.addEventListener("touchstart",d,R),function(){T=T.filter(function(i){return i!==c}),document.removeEventListener("wheel",h,R),document.removeEventListener("touchmove",h,R),document.removeEventListener("touchstart",d,R)}},[]);var k=e.removeScrollBar,b=e.inert;return u.createElement(u.Fragment,null,b?u.createElement(c,{styles:Be(a)}):null,k?u.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=u.forwardRef(function(e,t){return u.createElement(B,E({},e,{ref:t,sideCar:De}))});ee.classNames=B.classNames;const Ve=p.forwardRef((e,t)=>{const[n,r]=p.useState(!1),[a,c]=p.useState(!1),[l,o]=p.useState(),[h,m]=p.useState(""),[d,y]=p.useState(),{data:S,...k}=e,b=p.useRef(null),i=p.useRef(null);p.useEffect(()=>{if(a){c(!1);return}if(d!=null&&d.length&&h&&y(void 0),S&&typeof S=="function"){const f=S(h);if(f instanceof Promise){f.then(v=>{y(v)});return}y(f)}else S&&y(S)},[a]);const s=f=>{const v=f.target;b.current&&!b.current.contains(v)&&i.current&&!i.current.contains(v)&&r(!1)};return p.useEffect(()=>(document.addEventListener("mousedown",s),()=>{document.removeEventListener("mousedown",s)}),[]),C.jsxs("div",{children:[C.jsx("input",{ref:b,onFocus:()=>r(!0),className:"p-2 bg-gray-200 cursor-pointer focus:cursor-text",type:"text",value:(l==null?void 0:l.label)||h,onChange:f=>{m(f.target.value.toLowerCase()),c(!0)},placeholder:e.placeholder,disabled:e.disabled}),C.jsx("input",{ref:t,...k,disabled:!0,className:"hidden",type:"text",value:(l==null?void 0:l.value)??""}),n&&d&&d.length>0&&C.jsx(ee,{children:C.jsx("div",{ref:i,className:"absolute z-10 w-full bg-white border border-gray-300 rounded mt-1",children:d.filter(f=>String(f.label).toLowerCase().indexOf(h??"")>-1).map((f,v)=>C.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,T=[];function Ae(e){var t=u.useRef([]),n=u.useRef([0,0]),r=u.useRef(),a=u.useState(Ie++)[0],c=u.useState(Z)[0],l=u.useRef(e);u.useEffect(function(){l.current=e},[e]),u.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(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=u.useCallback(function(i,s){if("touches"in i&&i.touches.length===2)return!l.current.allowPinchZoom;var f=A(i),v=n.current,w="deltaX"in i?i.deltaX:v[0]-f[0],P="deltaY"in i?i.deltaY:v[1]-f[1],g,N=i.target,O=Math.abs(w)>Math.abs(P)?"h":"v";if("touches"in i&&O==="h"&&N.type==="range")return!1;var W=G(O,N);if(!W)return!0;if(W?g=O:(g=O==="v"?"h":"v",W=G(O,N)),!W)return!1;if(!r.current&&"changedTouches"in i&&(w||P)&&(r.current=g),!g)return!0;var te=r.current||g;return Me(te,s,i,te==="h"?w:P,!0)},[]),h=u.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(g){return g.name===s.type&&(g.target===s.target||s.target===g.shadowParent)&&je(g.delta,f)})[0];if(v&&v.should){s.cancelable&&s.preventDefault();return}if(!v){var w=(l.current.shards||[]).map(K).filter(Boolean).filter(function(g){return g.contains(s.target)}),P=w.length>0?o(s,w[0]):!l.current.noIsolation;P&&s.cancelable&&s.preventDefault()}}},[]),m=u.useCallback(function(i,s,f,v){var w={name:i,delta:s,target:f,should:v,shadowParent:We(f)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(P){return P!==w})},1)},[]),d=u.useCallback(function(i){n.current=A(i),r.current=void 0},[]),y=u.useCallback(function(i){m(i.type,J(i),i.target,o(i,e.lockRef.current))},[]),S=u.useCallback(function(i){m(i.type,A(i),i.target,o(i,e.lockRef.current))},[]);u.useEffect(function(){return T.push(c),e.setCallbacks({onScrollCapture:y,onWheelCapture:y,onTouchMoveCapture:S}),document.addEventListener("wheel",h,R),document.addEventListener("touchmove",h,R),document.addEventListener("touchstart",d,R),function(){T=T.filter(function(i){return i!==c}),document.removeEventListener("wheel",h,R),document.removeEventListener("touchmove",h,R),document.removeEventListener("touchstart",d,R)}},[]);var k=e.removeScrollBar,b=e.inert;return u.createElement(u.Fragment,null,b?u.createElement(c,{styles:Be(a)}):null,k?u.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=u.forwardRef(function(e,t){return u.createElement(B,E({},e,{ref:t,sideCar:De}))});ee.classNames=B.classNames;const Ve=p.forwardRef((e,t)=>{const[n,r]=p.useState(!1),[a,c]=p.useState(!1),[l,o]=p.useState(),[h,m]=p.useState(""),[d,y]=p.useState(),{data:S,...k}=e,b=p.useRef(null),i=p.useRef(null);p.useEffect(()=>{if(a){c(!1);return}if(d!=null&&d.length&&h&&y(void 0),S&&typeof S=="function"){const f=S(h.toLowerCase());if(f instanceof Promise){f.then(v=>{y(v)});return}y(f)}else S&&y(S)},[a]);const s=f=>{const v=f.target;b.current&&!b.current.contains(v)&&i.current&&!i.current.contains(v)&&r(!1)};return p.useEffect(()=>(document.addEventListener("mousedown",s),()=>{document.removeEventListener("mousedown",s)}),[]),C.jsxs("div",{children:[C.jsx("input",{ref:b,onFocus:()=>r(!0),className:"p-2 bg-gray-200 cursor-pointer focus:cursor-text",type:"text",value:(l==null?void 0:l.label)||h,onChange:f=>{m(f.target.value),c(!0)},placeholder:e.placeholder,disabled:e.disabled,...k}),C.jsx("input",{ref:t,disabled:!0,className:"hidden",type:"text",value:(l==null?void 0:l.value)??""}),n&&d&&d.length>0&&C.jsx(ee,{children:C.jsx("div",{ref:i,className:"absolute z-10 w-full bg-white border border-gray-300 rounded mt-1",children:d.filter(f=>String(f.label).toLowerCase().indexOf(h.toLowerCase()??"")>-1).map((f,v)=>C.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"})}); |
{ | ||
"name": "simple-search-dropdown", | ||
"private": false, | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"main": "./dist/index.umd.js", | ||
@@ -6,0 +6,0 @@ "module": "./dist/index.es.js", |
37679
632