@gemologic/sheen-table 0.3.0 → 0.4.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 (43) hide show
  1. package/dist/DataTable.d.ts +57 -13
  2. package/dist/DataTable.js +963 -820
  3. package/dist/FilterBar.d.ts +3 -3
  4. package/dist/FilterBar.js +5 -1
  5. package/dist/client-state.d.ts +9 -3
  6. package/dist/client-state.js +38 -32
  7. package/dist/core.d.ts +5 -5
  8. package/dist/core.js +28 -28
  9. package/dist/data-table-features.d.ts +18 -13
  10. package/dist/data-table-features.js +11 -1
  11. package/dist/index.d.ts +5 -3
  12. package/dist/index.js +32 -31
  13. package/dist/messages.d.ts +3 -0
  14. package/dist/messages.js +3 -0
  15. package/dist/pagination.d.ts +43 -1
  16. package/dist/pagination.js +109 -54
  17. package/dist/requests.d.ts +3 -3
  18. package/dist/requests.js +38 -28
  19. package/dist/saved-views.d.ts +17 -14
  20. package/dist/saved-views.js +71 -68
  21. package/dist/server-export.d.ts +16 -7
  22. package/dist/server-export.js +57 -53
  23. package/dist/table-state-changes.d.ts +6 -3
  24. package/dist/table-state-changes.js +44 -40
  25. package/dist/table-state.d.ts +20 -4
  26. package/dist/table-state.js +66 -40
  27. package/dist/url-state.d.ts +12 -9
  28. package/dist/url-state.js +33 -30
  29. package/package.json +3 -3
  30. package/src/DataTable.tsx +221 -61
  31. package/src/FilterBar.tsx +5 -3
  32. package/src/client-state.ts +31 -17
  33. package/src/core.ts +5 -5
  34. package/src/data-table-features.tsx +23 -10
  35. package/src/index.ts +5 -3
  36. package/src/messages.ts +1 -1
  37. package/src/pagination.ts +83 -14
  38. package/src/requests.ts +22 -8
  39. package/src/saved-views.ts +33 -11
  40. package/src/server-export.ts +17 -11
  41. package/src/table-state-changes.ts +22 -12
  42. package/src/table-state.ts +53 -11
  43. package/src/url-state.ts +27 -10
@@ -1,17 +1,18 @@
1
1
  import type { BulkSelection } from "./selection.ts";
2
+ import type { ServerPagination, TablePagination } from "./pagination.ts";
2
3
  import type { TableState, TableStateSchema } from "./table-state.ts";
3
- export interface TableExportRequest {
4
+ export interface TableExportRequest<Pagination extends ServerPagination = TablePagination> {
4
5
  readonly format: "csv" | "json";
5
- readonly state: TableState;
6
+ readonly state: TableState<Pagination>;
6
7
  /** null exports the whole matching view; explicit empty IDs export zero rows. */
7
8
  readonly selection: BulkSelection | null;
8
9
  }
9
- export interface ServerExportSnapshot<Artifact> {
10
+ export interface ServerExportSnapshot<Artifact, Pagination extends ServerPagination = TablePagination> {
10
11
  readonly accepted: {
11
- readonly request: TableExportRequest;
12
+ readonly request: TableExportRequest<Pagination>;
12
13
  readonly artifact: Artifact;
13
14
  } | null;
14
- readonly requested: TableExportRequest | null;
15
+ readonly requested: TableExportRequest<Pagination> | null;
15
16
  readonly pending: boolean;
16
17
  readonly error: unknown;
17
18
  }
@@ -19,8 +20,16 @@ export type ServerExportOutcome = "accepted" | "failed" | "busy" | "unavailable"
19
20
  /** App callback creates the artifact; only the accepted result should be offered for download. */
20
21
  export declare function createServerExport<Artifact>(schema: TableStateSchema, onExport?: (request: TableExportRequest, signal: AbortSignal) => Promise<Artifact>): {
21
22
  available: boolean;
22
- getSnapshot: () => ServerExportSnapshot<Artifact>;
23
- request: (value: TableExportRequest) => Promise<ServerExportOutcome>;
23
+ getSnapshot: () => ServerExportSnapshot<Artifact, TablePagination>;
24
+ request: (value: TableExportRequest<TablePagination>) => Promise<ServerExportOutcome>;
25
+ retry: () => Promise<ServerExportOutcome>;
26
+ clear: () => void;
27
+ dispose(): void;
28
+ };
29
+ export declare function createServerExportWith<Artifact, Pagination extends ServerPagination>(schema: TableStateSchema, readPagination: (value: unknown) => Pagination, onExport?: (request: TableExportRequest<Pagination>, signal: AbortSignal) => Promise<Artifact>): {
30
+ available: boolean;
31
+ getSnapshot: () => ServerExportSnapshot<Artifact, Pagination>;
32
+ request: (value: TableExportRequest<Pagination>) => Promise<ServerExportOutcome>;
24
33
  retry: () => Promise<ServerExportOutcome>;
25
34
  clear: () => void;
26
35
  dispose(): void;
@@ -1,84 +1,88 @@
1
1
  import { parseFilter as e } from "./filter.js";
2
- import { parseTableState as t } from "./table-state.js";
2
+ import { parsePagination as t } from "./pagination.js";
3
+ import { parseTableStateWith as n } from "./table-state.js";
3
4
  // src/server-export.ts
4
- function n(n, r) {
5
- if (n.format !== "csv" && n.format !== "json") throw Error("Unsupported table export format");
6
- let i = t(n.state, r), a = null;
7
- if (n.selection !== null) {
8
- let t = n.selection;
9
- if (t.kind !== "ids" && t.kind !== "query") throw Error("Invalid export selection kind");
10
- let i = t.kind === "ids" ? t.ids : t.excluded;
5
+ function r(t, r, i) {
6
+ if (t.format !== "csv" && t.format !== "json") throw Error("Unsupported table export format");
7
+ let a = n(t.state, r, i), o = null;
8
+ if (t.selection !== null) {
9
+ let n = t.selection;
10
+ if (n.kind !== "ids" && n.kind !== "query") throw Error("Invalid export selection kind");
11
+ let i = n.kind === "ids" ? n.ids : n.excluded;
11
12
  if (!Array.isArray(i)) throw Error("Export selection IDs must be an array");
12
- let o = /* @__PURE__ */ new Set();
13
+ let a = /* @__PURE__ */ new Set();
13
14
  for (let e of i) {
14
- if (typeof e != "string" || !e.trim() || o.has(e)) throw Error("Export selection IDs must be unique nonempty strings");
15
- o.add(e);
15
+ if (typeof e != "string" || !e.trim() || a.has(e)) throw Error("Export selection IDs must be unique nonempty strings");
16
+ a.add(e);
16
17
  }
17
- a = t.kind === "ids" ? Object.freeze({
18
+ o = n.kind === "ids" ? Object.freeze({
18
19
  kind: "ids",
19
- ids: Object.freeze([...o])
20
+ ids: Object.freeze([...a])
20
21
  }) : Object.freeze({
21
22
  kind: "query",
22
- filter: e(t.filter, r.filterColumns),
23
- excluded: Object.freeze([...o])
23
+ filter: e(n.filter, r.filterColumns),
24
+ excluded: Object.freeze([...a])
24
25
  });
25
26
  }
26
27
  return Object.freeze({
27
- format: n.format,
28
- state: i,
29
- selection: a
28
+ format: t.format,
29
+ state: a,
30
+ selection: o
30
31
  });
31
32
  }
32
- function r(e, t) {
33
- let r = {
33
+ function i(e, n) {
34
+ return a(e, t, n);
35
+ }
36
+ function a(e, t, n) {
37
+ let i = {
34
38
  accepted: null,
35
39
  requested: null,
36
40
  pending: !1,
37
41
  error: null
38
- }, i = 0n, a, o = !1, s = !1;
39
- async function c(c) {
40
- if (o) return "disposed";
41
- if (!t) return "unavailable";
42
- if (s) return "canceled";
43
- if (r.pending) return "busy";
44
- let l = ++i, u = new AbortController();
45
- a = u, r = {
46
- ...r,
42
+ }, a = 0n, o, s = !1, c = !1;
43
+ async function l(l) {
44
+ if (s) return "disposed";
45
+ if (!n) return "unavailable";
46
+ if (c) return "canceled";
47
+ if (i.pending) return "busy";
48
+ let u = ++a, d = new AbortController();
49
+ o = d, i = {
50
+ ...i,
47
51
  requested: null,
48
52
  pending: !0,
49
53
  error: null
50
54
  };
51
55
  try {
52
- let a = n(c, e);
53
- r = {
54
- ...r,
55
- requested: a
56
+ let o = r(l, e, t);
57
+ i = {
58
+ ...i,
59
+ requested: o
56
60
  };
57
- let s = await t(a, u.signal);
58
- return o ? "disposed" : l === i ? (r = {
61
+ let c = await n(o, d.signal);
62
+ return s ? "disposed" : u === a ? (i = {
59
63
  accepted: {
60
- request: a,
61
- artifact: s
64
+ request: o,
65
+ artifact: c
62
66
  },
63
67
  requested: null,
64
68
  pending: !1,
65
69
  error: null
66
70
  }, "accepted") : "canceled";
67
71
  } catch (e) {
68
- return o ? "disposed" : l === i ? (r = {
69
- ...r,
72
+ return s ? "disposed" : u === a ? (i = {
73
+ ...i,
70
74
  pending: !1,
71
75
  error: e
72
76
  }, "failed") : "canceled";
73
77
  } finally {
74
- l === i && (a = void 0);
78
+ u === a && (o = void 0);
75
79
  }
76
80
  }
77
- function l() {
78
- if (s) return;
79
- s = !0, i++;
80
- let e = a;
81
- a = void 0, r = {
81
+ function u() {
82
+ if (c) return;
83
+ c = !0, a++;
84
+ let e = o;
85
+ o = void 0, i = {
82
86
  accepted: null,
83
87
  requested: null,
84
88
  pending: !1,
@@ -87,18 +91,18 @@ function r(e, t) {
87
91
  try {
88
92
  e?.abort();
89
93
  } finally {
90
- s = !1;
94
+ c = !1;
91
95
  }
92
96
  }
93
97
  return {
94
- available: t !== void 0,
95
- getSnapshot: () => r,
96
- request: c,
97
- retry: () => r.requested ? c(r.requested) : Promise.resolve(o ? "disposed" : t ? "failed" : "unavailable"),
98
- clear: l,
98
+ available: n !== void 0,
99
+ getSnapshot: () => i,
100
+ request: l,
101
+ retry: () => i.requested ? l(i.requested) : Promise.resolve(s ? "disposed" : n ? "failed" : "unavailable"),
102
+ clear: u,
99
103
  dispose() {
100
- o = !0, l();
104
+ s = !0, u();
101
105
  }
102
106
  };
103
107
  }
104
- export { r as createServerExport };
108
+ export { i as createServerExport, a as createServerExportWith };
@@ -1,8 +1,9 @@
1
1
  import type { ClientStateChange } from "./client-state.ts";
2
- import type { ColumnState, TableState, TableStateSchema } from "./table-state.ts";
3
- export type TableStateChange = {
2
+ import type { CursorPagination, ServerPagination, TablePagination } from "./pagination.ts";
3
+ import type { ColumnState, CursorTableStateSchema, TableState, TableStateSchema, TableStateSchemaFields } from "./table-state.ts";
4
+ export type TableStateChange<Pagination extends ServerPagination = TablePagination> = {
4
5
  readonly kind: "query";
5
- readonly change: ClientStateChange;
6
+ readonly change: ClientStateChange<Pagination>;
6
7
  } | {
7
8
  readonly kind: "sortCycle";
8
9
  readonly column: string;
@@ -24,4 +25,6 @@ export type TableStateChange = {
24
25
  readonly pin: ColumnState["pin"];
25
26
  };
26
27
  /** Pure requested-state update. Apply accepted layout/query/results atomically in the table owner. */
28
+ export declare function changeTableState(value: TableState<CursorPagination>, change: TableStateChange<CursorPagination>, schema: CursorTableStateSchema): TableState<CursorPagination>;
27
29
  export declare function changeTableState(value: TableState, change: TableStateChange, schema: TableStateSchema): TableState;
30
+ export declare function changeTableStateWith<Pagination extends ServerPagination>(value: TableState<Pagination>, change: TableStateChange<Pagination>, schema: TableStateSchemaFields, readPagination: (value: unknown) => Pagination): TableState<Pagination>;
@@ -1,66 +1,70 @@
1
- import { changeClientViewState as e } from "./client-state.js";
2
- import { parseTableState as t } from "./table-state.js";
1
+ import { changeQueryState as e } from "./client-state.js";
2
+ import { parseCursorPagination as t, parsePagination as n } from "./pagination.js";
3
+ import { parseTableStateWith as r, schemaPagination as i } from "./table-state.js";
3
4
  // src/table-state-changes.ts
4
- function n(n, r, i) {
5
- let a = t(n, i), o = {
6
- search: a.search,
7
- filter: a.filter,
8
- sorting: a.sorting,
9
- pagination: a.pagination
5
+ function a(e, r, a) {
6
+ return i(a) === "cursor" ? o(e, r, a, t) : o(e, r, a, n);
7
+ }
8
+ function o(t, n, i, a) {
9
+ let o = (e) => r(e, i, a), s = (t, n) => e(t, n, i, a), c = o(t), l = {
10
+ search: c.search,
11
+ filter: c.filter,
12
+ sorting: c.sorting,
13
+ pagination: c.pagination
10
14
  };
11
- switch (r.kind) {
12
- case "query": return t({
13
- ...e(o, r.change, i),
14
- columns: a.columns
15
- }, i);
15
+ switch (n.kind) {
16
+ case "query": return o({
17
+ ...s(l, n.change),
18
+ columns: c.columns
19
+ });
16
20
  case "sortCycle": {
17
- if (!i.sortColumns.some((e) => e.id === r.column)) throw Error(`Column does not support sorting: ${r.column}`);
18
- let n = a.sorting.find((e) => e.column === r.column), s = n?.direction === "desc" ? null : {
19
- column: r.column,
20
- direction: n ? "desc" : "asc"
21
- }, c;
22
- return c = r.multiple ? !n && s ? [...a.sorting, s] : a.sorting.flatMap((e) => e.column === r.column ? s ? [s] : [] : [e]) : s ? [s] : [], t({
23
- ...e(o, {
21
+ if (!i.sortColumns.some((e) => e.id === n.column)) throw Error(`Column does not support sorting: ${n.column}`);
22
+ let e = c.sorting.find((e) => e.column === n.column), t = e?.direction === "desc" ? null : {
23
+ column: n.column,
24
+ direction: e ? "desc" : "asc"
25
+ }, r;
26
+ return r = n.multiple ? !e && t ? [...c.sorting, t] : c.sorting.flatMap((e) => e.column === n.column ? t ? [t] : [] : [e]) : t ? [t] : [], o({
27
+ ...s(l, {
24
28
  kind: "sorting",
25
- value: c
26
- }, i),
27
- columns: a.columns
28
- }, i);
29
+ value: r
30
+ }),
31
+ columns: c.columns
32
+ });
29
33
  }
30
34
  case "columnOrder": {
31
- let e = new Map(a.columns.map((e) => [e.id, e]));
32
- return t({
33
- ...a,
34
- columns: Array.from(r.ids, (t) => e.get(t))
35
- }, i);
35
+ let e = new Map(c.columns.map((e) => [e.id, e]));
36
+ return o({
37
+ ...c,
38
+ columns: Array.from(n.ids, (t) => e.get(t))
39
+ });
36
40
  }
37
41
  case "columnVisibility":
38
42
  case "columnWidth":
39
43
  case "columnPin": {
40
- if (!a.columns.some((e) => e.id === r.column)) throw Error(`Unknown table column: ${r.column}`);
41
- let e = a.columns.map((e) => {
42
- if (e.id !== r.column) return e;
43
- switch (r.kind) {
44
+ if (!c.columns.some((e) => e.id === n.column)) throw Error(`Unknown table column: ${n.column}`);
45
+ let e = c.columns.map((e) => {
46
+ if (e.id !== n.column) return e;
47
+ switch (n.kind) {
44
48
  case "columnVisibility": return {
45
49
  ...e,
46
- visible: r.visible
50
+ visible: n.visible
47
51
  };
48
52
  case "columnWidth": return {
49
53
  ...e,
50
- width: r.width
54
+ width: n.width
51
55
  };
52
56
  case "columnPin": return {
53
57
  ...e,
54
- pin: r.pin
58
+ pin: n.pin
55
59
  };
56
60
  }
57
61
  });
58
- return t({
59
- ...a,
62
+ return o({
63
+ ...c,
60
64
  columns: e
61
- }, i);
65
+ });
62
66
  }
63
67
  default: throw Error("Unknown table state change");
64
68
  }
65
69
  }
66
- export { n as changeTableState };
70
+ export { a as changeTableState, o as changeTableStateWith };
@@ -1,5 +1,5 @@
1
- import type { ClientStateSchema } from "./client-state.ts";
2
- import type { ClientViewState } from "./client-view.ts";
1
+ import type { ClientStateSchema, QueryState } from "./client-state.ts";
2
+ import type { CursorPagination, ServerPagination, TablePagination } from "./pagination.ts";
3
3
  export interface ColumnState {
4
4
  readonly id: string;
5
5
  readonly visible: boolean;
@@ -7,14 +7,30 @@ export interface ColumnState {
7
7
  readonly width: number | null;
8
8
  readonly pin: "start" | "end" | false;
9
9
  }
10
- export interface TableState extends ClientViewState {
10
+ export interface TableState<Pagination extends ServerPagination = TablePagination> extends QueryState<Pagination> {
11
11
  /** Array order is the user-defined column order. Every available column occurs once. */
12
12
  readonly columns: readonly ColumnState[];
13
13
  }
14
- export interface TableStateSchema extends ClientStateSchema {
14
+ /** Shared column and query fields; internal pagination-generic owners accept it. */
15
+ export interface TableStateSchemaFields extends ClientStateSchema {
15
16
  readonly columns: readonly string[];
16
17
  }
18
+ /** Schema for complete or numbered pagination state. */
19
+ export interface TableStateSchema extends TableStateSchemaFields {
20
+ readonly pagination?: never;
21
+ }
22
+ /** Schema for cursor pagination state. Persisted envelopes always store `cursor: null` because cursor tokens are short-lived. */
23
+ export interface CursorTableStateSchema extends TableStateSchemaFields {
24
+ readonly pagination: "cursor";
25
+ }
26
+ /** Cursor schemas read only cursor state; other schemas read complete or numbered state. Unknown schema kinds fail closed. */
27
+ export declare function schemaPagination(schema: TableStateSchema | CursorTableStateSchema): "cursor" | "page";
17
28
  /** Strictly validate before applying saved/URL state, never partially restore it. */
29
+ export declare function parseTableState(value: unknown, schema: CursorTableStateSchema): TableState<CursorPagination>;
18
30
  export declare function parseTableState(value: unknown, schema: TableStateSchema): TableState;
31
+ export declare function parseTableStateWith<Pagination extends ServerPagination>(value: unknown, schema: TableStateSchemaFields, readPagination: (value: unknown) => Pagination): TableState<Pagination>;
32
+ /** Cursor state is persisted as its first page: the live cursor token is replaced with null. */
33
+ export declare function serializeState(state: TableState<CursorPagination>, schema: CursorTableStateSchema): string;
19
34
  export declare function serializeState(state: TableState, schema: TableStateSchema): string;
35
+ export declare function deserializeState(serialized: string, schema: CursorTableStateSchema): TableState<CursorPagination>;
20
36
  export declare function deserializeState(serialized: string, schema: TableStateSchema): TableState;
@@ -1,46 +1,61 @@
1
- import { parseClientViewState as e } from "./client-state.js";
1
+ import { parseQueryState as e } from "./client-state.js";
2
+ import { parseCursorPagination as t, parsePagination as n } from "./pagination.js";
2
3
  // src/table-state.ts
3
- function t(e) {
4
+ function r(e) {
4
5
  return typeof e == "object" && !!e && !Array.isArray(e);
5
6
  }
6
- function n(e, t, n) {
7
+ function i(e, t, n) {
7
8
  for (let r of Object.keys(e)) if (!t.includes(r)) throw Error(`Invalid table state at ${n}: unknown field ${r}`);
8
9
  for (let r of t) if (!Object.hasOwn(e, r)) throw Error(`Invalid table state at ${n}: missing ${r}`);
9
10
  }
10
- function r(r, i) {
11
- let a = /* @__PURE__ */ new Set();
12
- for (let e of i.columns) {
13
- if (typeof e != "string" || !e.trim() || a.has(e)) throw Error("Invalid or duplicate table schema column");
14
- a.add(e);
11
+ function a(e) {
12
+ let t = e.pagination;
13
+ if (t === void 0) return "page";
14
+ if (t === "cursor") return t;
15
+ throw Error("Table state schema pagination must be omitted or cursor");
16
+ }
17
+ function o(e) {
18
+ let n = t(e);
19
+ if (n.cursor !== null) throw Error("Persisted cursor pagination must use cursor: null");
20
+ return n;
21
+ }
22
+ function s(e, r) {
23
+ return a(r) === "cursor" ? c(e, r, t) : c(e, r, n);
24
+ }
25
+ function c(t, n, a) {
26
+ let o = /* @__PURE__ */ new Set();
27
+ for (let e of n.columns) {
28
+ if (typeof e != "string" || !e.trim() || o.has(e)) throw Error("Invalid or duplicate table schema column");
29
+ o.add(e);
15
30
  }
16
- for (let e of [...i.filterColumns, ...i.sortColumns]) if (!a.has(e.id)) throw Error(`Query schema references unavailable table column: ${e.id}`);
17
- if (!t(r)) throw Error("Invalid table state: expected an object");
18
- n(r, [
31
+ for (let e of [...n.filterColumns, ...n.sortColumns]) if (!o.has(e.id)) throw Error(`Query schema references unavailable table column: ${e.id}`);
32
+ if (!r(t)) throw Error("Invalid table state: expected an object");
33
+ i(t, [
19
34
  "search",
20
35
  "filter",
21
36
  "sorting",
22
37
  "pagination",
23
38
  "columns"
24
39
  ], "$");
25
- let o = e({
26
- search: r.search,
27
- filter: r.filter,
28
- sorting: r.sorting,
29
- pagination: r.pagination
30
- }, i);
31
- if (!Array.isArray(r.columns) || r.columns.length !== a.size) throw Error("Invalid table state: expected one state entry per available column");
32
- let s = /* @__PURE__ */ new Set(), c = Array.from(r.columns, (e, r) => {
33
- let i = `$.columns[${r}]`;
34
- if (!t(e)) throw Error(`Invalid table state at ${i}: expected a column object`);
35
- if (n(e, [
40
+ let s = e({
41
+ search: t.search,
42
+ filter: t.filter,
43
+ sorting: t.sorting,
44
+ pagination: t.pagination
45
+ }, n, a);
46
+ if (!Array.isArray(t.columns) || t.columns.length !== o.size) throw Error("Invalid table state: expected one state entry per available column");
47
+ let c = /* @__PURE__ */ new Set(), l = Array.from(t.columns, (e, t) => {
48
+ let n = `$.columns[${t}]`;
49
+ if (!r(e)) throw Error(`Invalid table state at ${n}: expected a column object`);
50
+ if (i(e, [
36
51
  "id",
37
52
  "visible",
38
53
  "width",
39
54
  "pin"
40
- ], i), typeof e.id != "string" || !a.has(e.id) || s.has(e.id)) throw Error(`Invalid table state at ${i}: unknown or duplicate column`);
41
- if (s.add(e.id), typeof e.visible != "boolean") throw Error(`Invalid table state at ${i}: visible must be boolean`);
42
- if (e.width !== null && (typeof e.width != "number" || !Number.isFinite(e.width) || e.width <= 0)) throw Error(`Invalid table state at ${i}: width must be null or a positive finite pixel value`);
43
- if (e.pin !== !1 && e.pin !== "start" && e.pin !== "end") throw Error(`Invalid table state at ${i}: pin must be false, start, or end`);
55
+ ], n), typeof e.id != "string" || !o.has(e.id) || c.has(e.id)) throw Error(`Invalid table state at ${n}: unknown or duplicate column`);
56
+ if (c.add(e.id), typeof e.visible != "boolean") throw Error(`Invalid table state at ${n}: visible must be boolean`);
57
+ if (e.width !== null && (typeof e.width != "number" || !Number.isFinite(e.width) || e.width <= 0)) throw Error(`Invalid table state at ${n}: width must be null or a positive finite pixel value`);
58
+ if (e.pin !== !1 && e.pin !== "start" && e.pin !== "end") throw Error(`Invalid table state at ${n}: pin must be false, start, or end`);
44
59
  return Object.freeze({
45
60
  id: e.id,
46
61
  visible: e.visible,
@@ -49,28 +64,39 @@ function r(r, i) {
49
64
  });
50
65
  });
51
66
  return Object.freeze({
52
- ...o,
53
- columns: Object.freeze(c)
67
+ ...s,
68
+ columns: Object.freeze(l)
54
69
  });
55
70
  }
56
- function i(e, t) {
57
- let n = JSON.stringify({
71
+ function l(e) {
72
+ let t = JSON.stringify({
58
73
  version: 1,
59
- state: r(e, t)
74
+ state: e
60
75
  });
61
- if (n.length > 262144) throw Error("Serialized table state exceeds 262144 characters");
62
- return n;
76
+ if (t.length > 262144) throw Error("Serialized table state exceeds 262144 characters");
77
+ return t;
78
+ }
79
+ function u(e, r) {
80
+ if (a(r) === "page") return l(c(e, r, n));
81
+ let i = c(e, r, t);
82
+ return l(c({
83
+ ...i,
84
+ pagination: {
85
+ ...i.pagination,
86
+ cursor: null
87
+ }
88
+ }, r, o));
63
89
  }
64
- function a(e, i) {
90
+ function d(e, t) {
65
91
  if (e.length > 262144) throw Error("Serialized table state exceeds 262144 characters");
66
- let a;
92
+ let s;
67
93
  try {
68
- a = JSON.parse(e);
94
+ s = JSON.parse(e);
69
95
  } catch {
70
96
  throw Error("Invalid table state JSON");
71
97
  }
72
- if (!t(a)) throw Error("Invalid table state envelope");
73
- if (n(a, ["version", "state"], "$"), a.version !== 1) throw Error("Unsupported table state version");
74
- return r(a.state, i);
98
+ if (!r(s)) throw Error("Invalid table state envelope");
99
+ if (i(s, ["version", "state"], "$"), s.version !== 1) throw Error("Unsupported table state version");
100
+ return a(t) === "cursor" ? c(s.state, t, o) : c(s.state, t, n);
75
101
  }
76
- export { a as deserializeState, r as parseTableState, i as serializeState };
102
+ export { d as deserializeState, s as parseTableState, c as parseTableStateWith, a as schemaPagination, u as serializeState };
@@ -1,4 +1,5 @@
1
- import type { TableState, TableStateSchema } from "./table-state.ts";
1
+ import type { CursorPagination, ServerPagination, TablePagination } from "./pagination.ts";
2
+ import type { CursorTableStateSchema, TableState, TableStateSchema } from "./table-state.ts";
2
3
  export interface TableUrlLocation {
3
4
  readonly pathname: string;
4
5
  readonly search: string;
@@ -11,11 +12,11 @@ export interface TableUrlRouter {
11
12
  readonly scroll?: boolean;
12
13
  }) => void;
13
14
  }
14
- export type TableUrlRead = {
15
+ export type TableUrlRead<Pagination extends ServerPagination = TablePagination> = {
15
16
  readonly kind: "absent";
16
17
  } | {
17
18
  readonly kind: "accepted";
18
- readonly state: TableState;
19
+ readonly state: TableState<Pagination>;
19
20
  } | {
20
21
  readonly kind: "invalid";
21
22
  readonly error: unknown;
@@ -27,13 +28,15 @@ export type TableUrlWrite = {
27
28
  readonly kind: "navigated";
28
29
  readonly to: string;
29
30
  };
30
- /** Pull-based URL state using the same structural adapter as AppShell. */
31
- export declare function createTableUrlState(router: TableUrlRouter, parameter: string, schema: TableStateSchema): {
32
- read: () => TableUrlRead;
33
- write: (state: TableState, options?: {
31
+ export interface TableUrlState<Pagination extends ServerPagination = TablePagination> {
32
+ readonly read: () => TableUrlRead<Pagination>;
33
+ readonly write: (state: TableState<Pagination>, options?: {
34
34
  readonly replace?: boolean;
35
35
  }) => TableUrlWrite;
36
- clear: (options?: {
36
+ readonly clear: (options?: {
37
37
  readonly replace?: boolean;
38
38
  }) => TableUrlWrite;
39
- };
39
+ }
40
+ /** Pull-based URL state using the same structural adapter as AppShell. Cursor schemas write and read only the first page. */
41
+ export declare function createTableUrlState(router: TableUrlRouter, parameter: string, schema: CursorTableStateSchema): TableUrlState<CursorPagination>;
42
+ export declare function createTableUrlState(router: TableUrlRouter, parameter: string, schema: TableStateSchema): TableUrlState;