@strictly/react-form 0.0.1

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 (239) hide show
  1. package/.eslintrc.cjs +26 -0
  2. package/.out/.storybook/main.d.ts +3 -0
  3. package/.out/.storybook/main.js +32 -0
  4. package/.out/.storybook/preview.d.ts +4 -0
  5. package/.out/.storybook/preview.js +20 -0
  6. package/.out/.vitest/install_deterministic_random.d.ts +2 -0
  7. package/.out/.vitest/install_deterministic_random.js +15 -0
  8. package/.out/.vitest/install_storybook_preview.d.ts +1 -0
  9. package/.out/.vitest/install_storybook_preview.js +7 -0
  10. package/.out/.vitest/match_media.d.ts +1 -0
  11. package/.out/.vitest/match_media.js +5 -0
  12. package/.out/.vitest/resize_observer.d.ts +1 -0
  13. package/.out/.vitest/resize_observer.js +4 -0
  14. package/.out/core/mobx/field_adapter.d.ts +9 -0
  15. package/.out/core/mobx/field_adapter.js +1 -0
  16. package/.out/core/mobx/field_adapter_builder.d.ts +22 -0
  17. package/.out/core/mobx/field_adapter_builder.js +56 -0
  18. package/.out/core/mobx/flattened_adapters_of_fields.d.ts +9 -0
  19. package/.out/core/mobx/flattened_adapters_of_fields.js +1 -0
  20. package/.out/core/mobx/flattened_list_type_defs_of.d.ts +8 -0
  21. package/.out/core/mobx/flattened_list_type_defs_of.js +1 -0
  22. package/.out/core/mobx/form_presenter.d.ts +61 -0
  23. package/.out/core/mobx/form_presenter.js +425 -0
  24. package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.d.ts +1 -0
  25. package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.js +13 -0
  26. package/.out/core/mobx/specs/flattened_list_type_defs_of.tests.d.ts +1 -0
  27. package/.out/core/mobx/specs/flattened_list_type_defs_of.tests.js +16 -0
  28. package/.out/core/mobx/specs/form_presenter.tests.d.ts +1 -0
  29. package/.out/core/mobx/specs/form_presenter.tests.js +697 -0
  30. package/.out/core/mobx/types.d.ts +19 -0
  31. package/.out/core/mobx/types.js +1 -0
  32. package/.out/core/props.d.ts +12 -0
  33. package/.out/core/props.js +1 -0
  34. package/.out/field_converters/chain_field_converter.d.ts +3 -0
  35. package/.out/field_converters/chain_field_converter.js +46 -0
  36. package/.out/field_converters/identity_converter.d.ts +3 -0
  37. package/.out/field_converters/identity_converter.js +14 -0
  38. package/.out/field_converters/integer_to_string_converter.d.ts +7 -0
  39. package/.out/field_converters/integer_to_string_converter.js +26 -0
  40. package/.out/field_converters/list_converter.d.ts +2 -0
  41. package/.out/field_converters/list_converter.js +8 -0
  42. package/.out/field_converters/maybe_identity_converter.d.ts +8 -0
  43. package/.out/field_converters/maybe_identity_converter.js +15 -0
  44. package/.out/field_converters/nullable_to_boolean_converter.d.ts +11 -0
  45. package/.out/field_converters/nullable_to_boolean_converter.js +31 -0
  46. package/.out/field_converters/select_value_type_converter.d.ts +23 -0
  47. package/.out/field_converters/select_value_type_converter.js +60 -0
  48. package/.out/field_converters/trimming_string_converter.d.ts +6 -0
  49. package/.out/field_converters/trimming_string_converter.js +14 -0
  50. package/.out/field_converters/validating_converter.d.ts +3 -0
  51. package/.out/field_converters/validating_converter.js +21 -0
  52. package/.out/field_validators/minimum_string_length_field_validator.d.ts +2 -0
  53. package/.out/field_validators/minimum_string_length_field_validator.js +8 -0
  54. package/.out/field_value_factories/prototyping_field_value_factory.d.ts +2 -0
  55. package/.out/field_value_factories/prototyping_field_value_factory.js +5 -0
  56. package/.out/index.d.ts +16 -0
  57. package/.out/index.js +16 -0
  58. package/.out/mantine/create_checkbox.d.ts +9 -0
  59. package/.out/mantine/create_checkbox.js +37 -0
  60. package/.out/mantine/create_list.d.ts +15 -0
  61. package/.out/mantine/create_list.js +16 -0
  62. package/.out/mantine/create_pill.d.ts +7 -0
  63. package/.out/mantine/create_pill.js +15 -0
  64. package/.out/mantine/create_radio.d.ts +8 -0
  65. package/.out/mantine/create_radio.js +10 -0
  66. package/.out/mantine/create_radio_group.d.ts +9 -0
  67. package/.out/mantine/create_radio_group.js +34 -0
  68. package/.out/mantine/create_text_input.d.ts +19 -0
  69. package/.out/mantine/create_text_input.js +38 -0
  70. package/.out/mantine/create_value_input.d.ts +17 -0
  71. package/.out/mantine/create_value_input.js +38 -0
  72. package/.out/mantine/hooks.d.ts +56 -0
  73. package/.out/mantine/hooks.js +135 -0
  74. package/.out/mantine/specs/checkbox_constants.d.ts +1 -0
  75. package/.out/mantine/specs/checkbox_constants.js +1 -0
  76. package/.out/mantine/specs/checkbox_hooks.stories.d.ts +13 -0
  77. package/.out/mantine/specs/checkbox_hooks.stories.js +63 -0
  78. package/.out/mantine/specs/checkbox_hooks.tests.d.ts +1 -0
  79. package/.out/mantine/specs/checkbox_hooks.tests.js +74 -0
  80. package/.out/mantine/specs/list_hooks.stories.d.ts +11 -0
  81. package/.out/mantine/specs/list_hooks.stories.js +48 -0
  82. package/.out/mantine/specs/list_hooks.tests.d.ts +1 -0
  83. package/.out/mantine/specs/list_hooks.tests.js +12 -0
  84. package/.out/mantine/specs/radio_group_constants.d.ts +4 -0
  85. package/.out/mantine/specs/radio_group_constants.js +11 -0
  86. package/.out/mantine/specs/radio_group_hooks.stories.d.ts +14 -0
  87. package/.out/mantine/specs/radio_group_hooks.stories.js +68 -0
  88. package/.out/mantine/specs/radio_group_hooks.tests.d.ts +1 -0
  89. package/.out/mantine/specs/radio_group_hooks.tests.js +62 -0
  90. package/.out/mantine/specs/select_hooks.stories.d.ts +12 -0
  91. package/.out/mantine/specs/select_hooks.stories.js +57 -0
  92. package/.out/mantine/specs/select_hooks.tests.d.ts +1 -0
  93. package/.out/mantine/specs/select_hooks.tests.js +12 -0
  94. package/.out/mantine/specs/select_hooks_constant.d.ts +1 -0
  95. package/.out/mantine/specs/select_hooks_constant.js +1 -0
  96. package/.out/mantine/specs/text_input_constants.d.ts +1 -0
  97. package/.out/mantine/specs/text_input_constants.js +1 -0
  98. package/.out/mantine/specs/text_input_hooks.stories.d.ts +21 -0
  99. package/.out/mantine/specs/text_input_hooks.stories.js +88 -0
  100. package/.out/mantine/specs/text_input_hooks.tests.d.ts +1 -0
  101. package/.out/mantine/specs/text_input_hooks.tests.js +79 -0
  102. package/.out/mantine/specs/value_input_constants.d.ts +2 -0
  103. package/.out/mantine/specs/value_input_constants.js +2 -0
  104. package/.out/mantine/specs/value_input_hooks.stories.d.ts +23 -0
  105. package/.out/mantine/specs/value_input_hooks.stories.js +124 -0
  106. package/.out/mantine/specs/value_input_hooks.tests.d.ts +1 -0
  107. package/.out/mantine/specs/value_input_hooks.tests.js +12 -0
  108. package/.out/mantine/types.d.ts +11 -0
  109. package/.out/mantine/types.js +1 -0
  110. package/.out/tsconfig.json +27 -0
  111. package/.out/tsconfig.tsbuildinfo +1 -0
  112. package/.out/tsup.config.d.ts +3 -0
  113. package/.out/tsup.config.js +12 -0
  114. package/.out/types/all_fields_of_fields.d.ts +5 -0
  115. package/.out/types/all_fields_of_fields.js +1 -0
  116. package/.out/types/boolean_fields_of_fields.d.ts +5 -0
  117. package/.out/types/boolean_fields_of_fields.js +1 -0
  118. package/.out/types/error_type_of_field.d.ts +2 -0
  119. package/.out/types/error_type_of_field.js +1 -0
  120. package/.out/types/field.d.ts +7 -0
  121. package/.out/types/field.js +1 -0
  122. package/.out/types/field_converters.d.ts +29 -0
  123. package/.out/types/field_converters.js +5 -0
  124. package/.out/types/field_validator.d.ts +3 -0
  125. package/.out/types/field_validator.js +1 -0
  126. package/.out/types/flattened_form_fields_of.d.ts +9 -0
  127. package/.out/types/flattened_form_fields_of.js +1 -0
  128. package/.out/types/list_fields_of_fields.d.ts +5 -0
  129. package/.out/types/list_fields_of_fields.js +1 -0
  130. package/.out/types/specs/boolean_fields_of_fields.tests.d.ts +1 -0
  131. package/.out/types/specs/boolean_fields_of_fields.tests.js +11 -0
  132. package/.out/types/specs/error_type_of_field.tests.d.ts +1 -0
  133. package/.out/types/specs/error_type_of_field.tests.js +7 -0
  134. package/.out/types/specs/flattened_form_fields_of.tests.d.ts +1 -0
  135. package/.out/types/specs/flattened_form_fields_of.tests.js +13 -0
  136. package/.out/types/specs/string_fields_of_fields.tests.d.ts +1 -0
  137. package/.out/types/specs/string_fields_of_fields.tests.js +19 -0
  138. package/.out/types/specs/value_type_of_field.tests.d.ts +1 -0
  139. package/.out/types/specs/value_type_of_field.tests.js +7 -0
  140. package/.out/types/string_fields_of_fields.d.ts +5 -0
  141. package/.out/types/string_fields_of_fields.js +1 -0
  142. package/.out/types/value_type_of_field.d.ts +2 -0
  143. package/.out/types/value_type_of_field.js +1 -0
  144. package/.out/util/partial.d.ts +11 -0
  145. package/.out/util/partial.js +74 -0
  146. package/.out/vitest.workspace.d.ts +2 -0
  147. package/.out/vitest.workspace.js +22 -0
  148. package/.storybook/main.ts +40 -0
  149. package/.storybook/preview.tsx +28 -0
  150. package/.storybook/vite.config.mts +38 -0
  151. package/.turbo/turbo-build.log +18 -0
  152. package/.turbo/turbo-check-types.log +3 -0
  153. package/.turbo/turbo-release$colon$exports.log +3 -0
  154. package/.vitest/install_deterministic_random.ts +17 -0
  155. package/.vitest/install_storybook_preview.ts +9 -0
  156. package/.vitest/match_media.ts +7 -0
  157. package/.vitest/resize_observer.ts +5 -0
  158. package/README.md +2 -0
  159. package/core/mobx/field_adapter.ts +32 -0
  160. package/core/mobx/field_adapter_builder.ts +313 -0
  161. package/core/mobx/flattened_adapters_of_fields.ts +35 -0
  162. package/core/mobx/flattened_list_type_defs_of.ts +17 -0
  163. package/core/mobx/form_presenter.ts +705 -0
  164. package/core/mobx/specs/flattened_adapters_of_fields.tests.ts +72 -0
  165. package/core/mobx/specs/flattened_list_type_defs_of.tests.ts +35 -0
  166. package/core/mobx/specs/form_presenter.tests.ts +989 -0
  167. package/core/mobx/types.ts +54 -0
  168. package/core/props.ts +21 -0
  169. package/dist/index.cjs +11479 -0
  170. package/dist/index.d.cts +345 -0
  171. package/dist/index.d.ts +345 -0
  172. package/dist/index.js +11486 -0
  173. package/field_converters/chain_field_converter.ts +74 -0
  174. package/field_converters/identity_converter.ts +39 -0
  175. package/field_converters/integer_to_string_converter.ts +32 -0
  176. package/field_converters/list_converter.ts +15 -0
  177. package/field_converters/maybe_identity_converter.ts +23 -0
  178. package/field_converters/nullable_to_boolean_converter.ts +56 -0
  179. package/field_converters/select_value_type_converter.ts +141 -0
  180. package/field_converters/trimming_string_converter.ts +23 -0
  181. package/field_converters/validating_converter.ts +35 -0
  182. package/field_validators/minimum_string_length_field_validator.ts +13 -0
  183. package/field_value_factories/prototyping_field_value_factory.ts +11 -0
  184. package/index.ts +16 -0
  185. package/mantine/create_checkbox.tsx +79 -0
  186. package/mantine/create_list.tsx +58 -0
  187. package/mantine/create_pill.tsx +43 -0
  188. package/mantine/create_radio.tsx +36 -0
  189. package/mantine/create_radio_group.tsx +71 -0
  190. package/mantine/create_text_input.tsx +80 -0
  191. package/mantine/create_value_input.tsx +81 -0
  192. package/mantine/hooks.tsx +394 -0
  193. package/mantine/specs/__snapshots__/check_box_hooks.tests.tsx.snap +227 -0
  194. package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +227 -0
  195. package/mantine/specs/__snapshots__/list_hooks.tests.tsx.snap +68 -0
  196. package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +695 -0
  197. package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +225 -0
  198. package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +202 -0
  199. package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +613 -0
  200. package/mantine/specs/checkbox_constants.ts +1 -0
  201. package/mantine/specs/checkbox_hooks.stories.tsx +79 -0
  202. package/mantine/specs/checkbox_hooks.tests.tsx +100 -0
  203. package/mantine/specs/list_hooks.stories.tsx +83 -0
  204. package/mantine/specs/list_hooks.tests.tsx +15 -0
  205. package/mantine/specs/radio_group_constants.ts +12 -0
  206. package/mantine/specs/radio_group_hooks.stories.tsx +103 -0
  207. package/mantine/specs/radio_group_hooks.tests.tsx +92 -0
  208. package/mantine/specs/select_hooks.stories.tsx +77 -0
  209. package/mantine/specs/select_hooks.tests.tsx +14 -0
  210. package/mantine/specs/select_hooks_constant.ts +1 -0
  211. package/mantine/specs/text_input_constants.ts +1 -0
  212. package/mantine/specs/text_input_hooks.stories.tsx +124 -0
  213. package/mantine/specs/text_input_hooks.tests.tsx +106 -0
  214. package/mantine/specs/value_input_constants.ts +2 -0
  215. package/mantine/specs/value_input_hooks.stories.tsx +182 -0
  216. package/mantine/specs/value_input_hooks.tests.tsx +14 -0
  217. package/mantine/types.ts +13 -0
  218. package/package.exports.json +18 -0
  219. package/package.json +74 -0
  220. package/tsconfig.build.json +13 -0
  221. package/tsconfig.json +27 -0
  222. package/tsup.config.ts +16 -0
  223. package/types/all_fields_of_fields.ts +9 -0
  224. package/types/boolean_fields_of_fields.ts +8 -0
  225. package/types/error_type_of_field.ts +3 -0
  226. package/types/field.ts +9 -0
  227. package/types/field_converters.ts +64 -0
  228. package/types/field_validator.ts +7 -0
  229. package/types/flattened_form_fields_of.ts +16 -0
  230. package/types/list_fields_of_fields.ts +7 -0
  231. package/types/specs/boolean_fields_of_fields.tests.ts +23 -0
  232. package/types/specs/error_type_of_field.tests.ts +10 -0
  233. package/types/specs/flattened_form_fields_of.tests.ts +43 -0
  234. package/types/specs/string_fields_of_fields.tests.ts +40 -0
  235. package/types/specs/value_type_of_field.tests.ts +10 -0
  236. package/types/string_fields_of_fields.ts +6 -0
  237. package/types/value_type_of_field.ts +3 -0
  238. package/util/partial.tsx +200 -0
  239. package/vitest.workspace.ts +26 -0
package/.eslintrc.cjs ADDED
@@ -0,0 +1,26 @@
1
+ /* eslint-env node */
2
+ /** @type {import('@types/eslint').Linter.Config} */
3
+ module.exports = {
4
+ root: true,
5
+ extends: ['../../.eslintrc.cjs'],
6
+ parserOptions: {
7
+ project: [
8
+ 'tsconfig.json',
9
+ 'tsconfig.build.json',
10
+ ],
11
+ tsconfigRootDir: __dirname,
12
+ sourceType: 'module',
13
+ ecmaVersion: '2015',
14
+ },
15
+ rules: {
16
+ 'import/no-extraneous-dependencies': [
17
+ 'warn',
18
+ {
19
+ packageDir: [
20
+ '.',
21
+ '../..',
22
+ ],
23
+ },
24
+ ],
25
+ },
26
+ }
@@ -0,0 +1,3 @@
1
+ import { type StorybookConfig } from '@storybook/react-vite';
2
+ declare const config: StorybookConfig;
3
+ export default config;
@@ -0,0 +1,32 @@
1
+ import { dirname, join, } from 'path';
2
+ /**
3
+ * This function is used to resolve the absolute path of a package.
4
+ * It is needed in projects that use Yarn PnP or are set up within a monorepo.
5
+ */
6
+ function getAbsolutePath(value) {
7
+ return dirname(require.resolve(join(value, 'package.json')));
8
+ }
9
+ const config = {
10
+ stories: ['../**/*.stories.@(ts|tsx)'],
11
+ addons: [
12
+ getAbsolutePath('@storybook/addon-links'),
13
+ getAbsolutePath('@storybook/addon-essentials'),
14
+ getAbsolutePath('@chromatic-com/storybook'),
15
+ getAbsolutePath('@storybook/addon-interactions'),
16
+ ],
17
+ core: {
18
+ builder: {
19
+ name: getAbsolutePath('@storybook/builder-vite'),
20
+ options: {
21
+ viteConfigPath: './.storybook/vite.config.mts',
22
+ },
23
+ },
24
+ },
25
+ framework: {
26
+ // NOTE: the documentation says this should be @storybook/react-vite, which fails completely
27
+ // https://storybook.js.org/docs/get-started/frameworks/react-vite
28
+ name: getAbsolutePath('@storybook/react'),
29
+ options: {},
30
+ },
31
+ };
32
+ export default config;
@@ -0,0 +1,4 @@
1
+ import '@mantine/core/styles.css';
2
+ import { type Preview } from '@storybook/react';
3
+ declare const preview: Preview;
4
+ export default preview;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import '@mantine/core/styles.css';
3
+ import { MantineProvider } from '@mantine/core';
4
+ import { StrictMode } from 'react';
5
+ const preview = {
6
+ parameters: {
7
+ controls: {
8
+ matchers: {
9
+ color: /(background|color)$/i,
10
+ date: /Date$/i,
11
+ },
12
+ },
13
+ },
14
+ decorators: [
15
+ function (Story) {
16
+ return (_jsx(MantineProvider, { children: _jsx(StrictMode, { children: _jsx(Story, {}) }) }));
17
+ },
18
+ ],
19
+ };
20
+ export default preview;
@@ -0,0 +1,2 @@
1
+ declare const originalMathRandom: () => number;
2
+ declare const LIMIT = 100;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // sadly Mantine uses randomness to generate certain fields (e.g. label mappings), we
3
+ // override Math.random to ensure these seeds remain the same between runs
4
+ const originalMathRandom = Math.random;
5
+ const LIMIT = 100;
6
+ beforeEach(function () {
7
+ let count = 0;
8
+ Math.random = function () {
9
+ count++;
10
+ return (count % LIMIT) / LIMIT;
11
+ };
12
+ });
13
+ afterEach(function () {
14
+ Math.random = originalMathRandom;
15
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ // adapted from https://storybook.js.org/docs/api/portable-stories/portable-stories-jest
2
+ import { setProjectAnnotations } from '@storybook/react';
3
+ // eslint-disable-next-line no-relative-import-paths/no-relative-import-paths
4
+ import * as previewAnnotations from '../.storybook/preview';
5
+ const annotations = setProjectAnnotations([previewAnnotations]);
6
+ // Run Storybook's beforeAll hook
7
+ beforeAll(annotations.beforeAll);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import MatchMediaMock from 'vitest-matchmedia-mock';
2
+ const matchMediaMock = new MatchMediaMock();
3
+ beforeAll(function () {
4
+ matchMediaMock.clear();
5
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import ResizeObserver from 'resize-observer-polyfill';
2
+ beforeAll(function () {
3
+ window.ResizeObserver = window.ResizeObserver || ResizeObserver;
4
+ });
@@ -0,0 +1,9 @@
1
+ import { type FieldConverter, type FieldValueFactory, type SafeFieldConverter } from 'types/field_converters';
2
+ export type FieldAdapter<From = any, To = any, E = any, ValuePath extends string = any, Context = any> = {
3
+ readonly convert: SafeFieldConverter<From, To, ValuePath, Context>;
4
+ readonly create: FieldValueFactory<From, ValuePath, Context>;
5
+ readonly revert?: FieldConverter<To, From, E, ValuePath, Context>;
6
+ };
7
+ export type FromTypeOfFieldAdapter<C extends FieldAdapter> = C extends FieldAdapter<infer From> ? From : never;
8
+ export type ToTypeOfFieldAdapter<C extends FieldAdapter> = C extends FieldAdapter<infer _F, infer To> ? To : never;
9
+ export type ErrorTypeOfFieldAdapter<C extends FieldAdapter> = C extends FieldAdapter<infer _From, infer _To, infer E> ? NonNullable<E> : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { type FieldConverter, type FieldValueFactory, type SafeFieldConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory } from 'types/field_converters';
2
+ import { type FieldValidator } from 'types/field_validator';
3
+ declare class FieldAdapterBuilder<From, To, E, ValuePath extends string, Context> {
4
+ readonly convert: SafeFieldConverter<From, To, ValuePath, Context>;
5
+ readonly create: FieldValueFactory<From, ValuePath, Context>;
6
+ readonly revert?: FieldConverter<To, From, E, ValuePath, Context> | undefined;
7
+ constructor(convert: SafeFieldConverter<From, To, ValuePath, Context>, create: FieldValueFactory<From, ValuePath, Context>, revert?: FieldConverter<To, From, E, ValuePath, Context> | undefined);
8
+ validateFrom<E2>(...validators: readonly FieldValidator<From, E2, ValuePath, Context>[]): FieldAdapterBuilder<From, To, E | E2, ValuePath, Context>;
9
+ validateTo<E2>(...validators: readonly FieldValidator<To, E2, ValuePath, Context>[]): FieldAdapterBuilder<From, To, E | E2, ValuePath, Context>;
10
+ chain<To2, E2 = E>(converter: SafeFieldConverter<To, To2, ValuePath, Context>, reverter?: FieldConverter<To2, To, E2, ValuePath, Context>): FieldAdapterBuilder<From, To2, E | E2, ValuePath, Context>;
11
+ withReverter(reverter: FieldConverter<To, From, E, ValuePath, Context>): FieldAdapterBuilder<From, To, E, ValuePath, Context>;
12
+ withIdentity(isFrom: (from: To | From) => from is From): FieldAdapterBuilder<From, To | From, E, ValuePath, Context>;
13
+ }
14
+ export declare function adapter<From, To, ValuePath extends string, Context>(converter: SafeFieldConverter<From, To, ValuePath, Context>, valueFactory: FieldValueFactory<From, ValuePath, Context>): FieldAdapterBuilder<From, To, never, ValuePath, Context>;
15
+ export declare function adapter<From, To, E, ValuePath extends string, Context>(converter: SafeFieldConverter<From, To, ValuePath, Context>, valueFactory: FieldValueFactory<From, ValuePath, Context>, reverter: FieldConverter<To, From, E, ValuePath, Context>): FieldAdapterBuilder<From, To, E, ValuePath, Context>;
16
+ export declare function adapterFromTwoWayConverter<From, To, E, ValuePath extends string, Context>(converter: TwoWayFieldConverter<From, To, E, ValuePath, Context>, valueFactory: FieldValueFactory<From, ValuePath, Context>): FieldAdapterBuilder<From, To, E, ValuePath, Context>;
17
+ export declare function adapterFromTwoWayConverter<From, To, E, ValuePath extends string, Context>(converter: TwoWayFieldConverterWithValueFactory<From, To, E, ValuePath, Context>): FieldAdapterBuilder<From, To, E, ValuePath, Context>;
18
+ export declare function adapterFromPrototype<From, To, ValuePath extends string, Context>(converter: SafeFieldConverter<From, To, ValuePath, Context>, prototype: From): FieldAdapterBuilder<From, To, never, ValuePath, Context>;
19
+ 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>;
20
+ export declare function identityAdapter<V, ValuePath extends string, Context>(prototype: V): FieldAdapterBuilder<V, V, never, ValuePath, Context>;
21
+ export declare function listAdapter<E, K extends string, ValuePath extends string, Context>(): FieldAdapterBuilder<readonly E[], readonly K[], never, ValuePath, Context>;
22
+ export {};
@@ -0,0 +1,56 @@
1
+ import { chainFieldConverter, chainSafeFieldConverter, } from 'field_converters/chain_field_converter';
2
+ import { identityConverter, safeIdentityConverter, } from 'field_converters/identity_converter';
3
+ import { listConverter } from 'field_converters/list_converter';
4
+ import { MaybeIdentityConverter } from 'field_converters/maybe_identity_converter';
5
+ import { validatingConverter, } from 'field_converters/validating_converter';
6
+ import { prototypingFieldValueFactory } from 'field_value_factories/prototyping_field_value_factory';
7
+ class FieldAdapterBuilder {
8
+ convert;
9
+ create;
10
+ revert;
11
+ constructor(convert, create, revert) {
12
+ this.convert = convert;
13
+ this.create = create;
14
+ this.revert = revert;
15
+ }
16
+ validateFrom(...validators) {
17
+ return new FieldAdapterBuilder(this.convert, this.create, this.revert && chainFieldConverter(this.revert, validatingConverter(validators)));
18
+ }
19
+ validateTo(...validators) {
20
+ return new FieldAdapterBuilder(this.convert, this.create, this.revert && chainFieldConverter(validatingConverter(validators), this.revert));
21
+ }
22
+ chain(converter, reverter) {
23
+ return new FieldAdapterBuilder(chainSafeFieldConverter(this.convert, converter), this.create, this.revert && reverter && chainFieldConverter(reverter, this.revert));
24
+ }
25
+ withReverter(reverter) {
26
+ return new FieldAdapterBuilder(this.convert, this.create, reverter);
27
+ }
28
+ withIdentity(isFrom) {
29
+ const identityConverter = new MaybeIdentityConverter({
30
+ convert: this.convert,
31
+ // should never get called if null
32
+ revert: this.revert,
33
+ }, isFrom);
34
+ return new FieldAdapterBuilder(identityConverter.convert.bind(identityConverter), this.create, this.revert && identityConverter.revert.bind(identityConverter));
35
+ }
36
+ }
37
+ export function adapter(converter, valueFactory, reverter) {
38
+ return new FieldAdapterBuilder(converter, valueFactory, reverter);
39
+ }
40
+ export function adapterFromTwoWayConverter(converter,
41
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
42
+ valueFactory = converter.create.bind(converter)) {
43
+ return new FieldAdapterBuilder(converter.convert.bind(converter), valueFactory, converter.revert.bind(converter));
44
+ }
45
+ export function adapterFromPrototype(converter, prototype) {
46
+ const factory = prototypingFieldValueFactory(prototype);
47
+ return typeof converter === 'function'
48
+ ? new FieldAdapterBuilder(converter, factory)
49
+ : new FieldAdapterBuilder(converter.convert.bind(converter), factory, converter.revert.bind(converter));
50
+ }
51
+ export function identityAdapter(prototype) {
52
+ return new FieldAdapterBuilder(safeIdentityConverter(), prototypingFieldValueFactory(prototype), identityConverter());
53
+ }
54
+ export function listAdapter() {
55
+ return new FieldAdapterBuilder(listConverter(), prototypingFieldValueFactory([]));
56
+ }
@@ -0,0 +1,9 @@
1
+ import { type ReadonlyTypeDefOf, type Type, type ValueTypeOf } from '@strictly/define';
2
+ import { type FieldAdapter } from 'core/mobx/field_adapter';
3
+ import { type SimplifyDeep, type ValueOf } from 'type-fest';
4
+ import { type Field } from 'types/field';
5
+ export type FlattenedAdaptersOfFields<ValuePathsToTypePaths extends Readonly<Record<string, string>>, FlattenedTypeDefs extends Partial<Readonly<Record<ValueOf<ValuePathsToTypePaths>, Type>>>, FormFields extends Partial<Readonly<Record<keyof ValuePathsToTypePaths, Field>>>> = SimplifyDeep<{
6
+ readonly [K in keyof ValuePathsToTypePaths as FormFields[K] extends Field ? ValuePathsToTypePaths[K] : never]: AdapterOfField<NonNullable<FormFields[K]>, FlattenedTypeDefs[ValuePathsToTypePaths[K]], K>;
7
+ }>;
8
+ type AdapterOfField<F extends Field, T extends Type | undefined, ValuePath extends string | number | symbol> = ValuePath extends string ? F extends Field<infer V, infer E> ? undefined extends T ? FieldAdapter<V, V, E, ValuePath> : FieldAdapter<ValueTypeOf<ReadonlyTypeDefOf<NonNullable<T>>>, V, E, ValuePath> : never : never;
9
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { type FlattenedTypeDefsOf, type ListTypeDef, type Type } from '@strictly/define';
2
+ import { type SimplifyDeep } from 'type-fest';
3
+ export type ListJsonPathsOf<T extends Type> = keyof FlattenedListTypeDefsOf<T>;
4
+ export type FlattenedListTypeDefsOf<T extends Type> = FlattenedListTypeDefsOfFlattened<SimplifyDeep<FlattenedTypeDefsOf<T, null>>>;
5
+ type FlattenedListTypeDefsOfFlattened<T extends Readonly<Record<string, Type>>> = {
6
+ [K in keyof T as T[K]['definition'] extends ListTypeDef ? K : never]: T[K];
7
+ };
8
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ import { type ElementOfArray, type Maybe } from '@strictly/base';
2
+ import { type Accessor, type FlattenedValueTypesOf, type MobxValueTypeOf, type ReadonlyTypeDefOf, type Type, type ValueTypeOf } from '@strictly/define';
3
+ import { type ReadonlyDeep, type SimplifyDeep, type StringKeyOf, type ValueOf } from 'type-fest';
4
+ import { type Field } from 'types/field';
5
+ import { type ErrorTypeOfFieldAdapter, type FieldAdapter, type ToTypeOfFieldAdapter } from './field_adapter';
6
+ import { type FlattenedListTypeDefsOf } from './flattened_list_type_defs_of';
7
+ export type FlattenedConvertedFieldsOf<ValuePathsToAdapters extends Readonly<Record<string, FieldAdapter>>> = {
8
+ readonly [K in keyof ValuePathsToAdapters]: Field<ToTypeOfFieldAdapter<ValuePathsToAdapters[K]>, ErrorTypeOfFieldAdapter<ValuePathsToAdapters[K]>>;
9
+ };
10
+ export type FlattenedTypePathsToAdaptersOf<FlattenedValues extends Readonly<Record<string, any>>, Context> = {
11
+ readonly [K in keyof FlattenedValues]?: FieldAdapter<ReadonlyDeep<FlattenedValues[K]>, any, any, any, Context>;
12
+ };
13
+ type FieldOverride<V = any> = {
14
+ value: V;
15
+ };
16
+ type FlattenedFieldOverrides<ValuePathsToAdapters extends Readonly<Record<string, FieldAdapter>>> = {
17
+ -readonly [K in keyof ValuePathsToAdapters]?: FieldOverride<ToTypeOfFieldAdapter<ValuePathsToAdapters[K]>>;
18
+ };
19
+ type FlattenedErrors<ValuePathsToAdapters extends Readonly<Record<string, FieldAdapter>>> = {
20
+ -readonly [K in keyof ValuePathsToAdapters]?: ErrorTypeOfFieldAdapter<ValuePathsToAdapters[K]>;
21
+ };
22
+ export type ValuePathsToAdaptersOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>, ValuePathsToTypePaths extends Readonly<Record<string, string>>> = keyof TypePathsToAdapters extends ValueOf<ValuePathsToTypePaths> ? {
23
+ readonly [K in keyof ValuePathsToTypePaths as unknown extends TypePathsToAdapters[ValuePathsToTypePaths[K]] ? never : K]: NonNullable<TypePathsToAdapters[ValuePathsToTypePaths[K]]>;
24
+ } : never;
25
+ export declare class FormPresenter<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValueTypesOf<T, '*'>, ValueTypeOf<ReadonlyTypeDefOf<T>>>, ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>> {
26
+ readonly typeDef: T;
27
+ private readonly adapters;
28
+ constructor(typeDef: T, adapters: TypePathsToAdapters);
29
+ private maybeGetAdapterForValuePath;
30
+ private getAdapterForValuePath;
31
+ typePath<K extends keyof ValueToTypePaths>(valuePath: K): ValueToTypePaths[K];
32
+ setFieldValueAndValidate<K extends keyof ValuePathsToAdapters>(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, valuePath: K, value: ToTypeOfFieldAdapter<ValuePathsToAdapters[K]>): boolean;
33
+ setFieldValue<K extends keyof ValuePathsToAdapters>(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, valuePath: K, value: ToTypeOfFieldAdapter<ValuePathsToAdapters[K]>): boolean;
34
+ addListItem<K extends keyof FlattenedListTypeDefsOf<T>>(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, valuePath: K, elementValue: Maybe<ElementOfArray<FlattenedValueTypesOf<T>[K]>>, index?: number): void;
35
+ removeListItem<K extends keyof FlattenedListTypeDefsOf<T>>(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, elementValuePath: `${K}.${number}`): void;
36
+ private internalSetFieldValue;
37
+ clearFieldError<K extends keyof ValuePathsToAdapters>(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, valuePath: K): void;
38
+ clearFieldValue<K extends StringKeyOf<ValuePathsToAdapters>>(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, valuePath: K): void;
39
+ clearAll(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, value: ValueTypeOf<T>): void;
40
+ validateField<K extends keyof ValuePathsToAdapters>(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>, valuePath: K): boolean;
41
+ validateAll(model: FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>): boolean;
42
+ createModel(value: ValueTypeOf<ReadonlyTypeDefOf<T>>): FormModel<T, ValueToTypePaths, TypePathsToAdapters, ValuePathsToAdapters>;
43
+ }
44
+ export declare class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValueTypesOf<T, '*'>, ValueTypeOf<ReadonlyTypeDefOf<T>>>, ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>> {
45
+ private readonly typeDef;
46
+ private readonly adapters;
47
+ accessor value: MobxValueTypeOf<T>;
48
+ accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
49
+ accessor errors: FlattenedErrors<ValuePathsToAdapters>;
50
+ private readonly flattenedTypeDefs;
51
+ constructor(typeDef: T, value: ValueTypeOf<ReadonlyTypeDefOf<T>>, adapters: TypePathsToAdapters);
52
+ get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
53
+ private get knownFields();
54
+ private maybeSynthesizeFieldByValuePath;
55
+ private synthesizeFieldByPaths;
56
+ getAccessorForValuePath(valuePath: keyof ValuePathsToAdapters): Accessor | undefined;
57
+ get accessors(): Readonly<Record<string, Accessor>>;
58
+ protected isDisabled(_valuePath: keyof ValuePathsToAdapters): boolean;
59
+ protected isRequired(_valuePath: keyof ValuePathsToAdapters): boolean;
60
+ }
61
+ export {};