@shotleybuilder/svelte-gridlite-kit 0.1.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/README.md +260 -0
- package/dist/GridLite.svelte +1361 -0
- package/dist/GridLite.svelte.d.ts +42 -0
- package/dist/components/CellContextMenu.svelte +209 -0
- package/dist/components/CellContextMenu.svelte.d.ts +28 -0
- package/dist/components/ColumnMenu.svelte +234 -0
- package/dist/components/ColumnMenu.svelte.d.ts +29 -0
- package/dist/components/ColumnPicker.svelte +403 -0
- package/dist/components/ColumnPicker.svelte.d.ts +29 -0
- package/dist/components/FilterBar.svelte +390 -0
- package/dist/components/FilterBar.svelte.d.ts +38 -0
- package/dist/components/FilterCondition.svelte +643 -0
- package/dist/components/FilterCondition.svelte.d.ts +35 -0
- package/dist/components/GroupBar.svelte +463 -0
- package/dist/components/GroupBar.svelte.d.ts +33 -0
- package/dist/components/RowDetailModal.svelte +213 -0
- package/dist/components/RowDetailModal.svelte.d.ts +25 -0
- package/dist/components/SortBar.svelte +232 -0
- package/dist/components/SortBar.svelte.d.ts +30 -0
- package/dist/components/SortCondition.svelte +129 -0
- package/dist/components/SortCondition.svelte.d.ts +30 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +29 -0
- package/dist/query/builder.d.ts +160 -0
- package/dist/query/builder.js +432 -0
- package/dist/query/live.d.ts +50 -0
- package/dist/query/live.js +118 -0
- package/dist/query/schema.d.ts +30 -0
- package/dist/query/schema.js +75 -0
- package/dist/state/migrations.d.ts +29 -0
- package/dist/state/migrations.js +113 -0
- package/dist/state/views.d.ts +54 -0
- package/dist/state/views.js +130 -0
- package/dist/styles/gridlite.css +966 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.js +2 -0
- package/dist/utils/filters.d.ts +14 -0
- package/dist/utils/filters.js +49 -0
- package/dist/utils/formatters.d.ts +16 -0
- package/dist/utils/formatters.js +39 -0
- package/dist/utils/fuzzy.d.ts +47 -0
- package/dist/utils/fuzzy.js +142 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# svelte-gridlite-kit
|
|
2
|
+
|
|
3
|
+
A SQL-native data grid component library for Svelte and SvelteKit, powered by [PGLite](https://pglite.dev/) (Postgres in the browser via WASM).
|
|
4
|
+
|
|
5
|
+
Where traditional table libraries operate on in-memory JavaScript arrays, svelte-gridlite-kit treats a real SQL database as the table engine. Filtering becomes `WHERE` clauses. Sorting becomes `ORDER BY`. Grouping becomes `GROUP BY` with real aggregation functions. Config and view state persist in PGLite tables backed by IndexedDB — no localStorage serialization.
|
|
6
|
+
|
|
7
|
+
## Status
|
|
8
|
+
|
|
9
|
+
**Beta.** Published to npm as `@shotleybuilder/svelte-gridlite-kit`.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @shotleybuilder/svelte-gridlite-kit @electric-sql/pglite
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```svelte
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { onMount } from 'svelte';
|
|
22
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
23
|
+
import { live } from '@electric-sql/pglite/live';
|
|
24
|
+
import { GridLite } from '@shotleybuilder/svelte-gridlite-kit';
|
|
25
|
+
import '@shotleybuilder/svelte-gridlite-kit/styles';
|
|
26
|
+
|
|
27
|
+
let db = null;
|
|
28
|
+
let ready = false;
|
|
29
|
+
|
|
30
|
+
onMount(async () => {
|
|
31
|
+
db = new PGlite({ extensions: { live } });
|
|
32
|
+
|
|
33
|
+
await db.exec(`
|
|
34
|
+
CREATE TABLE IF NOT EXISTS contacts (
|
|
35
|
+
id SERIAL PRIMARY KEY,
|
|
36
|
+
name TEXT NOT NULL,
|
|
37
|
+
email TEXT,
|
|
38
|
+
company TEXT,
|
|
39
|
+
created_at DATE DEFAULT CURRENT_DATE
|
|
40
|
+
)
|
|
41
|
+
`);
|
|
42
|
+
|
|
43
|
+
// Insert some data...
|
|
44
|
+
ready = true;
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
{#if ready && db}
|
|
49
|
+
<GridLite
|
|
50
|
+
{db}
|
|
51
|
+
table="contacts"
|
|
52
|
+
config={{
|
|
53
|
+
id: 'my-contacts-grid',
|
|
54
|
+
columns: [
|
|
55
|
+
{ name: 'name', label: 'Name' },
|
|
56
|
+
{ name: 'email', label: 'Email' },
|
|
57
|
+
{ name: 'company', label: 'Company' },
|
|
58
|
+
{ name: 'created_at', label: 'Created' }
|
|
59
|
+
],
|
|
60
|
+
pagination: { pageSize: 25 }
|
|
61
|
+
}}
|
|
62
|
+
features={{
|
|
63
|
+
filtering: true,
|
|
64
|
+
sorting: true,
|
|
65
|
+
grouping: true,
|
|
66
|
+
pagination: true,
|
|
67
|
+
globalSearch: true,
|
|
68
|
+
rowDetail: true
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
{/if}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
> **SvelteKit note:** PGLite requires browser APIs (WebAssembly, IndexedDB). Disable SSR for pages that use it:
|
|
75
|
+
>
|
|
76
|
+
> ```typescript
|
|
77
|
+
> // +layout.ts or +page.ts
|
|
78
|
+
> export const ssr = false;
|
|
79
|
+
> ```
|
|
80
|
+
>
|
|
81
|
+
> Also add to your `vite.config.ts`:
|
|
82
|
+
>
|
|
83
|
+
> ```typescript
|
|
84
|
+
> optimizeDeps: {
|
|
85
|
+
> exclude: ['@electric-sql/pglite']
|
|
86
|
+
> }
|
|
87
|
+
> ```
|
|
88
|
+
|
|
89
|
+
## Guides
|
|
90
|
+
|
|
91
|
+
Structured reference docs for every feature, designed to be both human-readable and AI-agent-friendly:
|
|
92
|
+
|
|
93
|
+
- **[Quick Start](.claude/skills/quick-start/SKILL.md)** — Install, PGLite init, minimal component, SvelteKit config
|
|
94
|
+
- **[Props API](.claude/skills/props-api/SKILL.md)** — Complete prop reference with types, defaults, examples
|
|
95
|
+
- **[Filtering](.claude/skills/filtering/SKILL.md)** — FilterBar, operators by type, programmatic filter control
|
|
96
|
+
- **[Sorting & Grouping](.claude/skills/sorting-grouping/SKILL.md)** — SortBar, GroupBar, multi-level grouping, aggregations
|
|
97
|
+
- **[Column Management](.claude/skills/column-management/SKILL.md)** — Visibility, resizing, reordering, ColumnPicker
|
|
98
|
+
- **[Pagination & Search](.claude/skills/pagination-search/SKILL.md)** — Page size, global search, SQL implementation
|
|
99
|
+
- **[Styling](.claude/skills/styling/SKILL.md)** — Row height, column spacing, toolbar layouts, custom classes
|
|
100
|
+
- **[State & Callbacks](.claude/skills/state-callbacks/SKILL.md)** — onStateChange, GridState, view persistence
|
|
101
|
+
- **[Recipes](.claude/skills/recipes/SKILL.md)** — Custom formatters, raw query mode, common integration patterns
|
|
102
|
+
|
|
103
|
+
## Examples
|
|
104
|
+
|
|
105
|
+
Focused, single-feature demo pages in `src/routes/examples/`:
|
|
106
|
+
|
|
107
|
+
| Route | What it shows |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `/examples/minimal` | Zero-config — auto-detected schema, default everything |
|
|
110
|
+
| `/examples/filtering` | FilterBar + programmatic filter buttons |
|
|
111
|
+
| `/examples/grouping` | Hierarchical grouping with aggregations |
|
|
112
|
+
| `/examples/custom-cells` | Currency, date, boolean, rating star formatters |
|
|
113
|
+
| `/examples/raw-query` | JOIN, aggregate, CTE queries via the `query` prop |
|
|
114
|
+
|
|
115
|
+
Run `npm run dev` and visit `http://localhost:5173/examples/minimal` to start.
|
|
116
|
+
|
|
117
|
+
## For AI Agents
|
|
118
|
+
|
|
119
|
+
This library includes structured skill files in `.claude/skills/` optimised for Claude Code and other AI coding assistants. Each skill file covers one topic with:
|
|
120
|
+
|
|
121
|
+
- Quick copy-paste examples
|
|
122
|
+
- Complete prop/type references
|
|
123
|
+
- Common patterns and troubleshooting
|
|
124
|
+
|
|
125
|
+
**To use in a consuming project:** Copy the relevant `.claude/skills/<topic>/SKILL.md` files into your project, or point your AI agent at this repository's `.claude/skills/` directory. See `CLAUDE.md` for additional architectural context and integration guidance.
|
|
126
|
+
|
|
127
|
+
## Origin
|
|
128
|
+
|
|
129
|
+
Forked from [`@shotleybuilder/svelte-table-kit`](https://github.com/shotleybuilder/svelte-table-kit) (v0.15.1), a TanStack Table-based data table library. The architectural shift to PGLite as a local-first data layer meant the in-memory array paradigm and TanStack Table's client-side row models were no longer the right foundation. This is a purpose-built rewrite for the SQL-native stack.
|
|
130
|
+
|
|
131
|
+
See [Architecture](#architecture) below for the full rationale.
|
|
132
|
+
|
|
133
|
+
## Why Not Extend svelte-table-kit?
|
|
134
|
+
|
|
135
|
+
- **Different paradigms.** Array iteration and SQL queries aren't two implementations of the same abstraction — they're fundamentally different data models. Abstracting over both creates a lowest-common-denominator interface that limits both.
|
|
136
|
+
- **PGLite exceeds what FilterCondition can express.** Joins, CTEs, window functions, full-text search, pgvector — none of these work through a `FilterCondition[]` interface.
|
|
137
|
+
- **TanStack Table becomes dead weight.** With `manualFiltering`, `manualSorting`, `manualPagination`, it's just a column definition format and rendering loop.
|
|
138
|
+
- **Config in PGLite is a strict upgrade.** Queryable, syncable, versionable, relational config storage vs flat JSON blobs in localStorage.
|
|
139
|
+
- **svelte-table-kit remains valuable.** Not every project needs a 3MB WASM Postgres. For simple Svelte apps with small in-memory datasets, it's the right tool.
|
|
140
|
+
|
|
141
|
+
## Architecture
|
|
142
|
+
|
|
143
|
+
### Core Principle
|
|
144
|
+
|
|
145
|
+
The component accepts a **PGLite instance + table name** (or a raw SQL query), not a data array. All operations translate to SQL query modifications. PGLite's live queries push reactive updates to the UI.
|
|
146
|
+
|
|
147
|
+
### How Operations Map to SQL
|
|
148
|
+
|
|
149
|
+
| UI Operation | svelte-table-kit (old) | svelte-gridlite-kit |
|
|
150
|
+
|---|---|---|
|
|
151
|
+
| Filtering | `applyFilters()` iterates JS array | `WHERE` clauses |
|
|
152
|
+
| Sorting | TanStack `getSortedRowModel()` | `ORDER BY` |
|
|
153
|
+
| Grouping | TanStack `getGroupedRowModel()` | `GROUP BY` with `SUM`, `AVG`, `COUNT` |
|
|
154
|
+
| Pagination | TanStack `getPaginationRowModel()` | `LIMIT` / `OFFSET` + `SELECT COUNT(*)` |
|
|
155
|
+
| Value suggestions | Scan all rows for unique values | `SELECT DISTINCT` |
|
|
156
|
+
| Numeric range hints | Scan all rows for min/max | `SELECT MIN(), MAX()` |
|
|
157
|
+
| Column type detection | Sample rows and guess | Schema introspection |
|
|
158
|
+
| Config persistence | localStorage JSON | PGLite tables with IndexedDB backing |
|
|
159
|
+
| Global search | String matching across columns | `ILIKE` or full-text search |
|
|
160
|
+
|
|
161
|
+
### Key Design Decisions
|
|
162
|
+
|
|
163
|
+
- **No TanStack Table dependency.** The SQL engine IS the table engine.
|
|
164
|
+
- **PGLite is the state store.** Table configs, view presets, column visibility, sort/filter state — all stored in PGLite tables, persisted automatically via IndexedDB.
|
|
165
|
+
- **FilterBar emits SQL.** Postgres operators (regex, `ILIKE`, date math, JSON paths, FTS) are available natively.
|
|
166
|
+
- **Live queries drive reactivity.** PGLite `live.query()` replaces Svelte writable stores for data. UI auto-updates when underlying data changes.
|
|
167
|
+
- **Column types come from schema introspection**, not data sampling.
|
|
168
|
+
- **ElectricSQL sync is native** for multi-device, offline-first use cases.
|
|
169
|
+
|
|
170
|
+
### Project Structure
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
src/lib/
|
|
174
|
+
├── GridLite.svelte # Main component
|
|
175
|
+
├── index.ts # Public API exports
|
|
176
|
+
├── types.ts # Column metadata, view configs, feature flags
|
|
177
|
+
├── query/
|
|
178
|
+
│ ├── builder.ts # FilterCondition -> SQL WHERE clause builder
|
|
179
|
+
│ ├── live.ts # Svelte store wrapper for PGLite live queries
|
|
180
|
+
│ └── schema.ts # Table schema introspection for column types
|
|
181
|
+
├── state/
|
|
182
|
+
│ ├── views.ts # View configs stored in PGLite tables
|
|
183
|
+
│ └── migrations.ts # Schema definitions for config tables
|
|
184
|
+
├── components/
|
|
185
|
+
│ ├── FilterBar.svelte # Advanced filtering UI
|
|
186
|
+
│ ├── GroupBar.svelte # Multi-level grouping controls
|
|
187
|
+
│ ├── SortBar.svelte # Sort controls
|
|
188
|
+
│ ├── ColumnMenu.svelte # Column context menu
|
|
189
|
+
│ ├── CellContextMenu.svelte # Right-click cell actions
|
|
190
|
+
│ └── RowDetailModal.svelte # Row detail overlay
|
|
191
|
+
├── utils/
|
|
192
|
+
│ ├── fuzzy.ts # Fuzzy search with scoring
|
|
193
|
+
│ └── formatters.ts # Date, currency, number formatters
|
|
194
|
+
└── styles/
|
|
195
|
+
└── gridlite.css # Default styles
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### What Carries Over from svelte-table-kit
|
|
199
|
+
|
|
200
|
+
- **UI components** — FilterBar, GroupBar, SortBar, ColumnMenu, CellContextMenu, RowDetailModal (rendering layer, adapted for SQL-backed data)
|
|
201
|
+
- **Styling system** — rowHeight, columnSpacing, classNames, themes
|
|
202
|
+
- **Feature flags pattern** — boolean toggles for enabling/disabling functionality
|
|
203
|
+
- **AI configuration concept** — TableConfig becomes SQL view definitions
|
|
204
|
+
- **Utilities** — fuzzy search, value formatters
|
|
205
|
+
|
|
206
|
+
### What Gets Rewritten
|
|
207
|
+
|
|
208
|
+
- Data pipeline (SQL queries replace array iteration)
|
|
209
|
+
- State management (PGLite tables replace localStorage)
|
|
210
|
+
- Column type detection (schema introspection replaces data sampling)
|
|
211
|
+
- Value suggestions (`SELECT DISTINCT` replaces row scanning)
|
|
212
|
+
- Pagination (SQL-based)
|
|
213
|
+
- TanStack Table integration layer (removed entirely)
|
|
214
|
+
- Svelte reactive bindings for PGLite live queries (new — no existing Svelte hooks)
|
|
215
|
+
|
|
216
|
+
## Dependencies
|
|
217
|
+
|
|
218
|
+
| Package | Role |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `@electric-sql/pglite` | Postgres WASM engine (~3MB gzipped) |
|
|
221
|
+
| `svelte` | Reactive UI framework |
|
|
222
|
+
| `@sveltejs/kit` | Dev server and packaging (dev only) |
|
|
223
|
+
|
|
224
|
+
## Development
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
npm install # Install dependencies
|
|
228
|
+
npm run dev # Start dev server
|
|
229
|
+
npm run build # Build library
|
|
230
|
+
npm run package # Package for npm
|
|
231
|
+
npm run check # Type checking
|
|
232
|
+
npm test # Run tests
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## PGLite Quick Reference
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
239
|
+
|
|
240
|
+
// Ephemeral (in-memory)
|
|
241
|
+
const db = new PGlite();
|
|
242
|
+
|
|
243
|
+
// Persistent (IndexedDB)
|
|
244
|
+
const db = new PGlite('idb://my-app-db');
|
|
245
|
+
|
|
246
|
+
// Live query (reactive)
|
|
247
|
+
const result = await db.live.query('SELECT * FROM users WHERE active = true');
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
See [PGLite docs](https://pglite.dev/docs/) for full API reference.
|
|
251
|
+
|
|
252
|
+
## Related
|
|
253
|
+
|
|
254
|
+
- [`@shotleybuilder/svelte-table-kit`](https://github.com/shotleybuilder/svelte-table-kit) — In-memory array-based data table for Svelte (TanStack Table)
|
|
255
|
+
- [PGLite](https://pglite.dev/) — Embeddable Postgres with reactive bindings
|
|
256
|
+
- [ElectricSQL](https://electric-sql.com/) — Local-first sync for Postgres
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT
|