@usefragments/ui 1.2.0 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefragments/ui",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "license": "MIT",
5
5
  "description": "Customizable UI components built on Base UI headless primitives",
6
6
  "author": "Conan McNicholl",
@@ -99,6 +99,16 @@
99
99
  "default": "./dist/data-table.cjs"
100
100
  }
101
101
  },
102
+ "./data-table-virtual": {
103
+ "import": {
104
+ "types": "./dist/components/DataTable/DataTable.virtual.d.ts",
105
+ "default": "./dist/data-table-virtual.js"
106
+ },
107
+ "require": {
108
+ "types": "./dist/components/DataTable/DataTable.virtual.d.ts",
109
+ "default": "./dist/data-table-virtual.cjs"
110
+ }
111
+ },
102
112
  "./editor": {
103
113
  "import": {
104
114
  "types": "./dist/components/Editor/index.d.ts",
@@ -110,10 +120,12 @@
110
120
  }
111
121
  },
112
122
  "./styles": {
123
+ "types": "./src/styles/styles.d.ts",
113
124
  "sass": "./src/styles/globals.scss",
114
125
  "default": "./dist/assets/ui.css"
115
126
  },
116
127
  "./globals": {
128
+ "types": "./src/styles/styles.d.ts",
117
129
  "sass": "./src/styles/globals.scss",
118
130
  "default": "./dist/assets/ui.css"
119
131
  },
@@ -155,6 +167,44 @@
155
167
  "remark-gfm": ">=4.0.0",
156
168
  "shiki": ">=1.0.0"
157
169
  },
170
+ "peerDependenciesMeta": {
171
+ "@tanstack/react-table": {
172
+ "optional": true
173
+ },
174
+ "@tanstack/react-virtual": {
175
+ "optional": true
176
+ },
177
+ "@tiptap/extension-link": {
178
+ "optional": true
179
+ },
180
+ "@tiptap/react": {
181
+ "optional": true
182
+ },
183
+ "@tiptap/starter-kit": {
184
+ "optional": true
185
+ },
186
+ "date-fns": {
187
+ "optional": true
188
+ },
189
+ "react-colorful": {
190
+ "optional": true
191
+ },
192
+ "react-day-picker": {
193
+ "optional": true
194
+ },
195
+ "react-markdown": {
196
+ "optional": true
197
+ },
198
+ "recharts": {
199
+ "optional": true
200
+ },
201
+ "remark-gfm": {
202
+ "optional": true
203
+ },
204
+ "shiki": {
205
+ "optional": true
206
+ }
207
+ },
158
208
  "dependencies": {
159
209
  "@base-ui/react": "1.6.0",
160
210
  "@phosphor-icons/react": "^2.1.10"
@@ -190,7 +240,7 @@
190
240
  "vite": "^6.0.0",
191
241
  "vitest": "^2.1.8",
192
242
  "vitest-axe": "^0.1.0",
193
- "@usefragments/core": "1.3.0"
243
+ "@usefragments/core": "1.4.0"
194
244
  },
195
245
  "files": [
196
246
  "src",
@@ -5,13 +5,40 @@ import styles from "./DataTable.module.scss";
5
5
  import { Checkbox } from "../Checkbox";
6
6
  import { ExpandIcon, SortAscIcon, SortDescIcon, SortIcon } from "./DataTable.icons";
7
7
  import { DataTableSkeletonRows, useArrowKeyRowNav } from "./DataTable.support";
8
- import {
9
- flexRender,
10
- getCoreRowModel,
11
- getExpandedRowModel,
12
- getSortedRowModel,
13
- useReactTable,
14
- } from "@tanstack/react-table";
8
+
9
+ // ============================================
10
+ // Dependency (@tanstack/react-table) — lazy-required
11
+ // ============================================
12
+ // `@tanstack/react-table` is an optional peer dependency. It is pulled in via a
13
+ // synchronous `require()` (mirroring Chart/Editor) rather than a static ESM
14
+ // import so a bundler's dep-optimizer (e.g. Vite dev) does not create a static
15
+ // import edge for consumers who only use, say, `{ Button }`. `require` resolves
16
+ // synchronously, so `useReactTable` (a hook) is available before the first hook
17
+ // call and hook order stays stable across renders. When the peer is absent the
18
+ // component throws a friendly install message on first render.
19
+
20
+ type ReactTableModule = {
21
+ flexRender: (...args: any[]) => React.ReactNode;
22
+ getCoreRowModel: (...args: any[]) => any;
23
+ getExpandedRowModel: (...args: any[]) => any;
24
+ getSortedRowModel: (...args: any[]) => any;
25
+ useReactTable: (options: any) => any;
26
+ };
27
+
28
+ let _reactTable: ReactTableModule | null = null;
29
+ let _reactTableLoaded = false;
30
+ let _reactTableFailed = false;
31
+
32
+ function loadReactTable() {
33
+ if (_reactTableLoaded) return;
34
+ _reactTableLoaded = true;
35
+ try {
36
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
37
+ _reactTable = require("@tanstack/react-table") as ReactTableModule;
38
+ } catch {
39
+ _reactTableFailed = true;
40
+ }
41
+ }
15
42
 
16
43
  /** Horizontal alignment for a column's header + cells. */
17
44
  export type ColumnAlign = "left" | "right" | "center";
@@ -50,15 +77,6 @@ export type DataTableRowClickEvent =
50
77
 
51
78
  export type DataTableColumn<T> = ColumnDef<T, unknown>;
52
79
 
53
- // ============================================
54
- // Dependency (@tanstack/react-table)
55
- // ============================================
56
- // Statically imported (ESM) so DataTable works in every bundler, including
57
- // browser SPAs (Vite) where `require` is unavailable. `useReactTable` is a
58
- // hook and must resolve synchronously on first render. The package is an
59
- // optional peer dep + `sideEffects: false`, so this import is tree-shaken
60
- // out of bundles that never import DataTable.
61
-
62
80
  export interface DataTableProps<T> extends Omit<React.HTMLAttributes<HTMLTableElement>, "onClick"> {
63
81
  /** Column definitions */
64
82
  columns: DataTableColumn<T>[];
@@ -186,6 +204,16 @@ function DataTableRoot<T>({
186
204
  "aria-describedby": ariaDescribedBy,
187
205
  ...htmlProps
188
206
  }: DataTableProps<T>) {
207
+ loadReactTable();
208
+ if (_reactTableFailed || !_reactTable) {
209
+ throw new Error(
210
+ "[@usefragments/ui] DataTable: @tanstack/react-table is not installed. " +
211
+ "Install it with: npm install @tanstack/react-table"
212
+ );
213
+ }
214
+ const { flexRender, getCoreRowModel, getExpandedRowModel, getSortedRowModel, useReactTable } =
215
+ _reactTable;
216
+
189
217
  const tableRef = React.useRef<HTMLTableElement>(null);
190
218
  useArrowKeyRowNav(tableRef, !!onRowClick);
191
219
 
package/src/index.ts CHANGED
@@ -257,15 +257,14 @@ export {
257
257
  type ExpandedState,
258
258
  } from "./components/DataTable";
259
259
 
260
- // DataTable row virtualization (opt-in; requires @tanstack/react-virtual)
261
- export {
262
- DataTableVirtual,
263
- useTableVirtualizer,
264
- type DataTableVirtualProps,
265
- type UseTableVirtualizerOptions,
266
- type UseTableVirtualizerResult,
267
- type VirtualTableRow,
268
- } from "./components/DataTable/DataTable.virtual";
260
+ // DataTable row virtualization (opt-in; requires @tanstack/react-virtual).
261
+ // Intentionally NOT re-exported from the main barrel: `useTableVirtualizer`
262
+ // wraps a hook that must resolve synchronously, so — unlike DataTable/Chart/
263
+ // Editor — it cannot be lazy-required. Re-exporting it here (or routing it
264
+ // through the `./data-table` subpath, which the main barrel imports) would
265
+ // statically pull @tanstack/react-virtual into every consumer's Button-only
266
+ // build. It lives behind its own dedicated subpath the barrel never imports:
267
+ // import { DataTableVirtual, useTableVirtualizer } from "@usefragments/ui/data-table-virtual";
269
268
 
270
269
  // EmptyState
271
270
  export {
@@ -0,0 +1,8 @@
1
+ // Ambient type surface for the side-effect style entrypoints
2
+ // (`@usefragments/ui/styles` and `@usefragments/ui/globals`). These specifiers
3
+ // resolve to compiled CSS (or the raw SCSS under the `sass` condition) and carry
4
+ // no runtime exports, so a bare `import "@usefragments/ui/styles";` needs a
5
+ // resolvable `types` target to keep TypeScript from erroring. This file ships in
6
+ // the published tarball via the package `files: ["src"]` entry and is referenced
7
+ // by the `types` condition of both exports in `publishConfig`.
8
+ export {};