@dakataa/crud-react 1.0.10 → 2.0.0

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 (108) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +439 -169
  3. package/dist/Crud.d.ts +15 -0
  4. package/dist/component/BaseButtonContent.d.ts +10 -0
  5. package/dist/component/Button.d.ts +9 -0
  6. package/dist/component/Dropdown.d.ts +17 -0
  7. package/dist/component/Empty.d.ts +5 -0
  8. package/dist/component/Link.d.ts +6 -0
  9. package/dist/component/LottieAnimation.d.ts +8 -0
  10. package/dist/component/Modal.d.ts +22 -0
  11. package/dist/component/Money.d.ts +7 -0
  12. package/dist/component/Preloader.d.ts +20 -0
  13. package/dist/component/Translation.d.ts +14 -0
  14. package/dist/component/crud/ActionLink.d.ts +10 -0
  15. package/dist/component/crud/CrudLoader.d.ts +29 -0
  16. package/dist/component/crud/DynamicView.d.ts +19 -0
  17. package/dist/component/crud/FiltersView.d.ts +6 -0
  18. package/dist/component/crud/GridView.d.ts +27 -0
  19. package/dist/component/crud/IsListItemActionGranted.d.ts +10 -0
  20. package/dist/component/crud/ItemAction.d.ts +9 -0
  21. package/dist/component/crud/ItemActions.d.ts +7 -0
  22. package/dist/component/crud/ItemLabel.d.ts +6 -0
  23. package/dist/component/crud/ItemValue.d.ts +6 -0
  24. package/dist/component/crud/List.d.ts +19 -0
  25. package/dist/component/crud/ListItem.d.ts +4 -0
  26. package/dist/component/crud/ListView.d.ts +8 -0
  27. package/dist/component/crud/Modify.d.ts +9 -0
  28. package/dist/component/crud/Navigation.d.ts +19 -0
  29. package/dist/component/crud/Paginator.d.ts +2 -0
  30. package/dist/component/crud/ViewLoader.d.ts +14 -0
  31. package/dist/component/crud/batch/BatchActionSelector.d.ts +2 -0
  32. package/dist/component/crud/batch/BatchActionsContext.d.ts +17 -0
  33. package/dist/component/crud/batch/BatchItemSelector.d.ts +4 -0
  34. package/dist/component/crud/form/Form.d.ts +31 -0
  35. package/dist/component/crud/form/FormError.d.ts +6 -0
  36. package/dist/component/crud/form/FormField.d.ts +11 -0
  37. package/dist/component/crud/form/FormGroup.d.ts +76 -0
  38. package/dist/component/crud/form/FormGroupViewLoader.d.ts +2 -0
  39. package/dist/component/crud/form/FormLabel.d.ts +4 -0
  40. package/dist/component/crud/form/FormRequestError.d.ts +14 -0
  41. package/dist/component/crud/form/FormRest.d.ts +2 -0
  42. package/dist/component/crud/form/FormRestError.d.ts +4 -0
  43. package/dist/component/error/ErrorBoundary.d.ts +13 -0
  44. package/dist/component/error/Exception.d.ts +9 -0
  45. package/dist/component/error/HttpException.d.ts +16 -0
  46. package/dist/component/form/Choice.d.ts +24 -0
  47. package/dist/component/form/Collection.d.ts +27 -0
  48. package/dist/component/form/Form.d.ts +62 -0
  49. package/dist/component/form/FormAlert.d.ts +3 -0
  50. package/dist/component/form/FormFieldError.d.ts +6 -0
  51. package/dist/component/form/FormGroup.d.ts +8 -0
  52. package/dist/component/form/FormHelp.d.ts +5 -0
  53. package/dist/component/form/FormLabel.d.ts +7 -0
  54. package/dist/component/form/FormSetting.d.ts +11 -0
  55. package/dist/component/form/FormStore.d.ts +93 -0
  56. package/dist/component/form/Input.d.ts +13 -0
  57. package/dist/component/form/Textarea.d.ts +15 -0
  58. package/dist/component/form/constraint/Contraint.d.ts +6 -0
  59. package/dist/component/form/constraint/NotBlank.d.ts +11 -0
  60. package/dist/component/form/formChoices.d.ts +8 -0
  61. package/dist/component/form/formSession.d.ts +3 -0
  62. package/dist/component/form/formView.d.ts +35 -0
  63. package/dist/component/router/Route.d.ts +11 -0
  64. package/dist/component/templating/Template.d.ts +17 -0
  65. package/dist/component/templating/TemplateBlock.d.ts +8 -0
  66. package/dist/component/templating/TemplateExtend.d.ts +9 -0
  67. package/dist/component/templating/TemplateParentBlock.d.ts +5 -0
  68. package/dist/context/ActionContext.d.ts +46 -0
  69. package/dist/context/AlertContext.d.ts +52 -0
  70. package/dist/context/ConfigContext.d.ts +34 -0
  71. package/dist/context/CrudProvider.d.ts +7 -0
  72. package/dist/context/GetData.d.ts +43 -0
  73. package/dist/context/ListContext.d.ts +69 -0
  74. package/dist/context/ListItemContext.d.ts +8 -0
  75. package/dist/context/LoaderContext.d.ts +5 -0
  76. package/dist/context/ModalContext.d.ts +18 -0
  77. package/dist/context/NamespaceContext.d.ts +5 -0
  78. package/dist/crud-react.css +2 -1
  79. package/dist/crud-react.js +4014 -2955
  80. package/dist/denied-Emsz18Y8.js +688 -0
  81. package/dist/helper/ObjectUtils.d.ts +3 -0
  82. package/dist/helper/PathUtils.d.ts +12 -0
  83. package/dist/helper/StringUtils.d.ts +3 -0
  84. package/dist/info-C897Uj_w.js +626 -0
  85. package/dist/layout/default/Base.d.ts +5 -0
  86. package/dist/layout/default/Error.d.ts +11 -0
  87. package/dist/layout/default/Main.d.ts +4 -0
  88. package/dist/main.d.ts +91 -79
  89. package/dist/setupTests.d.ts +0 -0
  90. package/dist/success-YbPKEx5j.js +559 -0
  91. package/dist/type/ActionRequestType.d.ts +17 -0
  92. package/dist/type/ActionType.d.ts +15 -0
  93. package/dist/type/ColumnType.d.ts +24 -0
  94. package/dist/type/ExceptionType.d.ts +6 -0
  95. package/dist/type/FormType.d.ts +6 -0
  96. package/dist/type/FormViewType.d.ts +96 -0
  97. package/dist/type/ListMetaType.d.ts +8 -0
  98. package/dist/type/ListType.d.ts +32 -0
  99. package/dist/type/ModifyType.d.ts +15 -0
  100. package/dist/type/RedirectType.d.ts +7 -0
  101. package/dist/type/RouteType.d.ts +7 -0
  102. package/dist/type/ViewType.d.ts +15 -0
  103. package/dist/warning-DJITKJj5.js +630 -0
  104. package/package.json +86 -81
  105. package/dist/denied-CgoMpaA7.js +0 -27
  106. package/dist/info-D-NzIEYs.js +0 -144
  107. package/dist/success-Bu_BJcf1.js +0 -27
  108. package/dist/warning-B1nr7TsB.js +0 -27
package/README.md CHANGED
@@ -26,6 +26,7 @@ The library provides:
26
26
  9. [Hooks and contexts](#hooks-and-contexts)
27
27
  10. [Core components](#core-components)
28
28
  11. [Troubleshooting](#troubleshooting)
29
+ 12. [Code style](#code-style)
29
30
 
30
31
  ## How it works
31
32
 
@@ -67,47 +68,52 @@ If your project does not already include Bootstrap styles, add your theme or Boo
67
68
  ## Quick start
68
69
 
69
70
  ```tsx
70
- import { StrictMode } from 'react';
71
- import { createRoot } from 'react-dom/client';
71
+ import { StrictMode } from "react";
72
+ import { createRoot } from "react-dom/client";
72
73
  import {
73
- Crud,
74
- CrudConfiguration,
75
- CrudLoader,
76
- MainLayout,
77
- Outlet,
78
- Route,
79
- Router,
80
- } from '@dakataa/crud-react';
74
+ Crud,
75
+ CrudConfiguration,
76
+ CrudLoader,
77
+ MainLayout,
78
+ Outlet,
79
+ Route,
80
+ Router
81
+ } from "@dakataa/crud-react";
81
82
 
82
- const templates = import.meta.glob('./crud/**');
83
+ const templates = import.meta.glob("./crud/**");
83
84
 
84
85
  CrudConfiguration({
85
- connection: {
86
- baseURL: 'https://project.local',
87
- headers: {
88
- Accept: 'application/json',
86
+ connection: {
87
+ baseURL: "https://project.local",
88
+ headers: {
89
+ Accept: "application/json"
90
+ }
89
91
  },
90
- },
91
- templates,
92
+ templates
92
93
  });
93
94
 
94
- createRoot(document.getElementById('root')!).render(
95
- <StrictMode>
96
- <Crud
97
- config={{
98
- templates,
99
- currency: 'BGN',
100
- locale: 'bg',
101
- env: import.meta.env.CRUD_ENV,
102
- }}
103
- >
104
- <Router>
105
- <Route element={<MainLayout><Outlet /></MainLayout>}>
106
- <Route path="*" element={<CrudLoader />} />
107
- </Route>
108
- </Router>
109
- </Crud>
110
- </StrictMode>
95
+ createRoot(document.getElementById("root")!).render(
96
+ <StrictMode>
97
+ <Crud
98
+ config={{
99
+ templates,
100
+ currency: "BGN",
101
+ locale: "bg",
102
+ timezone: "UTC",
103
+ env: import.meta.env.CRUD_ENV
104
+ }}>
105
+ <Router>
106
+ <Route
107
+ element={
108
+ <MainLayout>
109
+ <Outlet />
110
+ </MainLayout>
111
+ }>
112
+ <Route path="*" element={<CrudLoader />} />
113
+ </Route>
114
+ </Router>
115
+ </Crud>
116
+ </StrictMode>
111
117
  );
112
118
  ```
113
119
 
@@ -121,16 +127,16 @@ There are two configuration layers:
121
127
  ### `CrudConfiguration`
122
128
 
123
129
  ```ts
124
- import { CrudConfiguration } from '@dakataa/crud-react';
130
+ import { CrudConfiguration } from "@dakataa/crud-react";
125
131
 
126
132
  CrudConfiguration({
127
- connection: {
128
- baseURL: 'https://crud-api.local',
129
- headers: {
130
- Accept: 'application/json',
133
+ connection: {
134
+ baseURL: "https://crud-api.local",
135
+ headers: {
136
+ Accept: "application/json"
137
+ }
131
138
  },
132
- },
133
- templates: import.meta.glob('./crud/**'),
139
+ templates: import.meta.glob("./crud/**")
134
140
  });
135
141
  ```
136
142
 
@@ -138,19 +144,26 @@ CrudConfiguration({
138
144
 
139
145
  ```ts
140
146
  type Config = {
141
- env?: 'prod' | 'dev' | 'test' | string;
142
- link?: {
143
- path?: string;
144
- prefix?: string;
145
- includePrefix?: boolean;
146
- };
147
- templates?: { [path: string]: () => Promise<any> };
148
- locale?: string;
149
- currency?: string;
150
- options?: {
151
- HTMLTableElement: React.HTMLAttributes<HTMLTableElement>;
152
- GridView: React.HTMLAttributes<HTMLDivElement>;
153
- };
147
+ env?: "prod" | "dev" | "test" | string;
148
+ link?: {
149
+ path?: string;
150
+ prefix?: string;
151
+ includePrefix?: boolean;
152
+ };
153
+ templates?: { [path: string]: () => Promise<any> };
154
+ locale?: string;
155
+ currency?: string;
156
+ translate?: (
157
+ key: string,
158
+ options?: {
159
+ domain?: string;
160
+ properties?: { [key: string]: string | number | null };
161
+ }
162
+ ) => string;
163
+ options?: {
164
+ HTMLTableElement: React.HTMLAttributes<HTMLTableElement>;
165
+ GridView: React.HTMLAttributes<HTMLDivElement>;
166
+ };
154
167
  };
155
168
  ```
156
169
 
@@ -160,11 +173,37 @@ type Config = {
160
173
  - `templates`: runtime template overrides merged with global templates
161
174
  - `locale`: used by components such as `Money`
162
175
  - `currency`: default currency for money formatting
176
+ - `translate`: used by `Translation` and form components for labels, help text, placeholders, tooltips (`title`), accessible labels (`aria-label`, `aria-description`), and choice group labels. `Translation` calls this callback directly; it no longer loads a template. It translates `translationKey` when provided, otherwise joins text children into a single key, and forwards `domain` and `properties`. Without this callback, children are preserved; when children are absent, the translation key is returned unchanged. Children containing React elements are preserved unless an explicit translation key is provided.
163
177
  - `link.prefix`: useful when the CRUD UI is mounted under a sub-path such as `/admin`
164
178
  - `link.path`: lets you force `CrudLoader` to resolve a custom path instead of `location.pathname + location.search`
165
179
  - `options.HTMLTableElement`: default props for generated tables
166
180
  - `options.GridView`: default props for the `GridView` wrapper
167
181
 
182
+ Connect your translation library once when configuring `Crud`. Forms can then pass translation keys directly:
183
+
184
+ ```tsx
185
+ <Crud
186
+ config={{
187
+ translate: (key, options) =>
188
+ t(key, {
189
+ ...options?.properties,
190
+ ...(options?.domain ? { ns: options.domain } : {})
191
+ }),
192
+ templates
193
+ }}>
194
+ <FormGroup
195
+ name="vat"
196
+ options={{
197
+ label: "VAT",
198
+ attr: { "aria-label": "Registered for VAT" },
199
+ label_attr: { title: "Registered for VAT" }
200
+ }}
201
+ />
202
+ </Crud>
203
+ ```
204
+
205
+ Custom form templates can use `UseTranslate()` where they render text that needs translation. Form attribute objects are passed through; only the specific text properties above are translated at their render sites.
206
+
168
207
  ## Backend contract
169
208
 
170
209
  For the library to work, your backend must expose action metadata and action payloads in the expected format.
@@ -181,17 +220,17 @@ Each action looks like this:
181
220
 
182
221
  ```ts
183
222
  type ActionType = {
184
- entity: string;
185
- namespace?: string;
186
- name: string;
187
- title?: string;
188
- visibility?: 'list' | 'object' | 'internal';
189
- permission?: string;
190
- route?: {
191
- path: string;
192
- defaults?: { [key: string]: string };
193
- methods?: string[];
194
- };
223
+ entity: string;
224
+ namespace?: string;
225
+ name: string;
226
+ title?: string;
227
+ visibility?: "list" | "object" | "internal";
228
+ permission?: string;
229
+ route?: {
230
+ path: string;
231
+ defaults?: { [key: string]: string };
232
+ methods?: string[];
233
+ };
195
234
  };
196
235
  ```
197
236
 
@@ -199,26 +238,26 @@ Example:
199
238
 
200
239
  ```json
201
240
  [
202
- {
203
- "entity": "Article",
204
- "namespace": "blog",
205
- "name": "list",
206
- "title": "Articles",
207
- "visibility": "list",
208
- "route": {
209
- "path": "/article"
210
- }
211
- },
212
- {
213
- "entity": "Article",
214
- "namespace": "blog",
215
- "name": "edit",
216
- "title": "Edit article",
217
- "visibility": "object",
218
- "route": {
219
- "path": "/article/{id}/edit"
241
+ {
242
+ "entity": "Article",
243
+ "namespace": "blog",
244
+ "name": "list",
245
+ "title": "Articles",
246
+ "visibility": "list",
247
+ "route": {
248
+ "path": "/article"
249
+ }
250
+ },
251
+ {
252
+ "entity": "Article",
253
+ "namespace": "blog",
254
+ "name": "edit",
255
+ "title": "Edit article",
256
+ "visibility": "object",
257
+ "route": {
258
+ "path": "/article/{id}/edit"
259
+ }
220
260
  }
221
- }
222
261
  ]
223
262
  ```
224
263
 
@@ -228,24 +267,24 @@ The default list view expects a payload compatible with:
228
267
 
229
268
  ```ts
230
269
  type ListType = {
231
- title: string | null;
232
- entity: {
233
- name: string;
234
- columns: ColumnType[];
235
- primaryColumn: ColumnType;
236
- data: {
237
- items: Array<{ [key: string]: any }>;
238
- meta: ListMetaType;
270
+ title: string | null;
271
+ entity: {
272
+ name: string;
273
+ columns: ColumnType[];
274
+ primaryColumn: ColumnType;
275
+ data: {
276
+ items: Array<{ [key: string]: any }>;
277
+ meta: ListMetaType;
278
+ };
279
+ acl: { [key: string]: Array<number | string> };
239
280
  };
240
- acl: { [key: string]: Array<number | string> };
241
- };
242
- form: {
243
- [key: string]: FormType;
244
- filter: FormType;
245
- batch: FormType;
246
- };
247
- sort: { [key: string]: 'ASC' | 'DESC' | null };
248
- action: { [key: string]: ActionType };
281
+ form: {
282
+ [key: string]: FormType;
283
+ filter: FormType;
284
+ batch: FormType;
285
+ };
286
+ sort: { [key: string]: "ASC" | "DESC" | null };
287
+ action: { [key: string]: ActionType };
249
288
  };
250
289
  ```
251
290
 
@@ -263,11 +302,11 @@ The default add/edit view expects:
263
302
 
264
303
  ```ts
265
304
  type ModifyType = {
266
- title: string | null;
267
- object: { [key: string]: any } | null;
268
- form: { [key: string]: FormType };
269
- messages: { [key: string]: string[] };
270
- redirect?: RedirectType;
305
+ title: string | null;
306
+ object: { [key: string]: any } | null;
307
+ form: { [key: string]: FormType };
308
+ messages: { [key: string]: string[] };
309
+ redirect?: RedirectType;
271
310
  };
272
311
  ```
273
312
 
@@ -280,7 +319,7 @@ Dynamic views are loaded from the `templates` object you pass through `CrudConfi
280
319
  Typical setup:
281
320
 
282
321
  ```ts
283
- const templates = import.meta.glob('./crud/**');
322
+ const templates = import.meta.glob("./crud/**");
284
323
  ```
285
324
 
286
325
  The resolver looks for files in this order:
@@ -309,37 +348,44 @@ View names are normalized to PascalCase, so:
309
348
  ### Minimal override example
310
349
 
311
350
  ```tsx
312
- import { AsTemplate, Block, Extend, Parent, Translation as T } from '@dakataa/crud-react';
313
-
314
- export default AsTemplate(() => {
315
- return (
316
- <section className="custom-list">
317
- <header>
318
- <Block name="title">
319
- <h2><T>Custom list title</T></h2>
320
- </Block>
321
- </header>
322
-
323
- <main>
324
- <Block name="content" />
325
- </main>
326
- </section>
327
- );
328
- }, { name: 'list' });
351
+ import { AsTemplate, Block, Extend, Parent, Translation as T } from "@dakataa/crud-react";
352
+
353
+ export default AsTemplate(
354
+ () => {
355
+ return (
356
+ <section className="custom-list">
357
+ <header>
358
+ <Block name="title">
359
+ <h2>
360
+ <T>Custom list title</T>
361
+ </h2>
362
+ </Block>
363
+ </header>
364
+
365
+ <main>
366
+ <Block name="content" />
367
+ </main>
368
+ </section>
369
+ );
370
+ },
371
+ { name: "list" }
372
+ );
329
373
  ```
330
374
 
331
375
  Example of extending an existing template block:
332
376
 
333
377
  ```tsx
334
- import { Extend, Parent } from '@dakataa/crud-react';
378
+ import { Extend, Parent } from "@dakataa/crud-react";
335
379
 
336
380
  export default function CustomModifyNavigation() {
337
- return (
338
- <Extend name="navigation">
339
- <Parent />
340
- <a href="/help" className="btn btn-sm btn-outline-secondary">Help</a>
341
- </Extend>
342
- );
381
+ return (
382
+ <Extend name="navigation">
383
+ <Parent />
384
+ <a href="/help" className="btn btn-sm btn-outline-secondary">
385
+ Help
386
+ </a>
387
+ </Extend>
388
+ );
343
389
  }
344
390
  ```
345
391
 
@@ -348,16 +394,21 @@ export default function CustomModifyNavigation() {
348
394
  The package exports its own lightweight router:
349
395
 
350
396
  ```tsx
351
- import { Router, Route, Outlet } from '@dakataa/crud-react';
397
+ import { Router, Route, Outlet } from "@dakataa/crud-react";
352
398
  ```
353
399
 
354
400
  Example:
355
401
 
356
402
  ```tsx
357
403
  <Router>
358
- <Route element={<MainLayout><Outlet /></MainLayout>}>
359
- <Route path="*" element={<CrudLoader />} />
360
- </Route>
404
+ <Route
405
+ element={
406
+ <MainLayout>
407
+ <Outlet />
408
+ </MainLayout>
409
+ }>
410
+ <Route path="*" element={<CrudLoader />} />
411
+ </Route>
361
412
  </Router>
362
413
  ```
363
414
 
@@ -367,8 +418,8 @@ Example:
367
418
 
368
419
  - `getAction(entity, name, namespace?)`
369
420
  - `getActionByPath(path)`
370
- - `getOnClickActionByPath(path)`
371
- - `generateActionLink(onClickAction)`
421
+ - `getActionRequestByPath(path)`
422
+ - `generateActionLink(actionRequest)`
372
423
  - `generateRoute(route, parameters?, query?)`
373
424
  - `generatePath(pattern, parameters?, query?)`
374
425
  - `navigate(to, replace?)`
@@ -379,15 +430,14 @@ If your admin panel lives under `/admin`, configure a prefix:
379
430
 
380
431
  ```tsx
381
432
  <Crud
382
- config={{
383
- link: {
384
- prefix: 'admin',
385
- },
386
- }}
387
- >
388
- <Router>
389
- <Route path="*" element={<CrudLoader />} />
390
- </Router>
433
+ config={{
434
+ link: {
435
+ prefix: "admin"
436
+ }
437
+ }}>
438
+ <Router>
439
+ <Route path="*" element={<CrudLoader />} />
440
+ </Router>
391
441
  </Crud>
392
442
  ```
393
443
 
@@ -397,6 +447,10 @@ This lets internal CRUD routes stay backend-friendly while browser URLs include
397
447
 
398
448
  The add/edit screens are driven by `form.modify.view`.
399
449
 
450
+ See the [Form API reference](src/component/form/README.md) for props, hooks,
451
+ value lifecycle and short implementation examples. Version 2 removes the tuple
452
+ `UseForm` API; see the [migration notes](src/component/form/README.md#migration-from-v1).
453
+
400
454
  Default behavior:
401
455
 
402
456
  1. `CrudLoader` resolves the current action
@@ -409,10 +463,10 @@ Default behavior:
409
463
  ### Default form rendering
410
464
 
411
465
  ```tsx
412
- import { Modify } from '@dakataa/crud-react';
466
+ import { Modify } from "@dakataa/crud-react";
413
467
 
414
468
  export default function EditArticle() {
415
- return <Modify />;
469
+ return <Modify />;
416
470
  }
417
471
  ```
418
472
 
@@ -422,28 +476,180 @@ If you need custom rendering around the form schema:
422
476
 
423
477
  ```tsx
424
478
  import {
425
- CrudForm,
426
- FormFieldViewLoader,
427
- FormRest,
428
- FormRestError,
429
- FormViewProvider,
430
- } from '@dakataa/crud-react';
479
+ CrudForm,
480
+ FormFieldViewLoader,
481
+ FormGroup,
482
+ FormRest,
483
+ FormRestError,
484
+ FormViewProvider
485
+ } from "@dakataa/crud-react";
431
486
  ```
432
487
 
433
488
  Useful helpers:
434
489
 
435
490
  - `UseFormView()`: access the current form view node
491
+ - `useFormValue(field)`: observe one store value without registering a control
492
+ - `useFormValues(fields)`: observe several values for dependent UI or calculations
493
+ - `choiceToken`, `choiceList`, `selectionTokens`: normalize choices and selection values
436
494
  - `FormFieldViewLoader`: render fields from the current schema node
495
+ - `FormGroup`: render the current schema node or one of its direct children
437
496
  - `FormRest`: render non-explicitly-rendered fields
438
497
  - `FormRestError`: render non-explicitly-rendered errors
439
498
 
499
+ ### Current values and field lifecycle
500
+
501
+ `FormView` describes the backend schema and initial values. Treat its nodes as
502
+ immutable: modifying `UseFormView().form.data` does not update an editable field.
503
+ The base `Form` owns current values and collection rows, so hiding and remounting
504
+ fields preserves drafts, additions, and deletions. A field subscribes to its own
505
+ value and errors rather than rerendering the entire form on each edit.
506
+
507
+ Use `UseFormView().setValue(relativeName, value)` or the existing `FormRef`
508
+ `setValue`, `setValues`, and `setFormData` methods for programmatic changes.
509
+ Values can be set while a field is unmounted. `setValue()` followed immediately
510
+ by `getFormData()` or `submit()` sees the updated values. Ordinary native inputs
511
+ in custom templates continue to participate in native submission; use the
512
+ binding hook when their drafts must also survive unmounting.
513
+
514
+ ```tsx
515
+ import { useFormField, UseFormView } from "@dakataa/crud-react";
516
+
517
+ function CustomTitle() {
518
+ const { form: view } = UseFormView();
519
+ const field = useFormField(view);
520
+
521
+ return (
522
+ <input
523
+ name={field.name}
524
+ value={Array.isArray(field.value) ? "" : (field.value ?? "")}
525
+ aria-invalid={field.errors.length > 0}
526
+ onChange={(event) => {
527
+ field.change(event.target.value);
528
+ }}
529
+ />
530
+ );
531
+ }
532
+ ```
533
+
534
+ The hook returns `value`, `errors`, `dirty`, the HTML `name`, and `change`.
535
+ `change` also accepts a function of the current value for grouped selections.
536
+ Checkbox/radio components control `checked` separately from their submitted
537
+ option token. File inputs remain native; reset clears their selection, and
538
+ remounting their DOM node does not restore the browser file picker.
539
+
540
+ `FormField` and `FormGroup` still shallowly apply `options` without mutating the
541
+ backend node. An override of `data`, `value`, or `checked` supplies a local
542
+ initial default once per field/session. Update a current value through the form
543
+ API rather than changing that override. Binding-owned HTML attributes (`value`,
544
+ `defaultValue`, `checked`, `defaultChecked`, and `name`) cannot be overridden via
545
+ `attr`. Existing event callbacks are composed with the binding; preventing the
546
+ change event cancels the edit.
547
+
548
+ A refresh of the same record updates pristine fields and the reset baseline
549
+ while retaining drafts and local collection changes. An invalid submit keeps
550
+ the original baseline and applies backend errors. A successful submit adopts
551
+ persisted values as the new baseline, retaining any edits made after submission.
552
+ Collection responses must retain stable row names; row identity is never inferred
553
+ from its position. Changing the edited record starts a new form session. Filter
554
+ forms start a new session when the applied query changes, excluding refresh
555
+ `_ts` parameters.
556
+
557
+ Both a native reset button and `FormRef.reset()` restore the current baseline,
558
+ including collection rows, and clear errors and submission status. Preserving a
559
+ cached value does not automatically submit it: unmounted and disabled controls
560
+ are excluded, while mounted hidden controls, repeated names, native controls,
561
+ files, and the submit button retain standard `FormData` behavior.
562
+
563
+ ### `FormGroup`
564
+
565
+ `FormGroup` renders one node from the form schema exposed by the nearest
566
+ `FormViewProvider`. In a standard add/edit screen, `CrudForm` supplies this
567
+ provider automatically.
568
+
569
+ ```tsx
570
+ import { FormGroup } from "@dakataa/crud-react";
571
+
572
+ export default function ArticleFields() {
573
+ return (
574
+ <>
575
+ <FormGroup name="title" />
576
+ <FormGroup name="content" />
577
+ </>
578
+ );
579
+ }
580
+ ```
581
+
582
+ The `name` prop selects a direct child of the current schema node. If `name` is
583
+ omitted, the current node itself is rendered. Container nodes are traversed
584
+ recursively; leaf nodes use the standard field group with its label, input,
585
+ validation error, and help text.
586
+
587
+ #### Props
588
+
589
+ The component accepts the exported `FormGroupProps` type:
590
+
591
+ ```ts
592
+ export type FormGroupProps = {
593
+ name?: string;
594
+ options?: Omit<FormViewType, "type">;
595
+ optional?: boolean;
596
+ };
597
+ ```
598
+
599
+ Consumers can import it with
600
+ `import type { FormGroupProps } from '@dakataa/crud-react'`.
601
+
602
+ `FormGroupProps` describes the complete props object. The table below shows the
603
+ type of each individual property; therefore `options` is listed with its own
604
+ `Omit<FormViewType, 'type'>` type.
605
+
606
+ | Prop | Type | Default | Description |
607
+ | ---------- | ---------------------------- | ------------ | ----------------------------------------------------------------------------------- |
608
+ | `name` | `string` | current view | Selects a direct child of the current form view. Dotted paths are not supported. |
609
+ | `options` | `Omit<FormViewType, 'type'>` | `{}` | Applies shallow schema overrides for this render. The field type cannot be changed. |
610
+ | `optional` | `boolean` | `false` | Returns `null` when the selected child is missing instead of throwing an error. |
611
+
612
+ Use `options` to customize the selected schema node without changing the
613
+ backend response:
614
+
615
+ ```tsx
616
+ <FormGroup
617
+ name="price"
618
+ options={{
619
+ label: "Unit price",
620
+ help: "Enter the amount before tax.",
621
+ attr: { className: "form-control text-end" }
622
+ }}
623
+ />
624
+ ```
625
+
626
+ Overrides are shallow. Supplying an object-valued property such as `attr` or
627
+ `children` replaces that property completely; it is not deep-merged.
628
+
629
+ For schemas where a field is conditional, opt into missing-field handling
630
+ explicitly:
631
+
632
+ ```tsx
633
+ <FormGroup name="companyNumber" optional />
634
+ <FormField name="companyNumber" optional />
635
+ ```
636
+
637
+ Without `optional`, a missing child throws
638
+ `Missing Provided Form View to Form Group: companyNumber`. Rendering outside a
639
+ `FormViewProvider` throws `UseFormView must be used within a FormViewProvider.`
640
+
641
+ `FormField` also accepts `optional`, which defaults to `false`. When the named
642
+ child is missing, it returns `null` if `optional` is set; otherwise it throws
643
+ `Missing Form View for FormField: companyNumber`. Existing fields still render
644
+ normally, including their `required` validation.
645
+
440
646
  ## Hooks and contexts
441
647
 
442
648
  ### `UseActions()`
443
649
 
444
650
  Access loaded actions, route matching, link generation and programmatic navigation.
445
651
 
446
- ### `UseCurrentAction()`
652
+ ### `UseCurrentActionRequest()`
447
653
 
448
654
  Get the current resolved CRUD action and update it from inside a view.
449
655
 
@@ -457,22 +663,22 @@ Fetch arbitrary data through the configured CRUD requester.
457
663
 
458
664
  ```tsx
459
665
  const { results, status, refresh, cancel } = GetData({
460
- path: '/article',
666
+ path: "/article"
461
667
  });
462
668
  ```
463
669
 
464
670
  ### `GetDataByAction(...)`
465
671
 
466
- Fetch data using an `OnClickAction`.
672
+ Fetch data using an `ActionRequest`.
467
673
 
468
674
  ```tsx
469
675
  const data = GetDataByAction({
470
- action: {
471
- action: {
472
- entity: 'Article',
473
- name: 'list',
474
- },
475
- },
676
+ actionRequest: {
677
+ action: {
678
+ entity: "Article",
679
+ name: "list"
680
+ }
681
+ }
476
682
  });
477
683
  ```
478
684
 
@@ -480,12 +686,13 @@ Returned shape:
480
686
 
481
687
  ```ts
482
688
  type GetDataType = {
483
- url: string;
484
- status: number;
485
- results: any;
486
- response?: Response;
487
- refresh: () => void;
488
- cancel: () => void;
689
+ url: string;
690
+ status: number;
691
+ results: any;
692
+ response?: Response;
693
+ refresh: () => void;
694
+ cancel: () => void;
695
+ registerErrorHandler?: (handler: (error: unknown) => boolean) => () => void;
489
696
  };
490
697
  ```
491
698
 
@@ -597,3 +804,66 @@ If you want, the next useful step is to split this README into:
597
804
  - a `/docs` folder with standalone guides such as `backend-contract.md`, `templates.md`, `forms.md`, and `recipes.md`
598
805
 
599
806
  That usually makes the onboarding flow easier for new users.
807
+
808
+ ## Tests
809
+
810
+ Tests live in `tests/`, grouped by the behavior they verify:
811
+
812
+ - `tests/form/`: form APIs, controls, values, state and value lifecycle.
813
+ - `tests/form/choices.test.tsx`: choice helpers, selection, placeholders and transforms.
814
+ - `tests/crud/`: CRUD form requests and response handling.
815
+
816
+ Use descriptive file names without repeating the feature folder name. Add related
817
+ cases to the existing file and organize them with shallow `describe` groups.
818
+ Split large files by behavior within their feature folder when needed. A test
819
+ that uses a Choice control to verify a general form API stays with that API.
820
+
821
+ ```bash
822
+ npm test
823
+ npm run test:form
824
+ npm run test:crud
825
+ npm test -- tests/form/choices.test.tsx
826
+ ```
827
+
828
+ ## Code style
829
+
830
+ This project and the related React projects use the same formatting profile:
831
+
832
+ - Four spaces, UTF-8, LF line endings, and a final newline.
833
+ - Double quotes by default, semicolons, no trailing commas, and a target line width of 100.
834
+ - Braces for all control statements, no nested ternaries, and top-level `import type` declarations.
835
+ - Concise bodies for simple arrow functions; multiline blocks for multiple statements or complex logic.
836
+
837
+ `.editorconfig` provides basic editor settings. `.prettierrc.json` controls formatting,
838
+ and `eslint.code-style.js` defines the shared code rules. ESLint uses
839
+ `eslint-config-prettier` to disable formatting rules that conflict with Prettier.
840
+ The formatter and ESLint versions are pinned in `package.json`.
841
+
842
+ For specific files, use the project-local tools:
843
+
844
+ ```bash
845
+ npm exec -- eslint --fix path/to/file.tsx
846
+ npm exec -- prettier --write path/to/file.tsx
847
+ npm exec -- eslint path/to/file.tsx
848
+ npm exec -- prettier --check path/to/file.tsx
849
+ ```
850
+
851
+ Repository-wide commands are available as `npm run format`, `npm run format:check`,
852
+ `npm run lint`, and `npm run lint:fix`. The checks also report legacy code that
853
+ has not yet adopted this profile. Format edited files during normal work;
854
+ repository-wide style migration should be a separate change.
855
+
856
+ ### PhpStorm
857
+
858
+ 1. Enable EditorConfig support under **Settings → Editor → Code Style**.
859
+ 2. Open **Settings → Languages & Frameworks → JavaScript → Prettier**.
860
+ 3. Select the project's `node_modules/prettier` package. Enable **Run on save** and
861
+ **Run on 'Reformat Code' action**. If necessary, select manual configuration to
862
+ expose the reformat setting. Use `**/*.{js,jsx,ts,tsx,cjs,mjs,json,css,scss}` as the
863
+ file pattern and keep the repository's `.prettierignore` enabled.
864
+ 4. Enable automatic ESLint configuration under **JavaScript → Code Quality Tools → ESLint**.
865
+
866
+ Other editors and agents should use the same project-local formatter, ESLint,
867
+ and configuration files. When adding a related project, copy the shared
868
+ `.editorconfig`, `.prettierrc.json`, `.prettierignore`, and `eslint.code-style.js`,
869
+ import the code rules into its ESLint configuration, and pin the same tool versions.