@wordpress/dataviews 13.1.1-next.v.202603102151.0 → 14.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.
- package/CHANGELOG.md +18 -1
- package/README.md +19 -3
- package/build/components/dataform-controls/datetime.cjs +8 -4
- package/build/components/dataform-controls/datetime.cjs.map +2 -2
- package/build/components/dataform-layouts/card/index.cjs +132 -128
- package/build/components/dataform-layouts/card/index.cjs.map +3 -3
- package/build/components/dataviews-bulk-actions/index.cjs +28 -5
- package/build/components/dataviews-bulk-actions/index.cjs.map +2 -2
- package/build/components/dataviews-context/index.cjs +2 -2
- package/build/components/dataviews-context/index.cjs.map +2 -2
- package/build/components/dataviews-footer/index.cjs +2 -3
- package/build/components/dataviews-footer/index.cjs.map +2 -2
- package/build/components/dataviews-layout/index.cjs +12 -3
- package/build/components/dataviews-layout/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/grid/composite-grid.cjs +378 -245
- package/build/components/dataviews-layouts/grid/composite-grid.cjs.map +2 -2
- package/build/components/dataviews-layouts/index.cjs +3 -3
- package/build/components/dataviews-layouts/index.cjs.map +3 -3
- package/build/components/dataviews-layouts/picker-grid/index.cjs +76 -32
- package/build/components/dataviews-layouts/picker-grid/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/picker-table/index.cjs +34 -22
- package/build/components/dataviews-layouts/picker-table/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/table/index.cjs +97 -88
- package/build/components/dataviews-layouts/table/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/table/{use-is-horizontal-scroll-end.cjs → use-scroll-state.cjs} +29 -33
- package/build/components/dataviews-layouts/table/use-scroll-state.cjs.map +7 -0
- package/build/components/dataviews-layouts/utils/density-picker.cjs.map +2 -2
- package/build/components/dataviews-layouts/utils/grid-config-options.cjs +45 -0
- package/build/components/dataviews-layouts/utils/grid-config-options.cjs.map +7 -0
- package/build/components/dataviews-layouts/utils/use-infinite-scroll.cjs +62 -0
- package/build/components/dataviews-layouts/utils/use-infinite-scroll.cjs.map +7 -0
- package/build/components/dataviews-picker-footer/index.cjs +23 -4
- package/build/components/dataviews-picker-footer/index.cjs.map +2 -2
- package/build/components/dataviews-search/index.cjs +2 -1
- package/build/components/dataviews-search/index.cjs.map +2 -2
- package/build/components/dataviews-selection-checkbox/index.cjs +3 -2
- package/build/components/dataviews-selection-checkbox/index.cjs.map +2 -2
- package/build/components/dataviews-view-config/index.cjs +0 -2
- package/build/components/dataviews-view-config/index.cjs.map +3 -3
- package/build/components/dataviews-view-config/infinite-scroll-toggle.cjs +0 -3
- package/build/components/dataviews-view-config/infinite-scroll-toggle.cjs.map +2 -2
- package/build/dataviews/index.cjs +38 -34
- package/build/dataviews/index.cjs.map +3 -3
- package/build/dataviews-picker/index.cjs +26 -25
- package/build/dataviews-picker/index.cjs.map +3 -3
- package/build/hooks/index.cjs +11 -2
- package/build/hooks/index.cjs.map +2 -2
- package/build/hooks/use-data.cjs +146 -9
- package/build/hooks/use-data.cjs.map +2 -2
- package/build/hooks/use-infinite-scroll.cjs +208 -0
- package/build/hooks/use-infinite-scroll.cjs.map +7 -0
- package/build/hooks/use-selected-items.cjs +57 -0
- package/build/hooks/use-selected-items.cjs.map +7 -0
- package/build/types/dataviews.cjs.map +1 -1
- package/build/types/field-api.cjs.map +1 -1
- package/build/utils/filter-sort-and-paginate.cjs +5 -1
- package/build/utils/filter-sort-and-paginate.cjs.map +2 -2
- package/build/utils/get-footer-message.cjs +8 -8
- package/build/utils/get-footer-message.cjs.map +2 -2
- package/build-module/components/dataform-controls/datetime.mjs +8 -4
- package/build-module/components/dataform-controls/datetime.mjs.map +2 -2
- package/build-module/components/dataform-layouts/card/index.mjs +132 -133
- package/build-module/components/dataform-layouts/card/index.mjs.map +2 -2
- package/build-module/components/dataviews-bulk-actions/index.mjs +28 -5
- package/build-module/components/dataviews-bulk-actions/index.mjs.map +2 -2
- package/build-module/components/dataviews-context/index.mjs +2 -2
- package/build-module/components/dataviews-context/index.mjs.map +2 -2
- package/build-module/components/dataviews-footer/index.mjs +2 -3
- package/build-module/components/dataviews-footer/index.mjs.map +2 -2
- package/build-module/components/dataviews-layout/index.mjs +12 -3
- package/build-module/components/dataviews-layout/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs +387 -246
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/index.mjs +3 -3
- package/build-module/components/dataviews-layouts/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/picker-grid/index.mjs +80 -33
- package/build-module/components/dataviews-layouts/picker-grid/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/picker-table/index.mjs +34 -22
- package/build-module/components/dataviews-layouts/picker-table/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/index.mjs +97 -88
- package/build-module/components/dataviews-layouts/table/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/use-scroll-state.mjs +46 -0
- package/build-module/components/dataviews-layouts/table/use-scroll-state.mjs.map +7 -0
- package/build-module/components/dataviews-layouts/utils/density-picker.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/utils/grid-config-options.mjs +14 -0
- package/build-module/components/dataviews-layouts/utils/grid-config-options.mjs.map +7 -0
- package/build-module/components/dataviews-layouts/utils/use-infinite-scroll.mjs +26 -0
- package/build-module/components/dataviews-layouts/utils/use-infinite-scroll.mjs.map +7 -0
- package/build-module/components/dataviews-picker-footer/index.mjs +23 -4
- package/build-module/components/dataviews-picker-footer/index.mjs.map +2 -2
- package/build-module/components/dataviews-search/index.mjs +2 -1
- package/build-module/components/dataviews-search/index.mjs.map +2 -2
- package/build-module/components/dataviews-selection-checkbox/index.mjs +3 -2
- package/build-module/components/dataviews-selection-checkbox/index.mjs.map +2 -2
- package/build-module/components/dataviews-view-config/index.mjs +0 -2
- package/build-module/components/dataviews-view-config/index.mjs.map +2 -2
- package/build-module/components/dataviews-view-config/infinite-scroll-toggle.mjs +0 -3
- package/build-module/components/dataviews-view-config/infinite-scroll-toggle.mjs.map +2 -2
- package/build-module/dataviews/index.mjs +46 -36
- package/build-module/dataviews/index.mjs.map +2 -2
- package/build-module/dataviews-picker/index.mjs +34 -27
- package/build-module/dataviews-picker/index.mjs.map +2 -2
- package/build-module/hooks/index.mjs +7 -1
- package/build-module/hooks/index.mjs.map +2 -2
- package/build-module/hooks/use-data.mjs +147 -10
- package/build-module/hooks/use-data.mjs.map +2 -2
- package/build-module/hooks/use-infinite-scroll.mjs +188 -0
- package/build-module/hooks/use-infinite-scroll.mjs.map +7 -0
- package/build-module/hooks/use-selected-items.mjs +36 -0
- package/build-module/hooks/use-selected-items.mjs.map +7 -0
- package/build-module/utils/filter-sort-and-paginate.mjs +5 -1
- package/build-module/utils/filter-sort-and-paginate.mjs.map +2 -2
- package/build-module/utils/get-footer-message.mjs +8 -8
- package/build-module/utils/get-footer-message.mjs.map +2 -2
- package/build-style/style-rtl.css +107 -41
- package/build-style/style.css +107 -41
- package/build-types/components/dataform-controls/datetime.d.ts +1 -1
- package/build-types/components/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/card/index.d.ts.map +1 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts +2 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +1 -1
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-footer/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/grid/composite-grid.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/index.d.ts +3 -3
- package/build-types/components/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/picker-grid/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/picker-table/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts +25 -0
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts.map +1 -0
- package/build-types/components/dataviews-layouts/utils/density-picker.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/utils/grid-config-options.d.ts +2 -0
- package/build-types/components/dataviews-layouts/utils/grid-config-options.d.ts.map +1 -0
- package/build-types/components/dataviews-layouts/utils/use-infinite-scroll.d.ts +22 -0
- package/build-types/components/dataviews-layouts/utils/use-infinite-scroll.d.ts.map +1 -0
- package/build-types/components/dataviews-picker-footer/index.d.ts.map +1 -1
- package/build-types/components/dataviews-search/index.d.ts.map +1 -1
- package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/infinite-scroll-toggle.d.ts +1 -1
- package/build-types/components/dataviews-view-config/infinite-scroll-toggle.d.ts.map +1 -1
- package/build-types/dataviews/index.d.ts +0 -1
- package/build-types/dataviews/index.d.ts.map +1 -1
- package/build-types/dataviews/stories/empty.d.ts +1 -2
- package/build-types/dataviews/stories/empty.d.ts.map +1 -1
- package/build-types/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/dataviews/stories/free-composition.d.ts.map +1 -1
- package/build-types/dataviews/stories/index.story.d.ts +18 -10
- package/build-types/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/dataviews/stories/infinite-scroll.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-activity.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-custom.d.ts +3 -1
- package/build-types/dataviews/stories/layout-custom.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-grid.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-list.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-table.d.ts.map +1 -1
- package/build-types/dataviews/stories/with-card.d.ts +3 -1
- package/build-types/dataviews/stories/with-card.d.ts.map +1 -1
- package/build-types/dataviews-picker/index.d.ts +0 -1
- package/build-types/dataviews-picker/index.d.ts.map +1 -1
- package/build-types/dataviews-picker/stories/fixtures.d.ts.map +1 -1
- package/build-types/dataviews-picker/stories/index.story.d.ts.map +1 -1
- package/build-types/field-types/stories/index.story.d.ts.map +1 -1
- package/build-types/hooks/index.d.ts +3 -0
- package/build-types/hooks/index.d.ts.map +1 -1
- package/build-types/hooks/test/use-data.d.ts +2 -0
- package/build-types/hooks/test/use-data.d.ts.map +1 -0
- package/build-types/hooks/use-data.d.ts +41 -3
- package/build-types/hooks/use-data.d.ts.map +1 -1
- package/build-types/hooks/use-infinite-scroll.d.ts +21 -0
- package/build-types/hooks/use-infinite-scroll.d.ts.map +1 -0
- package/build-types/hooks/use-selected-items.d.ts +19 -0
- package/build-types/hooks/use-selected-items.d.ts.map +1 -0
- package/build-types/types/dataviews.d.ts +15 -1
- package/build-types/types/dataviews.d.ts.map +1 -1
- package/build-types/types/field-api.d.ts +15 -4
- package/build-types/types/field-api.d.ts.map +1 -1
- package/build-types/utils/filter-sort-and-paginate.d.ts.map +1 -1
- package/build-types/utils/get-footer-message.d.ts +3 -2
- package/build-types/utils/get-footer-message.d.ts.map +1 -1
- package/build-wp/index.js +3202 -2761
- package/package.json +19 -19
- package/src/components/dataform-controls/datetime.tsx +19 -11
- package/src/components/dataform-layouts/card/index.tsx +171 -146
- package/src/components/dataform-layouts/card/style.scss +8 -5
- package/src/components/dataviews-bulk-actions/index.tsx +28 -1
- package/src/components/dataviews-context/index.ts +2 -2
- package/src/components/dataviews-footer/index.tsx +1 -6
- package/src/components/dataviews-layout/index.tsx +41 -19
- package/src/components/dataviews-layout/style.scss +8 -0
- package/src/components/dataviews-layouts/grid/composite-grid.tsx +433 -278
- package/src/components/dataviews-layouts/grid/style.scss +22 -2
- package/src/components/dataviews-layouts/index.ts +3 -3
- package/src/components/dataviews-layouts/picker-grid/index.tsx +70 -17
- package/src/components/dataviews-layouts/picker-grid/style.scss +10 -0
- package/src/components/dataviews-layouts/picker-table/index.tsx +42 -22
- package/src/components/dataviews-layouts/table/index.tsx +10 -4
- package/src/components/dataviews-layouts/table/style.scss +13 -0
- package/src/components/dataviews-layouts/table/use-scroll-state.ts +79 -0
- package/src/components/dataviews-layouts/utils/density-picker.tsx +12 -2
- package/src/components/dataviews-layouts/utils/grid-config-options.tsx +14 -0
- package/src/components/dataviews-layouts/utils/grid-items.scss +9 -1
- package/src/components/dataviews-layouts/utils/use-infinite-scroll.ts +64 -0
- package/src/components/dataviews-picker-footer/index.tsx +21 -1
- package/src/components/dataviews-search/index.tsx +2 -1
- package/src/components/dataviews-selection-checkbox/index.tsx +4 -2
- package/src/components/dataviews-view-config/index.tsx +0 -2
- package/src/components/dataviews-view-config/infinite-scroll-toggle.tsx +0 -5
- package/src/dataviews/index.tsx +58 -45
- package/src/dataviews/stories/empty.tsx +1 -3
- package/src/dataviews/stories/fixtures.tsx +288 -0
- package/src/dataviews/stories/free-composition.tsx +44 -45
- package/src/dataviews/stories/index.story.tsx +31 -8
- package/src/dataviews/stories/infinite-scroll.tsx +7 -93
- package/src/dataviews/stories/layout-activity.tsx +1 -0
- package/src/dataviews/stories/layout-custom.tsx +7 -3
- package/src/dataviews/stories/layout-grid.tsx +1 -0
- package/src/dataviews/stories/layout-list.tsx +1 -0
- package/src/dataviews/stories/layout-table.tsx +1 -0
- package/src/dataviews/stories/style.css +0 -5
- package/src/dataviews/stories/with-card.tsx +35 -24
- package/src/dataviews/style.scss +5 -8
- package/src/dataviews/test/dataviews.tsx +54 -1
- package/src/dataviews-picker/index.tsx +41 -35
- package/src/dataviews-picker/stories/fixtures.tsx +270 -0
- package/src/dataviews-picker/stories/index.story.tsx +62 -129
- package/src/field-types/stories/index.story.tsx +12 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/test/use-data.ts +791 -0
- package/src/hooks/use-data.ts +288 -21
- package/src/hooks/use-infinite-scroll.ts +304 -0
- package/src/hooks/use-selected-items.ts +72 -0
- package/src/style.scss +1 -0
- package/src/types/dataviews.ts +18 -1
- package/src/types/field-api.ts +16 -3
- package/src/utils/filter-sort-and-paginate.ts +13 -1
- package/src/utils/get-footer-message.ts +12 -9
- package/src/utils/test/filter-sort-and-paginate.js +78 -54
- package/build/components/dataviews-layouts/table/use-is-horizontal-scroll-end.cjs.map +0 -7
- package/build-module/components/dataviews-layouts/table/use-is-horizontal-scroll-end.mjs +0 -50
- package/build-module/components/dataviews-layouts/table/use-is-horizontal-scroll-end.mjs.map +0 -7
- package/build-types/components/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts +0 -19
- package/build-types/components/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts.map +0 -1
- package/src/components/dataviews-layouts/table/use-is-horizontal-scroll-end.ts +0 -82
package/CHANGELOG.md
CHANGED
|
@@ -2,15 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 14.0.0 (2026-04-01)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- DataViews: Use intersectionObserver to improve performance by unloading invisible items. Change how infinite scroll is enabled to require only 2 view properties: `infiniteScrollEnabled` and `startPosition`. [#74378](https://github.com/WordPress/gutenberg/pull/74378)
|
|
10
|
+
- DataForm: The card layout now uses `Card` and `CollapsibleCard` from `@wordpress/ui` instead of `Card`, `CardHeader`, and `CardBody` from `@wordpress/components`. This changes the card's visual appearance (spacing, typography, and removal of the header/content separator). Custom CSS targeting `.components-card__body` within DataViews has been removed. Consumers wrapping DataViews or DataForm in a card should migrate to the `Card` and `CollapsibleCard` components from `@wordpress/ui`. [#76282](https://github.com/WordPress/gutenberg/pull/76282)
|
|
11
|
+
|
|
12
|
+
### Enhancements
|
|
13
|
+
|
|
14
|
+
- DataForm: Add `compact` configuration option to the `datetime` control. [#76905](https://github.com/WordPress/gutenberg/pull/76905)
|
|
15
|
+
- DataViews: Field's description can accept ReactElements. [#76829](https://github.com/WordPress/gutenberg/pull/76829)
|
|
16
|
+
- DataForm: Use `CollapsibleCard.HeaderDescription` for card layout header descriptions instead of manual `aria-describedby`. [#76867](https://github.com/WordPress/gutenberg/pull/76867)
|
|
17
|
+
|
|
18
|
+
## 13.1.0 (2026-03-18)
|
|
6
19
|
|
|
7
20
|
### Enhancements
|
|
8
21
|
|
|
9
22
|
- DataForm: Reduce panel's dialog min-width. [#76345](https://github.com/WordPress/gutenberg/pull/76345)
|
|
23
|
+
- DataViews: Add border to sticky table headers. [#76396](https://github.com/WordPress/gutenberg/pull/76396)
|
|
24
|
+
- DataViews: Update scrolling so the scrollbar appears on the active layout when DataViews is rendered in a constrained-height container. This may slightly change the UI depending on the container height. [#76453](https://github.com/WordPress/gutenberg/pull/76453)
|
|
25
|
+
- DataViews: Add density option to Grid and PickerGrid layouts. [#75887](https://github.com/WordPress/gutenberg/pull/75887)
|
|
10
26
|
|
|
11
27
|
### Bug Fixes
|
|
12
28
|
|
|
13
29
|
- DataViews: Fix last column classname in table layout. [#76133](https://github.com/WordPress/gutenberg/pull/76133)
|
|
30
|
+
- DataViews: Add spinner in DataViewsLayout in initial load of data. [#76486](https://github.com/WordPress/gutenberg/pull/76486)
|
|
14
31
|
- DataForm: Properly handle dates in datetime control. [#76193](https://github.com/WordPress/gutenberg/pull/76193)
|
|
15
32
|
|
|
16
33
|
### Code Quality
|
package/README.md
CHANGED
|
@@ -216,6 +216,7 @@ Properties:
|
|
|
216
216
|
- `isLocked`: whether the filter is locked (cannot be edited by the user).
|
|
217
217
|
- `perPage`: number of records to show per page.
|
|
218
218
|
- `page`: the page that is visible.
|
|
219
|
+
- `startPosition`: the first item to load when infinite scroll is enabled. Used instead of `page`.
|
|
219
220
|
- `sort`:
|
|
220
221
|
- `field`: the field used for sorting the dataset.
|
|
221
222
|
- `direction`: the direction to use for sorting, one of `asc` or `desc`.
|
|
@@ -240,7 +241,7 @@ Properties:
|
|
|
240
241
|
|
|
241
242
|
| Props / Layout | `table` | `pickerTable` | `grid` | `pickerGrid` | `list` | `activity` |
|
|
242
243
|
| -------------- | ------- | ------------- | ------ | ------------ | ------ | ---------- |
|
|
243
|
-
| `density` | ✓ | ✓ |
|
|
244
|
+
| `density` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
244
245
|
| `enableMoving` | ✓ | ✓ | | | | |
|
|
245
246
|
| `styles` | ✓ | ✓ | | | | |
|
|
246
247
|
| `badgeFields` | | | ✓ | ✓ | | |
|
|
@@ -258,6 +259,7 @@ Right-align (`'end'`) whenever the cell value is fundamentally quantitative—nu
|
|
|
258
259
|
`grid` and `pickerGrid` layout:
|
|
259
260
|
|
|
260
261
|
- `badgeFields`: a list of field's `id` to render without label and styled as badges.
|
|
262
|
+
- `density`: one of `comfortable`, `balanced`, or `compact`. Configures the gap between items in the grid.
|
|
261
263
|
- `previewSize`: a `number` representing the size of the preview.
|
|
262
264
|
|
|
263
265
|
`list` layout:
|
|
@@ -388,7 +390,6 @@ const actions = [
|
|
|
388
390
|
|
|
389
391
|
- `totalItems`: the total number of items in the datasets.
|
|
390
392
|
- `totalPages`: the total number of pages, taking into account the total items in the dataset and the number of items per page provided by the user.
|
|
391
|
-
- `infiniteScrollHandler`: a function that handles infinite scrolling. This function should be called when the user scrolls to the bottom of the page. See [example in storybook](https://wordpress.github.io/gutenberg/?path=/story/dataviews-dataviews--infinite-scroll).
|
|
392
393
|
|
|
393
394
|
#### `search`: `boolean`
|
|
394
395
|
|
|
@@ -689,7 +690,7 @@ A list of actions that can be performed on the dataset. See "Actions API" for mo
|
|
|
689
690
|
|
|
690
691
|
#### `paginationInfo`: `Object`
|
|
691
692
|
|
|
692
|
-
Same as `DataViews`. Contains `totalItems` and `totalPages` properties
|
|
693
|
+
Same as `DataViews`. Contains `totalItems` and `totalPages` properties.
|
|
693
694
|
|
|
694
695
|
#### `search`: `boolean`
|
|
695
696
|
|
|
@@ -1577,6 +1578,20 @@ Additionally, some of the bundled Edit controls are configurable via a config ob
|
|
|
1577
1578
|
}
|
|
1578
1579
|
```
|
|
1579
1580
|
|
|
1581
|
+
- `datetime` configuration:
|
|
1582
|
+
|
|
1583
|
+
```js
|
|
1584
|
+
{
|
|
1585
|
+
id: 'date',
|
|
1586
|
+
type: 'datetime',
|
|
1587
|
+
label: 'Date',
|
|
1588
|
+
Edit: {
|
|
1589
|
+
control: 'datetime',
|
|
1590
|
+
compact: true
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
```
|
|
1594
|
+
|
|
1580
1595
|
Finally, the field author can always provide its own custom `Edit` control. It receives the following props:
|
|
1581
1596
|
|
|
1582
1597
|
- `data`: the item to be processed
|
|
@@ -1590,6 +1605,7 @@ Finally, the field author can always provide its own custom `Edit` control. It r
|
|
|
1590
1605
|
- `prefix`: a React component to be rendered as a prefix
|
|
1591
1606
|
- `suffix`: a React component to be rendered as a suffix
|
|
1592
1607
|
- `rows`: the number of rows to display (e.g., in the text area component)
|
|
1608
|
+
- `compact`: whether to render a compact version without the calendar widget (datetime control)
|
|
1593
1609
|
|
|
1594
1610
|
```js
|
|
1595
1611
|
{
|
|
@@ -57,8 +57,10 @@ function CalendarDateTimeControl({
|
|
|
57
57
|
onChange,
|
|
58
58
|
hideLabelFromVision,
|
|
59
59
|
markWhenOptional,
|
|
60
|
-
validity
|
|
60
|
+
validity,
|
|
61
|
+
config
|
|
61
62
|
}) {
|
|
63
|
+
const { compact } = config || {};
|
|
62
64
|
const { id, label, description, setValue, getValue, isValid } = field;
|
|
63
65
|
const fieldValue = getValue({ item: data });
|
|
64
66
|
const value = typeof fieldValue === "string" ? fieldValue : void 0;
|
|
@@ -162,7 +164,7 @@ function CalendarDateTimeControl({
|
|
|
162
164
|
onChange: handleManualDateTimeChange
|
|
163
165
|
}
|
|
164
166
|
),
|
|
165
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
167
|
+
!compact && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
166
168
|
DateCalendar,
|
|
167
169
|
{
|
|
168
170
|
style: { width: "100%" },
|
|
@@ -185,7 +187,8 @@ function DateTime({
|
|
|
185
187
|
hideLabelFromVision,
|
|
186
188
|
markWhenOptional,
|
|
187
189
|
operator,
|
|
188
|
-
validity
|
|
190
|
+
validity,
|
|
191
|
+
config
|
|
189
192
|
}) {
|
|
190
193
|
if (operator === import_constants.OPERATOR_IN_THE_PAST || operator === import_constants.OPERATOR_OVER) {
|
|
191
194
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -208,7 +211,8 @@ function DateTime({
|
|
|
208
211
|
onChange,
|
|
209
212
|
hideLabelFromVision,
|
|
210
213
|
markWhenOptional,
|
|
211
|
-
validity
|
|
214
|
+
validity,
|
|
215
|
+
config
|
|
212
216
|
}
|
|
213
217
|
);
|
|
214
218
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataform-controls/datetime.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tBaseControl,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { dateI18n, getDate, getSettings } from '@wordpress/date';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps, FormatDatetime } from '../../types';\nimport { OPERATOR_IN_THE_PAST, OPERATOR_OVER } from '../../constants';\nimport RelativeDateControl from './utils/relative-date-control';\nimport getCustomValidity from './utils/get-custom-validity';\nimport parseDateTime from '../../field-types/utils/parse-date-time';\nimport { unlock } from '../../lock-unlock';\n\nconst { DateCalendar, ValidatedInputControl } = unlock( componentsPrivateApis );\n\nconst formatDateTime = ( value?: string ): string => {\n\tif ( ! value ) {\n\t\treturn '';\n\t}\n\t// Format in WordPress timezone for datetime-local input: YYYY-MM-DDTHH:mm\n\treturn dateI18n( 'Y-m-d\\\\TH:i', getDate( value ) );\n};\n\nfunction CalendarDateTimeControl< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tmarkWhenOptional,\n\tvalidity,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, description, setValue, getValue, isValid } = field;\n\tconst fieldValue = getValue( { item: data } );\n\tconst value = typeof fieldValue === 'string' ? fieldValue : undefined;\n\n\tconst [ calendarMonth, setCalendarMonth ] = useState< Date >( () => {\n\t\tconst parsedDate = parseDateTime( value );\n\t\treturn parsedDate || new Date(); // Default to current month\n\t} );\n\n\tconst inputControlRef = useRef< HTMLInputElement >( null );\n\tconst validationTimeoutRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >( undefined );\n\tconst previousFocusRef = useRef< Element | null >( null );\n\n\tconst onChangeCallback = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( setValue( { item: data, value: newValue } ) ),\n\t\t[ data, onChange, setValue ]\n\t);\n\n\t// Cleanup timeout on unmount\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( validationTimeoutRef.current ) {\n\t\t\t\tclearTimeout( validationTimeoutRef.current );\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\tconst onSelectDate = useCallback(\n\t\t( newDate: Date | undefined | null ) => {\n\t\t\tlet dateTimeValue: string | undefined;\n\t\t\tif ( newDate ) {\n\t\t\t\t// Extract the date part in WP timezone from the calendar selection\n\t\t\t\tconst wpDate = dateI18n( 'Y-m-d', newDate );\n\n\t\t\t\t// Preserve time if it exists in current value, otherwise use current time\n\t\t\t\tlet wpTime: string;\n\t\t\t\tif ( value ) {\n\t\t\t\t\twpTime = dateI18n( 'H:i', getDate( value ) );\n\t\t\t\t} else {\n\t\t\t\t\twpTime = dateI18n( 'H:i', newDate );\n\t\t\t\t}\n\n\t\t\t\t// Combine date and time in WP timezone and convert to ISO\n\t\t\t\tconst finalDateTime = getDate( `${ wpDate }T${ wpTime }` );\n\t\t\t\tdateTimeValue = finalDateTime.toISOString();\n\t\t\t\tonChangeCallback( dateTimeValue );\n\n\t\t\t\t// Clear any existing timeout\n\t\t\t\tif ( validationTimeoutRef.current ) {\n\t\t\t\t\tclearTimeout( validationTimeoutRef.current );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tonChangeCallback( undefined );\n\t\t\t}\n\t\t\t// Save the currently focused element\n\t\t\tpreviousFocusRef.current =\n\t\t\t\tinputControlRef.current &&\n\t\t\t\tinputControlRef.current.ownerDocument.activeElement;\n\n\t\t\t// Trigger validation display by simulating focus, blur, and changes.\n\t\t\t// Use a timeout to ensure it runs after the value update.\n\t\t\tvalidationTimeoutRef.current = setTimeout( () => {\n\t\t\t\tif ( inputControlRef.current ) {\n\t\t\t\t\tinputControlRef.current.focus();\n\t\t\t\t\tinputControlRef.current.blur();\n\t\t\t\t\tonChangeCallback( dateTimeValue );\n\n\t\t\t\t\t// Restore focus to the previously focused element\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviousFocusRef.current &&\n\t\t\t\t\t\tpreviousFocusRef.current instanceof HTMLElement\n\t\t\t\t\t) {\n\t\t\t\t\t\tpreviousFocusRef.current.focus();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, 0 );\n\t\t},\n\t\t[ onChangeCallback, value ]\n\t);\n\n\tconst handleManualDateTimeChange = useCallback(\n\t\t( newValue?: string ) => {\n\t\t\tif ( newValue ) {\n\t\t\t\t// Interpret the datetime-local value in WordPress timezone\n\t\t\t\tconst dateTime = getDate( newValue );\n\t\t\t\tonChangeCallback( dateTime.toISOString() );\n\n\t\t\t\t// Update calendar month to match\n\t\t\t\tconst parsedDate = parseDateTime( dateTime.toISOString() );\n\t\t\t\tif ( parsedDate ) {\n\t\t\t\t\tsetCalendarMonth( parsedDate );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tonChangeCallback( undefined );\n\t\t\t}\n\t\t},\n\t\t[ onChangeCallback ]\n\t);\n\n\tconst { format: fieldFormat } = field;\n\tconst weekStartsOn =\n\t\t( fieldFormat as FormatDatetime ).weekStartsOn ??\n\t\tgetSettings().l10n.startOfWeek;\n\tconst {\n\t\ttimezone: { string: timezoneString },\n\t} = getSettings();\n\n\tlet displayLabel = label;\n\tif ( isValid?.required && ! markWhenOptional && ! hideLabelFromVision ) {\n\t\tdisplayLabel = `${ label } (${ __( 'Required' ) })`;\n\t} else if (\n\t\t! isValid?.required &&\n\t\tmarkWhenOptional &&\n\t\t! hideLabelFromVision\n\t) {\n\t\tdisplayLabel = `${ label } (${ __( 'Optional' ) })`;\n\t}\n\n\treturn (\n\t\t<BaseControl\n\t\t\tid={ id }\n\t\t\tlabel={ displayLabel }\n\t\t\thelp={ description }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t>\n\t\t\t<Stack direction=\"column\" gap=\"lg\">\n\t\t\t\t{ /* Manual datetime input */ }\n\t\t\t\t<ValidatedInputControl\n\t\t\t\t\tref={ inputControlRef }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\trequired={ !! isValid?.required }\n\t\t\t\t\tcustomValidity={ getCustomValidity( isValid, validity ) }\n\t\t\t\t\ttype=\"datetime-local\"\n\t\t\t\t\tlabel={ __( 'Date time' ) }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tvalue={ formatDateTime( value ) }\n\t\t\t\t\tonChange={ handleManualDateTimeChange }\n\t\t\t\t/>\n\t\t\t\t{ /* Calendar widget */ }\n\t\t\t\t<DateCalendar\n\t\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\t\tselected={\n\t\t\t\t\t\tvalue
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAGO;AACP,qBAAyD;AACzD,kBAAmB;AACnB,kBAA+C;AAC/C,gBAAsB;AAMtB,uBAAoD;AACpD,mCAAgC;AAChC,iCAA8B;AAC9B,6BAA0B;AAC1B,yBAAuB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tBaseControl,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { dateI18n, getDate, getSettings } from '@wordpress/date';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps, FormatDatetime } from '../../types';\nimport { OPERATOR_IN_THE_PAST, OPERATOR_OVER } from '../../constants';\nimport RelativeDateControl from './utils/relative-date-control';\nimport getCustomValidity from './utils/get-custom-validity';\nimport parseDateTime from '../../field-types/utils/parse-date-time';\nimport { unlock } from '../../lock-unlock';\n\nconst { DateCalendar, ValidatedInputControl } = unlock( componentsPrivateApis );\n\nconst formatDateTime = ( value?: string ): string => {\n\tif ( ! value ) {\n\t\treturn '';\n\t}\n\t// Format in WordPress timezone for datetime-local input: YYYY-MM-DDTHH:mm\n\treturn dateI18n( 'Y-m-d\\\\TH:i', getDate( value ) );\n};\n\nfunction CalendarDateTimeControl< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tmarkWhenOptional,\n\tvalidity,\n\tconfig,\n}: DataFormControlProps< Item > ) {\n\tconst { compact } = config || {};\n\tconst { id, label, description, setValue, getValue, isValid } = field;\n\tconst fieldValue = getValue( { item: data } );\n\tconst value = typeof fieldValue === 'string' ? fieldValue : undefined;\n\n\tconst [ calendarMonth, setCalendarMonth ] = useState< Date >( () => {\n\t\tconst parsedDate = parseDateTime( value );\n\t\treturn parsedDate || new Date(); // Default to current month\n\t} );\n\n\tconst inputControlRef = useRef< HTMLInputElement >( null );\n\tconst validationTimeoutRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >( undefined );\n\tconst previousFocusRef = useRef< Element | null >( null );\n\n\tconst onChangeCallback = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( setValue( { item: data, value: newValue } ) ),\n\t\t[ data, onChange, setValue ]\n\t);\n\n\t// Cleanup timeout on unmount\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( validationTimeoutRef.current ) {\n\t\t\t\tclearTimeout( validationTimeoutRef.current );\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\tconst onSelectDate = useCallback(\n\t\t( newDate: Date | undefined | null ) => {\n\t\t\tlet dateTimeValue: string | undefined;\n\t\t\tif ( newDate ) {\n\t\t\t\t// Extract the date part in WP timezone from the calendar selection\n\t\t\t\tconst wpDate = dateI18n( 'Y-m-d', newDate );\n\n\t\t\t\t// Preserve time if it exists in current value, otherwise use current time\n\t\t\t\tlet wpTime: string;\n\t\t\t\tif ( value ) {\n\t\t\t\t\twpTime = dateI18n( 'H:i', getDate( value ) );\n\t\t\t\t} else {\n\t\t\t\t\twpTime = dateI18n( 'H:i', newDate );\n\t\t\t\t}\n\n\t\t\t\t// Combine date and time in WP timezone and convert to ISO\n\t\t\t\tconst finalDateTime = getDate( `${ wpDate }T${ wpTime }` );\n\t\t\t\tdateTimeValue = finalDateTime.toISOString();\n\t\t\t\tonChangeCallback( dateTimeValue );\n\n\t\t\t\t// Clear any existing timeout\n\t\t\t\tif ( validationTimeoutRef.current ) {\n\t\t\t\t\tclearTimeout( validationTimeoutRef.current );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tonChangeCallback( undefined );\n\t\t\t}\n\t\t\t// Save the currently focused element\n\t\t\tpreviousFocusRef.current =\n\t\t\t\tinputControlRef.current &&\n\t\t\t\tinputControlRef.current.ownerDocument.activeElement;\n\n\t\t\t// Trigger validation display by simulating focus, blur, and changes.\n\t\t\t// Use a timeout to ensure it runs after the value update.\n\t\t\tvalidationTimeoutRef.current = setTimeout( () => {\n\t\t\t\tif ( inputControlRef.current ) {\n\t\t\t\t\tinputControlRef.current.focus();\n\t\t\t\t\tinputControlRef.current.blur();\n\t\t\t\t\tonChangeCallback( dateTimeValue );\n\n\t\t\t\t\t// Restore focus to the previously focused element\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviousFocusRef.current &&\n\t\t\t\t\t\tpreviousFocusRef.current instanceof HTMLElement\n\t\t\t\t\t) {\n\t\t\t\t\t\tpreviousFocusRef.current.focus();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, 0 );\n\t\t},\n\t\t[ onChangeCallback, value ]\n\t);\n\n\tconst handleManualDateTimeChange = useCallback(\n\t\t( newValue?: string ) => {\n\t\t\tif ( newValue ) {\n\t\t\t\t// Interpret the datetime-local value in WordPress timezone\n\t\t\t\tconst dateTime = getDate( newValue );\n\t\t\t\tonChangeCallback( dateTime.toISOString() );\n\n\t\t\t\t// Update calendar month to match\n\t\t\t\tconst parsedDate = parseDateTime( dateTime.toISOString() );\n\t\t\t\tif ( parsedDate ) {\n\t\t\t\t\tsetCalendarMonth( parsedDate );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tonChangeCallback( undefined );\n\t\t\t}\n\t\t},\n\t\t[ onChangeCallback ]\n\t);\n\n\tconst { format: fieldFormat } = field;\n\tconst weekStartsOn =\n\t\t( fieldFormat as FormatDatetime ).weekStartsOn ??\n\t\tgetSettings().l10n.startOfWeek;\n\tconst {\n\t\ttimezone: { string: timezoneString },\n\t} = getSettings();\n\n\tlet displayLabel = label;\n\tif ( isValid?.required && ! markWhenOptional && ! hideLabelFromVision ) {\n\t\tdisplayLabel = `${ label } (${ __( 'Required' ) })`;\n\t} else if (\n\t\t! isValid?.required &&\n\t\tmarkWhenOptional &&\n\t\t! hideLabelFromVision\n\t) {\n\t\tdisplayLabel = `${ label } (${ __( 'Optional' ) })`;\n\t}\n\n\treturn (\n\t\t<BaseControl\n\t\t\tid={ id }\n\t\t\tlabel={ displayLabel }\n\t\t\thelp={ description }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t>\n\t\t\t<Stack direction=\"column\" gap=\"lg\">\n\t\t\t\t{ /* Manual datetime input */ }\n\t\t\t\t<ValidatedInputControl\n\t\t\t\t\tref={ inputControlRef }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\trequired={ !! isValid?.required }\n\t\t\t\t\tcustomValidity={ getCustomValidity( isValid, validity ) }\n\t\t\t\t\ttype=\"datetime-local\"\n\t\t\t\t\tlabel={ __( 'Date time' ) }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tvalue={ formatDateTime( value ) }\n\t\t\t\t\tonChange={ handleManualDateTimeChange }\n\t\t\t\t/>\n\t\t\t\t{ /* Calendar widget */ }\n\t\t\t\t{ ! compact && (\n\t\t\t\t\t<DateCalendar\n\t\t\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\t\t\tselected={\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t? parseDateTime( value ) || undefined\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonSelect={ onSelectDate }\n\t\t\t\t\t\tmonth={ calendarMonth }\n\t\t\t\t\t\tonMonthChange={ setCalendarMonth }\n\t\t\t\t\t\ttimeZone={ timezoneString || undefined }\n\t\t\t\t\t\tweekStartsOn={ weekStartsOn }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Stack>\n\t\t</BaseControl>\n\t);\n}\n\nexport default function DateTime< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tmarkWhenOptional,\n\toperator,\n\tvalidity,\n\tconfig,\n}: DataFormControlProps< Item > ) {\n\tif ( operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER ) {\n\t\treturn (\n\t\t\t<RelativeDateControl\n\t\t\t\tclassName=\"dataviews-controls__datetime\"\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\tonChange={ onChange }\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t\toperator={ operator }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<CalendarDateTimeControl\n\t\t\tdata={ data }\n\t\t\tfield={ field }\n\t\t\tonChange={ onChange }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\tmark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EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,MAAK,aAAa,yCAAwB,aAAa,gCAAgB;AACtE,WACC;AAAA,MAAC,6BAAAE;AAAA,MAAA;AAAA,QACA,WAAU;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,EAEF;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["componentsPrivateApis", "parseDateTime", "getCustomValidity", "RelativeDateControl"]
|
|
7
7
|
}
|
|
@@ -33,10 +33,8 @@ __export(card_exports, {
|
|
|
33
33
|
default: () => FormCardField
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(card_exports);
|
|
36
|
-
var import_components = require("@wordpress/components");
|
|
37
|
-
var import_compose = require("@wordpress/compose");
|
|
38
36
|
var import_element = require("@wordpress/element");
|
|
39
|
-
var
|
|
37
|
+
var import_ui = require("@wordpress/ui");
|
|
40
38
|
var import__ = require("../index.cjs");
|
|
41
39
|
var import_dataform_context = __toESM(require("../../dataform-context/index.cjs"));
|
|
42
40
|
var import_data_form_layout = require("../data-form-layout.cjs");
|
|
@@ -70,6 +68,84 @@ function isSummaryFieldVisible(summaryField, summaryConfig, isOpen) {
|
|
|
70
68
|
}
|
|
71
69
|
return true;
|
|
72
70
|
}
|
|
71
|
+
function HeaderContent({
|
|
72
|
+
data,
|
|
73
|
+
fields,
|
|
74
|
+
label,
|
|
75
|
+
layout,
|
|
76
|
+
isOpen,
|
|
77
|
+
touched,
|
|
78
|
+
validity
|
|
79
|
+
}) {
|
|
80
|
+
const summaryFields = (0, import_get_summary_fields.getSummaryFields)(layout.summary, fields);
|
|
81
|
+
const visibleSummaryFields = summaryFields.filter(
|
|
82
|
+
(summaryField) => isSummaryFieldVisible(summaryField, layout.summary, isOpen)
|
|
83
|
+
);
|
|
84
|
+
const hasBadge = touched && layout.isCollapsible;
|
|
85
|
+
const hasSummary = visibleSummaryFields.length > 0 && layout.withHeader;
|
|
86
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
87
|
+
import_ui.Stack,
|
|
88
|
+
{
|
|
89
|
+
align: "center",
|
|
90
|
+
justify: "space-between",
|
|
91
|
+
className: "dataforms-layouts-card__field-header-content",
|
|
92
|
+
children: [
|
|
93
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Card.Title, { children: label }),
|
|
94
|
+
(hasBadge || hasSummary) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.CollapsibleCard.HeaderDescription, { className: "dataforms-layouts-card__field-header-content-description", children: [
|
|
95
|
+
hasBadge && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_validation_badge.default, { validity }),
|
|
96
|
+
hasSummary && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dataforms-layouts-card__field-summary", children: visibleSummaryFields.map((summaryField) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
97
|
+
summaryField.render,
|
|
98
|
+
{
|
|
99
|
+
item: data,
|
|
100
|
+
field: summaryField
|
|
101
|
+
},
|
|
102
|
+
summaryField.id
|
|
103
|
+
)) })
|
|
104
|
+
] })
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
function BodyContent({
|
|
110
|
+
data,
|
|
111
|
+
field,
|
|
112
|
+
form,
|
|
113
|
+
onChange,
|
|
114
|
+
hideLabelFromVision,
|
|
115
|
+
markWhenOptional,
|
|
116
|
+
validity,
|
|
117
|
+
withHeader
|
|
118
|
+
}) {
|
|
119
|
+
if (field.children) {
|
|
120
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
121
|
+
field.description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dataforms-layouts-card__field-description", children: field.description }),
|
|
122
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
123
|
+
import_data_form_layout.DataFormLayout,
|
|
124
|
+
{
|
|
125
|
+
data,
|
|
126
|
+
form,
|
|
127
|
+
onChange,
|
|
128
|
+
validity: validity?.children
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
] });
|
|
132
|
+
}
|
|
133
|
+
const SingleFieldLayout = (0, import__.getFormFieldLayout)("regular")?.component;
|
|
134
|
+
if (!SingleFieldLayout) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
138
|
+
SingleFieldLayout,
|
|
139
|
+
{
|
|
140
|
+
data,
|
|
141
|
+
field,
|
|
142
|
+
onChange,
|
|
143
|
+
hideLabelFromVision: hideLabelFromVision || withHeader,
|
|
144
|
+
markWhenOptional,
|
|
145
|
+
validity
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
73
149
|
function FormCardField({
|
|
74
150
|
data,
|
|
75
151
|
field,
|
|
@@ -80,10 +156,7 @@ function FormCardField({
|
|
|
80
156
|
}) {
|
|
81
157
|
const { fields } = (0, import_element.useContext)(import_dataform_context.default);
|
|
82
158
|
const layout = field.layout;
|
|
83
|
-
const
|
|
84
|
-
const instanceId = (0, import_compose.useInstanceId)(FormCardField);
|
|
85
|
-
const bodyId = `dataforms-layouts-card-card-body-${instanceId}`;
|
|
86
|
-
const titleId = `dataforms-layouts-card-card-title-${instanceId}`;
|
|
159
|
+
const contentRef = (0, import_element.useRef)(null);
|
|
87
160
|
const form = (0, import_element.useMemo)(
|
|
88
161
|
() => ({
|
|
89
162
|
layout: import_normalize_form.DEFAULT_LAYOUT,
|
|
@@ -92,52 +165,28 @@ function FormCardField({
|
|
|
92
165
|
[field]
|
|
93
166
|
);
|
|
94
167
|
const { isOpened, isCollapsible } = layout;
|
|
95
|
-
const [
|
|
168
|
+
const [isOpen, setIsOpen] = (0, import_element.useState)(isOpened);
|
|
96
169
|
const [touched, setTouched] = (0, import_element.useState)(false);
|
|
97
170
|
(0, import_element.useEffect)(() => {
|
|
98
171
|
setIsOpen(isOpened);
|
|
99
172
|
}, [isOpened]);
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return !prev;
|
|
106
|
-
});
|
|
173
|
+
const handleOpenChange = (0, import_element.useCallback)((open) => {
|
|
174
|
+
if (!open) {
|
|
175
|
+
setTouched(true);
|
|
176
|
+
}
|
|
177
|
+
setIsOpen(open);
|
|
107
178
|
}, []);
|
|
108
|
-
const isOpen = isCollapsible ? internalIsOpen : true;
|
|
109
179
|
const handleBlur = (0, import_element.useCallback)(() => {
|
|
110
180
|
setTouched(true);
|
|
111
|
-
}, [
|
|
112
|
-
(0, import_use_report_validity.default)(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
(summaryField) => isSummaryFieldVisible(summaryField, layout.summary, isOpen)
|
|
181
|
+
}, []);
|
|
182
|
+
(0, import_use_report_validity.default)(
|
|
183
|
+
contentRef,
|
|
184
|
+
(isCollapsible ? isOpen : true) && touched
|
|
116
185
|
);
|
|
117
|
-
const validationBadge = touched && layout.isCollapsible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_validation_badge.default, { validity }) : null;
|
|
118
|
-
const sizeCard = {
|
|
119
|
-
blockStart: "medium",
|
|
120
|
-
blockEnd: "medium",
|
|
121
|
-
inlineStart: "medium",
|
|
122
|
-
inlineEnd: "medium"
|
|
123
|
-
};
|
|
124
186
|
let label = field.label;
|
|
125
187
|
let withHeader;
|
|
126
|
-
let bodyContent;
|
|
127
188
|
if (field.children) {
|
|
128
189
|
withHeader = !!label && layout.withHeader;
|
|
129
|
-
bodyContent = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
130
|
-
field.description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dataforms-layouts-card__field-description", children: field.description }),
|
|
131
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
132
|
-
import_data_form_layout.DataFormLayout,
|
|
133
|
-
{
|
|
134
|
-
data,
|
|
135
|
-
form,
|
|
136
|
-
onChange,
|
|
137
|
-
validity: validity?.children
|
|
138
|
-
}
|
|
139
|
-
)
|
|
140
|
-
] });
|
|
141
190
|
} else {
|
|
142
191
|
const fieldDefinition = fields.find(
|
|
143
192
|
(fieldDef) => fieldDef.id === field.id
|
|
@@ -145,103 +194,58 @@ function FormCardField({
|
|
|
145
194
|
if (!fieldDefinition || !fieldDefinition.Edit) {
|
|
146
195
|
return null;
|
|
147
196
|
}
|
|
148
|
-
const SingleFieldLayout = (0, import__.getFormFieldLayout)("regular")?.component;
|
|
149
|
-
if (!SingleFieldLayout) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
197
|
label = fieldDefinition.label;
|
|
153
198
|
withHeader = !!label && layout.withHeader;
|
|
154
|
-
bodyContent = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
155
|
-
SingleFieldLayout,
|
|
156
|
-
{
|
|
157
|
-
data,
|
|
158
|
-
field,
|
|
159
|
-
onChange,
|
|
160
|
-
hideLabelFromVision: hideLabelFromVision || withHeader,
|
|
161
|
-
markWhenOptional,
|
|
162
|
-
validity
|
|
163
|
-
}
|
|
164
|
-
);
|
|
165
199
|
}
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
200
|
+
const bodyContent = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
201
|
+
BodyContent,
|
|
202
|
+
{
|
|
203
|
+
data,
|
|
204
|
+
field,
|
|
205
|
+
form,
|
|
206
|
+
onChange,
|
|
207
|
+
hideLabelFromVision,
|
|
208
|
+
markWhenOptional,
|
|
209
|
+
validity,
|
|
210
|
+
withHeader
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
const headerContent = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
214
|
+
HeaderContent,
|
|
215
|
+
{
|
|
216
|
+
data,
|
|
217
|
+
fields,
|
|
218
|
+
label,
|
|
219
|
+
layout,
|
|
220
|
+
isOpen: isCollapsible ? !!isOpen : true,
|
|
221
|
+
touched,
|
|
222
|
+
validity
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
if (withHeader && isCollapsible) {
|
|
226
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
227
|
+
import_ui.CollapsibleCard.Root,
|
|
175
228
|
{
|
|
176
|
-
className: "dataforms-layouts-card__field
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
cursor: isCollapsible ? "pointer" : void 0
|
|
180
|
-
},
|
|
181
|
-
isBorderless: true,
|
|
229
|
+
className: "dataforms-layouts-card__field",
|
|
230
|
+
open: isOpen,
|
|
231
|
+
onOpenChange: handleOpenChange,
|
|
182
232
|
children: [
|
|
183
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
style: {
|
|
187
|
-
// Match the expand/collapse button's height to avoid layout
|
|
188
|
-
// differences when that button is not displayed.
|
|
189
|
-
height: isCollapsible ? void 0 : "40px",
|
|
190
|
-
width: "100%",
|
|
191
|
-
display: "flex",
|
|
192
|
-
justifyContent: "space-between",
|
|
193
|
-
alignItems: "center"
|
|
194
|
-
},
|
|
195
|
-
children: [
|
|
196
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
197
|
-
"span",
|
|
198
|
-
{
|
|
199
|
-
id: titleId,
|
|
200
|
-
className: "dataforms-layouts-card__field-header-label",
|
|
201
|
-
children: label
|
|
202
|
-
}
|
|
203
|
-
),
|
|
204
|
-
validationBadge,
|
|
205
|
-
visibleSummaryFields.length > 0 && layout.withHeader && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dataforms-layouts-card__field-summary", children: visibleSummaryFields.map(
|
|
206
|
-
(summaryField) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
207
|
-
summaryField.render,
|
|
208
|
-
{
|
|
209
|
-
item: data,
|
|
210
|
-
field: summaryField
|
|
211
|
-
},
|
|
212
|
-
summaryField.id
|
|
213
|
-
)
|
|
214
|
-
) })
|
|
215
|
-
]
|
|
216
|
-
}
|
|
217
|
-
),
|
|
218
|
-
isCollapsible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
219
|
-
import_components.Button,
|
|
233
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.CollapsibleCard.Header, { children: headerContent }),
|
|
234
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
235
|
+
import_ui.CollapsibleCard.Content,
|
|
220
236
|
{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
"aria-expanded": isOpen,
|
|
225
|
-
"aria-controls": bodyId,
|
|
226
|
-
"aria-labelledby": titleId
|
|
237
|
+
ref: contentRef,
|
|
238
|
+
onBlur: handleBlur,
|
|
239
|
+
children: bodyContent
|
|
227
240
|
}
|
|
228
241
|
)
|
|
229
242
|
]
|
|
230
243
|
}
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
235
|
-
|
|
236
|
-
{
|
|
237
|
-
id: bodyId,
|
|
238
|
-
size: sizeCardBody,
|
|
239
|
-
className: "dataforms-layouts-card__field-control",
|
|
240
|
-
ref: cardBodyRef,
|
|
241
|
-
onBlur: handleBlur,
|
|
242
|
-
children: bodyContent
|
|
243
|
-
}
|
|
244
|
-
)
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Card.Root, { className: "dataforms-layouts-card__field", children: [
|
|
247
|
+
withHeader && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Card.Header, { children: headerContent }),
|
|
248
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Card.Content, { ref: contentRef, onBlur: handleBlur, children: bodyContent })
|
|
245
249
|
] });
|
|
246
250
|
}
|
|
247
251
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataform-layouts/card/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n// TODO: enable in the ESlint rule once we complete\n// https://github.com/WordPress/gutenberg/issues/76135.\n// eslint-disable-next-line @wordpress/use-recommended-components\nimport { Card, CollapsibleCard, Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport { getFormFieldLayout } from '..';\nimport DataFormContext from '../../dataform-context';\nimport type {\n\tFieldLayoutProps,\n\tNormalizedCardLayout,\n\tNormalizedField,\n\tNormalizedForm,\n\tNormalizedLayout,\n} from '../../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { DEFAULT_LAYOUT } from '../normalize-form';\nimport { getSummaryFields } from '../get-summary-fields';\nimport useReportValidity from '../../../hooks/use-report-validity';\nimport ValidationBadge from '../validation-badge';\n\nfunction isSummaryFieldVisible< Item >(\n\tsummaryField: NormalizedField< Item >,\n\tsummaryConfig: NormalizedCardLayout[ 'summary' ],\n\tisOpen: boolean\n) {\n\t// If no summary config, dont't show any fields\n\tif (\n\t\t! summaryConfig ||\n\t\t( Array.isArray( summaryConfig ) && summaryConfig.length === 0 )\n\t) {\n\t\treturn false;\n\t}\n\n\t// Convert to array for consistent handling\n\tconst summaryConfigArray = Array.isArray( summaryConfig )\n\t\t? summaryConfig\n\t\t: [ summaryConfig ];\n\n\t// Find the config for this specific field\n\tconst fieldConfig = summaryConfigArray.find( ( config ) => {\n\t\tif ( typeof config === 'string' ) {\n\t\t\treturn config === summaryField.id;\n\t\t}\n\t\tif ( typeof config === 'object' && 'id' in config ) {\n\t\t\treturn config.id === summaryField.id;\n\t\t}\n\t\treturn false;\n\t} );\n\n\t// If field is not in summary config, don't show it\n\tif ( ! fieldConfig ) {\n\t\treturn false;\n\t}\n\n\t// If it's a string, always show it\n\tif ( typeof fieldConfig === 'string' ) {\n\t\treturn true;\n\t}\n\n\t// If it has visibility rules, respect them\n\tif ( typeof fieldConfig === 'object' && 'visibility' in fieldConfig ) {\n\t\treturn (\n\t\t\tfieldConfig.visibility === 'always' ||\n\t\t\t( fieldConfig.visibility === 'when-collapsed' && ! isOpen )\n\t\t);\n\t}\n\n\t// Default to always show\n\treturn true;\n}\n\nfunction HeaderContent< Item >( {\n\tdata,\n\tfields,\n\tlabel,\n\tlayout,\n\tisOpen,\n\ttouched,\n\tvalidity,\n}: {\n\tdata: Item;\n\tfields: NormalizedField< Item >[];\n\tlabel: string | undefined;\n\tlayout: NormalizedCardLayout;\n\tisOpen: boolean;\n\ttouched: boolean;\n\tvalidity: FieldLayoutProps< Item >[ 'validity' ];\n} ) {\n\tconst summaryFields = getSummaryFields< Item >( layout.summary, fields );\n\n\tconst visibleSummaryFields = summaryFields.filter( ( summaryField ) =>\n\t\tisSummaryFieldVisible( summaryField, layout.summary, isOpen )\n\t);\n\n\tconst hasBadge = touched && layout.isCollapsible;\n\tconst hasSummary = visibleSummaryFields.length > 0 && layout.withHeader;\n\n\treturn (\n\t\t<Stack\n\t\t\talign=\"center\"\n\t\t\tjustify=\"space-between\"\n\t\t\tclassName=\"dataforms-layouts-card__field-header-content\"\n\t\t>\n\t\t\t<Card.Title>{ label }</Card.Title>\n\t\t\t{ ( hasBadge || hasSummary ) && (\n\t\t\t\t<CollapsibleCard.HeaderDescription className=\"dataforms-layouts-card__field-header-content-description\">\n\t\t\t\t\t{ hasBadge && <ValidationBadge validity={ validity } /> }\n\t\t\t\t\t{ hasSummary && (\n\t\t\t\t\t\t<div className=\"dataforms-layouts-card__field-summary\">\n\t\t\t\t\t\t\t{ visibleSummaryFields.map( ( summaryField ) => (\n\t\t\t\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t</CollapsibleCard.HeaderDescription>\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction BodyContent< Item >( {\n\tdata,\n\tfield,\n\tform,\n\tonChange,\n\thideLabelFromVision,\n\tmarkWhenOptional,\n\tvalidity,\n\twithHeader,\n}: {\n\tdata: Item;\n\tfield: FieldLayoutProps< Item >[ 'field' ];\n\tform: NormalizedForm;\n\tonChange: FieldLayoutProps< Item >[ 'onChange' ];\n\thideLabelFromVision?: boolean;\n\tmarkWhenOptional?: boolean;\n\tvalidity: FieldLayoutProps< Item >[ 'validity' ];\n\twithHeader: boolean;\n} ) {\n\tif ( field.children ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ field.description && (\n\t\t\t\t\t<div className=\"dataforms-layouts-card__field-description\">\n\t\t\t\t\t\t{ field.description }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<DataFormLayout\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tvalidity={ validity?.children }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n\n\tconst SingleFieldLayout = getFormFieldLayout( 'regular' )?.component;\n\tif ( ! SingleFieldLayout ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<SingleFieldLayout\n\t\t\tdata={ data }\n\t\t\tfield={ field }\n\t\t\tonChange={ onChange }\n\t\t\thideLabelFromVision={ hideLabelFromVision || withHeader }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tvalidity={ validity }\n\t\t/>\n\t);\n}\n\nexport default function FormCardField< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tmarkWhenOptional,\n\tvalidity,\n}: FieldLayoutProps< Item > ) {\n\tconst { fields } = useContext( DataFormContext );\n\tconst layout = field.layout as NormalizedCardLayout;\n\tconst contentRef = useRef< HTMLDivElement >( null );\n\n\tconst form: NormalizedForm = useMemo(\n\t\t() => ( {\n\t\t\tlayout: DEFAULT_LAYOUT as NormalizedLayout,\n\t\t\tfields: field.children ?? [],\n\t\t} ),\n\t\t[ field ]\n\t);\n\n\tconst { isOpened, isCollapsible } = layout;\n\tconst [ isOpen, setIsOpen ] = useState( isOpened );\n\tconst [ touched, setTouched ] = useState( false );\n\n\t// Sync internal state when the isOpened prop changes.\n\t// This is unlikely to happen in production, but it helps with storybook controls.\n\tuseEffect( () => {\n\t\tsetIsOpen( isOpened );\n\t}, [ isOpened ] );\n\n\tconst handleOpenChange = useCallback( ( open: boolean ) => {\n\t\t// Mark as touched when collapsing (going from open to closed)\n\t\tif ( ! open ) {\n\t\t\tsetTouched( true );\n\t\t}\n\t\tsetIsOpen( open );\n\t}, [] );\n\n\t// Mark the card as touched when any field inside it is blurred.\n\t// This aligns with how validated controls show errors on blur.\n\tconst handleBlur = useCallback( () => {\n\t\tsetTouched( true );\n\t}, [] );\n\n\t// When the card is expanded after being touched (collapsed with errors),\n\t// trigger reportValidity to show field-level errors.\n\tuseReportValidity(\n\t\tcontentRef,\n\t\t( isCollapsible ? isOpen : true ) && touched\n\t);\n\n\tlet label = field.label;\n\tlet withHeader: boolean;\n\n\tif ( field.children ) {\n\t\twithHeader = !! label && layout.withHeader;\n\t} else {\n\t\tconst fieldDefinition = fields.find(\n\t\t\t( fieldDef ) => fieldDef.id === field.id\n\t\t);\n\n\t\tif ( ! fieldDefinition || ! fieldDefinition.Edit ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tlabel = fieldDefinition.label;\n\t\twithHeader = !! label && layout.withHeader;\n\t}\n\n\tconst bodyContent = (\n\t\t<BodyContent\n\t\t\tdata={ data }\n\t\t\tfield={ field }\n\t\t\tform={ form }\n\t\t\tonChange={ onChange }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tvalidity={ validity }\n\t\t\twithHeader={ withHeader }\n\t\t/>\n\t);\n\n\tconst headerContent = (\n\t\t<HeaderContent\n\t\t\tdata={ data }\n\t\t\tfields={ fields }\n\t\t\tlabel={ label }\n\t\t\tlayout={ layout }\n\t\t\tisOpen={ isCollapsible ? !! isOpen : true }\n\t\t\ttouched={ touched }\n\t\t\tvalidity={ validity }\n\t\t/>\n\t);\n\n\tif ( withHeader && isCollapsible ) {\n\t\treturn (\n\t\t\t<CollapsibleCard.Root\n\t\t\t\tclassName=\"dataforms-layouts-card__field\"\n\t\t\t\topen={ isOpen }\n\t\t\t\tonOpenChange={ handleOpenChange }\n\t\t\t>\n\t\t\t\t<CollapsibleCard.Header>\n\t\t\t\t\t{ headerContent }\n\t\t\t\t</CollapsibleCard.Header>\n\t\t\t\t<CollapsibleCard.Content\n\t\t\t\t\tref={ contentRef }\n\t\t\t\t\tonBlur={ handleBlur }\n\t\t\t\t>\n\t\t\t\t\t{ bodyContent }\n\t\t\t\t</CollapsibleCard.Content>\n\t\t\t</CollapsibleCard.Root>\n\t\t);\n\t}\n\n\treturn (\n\t\t<Card.Root className=\"dataforms-layouts-card__field\">\n\t\t\t{ withHeader && <Card.Header>{ headerContent }</Card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