@twintag/twintag-form 0.4.1 → 0.5.0

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.
Files changed (75) hide show
  1. package/.turbo/turbo-build.log +10 -54
  2. package/CHANGELOG.md +23 -0
  3. package/README.md +9 -5
  4. package/dist/components/Category/__styles.d.ts +19 -0
  5. package/dist/{lib/components → components}/Category/index.d.ts +2 -3
  6. package/dist/components/Form/index.d.ts +12 -0
  7. package/dist/{lib/types/index.d.ts → components/Input/__props.d.ts} +0 -6
  8. package/dist/components/Input/__styles.d.ts +245 -0
  9. package/dist/{lib/components → components}/Input/checkbox.d.ts +2 -3
  10. package/dist/{lib/components → components}/Input/file.d.ts +2 -3
  11. package/dist/{lib/components → components}/Input/index.d.ts +0 -1
  12. package/dist/{lib/components → components}/Input/simple.d.ts +2 -3
  13. package/dist/{lib/components → components}/Input/submit.d.ts +2 -3
  14. package/dist/{lib/components → components}/Input/textarea.d.ts +2 -3
  15. package/dist/{lib/components → components}/Input/toggle.d.ts +2 -3
  16. package/dist/{lib/components → components}/Label/index.d.ts +0 -1
  17. package/dist/components/index.d.ts +4 -0
  18. package/dist/index.d.ts +14 -0
  19. package/dist/react.d.ts +1 -0
  20. package/dist/styles.d.ts +262 -0
  21. package/dist/twintag-form.react.js +8658 -0
  22. package/dist/twintag-form.webcomponent.js +4503 -0
  23. package/dist/webcomponent.d.ts +1 -0
  24. package/lib/__stories__/Form.stories.tsx +102 -10
  25. package/lib/components/Category/__styles.ts +12 -0
  26. package/lib/components/Category/index.tsx +5 -8
  27. package/lib/components/Form/index.tsx +33 -34
  28. package/lib/{types/index.ts → components/Input/__props.ts} +0 -6
  29. package/lib/components/Input/__styles.ts +132 -0
  30. package/lib/components/Input/checkbox.tsx +8 -11
  31. package/lib/components/Input/file.tsx +9 -12
  32. package/lib/components/Input/simple.tsx +8 -10
  33. package/lib/components/Input/submit.tsx +3 -9
  34. package/lib/components/Input/textarea.tsx +8 -10
  35. package/lib/components/Input/toggle.tsx +10 -11
  36. package/lib/components/Label/index.tsx +2 -1
  37. package/lib/components/index.tsx +4 -6
  38. package/lib/index.tsx +35 -157
  39. package/lib/styles.ts +2 -1
  40. package/lib/webcomponent.ts +1 -1
  41. package/package.json +11 -14
  42. package/tsconfig.json +3 -2
  43. package/vite.config.ts +47 -0
  44. package/dist/index.es.js +0 -27362
  45. package/dist/index.umd.js +0 -196
  46. package/dist/lib/__stories__/Form.stories.d.ts +0 -7
  47. package/dist/lib/__stories__/Form.stories.d.ts.map +0 -1
  48. package/dist/lib/components/Category/index.d.ts.map +0 -1
  49. package/dist/lib/components/Form/index.d.ts +0 -10
  50. package/dist/lib/components/Form/index.d.ts.map +0 -1
  51. package/dist/lib/components/Form/register.d.ts +0 -12
  52. package/dist/lib/components/Form/register.d.ts.map +0 -1
  53. package/dist/lib/components/Input/checkbox.d.ts.map +0 -1
  54. package/dist/lib/components/Input/file.d.ts.map +0 -1
  55. package/dist/lib/components/Input/index.d.ts.map +0 -1
  56. package/dist/lib/components/Input/simple.d.ts.map +0 -1
  57. package/dist/lib/components/Input/submit.d.ts.map +0 -1
  58. package/dist/lib/components/Input/textarea.d.ts.map +0 -1
  59. package/dist/lib/components/Input/toggle.d.ts.map +0 -1
  60. package/dist/lib/components/Label/index.d.ts.map +0 -1
  61. package/dist/lib/components/index.d.ts +0 -6
  62. package/dist/lib/components/index.d.ts.map +0 -1
  63. package/dist/lib/index.d.ts +0 -20
  64. package/dist/lib/index.d.ts.map +0 -1
  65. package/dist/lib/styles.d.ts +0 -131
  66. package/dist/lib/styles.d.ts.map +0 -1
  67. package/dist/lib/types/index.d.ts.map +0 -1
  68. package/dist/lib/webcomponent.d.ts +0 -2
  69. package/dist/lib/webcomponent.d.ts.map +0 -1
  70. package/dist/twind.config.d.ts +0 -5
  71. package/dist/twind.config.d.ts.map +0 -1
  72. package/dist/webcomponent.es.js +0 -31726
  73. package/dist/webcomponent.umd.js +0 -196
  74. package/lib/components/Form/register.tsx +0 -69
  75. package/scripts/build.js +0 -60
package/lib/index.tsx CHANGED
@@ -1,178 +1,56 @@
1
- import type { FC, ReactNode } from 'react';
1
+ import type { ComponentRef, Ref } from 'react';
2
+ import type { RawJsonComponent } from '@twintag/twintag-json-renderer/types';
2
3
 
3
- import { LabelToString } from 'twintag-types/dom';
4
+ import { forwardRef } from 'react';
4
5
 
5
6
  import Form from '@twintag-form/components/Form';
6
7
  import Input from '@twintag-form/components/Input';
7
8
  import Category from '@twintag-form/components/Category';
8
9
 
9
- type Config = {
10
- key?: number;
11
- type?: any;
12
- subtype?: string;
13
- label?: string;
14
- items?: any[];
15
- bind?: string;
16
- options?: Record<string, any>;
17
- };
18
-
19
- type Component = {
20
- subtype?: string;
21
- label?: string;
22
- bind?: string;
23
- children?: ReactNode;
24
- options?: Record<string, any>;
25
- };
26
-
27
- type Format = {
28
- $config: Config;
29
- $blocks?: Map<string, FC<Component>>;
30
- $containers?: Map<string, FC<Component>>;
31
- $available?: Map<string, FC<Component>>;
32
- };
33
-
34
- const format = ({ $config, $blocks, $containers, $available }: Format) => {
35
- const config: Config & {
36
- block?: FC<Component>;
37
- container?: FC<Component>;
38
- } = { ...$config };
39
-
40
- const typeLength = config.type.length;
41
- const colonIndex = config.type.indexOf(':');
42
-
43
- const typeFiltered = config.type.substring(
44
- 0,
45
- colonIndex > 0 ? config.type.lastIndexOf(':') : typeLength + 1
46
- );
47
- const subtypeFiltered =
48
- colonIndex > 0 && colonIndex + 1 !== typeLength
49
- ? config.type.substring(colonIndex + 1, typeLength + 1)
50
- : undefined;
51
-
52
- const isTypeAvailable = $available?.has(typeFiltered);
53
-
54
- if (isTypeAvailable) {
55
- const block = $blocks?.get(typeFiltered);
56
- const container = $containers?.get(typeFiltered);
57
-
58
- config.type = typeFiltered;
59
- config.subtype = config.subtype ? config.subtype : subtypeFiltered;
60
- config.block = block;
61
- config.container = container;
62
- }
63
-
64
- if (config.label) config.label = LabelToString.parse(config.label);
65
-
66
- if (config.items && Array.isArray(config.items))
67
- config.items = config.items.map((item) =>
68
- format({
69
- $config: item,
70
- $available,
71
- $blocks,
72
- $containers,
73
- })
74
- );
75
-
76
- return config;
77
- };
78
-
79
- type Params = {
80
- $config: Config;
81
- $blocks?: Map<string, FC<Component>>;
82
- $containers?: Map<string, FC<Component>>;
83
- };
84
-
85
- const useConfig = (params: Params) => {
86
- const available = new Map([
87
- ...new Map(params.$blocks),
88
- ...new Map(params.$containers),
89
- ]);
90
-
91
- return format({
92
- ...params,
93
- $available: available,
94
- });
95
- };
10
+ import {
11
+ TwintagJsonRenderer,
12
+ TwintagJsonRegisterProvider,
13
+ } from '@twintag/twintag-json-renderer';
96
14
 
97
15
  const blocks = new Map().set('input', Input);
98
- const containers = new Map().set('form', Form).set('category', Category);
16
+ const containers = new Map().set('category', Category);
99
17
 
100
- type RendererProps = {
101
- config: Config & {
102
- block?: FC<Component>;
103
- container?: FC<Component>;
18
+ type Props = {
19
+ config: RawJsonComponent[];
20
+ options?: {
21
+ variant?: string;
22
+ resetOnSubmit?: boolean;
104
23
  };
105
24
  };
106
25
 
107
- const FormRenderer: FC<RendererProps> = ({ config }) => {
108
- const { key, type, subtype, label, bind, items, block, container, ...rest } =
109
- config;
110
-
111
- if (!type) return null;
112
-
113
- if (container) {
114
- const Component = container;
115
-
26
+ export const TwintagForm = forwardRef(
27
+ ({ config, options }: Props, ref: Ref<ComponentRef<typeof Form>>) => {
116
28
  return (
117
- <Component key={key} subtype={subtype} label={label} {...rest}>
118
- {items && Array.isArray(items) ? (
119
- items.map((item, idx) => (
120
- <FormRenderer
29
+ <TwintagJsonRegisterProvider
30
+ register={{
31
+ blocks,
32
+ containers,
33
+ custom: new Map(),
34
+ }}
35
+ >
36
+ <Form ref={ref} options={options}>
37
+ {config.map((item, idx) => (
38
+ <TwintagJsonRenderer
121
39
  key={idx}
122
40
  config={{
123
- ...rest,
124
41
  ...item,
125
- options: {
126
- ...item.options,
127
- variant: rest.options?.variant,
42
+ props: {
43
+ ...item.props,
44
+ options: {
45
+ ...item.props.options,
46
+ variant: options?.variant,
47
+ },
128
48
  },
129
49
  }}
130
50
  />
131
- ))
132
- ) : (
133
- <></>
134
- )}
135
- </Component>
136
- );
137
- }
138
-
139
- if (block) {
140
- const Component = block;
141
-
142
- return (
143
- <Component
144
- key={key}
145
- subtype={subtype}
146
- label={label}
147
- bind={bind}
148
- {...rest}
149
- />
51
+ ))}
52
+ </Form>
53
+ </TwintagJsonRegisterProvider>
150
54
  );
151
55
  }
152
-
153
- return null;
154
- };
155
-
156
- type Props = {
157
- config: Config[];
158
- options?: {
159
- variant?: string;
160
- resetOnSubmit?: boolean;
161
- };
162
- };
163
-
164
- const TwintagForm: FC<Props> = ({ config, options }) => {
165
- const __config = useConfig({
166
- $blocks: blocks,
167
- $containers: containers,
168
- $config: {
169
- type: 'form',
170
- items: config ? config : [],
171
- options,
172
- },
173
- });
174
-
175
- return <FormRenderer config={__config} />;
176
- };
177
-
178
- export default TwintagForm;
56
+ );
package/lib/styles.ts CHANGED
@@ -76,7 +76,8 @@ export const simpleStyle = tv({
76
76
  className: 'w-full',
77
77
  }),
78
78
  span: '',
79
- input: 'w-full ring-0 placeholder:text-placeholder focus:ring-0 border-2 border-transparent text-input',
79
+ input:
80
+ 'w-full ring-0 placeholder:text-placeholder focus:ring-0 border-2 border-transparent text-input',
80
81
  },
81
82
  variants: {
82
83
  variant: {
@@ -3,7 +3,7 @@ import r2wc from '@r2wc/react-to-web-component';
3
3
 
4
4
  import config from '../twind.config';
5
5
 
6
- import TwintagForm from './index';
6
+ import { TwintagForm } from '@twintag-form/index';
7
7
 
8
8
  const withTwind = install(config);
9
9
 
package/package.json CHANGED
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "name": "@twintag/twintag-form",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "author": "Twintag",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./dist/index.es.js",
9
- "require": "./dist/index.umd.js",
10
- "types": "./dist/index.d.ts"
8
+ "import": "./dist/twintag-form.react.js",
9
+ "types": "./dist/react.d.ts"
11
10
  },
12
11
  "./webcomponent": {
13
- "import": "./dist/webcomponent.es.js",
14
- "require": "./dist/webcomponent.umd.js",
12
+ "import": "./dist/twintag-form.webcomponent.js",
15
13
  "types": "./dist/webcomponent.d.ts"
16
14
  }
17
15
  },
@@ -29,7 +27,8 @@
29
27
  "@twind/with-web-components": "^1.1.3",
30
28
  "react": "^18.2.0",
31
29
  "react-dom": "^18.2.0",
32
- "react-hook-form": "^7.43.1"
30
+ "react-hook-form": "^7.43.1",
31
+ "@twintag/twintag-json-renderer": "0.1.0"
33
32
  },
34
33
  "devDependencies": {
35
34
  "@rollup/plugin-typescript": "^11.1.1",
@@ -38,18 +37,16 @@
38
37
  "@types/react-dom": "^18.0.11",
39
38
  "eslint": "^8.38.0",
40
39
  "rollup": "^3.18.0",
41
- "vite-plugin-dts": "^2.1.0",
42
- "tailwind-config": "0.0.1",
40
+ "vite-plugin-dts": "^3.0.3",
41
+ "tailwind-config": "0.1.0",
43
42
  "tsconfig": "0.0.0",
44
- "twintag-types": "0.0.0"
43
+ "twintag-types": "0.1.0"
45
44
  },
46
45
  "publishConfig": {
47
46
  "access": "public"
48
47
  },
49
48
  "scripts": {
50
- "dev": "vite",
51
- "build": "tsc && node ./scripts/build.js",
52
- "lint": "eslint lib --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
53
- "preview": "vite preview"
49
+ "build": "tsc && vite build",
50
+ "lint": "eslint lib --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
54
51
  }
55
52
  }
package/tsconfig.json CHANGED
@@ -3,11 +3,12 @@
3
3
  "include": ["lib", "types.d.ts", "scripts"],
4
4
  "exclude": ["dist"],
5
5
  "compilerOptions": {
6
+ "moduleResolution": "Bundler",
7
+ "declaration": true,
8
+ "declarationMap": false,
6
9
  "baseUrl": ".",
7
10
  "paths": {
8
11
  "@twintag-form/*": ["./lib/*"]
9
12
  },
10
- "outDir": "./dist",
11
- "declaration": true
12
13
  }
13
14
  }
package/vite.config.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { resolve } from 'pathe';
2
+ import { defineConfig } from 'vite';
3
+ import react from '@vitejs/plugin-react-swc';
4
+ import dts from 'vite-plugin-dts';
5
+
6
+ // https://vitejs.dev/config/
7
+ export default defineConfig({
8
+ resolve: {
9
+ alias: {
10
+ '@twintag-form': resolve(__dirname, './lib'),
11
+ },
12
+ },
13
+ build: {
14
+ lib: {
15
+ // Could also be a dictionary or array of multiple entry points
16
+ entry: {
17
+ react: resolve(__dirname, './lib/index.tsx'),
18
+ webcomponent: resolve(__dirname, './lib/webcomponent.ts'),
19
+ },
20
+ name: 'twintag-form',
21
+ formats: ['es'],
22
+ // the proper extensions will be added
23
+ fileName: (_, entryName) => `twintag-form.${entryName}.js`,
24
+ },
25
+ rollupOptions: {
26
+ // make sure to externalize deps that shouldn't be bundled
27
+ // into your library
28
+ external: ['react', 'react-dom'],
29
+ output: {
30
+ // Provide global variables to use in the UMD build
31
+ // for externalized deps
32
+ globals: {
33
+ react: 'React',
34
+ },
35
+ },
36
+ },
37
+ },
38
+ plugins: [
39
+ react(),
40
+ dts({
41
+ entryRoot: resolve(__dirname, 'lib'),
42
+ insertTypesEntry: true,
43
+ staticImport: true,
44
+ exclude: ['**/__tests__/**', '**/__stories__/**'],
45
+ }),
46
+ ],
47
+ });