datatable-tree 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +240 -2
- package/dist/DataTable.d.ts +583 -0
- package/dist/DataTable.js +620 -0
- package/dist/Draggable.d.ts +35 -0
- package/dist/Draggable.js +91 -0
- package/dist/ListBox.d.ts +132 -0
- package/dist/ListBox.js +243 -0
- package/dist/ListVirtualizer.d.ts +59 -0
- package/dist/ListVirtualizer.js +180 -0
- package/dist/TreeList.d.ts +196 -0
- package/dist/TreeList.js +300 -0
- package/dist/config.d.ts +55 -0
- package/dist/config.js +33 -0
- package/dist/datatable.css +161 -0
- package/dist/hooks.d.ts +27 -0
- package/dist/hooks.js +115 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +15 -0
- package/dist/interfaces.d.ts +269 -0
- package/dist/interfaces.js +3 -0
- package/dist/mobx-adapter.d.ts +12 -0
- package/dist/mobx-adapter.js +21 -0
- package/dist/reactivity.d.ts +112 -0
- package/dist/reactivity.js +155 -0
- package/dist/styles.d.ts +64 -0
- package/dist/styles.js +86 -0
- package/dist/theme.d.ts +160 -0
- package/dist/theme.js +239 -0
- package/dist/util.d.ts +28 -0
- package/dist/util.js +45 -0
- package/package.json +137 -4
- package/src/DataTable.tsx +1332 -0
- package/src/Draggable.tsx +133 -0
- package/src/ListBox.tsx +423 -0
- package/src/ListVirtualizer.ts +234 -0
- package/src/TreeList.tsx +590 -0
- package/src/config.tsx +96 -0
- package/src/css.d.ts +1 -0
- package/src/datatable.css +161 -0
- package/src/hooks.ts +138 -0
- package/src/index.ts +15 -0
- package/src/interfaces.ts +309 -0
- package/src/mobx-adapter.ts +24 -0
- package/src/reactivity.ts +222 -0
- package/src/styles.tsx +102 -0
- package/src/theme.ts +346 -0
- package/src/util.ts +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Piepgrass
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,241 @@
|
|
|
1
|
-
#
|
|
1
|
+
# datatable-tree
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
I built this component for a real commercial app in response to my frustrations with other options
|
|
4
|
+
that were available in 2022. I let AI write the rest of this but haven't unslopped it yet...
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
React `DataTable` / `TreeList` / `ListBox` widget stack: sortable, user-resizable, virtualizable
|
|
9
|
+
tables and tree grids, with
|
|
10
|
+
|
|
11
|
+
- User can **sort & resize columns** (your code can constrain this)
|
|
12
|
+
- Supports **selections** (single-select, multi-select or no select)
|
|
13
|
+
- **Mixing data types**: you can define more than one type of row in the same table via `getRowConfig`
|
|
14
|
+
- **Trees are easy** — provide `getChildren` or `getParents` and mark one column
|
|
15
|
+
`isTreeCol`; parents expand/collapse
|
|
16
|
+
- Supports **Pinning, col-spans and reactivity**
|
|
17
|
+
- **Row virtualization** for large lists, selection/multiselect, sticky headers, column
|
|
18
|
+
resizing, custom renderers at three levels (`getValue` → `renderCell` → `RenderCell`).
|
|
19
|
+
- **No hard UI-framework or state-library dependencies**
|
|
20
|
+
- **CSS-variable theming**
|
|
21
|
+
|
|
22
|
+
The library is a layered stack — `ListBox`/`ListCore` (selection) → `TreeList`/`TreeListCore`
|
|
23
|
+
(nesting) → `DataTable`/`DataTableCore` (columns) — and every layer is exported and usable on
|
|
24
|
+
its own. Start with the big doc comment in [`src/DataTable.tsx`](src/DataTable.tsx), which
|
|
25
|
+
includes a complete multi-row-type "file browser" example.
|
|
26
|
+
|
|
27
|
+
**Docs:** [homepage and live demo](https://qwertie.github.io/datatable-tree/) ·
|
|
28
|
+
[manual](https://qwertie.github.io/datatable-tree/manual.html) ·
|
|
29
|
+
[API reference](https://qwertie.github.io/datatable-tree/api/). Their sources live in
|
|
30
|
+
[`docs/`](docs/) — the hand-written manual is [`docs/manual.md`](docs/manual.md), and TypeDoc
|
|
31
|
+
generates the reference from the doc comments in `src/`. `npm run build:docs` assembles all
|
|
32
|
+
three into `docs-built/`, which is gitignored because
|
|
33
|
+
[a workflow](.github/workflows/pages.yml) rebuilds and publishes it on every push to `main`.
|
|
34
|
+
|
|
35
|
+
## Requirements
|
|
36
|
+
|
|
37
|
+
React 16.14 or newer. The floor is set by the two oldest things this library uses: hooks
|
|
38
|
+
(React 16.8) and the automatic JSX runtime, `react/jsx-runtime` (React 17, backported to
|
|
39
|
+
16.14). Nothing here calls a React 18 API.
|
|
40
|
+
|
|
41
|
+
`dist/` is ES2017 ESM. The target is deliberately below the syntax this source uses, so that
|
|
42
|
+
the published code contains no optional chaining or nullish coalescing: webpack 4 and other
|
|
43
|
+
older parsers choke on those, and because bundlers exclude `node_modules` from Babel by
|
|
44
|
+
default, the resulting failure would reach the browser instead of the build. ES2017 still
|
|
45
|
+
emits arrow functions, `let`/`const` and `class`, so a consumer who must ship ES5 does need
|
|
46
|
+
to run this package through Babel/SWC rather than excluding it:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// webpack: transpile us too, instead of exclude: /node_modules/
|
|
50
|
+
exclude: /node_modules\/(?!datatable-tree)/
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Preact works, because this library imports `react` and never `react-dom`. Alias `react` and
|
|
54
|
+
`react/jsx-runtime` to `preact/compat` and `preact/compat/jsx-runtime` the way you already
|
|
55
|
+
would, and no further shims are needed. The `datatable-tree/mobx` entry point is the exception:
|
|
56
|
+
it pulls in `mobx-react`, whose own requirements apply.
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm install datatable-tree
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import 'datatable-tree/datatable.css'; // once, anywhere in your app
|
|
66
|
+
import { DataTable } from 'datatable-tree';
|
|
67
|
+
|
|
68
|
+
<DataTable
|
|
69
|
+
list={files}
|
|
70
|
+
columns={[
|
|
71
|
+
{ name: 'name', heading: 'Name', width: 300 },
|
|
72
|
+
{ name: 'size', heading: 'Size', width: 100 },
|
|
73
|
+
]}/>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Optional app-level configuration (icons, theme, MobX):
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { applyTheme, setReactivityAdapter, TableConfig, darkTheme } from 'datatable-tree';
|
|
80
|
+
import { mobxReactivityAdapter } from 'datatable-tree/mobx'; // requires mobx & mobx-react
|
|
81
|
+
|
|
82
|
+
setReactivityAdapter(mobxReactivityAdapter); // once, before rendering (skip if not using MobX)
|
|
83
|
+
applyTheme(darkTheme); // alternative to <TableConfig theme>; also themes portals and *Core
|
|
84
|
+
|
|
85
|
+
root.render(
|
|
86
|
+
<TableConfig theme={darkTheme}
|
|
87
|
+
icons={{ expanded: <MyChevronDown/>, collapsed: <MyChevronRight/> }}>
|
|
88
|
+
<App/>
|
|
89
|
+
</TableConfig>);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Every module is also published as its own subpath, so you can import one widget instead of
|
|
93
|
+
everything:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { TreeList } from 'datatable-tree/TreeList';
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
No entry point imports `datatable.css` for you. A CSS import inside library code makes the
|
|
100
|
+
package unloadable by anything without a CSS-aware bundler — which is what breaks plain Node,
|
|
101
|
+
server-side rendering, and a consumer's `vitest` run — so importing it is your job, once, as
|
|
102
|
+
the quick start shows. This also retires an old hazard: when the entry point did import it,
|
|
103
|
+
adding a `sideEffects` field to package.json made Vite on Windows tree-shake that import away
|
|
104
|
+
and silently produce unstyled tables.
|
|
105
|
+
|
|
106
|
+
## Developing
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
npm install # note: .npmrc sets legacy-peer-deps
|
|
110
|
+
npm test # vitest (jsdom)
|
|
111
|
+
npm run typecheck
|
|
112
|
+
npm run build # emits dist/ (tsc + datatable.css)
|
|
113
|
+
npm run dev # dev server on docs/ with live reload (edits to src/ apply too)
|
|
114
|
+
npm run build:docs # docs/ + manual.md + TypeDoc -> docs-built/, then check every link
|
|
115
|
+
npm run serve # build:docs, then serve docs-built/ so you see the current sources
|
|
116
|
+
npm run testpack # run the tests against the *packaged* library (see below)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### The docs site
|
|
120
|
+
|
|
121
|
+
`npm run build:docs` assembles three things into `docs-built/`, in this order:
|
|
122
|
+
|
|
123
|
+
1. **Vite** builds `docs/index.html` (the homepage and the editable live demo) and
|
|
124
|
+
`docs/manual.html`. The manual is a real Vite entry point whose `<main>` is empty in the
|
|
125
|
+
source; a plugin in `vite.config.ts` renders `docs/manual.md` into it at build time. It has to
|
|
126
|
+
be an entry point rather than a file the plugin writes itself, because Vite content-hashes the
|
|
127
|
+
stylesheets, so `site.css` does not exist under that name in the output.
|
|
128
|
+
2. **TypeDoc** generates the API reference into `docs-built/api/` from the doc comments in `src/`.
|
|
129
|
+
It runs after Vite because `build.emptyOutDir` would otherwise delete it. `treatWarningsAsErrors`
|
|
130
|
+
is on, so a doc comment TypeDoc cannot parse — or a public type `index.ts` forgets to export —
|
|
131
|
+
fails the build. Nothing else here checks either of those.
|
|
132
|
+
3. **`scripts/postbuild-docs.mjs`** rewrites the `__SITE__/` sentinel in TypeDoc's toolbar links to
|
|
133
|
+
the right number of `../` for each page's depth (TypeDoc emits `navigationLinks` verbatim, so one
|
|
134
|
+
literal prefix cannot serve both `api/index.html` and `api/functions/DataTable.html`), then
|
|
135
|
+
checks that every relative link in the site resolves to a file that exists.
|
|
136
|
+
|
|
137
|
+
`npm run dev` serves only step 1, so the "API reference" links 404 until you run `npm run serve`.
|
|
138
|
+
|
|
139
|
+
Publishing is automatic — [`.github/workflows/pages.yml`](.github/workflows/pages.yml) typechecks,
|
|
140
|
+
tests, builds and deploys to GitHub Pages on every push to `main`. To redeploy without a commit,
|
|
141
|
+
run the workflow from the Actions tab.
|
|
142
|
+
|
|
143
|
+
It does need the repository configured once, under **Settings → Pages → Build and deployment →
|
|
144
|
+
Source: "GitHub Actions"**. Until that is set, every run fails at the deploy step with "Get Pages
|
|
145
|
+
site failed". The workflow cannot do it for you: `actions/configure-pages` offers an
|
|
146
|
+
`enablement: true` input for exactly this, but `GITHUB_TOKEN` is refused ("Resource not accessible
|
|
147
|
+
by integration") because creating a Pages site needs admin rights the workflow token lacks.
|
|
148
|
+
|
|
149
|
+
### Testing the package, not the working tree
|
|
150
|
+
|
|
151
|
+
`npm test` proves the source works. It cannot prove the *published* package works, because it
|
|
152
|
+
resolves `../DataTable.js` straight to the TypeScript in `src/` and it resolves dependencies out of
|
|
153
|
+
this repo's own `node_modules`, where devDependencies are present. Plenty of mistakes hide in that
|
|
154
|
+
gap: a file missing from `files`, an `exports` entry pointing at a path that does not exist, a real
|
|
155
|
+
dependency parked in devDependencies, or a `.d.ts` that disagrees with the `.js` beside it.
|
|
156
|
+
|
|
157
|
+
`npm run testpack` closes the gap. [testpack](https://www.npmjs.com/package/testpack-cli) packs the
|
|
158
|
+
package, installs the tarball into `../datatable-tree-testpack`, copies the tests there, rewrites
|
|
159
|
+
their relative imports into package imports, and runs them. The tests then reach the library the
|
|
160
|
+
way a consumer does — some through the root entry point, one through `datatable-tree/mobx`, one
|
|
161
|
+
through the deep `datatable-tree/ListVirtualizer.js` subpath — so a broken `exports` map fails the
|
|
162
|
+
run.
|
|
163
|
+
|
|
164
|
+
Two extra checks run first, because the vitest suite alone would miss them:
|
|
165
|
+
|
|
166
|
+
- `scripts/check-package-deps.mjs` reads every bare import in `dist/`, then insists package.json
|
|
167
|
+
declares it and that it resolves. tsc will not do this for us: `skipLibCheck` suppresses
|
|
168
|
+
unresolved imports inside a dependency's `.d.ts`, and `holders` is type-only, so it appears in
|
|
169
|
+
`.d.ts` files and nowhere else.
|
|
170
|
+
- `scripts/check-node-loadable.mjs` imports the package in plain `node` and server-renders a table.
|
|
171
|
+
Everything else in the run goes through vite's resolver, which invents missing file extensions and
|
|
172
|
+
understands CSS imports; `node` does neither. This is what keeps server-side rendering working, and
|
|
173
|
+
what fails if `src/index.ts` ever imports `datatable.css` again.
|
|
174
|
+
|
|
175
|
+
`npm run safePublish` runs `testpack` and then `npm publish`.
|
|
176
|
+
|
|
177
|
+
Run it before publishing and after any change to `exports`, `files`, `dependencies`, or the build.
|
|
178
|
+
Each run reinstalls from scratch and takes about a minute; add `--dirty --setup-command=` to reuse
|
|
179
|
+
the previous install while iterating.
|
|
180
|
+
|
|
181
|
+
## Using this repo inside a bigger repo (git-subrepo)
|
|
182
|
+
|
|
183
|
+
This library is developed both standalone and embedded in a host application's monorepo
|
|
184
|
+
(originally [Barreleye](https://barreleyesoftware.com)).
|
|
185
|
+
The embedding uses [git-subrepo](https://github.com/ingydotnet/git-subrepo), which stores a
|
|
186
|
+
plain copy of this repo in a subdirectory of the host repo — teammates need no special tools
|
|
187
|
+
or workflow; only the person syncing changes needs git-subrepo installed.
|
|
188
|
+
|
|
189
|
+
### One-time setup in a host repo
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
git subrepo clone <URL-of-this-repo> path/to/DataTable
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
This creates `path/to/DataTable/` containing this repo's files plus a `.gitrepo` file that
|
|
196
|
+
records the remote URL, branch, and the upstream commit the copy corresponds to. Commit is
|
|
197
|
+
automatic. (If the copy already exists and you need to re-point it at a new remote, edit
|
|
198
|
+
`.gitrepo` or run `git subrepo clone --force <new-url> path/to/DataTable`.)
|
|
199
|
+
|
|
200
|
+
### Day-to-day in the host repo
|
|
201
|
+
|
|
202
|
+
Edit files under `path/to/DataTable/` and commit to the host repo as normal — subrepo changes
|
|
203
|
+
can even be mixed with host-repo changes in one commit (though separate commits make cleaner
|
|
204
|
+
upstream history).
|
|
205
|
+
|
|
206
|
+
### Pushing host-repo changes upstream (to this repo)
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# from the host repo's root, with a clean index:
|
|
210
|
+
git subrepo push path/to/DataTable
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
git-subrepo extracts the host commits that touched the subdirectory, replays them onto the
|
|
214
|
+
upstream branch recorded in `.gitrepo`, and pushes. Add `-b <branch>` to push to a different
|
|
215
|
+
upstream branch (e.g. for review).
|
|
216
|
+
|
|
217
|
+
### Pulling upstream changes into the host repo
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
git subrepo pull path/to/DataTable
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
This fetches the upstream branch and squash-merges new upstream commits into the
|
|
224
|
+
subdirectory, creating one host commit (add `--method rebase` if you prefer). If the same
|
|
225
|
+
lines changed both upstream and in the host repo, you'll get a normal git conflict to resolve;
|
|
226
|
+
then `git subrepo commit path/to/DataTable`.
|
|
227
|
+
|
|
228
|
+
### Tips & troubleshooting
|
|
229
|
+
|
|
230
|
+
- Run subrepo commands from the host repo root with a **clean index** (commit or stash first).
|
|
231
|
+
- `git subrepo status path/to/DataTable` shows the recorded remote/branch/commit.
|
|
232
|
+
- The `.gitrepo` file is metadata maintained by git-subrepo — don't edit it during normal work,
|
|
233
|
+
and do commit it when subrepo commands change it.
|
|
234
|
+
- If a `push` is rejected because upstream moved, `git subrepo pull` first, then push again.
|
|
235
|
+
- History note: `push` replays *squashed-per-host-commit* changes; fine-grained host history
|
|
236
|
+
stays in the host repo.
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
MIT (see [LICENSE](LICENSE)). `src/interfaces.ts` is copied from the MIT-licensed
|
|
241
|
+
[sorted-btree](https://github.com/qwertie/btree-typescript) package by the same author.
|