@wordpress/dataviews 14.2.1-next.v.202605131032.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/build/components/dataform-controls/date.cjs.map +3 -3
- package/build/components/dataform-controls/datetime.cjs.map +2 -2
- package/build/components/dataform-controls/email.cjs.map +3 -3
- package/build/components/dataform-controls/telephone.cjs.map +3 -3
- package/build/components/dataform-controls/url.cjs.map +3 -3
- package/build/components/dataform-layouts/panel/summary-button.cjs +18 -1
- package/build/components/dataform-layouts/panel/summary-button.cjs.map +3 -3
- package/build/components/dataform-layouts/panel/utils/get-label-content.cjs +17 -4
- package/build/components/dataform-layouts/panel/utils/get-label-content.cjs.map +3 -3
- package/build/components/dataviews-context/index.cjs.map +2 -2
- package/build/components/dataviews-filters/filter.cjs +86 -80
- package/build/components/dataviews-filters/filter.cjs.map +3 -3
- package/build/components/dataviews-filters/search-widget.cjs.map +3 -3
- package/build/components/dataviews-layouts/grid/composite-grid.cjs +10 -2
- package/build/components/dataviews-layouts/grid/composite-grid.cjs.map +2 -2
- package/build/components/dataviews-layouts/picker-table/index.cjs +8 -0
- package/build/components/dataviews-layouts/picker-table/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/table/column-header-menu.cjs.map +3 -3
- package/build/components/dataviews-layouts/table/use-scroll-state.cjs.map +1 -1
- package/build/components/dataviews-layouts/utils/item-click-wrapper.cjs.map +2 -2
- package/build/components/dataviews-view-config/properties-section.cjs.map +3 -3
- package/build/hooks/use-form-validity.cjs.map +1 -1
- package/build-module/components/dataform-controls/date.mjs +2 -2
- package/build-module/components/dataform-controls/date.mjs.map +2 -2
- package/build-module/components/dataform-controls/datetime.mjs.map +2 -2
- package/build-module/components/dataform-controls/email.mjs +2 -2
- package/build-module/components/dataform-controls/email.mjs.map +2 -2
- package/build-module/components/dataform-controls/telephone.mjs +2 -2
- package/build-module/components/dataform-controls/telephone.mjs.map +2 -2
- package/build-module/components/dataform-controls/url.mjs +2 -2
- package/build-module/components/dataform-controls/url.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/summary-button.mjs +19 -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 +18 -5
- package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs.map +2 -2
- package/build-module/components/dataviews-context/index.mjs.map +2 -2
- package/build-module/components/dataviews-filters/filter.mjs +88 -83
- package/build-module/components/dataviews-filters/filter.mjs.map +2 -2
- package/build-module/components/dataviews-filters/search-widget.mjs +3 -3
- package/build-module/components/dataviews-filters/search-widget.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs +11 -4
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/picker-table/index.mjs +8 -0
- package/build-module/components/dataviews-layouts/picker-table/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/column-header-menu.mjs +5 -5
- package/build-module/components/dataviews-layouts/table/column-header-menu.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/use-scroll-state.mjs.map +1 -1
- package/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs.map +2 -2
- package/build-module/components/dataviews-view-config/properties-section.mjs +2 -2
- package/build-module/components/dataviews-view-config/properties-section.mjs.map +2 -2
- package/build-module/hooks/use-form-validity.mjs.map +1 -1
- package/build-style/style-rtl.css +395 -377
- package/build-style/style.css +395 -377
- 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-context/index.d.ts +2 -2
- package/build-types/components/dataviews-context/index.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-layouts/picker-table/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts +9 -5
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/utils/item-click-wrapper.d.ts.map +1 -1
- package/build-types/dataviews/stories/free-composition.d.ts.map +1 -1
- package/build-wp/index.js +3298 -1396
- package/package.json +18 -18
- package/src/components/dataform-controls/date.tsx +2 -2
- package/src/components/dataform-controls/datetime.tsx +1 -1
- package/src/components/dataform-controls/email.tsx +2 -2
- package/src/components/dataform-controls/style.scss +2 -4
- package/src/components/dataform-controls/telephone.tsx +2 -2
- package/src/components/dataform-controls/url.tsx +2 -2
- package/src/components/dataform-layouts/card/style.scss +4 -7
- package/src/components/dataform-layouts/details/style.scss +2 -4
- package/src/components/dataform-layouts/panel/style.scss +41 -21
- package/src/components/dataform-layouts/panel/summary-button.tsx +17 -6
- package/src/components/dataform-layouts/panel/utils/get-label-content.tsx +15 -7
- package/src/components/dataform-layouts/regular/style.scss +5 -8
- package/src/components/dataviews-bulk-actions/style.scss +2 -6
- package/src/components/dataviews-context/index.ts +2 -4
- package/src/components/dataviews-filters/filter.tsx +93 -77
- package/src/components/dataviews-filters/search-widget.tsx +3 -3
- package/src/components/dataviews-filters/style.scss +93 -95
- package/src/components/dataviews-footer/style.scss +4 -6
- package/src/components/dataviews-item-actions/style.scss +1 -3
- package/src/components/dataviews-layouts/activity/style.scss +39 -41
- package/src/components/dataviews-layouts/grid/composite-grid.tsx +15 -8
- package/src/components/dataviews-layouts/grid/style.scss +46 -50
- package/src/components/dataviews-layouts/list/style.scss +61 -59
- package/src/components/dataviews-layouts/picker-grid/style.scss +33 -37
- package/src/components/dataviews-layouts/picker-table/index.tsx +15 -0
- package/src/components/dataviews-layouts/picker-table/style.scss +5 -8
- package/src/components/dataviews-layouts/table/column-header-menu.tsx +5 -5
- package/src/components/dataviews-layouts/table/style.scss +44 -46
- package/src/components/dataviews-layouts/table/use-scroll-state.ts +6 -6
- package/src/components/dataviews-layouts/utils/grid-items.scss +4 -6
- package/src/components/dataviews-layouts/utils/item-click-wrapper.tsx +3 -1
- package/src/components/dataviews-pagination/style.scss +2 -3
- package/src/components/dataviews-picker-footer/style.scss +1 -3
- package/src/components/dataviews-selection-checkbox/style.scss +0 -1
- package/src/components/dataviews-view-config/properties-section.tsx +2 -2
- package/src/components/dataviews-view-config/style.scss +8 -11
- package/src/dataviews/stories/free-composition.tsx +3 -1
- package/src/dataviews/style.scss +27 -18
- package/src/dataviews-picker/stories/index.story.tsx +2 -0
- package/src/field-types/stories/index.story.tsx +2 -2
- package/src/hooks/use-form-validity.ts +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataviews-layouts/picker-table/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Spinner, Composite } from '@wordpress/components';\nimport {\n\tuseContext,\n\tuseEffect,\n\tuseId,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../../dataviews-context';\nimport DataViewsSelectionCheckbox from '../../dataviews-selection-checkbox';\nimport { useIsMultiselectPicker } from '../../dataviews-picker-footer';\nimport { BulkSelectionCheckbox } from '../../dataviews-bulk-actions';\nimport { sortValues } from '../../../constants';\nimport type {\n\tNormalizedField,\n\tViewPickerTable as ViewPickerTableType,\n\tViewPickerTableProps,\n} from '../../../types';\nimport type { SetSelection } from '../../../types/private';\nimport ColumnHeaderMenu from '../table/column-header-menu';\nimport ColumnPrimary from '../table/column-primary';\nimport getDataByGroup from '../utils/get-data-by-group';\nimport { useIntersectionObserver } from '../utils/use-infinite-scroll';\n\ninterface TableColumnFieldProps< Item > {\n\tfields: NormalizedField< Item >[];\n\tcolumn: string;\n\titem: Item;\n\talign?: 'start' | 'center' | 'end';\n}\n\ninterface TableRowProps< Item > {\n\titem: Item;\n\tfields: NormalizedField< Item >[];\n\tid: string;\n\tview: ViewPickerTableType;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tselection: string[];\n\tgetItemId: ( item: Item ) => string;\n\tonChangeSelection: SetSelection;\n\tmultiselect: boolean;\n\tposinset?: number;\n}\n\nfunction TableColumnField< Item >( {\n\titem,\n\tfields,\n\tcolumn,\n\talign,\n}: TableColumnFieldProps< Item > ) {\n\tconst field = fields.find( ( f ) => f.id === column );\n\n\tif ( ! field ) {\n\t\treturn null;\n\t}\n\n\tconst className = clsx( 'dataviews-view-table__cell-content-wrapper', {\n\t\t'dataviews-view-table__cell-align-end': align === 'end',\n\t\t'dataviews-view-table__cell-align-center': align === 'center',\n\t} );\n\n\treturn (\n\t\t<div className={ className }>\n\t\t\t<field.render item={ item } field={ field } />\n\t\t</div>\n\t);\n}\n\nfunction TableRow< Item >( {\n\titem,\n\tfields,\n\tid,\n\tview,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tselection,\n\tgetItemId,\n\tonChangeSelection,\n\tmultiselect,\n\tposinset,\n}: TableRowProps< Item > ) {\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\n\tconst isSelected = selection.includes( id );\n\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst elementRef = useRef< HTMLButtonElement >( null );\n\n\tuseIntersectionObserver( elementRef, posinset );\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst handleMouseEnter = () => {\n\t\tsetIsHovered( true );\n\t};\n\tconst handleMouseLeave = () => {\n\t\tsetIsHovered( false );\n\t};\n\n\tconst columns = view.fields ?? [];\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\n\treturn (\n\t\t<Composite.Item\n\t\t\tkey={ id }\n\t\t\tref={ elementRef }\n\t\t\trender={ ( { children, ...props } ) => (\n\t\t\t\t<tr\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-table__row', {\n\t\t\t\t\t\t'is-selected': isSelected,\n\t\t\t\t\t\t'is-hovered': isHovered,\n\t\t\t\t\t} ) }\n\t\t\t\t\tonMouseEnter={ handleMouseEnter }\n\t\t\t\t\tonMouseLeave={ handleMouseLeave }\n\t\t\t\t\tchildren={ children }\n\t\t\t\t\t{ ...props }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\taria-selected={ isSelected }\n\t\t\taria-setsize={ paginationInfo.totalItems || undefined }\n\t\t\taria-posinset={ posinset }\n\t\t\trole={ infiniteScrollEnabled ? 'article' : 'option' }\n\t\t\tonClick={ () => {\n\t\t\t\t// Toggle in/out of selection array\n\t\t\t\tif ( isSelected ) {\n\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\tselection.filter( ( itemId ) => id !== itemId )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconst newSelection = multiselect\n\t\t\t\t\t\t? [ ...selection, id ]\n\t\t\t\t\t\t: [ id ];\n\t\t\t\t\tonChangeSelection( newSelection );\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t<td\n\t\t\t\tclassName=\"dataviews-view-table__checkbox-column\"\n\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\trole=\"presentation\"\n\t\t\t>\n\t\t\t\t<div className=\"dataviews-view-table__cell-content-wrapper\">\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={ false }\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</td>\n\n\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t<td\n\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\t\trole=\"presentation\"\n\t\t\t\t>\n\t\t\t\t\t<ColumnPrimary\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\ttitleField={ showTitle ? titleField : undefined }\n\t\t\t\t\t\tmediaField={ showMedia ? mediaField : undefined }\n\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\tshowDescription ? descriptionField : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisItemClickable={ () => false }\n\t\t\t\t\t/>\n\t\t\t\t</td>\n\t\t\t) }\n\t\t\t{ columns.map( ( column: string ) => {\n\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\n\t\t\t\treturn (\n\t\t\t\t\t<td\n\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<TableColumnField\n\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tcolumn={ column }\n\t\t\t\t\t\t\talign={ align }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</td>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Composite.Item>\n\t);\n}\n\nfunction ViewPickerTable< Item >( {\n\tactions,\n\tdata,\n\tfields,\n\tgetItemId,\n\tisLoading = false,\n\tonChangeView,\n\tonChangeSelection,\n\tselection,\n\tsetOpenedFilter,\n\tview,\n\tclassName,\n\tempty,\n}: ViewPickerTableProps< Item > ) {\n\tconst headerMenuRefs = useRef<\n\t\tMap< string, { node: HTMLButtonElement; fallback: string } >\n\t>( new Map() );\n\tconst headerMenuToFocusRef = useRef< HTMLButtonElement >( undefined );\n\tconst [ nextHeaderMenuToFocus, setNextHeaderMenuToFocus ] =\n\t\tuseState< HTMLButtonElement >();\n\tconst isMultiselect = useIsMultiselectPicker( actions ) ?? false;\n\n\tuseEffect( () => {\n\t\tif ( headerMenuToFocusRef.current ) {\n\t\t\theaderMenuToFocusRef.current.focus();\n\t\t\theaderMenuToFocusRef.current = undefined;\n\t\t}\n\t} );\n\n\tconst groupField = view.groupBy?.field\n\t\t? fields.find( ( f ) => f.id === view.groupBy?.field )\n\t\t: null;\n\tconst dataByGroup = groupField ? getDataByGroup( data, groupField ) : null;\n\tconst isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup;\n\n\tconst tableNoticeId = useId();\n\n\tif ( nextHeaderMenuToFocus ) {\n\t\t// If we need to force focus, we short-circuit rendering here\n\t\t// to prevent any additional work while we handle that.\n\t\t// Clearing out the focus directive is necessary to make sure\n\t\t// future renders don't cause unexpected focus jumps.\n\t\theaderMenuToFocusRef.current = nextHeaderMenuToFocus;\n\t\tsetNextHeaderMenuToFocus( undefined );\n\t\treturn;\n\t}\n\n\tconst onHide = ( field: NormalizedField< Item > ) => {\n\t\tconst hidden = headerMenuRefs.current.get( field.id );\n\t\tconst fallback = hidden\n\t\t\t? headerMenuRefs.current.get( hidden.fallback )\n\t\t\t: undefined;\n\t\tsetNextHeaderMenuToFocus( fallback?.node );\n\t};\n\n\tconst hasData = !! data?.length;\n\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\n\tconst { showTitle = true, showMedia = true, showDescription = true } = view;\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\tconst columns = view.fields ?? [];\n\tconst headerMenuRef =\n\t\t( column: string, index: number ) => ( node: HTMLButtonElement ) => {\n\t\t\tif ( node ) {\n\t\t\t\theaderMenuRefs.current.set( column, {\n\t\t\t\t\tnode,\n\t\t\t\t\tfallback: columns[ index > 0 ? index - 1 : 1 ],\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\theaderMenuRefs.current.delete( column );\n\t\t\t}\n\t\t};\n\n\treturn (\n\t\t<>\n\t\t\t<table\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'dataviews-view-table',\n\t\t\t\t\t'dataviews-view-picker-table',\n\t\t\t\t\tclassName,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\taria-busy={ isLoading }\n\t\t\t\taria-describedby={ tableNoticeId }\n\t\t\t\trole={ isInfiniteScroll ? 'feed' : 'listbox' }\n\t\t\t>\n\t\t\t\t<thead role=\"presentation\">\n\t\t\t\t\t<tr\n\t\t\t\t\t\tclassName=\"dataviews-view-table__row\"\n\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<th className=\"dataviews-view-table__checkbox-column\">\n\t\t\t\t\t\t\t{ isMultiselect && (\n\t\t\t\t\t\t\t\t<BulkSelectionCheckbox\n\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\tdisableSelectAll={ isInfiniteScroll }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</th>\n\t\t\t\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t\t\t\t<th>\n\t\t\t\t\t\t\t\t{ titleField && (\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef(\n\t\t\t\t\t\t\t\t\t\t\ttitleField.id,\n\t\t\t\t\t\t\t\t\t\t\t0\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ titleField.id }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={ false }\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</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ columns.map( ( column, index ) => {\n\t\t\t\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t\t\t\t\ttextAlign: align,\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taria-sort={\n\t\t\t\t\t\t\t\t\t\tview.sort?.direction &&\n\t\t\t\t\t\t\t\t\t\tview.sort?.field === column\n\t\t\t\t\t\t\t\t\t\t\t? sortValues[ view.sort.direction ]\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tscope=\"col\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef( column, index ) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ column }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={\n\t\t\t\t\t\t\t\t\t\t\tview.layout?.enableMoving ?? true\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</th>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</tr>\n\t\t\t\t</thead>\n\t\t\t\t{ /* Render grouped data if groupBy is specified */ }\n\t\t\t\t{ hasData && groupField && dataByGroup ? (\n\t\t\t\t\tArray.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<Composite\n\t\t\t\t\t\t\t\tkey={ `group-${ groupName }` }\n\t\t\t\t\t\t\t\tvirtualFocus\n\t\t\t\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\t\t\t\trender={ <tbody role=\"group\" /> }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<tr\n\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__group-header-row\"\n\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\t\t\tcolSpan={\n\t\t\t\t\t\t\t\t\t\t\tcolumns.length +\n\t\t\t\t\t\t\t\t\t\t\t( hasPrimaryColumn ? 1 : 0 ) +\n\t\t\t\t\t\t\t\t\t\t\t1\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__group-header-cell\"\n\t\t\t\t\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ view.groupBy?.showLabel === false\n\t\t\t\t\t\t\t\t\t\t\t? groupName\n\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\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\t__( '%1$s: %2$s' ),\n\t\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\t\tgroupName\n\t\t\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item, index ) => (\n\t\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tid={\n\t\t\t\t\t\t\t\t\t\t\tgetItemId( item ) ||\n\t\t\t\t\t\t\t\t\t\t\tindex.toString()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\t\tmultiselect={ isMultiselect }\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>\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) : (\n\t\t\t\t\t<Composite\n\t\t\t\t\t\trender={ <tbody role=\"presentation\" /> }\n\t\t\t\t\t\tvirtualFocus\n\t\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasData &&\n\t\t\t\t\t\t\tdata.map( ( item, index ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId( item );\n\t\t\t\t\t\t\t\t// Use position from item for accessibility in infinite scroll mode.\n\t\t\t\t\t\t\t\tconst posinset = ( item as any ).position;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\t\tkey={ itemId }\n\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tid={ itemId || index.toString() }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\t\tmultiselect={ isMultiselect }\n\t\t\t\t\t\t\t\t\t\tposinset={ posinset }\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</Composite>\n\t\t\t\t) }\n\t\t\t</table>\n\t\t\t<div\n\t\t\t\tclassName={ clsx( {\n\t\t\t\t\t'dataviews-loading': isLoading,\n\t\t\t\t\t'dataviews-no-results': ! hasData && ! isLoading,\n\t\t\t\t} ) }\n\t\t\t\tid={ tableNoticeId }\n\t\t\t>\n\t\t\t\t{ ! hasData &&\n\t\t\t\t\t( isLoading ? (\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</p>\n\t\t\t\t\t) : (\n\t\t\t\t\t\tempty\n\t\t\t\t\t) ) }\n\t\t\t\t{ hasData && isLoading && (\n\t\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default ViewPickerTable;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,kBAA4B;AAC5B,wBAAmC;AACnC,qBAMO;AAKP,+BAA6B;AAC7B,0CAAuC;AACvC,qCAAuC;AACvC,oCAAsC;AACtC,uBAA2B;AAO3B,gCAA6B;AAC7B,4BAA0B;AAC1B,+BAA2B;AAC3B,iCAAwC;AA2CrC;AAnBH,SAAS,iBAA0B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,QAAQ,OAAO,KAAM,CAAE,MAAO,EAAE,OAAO,MAAO;AAEpD,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,gBAAY,YAAAA,SAAM,8CAA8C;AAAA,IACrE,wCAAwC,UAAU;AAAA,IAClD,2CAA2C,UAAU;AAAA,EACtD,CAAE;AAEF,SACC,4CAAC,SAAI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,UAC/C;AAAA,QACD,OAAO;AACN,gBAAM,eAAe,cAClB,CAAE,GAAG,WAAW,EAAG,IACnB,CAAE,EAAG;AACR,4BAAmB,YAAa;AAAA,QACjC;AAAA,MACD;AAAA,MAEA;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YAEV,MAAK;AAAA,YAEL,sDAAC,SAAI,WAAU,8CACd;AAAA,cAAC,oCAAAE;AAAA,cAAA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA,UAAW;AAAA,gBACX,eAAW;AAAA,gBACX,UAAW;AAAA;AAAA,YACZ,GACD;AAAA;AAAA,QACD;AAAA,QAEE,oBACD;AAAA,UAAC;AAAA;AAAA,YAEA,MAAK;AAAA,YAEL;AAAA,cAAC,sBAAAC;AAAA,cAAA;AAAA,gBACA;AAAA,gBACA,YAAa,YAAY,aAAa;AAAA,gBACtC,YAAa,YAAY,aAAa;AAAA,gBACtC,kBACC,kBAAkB,mBAAmB;AAAA,gBAEtC,iBAAkB,MAAM;AAAA;AAAA,YACzB;AAAA;AAAA,QACD;AAAA,QAEC,QAAQ,IAAK,CAAE,WAAoB;AAEpC,gBAAM,EAAE,OAAO,UAAU,UAAU,MAAM,IACxC,KAAK,QAAQ,SAAU,MAAO,KAAK,CAAC;AAErC,iBACC;AAAA,YAAC;AAAA;AAAA,cAEA,OAAQ;AAAA,gBACP;AAAA,gBACA;AAAA,gBACA;AAAA,cACD;AAAA,cAEA,MAAK;AAAA,cAEL;AAAA,gBAAC;AAAA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA;AAAA,cACD;AAAA;AAAA,YAdM;AAAA,UAeP;AAAA,QAEF,CAAE;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Spinner, Composite } from '@wordpress/components';\nimport {\n\tuseContext,\n\tuseEffect,\n\tuseId,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../../dataviews-context';\nimport DataViewsSelectionCheckbox from '../../dataviews-selection-checkbox';\nimport { useIsMultiselectPicker } from '../../dataviews-picker-footer';\nimport { BulkSelectionCheckbox } from '../../dataviews-bulk-actions';\nimport { sortValues } from '../../../constants';\nimport type {\n\tNormalizedField,\n\tViewPickerTable as ViewPickerTableType,\n\tViewPickerTableProps,\n} from '../../../types';\nimport type { SetSelection } from '../../../types/private';\nimport ColumnHeaderMenu from '../table/column-header-menu';\nimport ColumnPrimary from '../table/column-primary';\nimport getDataByGroup from '../utils/get-data-by-group';\nimport { useIntersectionObserver } from '../utils/use-infinite-scroll';\n\ninterface TableColumnFieldProps< Item > {\n\tfields: NormalizedField< Item >[];\n\tcolumn: string;\n\titem: Item;\n\talign?: 'start' | 'center' | 'end';\n}\n\ninterface TableRowProps< Item > {\n\titem: Item;\n\tfields: NormalizedField< Item >[];\n\tid: string;\n\tview: ViewPickerTableType;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tselection: string[];\n\tgetItemId: ( item: Item ) => string;\n\tonChangeSelection: SetSelection;\n\tmultiselect: boolean;\n\tposinset?: number;\n}\n\nfunction TableColumnField< Item >( {\n\titem,\n\tfields,\n\tcolumn,\n\talign,\n}: TableColumnFieldProps< Item > ) {\n\tconst field = fields.find( ( f ) => f.id === column );\n\n\tif ( ! field ) {\n\t\treturn null;\n\t}\n\n\tconst className = clsx( 'dataviews-view-table__cell-content-wrapper', {\n\t\t'dataviews-view-table__cell-align-end': align === 'end',\n\t\t'dataviews-view-table__cell-align-center': align === 'center',\n\t} );\n\n\treturn (\n\t\t<div className={ className }>\n\t\t\t<field.render item={ item } field={ field } />\n\t\t</div>\n\t);\n}\n\nfunction TableRow< Item >( {\n\titem,\n\tfields,\n\tid,\n\tview,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tselection,\n\tgetItemId,\n\tonChangeSelection,\n\tmultiselect,\n\tposinset,\n}: TableRowProps< Item > ) {\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\n\tconst isSelected = selection.includes( id );\n\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst elementRef = useRef< HTMLButtonElement >( null );\n\n\tuseIntersectionObserver( elementRef, posinset );\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst handleMouseEnter = () => {\n\t\tsetIsHovered( true );\n\t};\n\tconst handleMouseLeave = () => {\n\t\tsetIsHovered( false );\n\t};\n\n\tconst columns = view.fields ?? [];\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\n\treturn (\n\t\t<Composite.Item\n\t\t\tkey={ id }\n\t\t\tref={ elementRef }\n\t\t\trender={ ( { children, ...props } ) => (\n\t\t\t\t<tr\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-table__row', {\n\t\t\t\t\t\t'is-selected': isSelected,\n\t\t\t\t\t\t'is-hovered': isHovered,\n\t\t\t\t\t} ) }\n\t\t\t\t\tonMouseEnter={ handleMouseEnter }\n\t\t\t\t\tonMouseLeave={ handleMouseLeave }\n\t\t\t\t\tchildren={ children }\n\t\t\t\t\t{ ...props }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\taria-selected={ isSelected }\n\t\t\taria-setsize={ paginationInfo.totalItems || undefined }\n\t\t\taria-posinset={ posinset }\n\t\t\trole={ infiniteScrollEnabled ? 'article' : 'option' }\n\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\tif ( event.button !== 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Pre-focus the Composite container (parent `tbody`) so that\n\t\t\t\t// when the row is focused on click, Ariakit sees the focus\n\t\t\t\t// coming from within the Composite and uses `focusSilently`\n\t\t\t\t// (which passes `preventScroll: true`). Without this, the\n\t\t\t\t// first focus into the Composite scrolls the active row\n\t\t\t\t// under the sticky table header, which also causes the click\n\t\t\t\t// to land on a different element than the original target.\n\t\t\t\tevent.currentTarget.parentElement?.focus( {\n\t\t\t\t\tpreventScroll: true,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tonClick={ () => {\n\t\t\t\t// Toggle in/out of selection array\n\t\t\t\tif ( isSelected ) {\n\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\tselection.filter( ( itemId ) => id !== itemId )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tconst newSelection = multiselect\n\t\t\t\t\t\t? [ ...selection, id ]\n\t\t\t\t\t\t: [ id ];\n\t\t\t\t\tonChangeSelection( newSelection );\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t<td\n\t\t\t\tclassName=\"dataviews-view-table__checkbox-column\"\n\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\trole=\"presentation\"\n\t\t\t>\n\t\t\t\t<div className=\"dataviews-view-table__cell-content-wrapper\">\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={ false }\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</td>\n\n\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t<td\n\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\t\trole=\"presentation\"\n\t\t\t\t>\n\t\t\t\t\t<ColumnPrimary\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\ttitleField={ showTitle ? titleField : undefined }\n\t\t\t\t\t\tmediaField={ showMedia ? mediaField : undefined }\n\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\tshowDescription ? descriptionField : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisItemClickable={ () => false }\n\t\t\t\t\t/>\n\t\t\t\t</td>\n\t\t\t) }\n\t\t\t{ columns.map( ( column: string ) => {\n\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\n\t\t\t\treturn (\n\t\t\t\t\t<td\n\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<TableColumnField\n\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tcolumn={ column }\n\t\t\t\t\t\t\talign={ align }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</td>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Composite.Item>\n\t);\n}\n\nfunction ViewPickerTable< Item >( {\n\tactions,\n\tdata,\n\tfields,\n\tgetItemId,\n\tisLoading = false,\n\tonChangeView,\n\tonChangeSelection,\n\tselection,\n\tsetOpenedFilter,\n\tview,\n\tclassName,\n\tempty,\n}: ViewPickerTableProps< Item > ) {\n\tconst headerMenuRefs = useRef<\n\t\tMap< string, { node: HTMLButtonElement; fallback: string } >\n\t>( new Map() );\n\tconst headerMenuToFocusRef = useRef< HTMLButtonElement >( undefined );\n\tconst [ nextHeaderMenuToFocus, setNextHeaderMenuToFocus ] =\n\t\tuseState< HTMLButtonElement >();\n\tconst isMultiselect = useIsMultiselectPicker( actions ) ?? false;\n\n\tuseEffect( () => {\n\t\tif ( headerMenuToFocusRef.current ) {\n\t\t\theaderMenuToFocusRef.current.focus();\n\t\t\theaderMenuToFocusRef.current = undefined;\n\t\t}\n\t} );\n\n\tconst groupField = view.groupBy?.field\n\t\t? fields.find( ( f ) => f.id === view.groupBy?.field )\n\t\t: null;\n\tconst dataByGroup = groupField ? getDataByGroup( data, groupField ) : null;\n\tconst isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup;\n\n\tconst tableNoticeId = useId();\n\n\tif ( nextHeaderMenuToFocus ) {\n\t\t// If we need to force focus, we short-circuit rendering here\n\t\t// to prevent any additional work while we handle that.\n\t\t// Clearing out the focus directive is necessary to make sure\n\t\t// future renders don't cause unexpected focus jumps.\n\t\theaderMenuToFocusRef.current = nextHeaderMenuToFocus;\n\t\tsetNextHeaderMenuToFocus( undefined );\n\t\treturn;\n\t}\n\n\tconst onHide = ( field: NormalizedField< Item > ) => {\n\t\tconst hidden = headerMenuRefs.current.get( field.id );\n\t\tconst fallback = hidden\n\t\t\t? headerMenuRefs.current.get( hidden.fallback )\n\t\t\t: undefined;\n\t\tsetNextHeaderMenuToFocus( fallback?.node );\n\t};\n\n\tconst hasData = !! data?.length;\n\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\n\tconst { showTitle = true, showMedia = true, showDescription = true } = view;\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\tconst columns = view.fields ?? [];\n\tconst headerMenuRef =\n\t\t( column: string, index: number ) => ( node: HTMLButtonElement ) => {\n\t\t\tif ( node ) {\n\t\t\t\theaderMenuRefs.current.set( column, {\n\t\t\t\t\tnode,\n\t\t\t\t\tfallback: columns[ index > 0 ? index - 1 : 1 ],\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\theaderMenuRefs.current.delete( column );\n\t\t\t}\n\t\t};\n\n\treturn (\n\t\t<>\n\t\t\t<table\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'dataviews-view-table',\n\t\t\t\t\t'dataviews-view-picker-table',\n\t\t\t\t\tclassName,\n\t\t\t\t\t{\n\t\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\taria-busy={ isLoading }\n\t\t\t\taria-describedby={ tableNoticeId }\n\t\t\t\trole={ isInfiniteScroll ? 'feed' : 'listbox' }\n\t\t\t>\n\t\t\t\t<thead role=\"presentation\">\n\t\t\t\t\t<tr\n\t\t\t\t\t\tclassName=\"dataviews-view-table__row\"\n\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<th className=\"dataviews-view-table__checkbox-column\">\n\t\t\t\t\t\t\t{ isMultiselect && (\n\t\t\t\t\t\t\t\t<BulkSelectionCheckbox\n\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\tdisableSelectAll={ isInfiniteScroll }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</th>\n\t\t\t\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t\t\t\t<th>\n\t\t\t\t\t\t\t\t{ titleField && (\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef(\n\t\t\t\t\t\t\t\t\t\t\ttitleField.id,\n\t\t\t\t\t\t\t\t\t\t\t0\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ titleField.id }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={ false }\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</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ columns.map( ( column, index ) => {\n\t\t\t\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t\t\t\t\ttextAlign: align,\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taria-sort={\n\t\t\t\t\t\t\t\t\t\tview.sort?.direction &&\n\t\t\t\t\t\t\t\t\t\tview.sort?.field === column\n\t\t\t\t\t\t\t\t\t\t\t? sortValues[ view.sort.direction ]\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tscope=\"col\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef( column, index ) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ column }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={\n\t\t\t\t\t\t\t\t\t\t\tview.layout?.enableMoving ?? true\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</th>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</tr>\n\t\t\t\t</thead>\n\t\t\t\t{ /* Render grouped data if groupBy is specified */ }\n\t\t\t\t{ hasData && groupField && dataByGroup ? (\n\t\t\t\t\tArray.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<Composite\n\t\t\t\t\t\t\t\tkey={ `group-${ groupName }` }\n\t\t\t\t\t\t\t\tvirtualFocus\n\t\t\t\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\t\t\t\trender={ <tbody role=\"group\" /> }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<tr\n\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__group-header-row\"\n\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\t\t\tcolSpan={\n\t\t\t\t\t\t\t\t\t\t\tcolumns.length +\n\t\t\t\t\t\t\t\t\t\t\t( hasPrimaryColumn ? 1 : 0 ) +\n\t\t\t\t\t\t\t\t\t\t\t1\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__group-header-cell\"\n\t\t\t\t\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role\n\t\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ view.groupBy?.showLabel === false\n\t\t\t\t\t\t\t\t\t\t\t? groupName\n\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\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\t__( '%1$s: %2$s' ),\n\t\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\t\tgroupName\n\t\t\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item, index ) => (\n\t\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tid={\n\t\t\t\t\t\t\t\t\t\t\tgetItemId( item ) ||\n\t\t\t\t\t\t\t\t\t\t\tindex.toString()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\t\tmultiselect={ isMultiselect }\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>\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) : (\n\t\t\t\t\t<Composite\n\t\t\t\t\t\trender={ <tbody role=\"presentation\" /> }\n\t\t\t\t\t\tvirtualFocus\n\t\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasData &&\n\t\t\t\t\t\t\tdata.map( ( item, index ) => {\n\t\t\t\t\t\t\t\tconst itemId = getItemId( item );\n\t\t\t\t\t\t\t\t// Use position from item for accessibility in infinite scroll mode.\n\t\t\t\t\t\t\t\tconst posinset = ( item as any ).position;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\t\tkey={ itemId }\n\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tid={ itemId || index.toString() }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\t\tmultiselect={ isMultiselect }\n\t\t\t\t\t\t\t\t\t\tposinset={ posinset }\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</Composite>\n\t\t\t\t) }\n\t\t\t</table>\n\t\t\t<div\n\t\t\t\tclassName={ clsx( {\n\t\t\t\t\t'dataviews-loading': isLoading,\n\t\t\t\t\t'dataviews-no-results': ! hasData && ! isLoading,\n\t\t\t\t} ) }\n\t\t\t\tid={ tableNoticeId }\n\t\t\t>\n\t\t\t\t{ ! hasData &&\n\t\t\t\t\t( isLoading ? (\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</p>\n\t\t\t\t\t) : (\n\t\t\t\t\t\tempty\n\t\t\t\t\t) ) }\n\t\t\t\t{ hasData && isLoading && (\n\t\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default ViewPickerTable;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,kBAA4B;AAC5B,wBAAmC;AACnC,qBAMO;AAKP,+BAA6B;AAC7B,0CAAuC;AACvC,qCAAuC;AACvC,oCAAsC;AACtC,uBAA2B;AAO3B,gCAA6B;AAC7B,4BAA0B;AAC1B,+BAA2B;AAC3B,iCAAwC;AA2CrC;AAnBH,SAAS,iBAA0B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,QAAQ,OAAO,KAAM,CAAE,MAAO,EAAE,OAAO,MAAO;AAEpD,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,gBAAY,YAAAA,SAAM,8CAA8C;AAAA,IACrE,wCAAwC,UAAU;AAAA,IAClD,2CAA2C,UAAU;AAAA,EACtD,CAAE;AAEF,SACC,4CAAC,SAAI,WACJ,sDAAC,MAAM,QAAN,EAAa,MAAc,OAAgB,GAC7C;AAEF;AAEA,SAAS,SAAkB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA2B;AAC1B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 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataviews-layouts/table/column-header-menu.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactNode, Ref, PropsWithoutRef, RefAttributes } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __, isRTL } from '@wordpress/i18n';\nimport { arrowLeft, arrowRight, unseen, funnel } from '@wordpress/icons';\nimport {\n\tButton,\n\tIcon,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { forwardRef, Children, Fragment, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport { SORTING_DIRECTIONS, sortArrows, sortLabels } from '../../../constants';\nimport type {\n\tNormalizedField,\n\tSortDirection,\n\tViewTable as ViewTableType,\n\tViewPickerTable as ViewPickerTableType,\n\tOperator,\n} from '../../../types';\nimport DataViewsContext from '../../dataviews-context';\nimport getHideableFields from '../../../utils/get-hideable-fields';\n\nconst { Menu } = unlock( componentsPrivateApis );\n\ninterface HeaderMenuProps< Item > {\n\tfieldId: string;\n\tview: ViewTableType | ViewPickerTableType;\n\tfields: NormalizedField< Item >[];\n\tonChangeView: ( view: ViewTableType | ViewPickerTableType ) => void;\n\tonHide: ( field: NormalizedField< Item > ) => void;\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tcanMove?: boolean;\n\tcanInsertLeft?: boolean;\n\tcanInsertRight?: boolean;\n}\n\nfunction WithMenuSeparators( { children }: { children: ReactNode } ) {\n\treturn Children.toArray( children )\n\t\t.filter( Boolean )\n\t\t.map( ( child, i ) => (\n\t\t\t<Fragment key={ i }>\n\t\t\t\t{ i > 0 && <Menu.Separator /> }\n\t\t\t\t{ child }\n\t\t\t</Fragment>\n\t\t) );\n}\n\nconst _HeaderMenu = forwardRef( function HeaderMenu< Item >(\n\t{\n\t\tfieldId,\n\t\tview,\n\t\tfields,\n\t\tonChangeView,\n\t\tonHide,\n\t\tsetOpenedFilter,\n\t\tcanMove = true,\n\t\tcanInsertLeft = true,\n\t\tcanInsertRight = true,\n\t}: HeaderMenuProps< Item >,\n\tref: Ref< HTMLButtonElement >\n) {\n\tconst visibleFieldIds = view.fields ?? [];\n\tconst index = visibleFieldIds?.indexOf( fieldId ) as number;\n\tconst isSorted = view.sort?.field === fieldId;\n\tlet isHidable = false;\n\tlet isSortable = false;\n\tlet canAddFilter = false;\n\tlet operators: Operator[] = [];\n\tconst field = fields.find( ( f ) => f.id === fieldId );\n\n\tconst { setIsShowingFilter } = useContext( DataViewsContext );\n\n\tif ( ! field ) {\n\t\t// No combined or regular field found.\n\t\treturn null;\n\t}\n\n\tisHidable = field.enableHiding !== false;\n\tisSortable = field.enableSorting !== false;\n\tconst header = field.header;\n\n\toperators = ( !! field.filterBy && field.filterBy?.operators ) || [];\n\n\t// Filter can be added if:\n\t//\n\t// 1. The field is not already part of a view's filters.\n\t// 2. The field has elements or Edit property.\n\t// 3. The field does not opt-out of filtering.\n\t// 4. The filter is not primary (if it is, it is already visible).\n\tcanAddFilter =\n\t\t! view.filters?.some( ( _filter ) => fieldId === _filter.field ) &&\n\t\t!! ( field.hasElements || field.Edit ) &&\n\t\tfield.filterBy !== false &&\n\t\t! field.filterBy?.isPrimary;\n\n\tif ( ! isSortable && ! canMove && ! isHidable && ! canAddFilter ) {\n\t\treturn header;\n\t}\n\n\tconst hiddenFields = getHideableFields( view, fields ).filter(\n\t\t( f ) => ! visibleFieldIds.includes( f.id )\n\t);\n\tconst canInsert =\n\t\t( canInsertLeft || canInsertRight ) && !! hiddenFields.length;\n\n\tconst isRtl = isRTL();\n\n\treturn (\n\t\t<Menu>\n\t\t\t<Menu.TriggerButton\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\tclassName=\"dataviews-view-table-header-button\"\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ header }\n\t\t\t\t{ view.sort && isSorted && (\n\t\t\t\t\t<span aria-hidden=\"true\">\n\t\t\t\t\t\t{ sortArrows[ view.sort.direction ] }\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t</Menu.TriggerButton>\n\t\t\t<Menu.Popover style={ { minWidth: '240px' } }>\n\t\t\t\t<WithMenuSeparators>\n\t\t\t\t\t{ isSortable && (\n\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t{ SORTING_DIRECTIONS.map(\n\t\t\t\t\t\t\t\t( direction: SortDirection ) => {\n\t\t\t\t\t\t\t\t\tconst isChecked =\n\t\t\t\t\t\t\t\t\t\tview.sort &&\n\t\t\t\t\t\t\t\t\t\tisSorted &&\n\t\t\t\t\t\t\t\t\t\tview.sort.direction === direction;\n\n\t\t\t\t\t\t\t\t\tconst value = `${ fieldId }-${ direction }`;\n\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<Menu.RadioItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ value }\n\t\t\t\t\t\t\t\t\t\t\t// All sorting radio items share the same name, so that\n\t\t\t\t\t\t\t\t\t\t\t// selecting a sorting option automatically deselects the\n\t\t\t\t\t\t\t\t\t\t\t// previously selected one, even if it is displayed in\n\t\t\t\t\t\t\t\t\t\t\t// another submenu. The field and direction are passed via\n\t\t\t\t\t\t\t\t\t\t\t// the `value` prop.\n\t\t\t\t\t\t\t\t\t\t\tname=\"view-table-sorting\"\n\t\t\t\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\t\t\t\tchecked={ isChecked }\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\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\t\tsort: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfield: fieldId,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdirection,\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\tshowLevels: false,\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t{ sortLabels[ direction ] }\n\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t</Menu.RadioItem>\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</Menu.Group>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canAddFilter && (\n\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\tprefix={ <Icon icon={ funnel } /> }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tsetOpenedFilter( fieldId );\n\t\t\t\t\t\t\t\t\tsetIsShowingFilter( true );\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\tfilters: [\n\t\t\t\t\t\t\t\t\t\t\t...( view.filters || [] ),\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tfield: fieldId,\n\t\t\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t\t\t\toperator: operators[ 0 ],\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t{ __( 'Add filter' ) }\n\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t</Menu.Group>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ( canMove || isHidable || canInsert ) && field && (\n\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t{ canMove && (\n\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\tprefix={ <Icon icon={ arrowLeft } /> }\n\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\tisRtl\n\t\t\t\t\t\t\t\t\t\t\t? index >=\n\t\t\t\t\t\t\t\t\t\t\t visibleFieldIds.length - 1\n\t\t\t\t\t\t\t\t\t\t\t: index < 1\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t// In RTL, moving left visually means moving right in the array\n\t\t\t\t\t\t\t\t\t\tconst targetIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t\t\t: index - 1;\n\t\t\t\t\t\t\t\t\t\tconst newFields = [\n\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds,\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\tnewFields.splice( index, 1 );\n\t\t\t\t\t\t\t\t\t\tnewFields.splice(\n\t\t\t\t\t\t\t\t\t\t\ttargetIndex,\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\tfieldId\n\t\t\t\t\t\t\t\t\t\t);\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\tfields: newFields,\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Move left' ) }\n\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ canMove && (\n\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\tprefix={ <Icon icon={ arrowRight } /> }\n\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\tisRtl\n\t\t\t\t\t\t\t\t\t\t\t? index < 1\n\t\t\t\t\t\t\t\t\t\t\t: index >=\n\t\t\t\t\t\t\t\t\t\t\t visibleFieldIds.length - 1\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t// In RTL, moving right visually means moving left in the array\n\t\t\t\t\t\t\t\t\t\tconst targetIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t? index - 1\n\t\t\t\t\t\t\t\t\t\t\t: index + 1;\n\t\t\t\t\t\t\t\t\t\tconst newFields = [\n\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds,\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\tnewFields.splice( index, 1 );\n\t\t\t\t\t\t\t\t\t\tnewFields.splice(\n\t\t\t\t\t\t\t\t\t\t\ttargetIndex,\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\tfieldId\n\t\t\t\t\t\t\t\t\t\t);\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\tfields: newFields,\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Move right' ) }\n\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ canInsertLeft && !! hiddenFields.length && (\n\t\t\t\t\t\t\t\t<Menu>\n\t\t\t\t\t\t\t\t\t<Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Insert left' ) }\n\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t</Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t\t\t\t{ hiddenFields.map( ( hiddenField ) => {\n\t\t\t\t\t\t\t\t\t\t\tconst insertIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t\t\t\t: index;\n\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey={ hiddenField.id }\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\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\t\t\t\tfields: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t\thiddenField.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t],\n\t\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} }\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\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ hiddenField.label }\n\t\t\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t</Menu.Item>\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</Menu.Popover>\n\t\t\t\t\t\t\t\t</Menu>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ canInsertRight && !! hiddenFields.length && (\n\t\t\t\t\t\t\t\t<Menu>\n\t\t\t\t\t\t\t\t\t<Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Insert right' ) }\n\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t</Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t\t\t\t{ hiddenFields.map( ( hiddenField ) => {\n\t\t\t\t\t\t\t\t\t\t\tconst insertIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t\t? index\n\t\t\t\t\t\t\t\t\t\t\t\t: index + 1;\n\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey={ hiddenField.id }\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\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\t\t\t\tfields: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t\thiddenField.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t],\n\t\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} }\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\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ hiddenField.label }\n\t\t\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t</Menu.Item>\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</Menu.Popover>\n\t\t\t\t\t\t\t\t</Menu>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ isHidable && field && (\n\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\tprefix={ <Icon icon={ unseen } /> }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonHide( field );\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\tfields: visibleFieldIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t\t( id ) => id !== fieldId\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Hide column' ) }\n\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Menu.Group>\n\t\t\t\t\t) }\n\t\t\t\t</WithMenuSeparators>\n\t\t\t</Menu.Popover>\n\t\t</Menu>\n\t);\n} );\n\n// @ts-expect-error Lift the `Item` type argument through the forwardRef.\nconst ColumnHeaderMenu: < Item >(\n\tprops: PropsWithoutRef< HeaderMenuProps< Item > > &\n\t\tRefAttributes< HTMLButtonElement >\n) => ReturnType< typeof _HeaderMenu > = _HeaderMenu;\n\nexport default ColumnHeaderMenu;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,kBAA0B;AAC1B,mBAAsD;AACtD,wBAIO;AACP,qBAA2D;AAK3D,yBAAuB;AACvB,uBAA2D;AAQ3D,+BAA6B;AAC7B,iCAA8B;AAoB3B;AAlBH,IAAM,EAAE,KAAK,QAAI,2BAAQ,kBAAAA,WAAsB;AAc/C,SAAS,mBAAoB,EAAE,SAAS,GAA6B;AACpE,SAAO,wBAAS,QAAS,QAAS,EAChC,OAAQ,OAAQ,EAChB,IAAK,CAAE,OAAO,MACd,6CAAC,2BACE;AAAA,QAAI,KAAK,4CAAC,KAAK,WAAL,EAAe;AAAA,IACzB;AAAA,OAFa,CAGhB,CACC;AACJ;AAEA,IAAM,kBAAc,2BAAY,SAAS,WACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,E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AAK,KAAK,SAAU,GACnC;AAAA;AAAA;AAAA,IAEF;AAAA,IACA,4CAAC,KAAK,SAAL,EAAa,OAAQ,EAAE,UAAU,QAAQ,GACzC,uDAAC,sBACE;AAAA,oBACD,4CAAC,KAAK,OAAL,EACE,8CAAmB;AAAA,QACpB,CAAE,cAA8B;AAC/B,gBAAM,YACL,KAAK,QACL,YACA,KAAK,KAAK,cAAc;AAEzB,gBAAM,QAAQ,GAAI,OAAQ,IAAK,SAAU;AAEzC,iBACC;AAAA,YAAC,KAAK;AAAA,YAAL;AAAA,cAOA,MAAK;AAAA,cACL;AAAA,cACA,SAAU;AAAA,cACV,UAAW,MAAM;AAChB,6BAAc;AAAA,kBACb,GAAG;AAAA,kBACH,MAAM;AAAA,oBACL,OAAO;AAAA,oBACP;AAAA,kBACD;AAAA,kBACA,YAAY;AAAA,gBACb,CAAE;AAAA,cACH;AAAA,cAEA,sDAAC,KAAK,WAAL,EACE,sCAAY,SAAU,GACzB;AAAA;AAAA,YAtBM;AAAA,UAuBP;AAAA,QAEF;AAAA,MACD,GACD;AAAA,MAEC,gBACD,4CAAC,KAAK,OAAL,EACA;AAAA,QAAC,KAAK;AAAA,QAAL;AAAA,UACA,QAAS,4CAAC,
|
|
6
|
-
"names": ["componentsPrivateApis", "DataViewsContext", "getHideableFields"]
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactNode, Ref, PropsWithoutRef, RefAttributes } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __, isRTL } from '@wordpress/i18n';\nimport { arrowLeft, arrowRight, unseen, funnel } from '@wordpress/icons';\nimport {\n\tButton,\n\tIcon as WCIcon,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { forwardRef, Children, Fragment, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport { SORTING_DIRECTIONS, sortArrows, sortLabels } from '../../../constants';\nimport type {\n\tNormalizedField,\n\tSortDirection,\n\tViewTable as ViewTableType,\n\tViewPickerTable as ViewPickerTableType,\n\tOperator,\n} from '../../../types';\nimport DataViewsContext from '../../dataviews-context';\nimport getHideableFields from '../../../utils/get-hideable-fields';\n\nconst { Menu } = unlock( componentsPrivateApis );\n\ninterface HeaderMenuProps< Item > {\n\tfieldId: string;\n\tview: ViewTableType | ViewPickerTableType;\n\tfields: NormalizedField< Item >[];\n\tonChangeView: ( view: ViewTableType | ViewPickerTableType ) => void;\n\tonHide: ( field: NormalizedField< Item > ) => void;\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tcanMove?: boolean;\n\tcanInsertLeft?: boolean;\n\tcanInsertRight?: boolean;\n}\n\nfunction WithMenuSeparators( { children }: { children: ReactNode } ) {\n\treturn Children.toArray( children )\n\t\t.filter( Boolean )\n\t\t.map( ( child, i ) => (\n\t\t\t<Fragment key={ i }>\n\t\t\t\t{ i > 0 && <Menu.Separator /> }\n\t\t\t\t{ child }\n\t\t\t</Fragment>\n\t\t) );\n}\n\nconst _HeaderMenu = forwardRef( function HeaderMenu< Item >(\n\t{\n\t\tfieldId,\n\t\tview,\n\t\tfields,\n\t\tonChangeView,\n\t\tonHide,\n\t\tsetOpenedFilter,\n\t\tcanMove = true,\n\t\tcanInsertLeft = true,\n\t\tcanInsertRight = true,\n\t}: HeaderMenuProps< Item >,\n\tref: Ref< HTMLButtonElement >\n) {\n\tconst visibleFieldIds = view.fields ?? [];\n\tconst index = visibleFieldIds?.indexOf( fieldId ) as number;\n\tconst isSorted = view.sort?.field === fieldId;\n\tlet isHidable = false;\n\tlet isSortable = false;\n\tlet canAddFilter = false;\n\tlet operators: Operator[] = [];\n\tconst field = fields.find( ( f ) => f.id === fieldId );\n\n\tconst { setIsShowingFilter } = useContext( DataViewsContext );\n\n\tif ( ! field ) {\n\t\t// No combined or regular field found.\n\t\treturn null;\n\t}\n\n\tisHidable = field.enableHiding !== false;\n\tisSortable = field.enableSorting !== false;\n\tconst header = field.header;\n\n\toperators = ( !! field.filterBy && field.filterBy?.operators ) || [];\n\n\t// Filter can be added if:\n\t//\n\t// 1. The field is not already part of a view's filters.\n\t// 2. The field has elements or Edit property.\n\t// 3. The field does not opt-out of filtering.\n\t// 4. The filter is not primary (if it is, it is already visible).\n\tcanAddFilter =\n\t\t! view.filters?.some( ( _filter ) => fieldId === _filter.field ) &&\n\t\t!! ( field.hasElements || field.Edit ) &&\n\t\tfield.filterBy !== false &&\n\t\t! field.filterBy?.isPrimary;\n\n\tif ( ! isSortable && ! canMove && ! isHidable && ! canAddFilter ) {\n\t\treturn header;\n\t}\n\n\tconst hiddenFields = getHideableFields( view, fields ).filter(\n\t\t( f ) => ! visibleFieldIds.includes( f.id )\n\t);\n\tconst canInsert =\n\t\t( canInsertLeft || canInsertRight ) && !! hiddenFields.length;\n\n\tconst isRtl = isRTL();\n\n\treturn (\n\t\t<Menu>\n\t\t\t<Menu.TriggerButton\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\tclassName=\"dataviews-view-table-header-button\"\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ header }\n\t\t\t\t{ view.sort && isSorted && (\n\t\t\t\t\t<span aria-hidden=\"true\">\n\t\t\t\t\t\t{ sortArrows[ view.sort.direction ] }\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t</Menu.TriggerButton>\n\t\t\t<Menu.Popover style={ { minWidth: '240px' } }>\n\t\t\t\t<WithMenuSeparators>\n\t\t\t\t\t{ isSortable && (\n\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t{ SORTING_DIRECTIONS.map(\n\t\t\t\t\t\t\t\t( direction: SortDirection ) => {\n\t\t\t\t\t\t\t\t\tconst isChecked =\n\t\t\t\t\t\t\t\t\t\tview.sort &&\n\t\t\t\t\t\t\t\t\t\tisSorted &&\n\t\t\t\t\t\t\t\t\t\tview.sort.direction === direction;\n\n\t\t\t\t\t\t\t\t\tconst value = `${ fieldId }-${ direction }`;\n\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<Menu.RadioItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ value }\n\t\t\t\t\t\t\t\t\t\t\t// All sorting radio items share the same name, so that\n\t\t\t\t\t\t\t\t\t\t\t// selecting a sorting option automatically deselects the\n\t\t\t\t\t\t\t\t\t\t\t// previously selected one, even if it is displayed in\n\t\t\t\t\t\t\t\t\t\t\t// another submenu. The field and direction are passed via\n\t\t\t\t\t\t\t\t\t\t\t// the `value` prop.\n\t\t\t\t\t\t\t\t\t\t\tname=\"view-table-sorting\"\n\t\t\t\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\t\t\t\tchecked={ isChecked }\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\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\t\tsort: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfield: fieldId,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdirection,\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\tshowLevels: false,\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t{ sortLabels[ direction ] }\n\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t</Menu.RadioItem>\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</Menu.Group>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canAddFilter && (\n\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\tprefix={ <WCIcon icon={ funnel } /> }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tsetOpenedFilter( fieldId );\n\t\t\t\t\t\t\t\t\tsetIsShowingFilter( true );\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\tfilters: [\n\t\t\t\t\t\t\t\t\t\t\t...( view.filters || [] ),\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tfield: fieldId,\n\t\t\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t\t\t\toperator: operators[ 0 ],\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t{ __( 'Add filter' ) }\n\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t</Menu.Group>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ( canMove || isHidable || canInsert ) && field && (\n\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t{ canMove && (\n\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\tprefix={ <WCIcon icon={ arrowLeft } /> }\n\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\tisRtl\n\t\t\t\t\t\t\t\t\t\t\t? index >=\n\t\t\t\t\t\t\t\t\t\t\t visibleFieldIds.length - 1\n\t\t\t\t\t\t\t\t\t\t\t: index < 1\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t// In RTL, moving left visually means moving right in the array\n\t\t\t\t\t\t\t\t\t\tconst targetIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t\t\t: index - 1;\n\t\t\t\t\t\t\t\t\t\tconst newFields = [\n\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds,\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\tnewFields.splice( index, 1 );\n\t\t\t\t\t\t\t\t\t\tnewFields.splice(\n\t\t\t\t\t\t\t\t\t\t\ttargetIndex,\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\tfieldId\n\t\t\t\t\t\t\t\t\t\t);\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\tfields: newFields,\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Move left' ) }\n\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ canMove && (\n\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\tprefix={ <WCIcon icon={ arrowRight } /> }\n\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\tisRtl\n\t\t\t\t\t\t\t\t\t\t\t? index < 1\n\t\t\t\t\t\t\t\t\t\t\t: index >=\n\t\t\t\t\t\t\t\t\t\t\t visibleFieldIds.length - 1\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t// In RTL, moving right visually means moving left in the array\n\t\t\t\t\t\t\t\t\t\tconst targetIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t? index - 1\n\t\t\t\t\t\t\t\t\t\t\t: index + 1;\n\t\t\t\t\t\t\t\t\t\tconst newFields = [\n\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds,\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\tnewFields.splice( index, 1 );\n\t\t\t\t\t\t\t\t\t\tnewFields.splice(\n\t\t\t\t\t\t\t\t\t\t\ttargetIndex,\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\tfieldId\n\t\t\t\t\t\t\t\t\t\t);\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\tfields: newFields,\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Move right' ) }\n\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ canInsertLeft && !! hiddenFields.length && (\n\t\t\t\t\t\t\t\t<Menu>\n\t\t\t\t\t\t\t\t\t<Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Insert left' ) }\n\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t</Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t\t\t\t{ hiddenFields.map( ( hiddenField ) => {\n\t\t\t\t\t\t\t\t\t\t\tconst insertIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t\t\t\t: index;\n\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey={ hiddenField.id }\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\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\t\t\t\tfields: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t\thiddenField.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t],\n\t\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} }\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\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ hiddenField.label }\n\t\t\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t</Menu.Item>\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</Menu.Popover>\n\t\t\t\t\t\t\t\t</Menu>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ canInsertRight && !! hiddenFields.length && (\n\t\t\t\t\t\t\t\t<Menu>\n\t\t\t\t\t\t\t\t\t<Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Insert right' ) }\n\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t</Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t\t\t\t{ hiddenFields.map( ( hiddenField ) => {\n\t\t\t\t\t\t\t\t\t\t\tconst insertIndex = isRtl\n\t\t\t\t\t\t\t\t\t\t\t\t? index\n\t\t\t\t\t\t\t\t\t\t\t\t: index + 1;\n\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\t\t\t\t\tkey={ hiddenField.id }\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\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\t\t\t\tfields: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t\thiddenField.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t...visibleFieldIds.slice(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsertIndex\n\t\t\t\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\t\t],\n\t\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} }\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\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ hiddenField.label }\n\t\t\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t</Menu.Item>\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</Menu.Popover>\n\t\t\t\t\t\t\t\t</Menu>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ isHidable && field && (\n\t\t\t\t\t\t\t\t<Menu.Item\n\t\t\t\t\t\t\t\t\tprefix={ <WCIcon icon={ unseen } /> }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonHide( field );\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\tfields: visibleFieldIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t\t( id ) => id !== fieldId\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Hide column' ) }\n\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t</Menu.Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Menu.Group>\n\t\t\t\t\t) }\n\t\t\t\t</WithMenuSeparators>\n\t\t\t</Menu.Popover>\n\t\t</Menu>\n\t);\n} );\n\n// @ts-expect-error Lift the `Item` type argument through the forwardRef.\nconst ColumnHeaderMenu: < Item >(\n\tprops: PropsWithoutRef< HeaderMenuProps< Item > > &\n\t\tRefAttributes< HTMLButtonElement >\n) => ReturnType< typeof _HeaderMenu > = _HeaderMenu;\n\nexport default ColumnHeaderMenu;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,kBAA0B;AAC1B,mBAAsD;AACtD,wBAIO;AACP,qBAA2D;AAK3D,yBAAuB;AACvB,uBAA2D;AAQ3D,+BAA6B;AAC7B,iCAA8B;AAoB3B;AAlBH,IAAM,EAAE,KAAK,QAAI,2BAAQ,kBAAAA,WAAsB;AAc/C,SAAS,mBAAoB,EAAE,SAAS,GAA6B;AACpE,SAAO,wBAAS,QAAS,QAAS,EAChC,OAAQ,OAAQ,EAChB,IAAK,CAAE,OAAO,MACd,6CAAC,2BACE;AAAA,QAAI,KAAK,4CAAC,KAAK,WAAL,EAAe;AAAA,IACzB;AAAA,OAFa,CAGhB,CACC;AACJ;AAEA,IAAM,kBAAc,2BAAY,SAAS,WACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,iBAAiB;AAClB,GACA,KACC;AACD,QAAM,kBAAkB,KAAK,UAAU,CAAC;AACxC,QAAM,QAAQ,iBAAiB,QAAS,OAAQ;AAChD,QAAM,WAAW,KAAK,MAAM,UAAU;AACtC,MAAI,YAAY;AAChB,MAAI,aAAa;AACjB,MAAI,eAAe;AACnB,MAAI,YAAwB,CAAC;AAC7B,QAAM,QAAQ,OAAO,KAAM,CAAE,MAAO,EAAE,OAAO,OAAQ;AAErD,QAAM,EAAE,mBAAmB,QAAI,2BAAY,yBAAAC,OAAiB;AAE5D,MAAK,CAAE,OAAQ;AAEd,WAAO;AAAA,EACR;AAEA,cAAY,MAAM,iBAAiB;AACnC,eAAa,MAAM,kBAAkB;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
3
|
"sources": ["../../../../src/components/dataviews-layouts/table/use-scroll-state.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type {
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { isRTL } from '@wordpress/i18n';\n\nconst isScrolledToEnd = ( element: Element ) => {\n\tif ( isRTL() ) {\n\t\tconst scrollLeft = Math.abs( element.scrollLeft );\n\t\treturn scrollLeft <= 1;\n\t}\n\n\treturn element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;\n};\n\n/**\n * A hook to track the scroll state of a container element.\n *\n * Returns whether the container has been scrolled vertically (for sticky header styling)\n * and whether it has reached the horizontal scroll end (for sticky actions column styling).\n *\n * The current way receives \"refs\" as arguments, but it lacks a mechanism to detect when a ref has changed.\n * As a result, when the \"ref\" is updated and attached to a new div, the computation should trigger again.\n * However, this isn't possible in the current setup because the hook is unaware that the ref has changed.\n *\n * See https://github.com/Automattic/wp-calypso/pull/103005#discussion_r2077567912.\n *\n * @param params The parameters for the hook.\n * @param params.scrollContainerRef The ref to the scroll container element.\n * @param [params.enabledHorizontal=false] Whether to track horizontal scroll end.\n * @return The scroll state.\n */\nexport function useScrollState( {\n\tscrollContainerRef,\n\tenabledHorizontal = false,\n}: {\n\tscrollContainerRef: RefObject< HTMLDivElement | null >;\n\tenabledHorizontal?: boolean;\n} ): { isHorizontalScrollEnd: boolean; isVerticallyScrolled: boolean } {\n\tconst [ isHorizontalScrollEnd, setIsHorizontalScrollEnd ] =\n\t\tuseState( false );\n\tconst [ isVerticallyScrolled, setIsVerticallyScrolled ] = useState( false );\n\n\tconst handleScroll = useCallback( () => {\n\t\tconst scrollContainer = scrollContainerRef.current;\n\t\tif ( ! scrollContainer ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( enabledHorizontal ) {\n\t\t\tsetIsHorizontalScrollEnd( isScrolledToEnd( scrollContainer ) );\n\t\t}\n\n\t\tsetIsVerticallyScrolled( scrollContainer.scrollTop > 0 );\n\t}, [ scrollContainerRef, enabledHorizontal ] );\n\tuseEffect( () => {\n\t\tif ( typeof window === 'undefined' || ! scrollContainerRef.current ) {\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst scrollContainer = scrollContainerRef.current;\n\n\t\thandleScroll();\n\t\tscrollContainer.addEventListener( 'scroll', handleScroll );\n\t\twindow.addEventListener( 'resize', handleScroll );\n\n\t\treturn () => {\n\t\t\tscrollContainer.removeEventListener( 'scroll', handleScroll );\n\t\t\twindow.removeEventListener( 'resize', handleScroll );\n\t\t};\n\t}, [ scrollContainerRef, enabledHorizontal, handleScroll ] );\n\n\treturn { isHorizontalScrollEnd, isVerticallyScrolled };\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAAiD;AACjD,kBAAsB;AAEtB,IAAM,kBAAkB,CAAE,YAAsB;AAC/C,UAAK,mBAAM,GAAI;AACd,UAAM,aAAa,KAAK,IAAK,QAAQ,UAAW;AAChD,WAAO,cAAc;AAAA,EACtB;AAEA,SAAO,QAAQ,aAAa,QAAQ,eAAe,QAAQ,cAAc;AAC1E;AAmBO,SAAS,eAAgB;AAAA,EAC/B;AAAA,EACA,oBAAoB;AACrB,GAGuE;AACtE,QAAM,CAAE,uBAAuB,wBAAyB,QACvD,yBAAU,KAAM;AACjB,QAAM,CAAE,sBAAsB,uBAAwB,QAAI,yBAAU,KAAM;AAE1E,QAAM,mBAAe,4BAAa,MAAM;AACvC,UAAM,kBAAkB,mBAAmB;AAC3C,QAAK,CAAE,iBAAkB;AACxB;AAAA,IACD;AAEA,QAAK,mBAAoB;AACxB,+BAA0B,gBAAiB,eAAgB,CAAE;AAAA,IAC9D;AAEA,4BAAyB,gBAAgB,YAAY,CAAE;AAAA,EACxD,GAAG,CAAE,oBAAoB,iBAAkB,CAAE;AAC7C,gCAAW,MAAM;AAChB,QAAK,OAAO,WAAW,eAAe,CAAE,mBAAmB,SAAU;AACpE,aAAO,MAAM;AAAA,MAAC;AAAA,IACf;AAEA,UAAM,kBAAkB,mBAAmB;AAE3C,iBAAa;AACb,oBAAgB,iBAAkB,UAAU,YAAa;AACzD,WAAO,iBAAkB,UAAU,YAAa;AAEhD,WAAO,MAAM;AACZ,sBAAgB,oBAAqB,UAAU,YAAa;AAC5D,aAAO,oBAAqB,UAAU,YAAa;AAAA,IACpD;AAAA,EACD,GAAG,CAAE,oBAAoB,mBAAmB,YAAa,CAAE;AAE3D,SAAO,EAAE,uBAAuB,qBAAqB;AACtD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataviews-layouts/utils/item-click-wrapper.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactNode, ReactElement, ComponentProps } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { cloneElement } from '@wordpress/element';\n\nfunction getClickableItemProps< Item >( {\n\titem,\n\tisItemClickable,\n\tonClickItem,\n\tclassName,\n}: {\n\titem: Item;\n\tisItemClickable: ( item: Item ) => boolean;\n\tonClickItem?: ( item: Item ) => void;\n\tclassName?: string;\n} ) {\n\tif ( ! isItemClickable( item ) || ! onClickItem ) {\n\t\treturn { className };\n\t}\n\n\treturn {\n\t\tclassName: className\n\t\t\t? `${ className } ${ className }--clickable`\n\t\t\t: undefined,\n\t\trole: 'button',\n\t\ttabIndex: 0,\n\t\tonClick: ( event: React.MouseEvent ) => {\n\t\t\t// Prevents onChangeSelection from triggering.\n\t\t\tevent.stopPropagation();\n\t\t\tonClickItem( item );\n\t\t},\n\t\tonKeyDown: ( event: React.KeyboardEvent ) => {\n\t\t\tif (\n\t\t\t\tevent.key === 'Enter' ||\n\t\t\t\tevent.key === '' ||\n\t\t\t\tevent.key === ' '\n\t\t\t) {\n\t\t\t\t// Prevents onChangeSelection from triggering.\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tonClickItem( item );\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function ItemClickWrapper< Item >( {\n\titem,\n\tisItemClickable,\n\tonClickItem,\n\trenderItemLink,\n\tclassName,\n\tchildren,\n\t...extraProps\n}: {\n\titem: Item;\n\tisItemClickable: ( item: Item ) => boolean;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tclassName?: string;\n\ttitle?: string;\n\tchildren: ReactNode;\n} ) {\n\t// Always render a wrapper element so layout and styling relying on the wrapper\n\t// still works even if the item is not clickable.\n\tif ( ! isItemClickable( item ) ) {\n\t\treturn (\n\t\t\t<div className={ className } { ...extraProps }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// If we have a renderItemLink, use it\n\tif ( renderItemLink ) {\n\t\tconst renderedElement = renderItemLink( {\n\t\t\titem,\n\t\t\tclassName: `${ className } ${ className }--clickable`,\n\t\t\t...extraProps,\n\t\t\tchildren,\n\t\t} )
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA6B;AAmE1B;AAjEH,SAAS,sBAA+B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAKI;AACH,MAAK,CAAE,gBAAiB,IAAK,KAAK,CAAE,aAAc;AACjD,WAAO,EAAE,UAAU;AAAA,EACpB;AAEA,SAAO;AAAA,IACN,WAAW,YACR,GAAI,SAAU,IAAK,SAAU,gBAC7B;AAAA,IACH,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS,CAAE,UAA6B;AAEvC,YAAM,gBAAgB;AACtB,kBAAa,IAAK;AAAA,IACnB;AAAA,IACA,WAAW,CAAE,UAAgC;AAC5C,UACC,MAAM,QAAQ,WACd,MAAM,QAAQ,MACd,MAAM,QAAQ,KACb;AAED,cAAM,gBAAgB;AACtB,oBAAa,IAAK;AAAA,MACnB;AAAA,IACD;AAAA,EACD;AACD;AAEO,SAAS,iBAA0B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACJ,GAYI;AAGH,MAAK,CAAE,gBAAiB,IAAK,GAAI;AAChC,WACC,4CAAC,SAAI,WAA0B,GAAG,YAC/B,UACH;AAAA,EAEF;AAGA,MAAK,gBAAiB;AACrB,UAAM,kBAAkB,eAAgB;AAAA,MACvC;AAAA,MACA,WAAW,GAAI,SAAU,IAAK,SAAU;AAAA,MACxC,GAAG;AAAA,MACH;AAAA,IACD,CAAE;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactNode, ReactElement, ComponentProps } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { cloneElement } from '@wordpress/element';\n\nfunction getClickableItemProps< Item >( {\n\titem,\n\tisItemClickable,\n\tonClickItem,\n\tclassName,\n}: {\n\titem: Item;\n\tisItemClickable: ( item: Item ) => boolean;\n\tonClickItem?: ( item: Item ) => void;\n\tclassName?: string;\n} ) {\n\tif ( ! isItemClickable( item ) || ! onClickItem ) {\n\t\treturn { className };\n\t}\n\n\treturn {\n\t\tclassName: className\n\t\t\t? `${ className } ${ className }--clickable`\n\t\t\t: undefined,\n\t\trole: 'button',\n\t\ttabIndex: 0,\n\t\tonClick: ( event: React.MouseEvent ) => {\n\t\t\t// Prevents onChangeSelection from triggering.\n\t\t\tevent.stopPropagation();\n\t\t\tonClickItem( item );\n\t\t},\n\t\tonKeyDown: ( event: React.KeyboardEvent ) => {\n\t\t\tif (\n\t\t\t\tevent.key === 'Enter' ||\n\t\t\t\tevent.key === '' ||\n\t\t\t\tevent.key === ' '\n\t\t\t) {\n\t\t\t\t// Prevents onChangeSelection from triggering.\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tonClickItem( item );\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function ItemClickWrapper< Item >( {\n\titem,\n\tisItemClickable,\n\tonClickItem,\n\trenderItemLink,\n\tclassName,\n\tchildren,\n\t...extraProps\n}: {\n\titem: Item;\n\tisItemClickable: ( item: Item ) => boolean;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tclassName?: string;\n\ttitle?: string;\n\tchildren: ReactNode;\n} ) {\n\t// Always render a wrapper element so layout and styling relying on the wrapper\n\t// still works even if the item is not clickable.\n\tif ( ! isItemClickable( item ) ) {\n\t\treturn (\n\t\t\t<div className={ className } { ...extraProps }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// If we have a renderItemLink, use it\n\tif ( renderItemLink ) {\n\t\tconst renderedElement = renderItemLink( {\n\t\t\titem,\n\t\t\tclassName: `${ className } ${ className }--clickable`,\n\t\t\t...extraProps,\n\t\t\tchildren,\n\t\t} ) as ReactElement<\n\t\t\tPick< React.DOMAttributes< Element >, 'onClick' | 'onKeyDown' >\n\t\t>;\n\n\t\t// Clone the element and enhance onClick to stop propagation\n\t\treturn cloneElement( renderedElement, {\n\t\t\tonClick: ( event: React.MouseEvent ) => {\n\t\t\t\t// Always stop propagation to prevent selection\n\t\t\t\tevent.stopPropagation();\n\n\t\t\t\t// If consumer provided an onClick, call it\n\t\t\t\tif ( renderedElement.props.onClick ) {\n\t\t\t\t\trenderedElement.props.onClick( event );\n\t\t\t\t}\n\t\t\t},\n\t\t\tonKeyDown: ( event: React.KeyboardEvent ) => {\n\t\t\t\tif (\n\t\t\t\t\tevent.key === 'Enter' ||\n\t\t\t\t\tevent.key === '' ||\n\t\t\t\t\tevent.key === ' '\n\t\t\t\t) {\n\t\t\t\t\t// Prevents onChangeSelection from triggering.\n\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t// If consumer provided an onKeyDown, call it\n\t\t\t\t\tif ( renderedElement.props.onKeyDown ) {\n\t\t\t\t\t\trenderedElement.props.onKeyDown( event );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t} );\n\t}\n\n\t// Otherwise use the classic click handler approach\n\tconst clickProps = getClickableItemProps( {\n\t\titem,\n\t\tisItemClickable,\n\t\tonClickItem,\n\t\tclassName,\n\t} );\n\n\treturn (\n\t\t<div { ...clickProps } { ...extraProps }>\n\t\t\t{ children }\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA6B;AAmE1B;AAjEH,SAAS,sBAA+B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAKI;AACH,MAAK,CAAE,gBAAiB,IAAK,KAAK,CAAE,aAAc;AACjD,WAAO,EAAE,UAAU;AAAA,EACpB;AAEA,SAAO;AAAA,IACN,WAAW,YACR,GAAI,SAAU,IAAK,SAAU,gBAC7B;AAAA,IACH,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS,CAAE,UAA6B;AAEvC,YAAM,gBAAgB;AACtB,kBAAa,IAAK;AAAA,IACnB;AAAA,IACA,WAAW,CAAE,UAAgC;AAC5C,UACC,MAAM,QAAQ,WACd,MAAM,QAAQ,MACd,MAAM,QAAQ,KACb;AAED,cAAM,gBAAgB;AACtB,oBAAa,IAAK;AAAA,MACnB;AAAA,IACD;AAAA,EACD;AACD;AAEO,SAAS,iBAA0B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACJ,GAYI;AAGH,MAAK,CAAE,gBAAiB,IAAK,GAAI;AAChC,WACC,4CAAC,SAAI,WAA0B,GAAG,YAC/B,UACH;AAAA,EAEF;AAGA,MAAK,gBAAiB;AACrB,UAAM,kBAAkB,eAAgB;AAAA,MACvC;AAAA,MACA,WAAW,GAAI,SAAU,IAAK,SAAU;AAAA,MACxC,GAAG;AAAA,MACH;AAAA,IACD,CAAE;AAKF,eAAO,6BAAc,iBAAiB;AAAA,MACrC,SAAS,CAAE,UAA6B;AAEvC,cAAM,gBAAgB;AAGtB,YAAK,gBAAgB,MAAM,SAAU;AACpC,0BAAgB,MAAM,QAAS,KAAM;AAAA,QACtC;AAAA,MACD;AAAA,MACA,WAAW,CAAE,UAAgC;AAC5C,YACC,MAAM,QAAQ,WACd,MAAM,QAAQ,MACd,MAAM,QAAQ,KACb;AAED,gBAAM,gBAAgB;AAEtB,cAAK,gBAAgB,MAAM,WAAY;AACtC,4BAAgB,MAAM,UAAW,KAAM;AAAA,UACxC;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH;AAGA,QAAM,aAAa,sBAAuB;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SACC,4CAAC,SAAM,GAAG,YAAe,GAAG,YACzB,UACH;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-view-config/properties-section.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\tBaseControl,\n\tIcon,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useContext } from '@wordpress/element';\nimport { check } from '@wordpress/icons';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedField } from '../../types';\nimport DataViewsContext from '../dataviews-context';\nimport getHideableFields from '../../utils/get-hideable-fields';\n\nfunction FieldItem( {\n\tfield,\n\tisVisible,\n\tonToggleVisibility,\n}: {\n\tfield: NormalizedField< any >;\n\tisVisible: boolean;\n\tonToggleVisibility?: () => void;\n} ) {\n\treturn (\n\t\t<Item onClick={ field.enableHiding ? onToggleVisibility : undefined }>\n\t\t\t<Stack direction=\"row\" gap=\"sm\" justify=\"flex-start\" align=\"center\">\n\t\t\t\t<div style={ { height: 24, width: 24 } }>\n\t\t\t\t\t{ isVisible && <
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAKO;AACP,kBAAmB;AACnB,qBAA2B;AAC3B,mBAAsB;AACtB,gBAAsB;AAMtB,+BAA6B;AAC7B,iCAA8B;AAa3B;AAXH,SAAS,UAAW;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AACD,GAII;AACH,SACC,4CAAC,kBAAAA,oBAAA,EAAK,SAAU,MAAM,eAAe,qBAAqB,QACzD,uDAAC,mBAAM,WAAU,OAAM,KAAI,MAAK,SAAQ,cAAa,OAAM,UAC1D;AAAA,gDAAC,SAAI,OAAQ,EAAE,QAAQ,IAAI,OAAO,GAAG,GAClC,uBAAa,4CAAC,
|
|
6
|
-
"names": ["Item", "DataViewsContext", "getHideableFields", "ItemGroup"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\tBaseControl,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useContext } from '@wordpress/element';\nimport { check } from '@wordpress/icons';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedField } from '../../types';\nimport DataViewsContext from '../dataviews-context';\nimport getHideableFields from '../../utils/get-hideable-fields';\n\nfunction FieldItem( {\n\tfield,\n\tisVisible,\n\tonToggleVisibility,\n}: {\n\tfield: NormalizedField< any >;\n\tisVisible: boolean;\n\tonToggleVisibility?: () => void;\n} ) {\n\treturn (\n\t\t<Item onClick={ field.enableHiding ? onToggleVisibility : undefined }>\n\t\t\t<Stack direction=\"row\" gap=\"sm\" justify=\"flex-start\" align=\"center\">\n\t\t\t\t<div style={ { height: 24, width: 24 } }>\n\t\t\t\t\t{ isVisible && <WCIcon icon={ check } /> }\n\t\t\t\t</div>\n\t\t\t\t<span className=\"dataviews-view-config__label\">\n\t\t\t\t\t{ field.label }\n\t\t\t\t</span>\n\t\t\t</Stack>\n\t\t</Item>\n\t);\n}\n\nfunction isDefined< T >( item: T | undefined ): item is T {\n\treturn !! item;\n}\n\nexport function PropertiesSection( {\n\tshowLabel = true,\n}: {\n\tshowLabel?: boolean;\n} ) {\n\tconst { view, fields, onChangeView } = useContext( DataViewsContext );\n\n\t// Get all regular fields (non-locked) in their original order from fields prop\n\tconst regularFields = getHideableFields( view, fields );\n\n\tif ( ! regularFields?.length ) {\n\t\treturn null;\n\t}\n\tconst titleField = fields.find( ( f ) => f.id === view.titleField );\n\tconst previewField = fields.find( ( f ) => f.id === view.mediaField );\n\tconst descriptionField = fields.find(\n\t\t( f ) => f.id === view.descriptionField\n\t);\n\n\tconst lockedFields = [\n\t\t{\n\t\t\tfield: titleField,\n\t\t\tisVisibleFlag: 'showTitle',\n\t\t},\n\t\t{\n\t\t\tfield: previewField,\n\t\t\tisVisibleFlag: 'showMedia',\n\t\t},\n\t\t{\n\t\t\tfield: descriptionField,\n\t\t\tisVisibleFlag: 'showDescription',\n\t\t},\n\t].filter( ( { field } ) => isDefined( field ) ) as Array< {\n\t\tfield: NormalizedField< any >;\n\t\tisVisibleFlag: string;\n\t} >;\n\tconst visibleFieldIds = view.fields ?? [];\n\tconst visibleRegularFieldsCount = regularFields.filter( ( f ) =>\n\t\tvisibleFieldIds.includes( f.id )\n\t).length;\n\n\tconst visibleLockedFields = lockedFields.filter(\n\t\t( { isVisibleFlag } ) =>\n\t\t\t// @ts-expect-error\n\t\t\tview[ isVisibleFlag ] ?? true\n\t);\n\n\t// If only one field (locked or regular) is visible, prevent it from being hidden\n\tconst totalVisibleFields =\n\t\tvisibleLockedFields.length + visibleRegularFieldsCount;\n\tconst isSingleVisibleLockedField =\n\t\ttotalVisibleFields === 1 && visibleLockedFields.length === 1;\n\n\treturn (\n\t\t<Stack direction=\"column\" className=\"dataviews-field-control\">\n\t\t\t{ showLabel && (\n\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t{ __( 'Properties' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t) }\n\t\t\t<Stack\n\t\t\t\tdirection=\"column\"\n\t\t\t\tclassName=\"dataviews-view-config__properties\"\n\t\t\t>\n\t\t\t\t<ItemGroup isBordered isSeparated size=\"medium\">\n\t\t\t\t\t{ lockedFields.map( ( { field, isVisibleFlag } ) => {\n\t\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\t\tconst isVisible = view[ isVisibleFlag ] ?? true;\n\t\t\t\t\t\tconst fieldToRender =\n\t\t\t\t\t\t\tisSingleVisibleLockedField && isVisible\n\t\t\t\t\t\t\t\t? { ...field, enableHiding: false }\n\t\t\t\t\t\t\t\t: field;\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<FieldItem\n\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\tfield={ fieldToRender }\n\t\t\t\t\t\t\t\tisVisible={ isVisible }\n\t\t\t\t\t\t\t\tonToggleVisibility={ () => {\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\t[ isVisibleFlag ]: ! isVisible,\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} ) }\n\n\t\t\t\t\t{ regularFields.map( ( field ) => {\n\t\t\t\t\t\t// Check if this is the last visible field to prevent hiding\n\t\t\t\t\t\tconst isVisible = visibleFieldIds.includes( field.id );\n\t\t\t\t\t\tconst fieldToRender =\n\t\t\t\t\t\t\ttotalVisibleFields === 1 && isVisible\n\t\t\t\t\t\t\t\t? { ...field, enableHiding: false }\n\t\t\t\t\t\t\t\t: field;\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<FieldItem\n\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\tfield={ fieldToRender }\n\t\t\t\t\t\t\t\tisVisible={ isVisible }\n\t\t\t\t\t\t\t\tonToggleVisibility={ () => {\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\tfields: isVisible\n\t\t\t\t\t\t\t\t\t\t\t? visibleFieldIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t\t\t( fieldId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfieldId !== field.id\n\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t: [ ...visibleFieldIds, field.id ],\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} ) }\n\t\t\t\t</ItemGroup>\n\t\t\t</Stack>\n\t\t</Stack>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAKO;AACP,kBAAmB;AACnB,qBAA2B;AAC3B,mBAAsB;AACtB,gBAAsB;AAMtB,+BAA6B;AAC7B,iCAA8B;AAa3B;AAXH,SAAS,UAAW;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AACD,GAII;AACH,SACC,4CAAC,kBAAAA,oBAAA,EAAK,SAAU,MAAM,eAAe,qBAAqB,QACzD,uDAAC,mBAAM,WAAU,OAAM,KAAI,MAAK,SAAQ,cAAa,OAAM,UAC1D;AAAA,gDAAC,SAAI,OAAQ,EAAE,QAAQ,IAAI,OAAO,GAAG,GAClC,uBAAa,4CAAC,kBAAAC,MAAA,EAA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{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-form-validity.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport normalizeFields from '../field-types';\nimport normalizeForm from '../components/dataform-layouts/normalize-form';\nimport type {\n\tField,\n\tFieldValidity,\n\tForm,\n\tFormValidity,\n\tNormalizedField,\n\tNormalizedFormField,\n} from '../types';\n\nfunction isFormValid( formValidity: FormValidity | undefined ): boolean {\n\tif ( ! formValidity ) {\n\t\treturn true;\n\t}\n\n\treturn Object.values( formValidity ).every( ( fieldValidation ) => {\n\t\treturn Object.entries( fieldValidation ).every(\n\t\t\t( [ key, validation ] ) => {\n\t\t\t\tif (\n\t\t\t\t\tkey === 'children' &&\n\t\t\t\t\tvalidation &&\n\t\t\t\t\ttypeof validation === 'object'\n\t\t\t\t) {\n\t\t\t\t\t// Recursively check children validations\n\t\t\t\t\treturn isFormValid( validation as FormValidity );\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\tvalidation.type !== 'invalid' &&\n\t\t\t\t\tvalidation.type !== 'validating'\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\t} );\n}\n\ntype FormFieldToValidate< Item > = {\n\tid: string;\n\tchildren: FormFieldToValidate< Item >[];\n\tfield?: NormalizedField< Item >;\n};\n\nfunction getFormFieldsToValidate< Item >(\n\tform: Form,\n\tfields: Field< Item >[]\n): FormFieldToValidate< Item >[] {\n\tconst normalizedForm = normalizeForm( form );\n\tif ( normalizedForm.fields.length === 0 ) {\n\t\treturn [];\n\t}\n\n\t// Create a map of field IDs to Field definitions for fast lookup\n\tconst fieldsMap = new Map< string, Field< Item > >();\n\tfields.forEach( ( field ) => {\n\t\tfieldsMap.set( field.id, field );\n\t} );\n\n\t// Recursive function to process form fields and their children\n\tfunction processFormField(\n\t\tformField: NormalizedFormField\n\t): FormFieldToValidate< Item > | null {\n\t\t// Handle combined fields (fields with children)\n\t\tif ( 'children' in formField && Array.isArray( formField.children ) ) {\n\t\t\tconst processedChildren = formField.children\n\t\t\t\t.map( processFormField )\n\t\t\t\t.filter( ( child ) => child !== null );\n\n\t\t\tif ( processedChildren.length === 0 ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\t\tif ( fieldDef ) {\n\t\t\t\tconst [ normalizedField ] = normalizeFields< Item >( [\n\t\t\t\t\tfieldDef,\n\t\t\t\t] );\n\n\t\t\t\treturn {\n\t\t\t\t\tid: formField.id,\n\t\t\t\t\tchildren: processedChildren,\n\t\t\t\t\tfield: normalizedField,\n\t\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: formField.id,\n\t\t\t\tchildren: processedChildren,\n\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t}\n\n\t\t// Handle leaf fields (fields without children)\n\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\tif ( ! fieldDef ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst [ normalizedField ] = normalizeFields< Item >( [ fieldDef ] );\n\t\treturn {\n\t\t\tid: formField.id,\n\t\t\tchildren: [],\n\t\t\tfield: normalizedField,\n\t\t} as FormFieldToValidate< Item >;\n\t}\n\n\tconst toValidate = normalizedForm.fields\n\t\t.map( processFormField )\n\t\t.filter( ( field ) => field !== null );\n\n\treturn toValidate;\n}\n\nfunction setValidityAtPath(\n\tformValidity: FormValidity | undefined,\n\tfieldValidity: FieldValidity,\n\tpath: string[]\n): FormValidity {\n\t// Handle empty validity or empty path\n\tif ( ! formValidity ) {\n\t\tformValidity = {};\n\t}\n\n\tif ( path.length === 0 ) {\n\t\treturn formValidity;\n\t}\n\n\t// Clone the root to avoid mutations\n\tconst result = { ...formValidity };\n\n\t// Navigate through the result tree,\n\t// setting up empty paths if they don't exist.\n\tlet current: any = result;\n\tfor ( let i = 0; i < path.length - 1; i++ ) {\n\t\tconst segment = path[ i ];\n\t\tif ( ! current[ segment ] ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t}\n\n\t\tcurrent[ segment ] = { ...current[ segment ] };\n\t\tcurrent = current[ segment ];\n\t}\n\n\t// At the final destination, merge the new validity with the existing.\n\tconst finalKey = path[ path.length - 1 ];\n\tcurrent[ finalKey ] = {\n\t\t...( current[ finalKey ] || {} ),\n\t\t...fieldValidity,\n\t};\n\n\treturn result;\n}\n\nfunction removeValidationProperty(\n\tformValidity: FormValidity | undefined,\n\tpath: string[],\n\tproperty: keyof FieldValidity\n): FormValidity | undefined {\n\tif ( ! formValidity || path.length === 0 ) {\n\t\treturn formValidity;\n\t}\n\tconst result = { ...formValidity };\n\t// Navigate to parent of target.\n\tlet current: any = result;\n\tfor ( let i = 0; i < path.length - 1; i++ ) {\n\t\tconst segment = path[ i ];\n\t\tif ( ! current[ segment ] ) {\n\t\t\treturn formValidity; // Path doesn't exist\n\t\t}\n\t\tcurrent[ segment ] = { ...current[ segment ] };\n\t\tcurrent = current[ segment ];\n\t}\n\tconst finalKey = path[ path.length - 1 ];\n\tif ( ! current[ finalKey ] ) {\n\t\treturn formValidity;\n\t}\n\tconst fieldValidity = { ...current[ finalKey ] };\n\tdelete fieldValidity[ property ];\n\t// If field has no more validations, remove it entirely.\n\tif ( Object.keys( fieldValidity ).length === 0 ) {\n\t\tdelete current[ finalKey ];\n\t} else {\n\t\t// Keep the field if it has other validations (including children).\n\t\tcurrent[ finalKey ] = fieldValidity;\n\t}\n\t// If root is empty, return undefined\n\tif ( Object.keys( result ).length === 0 ) {\n\t\treturn undefined;\n\t}\n\treturn result;\n}\n\nfunction handleElementsValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { elementsCounterRef, setFormValidity, path, item } = promiseHandler;\n\tconst currentToken =\n\t\t( elementsCounterRef.current[ formField.id ] || 0 ) + 1;\n\telementsCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! Array.isArray( result ) ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __( 'Could not validate elements.' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tformField.field?.isValid.elements &&\n\t\t\t\t! formField.field.isValid.elements.validate( item, {\n\t\t\t\t\t...formField.field,\n\t\t\t\t\telements: result,\n\t\t\t\t} )\n\t\t\t) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __(\n\t\t\t\t\t\t\t\t\t'Value must be one of the elements.'\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[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\t// Validation passed so we need to remove `elements` from validity.\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\treturn removeValidationProperty(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t[ ...path, formField.id ],\n\t\t\t\t\t\t'elements'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running elements validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\nfunction handleCustomValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { customCounterRef, setFormValidity, path } = promiseHandler;\n\tconst currentToken = ( customCounterRef.current[ formField.id ] || 0 ) + 1;\n\tcustomCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( result === null ) {\n\t\t\t\t// Validation passed so we need to remove `custom` from validity.\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\treturn removeValidationProperty(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t[ ...path, formField.id ],\n\t\t\t\t\t\t'custom'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( typeof result === 'string' ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: result,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: __( 'Validation could not be processed.' ),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running custom validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\ntype PromiseHandler< Item > = {\n\tcustomCounterRef: React.MutableRefObject< Record< string, number > >;\n\telementsCounterRef: React.MutableRefObject< Record< string, number > >;\n\tsetFormValidity: React.Dispatch< React.SetStateAction< FormValidity > >;\n\tpath: string[];\n\titem: Item;\n};\n\nfunction validateFormField< Item >(\n\titem: Item,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n): FieldValidity | undefined {\n\t// Validate the field: isValid.required\n\tif (\n\t\tformField.field?.isValid.required &&\n\t\t! formField.field.isValid.required.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\trequired: { type: 'invalid' },\n\t\t};\n\t}\n\n\t// Validate the field: isValid.pattern\n\tif (\n\t\tformField.field?.isValid.pattern &&\n\t\t! formField.field.isValid.pattern.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tpattern: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value does not match the required pattern.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.min\n\tif (\n\t\tformField.field?.isValid.min &&\n\t\t! formField.field.isValid.min.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmin: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is below the minimum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.max\n\tif (\n\t\tformField.field?.isValid.max &&\n\t\t! formField.field.isValid.max.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmax: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is above the maximum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.minLength\n\tif (\n\t\tformField.field?.isValid.minLength &&\n\t\t! formField.field.isValid.minLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tminLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too short.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.maxLength\n\tif (\n\t\tformField.field?.isValid.maxLength &&\n\t\t! formField.field.isValid.maxLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmaxLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too long.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.elements (static)\n\tif (\n\t\tformField.field?.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\t! formField.field.getElements &&\n\t\tArray.isArray( formField.field.elements ) &&\n\t\t! formField.field.isValid.elements.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\telements: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value must be one of the elements.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (sync)\n\tlet customError;\n\tif ( !! formField.field && formField.field.isValid.custom ) {\n\t\ttry {\n\t\t\tconst value = formField.field.getValue( { item } );\n\t\t\tcustomError = formField.field.isValid.custom(\n\t\t\t\tdeepMerge(\n\t\t\t\t\titem,\n\t\t\t\t\tformField.field.setValue( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tformField.field\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__( 'Unknown error when running custom validation.' );\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcustom: {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\n\tif ( typeof customError === 'string' ) {\n\t\treturn {\n\t\t\tcustom: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: customError,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Aggregate async validations (`elements` and `custom`).\n\tconst fieldValidity: FieldValidity = {};\n\t// Validate the field: isValid.elements (async)\n\tif (\n\t\t!! formField.field &&\n\t\tformField.field.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\ttypeof formField.field.getElements === 'function'\n\t) {\n\t\thandleElementsValidationAsync(\n\t\t\tformField.field.getElements(),\n\t\t\tformField,\n\t\t\tpromiseHandler\n\t\t);\n\t\tfieldValidity.elements = {\n\t\t\ttype: 'validating',\n\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (async)\n\tif ( customError instanceof Promise ) {\n\t\thandleCustomValidationAsync( customError, formField, promiseHandler );\n\n\t\tfieldValidity.custom = {\n\t\t\ttype: 'validating',\n\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t};\n\t}\n\n\t// Return aggregated validations if any exist\n\tif ( Object.keys( fieldValidity ).length > 0 ) {\n\t\treturn fieldValidity;\n\t}\n\n\t// Validate its children.\n\tif ( formField.children.length > 0 ) {\n\t\tconst result: Record< string, FieldValidity | undefined > = {};\n\t\tformField.children.forEach( ( child ) => {\n\t\t\tresult[ child.id ] = validateFormField( item, child, {\n\t\t\t\t...promiseHandler,\n\t\t\t\tpath: [ ...promiseHandler.path, formField.id, 'children' ],\n\t\t\t} );\n\t\t} );\n\n\t\tconst filteredResult: Record< string, FieldValidity > = {};\n\t\tObject.entries( result ).forEach( ( [ key, value ] ) => {\n\t\t\tif ( value !== undefined ) {\n\t\t\t\tfilteredResult[ key ] = value;\n\t\t\t}\n\t\t} );\n\n\t\tif ( Object.keys( filteredResult ).length === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tchildren: filteredResult,\n\t\t};\n\t}\n\n\t// No errors for this field or its children.\n\treturn undefined;\n}\n\nfunction getFormFieldValue< Item >(\n\tformField: FormFieldToValidate< Item >,\n\titem: Item\n): any {\n\tconst fieldValue = formField?.field?.getValue( { item } );\n\tif ( formField.children.length === 0 ) {\n\t\treturn fieldValue;\n\t}\n\n\tconst childrenValues = formField.children.map( ( child ) =>\n\t\tgetFormFieldValue( child, item )\n\t);\n\tif ( ! childrenValues ) {\n\t\treturn fieldValue;\n\t}\n\n\treturn {\n\t\tvalue: fieldValue,\n\t\tchildren: childrenValues,\n\t};\n}\n\n/**\n * Hook that validates a form item and returns an object with error messages for each field.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return Record of field IDs to error messages (undefined means no error).\n */\nexport function useFormValidity< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): { validity: FormValidity; isValid: boolean } {\n\tconst [ formValidity, setFormValidity ] = useState< FormValidity >();\n\tconst customCounterRef = useRef< Record< string, number > >( {} );\n\tconst elementsCounterRef = useRef< Record< string, number > >( {} );\n\tconst previousValuesRef = useRef< Record< string, any > >( {} );\n\n\tconst validate = useCallback( () => {\n\t\tconst promiseHandler = {\n\t\t\tcustomCounterRef,\n\t\t\telementsCounterRef,\n\t\t\tsetFormValidity,\n\t\t\tpath: [],\n\t\t\titem,\n\t\t};\n\n\t\tconst formFieldsToValidate = getFormFieldsToValidate( form, fields );\n\t\tif ( formFieldsToValidate.length === 0 ) {\n\t\t\tsetFormValidity( undefined );\n\t\t\treturn;\n\t\t}\n\n\t\tconst newFormValidity: FormValidity = {};\n\t\tconst untouchedFields: string[] = [];\n\t\tformFieldsToValidate.forEach( ( formField ) => {\n\t\t\t// Skip fields that did not change.\n\t\t\tconst value = getFormFieldValue< Item >( formField, item );\n\t\t\tif (\n\t\t\t\tpreviousValuesRef.current.hasOwnProperty( formField.id ) &&\n\t\t\t\tfastDeepEqual(\n\t\t\t\t\tpreviousValuesRef.current[ formField.id ],\n\t\t\t\t\tvalue\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tuntouchedFields.push( formField.id );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpreviousValuesRef.current[ formField.id ] = value;\n\n\t\t\t// Calculate validity for those fields that changed.\n\t\t\tconst fieldValidity = validateFormField(\n\t\t\t\titem,\n\t\t\t\tformField,\n\t\t\t\tpromiseHandler\n\t\t\t);\n\t\t\tif ( fieldValidity !== undefined ) {\n\t\t\t\tnewFormValidity[ formField.id ] = fieldValidity;\n\t\t\t}\n\t\t} );\n\n\t\tsetFormValidity( ( existingFormValidity ) => {\n\t\t\tlet validity: FormValidity = {\n\t\t\t\t...existingFormValidity,\n\t\t\t\t...newFormValidity,\n\t\t\t};\n\n\t\t\tconst fieldsToKeep = [\n\t\t\t\t...untouchedFields,\n\t\t\t\t...Object.keys( newFormValidity ),\n\t\t\t];\n\t\t\tObject.keys( validity ).forEach( ( key ) => {\n\t\t\t\tif ( validity && ! fieldsToKeep.includes( key ) ) {\n\t\t\t\t\tdelete validity[ key ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tif ( Object.keys( validity ).length === 0 ) {\n\t\t\t\tvalidity = undefined;\n\t\t\t}\n\n\t\t\tconst areEqual = fastDeepEqual( existingFormValidity, validity );\n\t\t\tif ( areEqual ) {\n\t\t\t\treturn existingFormValidity;\n\t\t\t}\n\n\t\t\treturn validity;\n\t\t} );\n\t}, [ item, fields, form ] );\n\n\tuseEffect( () => {\n\t\tvalidate();\n\t}, [ validate ] );\n\n\treturn {\n\t\tvalidity: formValidity,\n\t\tisValid: isFormValid( formValidity ),\n\t};\n}\n\nexport default useFormValidity;\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport normalizeFields from '../field-types';\nimport normalizeForm from '../components/dataform-layouts/normalize-form';\nimport type {\n\tField,\n\tFieldValidity,\n\tForm,\n\tFormValidity,\n\tNormalizedField,\n\tNormalizedFormField,\n} from '../types';\n\nfunction isFormValid( formValidity: FormValidity | undefined ): boolean {\n\tif ( ! formValidity ) {\n\t\treturn true;\n\t}\n\n\treturn Object.values( formValidity ).every( ( fieldValidation ) => {\n\t\treturn Object.entries( fieldValidation ).every(\n\t\t\t( [ key, validation ] ) => {\n\t\t\t\tif (\n\t\t\t\t\tkey === 'children' &&\n\t\t\t\t\tvalidation &&\n\t\t\t\t\ttypeof validation === 'object'\n\t\t\t\t) {\n\t\t\t\t\t// Recursively check children validations\n\t\t\t\t\treturn isFormValid( validation as FormValidity );\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\tvalidation.type !== 'invalid' &&\n\t\t\t\t\tvalidation.type !== 'validating'\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\t} );\n}\n\ntype FormFieldToValidate< Item > = {\n\tid: string;\n\tchildren: FormFieldToValidate< Item >[];\n\tfield?: NormalizedField< Item >;\n};\n\nfunction getFormFieldsToValidate< Item >(\n\tform: Form,\n\tfields: Field< Item >[]\n): FormFieldToValidate< Item >[] {\n\tconst normalizedForm = normalizeForm( form );\n\tif ( normalizedForm.fields.length === 0 ) {\n\t\treturn [];\n\t}\n\n\t// Create a map of field IDs to Field definitions for fast lookup\n\tconst fieldsMap = new Map< string, Field< Item > >();\n\tfields.forEach( ( field ) => {\n\t\tfieldsMap.set( field.id, field );\n\t} );\n\n\t// Recursive function to process form fields and their children\n\tfunction processFormField(\n\t\tformField: NormalizedFormField\n\t): FormFieldToValidate< Item > | null {\n\t\t// Handle combined fields (fields with children)\n\t\tif ( 'children' in formField && Array.isArray( formField.children ) ) {\n\t\t\tconst processedChildren = formField.children\n\t\t\t\t.map( processFormField )\n\t\t\t\t.filter( ( child ) => child !== null );\n\n\t\t\tif ( processedChildren.length === 0 ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\t\tif ( fieldDef ) {\n\t\t\t\tconst [ normalizedField ] = normalizeFields< Item >( [\n\t\t\t\t\tfieldDef,\n\t\t\t\t] );\n\n\t\t\t\treturn {\n\t\t\t\t\tid: formField.id,\n\t\t\t\t\tchildren: processedChildren,\n\t\t\t\t\tfield: normalizedField,\n\t\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: formField.id,\n\t\t\t\tchildren: processedChildren,\n\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t}\n\n\t\t// Handle leaf fields (fields without children)\n\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\tif ( ! fieldDef ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst [ normalizedField ] = normalizeFields< Item >( [ fieldDef ] );\n\t\treturn {\n\t\t\tid: formField.id,\n\t\t\tchildren: [],\n\t\t\tfield: normalizedField,\n\t\t} as FormFieldToValidate< Item >;\n\t}\n\n\tconst toValidate = normalizedForm.fields\n\t\t.map( processFormField )\n\t\t.filter( ( field ) => field !== null );\n\n\treturn toValidate;\n}\n\nfunction setValidityAtPath(\n\tformValidity: FormValidity | undefined,\n\tfieldValidity: FieldValidity,\n\tpath: string[]\n): FormValidity {\n\t// Handle empty validity or empty path\n\tif ( ! formValidity ) {\n\t\tformValidity = {};\n\t}\n\n\tif ( path.length === 0 ) {\n\t\treturn formValidity;\n\t}\n\n\t// Clone the root to avoid mutations\n\tconst result = { ...formValidity };\n\n\t// Navigate through the result tree,\n\t// setting up empty paths if they don't exist.\n\tlet current: any = result;\n\tfor ( let i = 0; i < path.length - 1; i++ ) {\n\t\tconst segment = path[ i ];\n\t\tif ( ! current[ segment ] ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t}\n\n\t\tcurrent[ segment ] = { ...current[ segment ] };\n\t\tcurrent = current[ segment ];\n\t}\n\n\t// At the final destination, merge the new validity with the existing.\n\tconst finalKey = path[ path.length - 1 ];\n\tcurrent[ finalKey ] = {\n\t\t...( current[ finalKey ] || {} ),\n\t\t...fieldValidity,\n\t};\n\n\treturn result;\n}\n\nfunction removeValidationProperty(\n\tformValidity: FormValidity | undefined,\n\tpath: string[],\n\tproperty: keyof FieldValidity\n): FormValidity | undefined {\n\tif ( ! formValidity || path.length === 0 ) {\n\t\treturn formValidity;\n\t}\n\tconst result = { ...formValidity };\n\t// Navigate to parent of target.\n\tlet current: any = result;\n\tfor ( let i = 0; i < path.length - 1; i++ ) {\n\t\tconst segment = path[ i ];\n\t\tif ( ! current[ segment ] ) {\n\t\t\treturn formValidity; // Path doesn't exist\n\t\t}\n\t\tcurrent[ segment ] = { ...current[ segment ] };\n\t\tcurrent = current[ segment ];\n\t}\n\tconst finalKey = path[ path.length - 1 ];\n\tif ( ! current[ finalKey ] ) {\n\t\treturn formValidity;\n\t}\n\tconst fieldValidity = { ...current[ finalKey ] };\n\tdelete fieldValidity[ property ];\n\t// If field has no more validations, remove it entirely.\n\tif ( Object.keys( fieldValidity ).length === 0 ) {\n\t\tdelete current[ finalKey ];\n\t} else {\n\t\t// Keep the field if it has other validations (including children).\n\t\tcurrent[ finalKey ] = fieldValidity;\n\t}\n\t// If root is empty, return undefined\n\tif ( Object.keys( result ).length === 0 ) {\n\t\treturn undefined;\n\t}\n\treturn result;\n}\n\nfunction handleElementsValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { elementsCounterRef, setFormValidity, path, item } = promiseHandler;\n\tconst currentToken =\n\t\t( elementsCounterRef.current[ formField.id ] || 0 ) + 1;\n\telementsCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! Array.isArray( result ) ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __( 'Could not validate elements.' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tformField.field?.isValid.elements &&\n\t\t\t\t! formField.field.isValid.elements.validate( item, {\n\t\t\t\t\t...formField.field,\n\t\t\t\t\telements: result,\n\t\t\t\t} )\n\t\t\t) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __(\n\t\t\t\t\t\t\t\t\t'Value must be one of the elements.'\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[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\t// Validation passed so we need to remove `elements` from validity.\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\treturn removeValidationProperty(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t[ ...path, formField.id ],\n\t\t\t\t\t\t'elements'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running elements validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\nfunction handleCustomValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { customCounterRef, setFormValidity, path } = promiseHandler;\n\tconst currentToken = ( customCounterRef.current[ formField.id ] || 0 ) + 1;\n\tcustomCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( result === null ) {\n\t\t\t\t// Validation passed so we need to remove `custom` from validity.\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\treturn removeValidationProperty(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t[ ...path, formField.id ],\n\t\t\t\t\t\t'custom'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( typeof result === 'string' ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: result,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: __( 'Validation could not be processed.' ),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running custom validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\ntype PromiseHandler< Item > = {\n\tcustomCounterRef: React.RefObject< Record< string, number > >;\n\telementsCounterRef: React.RefObject< Record< string, number > >;\n\tsetFormValidity: React.Dispatch< React.SetStateAction< FormValidity > >;\n\tpath: string[];\n\titem: Item;\n};\n\nfunction validateFormField< Item >(\n\titem: Item,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n): FieldValidity | undefined {\n\t// Validate the field: isValid.required\n\tif (\n\t\tformField.field?.isValid.required &&\n\t\t! formField.field.isValid.required.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\trequired: { type: 'invalid' },\n\t\t};\n\t}\n\n\t// Validate the field: isValid.pattern\n\tif (\n\t\tformField.field?.isValid.pattern &&\n\t\t! formField.field.isValid.pattern.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tpattern: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value does not match the required pattern.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.min\n\tif (\n\t\tformField.field?.isValid.min &&\n\t\t! formField.field.isValid.min.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmin: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is below the minimum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.max\n\tif (\n\t\tformField.field?.isValid.max &&\n\t\t! formField.field.isValid.max.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmax: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is above the maximum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.minLength\n\tif (\n\t\tformField.field?.isValid.minLength &&\n\t\t! formField.field.isValid.minLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tminLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too short.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.maxLength\n\tif (\n\t\tformField.field?.isValid.maxLength &&\n\t\t! formField.field.isValid.maxLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmaxLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too long.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.elements (static)\n\tif (\n\t\tformField.field?.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\t! formField.field.getElements &&\n\t\tArray.isArray( formField.field.elements ) &&\n\t\t! formField.field.isValid.elements.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\telements: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value must be one of the elements.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (sync)\n\tlet customError;\n\tif ( !! formField.field && formField.field.isValid.custom ) {\n\t\ttry {\n\t\t\tconst value = formField.field.getValue( { item } );\n\t\t\tcustomError = formField.field.isValid.custom(\n\t\t\t\tdeepMerge(\n\t\t\t\t\titem,\n\t\t\t\t\tformField.field.setValue( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tformField.field\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__( 'Unknown error when running custom validation.' );\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcustom: {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\n\tif ( typeof customError === 'string' ) {\n\t\treturn {\n\t\t\tcustom: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: customError,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Aggregate async validations (`elements` and `custom`).\n\tconst fieldValidity: FieldValidity = {};\n\t// Validate the field: isValid.elements (async)\n\tif (\n\t\t!! formField.field &&\n\t\tformField.field.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\ttypeof formField.field.getElements === 'function'\n\t) {\n\t\thandleElementsValidationAsync(\n\t\t\tformField.field.getElements(),\n\t\t\tformField,\n\t\t\tpromiseHandler\n\t\t);\n\t\tfieldValidity.elements = {\n\t\t\ttype: 'validating',\n\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (async)\n\tif ( customError instanceof Promise ) {\n\t\thandleCustomValidationAsync( customError, formField, promiseHandler );\n\n\t\tfieldValidity.custom = {\n\t\t\ttype: 'validating',\n\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t};\n\t}\n\n\t// Return aggregated validations if any exist\n\tif ( Object.keys( fieldValidity ).length > 0 ) {\n\t\treturn fieldValidity;\n\t}\n\n\t// Validate its children.\n\tif ( formField.children.length > 0 ) {\n\t\tconst result: Record< string, FieldValidity | undefined > = {};\n\t\tformField.children.forEach( ( child ) => {\n\t\t\tresult[ child.id ] = validateFormField( item, child, {\n\t\t\t\t...promiseHandler,\n\t\t\t\tpath: [ ...promiseHandler.path, formField.id, 'children' ],\n\t\t\t} );\n\t\t} );\n\n\t\tconst filteredResult: Record< string, FieldValidity > = {};\n\t\tObject.entries( result ).forEach( ( [ key, value ] ) => {\n\t\t\tif ( value !== undefined ) {\n\t\t\t\tfilteredResult[ key ] = value;\n\t\t\t}\n\t\t} );\n\n\t\tif ( Object.keys( filteredResult ).length === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tchildren: filteredResult,\n\t\t};\n\t}\n\n\t// No errors for this field or its children.\n\treturn undefined;\n}\n\nfunction getFormFieldValue< Item >(\n\tformField: FormFieldToValidate< Item >,\n\titem: Item\n): any {\n\tconst fieldValue = formField?.field?.getValue( { item } );\n\tif ( formField.children.length === 0 ) {\n\t\treturn fieldValue;\n\t}\n\n\tconst childrenValues = formField.children.map( ( child ) =>\n\t\tgetFormFieldValue( child, item )\n\t);\n\tif ( ! childrenValues ) {\n\t\treturn fieldValue;\n\t}\n\n\treturn {\n\t\tvalue: fieldValue,\n\t\tchildren: childrenValues,\n\t};\n}\n\n/**\n * Hook that validates a form item and returns an object with error messages for each field.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return Record of field IDs to error messages (undefined means no error).\n */\nexport function useFormValidity< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): { validity: FormValidity; isValid: boolean } {\n\tconst [ formValidity, setFormValidity ] = useState< FormValidity >();\n\tconst customCounterRef = useRef< Record< string, number > >( {} );\n\tconst elementsCounterRef = useRef< Record< string, number > >( {} );\n\tconst previousValuesRef = useRef< Record< string, any > >( {} );\n\n\tconst validate = useCallback( () => {\n\t\tconst promiseHandler = {\n\t\t\tcustomCounterRef,\n\t\t\telementsCounterRef,\n\t\t\tsetFormValidity,\n\t\t\tpath: [],\n\t\t\titem,\n\t\t};\n\n\t\tconst formFieldsToValidate = getFormFieldsToValidate( form, fields );\n\t\tif ( formFieldsToValidate.length === 0 ) {\n\t\t\tsetFormValidity( undefined );\n\t\t\treturn;\n\t\t}\n\n\t\tconst newFormValidity: FormValidity = {};\n\t\tconst untouchedFields: string[] = [];\n\t\tformFieldsToValidate.forEach( ( formField ) => {\n\t\t\t// Skip fields that did not change.\n\t\t\tconst value = getFormFieldValue< Item >( formField, item );\n\t\t\tif (\n\t\t\t\tpreviousValuesRef.current.hasOwnProperty( formField.id ) &&\n\t\t\t\tfastDeepEqual(\n\t\t\t\t\tpreviousValuesRef.current[ formField.id ],\n\t\t\t\t\tvalue\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tuntouchedFields.push( formField.id );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpreviousValuesRef.current[ formField.id ] = value;\n\n\t\t\t// Calculate validity for those fields that changed.\n\t\t\tconst fieldValidity = validateFormField(\n\t\t\t\titem,\n\t\t\t\tformField,\n\t\t\t\tpromiseHandler\n\t\t\t);\n\t\t\tif ( fieldValidity !== undefined ) {\n\t\t\t\tnewFormValidity[ formField.id ] = fieldValidity;\n\t\t\t}\n\t\t} );\n\n\t\tsetFormValidity( ( existingFormValidity ) => {\n\t\t\tlet validity: FormValidity = {\n\t\t\t\t...existingFormValidity,\n\t\t\t\t...newFormValidity,\n\t\t\t};\n\n\t\t\tconst fieldsToKeep = [\n\t\t\t\t...untouchedFields,\n\t\t\t\t...Object.keys( newFormValidity ),\n\t\t\t];\n\t\t\tObject.keys( validity ).forEach( ( key ) => {\n\t\t\t\tif ( validity && ! fieldsToKeep.includes( key ) ) {\n\t\t\t\t\tdelete validity[ key ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tif ( Object.keys( validity ).length === 0 ) {\n\t\t\t\tvalidity = undefined;\n\t\t\t}\n\n\t\t\tconst areEqual = fastDeepEqual( existingFormValidity, validity );\n\t\t\tif ( areEqual ) {\n\t\t\t\treturn existingFormValidity;\n\t\t\t}\n\n\t\t\treturn validity;\n\t\t} );\n\t}, [ item, fields, form ] );\n\n\tuseEffect( () => {\n\t\tvalidate();\n\t}, [ validate ] );\n\n\treturn {\n\t\tvalidity: formValidity,\n\t\tisValid: isFormValid( formValidity ),\n\t};\n}\n\nexport default useFormValidity;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAsB;AACtB,iBAA0B;AAK1B,qBAAyD;AACzD,kBAAmB;AAKnB,yBAA4B;AAC5B,4BAA0B;AAU1B,SAAS,YAAa,cAAkD;AACvE,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AAEA,SAAO,OAAO,OAAQ,YAAa,EAAE,MAAO,CAAE,oBAAqB;AAClE,WAAO,OAAO,QAAS,eAAgB,EAAE;AAAA,MACxC,CAAE,CAAE,KAAK,UAAW,MAAO;AAC1B,YACC,QAAQ,cACR,c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C;AACD;AAEA,IAAO,4BAAQ;",
|
|
6
6
|
"names": ["normalizeForm", "fieldDef", "normalizedField", "normalizeFields", "deepMerge", "fastDeepEqual"]
|
|
7
7
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
BaseControl,
|
|
14
14
|
Button,
|
|
15
|
-
Icon,
|
|
15
|
+
Icon as WCIcon,
|
|
16
16
|
privateApis as componentsPrivateApis,
|
|
17
17
|
__experimentalInputControl as InputControl
|
|
18
18
|
} from "@wordpress/components";
|
|
@@ -205,7 +205,7 @@ function ValidatedDateControl({
|
|
|
205
205
|
),
|
|
206
206
|
children: [
|
|
207
207
|
/* @__PURE__ */ jsx(
|
|
208
|
-
|
|
208
|
+
WCIcon,
|
|
209
209
|
{
|
|
210
210
|
className: "components-validated-control__indicator-icon",
|
|
211
211
|
icon: errorIcon,
|