@bbodek/hooks 0.0.17 → 0.0.18
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/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useResponsible/constants/index.d.ts +11 -0
- package/dist/hooks/useResponsible/constants/index.d.ts.map +1 -0
- package/dist/hooks/useResponsible/effects/useResponsibleStatusEffect.d.ts +4 -0
- package/dist/hooks/useResponsible/effects/useResponsibleStatusEffect.d.ts.map +1 -0
- package/dist/hooks/useResponsible/effects/useSetResponsibleStatusEffect.d.ts +1 -0
- package/dist/hooks/useResponsible/effects/useSetResponsibleStatusEffect.d.ts.map +1 -0
- package/dist/hooks/useResponsible/index.d.ts +4 -0
- package/dist/hooks/useResponsible/index.d.ts.map +1 -0
- package/dist/hooks/useResponsible/types/index.d.ts +7 -0
- package/dist/hooks/useResponsible/types/index.d.ts.map +1 -0
- package/dist/hooks/useResponsible/useResponsible.d.ts +6 -0
- package/dist/hooks/useResponsible/useResponsible.d.ts.map +1 -0
- package/dist/index.es.js +1 -1
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const RESPONSIBLE_STATUS: {
|
|
2
|
+
readonly MOBILE: "MOBILE";
|
|
3
|
+
readonly TABLET: "TABLET";
|
|
4
|
+
readonly DESKTOP: "DESKTOP";
|
|
5
|
+
};
|
|
6
|
+
export declare const BREAKPOINT_SIZE: {
|
|
7
|
+
readonly MOBILE: 360;
|
|
8
|
+
readonly TABLET: 820;
|
|
9
|
+
readonly DESKTOP: 1180;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useResponsible/constants/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB;;;;CAIrB,CAAC;AAEX,eAAO,MAAM,eAAe;;;;CAIlB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UseResponsibleStatusEffectParams } from '../../../hooks/useResponsible/types';
|
|
2
|
+
declare const useResponsibleStatusEffect: ({ setStatus, }: UseResponsibleStatusEffectParams) => void;
|
|
3
|
+
export default useResponsibleStatusEffect;
|
|
4
|
+
//# sourceMappingURL=useResponsibleStatusEffect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useResponsibleStatusEffect.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useResponsible/effects/useResponsibleStatusEffect.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAEhF,QAAA,MAAM,0BAA0B,GAAI,gBAEjC,gCAAgC,SA0BlC,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=useSetResponsibleStatusEffect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSetResponsibleStatusEffect.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useResponsible/effects/useSetResponsibleStatusEffect.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useResponsible/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { RESPONSIBLE_STATUS } from '../../../hooks/useResponsible/constants';
|
|
3
|
+
export type ResponsibleStatus = (typeof RESPONSIBLE_STATUS)[keyof typeof RESPONSIBLE_STATUS];
|
|
4
|
+
export interface UseResponsibleStatusEffectParams {
|
|
5
|
+
setStatus: Dispatch<SetStateAction<ResponsibleStatus | null>>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useResponsible/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE/D,MAAM,WAAW,gCAAgC;IAC/C,SAAS,EAAE,QAAQ,CAAC,cAAc,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC;CAC/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useResponsible.d.ts","sourceRoot":"","sources":["../../../src/hooks/useResponsible/useResponsible.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,QAAA,MAAM,cAAc;;CAMnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as e,useEffect as t,useLayoutEffect as r,useCallback as n,useMemo as i,useReducer as
|
|
1
|
+
import{useRef as e,useEffect as t,useLayoutEffect as r,useCallback as n,useMemo as i,useReducer as s,useState as a}from"react";import{composeEventHandler as l,ACCEPT_FILES as c,executeFunction as o,getUUID as d}from"@bbodek/utils";const E=r=>{const n=e(!0);t((()=>{n.current&&(n.current=!1,r())}),[])},p="undefined"!=typeof window?r:t,u=({isLocked:e,target:r})=>{t((()=>{const t=r?document.getElementById(r):document.body;if(t)return t.style.overflow=e?"hidden":"auto",()=>{t.style.overflow="auto"}}),[e,r])},v=({ref:e,onClose:r,useClickOutsideEvent:n=!0})=>{t((()=>{const t=t=>{e.current&&!e.current.contains(t.target)&&r(t)};return n?document.addEventListener("mousedown",t):document.removeEventListener("mousedown",t),()=>{n&&document.removeEventListener("mousedown",t)}}),[e.current,n])},L=({onClose:t,useClickOutsideEvent:r})=>{const n=e(null);return v({ref:n,onClose:t,useClickOutsideEvent:r}),{contentRef:n}},F=()=>({compose:n((e=>l(e)),[])}),f={DRAG:"drag",HOVER:"hover",SET_FILES:"setFiles",SET_REJECT:"setReject",DELETE_FILE:"deleteFile",RESET_FILES:"resetFiles"},T={SINGLE_FILE_ONLY:"SINGLE_FILE_ONLY",TOO_MANY_FILES:"TOO_MANY_FILES",NEED_ACTIVE_MULTIPLE_OPTION:"NEED_ACTIVE_MULTIPLE_OPTION",INVALID_FILE_FORMAT:"INVALID_FILE_FORMAT"},D={[T.SINGLE_FILE_ONLY]:"한 개의 파일만 선택할 수 있어요",[T.TOO_MANY_FILES]:"너무 많은 파일이 선택되었어요",[T.NEED_ACTIVE_MULTIPLE_OPTION]:"다중 선택 옵션을 활성화 시켜주세요",[T.INVALID_FILE_FORMAT]:"지원하지 않는 형식의 파일이 있어요"},I=({url:e})=>Array.isArray(e)?e.forEach((e=>URL.revokeObjectURL(e))):URL.revokeObjectURL(e),_=({accept:e=c})=>e.join(","),A=()=>({execute:n((e=>o(e)),[])}),O={isDragActive:!1,isHover:!1,isActive:!1,acceptedFiles:[],rejectedFiles:void 0},m=(e,t)=>{switch(t.type){case f.DRAG:return{...e,isDragActive:t.isDragActive??e.isDragActive,isActive:t.isDragActive??e.isDragActive};case f.HOVER:return{...e,isHover:t.isHover??e.isHover,isActive:t.isHover??e.isHover};case f.SET_FILES:return{...e,acceptedFiles:t.acceptedFiles??e.acceptedFiles,rejectedFiles:void 0,isDragActive:!1,isHover:!1,isActive:!1};case f.SET_REJECT:return{...e,rejectedFiles:t.rejectedFiles??e.rejectedFiles,isDragActive:!1,isHover:!1,isActive:!1};case f.DELETE_FILE:return{...e,acceptedFiles:e.acceptedFiles.filter((e=>e.id!==t.id))};case f.RESET_FILES:return{...e,acceptedFiles:[]};default:return e}},R=t=>{const{multiple:r=!0,limit:a,disabled:l=!1,onDrop:o,onDropAccepted:p,onDropRejected:u,accept:v=c}=t,{state:L,dispatch:D}=(()=>{const[e,t]=s(m,O);return{state:e,dispatch:t}})(),{handleUpload:R,deleteFile:g,resetFiles:h}=(({uploadedFiles:e,state:t,dispatch:r,multiple:n=!0,limit:i,onDrop:s,onDropAccepted:a,onDropRejected:l,accept:o=c})=>{const E=e=>{const{name:t,size:r,type:n,lastModified:i,webkitRelativePath:s}=e;return{id:d(),name:t,size:r,type:n,lastModified:i,webkitRelativePath:s,blob:URL.createObjectURL(e),original:e}},p=({acceptedFiles:e,rejectCode:n})=>{const i={files:e,code:n};r({type:f.SET_REJECT,acceptedFiles:e,rejectedFiles:i}),l?.({rejectedFiles:i,state:t,dispatch:r}),s?.({acceptedFiles:[],rejectedFiles:i,state:t,dispatch:r})};return{handleUpload:({files:e})=>{const l=Array.from(e,E);if(!n&&l.length>1)return p({acceptedFiles:l,rejectCode:T.SINGLE_FILE_ONLY});if(void 0!==i){if(!n)return p({acceptedFiles:l,rejectCode:T.NEED_ACTIVE_MULTIPLE_OPTION});if(l.length>i)return p({acceptedFiles:l,rejectCode:T.TOO_MANY_FILES})}if(l.some((e=>["type","name"].every((t=>!o.some((r=>e[t].toLowerCase().includes(r))))))))return p({acceptedFiles:l,rejectCode:T.INVALID_FILE_FORMAT});r({type:f.SET_FILES,acceptedFiles:l}),a?.({acceptedFiles:l,state:t,dispatch:r}),s?.({acceptedFiles:l,state:t,dispatch:r})},deleteFile:({id:e})=>{r({type:f.DELETE_FILE,id:e})},resetFiles:()=>{I({url:e.map((e=>e.blob))}),r({type:f.RESET_FILES})}}})({uploadedFiles:L.acceptedFiles,state:L,dispatch:D,multiple:r,limit:a,onDrop:o,onDropAccepted:p,onDropRejected:u,accept:v}),{inputProps:H,inputRef:S}=(({multiple:t=!0,accept:r=c,disabled:s=!1,handleUpload:a})=>{const l=e(null),{execute:o}=A(),{compose:d}=F(),E=n((e=>{if(e.preventDefault(),!e.target||!e.target.files)return;const{files:t}=e.target;a({files:t})}),[a]);return{inputProps:i((()=>({onChange:e,...n}={})=>({multiple:t,type:"file",style:{display:"none"},tabIndex:-1,ref:l,onChange:o({disabled:s,fn:d({externalEventHandler:e,internalEventHandler:E})}),accept:_({accept:r}),disabled:s,...n})),[t,r,l,E,s,o,d]),inputRef:l}})({disabled:l,handleUpload:R,multiple:r,accept:v}),{rootProps:b}=(({inputRef:t,dispatch:r,disabled:s=!1,handleUpload:a})=>{const l=e(null),{execute:c}=A(),{compose:o}=F(),d=i((()=>e=>e.relatedTarget instanceof Node&&l.current&&l.current.contains(e.relatedTarget)),[l.current]),E=n((()=>r({type:f.HOVER,isHover:!0})),[r]),p=n((e=>{d(e)||r({type:f.HOVER,isHover:!1})}),[r,d]),u=n((e=>{e.preventDefault(),r({type:f.DRAG,isDragActive:!0})}),[r]),v=n((e=>{e.preventDefault(),d(e)||r({type:f.DRAG,isDragActive:!1})}),[r,d]),L=n((e=>e.preventDefault()),[]),T=n((e=>{if(e.preventDefault(),!e.dataTransfer||!e.dataTransfer.files)return;const{files:t}=e.dataTransfer;a({files:t})}),[a]),D=n((()=>{t.current&&(t.current.value="",t.current.click())}),[t.current]);return{rootProps:i((()=>({onDrop:e,onClick:t,onDragEnter:r,onDragLeave:n,onDragOver:i,onMouseEnter:a,onMouseLeave:d,role:F,...f}={})=>({onDrop:c({disabled:s,fn:o({externalEventHandler:e,internalEventHandler:T})}),onClick:c({disabled:s,fn:o({externalEventHandler:t,internalEventHandler:D})}),onDragEnter:c({disabled:s,fn:o({externalEventHandler:r,internalEventHandler:u})}),onDragLeave:c({disabled:s,fn:o({externalEventHandler:n,internalEventHandler:v})}),onDragOver:c({disabled:s,fn:o({externalEventHandler:i,internalEventHandler:L})}),onMouseEnter:c({disabled:s,fn:o({externalEventHandler:a,internalEventHandler:E})}),onMouseLeave:c({disabled:s,fn:o({externalEventHandler:d,internalEventHandler:p})}),role:"string"==typeof F&&""!==F?F:"presentation",ref:l,...f})),[T,D,u,v,L,E,p,l,s,c,o])}})({inputRef:S,dispatch:D,disabled:l,handleUpload:R});return(({acceptedFiles:e})=>{E((()=>{I({url:e.map((e=>e.blob))})}))})({acceptedFiles:L.acceptedFiles}),{state:L,deleteFile:g,resetFiles:h,rootProps:b,inputProps:H,dispatch:D}},g=({initialValues:e,validate:t})=>{const[r,n]=a(e),[i,s]=a({});return{values:r,setValues:e=>{const i="function"==typeof e?e(r):e;if(n(i),t){const e=t(i);s(e)}},errors:i,handleChange:i=>{const{name:a,value:l}=i.target;if(a in e&&(n({...r,[a]:l}),t)){const e=t({...r,[a]:l});s(e)}},setErrors:s}},h={MOBILE:"MOBILE",TABLET:"TABLET",DESKTOP:"DESKTOP"},H={[h.MOBILE]:360,[h.TABLET]:820,[h.DESKTOP]:1180},S=()=>{const[e,r]=a(null);return(({setStatus:e})=>{t((()=>{const t=()=>{const t=window.innerWidth;e(t>=H.DESKTOP?h.DESKTOP:t>=H.TABLET?h.TABLET:h.MOBILE)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}}),[])})({setStatus:r}),{status:e}};export{H as BREAKPOINT_SIZE,f as DROPZONE_ACTION_MAPPER,T as DROPZONE_REJECT_CODE_MAPPER,D as DROPZONE_REJECT_MESSAGE,h as RESPONSIBLE_STATUS,v as useClickOutSideEffect,L as useClickOutside,F as useComposeEventHandler,R as useDropzone,A as useExecuteFunction,E as useFirstRenderEffect,g as useForm,p as useIsomorphicLayoutEffect,S as useResponsible,u as useScrollLockEffect};
|
|
2
2
|
//# sourceMappingURL=index.es.js.map
|