autoforma 1.0.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 (105) hide show
  1. package/.github/workflows/npm_test.yml +27 -0
  2. package/.nvmrc +1 -0
  3. package/.prettierrc.mjs +35 -0
  4. package/.storybook/main.ts +17 -0
  5. package/.storybook/preview.tsx +18 -0
  6. package/.storybook/vitest.setup.ts +9 -0
  7. package/.stylelintignore +1 -0
  8. package/.stylelintrc.json +28 -0
  9. package/.yarn/releases/yarn-4.9.1.cjs +948 -0
  10. package/.yarnrc.yml +3 -0
  11. package/README.md +157 -0
  12. package/eslint.config.js +11 -0
  13. package/index.html +16 -0
  14. package/package.json +87 -0
  15. package/postcss.config.cjs +14 -0
  16. package/src/components/AutoForm.tsx +201 -0
  17. package/src/components/FieldRender.tsx +217 -0
  18. package/src/components/fields/ArrayField.tsx +59 -0
  19. package/src/components/fields/CheckField.tsx +23 -0
  20. package/src/components/fields/DateField.tsx +26 -0
  21. package/src/components/fields/DateTimeField.tsx +26 -0
  22. package/src/components/fields/NumberField.tsx +20 -0
  23. package/src/components/fields/ObjectField.tsx +41 -0
  24. package/src/components/fields/SelectField.tsx +23 -0
  25. package/src/components/fields/TextAreaField.tsx +25 -0
  26. package/src/components/fields/TextField.tsx +20 -0
  27. package/src/components/fields/TimeField.tsx +32 -0
  28. package/src/favicon.svg +1 -0
  29. package/src/index.ts +3 -0
  30. package/src/stories/AutoForm.stories.tsx +473 -0
  31. package/src/stories/Fields.stories.tsx +190 -0
  32. package/src/theme.ts +5 -0
  33. package/src/types/custom-render.ts +22 -0
  34. package/src/types/field.ts +32 -0
  35. package/src/types/form.ts +8 -0
  36. package/src/vite-env.d.ts +1 -0
  37. package/storybook-static/assets/AutoForm-CEr4m2za.js +53 -0
  38. package/storybook-static/assets/AutoForm.stories-CtOmRKOV.js +164 -0
  39. package/storybook-static/assets/Color-YHDXOIA2-pc5-Ao7n.js +1 -0
  40. package/storybook-static/assets/DocsRenderer-CFRXHY34-D-_1VvMG.js +575 -0
  41. package/storybook-static/assets/Fields.stories-CoRkpMbJ.js +29 -0
  42. package/storybook-static/assets/chunk-XP5HYGXS-BpfKkqn7.js +1 -0
  43. package/storybook-static/assets/entry-preview-CkHoqRUh.js +2 -0
  44. package/storybook-static/assets/entry-preview-docs-hFR7sEJd.js +46 -0
  45. package/storybook-static/assets/get-contrast-color-Db6nT3bs.js +1 -0
  46. package/storybook-static/assets/iframe-CzpwBD2i.js +211 -0
  47. package/storybook-static/assets/index-B8rYRX2K.js +1 -0
  48. package/storybook-static/assets/index-BQQLSK9g.js +1 -0
  49. package/storybook-static/assets/index-CXQShRbs.js +8 -0
  50. package/storybook-static/assets/index-D4lIrffr.js +9 -0
  51. package/storybook-static/assets/index-Domkg0jQ.js +240 -0
  52. package/storybook-static/assets/index-DrFu-skq.js +6 -0
  53. package/storybook-static/assets/index-DsJinFGm.js +9 -0
  54. package/storybook-static/assets/jsx-runtime-D_zvdyIk.js +9 -0
  55. package/storybook-static/assets/preview-B8lJiyuQ.js +34 -0
  56. package/storybook-static/assets/preview-BBWR9nbA.js +1 -0
  57. package/storybook-static/assets/preview-BOfrPh1e.js +2 -0
  58. package/storybook-static/assets/preview-BWzBA1C2.js +396 -0
  59. package/storybook-static/assets/preview-C2Qr78FS.js +4 -0
  60. package/storybook-static/assets/preview-CvbIS5ZJ.js +1 -0
  61. package/storybook-static/assets/preview-DD_OYowb.js +1 -0
  62. package/storybook-static/assets/preview-DGUiP6tS.js +7 -0
  63. package/storybook-static/assets/preview-DioFdWiE.css +1 -0
  64. package/storybook-static/assets/preview-Dyg8NwXV.js +1 -0
  65. package/storybook-static/assets/react-18-Dhjvimrl.js +25 -0
  66. package/storybook-static/assets/test-utils--_O2wM1y.js +9 -0
  67. package/storybook-static/favicon.svg +1 -0
  68. package/storybook-static/iframe.html +666 -0
  69. package/storybook-static/index.html +181 -0
  70. package/storybook-static/index.json +1 -0
  71. package/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
  72. package/storybook-static/nunito-sans-bold.woff2 +0 -0
  73. package/storybook-static/nunito-sans-italic.woff2 +0 -0
  74. package/storybook-static/nunito-sans-regular.woff2 +0 -0
  75. package/storybook-static/project.json +1 -0
  76. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js +331 -0
  77. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js.LEGAL.txt +51 -0
  78. package/storybook-static/sb-addons/docs-11/manager-bundle.js +242 -0
  79. package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js +3 -0
  80. package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js +12 -0
  81. package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js +402 -0
  82. package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js +3 -0
  83. package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js +3 -0
  84. package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js +3 -0
  85. package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js +3 -0
  86. package/storybook-static/sb-addons/onboarding-8/manager-bundle.js +127 -0
  87. package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js +3 -0
  88. package/storybook-static/sb-addons/storybook-experimental-addon-test-10/manager-bundle.js +223 -0
  89. package/storybook-static/sb-common-assets/favicon.svg +1 -0
  90. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  91. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  92. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  93. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  94. package/storybook-static/sb-manager/globals-module-info.js +1051 -0
  95. package/storybook-static/sb-manager/globals-runtime.js +41591 -0
  96. package/storybook-static/sb-manager/globals.js +48 -0
  97. package/storybook-static/sb-manager/runtime.js +12048 -0
  98. package/test-utils/index.ts +5 -0
  99. package/test-utils/render.tsx +11 -0
  100. package/text +64 -0
  101. package/tsconfig.json +25 -0
  102. package/vite.config.mjs +19 -0
  103. package/vitest.setup.mjs +29 -0
  104. package/vitest.shims.d.ts +1 -0
  105. package/vitest.workspace.js +30 -0
@@ -0,0 +1,5 @@
1
+ import userEvent from '@testing-library/user-event';
2
+
3
+ export * from '@testing-library/react';
4
+ export { render } from './render';
5
+ export { userEvent };
@@ -0,0 +1,11 @@
1
+ import { render as testingLibraryRender } from '@testing-library/react';
2
+ import { MantineProvider } from '@mantine/core';
3
+ import { theme } from '../src/theme';
4
+
5
+ export function render(ui: React.ReactNode) {
6
+ return testingLibraryRender(ui, {
7
+ wrapper: ({ children }: { children: React.ReactNode }) => (
8
+ <MantineProvider theme={theme}>{children}</MantineProvider>
9
+ ),
10
+ });
11
+ }
package/text ADDED
@@ -0,0 +1,64 @@
1
+ customRender={(field, value, error, onParentChange, formValues, options) => {
2
+ if (field.type === 'object' && field?.fields) {
3
+ const onChange = (name: string, value: any) => {
4
+ onParentChange(`${field.name}.${name}`, value);
5
+ };
6
+
7
+ const parentName = field.name;
8
+
9
+ const fieldError: Record<string, React.ReactNode> =
10
+ error &&
11
+ typeof error === 'object' &&
12
+ !React.isValidElement(error) &&
13
+ !Array.isArray(error) &&
14
+ !(error instanceof Promise)
15
+ ? (error as Record<string, React.ReactNode>)
16
+ : {};
17
+
18
+ const content = field?.fields.map((field, index) => (
19
+ <Grid.Col key={index} span={{ base: 12, md: 6 }}>
20
+ <FieldRender
21
+ key={index}
22
+ field={field}
23
+ formValues={formValues}
24
+ onChange={onChange}
25
+ error={fieldError[`${parentName}.${field.name}`]}
26
+ value={value[field.name]}
27
+ />
28
+ </Grid.Col>
29
+ ));
30
+
31
+ return (
32
+ <>
33
+ <Accordion
34
+ defaultValue={field.name}
35
+ variant="contained"
36
+ styles={{
37
+ root: {
38
+ border:
39
+ typeof error === 'object' && Object.keys(fieldError).length
40
+ ? 'red 1px solid'
41
+ : undefined,
42
+ },
43
+ }}
44
+ >
45
+ <Accordion.Item value={field.name}>
46
+ <Accordion.Control
47
+ styles={{
48
+ label: {
49
+ visibility: 'hidden',
50
+ },
51
+ }}
52
+ >
53
+ {field.label}
54
+ </Accordion.Control>
55
+ <Accordion.Panel>
56
+ <Grid>{content}</Grid>
57
+ </Accordion.Panel>
58
+ </Accordion.Item>
59
+ </Accordion>
60
+ </>
61
+ );
62
+ }
63
+ return null;
64
+ }}
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "types": ["node", "@testing-library/jest-dom", "vitest/globals"],
4
+ "target": "ESNext",
5
+ "useDefineForClassFields": true,
6
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
7
+ "allowJs": false,
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": false,
10
+ "allowSyntheticDefaultImports": true,
11
+ "strict": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "module": "ESNext",
14
+ "moduleResolution": "Node",
15
+ "resolveJsonModule": true,
16
+ "isolatedModules": true,
17
+ "noEmit": true,
18
+ "jsx": "react-jsx",
19
+ "paths": {
20
+ "@/*": ["./src/*"],
21
+ "@test-utils": ["./test-utils"]
22
+ }
23
+ },
24
+ "include": ["src", "test-utils"]
25
+ }
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import dts from 'vite-plugin-dts';
4
+
5
+ export default defineConfig({
6
+ build: {
7
+ lib: {
8
+ entry: 'src/index.ts',
9
+ name: 'AutoForma',
10
+ formats: ['es', 'cjs'],
11
+ fileName: (format) => `index.${format}.js`,
12
+ },
13
+ rollupOptions: {
14
+ external: ['react', 'react-dom'],
15
+ },
16
+ outDir: 'dist',
17
+ },
18
+ plugins: [react(), dts()],
19
+ });
@@ -0,0 +1,29 @@
1
+ import '@testing-library/jest-dom/vitest';
2
+
3
+ import { vi } from 'vitest';
4
+
5
+ const { getComputedStyle } = window;
6
+ window.getComputedStyle = (elt) => getComputedStyle(elt);
7
+ window.HTMLElement.prototype.scrollIntoView = () => {};
8
+
9
+ Object.defineProperty(window, 'matchMedia', {
10
+ writable: true,
11
+ value: vi.fn().mockImplementation((query) => ({
12
+ matches: false,
13
+ media: query,
14
+ onchange: null,
15
+ addListener: vi.fn(),
16
+ removeListener: vi.fn(),
17
+ addEventListener: vi.fn(),
18
+ removeEventListener: vi.fn(),
19
+ dispatchEvent: vi.fn(),
20
+ })),
21
+ });
22
+
23
+ class ResizeObserver {
24
+ observe() {}
25
+ unobserve() {}
26
+ disconnect() {}
27
+ }
28
+
29
+ window.ResizeObserver = ResizeObserver;
@@ -0,0 +1 @@
1
+ /// <reference types="@vitest/browser/providers/playwright" />
@@ -0,0 +1,30 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin';
4
+ import { defineWorkspace } from 'vitest/config';
5
+
6
+ const dirname =
7
+ typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url));
8
+
9
+ // More info at: https://storybook.js.org/docs/writing-tests/test-addon
10
+ export default defineWorkspace([
11
+ 'vite.config.mjs',
12
+ {
13
+ extends: 'vite.config.mjs',
14
+ plugins: [
15
+ // The plugin will run tests for the stories defined in your Storybook config
16
+ // See options at: https://storybook.js.org/docs/writing-tests/test-addon#storybooktest
17
+ storybookTest({ configDir: path.join(dirname, '.storybook') }),
18
+ ],
19
+ test: {
20
+ name: 'storybook',
21
+ browser: {
22
+ enabled: true,
23
+ headless: true,
24
+ provider: 'playwright',
25
+ instances: [{ browser: 'chromium' }],
26
+ },
27
+ setupFiles: ['.storybook/vitest.setup.ts'],
28
+ },
29
+ },
30
+ ]);