@wordpress/dataviews 16.0.1 → 17.0.1-next.v.202606191442.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 +25 -0
- package/README.md +2 -2
- package/build/components/dataform-layouts/panel/summary-button.cjs.map +2 -2
- package/build/components/dataform-layouts/panel/utils/get-label-content.cjs.map +2 -2
- package/build/components/dataviews-filters/filter.cjs.map +2 -2
- package/build/components/dataviews-layouts/grid/composite-grid.cjs.map +2 -2
- package/build/components/dataviews-layouts/list/index.cjs.map +1 -1
- package/build/components/dataviews-layouts/table/column-primary.cjs +2 -2
- package/build/components/dataviews-layouts/table/column-primary.cjs.map +2 -2
- package/build/components/dataviews-pagination/index.cjs.map +1 -1
- package/build/components/dataviews-picker-footer/index.cjs +72 -33
- package/build/components/dataviews-picker-footer/index.cjs.map +2 -2
- package/build/constants.cjs +1 -1
- package/build/constants.cjs.map +2 -2
- package/build/dataviews-picker/index.cjs +2 -1
- package/build/dataviews-picker/index.cjs.map +2 -2
- package/build/field-types/password.cjs +1 -1
- package/build/field-types/password.cjs.map +2 -2
- package/build/hooks/use-form-validity.cjs +2 -2
- package/build/hooks/use-form-validity.cjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/summary-button.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs.map +2 -2
- package/build-module/components/dataviews-filters/filter.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/list/index.mjs.map +1 -1
- package/build-module/components/dataviews-layouts/table/column-primary.mjs +2 -2
- package/build-module/components/dataviews-layouts/table/column-primary.mjs.map +2 -2
- package/build-module/components/dataviews-pagination/index.mjs.map +1 -1
- package/build-module/components/dataviews-picker-footer/index.mjs +71 -33
- package/build-module/components/dataviews-picker-footer/index.mjs.map +2 -2
- package/build-module/constants.mjs +1 -1
- package/build-module/constants.mjs.map +2 -2
- package/build-module/dataviews-picker/index.mjs +6 -2
- package/build-module/dataviews-picker/index.mjs.map +2 -2
- package/build-module/field-types/password.mjs +1 -1
- package/build-module/field-types/password.mjs.map +2 -2
- package/build-module/hooks/use-form-validity.mjs +2 -2
- package/build-module/hooks/use-form-validity.mjs.map +2 -2
- package/build-style/style-rtl.css +164 -176
- package/build-style/style.css +164 -176
- package/build-types/components/dataform-layouts/panel/summary-button.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/utils/get-label-content.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/filter.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/grid/composite-grid.d.ts.map +1 -1
- package/build-types/components/dataviews-picker-footer/index.d.ts +3 -2
- package/build-types/components/dataviews-picker-footer/index.d.ts.map +1 -1
- package/build-types/dataviews-picker/index.d.ts +3 -2
- package/build-types/dataviews-picker/index.d.ts.map +1 -1
- package/build-wp/index.js +324 -282
- package/package.json +26 -21
- package/src/components/dataform-controls/style.scss +1 -1
- package/src/components/dataform-layouts/card/style.scss +1 -1
- package/src/components/dataform-layouts/details/style.scss +1 -1
- package/src/components/dataform-layouts/panel/style.scss +18 -31
- package/src/components/dataform-layouts/panel/summary-button.tsx +0 -1
- package/src/components/dataform-layouts/panel/utils/get-label-content.tsx +0 -1
- package/src/components/dataform-layouts/regular/style.scss +4 -4
- package/src/components/dataviews-bulk-actions/style.scss +2 -2
- package/src/components/dataviews-filters/filter.tsx +0 -1
- package/src/components/dataviews-filters/style.scss +44 -45
- package/src/components/dataviews-layouts/activity/style.scss +11 -11
- package/src/components/dataviews-layouts/grid/composite-grid.tsx +0 -1
- package/src/components/dataviews-layouts/grid/style.scss +12 -12
- package/src/components/dataviews-layouts/list/style.scss +20 -21
- package/src/components/dataviews-layouts/picker-activity/style.scss +10 -10
- package/src/components/dataviews-layouts/picker-grid/style.scss +10 -10
- package/src/components/dataviews-layouts/picker-table/style.scss +4 -4
- package/src/components/dataviews-layouts/table/style.scss +17 -17
- package/src/components/dataviews-picker-footer/index.tsx +94 -31
- package/src/components/dataviews-picker-footer/style.scss +1 -1
- package/src/components/dataviews-view-config/style.scss +1 -1
- package/src/dataviews/style.scss +8 -8
- package/src/dataviews-picker/index.tsx +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 17.0.0-next.0 (2026-06-19)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- `DataViewsPicker`: `DataViewsPicker.BulkActionToolbar` now renders only the bulk-selection info and action buttons, without pagination, matching `DataViews.BulkActionToolbar`. The full footer it previously rendered (including pagination) is now exposed as `DataViewsPicker.Footer`, matching `DataViews.Footer`. [#79180](https://github.com/WordPress/gutenberg/pull/79180)
|
|
10
|
+
|
|
11
|
+
### Bug Fix
|
|
12
|
+
|
|
13
|
+
- DataForm panel layout: use `overflow: clip` on field controls so focus rings of inner elements are no longer clipped. [#79275](https://github.com/WordPress/gutenberg/pull/79275)
|
|
14
|
+
|
|
15
|
+
### Code Quality
|
|
16
|
+
|
|
17
|
+
- Move `@types/react` from `dependencies` to an optional peer dependency so consumers' React type version is used [#79095](https://github.com/WordPress/gutenberg/pull/79095).
|
|
18
|
+
- DataForm panel layout: remove button/dropdown-specific overrides from `.dataforms-layouts-panel__field-control`; those overrides are no longer needed. [#79275](https://github.com/WordPress/gutenberg/pull/79275)
|
|
19
|
+
- DataForm panel layout: align `label-side` gap with the regular layout by using `--wpds-dimension-gap-sm` (8px). [#79311](https://github.com/WordPress/gutenberg/pull/79311)
|
|
20
|
+
|
|
21
|
+
### Documentation
|
|
22
|
+
|
|
23
|
+
- Fix `overriden` typo to `overridden` in README. ([#79331](https://github.com/WordPress/gutenberg/pull/79331))
|
|
24
|
+
|
|
25
|
+
### Internal
|
|
26
|
+
|
|
27
|
+
- Adopt `--wpds-dimension-size-*` design tokens [#79093](https://github.com/WordPress/gutenberg/pull/79093).
|
|
28
|
+
|
|
5
29
|
## 16.0.1 (2026-06-16)
|
|
6
30
|
|
|
7
31
|
## 16.0.0 (2026-06-10)
|
|
@@ -24,6 +48,7 @@
|
|
|
24
48
|
|
|
25
49
|
### Internal
|
|
26
50
|
|
|
51
|
+
- Update `@ariakit/react` to `0.4.29` ([#79055](https://github.com/WordPress/gutenberg/pull/79055)).
|
|
27
52
|
- Dependency updates ([#77954](https://github.com/WordPress/gutenberg/pull/77954)).
|
|
28
53
|
|
|
29
54
|
## 15.0.0 (2026-05-27)
|
package/README.md
CHANGED
|
@@ -1669,7 +1669,7 @@ When the field declares a type, it gets a default sort function:
|
|
|
1669
1669
|
}
|
|
1670
1670
|
```
|
|
1671
1671
|
|
|
1672
|
-
The default sorting can be
|
|
1672
|
+
The default sorting can be overridden by providing a custom sort function. It takes the following arguments:
|
|
1673
1673
|
|
|
1674
1674
|
- `a`: the first item to compare
|
|
1675
1675
|
- `b`: the second item to compare
|
|
@@ -1717,7 +1717,7 @@ Fields that define a type come with default validation for the type. For example
|
|
|
1717
1717
|
}
|
|
1718
1718
|
```
|
|
1719
1719
|
|
|
1720
|
-
The validation rules can be
|
|
1720
|
+
The validation rules can be overridden by the field author. For example, to set the field as required, or to provide a custom validation so that only even numbers are valid:
|
|
1721
1721
|
|
|
1722
1722
|
```js
|
|
1723
1723
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataform-layouts/panel/summary-button.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Icon as WCIcon } from '@wordpress/components';\nimport { sprintf, _x } from '@wordpress/i18n';\nimport { error as errorIcon, pencil } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,wBAAuC;AACvC,kBAA4B;AAC5B,mBAA2C;AAC3C,qBAA8B;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Icon as WCIcon } from '@wordpress/components';\nimport { sprintf, _x } from '@wordpress/i18n';\nimport { error as errorIcon, pencil } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\nimport { Tooltip } from '@wordpress/ui';\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tFieldValidity,\n\tNormalizedField,\n\tNormalizedFormField,\n\tNormalizedPanelLayout,\n} from '../../../types';\nimport getLabelClassName from './utils/get-label-classname';\nimport getLabelContent from './utils/get-label-content';\nimport getFirstValidationError from './utils/get-first-validation-error';\n\nexport default function SummaryButton< Item >( {\n\tdata,\n\tfield,\n\tfieldLabel,\n\tsummaryFields,\n\tvalidity,\n\ttouched,\n\tdisabled,\n\tonClick,\n\t'aria-expanded': ariaExpanded,\n}: {\n\tdata: Item;\n\tfield: NormalizedFormField;\n\tfieldLabel?: string;\n\tsummaryFields: NormalizedField< Item >[];\n\tvalidity?: FieldValidity;\n\ttouched: boolean;\n\tdisabled?: boolean;\n\tonClick: () => void;\n\t'aria-expanded'?: boolean;\n} ) {\n\tconst { labelPosition, editVisibility } =\n\t\tfield.layout as NormalizedPanelLayout;\n\tconst errorMessage = getFirstValidationError( validity );\n\tconst showError = touched && !! errorMessage;\n\tconst labelClassName = getLabelClassName( labelPosition, showError );\n\tconst labelContent = getLabelContent( showError, errorMessage, fieldLabel );\n\tconst className = clsx(\n\t\t'dataforms-layouts-panel__field-trigger',\n\t\t`dataforms-layouts-panel__field-trigger--label-${ labelPosition }`,\n\t\t{\n\t\t\t'is-disabled': disabled,\n\t\t\t'dataforms-layouts-panel__field-trigger--edit-always':\n\t\t\t\teditVisibility === 'always',\n\t\t}\n\t);\n\n\tconst controlId = useInstanceId(\n\t\tSummaryButton,\n\t\t'dataforms-layouts-panel__field-control'\n\t);\n\n\tconst ariaLabel = showError\n\t\t? sprintf(\n\t\t\t\t// translators: %s: Field name.\n\t\t\t\t_x( 'Edit %s (has errors)', 'field' ),\n\t\t\t\tfieldLabel || ''\n\t\t )\n\t\t: sprintf(\n\t\t\t\t// translators: %s: Field name.\n\t\t\t\t_x( 'Edit %s', 'field' ),\n\t\t\t\tfieldLabel || ''\n\t\t );\n\n\tconst rowRef = useRef< HTMLDivElement >( null );\n\n\tconst handleRowClick = () => {\n\t\tconst selection =\n\t\t\trowRef.current?.ownerDocument.defaultView?.getSelection();\n\t\tif ( selection && selection.toString().length > 0 ) {\n\t\t\treturn;\n\t\t}\n\t\tonClick();\n\t};\n\n\tconst handleKeyDown = ( event: React.KeyboardEvent ) => {\n\t\tif (\n\t\t\tevent.target === event.currentTarget &&\n\t\t\t( event.key === 'Enter' || event.key === ' ' )\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\tonClick();\n\t\t}\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tref={ rowRef }\n\t\t\tclassName={ className }\n\t\t\tonClick={ ! disabled ? handleRowClick : undefined }\n\t\t\tonKeyDown={ ! disabled ? handleKeyDown : undefined }\n\t\t>\n\t\t\t{ labelPosition !== 'none' && (\n\t\t\t\t<span className={ labelClassName }>{ labelContent }</span>\n\t\t\t) }\n\t\t\t{ labelPosition === 'none' && showError && (\n\t\t\t\t<Tooltip.Root>\n\t\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"dataforms-layouts-panel__field-label-error-content\"\n\t\t\t\t\t\t\t\trole=\"img\"\n\t\t\t\t\t\t\t\taria-label={ errorMessage }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<WCIcon icon={ errorIcon } size={ 16 } />\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<Tooltip.Popup>{ errorMessage }</Tooltip.Popup>\n\t\t\t\t</Tooltip.Root>\n\t\t\t) }\n\t\t\t<span\n\t\t\t\tid={ `${ controlId }` }\n\t\t\t\tclassName=\"dataforms-layouts-panel__field-control\"\n\t\t\t>\n\t\t\t\t{ summaryFields.length > 1 ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\t\t\tflexDirection: 'column',\n\t\t\t\t\t\t\talignItems: 'flex-start',\n\t\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\t\tgap: '2px',\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ summaryFields.map( ( summaryField ) => (\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<summaryField.render\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</span>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</span>\n\t\t\t\t) : (\n\t\t\t\t\tsummaryFields.map( ( summaryField ) => (\n\t\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) )\n\t\t\t\t) }\n\t\t\t</span>\n\t\t\t{ ! disabled && (\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"dataforms-layouts-panel__field-trigger-icon\"\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\ticon={ pencil }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\taria-expanded={ ariaExpanded }\n\t\t\t\t\taria-haspopup=\"dialog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AA,YACH,IAEA,cAAc,IAAK,CAAE,iBACpB;AAAA,cAAC,aAAa;AAAA,cAAb;AAAA,gBAEA,MAAO;AAAA,gBACP,OAAQ;AAAA;AAAA,cAFF,aAAa;AAAA,YAGpB,CACC;AAAA;AAAA,QAEJ;AAAA,QACE,CAAE,YACH;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ;AAAA,YACR,MAAO;AAAA,YACP,MAAK;AAAA,YACL,iBAAgB;AAAA,YAChB,iBAAc;AAAA,YACd,oBAAmB,GAAI,SAAU;AAAA;AAAA,QAClC;AAAA;AAAA;AAAA,EAEF;AAEF;",
|
|
6
6
|
"names": ["getFirstValidationError", "getLabelClassName", "getLabelContent", "clsx", "WCIcon", "errorIcon"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/components/dataform-layouts/panel/utils/get-label-content.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Icon as WCIcon } from '@wordpress/components';\nimport { error as errorIcon } from '@wordpress/icons';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA+B;AAC/B,mBAAmC;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Icon as WCIcon } from '@wordpress/components';\nimport { error as errorIcon } from '@wordpress/icons';\nimport { Tooltip, VisuallyHidden } from '@wordpress/ui';\n\nfunction getLabelContent(\n\tshowError?: boolean,\n\terrorMessage?: string,\n\tfieldLabel?: string\n) {\n\treturn showError ? (\n\t\t<Tooltip.Root>\n\t\t\t<Tooltip.Trigger\n\t\t\t\trender={\n\t\t\t\t\t<span className=\"dataforms-layouts-panel__field-label-error-content\">\n\t\t\t\t\t\t<WCIcon icon={ errorIcon } size={ 16 } />\n\t\t\t\t\t\t<VisuallyHidden>{ errorMessage }: </VisuallyHidden>\n\t\t\t\t\t\t{ fieldLabel }\n\t\t\t\t\t</span>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Tooltip.Popup>{ errorMessage }</Tooltip.Popup>\n\t\t</Tooltip.Root>\n\t) : (\n\t\tfieldLabel\n\t);\n}\n\nexport default getLabelContent;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA+B;AAC/B,mBAAmC;AACnC,gBAAwC;AAYlC;AAVN,SAAS,gBACR,WACA,cACA,YACC;AACD,SAAO,YACN,6CAAC,kBAAQ,MAAR,EACA;AAAA;AAAA,MAAC,kBAAQ;AAAA,MAAR;AAAA,QACA,QACC,6CAAC,UAAK,WAAU,sDACf;AAAA,sDAAC,kBAAAA,MAAA,EAAO,MAAO,aAAAC,OAAY,MAAO,IAAK;AAAA,UACvC,6CAAC,4BAAiB;AAAA;AAAA,YAAc;AAAA,aAAE;AAAA,UAChC;AAAA,WACH;AAAA;AAAA,IAEF;AAAA,IACA,4CAAC,kBAAQ,OAAR,EAAgB,wBAAc;AAAA,KAChC,IAEA;AAEF;AAEA,IAAO,4BAAQ;",
|
|
6
6
|
"names": ["WCIcon", "errorIcon"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-filters/filter.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdown,\n\tFlexItem,\n\tSelectControl,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useRef } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\n// eslint-disable-next-line @wordpress/use-recommended-components -- `Tooltip` is not yet on the recommended `@wordpress/ui` allow-list; landing as a migration step ahead of the wider rollout.\nimport { Stack, Tooltip } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport SearchWidget from './search-widget';\nimport InputWidget from './input-widget';\nimport { getOperatorByName } from '../../utils/operators';\nimport type {\n\tFilter,\n\tNormalizedField,\n\tNormalizedFilter,\n\tOperator,\n\tOption,\n\tView,\n} from '../../types';\nimport useElements from '../../hooks/use-elements';\n\nconst ENTER = 'Enter';\nconst SPACE = ' ';\n\ninterface FilterTextProps {\n\tactiveElements: Option[];\n\tfilterInView?: Filter;\n\tfilter: NormalizedFilter;\n}\n\ninterface OperatorSelectorProps {\n\tfilter: NormalizedFilter;\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n}\n\ninterface FilterProps extends OperatorSelectorProps {\n\taddFilterRef: RefObject< HTMLButtonElement | null >;\n\topenedFilter: string | null;\n\tfields: NormalizedField< any >[];\n}\n\nconst FilterText = ( {\n\tactiveElements,\n\tfilterInView,\n\tfilter,\n}: FilterTextProps ) => {\n\tif ( activeElements === undefined || activeElements.length === 0 ) {\n\t\treturn filter.name;\n\t}\n\n\tconst operator = getOperatorByName( filterInView?.operator );\n\tif ( operator !== undefined ) {\n\t\treturn operator.filterText( filter, activeElements );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: 1: Filter name e.g.: \"Unknown status for Author\". */\n\t\t__( 'Unknown status for %1$s' ),\n\t\tfilter.name\n\t);\n};\n\nfunction OperatorSelector( {\n\tfilter,\n\tview,\n\tonChangeView,\n}: OperatorSelectorProps ) {\n\tconst operatorOptions = filter.operators?.map( ( operator ) => ( {\n\t\tvalue: operator,\n\t\tlabel: getOperatorByName( operator )?.label || operator,\n\t} ) );\n\tconst currentFilter = view.filters?.find(\n\t\t( _filter ) => _filter.field === filter.field\n\t);\n\tconst value = currentFilter?.operator || filter.operators[ 0 ];\n\treturn (\n\t\toperatorOptions.length > 1 && (\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tgap=\"sm\"\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-filters__summary-operators-container\"\n\t\t\t\talign=\"center\"\n\t\t\t>\n\t\t\t\t<FlexItem className=\"dataviews-filters__summary-operators-filter-name\">\n\t\t\t\t\t{ filter.name }\n\t\t\t\t</FlexItem>\n\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-filters__summary-operators-filter-select\"\n\t\t\t\t\tlabel={ __( 'Conditions' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\toptions={ operatorOptions }\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tconst newOperator = newValue as Operator;\n\t\t\t\t\t\tconst currentOperator = currentFilter?.operator;\n\t\t\t\t\t\tconst newFilters = currentFilter\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ).map(\n\t\t\t\t\t\t\t\t\t\t( _filter ) => {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst currentOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\t\t\t\t\t\t\t\t\t\t\t\tconst newOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\n\t\t\t\t\t\t\t\t\t\t\t\tconst shouldResetValue =\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel !==\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t].includes( 'custom' );\n\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: shouldResetValue\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: _filter.value,\n\t\t\t\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn _filter;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ];\n\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\tfilters: newFilters,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tvariant=\"minimal\"\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</Stack>\n\t\t)\n\t);\n}\n\nexport default function Filter( {\n\taddFilterRef,\n\topenedFilter,\n\tfields,\n\t...commonProps\n}: FilterProps ) {\n\tconst toggleRef = useRef< HTMLDivElement >( null );\n\tconst { filter, view, onChangeView } = commonProps;\n\tconst filterInView = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\n\tlet activeElements: Option[] = [];\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Configure getValue as if Item was a plain object.\n\t\t\t\t// See related input-widget.tsx\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t};\n\t\t}\n\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst { elements } = useElements( {\n\t\telements: filter.elements,\n\t\tgetElements: filter.getElements,\n\t} );\n\n\tif ( elements.length > 0 ) {\n\t\t// When there are elements, we favor those\n\t\tactiveElements = elements.filter( ( element ) => {\n\t\t\tif ( filter.singleSelection ) {\n\t\t\t\treturn element.value === filterInView?.value;\n\t\t\t}\n\t\t\treturn filterInView?.value?.includes( element.value );\n\t\t} );\n\t} else if ( Array.isArray( filterInView?.value ) ) {\n\t\t// or, filterInView.value can also be array\n\t\t// for the between operator, as in [ 1, 2 ]\n\t\tconst label = filterInView.value.map( ( v ) => {\n\t\t\tconst formattedValue = field?.getValueFormatted( {\n\t\t\t\titem: { [ field.id ]: v },\n\t\t\t\tfield,\n\t\t\t} );\n\t\t\treturn formattedValue || String( v );\n\t\t} );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\t// @ts-ignore\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t} else if ( typeof filterInView?.value === 'object' ) {\n\t\t// or, it can also be object for the inThePast/over operators,\n\t\t// as in { value: '1', units: 'days' }\n\t\tactiveElements = [\n\t\t\t{ value: filterInView.value, label: filterInView.value },\n\t\t];\n\t} else if ( filterInView?.value !== undefined ) {\n\t\t// otherwise, filterInView.value is a single value\n\t\tconst label =\n\t\t\tfield !== undefined\n\t\t\t\t? field.getValueFormatted( {\n\t\t\t\t\t\titem: { [ field.id ]: filterInView.value },\n\t\t\t\t\t\tfield,\n\t\t\t\t } )\n\t\t\t\t: String( filterInView.value );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t}\n\n\tconst isPrimary = filter.isPrimary;\n\tconst isLocked = filterInView?.isLocked;\n\tconst hasValues = ! isLocked && filterInView?.value !== undefined;\n\tconst canResetOrRemove = ! isLocked && ( ! isPrimary || hasValues );\n\t// TODO: revisit once `@wordpress/ui`'s `IconButton` is ready \u2014 it should\n\t// collapse the manual icon-only `<button>` + `aria-label` + Tooltip\n\t// composition below into a single primitive.\n\tconst resetOrRemoveLabel = isPrimary ? __( 'Reset' ) : __( 'Remove' );\n\treturn (\n\t\t<Dropdown\n\t\t\tdefaultOpen={ openedFilter === filter.field }\n\t\t\tcontentClassName=\"dataviews-filters__summary-popover\"\n\t\t\tpopoverProps={ { placement: 'bottom-start', role: 'dialog' } }\n\t\t\tonClose={ () => {\n\t\t\t\ttoggleRef.current?.focus();\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<div className=\"dataviews-filters__summary-chip-container\">\n\t\t\t\t\t<Tooltip.Root>\n\t\t\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip',\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t'has-reset': canResetOrRemove,\n\t\t\t\t\t\t\t\t\t\t\t'has-values': hasValues,\n\t\t\t\t\t\t\t\t\t\t\t'is-not-clickable': isLocked,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\t\t\ttabIndex={ isLocked ? -1 : 0 }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tif ( ! isLocked ) {\n\t\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t! isLocked &&\n\t\t\t\t\t\t\t\t\t\t\t[ ENTER, SPACE ].includes(\n\t\t\t\t\t\t\t\t\t\t\t\tevent.key\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taria-disabled={ isLocked }\n\t\t\t\t\t\t\t\t\taria-pressed={ isOpen }\n\t\t\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\t\t\tref={ toggleRef }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<FilterText\n\t\t\t\t\t\t\t\t\t\tactiveElements={ activeElements }\n\t\t\t\t\t\t\t\t\t\tfilterInView={ filterInView }\n\t\t\t\t\t\t\t\t\t\tfilter={ filter }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t/* translators: 1: Filter name. */\n\t\t\t\t\t\t\t\t__( 'Filter by: %1$s' ),\n\t\t\t\t\t\t\t\tfilter.name.toLowerCase()\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Tooltip.Popup>\n\t\t\t\t\t</Tooltip.Root>\n\t\t\t\t\t{ canResetOrRemove && (\n\t\t\t\t\t\t<Tooltip.Root>\n\t\t\t\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip-remove',\n\t\t\t\t\t\t\t\t\t\t\t{ 'has-values': hasValues }\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\taria-label={ resetOrRemoveLabel }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\t\t\tfilters: view.filters?.filter(\n\t\t\t\t\t\t\t\t\t\t\t\t\t( _filter ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t_filter.field !==\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilter.field\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\t\t// If the filter is not primary and can be removed, it will be added\n\t\t\t\t\t\t\t\t\t\t\t// back to the available filters from `Add filter` component.\n\t\t\t\t\t\t\t\t\t\t\tif ( ! isPrimary ) {\n\t\t\t\t\t\t\t\t\t\t\t\taddFilterRef.current?.focus();\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\t// If is primary, focus the toggle button.\n\t\t\t\t\t\t\t\t\t\t\t\ttoggleRef.current?.focus();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<WCIcon icon={ closeSmall } />\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t\t\t\t{ resetOrRemoveLabel }\n\t\t\t\t\t\t\t</Tooltip.Popup>\n\t\t\t\t\t\t</Tooltip.Root>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\trenderContent={ () => {\n\t\t\t\treturn (\n\t\t\t\t\t<Stack direction=\"column\" justify=\"flex-start\">\n\t\t\t\t\t\t<OperatorSelector { ...commonProps } />\n\t\t\t\t\t\t{ commonProps.filter.hasElements ? (\n\t\t\t\t\t\t\t<SearchWidget\n\t\t\t\t\t\t\t\t{ ...commonProps }\n\t\t\t\t\t\t\t\tfilter={ {\n\t\t\t\t\t\t\t\t\t...commonProps.filter,\n\t\t\t\t\t\t\t\t\telements,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<InputWidget { ...commonProps } fields={ fields } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Stack>\n\t\t\t\t);\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,wBAKO;AACP,kBAA4B;AAC5B,qBAAgC;AAChC,mBAA2B;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdown,\n\tFlexItem,\n\tSelectControl,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useRef } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\nimport { Stack, Tooltip } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport SearchWidget from './search-widget';\nimport InputWidget from './input-widget';\nimport { getOperatorByName } from '../../utils/operators';\nimport type {\n\tFilter,\n\tNormalizedField,\n\tNormalizedFilter,\n\tOperator,\n\tOption,\n\tView,\n} from '../../types';\nimport useElements from '../../hooks/use-elements';\n\nconst ENTER = 'Enter';\nconst SPACE = ' ';\n\ninterface FilterTextProps {\n\tactiveElements: Option[];\n\tfilterInView?: Filter;\n\tfilter: NormalizedFilter;\n}\n\ninterface OperatorSelectorProps {\n\tfilter: NormalizedFilter;\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n}\n\ninterface FilterProps extends OperatorSelectorProps {\n\taddFilterRef: RefObject< HTMLButtonElement | null >;\n\topenedFilter: string | null;\n\tfields: NormalizedField< any >[];\n}\n\nconst FilterText = ( {\n\tactiveElements,\n\tfilterInView,\n\tfilter,\n}: FilterTextProps ) => {\n\tif ( activeElements === undefined || activeElements.length === 0 ) {\n\t\treturn filter.name;\n\t}\n\n\tconst operator = getOperatorByName( filterInView?.operator );\n\tif ( operator !== undefined ) {\n\t\treturn operator.filterText( filter, activeElements );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: 1: Filter name e.g.: \"Unknown status for Author\". */\n\t\t__( 'Unknown status for %1$s' ),\n\t\tfilter.name\n\t);\n};\n\nfunction OperatorSelector( {\n\tfilter,\n\tview,\n\tonChangeView,\n}: OperatorSelectorProps ) {\n\tconst operatorOptions = filter.operators?.map( ( operator ) => ( {\n\t\tvalue: operator,\n\t\tlabel: getOperatorByName( operator )?.label || operator,\n\t} ) );\n\tconst currentFilter = view.filters?.find(\n\t\t( _filter ) => _filter.field === filter.field\n\t);\n\tconst value = currentFilter?.operator || filter.operators[ 0 ];\n\treturn (\n\t\toperatorOptions.length > 1 && (\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tgap=\"sm\"\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-filters__summary-operators-container\"\n\t\t\t\talign=\"center\"\n\t\t\t>\n\t\t\t\t<FlexItem className=\"dataviews-filters__summary-operators-filter-name\">\n\t\t\t\t\t{ filter.name }\n\t\t\t\t</FlexItem>\n\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-filters__summary-operators-filter-select\"\n\t\t\t\t\tlabel={ __( 'Conditions' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\toptions={ operatorOptions }\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tconst newOperator = newValue as Operator;\n\t\t\t\t\t\tconst currentOperator = currentFilter?.operator;\n\t\t\t\t\t\tconst newFilters = currentFilter\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ).map(\n\t\t\t\t\t\t\t\t\t\t( _filter ) => {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst currentOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\t\t\t\t\t\t\t\t\t\t\t\tconst newOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\n\t\t\t\t\t\t\t\t\t\t\t\tconst shouldResetValue =\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel !==\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t].includes( 'custom' );\n\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: shouldResetValue\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: _filter.value,\n\t\t\t\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn _filter;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ];\n\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\tfilters: newFilters,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tvariant=\"minimal\"\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</Stack>\n\t\t)\n\t);\n}\n\nexport default function Filter( {\n\taddFilterRef,\n\topenedFilter,\n\tfields,\n\t...commonProps\n}: FilterProps ) {\n\tconst toggleRef = useRef< HTMLDivElement >( null );\n\tconst { filter, view, onChangeView } = commonProps;\n\tconst filterInView = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\n\tlet activeElements: Option[] = [];\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Configure getValue as if Item was a plain object.\n\t\t\t\t// See related input-widget.tsx\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t};\n\t\t}\n\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst { elements } = useElements( {\n\t\telements: filter.elements,\n\t\tgetElements: filter.getElements,\n\t} );\n\n\tif ( elements.length > 0 ) {\n\t\t// When there are elements, we favor those\n\t\tactiveElements = elements.filter( ( element ) => {\n\t\t\tif ( filter.singleSelection ) {\n\t\t\t\treturn element.value === filterInView?.value;\n\t\t\t}\n\t\t\treturn filterInView?.value?.includes( element.value );\n\t\t} );\n\t} else if ( Array.isArray( filterInView?.value ) ) {\n\t\t// or, filterInView.value can also be array\n\t\t// for the between operator, as in [ 1, 2 ]\n\t\tconst label = filterInView.value.map( ( v ) => {\n\t\t\tconst formattedValue = field?.getValueFormatted( {\n\t\t\t\titem: { [ field.id ]: v },\n\t\t\t\tfield,\n\t\t\t} );\n\t\t\treturn formattedValue || String( v );\n\t\t} );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\t// @ts-ignore\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t} else if ( typeof filterInView?.value === 'object' ) {\n\t\t// or, it can also be object for the inThePast/over operators,\n\t\t// as in { value: '1', units: 'days' }\n\t\tactiveElements = [\n\t\t\t{ value: filterInView.value, label: filterInView.value },\n\t\t];\n\t} else if ( filterInView?.value !== undefined ) {\n\t\t// otherwise, filterInView.value is a single value\n\t\tconst label =\n\t\t\tfield !== undefined\n\t\t\t\t? field.getValueFormatted( {\n\t\t\t\t\t\titem: { [ field.id ]: filterInView.value },\n\t\t\t\t\t\tfield,\n\t\t\t\t } )\n\t\t\t\t: String( filterInView.value );\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t}\n\n\tconst isPrimary = filter.isPrimary;\n\tconst isLocked = filterInView?.isLocked;\n\tconst hasValues = ! isLocked && filterInView?.value !== undefined;\n\tconst canResetOrRemove = ! isLocked && ( ! isPrimary || hasValues );\n\t// TODO: revisit once `@wordpress/ui`'s `IconButton` is ready — it should\n\t// collapse the manual icon-only `<button>` + `aria-label` + Tooltip\n\t// composition below into a single primitive.\n\tconst resetOrRemoveLabel = isPrimary ? __( 'Reset' ) : __( 'Remove' );\n\treturn (\n\t\t<Dropdown\n\t\t\tdefaultOpen={ openedFilter === filter.field }\n\t\t\tcontentClassName=\"dataviews-filters__summary-popover\"\n\t\t\tpopoverProps={ { placement: 'bottom-start', role: 'dialog' } }\n\t\t\tonClose={ () => {\n\t\t\t\ttoggleRef.current?.focus();\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<div className=\"dataviews-filters__summary-chip-container\">\n\t\t\t\t\t<Tooltip.Root>\n\t\t\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip',\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t'has-reset': canResetOrRemove,\n\t\t\t\t\t\t\t\t\t\t\t'has-values': hasValues,\n\t\t\t\t\t\t\t\t\t\t\t'is-not-clickable': isLocked,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\t\t\ttabIndex={ isLocked ? -1 : 0 }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tif ( ! isLocked ) {\n\t\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t! isLocked &&\n\t\t\t\t\t\t\t\t\t\t\t[ ENTER, SPACE ].includes(\n\t\t\t\t\t\t\t\t\t\t\t\tevent.key\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taria-disabled={ isLocked }\n\t\t\t\t\t\t\t\t\taria-pressed={ isOpen }\n\t\t\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\t\t\tref={ toggleRef }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<FilterText\n\t\t\t\t\t\t\t\t\t\tactiveElements={ activeElements }\n\t\t\t\t\t\t\t\t\t\tfilterInView={ filterInView }\n\t\t\t\t\t\t\t\t\t\tfilter={ filter }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t/* translators: 1: Filter name. */\n\t\t\t\t\t\t\t\t__( 'Filter by: %1$s' ),\n\t\t\t\t\t\t\t\tfilter.name.toLowerCase()\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Tooltip.Popup>\n\t\t\t\t\t</Tooltip.Root>\n\t\t\t\t\t{ canResetOrRemove && (\n\t\t\t\t\t\t<Tooltip.Root>\n\t\t\t\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip-remove',\n\t\t\t\t\t\t\t\t\t\t\t{ 'has-values': hasValues }\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\taria-label={ resetOrRemoveLabel }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\t\t\tfilters: view.filters?.filter(\n\t\t\t\t\t\t\t\t\t\t\t\t\t( _filter ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t_filter.field !==\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilter.field\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\t\t// If the filter is not primary and can be removed, it will be added\n\t\t\t\t\t\t\t\t\t\t\t// back to the available filters from `Add filter` component.\n\t\t\t\t\t\t\t\t\t\t\tif ( ! isPrimary ) {\n\t\t\t\t\t\t\t\t\t\t\t\taddFilterRef.current?.focus();\n\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\t// If is primary, focus the toggle button.\n\t\t\t\t\t\t\t\t\t\t\t\ttoggleRef.current?.focus();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<WCIcon icon={ closeSmall } />\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t\t\t\t{ resetOrRemoveLabel }\n\t\t\t\t\t\t\t</Tooltip.Popup>\n\t\t\t\t\t\t</Tooltip.Root>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\trenderContent={ () => {\n\t\t\t\treturn (\n\t\t\t\t\t<Stack direction=\"column\" justify=\"flex-start\">\n\t\t\t\t\t\t<OperatorSelector { ...commonProps } />\n\t\t\t\t\t\t{ commonProps.filter.hasElements ? (\n\t\t\t\t\t\t\t<SearchWidget\n\t\t\t\t\t\t\t\t{ ...commonProps }\n\t\t\t\t\t\t\t\tfilter={ {\n\t\t\t\t\t\t\t\t\t...commonProps.filter,\n\t\t\t\t\t\t\t\t\telements,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<InputWidget { ...commonProps } fields={ fields } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Stack>\n\t\t\t\t);\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,wBAKO;AACP,kBAA4B;AAC5B,qBAAgC;AAChC,mBAA2B;AAC3B,gBAA+B;AAK/B,2BAAyB;AACzB,0BAAwB;AACxB,uBAAkC;AASlC,0BAAwB;AA2DrB;AAzDH,IAAM,QAAQ;AACd,IAAM,QAAQ;AAoBd,IAAM,aAAa,CAAE;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACD,MAAwB;AACvB,MAAK,mBAAmB,UAAa,eAAe,WAAW,GAAI;AAClE,WAAO,OAAO;AAAA,EACf;AAEA,QAAM,eAAW,oCAAmB,cAAc,QAAS;AAC3D,MAAK,aAAa,QAAY;AAC7B,WAAO,SAAS,WAAY,QAAQ,cAAe;AAAA,EACpD;AAEA,aAAO;AAAA;AAAA,QAEN,gBAAI,yBAA0B;AAAA,IAC9B,OAAO;AAAA,EACR;AACD;AAEA,SAAS,iBAAkB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AACD,GAA2B;AAC1B,QAAM,kBAAkB,OAAO,WAAW,IAAK,CAAE,cAAgB;AAAA,IAChE,OAAO;AAAA,IACP,WAAO,oCAAmB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A,cAC7B;AAAA;AAAA,UAEF;AAAA,UACA,4CAAC,kBAAQ,OAAR,EACE,8BACH;AAAA,WACD;AAAA,SAEF;AAAA,MAED,eAAgB,MAAM;AACrB,eACC,6CAAC,mBAAM,WAAU,UAAS,SAAQ,cACjC;AAAA,sDAAC,oBAAmB,GAAG,aAAc;AAAA,UACnC,YAAY,OAAO,cACpB;AAAA,YAAC,qBAAAC;AAAA,YAAA;AAAA,cACE,GAAG;AAAA,cACL,QAAS;AAAA,gBACR,GAAG,YAAY;AAAA,gBACf;AAAA,cACD;AAAA;AAAA,UACD,IAEA,4CAAC,oBAAAC,SAAA,EAAc,GAAG,aAAc,QAAkB;AAAA,WAEpD;AAAA,MAEF;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["useElements", "clsx", "WCIcon", "SearchWidget", "InputWidget"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataviews-layouts/grid/composite-grid.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ComponentProps, ReactElement, HTMLAttributes } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tFlex,\n\tFlexItem,\n\tComposite,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\n// eslint-disable-next-line @wordpress/use-recommended-components -- `Tooltip` is not yet on the recommended `@wordpress/ui` allow-list; landing as a migration step ahead of the wider rollout.\nimport { Stack, Tooltip } from '@wordpress/ui';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useInstanceId } from '@wordpress/compose';\nimport { isAppleOS } from '@wordpress/keycodes';\nimport {\n\tuseCallback,\n\tuseContext,\n\tuseRef,\n\tforwardRef,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport ItemActions from '../../dataviews-item-actions';\nimport DataViewsSelectionCheckbox from '../../dataviews-selection-checkbox';\nimport DataViewsContext from '../../dataviews-context';\nimport {\n\tuseHasAPossibleBulkAction,\n\tuseSomeItemHasAPossibleBulkAction,\n} from '../../dataviews-bulk-actions';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewGrid as ViewGridType,\n} from '../../../types';\nimport type { SetSelection } from '../../../types/private';\nimport { ItemClickWrapper } from '../utils/item-click-wrapper';\nconst { Badge: WCBadge } = unlock( componentsPrivateApis );\nimport { useGridColumns } from './preview-size-picker';\nimport { GridItems } from '../utils/grid-items';\nimport {\n\tuseIntersectionObserver,\n\tusePlaceholdersNeeded,\n} from '../utils/use-infinite-scroll';\n\nfunction chunk< T >( array: T[], size: number ): T[][] {\n\tconst chunks: T[][] = [];\n\tfor ( let i = 0, j = array.length; i < j; i += size ) {\n\t\tchunks.push( array.slice( i, i + size ) );\n\t}\n\treturn chunks;\n}\n\ninterface GridItemProps< Item > extends HTMLAttributes< HTMLDivElement > {\n\tview: ViewGridType;\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tgetItemId: ( item: Item ) => string;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\titem: Item;\n\tactions: Action< Item >[];\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tregularFields: NormalizedField< Item >[];\n\tbadgeFields: NormalizedField< Item >[];\n\thasBulkActions: boolean;\n\tconfig: {\n\t\tsizes: string;\n\t};\n\tposinset?: number;\n\tsetsize?: number;\n}\n\nconst GridItem = forwardRef< HTMLDivElement, GridItemProps< any > >(\n\tfunction GridItem(\n\t\t{\n\t\t\tview,\n\t\t\tselection,\n\t\t\tonChangeSelection,\n\t\t\tonClickItem,\n\t\t\tisItemClickable,\n\t\t\trenderItemLink,\n\t\t\tgetItemId,\n\t\t\titem,\n\t\t\tactions,\n\t\t\tmediaField,\n\t\t\ttitleField,\n\t\t\tdescriptionField,\n\t\t\tregularFields,\n\t\t\tbadgeFields,\n\t\t\thasBulkActions,\n\t\t\tconfig,\n\t\t\tposinset,\n\t\t\tsetsize,\n\t\t\t...props\n\t\t},\n\t\tforwardedRef\n\t) {\n\t\tconst {\n\t\t\tshowTitle = true,\n\t\t\tshowMedia = true,\n\t\t\tshowDescription = true,\n\t\t} = view;\n\t\tconst hasBulkAction = useHasAPossibleBulkAction( actions, item );\n\t\tconst id = getItemId( item );\n\t\tconst elementRef = useRef< HTMLDivElement | null >( null );\n\n\t\t// Merge refs callback\n\t\tconst setRefs = useCallback(\n\t\t\t( node: HTMLDivElement | null ) => {\n\t\t\t\telementRef.current = node;\n\t\t\t\tif ( typeof forwardedRef === 'function' ) {\n\t\t\t\t\tforwardedRef( node );\n\t\t\t\t} else if ( forwardedRef ) {\n\t\t\t\t\tforwardedRef.current = node;\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ forwardedRef ]\n\t\t);\n\t\tuseIntersectionObserver( elementRef, posinset );\n\t\tconst instanceId = useInstanceId( GridItem );\n\n\t\tconst isSelected = selection.includes( id );\n\n\t\tconst mediaPlaceholder = (\n\t\t\t<span className=\"dataviews-view-grid__media-placeholder\" />\n\t\t);\n\t\tconst rendersMediaField = showMedia && mediaField?.render;\n\t\tconst renderedMediaField = rendersMediaField ? (\n\t\t\t<mediaField.render\n\t\t\t\titem={ item }\n\t\t\t\tfield={ mediaField }\n\t\t\t\tconfig={ config }\n\t\t\t/>\n\t\t) : (\n\t\t\tmediaPlaceholder\n\t\t);\n\t\tconst renderedTitleField =\n\t\t\tshowTitle && titleField?.render ? (\n\t\t\t\t<titleField.render item={ item } field={ titleField } />\n\t\t\t) : null;\n\t\tlet mediaA11yProps;\n\t\tlet titleA11yProps;\n\t\tif ( isItemClickable( item ) && onClickItem ) {\n\t\t\tif ( renderedTitleField ) {\n\t\t\t\tmediaA11yProps = {\n\t\t\t\t\t'aria-labelledby': `dataviews-view-grid__title-field-${ instanceId }`,\n\t\t\t\t};\n\t\t\t\ttitleA11yProps = {\n\t\t\t\t\tid: `dataviews-view-grid__title-field-${ instanceId }`,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tmediaA11yProps = {\n\t\t\t\t\t'aria-label': __( 'Navigate to item' ),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tdirection=\"column\"\n\t\t\t\t{ ...props }\n\t\t\t\tref={ setRefs }\n\t\t\t\taria-setsize={ setsize }\n\t\t\t\taria-posinset={ posinset }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'dataviews-view-grid__row__gridcell',\n\t\t\t\t\t'dataviews-view-grid__card',\n\t\t\t\t\t{\n\t\t\t\t\t\t'is-selected': hasBulkAction && isSelected,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\tonClickCapture={ ( event ) => {\n\t\t\t\t\tprops.onClickCapture?.( event );\n\t\t\t\t\tif ( isAppleOS() ? event.metaKey : event.ctrlKey ) {\n\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tif ( ! hasBulkAction ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\tisSelected\n\t\t\t\t\t\t\t\t? selection.filter(\n\t\t\t\t\t\t\t\t\t\t( itemId ) => id !== itemId\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: [ ...selection, id ]\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<ItemClickWrapper\n\t\t\t\t\titem={ item }\n\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-grid__media', {\n\t\t\t\t\t\t'dataviews-view-grid__media--placeholder':\n\t\t\t\t\t\t\t! rendersMediaField,\n\t\t\t\t\t} ) }\n\t\t\t\t\t{ ...mediaA11yProps }\n\t\t\t\t>\n\t\t\t\t\t{ renderedMediaField }\n\t\t\t\t</ItemClickWrapper>\n\t\t\t\t{ hasBulkActions && (\n\t\t\t\t\t<DataViewsSelectionCheckbox\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\tdisabled={ ! hasBulkAction }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ !! actions?.length && (\n\t\t\t\t\t<div className=\"dataviews-view-grid__media-actions\">\n\t\t\t\t\t\t<ItemActions\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\tisCompact\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ showTitle && (\n\t\t\t\t\t<div className=\"dataviews-view-grid__title-actions\">\n\t\t\t\t\t\t<ItemClickWrapper\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__title-field dataviews-title-field\"\n\t\t\t\t\t\t\t{ ...titleA11yProps }\n\t\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\t\ttitleField?.getValueFormatted( {\n\t\t\t\t\t\t\t\t\titem,\n\t\t\t\t\t\t\t\t\tfield: titleField,\n\t\t\t\t\t\t\t\t} ) || undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ renderedTitleField }\n\t\t\t\t\t\t</ItemClickWrapper>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<Stack direction=\"column\" gap=\"xs\">\n\t\t\t\t\t{ showDescription && descriptionField?.render && (\n\t\t\t\t\t\t<descriptionField.render\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tfield={ descriptionField }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ !! badgeFields?.length && (\n\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__badge-fields\"\n\t\t\t\t\t\t\tgap=\"sm\"\n\t\t\t\t\t\t\twrap=\"wrap\"\n\t\t\t\t\t\t\talign=\"top\"\n\t\t\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ badgeFields.map( ( field ) => {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<WCBadge\n\t\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field-value\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</WCBadge>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t) }\n\t\t\t\t\t{ !! regularFields?.length && (\n\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__fields\"\n\t\t\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ regularFields.map( ( field ) => {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field\"\n\t\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\t\tgap={ 1 }\n\t\t\t\t\t\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\t\t\t\t\t\texpanded\n\t\t\t\t\t\t\t\t\t\tstyle={ { height: 'auto' } }\n\t\t\t\t\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t\t<Tooltip.Root>\n\t\t\t\t\t\t\t\t\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<FlexItem className=\"dataviews-view-grid__field-name\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ field.header }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t\t\t\t\t\t\t\t</Tooltip.Popup>\n\t\t\t\t\t\t\t\t\t\t\t</Tooltip.Root>\n\t\t\t\t\t\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field-value\"\n\t\t\t\t\t\t\t\t\t\t\t\tstyle={ { maxHeight: 'none' } }\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t\t</Flex>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t);\n\t}\n) as < Item >(\n\tprops: GridItemProps< Item > & {\n\t\tref?: React.ForwardedRef< HTMLDivElement >;\n\t}\n) => React.ReactNode;\ninterface CompositeGridProps< Item > {\n\tdata: Item[];\n\tisInfiniteScroll: boolean;\n\tclassName?: string;\n\tinert?: string;\n\tisLoading?: boolean;\n\tview: ViewGridType;\n\tfields: NormalizedField< Item >[];\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tonClickItem?: ( item: Item ) => void;\n\tisItemClickable: ( item: Item ) => boolean;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tgetItemId: ( item: Item ) => string;\n\tactions: Action< Item >[];\n}\n\nexport default function CompositeGrid< Item >( {\n\tdata,\n\tisInfiniteScroll,\n\tclassName,\n\tinert,\n\tisLoading,\n\tview,\n\tfields,\n\tselection,\n\tonChangeSelection,\n\tonClickItem,\n\tisItemClickable,\n\trenderItemLink,\n\tgetItemId,\n\tactions,\n}: CompositeGridProps< Item > ) {\n\tconst { paginationInfo, resizeObserverRef } =\n\t\tuseContext( DataViewsContext );\n\tconst gridColumns = useGridColumns();\n\tconst hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data );\n\tconst titleField = fields.find(\n\t\t( field ) => field.id === view?.titleField\n\t);\n\tconst mediaField = fields.find(\n\t\t( field ) => field.id === view?.mediaField\n\t);\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view?.descriptionField\n\t);\n\tconst otherFields = view.fields ?? [];\n\tconst { regularFields, badgeFields } = otherFields.reduce(\n\t\t(\n\t\t\taccumulator: Record< string, NormalizedField< Item >[] >,\n\t\t\tfieldId\n\t\t) => {\n\t\t\tconst field = fields.find( ( f ) => f.id === fieldId );\n\t\t\tif ( ! field ) {\n\t\t\t\treturn accumulator;\n\t\t\t}\n\t\t\t// If the field is a badge field, add it to the badgeFields array\n\t\t\t// otherwise add it to the rest visibleFields array.\n\t\t\tconst key = view.layout?.badgeFields?.includes( fieldId )\n\t\t\t\t? 'badgeFields'\n\t\t\t\t: 'regularFields';\n\t\t\taccumulator[ key ].push( field );\n\t\t\treturn accumulator;\n\t\t},\n\t\t{ regularFields: [], badgeFields: [] }\n\t);\n\n\t/*\n\t * This is the maximum width that an image can achieve in the grid. The reasoning is:\n\t * The biggest min image width available is 430px (see /dataviews-layouts/grid/preview-size-picker.tsx).\n\t * Because the grid is responsive, once there is room for another column, the images shrink to accommodate it.\n\t * So each image will never grow past 2*430px plus a little more to account for the gaps.\n\t */\n\tconst size = '900px';\n\tconst totalRows = Math.ceil( data.length / gridColumns );\n\n\t// Calculate placeholders needed for infinite scroll\n\tconst placeholdersNeeded = usePlaceholdersNeeded(\n\t\tdata,\n\t\tisInfiniteScroll,\n\t\tgridColumns\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{\n\t\t\t\t// Render infinite scroll layout (no rows, feed semantics)\n\t\t\t\tisInfiniteScroll && (\n\t\t\t\t\t<Composite\n\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t<GridItems\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-view-grid-infinite-scroll',\n\t\t\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t'compact',\n\t\t\t\t\t\t\t\t\t\t\t\t'comfortable',\n\t\t\t\t\t\t\t\t\t\t\t].includes( view.layout.density ),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tpreviewSize={ view.layout?.previewSize }\n\t\t\t\t\t\t\t\taria-busy={ isLoading }\n\t\t\t\t\t\t\t\tref={ resizeObserverRef }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\trole=\"feed\"\n\t\t\t\t\t\tfocusWrap\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tinert={ inert }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ /* Render placeholders for unloaded items in first row */ }\n\t\t\t\t\t\t{ Array.from( { length: placeholdersNeeded } ).map(\n\t\t\t\t\t\t\t( _, index ) => (\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tkey={ `placeholder-${ index }` }\n\t\t\t\t\t\t\t\t\trender={ ( props ) => (\n\t\t\t\t\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\t\t\t\trole=\"article\"\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__row__gridcell dataviews-view-grid__card dataviews-view-grid__placeholder\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ data.map( ( item ) => {\n\t\t\t\t\t\t\tconst itemId = getItemId( item );\n\t\t\t\t\t\t\t// Use position from item for infinite scroll\n\t\t\t\t\t\t\tconst stablePosition = ( item as any ).position;\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tkey={ itemId }\n\t\t\t\t\t\t\t\t\trender={ ( props ) => (\n\t\t\t\t\t\t\t\t\t\t<GridItem\n\t\t\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\t\t\tid={ itemId }\n\t\t\t\t\t\t\t\t\t\t\trole=\"article\"\n\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\t\tonChangeSelection={\n\t\t\t\t\t\t\t\t\t\t\t\tonChangeSelection\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tregularFields={ regularFields }\n\t\t\t\t\t\t\t\t\t\t\tbadgeFields={ badgeFields }\n\t\t\t\t\t\t\t\t\t\t\thasBulkActions={ hasBulkActions }\n\t\t\t\t\t\t\t\t\t\t\tposinset={ stablePosition }\n\t\t\t\t\t\t\t\t\t\t\tsetsize={\n\t\t\t\t\t\t\t\t\t\t\t\tpaginationInfo.totalItems\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tconfig={ {\n\t\t\t\t\t\t\t\t\t\t\t\tsizes: size,\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</Composite>\n\t\t\t\t)\n\t\t\t}\n\t\t\t{\n\t\t\t\t// Render standard grid layout (with rows, grid semantics)\n\t\t\t\t! isInfiniteScroll && (\n\t\t\t\t\t<Composite\n\t\t\t\t\t\trole=\"grid\"\n\t\t\t\t\t\tclassName={ clsx( 'dataviews-view-grid', className, {\n\t\t\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t\tfocusWrap\n\t\t\t\t\t\taria-busy={ isLoading }\n\t\t\t\t\t\taria-rowcount={ totalRows }\n\t\t\t\t\t\tref={ resizeObserverRef }\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tinert={ inert }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ chunk( data, gridColumns ).map( ( row, i ) => (\n\t\t\t\t\t\t\t<Composite.Row\n\t\t\t\t\t\t\t\tkey={ i }\n\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\trole=\"row\"\n\t\t\t\t\t\t\t\t\t\taria-rowindex={ i + 1 }\n\t\t\t\t\t\t\t\t\t\taria-label={ sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %d: The row number in the grid */\n\t\t\t\t\t\t\t\t\t\t\t__( 'Row %d' ),\n\t\t\t\t\t\t\t\t\t\t\ti + 1\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__row\"\n\t\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\t\tgridTemplateColumns: `repeat( ${ gridColumns }, minmax(0, 1fr) )`,\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ row.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst itemId = getItemId( item );\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\t\t\tkey={ itemId }\n\t\t\t\t\t\t\t\t\t\t\trender={ ( props ) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<GridItem\n\t\t\t\t\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\t\t\t\t\tid={ itemId }\n\t\t\t\t\t\t\t\t\t\t\t\t\trole=\"gridcell\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeSelection={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeSelection\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\t\t\t\t\tisItemClickable={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tisItemClickable\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\trenderItemLink={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trenderItemLink\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tregularFields={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tregularFields\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tbadgeFields={ badgeFields }\n\t\t\t\t\t\t\t\t\t\t\t\t\thasBulkActions={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\thasBulkActions\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tconfig={ {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsizes: size,\n\t\t\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</Composite.Row>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Composite>\n\t\t\t\t)\n\t\t\t}\n\t\t</>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,wBAKO;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ComponentProps, ReactElement, HTMLAttributes } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tFlex,\n\tFlexItem,\n\tComposite,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { Stack, Tooltip } from '@wordpress/ui';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useInstanceId } from '@wordpress/compose';\nimport { isAppleOS } from '@wordpress/keycodes';\nimport {\n\tuseCallback,\n\tuseContext,\n\tuseRef,\n\tforwardRef,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport ItemActions from '../../dataviews-item-actions';\nimport DataViewsSelectionCheckbox from '../../dataviews-selection-checkbox';\nimport DataViewsContext from '../../dataviews-context';\nimport {\n\tuseHasAPossibleBulkAction,\n\tuseSomeItemHasAPossibleBulkAction,\n} from '../../dataviews-bulk-actions';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewGrid as ViewGridType,\n} from '../../../types';\nimport type { SetSelection } from '../../../types/private';\nimport { ItemClickWrapper } from '../utils/item-click-wrapper';\nconst { Badge: WCBadge } = unlock( componentsPrivateApis );\nimport { useGridColumns } from './preview-size-picker';\nimport { GridItems } from '../utils/grid-items';\nimport {\n\tuseIntersectionObserver,\n\tusePlaceholdersNeeded,\n} from '../utils/use-infinite-scroll';\n\nfunction chunk< T >( array: T[], size: number ): T[][] {\n\tconst chunks: T[][] = [];\n\tfor ( let i = 0, j = array.length; i < j; i += size ) {\n\t\tchunks.push( array.slice( i, i + size ) );\n\t}\n\treturn chunks;\n}\n\ninterface GridItemProps< Item > extends HTMLAttributes< HTMLDivElement > {\n\tview: ViewGridType;\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tgetItemId: ( item: Item ) => string;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\titem: Item;\n\tactions: Action< Item >[];\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tregularFields: NormalizedField< Item >[];\n\tbadgeFields: NormalizedField< Item >[];\n\thasBulkActions: boolean;\n\tconfig: {\n\t\tsizes: string;\n\t};\n\tposinset?: number;\n\tsetsize?: number;\n}\n\nconst GridItem = forwardRef< HTMLDivElement, GridItemProps< any > >(\n\tfunction GridItem(\n\t\t{\n\t\t\tview,\n\t\t\tselection,\n\t\t\tonChangeSelection,\n\t\t\tonClickItem,\n\t\t\tisItemClickable,\n\t\t\trenderItemLink,\n\t\t\tgetItemId,\n\t\t\titem,\n\t\t\tactions,\n\t\t\tmediaField,\n\t\t\ttitleField,\n\t\t\tdescriptionField,\n\t\t\tregularFields,\n\t\t\tbadgeFields,\n\t\t\thasBulkActions,\n\t\t\tconfig,\n\t\t\tposinset,\n\t\t\tsetsize,\n\t\t\t...props\n\t\t},\n\t\tforwardedRef\n\t) {\n\t\tconst {\n\t\t\tshowTitle = true,\n\t\t\tshowMedia = true,\n\t\t\tshowDescription = true,\n\t\t} = view;\n\t\tconst hasBulkAction = useHasAPossibleBulkAction( actions, item );\n\t\tconst id = getItemId( item );\n\t\tconst elementRef = useRef< HTMLDivElement | null >( null );\n\n\t\t// Merge refs callback\n\t\tconst setRefs = useCallback(\n\t\t\t( node: HTMLDivElement | null ) => {\n\t\t\t\telementRef.current = node;\n\t\t\t\tif ( typeof forwardedRef === 'function' ) {\n\t\t\t\t\tforwardedRef( node );\n\t\t\t\t} else if ( forwardedRef ) {\n\t\t\t\t\tforwardedRef.current = node;\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ forwardedRef ]\n\t\t);\n\t\tuseIntersectionObserver( elementRef, posinset );\n\t\tconst instanceId = useInstanceId( GridItem );\n\n\t\tconst isSelected = selection.includes( id );\n\n\t\tconst mediaPlaceholder = (\n\t\t\t<span className=\"dataviews-view-grid__media-placeholder\" />\n\t\t);\n\t\tconst rendersMediaField = showMedia && mediaField?.render;\n\t\tconst renderedMediaField = rendersMediaField ? (\n\t\t\t<mediaField.render\n\t\t\t\titem={ item }\n\t\t\t\tfield={ mediaField }\n\t\t\t\tconfig={ config }\n\t\t\t/>\n\t\t) : (\n\t\t\tmediaPlaceholder\n\t\t);\n\t\tconst renderedTitleField =\n\t\t\tshowTitle && titleField?.render ? (\n\t\t\t\t<titleField.render item={ item } field={ titleField } />\n\t\t\t) : null;\n\t\tlet mediaA11yProps;\n\t\tlet titleA11yProps;\n\t\tif ( isItemClickable( item ) && onClickItem ) {\n\t\t\tif ( renderedTitleField ) {\n\t\t\t\tmediaA11yProps = {\n\t\t\t\t\t'aria-labelledby': `dataviews-view-grid__title-field-${ instanceId }`,\n\t\t\t\t};\n\t\t\t\ttitleA11yProps = {\n\t\t\t\t\tid: `dataviews-view-grid__title-field-${ instanceId }`,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tmediaA11yProps = {\n\t\t\t\t\t'aria-label': __( 'Navigate to item' ),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tdirection=\"column\"\n\t\t\t\t{ ...props }\n\t\t\t\tref={ setRefs }\n\t\t\t\taria-setsize={ setsize }\n\t\t\t\taria-posinset={ posinset }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'dataviews-view-grid__row__gridcell',\n\t\t\t\t\t'dataviews-view-grid__card',\n\t\t\t\t\t{\n\t\t\t\t\t\t'is-selected': hasBulkAction && isSelected,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\tonClickCapture={ ( event ) => {\n\t\t\t\t\tprops.onClickCapture?.( event );\n\t\t\t\t\tif ( isAppleOS() ? event.metaKey : event.ctrlKey ) {\n\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tif ( ! hasBulkAction ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\tisSelected\n\t\t\t\t\t\t\t\t? selection.filter(\n\t\t\t\t\t\t\t\t\t\t( itemId ) => id !== itemId\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: [ ...selection, id ]\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<ItemClickWrapper\n\t\t\t\t\titem={ item }\n\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-grid__media', {\n\t\t\t\t\t\t'dataviews-view-grid__media--placeholder':\n\t\t\t\t\t\t\t! rendersMediaField,\n\t\t\t\t\t} ) }\n\t\t\t\t\t{ ...mediaA11yProps }\n\t\t\t\t>\n\t\t\t\t\t{ renderedMediaField }\n\t\t\t\t</ItemClickWrapper>\n\t\t\t\t{ hasBulkActions && (\n\t\t\t\t\t<DataViewsSelectionCheckbox\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\tdisabled={ ! hasBulkAction }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ !! actions?.length && (\n\t\t\t\t\t<div className=\"dataviews-view-grid__media-actions\">\n\t\t\t\t\t\t<ItemActions\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\tisCompact\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ showTitle && (\n\t\t\t\t\t<div className=\"dataviews-view-grid__title-actions\">\n\t\t\t\t\t\t<ItemClickWrapper\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__title-field dataviews-title-field\"\n\t\t\t\t\t\t\t{ ...titleA11yProps }\n\t\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\t\ttitleField?.getValueFormatted( {\n\t\t\t\t\t\t\t\t\titem,\n\t\t\t\t\t\t\t\t\tfield: titleField,\n\t\t\t\t\t\t\t\t} ) || undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ renderedTitleField }\n\t\t\t\t\t\t</ItemClickWrapper>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t<Stack direction=\"column\" gap=\"xs\">\n\t\t\t\t\t{ showDescription && descriptionField?.render && (\n\t\t\t\t\t\t<descriptionField.render\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tfield={ descriptionField }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ !! badgeFields?.length && (\n\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__badge-fields\"\n\t\t\t\t\t\t\tgap=\"sm\"\n\t\t\t\t\t\t\twrap=\"wrap\"\n\t\t\t\t\t\t\talign=\"top\"\n\t\t\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ badgeFields.map( ( field ) => {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<WCBadge\n\t\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field-value\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</WCBadge>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t) }\n\t\t\t\t\t{ !! regularFields?.length && (\n\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__fields\"\n\t\t\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ regularFields.map( ( field ) => {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field\"\n\t\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\t\tgap={ 1 }\n\t\t\t\t\t\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\t\t\t\t\t\texpanded\n\t\t\t\t\t\t\t\t\t\tstyle={ { height: 'auto' } }\n\t\t\t\t\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t\t<Tooltip.Root>\n\t\t\t\t\t\t\t\t\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<FlexItem className=\"dataviews-view-grid__field-name\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ field.header }\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t\t\t\t\t\t\t\t</Tooltip.Popup>\n\t\t\t\t\t\t\t\t\t\t\t</Tooltip.Root>\n\t\t\t\t\t\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__field-value\"\n\t\t\t\t\t\t\t\t\t\t\t\tstyle={ { maxHeight: 'none' } }\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t\t</Flex>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t);\n\t}\n) as < Item >(\n\tprops: GridItemProps< Item > & {\n\t\tref?: React.ForwardedRef< HTMLDivElement >;\n\t}\n) => React.ReactNode;\ninterface CompositeGridProps< Item > {\n\tdata: Item[];\n\tisInfiniteScroll: boolean;\n\tclassName?: string;\n\tinert?: string;\n\tisLoading?: boolean;\n\tview: ViewGridType;\n\tfields: NormalizedField< Item >[];\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\tonClickItem?: ( item: Item ) => void;\n\tisItemClickable: ( item: Item ) => boolean;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tgetItemId: ( item: Item ) => string;\n\tactions: Action< Item >[];\n}\n\nexport default function CompositeGrid< Item >( {\n\tdata,\n\tisInfiniteScroll,\n\tclassName,\n\tinert,\n\tisLoading,\n\tview,\n\tfields,\n\tselection,\n\tonChangeSelection,\n\tonClickItem,\n\tisItemClickable,\n\trenderItemLink,\n\tgetItemId,\n\tactions,\n}: CompositeGridProps< Item > ) {\n\tconst { paginationInfo, resizeObserverRef } =\n\t\tuseContext( DataViewsContext );\n\tconst gridColumns = useGridColumns();\n\tconst hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data );\n\tconst titleField = fields.find(\n\t\t( field ) => field.id === view?.titleField\n\t);\n\tconst mediaField = fields.find(\n\t\t( field ) => field.id === view?.mediaField\n\t);\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view?.descriptionField\n\t);\n\tconst otherFields = view.fields ?? [];\n\tconst { regularFields, badgeFields } = otherFields.reduce(\n\t\t(\n\t\t\taccumulator: Record< string, NormalizedField< Item >[] >,\n\t\t\tfieldId\n\t\t) => {\n\t\t\tconst field = fields.find( ( f ) => f.id === fieldId );\n\t\t\tif ( ! field ) {\n\t\t\t\treturn accumulator;\n\t\t\t}\n\t\t\t// If the field is a badge field, add it to the badgeFields array\n\t\t\t// otherwise add it to the rest visibleFields array.\n\t\t\tconst key = view.layout?.badgeFields?.includes( fieldId )\n\t\t\t\t? 'badgeFields'\n\t\t\t\t: 'regularFields';\n\t\t\taccumulator[ key ].push( field );\n\t\t\treturn accumulator;\n\t\t},\n\t\t{ regularFields: [], badgeFields: [] }\n\t);\n\n\t/*\n\t * This is the maximum width that an image can achieve in the grid. The reasoning is:\n\t * The biggest min image width available is 430px (see /dataviews-layouts/grid/preview-size-picker.tsx).\n\t * Because the grid is responsive, once there is room for another column, the images shrink to accommodate it.\n\t * So each image will never grow past 2*430px plus a little more to account for the gaps.\n\t */\n\tconst size = '900px';\n\tconst totalRows = Math.ceil( data.length / gridColumns );\n\n\t// Calculate placeholders needed for infinite scroll\n\tconst placeholdersNeeded = usePlaceholdersNeeded(\n\t\tdata,\n\t\tisInfiniteScroll,\n\t\tgridColumns\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{\n\t\t\t\t// Render infinite scroll layout (no rows, feed semantics)\n\t\t\t\tisInfiniteScroll && (\n\t\t\t\t\t<Composite\n\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t<GridItems\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-view-grid-infinite-scroll',\n\t\t\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t'compact',\n\t\t\t\t\t\t\t\t\t\t\t\t'comfortable',\n\t\t\t\t\t\t\t\t\t\t\t].includes( view.layout.density ),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tpreviewSize={ view.layout?.previewSize }\n\t\t\t\t\t\t\t\taria-busy={ isLoading }\n\t\t\t\t\t\t\t\tref={ resizeObserverRef }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\trole=\"feed\"\n\t\t\t\t\t\tfocusWrap\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tinert={ inert }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ /* Render placeholders for unloaded items in first row */ }\n\t\t\t\t\t\t{ Array.from( { length: placeholdersNeeded } ).map(\n\t\t\t\t\t\t\t( _, index ) => (\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tkey={ `placeholder-${ index }` }\n\t\t\t\t\t\t\t\t\trender={ ( props ) => (\n\t\t\t\t\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\t\t\t\trole=\"article\"\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__row__gridcell dataviews-view-grid__card dataviews-view-grid__placeholder\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ data.map( ( item ) => {\n\t\t\t\t\t\t\tconst itemId = getItemId( item );\n\t\t\t\t\t\t\t// Use position from item for infinite scroll\n\t\t\t\t\t\t\tconst stablePosition = ( item as any ).position;\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tkey={ itemId }\n\t\t\t\t\t\t\t\t\trender={ ( props ) => (\n\t\t\t\t\t\t\t\t\t\t<GridItem\n\t\t\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\t\t\tid={ itemId }\n\t\t\t\t\t\t\t\t\t\t\trole=\"article\"\n\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\t\tonChangeSelection={\n\t\t\t\t\t\t\t\t\t\t\t\tonChangeSelection\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tregularFields={ regularFields }\n\t\t\t\t\t\t\t\t\t\t\tbadgeFields={ badgeFields }\n\t\t\t\t\t\t\t\t\t\t\thasBulkActions={ hasBulkActions }\n\t\t\t\t\t\t\t\t\t\t\tposinset={ stablePosition }\n\t\t\t\t\t\t\t\t\t\t\tsetsize={\n\t\t\t\t\t\t\t\t\t\t\t\tpaginationInfo.totalItems\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tconfig={ {\n\t\t\t\t\t\t\t\t\t\t\t\tsizes: size,\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</Composite>\n\t\t\t\t)\n\t\t\t}\n\t\t\t{\n\t\t\t\t// Render standard grid layout (with rows, grid semantics)\n\t\t\t\t! isInfiniteScroll && (\n\t\t\t\t\t<Composite\n\t\t\t\t\t\trole=\"grid\"\n\t\t\t\t\t\tclassName={ clsx( 'dataviews-view-grid', className, {\n\t\t\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t\tfocusWrap\n\t\t\t\t\t\taria-busy={ isLoading }\n\t\t\t\t\t\taria-rowcount={ totalRows }\n\t\t\t\t\t\tref={ resizeObserverRef }\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\tinert={ inert }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ chunk( data, gridColumns ).map( ( row, i ) => (\n\t\t\t\t\t\t\t<Composite.Row\n\t\t\t\t\t\t\t\tkey={ i }\n\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\trole=\"row\"\n\t\t\t\t\t\t\t\t\t\taria-rowindex={ i + 1 }\n\t\t\t\t\t\t\t\t\t\taria-label={ sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %d: The row number in the grid */\n\t\t\t\t\t\t\t\t\t\t\t__( 'Row %d' ),\n\t\t\t\t\t\t\t\t\t\t\ti + 1\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-grid__row\"\n\t\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\t\tgridTemplateColumns: `repeat( ${ gridColumns }, minmax(0, 1fr) )`,\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ row.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst itemId = getItemId( item );\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\t\t\tkey={ itemId }\n\t\t\t\t\t\t\t\t\t\t\trender={ ( props ) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<GridItem\n\t\t\t\t\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\t\t\t\t\tid={ itemId }\n\t\t\t\t\t\t\t\t\t\t\t\t\trole=\"gridcell\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeSelection={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeSelection\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\t\t\t\t\tisItemClickable={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tisItemClickable\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\trenderItemLink={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trenderItemLink\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tregularFields={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tregularFields\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tbadgeFields={ badgeFields }\n\t\t\t\t\t\t\t\t\t\t\t\t\thasBulkActions={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\thasBulkActions\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tconfig={ {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsizes: size,\n\t\t\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</Composite.Row>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Composite>\n\t\t\t\t)\n\t\t\t}\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,wBAKO;AACP,gBAA+B;AAC/B,kBAA4B;AAC5B,qBAA8B;AAC9B,sBAA0B;AAC1B,qBAKO;AAKP,yBAAuB;AACvB,oCAAwB;AACxB,0CAAuC;AACvC,+BAA6B;AAC7B,oCAGO;AAOP,gCAAiC;AAEjC,iCAA+B;AAC/B,wBAA0B;AAC1B,iCAGO;AAyFJ;AA/FH,IAAM,EAAE,OAAO,QAAQ,QAAI,2BAAQ,kBAAAA,WAAsB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AAAA,kBACpB,kBAAa;AAAA;AAAA,wBAEZ,gBAAI,QAAS;AAAA,oBACb,IAAI;AAAA,kBACL;AAAA,kBACA,WAAU;AAAA,kBACV,OAAQ;AAAA,oBACP,qBAAqB,WAAY,WAAY;AAAA,kBAC9C;AAAA;AAAA,cACD;AAAA,cAGC,cAAI,IAAK,CAAE,SAAU;AACtB,sBAAM,SAAS,UAAW,IAAK;AAC/B,uBACC;AAAA,kBAAC,4BAAU;AAAA,kBAAV;AAAA,oBAEA,QAAS,CAAE,UACV;AAAA,sBAAC;AAAA;AAAA,wBACE,GAAG;AAAA,wBACL,IAAK;AAAA,wBACL,MAAK;AAAA,wBACL;AAAA,wBACA;AAAA,wBACA;AAAA,wBAGA;AAAA,wBACA;AAAA,wBAGA;AAAA,wBAGA;AAAA,wBACA;AAAA,wBACA;AAAA,wBACA;AAAA,wBACA;AAAA,wBACA;AAAA,wBAGA;AAAA,wBAGA;AAAA,wBACA;AAAA,wBAGA,QAAS;AAAA,0BACR,OAAO;AAAA,wBACR;AAAA;AAAA,oBACD;AAAA;AAAA,kBApCK;AAAA,gBAsCP;AAAA,cAEF,CAAE;AAAA;AAAA,YA7DI;AAAA,UA8DP,CACC;AAAA;AAAA,MACH;AAAA;AAAA,GAGH;AAEF;",
|
|
6
6
|
"names": ["componentsPrivateApis", "GridItem", "clsx", "DataViewsSelectionCheckbox", "ItemActions", "DataViewsContext"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataviews-layouts/list/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId, usePrevious } from '@wordpress/compose';\nimport {\n\tButton,\n\tprivateApis as componentsPrivateApis,\n\tSpinner,\n\tComposite,\n} from '@wordpress/components';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseContext,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { moreVertical } from '@wordpress/icons';\nimport { useRegistry } from '@wordpress/data';\nimport { Stack, VisuallyHidden } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport { ActionsMenuGroup, ActionModal } from '../../dataviews-item-actions';\nimport DataViewsContext from '../../dataviews-context';\nimport { useDelayedLoading } from '../../../hooks/use-delayed-loading';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewList as ViewListType,\n\tViewListProps,\n\tActionModal as ActionModalType,\n} from '../../../types';\nimport getDataByGroup from '../utils/get-data-by-group';\n\ninterface ListViewItemProps< Item > {\n\tview: ViewListType;\n\tactions: Action< Item >[];\n\tidPrefix: string;\n\tisSelected: boolean;\n\titem: Item;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tonSelect: ( item: Item ) => void;\n\totherFields: NormalizedField< Item >[];\n\tonDropdownTriggerKeyDown: React.KeyboardEventHandler< HTMLButtonElement >;\n\tposinset?: number;\n}\n\nconst { Menu } = unlock( componentsPrivateApis );\n\nfunction generateItemWrapperCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-item-wrapper`;\n}\nfunction generatePrimaryActionCompositeId(\n\tidPrefix: string,\n\tprimaryActionId: string\n) {\n\treturn `${ idPrefix }-primary-action-${ primaryActionId }`;\n}\nfunction generateDropdownTriggerCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-dropdown`;\n}\n\nfunction PrimaryActionGridCell< Item >( {\n\tidPrefix,\n\tprimaryAction,\n\titem,\n}: {\n\tidPrefix: string;\n\tprimaryAction: Action< Item >;\n\titem: Item;\n} ) {\n\tconst registry = useRegistry();\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\n\tconst compositeItemId = generatePrimaryActionCompositeId(\n\t\tidPrefix,\n\t\tprimaryAction.id\n\t);\n\n\tconst label =\n\t\ttypeof primaryAction.label === 'string'\n\t\t\t? primaryAction.label\n\t\t\t: primaryAction.label( [ item ] );\n\n\treturn 'RenderModal' in primaryAction ? (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\ttext={ label }\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ isModalOpen && (\n\t\t\t\t\t<ActionModal< Item >\n\t\t\t\t\t\taction={ primaryAction }\n\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Composite.Item>\n\t\t</div>\n\t) : (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tprimaryAction.callback( [ item ], { registry } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</Button>\n\t\t\t\t}\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction ListItem< Item >( {\n\tview,\n\tactions,\n\tidPrefix,\n\tisSelected,\n\titem,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tonSelect,\n\totherFields,\n\tonDropdownTriggerKeyDown,\n\tposinset,\n}: ListViewItemProps< Item > ) {\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst itemRef = useRef< HTMLDivElement >( null );\n\tconst labelId = `${ idPrefix }-label`;\n\tconst descriptionId = `${ idPrefix }-description`;\n\n\tconst registry = useRegistry();\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst [ activeModalAction, setActiveModalAction ] = useState(\n\t\tnull as ActionModalType< Item > | null\n\t);\n\tconst handleHover: React.MouseEventHandler = ( { type } ) => {\n\t\tconst isHover = type === 'mouseenter';\n\t\tsetIsHovered( isHover );\n\t};\n\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\tuseEffect( () => {\n\t\tif ( isSelected ) {\n\t\t\titemRef.current?.scrollIntoView( {\n\t\t\t\tbehavior: 'auto',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\t}, [ isSelected ] );\n\n\tconst { primaryAction, eligibleActions } = useMemo( () => {\n\t\t// If an action is eligible for all items, doesn't need\n\t\t// to provide the `isEligible` function.\n\t\tconst _eligibleActions = actions.filter(\n\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t);\n\t\tconst _primaryActions = _eligibleActions.filter(\n\t\t\t( action ) => action.isPrimary\n\t\t);\n\t\treturn {\n\t\t\tprimaryAction: _primaryActions[ 0 ],\n\t\t\teligibleActions: _eligibleActions,\n\t\t};\n\t}, [ actions, item ] );\n\n\tconst hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;\n\n\tconst renderedMediaField =\n\t\tshowMedia && mediaField?.render ? (\n\t\t\t<div className=\"dataviews-view-list__media-wrapper\">\n\t\t\t\t<mediaField.render\n\t\t\t\t\titem={ item }\n\t\t\t\t\tfield={ mediaField }\n\t\t\t\t\tconfig={ { sizes: '52px' } }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t) : null;\n\n\tconst renderedTitleField =\n\t\tshowTitle && titleField?.render ? (\n\t\t\t<titleField.render item={ item } field={ titleField } />\n\t\t) : null;\n\n\tconst renderDescription = showDescription && descriptionField?.render;\n\t// When we have only the media and title fields, we want to center them vertically in the list item.\n\tconst hasOnlyMediaAndTitle =\n\t\t!! renderedMediaField && ! renderDescription && ! otherFields.length;\n\tconst usedActions = eligibleActions?.length > 0 && (\n\t\t<Stack\n\t\t\tdirection=\"row\"\n\t\t\tgap=\"md\"\n\t\t\tclassName=\"dataviews-view-list__item-actions\"\n\t\t>\n\t\t\t{ primaryAction && (\n\t\t\t\t<PrimaryActionGridCell\n\t\t\t\t\tidPrefix={ idPrefix }\n\t\t\t\t\tprimaryAction={ primaryAction }\n\t\t\t\t\titem={ item }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! hasOnlyOnePrimaryAction && (\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Menu placement=\"bottom-end\">\n\t\t\t\t\t\t<Menu.TriggerButton\n\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tid={ generateDropdownTriggerCompositeId(\n\t\t\t\t\t\t\t\t\t\tidPrefix\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Actions' ) }\n\t\t\t\t\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\t\t\t\t\tdisabled={ ! actions.length }\n\t\t\t\t\t\t\t\t\t\t\tonKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t<ActionsMenuGroup\n\t\t\t\t\t\t\t\tactions={ eligibleActions }\n\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\tregistry={ registry }\n\t\t\t\t\t\t\t\tsetActiveModalAction={ setActiveModalAction }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Menu.Popover>\n\t\t\t\t\t</Menu>\n\t\t\t\t\t{ !! activeModalAction && (\n\t\t\t\t\t\t<ActionModal\n\t\t\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</Stack>\n\t);\n\n\treturn (\n\t\t<Composite.Row\n\t\t\tref={ itemRef }\n\t\t\trender={\n\t\t\t\t/* aria-posinset breaks Composite.Row if passed to it directly. */\n\t\t\t\t<div\n\t\t\t\t\taria-posinset={ posinset }\n\t\t\t\t\taria-setsize={\n\t\t\t\t\t\tinfiniteScrollEnabled\n\t\t\t\t\t\t\t? paginationInfo.totalItems\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t}\n\t\t\trole={ infiniteScrollEnabled ? 'article' : 'row' }\n\t\t\tclassName={ clsx( {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'is-hovered': isHovered,\n\t\t\t} ) }\n\t\t\tonMouseEnter={ handleHover }\n\t\t\tonMouseLeave={ handleHover }\n\t\t>\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-view-list__item-wrapper\"\n\t\t\t>\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\tid={ generateItemWrapperCompositeId( idPrefix ) }\n\t\t\t\t\t\taria-pressed={ isSelected }\n\t\t\t\t\t\taria-labelledby={ labelId }\n\t\t\t\t\t\taria-describedby={ descriptionId }\n\t\t\t\t\t\tclassName=\"dataviews-view-list__item\"\n\t\t\t\t\t\tonClick={ () => onSelect( item ) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\tgap=\"md\"\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\talign={ hasOnlyMediaAndTitle ? 'center' : 'flex-start' }\n\t\t\t\t\tstyle={ { flex: 1, minWidth: 0 } }\n\t\t\t\t>\n\t\t\t\t\t{ renderedMediaField }\n\t\t\t\t\t<Stack\n\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\t\tclassName=\"dataviews-view-list__field-wrapper\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"row\" align=\"center\">\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"dataviews-title-field dataviews-view-list__title-field\"\n\t\t\t\t\t\t\t\tid={ labelId }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ renderedTitleField }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ usedActions }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t{ renderDescription && (\n\t\t\t\t\t\t\t<div className=\"dataviews-view-list__field\">\n\t\t\t\t\t\t\t\t<descriptionField.render\n\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\tfield={ descriptionField }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"dataviews-view-list__fields\"\n\t\t\t\t\t\t\tid={ descriptionId }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ otherFields.map( ( field ) => (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field-label\"\n\t\t\t\t\t\t\t\t\t\trender={ <span /> }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t\t\t<span className=\"dataviews-view-list__field-value\">\n\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Stack>\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t</Composite.Row>\n\t);\n}\n\nfunction isDefined< T >( item: T | undefined ): item is T {\n\treturn !! item;\n}\n\nexport default function ViewList< Item >( props: ViewListProps< Item > ) {\n\tconst {\n\t\tactions,\n\t\tdata,\n\t\tfields,\n\t\tgetItemId,\n\t\tisLoading,\n\t\tonChangeSelection,\n\t\tselection,\n\t\tview,\n\t\tclassName,\n\t\tempty,\n\t} = props;\n\tconst baseId = useInstanceId( ViewList, 'view-list' );\n\tconst isDelayedLoading = useDelayedLoading( !! isLoading );\n\n\tconst selectedItem = data?.findLast( ( item ) =>\n\t\tselection.includes( getItemId( item ) )\n\t);\n\tconst titleField = fields.find( ( field ) => field.id === view.titleField );\n\tconst mediaField = fields.find( ( field ) => field.id === view.mediaField );\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view.descriptionField\n\t);\n\tconst otherFields = ( view?.fields ?? [] )\n\t\t.map( ( fieldId ) => fields.find( ( f ) => fieldId === f.id ) )\n\t\t.filter( isDefined );\n\n\tconst onSelect = ( item: Item ) =>\n\t\tonChangeSelection( [ getItemId( item ) ] );\n\n\tconst generateCompositeItemIdPrefix = useCallback(\n\t\t( item: Item ) => `${ baseId }-${ getItemId( item ) }`,\n\t\t[ baseId, getItemId ]\n\t);\n\n\tconst isActiveCompositeItem = useCallback(\n\t\t( item: Item, idToCheck: string ) => {\n\t\t\t// All composite items use the same prefix in their IDs.\n\t\t\treturn idToCheck.startsWith(\n\t\t\t\tgenerateCompositeItemIdPrefix( item )\n\t\t\t);\n\t\t},\n\t\t[ generateCompositeItemIdPrefix ]\n\t);\n\n\t// Controlled state for the active composite item.\n\tconst [ activeCompositeId, setActiveCompositeId ] = useState<\n\t\tstring | null | undefined\n\t>( undefined );\n\n\tconst compositeRef = useRef< HTMLDivElement >( null );\n\n\t// Update the active composite item when the selected item changes.\n\tuseEffect( () => {\n\t\tif ( selectedItem ) {\n\t\t\tsetActiveCompositeId(\n\t\t\t\tgenerateItemWrapperCompositeId(\n\t\t\t\t\tgenerateCompositeItemIdPrefix( selectedItem )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}, [ selectedItem, generateCompositeItemIdPrefix ] );\n\n\tconst activeItemIndex = data.findIndex( ( item ) =>\n\t\tisActiveCompositeItem( item, activeCompositeId ?? '' )\n\t);\n\tconst previousActiveItemIndex = usePrevious( activeItemIndex );\n\tconst isActiveIdInList = activeItemIndex !== -1;\n\n\tconst selectCompositeItem = useCallback(\n\t\t(\n\t\t\ttargetIndex: number,\n\t\t\t// Allows invokers to specify a custom function to generate the\n\t\t\t// target composite item ID\n\t\t\tgenerateCompositeId: ( idPrefix: string ) => string\n\t\t) => {\n\t\t\t// Clamping between 0 and data.length - 1 to avoid out of bounds.\n\t\t\tconst clampedIndex = Math.min(\n\t\t\t\tdata.length - 1,\n\t\t\t\tMath.max( 0, targetIndex )\n\t\t\t);\n\t\t\tif ( ! data[ clampedIndex ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst itemIdPrefix = generateCompositeItemIdPrefix(\n\t\t\t\tdata[ clampedIndex ]\n\t\t\t);\n\t\t\tconst targetCompositeItemId = generateCompositeId( itemIdPrefix );\n\n\t\t\tsetActiveCompositeId( targetCompositeItemId );\n\t\t\t// The active composite item is controlled state that\n\t\t\t// can update without needing a focus move (e.g., searching\n\t\t\t// can trigger an active ID update). Only move DOM focus\n\t\t\t// when it's already within the list.\n\t\t\tif (\n\t\t\t\tcompositeRef.current?.contains(\n\t\t\t\t\tcompositeRef.current.ownerDocument.activeElement\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tdocument.getElementById( targetCompositeItemId )?.focus();\n\t\t\t}\n\t\t},\n\t\t[ data, generateCompositeItemIdPrefix ]\n\t);\n\n\t// Select a new active composite item when the current active item\n\t// is removed from the list.\n\tuseEffect( () => {\n\t\tconst wasActiveIdInList =\n\t\t\tpreviousActiveItemIndex !== undefined &&\n\t\t\tpreviousActiveItemIndex !== -1;\n\t\tif ( ! isActiveIdInList && wasActiveIdInList ) {\n\t\t\t// By picking `previousActiveItemIndex` as the next item index, we are\n\t\t\t// basically picking the item that would have been after the deleted one.\n\t\t\t// If the previously active (and removed) item was the last of the list,\n\t\t\t// we will select the item before it \u2014 which is the new last item.\n\t\t\tselectCompositeItem(\n\t\t\t\tpreviousActiveItemIndex,\n\t\t\t\tgenerateItemWrapperCompositeId\n\t\t\t);\n\t\t}\n\t}, [ isActiveIdInList, selectCompositeItem, previousActiveItemIndex ] );\n\n\t// Prevent the default behavior (open dropdown menu) and instead select the\n\t// dropdown menu trigger on the previous/next row.\n\t// https://github.com/ariakit/ariakit/issues/3768\n\tconst onDropdownTriggerKeyDown = useCallback(\n\t\t( event: React.KeyboardEvent< HTMLButtonElement > ) => {\n\t\t\tif ( event.key === 'ArrowDown' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the next row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex + 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ( event.key === 'ArrowUp' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the previous row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex - 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ selectCompositeItem, activeItemIndex ]\n\t);\n\n\tconst hasData = !! data?.length;\n\tconst groupField = view.groupBy?.field\n\t\t? fields.find( ( field ) => field.id === view.groupBy?.field )\n\t\t: null;\n\tconst dataByGroup =\n\t\thasData && groupField ? getDataByGroup( data, groupField ) : null;\n\tconst isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup;\n\tif ( ! hasData ) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'dataviews-no-results', {\n\t\t\t\t\t'is-refreshing': isDelayedLoading,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ empty }\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Render data grouped by field\n\tif ( hasData && groupField && dataByGroup ) {\n\t\treturn (\n\t\t\t<Composite\n\t\t\t\tref={ compositeRef }\n\t\t\t\tid={ `${ baseId }` }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName=\"dataviews-view-list__group\"\n\t\t\t\trole=\"grid\"\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tgap=\"lg\"\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-list', className ) }\n\t\t\t\t>\n\t\t\t\t\t{ Array.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tkey={ groupName }\n\t\t\t\t\t\t\t\tgap=\"sm\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<h3 className=\"dataviews-view-list__group-header\">\n\t\t\t\t\t\t\t\t\t{ view.groupBy?.showLabel === false\n\t\t\t\t\t\t\t\t\t\t? groupName\n\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t// translators: 1: The label of the field e.g. \"Date\". 2: The value of the field, e.g.: \"May 2022\".\n\t\t\t\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\t\t\t\tgroupField.label,\n\t\t\t\t\t\t\t\t\t\t\t\tgroupName\n\t\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t</h3>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst id =\n\t\t\t\t\t\t\t\t\t\tgenerateCompositeItemIdPrefix( item );\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t)\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</Composite>\n\t\t);\n\t}\n\n\t// Render ungrouped data\n\treturn (\n\t\t<>\n\t\t\t<Composite\n\t\t\t\tref={ compositeRef }\n\t\t\t\tid={ baseId }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName={ clsx( 'dataviews-view-list', className, {\n\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t),\n\t\t\t\t\t'is-refreshing': ! isInfiniteScroll && isDelayedLoading,\n\t\t\t\t} ) }\n\t\t\t\trole={ view.infiniteScrollEnabled ? 'feed' : 'grid' }\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t\t// @ts-ignore\n\t\t\t\tinert={\n\t\t\t\t\t! isInfiniteScroll && !! isLoading ? 'true' : undefined\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ data.map( ( item, index ) => {\n\t\t\t\t\tconst id = generateCompositeItemIdPrefix( item );\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tposinset={\n\t\t\t\t\t\t\t\tview.infiniteScrollEnabled\n\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</Composite>\n\t\t\t{ isInfiniteScroll && isLoading && (\n\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId, usePrevious } from '@wordpress/compose';\nimport {\n\tButton,\n\tprivateApis as componentsPrivateApis,\n\tSpinner,\n\tComposite,\n} from '@wordpress/components';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseContext,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { moreVertical } from '@wordpress/icons';\nimport { useRegistry } from '@wordpress/data';\nimport { Stack, VisuallyHidden } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport { ActionsMenuGroup, ActionModal } from '../../dataviews-item-actions';\nimport DataViewsContext from '../../dataviews-context';\nimport { useDelayedLoading } from '../../../hooks/use-delayed-loading';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewList as ViewListType,\n\tViewListProps,\n\tActionModal as ActionModalType,\n} from '../../../types';\nimport getDataByGroup from '../utils/get-data-by-group';\n\ninterface ListViewItemProps< Item > {\n\tview: ViewListType;\n\tactions: Action< Item >[];\n\tidPrefix: string;\n\tisSelected: boolean;\n\titem: Item;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tonSelect: ( item: Item ) => void;\n\totherFields: NormalizedField< Item >[];\n\tonDropdownTriggerKeyDown: React.KeyboardEventHandler< HTMLButtonElement >;\n\tposinset?: number;\n}\n\nconst { Menu } = unlock( componentsPrivateApis );\n\nfunction generateItemWrapperCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-item-wrapper`;\n}\nfunction generatePrimaryActionCompositeId(\n\tidPrefix: string,\n\tprimaryActionId: string\n) {\n\treturn `${ idPrefix }-primary-action-${ primaryActionId }`;\n}\nfunction generateDropdownTriggerCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-dropdown`;\n}\n\nfunction PrimaryActionGridCell< Item >( {\n\tidPrefix,\n\tprimaryAction,\n\titem,\n}: {\n\tidPrefix: string;\n\tprimaryAction: Action< Item >;\n\titem: Item;\n} ) {\n\tconst registry = useRegistry();\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\n\tconst compositeItemId = generatePrimaryActionCompositeId(\n\t\tidPrefix,\n\t\tprimaryAction.id\n\t);\n\n\tconst label =\n\t\ttypeof primaryAction.label === 'string'\n\t\t\t? primaryAction.label\n\t\t\t: primaryAction.label( [ item ] );\n\n\treturn 'RenderModal' in primaryAction ? (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\ttext={ label }\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ isModalOpen && (\n\t\t\t\t\t<ActionModal< Item >\n\t\t\t\t\t\taction={ primaryAction }\n\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Composite.Item>\n\t\t</div>\n\t) : (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tprimaryAction.callback( [ item ], { registry } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</Button>\n\t\t\t\t}\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction ListItem< Item >( {\n\tview,\n\tactions,\n\tidPrefix,\n\tisSelected,\n\titem,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tonSelect,\n\totherFields,\n\tonDropdownTriggerKeyDown,\n\tposinset,\n}: ListViewItemProps< Item > ) {\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst itemRef = useRef< HTMLDivElement >( null );\n\tconst labelId = `${ idPrefix }-label`;\n\tconst descriptionId = `${ idPrefix }-description`;\n\n\tconst registry = useRegistry();\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst [ activeModalAction, setActiveModalAction ] = useState(\n\t\tnull as ActionModalType< Item > | null\n\t);\n\tconst handleHover: React.MouseEventHandler = ( { type } ) => {\n\t\tconst isHover = type === 'mouseenter';\n\t\tsetIsHovered( isHover );\n\t};\n\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\tuseEffect( () => {\n\t\tif ( isSelected ) {\n\t\t\titemRef.current?.scrollIntoView( {\n\t\t\t\tbehavior: 'auto',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\t}, [ isSelected ] );\n\n\tconst { primaryAction, eligibleActions } = useMemo( () => {\n\t\t// If an action is eligible for all items, doesn't need\n\t\t// to provide the `isEligible` function.\n\t\tconst _eligibleActions = actions.filter(\n\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t);\n\t\tconst _primaryActions = _eligibleActions.filter(\n\t\t\t( action ) => action.isPrimary\n\t\t);\n\t\treturn {\n\t\t\tprimaryAction: _primaryActions[ 0 ],\n\t\t\teligibleActions: _eligibleActions,\n\t\t};\n\t}, [ actions, item ] );\n\n\tconst hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;\n\n\tconst renderedMediaField =\n\t\tshowMedia && mediaField?.render ? (\n\t\t\t<div className=\"dataviews-view-list__media-wrapper\">\n\t\t\t\t<mediaField.render\n\t\t\t\t\titem={ item }\n\t\t\t\t\tfield={ mediaField }\n\t\t\t\t\tconfig={ { sizes: '52px' } }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t) : null;\n\n\tconst renderedTitleField =\n\t\tshowTitle && titleField?.render ? (\n\t\t\t<titleField.render item={ item } field={ titleField } />\n\t\t) : null;\n\n\tconst renderDescription = showDescription && descriptionField?.render;\n\t// When we have only the media and title fields, we want to center them vertically in the list item.\n\tconst hasOnlyMediaAndTitle =\n\t\t!! renderedMediaField && ! renderDescription && ! otherFields.length;\n\tconst usedActions = eligibleActions?.length > 0 && (\n\t\t<Stack\n\t\t\tdirection=\"row\"\n\t\t\tgap=\"md\"\n\t\t\tclassName=\"dataviews-view-list__item-actions\"\n\t\t>\n\t\t\t{ primaryAction && (\n\t\t\t\t<PrimaryActionGridCell\n\t\t\t\t\tidPrefix={ idPrefix }\n\t\t\t\t\tprimaryAction={ primaryAction }\n\t\t\t\t\titem={ item }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! hasOnlyOnePrimaryAction && (\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Menu placement=\"bottom-end\">\n\t\t\t\t\t\t<Menu.TriggerButton\n\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tid={ generateDropdownTriggerCompositeId(\n\t\t\t\t\t\t\t\t\t\tidPrefix\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Actions' ) }\n\t\t\t\t\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\t\t\t\t\tdisabled={ ! actions.length }\n\t\t\t\t\t\t\t\t\t\t\tonKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t<ActionsMenuGroup\n\t\t\t\t\t\t\t\tactions={ eligibleActions }\n\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\tregistry={ registry }\n\t\t\t\t\t\t\t\tsetActiveModalAction={ setActiveModalAction }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Menu.Popover>\n\t\t\t\t\t</Menu>\n\t\t\t\t\t{ !! activeModalAction && (\n\t\t\t\t\t\t<ActionModal\n\t\t\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</Stack>\n\t);\n\n\treturn (\n\t\t<Composite.Row\n\t\t\tref={ itemRef }\n\t\t\trender={\n\t\t\t\t/* aria-posinset breaks Composite.Row if passed to it directly. */\n\t\t\t\t<div\n\t\t\t\t\taria-posinset={ posinset }\n\t\t\t\t\taria-setsize={\n\t\t\t\t\t\tinfiniteScrollEnabled\n\t\t\t\t\t\t\t? paginationInfo.totalItems\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t}\n\t\t\trole={ infiniteScrollEnabled ? 'article' : 'row' }\n\t\t\tclassName={ clsx( {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'is-hovered': isHovered,\n\t\t\t} ) }\n\t\t\tonMouseEnter={ handleHover }\n\t\t\tonMouseLeave={ handleHover }\n\t\t>\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-view-list__item-wrapper\"\n\t\t\t>\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\tid={ generateItemWrapperCompositeId( idPrefix ) }\n\t\t\t\t\t\taria-pressed={ isSelected }\n\t\t\t\t\t\taria-labelledby={ labelId }\n\t\t\t\t\t\taria-describedby={ descriptionId }\n\t\t\t\t\t\tclassName=\"dataviews-view-list__item\"\n\t\t\t\t\t\tonClick={ () => onSelect( item ) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\tgap=\"md\"\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\talign={ hasOnlyMediaAndTitle ? 'center' : 'flex-start' }\n\t\t\t\t\tstyle={ { flex: 1, minWidth: 0 } }\n\t\t\t\t>\n\t\t\t\t\t{ renderedMediaField }\n\t\t\t\t\t<Stack\n\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\t\tclassName=\"dataviews-view-list__field-wrapper\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"row\" align=\"center\">\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"dataviews-title-field dataviews-view-list__title-field\"\n\t\t\t\t\t\t\t\tid={ labelId }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ renderedTitleField }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ usedActions }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t{ renderDescription && (\n\t\t\t\t\t\t\t<div className=\"dataviews-view-list__field\">\n\t\t\t\t\t\t\t\t<descriptionField.render\n\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\tfield={ descriptionField }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"dataviews-view-list__fields\"\n\t\t\t\t\t\t\tid={ descriptionId }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ otherFields.map( ( field ) => (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field-label\"\n\t\t\t\t\t\t\t\t\t\trender={ <span /> }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t\t\t<span className=\"dataviews-view-list__field-value\">\n\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Stack>\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t</Composite.Row>\n\t);\n}\n\nfunction isDefined< T >( item: T | undefined ): item is T {\n\treturn !! item;\n}\n\nexport default function ViewList< Item >( props: ViewListProps< Item > ) {\n\tconst {\n\t\tactions,\n\t\tdata,\n\t\tfields,\n\t\tgetItemId,\n\t\tisLoading,\n\t\tonChangeSelection,\n\t\tselection,\n\t\tview,\n\t\tclassName,\n\t\tempty,\n\t} = props;\n\tconst baseId = useInstanceId( ViewList, 'view-list' );\n\tconst isDelayedLoading = useDelayedLoading( !! isLoading );\n\n\tconst selectedItem = data?.findLast( ( item ) =>\n\t\tselection.includes( getItemId( item ) )\n\t);\n\tconst titleField = fields.find( ( field ) => field.id === view.titleField );\n\tconst mediaField = fields.find( ( field ) => field.id === view.mediaField );\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view.descriptionField\n\t);\n\tconst otherFields = ( view?.fields ?? [] )\n\t\t.map( ( fieldId ) => fields.find( ( f ) => fieldId === f.id ) )\n\t\t.filter( isDefined );\n\n\tconst onSelect = ( item: Item ) =>\n\t\tonChangeSelection( [ getItemId( item ) ] );\n\n\tconst generateCompositeItemIdPrefix = useCallback(\n\t\t( item: Item ) => `${ baseId }-${ getItemId( item ) }`,\n\t\t[ baseId, getItemId ]\n\t);\n\n\tconst isActiveCompositeItem = useCallback(\n\t\t( item: Item, idToCheck: string ) => {\n\t\t\t// All composite items use the same prefix in their IDs.\n\t\t\treturn idToCheck.startsWith(\n\t\t\t\tgenerateCompositeItemIdPrefix( item )\n\t\t\t);\n\t\t},\n\t\t[ generateCompositeItemIdPrefix ]\n\t);\n\n\t// Controlled state for the active composite item.\n\tconst [ activeCompositeId, setActiveCompositeId ] = useState<\n\t\tstring | null | undefined\n\t>( undefined );\n\n\tconst compositeRef = useRef< HTMLDivElement >( null );\n\n\t// Update the active composite item when the selected item changes.\n\tuseEffect( () => {\n\t\tif ( selectedItem ) {\n\t\t\tsetActiveCompositeId(\n\t\t\t\tgenerateItemWrapperCompositeId(\n\t\t\t\t\tgenerateCompositeItemIdPrefix( selectedItem )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}, [ selectedItem, generateCompositeItemIdPrefix ] );\n\n\tconst activeItemIndex = data.findIndex( ( item ) =>\n\t\tisActiveCompositeItem( item, activeCompositeId ?? '' )\n\t);\n\tconst previousActiveItemIndex = usePrevious( activeItemIndex );\n\tconst isActiveIdInList = activeItemIndex !== -1;\n\n\tconst selectCompositeItem = useCallback(\n\t\t(\n\t\t\ttargetIndex: number,\n\t\t\t// Allows invokers to specify a custom function to generate the\n\t\t\t// target composite item ID\n\t\t\tgenerateCompositeId: ( idPrefix: string ) => string\n\t\t) => {\n\t\t\t// Clamping between 0 and data.length - 1 to avoid out of bounds.\n\t\t\tconst clampedIndex = Math.min(\n\t\t\t\tdata.length - 1,\n\t\t\t\tMath.max( 0, targetIndex )\n\t\t\t);\n\t\t\tif ( ! data[ clampedIndex ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst itemIdPrefix = generateCompositeItemIdPrefix(\n\t\t\t\tdata[ clampedIndex ]\n\t\t\t);\n\t\t\tconst targetCompositeItemId = generateCompositeId( itemIdPrefix );\n\n\t\t\tsetActiveCompositeId( targetCompositeItemId );\n\t\t\t// The active composite item is controlled state that\n\t\t\t// can update without needing a focus move (e.g., searching\n\t\t\t// can trigger an active ID update). Only move DOM focus\n\t\t\t// when it's already within the list.\n\t\t\tif (\n\t\t\t\tcompositeRef.current?.contains(\n\t\t\t\t\tcompositeRef.current.ownerDocument.activeElement\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tdocument.getElementById( targetCompositeItemId )?.focus();\n\t\t\t}\n\t\t},\n\t\t[ data, generateCompositeItemIdPrefix ]\n\t);\n\n\t// Select a new active composite item when the current active item\n\t// is removed from the list.\n\tuseEffect( () => {\n\t\tconst wasActiveIdInList =\n\t\t\tpreviousActiveItemIndex !== undefined &&\n\t\t\tpreviousActiveItemIndex !== -1;\n\t\tif ( ! isActiveIdInList && wasActiveIdInList ) {\n\t\t\t// By picking `previousActiveItemIndex` as the next item index, we are\n\t\t\t// basically picking the item that would have been after the deleted one.\n\t\t\t// If the previously active (and removed) item was the last of the list,\n\t\t\t// we will select the item before it — which is the new last item.\n\t\t\tselectCompositeItem(\n\t\t\t\tpreviousActiveItemIndex,\n\t\t\t\tgenerateItemWrapperCompositeId\n\t\t\t);\n\t\t}\n\t}, [ isActiveIdInList, selectCompositeItem, previousActiveItemIndex ] );\n\n\t// Prevent the default behavior (open dropdown menu) and instead select the\n\t// dropdown menu trigger on the previous/next row.\n\t// https://github.com/ariakit/ariakit/issues/3768\n\tconst onDropdownTriggerKeyDown = useCallback(\n\t\t( event: React.KeyboardEvent< HTMLButtonElement > ) => {\n\t\t\tif ( event.key === 'ArrowDown' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the next row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex + 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ( event.key === 'ArrowUp' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the previous row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex - 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ selectCompositeItem, activeItemIndex ]\n\t);\n\n\tconst hasData = !! data?.length;\n\tconst groupField = view.groupBy?.field\n\t\t? fields.find( ( field ) => field.id === view.groupBy?.field )\n\t\t: null;\n\tconst dataByGroup =\n\t\thasData && groupField ? getDataByGroup( data, groupField ) : null;\n\tconst isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup;\n\tif ( ! hasData ) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'dataviews-no-results', {\n\t\t\t\t\t'is-refreshing': isDelayedLoading,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ empty }\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Render data grouped by field\n\tif ( hasData && groupField && dataByGroup ) {\n\t\treturn (\n\t\t\t<Composite\n\t\t\t\tref={ compositeRef }\n\t\t\t\tid={ `${ baseId }` }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName=\"dataviews-view-list__group\"\n\t\t\t\trole=\"grid\"\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tgap=\"lg\"\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-list', className ) }\n\t\t\t\t>\n\t\t\t\t\t{ Array.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tkey={ groupName }\n\t\t\t\t\t\t\t\tgap=\"sm\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<h3 className=\"dataviews-view-list__group-header\">\n\t\t\t\t\t\t\t\t\t{ view.groupBy?.showLabel === false\n\t\t\t\t\t\t\t\t\t\t? groupName\n\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t// translators: 1: The label of the field e.g. \"Date\". 2: The value of the field, e.g.: \"May 2022\".\n\t\t\t\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\t\t\t\tgroupField.label,\n\t\t\t\t\t\t\t\t\t\t\t\tgroupName\n\t\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t</h3>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst id =\n\t\t\t\t\t\t\t\t\t\tgenerateCompositeItemIdPrefix( item );\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t)\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</Composite>\n\t\t);\n\t}\n\n\t// Render ungrouped data\n\treturn (\n\t\t<>\n\t\t\t<Composite\n\t\t\t\tref={ compositeRef }\n\t\t\t\tid={ baseId }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName={ clsx( 'dataviews-view-list', className, {\n\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t),\n\t\t\t\t\t'is-refreshing': ! isInfiniteScroll && isDelayedLoading,\n\t\t\t\t} ) }\n\t\t\t\trole={ view.infiniteScrollEnabled ? 'feed' : 'grid' }\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t\t// @ts-ignore\n\t\t\t\tinert={\n\t\t\t\t\t! isInfiniteScroll && !! isLoading ? 'true' : undefined\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ data.map( ( item, index ) => {\n\t\t\t\t\tconst id = generateCompositeItemIdPrefix( item );\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tposinset={\n\t\t\t\t\t\t\t\tview.infiniteScrollEnabled\n\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</Composite>\n\t\t\t{ isInfiniteScroll && isLoading && (\n\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
5
5
|
"m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AAA,QACD;AAAA;AAAA,IACD;AAAA,EAEF;AAGA,SACC,4EACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,KAAM;AAAA,QACN,IAAK;AAAA,QACL,QAAS,4CAAC,SAAI;AAAA,QACd,eAAY,YAAAA,SAAM,uBAAuB,WAAW;AAAA,UACnD,CAAE,OAAQ,KAAK,QAAQ,OAAQ,UAAW,GACzC,KAAK,QAAQ,WACb,CAAE,WAAW,aAAc,EAAE;AAAA,YAC5B,KAAK,OAAO;AAAA,UACb;AAAA,UACD,iBAAiB,CAAE,oBAAoB;AAAA,QACxC,CAAE;AAAA,QACF,MAAO,KAAK,wBAAwB,SAAS;AAAA,QAC7C,UAAW;AAAA,QACX,aAAc;AAAA,QAEd,OACC,CAAE,oBAAoB,CAAC,CAAE,YAAY,SAAS;AAAA,QAG7C,eAAK,IAAK,CAAE,MAAM,UAAW;AAC9B,gBAAM,KAAK,8BAA+B,IAAK;AAC/C,iBACC;AAAA,YAAC;AAAA;AAAA,cAEA;AAAA,cACA,UAAW;AAAA,cACX;AAAA,cACA;AAAA,cACA,YAAa,SAAS;AAAA,cACtB;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cAGA,UACC,KAAK,wBACF,QAAQ,IACR;AAAA;AAAA,YAjBE;AAAA,UAmBP;AAAA,QAEF,CAAE;AAAA;AAAA,IACH;AAAA,IACE,oBAAoB,aACrB,4CAAC,OAAE,WAAU,0BACZ,sDAAC,6BAAQ,GACV;AAAA,KAEF;AAEF;",
|
|
6
6
|
"names": ["componentsPrivateApis", "DataViewsContext", "clsx", "getDataByGroup"]
|
|
7
7
|
}
|
|
@@ -73,8 +73,8 @@ function ColumnPrimary({
|
|
|
73
73
|
className: "dataviews-view-table__cell-content-wrapper dataviews-title-field",
|
|
74
74
|
children: [
|
|
75
75
|
level !== void 0 && level > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dataviews-view-table__level", children: [
|
|
76
|
-
Array(level).fill("
|
|
77
|
-
"
|
|
76
|
+
Array(level).fill("—").join(" "),
|
|
77
|
+
" "
|
|
78
78
|
] }),
|
|
79
79
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(titleField.render, { item, field: titleField })
|
|
80
80
|
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataviews-layouts/table/column-primary.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentProps, ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedField } from '../../../types';\nimport { ItemClickWrapper } from '../utils/item-click-wrapper';\n\nfunction ColumnPrimary< Item >( {\n\titem,\n\tlevel,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tonClickItem,\n\trenderItemLink,\n\tisItemClickable,\n}: {\n\titem: Item;\n\tlevel?: number;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n} ) {\n\treturn (\n\t\t<Stack direction=\"row\" gap=\"md\" align=\"flex-start\" justify=\"flex-start\">\n\t\t\t{ mediaField && (\n\t\t\t\t<ItemClickWrapper\n\t\t\t\t\titem={ item }\n\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\tclassName=\"dataviews-view-table__cell-content-wrapper dataviews-column-primary__media\"\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tisItemClickable( item ) &&\n\t\t\t\t\t\t( !! onClickItem || !! renderItemLink ) &&\n\t\t\t\t\t\t!! titleField\n\t\t\t\t\t\t\t? titleField.getValue?.( { item } )\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<mediaField.render\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tfield={ mediaField }\n\t\t\t\t\t\tconfig={ { sizes: '32px' } }\n\t\t\t\t\t/>\n\t\t\t\t</ItemClickWrapper>\n\t\t\t) }\n\t\t\t<Stack\n\t\t\t\tdirection=\"column\"\n\t\t\t\talign=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-view-table__primary-column-content\"\n\t\t\t>\n\t\t\t\t{ titleField && (\n\t\t\t\t\t<ItemClickWrapper\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\tclassName=\"dataviews-view-table__cell-content-wrapper dataviews-title-field\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ level !== undefined && level > 0 && (\n\t\t\t\t\t\t\t<span className=\"dataviews-view-table__level\">\n\t\t\t\t\t\t\t\t{ Array( level ).fill( '
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,gBAAsB;AAMtB,gCAAiC;AA0C5B;AAxCL,SAAS,cAAuB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAaI;AACH,SACC,6CAAC,mBAAM,WAAU,OAAM,KAAI,MAAK,OAAM,cAAa,SAAQ,cACxD;AAAA,kBACD;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAU;AAAA,QACV,cACC,gBAAiB,IAAK,MACpB,CAAC,CAAE,eAAe,CAAC,CAAE,mBACvB,CAAC,CAAE,aACA,WAAW,WAAY,EAAE,KAAK,CAAE,IAChC;AAAA,QAGJ;AAAA,UAAC,WAAW;AAAA,UAAX;AAAA,YACA;AAAA,YACA,OAAQ;AAAA,YACR,QAAS,EAAE,OAAO,OAAO;AAAA;AAAA,QAC1B;AAAA;AAAA,IACD;AAAA,IAED;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,OAAM;AAAA,QACN,WAAU;AAAA,QAER;AAAA,wBACD;AAAA,YAAC;AAAA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA,WAAU;AAAA,cAER;AAAA,0BAAU,UAAa,QAAQ,KAChC,6CAAC,UAAK,WAAU,+BACb;AAAA,wBAAO,KAAM,EAAE,KAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentProps, ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedField } from '../../../types';\nimport { ItemClickWrapper } from '../utils/item-click-wrapper';\n\nfunction ColumnPrimary< Item >( {\n\titem,\n\tlevel,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tonClickItem,\n\trenderItemLink,\n\tisItemClickable,\n}: {\n\titem: Item;\n\tlevel?: number;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n} ) {\n\treturn (\n\t\t<Stack direction=\"row\" gap=\"md\" align=\"flex-start\" justify=\"flex-start\">\n\t\t\t{ mediaField && (\n\t\t\t\t<ItemClickWrapper\n\t\t\t\t\titem={ item }\n\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\tclassName=\"dataviews-view-table__cell-content-wrapper dataviews-column-primary__media\"\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tisItemClickable( item ) &&\n\t\t\t\t\t\t( !! onClickItem || !! renderItemLink ) &&\n\t\t\t\t\t\t!! titleField\n\t\t\t\t\t\t\t? titleField.getValue?.( { item } )\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<mediaField.render\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tfield={ mediaField }\n\t\t\t\t\t\tconfig={ { sizes: '32px' } }\n\t\t\t\t\t/>\n\t\t\t\t</ItemClickWrapper>\n\t\t\t) }\n\t\t\t<Stack\n\t\t\t\tdirection=\"column\"\n\t\t\t\talign=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-view-table__primary-column-content\"\n\t\t\t>\n\t\t\t\t{ titleField && (\n\t\t\t\t\t<ItemClickWrapper\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\tclassName=\"dataviews-view-table__cell-content-wrapper dataviews-title-field\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ level !== undefined && level > 0 && (\n\t\t\t\t\t\t\t<span className=\"dataviews-view-table__level\">\n\t\t\t\t\t\t\t\t{ Array( level ).fill( '—' ).join( ' ' ) } \n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<titleField.render item={ item } field={ titleField } />\n\t\t\t\t\t</ItemClickWrapper>\n\t\t\t\t) }\n\t\t\t\t{ descriptionField && (\n\t\t\t\t\t<descriptionField.render\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tfield={ descriptionField }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Stack>\n\t\t</Stack>\n\t);\n}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KACD;AAEF;AAEA,IAAO,yBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-pagination/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button, SelectControl } from '@wordpress/components';\nimport { createInterpolateElement, memo, useContext } from '@wordpress/element';\nimport { sprintf, __, _x, isRTL } from '@wordpress/i18n';\nimport { next, previous } from '@wordpress/icons';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\n\nexport function DataViewsPagination() {\n\tconst {\n\t\tview,\n\t\tonChangeView,\n\t\tpaginationInfo: { totalItems = 0, totalPages },\n\t} = useContext( DataViewsContext );\n\n\tif ( ! totalItems || ! totalPages || view.infiniteScrollEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst currentPage = view.page ?? 1;\n\tconst pageSelectOptions = Array.from( Array( totalPages ) ).map(\n\t\t( _, i ) => {\n\t\t\tconst page = i + 1;\n\t\t\treturn {\n\t\t\t\tvalue: page.toString(),\n\t\t\t\tlabel: page.toString(),\n\t\t\t\t'aria-label':\n\t\t\t\t\tcurrentPage === page\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: 1: current page number. 2: total number of pages.\n\t\t\t\t\t\t\t\t__( 'Page %1$d of %2$d' ),\n\t\t\t\t\t\t\t\tcurrentPage,\n\t\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: page.toString(),\n\t\t\t};\n\t\t}\n\t);\n\n\treturn (\n\t\t!! totalItems &&\n\t\ttotalPages !== 1 && (\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-pagination\"\n\t\t\t\tjustify=\"end\"\n\t\t\t\talign=\"center\"\n\t\t\t\tgap=\"xl\"\n\t\t\t>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\talign=\"center\"\n\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\tclassName=\"dataviews-pagination__page-select\"\n\t\t\t\t>\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t// translators: 1: Current page number, 2: Total number of pages.\n\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t'<div>Page</div>%1$s<div>of %2$d</div>',\n\t\t\t\t\t\t\t\t'paging'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t'<CurrentPage />',\n\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdiv: <div aria-hidden />,\n\t\t\t\t\t\t\t// @ts-expect-error
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button, SelectControl } from '@wordpress/components';\nimport { createInterpolateElement, memo, useContext } from '@wordpress/element';\nimport { sprintf, __, _x, isRTL } from '@wordpress/i18n';\nimport { next, previous } from '@wordpress/icons';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\n\nexport function DataViewsPagination() {\n\tconst {\n\t\tview,\n\t\tonChangeView,\n\t\tpaginationInfo: { totalItems = 0, totalPages },\n\t} = useContext( DataViewsContext );\n\n\tif ( ! totalItems || ! totalPages || view.infiniteScrollEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst currentPage = view.page ?? 1;\n\tconst pageSelectOptions = Array.from( Array( totalPages ) ).map(\n\t\t( _, i ) => {\n\t\t\tconst page = i + 1;\n\t\t\treturn {\n\t\t\t\tvalue: page.toString(),\n\t\t\t\tlabel: page.toString(),\n\t\t\t\t'aria-label':\n\t\t\t\t\tcurrentPage === page\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: 1: current page number. 2: total number of pages.\n\t\t\t\t\t\t\t\t__( 'Page %1$d of %2$d' ),\n\t\t\t\t\t\t\t\tcurrentPage,\n\t\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: page.toString(),\n\t\t\t};\n\t\t}\n\t);\n\n\treturn (\n\t\t!! totalItems &&\n\t\ttotalPages !== 1 && (\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-pagination\"\n\t\t\t\tjustify=\"end\"\n\t\t\t\talign=\"center\"\n\t\t\t\tgap=\"xl\"\n\t\t\t>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\talign=\"center\"\n\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\tclassName=\"dataviews-pagination__page-select\"\n\t\t\t\t>\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t// translators: 1: Current page number, 2: Total number of pages.\n\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t'<div>Page</div>%1$s<div>of %2$d</div>',\n\t\t\t\t\t\t\t\t'paging'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t'<CurrentPage />',\n\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdiv: <div aria-hidden />,\n\t\t\t\t\t\t\t// @ts-expect-error — Tag injected via sprintf argument, not visible in format string.\n\t\t\t\t\t\t\tCurrentPage: (\n\t\t\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\t\t\taria-label={ __( 'Current page' ) }\n\t\t\t\t\t\t\t\t\tvalue={ currentPage.toString() }\n\t\t\t\t\t\t\t\t\toptions={ pageSelectOptions }\n\t\t\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\t\tpage: +newValue,\n\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\tvariant=\"minimal\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t\t<Stack direction=\"row\" gap=\"xs\" align=\"center\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\tpage: currentPage - 1,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdisabled={ currentPage === 1 }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tlabel={ __( 'Previous page' ) }\n\t\t\t\t\t\ticon={ isRTL() ? next : previous }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\t/>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tonChangeView( { ...view, page: currentPage + 1 } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdisabled={ currentPage >= totalPages }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tlabel={ __( 'Next page' ) }\n\t\t\t\t\t\ticon={ isRTL() ? previous : next }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\t/>\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t)\n\t);\n}\n\nexport default memo( DataViewsPagination );\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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