@wordpress/dataviews 10.3.1-next.2f1c7c01b.0 → 10.4.1-next.dc3f6d3c1.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 +23 -5
- package/README.md +413 -148
- package/build/components/dataviews-filters/filter.js +11 -1
- package/build/components/dataviews-filters/filter.js.map +2 -2
- package/build/components/dataviews-view-config/index.js +11 -396
- package/build/components/dataviews-view-config/index.js.map +3 -3
- package/build/components/dataviews-view-config/properties-section.js +177 -0
- package/build/components/dataviews-view-config/properties-section.js.map +7 -0
- package/build/constants.js +3 -0
- package/build/constants.js.map +2 -2
- package/build/dataform-controls/date.js +23 -7
- package/build/dataform-controls/date.js.map +2 -2
- package/build/dataform-controls/email.js +1 -1
- package/build/dataform-controls/email.js.map +1 -1
- package/build/dataform-layouts/details/index.js +78 -0
- package/build/dataform-layouts/details/index.js.map +7 -0
- package/build/dataform-layouts/index.js +5 -0
- package/build/dataform-layouts/index.js.map +3 -3
- package/build/dataform-layouts/normalize-form.js +5 -0
- package/build/dataform-layouts/normalize-form.js.map +2 -2
- package/build/dataviews-layouts/index.js +9 -0
- package/build/dataviews-layouts/index.js.map +3 -3
- package/build/dataviews-layouts/picker-table/index.js +422 -0
- package/build/dataviews-layouts/picker-table/index.js.map +7 -0
- package/build/dataviews-layouts/table/column-header-menu.js.map +2 -2
- package/build/dataviews-layouts/table/column-primary.js +1 -6
- package/build/dataviews-layouts/table/column-primary.js.map +2 -2
- package/build/dataviews-layouts/table/index.js +47 -2
- package/build/dataviews-layouts/table/index.js.map +2 -2
- package/build/field-types/date.js +4 -2
- package/build/field-types/date.js.map +2 -2
- package/build/types/dataform.js.map +1 -1
- package/build/types/dataviews.js.map +1 -1
- package/build/types/field-api.js.map +1 -1
- package/build/utils/normalize-fields.js +23 -3
- package/build/utils/normalize-fields.js.map +2 -2
- package/build/utils/week-starts-on.js +59 -0
- package/build/utils/week-starts-on.js.map +7 -0
- package/build-module/components/dataviews-filters/filter.js +11 -1
- package/build-module/components/dataviews-filters/filter.js.map +2 -2
- package/build-module/components/dataviews-view-config/index.js +15 -412
- package/build-module/components/dataviews-view-config/index.js.map +2 -2
- package/build-module/components/dataviews-view-config/properties-section.js +149 -0
- package/build-module/components/dataviews-view-config/properties-section.js.map +7 -0
- package/build-module/constants.js +2 -0
- package/build-module/constants.js.map +2 -2
- package/build-module/dataform-controls/date.js +23 -7
- package/build-module/dataform-controls/date.js.map +2 -2
- package/build-module/dataform-controls/email.js +2 -2
- package/build-module/dataform-controls/email.js.map +1 -1
- package/build-module/dataform-layouts/details/index.js +47 -0
- package/build-module/dataform-layouts/details/index.js.map +7 -0
- package/build-module/dataform-layouts/index.js +5 -0
- package/build-module/dataform-layouts/index.js.map +2 -2
- package/build-module/dataform-layouts/normalize-form.js +5 -0
- package/build-module/dataform-layouts/normalize-form.js.map +2 -2
- package/build-module/dataviews-layouts/index.js +11 -1
- package/build-module/dataviews-layouts/index.js.map +2 -2
- package/build-module/dataviews-layouts/picker-table/index.js +397 -0
- package/build-module/dataviews-layouts/picker-table/index.js.map +7 -0
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +2 -2
- package/build-module/dataviews-layouts/table/column-primary.js +1 -6
- package/build-module/dataviews-layouts/table/column-primary.js.map +2 -2
- package/build-module/dataviews-layouts/table/index.js +48 -3
- package/build-module/dataviews-layouts/table/index.js.map +2 -2
- package/build-module/field-types/date.js +5 -3
- package/build-module/field-types/date.js.map +2 -2
- package/build-module/utils/normalize-fields.js +23 -3
- package/build-module/utils/normalize-fields.js.map +2 -2
- package/build-module/utils/week-starts-on.js +32 -0
- package/build-module/utils/week-starts-on.js.map +7 -0
- package/build-style/style-rtl.css +58 -54
- package/build-style/style.css +58 -54
- package/build-types/components/dataviews-filters/filter.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/utils.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/properties-section.d.ts +4 -0
- package/build-types/components/dataviews-view-config/properties-section.d.ts.map +1 -0
- package/build-types/constants.d.ts +1 -0
- package/build-types/constants.d.ts.map +1 -1
- package/build-types/dataform-controls/date.d.ts.map +1 -1
- package/build-types/dataform-layouts/details/index.d.ts +6 -0
- package/build-types/dataform-layouts/details/index.d.ts.map +1 -0
- package/build-types/dataform-layouts/get-summary-fields.d.ts.map +1 -1
- package/build-types/dataform-layouts/index.d.ts +5 -0
- package/build-types/dataform-layouts/index.d.ts.map +1 -1
- package/build-types/dataform-layouts/normalize-form.d.ts.map +1 -1
- package/build-types/dataviews-layouts/index.d.ts +8 -0
- package/build-types/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/picker-table/index.d.ts +4 -0
- package/build-types/dataviews-layouts/picker-table/index.d.ts.map +1 -0
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts +3 -3
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-primary.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/field-types/date.d.ts.map +1 -1
- package/build-types/stories/dataform.story.d.ts +3 -0
- package/build-types/stories/dataform.story.d.ts.map +1 -1
- package/build-types/stories/dataviews-picker.story.d.ts +2 -0
- package/build-types/stories/dataviews-picker.story.d.ts.map +1 -1
- package/build-types/stories/dataviews.story.d.ts +7 -1
- package/build-types/stories/dataviews.story.d.ts.map +1 -1
- package/build-types/stories/field-types.story.d.ts +27 -1
- package/build-types/stories/field-types.story.d.ts.map +1 -1
- package/build-types/types/dataform.d.ts +11 -3
- package/build-types/types/dataform.d.ts.map +1 -1
- package/build-types/types/dataviews.d.ts +23 -2
- package/build-types/types/dataviews.d.ts.map +1 -1
- package/build-types/types/field-api.d.ts +28 -1
- package/build-types/types/field-api.d.ts.map +1 -1
- package/build-types/utils/normalize-fields.d.ts.map +1 -1
- package/build-types/utils/week-starts-on.d.ts +20 -0
- package/build-types/utils/week-starts-on.d.ts.map +1 -0
- package/build-wp/index.js +1497 -1188
- package/package.json +15 -15
- package/src/components/dataviews/style.scss +2 -0
- package/src/components/dataviews-filters/filter.tsx +11 -1
- package/src/components/dataviews-footer/style.scss +1 -1
- package/src/components/dataviews-view-config/index.tsx +8 -504
- package/src/components/dataviews-view-config/properties-section.tsx +201 -0
- package/src/components/dataviews-view-config/style.scss +2 -39
- package/src/constants.ts +1 -0
- package/src/dataform-controls/date.tsx +24 -6
- package/src/dataform-controls/email.tsx +2 -2
- package/src/dataform-layouts/details/index.tsx +71 -0
- package/src/dataform-layouts/details/style.scss +5 -0
- package/src/dataform-layouts/index.tsx +5 -0
- package/src/dataform-layouts/normalize-form.ts +6 -0
- package/src/dataviews-layouts/index.ts +10 -0
- package/src/dataviews-layouts/list/style.scss +1 -0
- package/src/dataviews-layouts/picker-table/index.tsx +487 -0
- package/src/dataviews-layouts/picker-table/style.scss +47 -0
- package/src/dataviews-layouts/table/column-header-menu.tsx +3 -2
- package/src/dataviews-layouts/table/column-primary.tsx +4 -7
- package/src/dataviews-layouts/table/index.tsx +55 -2
- package/src/dataviews-layouts/table/style.scss +36 -19
- package/src/field-types/date.tsx +11 -5
- package/src/stories/dataform.story.tsx +84 -0
- package/src/stories/dataviews-picker.story.tsx +11 -6
- package/src/stories/dataviews.story.tsx +10 -2
- package/src/stories/field-types.story.tsx +67 -2
- package/src/style.scss +2 -0
- package/src/test/normalize-fields.ts +53 -0
- package/src/types/dataform.ts +18 -3
- package/src/types/dataviews.ts +36 -2
- package/src/types/field-api.ts +42 -1
- package/src/utils/normalize-fields.ts +51 -2
- package/src/utils/week-starts-on.ts +46 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -47,6 +47,7 @@ var import_column_header_menu = __toESM(require("./column-header-menu"));
|
|
|
47
47
|
var import_column_primary = __toESM(require("./column-primary"));
|
|
48
48
|
var import_use_is_horizontal_scroll_end = require("./use-is-horizontal-scroll-end");
|
|
49
49
|
var import_get_data_by_group = __toESM(require("../utils/get-data-by-group"));
|
|
50
|
+
var import_properties_section = require("../../components/dataviews-view-config/properties-section");
|
|
50
51
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
52
|
function TableColumnField({
|
|
52
53
|
item,
|
|
@@ -231,6 +232,7 @@ function ViewTable({
|
|
|
231
232
|
const headerMenuToFocusRef = (0, import_element.useRef)();
|
|
232
233
|
const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element.useState)();
|
|
233
234
|
const hasBulkActions = (0, import_dataviews_bulk_actions.useSomeItemHasAPossibleBulkAction)(actions, data);
|
|
235
|
+
const [contextMenuAnchor, setContextMenuAnchor] = (0, import_element.useState)(null);
|
|
234
236
|
(0, import_element.useEffect)(() => {
|
|
235
237
|
if (headerMenuToFocusRef.current) {
|
|
236
238
|
headerMenuToFocusRef.current.focus();
|
|
@@ -252,6 +254,26 @@ function ViewTable({
|
|
|
252
254
|
const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
|
|
253
255
|
setNextHeaderMenuToFocus(fallback?.node);
|
|
254
256
|
};
|
|
257
|
+
const handleHeaderContextMenu = (event) => {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
event.stopPropagation();
|
|
260
|
+
const virtualAnchor = {
|
|
261
|
+
getBoundingClientRect: () => ({
|
|
262
|
+
x: event.clientX,
|
|
263
|
+
y: event.clientY,
|
|
264
|
+
top: event.clientY,
|
|
265
|
+
left: event.clientX,
|
|
266
|
+
right: event.clientX,
|
|
267
|
+
bottom: event.clientY,
|
|
268
|
+
width: 0,
|
|
269
|
+
height: 0,
|
|
270
|
+
toJSON: () => ({})
|
|
271
|
+
})
|
|
272
|
+
};
|
|
273
|
+
window.requestAnimationFrame(() => {
|
|
274
|
+
setContextMenuAnchor(virtualAnchor);
|
|
275
|
+
});
|
|
276
|
+
};
|
|
255
277
|
const hasData = !!data?.length;
|
|
256
278
|
const titleField = fields.find((field) => field.id === view.titleField);
|
|
257
279
|
const mediaField = fields.find((field) => field.id === view.mediaField);
|
|
@@ -281,18 +303,41 @@ function ViewTable({
|
|
|
281
303
|
className: (0, import_clsx.default)("dataviews-view-table", className, {
|
|
282
304
|
[`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
|
|
283
305
|
view.layout.density
|
|
284
|
-
)
|
|
306
|
+
),
|
|
307
|
+
"has-bulk-actions": hasBulkActions
|
|
285
308
|
}),
|
|
286
309
|
"aria-busy": isLoading,
|
|
287
310
|
"aria-describedby": tableNoticeId,
|
|
288
311
|
role: isInfiniteScroll ? "feed" : void 0,
|
|
289
312
|
children: [
|
|
290
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
313
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("colgroup", { children: [
|
|
314
|
+
hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("col", { className: "dataviews-view-table__col-checkbox" }),
|
|
315
|
+
hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("col", { className: "dataviews-view-table__col-primary" }),
|
|
316
|
+
columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
317
|
+
"col",
|
|
318
|
+
{
|
|
319
|
+
className: `dataviews-view-table__col-${column}`
|
|
320
|
+
},
|
|
321
|
+
`col-${column}`
|
|
322
|
+
)),
|
|
323
|
+
!!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("col", { className: "dataviews-view-table__col-actions" })
|
|
324
|
+
] }),
|
|
325
|
+
contextMenuAnchor && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
326
|
+
import_components.Popover,
|
|
327
|
+
{
|
|
328
|
+
anchor: contextMenuAnchor,
|
|
329
|
+
onClose: () => setContextMenuAnchor(null),
|
|
330
|
+
placement: "bottom-start",
|
|
331
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_properties_section.PropertiesSection, { showLabel: false })
|
|
332
|
+
}
|
|
333
|
+
),
|
|
334
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { onContextMenu: handleHeaderContextMenu, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { className: "dataviews-view-table__row", children: [
|
|
291
335
|
hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
292
336
|
"th",
|
|
293
337
|
{
|
|
294
338
|
className: "dataviews-view-table__checkbox-column",
|
|
295
339
|
scope: "col",
|
|
340
|
+
onContextMenu: handleHeaderContextMenu,
|
|
296
341
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
297
342
|
import_dataviews_bulk_actions.BulkSelectionCheckbox,
|
|
298
343
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/dataviews-layouts/table/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ComponentProps, ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Spinner } from '@wordpress/components';\nimport {\n\tuseContext,\n\tuseEffect,\n\tuseId,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../../components/dataviews-context';\nimport DataViewsSelectionCheckbox from '../../components/dataviews-selection-checkbox';\nimport ItemActions from '../../components/dataviews-item-actions';\nimport { sortValues } from '../../constants';\nimport {\n\tuseSomeItemHasAPossibleBulkAction,\n\tuseHasAPossibleBulkAction,\n\tBulkSelectionCheckbox,\n} from '../../components/dataviews-bulk-actions';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewTable as ViewTableType,\n\tViewTableProps,\n} from '../../types';\nimport type { SetSelection } from '../../types/private';\nimport ColumnHeaderMenu from './column-header-menu';\nimport ColumnPrimary from './column-primary';\nimport { useIsHorizontalScrollEnd } from './use-is-horizontal-scroll-end';\nimport getDataByGroup from '../utils/get-data-by-group';\n\ninterface TableColumnFieldProps< Item > {\n\tfields: NormalizedField< Item >[];\n\tcolumn: string;\n\titem: Item;\n\talign?: 'start' | 'center' | 'end';\n}\n\ninterface TableRowProps< Item > {\n\thasBulkActions: boolean;\n\titem: Item;\n\tlevel?: number;\n\tactions: Action< Item >[];\n\tfields: NormalizedField< Item >[];\n\tid: string;\n\tview: ViewTableType;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tselection: string[];\n\tgetItemId: ( item: Item ) => string;\n\tonChangeSelection: SetSelection;\n\tisItemClickable: ( item: Item ) => boolean;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisActionsColumnSticky?: boolean;\n\tposinset?: number;\n}\n\nfunction TableColumnField< Item >( {\n\titem,\n\tfields,\n\tcolumn,\n\talign,\n}: TableColumnFieldProps< Item > ) {\n\tconst field = fields.find( ( f ) => f.id === column );\n\n\tif ( ! field ) {\n\t\treturn null;\n\t}\n\n\tconst className = clsx( 'dataviews-view-table__cell-content-wrapper', {\n\t\t'dataviews-view-table__cell-align-end': align === 'end',\n\t\t'dataviews-view-table__cell-align-center': align === 'center',\n\t} );\n\n\treturn (\n\t\t<div className={ className }>\n\t\t\t<field.render item={ item } field={ field } />\n\t\t</div>\n\t);\n}\n\nfunction TableRow< Item >( {\n\thasBulkActions,\n\titem,\n\tlevel,\n\tactions,\n\tfields,\n\tid,\n\tview,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tselection,\n\tgetItemId,\n\tisItemClickable,\n\tonClickItem,\n\trenderItemLink,\n\tonChangeSelection,\n\tisActionsColumnSticky,\n\tposinset,\n}: TableRowProps< Item > ) {\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\tconst hasPossibleBulkAction = useHasAPossibleBulkAction( actions, item );\n\tconst isSelected = hasPossibleBulkAction && selection.includes( id );\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst handleMouseEnter = () => {\n\t\tsetIsHovered( true );\n\t};\n\tconst handleMouseLeave = () => {\n\t\tsetIsHovered( false );\n\t};\n\n\t// Will be set to true if `onTouchStart` fires. This happens before\n\t// `onClick` and can be used to exclude touchscreen devices from certain\n\t// behaviours.\n\tconst isTouchDeviceRef = useRef( false );\n\tconst columns = view.fields ?? [];\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\n\treturn (\n\t\t<tr\n\t\t\tclassName={ clsx( 'dataviews-view-table__row', {\n\t\t\t\t'is-selected': hasPossibleBulkAction && isSelected,\n\t\t\t\t'is-hovered': isHovered,\n\t\t\t\t'has-bulk-actions': hasPossibleBulkAction,\n\t\t\t} ) }\n\t\t\tonMouseEnter={ handleMouseEnter }\n\t\t\tonMouseLeave={ handleMouseLeave }\n\t\t\tonTouchStart={ () => {\n\t\t\t\tisTouchDeviceRef.current = true;\n\t\t\t} }\n\t\t\taria-setsize={\n\t\t\t\tinfiniteScrollEnabled ? paginationInfo.totalItems : undefined\n\t\t\t}\n\t\t\taria-posinset={ posinset }\n\t\t\trole={ infiniteScrollEnabled ? 'article' : undefined }\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tif ( ! hasPossibleBulkAction ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t! isTouchDeviceRef.current &&\n\t\t\t\t\tdocument.getSelection()?.type !== 'Range'\n\t\t\t\t) {\n\t\t\t\t\tif ( isAppleOS() ? event.metaKey : event.ctrlKey ) {\n\t\t\t\t\t\t// Handle non-consecutive selection.\n\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\tselection.includes( id )\n\t\t\t\t\t\t\t\t? selection.filter(\n\t\t\t\t\t\t\t\t\t\t( itemId ) => id !== itemId\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: [ ...selection, id ]\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Handle single selection\n\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\tselection.includes( id )\n\t\t\t\t\t\t\t\t? selection.filter(\n\t\t\t\t\t\t\t\t\t\t( itemId ) => id !== itemId\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: [ id ]\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t{ hasBulkActions && (\n\t\t\t\t<td className=\"dataviews-view-table__checkbox-column\">\n\t\t\t\t\t<div className=\"dataviews-view-table__cell-content-wrapper\">\n\t\t\t\t\t\t<DataViewsSelectionCheckbox\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\tdisabled={ ! hasPossibleBulkAction }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</td>\n\t\t\t) }\n\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t<td>\n\t\t\t\t\t<ColumnPrimary\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tlevel={ level }\n\t\t\t\t\t\ttitleField={ showTitle ? titleField : undefined }\n\t\t\t\t\t\tmediaField={ showMedia ? mediaField : undefined }\n\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\tshowDescription ? descriptionField : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t/>\n\t\t\t\t</td>\n\t\t\t) }\n\t\t\t{ columns.map( ( column: string ) => {\n\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\n\t\t\t\treturn (\n\t\t\t\t\t<td\n\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<TableColumnField\n\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tcolumn={ column }\n\t\t\t\t\t\t\talign={ align }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</td>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t\t{ !! actions?.length && (\n\t\t\t\t// Disable reason: we are not making the element interactive,\n\t\t\t\t// but preventing any click events from bubbling up to the\n\t\t\t\t// table row. This allows us to add a click handler to the row\n\t\t\t\t// itself (to toggle row selection) without erroneously\n\t\t\t\t// intercepting click events from ItemActions.\n\n\t\t\t\t/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */\n\t\t\t\t<td\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-table__actions-column', {\n\t\t\t\t\t\t'dataviews-view-table__actions-column--sticky': true,\n\t\t\t\t\t\t'dataviews-view-table__actions-column--stuck':\n\t\t\t\t\t\t\tisActionsColumnSticky,\n\t\t\t\t\t} ) }\n\t\t\t\t\tonClick={ ( e ) => e.stopPropagation() }\n\t\t\t\t>\n\t\t\t\t\t<ItemActions item={ item } actions={ actions } />\n\t\t\t\t</td>\n\t\t\t\t/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */\n\t\t\t) }\n\t\t</tr>\n\t);\n}\n\nfunction ViewTable< Item >( {\n\tactions,\n\tdata,\n\tfields,\n\tgetItemId,\n\tgetItemLevel,\n\tisLoading = false,\n\tonChangeView,\n\tonChangeSelection,\n\tselection,\n\tsetOpenedFilter,\n\tonClickItem,\n\tisItemClickable,\n\trenderItemLink,\n\tview,\n\tclassName,\n\tempty,\n}: ViewTableProps< Item > ) {\n\tconst { containerRef } = useContext( DataViewsContext );\n\tconst headerMenuRefs = useRef<\n\t\tMap< string, { node: HTMLButtonElement; fallback: string } >\n\t>( new Map() );\n\tconst headerMenuToFocusRef = useRef< HTMLButtonElement >();\n\tconst [ nextHeaderMenuToFocus, setNextHeaderMenuToFocus ] =\n\t\tuseState< HTMLButtonElement >();\n\tconst hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data );\n\n\tuseEffect( () => {\n\t\tif ( headerMenuToFocusRef.current ) {\n\t\t\theaderMenuToFocusRef.current.focus();\n\t\t\theaderMenuToFocusRef.current = undefined;\n\t\t}\n\t} );\n\n\tconst tableNoticeId = useId();\n\n\tconst isHorizontalScrollEnd = useIsHorizontalScrollEnd( {\n\t\tscrollContainerRef: containerRef,\n\t\tenabled: !! actions?.length,\n\t} );\n\n\tif ( nextHeaderMenuToFocus ) {\n\t\t// If we need to force focus, we short-circuit rendering here\n\t\t// to prevent any additional work while we handle that.\n\t\t// Clearing out the focus directive is necessary to make sure\n\t\t// future renders don't cause unexpected focus jumps.\n\t\theaderMenuToFocusRef.current = nextHeaderMenuToFocus;\n\t\tsetNextHeaderMenuToFocus( undefined );\n\t\treturn;\n\t}\n\n\tconst onHide = ( field: NormalizedField< Item > ) => {\n\t\tconst hidden = headerMenuRefs.current.get( field.id );\n\t\tconst fallback = hidden\n\t\t\t? headerMenuRefs.current.get( hidden.fallback )\n\t\t\t: undefined;\n\t\tsetNextHeaderMenuToFocus( fallback?.node );\n\t};\n\n\tconst hasData = !! data?.length;\n\n\tconst titleField = fields.find( ( field ) => field.id === view.titleField );\n\tconst mediaField = fields.find( ( field ) => field.id === view.mediaField );\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view.descriptionField\n\t);\n\n\tconst groupField = view.groupByField\n\t\t? fields.find( ( f ) => f.id === view.groupByField )\n\t\t: null;\n\tconst dataByGroup = groupField ? getDataByGroup( data, groupField ) : null;\n\tconst { showTitle = true, showMedia = true, showDescription = true } = view;\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\tconst columns = view.fields ?? [];\n\tconst headerMenuRef =\n\t\t( column: string, index: number ) => ( node: HTMLButtonElement ) => {\n\t\t\tif ( node ) {\n\t\t\t\theaderMenuRefs.current.set( column, {\n\t\t\t\t\tnode,\n\t\t\t\t\tfallback: columns[ index > 0 ? index - 1 : 1 ],\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\theaderMenuRefs.current.delete( column );\n\t\t\t}\n\t\t};\n\tconst isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup;\n\n\treturn (\n\t\t<>\n\t\t\t<table\n\t\t\t\tclassName={ clsx( 'dataviews-view-table', 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\taria-busy={ isLoading }\n\t\t\t\taria-describedby={ tableNoticeId }\n\t\t\t\trole={ isInfiniteScroll ? 'feed' : undefined }\n\t\t\t>\n\t\t\t\t<thead>\n\t\t\t\t\t<tr className=\"dataviews-view-table__row\">\n\t\t\t\t\t\t{ hasBulkActions && (\n\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__checkbox-column\"\n\t\t\t\t\t\t\t\tscope=\"col\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<BulkSelectionCheckbox\n\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t\t\t\t<th scope=\"col\">\n\t\t\t\t\t\t\t\t{ titleField && (\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef(\n\t\t\t\t\t\t\t\t\t\t\ttitleField.id,\n\t\t\t\t\t\t\t\t\t\t\t0\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ titleField.id }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={ false }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ columns.map( ( column, index ) => {\n\t\t\t\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t\t\t\t\ttextAlign: align,\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taria-sort={\n\t\t\t\t\t\t\t\t\t\tview.sort?.direction &&\n\t\t\t\t\t\t\t\t\t\tview.sort?.field === column\n\t\t\t\t\t\t\t\t\t\t\t? sortValues[ view.sort.direction ]\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tscope=\"col\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef( column, index ) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ column }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={\n\t\t\t\t\t\t\t\t\t\t\tview.layout?.enableMoving ?? true\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t{ !! actions?.length && (\n\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-view-table__actions-column',\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t'dataviews-view-table__actions-column--sticky':\n\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t'dataviews-view-table__actions-column--stuck':\n\t\t\t\t\t\t\t\t\t\t\t! isHorizontalScrollEnd,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span className=\"dataviews-view-table-header\">\n\t\t\t\t\t\t\t\t\t{ __( 'Actions' ) }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</tr>\n\t\t\t\t</thead>\n\t\t\t\t{ /* Render grouped data if groupByField is specified */ }\n\t\t\t\t{ hasData && groupField && dataByGroup ? (\n\t\t\t\t\tArray.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<tbody key={ `group-${ groupName }` }>\n\t\t\t\t\t\t\t\t<tr className=\"dataviews-view-table__group-header-row\">\n\t\t\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\t\t\tcolSpan={\n\t\t\t\t\t\t\t\t\t\t\tcolumns.length +\n\t\t\t\t\t\t\t\t\t\t\t( hasPrimaryColumn ? 1 : 0 ) +\n\t\t\t\t\t\t\t\t\t\t\t( hasBulkActions ? 1 : 0 ) +\n\t\t\t\t\t\t\t\t\t\t\t( actions?.length ? 1 : 0 )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__group-header-cell\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ sprintf(\n\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__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\t\t\tgroupField.label,\n\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\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item, index ) => (\n\t\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\tlevel={\n\t\t\t\t\t\t\t\t\t\t\tview.showLevels &&\n\t\t\t\t\t\t\t\t\t\t\ttypeof getItemLevel === 'function'\n\t\t\t\t\t\t\t\t\t\t\t\t? getItemLevel( item )\n\t\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\thasBulkActions={ hasBulkActions }\n\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tid={\n\t\t\t\t\t\t\t\t\t\t\tgetItemId( item ) ||\n\t\t\t\t\t\t\t\t\t\t\tindex.toString()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\t\t\t\tisActionsColumnSticky={\n\t\t\t\t\t\t\t\t\t\t\t! isHorizontalScrollEnd\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</tbody>\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) : (\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{ hasData &&\n\t\t\t\t\t\t\tdata.map( ( item, index ) => (\n\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\tlevel={\n\t\t\t\t\t\t\t\t\t\tview.showLevels &&\n\t\t\t\t\t\t\t\t\t\ttypeof getItemLevel === 'function'\n\t\t\t\t\t\t\t\t\t\t\t? getItemLevel( item )\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\thasBulkActions={ hasBulkActions }\n\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\tid={ getItemId( item ) || index.toString() }\n\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\t\t\tisActionsColumnSticky={\n\t\t\t\t\t\t\t\t\t\t! isHorizontalScrollEnd\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tposinset={\n\t\t\t\t\t\t\t\t\t\tisInfiniteScroll ? index + 1 : undefined\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</tbody>\n\t\t\t\t) }\n\t\t\t</table>\n\t\t\t<div\n\t\t\t\tclassName={ clsx( {\n\t\t\t\t\t'dataviews-loading': isLoading,\n\t\t\t\t\t'dataviews-no-results': ! hasData && ! isLoading,\n\t\t\t\t} ) }\n\t\t\t\tid={ tableNoticeId }\n\t\t\t>\n\t\t\t\t{ ! hasData &&\n\t\t\t\t\t( isLoading ? (\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</p>\n\t\t\t\t\t) : (\n\t\t\t\t\t\tempty\n\t\t\t\t\t) ) }\n\t\t\t\t{ hasData && isLoading && (\n\t\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default ViewTable;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,kBAA4B;AAC5B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ComponentProps, ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Spinner, Popover } from '@wordpress/components';\nimport {\n\tuseContext,\n\tuseEffect,\n\tuseId,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../../components/dataviews-context';\nimport DataViewsSelectionCheckbox from '../../components/dataviews-selection-checkbox';\nimport ItemActions from '../../components/dataviews-item-actions';\nimport { sortValues } from '../../constants';\nimport {\n\tuseSomeItemHasAPossibleBulkAction,\n\tuseHasAPossibleBulkAction,\n\tBulkSelectionCheckbox,\n} from '../../components/dataviews-bulk-actions';\nimport type {\n\tAction,\n\tNormalizedField,\n\tViewTable as ViewTableType,\n\tViewTableProps,\n} from '../../types';\nimport type { SetSelection } from '../../types/private';\nimport ColumnHeaderMenu from './column-header-menu';\nimport ColumnPrimary from './column-primary';\nimport { useIsHorizontalScrollEnd } from './use-is-horizontal-scroll-end';\nimport getDataByGroup from '../utils/get-data-by-group';\nimport { PropertiesSection } from '../../components/dataviews-view-config/properties-section';\n\ninterface TableColumnFieldProps< Item > {\n\tfields: NormalizedField< Item >[];\n\tcolumn: string;\n\titem: Item;\n\talign?: 'start' | 'center' | 'end';\n}\n\ninterface TableRowProps< Item > {\n\thasBulkActions: boolean;\n\titem: Item;\n\tlevel?: number;\n\tactions: Action< Item >[];\n\tfields: NormalizedField< Item >[];\n\tid: string;\n\tview: ViewTableType;\n\ttitleField?: NormalizedField< Item >;\n\tmediaField?: NormalizedField< Item >;\n\tdescriptionField?: NormalizedField< Item >;\n\tselection: string[];\n\tgetItemId: ( item: Item ) => string;\n\tonChangeSelection: SetSelection;\n\tisItemClickable: ( item: Item ) => boolean;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisActionsColumnSticky?: boolean;\n\tposinset?: number;\n}\n\nfunction TableColumnField< Item >( {\n\titem,\n\tfields,\n\tcolumn,\n\talign,\n}: TableColumnFieldProps< Item > ) {\n\tconst field = fields.find( ( f ) => f.id === column );\n\n\tif ( ! field ) {\n\t\treturn null;\n\t}\n\n\tconst className = clsx( 'dataviews-view-table__cell-content-wrapper', {\n\t\t'dataviews-view-table__cell-align-end': align === 'end',\n\t\t'dataviews-view-table__cell-align-center': align === 'center',\n\t} );\n\n\treturn (\n\t\t<div className={ className }>\n\t\t\t<field.render item={ item } field={ field } />\n\t\t</div>\n\t);\n}\n\nfunction TableRow< Item >( {\n\thasBulkActions,\n\titem,\n\tlevel,\n\tactions,\n\tfields,\n\tid,\n\tview,\n\ttitleField,\n\tmediaField,\n\tdescriptionField,\n\tselection,\n\tgetItemId,\n\tisItemClickable,\n\tonClickItem,\n\trenderItemLink,\n\tonChangeSelection,\n\tisActionsColumnSticky,\n\tposinset,\n}: TableRowProps< Item > ) {\n\tconst { paginationInfo } = useContext( DataViewsContext );\n\tconst hasPossibleBulkAction = useHasAPossibleBulkAction( actions, item );\n\tconst isSelected = hasPossibleBulkAction && selection.includes( id );\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst {\n\t\tshowTitle = true,\n\t\tshowMedia = true,\n\t\tshowDescription = true,\n\t\tinfiniteScrollEnabled,\n\t} = view;\n\tconst handleMouseEnter = () => {\n\t\tsetIsHovered( true );\n\t};\n\tconst handleMouseLeave = () => {\n\t\tsetIsHovered( false );\n\t};\n\n\t// Will be set to true if `onTouchStart` fires. This happens before\n\t// `onClick` and can be used to exclude touchscreen devices from certain\n\t// behaviours.\n\tconst isTouchDeviceRef = useRef( false );\n\tconst columns = view.fields ?? [];\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\n\treturn (\n\t\t<tr\n\t\t\tclassName={ clsx( 'dataviews-view-table__row', {\n\t\t\t\t'is-selected': hasPossibleBulkAction && isSelected,\n\t\t\t\t'is-hovered': isHovered,\n\t\t\t\t'has-bulk-actions': hasPossibleBulkAction,\n\t\t\t} ) }\n\t\t\tonMouseEnter={ handleMouseEnter }\n\t\t\tonMouseLeave={ handleMouseLeave }\n\t\t\tonTouchStart={ () => {\n\t\t\t\tisTouchDeviceRef.current = true;\n\t\t\t} }\n\t\t\taria-setsize={\n\t\t\t\tinfiniteScrollEnabled ? paginationInfo.totalItems : undefined\n\t\t\t}\n\t\t\taria-posinset={ posinset }\n\t\t\trole={ infiniteScrollEnabled ? 'article' : undefined }\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tif ( ! hasPossibleBulkAction ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t! isTouchDeviceRef.current &&\n\t\t\t\t\tdocument.getSelection()?.type !== 'Range'\n\t\t\t\t) {\n\t\t\t\t\tif ( isAppleOS() ? event.metaKey : event.ctrlKey ) {\n\t\t\t\t\t\t// Handle non-consecutive selection.\n\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\tselection.includes( id )\n\t\t\t\t\t\t\t\t? selection.filter(\n\t\t\t\t\t\t\t\t\t\t( itemId ) => id !== itemId\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: [ ...selection, id ]\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Handle single selection\n\t\t\t\t\t\tonChangeSelection(\n\t\t\t\t\t\t\tselection.includes( id )\n\t\t\t\t\t\t\t\t? selection.filter(\n\t\t\t\t\t\t\t\t\t\t( itemId ) => id !== itemId\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: [ id ]\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t{ hasBulkActions && (\n\t\t\t\t<td className=\"dataviews-view-table__checkbox-column\">\n\t\t\t\t\t<div className=\"dataviews-view-table__cell-content-wrapper\">\n\t\t\t\t\t\t<DataViewsSelectionCheckbox\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\tdisabled={ ! hasPossibleBulkAction }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</td>\n\t\t\t) }\n\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t<td>\n\t\t\t\t\t<ColumnPrimary\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tlevel={ level }\n\t\t\t\t\t\ttitleField={ showTitle ? titleField : undefined }\n\t\t\t\t\t\tmediaField={ showMedia ? mediaField : undefined }\n\t\t\t\t\t\tdescriptionField={\n\t\t\t\t\t\t\tshowDescription ? descriptionField : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t/>\n\t\t\t\t</td>\n\t\t\t) }\n\t\t\t{ columns.map( ( column: string ) => {\n\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\n\t\t\t\treturn (\n\t\t\t\t\t<td\n\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<TableColumnField\n\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\tcolumn={ column }\n\t\t\t\t\t\t\talign={ align }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</td>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t\t{ !! actions?.length && (\n\t\t\t\t// Disable reason: we are not making the element interactive,\n\t\t\t\t// but preventing any click events from bubbling up to the\n\t\t\t\t// table row. This allows us to add a click handler to the row\n\t\t\t\t// itself (to toggle row selection) without erroneously\n\t\t\t\t// intercepting click events from ItemActions.\n\n\t\t\t\t/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */\n\t\t\t\t<td\n\t\t\t\t\tclassName={ clsx( 'dataviews-view-table__actions-column', {\n\t\t\t\t\t\t'dataviews-view-table__actions-column--sticky': true,\n\t\t\t\t\t\t'dataviews-view-table__actions-column--stuck':\n\t\t\t\t\t\t\tisActionsColumnSticky,\n\t\t\t\t\t} ) }\n\t\t\t\t\tonClick={ ( e ) => e.stopPropagation() }\n\t\t\t\t>\n\t\t\t\t\t<ItemActions item={ item } actions={ actions } />\n\t\t\t\t</td>\n\t\t\t\t/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */\n\t\t\t) }\n\t\t</tr>\n\t);\n}\n\nfunction ViewTable< Item >( {\n\tactions,\n\tdata,\n\tfields,\n\tgetItemId,\n\tgetItemLevel,\n\tisLoading = false,\n\tonChangeView,\n\tonChangeSelection,\n\tselection,\n\tsetOpenedFilter,\n\tonClickItem,\n\tisItemClickable,\n\trenderItemLink,\n\tview,\n\tclassName,\n\tempty,\n}: ViewTableProps< Item > ) {\n\tconst { containerRef } = useContext( DataViewsContext );\n\tconst headerMenuRefs = useRef<\n\t\tMap< string, { node: HTMLButtonElement; fallback: string } >\n\t>( new Map() );\n\tconst headerMenuToFocusRef = useRef< HTMLButtonElement >();\n\tconst [ nextHeaderMenuToFocus, setNextHeaderMenuToFocus ] =\n\t\tuseState< HTMLButtonElement >();\n\tconst hasBulkActions = useSomeItemHasAPossibleBulkAction( actions, data );\n\tconst [ contextMenuAnchor, setContextMenuAnchor ] = useState< {\n\t\tgetBoundingClientRect: () => DOMRect;\n\t} | null >( null );\n\n\tuseEffect( () => {\n\t\tif ( headerMenuToFocusRef.current ) {\n\t\t\theaderMenuToFocusRef.current.focus();\n\t\t\theaderMenuToFocusRef.current = undefined;\n\t\t}\n\t} );\n\n\tconst tableNoticeId = useId();\n\n\tconst isHorizontalScrollEnd = useIsHorizontalScrollEnd( {\n\t\tscrollContainerRef: containerRef,\n\t\tenabled: !! actions?.length,\n\t} );\n\n\tif ( nextHeaderMenuToFocus ) {\n\t\t// If we need to force focus, we short-circuit rendering here\n\t\t// to prevent any additional work while we handle that.\n\t\t// Clearing out the focus directive is necessary to make sure\n\t\t// future renders don't cause unexpected focus jumps.\n\t\theaderMenuToFocusRef.current = nextHeaderMenuToFocus;\n\t\tsetNextHeaderMenuToFocus( undefined );\n\t\treturn;\n\t}\n\n\tconst onHide = ( field: NormalizedField< Item > ) => {\n\t\tconst hidden = headerMenuRefs.current.get( field.id );\n\t\tconst fallback = hidden\n\t\t\t? headerMenuRefs.current.get( hidden.fallback )\n\t\t\t: undefined;\n\t\tsetNextHeaderMenuToFocus( fallback?.node );\n\t};\n\n\tconst handleHeaderContextMenu = ( event: React.MouseEvent ) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\t\tconst virtualAnchor = {\n\t\t\tgetBoundingClientRect: () => ( {\n\t\t\t\tx: event.clientX,\n\t\t\t\ty: event.clientY,\n\t\t\t\ttop: event.clientY,\n\t\t\t\tleft: event.clientX,\n\t\t\t\tright: event.clientX,\n\t\t\t\tbottom: event.clientY,\n\t\t\t\twidth: 0,\n\t\t\t\theight: 0,\n\t\t\t\ttoJSON: () => ( {} ),\n\t\t\t} ),\n\t\t};\n\t\twindow.requestAnimationFrame( () => {\n\t\t\tsetContextMenuAnchor( virtualAnchor );\n\t\t} );\n\t};\n\n\tconst hasData = !! data?.length;\n\n\tconst titleField = fields.find( ( field ) => field.id === view.titleField );\n\tconst mediaField = fields.find( ( field ) => field.id === view.mediaField );\n\tconst descriptionField = fields.find(\n\t\t( field ) => field.id === view.descriptionField\n\t);\n\n\tconst groupField = view.groupByField\n\t\t? fields.find( ( f ) => f.id === view.groupByField )\n\t\t: null;\n\tconst dataByGroup = groupField ? getDataByGroup( data, groupField ) : null;\n\tconst { showTitle = true, showMedia = true, showDescription = true } = view;\n\tconst hasPrimaryColumn =\n\t\t( titleField && showTitle ) ||\n\t\t( mediaField && showMedia ) ||\n\t\t( descriptionField && showDescription );\n\tconst columns = view.fields ?? [];\n\tconst headerMenuRef =\n\t\t( column: string, index: number ) => ( node: HTMLButtonElement ) => {\n\t\t\tif ( node ) {\n\t\t\t\theaderMenuRefs.current.set( column, {\n\t\t\t\t\tnode,\n\t\t\t\t\tfallback: columns[ index > 0 ? index - 1 : 1 ],\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\theaderMenuRefs.current.delete( column );\n\t\t\t}\n\t\t};\n\tconst isInfiniteScroll = view.infiniteScrollEnabled && ! dataByGroup;\n\n\treturn (\n\t\t<>\n\t\t\t<table\n\t\t\t\tclassName={ clsx( 'dataviews-view-table', className, {\n\t\t\t\t\t[ `has-${ view.layout?.density }-density` ]:\n\t\t\t\t\t\tview.layout?.density &&\n\t\t\t\t\t\t[ 'compact', 'comfortable' ].includes(\n\t\t\t\t\t\t\tview.layout.density\n\t\t\t\t\t\t),\n\t\t\t\t\t'has-bulk-actions': hasBulkActions,\n\t\t\t\t} ) }\n\t\t\t\taria-busy={ isLoading }\n\t\t\t\taria-describedby={ tableNoticeId }\n\t\t\t\trole={ isInfiniteScroll ? 'feed' : undefined }\n\t\t\t>\n\t\t\t\t<colgroup>\n\t\t\t\t\t{ hasBulkActions && (\n\t\t\t\t\t\t<col className=\"dataviews-view-table__col-checkbox\" />\n\t\t\t\t\t) }\n\t\t\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t\t\t<col className=\"dataviews-view-table__col-primary\" />\n\t\t\t\t\t) }\n\t\t\t\t\t{ columns.map( ( column ) => (\n\t\t\t\t\t\t<col\n\t\t\t\t\t\t\tkey={ `col-${ column }` }\n\t\t\t\t\t\t\tclassName={ `dataviews-view-table__col-${ column }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ !! actions?.length && (\n\t\t\t\t\t\t<col className=\"dataviews-view-table__col-actions\" />\n\t\t\t\t\t) }\n\t\t\t\t</colgroup>\n\t\t\t\t{ contextMenuAnchor && (\n\t\t\t\t\t<Popover\n\t\t\t\t\t\tanchor={ contextMenuAnchor }\n\t\t\t\t\t\tonClose={ () => setContextMenuAnchor( null ) }\n\t\t\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<PropertiesSection showLabel={ false } />\n\t\t\t\t\t</Popover>\n\t\t\t\t) }\n\t\t\t\t<thead onContextMenu={ handleHeaderContextMenu }>\n\t\t\t\t\t<tr className=\"dataviews-view-table__row\">\n\t\t\t\t\t\t{ hasBulkActions && (\n\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__checkbox-column\"\n\t\t\t\t\t\t\t\tscope=\"col\"\n\t\t\t\t\t\t\t\tonContextMenu={ handleHeaderContextMenu }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<BulkSelectionCheckbox\n\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ hasPrimaryColumn && (\n\t\t\t\t\t\t\t<th scope=\"col\">\n\t\t\t\t\t\t\t\t{ titleField && (\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef(\n\t\t\t\t\t\t\t\t\t\t\ttitleField.id,\n\t\t\t\t\t\t\t\t\t\t\t0\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ titleField.id }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={ false }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ columns.map( ( column, index ) => {\n\t\t\t\t\t\t\t// Explicit picks the supported styles.\n\t\t\t\t\t\t\tconst { width, maxWidth, minWidth, align } =\n\t\t\t\t\t\t\t\tview.layout?.styles?.[ column ] ?? {};\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\t\tkey={ column }\n\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\t\t\t\t\tminWidth,\n\t\t\t\t\t\t\t\t\t\ttextAlign: align,\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taria-sort={\n\t\t\t\t\t\t\t\t\t\tview.sort?.direction &&\n\t\t\t\t\t\t\t\t\t\tview.sort?.field === column\n\t\t\t\t\t\t\t\t\t\t\t? sortValues[ view.sort.direction ]\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tscope=\"col\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ColumnHeaderMenu\n\t\t\t\t\t\t\t\t\t\tref={ headerMenuRef( column, index ) }\n\t\t\t\t\t\t\t\t\t\tfieldId={ column }\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t\t\t\tonHide={ onHide }\n\t\t\t\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\t\t\t\tcanMove={\n\t\t\t\t\t\t\t\t\t\t\tview.layout?.enableMoving ?? true\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t{ !! actions?.length && (\n\t\t\t\t\t\t\t<th\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-view-table__actions-column',\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t'dataviews-view-table__actions-column--sticky':\n\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t'dataviews-view-table__actions-column--stuck':\n\t\t\t\t\t\t\t\t\t\t\t! isHorizontalScrollEnd,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span className=\"dataviews-view-table-header\">\n\t\t\t\t\t\t\t\t\t{ __( 'Actions' ) }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</th>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</tr>\n\t\t\t\t</thead>\n\t\t\t\t{ /* Render grouped data if groupByField is specified */ }\n\t\t\t\t{ hasData && groupField && dataByGroup ? (\n\t\t\t\t\tArray.from( dataByGroup.entries() ).map(\n\t\t\t\t\t\t( [ groupName, groupItems ] ) => (\n\t\t\t\t\t\t\t<tbody key={ `group-${ groupName }` }>\n\t\t\t\t\t\t\t\t<tr className=\"dataviews-view-table__group-header-row\">\n\t\t\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\t\t\tcolSpan={\n\t\t\t\t\t\t\t\t\t\t\tcolumns.length +\n\t\t\t\t\t\t\t\t\t\t\t( hasPrimaryColumn ? 1 : 0 ) +\n\t\t\t\t\t\t\t\t\t\t\t( hasBulkActions ? 1 : 0 ) +\n\t\t\t\t\t\t\t\t\t\t\t( actions?.length ? 1 : 0 )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tclassName=\"dataviews-view-table__group-header-cell\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ sprintf(\n\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__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\t\t\tgroupField.label,\n\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\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t{ groupItems.map( ( item, index ) => (\n\t\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\t\tlevel={\n\t\t\t\t\t\t\t\t\t\t\tview.showLevels &&\n\t\t\t\t\t\t\t\t\t\t\ttypeof getItemLevel === 'function'\n\t\t\t\t\t\t\t\t\t\t\t\t? getItemLevel( item )\n\t\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\thasBulkActions={ hasBulkActions }\n\t\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\t\tid={\n\t\t\t\t\t\t\t\t\t\t\tgetItemId( item ) ||\n\t\t\t\t\t\t\t\t\t\t\tindex.toString()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\t\t\t\tisActionsColumnSticky={\n\t\t\t\t\t\t\t\t\t\t\t! isHorizontalScrollEnd\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</tbody>\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) : (\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{ hasData &&\n\t\t\t\t\t\t\tdata.map( ( item, index ) => (\n\t\t\t\t\t\t\t\t<TableRow\n\t\t\t\t\t\t\t\t\tkey={ getItemId( item ) }\n\t\t\t\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\t\t\t\tlevel={\n\t\t\t\t\t\t\t\t\t\tview.showLevels &&\n\t\t\t\t\t\t\t\t\t\ttypeof getItemLevel === 'function'\n\t\t\t\t\t\t\t\t\t\t\t? getItemLevel( item )\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\thasBulkActions={ hasBulkActions }\n\t\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\t\t\t\tid={ getItemId( item ) || index.toString() }\n\t\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\t\ttitleField={ titleField }\n\t\t\t\t\t\t\t\t\tmediaField={ mediaField }\n\t\t\t\t\t\t\t\t\tdescriptionField={ descriptionField }\n\t\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t\t\tonChangeSelection={ onChangeSelection }\n\t\t\t\t\t\t\t\t\tonClickItem={ onClickItem }\n\t\t\t\t\t\t\t\t\trenderItemLink={ renderItemLink }\n\t\t\t\t\t\t\t\t\tisItemClickable={ isItemClickable }\n\t\t\t\t\t\t\t\t\tisActionsColumnSticky={\n\t\t\t\t\t\t\t\t\t\t! isHorizontalScrollEnd\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tposinset={\n\t\t\t\t\t\t\t\t\t\tisInfiniteScroll ? index + 1 : undefined\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</tbody>\n\t\t\t\t) }\n\t\t\t</table>\n\t\t\t<div\n\t\t\t\tclassName={ clsx( {\n\t\t\t\t\t'dataviews-loading': isLoading,\n\t\t\t\t\t'dataviews-no-results': ! hasData && ! isLoading,\n\t\t\t\t} ) }\n\t\t\t\tid={ tableNoticeId }\n\t\t\t>\n\t\t\t\t{ ! hasData &&\n\t\t\t\t\t( isLoading ? (\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</p>\n\t\t\t\t\t) : (\n\t\t\t\t\t\tempty\n\t\t\t\t\t) ) }\n\t\t\t\t{ hasData && isLoading && (\n\t\t\t\t\t<p className=\"dataviews-loading-more\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default ViewTable;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,kBAA4B;AAC5B,wBAAiC;AACjC,qBAMO;AACP,sBAA0B;AAK1B,+BAA6B;AAC7B,0CAAuC;AACvC,oCAAwB;AACxB,uBAA2B;AAC3B,oCAIO;AAQP,gCAA6B;AAC7B,4BAA0B;AAC1B,0CAAyC;AACzC,+BAA2B;AAC3B,gCAAkC;AAqD/B;AAnBH,SAAS,iBAA0B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,QAAQ,OAAO,KAAM,CAAE,MAAO,EAAE,OAAO,MAAO;AAEpD,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,gBAAY,YAAAA,SAAM,8CAA8C;AAAA,IACrE,wCAAwC,UAAU;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,QAAQ,IAAI;AAAA;AAAA,YA1B1B,UAAW,IAAK;AAAA,UA4BvB,CACC,GACJ;AAAA;AAAA;AAAA,IAEF;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,eAAY,YAAAA,SAAM;AAAA,UACjB,qBAAqB;AAAA,UACrB,wBAAwB,CAAE,WAAW,CAAE;AAAA,QACxC,CAAE;AAAA,QACF,IAAK;AAAA,QAEH;AAAA,WAAE,YACD,YACD,4CAAC,OACA,sDAAC,6BAAQ,GACV,IAEA;AAAA,UAEA,WAAW,aACZ,4CAAC,OAAE,WAAU,0BACZ,sDAAC,6BAAQ,GACV;AAAA;AAAA;AAAA,IAEF;AAAA,KACD;AAEF;AAEA,IAAO,gBAAQ;",
|
|
6
6
|
"names": ["clsx", "DataViewsContext", "DataViewsSelectionCheckbox", "ColumnPrimary", "ItemActions", "getDataByGroup", "ColumnHeaderMenu"]
|
|
7
7
|
}
|
|
@@ -37,7 +37,6 @@ var import_date = require("@wordpress/date");
|
|
|
37
37
|
var import_render_from_elements = __toESM(require("./utils/render-from-elements"));
|
|
38
38
|
var import_constants = require("../constants");
|
|
39
39
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
-
var getFormattedDate = (dateToDisplay) => (0, import_date.dateI18n)((0, import_date.getSettings)().formats.date, (0, import_date.getDate)(dateToDisplay));
|
|
41
40
|
function sort(a, b, direction) {
|
|
42
41
|
const timeA = new Date(a).getTime();
|
|
43
42
|
const timeB = new Date(b).getTime();
|
|
@@ -58,7 +57,10 @@ var date_default = {
|
|
|
58
57
|
if (!value) {
|
|
59
58
|
return "";
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
if (field.type !== "date") {
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
return (0, import_date.dateI18n)(field.format.date, (0, import_date.getDate)(value));
|
|
62
64
|
},
|
|
63
65
|
enableSorting: true,
|
|
64
66
|
filterBy: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/field-types/date.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dateI18n, getDate
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dateI18n, getDate } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tFieldTypeDefinition,\n} from '../types';\nimport RenderFromElements from './utils/render-from-elements';\nimport {\n\tOPERATOR_ON,\n\tOPERATOR_NOT_ON,\n\tOPERATOR_BEFORE,\n\tOPERATOR_AFTER,\n\tOPERATOR_BEFORE_INC,\n\tOPERATOR_AFTER_INC,\n\tOPERATOR_IN_THE_PAST,\n\tOPERATOR_OVER,\n\tOPERATOR_BETWEEN,\n} from '../constants';\n\nfunction sort( a: any, b: any, direction: SortDirection ) {\n\tconst timeA = new Date( a ).getTime();\n\tconst timeB = new Date( b ).getTime();\n\n\treturn direction === 'asc' ? timeA - timeB : timeB - timeA;\n}\n\nexport default {\n\tsort,\n\tEdit: 'date',\n\tisValid: {\n\t\telements: true,\n\t\tcustom: () => null,\n\t},\n\trender: ( { item, field }: DataViewRenderFieldProps< any > ) => {\n\t\tif ( field.hasElements ) {\n\t\t\treturn <RenderFromElements item={ item } field={ field } />;\n\t\t}\n\n\t\tconst value = field.getValue( { item } );\n\t\tif ( ! value ) {\n\t\t\treturn '';\n\t\t}\n\n\t\t// Not all fields have format, but date fields do.\n\t\t//\n\t\t// At runtime, this method will never be called for non-date fields.\n\t\t// However, the type system does not know this, so we need to check it.\n\t\t// There's an opportunity here to improve the type system.\n\t\tif ( field.type !== 'date' ) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn dateI18n( field.format.date, getDate( value ) );\n\t},\n\tenableSorting: true,\n\tfilterBy: {\n\t\tdefaultOperators: [\n\t\t\tOPERATOR_ON,\n\t\t\tOPERATOR_NOT_ON,\n\t\t\tOPERATOR_BEFORE,\n\t\t\tOPERATOR_AFTER,\n\t\t\tOPERATOR_BEFORE_INC,\n\t\t\tOPERATOR_AFTER_INC,\n\t\t\tOPERATOR_IN_THE_PAST,\n\t\t\tOPERATOR_OVER,\n\t\t\tOPERATOR_BETWEEN,\n\t\t],\n\t\tvalidOperators: [\n\t\t\tOPERATOR_ON,\n\t\t\tOPERATOR_NOT_ON,\n\t\t\tOPERATOR_BEFORE,\n\t\t\tOPERATOR_AFTER,\n\t\t\tOPERATOR_BEFORE_INC,\n\t\t\tOPERATOR_AFTER_INC,\n\t\t\tOPERATOR_IN_THE_PAST,\n\t\t\tOPERATOR_OVER,\n\t\t\tOPERATOR_BETWEEN,\n\t\t],\n\t},\n} satisfies FieldTypeDefinition< any >;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAkC;AAUlC,kCAA+B;AAC/B,uBAUO;AAkBG;AAhBV,SAAS,KAAM,GAAQ,GAAQ,WAA2B;AACzD,QAAM,QAAQ,IAAI,KAAM,CAAE,EAAE,QAAQ;AACpC,QAAM,QAAQ,IAAI,KAAM,CAAE,EAAE,QAAQ;AAEpC,SAAO,cAAc,QAAQ,QAAQ,QAAQ,QAAQ;AACtD;AAEA,IAAO,eAAQ;AAAA,EACd;AAAA,EACA,MAAM;AAAA,EACN,SAAS;AAAA,IACR,UAAU;AAAA,IACV,QAAQ,MAAM;AAAA,EACf;AAAA,EACA,QAAQ,CAAE,EAAE,MAAM,MAAM,MAAwC;AAC/D,QAAK,MAAM,aAAc;AACxB,aAAO,4CAAC,4BAAAA,SAAA,EAAmB,MAAc,OAAgB;AAAA,IAC1D;AAEA,UAAM,QAAQ,MAAM,SAAU,EAAE,KAAK,CAAE;AACvC,QAAK,CAAE,OAAQ;AACd,aAAO;AAAA,IACR;AAOA,QAAK,MAAM,SAAS,QAAS;AAC5B,aAAO;AAAA,IACR;AAEA,eAAO,sBAAU,MAAM,OAAO,UAAM,qBAAS,KAAM,CAAE;AAAA,EACtD;AAAA,EACA,eAAe;AAAA,EACf,UAAU;AAAA,IACT,kBAAkB;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA,gBAAgB;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["RenderFromElements"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types/dataform.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Field, FieldValidity } from './field-api';\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type PanelSummaryField = string | string[];\nexport type NormalizedPanelSummaryField = string[];\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n\tsummary?: PanelSummaryField;\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n\tsummary: NormalizedPanelSummaryField;\n};\n\nexport type CardSummaryField =\n\t| PanelSummaryField // Basic usage: string or string[]\n\t| Array<\n\t\t\t| string\n\t\t\t| {\n\t\t\t\t\tid: string;\n\t\t\t\t\tvisibility: 'always' | 'when-collapsed';\n\t\t\t }\n\t >;\n\nexport type NormalizedCardSummaryField = Array< {\n\tid: string;\n\tvisibility: 'always' | 'when-collapsed';\n} >;\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t\t\t// isCollapsible cannot be true if withHeader is false as well.\n\t\t\tisCollapsible?: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t\t\tsummary?: CardSummaryField;\n\t\t\tisCollapsible?: boolean | undefined;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t\t\t// Summary is an empty array\n\t\t\tsummary: [];\n\t\t\t// If no header, the card should not be collapsible.\n\t\t\tisCollapsible: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t\t\tsummary: NormalizedCardSummaryField;\n\t\t\tisCollapsible: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n\tstyles?: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n\tstyles: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\n\nexport type
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Field, FieldValidity } from './field-api';\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row' | 'details';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type PanelSummaryField = string | string[];\nexport type NormalizedPanelSummaryField = string[];\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n\tsummary?: PanelSummaryField;\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n\tsummary: NormalizedPanelSummaryField;\n};\n\nexport type CardSummaryField =\n\t| PanelSummaryField // Basic usage: string or string[]\n\t| Array<\n\t\t\t| string\n\t\t\t| {\n\t\t\t\t\tid: string;\n\t\t\t\t\tvisibility: 'always' | 'when-collapsed';\n\t\t\t }\n\t >;\n\nexport type NormalizedCardSummaryField = Array< {\n\tid: string;\n\tvisibility: 'always' | 'when-collapsed';\n} >;\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t\t\t// isCollapsible cannot be true if withHeader is false as well.\n\t\t\tisCollapsible?: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t\t\tsummary?: CardSummaryField;\n\t\t\tisCollapsible?: boolean | undefined;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t\t\t// Summary is an empty array\n\t\t\tsummary: [];\n\t\t\t// If no header, the card should not be collapsible.\n\t\t\tisCollapsible: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t\t\tsummary: NormalizedCardSummaryField;\n\t\t\tisCollapsible: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n\tstyles?: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n\tstyles: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\n\nexport type DetailsLayout = {\n\ttype: 'details';\n\tsummary?: string;\n};\nexport type NormalizedDetailsLayout = {\n\ttype: 'details';\n\tsummary: string;\n};\n\nexport type Layout =\n\t| RegularLayout\n\t| PanelLayout\n\t| CardLayout\n\t| RowLayout\n\t| DetailsLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout\n\t| NormalizedRowLayout\n\t| NormalizedDetailsLayout;\n\nexport type NormalizedSummaryField =\n\t| NormalizedPanelSummaryField\n\t| NormalizedCardSummaryField;\n\nexport type FormField = {\n\tid: string;\n\tlabel?: string;\n\tdescription?: string;\n\tlayout?: Layout;\n\tchildren?: Array< FormField | string >;\n};\nexport type NormalizedFormField = {\n\tid: string;\n\tlayout: NormalizedLayout;\n\tlabel?: string;\n\tdescription?: string;\n\tchildren?: NormalizedFormField[];\n};\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\tlayout?: Layout;\n\tfields?: Array< FormField | string >;\n};\nexport type NormalizedForm = {\n\tlayout: NormalizedLayout;\n\tfields: NormalizedFormField[];\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n\tvalidity?: FormValidity;\n}\n\nexport type FormValidity = Record< string, FieldValidity > | undefined;\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: NormalizedFormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n\tvalidity?: FieldValidity;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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 field to group by.\n\t */\n\tgroupByField?: string;\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 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 type View
|
|
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 field to group by.\n\t */\n\tgroupByField?: string;\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 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\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 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\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\tpickerGrid?: Omit< ViewPickerGrid, 'type' >;\n\tpickerTable?: Omit< ViewPickerTable, 'type' >;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types/field-api.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType } from 'react';\n\n/**\n * Utility type that makes all properties of T optional recursively.\n * Used by field setValue functions to allow partial item updates.\n */\nexport type DeepPartial< T > = {\n\t[ P in keyof T ]?: T[ P ] extends object ? DeepPartial< T[ P ] > : T[ P ];\n};\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport interface NormalizedFilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'number'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: Rules< Item >;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit:\n\t\t| ComponentType< DataFormControlProps< Item > >\n\t\t| string\n\t\t| EditConfig\n\t\t| null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\telements?: boolean;\n\tcustom?:\n\t\t| ( ( item: Item, field: NormalizedField< Item > ) => null | string )\n\t\t| ( (\n\t\t\t\titem: Item,\n\t\t\t\tfield: NormalizedField< Item >\n\t\t ) => Promise< null | string > );\n};\n\n/**\n * Edit configuration for textarea controls.\n */\nexport type EditConfigTextarea = {\n\tcontrol: 'textarea';\n\t/**\n\t * Number of rows for the textarea.\n\t */\n\trows?: number;\n};\n\n/**\n * Edit configuration for text controls.\n */\nexport type EditConfigText = {\n\tcontrol: 'text';\n\t/**\n\t * Prefix component to display before the input.\n\t */\n\tprefix?: React.ComponentType;\n\t/**\n\t * Suffix component to display after the input.\n\t */\n\tsuffix?: React.ComponentType;\n};\n\n/**\n * Edit configuration for other control types (excluding 'text' and 'textarea').\n */\nexport type EditConfigGeneric = {\n\tcontrol: Exclude< FieldType, 'text' | 'textarea' >;\n};\n\n/**\n * Edit configuration object with type-safe control options.\n * Each control type has its own specific configuration properties.\n */\nexport type EditConfig =\n\t| EditConfigTextarea\n\t| EditConfigText\n\t| EditConfigGeneric;\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string | EditConfig;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field can be hidden in the UI.\n\t */\n\tenableHiding?: boolean;\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 for elements.\n\t */\n\tgetElements?: () => Promise< Option[] >;\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n\n\t/**\n\t * Callback used to set the value of the field on the item.\n\t * Used for editing operations to update field values.\n\t */\n\tsetValue?: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n};\n\nexport type
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType } from 'react';\n\n/**\n * Utility type that makes all properties of T optional recursively.\n * Used by field setValue functions to allow partial item updates.\n */\nexport type DeepPartial< T > = {\n\t[ P in keyof T ]?: T[ P ] extends object ? DeepPartial< T[ P ] > : T[ P ];\n};\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport interface NormalizedFilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'number'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: Rules< Item >;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit:\n\t\t| ComponentType< DataFormControlProps< Item > >\n\t\t| string\n\t\t| EditConfig\n\t\t| null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\telements?: boolean;\n\tcustom?:\n\t\t| ( ( item: Item, field: NormalizedField< Item > ) => null | string )\n\t\t| ( (\n\t\t\t\titem: Item,\n\t\t\t\tfield: NormalizedField< Item >\n\t\t ) => Promise< null | string > );\n};\n\n/**\n * Edit configuration for textarea controls.\n */\nexport type EditConfigTextarea = {\n\tcontrol: 'textarea';\n\t/**\n\t * Number of rows for the textarea.\n\t */\n\trows?: number;\n};\n\n/**\n * Edit configuration for text controls.\n */\nexport type EditConfigText = {\n\tcontrol: 'text';\n\t/**\n\t * Prefix component to display before the input.\n\t */\n\tprefix?: React.ComponentType;\n\t/**\n\t * Suffix component to display after the input.\n\t */\n\tsuffix?: React.ComponentType;\n};\n\n/**\n * Edit configuration for other control types (excluding 'text' and 'textarea').\n */\nexport type EditConfigGeneric = {\n\tcontrol: Exclude< FieldType, 'text' | 'textarea' >;\n};\n\n/**\n * Edit configuration object with type-safe control options.\n * Each control type has its own specific configuration properties.\n */\nexport type EditConfig =\n\t| EditConfigTextarea\n\t| EditConfigText\n\t| EditConfigGeneric;\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string | EditConfig;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field can be hidden in the UI.\n\t */\n\tenableHiding?: boolean;\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 for elements.\n\t */\n\tgetElements?: () => Promise< Option[] >;\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n\n\t/**\n\t * Callback used to set the value of the field on the item.\n\t * Used for editing operations to update field values.\n\t */\n\tsetValue?: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\n\t/**\n\t * Display format configuration for fields.\n\t */\n\tformat?: FormatDate;\n};\n\n/**\n * Format for date fields:\n *\n * - date: the format string (e.g., 'F j, Y' for WordPress default format like 'March 10, 2023')\n * - weekStartsOn: to specify the first day of the week ('sunday', 'monday', etc.).\n *\n * If not provided, defaults to WordPress date format settings.\n */\ntype FormatDate = {\n\tdate?: string;\n\tweekStartsOn?: DayString;\n};\nexport type DayNumber = 0 | 1 | 2 | 3 | 4 | 5 | 6;\nexport type DayString =\n\t| 'sunday'\n\t| 'monday'\n\t| 'tuesday'\n\t| 'wednesday'\n\t| 'thursday'\n\t| 'friday'\n\t| 'saturday';\n\ntype NormalizedFieldBase< Item > = Omit< Field< Item >, 'Edit' > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\tsetValue: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\thasElements: boolean;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: Rules< Item >;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: NormalizedFilterByConfig | false;\n\treadOnly: boolean;\n};\n\ntype NormalizedFieldDate< Item > = NormalizedFieldBase< Item > & {\n\ttype: 'date';\n\tformat: Required< FormatDate >;\n};\n\ntype NormalizedFieldGeneric< Item > = NormalizedFieldBase< Item > & {\n\ttype?: Exclude< FieldType, 'date' >;\n\tformat: {};\n};\n\nexport type NormalizedField< Item > =\n\t| NormalizedFieldGeneric< Item >\n\t| NormalizedFieldDate< Item >;\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type FieldValidity = {\n\trequired?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage?: string;\n\t};\n\telements?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tcustom?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tchildren?: Record< string, FieldValidity >;\n};\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: DeepPartial< Item > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n\t/**\n\t * Validity information for the field, if any.\n\t */\n\tvalidity?: FieldValidity;\n\t/**\n\t * Configuration object for the control.\n\t */\n\tconfig?: {\n\t\tprefix?: React.ComponentType;\n\t\tsuffix?: React.ComponentType;\n\t\trows?: number;\n\t};\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n\tconfig?: {\n\t\tsizes: string;\n\t};\n};\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -33,10 +33,12 @@ __export(normalize_fields_exports, {
|
|
|
33
33
|
default: () => normalizeFields
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(normalize_fields_exports);
|
|
36
|
+
var import_date = require("@wordpress/date");
|
|
36
37
|
var import_field_types = __toESM(require("../field-types"));
|
|
37
38
|
var import_dataform_controls = require("../dataform-controls");
|
|
38
39
|
var import_constants = require("../constants");
|
|
39
40
|
var import_has_elements = __toESM(require("./has-elements"));
|
|
41
|
+
var import_week_starts_on = require("./week-starts-on");
|
|
40
42
|
var getValueFromId = (id) => ({ item }) => {
|
|
41
43
|
const path = id.split(".");
|
|
42
44
|
let value = item;
|
|
@@ -141,8 +143,9 @@ function normalizeFields(fields) {
|
|
|
141
143
|
return fieldTypeDefinition.render({ item, field: renderedField });
|
|
142
144
|
};
|
|
143
145
|
const filterBy = getFilterBy(field, fieldTypeDefinition);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
const { type, ...fieldWithoutType } = field;
|
|
147
|
+
const baseField = {
|
|
148
|
+
...fieldWithoutType,
|
|
146
149
|
label: field.label || field.id,
|
|
147
150
|
header: field.header || field.label || field.id,
|
|
148
151
|
getValue,
|
|
@@ -155,8 +158,25 @@ function normalizeFields(fields) {
|
|
|
155
158
|
enableHiding: field.enableHiding ?? true,
|
|
156
159
|
enableSorting: field.enableSorting ?? fieldTypeDefinition.enableSorting ?? true,
|
|
157
160
|
filterBy,
|
|
158
|
-
readOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false
|
|
161
|
+
readOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false,
|
|
162
|
+
format: {}
|
|
159
163
|
};
|
|
164
|
+
if (field.type === "date") {
|
|
165
|
+
const format = {
|
|
166
|
+
date: field.format?.date !== void 0 && typeof field.format.date === "string" ? field.format.date : (0, import_date.getSettings)().formats.date,
|
|
167
|
+
weekStartsOn: field.format?.weekStartsOn !== void 0 && import_week_starts_on.DAYS_OF_WEEK.includes(
|
|
168
|
+
field.format?.weekStartsOn
|
|
169
|
+
) ? field.format.weekStartsOn : (0, import_week_starts_on.numberToWeekStartsOn)(
|
|
170
|
+
(0, import_date.getSettings)().l10n.startOfWeek
|
|
171
|
+
)
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
...baseField,
|
|
175
|
+
type: "date",
|
|
176
|
+
format
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return { ...baseField, type: field.type, format: {} };
|
|
160
180
|
});
|
|
161
181
|
}
|
|
162
182
|
//# sourceMappingURL=normalize-fields.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/normalize-fields.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from '../field-types';\nimport type {\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from '../types';\nimport { getControl } from '../dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from '../constants';\nimport hasElements from './has-elements';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nconst setValueFromId =\n\t( id: string ) =>\n\t( { value }: { value: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tconst result: any = {};\n\t\tlet current = result;\n\n\t\tfor ( const segment of path.slice( 0, -1 ) ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t\tcurrent = current[ segment ];\n\t\t}\n\n\t\tcurrent[ path.at( -1 )! ] = value;\n\t\treturn result;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( hasElements( field ) && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif (\n\t\thasElements( field ) &&\n\t\tdefaultOperators.includes( OPERATOR_BETWEEN )\n\t) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport default function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\t\tconst setValue = field.setValue || setValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid = {\n\t\t\t...fieldTypeDefinition.isValid,\n\t\t\t...field.isValid,\n\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,yBAAmC;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { getSettings } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from '../field-types';\nimport type {\n\tDayString,\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from '../types';\nimport { getControl } from '../dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from '../constants';\nimport hasElements from './has-elements';\nimport { numberToWeekStartsOn, DAYS_OF_WEEK } from './week-starts-on';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nconst setValueFromId =\n\t( id: string ) =>\n\t( { value }: { value: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tconst result: any = {};\n\t\tlet current = result;\n\n\t\tfor ( const segment of path.slice( 0, -1 ) ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t\tcurrent = current[ segment ];\n\t\t}\n\n\t\tcurrent[ path.at( -1 )! ] = value;\n\t\treturn result;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( hasElements( field ) && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif (\n\t\thasElements( field ) &&\n\t\tdefaultOperators.includes( OPERATOR_BETWEEN )\n\t) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport default function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\t\tconst setValue = field.setValue || setValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid = {\n\t\t\t...fieldTypeDefinition.isValid,\n\t\t\t...field.isValid,\n\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\t/**\n\t\t * NormalizedField is a discriminated union type: the shape of the format property\n\t\t * depends on the type property. For example, for the 'date' type, the format\n\t\t * contains date or weekStartsOn \u2014 which are not valid for other types.\n\t\t *\n\t\t * Being type and format interdependent, we need to write the code\n\t\t * in a way that TypeScript is able to statically infer the types.\n\t\t * That's why we have a return branch for every item in the union type.\n\t\t *\n\t\t * See a longer explanation with examples at\n\t\t * https://github.com/WordPress/gutenberg/pull/72999#discussion_r2523145453\n\t\t */\n\t\tconst { type, ...fieldWithoutType } = field;\n\n\t\tconst baseField = {\n\t\t\t...fieldWithoutType,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\tsetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\thasElements: hasElements( field ),\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting:\n\t\t\t\tfield.enableSorting ??\n\t\t\t\tfieldTypeDefinition.enableSorting ??\n\t\t\t\ttrue,\n\t\t\tfilterBy,\n\t\t\treadOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false,\n\t\t\tformat: {},\n\t\t};\n\n\t\tif ( field.type === 'date' ) {\n\t\t\tconst format = {\n\t\t\t\tdate:\n\t\t\t\t\tfield.format?.date !== undefined &&\n\t\t\t\t\ttypeof field.format.date === 'string'\n\t\t\t\t\t\t? field.format.date\n\t\t\t\t\t\t: getSettings().formats.date,\n\t\t\t\tweekStartsOn:\n\t\t\t\t\tfield.format?.weekStartsOn !== undefined &&\n\t\t\t\t\tDAYS_OF_WEEK.includes(\n\t\t\t\t\t\tfield.format?.weekStartsOn as DayString\n\t\t\t\t\t)\n\t\t\t\t\t\t? field.format.weekStartsOn\n\t\t\t\t\t\t: numberToWeekStartsOn(\n\t\t\t\t\t\t\t\tgetSettings().l10n.startOfWeek\n\t\t\t\t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A,QACN,GAAG;AAAA,QACH,MAAM;AAAA,QACN;AAAA,MACD;AAAA,IACD;AAEA,WAAO,EAAE,GAAG,WAAW,MAAM,MAAM,MAAM,QAAQ,CAAC,EAAE;AAAA,EACrD,CAAE;AACH;",
|
|
6
6
|
"names": ["hasElements", "getFieldTypeDefinition", "sort", "render"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/dataviews/src/utils/week-starts-on.ts
|
|
21
|
+
var week_starts_on_exports = {};
|
|
22
|
+
__export(week_starts_on_exports, {
|
|
23
|
+
DAYS_OF_WEEK: () => DAYS_OF_WEEK,
|
|
24
|
+
numberToWeekStartsOn: () => numberToWeekStartsOn,
|
|
25
|
+
weekStartsOnToNumber: () => weekStartsOnToNumber
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(week_starts_on_exports);
|
|
28
|
+
var DAYS_OF_WEEK = [
|
|
29
|
+
"sunday",
|
|
30
|
+
"monday",
|
|
31
|
+
"tuesday",
|
|
32
|
+
"wednesday",
|
|
33
|
+
"thursday",
|
|
34
|
+
"friday",
|
|
35
|
+
"saturday"
|
|
36
|
+
];
|
|
37
|
+
var DEFAULT_DAY_STRING = "sunday";
|
|
38
|
+
var DEFAULT_DAY_NUMBER = 0;
|
|
39
|
+
function weekStartsOnToNumber(day) {
|
|
40
|
+
const index = DAYS_OF_WEEK.indexOf(day);
|
|
41
|
+
if (index === -1) {
|
|
42
|
+
return DEFAULT_DAY_NUMBER;
|
|
43
|
+
}
|
|
44
|
+
return index;
|
|
45
|
+
}
|
|
46
|
+
function numberToWeekStartsOn(day) {
|
|
47
|
+
const result = DAYS_OF_WEEK[day];
|
|
48
|
+
if (result === void 0) {
|
|
49
|
+
return DEFAULT_DAY_STRING;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
DAYS_OF_WEEK,
|
|
56
|
+
numberToWeekStartsOn,
|
|
57
|
+
weekStartsOnToNumber
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=week-starts-on.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/week-starts-on.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { DayNumber, DayString } from '../types/field-api';\n\nexport const DAYS_OF_WEEK: DayString[] = [\n\t'sunday',\n\t'monday',\n\t'tuesday',\n\t'wednesday',\n\t'thursday',\n\t'friday',\n\t'saturday',\n];\nconst DEFAULT_DAY_STRING = 'sunday';\nconst DEFAULT_DAY_NUMBER = 0;\n\n/**\n * Converts a weekStartsOn string to a number (0-6).\n *\n * @param day - The day name ('sunday', 'monday', etc.)\n * @return The corresponding number (0 for Sunday, 1 for Monday, etc.)\n */\nexport function weekStartsOnToNumber( day: DayString ): DayNumber {\n\tconst index = DAYS_OF_WEEK.indexOf( day );\n\tif ( index === -1 ) {\n\t\treturn DEFAULT_DAY_NUMBER;\n\t}\n\n\treturn index as DayNumber;\n}\n\n/**\n * Converts a weekStartsOn number (0-6) to a string.\n *\n * @param day - The day number (0 for Sunday, 1 for Monday, etc.)\n * @return The corresponding day name ('sunday', 'monday', etc.)\n */\nexport function numberToWeekStartsOn( day: DayNumber ): DayString {\n\tconst result = DAYS_OF_WEEK[ day ];\n\tif ( result === undefined ) {\n\t\treturn DEFAULT_DAY_STRING;\n\t}\n\n\treturn result;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,eAA4B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AACA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAQpB,SAAS,qBAAsB,KAA4B;AACjE,QAAM,QAAQ,aAAa,QAAS,GAAI;AACxC,MAAK,UAAU,IAAK;AACnB,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAQO,SAAS,qBAAsB,KAA4B;AACjE,QAAM,SAAS,aAAc,GAAI;AACjC,MAAK,WAAW,QAAY;AAC3B,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|