datatable-tree 0.0.0-stage → 0.1.1

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