@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.
- package/.out/.storybook/main.js +3 -1
- package/.out/core/mobx/specs/sub_form_field_adapters.tests.d.ts +1 -0
- package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +41 -0
- package/.out/core/mobx/sub_form_field_adapters.d.ts +7 -0
- package/.out/core/mobx/sub_form_field_adapters.js +8 -0
- package/.out/index.d.ts +1 -0
- package/.out/index.js +1 -0
- package/.out/mantine/create_sub_form.d.ts +6 -0
- package/.out/mantine/create_sub_form.js +40 -0
- package/.out/mantine/hooks.d.ts +5 -3
- package/.out/mantine/hooks.js +9 -0
- package/.out/mantine/specs/sub_form_hooks.stories.d.ts +15 -0
- package/.out/mantine/specs/sub_form_hooks.stories.js +107 -0
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/specs/list_fields_of_fields.tests.d.ts +1 -0
- package/.out/types/specs/list_fields_of_fields.tests.js +12 -0
- package/.out/types/specs/sub_form_fields.tests.d.ts +1 -0
- package/.out/types/specs/sub_form_fields.tests.js +12 -0
- package/.out/types/sub_form_fields.d.ts +7 -0
- package/.out/types/sub_form_fields.js +1 -0
- package/.storybook/main.ts +3 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/core/mobx/specs/sub_form_field_adapters.tests.ts +59 -0
- package/core/mobx/sub_form_field_adapters.ts +21 -0
- package/dist/index.cjs +241 -10302
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +258 -10333
- package/index.ts +1 -0
- package/mantine/create_sub_form.tsx +70 -0
- package/mantine/hooks.tsx +29 -6
- package/mantine/specs/sub_form_hooks.stories.tsx +135 -0
- package/package.json +5 -4
- package/types/specs/list_fields_of_fields.tests.ts +29 -0
- package/types/specs/sub_form_fields.tests.ts +22 -0
- 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 {};
|
package/.storybook/main.ts
CHANGED
|
@@ -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.
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -7,12 +7,12 @@ $ tsup
|
|
|
7
7
|
[34mCLI[39m Target: esnext
|
|
8
8
|
[34mCJS[39m Build start
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m46.90 KB[39m
|
|
11
|
+
[32mCJS[39m ⚡️ Build success in 104ms
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m43.20 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 106ms
|
|
10
14
|
[34mDTS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in 10720ms
|
|
16
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[32m34.05 KB[39m
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m34.05 KB[39m
|
|
18
|
-
Done in 12.03s.
|
|
15
|
+
[32mDTS[39m ⚡️ Build success in 9810ms
|
|
16
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m34.83 KB[39m
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m34.83 KB[39m
|
|
18
|
+
Done in 10.96s.
|
|
@@ -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
|
+
}
|