@pega/lists-react 8.34.7 → 8.34.9
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/lib/Core/Components/DefaultComponents/RowHeight.d.ts.map +1 -1
- package/lib/Core/Components/DefaultComponents/RowHeight.js +5 -2
- package/lib/Core/Components/DefaultComponents/RowHeight.js.map +1 -1
- package/lib/Core/Components/Toolbar/ColumnSelector.d.ts.map +1 -1
- package/lib/Core/Components/Toolbar/ColumnSelector.js +4 -2
- package/lib/Core/Components/Toolbar/ColumnSelector.js.map +1 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.d.ts.map +1 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.js +2 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.js.map +1 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.d.ts +2 -2
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.d.ts.map +1 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.js +22 -5
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.js.map +1 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/utils.d.ts +2 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/utils.d.ts.map +1 -1
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/utils.js +7 -3
- package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/utils.js.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowHeight.d.ts","sourceRoot":"","sources":["../../../../Core/Components/DefaultComponents/RowHeight.jsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RowHeight.d.ts","sourceRoot":"","sources":["../../../../Core/Components/DefaultComponents/RowHeight.jsx"],"names":[],"mappings":"AAQA;;;4CAoBC;;;;;;;;;;sBA5BqB,YAAY"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
import { Menu, useFocusTrap } from '@pega/cosmos-react-core';
|
|
4
5
|
import { ROW_DENSITY } from 'pega-repeating-structures-core/lib/types/Meta.types';
|
|
5
6
|
import useTranslate from '../../Hooks/useTranslate';
|
|
6
7
|
export default function RowHeight({ view, onClose }) {
|
|
7
8
|
const [translate] = useTranslate();
|
|
9
|
+
const menuRef = useRef(null);
|
|
8
10
|
const actions = [
|
|
9
11
|
view.meta.displayDensity
|
|
10
12
|
.filter(option => option.id !== ROW_DENSITY.WRAP_CONTENT)
|
|
@@ -18,7 +20,8 @@ export default function RowHeight({ view, onClose }) {
|
|
|
18
20
|
}
|
|
19
21
|
}))
|
|
20
22
|
];
|
|
21
|
-
|
|
23
|
+
useFocusTrap(menuRef, false);
|
|
24
|
+
return _jsx(Menu, { items: actions.flat(), mode: 'single-select', ref: menuRef });
|
|
22
25
|
}
|
|
23
26
|
RowHeight.propTypes = {
|
|
24
27
|
view: PropTypes.objectOf(PropTypes.any).isRequired,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowHeight.js","sourceRoot":"","sources":["../../../../Core/Components/DefaultComponents/RowHeight.jsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"RowHeight.js","sourceRoot":"","sources":["../../../../Core/Components/DefaultComponents/RowHeight.jsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC7D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{ ROW_DENSITY } from 'pega-repeating-structures-core/lib/types/Meta.types';\n\nimport useTranslate from '../../Hooks/useTranslate';\n\nexport default function RowHeight({ view, onClose }) {\n const [translate] = useTranslate();\n const menuRef = useRef(null);\n const actions = [\n view.meta.displayDensity\n .filter(option => option.id !== ROW_DENSITY.WRAP_CONTENT)\n .map(option => ({\n primary: translate(option.name),\n selected: view.state.selectedHeightOption === option.id,\n id: option.id,\n onClick: () => {\n view.type.applyRowHeight(option.id);\n onClose();\n }\n }))\n ];\n\n useFocusTrap(menuRef, false);\n\n return <Menu items={actions.flat()} mode='single-select' ref={menuRef} />;\n}\n\nRowHeight.propTypes = {\n view: PropTypes.objectOf(PropTypes.any).isRequired,\n onClose: PropTypes.func\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnSelector.d.ts","sourceRoot":"","sources":["../../../../Core/Components/Toolbar/ColumnSelector.jsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ColumnSelector.d.ts","sourceRoot":"","sources":["../../../../Core/Components/Toolbar/ColumnSelector.jsx"],"names":[],"mappings":"AAkBA,uFAGC;AACD;;;;GAIG;AACH,kEA4DC;AAED,2FAkEC;;;;;;;;AA5ID,6BAA8B,mBAAmB,CAAC;AAClD,sBAAuB,gBAAgB,CAAC;;;sBAflB,YAAY;AAkKlC;;;;4CAwBC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { memo, useCallback, useEffect, useRef, useState, useMemo } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { Icon, SearchInput, Menu, menuHelpers, useElement } from '@pega/cosmos-react-core';
|
|
4
|
+
import { Icon, SearchInput, Menu, menuHelpers, useElement, useFocusTrap } from '@pega/cosmos-react-core';
|
|
5
5
|
import useSelect from '../../Hooks/useSelect';
|
|
6
6
|
import { allowToggle, getFieldIcon } from '../../Utils';
|
|
7
7
|
export const colsVisibility = 'Show/hide columns';
|
|
@@ -90,6 +90,7 @@ export function ColumnSelectorControl(props) {
|
|
|
90
90
|
const [searchQuery, onSearch] = useState('');
|
|
91
91
|
const [searchEl, setSearchEl] = useElement(null);
|
|
92
92
|
const hasMountedRef = useRef(false);
|
|
93
|
+
const menuRef = useRef(null);
|
|
93
94
|
const onSearchTriggered = useCallback(searchString => {
|
|
94
95
|
onSearch(searchString);
|
|
95
96
|
}, [onSearch]);
|
|
@@ -109,10 +110,11 @@ export function ColumnSelectorControl(props) {
|
|
|
109
110
|
}
|
|
110
111
|
hasMountedRef.current = true;
|
|
111
112
|
}, [visibleColumns]);
|
|
113
|
+
useFocusTrap(menuRef, false);
|
|
112
114
|
const itemsToRender = searchQuery
|
|
113
115
|
? flatData.filter(item => item.label.toLowerCase().includes(searchQuery.toLowerCase()))
|
|
114
116
|
: data;
|
|
115
|
-
return (_jsx(Menu, { items: itemsToRender, mode: 'multi-select', onItemClick: onChange, role: 'listbox', focusControlEl: searchEl || undefined, header: _jsx(SearchInput, { value: searchQuery, onSearchChange: onSearchTriggered, ref: setSearchEl }) }));
|
|
117
|
+
return (_jsx(Menu, { items: itemsToRender, mode: 'multi-select', onItemClick: onChange, role: 'listbox', focusControlEl: searchEl || undefined, ref: menuRef, header: _jsx(SearchInput, { value: searchQuery, onSearchChange: onSearchTriggered, ref: setSearchEl }) }));
|
|
116
118
|
}
|
|
117
119
|
ColumnSelectorControl.propTypes = {
|
|
118
120
|
data: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnSelector.js","sourceRoot":"","sources":["../../../../Core/Components/Toolbar/ColumnSelector.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,SAAS,MAAM,YAAY,CAAC;AAE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Ac,CAAC,SAAS,GAAG;IACzB,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACnC,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,UAAU;IACvD,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;CACpC,CAAC;AAEF,eAAe,IAAI,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { memo, useCallback, useEffect, useRef, useState, useMemo } from 'react';\nimport PropTypes from 'prop-types';\n\nimport { Icon, SearchInput, Menu, menuHelpers, useElement } from '@pega/cosmos-react-core';\n\nimport useSelect from '../../Hooks/useSelect';\nimport { allowToggle, getFieldIcon } from '../../Utils';\n\nexport const colsVisibility = 'Show/hide columns';\nexport const pinning = 'Freeze columns';\n\nexport function getIconByFieldType(type) {\n const iconName = getFieldIcon(type);\n return <Icon data-test-id={iconName} data-testid={iconName} name={iconName} />;\n}\n/**\n * Transforms the columns array into array of columns grouped by category\n * @param {Array} columns : ;\n * @returns Arrays of columns nested by category\n */\nexport function transformData(columns, action) {\n const result = [];\n if (!columns?.length) return result;\n\n const categoryObj = {};\n const allowColumnToggle = allowToggle(columns[0].parent.getVisibleColumns());\n\n columns\n ?.filter(c => c.field.toggle)\n .forEach(column => {\n const {\n field: { id, category = [], type },\n label,\n hidden,\n frozen\n } = column;\n const lastCategoryLabel = category.length ? category[category.length - 1].label : undefined;\n let selectAction;\n let disabled;\n if (action === colsVisibility) {\n selectAction = !hidden;\n disabled = !allowColumnToggle && !hidden;\n } else if (action === pinning) selectAction = frozen;\n if (categoryObj[lastCategoryLabel])\n categoryObj[lastCategoryLabel].items.push({\n id,\n primary: label,\n label,\n selected: selectAction,\n type,\n disabled\n });\n else {\n categoryObj[lastCategoryLabel] = {\n id: `category:${lastCategoryLabel}`,\n label: lastCategoryLabel,\n items: [\n {\n id,\n primary: label,\n selected: selectAction,\n label,\n type,\n disabled\n }\n ]\n };\n }\n });\n // Items with no category attribute are set in the root of returned array\n if (categoryObj[undefined] && categoryObj[undefined].items) {\n result.push(...categoryObj[undefined].items);\n delete categoryObj[undefined];\n }\n const keys = Object.keys(categoryObj);\n // Items with category attribute are grouped inside the nested category object\n keys.forEach(key => {\n result.push(categoryObj[key]);\n });\n return result;\n}\n\nexport function ColumnSelectorControl(props) {\n const { data, onSelect, forceShowPopup } = props;\n const flatData = menuHelpers.flatten(data);\n\n data.forEach(d => {\n if (d.items)\n d.items.forEach(item => {\n item.visual = getIconByFieldType(item.type);\n });\n else {\n d.visual = getIconByFieldType(d.type);\n }\n });\n\n const selectedData = flatData.filter(o => o.selected).map(obj => obj.id);\n const [visibleColumns, onChecked] = useSelect(selectedData);\n const onChange = useCallback(id => onChecked(id), [onChecked]);\n const [searchQuery, onSearch] = useState('');\n const [searchEl, setSearchEl] = useElement(null);\n\n const hasMountedRef = useRef(false);\n\n const onSearchTriggered = useCallback(\n searchString => {\n onSearch(searchString);\n },\n [onSearch]\n );\n\n useEffect(() => {\n if (forceShowPopup && searchEl) searchEl.focus();\n }, [forceShowPopup, searchEl]);\n\n useEffect(() => {\n if (hasMountedRef.current) {\n const previousVisibleColumns = flatData.filter(o => o.selected).map(o => o.id);\n const currentVisibleColumns = [...visibleColumns];\n const toggledColumns = [\n ...currentVisibleColumns.filter(id => !previousVisibleColumns.includes(id)),\n ...previousVisibleColumns.filter(id => !visibleColumns.has(id))\n ];\n onSelect(toggledColumns);\n }\n hasMountedRef.current = true;\n }, [visibleColumns]);\n\n const itemsToRender = searchQuery\n ? flatData.filter(item => item.label.toLowerCase().includes(searchQuery.toLowerCase()))\n : data;\n\n return (\n <Menu\n items={itemsToRender}\n mode='multi-select'\n onItemClick={onChange}\n role='listbox'\n focusControlEl={searchEl || undefined}\n header={\n <SearchInput value={searchQuery} onSearchChange={onSearchTriggered} ref={setSearchEl} />\n }\n />\n );\n}\n\nColumnSelectorControl.propTypes = {\n data: PropTypes.arrayOf(PropTypes.object).isRequired,\n onSelect: PropTypes.func.isRequired,\n forceShowPopup: PropTypes.bool.isRequired\n};\n\nfunction ColumnSelector({ dispatch, columns, action }) {\n const data = useMemo(() => transformData(columns, action), [columns, action]);\n const [forceShowPopup, setForceShowPopup] = useState(true);\n const onSelectHandler = useCallback(\n cols => {\n if (columns.length > 100) {\n setForceShowPopup(false);\n }\n if (cols.length > 0) dispatch(cols);\n },\n [dispatch, columns.length]\n );\n\n return (\n <>\n {forceShowPopup && (\n <ColumnSelectorControl\n data={data}\n onSelect={onSelectHandler}\n forceShowPopup={forceShowPopup}\n />\n )}\n </>\n );\n}\n\nColumnSelector.propTypes = {\n dispatch: PropTypes.func.isRequired,\n columns: PropTypes.arrayOf(PropTypes.object).isRequired,\n action: PropTypes.string.isRequired\n};\n\nexport default memo(ColumnSelector);\n"]}
|
|
1
|
+
{"version":3,"file":"ColumnSelector.js","sourceRoot":"","sources":["../../../../Core/Components/Toolbar/ColumnSelector.jsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EACL,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,WAAW,EACX,UAAU,EACV,YAAY,EACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,SAAS,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAClD,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,MAAM,UAAU,kBAAkB,CAAC,IAAI;IACrC,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,KAAC,IAAI,oBAAe,QAAQ,iBAAe,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAI,CAAC;AACjF,CAAC;AACD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CAAC,IAAI,CAAC,UAAU;IACnC,cAAc,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;CAC1C,CAAC;AAEF,SAAS,cAAc,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE;IACnD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9E,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC3D,MAAM,eAAe,GAAG,WAAW,CACjC,IAAI,CAAC,EAAE;QACL,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACzB,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAC3B,CAAC;IAEF,OAAO,CACL,4BACG,cAAc,IAAI,CACjB,KAAC,qBAAqB,IACpB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,eAAe,EACzB,cAAc,EAAE,cAAc,GAC9B,CACH,GACA,CACJ,CAAC;AACJ,CAAC;AAED,cAAc,CAAC,SAAS,GAAG;IACzB,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACnC,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,UAAU;IACvD,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;CACpC,CAAC;AAEF,eAAe,IAAI,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { memo, useCallback, useEffect, useRef, useState, useMemo } from 'react';\nimport PropTypes from 'prop-types';\n\nimport {\n Icon,\n SearchInput,\n Menu,\n menuHelpers,\n useElement,\n useFocusTrap\n} from '@pega/cosmos-react-core';\n\nimport useSelect from '../../Hooks/useSelect';\nimport { allowToggle, getFieldIcon } from '../../Utils';\n\nexport const colsVisibility = 'Show/hide columns';\nexport const pinning = 'Freeze columns';\n\nexport function getIconByFieldType(type) {\n const iconName = getFieldIcon(type);\n return <Icon data-test-id={iconName} data-testid={iconName} name={iconName} />;\n}\n/**\n * Transforms the columns array into array of columns grouped by category\n * @param {Array} columns : ;\n * @returns Arrays of columns nested by category\n */\nexport function transformData(columns, action) {\n const result = [];\n if (!columns?.length) return result;\n\n const categoryObj = {};\n const allowColumnToggle = allowToggle(columns[0].parent.getVisibleColumns());\n\n columns\n ?.filter(c => c.field.toggle)\n .forEach(column => {\n const {\n field: { id, category = [], type },\n label,\n hidden,\n frozen\n } = column;\n const lastCategoryLabel = category.length ? category[category.length - 1].label : undefined;\n let selectAction;\n let disabled;\n if (action === colsVisibility) {\n selectAction = !hidden;\n disabled = !allowColumnToggle && !hidden;\n } else if (action === pinning) selectAction = frozen;\n if (categoryObj[lastCategoryLabel])\n categoryObj[lastCategoryLabel].items.push({\n id,\n primary: label,\n label,\n selected: selectAction,\n type,\n disabled\n });\n else {\n categoryObj[lastCategoryLabel] = {\n id: `category:${lastCategoryLabel}`,\n label: lastCategoryLabel,\n items: [\n {\n id,\n primary: label,\n selected: selectAction,\n label,\n type,\n disabled\n }\n ]\n };\n }\n });\n // Items with no category attribute are set in the root of returned array\n if (categoryObj[undefined] && categoryObj[undefined].items) {\n result.push(...categoryObj[undefined].items);\n delete categoryObj[undefined];\n }\n const keys = Object.keys(categoryObj);\n // Items with category attribute are grouped inside the nested category object\n keys.forEach(key => {\n result.push(categoryObj[key]);\n });\n return result;\n}\n\nexport function ColumnSelectorControl(props) {\n const { data, onSelect, forceShowPopup } = props;\n const flatData = menuHelpers.flatten(data);\n\n data.forEach(d => {\n if (d.items)\n d.items.forEach(item => {\n item.visual = getIconByFieldType(item.type);\n });\n else {\n d.visual = getIconByFieldType(d.type);\n }\n });\n\n const selectedData = flatData.filter(o => o.selected).map(obj => obj.id);\n const [visibleColumns, onChecked] = useSelect(selectedData);\n const onChange = useCallback(id => onChecked(id), [onChecked]);\n const [searchQuery, onSearch] = useState('');\n const [searchEl, setSearchEl] = useElement(null);\n\n const hasMountedRef = useRef(false);\n const menuRef = useRef(null);\n\n const onSearchTriggered = useCallback(\n searchString => {\n onSearch(searchString);\n },\n [onSearch]\n );\n\n useEffect(() => {\n if (forceShowPopup && searchEl) searchEl.focus();\n }, [forceShowPopup, searchEl]);\n\n useEffect(() => {\n if (hasMountedRef.current) {\n const previousVisibleColumns = flatData.filter(o => o.selected).map(o => o.id);\n const currentVisibleColumns = [...visibleColumns];\n const toggledColumns = [\n ...currentVisibleColumns.filter(id => !previousVisibleColumns.includes(id)),\n ...previousVisibleColumns.filter(id => !visibleColumns.has(id))\n ];\n onSelect(toggledColumns);\n }\n hasMountedRef.current = true;\n }, [visibleColumns]);\n\n useFocusTrap(menuRef, false);\n\n const itemsToRender = searchQuery\n ? flatData.filter(item => item.label.toLowerCase().includes(searchQuery.toLowerCase()))\n : data;\n\n return (\n <Menu\n items={itemsToRender}\n mode='multi-select'\n onItemClick={onChange}\n role='listbox'\n focusControlEl={searchEl || undefined}\n ref={menuRef}\n header={\n <SearchInput value={searchQuery} onSearchChange={onSearchTriggered} ref={setSearchEl} />\n }\n />\n );\n}\n\nColumnSelectorControl.propTypes = {\n data: PropTypes.arrayOf(PropTypes.object).isRequired,\n onSelect: PropTypes.func.isRequired,\n forceShowPopup: PropTypes.bool.isRequired\n};\n\nfunction ColumnSelector({ dispatch, columns, action }) {\n const data = useMemo(() => transformData(columns, action), [columns, action]);\n const [forceShowPopup, setForceShowPopup] = useState(true);\n const onSelectHandler = useCallback(\n cols => {\n if (columns.length > 100) {\n setForceShowPopup(false);\n }\n if (cols.length > 0) dispatch(cols);\n },\n [dispatch, columns.length]\n );\n\n return (\n <>\n {forceShowPopup && (\n <ColumnSelectorControl\n data={data}\n onSelect={onSelectHandler}\n forceShowPopup={forceShowPopup}\n />\n )}\n </>\n );\n}\n\nColumnSelector.propTypes = {\n dispatch: PropTypes.func.isRequired,\n columns: PropTypes.arrayOf(PropTypes.object).isRequired,\n action: PropTypes.string.isRequired\n};\n\nexport default memo(ColumnSelector);\n"]}
|
package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableHeightVirtualizer.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,OAAO,CAAC;AAsBrD,MAAM,WAAW,WAAW;IAC1B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AASD,MAAM,WAAW,8BAA8B;IAC7C,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,oEAAoE;IACpE,QAAQ,EAAE,SAAS,CAAC;IACpB,wCAAwC;IACxC,WAAW,EAAE,CACX,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAC5D,OAAO,EAAE;QAAE,gBAAgB,EAAE,OAAO,CAAA;KAAE,KACnC,IAAI,CAAC;IACV,oDAAoD;IACpD,cAAc,EAAE,OAAO,CAAC;IACxB,4CAA4C;IAC5C,eAAe,EAAE,eAAe,CAAC;IACjC,gDAAgD;IAChD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,yCAAyC;IACzC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qCAAqC;IACrC,cAAc,CAAC,EAAE,CAAC,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC;IAC1C,qCAAqC;IACrC,cAAc,CAAC,EAAE,CAAC,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC;IAC1C,8CAA8C;IAC9C,gBAAgB,CAAC,EAAE,CAAC,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC;IAC5C,wCAAwC;IACxC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,6CAA6C;IAC7C,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACvC,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,iDAAiD;IACjD,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACvC;AAED,UAAU,cAAc;IACtB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,4CAA4C;IAC5C,kBAAkB,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IAC7C,4CAA4C;IAC5C,kBAAkB,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IAC7C,4CAA4C;IAC5C,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B;AAaD;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,QAAA,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"VariableHeightVirtualizer.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,OAAO,CAAC;AAsBrD,MAAM,WAAW,WAAW;IAC1B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,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,+CAA+C;IAC/C,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,4CAA4C;IAC5C,kBAAkB,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IAC7C,4CAA4C;IAC5C,kBAAkB,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IAC7C,4CAA4C;IAC5C,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B;AAaD;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,QAAA,MAAM,yBAAyB,2HA6T9B,CAAC;AAIF,eAAe,yBAAyB,CAAC"}
|
package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.js
CHANGED
|
@@ -200,13 +200,14 @@ const VariableHeightVirtualizer = forwardRef(({ id, children, buffer = 15, apiCa
|
|
|
200
200
|
(!endIndex ||
|
|
201
201
|
(itemContainerRef.current &&
|
|
202
202
|
parentContainerRef.current &&
|
|
203
|
-
isViewNotFilled(virtualizedCount, itemContainerRef.current, parentContainerRef.current, !!headerRenderer)))) {
|
|
203
|
+
isViewNotFilled(virtualizedCount, itemContainerRef.current, parentContainerRef.current, !!headerRenderer, startIndex)))) {
|
|
204
204
|
triggerPagination(scrollTop);
|
|
205
205
|
}
|
|
206
206
|
}, [
|
|
207
207
|
loadedDataRange,
|
|
208
208
|
scrollTop,
|
|
209
209
|
virtualizedCount,
|
|
210
|
+
startIndex,
|
|
210
211
|
endIndex,
|
|
211
212
|
triggerPagination,
|
|
212
213
|
parentContainerDimensionChangeTrigger,
|
package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableHeightVirtualizer.js","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,QAAQ,EACR,WAAW,EACX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B,CAAC","sourcesContent":["import {\n useRef,\n useEffect,\n useState,\n useCallback,\n useLayoutEffect,\n forwardRef,\n useImperativeHandle,\n useMemo\n} from 'react';\nimport type { ReactNode, ForwardedRef } from 'react';\nimport Styled from 'styled-components';\n\nimport { Progress } from '@pega/cosmos-react-core';\n\nimport useResizeObserver from '../UseResizeObserver';\nimport useTranslate from '../../../Hooks/useTranslate';\n\nimport useChildrenHeightResizeObserver from './useChildrenHeightResizeObserver';\nimport useLoaderPositioning from './useLoaderPositioning';\nimport usePagination from './usePagination';\nimport useScroll from './useScroll';\nimport useVirtualizerItemCount from './useVirtualizerItemCount';\nimport {\n calculateCumulativeItemSizeChange,\n getMaxHeight,\n isViewNotFilled,\n calculateTotalBufferHeight,\n getChangedItemsHeight,\n updateItemPositionStyles\n} from './utils';\n\nexport interface ItemsHeight {\n [index: number]: number;\n}\n\nexport interface LoadedDataRange {\n startIndex?: number;\n endIndex?: number;\n}\n\ninterface StyledLoaderProps {\n $style: {\n top: string;\n left: string;\n };\n}\n\nexport interface VariableHeightVirtualizerProps {\n /** Unique identifier for the virtualizer instance. */\n id: string;\n /** The React children elements to render inside the virtualizer. */\n children: ReactNode;\n /** Callback to fetch paginated data. */\n apiCallback: (\n params: { startIndex: number; endIndex: number; id: string },\n options: { takeLatestAction: boolean }\n ) => void;\n /** Indicates if data is currently being fetched. */\n isDataFetching: boolean;\n /** Range of data that is already loaded. */\n loadedDataRange: LoadedDataRange;\n /** Default height for items if not measured. */\n defaultItemHeight?: number;\n /** Total number of items in the list. */\n totalItemCount?: number | null;\n /** Number of items to buffer before/after the visible range. */\n buffer?: number;\n /** Maximum number of items to render at once. */\n maxItemsToPaint?: number;\n /** Function to render the header. */\n headerRenderer?: (() => ReactNode) | null;\n /** Function to render the footer. */\n footerRenderer?: (() => ReactNode) | null;\n /** Function to render the no-result state. */\n noResultRenderer?: (() => ReactNode) | null;\n /** CSS class for the item container. */\n itemContainerClass?: string;\n /** Maximum height for the view container. */\n viewMaxHeight?: string | number | null;\n /** Minimum height for the view container. */\n minHeight?: string | number;\n /** Minimum height when no items are rendered. */\n minHeightWhenNoItemsRendered?: string;\n}\n\ninterface VirtualizerRef {\n /** Scrolls the parent container to the top. */\n scrollToTop: () => void;\n /** Returns the parent container element. */\n getParentContainer: () => HTMLElement | null;\n /** Returns the buffer container element. */\n getBufferContainer: () => HTMLElement | null;\n /** Triggers a count change notification. */\n notifyCountChange: () => void;\n}\n\nconst StyledLoader = Styled.div<StyledLoaderProps>`\n display: flex;\n justify-content: center;\n padding: 0.5rem;\n position: absolute;\n width: var(--container-width);\n left: ${props => `var(${props.$style.left})`};\n top: ${props => `var(${props.$style.top})`};\n width: 100%;\n`;\n\n/**\n * Flow:\n * 1. First load/user scrolls/screen size change/column resize\n * 2. Calculate new pagination range based on scroll position or if view not filled\n * 3. Consumer executes API call to fetch new data\n * 4. New items are prepared and rendered\n * 5. Update cache of item heights\n * 6. Update buffer height\n * 7. Adjust itemContainer top\n * 8. Adjust scrollTop (if needed) to keep the items at same position visually\n */\n\n/**\n * VariableHeightVirtualizer is a React component that efficiently renders large lists with items of variable heights,\n * using virtualization techniques to minimize DOM nodes and improve performance.\n *\n * @param props - {@link VariableHeightVirtualizerProps}\n * @param ref - Forwarded ref exposing imperative APIs: scrollToTop, getParentContainer, getBufferContainer, notifyCountChange.\n *\n * @example\n * ```tsx\n * <VariableHeightVirtualizer\n * id=\"my-list\"\n * totalItemCount={10000}\n * loadedDataRange={{ startIndex: 0, endIndex: 49 }}\n * isDataFetching={isLoading}\n * apiCallback={fetchData}\n * defaultItemHeight={40}\n * buffer={10}\n * headerRenderer={() => <Header />}\n * footerRenderer={() => <Footer />}\n * noResultRenderer={() => <NoResults />}\n * >\n * {items.map(item => <ListItem key={item.id} {...item} />)}\n * </VariableHeightVirtualizer>\n * ```\n */\nconst VariableHeightVirtualizer = forwardRef<VirtualizerRef, VariableHeightVirtualizerProps>(\n (\n {\n id,\n children,\n buffer = 15,\n apiCallback,\n loadedDataRange = {},\n defaultItemHeight = 30,\n totalItemCount,\n maxItemsToPaint = 5000,\n headerRenderer = null,\n footerRenderer = null,\n noResultRenderer = null,\n itemContainerClass = '',\n viewMaxHeight = null,\n minHeight = 'auto',\n isDataFetching = false,\n minHeightWhenNoItemsRendered = 'auto'\n },\n ref: ForwardedRef<VirtualizerRef>\n ) => {\n const [startIndex, setStartIndex] = useState<number>(0);\n const [endIndex, setEndIndex] = useState<number>(0);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [totalBufferHeight, setTotalBufferHeight] = useState<number>(0);\n const [itemsHeight, setItemsHeight] = useState<ItemsHeight>({});\n const [itemContainerHeight, setItemContainerHeight] = useState<number>(0);\n\n const [countChangeTrigger, setCountChangeTrigger] = useState<number>(0);\n const [itemHeightChangeTrigger, setItemHeightChangeTrigger] = useState<number>(0);\n const [parentContainerDimensionChangeTrigger, setParentContainerDimensionChangeTrigger] =\n useState<number>(0);\n\n const parentContainerRef = useRef<HTMLDivElement>(null);\n const bufferContainerRef = useRef<HTMLDivElement>(null);\n const itemContainerRef = useRef<HTMLDivElement>(null);\n const previousItemsHeightRef = useRef<ItemsHeight>({});\n const previousFirstItemDataIndexRef = useRef<number | null>(null);\n\n const [translate] = useTranslate();\n\n const onParentContainerDimensionUpdate = useCallback(() => {\n const { height: parentContainerHeight, width: parentContainerWidth } =\n parentContainerRef.current?.getBoundingClientRect() ?? {};\n // trigger virtualizer operations only when the container has some height and width\n if (parentContainerHeight && parentContainerWidth) {\n setParentContainerDimensionChangeTrigger(value => value + 1);\n }\n }, []);\n\n const getParentContainer = useCallback(\n (): HTMLDivElement | null => parentContainerRef.current,\n []\n );\n useResizeObserver(getParentContainer, onParentContainerDimensionUpdate);\n\n const { isInfiniteMode, virtualizedCount } = useVirtualizerItemCount({\n totalItemCount,\n startIndex,\n endIndex,\n loadedDataRange,\n isDataFetching,\n itemContainerRef,\n children,\n buffer,\n countResetSignal: countChangeTrigger\n });\n\n const { triggerPagination, isForceRefreshedPagination } = usePagination({\n apiCallback,\n id,\n buffer,\n maxItemsToPaint,\n startIndex,\n endIndex,\n virtualizedCount,\n isInfiniteMode,\n itemsHeight,\n defaultItemHeight,\n parentContainerRef,\n itemContainerRef,\n setStartIndex,\n setEndIndex,\n previousFirstItemDataIndexRef\n });\n\n // Listens to the scroll events and trigger pagination when more records are needed to enable smooth scrolling\n useScroll({\n parentContainerRef,\n itemContainerRef,\n onThresholdBreach: (sTop: number) => {\n setScrollTop(sTop);\n triggerPagination(sTop);\n },\n delay: 150\n });\n\n // Expose APIs to the consumer\n useImperativeHandle(\n ref,\n (): VirtualizerRef => ({\n scrollToTop: () => {\n if (parentContainerRef.current) {\n parentContainerRef.current.scrollTop = 0;\n setScrollTop(0);\n\n triggerPagination(0, true);\n }\n },\n getParentContainer: () => parentContainerRef.current,\n getBufferContainer: () => itemContainerRef.current,\n notifyCountChange: () => setCountChangeTrigger(value => value + 1)\n })\n );\n\n // Measure height of rendered items and cache the heights\n useLayoutEffect(() => {\n if (!itemContainerRef.current) return;\n\n const newHeights = getChangedItemsHeight(\n itemContainerRef.current,\n itemsHeight,\n defaultItemHeight\n );\n if (Object.keys(newHeights).length > 0) {\n setItemsHeight((prev: ItemsHeight) => ({ ...prev, ...newHeights }));\n }\n }, [\n startIndex,\n itemsHeight,\n children,\n isDataFetching,\n defaultItemHeight,\n itemHeightChangeTrigger\n ]);\n\n // buffer height calculation\n useLayoutEffect(() => {\n const newBufferHeight = calculateTotalBufferHeight(\n virtualizedCount,\n itemsHeight,\n defaultItemHeight\n );\n\n if (newBufferHeight !== totalBufferHeight) {\n setTotalBufferHeight(newBufferHeight);\n }\n }, [itemsHeight, virtualizedCount, defaultItemHeight, totalBufferHeight]);\n\n // itemContainer size and position adjustments\n useLayoutEffect(() => {\n if (!itemContainerRef.current) return;\n\n setItemContainerHeight(\n updateItemPositionStyles(itemContainerRef.current, itemsHeight, defaultItemHeight)\n );\n }, [children, itemsHeight, defaultItemHeight]);\n\n // scroll position adjustment if rendered height is different than estimated height\n useLayoutEffect(() => {\n if (!parentContainerRef.current) return;\n\n const atTop = parentContainerRef.current.scrollTop === 0;\n if (!atTop) {\n const delta = calculateCumulativeItemSizeChange(\n startIndex,\n previousFirstItemDataIndexRef.current,\n itemsHeight,\n previousItemsHeightRef.current,\n defaultItemHeight\n );\n\n if (delta !== 0) {\n parentContainerRef.current.scrollTop += delta;\n }\n }\n\n previousItemsHeightRef.current = { ...itemsHeight };\n }, [startIndex, itemsHeight, defaultItemHeight]);\n\n // Adjust loader positions\n useLoaderPositioning({\n isDataFetching,\n parentContainerRef,\n itemContainerRef,\n children,\n itemsHeight,\n defaultItemHeight\n });\n\n // Initial pagination trigger and subsequent triggers if the view is not completely filled\n useEffect(() => {\n // If consumer already has data for initial items, then no need to trigger pagination. Just hydrate the internal state in sync with existing data.\n if (\n !endIndex &&\n loadedDataRange.startIndex !== undefined &&\n loadedDataRange.startIndex >= 0 &&\n loadedDataRange.endIndex !== undefined &&\n loadedDataRange.endIndex >= 0\n ) {\n setStartIndex(loadedDataRange.startIndex);\n setEndIndex(loadedDataRange.endIndex);\n return;\n }\n\n // If the consumer doesn't have data or view not filled then trigger pagination\n if (\n !isDataFetching &&\n (!endIndex ||\n (itemContainerRef.current &&\n parentContainerRef.current &&\n isViewNotFilled(\n virtualizedCount,\n itemContainerRef.current,\n parentContainerRef.current,\n !!headerRenderer\n )))\n ) {\n triggerPagination(scrollTop);\n }\n }, [\n loadedDataRange,\n scrollTop,\n virtualizedCount,\n endIndex,\n triggerPagination,\n parentContainerDimensionChangeTrigger,\n isDataFetching,\n headerRenderer\n ]);\n\n // Resize observer on items to track height changes\n const onItemsHeightUpdate = useCallback(() => {\n setItemHeightChangeTrigger(value => value + 1);\n }, []);\n useChildrenHeightResizeObserver({\n childrenContainerRef: itemContainerRef,\n children,\n itemsHeight,\n defaultItemHeight,\n onItemsHeightUpdate\n });\n\n const maxHeight = useMemo((): string => getMaxHeight(viewMaxHeight), [viewMaxHeight]);\n\n return (\n <div\n ref={parentContainerRef}\n style={{\n maxHeight,\n minHeight: virtualizedCount === 0 ? minHeightWhenNoItemsRendered : minHeight,\n overflowY: 'auto',\n position: 'relative',\n width: '100%'\n }}\n className='pContainer variableHeightVirtualizer'\n data-total-records={totalItemCount}\n >\n {headerRenderer && headerRenderer()}\n <div\n className='bContainer'\n ref={bufferContainerRef}\n style={{ height: totalBufferHeight, position: 'relative' }}\n >\n {isDataFetching && !isForceRefreshedPagination && (\n <StyledLoader\n $style={{\n top: '--above-loader-top',\n left: '--loader-left'\n }}\n >\n <Progress\n className='above-loader'\n placement='block'\n tabIndex={0}\n aria-label={translate('Loading more results')}\n />\n </StyledLoader>\n )}\n\n <div\n ref={itemContainerRef}\n style={{\n position: 'absolute',\n left: 0,\n width: '100%',\n height: `${itemContainerHeight}px`\n }}\n className={`${itemContainerClass} row-container`}\n >\n {children}\n </div>\n\n {isDataFetching && !isForceRefreshedPagination && (\n <StyledLoader\n $style={{\n top: '--below-loader-top',\n left: '--loader-left'\n }}\n >\n <Progress\n className='below-loader'\n placement='block'\n tabIndex={0}\n aria-label={translate('Loading more results')}\n />\n </StyledLoader>\n )}\n </div>\n {virtualizedCount === 0 && !isDataFetching && noResultRenderer ? noResultRenderer() : null}\n {footerRenderer && footerRenderer()}\n </div>\n );\n }\n);\n\nVariableHeightVirtualizer.displayName = 'VariableHeightVirtualizer';\n\nexport default VariableHeightVirtualizer;\n"]}
|
|
1
|
+
{"version":3,"file":"VariableHeightVirtualizer.js","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/VariableHeightVirtualizer.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,QAAQ,EACR,WAAW,EACX,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,OAAO,EACR,MAAM,OAAO,CAAC;AAEf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,O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AkB,EACvB,KAAK,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAE,aAEzD,cAAc,IAAI,CAAC,0BAA0B,IAAI,CAChD,KAAC,YAAY,cACH;4BACN,GAAG,EAAE,oBAAoB;4BACzB,IAAI,EAAE,eAAe;yBACtB,YAED,KAAC,QAAQ,IACP,SAAS,EAAC,cAAc,EACxB,SAAS,EAAC,OAAO,EACjB,QAAQ,EAAE,CAAC,gBACC,SAAS,CAAC,sBAAsB,CAAC,GAC7C,GACW,CAChB,EAED,cACE,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE;4BACL,QAAQ,EAAE,UAAU;4BACpB,IAAI,EAAE,CAAC;4BACP,KAAK,EAAE,MAAM;4BACb,MAAM,EAAE,GAAG,mBAAmB,IAAI;yBACnC,EACD,SAAS,EAAE,GAAG,kBAAkB,gBAAgB,YAE/C,QAAQ,GACL,EAEL,cAAc,IAAI,CAAC,0BAA0B,IAAI,CAChD,KAAC,YAAY,cACH;4BACN,GAAG,EAAE,oBAAoB;4BACzB,IAAI,EAAE,eAAe;yBACtB,YAED,KAAC,QAAQ,IACP,SAAS,EAAC,cAAc,EACxB,SAAS,EAAC,OAAO,EACjB,QAAQ,EAAE,CAAC,gBACC,SAAS,CAAC,sBAAsB,CAAC,GAC7C,GACW,CAChB,IACG,EACL,gBAAgB,KAAK,CAAC,IAAI,CAAC,cAAc,IAAI,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,IAAI,EACzF,cAAc,IAAI,cAAc,EAAE,IAC/B,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,yBAAyB,CAAC,WAAW,GAAG,2BAA2B,CAAC;AAEpE,eAAe,yBAAyB,CAAC","sourcesContent":["import {\n useRef,\n useEffect,\n useState,\n useCallback,\n useLayoutEffect,\n forwardRef,\n useImperativeHandle,\n useMemo\n} from 'react';\nimport type { ReactNode, ForwardedRef } from 'react';\nimport Styled from 'styled-components';\n\nimport { Progress } from '@pega/cosmos-react-core';\n\nimport useResizeObserver from '../UseResizeObserver';\nimport useTranslate from '../../../Hooks/useTranslate';\n\nimport useChildrenHeightResizeObserver from './useChildrenHeightResizeObserver';\nimport useLoaderPositioning from './useLoaderPositioning';\nimport usePagination from './usePagination';\nimport useScroll from './useScroll';\nimport useVirtualizerItemCount from './useVirtualizerItemCount';\nimport {\n calculateCumulativeItemSizeChange,\n getMaxHeight,\n isViewNotFilled,\n calculateTotalBufferHeight,\n getChangedItemsHeight,\n updateItemPositionStyles\n} from './utils';\n\nexport interface ItemsHeight {\n [index: number]: number;\n}\n\nexport interface LoadedDataRange {\n startIndex?: number;\n endIndex?: number;\n}\n\ninterface StyledLoaderProps {\n $style: {\n top: string;\n left: string;\n };\n}\n\nexport interface VariableHeightVirtualizerProps {\n /** Unique identifier for the virtualizer instance. */\n id: string;\n /** The React children elements to render inside the virtualizer. */\n children: ReactNode;\n /** Callback to fetch paginated data. */\n apiCallback: (\n params: { startIndex: number; endIndex: number; id: string },\n options: { takeLatestAction: boolean }\n ) => void;\n /** Indicates if data is currently being fetched. */\n isDataFetching: boolean;\n /** Range of data that is already loaded. */\n loadedDataRange: LoadedDataRange;\n /** Default height for items if not measured. */\n defaultItemHeight?: number;\n /** Total number of items in the list. */\n totalItemCount?: number | null;\n /** Number of items to buffer before/after the visible range. */\n buffer?: number;\n /** Maximum number of items to render at once. */\n maxItemsToPaint?: number;\n /** Function to render the header. */\n headerRenderer?: (() => ReactNode) | null;\n /** Function to render the footer. */\n footerRenderer?: (() => ReactNode) | null;\n /** Function to render the no-result state. */\n noResultRenderer?: (() => ReactNode) | null;\n /** CSS class for the item container. */\n itemContainerClass?: string;\n /** Maximum height for the view container. */\n viewMaxHeight?: string | number | null;\n /** Minimum height for the view container. */\n minHeight?: string | number;\n /** Minimum height when no items are rendered. */\n minHeightWhenNoItemsRendered?: string;\n}\n\ninterface VirtualizerRef {\n /** Scrolls the parent container to the top. */\n scrollToTop: () => void;\n /** Returns the parent container element. */\n getParentContainer: () => HTMLElement | null;\n /** Returns the buffer container element. */\n getBufferContainer: () => HTMLElement | null;\n /** Triggers a count change notification. */\n notifyCountChange: () => void;\n}\n\nconst StyledLoader = Styled.div<StyledLoaderProps>`\n display: flex;\n justify-content: center;\n padding: 0.5rem;\n position: absolute;\n width: var(--container-width);\n left: ${props => `var(${props.$style.left})`};\n top: ${props => `var(${props.$style.top})`};\n width: 100%;\n`;\n\n/**\n * Flow:\n * 1. First load/user scrolls/screen size change/column resize\n * 2. Calculate new pagination range based on scroll position or if view not filled\n * 3. Consumer executes API call to fetch new data\n * 4. New items are prepared and rendered\n * 5. Update cache of item heights\n * 6. Update buffer height\n * 7. Adjust itemContainer top\n * 8. Adjust scrollTop (if needed) to keep the items at same position visually\n */\n\n/**\n * VariableHeightVirtualizer is a React component that efficiently renders large lists with items of variable heights,\n * using virtualization techniques to minimize DOM nodes and improve performance.\n *\n * @param props - {@link VariableHeightVirtualizerProps}\n * @param ref - Forwarded ref exposing imperative APIs: scrollToTop, getParentContainer, getBufferContainer, notifyCountChange.\n *\n * @example\n * ```tsx\n * <VariableHeightVirtualizer\n * id=\"my-list\"\n * totalItemCount={10000}\n * loadedDataRange={{ startIndex: 0, endIndex: 49 }}\n * isDataFetching={isLoading}\n * apiCallback={fetchData}\n * defaultItemHeight={40}\n * buffer={10}\n * headerRenderer={() => <Header />}\n * footerRenderer={() => <Footer />}\n * noResultRenderer={() => <NoResults />}\n * >\n * {items.map(item => <ListItem key={item.id} {...item} />)}\n * </VariableHeightVirtualizer>\n * ```\n */\nconst VariableHeightVirtualizer = forwardRef<VirtualizerRef, VariableHeightVirtualizerProps>(\n (\n {\n id,\n children,\n buffer = 15,\n apiCallback,\n loadedDataRange = {},\n defaultItemHeight = 30,\n totalItemCount,\n maxItemsToPaint = 5000,\n headerRenderer = null,\n footerRenderer = null,\n noResultRenderer = null,\n itemContainerClass = '',\n viewMaxHeight = null,\n minHeight = 'auto',\n isDataFetching = false,\n minHeightWhenNoItemsRendered = 'auto'\n },\n ref: ForwardedRef<VirtualizerRef>\n ) => {\n const [startIndex, setStartIndex] = useState<number>(0);\n const [endIndex, setEndIndex] = useState<number>(0);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [totalBufferHeight, setTotalBufferHeight] = useState<number>(0);\n const [itemsHeight, setItemsHeight] = useState<ItemsHeight>({});\n const [itemContainerHeight, setItemContainerHeight] = useState<number>(0);\n\n const [countChangeTrigger, setCountChangeTrigger] = useState<number>(0);\n const [itemHeightChangeTrigger, setItemHeightChangeTrigger] = useState<number>(0);\n const [parentContainerDimensionChangeTrigger, setParentContainerDimensionChangeTrigger] =\n useState<number>(0);\n\n const parentContainerRef = useRef<HTMLDivElement>(null);\n const bufferContainerRef = useRef<HTMLDivElement>(null);\n const itemContainerRef = useRef<HTMLDivElement>(null);\n const previousItemsHeightRef = useRef<ItemsHeight>({});\n const previousFirstItemDataIndexRef = useRef<number | null>(null);\n\n const [translate] = useTranslate();\n\n const onParentContainerDimensionUpdate = useCallback(() => {\n const { height: parentContainerHeight, width: parentContainerWidth } =\n parentContainerRef.current?.getBoundingClientRect() ?? {};\n // trigger virtualizer operations only when the container has some height and width\n if (parentContainerHeight && parentContainerWidth) {\n setParentContainerDimensionChangeTrigger(value => value + 1);\n }\n }, []);\n\n const getParentContainer = useCallback(\n (): HTMLDivElement | null => parentContainerRef.current,\n []\n );\n useResizeObserver(getParentContainer, onParentContainerDimensionUpdate);\n\n const { isInfiniteMode, virtualizedCount } = useVirtualizerItemCount({\n totalItemCount,\n startIndex,\n endIndex,\n loadedDataRange,\n isDataFetching,\n itemContainerRef,\n children,\n buffer,\n countResetSignal: countChangeTrigger\n });\n\n const { triggerPagination, isForceRefreshedPagination } = usePagination({\n apiCallback,\n id,\n buffer,\n maxItemsToPaint,\n startIndex,\n endIndex,\n virtualizedCount,\n isInfiniteMode,\n itemsHeight,\n defaultItemHeight,\n parentContainerRef,\n itemContainerRef,\n setStartIndex,\n setEndIndex,\n previousFirstItemDataIndexRef\n });\n\n // Listens to the scroll events and trigger pagination when more records are needed to enable smooth scrolling\n useScroll({\n parentContainerRef,\n itemContainerRef,\n onThresholdBreach: (sTop: number) => {\n setScrollTop(sTop);\n triggerPagination(sTop);\n },\n delay: 150\n });\n\n // Expose APIs to the consumer\n useImperativeHandle(\n ref,\n (): VirtualizerRef => ({\n scrollToTop: () => {\n if (parentContainerRef.current) {\n parentContainerRef.current.scrollTop = 0;\n setScrollTop(0);\n\n triggerPagination(0, true);\n }\n },\n getParentContainer: () => parentContainerRef.current,\n getBufferContainer: () => itemContainerRef.current,\n notifyCountChange: () => setCountChangeTrigger(value => value + 1)\n })\n );\n\n // Measure height of rendered items and cache the heights\n useLayoutEffect(() => {\n if (!itemContainerRef.current) return;\n\n const newHeights = getChangedItemsHeight(\n itemContainerRef.current,\n itemsHeight,\n defaultItemHeight\n );\n if (Object.keys(newHeights).length > 0) {\n setItemsHeight((prev: ItemsHeight) => ({ ...prev, ...newHeights }));\n }\n }, [\n startIndex,\n itemsHeight,\n children,\n isDataFetching,\n defaultItemHeight,\n itemHeightChangeTrigger\n ]);\n\n // buffer height calculation\n useLayoutEffect(() => {\n const newBufferHeight = calculateTotalBufferHeight(\n virtualizedCount,\n itemsHeight,\n defaultItemHeight\n );\n\n if (newBufferHeight !== totalBufferHeight) {\n setTotalBufferHeight(newBufferHeight);\n }\n }, [itemsHeight, virtualizedCount, defaultItemHeight, totalBufferHeight]);\n\n // itemContainer size and position adjustments\n useLayoutEffect(() => {\n if (!itemContainerRef.current) return;\n\n setItemContainerHeight(\n updateItemPositionStyles(itemContainerRef.current, itemsHeight, defaultItemHeight)\n );\n }, [children, itemsHeight, defaultItemHeight]);\n\n // scroll position adjustment if rendered height is different than estimated height\n useLayoutEffect(() => {\n if (!parentContainerRef.current) return;\n\n const atTop = parentContainerRef.current.scrollTop === 0;\n if (!atTop) {\n const delta = calculateCumulativeItemSizeChange(\n startIndex,\n previousFirstItemDataIndexRef.current,\n itemsHeight,\n previousItemsHeightRef.current,\n defaultItemHeight\n );\n\n if (delta !== 0) {\n parentContainerRef.current.scrollTop += delta;\n }\n }\n\n previousItemsHeightRef.current = { ...itemsHeight };\n }, [startIndex, itemsHeight, defaultItemHeight]);\n\n // Adjust loader positions\n useLoaderPositioning({\n isDataFetching,\n parentContainerRef,\n itemContainerRef,\n children,\n itemsHeight,\n defaultItemHeight\n });\n\n // Initial pagination trigger and subsequent triggers if the view is not completely filled\n useEffect(() => {\n // If consumer already has data for initial items, then no need to trigger pagination. Just hydrate the internal state in sync with existing data.\n if (\n !endIndex &&\n loadedDataRange.startIndex !== undefined &&\n loadedDataRange.startIndex >= 0 &&\n loadedDataRange.endIndex !== undefined &&\n loadedDataRange.endIndex >= 0\n ) {\n setStartIndex(loadedDataRange.startIndex);\n setEndIndex(loadedDataRange.endIndex);\n return;\n }\n\n // If the consumer doesn't have data or view not filled then trigger pagination\n if (\n !isDataFetching &&\n (!endIndex ||\n (itemContainerRef.current &&\n parentContainerRef.current &&\n isViewNotFilled(\n virtualizedCount,\n itemContainerRef.current,\n parentContainerRef.current,\n !!headerRenderer,\n startIndex\n )))\n ) {\n triggerPagination(scrollTop);\n }\n }, [\n loadedDataRange,\n scrollTop,\n virtualizedCount,\n startIndex,\n endIndex,\n triggerPagination,\n parentContainerDimensionChangeTrigger,\n isDataFetching,\n headerRenderer\n ]);\n\n // Resize observer on items to track height changes\n const onItemsHeightUpdate = useCallback(() => {\n setItemHeightChangeTrigger(value => value + 1);\n }, []);\n useChildrenHeightResizeObserver({\n childrenContainerRef: itemContainerRef,\n children,\n itemsHeight,\n defaultItemHeight,\n onItemsHeightUpdate\n });\n\n const maxHeight = useMemo((): string => getMaxHeight(viewMaxHeight), [viewMaxHeight]);\n\n return (\n <div\n ref={parentContainerRef}\n style={{\n maxHeight,\n minHeight: virtualizedCount === 0 ? minHeightWhenNoItemsRendered : minHeight,\n overflowY: 'auto',\n position: 'relative',\n width: '100%'\n }}\n className='pContainer variableHeightVirtualizer'\n data-total-records={totalItemCount}\n >\n {headerRenderer && headerRenderer()}\n <div\n className='bContainer'\n ref={bufferContainerRef}\n style={{ height: totalBufferHeight, position: 'relative' }}\n >\n {isDataFetching && !isForceRefreshedPagination && (\n <StyledLoader\n $style={{\n top: '--above-loader-top',\n left: '--loader-left'\n }}\n >\n <Progress\n className='above-loader'\n placement='block'\n tabIndex={0}\n aria-label={translate('Loading more results')}\n />\n </StyledLoader>\n )}\n\n <div\n ref={itemContainerRef}\n style={{\n position: 'absolute',\n left: 0,\n width: '100%',\n height: `${itemContainerHeight}px`\n }}\n className={`${itemContainerClass} row-container`}\n >\n {children}\n </div>\n\n {isDataFetching && !isForceRefreshedPagination && (\n <StyledLoader\n $style={{\n top: '--below-loader-top',\n left: '--loader-left'\n }}\n >\n <Progress\n className='below-loader'\n placement='block'\n tabIndex={0}\n aria-label={translate('Loading more results')}\n />\n </StyledLoader>\n )}\n </div>\n {virtualizedCount === 0 && !isDataFetching && noResultRenderer ? noResultRenderer() : null}\n {footerRenderer && footerRenderer()}\n </div>\n );\n }\n);\n\nVariableHeightVirtualizer.displayName = 'VariableHeightVirtualizer';\n\nexport default VariableHeightVirtualizer;\n"]}
|
package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ interface VirtualizerItemCountParams {
|
|
|
17
17
|
totalItemCount?: number | null;
|
|
18
18
|
/** Optional buffer to add to the count in infinite mode. */
|
|
19
19
|
buffer?: number;
|
|
20
|
-
/** Signal to reset the count
|
|
20
|
+
/** Signal to reset the count when the list data changes. */
|
|
21
21
|
countResetSignal?: number;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -27,7 +27,7 @@ interface VirtualizerItemCountParams {
|
|
|
27
27
|
* - `isInfiniteMode`: Whether the list is in infinite scrolling mode.
|
|
28
28
|
* - `virtualizedCount`: The current count of virtualized items.
|
|
29
29
|
*
|
|
30
|
-
* NOTE: In finite mode, the count is based on `totalItemCount
|
|
30
|
+
* NOTE: In finite mode, the count is based on `totalItemCount` and can shrink on a short page.
|
|
31
31
|
* NOTE: In infinite mode, the count is dynamically calculated based on loaded items and buffer.
|
|
32
32
|
*/
|
|
33
33
|
export default function useVirtualizerItemCount(params: VirtualizerItemCountParams): {
|
package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualizerItemCount.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE,UAAU,0BAA0B;IAClC,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,eAAe,EAAE,eAAe,CAAC;IACjC,wDAAwD;IACxD,cAAc,EAAE,OAAO,CAAC;IAExB,mDAAmD;IACnD,gBAAgB,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IACzC,gDAAgD;IAChD,QAAQ,EAAE,SAAS,CAAC;IAEpB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,
|
|
1
|
+
{"version":3,"file":"useVirtualizerItemCount.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE,UAAU,0BAA0B;IAClC,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,eAAe,EAAE,eAAe,CAAC;IACjC,wDAAwD;IACxD,cAAc,EAAE,OAAO,CAAC;IAExB,mDAAmD;IACnD,gBAAgB,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IACzC,gDAAgD;IAChD,QAAQ,EAAE,SAAS,CAAC;IAEpB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,MAAM,EAAE,0BAA0B,GAAG;IACnF,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAiGA"}
|
|
@@ -7,7 +7,7 @@ import { getDataIndex } from './utils';
|
|
|
7
7
|
* - `isInfiniteMode`: Whether the list is in infinite scrolling mode.
|
|
8
8
|
* - `virtualizedCount`: The current count of virtualized items.
|
|
9
9
|
*
|
|
10
|
-
* NOTE: In finite mode, the count is based on `totalItemCount
|
|
10
|
+
* NOTE: In finite mode, the count is based on `totalItemCount` and can shrink on a short page.
|
|
11
11
|
* NOTE: In infinite mode, the count is dynamically calculated based on loaded items and buffer.
|
|
12
12
|
*/
|
|
13
13
|
export default function useVirtualizerItemCount(params) {
|
|
@@ -18,17 +18,33 @@ export default function useVirtualizerItemCount(params) {
|
|
|
18
18
|
if (!isInfiniteMode) {
|
|
19
19
|
setVirtualizedCount(totalItemCount ?? 0);
|
|
20
20
|
}
|
|
21
|
-
}, [totalItemCount, isInfiniteMode]);
|
|
21
|
+
}, [totalItemCount, isInfiniteMode, countResetSignal]);
|
|
22
22
|
useLayoutEffect(() => {
|
|
23
23
|
if (isInfiniteMode) {
|
|
24
24
|
setVirtualizedCount(0);
|
|
25
25
|
}
|
|
26
26
|
}, [countResetSignal, isInfiniteMode]);
|
|
27
|
-
//
|
|
27
|
+
// Check completed short pages in finite mode; grow the count only in infinite mode.
|
|
28
28
|
useEffect(() => {
|
|
29
|
-
if (!
|
|
29
|
+
if (!endIndex || !loadedDataRange.endIndex || isDataFetching)
|
|
30
30
|
return;
|
|
31
31
|
const items = itemContainerRef.current?.children;
|
|
32
|
+
if (!isInfiniteMode) {
|
|
33
|
+
// Wait for the requested page's results before reducing the finite count.
|
|
34
|
+
// Otherwise, rows from the previous page could be mistaken for a short response.
|
|
35
|
+
if (loadedDataRange.startIndex !== startIndex ||
|
|
36
|
+
loadedDataRange.endIndex !== endIndex ||
|
|
37
|
+
!items?.length) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const lastItemDataIndex = getDataIndex(items[items.length - 1]);
|
|
41
|
+
// If results end before the requested end index, reduce the count to the last returned index + 1.
|
|
42
|
+
if (lastItemDataIndex !== null && lastItemDataIndex < endIndex) {
|
|
43
|
+
setVirtualizedCount(count => Math.min(count, lastItemDataIndex + 1));
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Infinite mode logic
|
|
32
48
|
if (!items?.length) {
|
|
33
49
|
setVirtualizedCount(0);
|
|
34
50
|
return;
|
|
@@ -52,7 +68,8 @@ export default function useVirtualizerItemCount(params) {
|
|
|
52
68
|
loadedDataRange,
|
|
53
69
|
virtualizedCount,
|
|
54
70
|
itemContainerRef,
|
|
55
|
-
endIndex
|
|
71
|
+
endIndex,
|
|
72
|
+
startIndex
|
|
56
73
|
]);
|
|
57
74
|
return {
|
|
58
75
|
isInfiniteMode,
|
package/lib/Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualizerItemCount.js","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,EACf,OAAO,EACP,QAAQ,EAGT,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAyBvC;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,MAAkC;IAIhF,MAAM,EACJ,UAAU,EACV,QAAQ,EACR,eAAe,EACf,cAAc,EACd,cAAc,EACd,MAAM,GAAG,EAAE,EACX,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACT,GAAG,MAAM,CAAC;IAEX,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAC,cAAc,IAAI,CAAC,CAAC,CAAC;IAE9E,MAAM,cAAc,GAAG,OAAO,CAC5B,GAAG,EAAE,CAAC,cAAc,KAAK,IAAI,IAAI,cAAc,KAAK,SAAS,EAC7D,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,mBAAmB,CAAC,cAAc,IAAI,CAAC,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"useVirtualizerItemCount.js","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/useVirtualizerItemCount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,EACf,OAAO,EACP,QAAQ,EAGT,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAyBvC;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,MAAkC;IAIhF,MAAM,EACJ,UAAU,EAC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LoadedDataRange } from './VariableHeightVirtualizer';\nimport { getDataIndex } from './utils';\n\ninterface VirtualizerItemCountParams {\n /** The starting index requested by virtualizer. */\n startIndex: number;\n /** The ending index requested by virtualizer. */\n endIndex: number;\n /** The range of items currently loaded. */\n loadedDataRange: LoadedDataRange;\n /** Indicates if the data is currently being fetched. */\n isDataFetching: boolean;\n\n /** Ref to the container holding rendered items. */\n itemContainerRef: RefObject<HTMLElement>;\n /** The rendered children items as ReactNode. */\n children: ReactNode;\n\n /** The total number of items if known, or `null`/`undefined` for infinite mode. */\n totalItemCount?: number | null;\n /** Optional buffer to add to the count in infinite mode. */\n buffer?: number;\n /** Signal to reset the count when the list data changes. */\n countResetSignal?: number;\n}\n\n/**\n * Determines the count of virtualized items in a list and whether the list is in infinite scrolling mode or not.\n *\n * @returns An object containing:\n * - `isInfiniteMode`: Whether the list is in infinite scrolling mode.\n * - `virtualizedCount`: The current count of virtualized items.\n *\n * NOTE: In finite mode, the count is based on `totalItemCount` and can shrink on a short page.\n * NOTE: In infinite mode, the count is dynamically calculated based on loaded items and buffer.\n */\nexport default function useVirtualizerItemCount(params: VirtualizerItemCountParams): {\n isInfiniteMode: boolean;\n virtualizedCount: number;\n} {\n const {\n startIndex,\n endIndex,\n loadedDataRange,\n isDataFetching,\n totalItemCount,\n buffer = 10,\n countResetSignal,\n itemContainerRef,\n children\n } = params;\n\n const [virtualizedCount, setVirtualizedCount] = useState(totalItemCount || 0);\n\n const isInfiniteMode = useMemo(\n () => totalItemCount === null || totalItemCount === undefined,\n [totalItemCount]\n );\n\n useLayoutEffect(() => {\n if (!isInfiniteMode) {\n setVirtualizedCount(totalItemCount ?? 0);\n }\n }, [totalItemCount, isInfiniteMode, countResetSignal]);\n\n useLayoutEffect(() => {\n if (isInfiniteMode) {\n setVirtualizedCount(0);\n }\n }, [countResetSignal, isInfiniteMode]);\n\n // Check completed short pages in finite mode; grow the count only in infinite mode.\n useEffect(() => {\n if (!endIndex || !loadedDataRange.endIndex || isDataFetching) return;\n\n const items = itemContainerRef.current?.children;\n\n if (!isInfiniteMode) {\n // Wait for the requested page's results before reducing the finite count.\n // Otherwise, rows from the previous page could be mistaken for a short response.\n if (\n loadedDataRange.startIndex !== startIndex ||\n loadedDataRange.endIndex !== endIndex ||\n !items?.length\n ) {\n return;\n }\n\n const lastItemDataIndex = getDataIndex(items[items.length - 1]);\n\n // If results end before the requested end index, reduce the count to the last returned index + 1.\n if (lastItemDataIndex !== null && lastItemDataIndex < endIndex) {\n setVirtualizedCount(count => Math.min(count, lastItemDataIndex + 1));\n }\n\n return;\n }\n\n // Infinite mode logic\n\n if (!items?.length) {\n setVirtualizedCount(0);\n return;\n }\n\n const lastItemDataIndex = getDataIndex(items[items.length - 1]) ?? -1;\n\n const hasMoreResults =\n loadedDataRange.startIndex === startIndex &&\n loadedDataRange.endIndex === endIndex &&\n lastItemDataIndex === endIndex;\n\n if (!hasMoreResults && Number.isInteger(lastItemDataIndex)) {\n setVirtualizedCount(lastItemDataIndex + 1);\n return;\n }\n\n const countWithBuffer = loadedDataRange.endIndex + 1 + buffer;\n if (hasMoreResults && countWithBuffer > virtualizedCount) {\n setVirtualizedCount(countWithBuffer);\n }\n }, [\n isDataFetching,\n children,\n isInfiniteMode,\n loadedDataRange,\n virtualizedCount,\n itemContainerRef,\n endIndex,\n startIndex\n ]);\n\n return {\n isInfiniteMode,\n virtualizedCount\n };\n}\n"]}
|
|
@@ -62,9 +62,10 @@ export declare const getOffsetForIndex: (index: number, itemsHeight: ItemsHeight
|
|
|
62
62
|
* @param itemContainer - The HTML element containing the rendered items.
|
|
63
63
|
* @param parentContainer - The parent HTML element that contains the items and possibly the header.
|
|
64
64
|
* @param renderHeader - Indicates whether a header is rendered at the top of the parent container.
|
|
65
|
+
* @param startIndex - The requested window's start index, used to allow recovery from an empty out-of-range window.
|
|
65
66
|
* @returns `true` if the view is not filled with all items, `false` otherwise.
|
|
66
67
|
*/
|
|
67
|
-
export declare const isViewNotFilled: (totalItemCount: number, itemContainer: HTMLDivElement, parentContainer: HTMLDivElement, renderHeader: boolean) => boolean;
|
|
68
|
+
export declare const isViewNotFilled: (totalItemCount: number, itemContainer: HTMLDivElement, parentContainer: HTMLDivElement, renderHeader: boolean, startIndex: number) => boolean;
|
|
68
69
|
/**
|
|
69
70
|
* Retrieves the numeric data index from the `data-index` attribute of a given Element.
|
|
70
71
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,UAAU,qCAAqC;IAC7C,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACxC,kDAAkD;IAClD,gBAAgB,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAE5C,6BAA6B;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,WAAW,EAAE,WAAW,CAAC;IACzB,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,CAAC;IAE1B,iGAAiG;IACjG,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,+FAA+F;IAC/F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,GAC1C,OAAO,qCAAqC,KAC3C;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAgDxC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACrC,gBAAgB,MAAM,EACtB,aAAa,WAAW,EACxB,mBAAmB,MAAM,KACxB,MAOF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,eAAe,MAAM,GAAG,MAAM,GAAG,IAAI,KAAG,MAGpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,MAAM,EACb,aAAa,WAAW,EACxB,mBAAmB,MAAM,KACxB,MAOF,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,UAAU,qCAAqC;IAC7C,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACxC,kDAAkD;IAClD,gBAAgB,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAE5C,6BAA6B;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,WAAW,EAAE,WAAW,CAAC;IACzB,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,CAAC;IAE1B,iGAAiG;IACjG,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,+FAA+F;IAC/F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,GAC1C,OAAO,qCAAqC,KAC3C;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAgDxC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACrC,gBAAgB,MAAM,EACtB,aAAa,WAAW,EACxB,mBAAmB,MAAM,KACxB,MAOF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,eAAe,MAAM,GAAG,MAAM,GAAG,IAAI,KAAG,MAGpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,MAAM,EACb,aAAa,WAAW,EACxB,mBAAmB,MAAM,KACxB,MAOF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAC1B,gBAAgB,MAAM,EACtB,eAAe,cAAc,EAC7B,iBAAiB,cAAc,EAC/B,cAAc,OAAO,EACrB,YAAY,MAAM,KACjB,OA8BF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,OAAO,KAAG,MAAM,GAAG,IAKxD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,cAAc,EAC7B,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,MAAM,GACxB,WAAW,CAkBb;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,GAC5C,YAAY,MAAM,EAClB,4BAA4B,MAAM,GAAG,IAAI,EACzC,aAAa,WAAW,EACxB,qBAAqB,WAAW,EAChC,mBAAmB,MAAM,KACxB,MAiBF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,cAAc,EAC7B,aAAa,WAAW,EACxB,mBAAmB,MAAM,KACxB,MAwBF,CAAC"}
|
|
@@ -87,9 +87,10 @@ export const getOffsetForIndex = (index, itemsHeight, defaultItemHeight) => {
|
|
|
87
87
|
* @param itemContainer - The HTML element containing the rendered items.
|
|
88
88
|
* @param parentContainer - The parent HTML element that contains the items and possibly the header.
|
|
89
89
|
* @param renderHeader - Indicates whether a header is rendered at the top of the parent container.
|
|
90
|
+
* @param startIndex - The requested window's start index, used to allow recovery from an empty out-of-range window.
|
|
90
91
|
* @returns `true` if the view is not filled with all items, `false` otherwise.
|
|
91
92
|
*/
|
|
92
|
-
export const isViewNotFilled = (totalItemCount, itemContainer, parentContainer, renderHeader) => {
|
|
93
|
+
export const isViewNotFilled = (totalItemCount, itemContainer, parentContainer, renderHeader, startIndex) => {
|
|
93
94
|
const parentContainerPosition = parentContainer.getBoundingClientRect();
|
|
94
95
|
let headerHeight = 0;
|
|
95
96
|
if (renderHeader && parentContainer.childElementCount > 1) {
|
|
@@ -102,8 +103,11 @@ export const isViewNotFilled = (totalItemCount, itemContainer, parentContainer,
|
|
|
102
103
|
const items = Array.from(itemContainer.children);
|
|
103
104
|
if (!items.length && !totalItemCount)
|
|
104
105
|
return false;
|
|
105
|
-
if (!items.length && totalItemCount)
|
|
106
|
-
|
|
106
|
+
if (!items.length && totalItemCount) {
|
|
107
|
+
// Do not keep fetching to fill an empty page.
|
|
108
|
+
// If this page is past the end of the list, allow pagination to reset.
|
|
109
|
+
return startIndex >= totalItemCount;
|
|
110
|
+
}
|
|
107
111
|
return (!!totalItemCount &&
|
|
108
112
|
items.length !== totalItemCount &&
|
|
109
113
|
(Math.floor(items[items.length - 1].getBoundingClientRect().bottom) <
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AA2BrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,KAA4C,EACF,EAAE;IAC5C,MAAM,EACJ,cAAc,EACd,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,cAAc,EACf,GAAG,KAAK,CAAC;IAEV,MAAM,wBAAwB,GAAG,MAAM,GAAG,CAAC,CAAC;IAC5C,IAAI,cAAc,KAAK,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,KAAK,CAAC,EAAE,CAA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,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QACjC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,0BAA0B,IAAI,CAAC;QACnD,0BAA0B,IAAI,WAAW,CAAC,gBAAgB,CAAC,IAAI,iBAAiB,CAAC;QACjF,gBAAgB,IAAI,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import type { RefObject } from 'react';\n\nimport { getScrollbarWidth } from 'pega-repeating-structures-core';\nimport { isInstance } from '@pega/cosmos-react-core';\n\nimport type { ItemsHeight } from './VariableHeightVirtualizer';\n\ninterface GetVirtualizedPaginationIndicesParams {\n /** Current vertical scroll offset of the container. */\n scrollTop: number;\n /** Ref to the scrolling container element */\n containerRef: RefObject<HTMLDivElement>;\n /** Ref to the container holding the list items */\n itemContainerRef: RefObject<HTMLDivElement>;\n\n /** Total number of items. */\n totalItemCount: number;\n /** Mapping of item indices and their actual height. */\n itemsHeight: ItemsHeight;\n /** Default height for items if not measured. */\n defaultItemHeight: number;\n\n /** Number of extra items to render above and below the visible viewport for smooth scrolling. */\n buffer: number;\n /** Maximum allowed end index (exclusive). */\n endIndexLimit: number;\n /** If true, allows indices to exceed totalCount for infinite scrolling by including buffer. */\n isInfiniteMode?: boolean;\n}\n\n/**\n * Calculates the start and end indices for virtualized pagination in a variable-height list.\n *\n * @returns {{ startIndex: number, endIndex: number }} Object containing the calculated start and end indices for rendering (inclusive both indices).\n */\nexport const getVirtualizedPaginationIndices = (\n param: GetVirtualizedPaginationIndicesParams\n): { startIndex: number; endIndex: number } => {\n const {\n totalItemCount,\n buffer,\n itemContainerRef,\n scrollTop,\n containerRef,\n itemsHeight,\n defaultItemHeight,\n endIndexLimit,\n isInfiniteMode\n } = param;\n\n const minimumItemsToFetchOnTop = buffer * 4;\n if (totalItemCount === 0 || itemContainerRef.current?.childElementCount === 0) {\n return { startIndex: 0, endIndex: minimumItemsToFetchOnTop };\n }\n\n const viewportHeight = containerRef.current?.clientHeight || 0;\n\n // Find the first visible item index for the current scroll position\n let aboveTheFoldItemsHeight = 0;\n let visibleStartIndex = 0;\n while (\n visibleStartIndex < totalItemCount &&\n aboveTheFoldItemsHeight + (itemsHeight[visibleStartIndex] ?? defaultItemHeight) < scrollTop\n ) {\n aboveTheFoldItemsHeight += itemsHeight[visibleStartIndex] ?? defaultItemHeight;\n visibleStartIndex += 1;\n }\n\n // Find the last visible item index for the current scroll position\n let inViewItemsHeight = 0;\n let visibleEndIndex = visibleStartIndex;\n while (visibleEndIndex < totalItemCount && inViewItemsHeight < viewportHeight) {\n inViewItemsHeight += itemsHeight[visibleEndIndex] ?? defaultItemHeight;\n visibleEndIndex += 1;\n }\n\n const startIndex = Math.max(0, visibleStartIndex - buffer);\n let endIndex = Math.min(visibleEndIndex + buffer, endIndexLimit - 1);\n if (isInfiniteMode) {\n endIndex = Math.max(endIndex, minimumItemsToFetchOnTop);\n } else {\n // In cases where the count is very less due to filters, we would fetch more items to avoid unnecessary API calls if the count after the filter removed is more\n endIndex = Math.max(Math.min(totalItemCount - 1, endIndex), minimumItemsToFetchOnTop);\n }\n return { startIndex, endIndex };\n};\n\n/**\n * Calculates the total buffer height for a list of items, using their individual heights if available,\n * or a default height otherwise.\n *\n * @param totalItemCount - The total number of items in the list.\n * @param itemsHeight - An object or array containing the heights of individual items, indexed by item position.\n * @param defaultItemHeight - The default height to use for items whose height is not specified in `itemsHeight`.\n * @returns The sum of all item heights, using the default height for any missing values.\n */\nexport const calculateTotalBufferHeight = (\n totalItemCount: number,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n let totalBufferHeight = 0;\n for (let i = 0; i < totalItemCount; i += 1) {\n totalBufferHeight += itemsHeight[i] || defaultItemHeight;\n }\n\n return totalBufferHeight;\n};\n\n/**\n * Returns a CSS-compatible max-height value based on the input.\n *\n * @param viewMaxHeight - The maximum height value, which can be a number (pixels), a string (CSS value), or `null`.\n * @returns A string representing the CSS max-height value.\n */\nexport const getMaxHeight = (viewMaxHeight: number | string | null): string => {\n if (!viewMaxHeight) return 'none';\n return typeof viewMaxHeight === 'number' ? `${viewMaxHeight}px` : viewMaxHeight;\n};\n\n/**\n * Calculates the vertical offset for a given item index in a list with variable item heights.\n *\n * @param index - The index of the item for which to calculate the offset.\n * @param itemsHeight - Mapping of item indices and their actual height.\n * @param defaultItemHeight - The default height to use for items not present in the cache.\n * @returns The total offset (in pixels) from the top of the list to the specified index.\n */\nexport const getOffsetForIndex = (\n index: number,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n let offset = 0;\n\n for (let i = 0; i < index; i += 1) {\n offset += itemsHeight[i] ?? defaultItemHeight;\n }\n return offset;\n};\n\n/**\n * Determines whether the viewable area of a virtualized list is not fully filled with rendered items.\n *\n * @param totalItemCount - The total number of items that should be rendered.\n * @param itemContainer - The HTML element containing the rendered items.\n * @param parentContainer - The parent HTML element that contains the items and possibly the header.\n * @param renderHeader - Indicates whether a header is rendered at the top of the parent container.\n * @returns `true` if the view is not filled with all items, `false` otherwise.\n */\nexport const isViewNotFilled = (\n totalItemCount: number,\n itemContainer: HTMLDivElement,\n parentContainer: HTMLDivElement,\n renderHeader: boolean\n): boolean => {\n const parentContainerPosition = parentContainer.getBoundingClientRect();\n let headerHeight = 0;\n if (renderHeader && parentContainer.childElementCount > 1) {\n const firstChild = parentContainer.children[0];\n if (isInstance(firstChild, HTMLDivElement)) {\n headerHeight = firstChild.offsetHeight;\n }\n }\n\n const scrollbarWidth = getScrollbarWidth();\n const items = Array.from(itemContainer.children);\n\n if (!items.length && !totalItemCount) return false;\n if (!items.length && totalItemCount) return true;\n\n return (\n !!totalItemCount &&\n items.length !== totalItemCount &&\n (Math.floor(items[items.length - 1].getBoundingClientRect().bottom) <\n Math.floor(parentContainerPosition.bottom - scrollbarWidth) ||\n Math.floor(items[0].getBoundingClientRect().top) >\n Math.floor(parentContainerPosition.top + headerHeight) ||\n items.length === 0)\n );\n};\n\n/**\n * Retrieves the numeric data index from the `data-index` attribute of a given Element.\n *\n * @param element - The Element from which to extract the data index.\n * @returns The parsed integer value of the `data-index` attribute, or `null` if the attribute is not present.\n */\nexport const getDataIndex = (element: Element): number | null => {\n const dataIndexStr = element?.getAttribute('data-index');\n if (!dataIndexStr) return null;\n const parsedDataIndex = parseInt(dataIndexStr, 10);\n return Number.isNaN(parsedDataIndex) ? null : parsedDataIndex;\n};\n\n/**\n * Calculates and returns an object containing the heights of items whose heights have changed\n * compared to their previous values.\n *\n * @param itemContainer - The container HTMLElement whose child nodes represent items to measure.\n * @param itemsHeight - An object mapping item indices to their measured heights.\n * @param defaultItemHeight - The default height to use for items not present in `itemsHeight`.\n * @returns An object mapping item indices to their new heights for items whose heights have changed.\n */\nexport function getChangedItemsHeight(\n itemContainer: HTMLDivElement,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): ItemsHeight {\n if (!itemContainer) return {};\n\n const newHeights: ItemsHeight = {};\n const nodes = Array.from(itemContainer.children);\n\n nodes.forEach(node => {\n const itemDataIndex = getDataIndex(node);\n if (itemDataIndex === null) return;\n\n const measuredHeight = node.getBoundingClientRect().height;\n const prevHeight = itemsHeight[itemDataIndex] ?? defaultItemHeight;\n if (measuredHeight !== prevHeight) {\n newHeights[itemDataIndex] = measuredHeight;\n }\n });\n\n return newHeights;\n}\n\n/**\n * Calculates the cumulative change in item heights between two sets of item height data,\n * for a range of items starting from `startIndex` up to (but not including) `previousFirstItemDataIndex`.\n *\n * This function compares the current heights (`itemsHeight`) with the previous heights (`previousItemsHeight`)\n * for each item in the specified range, using `defaultItemHeight` as a fallback if a previous height is missing.\n * The result is the sum of the differences in height for all items in the range.\n *\n * @param startIndex - The index at which to start calculating the cumulative height change.\n * @param previousFirstItemDataIndex - The index up to which to calculate (exclusive). If `null` or less than or equal to 0, returns 0.\n * @param itemsHeight - An object mapping item indices to their measured heights.\n * @param previousItemsHeight - An object mapping item indices of previously rendered items to their heights.\n * @param defaultItemHeight - The default height to use if a previous height is not available.\n * @returns The cumulative change in item heights for the specified range, or 0 if the result is not finite.\n */\nexport const calculateCumulativeItemSizeChange = (\n startIndex: number,\n previousFirstItemDataIndex: number | null,\n itemsHeight: ItemsHeight,\n previousItemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n if (previousFirstItemDataIndex === null || previousFirstItemDataIndex <= 0) {\n return 0;\n }\n\n let delta = 0;\n\n for (let i = startIndex; i < previousFirstItemDataIndex; i += 1) {\n const actualHeight = itemsHeight[i];\n const previousHeight = previousItemsHeight[i] ?? defaultItemHeight;\n\n if (actualHeight !== null && actualHeight !== undefined) {\n delta += actualHeight - previousHeight;\n }\n }\n\n return Number.isFinite(delta) ? delta : 0;\n};\n\n/**\n * Updates the position styles of child items within a container element to enable virtualized rendering.\n * Sets the container's top offset and positions each child absolutely based on their calculated heights.\n *\n * @param itemContainer - The HTML element containing the list items to be positioned.\n * @param itemsHeight - An object mapping item indices to their measured heights.\n * @param defaultItemHeight - The default height to use for items without a specified height.\n * @returns The total height of all items within the container, rounded down to the nearest integer.\n */\nexport const updateItemPositionStyles = (\n itemContainer: HTMLDivElement,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n const items = itemContainer.children;\n if (!items?.length) {\n return 0;\n }\n\n const firstItemDataIndex = getDataIndex(items[0]);\n if (firstItemDataIndex === null) return 0;\n\n const offset = getOffsetForIndex(firstItemDataIndex, itemsHeight, defaultItemHeight);\n itemContainer.style.top = `${offset}px`;\n\n let itemContainerCurrentHeight = 0;\n let currentItemIndex = firstItemDataIndex;\n Array.from(items).forEach(item => {\n if (!isInstance(item, HTMLDivElement)) return;\n\n item.style.position = 'absolute';\n item.style.top = `${itemContainerCurrentHeight}px`;\n itemContainerCurrentHeight += itemsHeight[currentItemIndex] ?? defaultItemHeight;\n currentItemIndex += 1;\n });\n\n return Math.floor(itemContainerCurrentHeight);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../Core/Components/Virtualise/VariableHeightVirtualizer/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AA2BrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,KAA4C,EACF,EAAE;IAC5C,MAAM,EACJ,cAAc,EACd,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,cAAc,EACf,GAAG,KAAK,CAAC;IAEV,MAAM,wBAAwB,GAAG,MAAM,GAAG,CAAC,CAAC;IAC5C,IAAI,cAAc,KAAK,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,KAAK,CAAC,EAAE,CAAC;QAC9E,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,wBAAwB,EAAE,CAAC;IAC/D,CAAC;IAED,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,EAAE,YAAY,IAAI,CAAC,CAAC;IAE/D,oEAAoE;IACpE,IAAI,uBAAuB,GAAG,CAAC,CAAC;IAChC,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,OACE,iBAAiB,GAAG,cAAc;QAClC,uBAAuB,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC,GAAG,SAAS,EAC3F,CAAC;QACD,uBAAuB,IAAI,WAAW,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;QAC/E,iBAAiB,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,mEAAmE;IACnE,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,IAAI,eAAe,GAAG,iBAAiB,CAAC;IACxC,OAAO,eAAe,GAAG,cAAc,IAAI,iBAAiB,GAAG,cAAc,EAAE,CAAC;QAC9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ACV,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC;IACrC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,kBAAkB,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,IAAI,kBAAkB,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IAE1C,MAAM,MAAM,GAAG,iBAAiB,CAAC,kBAAkB,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;IACrF,aAAa,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,MAAM,IAAI,CAAC;IAExC,IAAI,0BAA0B,GAAG,CAAC,CAAC;IACnC,IAAI,gBAAgB,GAAG,kBAAkB,CAAC;IAC1C,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,cAAc,CAAC;YAAE,OAAO;QAE9C,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QACjC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,0BAA0B,IAAI,CAAC;QACnD,0BAA0B,IAAI,WAAW,CAAC,gBAAgB,CAAC,IAAI,iBAAiB,CAAC;QACjF,gBAAgB,IAAI,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import type { RefObject } from 'react';\n\nimport { getScrollbarWidth } from 'pega-repeating-structures-core';\nimport { isInstance } from '@pega/cosmos-react-core';\n\nimport type { ItemsHeight } from './VariableHeightVirtualizer';\n\ninterface GetVirtualizedPaginationIndicesParams {\n /** Current vertical scroll offset of the container. */\n scrollTop: number;\n /** Ref to the scrolling container element */\n containerRef: RefObject<HTMLDivElement>;\n /** Ref to the container holding the list items */\n itemContainerRef: RefObject<HTMLDivElement>;\n\n /** Total number of items. */\n totalItemCount: number;\n /** Mapping of item indices and their actual height. */\n itemsHeight: ItemsHeight;\n /** Default height for items if not measured. */\n defaultItemHeight: number;\n\n /** Number of extra items to render above and below the visible viewport for smooth scrolling. */\n buffer: number;\n /** Maximum allowed end index (exclusive). */\n endIndexLimit: number;\n /** If true, allows indices to exceed totalCount for infinite scrolling by including buffer. */\n isInfiniteMode?: boolean;\n}\n\n/**\n * Calculates the start and end indices for virtualized pagination in a variable-height list.\n *\n * @returns {{ startIndex: number, endIndex: number }} Object containing the calculated start and end indices for rendering (inclusive both indices).\n */\nexport const getVirtualizedPaginationIndices = (\n param: GetVirtualizedPaginationIndicesParams\n): { startIndex: number; endIndex: number } => {\n const {\n totalItemCount,\n buffer,\n itemContainerRef,\n scrollTop,\n containerRef,\n itemsHeight,\n defaultItemHeight,\n endIndexLimit,\n isInfiniteMode\n } = param;\n\n const minimumItemsToFetchOnTop = buffer * 4;\n if (totalItemCount === 0 || itemContainerRef.current?.childElementCount === 0) {\n return { startIndex: 0, endIndex: minimumItemsToFetchOnTop };\n }\n\n const viewportHeight = containerRef.current?.clientHeight || 0;\n\n // Find the first visible item index for the current scroll position\n let aboveTheFoldItemsHeight = 0;\n let visibleStartIndex = 0;\n while (\n visibleStartIndex < totalItemCount &&\n aboveTheFoldItemsHeight + (itemsHeight[visibleStartIndex] ?? defaultItemHeight) < scrollTop\n ) {\n aboveTheFoldItemsHeight += itemsHeight[visibleStartIndex] ?? defaultItemHeight;\n visibleStartIndex += 1;\n }\n\n // Find the last visible item index for the current scroll position\n let inViewItemsHeight = 0;\n let visibleEndIndex = visibleStartIndex;\n while (visibleEndIndex < totalItemCount && inViewItemsHeight < viewportHeight) {\n inViewItemsHeight += itemsHeight[visibleEndIndex] ?? defaultItemHeight;\n visibleEndIndex += 1;\n }\n\n const startIndex = Math.max(0, visibleStartIndex - buffer);\n let endIndex = Math.min(visibleEndIndex + buffer, endIndexLimit - 1);\n if (isInfiniteMode) {\n endIndex = Math.max(endIndex, minimumItemsToFetchOnTop);\n } else {\n // In cases where the count is very less due to filters, we would fetch more items to avoid unnecessary API calls if the count after the filter removed is more\n endIndex = Math.max(Math.min(totalItemCount - 1, endIndex), minimumItemsToFetchOnTop);\n }\n return { startIndex, endIndex };\n};\n\n/**\n * Calculates the total buffer height for a list of items, using their individual heights if available,\n * or a default height otherwise.\n *\n * @param totalItemCount - The total number of items in the list.\n * @param itemsHeight - An object or array containing the heights of individual items, indexed by item position.\n * @param defaultItemHeight - The default height to use for items whose height is not specified in `itemsHeight`.\n * @returns The sum of all item heights, using the default height for any missing values.\n */\nexport const calculateTotalBufferHeight = (\n totalItemCount: number,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n let totalBufferHeight = 0;\n for (let i = 0; i < totalItemCount; i += 1) {\n totalBufferHeight += itemsHeight[i] || defaultItemHeight;\n }\n\n return totalBufferHeight;\n};\n\n/**\n * Returns a CSS-compatible max-height value based on the input.\n *\n * @param viewMaxHeight - The maximum height value, which can be a number (pixels), a string (CSS value), or `null`.\n * @returns A string representing the CSS max-height value.\n */\nexport const getMaxHeight = (viewMaxHeight: number | string | null): string => {\n if (!viewMaxHeight) return 'none';\n return typeof viewMaxHeight === 'number' ? `${viewMaxHeight}px` : viewMaxHeight;\n};\n\n/**\n * Calculates the vertical offset for a given item index in a list with variable item heights.\n *\n * @param index - The index of the item for which to calculate the offset.\n * @param itemsHeight - Mapping of item indices and their actual height.\n * @param defaultItemHeight - The default height to use for items not present in the cache.\n * @returns The total offset (in pixels) from the top of the list to the specified index.\n */\nexport const getOffsetForIndex = (\n index: number,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n let offset = 0;\n\n for (let i = 0; i < index; i += 1) {\n offset += itemsHeight[i] ?? defaultItemHeight;\n }\n return offset;\n};\n\n/**\n * Determines whether the viewable area of a virtualized list is not fully filled with rendered items.\n *\n * @param totalItemCount - The total number of items that should be rendered.\n * @param itemContainer - The HTML element containing the rendered items.\n * @param parentContainer - The parent HTML element that contains the items and possibly the header.\n * @param renderHeader - Indicates whether a header is rendered at the top of the parent container.\n * @param startIndex - The requested window's start index, used to allow recovery from an empty out-of-range window.\n * @returns `true` if the view is not filled with all items, `false` otherwise.\n */\nexport const isViewNotFilled = (\n totalItemCount: number,\n itemContainer: HTMLDivElement,\n parentContainer: HTMLDivElement,\n renderHeader: boolean,\n startIndex: number\n): boolean => {\n const parentContainerPosition = parentContainer.getBoundingClientRect();\n let headerHeight = 0;\n if (renderHeader && parentContainer.childElementCount > 1) {\n const firstChild = parentContainer.children[0];\n if (isInstance(firstChild, HTMLDivElement)) {\n headerHeight = firstChild.offsetHeight;\n }\n }\n\n const scrollbarWidth = getScrollbarWidth();\n const items = Array.from(itemContainer.children);\n\n if (!items.length && !totalItemCount) return false;\n\n if (!items.length && totalItemCount) {\n // Do not keep fetching to fill an empty page.\n // If this page is past the end of the list, allow pagination to reset.\n return startIndex >= totalItemCount;\n }\n\n return (\n !!totalItemCount &&\n items.length !== totalItemCount &&\n (Math.floor(items[items.length - 1].getBoundingClientRect().bottom) <\n Math.floor(parentContainerPosition.bottom - scrollbarWidth) ||\n Math.floor(items[0].getBoundingClientRect().top) >\n Math.floor(parentContainerPosition.top + headerHeight) ||\n items.length === 0)\n );\n};\n\n/**\n * Retrieves the numeric data index from the `data-index` attribute of a given Element.\n *\n * @param element - The Element from which to extract the data index.\n * @returns The parsed integer value of the `data-index` attribute, or `null` if the attribute is not present.\n */\nexport const getDataIndex = (element: Element): number | null => {\n const dataIndexStr = element?.getAttribute('data-index');\n if (!dataIndexStr) return null;\n const parsedDataIndex = parseInt(dataIndexStr, 10);\n return Number.isNaN(parsedDataIndex) ? null : parsedDataIndex;\n};\n\n/**\n * Calculates and returns an object containing the heights of items whose heights have changed\n * compared to their previous values.\n *\n * @param itemContainer - The container HTMLElement whose child nodes represent items to measure.\n * @param itemsHeight - An object mapping item indices to their measured heights.\n * @param defaultItemHeight - The default height to use for items not present in `itemsHeight`.\n * @returns An object mapping item indices to their new heights for items whose heights have changed.\n */\nexport function getChangedItemsHeight(\n itemContainer: HTMLDivElement,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): ItemsHeight {\n if (!itemContainer) return {};\n\n const newHeights: ItemsHeight = {};\n const nodes = Array.from(itemContainer.children);\n\n nodes.forEach(node => {\n const itemDataIndex = getDataIndex(node);\n if (itemDataIndex === null) return;\n\n const measuredHeight = node.getBoundingClientRect().height;\n const prevHeight = itemsHeight[itemDataIndex] ?? defaultItemHeight;\n if (measuredHeight !== prevHeight) {\n newHeights[itemDataIndex] = measuredHeight;\n }\n });\n\n return newHeights;\n}\n\n/**\n * Calculates the cumulative change in item heights between two sets of item height data,\n * for a range of items starting from `startIndex` up to (but not including) `previousFirstItemDataIndex`.\n *\n * This function compares the current heights (`itemsHeight`) with the previous heights (`previousItemsHeight`)\n * for each item in the specified range, using `defaultItemHeight` as a fallback if a previous height is missing.\n * The result is the sum of the differences in height for all items in the range.\n *\n * @param startIndex - The index at which to start calculating the cumulative height change.\n * @param previousFirstItemDataIndex - The index up to which to calculate (exclusive). If `null` or less than or equal to 0, returns 0.\n * @param itemsHeight - An object mapping item indices to their measured heights.\n * @param previousItemsHeight - An object mapping item indices of previously rendered items to their heights.\n * @param defaultItemHeight - The default height to use if a previous height is not available.\n * @returns The cumulative change in item heights for the specified range, or 0 if the result is not finite.\n */\nexport const calculateCumulativeItemSizeChange = (\n startIndex: number,\n previousFirstItemDataIndex: number | null,\n itemsHeight: ItemsHeight,\n previousItemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n if (previousFirstItemDataIndex === null || previousFirstItemDataIndex <= 0) {\n return 0;\n }\n\n let delta = 0;\n\n for (let i = startIndex; i < previousFirstItemDataIndex; i += 1) {\n const actualHeight = itemsHeight[i];\n const previousHeight = previousItemsHeight[i] ?? defaultItemHeight;\n\n if (actualHeight !== null && actualHeight !== undefined) {\n delta += actualHeight - previousHeight;\n }\n }\n\n return Number.isFinite(delta) ? delta : 0;\n};\n\n/**\n * Updates the position styles of child items within a container element to enable virtualized rendering.\n * Sets the container's top offset and positions each child absolutely based on their calculated heights.\n *\n * @param itemContainer - The HTML element containing the list items to be positioned.\n * @param itemsHeight - An object mapping item indices to their measured heights.\n * @param defaultItemHeight - The default height to use for items without a specified height.\n * @returns The total height of all items within the container, rounded down to the nearest integer.\n */\nexport const updateItemPositionStyles = (\n itemContainer: HTMLDivElement,\n itemsHeight: ItemsHeight,\n defaultItemHeight: number\n): number => {\n const items = itemContainer.children;\n if (!items?.length) {\n return 0;\n }\n\n const firstItemDataIndex = getDataIndex(items[0]);\n if (firstItemDataIndex === null) return 0;\n\n const offset = getOffsetForIndex(firstItemDataIndex, itemsHeight, defaultItemHeight);\n itemContainer.style.top = `${offset}px`;\n\n let itemContainerCurrentHeight = 0;\n let currentItemIndex = firstItemDataIndex;\n Array.from(items).forEach(item => {\n if (!isInstance(item, HTMLDivElement)) return;\n\n item.style.position = 'absolute';\n item.style.top = `${itemContainerCurrentHeight}px`;\n itemContainerCurrentHeight += itemsHeight[currentItemIndex] ?? defaultItemHeight;\n currentItemIndex += 1;\n });\n\n return Math.floor(itemContainerCurrentHeight);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/lists-react",
|
|
3
|
-
"version": "8.34.
|
|
3
|
+
"version": "8.34.9",
|
|
4
4
|
"description": "Repeating view structures such as Table, Gallery(Repeating layouts), Kanban etc.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Pegasystems",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"build": "tsc -b tsconfig.build.json"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@pega/cosmos-react-condition-builder": "8.34.
|
|
18
|
-
"@pega/cosmos-react-core": "8.34.
|
|
19
|
-
"@pega/cosmos-react-rte": "8.34.
|
|
20
|
-
"@pega/cosmos-react-work": "8.34.
|
|
17
|
+
"@pega/cosmos-react-condition-builder": "8.34.9",
|
|
18
|
+
"@pega/cosmos-react-core": "8.34.9",
|
|
19
|
+
"@pega/cosmos-react-rte": "8.34.9",
|
|
20
|
+
"@pega/cosmos-react-work": "8.34.9",
|
|
21
21
|
"@types/lodash.get": "^4.4.9",
|
|
22
22
|
"@types/react": "^17.0.62 || ^18.3.3",
|
|
23
23
|
"@types/react-dom": "^17.0.20 || ^18.3.0",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"dayjs": "^1.11.13",
|
|
26
26
|
"fast-deep-equal": "^3.1.3",
|
|
27
27
|
"lodash.get": "^4.4.2",
|
|
28
|
-
"pega-repeating-structures-core": "npm:@pega/lists-core@8.34.
|
|
29
|
-
"pega-ui-list-data-apis": "npm:@pega/lists-core-utils@8.34.
|
|
28
|
+
"pega-repeating-structures-core": "npm:@pega/lists-core@8.34.9",
|
|
29
|
+
"pega-ui-list-data-apis": "npm:@pega/lists-core-utils@8.34.9",
|
|
30
30
|
"polished": "^4.1.0",
|
|
31
31
|
"prop-types": "^15.8.1",
|
|
32
32
|
"react": "^17.0.0 || ^18.0.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@testing-library/react": "^16.0.0",
|
|
46
46
|
"@testing-library/user-event": "^14.6.1",
|
|
47
47
|
"jest-axe": "^8.0.0",
|
|
48
|
-
"srs-utils": "8.34.
|
|
48
|
+
"srs-utils": "8.34.9",
|
|
49
49
|
"typescript": "~5.8.3"
|
|
50
50
|
}
|
|
51
51
|
}
|