@twintag/twintag-form 1.6.2-beta.1 → 1.6.2

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/lib/index.tsx CHANGED
@@ -1,45 +1,45 @@
1
- import type { ComponentProps } from 'react';
2
- import type { RawJsonComponent } from '@twintag/twintag-form/types';
3
-
4
- import { forwardRef } from 'react';
5
-
6
- import { components, Inputs } from '@twintag/twintag-form/components/config';
7
- import { TwintagForm } from '@twintag/twintag-form/components/form';
8
- import { TwintagFormProvider } from '@twintag/twintag-form/components/provider';
9
- import { JsonRenderer } from '@twintag/twintag-form/components/renderer';
10
-
11
- type Props = {
12
- config: RawJsonComponent[];
13
- options?: Partial<{
14
- defaultValues: ComponentProps<typeof TwintagForm>['defaultValues'];
15
- variant: ComponentProps<typeof TwintagFormProvider>['variant'];
16
- size: ComponentProps<typeof TwintagFormProvider>['size'];
17
- resetOnSubmit?: boolean;
18
- acceptFileType?: ComponentProps<
19
- typeof TwintagFormProvider
20
- >['acceptFileType'];
21
- }>;
22
- };
23
-
24
- export const Form = forwardRef<HTMLFormElement, Props>(
25
- ({ config, options }, ref) => {
26
- return (
27
- <TwintagFormProvider
28
- inputs={Inputs}
29
- components={components}
30
- variant={options?.variant}
31
- size={options?.size}
32
- config={config}
33
- acceptFileType={options?.acceptFileType}
34
- >
35
- <TwintagForm
36
- ref={ref}
37
- defaultValues={options?.defaultValues}
38
- resetOnSubmit={options?.resetOnSubmit}
39
- >
40
- <JsonRenderer />
41
- </TwintagForm>
42
- </TwintagFormProvider>
43
- );
44
- },
45
- );
1
+ import type { ComponentProps } from 'react';
2
+ import type { RawJsonComponent } from '@twintag/twintag-form/types';
3
+
4
+ import { forwardRef } from 'react';
5
+
6
+ import { components, Inputs } from '@twintag/twintag-form/components/config';
7
+ import { TwintagForm } from '@twintag/twintag-form/components/form';
8
+ import { TwintagFormProvider } from '@twintag/twintag-form/components/provider';
9
+ import { JsonRenderer } from '@twintag/twintag-form/components/renderer';
10
+
11
+ type Props = {
12
+ config: RawJsonComponent[];
13
+ options?: Partial<{
14
+ defaultValues: ComponentProps<typeof TwintagForm>['defaultValues'];
15
+ variant: ComponentProps<typeof TwintagFormProvider>['variant'];
16
+ size: ComponentProps<typeof TwintagFormProvider>['size'];
17
+ resetOnSubmit?: boolean;
18
+ acceptFileType?: ComponentProps<
19
+ typeof TwintagFormProvider
20
+ >['acceptFileType'];
21
+ }>;
22
+ };
23
+
24
+ export const Form = forwardRef<HTMLFormElement, Props>(
25
+ ({ config, options }, ref) => {
26
+ return (
27
+ <TwintagFormProvider
28
+ inputs={Inputs}
29
+ components={components}
30
+ variant={options?.variant}
31
+ size={options?.size}
32
+ config={config}
33
+ acceptFileType={options?.acceptFileType}
34
+ >
35
+ <TwintagForm
36
+ ref={ref}
37
+ defaultValues={options?.defaultValues}
38
+ resetOnSubmit={options?.resetOnSubmit}
39
+ >
40
+ <JsonRenderer />
41
+ </TwintagForm>
42
+ </TwintagFormProvider>
43
+ );
44
+ },
45
+ );
@@ -1,102 +1,102 @@
1
- import type { ElementType } from 'react';
2
-
3
- export type InputCompConfig = {
4
- defaultValue?: unknown;
5
- component: ElementType;
6
- };
7
-
8
- type BaseInputOptions = Partial<{
9
- description: string;
10
- error: string;
11
- optionalField: boolean;
12
- }>;
13
-
14
- type TextInputOptions = BaseInputOptions & {
15
- placeholder?: string;
16
- };
17
-
18
- type DatePickerInputOptions = BaseInputOptions & {
19
- placeholder?: string;
20
- };
21
-
22
- type FileInputOptions = BaseInputOptions & {
23
- accept?: string;
24
- };
25
-
26
- type CompType = 'input' | 'item' | 'accordion' | 'category';
27
- type StringLiteral<T> = T extends string
28
- ? string extends T
29
- ? never
30
- : T
31
- : never;
32
-
33
- type RawProps<
34
- TType extends string = string,
35
- TSubtype extends string = string,
36
- > = TType extends 'input' | 'item'
37
- ? {
38
- type: TType;
39
- bind: string;
40
- label?: string;
41
- subtype?: string;
42
- options?: TSubtype extends 'text' | 'textarea'
43
- ? TextInputOptions
44
- : TSubtype extends 'datepicker'
45
- ? DatePickerInputOptions
46
- : TSubtype extends 'file'
47
- ? FileInputOptions
48
- : BaseInputOptions;
49
- }
50
- : TType extends 'accordion'
51
- ? TSubtype extends 'item'
52
- ? {
53
- type: TType;
54
- subtype: TSubtype;
55
- value?: string;
56
- label: string;
57
- icon: string;
58
- }
59
- : TSubtype extends 'multiple' | 'single'
60
- ? { type: TType; subtype: TSubtype; defaultValue?: string }
61
- : never
62
- : {
63
- type: TType;
64
- label?: string;
65
- subtype?: string;
66
- };
67
-
68
- export type RawJsonComponent = CompType extends infer T
69
- ? T extends CompType
70
- ? {
71
- type: StringLiteral<T>;
72
- props?: Omit<RawProps<StringLiteral<T>>, 'type'>;
73
- children?: RawJsonComponent[];
74
- }
75
- : never
76
- : never;
77
-
78
- export type ParsedJsonComponent<TType extends string = string> =
79
- RawProps<TType> & {
80
- id: string;
81
- type: string;
82
- subtype?: string;
83
- comp?: ElementType;
84
- items?: ParsedJsonComponent[];
85
- };
86
-
87
- export type Props<
88
- TType extends string = string,
89
- TSubtype extends string = string,
90
- > = Omit<RawProps<TType, TSubtype>, 'type'> & {
91
- items?: (Props<'input'> & ParsedJsonComponent)[];
92
- };
93
-
94
- export type TwintagFormContext = {
95
- variant?: 'default' | 'outline';
96
- size?: 'base' | 'sm';
97
- inputs: Map<string, InputCompConfig>;
98
- components: Map<string, ElementType>;
99
- config: ParsedJsonComponent[] | ParsedJsonComponent;
100
- resetValues: Record<string, unknown>;
101
- acceptFileType?: string;
102
- };
1
+ import type { ElementType } from 'react';
2
+
3
+ export type InputCompConfig = {
4
+ defaultValue?: unknown;
5
+ component: ElementType;
6
+ };
7
+
8
+ type BaseInputOptions = Partial<{
9
+ description: string;
10
+ error: string;
11
+ optionalField: boolean;
12
+ }>;
13
+
14
+ type TextInputOptions = BaseInputOptions & {
15
+ placeholder?: string;
16
+ };
17
+
18
+ type DatePickerInputOptions = BaseInputOptions & {
19
+ placeholder?: string;
20
+ };
21
+
22
+ type FileInputOptions = BaseInputOptions & {
23
+ accept?: string;
24
+ };
25
+
26
+ type CompType = 'input' | 'item' | 'accordion' | 'category';
27
+ type StringLiteral<T> = T extends string
28
+ ? string extends T
29
+ ? never
30
+ : T
31
+ : never;
32
+
33
+ type RawProps<
34
+ TType extends string = string,
35
+ TSubtype extends string = string,
36
+ > = TType extends 'input' | 'item'
37
+ ? {
38
+ type: TType;
39
+ bind: string;
40
+ label?: string;
41
+ subtype?: string;
42
+ options?: TSubtype extends 'text' | 'textarea'
43
+ ? TextInputOptions
44
+ : TSubtype extends 'datepicker'
45
+ ? DatePickerInputOptions
46
+ : TSubtype extends 'file'
47
+ ? FileInputOptions
48
+ : BaseInputOptions;
49
+ }
50
+ : TType extends 'accordion'
51
+ ? TSubtype extends 'item'
52
+ ? {
53
+ type: TType;
54
+ subtype: TSubtype;
55
+ value?: string;
56
+ label: string;
57
+ icon: string;
58
+ }
59
+ : TSubtype extends 'multiple' | 'single'
60
+ ? { type: TType; subtype: TSubtype; defaultValue?: string }
61
+ : never
62
+ : {
63
+ type: TType;
64
+ label?: string;
65
+ subtype?: string;
66
+ };
67
+
68
+ export type RawJsonComponent = CompType extends infer T
69
+ ? T extends CompType
70
+ ? {
71
+ type: StringLiteral<T>;
72
+ props?: Omit<RawProps<StringLiteral<T>>, 'type'>;
73
+ children?: RawJsonComponent[];
74
+ }
75
+ : never
76
+ : never;
77
+
78
+ export type ParsedJsonComponent<TType extends string = string> =
79
+ RawProps<TType> & {
80
+ id: string;
81
+ type: string;
82
+ subtype?: string;
83
+ comp?: ElementType;
84
+ items?: ParsedJsonComponent[];
85
+ };
86
+
87
+ export type Props<
88
+ TType extends string = string,
89
+ TSubtype extends string = string,
90
+ > = Omit<RawProps<TType, TSubtype>, 'type'> & {
91
+ items?: (Props<'input'> & ParsedJsonComponent)[];
92
+ };
93
+
94
+ export type TwintagFormContext = {
95
+ variant?: 'default' | 'outline';
96
+ size?: 'base' | 'sm';
97
+ inputs: Map<string, InputCompConfig>;
98
+ components: Map<string, ElementType>;
99
+ config: ParsedJsonComponent[] | ParsedJsonComponent;
100
+ resetValues: Record<string, unknown>;
101
+ acceptFileType?: string;
102
+ };
@@ -1,9 +1,8 @@
1
1
  import r2wc from '@r2wc/react-to-web-component';
2
2
  import install from '@twind/with-web-components';
3
3
 
4
- import { Form } from './index';
5
-
6
4
  import config from '../twind.config';
5
+ import { Form } from './index';
7
6
 
8
7
  const withTwind = install(config);
9
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twintag/twintag-form",
3
- "version": "1.6.2-beta.1",
3
+ "version": "1.6.2",
4
4
  "author": "Twintag",
5
5
  "type": "module",
6
6
  "exports": {
package/vite.config.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { fileURLToPath } from 'node:url';
2
+
1
3
  import react from '@vitejs/plugin-react-swc';
2
4
  import { dirname, resolve } from 'pathe';
3
- import { fileURLToPath } from 'node:url'
4
5
  import { defineConfig } from 'vite';
5
6
  import dts from 'vite-plugin-dts';
6
7