UNPKG

react-select-items

Version:
31 lines (28 loc) 19.4 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react");var ce={exports:{}},X={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Me;function ht(){if(Me)return X;Me=1;var n=h,a=Symbol.for("react.element"),d=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,l=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,O={key:!0,ref:!0,__self:!0,__source:!0};function _(b,v,m){var u,p={},C=null,E=null;m!==void 0&&(C=""+m),v.key!==void 0&&(C=""+v.key),v.ref!==void 0&&(E=v.ref);for(u in v)s.call(v,u)&&!O.hasOwnProperty(u)&&(p[u]=v[u]);if(b&&b.defaultProps)for(u in v=b.defaultProps,v)p[u]===void 0&&(p[u]=v[u]);return{$$typeof:a,type:b,key:C,ref:E,props:p,_owner:l.current}}return X.Fragment=d,X.jsx=_,X.jsxs=_,X}var q={};/** * @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 Ae;function mt(){return Ae||(Ae=1,process.env.NODE_ENV!=="production"&&function(){var n=h,a=Symbol.for("react.element"),d=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),O=Symbol.for("react.profiler"),_=Symbol.for("react.provider"),b=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),E=Symbol.for("react.offscreen"),j=Symbol.iterator,T="@@iterator";function x(e){if(e===null||typeof e!="object")return null;var t=j&&e[j]||e[T];return typeof t=="function"?t:null}var k=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(e){{for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];S("error",e,r)}}function S(e,t,r){{var o=k.ReactDebugCurrentFrame,f=o.getStackAddendum();f!==""&&(t+="%s",r=r.concat([f]));var g=r.map(function(c){return String(c)});g.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,g)}}var Y=!1,A=!1,W=!1,J=!1,We=!1,le;le=Symbol.for("react.module.reference");function $e(e){return!!(typeof e=="string"||typeof e=="function"||e===s||e===O||We||e===l||e===m||e===u||J||e===E||Y||A||W||typeof e=="object"&&e!==null&&(e.$$typeof===C||e.$$typeof===p||e.$$typeof===_||e.$$typeof===b||e.$$typeof===v||e.$$typeof===le||e.getModuleId!==void 0))}function Ue(e,t,r){var o=e.displayName;if(o)return o;var f=t.displayName||t.name||"";return f!==""?r+"("+f+")":r}function fe(e){return e.displayName||"Context"}function M(e){if(e==null)return null;if(typeof e.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case s:return"Fragment";case d:return"Portal";case O:return"Profiler";case l:return"StrictMode";case m:return"Suspense";case u:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case b:var t=e;return fe(t)+".Consumer";case _:var r=e;return fe(r._context)+".Provider";case v:return Ue(e,e.render,"ForwardRef");case p:var o=e.displayName||null;return o!==null?o:M(e.type)||"Memo";case C:{var f=e,g=f._payload,c=f._init;try{return M(c(g))}catch{return null}}}return null}var F=Object.assign,N=0,de,ve,pe,ge,he,me,be;function ye(){}ye.__reactDisabledLog=!0;function Ve(){{if(N===0){de=console.log,ve=console.info,pe=console.warn,ge=console.error,he=console.group,me=console.groupCollapsed,be=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ye,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}N++}}function Ne(){{if(N--,N===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:de}),info:F({},e,{value:ve}),warn:F({},e,{value:pe}),error:F({},e,{value:ge}),group:F({},e,{value:he}),groupCollapsed:F({},e,{value:me}),groupEnd:F({},e,{value:be})})}N<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ee=k.ReactCurrentDispatcher,te;function G(e,t,r){{if(te===void 0)try{throw Error()}catch(f){var o=f.stack.trim().match(/\n( *(at )?)/);te=o&&o[1]||""}return` `+te+e}}var re=!1,H;{var Ke=typeof WeakMap=="function"?WeakMap:Map;H=new Ke}function Ee(e,t){if(!e||re)return"";{var r=H.get(e);if(r!==void 0)return r}var o;re=!0;var f=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var g;g=ee.current,ee.current=null,Ve();try{if(t){var c=function(){throw Error()};if(Object.defineProperty(c.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(c,[])}catch(D){o=D}Reflect.construct(e,[],c)}else{try{c.call()}catch(D){o=D}e.call(c.prototype)}}else{try{throw Error()}catch(D){o=D}e()}}catch(D){if(D&&o&&typeof D.stack=="string"){for(var i=D.stack.split(` `),P=o.stack.split(` `),R=i.length-1,w=P.length-1;R>=1&&w>=0&&i[R]!==P[w];)w--;for(;R>=1&&w>=0;R--,w--)if(i[R]!==P[w]){if(R!==1||w!==1)do if(R--,w--,w<0||i[R]!==P[w]){var I=` `+i[R].replace(" at new "," at ");return e.displayName&&I.includes("<anonymous>")&&(I=I.replace("<anonymous>",e.displayName)),typeof e=="function"&&H.set(e,I),I}while(R>=1&&w>=0);break}}}finally{re=!1,ee.current=g,Ne(),Error.prepareStackTrace=f}var U=e?e.displayName||e.name:"",L=U?G(U):"";return typeof e=="function"&&H.set(e,L),L}function ze(e,t,r){return Ee(e,!1)}function Xe(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function Z(e,t,r){if(e==null)return"";if(typeof e=="function")return Ee(e,Xe(e));if(typeof e=="string")return G(e);switch(e){case m:return G("Suspense");case u:return G("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case v:return ze(e.render);case p:return Z(e.type,t,r);case C:{var o=e,f=o._payload,g=o._init;try{return Z(g(f),t,r)}catch{}}}return""}var K=Object.prototype.hasOwnProperty,Se={},Re=k.ReactDebugCurrentFrame;function Q(e){if(e){var t=e._owner,r=Z(e.type,e._source,t?t.type:null);Re.setExtraStackFrame(r)}else Re.setExtraStackFrame(null)}function qe(e,t,r,o,f){{var g=Function.call.bind(K);for(var c in e)if(g(e,c)){var i=void 0;try{if(typeof e[c]!="function"){var P=Error((o||"React class")+": "+r+" type `"+c+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[c]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw P.name="Invariant Violation",P}i=e[c](t,c,o,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(R){i=R}i&&!(i instanceof Error)&&(Q(f),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",o||"React class",r,c,typeof i),Q(null)),i instanceof Error&&!(i.message in Se)&&(Se[i.message]=!0,Q(f),y("Failed %s type: %s",r,i.message),Q(null))}}}var Je=Array.isArray;function ne(e){return Je(e)}function Ge(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,r=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r}}function He(e){try{return _e(e),!1}catch{return!0}}function _e(e){return""+e}function we(e){if(He(e))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ge(e)),_e(e)}var z=k.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},xe,Oe,ae;ae={};function Qe(e){if(K.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function et(e){if(K.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function tt(e,t){if(typeof e.ref=="string"&&z.current&&t&&z.current.stateNode!==t){var r=M(z.current.type);ae[r]||(y('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',M(z.current.type),e.ref),ae[r]=!0)}}function rt(e,t){{var r=function(){xe||(xe=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}}function nt(e,t){{var r=function(){Oe||(Oe=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}}var at=function(e,t,r,o,f,g,c){var i={$$typeof:a,type:e,key:t,ref:r,props:c,_owner:g};return i._store={},Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:f}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i};function ot(e,t,r,o,f){{var g,c={},i=null,P=null;r!==void 0&&(we(r),i=""+r),et(t)&&(we(t.key),i=""+t.key),Qe(t)&&(P=t.ref,tt(t,f));for(g in t)K.call(t,g)&&!Ze.hasOwnProperty(g)&&(c[g]=t[g]);if(e&&e.defaultProps){var R=e.defaultProps;for(g in R)c[g]===void 0&&(c[g]=R[g])}if(i||P){var w=typeof e=="function"?e.displayName||e.name||"Unknown":e;i&&rt(c,w),P&&nt(c,w)}return at(e,i,P,f,o,z.current,c)}}var oe=k.ReactCurrentOwner,Ce=k.ReactDebugCurrentFrame;function $(e){if(e){var t=e._owner,r=Z(e.type,e._source,t?t.type:null);Ce.setExtraStackFrame(r)}else Ce.setExtraStackFrame(null)}var se;se=!1;function ie(e){return typeof e=="object"&&e!==null&&e.$$typeof===a}function Te(){{if(oe.current){var e=M(oe.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function st(e){return""}var Pe={};function it(e){{var t=Te();if(!t){var r=typeof e=="string"?e:e.displayName||e.name;r&&(t=` Check the top-level render call using <`+r+">.")}return t}}function je(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var r=it(t);if(Pe[r])return;Pe[r]=!0;var o="";e&&e._owner&&e._owner!==oe.current&&(o=" It was passed a child from "+M(e._owner.type)+"."),$(e),y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,o),$(null)}}function De(e,t){{if(typeof e!="object")return;if(ne(e))for(var r=0;r<e.length;r++){var o=e[r];ie(o)&&je(o,t)}else if(ie(e))e._store&&(e._store.validated=!0);else if(e){var f=x(e);if(typeof f=="function"&&f!==e.entries)for(var g=f.call(e),c;!(c=g.next()).done;)ie(c.value)&&je(c.value,t)}}}function ut(e){{var t=e.type;if(t==null||typeof t=="string")return;var r;if(typeof t=="function")r=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===v||t.$$typeof===p))r=t.propTypes;else return;if(r){var o=M(t);qe(r,e.props,"prop",o,e)}else if(t.PropTypes!==void 0&&!se){se=!0;var f=M(t);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",f||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ct(e){{for(var t=Object.keys(e.props),r=0;r<t.length;r++){var o=t[r];if(o!=="children"&&o!=="key"){$(e),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",o),$(null);break}}e.ref!==null&&($(e),y("Invalid attribute `ref` supplied to `React.Fragment`."),$(null))}}var ke={};function Ie(e,t,r,o,f,g){{var c=$e(e);if(!c){var i="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(i+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var P=st();P?i+=P:i+=Te();var R;e===null?R="null":ne(e)?R="array":e!==void 0&&e.$$typeof===a?(R="<"+(M(e.type)||"Unknown")+" />",i=" Did you accidentally export a JSX literal instead of a component?"):R=typeof e,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",R,i)}var w=ot(e,t,r,f,g);if(w==null)return w;if(c){var I=t.children;if(I!==void 0)if(o)if(ne(I)){for(var U=0;U<I.length;U++)De(I[U],e);Object.freeze&&Object.freeze(I)}else y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else De(I,e)}if(K.call(t,"key")){var L=M(e),D=Object.keys(t).filter(function(gt){return gt!=="key"}),ue=D.length>0?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}";if(!ke[L+ue]){var pt=D.length>0?"{"+D.join(": ..., ")+": ...}":"{}";y(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,ue,L,pt,L),ke[L+ue]=!0}}return e===s?ct(w):ut(w),w}}function lt(e,t,r){return Ie(e,t,r,!0)}function ft(e,t,r){return Ie(e,t,r,!1)}var dt=ft,vt=lt;q.Fragment=s,q.jsx=dt,q.jsxs=vt}()),q}process.env.NODE_ENV==="production"?ce.exports=ht():ce.exports=mt();var B=ce.exports;const Fe=n=>{let a;const d=new Set,s=(m,u)=>{const p=typeof m=="function"?m(a):m;if(!Object.is(p,a)){const C=a;a=u??(typeof p!="object"||p===null)?p:Object.assign({},a,p),d.forEach(E=>E(a,C))}},l=()=>a,b={setState:s,getState:l,getInitialState:()=>v,subscribe:m=>(d.add(m),()=>d.delete(m))},v=a=n(s,l,b);return b},bt=n=>n?Fe(n):Fe,yt=n=>n;function Et(n,a=yt){const d=h.useSyncExternalStore(n.subscribe,()=>a(n.getState()),()=>a(n.getInitialState()));return h.useDebugValue(d),d}const Le=n=>{const a=bt(n),d=s=>Et(a,s);return Object.assign(d,a),d},St=n=>n?Le(n):Le,Be=h.createContext(null),Rt=({children:n})=>{const d=h.useMemo(()=>St(s=>({selectedIndexes:new Set,setSelectedIndexes:l=>s({selectedIndexes:l}),focusedIndex:0,setFocusedIndex:l=>s({focusedIndex:l}),selectionOptions:{useCtrl:!0,useShift:!0,useCtrlShift:!0,useDrag:!0,useShiftToDrag:!1},setSelectionOptions:l=>s(O=>({selectionOptions:{...O.selectionOptions,...l}})),dragBoxElement:null,setDragBoxElement:l=>s({dragBoxElement:l}),isDragging:!1,setIsDragging:l=>s({isDragging:l})})),[])();return B.jsx(Be.Provider,{value:d,children:n})},V=()=>{const n=h.useContext(Be);if(!n)throw new Error("useSelectStore must be used within a SelectProvider");return n},_t="react-select-items-drag-box";function wt({position:n,size:a,className:d}){const{setDragBoxElement:s}=V();return B.jsx("div",{ref:s,className:d??_t,style:{position:"fixed",border:"1px dashed gray",left:n.x,top:n.y,width:a.width,height:a.height}})}function xt({useShift:n}){const a=h.useRef(null),{setIsDragging:d}=V(),[s,l]=h.useState(null),[O,_]=h.useState(null),[b,v]=h.useState(null),m=h.useRef(null),u=h.useRef(null),p=h.useCallback(E=>{var T,x;if(!a.current||n&&!E.shiftKey||((T=a.current)==null?void 0:T.x)===E.clientX&&((x=a.current)==null?void 0:x.y)===E.clientY||(d(!0),!s||!u.current))return;const j={x:Math.max(u.current.left,Math.min(E.clientX,u.current.right)),y:Math.max(u.current.top,Math.min(E.clientY,u.current.bottom))};_(Ot({dragStartPoint:s,dragEndPoint:j})),v(Ct({dragStartPoint:s,dragEndPoint:j}))},[s,d,n]),C=h.useCallback(()=>{l(null),_(null),v(null),a.current=null},[]);return h.useEffect(()=>{const E=m.current;if(!E)return;const j=T=>{a.current={x:T.clientX,y:T.clientY};const x=E.getBoundingClientRect();u.current=x;const k={x:Math.max(x.left,Math.min(T.clientX,x.right)),y:Math.max(x.top,Math.min(T.clientY,x.bottom))};l(k)};return E.addEventListener("mousedown",j),window.addEventListener("mousemove",p),window.addEventListener("mouseup",C),()=>{E.removeEventListener("mousedown",j),window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",C)}},[p,C]),{wrapperRef:m,dragBoxPosition:O,dragBoxSize:b}}function Ot({dragStartPoint:n,dragEndPoint:a}){return{x:Math.min(n.x,a.x),y:Math.min(n.y,a.y)}}function Ct({dragStartPoint:n,dragEndPoint:a}){return{width:Math.abs(a.x-n.x),height:Math.abs(a.y-n.y)}}function Ye(){const{selectedIndexes:n,setSelectedIndexes:a}=V(),d=h.useCallback(b=>{a(new Set([b]))},[a]),s=h.useCallback(b=>{a(new Set([...n,b]))},[n,a]),l=h.useCallback(b=>{a(new Set([...n].filter(v=>v!==b)))},[n,a]),O=h.useCallback(({startIndex:b,endIndex:v,append:m})=>{const u=m?new Set([...n]):new Set;for(let p=b;p<=v;p++)u.add(p);a(u)},[n,a]),_=h.useCallback(()=>{a(new Set)},[a]);return{selectOnlyOne:d,select:s,unselect:l,selectRange:O,unselectAll:_}}function Tt({onSelect:n,onUnselect:a,onFocus:d,options:s,dragBoxClassName:l,children:O}){const{selectedIndexes:_,focusedIndex:b,isDragging:v,setIsDragging:m,setSelectionOptions:u}=V(),p=h.useRef(_),{selectionOptions:C}=V(),{wrapperRef:E,dragBoxPosition:j,dragBoxSize:T}=xt({useShift:C.useShiftToDrag}),{unselectAll:x}=Ye();h.useEffect(()=>{s&&u(s)},[s,u]),h.useEffect(()=>{const y=p.current;_.forEach(S=>{y.has(S)||n(S)}),y.forEach(S=>{_.has(S)||a(S)}),d(b),p.current=_},[_,b]),h.useEffect(()=>{if(!E.current)return;const S=()=>{m(!1)};return window.addEventListener("mouseup",S),()=>{window.removeEventListener("mouseup",S)}},[m,E]);const k=y=>{y.target instanceof HTMLElement&&!y.target.closest(".temp")&&!v&&x(),m(!1)};return B.jsxs("div",{ref:E,onMouseUp:k,style:{width:"100%",height:"100%"},children:[j&&T&&B.jsx(wt,{position:{x:j.x,y:j.y},size:{width:T.width,height:T.height},className:l}),O]})}function Pt({onSelect:n=()=>{},onUnselect:a=()=>{},onFocus:d=()=>{},options:s,dragBoxClassName:l,children:O}){return B.jsx(Rt,{children:B.jsx(Tt,{onSelect:n,onUnselect:a,onFocus:d,options:s,dragBoxClassName:l,children:O})})}function jt({index:n,children:a}){const{selectOnlyOne:d,select:s,unselect:l,selectRange:O}=Ye(),{focusedIndex:_,setFocusedIndex:b,selectionOptions:v,selectedIndexes:m,dragBoxElement:u,setIsDragging:p}=V(),{useCtrl:C,useShift:E,useCtrlShift:j}=v,T=h.useRef(null),x=m.has(n),k=S=>{if(p(!1),b(n),C&&S.ctrlKey&&!S.shiftKey)x?l(n):s(n);else if(E&&S.shiftKey){const Y=Math.min(_,n),A=Math.max(_,n);O({startIndex:Y,endIndex:A,append:!!j&&S.ctrlKey})}else{if(m.size>1&&x)return;d(n)}},y=S=>{m.size>1&&x&&!S.ctrlKey&&!S.shiftKey&&d(n)};return h.useEffect(()=>{const S=T.current,Y=()=>{if(!u||!S)return;const A=u.getBoundingClientRect(),W=S.getBoundingClientRect(),J=!(A.right<W.left||A.left>W.right||A.bottom<W.top||A.top>W.bottom);J&&!x?s(n):!J&&x&&l(n)};return u&&window.addEventListener("mousemove",Y),()=>{window.removeEventListener("mousemove",Y)}},[u,n,x,s,l]),B.jsx("div",{ref:T,onMouseDown:k,onMouseUp:y,className:"temp",children:a})}exports.SelectArea=Pt;exports.Selectable=jt;