@coding_doc/sveltedt 0.0.0 → 0.1.0-rehearsal.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +52 -0
  3. package/README.md +618 -2
  4. package/dist/DataTable.svelte +313 -0
  5. package/dist/DataTable.svelte.d.ts +26 -0
  6. package/dist/Pagination.svelte +125 -0
  7. package/dist/Pagination.svelte.d.ts +5 -0
  8. package/dist/checks.d.ts +5 -0
  9. package/dist/checks.js +7 -0
  10. package/dist/connection/answer.d.ts +6 -0
  11. package/dist/connection/answer.js +47 -0
  12. package/dist/connection/connection.svelte.d.ts +16 -0
  13. package/dist/connection/connection.svelte.js +214 -0
  14. package/dist/connection/index.d.ts +8 -0
  15. package/dist/connection/index.js +7 -0
  16. package/dist/connection/request.d.ts +4 -0
  17. package/dist/connection/request.js +71 -0
  18. package/dist/connection/types.d.ts +182 -0
  19. package/dist/connection/types.js +1 -0
  20. package/dist/faults.d.ts +6 -0
  21. package/dist/faults.js +64 -0
  22. package/dist/filters.d.ts +23 -0
  23. package/dist/filters.js +65 -0
  24. package/dist/index.d.ts +9 -0
  25. package/dist/index.js +8 -0
  26. package/dist/messages.d.ts +4 -0
  27. package/dist/messages.js +62 -0
  28. package/dist/pager.d.ts +19 -0
  29. package/dist/pager.js +80 -0
  30. package/dist/parts/ColumnFilter.svelte +213 -0
  31. package/dist/parts/ColumnFilter.svelte.d.ts +11 -0
  32. package/dist/parts/HeaderCell.svelte +90 -0
  33. package/dist/parts/HeaderCell.svelte.d.ts +34 -0
  34. package/dist/parts/Search.svelte +79 -0
  35. package/dist/parts/Search.svelte.d.ts +9 -0
  36. package/dist/parts/Toolbar.svelte +70 -0
  37. package/dist/parts/Toolbar.svelte.d.ts +29 -0
  38. package/dist/picks.svelte.d.ts +6 -0
  39. package/dist/picks.svelte.js +42 -0
  40. package/dist/search.svelte.d.ts +15 -0
  41. package/dist/search.svelte.js +76 -0
  42. package/dist/sort.d.ts +6 -0
  43. package/dist/sort.js +32 -0
  44. package/dist/styles.css +230 -0
  45. package/dist/types.d.ts +323 -0
  46. package/dist/types.js +1 -0
  47. package/dist/validate.d.ts +5 -0
  48. package/dist/validate.js +201 -0
  49. package/dist/view.svelte.d.ts +7 -0
  50. package/dist/view.svelte.js +75 -0
  51. package/package.json +83 -3
package/README.md CHANGED
@@ -1,3 +1,619 @@
1
- # @coding_doc/sveltedt
1
+ # SvelteDT
2
2
 
3
- Name reserved for SvelteDT, a data table component for Svelte 5. The first release is in development: https://github.com/hniedner/sveltedt
3
+ [![CI](https://github.com/hniedner/sveltedt/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/hniedner/sveltedt/actions/workflows/ci.yml?query=branch%3Amain)
4
+ [![CodeQL](https://github.com/hniedner/sveltedt/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/hniedner/sveltedt/actions/workflows/github-code-scanning/codeql)
5
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/hniedner/sveltedt/badge)](https://scorecard.dev/viewer/?uri=github.com/hniedner/sveltedt)
6
+ [![licence](https://img.shields.io/github/license/hniedner/sveltedt)](LICENSE)
7
+ [![tested with Svelte](https://img.shields.io/github/package-json/dependency-version/hniedner/sveltedt/dev/svelte?label=tested%20with%20Svelte)](package.json)
8
+ [![TypeScript](https://img.shields.io/github/package-json/dependency-version/hniedner/sveltedt/dev/typescript?label=TypeScript)](package.json)
9
+
10
+ A data table for Svelte 5 (5.57.1 or later), inspired by DataTables, built to be accessible and usable under a strict content-security
11
+ policy.
12
+
13
+ SvelteDT brings the utility of DataTables (datatables.net) to Svelte 5: a data table for server-side and client-side
14
+ data, built idiomatically for Svelte with components, props, callbacks and snippets rather than as an imitation of
15
+ DataTables' JavaScript API. It is styled by one stylesheet and prefixed tokens that work with any CSS approach, Tailwind
16
+ 4 included. Two adoption paths are first-class: a new project, and a project migrating from DataTables, which keeps its
17
+ server-side backend working through a connection helper and maps its options with a migration guide. SvelteDT is an
18
+ independent project, not affiliated with or endorsed by DataTables.
19
+
20
+ ## Quick start
21
+
22
+ Nothing usable is published yet (0.0.0 only holds the name): these steps work once 0.1.0 is on npm. The package is `@coding_doc/sveltedt` (npm refused the
23
+ bare name `sveltedt` as too similar to an existing package); if npm grants the bare name later, the package moves there
24
+ and `@coding_doc/sveltedt` is deprecated with a pointer to it. Every block below that is a file of the
25
+ [consumer project](consumer/), a SvelteKit app the tests install the packed package into and run in Chromium, Firefox
26
+ and WebKit, is checked to equal that file, so the code runs as shown.
27
+
28
+ Add the package to a SvelteKit app (SvelteKit bundles development dependencies into the app's server build):
29
+
30
+ ```sh
31
+ pnpm add -D @coding_doc/sveltedt
32
+ ```
33
+
34
+ Import the stylesheet once. In an application without Tailwind, import it in the root layout:
35
+
36
+ ```js
37
+ import "@coding_doc/sveltedt/styles.css";
38
+ ```
39
+
40
+ The consumer project has no app without Tailwind yet, so no test runs that line. In a Tailwind 4 application, import
41
+ it into the components layer of the main CSS file, `src/app.css`, after Tailwind:
42
+
43
+ <!-- quick start: consumer/src/app.css -->
44
+
45
+ ```css
46
+ @import "tailwindcss";
47
+ @import "@coding_doc/sveltedt/styles.css" layer(components);
48
+ ```
49
+
50
+ and import that file in the root layout, `src/routes/+layout.svelte`:
51
+
52
+ <!-- quick start: consumer/src/routes/+layout.svelte -->
53
+
54
+ ```svelte
55
+ <script lang="ts">
56
+ import type { Snippet } from "svelte";
57
+ import "../app.css";
58
+
59
+ let { children }: { children: Snippet } = $props();
60
+ </script>
61
+
62
+ {@render children()}
63
+ ```
64
+
65
+ A first table, `src/routes/+page.svelte`, with a sortable column and a pager:
66
+
67
+ <!-- quick start: consumer/src/routes/+page.svelte -->
68
+
69
+ ```svelte
70
+ <script lang="ts">
71
+ import { DataTable, Pagination } from "@coding_doc/sveltedt";
72
+ import type {
73
+ DataTableColumn,
74
+ DataTableSortEntry,
75
+ } from "@coding_doc/sveltedt";
76
+ import { orders } from "../lib/orders.ts";
77
+ import type { Order } from "../lib/orders.ts";
78
+
79
+ const columns: DataTableColumn<Order>[] = [
80
+ {
81
+ id: "name",
82
+ label: "Order",
83
+ value: ({ row }) => row.name,
84
+ sortable: ["asc", "desc"],
85
+ },
86
+ ];
87
+
88
+ // The table shows the rows it is given and reports what the user asks for; the page sorts and pages them.
89
+ let sort = $state<DataTableSortEntry[]>([]);
90
+ let offset = $state(0);
91
+ let limit = $state(25);
92
+
93
+ function onsort(next: DataTableSortEntry[]): void {
94
+ sort = next;
95
+ offset = 0;
96
+ }
97
+ function onpage(next: number): void {
98
+ offset = next;
99
+ }
100
+ function onsize(next: number): void {
101
+ offset -= offset % next;
102
+ limit = next;
103
+ }
104
+
105
+ const sorted = $derived(
106
+ sort[0] === undefined
107
+ ? orders
108
+ : orders.toSorted(
109
+ (a, b) =>
110
+ a.name.localeCompare(b.name) *
111
+ (sort[0]?.direction === "desc" ? -1 : 1),
112
+ ),
113
+ );
114
+ const visible = $derived(sorted.slice(offset, offset + limit));
115
+ </script>
116
+
117
+ <DataTable
118
+ rows={visible}
119
+ {columns}
120
+ getRowId={({ row }) => row.id}
121
+ caption="Orders"
122
+ regionLabel="Orders"
123
+ {sort}
124
+ {onsort}
125
+ />
126
+ <Pagination
127
+ {offset}
128
+ {limit}
129
+ total={sorted.length}
130
+ sizes={[10, 25]}
131
+ label="Orders pages"
132
+ {onpage}
133
+ {onsize}
134
+ />
135
+ ```
136
+
137
+ Its rows, `src/lib/orders.ts`:
138
+
139
+ <!-- quick start: consumer/src/lib/orders.ts -->
140
+
141
+ ```ts
142
+ // 20 example orders, in no particular order. Your rows come from your own data; each needs a unique, stable id.
143
+ export interface Order {
144
+ id: string;
145
+ name: string;
146
+ }
147
+
148
+ const NUMBERS = "07 03 15 01 20 11 05 18 09 13 02 17 06 14 10 19 04 12 16 08";
149
+
150
+ export const orders: readonly Order[] = NUMBERS.split(" ").map((number) => ({
151
+ id: `o${number}`,
152
+ name: `Order ${number}`,
153
+ }));
154
+ ```
155
+
156
+ The table keeps no copy of the data: it shows the rows, the sort and the page it is given, and reports what the user
157
+ asks for through `onsort`, `onpage` and `onsize`; the page answers. With a server, the server sorts and pages instead,
158
+ and the connection helper (`@coding_doc/sveltedt/connection`, below) turns those requests into DataTables server-side
159
+ requests and their answers back into rows, as the next section shows. Tokens, colours and classes are in
160
+ [the styling guide](docs/styling.md).
161
+
162
+ ## Connect a server
163
+
164
+ The connection helper sends the table's requests in the form of DataTables' server-side processing, so a backend
165
+ that already answers DataTables keeps working. This page of the consumer project, `src/routes/connection/+page.svelte`,
166
+ loads its rows from a route of its own, five to a page, with the global search and a text filter on the Order column:
167
+
168
+ <!-- quick start: consumer/src/routes/connection/+page.svelte -->
169
+
170
+ ```svelte
171
+ <script lang="ts">
172
+ import { DataTable, Pagination } from "@coding_doc/sveltedt";
173
+ import type { DataTableColumn } from "@coding_doc/sveltedt";
174
+ import { createConnection } from "@coding_doc/sveltedt/connection";
175
+ import type { Order } from "../../lib/orders.ts";
176
+
177
+ const columns: DataTableColumn<Order>[] = [
178
+ {
179
+ id: "name",
180
+ label: "Order",
181
+ value: ({ row }) => row.name,
182
+ filter: { kind: "text" },
183
+ },
184
+ ];
185
+
186
+ // The transport: the request goes to the route beside this page; a non-2xx answer or a body that is not JSON
187
+ // rejects, and the table then shows its failed state.
188
+ async function send({
189
+ request,
190
+ signal,
191
+ }: {
192
+ request: URLSearchParams;
193
+ signal: AbortSignal;
194
+ }): Promise<unknown> {
195
+ const answer = await fetch(`/connection/orders?${request}`, { signal });
196
+ if (!answer.ok) throw new Error(`The route answered ${answer.status}.`);
197
+ return answer.json();
198
+ }
199
+
200
+ // Entry i of this list is the server's column i; `id` names the table column it serves.
201
+ const connection = createConnection<Order>({
202
+ send,
203
+ columns: [
204
+ { data: "id", name: "id" },
205
+ { data: "name", name: "name", id: "name" },
206
+ ],
207
+ query: { limit: 5 },
208
+ onerror: (error) => console.error(error),
209
+ });
210
+ </script>
211
+
212
+ <DataTable
213
+ rows={connection.table.rows}
214
+ {columns}
215
+ getRowId={({ row }) => row.id}
216
+ caption="Orders"
217
+ regionLabel="Orders"
218
+ status={connection.table.status}
219
+ busy={connection.table.busy}
220
+ search={connection.table.search}
221
+ onsearch={connection.table.onsearch}
222
+ filters={connection.table.filters}
223
+ onfilter={connection.table.onfilter}
224
+ onclearfilter={connection.table.onclearfilter}
225
+ onclearfilters={connection.table.onclearfilters}
226
+ onreset={connection.table.onreset}
227
+ oncancel={connection.table.oncancel}
228
+ onretry={connection.table.onretry}
229
+ />
230
+ {#if connection.pager}
231
+ <Pagination
232
+ offset={connection.pager.offset}
233
+ limit={connection.pager.limit}
234
+ total={connection.pager.total}
235
+ unfilteredTotal={connection.pager.unfilteredTotal}
236
+ onpage={connection.pager.onpage}
237
+ onsize={connection.pager.onsize}
238
+ label="Orders pages"
239
+ />
240
+ {/if}
241
+ ```
242
+
243
+ The route, `src/routes/connection/orders/+server.ts`, stands in for your backend:
244
+
245
+ <!-- quick start: consumer/src/routes/connection/orders/+server.ts -->
246
+
247
+ ```ts
248
+ // A DataTables server-side route over the 20 example orders: it reads the request the connection helper sends,
249
+ // matches the global search and the Order column's search as text that the name contains, ignoring case, and answers
250
+ // one page of the matching rows. Your route queries your own data store instead.
251
+ import { error, json } from "@sveltejs/kit";
252
+ import type { RequestHandler } from "@sveltejs/kit";
253
+ import { orders } from "../../../lib/orders.ts";
254
+
255
+ // A whole number written in one to nine digits, as a number; undefined for anything else
256
+ function whole(text: string | null): number | undefined {
257
+ return text !== null && /^\d{1,9}$/.test(text) ? Number(text) : undefined;
258
+ }
259
+
260
+ export const GET: RequestHandler = ({ url }) => {
261
+ const query = url.searchParams;
262
+ const draw = whole(query.get("draw"));
263
+ const start = whole(query.get("start"));
264
+ const length = whole(query.get("length"));
265
+ // Refuse what the page never sends, a page of more than 100 rows included
266
+ if (draw === undefined || start === undefined || !length || length > 100)
267
+ error(400, "Invalid paging.");
268
+ const search = (query.get("search[value]") ?? "").toLowerCase();
269
+ const name = (query.get("columns[1][search][value]") ?? "").toLowerCase();
270
+ const matching = orders.filter((order) => {
271
+ const text = order.name.toLowerCase();
272
+ return text.includes(search) && text.includes(name);
273
+ });
274
+ return json({
275
+ draw,
276
+ recordsTotal: orders.length,
277
+ recordsFiltered: matching.length,
278
+ data: matching.slice(start, start + length),
279
+ });
280
+ };
281
+ ```
282
+
283
+ The search goes out as `search[value]`, the Order column's filter as `columns[1][search][value]`, each as the text
284
+ the user applied; the page as `start` and `length`. The answer holds `draw` as sent, `recordsTotal` (all rows),
285
+ `recordsFiltered` (the rows that match) and `data` (the rows of the page).
286
+
287
+ Everything in the request comes from the browser, and anyone can send it by hand. When your route reads a database,
288
+ pass the search texts as bound parameters, never as part of the query's text; take a sort column by its index from a
289
+ list of columns your server holds, never by the name the request sends; never run a pattern the request sends (a
290
+ categorical filter sends one with `regex=true`) without a limit on its cost; cap the page size, as this route does at
291
+ 100; and check access as on every other route of your app.
292
+
293
+ A server refuses what it cannot answer, such as an invalid page or a filter it does not accept, in one of two ways:
294
+ with an HTTP error status, as this route does, or with HTTP 200 and an answer whose `error` is set. The helper reports
295
+ either once to `onerror`, and the table shows its failed state with "Try again"; no text from the server is shown.
296
+ For words of your own, pass the text you choose as `messages.failed` of `DataTable`. To choose by the kind of failure,
297
+ read it in `onerror`: an answer with `error` arrives as an error whose `code` is the answer's `errorCode` when that is
298
+ a string, else `null`; an HTTP error arrives as what your `send` throws, so give that error what you need (this page's
299
+ `send` throws a plain `Error` that names the status). The full guide for server implementers comes after 0.1.0.
300
+
301
+ ## Status: pre-release
302
+
303
+ Nothing usable is published yet (0.0.0 only holds the name). What is on `main` today:
304
+
305
+ - the read-only table: rows in the order given, text or snippet cells, a caption and a labelled region; every
306
+ function and snippet it calls for a row or a cell takes one object (`value({ row })`, `getRowId({ row })`, a
307
+ `cell` snippet's `{ row, column }`);
308
+ - the wide table: the region scrolls sideways when the table is wider than it, and only then is a Tab stop, so the
309
+ arrow keys scroll it once it has focus; its focus indicator is the browser's own ring, the caption is hidden visually
310
+ and still names the table, hovering or focusing shows nothing new, and Tab follows the reading order (heading
311
+ controls, actions, the region, then the cells row by row). Proved in Chromium, Firefox and WebKit on the test site's
312
+ table page (`/table.html`). axe finds no serious or critical violation in the loading, failed, empty, ready, busy,
313
+ focused-region and invalid-input states, there and on `/table-plain.html` (the package stylesheet, the site's layout
314
+ rules and no token), whose focus ring also shows; axe's incomplete (undecidable) items are left to manual review.
315
+ Mounting, new rows, state changes and unmounting leave the window where it was (observed for two frames).
316
+ Limits: "loading" is read at whatever moment the real clock gives (A11Y-25 owns its sub-states); a focused region that
317
+ stops overflowing loses its Tab stop and focus is not moved (not tested); the stop follows widths, not the
318
+ stylesheet (without the package stylesheet the region is no scroll container, yet a table wider than it still makes
319
+ it a stop); a height cap on the region is not supported (the region
320
+ would scroll vertically without a stop); without `ResizeObserver` (a jsdom test) the region is never a stop;
321
+ - the alert for invalid input (an empty caption, missing or duplicate column ids and labels, columns, or rows while
322
+ ready, that are not a list, empty, duplicate or unreadable row ids), shown instead of a wrong table;
323
+ - row ids that are strings or finite numbers, as server JSON gives them;
324
+ - the loading, failed and busy states: the loading text in a status element, the failure in an alert, `aria-busy`
325
+ on the table, the rows kept while busy, and the row count in a polite live region, its digits grouped the
326
+ English way ("1,000") whatever the runtime's locale;
327
+ - the stopped state: `status="stopped"` shows "Loading stopped" in one cell where the rows would be, with the header
328
+ kept and no empty message, as plain text and not as an alert;
329
+ - slow loads: after 1 second of loading or busy the table adds a progress indicator element, hidden from assistive
330
+ technology and kept at least 500 ms, drawn as a bar along the foot of the status line that pulses (grows from its
331
+ centre once a second) for 5 seconds and then rests full (it rests from the start under `prefers-reduced-motion`), and
332
+ after 5 more seconds the status element also says "Still loading", added once for screen readers. From the first load
333
+ or refetch until it unmounts the table keeps a status line above the region. Once that line has appeared, the
334
+ indicator, "Still loading" and "Cancel" can appear and go, and a load that ends in a ready answer can take them away,
335
+ without moving the table. A table that never loads has no status line; any other table moves down once, by at most the
336
+ height of that line, when its first load or refetch starts (measured for a table mounted ready; for one mounted in
337
+ another state the move is that line less what it replaces, not browser-proved). A load that ends in failure adds a
338
+ line: the failed notice, an element with `role="alert"`, sits between the status line and the region. Limits: the
339
+ words and "Cancel" sit on one line while they fit, and "Cancel" wraps in a line too narrow for both; an application
340
+ style that makes "Cancel" taller than the line moves the table; a second press at the same spot, made right after the
341
+ press that starts the first load or refetch, lands on what is now one line above the control it aimed at, because that
342
+ control moved down. Proved in Chromium, Firefox and WebKit on the test site's slow-load page, except the last limit
343
+ and the move of a table mounted in another state;
344
+ - the two buttons of a slow load: with `oncancel` a "Cancel" button after the status element while "Still loading"
345
+ shows, and with `onretry` a "Try again" button after the stopped or failed table, never beside the invalid-input
346
+ alert; a press calls its callback once with no argument, ignores what it returns, and changes nothing on screen
347
+ by itself (a double press calls it twice); the status element also says "Loading stopped" once when `status` becomes
348
+ `stopped`. When new props remove a focused "Cancel" or "Try again", focus moves to the table without scrolling
349
+ (proved in Chromium, Firefox and WebKit on the test site's slow-load page), and the table can take focus only until
350
+ focus leaves it. If the window loses focus right after the move, for example when the user switches window, the table
351
+ gives up that focus while it is still the active element and focus lands on the page body. With invalid input there is
352
+ no table, so a focused button that goes then leaves focus on the page body. "Cancel" takes no focus when it appears
353
+ and "Try again" none when it appears or returns; Tab reaches "Try again" after the actions, and "Cancel" after the
354
+ actions and before the controls in the cells; axe finds no serious or critical violation in the long-loading, busy,
355
+ stopped and failed states, on `/slow.html` and with no token defined on `/slow-plain.html` (proved in Chromium,
356
+ Firefox and WebKit);
357
+ - the four words of a slow load ("Still loading", "Cancel", "Loading stopped", "Try again") as the `messages` keys
358
+ `stillLoading`, `cancel`, `stopped` and `retry`, shown as plain text;
359
+ - every fixed word as a `messages` prop with an English default;
360
+ - sort by column header: a click emits the next whole order through `onsort`, Shift+click adds a column, the
361
+ table shows the order it is given (`aria-sort` on the lead column, a hidden direction mark and rank, a button named
362
+ by its label and described, and a hidden sentence in the caption that says the headers are buttons), and invalid
363
+ sort input gets the alert; the test site's list page sorts its Order column;
364
+ - sort by keyboard: Enter and Space press the focused sort button, Shift+Enter and Shift+Space add a column, and
365
+ focus stays on the button while the new order loads, proved in Chromium, Firefox and WebKit on the test site's
366
+ sort page (`/sort.html`) with an axe check of the sort controls; the focused sort button shows the browser's focus
367
+ ring, and with no token defined (`/sort-plain.html`, the package stylesheet alone) axe still finds no serious or
368
+ critical violation and the ring still shows;
369
+ - the pager core, a separate `Pagination` component: a labelled `nav` with step buttons and at most seven page
370
+ places (gaps hidden from assistive technology), `aria-current` on the current page, steps that cannot move
371
+ marked `aria-disabled`, a press emitting the page's offset through `onpage`, an optional page-size select
372
+ emitting through `onsize`, and for invalid input one fixed alert ("Page navigation cannot be shown.", the
373
+ `messages` key `invalidInput`) with the cause written once to the console as a code, its English text in
374
+ development builds only. The test site's list page pages its rows with it. Proved in Chromium, Firefox and
375
+ WebKit on the test site's pager page (`/pager.html`): the places of 2^53 - 1 pages show within one second; focus
376
+ stays on the step button, the page number or the page-size select once the new offset or size arrives; the
377
+ select's name is visible text; mounting, paging and unmounting leave the window where it was; hovering or
378
+ focusing a control makes nothing appear; every control shows a visible focus indicator when focused by keyboard;
379
+ axe finds no serious or critical violation with 20 pages, with none, and on the alert; with no token defined
380
+ (`/pager-plain.html`, the package stylesheet alone) axe still finds none and the indicator still shows;
381
+ - the pager's information line ("Showing 1 to 10 of 57 rows", with "(filtered from 1,000 total rows)" when an
382
+ unfiltered total is given and differs), plain text between the page-size select and the step buttons and not
383
+ announced, and every fixed word of the pager as a `messages` prop with an English default;
384
+ - the global search field, shown while `onsearch` is given and the alert is not showing, after the `actions` snippet
385
+ and before the filter badges and the `panels` snippet. It emits through `onsearch` after the `searchDelay` pause, at
386
+ once on Enter, or on Enter only with `searchOnEnter`, and then says "Press Enter to apply."; the text emitted has no
387
+ leading or trailing white space, while the field keeps what was typed. A text that, trimmed, holds a control
388
+ character or is longer than `maxLength` (255 by default, counted in code points, not bytes) is not emitted: the
389
+ field is marked invalid, with a message of its own for each condition. It shows the applied `search`, and keeps newer typing when `search` changes.
390
+ An application that wants another field leaves out `onsearch` and renders its own, and then has neither the pause,
391
+ the trimming, the refusal nor the newer-typing rule. Enter in the field never submits a `<form>` the table sits in,
392
+ and Enter that ends an input method's composition does not apply the search. Limit: an application that applies
393
+ `search` only after the answer arrives should still pass the new text at once, as the connection helper does;
394
+ - the filter controls, driven by the application's `filters`: a button "Filter <label>" in the header cell of each
395
+ filtered column, which opens the column's filter dialog, a popover named "<label> filter". A text filter's field in
396
+ it emits through `onfilter` by the search field's rules (the pause, at once on Enter, on Enter only with
397
+ `searchOnEnter`, outer white space trimmed and the typed text kept; the field shows the applied text when its
398
+ dialog opens and takes a newer one while nothing new is typed in it; under `searchOnEnter` it is described by "Press
399
+ Enter to apply."; text that, trimmed, holds a control character or is longer than `maxLength` is marked invalid with
400
+ one alert per reason and not emitted; proved in Chromium, Firefox and WebKit on the test site's filter dialog
401
+ page). A categorical filter's dialog offers its options as checkboxes in the given order (with `emptyOption: true` one
402
+ more, "(empty)", last, whose value is `''`), each ticked while `filters` selects it, or while a press `filters` has
403
+ not yet answered selects it; a press emits the next selection's values in the options' order through `onfilter` and
404
+ ticks or unticks its box at once. With more than 10 options, "(empty)" included, a find field "Find <label> options"
405
+ above them narrows the ones shown to those whose label contains its text, ignoring case; it emits nothing, says "No
406
+ options match." when none does (in a status region, for screen readers), and is empty again when the dialog reopens. A
407
+ press made before `filters` answers the last one builds on it, so quick presses add up; the boxes show `filters` again
408
+ once it changes to anything but an earlier press's selection, or when the dialog closes. An application that refuses a
409
+ press, by giving the old selection back or by leaving `filters` as it is, leaves the press shown until the dialog
410
+ closes. When an answer equals a selection pressed earlier than the last one (an application that answers only some
411
+ presses, after three presses of one box), the boxes may keep showing the quick presses until the dialog closes, even
412
+ after `filters` changes from outside to that earlier selection. Text typed and not yet sent (still within the pause,
413
+ or not yet confirmed with Enter under `searchOnEnter`) is dropped when the dialog closes. The filter button's
414
+ `aria-expanded` follows its dialog, and opening a dialog closes any other one and moves focus to its first field.
415
+ Enter on a field of a dialog, other than one that ends an input method's composition, never submits a `<form>`
416
+ the table sits in.
417
+ Escape in the open dialog, or on its button, closes it, returns focus to the button and goes no further: an
418
+ application's own Escape listener on the page never sees it. Tab out of the dialog, or a press outside it, closes it
419
+ (the press still acts on what it hits); a press on its button closes it and keeps focus there; Shift+Tab back to its
420
+ button keeps it open. Focus that goes to no element keeps the dialog open: a switch to another window, and a Tab that
421
+ leaves the page (from the last control, or in Safari, whose Tab skips buttons by default). The dialog is a popover, so
422
+ the region never clips it (all proved in Chromium, Firefox and WebKit on the filter dialog page). A clearable badge
423
+ for each applied filter, whose press moves focus to the column's filter button (proved there too), "Clear column
424
+ filters", "Reset table" (while `onreset` is given) and the application's own `criteria` snippet, every header cell
425
+ named by its column label alone (proved in Chromium, Firefox and WebKit on the test site's filter page), and an
426
+ invalid filter, `search`, `searchDelay` or `maxLength` prop gets the alert;
427
+ - the `panels` snippet, for the application's own panels (an advanced search, batch actions) that a button in its
428
+ `actions` snippet opens: rendered after the toolbar's controls and before the status line, in every state, the
429
+ invalid-input alert's included, with its elements kept when the state changes (proved by component tests). A block
430
+ in it is as wide as the region (proved in Chromium, Firefox and WebKit on the test site's table page). The table
431
+ keeps no open state and adds no toggle: the application decides when a panel shows, and gives its button
432
+ `aria-expanded` and `aria-controls` (the WAI-ARIA disclosure pattern). Limits: inline content sits on the toolbar's
433
+ line, so wrap a panel in a block element; opening or closing a panel moves the status line and the table, as any
434
+ content above them does; with a panel open, Tab reaches "Cancel" only after the panel's controls; the table moves no
435
+ focus when a panel opens or closes (see "A button that opens a panel" below);
436
+ - the connection helper, exported as `@coding_doc/sveltedt/connection`: `createConnection` sends the first request through
437
+ the application's `send({ request, signal })`, maps the answer to rows and totals, and changes page through
438
+ `pager.onpage` with the rows kept while busy. An answer it cannot map (its message names the check that failed), an
439
+ answer with a truthy `error` (the server's text counts), and a `send` that rejects, throws or returns no promise each
440
+ show the failed state and reach `onerror` once, and no server text is shown. An answer's failure carries `code`, a
441
+ string or `null` (the answer's `errorCode` when it is a string); a rejection is your `send`'s own error, passed as it
442
+ is; if your transport's errors carry a string `code` (axios does), tell them apart in `send`. To show your own text
443
+ for a code, pass it as `messages.failed` of `DataTable`. The answer or rejection of a superseded request, or of one
444
+ running at unmount, is dropped, and its signal is aborted. Its sort intent (`table.onsort`) and page-size intent
445
+ (`pager.onsize`) each set the query at once and send one request; so do its filter intents (`table.onfilter`,
446
+ `onclearfilter`, `onclearfilters`) and its search intent (`table.onsearch`), and each of these filter and search
447
+ intents returns to the first page (the page-size intent keeps the page of the first row shown): a text filter and
448
+ the search go out as given, a categorical filter as an anchored alternation of its escaped values with `regex=true`
449
+ (a server that ignores `regex` and matches by substring finds no row), `query.filters` and `query.search` give the
450
+ starting filters and search and are read back as `table.filters` and `table.search`, and `table.onsearch` is the
451
+ `onsearch` of `DataTable`; `table.onreset`, the `onreset` of `DataTable`, sends one request with the starting sort,
452
+ no filter, an empty search and the first page, keeping the page size; `reload()` sends the current query again, the
453
+ page included; `table.oncancel` and `table.onretry` are the `oncancel` and `onretry` of `DataTable`: a cancel aborts
454
+ the running request and drops its answer or rejection, then, with rows on screen, returns the query (sort, filters,
455
+ search, page and page size) to the one those rows were asked with and sends nothing, and with none, shows the
456
+ stopped state and keeps the query; `table.onretry` sends the current query again, as `reload()` does; each column
457
+ map entry can say `searchable` and `orderable`; the request goes out in the bracketed
458
+ form by default, dotted with `form: "dotted"`, or as the plain object with `form: "json"`; and a sort or filter on a
459
+ column id no map entry serves sends nothing and is reported once through `onerror`. Its tests use answers written by
460
+ hand.
461
+ The test site's connection page (`/connection.html`) loads its orders through it from the site's own route
462
+ `/api/orders`, pages them with `Pagination`, sorts them by the Order column and changes the page size, proved in
463
+ Chromium, Firefox and WebKit.
464
+
465
+ Not yet: column features, selection and the published package; see
466
+ [What 0.1.0 does not do yet](#what-010-does-not-do-yet).
467
+
468
+ The badges above show the Svelte and TypeScript versions the tests run with; the package supports Svelte 5.57.1 or a
469
+ later Svelte 5 (its peer range in `package.json`).
470
+
471
+ ## What 0.1.0 does not do yet
472
+
473
+ 0.1.0 is a first release: the server-driven table with sort, pager, search and filters, the connection helper and the
474
+ stylesheet. What it does not do yet is listed here, in the order planned (the
475
+ [milestones](https://github.com/hniedner/sveltedt/milestones)), with the reason each part is absent. After 0.1.0 each
476
+ 0.x minor release adds one feature group. The ids name requirements of the [product requirements](docs/PRD.md); a check
477
+ fails when a required feature that no test names is missing from this list (a feature tested in part is listed by
478
+ hand).
479
+
480
+ Planned, in this order:
481
+
482
+ - **A local data source** (PRD-B21, [#133]), in 0.2: sorting, filtering and paging rows the browser already holds.
483
+ Until then the server, or the application's own code, sorts, filters and pages.
484
+ - **The import line for an application without Tailwind** is not yet run by a consumer app in CI ([#342], 0.2); it is to
485
+ be checked by hand at the rehearsal prerelease ([#166]).
486
+ - **Columns** (PRD-B10, PRD-B11, PRD-B12, PRD-A7; [#89] to [#92]): the column chooser, hiding, reordering and
487
+ resizing, each with a way that needs no drag. They come as one group after the local data source.
488
+ - **Row selection and child rows** (PRD-B13, PRD-B27; [#95], [#97], [#98]): the group after columns.
489
+ - **The sticky header and sticky columns** (PRD-B14; [#104], [#173]): they need the column and selection columns in
490
+ place first.
491
+ - **Accessibility beyond the automated checks**: forced colours (PRD-A8), 200 % zoom, 320 px width and text spacing
492
+ (PRD-A11), right-to-left (PRD-I3), the "Skip past table" link (PRD-A9), the contrast check over the token pairs
493
+ (PRD-A12), the target size of every control (PRD-A6), and the criterion-by-criterion proof of PRD section 4.3
494
+ ([#100], [#120], [#309]). 0.1.0 claims that axe finds no serious or critical violation in Chromium, Firefox and
495
+ WebKit, not that every WCAG 2.2 AA criterion is proved.
496
+ - **Screen-reader runs** (PRD-A5, [#179]): 0.1.0 is verified by automated checks in Chromium, Firefox and WebKit;
497
+ screen-reader runs are not yet done.
498
+ - **Branded browsers** (PRD-E1, [#181]): the tests run Playwright's Chromium, Firefox and WebKit at the versions in
499
+ the lockfile; branded Chrome and Edge and real Safari are not yet run.
500
+ - **Styling hooks and variants** (PRD-T7, PRD-T8, PRD-T13, PRD-T14, PRD-T10; [#111], [#118]): a column's `class`,
501
+ `align` and `headerClass`, `rowClass` and `cellClass`, `orderColumn`, and the striped, hover, bordered and compact
502
+ variants. Until then the public classes of the [styling guide](docs/styling.md) are the hooks.
503
+ - **A Bootstrap 5.3 consumer app** (PRD-W8, [#343]): the packed package is run in a Tailwind 4 SvelteKit app, not yet
504
+ in a Bootstrap page.
505
+ - **The test site's page with every feature** (PRD-W6, [#172]) and its check that the site imports SvelteDT only
506
+ through the package's exports (PRD-W1): the page needs the features above, and the import check is not yet built.
507
+ - **Speed, size and memory budgets** (PRD-P1, PRD-P3, PRD-P4, PRD-P5, PRD-P6, and the 50,000-row dataset they run on,
508
+ PRD-W3): 0.1.0 renders every row it is given, with no virtualisation, but its speed with 1,000 rows and its bundle
509
+ size are not yet held to a budget.
510
+ - **Recorded exchanges with four DataTables backends, and the migration guide from DataTables** (PRD-W11, PRD-D8;
511
+ [#248] to [#250], [#252]): the connection helper's tests use answers written by hand.
512
+
513
+ Not yet scheduled:
514
+
515
+ - **Column footers** (PRD-B28).
516
+ - **The connection helper's writable query and a first page loaded on the server** (PRD-B20): 0.1.0's helper reads the
517
+ query once, when it is created, and loads the first page in the browser.
518
+ - **A zero-violation check of the strict policy on a server-rendered page** (PRD-S1): the consumer project's server
519
+ HTML and policy header are checked, and the test site's pages are checked for zero violations; the check of the
520
+ server-rendered page waits for a decision on the requirement's text.
521
+ - **The server implementer guide** (PRD-D6): until then the [connection spec](spec/connection.md) states the requests
522
+ the helper sends and the answers it reads.
523
+ - **The default words and the CSS names in the API report** (PRD-K1): the [API reference](docs/api/README.md) is the
524
+ report of the exported types and fails CI on an unreviewed change; the default-word map, the stylesheet's `--sdt-*`
525
+ names and the public classes are not in it yet.
526
+ - **A public documentation site** (PRD-W10) on GitHub Pages; until then the documents live in this repository.
527
+ - **A `CHANGELOG.md` and upgrade notes** (PRD-D5): 0.1.0 is the first release, so there is nothing to upgrade from.
528
+
529
+ Not planned (owner's decisions; each may follow if adopters ask):
530
+
531
+ - **A `layout` option**: the table keeps one fixed order of its parts, takes the application's content through
532
+ snippets, and the application places the pager.
533
+ - **An advanced-search builder** (conditions combined with and/or): it stays the application's (PRD section 5.2),
534
+ shown in the `panels` snippet; a separate optional component may follow.
535
+
536
+ [#89]: https://github.com/hniedner/sveltedt/issues/89
537
+ [#92]: https://github.com/hniedner/sveltedt/issues/92
538
+ [#95]: https://github.com/hniedner/sveltedt/issues/95
539
+ [#97]: https://github.com/hniedner/sveltedt/issues/97
540
+ [#98]: https://github.com/hniedner/sveltedt/issues/98
541
+ [#100]: https://github.com/hniedner/sveltedt/issues/100
542
+ [#104]: https://github.com/hniedner/sveltedt/issues/104
543
+ [#111]: https://github.com/hniedner/sveltedt/issues/111
544
+ [#118]: https://github.com/hniedner/sveltedt/issues/118
545
+ [#120]: https://github.com/hniedner/sveltedt/issues/120
546
+ [#133]: https://github.com/hniedner/sveltedt/issues/133
547
+ [#166]: https://github.com/hniedner/sveltedt/issues/166
548
+ [#172]: https://github.com/hniedner/sveltedt/issues/172
549
+ [#173]: https://github.com/hniedner/sveltedt/issues/173
550
+ [#179]: https://github.com/hniedner/sveltedt/issues/179
551
+ [#181]: https://github.com/hniedner/sveltedt/issues/181
552
+ [#248]: https://github.com/hniedner/sveltedt/issues/248
553
+ [#250]: https://github.com/hniedner/sveltedt/issues/250
554
+ [#252]: https://github.com/hniedner/sveltedt/issues/252
555
+ [#309]: https://github.com/hniedner/sveltedt/issues/309
556
+ [#342]: https://github.com/hniedner/sveltedt/issues/342
557
+ [#343]: https://github.com/hniedner/sveltedt/issues/343
558
+
559
+ ## See it running
560
+
561
+ The test site shows the table on a list page of synthetic orders. With Node (the major version in `.node-version`)
562
+ and pnpm (the version in `package.json`'s `packageManager`):
563
+
564
+ ```sh
565
+ pnpm install --frozen-lockfile
566
+ pnpm site:build
567
+ pnpm site:serve
568
+ ```
569
+
570
+ Then open <http://127.0.0.1:4173>, or <http://127.0.0.1:4173/connection.html> for the page whose rows come from the
571
+ site's route `/api/orders` through the connection helper, or <http://127.0.0.1:4173/panels.html> for a button that opens
572
+ a panel. The list page takes the example token set's light set by default; add `?tokens=dark` for the dark set or
573
+ `?tokens=none` for no token at all ([styling guide](docs/styling.md)). The site listens on that address only and
574
+ sends the strict content-security policy (`default-src 'self'; script-src 'self'; style-src 'self'`) with every
575
+ answer.
576
+
577
+ The browser tests open the built site in Chromium, Firefox and WebKit (stop `pnpm site:serve` first: they start the
578
+ server on that address themselves; on Linux, `pnpm exec playwright install --with-deps` also installs the system
579
+ libraries):
580
+
581
+ ```sh
582
+ pnpm exec playwright install
583
+ pnpm site:build
584
+ node scripts/check-repo.ts browser
585
+ ```
586
+
587
+ ## A button that opens a panel
588
+
589
+ The table keeps no open state for its `panels` snippet and moves no focus for it: the application does both. The
590
+ test site's panels page (`/panels.html`, its source in [site/src/PanelsPage.svelte](site/src/PanelsPage.svelte)) shows
591
+ one way, proved by keyboard in Chromium, Firefox and WebKit (`spec/site.md`, section 9):
592
+
593
+ - the button in the `actions` snippet is a plain `<button type="button">` with `aria-expanded` (`"true"` while the
594
+ panel shows) and `aria-controls` naming the panel's `id`, as the WAI-ARIA disclosure pattern describes; Enter and
595
+ Space press it, and focus stays on it;
596
+ - the panel in the `panels` snippet is a block element, so it takes the table's width, and it stays in the document
597
+ with the `hidden` attribute while closed, so `aria-controls` always names an element;
598
+ - a control inside the panel that closes it moves focus back to the button: without it, focus does not return to the
599
+ button, and where it goes differs by browser.
600
+
601
+ ## Documents
602
+
603
+ - What it must do: [the product requirements](docs/PRD.md), and where it departs from DataTables and why:
604
+ [departures](docs/departures.md).
605
+ - What each part does, sentence by sentence: [the component spec](spec/table.md).
606
+ - Every export, prop and type: [the API reference](docs/api/README.md), generated from the package's types.
607
+ - How to import and theme it: [the styling guide](docs/styling.md) (the tokens, their contrast pairs and the public
608
+ classes).
609
+ - How it is built: [the engineering method](docs/engineering/method.md) and
610
+ [how each check works](docs/engineering/gates.md).
611
+
612
+ ## Contributing and security
613
+
614
+ Contributions follow [CONTRIBUTING.md](CONTRIBUTING.md), which also sets up the checks (`pnpm gate`). Report a
615
+ vulnerability privately as [SECURITY.md](SECURITY.md) says.
616
+
617
+ ## Licence
618
+
619
+ MIT: see [LICENSE](LICENSE); third-party notices are in [NOTICE](NOTICE).