@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,161 @@
1
+ import { RegionCardinality } from "@blueprintjs/table";
2
+ import { atom } from "jotai";
3
+ import { storeAtom } from "./core.ts";
4
+
5
+ export enum DataViewRendererType {
6
+ CARDS = "cards",
7
+ TABLE = "table",
8
+ }
9
+
10
+ export interface InteractionOptionsResolved {
11
+ enableEditing: boolean;
12
+ enableSelection: boolean;
13
+ // We have a potentially modal selection
14
+ enableModalSelection: boolean;
15
+ /** Options for data interaction (editing and selection) */
16
+ enableMultipleSelection: boolean;
17
+ // Enable drag-to-select (data table only)
18
+ enableDragValue: boolean;
19
+ selectionModes: RegionCardinality[];
20
+ }
21
+
22
+ const defaultInteractionOptions: InteractionOptionsResolved = {
23
+ enableEditing: false,
24
+ enableSelection: false,
25
+ enableModalSelection: false,
26
+ enableMultipleSelection: false,
27
+ enableDragValue: false,
28
+ selectionModes: [],
29
+ };
30
+
31
+ /** Atom to store interaction options state */
32
+ export const interactionOptionsAtom = atom<InteractionOptionsResolved>(
33
+ defaultInteractionOptions,
34
+ );
35
+
36
+ export enum SelectionInteractionStyle {
37
+ ALWAYS = "always",
38
+ NEVER = "never",
39
+ MODAL = "modal",
40
+ }
41
+
42
+ export interface InteractionOptions {
43
+ /** Options for data interaction (editing and selection) */
44
+ /** @deprecated: Use enableEditing instead */
45
+ editable?: boolean;
46
+ enableEditing?: boolean;
47
+ enableSelection?: boolean | SelectionInteractionStyle;
48
+ enableMultipleSelection?: boolean;
49
+ // Enable drag-to-select (data table only)
50
+ enableDragValue?: boolean;
51
+ selectionModes?: RegionCardinality[];
52
+ interactionOptions?: InteractionOptionsResolved;
53
+ }
54
+
55
+ export const interactionOptionsKeys: Set<keyof InteractionOptions> = new Set([
56
+ "editable",
57
+ "enableEditing",
58
+ "enableSelection",
59
+ "enableMultipleSelection",
60
+ "enableDragValue",
61
+ "selectionModes",
62
+ "interactionOptions",
63
+ ]);
64
+
65
+ /** Resolve the granular interaction options for a particular editing domain */
66
+ export function resolveInteractionOptions(
67
+ opts: InteractionOptions,
68
+ renderer: DataViewRendererType,
69
+ ): InteractionOptionsResolved {
70
+ // If the user has provided interaction options, use them.
71
+ if (opts.interactionOptions) return opts.interactionOptions;
72
+
73
+ /** Resolve a unified set of interaction options for the table and cards */
74
+ let {
75
+ enableEditing,
76
+ selectionModes,
77
+ enableSelection: _enableSelection,
78
+ enableDragValue,
79
+ enableMultipleSelection,
80
+ } = opts;
81
+
82
+ if (renderer == DataViewRendererType.CARDS) {
83
+ _enableSelection ??= true;
84
+ }
85
+
86
+ let enableSelection: boolean;
87
+ let enableModalSelection = false;
88
+ if (typeof _enableSelection === "string") {
89
+ switch (_enableSelection) {
90
+ case SelectionInteractionStyle.ALWAYS:
91
+ enableSelection = true;
92
+ break;
93
+ case SelectionInteractionStyle.NEVER:
94
+ enableSelection = false;
95
+ break;
96
+ case SelectionInteractionStyle.MODAL:
97
+ enableSelection = false;
98
+ enableModalSelection = true;
99
+ break;
100
+ }
101
+ } else {
102
+ enableSelection ??= _enableSelection ?? true;
103
+ }
104
+
105
+ enableEditing ??= opts.editable ?? enableSelection ?? true;
106
+ enableMultipleSelection ??= true;
107
+ if (renderer == DataViewRendererType.TABLE) {
108
+ if (selectionModes != null) {
109
+ enableSelection = new Set(selectionModes).size > 0;
110
+ }
111
+ enableSelection ??= true;
112
+ if (enableSelection) {
113
+ selectionModes ??= [
114
+ RegionCardinality.FULL_TABLE,
115
+ RegionCardinality.CELLS,
116
+ RegionCardinality.FULL_ROWS,
117
+ RegionCardinality.FULL_COLUMNS,
118
+ ];
119
+ enableEditing ??= true;
120
+ enableDragValue ??= true;
121
+ } else {
122
+ selectionModes ??= [RegionCardinality.FULL_TABLE];
123
+ }
124
+ if (!selectionModes.includes(RegionCardinality.CELLS)) {
125
+ enableEditing = false;
126
+ }
127
+ enableDragValue ??= enableEditing;
128
+ } else if (renderer == DataViewRendererType.CARDS) {
129
+ if (enableSelection) {
130
+ // Only one selection mode possible
131
+ selectionModes = [
132
+ RegionCardinality.FULL_ROWS,
133
+ RegionCardinality.FULL_TABLE,
134
+ ];
135
+ enableEditing ??= true;
136
+ } else {
137
+ selectionModes = [RegionCardinality.FULL_TABLE];
138
+ }
139
+ enableDragValue = false;
140
+ }
141
+ if (!enableEditing) {
142
+ enableDragValue = false;
143
+ }
144
+
145
+ return {
146
+ enableEditing,
147
+ enableDragValue: enableDragValue ?? false,
148
+ enableMultipleSelection,
149
+ selectionModes: selectionModes as RegionCardinality[],
150
+ enableModalSelection,
151
+ enableSelection,
152
+ };
153
+ }
154
+
155
+ export const enableDragValueAtom = atom((get) => {
156
+ return get(interactionOptionsAtom).enableDragValue;
157
+ });
158
+ export const dragValueHandlerAtom = atom((get) => {
159
+ if (!get(enableDragValueAtom)) return undefined;
160
+ return get(storeAtom)?.onDragValue;
161
+ });
@@ -0,0 +1,31 @@
1
+ import { atom } from "jotai";
2
+ import { interactionOptionsAtom } from "./interactions.ts";
3
+ import { storeAtom } from "./core.ts";
4
+ import type { Region } from "@blueprintjs/table";
5
+
6
+ // The anchor for shift-range selection: the last row clicked without shift.
7
+ // Reset when the selection is cleared elsewhere (e.g. the toolbar's ✕).
8
+ export const anchorRefAtom = atom<{ current: number | null }>({
9
+ current: null,
10
+ });
11
+
12
+ export const selectionAtom = atom(
13
+ (get) => {
14
+ if (!get(interactionOptionsAtom).enableSelection) return [];
15
+ return get(storeAtom)?.selection ?? [];
16
+ },
17
+ (get, set, regions: Region[] = []) => {
18
+ /** Don't do anything if selection isn't enabled */
19
+ if (!get(interactionOptionsAtom).enableSelection) return;
20
+ /** Reset the selection anchor ref */
21
+ if (regions.length === 0) {
22
+ get(anchorRefAtom).current = null;
23
+ }
24
+ set(storeAtom, (s) => ({
25
+ ...s,
26
+ selection: regions,
27
+ focusedCell: null,
28
+ topLeftCell: null,
29
+ }));
30
+ },
31
+ );
@@ -0,0 +1,178 @@
1
+ import { ColumnSort, TableElementStatus } from "./types.ts";
2
+ import { atom } from "jotai";
3
+ import { TableActionContext } from "../actions";
4
+
5
+ /** The active view state (a filter's id / column / config), passed to a
6
+ * `fetchChunk`. A server provider translates `columnKey` + `state` into a
7
+ * query; a local (in-memory) provider applies `predicate` directly. Both come
8
+ * from the same `TableFilter`, so one filter definition serves either target. */
9
+ export interface FetchDataFilter {
10
+ id: string;
11
+ columnKey?: string;
12
+ state: any;
13
+ /** Client-side row predicate (from the `TableFilter`). Server providers
14
+ * ignore it and translate `columnKey` + `state` instead. */
15
+ predicate?: (row: any, state: any) => boolean;
16
+ }
17
+
18
+ /** Parameters passed to a `fetchChunk` implementation for one window. */
19
+ export interface FetchDataParams {
20
+ /** Row offset of the requested chunk (chunk-aligned). */
21
+ offset: number;
22
+ /** Maximum rows to return. */
23
+ limit: number;
24
+ /** Aborts when the request is superseded (view change / unmount). */
25
+ signal: AbortSignal;
26
+ /** Active sorts, in priority order. */
27
+ sorts: ColumnSort[];
28
+ /** Active filters (id + column + config). */
29
+ filters: FetchDataFilter[];
30
+ /** In scroll mode, the already-loaded row immediately before this chunk
31
+ * (and its data-array index), or `null` at the start / in paged mode. Keyset
32
+ * sources can page from this cursor (e.g. `WHERE key > cursor`) instead of a
33
+ * slow `OFFSET`; offset-based sources can ignore it. */
34
+ cursor?: { row: any; index: number } | null;
35
+ }
36
+
37
+ /** Result of a `fetchChunk` call. `totalCount` reports the source length when
38
+ * known (drives sparse-array pre-sizing and a proportional scrollbar); omit it
39
+ * for unknown-length sources (the array grows as chunks arrive). */
40
+ export interface FetchDataResult<T = any> {
41
+ rows: T[];
42
+ totalCount?: number | null;
43
+ }
44
+
45
+ export type FetchData<T = any> = (
46
+ params: FetchDataParams,
47
+ ) => Promise<FetchDataResult<T>>;
48
+
49
+ /**
50
+ * A table's data source, addressed uniformly whether it's an in-memory array or
51
+ * a remote backend. `fetchChunk` returns a window with the active sorts/filters
52
+ * already applied (in memory by the local provider, in SQL by a server one);
53
+ * `identity` addresses a row for edits/mutations — stable across re-sorts,
54
+ * unlike an array index. The mutation ops are present only for editable /
55
+ * persisting sources. The in-memory case (`createLocalProvider`) is just the
56
+ * degenerate implementation, so local and server tables share one path.
57
+ */
58
+ export interface TableDataProvider<T = any> {
59
+ fetchData(params: FetchDataParams): Promise<FetchDataResult<T>>;
60
+ identity(row: T): string | number;
61
+ saveRows?(rows: T[]): Promise<void>;
62
+ deleteRows?(ids: Array<string | number>): Promise<void>;
63
+ insertRow?(row: Partial<T>): Promise<void>;
64
+ }
65
+
66
+ /**
67
+ * The degenerate provider: an in-memory array. `fetchChunk` applies the active
68
+ * filter predicates and sorts over the array and returns the requested slice
69
+ * plus the (fully-known) total — the same view engine used for client-side
70
+ * tables, expressed as a provider.
71
+ */
72
+ export function createLocalProvider<T = any>(
73
+ data: T[],
74
+ options: { identity?: (row: T) => string | number } = {},
75
+ ): TableDataProvider<T> {
76
+ const identity: any = options.identity ?? defaultLocalIdentity;
77
+
78
+ return {
79
+ identity,
80
+ async fetchData({ offset, limit, sorts, filters }) {
81
+ let rows = data;
82
+ if (filters != null && filters.length > 0) {
83
+ rows = rows.filter((row) =>
84
+ filters.every((f) =>
85
+ f.predicate != null ? f.predicate(row, f.state) : true,
86
+ ),
87
+ );
88
+ }
89
+ if (sorts != null && sorts.length > 0) {
90
+ rows = [...rows].sort(compareRowsBySorts(sorts));
91
+ }
92
+ return {
93
+ rows: rows.slice(offset, offset + limit),
94
+ totalCount: rows.length,
95
+ };
96
+ },
97
+ };
98
+ }
99
+
100
+ // Stable synthetic identity for in-memory rows lacking a natural `id`. Keyed by
101
+ // object reference (a local data array keeps the same row objects across
102
+ // re-sorts), so edits survive re-ordering even without an id field.
103
+ const _syntheticRowIds = new WeakMap<object, string>();
104
+ let _syntheticRowCounter = 0;
105
+
106
+ function defaultLocalIdentity(row: any): string | number | undefined {
107
+ if (row == null) return undefined;
108
+ if (row.id != null) return row.id;
109
+ if (typeof row !== "object") return row;
110
+ let id = _syntheticRowIds.get(row);
111
+ if (id == null) {
112
+ id = `__row_${_syntheticRowCounter++}`;
113
+ _syntheticRowIds.set(row, id);
114
+ }
115
+ return id;
116
+ }
117
+
118
+ /** Multi-key row comparator (priority order; nulls first when ascending),
119
+ * shared by the local provider and any other in-memory sort. */
120
+ export function compareRowsBySorts(sorts: ColumnSort[]) {
121
+ return (a: any, b: any): number => {
122
+ for (const sort of sorts) {
123
+ const av = a?.[sort.key];
124
+ const bv = b?.[sort.key];
125
+ if (av == null && bv == null) continue;
126
+ if (av == null) return sort.ascending ? -1 : 1;
127
+ if (bv == null) return sort.ascending ? 1 : -1;
128
+ const cmp = av < bv ? -1 : av > bv ? 1 : 0;
129
+ if (cmp !== 0) return sort.ascending ? cmp : -cmp;
130
+ }
131
+ return 0;
132
+ };
133
+ }
134
+
135
+ /** Bump this to force the active chunk loader to reset and re-fetch from
136
+ * scratch — e.g. after a mutation (save/delete) that invalidates loaded rows. */
137
+ export const dataRefreshTokenAtom = atom(0);
138
+
139
+ /** Persist all pending changes through a data provider: added rows via
140
+ * `insertRow`, edited rows via `saveRows`, deleted rows via `deleteRows`
141
+ * (addressed by `provider.identity`). Used by the built-in Save action when an
142
+ * explicit provider owns persistence. */
143
+ export async function persistViaProvider<T>(
144
+ provider: TableDataProvider<T>,
145
+ ctx: TableActionContext<T>,
146
+ ): Promise<void> {
147
+ const base = (ctx.data ?? []) as any[];
148
+ const updates = (ctx.updatedData ?? []) as any[];
149
+ const status = (ctx.rowStatus ?? []) as any[];
150
+ const n = Math.max(base.length, updates.length, status.length);
151
+ const toSave: T[] = [];
152
+ const toInsert: T[] = [];
153
+ const toDelete: Array<string | number> = [];
154
+ for (let i = 0; i < n; i++) {
155
+ if (status[i] === TableElementStatus.DELETED) {
156
+ const id = provider.identity(base[i]);
157
+ if (id != null) toDelete.push(id);
158
+ continue;
159
+ }
160
+ const upd = updates[i];
161
+ const hasEdit =
162
+ upd != null && typeof upd === "object" && Object.keys(upd).length > 0;
163
+ if (status[i] === TableElementStatus.ADDED) {
164
+ toInsert.push({ ...base[i], ...upd } as T);
165
+ } else if (hasEdit) {
166
+ toSave.push({ ...base[i], ...upd } as T);
167
+ }
168
+ }
169
+ if (toDelete.length > 0 && provider.deleteRows != null) {
170
+ await provider.deleteRows(toDelete);
171
+ }
172
+ for (const row of toInsert) {
173
+ if (provider.insertRow != null) await provider.insertRow(row);
174
+ }
175
+ if (toSave.length > 0 && provider.saveRows != null) {
176
+ await provider.saveRows(toSave);
177
+ }
178
+ }
@@ -0,0 +1,273 @@
1
+ import type {
2
+ FocusedCellCoordinates,
3
+ Region,
4
+ RegionCardinality,
5
+ Table2,
6
+ } from "@blueprintjs/table";
7
+ import type { ColumnSpec, ColumnSpecOptions } from "./column-spec";
8
+ import { OverlayToaster } from "@blueprintjs/core";
9
+ import { DataViewCoreProps } from "../types";
10
+ import { DataViewRendererType } from "./interactions.ts";
11
+
12
+ /** A single column sort entry for client-side sorting.
13
+ * Defined here (rather than in actions/types) to avoid circular imports. */
14
+ export interface ColumnSort {
15
+ key: string;
16
+ ascending: boolean;
17
+ }
18
+
19
+ /** Direction of keyboard navigation between cells. */
20
+ export type NavDirection = "up" | "down" | "left" | "right";
21
+
22
+ /**
23
+ * A structured, revertible description of a user edit. Emitted via the
24
+ * `onEdit` hook so a consumer can capture edits as operations (and, with the
25
+ * controlled-overlay API, own the edited state) instead of diffing
26
+ * `updatedData`. This is the write half of the data-sheet's read/write
27
+ * contract — the mirror of how data flows in.
28
+ */
29
+ export type EditEvent<T = any> =
30
+ | { type: "setCells"; cells: CellEdit[] }
31
+ | { type: "deleteRows"; rowIndices: number[] }
32
+ | { type: "restoreRows"; rowIndices: number[] }
33
+ | { type: "addRow"; rowIndex: number; value: Partial<T> }
34
+ | { type: "resetChanges" };
35
+
36
+ export enum TableElementStatus {
37
+ DELETED = "deleted",
38
+ ADDED = "added",
39
+ }
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
+
47
+ /** Presentation for a row status: applied to the row's cells and its header
48
+ * cell. Keyed by status value in `rowStatusStyles`. The library ships a
49
+ * default for `"deleted"` (dimmed + struck through, danger intent); consumers
50
+ * merge in styles for their own statuses (and may override the defaults). */
51
+ export interface RowStatusStyle {
52
+ /** Style merged onto each cell in a row with this status. */
53
+ cellStyle?: import("react").CSSProperties;
54
+ /** Style applied to the row's header cell. */
55
+ headerStyle?: import("react").CSSProperties;
56
+ /** Blueprint intent applied to the row's cells (precedence: validation >
57
+ * this > edited-green). */
58
+ intent?: import("@blueprintjs/core").Intent;
59
+ }
60
+
61
+ export type RowStatusStyles = Record<string, RowStatusStyle>;
62
+
63
+ /** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged
64
+ * over this, so `"deleted"` keeps its look unless explicitly overridden. */
65
+ export const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles = {
66
+ [TableElementStatus.DELETED]: {
67
+ cellStyle: { opacity: 0.5, textDecoration: "line-through" },
68
+ headerStyle: { opacity: 0.5, textDecoration: "line-through" },
69
+ intent: "danger",
70
+ },
71
+ };
72
+
73
+ /** Context passed to a custom `rowHeaderRenderer`, so it can label and style
74
+ * the row header from the row's data and status (group-key labels, an
75
+ * omit indicator, etc.). Return a node to use as the header's name, or a
76
+ * nullish value to fall back to the default (1-based row number). */
77
+ export interface RowHeaderRenderContext<T = any> {
78
+ /** Data-row index (stable under sort/filter). */
79
+ rowIndex: number;
80
+ /** Visible (display) row index. */
81
+ visibleIndex: number;
82
+ /** The row's data (base, overlaid with edits if present). */
83
+ row: T | undefined;
84
+ /** The row's status, if any. */
85
+ status: RowStatusValue | undefined;
86
+ /** Convenience: `status === TableElementStatus.DELETED`. */
87
+ isDeleted: boolean;
88
+ /** The default label (`"${rowIndex + 1}"`). */
89
+ defaultLabel: string;
90
+ }
91
+
92
+ /** Property key holding a stable synthetic id on rows added in-table. Added
93
+ * rows aren't in the data provider, so they need their own identity to survive
94
+ * a provider re-fetch; it's carried on the row and preserved through edits. */
95
+ export const DS_ROW_ID = "__dsRowId";
96
+
97
+ /** Proxy stored during a copy operation, enabling backend-mediated paste
98
+ * for lazy-loaded tables where not all data is available locally. */
99
+ export interface ClipboardProxy {
100
+ cardinality: RegionCardinality;
101
+ /** Source row indices (for row/cell copies) */
102
+ rowIndices?: number[];
103
+ /** Source column keys (for column/cell copies) */
104
+ columnKeys?: string[];
105
+ /** The plain text written to the clipboard, used to verify the proxy
106
+ * is still valid on paste (i.e., clipboard hasn't been overwritten). */
107
+ text: string;
108
+ }
109
+
110
+ export interface DataSheetState<T> {
111
+ selection: Region[];
112
+ columnSpec: ColumnSpec[];
113
+ columnSpecOptions?: ColumnSpecOptions<T>;
114
+ /** When `true`, the loader's first-chunk auto-generation of `columnSpec` is
115
+ * suppressed — a function `columnSpec` derives it from the loaded rows
116
+ * instead (in `_DataSheet`). Set at init from the prop's shape. */
117
+ deferColumnSpec: boolean;
118
+ fillValueBaseCell: FocusedCellCoordinates | null;
119
+ focusedCell: FocusedCellCoordinates | null;
120
+ topLeftCell: FocusedCellCoordinates | null;
121
+ /**
122
+ * Set of row indices that have been added to the table,
123
+ * but not yet committed to the underlying data array.
124
+ *
125
+ * This is used to track which rows should be reverted when
126
+ * a "reset" action is performed.
127
+ */
128
+ rowStatus: (RowStatusValue | undefined)[];
129
+ /** Presentation per row-status value (merged: defaults + the
130
+ * `rowStatusStyles` prop). Read by the cell renderer and row-header renderer
131
+ * to style rows by status. */
132
+ rowStatusStyles: RowStatusStyles;
133
+ // Sparse data structure for updated data
134
+ updatedData: (T | null | undefined)[];
135
+ data: T[];
136
+ initialized: boolean;
137
+ columnWidthsIndex: Map<string, number>;
138
+ /** Active column/table filters. Keys are filter IDs, values carry the
139
+ * filter definition and its current configuration state. */
140
+ activeFilters: Map<string, { filter: any; state: any }>;
141
+ /** Clipboard proxy from the last copy operation */
142
+ clipboardProxy: ClipboardProxy | null;
143
+ /** Visible row indices when filters are active. `null` means show all rows. */
144
+ filteredRowIndices: number[] | null;
145
+ /** Active column sort entries for client-side sorting. */
146
+ columnSorts: ColumnSort[];
147
+ /** Whether selecting a cell automatically activates its surface (opens an
148
+ * editor/detail panel and, for editors, focuses it). `"manual"` opens only
149
+ * on click. */
150
+ cellInteraction: "auto" | "manual";
151
+ /** Runtime override of `cellInteraction`: while `false`, auto-activation is
152
+ * suppressed (set by pressing Escape, re-armed by clicking a cell) so the
153
+ * keyboard prioritizes navigation. */
154
+ autoActivateArmed: boolean;
155
+ /** Direction of the last keyboard navigation, used to place an editor's
156
+ * cursor on the side the user is travelling toward. `null` after a click. */
157
+ lastNavDirection: NavDirection | null;
158
+ /** The table's focusable holder element; editors return focus here when the
159
+ * cursor leaves them so arrow-key navigation resumes. */
160
+ tableElement: HTMLElement | null;
161
+ /** Whether the focused cell's surface (editor or detail panel) is open.
162
+ * Owned by the store — not per-popover — so navigation, clicks, and the
163
+ * Escape handler all agree on it. */
164
+ cellSurfaceOpen: boolean;
165
+ /** Optional observer called for every user edit as a structured
166
+ * `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a
167
+ * consumer capture edits as revertible operations. */
168
+ onEdit?: (event: EditEvent<T>) => void;
169
+ /** Row identity for the edit overlay — stable across a provider re-sort,
170
+ * unlike an array index. Defaults to `(row) => row?.id`; a data provider
171
+ * supplies its own (e.g. a PostgREST identity key). Used to re-attach edits
172
+ * when the loader replaces `data` with a re-ordered window. */
173
+ identity: (row: any) => string | number | null | undefined;
174
+ /** Edits/statuses held by identity for rows not currently loaded (server
175
+ * sources), re-attached when their row next arrives. */
176
+ pendingOverlayById: Map<
177
+ string | number,
178
+ { edit?: any; status?: TableElementStatus }
179
+ >;
180
+ /** True when the consumer controls the `updatedData`/`rowStatus` overlay; the
181
+ * loader-boundary identity remap is skipped (the consumer owns it). */
182
+ controlledOverlay: boolean;
183
+ /** Whether row deletion is available. Set from the data provider: an explicit
184
+ * `provider` without `deleteRows` disables deletion entirely (the delete
185
+ * affordance greys out and the delete key is a no-op). Defaults to `true`. */
186
+ canDeleteRows: boolean;
187
+ /** Provider-backed, auto-refreshing row mutations for immediate-edit consumers
188
+ * (chiefly `DataPanel`). Each persists through the data provider and then
189
+ * re-fetches. Wired by the consumer that owns the provider + loader; exposed
190
+ * on the action context as `saveRows` / `deleteRows` / `insertRow` /
191
+ * `refresh`, so a selection action can edit without hand-wiring persistence.
192
+ * Absent when no persisting provider. */
193
+ rowEditing?: {
194
+ saveRows?: (rows: any[]) => Promise<void>;
195
+ deleteRows?: (ids: Array<string | number>) => Promise<void>;
196
+ insertRow?: (row: any) => Promise<void>;
197
+ refresh?: () => void;
198
+ };
199
+ }
200
+
201
+ type DataSheetVals<T> = DataSheetState<T> & DataViewCoreProps<T>;
202
+ export type StateUpdater<T> = T[] | ((state: T[]) => T[]);
203
+
204
+ export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
205
+ setSelection(selection: Region[]): void;
206
+ onDragValue(event: MouseEvent): void;
207
+ setUpdatedData(data: StateUpdater<T>): void;
208
+ onCellEdited(rowIndex: number, columnName: string, value: any): void;
209
+ onSelectionEdited(value: any): void;
210
+ onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;
211
+ onColumnWidthChanged(columnIndex: number, newWidth: number): void;
212
+ moveFocusedCell(direction: NavDirection): void;
213
+ /** Suppress auto-activation until the next click (Escape enters nav mode). */
214
+ suppressAutoActivate(): void;
215
+ /** Re-arm auto-activation (a click re-enables auto-focus). */
216
+ armAutoActivate(): void;
217
+ /** Open the focused cell's surface (editor or detail panel). */
218
+ openCellSurface(): void;
219
+ /** Close the focused cell's surface. When `suppress` is true (the default,
220
+ * as for Escape), auto mode also enters navigation mode (auto-activation is
221
+ * suppressed until the next click). A click-dismiss passes `suppress: false`
222
+ * so it just closes without changing the global mode. */
223
+ closeCellSurface(opts?: { suppress?: boolean }): void;
224
+ deleteSelectedRows(): void;
225
+ clearSelection(): void;
226
+ resetChanges(): void;
227
+ addRow(): void;
228
+ /** Activate or update a column/table filter.
229
+ * Filter is any object satisfying `TableFilter` from the actions module. */
230
+ setFilter(filterId: string, filter: any, filterState: any): void;
231
+ /** Remove a filter by ID */
232
+ removeFilter(filterId: string): void;
233
+ /** Remove all active filters */
234
+ clearFilters(): void;
235
+ /** Set or clear a column sort. Pass `null` for ascending to clear. */
236
+ setColumnSort(key: string, ascending: boolean | null): void;
237
+ /** Remove all active column sorts */
238
+ clearColumnSorts(): void;
239
+ /** Store a clipboard proxy for potential backend-mediated paste */
240
+ setClipboardProxy(proxy: ClipboardProxy | null): void;
241
+ //initialize(props: Partial<DataSheetStoreMain<T>>): void;
242
+ onSelection(selection: Region[]): void;
243
+ // Internal method used for infinite scrolling
244
+ scrollToRow(rowIndex: number): void;
245
+ tableRef: React.MutableRefObject<Table2> | null;
246
+ columnWidthsIndex: Map<string, number>;
247
+ defaultColumnWidth: number;
248
+ // Editable is not optional on store
249
+ editable: boolean;
250
+ }
251
+
252
+ export type DataSheetProviderProps<T> = DataViewCoreProps<T> & {
253
+ toaster?: OverlayToaster;
254
+ viewType?: DataViewRendererType;
255
+ children?: React.ReactNode;
256
+ };
257
+
258
+ export interface VisibleCells {
259
+ rowIndexStart: number;
260
+ rowIndexEnd: number;
261
+ }
262
+
263
+ export type DataSheetStore<T> = DataSheetStoreMain<T>;
264
+
265
+ /** A single cell edit, used with `editCells` for batch updates. */
266
+ export interface CellEdit {
267
+ rowIndex: number;
268
+ column: string;
269
+ value: any;
270
+ /** The underlying row (base data). Populated on emitted `onEdit` events so a
271
+ * handler can address the row (identity) without reaching into the store. */
272
+ row?: any;
273
+ }