Compare commits

..
Author SHA1 Message Date
Tanner Linsley b3956ce891 v7.0.0-beta.26 2019-12-03 12:57:41 -07:00
Tanner Linsley 5d81f95d9b Upgrade examples to use "latest" 2019-12-03 12:55:01 -07:00
Tanner Linsley 403bb2848b Merge branch 'master' of https://github.com/react-tools/react-table 2019-12-03 12:54:51 -07:00
Tanner Linsley 1b1fda6815 Remove typescript dep 2019-12-03 12:54:35 -07:00
Cody SchwebkeandTanner Linsley 7014647b4a fix: fix crash in useSortBy resetSortBy action (#1695) 2019-12-03 12:52:08 -07:00
onnadi-saandTanner Linsley 872cb49242 Change An -> A (#1693) 2019-12-03 12:31:03 -07:00
onnadi-saandTanner Linsley 945bf18ee0 Fix typo (#1692) 2019-12-03 12:04:18 -07:00
size-plugin[bot]andGitHub 1e321f22d3 🇱🇧 👩🏾‍🚒 update sizes-es.json 👍 2019-12-03 16:44:30 +00:00
size-plugin[bot]andGitHub 2740e55d76 🎴 🤗 update sizes-cjs.json 👍 2019-12-03 16:44:29 +00:00
Tanner Linsley 6b88340051 Merge branch 'master' of https://github.com/react-tools/react-table 2019-12-03 09:42:27 -07:00
Tanner Linsley 92603b6a70 v7.0.0-beta.24 2019-12-03 09:40:53 -07:00
size-plugin[bot]andGitHub 09c212ec6c 👭🏾 🚜 update sizes-es.json 👍 2019-12-03 03:50:37 +00:00
size-plugin[bot]andGitHub 482cef191f 👳🏼‍♀️ 😆 update sizes-cjs.json 👍 2019-12-03 03:50:37 +00:00
Roman KovtunandTanner Linsley d7da8b631d Fix issue with missing columnId in updater on column spread (#1682) 2019-12-02 20:49:04 -07:00
size-plugin[bot]andGitHub 85153d287f 🏃‍♂️ ⏺️ create sizes-es.json 👍 2019-12-03 00:08:05 +00:00
size-plugin[bot]andGitHub c7ac522da3 👩🏾🤝👨🏽 🌈 create sizes-cjs.json 👍 2019-12-03 00:08:04 +00:00
anotherjsguyandTanner Linsley 5393ebc7fa setup size-plugin-bot (#1677)
* setup size-plugin-bot

* Update package.json
2019-12-02 17:06:31 -07:00
Tanner Linsley f74e347a06 v7.0.0-beta.23 2019-12-02 16:53:57 -07:00
Tanner Linsley ef29b639bd Update CHANGELOG.md 2019-12-02 16:52:37 -07:00
Tanner Linsley 12b5d05ba2 Fix column resizing 2019-12-02 16:52:10 -07:00
Tanner Linsley f9a6273184 Rename useMain and useBeforeDimensions hooks 2019-12-02 16:12:23 -07:00
Tanner Linsley 83f889dad5 v7.0.0-beta.22 2019-12-02 12:29:46 -07:00
Tanner Linsley 49674a094a Update README.md 2019-12-02 11:18:06 -07:00
52 changed files with 337 additions and 941 deletions
+3
View File
@@ -0,0 +1,3 @@
size-files:
- sizes-cjs.json
- sizes-es.json
+7 -7
View File
@@ -1,20 +1,20 @@
{
"dist/index.js": {
"bundled": 96409,
"minified": 46532,
"gzipped": 12274
"bundled": 96781,
"minified": 46762,
"gzipped": 12304
},
"dist/index.es.js": {
"bundled": 95844,
"minified": 46040,
"gzipped": 12164,
"bundled": 96216,
"minified": 46270,
"gzipped": 12188,
"treeshaked": {
"rollup": {
"code": 78,
"import_statements": 21
},
"webpack": {
"code": 11105
"code": 11143
}
}
}
+19
View File
@@ -1,3 +1,22 @@
## 7.0.0-beta.25
- Fixed an issue where `useRowState` would crash due to invalid initial state of previous cell state on `columnId` lookup
## 7.0.0-beta.24
- Changed `selectedRowPaths` to use a `Set()` instead of an array for performance.
- Removed types and related files from the repo. The community will now maintain types externally on Definitely Typed
## 7.0.0-beta.23
- The internal `useMain` hook has been renamed to `useInstance`
- The internal `useBeforeDimensions` hook has been renamed to `useInstanceBeforeDimensions`
- Fixed an issue where `useResizeColumns` wasn't working properly
## 7.0.0-beta.22
- Fixed an issue where `useRowState` would crash due to invalid initial state attempting to spread into the new state
## 7.0.0-beta.21
- Removed deprecated `defaultState` export
+17 -24
View File
@@ -37,36 +37,13 @@ Enjoy this library? Try them all! [React Query](https://github.com/tannerlinsley
- Extensible via hook-based plugin system
- <a href="https://medium.com/@tannerlinsley/why-i-wrote-react-table-and-the-problems-it-has-solved-for-nozzle-others-445c4e93d4a8#.axza4ixba" target="\_parent">"Why I wrote React Table and the problems it has solved for Nozzle.io"</a> by Tanner Linsley
## News / Q&A
#### What is the current state of React Table?
React Table v7 is still under active development, and its API is still changing, albeit only slightly. For this reason, it is currently in an **beta** release state. It's estimated that it will be fully released as a stable version sometime during October 2019.
#### Should I use v7@beta in production?
You can use it in production as long as you lock in the beta version in your package.json and also accept that there may be unlikely, but possible bug fixes and/or API changes before it's official release.
#### I'm still using v6, what should I do?
v6 is a great library and is still the default install for `react-table`, however, I do not intend on offering any long-term support for it. If you intend to keep using v6, I recommend maintaining your own fork of the library and keeping it up to date for your version of React.
#### Where are the docs for the older v6 version?
Please [visit the v6 branch](https://github.com/tannerlinsley/react-table/tree/v6)
#### I want to migrate from v6 to v7. How do I do that?
The differences between the 2 versions are incredibly massive. Unfortunately, I cannot write a one-to-one upgrade guide for any of v6's API, simply because much of it is irrelevant with v7's headless approach. The best approach for migrating to v7 is to learn its API by reading the documentation and then following some of the examples to begin building your own table component.
In case you would need to have both v6 and v7 in one app during the migration process (large codebase, complex use cases), you can install an official [`react-table-6` package](https://www.npmjs.com/package/react-table-6) alongside the `react-table`.
## Documentation
- [Installation](./docs/installation.md) - Walk through how to install React Table
- [Concepts](./docs/concepts.md) - Read how React Table works and how you can use it better
- [Examples](./docs/examples.md) - Experience and learn from some examples and guides of how to use React Table and implement common patterns
- [API](./docs/api.md) - Get to know React Table's API, how to use it and how to extend its functionality
- [Using V6 Still?](#v6-info)
- [Contributing](./CONTRIBUTING.md) - Become familiar with how to contribute back to React Table
- [Code of Conduct](./CODE_OF_CONDUCT.md) - Be a good React Table citizen by following these repository rules
@@ -216,3 +193,19 @@ This library is being built and maintained by me, @tannerlinsley and I am always
</table>
### [Become a Sponsor](https://github.com/sponsors/tannerlinsley/)
## v6 Info
#### I'm still using v6, what should I do?
v6 is a great library and while it is still available for use, I do not intend on offering any long-term support for it. If you intend to keep using v6, I recommend maintaining your own fork of the library and keeping it up to date for your version of React.
#### Where are the docs for the older v6 version?
Please [visit the v6 branch](https://github.com/tannerlinsley/react-table/tree/v6)
#### I want to migrate from v6 to v7. How do I do that?
The differences between the 2 versions are incredibly massive. Unfortunately, I cannot write a one-to-one upgrade guide for any of v6's API, simply because much of it is irrelevant with v7's headless approach. The best approach for migrating to v7 is to learn its API by reading the documentation and then following some of the examples to begin building your own table component.
In case you would need to have both v6 and v7 in one app during the migration process (large codebase, complex use cases), you can install an official [`react-table-6` package](https://www.npmjs.com/package/react-table-6) alongside the `react-table`.
+2 -36
View File
@@ -1,39 +1,5 @@
# Using TypeScript with React-Table
React-table is a very flexible library, because of this, the shape of data at almost every contact point is defined by the specific set of plugins that you choose to pass to `useTable`.
Types for React Table are maintained externally by the Typescript community and are located at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table.
To get started, copy the file `react-table-config.d.ts` into your source tree (e.g. into a types folder). This expands the default types with all of the plugin extensions currently in the type definitions.
You can stop here if you like, but while this is simple, it's a bit misleading. Out of the box, these types will suggest that you have access to values that come from plugins that you aren't using, i.e. the error checking is weakened.
To bring the resulting types into better alignment with your plugins, you should edit your local copy of `react-table-config.d.ts` and comment out all of the interfaces that don't apply to your chosen set of plugins.
e.g.
if you are only using `useSortBy` and `usePagination` then you would take this:
```tsx
extends UseExpandedOptions<D>,
UseFiltersOptions<D>,
UseGroupByOptions<D>,
UsePaginationOptions<D>,
UseRowSelectOptions<D>,
UseSortByOptions<D>,
UseFiltersOptions<D>,
UseResizeColumnsOptions<D>,
Record<string, any> {}
```
and convert it to this:
```tsx
export interface TableOptions<D extends object>
extends UsePaginationOptions<D>,
UseSortByOptions<D> {}
```
Then follow the same pattern for all of the other interfaces in the file. You'll notice that many plugins don't extend all of the top-level interfaces.
## Caveat
The interfaces are all global. If you have several different configurations for the table, you should create interfaces using the union of all of the plugins that you are using.
Because React Table is not written in Typescript and the types are not maintained by the core team, there are no guarantees around the types always being up to date or working perfectly. If this is an issue for you, please contribute to the community types and discuss solutions there.
+5 -5
View File
@@ -25,7 +25,7 @@ React Table is essentially a compatible collection of **custom React hooks**:
### Hook Usage
`useTable` is the **primary** hook used to build a React Table. It serves as the starting point for **every option and every plugin hook** that React Table supports. The options passed into `useTable` are supplied to every plugin hook after it in the order they are supplied, eventually resulting a final `instance` object that you can use to build your table UI and interact with the table's state.
`useTable` is the **primary** hook used to build a React Table. It serves as the starting point for **every option and every plugin hook** that React Table supports. The options passed into `useTable` are supplied to every plugin hook after it in the order they are supplied, eventually resulting in a final `instance` object that you can use to build your table UI and interact with the table's state.
```js
const instance = useTable(
@@ -196,7 +196,7 @@ The following properties are available on the table instance returned from `useT
- **Some of these headers may be materialized as placeholders**
- See [Header Group Properties](#headergroup-properties) for more information
- `headers: Array<Column>`
- An **nested** array of final header objects, **similar in structure to the original columns configuration option, but rebuilt for ordering**
- A **nested** array of final header objects, **similar in structure to the original columns configuration option, but rebuilt for ordering**
- Each contains the headers that are displayed underneath it.
- **Some of these headers may be materialized as placeholders**
- See [Column Properties](#column-properties) for more information
@@ -535,7 +535,7 @@ The following properties are available on every `Column` object returned by the
- `canFilter: Bool`
- Denotes whether a column is filterable or not depending on if it has a valid accessor/data model or is manually disabled via an option.
- `setFilter: Function(filterValue) => void`
- An column-level function used to update the filter value for this column
- A column-level function used to update the filter value for this column
- `filterValue: any`
- The current filter value for this column, resolved from the table state's `filters` object
- `preFilteredRows: Array<row>`
@@ -847,9 +847,9 @@ The following values are provided to the table `instance`:
The following options are supported via the main options object passed to `useTable(options)`
- `state.selectedRowPaths: Array<RowPathKey>`
- `state.selectedRowPaths: Set<RowPathKey>`
- Optional
- Defaults to `[]`
- Defaults to `new Set()`
- If a row's path key (eg. a row path of `[1, 3, 2]` would have a path key of `1.3.2`) is found in this array, it will have a selected state.
- `initialState.selectedRowPaths`
- Identical to the `state.selectedRowPaths` option above
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -13,7 +13,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+16 -17
View File
@@ -59,9 +59,9 @@ const Styles = styled.div`
function Table({ columns, data }) {
const defaultColumn = React.useMemo(
() => ({
minWidth: 20,
minWidth: 30,
width: 150,
maxWidth: 500,
maxWidth: 400,
}),
[]
)
@@ -102,21 +102,20 @@ function Table({ columns, data }) {
</div>
<div {...getTableBodyProps()}>
{rows.map(
(row, i) => {
prepareRow(row);
return (
<div {...row.getRowProps()} className="tr">
{row.cells.map(cell => {
return (
<div {...cell.getCellProps()} className="td">
{cell.render('Cell')}
</div>
)
})}
</div>
)}
)}
{rows.map((row, i) => {
prepareRow(row)
return (
<div {...row.getRowProps()} className="tr">
{row.cells.map(cell => {
return (
<div {...cell.getCellProps()} className="td">
{cell.render('Cell')}
</div>
)
})}
</div>
)
})}
</div>
</div>
)
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -12,7 +12,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
@@ -12,7 +12,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -12,7 +12,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -12,7 +12,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next"
"react-table": "latest"
},
"devDependencies": {
"@rescripts/cli": "^0.0.11",
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+2 -2
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2",
"react-dnd": "^9.4.0",
"react-dnd-html5-backend": "^9.4.0",
@@ -35,4 +35,4 @@
"last 1 safari version"
]
}
}
}
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+4 -4
View File
@@ -66,7 +66,7 @@ function Table({ columns, data }) {
))}
</thead>
<tbody {...getTableBodyProps()}>
{rows.map((row, i) => {
{rows.slice(0, 10).map((row, i) => {
prepareRow(row)
return (
<tr {...row.getRowProps()}>
@@ -79,11 +79,11 @@ function Table({ columns, data }) {
</tbody>
</table>
<p>Selected Rows: {selectedRowPaths.length}</p>
<pre>
{/* <pre>
<code>
{JSON.stringify(
{
selectedRowPaths,
selectedRowPaths: [...selectedRowPaths.values()],
'selectedFlatRows[].original': selectedFlatRows.map(
d => d.original
),
@@ -92,7 +92,7 @@ function Table({ columns, data }) {
2
)}
</code>
</pre>
</pre> */}
</>
)
}
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"styled-components": "^4.3.2"
},
"devDependencies": {
+1 -1
View File
@@ -11,7 +11,7 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-table": "next",
"react-table": "latest",
"react-window": "^1.8.5",
"styled-components": "^4.3.2"
},
Vendored
-638
View File
@@ -1,638 +0,0 @@
// TypeScript Version: 3.5
import { ReactNode, ComponentType, MouseEvent } from 'react'
/**
* The empty definitions of below provides a base definition for the parts used by useTable, that can then be extended in the users code.
*
* @example
* export interface TableOptions<D extends object = {}}>
* extends
* UseExpandedOptions<D>,
* UseFiltersOptions<D> {}
*/
export interface TableOptions<D extends object> extends UseTableOptions<D> {}
export interface TableInstance<D extends object = {}>
extends Omit<TableOptions<D>, 'columns' | 'state'>,
UseTableInstanceProps<D> {}
export interface TableState<
D extends object = {}
> {} /* tslint:disable-line no-empty-interface */ // eslint-disable-line @typescript-eslint/no-empty-interface
export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}
export interface Cell<D extends object = {}> extends UseTableCellProps<D> {}
export interface Column<D extends object = {}>
extends UseTableColumnOptions<D> {}
export interface ColumnInstance<D extends object = {}>
extends Omit<Column<D>, 'id'>,
UseTableColumnProps<D> {}
export interface HeaderGroup<D extends object = {}>
extends ColumnInstance<D>,
UseTableHeaderGroupProps<D> {}
export interface Row<D extends object = {}> extends UseTableRowProps<D> {}
/* #region useTable */
export function useTable<D extends object = {}>(
options: TableOptions<D>,
...plugins: Array<PluginHook<D>>
): TableInstance<D>
/**
* NOTE: To use custom options, use "Interface Merging" to add the custom options
*/
export type UseTableOptions<D extends object> = {
columns: Array<Column<D>>
data: D[]
} & Partial<{
initialState: Partial<TableState<D>>
state: Partial<TableState<D>>
reducer: (
oldState: TableState<D>,
newState: TableState<D>,
type: string
) => TableState<D>
defaultColumn: Partial<Column<D>>
initialRowStateKey: IdType<D>
getSubRows: (originalRow: D, relativeIndex: number) => Array<D>
getRowID: (originalRow: D, relativeIndex: number) => IdType<D>
debug: boolean
}>
export interface UseTableHooks<D extends object> {
columnsBeforeHeaderGroups: Array<
(
flatColumns: Array<Column<D>>,
instance: TableInstance<D>
) => Array<Column<D>>
>
columnsBeforeHeaderGroupsDeps: Array<
(deps: any[], instance: TableInstance<D>) => any[]
>
useMain: Array<(instance: TableInstance<D>) => TableInstance<D>>
useRows: Array<
(rows: Array<Row<D>>, instance: TableInstance<D>) => Array<Row<D>>
>
prepareRow: Array<(row: Row<D>, instance: TableInstance<D>) => Row<D>>
// Prop Hooks
getTableProps: Array<(instance: TableInstance<D>) => object>
getTableBodyProps: Array<(instance: TableInstance<D>) => object>
getRowProps: Array<(row: Row<D>, instance: TableInstance<D>) => object>
getHeaderGroupProps: Array<
(headerGroup: HeaderGroup<D>, instance: TableInstance<D>) => object
>
getHeaderProps: Array<
(column: Column<D>, instance: TableInstance<D>) => object
>
getCellProps: Array<(cell: Cell<D>, instance: TableInstance<D>) => object>
}
export interface UseTableColumnOptions<D extends object>
extends Accessor<D>,
Partial<{
columns: Array<Column<D>>
show: boolean | ((instance: TableInstance<D>) => boolean)
Header: Renderer<HeaderProps<D>>
Cell: Renderer<CellProps<D>>
width?: number
minWidth?: number
maxWidth?: number
}> {}
export interface UseTableInstanceProps<D extends object> {
columns: Array<ColumnInstance<D>>
flatColumns: Array<ColumnInstance<D>>
headerGroups: Array<HeaderGroup<D>>
headers: Array<ColumnInstance<D>>
flatHeaders: Array<ColumnInstance<D>>
rows: Array<Row<D>>
getTableProps: (props?: object) => object
getTableBodyProps: (props?: object) => object
prepareRow: (row: Row<D>) => void
rowPaths: string[]
flatRows: Array<Row<D>>
state: TableState<D>
setState: SetState<D>
totalColumnsWidth: number
}
export interface UseTableHeaderGroupProps<D extends object> {
headers: Array<ColumnInstance<D>>
getHeaderGroupProps: (props?: object) => object
totalHeaderCount: number
}
export interface UseTableColumnProps<D extends object> {
id: IdType<D>
isVisible: boolean
render: (type: 'Header' | string, props?: object) => ReactNode
getHeaderProps: (props?: object) => object
parent: ColumnInstance<D>
depth: number
index: number
}
export interface UseTableRowProps<D extends object> {
cells: Array<Cell<D>>
values: Record<IdType<D>, CellValue>
getRowProps: (props?: object) => object
index: number
original: D
path: Array<IdType<D>>
subRows: Array<Row<D>>
}
export interface UseTableCellProps<D extends object> {
column: ColumnInstance<D>
row: Row<D>
value: CellValue
getCellProps: (props?: object) => object
render: (type: 'Cell' | string, userProps?: object) => ReactNode
}
export type HeaderProps<D extends object> = TableInstance<D> & {
column: ColumnInstance<D>
}
export type CellProps<D extends object> = TableInstance<D> & {
column: ColumnInstance<D>
row: Row<D>
cell: Cell<D>
}
// NOTE: At least one of (id | accessor | Header as string) required
export interface Accessor<D extends object> {
accessor?:
| IdType<D>
| ((
originalRow: D,
index: number,
sub: {
subRows: D[]
depth: number
data: D[]
}
) => CellValue)
id?: IdType<D>
}
/* #endregion */
// Plugins
/* #region useColumnOrder */
export function useColumnOrder<D extends object = {}>(hooks: Hooks<D>): void
export namespace useColumnOrder {
const pluginName = 'useColumnOrder'
}
export interface UseColumnOrderState<D extends object> {
columnOrder: Array<IdType<D>>
}
export interface UseColumnOrderInstanceProps<D extends object> {
setColumnOrder: (
updater: (columnOrder: Array<IdType<D>>) => Array<IdType<D>>
) => void
}
/* #endregion */
/* #region useExpanded */
export function useExpanded<D extends object = {}>(hooks: Hooks<D>): void
export namespace useExpanded {
const pluginName = 'useExpanded'
}
export type UseExpandedOptions<D extends object> = Partial<{
manualExpandedKey: IdType<D>
paginateExpandedRows: boolean
getResetExpandedDeps: (i: TableInstance) => Array<any>
}>
export interface UseExpandedHooks<D extends object> {
getExpandedToggleProps: Array<
(row: Row<D>, instance: TableInstance<D>) => object
>
}
export interface UseExpandedState<D extends object> {
expanded: Array<IdType<D>>
}
export interface UseExpandedInstanceProps<D extends object> {
rows: Array<Row<D>>
toggleExpandedByPath: (path: Array<IdType<D>>, isExpanded: boolean) => void
expandedDepth: number
}
export interface UseExpandedRowProps<D extends object> {
isExpanded: boolean
canExpand: boolean
subRows: Array<Row<D>>
toggleExpanded: (isExpanded?: boolean) => void
getExpandedToggleProps: (props?: object) => object
}
/* #endregion */
/* #region useFilters */
export function useFilters<D extends object = {}>(hooks: Hooks<D>): void
export namespace useFilters {
const pluginName = 'useFilters'
}
export type UseFiltersOptions<D extends object> = Partial<{
manualFilters: boolean
disableFilters: boolean
filterTypes: Filters<D>
getResetFiltersDeps: (i: TableInstance) => Array<any>
}>
export interface UseFiltersState<D extends object> {
filters: Filters<D>
}
export type UseFiltersColumnOptions<D extends object> = Partial<{
disableFilters: boolean
Filter: Renderer<FilterProps<D>>
filter: FilterType<D> | DefaultFilterTypes | keyof Filters<D>
}>
export interface UseFiltersInstanceProps<D extends object> {
rows: Array<Row<D>>
preFilteredRows: Array<Row<D>>
setFilter: (
columnId: IdType<D>,
updater: ((filterValue: FilterValue) => FilterValue) | FilterValue
) => void
setAllFilters: (
updater: Filters<D> | ((filters: Filters<D>) => Filters<D>)
) => void
}
export interface UseFiltersColumnProps<D extends object> {
canFilter: boolean
setFilter: (
updater: ((filterValue: FilterValue) => FilterValue) | FilterValue
) => void
filterValue: FilterValue
preFilteredRows: Array<Row<D>>
filteredRows: Array<Row<D>>
}
export type FilterProps<D extends object> = HeaderProps<D>
export type FilterValue = any
export type Filters<D extends object> = Record<IdType<D>, FilterValue>
export type DefaultFilterTypes =
| 'text'
| 'exactText'
| 'exactTextCase'
| 'includes'
| 'includesAll'
| 'exact'
| 'equals'
| 'between'
export interface FilterType<D extends object> {
(
rows: Array<Row<D>>,
columnId: IdType<D>,
filterValue: FilterValue,
column: ColumnInstance<D>
): Array<Row<D>>
autoRemove?: (filterValue: FilterValue) => boolean
}
/* #endregion */
/* #region useGroupBy */
export function useGroupBy<D extends object = {}>(hooks: Hooks<D>): void
export namespace useGroupBy {
const pluginName = 'useGroupBy'
}
export type UseGroupByOptions<D extends object> = Partial<{
manualGroupBy: boolean
disableGroupBy: boolean
aggregations: Record<string, AggregatorFn<D>>
groupByFn: (
rows: Array<Row<D>>,
columnId: IdType<D>
) => Record<string, Row<D>>
getResetGroupByDeps: (i: TableInstance) => Array<any>
}>
export interface UseGroupByHooks<D extends object> {
getGroupByToggleProps: Array<
(header: HeaderGroup<D>, instance: TableInstance<D>) => object
>
}
export interface UseGroupByState<D extends object> {
groupBy: Array<IdType<D>>
}
export type UseGroupByColumnOptions<D extends object> = Partial<{
aggregate: Aggregator<D> | Array<Aggregator<D>>
Aggregated: Renderer<CellProps<D>>
disableGroupBy: boolean
groupByBoundary: boolean
}>
export interface UseGroupByInstanceProps<D extends object> {
rows: Array<Row<D>>
preGroupedRows: Array<Row<D>>
toggleGroupBy: (columnId: IdType<D>, toggle: boolean) => void
}
export interface UseGroupByColumnProps<D extends object> {
canGroupBy: boolean
isGrouped: boolean
groupedIndex: number
toggleGroupBy: () => void
getGroupByToggleProps: (props?: object) => object
}
export interface UseGroupByRowProps<D extends object> {
isAggregated: boolean
groupByID: IdType<D>
groupByVal: string
values: Record<IdType<D>, AggregatedValue>
subRows: Array<Row<D>>
depth: number
path: Array<IdType<D>>
index: number
}
export interface UseGroupByCellProps<D extends object> {
isGrouped: boolean
isRepeatedValue: boolean
isAggregated: boolean
}
export type DefaultAggregators =
| 'sum'
| 'average'
| 'median'
| 'uniqueCount'
| 'count'
export type AggregatorFn<D extends object> = (
columnValues: CellValue[],
rows: Array<Row<D>>
) => AggregatedValue
export type Aggregator<D extends object> =
| AggregatorFn<D>
| DefaultAggregators
| string
export type AggregatedValue = any
/* #endregion */
/* #region usePagination */
export function usePagination<D extends object = {}>(hooks: Hooks<D>): void
export namespace usePagination {
const pluginName = 'usePagination'
}
export type UsePaginationOptions<D extends object> = Partial<{
pageCount: number
manualPagination: boolean
getResetPageDeps: (i: TableInstance) => Array<any>
paginateExpandedRows: boolean
}>
export interface UsePaginationState<D extends object> {
pageSize: number
pageIndex: number
}
export interface UsePaginationInstanceProps<D extends object> {
page: Array<Row<D>>
pageCount: number
pageOptions: number[]
canPreviousPage: boolean
canNextPage: boolean
gotoPage: (updater: ((pageIndex: number) => number) | number) => void
previousPage: () => void
nextPage: () => void
setPageSize: (pageSize: number) => void
pageIndex: number
pageSize: number
}
/* #endregion */
/* #region useRowSelect */
export function useRowSelect<D extends object = {}>(hooks: Hooks<D>): void
export namespace useRowSelect {
const pluginName = 'useRowSelect'
}
export type UseRowSelectOptions<D extends object> = Partial<{
manualRowSelectedKey: IdType<D>
getResetSelectedRowPathsDeps: (i: TableInstance) => Array<any>
}>
export interface UseRowSelectHooks<D extends object> {
getToggleRowSelectedProps: Array<
(row: Row<D>, instance: TableInstance<D>) => object
>
getToggleAllRowsSelectedProps: Array<(instance: TableInstance<D>) => object>
}
export interface UseRowSelectState<D extends object> {
selectedRowPaths: Array<IdType<D>>
}
export interface UseRowSelectInstanceProps<D extends object> {
toggleRowSelected: (rowPath: IdType<D>, set?: boolean) => void
toggleRowSelectedAll: (set?: boolean) => void
getToggleAllRowsSelectedProps: (props?: object) => object
isAllRowsSelected: boolean
selectedFlatRows: Array<Row<D>>
}
export interface UseRowSelectRowProps<D extends object> {
isSelected: boolean
toggleRowSelected: (set?: boolean) => void
getToggleRowSelectedProps: (props?: object) => object
}
/* #endregion */
/* #region useRowState */
export function useRowState<D extends object = {}>(hooks: Hooks<D>): void
export namespace useRowState {
const pluginName = 'useRowState'
}
export type UseRowStateOptions<D extends object> = Partial<{
initialRowStateAccessor: (row: Row<D>) => UseRowStateLocalState<D>
}>
export interface UseRowStateState<D extends object> {
rowState: Partial<{
cellState: UseRowStateLocalState<D>
rowState: UseRowStateLocalState<D>
}>
}
export interface UseRowStateInstanceProps<D extends object> {
setRowState: (rowPath: string[], updater: UseRowUpdater) => void // Purposely not exposing action
setCellState: (
rowPath: string[],
columnId: IdType<D>,
updater: UseRowUpdater
) => void
}
export interface UseRowStateRowProps<D extends object> {
state: UseRowStateLocalState<D>
setState: (updater: UseRowUpdater) => void
}
export interface UseRowStateCellProps<D extends object> {
state: UseRowStateLocalState<D>
setState: (updater: UseRowUpdater) => void
}
export type UseRowUpdater<T = unknown> = T | ((prev: T) => T)
export type UseRowStateLocalState<D extends object, T = unknown> = Record<
IdType<D>,
T
>
/* #endregion */
/* #region useSortBy */
export function useSortBy<D extends object = {}>(hooks: Hooks<D>): void
export namespace useSortBy {
const pluginName = 'useSortBy'
}
export type UseSortByOptions<D extends object> = Partial<{
manualSorting: boolean
disableSortBy: boolean
disableMultiSort: boolean
isMultiSortEvent: (e: MouseEvent) => boolean
maxMultiSortColCount: number
disableSortRemove: boolean
disabledMultiRemove: boolean
orderByFn: (
rows: Array<Row<D>>,
sortFns: Array<SortByFn<D>>,
directions: boolean[]
) => Array<Row<D>>
sortTypes: Record<string, SortByFn<D>>
getResetSortByDeps: (i: TableInstance) => Array<any>
}>
export interface UseSortByHooks<D extends object> {
getSortByToggleProps: Array<
(column: Column<D>, instance: TableInstance<D>) => object
>
}
export interface UseSortByState<D extends object> {
sortBy: Array<SortingRule<D>>
}
export type UseSortByColumnOptions<D extends object> = Partial<{
disableSortBy: boolean
sortDescFirst: boolean
sortInverted: boolean
sortType: SortByFn<D> | DefaultSortTypes | string
}>
export interface UseSortByInstanceProps<D extends object> {
rows: Array<Row<D>>
preSortedRows: Array<Row<D>>
toggleSortBy: (
columnId: IdType<D>,
descending: boolean,
isMulti: boolean
) => void
}
export interface UseSortByColumnProps<D extends object> {
canSort: boolean
toggleSortBy: (descending: boolean, multi: boolean) => void
getSortByToggleProps: (props?: object) => object
clearSorting: () => void
isSorted: boolean
sortedIndex: number
isSortedDesc: boolean | undefined
}
export type SortByFn<D extends object> = (
rowA: Row<D>,
rowB: Row<D>,
columnId: IdType<D>
) => 0 | 1 | -1
export type DefaultSortTypes = 'alphanumeric' | 'datetime' | 'basic'
export interface SortingRule<D> {
id: IdType<D>
desc?: boolean
}
/* #endregion */
/* #region useAbsoluteLayout */
export function useAbsoluteLayout<D extends object = {}>(hooks: Hooks<D>): void
export namespace useAbsoluteLayout {
const pluginName = 'useAbsoluteLayout'
}
/* #endregion */
/* #region useBlockLayout */
export function useBlockLayout<D extends object = {}>(hooks: Hooks<D>): void
export namespace useBlockLayout {
const pluginName = 'useBlockLayout'
}
/* #endregion */
/* #region useResizeColumns */
export function useResizeColumns<D extends object = {}>(hooks: Hooks<D>): void
export namespace useResizeColumns {
const pluginName = 'useResizeColumns'
}
export interface UseResizeColumnsOptions<D extends object> {
disableResizing?: boolean
}
export interface UseResizeColumnsColumnOptions<D extends object> {
disableResizing?: boolean
}
export interface UseResizeColumnsHeaderProps<D extends object> {
getResizerProps: (props?: object) => object
canResize: boolean
isResizing: boolean
}
/* #endregion */
// Additional API
export const actions: Record<string, string>
export function addActions(...actions: string[]): void
export const defaultState: Record<string, any>
// Helpers
export type StringKey<D> = Extract<keyof D, string>
export type IdType<D> = StringKey<D> | string
export type CellValue = any
export type Renderer<Props> = ComponentType<Props> | ReactNode
export interface PluginHook<D extends object> {
(hooks: Hooks<D>): void
pluginName: string
}
export type SetState<D extends object> = (
updater: (old: TableState<D>) => TableState<D>,
type: keyof typeof actions
) => void
+4 -5
View File
@@ -1,6 +1,6 @@
{
"name": "react-table",
"version": "7.0.0-beta.21",
"version": "7.0.0-beta.26",
"description": "A fast, lightweight, opinionated table and datagrid built on React",
"license": "MIT",
"homepage": "https://github.com/tannerlinsley/react-table#readme",
@@ -20,10 +20,9 @@
"commit": "git add . && git-cz",
"test": "is-ci \"test:ci\" \"test:dev\"",
"test:dev": "jest --watch",
"test:ci": "yarn test:jest && yarn test:types",
"test:ci": "yarn test:jest",
"test:jest": "jest",
"test:types": "echo '\n****\nTODO: Re-enable dtslint\n****\n'",
"build": "rollup -c",
"build": "cross-env NODE_ENV=production rollup -c",
"start": "rollup -c -w",
"prepare": "yarn build",
"release": "yarn publish",
@@ -40,7 +39,6 @@
"README.md"
],
"peerDependencies": {
"prop-types": "^15.5.0",
"react": "^16.8.3",
"react-dom": "^16.8.3"
},
@@ -92,6 +90,7 @@
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.0",
"rollup-plugin-size": "^0.2.1",
"rollup-plugin-size-snapshot": "^0.10.0",
"rollup-plugin-terser": "^5.1.2",
"snapshot-diff": "^0.6.1"
-99
View File
@@ -1,99 +0,0 @@
import {
UseColumnOrderInstanceProps,
UseColumnOrderState,
UseExpandedInstanceProps,
UseExpandedOptions,
UseExpandedRowProps,
UseExpandedState,
UseFiltersColumnOptions,
UseFiltersColumnProps,
UseFiltersInstanceProps,
UseFiltersOptions,
UseFiltersState,
UseGroupByCellProps,
UseGroupByColumnOptions,
UseGroupByColumnProps,
UseGroupByInstanceProps,
UseGroupByOptions,
UseGroupByRowProps,
UseGroupByState,
UsePaginationInstanceProps,
UsePaginationOptions,
UsePaginationState,
UseResizeColumnsColumnOptions,
UseResizeColumnsHeaderProps,
UseResizeColumnsOptions,
UseRowSelectInstanceProps,
UseRowSelectOptions,
UseRowSelectRowProps,
UseRowSelectState,
UseRowStateCellProps,
UseRowStateInstanceProps,
UseRowStateRowProps,
UseSortByColumnOptions,
UseSortByColumnProps,
UseSortByInstanceProps,
UseSortByOptions,
UseSortByState,
UseTableCellProps,
} from 'react-table'
declare module 'react-table' {
// take this file as-is, or comment out the sections that don't apply to your plugin configuration
export interface TableOptions<D extends object>
extends UseExpandedOptions<D>,
UseFiltersOptions<D>,
UseGroupByOptions<D>,
UsePaginationOptions<D>,
UseRowSelectOptions<D>,
UseSortByOptions<D>,
UseFiltersOptions<D>,
UseResizeColumnsOptions<D>,
// note that having Record here allows you to add anything to the options, this matches the spirit of the
// underlying js library, but might be cleaner if it's replaced by a more specific type that matches your
// feature set, this is a safe default.
Record<string, any> {}
export interface TableInstance<D extends object = {}>
extends UseColumnOrderInstanceProps<D>,
UseExpandedInstanceProps<D>,
UseFiltersInstanceProps<D>,
UseGroupByInstanceProps<D>,
UsePaginationInstanceProps<D>,
UseRowSelectInstanceProps<D>,
UseRowStateInstanceProps<D>,
UseSortByInstanceProps<D> {}
export interface TableState<D extends object = {}>
extends UseColumnOrderState<D>,
UseExpandedState<D>,
UseFiltersState<D>,
UseGroupByState<D>,
UsePaginationState<D>,
UseRowSelectState<D>,
UseSortByState<D> {}
export interface Column<D extends object = {}>
extends UseFiltersColumnOptions<D>,
UseGroupByColumnOptions<D>,
UseSortByColumnOptions<D>,
UseResizeColumnsColumnOptions<D> {}
export interface ColumnInstance<D extends object = {}>
extends UseFiltersColumnProps<D>,
UseGroupByColumnProps<D>,
UseSortByColumnProps<D>,
UseResizeColumnsHeaderProps<D> {}
export interface Cell<D extends object = {}>
extends UseTableCellProps<D>,
UseGroupByCellProps<D>,
UseRowStateCellProps<D> {}
export interface Row<D extends object = {}>
extends UseExpandedRowProps<D>,
UseGroupByRowProps<D>,
UseRowSelectRowProps<D>,
UseRowStateRowProps<D> {}
}
+25 -3
View File
@@ -3,7 +3,7 @@ import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
import resolve from 'rollup-plugin-node-resolve'
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
import size from 'rollup-plugin-size'
import pkg from './package.json'
export default [
@@ -14,7 +14,19 @@ export default [
format: 'cjs',
sourcemap: true,
},
plugins: [external(), babel(), resolve(), commonjs(), sizeSnapshot()],
plugins: [
external(),
babel(),
resolve(),
commonjs(),
size({
publish: true,
exclude: pkg.module,
filename: 'sizes-cjs.json',
writeFile: process.env.CI ? true : false,
}),
sizeSnapshot(),
],
},
{
input: 'src/index.js',
@@ -23,6 +35,16 @@ export default [
format: 'es',
sourcemap: true,
},
plugins: [external(), babel(), sizeSnapshot()],
plugins: [
external(),
babel(),
size({
publish: true,
exclude: pkg.main,
filename: 'sizes-es.json',
writeFile: process.env.CI ? true : false,
}),
sizeSnapshot(),
],
},
]
+32
View File
@@ -0,0 +1,32 @@
[
{
"timestamp": 1575391465436,
"files": [
{
"filename": "index.js",
"size": 20511,
"delta": 1
}
]
},
{
"timestamp": 1575345020328,
"files": [
{
"filename": "index.js",
"size": 20510,
"delta": 5
}
]
},
{
"timestamp": 1575331661254,
"files": [
{
"filename": "index.js",
"size": 20505,
"delta": 20505
}
]
}
]
+32
View File
@@ -0,0 +1,32 @@
[
{
"timestamp": 1575391457318,
"files": [
{
"filename": "index.es.js",
"size": 20368,
"delta": -1
}
]
},
{
"timestamp": 1575345027852,
"files": [
{
"filename": "index.es.js",
"size": 20369,
"delta": 4
}
]
},
{
"timestamp": 1575331668355,
"files": [
{
"filename": "index.es.js",
"size": 20365,
"delta": 20365
}
]
}
]
+8 -8
View File
@@ -84,8 +84,8 @@ export const useTable = (props, ...plugins) => {
hooks: {
columnsBeforeHeaderGroups: [],
columnsBeforeHeaderGroupsDeps: [],
useBeforeDimensions: [],
useMain: [],
useInstanceBeforeDimensions: [],
useInstance: [],
useRows: [],
prepareRow: [],
getTableProps: [],
@@ -230,24 +230,24 @@ export const useTable = (props, ...plugins) => {
)
if (process.env.NODE_ENV !== 'production' && debug)
console.time('hooks.useBeforeDimensions')
console.time('hooks.useInstanceBeforeDimensions')
instanceRef.current = applyHooks(
instanceRef.current.hooks.useBeforeDimensions,
instanceRef.current.hooks.useInstanceBeforeDimensions,
instanceRef.current
)
if (process.env.NODE_ENV !== 'production' && debug)
console.timeEnd('hooks.useBeforeDimensions')
console.timeEnd('hooks.useInstanceBeforeDimensions')
calculateDimensions(instanceRef.current)
if (process.env.NODE_ENV !== 'production' && debug)
console.time('hooks.useMain')
console.time('hooks.useInstance')
instanceRef.current = applyHooks(
instanceRef.current.hooks.useMain,
instanceRef.current.hooks.useInstance,
instanceRef.current
)
if (process.env.NODE_ENV !== 'production' && debug)
console.timeEnd('hooks.useMain')
console.timeEnd('hooks.useInstance')
// Each materialized header needs to be assigned a render function and other
// prop getter properties here.
+8 -2
View File
@@ -113,9 +113,15 @@ function Table({ columns, data }) {
)}
</tbody>
</table>
<p>Selected Rows: {selectedRowPaths.length}</p>
<p>Selected Rows: {selectedRowPaths.size}</p>
<pre>
<code>{JSON.stringify({ selectedRowPaths }, null, 2)}</code>
<code>
{JSON.stringify(
{ selectedRowPaths: [...selectedRowPaths.values()] },
null,
2
)}
</code>
</pre>
</>
)
+2 -2
View File
@@ -1,10 +1,10 @@
export const useAbsoluteLayout = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useAbsoluteLayout.pluginName = 'useAbsoluteLayout'
const useMain = instance => {
const useInstance = instance => {
const {
totalColumnsWidth,
hooks: {
+2 -2
View File
@@ -1,10 +1,10 @@
export const useBlockLayout = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useBlockLayout.pluginName = 'useBlockLayout'
const useMain = instance => {
const useInstance = instance => {
const {
totalColumnsWidth,
hooks: { getRowProps, getHeaderGroupProps, getHeaderProps, getCellProps },
+2 -2
View File
@@ -38,7 +38,7 @@ export const useColumnOrder = hooks => {
return [...deps, instance.state.columnOrder]
})
hooks.columnsBeforeHeaderGroups.push(columnsBeforeHeaderGroups)
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useColumnOrder.pluginName = pluginName
@@ -74,7 +74,7 @@ function columnsBeforeHeaderGroups(columns, instance) {
return [...columnsInOrder, ...columnsCopy]
}
function useMain(instance) {
function useInstance(instance) {
const { dispatch } = instance
const setColumnOrder = React.useCallback(
+2 -2
View File
@@ -54,14 +54,14 @@ reducerHandlers[pluginName] = (state, action) => {
export const useExpanded = hooks => {
hooks.getExpandedToggleProps = []
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useExpanded.pluginName = pluginName
const defaultGetResetExpandedDeps = ({ data }) => [data]
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,
+2 -2
View File
@@ -109,12 +109,12 @@ reducerHandlers[pluginName] = (state, action) => {
}
export const useFilters = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useFilters.pluginName = pluginName
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,
+2 -2
View File
@@ -58,7 +58,7 @@ export const useGroupBy = hooks => {
deps.push(instance.state.groupBy)
return deps
})
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useGroupBy.pluginName = pluginName
@@ -83,7 +83,7 @@ function columnsBeforeHeaderGroups(flatColumns, { state: { groupBy } }) {
const defaultUserAggregations = {}
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,
+2 -2
View File
@@ -61,7 +61,7 @@ reducerHandlers[pluginName] = (state, action) => {
}
export const usePagination = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
usePagination.pluginName = pluginName
@@ -72,7 +72,7 @@ const defaultGetResetPageDeps = ({
state: { filters, groupBy, sortBy },
}) => [manualPagination ? null : data, filters, groupBy, sortBy]
function useMain(instance) {
function useInstance(instance) {
const {
rows,
manualPagination,
+15 -9
View File
@@ -30,14 +30,15 @@ reducerHandlers[pluginName] = (state, action) => {
}
if (action.type === actions.columnStartResizing) {
const { startX, columnId, headerIdWidths } = action
const { clientX, columnId, columnWidth, headerIdWidths } = action
return {
...state,
columnResizing: {
...state.columnResizing,
startX,
startX: clientX,
headerIdWidths,
columnWidth,
isResizingColumn: columnId,
},
}
@@ -45,14 +46,18 @@ reducerHandlers[pluginName] = (state, action) => {
if (action.type === actions.columnResizing) {
const { clientX } = action
const { startX, headerIdWidths } = state.columnResizing
const { startX, columnWidth, headerIdWidths } = state.columnResizing
const deltaX = clientX - startX
const percentageDeltaX = deltaX / headerIdWidths.length
const percentageDeltaX = deltaX / columnWidth
const newColumnWidths = {}
headerIdWidths.forEach(([headerId, headerWidth], index) => {
newColumnWidths[headerId] = Math.max(headerWidth + percentageDeltaX, 0)
headerIdWidths.forEach(([headerId, headerWidth]) => {
newColumnWidths[headerId] = Math.max(
headerWidth + headerWidth * percentageDeltaX,
0
)
})
return {
@@ -61,7 +66,7 @@ reducerHandlers[pluginName] = (state, action) => {
...state.columnResizing,
columnWidths: {
...state.columnResizing.columnWidths,
...action.columnWidths,
...newColumnWidths,
},
},
}
@@ -80,12 +85,12 @@ reducerHandlers[pluginName] = (state, action) => {
}
export const useResizeColumns = hooks => {
hooks.useBeforeDimensions.push(useBeforeDimensions)
hooks.useInstanceBeforeDimensions.push(useInstanceBeforeDimensions)
}
useResizeColumns.pluginName = pluginName
const useBeforeDimensions = instance => {
const useInstanceBeforeDimensions = instance => {
instance.hooks.getResizerProps = []
const {
@@ -129,6 +134,7 @@ const useBeforeDimensions = instance => {
dispatch({
type: actions.columnStartResizing,
columnId: header.id,
columnWidth: header.totalWidth,
headerIdWidths,
clientX,
})
+15 -14
View File
@@ -19,7 +19,7 @@ actions.toggleRowSelected = 'toggleRowSelected'
reducerHandlers[pluginName] = (state, action) => {
if (action.type === actions.init) {
return {
selectedRowPaths: [],
selectedRowPaths: new Set(),
...state,
}
}
@@ -27,7 +27,7 @@ reducerHandlers[pluginName] = (state, action) => {
if (action.type === actions.resetSelectedRows) {
return {
...state,
selectedRowPaths: [],
selectedRowPaths: new Set(),
}
}
@@ -44,7 +44,7 @@ reducerHandlers[pluginName] = (state, action) => {
return {
...state,
selectedRowPaths: selectAll ? flatRowPaths : [],
selectedRowPaths: selectAll ? new Set(flatRowPaths) : new Set(),
}
}
@@ -63,20 +63,21 @@ reducerHandlers[pluginName] = (state, action) => {
// Join the paths of deep rows
// to make a key, then manage all of the keys
// in a flat object
const exists = state.selectedRowPaths.includes(key)
const exists = state.selectedRowPaths.has(key)
const shouldExist = typeof set !== 'undefined' ? selected : !exists
let newSelectedRows = new Set(state.selectedRowPaths)
let newSelectedRowPaths = new Set(state.selectedRowPaths)
if (!exists && shouldExist) {
flatRowPaths.forEach(rowPath => {
if (rowPath === key || rowPath.startsWith(childRowPrefixKey)) {
newSelectedRows.add(rowPath)
newSelectedRowPaths.add(rowPath)
}
})
} else if (exists && !shouldExist) {
flatRowPaths.forEach(rowPath => {
if (rowPath === key || rowPath.startsWith(childRowPrefixKey)) {
newSelectedRows.delete(rowPath)
newSelectedRowPaths.delete(rowPath)
}
})
} else {
@@ -105,11 +106,11 @@ reducerHandlers[pluginName] = (state, action) => {
// If the row is a subRow update
// its parent row to reflect changes
if (path.length > 1) updateParentRow(newSelectedRows, path)
if (path.length > 1) updateParentRow(newSelectedRowPaths, path)
return {
...state,
selectedRowPaths: [...newSelectedRows.values()],
selectedRowPaths: newSelectedRowPaths,
}
}
}
@@ -118,7 +119,7 @@ export const useRowSelect = hooks => {
hooks.getToggleRowSelectedProps = []
hooks.getToggleAllRowsSelectedProps = []
hooks.useRows.push(useRows)
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useRowSelect.pluginName = pluginName
@@ -147,7 +148,7 @@ function useRows(rows, instance) {
const defaultGetResetSelectedRowPathsDeps = ({ data }) => [data]
function useMain(instance) {
function useInstance(instance) {
const {
hooks,
manualRowSelectedKey = 'isSelected',
@@ -167,10 +168,10 @@ function useMain(instance) {
const flatRowPaths = flatRows.map(d => d.path.join('.'))
let isAllRowsSelected = !!flatRowPaths.length && !!selectedRowPaths.length
let isAllRowsSelected = !!flatRowPaths.length && !!selectedRowPaths.size
if (isAllRowsSelected) {
if (flatRowPaths.some(d => !selectedRowPaths.includes(d))) {
if (flatRowPaths.some(d => !selectedRowPaths.has(d))) {
isAllRowsSelected = false
}
}
@@ -270,5 +271,5 @@ function getRowIsSelected(row, selectedRowPaths) {
)
}
return selectedRowPaths.includes(row.path.join('.'))
return selectedRowPaths.has(row.path.join('.'))
}
+8 -8
View File
@@ -36,21 +36,21 @@ reducerHandlers[pluginName] = (state, action) => {
...state,
rowState: {
...state.rowState,
[pathKey]: functionalUpdate(value, state.rowState[pathKey]),
[pathKey]: functionalUpdate(value, state.rowState[pathKey] || {}),
},
}
}
}
export const useRowState = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useRowState.pluginName = pluginName
const defaultGetResetRowStateDeps = ({ data }) => [data]
function useMain(instance) {
function useInstance(instance) {
const {
hooks,
initialRowStateAccessor,
@@ -71,7 +71,7 @@ function useMain(instance) {
)
const setCellState = React.useCallback(
(rowPath, columnId, updater) => {
(rowPath, columnId, value) => {
return setRowState(
rowPath,
old => {
@@ -79,10 +79,10 @@ function useMain(instance) {
...old,
cellState: {
...old.cellState,
[columnId]:
typeof updater === 'function'
? updater(old.cellState[columnId])
: updater,
[columnId]: functionalUpdate(
value,
(old.cellState || {})[columnId] || {}
),
},
}
},
+3 -3
View File
@@ -30,7 +30,7 @@ reducerHandlers[pluginName] = (state, action) => {
if (action.type === actions.resetSortBy) {
return {
...state,
sortBy: {},
sortBy: [],
}
}
@@ -149,12 +149,12 @@ defaultColumn.sortType = 'alphanumeric'
defaultColumn.sortDescFirst = false
export const useSortBy = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useSortBy.pluginName = pluginName
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,
-10
View File
@@ -1,10 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"strict": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts"]
}
-9
View File
@@ -1,9 +0,0 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-empty-interface": false,
"no-unnecessary-generics": false,
"semicolon": false,
"whitespace": false
}
}
+77 -3
View File
@@ -2307,6 +2307,14 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
axios@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
dependencies:
follow-redirects "1.5.10"
is-buffer "^2.0.2"
axobject-query@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.0.2.tgz#ea187abe5b9002b377f925d8bf7d1c561adf38f9"
@@ -2488,6 +2496,13 @@ brorand@^1.0.1:
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
integrity sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=
brotli-size@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/brotli-size/-/brotli-size-4.0.0.tgz#a05ee3faad3c0e700a2f2da826ba6b4d76e69e5e"
integrity sha512-uA9fOtlTRC0iqKfzff1W34DXUA3GyVqbUaeo3Rw3d4gd1eavKVCETXrn3NzO74W+UVkG3UHu8WxUi+XvKI/huA==
dependencies:
duplexer "0.1.1"
browser-process-hrtime@^0.1.2:
version "0.1.3"
resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-0.1.3.tgz#616f00faef1df7ec1b5bf9cfe2bdc3170f26c7b4"
@@ -2771,6 +2786,11 @@ chrome-trace-event@^1.0.2:
dependencies:
tslib "^1.9.0"
ci-env@^1.11.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/ci-env/-/ci-env-1.12.0.tgz#8b430c4c8fcfe730cb8ac330836bffaa6e5f2ab8"
integrity sha512-4dS9YjX4kpaFmkJWZPuDPK3WlPKdMjx/3JH39vyHj+G4/ED2DCgHQLbh9tKBQjwAwR/sGHOqIVMTlMUZcfJPWw==
ci-info@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
@@ -3304,6 +3324,13 @@ date-fns@^1.27.2:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==
debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"
debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@@ -3574,7 +3601,7 @@ dtslint@^0.9.8:
tslint "5.14.0"
typescript next
duplexer@^0.1.1:
duplexer@0.1.1, duplexer@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
integrity sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=
@@ -4306,6 +4333,13 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3"
readable-stream "^2.3.6"
follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"
for-in@^0.1.3:
version "0.1.8"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"
@@ -4352,7 +4386,7 @@ from2@^2.1.0:
inherits "^2.0.1"
readable-stream "^2.0.0"
fs-extra@8.1.0:
fs-extra@8.1.0, fs-extra@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
@@ -4581,7 +4615,7 @@ growly@^1.3.0:
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=
gzip-size@^5.0.0:
gzip-size@^5.0.0, gzip-size@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-5.1.1.tgz#cb9bee692f87c0612b232840a873904e4c135274"
integrity sha512-FNHi6mmoHvs1mxZAds4PpdCS6QG8B4C1krxJsMutgxl5t3+GlRTzzI3NEkifXx2pVsOvJdOGSmIgDhQ55FwdPA==
@@ -4940,6 +4974,11 @@ is-buffer@^1.0.2, is-buffer@^1.1.5:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
is-buffer@^2.0.2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.4.tgz#3e572f23c8411a5cfd9557c849e3665e0b290623"
integrity sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==
is-callable@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"
@@ -7246,6 +7285,11 @@ prettier@^1.19.1:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
pretty-bytes@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.3.0.tgz#f2849e27db79fb4d6cfe24764fc4134f165989f2"
integrity sha512-hjGrh+P926p4R4WbaB6OckyRtO0F0/lQBiT+0gnxjV+5kjPBrfVBFCsCLbMqVQeydvIoouYTCmmEURiH3R1Bdg==
pretty-format@^23.6.0:
version "23.6.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.6.0.tgz#5eaac8eeb6b33b987b7fe6097ea6a8a146ab5760"
@@ -7894,6 +7938,13 @@ rollup-plugin-size-snapshot@^0.10.0:
terser "^4.1.2"
webpack "^4.28.4"
rollup-plugin-size@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-size/-/rollup-plugin-size-0.2.1.tgz#aec287896740e73550629c43cd6d402f71cc51de"
integrity sha512-ZwOXarF21okk8u7gZKTH9JyULNFmaUyosOMifxa0vvdjJGaJs3NDhnTgFaJW8PsFMxOVgwxqJrLqqTmFfvH4EA==
dependencies:
size-plugin-core "^0.0.7"
rollup-plugin-terser@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-5.1.2.tgz#3e41256205cb75f196fc70d4634227d1002c255c"
@@ -8132,6 +8183,29 @@ sisteransi@^1.0.3:
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.4.tgz#386713f1ef688c7c0304dc4c0632898941cad2e3"
integrity sha512-/ekMoM4NJ59ivGSfKapeG+FWtrmWvA1p6FBZwXrqojw90vJu8lBmrTxCMuBCydKtkaUe2zt4PlxeTKpjwMbyig==
size-plugin-core@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/size-plugin-core/-/size-plugin-core-0.0.7.tgz#f63875902d6ae694d3989b7385286934a78020cd"
integrity sha512-vMX3AhK3hh5vxfOL5VgEIxUkcm0MFfiPsZ9LqZsZRH7iQ+erU669zYsx+WCF4EQ+nn11GYXL91U/sEvS1FnPug==
dependencies:
brotli-size "^4.0.0"
chalk "^2.4.2"
fs-extra "^8.1.0"
glob "^7.1.4"
gzip-size "^5.1.1"
minimatch "^3.0.4"
pretty-bytes "^5.3.0"
size-plugin-store "^0.0.5"
util.promisify "^1.0.0"
size-plugin-store@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/size-plugin-store/-/size-plugin-store-0.0.5.tgz#5b36e6f0f12e2f25f7bf1cab029a52e000348f98"
integrity sha512-SIFBv0wMMMfdqg1Po8vem90OaXe2Cftfo0AiXYU9m9JxDhOd726K+0BfNcYyOmDyrH2uUM7zMlnU2OhbbsDv5Q==
dependencies:
axios "^0.19.0"
ci-env "^1.11.0"
slash@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"