@strictly/react-form 0.0.2 → 0.0.4

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 (38) hide show
  1. package/.out/.storybook/main.js +3 -1
  2. package/.out/core/mobx/specs/sub_form_field_adapters.tests.d.ts +1 -0
  3. package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +41 -0
  4. package/.out/core/mobx/sub_form_field_adapters.d.ts +7 -0
  5. package/.out/core/mobx/sub_form_field_adapters.js +8 -0
  6. package/.out/index.d.ts +1 -0
  7. package/.out/index.js +1 -0
  8. package/.out/mantine/create_sub_form.d.ts +6 -0
  9. package/.out/mantine/create_sub_form.js +40 -0
  10. package/.out/mantine/hooks.d.ts +5 -3
  11. package/.out/mantine/hooks.js +9 -0
  12. package/.out/mantine/specs/sub_form_hooks.stories.d.ts +15 -0
  13. package/.out/mantine/specs/sub_form_hooks.stories.js +107 -0
  14. package/.out/tsconfig.tsbuildinfo +1 -1
  15. package/.out/types/specs/list_fields_of_fields.tests.d.ts +1 -0
  16. package/.out/types/specs/list_fields_of_fields.tests.js +12 -0
  17. package/.out/types/specs/sub_form_fields.tests.d.ts +1 -0
  18. package/.out/types/specs/sub_form_fields.tests.js +12 -0
  19. package/.out/types/sub_form_fields.d.ts +7 -0
  20. package/.out/types/sub_form_fields.js +1 -0
  21. package/.storybook/main.ts +3 -1
  22. package/.turbo/turbo-build.log +8 -8
  23. package/.turbo/turbo-check-types.log +1 -1
  24. package/.turbo/turbo-release$colon$exports.log +1 -1
  25. package/core/mobx/specs/sub_form_field_adapters.tests.ts +59 -0
  26. package/core/mobx/sub_form_field_adapters.ts +21 -0
  27. package/dist/index.cjs +241 -10302
  28. package/dist/index.d.cts +17 -4
  29. package/dist/index.d.ts +17 -4
  30. package/dist/index.js +258 -10333
  31. package/index.ts +1 -0
  32. package/mantine/create_sub_form.tsx +70 -0
  33. package/mantine/hooks.tsx +29 -6
  34. package/mantine/specs/sub_form_hooks.stories.tsx +135 -0
  35. package/package.json +5 -4
  36. package/types/specs/list_fields_of_fields.tests.ts +29 -0
  37. package/types/specs/sub_form_fields.tests.ts +22 -0
  38. package/types/sub_form_fields.ts +7 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ describe('ListFieldsOfFields', () => {
2
+ it('matches the expected type of an empty set of fields', () => {
3
+ expectTypeOf().toEqualTypeOf();
4
+ });
5
+ it('matches the expected type of a set of fields containing a single list', () => {
6
+ expectTypeOf().toEqualTypeOf();
7
+ });
8
+ it('matches the expected type of a set of fields containing a multiple fields, including a list', () => {
9
+ expectTypeOf().toEqualTypeOf();
10
+ });
11
+ });
12
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ describe('SubFormFields', () => {
2
+ it('works on single field', () => {
3
+ expectTypeOf().toEqualTypeOf();
4
+ });
5
+ it('works on more two fields', () => {
6
+ expectTypeOf().toEqualTypeOf();
7
+ });
8
+ it('works on subfields', () => {
9
+ expectTypeOf().toEqualTypeOf();
10
+ });
11
+ });
12
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type StringConcatOf } from '@strictly/base';
2
+ import { type Fields } from './field';
3
+ export type SubFormFields<F extends Fields, P extends keyof F> = P extends string ? {
4
+ [K in keyof F as K extends StringConcatOf<`${P}.`, infer S> ? `$.${S}` : never]: F[K];
5
+ } & {
6
+ $: F[P];
7
+ } : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,12 @@
1
1
  /* eslint-env node */
2
2
  import { type StorybookConfig } from '@storybook/react-vite'
3
+ import { createRequire } from 'module'
3
4
  import {
4
5
  dirname,
5
6
  join,
6
- } from 'path'
7
+ } from 'node:path'
7
8
 
9
+ const require = createRequire(import.meta.url)
8
10
  /**
9
11
  * This function is used to resolve the absolute path of a package.
10
12
  * It is needed in projects that use Yarn PnP or are set up within a monorepo.
@@ -7,12 +7,12 @@ $ tsup
7
7
  CLI Target: esnext
8
8
  CJS Build start
9
9
  ESM Build start
10
+ CJS dist/index.cjs 46.90 KB
11
+ CJS ⚡️ Build success in 104ms
12
+ ESM dist/index.js 43.20 KB
13
+ ESM ⚡️ Build success in 106ms
10
14
  DTS Build start
11
- CJS dist/index.cjs 373.16 KB
12
- CJS ⚡️ Build success in 1665ms
13
- ESM dist/index.js 363.03 KB
14
- ESM ⚡️ Build success in 1708ms
15
- DTS ⚡️ Build success in 10720ms
16
- DTS dist/index.d.cts 34.05 KB
17
- DTS dist/index.d.ts 34.05 KB
18
- Done in 12.03s.
15
+ DTS ⚡️ Build success in 9810ms
16
+ DTS dist/index.d.cts 34.83 KB
17
+ DTS dist/index.d.ts 34.83 KB
18
+ Done in 10.96s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ tsc
3
- Done in 7.83s.
3
+ Done in 7.63s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ json -f package.json -f package.exports.json --merge > package.release.json
3
- Done in 0.10s.
3
+ Done in 0.11s.
@@ -0,0 +1,59 @@
1
+ import { type FieldAdapter } from 'core/mobx/field_adapter'
2
+ import {
3
+ subFormFieldAdapters,
4
+ } from 'core/mobx/sub_form_field_adapters'
5
+ import { mockDeep } from 'vitest-mock-extended'
6
+
7
+ describe('subFormFieldAdapters', () => {
8
+ const fieldAdapter1: FieldAdapter<string, boolean> = mockDeep()
9
+ const fieldAdapter2: FieldAdapter<number, boolean> = mockDeep()
10
+
11
+ describe('empty value', () => {
12
+ const adapters = subFormFieldAdapters({}, '$.a')
13
+
14
+ it('equals expected type', () => {
15
+ expectTypeOf(adapters).toEqualTypeOf<{}>()
16
+ })
17
+
18
+ it('equals expected value', () => {
19
+ expect(adapters).toEqual({})
20
+ })
21
+ })
22
+
23
+ describe('single adapter', () => {
24
+ const adapters = subFormFieldAdapters({
25
+ $: fieldAdapter1,
26
+ }, '$.a')
27
+
28
+ it('equals expected type', () => {
29
+ expectTypeOf(adapters).toEqualTypeOf<{
30
+ '$.a': FieldAdapter<string, boolean>,
31
+ }>()
32
+ })
33
+
34
+ it('equals expected value', () => {
35
+ expect(adapters).toEqual({ '$.a': fieldAdapter1 })
36
+ })
37
+ })
38
+
39
+ describe('multiple adapters', () => {
40
+ const adapters = subFormFieldAdapters({
41
+ '$.x': fieldAdapter1,
42
+ '$.y': fieldAdapter2,
43
+ }, '$.a')
44
+
45
+ it('equals expected type', () => {
46
+ expectTypeOf(adapters).toEqualTypeOf<{
47
+ '$.a.x': FieldAdapter<string, boolean>,
48
+ '$.a.y': FieldAdapter<number, boolean>,
49
+ }>()
50
+ })
51
+
52
+ it('equals expected value', () => {
53
+ expect(adapters).toEqual({
54
+ '$.a.x': fieldAdapter1,
55
+ '$.a.y': fieldAdapter2,
56
+ })
57
+ })
58
+ })
59
+ })
@@ -0,0 +1,21 @@
1
+ import { type StringConcatOf } from '@strictly/base'
2
+ import { type FieldAdapter } from './field_adapter'
3
+
4
+ type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
5
+ [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K]
6
+ }
7
+
8
+ export function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(
9
+ subAdapters: SubAdapters,
10
+ prefix: P,
11
+ ): SubFormFieldAdapters<SubAdapters, P> {
12
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
13
+ return Object.entries(subAdapters).reduce<Record<string, FieldAdapter>>((acc, [
14
+ subKey,
15
+ subValue,
16
+ ]) => {
17
+ const key = subKey.replace('$', prefix)
18
+ acc[key] = subValue
19
+ return acc
20
+ }, {}) as SubFormFieldAdapters<SubAdapters, P>
21
+ }