@gemologic/sheen-table 0.2.1 → 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 (71) hide show
  1. package/dist/DataTable.d.ts +58 -10
  2. package/dist/DataTable.js +1294 -1625
  3. package/dist/DataTableToolbar.js +1 -2
  4. package/dist/FilterBar.d.ts +3 -0
  5. package/dist/FilterBar.js +131 -108
  6. package/dist/QueryBuilder.js +72 -68
  7. package/dist/cell-edit.js +1 -2
  8. package/dist/client-state.d.ts +9 -3
  9. package/dist/client-state.js +36 -31
  10. package/dist/client-view.js +12 -13
  11. package/dist/column-layout.js +1 -2
  12. package/dist/columns.d.ts +5 -1
  13. package/dist/columns.js +7 -5
  14. package/dist/constrained-columns.js +1 -2
  15. package/dist/core.d.ts +5 -5
  16. package/dist/core.js +28 -28
  17. package/dist/data-table-features.d.ts +134 -0
  18. package/dist/data-table-features.js +560 -0
  19. package/dist/export.js +1 -2
  20. package/dist/facets.js +5 -7
  21. package/dist/filter-bar-state.js +14 -18
  22. package/dist/filter-client.js +1 -2
  23. package/dist/filter.js +1 -2
  24. package/dist/grouping.js +1 -2
  25. package/dist/index.d.ts +5 -3
  26. package/dist/index.js +32 -31
  27. package/dist/messages.d.ts +4 -1
  28. package/dist/messages.js +5 -3
  29. package/dist/pagination.d.ts +43 -1
  30. package/dist/pagination.js +110 -56
  31. package/dist/query-builder-state.js +1 -2
  32. package/dist/requests.d.ts +3 -3
  33. package/dist/requests.js +39 -30
  34. package/dist/row-hierarchy.js +1 -2
  35. package/dist/row-identity.js +1 -2
  36. package/dist/saved-views.d.ts +17 -14
  37. package/dist/saved-views.js +72 -70
  38. package/dist/search-controller.js +1 -2
  39. package/dist/search.js +1 -2
  40. package/dist/selection-client.js +1 -2
  41. package/dist/selection.d.ts +3 -0
  42. package/dist/selection.js +9 -2
  43. package/dist/server-export.d.ts +16 -7
  44. package/dist/server-export.js +58 -55
  45. package/dist/sorting.js +1 -2
  46. package/dist/table-state-changes.d.ts +6 -3
  47. package/dist/table-state-changes.js +45 -42
  48. package/dist/table-state.d.ts +20 -4
  49. package/dist/table-state.js +67 -42
  50. package/dist/text-normalization.js +1 -2
  51. package/dist/url-state.d.ts +12 -9
  52. package/dist/url-state.js +34 -32
  53. package/package.json +5 -5
  54. package/src/DataTable.tsx +490 -766
  55. package/src/FilterBar.tsx +19 -3
  56. package/src/QueryBuilder.tsx +5 -5
  57. package/src/client-state.ts +31 -17
  58. package/src/columns.ts +9 -3
  59. package/src/core.ts +5 -5
  60. package/src/data-table-features.tsx +592 -0
  61. package/src/index.ts +5 -3
  62. package/src/messages.ts +2 -2
  63. package/src/pagination.ts +83 -14
  64. package/src/requests.ts +22 -8
  65. package/src/saved-views.ts +33 -11
  66. package/src/selection.ts +8 -0
  67. package/src/server-export.ts +17 -11
  68. package/src/styles.css +17 -11
  69. package/src/table-state-changes.ts +22 -12
  70. package/src/table-state.ts +53 -11
  71. package/src/url-state.ts +27 -10
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./core.ts";
2
- export { DataTable } from "./DataTable.tsx";
3
- export type { DataTableProps, DataTableResult, DataTableInitialState, DataTableSelectionOptions, DataTableGroupingOptions, DataTableHierarchyOptions, DataTableExportFormat, DataTableExportOptions, DataTableCellCommitRequest, DataTableAction, DataTableActionContext, DataTableMobileLayoutOptions, DataTableVariant, DataTableDensity, DataTableSearchOptions, DataTableFilterBarOptions, ClientDataTableProps, ServerDataTableProps } from "./DataTable.tsx";
4
- export { FilterBar } from "./FilterBar.tsx";
2
+ export { DataTable, createDataTable } from "./DataTable.tsx";
3
+ export { groupingFeature, hierarchyFeature, cellEditingFeature } from "./data-table-features.tsx";
4
+ export type { DataTableFeature, DataTableFeatureId } from "./data-table-features.tsx";
5
+ export type { ComposedDataTable, ComposedDataTableProps, DataTableProps, DataTableResult, DataTableCursorResult, DataTableInitialState, DataTableSelectionOptions, DataTableGroupingOptions, DataTableHierarchyOptions, DataTableExportFormat, DataTableExportOptions, DataTableCellCommitRequest, DataTableAction, DataTableActionContext, DataTableMobileLayoutOptions, DataTableVariant, DataTableDensity, DataTableSearchOptions, DataTableFilterBarOptions, ClientDataTableProps, ServerDataTableProps } from "./DataTable.tsx";
6
+ export { FilterBar, filterBarFeature } from "./FilterBar.tsx";
5
7
  export type { FilterBarProps, FilterDateEditor, FilterDateEditorProps } from "./FilterBar.tsx";
6
8
  export { QueryBuilder } from "./QueryBuilder.tsx";
7
9
  export type { QueryBuilderProps } from "./QueryBuilder.tsx";
package/dist/index.js CHANGED
@@ -1,31 +1,32 @@
1
- import { assessServerPage as e, getPageRange as t, paginateClientRows as n, parsePagination as r, resetPagination as i, resizePagination as a, resolvePagination as o } from "./pagination.js";
2
- import { createTableRequests as s } from "./requests.js";
3
- import { deserializeFilter as c, parseFilter as l, serializeFilter as u } from "./filter.js";
4
- import { appendQueryChild as d, defaultQueryRule as f, moveQueryNode as p, queryBuilderFilterColumns as m, queryNodeAt as h, removeQueryNode as g, replaceQueryNode as _, toggleQueryNegation as v } from "./query-builder-state.js";
5
- import { appendFilterCondition as y, listFilterConditions as b, removeFilterColumnConditions as x, removeFilterCondition as S, replaceFilterCondition as C } from "./filter-bar-state.js";
6
- import { compileFilter as w, filterClientRows as T } from "./filter-client.js";
7
- import { parseSorting as E, sortClientRows as D } from "./sorting.js";
8
- import { countClientFacets as O } from "./facets.js";
9
- import { formatSearchQuery as k, parseSearchQuery as A, searchClientRows as j } from "./search.js";
10
- import { createDebouncedSearch as M } from "./search-controller.js";
11
- import { createClientView as N } from "./client-view.js";
12
- import { changeClientViewState as P, parseClientViewState as F } from "./client-state.js";
13
- import { deserializeState as I, parseTableState as L, serializeState as R } from "./table-state.js";
14
- import { changeTableState as z } from "./table-state-changes.js";
15
- import { canMoveColumn as B, moveColumn as V, orderColumnStates as H, placeColumn as U } from "./column-layout.js";
16
- import { createTableSelection as W } from "./selection.js";
17
- import { createClientExport as G } from "./export.js";
18
- import { selectClientRows as K } from "./selection-client.js";
19
- import { createServerExport as q } from "./server-export.js";
20
- import { createCellEdit as J } from "./cell-edit.js";
21
- import { defineColumns as Y } from "./columns.js";
22
- import { createRowIdentity as X } from "./row-identity.js";
23
- import { groupClientRows as Z, normalizeServerGroups as Q } from "./grouping.js";
24
- import { createRowHierarchy as $ } from "./row-hierarchy.js";
25
- import { createTableUrlState as ee } from "./url-state.js";
26
- import { createSavedViews as te } from "./saved-views.js";
27
- import { englishTableMessages as ne, resolveTableMessages as re } from "./messages.js";
28
- import { FilterBar as ie } from "./FilterBar.js";
29
- import { DataTable as ae } from "./DataTable.js";
30
- import { QueryBuilder as oe } from "./QueryBuilder.js";
31
- export { ae as DataTable, ie as FilterBar, oe as QueryBuilder, y as appendFilterCondition, d as appendQueryChild, e as assessServerPage, B as canMoveColumn, P as changeClientViewState, z as changeTableState, w as compileFilter, O as countClientFacets, J as createCellEdit, G as createClientExport, N as createClientView, M as createDebouncedSearch, $ as createRowHierarchy, X as createRowIdentity, te as createSavedViews, q as createServerExport, s as createTableRequests, W as createTableSelection, ee as createTableUrlState, f as defaultQueryRule, Y as defineColumns, c as deserializeFilter, I as deserializeState, ne as englishTableMessages, T as filterClientRows, k as formatSearchQuery, t as getPageRange, Z as groupClientRows, b as listFilterConditions, V as moveColumn, p as moveQueryNode, Q as normalizeServerGroups, H as orderColumnStates, n as paginateClientRows, F as parseClientViewState, l as parseFilter, r as parsePagination, A as parseSearchQuery, E as parseSorting, L as parseTableState, U as placeColumn, m as queryBuilderFilterColumns, h as queryNodeAt, x as removeFilterColumnConditions, S as removeFilterCondition, g as removeQueryNode, C as replaceFilterCondition, _ as replaceQueryNode, i as resetPagination, a as resizePagination, o as resolvePagination, re as resolveTableMessages, j as searchClientRows, K as selectClientRows, u as serializeFilter, R as serializeState, D as sortClientRows, v as toggleQueryNegation };
1
+ import { assessCursorPage as e, assessServerPage as t, getPageRange as n, paginateClientRows as r, parseCursorPagination as i, parsePagination as a, parseServerPagination as o, resetPagination as s, resizePagination as c, resolvePagination as l } from "./pagination.js";
2
+ import { createTableRequests as u } from "./requests.js";
3
+ import { deserializeFilter as d, parseFilter as f, serializeFilter as p } from "./filter.js";
4
+ import { appendQueryChild as m, defaultQueryRule as h, moveQueryNode as g, queryBuilderFilterColumns as _, queryNodeAt as v, removeQueryNode as y, replaceQueryNode as b, toggleQueryNegation as x } from "./query-builder-state.js";
5
+ import { appendFilterCondition as S, listFilterConditions as C, removeFilterColumnConditions as w, removeFilterCondition as T, replaceFilterCondition as E } from "./filter-bar-state.js";
6
+ import { compileFilter as D, filterClientRows as O } from "./filter-client.js";
7
+ import { parseSorting as k, sortClientRows as A } from "./sorting.js";
8
+ import { countClientFacets as j } from "./facets.js";
9
+ import { formatSearchQuery as M, parseSearchQuery as N, searchClientRows as P } from "./search.js";
10
+ import { createDebouncedSearch as F } from "./search-controller.js";
11
+ import { createClientView as I } from "./client-view.js";
12
+ import { changeClientViewState as L, parseClientViewState as R } from "./client-state.js";
13
+ import { deserializeState as z, parseTableState as B, serializeState as V } from "./table-state.js";
14
+ import { changeTableState as H } from "./table-state-changes.js";
15
+ import { canMoveColumn as U, moveColumn as W, orderColumnStates as G, placeColumn as K } from "./column-layout.js";
16
+ import { createTableSelection as q } from "./selection.js";
17
+ import { createClientExport as J } from "./export.js";
18
+ import { selectClientRows as Y } from "./selection-client.js";
19
+ import { createServerExport as X } from "./server-export.js";
20
+ import { createCellEdit as Z } from "./cell-edit.js";
21
+ import { defineColumns as Q } from "./columns.js";
22
+ import { createRowIdentity as $ } from "./row-identity.js";
23
+ import { groupClientRows as ee, normalizeServerGroups as te } from "./grouping.js";
24
+ import { createRowHierarchy as ne } from "./row-hierarchy.js";
25
+ import { createTableUrlState as re } from "./url-state.js";
26
+ import { createSavedViews as ie } from "./saved-views.js";
27
+ import { englishTableMessages as ae, resolveTableMessages as oe } from "./messages.js";
28
+ import { DataTable as se, createDataTable as ce } from "./DataTable.js";
29
+ import { cellEditingFeature as le, groupingFeature as ue, hierarchyFeature as de } from "./data-table-features.js";
30
+ import { FilterBar as fe, filterBarFeature as pe } from "./FilterBar.js";
31
+ import { QueryBuilder as me } from "./QueryBuilder.js";
32
+ export { se as DataTable, fe as FilterBar, me as QueryBuilder, S as appendFilterCondition, m as appendQueryChild, e as assessCursorPage, t as assessServerPage, U as canMoveColumn, le as cellEditingFeature, L as changeClientViewState, H as changeTableState, D as compileFilter, j as countClientFacets, Z as createCellEdit, J as createClientExport, I as createClientView, ce as createDataTable, F as createDebouncedSearch, ne as createRowHierarchy, $ as createRowIdentity, ie as createSavedViews, X as createServerExport, u as createTableRequests, q as createTableSelection, re as createTableUrlState, h as defaultQueryRule, Q as defineColumns, d as deserializeFilter, z as deserializeState, ae as englishTableMessages, pe as filterBarFeature, O as filterClientRows, M as formatSearchQuery, n as getPageRange, ee as groupClientRows, ue as groupingFeature, de as hierarchyFeature, C as listFilterConditions, W as moveColumn, g as moveQueryNode, te as normalizeServerGroups, G as orderColumnStates, r as paginateClientRows, R as parseClientViewState, i as parseCursorPagination, f as parseFilter, a as parsePagination, N as parseSearchQuery, o as parseServerPagination, k as parseSorting, B as parseTableState, K as placeColumn, _ as queryBuilderFilterColumns, v as queryNodeAt, w as removeFilterColumnConditions, T as removeFilterCondition, y as removeQueryNode, E as replaceFilterCondition, b as replaceQueryNode, s as resetPagination, c as resizePagination, l as resolvePagination, oe as resolveTableMessages, P as searchClientRows, Y as selectClientRows, p as serializeFilter, V as serializeState, A as sortClientRows, x as toggleQueryNegation };
@@ -13,6 +13,9 @@ export declare const englishTableMessages: Readonly<{
13
13
  tableControls: "{caption} table controls";
14
14
  resultCountOne: "{count} result";
15
15
  resultCount: "{count} results";
16
+ resultCountEstimate: "About {count} results";
17
+ resultCountAtLeast: "{count}+ results";
18
+ cursorPageRows: "Rows on this page: {count}";
16
19
  previousResults: "Previous results";
17
20
  clearFilters: "Clear filters";
18
21
  clearSearchAndFilters: "Clear search and filters";
@@ -38,7 +41,7 @@ export declare const englishTableMessages: Readonly<{
38
41
  retryExport: "Retry export";
39
42
  downloadLastExport: "Download last export";
40
43
  filters: "Filters";
41
- filterAdd: "+ Filter";
44
+ filterAdd: "Add filter";
42
45
  filterColumns: "Filter columns";
43
46
  filterSearchColumns: "Search filter columns";
44
47
  filterEdit: "Edit filter";
package/dist/messages.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/messages.ts
1
+ // src/messages.ts
2
2
  var e = Object.freeze({
3
3
  loading: "Loading",
4
4
  refreshing: "Refreshing, showing existing results",
@@ -14,6 +14,9 @@ var e = Object.freeze({
14
14
  tableControls: "{caption} table controls",
15
15
  resultCountOne: "{count} result",
16
16
  resultCount: "{count} results",
17
+ resultCountEstimate: "About {count} results",
18
+ resultCountAtLeast: "{count}+ results",
19
+ cursorPageRows: "Rows on this page: {count}",
17
20
  previousResults: "Previous results",
18
21
  clearFilters: "Clear filters",
19
22
  clearSearchAndFilters: "Clear search and filters",
@@ -39,7 +42,7 @@ var e = Object.freeze({
39
42
  retryExport: "Retry export",
40
43
  downloadLastExport: "Download last export",
41
44
  filters: "Filters",
42
- filterAdd: "+ Filter",
45
+ filterAdd: "Add filter",
43
46
  filterColumns: "Filter columns",
44
47
  filterSearchColumns: "Search filter columns",
45
48
  filterEdit: "Edit filter",
@@ -120,5 +123,4 @@ function t(t) {
120
123
  ...t
121
124
  });
122
125
  }
123
- //#endregion
124
126
  export { e as englishTableMessages, t as resolveTableMessages };
@@ -21,11 +21,51 @@ export type ServerPageAssessment<Row> = {
21
21
  readonly pagination: PageState;
22
22
  readonly total: number;
23
23
  };
24
+ /** Opaque server cursor plus the side of it to read. Null requests the first page. */
25
+ export interface CursorPosition {
26
+ readonly direction: "after" | "before";
27
+ readonly value: string;
28
+ }
29
+ export interface CursorPagination {
30
+ readonly kind: "cursor";
31
+ readonly pageSize: number;
32
+ readonly cursor: CursorPosition | null;
33
+ }
34
+ /** Every server pagination choice: complete (false), numbered, or cursor. */
35
+ export type ServerPagination = TablePagination | CursorPagination;
36
+ /** Optional full-query count. Estimates and lower bounds are announced as such, never as exact counts. */
37
+ export interface CursorTotal {
38
+ readonly kind: "exact" | "estimate" | "atLeast";
39
+ readonly value: number;
40
+ }
41
+ export interface CursorPageResult<Row> {
42
+ readonly rows: readonly Row[];
43
+ /** Null when no later page exists. */
44
+ readonly nextCursor: string | null;
45
+ /** Null when no earlier page exists. */
46
+ readonly previousCursor: string | null;
47
+ readonly total?: CursorTotal;
48
+ }
49
+ export type CursorPageAssessment<Row> = {
50
+ readonly kind: "accepted";
51
+ readonly pagination: CursorPagination;
52
+ readonly result: CursorPageResult<Row>;
53
+ } | {
54
+ readonly kind: "refetch";
55
+ readonly pagination: CursorPagination;
56
+ };
24
57
  export declare function parsePagination(value: unknown): TablePagination;
25
58
  export declare function resolvePagination(mode: "client" | "server", value?: TablePagination): TablePagination;
26
- /** Filter and sort changes reset the requested page, not accepted rows. */
59
+ export declare function parseCursorPagination(value: unknown): CursorPagination;
60
+ /** Validates any server choice. Cursor state is distinguished by its kind field. */
61
+ export declare function parseServerPagination(value: unknown): ServerPagination;
62
+ /** Filter and sort changes reset the requested page, not accepted rows. Cursor state returns to the first page. */
27
63
  export declare function resetPagination(value: TablePagination): TablePagination;
64
+ export declare function resetPagination(value: CursorPagination): CursorPagination;
65
+ export declare function resetPagination(value: ServerPagination): ServerPagination;
28
66
  export declare function resizePagination(value: PageState, pageSize: number): PageState;
67
+ export declare function resizePagination(value: CursorPagination, pageSize: number): CursorPagination;
68
+ export declare function resizePagination(value: PageState | CursorPagination, pageSize: number): PageState | CursorPagination;
29
69
  /** Clamp before multiplying so even extreme valid requested indices cannot overflow the offset. */
30
70
  export declare function getPageRange(value: PageState, total: number): PageRange;
31
71
  /** Call after transforming the complete client dataset, never on an individual server page. */
@@ -34,3 +74,5 @@ export declare function paginateClientRows<Row>(rows: readonly Row[], value?: Ta
34
74
  };
35
75
  /** Validate a single response; never fetch, concatenate pages, or publish an invalid result. */
36
76
  export declare function assessServerPage<Row>(value: TablePagination, result: PageResult<Row>): ServerPageAssessment<Row>;
77
+ /** Validate a single cursor response. An empty later page (for example after deletions) refetches the first page. */
78
+ export declare function assessCursorPage<Row>(value: CursorPagination, result: CursorPageResult<Row>): CursorPageAssessment<Row>;
@@ -1,102 +1,156 @@
1
- //#region src/pagination.ts
2
- function e(e, t) {
1
+ // src/pagination.ts
2
+ var e = "Server mode requires explicit pagination, including explicit false for complete results";
3
+ function t(e, t) {
3
4
  if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw Error(`${t} must be a nonnegative safe integer`);
4
5
  }
5
- function t(t) {
6
- if (t === !1) return !1;
7
- if (typeof t != "object" || !t || Array.isArray(t) || !("pageIndex" in t) || !("pageSize" in t)) throw Error("pagination must be false or { pageIndex, pageSize }");
8
- if (Object.keys(t).some((e) => e !== "pageIndex" && e !== "pageSize")) throw Error("pagination contains unknown fields");
9
- if (e(t.pageIndex, "pageIndex"), e(t.pageSize, "pageSize"), t.pageSize === 0) throw Error("pageSize must be positive");
10
- return Object.freeze({
11
- pageIndex: t.pageIndex,
12
- pageSize: t.pageSize
6
+ function n(e) {
7
+ if (t(e, "pageSize"), e === 0) throw Error("pageSize must be positive");
8
+ return e;
9
+ }
10
+ function r(e, t) {
11
+ if (Object.keys(e).some((e) => !t.includes(e))) throw Error("pagination contains unknown fields");
12
+ }
13
+ function i(e, t) {
14
+ if (typeof e != "string" || !e) throw Error(`${t} must be a nonempty string or null`);
15
+ return e;
16
+ }
17
+ function a(e) {
18
+ if (e === !1) return !1;
19
+ if (typeof e != "object" || !e || Array.isArray(e) || !("pageIndex" in e) || !("pageSize" in e)) throw Error("pagination must be false or { pageIndex, pageSize }");
20
+ return r(e, ["pageIndex", "pageSize"]), t(e.pageIndex, "pageIndex"), Object.freeze({
21
+ pageIndex: e.pageIndex,
22
+ pageSize: n(e.pageSize)
13
23
  });
14
24
  }
15
- function n(e, n) {
16
- if (e !== "client" && e !== "server") throw Error("Table mode must be client or server");
25
+ function o(t, n) {
26
+ if (t !== "client" && t !== "server") throw Error("Table mode must be client or server");
17
27
  if (n === void 0) {
18
- if (e === "server") throw Error("Server mode requires explicit pagination, including explicit false for complete results");
28
+ if (t === "server") throw Error(e);
19
29
  return !1;
20
30
  }
21
- return t(n);
31
+ return a(n);
22
32
  }
23
- function r(e) {
24
- let n = t(e);
25
- return n !== !1 && Object.freeze({
26
- ...n,
27
- pageIndex: 0
33
+ function s(e) {
34
+ if (typeof e != "object" || !e || Array.isArray(e) || !("kind" in e) || e.kind !== "cursor" || !("pageSize" in e) || !("cursor" in e)) throw Error("cursor pagination must be { kind: \"cursor\", pageSize, cursor }");
35
+ r(e, [
36
+ "kind",
37
+ "pageSize",
38
+ "cursor"
39
+ ]);
40
+ let t = e.cursor;
41
+ if (t === null) return Object.freeze({
42
+ kind: "cursor",
43
+ pageSize: n(e.pageSize),
44
+ cursor: null
45
+ });
46
+ if (typeof t != "object" || !("direction" in t) || !("value" in t) || t.direction !== "after" && t.direction !== "before") throw Error("cursor must be null or { direction: after | before, value }");
47
+ return r(t, ["direction", "value"]), Object.freeze({
48
+ kind: "cursor",
49
+ pageSize: n(e.pageSize),
50
+ cursor: Object.freeze({
51
+ direction: t.direction,
52
+ value: i(t.value, "cursor value")
53
+ })
28
54
  });
29
55
  }
30
- function i(n, r) {
31
- if (t(n) === !1) throw Error("Page-size changes require paginated state");
32
- if (e(r, "pageSize"), r === 0) throw Error("pageSize must be positive");
33
- return Object.freeze({
56
+ function c(t) {
57
+ if (t === void 0) throw Error(e);
58
+ return typeof t == "object" && t && "kind" in t ? s(t) : a(t);
59
+ }
60
+ function l(e) {
61
+ let t = c(e);
62
+ return t !== !1 && u(t, t.pageSize);
63
+ }
64
+ function u(e, t) {
65
+ let r = c(e);
66
+ if (r === !1) throw Error("Page-size changes require paginated state");
67
+ return "kind" in r ? Object.freeze({
68
+ kind: "cursor",
69
+ pageSize: n(t),
70
+ cursor: null
71
+ }) : Object.freeze({
34
72
  pageIndex: 0,
35
- pageSize: r
73
+ pageSize: n(t)
36
74
  });
37
75
  }
38
- function a(n, r) {
39
- let i = t(n);
40
- if (i === !1) throw Error("Page ranges require paginated state");
41
- e(r, "total");
42
- let a = Math.ceil(r / i.pageSize), o = Math.min(i.pageIndex, Math.max(0, a - 1)), s = o * i.pageSize, c = s + Math.min(i.pageSize, r - s);
76
+ function d(e, n) {
77
+ let r = a(e);
78
+ if (r === !1) throw Error("Page ranges require paginated state");
79
+ t(n, "total");
80
+ let i = Math.ceil(n / r.pageSize), o = Math.min(r.pageIndex, Math.max(0, i - 1)), s = o * r.pageSize, c = s + Math.min(r.pageSize, n - s);
43
81
  return Object.freeze({
44
82
  pageIndex: o,
45
- pageSize: i.pageSize,
46
- pageCount: a,
83
+ pageSize: r.pageSize,
84
+ pageCount: i,
47
85
  start: s,
48
86
  end: c
49
87
  });
50
88
  }
51
- function o(e, n = !1) {
52
- let r = t(n);
53
- if (r === !1) return {
89
+ function f(e, t = !1) {
90
+ let n = a(t);
91
+ if (n === !1) return {
54
92
  rows: e,
55
93
  total: e.length,
56
94
  pagination: !1
57
95
  };
58
- let i = a(r, e.length);
96
+ let r = d(n, e.length);
59
97
  return {
60
- rows: e.slice(i.start, i.end),
98
+ rows: e.slice(r.start, r.end),
61
99
  total: e.length,
62
100
  pagination: Object.freeze({
63
- pageIndex: i.pageIndex,
64
- pageSize: i.pageSize
101
+ pageIndex: r.pageIndex,
102
+ pageSize: r.pageSize
65
103
  })
66
104
  };
67
105
  }
68
- function s(n, r) {
69
- let i = t(n);
70
- if (e(r.total, "total"), !Array.isArray(r.rows)) throw Error("Server rows must be an array");
71
- if (i === !1) {
72
- if (r.rows.length !== r.total) throw Error("Non-paginated server results must be complete: rows.length must equal total");
106
+ function p(e, n) {
107
+ let r = a(e);
108
+ if (t(n.total, "total"), !Array.isArray(n.rows)) throw Error("Server rows must be an array");
109
+ if (r === !1) {
110
+ if (n.rows.length !== n.total) throw Error("Non-paginated server results must be complete: rows.length must equal total");
73
111
  return {
74
112
  kind: "accepted",
75
113
  pagination: !1,
76
- result: r
114
+ result: n
77
115
  };
78
116
  }
79
- let o = a(i, r.total);
80
- if (o.pageIndex !== i.pageIndex && r.total > 0) {
81
- if (r.rows.length) throw Error("Out-of-range server page must not contain rows");
117
+ let i = d(r, n.total);
118
+ if (i.pageIndex !== r.pageIndex && n.total > 0) {
119
+ if (n.rows.length) throw Error("Out-of-range server page must not contain rows");
82
120
  return {
83
121
  kind: "refetch",
84
122
  pagination: Object.freeze({
85
- pageIndex: o.pageIndex,
86
- pageSize: o.pageSize
123
+ pageIndex: i.pageIndex,
124
+ pageSize: i.pageSize
87
125
  }),
88
- total: r.total
126
+ total: n.total
89
127
  };
90
128
  }
91
- if (r.rows.length !== o.end - o.start) throw Error("Server page row count does not match the requested page and total");
129
+ if (n.rows.length !== i.end - i.start) throw Error("Server page row count does not match the requested page and total");
92
130
  return {
93
131
  kind: "accepted",
94
132
  pagination: Object.freeze({
95
- pageIndex: o.pageIndex,
96
- pageSize: o.pageSize
133
+ pageIndex: i.pageIndex,
134
+ pageSize: i.pageSize
97
135
  }),
98
- result: r
136
+ result: n
137
+ };
138
+ }
139
+ function m(e, n) {
140
+ let r = s(e);
141
+ if (!Array.isArray(n.rows)) throw Error("Server rows must be an array");
142
+ if (n.rows.length > r.pageSize) throw Error("Cursor page contains more rows than pageSize");
143
+ if (n.nextCursor !== null && i(n.nextCursor, "nextCursor"), n.previousCursor !== null && i(n.previousCursor, "previousCursor"), n.total !== void 0) {
144
+ if (typeof n.total != "object" || n.total === null || n.total.kind !== "exact" && n.total.kind !== "estimate" && n.total.kind !== "atLeast") throw Error("Cursor total must be { kind: exact | estimate | atLeast, value }");
145
+ t(n.total.value, "total value");
146
+ }
147
+ return n.rows.length === 0 && r.cursor !== null ? {
148
+ kind: "refetch",
149
+ pagination: l(r)
150
+ } : {
151
+ kind: "accepted",
152
+ pagination: r,
153
+ result: n
99
154
  };
100
155
  }
101
- //#endregion
102
- export { s as assessServerPage, a as getPageRange, o as paginateClientRows, t as parsePagination, r as resetPagination, i as resizePagination, n as resolvePagination };
156
+ export { m as assessCursorPage, p as assessServerPage, d as getPageRange, f as paginateClientRows, s as parseCursorPagination, a as parsePagination, c as parseServerPagination, l as resetPagination, u as resizePagination, o as resolvePagination };
@@ -1,5 +1,5 @@
1
1
  import { parseFilter as e } from "./filter.js";
2
- //#region src/query-builder-state.ts
2
+ // src/query-builder-state.ts
3
3
  function t(e) {
4
4
  let t = /* @__PURE__ */ new Set();
5
5
  return Object.freeze(e.map((e) => {
@@ -124,5 +124,4 @@ function l(t, n, i) {
124
124
  child: e
125
125
  })), i);
126
126
  }
127
- //#endregion
128
127
  export { o as appendQueryChild, n as defaultQueryRule, c as moveQueryNode, t as queryBuilderFilterColumns, i as queryNodeAt, s as removeQueryNode, a as replaceQueryNode, l as toggleQueryNegation };
@@ -1,6 +1,6 @@
1
- import type { PageResult, TablePagination } from "./pagination.ts";
1
+ import type { CursorPageResult, PageResult, ServerPagination } from "./pagination.ts";
2
2
  export interface TableRequestState {
3
- readonly pagination: TablePagination;
3
+ readonly pagination: ServerPagination;
4
4
  }
5
5
  export interface TableRequestSnapshot<State, Result> {
6
6
  readonly accepted: {
@@ -17,7 +17,7 @@ export interface InitialTableResult<State, Result> {
17
17
  readonly result: Result;
18
18
  }
19
19
  /** Framework-neutral request ownership. Read snapshots before/after awaiting request in the UI adapter. */
20
- export declare function createTableRequests<State extends TableRequestState, Result extends PageResult<unknown>>(onStateChange: (state: State, signal: AbortSignal) => Promise<Result>, initial?: InitialTableResult<State, Result>): {
20
+ export declare function createTableRequests<State extends TableRequestState, Result extends PageResult<unknown> | CursorPageResult<unknown>>(onStateChange: (state: State, signal: AbortSignal) => Promise<Result>, initial?: InitialTableResult<State, Result>): {
21
21
  getSnapshot: () => TableRequestSnapshot<State, Result>;
22
22
  request: (value: State) => Promise<TableRequestOutcome>;
23
23
  retry: () => Promise<TableRequestOutcome>;
package/dist/requests.js CHANGED
@@ -1,24 +1,34 @@
1
- import { assessServerPage as e, resolvePagination as t } from "./pagination.js";
2
- //#region src/requests.ts
3
- function n(n, r) {
4
- let i = {
1
+ import { assessCursorPage as e, assessServerPage as t, parseServerPagination as n } from "./pagination.js";
2
+ // src/requests.ts
3
+ function r(e) {
4
+ return "nextCursor" in e && "previousCursor" in e;
5
+ }
6
+ function i(i, a) {
7
+ let o = n(i);
8
+ if (o !== !1 && "kind" in o) {
9
+ if (!r(a)) throw Error("Cursor pagination results require nextCursor and previousCursor");
10
+ return e(o, a);
11
+ }
12
+ if (r(a)) throw Error("Numbered and complete server results must report total instead of cursors");
13
+ return t(o, a);
14
+ }
15
+ function a(e, t) {
16
+ let r = {
5
17
  accepted: null,
6
18
  requested: null,
7
19
  pending: !1,
8
20
  error: null
9
21
  };
10
- if (r) {
11
- let n = structuredClone(r.state);
12
- t("server", n.pagination);
13
- let a = e(n.pagination, r.result);
14
- if (a.kind !== "accepted") throw Error("Initial table results must describe a valid accepted page, not a page requiring refetch");
15
- i = {
22
+ if (t) {
23
+ let e = structuredClone(t.state), n = i(e.pagination, t.result);
24
+ if (n.kind !== "accepted") throw Error("Initial table results must describe a valid accepted page, not a page requiring refetch");
25
+ r = {
16
26
  accepted: {
17
27
  state: {
18
- ...n,
19
- pagination: a.pagination
28
+ ...e,
29
+ pagination: n.pagination
20
30
  },
21
- result: r.result
31
+ result: t.result
22
32
  },
23
33
  requested: null,
24
34
  pending: !1,
@@ -26,36 +36,36 @@ function n(n, r) {
26
36
  };
27
37
  }
28
38
  let a = 0n, o, s = !1, c = !1;
29
- async function l(r) {
39
+ async function l(t) {
30
40
  if (s) return "disposed";
31
41
  if (c) return "superseded";
32
42
  let l = ++a;
33
43
  if (o?.abort(), s) return "disposed";
34
44
  if (l !== a) return "superseded";
35
45
  let u = new AbortController();
36
- o = u, i = {
37
- ...i,
46
+ o = u, r = {
47
+ ...r,
38
48
  requested: null,
39
49
  pending: !0,
40
50
  error: null
41
51
  };
42
52
  try {
43
- let o = structuredClone(r);
44
- t("server", o.pagination), i = {
45
- ...i,
53
+ let o = structuredClone(t);
54
+ n(o.pagination), r = {
55
+ ...r,
46
56
  requested: structuredClone(o),
47
57
  pending: !0,
48
58
  error: null
49
59
  };
50
60
  for (let t = 0; t < 4; t++) {
51
- let t = await n(structuredClone(o), u.signal);
61
+ let t = await e(structuredClone(o), u.signal);
52
62
  if (s) return "disposed";
53
63
  if (l !== a) return "superseded";
54
- let r = e(o.pagination, t);
64
+ let n = i(o.pagination, t);
55
65
  if (o = {
56
66
  ...o,
57
- pagination: r.pagination
58
- }, r.kind === "accepted") return i = {
67
+ pagination: n.pagination
68
+ }, n.kind === "accepted") return r = {
59
69
  accepted: {
60
70
  state: o,
61
71
  result: t
@@ -67,8 +77,8 @@ function n(n, r) {
67
77
  }
68
78
  throw Error("Server page kept moving during clamping; retry the latest query");
69
79
  } catch (e) {
70
- return s ? "disposed" : l === a ? (i = {
71
- ...i,
80
+ return s ? "disposed" : l === a ? (r = {
81
+ ...r,
72
82
  pending: !1,
73
83
  error: e
74
84
  }, "failed") : "superseded";
@@ -80,7 +90,7 @@ function n(n, r) {
80
90
  if (c) return;
81
91
  c = !0, a++;
82
92
  let e = o;
83
- o = void 0, i = {
93
+ o = void 0, r = {
84
94
  accepted: null,
85
95
  requested: null,
86
96
  pending: !1,
@@ -93,14 +103,13 @@ function n(n, r) {
93
103
  }
94
104
  }
95
105
  return {
96
- getSnapshot: () => i,
106
+ getSnapshot: () => r,
97
107
  request: l,
98
- retry: () => i.requested ? l(i.requested) : Promise.resolve(s ? "disposed" : "failed"),
108
+ retry: () => r.requested ? l(r.requested) : Promise.resolve(s ? "disposed" : "failed"),
99
109
  clear: u,
100
110
  dispose: () => {
101
111
  s = !0, u();
102
112
  }
103
113
  };
104
114
  }
105
- //#endregion
106
- export { n as createTableRequests };
115
+ export { a as createTableRequests };
@@ -1,4 +1,4 @@
1
- //#region src/row-hierarchy.ts
1
+ // src/row-hierarchy.ts
2
2
  function e(e, t) {
3
3
  if (!Array.isArray(e)) throw Error(`${t} must be an array`);
4
4
  let n = [];
@@ -166,5 +166,4 @@ function t(t) {
166
166
  }
167
167
  };
168
168
  }
169
- //#endregion
170
169
  export { t as createRowHierarchy };
@@ -1,4 +1,4 @@
1
- //#region src/row-identity.ts
1
+ // src/row-identity.ts
2
2
  function e(e) {
3
3
  if (typeof e != "function") throw Error("getRowId must be a function");
4
4
  let t = /* @__PURE__ */ new WeakMap();
@@ -32,5 +32,4 @@ function e(e) {
32
32
  }
33
33
  };
34
34
  }
35
- //#endregion
36
35
  export { e as createRowIdentity };