@economic/taco 2.54.0 → 2.55.0-settings.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Checkbox/Checkbox.d.ts +7 -2
- package/dist/components/List/List.d.ts +2 -2
- package/dist/components/List/components/Toggle.d.ts +2 -2
- package/dist/components/ModeSwitch/ModeSwitch.d.ts +6 -3
- package/dist/components/Provider/Provider.d.ts +7 -6
- package/dist/components/Provider/TacoContext.d.ts +7 -0
- package/dist/components/Provider/useTacoSettings.d.ts +8 -0
- package/dist/components/Report/Report.d.ts +1 -1
- package/dist/components/Switch/Switch.d.ts +6 -4
- package/dist/esm/index.css +76 -5
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js +41 -63
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/packages/taco/src/components/List/components/Toggle.js +14 -4
- package/dist/esm/packages/taco/src/components/List/components/Toggle.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Listbox/ScrollableList.js +6 -3
- package/dist/esm/packages/taco/src/components/Listbox/ScrollableList.js.map +1 -1
- package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js +34 -12
- package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Provider.js +14 -7
- package/dist/esm/packages/taco/src/components/Provider/Provider.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/TacoContext.js +6 -0
- package/dist/esm/packages/taco/src/components/Provider/TacoContext.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Provider/useTacoSettings.js +39 -0
- package/dist/esm/packages/taco/src/components/Provider/useTacoSettings.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Report/Report.js +8 -0
- package/dist/esm/packages/taco/src/components/Report/Report.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Switch/Switch.js +37 -35
- package/dist/esm/packages/taco/src/components/Switch/Switch.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +8 -0
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js.map +1 -1
- package/dist/esm/packages/taco/src/hooks/useTaco.js +9 -0
- package/dist/esm/packages/taco/src/hooks/useTaco.js.map +1 -0
- package/dist/esm/packages/taco/src/index.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Header/Header.js +1 -0
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Header/Header.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/Toolbar.js +6 -4
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +9 -5
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTablePrinting.js +18 -21
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTablePrinting.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js +2 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSettingsListener.js +57 -9
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSettingsListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +7 -5
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableSettingsPreloader.js +44 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableSettingsPreloader.js.map +1 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/settings.js +3 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/settings.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +5 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
- package/dist/hooks/useTaco.d.ts +1 -0
- package/dist/index.css +76 -5
- package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +2 -2
- package/dist/primitives/Table/Core/useTable.d.ts +4 -4
- package/dist/primitives/Table/types.d.ts +16 -6
- package/dist/primitives/Table/useTableManager/features/useTablePrinting.d.ts +2 -8
- package/dist/primitives/Table/useTableManager/features/useTableRowActive.d.ts +2 -2
- package/dist/primitives/Table/useTableManager/listeners/useTableSettingsListener.d.ts +2 -2
- package/dist/primitives/Table/useTableManager/useTableSettingsPreloader.d.ts +3 -0
- package/dist/primitives/Table/useTableManager/util/settings.d.ts +2 -0
- package/dist/taco.cjs.development.js +328 -272
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +3 -3
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js +0 -44
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js.map +0 -1
- package/dist/esm/packages/taco/src/hooks/useTacoSettings.js +0 -9
- package/dist/esm/packages/taco/src/hooks/useTacoSettings.js.map +0 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSettings.js +0 -69
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSettings.js.map +0 -1
- package/dist/hooks/useLocalStorage.d.ts +0 -2
- package/dist/hooks/useTacoSettings.d.ts +0 -1
- package/dist/primitives/Table/useTableManager/features/useTableSettings.d.ts +0 -3
@@ -1,4 +1,5 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
+
import { getSettings } from '../../useTableManager/util/settings.js';
|
2
3
|
import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
|
3
4
|
import { ROW_HEIGHT_ESTIMATES } from '../util/rows.js';
|
4
5
|
import { Row } from '../components/Row/Row.js';
|
@@ -84,11 +85,14 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
|
|
84
85
|
const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, startValue !== null && startValue !== void 0 ? startValue : 0), Math.max(0, totalSize - ((_virtualItems$end = (_virtualItems = virtualItems[virtualItems.length - 1]) === null || _virtualItems === void 0 ? void 0 : _virtualItems.end) !== null && _virtualItems$end !== void 0 ? _virtualItems$end : 0))] : [0, 0];
|
85
86
|
// ensure default active rows are scrolled to
|
86
87
|
React__default.useEffect(() => {
|
87
|
-
if (defaultRowActiveIndex) {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
if (defaultRowActiveIndex !== undefined) {
|
89
|
+
const index = typeof defaultRowActiveIndex === 'function' ? defaultRowActiveIndex(getSettings(table)) : defaultRowActiveIndex;
|
90
|
+
if (index !== undefined) {
|
91
|
+
scrollToIndex(index, {
|
92
|
+
align: 'center',
|
93
|
+
behavior: 'auto'
|
94
|
+
});
|
95
|
+
}
|
92
96
|
}
|
93
97
|
}, []);
|
94
98
|
// rendered output
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableRenderer.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import React, { CSSProperties } from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta, Row as ReactTableRow } from '@tanstack/react-table';\nimport {\n useVirtualizer,\n defaultRangeExtractor,\n ScrollToOptions as ReactVirtualScrollToOptions,\n Range,\n} from '@tanstack/react-virtual';\nimport { ROW_HEIGHT_ESTIMATES } from '../util/rows';\nimport { Row } from '../components/Row/Row';\nimport { useTableRenderers, useTableRenderOptions } from '../types';\nimport { TableRef } from '../../types';\nimport { SkeletonRow } from '../components/Row/BuiltIns/SkeletonRow';\n\n// scroll padding end is designed to always show half of the next row\nfunction getScrollPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n let offset = 2;\n\n if (tableMeta.footer.isEnabled) {\n offset += 1;\n }\n\n if (table.getHeaderGroups().length > 1) {\n offset += table.getHeaderGroups().length - 1;\n }\n\n let height = ROW_HEIGHT_ESTIMATES.medium * offset;\n\n const bottomRows = table.getBottomRows();\n\n if (bottomRows.length) {\n // 1.4 offsets for half rows and also accounts for increased row heights (which is likely in pinned rows)\n height += ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] * 1.4 * bottomRows.length;\n }\n\n return height;\n}\n\n// scroll padding end is designed to always show half of the next row\nfunction getPaddingEndOffset<TType = unknown>(table: ReactTable<TType>, options?: useTableRenderOptions) {\n const bottomRows = table.getBottomRows() ?? [];\n return ROW_HEIGHT_ESTIMATES.medium * (options?.virtualiserPaddingEndOffset ?? 1) * bottomRows.length;\n}\n\n// A higher number ensure less scroll jumping for dynamic row heights, but too high can reduce performance. 8 worked well\nconst OVERSCAN_ROW_COUNT = 8;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n length: number,\n defaultRowActiveIndex?: number | undefined,\n options?: useTableRenderOptions\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const isTableRowGrouped = !!table.getState().grouping?.length;\n const rows = table.getCenterRows() ?? [];\n\n // row groups\n const rangeExtractor = useRowGroupVirtualisation<TType>(table);\n\n // account for thead and tfoot in the scroll area - both are always medium row height\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n\n const count = tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2 ? length : rows.length;\n\n const virtualiser = useVirtualizer({\n count,\n estimateSize: () => {\n return tableMeta.rowHeight.height ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] : ROW_HEIGHT_ESTIMATES.medium;\n },\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? count : OVERSCAN_ROW_COUNT,\n rangeExtractor,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: getScrollPaddingEndOffset(table),\n paddingEnd: getPaddingEndOffset(table, options),\n });\n\n React.useEffect(() => {\n virtualiser.measure();\n }, [table.getState().expanded]);\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === count - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, count]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;\n\n const startValue = isTableRowGrouped\n ? virtualItems[paddingStartIndex]?.start - virtualItems[paddingStartIndex]?.size\n : virtualItems[paddingStartIndex]?.start;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems[virtualItems.length - 1]?.end ?? 0))]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (JSX.Element | null)[] | null = null;\n\n // bottom rows aren't virtualised (they're sticky) but we need to set the height\n if (count || table.getBottomRows().length) {\n style = {\n height: totalSize,\n paddingBottom: isNaN(paddingBottom) ? 0 : paddingBottom,\n paddingTop: isNaN(paddingTop) ? 0 : paddingTop,\n };\n }\n\n // only render non sticky rows\n if (count) {\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n let row: ReactTableRow<TType> | undefined;\n\n if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {\n const currentPageIndex =\n (Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize) /\n tableMeta.server.pageSize;\n const pagePosition = tableMeta.server.pages?.indexOf(currentPageIndex) ?? -1;\n\n if (pagePosition > -1) {\n // \"flatten\" row indexes down into the dataloader2 dataset size\n // for example, with a page size of 100...\n // row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)\n const fakeIndex = pagePosition * tableMeta.server.pageSize + (virtualRow.index % tableMeta.server.pageSize);\n row = rows[fakeIndex];\n }\n } else {\n row = rows[virtualRow.index];\n }\n\n if (!row?.original) {\n return (\n <SkeletonRow\n key={virtualRow.index}\n index={virtualRow.index}\n scrollDirection={virtualiser.scrollDirection ?? undefined}\n table={table}\n />\n );\n }\n\n const measureRow = (rowHeight: number) => {\n virtualiser.resizeItem(virtualRow, rowHeight);\n };\n\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n scrollDirection={virtualiser.scrollDirection ?? undefined}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index);\n }\n });\n }\n\n return indexes;\n }, [rows]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n (range: Range) => {\n const activeRowGroupIndex =\n [...rowGroupIndexes].reverse().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n const next = new Set([activeRowGroupIndex, ...defaultRangeExtractor(range)]);\n return [...next].sort((a, b) => a - b);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["getScrollPaddingEndOffset","table","tableMeta","options","meta","offset","footer","isEnabled","getHeaderGroups","length","height","ROW_HEIGHT_ESTIMATES","medium","bottomRows","getBottomRows","rowHeight","getPaddingEndOffset","_table$getBottomRows","_options$virtualiserP","virtualiserPaddingEndOffset","OVERSCAN_ROW_COUNT","useTableRenderer","renderers","tableRef","defaultRowActiveIndex","isTableRowGrouped","_table$getState$group","getState","grouping","rows","_table$getCenterRows","getCenterRows","rangeExtractor","useRowGroupVirtualisation","scrollPaddingStart","count","server","_experimentalDataLoader2","virtualiser","useVirtualizer","estimateSize","getScrollElement","current","overscan","printing","isPrinting","scrollPaddingEnd","paddingEnd","React","useEffect","measure","expanded","totalSize","getTotalSize","virtualItems","getVirtualItems","scrollToIndex","useCallback","index","align","behavior","notSmooth","scrollToOffset","scrollTop","scrollHeight","paddingStartIndex","startValue","_virtualItems$padding","start","_virtualItems$padding2","size","_virtualItems$padding3","paddingTop","paddingBottom","Math","max","_virtualItems$end","_virtualItems","end","style","content","isNaN","map","virtualRow","row","_tableMeta$server$pag","_tableMeta$server$pag2","currentPageIndex","floor","pageSize","pagePosition","pages","indexOf","fakeIndex","_row","original","_virtualiser$scrollDi","SkeletonRow","key","scrollDirection","undefined","measureRow","resizeItem","Row","id","_virtualiser$scrollDi2","renderer","cellRenderer","cell","getRowModel","isTableGrouped","rowGroupIndexes","useMemo","indexes","forEach","getIsGrouped","push","range","activeRowGroupIndex","_reverse$find","reverse","find","startIndex","next","Set","defaultRangeExtractor","sort","a","b"],"mappings":";;;;;;AAcA;AACA,SAASA,yBAAyBA,CAAkBC,KAAwB;EACxE,MAAMC,SAAS,GAAGD,KAAK,CAACE,OAAO,CAACC,IAA6B;EAC7D,IAAIC,MAAM,GAAG,CAAC;EAEd,IAAIH,SAAS,CAACI,MAAM,CAACC,SAAS,EAAE;IAC5BF,MAAM,IAAI,CAAC;;EAGf,IAAIJ,KAAK,CAACO,eAAe,EAAE,CAACC,MAAM,GAAG,CAAC,EAAE;IACpCJ,MAAM,IAAIJ,KAAK,CAACO,eAAe,EAAE,CAACC,MAAM,GAAG,CAAC;;EAGhD,IAAIC,MAAM,GAAGC,oBAAoB,CAACC,MAAM,GAAGP,MAAM;EAEjD,MAAMQ,UAAU,GAAGZ,KAAK,CAACa,aAAa,EAAE;EAExC,IAAID,UAAU,CAACJ,MAAM,EAAE;;IAEnBC,MAAM,IAAIC,oBAAoB,CAACT,SAAS,CAACa,SAAS,CAACL,MAAM,CAAC,GAAG,GAAG,GAAGG,UAAU,CAACJ,MAAM;;EAGxF,OAAOC,MAAM;AACjB;AAEA;AACA,SAASM,mBAAmBA,CAAkBf,KAAwB,EAAEE,OAA+B;;EACnG,MAAMU,UAAU,IAAAI,oBAAA,GAAGhB,KAAK,CAACa,aAAa,EAAE,cAAAG,oBAAA,cAAAA,oBAAA,GAAI,EAAE;EAC9C,OAAON,oBAAoB,CAACC,MAAM,KAAAM,qBAAA,GAAIf,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEgB,2BAA2B,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,CAAC,CAAC,GAAGL,UAAU,CAACJ,MAAM;AACxG;AAEA;AACA,MAAMW,kBAAkB,GAAG,CAAC;SAEZC,gBAAgBA,CAC5BC,SAAmC,EACnCrB,KAAwB,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e,CAAC,CAAC,CAAC;IAEjG,MAAMY,IAAI,GAAG,IAAIC,GAAG,CAAC,CAACN,mBAAmB,EAAE,GAAGO,qBAAqB,CAACR,KAAK,CAAC,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAGM,IAAI,CAAC,CAACG,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,GAAGC,CAAC,CAAC;GACzC,EACD,CAACjB,eAAe,CAAC,CACpB;EAED,OAAOD,cAAc,GAAG9E,cAAc,GAAGoE,SAAS;AACtD;;;;"}
|
1
|
+
{"version":3,"file":"useTableRenderer.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import React, { CSSProperties } from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta, Row as ReactTableRow } from '@tanstack/react-table';\nimport {\n useVirtualizer,\n defaultRangeExtractor,\n ScrollToOptions as ReactVirtualScrollToOptions,\n Range,\n} from '@tanstack/react-virtual';\nimport { ROW_HEIGHT_ESTIMATES } from '../util/rows';\nimport { Row } from '../components/Row/Row';\nimport { useTableRenderers, useTableRenderOptions } from '../types';\nimport { TableRef, TableDefaultRowActiveIndex } from '../../types';\nimport { SkeletonRow } from '../components/Row/BuiltIns/SkeletonRow';\nimport { getSettings } from '../../useTableManager/util/settings';\n\n// scroll padding end is designed to always show half of the next row\nfunction getScrollPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n let offset = 2;\n\n if (tableMeta.footer.isEnabled) {\n offset += 1;\n }\n\n if (table.getHeaderGroups().length > 1) {\n offset += table.getHeaderGroups().length - 1;\n }\n\n let height = ROW_HEIGHT_ESTIMATES.medium * offset;\n\n const bottomRows = table.getBottomRows();\n\n if (bottomRows.length) {\n // 1.4 offsets for half rows and also accounts for increased row heights (which is likely in pinned rows)\n height += ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] * 1.4 * bottomRows.length;\n }\n\n return height;\n}\n\n// scroll padding end is designed to always show half of the next row\nfunction getPaddingEndOffset<TType = unknown>(table: ReactTable<TType>, options?: useTableRenderOptions) {\n const bottomRows = table.getBottomRows() ?? [];\n return ROW_HEIGHT_ESTIMATES.medium * (options?.virtualiserPaddingEndOffset ?? 1) * bottomRows.length;\n}\n\n// A higher number ensure less scroll jumping for dynamic row heights, but too high can reduce performance. 8 worked well\nconst OVERSCAN_ROW_COUNT = 8;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n length: number,\n defaultRowActiveIndex?: TableDefaultRowActiveIndex | undefined,\n options?: useTableRenderOptions\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const isTableRowGrouped = !!table.getState().grouping?.length;\n const rows = table.getCenterRows() ?? [];\n\n // row groups\n const rangeExtractor = useRowGroupVirtualisation<TType>(table);\n\n // account for thead and tfoot in the scroll area - both are always medium row height\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n\n const count = tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2 ? length : rows.length;\n\n const virtualiser = useVirtualizer({\n count,\n estimateSize: () => {\n return tableMeta.rowHeight.height ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] : ROW_HEIGHT_ESTIMATES.medium;\n },\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? count : OVERSCAN_ROW_COUNT,\n rangeExtractor,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: getScrollPaddingEndOffset(table),\n paddingEnd: getPaddingEndOffset(table, options),\n });\n\n React.useEffect(() => {\n virtualiser.measure();\n }, [table.getState().expanded]);\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === count - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, count]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;\n\n const startValue = isTableRowGrouped\n ? virtualItems[paddingStartIndex]?.start - virtualItems[paddingStartIndex]?.size\n : virtualItems[paddingStartIndex]?.start;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems[virtualItems.length - 1]?.end ?? 0))]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex !== undefined) {\n const index =\n typeof defaultRowActiveIndex === 'function' ? defaultRowActiveIndex(getSettings(table)) : defaultRowActiveIndex;\n\n if (index !== undefined) {\n scrollToIndex(index, { align: 'center', behavior: 'auto' });\n }\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (JSX.Element | null)[] | null = null;\n\n // bottom rows aren't virtualised (they're sticky) but we need to set the height\n if (count || table.getBottomRows().length) {\n style = {\n height: totalSize,\n paddingBottom: isNaN(paddingBottom) ? 0 : paddingBottom,\n paddingTop: isNaN(paddingTop) ? 0 : paddingTop,\n };\n }\n\n // only render non sticky rows\n if (count) {\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n let row: ReactTableRow<TType> | undefined;\n\n if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {\n const currentPageIndex =\n (Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize) /\n tableMeta.server.pageSize;\n const pagePosition = tableMeta.server.pages?.indexOf(currentPageIndex) ?? -1;\n\n if (pagePosition > -1) {\n // \"flatten\" row indexes down into the dataloader2 dataset size\n // for example, with a page size of 100...\n // row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)\n const fakeIndex = pagePosition * tableMeta.server.pageSize + (virtualRow.index % tableMeta.server.pageSize);\n row = rows[fakeIndex];\n }\n } else {\n row = rows[virtualRow.index];\n }\n\n if (!row?.original) {\n return (\n <SkeletonRow\n key={virtualRow.index}\n index={virtualRow.index}\n scrollDirection={virtualiser.scrollDirection ?? undefined}\n table={table}\n />\n );\n }\n\n const measureRow = (rowHeight: number) => {\n virtualiser.resizeItem(virtualRow, rowHeight);\n };\n\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n scrollDirection={virtualiser.scrollDirection ?? undefined}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index);\n }\n });\n }\n\n return indexes;\n }, [rows]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n (range: Range) => {\n const activeRowGroupIndex =\n [...rowGroupIndexes].reverse().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n const next = new Set([activeRowGroupIndex, ...defaultRangeExtractor(range)]);\n return [...next].sort((a, b) => a - b);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["getScrollPaddingEndOffset","table","tableMeta","options","meta","offset","footer","isEnabled","getHeaderGroups","length","height","ROW_HEIGHT_ESTIMATES","medium","bottomRows","getBottomRows","rowHeight","getPaddingEndOffset","_table$getBottomRows","_options$virtualiserP","virtualiserPaddingEndOffset","OVERSCAN_ROW_COUNT","useTableRenderer","renderers","tableRef","defaultRowActiveIndex","isTableRowGrouped","_table$getState$group","getState","grouping","rows","_table$getCenterRows","getCenterRows","rangeExtractor","useRowGroupVirtualisation","scrollPaddingStart","count","server","_experimentalDataLoader2","virtualiser","useVirtualizer","estimateSize","getScrollElement","current","overscan","printing","isPrinting","scrollPaddingEnd","paddingEnd","React","useEffect","measure","expanded","totalSize","getTotalSize","virtualItems","getVirtualItems","scrollToIndex","useCallback","index","align","behavior","notSmooth","scrollToOffset","scrollTop","scrollHeight","paddingStartIndex","startValue","_virtualItems$padding","start","_virtualItems$padding2","size","_virtualItems$padding3","paddingTop","paddingBottom","Math","max","_virtualItems$end","_virtualItems","end","undefined","getSettings","style","content","isNaN","map","virtualRow","row","_tableMeta$server$pag","_tableMeta$server$pag2","currentPageIndex","floor","pageSize","pagePosition","pages","indexOf","fakeIndex","_row","original","_virtualiser$scrollDi","SkeletonRow","key","scrollDirection","measureRow","resizeItem","Row","id","_virtualiser$scrollDi2","renderer","cellRenderer","cell","getRowModel","isTableGrouped","rowGroupIndexes","useMemo","indexes","forEach","getIsGrouped","push","range","activeRowGroupIndex","_reverse$find","reverse","find","startIndex","next","Set","defaultRangeExtractor","sort","a","b"],"mappings":";;;;;;;AAeA;AACA,SAASA,yBAAyBA,CAAkBC,KAAwB;EACxE,MAAMC,SAAS,GAAGD,KAAK,CAACE,OAAO,CAACC,IAA6B;EAC7D,IAAIC,MAAM,GAAG,CAAC;EAEd,IAAIH,SAAS,CAACI,MAAM,CAACC,SAAS,EAAE;IAC5BF,MAAM,IAAI,CAAC;;EAGf,IAAIJ,KAAK,CAACO,eAAe,EAAE,CAACC,MAAM,G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D,CAAC,GAAGC,CAAC,CAAC;GACzC,EACD,CAACjB,eAAe,CAAC,CACpB;EAED,OAAOD,cAAc,GAAG/E,cAAc,GAAG+C,SAAS;AACtD;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTable.js","sources":["../../../../../../../../src/primitives/Table/Core/useTable.ts"],"sourcesContent":["import { Table as ReactTable, TableMeta as ReactTableMeta, TableState as ReactTableState } from '@tanstack/react-table';\nimport { ScrollToOptions as ReactVirtualScrollToOptions } from '@tanstack/react-virtual';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { TableCustomSettingsRenderer, TableEmptyStateRenderer, TableProps } from '../types';\nimport { useTableManager } from '../useTableManager/useTableManager';\nimport { useTableStyle } from './features/useTableStyle';\nimport { useTableGlobalShortcuts } from './features/useTableGlobalShortcuts';\nimport { useTableRef } from './features/useTableRef';\nimport { useTableRenderer } from './features/useTableRenderer';\nimport { useTableRowActiveListener } from './listeners/useTableRowActiveListener';\nimport { TableRef } from '../types';\nimport { useTableRenderers, useTableRenderOptions } from './types';\nimport { renderer as rowActions } from './components/Columns/Internal/Actions';\nimport { renderer as rowDrag } from './components/Columns/Internal/Drag';\nimport { renderer as rowExpansion } from './components/Columns/Internal/Expansion';\nimport { renderer as rowSelection } from './components/Columns/Internal/Selection';\nimport { useTableManagerInternalColumns } from '../useTableManager/types';\n\nconst INTERNAL_RENDERERS = {\n rowActions,\n rowDrag,\n rowExpansion,\n rowSelection,\n};\n\nexport type useTableReturnValue<TType = unknown> = {\n id: string;\n instance: ReactTable<TType>;\n meta: ReactTableMeta<TType>;\n props: {\n customSettings: TableCustomSettingsRenderer | undefined;\n emptyState: TableEmptyStateRenderer | undefined;\n toolbarLeft:
|
1
|
+
{"version":3,"file":"useTable.js","sources":["../../../../../../../../src/primitives/Table/Core/useTable.ts"],"sourcesContent":["import { Table as ReactTable, TableMeta as ReactTableMeta, TableState as ReactTableState } from '@tanstack/react-table';\nimport { ScrollToOptions as ReactVirtualScrollToOptions } from '@tanstack/react-virtual';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { TableCustomSettingsRenderer, TableEmptyStateRenderer, TableProps, TableToolbarRenderer } from '../types';\nimport { useTableManager } from '../useTableManager/useTableManager';\nimport { useTableStyle } from './features/useTableStyle';\nimport { useTableGlobalShortcuts } from './features/useTableGlobalShortcuts';\nimport { useTableRef } from './features/useTableRef';\nimport { useTableRenderer } from './features/useTableRenderer';\nimport { useTableRowActiveListener } from './listeners/useTableRowActiveListener';\nimport { TableRef } from '../types';\nimport { useTableRenderers, useTableRenderOptions } from './types';\nimport { renderer as rowActions } from './components/Columns/Internal/Actions';\nimport { renderer as rowDrag } from './components/Columns/Internal/Drag';\nimport { renderer as rowExpansion } from './components/Columns/Internal/Expansion';\nimport { renderer as rowSelection } from './components/Columns/Internal/Selection';\nimport { useTableManagerInternalColumns } from '../useTableManager/types';\n\nconst INTERNAL_RENDERERS = {\n rowActions,\n rowDrag,\n rowExpansion,\n rowSelection,\n};\n\nexport type useTableReturnValue<TType = unknown> = {\n id: string;\n instance: ReactTable<TType>;\n meta: ReactTableMeta<TType>;\n props: {\n customSettings: TableCustomSettingsRenderer | undefined;\n emptyState: TableEmptyStateRenderer | undefined;\n toolbarLeft: TableToolbarRenderer | undefined;\n toolbarPanel: TableToolbarRenderer | undefined;\n toolbarRight: TableToolbarRenderer | undefined;\n };\n ref: React.RefObject<TableRef>;\n renderer: {\n rows: (JSX.Element | null)[] | null;\n style: React.CSSProperties;\n scrollToIndex: (index: number, options?: ReactVirtualScrollToOptions) => void;\n };\n style: React.CSSProperties;\n stylesheet: string;\n state: ReactTableState;\n};\n\nexport function useTable<TType = unknown, TMeta = {}>(\n props: TableProps<TType>,\n externalRef: React.Ref<TableRef>,\n renderers: useTableRenderers<TType>,\n meta?: Partial<ReactTableMeta<TType>> & TMeta,\n options?: useTableRenderOptions\n): useTableReturnValue<TType> {\n // create a ref and merge with the consumer's ref\n const ref = useMergedRef<TableRef>(externalRef);\n // configure the table\n const manager = useTableManager<TType>(props, meta, INTERNAL_RENDERERS as useTableManagerInternalColumns<TType>);\n\n // configure the virtualised renderer\n const renderer = useTableRenderer<TType>(\n renderers,\n manager.instance,\n ref,\n manager.meta.length,\n props.defaultRowActiveIndex,\n options\n );\n // configure dynamic styling\n const { style, stylesheet } = useTableStyle(manager.id, manager.instance);\n // configure global keyboard shortcuts\n useTableGlobalShortcuts(manager.instance, ref, renderer.scrollToIndex);\n // augment the ref with some helper functions\n useTableRef(manager.instance, ref);\n\n // listeners - they are here and not in useTableManager because they rely on the dom and the table ref\n useTableRowActiveListener(manager.instance, ref);\n\n return {\n ...manager,\n props: {\n customSettings: props.customSettings,\n emptyState: props.emptyState,\n toolbarLeft: props.toolbarLeft,\n toolbarPanel: props.toolbarPanel,\n toolbarRight: props.toolbarRight,\n },\n renderer,\n style,\n stylesheet,\n ref,\n };\n}\n"],"names":["INTERNAL_RENDERERS","rowActions","rowDrag","rowExpansion","rowSelection","useTable","props","externalRef","renderers","meta","options","ref","useMergedRef","manager","useTableManager","renderer","useTableRenderer","instance","length","defaultRowActiveIndex","style","stylesheet","useTableStyle","id","useTableGlobalShortcuts","scrollToIndex","useTableRef","useTableRowActiveListener","customSettings","emptyState","toolbarLeft","toolbarPanel","toolbarRight"],"mappings":";;;;;;;;;;;;AAkBA,MAAMA,kBAAkB,GAAG;cACvBC,QAAU;WACVC,UAAO;gBACPC,UAAY;gBACZC;CACH;SAwBeC,QAAQA,CACpBC,KAAwB,EACxBC,WAAgC,EAChCC,SAAmC,EACnCC,IAA6C,EAC7CC,OAA+B;;EAG/B,MAAMC,GAAG,GAAGC,YAAY,CAAWL,WAAW,CAAC;;EAE/C,MAAMM,OAAO,GAAGC,eAAe,CAAQR,KAAK,EAAEG,IAAI,EAAET,kBAA2D,CAAC;;EAGhH,MAAMe,QAAQ,GAAGC,gBAAgB,CAC7BR,SAAS,EACTK,OAAO,CAACI,QAAQ,EAChBN,GAAG,EACHE,OAAO,CAACJ,IAAI,CAACS,MAAM,EACnBZ,KAAK,CAACa,qBAAqB,EAC3BT,OAAO,CACV;;EAED,MAAM;IAAEU,KAAK;IAAEC;GAAY,GAAGC,aAAa,CAACT,OAAO,CAACU,EAAE,EAAEV,OAAO,CAACI,QAAQ,CAAC;;EAEzEO,uBAAuB,CAACX,OAAO,CAACI,QAAQ,EAAEN,GAAG,EAAEI,QAAQ,CAACU,aAAa,CAAC;;EAEtEC,WAAW,CAACb,OAAO,CAACI,QAAQ,EAAEN,GAAG,CAAC;;EAGlCgB,yBAAyB,CAACd,OAAO,CAACI,QAAQ,EAAEN,GAAG,CAAC;EAEhD,OAAO;IACH,GAAGE,OAAO;IACVP,KAAK,EAAE;MACHsB,cAAc,EAAEtB,KAAK,CAACsB,cAAc;MACpCC,UAAU,EAAEvB,KAAK,CAACuB,UAAU;MAC5BC,WAAW,EAAExB,KAAK,CAACwB,WAAW;MAC9BC,YAAY,EAAEzB,KAAK,CAACyB,YAAY;MAChCC,YAAY,EAAE1B,KAAK,CAAC0B;KACvB;IACDjB,QAAQ;IACRK,KAAK;IACLC,UAAU;IACVV;GACH;AACL;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../../../../src/primitives/Table/types.ts"],"sourcesContent":["import {\n ColumnFilter as ReactTableColumnFilter,\n ColumnFiltersState as ReactTableColumnFilterState,\n ColumnOrderState as ReactTableColumnOrderState,\n ColumnPinningState as ReactTableColumnPinningState,\n ColumnSort as ReactTableColumnSort,\n ColumnSizingState as ReactTableColumnSizingState,\n VisibilityState as ReactTableColumnVisibilityState,\n SortingState as ReactTableSortingState,\n BuiltInAggregationFn as ReactTableBuiltInAggregationFn,\n BuiltInSortingFn as ReactTableBuiltInSortingFn,\n} from '@tanstack/react-table';\nimport { FontSize, FontSizes, StringWithAutocompleteOptions, ValueOf } from '../../types';\nimport { MenuItemProps } from '../../components/Menu/components/Item';\n\nexport type TableRef = HTMLTableElement & {\n instance: {\n resetFiltering: () => void;\n resetRowExpansion: () => void;\n resetRowSelection: () => void;\n resetSorting: () => void;\n };\n};\n\n// filtering\nexport enum TableFilterComparator {\n Contains,\n DoesNotContain,\n IsEqualTo,\n IsNotEqualTo,\n IsGreaterThan,\n IsLessThan,\n IsBetween,\n IsEmpty,\n IsNotEmpty,\n IsLessThanOrEqualTo,\n IsGreaterThanOrEqualTo,\n HasAnyOf,\n HasAllOf,\n HasNoneOf,\n IsOneOf,\n IsNoneOf,\n}\nexport type TableFilterValue = {\n comparator: TableFilterComparator;\n value: any;\n};\nexport type TableFilter = {\n id: string;\n value: TableFilterValue;\n};\n\n// columns\nexport type TableColumnAlignment = 'left' | 'center' | 'right';\nexport type TableColumnClassNameHandler<TType = unknown> = string | ((row: TType) => string | undefined);\nexport type TableColumnDataType =\n // base\n | 'text'\n | 'number'\n | 'datetime'\n | 'boolean'\n // advanced\n | 'amount';\nexport type TableColumnFilter = ReactTableColumnFilter;\nexport type TableColumnMenu = ((columnId: string) => React.ReactNode | null)[];\nexport type TableColumnRenderer<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererAggregate<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererControl<TType = unknown> =\n | ((props: TableColumnRendererControlProps, row?: TType, filterState?: TableFilter[]) => JSX.Element)\n | 'datepicker'\n | 'input'\n | 'switch'\n | 'checkbox'\n | 'textarea';\nexport type TableColumnRendererControlProps = {\n className?: string;\n disabled?: boolean;\n fontSize?: FontSize;\n invalid?: boolean;\n onBlur?: (value: any) => void;\n onKeyDown?: React.KeyboardEventHandler;\n onFocus?: React.FocusEventHandler;\n readOnly?: boolean;\n ref: React.RefObject<HTMLElement> | ((instance: HTMLElement | null | undefined) => void);\n setValue: (value: any) => void;\n value: any;\n};\nexport type TableColumnRendererHeader = string | JSX.Element;\nexport type TableColumnRendererFooter<TType> = (rows: TType[]) => JSX.Element | string | number | null;\nexport type TableColumnSort = ReactTableColumnSort;\nexport type TableColumnSortDirection = 'asc' | 'desc';\nexport type TableColumnSortFn<TType = unknown> =\n | ((rowA: TType, rowB: TType, columnId: string) => -1 | 0 | 1)\n | ReactTableBuiltInSortingFn\n | 'auto';\nexport type TableColumnWidth = number | 'grow';\n\n// rows\nexport type TableRowActionRenderer<TType = unknown> = (\n row: TType,\n internalRowId: string,\n cleanup: (rowId: string) => void\n) => JSX.Element | null;\nexport type TableRowActionGroupRenderer<TType = unknown> = (rows: TType[]) => JSX.Element | null;\nexport type TableRowClickHandler<TType = unknown> = (row: TType) => void;\nexport type TableRowDragHandler<TType = unknown> = (\n rows: TType[],\n showPlaceholder: (string) => void,\n setDataTransfer: (data: string) => void\n) => void;\nexport type TableRowDropHandler<TType = unknown> = (event: React.DragEvent, row: TType) => void;\nexport type TableRowGotoHandler = (\n column: string,\n query: string,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<number>;\nexport type TableRowHeight = 'short' | 'medium' | 'tall' | 'extra-tall';\nexport type TableRowSelectHandler<TType = unknown> = (rows: TType[], ids: string[]) => void;\nexport type TableRowWithMetaData<TType = unknown> = TType & {\n _meta?: {\n layout?: 'heading' | 'summary' | 'item';\n };\n};\n\n// shortcuts\nexport type TableShortcutHandlerFn<TType = unknown> = (row: TType) => void;\nexport type TableShortcutHandlerObject<TType = unknown> = {\n handler: TableShortcutHandlerFn<TType>;\n meta?: boolean;\n shift?: boolean;\n};\n\n// table\nexport type TableSortHandler = (sorting: TableColumnSort[]) => Promise<void>;\nexport type TableFilterHandler = (filters: TableColumnFilter[], hiddenColumns: string[]) => Promise<void>;\nexport type TableSearchHandler = (search: string | undefined, hiddenColumns: string[]) => Promise<void>;\nexport type TableFontSize = keyof typeof FontSizes;\nexport type TablePreset = 'complex' | 'list' | 'simple';\nexport type TableRowExpansionRenderer<TType = unknown> = (row: TType) => (() => JSX.Element) | null;\nexport type TableScrollToIndexHandler = (index: number, options?: { align: 'start' | 'center' | 'end' | 'auto' }) => void;\nexport type TableServerLoadPageHandler = (\n pageIndex: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n hiddenColumns: string[],\n search: string | undefined\n) => Promise<void>;\nexport type TableServerLoadAllHandler = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n hiddenColumns: string[],\n search: string | undefined\n) => Promise<void>;\nexport type TableSettingsHandler = (settings: TableSettings) => void | Promise<void>;\nexport type TableShortcuts<TType = unknown> = Record<string, TableShortcutHandlerFn<TType> | TableShortcutHandlerObject<TType>>;\nexport type TableCustomSettingsRenderer = (props: TableSettings) => React.ReactElement<MenuItemProps>[];\nexport type TableEmptyStateReason = 'empty' | 'filtering' | 'searching';\nexport type TableEmptyStateRenderer = (props: { reason: TableEmptyStateReason }) => JSX.Element | null;\nexport type TableEvent = 'editing-mode';\nexport type TableEventHandler = (event: TableEvent, data?: object) => void;\n\n// settings\nexport type TableSettings = {\n columnFilters?: ReactTableColumnFilterState;\n columnOrder?: ReactTableColumnOrderState;\n columnPinning?: ReactTableColumnPinningState;\n columnSizing?: ReactTableColumnSizingState;\n columnVisibility?: ReactTableColumnVisibilityState;\n excludeUnmatchedRecordsInSearch?: boolean;\n fontSize?: TableFontSize;\n rowHeight?: TableRowHeight;\n searchQuery?: string;\n sorting?: ReactTableSortingState;\n};\nexport type TableEnableSettingsOptions = {\n columnOrder: boolean;\n columnPinning: boolean;\n columnSizing: boolean;\n columnVisibility: boolean;\n excludeUnmatchedRecordsInSearch: boolean;\n fontSize: boolean;\n grouping: boolean;\n rowHeight: boolean;\n sorting: boolean;\n};\n\n// props\nexport type TableConditionalRowProp<TType = unknown> = boolean | ((row: TType) => boolean);\nexport type TableFeatureProps<TType = unknown> = {\n // react-table built-in\n enableFiltering?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableColumnFreezing?: boolean;\n enableColumnHiding?: boolean;\n enableColumnResizing?: boolean;\n enableRowExpansion?: boolean;\n enableRowExpansionAll?: boolean;\n enableRowSelection?: TableConditionalRowProp<TType>;\n\n // custom -- common between all table types\n enableColumnOrdering?: boolean;\n enableFontSize?: boolean;\n enableFooter?: boolean;\n enablePrinting?: boolean;\n enableRowActions?: boolean;\n enableRowActive?: boolean;\n enableRowClick?: TableConditionalRowProp<TType>;\n enableRowDrag?: boolean;\n enableRowDrop?: boolean;\n enableRowGoto?: boolean;\n enableRowHeight?: boolean;\n enableSaveSettings?: boolean | Partial<TableEnableSettingsOptions>;\n};\n\nexport type TableChild = JSX.Element | boolean | null | undefined;\n\nexport type TableCommonProps<TType = unknown> = TableFeatureProps<TType> & {\n children: TableChild | TableChild[];\n data: TType[];\n id: string;\n\n // misc\n customSettings?: TableCustomSettingsRenderer;\n defaultColumnFreezingIndex?: number;\n defaultRowActiveIndex?: number;\n defaultRowGroupColumnId?: keyof TType;\n defaultSettings?: TableSettings;\n emptyState?: TableEmptyStateRenderer;\n preset?: TablePreset;\n rowActions?: TableRowActionRenderer<TType>[];\n rowActionsForGroup?: TableRowActionGroupRenderer<TType>[];\n rowActionsLength?: number;\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>;\n rowIdentityAccessor?: keyof TType;\n shortcuts?: TableShortcuts<TType>;\n toolbarLeft?: JSX.Element;\n toolbarRight?: JSX.Element;\n toolbarPanel?: JSX.Element;\n\n // handlers\n onEvent?: TableEventHandler;\n onRowClick?: TableRowClickHandler<TType>;\n onRowDrag?: TableRowDragHandler<TType>;\n onRowDrop?: TableRowDropHandler<TType>;\n onRowGoto?: TableRowGotoHandler;\n onRowSelect?: TableRowSelectHandler<TType>;\n\n // state change handlers\n onChangeFilter?: TableFilterHandler;\n onChangeSearch?: TableSearchHandler;\n onChangeSettings?: TableSettingsHandler;\n onChangeSort?: TableSortHandler;\n};\n\nexport interface TableClientProps<TType = unknown> extends TableCommonProps<TType> {\n length?: never;\n loadAll?: never;\n loadPage?: never;\n pageSize?: never;\n pages?: never;\n\n // experimental\n _experimentalDataLoader2?: never;\n}\n\nexport interface TableServerProps<TType = unknown> extends TableCommonProps<TType> {\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n pageSize?: number;\n pages?: number[];\n\n // experimental\n _experimentalDataLoader2?: boolean;\n}\n\nexport type TableProps<TType = unknown> = TableClientProps<TType> | TableServerProps<TType>;\n\nexport type TableColumnProps<TType = unknown> = ValueOf<{\n [Key in keyof TType]: {\n accessor?: Key;\n id: StringWithAutocompleteOptions<Key>;\n // renderers\n renderer?: TableColumnRenderer<TType, TType[Key]>;\n /** Renderer to use if the cell is an aggregate cell and part of a grouped row */\n aggregate?: TableColumnRendererAggregate<TType, TType[Key]>;\n control?: TableColumnRendererControl<TType>;\n footer?: TableColumnRendererFooter<TType>;\n header: TableColumnRendererHeader;\n // options\n /** Aggregation function to be used when the column is part of a grouped row */\n aggregationFn?: 'auto' | ReactTableBuiltInAggregationFn;\n align?: TableColumnAlignment;\n className?: TableColumnClassNameHandler<TType>;\n dataType?: TableColumnDataType;\n defaultHidden?: boolean;\n defaultWidth?: TableColumnWidth;\n enableEditing?: boolean;\n enableFiltering?: boolean;\n enableGrouping?: boolean;\n enableHiding?: boolean;\n enableOrdering?: boolean;\n enablePrinting?: boolean;\n enableResizing?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableTruncate?: boolean;\n filters?: TableFilterComparator[];\n headerClassName?: string;\n menu?: TableColumnMenu;\n minWidth?: number;\n sort?: TableColumnSortDirection;\n sortFn?: TableColumnSortFn<TType>;\n tooltip?: string;\n };\n}>;\n\nexport type TableGroupProps = {\n children: (JSX.Element | boolean | null | undefined)[];\n header: string;\n id: string;\n};\n\nexport type TableTexts = {\n columns: {\n actions: {\n tooltip: string;\n };\n drag: {\n tooltip: string;\n };\n expansion: {\n collapse: string;\n collapseAll: string;\n expand: string;\n expandAll: string;\n };\n menu: {\n editFilter: string;\n filter: string;\n freezeFirstColumn: string;\n freezeUptoColumn: string;\n gotoRow: string;\n hideColumn: string;\n unfreezeColumns: string;\n sorting: string;\n sortingOrder: {\n ascending: string;\n descending: string;\n unsorted: string;\n };\n };\n resize: {\n tooltip: string;\n };\n select: {\n deselect: string;\n deselectAll: string;\n select: string;\n selectAll: string;\n };\n };\n columnSettings: {\n button: string;\n noResults: string;\n search: string;\n tooltip: string;\n };\n filters: {\n button: string;\n buttons: {\n addFilter: string;\n clearFilters: string;\n cancel: string;\n clear: string;\n apply: string;\n };\n comparators: {\n contains: string;\n doesNotContain: string;\n isEqualTo: string;\n isNotEqualTo: string;\n isGreaterThan: string;\n isLessThan: string;\n isBetween: string;\n isOneOf: string;\n isNoneOf: string;\n isEmpty: string;\n isNotEmpty: string;\n isBefore: string;\n isAfter: string;\n isLessThanOrEqualTo: string;\n isGreaterThanOrEqualTo: string;\n isOnOrBefore: string;\n isOnOrAfter: string;\n hasAnyOf: string;\n hasAllOf: string;\n hasNoneOf: string;\n };\n conditions: {\n and: string;\n where: string;\n };\n emptyFilter: {\n condition: string;\n value: string;\n };\n hiddenColumn: string;\n hiddenGroupedColumn: string;\n tooltip: string;\n total: string;\n };\n fontSize: {\n tooltip: string;\n sizes: {\n small: string;\n medium: string;\n large: string;\n };\n };\n footer: {\n summary: {\n count: string;\n records: string;\n selected: string;\n };\n };\n print: {\n error: string;\n loading: string;\n tooltip: string;\n warningDialog: {\n title: string;\n description: string;\n checkboxVisibilityLabel: string;\n cancelButtonText: string;\n printButtonText: string;\n };\n settingsDialog: {\n title: string;\n size: string;\n sizeA5: string;\n sizeA4: string;\n sizeA3: string;\n sizeLetter: string;\n sizeLegal: string;\n orientation: string;\n orientationLandscape: string;\n orientationPortrait: string;\n rows: string;\n rowsAll: string;\n rowsSelected: string;\n layout: string;\n layoutSplitGroups: string;\n };\n };\n rowHeight: {\n tooltip: string;\n sizes: {\n short: string;\n medium: string;\n tall: string;\n extraTall: string;\n };\n };\n search: {\n excludeUnmatchedResults: string;\n placeholder: string;\n };\n otherOptions: {\n tooltip: string;\n };\n};\n"],"names":["TableFilterComparator"],"mappings":"AAwBA;IACYA;AAAZ,WAAYA,qBAAqB;EAC7BA,yEAAQ;EACRA,qFAAc;EACdA,2EAAS;EACTA,iFAAY;EACZA,mFAAa;EACbA,6EAAU;EACVA,2EAAS;EACTA,uEAAO;EACPA,6EAAU;EACVA,+FAAmB;EACnBA,sGAAsB;EACtBA,0EAAQ;EACRA,0EAAQ;EACRA,4EAAS;EACTA,wEAAO;EACPA,0EAAQ;AACZ,CAAC,EAjBWA,qBAAqB,KAArBA,qBAAqB;;;;"}
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../../../../src/primitives/Table/types.ts"],"sourcesContent":["import {\n ColumnFilter as ReactTableColumnFilter,\n ColumnFiltersState as ReactTableColumnFilterState,\n ColumnOrderState as ReactTableColumnOrderState,\n ColumnPinningState as ReactTableColumnPinningState,\n ColumnSort as ReactTableColumnSort,\n ColumnSizingState as ReactTableColumnSizingState,\n VisibilityState as ReactTableColumnVisibilityState,\n SortingState as ReactTableSortingState,\n BuiltInAggregationFn as ReactTableBuiltInAggregationFn,\n BuiltInSortingFn as ReactTableBuiltInSortingFn,\n} from '@tanstack/react-table';\nimport { FontSize, FontSizes, StringWithAutocompleteOptions, ValueOf } from '../../types';\nimport { MenuItemProps } from '../../components/Menu/components/Item';\n\nexport type TableRef = HTMLTableElement & {\n instance: {\n resetFiltering: () => void;\n resetRowExpansion: () => void;\n resetRowSelection: () => void;\n resetSorting: () => void;\n };\n};\n\n// filtering\nexport enum TableFilterComparator {\n Contains,\n DoesNotContain,\n IsEqualTo,\n IsNotEqualTo,\n IsGreaterThan,\n IsLessThan,\n IsBetween,\n IsEmpty,\n IsNotEmpty,\n IsLessThanOrEqualTo,\n IsGreaterThanOrEqualTo,\n HasAnyOf,\n HasAllOf,\n HasNoneOf,\n IsOneOf,\n IsNoneOf,\n}\nexport type TableFilterValue = {\n comparator: TableFilterComparator;\n value: any;\n};\nexport type TableFilter = {\n id: string;\n value: TableFilterValue;\n};\n\n// columns\nexport type TableColumnAlignment = 'left' | 'center' | 'right';\nexport type TableColumnClassNameHandler<TType = unknown> = string | ((row: TType) => string | undefined);\nexport type TableColumnDataType =\n // base\n | 'text'\n | 'number'\n | 'datetime'\n | 'boolean'\n // advanced\n | 'amount';\nexport type TableColumnFilter = ReactTableColumnFilter;\nexport type TableColumnMenu = ((columnId: string) => React.ReactNode | null)[];\nexport type TableColumnRenderer<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererAggregate<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererControl<TType = unknown> =\n | ((props: TableColumnRendererControlProps, row?: TType, filterState?: TableFilter[]) => JSX.Element)\n | 'datepicker'\n | 'input'\n | 'switch'\n | 'checkbox'\n | 'textarea';\nexport type TableColumnRendererControlProps = {\n className?: string;\n disabled?: boolean;\n fontSize?: FontSize;\n invalid?: boolean;\n onBlur?: (value: any) => void;\n onKeyDown?: React.KeyboardEventHandler;\n onFocus?: React.FocusEventHandler;\n readOnly?: boolean;\n ref: React.RefObject<HTMLElement> | ((instance: HTMLElement | null | undefined) => void);\n setValue: (value: any) => void;\n value: any;\n};\nexport type TableColumnRendererHeader = string | JSX.Element;\nexport type TableColumnRendererFooter<TType> = (rows: TType[]) => JSX.Element | string | number | null;\nexport type TableColumnSort = ReactTableColumnSort;\nexport type TableColumnSortDirection = 'asc' | 'desc';\nexport type TableColumnSortFn<TType = unknown> =\n | ((rowA: TType, rowB: TType, columnId: string) => -1 | 0 | 1)\n | ReactTableBuiltInSortingFn\n | 'auto';\nexport type TableColumnWidth = number | 'grow';\n\n// rows\nexport type TableRowActionRenderer<TType = unknown> = (\n row: TType,\n internalRowId: string,\n cleanup: (rowId: string) => void\n) => JSX.Element | null;\nexport type TableRowActionGroupRenderer<TType = unknown> = (rows: TType[]) => JSX.Element | null;\nexport type TableRowClickHandler<TType = unknown> = (row: TType) => void;\nexport type TableRowDragHandler<TType = unknown> = (\n rows: TType[],\n showPlaceholder: (string) => void,\n setDataTransfer: (data: string) => void\n) => void;\nexport type TableRowDropHandler<TType = unknown> = (event: React.DragEvent, row: TType) => void;\nexport type TableRowGotoHandler = (\n column: string,\n query: string,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<number>;\nexport type TableRowHeight = 'short' | 'medium' | 'tall' | 'extra-tall';\nexport type TableRowSelectHandler<TType = unknown> = (rows: TType[], ids: string[]) => void;\nexport type TableRowWithMetaData<TType = unknown> = TType & {\n _meta?: {\n layout?: 'heading' | 'summary' | 'item';\n };\n};\n\n// shortcuts\nexport type TableShortcutHandlerFn<TType = unknown> = (row: TType) => void;\nexport type TableShortcutHandlerObject<TType = unknown> = {\n handler: TableShortcutHandlerFn<TType>;\n meta?: boolean;\n shift?: boolean;\n};\n\n// table\nexport type TableSortHandler = (sorting: TableColumnSort[]) => Promise<void>;\nexport type TableFilterHandler = (filters: TableColumnFilter[], hiddenColumns: string[]) => Promise<void>;\nexport type TableSearchHandler = (search: string | undefined, hiddenColumns: string[]) => Promise<void>;\nexport type TableFontSize = keyof typeof FontSizes;\nexport type TablePreset = 'complex' | 'list' | 'simple';\nexport type TableRowExpansionRenderer<TType = unknown> = (row: TType) => (() => JSX.Element) | null;\nexport type TableScrollToIndexHandler = (index: number, options?: { align: 'start' | 'center' | 'end' | 'auto' }) => void;\nexport type TableServerLoadPageHandler = (\n pageIndex: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n hiddenColumns: string[],\n search: string | undefined\n) => Promise<void>;\nexport type TableServerLoadAllHandler = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n hiddenColumns: string[],\n search: string | undefined\n) => Promise<void>;\nexport type TableSettingsHandler = (settings: TableSettings) => void | Promise<void>;\nexport type TableShortcuts<TType = unknown> = Record<string, TableShortcutHandlerFn<TType> | TableShortcutHandlerObject<TType>>;\nexport type TableCustomSettingsRenderer = (props: TableSettings) => React.ReactElement<MenuItemProps>[];\nexport type TableEmptyStateReason = 'empty' | 'filtering' | 'searching';\nexport type TableEmptyStateRenderer = (props: { reason: TableEmptyStateReason }) => JSX.Element | null;\nexport type TableEvent = 'editing-mode';\nexport type TableEventHandler = (event: TableEvent, data?: object) => void;\n\nexport type TablePrintSettings = {\n allRows: boolean;\n orientation: 'portrait' | 'landscape';\n size: 'A3' | 'A4' | 'A5' | 'letter' | 'legal';\n splitGroups: boolean;\n};\n\n// settings\nexport type TableSettings = {\n columnFilters?: ReactTableColumnFilterState;\n columnOrder?: ReactTableColumnOrderState;\n columnPinning?: ReactTableColumnPinningState;\n columnSizing?: ReactTableColumnSizingState;\n columnVisibility?: ReactTableColumnVisibilityState;\n excludeUnmatchedRecordsInSearch?: boolean;\n fontSize?: TableFontSize;\n print?: TablePrintSettings;\n rowHeight?: TableRowHeight;\n searchQuery?: string;\n sorting?: ReactTableSortingState;\n};\n\nexport type TableEnableSettingsOptions = {\n columnOrder: boolean;\n columnPinning: boolean;\n columnSizing: boolean;\n columnVisibility: boolean;\n excludeUnmatchedRecordsInSearch: boolean;\n fontSize: boolean;\n grouping: boolean;\n rowHeight: boolean;\n sorting: boolean;\n};\n\n// props\nexport type TableConditionalRowProp<TType = unknown> = boolean | ((row: TType) => boolean);\nexport type TableFeatureProps<TType = unknown> = {\n // react-table built-in\n enableFiltering?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableColumnFreezing?: boolean;\n enableColumnHiding?: boolean;\n enableColumnResizing?: boolean;\n enableRowExpansion?: boolean;\n enableRowExpansionAll?: boolean;\n enableRowSelection?: TableConditionalRowProp<TType>;\n\n // custom -- common between all table types\n enableColumnOrdering?: boolean;\n enableFontSize?: boolean;\n enableFooter?: boolean;\n enablePrinting?: boolean;\n enableRowActions?: boolean;\n enableRowActive?: boolean;\n enableRowClick?: TableConditionalRowProp<TType>;\n enableRowDrag?: boolean;\n enableRowDrop?: boolean;\n enableRowGoto?: boolean;\n enableRowHeight?: boolean;\n enableSaveSettings?: boolean | Partial<TableEnableSettingsOptions>;\n};\n\nexport type TableChild = JSX.Element | boolean | null | undefined;\nexport type TableToolbarRenderer = JSX.Element | ((settings: TableSettings) => JSX.Element);\nexport type TableDefaultColumnFreezingIndex = number | ((settings: TableSettings) => number | undefined);\nexport type TableDefaultRowActiveIndex = number | ((settings: TableSettings) => number | undefined);\n\nexport type TableCommonProps<TType = unknown> = TableFeatureProps<TType> & {\n children: TableChild | TableChild[];\n data: TType[];\n id: string;\n\n // misc\n customSettings?: TableCustomSettingsRenderer;\n defaultColumnFreezingIndex?: TableDefaultColumnFreezingIndex;\n defaultRowActiveIndex?: TableDefaultRowActiveIndex;\n defaultRowGroupColumnId?: keyof TType;\n defaultSettings?: TableSettings;\n emptyState?: TableEmptyStateRenderer;\n preset?: TablePreset;\n rowActions?: TableRowActionRenderer<TType>[];\n rowActionsForGroup?: TableRowActionGroupRenderer<TType>[];\n rowActionsLength?: number;\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>;\n rowIdentityAccessor?: keyof TType;\n shortcuts?: TableShortcuts<TType>;\n toolbarLeft?: TableToolbarRenderer;\n toolbarRight?: TableToolbarRenderer;\n toolbarPanel?: TableToolbarRenderer;\n\n // handlers\n onEvent?: TableEventHandler;\n onRowClick?: TableRowClickHandler<TType>;\n onRowDrag?: TableRowDragHandler<TType>;\n onRowDrop?: TableRowDropHandler<TType>;\n onRowGoto?: TableRowGotoHandler;\n onRowSelect?: TableRowSelectHandler<TType>;\n\n // state change handlers\n onChangeFilter?: TableFilterHandler;\n onChangeSearch?: TableSearchHandler;\n onChangeSort?: TableSortHandler;\n _DEPRECATED_DO_NOT_USE_onChangeSettings?: TableSettingsHandler;\n};\n\nexport interface TableClientProps<TType = unknown> extends TableCommonProps<TType> {\n length?: never;\n loadAll?: never;\n loadPage?: never;\n pageSize?: never;\n pages?: never;\n\n // experimental\n _experimentalDataLoader2?: never;\n}\n\nexport interface TableServerProps<TType = unknown> extends TableCommonProps<TType> {\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n pageSize?: number;\n pages?: number[];\n\n // experimental\n _experimentalDataLoader2?: boolean;\n}\n\nexport type TableProps<TType = unknown> = TableClientProps<TType> | TableServerProps<TType>;\n\nexport type TableColumnProps<TType = unknown> = ValueOf<{\n [Key in keyof TType]: {\n accessor?: Key;\n id: StringWithAutocompleteOptions<Key>;\n // renderers\n renderer?: TableColumnRenderer<TType, TType[Key]>;\n /** Renderer to use if the cell is an aggregate cell and part of a grouped row */\n aggregate?: TableColumnRendererAggregate<TType, TType[Key]>;\n control?: TableColumnRendererControl<TType>;\n footer?: TableColumnRendererFooter<TType>;\n header: TableColumnRendererHeader;\n // options\n /** Aggregation function to be used when the column is part of a grouped row */\n aggregationFn?: 'auto' | ReactTableBuiltInAggregationFn;\n align?: TableColumnAlignment;\n className?: TableColumnClassNameHandler<TType>;\n dataType?: TableColumnDataType;\n defaultHidden?: boolean;\n defaultWidth?: TableColumnWidth;\n enableEditing?: boolean;\n enableFiltering?: boolean;\n enableGrouping?: boolean;\n enableHiding?: boolean;\n enableOrdering?: boolean;\n enablePrinting?: boolean;\n enableResizing?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableTruncate?: boolean;\n filters?: TableFilterComparator[];\n headerClassName?: string;\n menu?: TableColumnMenu;\n minWidth?: number;\n sort?: TableColumnSortDirection;\n sortFn?: TableColumnSortFn<TType>;\n tooltip?: string;\n };\n}>;\n\nexport type TableGroupProps = {\n children: (JSX.Element | boolean | null | undefined)[];\n header: string;\n id: string;\n};\n\nexport type TableTexts = {\n columns: {\n actions: {\n tooltip: string;\n };\n drag: {\n tooltip: string;\n };\n expansion: {\n collapse: string;\n collapseAll: string;\n expand: string;\n expandAll: string;\n };\n menu: {\n editFilter: string;\n filter: string;\n freezeFirstColumn: string;\n freezeUptoColumn: string;\n gotoRow: string;\n hideColumn: string;\n unfreezeColumns: string;\n sorting: string;\n sortingOrder: {\n ascending: string;\n descending: string;\n unsorted: string;\n };\n };\n resize: {\n tooltip: string;\n };\n select: {\n deselect: string;\n deselectAll: string;\n select: string;\n selectAll: string;\n };\n };\n columnSettings: {\n button: string;\n noResults: string;\n search: string;\n tooltip: string;\n };\n filters: {\n button: string;\n buttons: {\n addFilter: string;\n clearFilters: string;\n cancel: string;\n clear: string;\n apply: string;\n };\n comparators: {\n contains: string;\n doesNotContain: string;\n isEqualTo: string;\n isNotEqualTo: string;\n isGreaterThan: string;\n isLessThan: string;\n isBetween: string;\n isOneOf: string;\n isNoneOf: string;\n isEmpty: string;\n isNotEmpty: string;\n isBefore: string;\n isAfter: string;\n isLessThanOrEqualTo: string;\n isGreaterThanOrEqualTo: string;\n isOnOrBefore: string;\n isOnOrAfter: string;\n hasAnyOf: string;\n hasAllOf: string;\n hasNoneOf: string;\n };\n conditions: {\n and: string;\n where: string;\n };\n emptyFilter: {\n condition: string;\n value: string;\n };\n hiddenColumn: string;\n hiddenGroupedColumn: string;\n tooltip: string;\n total: string;\n };\n fontSize: {\n tooltip: string;\n sizes: {\n small: string;\n medium: string;\n large: string;\n };\n };\n footer: {\n summary: {\n count: string;\n records: string;\n selected: string;\n };\n };\n print: {\n error: string;\n loading: string;\n tooltip: string;\n warningDialog: {\n title: string;\n description: string;\n checkboxVisibilityLabel: string;\n cancelButtonText: string;\n printButtonText: string;\n };\n settingsDialog: {\n title: string;\n size: string;\n sizeA5: string;\n sizeA4: string;\n sizeA3: string;\n sizeLetter: string;\n sizeLegal: string;\n orientation: string;\n orientationLandscape: string;\n orientationPortrait: string;\n rows: string;\n rowsAll: string;\n rowsSelected: string;\n layout: string;\n layoutSplitGroups: string;\n };\n };\n rowHeight: {\n tooltip: string;\n sizes: {\n short: string;\n medium: string;\n tall: string;\n extraTall: string;\n };\n };\n search: {\n excludeUnmatchedResults: string;\n placeholder: string;\n };\n otherOptions: {\n tooltip: string;\n };\n};\n"],"names":["TableFilterComparator"],"mappings":"AAwBA;IACYA;AAAZ,WAAYA,qBAAqB;EAC7BA,yEAAQ;EACRA,qFAAc;EACdA,2EAAS;EACTA,iFAAY;EACZA,mFAAa;EACbA,6EAAU;EACVA,2EAAS;EACTA,uEAAO;EACPA,6EAAU;EACVA,+FAAmB;EACnBA,sGAAsB;EACtBA,0EAAQ;EACRA,0EAAQ;EACRA,4EAAS;EACTA,wEAAO;EACPA,0EAAQ;AACZ,CAAC,EAjBWA,qBAAqB,KAArBA,qBAAqB;;;;"}
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTablePrinting.js
CHANGED
@@ -1,35 +1,32 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import {
|
3
|
-
import {
|
2
|
+
import { getSettingsId } from '../util/settings.js';
|
3
|
+
import { useTaco } from '../../../../hooks/useTaco.js';
|
4
4
|
|
5
|
-
function useTablePrinting(isEnabled = false, tableId) {
|
6
|
-
const [isPrinting, setIsPrinting] = React__default.useState(false);
|
7
|
-
const [settings, setSetting] = useTablePrintingSettings(tableId);
|
8
|
-
return {
|
9
|
-
isEnabled,
|
10
|
-
isPrinting,
|
11
|
-
setIsPrinting,
|
12
|
-
settings,
|
13
|
-
setSetting
|
14
|
-
};
|
15
|
-
}
|
16
5
|
const DEFAULT_PRINT_SETTINGS = {
|
17
6
|
size: 'A4',
|
18
7
|
orientation: 'portrait',
|
19
8
|
allRows: true,
|
20
9
|
splitGroups: true
|
21
10
|
};
|
22
|
-
function
|
23
|
-
|
24
|
-
const
|
25
|
-
const
|
26
|
-
|
27
|
-
|
11
|
+
function useTablePrinting(isEnabled = false, tableId) {
|
12
|
+
var _taco$settings$getSet, _taco$settings$getSet2;
|
13
|
+
const [isPrinting, setIsPrinting] = React__default.useState(false);
|
14
|
+
const taco = useTaco();
|
15
|
+
const key = getSettingsId(tableId);
|
16
|
+
const [settings, _setSettings] = React__default.useState((_taco$settings$getSet = (_taco$settings$getSet2 = taco.settings.getSetting(key)) === null || _taco$settings$getSet2 === void 0 ? void 0 : _taco$settings$getSet2.print) !== null && _taco$settings$getSet !== void 0 ? _taco$settings$getSet : DEFAULT_PRINT_SETTINGS);
|
17
|
+
function setSetting(path, value) {
|
18
|
+
_setSettings(currentSettings => ({
|
28
19
|
...currentSettings,
|
29
|
-
[
|
20
|
+
[path]: value
|
30
21
|
}));
|
31
22
|
}
|
32
|
-
return
|
23
|
+
return {
|
24
|
+
isEnabled,
|
25
|
+
isPrinting,
|
26
|
+
setIsPrinting,
|
27
|
+
settings,
|
28
|
+
setSetting
|
29
|
+
};
|
33
30
|
}
|
34
31
|
|
35
32
|
export { useTablePrinting };
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTablePrinting.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTablePrinting.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTablePrinting.ts"],"sourcesContent":["import React from 'react';\nimport {
|
1
|
+
{"version":3,"file":"useTablePrinting.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTablePrinting.ts"],"sourcesContent":["import React from 'react';\nimport { useTaco } from '../../../../hooks/useTaco';\nimport { TablePrintSettings, TableSettings } from '../../types';\nimport { getSettingsId } from '../util/settings';\n\nconst DEFAULT_PRINT_SETTINGS: TablePrintSettings = {\n size: 'A4',\n orientation: 'portrait',\n allRows: true,\n splitGroups: true,\n};\n\nexport function useTablePrinting(isEnabled = false, tableId: string) {\n const [isPrinting, setIsPrinting] = React.useState(false);\n const taco = useTaco();\n const key = getSettingsId(tableId);\n const [settings, _setSettings] = React.useState<TablePrintSettings>(\n taco.settings.getSetting<TableSettings>(key)?.print ?? DEFAULT_PRINT_SETTINGS\n );\n\n function setSetting(path: keyof TablePrintSettings, value: any) {\n _setSettings(currentSettings => ({ ...currentSettings, [path]: value }));\n }\n\n return {\n isEnabled,\n isPrinting,\n setIsPrinting,\n settings,\n setSetting,\n };\n}\n"],"names":["DEFAULT_PRINT_SETTINGS","size","orientation","allRows","splitGroups","useTablePrinting","isEnabled","tableId","isPrinting","setIsPrinting","React","useState","taco","useTaco","key","getSettingsId","settings","_setSettings","_taco$settings$getSet","_taco$settings$getSet2","getSetting","print","setSetting","path","value","currentSettings"],"mappings":";;;;AAKA,MAAMA,sBAAsB,GAAuB;EAC/CC,IAAI,EAAE,IAAI;EACVC,WAAW,EAAE,UAAU;EACvBC,OAAO,EAAE,IAAI;EACbC,WAAW,EAAE;CAChB;SAEeC,gBAAgBA,CAACC,SAAS,GAAG,KAAK,EAAEC,OAAe;;EAC/D,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAMC,IAAI,GAAGC,OAAO,EAAE;EACtB,MAAMC,GAAG,GAAGC,aAAa,CAACR,OAAO,CAAC;EAClC,MAAM,CAACS,QAAQ,EAAEC,YAAY,CAAC,GAAGP,cAAK,CAACC,QAAQ,EAAAO,qBAAA,IAAAC,sBAAA,GAC3CP,IAAI,CAACI,QAAQ,CAACI,UAAU,CAAgBN,GAAG,CAAC,cAAAK,sBAAA,uBAA5CA,sBAAA,CAA8CE,KAAK,cAAAH,qBAAA,cAAAA,qBAAA,GAAIlB,sBAAsB,CAChF;EAED,SAASsB,UAAUA,CAACC,IAA8B,EAAEC,KAAU;IAC1DP,YAAY,CAACQ,eAAe,KAAK;MAAE,GAAGA,eAAe;MAAE,CAACF,IAAI,GAAGC;KAAO,CAAC,CAAC;;EAG5E,OAAO;IACHlB,SAAS;IACTE,UAAU;IACVC,aAAa;IACbO,QAAQ;IACRM;GACH;AACL;;;;"}
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js
CHANGED
@@ -2,8 +2,8 @@ import React__default from 'react';
|
|
2
2
|
import { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom.js';
|
3
3
|
import { useIsHoverStatePaused } from '../../../../hooks/useIsHoverStatePaused.js';
|
4
4
|
|
5
|
-
function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
|
6
|
-
const [rowActiveIndex, setRowActiveIndex] = React__default.useState(initialRowActiveIndex);
|
5
|
+
function useTableRowActive(isEnabled = false, tableSettings, initialRowActiveIndex) {
|
6
|
+
const [rowActiveIndex, setRowActiveIndex] = React__default.useState(typeof initialRowActiveIndex === 'function' ? initialRowActiveIndex(tableSettings) : initialRowActiveIndex);
|
7
7
|
const [rowHoverIndex, setRowHoverIndex] = React__default.useState(undefined);
|
8
8
|
const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();
|
9
9
|
const move = (direction, length, scrollToIndex) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableRowActive.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowActive.ts"],"sourcesContent":["import React from 'react';\nimport { TableScrollToIndexHandler } from '../../types';\nimport { useIsHoverStatePaused } from '../../../../hooks/useIsHoverStatePaused';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom';\n\nexport function useTableRowActive(isEnabled = false
|
1
|
+
{"version":3,"file":"useTableRowActive.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowActive.ts"],"sourcesContent":["import React from 'react';\nimport { TableDefaultRowActiveIndex, TableScrollToIndexHandler, TableSettings } from '../../types';\nimport { useIsHoverStatePaused } from '../../../../hooks/useIsHoverStatePaused';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom';\n\nexport function useTableRowActive(\n isEnabled = false,\n tableSettings: TableSettings,\n initialRowActiveIndex?: TableDefaultRowActiveIndex\n) {\n const [rowActiveIndex, setRowActiveIndex] = React.useState<number | undefined>(\n typeof initialRowActiveIndex === 'function' ? initialRowActiveIndex(tableSettings) : initialRowActiveIndex\n );\n const [rowHoverIndex, setRowHoverIndex] = React.useState<number | undefined>(undefined);\n const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();\n\n const move = (direction: -1 | 1, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n const nextIndex = rowActiveIndex !== undefined ? getNextIndex(direction, rowActiveIndex, length) : 0;\n scrollToIndex(nextIndex);\n setTimeout(() => setRowActiveIndex(nextIndex), 50);\n };\n\n const onKeyDown = React.useCallback(\n (event: KeyboardEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.defaultPrevented) {\n return;\n }\n\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n setHoverStatePaused(true);\n }\n\n if (event.key === 'ArrowUp') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = 0;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(-1, length, scrollToIndex);\n }\n\n return;\n } else if (event.key === 'ArrowDown') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = length - 1;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(+1, length, scrollToIndex);\n }\n return;\n }\n },\n [isEnabled, rowActiveIndex]\n );\n\n const onFocus = React.useCallback(\n (event: React.FocusEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.isDefaultPrevented()) {\n return;\n }\n\n if (event.target.closest('tbody') || isElementInsideOrTriggeredFromContainer(event.target, event.currentTarget)) {\n return;\n }\n\n if (rowActiveIndex === undefined && length > 0) {\n setRowActiveIndex(index => {\n if (index === undefined) {\n scrollToIndex(0);\n return 0;\n }\n return index;\n });\n }\n },\n [rowActiveIndex, isEnabled]\n );\n\n return {\n isEnabled,\n rowActiveIndex,\n setRowActiveIndex: isEnabled ? setRowActiveIndex : () => undefined,\n rowHoverIndex,\n setRowHoverIndex,\n isHoverStatePaused,\n setHoverStatePaused: isEnabled ? setHoverStatePaused : () => undefined,\n handleFocus: isEnabled ? onFocus : () => undefined,\n handleKeyDown: isEnabled ? onKeyDown : () => undefined,\n };\n}\n\nfunction getNextIndex(direction: -1 | 1, currentIndex: number, length: number) {\n if (direction === -1) {\n return currentIndex - 1 > 0 ? currentIndex - 1 : 0;\n }\n\n return currentIndex + 1 < length ? currentIndex + 1 : currentIndex;\n}\n"],"names":["useTableRowActive","isEnabled","tableSettings","initialRowActiveIndex","rowActiveIndex","setRowActiveIndex","React","useState","rowHoverIndex","setRowHoverIndex","undefined","isHoverStatePaused","setHoverStatePaused","useIsHoverStatePaused","move","direction","length","scrollToIndex","nextIndex","getNextIndex","setTimeout","onKeyDown","useCallback","event","defaultPrevented","key","preventDefault","ctrlKey","metaKey","newIndex","onFocus","isDefaultPrevented","target","closest","isElementInsideOrTriggeredFromContainer","currentTarget","index","handleFocus","handleKeyDown","currentIndex"],"mappings":";;;;SAKgBA,iBAAiBA,CAC7BC,SAAS,GAAG,KAAK,EACjBC,aAA4B,EAC5BC,qBAAkD;EAElD,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGC,cAAK,CAACC,QAAQ,CACtD,OAAOJ,qBAAqB,KAAK,UAAU,GAAGA,qBAAqB,CAACD,aAAa,CAAC,GAAGC,qBAAqB,CAC7G;EACD,MAAM,CAACK,aAAa,EAAEC,gBAAgB,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAqBG,SAAS,CAAC;EACvF,MAAM,CAACC,kBAAkB,EAAEC,mBAAmB,CAAC,GAAGC,qBAAqB,EAAE;EAEzE,MAAMC,IAAI,GAAGA,CAACC,SAAiB,EAAEC,MAAc,EAAEC,aAAwC;IACrF,MAAMC,SAAS,GAAGd,cAAc,KAAKM,SAAS,GAAGS,YAAY,CAACJ,SAAS,EAAEX,cAAc,EAAEY,MAAM,CAAC,GAAG,CAAC;IACpGC,aAAa,CAACC,SAAS,CAAC;IACxBE,UAAU,CAAC,MAAMf,iBAAiB,CAACa,SAAS,CAAC,EAAE,EAAE,CAAC;GACrD;EAED,MAAMG,SAAS,GAAGf,cAAK,CAACgB,WAAW,CAC/B,CAACC,KAAoB,EAAEP,MAAc,EAAEC,aAAwC;IAC3E,IAAI,CAAChB,SAAS,IAAIsB,KAAK,CAACC,gBAAgB,EAAE;MACtC;;IAGJ,IAAID,KAAK,CAACE,GAAG,KAAK,SAAS,IAA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B,IAAIA,KAAK,KAAK1B,SAAS,EAAE;UACrBO,aAAa,CAAC,CAAC,CAAC;UAChB,OAAO,CAAC;;QAEZ,OAAOmB,KAAK;OACf,CAAC;;GAET,EACD,CAAChC,cAAc,EAAEH,SAAS,CAAC,CAC9B;EAED,OAAO;IACHA,SAAS;IACTG,cAAc;IACdC,iBAAiB,EAAEJ,SAAS,GAAGI,iBAAiB,GAAG,MAAMK,SAAS;IAClEF,aAAa;IACbC,gBAAgB;IAChBE,kBAAkB;IAClBC,mBAAmB,EAAEX,SAAS,GAAGW,mBAAmB,GAAG,MAAMF,SAAS;IACtE2B,WAAW,EAAEpC,SAAS,GAAG6B,OAAO,GAAG,MAAMpB,SAAS;IAClD4B,aAAa,EAAErC,SAAS,GAAGoB,SAAS,GAAG,MAAMX;GAChD;AACL;AAEA,SAASS,YAAYA,CAACJ,SAAiB,EAAEwB,YAAoB,EAAEvB,MAAc;EACzE,IAAID,SAAS,KAAK,CAAC,CAAC,EAAE;IAClB,OAAOwB,YAAY,GAAG,CAAC,GAAG,CAAC,GAAGA,YAAY,GAAG,CAAC,GAAG,CAAC;;EAGtD,OAAOA,YAAY,GAAG,CAAC,GAAGvB,MAAM,GAAGuB,YAAY,GAAG,CAAC,GAAGA,YAAY;AACtE;;;;"}
|
@@ -1,26 +1,74 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import { getSettings } from '../util/settings.js';
|
2
|
+
import { getSettings, getSettingsId } from '../util/settings.js';
|
3
|
+
import { useTaco } from '../../../../hooks/useTaco.js';
|
3
4
|
|
4
|
-
function useTableSettingsListener(table, onChangeSettings) {
|
5
|
+
function useTableSettingsListener(table, tableId, onChangeSettings, isEnabled = false) {
|
6
|
+
const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);
|
7
|
+
const taco = useTaco();
|
5
8
|
const meta = table.options.meta;
|
6
9
|
const state = table.getState();
|
7
10
|
React__default.useEffect(() => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
const handler = setTimeout(() => {
|
12
|
+
if (!hasSomeEnabledSettings) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
const settings = removeDisabledSettings(getSettings(table), enabledSettings);
|
16
|
+
if (Object.keys(settings).length) {
|
11
17
|
// some settings shouldn't be persisted, but we comment them out here to highlight the intention
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
taco.settings.saveSetting(getSettingsId(tableId), settings);
|
19
|
+
if (onChangeSettings) {
|
20
|
+
onChangeSettings(getSettings(table));
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}, 250);
|
15
24
|
return () => clearTimeout(handler);
|
16
25
|
}, [
|
17
26
|
//state.columnFilters,
|
18
27
|
state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, table.options.enableGlobalFilter, meta.fontSize.size,
|
19
28
|
//state.grouping,
|
20
|
-
meta.rowHeight.height,
|
29
|
+
meta.printing.settings, meta.rowHeight.height,
|
21
30
|
//state.globalFilter,
|
22
31
|
state.sorting]);
|
23
32
|
}
|
33
|
+
const DEFAULT_ENABLED_OPTIONS = {
|
34
|
+
columnOrder: true,
|
35
|
+
columnPinning: true,
|
36
|
+
columnSizing: true,
|
37
|
+
columnVisibility: true,
|
38
|
+
excludeUnmatchedRecordsInSearch: true,
|
39
|
+
fontSize: true,
|
40
|
+
grouping: true,
|
41
|
+
rowHeight: true,
|
42
|
+
sorting: true
|
43
|
+
};
|
44
|
+
function useEnabledSettings(isEnabled) {
|
45
|
+
return React__default.useMemo(() => {
|
46
|
+
if (isEnabled === false) {
|
47
|
+
return [Object.keys(DEFAULT_ENABLED_OPTIONS).reduce((o, key) => ({
|
48
|
+
...o,
|
49
|
+
[key]: false
|
50
|
+
}), {}), false];
|
51
|
+
} else if (isEnabled === true) {
|
52
|
+
return [DEFAULT_ENABLED_OPTIONS, true];
|
53
|
+
}
|
54
|
+
const options = {
|
55
|
+
...DEFAULT_ENABLED_OPTIONS,
|
56
|
+
...isEnabled
|
57
|
+
};
|
58
|
+
return [options, Object.values(options).some(o => o === true)];
|
59
|
+
}, [isEnabled]);
|
60
|
+
}
|
61
|
+
function removeDisabledSettings(settings, enabledSettings) {
|
62
|
+
const sanitizedSettings = {
|
63
|
+
...settings
|
64
|
+
};
|
65
|
+
Object.keys(enabledSettings).forEach(setting => {
|
66
|
+
if (!enabledSettings[setting]) {
|
67
|
+
delete sanitizedSettings[setting];
|
68
|
+
}
|
69
|
+
});
|
70
|
+
return sanitizedSettings;
|
71
|
+
}
|
24
72
|
|
25
73
|
export { useTableSettingsListener };
|
26
74
|
//# sourceMappingURL=useTableSettingsListener.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableSettingsListener.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/listeners/useTableSettingsListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {
|
1
|
+
{"version":3,"file":"useTableSettingsListener.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/listeners/useTableSettingsListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { getSettings, getSettingsId } from '../util/settings';\nimport { useTaco } from '../../../../hooks/useTaco';\nimport { TableEnableSettingsOptions, TableSettings, TableSettingsHandler } from '../../types';\n\nexport function useTableSettingsListener<TType = unknown>(\n table: ReactTable<TType>,\n tableId: string,\n onChangeSettings: TableSettingsHandler | undefined,\n isEnabled: boolean | Partial<TableEnableSettingsOptions> = false\n) {\n const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);\n const taco = useTaco();\n const meta = table.options.meta as ReactTableMeta<TType>;\n const state = table.getState();\n\n React.useEffect(() => {\n const handler = setTimeout(() => {\n if (!hasSomeEnabledSettings) {\n return;\n }\n\n const settings = removeDisabledSettings(getSettings(table), enabledSettings);\n\n if (Object.keys(settings).length) {\n // some settings shouldn't be persisted, but we comment them out here to highlight the intention\n taco.settings.saveSetting(getSettingsId(tableId), settings);\n\n if (onChangeSettings) {\n onChangeSettings(getSettings(table));\n }\n }\n }, 250);\n\n return () => clearTimeout(handler);\n }, [\n //state.columnFilters,\n state.columnOrder,\n state.columnPinning,\n state.columnSizing,\n state.columnVisibility,\n table.options.enableGlobalFilter,\n meta.fontSize.size,\n //state.grouping,\n meta.printing.settings,\n meta.rowHeight.height,\n //state.globalFilter,\n state.sorting,\n ]);\n}\n\nconst DEFAULT_ENABLED_OPTIONS = {\n columnOrder: true,\n columnPinning: true,\n columnSizing: true,\n columnVisibility: true,\n excludeUnmatchedRecordsInSearch: true,\n fontSize: true,\n grouping: true,\n rowHeight: true,\n sorting: true,\n};\n\nfunction useEnabledSettings(isEnabled: boolean | Partial<TableEnableSettingsOptions>): [TableEnableSettingsOptions, boolean] {\n return React.useMemo(() => {\n if (isEnabled === false) {\n return [\n Object.keys(DEFAULT_ENABLED_OPTIONS).reduce(\n (o, key) => ({ ...o, [key]: false }),\n {}\n ) as TableEnableSettingsOptions,\n false,\n ];\n } else if (isEnabled === true) {\n return [DEFAULT_ENABLED_OPTIONS, true];\n }\n\n const options = { ...DEFAULT_ENABLED_OPTIONS, ...isEnabled };\n return [options, Object.values(options).some(o => o === true)];\n }, [isEnabled]);\n}\n\nfunction removeDisabledSettings(settings: TableSettings, enabledSettings: TableEnableSettingsOptions) {\n const sanitizedSettings: TableSettings = { ...settings };\n\n Object.keys(enabledSettings).forEach(setting => {\n if (!enabledSettings[setting]) {\n delete sanitizedSettings[setting];\n }\n });\n\n return sanitizedSettings;\n}\n"],"names":["useTableSettingsListener","table","tableId","onChangeSettings","isEnabled","enabledSettings","hasSomeEnabledSettings","useEnabledSettings","taco","useTaco","meta","options","state","getState","React","useEffect","handler","setTimeout","settings","removeDisabledSettings","getSettings","Object","keys","length","saveSetting","getSettingsId","clearTimeout","columnOrder","columnPinning","columnSizing","columnVisibility","enableGlobalFilter","fontSize","size","printing","rowHeight","height","sorting","DEFAULT_ENABLED_OPTIONS","excludeUnmatchedRecordsInSearch","grouping","useMemo","reduce","o","key","values","some","sanitizedSettings","forEach","setting"],"mappings":";;;;SAMgBA,wBAAwBA,CACpCC,KAAwB,EACxBC,OAAe,EACfC,gBAAkD,EAClDC,YAA2D,KAAK;EAEhE,MAAM,CAACC,eAAe,EAAEC,sBAAsB,CAAC,GAAGC,kBAAkB,CAACH,SAAS,CAAC;EAC/E,MAAMI,IAAI,GAAGC,OAAO,EAAE;EACtB,MAAMC,IAAI,GAAGT,KAAK,CAACU,OAAO,CAACD,IAA6B;EACxD,MAAME,KAAK,GAAGX,KAAK,CAACY,QAAQ,EAAE;EAE9BC,cAAK,CAACC,SAAS,CAAC;IACZ,MAAMC,OAAO,GAAGC,UAAU,CAAC;MACvB,IAAI,CAACX,sBAAsB,EAAE;QACzB;;MAGJ,MAAMY,QAAQ,GAAGC,sBAAsB,CAACC,WAAW,CAACnB,KAAK,CAAC,EAAEI,eAAe,CAAC;MAE5E,IAAIgB,MAAM,CAACC,IAAI,CAACJ,QAAQ,CAAC,CAACK,MAAM,EAAE;;QAE9Bf,IAAI,CAACU,QAAQ,CAACM,WAAW,CAACC,aAAa,CAACvB,OAAO,CAAC,EAAEgB,QAAQ,CAAC;QAE3D,IAAIf,gBAAgB,EAAE;UAClBA,gBAAgB,CAACiB,WAAW,CAACnB,KAAK,CAAC,CAAC;;;KAG/C,EAAE,GAAG,CAAC;IAEP,OAAO,MAAMyB,YAAY,CAACV,OAAO,CAAC;GACrC,EAAE;;EAECJ,KAAK,CAACe,WAAW,EACjBf,KAAK,CAACgB,aAAa,EACnBhB,KAAK,CAACiB,YAAY,EAClBjB,KAAK,CAACkB,gBAAgB,EACtB7B,KAAK,CAACU,OAAO,CAACoB,kBAAkB,EAChCrB,IAAI,CAACsB,QAAQ,CAACC,IAAI;;EAElBvB,IAAI,CAACwB,QAAQ,CAAChB,QAAQ,EACtBR,IAAI,CAACyB,SAAS,CAACC,MAAM;;EAErBxB,KAAK,CAACyB,OAAO,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AAC5B;;;;"}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { useLocalization } from '../../../components/Provider/Localization.js';
|
2
2
|
import { useReactTable, getCoreRowModel } from '@tanstack/react-table';
|
3
|
+
import { getSettingsId } from './util/settings.js';
|
3
4
|
import { mapTableChildrenToColumns, useReactTableInitialState, configureReactTableOptions } from './util/setup.js';
|
4
5
|
import { getTableFeaturePreset } from './util/presets.js';
|
5
6
|
import { useTableColumnFreezing } from './features/useTableColumnFreezing.js';
|
6
7
|
import { useTableColumnOrdering } from './features/useTableColumnOrdering.js';
|
7
8
|
import { useTableFooter } from './features/useTableFooter.js';
|
8
9
|
import { useTableFontSize } from './features/useTableFontSize.js';
|
10
|
+
import { useTaco } from '../../../hooks/useTaco.js';
|
9
11
|
import { useTablePrinting } from './features/useTablePrinting.js';
|
10
12
|
import { useTableRowActions } from './features/useTableRowActions.js';
|
11
13
|
import { useTableRowActive } from './features/useTableRowActive.js';
|
@@ -17,7 +19,6 @@ import { useTableRowHeight } from './features/useTableRowHeight.js';
|
|
17
19
|
import { useTableRowSelection } from './features/useTableRowSelection.js';
|
18
20
|
import { useTableSearch } from './features/useTableSearch.js';
|
19
21
|
import { useTableServerLoading } from './features/useTableServerLoading.js';
|
20
|
-
import { useTableSettings } from './features/useTableSettings.js';
|
21
22
|
import { useTableDataListener } from './listeners/useTableDataListener.js';
|
22
23
|
import { useTableFilterListener } from './listeners/useTableFilterListener.js';
|
23
24
|
import { useTableFontSizeListener } from './listeners/useTableFontSizeListener.js';
|
@@ -34,14 +35,15 @@ import { useTableRowDrop } from './features/useTableRowDrop.js';
|
|
34
35
|
// Placed this array outside the hook to avoid creating a new array reference on each hook re-render
|
35
36
|
const DEFAULT_EMPTY_ARRAY = [];
|
36
37
|
function useTableManager(props, meta, internalColumns) {
|
37
|
-
var _props$data, _props$length, _meta$editing, _instance$options$met;
|
38
|
+
var _ref, _taco$settings$getSet, _props$data, _props$length, _meta$editing, _instance$options$met;
|
39
|
+
const taco = useTaco();
|
38
40
|
const localization = useLocalization();
|
39
41
|
// CSS.escape would be best here, but it doesn't seem to work very well
|
40
42
|
const safeId = props.id.replace('.', '_');
|
41
43
|
// configure table options, merging props with presets
|
42
44
|
const options = getTableFeaturePreset(props);
|
43
45
|
// load any persisted table settings and merge them with any defaults
|
44
|
-
const
|
46
|
+
const settings = (_ref = (_taco$settings$getSet = taco.settings.getSetting(getSettingsId(safeId))) !== null && _taco$settings$getSet !== void 0 ? _taco$settings$getSet : props.defaultSettings) !== null && _ref !== void 0 ? _ref : {};
|
45
47
|
// ensure data is always valid
|
46
48
|
const data = (_props$data = props.data) !== null && _props$data !== void 0 ? _props$data : DEFAULT_EMPTY_ARRAY;
|
47
49
|
const length = (_props$length = props.length) !== null && _props$length !== void 0 ? _props$length : data.length;
|
@@ -51,7 +53,7 @@ function useTableManager(props, meta, internalColumns) {
|
|
51
53
|
const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);
|
52
54
|
const footer = useTableFooter(options.enableFooter);
|
53
55
|
const printing = useTablePrinting(options.enablePrinting, safeId);
|
54
|
-
const rowActive = useTableRowActive(options.enableRowActive, props.defaultRowActiveIndex);
|
56
|
+
const rowActive = useTableRowActive(options.enableRowActive, settings, props.defaultRowActiveIndex);
|
55
57
|
const rowActions = useTableRowActions(options.enableRowActions, props.rowActions, props.rowActionsLength);
|
56
58
|
const rowClick = useTableRowClick(options.enableRowClick, props.onRowClick);
|
57
59
|
const rowDrag = useTableRowDrag(options.enableRowDrag && !(meta !== null && meta !== void 0 && (_meta$editing = meta.editing) !== null && _meta$editing !== void 0 && _meta$editing.isEditing), props.onRowDrag);
|
@@ -116,7 +118,7 @@ function useTableManager(props, meta, internalColumns) {
|
|
116
118
|
useTableRowSelectionListener(instance, props.onRowSelect);
|
117
119
|
useTableSearchListener(instance);
|
118
120
|
useTableServerLoadingListener(instance, server.loadPage);
|
119
|
-
useTableSettingsListener(instance,
|
121
|
+
useTableSettingsListener(instance, safeId, props._DEPRECATED_DO_NOT_USE_onChangeSettings, options.enableSaveSettings);
|
120
122
|
useTableShortcutsListener(instance, props.shortcuts);
|
121
123
|
useTableSortingListener(instance, props.onChangeSort);
|
122
124
|
return {
|