@primereact/hooks 11.0.0-alpha.9 → 11.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +45 -0
- package/README.md +34 -0
- package/index.d.ts +7 -0
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/package.json +8 -12
- package/use-controlled-state/index.mjs +1 -1
- package/use-controlled-state/index.mjs.map +1 -1
- package/use-filter/_matchers.d.ts +23 -0
- package/use-filter/index.d.ts +94 -0
- package/use-filter/index.mjs +2 -0
- package/use-filter/index.mjs.map +1 -0
- package/use-is-mobile/index.d.ts +18 -0
- package/use-is-mobile/index.mjs +2 -0
- package/use-is-mobile/index.mjs.map +1 -0
- package/use-local-storage/index.d.ts +56 -0
- package/use-local-storage/index.mjs +2 -0
- package/use-local-storage/index.mjs.map +1 -0
- package/use-mask/index.d.ts +96 -67
- package/use-mask/index.mjs +1 -1
- package/use-mask/index.mjs.map +1 -1
- package/use-mounted/index.d.ts +36 -0
- package/use-mounted/index.mjs +2 -0
- package/use-mounted/index.mjs.map +1 -0
- package/use-number-formatter/index.d.ts +194 -0
- package/use-number-formatter/index.mjs +2 -0
- package/use-number-formatter/index.mjs.map +1 -0
- package/use-number-formatter/index.test.d.ts +0 -0
- package/use-presence/index.d.ts +1 -2
- package/use-presence/index.mjs +1 -1
- package/use-presence/index.mjs.map +1 -1
- package/use-props/index.d.ts +16 -11
- package/use-props/index.mjs +1 -1
- package/use-props/index.mjs.map +1 -1
- package/use-sortable-list/index.d.ts +43 -0
- package/use-sortable-list/index.mjs +2 -0
- package/use-sortable-list/index.mjs.map +1 -0
- package/use-tree-filter/index.d.ts +52 -0
- package/use-tree-filter/index.mjs +2 -0
- package/use-tree-filter/index.mjs.map +1 -0
- package/LICENSE +0 -21
package/use-mask/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var xe=Object.defineProperty;var Oe=Object.getOwnPropertySymbols;var je=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable;var Ie=(M,o,k)=>o in M?xe(M,o,{enumerable:!0,configurable:!0,writable:!0,value:k}):M[o]=k,J=(M,o)=>{for(var k in o||(o={}))je.call(o,k)&&Ie(M,k,o[k]);if(Oe)for(var k of Oe(o))He.call(o,k)&&Ie(M,k,o[k]);return M};import{getUserAgent as Q}from"@primeuix/utils";import*as c from"react";var Be={9:/[0-9]/,a:/[A-Za-z]/,A:/[A-Z]/,"*":/[A-Za-z0-9]/};function _e(M){let{mask:o,tokens:k,value:C,defaultValue:S,onValueChange:X,onComplete:Y,slotChar:$="_",showMaskOnFocus:ee=!1,alwaysShowMask:te=!1,autoClear:re=!0,transform:ne,readOnly:ue=!1}=M,P=c.useRef(X);P.current=X;let D=c.useRef(Y);D.current=Y;let B=c.useRef(ne);B.current=ne;let N=C!==void 0,[Se,Ae]=c.useState(S!=null?S:""),O=N?C!=null?C:"":Se,ce=c.useCallback(e=>{N||Ae(e)},[N]),g=c.useRef(null),d=c.useRef(0),i=c.useRef([]),p=c.useRef([]),L=c.useRef(""),I=c.useRef(0),se=c.useRef(!1),Z=c.useRef(!1),_=c.useRef(null),T=c.useRef(null),q=c.useRef(0),z=c.useRef(null),F=c.useRef(null),U=c.useRef(null),W=c.useRef(!1),ae=c.useRef(null),h=c.useRef({slotChar:$,showMaskOnFocus:ee,alwaysShowMask:te,autoClear:re,readOnly:ue,mask:o,userTokens:k});h.current={slotChar:$,showMaskOnFocus:ee,alwaysShowMask:te,autoClear:re,readOnly:ue,mask:o,userTokens:k};let v=c.useCallback(e=>{let r=h.current.slotChar;return r==null?"":e<r.length?r.charAt(e):r.charAt(0)},[]),l=c.useCallback((e,r)=>{var s,f;let n=g.current,t=0,u=0;return n?(typeof e=="number"?(t=e,u=typeof r=="number"?r:t,n.setSelectionRange(t,u)):(t=(s=n.selectionStart)!=null?s:0,u=(f=n.selectionEnd)!=null?f:0),{begin:t,end:u}):{begin:t,end:u}},[]),E=c.useCallback(e=>{for(;++e<d.current&&!i.current[e];);return e},[]),le=c.useCallback(e=>{for(;--e>=0&&!i.current[e];);return e},[]),G=c.useRef(!1),a=c.useCallback((e,r)=>{var u;let n=window.HTMLInputElement.prototype,t=(u=Object.getOwnPropertyDescriptor(n,"value"))==null?void 0:u.set;t?t.call(e,r):e.value=r},[]),oe=c.useCallback(e=>{G.current=!0;try{e.dispatchEvent(new Event("input",{bubbles:!0}))}finally{G.current=!1}},[]),w=c.useCallback(()=>{let e=g.current;e&&a(e,p.current.join(""))},[a]),V=c.useCallback((e,r)=>{for(let n=e;n<r&&n<d.current;n++)i.current[n]&&(p.current[n]=v(n))},[v]),x=c.useCallback((e,r)=>{var t,u;if(e<0)return;let n=E(r);for(let s=e;s<d.current;s++)if(i.current[s]){if(n<d.current&&((t=i.current[s])!=null&&t.test(p.current[n])))p.current[s]=p.current[n],p.current[n]=v(n);else break;n=E(n)}w(),l(Math.max((u=T.current)!=null?u:0,e))},[E,v,w,l]),ie=c.useCallback(e=>{var n;let r=v(e);for(let t=e;t<d.current;t++)if(i.current[t]){let u=E(t),s=p.current[t];if(p.current[t]=r,u<d.current&&((n=i.current[u])!=null&&n.test(s)))r=s;else break}},[v,E]),R=c.useCallback((e=!1)=>{var y,A,K,Le,Te;let r=g.current;if(!r)return(y=T.current)!=null?y:0;let n=r.value,t=-1,u,s,f;for(u=0,f=0;u<d.current;u++){let Ve=i.current[u];if(Ve!==null){for(p.current[u]=v(u);f++<((A=n==null?void 0:n.length)!=null?A:0);)if(s=(K=n==null?void 0:n.charAt(f-1))!=null?K:"",Ve.test(s)){p.current[u]=s,t=u;break}if(f>((Le=n==null?void 0:n.length)!=null?Le:0)){V(u+1,d.current);break}}else p.current[u]===(n==null?void 0:n.charAt(f))&&f++,u<I.current&&(t=u)}return e?w():t+1<I.current?h.current.autoClear||p.current.join("")===L.current?(r.value&&a(r,""),V(0,d.current)):w():(w(),a(r,r.value.substring(0,t+1))),I.current?u:(Te=T.current)!=null?Te:0},[v,V,w,a]),j=c.useCallback(e=>{let r=[],n=e.split("");for(let t=0;t<n.length;t++){let u=n[t];i.current[t]&&u!==v(t)&&r.push(u)}return r.join("")},[v]),H=c.useCallback(e=>{var n;let r=e.split("");for(let t=0;t<=q.current&&t<d.current;t++)if(i.current[t]){let u=r[t];if(!u||!((n=i.current[t])!=null&&n.test(u)))return!1}return!0},[]),b=c.useCallback(e=>{var A,K;let r=g.current;if(!r)return;let n=r.value,t=n===L.current,u=t?"":n;if(ae.current===u)return;ae.current=u,(e==null?void 0:e.type)!=="input"&&oe(r);let s=t?"":j(n),f=!t&&H(n),y={originalEvent:e,value:u,rawValue:s,isComplete:f};ce(u),(A=P.current)==null||A.call(P,y),f&&!W.current&&((K=D.current)==null||K.call(D,y)),W.current=f,U.current=n},[j,H,ce,oe]),fe=c.useCallback(e=>{if(h.current.readOnly||e.type==="paste")return;let r=R(!0);l(r),b(e)},[R,l,b]),Re=c.useCallback(e=>{var u;let r=g.current;if(!r)return;let n=r.value,t=l();if(t){if(F.current&&F.current.length&&F.current.length>n.length){for(R(!0);t.begin>0&&!i.current[t.begin-1];)t.begin--;if(t.begin===0)for(;t.begin<((u=T.current)!=null?u:0)&&!i.current[t.begin];)t.begin++;l(t.begin,t.begin)}else{for(R(!0);t.begin<d.current&&!i.current[t.begin];)t.begin++;l(t.begin,t.begin)}b(e)}},[l,R,b]),be=c.useCallback(e=>{g.current&&(G.current||"isComposing"in e&&e.isComposing||(se.current?Re(e):fe(e)))},[Re,fe]),ge=c.useCallback(e=>{var y;let r=g.current;if(!r||h.current.readOnly)return;let n=e.code,t,u,s,f=/iphone/i.test(Q());if(F.current=r.value,n==="Backspace"||n==="Delete"||f&&n==="Escape"){if(t=l(),!t)return;u=t.begin,s=t.end,s-u===0&&(u=n!=="Delete"?le(u):s=E(u-1),s=n==="Delete"?E(s):s),V(u,s),x(u,s-1),b(e),e.preventDefault()}else n==="Enter"?(r.blur(),b(e)):n==="Escape"&&(a(r,(y=_.current)!=null?y:""),l(0,R()),b(e),e.preventDefault())},[l,le,E,V,x,b,a,R]),pe=c.useCallback(e=>{var u;if(!g.current||h.current.readOnly)return;let n=e.code,t=l();if(t&&!(e.ctrlKey||e.altKey||e.metaKey||e.shiftKey||e.key==="CapsLock"||e.key==="Escape"||e.key==="Tab")){if(n&&n!=="Enter"){t.end-t.begin!==0&&(V(t.begin,t.end),x(t.begin,t.end-1));let s=E(t.begin-1);if(s<d.current){let f=e.key;if(B.current&&(f=B.current(f)),(u=i.current[s])!=null&&u.test(f)){ie(s),p.current[s]=f,w();let y=E(s);/android/i.test(Q())?setTimeout(()=>l(y),0):l(y)}}e.preventDefault()}b(e)}},[l,V,x,E,ie,w,b]),ke=c.useCallback(e=>{let r=g.current;if(!r||h.current.readOnly)return;z.current&&clearTimeout(z.current),Z.current=!0,_.current=r.value;let n=h.current.showMaskOnFocus||h.current.alwaysShowMask;if(!r.value||r.value===L.current)n&&a(r,L.current),requestAnimationFrame(()=>{var t,u;r===document.activeElement&&l((t=T.current)!=null?t:0,(u=T.current)!=null?u:0)});else{let t=R();z.current=setTimeout(()=>{var u;r===document.activeElement&&(w(),t===((u=h.current.mask)==null?void 0:u.replace("?","").length)?l(0,t):l(t))},10)}},[l,R,w,a]),de=c.useCallback(e=>{let r=g.current;r&&(Z.current=!1,R(),!h.current.alwaysShowMask&&r.value===L.current&&a(r,""),b(e),r.value!==_.current&&r.dispatchEvent(new Event("change",{bubbles:!0,cancelable:!1})))},[R,b,a]),he=c.useCallback(e=>{!g.current||h.current.readOnly||setTimeout(()=>{let n=R(!0);l(n),b(e)},0)},[R,l,b]),me=c.useCallback(()=>{i.current=[],I.current=o?o.length:0,d.current=o?o.length:0,T.current=null,q.current=0;let e=J(J({},Be),k),r=Q();se.current=/chrome/i.test(r)&&/android/i.test(r);let n=o?o.split(""):[];for(let u=0;u<n.length;u++){let s=n[u];s==="?"?(d.current--,I.current=u):e[s]?(i.current.push(e[s]),T.current===null&&(T.current=i.current.length-1),u<I.current&&(q.current=i.current.length-1)):i.current.push(null)}p.current=[];for(let u=0;u<n.length;u++){let s=n[u];s!=="?"&&(e[s]?p.current.push(v(u)):p.current.push(s))}L.current=p.current.join("");let t=g.current;t&&!t.value&&h.current.alwaysShowMask&&a(t,L.current)},[o,k,v,a]);c.useEffect(()=>{me()},[me]),c.useEffect(()=>{let e=g.current;e&&C!==void 0&&C!==U.current&&(Z.current||(a(e,C),R(),U.current=e.value))},[C,a,R]);let ve=c.useRef(be);ve.current=be;let Ee=c.useRef(ge);Ee.current=ge;let ye=c.useRef(pe);ye.current=pe;let Ce=c.useRef(ke);Ce.current=ke;let we=c.useRef(de);we.current=de;let Me=c.useRef(he);Me.current=he;let m=c.useMemo(()=>({input:e=>ve.current(e),keydown:e=>Ee.current(e),keypress:e=>ye.current(e),focus:e=>Ce.current(e),blur:e=>we.current(e),paste:e=>Me.current(e)}),[]),Ke=c.useCallback(e=>{let r=g.current;r&&r!==e&&(r.removeEventListener("input",m.input),r.removeEventListener("keydown",m.keydown),r.removeEventListener("keypress",m.keypress),r.removeEventListener("focus",m.focus),r.removeEventListener("blur",m.blur),r.removeEventListener("paste",m.paste)),g.current=e,e&&e!==r&&(e.addEventListener("input",m.input),e.addEventListener("keydown",m.keydown),e.addEventListener("keypress",m.keypress),e.addEventListener("focus",m.focus),e.addEventListener("blur",m.blur),e.addEventListener("paste",m.paste),C?(a(e,C),R()):S&&!e.value?(a(e,S),R()):h.current.alwaysShowMask&&!e.value&&a(e,L.current))},[m]),Pe=c.useMemo(()=>O?j(O):"",[O,j]),De=c.useMemo(()=>O?H(O):!1,[O,H]),Fe=c.useCallback(e=>{let r=g.current;r&&(a(r,e!=null?e:""),R(!0),b(null))},[a,R,b]),Ue=c.useCallback(()=>{let e=g.current;e&&(a(e,""),V(0,d.current),h.current.alwaysShowMask&&a(e,L.current),U.current=e.value,W.current=!1,b(null))},[a,V,b]);return{ref:Ke,value:O,rawValue:Pe,isComplete:De,setValue:Fe,reset:Ue}}export{_e as useMask};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/use-mask/index.mjs.map
CHANGED
|
@@ -1 +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,CAA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,IAAMZ,EAAImC,EAAWvB,CAAC,EAElBZ,IAAM,MACFiC,EAAKjC,CAAC,EAAG/B,EAAO,QAAQ,KAAK0C,EAAeC,CAAC,CAAC,EAC7C3C,EAAO,QAAQ,KAAK+B,CAAC,EAElC,CAEA9B,EAAc,QAAUD,EAAO,QAAQ,KAAK,EAAE,EAE9C6D,EAAY,EAAK,CACrB,EAEA,OAAA3E,GAAe,IAAM,CACjB6E,GAAS,CACb,CAAC,EAEM,CACH,YAAApD,EACA,cAAAI,EACA,eAAAc,EACA,YAAAM,EACA,WAAAC,EACA,YAAAE,CACJ,CACJ","names":["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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/use-mask/index.ts"],"sourcesContent":["import { getUserAgent } from '@primeuix/utils';\nimport * as React from 'react';\n\n/**\n * Event payload for `useMask` value/complete callbacks.\n */\nexport interface UseMaskValueChangeEvent {\n /**\n * The DOM event that triggered the change, or `null` for programmatic\n * updates (`setValue`, `reset`).\n */\n originalEvent: Event | null;\n /**\n * Masked value (e.g. `\"12/05/2026\"`). Always in masked form.\n */\n value: string;\n /**\n * Unmasked (raw) value (e.g. `\"12052026\"`). Separators and placeholder\n * characters are stripped.\n */\n rawValue: string;\n /**\n * Whether all required slots are filled.\n */\n isComplete: boolean;\n}\n\n/**\n * Options for the `useMask` hook.\n */\nexport interface UseMaskOptions {\n /**\n * Mask pattern. Built-in tokens:\n * - `9` → [0-9]\n * - `a` → [A-Za-z]\n * - `A` → [A-Z]\n * - `*` → [A-Za-z0-9]\n * Append `?` to mark the remainder of the mask as optional. Extend with\n * the `tokens` option.\n */\n mask: string;\n /**\n * Custom token map merged on top of the built-in tokens. Each token\n * character is matched against the supplied RegExp.\n * @example { '#': /[0-9]/, H: /[A-Fa-f0-9]/ }\n */\n tokens?: Record<string, RegExp>;\n /**\n * Controlled masked value. When provided, the hook operates in\n * controlled mode.\n */\n value?: string;\n /**\n * Initial masked value for uncontrolled mode. Ignored when `value` is\n * provided.\n */\n defaultValue?: string;\n /**\n * Fires whenever the value changes (typing, paste, programmatic).\n */\n onValueChange?: (event: UseMaskValueChangeEvent) => void;\n /**\n * Fires when the value transitions to complete (all required slots\n * filled). Re-fires if the value becomes incomplete and is completed\n * again.\n */\n onComplete?: (event: UseMaskValueChangeEvent) => void;\n /**\n * Placeholder character for empty slots. Pass `null` to skip filling\n * empty slots visually.\n * @default '_'\n */\n slotChar?: string | null;\n /**\n * Whether to render the mask skeleton on focus.\n * @default false\n */\n showMaskOnFocus?: boolean;\n /**\n * Always render the mask skeleton, regardless of focus state.\n * @default false\n */\n alwaysShowMask?: boolean;\n /**\n * Clear an incomplete value on blur.\n * @default true\n */\n autoClear?: boolean;\n /**\n * Transform every character before token validation (e.g. uppercase).\n */\n transform?: (char: string) => string;\n /**\n * Read-only mode. Typing is blocked; programmatic `setValue` still\n * works.\n * @default false\n */\n readOnly?: boolean;\n}\n\n/**\n * Return type of the `useMask` hook.\n */\nexport interface UseMaskReturn {\n /**\n * Ref callback for the target `<input>` (or `<textarea>`). Attaches\n * native event listeners on mount and tears them down on unmount or\n * when the ref switches to a new element.\n */\n ref: (element: HTMLInputElement | null) => void;\n /**\n * Current masked value (always reflects what is in the input).\n */\n value: string;\n /**\n * Current unmasked (raw) value.\n */\n rawValue: string;\n /**\n * Whether all required slots are filled.\n */\n isComplete: boolean;\n /**\n * Programmatically set the masked value. The value is normalized\n * through the mask before being applied.\n */\n setValue: (next: string) => void;\n /**\n * Reset the input to an empty mask skeleton.\n */\n reset: () => void;\n}\n\nconst DEFAULT_TOKENS: Record<string, RegExp> = {\n '9': /[0-9]/,\n a: /[A-Za-z]/,\n A: /[A-Z]/,\n '*': /[A-Za-z0-9]/\n};\n\n/**\n * React hook for masked text input. Attach the returned `ref` to any\n * component that forwards a ref to a real `<input>` (e.g. `InputText`,\n * `Textarea`, `DatePicker.Input`). The hook installs DOM event listeners\n * directly on the element, so no other props need to be wired.\n *\n * @example\n * const { ref, value, rawValue, isComplete } = useMask({ mask: '99/99/9999' });\n * return <InputText ref={ref} placeholder=\"DD/MM/YYYY\" />;\n */\nexport function useMask(options: UseMaskOptions): UseMaskReturn {\n const { mask, tokens: userTokens, value: controlledValue, defaultValue, onValueChange, onComplete, slotChar = '_', showMaskOnFocus = false, alwaysShowMask = false, autoClear = true, transform, readOnly = false } = options;\n\n // Latest callback refs so handlers always see the freshest values\n // without forcing the listener registration to re-run on every render.\n const onValueChangeRef = React.useRef(onValueChange);\n\n onValueChangeRef.current = onValueChange;\n const onCompleteRef = React.useRef(onComplete);\n\n onCompleteRef.current = onComplete;\n const transformRef = React.useRef(transform);\n\n transformRef.current = transform;\n\n // Controlled / uncontrolled hybrid state. The hook owns an internal\n // string that mirrors the masked DOM value. When the consumer passes\n // `value` we operate in controlled mode and ignore internal state for\n // the public `value` field. Internal state still drives derived\n // outputs (`rawValue`, `isComplete`) when uncontrolled.\n const isControlled = controlledValue !== undefined;\n const [internalValue, setInternalValue] = React.useState<string>(defaultValue ?? '');\n const value = isControlled ? (controlledValue ?? '') : internalValue;\n const setStateValue = React.useCallback(\n (next: string) => {\n if (!isControlled) setInternalValue(next);\n },\n [isControlled]\n );\n\n // ---------------------------------------------------------------------\n // Mask engine state — preserved from the previous implementation. These\n // refs hold the parsed mask metadata and the live character buffer.\n // ---------------------------------------------------------------------\n const targetRef = React.useRef<HTMLInputElement | null>(null);\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>('');\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<ReturnType<typeof setTimeout> | null>(null);\n const oldVal = React.useRef<string | null>(null);\n const currentVal = React.useRef<string | null>(null);\n const wasComplete = React.useRef(false);\n const lastEmittedValue = React.useRef<string | null>(null);\n\n // Cached options so handlers don't capture stale closures when options\n // change between renders.\n const optsRef = React.useRef({ slotChar, showMaskOnFocus, alwaysShowMask, autoClear, readOnly, mask, userTokens });\n\n optsRef.current = { slotChar, showMaskOnFocus, alwaysShowMask, autoClear, readOnly, mask, userTokens };\n\n // ---------------------------------------------------------------------\n // Helpers (all read `targetRef.current` lazily so a ref swap is safe).\n // ---------------------------------------------------------------------\n\n const getPlaceholder = React.useCallback((i: number) => {\n const sc = optsRef.current.slotChar;\n\n if (sc == null) return '';\n\n if (i < sc.length) return sc.charAt(i);\n\n return sc.charAt(0);\n }, []);\n\n const caret = React.useCallback((first?: number, last?: number): { begin: number; end: number } | undefined => {\n const target = targetRef.current;\n let begin = 0;\n let end = 0;\n\n if (!target) return { begin, end };\n\n if (typeof first === 'number') {\n begin = first;\n end = typeof last === 'number' ? last : begin;\n target.setSelectionRange(begin, end);\n } else {\n begin = target.selectionStart ?? 0;\n end = target.selectionEnd ?? 0;\n }\n\n return { begin, end };\n }, []);\n\n const seekNext = React.useCallback((pos: number) => {\n while (++pos < len.current && !tests.current[pos]);\n\n return pos;\n }, []);\n\n const seekPrev = React.useCallback((pos: number) => {\n while (--pos >= 0 && !tests.current[pos]);\n\n return pos;\n }, []);\n\n // Track whether we're currently writing to the DOM ourselves, so the\n // resulting `input` event doesn't re-enter our own handler chain.\n const internalWrite = React.useRef(false);\n\n // DOM value setter using React's native value setter so React's\n // `_valueTracker` stays in sync. Note: this only mutates the DOM —\n // it intentionally does NOT dispatch an `input` event. We dispatch\n // exactly once per user-visible change (see `notifyReact` below)\n // to avoid firing React `onChange` mid-operation and to keep\n // downstream consumers (e.g. DatePicker.Input parsing the value)\n // from seeing intermediate buffer states.\n const setNativeValue = React.useCallback((target: HTMLInputElement, next: string) => {\n const proto = window.HTMLInputElement.prototype;\n const setter = Object.getOwnPropertyDescriptor(proto, 'value')?.set;\n\n if (setter) setter.call(target, next);\n else target.value = next;\n }, []);\n\n // Notify React (and any other React-side onChange listeners) that\n // the input value has changed. Wraps the dispatch in `internalWrite`\n // so our own native `input` listener doesn't re-process the event.\n const notifyReact = React.useCallback((target: HTMLInputElement) => {\n internalWrite.current = true;\n try {\n target.dispatchEvent(new Event('input', { bubbles: true }));\n } finally {\n internalWrite.current = false;\n }\n }, []);\n\n const writeBuffer = React.useCallback(() => {\n const target = targetRef.current;\n\n if (!target) return;\n setNativeValue(target, buffer.current.join(''));\n }, [setNativeValue]);\n\n const clearBuffer = React.useCallback(\n (start: number, end: number) => {\n for (let i = start; i < end && i < len.current; i++) {\n if (tests.current[i]) buffer.current[i] = getPlaceholder(i);\n }\n },\n [getPlaceholder]\n );\n\n const shiftL = React.useCallback(\n (begin: number, end: number) => {\n if (begin < 0) return;\n\n let j = seekNext(end);\n\n for (let i = begin; 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 [seekNext, getPlaceholder, writeBuffer, caret]\n );\n\n const shiftR = React.useCallback(\n (pos: number) => {\n let c = getPlaceholder(pos);\n\n for (let i = pos; i < len.current; i++) {\n if (tests.current[i]) {\n const j = seekNext(i);\n const t = buffer.current[i];\n\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 [getPlaceholder, seekNext]\n );\n\n const checkVal = React.useCallback(\n (allow = false): number => {\n const target = targetRef.current;\n\n if (!target) return firstNonMaskPos.current ?? 0;\n\n const test = target.value;\n let lastMatch = -1;\n let i: number;\n let c: string;\n let pos: number;\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)) pos++;\n\n if (i < partialPosition.current) lastMatch = i;\n }\n }\n\n if (allow) {\n writeBuffer();\n } else if (lastMatch + 1 < partialPosition.current) {\n if (optsRef.current.autoClear || buffer.current.join('') === defaultBuffer.current) {\n if (target.value) setNativeValue(target, '');\n clearBuffer(0, len.current);\n } else {\n writeBuffer();\n }\n } else {\n writeBuffer();\n setNativeValue(target, target.value.substring(0, lastMatch + 1));\n }\n\n return partialPosition.current ? i! : (firstNonMaskPos.current ?? 0);\n },\n [getPlaceholder, clearBuffer, writeBuffer, setNativeValue]\n );\n\n const unmaskValue = React.useCallback(\n (masked: string) => {\n const out: string[] = [];\n const chars = masked.split('');\n\n for (let i = 0; i < chars.length; i++) {\n const c = chars[i];\n\n if (tests.current[i] && c !== getPlaceholder(i)) {\n out.push(c);\n }\n }\n\n return out.join('');\n },\n [getPlaceholder]\n );\n\n const computeIsComplete = React.useCallback((maskedValue: string) => {\n // Complete when the buffer up to lastRequiredNonMaskPos has no\n // placeholders in its required slots.\n const chars = maskedValue.split('');\n\n for (let i = 0; i <= lastRequiredNonMaskPos.current && i < len.current; i++) {\n if (tests.current[i]) {\n const c = chars[i];\n\n if (!c || !tests.current[i]?.test(c)) return false;\n }\n }\n\n return true;\n }, []);\n\n // Single source of truth for emitting changes. Reads the current DOM\n // value, notifies React (so onChange handlers fire), derives\n // rawValue/isComplete, syncs internal state, and fires user callbacks.\n const emitChange = React.useCallback(\n (originalEvent: Event | null) => {\n const target = targetRef.current;\n\n if (!target) return;\n\n const masked = target.value;\n const isDefault = masked === defaultBuffer.current;\n const reported = isDefault ? '' : masked;\n\n if (lastEmittedValue.current === reported) return;\n lastEmittedValue.current = reported;\n\n // Notify React-side `onChange` handlers (e.g. DatePicker.Input's\n // parser) that the DOM value has changed. The flag `internalWrite`\n // prevents our own listener from re-processing this dispatch.\n // We only dispatch when the originating event was NOT a native\n // `input` event — for those, React already gets the change via\n // the original event.\n if (originalEvent?.type !== 'input') {\n notifyReact(target);\n }\n\n const rawValue = isDefault ? '' : unmaskValue(masked);\n const complete = !isDefault && computeIsComplete(masked);\n const eventPayload: UseMaskValueChangeEvent = {\n originalEvent,\n value: reported,\n rawValue,\n isComplete: complete\n };\n\n // Mirror DOM into hook's internal state (no-op in controlled mode).\n setStateValue(reported);\n\n onValueChangeRef.current?.(eventPayload);\n\n if (complete && !wasComplete.current) {\n onCompleteRef.current?.(eventPayload);\n }\n\n wasComplete.current = complete;\n currentVal.current = masked;\n },\n [unmaskValue, computeIsComplete, setStateValue, notifyReact]\n );\n\n // ---------------------------------------------------------------------\n // Event handlers — invoked from native DOM listeners installed in the\n // ref callback below.\n // ---------------------------------------------------------------------\n\n const handleInputChange = React.useCallback(\n (event: Event) => {\n if (optsRef.current.readOnly) return;\n if (event.type === 'paste') return;\n\n const pos = checkVal(true);\n\n caret(pos);\n emitChange(event);\n },\n [checkVal, caret, emitChange]\n );\n\n const handleAndroidInput = React.useCallback(\n (event: Event) => {\n const target = targetRef.current;\n\n if (!target) return;\n\n const curVal = target.value;\n const pos = caret();\n\n if (!pos) return;\n\n if (oldVal.current && oldVal.current.length && oldVal.current.length > curVal.length) {\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 caret(pos.begin, pos.begin);\n }\n\n emitChange(event);\n },\n [caret, checkVal, emitChange]\n );\n\n const onInput = React.useCallback(\n (event: Event) => {\n const target = targetRef.current;\n\n if (!target) return;\n // Ignore our own re-dispatched input events — they exist only to\n // notify React listeners (e.g. DatePicker.Input's onChange parse).\n if (internalWrite.current) return;\n\n if ('isComposing' in event && (event as InputEvent).isComposing) return;\n\n if (androidChrome.current) handleAndroidInput(event);\n else handleInputChange(event);\n },\n [handleAndroidInput, handleInputChange]\n );\n\n const onKeyDown = React.useCallback(\n (event: KeyboardEvent) => {\n const target = targetRef.current;\n\n if (!target || optsRef.current.readOnly) return;\n\n const k = event.code;\n let pos: { begin: number; end: number } | undefined;\n let begin: number;\n let end: number;\n const iPhone = /iphone/i.test(getUserAgent());\n\n oldVal.current = target.value;\n\n if (k === 'Backspace' || k === 'Delete' || (iPhone && k === 'Escape')) {\n pos = caret();\n\n if (!pos) return;\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 emitChange(event);\n\n event.preventDefault();\n } else if (k === 'Enter') {\n target.blur();\n emitChange(event);\n } else if (k === 'Escape') {\n setNativeValue(target, focusText.current ?? '');\n caret(0, checkVal());\n emitChange(event);\n event.preventDefault();\n }\n },\n [caret, seekPrev, seekNext, clearBuffer, shiftL, emitChange, setNativeValue, checkVal]\n );\n\n const onKeyPress = React.useCallback(\n (event: KeyboardEvent) => {\n const target = targetRef.current;\n\n if (!target || optsRef.current.readOnly) return;\n\n const k = event.code;\n const pos = caret();\n\n if (!pos) return;\n\n if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey || event.key === 'CapsLock' || event.key === 'Escape' || event.key === 'Tab') {\n return;\n }\n\n 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 const p = seekNext(pos.begin - 1);\n\n if (p < len.current) {\n let c = event.key;\n\n if (transformRef.current) c = transformRef.current(c);\n\n if (tests.current[p]?.test(c)) {\n shiftR(p);\n buffer.current[p] = c;\n writeBuffer();\n const next = seekNext(p);\n\n if (/android/i.test(getUserAgent())) {\n setTimeout(() => caret(next), 0);\n } else {\n caret(next);\n }\n }\n }\n\n event.preventDefault();\n }\n\n emitChange(event);\n },\n [caret, clearBuffer, shiftL, seekNext, shiftR, writeBuffer, emitChange]\n );\n\n const onFocus = React.useCallback(\n (_event: FocusEvent) => {\n const target = targetRef.current;\n\n if (!target || optsRef.current.readOnly) return;\n if (caretTimeoutId.current) clearTimeout(caretTimeoutId.current);\n focus.current = true;\n focusText.current = target.value;\n\n const shouldShowSkeleton = optsRef.current.showMaskOnFocus || optsRef.current.alwaysShowMask;\n\n if (!target.value || target.value === defaultBuffer.current) {\n if (shouldShowSkeleton) {\n setNativeValue(target, defaultBuffer.current);\n }\n\n requestAnimationFrame(() => {\n if (target === document.activeElement) {\n caret(firstNonMaskPos.current ?? 0, firstNonMaskPos.current ?? 0);\n }\n });\n } else {\n const pos = checkVal();\n\n caretTimeoutId.current = setTimeout(() => {\n if (target !== document.activeElement) return;\n writeBuffer();\n\n if (pos === optsRef.current.mask?.replace('?', '').length) {\n caret(0, pos);\n } else {\n caret(pos);\n }\n }, 10);\n }\n },\n [caret, checkVal, writeBuffer, setNativeValue]\n );\n\n const onBlur = React.useCallback(\n (event: FocusEvent) => {\n const target = targetRef.current;\n\n if (!target) return;\n focus.current = false;\n checkVal();\n\n if (!optsRef.current.alwaysShowMask && target.value === defaultBuffer.current) {\n setNativeValue(target, '');\n }\n\n emitChange(event);\n\n if (target.value !== focusText.current) {\n target.dispatchEvent(new Event('change', { bubbles: true, cancelable: false }));\n }\n },\n [checkVal, emitChange, setNativeValue]\n );\n\n const onPaste = React.useCallback(\n (event: Event) => {\n const target = targetRef.current;\n\n if (!target || optsRef.current.readOnly) return;\n\n // Defer to next tick so the pasted content is already in the input,\n // then run a full revalidation through checkVal(true).\n setTimeout(() => {\n const pos = checkVal(true);\n\n caret(pos);\n emitChange(event);\n }, 0);\n },\n [checkVal, caret, emitChange]\n );\n\n // ---------------------------------------------------------------------\n // Mask initialization: parses the pattern into the tests/buffer refs\n // and writes the initial value into the bound input (if any).\n // ---------------------------------------------------------------------\n const initMask = React.useCallback(() => {\n tests.current = [];\n partialPosition.current = mask ? mask.length : 0;\n len.current = mask ? mask.length : 0;\n firstNonMaskPos.current = null;\n lastRequiredNonMaskPos.current = 0;\n\n const tokenMap: Record<string, RegExp> = { ...DEFAULT_TOKENS, ...userTokens };\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 (tokenMap[c]) {\n tests.current.push(tokenMap[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 (tokenMap[c]) buffer.current.push(getPlaceholder(i));\n else buffer.current.push(c);\n }\n }\n\n defaultBuffer.current = buffer.current.join('');\n\n const target = targetRef.current;\n\n if (target) {\n // Seed initial skeleton only when alwaysShowMask is on AND\n // the input has no value yet. Initial controlled/defaultValue\n // sync is handled by the dedicated effect below — keeping\n // `initMask` independent of `value` prevents it from\n // re-running on every keystroke (which would re-write the\n // DOM and fight user typing).\n if (!target.value && optsRef.current.alwaysShowMask) {\n setNativeValue(target, defaultBuffer.current);\n }\n }\n }, [mask, userTokens, getPlaceholder, setNativeValue]);\n\n // Re-init when mask or tokens change.\n React.useEffect(() => {\n initMask();\n }, [initMask]);\n\n // ---------------------------------------------------------------------\n // Sync controlled value -> input. When the consumer changes `value`\n // externally we must reflect it in the DOM.\n // ---------------------------------------------------------------------\n React.useEffect(() => {\n const target = targetRef.current;\n\n if (!target) return;\n if (controlledValue === undefined) return;\n if (controlledValue === currentVal.current) return;\n if (focus.current) return; // Don't fight the user while typing.\n\n setNativeValue(target, controlledValue);\n checkVal();\n currentVal.current = target.value;\n }, [controlledValue, setNativeValue, checkVal]);\n\n // ---------------------------------------------------------------------\n // Ref callback: install / tear down native listeners on the target.\n //\n // The callback has a STABLE identity (`useCallback` with no deps) so\n // React doesn't tear down and re-attach listeners on every render.\n // Listeners themselves are stable refs to the latest handlers via\n // the `*Handler` indirections below.\n // ---------------------------------------------------------------------\n const onInputRef = React.useRef(onInput);\n\n onInputRef.current = onInput;\n const onKeyDownRef = React.useRef(onKeyDown);\n\n onKeyDownRef.current = onKeyDown;\n const onKeyPressRef = React.useRef(onKeyPress);\n\n onKeyPressRef.current = onKeyPress;\n const onFocusRef = React.useRef(onFocus);\n\n onFocusRef.current = onFocus;\n const onBlurRef = React.useRef(onBlur);\n\n onBlurRef.current = onBlur;\n const onPasteRef = React.useRef(onPaste);\n\n onPasteRef.current = onPaste;\n\n // Stable trampoline handlers that delegate to the latest refs.\n const stableHandlers = React.useMemo(\n () => ({\n input: (e: Event) => onInputRef.current(e),\n keydown: (e: KeyboardEvent) => onKeyDownRef.current(e),\n keypress: (e: KeyboardEvent) => onKeyPressRef.current(e),\n focus: (e: FocusEvent) => onFocusRef.current(e),\n blur: (e: FocusEvent) => onBlurRef.current(e),\n paste: (e: Event) => onPasteRef.current(e)\n }),\n []\n );\n\n const refCallback = React.useCallback(\n (element: HTMLInputElement | null) => {\n const previous = targetRef.current;\n\n if (previous && previous !== element) {\n previous.removeEventListener('input', stableHandlers.input);\n previous.removeEventListener('keydown', stableHandlers.keydown);\n previous.removeEventListener('keypress', stableHandlers.keypress);\n previous.removeEventListener('focus', stableHandlers.focus);\n previous.removeEventListener('blur', stableHandlers.blur);\n previous.removeEventListener('paste', stableHandlers.paste);\n }\n\n targetRef.current = element;\n\n if (element && element !== previous) {\n element.addEventListener('input', stableHandlers.input);\n element.addEventListener('keydown', stableHandlers.keydown);\n element.addEventListener('keypress', stableHandlers.keypress);\n element.addEventListener('focus', stableHandlers.focus);\n element.addEventListener('blur', stableHandlers.blur);\n element.addEventListener('paste', stableHandlers.paste);\n\n // Seed the freshly-bound element. Use `controlledValue`\n // (not `value`) so the seed only happens for an externally\n // supplied controlled value; uncontrolled internal state\n // changes are handled by the user's typing and shouldn't\n // re-seed mid-stream.\n if (controlledValue) {\n setNativeValue(element, controlledValue);\n checkVal();\n } else if (defaultValue && !element.value) {\n setNativeValue(element, defaultValue);\n checkVal();\n } else if (optsRef.current.alwaysShowMask && !element.value) {\n setNativeValue(element, defaultBuffer.current);\n }\n }\n },\n // Intentionally NO `value`/`controlledValue` deps — see comment\n // above. The setter closures below read fresh values from refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [stableHandlers]\n );\n\n // ---------------------------------------------------------------------\n // Derived public outputs.\n // ---------------------------------------------------------------------\n const rawValue = React.useMemo(() => (value ? unmaskValue(value) : ''), [value, unmaskValue]);\n const isComplete = React.useMemo(() => (value ? computeIsComplete(value) : false), [value, computeIsComplete]);\n\n const setValue = React.useCallback(\n (next: string) => {\n const target = targetRef.current;\n\n if (!target) return;\n setNativeValue(target, next ?? '');\n checkVal(true);\n emitChange(null);\n },\n [setNativeValue, checkVal, emitChange]\n );\n\n const reset = React.useCallback(() => {\n const target = targetRef.current;\n\n if (!target) return;\n setNativeValue(target, '');\n clearBuffer(0, len.current);\n\n if (optsRef.current.alwaysShowMask) {\n setNativeValue(target, defaultBuffer.current);\n }\n\n currentVal.current = target.value;\n wasComplete.current = false;\n emitChange(null);\n }, [setNativeValue, clearBuffer, emitChange]);\n\n return {\n ref: refCallback,\n value,\n rawValue,\n isComplete,\n setValue,\n reset\n };\n}\n"],"mappings":"qWAAA,OAAS,gBAAAA,MAAoB,kBAC7B,UAAYC,MAAW,QAoIvB,IAAMC,GAAyC,CAC3C,EAAK,QACL,EAAG,WACH,EAAG,QACH,IAAK,aACT,EAYO,SAASC,GAAQC,EAAwC,CAC5D,GAAM,CAAE,KAAAC,EAAM,OAAQC,EAAY,MAAOC,EAAiB,aAAAC,EAAc,cAAAC,EAAe,WAAAC,EAAY,SAAAC,EAAW,IAAK,gBAAAC,GAAkB,GAAO,eAAAC,GAAiB,GAAO,UAAAC,GAAY,GAAM,UAAAC,GAAW,SAAAC,GAAW,EAAM,EAAIZ,EAIhNa,EAAyB,SAAOR,CAAa,EAEnDQ,EAAiB,QAAUR,EAC3B,IAAMS,EAAsB,SAAOR,CAAU,EAE7CQ,EAAc,QAAUR,EACxB,IAAMS,EAAqB,SAAOJ,EAAS,EAE3CI,EAAa,QAAUJ,GAOvB,IAAMK,EAAeb,IAAoB,OACnC,CAACc,GAAeC,EAAgB,EAAU,WAAiBd,GAAA,KAAAA,EAAgB,EAAE,EAC7Ee,EAAQH,EAAgBb,GAAA,KAAAA,EAAmB,GAAMc,GACjDG,GAAsB,cACvBC,GAAiB,CACTL,GAAcE,GAAiBG,CAAI,CAC5C,EACA,CAACL,CAAY,CACjB,EAMMM,EAAkB,SAAgC,IAAI,EACtDC,EAAY,SAAO,CAAC,EACpBC,EAAc,SAA6B,CAAC,CAAC,EAC7CC,EAAe,SAAiB,CAAC,CAAC,EAClCC,EA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AAI,EACpDE,EAAQ,iBAAiB,QAASF,EAAe,KAAK,EAOlD/G,GACAmD,EAAe8D,EAASjH,CAAe,EACvC+D,EAAS,GACF9D,GAAgB,CAACgH,EAAQ,OAChC9D,EAAe8D,EAAShH,CAAY,EACpC8D,EAAS,GACF5B,EAAQ,QAAQ,gBAAkB,CAAC8E,EAAQ,OAClD9D,EAAe8D,EAAS1F,EAAc,OAAO,EAGzD,EAIA,CAACwF,CAAc,CACnB,EAKM9B,GAAiB,UAAQ,IAAOjE,EAAQuD,EAAYvD,CAAK,EAAI,GAAK,CAACA,EAAOuD,CAAW,CAAC,EACtF4C,GAAmB,UAAQ,IAAOnG,EAAQ2D,EAAkB3D,CAAK,EAAI,GAAQ,CAACA,EAAO2D,CAAiB,CAAC,EAEvGyC,GAAiB,cAClBlG,GAAiB,CACd,IAAM0B,EAASzB,EAAU,QAEpByB,IACLO,EAAeP,EAAQ1B,GAAA,KAAAA,EAAQ,EAAE,EACjC6C,EAAS,EAAI,EACbc,EAAW,IAAI,EACnB,EACA,CAAC1B,EAAgBY,EAAUc,CAAU,CACzC,EAEMwC,GAAc,cAAY,IAAM,CAClC,IAAMzE,EAASzB,EAAU,QAEpByB,IACLO,EAAeP,EAAQ,EAAE,EACzBY,EAAY,EAAGpC,EAAI,OAAO,EAEtBe,EAAQ,QAAQ,gBAChBgB,EAAeP,EAAQrB,EAAc,OAAO,EAGhDS,EAAW,QAAUY,EAAO,MAC5BX,EAAY,QAAU,GACtB4C,EAAW,IAAI,EACnB,EAAG,CAAC1B,EAAgBK,EAAaqB,CAAU,CAAC,EAE5C,MAAO,CACH,IAAKmC,GACL,MAAAhG,EACA,SAAAiE,GACA,WAAAkC,GACA,SAAAC,GACA,MAAAC,EACJ,CACJ","names":["getUserAgent","React","DEFAULT_TOKENS","useMask","options","mask","userTokens","controlledValue","defaultValue","onValueChange","onComplete","slotChar","showMaskOnFocus","alwaysShowMask","autoClear","transform","readOnly","onValueChangeRef","onCompleteRef","transformRef","isControlled","internalValue","setInternalValue","value","setStateValue","next","targetRef","len","tests","buffer","defaultBuffer","partialPosition","androidChrome","focus","focusText","firstNonMaskPos","lastRequiredNonMaskPos","caretTimeoutId","oldVal","currentVal","wasComplete","lastEmittedValue","optsRef","getPlaceholder","i","sc","caret","first","last","_a","_b","target","begin","end","seekNext","pos","seekPrev","internalWrite","setNativeValue","proto","setter","notifyReact","writeBuffer","clearBuffer","start","shiftL","j","shiftR","c","t","checkVal","allow","_c","_d","_e","test","lastMatch","currentTest","unmaskValue","masked","out","chars","computeIsComplete","maskedValue","emitChange","originalEvent","isDefault","reported","rawValue","complete","eventPayload","handleInputChange","event","handleAndroidInput","curVal","onInput","onKeyDown","k","iPhone","getUserAgent","onKeyPress","p","onFocus","_event","shouldShowSkeleton","onBlur","onPaste","initMask","tokenMap","__spreadValues","ua","maskTokens","onInputRef","onKeyDownRef","onKeyPressRef","onFocusRef","onBlurRef","onPasteRef","stableHandlers","refCallback","element","previous","isComplete","setValue","reset"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the useMounted hook.
|
|
3
|
+
*/
|
|
4
|
+
export interface UseMountedOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Callback invoked when the component transitions to mounted state.
|
|
7
|
+
*/
|
|
8
|
+
onMounted?: () => void;
|
|
9
|
+
/**
|
|
10
|
+
* Callback invoked when the component transitions to unmounted state
|
|
11
|
+
* or when the component is destroyed while mounted.
|
|
12
|
+
*/
|
|
13
|
+
onUnmounted?: () => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Custom hook that tracks whether a component is mounted on the client.
|
|
17
|
+
* Provides SSR-safe mounting detection with optional lifecycle callbacks.
|
|
18
|
+
*
|
|
19
|
+
* @param {UseMountedOptions} options configuration options
|
|
20
|
+
* @returns {boolean} whether the component is currently mounted
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const MyComponent = () => {
|
|
25
|
+
* const mounted = useMounted({
|
|
26
|
+
* onMounted: () => console.log('Mounted'),
|
|
27
|
+
* onUnmounted: () => console.log('Unmounted')
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* if (!mounted) return null;
|
|
31
|
+
*
|
|
32
|
+
* return <div>Content</div>;
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function useMounted(options?: UseMountedOptions): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/use-mounted/index.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * Options for the useMounted hook.\n */\nexport interface UseMountedOptions {\n /**\n * Callback invoked when the component transitions to mounted state.\n */\n onMounted?: () => void;\n /**\n * Callback invoked when the component transitions to unmounted state\n * or when the component is destroyed while mounted.\n */\n onUnmounted?: () => void;\n}\n\n/**\n * Custom hook that tracks whether a component is mounted on the client.\n * Provides SSR-safe mounting detection with optional lifecycle callbacks.\n *\n * @param {UseMountedOptions} options configuration options\n * @returns {boolean} whether the component is currently mounted\n *\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const mounted = useMounted({\n * onMounted: () => console.log('Mounted'),\n * onUnmounted: () => console.log('Unmounted')\n * });\n *\n * if (!mounted) return null;\n *\n * return <div>Content</div>;\n * };\n * ```\n */\nexport function useMounted(options: UseMountedOptions = {}): boolean {\n const [mounted, setMounted] = React.useState(false);\n\n React.useEffect(() => {\n setMounted(true);\n\n options.onMounted?.();\n\n return () => {\n options.onUnmounted?.();\n };\n }, []);\n\n return mounted;\n}\n"],"mappings":"AAAA,UAAYA,MAAW,QAsChB,SAASC,EAAWC,EAA6B,CAAC,EAAY,CACjE,GAAM,CAACC,EAASC,CAAU,EAAU,WAAS,EAAK,EAElD,OAAM,YAAU,IAAM,CAzC1B,IAAAC,EA0CQ,OAAAD,EAAW,EAAI,GAEfC,EAAAH,EAAQ,YAAR,MAAAG,EAAA,KAAAH,GAEO,IAAM,CA9CrB,IAAAG,GA+CYA,EAAAH,EAAQ,cAAR,MAAAG,EAAA,KAAAH,EACJ,CACJ,EAAG,CAAC,CAAC,EAEEC,CACX","names":["React","useMounted","options","mounted","setMounted","_a"]}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The options for the `useNumberFormatter` hook.
|
|
3
|
+
*/
|
|
4
|
+
export interface UseNumberFormatterOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The numeric value to be formatted.
|
|
7
|
+
*/
|
|
8
|
+
value?: number | string | null | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Locale to be used in formatting.
|
|
11
|
+
*/
|
|
12
|
+
locale?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The locale matching algorithm to use. Possible values are 'lookup' and 'best fit'.
|
|
15
|
+
* @default 'best fit'
|
|
16
|
+
*/
|
|
17
|
+
localeMatcher?: 'lookup' | 'best fit';
|
|
18
|
+
/**
|
|
19
|
+
* Defines the behavior of the component.
|
|
20
|
+
* @default 'decimal'
|
|
21
|
+
*/
|
|
22
|
+
mode?: 'decimal' | 'currency';
|
|
23
|
+
/**
|
|
24
|
+
* The currency to use in currency formatting (ISO 4217 currency codes).
|
|
25
|
+
*/
|
|
26
|
+
currency?: string;
|
|
27
|
+
/**
|
|
28
|
+
* How to display the currency in currency formatting.
|
|
29
|
+
*/
|
|
30
|
+
currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name';
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use grouping separators, such as thousands separators.
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
useGrouping?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The minimum number of fraction digits to use.
|
|
38
|
+
*/
|
|
39
|
+
minFractionDigits?: number;
|
|
40
|
+
/**
|
|
41
|
+
* The maximum number of fraction digits to use.
|
|
42
|
+
*/
|
|
43
|
+
maxFractionDigits?: number;
|
|
44
|
+
/**
|
|
45
|
+
* How decimals should be rounded.
|
|
46
|
+
*/
|
|
47
|
+
roundingMode?: 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfCeil' | 'halfFloor' | 'halfExpand' | 'halfTrunc' | 'halfEven';
|
|
48
|
+
/**
|
|
49
|
+
* Text to display before the value.
|
|
50
|
+
*/
|
|
51
|
+
prefix?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Text to display after the value.
|
|
54
|
+
*/
|
|
55
|
+
suffix?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Minimum boundary value (used to determine if minus sign is allowed).
|
|
58
|
+
*/
|
|
59
|
+
min?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to format the value.
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
format?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The exposes for the `useNumberFormatter` hook.
|
|
68
|
+
*/
|
|
69
|
+
export interface UseNumberFormatterExposes {
|
|
70
|
+
/**
|
|
71
|
+
* The formatted value based on the provided value and options.
|
|
72
|
+
*/
|
|
73
|
+
formattedValue: string;
|
|
74
|
+
/**
|
|
75
|
+
* Formats a numeric value to a localized string.
|
|
76
|
+
* @param value - The value to format
|
|
77
|
+
* @returns The formatted string
|
|
78
|
+
*/
|
|
79
|
+
formatValue: (value: number | string | null | undefined) => string;
|
|
80
|
+
/**
|
|
81
|
+
* Parses a formatted string back to a numeric value.
|
|
82
|
+
* @param text - The text to parse
|
|
83
|
+
* @returns The parsed number, '-' for minus sign only, or null if invalid
|
|
84
|
+
*/
|
|
85
|
+
parseValue: (text: string) => number | string | null;
|
|
86
|
+
/**
|
|
87
|
+
* Adds two numbers with floating-point precision handling.
|
|
88
|
+
* @param base - The base number
|
|
89
|
+
* @param increment - The increment to add
|
|
90
|
+
* @returns The sum with proper precision
|
|
91
|
+
*/
|
|
92
|
+
addWithPrecision: (base: number, increment: number) => number;
|
|
93
|
+
/**
|
|
94
|
+
* Checks if the mode is decimal.
|
|
95
|
+
* @returns True if mode is 'decimal'
|
|
96
|
+
*/
|
|
97
|
+
isDecimalMode: () => boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Checks if a character is a numeral character (digit, decimal, group separator, or minus sign).
|
|
100
|
+
* @param char - The character to check
|
|
101
|
+
* @returns True if the character is a numeral character
|
|
102
|
+
*/
|
|
103
|
+
isNumeralChar: (char: string) => boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if a character is a minus sign.
|
|
106
|
+
* @param char - The character to check
|
|
107
|
+
* @returns True if the character is a minus sign
|
|
108
|
+
*/
|
|
109
|
+
isMinusSign: (char: string) => boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Checks if a character is a decimal sign.
|
|
112
|
+
* @param char - The character to check
|
|
113
|
+
* @returns True if the character is a decimal sign
|
|
114
|
+
*/
|
|
115
|
+
isDecimalSign: (char: string) => boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Checks if minus sign is allowed based on min value.
|
|
118
|
+
* @returns True if minus sign is allowed
|
|
119
|
+
*/
|
|
120
|
+
allowMinusSign: () => boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the decimal character indexes in a value string.
|
|
123
|
+
* @param val - The value string to analyze
|
|
124
|
+
* @returns Object with decimalCharIndex and decimalCharIndexWithoutPrefix
|
|
125
|
+
*/
|
|
126
|
+
getDecimalCharIndexes: (val: string) => {
|
|
127
|
+
decimalCharIndex: number;
|
|
128
|
+
decimalCharIndexWithoutPrefix: number;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Gets various character indexes (decimal, minus, suffix, currency) in a value string.
|
|
132
|
+
* @param val - The value string to analyze
|
|
133
|
+
* @returns Object with character indexes
|
|
134
|
+
*/
|
|
135
|
+
getCharIndexes: (val: string) => {
|
|
136
|
+
decimalCharIndex: number;
|
|
137
|
+
minusCharIndex: number;
|
|
138
|
+
suffixCharIndex: number;
|
|
139
|
+
currencyCharIndex: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Gets the length of decimal part in a formatted value.
|
|
143
|
+
* @param value - The formatted value string
|
|
144
|
+
* @returns The decimal length
|
|
145
|
+
*/
|
|
146
|
+
getDecimalLength: (value: string) => number;
|
|
147
|
+
/**
|
|
148
|
+
* Concatenates two value strings, handling decimal positions.
|
|
149
|
+
* @param val1 - The first value
|
|
150
|
+
* @param val2 - The second value
|
|
151
|
+
* @returns The concatenated result
|
|
152
|
+
*/
|
|
153
|
+
concatValues: (val1: string, val2: string) => string;
|
|
154
|
+
/**
|
|
155
|
+
* The group character used for thousands separator.
|
|
156
|
+
*/
|
|
157
|
+
groupChar: string | null;
|
|
158
|
+
/**
|
|
159
|
+
* The prefix character/string.
|
|
160
|
+
*/
|
|
161
|
+
prefixChar: string | null;
|
|
162
|
+
/**
|
|
163
|
+
* The suffix character/string.
|
|
164
|
+
*/
|
|
165
|
+
suffixChar: string | null;
|
|
166
|
+
/**
|
|
167
|
+
* The resolved Intl.NumberFormat options.
|
|
168
|
+
*/
|
|
169
|
+
resolvedOptions: () => Intl.ResolvedNumberFormatOptions | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Reinitializes the parser (call when options change).
|
|
172
|
+
*/
|
|
173
|
+
constructParser: () => void;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* useNumberFormatter hook is used to format and parse numbers using Intl.NumberFormat.
|
|
177
|
+
*
|
|
178
|
+
* @param {UseNumberFormatterOptions} options - The options for the number formatter.
|
|
179
|
+
* @returns {UseNumberFormatterExposes} - The exposed methods for the number formatter.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```tsx
|
|
183
|
+
* const formatter = useNumberFormatter({
|
|
184
|
+
* value: 1234.56,
|
|
185
|
+
* locale: 'en-US',
|
|
186
|
+
* mode: 'currency',
|
|
187
|
+
* currency: 'USD'
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
* const formatted = formatter.formatValue(1234.56); // "$1,234.56"
|
|
191
|
+
* const parsed = formatter.parseValue("$1,234.56"); // 1234.56
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function useNumberFormatter(options?: UseNumberFormatterOptions): UseNumberFormatterExposes;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var ar=Object.defineProperty,lr=Object.defineProperties;var or=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var mr=Object.prototype.hasOwnProperty,fr=Object.prototype.propertyIsEnumerable;var T=(o,a,t)=>a in o?ar(o,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[a]=t,k=(o,a)=>{for(var t in a||(a={}))mr.call(a,t)&&T(o,t,a[t]);if(L)for(var t of L(a))fr.call(a,t)&&T(o,t,a[t]);return o},A=(o,a)=>lr(o,or(a));import*as i from"react";function pr(o={}){let{value:a,locale:t,localeMatcher:G,mode:x="decimal",currency:g,currencyDisplay:h,useGrouping:_=!0,minFractionDigits:C,maxFractionDigits:E,roundingMode:F,prefix:b,suffix:R,min:S,format:q=!0}=o,O=i.useRef(null),V=i.useRef(null),w=i.useRef(null),I=i.useRef(null),l=i.useRef(null),p=i.useRef(null),s=i.useRef(null),d=i.useRef(null),c=i.useRef(null),m=i.useRef(null),y=i.useRef(null),D=i.useRef(null),P=()=>({localeMatcher:G,style:x,currency:g,currencyDisplay:h,useGrouping:_,minimumFractionDigits:C!=null?C:void 0,maximumFractionDigits:E!=null?E:void 0,roundingMode:F}),N=r=>r.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),z=()=>{var e,n;let r=new Intl.NumberFormat(t,A(k({},P()),{useGrouping:!1}));return new RegExp(`[${r.format(1.1).replace((e=d.current)!=null?e:"","").trim().replace((n=l.current)!=null?n:"","")}]`,"g")},B=()=>{var e;let r=new Intl.NumberFormat(t,{useGrouping:!0});return V.current=r.format(1e6).trim().replace((e=l.current)!=null?e:"","").charAt(0),new RegExp(`[${V.current}]`,"g")},H=()=>{var e;let r=new Intl.NumberFormat(t,{useGrouping:!1});return new RegExp(`[${r.format(-1).trim().replace((e=l.current)!=null?e:"","")}]`,"g")},J=()=>{var r,e;if(g){let n=new Intl.NumberFormat(t,{style:"currency",currency:g,currencyDisplay:h,minimumFractionDigits:0,maximumFractionDigits:0,roundingMode:F});return new RegExp(`[${n.format(1).replace(/\s/g,"").replace((r=l.current)!=null?r:"","").replace((e=p.current)!=null?e:"","")}]`,"g")}return new RegExp("[]","g")},K=()=>{if(b)y.current=new RegExp(N(b),"g");else{let e=new Intl.NumberFormat(t,{style:x,currency:g,currencyDisplay:h}).format(1).split("1")[0];y.current=new RegExp(N(e),"g")}return y.current},Q=()=>{if(R)m.current=new RegExp(N(R),"g");else{let e=new Intl.NumberFormat(t,{style:x,currency:g,currencyDisplay:h,minimumFractionDigits:0,maximumFractionDigits:0,roundingMode:F}).format(1).split("1")[1];m.current=new RegExp(N(e),"g")}return m.current},U=()=>{O.current=new Intl.NumberFormat(t,P());let r=[...new Intl.NumberFormat(t,{useGrouping:!1}).format(9876543210)].reverse(),e=new Map(r.map((n,u)=>[n,u]));if(l.current=new RegExp(`[${r.join("")}]`,"g"),p.current=B(),s.current=H(),d.current=J(),c.current=z(),m.current=Q(),y.current=K(),D.current=n=>e.get(n),b)w.current=b;else{let n=new Intl.NumberFormat(t,{style:x,currency:g,currencyDisplay:h});w.current=n.format(1).split("1")[0]}if(R)I.current=R;else{let n=new Intl.NumberFormat(t,{style:x,currency:g,currencyDisplay:h,minimumFractionDigits:0,maximumFractionDigits:0,roundingMode:F});I.current=n.format(1).split("1")[1]}},W=r=>{if(r!=null){if(typeof r=="string"&&r==="-")return r;if(q){let e=new Intl.NumberFormat(t,P()),n=typeof r=="string"?Number(r):r,u=e.format(n);return b&&(u=b+u),R&&(u=u+R),u}return r.toString()}return""},X=r=>{var n;let e=r.replace(m.current||"","").replace(y.current||"","").trim().replace(/\s/g,"").replace(d.current||"","");if(c.current&&s.current&&l.current){let u=new RegExp(`[${[...new Intl.NumberFormat(t,{useGrouping:!1}).format(9876543210)].reverse().join("")}${new Intl.NumberFormat(t).format(1.1).replace(/[0-9]/g,"")}${new Intl.NumberFormat(t).format(-1).replace(/[0-9]/g,"")}]`,"g");e=((n=e.match(u))==null?void 0:n.join(""))||""}if(p.current&&(e=e.replace(p.current,"")),s.current&&(e=e.replace(s.current,"-")),c.current&&(e=e.replace(c.current,".")),l.current&&D.current&&(e=e.replace(l.current,u=>{let f=D.current?D.current(u):void 0;return f!==void 0?f.toString():""})),e){if(e==="-")return e;let u=+e;return isNaN(u)?null:u}return null},Y=(r,e)=>{let n=r.toString(),u=e.toString(),f=n.includes(".")?n.split(".")[1].length:0,$=u.includes(".")?u.split(".")[1].length:0,M=Math.max(f,$),j=Math.pow(10,M);return Math.round((r+e)*j)/j},Z=()=>x==="decimal",v=()=>{l.current&&(l.current.lastIndex=0),c.current&&(c.current.lastIndex=0),p.current&&(p.current.lastIndex=0),s.current&&(s.current.lastIndex=0)},rr=r=>r.length===1&&(l.current&&l.current.test(r)||c.current&&c.current.test(r)||p.current&&p.current.test(r)||s.current&&s.current.test(r))?(v(),!0):!1,er=r=>s.current&&s.current.test(r)||r==="-"?(s.current&&(s.current.lastIndex=0),!0):!1,nr=r=>t!=null&&t.includes("fr")&&[".",","].includes(r)||c.current&&c.current.test(r)?(c.current&&(c.current.lastIndex=0),!0):!1,tr=()=>S==null||S<0,ur=r=>{let e=c.current?r.search(c.current):-1;c.current&&(c.current.lastIndex=0);let n=r.replace(y.current||"","").trim().replace(/\s/g,"").replace(d.current||"",""),u=c.current?n.search(c.current):-1;return c.current&&(c.current.lastIndex=0),{decimalCharIndex:e,decimalCharIndexWithoutPrefix:u}},cr=r=>{let e=M=>{M&&(M.lastIndex=0)},n=c.current?r.search(c.current):-1;e(c.current);let u=s.current?r.search(s.current):-1;e(s.current);let f=m.current?r.search(m.current):-1;e(m.current);let $=d.current?r.search(d.current):-1;return e(d.current),{decimalCharIndex:n,minusCharIndex:u,suffixCharIndex:f,currencyCharIndex:$}},sr=r=>{var e,n,u;if(r){let f=r.split((e=c.current)!=null?e:"");if(f.length===2)return f[1].replace((n=m.current)!=null?n:"","").trim().replace(/\s/g,"").replace((u=d.current)!=null?u:"","").length}return 0},ir=(r,e)=>{if(r&&e){let n=c.current,u=n?e.search(n):-1;if(n&&(n.lastIndex=0),I.current)return u!==-1?r.replace(I.current,"").split(n!=null?n:"")[0]+e.replace(I.current,"").slice(u)+I.current:r;if(w.current)return u!==-1?r.split(n!=null?n:"")[0]+e.slice(u):r}return r};return i.useEffect(()=>{U()},[t,G,x,g,h,_,C,E,F,b,R]),{formattedValue:W(a),formatValue:W,parseValue:X,addWithPrecision:Y,isDecimalMode:Z,isNumeralChar:rr,isMinusSign:er,isDecimalSign:nr,allowMinusSign:tr,getDecimalCharIndexes:ur,getCharIndexes:cr,getDecimalLength:sr,concatValues:ir,groupChar:V.current,prefixChar:w.current,suffixChar:I.current,resolvedOptions:()=>{var r;return(r=O.current)==null?void 0:r.resolvedOptions()},constructParser:U}}export{pr as useNumberFormatter};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/use-number-formatter/index.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * The options for the `useNumberFormatter` hook.\n */\nexport interface UseNumberFormatterOptions {\n /**\n * The numeric value to be formatted.\n */\n value?: number | string | null | undefined;\n /**\n * Locale to be used in formatting.\n */\n locale?: string;\n /**\n * The locale matching algorithm to use. Possible values are 'lookup' and 'best fit'.\n * @default 'best fit'\n */\n localeMatcher?: 'lookup' | 'best fit';\n /**\n * Defines the behavior of the component.\n * @default 'decimal'\n */\n mode?: 'decimal' | 'currency';\n /**\n * The currency to use in currency formatting (ISO 4217 currency codes).\n */\n currency?: string;\n /**\n * How to display the currency in currency formatting.\n */\n currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name';\n /**\n * Whether to use grouping separators, such as thousands separators.\n * @default true\n */\n useGrouping?: boolean;\n /**\n * The minimum number of fraction digits to use.\n */\n minFractionDigits?: number;\n /**\n * The maximum number of fraction digits to use.\n */\n maxFractionDigits?: number;\n /**\n * How decimals should be rounded.\n */\n roundingMode?: 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfCeil' | 'halfFloor' | 'halfExpand' | 'halfTrunc' | 'halfEven';\n /**\n * Text to display before the value.\n */\n prefix?: string;\n /**\n * Text to display after the value.\n */\n suffix?: string;\n /**\n * Minimum boundary value (used to determine if minus sign is allowed).\n */\n min?: number;\n /**\n * Whether to format the value.\n * @default true\n */\n format?: boolean;\n}\n\n/**\n * The exposes for the `useNumberFormatter` hook.\n */\nexport interface UseNumberFormatterExposes {\n /**\n * The formatted value based on the provided value and options.\n */\n formattedValue: string;\n /**\n * Formats a numeric value to a localized string.\n * @param value - The value to format\n * @returns The formatted string\n */\n formatValue: (value: number | string | null | undefined) => string;\n /**\n * Parses a formatted string back to a numeric value.\n * @param text - The text to parse\n * @returns The parsed number, '-' for minus sign only, or null if invalid\n */\n parseValue: (text: string) => number | string | null;\n /**\n * Adds two numbers with floating-point precision handling.\n * @param base - The base number\n * @param increment - The increment to add\n * @returns The sum with proper precision\n */\n addWithPrecision: (base: number, increment: number) => number;\n /**\n * Checks if the mode is decimal.\n * @returns True if mode is 'decimal'\n */\n isDecimalMode: () => boolean;\n /**\n * Checks if a character is a numeral character (digit, decimal, group separator, or minus sign).\n * @param char - The character to check\n * @returns True if the character is a numeral character\n */\n isNumeralChar: (char: string) => boolean;\n /**\n * Checks if a character is a minus sign.\n * @param char - The character to check\n * @returns True if the character is a minus sign\n */\n isMinusSign: (char: string) => boolean;\n /**\n * Checks if a character is a decimal sign.\n * @param char - The character to check\n * @returns True if the character is a decimal sign\n */\n isDecimalSign: (char: string) => boolean;\n /**\n * Checks if minus sign is allowed based on min value.\n * @returns True if minus sign is allowed\n */\n allowMinusSign: () => boolean;\n /**\n * Gets the decimal character indexes in a value string.\n * @param val - The value string to analyze\n * @returns Object with decimalCharIndex and decimalCharIndexWithoutPrefix\n */\n getDecimalCharIndexes: (val: string) => { decimalCharIndex: number; decimalCharIndexWithoutPrefix: number };\n /**\n * Gets various character indexes (decimal, minus, suffix, currency) in a value string.\n * @param val - The value string to analyze\n * @returns Object with character indexes\n */\n getCharIndexes: (val: string) => { decimalCharIndex: number; minusCharIndex: number; suffixCharIndex: number; currencyCharIndex: number };\n /**\n * Gets the length of decimal part in a formatted value.\n * @param value - The formatted value string\n * @returns The decimal length\n */\n getDecimalLength: (value: string) => number;\n /**\n * Concatenates two value strings, handling decimal positions.\n * @param val1 - The first value\n * @param val2 - The second value\n * @returns The concatenated result\n */\n concatValues: (val1: string, val2: string) => string;\n /**\n * The group character used for thousands separator.\n */\n groupChar: string | null;\n /**\n * The prefix character/string.\n */\n prefixChar: string | null;\n /**\n * The suffix character/string.\n */\n suffixChar: string | null;\n /**\n * The resolved Intl.NumberFormat options.\n */\n resolvedOptions: () => Intl.ResolvedNumberFormatOptions | undefined;\n /**\n * Reinitializes the parser (call when options change).\n */\n constructParser: () => void;\n}\n\n/**\n * useNumberFormatter hook is used to format and parse numbers using Intl.NumberFormat.\n *\n * @param {UseNumberFormatterOptions} options - The options for the number formatter.\n * @returns {UseNumberFormatterExposes} - The exposed methods for the number formatter.\n *\n * @example\n * ```tsx\n * const formatter = useNumberFormatter({\n * value: 1234.56,\n * locale: 'en-US',\n * mode: 'currency',\n * currency: 'USD'\n * });\n *\n * const formatted = formatter.formatValue(1234.56); // \"$1,234.56\"\n * const parsed = formatter.parseValue(\"$1,234.56\"); // 1234.56\n * ```\n */\nexport function useNumberFormatter(options: UseNumberFormatterOptions = {}): UseNumberFormatterExposes {\n const { value, locale, localeMatcher, mode = 'decimal', currency, currencyDisplay, useGrouping = true, minFractionDigits, maxFractionDigits, roundingMode, prefix, suffix, min, format = true } = options;\n\n // Internal refs for regex patterns\n const numberFormat = React.useRef<Intl.NumberFormat | null>(null);\n const groupCharRef = React.useRef<string | null>(null);\n const prefixCharRef = React.useRef<string | null>(null);\n const suffixCharRef = React.useRef<string | null>(null);\n const _numeral = React.useRef<RegExp | null>(null);\n const _group = React.useRef<RegExp | null>(null);\n const _minusSign = React.useRef<RegExp | null>(null);\n const _currency = React.useRef<RegExp | null>(null);\n const _decimal = React.useRef<RegExp | null>(null);\n const _suffix = React.useRef<RegExp | null>(null);\n const _prefix = React.useRef<RegExp | null>(null);\n const _index = React.useRef<((d: string) => number | undefined) | null>(null);\n\n const getOptions = () => {\n return {\n localeMatcher: localeMatcher,\n style: mode,\n currency: currency,\n currencyDisplay: currencyDisplay,\n useGrouping: useGrouping,\n minimumFractionDigits: minFractionDigits ?? undefined,\n maximumFractionDigits: maxFractionDigits ?? undefined,\n roundingMode: roundingMode\n };\n };\n\n const escapeRegExp = (text: string) => {\n return text.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n };\n\n const getDecimalExpression = () => {\n const formatter = new Intl.NumberFormat(locale, { ...getOptions(), useGrouping: false });\n\n return new RegExp(\n `[${formatter\n .format(1.1)\n .replace(_currency.current ?? '', '')\n .trim()\n .replace(_numeral.current ?? '', '')}]`,\n 'g'\n );\n };\n\n const getGroupingExpression = () => {\n const formatter = new Intl.NumberFormat(locale, { useGrouping: true });\n\n groupCharRef.current = formatter\n .format(1000000)\n .trim()\n .replace(_numeral.current ?? '', '')\n .charAt(0);\n\n return new RegExp(`[${groupCharRef.current}]`, 'g');\n };\n\n const getMinusSignExpression = () => {\n const formatter = new Intl.NumberFormat(locale, { useGrouping: false });\n\n return new RegExp(\n `[${formatter\n .format(-1)\n .trim()\n .replace(_numeral.current ?? '', '')}]`,\n 'g'\n );\n };\n\n const getCurrencyExpression = () => {\n if (currency) {\n const formatter = new Intl.NumberFormat(locale, { style: 'currency', currency: currency, currencyDisplay: currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: roundingMode });\n\n return new RegExp(\n `[${formatter\n .format(1)\n .replace(/\\s/g, '')\n .replace(_numeral.current ?? '', '')\n .replace(_group.current ?? '', '')}]`,\n 'g'\n );\n }\n\n return new RegExp(`[]`, 'g');\n };\n\n const getPrefixExpression = () => {\n if (prefix) {\n _prefix.current = new RegExp(escapeRegExp(prefix), 'g');\n } else {\n const formatter = new Intl.NumberFormat(locale, { style: mode, currency: currency, currencyDisplay: currencyDisplay });\n\n const prefixStr = formatter.format(1).split('1')[0];\n\n _prefix.current = new RegExp(escapeRegExp(prefixStr), 'g');\n }\n\n return _prefix.current;\n };\n\n const getSuffixExpression = () => {\n if (suffix) {\n _suffix.current = new RegExp(escapeRegExp(suffix), 'g');\n } else {\n const formatter = new Intl.NumberFormat(locale, { style: mode, currency: currency, currencyDisplay: currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: roundingMode });\n\n const suffixStr = formatter.format(1).split('1')[1];\n\n _suffix.current = new RegExp(escapeRegExp(suffixStr), 'g');\n }\n\n return _suffix.current;\n };\n\n const constructParser = () => {\n numberFormat.current = new Intl.NumberFormat(locale, getOptions());\n const numerals = [...new Intl.NumberFormat(locale, { useGrouping: false }).format(9876543210)].reverse();\n const index = new Map(numerals.map((d, i) => [d, i]));\n\n _numeral.current = new RegExp(`[${numerals.join('')}]`, 'g');\n _group.current = getGroupingExpression();\n _minusSign.current = getMinusSignExpression();\n _currency.current = getCurrencyExpression();\n _decimal.current = getDecimalExpression();\n _suffix.current = getSuffixExpression();\n _prefix.current = getPrefixExpression();\n _index.current = (d) => index.get(d);\n\n // Set prefix and suffix chars\n if (prefix) {\n prefixCharRef.current = prefix;\n } else {\n const formatter = new Intl.NumberFormat(locale, { style: mode, currency: currency, currencyDisplay: currencyDisplay });\n\n prefixCharRef.current = formatter.format(1).split('1')[0];\n }\n\n if (suffix) {\n suffixCharRef.current = suffix;\n } else {\n const formatter = new Intl.NumberFormat(locale, { style: mode, currency: currency, currencyDisplay: currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: roundingMode });\n\n suffixCharRef.current = formatter.format(1).split('1')[1];\n }\n };\n\n const formatValue = (value: number | string | null | undefined) => {\n if (value != null) {\n if (typeof value === 'string' && value === '-') {\n // Minus sign\n return value;\n }\n\n if (format) {\n const formatter = new Intl.NumberFormat(locale, getOptions());\n const numericValue = typeof value === 'string' ? Number(value) : value;\n let formattedValue = formatter.format(numericValue);\n\n if (prefix) {\n formattedValue = prefix + formattedValue;\n }\n\n if (suffix) {\n formattedValue = formattedValue + suffix;\n }\n\n return formattedValue;\n }\n\n return value.toString();\n }\n\n return '';\n };\n\n const parseValue = (text: string) => {\n let cleanText = text\n .replace(_suffix.current || '', '')\n .replace(_prefix.current || '', '')\n .trim()\n .replace(/\\s/g, '')\n .replace(_currency.current || '', '');\n\n if (_decimal.current && _minusSign.current && _numeral.current) {\n const validChars = new RegExp(\n `[${[...new Intl.NumberFormat(locale, { useGrouping: false }).format(9876543210)].reverse().join('')}${new Intl.NumberFormat(locale).format(1.1).replace(/[0-9]/g, '')}${new Intl.NumberFormat(locale)\n .format(-1)\n .replace(/[0-9]/g, '')}]`,\n 'g'\n );\n\n cleanText = cleanText.match(validChars)?.join('') || '';\n }\n\n if (_group.current) {\n cleanText = cleanText.replace(_group.current, '');\n }\n\n if (_minusSign.current) {\n cleanText = cleanText.replace(_minusSign.current, '-');\n }\n\n if (_decimal.current) {\n cleanText = cleanText.replace(_decimal.current, '.');\n }\n\n if (_numeral.current && _index.current) {\n cleanText = cleanText.replace(_numeral.current, (d) => {\n const res = _index.current ? _index.current(d) : undefined;\n\n return res !== undefined ? res.toString() : '';\n });\n }\n\n if (cleanText) {\n if (cleanText === '-') return cleanText;\n\n const parsedValue = +cleanText;\n\n return isNaN(parsedValue) ? null : parsedValue;\n }\n\n return null;\n };\n\n const addWithPrecision = (base: number, increment: number) => {\n const baseStr = base.toString();\n const stepStr = increment.toString();\n\n const baseDecimalPlaces = baseStr.includes('.') ? baseStr.split('.')[1].length : 0;\n const stepDecimalPlaces = stepStr.includes('.') ? stepStr.split('.')[1].length : 0;\n\n const maxDecimalPlaces = Math.max(baseDecimalPlaces, stepDecimalPlaces);\n const precision = Math.pow(10, maxDecimalPlaces);\n\n return Math.round((base + increment) * precision) / precision;\n };\n\n const isDecimalMode = () => {\n return mode === 'decimal';\n };\n\n const resetRegex = () => {\n if (_numeral.current) _numeral.current.lastIndex = 0;\n\n if (_decimal.current) _decimal.current.lastIndex = 0;\n\n if (_group.current) _group.current.lastIndex = 0;\n\n if (_minusSign.current) _minusSign.current.lastIndex = 0;\n };\n\n const isNumeralChar = (char: string) => {\n if (char.length === 1 && ((_numeral.current && _numeral.current.test(char)) || (_decimal.current && _decimal.current.test(char)) || (_group.current && _group.current.test(char)) || (_minusSign.current && _minusSign.current.test(char)))) {\n resetRegex();\n\n return true;\n }\n\n return false;\n };\n\n const isMinusSignFn = (char: string) => {\n if ((_minusSign.current && _minusSign.current.test(char)) || char === '-') {\n if (_minusSign.current) {\n _minusSign.current.lastIndex = 0;\n }\n\n return true;\n }\n\n return false;\n };\n\n const isDecimalSignFn = (char: string) => {\n if ((locale?.includes('fr') && ['.', ','].includes(char)) || (_decimal.current && _decimal.current.test(char))) {\n if (_decimal.current) {\n _decimal.current.lastIndex = 0;\n }\n\n return true;\n }\n\n return false;\n };\n\n const allowMinusSign = () => {\n return min === undefined || min === null || min < 0;\n };\n\n const getDecimalCharIndexes = (val: string) => {\n const decimalCharIndex = _decimal.current ? val.search(_decimal.current) : -1;\n\n if (_decimal.current) {\n _decimal.current.lastIndex = 0;\n }\n\n const filteredVal = val\n .replace(_prefix.current || '', '')\n .trim()\n .replace(/\\s/g, '')\n .replace(_currency.current || '', '');\n const decimalCharIndexWithoutPrefix = _decimal.current ? filteredVal.search(_decimal.current) : -1;\n\n if (_decimal.current) {\n _decimal.current.lastIndex = 0;\n }\n\n return { decimalCharIndex, decimalCharIndexWithoutPrefix };\n };\n\n const getCharIndexes = (val: string) => {\n const resetRegexLastIndex = (regex: RegExp | null) => {\n if (regex) {\n regex.lastIndex = 0;\n }\n };\n\n const decimalCharIndex = _decimal.current ? val.search(_decimal.current) : -1;\n\n resetRegexLastIndex(_decimal.current);\n\n const minusCharIndex = _minusSign.current ? val.search(_minusSign.current) : -1;\n\n resetRegexLastIndex(_minusSign.current);\n\n const suffixCharIndex = _suffix.current ? val.search(_suffix.current) : -1;\n\n resetRegexLastIndex(_suffix.current);\n\n const currencyCharIndex = _currency.current ? val.search(_currency.current) : -1;\n\n resetRegexLastIndex(_currency.current);\n\n return { decimalCharIndex, minusCharIndex, suffixCharIndex, currencyCharIndex };\n };\n\n const getDecimalLength = (value: string) => {\n if (value) {\n const valueSplit = value.split(_decimal.current ?? '');\n\n if (valueSplit.length === 2) {\n return valueSplit[1]\n .replace(_suffix.current ?? '', '')\n .trim()\n .replace(/\\s/g, '')\n .replace(_currency.current ?? '', '').length;\n }\n }\n\n return 0;\n };\n\n const concatValues = (val1: string, val2: string) => {\n if (val1 && val2) {\n const decimalRegex = _decimal.current;\n const decimalCharIndex = decimalRegex ? val2.search(decimalRegex) : -1;\n\n if (decimalRegex) {\n decimalRegex.lastIndex = 0;\n }\n\n if (suffixCharRef.current) {\n return decimalCharIndex !== -1 ? val1.replace(suffixCharRef.current, '').split(decimalRegex ?? '')[0] + val2.replace(suffixCharRef.current, '').slice(decimalCharIndex) + suffixCharRef.current : val1;\n } else if (prefixCharRef.current) {\n return decimalCharIndex !== -1 ? val1.split(decimalRegex ?? '')[0] + val2.slice(decimalCharIndex) : val1;\n }\n }\n\n return val1;\n };\n\n React.useEffect(() => {\n constructParser();\n }, [locale, localeMatcher, mode, currency, currencyDisplay, useGrouping, minFractionDigits, maxFractionDigits, roundingMode, prefix, suffix]);\n\n return {\n formattedValue: formatValue(value),\n formatValue,\n parseValue,\n addWithPrecision,\n isDecimalMode,\n isNumeralChar,\n isMinusSign: isMinusSignFn,\n isDecimalSign: isDecimalSignFn,\n allowMinusSign,\n getDecimalCharIndexes,\n getCharIndexes,\n getDecimalLength,\n concatValues,\n groupChar: groupCharRef.current,\n prefixChar: prefixCharRef.current,\n suffixChar: suffixC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IAAqB,GAAKa,EAAK,QAAQrE,EAAc,QAAS,EAAE,EAAE,MAAMuE,GAAA,KAAAA,EAAgB,EAAE,EAAE,CAAC,EAAID,EAAK,QAAQtE,EAAc,QAAS,EAAE,EAAE,MAAMwD,CAAgB,EAAIxD,EAAc,QAAUqE,EAC/L,GAAItE,EAAc,QACrB,OAAOyD,IAAqB,GAAKa,EAAK,MAAME,GAAA,KAAAA,EAAgB,EAAE,EAAE,CAAC,EAAID,EAAK,MAAMd,CAAgB,EAAIa,CAE5G,CAEA,OAAOA,CACX,EAEA,OAAM,YAAU,IAAM,CAClB5C,EAAgB,CACpB,EAAG,CAACzC,EAAQC,EAAeC,EAAMC,EAAUC,EAAiBC,EAAaC,EAAmBC,EAAmBC,EAAcC,EAAQC,CAAM,CAAC,EAErI,CACH,eAAgBoC,EAAY/C,CAAK,EACjC,YAAA+C,EACA,WAAAG,EACA,iBAAAK,EACA,cAAAS,EACA,cAAAE,GACA,YAAaE,GACb,cAAeC,GACf,eAAAC,GACA,sBAAAC,GACA,eAAAK,GACA,iBAAAM,GACA,aAAAG,GACA,UAAWtE,EAAa,QACxB,WAAYC,EAAc,QAC1B,WAAYC,EAAc,QAC1B,gBAAiB,IAAG,CAxkB5B,IAAAa,EAwkB+B,OAAAA,EAAAhB,EAAa,UAAb,YAAAgB,EAAsB,mBAC7C,gBAAAY,CACJ,CACJ","names":["React","useNumberFormatter","options","value","locale","localeMatcher","mode","currency","currencyDisplay","useGrouping","minFractionDigits","maxFractionDigits","roundingMode","prefix","suffix","min","format","numberFormat","groupCharRef","prefixCharRef","suffixCharRef","_numeral","_group","_minusSign","_currency","_decimal","_suffix","_prefix","_index","getOptions","escapeRegExp","text","getDecimalExpression","_a","_b","formatter","__spreadProps","__spreadValues","getGroupingExpression","getMinusSignExpression","getCurrencyExpression","getPrefixExpression","prefixStr","getSuffixExpression","suffixStr","constructParser","numerals","index","d","i","formatValue","numericValue","formattedValue","parseValue","cleanText","validChars","res","parsedValue","addWithPrecision","base","increment","baseStr","stepStr","baseDecimalPlaces","stepDecimalPlaces","maxDecimalPlaces","precision","isDecimalMode","resetRegex","isNumeralChar","char","isMinusSignFn","isDecimalSignFn","allowMinusSign","getDecimalCharIndexes","val","decimalCharIndex","filteredVal","decimalCharIndexWithoutPrefix","getCharIndexes","resetRegexLastIndex","regex","minusCharIndex","suffixCharIndex","currencyCharIndex","getDecimalLength","_c","valueSplit","concatValues","val1","val2","decimalRegex"]}
|
|
File without changes
|
package/use-presence/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
/**
|
|
3
2
|
* usePresence hook is used to manage the presence of a component.
|
|
4
3
|
*
|
|
@@ -17,5 +16,5 @@ export declare function usePresence(open: boolean, fallbackMs?: number): {
|
|
|
17
16
|
present: boolean;
|
|
18
17
|
exiting: boolean;
|
|
19
18
|
mounted: boolean;
|
|
20
|
-
ref:
|
|
19
|
+
ref: (node: HTMLElement | null) => void;
|
|
21
20
|
};
|
package/use-presence/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as n from"react";function E(c,f=500){let[m,i]=n.useState(c),[d,a]=n.useState(!1),[R,l]=n.useState(!1),o=n.useRef(null),t=n.useRef(null),r=n.useRef(null),v=n.useCallback(e=>{o.current=e},[]);return n.useEffect(()=>{if(t.current&&(t.current(),t.current=null),r.current&&(r.current(),r.current=null),c){i(!0),a(!1);let e=[];e.push(requestAnimationFrame(()=>{e.push(requestAnimationFrame(()=>{e.push(requestAnimationFrame(()=>l(!0)))}))})),r.current=()=>{e.forEach(u=>cancelAnimationFrame(u)),e.length=0}}else if(o.current){a(!0),l(!1);let e=o.current,u=!1,s=()=>{u||(u=!0,i(!1),a(!1),e.removeEventListener("transitionend",s),e.removeEventListener("animationend",s),t.current=null)};e.addEventListener("transitionend",s,{passive:!0}),e.addEventListener("animationend",s,{passive:!0}),t.current=()=>{u||(e.removeEventListener("transitionend",s),e.removeEventListener("animationend",s))}}else l(!1),i(!1),a(!1)},[c,f]),n.useEffect(()=>()=>{t.current&&t.current(),r.current&&r.current()},[]),{present:m,exiting:d,mounted:R,ref:v}}export{E as usePresence};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|