@strictly/react-form 0.0.3 → 0.0.5
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/field_adapter_builder.d.ts +1 -1
- package/.out/core/mobx/field_adapter_builder.js +1 -2
- 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_list.d.ts +5 -4
- package/.out/mantine/create_list.js +4 -2
- 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 -2
- package/.out/mantine/hooks.js +9 -0
- package/.out/mantine/specs/list_hooks.stories.js +6 -6
- 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/field_adapter_builder.ts +3 -4
- 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 +86 -24
- package/dist/index.d.cts +22 -8
- package/dist/index.d.ts +22 -8
- package/dist/index.js +85 -24
- package/index.ts +1 -0
- package/mantine/create_list.tsx +10 -4
- package/mantine/create_sub_form.tsx +70 -0
- package/mantine/hooks.tsx +29 -5
- package/mantine/specs/__snapshots__/list_hooks.tests.tsx.snap +56 -8
- package/mantine/specs/list_hooks.stories.tsx +16 -6
- package/mantine/specs/sub_form_hooks.stories.tsx +135 -0
- package/package.json +1 -1
- 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
- package/.out/field_converters/list_converter.d.ts +0 -2
- package/.out/field_converters/list_converter.js +0 -13
- package/field_converters/list_converter.ts +0 -20
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Simplify } from 'type-fest'
|
|
2
|
+
import { type Field } from 'types/field'
|
|
3
|
+
import { type SubFormFields } from 'types/sub_form_fields'
|
|
4
|
+
|
|
5
|
+
describe('SubFormFields', () => {
|
|
6
|
+
it('works on single field', () => {
|
|
7
|
+
type T = Simplify<SubFormFields<{ $: Field }, '$'>>
|
|
8
|
+
expectTypeOf<T>().toEqualTypeOf<{ $: Field }>()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('works on more two fields', () => {
|
|
12
|
+
type T = Simplify<SubFormFields<{ '$.a': Field<string>, '$.b': Field<boolean> }, '$.a'>>
|
|
13
|
+
expectTypeOf<T>().toEqualTypeOf<{ $: Field<string> }>()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('works on subfields', () => {
|
|
17
|
+
type T = Simplify<
|
|
18
|
+
SubFormFields<{ $: Field<null>, '$.a': Field<string>, '$.a.b': Field<boolean>, '$.a.b.c': Field<number> }, '$.a'>
|
|
19
|
+
>
|
|
20
|
+
expectTypeOf<T>().toEqualTypeOf<{ $: Field<string>, '$.b': Field<boolean>, '$.b.c': Field<number> }>()
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type StringConcatOf } from '@strictly/base'
|
|
2
|
+
import { type Fields } from './field'
|
|
3
|
+
|
|
4
|
+
export type SubFormFields<F extends Fields, P extends keyof F> = P extends string ? {
|
|
5
|
+
[K in keyof F as K extends StringConcatOf<`${P}.`, infer S> ? `$.${S}` : never]: F[K]
|
|
6
|
+
} & { $: F[P] }
|
|
7
|
+
: never
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function listConverter() {
|
|
2
|
-
return function (from, valuePath) {
|
|
3
|
-
const value = from.map(function (_v, i) {
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
5
|
-
return `${valuePath}.${i}`;
|
|
6
|
-
});
|
|
7
|
-
return {
|
|
8
|
-
value,
|
|
9
|
-
required: false,
|
|
10
|
-
readonly: false,
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type AnnotatedFieldConverter } from 'types/field_converters'
|
|
2
|
-
|
|
3
|
-
export function listConverter<
|
|
4
|
-
E,
|
|
5
|
-
K extends string,
|
|
6
|
-
ValuePath extends string,
|
|
7
|
-
Context,
|
|
8
|
-
>(): AnnotatedFieldConverter<readonly E[], K[], ValuePath, Context> {
|
|
9
|
-
return function (from: readonly E[], valuePath: ValuePath) {
|
|
10
|
-
const value = from.map(function (_v, i) {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
12
|
-
return `${valuePath as string}.${i}` as K
|
|
13
|
-
})
|
|
14
|
-
return {
|
|
15
|
-
value,
|
|
16
|
-
required: false,
|
|
17
|
-
readonly: false,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|