@strictly/react-form 0.0.4 → 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.
@@ -17,5 +17,5 @@ export declare function adapterFromTwoWayConverter<From, To, E, ValuePath extend
17
17
  export declare function adapterFromPrototype<From, To, ValuePath extends string, Context>(converter: AnnotatedFieldConverter<From, To, ValuePath, Context>, prototype: From): FieldAdapterBuilder<From, To, never, ValuePath, Context>;
18
18
  export declare function adapterFromPrototype<From, To, E, ValuePath extends string, Context>(converter: TwoWayFieldConverter<From, To, E, ValuePath, Context>, prototype: From): FieldAdapterBuilder<From, To, E, ValuePath, Context>;
19
19
  export declare function identityAdapter<V, ValuePath extends string, Context>(prototype: V, required?: boolean): FieldAdapterBuilder<V, V, never, ValuePath, Context>;
20
- export declare function listAdapter<E, K extends string, ValuePath extends string, Context>(): FieldAdapterBuilder<readonly E[], readonly K[], never, ValuePath, Context>;
20
+ export declare function listAdapter<E, ValuePath extends string, Context>(): FieldAdapterBuilder<readonly E[], readonly E[], never, ValuePath, Context>;
21
21
  export {};
@@ -1,6 +1,5 @@
1
1
  import { chainAnnotatedFieldConverter, chainUnreliableFieldConverter, } from 'field_converters/chain_field_converter';
2
2
  import { annotatedIdentityConverter, unreliableIdentityConverter, } from 'field_converters/identity_converter';
3
- import { listConverter } from 'field_converters/list_converter';
4
3
  import { MaybeIdentityConverter } from 'field_converters/maybe_identity_converter';
5
4
  import { prototypingFieldValueFactory } from 'field_value_factories/prototyping_field_value_factory';
6
5
  class FieldAdapterBuilder {
@@ -48,5 +47,5 @@ export function identityAdapter(prototype, required) {
48
47
  return new FieldAdapterBuilder(annotatedIdentityConverter(required), prototypingFieldValueFactory(prototype), unreliableIdentityConverter());
49
48
  }
50
49
  export function listAdapter() {
51
- return new FieldAdapterBuilder(listConverter(), prototypingFieldValueFactory([]));
50
+ return new FieldAdapterBuilder(annotatedIdentityConverter(false), prototypingFieldValueFactory([]), unreliableIdentityConverter());
52
51
  }
@@ -4,12 +4,13 @@ import { type Fields } from 'types/field';
4
4
  import { type ListFieldsOfFields } from 'types/list_fields_of_fields';
5
5
  import { type ValueTypeOfField } from 'types/value_type_of_field';
6
6
  import { type MantineFieldComponent, type MantineForm } from './types';
7
- export type SuppliedListProps<Value = any> = {
7
+ export type SuppliedListProps<Value = any, ListPath extends string = string> = {
8
8
  values: readonly Value[];
9
+ listPath: ListPath;
9
10
  };
10
11
  export declare function createList<F extends Fields, K extends keyof ListFieldsOfFields<F>, Props extends SuppliedListProps<ElementOfArray<ValueTypeOfField<F[K]>>> & {
11
- children: (value: ElementOfArray<ValueTypeOfField<F[K]>>, index: number) => React.ReactNode;
12
+ children: (valuePath: `${K}.${number}`, value: ElementOfArray<ValueTypeOfField<F[K]>>, index: number) => React.ReactNode;
12
13
  }>(this: MantineForm<F>, valuePath: K, List: ComponentType<Props>): MantineFieldComponent<SuppliedListProps<ElementOfArray<ValueTypeOfField<F[K]>>>, Props>;
13
- export declare function DefaultList<Value>({ values, children, }: SuppliedListProps<Value> & {
14
- children: (value: Value, index: number) => React.ReactNode;
14
+ export declare function DefaultList<Value, ListPath extends string>({ values, listPath, children, }: SuppliedListProps<Value, ListPath> & {
15
+ children: (valuePath: `${ListPath}.${number}`, value: Value, index: number) => React.ReactNode;
15
16
  }): import("react/jsx-runtime").JSX.Element;
@@ -5,12 +5,14 @@ export function createList(valuePath, List) {
5
5
  const values = [...this.fields[valuePath].value];
6
6
  return {
7
7
  values,
8
+ listPath: valuePath,
8
9
  };
9
10
  };
10
11
  return createUnsafePartialObserverComponent(List, propSource);
11
12
  }
12
- export function DefaultList({ values, children, }) {
13
+ export function DefaultList({ values, listPath, children, }) {
13
14
  return (_jsx(_Fragment, { children: values.map(function (value, index) {
14
- return children(value, index);
15
+ const valuePath = `${listPath}.${index}`;
16
+ return children(valuePath, value, index);
15
17
  }) }));
16
18
  }
@@ -1,4 +1,5 @@
1
1
  import { type CheckboxProps, type PillProps, type RadioGroupProps, type RadioProps, type SelectProps, type TextInputProps } from '@mantine/core';
2
+ import { type ElementOfArray } from '@strictly/base';
2
3
  import { type FormProps } from 'core/props';
3
4
  import { type ComponentProps, type ComponentType } from 'react';
4
5
  import { type AllFieldsOfFields } from 'types/all_fields_of_fields';
@@ -48,7 +49,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
48
49
  radio<K extends keyof StringFieldsOfFields<F>, P extends SuppliedRadioProps>(valuePath: K, value: ValueTypeOfField<F[K]>, Radio: ComponentType<P>): MantineFieldComponent<SuppliedRadioProps, P, ErrorOfField<F[K]>>;
49
50
  pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
50
51
  pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P>;
51
- list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<`${K}.${number}`>>>;
52
+ list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>>;
52
53
  subForm<K extends keyof AllFieldsOfFields<F>, S extends SubFormFields<F, K>>(valuePath: K, SubForm: ComponentType<FormProps<S>>): ComponentType;
53
54
  }
54
55
  export {};
@@ -5,8 +5,8 @@ import { useMantineForm } from 'mantine/hooks';
5
5
  function Component(props) {
6
6
  const form = useMantineForm(props);
7
7
  const List = form.list('$');
8
- return (_jsx(Paper, { p: 'sm', withBorder: true, children: _jsx(Stack, { children: _jsx(List, { children: function (valuePath) {
9
- return (_jsxs(Code, { children: ["ValuePath: ", valuePath] }, valuePath));
8
+ return (_jsx(Paper, { p: 'sm', withBorder: true, children: _jsx(Stack, { children: _jsx(List, { children: function (valuePath, value, index) {
9
+ return (_jsxs(Code, { children: [_jsxs("span", { children: ["ValuePath: ", valuePath] }), _jsx("br", {}), _jsxs("span", { children: ["Value: ", value] }), _jsx("br", {}), _jsxs("span", { children: ["Index: ", index] })] }, valuePath));
10
10
  } }) }) }));
11
11
  }
12
12
  const meta = {
@@ -37,10 +37,10 @@ export const Populated = {
37
37
  readonly: false,
38
38
  required: false,
39
39
  value: [
40
- '$.4',
41
- '$.6',
42
- '$.19',
43
- '$.0',
40
+ 'A',
41
+ 'B',
42
+ 'C',
43
+ 'D',
44
44
  ],
45
45
  },
46
46
  },