@form-instant/react-input-mapping 0.1.0 → 0.1.5
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/README.md +198 -103
- package/dist/InputMapping/class.d.ts +2 -2
- package/dist/InputMapping/context.d.ts +1 -1
- package/dist/InputMapping/provider.d.ts +2 -2
- package/dist/InputMapping/types.d.ts +1 -1
- package/dist/react-input-mapping.cjs.development.js +7 -7
- package/dist/react-input-mapping.cjs.development.js.map +1 -1
- package/dist/react-input-mapping.cjs.production.min.js.map +1 -1
- package/dist/react-input-mapping.esm.js +7 -7
- package/dist/react-input-mapping.esm.js.map +1 -1
- package/package.json +81 -74
- package/src/InputMapping/class.ts +9 -9
- package/src/InputMapping/context.tsx +2 -3
- package/src/InputMapping/provider.tsx +9 -6
- package/src/InputMapping/types.ts +20 -20
- package/src/InputMapping/useInputMapping.tsx +18 -19
- package/src/global.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,160 +1,255 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Install
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## input-mapping
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<!-- tabs:start -->
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
#### **npm**
|
|
8
8
|
|
|
9
|
-
|
|
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
|
|
9
|
+
```shell
|
|
10
|
+
npm i @form-instant/react-input-mapping
|
|
17
11
|
```
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
#### **bun**
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
cd example
|
|
25
|
-
npm i # or yarn to install dependencies
|
|
26
|
-
npm start # or yarn start
|
|
15
|
+
```shell
|
|
16
|
+
bun add @form-instant/react-input-mapping
|
|
27
17
|
```
|
|
28
18
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
To do a one-off build, use `npm run build` or `yarn build`.
|
|
19
|
+
<!-- tabs:end -->
|
|
32
20
|
|
|
33
|
-
|
|
21
|
+
## resolvers
|
|
34
22
|
|
|
35
|
-
|
|
23
|
+
<!-- tabs:start -->
|
|
36
24
|
|
|
37
|
-
|
|
25
|
+
#### **zod**
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
<!-- tabs:start -->
|
|
40
28
|
|
|
41
|
-
|
|
29
|
+
#### **npm**
|
|
42
30
|
|
|
43
|
-
|
|
31
|
+
```shell
|
|
32
|
+
npm i @form-instant/react-resolver-zod
|
|
33
|
+
```
|
|
44
34
|
|
|
45
|
-
|
|
35
|
+
#### **bun**
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
```shell
|
|
38
|
+
bun add @form-instant/react-resolver-zod
|
|
39
|
+
```
|
|
48
40
|
|
|
49
|
-
|
|
41
|
+
<!-- tabs:end -->
|
|
50
42
|
|
|
51
|
-
|
|
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
|
-
```
|
|
43
|
+
<!-- tabs:end -->
|
|
66
44
|
|
|
67
|
-
|
|
45
|
+
# Example
|
|
68
46
|
|
|
69
|
-
|
|
47
|
+
## react
|
|
70
48
|
|
|
71
|
-
###
|
|
49
|
+
### constructor new InputMapping
|
|
72
50
|
|
|
73
|
-
|
|
51
|
+
#### \* **_new Input Mapping_**
|
|
74
52
|
|
|
75
|
-
|
|
53
|
+
Is the pillar of this set of tools, it consists of an extraction of the native **_new Map_** method in **_javascript_**, which receives as a parameter an object which works as a mapping of the input types, it also accepts two types as a parameter **_P_** are the parameters that each **_input_** component will accept and **_K_** are additional keys that are added to the input glossary.
|
|
76
54
|
|
|
77
|
-
|
|
55
|
+
```typescript
|
|
56
|
+
import {
|
|
57
|
+
InputMapping
|
|
58
|
+
} from "@form-instant/react-input-mapping";
|
|
78
59
|
|
|
79
|
-
|
|
60
|
+
exprot type extendProps = React.InputHTMLAttributes<HTMLInputElement>;
|
|
80
61
|
|
|
81
|
-
|
|
62
|
+
export type P = Record<
|
|
63
|
+
string,
|
|
64
|
+
ParsedField<extendProps, string>
|
|
65
|
+
>;
|
|
66
|
+
export type K = "email" | "password" | "date";
|
|
82
67
|
|
|
83
|
-
|
|
68
|
+
export const inputMapping = new InputMapping<P, K>({
|
|
69
|
+
fallback: (props) => {
|
|
70
|
+
const { fieldConfig, ...prop } = props;
|
|
84
71
|
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
return <input {...prop} {...fieldConfig} />;
|
|
73
|
+
},
|
|
74
|
+
textarea: () => <textarea />,
|
|
75
|
+
number: () => <input type="number" />,
|
|
76
|
+
text: (props) => {
|
|
77
|
+
const { fieldConfig, ...prop } = props;
|
|
87
78
|
|
|
88
|
-
|
|
79
|
+
return <input {...prop} {...fieldConfig} />;
|
|
80
|
+
},
|
|
81
|
+
date: () => <input type="date" />,
|
|
82
|
+
email: (props) => {
|
|
83
|
+
const { fieldConfig, ...prop } = props;
|
|
89
84
|
|
|
90
|
-
|
|
85
|
+
return <input {...prop} {...fieldConfig} />;
|
|
86
|
+
},
|
|
87
|
+
password: (props) => {
|
|
88
|
+
const { fieldConfig, ...prop } = props;
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
return <input {...prop} {...fieldConfig} />;
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
default keys glossary, all values entered by **_k_** will only understand the default listing.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
export type INPUT_COMPONENTS_KEYS =
|
|
99
|
+
| 'checkbox'
|
|
100
|
+
| 'date'
|
|
101
|
+
| 'select'
|
|
102
|
+
| 'radio'
|
|
103
|
+
| 'switch'
|
|
104
|
+
| 'textarea'
|
|
105
|
+
| 'number'
|
|
106
|
+
| 'file'
|
|
107
|
+
| 'text'
|
|
108
|
+
| 'fallback';
|
|
100
109
|
```
|
|
101
110
|
|
|
102
|
-
|
|
111
|
+
#### \* **_create global provider_**
|
|
103
112
|
|
|
104
|
-
|
|
113
|
+
We created a global provider to be able to access input mapping.
|
|
105
114
|
|
|
106
|
-
|
|
115
|
+
```typescript
|
|
116
|
+
import { createFormInstantContainer } from '@form-instant/react-input-mapping';
|
|
117
|
+
import { inputMapping, P, K } from './inputMapping.tsx';
|
|
107
118
|
|
|
108
|
-
|
|
119
|
+
export const { FormInstantInputsProvider, useInputMapping } = createFormInstantContainer<P, K>(
|
|
120
|
+
inputMapping,
|
|
121
|
+
);
|
|
122
|
+
```
|
|
109
123
|
|
|
110
|
-
|
|
124
|
+
we add our provider in the root of the **_vite_** project "./App.tsx" and **_next.js_** "layout.tsx" in the root.
|
|
111
125
|
|
|
112
|
-
|
|
126
|
+
<!-- tabs:start -->
|
|
113
127
|
|
|
114
|
-
|
|
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
|
-
```
|
|
128
|
+
#### **next.js**
|
|
119
129
|
|
|
120
|
-
|
|
130
|
+
```typescript
|
|
131
|
+
import { ReactNode } from "react";
|
|
132
|
+
import { FormInstantInputsProvider } from "./components/providers";
|
|
121
133
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
function Layout({ children }: { children: ReactNode }) {
|
|
135
|
+
return (
|
|
136
|
+
<FormInstantInputsProvider>
|
|
137
|
+
{children}
|
|
138
|
+
</FormInstantInputsProvider>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
128
141
|
|
|
129
|
-
|
|
142
|
+
export default Layout;
|
|
143
|
+
```
|
|
130
144
|
|
|
131
|
-
|
|
145
|
+
#### **vite**
|
|
132
146
|
|
|
133
|
-
|
|
147
|
+
```typescript
|
|
148
|
+
import "./App.css";
|
|
149
|
+
import { Router } from "./router";
|
|
150
|
+
import { FormInstantInputsProvider } from "./components/providers";
|
|
134
151
|
|
|
135
|
-
|
|
152
|
+
function App() {
|
|
153
|
+
return (
|
|
154
|
+
<FormInstantInputsProvider>
|
|
155
|
+
<Forms />
|
|
156
|
+
</FormInstantInputsProvider>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
136
159
|
|
|
137
|
-
|
|
160
|
+
export default App;
|
|
161
|
+
```
|
|
138
162
|
|
|
139
|
-
|
|
163
|
+
<!-- tabs:end -->
|
|
140
164
|
|
|
141
|
-
|
|
165
|
+
#### \* **_use resolver_**
|
|
142
166
|
|
|
143
|
-
|
|
167
|
+
To use our resolver we must instantiate the function to generate the **_fieldConfig_**.
|
|
144
168
|
|
|
145
|
-
|
|
169
|
+
```typescript
|
|
170
|
+
import { createFormInstantContainer } from '@form-instant/react-input-mapping';
|
|
171
|
+
import { inputMapping, P, K, extendProps } from './inputMapping.tsx';
|
|
146
172
|
|
|
147
|
-
|
|
173
|
+
export const { FormInstantInputsProvider, useInputMapping } = createFormInstantContainer<P, K>(
|
|
174
|
+
inputMapping,
|
|
175
|
+
);
|
|
148
176
|
|
|
149
|
-
|
|
177
|
+
export const fieldConfig = createZodSchemaFieldConfig<extendProps>();
|
|
178
|
+
```
|
|
150
179
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
180
|
+
#### \* **_build form_**
|
|
181
|
+
|
|
182
|
+
- schema:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { z } from 'zod';
|
|
186
|
+
import { fieldConfig } from './providers';
|
|
187
|
+
|
|
188
|
+
export const formSchema = z.object({
|
|
189
|
+
security_data: z
|
|
190
|
+
.object({
|
|
191
|
+
email: z
|
|
192
|
+
.string()
|
|
193
|
+
.email()
|
|
194
|
+
.superRefine(
|
|
195
|
+
fieldConfig({
|
|
196
|
+
fieldType: 'email',
|
|
197
|
+
placeholder: 'example@mal.com',
|
|
198
|
+
}),
|
|
199
|
+
),
|
|
200
|
+
password: z.string().superRefine(
|
|
201
|
+
fieldConfig({
|
|
202
|
+
type: 'password',
|
|
203
|
+
placeholder: '******',
|
|
204
|
+
}),
|
|
205
|
+
),
|
|
206
|
+
confirm: z.string(),
|
|
207
|
+
})
|
|
208
|
+
.refine(({ confirm, password }) => confirm !== password, {
|
|
209
|
+
message: 'the confim password is diferent to password',
|
|
210
|
+
}),
|
|
211
|
+
|
|
212
|
+
personal_data: z.object({
|
|
213
|
+
last_name: z.string().superRefine(
|
|
214
|
+
fieldConfig({
|
|
215
|
+
placeholder: 'select date',
|
|
216
|
+
}),
|
|
217
|
+
),
|
|
218
|
+
firse_name: z.string(),
|
|
219
|
+
|
|
220
|
+
birthday: z.coerce.date().optional(),
|
|
221
|
+
|
|
222
|
+
code: z.string(),
|
|
223
|
+
}),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
export type formSchemaType = Zod.infer<typeof formSchema>;
|
|
158
227
|
```
|
|
159
228
|
|
|
160
|
-
|
|
229
|
+
- component
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import {
|
|
233
|
+
FormInstantElement,
|
|
234
|
+
FormInstantProvider,
|
|
235
|
+
} from "@form-instant/react-resolver-zod";
|
|
236
|
+
import { z } from "zod";
|
|
237
|
+
import { formSchema, formSchemaType } from "./schema";
|
|
238
|
+
|
|
239
|
+
export const Forms = () => {
|
|
240
|
+
return (
|
|
241
|
+
<form>
|
|
242
|
+
<h1>your form</h1>
|
|
243
|
+
<FormInstantProvider schema={formSchema}>
|
|
244
|
+
<div>
|
|
245
|
+
<FormInstantElement<formSchemaType> name="security_data" />
|
|
246
|
+
<br />
|
|
247
|
+
<FormInstantElement<formSchemaType> name="personal_data" />
|
|
248
|
+
</div>
|
|
249
|
+
</FormInstantProvider>
|
|
250
|
+
|
|
251
|
+
<button type="submit">submit</button>
|
|
252
|
+
</form>
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC } from
|
|
2
|
-
import { INPUT_COMPONENTS_KEYS } from
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { INPUT_COMPONENTS_KEYS } from './types';
|
|
3
3
|
type MergeKeys<T, U> = {
|
|
4
4
|
[K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;
|
|
5
5
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { InputMapping } from
|
|
1
|
+
import { InputMapping } from './class';
|
|
2
2
|
export declare const InputMappingContext: import("use-context-selector").Context<InputMapping<object, import("./types").INPUT_COMPONENTS_KEYS>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InputMapping } from
|
|
2
|
-
import { INPUT_COMPONENTS_KEYS } from
|
|
1
|
+
import { InputMapping } from './class';
|
|
2
|
+
import { INPUT_COMPONENTS_KEYS } from './types';
|
|
3
3
|
interface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {
|
|
4
4
|
useInputMapping: () => InputMapping<P, K>;
|
|
5
5
|
FormInstantInputsProvider: FCC;
|
|
@@ -8,6 +8,6 @@ export interface ParsedField<AdditionalRenderable, FieldTypes = string> {
|
|
|
8
8
|
options?: [string, string][];
|
|
9
9
|
schema?: ParsedField<AdditionalRenderable, FieldTypes>[];
|
|
10
10
|
}
|
|
11
|
-
export type FieldConfig<AdditionalRenderable =
|
|
11
|
+
export type FieldConfig<AdditionalRenderable = object, FieldTypes = string> = {
|
|
12
12
|
fieldType?: FieldTypes;
|
|
13
13
|
} & AdditionalRenderable;
|
|
@@ -116,12 +116,12 @@ var InputMapping = /*#__PURE__*/function (_Map) {
|
|
|
116
116
|
var _proto = InputMapping.prototype;
|
|
117
117
|
_proto.zodAdacter = function zodAdacter() {
|
|
118
118
|
return Object.entries({
|
|
119
|
-
ZodBoolean:
|
|
120
|
-
ZodDate:
|
|
121
|
-
ZodEnum:
|
|
122
|
-
ZodNativeEnum:
|
|
123
|
-
ZodNumber:
|
|
124
|
-
string:
|
|
119
|
+
ZodBoolean: 'checkbox',
|
|
120
|
+
ZodDate: 'date',
|
|
121
|
+
ZodEnum: 'select',
|
|
122
|
+
ZodNativeEnum: 'select',
|
|
123
|
+
ZodNumber: 'number',
|
|
124
|
+
string: 'text'
|
|
125
125
|
});
|
|
126
126
|
};
|
|
127
127
|
_proto.appendObj = function appendObj(obj) {
|
|
@@ -139,7 +139,7 @@ var InputMapping = /*#__PURE__*/function (_Map) {
|
|
|
139
139
|
};
|
|
140
140
|
_proto.exists = function exists(k) {
|
|
141
141
|
var isHas = _Map.prototype.has.call(this, k);
|
|
142
|
-
if (!isHas) return
|
|
142
|
+
if (!isHas) return 'fallback';
|
|
143
143
|
return k;
|
|
144
144
|
};
|
|
145
145
|
_proto.get = function get(k) {
|
|
@@ -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","\"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,SAAAA,SAASA,CAACJ,GAAsD,EAAA;AACpE,IAAA,IAAMiB,IAAI,GAAGR,MAAM,CAACQ,IAAI,CAACjB,GAAG,CAAqC,CAAA;AAIjE,IAAA,KAAA,IAAAkB,EAAA,GAAA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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;;;;;;;"}
|
|
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 } 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"],"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAA;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;;;;;;;"}
|
|
@@ -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
|
|
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 } 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"],"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","props","createElement","Provider","children"],"mappings":"89CAQaA,IAAAA,WAAmEC,GAyB5E,SAAAD,EAAYE,GAAuD,IAAAC,EAG/D,OAFAA,EAAAF,EAAAG,YAAOC,KAEFH,GAELC,EAAKG,UAAUJ,GAAKC,4HAFVI,CAAAJ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jB,OAlBAJ,EAAOK,QAAQ3B,IAAM,WAAY,IAAA,IAAA4B,EAAAC,UAAA/B,OAARgC,EAAIC,IAAAA,MAAAH,GAAAI,EAAA,EAAAA,EAAAJ,EAAAI,IAAJF,EAAIE,GAAAH,UAAAG,GAGzB,OAFAxD,EAAaS,UAAUe,IAAIiC,MAAMX,EAAOK,QAASG,GACjDN,IACOF,EAAOK,SAGlBL,EAAOK,QAAQO,MAAQ,WAAY,IAAA,IAAAC,EAAAN,UAAA/B,OAARgC,EAAIC,IAAAA,MAAAI,GAAAC,EAAA,EAAAA,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,0FClB0C,SACtCa,GAQA,MAAO,CACHC,0BAPmC,SAACC,GAAK,OACzCC,EAAaA,cAAC1B,EAAoB2B,SAAU,CACxCtC,MAAOkC,EACPK,SAAUH,EAAMG,UAClB,EAIF1B,gBAAAA,EAER"}
|
|
@@ -114,12 +114,12 @@ var InputMapping = /*#__PURE__*/function (_Map) {
|
|
|
114
114
|
var _proto = InputMapping.prototype;
|
|
115
115
|
_proto.zodAdacter = function zodAdacter() {
|
|
116
116
|
return Object.entries({
|
|
117
|
-
ZodBoolean:
|
|
118
|
-
ZodDate:
|
|
119
|
-
ZodEnum:
|
|
120
|
-
ZodNativeEnum:
|
|
121
|
-
ZodNumber:
|
|
122
|
-
string:
|
|
117
|
+
ZodBoolean: 'checkbox',
|
|
118
|
+
ZodDate: 'date',
|
|
119
|
+
ZodEnum: 'select',
|
|
120
|
+
ZodNativeEnum: 'select',
|
|
121
|
+
ZodNumber: 'number',
|
|
122
|
+
string: 'text'
|
|
123
123
|
});
|
|
124
124
|
};
|
|
125
125
|
_proto.appendObj = function appendObj(obj) {
|
|
@@ -137,7 +137,7 @@ var InputMapping = /*#__PURE__*/function (_Map) {
|
|
|
137
137
|
};
|
|
138
138
|
_proto.exists = function exists(k) {
|
|
139
139
|
var isHas = _Map.prototype.has.call(this, k);
|
|
140
|
-
if (!isHas) return
|
|
140
|
+
if (!isHas) return 'fallback';
|
|
141
141
|
return k;
|
|
142
142
|
};
|
|
143
143
|
_proto.get = function get(k) {
|
|
@@ -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
|
|
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 } 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"],"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,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AA,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,77 +1,84 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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"
|
|
2
|
+
"name": "@form-instant/react-input-mapping",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "leomerida15",
|
|
7
|
+
"email": "dimasmerida15@gmail.com",
|
|
8
|
+
"url": "https://github.com/leomerida15"
|
|
55
9
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
"doc:build": "bun nodemon --config docs/nodemon.json"
|
|
31
|
+
},
|
|
32
|
+
"husky": {
|
|
33
|
+
"hooks": {
|
|
34
|
+
"pre-commit": "dts lint"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"jest": {
|
|
38
|
+
"testEnvironment": "jsdom"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": ">=16"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=12"
|
|
45
|
+
},
|
|
46
|
+
"size-limit": [
|
|
47
|
+
{
|
|
48
|
+
"path": "dist/react-input-mapping.cjs.production.min.js",
|
|
49
|
+
"limit": "10 KB"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"path": "dist/react-input-mapping.esm.js",
|
|
53
|
+
"limit": "10 KB"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"use-context-selector": "^2.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@size-limit/preset-small-lib": "^11.1.4",
|
|
61
|
+
"@tsconfig/recommended": "^1.0.7",
|
|
62
|
+
"@tsconfig/vite-react": "^3.0.2",
|
|
63
|
+
"@types/bun": "^1.1.8",
|
|
64
|
+
"@types/react": "^18.3.12",
|
|
65
|
+
"dts-cli": "^2.0.5",
|
|
66
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
67
|
+
"husky": "^9.1.5",
|
|
68
|
+
"nodemon": "^3.1.4",
|
|
69
|
+
"prettier": "^3.3.3",
|
|
70
|
+
"size-limit": "^11.1.4",
|
|
71
|
+
"tslib": "^2.7.0",
|
|
72
|
+
"typescript": "^5.5.4"
|
|
73
|
+
},
|
|
74
|
+
"homepage": "https://leomerida15.github.io/form-instant-react-mapping",
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "git+https://github.com/leomerida15/form-instant-react-mapping.git"
|
|
78
|
+
},
|
|
79
|
+
"keywords": [
|
|
80
|
+
"@form-instant",
|
|
81
|
+
"react",
|
|
82
|
+
"mapping"
|
|
83
|
+
]
|
|
77
84
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC } from
|
|
2
|
-
import { INPUT_COMPONENTS_KEYS } from
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { INPUT_COMPONENTS_KEYS } from './types';
|
|
3
3
|
|
|
4
4
|
type MergeKeys<T, U> = {
|
|
5
5
|
[K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;
|
|
@@ -12,12 +12,12 @@ export class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS>
|
|
|
12
12
|
> {
|
|
13
13
|
private zodAdacter() {
|
|
14
14
|
return Object.entries({
|
|
15
|
-
ZodBoolean:
|
|
16
|
-
ZodDate:
|
|
17
|
-
ZodEnum:
|
|
18
|
-
ZodNativeEnum:
|
|
19
|
-
ZodNumber:
|
|
20
|
-
string:
|
|
15
|
+
ZodBoolean: 'checkbox',
|
|
16
|
+
ZodDate: 'date',
|
|
17
|
+
ZodEnum: 'select',
|
|
18
|
+
ZodNativeEnum: 'select',
|
|
19
|
+
ZodNumber: 'number',
|
|
20
|
+
string: 'text',
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -42,7 +42,7 @@ export class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS>
|
|
|
42
42
|
exists(k: string) {
|
|
43
43
|
const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);
|
|
44
44
|
|
|
45
|
-
if (!isHas) return
|
|
45
|
+
if (!isHas) return 'fallback';
|
|
46
46
|
|
|
47
47
|
return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;
|
|
48
48
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { InputMapping } from "./class";
|
|
1
|
+
import { createContext } from 'use-context-selector';
|
|
2
|
+
import { InputMapping } from './class';
|
|
4
3
|
|
|
5
4
|
export const InputMappingContext = createContext<InputMapping>(new InputMapping());
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createElement } from
|
|
2
|
-
import { InputMapping } from
|
|
3
|
-
import { InputMappingContext } from
|
|
4
|
-
import { INPUT_COMPONENTS_KEYS } from
|
|
5
|
-
import { useInputMapping } from
|
|
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
6
|
|
|
7
7
|
interface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {
|
|
8
8
|
useInputMapping: () => InputMapping<P, K>;
|
|
@@ -18,5 +18,8 @@ export const createFormInstantContainer = <P = object, K extends string = INPUT_
|
|
|
18
18
|
children: props.children,
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
return {
|
|
21
|
+
return {
|
|
22
|
+
FormInstantInputsProvider,
|
|
23
|
+
useInputMapping,
|
|
24
|
+
} as createFormInstantContainerRetuen<P, K>;
|
|
22
25
|
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
export type INPUT_COMPONENTS_KEYS =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
| 'checkbox'
|
|
3
|
+
| 'date'
|
|
4
|
+
| 'select'
|
|
5
|
+
| 'radio'
|
|
6
|
+
| 'switch'
|
|
7
|
+
| 'textarea'
|
|
8
|
+
| 'number'
|
|
9
|
+
| 'file'
|
|
10
|
+
| 'text'
|
|
11
|
+
| 'fallback';
|
|
12
12
|
|
|
13
13
|
export interface ParsedField<AdditionalRenderable, FieldTypes = string> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
key: string;
|
|
15
|
+
type: string;
|
|
16
|
+
required: boolean;
|
|
17
|
+
default?: any;
|
|
18
|
+
fieldConfig?: FieldConfig<AdditionalRenderable, FieldTypes>;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// Field-specific
|
|
21
|
+
options?: [string, string][]; // [value, label] for enums
|
|
22
|
+
schema?: ParsedField<AdditionalRenderable, FieldTypes>[]; // For objects and arrays
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type FieldConfig<AdditionalRenderable =
|
|
26
|
-
|
|
25
|
+
export type FieldConfig<AdditionalRenderable = object, FieldTypes = string> = {
|
|
26
|
+
fieldType?: FieldTypes;
|
|
27
27
|
} & AdditionalRenderable;
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
'use client';
|
|
2
1
|
import { useReducer, useRef } from 'react';
|
|
3
2
|
import { useContext } from 'use-context-selector';
|
|
4
3
|
import { InputMapping } from './class';
|
|
5
4
|
import { InputMappingContext } from './context';
|
|
6
5
|
|
|
7
6
|
export const useInputMapping = () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const initialState = useContext(InputMappingContext);
|
|
8
|
+
const mapRef = useRef(initialState);
|
|
9
|
+
const [, reRender] = useReducer((x) => x + 1, 0);
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
mapRef.current.set = (...args) => {
|
|
12
|
+
InputMapping.prototype.set.apply(mapRef.current, args);
|
|
13
|
+
reRender();
|
|
14
|
+
return mapRef.current;
|
|
15
|
+
};
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
mapRef.current.clear = (...args) => {
|
|
18
|
+
InputMapping.prototype.clear.apply(mapRef.current, args);
|
|
19
|
+
reRender();
|
|
20
|
+
};
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
mapRef.current.delete = (...args) => {
|
|
23
|
+
const res = InputMapping.prototype.delete.apply(mapRef.current, args);
|
|
24
|
+
reRender();
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
return res;
|
|
27
|
+
};
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
return mapRef.current;
|
|
31
30
|
};
|
package/src/global.d.ts
CHANGED