@strictly/react-form 0.0.9 → 0.0.11

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 (60) hide show
  1. package/.out/core/mobx/field_adapter_builder.js +18 -6
  2. package/.out/core/mobx/form_presenter.d.ts +5 -5
  3. package/.out/core/mobx/form_presenter.js +232 -127
  4. package/.out/core/mobx/hooks.d.ts +24 -4
  5. package/.out/core/mobx/hooks.js +26 -5
  6. package/.out/core/mobx/merge_field_adapters_with_validators.js +1 -5
  7. package/.out/core/mobx/specs/fixtures.js +2 -1
  8. package/.out/core/mobx/specs/form_presenter.tests.js +16 -8
  9. package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +2 -1
  10. package/.out/core/mobx/sub_form_field_adapters.d.ts +2 -2
  11. package/.out/field_converters/integer_to_string_converter.js +12 -4
  12. package/.out/field_converters/maybe_identity_converter.js +12 -4
  13. package/.out/field_converters/nullable_to_boolean_converter.js +24 -7
  14. package/.out/field_converters/select_value_type_converter.js +36 -12
  15. package/.out/mantine/create_checkbox.js +8 -4
  16. package/.out/mantine/create_fields_view.d.ts +9 -1
  17. package/.out/mantine/create_fields_view.js +20 -5
  18. package/.out/mantine/create_form.js +1 -1
  19. package/.out/mantine/create_radio_group.js +8 -4
  20. package/.out/mantine/create_text_input.js +8 -4
  21. package/.out/mantine/create_value_input.js +8 -4
  22. package/.out/mantine/hooks.d.ts +2 -1
  23. package/.out/mantine/hooks.js +219 -93
  24. package/.out/mantine/specs/checkbox_hooks.stories.js +13 -1
  25. package/.out/mantine/specs/checkbox_hooks.tests.js +22 -9
  26. package/.out/mantine/specs/create_fields_view.tests.d.ts +1 -0
  27. package/.out/mantine/specs/create_fields_view.tests.js +17 -0
  28. package/.out/mantine/specs/fields_view_hooks.stories.d.ts +6 -2
  29. package/.out/mantine/specs/fields_view_hooks.stories.js +39 -7
  30. package/.out/mantine/specs/fields_view_hooks.tests.js +30 -1
  31. package/.out/mantine/specs/radio_group_hooks.stories.js +13 -1
  32. package/.out/mantine/specs/radio_group_hooks.tests.js +23 -10
  33. package/.out/mantine/specs/select_hooks.stories.js +13 -1
  34. package/.out/mantine/specs/text_input_hooks.stories.js +13 -1
  35. package/.out/mantine/specs/text_input_hooks.tests.js +18 -7
  36. package/.out/mantine/specs/value_input_hooks.stories.js +14 -2
  37. package/.out/tsconfig.tsbuildinfo +1 -1
  38. package/.out/tsup.config.js +2 -9
  39. package/.out/types/merge_validators.js +1 -4
  40. package/.out/util/partial.js +5 -5
  41. package/.out/vitest.workspace.js +2 -10
  42. package/.turbo/turbo-build.log +9 -9
  43. package/.turbo/turbo-check-types.log +1 -1
  44. package/.turbo/turbo-release$colon$exports.log +1 -1
  45. package/core/mobx/form_presenter.ts +15 -14
  46. package/core/mobx/hooks.tsx +197 -0
  47. package/core/mobx/specs/form_presenter.tests.ts +24 -5
  48. package/core/mobx/sub_form_field_adapters.ts +14 -3
  49. package/dist/index.cjs +395 -277
  50. package/dist/index.d.cts +52 -26
  51. package/dist/index.d.ts +52 -26
  52. package/dist/index.js +398 -276
  53. package/mantine/create_fields_view.tsx +66 -31
  54. package/mantine/hooks.tsx +9 -6
  55. package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +194 -197
  56. package/mantine/specs/create_fields_view.tests.ts +29 -0
  57. package/mantine/specs/fields_view_hooks.stories.tsx +58 -15
  58. package/mantine/specs/fields_view_hooks.tests.tsx +26 -0
  59. package/package.json +1 -1
  60. package/core/mobx/hooks.ts +0 -112
@@ -1,10 +1,55 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
36
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
37
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
38
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
39
+ };
40
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
41
+ if (kind === "m") throw new TypeError("Private method is not writable");
42
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
+ };
1
46
  import { jsx as _jsx } from "react/jsx-runtime";
2
47
  import { Checkbox as CheckboxImpl, Pill as PillImpl, Radio as RadioImpl, Select, TextInput as TextInputImpl, } from '@mantine/core';
3
48
  import { Cache, } from '@strictly/base';
4
49
  import { observable, runInAction, } from 'mobx';
5
50
  import { useEffect, useMemo, } from 'react';
6
51
  import { createCheckbox, } from './create_checkbox';
7
- import { createFieldsView } from './create_fields_view';
52
+ import { createFieldsView, } from './create_fields_view';
8
53
  import { createForm } from './create_form';
9
54
  import { createList, DefaultList, } from './create_list';
10
55
  import { createPill, } from './create_pill';
@@ -13,7 +58,7 @@ import { createRadioGroup, } from './create_radio_group';
13
58
  import { createTextInput, } from './create_text_input';
14
59
  import { createValueInput, } from './create_value_input';
15
60
  function SimpleSelect(props) {
16
- return _jsx(Select, { ...props });
61
+ return _jsx(Select, Object.assign({}, props));
17
62
  }
18
63
  export function useMantineFormFields({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }) {
19
64
  const form = useMemo(function () {
@@ -56,94 +101,175 @@ export function useMantineFormFields({ onFieldValueChange, onFieldBlur, onFieldF
56
101
  ]);
57
102
  return form;
58
103
  }
59
- class MantineFormImpl {
60
- textInputCache = new Cache(createTextInput.bind(this));
61
- valueInputCache = new Cache(createValueInput.bind(this));
62
- checkboxCache = new Cache(createCheckbox.bind(this));
63
- radioGroupCache = new Cache(createRadioGroup.bind(this));
64
- radioCache = new Cache(createRadio.bind(this));
65
- pillCache = new Cache(createPill.bind(this));
66
- listCache = new Cache(createList.bind(this));
67
- fieldsViewCache = new Cache(createFieldsView.bind(this));
68
- formCache = new Cache(createForm.bind(this));
69
- @observable.ref
70
- accessor fields;
71
- onFieldValueChange;
72
- onFieldFocus;
73
- onFieldBlur;
74
- onFieldSubmit;
75
- constructor(fields) {
76
- this.fields = fields;
77
- }
78
- textInput(valuePath,
79
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
80
- TextInput = TextInputImpl) {
81
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
82
- return this.textInputCache.retrieveOrCreate(valuePath,
83
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
84
- TextInput);
85
- }
86
- valueInput(valuePath, ValueInput) {
87
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
88
- return this.valueInputCache.retrieveOrCreate(valuePath,
89
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
90
- ValueInput);
91
- }
92
- select(valuePath) {
93
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
94
- return this.valueInputCache.retrieveOrCreate(valuePath,
95
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
96
- SimpleSelect);
97
- }
98
- checkbox(valuePath,
99
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
100
- Checkbox = CheckboxImpl) {
101
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
102
- return this.checkboxCache.retrieveOrCreate(valuePath,
103
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
104
- Checkbox);
105
- }
106
- radioGroup(valuePath,
107
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
108
- RadioGroup = RadioImpl.Group) {
109
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
110
- return this.radioGroupCache.retrieveOrCreate(valuePath,
111
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
112
- RadioGroup);
113
- }
114
- radio(valuePath, value,
115
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
116
- Radio = RadioImpl) {
117
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
118
- return this.radioCache.retrieveOrCreate(valuePath, value,
119
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
120
- Radio);
121
- }
122
- pill(valuePath,
123
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
124
- Pill = PillImpl) {
125
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
126
- return this.pillCache.retrieveOrCreate(valuePath,
127
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
128
- Pill);
129
- }
130
- list(valuePath) {
131
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
132
- return this.listCache.retrieveOrCreate(valuePath, DefaultList);
133
- }
134
- fieldsView(valuePath, FieldsView) {
135
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
136
- return this.fieldsViewCache.retrieveOrCreate(valuePath,
137
- // strip props from component since we lose information in the cache
138
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
139
- FieldsView, this);
140
- }
141
- form(valuePath, Form) {
142
- // strip props from component since we lose information in the cache
143
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
144
- return this.formCache.retrieveOrCreate(valuePath,
145
- // strip props from component since we lose information in the cache
146
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
147
- Form, this);
148
- }
149
- }
104
+ let MantineFormImpl = (() => {
105
+ var _a, _MantineFormImpl_fields_accessor_storage;
106
+ var _b;
107
+ let _fields_decorators;
108
+ let _fields_initializers = [];
109
+ let _fields_extraInitializers = [];
110
+ return _a = class MantineFormImpl {
111
+ get fields() { return __classPrivateFieldGet(this, _MantineFormImpl_fields_accessor_storage, "f"); }
112
+ set fields(value) { __classPrivateFieldSet(this, _MantineFormImpl_fields_accessor_storage, value, "f"); }
113
+ constructor(fields) {
114
+ Object.defineProperty(this, "textInputCache", {
115
+ enumerable: true,
116
+ configurable: true,
117
+ writable: true,
118
+ value: new Cache(createTextInput.bind(this))
119
+ });
120
+ Object.defineProperty(this, "valueInputCache", {
121
+ enumerable: true,
122
+ configurable: true,
123
+ writable: true,
124
+ value: new Cache(createValueInput.bind(this))
125
+ });
126
+ Object.defineProperty(this, "checkboxCache", {
127
+ enumerable: true,
128
+ configurable: true,
129
+ writable: true,
130
+ value: new Cache(createCheckbox.bind(this))
131
+ });
132
+ Object.defineProperty(this, "radioGroupCache", {
133
+ enumerable: true,
134
+ configurable: true,
135
+ writable: true,
136
+ value: new Cache(createRadioGroup.bind(this))
137
+ });
138
+ Object.defineProperty(this, "radioCache", {
139
+ enumerable: true,
140
+ configurable: true,
141
+ writable: true,
142
+ value: new Cache(createRadio.bind(this))
143
+ });
144
+ Object.defineProperty(this, "pillCache", {
145
+ enumerable: true,
146
+ configurable: true,
147
+ writable: true,
148
+ value: new Cache(createPill.bind(this))
149
+ });
150
+ Object.defineProperty(this, "listCache", {
151
+ enumerable: true,
152
+ configurable: true,
153
+ writable: true,
154
+ value: new Cache(createList.bind(this))
155
+ });
156
+ Object.defineProperty(this, "fieldsViewCache", {
157
+ enumerable: true,
158
+ configurable: true,
159
+ writable: true,
160
+ value: new Cache(createFieldsView.bind(this))
161
+ });
162
+ Object.defineProperty(this, "formCache", {
163
+ enumerable: true,
164
+ configurable: true,
165
+ writable: true,
166
+ value: new Cache(createForm.bind(this))
167
+ });
168
+ _MantineFormImpl_fields_accessor_storage.set(this, __runInitializers(this, _fields_initializers, void 0));
169
+ Object.defineProperty(this, "onFieldValueChange", {
170
+ enumerable: true,
171
+ configurable: true,
172
+ writable: true,
173
+ value: __runInitializers(this, _fields_extraInitializers)
174
+ });
175
+ Object.defineProperty(this, "onFieldFocus", {
176
+ enumerable: true,
177
+ configurable: true,
178
+ writable: true,
179
+ value: void 0
180
+ });
181
+ Object.defineProperty(this, "onFieldBlur", {
182
+ enumerable: true,
183
+ configurable: true,
184
+ writable: true,
185
+ value: void 0
186
+ });
187
+ Object.defineProperty(this, "onFieldSubmit", {
188
+ enumerable: true,
189
+ configurable: true,
190
+ writable: true,
191
+ value: void 0
192
+ });
193
+ this.fields = fields;
194
+ }
195
+ textInput(valuePath,
196
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
197
+ TextInput = TextInputImpl) {
198
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
199
+ return this.textInputCache.retrieveOrCreate(valuePath,
200
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
201
+ TextInput);
202
+ }
203
+ valueInput(valuePath, ValueInput) {
204
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
205
+ return this.valueInputCache.retrieveOrCreate(valuePath,
206
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
207
+ ValueInput);
208
+ }
209
+ select(valuePath) {
210
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
211
+ return this.valueInputCache.retrieveOrCreate(valuePath,
212
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
213
+ SimpleSelect);
214
+ }
215
+ checkbox(valuePath,
216
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
217
+ Checkbox = CheckboxImpl) {
218
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
219
+ return this.checkboxCache.retrieveOrCreate(valuePath,
220
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
221
+ Checkbox);
222
+ }
223
+ radioGroup(valuePath,
224
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
225
+ RadioGroup = RadioImpl.Group) {
226
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
227
+ return this.radioGroupCache.retrieveOrCreate(valuePath,
228
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
229
+ RadioGroup);
230
+ }
231
+ radio(valuePath, value,
232
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
233
+ Radio = RadioImpl) {
234
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
235
+ return this.radioCache.retrieveOrCreate(valuePath, value,
236
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
237
+ Radio);
238
+ }
239
+ pill(valuePath,
240
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
241
+ Pill = PillImpl) {
242
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
243
+ return this.pillCache.retrieveOrCreate(valuePath,
244
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
245
+ Pill);
246
+ }
247
+ list(valuePath) {
248
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
249
+ return this.listCache.retrieveOrCreate(valuePath, DefaultList);
250
+ }
251
+ fieldsView(valuePath, FieldsView) {
252
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
253
+ return this.fieldsViewCache.retrieveOrCreate(valuePath,
254
+ // strip props from component since we lose information in the cache
255
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
256
+ FieldsView, this);
257
+ }
258
+ form(valuePath, Form) {
259
+ // strip props from component since we lose information in the cache
260
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
261
+ return this.formCache.retrieveOrCreate(valuePath,
262
+ // strip props from component since we lose information in the cache
263
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
264
+ Form, this);
265
+ }
266
+ },
267
+ _MantineFormImpl_fields_accessor_storage = new WeakMap(),
268
+ (() => {
269
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
270
+ _fields_decorators = [(_b = observable).ref.bind(_b)];
271
+ __esDecorate(_a, null, _fields_decorators, { kind: "accessor", name: "fields", static: false, private: false, access: { has: obj => "fields" in obj, get: obj => obj.fields, set: (obj, value) => { obj.fields = value; } }, metadata: _metadata }, _fields_initializers, _fields_extraInitializers);
272
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
273
+ })(),
274
+ _a;
275
+ })();
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx } from "react/jsx-runtime";
2
13
  import { action } from '@storybook/addon-actions';
3
14
  import { useMantineFormFields } from 'mantine/hooks';
@@ -5,7 +16,8 @@ import { CHECKBOX_LABEL } from './checkbox_constants';
5
16
  function ErrorRenderer({ error }) {
6
17
  return `Error ${error}`;
7
18
  }
8
- function Component({ ...props }) {
19
+ function Component(_a) {
20
+ var props = __rest(_a, []);
9
21
  const inputProps = useMantineFormFields(props);
10
22
  const CheckboxComponent = inputProps.checkbox('$');
11
23
  return (_jsx(CheckboxComponent, { ErrorRenderer: ErrorRenderer, label: CHECKBOX_LABEL }));
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { jsx as _jsx } from "react/jsx-runtime";
2
11
  import { composeStories } from '@storybook/react';
3
12
  import { toArray } from '@strictly/base';
@@ -27,10 +36,12 @@ describe('mantine checkbox hooks', function () {
27
36
  let onFieldValueChange;
28
37
  let wrapper;
29
38
  let checkbox;
30
- beforeEach(async function () {
31
- onFieldValueChange = vi.fn();
32
- wrapper = render(_jsx(Component, { onFieldValueChange: onFieldValueChange }));
33
- checkbox = await wrapper.findByLabelText(CHECKBOX_LABEL);
39
+ beforeEach(function () {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ onFieldValueChange = vi.fn();
42
+ wrapper = render(_jsx(Component, { onFieldValueChange: onFieldValueChange }));
43
+ checkbox = yield wrapper.findByLabelText(CHECKBOX_LABEL);
44
+ });
34
45
  });
35
46
  it('requests toggle', function () {
36
47
  fireEvent.click(checkbox);
@@ -43,11 +54,13 @@ describe('mantine checkbox hooks', function () {
43
54
  let onFieldBlur;
44
55
  let wrapper;
45
56
  let checkbox;
46
- beforeEach(async function () {
47
- onFieldFocus = vi.fn();
48
- onFieldBlur = vi.fn();
49
- wrapper = render((_jsx(Off, { onFieldBlur: onFieldBlur, onFieldFocus: onFieldFocus })));
50
- checkbox = await wrapper.findByLabelText(CHECKBOX_LABEL);
57
+ beforeEach(function () {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ onFieldFocus = vi.fn();
60
+ onFieldBlur = vi.fn();
61
+ wrapper = render((_jsx(Off, { onFieldBlur: onFieldBlur, onFieldFocus: onFieldFocus })));
62
+ checkbox = yield wrapper.findByLabelText(CHECKBOX_LABEL);
63
+ });
51
64
  });
52
65
  describe('focus', function () {
53
66
  beforeEach(function () {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ describe('createFieldsView', () => {
2
+ describe('CallbackMapper', () => {
3
+ it('maps a root paths', () => {
4
+ const callbackMapper = null;
5
+ expectTypeOf().toEqualTypeOf();
6
+ });
7
+ it('maps a simple paths', () => {
8
+ const callbackMapper = null;
9
+ expectTypeOf().toEqualTypeOf();
10
+ });
11
+ it('maps a indexed paths', () => {
12
+ const callbackMapper = null;
13
+ expectTypeOf().toEqualTypeOf();
14
+ });
15
+ });
16
+ });
17
+ export {};
@@ -1,10 +1,14 @@
1
1
  import { type Meta, type StoryObj } from '@storybook/react';
2
2
  import { type FieldsViewProps } from 'core/props';
3
3
  import { type Field } from 'types/field';
4
- declare function Component(props: FieldsViewProps<{
4
+ export declare function ParentFieldLabel(): string;
5
+ export declare function SubFieldLabel(): string;
6
+ declare function Component({ onClickField: onClickFieldImpl, ...props }: FieldsViewProps<{
5
7
  $: Field<string, string>;
6
8
  '$.a': Field<string, string>;
7
- }>): import("react/jsx-runtime").JSX.Element;
9
+ }> & {
10
+ onClickField: (valuePath: '$' | '$.a') => void;
11
+ }): import("react/jsx-runtime").JSX.Element;
8
12
  declare const meta: Meta<typeof Component>;
9
13
  export default meta;
10
14
  type Story = StoryObj<typeof Component>;
@@ -1,21 +1,52 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button, Stack, } from '@mantine/core';
13
+ import { Paper, Stack, Text, } from '@mantine/core';
3
14
  import { action } from '@storybook/addon-actions';
4
15
  import { useMantineFormFields } from 'mantine/hooks';
5
- const onClick = action('some button clicked');
16
+ import { useCallback, useMemo, } from 'react';
17
+ export function ParentFieldLabel() {
18
+ return '$';
19
+ }
20
+ export function SubFieldLabel() {
21
+ return '$ (child)';
22
+ }
6
23
  function ErrorRenderer({ error }) {
7
24
  return `error ${error}`;
8
25
  }
9
- function SubFieldsView(props) {
26
+ function SubFieldsView(_a) {
27
+ var { onClickField: onClickFieldImpl } = _a, props = __rest(_a, ["onClickField"]);
10
28
  const form = useMantineFormFields(props);
11
29
  const TextInput = form.textInput('$');
12
- return (_jsxs(Stack, { children: [_jsx(TextInput, { ErrorRenderer: ErrorRenderer, label: 'sub fields view' }), _jsx(Button, { onClick: props.onClick, children: "Bonus Button" })] }));
30
+ const onClick$ = useCallback(() => {
31
+ onClickFieldImpl('$');
32
+ }, [onClickFieldImpl]);
33
+ return (_jsx(Stack, { children: _jsx(TextInput, { ErrorRenderer: ErrorRenderer, label: SubFieldLabel(), onClick: onClick$ }) }));
13
34
  }
14
- function Component(props) {
35
+ function Component(_a) {
36
+ var { onClickField: onClickFieldImpl } = _a, props = __rest(_a, ["onClickField"]);
15
37
  const form = useMantineFormFields(props);
16
- const FieldsView = form.fieldsView('$.a', SubFieldsView);
38
+ const { Component, callbackMapper, } = form.fieldsView('$.a', SubFieldsView);
17
39
  const TextInput = form.textInput('$');
18
- return (_jsxs(Stack, { children: [_jsx(TextInput, { ErrorRenderer: ErrorRenderer, label: 'fields view' }), _jsx(FieldsView, { onClick: onClick })] }));
40
+ const onClick$ = useCallback(() => {
41
+ onClickFieldImpl('$');
42
+ }, [onClickFieldImpl]);
43
+ const onClickChildField = useMemo(() => {
44
+ return callbackMapper(onClickFieldImpl);
45
+ }, [
46
+ onClickFieldImpl,
47
+ callbackMapper,
48
+ ]);
49
+ return (_jsxs(Stack, { children: [_jsx(TextInput, { ErrorRenderer: ErrorRenderer, label: ParentFieldLabel(), onClick: onClick$ }), _jsxs(Paper, { p: 'sm', withBorder: true, children: [_jsx(Text, { children: "$.a" }), _jsx(Component, { onClickField: onClickChildField })] })] }));
19
50
  }
20
51
  const meta = {
21
52
  component: Component,
@@ -24,6 +55,7 @@ const meta = {
24
55
  onFieldFocus: action('onFieldFocus'),
25
56
  onFieldSubmit: action('onFieldSubmit'),
26
57
  onFieldValueChange: action('onFieldValueChange'),
58
+ onClickField: action('onClickField'),
27
59
  },
28
60
  };
29
61
  export default meta;
@@ -1,12 +1,41 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { jsx as _jsx } from "react/jsx-runtime";
2
11
  import { composeStories } from '@storybook/react';
3
12
  import { toArray } from '@strictly/base';
4
- import { render, } from '@testing-library/react';
13
+ import { fireEvent, render, } from '@testing-library/react';
5
14
  import * as stories from './fields_view_hooks.stories';
6
15
  const composedStories = composeStories(stories);
16
+ const { Empty, } = composedStories;
7
17
  describe('field view hooks', function () {
8
18
  it.each(toArray(composedStories))('renders %s', function (_name, Story) {
9
19
  const wrapper = render(_jsx(Story, {}));
10
20
  expect(wrapper.container).toMatchSnapshot();
11
21
  });
22
+ describe('callbackMapper', () => {
23
+ it.each([
24
+ [
25
+ '$',
26
+ stories.ParentFieldLabel(),
27
+ ],
28
+ [
29
+ '$.a',
30
+ stories.SubFieldLabel(),
31
+ ],
32
+ ])('calls back with the correct paths for field at %s', (valuePath, labelText) => __awaiter(this, void 0, void 0, function* () {
33
+ const onClickField = vi.fn();
34
+ const wrapper = render(_jsx(Empty, { onClickField: onClickField }));
35
+ const element = yield wrapper.findByLabelText(labelText);
36
+ fireEvent.click(element);
37
+ expect(onClickField).toHaveBeenCalledOnce();
38
+ expect(onClickField).toHaveBeenCalledWith(valuePath);
39
+ }));
40
+ });
12
41
  });
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx } from "react/jsx-runtime";
2
13
  import { Stack, } from '@mantine/core';
3
14
  import { action } from '@storybook/addon-actions';
@@ -6,7 +17,8 @@ import { RADIO_GROUP_LABEL, RADIO_LABELS, RADIO_VALUES, } from './radio_group_co
6
17
  function ErrorRenderer({ error }) {
7
18
  return `custom error ${error}`;
8
19
  }
9
- function Component({ ...props }) {
20
+ function Component(_a) {
21
+ var props = __rest(_a, []);
10
22
  const form = useMantineFormFields(props);
11
23
  const RadioGroupComponent = form.radioGroup('$');
12
24
  return (_jsx(RadioGroupComponent, { ErrorRenderer: ErrorRenderer, label: RADIO_GROUP_LABEL, children: _jsx(Stack, { children: RADIO_VALUES.map(function (value) {
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { jsx as _jsx } from "react/jsx-runtime";
2
11
  import { composeStories } from '@storybook/react';
3
12
  import { toArray } from '@strictly/base';
@@ -18,19 +27,23 @@ describe('mantine radio group hooks', function () {
18
27
  let onFieldBlur;
19
28
  let wrapper;
20
29
  let radioGroup;
21
- beforeEach(async function () {
22
- onFieldValueChange = vi.fn();
23
- onFieldFocus = vi.fn();
24
- onFieldBlur = vi.fn();
25
- wrapper = render((_jsx(Empty, { onFieldBlur: onFieldBlur, onFieldFocus: onFieldFocus, onFieldValueChange: onFieldValueChange })));
26
- radioGroup = await wrapper.findByLabelText(RADIO_GROUP_LABEL);
30
+ beforeEach(function () {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ onFieldValueChange = vi.fn();
33
+ onFieldFocus = vi.fn();
34
+ onFieldBlur = vi.fn();
35
+ wrapper = render((_jsx(Empty, { onFieldBlur: onFieldBlur, onFieldFocus: onFieldFocus, onFieldValueChange: onFieldValueChange })));
36
+ radioGroup = yield wrapper.findByLabelText(RADIO_GROUP_LABEL);
37
+ });
27
38
  });
28
39
  describe.each(RADIO_VALUES)('selects %s', function (value) {
29
40
  let radio;
30
- beforeEach(async function () {
31
- const label = RADIO_LABELS[value];
32
- radio = await wrapper.findByLabelText(label);
33
- fireEvent.click(radio);
41
+ beforeEach(function () {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const label = RADIO_LABELS[value];
44
+ radio = yield wrapper.findByLabelText(label);
45
+ fireEvent.click(radio);
46
+ });
34
47
  });
35
48
  it('fires onFieldValueChange', function () {
36
49
  expect(onFieldValueChange).toHaveBeenCalledOnce();