@form-instant/react-input-mapping 0.0.0-alpha

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 leomerida15
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # DTS React User Guide
2
+
3
+ Congrats! You just saved yourself hours of work by bootstrapping this project with DTS. Let’s get you oriented with what’s here and how to use it.
4
+
5
+ > This DTS setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
6
+
7
+ > If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
8
+
9
+ ## Commands
10
+
11
+ DTS scaffolds your new library inside `/src`, and also sets up a [Vite-based](https://vitejs.dev) playground for it inside `/example`.
12
+
13
+ The recommended workflow is to run DTS in one terminal:
14
+
15
+ ```bash
16
+ npm start # or yarn start
17
+ ```
18
+
19
+ This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
20
+
21
+ Then run the example inside another:
22
+
23
+ ```bash
24
+ cd example
25
+ npm i # or yarn to install dependencies
26
+ npm start # or yarn start
27
+ ```
28
+
29
+ The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure DTS is running in watch mode like we recommend above.
30
+
31
+ To do a one-off build, use `npm run build` or `yarn build`.
32
+
33
+ To run tests, use `npm test` or `yarn test`.
34
+
35
+ ## Configuration
36
+
37
+ Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
38
+
39
+ ### Jest
40
+
41
+ Jest tests are set up to run with `npm test` or `yarn test`.
42
+
43
+ ### Bundle analysis
44
+
45
+ Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`.
46
+
47
+ #### Setup Files
48
+
49
+ This is the folder structure we set up for you:
50
+
51
+ ```txt
52
+ /example
53
+ index.html
54
+ index.tsx # test your component here in a demo app
55
+ package.json
56
+ tsconfig.json
57
+ /src
58
+ index.tsx # EDIT THIS
59
+ /test
60
+ index.test.tsx # EDIT THIS
61
+ .gitignore
62
+ package.json
63
+ README.md # EDIT THIS
64
+ tsconfig.json
65
+ ```
66
+
67
+ #### React Testing Library
68
+
69
+ We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
70
+
71
+ ### Rollup
72
+
73
+ DTS uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
74
+
75
+ ### TypeScript
76
+
77
+ `tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
78
+
79
+ ## Continuous Integration
80
+
81
+ ### GitHub Actions
82
+
83
+ Two actions are added by default:
84
+
85
+ - `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
86
+ - `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
87
+
88
+ ## Optimizations
89
+
90
+ Please see the main `dts` [optimizations docs](https://github.com/weiran-zsd/dts-cli#optimizations). In particular, know that you can take advantage of development-only optimizations:
91
+
92
+ ```js
93
+ // ./types/index.d.ts
94
+ declare var __DEV__: boolean;
95
+
96
+ // inside your code...
97
+ if (__DEV__) {
98
+ console.log('foo');
99
+ }
100
+ ```
101
+
102
+ You can also choose to install and use [invariant](https://github.com/weiran-zsd/dts-cli#invariant) and [warning](https://github.com/weiran-zsd/dts-cli#warning) functions.
103
+
104
+ ## Module Formats
105
+
106
+ CJS, ESModules, and UMD module formats are supported.
107
+
108
+ The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
109
+
110
+ ## Deploying the Example Playground
111
+
112
+ The Playground is just a simple [Vite](https://vitejs.dev) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):
113
+
114
+ ```bash
115
+ cd example # if not already in the example folder
116
+ npm run build # builds to dist
117
+ netlify deploy # deploy the dist folder
118
+ ```
119
+
120
+ Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:
121
+
122
+ ```bash
123
+ netlify init
124
+ # build command: yarn build && cd example && yarn && yarn build
125
+ # directory to deploy: example/dist
126
+ # pick yes for netlify.toml
127
+ ```
128
+
129
+ ## Named Exports
130
+
131
+ Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
132
+
133
+ ## Including Styles
134
+
135
+ There are many ways to ship styles, including with CSS-in-JS. DTS has no opinion on this, configure how you like.
136
+
137
+ For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
138
+
139
+ ## Publishing to NPM
140
+
141
+ We recommend using [np](https://github.com/sindresorhus/np).
142
+
143
+ ## Usage with Lerna
144
+
145
+ When creating a new package with DTS within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
146
+
147
+ The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
148
+
149
+ Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
150
+
151
+ ```diff
152
+ "alias": {
153
+ - "react": "../node_modules/react",
154
+ - "react-dom": "../node_modules/react-dom"
155
+ + "react": "../../../node_modules/react",
156
+ + "react-dom": "../../../node_modules/react-dom"
157
+ },
158
+ ```
159
+
160
+ An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/formium/tsdx/issues/64)
@@ -0,0 +1,15 @@
1
+ import { FC } from "react";
2
+ import { INPUT_COMPONENTS_KEYS } from "./types";
3
+ type MergeKeys<T, U> = {
4
+ [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;
5
+ };
6
+ export declare class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<MergeKeys<K, INPUT_COMPONENTS_KEYS>, FC<P>> {
7
+ private zodAdacter;
8
+ private appendObj;
9
+ constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>);
10
+ exists(k: string): "fallback" | MergeKeys<K, INPUT_COMPONENTS_KEYS>;
11
+ get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string): FC<P> | undefined;
12
+ set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>): this;
13
+ extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>): InputMapping<P, INPUT_COMPONENTS_KEYS | K>;
14
+ }
15
+ export {};
@@ -0,0 +1,2 @@
1
+ import { InputMapping } from "./class";
2
+ export declare const InputMappingContext: import("use-context-selector").Context<InputMapping<object, import("./types").INPUT_COMPONENTS_KEYS>>;
@@ -0,0 +1,5 @@
1
+ export * from './class';
2
+ export * from './context';
3
+ export * from './provider';
4
+ export * from './types';
5
+ export * from './useInputMapping';
@@ -0,0 +1,8 @@
1
+ import { InputMapping } from "./class";
2
+ import { INPUT_COMPONENTS_KEYS } from "./types";
3
+ interface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {
4
+ useInputMapping: () => InputMapping<P, K>;
5
+ FormInstantInputsProvider: FCC;
6
+ }
7
+ export declare const createFormInstantContainer: <P = object, K extends string = INPUT_COMPONENTS_KEYS>(inputMapping: InputMapping<P, K>) => createFormInstantContainerRetuen<P, K>;
8
+ export {};
@@ -0,0 +1,13 @@
1
+ export type INPUT_COMPONENTS_KEYS = 'checkbox' | 'date' | 'select' | 'radio' | 'switch' | 'textarea' | 'number' | 'file' | 'text' | 'fallback';
2
+ export interface ParsedField<AdditionalRenderable, FieldTypes = string> {
3
+ key: string;
4
+ type: string;
5
+ required: boolean;
6
+ default?: any;
7
+ fieldConfig?: FieldConfig<AdditionalRenderable, FieldTypes>;
8
+ options?: [string, string][];
9
+ schema?: ParsedField<AdditionalRenderable, FieldTypes>[];
10
+ }
11
+ export type FieldConfig<AdditionalRenderable = {}, FieldTypes = string> = {
12
+ fieldType?: FieldTypes;
13
+ } & AdditionalRenderable;
@@ -0,0 +1,2 @@
1
+ import { InputMapping } from './class';
2
+ export declare const useInputMapping: () => InputMapping<object, import("./types").INPUT_COMPONENTS_KEYS>;
@@ -0,0 +1 @@
1
+ export * from './InputMapping';
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./react-input-mapping.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./react-input-mapping.cjs.development.js')
8
+ }
@@ -0,0 +1,212 @@
1
+ 'use strict';
2
+
3
+ var useContextSelector = require('use-context-selector');
4
+ var react = require('react');
5
+
6
+ function _arrayLikeToArray(r, a) {
7
+ (null == a || a > r.length) && (a = r.length);
8
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
9
+ return n;
10
+ }
11
+ function _assertThisInitialized(e) {
12
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13
+ return e;
14
+ }
15
+ function _construct(t, e, r) {
16
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
17
+ var o = [null];
18
+ o.push.apply(o, e);
19
+ var p = new (t.bind.apply(t, o))();
20
+ return r && _setPrototypeOf(p, r.prototype), p;
21
+ }
22
+ function _createForOfIteratorHelperLoose(r, e) {
23
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
24
+ if (t) return (t = t.call(r)).next.bind(t);
25
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
26
+ t && (r = t);
27
+ var o = 0;
28
+ return function () {
29
+ return o >= r.length ? {
30
+ done: !0
31
+ } : {
32
+ done: !1,
33
+ value: r[o++]
34
+ };
35
+ };
36
+ }
37
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
38
+ }
39
+ function _extends() {
40
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
41
+ for (var e = 1; e < arguments.length; e++) {
42
+ var t = arguments[e];
43
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
44
+ }
45
+ return n;
46
+ }, _extends.apply(null, arguments);
47
+ }
48
+ function _getPrototypeOf(t) {
49
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
50
+ return t.__proto__ || Object.getPrototypeOf(t);
51
+ }, _getPrototypeOf(t);
52
+ }
53
+ function _inheritsLoose(t, o) {
54
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
55
+ }
56
+ function _isNativeFunction(t) {
57
+ try {
58
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
59
+ } catch (n) {
60
+ return "function" == typeof t;
61
+ }
62
+ }
63
+ function _isNativeReflectConstruct() {
64
+ try {
65
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
66
+ } catch (t) {}
67
+ return (_isNativeReflectConstruct = function () {
68
+ return !!t;
69
+ })();
70
+ }
71
+ function _setPrototypeOf(t, e) {
72
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
73
+ return t.__proto__ = e, t;
74
+ }, _setPrototypeOf(t, e);
75
+ }
76
+ function _unsupportedIterableToArray(r, a) {
77
+ if (r) {
78
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
79
+ var t = {}.toString.call(r).slice(8, -1);
80
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
81
+ }
82
+ }
83
+ function _wrapNativeSuper(t) {
84
+ var r = "function" == typeof Map ? new Map() : void 0;
85
+ return _wrapNativeSuper = function (t) {
86
+ if (null === t || !_isNativeFunction(t)) return t;
87
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
88
+ if (void 0 !== r) {
89
+ if (r.has(t)) return r.get(t);
90
+ r.set(t, Wrapper);
91
+ }
92
+ function Wrapper() {
93
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
94
+ }
95
+ return Wrapper.prototype = Object.create(t.prototype, {
96
+ constructor: {
97
+ value: Wrapper,
98
+ enumerable: !1,
99
+ writable: !0,
100
+ configurable: !0
101
+ }
102
+ }), _setPrototypeOf(Wrapper, t);
103
+ }, _wrapNativeSuper(t);
104
+ }
105
+
106
+ // K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas
107
+ var InputMapping = /*#__PURE__*/function (_Map) {
108
+ function InputMapping(obj) {
109
+ var _this;
110
+ _this = _Map.call(this) || this;
111
+ if (!obj) return _assertThisInitialized(_this);
112
+ _this.appendObj(obj);
113
+ return _this;
114
+ }
115
+ _inheritsLoose(InputMapping, _Map);
116
+ var _proto = InputMapping.prototype;
117
+ _proto.zodAdacter = function zodAdacter() {
118
+ return Object.entries({
119
+ ZodBoolean: "checkbox",
120
+ ZodDate: "date",
121
+ ZodEnum: "select",
122
+ ZodNativeEnum: "select",
123
+ ZodNumber: "number",
124
+ string: "text"
125
+ });
126
+ };
127
+ _proto.appendObj = function appendObj(obj) {
128
+ var keys = Object.keys(obj);
129
+ for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
130
+ var key = _keys[_i];
131
+ this.set(key, obj[key]);
132
+ }
133
+ for (var _iterator = _createForOfIteratorHelperLoose(this.zodAdacter()), _step; !(_step = _iterator()).done;) {
134
+ var _step$value = _step.value,
135
+ k = _step$value[0],
136
+ v = _step$value[1];
137
+ this.set(k, this.get(v));
138
+ }
139
+ };
140
+ _proto.exists = function exists(k) {
141
+ var isHas = _Map.prototype.has.call(this, k);
142
+ if (!isHas) return "fallback";
143
+ return k;
144
+ };
145
+ _proto.get = function get(k) {
146
+ return _Map.prototype.get.call(this, k);
147
+ };
148
+ _proto.set = function set(k, v) {
149
+ if (!_Map.prototype.has.call(this, k)) _Map.prototype.set.call(this, k, v);
150
+ return this;
151
+ };
152
+ _proto["extends"] = function _extends$1(cb) {
153
+ var obj = Object.fromEntries(_Map.prototype.entries.call(this));
154
+ var extendObj = cb(this);
155
+ return new InputMapping(_extends({}, obj, extendObj));
156
+ };
157
+ return InputMapping;
158
+ }(/*#__PURE__*/_wrapNativeSuper(Map));
159
+
160
+ var InputMappingContext = /*#__PURE__*/useContextSelector.createContext(/*#__PURE__*/new InputMapping());
161
+
162
+ var useInputMapping = function useInputMapping() {
163
+ var initialState = useContextSelector.useContext(InputMappingContext);
164
+ var mapRef = react.useRef(initialState);
165
+ var _useReducer = react.useReducer(function (x) {
166
+ return x + 1;
167
+ }, 0),
168
+ reRender = _useReducer[1];
169
+ mapRef.current.set = function () {
170
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
171
+ args[_key] = arguments[_key];
172
+ }
173
+ InputMapping.prototype.set.apply(mapRef.current, args);
174
+ reRender();
175
+ return mapRef.current;
176
+ };
177
+ mapRef.current.clear = function () {
178
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
179
+ args[_key2] = arguments[_key2];
180
+ }
181
+ InputMapping.prototype.clear.apply(mapRef.current, args);
182
+ reRender();
183
+ };
184
+ mapRef.current["delete"] = function () {
185
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
186
+ args[_key3] = arguments[_key3];
187
+ }
188
+ var res = InputMapping.prototype["delete"].apply(mapRef.current, args);
189
+ reRender();
190
+ return res;
191
+ };
192
+ return mapRef.current;
193
+ };
194
+
195
+ var createFormInstantContainer = function createFormInstantContainer(inputMapping) {
196
+ var FormInstantInputsProvider = function FormInstantInputsProvider(props) {
197
+ return react.createElement(InputMappingContext.Provider, {
198
+ value: inputMapping,
199
+ children: props.children
200
+ });
201
+ };
202
+ return {
203
+ FormInstantInputsProvider: FormInstantInputsProvider,
204
+ useInputMapping: useInputMapping
205
+ };
206
+ };
207
+
208
+ exports.InputMapping = InputMapping;
209
+ exports.InputMappingContext = InputMappingContext;
210
+ exports.createFormInstantContainer = createFormInstantContainer;
211
+ exports.useInputMapping = useInputMapping;
212
+ //# sourceMappingURL=react-input-mapping.cjs.development.js.map
@@ -0,0 +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","\"use client\";\nimport { createContext } from \"use-context-selector\";\nimport { InputMapping } from \"./class\";\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","'use client';\nimport { 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 } 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 { FormInstantInputsProvider, useInputMapping } as createFormInstantContainerRetuen<P, K>;\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"],"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,S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ARoC,IAAI,GAAAC,IAAAA,KAAA,CAAAM,KAAA,GAAAC,KAAA,GAAA,CAAA,EAAAA,KAAA,GAAAD,KAAA,EAAAC,KAAA,EAAA,EAAA;AAAJR,MAAAA,IAAI,CAAAQ,KAAA,CAAAT,GAAAA,SAAA,CAAAS,KAAA,CAAA,CAAA;AAAA,KAAA;AAC9B,IAAA,IAAMC,GAAG,GAAGnE,YAAY,CAACS,SAAS,CAAO,QAAA,CAAA,CAACoD,KAAK,CAACZ,MAAM,CAACM,OAAO,EAAEG,IAAI,CAAC,CAAA;AACrEJ,IAAAA,QAAQ,EAAE,CAAA;AAEV,IAAA,OAAOa,GAAG,CAAA;GACX,CAAA;EAED,OAAOlB,MAAM,CAACM,OAAO,CAAA;AACvB;;ICnBaa,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;AAAEJ,IAAAA,yBAAyB,EAAzBA,yBAAyB;AAAExB,IAAAA,eAAe,EAAfA,eAAAA;GAA2D,CAAA;AACnG;;;;;;;"}
@@ -0,0 +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.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
+ //# sourceMappingURL=react-input-mapping.cjs.production.min.js.map
@@ -0,0 +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","\"use client\";\nimport { createContext } from \"use-context-selector\";\nimport { InputMapping } from \"./class\";\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","'use client';\nimport { 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 } 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 { FormInstantInputsProvider, useInputMapping } as createFormInstantContainerRetuen<P, K>;\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","inputMapping","FormInstantInputsProvider","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3EC,EAAsBC,EAAAA,cAA4B,IAAI1C,GCEtD2C,EAAkB,WAC7B,IAAMC,EAAeC,aAAWJ,GAC1BK,EAASC,SAAOH,GACbI,EAAYC,cAAW,SAACC,GAAC,OAAKA,EAAI,CAAC,GAAE,GAA7B,GAoBjB,OAlBAJ,EAAOK,QAAQ3B,IAAM,WAAY,IAAA,IAAA4B,EAAAC,UAAA/B,OAARgC,EAAIC,IAAAA,MAAAH,GAAAI,EAAA,EAAAA,EAAAJ,EAAAI,IAAJF,EAAIE,GAAAH,UAAAG,GAG3B,OAFAxD,EAAaS,UAAUe,IAAIiC,MAAMX,EAAOK,QAASG,GACjDN,IACOF,EAAOK,SAGhBL,EAAOK,QAAQO,MAAQ,WAAY,IAAA,IAAAC,EAAAN,UAAA/B,OAARgC,EAAIC,IAAAA,MAAAI,GAAAC,EAAA,EAAAA,EAAAD,EAAAC,IAAJN,EAAIM,GAAAP,UAAAO,GAC7B5D,EAAaS,UAAUiD,MAAMD,MAAMX,EAAOK,QAASG,GACnDN,KAGFF,EAAOK,QAAc,OAAG,WAAY,IAAA,IAAAU,EAAAR,UAAA/B,OAARgC,EAAIC,IAAAA,MAAAM,GAAAC,EAAA,EAAAA,EAAAD,EAAAC,IAAJR,EAAIQ,GAAAT,UAAAS,GAC9B,IAAMC,EAAM/D,EAAaS,UAAgB,OAACgD,MAAMX,EAAOK,QAASG,GAGhE,OAFAN,IAEOe,GAGFjB,EAAOK,OAChB,0FCnB0C,SACtCa,GAQA,MAAO,CAAEC,0BAN8B,SAACC,GAAK,OACzCC,EAAaA,cAAC1B,EAAoB2B,SAAU,CACxCtC,MAAOkC,EACPK,SAAUH,EAAMG,UAClB,EAE8B1B,gBAAAA,EACxC"}
@@ -0,0 +1,207 @@
1
+ import { createContext, useContext } from 'use-context-selector';
2
+ import { useRef, useReducer, createElement } from 'react';
3
+
4
+ function _arrayLikeToArray(r, a) {
5
+ (null == a || a > r.length) && (a = r.length);
6
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
7
+ return n;
8
+ }
9
+ function _assertThisInitialized(e) {
10
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
11
+ return e;
12
+ }
13
+ function _construct(t, e, r) {
14
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
15
+ var o = [null];
16
+ o.push.apply(o, e);
17
+ var p = new (t.bind.apply(t, o))();
18
+ return r && _setPrototypeOf(p, r.prototype), p;
19
+ }
20
+ function _createForOfIteratorHelperLoose(r, e) {
21
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
22
+ if (t) return (t = t.call(r)).next.bind(t);
23
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
24
+ t && (r = t);
25
+ var o = 0;
26
+ return function () {
27
+ return o >= r.length ? {
28
+ done: !0
29
+ } : {
30
+ done: !1,
31
+ value: r[o++]
32
+ };
33
+ };
34
+ }
35
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
36
+ }
37
+ function _extends() {
38
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
39
+ for (var e = 1; e < arguments.length; e++) {
40
+ var t = arguments[e];
41
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
42
+ }
43
+ return n;
44
+ }, _extends.apply(null, arguments);
45
+ }
46
+ function _getPrototypeOf(t) {
47
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
48
+ return t.__proto__ || Object.getPrototypeOf(t);
49
+ }, _getPrototypeOf(t);
50
+ }
51
+ function _inheritsLoose(t, o) {
52
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
53
+ }
54
+ function _isNativeFunction(t) {
55
+ try {
56
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
57
+ } catch (n) {
58
+ return "function" == typeof t;
59
+ }
60
+ }
61
+ function _isNativeReflectConstruct() {
62
+ try {
63
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
64
+ } catch (t) {}
65
+ return (_isNativeReflectConstruct = function () {
66
+ return !!t;
67
+ })();
68
+ }
69
+ function _setPrototypeOf(t, e) {
70
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
71
+ return t.__proto__ = e, t;
72
+ }, _setPrototypeOf(t, e);
73
+ }
74
+ function _unsupportedIterableToArray(r, a) {
75
+ if (r) {
76
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
77
+ var t = {}.toString.call(r).slice(8, -1);
78
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
79
+ }
80
+ }
81
+ function _wrapNativeSuper(t) {
82
+ var r = "function" == typeof Map ? new Map() : void 0;
83
+ return _wrapNativeSuper = function (t) {
84
+ if (null === t || !_isNativeFunction(t)) return t;
85
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
86
+ if (void 0 !== r) {
87
+ if (r.has(t)) return r.get(t);
88
+ r.set(t, Wrapper);
89
+ }
90
+ function Wrapper() {
91
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
92
+ }
93
+ return Wrapper.prototype = Object.create(t.prototype, {
94
+ constructor: {
95
+ value: Wrapper,
96
+ enumerable: !1,
97
+ writable: !0,
98
+ configurable: !0
99
+ }
100
+ }), _setPrototypeOf(Wrapper, t);
101
+ }, _wrapNativeSuper(t);
102
+ }
103
+
104
+ // K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas
105
+ var InputMapping = /*#__PURE__*/function (_Map) {
106
+ function InputMapping(obj) {
107
+ var _this;
108
+ _this = _Map.call(this) || this;
109
+ if (!obj) return _assertThisInitialized(_this);
110
+ _this.appendObj(obj);
111
+ return _this;
112
+ }
113
+ _inheritsLoose(InputMapping, _Map);
114
+ var _proto = InputMapping.prototype;
115
+ _proto.zodAdacter = function zodAdacter() {
116
+ return Object.entries({
117
+ ZodBoolean: "checkbox",
118
+ ZodDate: "date",
119
+ ZodEnum: "select",
120
+ ZodNativeEnum: "select",
121
+ ZodNumber: "number",
122
+ string: "text"
123
+ });
124
+ };
125
+ _proto.appendObj = function appendObj(obj) {
126
+ var keys = Object.keys(obj);
127
+ for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
128
+ var key = _keys[_i];
129
+ this.set(key, obj[key]);
130
+ }
131
+ for (var _iterator = _createForOfIteratorHelperLoose(this.zodAdacter()), _step; !(_step = _iterator()).done;) {
132
+ var _step$value = _step.value,
133
+ k = _step$value[0],
134
+ v = _step$value[1];
135
+ this.set(k, this.get(v));
136
+ }
137
+ };
138
+ _proto.exists = function exists(k) {
139
+ var isHas = _Map.prototype.has.call(this, k);
140
+ if (!isHas) return "fallback";
141
+ return k;
142
+ };
143
+ _proto.get = function get(k) {
144
+ return _Map.prototype.get.call(this, k);
145
+ };
146
+ _proto.set = function set(k, v) {
147
+ if (!_Map.prototype.has.call(this, k)) _Map.prototype.set.call(this, k, v);
148
+ return this;
149
+ };
150
+ _proto["extends"] = function _extends$1(cb) {
151
+ var obj = Object.fromEntries(_Map.prototype.entries.call(this));
152
+ var extendObj = cb(this);
153
+ return new InputMapping(_extends({}, obj, extendObj));
154
+ };
155
+ return InputMapping;
156
+ }(/*#__PURE__*/_wrapNativeSuper(Map));
157
+
158
+ var InputMappingContext = /*#__PURE__*/createContext(/*#__PURE__*/new InputMapping());
159
+
160
+ var useInputMapping = function useInputMapping() {
161
+ var initialState = useContext(InputMappingContext);
162
+ var mapRef = useRef(initialState);
163
+ var _useReducer = useReducer(function (x) {
164
+ return x + 1;
165
+ }, 0),
166
+ reRender = _useReducer[1];
167
+ mapRef.current.set = function () {
168
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
169
+ args[_key] = arguments[_key];
170
+ }
171
+ InputMapping.prototype.set.apply(mapRef.current, args);
172
+ reRender();
173
+ return mapRef.current;
174
+ };
175
+ mapRef.current.clear = function () {
176
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
177
+ args[_key2] = arguments[_key2];
178
+ }
179
+ InputMapping.prototype.clear.apply(mapRef.current, args);
180
+ reRender();
181
+ };
182
+ mapRef.current["delete"] = function () {
183
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
184
+ args[_key3] = arguments[_key3];
185
+ }
186
+ var res = InputMapping.prototype["delete"].apply(mapRef.current, args);
187
+ reRender();
188
+ return res;
189
+ };
190
+ return mapRef.current;
191
+ };
192
+
193
+ var createFormInstantContainer = function createFormInstantContainer(inputMapping) {
194
+ var FormInstantInputsProvider = function FormInstantInputsProvider(props) {
195
+ return createElement(InputMappingContext.Provider, {
196
+ value: inputMapping,
197
+ children: props.children
198
+ });
199
+ };
200
+ return {
201
+ FormInstantInputsProvider: FormInstantInputsProvider,
202
+ useInputMapping: useInputMapping
203
+ };
204
+ };
205
+
206
+ export { InputMapping, InputMappingContext, createFormInstantContainer, useInputMapping };
207
+ //# sourceMappingURL=react-input-mapping.esm.js.map
@@ -0,0 +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","\"use client\";\nimport { createContext } from \"use-context-selector\";\nimport { InputMapping } from \"./class\";\n\nexport const InputMappingContext = createContext<InputMapping>(new InputMapping());\n","'use client';\nimport { 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 } 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 { FormInstantInputsProvider, useInputMapping } as createFormInstantContainerRetuen<P, K>;\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","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YAAY,CAACS,SAAS,CAAO,QAAA,CAAA,CAACoD,KAAK,CAACZ,MAAM,CAACM,OAAO,EAAEG,IAAI,CAAC,CAAA;AACrEJ,IAAAA,QAAQ,EAAE,CAAA;AAEV,IAAA,OAAOa,GAAG,CAAA;GACX,CAAA;EAED,OAAOlB,MAAM,CAACM,OAAO,CAAA;AACvB;;ICnBaa,0BAA0B,GAAG,SAA7BA,0BAA0BA,CACnCC,YAAgC,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;AAAEJ,IAAAA,yBAAyB,EAAzBA,yBAAyB;AAAExB,IAAAA,eAAe,EAAfA,eAAAA;GAA2D,CAAA;AACnG;;;;"}
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@form-instant/react-input-mapping",
3
+ "version": "0.0.0-alpha",
4
+ "license": "MIT",
5
+ "author": {
6
+ "name": "leomerida15",
7
+ "email": "dimasmerida15@gmail.com",
8
+ "url": "https://github.com/leomerida15"
9
+ },
10
+ "main": "dist/index.js",
11
+ "module": "dist/react-input-mapping.esm.js",
12
+ "typings": "dist/index.d.ts",
13
+ "files": [
14
+ "dist",
15
+ "src"
16
+ ],
17
+ "private": false,
18
+ "exports": {
19
+ ".": "./src/index.ts"
20
+ },
21
+ "scripts": {
22
+ "analyze": "size-limit --why",
23
+ "build": "dts build",
24
+ "lint": "dts lint",
25
+ "prepare": "dts build",
26
+ "size": "size-limit",
27
+ "start": "dts watch",
28
+ "test": "dts test --passWithNoTests",
29
+ "Up": "npm publish --access public"
30
+ },
31
+ "husky": {
32
+ "hooks": {
33
+ "pre-commit": "dts lint"
34
+ }
35
+ },
36
+ "prettier": {
37
+ "printWidth": 80,
38
+ "semi": true,
39
+ "singleQuote": true,
40
+ "trailingComma": "es5"
41
+ },
42
+ "jest": {
43
+ "testEnvironment": "jsdom"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=16"
47
+ },
48
+ "engines": {
49
+ "node": ">=12"
50
+ },
51
+ "size-limit": [
52
+ {
53
+ "path": "dist/react-input-mapping.cjs.production.min.js",
54
+ "limit": "10 KB"
55
+ },
56
+ {
57
+ "path": "dist/react-input-mapping.esm.js",
58
+ "limit": "10 KB"
59
+ }
60
+ ],
61
+ "dependencies": {
62
+ "use-context-selector": "^2.0.0"
63
+ },
64
+ "devDependencies": {
65
+ "@size-limit/preset-small-lib": "^11.1.4",
66
+ "@tsconfig/recommended": "^1.0.7",
67
+ "@tsconfig/vite-react": "^3.0.2",
68
+ "@types/bun": "^1.1.8",
69
+ "dts-cli": "^2.0.5",
70
+ "husky": "^9.1.5",
71
+ "nodemon": "^3.1.4",
72
+ "prettier": "^3.3.3",
73
+ "size-limit": "^11.1.4",
74
+ "tslib": "^2.7.0",
75
+ "typescript": "^5.5.4"
76
+ }
77
+ }
@@ -0,0 +1,70 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ "use client";
2
+ import { createContext } from "use-context-selector";
3
+ import { InputMapping } from "./class";
4
+
5
+ export const InputMappingContext = createContext<InputMapping>(new InputMapping());
@@ -0,0 +1,5 @@
1
+ export * from './class';
2
+ export * from './context';
3
+ export * from './provider';
4
+ export * from './types';
5
+ export * from './useInputMapping';
@@ -0,0 +1,22 @@
1
+ import { createElement } from "react";
2
+ import { InputMapping } from "./class";
3
+ import { InputMappingContext } from "./context";
4
+ import { INPUT_COMPONENTS_KEYS } 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 { FormInstantInputsProvider, useInputMapping } as createFormInstantContainerRetuen<P, K>;
22
+ };
@@ -0,0 +1,27 @@
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 = {}, FieldTypes = string> = {
26
+ fieldType?: FieldTypes;
27
+ } & AdditionalRenderable;
@@ -0,0 +1,31 @@
1
+ 'use client';
2
+ import { useReducer, useRef } from 'react';
3
+ import { useContext } from 'use-context-selector';
4
+ import { InputMapping } from './class';
5
+ import { InputMappingContext } from './context';
6
+
7
+ export const useInputMapping = () => {
8
+ const initialState = useContext(InputMappingContext);
9
+ const mapRef = useRef(initialState);
10
+ const [, reRender] = useReducer((x) => x + 1, 0);
11
+
12
+ mapRef.current.set = (...args) => {
13
+ InputMapping.prototype.set.apply(mapRef.current, args);
14
+ reRender();
15
+ return mapRef.current;
16
+ };
17
+
18
+ mapRef.current.clear = (...args) => {
19
+ InputMapping.prototype.clear.apply(mapRef.current, args);
20
+ reRender();
21
+ };
22
+
23
+ mapRef.current.delete = (...args) => {
24
+ const res = InputMapping.prototype.delete.apply(mapRef.current, args);
25
+ reRender();
26
+
27
+ return res;
28
+ };
29
+
30
+ return mapRef.current;
31
+ };
@@ -0,0 +1,13 @@
1
+ import { FC as FCN, ReactNode } from "react";
2
+
3
+ declare global {
4
+ type FCCP<P extends object = object> = P & {
5
+ children: ReactNode;
6
+ };
7
+
8
+ type FCCR = ReactNode;
9
+
10
+ type FCC<P = object> = FCN<P & FCCP>;
11
+
12
+ type FC<P = object> = FCN<P>;
13
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './InputMapping';