@primereact/hooks 11.0.0-alpha.4 → 11.0.0-alpha.5
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/index.d.ts +2 -0
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/use-key-filter/index.d.ts +42 -0
- package/use-key-filter/index.mjs +2 -0
- package/use-key-filter/index.mjs.map +1 -0
- package/use-key-filter/index.test.d.ts +0 -0
- package/use-mask/index.d.ts +109 -0
- package/use-mask/index.mjs +2 -0
- package/use-mask/index.mjs.map +1 -0
- package/use-mask/index.test.d.ts +0 -0
package/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export * from './use-attr-selector';
|
|
|
2
2
|
export * from './use-controlled-state';
|
|
3
3
|
export * from './use-event-listener';
|
|
4
4
|
export * from './use-id';
|
|
5
|
+
export * from './use-key-filter';
|
|
6
|
+
export * from './use-mask';
|
|
5
7
|
export * from './use-match-media';
|
|
6
8
|
export * from './use-mount-effect';
|
|
7
9
|
export * from './use-previous';
|
package/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var ve=Object.defineProperty;var W=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var X=(u,s,c)=>s in u?ve(u,s,{enumerable:!0,configurable:!0,writable:!0,value:c}):u[s]=c,Y=(u,s)=>{for(var c in s||(s={}))be.call(s,c)&&X(u,c,s[c]);if(W)for(var c of W(s))Te.call(s,c)&&X(u,c,s[c]);return u};import*as S from"react";function xe(u=""){let s=S.useId();return S.useMemo(()=>`${u}${s.replaceAll(/:|«|»/g,"")}`.trim().toLowerCase(),[s,u])}import{resolve as Me}from"@primeuix/utils";import*as F from"react";function He({value:u,defaultValue:s,onChange:c}){let[p,m]=F.useState(s!=null?s:u),d=u!==void 0,R=d?u:p,o=F.useCallback(l=>{let[f,a]=Me(l,R,d);c==null||c(a),d||m(f)},[R,d,c]);return[R,o,d]}import{getTargetElement as ee,isNotEmpty as he}from"@primeuix/utils";import*as L from"react";import*as D from"react";function N(u){let s=D.useRef(null);return D.useEffect(()=>(s.current=u,()=>{s.current=null}),[u]),s.current}function Ue({target:u="document",type:s,listener:c,options:p,when:m=!0}){let d=L.useRef(null),R=L.useRef(null),o=N(c),l=N(p),f=(v={})=>{let{target:I}=v;he(I)&&(a(),(v.when||m)&&(d.current=ee(I))),!R.current&&d.current&&(R.current=h=>c&&c(h),d.current.addEventListener(s,R.current,p))},a=()=>{var v;R.current&&((v=d.current)==null||v.removeEventListener(s,R.current,p),R.current=null)},g=()=>{a(),o=null,l=null},b=L.useCallback(()=>{m?d.current=ee(u):(a(),d.current=null)},[u,m]);return L.useEffect(()=>()=>{g()},[]),L.useEffect(()=>{b()},[b]),L.useEffect(()=>{let v=`${o}`!=`${c}`,I=l!==p,h=R.current;h&&(v||I)?(a(),m&&f()):h||g()},[c,p,m]),[f,a]}import*as K from"react";function Oe(u){let s=K.useId(),[c,p]=K.useState(u||`pr_id_${s.replaceAll(/:|«|»/g,"")}`);return K.useEffect(()=>{p(u||`pr_id_${s.replaceAll(/:|«|»/g,"")}`)},[u,s]),c}import{isAndroid as te}from"@primeuix/utils";function De(u){let{pattern:s=/./,validateOnly:c=!1}=u,p={pint:/[\d]/,int:/[\d-]/,pnum:/[\d.]/,money:/[\d.\s,]/,num:/[\d-.]/,hex:/[0-9a-f]/i,email:/[a-z0-9_.-@]/i,alpha:/[a-z_]/i,alphanum:/[a-z0-9_]/},m=()=>typeof s=="string"?p[s]:s,d=a=>{c||!te()||l(a,a.data)},R=a=>{c||te()||a.ctrlKey||a.altKey||a.metaKey||l(a,a.key)},o=a=>{if(c)return;let g=m();[...a.clipboardData.getData("text")].forEach(v=>{if(!g.test(v))return a.preventDefault(),!1})},l=(a,g)=>{if(g==null||!(g.length<=2))return;m().test(g)||a.preventDefault()};return{onBeforeInput:d,onKeyPress:R,onPaste:o,validate:a=>{let g=a.target.value,b=!0,v=m();return g&&!v.test(g)&&(b=!1),b}}}import{useMountEffect as Le}from"@primereact/hooks";import{getUserAgent as $}from"@primeuix/utils";import*as T from"react";function je(u){let{mask:s,unmask:c,slotChar:p="_",autoClear:m=!0,readOnly:d=!1,onMaskChange:R,target:o}=u,l=T.useRef(0),f=T.useRef([]),a=T.useRef([]),g=T.useRef(null),b=T.useRef(0),v=T.useRef(!1),I=T.useRef(!1),h=T.useRef(null),C=T.useRef(null),ue=T.useRef(0),_=T.useRef(null),A=T.useRef(null),z=T.useRef(null),oe=e=>{"isComposing"in e&&e.isComposing||(v.current?de():Q(e))},ae=e=>{var y;if(d)return;let t=e.code,r,n,i,E=/iphone/i.test($());if(A.current=o==null?void 0:o.value,t==="Backspace"||t==="Delete"||E&&t==="Escape"){if(r=M(),!r)return;n=r.begin,i=r.end,i-n===0&&(n=t!=="Delete"?pe(n):i=H(n-1),i=t==="Delete"?H(i):i),O(n,i),J(n,i-1),x(e.target.value),e.preventDefault()}else t==="Enter"?(o.blur(),x(e.target.value)):t==="Escape"&&(o&&(o.value=(y=h.current)!=null?y:""),M(0,k()),x(e.target.value),e.preventDefault())},ce=e=>{var y;if(d)return;let t=e.code,r=M(),n,i,E;r&&(e.ctrlKey||e.altKey||e.metaKey||e.shiftKey||e.key==="CapsLock"||e.key==="Escape"||e.key==="Tab"||(t&&t!=="Enter"&&(r.end-r.begin!==0&&(O(r.begin,r.end),J(r.begin,r.end-1)),n=H(r.begin-1),n<l.current&&(i=e.key,(y=f.current[n])!=null&&y.test(i)&&(me(n),a.current[n]=i,P(),E=H(n),/android/i.test($())?setTimeout(()=>{M(E)},0):M(E))),e.preventDefault()),x(e.target.value)))},ie=()=>{if(!d)if(_.current&&clearTimeout(_.current),I.current=!0,h.current=o.value,!o.value||o.value===g.current)requestAnimationFrame(()=>{o===document.activeElement&&M(0,0)});else{let e=k();_.current=setTimeout(()=>{o===document.activeElement&&(P(),e===(s==null?void 0:s.replace("?","").length)?M(0,e):M(e))},10)}},le=e=>{if(I.current=!1,k(),x(e.target.value),o.value!==h.current){let t=new Event("change",{bubbles:!0,cancelable:!1});o.dispatchEvent(t)}},fe=e=>{Q(e)},M=(e,t)=>{var i,E;let r=0,n=0;return typeof e=="number"?(r=e,n=typeof t=="number"?t:r,o.setSelectionRange(r,n)):o&&(r=(i=o.selectionStart)!=null?i:0,n=(E=o.selectionEnd)!=null?E:0),{begin:r,end:n}},w=e=>e<p.length?p.charAt(e):p.charAt(0),H=e=>{for(;++e<l.current&&!f.current[e];);return e},pe=e=>{for(;--e>=0&&!f.current[e];);return e},J=(e,t)=>{var i,E;let r,n;if(!(e<0)){for(r=e,n=H(t);r<l.current;r++)if(f.current[r]){if(n<l.current&&((i=f.current[r])!=null&&i.test(a.current[n])))a.current[r]=a.current[n],a.current[n]=w(n);else break;n=H(n)}P(),M(Math.max((E=C.current)!=null?E:0,e))}},me=e=>{var E;let t,r,n,i;for(t=e,r=w(e);t<l.current;t++)if(f.current[t])if(n=H(t),i=a.current[t],a.current[t]=r,n<l.current&&((E=f.current[n])!=null&&E.test(i)))r=i;else break},de=()=>{var r;let e=o.value,t=M();if(t)if(A.current&&A.current.length&&A.current.length>e.length){for(k(!0);t.begin>0&&!f.current[t.begin-1];)t.begin--;if(t.begin===0)for(;t.begin<((r=C.current)!=null?r:0)&&!f.current[t.begin];)t.begin++;M(t.begin,t.begin)}else{for(k(!0);t.begin<l.current&&!f.current[t.begin];)t.begin++;M(t.begin,t.begin)}},O=(e,t)=>{let r;for(r=e;r<t&&r<l.current;r++)f.current[r]&&(a.current[r]=w(r))},P=()=>{o&&(o.value=a.current.join(""))},k=(e=!1)=>{var y,j,Z,q;let t=o.value,r=-1,n,i,E;for(n=0,E=0;n<l.current;n++){let G=f.current[n];if(G!==null){for(a.current[n]=w(n);E++<((y=t==null?void 0:t.length)!=null?y:0);)if(i=(j=t==null?void 0:t.charAt(E-1))!=null?j:"",G.test(i)){a.current[n]=i,r=n;break}if(E>((Z=t==null?void 0:t.length)!=null?Z:0)){O(n+1,l.current);break}}else a.current[n]===(t==null?void 0:t.charAt(E))&&E++,n<b.current&&(r=n)}return e?P():r+1<b.current?m||a.current.join("")===g.current?(o.value&&(o.value=""),O(0,l.current)):P():(P(),o&&(o.value=o.value.substring(0,r+1))),b.current?n:(q=C.current)!=null?q:0},Q=e=>{let t=e.type==="paste";if(d||t)return;let r=k(!0);M(r),x(e.target.value)},Ee=e=>{let t=[],r=e.split("");for(let n=0;n<r.length;n++){let i=r[n];f.current[n]&&i!==w(n)&&t.push(i)}return t.join("")},x=e=>{if(z.current===e)return;let t=c?Ee(e):e,r=g.current!==t?t:"";z.current=e,o&&(o.value=r),R&&R({value:r})},Re=(e=!0)=>{o&&(o.value==null?(o.value="",e&&x("")):(k(),setTimeout(()=>{o&&(P(),k(),e&&x(o.value))},10)),h.current=o.value)},ge=()=>{f.current=[],b.current=s?s.length:0,l.current=s?s.length:0,C.current=null;let e={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},t=$();v.current=/chrome/i.test(t)&&/android/i.test(t);let r=s?s.split(""):"";for(let n=0;n<r.length;n++){let i=r[n];i==="?"?(l.current--,b.current=n):e[i]?(f.current.push(new RegExp(e[i])),C.current===null&&(C.current=f.current.length-1),n<b.current&&(ue.current=f.current.length-1)):f.current.push(null)}a.current=[];for(let n=0;n<r.length;n++){let i=r[n];i!=="?"&&(e[i]?a.current.push(w(n)):a.current.push(i))}g.current=a.current.join(""),Re(!1)};return Le(()=>{ge()}),{onMaskInput:oe,onMaskKeyDown:ae,onMaskKeyPress:ce,onMaskFocus:ie,onMaskBlur:le,onMaskPaste:fe}}import*as U from"react";function $e(u,s=!0){let[c,p]=U.useState(!1),m=U.useRef(null),d=l=>p(l.matches),R=()=>{var l;return(l=m.current)==null?void 0:l.addEventListener("change",d)},o=()=>{var l;return((l=m.current)==null?void 0:l.removeEventListener("change",d))&&(m.current=null)};return U.useEffect(()=>(s&&(m.current=window.matchMedia(u),p(m.current.matches),R()),()=>{o()}),[u,s]),c}import*as V from"react";function Je(u){let s=V.useRef(!1);V.useEffect(()=>{s.current||(s.current=!0,u==null||u())},[])}import*as ne from"react";function Ze(u={},s={}){return ne.useMemo(()=>{let c={props:Y({},s),attrs:{}};return Object.entries(u).forEach(([p,m])=>{p in s?c.props[p]=m:c.attrs[p]=m}),c},[u,s])}import*as re from"react";function We(u){re.useEffect(()=>()=>{u==null||u()},[])}import*as B from"react";function Ye(u,s){let c=B.useRef(!1);B.useEffect(()=>{if(!c.current){c.current=!0;return}return u==null?void 0:u()},s)}import*as se from"react";function tt(){return se.useCallback(s=>{document.startViewTransition?document.startViewTransition(()=>{s()}):s()},[])}export{xe as useAttrSelector,He as useControlledState,Ue as useEventListener,Oe as useId,De as useKeyFilter,je as useMask,$e as useMatchMedia,Je as useMountEffect,N as usePrevious,Ze as useProps,We as useUnmountEffect,Ye as useUpdateEffect,tt as useViewTransition};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/use-attr-selector/index.ts","../src/use-controlled-state/index.ts","../src/use-event-listener/index.ts","../src/use-previous/index.ts","../src/use-id/index.ts","../src/use-match-media/index.ts","../src/use-mount-effect/index.ts","../src/use-props/index.ts","../src/use-unmount-effect/index.ts","../src/use-update-effect/index.ts","../src/use-view-transition/index.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * Generates a unique attribute selector based on the provided prefix.\n *\n * @param prefix - The prefix to prepend to the generated selector.\n * @returns A unique string combining the prefix and the selector.\n *\n * @example\n * ```ts\n * const selector = useAttrSelector('foo');\n * console.log(selector); // e.g., 'foo0'\n * ```\n */\nexport function useAttrSelector(prefix: string = ''): string {\n const id = React.useId();\n\n return React.useMemo(() => `${prefix}${id.replaceAll(/:|«|»/g, '')}`.trim().toLowerCase(), [id, prefix]);\n}\n","import { resolve } from '@primeuix/utils';\nimport * as React from 'react';\n\n/**\n * The options for the `useControlledState` hook.\n */\nexport interface UseControlledStateOptions<T = unknown, E = unknown> {\n /**\n * The value of the controlled state.\n */\n value?: T | undefined;\n /**\n * The default value of the uncontrolled state.\n */\n defaultValue?: T | undefined;\n /**\n * Callback function that is called when the value changes.\n */\n onChange?: (newValue: E) => void;\n}\n\n/**\n * The return type of the `useControlledState` hook.\n * A tuple containing the current value and a function to update it.\n */\nexport type UseControlledStateReturnType<T = unknown> = [T | undefined, (inValue: unknown | ((prev?: T) => unknown)) => void, boolean];\n\n/**\n * A custom hook that manages controlled and uncontrolled state.\n *\n * @param {UseControlledStateOptions} options - The options for the controlled state.\n * @returns A tuple containing the current value and a function to update it.\n *\n * @example\n * ```tsx\n * const ControlledComponent = () => {\n * const [controlledValue, setControlledValue] = React.useState('');\n *\n * const [value, setValue] = useControlledState({\n * value: controlledValue,\n * defaultValue: 'initial value',\n * onChange: (newValue) => {\n * setControlledValue(newValue);\n * }\n * });\n *\n * return <Component value={value} onChange={(e) => setValue(e.target.value)} />;\n * };\n * ```\n */\nexport function useControlledState<T = unknown, E = T>({ value, defaultValue, onChange }: UseControlledStateOptions<T, E>): UseControlledStateReturnType<T | undefined> {\n const [valueState, setValueState] = React.useState<T | undefined>(defaultValue ?? value);\n\n const isControlled = value !== undefined;\n const computedValue = isControlled ? (value as T) : valueState;\n\n const setValue = React.useCallback(\n (inValue: unknown | ((prev?: T) => unknown)) => {\n // @todo - update resolve to accept multiple parameters\n const [newValue, onChangeParam] = resolve(inValue, computedValue, isControlled) as [T, E];\n\n onChange?.(onChangeParam);\n\n if (!isControlled) {\n setValueState(newValue);\n }\n },\n [computedValue, isControlled, onChange]\n );\n\n return [computedValue, setValue, isControlled];\n}\n","import { getTargetElement, isNotEmpty } from '@primeuix/utils';\nimport * as React from 'react';\nimport { usePrevious } from '../use-previous';\n\n/**\n * The options for the `useEventListener` hook.\n */\nexport interface UseEventListenerOptions<T = keyof HTMLElementEventMap> {\n /**\n * The target element to bind the event listener to.\n * @default 'document'\n */\n target?: 'document' | 'window' | 'body' | HTMLElement | (() => HTMLElement) | React.Ref<HTMLElement> | string | null;\n /**\n * The event type to listen for.\n */\n type: T | string;\n /**\n * The event listener callback.\n */\n listener: EventListener;\n /**\n * The event listener options\n */\n options?: AddEventListenerOptions | boolean;\n /**\n * A boolean indicating whether the event listener should be active.\n */\n when?: boolean;\n}\n\n/**\n * The return type of the `useEventListener` hook.\n * A tuple containing functions;\n * 1. `bind` function is used to bind the event listener.\n * 2. `unbind` function is used to unbind the event listener.\n */\nexport type UseEventListenerReturnType = [(options?: Partial<Omit<UseEventListenerOptions, 'target'>> & { target?: UseEventListenerOptions['target'] | Document | null }) => void, () => void];\n\n/**\n * Listens for the specified event type on the target element.\n *\n * @param {UseEventListenerOptions} options - The options for the event listener.\n * @returns A tuple containing functions;\n * 1. `bind` function is used to bind the event listener.\n * 2. `unbind` function is used to unbind the event listener.\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const [bind, unbind] = useEventListener({\n * target: 'document',\n * type: 'click',\n * listener: (event) => {\n * console.log(event);\n * },\n * when: true\n * });\n *\n * return <div>Click me</div>;\n * };\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const [bind, unbind] = useEventListener({\n * target: () => document.querySelector('.element'),\n * type: 'mouseover',\n * listener: (event) => {\n * console.log(event);\n * }\n * });\n *\n * return <div>MouseOver to `.element`</div>;\n * };\n * ```\n */\nexport function useEventListener({ target = 'document', type, listener, options, when = true }: UseEventListenerOptions): UseEventListenerReturnType {\n const targetRef = React.useRef<HTMLElement | null>(null);\n const listenerRef = React.useRef<EventListener | null>(null);\n let prevListener = usePrevious(listener);\n let prevOptions = usePrevious(options);\n\n const bind = (bindOptions: Partial<Omit<UseEventListenerOptions, 'target'>> & { target?: UseEventListenerOptions['target'] | Document | null } = {}) => {\n const { target: bindTarget } = bindOptions;\n\n if (isNotEmpty(bindTarget)) {\n unbind();\n\n if (bindOptions.when || when) {\n targetRef.current = getTargetElement(bindTarget) as HTMLElement;\n }\n }\n\n if (!listenerRef.current && targetRef.current) {\n listenerRef.current = (event: Event) => listener && listener(event);\n targetRef.current.addEventListener(type, listenerRef.current, options);\n }\n };\n\n const unbind = () => {\n if (listenerRef.current) {\n targetRef.current?.removeEventListener(type, listenerRef.current, options);\n listenerRef.current = null;\n }\n };\n\n const dispose = () => {\n unbind();\n // Prevent memory leak by releasing\n prevListener = null;\n prevOptions = null;\n };\n\n const updateTarget = React.useCallback(() => {\n if (when) {\n targetRef.current = getTargetElement(target) as HTMLElement;\n } else {\n unbind();\n targetRef.current = null;\n }\n }, [target, when]);\n\n React.useEffect(() => {\n return () => {\n dispose();\n };\n }, []);\n\n React.useEffect(() => {\n updateTarget();\n }, [updateTarget]);\n\n React.useEffect(() => {\n const listenerChanged = `${prevListener}` !== `${listener}`;\n const optionsChanged = prevOptions !== options;\n const listenerExists = listenerRef.current;\n\n if (listenerExists && (listenerChanged || optionsChanged)) {\n unbind();\n\n if (when) {\n bind();\n }\n } else if (!listenerExists) {\n dispose();\n }\n }, [listener, options, when]);\n\n return [bind, unbind];\n}\n","import * as React from 'react';\n\n/**\n * Returns the previous value of the provided value.\n *\n * @param value - The value to track.\n * @returns The previous value of the provided value.\n *\n * @example\n * ```tsx\n * const [count, setCount] = React.useState(5);\n * const prevCount = usePrevious(count);\n *\n * console.log(prevCount); // undefined\n *\n * setCount(10);\n *\n * console.log(prevCount); // 5\n * ```\n */\nexport function usePrevious<T>(value: T): T | null | undefined {\n const ref = React.useRef<T | null>(null);\n\n React.useEffect(() => {\n ref.current = value;\n\n return () => {\n ref.current = null;\n };\n }, [value]);\n\n return ref.current;\n}\n","import * as React from 'react';\n\n/**\n * Generates a unique identifier.\n *\n * @param initialValue Optional initial value for the ID.\n * @returns The generated or provided ID.\n *\n * @example\n * ```tsx\n * const id = useId('foo');\n * console.log(id); // 'foo'\n * ```\n *\n * @example\n * ```tsx\n * const defaultId = useId();\n * console.log(defaultId); // e.g., 'pr_id_0'\n * ```\n */\nexport function useId(initialValue?: string): string {\n const idx = React.useId();\n const [idState, setIdState] = React.useState<string>(initialValue || `pr_id_${idx.replaceAll(/:|«|»/g, '')}`);\n\n React.useEffect(() => {\n setIdState(initialValue || `pr_id_${idx.replaceAll(/:|«|»/g, '')}`);\n }, [initialValue, idx]);\n\n return idState;\n}\n","import * as React from 'react';\n\n/**\n * Listens for the specified media query.\n *\n * @param query - The media query to match.\n * @param when - A boolean indicating whether the media query should be active.\n * @returns A boolean indicating whether the media query matches.\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const isMobile = useMatchMedia('(max-width: 768px)');\n *\n * return <div>{isMobile ? 'Mobile' : 'Desktop'}</div>;\n * };\n */\nexport function useMatchMedia(query: string, when: boolean = true): boolean {\n const [matches, setMatches] = React.useState(false);\n const matchMedia = React.useRef<MediaQueryList | null>(null);\n\n const handleChange = (event: MediaQueryListEvent) => setMatches(event.matches);\n const bind = () => matchMedia.current?.addEventListener('change', handleChange);\n const unbind = () => matchMedia.current?.removeEventListener('change', handleChange) && (matchMedia.current = null);\n\n React.useEffect(() => {\n if (when) {\n matchMedia.current = window.matchMedia(query);\n setMatches(matchMedia.current.matches);\n\n bind();\n }\n\n return () => {\n unbind();\n };\n }, [query, when]);\n\n return matches;\n}\n","import * as React from 'react';\n\n/**\n * Custom hook that runs a mount effect only once.\n * This is similar to `useEffect`, but it only runs on mount.\n *\n * @param {React.EffectCallback} effect the callback function\n * @returns {void}\n *\n * @example\n * ```tsx\n * const MyComponent = () => {\n * useMountEffect(() => {\n * console.log('Mounted');\n * });\n * };\n * ```\n */\nexport function useMountEffect(effect: React.EffectCallback): void {\n const mounted = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!mounted.current) {\n mounted.current = true;\n\n effect?.();\n }\n }, []);\n}\n","import * as React from 'react';\n\n/**\n * Used to merge and differentiate incoming props with the default props.\n * - Keys that exist in both `props1` and `props2` are placed in `props`, with values from `props1`.\n * - Keys that exist in `props1` but not in `props2` are placed in `attrs`.\n *\n * @template P1 The type of the incoming set of props.\n * @template P2 The type of the default set of props.\n *\n * @param props1 The incoming set of props (e.g., user-defined or dynamic props).\n * @param props2 The default set of props (e.g., default props).\n * @returns An object containing:\n * - `props`: A new object containing keys that exist in both `props1` and `props2`, using values from `props1`.\n * - `attrs`: A new object containing keys that exist only in `props1`, excluding any keys from `props2`.\n *\n * @example\n * ```ts\n * const { props, attrs } = useProps({ id: 'foo', className: 'bar' }, { className: 'baz' });\n *\n * console.log(props); // { className: 'bar' }\n * console.log(attrs); // { id: 'foo' }\n * ```\n */\nexport function useProps<P1, P2>(props1: P1 = {} as P1, props2: P2 = {} as P2) {\n type Props = Pick<P1 & P2, keyof P2>;\n type Attrs = Omit<P1, keyof P2>;\n type Result = { props: Props; attrs: Attrs };\n\n return React.useMemo(() => {\n const result: Result = { props: { ...props2 } as Props, attrs: {} as Attrs };\n\n Object.entries(props1 as Record<string, unknown>).forEach(([key, value]) => {\n if (key in (props2 as Record<string, unknown>)) {\n (result.props as Record<string, unknown>)[key] = value;\n } else {\n (result.attrs as Record<string, unknown>)[key] = value;\n }\n });\n\n return result;\n }, [props1, props2]);\n}\n","import * as React from 'react';\n\n/**\n * Custom hook that runs an unmount effect only once.\n * This is similar to `useEffect`, but it only runs on unmount.\n *\n * @param {React.EffectCallback} effect the callback function\n * @returns {void}\n *\n * @example\n * ```tsx\n * const Component = () => {\n * useUnmountEffect(() => {\n * console.log('Unmounted');\n * });\n * };\n * ```\n */\nexport function useUnmountEffect(effect: React.EffectCallback): void {\n React.useEffect(() => {\n return () => {\n effect?.();\n };\n }, []);\n}\n","import * as React from 'react';\n\n/**\n * Custom hook that runs an update effect whenever dependencies change.\n * This is similar to `useEffect`, but it does not run on mount.\n *\n * @param {React.EffectCallback} effect the callback function\n * @param {React.DependencyList} dependencies the dependencies\n * @returns {void}\n *\n * @example\n * ```tsx\n * const Component = ({ value }) => {\n * useUpdateEffect(() => {\n * console.log('Updated');\n * }, [value]);\n * };\n * ```\n */\nexport function useUpdateEffect(effect: React.EffectCallback, dependencies?: React.DependencyList): void {\n const mounted = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!mounted.current) {\n mounted.current = true;\n\n return;\n }\n\n return effect?.();\n }, dependencies);\n}\n","import * as React from 'react';\n\n/**\n * Starts a view transition.\n *\n * @returns A function that starts a view transition.\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const startTransition = useViewTransition();\n *\n * const handleClick = () => {\n * startTransition(() => {\n * // Perform some work\n * });\n * };\n *\n * return <button onClick={handleClick}>Click me</button>;\n * };\n */\nexport function useViewTransition() {\n const startTransition = React.useCallback((callback: () => void) => {\n if (document.startViewTransition) {\n document.startViewTransition(() => {\n callback();\n });\n } else {\n callback();\n }\n }, []);\n\n return startTransition;\n}\n"],"mappings":"yVAAA,UAAYA,MAAW,QAchB,SAASC,EAAgBC,EAAiB,GAAY,CACzD,IAAMC,EAAW,QAAM,EAEvB,OAAa,UAAQ,IAAM,GAAGD,CAAM,GAAGC,EAAG,WAAW,SAAU,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,EAAG,CAACA,EAAID,CAAM,CAAC,CAC3G,CClBA,OAAS,WAAAE,MAAe,kBACxB,UAAYC,MAAW,QAiDhB,SAASC,EAAuC,CAAE,MAAAC,EAAO,aAAAC,EAAc,SAAAC,CAAS,EAAiF,CACpK,GAAM,CAACC,EAAYC,CAAa,EAAU,WAAwBH,GAAA,KAAAA,EAAgBD,CAAK,EAEjFK,EAAeL,IAAU,OACzBM,EAAgBD,EAAgBL,EAAcG,EAE9CI,EAAiB,cAClBC,GAA+C,CAE5C,GAAM,CAACC,EAAUC,CAAa,EAAIb,EAAQW,EAASF,EAAeD,CAAY,EAE9EH,GAAA,MAAAA,EAAWQ,GAENL,GACDD,EAAcK,CAAQ,CAE9B,EACA,CAACH,EAAeD,EAAcH,CAAQ,CAC1C,EAEA,MAAO,CAACI,EAAeC,EAAUF,CAAY,CACjD,CCvEA,OAAS,oBAAAM,EAAkB,cAAAC,MAAkB,kBAC7C,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,EAAgB,SAAgB,EAAK,EAErC,YAAU,IAAM,CACbA,EAAQ,UACTA,EAAQ,QAAU,GAElBD,GAAA,MAAAA,IAER,EAAG,CAAC,CAAC,CACT,CC5BA,UAAYE,MAAW,QAwBhB,SAASC,GAAiBC,EAAa,CAAC,EAASC,EAAa,CAAC,EAAS,CAK3E,OAAa,UAAQ,IAAM,CACvB,IAAMC,EAAiB,CAAE,MAAOC,EAAA,GAAKF,GAAmB,MAAO,CAAC,CAAW,EAE3E,cAAO,QAAQD,CAAiC,EAAE,QAAQ,CAAC,CAACI,EAAKC,CAAK,IAAM,CACpED,KAAQH,EACPC,EAAO,MAAkCE,CAAG,EAAIC,EAEhDH,EAAO,MAAkCE,CAAG,EAAIC,CAEzD,CAAC,EAEMH,CACX,EAAG,CAACF,EAAQC,CAAM,CAAC,CACvB,CC1CA,UAAYK,MAAW,QAkBhB,SAASC,GAAiBC,EAAoC,CAC3D,YAAU,IACL,IAAM,CACTA,GAAA,MAAAA,GACJ,EACD,CAAC,CAAC,CACT,CCxBA,UAAYC,MAAW,QAmBhB,SAASC,GAAgBC,EAA8BC,EAA2C,CACrG,IAAMC,EAAgB,SAAgB,EAAK,EAErC,YAAU,IAAM,CAClB,GAAI,CAACA,EAAQ,QAAS,CAClBA,EAAQ,QAAU,GAElB,MACJ,CAEA,OAAOF,GAAA,YAAAA,GACX,EAAGC,CAAY,CACnB,CC/BA,UAAYE,MAAW,QAqBhB,SAASC,IAAoB,CAWhC,OAV8B,cAAaC,GAAyB,CAC5D,SAAS,oBACT,SAAS,oBAAoB,IAAM,CAC/BA,EAAS,CACb,CAAC,EAEDA,EAAS,CAEjB,EAAG,CAAC,CAAC,CAGT","names":["React","useAttrSelector","prefix","id","resolve","React","useControlledState","value","defaultValue","onChange","valueState","setValueState","isControlled","computedValue","setValue","inValue","newValue","onChangeParam","getTargetElement","isNotEmpty","React","React","usePrevious","value","ref","useEventListener","target","type","listener","options","when","targetRef","listenerRef","prevListener","usePrevious","prevOptions","bind","bindOptions","bindTarget","isNotEmpty","unbind","getTargetElement","event","_a","dispose","updateTarget","listenerChanged","optionsChanged","listenerExists","React","useId","initialValue","idx","idState","setIdState","React","useMatchMedia","query","when","matches","setMatches","matchMedia","handleChange","event","bind","_a","unbind","React","useMountEffect","effect","mounted","React","useProps","props1","props2","result","__spreadValues","key","value","React","useUnmountEffect","effect","React","useUpdateEffect","effect","dependencies","mounted","React","useViewTransition","callback"]}
|
|
1
|
+
{"version":3,"sources":["../src/use-attr-selector/index.ts","../src/use-controlled-state/index.ts","../src/use-event-listener/index.ts","../src/use-previous/index.ts","../src/use-id/index.ts","../src/use-key-filter/index.ts","../src/use-mask/index.ts","../src/use-match-media/index.ts","../src/use-mount-effect/index.ts","../src/use-props/index.ts","../src/use-unmount-effect/index.ts","../src/use-update-effect/index.ts","../src/use-view-transition/index.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * Generates a unique attribute selector based on the provided prefix.\n *\n * @param prefix - The prefix to prepend to the generated selector.\n * @returns A unique string combining the prefix and the selector.\n *\n * @example\n * ```ts\n * const selector = useAttrSelector('foo');\n * console.log(selector); // e.g., 'foo0'\n * ```\n */\nexport function useAttrSelector(prefix: string = ''): string {\n const id = React.useId();\n\n return React.useMemo(() => `${prefix}${id.replaceAll(/:|«|»/g, '')}`.trim().toLowerCase(), [id, prefix]);\n}\n","import { resolve } from '@primeuix/utils';\nimport * as React from 'react';\n\n/**\n * The options for the `useControlledState` hook.\n */\nexport interface UseControlledStateOptions<T = unknown, E = unknown> {\n /**\n * The value of the controlled state.\n */\n value?: T | undefined;\n /**\n * The default value of the uncontrolled state.\n */\n defaultValue?: T | undefined;\n /**\n * Callback function that is called when the value changes.\n */\n onChange?: (newValue: E) => void;\n}\n\n/**\n * The return type of the `useControlledState` hook.\n * A tuple containing the current value and a function to update it.\n */\nexport type UseControlledStateReturnType<T = unknown> = [T | undefined, (inValue: unknown | ((prev?: T) => unknown)) => void, boolean];\n\n/**\n * A custom hook that manages controlled and uncontrolled state.\n *\n * @param {UseControlledStateOptions} options - The options for the controlled state.\n * @returns A tuple containing the current value and a function to update it.\n *\n * @example\n * ```tsx\n * const ControlledComponent = () => {\n * const [controlledValue, setControlledValue] = React.useState('');\n *\n * const [value, setValue] = useControlledState({\n * value: controlledValue,\n * defaultValue: 'initial value',\n * onChange: (newValue) => {\n * setControlledValue(newValue);\n * }\n * });\n *\n * return <Component value={value} onChange={(e) => setValue(e.target.value)} />;\n * };\n * ```\n */\nexport function useControlledState<T = unknown, E = T>({ value, defaultValue, onChange }: UseControlledStateOptions<T, E>): UseControlledStateReturnType<T | undefined> {\n const [valueState, setValueState] = React.useState<T | undefined>(defaultValue ?? value);\n\n const isControlled = value !== undefined;\n const computedValue = isControlled ? (value as T) : valueState;\n\n const setValue = React.useCallback(\n (inValue: unknown | ((prev?: T) => unknown)) => {\n // @todo - update resolve to accept multiple parameters\n const [newValue, onChangeParam] = resolve(inValue, computedValue, isControlled) as [T, E];\n\n onChange?.(onChangeParam);\n\n if (!isControlled) {\n setValueState(newValue);\n }\n },\n [computedValue, isControlled, onChange]\n );\n\n return [computedValue, setValue, isControlled];\n}\n","import { getTargetElement, isNotEmpty } from '@primeuix/utils';\nimport * as React from 'react';\nimport { usePrevious } from '../use-previous';\n\n/**\n * The options for the `useEventListener` hook.\n */\nexport interface UseEventListenerOptions<T = keyof HTMLElementEventMap> {\n /**\n * The target element to bind the event listener to.\n * @default 'document'\n */\n target?: 'document' | 'window' | 'body' | HTMLElement | (() => HTMLElement) | React.Ref<HTMLElement> | string | null;\n /**\n * The event type to listen for.\n */\n type: T | string;\n /**\n * The event listener callback.\n */\n listener: EventListener;\n /**\n * The event listener options\n */\n options?: AddEventListenerOptions | boolean;\n /**\n * A boolean indicating whether the event listener should be active.\n */\n when?: boolean;\n}\n\n/**\n * The return type of the `useEventListener` hook.\n * A tuple containing functions;\n * 1. `bind` function is used to bind the event listener.\n * 2. `unbind` function is used to unbind the event listener.\n */\nexport type UseEventListenerReturnType = [(options?: Partial<Omit<UseEventListenerOptions, 'target'>> & { target?: UseEventListenerOptions['target'] | Document | null }) => void, () => void];\n\n/**\n * Listens for the specified event type on the target element.\n *\n * @param {UseEventListenerOptions} options - The options for the event listener.\n * @returns A tuple containing functions;\n * 1. `bind` function is used to bind the event listener.\n * 2. `unbind` function is used to unbind the event listener.\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const [bind, unbind] = useEventListener({\n * target: 'document',\n * type: 'click',\n * listener: (event) => {\n * console.log(event);\n * },\n * when: true\n * });\n *\n * return <div>Click me</div>;\n * };\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const [bind, unbind] = useEventListener({\n * target: () => document.querySelector('.element'),\n * type: 'mouseover',\n * listener: (event) => {\n * console.log(event);\n * }\n * });\n *\n * return <div>MouseOver to `.element`</div>;\n * };\n * ```\n */\nexport function useEventListener({ target = 'document', type, listener, options, when = true }: UseEventListenerOptions): UseEventListenerReturnType {\n const targetRef = React.useRef<HTMLElement | null>(null);\n const listenerRef = React.useRef<EventListener | null>(null);\n let prevListener = usePrevious(listener);\n let prevOptions = usePrevious(options);\n\n const bind = (bindOptions: Partial<Omit<UseEventListenerOptions, 'target'>> & { target?: UseEventListenerOptions['target'] | Document | null } = {}) => {\n const { target: bindTarget } = bindOptions;\n\n if (isNotEmpty(bindTarget)) {\n unbind();\n\n if (bindOptions.when || when) {\n targetRef.current = getTargetElement(bindTarget) as HTMLElement;\n }\n }\n\n if (!listenerRef.current && targetRef.current) {\n listenerRef.current = (event: Event) => listener && listener(event);\n targetRef.current.addEventListener(type, listenerRef.current, options);\n }\n };\n\n const unbind = () => {\n if (listenerRef.current) {\n targetRef.current?.removeEventListener(type, listenerRef.current, options);\n listenerRef.current = null;\n }\n };\n\n const dispose = () => {\n unbind();\n // Prevent memory leak by releasing\n prevListener = null;\n prevOptions = null;\n };\n\n const updateTarget = React.useCallback(() => {\n if (when) {\n targetRef.current = getTargetElement(target) as HTMLElement;\n } else {\n unbind();\n targetRef.current = null;\n }\n }, [target, when]);\n\n React.useEffect(() => {\n return () => {\n dispose();\n };\n }, []);\n\n React.useEffect(() => {\n updateTarget();\n }, [updateTarget]);\n\n React.useEffect(() => {\n const listenerChanged = `${prevListener}` !== `${listener}`;\n const optionsChanged = prevOptions !== options;\n const listenerExists = listenerRef.current;\n\n if (listenerExists && (listenerChanged || optionsChanged)) {\n unbind();\n\n if (when) {\n bind();\n }\n } else if (!listenerExists) {\n dispose();\n }\n }, [listener, options, when]);\n\n return [bind, unbind];\n}\n","import * as React from 'react';\n\n/**\n * Returns the previous value of the provided value.\n *\n * @param value - The value to track.\n * @returns The previous value of the provided value.\n *\n * @example\n * ```tsx\n * const [count, setCount] = React.useState(5);\n * const prevCount = usePrevious(count);\n *\n * console.log(prevCount); // undefined\n *\n * setCount(10);\n *\n * console.log(prevCount); // 5\n * ```\n */\nexport function usePrevious<T>(value: T): T | null | undefined {\n const ref = React.useRef<T | null>(null);\n\n React.useEffect(() => {\n ref.current = value;\n\n return () => {\n ref.current = null;\n };\n }, [value]);\n\n return ref.current;\n}\n","import * as React from 'react';\n\n/**\n * Generates a unique identifier.\n *\n * @param initialValue Optional initial value for the ID.\n * @returns The generated or provided ID.\n *\n * @example\n * ```tsx\n * const id = useId('foo');\n * console.log(id); // 'foo'\n * ```\n *\n * @example\n * ```tsx\n * const defaultId = useId();\n * console.log(defaultId); // e.g., 'pr_id_0'\n * ```\n */\nexport function useId(initialValue?: string): string {\n const idx = React.useId();\n const [idState, setIdState] = React.useState<string>(initialValue || `pr_id_${idx.replaceAll(/:|«|»/g, '')}`);\n\n React.useEffect(() => {\n setIdState(initialValue || `pr_id_${idx.replaceAll(/:|«|»/g, '')}`);\n }, [initialValue, idx]);\n\n return idState;\n}\n","import { isAndroid } from '@primeuix/utils';\n\n/**\n * The options for the `useKeyFilter` hook.\n */\nexport interface UseKeyFilterOptions {\n /**\n * Sets the pattern for key filtering.\n * @default /./\n */\n pattern?: 'pint' | 'int' | 'pnum' | 'money' | 'num' | 'hex' | 'email' | 'alpha' | 'alphanum' | RegExp;\n /**\n * When enabled, instead of blocking keys, input is validated internally to test against the regular expression.\n * @default false\n */\n validateOnly?: boolean;\n}\n\nexport interface UseKeyFilterExposes {\n /**\n * Handles input events for key filter.\n * Processes character input and composition events while applying the filter pattern.\n * @param event - The form or composition event from the input element\n */\n onBeforeInput: (event: React.CompositionEvent<HTMLInputElement>) => void;\n /**\n * Handles keypress events for character input validation.\n * Validates and places characters according to the filter pattern.\n * @param event - The keyboard event from the input element\n */\n onKeyPress: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n /**\n * Handles paste events for clipboard content insertion.\n * Processes pasted content according to the mask pattern.\n * @param event - The clipboard event from the input element\n */\n onPaste: (event: React.ClipboardEvent<HTMLInputElement>) => void;\n /**\n * Validates the current input value against the filter pattern.\n * @param event - The form event from the input element\n * @returns true if the value matches the pattern, false otherwise\n */\n validate: (event: React.FormEvent<HTMLInputElement>) => boolean;\n}\n\nexport function useKeyFilter(options: UseKeyFilterOptions): UseKeyFilterExposes {\n const { pattern = /./, validateOnly = false } = options;\n\n const DEFAULT_MASKS = {\n pint: /[\\d]/,\n int: /[\\d-]/,\n pnum: /[\\d.]/,\n money: /[\\d.\\s,]/,\n num: /[\\d-.]/,\n hex: /[0-9a-f]/i,\n email: /[a-z0-9_.-@]/i,\n alpha: /[a-z_]/i,\n alphanum: /[a-z0-9_]/\n };\n\n const getRegex = (): RegExp => {\n return typeof pattern === 'string' ? DEFAULT_MASKS[pattern] : pattern;\n };\n\n const onBeforeInput = (event: React.CompositionEvent<HTMLInputElement>) => {\n // android devices must use beforeinput https://stackoverflow.com/questions/36753548/keycode-on-android-is-always-229\n if (validateOnly || !isAndroid()) {\n return;\n }\n\n validateKey(event, event.data);\n };\n\n const onKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {\n // non android devices use keydown\n if (validateOnly || isAndroid()) {\n return;\n }\n\n if (event.ctrlKey || event.altKey || event.metaKey) {\n return;\n }\n\n validateKey(event, event.key);\n };\n\n const onPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {\n if (validateOnly) {\n return;\n }\n\n const regex = getRegex();\n const clipboard = event.clipboardData.getData('text');\n\n // loop over each letter pasted and if any fail prevent the paste\n [...clipboard].forEach((c) => {\n if (!regex.test(c)) {\n event.preventDefault();\n\n return false;\n }\n });\n };\n\n const validateKey = (event: React.CompositionEvent<HTMLInputElement> | React.KeyboardEvent<HTMLInputElement>, key: string) => {\n if (key === null || key === undefined) {\n return;\n }\n\n // some AZERTY keys come in with 2 chars like ´ç if Dead key is pressed first\n const isPrintableKey = key.length <= 2;\n\n if (!isPrintableKey) {\n return;\n }\n\n const regex = getRegex();\n\n if (!regex.test(key)) {\n event.preventDefault();\n }\n };\n\n const validate = (event: React.FormEvent<HTMLInputElement>) => {\n const value = (event.target as HTMLInputElement).value;\n let validatePattern = true;\n\n const regex = getRegex();\n\n if (value && !regex.test(value)) {\n validatePattern = false;\n }\n\n return validatePattern;\n };\n\n return {\n onBeforeInput,\n onKeyPress,\n onPaste,\n validate\n };\n}\n","import { useMountEffect } from '@primereact/hooks';\nimport { getUserAgent } from '@primeuix/utils';\nimport * as React from 'react';\n\n/**\n * Event fired when the component's state changes.\n */\nexport interface UseMaskChangeEvent {\n /**\n * The value of the component.\n */\n value: string | undefined;\n}\n\n/**\n * The options for the `useMask` hook.\n */\nexport interface UseMaskOptions {\n /**\n * Mask pattern.\n */\n mask: string;\n /**\n * Defines if model sets the raw unmasked value to bound value or the formatted mask value.\n * @default false\n */\n unmask?: string;\n /**\n * Placeholder character in mask, default is underscore.\n * @default _\n */\n slotChar?: string;\n /**\n * Clears the incomplete value on blur.\n * @default true\n */\n autoClear?: boolean;\n /**\n * Whether the components are clickable or not.\n * @default false\n */\n readOnly?: boolean;\n /**\n * Callback function that is called when the value is changed.\n * @param event The event that triggered the change.\n * @param event.value The value of the component.\n * @returns void\n */\n onMaskChange?: (event: UseMaskChangeEvent) => void;\n /**\n * Reference to the mask element.\n */\n target: HTMLInputElement;\n}\n\nexport interface UseMaskExposes {\n /**\n * Handles input events for the masked input field.\n * Processes character input and composition events while applying the mask pattern.\n * @param event - The form or composition event from the input element\n */\n onMaskInput: (event: React.FormEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) => void;\n /**\n * Handles keydown events for special key operations.\n * Manages backspace, delete, escape, and enter key behaviors.\n * @param event - The keyboard event from the input element\n */\n onMaskKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n /**\n * Handles keypress events for character input validation.\n * Validates and places characters according to the mask pattern.\n * @param event - The keyboard event from the input element\n */\n onMaskKeyPress: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n /**\n * Handles focus events when the input gains focus.\n * Initializes the mask display and sets the cursor position.\n * @param event - The focus event from the input element\n */\n onMaskFocus: (event: React.FocusEvent<HTMLInputElement>) => void;\n /**\n * Handles blur events when the input loses focus.\n * Validates the final value and triggers change events if needed.\n * @param event - The focus event from the input element\n */\n onMaskBlur: (event: React.FocusEvent<HTMLInputElement>) => void;\n /**\n * Handles paste events for clipboard content insertion.\n * Processes pasted content according to the mask pattern.\n * @param event - The clipboard event from the input element\n */\n onMaskPaste: (event: React.ClipboardEvent<HTMLInputElement>) => void;\n}\n\n/**\n * useMask hook is used to enter input in a certain format such as numeric, date, currency, email and phone.\n *\n * @param {UseMaskOptions} options - The options for the mask.\n * @returns {UseMaskExposes} - The exposed methods for the mask.\n *\n * @example\n * ```tsx\n * const { onMaskInput, onMaskKeyDown, onMaskKeyPress, onMaskFocus, onMaskBlur, onMaskPaste } = useMask({\n * mask: '99/99/9999',\n * onMaskChange: (event: UseMaskChangeEvent) => setValue(event.value ?? ''),\n * target: ref\n * });\n *\n * return (\n * <div className=\"card flex justify-center\">\n * <InputText ref={ref} value={value} placeholder=\"99/99/9999\" onInput={onMaskInput} onKeyDown={onMaskKeyDown} onKeyPress={onMaskKeyPress} onFocus={onMaskFocus} onBlur={onMaskBlur} onPaste={onMaskPaste} />\n * </div>\n * );\n */\nexport function useMask(options: UseMaskOptions): UseMaskExposes {\n const { mask, unmask, slotChar = '_', autoClear = true, readOnly = false, onMaskChange, target } = options;\n\n const len = React.useRef(0);\n const tests = React.useRef<Array<RegExp | null>>([]);\n const buffer = React.useRef<string[]>([]);\n const defaultBuffer = React.useRef<string | null>(null);\n const partialPosition = React.useRef<number>(0);\n const androidChrome = React.useRef(false);\n const focus = React.useRef(false);\n const focusText = React.useRef<string | null>(null);\n const firstNonMaskPos = React.useRef<number | null>(null);\n const lastRequiredNonMaskPos = React.useRef<number>(0);\n const caretTimeoutId = React.useRef<NodeJS.Timeout | null>(null);\n const oldVal = React.useRef<string | null>(null);\n const currentVal = React.useRef<string | null>(null);\n\n const onMaskInput = (event: React.FormEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) => {\n // Check if the event is part of a text composition process (e.g., for Asian languages).\n // If event.isComposing is true, it means the user is still composing text and the input is not finalized.\n if ('isComposing' in event && event.isComposing) {\n return;\n }\n\n if (androidChrome.current) handleAndroidInput();\n else handleInputChange(event);\n };\n\n const onMaskKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) {\n return;\n }\n\n const k = event.code;\n let pos, begin, end;\n const iPhone = /iphone/i.test(getUserAgent());\n\n oldVal.current = target?.value as string;\n\n //backspace, delete, and escape get special treatment\n if (k === 'Backspace' || k === 'Delete' || (iPhone && k === 'Escape')) {\n pos = caret();\n\n if (!pos) {\n return;\n }\n\n begin = pos.begin;\n end = pos.end;\n\n if (end - begin === 0) {\n begin = k !== 'Delete' ? seekPrev(begin) : (end = seekNext(begin - 1));\n end = k === 'Delete' ? seekNext(end) : end;\n }\n\n clearBuffer(begin, end);\n shiftL(begin, end - 1);\n updateModelValue((event.target as HTMLInputElement).value);\n\n event.preventDefault();\n } else if (k === 'Enter') {\n // enter\n target.blur();\n updateModelValue((event.target as HTMLInputElement).value);\n } else if (k === 'Escape') {\n // escape\n if (target) {\n target.value = focusText.current ?? '';\n }\n\n caret(0, checkVal());\n updateModelValue((event.target as HTMLInputElement).value);\n event.preventDefault();\n }\n };\n\n const onMaskKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) {\n return;\n }\n\n const k = event.code,\n pos = caret();\n let p: number, c: string, next: number;\n\n if (!pos) {\n return;\n }\n\n if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey || event.key === 'CapsLock' || event.key === 'Escape' || event.key === 'Tab') {\n //Ignore\n return;\n } else if (k && k !== 'Enter') {\n if (pos.end - pos.begin !== 0) {\n clearBuffer(pos.begin, pos.end);\n shiftL(pos.begin, pos.end - 1);\n }\n\n p = seekNext(pos.begin - 1);\n\n if (p < len.current) {\n c = event.key;\n\n if (tests.current[p]?.test(c)) {\n shiftR(p);\n\n buffer.current[p] = c;\n writeBuffer();\n next = seekNext(p);\n\n if (/android/i.test(getUserAgent())) {\n //Path for CSP Violation on FireFox OS 1.1\n const proxy = () => {\n caret(next);\n };\n\n setTimeout(proxy, 0);\n } else {\n caret(next);\n }\n }\n }\n\n event.preventDefault();\n }\n\n updateModelValue((event.target as HTMLInputElement).value);\n };\n\n const onMaskFocus = () => {\n if (readOnly) {\n return;\n }\n\n if (caretTimeoutId.current) {\n clearTimeout(caretTimeoutId.current as NodeJS.Timeout);\n }\n\n focus.current = true;\n focusText.current = target.value as string;\n\n if (!target.value || target.value === defaultBuffer.current) {\n requestAnimationFrame(() => {\n if (target === document.activeElement) {\n caret(0, 0);\n }\n });\n } else {\n const pos = checkVal();\n\n caretTimeoutId.current = setTimeout(() => {\n if (target !== document.activeElement) {\n return;\n }\n\n writeBuffer();\n\n if (pos === mask?.replace('?', '').length) {\n caret(0, pos);\n } else {\n caret(pos);\n }\n }, 10);\n }\n };\n\n const onMaskBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n focus.current = false;\n checkVal();\n updateModelValue(event.target.value);\n\n if (target.value !== focusText.current) {\n const e = new Event('change', { bubbles: true, cancelable: false });\n\n target.dispatchEvent(e);\n }\n };\n\n const onMaskPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {\n handleInputChange(event);\n };\n\n const caret = (first?: number, last?: number): { begin: number; end: number } | undefined => {\n let begin = 0,\n end = 0;\n\n if (typeof first === 'number') {\n begin = first;\n end = typeof last === 'number' ? last : begin;\n\n target.setSelectionRange(begin, end);\n } else {\n if (target) {\n begin = target.selectionStart ?? 0;\n end = target.selectionEnd ?? 0;\n }\n }\n\n return { begin, end };\n };\n\n const getPlaceholder = (i: number) => {\n if (i < slotChar.length) {\n return slotChar.charAt(i);\n }\n\n return slotChar.charAt(0);\n };\n\n const seekNext = (pos: number) => {\n while (++pos < len.current && !tests.current[pos]);\n\n return pos;\n };\n\n const seekPrev = (pos: number) => {\n while (--pos >= 0 && !tests.current[pos]);\n\n return pos;\n };\n\n const shiftL = (begin: number, end: number) => {\n let i, j;\n\n if (begin < 0) {\n return;\n }\n\n for (i = begin, j = seekNext(end); i < len.current; i++) {\n if (tests.current[i]) {\n if (j < len.current && tests.current[i]?.test(buffer.current[j])) {\n buffer.current[i] = buffer.current[j];\n buffer.current[j] = getPlaceholder(j);\n } else {\n break;\n }\n\n j = seekNext(j);\n }\n }\n\n writeBuffer();\n caret(Math.max(firstNonMaskPos.current ?? 0, begin));\n };\n\n const shiftR = (pos: number) => {\n let i, c, j, t;\n\n for (i = pos, c = getPlaceholder(pos); i < len.current; i++) {\n if (tests.current[i]) {\n j = seekNext(i);\n t = buffer.current[i];\n buffer.current[i] = c;\n\n if (j < len.current && tests.current[j]?.test(t)) {\n c = t;\n } else {\n break;\n }\n }\n }\n };\n\n const handleAndroidInput = () => {\n const curVal = target.value as string;\n const pos = caret();\n\n if (!pos) {\n return;\n }\n\n if (oldVal.current && oldVal.current.length && oldVal.current.length > curVal.length) {\n // a deletion or backspace happened\n checkVal(true);\n while (pos.begin > 0 && !tests.current[pos.begin - 1]) pos.begin--;\n\n if (pos.begin === 0) {\n while (pos.begin < (firstNonMaskPos.current ?? 0) && !tests.current[pos.begin]) pos.begin++;\n }\n\n caret(pos.begin, pos.begin);\n } else {\n checkVal(true);\n while (pos.begin < len.current && !tests.current[pos.begin]) pos.begin++;\n\n caret(pos.begin, pos.begin);\n }\n };\n\n const clearBuffer = (start: number, end: number) => {\n let i;\n\n for (i = start; i < end && i < len.current; i++) {\n if (tests.current[i]) {\n buffer.current[i] = getPlaceholder(i);\n }\n }\n };\n\n const writeBuffer = () => {\n if (target) {\n target.value = buffer.current.join('');\n }\n };\n\n const checkVal = (allow = false): number => {\n //try to place characters where they belong\n const test = target.value;\n let lastMatch = -1,\n i,\n c,\n pos;\n\n for (i = 0, pos = 0; i < len.current; i++) {\n const currentTest = tests.current[i];\n\n if (currentTest !== null) {\n buffer.current[i] = getPlaceholder(i);\n\n while (pos++ < (test?.length ?? 0)) {\n c = test?.charAt(pos - 1) ?? '';\n\n if (currentTest.test(c)) {\n buffer.current[i] = c;\n lastMatch = i;\n break;\n }\n }\n\n if (pos > (test?.length ?? 0)) {\n clearBuffer(i + 1, len.current);\n break;\n }\n } else {\n if (buffer.current[i] === test?.charAt(pos)) {\n pos++;\n }\n\n if (i < partialPosition.current) {\n lastMatch = i;\n }\n }\n }\n\n if (allow) {\n writeBuffer();\n } else if (lastMatch + 1 < partialPosition.current) {\n if (autoClear || buffer.current.join('') === defaultBuffer.current) {\n // Invalid value. Remove it and replace it with the\n // mask, which is the default behavior.\n if (target.value) {\n target.value = '';\n }\n\n clearBuffer(0, len.current);\n } else {\n // Invalid value, but we opt to show the value to the\n // user and allow them to correct their mistake.\n writeBuffer();\n }\n } else {\n writeBuffer();\n\n if (target) {\n target.value = target.value.substring(0, lastMatch + 1);\n }\n }\n\n return partialPosition.current ? i : (firstNonMaskPos.current ?? 0);\n };\n\n const handleInputChange = (event: React.FormEvent<HTMLInputElement> | React.ClipboardEvent<HTMLInputElement>) => {\n const isPasteEvent = event.type === 'paste';\n\n if (readOnly || isPasteEvent) {\n return;\n }\n\n const pos = checkVal(true);\n\n caret(pos);\n updateModelValue((event.target as HTMLInputElement).value);\n };\n\n const unmaskValue = (value: string) => {\n const unmaskedBuffer = [];\n const thisbuffer = value.split('');\n\n for (let i = 0; i < thisbuffer.length; i++) {\n const c = thisbuffer[i];\n\n if (tests.current[i] && c !== getPlaceholder(i)) {\n unmaskedBuffer.push(c);\n }\n }\n\n return unmaskedBuffer.join('');\n };\n\n const updateModelValue = (value: string) => {\n if (currentVal.current === value) return;\n\n const val = unmask ? unmaskValue(value) : value;\n const finalValue = defaultBuffer.current !== val ? val : '';\n\n currentVal.current = value;\n\n if (target) {\n target.value = finalValue;\n }\n\n // Call the onMaskChange callback to update React state\n if (onMaskChange) {\n onMaskChange({ value: finalValue });\n }\n };\n\n const updateValue = (updateModel = true) => {\n if (target) {\n if (target.value == null) {\n target.value = '';\n\n if (updateModel) {\n updateModelValue('');\n }\n } else {\n checkVal();\n\n setTimeout(() => {\n if (target) {\n writeBuffer();\n checkVal();\n\n if (updateModel) updateModelValue(target.value);\n }\n }, 10);\n }\n\n focusText.current = target.value;\n }\n };\n\n const initMask = () => {\n tests.current = [];\n partialPosition.current = mask ? mask.length : 0;\n len.current = mask ? mask.length : 0;\n firstNonMaskPos.current = null;\n const defs = {\n 9: '[0-9]',\n a: '[A-Za-z]',\n '*': '[A-Za-z0-9]'\n } as Record<string, string>;\n\n const ua = getUserAgent();\n\n androidChrome.current = /chrome/i.test(ua) && /android/i.test(ua);\n\n const maskTokens = mask ? mask.split('') : '';\n\n for (let i = 0; i < maskTokens.length; i++) {\n const c = maskTokens[i];\n\n if (c === '?') {\n len.current--;\n partialPosition.current = i;\n } else if (defs[c]) {\n tests.current.push(new RegExp(defs[c]));\n\n if (firstNonMaskPos.current === null) {\n firstNonMaskPos.current = tests.current.length - 1;\n }\n\n if (i < partialPosition.current) {\n lastRequiredNonMaskPos.current = tests.current.length - 1;\n }\n } else {\n tests.current.push(null);\n }\n }\n\n buffer.current = [];\n\n for (let i = 0; i < maskTokens.length; i++) {\n const c = maskTokens[i];\n\n if (c !== '?') {\n if (defs[c]) buffer.current.push(getPlaceholder(i));\n else buffer.current.push(c);\n }\n }\n\n defaultBuffer.current = buffer.current.join('');\n\n updateValue(false);\n };\n\n useMountEffect(() => {\n initMask();\n });\n\n return {\n onMaskInput,\n onMaskKeyDown,\n onMaskKeyPress,\n onMaskFocus,\n onMaskBlur,\n onMaskPaste\n };\n}\n","import * as React from 'react';\n\n/**\n * Listens for the specified media query.\n *\n * @param query - The media query to match.\n * @param when - A boolean indicating whether the media query should be active.\n * @returns A boolean indicating whether the media query matches.\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const isMobile = useMatchMedia('(max-width: 768px)');\n *\n * return <div>{isMobile ? 'Mobile' : 'Desktop'}</div>;\n * };\n */\nexport function useMatchMedia(query: string, when: boolean = true): boolean {\n const [matches, setMatches] = React.useState(false);\n const matchMedia = React.useRef<MediaQueryList | null>(null);\n\n const handleChange = (event: MediaQueryListEvent) => setMatches(event.matches);\n const bind = () => matchMedia.current?.addEventListener('change', handleChange);\n const unbind = () => matchMedia.current?.removeEventListener('change', handleChange) && (matchMedia.current = null);\n\n React.useEffect(() => {\n if (when) {\n matchMedia.current = window.matchMedia(query);\n setMatches(matchMedia.current.matches);\n\n bind();\n }\n\n return () => {\n unbind();\n };\n }, [query, when]);\n\n return matches;\n}\n","import * as React from 'react';\n\n/**\n * Custom hook that runs a mount effect only once.\n * This is similar to `useEffect`, but it only runs on mount.\n *\n * @param {React.EffectCallback} effect the callback function\n * @returns {void}\n *\n * @example\n * ```tsx\n * const MyComponent = () => {\n * useMountEffect(() => {\n * console.log('Mounted');\n * });\n * };\n * ```\n */\nexport function useMountEffect(effect: React.EffectCallback): void {\n const mounted = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!mounted.current) {\n mounted.current = true;\n\n effect?.();\n }\n }, []);\n}\n","import * as React from 'react';\n\n/**\n * Used to merge and differentiate incoming props with the default props.\n * - Keys that exist in both `props1` and `props2` are placed in `props`, with values from `props1`.\n * - Keys that exist in `props1` but not in `props2` are placed in `attrs`.\n *\n * @template P1 The type of the incoming set of props.\n * @template P2 The type of the default set of props.\n *\n * @param props1 The incoming set of props (e.g., user-defined or dynamic props).\n * @param props2 The default set of props (e.g., default props).\n * @returns An object containing:\n * - `props`: A new object containing keys that exist in both `props1` and `props2`, using values from `props1`.\n * - `attrs`: A new object containing keys that exist only in `props1`, excluding any keys from `props2`.\n *\n * @example\n * ```ts\n * const { props, attrs } = useProps({ id: 'foo', className: 'bar' }, { className: 'baz' });\n *\n * console.log(props); // { className: 'bar' }\n * console.log(attrs); // { id: 'foo' }\n * ```\n */\nexport function useProps<P1, P2>(props1: P1 = {} as P1, props2: P2 = {} as P2) {\n type Props = Pick<P1 & P2, keyof P2>;\n type Attrs = Omit<P1, keyof P2>;\n type Result = { props: Props; attrs: Attrs };\n\n return React.useMemo(() => {\n const result: Result = { props: { ...props2 } as Props, attrs: {} as Attrs };\n\n Object.entries(props1 as Record<string, unknown>).forEach(([key, value]) => {\n if (key in (props2 as Record<string, unknown>)) {\n (result.props as Record<string, unknown>)[key] = value;\n } else {\n (result.attrs as Record<string, unknown>)[key] = value;\n }\n });\n\n return result;\n }, [props1, props2]);\n}\n","import * as React from 'react';\n\n/**\n * Custom hook that runs an unmount effect only once.\n * This is similar to `useEffect`, but it only runs on unmount.\n *\n * @param {React.EffectCallback} effect the callback function\n * @returns {void}\n *\n * @example\n * ```tsx\n * const Component = () => {\n * useUnmountEffect(() => {\n * console.log('Unmounted');\n * });\n * };\n * ```\n */\nexport function useUnmountEffect(effect: React.EffectCallback): void {\n React.useEffect(() => {\n return () => {\n effect?.();\n };\n }, []);\n}\n","import * as React from 'react';\n\n/**\n * Custom hook that runs an update effect whenever dependencies change.\n * This is similar to `useEffect`, but it does not run on mount.\n *\n * @param {React.EffectCallback} effect the callback function\n * @param {React.DependencyList} dependencies the dependencies\n * @returns {void}\n *\n * @example\n * ```tsx\n * const Component = ({ value }) => {\n * useUpdateEffect(() => {\n * console.log('Updated');\n * }, [value]);\n * };\n * ```\n */\nexport function useUpdateEffect(effect: React.EffectCallback, dependencies?: React.DependencyList): void {\n const mounted = React.useRef<boolean>(false);\n\n React.useEffect(() => {\n if (!mounted.current) {\n mounted.current = true;\n\n return;\n }\n\n return effect?.();\n }, dependencies);\n}\n","import * as React from 'react';\n\n/**\n * Starts a view transition.\n *\n * @returns A function that starts a view transition.\n *\n * @example\n * ```tsx\n * const Component = () => {\n * const startTransition = useViewTransition();\n *\n * const handleClick = () => {\n * startTransition(() => {\n * // Perform some work\n * });\n * };\n *\n * return <button onClick={handleClick}>Click me</button>;\n * };\n */\nexport function useViewTransition() {\n const startTransition = React.useCallback((callback: () => void) => {\n if (document.startViewTransition) {\n document.startViewTransition(() => {\n callback();\n });\n } else {\n callback();\n }\n }, []);\n\n return startTransition;\n}\n"],"mappings":"+VAAA,UAAYA,MAAW,QAchB,SAASC,GAAgBC,EAAiB,GAAY,CACzD,IAAMC,EAAW,QAAM,EAEvB,OAAa,UAAQ,IAAM,GAAGD,CAAM,GAAGC,EAAG,WAAW,SAAU,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,EAAG,CAACA,EAAID,CAAM,CAAC,CAC3G,CClBA,OAAS,WAAAE,OAAe,kBACxB,UAAYC,MAAW,QAiDhB,SAASC,GAAuC,CAAE,MAAAC,EAAO,aAAAC,EAAc,SAAAC,CAAS,EAAiF,CACpK,GAAM,CAACC,EAAYC,CAAa,EAAU,WAAwBH,GAAA,KAAAA,EAAgBD,CAAK,EAEjFK,EAAeL,IAAU,OACzBM,EAAgBD,EAAgBL,EAAcG,EAE9CI,EAAiB,cAClBC,GAA+C,CAE5C,GAAM,CAACC,EAAUC,CAAa,EAAIb,GAAQW,EAASF,EAAeD,CAAY,EAE9EH,GAAA,MAAAA,EAAWQ,GAENL,GACDD,EAAcK,CAAQ,CAE9B,EACA,CAACH,EAAeD,EAAcH,CAAQ,CAC1C,EAEA,MAAO,CAACI,EAAeC,EAAUF,CAAY,CACjD,CCvEA,OAAS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CxBA,UAAYC,MAAW,QAmBhB,SAASC,GAAgBC,EAA8BC,EAA2C,CACrG,IAAMC,EAAgB,SAAgB,EAAK,EAErC,YAAU,IAAM,CAClB,GAAI,CAACA,EAAQ,QAAS,CAClBA,EAAQ,QAAU,GAElB,MACJ,CAEA,OAAOF,GAAA,YAAAA,GACX,EAAGC,CAAY,CACnB,CC/BA,UAAYE,OAAW,QAqBhB,SAASC,IAAoB,CAWhC,OAV8B,eAAaC,GAAyB,CAC5D,SAAS,oBACT,SAAS,oBAAoB,IAAM,CAC/BA,EAAS,CACb,CAAC,EAEDA,EAAS,CAEjB,EAAG,CAAC,CAAC,CAGT","names":["React","useAttrSelector","prefix","id","resolve","React","useControlledState","value","defaultValue","onChange","valueState","setValueState","isControlled","computedValue","setValue","inValue","newValue","onChangeParam","getTargetElement","isNotEmpty","React","React","usePrevious","value","ref","useEventListener","target","type","listener","options","when","targetRef","listenerRef","prevListener","usePrevious","prevOptions","bind","bindOptions","bindTarget","isNotEmpty","unbind","getTargetElement","event","_a","dispose","updateTarget","listenerChanged","optionsChanged","listenerExists","React","useId","initialValue","idx","idState","setIdState","isAndroid","useKeyFilter","options","pattern","validateOnly","DEFAULT_MASKS","getRegex","onBeforeInput","event","validateKey","onKeyPress","onPaste","regex","c","key","value","validatePattern","useMountEffect","getUserAgent","React","useMask","options","mask","unmask","slotChar","autoClear","readOnly","onMaskChange","target","len","tests","buffer","defaultBuffer","partialPosition","androidChrome","focus","focusText","firstNonMaskPos","lastRequiredNonMaskPos","caretTimeoutId","oldVal","currentVal","onMaskInput","event","handleAndroidInput","handleInputChange","onMaskKeyDown","_a","k","pos","begin","end","iPhone","caret","seekPrev","seekNext","clearBuffer","shiftL","updateModelValue","checkVal","onMaskKeyPress","p","c","next","shiftR","writeBuffer","onMaskFocus","onMaskBlur","e","onMaskPaste","first","last","_b","getPlaceholder","i","j","t","curVal","start","allow","_c","_d","test","lastMatch","currentTest","isPasteEvent","unmaskValue","value","unmaskedBuffer","thisbuffer","val","finalValue","updateValue","updateModel","initMask","defs","ua","maskTokens","React","useMatchMedia","query","when","matches","setMatches","matchMedia","handleChange","event","bind","_a","unbind","React","useMountEffect","effect","mounted","React","useProps","props1","props2","result","__spreadValues","key","value","React","useUnmountEffect","effect","React","useUpdateEffect","effect","dependencies","mounted","React","useViewTransition","callback"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The options for the `useKeyFilter` hook.
|
|
3
|
+
*/
|
|
4
|
+
export interface UseKeyFilterOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Sets the pattern for key filtering.
|
|
7
|
+
* @default /./
|
|
8
|
+
*/
|
|
9
|
+
pattern?: 'pint' | 'int' | 'pnum' | 'money' | 'num' | 'hex' | 'email' | 'alpha' | 'alphanum' | RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* When enabled, instead of blocking keys, input is validated internally to test against the regular expression.
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
validateOnly?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface UseKeyFilterExposes {
|
|
17
|
+
/**
|
|
18
|
+
* Handles input events for key filter.
|
|
19
|
+
* Processes character input and composition events while applying the filter pattern.
|
|
20
|
+
* @param event - The form or composition event from the input element
|
|
21
|
+
*/
|
|
22
|
+
onBeforeInput: (event: React.CompositionEvent<HTMLInputElement>) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Handles keypress events for character input validation.
|
|
25
|
+
* Validates and places characters according to the filter pattern.
|
|
26
|
+
* @param event - The keyboard event from the input element
|
|
27
|
+
*/
|
|
28
|
+
onKeyPress: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Handles paste events for clipboard content insertion.
|
|
31
|
+
* Processes pasted content according to the mask pattern.
|
|
32
|
+
* @param event - The clipboard event from the input element
|
|
33
|
+
*/
|
|
34
|
+
onPaste: (event: React.ClipboardEvent<HTMLInputElement>) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Validates the current input value against the filter pattern.
|
|
37
|
+
* @param event - The form event from the input element
|
|
38
|
+
* @returns true if the value matches the pattern, false otherwise
|
|
39
|
+
*/
|
|
40
|
+
validate: (event: React.FormEvent<HTMLInputElement>) => boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function useKeyFilter(options: UseKeyFilterOptions): UseKeyFilterExposes;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{isAndroid as s}from"@primeuix/utils";function v(p){let{pattern:r=/./,validateOnly:o=!1}=p,u={pint:/[\d]/,int:/[\d-]/,pnum:/[\d.]/,money:/[\d.\s,]/,num:/[\d-.]/,hex:/[0-9a-f]/i,email:/[a-z0-9_.-@]/i,alpha:/[a-z_]/i,alphanum:/[a-z0-9_]/},i=()=>typeof r=="string"?u[r]:r,c=e=>{o||!s()||l(e,e.data)},m=e=>{o||s()||e.ctrlKey||e.altKey||e.metaKey||l(e,e.key)},d=e=>{if(o)return;let t=i();[...e.clipboardData.getData("text")].forEach(a=>{if(!t.test(a))return e.preventDefault(),!1})},l=(e,t)=>{if(t==null||!(t.length<=2))return;i().test(t)||e.preventDefault()};return{onBeforeInput:c,onKeyPress:m,onPaste:d,validate:e=>{let t=e.target.value,n=!0,a=i();return t&&!a.test(t)&&(n=!1),n}}}export{v as useKeyFilter};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/use-key-filter/index.ts"],"sourcesContent":["import { isAndroid } from '@primeuix/utils';\n\n/**\n * The options for the `useKeyFilter` hook.\n */\nexport interface UseKeyFilterOptions {\n /**\n * Sets the pattern for key filtering.\n * @default /./\n */\n pattern?: 'pint' | 'int' | 'pnum' | 'money' | 'num' | 'hex' | 'email' | 'alpha' | 'alphanum' | RegExp;\n /**\n * When enabled, instead of blocking keys, input is validated internally to test against the regular expression.\n * @default false\n */\n validateOnly?: boolean;\n}\n\nexport interface UseKeyFilterExposes {\n /**\n * Handles input events for key filter.\n * Processes character input and composition events while applying the filter pattern.\n * @param event - The form or composition event from the input element\n */\n onBeforeInput: (event: React.CompositionEvent<HTMLInputElement>) => void;\n /**\n * Handles keypress events for character input validation.\n * Validates and places characters according to the filter pattern.\n * @param event - The keyboard event from the input element\n */\n onKeyPress: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n /**\n * Handles paste events for clipboard content insertion.\n * Processes pasted content according to the mask pattern.\n * @param event - The clipboard event from the input element\n */\n onPaste: (event: React.ClipboardEvent<HTMLInputElement>) => void;\n /**\n * Validates the current input value against the filter pattern.\n * @param event - The form event from the input element\n * @returns true if the value matches the pattern, false otherwise\n */\n validate: (event: React.FormEvent<HTMLInputElement>) => boolean;\n}\n\nexport function useKeyFilter(options: UseKeyFilterOptions): UseKeyFilterExposes {\n const { pattern = /./, validateOnly = false } = options;\n\n const DEFAULT_MASKS = {\n pint: /[\\d]/,\n int: /[\\d-]/,\n pnum: /[\\d.]/,\n money: /[\\d.\\s,]/,\n num: /[\\d-.]/,\n hex: /[0-9a-f]/i,\n email: /[a-z0-9_.-@]/i,\n alpha: /[a-z_]/i,\n alphanum: /[a-z0-9_]/\n };\n\n const getRegex = (): RegExp => {\n return typeof pattern === 'string' ? DEFAULT_MASKS[pattern] : pattern;\n };\n\n const onBeforeInput = (event: React.CompositionEvent<HTMLInputElement>) => {\n // android devices must use beforeinput https://stackoverflow.com/questions/36753548/keycode-on-android-is-always-229\n if (validateOnly || !isAndroid()) {\n return;\n }\n\n validateKey(event, event.data);\n };\n\n const onKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {\n // non android devices use keydown\n if (validateOnly || isAndroid()) {\n return;\n }\n\n if (event.ctrlKey || event.altKey || event.metaKey) {\n return;\n }\n\n validateKey(event, event.key);\n };\n\n const onPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {\n if (validateOnly) {\n return;\n }\n\n const regex = getRegex();\n const clipboard = event.clipboardData.getData('text');\n\n // loop over each letter pasted and if any fail prevent the paste\n [...clipboard].forEach((c) => {\n if (!regex.test(c)) {\n event.preventDefault();\n\n return false;\n }\n });\n };\n\n const validateKey = (event: React.CompositionEvent<HTMLInputElement> | React.KeyboardEvent<HTMLInputElement>, key: string) => {\n if (key === null || key === undefined) {\n return;\n }\n\n // some AZERTY keys come in with 2 chars like ´ç if Dead key is pressed first\n const isPrintableKey = key.length <= 2;\n\n if (!isPrintableKey) {\n return;\n }\n\n const regex = getRegex();\n\n if (!regex.test(key)) {\n event.preventDefault();\n }\n };\n\n const validate = (event: React.FormEvent<HTMLInputElement>) => {\n const value = (event.target as HTMLInputElement).value;\n let validatePattern = true;\n\n const regex = getRegex();\n\n if (value && !regex.test(value)) {\n validatePattern = false;\n }\n\n return validatePattern;\n };\n\n return {\n onBeforeInput,\n onKeyPress,\n onPaste,\n validate\n };\n}\n"],"mappings":"AAAA,OAAS,aAAAA,MAAiB,kBA6CnB,SAASC,EAAaC,EAAmD,CAC5E,GAAM,CAAE,QAAAC,EAAU,IAAK,aAAAC,EAAe,EAAM,EAAIF,EAE1CG,EAAgB,CAClB,KAAM,OACN,IAAK,QACL,KAAM,QACN,MAAO,WACP,IAAK,SACL,IAAK,YACL,MAAO,gBACP,MAAO,UACP,SAAU,WACd,EAEMC,EAAW,IACN,OAAOH,GAAY,SAAWE,EAAcF,CAAO,EAAIA,EAG5DI,EAAiBC,GAAoD,CAEnEJ,GAAgB,CAACJ,EAAU,GAI/BS,EAAYD,EAAOA,EAAM,IAAI,CACjC,EAEME,EAAcF,GAAiD,CAE7DJ,GAAgBJ,EAAU,GAI1BQ,EAAM,SAAWA,EAAM,QAAUA,EAAM,SAI3CC,EAAYD,EAAOA,EAAM,GAAG,CAChC,EAEMG,EAAWH,GAAkD,CAC/D,GAAIJ,EACA,OAGJ,IAAMQ,EAAQN,EAAS,EAIvB,CAAC,GAHiBE,EAAM,cAAc,QAAQ,MAAM,CAGvC,EAAE,QAASK,GAAM,CAC1B,GAAI,CAACD,EAAM,KAAKC,CAAC,EACb,OAAAL,EAAM,eAAe,EAEd,EAEf,CAAC,CACL,EAEMC,EAAc,CAACD,EAAyFM,IAAgB,CAQ1H,GAPIA,GAAQ,MAOR,EAFmBA,EAAI,QAAU,GAGjC,OAGUR,EAAS,EAEZ,KAAKQ,CAAG,GACfN,EAAM,eAAe,CAE7B,EAeA,MAAO,CACH,cAAAD,EACA,WAAAG,EACA,QAAAC,EACA,SAjBcH,GAA6C,CAC3D,IAAMO,EAASP,EAAM,OAA4B,MAC7CQ,EAAkB,GAEhBJ,EAAQN,EAAS,EAEvB,OAAIS,GAAS,CAACH,EAAM,KAAKG,CAAK,IAC1BC,EAAkB,IAGfA,CACX,CAOA,CACJ","names":["isAndroid","useKeyFilter","options","pattern","validateOnly","DEFAULT_MASKS","getRegex","onBeforeInput","event","validateKey","onKeyPress","onPaste","regex","c","key","value","validatePattern"]}
|
|
File without changes
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Event fired when the component's state changes.
|
|
4
|
+
*/
|
|
5
|
+
export interface UseMaskChangeEvent {
|
|
6
|
+
/**
|
|
7
|
+
* The value of the component.
|
|
8
|
+
*/
|
|
9
|
+
value: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The options for the `useMask` hook.
|
|
13
|
+
*/
|
|
14
|
+
export interface UseMaskOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Mask pattern.
|
|
17
|
+
*/
|
|
18
|
+
mask: string;
|
|
19
|
+
/**
|
|
20
|
+
* Defines if model sets the raw unmasked value to bound value or the formatted mask value.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
unmask?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Placeholder character in mask, default is underscore.
|
|
26
|
+
* @default _
|
|
27
|
+
*/
|
|
28
|
+
slotChar?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Clears the incomplete value on blur.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
autoClear?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the components are clickable or not.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
readOnly?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Callback function that is called when the value is changed.
|
|
41
|
+
* @param event The event that triggered the change.
|
|
42
|
+
* @param event.value The value of the component.
|
|
43
|
+
* @returns void
|
|
44
|
+
*/
|
|
45
|
+
onMaskChange?: (event: UseMaskChangeEvent) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Reference to the mask element.
|
|
48
|
+
*/
|
|
49
|
+
target: HTMLInputElement;
|
|
50
|
+
}
|
|
51
|
+
export interface UseMaskExposes {
|
|
52
|
+
/**
|
|
53
|
+
* Handles input events for the masked input field.
|
|
54
|
+
* Processes character input and composition events while applying the mask pattern.
|
|
55
|
+
* @param event - The form or composition event from the input element
|
|
56
|
+
*/
|
|
57
|
+
onMaskInput: (event: React.FormEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Handles keydown events for special key operations.
|
|
60
|
+
* Manages backspace, delete, escape, and enter key behaviors.
|
|
61
|
+
* @param event - The keyboard event from the input element
|
|
62
|
+
*/
|
|
63
|
+
onMaskKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Handles keypress events for character input validation.
|
|
66
|
+
* Validates and places characters according to the mask pattern.
|
|
67
|
+
* @param event - The keyboard event from the input element
|
|
68
|
+
*/
|
|
69
|
+
onMaskKeyPress: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Handles focus events when the input gains focus.
|
|
72
|
+
* Initializes the mask display and sets the cursor position.
|
|
73
|
+
* @param event - The focus event from the input element
|
|
74
|
+
*/
|
|
75
|
+
onMaskFocus: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Handles blur events when the input loses focus.
|
|
78
|
+
* Validates the final value and triggers change events if needed.
|
|
79
|
+
* @param event - The focus event from the input element
|
|
80
|
+
*/
|
|
81
|
+
onMaskBlur: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Handles paste events for clipboard content insertion.
|
|
84
|
+
* Processes pasted content according to the mask pattern.
|
|
85
|
+
* @param event - The clipboard event from the input element
|
|
86
|
+
*/
|
|
87
|
+
onMaskPaste: (event: React.ClipboardEvent<HTMLInputElement>) => void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* useMask hook is used to enter input in a certain format such as numeric, date, currency, email and phone.
|
|
91
|
+
*
|
|
92
|
+
* @param {UseMaskOptions} options - The options for the mask.
|
|
93
|
+
* @returns {UseMaskExposes} - The exposed methods for the mask.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* const { onMaskInput, onMaskKeyDown, onMaskKeyPress, onMaskFocus, onMaskBlur, onMaskPaste } = useMask({
|
|
98
|
+
* mask: '99/99/9999',
|
|
99
|
+
* onMaskChange: (event: UseMaskChangeEvent) => setValue(event.value ?? ''),
|
|
100
|
+
* target: ref
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* return (
|
|
104
|
+
* <div className="card flex justify-center">
|
|
105
|
+
* <InputText ref={ref} value={value} placeholder="99/99/9999" onInput={onMaskInput} onKeyDown={onMaskKeyDown} onKeyPress={onMaskKeyPress} onFocus={onMaskFocus} onBlur={onMaskBlur} onPaste={onMaskPaste} />
|
|
106
|
+
* </div>
|
|
107
|
+
* );
|
|
108
|
+
*/
|
|
109
|
+
export declare function useMask(options: UseMaskOptions): UseMaskExposes;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useMountEffect as te}from"@primereact/hooks";import{getUserAgent as x}from"@primeuix/utils";import*as i from"react";function ue(j){let{mask:m,unmask:N,slotChar:L="_",autoClear:O=!0,readOnly:v=!1,onMaskChange:K,target:s}=j,o=i.useRef(0),a=i.useRef([]),l=i.useRef([]),k=i.useRef(null),h=i.useRef(0),w=i.useRef(!1),P=i.useRef(!1),T=i.useRef(null),M=i.useRef(null),S=i.useRef(0),H=i.useRef(null),I=i.useRef(null),A=i.useRef(null),q=e=>{"isComposing"in e&&e.isComposing||(w.current?X():D(e))},z=e=>{var b;if(v)return;let t=e.code,r,n,u,c=/iphone/i.test(x());if(I.current=s==null?void 0:s.value,t==="Backspace"||t==="Delete"||c&&t==="Escape"){if(r=f(),!r)return;n=r.begin,u=r.end,u-n===0&&(n=t!=="Delete"?Q(n):u=d(n-1),u=t==="Delete"?d(u):u),y(n,u),F(n,u-1),g(e.target.value),e.preventDefault()}else t==="Enter"?(s.blur(),g(e.target.value)):t==="Escape"&&(s&&(s.value=(b=T.current)!=null?b:""),f(0,p()),g(e.target.value),e.preventDefault())},J=e=>{var b;if(v)return;let t=e.code,r=f(),n,u,c;r&&(e.ctrlKey||e.altKey||e.metaKey||e.shiftKey||e.key==="CapsLock"||e.key==="Escape"||e.key==="Tab"||(t&&t!=="Enter"&&(r.end-r.begin!==0&&(y(r.begin,r.end),F(r.begin,r.end-1)),n=d(r.begin-1),n<o.current&&(u=e.key,(b=a.current[n])!=null&&b.test(u)&&(W(n),l.current[n]=u,E(),c=d(n),/android/i.test(x())?setTimeout(()=>{f(c)},0):f(c))),e.preventDefault()),g(e.target.value)))},Z=()=>{if(!v)if(H.current&&clearTimeout(H.current),P.current=!0,T.current=s.value,!s.value||s.value===k.current)requestAnimationFrame(()=>{s===document.activeElement&&f(0,0)});else{let e=p();H.current=setTimeout(()=>{s===document.activeElement&&(E(),e===(m==null?void 0:m.replace("?","").length)?f(0,e):f(e))},10)}},_=e=>{if(P.current=!1,p(),g(e.target.value),s.value!==T.current){let t=new Event("change",{bubbles:!0,cancelable:!1});s.dispatchEvent(t)}},G=e=>{D(e)},f=(e,t)=>{var u,c;let r=0,n=0;return typeof e=="number"?(r=e,n=typeof t=="number"?t:r,s.setSelectionRange(r,n)):s&&(r=(u=s.selectionStart)!=null?u:0,n=(c=s.selectionEnd)!=null?c:0),{begin:r,end:n}},R=e=>e<L.length?L.charAt(e):L.charAt(0),d=e=>{for(;++e<o.current&&!a.current[e];);return e},Q=e=>{for(;--e>=0&&!a.current[e];);return e},F=(e,t)=>{var u,c;let r,n;if(!(e<0)){for(r=e,n=d(t);r<o.current;r++)if(a.current[r]){if(n<o.current&&((u=a.current[r])!=null&&u.test(l.current[n])))l.current[r]=l.current[n],l.current[n]=R(n);else break;n=d(n)}E(),f(Math.max((c=M.current)!=null?c:0,e))}},W=e=>{var c;let t,r,n,u;for(t=e,r=R(e);t<o.current;t++)if(a.current[t])if(n=d(t),u=l.current[t],l.current[t]=r,n<o.current&&((c=a.current[n])!=null&&c.test(u)))r=u;else break},X=()=>{var r;let e=s.value,t=f();if(t)if(I.current&&I.current.length&&I.current.length>e.length){for(p(!0);t.begin>0&&!a.current[t.begin-1];)t.begin--;if(t.begin===0)for(;t.begin<((r=M.current)!=null?r:0)&&!a.current[t.begin];)t.begin++;f(t.begin,t.begin)}else{for(p(!0);t.begin<o.current&&!a.current[t.begin];)t.begin++;f(t.begin,t.begin)}},y=(e,t)=>{let r;for(r=e;r<t&&r<o.current;r++)a.current[r]&&(l.current[r]=R(r))},E=()=>{s&&(s.value=l.current.join(""))},p=(e=!1)=>{var b,C,V,B;let t=s.value,r=-1,n,u,c;for(n=0,c=0;n<o.current;n++){let U=a.current[n];if(U!==null){for(l.current[n]=R(n);c++<((b=t==null?void 0:t.length)!=null?b:0);)if(u=(C=t==null?void 0:t.charAt(c-1))!=null?C:"",U.test(u)){l.current[n]=u,r=n;break}if(c>((V=t==null?void 0:t.length)!=null?V:0)){y(n+1,o.current);break}}else l.current[n]===(t==null?void 0:t.charAt(c))&&c++,n<h.current&&(r=n)}return e?E():r+1<h.current?O||l.current.join("")===k.current?(s.value&&(s.value=""),y(0,o.current)):E():(E(),s&&(s.value=s.value.substring(0,r+1))),h.current?n:(B=M.current)!=null?B:0},D=e=>{let t=e.type==="paste";if(v||t)return;let r=p(!0);f(r),g(e.target.value)},Y=e=>{let t=[],r=e.split("");for(let n=0;n<r.length;n++){let u=r[n];a.current[n]&&u!==R(n)&&t.push(u)}return t.join("")},g=e=>{if(A.current===e)return;let t=N?Y(e):e,r=k.current!==t?t:"";A.current=e,s&&(s.value=r),K&&K({value:r})},$=(e=!0)=>{s&&(s.value==null?(s.value="",e&&g("")):(p(),setTimeout(()=>{s&&(E(),p(),e&&g(s.value))},10)),T.current=s.value)},ee=()=>{a.current=[],h.current=m?m.length:0,o.current=m?m.length:0,M.current=null;let e={9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},t=x();w.current=/chrome/i.test(t)&&/android/i.test(t);let r=m?m.split(""):"";for(let n=0;n<r.length;n++){let u=r[n];u==="?"?(o.current--,h.current=n):e[u]?(a.current.push(new RegExp(e[u])),M.current===null&&(M.current=a.current.length-1),n<h.current&&(S.current=a.current.length-1)):a.current.push(null)}l.current=[];for(let n=0;n<r.length;n++){let u=r[n];u!=="?"&&(e[u]?l.current.push(R(n)):l.current.push(u))}k.current=l.current.join(""),$(!1)};return te(()=>{ee()}),{onMaskInput:q,onMaskKeyDown:z,onMaskKeyPress:J,onMaskFocus:Z,onMaskBlur:_,onMaskPaste:G}}export{ue as useMask};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/use-mask/index.ts"],"sourcesContent":["import { useMountEffect } from '@primereact/hooks';\nimport { getUserAgent } from '@primeuix/utils';\nimport * as React from 'react';\n\n/**\n * Event fired when the component's state changes.\n */\nexport interface UseMaskChangeEvent {\n /**\n * The value of the component.\n */\n value: string | undefined;\n}\n\n/**\n * The options for the `useMask` hook.\n */\nexport interface UseMaskOptions {\n /**\n * Mask pattern.\n */\n mask: string;\n /**\n * Defines if model sets the raw unmasked value to bound value or the formatted mask value.\n * @default false\n */\n unmask?: string;\n /**\n * Placeholder character in mask, default is underscore.\n * @default _\n */\n slotChar?: string;\n /**\n * Clears the incomplete value on blur.\n * @default true\n */\n autoClear?: boolean;\n /**\n * Whether the components are clickable or not.\n * @default false\n */\n readOnly?: boolean;\n /**\n * Callback function that is called when the value is changed.\n * @param event The event that triggered the change.\n * @param event.value The value of the component.\n * @returns void\n */\n onMaskChange?: (event: UseMaskChangeEvent) => void;\n /**\n * Reference to the mask element.\n */\n target: HTMLInputElement;\n}\n\nexport interface UseMaskExposes {\n /**\n * Handles input events for the masked input field.\n * Processes character input and composition events while applying the mask pattern.\n * @param event - The form or composition event from the input element\n */\n onMaskInput: (event: React.FormEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) => void;\n /**\n * Handles keydown events for special key operations.\n * Manages backspace, delete, escape, and enter key behaviors.\n * @param event - The keyboard event from the input element\n */\n onMaskKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n /**\n * Handles keypress events for character input validation.\n * Validates and places characters according to the mask pattern.\n * @param event - The keyboard event from the input element\n */\n onMaskKeyPress: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n /**\n * Handles focus events when the input gains focus.\n * Initializes the mask display and sets the cursor position.\n * @param event - The focus event from the input element\n */\n onMaskFocus: (event: React.FocusEvent<HTMLInputElement>) => void;\n /**\n * Handles blur events when the input loses focus.\n * Validates the final value and triggers change events if needed.\n * @param event - The focus event from the input element\n */\n onMaskBlur: (event: React.FocusEvent<HTMLInputElement>) => void;\n /**\n * Handles paste events for clipboard content insertion.\n * Processes pasted content according to the mask pattern.\n * @param event - The clipboard event from the input element\n */\n onMaskPaste: (event: React.ClipboardEvent<HTMLInputElement>) => void;\n}\n\n/**\n * useMask hook is used to enter input in a certain format such as numeric, date, currency, email and phone.\n *\n * @param {UseMaskOptions} options - The options for the mask.\n * @returns {UseMaskExposes} - The exposed methods for the mask.\n *\n * @example\n * ```tsx\n * const { onMaskInput, onMaskKeyDown, onMaskKeyPress, onMaskFocus, onMaskBlur, onMaskPaste } = useMask({\n * mask: '99/99/9999',\n * onMaskChange: (event: UseMaskChangeEvent) => setValue(event.value ?? ''),\n * target: ref\n * });\n *\n * return (\n * <div className=\"card flex justify-center\">\n * <InputText ref={ref} value={value} placeholder=\"99/99/9999\" onInput={onMaskInput} onKeyDown={onMaskKeyDown} onKeyPress={onMaskKeyPress} onFocus={onMaskFocus} onBlur={onMaskBlur} onPaste={onMaskPaste} />\n * </div>\n * );\n */\nexport function useMask(options: UseMaskOptions): UseMaskExposes {\n const { mask, unmask, slotChar = '_', autoClear = true, readOnly = false, onMaskChange, target } = options;\n\n const len = React.useRef(0);\n const tests = React.useRef<Array<RegExp | null>>([]);\n const buffer = React.useRef<string[]>([]);\n const defaultBuffer = React.useRef<string | null>(null);\n const partialPosition = React.useRef<number>(0);\n const androidChrome = React.useRef(false);\n const focus = React.useRef(false);\n const focusText = React.useRef<string | null>(null);\n const firstNonMaskPos = React.useRef<number | null>(null);\n const lastRequiredNonMaskPos = React.useRef<number>(0);\n const caretTimeoutId = React.useRef<NodeJS.Timeout | null>(null);\n const oldVal = React.useRef<string | null>(null);\n const currentVal = React.useRef<string | null>(null);\n\n const onMaskInput = (event: React.FormEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) => {\n // Check if the event is part of a text composition process (e.g., for Asian languages).\n // If event.isComposing is true, it means the user is still composing text and the input is not finalized.\n if ('isComposing' in event && event.isComposing) {\n return;\n }\n\n if (androidChrome.current) handleAndroidInput();\n else handleInputChange(event);\n };\n\n const onMaskKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) {\n return;\n }\n\n const k = event.code;\n let pos, begin, end;\n const iPhone = /iphone/i.test(getUserAgent());\n\n oldVal.current = target?.value as string;\n\n //backspace, delete, and escape get special treatment\n if (k === 'Backspace' || k === 'Delete' || (iPhone && k === 'Escape')) {\n pos = caret();\n\n if (!pos) {\n return;\n }\n\n begin = pos.begin;\n end = pos.end;\n\n if (end - begin === 0) {\n begin = k !== 'Delete' ? seekPrev(begin) : (end = seekNext(begin - 1));\n end = k === 'Delete' ? seekNext(end) : end;\n }\n\n clearBuffer(begin, end);\n shiftL(begin, end - 1);\n updateModelValue((event.target as HTMLInputElement).value);\n\n event.preventDefault();\n } else if (k === 'Enter') {\n // enter\n target.blur();\n updateModelValue((event.target as HTMLInputElement).value);\n } else if (k === 'Escape') {\n // escape\n if (target) {\n target.value = focusText.current ?? '';\n }\n\n caret(0, checkVal());\n updateModelValue((event.target as HTMLInputElement).value);\n event.preventDefault();\n }\n };\n\n const onMaskKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) {\n return;\n }\n\n const k = event.code,\n pos = caret();\n let p: number, c: string, next: number;\n\n if (!pos) {\n return;\n }\n\n if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey || event.key === 'CapsLock' || event.key === 'Escape' || event.key === 'Tab') {\n //Ignore\n return;\n } else if (k && k !== 'Enter') {\n if (pos.end - pos.begin !== 0) {\n clearBuffer(pos.begin, pos.end);\n shiftL(pos.begin, pos.end - 1);\n }\n\n p = seekNext(pos.begin - 1);\n\n if (p < len.current) {\n c = event.key;\n\n if (tests.current[p]?.test(c)) {\n shiftR(p);\n\n buffer.current[p] = c;\n writeBuffer();\n next = seekNext(p);\n\n if (/android/i.test(getUserAgent())) {\n //Path for CSP Violation on FireFox OS 1.1\n const proxy = () => {\n caret(next);\n };\n\n setTimeout(proxy, 0);\n } else {\n caret(next);\n }\n }\n }\n\n event.preventDefault();\n }\n\n updateModelValue((event.target as HTMLInputElement).value);\n };\n\n const onMaskFocus = () => {\n if (readOnly) {\n return;\n }\n\n if (caretTimeoutId.current) {\n clearTimeout(caretTimeoutId.current as NodeJS.Timeout);\n }\n\n focus.current = true;\n focusText.current = target.value as string;\n\n if (!target.value || target.value === defaultBuffer.current) {\n requestAnimationFrame(() => {\n if (target === document.activeElement) {\n caret(0, 0);\n }\n });\n } else {\n const pos = checkVal();\n\n caretTimeoutId.current = setTimeout(() => {\n if (target !== document.activeElement) {\n return;\n }\n\n writeBuffer();\n\n if (pos === mask?.replace('?', '').length) {\n caret(0, pos);\n } else {\n caret(pos);\n }\n }, 10);\n }\n };\n\n const onMaskBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n focus.current = false;\n checkVal();\n updateModelValue(event.target.value);\n\n if (target.value !== focusText.current) {\n const e = new Event('change', { bubbles: true, cancelable: false });\n\n target.dispatchEvent(e);\n }\n };\n\n const onMaskPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {\n handleInputChange(event);\n };\n\n const caret = (first?: number, last?: number): { begin: number; end: number } | undefined => {\n let begin = 0,\n end = 0;\n\n if (typeof first === 'number') {\n begin = first;\n end = typeof last === 'number' ? last : begin;\n\n target.setSelectionRange(begin, end);\n } else {\n if (target) {\n begin = target.selectionStart ?? 0;\n end = target.selectionEnd ?? 0;\n }\n }\n\n return { begin, end };\n };\n\n const getPlaceholder = (i: number) => {\n if (i < slotChar.length) {\n return slotChar.charAt(i);\n }\n\n return slotChar.charAt(0);\n };\n\n const seekNext = (pos: number) => {\n while (++pos < len.current && !tests.current[pos]);\n\n return pos;\n };\n\n const seekPrev = (pos: number) => {\n while (--pos >= 0 && !tests.current[pos]);\n\n return pos;\n };\n\n const shiftL = (begin: number, end: number) => {\n let i, j;\n\n if (begin < 0) {\n return;\n }\n\n for (i = begin, j = seekNext(end); i < len.current; i++) {\n if (tests.current[i]) {\n if (j < len.current && tests.current[i]?.test(buffer.current[j])) {\n buffer.current[i] = buffer.current[j];\n buffer.current[j] = getPlaceholder(j);\n } else {\n break;\n }\n\n j = seekNext(j);\n }\n }\n\n writeBuffer();\n caret(Math.max(firstNonMaskPos.current ?? 0, begin));\n };\n\n const shiftR = (pos: number) => {\n let i, c, j, t;\n\n for (i = pos, c = getPlaceholder(pos); i < len.current; i++) {\n if (tests.current[i]) {\n j = seekNext(i);\n t = buffer.current[i];\n buffer.current[i] = c;\n\n if (j < len.current && tests.current[j]?.test(t)) {\n c = t;\n } else {\n break;\n }\n }\n }\n };\n\n const handleAndroidInput = () => {\n const curVal = target.value as string;\n const pos = caret();\n\n if (!pos) {\n return;\n }\n\n if (oldVal.current && oldVal.current.length && oldVal.current.length > curVal.length) {\n // a deletion or backspace happened\n checkVal(true);\n while (pos.begin > 0 && !tests.current[pos.begin - 1]) pos.begin--;\n\n if (pos.begin === 0) {\n while (pos.begin < (firstNonMaskPos.current ?? 0) && !tests.current[pos.begin]) pos.begin++;\n }\n\n caret(pos.begin, pos.begin);\n } else {\n checkVal(true);\n while (pos.begin < len.current && !tests.current[pos.begin]) pos.begin++;\n\n caret(pos.begin, pos.begin);\n }\n };\n\n const clearBuffer = (start: number, end: number) => {\n let i;\n\n for (i = start; i < end && i < len.current; i++) {\n if (tests.current[i]) {\n buffer.current[i] = getPlaceholder(i);\n }\n }\n };\n\n const writeBuffer = () => {\n if (target) {\n target.value = buffer.current.join('');\n }\n };\n\n const checkVal = (allow = false): number => {\n //try to place characters where they belong\n const test = target.value;\n let lastMatch = -1,\n i,\n c,\n pos;\n\n for (i = 0, pos = 0; i < len.current; i++) {\n const currentTest = tests.current[i];\n\n if (currentTest !== null) {\n buffer.current[i] = getPlaceholder(i);\n\n while (pos++ < (test?.length ?? 0)) {\n c = test?.charAt(pos - 1) ?? '';\n\n if (currentTest.test(c)) {\n buffer.current[i] = c;\n lastMatch = i;\n break;\n }\n }\n\n if (pos > (test?.length ?? 0)) {\n clearBuffer(i + 1, len.current);\n break;\n }\n } else {\n if (buffer.current[i] === test?.charAt(pos)) {\n pos++;\n }\n\n if (i < partialPosition.current) {\n lastMatch = i;\n }\n }\n }\n\n if (allow) {\n writeBuffer();\n } else if (lastMatch + 1 < partialPosition.current) {\n if (autoClear || buffer.current.join('') === defaultBuffer.current) {\n // Invalid value. Remove it and replace it with the\n // mask, which is the default behavior.\n if (target.value) {\n target.value = '';\n }\n\n clearBuffer(0, len.current);\n } else {\n // Invalid value, but we opt to show the value to the\n // user and allow them to correct their mistake.\n writeBuffer();\n }\n } else {\n writeBuffer();\n\n if (target) {\n target.value = target.value.substring(0, lastMatch + 1);\n }\n }\n\n return partialPosition.current ? i : (firstNonMaskPos.current ?? 0);\n };\n\n const handleInputChange = (event: React.FormEvent<HTMLInputElement> | React.ClipboardEvent<HTMLInputElement>) => {\n const isPasteEvent = event.type === 'paste';\n\n if (readOnly || isPasteEvent) {\n return;\n }\n\n const pos = checkVal(true);\n\n caret(pos);\n updateModelValue((event.target as HTMLInputElement).value);\n };\n\n const unmaskValue = (value: string) => {\n const unmaskedBuffer = [];\n const thisbuffer = value.split('');\n\n for (let i = 0; i < thisbuffer.length; i++) {\n const c = thisbuffer[i];\n\n if (tests.current[i] && c !== getPlaceholder(i)) {\n unmaskedBuffer.push(c);\n }\n }\n\n return unmaskedBuffer.join('');\n };\n\n const updateModelValue = (value: string) => {\n if (currentVal.current === value) return;\n\n const val = unmask ? unmaskValue(value) : value;\n const finalValue = defaultBuffer.current !== val ? val : '';\n\n currentVal.current = value;\n\n if (target) {\n target.value = finalValue;\n }\n\n // Call the onMaskChange callback to update React state\n if (onMaskChange) {\n onMaskChange({ value: finalValue });\n }\n };\n\n const updateValue = (updateModel = true) => {\n if (target) {\n if (target.value == null) {\n target.value = '';\n\n if (updateModel) {\n updateModelValue('');\n }\n } else {\n checkVal();\n\n setTimeout(() => {\n if (target) {\n writeBuffer();\n checkVal();\n\n if (updateModel) updateModelValue(target.value);\n }\n }, 10);\n }\n\n focusText.current = target.value;\n }\n };\n\n const initMask = () => {\n tests.current = [];\n partialPosition.current = mask ? mask.length : 0;\n len.current = mask ? mask.length : 0;\n firstNonMaskPos.current = null;\n const defs = {\n 9: '[0-9]',\n a: '[A-Za-z]',\n '*': '[A-Za-z0-9]'\n } as Record<string, string>;\n\n const ua = getUserAgent();\n\n androidChrome.current = /chrome/i.test(ua) && /android/i.test(ua);\n\n const maskTokens = mask ? mask.split('') : '';\n\n for (let i = 0; i < maskTokens.length; i++) {\n const c = maskTokens[i];\n\n if (c === '?') {\n len.current--;\n partialPosition.current = i;\n } else if (defs[c]) {\n tests.current.push(new RegExp(defs[c]));\n\n if (firstNonMaskPos.current === null) {\n firstNonMaskPos.current = tests.current.length - 1;\n }\n\n if (i < partialPosition.current) {\n lastRequiredNonMaskPos.current = tests.current.length - 1;\n }\n } else {\n tests.current.push(null);\n }\n }\n\n buffer.current = [];\n\n for (let i = 0; i < maskTokens.length; i++) {\n const c = maskTokens[i];\n\n if (c !== '?') {\n if (defs[c]) buffer.current.push(getPlaceholder(i));\n else buffer.current.push(c);\n }\n }\n\n defaultBuffer.current = buffer.current.join('');\n\n updateValue(false);\n };\n\n useMountEffect(() => {\n initMask();\n });\n\n return {\n onMaskInput,\n onMaskKeyDown,\n onMaskKeyPress,\n onMaskFocus,\n onMaskBlur,\n onMaskPaste\n };\n}\n"],"mappings":"AAAA,OAAS,kBAAAA,OAAsB,oBAC/B,OAAS,gBAAAC,MAAoB,kBAC7B,UAAYC,MAAW,QAgHhB,SAASC,GAAQC,EAAyC,CAC7D,GAAM,CAAE,KAAAC,EAAM,OAAAC,EAAQ,SAAAC,EAAW,IAAK,UAAAC,EAAY,GAAM,SAAAC,EAAW,GAAO,aAAAC,EAAc,OAAAC,CAAO,EAAIP,EAE7FQ,EAAY,SAAO,CAAC,EACpBC,EAAc,SAA6B,CAAC,CAAC,EAC7CC,EAAe,SAAiB,CAAC,CAAC,EAClCC,EAAsB,SAAsB,IAAI,EAChDC,EAAwB,SAAe,CAAC,EACxCC,EAAsB,SAAO,EAAK,EAClCC,EAAc,SAAO,EAAK,EAC1BC,EAAkB,SAAsB,IAAI,EAC5CC,EAAwB,SAAsB,IAAI,EAClDC,EAA+B,SAAe,CAAC,EAC/CC,EAAuB,SAA8B,IAAI,EACzDC,EAAe,SAAsB,IAAI,EACzCC,EAAmB,SAAsB,IAAI,EAE7CC,EAAeC,GAAwF,CAGrG,gBAAiBA,GAASA,EAAM,cAIhCT,EAA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","mask","unmask","slotChar","autoClear","readOnly","onMaskChange","target","len","tests","buffer","defaultBuffer","partialPosition","androidChrome","focus","focusText","firstNonMaskPos","lastRequiredNonMaskPos","caretTimeoutId","oldVal","currentVal","onMaskInput","event","handleAndroidInput","handleInputChange","onMaskKeyDown","_a","k","pos","begin","end","iPhone","caret","seekPrev","seekNext","clearBuffer","shiftL","updateModelValue","checkVal","onMaskKeyPress","p","c","next","shiftR","writeBuffer","onMaskFocus","onMaskBlur","e","onMaskPaste","first","last","_b","getPlaceholder","i","j","t","curVal","start","allow","_c","_d","test","lastMatch","currentTest","isPasteEvent","unmaskValue","value","unmaskedBuffer","thisbuffer","val","finalValue","updateValue","updateModel","initMask","defs","ua","maskTokens"]}
|
|
File without changes
|