@fluentui/react-table 9.11.12 → 9.11.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -2
- package/lib/components/DataGridCell/DataGridCell.types.js +3 -1
- package/lib/components/DataGridCell/DataGridCell.types.js.map +1 -1
- package/lib/components/DataGridHeader/DataGridHeader.types.js +3 -1
- package/lib/components/DataGridHeader/DataGridHeader.types.js.map +1 -1
- package/lib/components/DataGridHeaderCell/DataGridHeaderCell.types.js +3 -1
- package/lib/components/DataGridHeaderCell/DataGridHeaderCell.types.js.map +1 -1
- package/lib/components/DataGridSelectionCell/DataGridSelectionCell.types.js +3 -1
- package/lib/components/DataGridSelectionCell/DataGridSelectionCell.types.js.map +1 -1
- package/lib/components/Table/Table.types.js +3 -1
- package/lib/components/Table/Table.types.js.map +1 -1
- package/lib/components/TableBody/TableBody.types.js +3 -1
- package/lib/components/TableBody/TableBody.types.js.map +1 -1
- package/lib/components/TableCell/TableCell.types.js +3 -1
- package/lib/components/TableCell/TableCell.types.js.map +1 -1
- package/lib/components/TableCellActions/TableCellActions.types.js +3 -1
- package/lib/components/TableCellActions/TableCellActions.types.js.map +1 -1
- package/lib/components/TableCellLayout/TableCellLayout.types.js +3 -1
- package/lib/components/TableCellLayout/TableCellLayout.types.js.map +1 -1
- package/lib/components/TableHeader/TableHeader.types.js +3 -1
- package/lib/components/TableHeader/TableHeader.types.js.map +1 -1
- package/lib/components/TableHeaderCell/TableHeaderCell.types.js +3 -1
- package/lib/components/TableHeaderCell/TableHeaderCell.types.js.map +1 -1
- package/lib/components/TableResizeHandle/TableResizeHandle.types.js +3 -1
- package/lib/components/TableResizeHandle/TableResizeHandle.types.js.map +1 -1
- package/lib/components/TableRow/TableRow.types.js +3 -1
- package/lib/components/TableRow/TableRow.types.js.map +1 -1
- package/lib/components/TableSelectionCell/TableSelectionCell.types.js +3 -1
- package/lib/components/TableSelectionCell/TableSelectionCell.types.js.map +1 -1
- package/lib/hooks/useTableSelection.js +3 -0
- package/lib/hooks/useTableSelection.js.map +1 -1
- package/lib-commonjs/components/DataGridCell/DataGridCell.types.js +3 -1
- package/lib-commonjs/components/DataGridCell/DataGridCell.types.js.map +1 -1
- package/lib-commonjs/components/DataGridHeader/DataGridHeader.types.js +3 -1
- package/lib-commonjs/components/DataGridHeader/DataGridHeader.types.js.map +1 -1
- package/lib-commonjs/components/DataGridHeaderCell/DataGridHeaderCell.types.js +3 -1
- package/lib-commonjs/components/DataGridHeaderCell/DataGridHeaderCell.types.js.map +1 -1
- package/lib-commonjs/components/DataGridSelectionCell/DataGridSelectionCell.types.js +3 -1
- package/lib-commonjs/components/DataGridSelectionCell/DataGridSelectionCell.types.js.map +1 -1
- package/lib-commonjs/components/Table/Table.types.js +3 -1
- package/lib-commonjs/components/Table/Table.types.js.map +1 -1
- package/lib-commonjs/components/TableBody/TableBody.types.js +3 -1
- package/lib-commonjs/components/TableBody/TableBody.types.js.map +1 -1
- package/lib-commonjs/components/TableCell/TableCell.types.js +3 -1
- package/lib-commonjs/components/TableCell/TableCell.types.js.map +1 -1
- package/lib-commonjs/components/TableCellActions/TableCellActions.types.js +3 -1
- package/lib-commonjs/components/TableCellActions/TableCellActions.types.js.map +1 -1
- package/lib-commonjs/components/TableCellLayout/TableCellLayout.types.js +3 -1
- package/lib-commonjs/components/TableCellLayout/TableCellLayout.types.js.map +1 -1
- package/lib-commonjs/components/TableHeader/TableHeader.types.js +3 -1
- package/lib-commonjs/components/TableHeader/TableHeader.types.js.map +1 -1
- package/lib-commonjs/components/TableHeaderCell/TableHeaderCell.types.js +3 -1
- package/lib-commonjs/components/TableHeaderCell/TableHeaderCell.types.js.map +1 -1
- package/lib-commonjs/components/TableResizeHandle/TableResizeHandle.types.js +3 -1
- package/lib-commonjs/components/TableResizeHandle/TableResizeHandle.types.js.map +1 -1
- package/lib-commonjs/components/TableRow/TableRow.types.js +3 -1
- package/lib-commonjs/components/TableRow/TableRow.types.js.map +1 -1
- package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.types.js +3 -1
- package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.types.js.map +1 -1
- package/lib-commonjs/contexts/columnIdContext.js +3 -3
- package/lib-commonjs/contexts/columnIdContext.js.map +1 -1
- package/lib-commonjs/contexts/dataGridContext.js +3 -3
- package/lib-commonjs/contexts/dataGridContext.js.map +1 -1
- package/lib-commonjs/contexts/rowIdContext.js +3 -3
- package/lib-commonjs/contexts/rowIdContext.js.map +1 -1
- package/lib-commonjs/contexts/tableContext.js +3 -3
- package/lib-commonjs/contexts/tableContext.js.map +1 -1
- package/lib-commonjs/hooks/useMeasureElement.js +3 -3
- package/lib-commonjs/hooks/useMeasureElement.js.map +1 -1
- package/lib-commonjs/hooks/useTableSelection.js +3 -0
- package/lib-commonjs/hooks/useTableSelection.js.map +1 -1
- package/lib-commonjs/index.js +213 -213
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/columnResizeUtils.js +7 -7
- package/lib-commonjs/utils/columnResizeUtils.js.map +1 -1
- package/package.json +11 -11
|
@@ -9,12 +9,12 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
tableContextDefaultValue: function() {
|
|
13
|
-
return tableContextDefaultValue;
|
|
14
|
-
},
|
|
15
12
|
TableContextProvider: function() {
|
|
16
13
|
return TableContextProvider;
|
|
17
14
|
},
|
|
15
|
+
tableContextDefaultValue: function() {
|
|
16
|
+
return tableContextDefaultValue;
|
|
17
|
+
},
|
|
18
18
|
useTableContext: function() {
|
|
19
19
|
return useTableContext;
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["tableContext.js"],"sourcesContent":["import * as React from 'react';\nconst tableContext = React.createContext(undefined);\nexport const tableContextDefaultValue = {\n size: 'medium',\n noNativeElements: false,\n sortable: false\n};\nexport const TableContextProvider = tableContext.Provider;\nexport const useTableContext = ()=>{\n var _React_useContext;\n return (_React_useContext = React.useContext(tableContext)) !== null && _React_useContext !== void 0 ? _React_useContext : tableContextDefaultValue;\n};\n"],"names":["
|
|
1
|
+
{"version":3,"sources":["tableContext.js"],"sourcesContent":["import * as React from 'react';\nconst tableContext = React.createContext(undefined);\nexport const tableContextDefaultValue = {\n size: 'medium',\n noNativeElements: false,\n sortable: false\n};\nexport const TableContextProvider = tableContext.Provider;\nexport const useTableContext = ()=>{\n var _React_useContext;\n return (_React_useContext = React.useContext(tableContext)) !== null && _React_useContext !== void 0 ? _React_useContext : tableContextDefaultValue;\n};\n"],"names":["TableContextProvider","tableContextDefaultValue","useTableContext","tableContext","React","createContext","undefined","size","noNativeElements","sortable","Provider","_React_useContext","useContext"],"mappings":";;;;;;;;;;;IAOaA,oBAAoB;eAApBA;;IALAC,wBAAwB;eAAxBA;;IAMAC,eAAe;eAAfA;;;;iEARU;AACvB,MAAMC,6BAAeC,OAAMC,aAAa,CAACC;AAClC,MAAML,2BAA2B;IACpCM,MAAM;IACNC,kBAAkB;IAClBC,UAAU;AACd;AACO,MAAMT,uBAAuBG,aAAaO,QAAQ;AAClD,MAAMR,kBAAkB;IAC3B,IAAIS;IACJ,OAAO,AAACA,CAAAA,oBAAoBP,OAAMQ,UAAU,CAACT,aAAY,MAAO,QAAQQ,sBAAsB,KAAK,IAAIA,oBAAoBV;AAC/H"}
|
|
@@ -9,11 +9,11 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
useMeasureElement: function() {
|
|
13
|
-
return useMeasureElement;
|
|
14
|
-
},
|
|
15
12
|
createResizeObserverFromDocument: function() {
|
|
16
13
|
return createResizeObserverFromDocument;
|
|
14
|
+
},
|
|
15
|
+
useMeasureElement: function() {
|
|
16
|
+
return useMeasureElement;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useMeasureElement.js"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n/**\n * Provides a way of reporting element width.\n * Returns\n * `width` - current element width (0 by default),\n * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure\n */ export function useMeasureElement() {\n const [width, setWidth] = React.useState(0);\n const container = React.useRef(undefined);\n const { targetDocument } = useFluent();\n // the handler for resize observer\n const handleResize = React.useCallback(()=>{\n var _container_current;\n const containerWidth = (_container_current = container.current) === null || _container_current === void 0 ? void 0 : _container_current.getBoundingClientRect().width;\n setWidth(containerWidth || 0);\n }, []);\n // Keep the reference of ResizeObserver in the state, as it should live through renders\n const [resizeObserver] = React.useState(()=>createResizeObserverFromDocument(targetDocument, handleResize));\n const measureElementRef = React.useCallback((el)=>{\n if (!targetDocument || !resizeObserver) {\n return;\n }\n // cleanup previous container\n if (container.current) {\n resizeObserver.unobserve(container.current);\n }\n container.current = undefined;\n if (el === null || el === void 0 ? void 0 : el.parentElement) {\n container.current = el.parentElement;\n resizeObserver.observe(container.current);\n handleResize();\n }\n }, [\n targetDocument,\n resizeObserver,\n handleResize\n ]);\n React.useEffect(()=>{\n return ()=>resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();\n }, [\n resizeObserver\n ]);\n return {\n width,\n measureElementRef\n };\n}\n/**\n * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar\n * A utility method that creates a ResizeObserver from a target document\n * @param targetDocument - document to use to create the ResizeObserver\n * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback\n * @returns a ResizeObserver instance or null if the global does not exist on the document\n */ export function createResizeObserverFromDocument(targetDocument, callback) {\n var _targetDocument_defaultView;\n if (!(targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.ResizeObserver)) {\n return null;\n }\n return new targetDocument.defaultView.ResizeObserver(callback);\n}\n"],"names":["
|
|
1
|
+
{"version":3,"sources":["useMeasureElement.js"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n/**\n * Provides a way of reporting element width.\n * Returns\n * `width` - current element width (0 by default),\n * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure\n */ export function useMeasureElement() {\n const [width, setWidth] = React.useState(0);\n const container = React.useRef(undefined);\n const { targetDocument } = useFluent();\n // the handler for resize observer\n const handleResize = React.useCallback(()=>{\n var _container_current;\n const containerWidth = (_container_current = container.current) === null || _container_current === void 0 ? void 0 : _container_current.getBoundingClientRect().width;\n setWidth(containerWidth || 0);\n }, []);\n // Keep the reference of ResizeObserver in the state, as it should live through renders\n const [resizeObserver] = React.useState(()=>createResizeObserverFromDocument(targetDocument, handleResize));\n const measureElementRef = React.useCallback((el)=>{\n if (!targetDocument || !resizeObserver) {\n return;\n }\n // cleanup previous container\n if (container.current) {\n resizeObserver.unobserve(container.current);\n }\n container.current = undefined;\n if (el === null || el === void 0 ? void 0 : el.parentElement) {\n container.current = el.parentElement;\n resizeObserver.observe(container.current);\n handleResize();\n }\n }, [\n targetDocument,\n resizeObserver,\n handleResize\n ]);\n React.useEffect(()=>{\n return ()=>resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();\n }, [\n resizeObserver\n ]);\n return {\n width,\n measureElementRef\n };\n}\n/**\n * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar\n * A utility method that creates a ResizeObserver from a target document\n * @param targetDocument - document to use to create the ResizeObserver\n * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback\n * @returns a ResizeObserver instance or null if the global does not exist on the document\n */ export function createResizeObserverFromDocument(targetDocument, callback) {\n var _targetDocument_defaultView;\n if (!(targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.ResizeObserver)) {\n return null;\n }\n return new targetDocument.defaultView.ResizeObserver(callback);\n}\n"],"names":["createResizeObserverFromDocument","useMeasureElement","width","setWidth","React","useState","container","useRef","undefined","targetDocument","useFluent","handleResize","useCallback","_container_current","containerWidth","current","getBoundingClientRect","resizeObserver","measureElementRef","el","unobserve","parentElement","observe","useEffect","disconnect","callback","_targetDocument_defaultView","defaultView","ResizeObserver"],"mappings":";;;;;;;;;;;IAsDoBA,gCAAgC;eAAhCA;;IA/CAC,iBAAiB;eAAjBA;;;;iEAPG;qCACyB;AAMrC,SAASA;IAChB,MAAM,CAACC,OAAOC,SAAS,GAAGC,OAAMC,QAAQ,CAAC;IACzC,MAAMC,YAAYF,OAAMG,MAAM,CAACC;IAC/B,MAAM,EAAEC,cAAc,EAAE,GAAGC,IAAAA,uCAAS;IACpC,kCAAkC;IAClC,MAAMC,eAAeP,OAAMQ,WAAW,CAAC;QACnC,IAAIC;QACJ,MAAMC,iBAAiB,AAACD,CAAAA,qBAAqBP,UAAUS,OAAO,AAAD,MAAO,QAAQF,uBAAuB,KAAK,IAAI,KAAK,IAAIA,mBAAmBG,qBAAqB,GAAGd,KAAK;QACrKC,SAASW,kBAAkB;IAC/B,GAAG,EAAE;IACL,uFAAuF;IACvF,MAAM,CAACG,eAAe,GAAGb,OAAMC,QAAQ,CAAC,IAAIL,iCAAiCS,gBAAgBE;IAC7F,MAAMO,oBAAoBd,OAAMQ,WAAW,CAAC,CAACO;QACzC,IAAI,CAACV,kBAAkB,CAACQ,gBAAgB;YACpC;QACJ;QACA,6BAA6B;QAC7B,IAAIX,UAAUS,OAAO,EAAE;YACnBE,eAAeG,SAAS,CAACd,UAAUS,OAAO;QAC9C;QACAT,UAAUS,OAAO,GAAGP;QACpB,IAAIW,OAAO,QAAQA,OAAO,KAAK,IAAI,KAAK,IAAIA,GAAGE,aAAa,EAAE;YAC1Df,UAAUS,OAAO,GAAGI,GAAGE,aAAa;YACpCJ,eAAeK,OAAO,CAAChB,UAAUS,OAAO;YACxCJ;QACJ;IACJ,GAAG;QACCF;QACAQ;QACAN;KACH;IACDP,OAAMmB,SAAS,CAAC;QACZ,OAAO,IAAIN,mBAAmB,QAAQA,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAeO,UAAU;IACxG,GAAG;QACCP;KACH;IACD,OAAO;QACHf;QACAgB;IACJ;AACJ;AAOW,SAASlB,iCAAiCS,cAAc,EAAEgB,QAAQ;IACzE,IAAIC;IACJ,IAAI,CAAEjB,CAAAA,mBAAmB,QAAQA,mBAAmB,KAAK,IAAI,KAAK,IAAI,AAACiB,CAAAA,8BAA8BjB,eAAekB,WAAW,AAAD,MAAO,QAAQD,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BE,cAAc,AAAD,GAAI;QACxO,OAAO;IACX;IACA,OAAO,IAAInB,eAAekB,WAAW,CAACC,cAAc,CAACH;AACzD"}
|
|
@@ -70,6 +70,9 @@ function useTableSelectionState(tableState, options) {
|
|
|
70
70
|
if (selected.size < selectableRowIds.size) {
|
|
71
71
|
return false;
|
|
72
72
|
}
|
|
73
|
+
if (selectableRowIds.size === 0) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
73
76
|
let res = true;
|
|
74
77
|
selectableRowIds.forEach((selectableRowId)=>{
|
|
75
78
|
if (!selected.has(selectableRowId)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTableSelection.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback, useSelection } from '@fluentui/react-utilities';\nconst noop = ()=>undefined;\nexport const defaultTableSelectionState = {\n allRowsSelected: false,\n clearRows: noop,\n deselectRow: noop,\n isRowSelected: ()=>false,\n selectRow: noop,\n selectedRows: new Set(),\n someRowsSelected: false,\n toggleAllRows: noop,\n toggleRow: noop,\n selectionMode: 'multiselect'\n};\nexport function useTableSelection(options) {\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState)=>useTableSelectionState(tableState, options);\n}\nexport function useTableSelectionState(tableState, options) {\n const { items, getRowId } = tableState;\n const { selectionMode: selectionMode, defaultSelectedItems, selectedItems, onSelectionChange } = options;\n const [selected, selectionMethods] = useSelection({\n selectionMode,\n defaultSelectedItems,\n selectedItems,\n onSelectionChange\n });\n // Selection state can contain obselete items (i.e. rows that are removed)\n const selectableRowIds = React.useMemo(()=>{\n const rowIds = new Set();\n for(let i = 0; i < items.length; i++){\n var _getRowId;\n rowIds.add((_getRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(items[i])) !== null && _getRowId !== void 0 ? _getRowId : i);\n }\n return rowIds;\n }, [\n items,\n getRowId\n ]);\n const allRowsSelected = React.useMemo(()=>{\n if (selectionMode === 'single') {\n const selectedRow = Array.from(selected)[0];\n return selectableRowIds.has(selectedRow);\n }\n // multiselect case\n if (selected.size < selectableRowIds.size) {\n return false;\n }\n let res = true;\n selectableRowIds.forEach((selectableRowId)=>{\n if (!selected.has(selectableRowId)) {\n res = false;\n }\n });\n return res;\n }, [\n selectableRowIds,\n selected,\n selectionMode\n ]);\n const someRowsSelected = React.useMemo(()=>{\n if (selected.size <= 0) {\n return false;\n }\n let res = false;\n selectableRowIds.forEach((selectableRowId)=>{\n if (selected.has(selectableRowId)) {\n res = true;\n }\n });\n return res;\n }, [\n selectableRowIds,\n selected\n ]);\n const toggleAllRows = useEventCallback((e)=>{\n selectionMethods.toggleAllItems(e, items.map((item, i)=>{\n var _getRowId;\n return (_getRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(item)) !== null && _getRowId !== void 0 ? _getRowId : i;\n }));\n });\n const toggleRow = useEventCallback((e, rowId)=>selectionMethods.toggleItem(e, rowId));\n const deselectRow = useEventCallback((e, rowId)=>selectionMethods.deselectItem(e, rowId));\n const selectRow = useEventCallback((e, rowId)=>selectionMethods.selectItem(e, rowId));\n const isRowSelected = (rowId)=>selectionMethods.isSelected(rowId);\n const clearRows = useEventCallback((e)=>selectionMethods.clearItems(e));\n return {\n ...tableState,\n selection: {\n selectionMode,\n someRowsSelected,\n allRowsSelected,\n selectedRows: selected,\n toggleRow,\n toggleAllRows,\n clearRows,\n deselectRow,\n selectRow,\n isRowSelected\n }\n };\n}\n"],"names":["defaultTableSelectionState","useTableSelection","useTableSelectionState","noop","undefined","allRowsSelected","clearRows","deselectRow","isRowSelected","selectRow","selectedRows","Set","someRowsSelected","toggleAllRows","toggleRow","selectionMode","options","tableState","items","getRowId","defaultSelectedItems","selectedItems","onSelectionChange","selected","selectionMethods","useSelection","selectableRowIds","React","useMemo","rowIds","i","length","_getRowId","add","selectedRow","Array","from","has","size","res","forEach","selectableRowId","useEventCallback","e","toggleAllItems","map","item","rowId","toggleItem","deselectItem","selectItem","isSelected","clearItems","selection"],"mappings":";;;;;;;;;;;IAGaA,0BAA0B;eAA1BA;;IAYGC,iBAAiB;eAAjBA;;IAKAC,sBAAsB;eAAtBA;;;;iEApBO;gCACwB;AAC/C,MAAMC,OAAO,IAAIC;AACV,MAAMJ,6BAA6B;IACtCK,iBAAiB;IACjBC,WAAWH;IACXI,aAAaJ;IACbK,eAAe,IAAI;IACnBC,WAAWN;IACXO,cAAc,IAAIC;IAClBC,kBAAkB;IAClBC,eAAeV;IACfW,WAAWX;IACXY,eAAe;AACnB;AACO,SAASd,kBAAkBe,OAAO;IACrC,4EAA4E;IAC5E,sDAAsD;IACtD,OAAO,CAACC,aAAaf,uBAAuBe,YAAYD;AAC5D;AACO,SAASd,uBAAuBe,UAAU,EAAED,OAAO;IACtD,MAAM,EAAEE,KAAK,EAAEC,QAAQ,EAAE,GAAGF;IAC5B,MAAM,EAAEF,eAAeA,aAAa,EAAEK,oBAAoB,EAAEC,aAAa,EAAEC,iBAAiB,EAAE,GAAGN;IACjG,MAAM,CAACO,UAAUC,iBAAiB,GAAGC,IAAAA,4BAAY,EAAC;QAC9CV;QACAK;QACAC;QACAC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a,QAAQA,aAAa,KAAK,IAAI,KAAK,IAAIA,SAAS2B,KAAI,MAAO,QAAQd,cAAc,KAAK,IAAIA,YAAYF;QAC3I;IACJ;IACA,MAAMhB,YAAY4B,IAAAA,gCAAgB,EAAC,CAACC,GAAGI,QAAQvB,iBAAiBwB,UAAU,CAACL,GAAGI;IAC9E,MAAMxC,cAAcmC,IAAAA,gCAAgB,EAAC,CAACC,GAAGI,QAAQvB,iBAAiByB,YAAY,CAACN,GAAGI;IAClF,MAAMtC,YAAYiC,IAAAA,gCAAgB,EAAC,CAACC,GAAGI,QAAQvB,iBAAiB0B,UAAU,CAACP,GAAGI;IAC9E,MAAMvC,gBAAgB,CAACuC,QAAQvB,iBAAiB2B,UAAU,CAACJ;IAC3D,MAAMzC,YAAYoC,IAAAA,gCAAgB,EAAC,CAACC,IAAInB,iBAAiB4B,UAAU,CAACT;IACpE,OAAO;QACH,GAAG1B,UAAU;QACboC,WAAW;YACPtC;YACAH;YACAP;YACAK,cAAca;YACdT;YACAD;YACAP;YACAC;YACAE;YACAD;QACJ;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useTableSelection.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback, useSelection } from '@fluentui/react-utilities';\nconst noop = ()=>undefined;\nexport const defaultTableSelectionState = {\n allRowsSelected: false,\n clearRows: noop,\n deselectRow: noop,\n isRowSelected: ()=>false,\n selectRow: noop,\n selectedRows: new Set(),\n someRowsSelected: false,\n toggleAllRows: noop,\n toggleRow: noop,\n selectionMode: 'multiselect'\n};\nexport function useTableSelection(options) {\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState)=>useTableSelectionState(tableState, options);\n}\nexport function useTableSelectionState(tableState, options) {\n const { items, getRowId } = tableState;\n const { selectionMode: selectionMode, defaultSelectedItems, selectedItems, onSelectionChange } = options;\n const [selected, selectionMethods] = useSelection({\n selectionMode,\n defaultSelectedItems,\n selectedItems,\n onSelectionChange\n });\n // Selection state can contain obselete items (i.e. rows that are removed)\n const selectableRowIds = React.useMemo(()=>{\n const rowIds = new Set();\n for(let i = 0; i < items.length; i++){\n var _getRowId;\n rowIds.add((_getRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(items[i])) !== null && _getRowId !== void 0 ? _getRowId : i);\n }\n return rowIds;\n }, [\n items,\n getRowId\n ]);\n const allRowsSelected = React.useMemo(()=>{\n if (selectionMode === 'single') {\n const selectedRow = Array.from(selected)[0];\n return selectableRowIds.has(selectedRow);\n }\n // multiselect case\n if (selected.size < selectableRowIds.size) {\n return false;\n }\n if (selectableRowIds.size === 0) {\n return false;\n }\n let res = true;\n selectableRowIds.forEach((selectableRowId)=>{\n if (!selected.has(selectableRowId)) {\n res = false;\n }\n });\n return res;\n }, [\n selectableRowIds,\n selected,\n selectionMode\n ]);\n const someRowsSelected = React.useMemo(()=>{\n if (selected.size <= 0) {\n return false;\n }\n let res = false;\n selectableRowIds.forEach((selectableRowId)=>{\n if (selected.has(selectableRowId)) {\n res = true;\n }\n });\n return res;\n }, [\n selectableRowIds,\n selected\n ]);\n const toggleAllRows = useEventCallback((e)=>{\n selectionMethods.toggleAllItems(e, items.map((item, i)=>{\n var _getRowId;\n return (_getRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(item)) !== null && _getRowId !== void 0 ? _getRowId : i;\n }));\n });\n const toggleRow = useEventCallback((e, rowId)=>selectionMethods.toggleItem(e, rowId));\n const deselectRow = useEventCallback((e, rowId)=>selectionMethods.deselectItem(e, rowId));\n const selectRow = useEventCallback((e, rowId)=>selectionMethods.selectItem(e, rowId));\n const isRowSelected = (rowId)=>selectionMethods.isSelected(rowId);\n const clearRows = useEventCallback((e)=>selectionMethods.clearItems(e));\n return {\n ...tableState,\n selection: {\n selectionMode,\n someRowsSelected,\n allRowsSelected,\n selectedRows: selected,\n toggleRow,\n toggleAllRows,\n clearRows,\n deselectRow,\n selectRow,\n isRowSelected\n }\n };\n}\n"],"names":["defaultTableSelectionState","useTableSelection","useTableSelectionState","noop","undefined","allRowsSelected","clearRows","deselectRow","isRowSelected","selectRow","selectedRows","Set","someRowsSelected","toggleAllRows","toggleRow","selectionMode","options","tableState","items","getRowId","defaultSelectedItems","selectedItems","onSelectionChange","selected","selectionMethods","useSelection","selectableRowIds","React","useMemo","rowIds","i","length","_getRowId","add","selectedRow","Array","from","has","size","res","forEach","selectableRowId","useEventCallback","e","toggleAllItems","map","item","rowId","toggleItem","deselectItem","selectItem","isSelected","clearItems","selection"],"mappings":";;;;;;;;;;;IAGaA,0BAA0B;eAA1BA;;IAYGC,iBAAiB;eAAjBA;;IAKAC,sBAAsB;eAAtBA;;;;iEApBO;gCACwB;AAC/C,MAAMC,OAAO,IAAIC;AACV,MAAMJ,6BAA6B;IACtCK,iBAAiB;IACjBC,WAAWH;IACXI,aAAaJ;IACbK,eAAe,IAAI;IACnBC,WAAWN;IACXO,cAAc,IAAIC;IAClBC,kBAAkB;IAClBC,eAAeV;IACfW,WAAWX;IACXY,eAAe;AACnB;AACO,SAASd,kBAAkBe,OAAO;IACrC,4EAA4E;IAC5E,sDAAsD;IACtD,OAAO,CAACC,aAAaf,uBAAuBe,YAAYD;AAC5D;AACO,SAASd,uBAAuBe,UAAU,EAAED,OAAO;IACtD,MAAM,EAAEE,KAAK,EAAEC,QAAQ,EAAE,GAAGF;IAC5B,MAAM,EAAEF,eAAeA,aAAa,EAAEK,oBAAoB,EAAEC,aAAa,EAAEC,iBAAiB,EAAE,GAAGN;IACjG,MAAM,CAACO,UAAUC,iBAAiB,GAAGC,IAAAA,4BAAY,EAAC;QAC9CV;QACAK;QACAC;QACAC;IACJ;IACA,0EAA0E;IAC1E,MAAMI,mBAAmBC,OAAMC,OAAO,CAAC;QACnC,MAAMC,SAAS,IAAIlB;QACnB,IAAI,IAAImB,IAAI,GAAGA,IAAIZ,MAAMa,MAAM,EAAED,IAAI;YACjC,IAAIE;YACJH,OAAOI,GAAG,CAAC,AAACD,CAAAA,YAAYb,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