xontable 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # xontable
2
2
 
3
- A spreadsheet-like React table component with selection, clipboard, fill handle, validation, filters, select dropdowns, and checkbox cells.
3
+ A spreadsheet-like React table component with Excel-style editing, selection, clipboard, fill handle, validation, filters, select dropdowns, checkbox cells, and column groups.
4
4
 
5
5
  ## Install
6
6
 
@@ -8,22 +8,172 @@ A spreadsheet-like React table component with selection, clipboard, fill handle,
8
8
  npm install xontable
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Quick Start
12
12
 
13
13
  ```tsx
14
+ import React, { useState } from "react";
14
15
  import { XOnTable, type ColumnDef } from "xontable";
15
16
  import "xontable/styles";
16
17
 
18
+ type Row = { id: string; name: string; qty: string };
19
+
17
20
  const columns: ColumnDef<Row>[] = [
18
- { key: "name", label: "Name", type: "text", editable: true },
21
+ { key: "name", label: "Name", editable: true },
19
22
  { key: "qty", label: "Qty", type: "number", editable: true },
20
23
  ];
21
24
 
22
- <XOnTable columns={columns} rows={rows} onChange={setRows} />;
25
+ export default function App() {
26
+ const [rows, setRows] = useState<Row[]>([
27
+ { id: "1", name: "Rice", qty: "10" },
28
+ ]);
29
+
30
+ return <XOnTable columns={columns} rows={rows} onChange={setRows} />;
31
+ }
32
+ ```
33
+
34
+ ## Styles (Required)
35
+
36
+ Always import the styles once in your app:
37
+
38
+ ```ts
39
+ import "xontable/styles";
23
40
  ```
24
41
 
25
- ## Notes
26
- - Built for React 19+
27
- - Styles are included via `xontable/styles`
42
+ ## Props
43
+
44
+ - `columns`: Column definitions
45
+ - `rows`: Data rows
46
+ - `onChange(nextRows, meta)`: Updated rows with change meta
47
+ - `readOnly`: Disable editing
48
+ - `theme`: `"light" | "dark"`
49
+
50
+ ## Column Definition
51
+
52
+ ```ts
53
+ type ColumnDef<Row> = {
54
+ key: keyof Row | string;
55
+ label: string;
56
+ width?: number;
57
+ editable?: boolean;
58
+ type?: "text" | "number" | "date" | "select" | "checkbox";
59
+ validator?: (value: string, row: Row) => string | null;
60
+ group?: string;
61
+ groupCollapsible?: boolean;
62
+ options?: { value: string; label: string }[];
63
+ getOptions?: (row: Row) => Promise<{ value: string; label: string }[]>;
64
+ dependsOn?: string; // for cascading selects
65
+ };
66
+ ```
67
+
68
+ ## Data Model
69
+
70
+ Rows are objects:
71
+
72
+ ```ts
73
+ type Row = { id: string; [key: string]: any };
74
+ ```
75
+
76
+ `onChange` receives a **new rows array** whenever edits/paste/fill happen.
77
+
78
+ ## Editing
79
+ - Single click selects
80
+ - Enter or double-click to edit
81
+ - Typing starts edit with typed character
82
+ - Enter commits, Esc cancels, Tab commits and moves
83
+
84
+ ## Keyboard Navigation
85
+ - Arrow keys move selection
86
+ - Tab / Shift+Tab moves horizontally
87
+ - Shift + arrows extends selection
88
+
89
+ ## Copy / Paste
90
+ - TSV compatible with Excel/Google Sheets
91
+ - Use Ctrl/Cmd+C to copy selection
92
+ - Use Ctrl/Cmd+V to paste into table
93
+
94
+ ## Fill Handle
95
+ - Drag the dot at bottom-right of active cell
96
+ - Fills down or across with repeated value
97
+
98
+ ## Validation
99
+
100
+ Per-column validation:
101
+
102
+ ```ts
103
+ { key: "qty", label: "Qty", type: "number", validator: (v) => v ? null : "Required" }
104
+ ```
105
+
106
+ Built-in number validation if `type: "number"`.
107
+
108
+ ## Select Dropdowns
109
+
110
+ Static options:
111
+
112
+ ```ts
113
+ { key: "city", label: "City", type: "select", options: [
114
+ { value: "tokyo", label: "Tokyo" }
115
+ ] }
116
+ ```
117
+
118
+ Async options:
119
+
120
+ ```ts
121
+ { key: "group", label: "Group", type: "select", getOptions: async () => groupOptions }
122
+ ```
123
+
124
+ Cascading select with `dependsOn`:
125
+
126
+ ```ts
127
+ { key: "subgroup", label: "Subgroup", type: "select", dependsOn: "group", getOptions: async (row) => options[row.group] }
128
+ ```
129
+
130
+ Invalid values will show validation color.
131
+
132
+ ## Checkbox Cells
133
+
134
+ ```ts
135
+ { key: "active", label: "Active", type: "checkbox" }
136
+ ```
137
+
138
+ Values are `true` / `false`.
139
+
140
+ ## Column Groups
141
+
142
+ ```ts
143
+ { key: "name", label: "Name", group: "User" }
144
+ { key: "active", label: "Active", group: "User", groupCollapsible: true }
145
+ ```
146
+
147
+ Groups render a top header row and can be collapsed if `groupCollapsible` is true.
148
+
149
+ ## Filters
150
+ Each column header shows a filter icon.
151
+ - Search inside the filter menu
152
+ - Toggle values on/off
153
+
154
+ ## Readonly Mode
155
+
156
+ ```tsx
157
+ <XOnTable readOnly />
158
+ ```
159
+
160
+ Readonly keeps selection and scrolling but disables editing.
161
+
162
+ ## Theme
163
+
164
+ ```tsx
165
+ <XOnTable theme="dark" />
166
+ ```
167
+
168
+ ## Requirements
169
+ - React 19+
170
+ - Peer deps: `react`, `react-dom`, `lucide-react`
171
+
172
+ ## Troubleshooting
173
+
174
+ **Error: Could not resolve "./styles/xontable.css"**
175
+ - Ensure you installed the latest version and it was built/published correctly.
176
+ - Clear Vite cache: delete `node_modules/.vite` and run `npm run dev -- --force`.
28
177
 
29
- See the root `BOOK.md` for full developer documentation.
178
+ ## License
179
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xontable",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,17 +11,16 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "default": "./dist/index.js"
13
13
  },
14
- "./styles": "./src/styles/xontable.css"
14
+ "./styles": "./dist/styles/xontable.css"
15
15
  },
16
16
  "sideEffects": [
17
- "./src/styles/xontable.css"
17
+ "./dist/styles/xontable.css"
18
18
  ],
19
19
  "files": [
20
- "dist",
21
- "src/styles"
20
+ "dist"
22
21
  ],
23
22
  "scripts": {
24
- "build": "tsc -p tsconfig.json",
23
+ "build": "tsc -p tsconfig.json && node ./scripts/copy-styles.mjs",
25
24
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
26
25
  "prepublishOnly": "npm run clean && npm run build"
27
26
  },
File without changes
File without changes
File without changes
File without changes