@form-instant/react-input-mapping 0.1.7 → 0.1.11
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/dist/react-input-mapping.cjs.development.js +1 -8
- package/dist/react-input-mapping.cjs.development.js.map +1 -1
- package/dist/react-input-mapping.cjs.production.min.js +1 -1
- package/dist/react-input-mapping.cjs.production.min.js.map +1 -1
- package/dist/react-input-mapping.esm.js +2 -9
- package/dist/react-input-mapping.esm.js.map +1 -1
- package/package.json +2 -7
- package/src/InputMapping/class.ts +0 -70
- package/src/InputMapping/context.tsx +0 -4
- package/src/InputMapping/index.ts +0 -5
- package/src/InputMapping/provider.tsx +0 -38
- package/src/InputMapping/types.ts +0 -27
- package/src/InputMapping/useInputMapping.tsx +0 -30
- package/src/global.d.ts +0 -13
- package/src/index.ts +0 -1
|
@@ -68,9 +68,6 @@ function _isNativeReflectConstruct() {
|
|
|
68
68
|
return !!t;
|
|
69
69
|
})();
|
|
70
70
|
}
|
|
71
|
-
function _objectDestructuringEmpty(t) {
|
|
72
|
-
if (null == t) throw new TypeError("Cannot destructure " + t);
|
|
73
|
-
}
|
|
74
71
|
function _setPrototypeOf(t, e) {
|
|
75
72
|
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
76
73
|
return t.__proto__ = e, t;
|
|
@@ -210,12 +207,8 @@ var createFormInstantContainer = function createFormInstantContainer(inputMappin
|
|
|
210
207
|
var ElementMapping = function ElementMapping(props) {
|
|
211
208
|
var InputMapping = useInputMapping();
|
|
212
209
|
var Element = InputMapping.get(props.type);
|
|
213
|
-
var key = react.useId();
|
|
214
|
-
var prop = _extends({}, (_objectDestructuringEmpty(props), props));
|
|
215
210
|
if (!Element) return null;
|
|
216
|
-
return react.createElement(Element,
|
|
217
|
-
key: key
|
|
218
|
-
}));
|
|
211
|
+
return react.createElement(Element, props);
|
|
219
212
|
};
|
|
220
213
|
|
|
221
214
|
exports.ElementMapping = ElementMapping;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-input-mapping.cjs.development.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/useInputMapping.tsx","../src/InputMapping/provider.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS } from './types';\n\ntype MergeKeys<T, U> = {\n [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;\n};\n\n// K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas\nexport class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<\n MergeKeys<K, INPUT_COMPONENTS_KEYS>,\n FC<P>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;\n\n type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n\n for (const key of keys) this.set(key as Ky, obj[key]!);\n\n for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);\n }\n\n constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n super();\n\n if (!obj) return;\n\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n\n if (!isHas) return 'fallback';\n\n return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n }\n\n get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {\n return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n }\n\n set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {\n if (!super.has(k)) super.set(k, v);\n\n return this;\n }\n\n extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {\n const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;\n\n const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);\n\n return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({\n ...obj,\n ...extendObj,\n } as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);\n }\n}\n","import { createContext } from 'use-context-selector';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","import { useReducer, useRef } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\n\nexport const useInputMapping = () => {\n const initialState = useContext(InputMappingContext);\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n mapRef.current.set = (...args) => {\n InputMapping.prototype.set.apply(mapRef.current, args);\n reRender();\n return mapRef.current;\n };\n\n mapRef.current.clear = (...args) => {\n InputMapping.prototype.clear.apply(mapRef.current, args);\n reRender();\n };\n\n mapRef.current.delete = (...args) => {\n const res = InputMapping.prototype.delete.apply(mapRef.current, args);\n reRender();\n\n return res;\n };\n\n return mapRef.current;\n};\n","import { createElement, useId } from 'react';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\nimport { INPUT_COMPONENTS_KEYS, ParsedField } from './types';\nimport { useInputMapping } from './useInputMapping';\n\ninterface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {\n useInputMapping: () => InputMapping<P, K>;\n FormInstantInputsProvider: FCC;\n}\n\nexport const createFormInstantContainer = <P = object, K extends string = INPUT_COMPONENTS_KEYS>(\n inputMapping: InputMapping<P, K>,\n) => {\n const FormInstantInputsProvider: FCC = (props) =>\n createElement(InputMappingContext.Provider, {\n value: inputMapping as InputMapping,\n children: props.children,\n });\n\n return {\n FormInstantInputsProvider,\n useInputMapping,\n } as createFormInstantContainerRetuen<P, K>;\n};\n\nexport const ElementMapping: FC<ParsedField<null, string>> = (props) => {\n const InputMapping = useInputMapping();\n\n const Element = InputMapping.get(props.type);\n const key = useId();\n\n const { ...prop } = props;\n\n if (!Element) return null;\n\n return createElement(Element, { ...prop, key });\n};\n"],"names":["InputMapping","_Map","obj","_this","call","_assertThisInitialized","appendObj","_inheritsLoose","_proto","prototype","zodAdacter","Object","entries","ZodBoolean","ZodDate","ZodEnum","ZodNativeEnum","ZodNumber","string","keys","_i","_keys","length","key","set","_iterator","_createForOfIteratorHelperLoose","_step","done","_step$value","value","k","v","get","exists","isHas","has","extends","cb","fromEntries","extendObj","_extends2","_wrapNativeSuper","Map","InputMappingContext","createContext","useInputMapping","initialState","useContext","mapRef","useRef","_useReducer","useReducer","x","reRender","current","_len","arguments","args","Array","_key","apply","clear","_len2","_key2","_len3","_key3","res","createFormInstantContainer","inputMapping","FormInstantInputsProvider","props","createElement","Provider","children","ElementMapping","Element","type","useId","prop","_extends","_objectDestructuringEmpty"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;AACaA,IAAAA,YAAmE,0BAAAC,IAAA,EAAA;EAyB5E,SAAAD,YAAAA,CAAYE,GAAuD,EAAA;AAAA,IAAA,IAAAC,KAAA,CAAA;AAC/DA,IAAAA,KAAA,GAAAF,IAAA,CAAAG,IAAA,MAAO,IAAA,IAAA,CAAA;AAEP,IAAA,IAAI,CAACF,GAAG,EAAE,OAAAG,sBAAA,CAAAF,KAAA,CAAA,CAAA;AAEVA,IAAAA,KAAA,CAAKG,SAAS,CAACJ,GAAG,CAAC,CAAA;AAAC,IAAA,OAAAC,KAAA,CAAA;AACxB,GAAA;EAACI,cAAA,CAAAP,YAAA,EAAAC,IAAA,CAAA,CAAA;AAAA,EAAA,IAAAO,MAAA,GAAAR,YAAA,CAAAS,S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eAAe,EAAfA,eAAAA;GACuC,CAAA;AAC/C,EAAC;IAEY6B,cAAc,GAAkC,SAAhDA,cAAcA,CAAmCJ,KAAK,EAAI;AACnE,EAAA,IAAMvE,YAAY,GAAG8C,eAAe,EAAE,CAAA;EAEtC,IAAM8B,OAAO,GAAG5E,YAAY,CAACiC,GAAG,CAACsC,KAAK,CAACM,IAAI,CAAC,CAAA;AAC5C,EAAA,IAAMtD,GAAG,GAAGuD,WAAK,EAAE,CAAA;EAEnB,IAAWC,IAAI,GAAAC,QAAA,CAAA,EAAA,GAAAC,yBAAA,CAAKV,KAAK,GAALA,KAAK,EAAA,CAAA;AAEzB,EAAA,IAAI,CAACK,OAAO,EAAE,OAAO,IAAI,CAAA;AAEzB,EAAA,OAAOJ,mBAAa,CAACI,OAAO,EAAAI,QAAA,KAAOD,IAAI,EAAA;AAAExD,IAAAA,GAAG,EAAHA,GAAAA;AAAG,GAAA,CAAE,CAAC,CAAA;AACnD;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"react-input-mapping.cjs.development.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/useInputMapping.tsx","../src/InputMapping/provider.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS } from './types';\n\ntype MergeKeys<T, U> = {\n [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;\n};\n\n// K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas\nexport class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<\n MergeKeys<K, INPUT_COMPONENTS_KEYS>,\n FC<P>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;\n\n type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n\n for (const key of keys) this.set(key as Ky, obj[key]!);\n\n for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);\n }\n\n constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n super();\n\n if (!obj) return;\n\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n\n if (!isHas) return 'fallback';\n\n return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n }\n\n get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {\n return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n }\n\n set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {\n if (!super.has(k)) super.set(k, v);\n\n return this;\n }\n\n extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {\n const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;\n\n const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);\n\n return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({\n ...obj,\n ...extendObj,\n } as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);\n }\n}\n","import { createContext } from 'use-context-selector';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","import { useReducer, useRef } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\n\nexport const useInputMapping = () => {\n const initialState = useContext(InputMappingContext);\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n mapRef.current.set = (...args) => {\n InputMapping.prototype.set.apply(mapRef.current, args);\n reRender();\n return mapRef.current;\n };\n\n mapRef.current.clear = (...args) => {\n InputMapping.prototype.clear.apply(mapRef.current, args);\n reRender();\n };\n\n mapRef.current.delete = (...args) => {\n const res = InputMapping.prototype.delete.apply(mapRef.current, args);\n reRender();\n\n return res;\n };\n\n return mapRef.current;\n};\n","import { createElement } from 'react';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\nimport { INPUT_COMPONENTS_KEYS, ParsedField } from './types';\nimport { useInputMapping } from './useInputMapping';\n\ninterface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {\n useInputMapping: () => InputMapping<P, K>;\n FormInstantInputsProvider: FCC;\n}\n\nexport const createFormInstantContainer = <P = object, K extends string = INPUT_COMPONENTS_KEYS>(\n inputMapping: InputMapping<P, K>,\n) => {\n const FormInstantInputsProvider: FCC = (props) =>\n createElement(InputMappingContext.Provider, {\n value: inputMapping as InputMapping,\n children: props.children,\n });\n\n return {\n FormInstantInputsProvider,\n useInputMapping,\n } as createFormInstantContainerRetuen<P, K>;\n};\n\nexport const ElementMapping: FC<ParsedField<null, string>> = (props) => {\n const InputMapping = useInputMapping();\n\n const Element = InputMapping.get(props.type);\n\n if (!Element) return null;\n\n return createElement(Element, props);\n};\n"],"names":["InputMapping","_Map","obj","_this","call","_assertThisInitialized","appendObj","_inheritsLoose","_proto","prototype","zodAdacter","Object","entries","ZodBoolean","ZodDate","ZodEnum","ZodNativeEnum","ZodNumber","string","keys","_i","_keys","length","key","set","_iterator","_createForOfIteratorHelperLoose","_step","done","_step$value","value","k","v","get","exists","isHas","has","extends","cb","fromEntries","extendObj","_extends2","_wrapNativeSuper","Map","InputMappingContext","createContext","useInputMapping","initialState","useContext","mapRef","useRef","_useReducer","useReducer","x","reRender","current","_len","arguments","args","Array","_key","apply","clear","_len2","_key2","_len3","_key3","res","createFormInstantContainer","inputMapping","FormInstantInputsProvider","props","createElement","Provider","children","ElementMapping","Element","type"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AACrEJ,IAAAA,QAAQ,EAAE,CAAA;AAEV,IAAA,OAAOa,GAAG,CAAA;GACb,CAAA;EAED,OAAOlB,MAAM,CAACM,OAAO,CAAA;AACzB;;IClBaa,0BAA0B,GAAG,SAA7BA,0BAA0BA,CACnCC,YAAgC,EAChC;AACA,EAAA,IAAMC,yBAAyB,GAAQ,SAAjCA,yBAAyBA,CAASC,KAAK,EAAA;AAAA,IAAA,OACzCC,mBAAa,CAAC5B,mBAAmB,CAAC6B,QAAQ,EAAE;AACxC3C,MAAAA,KAAK,EAAEuC,YAA4B;MACnCK,QAAQ,EAAEH,KAAK,CAACG,QAAAA;AACnB,KAAA,CAAC,CAAA;AAAA,GAAA,CAAA;EAEN,OAAO;AACHJ,IAAAA,yBAAyB,EAAzBA,yBAAyB;AACzBxB,IAAAA,eAAe,EAAfA,eAAAA;GACuC,CAAA;AAC/C,EAAC;IAEY6B,cAAc,GAAkC,SAAhDA,cAAcA,CAAmCJ,KAAK,EAAI;AACnE,EAAA,IAAMvE,YAAY,GAAG8C,eAAe,EAAE,CAAA;EAEtC,IAAM8B,OAAO,GAAG5E,YAAY,CAACiC,GAAG,CAACsC,KAAK,CAACM,IAAI,CAAC,CAAA;AAE5C,EAAA,IAAI,CAACD,OAAO,EAAE,OAAO,IAAI,CAAA;AAEzB,EAAA,OAAOJ,mBAAa,CAACI,OAAO,EAAEL,KAAK,CAAC,CAAA;AACxC;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("use-context-selector"),e=require("react");function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},n.apply(null,arguments)}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(u())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&a(o,r.prototype),o}(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),a(r,t)},c(t)}var i=function(t){function e(e){var r;return r=t.call(this)||this,e?(r.appendObj(e),r):function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(r)}var o,u;u=t,(o=e).prototype=Object.create(u.prototype),o.prototype.constructor=o,a(o,u);var c=e.prototype;return c.zodAdacter=function(){return Object.entries({ZodBoolean:"checkbox",ZodDate:"date",ZodEnum:"select",ZodNativeEnum:"select",ZodNumber:"number",string:"text"})},c.appendObj=function(t){for(var e=0,n=Object.keys(t);e<n.length;e++){var o=n[e];this.set(o,t[o])}for(var u,a=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t))){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.zodAdacter());!(u=a()).done;){var c=u.value;this.set(c[0],this.get(c[1]))}},c.exists=function(e){return t.prototype.has.call(this,e)?e:"fallback"},c.get=function(e){return t.prototype.get.call(this,e)},c.set=function(e,r){return t.prototype.has.call(this,e)||t.prototype.set.call(this,e,r),this},c.extends=function(r){return new e(n({},Object.fromEntries(t.prototype.entries.call(this)),r(this)))},e}(c(Map)),p=t.createContext(new i),l=function(){var r=t.useContext(p),n=e.useRef(r),o=e.useReducer((function(t){return t+1}),0)[1];return n.current.set=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return i.prototype.set.apply(n.current,e),o(),n.current},n.current.clear=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];i.prototype.clear.apply(n.current,e),o()},n.current.delete=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var u=i.prototype.delete.apply(n.current,e);return o(),u},n.current};exports.ElementMapping=function(t){var r=l().get(t.type)
|
|
1
|
+
"use strict";var t=require("use-context-selector"),e=require("react");function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},n.apply(null,arguments)}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(u())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&a(o,r.prototype),o}(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),a(r,t)},c(t)}var i=function(t){function e(e){var r;return r=t.call(this)||this,e?(r.appendObj(e),r):function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(r)}var o,u;u=t,(o=e).prototype=Object.create(u.prototype),o.prototype.constructor=o,a(o,u);var c=e.prototype;return c.zodAdacter=function(){return Object.entries({ZodBoolean:"checkbox",ZodDate:"date",ZodEnum:"select",ZodNativeEnum:"select",ZodNumber:"number",string:"text"})},c.appendObj=function(t){for(var e=0,n=Object.keys(t);e<n.length;e++){var o=n[e];this.set(o,t[o])}for(var u,a=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t))){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.zodAdacter());!(u=a()).done;){var c=u.value;this.set(c[0],this.get(c[1]))}},c.exists=function(e){return t.prototype.has.call(this,e)?e:"fallback"},c.get=function(e){return t.prototype.get.call(this,e)},c.set=function(e,r){return t.prototype.has.call(this,e)||t.prototype.set.call(this,e,r),this},c.extends=function(r){return new e(n({},Object.fromEntries(t.prototype.entries.call(this)),r(this)))},e}(c(Map)),p=t.createContext(new i),l=function(){var r=t.useContext(p),n=e.useRef(r),o=e.useReducer((function(t){return t+1}),0)[1];return n.current.set=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return i.prototype.set.apply(n.current,e),o(),n.current},n.current.clear=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];i.prototype.clear.apply(n.current,e),o()},n.current.delete=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var u=i.prototype.delete.apply(n.current,e);return o(),u},n.current};exports.ElementMapping=function(t){var r=l().get(t.type);return r?e.createElement(r,t):null},exports.InputMapping=i,exports.InputMappingContext=p,exports.createFormInstantContainer=function(t){return{FormInstantInputsProvider:function(r){return e.createElement(p.Provider,{value:t,children:r.children})},useInputMapping:l}},exports.useInputMapping=l;
|
|
2
2
|
//# sourceMappingURL=react-input-mapping.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-input-mapping.cjs.production.min.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/useInputMapping.tsx","../src/InputMapping/provider.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS } from './types';\n\ntype MergeKeys<T, U> = {\n [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;\n};\n\n// K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas\nexport class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<\n MergeKeys<K, INPUT_COMPONENTS_KEYS>,\n FC<P>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;\n\n type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n\n for (const key of keys) this.set(key as Ky, obj[key]!);\n\n for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);\n }\n\n constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n super();\n\n if (!obj) return;\n\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n\n if (!isHas) return 'fallback';\n\n return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n }\n\n get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {\n return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n }\n\n set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {\n if (!super.has(k)) super.set(k, v);\n\n return this;\n }\n\n extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {\n const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;\n\n const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);\n\n return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({\n ...obj,\n ...extendObj,\n } as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);\n }\n}\n","import { createContext } from 'use-context-selector';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","import { useReducer, useRef } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\n\nexport const useInputMapping = () => {\n const initialState = useContext(InputMappingContext);\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n mapRef.current.set = (...args) => {\n InputMapping.prototype.set.apply(mapRef.current, args);\n reRender();\n return mapRef.current;\n };\n\n mapRef.current.clear = (...args) => {\n InputMapping.prototype.clear.apply(mapRef.current, args);\n reRender();\n };\n\n mapRef.current.delete = (...args) => {\n const res = InputMapping.prototype.delete.apply(mapRef.current, args);\n reRender();\n\n return res;\n };\n\n return mapRef.current;\n};\n","import { createElement
|
|
1
|
+
{"version":3,"file":"react-input-mapping.cjs.production.min.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/useInputMapping.tsx","../src/InputMapping/provider.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS } from './types';\n\ntype MergeKeys<T, U> = {\n [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;\n};\n\n// K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas\nexport class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<\n MergeKeys<K, INPUT_COMPONENTS_KEYS>,\n FC<P>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;\n\n type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n\n for (const key of keys) this.set(key as Ky, obj[key]!);\n\n for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);\n }\n\n constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n super();\n\n if (!obj) return;\n\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n\n if (!isHas) return 'fallback';\n\n return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n }\n\n get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {\n return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n }\n\n set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {\n if (!super.has(k)) super.set(k, v);\n\n return this;\n }\n\n extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {\n const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;\n\n const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);\n\n return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({\n ...obj,\n ...extendObj,\n } as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);\n }\n}\n","import { createContext } from 'use-context-selector';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","import { useReducer, useRef } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\n\nexport const useInputMapping = () => {\n const initialState = useContext(InputMappingContext);\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n mapRef.current.set = (...args) => {\n InputMapping.prototype.set.apply(mapRef.current, args);\n reRender();\n return mapRef.current;\n };\n\n mapRef.current.clear = (...args) => {\n InputMapping.prototype.clear.apply(mapRef.current, args);\n reRender();\n };\n\n mapRef.current.delete = (...args) => {\n const res = InputMapping.prototype.delete.apply(mapRef.current, args);\n reRender();\n\n return res;\n };\n\n return mapRef.current;\n};\n","import { createElement } from 'react';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\nimport { INPUT_COMPONENTS_KEYS, ParsedField } from './types';\nimport { useInputMapping } from './useInputMapping';\n\ninterface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {\n useInputMapping: () => InputMapping<P, K>;\n FormInstantInputsProvider: FCC;\n}\n\nexport const createFormInstantContainer = <P = object, K extends string = INPUT_COMPONENTS_KEYS>(\n inputMapping: InputMapping<P, K>,\n) => {\n const FormInstantInputsProvider: FCC = (props) =>\n createElement(InputMappingContext.Provider, {\n value: inputMapping as InputMapping,\n children: props.children,\n });\n\n return {\n FormInstantInputsProvider,\n useInputMapping,\n } as createFormInstantContainerRetuen<P, K>;\n};\n\nexport const ElementMapping: FC<ParsedField<null, string>> = (props) => {\n const InputMapping = useInputMapping();\n\n const Element = InputMapping.get(props.type);\n\n if (!Element) return null;\n\n return createElement(Element, props);\n};\n"],"names":["InputMapping","_Map","obj","_this","call","this","appendObj","_assertThisInitialized","_proto","prototype","zodAdacter","Object","entries","ZodBoolean","ZodDate","ZodEnum","ZodNativeEnum","ZodNumber","string","_i","_keys","keys","length","key","set","_step","_iterator","_createForOfIteratorHelperLoose","done","_step$value","value","get","exists","k","has","v","cb","_extends2","fromEntries","_wrapNativeSuper","Map","InputMappingContext","createContext","useInputMapping","initialState","useContext","mapRef","useRef","reRender","useReducer","x","current","_len","arguments","args","Array","_key","apply","clear","_len2","_key2","_len3","_key3","res","props","Element","type","createElement","inputMapping","FormInstantInputsProvider","Provider","children"],"mappings":"89CAQaA,IAAAA,WAAmEC,GAyB5E,SAAAD,EAAYE,GAAuD,IAAAC,EAG/D,OAFAA,EAAAF,EAAAG,YAAOC,KAEFH,GAELC,EAAKG,UAAUJ,GAAKC,4HAFVI,CAAAJ,EAGd,WAACF,KAAAD,yEAAA,IAAAQ,EAAAR,EAAAS,UA6BA,OA7BAD,EA3BOE,WAAA,WACJ,OAAOC,OAAOC,QAAQ,CAClBC,WAAY,WACZC,QAAS,OACTC,QAAS,SACTC,cAAe,SACfC,UAAW,SACXC,OAAQ,UAEfV,EAEOF,UAAA,SAAUJ,GAKd,IAJA,IAIAiB,EAAA,EAAAC,EAJaT,OAAOU,KAAKnB,GAIHiB,EAAAC,EAAAE,OAAAH,IAAA,CAAjB,IAAMI,EAAGH,EAAAD,GAAUd,KAAKmB,IAAID,EAA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,EAAAD,EAAAC,IAAJN,EAAIM,GAAAP,UAAAO,GAC3B5D,EAAaS,UAAUiD,MAAMD,MAAMX,EAAOK,QAASG,GACnDN,KAGJF,EAAOK,QAAc,OAAG,WAAY,IAAA,IAAAU,EAAAR,UAAA/B,OAARgC,EAAIC,IAAAA,MAAAM,GAAAC,EAAA,EAAAA,EAAAD,EAAAC,IAAJR,EAAIQ,GAAAT,UAAAS,GAC5B,IAAMC,EAAM/D,EAAaS,UAAgB,OAACgD,MAAMX,EAAOK,QAASG,GAGhE,OAFAN,IAEOe,GAGJjB,EAAOK,OAClB,yBCH6D,SAACa,GAC1D,IAEMC,EAFetB,IAEQZ,IAAIiC,EAAME,MAEvC,OAAKD,EAEEE,EAAaA,cAACF,EAASD,GAFT,IAGzB,0FAvB0C,SACtCI,GAQA,MAAO,CACHC,0BAPmC,SAACL,GAAK,OACzCG,EAAaA,cAAC1B,EAAoB6B,SAAU,CACxCxC,MAAOsC,EACPG,SAAUP,EAAMO,UAClB,EAIF5B,gBAAAA,EAER"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext } from 'use-context-selector';
|
|
2
|
-
import { useRef, useReducer,
|
|
2
|
+
import { useRef, useReducer, createElement } from 'react';
|
|
3
3
|
|
|
4
4
|
function _arrayLikeToArray(r, a) {
|
|
5
5
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -66,9 +66,6 @@ function _isNativeReflectConstruct() {
|
|
|
66
66
|
return !!t;
|
|
67
67
|
})();
|
|
68
68
|
}
|
|
69
|
-
function _objectDestructuringEmpty(t) {
|
|
70
|
-
if (null == t) throw new TypeError("Cannot destructure " + t);
|
|
71
|
-
}
|
|
72
69
|
function _setPrototypeOf(t, e) {
|
|
73
70
|
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
74
71
|
return t.__proto__ = e, t;
|
|
@@ -208,12 +205,8 @@ var createFormInstantContainer = function createFormInstantContainer(inputMappin
|
|
|
208
205
|
var ElementMapping = function ElementMapping(props) {
|
|
209
206
|
var InputMapping = useInputMapping();
|
|
210
207
|
var Element = InputMapping.get(props.type);
|
|
211
|
-
var key = useId();
|
|
212
|
-
var prop = _extends({}, (_objectDestructuringEmpty(props), props));
|
|
213
208
|
if (!Element) return null;
|
|
214
|
-
return createElement(Element,
|
|
215
|
-
key: key
|
|
216
|
-
}));
|
|
209
|
+
return createElement(Element, props);
|
|
217
210
|
};
|
|
218
211
|
|
|
219
212
|
export { ElementMapping, InputMapping, InputMappingContext, createFormInstantContainer, useInputMapping };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-input-mapping.esm.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/useInputMapping.tsx","../src/InputMapping/provider.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS } from './types';\n\ntype MergeKeys<T, U> = {\n [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;\n};\n\n// K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas\nexport class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<\n MergeKeys<K, INPUT_COMPONENTS_KEYS>,\n FC<P>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;\n\n type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n\n for (const key of keys) this.set(key as Ky, obj[key]!);\n\n for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);\n }\n\n constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n super();\n\n if (!obj) return;\n\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n\n if (!isHas) return 'fallback';\n\n return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n }\n\n get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {\n return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n }\n\n set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {\n if (!super.has(k)) super.set(k, v);\n\n return this;\n }\n\n extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {\n const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;\n\n const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);\n\n return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({\n ...obj,\n ...extendObj,\n } as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);\n }\n}\n","import { createContext } from 'use-context-selector';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","import { useReducer, useRef } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\n\nexport const useInputMapping = () => {\n const initialState = useContext(InputMappingContext);\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n mapRef.current.set = (...args) => {\n InputMapping.prototype.set.apply(mapRef.current, args);\n reRender();\n return mapRef.current;\n };\n\n mapRef.current.clear = (...args) => {\n InputMapping.prototype.clear.apply(mapRef.current, args);\n reRender();\n };\n\n mapRef.current.delete = (...args) => {\n const res = InputMapping.prototype.delete.apply(mapRef.current, args);\n reRender();\n\n return res;\n };\n\n return mapRef.current;\n};\n","import { createElement, useId } from 'react';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\nimport { INPUT_COMPONENTS_KEYS, ParsedField } from './types';\nimport { useInputMapping } from './useInputMapping';\n\ninterface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {\n useInputMapping: () => InputMapping<P, K>;\n FormInstantInputsProvider: FCC;\n}\n\nexport const createFormInstantContainer = <P = object, K extends string = INPUT_COMPONENTS_KEYS>(\n inputMapping: InputMapping<P, K>,\n) => {\n const FormInstantInputsProvider: FCC = (props) =>\n createElement(InputMappingContext.Provider, {\n value: inputMapping as InputMapping,\n children: props.children,\n });\n\n return {\n FormInstantInputsProvider,\n useInputMapping,\n } as createFormInstantContainerRetuen<P, K>;\n};\n\nexport const ElementMapping: FC<ParsedField<null, string>> = (props) => {\n const InputMapping = useInputMapping();\n\n const Element = InputMapping.get(props.type);\n const key = useId();\n\n const { ...prop } = props;\n\n if (!Element) return null;\n\n return createElement(Element, { ...prop, key });\n};\n"],"names":["InputMapping","_Map","obj","_this","call","_assertThisInitialized","appendObj","_inheritsLoose","_proto","prototype","zodAdacter","Object","entries","ZodBoolean","ZodDate","ZodEnum","ZodNativeEnum","ZodNumber","string","keys","_i","_keys","length","key","set","_iterator","_createForOfIteratorHelperLoose","_step","done","_step$value","value","k","v","get","exists","isHas","has","extends","cb","fromEntries","extendObj","_extends2","_wrapNativeSuper","Map","InputMappingContext","createContext","useInputMapping","initialState","useContext","mapRef","useRef","_useReducer","useReducer","x","reRender","current","_len","arguments","args","Array","_key","apply","clear","_len2","_key2","_len3","_key3","res","createFormInstantContainer","inputMapping","FormInstantInputsProvider","props","createElement","Provider","children","ElementMapping","Element","type","useId","prop","_extends","_objectDestructuringEmpty"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;AACaA,IAAAA,YAAmE,0BAAAC,IAAA,EAAA;EAyB5E,SAAAD,YAAAA,CAAYE,GAAuD,EAAA;AAAA,IAAA,IAAAC,KAAA,CAAA;AAC/DA,IA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AgC,EAChC;AACA,EAAA,IAAMC,yBAAyB,GAAQ,SAAjCA,yBAAyBA,CAASC,KAAK,EAAA;AAAA,IAAA,OACzCC,aAAa,CAAC5B,mBAAmB,CAAC6B,QAAQ,EAAE;AACxC3C,MAAAA,KAAK,EAAEuC,YAA4B;MACnCK,QAAQ,EAAEH,KAAK,CAACG,QAAAA;AACnB,KAAA,CAAC,CAAA;AAAA,GAAA,CAAA;EAEN,OAAO;AACHJ,IAAAA,yBAAyB,EAAzBA,yBAAyB;AACzBxB,IAAAA,eAAe,EAAfA,eAAAA;GACuC,CAAA;AAC/C,EAAC;IAEY6B,cAAc,GAAkC,SAAhDA,cAAcA,CAAmCJ,KAAK,EAAI;AACnE,EAAA,IAAMvE,YAAY,GAAG8C,eAAe,EAAE,CAAA;EAEtC,IAAM8B,OAAO,GAAG5E,YAAY,CAACiC,GAAG,CAACsC,KAAK,CAACM,IAAI,CAAC,CAAA;AAC5C,EAAA,IAAMtD,GAAG,GAAGuD,KAAK,EAAE,CAAA;EAEnB,IAAWC,IAAI,GAAAC,QAAA,CAAA,EAAA,GAAAC,yBAAA,CAAKV,KAAK,GAALA,KAAK,EAAA,CAAA;AAEzB,EAAA,IAAI,CAACK,OAAO,EAAE,OAAO,IAAI,CAAA;AAEzB,EAAA,OAAOJ,aAAa,CAACI,OAAO,EAAAI,QAAA,KAAOD,IAAI,EAAA;AAAExD,IAAAA,GAAG,EAAHA,GAAAA;AAAG,GAAA,CAAE,CAAC,CAAA;AACnD;;;;"}
|
|
1
|
+
{"version":3,"file":"react-input-mapping.esm.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/useInputMapping.tsx","../src/InputMapping/provider.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS } from './types';\n\ntype MergeKeys<T, U> = {\n [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;\n};\n\n// K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas\nexport class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<\n MergeKeys<K, INPUT_COMPONENTS_KEYS>,\n FC<P>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;\n\n type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n\n for (const key of keys) this.set(key as Ky, obj[key]!);\n\n for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);\n }\n\n constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {\n super();\n\n if (!obj) return;\n\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n\n if (!isHas) return 'fallback';\n\n return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;\n }\n\n get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {\n return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);\n }\n\n set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {\n if (!super.has(k)) super.set(k, v);\n\n return this;\n }\n\n extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {\n const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;\n\n const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);\n\n return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({\n ...obj,\n ...extendObj,\n } as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);\n }\n}\n","import { createContext } from 'use-context-selector';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","import { useReducer, useRef } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\n\nexport const useInputMapping = () => {\n const initialState = useContext(InputMappingContext);\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n mapRef.current.set = (...args) => {\n InputMapping.prototype.set.apply(mapRef.current, args);\n reRender();\n return mapRef.current;\n };\n\n mapRef.current.clear = (...args) => {\n InputMapping.prototype.clear.apply(mapRef.current, args);\n reRender();\n };\n\n mapRef.current.delete = (...args) => {\n const res = InputMapping.prototype.delete.apply(mapRef.current, args);\n reRender();\n\n return res;\n };\n\n return mapRef.current;\n};\n","import { createElement } from 'react';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\nimport { INPUT_COMPONENTS_KEYS, ParsedField } from './types';\nimport { useInputMapping } from './useInputMapping';\n\ninterface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {\n useInputMapping: () => InputMapping<P, K>;\n FormInstantInputsProvider: FCC;\n}\n\nexport const createFormInstantContainer = <P = object, K extends string = INPUT_COMPONENTS_KEYS>(\n inputMapping: InputMapping<P, K>,\n) => {\n const FormInstantInputsProvider: FCC = (props) =>\n createElement(InputMappingContext.Provider, {\n value: inputMapping as InputMapping,\n children: props.children,\n });\n\n return {\n FormInstantInputsProvider,\n useInputMapping,\n } as createFormInstantContainerRetuen<P, K>;\n};\n\nexport const ElementMapping: FC<ParsedField<null, string>> = (props) => {\n const InputMapping = useInputMapping();\n\n const Element = InputMapping.get(props.type);\n\n if (!Element) return null;\n\n return createElement(Element, props);\n};\n"],"names":["InputMapping","_Map","obj","_this","call","_assertThisInitialized","appendObj","_inheritsLoose","_proto","prototype","zodAdacter","Object","entries","ZodBoolean","ZodDate","ZodEnum","ZodNativeEnum","ZodNumber","string","keys","_i","_keys","length","key","set","_iterator","_createForOfIteratorHelperLoose","_step","done","_step$value","value","k","v","get","exists","isHas","has","extends","cb","fromEntries","extendObj","_extends2","_wrapNativeSuper","Map","InputMappingContext","createContext","useInputMapping","initialState","useContext","mapRef","useRef","_useReducer","useReducer","x","reRender","current","_len","arguments","args","Array","_key","apply","clear","_len2","_key2","_len3","_key3","res","createFormInstantContainer","inputMapping","FormInstantInputsProvider","props","createElement","Provider","children","ElementMapping","Element","type"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;AACaA,IAAAA,YAAmE,0BAAAC,IAAA,EAAA;EAyB5E,SAAAD,YAAAA,CAAYE,GAAuD,EAAA;AAAA,IAAA,IAAAC,KAAA,CAAA;AAC/DA,IAAAA,KAAA,GAAAF,IAAA,CAAAG,IAAA,MAAO,IAAA,IAAA,CAAA;AAEP,IAAA,IAAI,CAACF,GAAG,EAAE,OAAAG,sBAAA,CAAAF,KAAA,CAAA,CAAA;AAEVA,IAAAA,KAAA,CAAKG,SAAS,CAACJ,GAAG,CAAC,CAAA;AAAC,IAAA,OAAAC,KAAA,CAAA;AACxB,GAAA;EAACI,cAAA,CAAAP,YAAA,EAAAC,IAAA,CAAA,CAAA;AAAA,EAAA,IAAAO,MAAA,GAAAR,YAAA,CAAAS,SAAA,CAAA;AAAAD,EAAAA,MAAA,CA3BOE,UAAU,GAAV,SAAAA,UAAUA,GAAA;IACd,OAAOC,MAAM,CAACC,OAAO,CAAC;AAClBC,MAAAA,UAAU,EAAE,UAAU;AACtBC,MAAAA,OAAO,EAAE,MAAM;AACfC,MAAAA,OAAO,EAAE,QAAQ;AACjBC,MAAAA,aAAa,EAAE,QAAQ;AACvBC,MAAAA,SAAS,EAAE,QAAQ;AACnBC,MAAAA,MAAM,EAAE,MAAA;AACX,KAAA,CAAC,CAAA;GACL,CAAA;AAAAV,EAAAA,MAAA,CAEOF,SAAS,GAAT,SAAAA,SAASA,CAACJ,GAAsD,E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@@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@form-instant/react-input-mapping",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "leomerida15",
|
|
@@ -11,13 +11,8 @@
|
|
|
11
11
|
"module": "dist/react-input-mapping.esm.js",
|
|
12
12
|
"typings": "dist/index.d.ts",
|
|
13
13
|
"files": [
|
|
14
|
-
"dist"
|
|
15
|
-
"src"
|
|
14
|
+
"dist"
|
|
16
15
|
],
|
|
17
|
-
"private": false,
|
|
18
|
-
"exports": {
|
|
19
|
-
".": "./src/index.ts"
|
|
20
|
-
},
|
|
21
16
|
"scripts": {
|
|
22
17
|
"analyze": "size-limit --why",
|
|
23
18
|
"build": "dts build",
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import { INPUT_COMPONENTS_KEYS } from './types';
|
|
3
|
-
|
|
4
|
-
type MergeKeys<T, U> = {
|
|
5
|
-
[K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas
|
|
9
|
-
export class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<
|
|
10
|
-
MergeKeys<K, INPUT_COMPONENTS_KEYS>,
|
|
11
|
-
FC<P>
|
|
12
|
-
> {
|
|
13
|
-
private zodAdacter() {
|
|
14
|
-
return Object.entries({
|
|
15
|
-
ZodBoolean: 'checkbox',
|
|
16
|
-
ZodDate: 'date',
|
|
17
|
-
ZodEnum: 'select',
|
|
18
|
-
ZodNativeEnum: 'select',
|
|
19
|
-
ZodNumber: 'number',
|
|
20
|
-
string: 'text',
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {
|
|
25
|
-
const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;
|
|
26
|
-
|
|
27
|
-
type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;
|
|
28
|
-
|
|
29
|
-
for (const key of keys) this.set(key as Ky, obj[key]!);
|
|
30
|
-
|
|
31
|
-
for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {
|
|
35
|
-
super();
|
|
36
|
-
|
|
37
|
-
if (!obj) return;
|
|
38
|
-
|
|
39
|
-
this.appendObj(obj);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
exists(k: string) {
|
|
43
|
-
const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);
|
|
44
|
-
|
|
45
|
-
if (!isHas) return 'fallback';
|
|
46
|
-
|
|
47
|
-
return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {
|
|
51
|
-
return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {
|
|
55
|
-
if (!super.has(k)) super.set(k, v);
|
|
56
|
-
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {
|
|
61
|
-
const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;
|
|
62
|
-
|
|
63
|
-
const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);
|
|
64
|
-
|
|
65
|
-
return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({
|
|
66
|
-
...obj,
|
|
67
|
-
...extendObj,
|
|
68
|
-
} as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createElement, useId } from 'react';
|
|
2
|
-
import { InputMapping } from './class';
|
|
3
|
-
import { InputMappingContext } from './context';
|
|
4
|
-
import { INPUT_COMPONENTS_KEYS, ParsedField } from './types';
|
|
5
|
-
import { useInputMapping } from './useInputMapping';
|
|
6
|
-
|
|
7
|
-
interface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {
|
|
8
|
-
useInputMapping: () => InputMapping<P, K>;
|
|
9
|
-
FormInstantInputsProvider: FCC;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const createFormInstantContainer = <P = object, K extends string = INPUT_COMPONENTS_KEYS>(
|
|
13
|
-
inputMapping: InputMapping<P, K>,
|
|
14
|
-
) => {
|
|
15
|
-
const FormInstantInputsProvider: FCC = (props) =>
|
|
16
|
-
createElement(InputMappingContext.Provider, {
|
|
17
|
-
value: inputMapping as InputMapping,
|
|
18
|
-
children: props.children,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
FormInstantInputsProvider,
|
|
23
|
-
useInputMapping,
|
|
24
|
-
} as createFormInstantContainerRetuen<P, K>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const ElementMapping: FC<ParsedField<null, string>> = (props) => {
|
|
28
|
-
const InputMapping = useInputMapping();
|
|
29
|
-
|
|
30
|
-
const Element = InputMapping.get(props.type);
|
|
31
|
-
const key = useId();
|
|
32
|
-
|
|
33
|
-
const { ...prop } = props;
|
|
34
|
-
|
|
35
|
-
if (!Element) return null;
|
|
36
|
-
|
|
37
|
-
return createElement(Element, { ...prop, key });
|
|
38
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type INPUT_COMPONENTS_KEYS =
|
|
2
|
-
| 'checkbox'
|
|
3
|
-
| 'date'
|
|
4
|
-
| 'select'
|
|
5
|
-
| 'radio'
|
|
6
|
-
| 'switch'
|
|
7
|
-
| 'textarea'
|
|
8
|
-
| 'number'
|
|
9
|
-
| 'file'
|
|
10
|
-
| 'text'
|
|
11
|
-
| 'fallback';
|
|
12
|
-
|
|
13
|
-
export interface ParsedField<AdditionalRenderable, FieldTypes = string> {
|
|
14
|
-
key: string;
|
|
15
|
-
type: string;
|
|
16
|
-
required: boolean;
|
|
17
|
-
default?: any;
|
|
18
|
-
fieldConfig?: FieldConfig<AdditionalRenderable, FieldTypes>;
|
|
19
|
-
|
|
20
|
-
// Field-specific
|
|
21
|
-
options?: [string, string][]; // [value, label] for enums
|
|
22
|
-
schema?: ParsedField<AdditionalRenderable, FieldTypes>[]; // For objects and arrays
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type FieldConfig<AdditionalRenderable = object, FieldTypes = string> = {
|
|
26
|
-
fieldType?: FieldTypes;
|
|
27
|
-
} & AdditionalRenderable;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useReducer, useRef } from 'react';
|
|
2
|
-
import { useContext } from 'use-context-selector';
|
|
3
|
-
import { InputMapping } from './class';
|
|
4
|
-
import { InputMappingContext } from './context';
|
|
5
|
-
|
|
6
|
-
export const useInputMapping = () => {
|
|
7
|
-
const initialState = useContext(InputMappingContext);
|
|
8
|
-
const mapRef = useRef(initialState);
|
|
9
|
-
const [, reRender] = useReducer((x) => x + 1, 0);
|
|
10
|
-
|
|
11
|
-
mapRef.current.set = (...args) => {
|
|
12
|
-
InputMapping.prototype.set.apply(mapRef.current, args);
|
|
13
|
-
reRender();
|
|
14
|
-
return mapRef.current;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
mapRef.current.clear = (...args) => {
|
|
18
|
-
InputMapping.prototype.clear.apply(mapRef.current, args);
|
|
19
|
-
reRender();
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
mapRef.current.delete = (...args) => {
|
|
23
|
-
const res = InputMapping.prototype.delete.apply(mapRef.current, args);
|
|
24
|
-
reRender();
|
|
25
|
-
|
|
26
|
-
return res;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return mapRef.current;
|
|
30
|
-
};
|
package/src/global.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './InputMapping';
|