@form-instant/react-input-mapping 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-instant/react-input-mapping",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "leomerida15",
@@ -11,13 +11,8 @@
11
11
  "module": "dist/react-input-mapping.esm.js",
12
12
  "typings": "dist/index.d.ts",
13
13
  "files": [
14
- "dist",
15
- "src"
14
+ "dist"
16
15
  ],
17
- "private": false,
18
- "exports": {
19
- ".": "./src/index.ts"
20
- },
21
16
  "scripts": {
22
17
  "analyze": "size-limit --why",
23
18
  "build": "dts build",
@@ -1,70 +0,0 @@
1
- import { FC } from 'react';
2
- import { INPUT_COMPONENTS_KEYS } from './types';
3
-
4
- type MergeKeys<T, U> = {
5
- [K in keyof T | keyof U]: K extends keyof T ? T[K] : K extends keyof U ? U[K] : never;
6
- };
7
-
8
- // K extiende de INPUT_COMPONENTS_KEYS y puede incluir más claves personalizadas
9
- export class InputMapping<P = object, K extends string = INPUT_COMPONENTS_KEYS> extends Map<
10
- MergeKeys<K, INPUT_COMPONENTS_KEYS>,
11
- FC<P>
12
- > {
13
- private zodAdacter() {
14
- return Object.entries({
15
- ZodBoolean: 'checkbox',
16
- ZodDate: 'date',
17
- ZodEnum: 'select',
18
- ZodNativeEnum: 'select',
19
- ZodNumber: 'number',
20
- string: 'text',
21
- });
22
- }
23
-
24
- private appendObj(obj: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {
25
- const keys = Object.keys(obj) as Array<K | INPUT_COMPONENTS_KEYS>;
26
-
27
- type Ky = MergeKeys<K, INPUT_COMPONENTS_KEYS>;
28
-
29
- for (const key of keys) this.set(key as Ky, obj[key]!);
30
-
31
- for (const [k, v] of this.zodAdacter()) this.set(k as Ky, this.get(v)!);
32
- }
33
-
34
- constructor(obj?: Partial<Record<K | INPUT_COMPONENTS_KEYS, FC<P>>>) {
35
- super();
36
-
37
- if (!obj) return;
38
-
39
- this.appendObj(obj);
40
- }
41
-
42
- exists(k: string) {
43
- const isHas = super.has(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);
44
-
45
- if (!isHas) return 'fallback';
46
-
47
- return k as MergeKeys<K, INPUT_COMPONENTS_KEYS>;
48
- }
49
-
50
- get(k: MergeKeys<K, INPUT_COMPONENTS_KEYS> | string) {
51
- return super.get(k as MergeKeys<K, INPUT_COMPONENTS_KEYS>);
52
- }
53
-
54
- set(k: MergeKeys<K, INPUT_COMPONENTS_KEYS>, v: FC<P>) {
55
- if (!super.has(k)) super.set(k, v);
56
-
57
- return this;
58
- }
59
-
60
- extends(cb: (mapingp: InputMapping<P, K | INPUT_COMPONENTS_KEYS>) => Record<never, FC<P>>) {
61
- const obj = Object.fromEntries(super.entries()) as Record<string, FC<P>>;
62
-
63
- const extendObj = cb(this as unknown as InputMapping<P, K | INPUT_COMPONENTS_KEYS>);
64
-
65
- return new InputMapping<P, K | INPUT_COMPONENTS_KEYS>({
66
- ...obj,
67
- ...extendObj,
68
- } as Record<K | INPUT_COMPONENTS_KEYS, FC<P>>);
69
- }
70
- }
@@ -1,4 +0,0 @@
1
- import { createContext } from 'use-context-selector';
2
- import { InputMapping } from './class';
3
-
4
- export const InputMappingContext = createContext<InputMapping>(new InputMapping());
@@ -1,5 +0,0 @@
1
- export * from './class';
2
- export * from './context';
3
- export * from './provider';
4
- export * from './types';
5
- export * from './useInputMapping';
@@ -1,35 +0,0 @@
1
- import { createElement } from 'react';
2
- import { InputMapping } from './class';
3
- import { InputMappingContext } from './context';
4
- import { INPUT_COMPONENTS_KEYS, ParsedField } from './types';
5
- import { useInputMapping } from './useInputMapping';
6
-
7
- interface createFormInstantContainerRetuen<P = object, K extends string = INPUT_COMPONENTS_KEYS> {
8
- useInputMapping: () => InputMapping<P, K>;
9
- FormInstantInputsProvider: FCC;
10
- }
11
-
12
- export const createFormInstantContainer = <P = object, K extends string = INPUT_COMPONENTS_KEYS>(
13
- inputMapping: InputMapping<P, K>,
14
- ) => {
15
- const FormInstantInputsProvider: FCC = (props) =>
16
- createElement(InputMappingContext.Provider, {
17
- value: inputMapping as InputMapping,
18
- children: props.children,
19
- });
20
-
21
- return {
22
- FormInstantInputsProvider,
23
- useInputMapping,
24
- } as createFormInstantContainerRetuen<P, K>;
25
- };
26
-
27
- export const ElementMapping: FC<ParsedField<null, string>> = (props) => {
28
- const InputMapping = useInputMapping();
29
-
30
- const Element = InputMapping.get(props.type);
31
-
32
- if (!Element) return null;
33
-
34
- return createElement(Element, props);
35
- };
@@ -1,27 +0,0 @@
1
- export type INPUT_COMPONENTS_KEYS =
2
- | 'checkbox'
3
- | 'date'
4
- | 'select'
5
- | 'radio'
6
- | 'switch'
7
- | 'textarea'
8
- | 'number'
9
- | 'file'
10
- | 'text'
11
- | 'fallback';
12
-
13
- export interface ParsedField<AdditionalRenderable, FieldTypes = string> {
14
- key: string;
15
- type: string;
16
- required: boolean;
17
- default?: any;
18
- fieldConfig?: FieldConfig<AdditionalRenderable, FieldTypes>;
19
-
20
- // Field-specific
21
- options?: [string, string][]; // [value, label] for enums
22
- schema?: ParsedField<AdditionalRenderable, FieldTypes>[]; // For objects and arrays
23
- }
24
-
25
- export type FieldConfig<AdditionalRenderable = object, FieldTypes = string> = {
26
- fieldType?: FieldTypes;
27
- } & AdditionalRenderable;
@@ -1,30 +0,0 @@
1
- import { useReducer, useRef } from 'react';
2
- import { useContext } from 'use-context-selector';
3
- import { InputMapping } from './class';
4
- import { InputMappingContext } from './context';
5
-
6
- export const useInputMapping = () => {
7
- const initialState = useContext(InputMappingContext);
8
- const mapRef = useRef(initialState);
9
- const [, reRender] = useReducer((x) => x + 1, 0);
10
-
11
- mapRef.current.set = (...args) => {
12
- InputMapping.prototype.set.apply(mapRef.current, args);
13
- reRender();
14
- return mapRef.current;
15
- };
16
-
17
- mapRef.current.clear = (...args) => {
18
- InputMapping.prototype.clear.apply(mapRef.current, args);
19
- reRender();
20
- };
21
-
22
- mapRef.current.delete = (...args) => {
23
- const res = InputMapping.prototype.delete.apply(mapRef.current, args);
24
- reRender();
25
-
26
- return res;
27
- };
28
-
29
- return mapRef.current;
30
- };
package/src/global.d.ts DELETED
@@ -1,13 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- export * from './InputMapping';