mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-19 08:20:30 +00:00
Compare commits
37
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb94eaf103 | ||
|
|
409c050cbf | ||
|
|
cee24c74d8 | ||
|
|
499f21c349 | ||
|
|
2a39d5a21c | ||
|
|
36ba233e27 | ||
|
|
c7dfc45e2e | ||
|
|
9dd36263fb | ||
|
|
227f7905b0 | ||
|
|
f1ad032587 | ||
|
|
93703d027c | ||
|
|
75fb61a17f | ||
|
|
7c73a7a631 | ||
|
|
cbb18368b2 | ||
|
|
4842bc061d | ||
|
|
0477ef26ca | ||
|
|
82734fc898 | ||
|
|
bbfc6428b7 | ||
|
|
280ef16a75 | ||
|
|
7db7d59b3d | ||
|
|
e43968c684 | ||
|
|
e5c04614c1 | ||
|
|
0ef0bc4126 | ||
|
|
ef67b15c07 | ||
|
|
d248be8877 | ||
|
|
ea0799763d | ||
|
|
98fffc3819 | ||
|
|
de7f5c9385 | ||
|
|
69e13b87c3 | ||
|
|
727f4157c1 | ||
|
|
3f9ba8daba | ||
|
|
3de1bbc3a7 | ||
|
|
7d84f86612 | ||
|
|
40477c1c83 | ||
|
|
906988c35a | ||
|
|
07d879f5bb | ||
|
|
e18f371623 |
@@ -10,3 +10,4 @@ react-table.css
|
||||
.idea
|
||||
.DS_Store
|
||||
.history
|
||||
package-lock.json
|
||||
|
||||
+13
-2
@@ -1,7 +1,18 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "10"
|
||||
- 10
|
||||
- 12
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
- windows
|
||||
|
||||
env:
|
||||
global:
|
||||
- YARN_GPG=no
|
||||
|
||||
cache: yarn
|
||||
|
||||
script: npm test
|
||||
script: yarn test
|
||||
|
||||
@@ -43,6 +43,8 @@ Hooks for building **lightweight, fast and extendable datagrids** for React
|
||||
- Row Expansion
|
||||
- Column Ordering
|
||||
- Animatable
|
||||
- Virtualizable
|
||||
- Resizable
|
||||
- Server-side/controlled data/state
|
||||
- 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
|
||||
@@ -83,7 +85,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
**React Table v7** is being built and maintained by me, @tannerlinsley and I am always in need of more Patreon support to keep this project afloat. If you would like to contribute to my Patreon goal for v7 and beyond, [visit my Patreon and help me out!](https://patreon.com/tannerlinsley)
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://patreon.com/tannerlinsley" target="_blank">
|
||||
@@ -105,7 +107,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://patreon.com/tannerlinsley" target="_blank">
|
||||
@@ -127,7 +129,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://patreon.com/tannerlinsley" target="_blank">
|
||||
@@ -144,7 +146,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<a href="https://patreon.com/tannerlinsley">
|
||||
@@ -154,13 +156,14 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
<td>
|
||||
<div><a href="https://www.metso.com/">Pekka</a></div>
|
||||
<div>Jon Eickmeier</div>
|
||||
<div><a href="https://github.com/Shah-Sahab">Syed Hussain<a></div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<a href="https://patreon.com/tannerlinsley">
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# 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`.
|
||||
|
||||
Tto 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 extends 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.
|
||||
+142
-877
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
## React Table is a "headless" UI library
|
||||
|
||||
React Table is a headless utility, which means out of the box, it doesn't render or supply any actual UI elements. You are in charge of utilizing the state and callbacks of the hooks provided by this library to render your own table markup. [Read this article to understand why React Table is built this way.](https://medium.com/merrickchristensen/headless-user-interface-components-565b0c0f2e18). If you don't want to, then here's a quick rundown anyway:
|
||||
React Table is a headless utility, which means out of the box, it doesn't render or supply any actual UI elements. You are in charge of utilizing the state and callbacks of the hooks provided by this library to render your own table markup. [Read this article to understand why React Table is built this way](https://medium.com/merrickchristensen/headless-user-interface-components-565b0c0f2e18). If you don't want to, then here's a quick rundown anyway:
|
||||
|
||||
- Separation of Concerns - Not that superficial kind you read about all the time. The real kind. React Table as a library honestly has no business being in charge of your UI. The look, feel, and overall experience of your table is what makes your app or product great. The less React Table gets in the way of that, the better!
|
||||
- Maintenance - By removing the massive (and seemingly endless) API surface area required to support every UI use-case, React Table can remain small, easy-to-use and simple to update/maintain.
|
||||
@@ -10,7 +10,7 @@ React Table is a headless utility, which means out of the box, it doesn't render
|
||||
|
||||
## The React Table instance
|
||||
|
||||
At the heart of every React Table is the `useTable` hook and the table `instance` object that it returns. This `instance` object contains everything you'll ever need to build a table and interact with it's state. This includes, but is not limited to:
|
||||
At the heart of every React Table is the `useTable` hook and the table `instance` object that it returns. This `instance` object contains everything you'll ever need to build a table and interact with its state. This includes, but is not limited to:
|
||||
|
||||
- Columns
|
||||
- Materialized Data
|
||||
@@ -23,7 +23,7 @@ At the heart of every React Table is the `useTable` hook and the table `instance
|
||||
|
||||
## Rendering your own UI
|
||||
|
||||
As of React Table v7, **you the developer** are responsible for rendering your own UI, but don't let that intimidate you! Table UI's are fun and React Table makes it so easy to wire up your own table UI. The easiest way to learn how to build your own table UI is to [see some existing React Table examples](./examples.md)!
|
||||
As of React Table v7, **you the developer** are responsible for rendering your own UI, but don't let that intimidate you! Table UIs are fun and React Table makes it so easy to wire up your own table UI. The easiest way to learn how to build your own table UI is to [see some existing React Table examples](./examples.md)!
|
||||
|
||||
---
|
||||
|
||||
|
||||
+19
-16
@@ -2,52 +2,55 @@
|
||||
|
||||
- **Simple** - All of these examples use automatic state management, meaning, they don't hoist any state out of the table or manually control anything. Start here for understanding the basics about how to build your table UI.
|
||||
- Basic
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/basic)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/basic)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic)
|
||||
- Sorting
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/sorting)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/sorting)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sorting)
|
||||
- Filtering
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/filtering)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/filtering)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/filtering)
|
||||
- Grouping
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/grouping)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/grouping)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/grouping)
|
||||
- Pagination
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/pagination)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/pagination)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/pagination)
|
||||
- Row Selection
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/row-selection)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/row-selection)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/row-selection)
|
||||
- Expanding
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/expanding)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/expanding)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/expanding)
|
||||
- Sub Components
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/sub-components)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/sub-components)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sub-components)
|
||||
- Editable Data
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/editable-data)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/editable-data)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/editable-data)
|
||||
- Column Ordering
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/column-ordering)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/column-ordering)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/column-ordering)
|
||||
- Column Resizing
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/column-resizing)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/column-resizing)
|
||||
- **Complex**
|
||||
- The "Kitchen Sink"
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/kitchen-sink)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/kitchen-sink)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/kitchen-sink)
|
||||
- **Controlled via `useTableState`** - These examples are more advanced because they demonstrate how to manually control and respond to the state of the table using the `useTableState` hook.
|
||||
- **Controlled** - These examples are more advanced because they demonstrate how to manually control and respond to the state of the table.
|
||||
- Pagination (Controlled)
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/pagination-controlled)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/pagination-controlled)
|
||||
- [Open in CodeSandobx](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/pagination-controlled)
|
||||
- **UI & Rendering** - These examples demonstrate how to use React Table with your favorite UI libraries or tools!
|
||||
- Virtualized Rows (React-Window)
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/virtualized-rows)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/virtualized-rows)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/virtualized-rows)
|
||||
- Animated (Framer-Motion)
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/animated-framer-motion)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/animated-framer-motion)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/animated-framer-motion)
|
||||
- Material-UI
|
||||
- [Source + Guide](https://github.com/tannerlinsley/react-table/tree/master/examples/material-UI-components)
|
||||
- [Source](https://github.com/tannerlinsley/react-table/tree/master/examples/material-UI-components)
|
||||
- [Open in CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/material-UI-components)
|
||||
- [ ] Styled-Components
|
||||
- [ ] CSS
|
||||
|
||||
@@ -294,7 +294,7 @@ function Table({ columns, data }) {
|
||||
</tbody>
|
||||
</table>
|
||||
<pre>
|
||||
<code>{JSON.stringify(state[0], null, 2)}</code>
|
||||
<code>{JSON.stringify(state, null, 2)}</code>
|
||||
</pre>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -95,7 +95,7 @@ function Table({ columns, data }) {
|
||||
</tbody>
|
||||
</table>
|
||||
<pre>
|
||||
<code>{JSON.stringify(state[0], null, 2)}</code>
|
||||
<code>{JSON.stringify(state, null, 2)}</code>
|
||||
</pre>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"presets": ["react-app"],
|
||||
"plugins": ["styled-components"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
SKIP_PREFLIGHT_CHECK=true
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": ["react-app", "prettier"],
|
||||
"rules": {
|
||||
// "eqeqeq": 0,
|
||||
// "jsx-a11y/anchor-is-valid": 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
@@ -0,0 +1,29 @@
|
||||
const path = require('path')
|
||||
const resolveFrom = require('resolve-from')
|
||||
|
||||
const fixLinkedDependencies = config => {
|
||||
config.resolve = {
|
||||
...config.resolve,
|
||||
alias: {
|
||||
...config.resolve.alias,
|
||||
react$: resolveFrom(path.resolve('node_modules'), 'react'),
|
||||
'react-dom$': resolveFrom(path.resolve('node_modules'), 'react-dom'),
|
||||
},
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
const includeSrcDirectory = config => {
|
||||
config.resolve = {
|
||||
...config.resolve,
|
||||
modules: [path.resolve('src'), ...config.resolve.modules],
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
module.exports = [
|
||||
['use-babel-config', '.babelrc'],
|
||||
['use-eslint-config', '.eslintrc'],
|
||||
fixLinkedDependencies,
|
||||
// includeSrcDirectory,
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app) and Rescripts.
|
||||
|
||||
You can:
|
||||
|
||||
- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/column-resizing)
|
||||
- `yarn` and `yarn start` to run and edit the example
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "rescripts start",
|
||||
"build": "rescripts build",
|
||||
"test": "rescripts test",
|
||||
"eject": "rescripts eject"
|
||||
},
|
||||
"dependencies": {
|
||||
"namor": "^1.1.2",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6",
|
||||
"react-scripts": "3.0.1",
|
||||
"react-table": "next",
|
||||
"styled-components": "^4.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rescripts/cli": "^0.0.11",
|
||||
"@rescripts/rescript-use-babel-config": "^0.0.8",
|
||||
"@rescripts/rescript-use-eslint-config": "^0.0.9",
|
||||
"babel-eslint": "10.0.1"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import React from 'react'
|
||||
import styled from 'styled-components'
|
||||
import { useTable, useBlockLayout, useResizeColumns } from 'react-table'
|
||||
|
||||
import makeData from './makeData'
|
||||
|
||||
const Styles = styled.div`
|
||||
padding: 1rem;
|
||||
|
||||
.table {
|
||||
display: inline-block;
|
||||
border-spacing: 0;
|
||||
border: 1px solid black;
|
||||
|
||||
.tr {
|
||||
:last-child {
|
||||
.td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.th,
|
||||
.td {
|
||||
margin: 0;
|
||||
padding: 0.5rem;
|
||||
border-bottom: 1px solid black;
|
||||
border-right: 1px solid black;
|
||||
|
||||
${'' /* In this example we use an absolutely position resizer,
|
||||
so this is required. */}
|
||||
position: relative;
|
||||
|
||||
:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
${'' /* The resizer styles! */}
|
||||
|
||||
.resizer {
|
||||
display: inline-block;
|
||||
background: blue;
|
||||
width: 5px;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
transform: translateX(50%);
|
||||
z-index: 1;
|
||||
|
||||
&.isResizing {
|
||||
background: red;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
function Table({ columns, data }) {
|
||||
const defaultColumn = React.useMemo(
|
||||
() => ({
|
||||
minWidth: 20,
|
||||
width: 150,
|
||||
maxWidth: 500,
|
||||
}),
|
||||
[]
|
||||
)
|
||||
|
||||
const {
|
||||
getTableProps,
|
||||
getTableBodyProps,
|
||||
headerGroups,
|
||||
rows,
|
||||
prepareRow,
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
data,
|
||||
defaultColumn,
|
||||
},
|
||||
useBlockLayout,
|
||||
useResizeColumns
|
||||
)
|
||||
|
||||
return (
|
||||
<div {...getTableProps()} className="table">
|
||||
<div>
|
||||
{headerGroups.map(headerGroup => (
|
||||
<div {...headerGroup.getHeaderGroupProps()} className="tr">
|
||||
{headerGroup.headers.map(column => (
|
||||
<div {...column.getHeaderProps()} className="th">
|
||||
{column.render('Header')}
|
||||
{/* Use column.getResizerProps to hook up the events correctly */}
|
||||
<div
|
||||
{...column.getResizerProps()}
|
||||
className={`resizer ${column.isResizing ? 'isResizing' : ''}`}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div {...getTableBodyProps()}>
|
||||
{rows.map(
|
||||
(row, i) =>
|
||||
prepareRow(row) || (
|
||||
<div {...row.getRowProps()} className="tr">
|
||||
{row.cells.map(cell => {
|
||||
return (
|
||||
<div {...cell.getCellProps()} className="td">
|
||||
{cell.render('Cell')}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function App() {
|
||||
const columns = React.useMemo(
|
||||
() => [
|
||||
{
|
||||
Header: 'Name',
|
||||
columns: [
|
||||
{
|
||||
Header: 'First Name',
|
||||
accessor: 'firstName',
|
||||
},
|
||||
{
|
||||
Header: 'Last Name',
|
||||
accessor: 'lastName',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
Header: 'Info',
|
||||
columns: [
|
||||
{
|
||||
Header: 'Age',
|
||||
accessor: 'age',
|
||||
width: 50,
|
||||
},
|
||||
{
|
||||
Header: 'Visits',
|
||||
accessor: 'visits',
|
||||
width: 60,
|
||||
},
|
||||
{
|
||||
Header: 'Status',
|
||||
accessor: 'status',
|
||||
},
|
||||
{
|
||||
Header: 'Profile Progress',
|
||||
accessor: 'progress',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
[]
|
||||
)
|
||||
|
||||
const data = React.useMemo(() => makeData(20), [])
|
||||
|
||||
return (
|
||||
<Styles>
|
||||
<Table columns={columns} data={data} />
|
||||
</Styles>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
@@ -0,0 +1,9 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './App'
|
||||
|
||||
it('renders without crashing', () => {
|
||||
const div = document.createElement('div')
|
||||
ReactDOM.render(<App />, div)
|
||||
ReactDOM.unmountComponentAtNode(div)
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import './index.css'
|
||||
import App from './App'
|
||||
import * as serviceWorker from './serviceWorker'
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('root'))
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||
serviceWorker.unregister()
|
||||
@@ -0,0 +1,40 @@
|
||||
import namor from 'namor'
|
||||
|
||||
const range = len => {
|
||||
const arr = []
|
||||
for (let i = 0; i < len; i++) {
|
||||
arr.push(i)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
const newPerson = () => {
|
||||
const statusChance = Math.random()
|
||||
return {
|
||||
firstName: namor.generate({ words: 1, numbers: 0 }),
|
||||
lastName: namor.generate({ words: 1, numbers: 0 }),
|
||||
age: Math.floor(Math.random() * 30),
|
||||
visits: Math.floor(Math.random() * 100),
|
||||
progress: Math.floor(Math.random() * 100),
|
||||
status:
|
||||
statusChance > 0.66
|
||||
? 'relationship'
|
||||
: statusChance > 0.33
|
||||
? 'complicated'
|
||||
: 'single',
|
||||
}
|
||||
}
|
||||
|
||||
export default function makeData(...lens) {
|
||||
const makeDataLevel = (depth = 0) => {
|
||||
const len = lens[depth]
|
||||
return range(len).map(d => {
|
||||
return {
|
||||
...newPerson(),
|
||||
subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return makeDataLevel()
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.1/8 is considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
)
|
||||
|
||||
export function register(config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href)
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config)
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
)
|
||||
})
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl, config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing
|
||||
if (installingWorker == null) {
|
||||
return
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
)
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration)
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.')
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error)
|
||||
})
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl, config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl)
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type')
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister()
|
||||
})
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -95,7 +95,7 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
nextPage,
|
||||
previousPage,
|
||||
setPageSize,
|
||||
state: [{ pageIndex, pageSize }],
|
||||
state: { pageIndex, pageSize },
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
|
||||
@@ -40,7 +40,7 @@ function Table({ columns: userColumns, data }) {
|
||||
headerGroups,
|
||||
rows,
|
||||
prepareRow,
|
||||
state: [{ expanded }],
|
||||
state: { expanded },
|
||||
} = useTable(
|
||||
{
|
||||
columns: userColumns,
|
||||
|
||||
@@ -235,7 +235,7 @@ function Table({ columns, data }) {
|
||||
<>
|
||||
<div>
|
||||
<pre>
|
||||
<code>{JSON.stringify(state[0].filters, null, 2)}</code>
|
||||
<code>{JSON.stringify(state.filters, null, 2)}</code>
|
||||
</pre>
|
||||
</div>
|
||||
<table {...getTableProps()}>
|
||||
|
||||
@@ -40,7 +40,7 @@ function Table({ columns, data }) {
|
||||
headerGroups,
|
||||
rows,
|
||||
prepareRow,
|
||||
state: [{ groupBy, expanded }],
|
||||
state: { groupBy, expanded },
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
useGroupBy,
|
||||
useExpanded,
|
||||
useRowSelect,
|
||||
useTableState,
|
||||
} from 'react-table'
|
||||
import matchSorter from 'match-sorter'
|
||||
|
||||
@@ -265,8 +264,6 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
[]
|
||||
)
|
||||
|
||||
const tableState = useTableState({ pageIndex: 2 })
|
||||
|
||||
// Use the state and functions returned from useTable to build your UI
|
||||
const {
|
||||
getTableProps,
|
||||
@@ -285,7 +282,14 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
nextPage,
|
||||
previousPage,
|
||||
setPageSize,
|
||||
state: [{ pageIndex, pageSize, groupBy, expanded, filters, selectedRows }],
|
||||
state: {
|
||||
pageIndex,
|
||||
pageSize,
|
||||
groupBy,
|
||||
expanded,
|
||||
filters,
|
||||
selectedRowPaths,
|
||||
},
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
@@ -293,7 +297,7 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
defaultColumn,
|
||||
filterTypes,
|
||||
// nestExpandedRows: true,
|
||||
state: tableState,
|
||||
initialState: { pageIndex: 2 },
|
||||
// updateMyData isn't part of the API, but
|
||||
// anything we put into these options will
|
||||
// automatically be available on the instance.
|
||||
@@ -438,7 +442,7 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
groupBy,
|
||||
expanded,
|
||||
filters,
|
||||
selectedRows,
|
||||
selectedRowPaths,
|
||||
},
|
||||
null,
|
||||
2
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
useGroupBy,
|
||||
useExpanded,
|
||||
useRowSelect,
|
||||
useTableState,
|
||||
} from 'react-table'
|
||||
import matchSorter from 'match-sorter'
|
||||
|
||||
@@ -265,8 +264,6 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
[]
|
||||
)
|
||||
|
||||
const tableState = useTableState({ pageIndex: 2 })
|
||||
|
||||
// Use the state and functions returned from useTable to build your UI
|
||||
const {
|
||||
getTableProps,
|
||||
@@ -285,7 +282,14 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
nextPage,
|
||||
previousPage,
|
||||
setPageSize,
|
||||
state: [{ pageIndex, pageSize, groupBy, expanded, filters, selectedRows }],
|
||||
state: {
|
||||
pageIndex,
|
||||
pageSize,
|
||||
groupBy,
|
||||
expanded,
|
||||
filters,
|
||||
selectedRowPaths,
|
||||
},
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
@@ -293,7 +297,7 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
defaultColumn,
|
||||
filterTypes,
|
||||
// nestExpandedRows: true,
|
||||
state: tableState,
|
||||
initialState: { pageIndex: 2 },
|
||||
// updateMyData isn't part of the API, but
|
||||
// anything we put into these options will
|
||||
// automatically be available on the instance.
|
||||
@@ -438,7 +442,7 @@ function Table({ columns, data, updateMyData, disablePageResetOnDataChange }) {
|
||||
groupBy,
|
||||
expanded,
|
||||
filters,
|
||||
selectedRows,
|
||||
selectedRowPaths,
|
||||
},
|
||||
null,
|
||||
2
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react'
|
||||
import styled from 'styled-components'
|
||||
import { useTable, useTableState, usePagination } from 'react-table'
|
||||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
import { useTable, usePagination } from "react-table";
|
||||
|
||||
import makeData from './makeData'
|
||||
import makeData from "./makeData";
|
||||
|
||||
const Styles = styled.div`
|
||||
padding: 1rem;
|
||||
@@ -35,7 +35,7 @@ const Styles = styled.div`
|
||||
.pagination {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
// Let's add a fetchData method to our Table component that will be used to fetch
|
||||
// new data when pagination state changes
|
||||
@@ -45,19 +45,8 @@ function Table({
|
||||
data,
|
||||
fetchData,
|
||||
loading,
|
||||
pageCount: controlledPageCount,
|
||||
pageCount: controlledPageCount
|
||||
}) {
|
||||
// Use useTableState to hoist the state (and state updater) out of the table and control it
|
||||
const tableState = useTableState({ pageIndex: 0 })
|
||||
|
||||
// Now we can get our table state from the hoisted table state tuple
|
||||
const [{ pageIndex, pageSize }] = tableState
|
||||
|
||||
// Listen for changes in pagination and use the state to fetch our new data
|
||||
React.useEffect(() => {
|
||||
fetchData({ pageIndex, pageSize })
|
||||
}, [fetchData, pageIndex, pageSize])
|
||||
|
||||
const {
|
||||
getTableProps,
|
||||
getTableBodyProps,
|
||||
@@ -72,19 +61,30 @@ function Table({
|
||||
nextPage,
|
||||
previousPage,
|
||||
setPageSize,
|
||||
rows,
|
||||
// Get the state from the instance
|
||||
state: { pageIndex, pageSize }
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
data,
|
||||
state: tableState, // Pass our hoisted table state
|
||||
initialState: { pageIndex: 0 }, // Pass our hoisted table state
|
||||
manualPagination: true, // Tell the usePagination
|
||||
// hook that we'll handle our own data fetching
|
||||
// This means we'll also have to provide our own
|
||||
// pageCount.
|
||||
pageCount: controlledPageCount,
|
||||
pageCount: controlledPageCount
|
||||
},
|
||||
usePagination
|
||||
)
|
||||
);
|
||||
|
||||
// Now we can get our table state from the hoisted table state tuple
|
||||
|
||||
// Listen for changes in pagination and use the state to fetch our new data
|
||||
React.useEffect(() => {
|
||||
console.log(pageIndex);
|
||||
fetchData({ pageIndex, pageSize });
|
||||
}, [fetchData, pageIndex, pageSize]);
|
||||
|
||||
// Render the UI for your table
|
||||
return (
|
||||
@@ -97,7 +97,7 @@ function Table({
|
||||
pageSize,
|
||||
pageCount,
|
||||
canNextPage,
|
||||
canPreviousPage,
|
||||
canPreviousPage
|
||||
},
|
||||
null,
|
||||
2
|
||||
@@ -109,7 +109,7 @@ function Table({
|
||||
{headerGroups.map(headerGroup => (
|
||||
<tr {...headerGroup.getHeaderGroupProps()}>
|
||||
{headerGroup.headers.map(column => (
|
||||
<th {...column.getHeaderProps()}>{column.render('Header')}</th>
|
||||
<th {...column.getHeaderProps()}>{column.render("Header")}</th>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
@@ -121,18 +121,23 @@ function Table({
|
||||
<tr {...row.getRowProps()}>
|
||||
{row.cells.map(cell => {
|
||||
return (
|
||||
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
|
||||
)
|
||||
<td {...cell.getCellProps()}>{cell.render("Cell")}</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
)
|
||||
)}
|
||||
{loading ? (
|
||||
// Use our custom loading state to show a loading indicator
|
||||
<tr>
|
||||
<tr>
|
||||
{loading ? (
|
||||
// Use our custom loading state to show a loading indicator
|
||||
<td>Loading...</td>
|
||||
</tr>
|
||||
) : null}
|
||||
) : (
|
||||
<td>
|
||||
Showing {page.length} of ~{controlledPageCount * pageSize}{" "}
|
||||
results
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{/*
|
||||
@@ -141,39 +146,39 @@ function Table({
|
||||
*/}
|
||||
<div className="pagination">
|
||||
<button onClick={() => gotoPage(0)} disabled={!canPreviousPage}>
|
||||
{'<<'}
|
||||
</button>{' '}
|
||||
{"<<"}
|
||||
</button>{" "}
|
||||
<button onClick={() => previousPage()} disabled={!canPreviousPage}>
|
||||
{'<'}
|
||||
</button>{' '}
|
||||
{"<"}
|
||||
</button>{" "}
|
||||
<button onClick={() => nextPage()} disabled={!canNextPage}>
|
||||
{'>'}
|
||||
</button>{' '}
|
||||
{">"}
|
||||
</button>{" "}
|
||||
<button onClick={() => gotoPage(pageCount - 1)} disabled={!canNextPage}>
|
||||
{'>>'}
|
||||
</button>{' '}
|
||||
{">>"}
|
||||
</button>{" "}
|
||||
<span>
|
||||
Page{' '}
|
||||
Page{" "}
|
||||
<strong>
|
||||
{pageIndex + 1} of {pageOptions.length}
|
||||
</strong>{' '}
|
||||
</strong>{" "}
|
||||
</span>
|
||||
<span>
|
||||
| Go to page:{' '}
|
||||
| Go to page:{" "}
|
||||
<input
|
||||
type="number"
|
||||
defaultValue={pageIndex + 1}
|
||||
onChange={e => {
|
||||
const page = e.target.value ? Number(e.target.value) - 1 : 0
|
||||
gotoPage(page)
|
||||
const page = e.target.value ? Number(e.target.value) - 1 : 0;
|
||||
gotoPage(page);
|
||||
}}
|
||||
style={{ width: '100px' }}
|
||||
style={{ width: "100px" }}
|
||||
/>
|
||||
</span>{' '}
|
||||
</span>{" "}
|
||||
<select
|
||||
value={pageSize}
|
||||
onChange={e => {
|
||||
setPageSize(Number(e.target.value))
|
||||
setPageSize(Number(e.target.value));
|
||||
}}
|
||||
>
|
||||
{[10, 20, 30, 40, 50].map(pageSize => (
|
||||
@@ -184,79 +189,86 @@ function Table({
|
||||
</select>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Let's simulate a large dataset on the server (outside of our component)
|
||||
const serverData = makeData(10000)
|
||||
const serverData = makeData(10000);
|
||||
|
||||
function App() {
|
||||
const columns = React.useMemo(
|
||||
() => [
|
||||
{
|
||||
Header: 'Name',
|
||||
Header: "Name",
|
||||
columns: [
|
||||
{
|
||||
Header: 'First Name',
|
||||
accessor: 'firstName',
|
||||
Header: "First Name",
|
||||
accessor: "firstName"
|
||||
},
|
||||
{
|
||||
Header: 'Last Name',
|
||||
accessor: 'lastName',
|
||||
},
|
||||
],
|
||||
Header: "Last Name",
|
||||
accessor: "lastName"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
Header: 'Info',
|
||||
Header: "Info",
|
||||
columns: [
|
||||
{
|
||||
Header: 'Age',
|
||||
accessor: 'age',
|
||||
Header: "Age",
|
||||
accessor: "age"
|
||||
},
|
||||
{
|
||||
Header: 'Visits',
|
||||
accessor: 'visits',
|
||||
Header: "Visits",
|
||||
accessor: "visits"
|
||||
},
|
||||
{
|
||||
Header: 'Status',
|
||||
accessor: 'status',
|
||||
Header: "Status",
|
||||
accessor: "status"
|
||||
},
|
||||
{
|
||||
Header: 'Profile Progress',
|
||||
accessor: 'progress',
|
||||
},
|
||||
],
|
||||
},
|
||||
Header: "Profile Progress",
|
||||
accessor: "progress"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
||||
// We'll start our table without any data
|
||||
const [data, setData] = React.useState([])
|
||||
const [loading, setLoading] = React.useState(false)
|
||||
const [pageCount, setPageCount] = React.useState(0)
|
||||
const [data, setData] = React.useState([]);
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
const [pageCount, setPageCount] = React.useState(0);
|
||||
const fetchIdRef = React.useRef(0);
|
||||
|
||||
const fetchData = React.useCallback(({ pageSize, pageIndex }) => {
|
||||
// This will get called when the table needs new data
|
||||
// You could fetch your data from literally anywhere,
|
||||
// even a server. But for this example, we'll just fake it.
|
||||
|
||||
// Give this fetch an ID
|
||||
const fetchID = ++fetchIdRef.current;
|
||||
|
||||
// Set the loading state
|
||||
setLoading(true)
|
||||
setLoading(true);
|
||||
|
||||
// We'll even set a delay to simulate a server here
|
||||
setTimeout(() => {
|
||||
const startRow = pageSize * pageIndex
|
||||
const endRow = startRow + pageSize
|
||||
setData(serverData.slice(startRow, endRow))
|
||||
// Only update the data if this is the latest fetch
|
||||
if (fetchID === fetchIdRef.current) {
|
||||
const startRow = pageSize * pageIndex;
|
||||
const endRow = startRow + pageSize;
|
||||
setData(serverData.slice(startRow, endRow));
|
||||
|
||||
// Your server could send back total page count.
|
||||
// For now we'll just fake it, too
|
||||
setPageCount(Math.ceil(serverData.length / pageSize))
|
||||
// Your server could send back total page count.
|
||||
// For now we'll just fake it, too
|
||||
setPageCount(Math.ceil(serverData.length / pageSize));
|
||||
|
||||
setLoading(false)
|
||||
}, 1000)
|
||||
}, [])
|
||||
setLoading(false);
|
||||
}
|
||||
}, 1000);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Styles>
|
||||
@@ -268,7 +280,7 @@ function App() {
|
||||
pageCount={pageCount}
|
||||
/>
|
||||
</Styles>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default App
|
||||
export default App;
|
||||
|
||||
@@ -42,7 +42,7 @@ function MyTable(props) {
|
||||
prepareRow,
|
||||
+ pageOptions,
|
||||
+ page,
|
||||
+ state: [{ pageIndex, pageSize }],
|
||||
+ state: { pageIndex, pageSize },
|
||||
+ gotoPage,
|
||||
+ previousPage,
|
||||
+ nextPage,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import styled from 'styled-components'
|
||||
import { useTable, usePagination, useTableState } from 'react-table'
|
||||
import { useTable, usePagination } from 'react-table'
|
||||
|
||||
import makeData from './makeData'
|
||||
|
||||
@@ -38,8 +38,6 @@ const Styles = styled.div`
|
||||
`
|
||||
|
||||
function Table({ columns, data }) {
|
||||
const tableState = useTableState({ pageIndex: 2 })
|
||||
|
||||
// Use the state and functions returned from useTable to build your UI
|
||||
const {
|
||||
getTableProps,
|
||||
@@ -58,12 +56,12 @@ function Table({ columns, data }) {
|
||||
nextPage,
|
||||
previousPage,
|
||||
setPageSize,
|
||||
state: [{ pageIndex, pageSize }],
|
||||
state: { pageIndex, pageSize },
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
data,
|
||||
state: tableState,
|
||||
initialState: { pageIndex: 2 },
|
||||
},
|
||||
usePagination
|
||||
)
|
||||
|
||||
@@ -41,7 +41,8 @@ function Table({ columns, data }) {
|
||||
headerGroups,
|
||||
rows,
|
||||
prepareRow,
|
||||
state: [{ selectedRows }],
|
||||
selectedFlatRows,
|
||||
state: { selectedRowPaths },
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
@@ -78,9 +79,20 @@ function Table({ columns, data }) {
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Selected Rows: {selectedRows.length}</p>
|
||||
<p>Selected Rows: {selectedRowPaths.length}</p>
|
||||
<pre>
|
||||
<code>{JSON.stringify({ selectedRows }, null, 2)}</code>
|
||||
<code>
|
||||
{JSON.stringify(
|
||||
{
|
||||
selectedRowPaths,
|
||||
'selectedFlatRows[].original': selectedFlatRows.map(
|
||||
d => d.original
|
||||
),
|
||||
},
|
||||
null,
|
||||
2
|
||||
)}
|
||||
</code>
|
||||
</pre>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ function Table({ columns: userColumns, data, renderRowSubComponent }) {
|
||||
rows,
|
||||
prepareRow,
|
||||
flatColumns,
|
||||
state: [{ expanded }],
|
||||
state: { expanded },
|
||||
} = useTable(
|
||||
{
|
||||
columns: userColumns,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"infiniteLoopProtection": false,
|
||||
"hardReloadOnChange": false,
|
||||
"view": "browser"
|
||||
}
|
||||
@@ -85,8 +85,6 @@ function Table({ columns, data }) {
|
||||
[prepareRow, rows]
|
||||
)
|
||||
|
||||
console.log(headerGroups)
|
||||
|
||||
// Render the UI for your table
|
||||
return (
|
||||
<div {...getTableProps()} className="table">
|
||||
|
||||
Vendored
+615
-273
@@ -1,288 +1,630 @@
|
||||
declare module 'react-table' {
|
||||
import { ReactNode, useState } from 'react'
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
type StringKey<D> = Extract<keyof D, string>
|
||||
type IdType<D> = StringKey<D> | string
|
||||
import { ReactNode, ComponentType, MouseEvent } from 'react'
|
||||
|
||||
type SortingRule<D> = {
|
||||
id: IdType<D>
|
||||
desc: boolean
|
||||
}
|
||||
/**
|
||||
* 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 type SortingRules<D> = SortingRule<D>[]
|
||||
export interface TableInstance<D extends object = {}>
|
||||
extends Omit<TableOptions<D>, 'columns' | 'state'>,
|
||||
UseTableInstanceProps<D> {}
|
||||
|
||||
export type SortByFn = (a: any, b: any, desc: boolean) => 0 | 1 | -1
|
||||
export interface TableState<
|
||||
D extends object = {}
|
||||
> {} /* tslint:disable-line no-empty-interface */ // eslint-disable-line @typescript-eslint/no-empty-interface
|
||||
|
||||
export type Filters<D> = Record<IdType<D>, string>
|
||||
export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}
|
||||
|
||||
export interface Cell<D = {}> extends TableInstance<D> {
|
||||
cell: { value: any }
|
||||
column: Column<D>
|
||||
row: Row<D>
|
||||
render: (type: 'Cell' | 'Aggregated', userProps?: any) => any
|
||||
isGrouped?: boolean
|
||||
isAggregated?: boolean
|
||||
isRepeatedValue?: boolean
|
||||
getCellProps: () => any
|
||||
}
|
||||
export interface Cell<D extends object = {}> extends UseTableCellProps<D> {}
|
||||
|
||||
export interface Row<D = {}> {
|
||||
index: number
|
||||
cells: Cell<D>[]
|
||||
getRowProps: (userProps?: any) => any
|
||||
original: D
|
||||
path: any[]
|
||||
values: any[]
|
||||
depth: number
|
||||
}
|
||||
export interface Column<D extends object = {}>
|
||||
extends UseTableColumnOptions<D> {}
|
||||
|
||||
export interface UseExpandedRow<D = {}> {
|
||||
subRows?: D[]
|
||||
groupByID?: string | number
|
||||
toggleExpanded?: () => any
|
||||
isExpanded?: boolean
|
||||
isAggregated?: boolean
|
||||
}
|
||||
export interface ColumnInstance<D extends object = {}>
|
||||
extends Omit<Column<D>, 'id'>,
|
||||
UseTableColumnProps<D> {}
|
||||
|
||||
export type AccessorFn<D> = (
|
||||
originalRow: D,
|
||||
index: number,
|
||||
sub: {
|
||||
subRows: [D]
|
||||
depth: number
|
||||
data: [D]
|
||||
}
|
||||
) => unknown
|
||||
export interface HeaderGroup<D extends object = {}>
|
||||
extends ColumnInstance<D>,
|
||||
UseTableHeaderGroupProps<D> {}
|
||||
|
||||
export interface HeaderColumn<D> {
|
||||
/**
|
||||
* This string/function is used to build the data model for your column.
|
||||
*/
|
||||
accessor: IdType<D> | AccessorFn<D>
|
||||
Header?: ReactNode | ((props: TableInstance<D>) => ReactNode)
|
||||
Filter?: ReactNode | ((props: TableInstance<D>) => ReactNode)
|
||||
Cell?: ReactNode | ((cell: Cell<D>) => ReactNode)
|
||||
/**
|
||||
* This is the unique ID for the column. It is used by reference in things like sorting, grouping, filtering etc.
|
||||
*/
|
||||
id?: IdType<D>
|
||||
minWidth?: string | number
|
||||
maxWidth?: string | number
|
||||
width?: string | number
|
||||
disableSorting?: boolean
|
||||
canSortBy?: boolean
|
||||
sortByFn?: SortByFn
|
||||
defaultSortDesc?: boolean
|
||||
isAggregated?: any
|
||||
}
|
||||
export interface Row<D extends object = {}> extends UseTableRowProps<D> {}
|
||||
|
||||
export interface Column<D> extends HeaderColumn<D> {
|
||||
show?: boolean | ((instance: TableInstance<D>) => boolean)
|
||||
columns?: Column<D>[]
|
||||
}
|
||||
/* #region useTable */
|
||||
export function useTable<D extends object = {}>(
|
||||
options: TableOptions<D>,
|
||||
...plugins: PluginHook<D>[]
|
||||
): TableInstance<D>
|
||||
|
||||
export type Page<D = {}> = Row<D>[]
|
||||
/**
|
||||
* NOTE: To use custom options, use "Interface Merging" to add the custom options
|
||||
*/
|
||||
export type UseTableOptions<D extends object> = {
|
||||
columns: 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: (row: Row<D>, relativeIndex: number) => Row<D>[]
|
||||
getRowID: (row: Row<D>, relativeIndex: number) => string
|
||||
debug: boolean
|
||||
}>
|
||||
|
||||
export interface EnhancedColumn<D>
|
||||
extends Omit<Column<D>, 'columns'>,
|
||||
TableInstance<D> {
|
||||
id: IdType<D>
|
||||
column: Column<D>
|
||||
render: (type: 'Header' | 'Filter', userProps?: any) => any
|
||||
getHeaderProps: (userProps?: any) => any
|
||||
getSortByToggleProps: (userProps?: any) => any
|
||||
isSorted: boolean
|
||||
isSortedDesc: boolean
|
||||
sortedIndex: number
|
||||
isVisible: boolean
|
||||
canSort?: boolean
|
||||
}
|
||||
export interface UseTableHooks<D extends object> {
|
||||
columnsBeforeHeaderGroups: ((
|
||||
flatColumns: Column<D>[],
|
||||
instance: TableInstance<D>
|
||||
) => Column<D>[])[]
|
||||
columnsBeforeHeaderGroupsDeps: ((
|
||||
deps: any[],
|
||||
instance: TableInstance<D>
|
||||
) => any[])[]
|
||||
useMain: ((instance: TableInstance<D>) => TableInstance<D>)[]
|
||||
useRows: ((rows: Row<D>[], instance: TableInstance<D>) => Row<D>[])[]
|
||||
prepareRow: ((row: Row<D>, instance: TableInstance<D>) => Row<D>)[]
|
||||
|
||||
export interface HeaderGroup<D = {}> {
|
||||
headers: EnhancedColumn<D>[]
|
||||
getHeaderGroupProps: (userProps?: any) => any
|
||||
}
|
||||
|
||||
export interface Hooks {
|
||||
columnsBeforeHeaderGroups: any[]
|
||||
columnsBeforeHeaderGroupsDeps: any[]
|
||||
useMain: any[]
|
||||
useColumns: any[]
|
||||
useHeaders: any[]
|
||||
useHeaderGroups: any[]
|
||||
useRows: any[]
|
||||
prepareRow: any[]
|
||||
getTableProps: any[]
|
||||
getRowProps: any[]
|
||||
getHeaderGroupProps: any[]
|
||||
getHeaderProps: any[]
|
||||
getCellProps: any[]
|
||||
}
|
||||
|
||||
export interface RowsProps {
|
||||
subRowsKey: string
|
||||
}
|
||||
|
||||
export interface FiltersProps {
|
||||
filterFn: () => void
|
||||
manualFilters: boolean
|
||||
disableFilters: boolean
|
||||
setFilter: () => any
|
||||
setAllFilters: () => any
|
||||
}
|
||||
|
||||
export interface UsePaginationState {
|
||||
pageIndex: number
|
||||
pageSize: number
|
||||
pageCount: number
|
||||
rowCount: number
|
||||
}
|
||||
|
||||
export interface UsePaginationValues<D = {}> {
|
||||
page: Page<D>
|
||||
pageIndex: number // yes, this is on instance and state
|
||||
pageSize: number // yes, this is on instance and state
|
||||
canPreviousPage: boolean
|
||||
canNextPage: boolean
|
||||
nextPage: () => any
|
||||
previousPage: () => any
|
||||
setPageSize: (size: number) => any
|
||||
pageOptions: any[]
|
||||
manualPagination: boolean
|
||||
paginateExpandedRows: boolean
|
||||
disablePageResetOnDataChange: boolean
|
||||
pageCount: number
|
||||
gotoPage: (page: number) => any
|
||||
}
|
||||
|
||||
export interface UseFiltersState<D> {
|
||||
filters?: Filters<D>
|
||||
}
|
||||
|
||||
export interface UseFiltersValues<D> {
|
||||
setFilter: (columnID: keyof D, value: string) => void
|
||||
setAllFilters: (values: Filters<D>) => void
|
||||
disableFilters: boolean
|
||||
}
|
||||
|
||||
export interface UseGroupByValues {
|
||||
groupByFn: any
|
||||
manualGroupBy: boolean
|
||||
disableGrouping: boolean
|
||||
aggregations: any
|
||||
}
|
||||
|
||||
export interface UseGroupByState {
|
||||
groupBy: string[]
|
||||
isAggregated?: boolean
|
||||
}
|
||||
|
||||
export interface UseExpandedValues {
|
||||
toggleExpanded?: () => any
|
||||
}
|
||||
|
||||
export interface UseSortbyOptions {
|
||||
sortByFn?: SortByFn
|
||||
manualSorting?: boolean
|
||||
disableSorting?: boolean
|
||||
defaultSortDesc?: boolean
|
||||
disableMultiSort?: boolean
|
||||
}
|
||||
|
||||
export interface UseSortbyState<D> {
|
||||
sortBy?: SortingRules<D>
|
||||
}
|
||||
|
||||
export interface TableInstance<D = {}> extends TableOptions<D> {
|
||||
hooks: Hooks
|
||||
rows: Row<D>[]
|
||||
columns: EnhancedColumn<D>[]
|
||||
headerGroups: HeaderGroup<D>[]
|
||||
headers: HeaderGroup<D>[]
|
||||
getTableProps: (userProps?: any) => any
|
||||
getRowProps: (userProps?: any) => any
|
||||
prepareRow: (row: Row<D>) => any
|
||||
}
|
||||
|
||||
export interface TableOptions<D = {}> {
|
||||
data: D[]
|
||||
columns: HeaderColumn<D>[]
|
||||
state: State<D>
|
||||
debug?: boolean
|
||||
loading: boolean
|
||||
defaultColumn?: Partial<Column<D>>
|
||||
}
|
||||
|
||||
// The empty definition of TableState is not an error. It provides a definition
|
||||
// for the state, that can then be extended in the users code.
|
||||
//
|
||||
// e.g.
|
||||
//
|
||||
// export interface TableState<D = {}}>
|
||||
// extends UsePaginationState,
|
||||
// UseGroupByState,
|
||||
// UseSortbyState<D>,
|
||||
// UseFiltersState<D> {}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface TableState<D = {}> {}
|
||||
|
||||
export type SetState<D> = (
|
||||
updater: (old: TableState<D>) => TableState<D>,
|
||||
actions: any
|
||||
) => void
|
||||
|
||||
export type State<D> = [TableState<D>, SetState<D>]
|
||||
|
||||
export function useTable<D = {}>(
|
||||
props: TableOptions<D>,
|
||||
...plugins: any[]
|
||||
): TableInstance<D>
|
||||
|
||||
export function useFilters<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & {
|
||||
rows: Row<D>[]
|
||||
}
|
||||
|
||||
export function useSortBy<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & {
|
||||
rows: Row<D>[]
|
||||
}
|
||||
|
||||
export function useGroupBy<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & { rows: Row<D>[] }
|
||||
|
||||
export function usePagination<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): UsePaginationValues<D>
|
||||
|
||||
export function useExpanded<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & {
|
||||
toggleExpandedByPath: () => any
|
||||
expandedDepth: []
|
||||
rows: Row<D>[]
|
||||
}
|
||||
|
||||
export function useTableState<D = {}>(
|
||||
initialState?: Partial<TableState<D>>,
|
||||
overriddenState?: Partial<TableState<D>>,
|
||||
options?: {
|
||||
reducer?: (
|
||||
oldState: TableState<D>,
|
||||
newState: TableState<D>,
|
||||
type: string
|
||||
) => any
|
||||
useState?: typeof useState
|
||||
}
|
||||
): State<D>
|
||||
|
||||
export const actions: Record<string, string>
|
||||
|
||||
export function addActions(...actions: string[]): void
|
||||
|
||||
export const defaultState: Record<string, any>
|
||||
// Prop Hooks
|
||||
getTableProps: ((instance: TableInstance<D>) => object)[]
|
||||
getTableBodyProps: ((instance: TableInstance<D>) => object)[]
|
||||
getRowProps: ((row: Row<D>, instance: TableInstance<D>) => object)[]
|
||||
getHeaderGroupProps: ((
|
||||
headerGroup: HeaderGroup<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
getHeaderProps: ((column: Column<D>, instance: TableInstance<D>) => object)[]
|
||||
getCellProps: ((cell: Cell<D>, instance: TableInstance<D>) => object)[]
|
||||
}
|
||||
|
||||
export interface UseTableColumnOptions<D extends object>
|
||||
extends Accessor<D>,
|
||||
Partial<{
|
||||
columns: 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: ColumnInstance<D>[]
|
||||
flatColumns: ColumnInstance<D>[]
|
||||
headerGroups: HeaderGroup<D>[]
|
||||
headers: ColumnInstance<D>[]
|
||||
flatHeaders: ColumnInstance<D>[]
|
||||
rows: Row<D>[]
|
||||
getTableProps: (props?: object) => object
|
||||
getTableBodyProps: (props?: object) => object
|
||||
prepareRow: (row: Row<D>) => void
|
||||
rowPaths: string[]
|
||||
flatRows: Row<D>[]
|
||||
state: TableState<D>
|
||||
setState: SetState<D>
|
||||
totalColumnsWidth: number
|
||||
}
|
||||
|
||||
export interface UseTableHeaderGroupProps<D extends object> {
|
||||
headers: 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: Cell<D>[]
|
||||
values: Record<IdType<D>, CellValue>
|
||||
getRowProps: (props?: object) => object
|
||||
index: number
|
||||
original: D
|
||||
path: IdType<D>[]
|
||||
subRows: 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>
|
||||
} & Record<string, any>
|
||||
export type CellProps<D extends object> = TableInstance<D> & {
|
||||
column: ColumnInstance<D>
|
||||
row: Row<D>
|
||||
cell: Cell<D>
|
||||
} & Record<string, any>
|
||||
|
||||
// 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: IdType<D>[]
|
||||
}
|
||||
|
||||
export interface UseColumnOrderInstanceProps<D extends object> {
|
||||
setColumnOrder: (updater: (columnOrder: IdType<D>[]) => 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<{
|
||||
getSubRows: (row: Row<D>, relativeIndex: number) => Row<D>[]
|
||||
manualExpandedKey: IdType<D>
|
||||
paginateExpandedRows: boolean
|
||||
}>
|
||||
|
||||
export interface UseExpandedHooks<D extends object> {
|
||||
getExpandedToggleProps: ((
|
||||
row: Row<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
}
|
||||
|
||||
export interface UseExpandedState<D extends object> {
|
||||
expanded: IdType<D>[]
|
||||
}
|
||||
|
||||
export interface UseExpandedInstanceProps<D extends object> {
|
||||
rows: Row<D>[]
|
||||
toggleExpandedByPath: (path: IdType<D>[], isExpanded: boolean) => void
|
||||
expandedDepth: number
|
||||
}
|
||||
|
||||
export interface UseExpandedRowProps<D extends object> {
|
||||
isExpanded: boolean
|
||||
canExpand: boolean
|
||||
subRows: 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>
|
||||
}>
|
||||
|
||||
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: Row<D>[]
|
||||
preFilteredRows: 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: Row<D>[]
|
||||
filteredRows: 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: Row<D>[],
|
||||
columnId: IdType<D>,
|
||||
filterValue: FilterValue,
|
||||
column: ColumnInstance<D>
|
||||
): 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
|
||||
disableGrouping: boolean
|
||||
aggregations: Record<string, AggregatorFn<D>>
|
||||
groupByFn: (rows: Row<D>[], columnId: IdType<D>) => Record<string, Row<D>>
|
||||
}>
|
||||
|
||||
export interface UseGroupByHooks<D extends object> {
|
||||
getGroupByToggleProps: ((
|
||||
header: HeaderGroup<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
}
|
||||
|
||||
export interface UseGroupByState<D extends object> {
|
||||
groupBy: IdType<D>[]
|
||||
}
|
||||
|
||||
export type UseGroupByColumnOptions<D extends object> = Partial<{
|
||||
aggregate: Aggregator<D> | Aggregator<D>[]
|
||||
Aggregated: Renderer<CellProps<D>>
|
||||
disableGrouping: boolean
|
||||
groupByBoundary: boolean
|
||||
}>
|
||||
|
||||
export interface UseGroupByInstanceProps<D extends object> {
|
||||
rows: Row<D>[]
|
||||
preGroupedRows: Row<D>[]
|
||||
toggleGroupBy: (columnId: IdType<D>, toggle: boolean) => void
|
||||
}
|
||||
|
||||
export interface UseGroupByColumnProps<D extends object> {
|
||||
canGroupBy: boolean
|
||||
isGrouped: boolean
|
||||
groupedIndex: number
|
||||
toggleGroupBy: () => void
|
||||
}
|
||||
|
||||
export interface UseGroupByHeaderProps<D extends object> {
|
||||
getGroupByToggleProps: (props?: object) => object
|
||||
}
|
||||
|
||||
export interface UseGroupByRowProps<D extends object> {
|
||||
isAggregated: boolean
|
||||
groupByID: IdType<D>
|
||||
groupByVal: string
|
||||
values: Record<IdType<D>, AggregatedValue>
|
||||
subRows: Row<D>[]
|
||||
depth: number
|
||||
path: 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: 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
|
||||
disablePageResetOnDataChange: boolean
|
||||
paginateExpandedRows: boolean
|
||||
}>
|
||||
|
||||
export interface UsePaginationState<D extends object> {
|
||||
pageSize: number
|
||||
pageIndex: number
|
||||
}
|
||||
|
||||
export interface UsePaginationInstanceProps<D extends object> {
|
||||
page: 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>
|
||||
}>
|
||||
|
||||
export interface UseRowSelectHooks<D extends object> {
|
||||
getToggleRowSelectedProps: ((
|
||||
row: Row<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
getToggleAllRowsSelectedProps: ((instance: TableInstance<D>) => object)[]
|
||||
}
|
||||
|
||||
export interface UseRowSelectState<D extends object> {
|
||||
selectedRows: 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
|
||||
}
|
||||
|
||||
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
|
||||
disableSorting: boolean
|
||||
disableMultiSort: boolean
|
||||
isMultiSortEvent: (e: MouseEvent) => boolean
|
||||
maxMultiSortColCount: number
|
||||
disableSortRemove: boolean
|
||||
disabledMultiRemove: boolean
|
||||
orderByFn: (
|
||||
rows: Row<D>[],
|
||||
sortFns: SortByFn<D>[],
|
||||
directions: boolean[]
|
||||
) => Row<D>[] // CHECK
|
||||
sortTypes: Record<string, SortByFn<D>>
|
||||
}>
|
||||
|
||||
export interface UseSortByHooks<D extends object> {
|
||||
getSortByToggleProps: ((
|
||||
column: Column<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
}
|
||||
|
||||
export interface UseSortByState<D extends object> {
|
||||
sortBy: SortingRule<D>[]
|
||||
}
|
||||
|
||||
export type UseSortByColumnOptions<D extends object> = Partial<{
|
||||
disableSorting: boolean
|
||||
sortDescFirst: boolean
|
||||
sortInverted: boolean
|
||||
sortType: SortByFn<D> | DefaultSortTypes | string
|
||||
}>
|
||||
|
||||
export interface UseSortByInstanceProps<D extends object> {
|
||||
rows: Row<D>[]
|
||||
preSortedRows: 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
|
||||
|
||||
Generated
-11505
File diff suppressed because it is too large
Load Diff
+5
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-table",
|
||||
"version": "7.0.0-beta.3",
|
||||
"version": "7.0.0-beta.12",
|
||||
"description": "A fast, lightweight, opinionated table and datagrid built on React",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/tannerlinsley/react-table#readme",
|
||||
@@ -17,9 +17,10 @@
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.es.js",
|
||||
"jsnext:main": "dist/index.es.js",
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"commit": "git add . && git-cz",
|
||||
"test": "is-ci 'test:ci' 'test:dev'",
|
||||
"test": "is-ci \"test:ci\" \"test:dev\"",
|
||||
"test:dev": "jest --watch",
|
||||
"test:ci": "jest",
|
||||
"build": "rollup -c",
|
||||
@@ -74,7 +75,7 @@
|
||||
"eslint-plugin-react-hooks": "1.7.0",
|
||||
"eslint-plugin-standard": "^4.0.0",
|
||||
"husky": "^3.0.3",
|
||||
"is-ci-cli": "^1.1.1",
|
||||
"is-ci-cli": "^2.0.0",
|
||||
"jest": "^24.8.0",
|
||||
"jest-cli": "^24.8.0",
|
||||
"jest-runner-eslint": "^0.7.4",
|
||||
@@ -90,7 +91,7 @@
|
||||
"rollup-plugin-commonjs": "^9.1.3",
|
||||
"rollup-plugin-node-resolve": "^4.0.0",
|
||||
"rollup-plugin-peer-deps-external": "^2.2.0",
|
||||
"rollup-plugin-uglify": "^6.0.2",
|
||||
"rollup-plugin-terser": "^5.1.2",
|
||||
"snapshot-diff": "^0.5.2"
|
||||
},
|
||||
"config": {
|
||||
|
||||
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
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> {}
|
||||
}
|
||||
+3
-16
@@ -2,7 +2,7 @@ import babel from 'rollup-plugin-babel'
|
||||
import commonjs from 'rollup-plugin-commonjs'
|
||||
import external from 'rollup-plugin-peer-deps-external'
|
||||
import resolve from 'rollup-plugin-node-resolve'
|
||||
import { uglify } from 'rollup-plugin-uglify'
|
||||
import { terser } from 'rollup-plugin-terser'
|
||||
|
||||
import pkg from './package.json'
|
||||
|
||||
@@ -14,28 +14,15 @@ export default [
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
external(),
|
||||
babel({
|
||||
exclude: 'node_modules/**',
|
||||
}),
|
||||
resolve(),
|
||||
commonjs(),
|
||||
uglify(),
|
||||
],
|
||||
plugins: [external(), babel(), resolve(), commonjs(), terser()],
|
||||
},
|
||||
{
|
||||
input: 'src/index.js',
|
||||
external: Object.keys(pkg.peerDependencies),
|
||||
output: {
|
||||
file: pkg.module,
|
||||
format: 'es',
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
babel({
|
||||
exclude: ['/**/node_modules/**'],
|
||||
}),
|
||||
],
|
||||
plugins: [external(), babel()],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -5,11 +5,6 @@ export { actions, types }
|
||||
|
||||
export const addActions = (...acts) => {
|
||||
acts.forEach(action => {
|
||||
if (actions[action]) {
|
||||
throw new Error(
|
||||
`An React Table action type called ${action} has already been registered!`
|
||||
)
|
||||
}
|
||||
// Action values are formatted this way to discourage
|
||||
// you (the dev) from interacting with them in any way
|
||||
// other than importing `{ actions } from 'react-table'`
|
||||
|
||||
+5
-1
@@ -44,7 +44,11 @@ includes.autoRemove = val => !val || !val.length
|
||||
export const includesAll = (rows, id, filterValue) => {
|
||||
return rows.filter(row => {
|
||||
const rowValue = row.values[id]
|
||||
return filterValue.every(val => rowValue.includes(val))
|
||||
return (
|
||||
rowValue &&
|
||||
rowValue.length &&
|
||||
filterValue.every(val => rowValue.includes(val))
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+59
-26
@@ -12,8 +12,6 @@ import {
|
||||
determineHeaderVisibility,
|
||||
} from '../utils'
|
||||
|
||||
import { useTableState } from './useTableState'
|
||||
|
||||
const propTypes = {
|
||||
// General
|
||||
data: PropTypes.array.isRequired,
|
||||
@@ -27,8 +25,11 @@ const propTypes = {
|
||||
const renderErr =
|
||||
'You must specify a valid render component. This could be "column.Cell", "column.Header", "column.Filter", "column.Aggregated" or any other custom renderer component.'
|
||||
|
||||
const defaultColumnInstance = {}
|
||||
export const defaultState = {}
|
||||
|
||||
const defaultInitialState = {}
|
||||
const defaultColumnInstance = {}
|
||||
const defaultReducer = (old, newState) => newState
|
||||
const defaultGetSubRows = (row, index) => row.subRows || []
|
||||
const defaultGetRowID = (row, index) => index
|
||||
|
||||
@@ -39,21 +40,46 @@ export const useTable = (props, ...plugins) => {
|
||||
// Destructure props
|
||||
let {
|
||||
data,
|
||||
state: userState,
|
||||
columns: userColumns,
|
||||
initialState = defaultInitialState,
|
||||
state: userState,
|
||||
defaultColumn = defaultColumnInstance,
|
||||
getSubRows = defaultGetSubRows,
|
||||
getRowID = defaultGetRowID,
|
||||
reducer = defaultReducer,
|
||||
debug,
|
||||
} = props
|
||||
|
||||
debug = process.env.NODE_ENV === 'production' ? false : debug
|
||||
|
||||
// Always provide a default table state
|
||||
const defaultState = useTableState()
|
||||
|
||||
// But use the users table state if provided
|
||||
const state = userState || defaultState
|
||||
let [originalState, originalSetState] = React.useState({
|
||||
...defaultState,
|
||||
...initialState,
|
||||
})
|
||||
|
||||
const state = React.useMemo(() => {
|
||||
if (userState) {
|
||||
const newState = {
|
||||
...originalState,
|
||||
}
|
||||
Object.keys(userState).forEach(key => {
|
||||
newState[key] = userState[key]
|
||||
})
|
||||
return newState
|
||||
}
|
||||
return originalState
|
||||
}, [originalState, userState])
|
||||
|
||||
const setState = React.useCallback(
|
||||
(updater, type) => {
|
||||
return originalSetState(old => {
|
||||
const newState = typeof updater === 'function' ? updater(old) : updater
|
||||
return reducer(old, newState, type)
|
||||
})
|
||||
},
|
||||
[reducer]
|
||||
)
|
||||
|
||||
// The table instance ref
|
||||
let instanceRef = React.useRef({})
|
||||
@@ -61,11 +87,13 @@ export const useTable = (props, ...plugins) => {
|
||||
Object.assign(instanceRef.current, {
|
||||
...props,
|
||||
data, // The raw data
|
||||
state, // The resolved table state
|
||||
state,
|
||||
setState, // The resolved table state
|
||||
plugins, // All resolved plugins
|
||||
hooks: {
|
||||
columnsBeforeHeaderGroups: [],
|
||||
columnsBeforeHeaderGroupsDeps: [],
|
||||
useBeforeDimensions: [],
|
||||
useMain: [],
|
||||
useRows: [],
|
||||
prepareRow: [],
|
||||
@@ -136,12 +164,11 @@ export const useTable = (props, ...plugins) => {
|
||||
})
|
||||
|
||||
// Access the row model
|
||||
const [rows, rowPaths, flatRows] = React.useMemo(() => {
|
||||
const [rows, flatRows] = React.useMemo(() => {
|
||||
if (process.env.NODE_ENV === 'development' && debug)
|
||||
console.time('getAccessedRows')
|
||||
|
||||
let flatRows = 0
|
||||
const rowPaths = []
|
||||
let flatRows = []
|
||||
|
||||
// Access the row's data
|
||||
const accessRow = (originalRow, i, depth = 0, parentPath = []) => {
|
||||
@@ -153,23 +180,21 @@ export const useTable = (props, ...plugins) => {
|
||||
// Make the new path for the row
|
||||
const path = [...parentPath, rowID]
|
||||
|
||||
flatRows++
|
||||
rowPaths.push(path.join('.'))
|
||||
const row = {
|
||||
original,
|
||||
index: i,
|
||||
path, // used to create a key for each row even if not nested
|
||||
depth,
|
||||
cells: [{}], // This is a dummy cell
|
||||
}
|
||||
|
||||
flatRows.push(row)
|
||||
|
||||
// Process any subRows
|
||||
let subRows = getSubRows(originalRow, i)
|
||||
|
||||
if (subRows) {
|
||||
subRows = subRows.map((d, i) => accessRow(d, i, depth + 1, path))
|
||||
}
|
||||
|
||||
const row = {
|
||||
original,
|
||||
index: i,
|
||||
path, // used to create a key for each row even if not nested
|
||||
subRows,
|
||||
depth,
|
||||
cells: [{}], // This is a dummy cell
|
||||
row.subRows = subRows.map((d, i) => accessRow(d, i, depth + 1, path))
|
||||
}
|
||||
|
||||
// Override common array functions (and the dummy cell's getCellProps function)
|
||||
@@ -199,11 +224,10 @@ export const useTable = (props, ...plugins) => {
|
||||
const accessedData = data.map((d, i) => accessRow(d, i))
|
||||
if (process.env.NODE_ENV === 'development' && debug)
|
||||
console.timeEnd('getAccessedRows')
|
||||
return [accessedData, rowPaths, flatRows]
|
||||
return [accessedData, flatRows]
|
||||
}, [debug, data, getRowID, getSubRows, flatColumns])
|
||||
|
||||
instanceRef.current.rows = rows
|
||||
instanceRef.current.rowPaths = rowPaths
|
||||
instanceRef.current.flatRows = flatRows
|
||||
|
||||
// Determine column visibility
|
||||
@@ -215,6 +239,15 @@ export const useTable = (props, ...plugins) => {
|
||||
[]
|
||||
)
|
||||
|
||||
if (process.env.NODE_ENV === 'development' && debug)
|
||||
console.time('hooks.useBeforeDimensions')
|
||||
instanceRef.current = applyHooks(
|
||||
instanceRef.current.hooks.useBeforeDimensions,
|
||||
instanceRef.current
|
||||
)
|
||||
if (process.env.NODE_ENV === 'development' && debug)
|
||||
console.timeEnd('hooks.useBeforeDimensions')
|
||||
|
||||
calculateDimensions(instanceRef.current)
|
||||
|
||||
if (process.env.NODE_ENV === 'development' && debug)
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import React from 'react'
|
||||
//
|
||||
import { types } from '../actions'
|
||||
|
||||
export const defaultState = {}
|
||||
|
||||
const defaultReducer = (old, newState) => newState
|
||||
|
||||
export const useTableState = (
|
||||
initialState = {},
|
||||
overrides,
|
||||
{ reducer = defaultReducer, useState: userUseState = React.useState } = {}
|
||||
) => {
|
||||
let [state, setState] = userUseState({
|
||||
...defaultState,
|
||||
...initialState,
|
||||
})
|
||||
|
||||
const overriddenState = React.useMemo(() => {
|
||||
const newState = {
|
||||
...state,
|
||||
}
|
||||
if (overrides) {
|
||||
Object.keys(overrides).forEach(key => {
|
||||
newState[key] = overrides[key]
|
||||
})
|
||||
}
|
||||
return newState
|
||||
}, [overrides, state])
|
||||
|
||||
const overriddenStateRef = React.useRef()
|
||||
overriddenStateRef.current = overriddenState
|
||||
|
||||
const reducedSetState = React.useCallback(
|
||||
(updater, type) => {
|
||||
if (!types[type]) {
|
||||
console.info({
|
||||
stateUpdaterFn: updater,
|
||||
actionType: type,
|
||||
currentState: overriddenStateRef.current,
|
||||
})
|
||||
throw new Error('Detected an unknown table action! (Details Above)')
|
||||
}
|
||||
return setState(old => {
|
||||
const newState = updater(old)
|
||||
return reducer(old, newState, type)
|
||||
})
|
||||
},
|
||||
[reducer, setState]
|
||||
)
|
||||
|
||||
return React.useMemo(() => [overriddenState, reducedSetState], [
|
||||
overriddenState,
|
||||
reducedSetState,
|
||||
])
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,7 @@
|
||||
import * as utils from './utils'
|
||||
export { utils }
|
||||
export { defaultColumn } from './utils'
|
||||
export { useTable } from './hooks/useTable'
|
||||
export { useTableState, defaultState } from './hooks/useTableState'
|
||||
export { useTable, defaultState } from './hooks/useTable'
|
||||
export { useExpanded } from './plugin-hooks/useExpanded'
|
||||
export { useFilters } from './plugin-hooks/useFilters'
|
||||
export { useGroupBy } from './plugin-hooks/useGroupBy'
|
||||
@@ -11,6 +10,7 @@ export { usePagination } from './plugin-hooks/usePagination'
|
||||
export { useRowSelect } from './plugin-hooks/useRowSelect'
|
||||
export { useRowState } from './plugin-hooks/useRowState'
|
||||
export { useColumnOrder } from './plugin-hooks/useColumnOrder'
|
||||
export { useResizeColumns } from './plugin-hooks/useResizeColumns'
|
||||
export { useAbsoluteLayout } from './plugin-hooks/useAbsoluteLayout'
|
||||
export { useBlockLayout } from './plugin-hooks/useBlockLayout'
|
||||
export { actions, addActions } from './actions'
|
||||
|
||||
@@ -8,7 +8,7 @@ exports[`renders a table 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="row"
|
||||
style="display: block; width: 1400px;"
|
||||
style="display: flex; width: 1400px;"
|
||||
>
|
||||
<div
|
||||
class="cell header"
|
||||
@@ -27,7 +27,7 @@ exports[`renders a table 1`] = `
|
||||
</div>
|
||||
<div
|
||||
class="row"
|
||||
style="display: block; width: 1400px;"
|
||||
style="display: flex; width: 1400px;"
|
||||
>
|
||||
<div
|
||||
class="cell header"
|
||||
@@ -78,7 +78,7 @@ exports[`renders a table 1`] = `
|
||||
>
|
||||
<div
|
||||
class="row"
|
||||
style="display: block; width: 1400px;"
|
||||
style="display: flex; width: 1400px;"
|
||||
>
|
||||
<div
|
||||
class="cell"
|
||||
@@ -119,7 +119,7 @@ exports[`renders a table 1`] = `
|
||||
</div>
|
||||
<div
|
||||
class="row"
|
||||
style="display: block; width: 1400px;"
|
||||
style="display: flex; width: 1400px;"
|
||||
>
|
||||
<div
|
||||
class="cell"
|
||||
@@ -160,7 +160,7 @@ exports[`renders a table 1`] = `
|
||||
</div>
|
||||
<div
|
||||
class="row"
|
||||
style="display: block; width: 1400px;"
|
||||
style="display: flex; width: 1400px;"
|
||||
>
|
||||
<div
|
||||
class="cell"
|
||||
|
||||
@@ -485,8 +485,8 @@ Snapshot Diff:
|
||||
<pre>
|
||||
<code>
|
||||
{
|
||||
- "selectedRows": []
|
||||
+ "selectedRows": [
|
||||
- "selectedRowPaths": []
|
||||
+ "selectedRowPaths": [
|
||||
+ "0",
|
||||
+ "1",
|
||||
+ "2",
|
||||
@@ -1015,7 +1015,7 @@ Snapshot Diff:
|
||||
<pre>
|
||||
<code>
|
||||
{
|
||||
- "selectedRows": [
|
||||
- "selectedRowPaths": [
|
||||
- "0",
|
||||
- "1",
|
||||
- "2",
|
||||
@@ -1053,7 +1053,7 @@ Snapshot Diff:
|
||||
- "22.1",
|
||||
- "23"
|
||||
- ]
|
||||
+ "selectedRows": []
|
||||
+ "selectedRowPaths": []
|
||||
}
|
||||
</code>
|
||||
</pre>
|
||||
@@ -1129,8 +1129,8 @@ Snapshot Diff:
|
||||
<pre>
|
||||
<code>
|
||||
{
|
||||
- "selectedRows": []
|
||||
+ "selectedRows": [
|
||||
- "selectedRowPaths": []
|
||||
+ "selectedRowPaths": [
|
||||
+ "0",
|
||||
+ "2",
|
||||
+ "2.0",
|
||||
@@ -1198,7 +1198,7 @@ Snapshot Diff:
|
||||
<pre>
|
||||
<code>
|
||||
{
|
||||
"selectedRows": [
|
||||
"selectedRowPaths": [
|
||||
- "0",
|
||||
- "2",
|
||||
- "2.0",
|
||||
@@ -1241,7 +1241,7 @@ Snapshot Diff:
|
||||
<pre>
|
||||
<code>
|
||||
{
|
||||
"selectedRows": [
|
||||
"selectedRowPaths": [
|
||||
- "0"
|
||||
+ "0",
|
||||
+ "2.0"
|
||||
@@ -1282,7 +1282,7 @@ Snapshot Diff:
|
||||
<pre>
|
||||
<code>
|
||||
{
|
||||
"selectedRows": [
|
||||
"selectedRowPaths": [
|
||||
"0",
|
||||
- "2.0"
|
||||
+ "2.0",
|
||||
@@ -1324,7 +1324,7 @@ Snapshot Diff:
|
||||
<pre>
|
||||
<code>
|
||||
{
|
||||
"selectedRows": [
|
||||
"selectedRowPaths": [
|
||||
"0",
|
||||
- "2.0",
|
||||
- "2.1"
|
||||
|
||||
@@ -52,7 +52,7 @@ function Table({ columns: userColumns, data, SubComponent }) {
|
||||
rows,
|
||||
prepareRow,
|
||||
flatColumns,
|
||||
state: [{ expanded }],
|
||||
state: { expanded },
|
||||
} = useTable(
|
||||
{
|
||||
columns: userColumns,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import React from 'react'
|
||||
import { render, fireEvent } from '@testing-library/react'
|
||||
import { useTable } from '../../hooks/useTable'
|
||||
import { useTableState } from '../../hooks/useTableState'
|
||||
import { usePagination } from '../usePagination'
|
||||
|
||||
const data = [...new Array(100)].map((d, i) => ({
|
||||
@@ -14,8 +13,6 @@ const data = [...new Array(100)].map((d, i) => ({
|
||||
}))
|
||||
|
||||
function Table({ columns, data }) {
|
||||
const tableState = useTableState({ pageIndex: 2 })
|
||||
|
||||
const {
|
||||
getTableProps,
|
||||
getTableBodyProps,
|
||||
@@ -30,12 +27,12 @@ function Table({ columns, data }) {
|
||||
nextPage,
|
||||
previousPage,
|
||||
setPageSize,
|
||||
state: [{ pageIndex, pageSize }],
|
||||
state: { pageIndex, pageSize },
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
data,
|
||||
state: tableState,
|
||||
initialState: { pageIndex: 2 },
|
||||
},
|
||||
usePagination
|
||||
)
|
||||
|
||||
@@ -75,7 +75,7 @@ function Table({ columns, data }) {
|
||||
headerGroups,
|
||||
rows,
|
||||
prepareRow,
|
||||
state: [{ selectedRows }],
|
||||
state: { selectedRowPaths },
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
@@ -113,9 +113,9 @@ function Table({ columns, data }) {
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Selected Rows: {selectedRows.length}</p>
|
||||
<p>Selected Rows: {selectedRowPaths.length}</p>
|
||||
<pre>
|
||||
<code>{JSON.stringify({ selectedRows }, null, 2)}</code>
|
||||
<code>{JSON.stringify({ selectedRowPaths }, null, 2)}</code>
|
||||
</pre>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -18,7 +18,7 @@ const useMain = instance => {
|
||||
|
||||
const rowStyles = {
|
||||
style: {
|
||||
display: 'block',
|
||||
display: 'flex',
|
||||
width: `${totalColumnsWidth}px`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
|
||||
defaultState.columnOrder = []
|
||||
|
||||
@@ -14,7 +14,7 @@ const propTypes = {
|
||||
|
||||
export const useColumnOrder = hooks => {
|
||||
hooks.columnsBeforeHeaderGroupsDeps.push((deps, instance) => {
|
||||
return [...deps, instance.state[0].columnOrder]
|
||||
return [...deps, instance.state.columnOrder]
|
||||
})
|
||||
hooks.columnsBeforeHeaderGroups.push(columnsBeforeHeaderGroups)
|
||||
hooks.useMain.push(useMain)
|
||||
@@ -24,7 +24,7 @@ useColumnOrder.pluginName = 'useColumnOrder'
|
||||
|
||||
function columnsBeforeHeaderGroups(columns, instance) {
|
||||
const {
|
||||
state: [{ columnOrder }],
|
||||
state: { columnOrder },
|
||||
} = instance
|
||||
|
||||
// If there is no order, return the normal columns
|
||||
@@ -56,9 +56,7 @@ function columnsBeforeHeaderGroups(columns, instance) {
|
||||
function useMain(instance) {
|
||||
PropTypes.checkPropTypes(propTypes, instance, 'property', 'useColumnOrder')
|
||||
|
||||
const {
|
||||
state: [, setState],
|
||||
} = instance
|
||||
const { setState } = instance
|
||||
|
||||
const setColumnOrder = React.useCallback(
|
||||
updater => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import { mergeProps, applyPropHooks, expandRows } from '../utils'
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
|
||||
defaultState.expanded = []
|
||||
|
||||
@@ -29,8 +29,10 @@ function useMain(instance) {
|
||||
rows,
|
||||
manualExpandedKey = 'expanded',
|
||||
paginateExpandedRows = true,
|
||||
expandSubRows = true,
|
||||
hooks,
|
||||
state: [{ expanded }, setState],
|
||||
state: { expanded },
|
||||
setState,
|
||||
} = instance
|
||||
|
||||
const toggleExpandedByPath = (path, set) => {
|
||||
@@ -82,11 +84,18 @@ function useMain(instance) {
|
||||
console.info('getExpandedRows')
|
||||
|
||||
if (paginateExpandedRows) {
|
||||
return expandRows(rows, { manualExpandedKey, expanded })
|
||||
return expandRows(rows, { manualExpandedKey, expanded, expandSubRows })
|
||||
}
|
||||
|
||||
return rows
|
||||
}, [debug, paginateExpandedRows, rows, manualExpandedKey, expanded])
|
||||
}, [
|
||||
debug,
|
||||
paginateExpandedRows,
|
||||
rows,
|
||||
manualExpandedKey,
|
||||
expanded,
|
||||
expandSubRows,
|
||||
])
|
||||
|
||||
const expandedDepth = findExpandedDepth(expanded)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
|
||||
import { getFirstDefined, isFunction } from '../utils'
|
||||
import * as filterTypes from '../filterTypes'
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
|
||||
defaultState.filters = {}
|
||||
|
||||
@@ -33,14 +33,17 @@ function useMain(instance) {
|
||||
const {
|
||||
debug,
|
||||
rows,
|
||||
flatRows,
|
||||
flatColumns,
|
||||
filterTypes: userFilterTypes,
|
||||
manualFilters,
|
||||
disableFilters,
|
||||
state: [{ filters }, setState],
|
||||
state: { filters },
|
||||
setState,
|
||||
} = instance
|
||||
|
||||
const preFilteredRows = rows
|
||||
const preFilteredFlatRows = flatRows
|
||||
|
||||
const setFilter = (id, updater) => {
|
||||
const column = flatColumns.find(d => d.id === id)
|
||||
@@ -129,11 +132,16 @@ function useMain(instance) {
|
||||
// cache for each row group (top-level rows, and each row's recursive subrows)
|
||||
// This would make multi-filtering a lot faster though. Too far?
|
||||
|
||||
const filteredRows = React.useMemo(() => {
|
||||
const { filteredRows, filteredFlatRows } = React.useMemo(() => {
|
||||
if (manualFilters || !Object.keys(filters).length) {
|
||||
return rows
|
||||
return {
|
||||
filteredRows: rows,
|
||||
filteredFlatRows: flatRows,
|
||||
}
|
||||
}
|
||||
|
||||
const filteredFlatRows = []
|
||||
|
||||
if (process.env.NODE_ENV === 'development' && debug)
|
||||
console.info('getFilteredRows')
|
||||
|
||||
@@ -169,7 +177,14 @@ function useMain(instance) {
|
||||
|
||||
// Pass the rows, id, filterValue and column to the filterMethod
|
||||
// to get the filtered rows back
|
||||
return filterMethod(filteredSoFar, columnID, filterValue, column)
|
||||
column.filteredRows = filterMethod(
|
||||
filteredSoFar,
|
||||
columnID,
|
||||
filterValue,
|
||||
column
|
||||
)
|
||||
|
||||
return column.filteredRows
|
||||
},
|
||||
rows
|
||||
)
|
||||
@@ -179,6 +194,7 @@ function useMain(instance) {
|
||||
// but that would severely hinder the API for the user, since they
|
||||
// would be required to do that recursion in some scenarios
|
||||
filteredRows = filteredRows.map(row => {
|
||||
filteredFlatRows.push(row)
|
||||
if (!row.subRows) {
|
||||
return row
|
||||
}
|
||||
@@ -194,8 +210,19 @@ function useMain(instance) {
|
||||
return filteredRows
|
||||
}
|
||||
|
||||
return filterRows(rows)
|
||||
}, [manualFilters, filters, debug, rows, flatColumns, userFilterTypes])
|
||||
return {
|
||||
filteredRows: filterRows(rows),
|
||||
filteredFlatRows,
|
||||
}
|
||||
}, [
|
||||
manualFilters,
|
||||
filters,
|
||||
debug,
|
||||
rows,
|
||||
flatRows,
|
||||
flatColumns,
|
||||
userFilterTypes,
|
||||
])
|
||||
|
||||
React.useMemo(() => {
|
||||
// Now that each filtered column has it's partially filtered rows,
|
||||
@@ -208,6 +235,7 @@ function useMain(instance) {
|
||||
// using every column's preFilteredRows value
|
||||
nonFilteredColumns.forEach(column => {
|
||||
column.preFilteredRows = filteredRows
|
||||
column.filteredRows = filteredRows
|
||||
})
|
||||
}, [filteredRows, filters, flatColumns])
|
||||
|
||||
@@ -216,7 +244,9 @@ function useMain(instance) {
|
||||
setFilter,
|
||||
setAllFilters,
|
||||
preFilteredRows,
|
||||
preFilteredFlatRows,
|
||||
rows: filteredRows,
|
||||
flatRows: filteredFlatRows,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import * as aggregations from '../aggregations'
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
import {
|
||||
mergeProps,
|
||||
applyPropHooks,
|
||||
@@ -40,7 +40,7 @@ const propTypes = {
|
||||
export const useGroupBy = hooks => {
|
||||
hooks.columnsBeforeHeaderGroups.push(columnsBeforeHeaderGroups)
|
||||
hooks.columnsBeforeHeaderGroupsDeps.push((deps, instance) => {
|
||||
deps.push(instance.state[0].groupBy)
|
||||
deps.push(instance.state.groupBy)
|
||||
return deps
|
||||
})
|
||||
hooks.useMain.push(useMain)
|
||||
@@ -48,7 +48,7 @@ export const useGroupBy = hooks => {
|
||||
|
||||
useGroupBy.pluginName = 'useGroupBy'
|
||||
|
||||
function columnsBeforeHeaderGroups(flatColumns, { state: [{ groupBy }] }) {
|
||||
function columnsBeforeHeaderGroups(flatColumns, { state: { groupBy } }) {
|
||||
// Sort grouped columns to the start of the column list
|
||||
// before the headers are built
|
||||
|
||||
@@ -80,7 +80,8 @@ function useMain(instance) {
|
||||
aggregations: userAggregations = {},
|
||||
hooks,
|
||||
plugins,
|
||||
state: [{ groupBy }, setState],
|
||||
state: { groupBy },
|
||||
setState,
|
||||
} = instance
|
||||
|
||||
ensurePluginOrder(plugins, [], 'useGroupBy', ['useSortBy', 'useExpanded'])
|
||||
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
||||
|
||||
//
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
import { ensurePluginOrder, safeUseLayoutEffect, expandRows } from '../utils'
|
||||
|
||||
defaultState.pageSize = 10
|
||||
@@ -36,10 +36,9 @@ function useMain(instance) {
|
||||
plugins,
|
||||
pageCount: userPageCount,
|
||||
paginateExpandedRows = true,
|
||||
state: [
|
||||
{ pageSize, pageIndex, filters, groupBy, sortBy, expanded },
|
||||
setState,
|
||||
],
|
||||
expandSubRows = true,
|
||||
state: { pageSize, pageIndex, filters, groupBy, sortBy, expanded },
|
||||
setState,
|
||||
} = instance
|
||||
|
||||
ensurePluginOrder(
|
||||
@@ -101,9 +100,10 @@ function useMain(instance) {
|
||||
return page
|
||||
}
|
||||
|
||||
return expandRows(page, { manualExpandedKey, expanded })
|
||||
return expandRows(page, { manualExpandedKey, expanded, expandSubRows })
|
||||
}, [
|
||||
debug,
|
||||
expandSubRows,
|
||||
expanded,
|
||||
manualExpandedKey,
|
||||
manualPagination,
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
//
|
||||
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
import { defaultColumn, getFirstDefined } from '../utils'
|
||||
import { mergeProps, applyPropHooks } from '../utils'
|
||||
|
||||
defaultState.columnResizing = {
|
||||
columnWidths: {},
|
||||
}
|
||||
|
||||
defaultColumn.canResize = true
|
||||
|
||||
const propTypes = {}
|
||||
|
||||
export const useResizeColumns = hooks => {
|
||||
hooks.useBeforeDimensions.push(useBeforeDimensions)
|
||||
}
|
||||
|
||||
useResizeColumns.pluginName = 'useResizeColumns'
|
||||
|
||||
const useBeforeDimensions = instance => {
|
||||
PropTypes.checkPropTypes(propTypes, instance, 'property', 'useResizeColumns')
|
||||
|
||||
instance.hooks.getResizerProps = []
|
||||
|
||||
const {
|
||||
flatHeaders,
|
||||
disableResizing,
|
||||
hooks: { getHeaderProps },
|
||||
state: { columnResizing },
|
||||
setState,
|
||||
} = instance
|
||||
|
||||
getHeaderProps.push(() => {
|
||||
return {
|
||||
style: {
|
||||
position: 'relative',
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const onMouseDown = (e, header) => {
|
||||
const headersToResize = getLeafHeaders(header)
|
||||
const startWidths = headersToResize.map(header => header.totalWidth)
|
||||
const startX = e.clientX
|
||||
|
||||
const onMouseMove = e => {
|
||||
const currentX = e.clientX
|
||||
const deltaX = currentX - startX
|
||||
|
||||
const percentageDeltaX = deltaX / headersToResize.length
|
||||
|
||||
const newColumnWidths = {}
|
||||
headersToResize.forEach((header, index) => {
|
||||
newColumnWidths[header.id] = Math.max(
|
||||
startWidths[index] + percentageDeltaX,
|
||||
0
|
||||
)
|
||||
})
|
||||
|
||||
setState(old => ({
|
||||
...old,
|
||||
columnResizing: {
|
||||
...old.columnResizing,
|
||||
columnWidths: {
|
||||
...old.columnResizing.columnWidths,
|
||||
...newColumnWidths,
|
||||
},
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
const onMouseUp = e => {
|
||||
document.removeEventListener('mousemove', onMouseMove)
|
||||
document.removeEventListener('mouseup', onMouseUp)
|
||||
|
||||
setState(old => ({
|
||||
...old,
|
||||
columnResizing: {
|
||||
...old.columnResizing,
|
||||
startX: null,
|
||||
isResizingColumn: null,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
document.addEventListener('mousemove', onMouseMove)
|
||||
document.addEventListener('mouseup', onMouseUp)
|
||||
|
||||
setState(old => ({
|
||||
...old,
|
||||
columnResizing: {
|
||||
...old.columnResizing,
|
||||
startX,
|
||||
isResizingColumn: header.id,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
flatHeaders.forEach(header => {
|
||||
const canResize = getFirstDefined(
|
||||
header.disableResizing === true ? false : undefined,
|
||||
disableResizing === true ? false : undefined,
|
||||
true
|
||||
)
|
||||
|
||||
header.canResize = canResize
|
||||
header.width = columnResizing.columnWidths[header.id] || header.width
|
||||
header.isResizing = columnResizing.isResizingColumn === header.id
|
||||
|
||||
if (canResize) {
|
||||
header.getResizerProps = userProps => {
|
||||
return mergeProps(
|
||||
{
|
||||
onMouseDown: e => e.persist() || onMouseDown(e, header),
|
||||
style: {
|
||||
cursor: 'ew-resize',
|
||||
},
|
||||
draggable: false,
|
||||
},
|
||||
applyPropHooks(instance.hooks.getResizerProps, header, instance),
|
||||
userProps
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
function getLeafHeaders(header) {
|
||||
const leafHeaders = []
|
||||
const recurseHeader = header => {
|
||||
if (header.columns && header.columns.length) {
|
||||
header.columns.map(recurseHeader)
|
||||
}
|
||||
leafHeaders.push(header)
|
||||
}
|
||||
recurseHeader(header)
|
||||
return leafHeaders
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { mergeProps, applyPropHooks, ensurePluginOrder } from '../utils'
|
||||
import {
|
||||
mergeProps,
|
||||
applyPropHooks,
|
||||
ensurePluginOrder,
|
||||
safeUseLayoutEffect,
|
||||
} from '../utils'
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
|
||||
defaultState.selectedRows = []
|
||||
defaultState.selectedRowPaths = []
|
||||
|
||||
addActions('toggleRowSelected', 'toggleRowSelectedAll')
|
||||
|
||||
@@ -15,20 +21,53 @@ const propTypes = {
|
||||
export const useRowSelect = hooks => {
|
||||
hooks.getToggleRowSelectedProps = []
|
||||
hooks.getToggleAllRowsSelectedProps = []
|
||||
hooks.useRows.push(useRows)
|
||||
hooks.useMain.push(useMain)
|
||||
}
|
||||
|
||||
useRowSelect.pluginName = 'useRowSelect'
|
||||
|
||||
function useRows(rows, instance) {
|
||||
PropTypes.checkPropTypes(propTypes, instance, 'property', 'useRowSelect')
|
||||
|
||||
const {
|
||||
state: { selectedRowPaths },
|
||||
} = instance
|
||||
|
||||
instance.selectedFlatRows = React.useMemo(() => {
|
||||
const selectedFlatRows = []
|
||||
rows.forEach(row => {
|
||||
if (row.isAggregated) {
|
||||
const subRowPaths = row.subRows.map(row => row.path)
|
||||
row.isSelected = subRowPaths.every(path =>
|
||||
selectedRowPaths.includes(path.join('.'))
|
||||
)
|
||||
} else {
|
||||
row.isSelected = selectedRowPaths.includes(row.path.join('.'))
|
||||
}
|
||||
if (row.isSelected) {
|
||||
selectedFlatRows.push(row)
|
||||
}
|
||||
})
|
||||
|
||||
return selectedFlatRows
|
||||
}, [rows, selectedRowPaths])
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
function useMain(instance) {
|
||||
PropTypes.checkPropTypes(propTypes, instance, 'property', 'useRowSelect')
|
||||
|
||||
const {
|
||||
hooks,
|
||||
manualRowSelectedKey = 'isSelected',
|
||||
disableSelectedRowsResetOnDataChange,
|
||||
plugins,
|
||||
rowPaths,
|
||||
state: [{ selectedRows }, setState],
|
||||
flatRows,
|
||||
data,
|
||||
state: { selectedRowPaths },
|
||||
setState,
|
||||
} = instance
|
||||
|
||||
ensurePluginOrder(
|
||||
@@ -38,34 +77,66 @@ function useMain(instance) {
|
||||
[]
|
||||
)
|
||||
|
||||
const isAllRowsSelected = rowPaths.length > 0 && rowPaths.length === selectedRows.length
|
||||
const flatRowPaths = flatRows.map(d => d.path.join('.'))
|
||||
|
||||
let isAllRowsSelected = !!flatRowPaths.length && !!selectedRowPaths.length
|
||||
|
||||
if (isAllRowsSelected) {
|
||||
if (flatRowPaths.some(d => !selectedRowPaths.includes(d))) {
|
||||
isAllRowsSelected = false
|
||||
}
|
||||
}
|
||||
|
||||
const isRowSelectedMountedRef = React.useRef()
|
||||
|
||||
// Bypass any effects from firing when this changes
|
||||
const disableSelectedRowsResetOnDataChangeRef = React.useRef()
|
||||
disableSelectedRowsResetOnDataChangeRef.current = disableSelectedRowsResetOnDataChange
|
||||
|
||||
safeUseLayoutEffect(() => {
|
||||
if (
|
||||
isRowSelectedMountedRef.current &&
|
||||
!disableSelectedRowsResetOnDataChangeRef.current
|
||||
) {
|
||||
setState(
|
||||
old => ({
|
||||
...old,
|
||||
selectedRowPaths: [],
|
||||
}),
|
||||
actions.pageChange
|
||||
)
|
||||
}
|
||||
isRowSelectedMountedRef.current = true
|
||||
}, [setState, data])
|
||||
|
||||
const toggleRowSelectedAll = set => {
|
||||
setState(old => {
|
||||
const selectAll = typeof set !== 'undefined' ? set : !isAllRowsSelected
|
||||
return {
|
||||
...old,
|
||||
selectedRows: selectAll ? [...rowPaths] : [],
|
||||
selectedRowPaths: selectAll ? flatRowPaths : [],
|
||||
}
|
||||
}, actions.toggleRowSelectedAll)
|
||||
}
|
||||
|
||||
const updateParentRow = (selectedRows, path) => {
|
||||
const updateParentRow = (selectedRowPaths, path) => {
|
||||
const parentPath = path.slice(0, path.length - 1)
|
||||
const parentKey = parentPath.join('.')
|
||||
const selected =
|
||||
rowPaths.filter(
|
||||
path =>
|
||||
flatRowPaths.filter(rowPath => {
|
||||
const path = rowPath
|
||||
return (
|
||||
path !== parentKey &&
|
||||
path.startsWith(parentKey) &&
|
||||
!selectedRows.has(path)
|
||||
).length === 0
|
||||
!selectedRowPaths.has(path)
|
||||
)
|
||||
}).length === 0
|
||||
if (selected) {
|
||||
selectedRows.add(parentKey)
|
||||
selectedRowPaths.add(parentKey)
|
||||
} else {
|
||||
selectedRows.delete(parentKey)
|
||||
selectedRowPaths.delete(parentKey)
|
||||
}
|
||||
if (parentPath.length > 1) updateParentRow(selectedRows, parentPath)
|
||||
if (parentPath.length > 1) updateParentRow(selectedRowPaths, parentPath)
|
||||
}
|
||||
|
||||
const toggleRowSelected = (path, set) => {
|
||||
@@ -76,18 +147,18 @@ function useMain(instance) {
|
||||
// Join the paths of deep rows
|
||||
// to make a key, then manage all of the keys
|
||||
// in a flat object
|
||||
const exists = old.selectedRows.includes(key)
|
||||
const exists = old.selectedRowPaths.includes(key)
|
||||
const shouldExist = typeof set !== 'undefined' ? set : !exists
|
||||
let newSelectedRows = new Set(old.selectedRows)
|
||||
let newSelectedRows = new Set(old.selectedRowPaths)
|
||||
|
||||
if (!exists && shouldExist) {
|
||||
rowPaths.forEach(rowPath => {
|
||||
flatRowPaths.forEach(rowPath => {
|
||||
if (rowPath === key || rowPath.startsWith(childRowPrefixKey)) {
|
||||
newSelectedRows.add(rowPath)
|
||||
}
|
||||
})
|
||||
} else if (exists && !shouldExist) {
|
||||
rowPaths.forEach(rowPath => {
|
||||
flatRowPaths.forEach(rowPath => {
|
||||
if (rowPath === key || rowPath.startsWith(childRowPrefixKey)) {
|
||||
newSelectedRows.delete(rowPath)
|
||||
}
|
||||
@@ -102,7 +173,7 @@ function useMain(instance) {
|
||||
|
||||
return {
|
||||
...old,
|
||||
selectedRows: [...newSelectedRows.values()],
|
||||
selectedRowPaths: [...newSelectedRows.values()],
|
||||
}
|
||||
}, actions.toggleRowSelected)
|
||||
}
|
||||
@@ -128,9 +199,6 @@ function useMain(instance) {
|
||||
// Aggregate rows have entirely different select logic
|
||||
if (row.isAggregated) {
|
||||
const subRowPaths = row.subRows.map(row => row.path)
|
||||
row.isSelected = subRowPaths.every(path =>
|
||||
selectedRows.includes(path.join('.'))
|
||||
)
|
||||
row.toggleRowSelected = set => {
|
||||
set = typeof set !== 'undefined' ? set : !row.isSelected
|
||||
subRowPaths.forEach(path => {
|
||||
@@ -166,7 +234,6 @@ function useMain(instance) {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
row.isSelected = selectedRows.includes(row.path.join('.'))
|
||||
row.toggleRowSelected = set => toggleRowSelected(row.path, set)
|
||||
row.getToggleRowSelectedProps = props => {
|
||||
let checked = false
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
|
||||
defaultState.rowState = {}
|
||||
|
||||
@@ -25,7 +25,8 @@ function useMain(instance) {
|
||||
hooks,
|
||||
rows,
|
||||
initialRowStateAccessor,
|
||||
state: [{ rowState }, setState],
|
||||
state: { rowState },
|
||||
setState,
|
||||
} = instance
|
||||
|
||||
const setRowState = React.useCallback(
|
||||
|
||||
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import { ensurePluginOrder, defaultColumn } from '../utils'
|
||||
import { addActions, actions } from '../actions'
|
||||
import { defaultState } from '../hooks/useTableState'
|
||||
import { defaultState } from '../hooks/useTable'
|
||||
import * as sortTypes from '../sortTypes'
|
||||
import {
|
||||
mergeProps,
|
||||
@@ -63,7 +63,8 @@ function useMain(instance) {
|
||||
maxMultiSortColCount = Number.MAX_SAFE_INTEGER,
|
||||
flatHeaders,
|
||||
hooks,
|
||||
state: [{ sortBy }, setState],
|
||||
state: { sortBy },
|
||||
setState,
|
||||
plugins,
|
||||
} = instance
|
||||
|
||||
|
||||
+9
-3
@@ -288,7 +288,10 @@ export function flexRender(Comp, props) {
|
||||
function isClassComponent(component) {
|
||||
return (
|
||||
typeof component === 'function' &&
|
||||
!!Object.getPrototypeOf(component).isReactComponent
|
||||
!!(() => {
|
||||
let proto = Object.getPrototypeOf(component)
|
||||
return proto.prototype && proto.prototype.isReactComponent
|
||||
})()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -402,7 +405,10 @@ This usually means you need to need to name your plugin hook by setting the 'plu
|
||||
})
|
||||
}
|
||||
|
||||
export function expandRows(rows, { manualExpandedKey, expanded }) {
|
||||
export function expandRows(
|
||||
rows,
|
||||
{ manualExpandedKey, expanded, expandSubRows = true }
|
||||
) {
|
||||
const expandedRows = []
|
||||
|
||||
const handleRow = row => {
|
||||
@@ -416,7 +422,7 @@ export function expandRows(rows, { manualExpandedKey, expanded }) {
|
||||
|
||||
expandedRows.push(row)
|
||||
|
||||
if (row.subRows && row.subRows.length && row.isExpanded) {
|
||||
if (expandSubRows && row.subRows && row.subRows.length && row.isExpanded) {
|
||||
row.subRows.forEach(handleRow)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2374,6 +2374,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
|
||||
shebang-command "^1.2.0"
|
||||
which "^1.2.9"
|
||||
|
||||
cross-spawn@^7.0.0:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
|
||||
integrity sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==
|
||||
dependencies:
|
||||
path-key "^3.1.0"
|
||||
shebang-command "^2.0.0"
|
||||
which "^2.0.1"
|
||||
|
||||
css-select-base-adapter@^0.1.1:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz#3b2ff4972cc362ab88561507a95408a1432135d7"
|
||||
@@ -4016,12 +4025,13 @@ is-callable@^1.1.4:
|
||||
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"
|
||||
integrity sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==
|
||||
|
||||
is-ci-cli@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/is-ci-cli/-/is-ci-cli-1.1.1.tgz#2dc924d192fe8d76074dcb96a2122a7d00d0ee83"
|
||||
integrity sha512-c8xV1IkPvcdB9fAKo3QZ4SmdzsgPHOZ8Xz88T9CCSMrksKMn41R4jUxUP1UbFNPYiYoz8XvHt3RZ3ODKIPyLYQ==
|
||||
is-ci-cli@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-ci-cli/-/is-ci-cli-2.0.0.tgz#606dd5051c636ac80e1deb4c1c30aa5294220159"
|
||||
integrity sha512-pgdXwbBaRfyG3XJ/+AYbgCb5WE10TZwj4pvoSYI1YrmGDslcS0lhvqvAKmZrSq2248/jGoZ2g9yC63APlBy1uQ==
|
||||
dependencies:
|
||||
is-ci "^1.0.10"
|
||||
cross-spawn "^7.0.0"
|
||||
is-ci "^2.0.0"
|
||||
|
||||
is-ci@^1.0.10:
|
||||
version "1.2.1"
|
||||
@@ -6171,7 +6181,7 @@ path-key@^2.0.0, path-key@^2.0.1:
|
||||
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
|
||||
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
|
||||
|
||||
path-key@^3.0.0:
|
||||
path-key@^3.0.0, path-key@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.0.tgz#99a10d870a803bdd5ee6f0470e58dfcd2f9a54d3"
|
||||
integrity sha512-8cChqz0RP6SHJkMt48FW0A7+qUOn+OsnOsVtzI59tZ8m+5bCSk7hzwET0pulwOM2YMn9J1efb07KB9l9f30SGg==
|
||||
@@ -6878,15 +6888,16 @@ rollup-plugin-peer-deps-external@^2.2.0:
|
||||
resolved "https://registry.yarnpkg.com/rollup-plugin-peer-deps-external/-/rollup-plugin-peer-deps-external-2.2.0.tgz#99ef9231aa01736f3e9605b7c3084a0d627f665b"
|
||||
integrity sha512-BmJMHUWQcvjS2dQMwJ7dzvdbwpRChnq4AYk2sTU/4aySt9Kumk8y8W3HhTHss31wxzKb0AC/wsiX1AqDcOBIEA==
|
||||
|
||||
rollup-plugin-uglify@^6.0.2:
|
||||
version "6.0.2"
|
||||
resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.2.tgz#681042cfdf7ea4e514971946344e1a95bc2772fe"
|
||||
integrity sha512-qwz2Tryspn5QGtPUowq5oumKSxANKdrnfz7C0jm4lKxvRDsNe/hSGsB9FntUul7UeC4TsZEWKErVgE1qWSO0gw==
|
||||
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"
|
||||
integrity sha512-sWKBCOS+vUkRtHtEiJPAf+WnBqk/C402fBD9AVHxSIXMqjsY7MnYWKYEUqGixtr0c8+1DjzUEPlNgOYQPVrS1g==
|
||||
dependencies:
|
||||
"@babel/code-frame" "^7.0.0"
|
||||
jest-worker "^24.0.0"
|
||||
serialize-javascript "^1.6.1"
|
||||
uglify-js "^3.4.9"
|
||||
jest-worker "^24.6.0"
|
||||
rollup-pluginutils "^2.8.1"
|
||||
serialize-javascript "^1.7.0"
|
||||
terser "^4.1.0"
|
||||
|
||||
rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.8.1:
|
||||
version "2.8.1"
|
||||
@@ -7014,10 +7025,10 @@ semver@^6.0.0, semver@^6.1.1:
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
||||
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
|
||||
|
||||
serialize-javascript@^1.6.1:
|
||||
version "1.7.0"
|
||||
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.7.0.tgz#d6e0dfb2a3832a8c94468e6eb1db97e55a192a65"
|
||||
integrity sha512-ke8UG8ulpFOxO8f8gRYabHQe/ZntKlcig2Mp+8+URDP1D8vJZ0KUt7LYo07q25Z/+JVSgpr/cui9PIp5H6/+nA==
|
||||
serialize-javascript@^1.7.0:
|
||||
version "1.9.1"
|
||||
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.9.1.tgz#cfc200aef77b600c47da9bb8149c943e798c2fdb"
|
||||
integrity sha512-0Vb/54WJ6k5v8sSWN09S0ora+Hnr+cX40r9F170nT+mSkaxltoE/7R3OrIdBSUv1OoiobH1QoWQbCnAO+e8J1A==
|
||||
|
||||
set-blocking@^2.0.0, set-blocking@~2.0.0:
|
||||
version "2.0.0"
|
||||
@@ -7051,11 +7062,23 @@ shebang-command@^1.2.0:
|
||||
dependencies:
|
||||
shebang-regex "^1.0.0"
|
||||
|
||||
shebang-command@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
|
||||
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==
|
||||
dependencies:
|
||||
shebang-regex "^3.0.0"
|
||||
|
||||
shebang-regex@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
|
||||
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
|
||||
|
||||
shebang-regex@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
|
||||
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
|
||||
|
||||
shelljs@0.7.6:
|
||||
version "0.7.6"
|
||||
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.6.tgz#379cccfb56b91c8601e4793356eb5382924de9ad"
|
||||
@@ -7187,6 +7210,14 @@ source-map-support@^0.5.6:
|
||||
buffer-from "^1.0.0"
|
||||
source-map "^0.6.0"
|
||||
|
||||
source-map-support@~0.5.12:
|
||||
version "0.5.13"
|
||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
|
||||
integrity sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==
|
||||
dependencies:
|
||||
buffer-from "^1.0.0"
|
||||
source-map "^0.6.0"
|
||||
|
||||
source-map-url@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
|
||||
@@ -7503,6 +7534,15 @@ tar@^4:
|
||||
safe-buffer "^5.1.2"
|
||||
yallist "^3.0.3"
|
||||
|
||||
terser@^4.1.0:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/terser/-/terser-4.3.4.tgz#ad91bade95619e3434685d69efa621a5af5f877d"
|
||||
integrity sha512-Kcrn3RiW8NtHBP0ssOAzwa2MsIRQ8lJWiBG/K7JgqPlomA3mtb2DEmp4/hrUA+Jujx+WZ02zqd7GYD+QRBB/2Q==
|
||||
dependencies:
|
||||
commander "^2.20.0"
|
||||
source-map "~0.6.1"
|
||||
source-map-support "~0.5.12"
|
||||
|
||||
test-exclude@^4.2.1:
|
||||
version "4.2.3"
|
||||
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.2.3.tgz#a9a5e64474e4398339245a0a769ad7c2f4a97c20"
|
||||
@@ -7678,7 +7718,7 @@ typedarray@^0.0.6:
|
||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
||||
|
||||
uglify-js@^3.1.4, uglify-js@^3.4.9:
|
||||
uglify-js@^3.1.4:
|
||||
version "3.6.0"
|
||||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.6.0.tgz#704681345c53a8b2079fb6cec294b05ead242ff5"
|
||||
integrity sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==
|
||||
@@ -7855,6 +7895,13 @@ which@^1.2.14, which@^1.2.9, which@^1.3.0:
|
||||
dependencies:
|
||||
isexe "^2.0.0"
|
||||
|
||||
which@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/which/-/which-2.0.1.tgz#f1cf94d07a8e571b6ff006aeb91d0300c47ef0a4"
|
||||
integrity sha512-N7GBZOTswtB9lkQBZA4+zAXrjEIWAUOB93AvzUiudRzRxhUdLURQ7D/gAIMY1gatT/LTbmbcv8SiYazy3eYB7w==
|
||||
dependencies:
|
||||
isexe "^2.0.0"
|
||||
|
||||
wide-align@^1.1.0:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"
|
||||
|
||||
Reference in New Issue
Block a user