@react-input/core
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -1,1 +0,1 @@ | ||
import{useRef as e,useMemo as t}from"react";import{unstable_batchedUpdates as n}from"react-dom";import r from"../errors/SyntheticChangeError.js";import l from"../utils/setInputAttributes.js";import"../_rollupPluginBabelHelpers-D3WySQMf.js";var u=["text","email","tel","search","url"];function i(i){var o=i.init,a=i.tracking,c=i.eventType,d=i.eventHandler,v=e({timeoutId:-1,fallbackTimeoutId:-1,cachedTimeoutId:-1,start:0,end:0}),s=e(!0),m=e(null),p=e({init:o,tracking:a,eventType:c,eventHandler:d});return p.current.init=o,p.current.tracking=a,p.current.eventType=c,p.current.eventHandler=d,t((function(){return function(e,t,n){var r=n.onFocus,i=n.onBlur,o=n.onInput;return new Proxy(e,{set:function(n,a,c){if("current"!==a)return!1;var d=null!==c&&u.includes(c.type);if("production"===process.env.NODE_ENV||null===c||d||console.warn("Warn: The input element type does not match one of the types: ".concat(u.join(", "),".")),c!==e.current&&(null!==e.current&&(e.current.removeEventListener("focus",r),e.current.removeEventListener("blur",i),e.current.removeEventListener("input",o)),null!==c&&d)){var v,s=null!==(v=c._wrapperState)&&void 0!==v?v:{},m=s.controlled,p=void 0!==m&&m,f=s.initialValue,h=void 0===f?"":f,E=t({controlled:p,initialValue:c.value||h});l(c,{value:E.value}),document.activeElement===c&&r(),c.addEventListener("focus",r),c.addEventListener("blur",i),c.addEventListener("input",o)}return n[a]=c,!0}})}(m,p.current.init,{onFocus:function(){v.current.timeoutId=window.setTimeout((function e(){var t,n,r,l;s.current?(v.current.start=null!==(t=null===(n=m.current)||void 0===n?void 0:n.selectionStart)&&void 0!==t?t:0,v.current.end=null!==(r=null===(l=m.current)||void 0===l?void 0:l.selectionEnd)&&void 0!==r?r:0,v.current.timeoutId=window.setTimeout(e)):v.current.fallbackTimeoutId=window.setTimeout(e)}))},onBlur:function(){window.clearTimeout(v.current.timeoutId),window.clearTimeout(v.current.fallbackTimeoutId),v.current.timeoutId=-1,v.current.fallbackTimeoutId=-1,v.current.cachedTimeoutId=-1},onInput:function(e){var t=m.current;if(null!==t)try{var u,i,o,a,c;if(v.current.cachedTimeoutId===v.current.timeoutId)throw new r("The input selection has not been updated.");v.current.cachedTimeoutId=v.current.timeoutId;var d=t.value,f=t.selectionStart,h=t.selectionEnd;if(null===f||null===h)throw new r("The selection attributes have not been initialized.");var E,w=null!==(u=null===(i=t._valueTracker)||void 0===i||null===(o=i.getValue)||void 0===o?void 0:o.call(i))&&void 0!==u?u:"";if(f>v.current.start?E="insert":f<=v.current.start&&f<v.current.end?E="deleteBackward":f===v.current.end&&d.length<w.length&&(E="deleteForward"),void 0===E||("deleteBackward"===E||"deleteForward"===E)&&d.length>w.length)throw new r("Input type detection error.");var T="",b="",_=v.current.start,g=v.current.end;if("insert"===E)T=d.slice(v.current.start,f);else{var I=w.length-d.length;_=f,g=f+I,b=w.slice(_,g)}var S=p.current.tracking({inputType:E,previousValue:w,value:d,addedValue:T,deletedValue:b,changeStart:_,changeEnd:g,selectionStart:f,selectionEnd:h});l(t,{value:S.value,selectionStart:S.selectionStart,selectionEnd:S.selectionEnd});var y=p.current.eventType,k=p.current.eventHandler;if("string"==typeof y&&k){var V=t.value,L=t.selectionStart,B=t.selectionEnd;s.current=!1,requestAnimationFrame((function(){l(t,{value:V,selectionStart:null!=L?L:V.length,selectionEnd:null!=B?B:V.length});var e=new CustomEvent(y,{bubbles:!0,cancelable:!1,composed:!0,detail:S.__detail});t.dispatchEvent(e),n?n(k,e):k(e),s.current=!0}))}null===(a=t._valueTracker)||void 0===a||null===(c=a.setValue)||void 0===c||c.call(a,w),v.current.start=S.selectionStart,v.current.end=S.selectionEnd}catch(n){var F,H,j,x,C,P,A,D,N,q,z,O=n,W=O.name,G=O.cause;if(l(t,{value:null!==(F=null!==(H=null==G||null===(j=G.__attributes)||void 0===j?void 0:j.value)&&void 0!==H?H:null===(x=t._valueTracker)||void 0===x||null===(C=x.getValue)||void 0===C?void 0:C.call(x))&&void 0!==F?F:"",selectionStart:null!==(P=null==G||null===(A=G.__attributes)||void 0===A?void 0:A.selectionStart)&&void 0!==P?P:v.current.start,selectionEnd:null!==(D=null==G||null===(N=G.__attributes)||void 0===N?void 0:N.selectionEnd)&&void 0!==D?D:v.current.end}),void 0!==(null==G||null===(q=G.__attributes)||void 0===q?void 0:q.selectionStart)&&(v.current.start=G.__attributes.selectionStart),void 0!==(null==G||null===(z=G.__attributes)||void 0===z?void 0:z.selectionEnd)&&(v.current.end=G.__attributes.selectionEnd),e.preventDefault(),e.stopPropagation(),"SyntheticChangeError"!==W)throw n}}})}),[])}export{i as default}; | ||
import{useRef as e,useMemo as t}from"react";import{unstable_batchedUpdates as n}from"react-dom";import r from"../errors/SyntheticChangeError.js";import l from"../utils/setInputAttributes.js";import"../_rollupPluginBabelHelpers-D3WySQMf.js";var u=["text","email","tel","search","url"];function i(i){var o=i.init,a=i.tracking,c=i.eventType,d=i.eventHandler,v=e({timeoutId:-1,fallbackTimeoutId:-1,cachedTimeoutId:-1,start:0,end:0}),s=e(!0),m=e(null),p=e({init:o,tracking:a,eventType:c,eventHandler:d});return p.current.init=o,p.current.tracking=a,p.current.eventType=c,p.current.eventHandler=d,t((function(){return function(e,t,n){var r=n.onFocus,i=n.onBlur,o=n.onInput;return new Proxy(e,{set:function(n,a,c){if("current"!==a)return!1;var d=null!==c&&u.includes(c.type);if("production"===process.env.NODE_ENV||null===c||d||console.warn("Warn: The input element type does not match one of the types: ".concat(u.join(", "),".")),c!==e.current&&(null!==e.current&&(e.current.removeEventListener("focus",r),e.current.removeEventListener("blur",i),e.current.removeEventListener("input",o)),null!==c&&d)){var v,s=null!==(v=c._wrapperState)&&void 0!==v?v:{},m=s.controlled,p=void 0!==m&&m,h=s.initialValue,f=void 0===h?"":h,E=t({controlled:p,initialValue:c.value||f});l(c,{value:E.value}),document.activeElement===c&&r(),c.addEventListener("focus",r),c.addEventListener("blur",i),c.addEventListener("input",o)}return n[a]=c,!0}})}(m,p.current.init,{onFocus:function(){v.current.timeoutId=window.setTimeout((function e(){var t,n,r,l;s.current?(v.current.start=null!==(t=null===(n=m.current)||void 0===n?void 0:n.selectionStart)&&void 0!==t?t:0,v.current.end=null!==(r=null===(l=m.current)||void 0===l?void 0:l.selectionEnd)&&void 0!==r?r:0,v.current.timeoutId=window.setTimeout(e)):v.current.fallbackTimeoutId=window.setTimeout(e)}))},onBlur:function(){window.clearTimeout(v.current.timeoutId),window.clearTimeout(v.current.fallbackTimeoutId),v.current.timeoutId=-1,v.current.fallbackTimeoutId=-1,v.current.cachedTimeoutId=-1},onInput:function(e){var t=m.current;if(null!==t)try{var u,i,o,a,c;if(v.current.cachedTimeoutId===v.current.timeoutId)throw new r("The input selection has not been updated.");v.current.cachedTimeoutId=v.current.timeoutId;var d=t.value,h=t.selectionStart,f=t.selectionEnd;if(null===h||null===f)throw new r("The selection attributes have not been initialized.");var E,w=null!==(u=null===(i=t._valueTracker)||void 0===i||null===(o=i.getValue)||void 0===o?void 0:o.call(i))&&void 0!==u?u:"";if(void 0===e.inputType&&(v.current.start=0,v.current.end=w.length),h>v.current.start?E="insert":h<=v.current.start&&h<v.current.end?E="deleteBackward":h===v.current.end&&d.length<w.length&&(E="deleteForward"),void 0===E||("deleteBackward"===E||"deleteForward"===E)&&d.length>w.length)throw new r("Input type detection error.");var T="",b="",g=v.current.start,_=v.current.end;if("insert"===E)T=d.slice(v.current.start,h);else{var I=w.length-d.length;g=h,_=h+I,b=w.slice(g,_)}var S=p.current.tracking({inputType:E,previousValue:w,value:d,addedValue:T,deletedValue:b,changeStart:g,changeEnd:_,selectionStart:h,selectionEnd:f});l(t,{value:S.value,selectionStart:S.selectionStart,selectionEnd:S.selectionEnd});var y=p.current.eventType,k=p.current.eventHandler;if("string"==typeof y&&k){var V=t.value,L=t.selectionStart,B=t.selectionEnd;s.current=!1,requestAnimationFrame((function(){l(t,{value:V,selectionStart:null!=L?L:V.length,selectionEnd:null!=B?B:V.length});var e=new CustomEvent(y,{bubbles:!0,cancelable:!1,composed:!0,detail:S.__detail});t.dispatchEvent(e),n?n(k,e):k(e),s.current=!0}))}null===(a=t._valueTracker)||void 0===a||null===(c=a.setValue)||void 0===c||c.call(a,w),v.current.start=S.selectionStart,v.current.end=S.selectionEnd}catch(n){var F,H,j,x,C,P,A,D,N,q,z,O=n,W=O.name,G=O.cause;if(l(t,{value:null!==(F=null!==(H=null==G||null===(j=G.__attributes)||void 0===j?void 0:j.value)&&void 0!==H?H:null===(x=t._valueTracker)||void 0===x||null===(C=x.getValue)||void 0===C?void 0:C.call(x))&&void 0!==F?F:"",selectionStart:null!==(P=null==G||null===(A=G.__attributes)||void 0===A?void 0:A.selectionStart)&&void 0!==P?P:v.current.start,selectionEnd:null!==(D=null==G||null===(N=G.__attributes)||void 0===N?void 0:N.selectionEnd)&&void 0!==D?D:v.current.end}),void 0!==(null==G||null===(q=G.__attributes)||void 0===q?void 0:q.selectionStart)&&(v.current.start=G.__attributes.selectionStart),void 0!==(null==G||null===(z=G.__attributes)||void 0===z?void 0:z.selectionEnd)&&(v.current.end=G.__attributes.selectionEnd),e.preventDefault(),e.stopPropagation(),"SyntheticChangeError"!==W)throw n}}})}),[])}export{i as default}; |
{ | ||
"name": "@react-input/core", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"author": "Nikolay Goncharuk <goncharuk.bro@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "The core of the packages included in the `@react-input` scope.", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24037