@alessiofrittoli/react-hooks 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -87,7 +87,7 @@
87
87
  - [`useTimeout`](#usetimeout)
88
88
  - [`useLightTimeout`](#uselighttimeout)
89
89
  - [Development](#development)
90
- - [Install depenendencies](#install-depenendencies)
90
+ - [Install dependencies](#install-dependencies)
91
91
  - [Build the source code](#build-the-source-code)
92
92
  - [ESLint](#eslint)
93
93
  - [Jest](#jest)
@@ -3082,7 +3082,7 @@ const MyComponent: React.FC = () => {
3082
3082
 
3083
3083
  ### Development
3084
3084
 
3085
- #### Install depenendencies
3085
+ #### Install dependencies
3086
3086
 
3087
3087
  ```bash
3088
3088
  npm install
@@ -3104,7 +3104,7 @@ pnpm build
3104
3104
 
3105
3105
  #### [ESLint](https://www.npmjs.com/package/eslint)
3106
3106
 
3107
- warnings / errors check.
3107
+ Run warnings and errors checks.
3108
3108
 
3109
3109
  ```bash
3110
3110
  pnpm lint
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkSV2TCLLEjs = require('../../chunk-SV2TCLLE.js');var _react = require('react');var _webutils = require('@alessiofrittoli/web-utils');var M=()=>{let[F,v]=_react.useState.call(void 0, !1),[I,x]=_react.useState.call(void 0, ),h=_react.useRef.call(void 0, !1),U=_react.useCallback.call(void 0, (s,a)=>{let{items:l}=s;if(l.length<=1)return s;v(!0),h.current||x(l.map(({uuid:p})=>p)),h.current=!0;let f=_chunkSV2TCLLEjs.e.call(void 0, l,a),c=l.slice(0,f+1),n=l.slice(f+1);return n.length<=1?s:{...s,items:[...c,..._webutils.shuffle.call(void 0, n)]}},[]),g=_react.useCallback.call(void 0, (s,a)=>{if(!I)return s;v(!1);let{items:l}=s,f=new Map(I.map((m,u)=>[m,u]));h.current=!1;let c=_chunkSV2TCLLEjs.e.call(void 0, l,a),n=l.slice(0,c+1),b=[...l.slice(c+1)].sort((m,u)=>(_nullishCoalesce(f.get(m.uuid), () => (0)))-(_nullishCoalesce(f.get(u.uuid), () => (0))));return x(void 0),{...s,items:[...n,...b]}},[I]),S=_react.useCallback.call(void 0, (s,a)=>h.current?g(s,a):U(s,a),[U,g]);return{enabled:F,shuffle:U,unshuffle:g,toggleShuffle:S}};var pe=F=>{let{queue:v,repeat:I=!0,current:x}=F,{enabled:h,shuffle:U,unshuffle:g,toggleShuffle:S}=M(),[s,a]=_react.useState.call(void 0, I),l=_react.useCallback.call(void 0, ()=>a(e=>!e),[]),[f,c]=_react.useState.call(void 0, v),[n,p]=_react.useState.call(void 0, []),[b,m]=_react.useState.call(void 0, x),[u,N]=_react.useState.call(void 0, _optionalChain([x, 'optionalAccess', _2 => _2.uuid])),t=f.items,T=_optionalChain([b, 'optionalAccess', _3 => _3.uuid]),A=_react.useMemo.call(void 0, ()=>_chunkSV2TCLLEjs.f.call(void 0, {queue:t,customQueue:n,uuid:T}),[t,n,T]),B=_react.useMemo.call(void 0, ()=>t.length<=0?!1:s?!0:u?_chunkSV2TCLLEjs.e.call(void 0, t,u)>0:t.length>0,[t,u,s]),z=_react.useMemo.call(void 0, ()=>n.length>0?!0:t.length<=0?!1:s?!0:u?_chunkSV2TCLLEjs.e.call(void 0, t,u)<t.length-1:t.length>0,[t,n,u,s]),O=_react.useCallback.call(void 0, e=>{let r={...e,items:_chunkSV2TCLLEjs.d.call(void 0, e.items)};return c(r),r},[]),G=_react.useCallback.call(void 0, e=>p(r=>[...r,..._chunkSV2TCLLEjs.b.call(void 0, e)]),[]),K=_react.useCallback.call(void 0, e=>{let r=o=>o.uuid===e,Q=o=>o.uuid!==e;c(o=>o.items.find(r)?{...o,items:o.items.filter(Q)}:o),p(o=>o.find(r)?o.filter(Q):o)},[]),L=_react.useCallback.call(void 0, ()=>p([]),[]),W=_react.useCallback.call(void 0, ({uuid:e,queue:r})=>{let Q=r?O(r).items:t;if(n.length>0){let w=_chunkSV2TCLLEjs.e.call(void 0, n,e);if(w>=0){let H=n.at(w);return m(H),p(n.slice(w+1)),H}}let o=e?_chunkSV2TCLLEjs.e.call(void 0, Q,e):0,E=Q[o];return m(E),N(_optionalChain([E, 'optionalAccess', _4 => _4.uuid])),E},[t,n,O]),P=_react.useCallback.call(void 0, ()=>{if(!T)return t.at(-1);let e=!!t.find(o=>o.uuid===T),r=_chunkSV2TCLLEjs.e.call(void 0, t,e?T:u);return t.at(e?_webutils.getPreviousIndex.call(void 0, t.length,r):r)},[T,u,t]),X=_react.useCallback.call(void 0, ()=>{let e=P();return m(e),N(_optionalChain([e, 'optionalAccess', _5 => _5.uuid])),e},[P]),R=_react.useCallback.call(void 0, ()=>{if(n.length>0)return n.at(0);let e=_chunkSV2TCLLEjs.e.call(void 0, f.items,u);return f.items.at(_webutils.getNextIndex.call(void 0, f.items.length,e))},[f,n,u]),Y=_react.useCallback.call(void 0, ()=>{if(n.length>0){let[r,...Q]=n;return m(r),p(Q),r}let e=R();return m(e),N(_optionalChain([e, 'optionalAccess', _6 => _6.uuid])),e},[n,R]),Z=_react.useCallback.call(void 0, ()=>c(e=>U(e,u)),[u,U]),_=_react.useCallback.call(void 0, ()=>c(e=>g(e,u)),[u,g]),$=_react.useCallback.call(void 0, ()=>c(e=>S(e,u)),[u,S]),ee=_react.useMemo.call(void 0, ()=>u?t.slice(_chunkSV2TCLLEjs.e.call(void 0, t,u)+1):t,[t,u]);return{queue:f,currentId:T,current:b,customQueue:n,effectiveQueue:A,nextFromQueue:ee,hasPrevious:B,hasNext:z,isShuffleEnabled:h,shuffle:Z,unshuffle:_,toggleShuffle:$,isRepeatEnabled:s,toggleRepeat:l,jumpTo:W,getPrevious:P,previous:X,getNext:R,next:Y,setQueue:O,addToQueue:G,removeFromQueue:K,clearQueue:L}};exports.useQueue = pe; exports.useShuffle = M;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkSV2TCLLEjs = require('../../chunk-SV2TCLLE.js');var _react = require('react');var _webutils = require('@alessiofrittoli/web-utils');var M=()=>{let[F,v]=_react.useState.call(void 0, !1),[I,x]=_react.useState.call(void 0, ),h=_react.useRef.call(void 0, !1),U=_react.useCallback.call(void 0, (s,a)=>{let{items:l}=s;if(l.length<=1)return s;v(!0),h.current||x(l.map(({uuid:p})=>p)),h.current=!0;let f=_chunkSV2TCLLEjs.e.call(void 0, l,a),c=l.slice(0,f+1),n=l.slice(f+1);return n.length<=1?s:{...s,items:[...c,..._webutils.shuffle.call(void 0, n)]}},[]),g=_react.useCallback.call(void 0, (s,a)=>{if(!I)return s;v(!1);let{items:l}=s,f=new Map(I.map((m,u)=>[m,u]));h.current=!1;let c=_chunkSV2TCLLEjs.e.call(void 0, l,a),n=l.slice(0,c+1),b=[...l.slice(c+1)].sort((m,u)=>(_nullishCoalesce(f.get(m.uuid), () => (0)))-(_nullishCoalesce(f.get(u.uuid), () => (0))));return x(void 0),{...s,items:[...n,...b]}},[I]),S=_react.useCallback.call(void 0, (s,a)=>h.current?g(s,a):U(s,a),[U,g]);return{enabled:F,shuffle:U,unshuffle:g,toggleShuffle:S}};var pe=F=>{let{queue:v,repeat:I=!0,current:x}=F,{enabled:h,shuffle:U,unshuffle:g,toggleShuffle:S}=M(),[s,a]=_react.useState.call(void 0, I),l=_react.useCallback.call(void 0, ()=>a(e=>!e),[]),[f,c]=_react.useState.call(void 0, v),[n,p]=_react.useState.call(void 0, []),[b,m]=_react.useState.call(void 0, x),[u,N]=_react.useState.call(void 0, _optionalChain([x, 'optionalAccess', _2 => _2.uuid])),t=f.items,T=_optionalChain([b, 'optionalAccess', _3 => _3.uuid]),A=_react.useMemo.call(void 0, ()=>_chunkSV2TCLLEjs.f.call(void 0, {queue:t,customQueue:n,uuid:T}),[t,n,T]),B=_react.useMemo.call(void 0, ()=>t.length<=0?!1:s?!0:u?_chunkSV2TCLLEjs.e.call(void 0, t,u)>0:t.length>0,[t,u,s]),z=_react.useMemo.call(void 0, ()=>n.length>0?!0:t.length<=0?!1:s?!0:u?_chunkSV2TCLLEjs.e.call(void 0, t,u)<t.length-1:t.length>0,[t,n,u,s]),O=_react.useCallback.call(void 0, e=>{let r={...e,items:_chunkSV2TCLLEjs.d.call(void 0, e.items)};return c(r),r},[]),G=_react.useCallback.call(void 0, e=>p(r=>[...r,..._chunkSV2TCLLEjs.b.call(void 0, e)]),[]),K=_react.useCallback.call(void 0, e=>{let r=o=>o.uuid===e,Q=o=>o.uuid!==e;c(o=>o.items.find(r)?{...o,items:o.items.filter(Q)}:o),p(o=>o.find(r)?o.filter(Q):o)},[]),L=_react.useCallback.call(void 0, ()=>p([]),[]),W=_react.useCallback.call(void 0, ({uuid:e,queue:r})=>{let Q=r?O(r).items:t;if(n.length>0){let w=_chunkSV2TCLLEjs.e.call(void 0, n,e);if(w>=0){let H=n.at(w);return m(H),p(n.slice(w+1)),H}}let o=e?_chunkSV2TCLLEjs.e.call(void 0, Q,e):0,E=Q[o===-1?0:o];return m(E),N(_optionalChain([E, 'optionalAccess', _4 => _4.uuid])),E},[t,n,O]),P=_react.useCallback.call(void 0, ()=>{if(!T)return t.at(-1);let e=!!t.find(o=>o.uuid===T),r=_chunkSV2TCLLEjs.e.call(void 0, t,e?T:u);return t.at(e?_webutils.getPreviousIndex.call(void 0, t.length,r):r)},[T,u,t]),X=_react.useCallback.call(void 0, ()=>{let e=P();return m(e),N(_optionalChain([e, 'optionalAccess', _5 => _5.uuid])),e},[P]),R=_react.useCallback.call(void 0, ()=>{if(n.length>0)return n.at(0);let e=_chunkSV2TCLLEjs.e.call(void 0, f.items,u);return f.items.at(_webutils.getNextIndex.call(void 0, f.items.length,e))},[f,n,u]),Y=_react.useCallback.call(void 0, ()=>{if(n.length>0){let[r,...Q]=n;return m(r),p(Q),r}let e=R();return m(e),N(_optionalChain([e, 'optionalAccess', _6 => _6.uuid])),e},[n,R]),Z=_react.useCallback.call(void 0, ()=>c(e=>U(e,u)),[u,U]),_=_react.useCallback.call(void 0, ()=>c(e=>g(e,u)),[u,g]),$=_react.useCallback.call(void 0, ()=>c(e=>S(e,u)),[u,S]),ee=_react.useMemo.call(void 0, ()=>u?t.slice(_chunkSV2TCLLEjs.e.call(void 0, t,u)+1):t,[t,u]);return{queue:f,currentId:T,current:b,customQueue:n,effectiveQueue:A,nextFromQueue:ee,hasPrevious:B,hasNext:z,isShuffleEnabled:h,shuffle:Z,unshuffle:_,toggleShuffle:$,isRepeatEnabled:s,toggleRepeat:l,jumpTo:W,getPrevious:P,previous:X,getNext:R,next:Y,setQueue:O,addToQueue:G,removeFromQueue:K,clearQueue:L}};exports.useQueue = pe; exports.useShuffle = M;
@@ -1 +1 @@
1
- import{b as V,d as J,e as d,f as j}from"../../chunk-OXQJOVCZ.mjs";import{useCallback as i,useMemo as D,useState as y}from"react";import{getNextIndex as se,getPreviousIndex as re}from"@alessiofrittoli/web-utils";import{useCallback as C,useRef as te,useState as k}from"react";import{shuffle as ne}from"@alessiofrittoli/web-utils";var A=()=>{let[F,v]=k(!1),[I,x]=k(),h=te(!1),U=C((s,a)=>{let{items:l}=s;if(l.length<=1)return s;v(!0),h.current||x(l.map(({uuid:p})=>p)),h.current=!0;let f=d(l,a),c=l.slice(0,f+1),n=l.slice(f+1);return n.length<=1?s:{...s,items:[...c,...ne(n)]}},[]),g=C((s,a)=>{if(!I)return s;v(!1);let{items:l}=s,f=new Map(I.map((m,u)=>[m,u]));h.current=!1;let c=d(l,a),n=l.slice(0,c+1),b=[...l.slice(c+1)].sort((m,u)=>(f.get(m.uuid)??0)-(f.get(u.uuid)??0));return x(void 0),{...s,items:[...n,...b]}},[I]),S=C((s,a)=>h.current?g(s,a):U(s,a),[U,g]);return{enabled:F,shuffle:U,unshuffle:g,toggleShuffle:S}};var Qe=F=>{let{queue:v,repeat:I=!0,current:x}=F,{enabled:h,shuffle:U,unshuffle:g,toggleShuffle:S}=A(),[s,a]=y(I),l=i(()=>a(e=>!e),[]),[f,c]=y(v),[n,p]=y([]),[b,m]=y(x),[u,N]=y(x?.uuid),t=f.items,T=b?.uuid,B=D(()=>j({queue:t,customQueue:n,uuid:T}),[t,n,T]),z=D(()=>t.length<=0?!1:s?!0:u?d(t,u)>0:t.length>0,[t,u,s]),G=D(()=>n.length>0?!0:t.length<=0?!1:s?!0:u?d(t,u)<t.length-1:t.length>0,[t,n,u,s]),O=i(e=>{let r={...e,items:J(e.items)};return c(r),r},[]),K=i(e=>p(r=>[...r,...V(e)]),[]),L=i(e=>{let r=o=>o.uuid===e,Q=o=>o.uuid!==e;c(o=>o.items.find(r)?{...o,items:o.items.filter(Q)}:o),p(o=>o.find(r)?o.filter(Q):o)},[]),W=i(()=>p([]),[]),X=i(({uuid:e,queue:r})=>{let Q=r?O(r).items:t;if(n.length>0){let w=d(n,e);if(w>=0){let H=n.at(w);return m(H),p(n.slice(w+1)),H}}let o=e?d(Q,e):0,E=Q[o];return m(E),N(E?.uuid),E},[t,n,O]),P=i(()=>{if(!T)return t.at(-1);let e=!!t.find(o=>o.uuid===T),r=d(t,e?T:u);return t.at(e?re(t.length,r):r)},[T,u,t]),Y=i(()=>{let e=P();return m(e),N(e?.uuid),e},[P]),R=i(()=>{if(n.length>0)return n.at(0);let e=d(f.items,u);return f.items.at(se(f.items.length,e))},[f,n,u]),Z=i(()=>{if(n.length>0){let[r,...Q]=n;return m(r),p(Q),r}let e=R();return m(e),N(e?.uuid),e},[n,R]),_=i(()=>c(e=>U(e,u)),[u,U]),$=i(()=>c(e=>g(e,u)),[u,g]),ee=i(()=>c(e=>S(e,u)),[u,S]),ue=D(()=>u?t.slice(d(t,u)+1):t,[t,u]);return{queue:f,currentId:T,current:b,customQueue:n,effectiveQueue:B,nextFromQueue:ue,hasPrevious:z,hasNext:G,isShuffleEnabled:h,shuffle:_,unshuffle:$,toggleShuffle:ee,isRepeatEnabled:s,toggleRepeat:l,jumpTo:X,getPrevious:P,previous:Y,getNext:R,next:Z,setQueue:O,addToQueue:K,removeFromQueue:L,clearQueue:W}};export{Qe as useQueue,A as useShuffle};
1
+ import{b as V,d as J,e as d,f as j}from"../../chunk-OXQJOVCZ.mjs";import{useCallback as i,useMemo as D,useState as y}from"react";import{getNextIndex as se,getPreviousIndex as re}from"@alessiofrittoli/web-utils";import{useCallback as C,useRef as te,useState as k}from"react";import{shuffle as ne}from"@alessiofrittoli/web-utils";var A=()=>{let[F,v]=k(!1),[I,x]=k(),h=te(!1),U=C((s,a)=>{let{items:l}=s;if(l.length<=1)return s;v(!0),h.current||x(l.map(({uuid:p})=>p)),h.current=!0;let f=d(l,a),c=l.slice(0,f+1),n=l.slice(f+1);return n.length<=1?s:{...s,items:[...c,...ne(n)]}},[]),g=C((s,a)=>{if(!I)return s;v(!1);let{items:l}=s,f=new Map(I.map((m,u)=>[m,u]));h.current=!1;let c=d(l,a),n=l.slice(0,c+1),b=[...l.slice(c+1)].sort((m,u)=>(f.get(m.uuid)??0)-(f.get(u.uuid)??0));return x(void 0),{...s,items:[...n,...b]}},[I]),S=C((s,a)=>h.current?g(s,a):U(s,a),[U,g]);return{enabled:F,shuffle:U,unshuffle:g,toggleShuffle:S}};var Qe=F=>{let{queue:v,repeat:I=!0,current:x}=F,{enabled:h,shuffle:U,unshuffle:g,toggleShuffle:S}=A(),[s,a]=y(I),l=i(()=>a(e=>!e),[]),[f,c]=y(v),[n,p]=y([]),[b,m]=y(x),[u,N]=y(x?.uuid),t=f.items,T=b?.uuid,B=D(()=>j({queue:t,customQueue:n,uuid:T}),[t,n,T]),z=D(()=>t.length<=0?!1:s?!0:u?d(t,u)>0:t.length>0,[t,u,s]),G=D(()=>n.length>0?!0:t.length<=0?!1:s?!0:u?d(t,u)<t.length-1:t.length>0,[t,n,u,s]),O=i(e=>{let r={...e,items:J(e.items)};return c(r),r},[]),K=i(e=>p(r=>[...r,...V(e)]),[]),L=i(e=>{let r=o=>o.uuid===e,Q=o=>o.uuid!==e;c(o=>o.items.find(r)?{...o,items:o.items.filter(Q)}:o),p(o=>o.find(r)?o.filter(Q):o)},[]),W=i(()=>p([]),[]),X=i(({uuid:e,queue:r})=>{let Q=r?O(r).items:t;if(n.length>0){let w=d(n,e);if(w>=0){let H=n.at(w);return m(H),p(n.slice(w+1)),H}}let o=e?d(Q,e):0,E=Q[o===-1?0:o];return m(E),N(E?.uuid),E},[t,n,O]),P=i(()=>{if(!T)return t.at(-1);let e=!!t.find(o=>o.uuid===T),r=d(t,e?T:u);return t.at(e?re(t.length,r):r)},[T,u,t]),Y=i(()=>{let e=P();return m(e),N(e?.uuid),e},[P]),R=i(()=>{if(n.length>0)return n.at(0);let e=d(f.items,u);return f.items.at(se(f.items.length,e))},[f,n,u]),Z=i(()=>{if(n.length>0){let[r,...Q]=n;return m(r),p(Q),r}let e=R();return m(e),N(e?.uuid),e},[n,R]),_=i(()=>c(e=>U(e,u)),[u,U]),$=i(()=>c(e=>g(e,u)),[u,g]),ee=i(()=>c(e=>S(e,u)),[u,S]),ue=D(()=>u?t.slice(d(t,u)+1):t,[t,u]);return{queue:f,currentId:T,current:b,customQueue:n,effectiveQueue:B,nextFromQueue:ue,hasPrevious:z,hasNext:G,isShuffleEnabled:h,shuffle:_,unshuffle:$,toggleShuffle:ee,isRepeatEnabled:s,toggleRepeat:l,jumpTo:X,getPrevious:P,previous:Y,getNext:R,next:Z,setQueue:O,addToQueue:K,removeFromQueue:L,clearQueue:W}};export{Qe as useQueue,A as useShuffle};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessiofrittoli/react-hooks",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "TypeScript React utility Hooks",
5
5
  "author": {
6
6
  "name": "Alessio Frittoli",