@dakataa/crud-react 1.0.9 → 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 +837 -96
  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 +4015 -2881
  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 -77
  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
@@ -1,128 +1,869 @@
1
- # CRUD Dashboard React (Frontend)
2
- This is a frontend react implementation of CRUD.
3
- Easy way to create CRUD ADMIN panel / Dashboard for your software.
4
-
5
- This library depend on [@dakataa/crud](https://github.com/dakataa/crud) which is CRUD REST API; however, it can also be used as a standalone
6
- if you provide the correct data structure. The components are based on the Bootstrap Framework.
7
-
8
- ### Table of Contents
9
- 1. [Installation](#installation)
10
- 2. [Configuration](#configuration)
11
- 3. [Examples](#examples)
12
- 4. [Components](#components)
13
- - [Grid](#GridView)
14
- - [Form](#form)
15
- - [Templating](#templates)
16
- - [Dynamic View](#dynamic-view)
17
- - [Modal](#modal)
18
- - [Alert](#alert)
19
- - [Navigation](#navigation)
20
- 5. Layout
21
- 6. [Hooks](#hooks)
22
-
23
-
24
- ### Installation
25
-
26
- #### Using npm:
27
- ```shell
1
+ # CRUD Dashboard React
2
+
3
+ `@dakataa/crud-react` is a React frontend library for building CRUD admin panels and dashboards.
4
+
5
+ It is designed to work with [`@dakataa/crud`](https://github.com/dakataa/crud), but it can also run against any backend that returns the same action and view data structures.
6
+
7
+ The library provides:
8
+
9
+ - automatic CRUD route resolution from backend actions
10
+ - default list/add/edit screens
11
+ - dynamic template overrides per namespace
12
+ - schema-driven form rendering
13
+ - modal and alert helpers
14
+ - Bootstrap-based UI components
15
+
16
+ ## Contents
17
+
18
+ 1. [How it works](#how-it-works)
19
+ 2. [Installation](#installation)
20
+ 3. [Quick start](#quick-start)
21
+ 4. [Configuration](#configuration)
22
+ 5. [Backend contract](#backend-contract)
23
+ 6. [Templates and dynamic views](#templates-and-dynamic-views)
24
+ 7. [Routing](#routing)
25
+ 8. [Forms](#forms)
26
+ 9. [Hooks and contexts](#hooks-and-contexts)
27
+ 10. [Core components](#core-components)
28
+ 11. [Troubleshooting](#troubleshooting)
29
+ 12. [Code style](#code-style)
30
+
31
+ ## How it works
32
+
33
+ The library loads available CRUD actions from `/_crud/actions`, matches the current URL to one of those actions, fetches the data for that action, and renders the matching view.
34
+
35
+ The default built-in views are:
36
+
37
+ - `list`
38
+ - `add`
39
+ - `edit`
40
+
41
+ Each view can be overridden with files loaded through `import.meta.glob('./crud/**')`.
42
+
43
+ ## Installation
44
+
45
+ Install the package:
46
+
47
+ ```bash
28
48
  npm install @dakataa/crud-react
29
49
  ```
30
50
 
31
- #### Using yarn:
32
- ```shell
51
+ or:
52
+
53
+ ```bash
33
54
  yarn add @dakataa/crud-react
34
55
  ```
35
56
 
36
- ### Configuration
57
+ This package also expects these peer dependencies in your app:
37
58
 
59
+ - `react`
60
+ - `react-dom`
61
+ - `@dakataa/requester`
62
+ - `@dakataa/crud-theme`
63
+ - `@popperjs/core`
64
+ - `lottie-web`
38
65
 
39
- ```ts
40
- import {CrudConfiguration} from "@dakataa/crud-react";
66
+ If your project does not already include Bootstrap styles, add your theme or Bootstrap setup in the host application.
67
+
68
+ ## Quick start
69
+
70
+ ```tsx
71
+ import { StrictMode } from "react";
72
+ import { createRoot } from "react-dom/client";
73
+ import {
74
+ Crud,
75
+ CrudConfiguration,
76
+ CrudLoader,
77
+ MainLayout,
78
+ Outlet,
79
+ Route,
80
+ Router
81
+ } from "@dakataa/crud-react";
82
+
83
+ const templates = import.meta.glob("./crud/**");
41
84
 
42
85
  CrudConfiguration({
43
- connection: {
44
- baseURL: 'https://crud-rest-api.local'
45
- }
86
+ connection: {
87
+ baseURL: "https://project.local",
88
+ headers: {
89
+ Accept: "application/json"
90
+ }
91
+ },
92
+ templates
46
93
  });
94
+
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>
117
+ );
47
118
  ```
48
119
 
49
- ### Example
120
+ ## Configuration
121
+
122
+ There are two configuration layers:
50
123
 
51
- #### Example with *react-router*
52
- main.tsx
124
+ - `CrudConfiguration(...)` configures the shared requester namespace and global templates
125
+ - `<Crud config={...}>` configures runtime behavior for the current React tree
53
126
 
54
- ```jsx
55
- import {StrictMode} from 'react'
56
- import {createRoot} from 'react-dom/client'
57
- import {Crud, CrudConfiguration, MainLayout, Router, Route, Outlet} from "@dakataa/crud-react";
127
+ ### `CrudConfiguration`
58
128
 
59
- const templates = import.meta.glob('./crud/**');
129
+ ```ts
130
+ import { CrudConfiguration } from "@dakataa/crud-react";
60
131
 
61
132
  CrudConfiguration({
62
- connection: {
63
- baseURL: 'https://project.local',
64
- headers: {
65
- Accept: 'application/json'
66
- }
67
- },
68
- templates: import.meta.glob('./crud/**')
133
+ connection: {
134
+ baseURL: "https://crud-api.local",
135
+ headers: {
136
+ Accept: "application/json"
137
+ }
138
+ },
139
+ templates: import.meta.glob("./crud/**")
69
140
  });
141
+ ```
142
+
143
+ ### `Crud` config
144
+
145
+ ```ts
146
+ type Config = {
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
+ };
167
+ };
168
+ ```
169
+
170
+ ### Common options
70
171
 
71
- createRoot(document.getElementById('root')!).render(
72
- <StrictMode>
73
- <Crud
74
- config={{templates, currency: 'BGN', locale: 'bg', env: import.meta.env.CRUD_ENV}}
75
- errorFallback={<CrudErrorFallback/>}
76
- >
77
- <Router>
78
- <Route element={<MainLayout><Outlet/></MainLayout>}>
79
- <Route path={"*"} element={<CrudLoader/>}/>
80
- </Route>
81
- </Router>
82
- </Crud>
83
- </StrictMode>
84
- )
85
- ```
86
-
87
-
88
- ### Legend
89
- * Action
90
- * **Entity** - Model Name (Article)
91
- * **Namespace**
92
- * **Route** - API Endpoint information.
172
+ - `env`: environment flag exposed through `UseConfig()`
173
+ - `templates`: runtime template overrides merged with global templates
174
+ - `locale`: used by components such as `Money`
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.
177
+ - `link.prefix`: useful when the CRUD UI is mounted under a sub-path such as `/admin`
178
+ - `link.path`: lets you force `CrudLoader` to resolve a custom path instead of `location.pathname + location.search`
179
+ - `options.HTMLTableElement`: default props for generated tables
180
+ - `options.GridView`: default props for the `GridView` wrapper
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
+
207
+ ## Backend contract
208
+
209
+ For the library to work, your backend must expose action metadata and action payloads in the expected format.
210
+
211
+ ### 1. Actions endpoint
212
+
213
+ The frontend loads available actions from:
214
+
215
+ ```text
216
+ /_crud/actions
217
+ ```
218
+
219
+ Each action looks like this:
220
+
221
+ ```ts
222
+ type ActionType = {
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
+ };
234
+ };
235
+ ```
236
+
237
+ Example:
238
+
239
+ ```json
240
+ [
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
+ }
260
+ }
261
+ ]
262
+ ```
263
+
264
+ ### 2. List response
265
+
266
+ The default list view expects a payload compatible with:
267
+
268
+ ```ts
269
+ type ListType = {
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> };
280
+ };
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 };
288
+ };
289
+ ```
290
+
291
+ This powers:
292
+
293
+ - table/grid columns
294
+ - row actions
295
+ - pagination
296
+ - filters
297
+ - batch actions
298
+
299
+ ### 3. Modify response
300
+
301
+ The default add/edit view expects:
302
+
303
+ ```ts
304
+ type ModifyType = {
305
+ title: string | null;
306
+ object: { [key: string]: any } | null;
307
+ form: { [key: string]: FormType };
308
+ messages: { [key: string]: string[] };
309
+ redirect?: RedirectType;
310
+ };
311
+ ```
312
+
313
+ The key part is `form.modify.view`, which contains the schema used to render the form.
314
+
315
+ ## Templates and dynamic views
316
+
317
+ Dynamic views are loaded from the `templates` object you pass through `CrudConfiguration` or `<Crud config={...}>`.
318
+
319
+ Typical setup:
320
+
321
+ ```ts
322
+ const templates = import.meta.glob("./crud/**");
323
+ ```
324
+
325
+ The resolver looks for files in this order:
326
+
327
+ 1. `crud/{namespace}/{prefix}/{ViewName}.tsx`
328
+ 2. `crud/general/{prefix}/{ViewName}.tsx`
329
+
330
+ View names are normalized to PascalCase, so:
331
+
332
+ - `list` -> `List.tsx`
333
+ - `content` -> `Content.tsx`
334
+ - `user_profile` -> `UserProfile.tsx`
335
+ - `user.profile` -> `UserProfile.tsx`
336
+
337
+ ### Useful template locations
338
+
339
+ - `crud/{namespace}/List.tsx`
340
+ - `crud/{namespace}/Add.tsx`
341
+ - `crud/{namespace}/Edit.tsx`
342
+ - `crud/{namespace}/list/Content.tsx`
343
+ - `crud/{namespace}/modify/Navigation.tsx`
344
+ - `crud/{namespace}/modify/Content.tsx`
345
+ - `crud/{namespace}/modify/form/{FormName}.tsx`
346
+ - `crud/general/...` for shared fallbacks
347
+
348
+ ### Minimal override example
349
+
350
+ ```tsx
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
+ );
373
+ ```
374
+
375
+ Example of extending an existing template block:
376
+
377
+ ```tsx
378
+ import { Extend, Parent } from "@dakataa/crud-react";
379
+
380
+ export default function CustomModifyNavigation() {
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
+ );
389
+ }
390
+ ```
93
391
 
94
392
  ## Routing
95
393
 
96
- ## Hooks
97
- ### Data Provider
394
+ The package exports its own lightweight router:
395
+
396
+ ```tsx
397
+ import { Router, Route, Outlet } from "@dakataa/crud-react";
398
+ ```
98
399
 
99
- `GetDataByAction` is a Hook that allows you to fetch data based on CRUD action (see section [Actions](#legend)).
400
+ Example:
100
401
 
101
- ```js
102
- const {
103
- results,
104
- setAction,
105
- setParameters,
106
- setQueryParameters,
107
- refresh
108
- } = GetDataByAction({action});
402
+ ```tsx
403
+ <Router>
404
+ <Route
405
+ element={
406
+ <MainLayout>
407
+ <Outlet />
408
+ </MainLayout>
409
+ }>
410
+ <Route path="*" element={<CrudLoader />} />
411
+ </Route>
412
+ </Router>
109
413
  ```
110
414
 
111
- ### Actions
415
+ ### Route generation
416
+
417
+ `UseActions()` exposes helpers for route generation and matching:
418
+
419
+ - `getAction(entity, name, namespace?)`
420
+ - `getActionByPath(path)`
421
+ - `getActionRequestByPath(path)`
422
+ - `generateActionLink(actionRequest)`
423
+ - `generateRoute(route, parameters?, query?)`
424
+ - `generatePath(pattern, parameters?, query?)`
425
+ - `navigate(to, replace?)`
426
+
427
+ ### Using a URL prefix
112
428
 
113
- CRUD Actions is a collection of entity routes
429
+ If your admin panel lives under `/admin`, configure a prefix:
114
430
 
115
- `UseActions` is Hook that allows you to get all available [CRUD Actions].
116
- ```js
117
- const {actions, getAction, getActionByPath} = UseActions();
431
+ ```tsx
432
+ <Crud
433
+ config={{
434
+ link: {
435
+ prefix: "admin"
436
+ }
437
+ }}>
438
+ <Router>
439
+ <Route path="*" element={<CrudLoader />} />
440
+ </Router>
441
+ </Crud>
118
442
  ```
119
443
 
444
+ This lets internal CRUD routes stay backend-friendly while browser URLs include the app prefix.
445
+
446
+ ## Forms
447
+
448
+ The add/edit screens are driven by `form.modify.view`.
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
+
454
+ Default behavior:
455
+
456
+ 1. `CrudLoader` resolves the current action
457
+ 2. `DataProvider` fetches the payload for that action
458
+ 3. `Modify` renders the page or modal
459
+ 4. `CrudForm` renders fields from `form.modify.view`
460
+ 5. On submit, the current action is re-issued as `POST`
461
+ 6. If the response is successful and contains a redirect, the UI navigates automatically
462
+
463
+ ### Default form rendering
464
+
465
+ ```tsx
466
+ import { Modify } from "@dakataa/crud-react";
467
+
468
+ export default function EditArticle() {
469
+ return <Modify />;
470
+ }
471
+ ```
472
+
473
+ ### Lower-level form API
474
+
475
+ If you need custom rendering around the form schema:
476
+
477
+ ```tsx
478
+ import {
479
+ CrudForm,
480
+ FormFieldViewLoader,
481
+ FormGroup,
482
+ FormRest,
483
+ FormRestError,
484
+ FormViewProvider
485
+ } from "@dakataa/crud-react";
486
+ ```
487
+
488
+ Useful helpers:
489
+
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
494
+ - `FormFieldViewLoader`: render fields from the current schema node
495
+ - `FormGroup`: render the current schema node or one of its direct children
496
+ - `FormRest`: render non-explicitly-rendered fields
497
+ - `FormRestError`: render non-explicitly-rendered errors
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
+
646
+ ## Hooks and contexts
647
+
648
+ ### `UseActions()`
649
+
650
+ Access loaded actions, route matching, link generation and programmatic navigation.
651
+
652
+ ### `UseCurrentActionRequest()`
653
+
654
+ Get the current resolved CRUD action and update it from inside a view.
655
+
656
+ ### `UseDataProvider()`
657
+
658
+ Access the current action payload loaded by `DataProvider`.
659
+
660
+ ### `GetData(...)`
661
+
662
+ Fetch arbitrary data through the configured CRUD requester.
663
+
664
+ ```tsx
665
+ const { results, status, refresh, cancel } = GetData({
666
+ path: "/article"
667
+ });
668
+ ```
669
+
670
+ ### `GetDataByAction(...)`
671
+
672
+ Fetch data using an `ActionRequest`.
673
+
674
+ ```tsx
675
+ const data = GetDataByAction({
676
+ actionRequest: {
677
+ action: {
678
+ entity: "Article",
679
+ name: "list"
680
+ }
681
+ }
682
+ });
683
+ ```
684
+
685
+ Returned shape:
686
+
687
+ ```ts
688
+ type GetDataType = {
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;
696
+ };
697
+ ```
698
+
699
+ ### `UseList()` and `UseListItem()`
700
+
701
+ Helpers for building custom list layouts and row renderers.
702
+
703
+ ### `UseModal()`
704
+
705
+ Open CRUD actions inside modals.
706
+
707
+ ```tsx
708
+ const { openModal, closeModal } = UseModal();
709
+ ```
710
+
711
+ ### `UseAlert()`
712
+
713
+ Open confirm, success, warning and error dialogs.
714
+
715
+ ```tsx
716
+ const { open } = UseAlert();
717
+ ```
718
+
719
+ ### `UseConfig()`
720
+
721
+ Access the merged CRUD configuration from context.
722
+
723
+ ## Core components
724
+
725
+ ### `Crud`
726
+
727
+ Top-level provider that wires config, alerts, modals, preloaders and action state.
728
+
729
+ ### `CrudLoader`
730
+
731
+ Resolves the current URL to a CRUD action and loads the matching view.
732
+
733
+ ### `List`
734
+
735
+ Default list view with filters, sorting, batch actions and pagination.
736
+
737
+ ### `Modify`
738
+
739
+ Default add/edit view with built-in success and error handling.
740
+
741
+ ### `GridView`
742
+
743
+ Bootstrap table renderer used by the default list template. Can be customized with `config.options` or component props.
744
+
745
+ ### `DynamicView`
746
+
747
+ Loads a namespace-aware template file and falls back to children when no override exists.
748
+
749
+ ### `Modal` and `UseModal`
750
+
751
+ Render CRUD screens inside nested modals.
752
+
753
+ ### `UseAlert`
754
+
755
+ Display animated alerts and confirmation dialogs.
756
+
757
+ ### `Link`, `Button`, `Translation`, `Money`, `Dropdown`
758
+
759
+ Reusable building blocks for custom CRUD templates.
760
+
761
+ ## Troubleshooting
762
+
763
+ ### `Invalid Configuration.`
764
+
765
+ `CrudLoader` throws this when `CrudConfiguration(...)` has not been called before rendering the CRUD tree.
766
+
767
+ ### `404 Not Found`
768
+
769
+ This usually means the current browser URL does not match any action returned by `/_crud/actions`.
770
+
771
+ Check:
772
+
773
+ - the backend action route
774
+ - the current browser path
775
+ - `config.link.prefix`
776
+ - whether actions were loaded successfully
777
+
778
+ ### `View "..." Not found`
779
+
780
+ This means no built-in view or dynamic template matched the resolved action name.
781
+
782
+ Check:
783
+
784
+ - that your action name is one of the supported defaults, or
785
+ - that you created the corresponding template file in `./crud/**`
786
+
787
+ ### Templates are not loading
788
+
789
+ Check:
790
+
791
+ - that `templates: import.meta.glob('./crud/**')` is passed to `CrudConfiguration(...)` or `<Crud config={...}>`
792
+ - that the file name matches the normalized PascalCase view name
793
+ - that the file is under the expected namespace or `crud/general`
794
+
795
+ ### Actions are stale
796
+
797
+ The action list is cached in `sessionStorage`. If your backend action definitions changed, clear session storage and reload.
798
+
799
+ ## Notes
800
+
801
+ If you want, the next useful step is to split this README into:
802
+
803
+ - a shorter package README for npm/GitHub
804
+ - a `/docs` folder with standalone guides such as `backend-contract.md`, `templates.md`, `forms.md`, and `recipes.md`
805
+
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**.
120
865
 
121
- ## Components
122
- ### Dynamic View
123
- ### Router
124
- ### Templates
125
- ### Modal
126
- ### Dropdown
127
- ### Translation
128
- ### Types
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.