UNPKG

react-vmodel

Version:

a vue v-model like usage for react with ts prompt

23 lines (22 loc) 9.22 kB
(function(R,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],g):(R=typeof globalThis<"u"?globalThis:R||self,g(R["react-vmodel"]={},R.react))})(this,function(R,g){"use strict";var p={exports:{}},w={};/** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var I;function K(){if(I)return w;I=1;var r=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(c,l,s){var h=null;if(s!==void 0&&(h=""+s),l.key!==void 0&&(h=""+l.key),"key"in l){s={};for(var f in l)f!=="key"&&(s[f]=l[f])}else s=l;return l=s.ref,{$$typeof:r,type:c,key:h,ref:l!==void 0?l:null,props:s}}return w.Fragment=t,w.jsx=n,w.jsxs=n,w}var x={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var L;function ee(){return L||(L=1,process.env.NODE_ENV!=="production"&&function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===de?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case A:return"Fragment";case O:return"Profiler";case _:return"StrictMode";case oe:return"Suspense";case se:return"SuspenseList";case ie:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case j:return"Portal";case ce:return(e.displayName||"Context")+".Provider";case P:return(e._context.displayName||"Context")+".Consumer";case le:var u=e.render;return e=e.displayName,e||(e=u.displayName||u.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case fe:return u=e.displayName||null,u!==null?u:r(e.type)||"Memo";case J:u=e._payload,e=e._init;try{return r(e(u))}catch{}}return null}function t(e){return""+e}function n(e){try{t(e);var u=!1}catch{u=!0}if(u){u=console;var i=u.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),t(e)}}function c(e){if(e===A)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===J)return"<...>";try{var u=r(e);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function l(){var e=V.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function h(e){if(q.call(e,"key")){var u=Object.getOwnPropertyDescriptor(e,"key").get;if(u&&u.isReactWarning)return!1}return e.key!==void 0}function f(e,u){function i(){X||(X=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",u))}i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}function a(){var e=r(this.type);return B[e]||(B[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function o(e,u,i,m,T,y,M,D){return i=y.ref,e={$$typeof:k,type:e,key:u,props:y,_owner:T},(i!==void 0?i:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:a}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:M}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,u,i,m,T,y,M,D){var v=u.children;if(v!==void 0)if(m)if(me(v)){for(m=0;m<v.length;m++)b(v[m]);Object.freeze&&Object.freeze(v)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else b(v);if(q.call(u,"key")){v=r(e);var S=Object.keys(u).filter(function(ve){return ve!=="key"});m=0<S.length?"{key: someKey, "+S.join(": ..., ")+": ...}":"{key: someKey}",Q[v+m]||(S=0<S.length?"{"+S.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,m,v,S,v),Q[v+m]=!0)}if(v=null,i!==void 0&&(n(i),v=""+i),h(u)&&(n(u.key),v=""+u.key),"key"in u){i={};for(var F in u)F!=="key"&&(i[F]=u[F])}else i=u;return v&&f(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),o(e,v,y,T,l(),i,M,D)}function b(e){typeof e=="object"&&e!==null&&e.$$typeof===k&&e._store&&(e._store.validated=1)}var E=g,k=Symbol.for("react.transitional.element"),j=Symbol.for("react.portal"),A=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),O=Symbol.for("react.profiler"),P=Symbol.for("react.consumer"),ce=Symbol.for("react.context"),le=Symbol.for("react.forward_ref"),oe=Symbol.for("react.suspense"),se=Symbol.for("react.suspense_list"),fe=Symbol.for("react.memo"),J=Symbol.for("react.lazy"),ie=Symbol.for("react.activity"),de=Symbol.for("react.client.reference"),V=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,q=Object.prototype.hasOwnProperty,me=Array.isArray,Y=console.createTask?console.createTask:function(){return null};E={"react-stack-bottom-frame":function(e){return e()}};var X,B={},H=E["react-stack-bottom-frame"].bind(E,s)(),Z=Y(c(s)),Q={};x.Fragment=A,x.jsx=function(e,u,i,m,T){var y=1e4>V.recentlyCreatedOwnerStacks++;return d(e,u,i,!1,m,T,y?Error("react-stack-top-frame"):H,y?Y(c(e)):Z)},x.jsxs=function(e,u,i,m,T){var y=1e4>V.recentlyCreatedOwnerStacks++;return d(e,u,i,!0,m,T,y?Error("react-stack-top-frame"):H,y?Y(c(e)):Z)}}()),x}process.env.NODE_ENV==="production"?p.exports=K():p.exports=ee();var W=p.exports;function $(r){const n=String(r).replaceAll('"',"").replaceAll("'","").split("."),c=[];return n.forEach(l=>{l.replaceAll("]","").split("[").forEach(s=>{s!==""&&c.push(s)})}),c}function U(r,t){if(t===void 0)return r;if(!(typeof r=="object"&&r!==null))return;let n=[];typeof t=="string"||typeof t=="number"||typeof t=="symbol"?n=$(t):n=t;const c=n.shift();return c!==void 0?n.length?U(r[c],n):r[c]:r}const re=r=>Array.isArray(r)?[...r]:typeof r=="object"?{...r}:r;function z(r,t,n){if(t===void 0)return r;if(!(typeof r=="object"&&r!==null))return;let c=[];typeof t=="string"||typeof t=="number"||typeof t=="symbol"?c=$(t):c=t;const l=c.shift(),s=re(r);return l!==void 0&&(c.length?s[l]=z(r[l],c,n):s[l]=n),s}function te(r,t){return U(r,t)}function ne(r,t,n){return z(r,t,n)}const G=r=>{let t=!0,n=!1;return r&&("trueValue"in r?t=r.trueValue:"value"in r&&(t=r.value),"falseValue"in r&&(n=r.falseValue)),{trueValue:t,falseValue:n}},N=(...r)=>{let t,n,c;for(let l=0;l<r.length;l++){const s=r[l];!t&&typeof s=="string"?t=s:!n&&typeof s=="object"?n=s:!c&&typeof s=="function"&&(c=s)}return c||(c=(l,s)=>({value:l,onChange:s})),{key:t,options:n,transform:c}},C=(r,t)=>{const n=(f,a)=>{const o=te(r,f);return a!=null&&a.getter?a.getter(o):o},c=(f,a)=>o=>{var k,j,A;if(t===void 0)return;let d=o!=null&&o.target?o.target.value:o;const b=n(f),E=(k=o==null?void 0:o.target)==null?void 0:k.type;if(a!=null&&a.checklist){const _=Array.isArray(b)?b.slice():[],O=_.indexOf(a==null?void 0:a.value),P=!a.checked;O!==-1?P||_.splice(O,1):P&&_.push(a==null?void 0:a.value),d=_}else if(a!=null&&a.checkbox){const _=((j=o.target)==null?void 0:j.checked)??((A=o.target)==null?void 0:A.value)??o??!(a!=null&&a.checked),{trueValue:O,falseValue:P}=G(a);d=_?O:P}if(typeof d=="string"&&(a!=null&&a.trim)&&(d=d.trim()),(E==="number"||a!=null&&a.parseNumber)&&(d=Number(d)),f!==void 0){const _=ne(r,f,d);t(_)}else t(d)};function l(...f){const{key:a,options:o,transform:d}=N(...f),b=n(a,o),E=c(a,o);return d(b,E)}l.number=f=>({value:n(f),onChange:c(f,{parseNumber:!0})}),l.trim=f=>({value:n(f),onChange:c(f,{trim:!0})});function s(...f){const{key:a,options:o}=N(...f),d=n(a),{trueValue:b}=G(o),E=d===b,k={checked:E,onChange:c(a,{...o,checked:E,checkbox:!0})};return{...k,value:(o==null?void 0:o.value)??k.checked}}l.checked=s;function h(...f){const{key:a,options:o}=N(...f),d=n(a);let b=!1;const E=o==null?void 0:o.value;return Array.isArray(d)&&(b=!!d.find(k=>k===E)),{value:E,checked:b,onChange:c(a,{...o,checked:b,checklist:!0})}}return l.checklist=h,l},ae=r=>{const[t,n]=g.useState(r);return[C(t,n),t,n]};function ue({children:r,value:t,onChange:n}){const c=C(t,n);return W.jsx(W.Fragment,{children:r(c,t,l=>{n&&n(l)})})}R.Model=ue,R.makeVModel=C,R.useVModel=ae,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});