@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
@@ -0,0 +1,92 @@
1
+ import { TableElementStatus } from "./types.js";
2
+ import { atom } from "jotai";
3
+ function createLocalProvider(data, options = {}) {
4
+ const identity = options.identity ?? defaultLocalIdentity;
5
+ return {
6
+ identity,
7
+ async fetchData({ offset, limit, sorts, filters }) {
8
+ let rows = data;
9
+ if (filters != null && filters.length > 0) {
10
+ rows = rows.filter(
11
+ (row) => filters.every(
12
+ (f) => f.predicate != null ? f.predicate(row, f.state) : true
13
+ )
14
+ );
15
+ }
16
+ if (sorts != null && sorts.length > 0) {
17
+ rows = [...rows].sort(compareRowsBySorts(sorts));
18
+ }
19
+ return {
20
+ rows: rows.slice(offset, offset + limit),
21
+ totalCount: rows.length
22
+ };
23
+ }
24
+ };
25
+ }
26
+ const _syntheticRowIds = /* @__PURE__ */ new WeakMap();
27
+ let _syntheticRowCounter = 0;
28
+ function defaultLocalIdentity(row) {
29
+ if (row == null) return void 0;
30
+ if (row.id != null) return row.id;
31
+ if (typeof row !== "object") return row;
32
+ let id = _syntheticRowIds.get(row);
33
+ if (id == null) {
34
+ id = `__row_${_syntheticRowCounter++}`;
35
+ _syntheticRowIds.set(row, id);
36
+ }
37
+ return id;
38
+ }
39
+ function compareRowsBySorts(sorts) {
40
+ return (a, b) => {
41
+ for (const sort of sorts) {
42
+ const av = a?.[sort.key];
43
+ const bv = b?.[sort.key];
44
+ if (av == null && bv == null) continue;
45
+ if (av == null) return sort.ascending ? -1 : 1;
46
+ if (bv == null) return sort.ascending ? 1 : -1;
47
+ const cmp = av < bv ? -1 : av > bv ? 1 : 0;
48
+ if (cmp !== 0) return sort.ascending ? cmp : -cmp;
49
+ }
50
+ return 0;
51
+ };
52
+ }
53
+ const dataRefreshTokenAtom = atom(0);
54
+ async function persistViaProvider(provider, ctx) {
55
+ const base = ctx.data ?? [];
56
+ const updates = ctx.updatedData ?? [];
57
+ const status = ctx.rowStatus ?? [];
58
+ const n = Math.max(base.length, updates.length, status.length);
59
+ const toSave = [];
60
+ const toInsert = [];
61
+ const toDelete = [];
62
+ for (let i = 0; i < n; i++) {
63
+ if (status[i] === TableElementStatus.DELETED) {
64
+ const id = provider.identity(base[i]);
65
+ if (id != null) toDelete.push(id);
66
+ continue;
67
+ }
68
+ const upd = updates[i];
69
+ const hasEdit = upd != null && typeof upd === "object" && Object.keys(upd).length > 0;
70
+ if (status[i] === TableElementStatus.ADDED) {
71
+ toInsert.push({ ...base[i], ...upd });
72
+ } else if (hasEdit) {
73
+ toSave.push({ ...base[i], ...upd });
74
+ }
75
+ }
76
+ if (toDelete.length > 0 && provider.deleteRows != null) {
77
+ await provider.deleteRows(toDelete);
78
+ }
79
+ for (const row of toInsert) {
80
+ if (provider.insertRow != null) await provider.insertRow(row);
81
+ }
82
+ if (toSave.length > 0 && provider.saveRows != null) {
83
+ await provider.saveRows(toSave);
84
+ }
85
+ }
86
+ export {
87
+ compareRowsBySorts,
88
+ createLocalProvider,
89
+ dataRefreshTokenAtom,
90
+ persistViaProvider
91
+ };
92
+ //# sourceMappingURL=table-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-data.js","sources":["../../src/provider/table-data.ts"],"sourcesContent":["import { ColumnSort, TableElementStatus } from \"./types.ts\";\nimport { atom } from \"jotai\";\nimport { TableActionContext } from \"../actions\";\n\n/** The active view state (a filter's id / column / config), passed to a\n * `fetchChunk`. A server provider translates `columnKey` + `state` into a\n * query; a local (in-memory) provider applies `predicate` directly. Both come\n * from the same `TableFilter`, so one filter definition serves either target. */\nexport interface FetchDataFilter {\n id: string;\n columnKey?: string;\n state: any;\n /** Client-side row predicate (from the `TableFilter`). Server providers\n * ignore it and translate `columnKey` + `state` instead. */\n predicate?: (row: any, state: any) => boolean;\n}\n\n/** Parameters passed to a `fetchChunk` implementation for one window. */\nexport interface FetchDataParams {\n /** Row offset of the requested chunk (chunk-aligned). */\n offset: number;\n /** Maximum rows to return. */\n limit: number;\n /** Aborts when the request is superseded (view change / unmount). */\n signal: AbortSignal;\n /** Active sorts, in priority order. */\n sorts: ColumnSort[];\n /** Active filters (id + column + config). */\n filters: FetchDataFilter[];\n /** In scroll mode, the already-loaded row immediately before this chunk\n * (and its data-array index), or `null` at the start / in paged mode. Keyset\n * sources can page from this cursor (e.g. `WHERE key > cursor`) instead of a\n * slow `OFFSET`; offset-based sources can ignore it. */\n cursor?: { row: any; index: number } | null;\n}\n\n/** Result of a `fetchChunk` call. `totalCount` reports the source length when\n * known (drives sparse-array pre-sizing and a proportional scrollbar); omit it\n * for unknown-length sources (the array grows as chunks arrive). */\nexport interface FetchDataResult<T = any> {\n rows: T[];\n totalCount?: number | null;\n}\n\nexport type FetchData<T = any> = (\n params: FetchDataParams,\n) => Promise<FetchDataResult<T>>;\n\n/**\n * A table's data source, addressed uniformly whether it's an in-memory array or\n * a remote backend. `fetchChunk` returns a window with the active sorts/filters\n * already applied (in memory by the local provider, in SQL by a server one);\n * `identity` addresses a row for edits/mutations — stable across re-sorts,\n * unlike an array index. The mutation ops are present only for editable /\n * persisting sources. The in-memory case (`createLocalProvider`) is just the\n * degenerate implementation, so local and server tables share one path.\n */\nexport interface TableDataProvider<T = any> {\n fetchData(params: FetchDataParams): Promise<FetchDataResult<T>>;\n identity(row: T): string | number;\n saveRows?(rows: T[]): Promise<void>;\n deleteRows?(ids: Array<string | number>): Promise<void>;\n insertRow?(row: Partial<T>): Promise<void>;\n}\n\n/**\n * The degenerate provider: an in-memory array. `fetchChunk` applies the active\n * filter predicates and sorts over the array and returns the requested slice\n * plus the (fully-known) total — the same view engine used for client-side\n * tables, expressed as a provider.\n */\nexport function createLocalProvider<T = any>(\n data: T[],\n options: { identity?: (row: T) => string | number } = {},\n): TableDataProvider<T> {\n const identity: any = options.identity ?? defaultLocalIdentity;\n\n return {\n identity,\n async fetchData({ offset, limit, sorts, filters }) {\n let rows = data;\n if (filters != null && filters.length > 0) {\n rows = rows.filter((row) =>\n filters.every((f) =>\n f.predicate != null ? f.predicate(row, f.state) : true,\n ),\n );\n }\n if (sorts != null && sorts.length > 0) {\n rows = [...rows].sort(compareRowsBySorts(sorts));\n }\n return {\n rows: rows.slice(offset, offset + limit),\n totalCount: rows.length,\n };\n },\n };\n}\n\n// Stable synthetic identity for in-memory rows lacking a natural `id`. Keyed by\n// object reference (a local data array keeps the same row objects across\n// re-sorts), so edits survive re-ordering even without an id field.\nconst _syntheticRowIds = new WeakMap<object, string>();\nlet _syntheticRowCounter = 0;\n\nfunction defaultLocalIdentity(row: any): string | number | undefined {\n if (row == null) return undefined;\n if (row.id != null) return row.id;\n if (typeof row !== \"object\") return row;\n let id = _syntheticRowIds.get(row);\n if (id == null) {\n id = `__row_${_syntheticRowCounter++}`;\n _syntheticRowIds.set(row, id);\n }\n return id;\n}\n\n/** Multi-key row comparator (priority order; nulls first when ascending),\n * shared by the local provider and any other in-memory sort. */\nexport function compareRowsBySorts(sorts: ColumnSort[]) {\n return (a: any, b: any): number => {\n for (const sort of sorts) {\n const av = a?.[sort.key];\n const bv = b?.[sort.key];\n if (av == null && bv == null) continue;\n if (av == null) return sort.ascending ? -1 : 1;\n if (bv == null) return sort.ascending ? 1 : -1;\n const cmp = av < bv ? -1 : av > bv ? 1 : 0;\n if (cmp !== 0) return sort.ascending ? cmp : -cmp;\n }\n return 0;\n };\n}\n\n/** Bump this to force the active chunk loader to reset and re-fetch from\n * scratch — e.g. after a mutation (save/delete) that invalidates loaded rows. */\nexport const dataRefreshTokenAtom = atom(0);\n\n/** Persist all pending changes through a data provider: added rows via\n * `insertRow`, edited rows via `saveRows`, deleted rows via `deleteRows`\n * (addressed by `provider.identity`). Used by the built-in Save action when an\n * explicit provider owns persistence. */\nexport async function persistViaProvider<T>(\n provider: TableDataProvider<T>,\n ctx: TableActionContext<T>,\n): Promise<void> {\n const base = (ctx.data ?? []) as any[];\n const updates = (ctx.updatedData ?? []) as any[];\n const status = (ctx.rowStatus ?? []) as any[];\n const n = Math.max(base.length, updates.length, status.length);\n const toSave: T[] = [];\n const toInsert: T[] = [];\n const toDelete: Array<string | number> = [];\n for (let i = 0; i < n; i++) {\n if (status[i] === TableElementStatus.DELETED) {\n const id = provider.identity(base[i]);\n if (id != null) toDelete.push(id);\n continue;\n }\n const upd = updates[i];\n const hasEdit =\n upd != null && typeof upd === \"object\" && Object.keys(upd).length > 0;\n if (status[i] === TableElementStatus.ADDED) {\n toInsert.push({ ...base[i], ...upd } as T);\n } else if (hasEdit) {\n toSave.push({ ...base[i], ...upd } as T);\n }\n }\n if (toDelete.length > 0 && provider.deleteRows != null) {\n await provider.deleteRows(toDelete);\n }\n for (const row of toInsert) {\n if (provider.insertRow != null) await provider.insertRow(row);\n }\n if (toSave.length > 0 && provider.saveRows != null) {\n await provider.saveRows(toSave);\n }\n}\n"],"names":[],"mappings":";;AAuEO,SAAS,oBACd,MACA,UAAsD,IAChC;AACtB,QAAM,WAAgB,QAAQ,YAAY;AAE1C,SAAO;AAAA,IACL;AAAA,IACA,MAAM,UAAU,EAAE,QAAQ,OAAO,OAAO,WAAW;AACjD,UAAI,OAAO;AACX,UAAI,WAAW,QAAQ,QAAQ,SAAS,GAAG;AACzC,eAAO,KAAK;AAAA,UAAO,CAAC,QAClB,QAAQ;AAAA,YAAM,CAAC,MACb,EAAE,aAAa,OAAO,EAAE,UAAU,KAAK,EAAE,KAAK,IAAI;AAAA,UAAA;AAAA,QACpD;AAAA,MAEJ;AACA,UAAI,SAAS,QAAQ,MAAM,SAAS,GAAG;AACrC,eAAO,CAAC,GAAG,IAAI,EAAE,KAAK,mBAAmB,KAAK,CAAC;AAAA,MACjD;AACA,aAAO;AAAA,QACL,MAAM,KAAK,MAAM,QAAQ,SAAS,KAAK;AAAA,QACvC,YAAY,KAAK;AAAA,MAAA;AAAA,IAErB;AAAA,EAAA;AAEJ;AAKA,MAAM,uCAAuB,QAAA;AAC7B,IAAI,uBAAuB;AAE3B,SAAS,qBAAqB,KAAuC;AACnE,MAAI,OAAO,KAAM,QAAO;AACxB,MAAI,IAAI,MAAM,KAAM,QAAO,IAAI;AAC/B,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,MAAI,KAAK,iBAAiB,IAAI,GAAG;AACjC,MAAI,MAAM,MAAM;AACd,SAAK,SAAS,sBAAsB;AACpC,qBAAiB,IAAI,KAAK,EAAE;AAAA,EAC9B;AACA,SAAO;AACT;AAIO,SAAS,mBAAmB,OAAqB;AACtD,SAAO,CAAC,GAAQ,MAAmB;AACjC,eAAW,QAAQ,OAAO;AACxB,YAAM,KAAK,IAAI,KAAK,GAAG;AACvB,YAAM,KAAK,IAAI,KAAK,GAAG;AACvB,UAAI,MAAM,QAAQ,MAAM,KAAM;AAC9B,UAAI,MAAM,KAAM,QAAO,KAAK,YAAY,KAAK;AAC7C,UAAI,MAAM,KAAM,QAAO,KAAK,YAAY,IAAI;AAC5C,YAAM,MAAM,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI;AACzC,UAAI,QAAQ,EAAG,QAAO,KAAK,YAAY,MAAM,CAAC;AAAA,IAChD;AACA,WAAO;AAAA,EACT;AACF;AAIO,MAAM,uBAAuB,KAAK,CAAC;AAM1C,eAAsB,mBACpB,UACA,KACe;AACf,QAAM,OAAQ,IAAI,QAAQ,CAAA;AAC1B,QAAM,UAAW,IAAI,eAAe,CAAA;AACpC,QAAM,SAAU,IAAI,aAAa,CAAA;AACjC,QAAM,IAAI,KAAK,IAAI,KAAK,QAAQ,QAAQ,QAAQ,OAAO,MAAM;AAC7D,QAAM,SAAc,CAAA;AACpB,QAAM,WAAgB,CAAA;AACtB,QAAM,WAAmC,CAAA;AACzC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,QAAI,OAAO,CAAC,MAAM,mBAAmB,SAAS;AAC5C,YAAM,KAAK,SAAS,SAAS,KAAK,CAAC,CAAC;AACpC,UAAI,MAAM,KAAM,UAAS,KAAK,EAAE;AAChC;AAAA,IACF;AACA,UAAM,MAAM,QAAQ,CAAC;AACrB,UAAM,UACJ,OAAO,QAAQ,OAAO,QAAQ,YAAY,OAAO,KAAK,GAAG,EAAE,SAAS;AACtE,QAAI,OAAO,CAAC,MAAM,mBAAmB,OAAO;AAC1C,eAAS,KAAK,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,KAAU;AAAA,IAC3C,WAAW,SAAS;AAClB,aAAO,KAAK,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,KAAU;AAAA,IACzC;AAAA,EACF;AACA,MAAI,SAAS,SAAS,KAAK,SAAS,cAAc,MAAM;AACtD,UAAM,SAAS,WAAW,QAAQ;AAAA,EACpC;AACA,aAAW,OAAO,UAAU;AAC1B,QAAI,SAAS,aAAa,KAAM,OAAM,SAAS,UAAU,GAAG;AAAA,EAC9D;AACA,MAAI,OAAO,SAAS,KAAK,SAAS,YAAY,MAAM;AAClD,UAAM,SAAS,SAAS,MAAM;AAAA,EAChC;AACF;"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var TableElementStatus = /* @__PURE__ */ ((TableElementStatus2) => {
4
+ TableElementStatus2["DELETED"] = "deleted";
5
+ TableElementStatus2["ADDED"] = "added";
6
+ return TableElementStatus2;
7
+ })(TableElementStatus || {});
8
+ const DEFAULT_ROW_STATUS_STYLES = {
9
+ [
10
+ "deleted"
11
+ /* DELETED */
12
+ ]: {
13
+ cellStyle: { opacity: 0.5, textDecoration: "line-through" },
14
+ headerStyle: { opacity: 0.5, textDecoration: "line-through" },
15
+ intent: "danger"
16
+ }
17
+ };
18
+ const DS_ROW_ID = "__dsRowId";
19
+ exports.DEFAULT_ROW_STATUS_STYLES = DEFAULT_ROW_STATUS_STYLES;
20
+ exports.DS_ROW_ID = DS_ROW_ID;
21
+ exports.TableElementStatus = TableElementStatus;
22
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sources":["../../src/provider/types.ts"],"sourcesContent":["import type {\n FocusedCellCoordinates,\n Region,\n RegionCardinality,\n Table2,\n} from \"@blueprintjs/table\";\nimport type { ColumnSpec, ColumnSpecOptions } from \"./column-spec\";\nimport { OverlayToaster } from \"@blueprintjs/core\";\nimport { DataViewCoreProps } from \"../types\";\nimport { DataViewRendererType } from \"./interactions.ts\";\n\n/** A single column sort entry for client-side sorting.\n * Defined here (rather than in actions/types) to avoid circular imports. */\nexport interface ColumnSort {\n key: string;\n ascending: boolean;\n}\n\n/** Direction of keyboard navigation between cells. */\nexport type NavDirection = \"up\" | \"down\" | \"left\" | \"right\";\n\n/**\n * A structured, revertible description of a user edit. Emitted via the\n * `onEdit` hook so a consumer can capture edits as operations (and, with the\n * controlled-overlay API, own the edited state) instead of diffing\n * `updatedData`. This is the write half of the data-sheet's read/write\n * contract — the mirror of how data flows in.\n */\nexport type EditEvent<T = any> =\n | { type: \"setCells\"; cells: CellEdit[] }\n | { type: \"deleteRows\"; rowIndices: number[] }\n | { type: \"restoreRows\"; rowIndices: number[] }\n | { type: \"addRow\"; rowIndex: number; value: Partial<T> }\n | { type: \"resetChanges\" };\n\nexport enum TableElementStatus {\n DELETED = \"deleted\",\n ADDED = \"added\",\n}\n\n/** A row's status value. The built-in `TableElementStatus` members\n * (`\"deleted\"` / `\"added\"`) plus any consumer-defined status string (e.g.\n * `\"omitted\"`). The `(string & {})` keeps autocomplete for the enum members\n * while still accepting arbitrary strings. */\nexport type RowStatusValue = TableElementStatus | (string & {});\n\n/** Presentation for a row status: applied to the row's cells and its header\n * cell. Keyed by status value in `rowStatusStyles`. The library ships a\n * default for `\"deleted\"` (dimmed + struck through, danger intent); consumers\n * merge in styles for their own statuses (and may override the defaults). */\nexport interface RowStatusStyle {\n /** Style merged onto each cell in a row with this status. */\n cellStyle?: import(\"react\").CSSProperties;\n /** Style applied to the row's header cell. */\n headerStyle?: import(\"react\").CSSProperties;\n /** Blueprint intent applied to the row's cells (precedence: validation >\n * this > edited-green). */\n intent?: import(\"@blueprintjs/core\").Intent;\n}\n\nexport type RowStatusStyles = Record<string, RowStatusStyle>;\n\n/** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged\n * over this, so `\"deleted\"` keeps its look unless explicitly overridden. */\nexport const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles = {\n [TableElementStatus.DELETED]: {\n cellStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n headerStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n intent: \"danger\",\n },\n};\n\n/** Context passed to a custom `rowHeaderRenderer`, so it can label and style\n * the row header from the row's data and status (group-key labels, an\n * omit indicator, etc.). Return a node to use as the header's name, or a\n * nullish value to fall back to the default (1-based row number). */\nexport interface RowHeaderRenderContext<T = any> {\n /** Data-row index (stable under sort/filter). */\n rowIndex: number;\n /** Visible (display) row index. */\n visibleIndex: number;\n /** The row's data (base, overlaid with edits if present). */\n row: T | undefined;\n /** The row's status, if any. */\n status: RowStatusValue | undefined;\n /** Convenience: `status === TableElementStatus.DELETED`. */\n isDeleted: boolean;\n /** The default label (`\"${rowIndex + 1}\"`). */\n defaultLabel: string;\n}\n\n/** Property key holding a stable synthetic id on rows added in-table. Added\n * rows aren't in the data provider, so they need their own identity to survive\n * a provider re-fetch; it's carried on the row and preserved through edits. */\nexport const DS_ROW_ID = \"__dsRowId\";\n\n/** Proxy stored during a copy operation, enabling backend-mediated paste\n * for lazy-loaded tables where not all data is available locally. */\nexport interface ClipboardProxy {\n cardinality: RegionCardinality;\n /** Source row indices (for row/cell copies) */\n rowIndices?: number[];\n /** Source column keys (for column/cell copies) */\n columnKeys?: string[];\n /** The plain text written to the clipboard, used to verify the proxy\n * is still valid on paste (i.e., clipboard hasn't been overwritten). */\n text: string;\n}\n\nexport interface DataSheetState<T> {\n selection: Region[];\n columnSpec: ColumnSpec[];\n columnSpecOptions?: ColumnSpecOptions<T>;\n /** When `true`, the loader's first-chunk auto-generation of `columnSpec` is\n * suppressed — a function `columnSpec` derives it from the loaded rows\n * instead (in `_DataSheet`). Set at init from the prop's shape. */\n deferColumnSpec: boolean;\n fillValueBaseCell: FocusedCellCoordinates | null;\n focusedCell: FocusedCellCoordinates | null;\n topLeftCell: FocusedCellCoordinates | null;\n /**\n * Set of row indices that have been added to the table,\n * but not yet committed to the underlying data array.\n *\n * This is used to track which rows should be reverted when\n * a \"reset\" action is performed.\n */\n rowStatus: (RowStatusValue | undefined)[];\n /** Presentation per row-status value (merged: defaults + the\n * `rowStatusStyles` prop). Read by the cell renderer and row-header renderer\n * to style rows by status. */\n rowStatusStyles: RowStatusStyles;\n // Sparse data structure for updated data\n updatedData: (T | null | undefined)[];\n data: T[];\n initialized: boolean;\n columnWidthsIndex: Map<string, number>;\n /** Active column/table filters. Keys are filter IDs, values carry the\n * filter definition and its current configuration state. */\n activeFilters: Map<string, { filter: any; state: any }>;\n /** Clipboard proxy from the last copy operation */\n clipboardProxy: ClipboardProxy | null;\n /** Visible row indices when filters are active. `null` means show all rows. */\n filteredRowIndices: number[] | null;\n /** Active column sort entries for client-side sorting. */\n columnSorts: ColumnSort[];\n /** Whether selecting a cell automatically activates its surface (opens an\n * editor/detail panel and, for editors, focuses it). `\"manual\"` opens only\n * on click. */\n cellInteraction: \"auto\" | \"manual\";\n /** Runtime override of `cellInteraction`: while `false`, auto-activation is\n * suppressed (set by pressing Escape, re-armed by clicking a cell) so the\n * keyboard prioritizes navigation. */\n autoActivateArmed: boolean;\n /** Direction of the last keyboard navigation, used to place an editor's\n * cursor on the side the user is travelling toward. `null` after a click. */\n lastNavDirection: NavDirection | null;\n /** The table's focusable holder element; editors return focus here when the\n * cursor leaves them so arrow-key navigation resumes. */\n tableElement: HTMLElement | null;\n /** Whether the focused cell's surface (editor or detail panel) is open.\n * Owned by the store — not per-popover — so navigation, clicks, and the\n * Escape handler all agree on it. */\n cellSurfaceOpen: boolean;\n /** Optional observer called for every user edit as a structured\n * `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a\n * consumer capture edits as revertible operations. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Row identity for the edit overlay — stable across a provider re-sort,\n * unlike an array index. Defaults to `(row) => row?.id`; a data provider\n * supplies its own (e.g. a PostgREST identity key). Used to re-attach edits\n * when the loader replaces `data` with a re-ordered window. */\n identity: (row: any) => string | number | null | undefined;\n /** Edits/statuses held by identity for rows not currently loaded (server\n * sources), re-attached when their row next arrives. */\n pendingOverlayById: Map<\n string | number,\n { edit?: any; status?: TableElementStatus }\n >;\n /** True when the consumer controls the `updatedData`/`rowStatus` overlay; the\n * loader-boundary identity remap is skipped (the consumer owns it). */\n controlledOverlay: boolean;\n /** Whether row deletion is available. Set from the data provider: an explicit\n * `provider` without `deleteRows` disables deletion entirely (the delete\n * affordance greys out and the delete key is a no-op). Defaults to `true`. */\n canDeleteRows: boolean;\n /** Provider-backed, auto-refreshing row mutations for immediate-edit consumers\n * (chiefly `DataPanel`). Each persists through the data provider and then\n * re-fetches. Wired by the consumer that owns the provider + loader; exposed\n * on the action context as `saveRows` / `deleteRows` / `insertRow` /\n * `refresh`, so a selection action can edit without hand-wiring persistence.\n * Absent when no persisting provider. */\n rowEditing?: {\n saveRows?: (rows: any[]) => Promise<void>;\n deleteRows?: (ids: Array<string | number>) => Promise<void>;\n insertRow?: (row: any) => Promise<void>;\n refresh?: () => void;\n };\n}\n\ntype DataSheetVals<T> = DataSheetState<T> & DataViewCoreProps<T>;\nexport type StateUpdater<T> = T[] | ((state: T[]) => T[]);\n\nexport interface DataSheetStoreMain<T> extends DataSheetVals<T> {\n setSelection(selection: Region[]): void;\n onDragValue(event: MouseEvent): void;\n setUpdatedData(data: StateUpdater<T>): void;\n onCellEdited(rowIndex: number, columnName: string, value: any): void;\n onSelectionEdited(value: any): void;\n onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;\n onColumnWidthChanged(columnIndex: number, newWidth: number): void;\n moveFocusedCell(direction: NavDirection): void;\n /** Suppress auto-activation until the next click (Escape enters nav mode). */\n suppressAutoActivate(): void;\n /** Re-arm auto-activation (a click re-enables auto-focus). */\n armAutoActivate(): void;\n /** Open the focused cell's surface (editor or detail panel). */\n openCellSurface(): void;\n /** Close the focused cell's surface. When `suppress` is true (the default,\n * as for Escape), auto mode also enters navigation mode (auto-activation is\n * suppressed until the next click). A click-dismiss passes `suppress: false`\n * so it just closes without changing the global mode. */\n closeCellSurface(opts?: { suppress?: boolean }): void;\n deleteSelectedRows(): void;\n clearSelection(): void;\n resetChanges(): void;\n addRow(): void;\n /** Activate or update a column/table filter.\n * Filter is any object satisfying `TableFilter` from the actions module. */\n setFilter(filterId: string, filter: any, filterState: any): void;\n /** Remove a filter by ID */\n removeFilter(filterId: string): void;\n /** Remove all active filters */\n clearFilters(): void;\n /** Set or clear a column sort. Pass `null` for ascending to clear. */\n setColumnSort(key: string, ascending: boolean | null): void;\n /** Remove all active column sorts */\n clearColumnSorts(): void;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n //initialize(props: Partial<DataSheetStoreMain<T>>): void;\n onSelection(selection: Region[]): void;\n // Internal method used for infinite scrolling\n scrollToRow(rowIndex: number): void;\n tableRef: React.MutableRefObject<Table2> | null;\n columnWidthsIndex: Map<string, number>;\n defaultColumnWidth: number;\n // Editable is not optional on store\n editable: boolean;\n}\n\nexport type DataSheetProviderProps<T> = DataViewCoreProps<T> & {\n toaster?: OverlayToaster;\n viewType?: DataViewRendererType;\n children?: React.ReactNode;\n};\n\nexport interface VisibleCells {\n rowIndexStart: number;\n rowIndexEnd: number;\n}\n\nexport type DataSheetStore<T> = DataSheetStoreMain<T>;\n\n/** A single cell edit, used with `editCells` for batch updates. */\nexport interface CellEdit {\n rowIndex: number;\n column: string;\n value: any;\n /** The underlying row (base data). Populated on emitted `onEdit` events so a\n * handler can address the row (identity) without reaching into the store. */\n row?: any;\n}\n"],"names":["TableElementStatus"],"mappings":";;AAmCO,IAAK,uCAAAA,wBAAL;AACLA,sBAAA,SAAA,IAAU;AACVA,sBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AA6BL,MAAM,4BAA6C;AAAA,EACxD;AAAA,IAAC;AAAA;AAAA,KAA6B;AAAA,IAC5B,WAAW,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC3C,aAAa,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC7C,QAAQ;AAAA,EAAA;AAEZ;AAwBO,MAAM,YAAY;;;;"}
@@ -0,0 +1,256 @@
1
+ import { FocusedCellCoordinates, Region, RegionCardinality, Table2 } from '@blueprintjs/table';
2
+ import { ColumnSpec, ColumnSpecOptions } from './column-spec';
3
+ import { OverlayToaster } from '@blueprintjs/core';
4
+ import { DataViewCoreProps } from '../types';
5
+ import { DataViewRendererType } from './interactions.ts';
6
+ /** A single column sort entry for client-side sorting.
7
+ * Defined here (rather than in actions/types) to avoid circular imports. */
8
+ export interface ColumnSort {
9
+ key: string;
10
+ ascending: boolean;
11
+ }
12
+ /** Direction of keyboard navigation between cells. */
13
+ export type NavDirection = "up" | "down" | "left" | "right";
14
+ /**
15
+ * A structured, revertible description of a user edit. Emitted via the
16
+ * `onEdit` hook so a consumer can capture edits as operations (and, with the
17
+ * controlled-overlay API, own the edited state) instead of diffing
18
+ * `updatedData`. This is the write half of the data-sheet's read/write
19
+ * contract — the mirror of how data flows in.
20
+ */
21
+ export type EditEvent<T = any> = {
22
+ type: "setCells";
23
+ cells: CellEdit[];
24
+ } | {
25
+ type: "deleteRows";
26
+ rowIndices: number[];
27
+ } | {
28
+ type: "restoreRows";
29
+ rowIndices: number[];
30
+ } | {
31
+ type: "addRow";
32
+ rowIndex: number;
33
+ value: Partial<T>;
34
+ } | {
35
+ type: "resetChanges";
36
+ };
37
+ export declare enum TableElementStatus {
38
+ DELETED = "deleted",
39
+ ADDED = "added"
40
+ }
41
+ /** A row's status value. The built-in `TableElementStatus` members
42
+ * (`"deleted"` / `"added"`) plus any consumer-defined status string (e.g.
43
+ * `"omitted"`). The `(string & {})` keeps autocomplete for the enum members
44
+ * while still accepting arbitrary strings. */
45
+ export type RowStatusValue = TableElementStatus | (string & {});
46
+ /** Presentation for a row status: applied to the row's cells and its header
47
+ * cell. Keyed by status value in `rowStatusStyles`. The library ships a
48
+ * default for `"deleted"` (dimmed + struck through, danger intent); consumers
49
+ * merge in styles for their own statuses (and may override the defaults). */
50
+ export interface RowStatusStyle {
51
+ /** Style merged onto each cell in a row with this status. */
52
+ cellStyle?: import('react').CSSProperties;
53
+ /** Style applied to the row's header cell. */
54
+ headerStyle?: import('react').CSSProperties;
55
+ /** Blueprint intent applied to the row's cells (precedence: validation >
56
+ * this > edited-green). */
57
+ intent?: import('@blueprintjs/core').Intent;
58
+ }
59
+ export type RowStatusStyles = Record<string, RowStatusStyle>;
60
+ /** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged
61
+ * over this, so `"deleted"` keeps its look unless explicitly overridden. */
62
+ export declare const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles;
63
+ /** Context passed to a custom `rowHeaderRenderer`, so it can label and style
64
+ * the row header from the row's data and status (group-key labels, an
65
+ * omit indicator, etc.). Return a node to use as the header's name, or a
66
+ * nullish value to fall back to the default (1-based row number). */
67
+ export interface RowHeaderRenderContext<T = any> {
68
+ /** Data-row index (stable under sort/filter). */
69
+ rowIndex: number;
70
+ /** Visible (display) row index. */
71
+ visibleIndex: number;
72
+ /** The row's data (base, overlaid with edits if present). */
73
+ row: T | undefined;
74
+ /** The row's status, if any. */
75
+ status: RowStatusValue | undefined;
76
+ /** Convenience: `status === TableElementStatus.DELETED`. */
77
+ isDeleted: boolean;
78
+ /** The default label (`"${rowIndex + 1}"`). */
79
+ defaultLabel: string;
80
+ }
81
+ /** Property key holding a stable synthetic id on rows added in-table. Added
82
+ * rows aren't in the data provider, so they need their own identity to survive
83
+ * a provider re-fetch; it's carried on the row and preserved through edits. */
84
+ export declare const DS_ROW_ID = "__dsRowId";
85
+ /** Proxy stored during a copy operation, enabling backend-mediated paste
86
+ * for lazy-loaded tables where not all data is available locally. */
87
+ export interface ClipboardProxy {
88
+ cardinality: RegionCardinality;
89
+ /** Source row indices (for row/cell copies) */
90
+ rowIndices?: number[];
91
+ /** Source column keys (for column/cell copies) */
92
+ columnKeys?: string[];
93
+ /** The plain text written to the clipboard, used to verify the proxy
94
+ * is still valid on paste (i.e., clipboard hasn't been overwritten). */
95
+ text: string;
96
+ }
97
+ export interface DataSheetState<T> {
98
+ selection: Region[];
99
+ columnSpec: ColumnSpec[];
100
+ columnSpecOptions?: ColumnSpecOptions<T>;
101
+ /** When `true`, the loader's first-chunk auto-generation of `columnSpec` is
102
+ * suppressed — a function `columnSpec` derives it from the loaded rows
103
+ * instead (in `_DataSheet`). Set at init from the prop's shape. */
104
+ deferColumnSpec: boolean;
105
+ fillValueBaseCell: FocusedCellCoordinates | null;
106
+ focusedCell: FocusedCellCoordinates | null;
107
+ topLeftCell: FocusedCellCoordinates | null;
108
+ /**
109
+ * Set of row indices that have been added to the table,
110
+ * but not yet committed to the underlying data array.
111
+ *
112
+ * This is used to track which rows should be reverted when
113
+ * a "reset" action is performed.
114
+ */
115
+ rowStatus: (RowStatusValue | undefined)[];
116
+ /** Presentation per row-status value (merged: defaults + the
117
+ * `rowStatusStyles` prop). Read by the cell renderer and row-header renderer
118
+ * to style rows by status. */
119
+ rowStatusStyles: RowStatusStyles;
120
+ updatedData: (T | null | undefined)[];
121
+ data: T[];
122
+ initialized: boolean;
123
+ columnWidthsIndex: Map<string, number>;
124
+ /** Active column/table filters. Keys are filter IDs, values carry the
125
+ * filter definition and its current configuration state. */
126
+ activeFilters: Map<string, {
127
+ filter: any;
128
+ state: any;
129
+ }>;
130
+ /** Clipboard proxy from the last copy operation */
131
+ clipboardProxy: ClipboardProxy | null;
132
+ /** Visible row indices when filters are active. `null` means show all rows. */
133
+ filteredRowIndices: number[] | null;
134
+ /** Active column sort entries for client-side sorting. */
135
+ columnSorts: ColumnSort[];
136
+ /** Whether selecting a cell automatically activates its surface (opens an
137
+ * editor/detail panel and, for editors, focuses it). `"manual"` opens only
138
+ * on click. */
139
+ cellInteraction: "auto" | "manual";
140
+ /** Runtime override of `cellInteraction`: while `false`, auto-activation is
141
+ * suppressed (set by pressing Escape, re-armed by clicking a cell) so the
142
+ * keyboard prioritizes navigation. */
143
+ autoActivateArmed: boolean;
144
+ /** Direction of the last keyboard navigation, used to place an editor's
145
+ * cursor on the side the user is travelling toward. `null` after a click. */
146
+ lastNavDirection: NavDirection | null;
147
+ /** The table's focusable holder element; editors return focus here when the
148
+ * cursor leaves them so arrow-key navigation resumes. */
149
+ tableElement: HTMLElement | null;
150
+ /** Whether the focused cell's surface (editor or detail panel) is open.
151
+ * Owned by the store — not per-popover — so navigation, clicks, and the
152
+ * Escape handler all agree on it. */
153
+ cellSurfaceOpen: boolean;
154
+ /** Optional observer called for every user edit as a structured
155
+ * `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a
156
+ * consumer capture edits as revertible operations. */
157
+ onEdit?: (event: EditEvent<T>) => void;
158
+ /** Row identity for the edit overlay — stable across a provider re-sort,
159
+ * unlike an array index. Defaults to `(row) => row?.id`; a data provider
160
+ * supplies its own (e.g. a PostgREST identity key). Used to re-attach edits
161
+ * when the loader replaces `data` with a re-ordered window. */
162
+ identity: (row: any) => string | number | null | undefined;
163
+ /** Edits/statuses held by identity for rows not currently loaded (server
164
+ * sources), re-attached when their row next arrives. */
165
+ pendingOverlayById: Map<string | number, {
166
+ edit?: any;
167
+ status?: TableElementStatus;
168
+ }>;
169
+ /** True when the consumer controls the `updatedData`/`rowStatus` overlay; the
170
+ * loader-boundary identity remap is skipped (the consumer owns it). */
171
+ controlledOverlay: boolean;
172
+ /** Whether row deletion is available. Set from the data provider: an explicit
173
+ * `provider` without `deleteRows` disables deletion entirely (the delete
174
+ * affordance greys out and the delete key is a no-op). Defaults to `true`. */
175
+ canDeleteRows: boolean;
176
+ /** Provider-backed, auto-refreshing row mutations for immediate-edit consumers
177
+ * (chiefly `DataPanel`). Each persists through the data provider and then
178
+ * re-fetches. Wired by the consumer that owns the provider + loader; exposed
179
+ * on the action context as `saveRows` / `deleteRows` / `insertRow` /
180
+ * `refresh`, so a selection action can edit without hand-wiring persistence.
181
+ * Absent when no persisting provider. */
182
+ rowEditing?: {
183
+ saveRows?: (rows: any[]) => Promise<void>;
184
+ deleteRows?: (ids: Array<string | number>) => Promise<void>;
185
+ insertRow?: (row: any) => Promise<void>;
186
+ refresh?: () => void;
187
+ };
188
+ }
189
+ type DataSheetVals<T> = DataSheetState<T> & DataViewCoreProps<T>;
190
+ export type StateUpdater<T> = T[] | ((state: T[]) => T[]);
191
+ export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
192
+ setSelection(selection: Region[]): void;
193
+ onDragValue(event: MouseEvent): void;
194
+ setUpdatedData(data: StateUpdater<T>): void;
195
+ onCellEdited(rowIndex: number, columnName: string, value: any): void;
196
+ onSelectionEdited(value: any): void;
197
+ onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;
198
+ onColumnWidthChanged(columnIndex: number, newWidth: number): void;
199
+ moveFocusedCell(direction: NavDirection): void;
200
+ /** Suppress auto-activation until the next click (Escape enters nav mode). */
201
+ suppressAutoActivate(): void;
202
+ /** Re-arm auto-activation (a click re-enables auto-focus). */
203
+ armAutoActivate(): void;
204
+ /** Open the focused cell's surface (editor or detail panel). */
205
+ openCellSurface(): void;
206
+ /** Close the focused cell's surface. When `suppress` is true (the default,
207
+ * as for Escape), auto mode also enters navigation mode (auto-activation is
208
+ * suppressed until the next click). A click-dismiss passes `suppress: false`
209
+ * so it just closes without changing the global mode. */
210
+ closeCellSurface(opts?: {
211
+ suppress?: boolean;
212
+ }): void;
213
+ deleteSelectedRows(): void;
214
+ clearSelection(): void;
215
+ resetChanges(): void;
216
+ addRow(): void;
217
+ /** Activate or update a column/table filter.
218
+ * Filter is any object satisfying `TableFilter` from the actions module. */
219
+ setFilter(filterId: string, filter: any, filterState: any): void;
220
+ /** Remove a filter by ID */
221
+ removeFilter(filterId: string): void;
222
+ /** Remove all active filters */
223
+ clearFilters(): void;
224
+ /** Set or clear a column sort. Pass `null` for ascending to clear. */
225
+ setColumnSort(key: string, ascending: boolean | null): void;
226
+ /** Remove all active column sorts */
227
+ clearColumnSorts(): void;
228
+ /** Store a clipboard proxy for potential backend-mediated paste */
229
+ setClipboardProxy(proxy: ClipboardProxy | null): void;
230
+ onSelection(selection: Region[]): void;
231
+ scrollToRow(rowIndex: number): void;
232
+ tableRef: React.MutableRefObject<Table2> | null;
233
+ columnWidthsIndex: Map<string, number>;
234
+ defaultColumnWidth: number;
235
+ editable: boolean;
236
+ }
237
+ export type DataSheetProviderProps<T> = DataViewCoreProps<T> & {
238
+ toaster?: OverlayToaster;
239
+ viewType?: DataViewRendererType;
240
+ children?: React.ReactNode;
241
+ };
242
+ export interface VisibleCells {
243
+ rowIndexStart: number;
244
+ rowIndexEnd: number;
245
+ }
246
+ export type DataSheetStore<T> = DataSheetStoreMain<T>;
247
+ /** A single cell edit, used with `editCells` for batch updates. */
248
+ export interface CellEdit {
249
+ rowIndex: number;
250
+ column: string;
251
+ value: any;
252
+ /** The underlying row (base data). Populated on emitted `onEdit` events so a
253
+ * handler can address the row (identity) without reaching into the store. */
254
+ row?: any;
255
+ }
256
+ export {};
@@ -0,0 +1,22 @@
1
+ var TableElementStatus = /* @__PURE__ */ ((TableElementStatus2) => {
2
+ TableElementStatus2["DELETED"] = "deleted";
3
+ TableElementStatus2["ADDED"] = "added";
4
+ return TableElementStatus2;
5
+ })(TableElementStatus || {});
6
+ const DEFAULT_ROW_STATUS_STYLES = {
7
+ [
8
+ "deleted"
9
+ /* DELETED */
10
+ ]: {
11
+ cellStyle: { opacity: 0.5, textDecoration: "line-through" },
12
+ headerStyle: { opacity: 0.5, textDecoration: "line-through" },
13
+ intent: "danger"
14
+ }
15
+ };
16
+ const DS_ROW_ID = "__dsRowId";
17
+ export {
18
+ DEFAULT_ROW_STATUS_STYLES,
19
+ DS_ROW_ID,
20
+ TableElementStatus
21
+ };
22
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../../src/provider/types.ts"],"sourcesContent":["import type {\n FocusedCellCoordinates,\n Region,\n RegionCardinality,\n Table2,\n} from \"@blueprintjs/table\";\nimport type { ColumnSpec, ColumnSpecOptions } from \"./column-spec\";\nimport { OverlayToaster } from \"@blueprintjs/core\";\nimport { DataViewCoreProps } from \"../types\";\nimport { DataViewRendererType } from \"./interactions.ts\";\n\n/** A single column sort entry for client-side sorting.\n * Defined here (rather than in actions/types) to avoid circular imports. */\nexport interface ColumnSort {\n key: string;\n ascending: boolean;\n}\n\n/** Direction of keyboard navigation between cells. */\nexport type NavDirection = \"up\" | \"down\" | \"left\" | \"right\";\n\n/**\n * A structured, revertible description of a user edit. Emitted via the\n * `onEdit` hook so a consumer can capture edits as operations (and, with the\n * controlled-overlay API, own the edited state) instead of diffing\n * `updatedData`. This is the write half of the data-sheet's read/write\n * contract — the mirror of how data flows in.\n */\nexport type EditEvent<T = any> =\n | { type: \"setCells\"; cells: CellEdit[] }\n | { type: \"deleteRows\"; rowIndices: number[] }\n | { type: \"restoreRows\"; rowIndices: number[] }\n | { type: \"addRow\"; rowIndex: number; value: Partial<T> }\n | { type: \"resetChanges\" };\n\nexport enum TableElementStatus {\n DELETED = \"deleted\",\n ADDED = \"added\",\n}\n\n/** A row's status value. The built-in `TableElementStatus` members\n * (`\"deleted\"` / `\"added\"`) plus any consumer-defined status string (e.g.\n * `\"omitted\"`). The `(string & {})` keeps autocomplete for the enum members\n * while still accepting arbitrary strings. */\nexport type RowStatusValue = TableElementStatus | (string & {});\n\n/** Presentation for a row status: applied to the row's cells and its header\n * cell. Keyed by status value in `rowStatusStyles`. The library ships a\n * default for `\"deleted\"` (dimmed + struck through, danger intent); consumers\n * merge in styles for their own statuses (and may override the defaults). */\nexport interface RowStatusStyle {\n /** Style merged onto each cell in a row with this status. */\n cellStyle?: import(\"react\").CSSProperties;\n /** Style applied to the row's header cell. */\n headerStyle?: import(\"react\").CSSProperties;\n /** Blueprint intent applied to the row's cells (precedence: validation >\n * this > edited-green). */\n intent?: import(\"@blueprintjs/core\").Intent;\n}\n\nexport type RowStatusStyles = Record<string, RowStatusStyle>;\n\n/** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged\n * over this, so `\"deleted\"` keeps its look unless explicitly overridden. */\nexport const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles = {\n [TableElementStatus.DELETED]: {\n cellStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n headerStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n intent: \"danger\",\n },\n};\n\n/** Context passed to a custom `rowHeaderRenderer`, so it can label and style\n * the row header from the row's data and status (group-key labels, an\n * omit indicator, etc.). Return a node to use as the header's name, or a\n * nullish value to fall back to the default (1-based row number). */\nexport interface RowHeaderRenderContext<T = any> {\n /** Data-row index (stable under sort/filter). */\n rowIndex: number;\n /** Visible (display) row index. */\n visibleIndex: number;\n /** The row's data (base, overlaid with edits if present). */\n row: T | undefined;\n /** The row's status, if any. */\n status: RowStatusValue | undefined;\n /** Convenience: `status === TableElementStatus.DELETED`. */\n isDeleted: boolean;\n /** The default label (`\"${rowIndex + 1}\"`). */\n defaultLabel: string;\n}\n\n/** Property key holding a stable synthetic id on rows added in-table. Added\n * rows aren't in the data provider, so they need their own identity to survive\n * a provider re-fetch; it's carried on the row and preserved through edits. */\nexport const DS_ROW_ID = \"__dsRowId\";\n\n/** Proxy stored during a copy operation, enabling backend-mediated paste\n * for lazy-loaded tables where not all data is available locally. */\nexport interface ClipboardProxy {\n cardinality: RegionCardinality;\n /** Source row indices (for row/cell copies) */\n rowIndices?: number[];\n /** Source column keys (for column/cell copies) */\n columnKeys?: string[];\n /** The plain text written to the clipboard, used to verify the proxy\n * is still valid on paste (i.e., clipboard hasn't been overwritten). */\n text: string;\n}\n\nexport interface DataSheetState<T> {\n selection: Region[];\n columnSpec: ColumnSpec[];\n columnSpecOptions?: ColumnSpecOptions<T>;\n /** When `true`, the loader's first-chunk auto-generation of `columnSpec` is\n * suppressed — a function `columnSpec` derives it from the loaded rows\n * instead (in `_DataSheet`). Set at init from the prop's shape. */\n deferColumnSpec: boolean;\n fillValueBaseCell: FocusedCellCoordinates | null;\n focusedCell: FocusedCellCoordinates | null;\n topLeftCell: FocusedCellCoordinates | null;\n /**\n * Set of row indices that have been added to the table,\n * but not yet committed to the underlying data array.\n *\n * This is used to track which rows should be reverted when\n * a \"reset\" action is performed.\n */\n rowStatus: (RowStatusValue | undefined)[];\n /** Presentation per row-status value (merged: defaults + the\n * `rowStatusStyles` prop). Read by the cell renderer and row-header renderer\n * to style rows by status. */\n rowStatusStyles: RowStatusStyles;\n // Sparse data structure for updated data\n updatedData: (T | null | undefined)[];\n data: T[];\n initialized: boolean;\n columnWidthsIndex: Map<string, number>;\n /** Active column/table filters. Keys are filter IDs, values carry the\n * filter definition and its current configuration state. */\n activeFilters: Map<string, { filter: any; state: any }>;\n /** Clipboard proxy from the last copy operation */\n clipboardProxy: ClipboardProxy | null;\n /** Visible row indices when filters are active. `null` means show all rows. */\n filteredRowIndices: number[] | null;\n /** Active column sort entries for client-side sorting. */\n columnSorts: ColumnSort[];\n /** Whether selecting a cell automatically activates its surface (opens an\n * editor/detail panel and, for editors, focuses it). `\"manual\"` opens only\n * on click. */\n cellInteraction: \"auto\" | \"manual\";\n /** Runtime override of `cellInteraction`: while `false`, auto-activation is\n * suppressed (set by pressing Escape, re-armed by clicking a cell) so the\n * keyboard prioritizes navigation. */\n autoActivateArmed: boolean;\n /** Direction of the last keyboard navigation, used to place an editor's\n * cursor on the side the user is travelling toward. `null` after a click. */\n lastNavDirection: NavDirection | null;\n /** The table's focusable holder element; editors return focus here when the\n * cursor leaves them so arrow-key navigation resumes. */\n tableElement: HTMLElement | null;\n /** Whether the focused cell's surface (editor or detail panel) is open.\n * Owned by the store — not per-popover — so navigation, clicks, and the\n * Escape handler all agree on it. */\n cellSurfaceOpen: boolean;\n /** Optional observer called for every user edit as a structured\n * `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a\n * consumer capture edits as revertible operations. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Row identity for the edit overlay — stable across a provider re-sort,\n * unlike an array index. Defaults to `(row) => row?.id`; a data provider\n * supplies its own (e.g. a PostgREST identity key). Used to re-attach edits\n * when the loader replaces `data` with a re-ordered window. */\n identity: (row: any) => string | number | null | undefined;\n /** Edits/statuses held by identity for rows not currently loaded (server\n * sources), re-attached when their row next arrives. */\n pendingOverlayById: Map<\n string | number,\n { edit?: any; status?: TableElementStatus }\n >;\n /** True when the consumer controls the `updatedData`/`rowStatus` overlay; the\n * loader-boundary identity remap is skipped (the consumer owns it). */\n controlledOverlay: boolean;\n /** Whether row deletion is available. Set from the data provider: an explicit\n * `provider` without `deleteRows` disables deletion entirely (the delete\n * affordance greys out and the delete key is a no-op). Defaults to `true`. */\n canDeleteRows: boolean;\n /** Provider-backed, auto-refreshing row mutations for immediate-edit consumers\n * (chiefly `DataPanel`). Each persists through the data provider and then\n * re-fetches. Wired by the consumer that owns the provider + loader; exposed\n * on the action context as `saveRows` / `deleteRows` / `insertRow` /\n * `refresh`, so a selection action can edit without hand-wiring persistence.\n * Absent when no persisting provider. */\n rowEditing?: {\n saveRows?: (rows: any[]) => Promise<void>;\n deleteRows?: (ids: Array<string | number>) => Promise<void>;\n insertRow?: (row: any) => Promise<void>;\n refresh?: () => void;\n };\n}\n\ntype DataSheetVals<T> = DataSheetState<T> & DataViewCoreProps<T>;\nexport type StateUpdater<T> = T[] | ((state: T[]) => T[]);\n\nexport interface DataSheetStoreMain<T> extends DataSheetVals<T> {\n setSelection(selection: Region[]): void;\n onDragValue(event: MouseEvent): void;\n setUpdatedData(data: StateUpdater<T>): void;\n onCellEdited(rowIndex: number, columnName: string, value: any): void;\n onSelectionEdited(value: any): void;\n onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;\n onColumnWidthChanged(columnIndex: number, newWidth: number): void;\n moveFocusedCell(direction: NavDirection): void;\n /** Suppress auto-activation until the next click (Escape enters nav mode). */\n suppressAutoActivate(): void;\n /** Re-arm auto-activation (a click re-enables auto-focus). */\n armAutoActivate(): void;\n /** Open the focused cell's surface (editor or detail panel). */\n openCellSurface(): void;\n /** Close the focused cell's surface. When `suppress` is true (the default,\n * as for Escape), auto mode also enters navigation mode (auto-activation is\n * suppressed until the next click). A click-dismiss passes `suppress: false`\n * so it just closes without changing the global mode. */\n closeCellSurface(opts?: { suppress?: boolean }): void;\n deleteSelectedRows(): void;\n clearSelection(): void;\n resetChanges(): void;\n addRow(): void;\n /** Activate or update a column/table filter.\n * Filter is any object satisfying `TableFilter` from the actions module. */\n setFilter(filterId: string, filter: any, filterState: any): void;\n /** Remove a filter by ID */\n removeFilter(filterId: string): void;\n /** Remove all active filters */\n clearFilters(): void;\n /** Set or clear a column sort. Pass `null` for ascending to clear. */\n setColumnSort(key: string, ascending: boolean | null): void;\n /** Remove all active column sorts */\n clearColumnSorts(): void;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n //initialize(props: Partial<DataSheetStoreMain<T>>): void;\n onSelection(selection: Region[]): void;\n // Internal method used for infinite scrolling\n scrollToRow(rowIndex: number): void;\n tableRef: React.MutableRefObject<Table2> | null;\n columnWidthsIndex: Map<string, number>;\n defaultColumnWidth: number;\n // Editable is not optional on store\n editable: boolean;\n}\n\nexport type DataSheetProviderProps<T> = DataViewCoreProps<T> & {\n toaster?: OverlayToaster;\n viewType?: DataViewRendererType;\n children?: React.ReactNode;\n};\n\nexport interface VisibleCells {\n rowIndexStart: number;\n rowIndexEnd: number;\n}\n\nexport type DataSheetStore<T> = DataSheetStoreMain<T>;\n\n/** A single cell edit, used with `editCells` for batch updates. */\nexport interface CellEdit {\n rowIndex: number;\n column: string;\n value: any;\n /** The underlying row (base data). Populated on emitted `onEdit` events so a\n * handler can address the row (identity) without reaching into the store. */\n row?: any;\n}\n"],"names":["TableElementStatus"],"mappings":"AAmCO,IAAK,uCAAAA,wBAAL;AACLA,sBAAA,SAAA,IAAU;AACVA,sBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AA6BL,MAAM,4BAA6C;AAAA,EACxD;AAAA,IAAC;AAAA;AAAA,KAA6B;AAAA,IAC5B,WAAW,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC3C,aAAa,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC7C,QAAQ;AAAA,EAAA;AAEZ;AAwBO,MAAM,YAAY;"}
@@ -2,9 +2,8 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const types = require("./types.cjs");
4
4
  const table = require("@blueprintjs/table");
5
- const index = require("./utils/index.cjs");
6
5
  const update = require("immutability-helper");
7
- const selection = require("./actions/selection.cjs");
6
+ const selection = require("../actions/selection.cjs");
8
7
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
9
8
  const update__default = /* @__PURE__ */ _interopDefault(update);
10
9
  let _addedRowCounter = 0;
@@ -171,7 +170,7 @@ function createZustandStore(set, get) {
171
170
  }
172
171
  },
173
172
  resetChanges(regions) {
174
- set((state) => resetChangesForSelection(state, regions));
173
+ set((state) => resetChangesForSelection(state, regions ?? []));
175
174
  get().onEdit?.({ type: "resetChanges" });
176
175
  },
177
176
  onColumnWidthChanged(columnIx, newWidth) {
@@ -218,13 +217,13 @@ function createZustandStore(set, get) {
218
217
  clearSelection() {
219
218
  const edits = [];
220
219
  set((state) => {
221
- const { selection: selection2, updatedData, columnSpec, data } = state;
220
+ const { selection: selection$1, updatedData, columnSpec, data } = state;
222
221
  const numVisible = visibleRowCount(state);
223
222
  let spec = {};
224
- for (const region of selection2) {
223
+ for (const region of selection$1) {
225
224
  const { cols, rows } = region;
226
- const rowRange = index.range(rows ?? [0, numVisible - 1]);
227
- const colRange = index.range(cols ?? [0, columnSpec.length - 1]);
225
+ const rowRange = selection.range(rows ?? [0, numVisible - 1]);
226
+ const colRange = selection.range(cols ?? [0, columnSpec.length - 1]);
228
227
  for (const visibleRow of rowRange) {
229
228
  const row = toDataRowIndex(state, visibleRow);
230
229
  const rowIsDeleted = state.rowStatus[row] === types.TableElementStatus.DELETED;
@@ -235,7 +234,12 @@ function createZustandStore(set, get) {
235
234
  const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
236
235
  if (currentValue != null && currentValue !== "") {
237
236
  vals[key] = "";
238
- edits.push({ rowIndex: row, column: key, value: "", row: data[row] });
237
+ edits.push({
238
+ rowIndex: row,
239
+ column: key,
240
+ value: "",
241
+ row: data[row]
242
+ });
239
243
  }
240
244
  }
241
245
  let op = updatedData[row] == null ? "$set" : "$merge";
@@ -252,7 +256,11 @@ function createZustandStore(set, get) {
252
256
  },
253
257
  onSelection(selection2) {
254
258
  set((state) => {
255
- if (selectionEquals(selection2, state.selection) && singleFocusedCell(selection2) == null) {
259
+ const isSameAsPrevSelection = selectionEquals(
260
+ selection2,
261
+ state.selection
262
+ );
263
+ if (isSameAsPrevSelection && singleFocusedCell(selection2) == null) {
256
264
  return {
257
265
  selection: [],
258
266
  focusedCell: null,
@@ -276,21 +284,26 @@ function createZustandStore(set, get) {
276
284
  onSelectionEdited(value) {
277
285
  const edits = [];
278
286
  set((state) => {
279
- const { selection: selection2, updatedData, columnSpec, editable } = state;
287
+ const { selection: selection$1, updatedData, columnSpec, editable } = state;
280
288
  if (!editable) return {};
281
289
  const numVisible = visibleRowCount(state);
282
290
  let spec = {};
283
- for (const region of selection2) {
291
+ for (const region of selection$1) {
284
292
  const { cols, rows } = region;
285
- const rowRange = index.range(rows ?? [0, numVisible - 1]);
286
- const colRange = index.range(cols ?? [0, columnSpec.length - 1]);
293
+ const rowRange = selection.range(rows ?? [0, numVisible - 1]);
294
+ const colRange = selection.range(cols ?? [0, columnSpec.length - 1]);
287
295
  for (const visibleRow of rowRange) {
288
296
  const row = toDataRowIndex(state, visibleRow);
289
297
  let vals = {};
290
298
  for (const col of colRange) {
291
299
  const key = columnSpec[col].key;
292
300
  vals[key] = value;
293
- edits.push({ rowIndex: row, column: key, value, row: state.data[row] });
301
+ edits.push({
302
+ rowIndex: row,
303
+ column: key,
304
+ value,
305
+ row: state.data[row]
306
+ });
294
307
  }
295
308
  let op = updatedData[row] == null ? "$set" : "$merge";
296
309
  spec[row] = { [op]: vals };
@@ -434,11 +447,11 @@ function singleFocusedCell(sel) {
434
447
  if (sel?.length !== 1) return null;
435
448
  return topLeftCell(sel, true);
436
449
  }
437
- function fillValues(state, selection2) {
450
+ function fillValues(state, selection$1) {
438
451
  const { updatedData, columnSpec, editable, fillValueBaseCell, data } = state;
439
- let regions = selection2.map((region) => {
452
+ let regions = selection$1.map((region) => {
440
453
  const { cols, rows } = region;
441
- const [col2] = cols;
454
+ const [col2] = cols ?? [];
442
455
  return { cols: [col2, col2], rows };
443
456
  });
444
457
  if (!editable || fillValueBaseCell == null) return updatedData;
@@ -449,7 +462,7 @@ function fillValues(state, selection2) {
449
462
  const spec = {};
450
463
  for (const region of regions) {
451
464
  const { rows } = region;
452
- for (const visibleRow of index.range(rows)) {
465
+ for (const visibleRow of selection.range(rows ?? [])) {
453
466
  const row = toDataRowIndex(state, visibleRow);
454
467
  let op = updatedData[row] == null ? "$set" : "$merge";
455
468
  spec[row] = { [op]: { [key]: value } };
@@ -531,14 +544,14 @@ function resetChangesForSelection(state, selection$1) {
531
544
  };
532
545
  }
533
546
  }
534
- function insertItemAtIndex(arr, index2, item) {
535
- if (arr.length < index2) {
547
+ function insertItemAtIndex(arr, index, item) {
548
+ if (arr.length < index) {
536
549
  const newArr = [...arr];
537
- newArr.length = index2;
538
- newArr[index2] = item;
550
+ newArr.length = index;
551
+ newArr[index] = item;
539
552
  return newArr;
540
553
  }
541
- return [...arr.slice(0, index2), item, ...arr.slice(index2)];
554
+ return [...arr.slice(0, index), item, ...arr.slice(index)];
542
555
  }
543
556
  exports.createZustandStore = createZustandStore;
544
557
  exports.singleFocusedCell = singleFocusedCell;