@zvndev/yable-vanilla 0.0.0-canary-20260629011348

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present ZVN DEV
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,125 @@
1
+ # @zvndev/yable-vanilla
2
+
3
+ Vanilla JavaScript / DOM renderer for the Yable data table engine.
4
+
5
+ `@zvndev/yable-vanilla` takes a `@zvndev/yable-core` table instance and returns an HTML string you can inject into any container. No framework required.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @zvndev/yable-core @zvndev/yable-vanilla
11
+ ```
12
+
13
+ ## Basic Usage
14
+
15
+ ```typescript
16
+ import { createTable, createColumnHelper } from '@zvndev/yable-core'
17
+ import { renderTable, renderPagination } from '@zvndev/yable-vanilla'
18
+ import '@zvndev/yable-themes'
19
+
20
+ interface Product {
21
+ name: string
22
+ price: number
23
+ stock: number
24
+ }
25
+
26
+ const columnHelper = createColumnHelper<Product>()
27
+ const columns = [
28
+ columnHelper.accessor('name', { header: 'Product' }),
29
+ columnHelper.accessor('price', { header: 'Price', enableSorting: true }),
30
+ columnHelper.accessor('stock', { header: 'Stock' }),
31
+ ]
32
+
33
+ const data: Product[] = [
34
+ { name: 'Widget', price: 9.99, stock: 150 },
35
+ { name: 'Gadget', price: 24.99, stock: 75 },
36
+ ]
37
+
38
+ const table = createTable({
39
+ data,
40
+ columns,
41
+ onStateChange: () => render(), // Re-render on state change
42
+ })
43
+
44
+ function render() {
45
+ const container = document.getElementById('table-container')!
46
+ container.innerHTML =
47
+ renderTable(table, {
48
+ striped: true,
49
+ stickyHeader: true,
50
+ }) + renderPagination(table)
51
+ }
52
+
53
+ render()
54
+ ```
55
+
56
+ > Security note: `renderTable()` returns escaped library output that is intended
57
+ > to be injected as-is. Do not concatenate unescaped user HTML into the returned
58
+ > string before assigning to `innerHTML`.
59
+
60
+ ## API
61
+
62
+ ### `renderTable(table, options?): string`
63
+
64
+ Returns the full table HTML string.
65
+
66
+ **Options:**
67
+
68
+ | Option | Type | Default | Description |
69
+ | --------------- | --------- | ----------- | --------------------------- |
70
+ | `stickyHeader` | `boolean` | `false` | Pin header row on scroll |
71
+ | `striped` | `boolean` | `false` | Alternate row backgrounds |
72
+ | `bordered` | `boolean` | `false` | Add cell borders |
73
+ | `compact` | `boolean` | `false` | Reduce padding |
74
+ | `theme` | `string` | -- | Theme class name suffix |
75
+ | `clickableRows` | `boolean` | `false` | Add clickable row styling |
76
+ | `footer` | `boolean` | `false` | Render table footer |
77
+ | `emptyMessage` | `string` | `"No data"` | Text when there are no rows |
78
+
79
+ ### `renderPagination(table, options?): string`
80
+
81
+ Returns pagination controls as an HTML string.
82
+
83
+ **Options:**
84
+
85
+ | Option | Type | Default | Description |
86
+ | -------------- | ---------- | ------------------- | ----------------------- |
87
+ | `showPageSize` | `boolean` | `true` | Show page size dropdown |
88
+ | `pageSizes` | `number[]` | `[10, 20, 50, 100]` | Available page sizes |
89
+ | `showInfo` | `boolean` | `true` | Show row count info |
90
+
91
+ ## Event Wiring
92
+
93
+ The rendered HTML uses `data-yable-*` attributes for event delegation. You wire up interactivity by attaching listeners to the container:
94
+
95
+ ```typescript
96
+ container.addEventListener('click', (e) => {
97
+ const target = e.target as HTMLElement
98
+
99
+ // Sort on header click
100
+ const columnId = target.closest('[data-yable-sortable="true"]')?.getAttribute('data-yable-column')
101
+ if (columnId) {
102
+ const column = table.getColumn(columnId)
103
+ column?.toggleSorting()
104
+ render()
105
+ }
106
+
107
+ // Pagination
108
+ const page = target.closest('[data-yable-page]')?.getAttribute('data-yable-page')
109
+ if (page === 'prev') table.previousPage()
110
+ else if (page === 'next') table.nextPage()
111
+ else if (page === 'first') table.firstPage()
112
+ else if (page === 'last') table.lastPage()
113
+ else if (page) table.setPageIndex(Number(page))
114
+
115
+ render()
116
+ })
117
+ ```
118
+
119
+ ## Editing Support
120
+
121
+ The renderer automatically outputs form elements (`<input>`, `<select>`, `<input type="checkbox">`) for cells in edit mode. Use `data-yable-input` and `data-yable-input-row` attributes to wire change events back to the table's `setPendingValue()` method.
122
+
123
+ ## License
124
+
125
+ MIT