@macrostrat/data-sheet 4.1.1 → 4.2.1

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 (304) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/actions/builtin.cjs +1 -1
  3. package/dist/actions/builtin.cjs.map +1 -1
  4. package/dist/actions/builtin.d.ts +0 -2
  5. package/dist/actions/builtin.js +1 -1
  6. package/dist/actions/builtin.js.map +1 -1
  7. package/dist/actions/clipboard.cjs +1 -1
  8. package/dist/actions/clipboard.cjs.map +1 -1
  9. package/dist/actions/clipboard.d.ts +3 -2
  10. package/dist/actions/clipboard.js +1 -1
  11. package/dist/actions/clipboard.js.map +1 -1
  12. package/dist/actions/column-controls.cjs +7 -196
  13. package/dist/actions/column-controls.cjs.map +1 -1
  14. package/dist/actions/column-controls.d.ts +1 -1
  15. package/dist/actions/column-controls.js +5 -194
  16. package/dist/actions/column-controls.js.map +1 -1
  17. package/dist/actions/column-filter.cjs +24 -73
  18. package/dist/actions/column-filter.cjs.map +1 -1
  19. package/dist/actions/column-filter.d.ts +6 -4
  20. package/dist/actions/column-filter.js +25 -74
  21. package/dist/actions/column-filter.js.map +1 -1
  22. package/dist/actions/context.cjs +147 -0
  23. package/dist/actions/context.cjs.map +1 -0
  24. package/dist/actions/context.d.ts +93 -0
  25. package/dist/actions/context.js +145 -0
  26. package/dist/actions/context.js.map +1 -0
  27. package/dist/actions/edit-actions.cjs.map +1 -1
  28. package/dist/actions/edit-actions.d.ts +3 -1
  29. package/dist/actions/edit-actions.js.map +1 -1
  30. package/dist/actions/index.d.ts +2 -3
  31. package/dist/actions/selection.cjs +70 -115
  32. package/dist/actions/selection.cjs.map +1 -1
  33. package/dist/actions/selection.d.ts +22 -12
  34. package/dist/actions/selection.js +71 -114
  35. package/dist/actions/selection.js.map +1 -1
  36. package/dist/actions/table-actions.cjs +41 -0
  37. package/dist/actions/table-actions.cjs.map +1 -0
  38. package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
  39. package/dist/actions/{table-controls.js → table-actions.js} +2 -23
  40. package/dist/actions/table-actions.js.map +1 -0
  41. package/dist/actions/types.d.ts +11 -89
  42. package/dist/components/cell-detail.cjs +6 -6
  43. package/dist/components/cell-detail.cjs.map +1 -1
  44. package/dist/components/cell-detail.js +1 -1
  45. package/dist/components/colors.cjs.map +1 -1
  46. package/dist/components/colors.js.map +1 -1
  47. package/dist/components/editor-popup.cjs +7 -7
  48. package/dist/components/editor-popup.cjs.map +1 -1
  49. package/dist/components/editor-popup.js +1 -1
  50. package/dist/components/index.d.ts +2 -1
  51. package/dist/components/indicators/filter-and-sort.cjs +378 -0
  52. package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
  53. package/dist/components/indicators/filter-and-sort.d.ts +59 -0
  54. package/dist/components/indicators/filter-and-sort.js +376 -0
  55. package/dist/components/indicators/filter-and-sort.js.map +1 -0
  56. package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
  57. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
  58. package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
  59. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
  60. package/dist/components/indicators/index.d.ts +4 -0
  61. package/dist/components/indicators/selection.cjs +113 -0
  62. package/dist/components/indicators/selection.cjs.map +1 -0
  63. package/dist/components/indicators/selection.d.ts +3 -0
  64. package/dist/components/indicators/selection.js +111 -0
  65. package/dist/components/indicators/selection.js.map +1 -0
  66. package/dist/components/indicators/selection.module.sass.cjs +19 -0
  67. package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
  68. package/dist/components/indicators/selection.module.sass.js +17 -0
  69. package/dist/components/indicators/selection.module.sass.js.map +1 -0
  70. package/dist/components/indicators/unified-filters.cjs +130 -0
  71. package/dist/components/indicators/unified-filters.cjs.map +1 -0
  72. package/dist/components/indicators/unified-filters.d.ts +10 -0
  73. package/dist/components/indicators/unified-filters.js +130 -0
  74. package/dist/components/indicators/unified-filters.js.map +1 -0
  75. package/dist/components/indicators/view-info.cjs +59 -0
  76. package/dist/components/indicators/view-info.cjs.map +1 -0
  77. package/dist/components/indicators/view-info.d.ts +11 -0
  78. package/dist/components/{view-info.js → indicators/view-info.js} +20 -16
  79. package/dist/components/indicators/view-info.js.map +1 -0
  80. package/dist/components/text-areas.cjs +5 -5
  81. package/dist/components/text-areas.cjs.map +1 -1
  82. package/dist/components/text-areas.js +1 -1
  83. package/dist/components/toolbars/actions-toolbar.cjs +185 -0
  84. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
  85. package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
  86. package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
  87. package/dist/components/toolbars/actions-toolbar.js.map +1 -0
  88. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
  89. package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
  90. package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
  91. package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
  92. package/dist/components/toolbars/active-filters.cjs +120 -0
  93. package/dist/components/toolbars/active-filters.cjs.map +1 -0
  94. package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
  95. package/dist/components/toolbars/active-filters.js +120 -0
  96. package/dist/components/toolbars/active-filters.js.map +1 -0
  97. package/dist/components/toolbars/index.d.ts +2 -0
  98. package/dist/data-panel.cjs +291 -0
  99. package/dist/data-panel.cjs.map +1 -0
  100. package/dist/data-panel.d.ts +110 -0
  101. package/dist/data-panel.js +289 -0
  102. package/dist/data-panel.js.map +1 -0
  103. package/dist/data-panel.module.sass.cjs +40 -0
  104. package/dist/data-panel.module.sass.cjs.map +1 -0
  105. package/dist/data-panel.module.sass.js +38 -0
  106. package/dist/data-panel.module.sass.js.map +1 -0
  107. package/dist/{core.cjs → data-sheet.cjs} +126 -188
  108. package/dist/data-sheet.cjs.map +1 -0
  109. package/dist/data-sheet.css +241 -13
  110. package/dist/data-sheet.d.ts +16 -0
  111. package/dist/{core.js → data-sheet.js} +95 -157
  112. package/dist/data-sheet.js.map +1 -0
  113. package/dist/data-view.cjs +47 -0
  114. package/dist/data-view.cjs.map +1 -0
  115. package/dist/data-view.d.ts +15 -0
  116. package/dist/data-view.js +45 -0
  117. package/dist/data-view.js.map +1 -0
  118. package/dist/filters/operators.cjs +19 -2
  119. package/dist/filters/operators.cjs.map +1 -1
  120. package/dist/filters/operators.d.ts +4 -3
  121. package/dist/filters/operators.js +19 -2
  122. package/dist/filters/operators.js.map +1 -1
  123. package/dist/index.cjs +106 -47
  124. package/dist/index.cjs.map +1 -1
  125. package/dist/index.d.ts +4 -3
  126. package/dist/index.js +76 -17
  127. package/dist/index.js.map +1 -1
  128. package/dist/notifications.cjs +4 -4
  129. package/dist/notifications.cjs.map +1 -1
  130. package/dist/notifications.js +1 -1
  131. package/dist/postgrest-table/data-loaders.cjs +128 -95
  132. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  133. package/dist/postgrest-table/data-loaders.d.ts +52 -82
  134. package/dist/postgrest-table/data-loaders.js +109 -76
  135. package/dist/postgrest-table/data-loaders.js.map +1 -1
  136. package/dist/postgrest-table/index.cjs +18 -17
  137. package/dist/postgrest-table/index.cjs.map +1 -1
  138. package/dist/postgrest-table/index.d.ts +4 -3
  139. package/dist/postgrest-table/index.js +9 -8
  140. package/dist/postgrest-table/index.js.map +1 -1
  141. package/dist/{utils → provider}/column-spec.cjs +23 -9
  142. package/dist/provider/column-spec.cjs.map +1 -0
  143. package/dist/{utils → provider}/column-spec.d.ts +73 -2
  144. package/dist/{utils → provider}/column-spec.js +24 -10
  145. package/dist/provider/column-spec.js.map +1 -0
  146. package/dist/provider/core.cjs +382 -0
  147. package/dist/provider/core.cjs.map +1 -0
  148. package/dist/provider/core.d.ts +74 -0
  149. package/dist/provider/core.js +380 -0
  150. package/dist/provider/core.js.map +1 -0
  151. package/dist/provider/index.d.ts +7 -0
  152. package/dist/provider/interactions.cjs +128 -0
  153. package/dist/provider/interactions.cjs.map +1 -0
  154. package/dist/provider/interactions.d.ts +39 -0
  155. package/dist/provider/interactions.js +128 -0
  156. package/dist/provider/interactions.js.map +1 -0
  157. package/dist/provider/selection.cjs +29 -0
  158. package/dist/provider/selection.cjs.map +1 -0
  159. package/dist/provider/selection.d.ts +9 -0
  160. package/dist/provider/selection.js +29 -0
  161. package/dist/provider/selection.js.map +1 -0
  162. package/dist/provider/table-data.cjs +92 -0
  163. package/dist/provider/table-data.cjs.map +1 -0
  164. package/dist/provider/table-data.d.ts +81 -0
  165. package/dist/provider/table-data.js +92 -0
  166. package/dist/provider/table-data.js.map +1 -0
  167. package/dist/provider/types.cjs +22 -0
  168. package/dist/provider/types.cjs.map +1 -0
  169. package/dist/provider/types.d.ts +256 -0
  170. package/dist/provider/types.js +22 -0
  171. package/dist/provider/types.js.map +1 -0
  172. package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
  173. package/dist/provider/zustand-store.cjs.map +1 -0
  174. package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
  175. package/dist/provider/zustand-store.js.map +1 -0
  176. package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
  177. package/dist/renderers/cell-renderer.cjs.map +1 -0
  178. package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
  179. package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
  180. package/dist/renderers/cell-renderer.js.map +1 -0
  181. package/dist/renderers/column-header-cell.cjs +21 -13
  182. package/dist/renderers/column-header-cell.cjs.map +1 -1
  183. package/dist/renderers/column-header-cell.d.ts +3 -2
  184. package/dist/renderers/column-header-cell.js +20 -12
  185. package/dist/renderers/column-header-cell.js.map +1 -1
  186. package/dist/renderers/index.d.ts +1 -0
  187. package/dist/types.cjs +7 -19
  188. package/dist/types.cjs.map +1 -1
  189. package/dist/types.d.ts +117 -229
  190. package/dist/types.js +7 -19
  191. package/dist/types.js.map +1 -1
  192. package/dist/utils/atoms.cjs +24 -0
  193. package/dist/utils/atoms.cjs.map +1 -0
  194. package/dist/utils/atoms.d.ts +4 -0
  195. package/dist/utils/atoms.js +24 -0
  196. package/dist/utils/atoms.js.map +1 -0
  197. package/dist/utils/debug-overlay.cjs.map +1 -1
  198. package/dist/utils/debug-overlay.js.map +1 -1
  199. package/dist/utils/index.d.ts +2 -3
  200. package/dist/utils/key-handling.cjs +140 -139
  201. package/dist/utils/key-handling.cjs.map +1 -1
  202. package/dist/utils/key-handling.d.ts +4 -2
  203. package/dist/utils/key-handling.js +136 -135
  204. package/dist/utils/key-handling.js.map +1 -1
  205. package/dist/utils/validation.cjs +6 -1
  206. package/dist/utils/validation.cjs.map +1 -1
  207. package/dist/utils/validation.d.ts +1 -1
  208. package/dist/utils/validation.js +6 -1
  209. package/dist/utils/validation.js.map +1 -1
  210. package/package.json +4 -3
  211. package/src/actions/builtin.ts +1 -4
  212. package/src/actions/clipboard.ts +4 -3
  213. package/src/actions/column-controls.ts +12 -245
  214. package/src/actions/column-filter.ts +28 -92
  215. package/src/actions/context.ts +299 -0
  216. package/src/actions/edit-actions.ts +3 -1
  217. package/src/actions/index.ts +2 -3
  218. package/src/actions/selection.ts +109 -156
  219. package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
  220. package/src/actions/types.ts +17 -101
  221. package/src/components/colors.ts +1 -1
  222. package/src/components/index.ts +2 -1
  223. package/src/components/indicators/filter-and-sort.module.sass +13 -0
  224. package/src/components/indicators/filter-and-sort.ts +478 -0
  225. package/src/components/indicators/index.ts +4 -0
  226. package/src/components/indicators/selection.module.sass +22 -0
  227. package/src/components/indicators/selection.ts +141 -0
  228. package/src/components/indicators/unified-filters.ts +161 -0
  229. package/src/components/{view-info.ts → indicators/view-info.ts} +19 -30
  230. package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
  231. package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
  232. package/src/components/toolbars/active-filters.ts +150 -0
  233. package/src/components/toolbars/index.ts +2 -0
  234. package/src/data-panel.module.sass +185 -0
  235. package/src/data-panel.ts +556 -0
  236. package/src/{core.ts → data-sheet.ts} +156 -327
  237. package/src/data-view.ts +70 -0
  238. package/src/filters/operators.ts +33 -3
  239. package/src/index.ts +4 -3
  240. package/src/postgrest-table/data-loaders.ts +244 -171
  241. package/src/postgrest-table/index.ts +10 -9
  242. package/src/{utils → provider}/column-spec.ts +30 -15
  243. package/src/provider/core.ts +585 -0
  244. package/src/provider/index.ts +7 -0
  245. package/src/provider/interactions.ts +161 -0
  246. package/src/provider/selection.ts +31 -0
  247. package/src/provider/table-data.ts +178 -0
  248. package/src/provider/types.ts +273 -0
  249. package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
  250. package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
  251. package/src/renderers/column-header-cell.ts +21 -14
  252. package/src/renderers/index.ts +1 -0
  253. package/src/types.ts +137 -239
  254. package/src/utils/atoms.ts +28 -0
  255. package/src/utils/debug-overlay.ts +1 -1
  256. package/src/utils/index.ts +2 -8
  257. package/src/utils/key-handling.ts +170 -164
  258. package/src/utils/validation.ts +7 -2
  259. package/dist/actions/filters.cjs +0 -139
  260. package/dist/actions/filters.cjs.map +0 -1
  261. package/dist/actions/filters.js +0 -139
  262. package/dist/actions/filters.js.map +0 -1
  263. package/dist/actions/table-controls.cjs +0 -62
  264. package/dist/actions/table-controls.cjs.map +0 -1
  265. package/dist/actions/table-controls.js.map +0 -1
  266. package/dist/actions/toolbar.cjs +0 -260
  267. package/dist/actions/toolbar.cjs.map +0 -1
  268. package/dist/actions/toolbar.js.map +0 -1
  269. package/dist/actions/toolbar.module.sass.cjs +0 -27
  270. package/dist/actions/toolbar.module.sass.cjs.map +0 -1
  271. package/dist/actions/toolbar.module.sass.js +0 -25
  272. package/dist/actions/toolbar.module.sass.js.map +0 -1
  273. package/dist/cell-renderer.cjs.map +0 -1
  274. package/dist/cell-renderer.js.map +0 -1
  275. package/dist/components/view-info.cjs +0 -55
  276. package/dist/components/view-info.cjs.map +0 -1
  277. package/dist/components/view-info.d.ts +0 -5
  278. package/dist/components/view-info.js.map +0 -1
  279. package/dist/core.cjs.map +0 -1
  280. package/dist/core.d.ts +0 -117
  281. package/dist/core.js.map +0 -1
  282. package/dist/provider.cjs +0 -197
  283. package/dist/provider.cjs.map +0 -1
  284. package/dist/provider.d.ts +0 -26
  285. package/dist/provider.js +0 -195
  286. package/dist/provider.js.map +0 -1
  287. package/dist/table-updates/data-parameter.d.ts +0 -14
  288. package/dist/table-updates/filter.d.ts +0 -16
  289. package/dist/table-updates/index.d.ts +0 -19
  290. package/dist/utils/column-spec.cjs.map +0 -1
  291. package/dist/utils/column-spec.js.map +0 -1
  292. package/dist/utils/index.cjs +0 -9
  293. package/dist/utils/index.cjs.map +0 -1
  294. package/dist/utils/index.js +0 -9
  295. package/dist/utils/index.js.map +0 -1
  296. package/dist/zustand-store.cjs.map +0 -1
  297. package/dist/zustand-store.js.map +0 -1
  298. package/src/actions/filters.ts +0 -176
  299. package/src/components/actions.module.sass +0 -8
  300. package/src/provider.ts +0 -267
  301. package/src/table-updates/data-parameter.ts +0 -44
  302. package/src/table-updates/filter.ts +0 -124
  303. package/src/table-updates/index.ts +0 -239
  304. /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
@@ -1,14 +1,15 @@
1
1
  import { PostgrestFilterBuilder } from '@supabase/postgrest-js';
2
2
  import { RowRegion } from './loading-utils.ts';
3
- import { ColumnSort } from '../types.ts';
4
- export type FetchMode = "scroll" | "paged";
3
+ import { FetchData, FetchDataFilter, TableDataProvider } from '../provider';
4
+ import { FetchDataOptions, FetchMode } from '../types.ts';
5
5
  export interface PostgrestOrder<T> {
6
6
  key: string;
7
7
  ascending?: boolean;
8
8
  nullsFirst?: boolean;
9
9
  }
10
- /** Operators available for server-side column filtering via PostgREST. */
11
- export type PostgrestFilterOperator = "eq" | "neq" | "like" | "ilike" | "gt" | "lt" | "gte" | "lte" | "is";
10
+ /** Operators available for server-side column filtering via PostgREST.
11
+ * `cs`/`ov` target array columns (contains / overlaps). */
12
+ export type PostgrestFilterOperator = "eq" | "neq" | "like" | "ilike" | "gt" | "lt" | "gte" | "lte" | "is" | "cs" | "ov";
12
13
  /** A single column sort entry. */
13
14
  export interface ColumnSortEntry {
14
15
  key: string;
@@ -21,6 +22,7 @@ export interface PostgrestColumnFilter {
21
22
  value: string;
22
23
  }
23
24
  export interface PostgrestFilter {
25
+ id?: string;
24
26
  type: "filter";
25
27
  apply(req: PostgrestFilterBuilder<any, any, any, any>): PostgrestFilterBuilder<any, any, any, any>;
26
28
  }
@@ -30,11 +32,6 @@ export declare function applyColumnFilters(req: PostgrestFilterBuilder<any, any,
30
32
  export declare const chunkPageAtom: import('jotai').PrimitiveAtom<number> & {
31
33
  init: number;
32
34
  };
33
- /** Bump this to force the active chunk loader to reset and re-fetch from
34
- * scratch — e.g. after a mutation (save/delete) that invalidates loaded rows. */
35
- export declare const dataRefreshTokenAtom: import('jotai').PrimitiveAtom<number> & {
36
- init: number;
37
- };
38
35
  /** Footer state for the optional bottom-of-table indicator: rows loaded, the
39
36
  * source total when known, load status, and — in paged mode — the current
40
37
  * page and total pages. */
@@ -48,6 +45,44 @@ export interface TableFooterInfo {
48
45
  totalPages: number | null;
49
46
  }
50
47
  export declare const tableFooterAtom: import('jotai').Atom<TableFooterInfo>;
48
+ /** Auto-load this many pages per burst, then pause (null ⇒ unbounded). Set by
49
+ * a consumer (e.g. `DataPanel`'s `autoLoadPages` prop). */
50
+ export declare const autoLoadPagesAtom: import('jotai').PrimitiveAtom<number | null> & {
51
+ init: number | null;
52
+ };
53
+ /** Row count at the last manual "load more" — the point auto-load resumes
54
+ * counting a fresh burst from. */
55
+ export declare const resumeBaselineAtom: import('jotai').PrimitiveAtom<number> & {
56
+ init: number;
57
+ };
58
+ /** Live loading controls, read from the store rather than passed down a
59
+ * boundary contract. Any component inside the provider can call
60
+ * `useLoadControls()` — a footer, a toolbar button, a status line — without the
61
+ * renderer wiring a specific prop shape to it. */
62
+ export interface LoadControls {
63
+ /** Load the next page and resume auto-loading (clears a paused state). */
64
+ loadMore: () => void;
65
+ /** A fetch is in flight. */
66
+ loading: boolean;
67
+ /** More rows remain to load. */
68
+ hasMore: boolean;
69
+ /** Rows loaded so far. */
70
+ loaded: number;
71
+ /** Source total when known, else `null`. */
72
+ total: number | null;
73
+ /** Auto-load is paused at the `autoLoadPages` checkpoint. */
74
+ paused: boolean;
75
+ /** Auto-load is currently permitted (`hasMore && !loading && !paused`) —
76
+ * used to gate an infinite-scroll sentinel. */
77
+ canLoadMore: boolean;
78
+ /** Advance one page *without* resuming a paused auto-load (the sentinel
79
+ * uses this; `loadMore` is the manual, un-pausing variant). */
80
+ advance: () => void;
81
+ }
82
+ /** Store-managed load controls (see `LoadControls`). Reads the loader's footer
83
+ * state, the loaded rows, and the pause atoms; `loadMore`/`advance` set the
84
+ * visible region so the loader fetches the next chunk. */
85
+ export declare function useLoadControls(): LoadControls;
51
86
  export interface ViewInfo {
52
87
  visibleRegion: RowRegion;
53
88
  totalCount: number | null;
@@ -56,79 +91,6 @@ export interface ViewInfo {
56
91
  }
57
92
  export declare const viewInfoAtom: import('jotai').Atom<ViewInfo>;
58
93
  export declare function useScrollHandler(): ((visibleCells: RowRegion) => void) & import('underscore').Cancelable;
59
- /** The active view state (a filter's id / column / config), passed to a
60
- * `fetchChunk`. A server provider translates `columnKey` + `state` into a
61
- * query; a local (in-memory) provider applies `predicate` directly. Both come
62
- * from the same `TableFilter`, so one filter definition serves either target. */
63
- export interface FetchDataFilter {
64
- id: string;
65
- columnKey?: string;
66
- state: any;
67
- /** Client-side row predicate (from the `TableFilter`). Server providers
68
- * ignore it and translate `columnKey` + `state` instead. */
69
- predicate?: (row: any, state: any) => boolean;
70
- }
71
- /** Parameters passed to a `fetchChunk` implementation for one window. */
72
- export interface FetchDataParams {
73
- /** Row offset of the requested chunk (chunk-aligned). */
74
- offset: number;
75
- /** Maximum rows to return. */
76
- limit: number;
77
- /** Aborts when the request is superseded (view change / unmount). */
78
- signal: AbortSignal;
79
- /** Active sorts, in priority order. */
80
- sorts: ColumnSort[];
81
- /** Active filters (id + column + config). */
82
- filters: FetchDataFilter[];
83
- /** In scroll mode, the already-loaded row immediately before this chunk
84
- * (and its data-array index), or `null` at the start / in paged mode. Keyset
85
- * sources can page from this cursor (e.g. `WHERE key > cursor`) instead of a
86
- * slow `OFFSET`; offset-based sources can ignore it. */
87
- cursor?: {
88
- row: any;
89
- index: number;
90
- } | null;
91
- }
92
- /** Result of a `fetchChunk` call. `totalCount` reports the source length when
93
- * known (drives sparse-array pre-sizing and a proportional scrollbar); omit it
94
- * for unknown-length sources (the array grows as chunks arrive). */
95
- export interface FetchDataResult<T = any> {
96
- rows: T[];
97
- totalCount?: number | null;
98
- }
99
- export type FetchData<T = any> = (params: FetchDataParams) => Promise<FetchDataResult<T>>;
100
- /**
101
- * A table's data source, addressed uniformly whether it's an in-memory array or
102
- * a remote backend. `fetchChunk` returns a window with the active sorts/filters
103
- * already applied (in memory by the local provider, in SQL by a server one);
104
- * `identity` addresses a row for edits/mutations — stable across re-sorts,
105
- * unlike an array index. The mutation ops are present only for editable /
106
- * persisting sources. The in-memory case (`createLocalProvider`) is just the
107
- * degenerate implementation, so local and server tables share one path.
108
- */
109
- export interface TableDataProvider<T = any> {
110
- fetchData(params: FetchDataParams): Promise<FetchDataResult<T>>;
111
- identity(row: T): string | number;
112
- saveRows?(rows: T[]): Promise<void>;
113
- deleteRows?(ids: Array<string | number>): Promise<void>;
114
- insertRow?(row: Partial<T>): Promise<void>;
115
- }
116
- /**
117
- * The degenerate provider: an in-memory array. `fetchChunk` applies the active
118
- * filter predicates and sorts over the array and returns the requested slice
119
- * plus the (fully-known) total — the same view engine used for client-side
120
- * tables, expressed as a provider.
121
- */
122
- export declare function createLocalProvider<T = any>(data: T[], options?: {
123
- identity?: (row: T) => string | number;
124
- }): TableDataProvider<T>;
125
- /** Multi-key row comparator (priority order; nulls first when ascending),
126
- * shared by the local provider and any other in-memory sort. */
127
- export declare function compareRowsBySorts(sorts: ColumnSort[]): (a: any, b: any) => number;
128
- export interface FetchDataOptions {
129
- pageSize?: number;
130
- fetchMode?: FetchMode;
131
- }
132
94
  /**
133
95
  * A generic, backend-agnostic windowed data source. Give it a `fetchChunk`
134
96
  * function and it drives the sheet's lazy loading: it loads the chunk covering
@@ -157,6 +119,11 @@ export declare function createPostgRESTFetchChunk<T = any>(config: {
157
119
  endpoint: string;
158
120
  table: string;
159
121
  identityKey: string;
122
+ /** Default ordering direction of the identity key (applied when no active
123
+ * sort targets it). `false` ⇒ the table defaults to identity-descending
124
+ * (e.g. newest `source_id` first) without a redundant `baseOrder` entry that
125
+ * would otherwise collide with the identity tiebreaker. Defaults to `true`. */
126
+ identityAscending?: boolean;
160
127
  columns?: string | string[];
161
128
  /** Order applied before the active column sorts (identity key appended last). */
162
129
  baseOrder?: PostgrestOrder<any>[];
@@ -176,6 +143,9 @@ export declare function createPostgRESTProvider<T = any>(config: {
176
143
  endpoint: string;
177
144
  table: string;
178
145
  identityKey: string;
146
+ /** Default ordering direction of the identity key (see
147
+ * `createPostgRESTFetchChunk`). `false` ⇒ identity-descending by default. */
148
+ identityAscending?: boolean;
179
149
  columns?: string | string[];
180
150
  baseOrder?: PostgrestOrder<any>[];
181
151
  baseFilter?: (q: PostgrestFilterBuilder<any, any, any, any>) => PostgrestFilterBuilder<any, any, any, any>;
@@ -4,8 +4,9 @@ import { useRef, useMemo, useEffect, useCallback } from "react";
4
4
  import update from "immutability-helper";
5
5
  import { PostgrestClient } from "@supabase/postgrest-js";
6
6
  import { adjustArraySize } from "./loading-utils.js";
7
- import { tableDataAtom, ctx, useSelector } from "../provider.js";
8
7
  import { atom } from "jotai";
8
+ import { tableDataAtom, ctx, dataProviderAtom, useSelector } from "../provider/core.js";
9
+ import { dataRefreshTokenAtom } from "../provider/table-data.js";
9
10
  function standardizeFilter(columnFilter) {
10
11
  return {
11
12
  type: "filter",
@@ -17,11 +18,22 @@ function standardizeFilter(columnFilter) {
17
18
  function applyColumnFilters(req, filters) {
18
19
  for (const cf of filters) {
19
20
  if (cf.value === "" || cf.value == null) continue;
21
+ if (cf.operator === "cs") {
22
+ req = req.contains(cf.key, splitFilterList(cf.value));
23
+ continue;
24
+ }
25
+ if (cf.operator === "ov") {
26
+ req = req.overlaps(cf.key, splitFilterList(cf.value));
27
+ continue;
28
+ }
20
29
  const val = cf.operator === "like" || cf.operator === "ilike" ? `*${cf.value}*` : cf.value;
21
30
  req = req.filter(cf.key, cf.operator, val);
22
31
  }
23
32
  return req;
24
33
  }
34
+ function splitFilterList(value) {
35
+ return String(value).split(",").map((s) => s.trim()).filter((s) => s !== "");
36
+ }
25
37
  function lazyLoadingReducer(state, action) {
26
38
  switch (action.type) {
27
39
  case "start-loading":
@@ -78,6 +90,31 @@ function lazyLoadingReducer(state, action) {
78
90
  return state;
79
91
  }
80
92
  }
93
+ function formatKeysetValue(v) {
94
+ const s = String(v);
95
+ if (s === "" || /[,.:()"\\ ]/.test(s)) {
96
+ return `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
97
+ }
98
+ return s;
99
+ }
100
+ function keysetEq(key, v) {
101
+ return v == null ? `${key}.is.null` : `${key}.eq.${formatKeysetValue(v)}`;
102
+ }
103
+ function buildKeysetPredicate(clauses, lastRow) {
104
+ const terms = [];
105
+ for (let i = 0; i < clauses.length; i++) {
106
+ const v = lastRow[clauses[i].key];
107
+ if (v == null) continue;
108
+ const conds = [];
109
+ for (let j = 0; j < i; j++) {
110
+ conds.push(keysetEq(clauses[j].key, lastRow[clauses[j].key]));
111
+ }
112
+ const op = clauses[i].ascending ?? true ? "gt" : "lt";
113
+ conds.push(`${clauses[i].key}.${op}.${formatKeysetValue(v)}`);
114
+ terms.push(conds.length === 1 ? conds[0] : `and(${conds.join(",")})`);
115
+ }
116
+ return terms.length > 0 ? terms.join(",") : null;
117
+ }
81
118
  function buildQuery(client, config) {
82
119
  const { columns = "*", count, lastLoadedRowIndex } = config;
83
120
  const opts = { count };
@@ -94,18 +131,17 @@ function buildQuery(client, config) {
94
131
  }
95
132
  const orderClauses = buildPostgrestOrderClauses(
96
133
  config.order ?? [],
97
- config.identityKey
134
+ config.identityOrder ?? config.identityKey
98
135
  );
99
136
  let hasOrdering = false;
100
137
  for (const clause of orderClauses) {
101
138
  query = query.order(clause.key, clause);
102
- if (config.lastLoadedRow != null) {
103
- const op = clause.ascending ?? true ? "gt" : "lt";
104
- const value = config.lastLoadedRow[clause.key];
105
- query = query[op](clause.key, value);
106
- }
107
139
  hasOrdering = true;
108
140
  }
141
+ if (config.lastLoadedRow != null && hasOrdering) {
142
+ const pred = buildKeysetPredicate(orderClauses, config.lastLoadedRow);
143
+ if (pred != null) query = query.or(pred);
144
+ }
109
145
  let offset = null;
110
146
  if (!hasOrdering && lastLoadedRowIndex > 0) {
111
147
  offset = lastLoadedRowIndex + 1;
@@ -118,7 +154,6 @@ function buildQuery(client, config) {
118
154
  query = query.limit(config.limit);
119
155
  }
120
156
  }
121
- console.log("query", query.url.search);
122
157
  return query;
123
158
  }
124
159
  const defaultVisibleRegion = {
@@ -135,7 +170,6 @@ const lazyLoaderCoreStateAtom = atom({
135
170
  pageSize: 100
136
171
  });
137
172
  const chunkPageAtom = atom(0);
138
- const dataRefreshTokenAtom = atom(0);
139
173
  const tableFooterAtom = atom((get) => {
140
174
  const core = get(lazyLoaderCoreStateAtom);
141
175
  const data = get(tableDataAtom) ?? [];
@@ -157,6 +191,44 @@ const tableFooterAtom = atom((get) => {
157
191
  totalPages
158
192
  };
159
193
  });
194
+ const autoLoadPagesAtom = atom(null);
195
+ const resumeBaselineAtom = atom(0);
196
+ function useLoadControls() {
197
+ const footer = ctx.useValue(tableFooterAtom);
198
+ const data = ctx.useValue(tableDataAtom) ?? [];
199
+ const { isLocalProvider } = ctx.useValue(dataProviderAtom);
200
+ const resumeBaseline = ctx.useValue(resumeBaselineAtom);
201
+ const autoLoadPages = ctx.useValue(autoLoadPagesAtom);
202
+ const setResumeBaseline = ctx.useSet(resumeBaselineAtom);
203
+ const setVisibleRegion = ctx.useSet(visibleRegionAtom);
204
+ let loadedCount = 0;
205
+ for (const row of data) if (row != null) loadedCount++;
206
+ const pageSize = footer.pageSize || 100;
207
+ const dataLength = data.length;
208
+ const hasMore = !isLocalProvider && loadedCount < dataLength;
209
+ const paused = autoLoadPages != null && loadedCount - resumeBaseline >= autoLoadPages * pageSize;
210
+ const canLoadMore = hasMore && !footer.loading && !paused;
211
+ const advance = useCallback(() => {
212
+ setVisibleRegion({
213
+ rowIndexStart: 0,
214
+ rowIndexEnd: Math.min(loadedCount + pageSize, dataLength)
215
+ });
216
+ }, [setVisibleRegion, loadedCount, pageSize, dataLength]);
217
+ const loadMore = useCallback(() => {
218
+ setResumeBaseline(loadedCount);
219
+ advance();
220
+ }, [setResumeBaseline, loadedCount, advance]);
221
+ return {
222
+ loadMore,
223
+ loading: footer.loading,
224
+ hasMore,
225
+ loaded: footer.loaded,
226
+ total: footer.total,
227
+ paused,
228
+ canLoadMore,
229
+ advance
230
+ };
231
+ }
160
232
  const viewInfoAtom = atom((get) => {
161
233
  const state = get(lazyLoaderStateAtom);
162
234
  return {
@@ -204,22 +276,27 @@ function useLazyLoaderReducer() {
204
276
  function buildPostgrestOrderClauses(sorts, identityOrder) {
205
277
  const identitySort = typeof identityOrder == "string" ? { key: identityOrder, ascending: true } : identityOrder;
206
278
  const identityKey = identitySort.key;
207
- const clauses = sorts.map((sort) => {
208
- return {
279
+ const seen = /* @__PURE__ */ new Set();
280
+ const clauses = [];
281
+ for (const sort of sorts) {
282
+ if (seen.has(sort.key)) continue;
283
+ seen.add(sort.key);
284
+ clauses.push({
209
285
  key: sort.key,
210
286
  ascending: sort.ascending,
211
287
  nullsFirst: "nullsFirst" in sort ? sort.nullsFirst : false
212
- };
213
- });
214
- const hasIdentityClause = clauses.some((d) => d.key === identityKey);
215
- if (hasIdentityClause) {
216
- clauses.sort((a, b) => {
217
- if (a.key === identityKey) return 1;
218
- if (b.key === identityKey) return -1;
219
- return 0;
220
288
  });
289
+ }
290
+ if (seen.has(identityKey)) {
291
+ const idx = clauses.findIndex((c) => c.key === identityKey);
292
+ const [idClause] = clauses.splice(idx, 1);
293
+ clauses.push(idClause);
221
294
  } else {
222
- clauses.push(identitySort);
295
+ clauses.push({
296
+ key: identitySort.key,
297
+ ascending: identitySort.ascending ?? true,
298
+ nullsFirst: identitySort.nullsFirst ?? false
299
+ });
223
300
  }
224
301
  return clauses;
225
302
  }
@@ -237,59 +314,10 @@ function useScrollHandler() {
237
314
  [setVisibleRegion]
238
315
  );
239
316
  }
240
- function createLocalProvider(data, options = {}) {
241
- const identity = options.identity ?? defaultLocalIdentity;
242
- return {
243
- identity,
244
- async fetchData({ offset, limit, sorts, filters }) {
245
- let rows = data;
246
- if (filters != null && filters.length > 0) {
247
- rows = rows.filter(
248
- (row) => filters.every(
249
- (f) => f.predicate != null ? f.predicate(row, f.state) : true
250
- )
251
- );
252
- }
253
- if (sorts != null && sorts.length > 0) {
254
- rows = [...rows].sort(compareRowsBySorts(sorts));
255
- }
256
- return {
257
- rows: rows.slice(offset, offset + limit),
258
- totalCount: rows.length
259
- };
260
- }
261
- };
262
- }
263
- const _syntheticRowIds = /* @__PURE__ */ new WeakMap();
264
- let _syntheticRowCounter = 0;
265
- function defaultLocalIdentity(row) {
266
- if (row == null) return void 0;
267
- if (row.id != null) return row.id;
268
- if (typeof row !== "object") return row;
269
- let id = _syntheticRowIds.get(row);
270
- if (id == null) {
271
- id = `__row_${_syntheticRowCounter++}`;
272
- _syntheticRowIds.set(row, id);
273
- }
274
- return id;
275
- }
276
- function compareRowsBySorts(sorts) {
277
- return (a, b) => {
278
- for (const sort of sorts) {
279
- const av = a?.[sort.key];
280
- const bv = b?.[sort.key];
281
- if (av == null && bv == null) continue;
282
- if (av == null) return sort.ascending ? -1 : 1;
283
- if (bv == null) return sort.ascending ? 1 : -1;
284
- const cmp = av < bv ? -1 : av > bv ? 1 : 0;
285
- if (cmp !== 0) return sort.ascending ? cmp : -cmp;
286
- }
287
- return 0;
288
- };
289
- }
290
317
  function useDataLoader(fetchChunk, options = {}) {
291
318
  const { pageSize = 100, fetchMode = "scroll" } = options;
292
319
  const [state, dispatch] = useLazyLoaderReducer();
320
+ const { isLocalProvider, provider } = ctx.useValue(dataProviderAtom);
293
321
  const visibleRegion = ctx.useValue(visibleRegionAtom);
294
322
  const page = ctx.useValue(chunkPageAtom);
295
323
  const setPage = ctx.useSet(chunkPageAtom);
@@ -396,8 +424,8 @@ function createPostgRESTFetchChunk(config) {
396
424
  return async ({ limit, signal, sorts, filters, cursor }) => {
397
425
  const client = new PostgrestClient(config.endpoint).from(config.table);
398
426
  const order = [
399
- ...config.baseOrder ?? [],
400
- ...sorts.map((s) => ({ key: s.key, ascending: s.ascending }))
427
+ ...sorts.map((s) => ({ key: s.key, ascending: s.ascending })),
428
+ ...config.baseOrder ?? []
401
429
  ];
402
430
  const pgFilters = [];
403
431
  if (config.baseFilter != null) {
@@ -414,6 +442,10 @@ function createPostgRESTFetchChunk(config) {
414
442
  count: cursor == null ? "exact" : void 0,
415
443
  limit,
416
444
  identityKey: config.identityKey,
445
+ identityOrder: {
446
+ key: config.identityKey,
447
+ ascending: config.identityAscending ?? true
448
+ },
417
449
  order,
418
450
  filters: pgFilters,
419
451
  lastLoadedRow: cursor?.row ?? null,
@@ -453,7 +485,8 @@ function standardColumnFilter(f) {
453
485
  return null;
454
486
  }
455
487
  function indexOfFirstNullInRegion(data, region) {
456
- for (let i = region.rowIndexStart; i < region.rowIndexEnd; i++) {
488
+ const end = Math.min(region.rowIndexEnd, data.length);
489
+ for (let i = region.rowIndexStart; i < end; i++) {
457
490
  if (data[i] == null) {
458
491
  return i;
459
492
  }
@@ -462,15 +495,15 @@ function indexOfFirstNullInRegion(data, region) {
462
495
  }
463
496
  export {
464
497
  applyColumnFilters,
498
+ autoLoadPagesAtom,
465
499
  chunkPageAtom,
466
- compareRowsBySorts,
467
- createLocalProvider,
468
500
  createPostgRESTFetchChunk,
469
501
  createPostgRESTProvider,
470
- dataRefreshTokenAtom,
502
+ resumeBaselineAtom,
471
503
  standardizeFilter,
472
504
  tableFooterAtom,
473
505
  useDataLoader,
506
+ useLoadControls,
474
507
  useScrollHandler,
475
508
  viewInfoAtom
476
509
  };