@wordpress/dataviews 11.1.1-next.76cff8c98.0 → 11.2.1-next.06ee73755.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 +7 -1
- package/build/components/dataviews-filters/input-widget.cjs +1 -1
- package/build/components/dataviews-filters/input-widget.cjs.map +1 -1
- package/build/components/dataviews-layouts/index.cjs +3 -2
- package/build/components/dataviews-layouts/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/list/index.cjs +5 -1
- package/build/components/dataviews-layouts/list/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/{table → utils}/density-picker.cjs +1 -1
- package/build/components/dataviews-layouts/{table → utils}/density-picker.cjs.map +2 -2
- package/build/components/dataviews-view-config/properties-section.cjs +11 -39
- package/build/components/dataviews-view-config/properties-section.cjs.map +2 -2
- package/build/hooks/use-form-validity.cjs +1 -1
- package/build/hooks/use-form-validity.cjs.map +1 -1
- package/build/types/dataviews.cjs.map +1 -1
- package/build-module/components/dataviews-filters/input-widget.mjs +1 -1
- package/build-module/components/dataviews-filters/input-widget.mjs.map +1 -1
- package/build-module/components/dataviews-layouts/index.mjs +3 -2
- package/build-module/components/dataviews-layouts/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/list/index.mjs +5 -1
- package/build-module/components/dataviews-layouts/list/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/{table → utils}/density-picker.mjs +1 -1
- package/build-module/components/dataviews-layouts/utils/density-picker.mjs.map +7 -0
- package/build-module/components/dataviews-view-config/properties-section.mjs +11 -39
- package/build-module/components/dataviews-view-config/properties-section.mjs.map +2 -2
- package/build-module/hooks/use-form-validity.mjs +1 -1
- package/build-module/hooks/use-form-validity.mjs.map +1 -1
- package/build-style/style-rtl.css +49 -5
- package/build-style/style.css +49 -5
- package/build-types/components/dataviews-layouts/index.d.ts +2 -2
- package/build-types/components/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/{table → utils}/density-picker.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/properties-section.d.ts.map +1 -1
- package/build-types/dataform/stories/index.story.d.ts +1 -1
- package/build-types/dataform/stories/validation.d.ts +1 -1
- package/build-types/dataform/stories/validation.d.ts.map +1 -1
- package/build-types/types/dataviews.d.ts +6 -0
- package/build-types/types/dataviews.d.ts.map +1 -1
- package/build-wp/index.js +165 -188
- package/package.json +23 -20
- package/src/components/dataviews-filters/input-widget.tsx +1 -1
- package/src/components/dataviews-layouts/index.ts +2 -1
- package/src/components/dataviews-layouts/list/index.tsx +7 -1
- package/src/components/dataviews-layouts/list/style.scss +65 -0
- package/src/components/dataviews-layouts/{table → utils}/density-picker.tsx +2 -2
- package/src/components/dataviews-view-config/properties-section.tsx +24 -49
- package/src/dataform/stories/index.story.tsx +1 -1
- package/src/dataform/stories/validation.tsx +8 -1
- package/src/hooks/use-form-validity.ts +1 -1
- package/src/types/dataviews.ts +7 -0
- package/build-module/components/dataviews-layouts/table/density-picker.mjs.map +0 -7
- /package/build-types/components/dataviews-layouts/{table → utils}/density-picker.d.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types/dataviews.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement, ReactNode, ComponentProps } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tNormalizedField,\n\tOperator,\n\tOption,\n\tSortDirection,\n} from './field-api';\nimport type { SetSelection } from './private';\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked?: boolean;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Retrieval function to get the elements.\n\t */\n\tgetElements?: () => Promise< Option[] >;\n\n\t/**\n\t * Whether the filter has elements.\n\t */\n\thasElements: boolean;\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The grouping configuration.\n\t */\n\tgroupBy?: {\n\t\t/**\n\t\t * The field to group by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\n\t\t/**\n\t\t * Whether to show the field label in the group header.\n\t\t *\n\t\t * @default true\n\t\t */\n\t\tshowLabel?: boolean;\n\t};\n\n\t/**\n\t * Whether infinite scroll is enabled.\n\t */\n\tinfiniteScrollEnabled?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewActivity extends ViewBase {\n\ttype: 'activity';\n\n\tlayout?: {\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\t};\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerGrid extends ViewBase {\n\ttype: 'pickerGrid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerTable extends ViewBase {\n\ttype: 'pickerTable';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport type View =\n\t| ViewList\n\t| ViewGrid\n\t| ViewTable\n\t| ViewPickerGrid\n\t| ViewPickerTable\n\t| ViewActivity;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n\tempty: ReactNode;\n}\n\nexport type ViewPickerBaseProps< Item > = Omit<\n\tViewBaseProps< Item >,\n\t| 'view'\n\t| 'onChangeView'\n\t// The following props are not supported for pickers.\n\t| 'isItemClickable'\n\t| 'onClickItem'\n\t| 'renderItemLink'\n\t| 'getItemLevel'\n> & {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n};\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewActivityProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewActivity;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport interface ViewPickerGridProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerGrid;\n}\n\nexport interface ViewPickerTableProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerTable;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >\n\t| ViewActivityProps< Item >;\n\nexport type ViewPickerProps< Item > =\n\t| ViewPickerGridProps< Item >\n\t| ViewPickerTableProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n\tactivity?: Omit< ViewActivity, 'type' >;\n\tpickerGrid?: Omit< ViewPickerGrid, 'type' >;\n\tpickerTable?: Omit< ViewPickerTable, 'type' >;\n}\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement, ReactNode, ComponentProps } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tNormalizedField,\n\tOperator,\n\tOption,\n\tSortDirection,\n} from './field-api';\nimport type { SetSelection } from './private';\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked?: boolean;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Retrieval function to get the elements.\n\t */\n\tgetElements?: () => Promise< Option[] >;\n\n\t/**\n\t * Whether the filter has elements.\n\t */\n\thasElements: boolean;\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The grouping configuration.\n\t */\n\tgroupBy?: {\n\t\t/**\n\t\t * The field to group by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\n\t\t/**\n\t\t * Whether to show the field label in the group header.\n\t\t *\n\t\t * @default true\n\t\t */\n\t\tshowLabel?: boolean;\n\t};\n\n\t/**\n\t * Whether infinite scroll is enabled.\n\t */\n\tinfiniteScrollEnabled?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n\n\tlayout?: {\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\t};\n}\n\nexport interface ViewActivity extends ViewBase {\n\ttype: 'activity';\n\n\tlayout?: {\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\t};\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerGrid extends ViewBase {\n\ttype: 'pickerGrid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerTable extends ViewBase {\n\ttype: 'pickerTable';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport type View =\n\t| ViewList\n\t| ViewGrid\n\t| ViewTable\n\t| ViewPickerGrid\n\t| ViewPickerTable\n\t| ViewActivity;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n\tempty: ReactNode;\n}\n\nexport type ViewPickerBaseProps< Item > = Omit<\n\tViewBaseProps< Item >,\n\t| 'view'\n\t| 'onChangeView'\n\t// The following props are not supported for pickers.\n\t| 'isItemClickable'\n\t| 'onClickItem'\n\t| 'renderItemLink'\n\t| 'getItemLevel'\n> & {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n};\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewActivityProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewActivity;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport interface ViewPickerGridProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerGrid;\n}\n\nexport interface ViewPickerTableProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerTable;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >\n\t| ViewActivityProps< Item >;\n\nexport type ViewPickerProps< Item > =\n\t| ViewPickerGridProps< Item >\n\t| ViewPickerTableProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n\tactivity?: Omit< ViewActivity, 'type' >;\n\tpickerGrid?: Omit< ViewPickerGrid, 'type' >;\n\tpickerTable?: Omit< ViewPickerTable, 'type' >;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/dataviews/src/components/dataviews-filters/input-widget.tsx
|
|
2
|
-
import fastDeepEqual from "fast-deep-equal/es6";
|
|
2
|
+
import fastDeepEqual from "fast-deep-equal/es6/index.js";
|
|
3
3
|
import { useEvent } from "@wordpress/compose";
|
|
4
4
|
import { useMemo } from "@wordpress/element";
|
|
5
5
|
import { Flex } from "@wordpress/components";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-filters/input-widget.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useEvent } from '@wordpress/compose';\nimport { useMemo } from '@wordpress/element';\nimport { Flex } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tView,\n\tNormalizedFilter,\n\tNormalizedField,\n\tNormalizedRules,\n} from '../../types';\nimport { getCurrentValue } from './utils';\n\ninterface UserInputWidgetProps {\n\tview: View;\n\tfilter: NormalizedFilter;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< any >[];\n}\n\nexport default function InputWidget( {\n\tfilter,\n\tview,\n\tonChangeView,\n\tfields,\n}: UserInputWidgetProps ) {\n\tconst currentFilter = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\tconst currentValue = getCurrentValue( filter, currentFilter );\n\n\t/*\n\t * We are reusing the field.Edit component for filters. By doing so,\n\t * we get for free a filter control specific to the field type\n\t * and other aspects of the field API (Edit control configuration, etc.).\n\t *\n\t * This approach comes with an issue: the field.Edit controls work with getValue\n\t * and setValue methods, which take an item (Item) as parameter. But, at this point,\n\t * we don't have an item and we don't know how to create one, either.\n\t *\n\t * So, what we do is to prepare the data and the relevant field configuration\n\t * as if Item was a plain object whose keys are the field ids:\n\t *\n\t * {\n\t * [ fieldOne.id ]: value,\n\t * [ fieldTwo.id ]: value,\n\t * }\n\t *\n\t */\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Deactivate validation for filters.\n\t\t\t\tisValid: {} satisfies NormalizedRules< any >,\n\t\t\t\t// Configure getValue/setValue as if Item was a plain object.\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t\tsetValue: ( { value }: { value: any } ) => ( {\n\t\t\t\t\t[ currentField.id ]: value,\n\t\t\t\t} ),\n\t\t\t};\n\t\t}\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst data = useMemo( () => {\n\t\treturn ( view.filters ?? [] ).reduce(\n\t\t\t( acc, activeFilter ) => {\n\t\t\t\t// We can now assume the field is stored as a Item prop.\n\t\t\t\tacc[ activeFilter.field ] = activeFilter.value;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record< string, any >\n\t\t);\n\t}, [ view.filters ] );\n\n\tconst handleChange = useEvent( ( updatedData: Record< string, any > ) => {\n\t\tif ( ! field || ! currentFilter ) {\n\t\t\treturn;\n\t\t}\n\t\tconst nextValue = field.getValue( { item: updatedData } );\n\t\tif ( fastDeepEqual( nextValue, currentValue ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tonChangeView( {\n\t\t\t...view,\n\t\t\tfilters: ( view.filters ?? [] ).map( ( _filter ) =>\n\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\toperator:\n\t\t\t\t\t\t\t\tcurrentFilter.operator || filter.operators[ 0 ],\n\t\t\t\t\t\t\t// Consider empty strings as undefined:\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records\n\t\t\t\t\t\t\t// - empty string as value means \"search empty string\": returns only the records that have an empty string as value\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// In practice, this means the filter will not be able to find an empty string as the value.\n\t\t\t\t\t\t\tvalue: nextValue === '' ? undefined : nextValue,\n\t\t\t\t\t }\n\t\t\t\t\t: _filter\n\t\t\t),\n\t\t} );\n\t} );\n\n\tif ( ! field || ! field.Edit || ! currentFilter ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"dataviews-filters__user-input-widget\"\n\t\t\tgap={ 2.5 }\n\t\t\tdirection=\"column\"\n\t\t>\n\t\t\t<field.Edit\n\t\t\t\thideLabelFromVision\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\toperator={ currentFilter.operator }\n\t\t\t\tonChange={ handleChange }\n\t\t\t/>\n\t\t</Flex>\n\t);\n}\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { useEvent } from '@wordpress/compose';\nimport { useMemo } from '@wordpress/element';\nimport { Flex } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tView,\n\tNormalizedFilter,\n\tNormalizedField,\n\tNormalizedRules,\n} from '../../types';\nimport { getCurrentValue } from './utils';\n\ninterface UserInputWidgetProps {\n\tview: View;\n\tfilter: NormalizedFilter;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< any >[];\n}\n\nexport default function InputWidget( {\n\tfilter,\n\tview,\n\tonChangeView,\n\tfields,\n}: UserInputWidgetProps ) {\n\tconst currentFilter = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\tconst currentValue = getCurrentValue( filter, currentFilter );\n\n\t/*\n\t * We are reusing the field.Edit component for filters. By doing so,\n\t * we get for free a filter control specific to the field type\n\t * and other aspects of the field API (Edit control configuration, etc.).\n\t *\n\t * This approach comes with an issue: the field.Edit controls work with getValue\n\t * and setValue methods, which take an item (Item) as parameter. But, at this point,\n\t * we don't have an item and we don't know how to create one, either.\n\t *\n\t * So, what we do is to prepare the data and the relevant field configuration\n\t * as if Item was a plain object whose keys are the field ids:\n\t *\n\t * {\n\t * [ fieldOne.id ]: value,\n\t * [ fieldTwo.id ]: value,\n\t * }\n\t *\n\t */\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Deactivate validation for filters.\n\t\t\t\tisValid: {} satisfies NormalizedRules< any >,\n\t\t\t\t// Configure getValue/setValue as if Item was a plain object.\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t\tsetValue: ( { value }: { value: any } ) => ( {\n\t\t\t\t\t[ currentField.id ]: value,\n\t\t\t\t} ),\n\t\t\t};\n\t\t}\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst data = useMemo( () => {\n\t\treturn ( view.filters ?? [] ).reduce(\n\t\t\t( acc, activeFilter ) => {\n\t\t\t\t// We can now assume the field is stored as a Item prop.\n\t\t\t\tacc[ activeFilter.field ] = activeFilter.value;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record< string, any >\n\t\t);\n\t}, [ view.filters ] );\n\n\tconst handleChange = useEvent( ( updatedData: Record< string, any > ) => {\n\t\tif ( ! field || ! currentFilter ) {\n\t\t\treturn;\n\t\t}\n\t\tconst nextValue = field.getValue( { item: updatedData } );\n\t\tif ( fastDeepEqual( nextValue, currentValue ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tonChangeView( {\n\t\t\t...view,\n\t\t\tfilters: ( view.filters ?? [] ).map( ( _filter ) =>\n\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\toperator:\n\t\t\t\t\t\t\t\tcurrentFilter.operator || filter.operators[ 0 ],\n\t\t\t\t\t\t\t// Consider empty strings as undefined:\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records\n\t\t\t\t\t\t\t// - empty string as value means \"search empty string\": returns only the records that have an empty string as value\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// In practice, this means the filter will not be able to find an empty string as the value.\n\t\t\t\t\t\t\tvalue: nextValue === '' ? undefined : nextValue,\n\t\t\t\t\t }\n\t\t\t\t\t: _filter\n\t\t\t),\n\t\t} );\n\t} );\n\n\tif ( ! field || ! field.Edit || ! currentFilter ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"dataviews-filters__user-input-widget\"\n\t\t\tgap={ 2.5 }\n\t\t\tdirection=\"column\"\n\t\t>\n\t\t\t<field.Edit\n\t\t\t\thideLabelFromVision\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\toperator={ currentFilter.operator }\n\t\t\t\tonChange={ handleChange }\n\t\t\t/>\n\t\t</Flex>\n\t);\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,OAAO,mBAAmB;AAK1B,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,YAAY;AAWrB,SAAS,uBAAuB;AA2G7B;AAlGY,SAAR,YAA8B;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,gBAAgB,KAAK,SAAS;AAAA,IACnC,CAAE,MAAO,EAAE,UAAU,OAAO;AAAA,EAC7B;AACA,QAAM,eAAe,gBAAiB,QAAQ,aAAc;AAoB5D,QAAM,QAAQ,QAAS,MAAM;AAC5B,UAAM,eAAe,OAAO,KAAM,CAAE,MAAO,EAAE,OAAO,OAAO,KAAM;AACjE,QAAK,cAAe;AACnB,aAAO;AAAA,QACN,GAAG;AAAA;AAAA,QAEH,SAAS,CAAC;AAAA;AAAA,QAEV,UAAU,CAAE,EAAE,KAAK,MAClB,KAAM,aAAa,EAAG;AAAA,QACvB,UAAU,CAAE,EAAE,MAAM,OAAyB;AAAA,UAC5C,CAAE,aAAa,EAAG,GAAG;AAAA,QACtB;AAAA,MACD;AAAA,IACD;AACA,WAAO;AA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from "../../constants.mjs";
|
|
24
24
|
import PreviewSizePicker from "./utils/preview-size-picker.mjs";
|
|
25
|
-
import DensityPicker from "./
|
|
25
|
+
import DensityPicker from "./utils/density-picker.mjs";
|
|
26
26
|
var VIEW_LAYOUTS = [
|
|
27
27
|
{
|
|
28
28
|
type: LAYOUT_TABLE,
|
|
@@ -42,7 +42,8 @@ var VIEW_LAYOUTS = [
|
|
|
42
42
|
type: LAYOUT_LIST,
|
|
43
43
|
label: __("List"),
|
|
44
44
|
component: ViewList,
|
|
45
|
-
icon: isRTL() ? formatListBulletsRTL : formatListBullets
|
|
45
|
+
icon: isRTL() ? formatListBulletsRTL : formatListBullets,
|
|
46
|
+
viewConfigOptions: DensityPicker
|
|
46
47
|
},
|
|
47
48
|
{
|
|
48
49
|
type: LAYOUT_ACTIVITY,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-layouts/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, isRTL } from '@wordpress/i18n';\nimport {\n\tblockTable,\n\tcategory,\n\tformatListBullets,\n\tformatListBulletsRTL,\n\tscheduled,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport ViewTable from './table';\nimport ViewGrid from './grid';\nimport ViewList from './list';\nimport ViewActivity from './activity';\nimport ViewPickerGrid from './picker-grid';\nimport ViewPickerTable from './picker-table';\nimport {\n\tLAYOUT_GRID,\n\tLAYOUT_LIST,\n\tLAYOUT_TABLE,\n\tLAYOUT_ACTIVITY,\n\tLAYOUT_PICKER_GRID,\n\tLAYOUT_PICKER_TABLE,\n} from '../../constants';\nimport PreviewSizePicker from './utils/preview-size-picker';\nimport DensityPicker from './
|
|
5
|
-
"mappings": ";AAGA,SAAS,IAAI,aAAa;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,OAAO,eAAe;AACtB,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,OAAO,kBAAkB;AACzB,OAAO,oBAAoB;AAC3B,OAAO,qBAAqB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAEnB,IAAM,eAAe;AAAA,EAC3B;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,OAAQ;AAAA,IACnB,WAAW;AAAA,IACX,MAAM;AAAA,IACN,mBAAmB;AAAA,EACpB;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,MAAO;AAAA,IAClB,WAAW;AAAA,IACX,MAAM;AAAA,IACN,mBAAmB;AAAA,EACpB;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,MAAO;AAAA,IAClB,WAAW;AAAA,IACX,MAAM,MAAM,IAAI,uBAAuB;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, isRTL } from '@wordpress/i18n';\nimport {\n\tblockTable,\n\tcategory,\n\tformatListBullets,\n\tformatListBulletsRTL,\n\tscheduled,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport ViewTable from './table';\nimport ViewGrid from './grid';\nimport ViewList from './list';\nimport ViewActivity from './activity';\nimport ViewPickerGrid from './picker-grid';\nimport ViewPickerTable from './picker-table';\nimport {\n\tLAYOUT_GRID,\n\tLAYOUT_LIST,\n\tLAYOUT_TABLE,\n\tLAYOUT_ACTIVITY,\n\tLAYOUT_PICKER_GRID,\n\tLAYOUT_PICKER_TABLE,\n} from '../../constants';\nimport PreviewSizePicker from './utils/preview-size-picker';\nimport DensityPicker from './utils/density-picker';\n\nexport const VIEW_LAYOUTS = [\n\t{\n\t\ttype: LAYOUT_TABLE,\n\t\tlabel: __( 'Table' ),\n\t\tcomponent: ViewTable,\n\t\ticon: blockTable,\n\t\tviewConfigOptions: DensityPicker,\n\t},\n\t{\n\t\ttype: LAYOUT_GRID,\n\t\tlabel: __( 'Grid' ),\n\t\tcomponent: ViewGrid,\n\t\ticon: category,\n\t\tviewConfigOptions: PreviewSizePicker,\n\t},\n\t{\n\t\ttype: LAYOUT_LIST,\n\t\tlabel: __( 'List' ),\n\t\tcomponent: ViewList,\n\t\ticon: isRTL() ? formatListBulletsRTL : formatListBullets,\n\t\tviewConfigOptions: DensityPicker,\n\t},\n\t{\n\t\ttype: LAYOUT_ACTIVITY,\n\t\tlabel: __( 'Activity' ),\n\t\tcomponent: ViewActivity,\n\t\ticon: scheduled,\n\t\tviewConfigOptions: DensityPicker,\n\t},\n\t{\n\t\ttype: LAYOUT_PICKER_GRID,\n\t\tlabel: __( 'Grid' ),\n\t\tcomponent: ViewPickerGrid,\n\t\ticon: category,\n\t\tviewConfigOptions: PreviewSizePicker,\n\t\tisPicker: true,\n\t},\n\t{\n\t\ttype: LAYOUT_PICKER_TABLE,\n\t\tlabel: __( 'Table' ),\n\t\tcomponent: ViewPickerTable,\n\t\ticon: blockTable,\n\t\tviewConfigOptions: DensityPicker,\n\t\tisPicker: true,\n\t},\n];\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,IAAI,aAAa;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,OAAO,eAAe;AACtB,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,OAAO,kBAAkB;AACzB,OAAO,oBAAoB;AAC3B,OAAO,qBAAqB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAEnB,IAAM,eAAe;AAAA,EAC3B;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,OAAQ;AAAA,IACnB,WAAW;AAAA,IACX,MAAM;AAAA,IACN,mBAAmB;AAAA,EACpB;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,MAAO;AAAA,IAClB,WAAW;AAAA,IACX,MAAM;AAAA,IACN,mBAAmB;AAAA,EACpB;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,MAAO;AAAA,IAClB,WAAW;AAAA,IACX,MAAM,MAAM,IAAI,uBAAuB;AAAA,IACvC,mBAAmB;AAAA,EACpB;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,UAAW;AAAA,IACtB,WAAW;AAAA,IACX,MAAM;AAAA,IACN,mBAAmB;AAAA,EACpB;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,MAAO;AAAA,IAClB,WAAW;AAAA,IACX,MAAM;AAAA,IACN,mBAAmB;AAAA,IACnB,UAAU;AAAA,EACX;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,OAAQ;AAAA,IACnB,WAAW;AAAA,IACX,MAAM;AAAA,IACN,mBAAmB;AAAA,IACnB,UAAU;AAAA,EACX;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -513,7 +513,11 @@ function ViewList(props) {
|
|
|
513
513
|
{
|
|
514
514
|
id: baseId,
|
|
515
515
|
render: /* @__PURE__ */ jsx("div", {}),
|
|
516
|
-
className: clsx("dataviews-view-list", className
|
|
516
|
+
className: clsx("dataviews-view-list", className, {
|
|
517
|
+
[`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
|
|
518
|
+
view.layout.density
|
|
519
|
+
)
|
|
520
|
+
}),
|
|
517
521
|
role: view.infiniteScrollEnabled ? "feed" : "grid",
|
|
518
522
|
activeId: activeCompositeId,
|
|
519
523
|
setActiveId: setActiveCompositeId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/dataviews-layouts/list/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId, usePrevious } from '@wordpress/compose';\nimport {\n\tButton,\n\tprivateApis as componentsPrivateApis,\n\tSpinner,\n\tVisuallyHidden,\n\tComposite,\n} from '@wordpress/components';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseContext,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { moreVertical } from '@wordpress/icons';\nimport { useRegistry } from '@wordpress/data';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport { ActionsMenuGroup, ActionModal } from '../../dataviews-item-actions';\nimport DataViewsContext from '../../dataviews-context';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewList as ViewListType,\n\tViewListProps,\n\tActionModal as ActionModalType,\n} from '../../../types';\nimport getDataByGroup from '../utils/get-data-by-group';\n\ninterface ListViewItemProps< Item > {\n\tview: ViewListType;\n\tactions: Action< Item >[];\n\tidPrefix: string;\n\tisSelected: boolean;\n\titem: Item;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tonSelect: ( item: Item ) => void;\n\totherFields: NormalizedField< Item >[];\n\tonDropdownTriggerKeyDown: React.KeyboardEventHandler< HTMLButtonElement >;\n\tposinset?: number;\n}\n\nconst { Menu } = unlock( componentsPrivateApis );\n\nfunction generateItemWrapperCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-item-wrapper`;\n}\nfunction generatePrimaryActionCompositeId(\n\tidPrefix: string,\n\tprimaryActionId: string\n) {\n\treturn `${ idPrefix }-primary-action-${ primaryActionId }`;\n}\nfunction generateDropdownTriggerCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-dropdown`;\n}\n\nfunction PrimaryActionGridCell< Item >( {\n\tidPrefix,\n\tprimaryAction,\n\titem,\n}: {\n\tidPrefix: string;\n\tprimaryAction: Action< Item >;\n\titem: Item;\n} ) {\n\tconst registry = useRegistry();\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\n\tconst compositeItemId = generatePrimaryActionCompositeId(\n\t\tidPrefix,\n\t\tprimaryAction.id\n\t);\n\n\tconst label =\n\t\ttypeof primaryAction.label === 'string'\n\t\t\t? primaryAction.label\n\t\t\t: primaryAction.label( [ item ] );\n\n\treturn 'RenderModal' in primaryAction ? (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\ttext={ label }\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ isModalOpen && (\n\t\t\t\t\t<ActionModal< Item >\n\t\t\t\t\t\taction={ primaryAction }\n\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Composite.Item>\n\t\t</div>\n\t) : (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tprimaryAction.callback( [ item ], { registry } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</Button>\n\t\t\t\t}\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction ListItem< Item >( {\n\tview,\n\tactions,\n\tidPrefix,\n\tisSelected,\n\titem,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tonSelect,\n\totherFields,\n\tonDropdownTriggerKeyDown,\n\tposinset,\n}: ListViewItemProps< Item > ) {\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst itemRef = useRef< HTMLDivElement >( null );\n\tconst labelId = `${ idPrefix }-label`;\n\tconst descriptionId = `${ idPrefix }-description`;\n\n\tconst registry = useRegistry();\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst [ activeModalAction, setActiveModalAction ] = useState(\n\t\tnull as ActionModalType< Item > | null\n\t);\n\tconst handleHover: React.MouseEventHandler = ( { type } ) => {\n\t\tconst isHover = type === 'mouseenter';\n\t\tsetIsHovered( isHover );\n\t};\n\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\tuseEffect( () => {\n\t\tif ( isSelected ) {\n\t\t\titemRef.current?.scrollIntoView( {\n\t\t\t\tbehavior: 'auto',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\t}, [ isSelected ] );\n\n\tconst { primaryAction, eligibleActions } = useMemo( () => {\n\t\t// If an action is eligible for all items, doesn't need\n\t\t// to provide the `isEligible` function.\n\t\tconst _eligibleActions = actions.filter(\n\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t);\n\t\tconst _primaryActions = _eligibleActions.filter(\n\t\t\t( action ) => action.isPrimary\n\t\t);\n\t\treturn {\n\t\t\tprimaryAction: _primaryActions[ 0 ],\n\t\t\teligibleActions: _eligibleActions,\n\t\t};\n\t}, [ actions, item ] );\n\n\tconst hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;\n\n\tconst renderedMediaField =\n\t\tshowMedia && mediaField?.render ? (\n\t\t\t<div className=\"dataviews-view-list__media-wrapper\">\n\t\t\t\t<mediaField.render\n\t\t\t\t\titem={ item }\n\t\t\t\t\tfield={ mediaField }\n\t\t\t\t\tconfig={ { sizes: '52px' } }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t) : null;\n\n\tconst renderedTitleField =\n\t\tshowTitle && titleField?.render ? (\n\t\t\t<titleField.render item={ item } field={ titleField } />\n\t\t) : null;\n\n\tconst usedActions = eligibleActions?.length > 0 && (\n\t\t<Stack\n\t\t\tdirection=\"row\"\n\t\t\tgap=\"sm\"\n\t\t\tclassName=\"dataviews-view-list__item-actions\"\n\t\t>\n\t\t\t{ primaryAction && (\n\t\t\t\t<PrimaryActionGridCell\n\t\t\t\t\tidPrefix={ idPrefix }\n\t\t\t\t\tprimaryAction={ primaryAction }\n\t\t\t\t\titem={ item }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! hasOnlyOnePrimaryAction && (\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Menu placement=\"bottom-end\">\n\t\t\t\t\t\t<Menu.TriggerButton\n\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tid={ generateDropdownTriggerCompositeId(\n\t\t\t\t\t\t\t\t\t\tidPrefix\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Actions' ) }\n\t\t\t\t\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\t\t\t\t\tdisabled={ ! actions.length }\n\t\t\t\t\t\t\t\t\t\t\tonKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t<ActionsMenuGroup\n\t\t\t\t\t\t\t\tactions={ eligibleActions }\n\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\tregistry={ registry }\n\t\t\t\t\t\t\t\tsetActiveModalAction={ setActiveModalAction }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Menu.Popover>\n\t\t\t\t\t</Menu>\n\t\t\t\t\t{ !! activeModalAction && (\n\t\t\t\t\t\t<ActionModal\n\t\t\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</Stack>\n\t);\n\n\treturn (\n\t\t<Composite.Row\n\t\t\tref={ itemRef }\n\t\t\trender={\n\t\t\t\t/* aria-posinset breaks Composite.Row if passed to it directly. */\n\t\t\t\t<div\n\t\t\t\t\taria-posinset={ posinset }\n\t\t\t\t\taria-setsize={\n\t\t\t\t\t\tinfiniteScrollEnabled\n\t\t\t\t\t\t\t? paginationInfo.totalItems\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t}\n\t\t\trole={ infiniteScrollEnabled ? 'article' : 'row' }\n\t\t\tclassName={ clsx( {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'is-hovered': isHovered,\n\t\t\t} ) }\n\t\t\tonMouseEnter={ handleHover }\n\t\t\tonMouseLeave={ handleHover }\n\t\t>\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-view-list__item-wrapper\"\n\t\t\t>\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\tid={ generateItemWrapperCompositeId( idPrefix ) }\n\t\t\t\t\t\taria-pressed={ isSelected }\n\t\t\t\t\t\taria-labelledby={ labelId }\n\t\t\t\t\t\taria-describedby={ descriptionId }\n\t\t\t\t\t\tclassName=\"dataviews-view-list__item\"\n\t\t\t\t\t\tonClick={ () => onSelect( item ) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\tgap=\"sm\"\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\tstyle={ { flex: 1 } }\n\t\t\t\t>\n\t\t\t\t\t{ renderedMediaField }\n\t\t\t\t\t<Stack\n\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\tgap=\"2xs\"\n\t\t\t\t\t\tclassName=\"dataviews-view-list__field-wrapper\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"row\" align=\"center\">\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"dataviews-title-field\"\n\t\t\t\t\t\t\t\tid={ labelId }\n\t\t\t\t\t\t\t\tstyle={ { flex: 1 } }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ renderedTitleField }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ usedActions }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t{ showDescription && descriptionField?.render && (\n\t\t\t\t\t\t\t<div className=\"dataviews-view-list__field\">\n\t\t\t\t\t\t\t\t<descriptionField.render\n\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\tfield={ descriptionField }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"dataviews-view-list__fields\"\n\t\t\t\t\t\t\tid={ descriptionId }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ otherFields.map( ( field ) => (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field-label\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t\t\t<span className=\"dataviews-view-list__field-value\">\n\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Stack>\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t</Composite.Row>\n\t);\n}\n\nfunction isDefined< T >( item: T | undefined ): item is T {\n\treturn !! item;\n}\n\nexport default function ViewList< Item >( props: ViewListProps< Item > ) {\n\tconst {\n\t\tactions,\n\t\tdata,\n\t\tfields,\n\t\tgetItemId,\n\t\tisLoading,\n\t\tonChangeSelection,\n\t\tselection,\n\t\tview,\n\t\tclassName,\n\t\tempty,\n\t} = props;\n\tconst baseId = useInstanceId( ViewList, 'view-list' );\n\n\tconst selectedItem = data?.findLast( ( item ) =>\n\t\tselection.includes( getItemId( item ) )\n\t);\n\tconst titleField = fields.find( ( field ) => field.id === view.titleField );\n\tconst mediaField = fields.find( ( field ) => field.id === view.mediaField );\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view.descriptionField\n\t);\n\tconst otherFields = ( view?.fields ?? [] )\n\t\t.map( ( fieldId ) => fields.find( ( f ) => fieldId === f.id ) )\n\t\t.filter( isDefined );\n\n\tconst onSelect = ( item: Item ) =>\n\t\tonChangeSelection( [ getItemId( item ) ] );\n\n\tconst generateCompositeItemIdPrefix = useCallback(\n\t\t( item: Item ) => `${ baseId }-${ getItemId( item ) }`,\n\t\t[ baseId, getItemId ]\n\t);\n\n\tconst isActiveCompositeItem = useCallback(\n\t\t( item: Item, idToCheck: string ) => {\n\t\t\t// All composite items use the same prefix in their IDs.\n\t\t\treturn idToCheck.startsWith(\n\t\t\t\tgenerateCompositeItemIdPrefix( item )\n\t\t\t);\n\t\t},\n\t\t[ generateCompositeItemIdPrefix ]\n\t);\n\n\t// Controlled state for the active composite item.\n\tconst [ activeCompositeId, setActiveCompositeId ] = useState<\n\t\tstring | null | undefined\n\t>( undefined );\n\n\t// Update the active composite item when the selected item changes.\n\tuseEffect( () => {\n\t\tif ( selectedItem ) {\n\t\t\tsetActiveCompositeId(\n\t\t\t\tgenerateItemWrapperCompositeId(\n\t\t\t\t\tgenerateCompositeItemIdPrefix( selectedItem )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}, [ selectedItem, generateCompositeItemIdPrefix ] );\n\n\tconst activeItemIndex = data.findIndex( ( item ) =>\n\t\tisActiveCompositeItem( item, activeCompositeId ?? '' )\n\t);\n\tconst previousActiveItemIndex = usePrevious( activeItemIndex );\n\tconst isActiveIdInList = activeItemIndex !== -1;\n\n\tconst selectCompositeItem = useCallback(\n\t\t(\n\t\t\ttargetIndex: number,\n\t\t\t// Allows invokers to specify a custom function to generate the\n\t\t\t// target composite item ID\n\t\t\tgenerateCompositeId: ( idPrefix: string ) => string\n\t\t) => {\n\t\t\t// Clamping between 0 and data.length - 1 to avoid out of bounds.\n\t\t\tconst clampedIndex = Math.min(\n\t\t\t\tdata.length - 1,\n\t\t\t\tMath.max( 0, targetIndex )\n\t\t\t);\n\t\t\tif ( ! data[ clampedIndex ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst itemIdPrefix = generateCompositeItemIdPrefix(\n\t\t\t\tdata[ clampedIndex ]\n\t\t\t);\n\t\t\tconst targetCompositeItemId = generateCompositeId( itemIdPrefix );\n\n\t\t\tsetActiveCompositeId( targetCompositeItemId );\n\t\t\tdocument.getElementById( targetCompositeItemId )?.focus();\n\t\t},\n\t\t[ data, generateCompositeItemIdPrefix ]\n\t);\n\n\t// Select a new active composite item when the current active item\n\t// is removed from the list.\n\tuseEffect( () => {\n\t\tconst wasActiveIdInList =\n\t\t\tpreviousActiveItemIndex !== undefined &&\n\t\t\tpreviousActiveItemIndex !== -1;\n\t\tif ( ! isActiveIdInList && wasActiveIdInList ) {\n\t\t\t// By picking `previousActiveItemIndex` as the next item index, we are\n\t\t\t// basically picking the item that would have been after the deleted one.\n\t\t\t// If the previously active (and removed) item was the last of the list,\n\t\t\t// we will select the item before it \u2014 which is the new last item.\n\t\t\tselectCompositeItem(\n\t\t\t\tpreviousActiveItemIndex,\n\t\t\t\tgenerateItemWrapperCompositeId\n\t\t\t);\n\t\t}\n\t}, [ isActiveIdInList, selectCompositeItem, previousActiveItemIndex ] );\n\n\t// Prevent the default behavior (open dropdown menu) and instead select the\n\t// dropdown menu trigger on the previous/next row.\n\t// https://github.com/ariakit/ariakit/issues/3768\n\tconst onDropdownTriggerKeyDown = useCallback(\n\t\t( event: React.KeyboardEvent< HTMLButtonElement > ) => {\n\t\t\tif ( event.key === 'ArrowDown' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the next row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex + 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ( event.key === 'ArrowUp' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the previous row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex - 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ selectCompositeItem, activeItemIndex ]\n\t);\n\n\tconst hasData = data?.length;\n\tif ( ! hasData ) {\n\t\treturn (\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>\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</div>\n\t\t);\n\t}\n\n\tconst groupField = view.groupBy?.field\n\t\t? fields.find( ( field ) => field.id === view.groupBy?.field )\n\t\t: null;\n\tconst dataByGroup = groupField ? getDataByGroup( data, groupField ) : null;\n\n\t// Render data grouped by field\n\tif ( hasData && groupField && dataByGroup ) {\n\t\treturn (\n\t\t\t<Composite\n\t\t\t\tid={ `${ baseId }` }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName=\"dataviews-view-list__group\"\n\t\t\t\trole=\"grid\"\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tgap=\"md\"\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-list', className ) }\n\t\t\t\t>\n\t\t\t\t\t{ Array.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tkey={ groupName }\n\t\t\t\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<h3 className=\"dataviews-view-list__group-header\">\n\t\t\t\t\t\t\t\t\t{ view.groupBy?.showLabel === false\n\t\t\t\t\t\t\t\t\t\t? groupName\n\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t// translators: 1: The label of the field e.g. \"Date\". 2: The value of the field, e.g.: \"May 2022\".\n\t\t\t\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\t\t\t\tgroupField.label,\n\t\t\t\t\t\t\t\t\t\t\t\tgroupName\n\t\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t</h3>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst id =\n\t\t\t\t\t\t\t\t\t\tgenerateCompositeItemIdPrefix( item );\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t)\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</Composite>\n\t\t);\n\t}\n\n\t// Render ungrouped data\n\treturn (\n\t\t<>\n\t\t\t<Composite\n\t\t\t\tid={ baseId }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName={ clsx( 'dataviews-view-list', className ) }\n\t\t\t\trole={ view.infiniteScrollEnabled ? 'feed' : 'grid' }\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t>\n\t\t\t\t{ data.map( ( item, index ) => {\n\t\t\t\t\tconst id = generateCompositeItemIdPrefix( item );\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tposinset={\n\t\t\t\t\t\t\t\tview.infiniteScrollEnabled\n\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</Composite>\n\t\t\t{ hasData && isLoading && (\n\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n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,KAAM,uBAAuB,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId, usePrevious } from '@wordpress/compose';\nimport {\n\tButton,\n\tprivateApis as componentsPrivateApis,\n\tSpinner,\n\tVisuallyHidden,\n\tComposite,\n} from '@wordpress/components';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseContext,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { moreVertical } from '@wordpress/icons';\nimport { useRegistry } from '@wordpress/data';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../../lock-unlock';\nimport { ActionsMenuGroup, ActionModal } from '../../dataviews-item-actions';\nimport DataViewsContext from '../../dataviews-context';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewList as ViewListType,\n\tViewListProps,\n\tActionModal as ActionModalType,\n} from '../../../types';\nimport getDataByGroup from '../utils/get-data-by-group';\n\ninterface ListViewItemProps< Item > {\n\tview: ViewListType;\n\tactions: Action< Item >[];\n\tidPrefix: string;\n\tisSelected: boolean;\n\titem: Item;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tonSelect: ( item: Item ) => void;\n\totherFields: NormalizedField< Item >[];\n\tonDropdownTriggerKeyDown: React.KeyboardEventHandler< HTMLButtonElement >;\n\tposinset?: number;\n}\n\nconst { Menu } = unlock( componentsPrivateApis );\n\nfunction generateItemWrapperCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-item-wrapper`;\n}\nfunction generatePrimaryActionCompositeId(\n\tidPrefix: string,\n\tprimaryActionId: string\n) {\n\treturn `${ idPrefix }-primary-action-${ primaryActionId }`;\n}\nfunction generateDropdownTriggerCompositeId( idPrefix: string ) {\n\treturn `${ idPrefix }-dropdown`;\n}\n\nfunction PrimaryActionGridCell< Item >( {\n\tidPrefix,\n\tprimaryAction,\n\titem,\n}: {\n\tidPrefix: string;\n\tprimaryAction: Action< Item >;\n\titem: Item;\n} ) {\n\tconst registry = useRegistry();\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\n\tconst compositeItemId = generatePrimaryActionCompositeId(\n\t\tidPrefix,\n\t\tprimaryAction.id\n\t);\n\n\tconst label =\n\t\ttypeof primaryAction.label === 'string'\n\t\t\t? primaryAction.label\n\t\t\t: primaryAction.label( [ item ] );\n\n\treturn 'RenderModal' in primaryAction ? (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\ttext={ label }\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ isModalOpen && (\n\t\t\t\t\t<ActionModal< Item >\n\t\t\t\t\t\taction={ primaryAction }\n\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Composite.Item>\n\t\t</div>\n\t) : (\n\t\t<div role=\"gridcell\" key={ primaryAction.id }>\n\t\t\t<Composite.Item\n\t\t\t\tid={ compositeItemId }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdisabled={ !! primaryAction.disabled }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tprimaryAction.callback( [ item ], { registry } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</Button>\n\t\t\t\t}\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction ListItem< Item >( {\n\tview,\n\tactions,\n\tidPrefix,\n\tisSelected,\n\titem,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tonSelect,\n\totherFields,\n\tonDropdownTriggerKeyDown,\n\tposinset,\n}: ListViewItemProps< Item > ) {\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst itemRef = useRef< HTMLDivElement >( null );\n\tconst labelId = `${ idPrefix }-label`;\n\tconst descriptionId = `${ idPrefix }-description`;\n\n\tconst registry = useRegistry();\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst [ activeModalAction, setActiveModalAction ] = useState(\n\t\tnull as ActionModalType< Item > | null\n\t);\n\tconst handleHover: React.MouseEventHandler = ( { type } ) => {\n\t\tconst isHover = type === 'mouseenter';\n\t\tsetIsHovered( isHover );\n\t};\n\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\tuseEffect( () => {\n\t\tif ( isSelected ) {\n\t\t\titemRef.current?.scrollIntoView( {\n\t\t\t\tbehavior: 'auto',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\t}, [ isSelected ] );\n\n\tconst { primaryAction, eligibleActions } = useMemo( () => {\n\t\t// If an action is eligible for all items, doesn't need\n\t\t// to provide the `isEligible` function.\n\t\tconst _eligibleActions = actions.filter(\n\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t);\n\t\tconst _primaryActions = _eligibleActions.filter(\n\t\t\t( action ) => action.isPrimary\n\t\t);\n\t\treturn {\n\t\t\tprimaryAction: _primaryActions[ 0 ],\n\t\t\teligibleActions: _eligibleActions,\n\t\t};\n\t}, [ actions, item ] );\n\n\tconst hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;\n\n\tconst renderedMediaField =\n\t\tshowMedia && mediaField?.render ? (\n\t\t\t<div className=\"dataviews-view-list__media-wrapper\">\n\t\t\t\t<mediaField.render\n\t\t\t\t\titem={ item }\n\t\t\t\t\tfield={ mediaField }\n\t\t\t\t\tconfig={ { sizes: '52px' } }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t) : null;\n\n\tconst renderedTitleField =\n\t\tshowTitle && titleField?.render ? (\n\t\t\t<titleField.render item={ item } field={ titleField } />\n\t\t) : null;\n\n\tconst usedActions = eligibleActions?.length > 0 && (\n\t\t<Stack\n\t\t\tdirection=\"row\"\n\t\t\tgap=\"sm\"\n\t\t\tclassName=\"dataviews-view-list__item-actions\"\n\t\t>\n\t\t\t{ primaryAction && (\n\t\t\t\t<PrimaryActionGridCell\n\t\t\t\t\tidPrefix={ idPrefix }\n\t\t\t\t\tprimaryAction={ primaryAction }\n\t\t\t\t\titem={ item }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! hasOnlyOnePrimaryAction && (\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Menu placement=\"bottom-end\">\n\t\t\t\t\t\t<Menu.TriggerButton\n\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\tid={ generateDropdownTriggerCompositeId(\n\t\t\t\t\t\t\t\t\t\tidPrefix\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Actions' ) }\n\t\t\t\t\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\t\t\t\t\tdisabled={ ! actions.length }\n\t\t\t\t\t\t\t\t\t\t\tonKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Menu.Popover>\n\t\t\t\t\t\t\t<ActionsMenuGroup\n\t\t\t\t\t\t\t\tactions={ eligibleActions }\n\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\tregistry={ registry }\n\t\t\t\t\t\t\t\tsetActiveModalAction={ setActiveModalAction }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Menu.Popover>\n\t\t\t\t\t</Menu>\n\t\t\t\t\t{ !! activeModalAction && (\n\t\t\t\t\t\t<ActionModal\n\t\t\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</Stack>\n\t);\n\n\treturn (\n\t\t<Composite.Row\n\t\t\tref={ itemRef }\n\t\t\trender={\n\t\t\t\t/* aria-posinset breaks Composite.Row if passed to it directly. */\n\t\t\t\t<div\n\t\t\t\t\taria-posinset={ posinset }\n\t\t\t\t\taria-setsize={\n\t\t\t\t\t\tinfiniteScrollEnabled\n\t\t\t\t\t\t\t? paginationInfo.totalItems\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t}\n\t\t\trole={ infiniteScrollEnabled ? 'article' : 'row' }\n\t\t\tclassName={ clsx( {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t\t'is-hovered': isHovered,\n\t\t\t} ) }\n\t\t\tonMouseEnter={ handleHover }\n\t\t\tonMouseLeave={ handleHover }\n\t\t>\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tclassName=\"dataviews-view-list__item-wrapper\"\n\t\t\t>\n\t\t\t\t<div role=\"gridcell\">\n\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\tid={ generateItemWrapperCompositeId( idPrefix ) }\n\t\t\t\t\t\taria-pressed={ isSelected }\n\t\t\t\t\t\taria-labelledby={ labelId }\n\t\t\t\t\t\taria-describedby={ descriptionId }\n\t\t\t\t\t\tclassName=\"dataviews-view-list__item\"\n\t\t\t\t\t\tonClick={ () => onSelect( item ) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\tgap=\"sm\"\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\tstyle={ { flex: 1 } }\n\t\t\t\t>\n\t\t\t\t\t{ renderedMediaField }\n\t\t\t\t\t<Stack\n\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\tgap=\"2xs\"\n\t\t\t\t\t\tclassName=\"dataviews-view-list__field-wrapper\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"row\" align=\"center\">\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"dataviews-title-field\"\n\t\t\t\t\t\t\t\tid={ labelId }\n\t\t\t\t\t\t\t\tstyle={ { flex: 1 } }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ renderedTitleField }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ usedActions }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t{ showDescription && descriptionField?.render && (\n\t\t\t\t\t\t\t<div className=\"dataviews-view-list__field\">\n\t\t\t\t\t\t\t\t<descriptionField.render\n\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\tfield={ descriptionField }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"dataviews-view-list__fields\"\n\t\t\t\t\t\t\tid={ descriptionId }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ otherFields.map( ( field ) => (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tkey={ field.id }\n\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-list__field-label\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t\t\t<span className=\"dataviews-view-list__field-value\">\n\t\t\t\t\t\t\t\t\t\t<field.render\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Stack>\n\t\t\t\t</Stack>\n\t\t\t</Stack>\n\t\t</Composite.Row>\n\t);\n}\n\nfunction isDefined< T >( item: T | undefined ): item is T {\n\treturn !! item;\n}\n\nexport default function ViewList< Item >( props: ViewListProps< Item > ) {\n\tconst {\n\t\tactions,\n\t\tdata,\n\t\tfields,\n\t\tgetItemId,\n\t\tisLoading,\n\t\tonChangeSelection,\n\t\tselection,\n\t\tview,\n\t\tclassName,\n\t\tempty,\n\t} = props;\n\tconst baseId = useInstanceId( ViewList, 'view-list' );\n\n\tconst selectedItem = data?.findLast( ( item ) =>\n\t\tselection.includes( getItemId( item ) )\n\t);\n\tconst titleField = fields.find( ( field ) => field.id === view.titleField );\n\tconst mediaField = fields.find( ( field ) => field.id === view.mediaField );\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view.descriptionField\n\t);\n\tconst otherFields = ( view?.fields ?? [] )\n\t\t.map( ( fieldId ) => fields.find( ( f ) => fieldId === f.id ) )\n\t\t.filter( isDefined );\n\n\tconst onSelect = ( item: Item ) =>\n\t\tonChangeSelection( [ getItemId( item ) ] );\n\n\tconst generateCompositeItemIdPrefix = useCallback(\n\t\t( item: Item ) => `${ baseId }-${ getItemId( item ) }`,\n\t\t[ baseId, getItemId ]\n\t);\n\n\tconst isActiveCompositeItem = useCallback(\n\t\t( item: Item, idToCheck: string ) => {\n\t\t\t// All composite items use the same prefix in their IDs.\n\t\t\treturn idToCheck.startsWith(\n\t\t\t\tgenerateCompositeItemIdPrefix( item )\n\t\t\t);\n\t\t},\n\t\t[ generateCompositeItemIdPrefix ]\n\t);\n\n\t// Controlled state for the active composite item.\n\tconst [ activeCompositeId, setActiveCompositeId ] = useState<\n\t\tstring | null | undefined\n\t>( undefined );\n\n\t// Update the active composite item when the selected item changes.\n\tuseEffect( () => {\n\t\tif ( selectedItem ) {\n\t\t\tsetActiveCompositeId(\n\t\t\t\tgenerateItemWrapperCompositeId(\n\t\t\t\t\tgenerateCompositeItemIdPrefix( selectedItem )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}, [ selectedItem, generateCompositeItemIdPrefix ] );\n\n\tconst activeItemIndex = data.findIndex( ( item ) =>\n\t\tisActiveCompositeItem( item, activeCompositeId ?? '' )\n\t);\n\tconst previousActiveItemIndex = usePrevious( activeItemIndex );\n\tconst isActiveIdInList = activeItemIndex !== -1;\n\n\tconst selectCompositeItem = useCallback(\n\t\t(\n\t\t\ttargetIndex: number,\n\t\t\t// Allows invokers to specify a custom function to generate the\n\t\t\t// target composite item ID\n\t\t\tgenerateCompositeId: ( idPrefix: string ) => string\n\t\t) => {\n\t\t\t// Clamping between 0 and data.length - 1 to avoid out of bounds.\n\t\t\tconst clampedIndex = Math.min(\n\t\t\t\tdata.length - 1,\n\t\t\t\tMath.max( 0, targetIndex )\n\t\t\t);\n\t\t\tif ( ! data[ clampedIndex ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst itemIdPrefix = generateCompositeItemIdPrefix(\n\t\t\t\tdata[ clampedIndex ]\n\t\t\t);\n\t\t\tconst targetCompositeItemId = generateCompositeId( itemIdPrefix );\n\n\t\t\tsetActiveCompositeId( targetCompositeItemId );\n\t\t\tdocument.getElementById( targetCompositeItemId )?.focus();\n\t\t},\n\t\t[ data, generateCompositeItemIdPrefix ]\n\t);\n\n\t// Select a new active composite item when the current active item\n\t// is removed from the list.\n\tuseEffect( () => {\n\t\tconst wasActiveIdInList =\n\t\t\tpreviousActiveItemIndex !== undefined &&\n\t\t\tpreviousActiveItemIndex !== -1;\n\t\tif ( ! isActiveIdInList && wasActiveIdInList ) {\n\t\t\t// By picking `previousActiveItemIndex` as the next item index, we are\n\t\t\t// basically picking the item that would have been after the deleted one.\n\t\t\t// If the previously active (and removed) item was the last of the list,\n\t\t\t// we will select the item before it \u2014 which is the new last item.\n\t\t\tselectCompositeItem(\n\t\t\t\tpreviousActiveItemIndex,\n\t\t\t\tgenerateItemWrapperCompositeId\n\t\t\t);\n\t\t}\n\t}, [ isActiveIdInList, selectCompositeItem, previousActiveItemIndex ] );\n\n\t// Prevent the default behavior (open dropdown menu) and instead select the\n\t// dropdown menu trigger on the previous/next row.\n\t// https://github.com/ariakit/ariakit/issues/3768\n\tconst onDropdownTriggerKeyDown = useCallback(\n\t\t( event: React.KeyboardEvent< HTMLButtonElement > ) => {\n\t\t\tif ( event.key === 'ArrowDown' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the next row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex + 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ( event.key === 'ArrowUp' ) {\n\t\t\t\t// Select the dropdown menu trigger item in the previous row.\n\t\t\t\tevent.preventDefault();\n\t\t\t\tselectCompositeItem(\n\t\t\t\t\tactiveItemIndex - 1,\n\t\t\t\t\tgenerateDropdownTriggerCompositeId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ selectCompositeItem, activeItemIndex ]\n\t);\n\n\tconst hasData = data?.length;\n\tif ( ! hasData ) {\n\t\treturn (\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>\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</div>\n\t\t);\n\t}\n\n\tconst groupField = view.groupBy?.field\n\t\t? fields.find( ( field ) => field.id === view.groupBy?.field )\n\t\t: null;\n\tconst dataByGroup = groupField ? getDataByGroup( data, groupField ) : null;\n\n\t// Render data grouped by field\n\tif ( hasData && groupField && dataByGroup ) {\n\t\treturn (\n\t\t\t<Composite\n\t\t\t\tid={ `${ baseId }` }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName=\"dataviews-view-list__group\"\n\t\t\t\trole=\"grid\"\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t>\n\t\t\t\t<Stack\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tgap=\"md\"\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-list', className ) }\n\t\t\t\t>\n\t\t\t\t\t{ Array.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<Stack\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tkey={ groupName }\n\t\t\t\t\t\t\t\tgap=\"xs\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<h3 className=\"dataviews-view-list__group-header\">\n\t\t\t\t\t\t\t\t\t{ view.groupBy?.showLabel === false\n\t\t\t\t\t\t\t\t\t\t? groupName\n\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t// translators: 1: The label of the field e.g. \"Date\". 2: The value of the field, e.g.: \"May 2022\".\n\t\t\t\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\t\t\t\tgroupField.label,\n\t\t\t\t\t\t\t\t\t\t\t\tgroupName\n\t\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t</h3>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst id =\n\t\t\t\t\t\t\t\t\t\tgenerateCompositeItemIdPrefix( item );\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\t\t\t\t\t\tdescriptionField\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</Stack>\n\t\t\t\t\t\t)\n\t\t\t\t\t) }\n\t\t\t\t</Stack>\n\t\t\t</Composite>\n\t\t);\n\t}\n\n\t// Render ungrouped data\n\treturn (\n\t\t<>\n\t\t\t<Composite\n\t\t\t\tid={ baseId }\n\t\t\t\trender={ <div /> }\n\t\t\t\tclassName={ clsx( 'dataviews-view-list', className, {\n\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t),\n\t\t\t\t} ) }\n\t\t\t\trole={ view.infiniteScrollEnabled ? 'feed' : 'grid' }\n\t\t\t\tactiveId={ activeCompositeId }\n\t\t\t\tsetActiveId={ setActiveCompositeId }\n\t\t\t>\n\t\t\t\t{ data.map( ( item, index ) => {\n\t\t\t\t\tconst id = generateCompositeItemIdPrefix( item );\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ListItem\n\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tidPrefix={ id }\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tisSelected={ item === selectedItem }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\totherFields={ otherFields }\n\t\t\t\t\t\t\tonDropdownTriggerKeyDown={\n\t\t\t\t\t\t\t\tonDropdownTriggerKeyDown\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tposinset={\n\t\t\t\t\t\t\t\tview.infiniteScrollEnabled\n\t\t\t\t\t\t\t\t\t? index + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</Composite>\n\t\t\t{ hasData && isLoading && (\n\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,eAAe,mBAAmB;AAC3C;AAAA,EACC;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AAKtB,SAAS,cAAc;AACvB,SAAS,kBAAkB,mBAAmB;AAC9C,OAAO,sBAAsB;AAQ7B,OAAO,oBAAoB;AA2DtB,SA0fH,UA1fG,KAoIA,YApIA;AA1CL,IAAM,EAAE,KAAK,IAAI,OAAQ,qBAAsB;AAE/C,SAAS,+BAAgC,UAAmB;AAC3D,SAAO,GAAI,QAAS;AACrB;AACA,SAAS,iCACR,UACA,iBACC;AACD,SAAO,GAAI,QAAS,mBAAoB,eAAgB;AACzD;AACA,SAAS,mCAAoC,UAAmB;AAC/D,SAAO,GAAI,QAAS;AACrB;AAEA,SAAS,sBAA+B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACD,GAII;AACH,QAAM,WAAW,YAAY;AAC7B,QAAM,CAAE,aAAa,cAAe,IAAI,SAAU,KAAM;AAExD,QAAM,kBAAkB;AAAA,IACvB;AAAA,IACA,cAAc;AAAA,EACf;AAEA,QAAM,QACL,OAAO,cAAc,UAAU,WAC5B,cAAc,QACd,cAAc,MAAO,CAAE,IAAK,CAAE;AAElC,SAAO,iBAAiB,gBACvB,oBAAC,SAAI,MAAK,YACT;AAAA,IAAC,UAAU;AAAA,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AAAA,gBApCI;AAAA,cAqCP;AAAA,YAEF;AAAA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,EAEF;AAGA,SACC,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,IAAK;AAAA,QACL,QAAS,oBAAC,SAAI;AAAA,QACd,WAAY,KAAM,uBAAuB,WAAW;AAAA,UACnD,CAAE,OAAQ,KAAK,QAAQ,OAAQ,UAAW,GACzC,KAAK,QAAQ,WACb,CAAE,WAAW,aAAc,EAAE;AAAA,YAC5B,KAAK,OAAO;AAAA,UACb;AAAA,QACF,CAAE;AAAA,QACF,MAAO,KAAK,wBAAwB,SAAS;AAAA,QAC7C,UAAW;AAAA,QACX,aAAc;AAAA,QAEZ,eAAK,IAAK,CAAE,MAAM,UAAW;AAC9B,gBAAM,KAAK,8BAA+B,IAAK;AAC/C,iBACC;AAAA,YAAC;AAAA;AAAA,cAEA;AAAA,cACA,UAAW;AAAA,cACX;AAAA,cACA;AAAA,cACA,YAAa,SAAS;AAAA,cACtB;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cAGA,UACC,KAAK,wBACF,QAAQ,IACR;AAAA;AAAA,YAjBE;AAAA,UAmBP;AAAA,QAEF,CAAE;AAAA;AAAA,IACH;AAAA,IACE,WAAW,aACZ,oBAAC,OAAE,WAAU,0BACZ,8BAAC,WAAQ,GACV;AAAA,KAEF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/dataviews/src/components/dataviews-layouts/
|
|
1
|
+
// packages/dataviews/src/components/dataviews-layouts/utils/density-picker.tsx
|
|
2
2
|
import {
|
|
3
3
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
4
4
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/dataviews-layouts/utils/density-picker.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../../dataviews-context';\nimport type { ViewTable, ViewList, Density } from '../../../types';\n\nexport default function DensityPicker() {\n\tconst context = useContext( DataViewsContext );\n\tconst view = context.view as ViewTable | ViewList;\n\treturn (\n\t\t<ToggleGroupControl\n\t\t\tsize=\"__unstable-large\"\n\t\t\tlabel={ __( 'Density' ) }\n\t\t\tvalue={ view.layout?.density || 'balanced' }\n\t\t\tonChange={ ( value ) => {\n\t\t\t\tcontext.onChangeView( {\n\t\t\t\t\t...view,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\t...view.layout,\n\t\t\t\t\t\tdensity: value as Density,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tisBlock\n\t\t>\n\t\t\t<ToggleGroupControlOption\n\t\t\t\tkey=\"comfortable\"\n\t\t\t\tvalue=\"comfortable\"\n\t\t\t\tlabel={ _x(\n\t\t\t\t\t'Comfortable',\n\t\t\t\t\t'Density option for DataView layout'\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t<ToggleGroupControlOption\n\t\t\t\tkey=\"balanced\"\n\t\t\t\tvalue=\"balanced\"\n\t\t\t\tlabel={ _x( 'Balanced', 'Density option for DataView layout' ) }\n\t\t\t/>\n\t\t\t<ToggleGroupControlOption\n\t\t\t\tkey=\"compact\"\n\t\t\t\tvalue=\"compact\"\n\t\t\t\tlabel={ _x( 'Compact', 'Density option for DataView layout' ) }\n\t\t\t/>\n\t\t</ToggleGroupControl>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC,oCAAoC;AAAA,EACpC,0CAA0C;AAAA,OACpC;AACP,SAAS,IAAI,UAAU;AACvB,SAAS,kBAAkB;AAK3B,OAAO,sBAAsB;AAO3B,SAeC,KAfD;AAJa,SAAR,gBAAiC;AACvC,QAAM,UAAU,WAAY,gBAAiB;AAC7C,QAAM,OAAO,QAAQ;AACrB,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,OAAQ,GAAI,SAAU;AAAA,MACtB,OAAQ,KAAK,QAAQ,WAAW;AAAA,MAChC,UAAW,CAAE,UAAW;AACvB,gBAAQ,aAAc;AAAA,UACrB,GAAG;AAAA,UACH,QAAQ;AAAA,YACP,GAAG,KAAK;AAAA,YACR,SAAS;AAAA,UACV;AAAA,QACD,CAAE;AAAA,MACH;AAAA,MACA,SAAO;AAAA,MAEP;AAAA;AAAA,UAAC;AAAA;AAAA,YAEA,OAAM;AAAA,YACN,OAAQ;AAAA,cACP;AAAA,cACA;AAAA,YACD;AAAA;AAAA,UALI;AAAA,QAML;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YAEA,OAAM;AAAA,YACN,OAAQ,GAAI,YAAY,oCAAqC;AAAA;AAAA,UAFzD;AAAA,QAGL;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YAEA,OAAM;AAAA,YACN,OAAQ,GAAI,WAAW,oCAAqC;AAAA;AAAA,UAFxD;AAAA,QAGL;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -56,27 +56,14 @@ function PropertiesSection({
|
|
|
56
56
|
const visibleRegularFieldsCount = regularFields.filter(
|
|
57
57
|
(f) => visibleFieldIds.includes(f.id)
|
|
58
58
|
).length;
|
|
59
|
-
|
|
60
|
-
({
|
|
59
|
+
const visibleLockedFields = lockedFields.filter(
|
|
60
|
+
({ isVisibleFlag }) => (
|
|
61
61
|
// @ts-expect-error
|
|
62
|
-
|
|
62
|
+
view[isVisibleFlag] ?? true
|
|
63
63
|
)
|
|
64
64
|
);
|
|
65
65
|
const totalVisibleFields = visibleLockedFields.length + visibleRegularFieldsCount;
|
|
66
|
-
|
|
67
|
-
if (visibleLockedFields.length === 1) {
|
|
68
|
-
visibleLockedFields = visibleLockedFields.map((locked) => ({
|
|
69
|
-
...locked,
|
|
70
|
-
field: { ...locked.field, enableHiding: false }
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const hiddenLockedFields = lockedFields.filter(
|
|
75
|
-
({ field, isVisibleFlag }) => (
|
|
76
|
-
// @ts-expect-error
|
|
77
|
-
isDefined(field) && !(view[isVisibleFlag] ?? true)
|
|
78
|
-
)
|
|
79
|
-
);
|
|
66
|
+
const isSingleVisibleLockedField = totalVisibleFields === 1 && visibleLockedFields.length === 1;
|
|
80
67
|
return /* @__PURE__ */ jsxs(Stack, { direction: "column", className: "dataviews-field-control", children: [
|
|
81
68
|
showLabel && /* @__PURE__ */ jsx(BaseControl.VisualLabel, { children: __("Properties") }),
|
|
82
69
|
/* @__PURE__ */ jsx(
|
|
@@ -85,32 +72,18 @@ function PropertiesSection({
|
|
|
85
72
|
direction: "column",
|
|
86
73
|
className: "dataviews-view-config__properties",
|
|
87
74
|
children: /* @__PURE__ */ jsxs(ItemGroup, { isBordered: true, isSeparated: true, size: "medium", children: [
|
|
88
|
-
|
|
75
|
+
lockedFields.map(({ field, isVisibleFlag }) => {
|
|
76
|
+
const isVisible = view[isVisibleFlag] ?? true;
|
|
77
|
+
const fieldToRender = isSingleVisibleLockedField && isVisible ? { ...field, enableHiding: false } : field;
|
|
89
78
|
return /* @__PURE__ */ jsx(
|
|
90
79
|
FieldItem,
|
|
91
80
|
{
|
|
92
|
-
field,
|
|
93
|
-
isVisible
|
|
94
|
-
onToggleVisibility: () => {
|
|
95
|
-
onChangeView({
|
|
96
|
-
...view,
|
|
97
|
-
[isVisibleFlag]: false
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
field.id
|
|
102
|
-
);
|
|
103
|
-
}),
|
|
104
|
-
hiddenLockedFields.map(({ field, isVisibleFlag }) => {
|
|
105
|
-
return /* @__PURE__ */ jsx(
|
|
106
|
-
FieldItem,
|
|
107
|
-
{
|
|
108
|
-
field,
|
|
109
|
-
isVisible: false,
|
|
81
|
+
field: fieldToRender,
|
|
82
|
+
isVisible,
|
|
110
83
|
onToggleVisibility: () => {
|
|
111
84
|
onChangeView({
|
|
112
85
|
...view,
|
|
113
|
-
[isVisibleFlag]:
|
|
86
|
+
[isVisibleFlag]: !isVisible
|
|
114
87
|
});
|
|
115
88
|
}
|
|
116
89
|
},
|
|
@@ -119,8 +92,7 @@ function PropertiesSection({
|
|
|
119
92
|
}),
|
|
120
93
|
regularFields.map((field) => {
|
|
121
94
|
const isVisible = visibleFieldIds.includes(field.id);
|
|
122
|
-
const
|
|
123
|
-
const fieldToRender = isLastVisible ? { ...field, enableHiding: false } : field;
|
|
95
|
+
const fieldToRender = totalVisibleFields === 1 && isVisible ? { ...field, enableHiding: false } : field;
|
|
124
96
|
return /* @__PURE__ */ jsx(
|
|
125
97
|
FieldItem,
|
|
126
98
|
{
|
|
@@ -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=\"xs\" justify=\"flex-start\" align=\"center\">\n\t\t\t\t<div style={ { height: 24, width: 24 } }>\n\t\t\t\t\t{ isVisible && <Icon 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 ) );\n\tconst visibleFieldIds = view.fields ?? [];\n\tconst visibleRegularFieldsCount = regularFields.filter( ( f ) =>\n\t\tvisibleFieldIds.includes( f.id )\n\t).length;\n\n\
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC,2BAA2B;AAAA,EAC3B,sBAAsB;AAAA,EACtB;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,aAAa;AAMtB,OA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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=\"xs\" justify=\"flex-start\" align=\"center\">\n\t\t\t\t<div style={ { height: 24, width: 24 } }>\n\t\t\t\t\t{ isVisible && <Icon 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": ";AAGA;AAAA,EACC,2BAA2B;AAAA,EAC3B,sBAAsB;AAAA,EACtB;AAAA,E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,oBACb,GAAG;AAAA,oBACH,QAAQ,YACL,gBAAgB;AAAA,sBAChB,CAAE,YACD,YAAY,MAAM;AAAA,oBACnB,IACA,CAAE,GAAG,iBAAiB,MAAM,EAAG;AAAA,kBACnC,CAAE;AAAA,gBACH;AAAA;AAAA,cAbM,MAAM;AAAA,YAcb;AAAA,UAEF,CAAE;AAAA,WACH;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/dataviews/src/hooks/use-form-validity.ts
|
|
2
2
|
import deepMerge from "deepmerge";
|
|
3
|
-
import fastDeepEqual from "fast-deep-equal/es6";
|
|
3
|
+
import fastDeepEqual from "fast-deep-equal/es6/index.js";
|
|
4
4
|
import { useCallback, useEffect, useRef, useState } from "@wordpress/element";
|
|
5
5
|
import { __ } from "@wordpress/i18n";
|
|
6
6
|
import normalizeFields from "../field-types/index.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
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';\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 validation.type === 'valid';\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 = 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 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}\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\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: 'valid',\n\t\t\t\t\t\t\t\tmessage: __( 'Valid' ),\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 ( 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.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\n\t\treturn {\n\t\t\telements: {\n\t\t\t\ttype: 'validating',\n\t\t\t\tmessage: __( 'Validating\u2026' ),\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// Validate the field: isValid.custom (async)\n\tif ( customError instanceof Promise ) {\n\t\thandleCustomValidationAsync( customError, formField, promiseHandler );\n\n\t\treturn {\n\t\t\tcustom: {\n\t\t\t\ttype: 'validating',\n\t\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t\t},\n\t\t};\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 validation.type === 'valid';\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 = 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 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}\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\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: 'valid',\n\t\t\t\t\t\t\t\tmessage: __( 'Valid' ),\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 ( 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.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\n\t\treturn {\n\t\t\telements: {\n\t\t\t\ttype: 'validating',\n\t\t\t\tmessage: __( 'Validating\u2026' ),\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// Validate the field: isValid.custom (async)\n\tif ( customError instanceof Promise ) {\n\t\thandleCustomValidationAsync( customError, formField, promiseHandler );\n\n\t\treturn {\n\t\t\tcustom: {\n\t\t\t\ttype: 'validating',\n\t\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t\t},\n\t\t};\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": ";AAGA,OAAO,eAAe;AACtB,OAAO,mBAAmB;AAK1B,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AACzD,SAAS,UAAU;AAKnB,OAAO,qBAAqB;AAC5B,OAAO,mBAAmB;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,cACA,OAAO,eAAe,UACrB;AAED,iBAAO,YAAa,UAA2B;AAAA,QAChD;AACA,eAAO,WAAW,SAAS;AAAA,MAC5B;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAQA,SAAS,wBACR,MACA,QACgC;AAChC,QAAM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