@itrocks/table 0.0.20 → 0.0.22
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 +208 -1
- package/package.json +12 -5
package/README.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
A lightweight, modular HTML table offering near-spreadsheet features such as edit, freeze, lock, scroll, and more.
|
|
10
10
|
|
|
11
|
+
*This documentation was written by an artificial intelligence and may contain errors or approximations.
|
|
12
|
+
It has not yet been fully reviewed by a human. If anything seems unclear or incomplete,
|
|
13
|
+
please feel free to contact the author of this package.*
|
|
14
|
+
|
|
11
15
|
## Installation
|
|
12
16
|
|
|
13
17
|
```bash
|
|
@@ -16,4 +20,207 @@ npm i @itrocks/table
|
|
|
16
20
|
|
|
17
21
|
## Usage
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
`@itrocks/table` is a lightweight, modular JavaScript table component that
|
|
24
|
+
turns a plain HTML `<table>` into a near‑spreadsheet widget: editable
|
|
25
|
+
cells, frozen columns, locked headers, horizontal and vertical scrolling,
|
|
26
|
+
and more.
|
|
27
|
+
|
|
28
|
+
At runtime you create `Table` instances from existing DOM elements.
|
|
29
|
+
|
|
30
|
+
### Minimal example
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { tableBySelector } from '@itrocks/table'
|
|
34
|
+
|
|
35
|
+
// Turn all matching <table> elements into interactive tables
|
|
36
|
+
const tables = tableBySelector('.js-data-table')
|
|
37
|
+
|
|
38
|
+
// Optionally keep a reference to one table
|
|
39
|
+
const table = tables[0]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Make sure the DOM is ready before you call `tableBySelector` (for example
|
|
43
|
+
after `DOMContentLoaded` or in your framework's mounted hook).
|
|
44
|
+
|
|
45
|
+
You can also construct a table directly from an element:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { tableByElement } from '@itrocks/table'
|
|
49
|
+
|
|
50
|
+
const element = document.querySelector('table#users') as HTMLTableElement
|
|
51
|
+
const table = tableByElement(element)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For more advanced usage (plugins, styling, demos), check out the
|
|
55
|
+
[GitHub demo folder](https://github.com/itrocks-ts/table/tree/master/demo).
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
The public API is intentionally small and focuses on a single `Table`
|
|
60
|
+
class plus a few helpers.
|
|
61
|
+
|
|
62
|
+
### `applyStyleSheets()`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { applyStyleSheets } from '@itrocks/table'
|
|
66
|
+
|
|
67
|
+
applyStyleSheets()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Forces the table module to (re)apply its internal style sheets. In most
|
|
71
|
+
applications you do not need to call this manually: it is handled when
|
|
72
|
+
creating `Table` instances. It can be useful in advanced integration
|
|
73
|
+
scenarios (dynamic theme switch, hot‑reloaded styles, etc.).
|
|
74
|
+
|
|
75
|
+
### `garbageCollector()`
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { garbageCollector } from '@itrocks/table'
|
|
79
|
+
|
|
80
|
+
garbageCollector()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Runs an internal cleanup pass to detach listeners and release resources
|
|
84
|
+
from tables that are no longer present in the DOM. You might call this
|
|
85
|
+
periodically in long‑running pages where tables are created and removed
|
|
86
|
+
dynamically.
|
|
87
|
+
|
|
88
|
+
### `getTables()`
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { getTables } from '@itrocks/table'
|
|
92
|
+
|
|
93
|
+
const tables = getTables()
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Returns the list of all `Table` instances currently managed by the
|
|
97
|
+
module. This is mainly useful for debugging or global operations (for
|
|
98
|
+
example applying a plugin to every existing table).
|
|
99
|
+
|
|
100
|
+
### `type Options = PluginOptions<Table>`
|
|
101
|
+
|
|
102
|
+
Configuration object passed when creating a `Table`. It is based on the
|
|
103
|
+
generic plugin system from
|
|
104
|
+
[`@itrocks/plugin`](https://github.com/itrocks-ts/plugin).
|
|
105
|
+
|
|
106
|
+
Typical usage:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import type { Options } from '@itrocks/table'
|
|
110
|
+
|
|
111
|
+
const options: Partial<Options> = {
|
|
112
|
+
// enable / configure plugins here
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The exact shape of the options depends on the plugins you enable (edit,
|
|
117
|
+
freeze, reorder, etc.). Refer to each plugin's documentation and the
|
|
118
|
+
demo code for details.
|
|
119
|
+
|
|
120
|
+
### `class Table extends HasPlugins<Table>`
|
|
121
|
+
|
|
122
|
+
Represents an interactive table instance bound to a single
|
|
123
|
+
`HTMLTableElement`.
|
|
124
|
+
|
|
125
|
+
#### Constructor
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { Table } from '@itrocks/table'
|
|
129
|
+
|
|
130
|
+
const table = new Table(element, options)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Parameters:
|
|
134
|
+
|
|
135
|
+
- `element: HTMLTableElement` – the DOM table to enhance.
|
|
136
|
+
- `options?: Partial<Options>` – optional configuration and plugins.
|
|
137
|
+
|
|
138
|
+
#### Properties
|
|
139
|
+
|
|
140
|
+
- `element: HTMLTableElement` – underlying table element.
|
|
141
|
+
- `id: number` – numeric identifier assigned to the table instance.
|
|
142
|
+
- `selector: string` – selector used when the table was created (when
|
|
143
|
+
relevant).
|
|
144
|
+
- `onReset: (() => void)[]` – list of callbacks invoked when the table
|
|
145
|
+
is reset.
|
|
146
|
+
- `styleSheet: string[]` – list of CSS rules associated with this table
|
|
147
|
+
instance.
|
|
148
|
+
|
|
149
|
+
#### Methods
|
|
150
|
+
|
|
151
|
+
##### `addEventListener(element, type, listener, options?)`
|
|
152
|
+
|
|
153
|
+
Delegates the registration of an event listener through the table
|
|
154
|
+
infrastructure, so it can be properly cleaned up on reset or removal.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
table.addEventListener(document, 'keydown', event => {
|
|
158
|
+
// react to keyboard shortcuts related to this table
|
|
159
|
+
})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
##### `cellColumnNumber(cell: HTMLTableCellElement): number`
|
|
163
|
+
|
|
164
|
+
Returns the zero‑based column index of the given table cell within its
|
|
165
|
+
row. This is handy when writing plugins that need to know which column a
|
|
166
|
+
cell belongs to.
|
|
167
|
+
|
|
168
|
+
##### `reset(): Table`
|
|
169
|
+
|
|
170
|
+
Resets the table to its initial state:
|
|
171
|
+
|
|
172
|
+
- clears plugin state,
|
|
173
|
+
- reapplies default configuration,
|
|
174
|
+
- triggers all callbacks registered in `onReset`.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
table.reset()
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Helper constructors
|
|
181
|
+
|
|
182
|
+
In addition to the `Table` class, the module exposes convenience
|
|
183
|
+
functions to create tables from different inputs.
|
|
184
|
+
|
|
185
|
+
#### `tableByElement(element, options?)`
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { tableByElement } from '@itrocks/table'
|
|
189
|
+
|
|
190
|
+
const table = tableByElement(element, { /* options */ })
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Creates (or returns an existing) `Table` instance for the given
|
|
194
|
+
`HTMLTableElement`.
|
|
195
|
+
|
|
196
|
+
#### `tableByElements(elements, options?)`
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { tableByElements } from '@itrocks/table'
|
|
200
|
+
|
|
201
|
+
const nodeList = document.querySelectorAll('table.data')
|
|
202
|
+
const tables = tableByElements(nodeList)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Accepts an array or a `NodeListOf<HTMLTableElement>` and returns an
|
|
206
|
+
array of `Table` instances.
|
|
207
|
+
|
|
208
|
+
#### `tableBySelector(selector, options?)`
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { tableBySelector } from '@itrocks/table'
|
|
212
|
+
|
|
213
|
+
const tables = tableBySelector('.js-data-table')
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Finds all tables matching the CSS selector and returns the corresponding
|
|
217
|
+
`Table` instances.
|
|
218
|
+
|
|
219
|
+
## Typical use cases
|
|
220
|
+
|
|
221
|
+
- Enhance existing HTML tables with spreadsheet‑like behaviours (edit,
|
|
222
|
+
freeze, lock, scroll) without rewriting the markup.
|
|
223
|
+
- Build rich back‑office or data‑entry screens where users can edit
|
|
224
|
+
multiple rows directly in a table.
|
|
225
|
+
- Implement custom plugins on top of `HasPlugins<Table>` to add domain‑
|
|
226
|
+
specific features (validation, inline actions, totals rows, etc.).
|
package/package.json
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"description": "A lightweight, modular HTML table offering near-spreadsheet features such as edit, freeze, lock, scroll, and more",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@itrocks/prepare-module": "latest",
|
|
13
|
-
"@types/node": "^
|
|
14
|
-
"sass": "^1.
|
|
15
|
-
"typescript": "~5.
|
|
13
|
+
"@types/node": "^24.10",
|
|
14
|
+
"sass": "^1.95",
|
|
15
|
+
"typescript": "~5.9"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"LICENSE",
|
|
@@ -24,18 +24,25 @@
|
|
|
24
24
|
],
|
|
25
25
|
"homepage": "https://it.rocks",
|
|
26
26
|
"keywords": [
|
|
27
|
+
"column",
|
|
28
|
+
"columns",
|
|
27
29
|
"drag",
|
|
28
30
|
"drop",
|
|
29
31
|
"edit",
|
|
30
32
|
"editable",
|
|
33
|
+
"feed",
|
|
31
34
|
"freeze",
|
|
32
35
|
"front-end",
|
|
33
36
|
"frozen",
|
|
34
37
|
"it.rocks",
|
|
35
38
|
"lock",
|
|
36
39
|
"reorder",
|
|
40
|
+
"row",
|
|
41
|
+
"rows",
|
|
37
42
|
"scroll",
|
|
38
|
-
"table"
|
|
43
|
+
"table",
|
|
44
|
+
"UI",
|
|
45
|
+
"UX"
|
|
39
46
|
],
|
|
40
47
|
"license": "LGPL-3.0-or-later",
|
|
41
48
|
"module": "./table.js",
|
|
@@ -49,5 +56,5 @@
|
|
|
49
56
|
},
|
|
50
57
|
"type": "module",
|
|
51
58
|
"types": "./table.d.ts",
|
|
52
|
-
"version": "0.0.
|
|
59
|
+
"version": "0.0.22"
|
|
53
60
|
}
|