@react-input/core
Advanced tools
Comparing version 2.0.1 to 2.0.2
export type InputType = 'insert' | 'deleteBackward' | 'deleteForward'; | ||
export interface InputAttributes { | ||
value: string; | ||
selectionStart: number; | ||
selectionEnd: number; | ||
} | ||
export type InitFunction<T> = (param: { | ||
@@ -24,3 +19,6 @@ initialValue: string; | ||
selectionEnd: number; | ||
}) => InputAttributes & { | ||
}) => { | ||
value: string; | ||
selectionStart: number; | ||
selectionEnd: number; | ||
options: T; | ||
@@ -27,0 +25,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
import{a as e,b as t,c as n,d as o}from"./helpers-C8k3UfPS.js";import i from"./SyntheticChangeError.js";var l,a=["options"],r=["text","email","tel","search","url"];function s(e,t){var n=t.value,o=t.selectionStart,i=t.selectionEnd;void 0!==n&&(e.value=n),void 0!==o&&void 0!==i&&e.setSelectionRange(o,i)}var c=e((function e(l){var c=l.init,d=l.tracking;t(this,e);var u=new WeakMap;this.register=function(e){var t;if(r.includes(e.type)){var l=null!==(t=e._wrapperState)&&void 0!==t?t:{},v=l.initialValue,p=void 0===v?"":v,h=l.controlled,f=void 0!==h&&h,E=c({initialValue:e.value||p,controlled:f}),w=E.value,g=E.options,S={value:w,options:g,fallbackOptions:g},m={id:-1,cachedId:-1},b={value:"",selectionStart:0,selectionEnd:0},y=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");Object.defineProperty(e,"value",n(n({},y),{},{set:function(t){var n;b.value=t,null==y||null===(n=y.set)||void 0===n||n.call(e,t)}})),s(e,{value:w});var T=function(){var t=function(){var n,o;b.selectionStart=null!==(n=e.selectionStart)&&void 0!==n?n:0,b.selectionEnd=null!==(o=e.selectionEnd)&&void 0!==o?o:0,m.id=window.setTimeout(t)};m.id=window.setTimeout(t)},I=function(){window.clearTimeout(m.id),m.id=-1,m.cachedId=-1},O=function(t){try{var n,l;if(m.cachedId===m.id)throw new i("The input selection has not been updated.");m.cachedId=m.id;var r=e.value,c=e.selectionStart,u=e.selectionEnd;if(null===c||null===u)throw new i("The selection attributes have not been initialized.");var v,p=b.value;if(void 0===t.inputType&&(b.selectionStart=0,b.selectionEnd=p.length),c>b.selectionStart?v="insert":c<=b.selectionStart&&c<b.selectionEnd?v="deleteBackward":c===b.selectionEnd&&r.length<p.length&&(v="deleteForward"),void 0===v||("deleteBackward"===v||"deleteForward"===v)&&r.length>p.length)throw new i("Input type detection error.");var h="",f=b.selectionStart,E=b.selectionEnd;if("insert"===v)h=r.slice(b.selectionStart,c);else{var w=p.length-r.length;f=c,E=c+w}S.value!==p?S.options=S.fallbackOptions:S.fallbackOptions=S.options;var g=S.options,y=d({inputType:v,previousValue:p,previousOptions:g,value:r,addedValue:h,changeStart:f,changeEnd:E,selectionStart:c,selectionEnd:u}),T=y.options,I=o(y,a);s(e,I),S.value=I.value,S.options=T,b.selectionStart=I.selectionStart,b.selectionEnd=I.selectionEnd,null===(n=e._valueTracker)||void 0===n||null===(l=n.setValue)||void 0===l||l.call(n,p)}catch(n){if(s(e,b),t.preventDefault(),t.stopPropagation(),"SyntheticChangeError"!==n.name)throw n}};document.activeElement===e&&T(),e.addEventListener("focus",T),e.addEventListener("blur",I),e.addEventListener("input",O),u.set(e,{onFocus:T,onBlur:I,onInput:O})}else"production"!==process.env.NODE_ENV&&console.warn("Warn: The input element type does not match one of the types: ".concat(r.join(", "),"."))},this.unregister=function(e){var t=u.get(e);void 0!==t&&(e.removeEventListener("focus",t.onFocus),e.removeEventListener("blur",t.onBlur),e.removeEventListener("input",t.onInput),u.delete(e))}}));l=c,Object.defineProperty(l.prototype,Symbol.toStringTag,{writable:!1,enumerable:!1,configurable:!0,value:"Input"});export{c as default}; | ||
import{a as e,b as t,c as n,d as o}from"./helpers-C8k3UfPS.js";import i from"./SyntheticChangeError.js";var l,a=["options"],r=["text","email","tel","search","url"],s=e((function e(l){var s=l.init,c=l.tracking;t(this,e);var u=new WeakMap;this.register=function(e){var t;if(r.includes(e.type)){var l=null!==(t=e._wrapperState)&&void 0!==t?t:{},d=l.initialValue,v=void 0===d?"":d,p=l.controlled,h=void 0!==p&&p,f=s({initialValue:e.value||v,controlled:h}),E=f.value,g=f.options,w={value:E,options:g,fallbackOptions:g},S={id:-1,cachedId:-1},m={value:"",selectionStart:0,selectionEnd:0},b=Object.getOwnPropertyDescriptor("_valueTracker"in e?e:HTMLInputElement.prototype,"value");Object.defineProperty(e,"value",n(n({},b),{},{set:function(t){var n;m.value=t,null==b||null===(n=b.set)||void 0===n||n.call(e,t)}})),e.value=E;var y=function(){var t=function(){var n,o;m.selectionStart=null!==(n=e.selectionStart)&&void 0!==n?n:0,m.selectionEnd=null!==(o=e.selectionEnd)&&void 0!==o?o:0,S.id=window.setTimeout(t)};S.id=window.setTimeout(t)},T=function(){window.clearTimeout(S.id),S.id=-1,S.cachedId=-1},k=function(t){try{var n,l;if(S.cachedId===S.id)throw new i("The input selection has not been updated.");S.cachedId=S.id;var r=e.value,s=e.selectionStart,u=e.selectionEnd;if(null===s||null===u)throw new i("The selection attributes have not been initialized.");var d,v=m.value;if(void 0===t.inputType&&(m.selectionStart=0,m.selectionEnd=v.length),s>m.selectionStart?d="insert":s<=m.selectionStart&&s<m.selectionEnd?d="deleteBackward":s===m.selectionEnd&&r.length<v.length&&(d="deleteForward"),void 0===d||("deleteBackward"===d||"deleteForward"===d)&&r.length>v.length)throw new i("Input type detection error.");var p="",h=m.selectionStart,f=m.selectionEnd;if("insert"===d)p=r.slice(m.selectionStart,s);else{var E=v.length-r.length;h=s,f=s+E}w.value!==v?w.options=w.fallbackOptions:w.fallbackOptions=w.options;var g=w.options,b=c({inputType:d,previousValue:v,previousOptions:g,value:r,addedValue:p,changeStart:h,changeEnd:f,selectionStart:s,selectionEnd:u}),y=b.options,T=o(b,a);e.value=T.value,e.setSelectionRange(T.selectionStart,T.selectionEnd),w.value=T.value,w.options=y,m.selectionStart=T.selectionStart,m.selectionEnd=T.selectionEnd,null===(n=e._valueTracker)||void 0===n||null===(l=n.setValue)||void 0===l||l.call(n,v)}catch(n){if(e.value=m.value,e.setSelectionRange(m.selectionStart,m.selectionEnd),t.preventDefault(),t.stopPropagation(),"SyntheticChangeError"!==n.name)throw n}};document.activeElement===e&&y(),e.addEventListener("focus",y),e.addEventListener("blur",T),e.addEventListener("input",k),u.set(e,{onFocus:y,onBlur:T,onInput:k})}else"production"!==process.env.NODE_ENV&&console.warn("Warn: The input element type does not match one of the types: ".concat(r.join(", "),"."))},this.unregister=function(e){var t=u.get(e);void 0!==t&&(e.removeEventListener("focus",t.onFocus),e.removeEventListener("blur",t.onBlur),e.removeEventListener("input",t.onInput),u.delete(e))}}));l=s,Object.defineProperty(l.prototype,Symbol.toStringTag,{writable:!1,enumerable:!1,configurable:!0,value:"Input"});export{s as default}; |
{ | ||
"name": "@react-input/core", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Nikolay Goncharuk <goncharuk.bro@gmail.com>", |
Sorry, the diff of this file is not supported yet
23289
122