@wordpress/dataviews 13.0.0 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +2 -1
- package/build/components/dataform-controls/date.cjs +11 -1
- package/build/components/dataform-controls/date.cjs.map +2 -2
- package/build/components/dataform-controls/datetime.cjs +23 -32
- package/build/components/dataform-controls/datetime.cjs.map +2 -2
- package/build/components/dataform-controls/utils/relative-date-control.cjs +2 -1
- package/build/components/dataform-controls/utils/relative-date-control.cjs.map +2 -2
- package/build/components/dataform-layouts/normalize-form.cjs +19 -1
- package/build/components/dataform-layouts/normalize-form.cjs.map +2 -2
- package/build/components/dataform-layouts/panel/index.cjs +1 -1
- package/build/components/dataform-layouts/panel/index.cjs.map +2 -2
- package/build/components/dataform-layouts/panel/modal.cjs +4 -3
- package/build/components/dataform-layouts/panel/modal.cjs.map +2 -2
- package/build/components/dataviews-layout/index.cjs +12 -3
- package/build/components/dataviews-layout/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/grid/composite-grid.cjs +5 -1
- package/build/components/dataviews-layouts/grid/composite-grid.cjs.map +2 -2
- package/build/components/dataviews-layouts/index.cjs +3 -3
- package/build/components/dataviews-layouts/index.cjs.map +3 -3
- package/build/components/dataviews-layouts/picker-grid/index.cjs +13 -2
- package/build/components/dataviews-layouts/picker-grid/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/table/index.cjs +98 -89
- package/build/components/dataviews-layouts/table/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/table/{use-is-horizontal-scroll-end.cjs → use-scroll-state.cjs} +29 -33
- package/build/components/dataviews-layouts/table/use-scroll-state.cjs.map +7 -0
- package/build/components/dataviews-layouts/utils/density-picker.cjs.map +2 -2
- package/build/components/dataviews-layouts/utils/grid-config-options.cjs +45 -0
- package/build/components/dataviews-layouts/utils/grid-config-options.cjs.map +7 -0
- package/build/dataviews/index.cjs +12 -8
- package/build/dataviews/index.cjs.map +2 -2
- package/build/dataviews-picker/index.cjs +1 -1
- package/build/dataviews-picker/index.cjs.map +2 -2
- package/build/types/dataform.cjs.map +1 -1
- package/build/types/dataviews.cjs.map +1 -1
- package/build-module/components/dataform-controls/date.mjs +11 -1
- package/build-module/components/dataform-controls/date.mjs.map +2 -2
- package/build-module/components/dataform-controls/datetime.mjs +24 -33
- package/build-module/components/dataform-controls/datetime.mjs.map +2 -2
- package/build-module/components/dataform-controls/utils/relative-date-control.mjs +2 -1
- package/build-module/components/dataform-controls/utils/relative-date-control.mjs.map +2 -2
- package/build-module/components/dataform-layouts/normalize-form.mjs +19 -1
- package/build-module/components/dataform-layouts/normalize-form.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/index.mjs +1 -1
- package/build-module/components/dataform-layouts/panel/index.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/modal.mjs +4 -3
- package/build-module/components/dataform-layouts/panel/modal.mjs.map +2 -2
- package/build-module/components/dataviews-layout/index.mjs +12 -3
- package/build-module/components/dataviews-layout/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs +5 -1
- package/build-module/components/dataviews-layouts/grid/composite-grid.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/index.mjs +3 -3
- package/build-module/components/dataviews-layouts/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/picker-grid/index.mjs +13 -2
- package/build-module/components/dataviews-layouts/picker-grid/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/index.mjs +98 -89
- package/build-module/components/dataviews-layouts/table/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/use-scroll-state.mjs +46 -0
- package/build-module/components/dataviews-layouts/table/use-scroll-state.mjs.map +7 -0
- package/build-module/components/dataviews-layouts/utils/density-picker.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/utils/grid-config-options.mjs +14 -0
- package/build-module/components/dataviews-layouts/utils/grid-config-options.mjs.map +7 -0
- package/build-module/dataviews/index.mjs +12 -8
- package/build-module/dataviews/index.mjs.map +2 -2
- package/build-module/dataviews-picker/index.mjs +1 -1
- package/build-module/dataviews-picker/index.mjs.map +2 -2
- package/build-style/style-rtl.css +47 -5
- package/build-style/style.css +47 -5
- package/build-types/components/dataform-controls/date.d.ts.map +1 -1
- package/build-types/components/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/components/dataform-controls/utils/relative-date-control.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/normalize-form.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/modal.d.ts.map +1 -1
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/grid/composite-grid.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/index.d.ts +3 -3
- package/build-types/components/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/picker-grid/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts +25 -0
- package/build-types/components/dataviews-layouts/table/use-scroll-state.d.ts.map +1 -0
- package/build-types/components/dataviews-layouts/utils/density-picker.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/utils/grid-config-options.d.ts +2 -0
- package/build-types/components/dataviews-layouts/utils/grid-config-options.d.ts.map +1 -0
- package/build-types/dataform/stories/index.story.d.ts +26 -1
- package/build-types/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/dataform/stories/layout-panel.d.ts +3 -1
- package/build-types/dataform/stories/layout-panel.d.ts.map +1 -1
- package/build-types/dataviews/index.d.ts.map +1 -1
- package/build-types/dataviews/stories/empty.d.ts +1 -2
- package/build-types/dataviews/stories/empty.d.ts.map +1 -1
- package/build-types/dataviews/stories/free-composition.d.ts.map +1 -1
- package/build-types/dataviews/stories/index.story.d.ts +18 -10
- package/build-types/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/dataviews/stories/infinite-scroll.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-activity.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-custom.d.ts +3 -1
- package/build-types/dataviews/stories/layout-custom.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-grid.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-list.d.ts.map +1 -1
- package/build-types/dataviews/stories/layout-table.d.ts.map +1 -1
- package/build-types/dataviews/stories/with-card.d.ts +3 -1
- package/build-types/dataviews/stories/with-card.d.ts.map +1 -1
- package/build-types/types/dataform.d.ts +17 -2
- package/build-types/types/dataform.d.ts.map +1 -1
- package/build-types/types/dataviews.d.ts +8 -0
- package/build-types/types/dataviews.d.ts.map +1 -1
- package/build-wp/index.js +883 -866
- package/package.json +19 -19
- package/src/components/dataform-controls/date.tsx +11 -1
- package/src/components/dataform-controls/datetime.tsx +28 -44
- package/src/components/dataform-controls/utils/relative-date-control.tsx +2 -1
- package/src/components/dataform-layouts/normalize-form.ts +24 -1
- package/src/components/dataform-layouts/panel/index.tsx +1 -1
- package/src/components/dataform-layouts/panel/modal.tsx +7 -3
- package/src/components/dataform-layouts/panel/style.scss +1 -1
- package/src/components/dataform-layouts/test/normalize-form.ts +98 -5
- package/src/components/dataviews-layout/index.tsx +41 -19
- package/src/components/dataviews-layout/style.scss +8 -0
- package/src/components/dataviews-layouts/grid/composite-grid.tsx +7 -1
- package/src/components/dataviews-layouts/grid/style.scss +18 -2
- package/src/components/dataviews-layouts/index.ts +3 -3
- package/src/components/dataviews-layouts/picker-grid/index.tsx +17 -2
- package/src/components/dataviews-layouts/picker-grid/style.scss +10 -0
- package/src/components/dataviews-layouts/table/index.tsx +11 -5
- package/src/components/dataviews-layouts/table/style.scss +13 -0
- package/src/components/dataviews-layouts/table/use-scroll-state.ts +79 -0
- package/src/components/dataviews-layouts/utils/density-picker.tsx +12 -2
- package/src/components/dataviews-layouts/utils/grid-config-options.tsx +14 -0
- package/src/components/dataviews-layouts/utils/grid-items.scss +9 -1
- package/src/dataform/stories/index.story.tsx +15 -0
- package/src/dataform/stories/layout-panel.tsx +19 -4
- package/src/dataviews/index.tsx +17 -9
- package/src/dataviews/stories/empty.tsx +1 -3
- package/src/dataviews/stories/free-composition.tsx +32 -34
- package/src/dataviews/stories/index.story.tsx +31 -8
- package/src/dataviews/stories/infinite-scroll.tsx +0 -6
- package/src/dataviews/stories/layout-activity.tsx +1 -0
- package/src/dataviews/stories/layout-custom.tsx +7 -3
- package/src/dataviews/stories/layout-grid.tsx +1 -0
- package/src/dataviews/stories/layout-list.tsx +1 -0
- package/src/dataviews/stories/layout-table.tsx +1 -0
- package/src/dataviews/stories/style.css +0 -5
- package/src/dataviews/stories/with-card.tsx +6 -2
- package/src/dataviews/style.scss +0 -1
- package/src/dataviews/test/dataviews.tsx +42 -1
- package/src/dataviews-picker/index.tsx +1 -1
- package/src/style.scss +1 -0
- package/src/types/dataform.ts +15 -2
- package/src/types/dataviews.ts +10 -0
- package/build/components/dataviews-layouts/table/use-is-horizontal-scroll-end.cjs.map +0 -7
- package/build-module/components/dataviews-layouts/table/use-is-horizontal-scroll-end.mjs +0 -50
- package/build-module/components/dataviews-layouts/table/use-is-horizontal-scroll-end.mjs.map +0 -7
- package/build-types/components/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts +0 -19
- package/build-types/components/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts.map +0 -1
- package/src/components/dataviews-layouts/table/use-is-horizontal-scroll-end.ts +0 -82
|
@@ -18,7 +18,11 @@ import filterSortAndPaginate from '../../utils/filter-sort-and-paginate';
|
|
|
18
18
|
import type { View } from '../../types';
|
|
19
19
|
import { actions, data, fields } from './fixtures';
|
|
20
20
|
|
|
21
|
-
const WithCardComponent = (
|
|
21
|
+
const WithCardComponent = ( {
|
|
22
|
+
containerHeight,
|
|
23
|
+
}: {
|
|
24
|
+
containerHeight: string;
|
|
25
|
+
} ) => {
|
|
22
26
|
const [ view, setView ] = useState< View >( {
|
|
23
27
|
type: LAYOUT_TABLE,
|
|
24
28
|
search: '',
|
|
@@ -37,7 +41,7 @@ const WithCardComponent = () => {
|
|
|
37
41
|
return (
|
|
38
42
|
<Card>
|
|
39
43
|
<CardHeader>Header</CardHeader>
|
|
40
|
-
<CardBody>
|
|
44
|
+
<CardBody style={ { height: containerHeight, minHeight: 0 } }>
|
|
41
45
|
<DataViews
|
|
42
46
|
getItemId={ ( item ) => item.id.toString() }
|
|
43
47
|
paginationInfo={ paginationInfo }
|
package/src/dataviews/style.scss
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
5
5
|
import userEvent from '@testing-library/user-event';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -240,6 +240,47 @@ describe( 'DataViews component', () => {
|
|
|
240
240
|
expect( screen.getByText( 'TEST TITLE' ) ).toBeInTheDocument();
|
|
241
241
|
} );
|
|
242
242
|
|
|
243
|
+
it( 'should trigger infinite scroll when the layout container scrolls', () => {
|
|
244
|
+
const infiniteScrollHandler = jest.fn();
|
|
245
|
+
const { container } = render(
|
|
246
|
+
<DataViewWrapper
|
|
247
|
+
view={ {
|
|
248
|
+
type: LAYOUT_GRID,
|
|
249
|
+
infiniteScrollEnabled: true,
|
|
250
|
+
perPage: 1,
|
|
251
|
+
} }
|
|
252
|
+
paginationInfo={ {
|
|
253
|
+
totalItems: data.length,
|
|
254
|
+
totalPages: data.length,
|
|
255
|
+
infiniteScrollHandler,
|
|
256
|
+
} }
|
|
257
|
+
/>
|
|
258
|
+
);
|
|
259
|
+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
|
|
260
|
+
const layoutContainer = container.querySelector(
|
|
261
|
+
'.dataviews-layout__container'
|
|
262
|
+
) as HTMLDivElement;
|
|
263
|
+
|
|
264
|
+
Object.defineProperties( layoutContainer, {
|
|
265
|
+
scrollTop: {
|
|
266
|
+
configurable: true,
|
|
267
|
+
value: 500,
|
|
268
|
+
},
|
|
269
|
+
scrollHeight: {
|
|
270
|
+
configurable: true,
|
|
271
|
+
value: 1000,
|
|
272
|
+
},
|
|
273
|
+
clientHeight: {
|
|
274
|
+
configurable: true,
|
|
275
|
+
value: 500,
|
|
276
|
+
},
|
|
277
|
+
} );
|
|
278
|
+
|
|
279
|
+
fireEvent.scroll( layoutContainer );
|
|
280
|
+
|
|
281
|
+
expect( infiniteScrollHandler ).toHaveBeenCalledTimes( 1 );
|
|
282
|
+
} );
|
|
283
|
+
|
|
243
284
|
describe( 'in table view', () => {
|
|
244
285
|
it( 'should display columns for each field', () => {
|
|
245
286
|
render( <DataViewWrapper /> );
|
|
@@ -241,7 +241,7 @@ function DataViewsPicker< Item >( {
|
|
|
241
241
|
hasInfiniteScrollHandler: !! infiniteScrollHandler,
|
|
242
242
|
} }
|
|
243
243
|
>
|
|
244
|
-
<div className="dataviews-picker-wrapper"
|
|
244
|
+
<div className="dataviews-picker-wrapper">
|
|
245
245
|
{ children ?? (
|
|
246
246
|
<DefaultUI search={ search } searchLabel={ searchLabel } />
|
|
247
247
|
) }
|
package/src/style.scss
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
@use "./dataviews/style.scss" as *;
|
|
2
2
|
@use "./components/dataviews-bulk-actions/style.scss" as *;
|
|
3
|
+
@use "./components/dataviews-layout/style.scss" as *;
|
|
3
4
|
@use "./components/dataviews-filters/style.scss" as *;
|
|
4
5
|
@use "./components/dataviews-footer/style.scss" as *;
|
|
5
6
|
@use "./components/dataviews-pagination/style.scss" as *;
|
package/src/types/dataform.ts
CHANGED
|
@@ -23,17 +23,30 @@ export type NormalizedRegularLayout = {
|
|
|
23
23
|
|
|
24
24
|
export type EditVisibility = 'always' | 'on-hover';
|
|
25
25
|
|
|
26
|
+
type PanelOpenAsDropdown = {
|
|
27
|
+
type: 'dropdown';
|
|
28
|
+
};
|
|
29
|
+
export type PanelOpenAsModal = {
|
|
30
|
+
type: 'modal';
|
|
31
|
+
applyLabel: string;
|
|
32
|
+
cancelLabel: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
26
35
|
export type PanelLayout = {
|
|
27
36
|
type: 'panel';
|
|
28
37
|
labelPosition?: LabelPosition;
|
|
29
|
-
openAs?:
|
|
38
|
+
openAs?:
|
|
39
|
+
| 'dropdown'
|
|
40
|
+
| 'modal'
|
|
41
|
+
| { type: 'dropdown' }
|
|
42
|
+
| { type: 'modal'; applyLabel?: string; cancelLabel?: string };
|
|
30
43
|
summary?: PanelSummaryField;
|
|
31
44
|
editVisibility?: EditVisibility;
|
|
32
45
|
};
|
|
33
46
|
export type NormalizedPanelLayout = {
|
|
34
47
|
type: 'panel';
|
|
35
48
|
labelPosition: LabelPosition;
|
|
36
|
-
openAs:
|
|
49
|
+
openAs: PanelOpenAsDropdown | PanelOpenAsModal;
|
|
37
50
|
summary: NormalizedPanelSummaryField;
|
|
38
51
|
editVisibility: EditVisibility;
|
|
39
52
|
};
|
package/src/types/dataviews.ts
CHANGED
|
@@ -285,6 +285,11 @@ export interface ViewGrid extends ViewBase {
|
|
|
285
285
|
* The preview size of the grid.
|
|
286
286
|
*/
|
|
287
287
|
previewSize?: number;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The density of the grid layout.
|
|
291
|
+
*/
|
|
292
|
+
density?: Density;
|
|
288
293
|
};
|
|
289
294
|
}
|
|
290
295
|
|
|
@@ -301,6 +306,11 @@ export interface ViewPickerGrid extends ViewBase {
|
|
|
301
306
|
* The preview size of the grid.
|
|
302
307
|
*/
|
|
303
308
|
previewSize?: number;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The density of the grid layout.
|
|
312
|
+
*/
|
|
313
|
+
density?: Density;
|
|
304
314
|
};
|
|
305
315
|
}
|
|
306
316
|
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/components/dataviews-layouts/table/use-is-horizontal-scroll-end.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { MutableRefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce } from '@wordpress/compose';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { isRTL } from '@wordpress/i18n';\n\nconst isScrolledToEnd = ( element: Element ) => {\n\tif ( isRTL() ) {\n\t\tconst scrollLeft = Math.abs( element.scrollLeft );\n\t\treturn scrollLeft <= 1;\n\t}\n\n\treturn element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;\n};\n\n/**\n * A hook to check if a given scroll container has reached the horizontal scroll end.\n *\n * The current way receives \"refs\" as arguments, but it lacks a mechanism to detect when a ref has changed.\n * As a result, when the \"ref\" is updated and attached to a new div, the computation should trigger again.\n * However, this isn't possible in the current setup because the hook is unaware that the ref has changed.\n *\n * See https://github.com/Automattic/wp-calypso/pull/103005#discussion_r2077567912.\n *\n * @param {Object} params The parameters for the hook.\n * @param {MutableRefObject<HTMLDivElement | null>} params.scrollContainerRef The ref to the scroll container element.\n * @param {boolean} [params.enabled=false] Whether the hook is enabled.\n * @return {boolean} - Returns true if the scroll container is scrolled to the end or false otherwise.\n */\nexport function useIsHorizontalScrollEnd( {\n\tscrollContainerRef,\n\tenabled = false,\n}: {\n\tscrollContainerRef: React.MutableRefObject< HTMLDivElement | null >;\n\tenabled?: boolean;\n} ): boolean {\n\tconst [ isHorizontalScrollEnd, setIsHorizontalScrollEnd ] =\n\t\tuseState( false );\n\n\tconst handleIsHorizontalScrollEnd = useDebounce(\n\t\tuseCallback( () => {\n\t\t\tconst scrollContainer = scrollContainerRef.current;\n\t\t\tif ( scrollContainer ) {\n\t\t\t\tsetIsHorizontalScrollEnd( isScrolledToEnd( scrollContainer ) );\n\t\t\t}\n\t\t}, [ scrollContainerRef, setIsHorizontalScrollEnd ] ),\n\t\t200\n\t);\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\ttypeof window === 'undefined' ||\n\t\t\t! enabled ||\n\t\t\t! scrollContainerRef.current\n\t\t) {\n\t\t\treturn () => {};\n\t\t}\n\n\t\thandleIsHorizontalScrollEnd();\n\t\tscrollContainerRef.current.addEventListener(\n\t\t\t'scroll',\n\t\t\thandleIsHorizontalScrollEnd\n\t\t);\n\t\twindow.addEventListener( 'resize', handleIsHorizontalScrollEnd );\n\n\t\treturn () => {\n\t\t\tscrollContainerRef.current?.removeEventListener(\n\t\t\t\t'scroll',\n\t\t\t\thandleIsHorizontalScrollEnd\n\t\t\t);\n\t\t\twindow.removeEventListener( 'resize', handleIsHorizontalScrollEnd );\n\t\t};\n\t}, [ scrollContainerRef, enabled ] );\n\n\treturn isHorizontalScrollEnd;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA4B;AAC5B,qBAAiD;AACjD,kBAAsB;AAEtB,IAAM,kBAAkB,CAAE,YAAsB;AAC/C,UAAK,mBAAM,GAAI;AACd,UAAM,aAAa,KAAK,IAAK,QAAQ,UAAW;AAChD,WAAO,cAAc;AAAA,EACtB;AAEA,SAAO,QAAQ,aAAa,QAAQ,eAAe,QAAQ,cAAc;AAC1E;AAgBO,SAAS,yBAA0B;AAAA,EACzC;AAAA,EACA,UAAU;AACX,GAGa;AACZ,QAAM,CAAE,uBAAuB,wBAAyB,QACvD,yBAAU,KAAM;AAEjB,QAAM,kCAA8B;AAAA,QACnC,4BAAa,MAAM;AAClB,YAAM,kBAAkB,mBAAmB;AAC3C,UAAK,iBAAkB;AACtB,iCAA0B,gBAAiB,eAAgB,CAAE;AAAA,MAC9D;AAAA,IACD,GAAG,CAAE,oBAAoB,wBAAyB,CAAE;AAAA,IACpD;AAAA,EACD;AAEA,gCAAW,MAAM;AAChB,QACC,OAAO,WAAW,eAClB,CAAE,WACF,CAAE,mBAAmB,SACpB;AACD,aAAO,MAAM;AAAA,MAAC;AAAA,IACf;AAEA,gCAA4B;AAC5B,uBAAmB,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,IACD;AACA,WAAO,iBAAkB,UAAU,2BAA4B;AAE/D,WAAO,MAAM;AACZ,yBAAmB,SAAS;AAAA,QAC3B;AAAA,QACA;AAAA,MACD;AACA,aAAO,oBAAqB,UAAU,2BAA4B;AAAA,IACnE;AAAA,EACD,GAAG,CAAE,oBAAoB,OAAQ,CAAE;AAEnC,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// packages/dataviews/src/components/dataviews-layouts/table/use-is-horizontal-scroll-end.ts
|
|
2
|
-
import { useDebounce } from "@wordpress/compose";
|
|
3
|
-
import { useCallback, useEffect, useState } from "@wordpress/element";
|
|
4
|
-
import { isRTL } from "@wordpress/i18n";
|
|
5
|
-
var isScrolledToEnd = (element) => {
|
|
6
|
-
if (isRTL()) {
|
|
7
|
-
const scrollLeft = Math.abs(element.scrollLeft);
|
|
8
|
-
return scrollLeft <= 1;
|
|
9
|
-
}
|
|
10
|
-
return element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
|
|
11
|
-
};
|
|
12
|
-
function useIsHorizontalScrollEnd({
|
|
13
|
-
scrollContainerRef,
|
|
14
|
-
enabled = false
|
|
15
|
-
}) {
|
|
16
|
-
const [isHorizontalScrollEnd, setIsHorizontalScrollEnd] = useState(false);
|
|
17
|
-
const handleIsHorizontalScrollEnd = useDebounce(
|
|
18
|
-
useCallback(() => {
|
|
19
|
-
const scrollContainer = scrollContainerRef.current;
|
|
20
|
-
if (scrollContainer) {
|
|
21
|
-
setIsHorizontalScrollEnd(isScrolledToEnd(scrollContainer));
|
|
22
|
-
}
|
|
23
|
-
}, [scrollContainerRef, setIsHorizontalScrollEnd]),
|
|
24
|
-
200
|
|
25
|
-
);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (typeof window === "undefined" || !enabled || !scrollContainerRef.current) {
|
|
28
|
-
return () => {
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
handleIsHorizontalScrollEnd();
|
|
32
|
-
scrollContainerRef.current.addEventListener(
|
|
33
|
-
"scroll",
|
|
34
|
-
handleIsHorizontalScrollEnd
|
|
35
|
-
);
|
|
36
|
-
window.addEventListener("resize", handleIsHorizontalScrollEnd);
|
|
37
|
-
return () => {
|
|
38
|
-
scrollContainerRef.current?.removeEventListener(
|
|
39
|
-
"scroll",
|
|
40
|
-
handleIsHorizontalScrollEnd
|
|
41
|
-
);
|
|
42
|
-
window.removeEventListener("resize", handleIsHorizontalScrollEnd);
|
|
43
|
-
};
|
|
44
|
-
}, [scrollContainerRef, enabled]);
|
|
45
|
-
return isHorizontalScrollEnd;
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
useIsHorizontalScrollEnd
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=use-is-horizontal-scroll-end.mjs.map
|
package/build-module/components/dataviews-layouts/table/use-is-horizontal-scroll-end.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/components/dataviews-layouts/table/use-is-horizontal-scroll-end.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { MutableRefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce } from '@wordpress/compose';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { isRTL } from '@wordpress/i18n';\n\nconst isScrolledToEnd = ( element: Element ) => {\n\tif ( isRTL() ) {\n\t\tconst scrollLeft = Math.abs( element.scrollLeft );\n\t\treturn scrollLeft <= 1;\n\t}\n\n\treturn element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;\n};\n\n/**\n * A hook to check if a given scroll container has reached the horizontal scroll end.\n *\n * The current way receives \"refs\" as arguments, but it lacks a mechanism to detect when a ref has changed.\n * As a result, when the \"ref\" is updated and attached to a new div, the computation should trigger again.\n * However, this isn't possible in the current setup because the hook is unaware that the ref has changed.\n *\n * See https://github.com/Automattic/wp-calypso/pull/103005#discussion_r2077567912.\n *\n * @param {Object} params The parameters for the hook.\n * @param {MutableRefObject<HTMLDivElement | null>} params.scrollContainerRef The ref to the scroll container element.\n * @param {boolean} [params.enabled=false] Whether the hook is enabled.\n * @return {boolean} - Returns true if the scroll container is scrolled to the end or false otherwise.\n */\nexport function useIsHorizontalScrollEnd( {\n\tscrollContainerRef,\n\tenabled = false,\n}: {\n\tscrollContainerRef: React.MutableRefObject< HTMLDivElement | null >;\n\tenabled?: boolean;\n} ): boolean {\n\tconst [ isHorizontalScrollEnd, setIsHorizontalScrollEnd ] =\n\t\tuseState( false );\n\n\tconst handleIsHorizontalScrollEnd = useDebounce(\n\t\tuseCallback( () => {\n\t\t\tconst scrollContainer = scrollContainerRef.current;\n\t\t\tif ( scrollContainer ) {\n\t\t\t\tsetIsHorizontalScrollEnd( isScrolledToEnd( scrollContainer ) );\n\t\t\t}\n\t\t}, [ scrollContainerRef, setIsHorizontalScrollEnd ] ),\n\t\t200\n\t);\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\ttypeof window === 'undefined' ||\n\t\t\t! enabled ||\n\t\t\t! scrollContainerRef.current\n\t\t) {\n\t\t\treturn () => {};\n\t\t}\n\n\t\thandleIsHorizontalScrollEnd();\n\t\tscrollContainerRef.current.addEventListener(\n\t\t\t'scroll',\n\t\t\thandleIsHorizontalScrollEnd\n\t\t);\n\t\twindow.addEventListener( 'resize', handleIsHorizontalScrollEnd );\n\n\t\treturn () => {\n\t\t\tscrollContainerRef.current?.removeEventListener(\n\t\t\t\t'scroll',\n\t\t\t\thandleIsHorizontalScrollEnd\n\t\t\t);\n\t\t\twindow.removeEventListener( 'resize', handleIsHorizontalScrollEnd );\n\t\t};\n\t}, [ scrollContainerRef, enabled ] );\n\n\treturn isHorizontalScrollEnd;\n}\n"],
|
|
5
|
-
"mappings": ";AAQA,SAAS,mBAAmB;AAC5B,SAAS,aAAa,WAAW,gBAAgB;AACjD,SAAS,aAAa;AAEtB,IAAM,kBAAkB,CAAE,YAAsB;AAC/C,MAAK,MAAM,GAAI;AACd,UAAM,aAAa,KAAK,IAAK,QAAQ,UAAW;AAChD,WAAO,cAAc;AAAA,EACtB;AAEA,SAAO,QAAQ,aAAa,QAAQ,eAAe,QAAQ,cAAc;AAC1E;AAgBO,SAAS,yBAA0B;AAAA,EACzC;AAAA,EACA,UAAU;AACX,GAGa;AACZ,QAAM,CAAE,uBAAuB,wBAAyB,IACvD,SAAU,KAAM;AAEjB,QAAM,8BAA8B;AAAA,IACnC,YAAa,MAAM;AAClB,YAAM,kBAAkB,mBAAmB;AAC3C,UAAK,iBAAkB;AACtB,iCAA0B,gBAAiB,eAAgB,CAAE;AAAA,MAC9D;AAAA,IACD,GAAG,CAAE,oBAAoB,wBAAyB,CAAE;AAAA,IACpD;AAAA,EACD;AAEA,YAAW,MAAM;AAChB,QACC,OAAO,WAAW,eAClB,CAAE,WACF,CAAE,mBAAmB,SACpB;AACD,aAAO,MAAM;AAAA,MAAC;AAAA,IACf;AAEA,gCAA4B;AAC5B,uBAAmB,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,IACD;AACA,WAAO,iBAAkB,UAAU,2BAA4B;AAE/D,WAAO,MAAM;AACZ,yBAAmB,SAAS;AAAA,QAC3B;AAAA,QACA;AAAA,MACD;AACA,aAAO,oBAAqB,UAAU,2BAA4B;AAAA,IACnE;AAAA,EACD,GAAG,CAAE,oBAAoB,OAAQ,CAAE;AAEnC,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A hook to check if a given scroll container has reached the horizontal scroll end.
|
|
3
|
-
*
|
|
4
|
-
* The current way receives "refs" as arguments, but it lacks a mechanism to detect when a ref has changed.
|
|
5
|
-
* As a result, when the "ref" is updated and attached to a new div, the computation should trigger again.
|
|
6
|
-
* However, this isn't possible in the current setup because the hook is unaware that the ref has changed.
|
|
7
|
-
*
|
|
8
|
-
* See https://github.com/Automattic/wp-calypso/pull/103005#discussion_r2077567912.
|
|
9
|
-
*
|
|
10
|
-
* @param {Object} params The parameters for the hook.
|
|
11
|
-
* @param {MutableRefObject<HTMLDivElement | null>} params.scrollContainerRef The ref to the scroll container element.
|
|
12
|
-
* @param {boolean} [params.enabled=false] Whether the hook is enabled.
|
|
13
|
-
* @return {boolean} - Returns true if the scroll container is scrolled to the end or false otherwise.
|
|
14
|
-
*/
|
|
15
|
-
export declare function useIsHorizontalScrollEnd({ scrollContainerRef, enabled, }: {
|
|
16
|
-
scrollContainerRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
17
|
-
enabled?: boolean;
|
|
18
|
-
}): boolean;
|
|
19
|
-
//# sourceMappingURL=use-is-horizontal-scroll-end.d.ts.map
|
package/build-types/components/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-horizontal-scroll-end.d.ts","sourceRoot":"","sources":["../../../../src/components/dataviews-layouts/table/use-is-horizontal-scroll-end.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAE,EACzC,kBAAkB,EAClB,OAAe,GACf,EAAE;IACF,kBAAkB,EAAE,KAAK,CAAC,gBAAgB,CAAE,cAAc,GAAG,IAAI,CAAE,CAAC;IACpE,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,GAAI,OAAO,CAwCX"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { MutableRefObject } from 'react';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { useDebounce } from '@wordpress/compose';
|
|
10
|
-
import { useCallback, useEffect, useState } from '@wordpress/element';
|
|
11
|
-
import { isRTL } from '@wordpress/i18n';
|
|
12
|
-
|
|
13
|
-
const isScrolledToEnd = ( element: Element ) => {
|
|
14
|
-
if ( isRTL() ) {
|
|
15
|
-
const scrollLeft = Math.abs( element.scrollLeft );
|
|
16
|
-
return scrollLeft <= 1;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A hook to check if a given scroll container has reached the horizontal scroll end.
|
|
24
|
-
*
|
|
25
|
-
* The current way receives "refs" as arguments, but it lacks a mechanism to detect when a ref has changed.
|
|
26
|
-
* As a result, when the "ref" is updated and attached to a new div, the computation should trigger again.
|
|
27
|
-
* However, this isn't possible in the current setup because the hook is unaware that the ref has changed.
|
|
28
|
-
*
|
|
29
|
-
* See https://github.com/Automattic/wp-calypso/pull/103005#discussion_r2077567912.
|
|
30
|
-
*
|
|
31
|
-
* @param {Object} params The parameters for the hook.
|
|
32
|
-
* @param {MutableRefObject<HTMLDivElement | null>} params.scrollContainerRef The ref to the scroll container element.
|
|
33
|
-
* @param {boolean} [params.enabled=false] Whether the hook is enabled.
|
|
34
|
-
* @return {boolean} - Returns true if the scroll container is scrolled to the end or false otherwise.
|
|
35
|
-
*/
|
|
36
|
-
export function useIsHorizontalScrollEnd( {
|
|
37
|
-
scrollContainerRef,
|
|
38
|
-
enabled = false,
|
|
39
|
-
}: {
|
|
40
|
-
scrollContainerRef: React.MutableRefObject< HTMLDivElement | null >;
|
|
41
|
-
enabled?: boolean;
|
|
42
|
-
} ): boolean {
|
|
43
|
-
const [ isHorizontalScrollEnd, setIsHorizontalScrollEnd ] =
|
|
44
|
-
useState( false );
|
|
45
|
-
|
|
46
|
-
const handleIsHorizontalScrollEnd = useDebounce(
|
|
47
|
-
useCallback( () => {
|
|
48
|
-
const scrollContainer = scrollContainerRef.current;
|
|
49
|
-
if ( scrollContainer ) {
|
|
50
|
-
setIsHorizontalScrollEnd( isScrolledToEnd( scrollContainer ) );
|
|
51
|
-
}
|
|
52
|
-
}, [ scrollContainerRef, setIsHorizontalScrollEnd ] ),
|
|
53
|
-
200
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
useEffect( () => {
|
|
57
|
-
if (
|
|
58
|
-
typeof window === 'undefined' ||
|
|
59
|
-
! enabled ||
|
|
60
|
-
! scrollContainerRef.current
|
|
61
|
-
) {
|
|
62
|
-
return () => {};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
handleIsHorizontalScrollEnd();
|
|
66
|
-
scrollContainerRef.current.addEventListener(
|
|
67
|
-
'scroll',
|
|
68
|
-
handleIsHorizontalScrollEnd
|
|
69
|
-
);
|
|
70
|
-
window.addEventListener( 'resize', handleIsHorizontalScrollEnd );
|
|
71
|
-
|
|
72
|
-
return () => {
|
|
73
|
-
scrollContainerRef.current?.removeEventListener(
|
|
74
|
-
'scroll',
|
|
75
|
-
handleIsHorizontalScrollEnd
|
|
76
|
-
);
|
|
77
|
-
window.removeEventListener( 'resize', handleIsHorizontalScrollEnd );
|
|
78
|
-
};
|
|
79
|
-
}, [ scrollContainerRef, enabled ] );
|
|
80
|
-
|
|
81
|
-
return isHorizontalScrollEnd;
|
|
82
|
-
}
|