@trellisjs/react 0.1.0-alpha.1 → 1.0.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -0
  3. package/package.json +19 -14
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 TrellisJS Contributors
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 ADDED
@@ -0,0 +1,86 @@
1
+ # @trellisjs/react
2
+
3
+ Headless data table components and hooks for React, powered by `@trellisjs/core`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @trellisjs/react @trellisjs/core react react-dom
9
+ ```
10
+
11
+ Requires React >= 18.
12
+
13
+ ## API
14
+
15
+ ### `useTrellis<T>(options)`
16
+
17
+ Creates and manages a Trellis instance. Returns `{ api }` where `api` is a
18
+ `TrellisAPI<T>`. The instance is created once and re-renders are triggered
19
+ automatically on state changes. Compatible with React StrictMode double-mount.
20
+
21
+ ```ts
22
+ const { api } = useTrellis<User>({ columns, data });
23
+ ```
24
+
25
+ **Parameters** -- `options: TrellisOptions<T>` (column definitions, initial
26
+ data, plugins, etc.) passed directly to the `Trellis` constructor.
27
+
28
+ ### `TrellisContext`
29
+
30
+ A React context holding a `TrellisAPI` instance. Wrap your tree with
31
+ `<TrellisContext.Provider value={api}>` so child components can access the
32
+ table API.
33
+
34
+ ### `useTrellisContext<T>()`
35
+
36
+ Hook that reads the `TrellisAPI` from `TrellisContext`. Throws if called
37
+ outside a provider.
38
+
39
+ ### Components
40
+
41
+ | Component | Description |
42
+ |-----------|-------------|
43
+ | `Table` | Renders a `<table>` with `<TableHead>` and `<TableBody>`. |
44
+ | `TableHead` | Header row from column definitions. |
45
+ | `TableBody` | Body rows from current data and columns. |
46
+ | `Tr` / `Th` / `Td` | Primitive row and cell components. |
47
+
48
+ ### `SlotRenderer`
49
+
50
+ Renders a named slot from the Trellis slot registry.
51
+
52
+ ```tsx
53
+ <SlotRenderer name="toolbar" fallback={<div>No toolbar</div>} />
54
+ ```
55
+
56
+ Props:
57
+
58
+ - `name` -- slot name to look up.
59
+ - `context` -- optional `SlotContext` passed to the renderer.
60
+ - `fallback` -- rendered when no slot is registered.
61
+
62
+ ## Quick Usage
63
+
64
+ ```tsx
65
+ import { useTrellis, TrellisContext, Table, SlotRenderer } from '@trellisjs/react';
66
+
67
+ const columns = [
68
+ { id: 'name', label: 'Name' },
69
+ { id: 'email', label: 'Email' },
70
+ ];
71
+
72
+ function App() {
73
+ const { api } = useTrellis({ columns, data: users });
74
+
75
+ return (
76
+ <TrellisContext.Provider value={api}>
77
+ <SlotRenderer name="toolbar" />
78
+ <Table />
79
+ </TrellisContext.Provider>
80
+ );
81
+ }
82
+ ```
83
+
84
+ ## License
85
+
86
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trellisjs/react",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "1.0.0",
4
4
  "description": "Trellis 的 React 適配器 — 無頭式資料表格元件",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,22 +20,14 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
- "scripts": {
24
- "build": "tsup",
25
- "dev": "tsup --watch",
26
- "test": "vitest run",
27
- "test:watch": "vitest",
28
- "clean": "rm -rf dist *.tsbuildinfo"
29
- },
30
23
  "peerDependencies": {
31
- "@trellisjs/core": "workspace:*",
32
24
  "react": ">=18.0.0",
33
- "react-dom": ">=18.0.0"
25
+ "react-dom": ">=18.0.0",
26
+ "@trellisjs/core": "0.1.0"
34
27
  },
35
28
  "devDependencies": {
36
29
  "@testing-library/jest-dom": "^6.9.1",
37
30
  "@testing-library/react": "^16.3.0",
38
- "@trellisjs/core": "workspace:*",
39
31
  "@types/react": "^19.1.0",
40
32
  "@types/react-dom": "^19.1.0",
41
33
  "jsdom": "^26.1.0",
@@ -43,8 +35,21 @@
43
35
  "react-dom": "^19.1.0",
44
36
  "tsup": "^8.4.0",
45
37
  "typescript": "^5.7.0",
46
- "vitest": "^3.1.0"
38
+ "vitest": "^3.1.0",
39
+ "@trellisjs/core": "0.1.0"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/cluion/trellis.git",
44
+ "directory": "packages/react"
47
45
  },
48
46
  "license": "MIT",
49
- "sideEffects": false
50
- }
47
+ "sideEffects": false,
48
+ "scripts": {
49
+ "build": "tsup",
50
+ "dev": "tsup --watch",
51
+ "test": "vitest run",
52
+ "test:watch": "vitest",
53
+ "clean": "rm -rf dist *.tsbuildinfo"
54
+ }
55
+ }