@timlassiter11/yatl 1.0.18 → 1.2.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": "@timlassiter11/yatl",
3
- "version": "1.0.18",
3
+ "version": "1.2.0",
4
4
  "description": "Yet another table library with all of the standard bells and whistles.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -11,7 +11,8 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.mjs",
13
13
  "require": "./dist/index.js"
14
- }
14
+ },
15
+ "./theme.css": "./dist/theme.css"
15
16
  },
16
17
  "sideEffects": [
17
18
  "./dist/index.mjs",
@@ -31,28 +32,25 @@
31
32
  ],
32
33
  "scripts": {
33
34
  "lint": "eslint",
34
- "format": "prettier src/* --write",
35
- "format:check": "prettier src/* --check",
35
+ "lint:fix": "eslint --fix",
36
+ "format": "prettier src/** --write",
37
+ "format:check": "prettier src/** --check",
36
38
  "type:check": "npx tsc --noEmit",
37
39
  "build": "tsup",
38
- "start": "web-dev-server --node-resolve",
39
- "start:watch": "web-dev-server --node-resolve --watch",
40
+ "build:watch": "tsup --watch",
40
41
  "test": "vitest run",
41
- "test:watch": "vitest",
42
- "test:ui": "vitest --ui",
43
- "preversion": "npm run format && npm test",
44
- "release": "npm version patch && git push origin main --follow-tags"
42
+ "test:watch": "vitest"
45
43
  },
46
44
  "repository": {
47
45
  "type": "git",
48
- "url": "https://github.com/timlassiter11/YATL"
46
+ "url": "git+https://github.com/timlassiter11/YATL.git"
49
47
  },
50
48
  "bugs": {
51
49
  "url": "https://github.com/timlassiter11/YATL/issues"
52
50
  },
53
51
  "homepage": "https://github.com/timlassiter11/YATL#readme",
54
52
  "engines": {
55
- "node": ">22.0.0"
53
+ "node": ">=18.0.0"
56
54
  },
57
55
  "publishConfig": {
58
56
  "access": "public",
@@ -62,8 +60,6 @@
62
60
  "@eslint/js": "^9.28.0",
63
61
  "@types/node": "^22.15.17",
64
62
  "@vitest/browser-playwright": "^4.0.18",
65
- "@web/dev-server": "^0.4.6",
66
- "esbuild": "^0.25.4",
67
63
  "eslint": "^9.28.0",
68
64
  "prettier": "^3.5.3",
69
65
  "tsup": "^8.4.0",
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Timothy Lassiter
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 DELETED
@@ -1,374 +0,0 @@
1
- # YATL (Yet Another Table Library)
2
-
3
- [![NPM Version](https://img.shields.io/npm/v/@timlassiter11/yatl)](https://www.npmjs.com/package/@timlassiter11/yatl)
4
- [![API Docs](https://img.shields.io/badge/docs-typedoc-blue)](https://timlassiter11.github.io/YATL/docs/index.html)
5
- [![Live Demo](https://img.shields.io/badge/demo-online-green)](https://timlassiter11.github.io/YATL/examples/index.html)
6
- [![License](https://img.shields.io/npm/l/@timlassiter11/yatl)](LICENSE)
7
-
8
- YATL is a powerful, feature-rich, and lightweight Web Component data table built with Lit. It handles large datasets with ease using virtual scrolling, offers advanced fuzzy search capabilities, supports state persistence, and works in any framework (React, Vue, Angular, or Vanilla JS).
9
-
10
- ## Why?!?
11
-
12
- I needed a free and simple table library for vanilla JS that was easy to customize and could handle large datasets... so I created YATL. As the project that I wrote this for grew, so did this library. Now it is a web component built using Lit that is fairly feature rich for simple use cases. There are many other great table libraries out there but if you want something simple to just drop in but with all of the major features already included, YATL might be for you.
13
-
14
- ## Features
15
-
16
- - **Virtual Scrolling**: Render 100,000+ rows smoothly with virtual scrolling.
17
- - **Smart Search**: Tokenized fuzzy search with relevance scoring and highlighting.
18
- - **State Persistence**: Automatically save and restore column order, visibility, sort, and widths to LocalStorage.
19
- - **Highly Customizable**: Slot support, CSS Shadow Parts, and custom cell renderers.
20
- - **Interactive**: Drag-and-drop column reordering, multi-column sorting (`SHIFT+CLICK`), and resizeable headers.
21
- - **Export**: Built-in CSV export for visible or all data.
22
- - **Type Safe**: Generic component with full type hint support.
23
-
24
- ## Installation
25
-
26
- The recommend method is to use npm.
27
-
28
- ```bash
29
- npm install @timlassiter11/yatl
30
- ```
31
-
32
- Alternatively you can manually download the source files from the [releases](https://github.com/timlassiter11/YATL/releases) section.
33
-
34
- ## Examples
35
- ### Lit
36
-
37
- ```ts
38
- import { html, LitElement } from 'lit';
39
-
40
- import { ColumnOptions, YatlRowClickEvent } from '@timlassiter11/yatl';
41
- import { customElement, state } from 'lit/decorators.js';
42
-
43
- type User = { id: number; name: string; dateCreated: Date };
44
-
45
- @customElement('my-component')
46
- export class MyComponent extends LitElement {
47
- private dateFormatter = Intl.DateTimeFormat(undefined, {
48
- dateStyle: 'short',
49
- timeStyle: undefined,
50
- });
51
-
52
- private colums: ColumnOptions<User>[] = [
53
- {
54
- field: 'id',
55
- title: 'ID',
56
- resizable: true,
57
- sortable: true,
58
- searchable: false,
59
- },
60
- {
61
- field: 'name',
62
- resizable: true,
63
- sortable: true,
64
- searchable: true,
65
- tokenize: true,
66
- },
67
- {
68
- field: 'dateCreated',
69
- resizable: true,
70
- sortable: true,
71
- searchable: false,
72
- valueFormatter: value => this.dateFormatter.format(value as Date),
73
- },
74
- ];
75
-
76
- @state()
77
- private data: User[] = [
78
- { id: 0, name: 'Bjarne Stroustrup', dateCreated: new Date(1968, 11, 30) },
79
- { id: 1, name: 'Guido van Rossum', dateCreated: new Date(1974, 0, 31) },
80
- ];
81
-
82
- protected override render() {
83
- return html`
84
- <yatl-table
85
- .columns=${this.colums}
86
- .data=${this.data}
87
- enable-virtual-scroll
88
- @yatl-row-click=${this.handleRowClicked}
89
- >
90
- </yatl-table>
91
- `;
92
- }
93
-
94
- private handleRowClicked = (event: YatlRowClickEvent<User>) => {
95
- console.log(event.detail);
96
- };
97
- }
98
- ```
99
-
100
- ### Vanilla JS
101
-
102
- ```html
103
- <!doctype html>
104
- <html lang="en">
105
- <head>
106
- <meta charset="utf-8" />
107
- <title>Basic Example</title>
108
- <style>
109
- body {
110
- height: 100vh;
111
- width: 100vw;
112
- margin: 0;
113
- padding: 20px;
114
- box-sizing: border-box;
115
- }
116
- </style>
117
- </head>
118
-
119
- <body>
120
- <yatl-table sortable resizable enable-footer></yatl-table>
121
- <script src="../dist/yatl.min.global.js"></script>
122
- <script>
123
- window.addEventListener('load', () => {
124
- const table = document.querySelector('yatl-table');
125
- table.columns = [
126
- {
127
- field: 'index',
128
- title: 'ID',
129
- },
130
- {
131
- field: 'name',
132
- },
133
- {
134
- field: 'value',
135
- },
136
- ];
137
-
138
- // Generate random rows of data
139
- table.data = new Array(100).fill(null).map((v, i) => ({
140
- index: i,
141
- name: `Row ${i}`,
142
- value: Math.random() * 1000,
143
- }));
144
-
145
- table.addEventListener('yatl-row-click', event => {
146
- console.log(event.detail);
147
- });
148
- });
149
- </script>
150
- </body>
151
- </html>
152
- ```
153
-
154
- ## Styling Guide
155
-
156
- YATL Table is built with extensive CSS Custom Properties (variables) to make theming easy. Styles are scoped to the shadow DOM, but you can control them from anywhere in your application (e.g., :root or a parent container) using the provided --yatl-table-\* variables.
157
-
158
- ### Quick Start
159
-
160
- You can apply styles directly to the component or inherit them globally.
161
-
162
- ```css
163
- /* Apply globally */
164
- :root {
165
- --yatl-table-font-size: 1rem;
166
- --yatl-table-bg-light: #fdfdfd;
167
- }
168
-
169
- /* Or scope to a specific class */
170
- .my-custom-table {
171
- --yatl-table-border-color: #ccc;
172
- --yatl-table-header-bg: #eee;
173
- }
174
- ```
175
-
176
- ### CSS Variables Reference
177
-
178
- #### Typography
179
-
180
- | Variable | Description |
181
- | ------------------------ | -------------------------------- |
182
- | --yatl-table-font | The font family stack. |
183
- | --yatl-table-font-size | Base font size for all text. |
184
- | --yatl-table-line-height | Line height for text legibility. |
185
-
186
- #### Spacing & Layout
187
-
188
- | Variable | Description |
189
- | --------------------------- | ------------------------------------------------- |
190
- | --yatl-table-cell-padding | Padding inside standard body cells. |
191
- | --yatl-table-header-padding | Padding inside header cells. |
192
- | --yatl-table-resizer-width | The width of the "grab" area for column resizing. |
193
-
194
- #### Color Variables
195
-
196
- | Variable | Description |
197
- | ---------------------------- | ---------------------------------------------- |
198
- | --yatl-table-bg | Main background color of the table. |
199
- | --yatl-table-text | Primary text color. |
200
- | --yatl-table-text-muted | Secondary/footer text color. |
201
- | --yatl-table-border-color | Border color for rows and the table container. |
202
- | --yatl-table-header-bg | Background for the sticky header row. |
203
- | --yatl-table-header-text | Text color for the header row. |
204
- | --yatl-table-row-hover-bg | Background color when hovering over a row. |
205
- | --yatl-table-row-selected-bg | Background color for selected rows. |
206
-
207
- **NOTE**: For each color variable, there is a dedicated `-light` and `-dark` variable. See [Color Scheme](#color-scheme) below for more info.
208
-
209
- ### Color Scheme
210
-
211
- By default, this component adapts to the current `color-scheme` by utilizing the [light-dark()](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/light-dark) CSS function. This will automatically adjust to the system theme, but can be manually overridden. If you have a theme toggler, you should have it set the document `color-scheme`. Below is an example assuming you set a `light` or `dark` class on your document element.
212
-
213
- ```css
214
- :root {
215
- color-scheme: light dark;
216
- }
217
-
218
- :root.light {
219
- color-scheme: light;
220
- }
221
-
222
- :root.dark {
223
- color-scheme: dark;
224
- }
225
- ```
226
-
227
- To force a color regardless of the current color scheme, you can override the base variable.
228
-
229
- ```css
230
- :root {
231
- /* Always dark background */
232
- --yatl-table-bg: #212121;
233
- }
234
- ```
235
-
236
- If you want to update a color for one of the color schemes, use the specific theme variable instead.
237
-
238
- ```css
239
- :root {
240
- /* light background */
241
- --yatl-table-bg-light: #e0e0e0;
242
- /* dark background */
243
- --yatl-table-bg-dark: #202020;
244
- }
245
- ```
246
-
247
- ### CSS Shadow Parts
248
-
249
- For deeper customization beyond color and spacing, you can target specific elements using the ::part pseudo-element.
250
-
251
- ```css
252
- yatl-table::part(header) {
253
- text-transform: uppercase;
254
- letter-spacing: 0.05em;
255
- }
256
- ```
257
-
258
- #### Parts Reference
259
-
260
- | Part Name | Description |
261
- | ---------------- | ----------------------------------------------- |
262
- | table | The main container grid. |
263
- | header | The container for the header row. |
264
- | header-cell | Individual header cells. |
265
- | header-title | The text span inside a header cell. |
266
- | header-sort-icon | The sorting arrow icon. |
267
- | header-resizer | The drag handle for resizing columns. |
268
- | row | The container for a data row. |
269
- | cell | Targets all cells (both header and body). |
270
- | body-cell | Targets only data cells (not headers). |
271
- | footer | The footer container. |
272
- | message | The empty state / no results message container. |
273
-
274
- ### Common Recipes
275
-
276
- #### Zebra Striping
277
-
278
- You can use standard pseudo-classes like :nth-child combined with ::part.
279
-
280
- ```css
281
- /* Stripe every even row */
282
- yatl-table::part(row):nth-child(even) {
283
- background-color: #f9f9f9;
284
- }
285
-
286
- /* Add a hover effect to rows */
287
- yatl-table::part(row):hover {
288
- background-color: #e0f2fe;
289
- cursor: pointer;
290
- }
291
- ```
292
-
293
- #### Targeting Specific Columns
294
-
295
- Every cell automatically gets a part name based on its field property in the format cell-{field}.
296
-
297
- For example, if you have a column defined as `{ field: 'status' }`:
298
-
299
- ```css
300
- /* Center the 'status' column and make it bold */
301
- yatl-table::part(cell-status) {
302
- justify-content: center; /* Flex alignment */
303
- font-weight: bold;
304
- text-align: center;
305
- }
306
-
307
- /* Set a specific width or background for the ID column */
308
- yatl-table::part(cell-id) {
309
- background-color: #f1f5f9;
310
- font-family: monospace;
311
- }
312
- ```
313
-
314
- #### Conditional Row Styling
315
-
316
- You can style rows based on their data using the rowParts property in JavaScript combined with CSS.
317
-
318
- ```js
319
- const table = document.querySelector('yatl-table');
320
-
321
- // Return a string (or array of strings) to add to the row's parts
322
- table.rowParts = row => {
323
- const parts = [];
324
- if (row.stock < 5) parts.push('low-stock');
325
- if (row.price > 1000) parts.push('expensive');
326
- return parts;
327
- };
328
- ```
329
-
330
- ```css
331
- /* Style rows tagged as 'low-stock' */
332
- yatl-table::part(low-stock) {
333
- background-color: #fef2f2; /* Light red */
334
- border-left: 4px solid #ef4444;
335
- }
336
-
337
- /* Style rows tagged as 'expensive' */
338
- yatl-table::part(expensive) {
339
- color: #0f172a;
340
- font-weight: 600;
341
- }
342
- ```
343
-
344
- #### Customizing the Footer
345
-
346
- ```css
347
- yatl-table::part(footer) {
348
- background-color: #1e293b;
349
- color: white;
350
- padding: 1rem;
351
- }
352
- ```
353
-
354
- ### Virtual Scroll
355
-
356
- Virtual scrolling is used to render only the rows that are visible (with some extras before and after). This allows the library to support tables with hundreads of thousands of rows without issue. This is done using `lit-virtualizer` and requires it's parent enforce a height. To do this you can simply add a height to the table.
357
-
358
- ```html
359
- <body>
360
- <yatl-table style="height: 500px;"></yatl-table>
361
- </body>
362
- ```
363
-
364
- Most of the time this isn't ideal though and instead we'd like to let the layout work it's magic. To do this, it's best to wrap the table in an element that can enforce a height.
365
-
366
- ```html
367
- <body style="height: 100vh;">
368
- <div style="display: flex;">
369
- <div>... Lot's of cool table controls or filters</div>
370
- <yatl-table style="flex-grow: 1;"></yatl-table>
371
- <div>... Some boring footer info or something</div>
372
- </div>
373
- </body>
374
- ```