@economic/taco 1.1.13-alpha.0 → 1.2.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/Group/Group.d.ts +11 -1
- package/dist/components/Toast/Toast.d.ts +2 -2
- package/dist/components/Toast/Toaster.d.ts +2 -2
- package/dist/esm/components/Accordion/Accordion.js +31 -34
- package/dist/esm/components/Accordion/Accordion.js.map +1 -1
- package/dist/esm/components/Backdrop/Backdrop.js +2 -2
- package/dist/esm/components/Backdrop/Backdrop.js.map +1 -1
- package/dist/esm/components/Badge/Badge.js +14 -14
- package/dist/esm/components/Badge/Badge.js.map +1 -1
- package/dist/esm/components/Banner/Banner.js +7 -5
- package/dist/esm/components/Banner/Banner.js.map +1 -1
- package/dist/esm/components/Banner/util.js +1 -1
- package/dist/esm/components/Banner/util.js.map +1 -1
- package/dist/esm/components/Button/Button.js +12 -13
- package/dist/esm/components/Button/Button.js.map +1 -1
- package/dist/esm/components/Button/util.js +18 -23
- package/dist/esm/components/Button/util.js.map +1 -1
- package/dist/esm/components/Calendar/Calendar.js +56 -71
- package/dist/esm/components/Calendar/Calendar.js.map +1 -1
- package/dist/esm/components/Card/Card.js +13 -12
- package/dist/esm/components/Card/Card.js.map +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +15 -18
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Combobox/Combobox.js +23 -25
- package/dist/esm/components/Combobox/Combobox.js.map +1 -1
- package/dist/esm/components/Combobox/useCombobox.js +78 -99
- package/dist/esm/components/Combobox/useCombobox.js.map +1 -1
- package/dist/esm/components/Datepicker/Datepicker.js +48 -52
- package/dist/esm/components/Datepicker/Datepicker.js.map +1 -1
- package/dist/esm/components/Datepicker/useDatepicker.js +27 -34
- package/dist/esm/components/Datepicker/useDatepicker.js.map +1 -1
- package/dist/esm/components/Dialog/Context.js +4 -4
- package/dist/esm/components/Dialog/Context.js.map +1 -1
- package/dist/esm/components/Dialog/Dialog.js +39 -58
- package/dist/esm/components/Dialog/Dialog.js.map +1 -1
- package/dist/esm/components/Dialog/components/Content.js +39 -44
- package/dist/esm/components/Dialog/components/Content.js.map +1 -1
- package/dist/esm/components/Dialog/components/Drawer.js +3 -3
- package/dist/esm/components/Dialog/components/Drawer.js.map +1 -1
- package/dist/esm/components/Dialog/components/Extra.js +2 -2
- package/dist/esm/components/Dialog/components/Extra.js.map +1 -1
- package/dist/esm/components/Dialog/components/Trigger.js +2 -2
- package/dist/esm/components/Dialog/components/Trigger.js.map +1 -1
- package/dist/esm/components/Field/Field.js +10 -12
- package/dist/esm/components/Field/Field.js.map +1 -1
- package/dist/esm/components/Form/Form.js +6 -8
- package/dist/esm/components/Form/Form.js.map +1 -1
- package/dist/esm/components/Group/Group.js +9 -8
- package/dist/esm/components/Group/Group.js.map +1 -1
- package/dist/esm/components/Hanger/Hanger.js +27 -35
- package/dist/esm/components/Hanger/Hanger.js.map +1 -1
- package/dist/esm/components/HoverCard/HoverCard.js +8 -9
- package/dist/esm/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/esm/components/Icon/Icon.js +7 -8
- package/dist/esm/components/Icon/Icon.js.map +1 -1
- package/dist/esm/components/Icon/components/index.js +4 -4
- package/dist/esm/components/Icon/components/index.js.map +1 -1
- package/dist/esm/components/IconButton/IconButton.js +9 -11
- package/dist/esm/components/IconButton/IconButton.js.map +1 -1
- package/dist/esm/components/Input/Input.js +25 -25
- package/dist/esm/components/Input/Input.js.map +1 -1
- package/dist/esm/components/Input/util.js +2 -2
- package/dist/esm/components/Input/util.js.map +1 -1
- package/dist/esm/components/Listbox/Listbox.js +24 -25
- package/dist/esm/components/Listbox/Listbox.js.map +1 -1
- package/dist/esm/components/Listbox/ScrollableList.js +65 -84
- package/dist/esm/components/Listbox/ScrollableList.js.map +1 -1
- package/dist/esm/components/Listbox/useListbox.js +53 -61
- package/dist/esm/components/Listbox/useListbox.js.map +1 -1
- package/dist/esm/components/Listbox/useMultiListbox.js +69 -96
- package/dist/esm/components/Listbox/useMultiListbox.js.map +1 -1
- package/dist/esm/components/Listbox/useTypeahead.js +10 -9
- package/dist/esm/components/Listbox/useTypeahead.js.map +1 -1
- package/dist/esm/components/Listbox/util.js +48 -85
- package/dist/esm/components/Listbox/util.js.map +1 -1
- package/dist/esm/components/Menu/Context.js +2 -2
- package/dist/esm/components/Menu/Context.js.map +1 -1
- package/dist/esm/components/Menu/Menu.js +16 -34
- package/dist/esm/components/Menu/Menu.js.map +1 -1
- package/dist/esm/components/Menu/components/Checkbox.js +9 -10
- package/dist/esm/components/Menu/components/Checkbox.js.map +1 -1
- package/dist/esm/components/Menu/components/Content.js +9 -11
- package/dist/esm/components/Menu/components/Content.js.map +1 -1
- package/dist/esm/components/Menu/components/Header.js +3 -3
- package/dist/esm/components/Menu/components/Header.js.map +1 -1
- package/dist/esm/components/Menu/components/Item.js +30 -31
- package/dist/esm/components/Menu/components/Item.js.map +1 -1
- package/dist/esm/components/Menu/components/Link.js +10 -11
- package/dist/esm/components/Menu/components/Link.js.map +1 -1
- package/dist/esm/components/Menu/components/RadioGroup.js +17 -19
- package/dist/esm/components/Menu/components/RadioGroup.js.map +1 -1
- package/dist/esm/components/Menu/components/Separator.js +1 -1
- package/dist/esm/components/Menu/components/Separator.js.map +1 -1
- package/dist/esm/components/Menu/components/Trigger.js +4 -4
- package/dist/esm/components/Menu/components/Trigger.js.map +1 -1
- package/dist/esm/components/Navigation/Navigation.js +35 -44
- package/dist/esm/components/Navigation/Navigation.js.map +1 -1
- package/dist/esm/components/Pagination/PageNumbers.js +23 -28
- package/dist/esm/components/Pagination/PageNumbers.js.map +1 -1
- package/dist/esm/components/Pagination/Pagination.js +39 -56
- package/dist/esm/components/Pagination/Pagination.js.map +1 -1
- package/dist/esm/components/Pagination/usePagination.js +7 -21
- package/dist/esm/components/Pagination/usePagination.js.map +1 -1
- package/dist/esm/components/Pagination/usePaginationShortcuts.js +13 -14
- package/dist/esm/components/Pagination/usePaginationShortcuts.js.map +1 -1
- package/dist/esm/components/Popover/Popover.js +29 -34
- package/dist/esm/components/Popover/Popover.js.map +1 -1
- package/dist/esm/components/Popover/Primitives.js +7 -8
- package/dist/esm/components/Popover/Primitives.js.map +1 -1
- package/dist/esm/components/Progress/Progress.js +11 -15
- package/dist/esm/components/Progress/Progress.js.map +1 -1
- package/dist/esm/components/Provider/Provider.js +13 -18
- package/dist/esm/components/Provider/Provider.js.map +1 -1
- package/dist/esm/components/RadioGroup/RadioGroup.js +45 -57
- package/dist/esm/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/components/SearchInput/SearchInput.js +10 -12
- package/dist/esm/components/SearchInput/SearchInput.js.map +1 -1
- package/dist/esm/components/Select/Select.js +30 -31
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Select/useSelect.js +69 -88
- package/dist/esm/components/Select/useSelect.js.map +1 -1
- package/dist/esm/components/Spinner/Spinner.js +12 -19
- package/dist/esm/components/Spinner/Spinner.js.map +1 -1
- package/dist/esm/components/Switch/Switch.js +9 -10
- package/dist/esm/components/Switch/Switch.js.map +1 -1
- package/dist/esm/components/Table/components/BaseTable.js +23 -30
- package/dist/esm/components/Table/components/BaseTable.js.map +1 -1
- package/dist/esm/components/Table/components/PaginatedTable.js +3 -7
- package/dist/esm/components/Table/components/PaginatedTable.js.map +1 -1
- package/dist/esm/components/Table/components/Table.js +18 -25
- package/dist/esm/components/Table/components/Table.js.map +1 -1
- package/dist/esm/components/Table/components/WindowedTable.js +89 -109
- package/dist/esm/components/Table/components/WindowedTable.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowActions.js +123 -148
- package/dist/esm/components/Table/hooks/plugins/useRowActions.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowDraggable.js +57 -61
- package/dist/esm/components/Table/hooks/plugins/useRowDraggable.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowEditing.js +39 -36
- package/dist/esm/components/Table/hooks/plugins/useRowEditing.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowSelect.js +79 -89
- package/dist/esm/components/Table/hooks/plugins/useRowSelect.js.map +1 -1
- package/dist/esm/components/Table/hooks/useRowCreation.js +29 -64
- package/dist/esm/components/Table/hooks/useRowCreation.js.map +1 -1
- package/dist/esm/components/Table/hooks/useTable.js +123 -141
- package/dist/esm/components/Table/hooks/useTable.js.map +1 -1
- package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js +23 -27
- package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js.map +1 -1
- package/dist/esm/components/Table/util/renderColumn.js +10 -10
- package/dist/esm/components/Table/util/renderColumn.js.map +1 -1
- package/dist/esm/components/Table/util/renderRow.js +37 -46
- package/dist/esm/components/Table/util/renderRow.js.map +1 -1
- package/dist/esm/components/Table/util/rowIndexPath.js +14 -16
- package/dist/esm/components/Table/util/rowIndexPath.js.map +1 -1
- package/dist/esm/components/Table/util/sortTypes.js +23 -31
- package/dist/esm/components/Table/util/sortTypes.js.map +1 -1
- package/dist/esm/components/Table/util.js +29 -41
- package/dist/esm/components/Table/util.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.js +25 -27
- package/dist/esm/components/Tabs/Tabs.js.map +1 -1
- package/dist/esm/components/Textarea/Textarea.js +11 -9
- package/dist/esm/components/Textarea/Textarea.js.map +1 -1
- package/dist/esm/components/Toast/Toast.js +27 -23
- package/dist/esm/components/Toast/Toast.js.map +1 -1
- package/dist/esm/components/Toast/Toaster.js +88 -118
- package/dist/esm/components/Toast/Toaster.js.map +1 -1
- package/dist/esm/components/Toast/util.js +2 -2
- package/dist/esm/components/Toast/util.js.map +1 -1
- package/dist/esm/components/Tooltip/Tooltip.js +7 -8
- package/dist/esm/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/components/Tour/Tour.js +46 -53
- package/dist/esm/components/Tour/Tour.js.map +1 -1
- package/dist/esm/components/Treeview/Treeview.js +26 -36
- package/dist/esm/components/Treeview/Treeview.js.map +1 -1
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +1 -1
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js.map +1 -1
- package/dist/esm/index.css +1 -9
- package/dist/esm/index.js +1 -1
- package/dist/esm/primitives/Button.js +9 -13
- package/dist/esm/primitives/Button.js.map +1 -1
- package/dist/esm/utils/date.js +20 -40
- package/dist/esm/utils/date.js.map +1 -1
- package/dist/esm/utils/hooks/useBoundingClientRectListener.js +12 -20
- package/dist/esm/utils/hooks/useBoundingClientRectListener.js.map +1 -1
- package/dist/esm/utils/hooks/useDraggable.js +16 -17
- package/dist/esm/utils/hooks/useDraggable.js.map +1 -1
- package/dist/esm/utils/hooks/useDropTarget.js +7 -10
- package/dist/esm/utils/hooks/useDropTarget.js.map +1 -1
- package/dist/esm/utils/hooks/useListKeyboardNavigation.js +15 -30
- package/dist/esm/utils/hooks/useListKeyboardNavigation.js.map +1 -1
- package/dist/esm/utils/hooks/useListScrollTo.js +9 -9
- package/dist/esm/utils/hooks/useListScrollTo.js.map +1 -1
- package/dist/esm/utils/hooks/useOnClickOutside.js +6 -8
- package/dist/esm/utils/hooks/useOnClickOutside.js.map +1 -1
- package/dist/esm/utils/hooks/useProxiedRef.js +3 -3
- package/dist/esm/utils/hooks/useProxiedRef.js.map +1 -1
- package/dist/esm/utils/hooks/useTimer.js +9 -17
- package/dist/esm/utils/hooks/useTimer.js.map +1 -1
- package/dist/esm/utils/input.js +8 -12
- package/dist/esm/utils/input.js.map +1 -1
- package/dist/esm/utils/mergeRefs.js +2 -2
- package/dist/esm/utils/mergeRefs.js.map +1 -1
- package/dist/esm/utils/taillwind.js +2 -2
- package/dist/esm/utils/taillwind.js.map +1 -1
- package/dist/index.css +1 -9
- package/dist/taco.cjs.development.js +2334 -2883
- 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/dist/utils/hooks/useListKeyboardNavigation.d.ts +1 -1
- package/package.json +4 -5
- package/types.json +10 -3
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +0 -34
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRowCreation.js","sources":["../../../../../src/components/Table/hooks/useRowCreation.tsx"],"sourcesContent":["import React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport set from 'lodash/set';\nimport unset from 'lodash/unset';\nimport get from 'lodash/get';\nimport compact from 'lodash/compact';\nimport pullAt from 'lodash/pullAt';\n\nimport { convertRowIndexPathToNumberArray, getByRowIndexPath, getParentRowIndexPath } from '../util/rowIndexPath';\nimport { Row, RowIndexPath, TableRef } from '../types';\n\nexport const insertChildTableRow = <TRow,>(\n data: Row<TRow>[],\n rowIndexPath: RowIndexPath = undefined,\n values: any = {}\n): [Row<TRow>[], RowIndexPath] => {\n const nexTRow: Row<TRow>[] = JSON.parse(JSON.stringify(data));\n\n let childRowIndexPath;\n\n if (rowIndexPath) {\n const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);\n const currentRow = getByRowIndexPath(nexTRow, rowIndexes.join('.'));\n const nextSubRows = currentRow?.subRows ?? [];\n\n const path = rowIndexes.map(i => `[${i}]`).join('.subRows') + '.subRows';\n nextSubRows.unshift(values);\n set(nexTRow, path, nextSubRows);\n\n // rebuild the new id\n rowIndexes.push(0);\n childRowIndexPath = rowIndexes.join('.');\n } else {\n nexTRow.unshift(values);\n childRowIndexPath = '0';\n }\n\n return [nexTRow, childRowIndexPath];\n};\n\nexport const removeChildTableRow = <TRow,>(data: Row<TRow>[], rowIndexPath: RowIndexPath): Row<TRow>[] => {\n const nexTRow = JSON.parse(JSON.stringify(data));\n\n const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);\n const rootIndex = Number(rowIndexes.shift());\n\n if (rowIndexes.length) {\n // unset\n const unsetPath = rowIndexes.map(index => `subRows[${index}]`).join('.');\n unset(nexTRow[rootIndex], unsetPath);\n\n // remove empty value from subRows\n rowIndexes.pop();\n const setPath = rowIndexes.length ? rowIndexes.map(index => `subRows[${index}]`).join('.') + '.subRows' : 'subRows';\n set(nexTRow[rootIndex], setPath, compact(get(nexTRow[rootIndex], setPath)));\n } else {\n pullAt(nexTRow, rootIndex);\n }\n\n return nexTRow;\n};\n\nexport type useTableRowCreation<TRow> = {\n data: Row<TRow>[];\n create: (rowIndexPath: RowIndexPath, values?: object | undefined) => RowIndexPath;\n remove: (rowIndexPath: RowIndexPath) => void;\n isCreating: boolean;\n};\n\nexport const useTableRowCreation = <TRow,>(data: Row<TRow>[], tableRef: React.RefObject<TableRef>): useTableRowCreation<TRow> => {\n const [internalData, setInternalData] = React.useState(JSON.parse(JSON.stringify(data)));\n const [activeRowIndexPath, setActiveRowIndexPath] = React.useState<string | undefined>(undefined);\n\n React.useEffect(() => {\n if (activeRowIndexPath !== undefined) {\n // keep the same edit key, so that we don't remount the row/form\n const currentRow: any = getByRowIndexPath(internalData, activeRowIndexPath);\n\n // get the active creation rows parent\n const parentId = getParentRowIndexPath(activeRowIndexPath);\n\n // insert a new empty row in the external data (with the same key)\n const [nexTRow, newRowIndexPath] = insertChildTableRow(JSON.parse(JSON.stringify(data)), parentId, currentRow);\n\n // update and set that row as active, we basically just changed it's position in our internal data\n setActiveRowIndexPath(newRowIndexPath);\n setInternalData(nexTRow);\n\n if (tableRef?.current) {\n tableRef.current.instance.toggleRowEditing(currentRow?._createKey);\n }\n } else {\n setInternalData(data);\n }\n }, [JSON.stringify(data)]);\n\n const create = (rowIndexPath: RowIndexPath = undefined, values: object | undefined = {}): RowIndexPath => {\n const _createKey = uuid();\n const [nexTRow, newRowIndexPath] = insertChildTableRow(internalData, rowIndexPath, { ...values, _createKey });\n setActiveRowIndexPath(newRowIndexPath);\n setInternalData(nexTRow);\n\n if (tableRef?.current) {\n tableRef.current.instance.toggleRowEditing(_createKey);\n }\n\n return newRowIndexPath;\n };\n\n const remove = (rowIndexPath: any): void => {\n const nexTRow = removeChildTableRow(internalData, rowIndexPath);\n setInternalData(nexTRow);\n setActiveRowIndexPath(undefined);\n };\n\n return {\n data: internalData,\n create,\n remove,\n isCreating: activeRowIndexPath !== undefined,\n };\n};\n"],"names":["insertChildTableRow","data","rowIndexPath","
|
1
|
+
{"version":3,"file":"useRowCreation.js","sources":["../../../../../src/components/Table/hooks/useRowCreation.tsx"],"sourcesContent":["import React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport set from 'lodash/set';\nimport unset from 'lodash/unset';\nimport get from 'lodash/get';\nimport compact from 'lodash/compact';\nimport pullAt from 'lodash/pullAt';\n\nimport { convertRowIndexPathToNumberArray, getByRowIndexPath, getParentRowIndexPath } from '../util/rowIndexPath';\nimport { Row, RowIndexPath, TableRef } from '../types';\n\nexport const insertChildTableRow = <TRow,>(\n data: Row<TRow>[],\n rowIndexPath: RowIndexPath = undefined,\n values: any = {}\n): [Row<TRow>[], RowIndexPath] => {\n const nexTRow: Row<TRow>[] = JSON.parse(JSON.stringify(data));\n\n let childRowIndexPath;\n\n if (rowIndexPath) {\n const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);\n const currentRow = getByRowIndexPath(nexTRow, rowIndexes.join('.'));\n const nextSubRows = currentRow?.subRows ?? [];\n\n const path = rowIndexes.map(i => `[${i}]`).join('.subRows') + '.subRows';\n nextSubRows.unshift(values);\n set(nexTRow, path, nextSubRows);\n\n // rebuild the new id\n rowIndexes.push(0);\n childRowIndexPath = rowIndexes.join('.');\n } else {\n nexTRow.unshift(values);\n childRowIndexPath = '0';\n }\n\n return [nexTRow, childRowIndexPath];\n};\n\nexport const removeChildTableRow = <TRow,>(data: Row<TRow>[], rowIndexPath: RowIndexPath): Row<TRow>[] => {\n const nexTRow = JSON.parse(JSON.stringify(data));\n\n const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);\n const rootIndex = Number(rowIndexes.shift());\n\n if (rowIndexes.length) {\n // unset\n const unsetPath = rowIndexes.map(index => `subRows[${index}]`).join('.');\n unset(nexTRow[rootIndex], unsetPath);\n\n // remove empty value from subRows\n rowIndexes.pop();\n const setPath = rowIndexes.length ? rowIndexes.map(index => `subRows[${index}]`).join('.') + '.subRows' : 'subRows';\n set(nexTRow[rootIndex], setPath, compact(get(nexTRow[rootIndex], setPath)));\n } else {\n pullAt(nexTRow, rootIndex);\n }\n\n return nexTRow;\n};\n\nexport type useTableRowCreation<TRow> = {\n data: Row<TRow>[];\n create: (rowIndexPath: RowIndexPath, values?: object | undefined) => RowIndexPath;\n remove: (rowIndexPath: RowIndexPath) => void;\n isCreating: boolean;\n};\n\nexport const useTableRowCreation = <TRow,>(data: Row<TRow>[], tableRef: React.RefObject<TableRef>): useTableRowCreation<TRow> => {\n const [internalData, setInternalData] = React.useState(JSON.parse(JSON.stringify(data)));\n const [activeRowIndexPath, setActiveRowIndexPath] = React.useState<string | undefined>(undefined);\n\n React.useEffect(() => {\n if (activeRowIndexPath !== undefined) {\n // keep the same edit key, so that we don't remount the row/form\n const currentRow: any = getByRowIndexPath(internalData, activeRowIndexPath);\n\n // get the active creation rows parent\n const parentId = getParentRowIndexPath(activeRowIndexPath);\n\n // insert a new empty row in the external data (with the same key)\n const [nexTRow, newRowIndexPath] = insertChildTableRow(JSON.parse(JSON.stringify(data)), parentId, currentRow);\n\n // update and set that row as active, we basically just changed it's position in our internal data\n setActiveRowIndexPath(newRowIndexPath);\n setInternalData(nexTRow);\n\n if (tableRef?.current) {\n tableRef.current.instance.toggleRowEditing(currentRow?._createKey);\n }\n } else {\n setInternalData(data);\n }\n }, [JSON.stringify(data)]);\n\n const create = (rowIndexPath: RowIndexPath = undefined, values: object | undefined = {}): RowIndexPath => {\n const _createKey = uuid();\n const [nexTRow, newRowIndexPath] = insertChildTableRow(internalData, rowIndexPath, { ...values, _createKey });\n setActiveRowIndexPath(newRowIndexPath);\n setInternalData(nexTRow);\n\n if (tableRef?.current) {\n tableRef.current.instance.toggleRowEditing(_createKey);\n }\n\n return newRowIndexPath;\n };\n\n const remove = (rowIndexPath: any): void => {\n const nexTRow = removeChildTableRow(internalData, rowIndexPath);\n setInternalData(nexTRow);\n setActiveRowIndexPath(undefined);\n };\n\n return {\n data: internalData,\n create,\n remove,\n isCreating: activeRowIndexPath !== undefined,\n };\n};\n"],"names":["insertChildTableRow","data","rowIndexPath","undefined","values","nexTRow","JSON","parse","stringify","childRowIndexPath","rowIndexes","convertRowIndexPathToNumberArray","currentRow","getByRowIndexPath","join","nextSubRows","subRows","path","map","i","unshift","set","push","removeChildTableRow","rootIndex","Number","shift","length","unsetPath","index","unset","pop","setPath","compact","get","pullAt","useTableRowCreation","tableRef","internalData","setInternalData","React","useState","activeRowIndexPath","setActiveRowIndexPath","useEffect","parentId","getParentRowIndexPath","newRowIndexPath","current","instance","toggleRowEditing","_createKey","create","uuid","remove","isCreating"],"mappings":";;;;;;;;;MAWaA,mBAAmB,GAAG,CAC/BC,IAD+B,EAE/BC,eAA6BC,SAFE,EAG/BC,SAAc,EAHiB;EAK/B,MAAMC,OAAO,GAAgBC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,SAAL,CAAeP,IAAf,CAAX,CAA7B;EAEA,IAAIQ,iBAAJ;;EAEA,IAAIP,YAAJ,EAAkB;IAAA;;IACd,MAAMQ,UAAU,GAAGC,gCAAgC,CAACT,YAAD,CAAnD;IACA,MAAMU,UAAU,GAAGC,iBAAiB,CAACR,OAAD,EAAUK,UAAU,CAACI,IAAX,CAAgB,GAAhB,CAAV,CAApC;IACA,MAAMC,WAAW,0BAAGH,UAAH,aAAGA,UAAH,uBAAGA,UAAU,CAAEI,OAAf,qEAA0B,EAA3C;IAEA,MAAMC,IAAI,GAAGP,UAAU,CAACQ,GAAX,CAAeC,CAAC,QAAQA,IAAxB,EAA8BL,IAA9B,CAAmC,UAAnC,IAAiD,UAA9D;IACAC,WAAW,CAACK,OAAZ,CAAoBhB,MAApB;IACAiB,GAAG,CAAChB,OAAD,EAAUY,IAAV,EAAgBF,WAAhB,CAAH,CAPc;;IA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AL;MAAa+C;KAA1C,CAAtD;IACAR,qBAAqB,CAACI,eAAD,CAArB;IACAR,eAAe,CAAClC,OAAD,CAAf;;IAEA,IAAIgC,QAAJ,aAAIA,QAAJ,eAAIA,QAAQ,CAAEW,OAAd,EAAuB;MACnBX,QAAQ,CAACW,OAAT,CAAiBC,QAAjB,CAA0BC,gBAA1B,CAA2CC,UAA3C;;;IAGJ,OAAOJ,eAAP;GAVJ;;EAaA,MAAMO,MAAM,GAAIpD,YAAD;IACX,MAAMG,OAAO,GAAGkB,mBAAmB,CAACe,YAAD,EAAepC,YAAf,CAAnC;IACAqC,eAAe,CAAClC,OAAD,CAAf;IACAsC,qBAAqB,CAACxC,SAAD,CAArB;GAHJ;;EAMA,OAAO;IACHF,IAAI,EAAEqC,YADH;IAEHc,MAFG;IAGHE,MAHG;IAIHC,UAAU,EAAEb,kBAAkB,KAAKvC;GAJvC;AAMH;;;;"}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { extends as _extends, objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import React__default from 'react';
|
3
2
|
import { useLocalization } from '../../Provider/Provider.js';
|
4
3
|
import { useTable as useTable$1, useRowState, useSortBy, useExpanded, usePagination } from 'react-table';
|
@@ -10,36 +9,31 @@ import { useRowSelect } from './plugins/useRowSelect.js';
|
|
10
9
|
import { useTableKeyboardNavigation } from './useTableKeyboardNavigation.js';
|
11
10
|
import { useRowDraggable } from './plugins/useRowDraggable.js';
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
var useTableRowActive = function useTableRowActive(activeIndex, rows, rowExpansionRenderer, handleonRowActive) {
|
17
|
-
React__default.useEffect(function () {
|
12
|
+
const useTableRowActive = (activeIndex, rows, rowExpansionRenderer, handleonRowActive) => {
|
13
|
+
React__default.useEffect(() => {
|
18
14
|
if (activeIndex !== undefined && rows.length && handleonRowActive) {
|
19
|
-
|
15
|
+
const focusedRow = rows[activeIndex];
|
20
16
|
|
21
17
|
if (focusedRow) {
|
22
|
-
|
18
|
+
const sanitizedFocusedRow = sanitizeRowProps(focusedRow, rowExpansionRenderer);
|
23
19
|
handleonRowActive(sanitizedFocusedRow);
|
24
20
|
}
|
25
21
|
}
|
26
22
|
}, [activeIndex, rows]);
|
27
23
|
};
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}, []);
|
42
|
-
React__default.useEffect(function () {
|
25
|
+
const useTableInstance = (instance, ref) => {
|
26
|
+
const sanitizedInstance = React__default.useMemo(() => ({
|
27
|
+
toggleAllRowsExpanded: instance.toggleAllRowsExpanded,
|
28
|
+
toggleHideAllColumns: instance.toggleHideAllColumns,
|
29
|
+
toggleHideColumn: instance.toggleHideColumn,
|
30
|
+
toggleEditing: instance.toggleEditing,
|
31
|
+
toggleRowEditing: instance.toggleRowEditing,
|
32
|
+
resetRowEditing: instance.resetRowEditing,
|
33
|
+
toggleRowExpanded: instance.toggleRowExpanded,
|
34
|
+
toggleSortBy: instance.toggleSortBy
|
35
|
+
}), []);
|
36
|
+
React__default.useEffect(() => {
|
43
37
|
if (ref !== null && ref !== void 0 && ref.current) {
|
44
38
|
ref.current.instance = sanitizedInstance;
|
45
39
|
}
|
@@ -47,33 +41,29 @@ var useTableInstance = function useTableInstance(instance, ref) {
|
|
47
41
|
return sanitizedInstance;
|
48
42
|
};
|
49
43
|
|
50
|
-
|
51
|
-
React__default.useEffect(
|
44
|
+
const useTablePaginationListener = (disablePagination, onPaginate, state) => {
|
45
|
+
React__default.useEffect(() => {
|
52
46
|
if (!disablePagination && onPaginate) {
|
53
47
|
onPaginate(state.pageIndex, state.pageSize);
|
54
48
|
}
|
55
49
|
}, [state.pageIndex, state.pageSize]);
|
56
50
|
};
|
57
51
|
|
58
|
-
|
59
|
-
React__default.useEffect(
|
52
|
+
const useTableSortingListener = (data, sortedRows, onSort, manualSorting, state) => {
|
53
|
+
React__default.useEffect(() => {
|
60
54
|
if (onSort) {
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
};
|
66
|
-
});
|
55
|
+
const sortRules = state.sortBy.map(rule => ({
|
56
|
+
accessor: rule.id,
|
57
|
+
desc: rule.desc
|
58
|
+
}));
|
67
59
|
|
68
60
|
if (manualSorting) {
|
69
61
|
onSort(sortRules);
|
70
62
|
} else {
|
71
|
-
|
63
|
+
let sortedData;
|
72
64
|
|
73
65
|
if (sortRules.length && sortedRows !== null && sortedRows !== void 0 && sortedRows.length) {
|
74
|
-
sortedData = sortedRows.map(
|
75
|
-
return row.original;
|
76
|
-
});
|
66
|
+
sortedData = sortedRows.map(row => row.original);
|
77
67
|
}
|
78
68
|
|
79
69
|
onSort(sortRules, sortedData || data);
|
@@ -82,61 +72,75 @@ var useTableSortingListener = function useTableSortingListener(data, sortedRows,
|
|
82
72
|
}, [onSort && JSON.stringify(state.sortBy), manualSorting]);
|
83
73
|
};
|
84
74
|
|
85
|
-
|
86
|
-
|
75
|
+
const DEFAULT_PAGE_SIZE = 10;
|
76
|
+
const useTable = (props, ref) => {
|
87
77
|
var _otherProps$tabIndex;
|
88
78
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
79
|
+
const {
|
80
|
+
children,
|
81
|
+
data,
|
82
|
+
dangerouslyHijackGlobalKeyboardNavigation: _,
|
83
|
+
onRowClick,
|
84
|
+
onRowDrag,
|
85
|
+
onSelectedRows,
|
86
|
+
rowClassName,
|
87
|
+
rowExpansionRenderer,
|
88
|
+
rowHeight,
|
89
|
+
selectedRows,
|
90
|
+
// sorting
|
91
|
+
disableSorting,
|
92
|
+
manualSorting,
|
93
|
+
onSort,
|
94
|
+
sortRules,
|
95
|
+
//index
|
96
|
+
activeIndex: _1,
|
97
|
+
defaultActiveIndex: _2,
|
98
|
+
onChangeActiveIndex: _3,
|
99
|
+
// pagination
|
100
|
+
disablePagination = true,
|
101
|
+
length,
|
102
|
+
onPaginate,
|
103
|
+
pageSize = DEFAULT_PAGE_SIZE,
|
104
|
+
pageIndex = 0,
|
105
|
+
// row editing
|
106
|
+
inlineEditingUniqueId = undefined,
|
107
|
+
onRowCreate,
|
108
|
+
// actions
|
109
|
+
actions,
|
110
|
+
onRowEdit,
|
111
|
+
onRowCopy,
|
112
|
+
onRowDelete,
|
113
|
+
onRowActive,
|
114
|
+
windowed = false,
|
115
|
+
...otherProps
|
116
|
+
} = props;
|
121
117
|
|
122
118
|
if (onSelectedRows && !selectedRows || !onSelectedRows && selectedRows) {
|
123
119
|
throw new Error('Selected rows in a Table component are fully controlled - you must pass both the `onSelectedRows` and `selectedRows` props when using row selection');
|
124
120
|
}
|
125
121
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
122
|
+
const {
|
123
|
+
texts
|
124
|
+
} = useLocalization();
|
125
|
+
const {
|
126
|
+
columns,
|
127
|
+
sortRules: defaultSortRules
|
128
|
+
} = React__default.useMemo(() => getColumnsFromChildren(children, rowExpansionRenderer), [children, rowExpansionRenderer]);
|
129
|
+
const manualPagination = !disablePagination && !!onPaginate && !!length;
|
130
|
+
const {
|
131
|
+
headerGroups,
|
132
|
+
rows,
|
133
|
+
sortedRows,
|
134
|
+
prepareRow: prepareBaseRow,
|
135
|
+
state,
|
136
|
+
// pagination
|
137
|
+
page,
|
138
|
+
gotoPage,
|
139
|
+
setPageSize,
|
140
|
+
...instance
|
141
|
+
} = useTable$1({
|
142
|
+
columns,
|
143
|
+
data,
|
140
144
|
initialState: {
|
141
145
|
// eslint-disable-next-line
|
142
146
|
// @ts-ignore: not sure how to type this correctly right now
|
@@ -144,7 +148,7 @@ var useTable = function useTable(props, ref) {
|
|
144
148
|
pageSize: !disablePagination ? pageSize : undefined,
|
145
149
|
pageIndex: !disablePagination ? pageIndex : undefined
|
146
150
|
},
|
147
|
-
manualPagination
|
151
|
+
manualPagination,
|
148
152
|
pageCount: manualPagination && length ? Math.ceil(length / pageSize) : -1,
|
149
153
|
manualSortBy: manualSorting,
|
150
154
|
disableSortBy: disableSorting,
|
@@ -153,75 +157,53 @@ var useTable = function useTable(props, ref) {
|
|
153
157
|
autoResetSelectedRows: false,
|
154
158
|
autoResetSortBy: false,
|
155
159
|
autoResetPage: false,
|
156
|
-
sortTypes: React__default.useMemo(
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
return _extends({}, currentState, {
|
162
|
-
selectedRowIds: selectedRows || []
|
163
|
-
});
|
164
|
-
}, [currentState, selectedRows]);
|
160
|
+
sortTypes: React__default.useMemo(() => sortTypes, []),
|
161
|
+
useControlledState: currentState => {
|
162
|
+
return React__default.useMemo(() => ({ ...currentState,
|
163
|
+
selectedRowIds: selectedRows || []
|
164
|
+
}), [currentState, selectedRows]);
|
165
165
|
}
|
166
166
|
}, useRowState, useSortBy, useExpanded, usePagination, useRowSelect(onSelectedRows), useRowDraggable(onRowDrag), useRowEditing(inlineEditingUniqueId), useRowActions(inlineEditingUniqueId, {
|
167
|
-
onRowCreate
|
168
|
-
onRowEdit
|
169
|
-
onRowCopy
|
170
|
-
onRowDelete
|
171
|
-
}, actions, rowExpansionRenderer, texts, windowed))
|
172
|
-
headerGroups = _useReactTable.headerGroups,
|
173
|
-
rows = _useReactTable.rows,
|
174
|
-
sortedRows = _useReactTable.sortedRows,
|
175
|
-
prepareBaseRow = _useReactTable.prepareRow,
|
176
|
-
state = _useReactTable.state,
|
177
|
-
page = _useReactTable.page,
|
178
|
-
gotoPage = _useReactTable.gotoPage,
|
179
|
-
setPageSize = _useReactTable.setPageSize,
|
180
|
-
instance = _objectWithoutPropertiesLoose(_useReactTable, _excluded2);
|
181
|
-
|
167
|
+
onRowCreate,
|
168
|
+
onRowEdit,
|
169
|
+
onRowCopy,
|
170
|
+
onRowDelete
|
171
|
+
}, actions, rowExpansionRenderer, texts, windowed));
|
182
172
|
useTablePaginationListener(disablePagination, onPaginate, state);
|
183
173
|
useTableSortingListener(data, sortedRows, onSort, !!manualSorting, state);
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
}, ref),
|
195
|
-
activeIndex = _useTableKeyboardNavi[0],
|
196
|
-
setActiveIndex = _useTableKeyboardNavi[1],
|
197
|
-
handleKeyDown = _useTableKeyboardNavi[2],
|
198
|
-
handleFocus = _useTableKeyboardNavi[3];
|
199
|
-
|
174
|
+
const sanitizedInstance = useTableInstance(instance, ref);
|
175
|
+
const visibleRows = !disablePagination && !manualPagination ? page : rows;
|
176
|
+
const [activeIndex, setActiveIndex, handleKeyDown, handleFocus] = useTableKeyboardNavigation(props, visibleRows, {
|
177
|
+
onRowClick,
|
178
|
+
onRowCreate,
|
179
|
+
onRowEdit,
|
180
|
+
onRowCopy,
|
181
|
+
onRowDelete,
|
182
|
+
rowExpansionRenderer
|
183
|
+
}, ref);
|
200
184
|
useTableRowActive(activeIndex, rows, rowExpansionRenderer, onRowActive);
|
201
|
-
|
185
|
+
const prepareRow = React__default.useCallback((row, index) => {
|
202
186
|
prepareBaseRow(row);
|
203
187
|
|
204
|
-
row.setActive =
|
205
|
-
return setActiveIndex(index);
|
206
|
-
};
|
188
|
+
row.setActive = () => setActiveIndex(index);
|
207
189
|
}, [prepareBaseRow, setActiveIndex]);
|
208
190
|
return {
|
209
191
|
rowProps: {
|
210
|
-
activeIndex
|
211
|
-
setActiveIndex
|
212
|
-
onRowClick
|
213
|
-
rowClassName
|
214
|
-
rowExpansionRenderer
|
215
|
-
rowHeight
|
216
|
-
inlineEditingUniqueId
|
192
|
+
activeIndex,
|
193
|
+
setActiveIndex,
|
194
|
+
onRowClick,
|
195
|
+
rowClassName,
|
196
|
+
rowExpansionRenderer,
|
197
|
+
rowHeight,
|
198
|
+
inlineEditingUniqueId
|
217
199
|
},
|
218
|
-
tableProps:
|
219
|
-
headerGroups
|
200
|
+
tableProps: { ...otherProps,
|
201
|
+
headerGroups,
|
220
202
|
onFocus: handleFocus,
|
221
203
|
onKeyDown: handleKeyDown,
|
222
204
|
tabIndex: (_otherProps$tabIndex = otherProps.tabIndex) !== null && _otherProps$tabIndex !== void 0 ? _otherProps$tabIndex : 0
|
223
|
-
}
|
224
|
-
state
|
205
|
+
},
|
206
|
+
state,
|
225
207
|
pagination: !disablePagination ? {
|
226
208
|
length: manualPagination && length ? length : data.length,
|
227
209
|
pageIndex: state.pageIndex,
|
@@ -230,7 +212,7 @@ var useTable = function useTable(props, ref) {
|
|
230
212
|
setPageSize: setPageSize
|
231
213
|
} : null,
|
232
214
|
rows: visibleRows,
|
233
|
-
prepareRow
|
215
|
+
prepareRow,
|
234
216
|
instance: sanitizedInstance
|
235
217
|
};
|
236
218
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTable.js","sources":["../../../../../src/components/Table/hooks/useTable.tsx"],"sourcesContent":["import React from 'react';\nimport { useTable as useReactTable, useExpanded, useSortBy, usePagination, useRowState } from 'react-table';\nimport { getColumnsFromChildren, getInternalSortRules } from '../util';\nimport { sortTypes } from '../util/sortTypes';\nimport { useRowEditing } from './plugins/useRowEditing';\nimport { useRowActions } from './plugins/useRowActions';\nimport { useRowSelect } from './plugins/useRowSelect';\nimport {\n InternalTable,\n InternalTableRow,\n PaginationHandler,\n RowActiveHandler,\n SortHandler,\n TableProps,\n TableRef,\n} from '../types';\nimport { useTableKeyboardNavigation } from './useTableKeyboardNavigation';\nimport { useLocalization } from '../../Provider/Provider';\nimport { useRowDraggable } from './plugins/useRowDraggable';\nimport { sanitizeRowProps } from '../util';\n\nconst useTableRowActive = (\n activeIndex: number | undefined,\n rows: InternalTableRow[],\n rowExpansionRenderer: TableProps<any>['rowExpansionRenderer'],\n handleonRowActive: RowActiveHandler<any> | undefined\n) => {\n React.useEffect(() => {\n if (activeIndex !== undefined && rows.length && handleonRowActive) {\n const focusedRow = rows[activeIndex];\n if (focusedRow) {\n const sanitizedFocusedRow = sanitizeRowProps(focusedRow, rowExpansionRenderer);\n handleonRowActive(sanitizedFocusedRow);\n }\n }\n }, [activeIndex, rows]);\n};\n\nconst useTableInstance = (instance: any, ref: React.RefObject<TableRef>): object => {\n const sanitizedInstance = React.useMemo(\n () => ({\n toggleAllRowsExpanded: instance.toggleAllRowsExpanded,\n toggleHideAllColumns: instance.toggleHideAllColumns,\n toggleHideColumn: instance.toggleHideColumn,\n toggleEditing: instance.toggleEditing,\n toggleRowEditing: instance.toggleRowEditing,\n resetRowEditing: instance.resetRowEditing,\n toggleRowExpanded: instance.toggleRowExpanded,\n toggleSortBy: instance.toggleSortBy,\n }),\n []\n );\n\n React.useEffect(() => {\n if (ref?.current) {\n ref.current.instance = sanitizedInstance;\n }\n }, [ref]);\n\n return sanitizedInstance;\n};\n\nconst useTablePaginationListener = (disablePagination: boolean, onPaginate: PaginationHandler | undefined, state: any): void => {\n React.useEffect(() => {\n if (!disablePagination && onPaginate) {\n onPaginate(state.pageIndex, state.pageSize);\n }\n }, [state.pageIndex, state.pageSize]);\n};\n\nconst useTableSortingListener = (\n data: any[],\n sortedRows: any[],\n onSort: SortHandler<any> | undefined,\n manualSorting: boolean,\n state: any\n): void => {\n React.useEffect(() => {\n if (onSort) {\n const sortRules = state.sortBy.map((rule: any) => ({ accessor: rule.id, desc: rule.desc }));\n\n if (manualSorting) {\n onSort(sortRules);\n } else {\n let sortedData;\n\n if (sortRules.length && sortedRows?.length) {\n sortedData = sortedRows.map((row: any) => row.original);\n }\n\n onSort(sortRules, sortedData || data);\n }\n }\n }, [onSort && JSON.stringify(state.sortBy), manualSorting]);\n};\n\nconst DEFAULT_PAGE_SIZE = 10;\n\nexport const useTable = <T extends {}>(\n props: TableProps<T> & { windowed?: boolean },\n ref: React.RefObject<TableRef>\n): InternalTable => {\n const {\n children,\n data,\n dangerouslyHijackGlobalKeyboardNavigation: _1,\n onRowClick,\n onRowDrag,\n onSelectedRows,\n rowClassName,\n rowExpansionRenderer,\n rowHeight,\n selectedRows,\n\n // sorting\n disableSorting,\n manualSorting,\n onSort,\n sortRules,\n\n // pagination\n disablePagination = true,\n length,\n onPaginate,\n pageSize = DEFAULT_PAGE_SIZE,\n pageIndex = 0,\n\n // row editing\n inlineEditingUniqueId = undefined,\n onRowCreate,\n\n // actions\n actions,\n onRowEdit,\n onRowCopy,\n onRowDelete,\n onRowActive,\n\n windowed = false,\n\n ...otherProps\n } = props;\n\n if ((onSelectedRows && !selectedRows) || (!onSelectedRows && selectedRows)) {\n throw new Error(\n 'Selected rows in a Table component are fully controlled - you must pass both the `onSelectedRows` and `selectedRows` props when using row selection'\n );\n }\n\n const { texts } = useLocalization();\n const { columns, sortRules: defaultSortRules } = React.useMemo(\n () => getColumnsFromChildren(children, rowExpansionRenderer),\n [children, rowExpansionRenderer]\n );\n\n const manualPagination = !disablePagination && !!onPaginate && !!length;\n\n const {\n headerGroups,\n rows,\n sortedRows,\n prepareRow: prepareBaseRow,\n state,\n // pagination\n page,\n gotoPage,\n setPageSize,\n ...instance\n }: any = useReactTable(\n {\n columns,\n data,\n initialState: {\n // eslint-disable-next-line\n // @ts-ignore: not sure how to type this correctly right now\n sortBy: getInternalSortRules(sortRules) || defaultSortRules,\n pageSize: !disablePagination ? pageSize : undefined,\n pageIndex: !disablePagination ? pageIndex : undefined,\n },\n manualPagination,\n pageCount: manualPagination && length ? Math.ceil(length / pageSize) : -1,\n manualSortBy: manualSorting,\n disableSortBy: disableSorting,\n // most of these resets preventions are needed for editing mode\n autoResetExpanded: false,\n autoResetSelectedRows: false,\n autoResetSortBy: false,\n autoResetPage: false,\n sortTypes: React.useMemo(() => sortTypes, []),\n useControlledState: currentState => {\n return React.useMemo(\n () => ({\n ...currentState,\n selectedRowIds: selectedRows || [],\n }),\n [currentState, selectedRows]\n );\n },\n },\n useRowState,\n useSortBy,\n useExpanded,\n usePagination,\n useRowSelect(onSelectedRows),\n useRowDraggable(onRowDrag),\n useRowEditing(inlineEditingUniqueId),\n useRowActions(\n inlineEditingUniqueId,\n { onRowCreate, onRowEdit, onRowCopy, onRowDelete },\n actions,\n rowExpansionRenderer,\n texts,\n windowed\n )\n );\n\n useTablePaginationListener(disablePagination, onPaginate, state);\n useTableSortingListener(data, sortedRows, onSort, !!manualSorting, state);\n\n const sanitizedInstance = useTableInstance(instance, ref);\n\n const visibleRows = !disablePagination && !manualPagination ? page : rows;\n\n const [activeIndex, setActiveIndex, handleKeyDown, handleFocus] = useTableKeyboardNavigation<T>(\n props,\n visibleRows,\n { onRowClick, onRowCreate, onRowEdit, onRowCopy, onRowDelete, rowExpansionRenderer },\n ref\n );\n\n useTableRowActive(activeIndex, rows, rowExpansionRenderer, onRowActive);\n\n const prepareRow = React.useCallback(\n (row: any, index: number) => {\n prepareBaseRow(row);\n row.setActive = () => setActiveIndex(index);\n },\n [prepareBaseRow, setActiveIndex]\n );\n\n return {\n rowProps: {\n activeIndex,\n setActiveIndex,\n onRowClick,\n rowClassName,\n rowExpansionRenderer,\n rowHeight,\n inlineEditingUniqueId,\n },\n tableProps: {\n ...otherProps,\n headerGroups,\n onFocus: handleFocus,\n onKeyDown: handleKeyDown,\n tabIndex: otherProps.tabIndex ?? 0,\n },\n state,\n pagination: !disablePagination\n ? {\n length: manualPagination && length ? length : data.length,\n pageIndex: state.pageIndex,\n pageSize: state.pageSize,\n setPageIndex: gotoPage,\n setPageSize: setPageSize,\n }\n : null,\n rows: visibleRows,\n prepareRow,\n instance: sanitizedInstance,\n };\n};\n"],"names":["useTableRowActive","activeIndex","rows","rowExpansionRenderer","handleonRowActive","React","useEffect","undefined","length","focusedRow","sanitizedFocusedRow","sanitizeRowProps","useTableInstance","instance","ref","sanitizedInstance","useMemo","toggleAllRowsExpanded","toggleHideAllColumns","toggleHideColumn","toggleEditing","toggleRowEditing","resetRowEditing","toggleRowExpanded","toggleSortBy","current","useTablePaginationListener","disablePagination","onPaginate","state","pageIndex","pageSize","useTableSortingListener","data","sortedRows","onSort","manualSorting","sortRules","sortBy","map","rule","accessor","id","desc","sortedData","row","original","JSON","stringify","DEFAULT_PAGE_SIZE","useTable","props","children","onRowClick","onRowDrag","onSelectedRows","rowClassName","rowHeight","selectedRows","disableSorting","inlineEditingUniqueId","onRowCreate","actions","onRowEdit","onRowCopy","onRowDelete","onRowActive","windowed","otherProps","Error","useLocalization","texts","getColumnsFromChildren","columns","defaultSortRules","manualPagination","useReactTable","initialState","getInternalSortRules","pageCount","Math","ceil","manualSortBy","disableSortBy","autoResetExpanded","autoResetSelectedRows","autoResetSortBy","autoResetPage","sortTypes","useControlledState","currentState","selectedRowIds","useRowState","useSortBy","useExpanded","usePagination","useRowSelect","useRowDraggable","useRowEditing","useRowActions","headerGroups","prepareBaseRow","prepareRow","page","gotoPage","setPageSize","visibleRows","useTableKeyboardNavigation","setActiveIndex","handleKeyDown","handleFocus","useCallback","index","setActive","rowProps","tableProps","onFocus","onKeyDown","tabIndex","pagination","setPageIndex"],"mappings":";;;;;;;;;;;;;;;AAqBA,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,CACtBC,WADsB,EAEtBC,IAFsB,EAGtBC,oBAHsB,EAItBC,iBAJsB;EAMtBC,cAAK,CAACC,SAAN,CAAgB;IACZ,IAAIL,WAAW,KAAKM,SAAhB,IAA6BL,IAAI,CAACM,MAAlC,IAA4CJ,iBAAhD,EAAmE;MAC/D,IAAMK,UAAU,GAAGP,IAAI,CAACD,WA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,UAAU,EAAVA,UA5BG;IA6BHzF,QAAQ,EAAEE;GA7Bd;AA+BH;;;;"}
|
1
|
+
{"version":3,"file":"useTable.js","sources":["../../../../../src/components/Table/hooks/useTable.tsx"],"sourcesContent":["import React from 'react';\nimport { useTable as useReactTable, useExpanded, useSortBy, usePagination, useRowState } from 'react-table';\nimport { getColumnsFromChildren, getInternalSortRules } from '../util';\nimport { sortTypes } from '../util/sortTypes';\nimport { useRowEditing } from './plugins/useRowEditing';\nimport { useRowActions } from './plugins/useRowActions';\nimport { useRowSelect } from './plugins/useRowSelect';\nimport {\n InternalTable,\n InternalTableRow,\n PaginationHandler,\n RowActiveHandler,\n SortHandler,\n TableProps,\n TableRef,\n} from '../types';\nimport { useTableKeyboardNavigation } from './useTableKeyboardNavigation';\nimport { useLocalization } from '../../Provider/Provider';\nimport { useRowDraggable } from './plugins/useRowDraggable';\nimport { sanitizeRowProps } from '../util';\n\nconst useTableRowActive = (\n activeIndex: number | undefined,\n rows: InternalTableRow[],\n rowExpansionRenderer: TableProps<any>['rowExpansionRenderer'],\n handleonRowActive: RowActiveHandler<any> | undefined\n) => {\n React.useEffect(() => {\n if (activeIndex !== undefined && rows.length && handleonRowActive) {\n const focusedRow = rows[activeIndex];\n if (focusedRow) {\n const sanitizedFocusedRow = sanitizeRowProps(focusedRow, rowExpansionRenderer);\n handleonRowActive(sanitizedFocusedRow);\n }\n }\n }, [activeIndex, rows]);\n};\n\nconst useTableInstance = (instance: any, ref: React.RefObject<TableRef>): object => {\n const sanitizedInstance = React.useMemo(\n () => ({\n toggleAllRowsExpanded: instance.toggleAllRowsExpanded,\n toggleHideAllColumns: instance.toggleHideAllColumns,\n toggleHideColumn: instance.toggleHideColumn,\n toggleEditing: instance.toggleEditing,\n toggleRowEditing: instance.toggleRowEditing,\n resetRowEditing: instance.resetRowEditing,\n toggleRowExpanded: instance.toggleRowExpanded,\n toggleSortBy: instance.toggleSortBy,\n }),\n []\n );\n\n React.useEffect(() => {\n if (ref?.current) {\n ref.current.instance = sanitizedInstance;\n }\n }, [ref]);\n\n return sanitizedInstance;\n};\n\nconst useTablePaginationListener = (disablePagination: boolean, onPaginate: PaginationHandler | undefined, state: any): void => {\n React.useEffect(() => {\n if (!disablePagination && onPaginate) {\n onPaginate(state.pageIndex, state.pageSize);\n }\n }, [state.pageIndex, state.pageSize]);\n};\n\nconst useTableSortingListener = (\n data: any[],\n sortedRows: any[],\n onSort: SortHandler<any> | undefined,\n manualSorting: boolean,\n state: any\n): void => {\n React.useEffect(() => {\n if (onSort) {\n const sortRules = state.sortBy.map((rule: any) => ({ accessor: rule.id, desc: rule.desc }));\n\n if (manualSorting) {\n onSort(sortRules);\n } else {\n let sortedData;\n\n if (sortRules.length && sortedRows?.length) {\n sortedData = sortedRows.map((row: any) => row.original);\n }\n\n onSort(sortRules, sortedData || data);\n }\n }\n }, [onSort && JSON.stringify(state.sortBy), manualSorting]);\n};\n\nconst DEFAULT_PAGE_SIZE = 10;\n\nexport const useTable = <T extends {}>(\n props: TableProps<T> & { windowed?: boolean },\n ref: React.RefObject<TableRef>\n): InternalTable => {\n const {\n children,\n data,\n dangerouslyHijackGlobalKeyboardNavigation: _,\n onRowClick,\n onRowDrag,\n onSelectedRows,\n rowClassName,\n rowExpansionRenderer,\n rowHeight,\n selectedRows,\n\n // sorting\n disableSorting,\n manualSorting,\n onSort,\n sortRules,\n\n //index\n activeIndex: _1,\n defaultActiveIndex: _2,\n onChangeActiveIndex: _3,\n\n // pagination\n disablePagination = true,\n length,\n onPaginate,\n pageSize = DEFAULT_PAGE_SIZE,\n pageIndex = 0,\n\n // row editing\n inlineEditingUniqueId = undefined,\n onRowCreate,\n\n // actions\n actions,\n onRowEdit,\n onRowCopy,\n onRowDelete,\n onRowActive,\n\n windowed = false,\n\n ...otherProps\n } = props;\n\n if ((onSelectedRows && !selectedRows) || (!onSelectedRows && selectedRows)) {\n throw new Error(\n 'Selected rows in a Table component are fully controlled - you must pass both the `onSelectedRows` and `selectedRows` props when using row selection'\n );\n }\n\n const { texts } = useLocalization();\n const { columns, sortRules: defaultSortRules } = React.useMemo(\n () => getColumnsFromChildren(children, rowExpansionRenderer),\n [children, rowExpansionRenderer]\n );\n\n const manualPagination = !disablePagination && !!onPaginate && !!length;\n\n const {\n headerGroups,\n rows,\n sortedRows,\n prepareRow: prepareBaseRow,\n state,\n // pagination\n page,\n gotoPage,\n setPageSize,\n ...instance\n }: any = useReactTable(\n {\n columns,\n data,\n initialState: {\n // eslint-disable-next-line\n // @ts-ignore: not sure how to type this correctly right now\n sortBy: getInternalSortRules(sortRules) || defaultSortRules,\n pageSize: !disablePagination ? pageSize : undefined,\n pageIndex: !disablePagination ? pageIndex : undefined,\n },\n manualPagination,\n pageCount: manualPagination && length ? Math.ceil(length / pageSize) : -1,\n manualSortBy: manualSorting,\n disableSortBy: disableSorting,\n // most of these resets preventions are needed for editing mode\n autoResetExpanded: false,\n autoResetSelectedRows: false,\n autoResetSortBy: false,\n autoResetPage: false,\n sortTypes: React.useMemo(() => sortTypes, []),\n useControlledState: currentState => {\n return React.useMemo(\n () => ({\n ...currentState,\n selectedRowIds: selectedRows || [],\n }),\n [currentState, selectedRows]\n );\n },\n },\n useRowState,\n useSortBy,\n useExpanded,\n usePagination,\n useRowSelect(onSelectedRows),\n useRowDraggable(onRowDrag),\n useRowEditing(inlineEditingUniqueId),\n useRowActions(\n inlineEditingUniqueId,\n { onRowCreate, onRowEdit, onRowCopy, onRowDelete },\n actions,\n rowExpansionRenderer,\n texts,\n windowed\n )\n );\n\n useTablePaginationListener(disablePagination, onPaginate, state);\n useTableSortingListener(data, sortedRows, onSort, !!manualSorting, state);\n\n const sanitizedInstance = useTableInstance(instance, ref);\n\n const visibleRows = !disablePagination && !manualPagination ? page : rows;\n\n const [activeIndex, setActiveIndex, handleKeyDown, handleFocus] = useTableKeyboardNavigation<T>(\n props,\n visibleRows,\n { onRowClick, onRowCreate, onRowEdit, onRowCopy, onRowDelete, rowExpansionRenderer },\n ref\n );\n\n useTableRowActive(activeIndex, rows, rowExpansionRenderer, onRowActive);\n\n const prepareRow = React.useCallback(\n (row: any, index: number) => {\n prepareBaseRow(row);\n row.setActive = () => setActiveIndex(index);\n },\n [prepareBaseRow, setActiveIndex]\n );\n\n return {\n rowProps: {\n activeIndex,\n setActiveIndex,\n onRowClick,\n rowClassName,\n rowExpansionRenderer,\n rowHeight,\n inlineEditingUniqueId,\n },\n tableProps: {\n ...otherProps,\n headerGroups,\n onFocus: handleFocus,\n onKeyDown: handleKeyDown,\n tabIndex: otherProps.tabIndex ?? 0,\n },\n state,\n pagination: !disablePagination\n ? {\n length: manualPagination && length ? length : data.length,\n pageIndex: state.pageIndex,\n pageSize: state.pageSize,\n setPageIndex: gotoPage,\n setPageSize: setPageSize,\n }\n : null,\n rows: visibleRows,\n prepareRow,\n instance: sanitizedInstance,\n };\n};\n"],"names":["useTableRowActive","activeIndex","rows","rowExpansionRenderer","handleonRowActive","React","useEffect","undefined","length","focusedRow","sanitizedFocusedRow","sanitizeRowProps","useTableInstance","instance","ref","sanitizedInstance","useMemo","toggleAllRowsExpanded","toggleHideAllColumns","toggleHideColumn","toggleEditing","toggleRowEditing","resetRowEditing","toggleRowExpanded","toggleSortBy","current","useTablePaginationListener","disablePagination","onPaginate","state","pageIndex","pageSize","useTableSortingListener","data","sortedRows","onSort","manualSorting","sortRules","sortBy","map","rule","accessor","id","desc","sortedData","row","original","JSON","stringify","DEFAULT_PAGE_SIZE","useTable","props","children","dangerouslyHijackGlobalKeyboardNavigation","_","onRowClick","onRowDrag","onSelectedRows","rowClassName","rowHeight","selectedRows","disableSorting","_1","defaultActiveIndex","_2","onChangeActiveIndex","_3","inlineEditingUniqueId","onRowCreate","actions","onRowEdit","onRowCopy","onRowDelete","onRowActive","windowed","otherProps","Error","texts","useLocalization","columns","defaultSortRules","getColumnsFromChildren","manualPagination","headerGroups","prepareRow","prepareBaseRow","page","gotoPage","setPageSize","useReactTable","initialState","getInternalSortRules","pageCount","Math","ceil","manualSortBy","disableSortBy","autoResetExpanded","autoResetSelectedRows","autoResetSortBy","autoResetPage","sortTypes","useControlledState","currentState","selectedRowIds","useRowState","useSortBy","useExpanded","usePagination","useRowSelect","useRowDraggable","useRowEditing","useRowActions","visibleRows","setActiveIndex","handleKeyDown","handleFocus","useTableKeyboardNavigation","useCallback","index","setActive","rowProps","tableProps","onFocus","onKeyDown","tabIndex","pagination","setPageIndex"],"mappings":";;;;;;;;;;;AAqBA,MAAMA,iBAAiB,GAAG,CACtBC,WADsB,EAEtBC,IAFsB,EAGtBC,oBAHsB,EAItBC,iBAJsB;EAMtBC,cAAK,CAACC,SAAN,CAAgB;IACZ,IAAIL,WAAW,KAAKM,SAAhB,IAA6BL,IAAI,CAACM,MAAlC,IAA4CJ,iBAAhD,EAAmE;MAC/D,MAAMK,UAAU,GAAGP,IAAI,CAACD,WAAD,CAAvB;;MACA,IAAIQ,UAAJ,EAAgB;QACZ,MAAMC,mBAAmB,GAAGC,gBAAgB,CAACF,UAAD,EAAaN,oBAAb,CAA5C;QACAC,iBAAiB,CAACM,mBAAD,CAAjB;;;GALZ,EAQG,CAACT,WAAD,EAAcC,IAAd,CARH;AASH,CAfD;;AAiBA,MAAMU,gBAAgB,GAAG,CAACC,QAAD,EAAgBC,GAAhB;EACrB,MAAMC,iBAAiB,GAAGV,cAAK,CAACW,OAAN,CACtB,OAAO;IACHC,qBAAqB,EAAEJ,QAAQ,CAACI,qBAD7B;IAEHC,oBAAoB,EAAEL,QAAQ,CAACK,oBAF5B;IAGHC,gBAAgB,EAAEN,QAAQ,CAACM,gBAHxB;IAIHC,aAAa,EAAEP,QAAQ,CAACO,aAJrB;IAKHC,gBAAgB,EAAER,QAAQ,CAACQ,gBALxB;IAMHC,eAAe,EAAET,QAAQ,CAACS,eANvB;IAOHC,iBAAiB,EAAEV,QAAQ,CAACU,iBAPzB;IAQHC,YAAY,EAAEX,QAAQ,CAACW;GAR3B,CADsB,EAWtB,EAXsB,CAA1B;EAcAnB,cAAK,CAACC,SAAN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WAHD;MAIRQ,SAAS,EAAET,aAJH;MAKRU,QAAQ,0BAAElD,UAAU,CAACkD,QAAb,uEAAyB;KAflC;IAiBHhG,KAjBG;IAkBHiG,UAAU,EAAE,CAACnG,iBAAD,GACN;MACInB,MAAM,EAAE0E,gBAAgB,IAAI1E,MAApB,GAA6BA,MAA7B,GAAsCyB,IAAI,CAACzB,MADvD;MAEIsB,SAAS,EAAED,KAAK,CAACC,SAFrB;MAGIC,QAAQ,EAAEF,KAAK,CAACE,QAHpB;MAIIgG,YAAY,EAAExC,QAJlB;MAKIC,WAAW,EAAEA;KANX,GAQN,IA1BH;IA2BHtF,IAAI,EAAE+G,WA3BH;IA4BH7B,UA5BG;IA6BHvE,QAAQ,EAAEE;GA7Bd;AA+BH;;;;"}
|
@@ -1,24 +1,20 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import
|
3
|
-
import { getNextIndexFromKeycode } from '../../../utils/hooks/useListKeyboardNavigation.js';
|
2
|
+
import { getNextIndexFromKey } from '../../../utils/hooks/useListKeyboardNavigation.js';
|
4
3
|
import { sanitizeRowProps } from '../util.js';
|
5
4
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
var _useControllableState = useControllableState({
|
6
|
+
const useTableKeyboardNavigation = (props, rows, rowProps, ref) => {
|
7
|
+
const useGlobalKeyboardNavigation = props.dangerouslyHijackGlobalKeyboardNavigation;
|
8
|
+
const [activeIndex, setActiveIndex] = useControllableState({
|
11
9
|
prop: props.activeIndex,
|
12
10
|
defaultProp: props.defaultActiveIndex !== undefined ? props.defaultActiveIndex : useGlobalKeyboardNavigation ? 0 : undefined,
|
13
11
|
onChange: props.onChangeActiveIndex
|
14
|
-
})
|
15
|
-
activeIndex = _useControllableState[0],
|
16
|
-
setActiveIndex = _useControllableState[1];
|
12
|
+
});
|
17
13
|
|
18
|
-
|
14
|
+
const onKeyDown = event => {
|
19
15
|
var _document$activeEleme;
|
20
16
|
|
21
|
-
|
17
|
+
const isModifierKeyPressed = event.metaKey || event.ctrlKey || event.altKey || event.shiftKey;
|
22
18
|
|
23
19
|
if (useGlobalKeyboardNavigation && document.activeElement !== ref.current && ((_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.getAttribute('type')) !== 'search' && document.activeElement !== document.body) {
|
24
20
|
return;
|
@@ -30,29 +26,29 @@ var useTableKeyboardNavigation = function useTableKeyboardNavigation(props, rows
|
|
30
26
|
}
|
31
27
|
|
32
28
|
if (activeIndex !== undefined) {
|
33
|
-
|
29
|
+
const currentRow = rows[activeIndex];
|
34
30
|
|
35
31
|
if (currentRow) {
|
36
|
-
|
32
|
+
const sanitizedRow = sanitizeRowProps(currentRow, rowProps.rowExpansionRenderer);
|
37
33
|
|
38
|
-
if (rowProps.onRowClick && event.
|
34
|
+
if (rowProps.onRowClick && event.key === 'Enter') {
|
39
35
|
event.preventDefault();
|
40
36
|
rowProps.onRowClick(sanitizedRow);
|
41
37
|
return;
|
42
38
|
}
|
43
39
|
|
44
|
-
if (currentRow.toggleRowSelected && event.
|
40
|
+
if (currentRow.toggleRowSelected && event.key === ' ') {
|
45
41
|
event.preventDefault();
|
46
42
|
currentRow.toggleRowSelected();
|
47
43
|
return;
|
48
44
|
}
|
49
45
|
|
50
46
|
if (currentRow.toggleRowExpanded) {
|
51
|
-
if (currentRow.isExpanded && event.
|
47
|
+
if (currentRow.isExpanded && event.key === 'ArrowLeft') {
|
52
48
|
event.preventDefault();
|
53
49
|
currentRow.toggleRowExpanded();
|
54
50
|
return;
|
55
|
-
} else if (!currentRow.isExpanded && event.
|
51
|
+
} else if (!currentRow.isExpanded && event.key === 'ArrowRight') {
|
56
52
|
event.preventDefault();
|
57
53
|
currentRow.toggleRowExpanded();
|
58
54
|
return;
|
@@ -62,7 +58,7 @@ var useTableKeyboardNavigation = function useTableKeyboardNavigation(props, rows
|
|
62
58
|
|
63
59
|
if (currentRow.toggleRowEditing) {
|
64
60
|
if (currentRow.canEdit && !currentRow.isEditing) {
|
65
|
-
if (rowProps.onRowCreate && event.shiftKey && event.
|
61
|
+
if (rowProps.onRowCreate && event.shiftKey && event.key === 'n') {
|
66
62
|
event.preventDefault();
|
67
63
|
|
68
64
|
if (!currentRow.isExpanded) {
|
@@ -73,7 +69,7 @@ var useTableKeyboardNavigation = function useTableKeyboardNavigation(props, rows
|
|
73
69
|
return;
|
74
70
|
}
|
75
71
|
|
76
|
-
if (event.
|
72
|
+
if (event.key === 'e') {
|
77
73
|
event.preventDefault();
|
78
74
|
currentRow.toggleRowEditing();
|
79
75
|
return;
|
@@ -81,19 +77,19 @@ var useTableKeyboardNavigation = function useTableKeyboardNavigation(props, rows
|
|
81
77
|
}
|
82
78
|
}
|
83
79
|
|
84
|
-
if (rowProps.onRowEdit && event.
|
80
|
+
if (rowProps.onRowEdit && event.key === 'e' && !isModifierKeyPressed) {
|
85
81
|
event.preventDefault();
|
86
82
|
rowProps.onRowEdit(sanitizedRow, event);
|
87
83
|
return;
|
88
84
|
}
|
89
85
|
|
90
|
-
if (rowProps.onRowCopy && event.
|
86
|
+
if (rowProps.onRowCopy && event.key === 'c' && !isModifierKeyPressed) {
|
91
87
|
event.preventDefault();
|
92
88
|
rowProps.onRowCopy(sanitizedRow, event);
|
93
89
|
return;
|
94
90
|
}
|
95
91
|
|
96
|
-
if (rowProps.onRowDelete && event.
|
92
|
+
if (rowProps.onRowDelete && event.key === 'Delete' && !isModifierKeyPressed) {
|
97
93
|
event.preventDefault();
|
98
94
|
rowProps.onRowDelete(sanitizedRow, event);
|
99
95
|
return;
|
@@ -101,7 +97,7 @@ var useTableKeyboardNavigation = function useTableKeyboardNavigation(props, rows
|
|
101
97
|
}
|
102
98
|
}
|
103
99
|
|
104
|
-
|
100
|
+
const nextIndex = getNextIndexFromKey(event.key, rows.length, activeIndex);
|
105
101
|
|
106
102
|
if (nextIndex !== undefined) {
|
107
103
|
event.preventDefault();
|
@@ -109,25 +105,25 @@ var useTableKeyboardNavigation = function useTableKeyboardNavigation(props, rows
|
|
109
105
|
}
|
110
106
|
};
|
111
107
|
|
112
|
-
|
108
|
+
const handleKeyDown = event => {
|
113
109
|
if (!useGlobalKeyboardNavigation) {
|
114
110
|
onKeyDown(event.nativeEvent);
|
115
111
|
}
|
116
112
|
};
|
117
113
|
|
118
|
-
React__default.useEffect(
|
114
|
+
React__default.useEffect(() => {
|
119
115
|
if (useGlobalKeyboardNavigation) {
|
120
116
|
window.addEventListener('keydown', onKeyDown);
|
121
117
|
}
|
122
118
|
|
123
|
-
return
|
119
|
+
return () => {
|
124
120
|
if (useGlobalKeyboardNavigation) {
|
125
121
|
window.removeEventListener('keydown', onKeyDown);
|
126
122
|
}
|
127
123
|
};
|
128
124
|
}, [onKeyDown]);
|
129
125
|
|
130
|
-
|
126
|
+
const handleFocus = () => {
|
131
127
|
if (activeIndex === undefined && rows.length) {
|
132
128
|
setActiveIndex(0);
|
133
129
|
}
|