@gopherium/godmin 0.30.0 → 0.32.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 (62) hide show
  1. package/README.md +2 -3
  2. package/dist/base.css +159 -29
  3. package/dist/breakpoints.d.ts +1 -1
  4. package/dist/breakpoints.js +1 -1
  5. package/dist/bulk-run.d.ts +10 -0
  6. package/dist/bulk-run.js +59 -10
  7. package/dist/bulk.d.ts +3 -0
  8. package/dist/confirm-dialog.d.ts +14 -14
  9. package/dist/confirm-dialog.js +8 -28
  10. package/dist/dialog-open.d.ts +63 -0
  11. package/dist/dialog-open.js +110 -0
  12. package/dist/focus-back.d.ts +20 -0
  13. package/dist/focus-back.js +36 -12
  14. package/dist/form-dialog.d.ts +14 -16
  15. package/dist/form-dialog.js +53 -13
  16. package/dist/index.d.ts +13 -13
  17. package/dist/index.js +7 -8
  18. package/dist/list-chrome/es-ES.js +3 -3
  19. package/dist/list-chrome/fr-FR.js +1 -0
  20. package/dist/list-run.js +39 -48
  21. package/dist/page-breadcrumbs.d.ts +28 -0
  22. package/dist/page-breadcrumbs.js +18 -0
  23. package/dist/page-tabs.js +18 -6
  24. package/dist/page.d.ts +8 -3
  25. package/dist/page.js +36 -9
  26. package/dist/rename-dialog.d.ts +24 -0
  27. package/dist/rename-dialog.js +16 -0
  28. package/dist/router.d.ts +2 -0
  29. package/dist/router.js +1 -0
  30. package/dist/toaster.js +21 -2
  31. package/dist/unsaved-changes-dialog.d.ts +19 -0
  32. package/dist/unsaved-changes-dialog.js +33 -0
  33. package/docs/build-and-versioning.md +92 -9
  34. package/docs/design-system/accessibility.md +12 -7
  35. package/docs/design-system/custom-properties.md +6 -2
  36. package/docs/design-system/dialogs.md +240 -0
  37. package/docs/design-system/layout.md +5 -3
  38. package/docs/design-system/lists.md +3 -1
  39. package/docs/design-system/loading.md +2 -0
  40. package/docs/design-system/motion.md +3 -2
  41. package/docs/design-system/overview.md +7 -1
  42. package/docs/design-system/record-pages.md +199 -0
  43. package/docs/design-system/toasts.md +13 -10
  44. package/docs/design-system/typography.md +1 -1
  45. package/docs/lists.md +321 -434
  46. package/docs/loading-and-feedback.md +14 -11
  47. package/docs/overview.md +2 -3
  48. package/docs/screens.md +87 -34
  49. package/docs/testing.md +11 -9
  50. package/package.json +20 -28
  51. package/dist/close-while-open.d.ts +0 -6
  52. package/dist/close-while-open.js +0 -21
  53. package/dist/confirm.d.ts +0 -21
  54. package/dist/confirm.js +0 -11
  55. package/dist/dialogs.d.ts +0 -4
  56. package/dist/dialogs.js +0 -3
  57. package/dist/form.d.ts +0 -28
  58. package/dist/form.js +0 -23
  59. package/dist/rename.d.ts +0 -20
  60. package/dist/rename.js +0 -14
  61. package/dist/run-confirm.d.ts +0 -22
  62. package/dist/run-confirm.js +0 -23
@@ -43,6 +43,8 @@ decides how it shows:
43
43
  page, under the title, as on a WordPress screen.
44
44
  - Inside a dialog, when nothing of the dialog body is known yet. It
45
45
  shows at once there too.
46
+ [When to ask first](./design-system/dialogs.md#when-to-ask-first)
47
+ says when an action opens a dialog at all.
46
48
  - Alone, when nothing of the screen is known yet, such as while the
47
49
  session loads before the frame is drawn. It then waits a moment, so
48
50
  a fast load shows nothing, and fades in, in the middle of the space
@@ -199,22 +201,23 @@ Name an item in straight double quotes and in full, like
199
201
  snackbar, and godmin does not either.
200
202
  [Size](./design-system/toasts.md#size) says how a long one wraps.
201
203
 
202
- Use a toast for a write that failed in a dialog or in a run over list
203
- rows too. WordPress shows those in its snackbar, never inside the
204
- dialog and never above the list, and godmin's dialogs and list runs
205
- do the same. Say what failed, in the words your server sent when it
206
- sent some. [A failure from a dialog](./lists.md#a-failure-from-a-dialog)
204
+ Use a toast for a write that failed too, on a page or in a run over
205
+ list rows. WordPress shows those in its snackbar, never above the
206
+ list, and godmin's list runs do the same. A dialog that closes says
207
+ how its write went in a toast too. A dialog that stays open says why
208
+ inside, as [a failed write](./design-system/dialogs.md#a-failed-write)
209
+ says.
210
+ Say what failed, in the words your server sent when it sent some. A
211
+ server message about one field goes under that field.
212
+ [A failure from a dialog](./lists.md#a-failure-from-a-dialog)
207
213
  shows how to raise one from a dialog.
208
214
  [Running an action over the picked rows](./lists.md#running-an-action-over-the-picked-rows)
209
215
  raises it for you after a run over a list.
210
216
 
211
217
  Keep an [`ErrorNotice`](./screens.md#errornotice) for a failure
212
- that has to stay on the screen until the user acts:
213
-
214
- - A screen or a list that failed to load. Show the notice where the
215
- content would be.
216
- - A form on a page of its own, not in a dialog. Show the notice next
217
- to the form, so the user sees what failed while they fix it.
218
+ that has to stay on the screen until the user acts, such as a screen
219
+ or a list that failed to load. Show the notice where the content
220
+ would be.
218
221
 
219
222
  Skip the toast in three more cases:
220
223
 
package/docs/overview.md CHANGED
@@ -29,11 +29,10 @@ duplicates something the packages above already ship.
29
29
 
30
30
  | Entry point | Contents |
31
31
  | --- | --- |
32
- | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ListNoResults`, `ConfirmBody`, `RenameBody`, `FormBody`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useListRun`, `useBulkRun`, `RunConfirm`, `useCloseWhileOpen`, `focusInDialog`, `useFocusBack`, `focusedTrigger`, `openOnTap`, `useUnsavedText`, `markLatest`, `viewNarrows`, `offeredView`, `offeredSize`, `sizedView`, `useMediaQuery`, `useTokenDocument`, the breakpoints `HUGE_BREAKPOINT`, `SIDEBAR_BREAKPOINT`, `EDGE_BREAKPOINT`, `DENSE_BREAKPOINT`, `SHEET_BREAKPOINT`, `TITLE_BREAKPOINT` and `SMALL_VIEWPORT`, `SUPPORTED_WPDS` |
32
+ | `@gopherium/godmin` | `AdminRoot`, `Frame`, `Page`, `PageTitle`, `PageTabs`, `PageTab`, `PageBreadcrumbs`, `PageBreadcrumb`, `SectionTitle`, `InitialsAvatar`, `NavigationScreen`, `MenuCount`, `ErrorNotice`, `LoadMore`, `LogList`, `LogItem`, `LogTime`, `LoadingScreen`, `Toaster`, `useToaster`, `RepeatRows`, `RowControls`, `useRowKeys`, `keyFromLabel`, `listChromeCatalogFor`, `LIST_CHROME_DOMAIN`, `ListEmpty`, `ListNoResults`, `ConfirmDialog`, `FormDialog`, `RenameDialog`, `FileButton`, `useServerPaging`, `pageWindow`, `paginationOf`, `runEach`, `bulkNotes`, `useListRun`, `useBulkRun`, `useDialogRun`, `focusInDialog`, `useFocusBack`, `focusedTrigger`, `openOnTap`, `useUnsavedText`, `markLatest`, `viewNarrows`, `offeredView`, `offeredSize`, `sizedView`, `useMediaQuery`, `useTokenDocument`, the breakpoints `HUGE_BREAKPOINT`, `SIDEBAR_BREAKPOINT`, `EDGE_BREAKPOINT`, `DENSE_BREAKPOINT`, `SHEET_BREAKPOINT`, `TITLE_BREAKPOINT` and `SMALL_VIEWPORT`, `SUPPORTED_WPDS` |
33
33
  | `@gopherium/godmin/base.css` | Cascade layer order, design tokens, host rules, frame and screen styles |
34
34
  | `@gopherium/godmin/dates` | `startListDates`, `listDate`, the only entry that loads `@wordpress/date` |
35
- | `@gopherium/godmin/dialogs` | `ConfirmDialog`, `FormDialog`, the only entry that loads `@wordpress/components`. Load `@wordpress/components/build-style/style.css` once in your app, as DataViews asks |
36
- | `@gopherium/godmin/router` | `Navigation`, `NavigationList`, `NavigationItem`, `DrilldownItem`, `useCanAccess` and the `MenuItem` type with its optional `count`, `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, `routerDefaults`, the `canvas`, `Sidebar` and `capability` route static data |
35
+ | `@gopherium/godmin/router` | `Navigation`, `NavigationList`, `NavigationItem`, `DrilldownItem`, `useCanAccess` and the `MenuItem` type with its optional `count`, `useListView`, `listSearch`, `openOnTap`, `useCanvas`, `useFrameLocation`, `routerDefaults`, `UnsavedChangesDialog`, the `canvas`, `Sidebar` and `capability` route static data |
37
36
  | `@gopherium/godmin/testing` | `installTestEnvironment`, `renderAdmin`, `setViewport` and its `TestViewport` type, `getAnnouncement`, `clearAnnouncements`, `assertElementPatched`, `WPDS_IGNORE_SELECTOR`, `textClasses`, `badgeClasses`, `buttonClasses`, `stubLayout` |
38
37
  | `@gopherium/godmin/vite` | `godminDedupe`, `godminSingleCopy`, `godminStylesheetFirst`, `duplicateCopies`, `hoistStylesheet` |
39
38
  | `@gopherium/godmin/stylelint` | The design system stylelint rules |
package/docs/screens.md CHANGED
@@ -19,40 +19,47 @@ one in a component of your own.
19
19
  </Page>
20
20
  ```
21
21
 
22
- `title` is required and becomes the page's heading, at 15px like the
23
- title of a WordPress page. It is an `h1` unless you pass
22
+ `title` is required and becomes the page's heading, at the size of a
23
+ WordPress page title. It is an `h1` unless you pass
24
24
  `headingLevel`, as [heading levels](#heading-levels) explains.
25
25
  `actions` renders top right,
26
26
  and `className` and `children` do what they always do. When the
27
27
  actions no longer fit beside the title, on a phone for example, they
28
- move to a line of their own under it.
29
-
30
- `subtitle` renders as one 13px grey line under the title and the
31
- actions, the way WordPress sets the sentence under a page title. The
32
- title row is 40px tall even with no actions, so the title and the
33
- subtitle sit in the same place on every page. Give the page compact
34
- buttons, `size="compact"`, to match the 32px buttons of a WordPress
35
- page header.
28
+ move to a line of their own under it. Beside breadcrumbs the title
29
+ gives way first, and the actions move only once it reaches its
30
+ smallest width.
31
+
32
+ `subtitle` renders as one grey line under the title and the actions,
33
+ the way WordPress sets the sentence under a page title. The title row
34
+ keeps its height even with no actions, so the title and the subtitle
35
+ sit in the same place on every page. Give the page compact buttons,
36
+ `size="compact"`, to match the buttons of a WordPress page header. A
37
+ button of the default size makes the row taller.
38
+ [The page header](./design-system/record-pages.md#the-page-header)
39
+ gives the values.
36
40
 
37
41
  `tabs` renders a row of tabs under the title block. See
38
42
  [PageTabs](#pagetabs) below.
39
43
 
40
- `aside` adds a second column beside the content, for the details
41
- that sit next to a record's main work:
44
+ `breadcrumbs` renders links back to what a record belongs to, before
45
+ the title. See [PageBreadcrumbs](#pagebreadcrumbs) below.
46
+
47
+ `aside` adds the details of a record in a fixed column at the end of
48
+ the page. `asideLabel` names that column for a screen reader:
42
49
 
43
50
  ```tsx
44
- <Page title="Invoice 1042" aside={<InvoiceDetails />}>
51
+ <Page title="Invoice 1042" aside={<InvoiceDetails />} asideLabel="Invoice details">
45
52
  <InvoiceLines />
46
53
  </Page>
47
54
  ```
48
55
 
49
- On a wide page the content keeps a 560px column and the aside takes
50
- the rest of the width, so the aside is the part that grows with the
51
- screen. Put the record's own details in the content and its longer
52
- lists, such as a history, in the aside. When the page is too narrow
53
- for both, the aside moves below the content and both fill the page.
54
- No breakpoint decides this, only the page's own width. An aside that
55
- renders nothing takes no room.
56
+ Put what grows, such as the invoice lines or a history, in the
57
+ content, and the record's own short fields and facts in the aside.
58
+ When the page is too narrow for both, the aside moves under the
59
+ content. An aside that renders nothing takes no room. A page with an
60
+ aside keeps its title in view while the content scrolls under it.
61
+ [Record pages](./design-system/record-pages.md) gives every value, and
62
+ what goes where.
56
63
 
57
64
  `list` marks a page whose content is a list, such as a DataViews
58
65
  table. The content then reaches out to the canvas edges, so the
@@ -84,7 +91,7 @@ and uses `PageTitle` directly, so the page still gets its heading:
84
91
  <PageTitle>Conversations</PageTitle>
85
92
  ```
86
93
 
87
- It draws the 15px large heading by default. Pass `variant` to change
94
+ It draws the large heading by default. Pass `variant` to change
88
95
  the text size, and `level` to change the heading level.
89
96
 
90
97
  ## PageTabs
@@ -130,8 +137,10 @@ navigation region, and a screen reader lists it beside the sidebar,
130
137
  so the name tells them apart.
131
138
 
132
139
  The tabs look like the WordPress tabs: 13px labels 16px apart, the
133
- current one underlined by a 2px grey line as wide as its label, and a
134
- 1px light line under the row that runs to the canvas edges.
140
+ current one underlined by a 2px dark line as wide as its label, and a
141
+ 1px light line under the row that runs to the canvas edges. A tab
142
+ under the pointer or the keyboard gets a soft shade that reaches 4px
143
+ past its label. The current tab keeps its plain look under the pointer.
135
144
 
136
145
  They are links and not the design system `Tabs` component on
137
146
  purpose. `Tabs` switches panels inside one page and moves between
@@ -140,6 +149,47 @@ link, reached with Tab and marked with `aria-current`, which is how
140
149
  assistive technology expects page navigation to work. godmin copies
141
150
  the look of the WordPress tabs and keeps the behavior of links.
142
151
 
152
+ ## PageBreadcrumbs
153
+
154
+ `PageBreadcrumbs` and `PageBreadcrumb` lead the title of a record with
155
+ links back to what it belongs to, like `Contacts / Maria Perez`, the
156
+ way a WordPress record page names its list:
157
+
158
+ ```tsx
159
+ <Page
160
+ title="Maria Perez"
161
+ breadcrumbs={
162
+ <PageBreadcrumbs label="Breadcrumbs">
163
+ <PageBreadcrumb render={<Link to="/contacts" activeOptions={{ exact: true }} />}>Contacts</PageBreadcrumb>
164
+ </PageBreadcrumbs>
165
+ }
166
+ aside={<ContactDetails />}
167
+ >
168
+ <ContactTasks />
169
+ </Page>
170
+ ```
171
+
172
+ Each breadcrumb is a link. Pass your router's link element as
173
+ `render`, or a plain address as `href`, as with `PageTab`. Leave the
174
+ page on screen out of the list, since its title already names it.
175
+
176
+ No breadcrumb is the current page, yet a router link can mark itself
177
+ as one for screen readers. TanStack Router counts a link to
178
+ `/contacts` as active on `/contacts/42` too, so without
179
+ `activeOptions={{ exact: true }}` a screen reader would hear the
180
+ breadcrumb as the page on screen. Pass it on every breadcrumb link, as
181
+ the example does.
182
+
183
+ `label` names the links for assistive technology. They are a
184
+ navigation region, and a screen reader lists it beside the sidebar and
185
+ any tabs, so the name tells them apart. Translate it.
186
+
187
+ Every page opened from a list takes breadcrumbs, a create page too,
188
+ as in `Contacts / New contact`. Beside breadcrumbs the title stays on
189
+ one line, so a long one ends in an ellipsis.
190
+ [The page header](./design-system/record-pages.md#the-page-header)
191
+ gives the values.
192
+
143
193
  ## SectionTitle
144
194
 
145
195
  `SectionTitle` heads a section inside a page, one size step above
@@ -213,10 +263,10 @@ reader came from after Back.
213
263
  It renders the design system's error notice and announces the
214
264
  message to screen readers. Use it wherever you would otherwise
215
265
  render a bare error string, such as a screen that failed to load. A
216
- write that fails in a dialog or in a run over list rows goes in a
217
- toast instead, as
266
+ write that fails goes in a toast instead, as
218
267
  [what goes in a toast](./loading-and-feedback.md#what-goes-in-a-toast)
219
- explains.
268
+ explains. A dialog that stays open draws its own notice, as
269
+ [a failed write](./design-system/dialogs.md#a-failed-write) says.
220
270
 
221
271
  ## LoadMore
222
272
 
@@ -351,7 +401,7 @@ runs into:
351
401
 
352
402
  | Name | For |
353
403
  | --- | --- |
354
- | `godmin-form` | A single column form, up to 560px wide |
404
+ | `godmin-form` | A single column form |
355
405
  | `godmin-form--inline` | A form that is one row, filling its column |
356
406
  | `godmin-form__row` | Short fields side by side inside a form |
357
407
  | `godmin-form__grow` | The field of a row that takes most of the free room |
@@ -380,12 +430,14 @@ A form row puts short fields and a button on one line:
380
430
  </form>
381
431
  ```
382
432
 
383
- Each field starts from 160px and they share the rest of the line. The
384
- button keeps its own width. When the line is too narrow, the fields
385
- wrap onto the next line, and a button left alone sits at the end of
386
- its line. A form that is only one row takes `godmin-form--inline`, so
387
- it fills its column instead of stopping at 560px. In a stacked form,
388
- a button keeps its own width instead of stretching across the form.
433
+ Each field takes a share of the line. The button keeps its own width.
434
+ When the line is too narrow, the fields wrap onto the next line, and
435
+ a button left alone sits at the end of its line. A form that is only
436
+ one row takes `godmin-form--inline`, so it fills its column instead
437
+ of stopping at its width. In a stacked form, a button keeps its own
438
+ width instead of stretching across the form.
439
+ [Forms on a page](./design-system/record-pages.md#forms-on-a-page)
440
+ gives the values.
389
441
 
390
442
  `godmin-table` and `godmin-table-scroll` are a pair, and they solve
391
443
  a phone problem: a table wider than the screen drags the whole page
@@ -400,7 +452,8 @@ instead:
400
452
 
401
453
  The scroll rule only activates on a phone, as
402
454
  [tables that stay custom](./design-system/lists.md#tables-that-stay-custom)
403
- gives. There the actions column, the cell marked
455
+ gives, and in a column of a record page at every width. On a phone
456
+ the actions column, the cell marked
404
457
  `godmin-table__actions`, stays pinned to the right edge, so a row's
405
458
  buttons are in view before any scroll. On a
406
459
  desktop the wrapper only draws a focus ring when a keyboard user
package/docs/testing.md CHANGED
@@ -135,20 +135,22 @@ setViewport(PHONE)
135
135
  ## Giving elements a layout box
136
136
 
137
137
  jsdom lays nothing out, so no element has a size or a place on the
138
- screen. The WordPress modal looks for the first element it can focus
139
- among those on screen, finds none, and leaves the focus where it was.
140
- A test that checks the dialog focused Cancel, or that a form dialog
141
- put the cursor in its first field, then fails, though a browser
142
- moves the focus there. `stubLayout` gives every element one small
143
- box, as a browser does for an element on screen:
138
+ screen. The `Modal` of `@wordpress/components`, such as one your app
139
+ draws itself or one DataViews opens for an action with a
140
+ `RenderModal`, looks for the first element it can focus among those
141
+ on screen, finds none, and leaves the focus where it was.
142
+ A test that checks such a modal put the cursor in its first field
143
+ then fails, though a browser moves the focus there. godmin's own
144
+ dialogs need no box for that. `stubLayout` gives every element one
145
+ small box, as a browser does for an element on screen:
144
146
 
145
147
  ```ts
146
148
  import { stubLayout } from '@gopherium/godmin/testing'
147
149
 
148
- test('focuses Cancel when the dialog opens', async () => {
150
+ test('puts the cursor in the note field when the export modal opens', async () => {
149
151
  stubLayout()
150
- await user.click(screen.getByRole('button', { name: 'Move to trash' }))
151
- await waitFor(() => expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Cancel' })))
152
+ await user.click(screen.getByRole('button', { name: 'Export' }))
153
+ await waitFor(() => expect(document.activeElement).toBe(screen.getByRole('textbox', { name: 'Note' })))
152
154
  })
153
155
  ```
154
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gopherium/godmin",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "description": "The admin kit for Gopherium projects: host layer for React admin applications on the WordPress Design System.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -31,10 +31,6 @@
31
31
  "types": "./dist/dates.d.ts",
32
32
  "default": "./dist/dates.js"
33
33
  },
34
- "./dialogs": {
35
- "types": "./dist/dialogs.d.ts",
36
- "default": "./dist/dialogs.js"
37
- },
38
34
  "./router": {
39
35
  "types": "./dist/router.d.ts",
40
36
  "default": "./dist/router.js"
@@ -60,7 +56,7 @@
60
56
  "lint:css": "stylelint 'src/**/*.css'",
61
57
  "storybook:dev": "storybook dev",
62
58
  "storybook:test": "vitest run --project storybook",
63
- "test:browser": "vitest run --project browser",
59
+ "test:browser": "vitest run --project browser --project scrollbars",
64
60
  "typecheck": "tsc --noEmit",
65
61
  "prepublishOnly": "pnpm run build"
66
62
  },
@@ -70,15 +66,14 @@
70
66
  "peerDependencies": {
71
67
  "@tanstack/react-router": "^1.170.44",
72
68
  "@testing-library/react": "^16.3.2",
73
- "@wordpress/a11y": ">=4.57.0 <5.0.0",
74
- "@wordpress/components": ">=42.0.0 <43.0.0",
75
- "@wordpress/dataviews": ">=20.0.0 <21.0.0",
76
- "@wordpress/date": ">=5.57.0 <6.0.0",
77
- "@wordpress/i18n": ">=6.30.0 <7.0.0",
78
- "@wordpress/icons": ">=18.0.0 <19.0.0",
79
- "@wordpress/style-runtime": ">=0.13.0 <0.14.0",
80
- "@wordpress/theme": ">=2.3.0 <3.0.0",
81
- "@wordpress/ui": ">=0.24.0 <0.25.0",
69
+ "@wordpress/a11y": ">=5.0.0 <6.0.0",
70
+ "@wordpress/dataviews": ">=21.0.0 <22.0.0",
71
+ "@wordpress/date": ">=6.0.0 <7.0.0",
72
+ "@wordpress/i18n": ">=7.0.0 <8.0.0",
73
+ "@wordpress/icons": ">=19.0.0 <20.0.0",
74
+ "@wordpress/style-runtime": ">=0.14.0 <0.15.0",
75
+ "@wordpress/theme": ">=3.0.0 <4.0.0",
76
+ "@wordpress/ui": ">=0.25.0 <0.26.0",
82
77
  "react": "^19.2.0",
83
78
  "stylelint": "^16 || ^17",
84
79
  "vitest": "^4.1.10 || ^5.0.0"
@@ -90,9 +85,6 @@
90
85
  "@testing-library/react": {
91
86
  "optional": true
92
87
  },
93
- "@wordpress/components": {
94
- "optional": true
95
- },
96
88
  "@wordpress/dataviews": {
97
89
  "optional": true
98
90
  },
@@ -120,16 +112,16 @@
120
112
  "@vitejs/plugin-react": "^6.0.3",
121
113
  "@vitest/browser-playwright": "^5.0.3",
122
114
  "@vitest/coverage-v8": "^5.0.3",
123
- "@wordpress/a11y": "4.57.0",
124
- "@wordpress/components": "42.0.0",
125
- "@wordpress/dataviews": "20.0.0",
126
- "@wordpress/date": "5.57.0",
127
- "@wordpress/element": "9.0.0",
128
- "@wordpress/i18n": "6.30.0",
129
- "@wordpress/icons": "18.0.0",
130
- "@wordpress/style-runtime": "0.13.0",
131
- "@wordpress/theme": "2.3.0",
132
- "@wordpress/ui": "0.24.0",
115
+ "@wordpress/a11y": "5.0.0",
116
+ "@wordpress/components": "43.0.0",
117
+ "@wordpress/dataviews": "21.0.0",
118
+ "@wordpress/date": "6.0.0",
119
+ "@wordpress/element": "10.0.0",
120
+ "@wordpress/i18n": "7.0.0",
121
+ "@wordpress/icons": "19.0.0",
122
+ "@wordpress/style-runtime": "0.14.0",
123
+ "@wordpress/theme": "3.0.0",
124
+ "@wordpress/ui": "0.25.0",
133
125
  "eslint": "^10.7.0",
134
126
  "eslint-plugin-jsdoc": "^63.2.0",
135
127
  "eslint-plugin-sonarjs": "^4.2.0",
@@ -1,6 +0,0 @@
1
- /**
2
- * Returns the close of a dialog body that acts only while that body is on screen, never on a dialog opened since.
3
- * @param close - Closes the dialog, none for a body drawn outside a dialog.
4
- * @returns The close, which does nothing once the body left the screen.
5
- */
6
- export declare function useCloseWhileOpen(close: (() => void) | undefined): () => void;
@@ -1,21 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- import { useEffect, useRef } from 'react';
3
- /**
4
- * Returns the close of a dialog body that acts only while that body is on screen, never on a dialog opened since.
5
- * @param close - Closes the dialog, none for a body drawn outside a dialog.
6
- * @returns The close, which does nothing once the body left the screen.
7
- */
8
- export function useCloseWhileOpen(close) {
9
- const open = useRef(true);
10
- useEffect(() => {
11
- open.current = true;
12
- return () => {
13
- open.current = false;
14
- };
15
- }, []);
16
- return () => {
17
- if (open.current) {
18
- close?.();
19
- }
20
- };
21
- }
package/dist/confirm.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- export interface ConfirmBodyProps {
3
- /** The question the modal asks. */
4
- children: ReactNode;
5
- /** The label of the button that carries the action out. */
6
- confirmLabel: string;
7
- /** The label of the button that closes the modal. */
8
- cancelLabel: string;
9
- /** Whether the action is running, the confirm button then busy and Cancel greyed out. */
10
- busy?: boolean;
11
- /** Carries the action out. */
12
- onConfirm: () => void;
13
- /** Closes the modal. */
14
- onCancel?: () => void;
15
- }
16
- /**
17
- * Renders a confirmation modal body: the question, an accent text Cancel and the confirm button, 20px apart.
18
- * @param props - The question, the labels, the busy flag and the handlers.
19
- * @returns The confirmation body.
20
- */
21
- export declare function ConfirmBody({ children, confirmLabel, cancelLabel, busy, onConfirm, onCancel, }: ConfirmBodyProps): import("react").JSX.Element;
package/dist/confirm.js DELETED
@@ -1,11 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { Button, Stack, Text } from '@wordpress/ui';
4
- /**
5
- * Renders a confirmation modal body: the question, an accent text Cancel and the confirm button, 20px apart.
6
- * @param props - The question, the labels, the busy flag and the handlers.
7
- * @returns The confirmation body.
8
- */
9
- export function ConfirmBody({ children, confirmLabel, cancelLabel, busy = false, onConfirm, onCancel, }) {
10
- return (_jsxs("div", { className: "godmin-modal-body", children: [_jsx(Text, { className: "godmin-modal-body__question", children: children }), _jsxs(Stack, { direction: "row", gap: "sm", justify: "flex-end", children: [_jsx(Button, { variant: "minimal", disabled: busy, onClick: onCancel, children: cancelLabel }), _jsx(Button, { loading: busy, onClick: onConfirm, children: confirmLabel })] })] }));
11
- }
package/dist/dialogs.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { ConfirmDialog } from './confirm-dialog.js';
2
- export type { ConfirmDialogProps } from './confirm-dialog.js';
3
- export { FormDialog } from './form-dialog.js';
4
- export type { FormDialogProps } from './form-dialog.js';
package/dist/dialogs.js DELETED
@@ -1,3 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- export { ConfirmDialog } from './confirm-dialog.js';
3
- export { FormDialog } from './form-dialog.js';
package/dist/form.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- /** What a form does, which sets the space above its buttons as WordPress spaces it. */
3
- export type FormKind = 'edit' | 'copy' | 'create';
4
- /** The props of the body of a form modal. */
5
- export interface FormBodyProps {
6
- /** The fields, and any help sentence before them, in the order the reader meets them. */
7
- children: ReactNode;
8
- /** The label of the button that sends the form. */
9
- submitLabel: string;
10
- /** The label of the button that closes the modal. */
11
- cancelLabel: string;
12
- /** Whether the form may be sent now, false while a needed field is empty, true when left out. */
13
- canSubmit?: boolean;
14
- /** Whether the write runs, the submit button then busy and a second send ignored. */
15
- busy?: boolean;
16
- /** What the form does: 20px above the buttons for an edit, the default, 12px for a copy, 16px for a create. */
17
- kind?: FormKind;
18
- /** Sends the form, from the submit button or Enter in a field. */
19
- onSubmit: () => void;
20
- /** Closes the modal. */
21
- onCancel?: () => void;
22
- }
23
- /**
24
- * Renders the body of a form modal: the fields, an accent text Cancel and the submit button.
25
- * @param props - The fields, the labels, the send gate, the busy flag, the kind and the handlers.
26
- * @returns The form.
27
- */
28
- export declare function FormBody({ children, submitLabel, cancelLabel, canSubmit, busy, kind, onSubmit, onCancel, }: FormBodyProps): import("react").JSX.Element;
package/dist/form.js DELETED
@@ -1,23 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { Button, Stack } from '@wordpress/ui';
4
- /** The classes of a form body of each kind. */
5
- const KIND_CLASSES = {
6
- edit: 'godmin-modal-body',
7
- copy: 'godmin-modal-body godmin-modal-body--copy',
8
- create: 'godmin-modal-body godmin-modal-body--create',
9
- };
10
- /**
11
- * Renders the body of a form modal: the fields, an accent text Cancel and the submit button.
12
- * @param props - The fields, the labels, the send gate, the busy flag, the kind and the handlers.
13
- * @returns The form.
14
- */
15
- export function FormBody({ children, submitLabel, cancelLabel, canSubmit = true, busy = false, kind = 'edit', onSubmit, onCancel, }) {
16
- const sendable = canSubmit && !busy;
17
- return (_jsxs("form", { className: KIND_CLASSES[kind], onSubmit: (event) => {
18
- event.preventDefault();
19
- if (sendable) {
20
- onSubmit();
21
- }
22
- }, children: [children, _jsxs(Stack, { direction: "row", gap: "sm", justify: "flex-end", children: [_jsx(Button, { variant: "minimal", onClick: onCancel, children: cancelLabel }), _jsx(Button, { type: "submit", loading: busy, disabled: !sendable, children: submitLabel })] })] }));
23
- }
package/dist/rename.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export interface RenameBodyProps {
2
- /** The text the field starts with: the name the item carries, or the name a failed write turned away. */
3
- name: string;
4
- /** The label of the name field. */
5
- fieldLabel: string;
6
- /** The label of the button that writes the new name. */
7
- submitLabel: string;
8
- /** The label of the button that closes the modal. */
9
- cancelLabel: string;
10
- /** Writes the name as typed, the one the item already has included. */
11
- onSubmit: (name: string) => void;
12
- /** Closes the modal. */
13
- onCancel?: () => void;
14
- }
15
- /**
16
- * Renders the body of a rename modal: the name field, an accent text Cancel and the submit button, off while blank.
17
- * @param props - The first name, the labels and the handlers.
18
- * @returns The rename form.
19
- */
20
- export declare function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, onSubmit, onCancel }: RenameBodyProps): import("react").JSX.Element;
package/dist/rename.js DELETED
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { InputControl } from '@wordpress/ui';
4
- import { useState } from 'react';
5
- import { FormBody } from './form.js';
6
- /**
7
- * Renders the body of a rename modal: the name field, an accent text Cancel and the submit button, off while blank.
8
- * @param props - The first name, the labels and the handlers.
9
- * @returns The rename form.
10
- */
11
- export function RenameBody({ name, fieldLabel, submitLabel, cancelLabel, onSubmit, onCancel }) {
12
- const [value, setValue] = useState(name);
13
- return (_jsx(FormBody, { submitLabel: submitLabel, cancelLabel: cancelLabel, canSubmit: value.trim() !== '', onSubmit: () => onSubmit(value), onCancel: onCancel, children: _jsx(InputControl, { label: fieldLabel, value: value, onChange: (event) => setValue(event.target.value) }) }));
14
- }
@@ -1,22 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- /** The props of a run confirm, the first two as a DataViews modal hands them. */
3
- export interface RunConfirmProps<Item> {
4
- /** The items the action runs over. */
5
- items: Item[];
6
- /** Closes the modal. */
7
- closeModal?: () => void;
8
- /** The question the modal asks. */
9
- children: ReactNode;
10
- /** The label of the button that starts the run. */
11
- confirmLabel: string;
12
- /** The label of the button that closes the modal. */
13
- cancelLabel: string;
14
- /** Runs the action over the items, settling once the list shows how it went. */
15
- run: (items: Item[]) => Promise<unknown>;
16
- }
17
- /**
18
- * Renders a confirmation that runs the action, keeps Cancel inert while it runs and closes only itself once it settles.
19
- * @param props - The items, the close handler, the question, the labels and the run.
20
- * @returns The confirmation body.
21
- */
22
- export declare function RunConfirm<Item>({ items, closeModal, children, confirmLabel, cancelLabel, run, }: RunConfirmProps<Item>): import("react").JSX.Element;
@@ -1,23 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { useState } from 'react';
4
- import { useCloseWhileOpen } from './close-while-open.js';
5
- import { ConfirmBody } from './confirm.js';
6
- /**
7
- * Renders a confirmation that runs the action, keeps Cancel inert while it runs and closes only itself once it settles.
8
- * @param props - The items, the close handler, the question, the labels and the run.
9
- * @returns The confirmation body.
10
- */
11
- export function RunConfirm({ items, closeModal, children, confirmLabel, cancelLabel, run, }) {
12
- const [busy, setBusy] = useState(false);
13
- const close = useCloseWhileOpen(closeModal);
14
- return (_jsx(ConfirmBody, { confirmLabel: confirmLabel, cancelLabel: cancelLabel, busy: busy, onCancel: closeModal, onConfirm: () => {
15
- setBusy(true);
16
- void Promise.resolve()
17
- .then(() => run(items))
18
- .finally(() => {
19
- setBusy(false);
20
- close();
21
- });
22
- }, children: children }));
23
- }