@macrostrat/data-sheet 4.1.1 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/CHANGELOG.md +34 -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/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
  78. package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
  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} +123 -190
  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} +92 -159
  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} +16 -27
  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} +145 -330
  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.js.map +0 -1
  278. package/dist/core.cjs.map +0 -1
  279. package/dist/core.d.ts +0 -117
  280. package/dist/core.js.map +0 -1
  281. package/dist/provider.cjs +0 -197
  282. package/dist/provider.cjs.map +0 -1
  283. package/dist/provider.d.ts +0 -26
  284. package/dist/provider.js +0 -195
  285. package/dist/provider.js.map +0 -1
  286. package/dist/table-updates/data-parameter.d.ts +0 -14
  287. package/dist/table-updates/filter.d.ts +0 -16
  288. package/dist/table-updates/index.d.ts +0 -19
  289. package/dist/utils/column-spec.cjs.map +0 -1
  290. package/dist/utils/column-spec.js.map +0 -1
  291. package/dist/utils/index.cjs +0 -9
  292. package/dist/utils/index.cjs.map +0 -1
  293. package/dist/utils/index.js +0 -9
  294. package/dist/utils/index.js.map +0 -1
  295. package/dist/zustand-store.cjs.map +0 -1
  296. package/dist/zustand-store.js.map +0 -1
  297. package/src/actions/filters.ts +0 -176
  298. package/src/components/actions.module.sass +0 -8
  299. package/src/provider.ts +0 -267
  300. package/src/table-updates/data-parameter.ts +0 -44
  301. package/src/table-updates/filter.ts +0 -124
  302. package/src/table-updates/index.ts +0 -239
  303. /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-spec.cjs","sources":["../../src/provider/column-spec.ts"],"sourcesContent":["import React from \"react\";\nimport { enhanceColumnFilter, TableFilter } from \"../actions\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | null | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any, ctx?: CellRenderContext) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec: ColumnSpec[] = [];\n for (const key of keys) {\n let width: number | undefined = undefined;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: Partial<ColumnSpecOptions<T>> = {},\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n const improvedSpec = filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n return postprocessColumnSpec(improvedSpec);\n}\n\nexport function postprocessColumnSpec(columnSpec: ColumnSpec[]) {\n /** Postprocess column spec to make sure that, e.g., column filters are\n * properly established, etc.\n */\n return columnSpec.map((col) => {\n return {\n ...col,\n filters: postprocessColumnFilters(col),\n actions: col.actions ?? [],\n };\n });\n}\n\nfunction postprocessColumnFilters(col: ColumnSpec): TableFilter[] | undefined {\n const { filterable = true, filters = [] } = col;\n if (!filterable) {\n return undefined;\n }\n return filters.map((f) => enhanceColumnFilter(col, f));\n}\n"],"names":["enhanceColumnFilter"],"mappings":"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"}
@@ -1,4 +1,5 @@
1
1
  import { default as React } from 'react';
2
+ import { TableFilter } from '../actions';
2
3
  interface ColumnSpecGenerateOptions {
3
4
  calculateWidths?: boolean;
4
5
  defaultWidth?: number;
@@ -34,7 +35,7 @@ export interface CellRenderContext<T = any> {
34
35
  /** The full column spec for this cell's column. */
35
36
  column: ColumnSpec;
36
37
  /** The full row object backing this cell (may be undefined while loading). */
37
- row: T | undefined;
38
+ row: T | null | undefined;
38
39
  /** Whether this cell has an uncommitted edit. */
39
40
  isEdited: boolean;
40
41
  /** Whether this cell's row is marked for deletion. */
@@ -156,5 +157,75 @@ export interface ColumnSpecOptions<T> {
156
157
  includeColumns?: string[];
157
158
  }
158
159
  export declare function generateDefaultColumnSpec<T>(data: Array<T>, options?: ColumnSpecGenerateOptions): ColumnSpec[];
159
- export declare function generateColumnSpec<T>(data: T[], options: ColumnSpecOptions<T>): ColumnSpec[];
160
+ export declare function generateColumnSpec<T>(data: T[], options?: Partial<ColumnSpecOptions<T>>): ColumnSpec[];
161
+ export declare function postprocessColumnSpec(columnSpec: ColumnSpec[]): {
162
+ filters: TableFilter<any, any>[] | undefined;
163
+ actions: any[];
164
+ name: string;
165
+ key: string;
166
+ /** When true, an empty value is an error (sugar over `validate`). */
167
+ required?: boolean;
168
+ /** Validate a cell's value. Return a `{ severity, message }` for a
169
+ * warning/error, or `null` when valid. Runs after the `required` check.
170
+ * `warning` flags the cell but allows saving; `error` blocks saving. */
171
+ validate?: (value: any, row: any, ctx: {
172
+ rowIndex: number;
173
+ }) => CellValidation | null;
174
+ /** @deprecated Prefer `validate`, which carries severity + a message.
175
+ * A falsy result maps to an `error`. */
176
+ isValid?: (d: any) => boolean;
177
+ transformValue?: (d: any) => any;
178
+ valueRenderer?: (d: any, ctx?: CellRenderContext) => string | React.ReactNode;
179
+ headerRenderer?: (d: any) => string | React.ReactNode;
180
+ dataEditor?: any;
181
+ /**
182
+ * Choose the editor for an individual cell from its render context,
183
+ * overriding the static `dataEditor` / `inlineEditor` for that cell. Return
184
+ * `undefined` (or omit a key) to fall back to the static configuration —
185
+ * e.g. show a textarea only for cells whose value is long. A returned key is
186
+ * respected even when its value is `false`/`null` (i.e. "no editor here").
187
+ */
188
+ editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;
189
+ /**
190
+ * Render a read-only detail panel for a cell. When set, selecting the cell
191
+ * opens a popover with this content (following the table's `cellInteraction`
192
+ * mode). The panel never takes keyboard focus, so arrow keys keep navigating
193
+ * the table; Escape closes it. Mutually distinct from `dataEditor` — use this
194
+ * for non-editable surfaces (previews, summaries, links).
195
+ *
196
+ * @deprecated Prefer `cellDetail`, which unifies editor and viewer.
197
+ */
198
+ detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;
199
+ /**
200
+ * The unified cell surface (Workstream A): one renderer that acts as an
201
+ * editor when `ctx.editable` and a read-only viewer otherwise, superseding
202
+ * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen
203
+ * separately via `detailPresentation` (popover / modal / inline), so the
204
+ * same component works in any container.
205
+ */
206
+ cellDetail?: (ctx: CellDetailContext) => React.ReactNode;
207
+ /** How `cellDetail` is presented. Defaults to `"popover"`. */
208
+ detailPresentation?: DetailPresentation;
209
+ cellComponent?: any;
210
+ category?: string;
211
+ editable?: boolean;
212
+ inlineEditor?: boolean | React.ComponentType<any> | string | null;
213
+ style?: React.CSSProperties;
214
+ width?: number;
215
+ /** Whether this column supports server-side sorting. */
216
+ sortable?: boolean;
217
+ /** Whether this column supports server-side filtering.
218
+ * Set to `true` for default operators, or provide a config object
219
+ * with a custom set of operators. */
220
+ filterable?: boolean | {
221
+ operators?: string[];
222
+ };
223
+ /** Inferred data type, used to select context-appropriate filter
224
+ * operators when `filterable` is `true` without explicit operators. */
225
+ dataType?: ColumnDataType;
226
+ /** Whether this column may be drag-reordered. Defaults to `true`; set
227
+ * `false` to pin a fixed/system column in place. Applied by the default
228
+ * header renderer (requires table-level `enableColumnReordering`). */
229
+ reorderable?: boolean;
230
+ }[];
160
231
  export {};
@@ -1,3 +1,4 @@
1
+ import { enhanceColumnFilter } from "../actions/column-filter.js";
1
2
  const defaultRenderers = {
2
3
  string: (d) => d,
3
4
  number: (d) => d?.toFixed(2),
@@ -56,7 +57,7 @@ function generateDefaultColumnSpec(data, options = {}) {
56
57
  }
57
58
  const spec = [];
58
59
  for (const key of keys) {
59
- let width = null;
60
+ let width = void 0;
60
61
  if (calculateWidths) {
61
62
  width = Math.min(
62
63
  Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),
@@ -77,13 +78,8 @@ function generateDefaultColumnSpec(data, options = {}) {
77
78
  }
78
79
  return spec;
79
80
  }
80
- function generateColumnSpec(data, options) {
81
- const {
82
- overrides = {},
83
- nRows = 10,
84
- omitColumns,
85
- includeColumns
86
- } = options ?? {};
81
+ function generateColumnSpec(data, options = {}) {
82
+ const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;
87
83
  if (data == null) return [];
88
84
  const _nRows = Math.min(nRows, data.length);
89
85
  let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));
@@ -96,7 +92,7 @@ function generateColumnSpec(data, options) {
96
92
  }
97
93
  return true;
98
94
  });
99
- return filteredSpec.map((col) => {
95
+ const improvedSpec = filteredSpec.map((col) => {
100
96
  let ovr = overrides[col.key];
101
97
  if (ovr == null) return col;
102
98
  if (typeof ovr === "string") {
@@ -104,9 +100,27 @@ function generateColumnSpec(data, options) {
104
100
  }
105
101
  return { ...col, ...ovr };
106
102
  });
103
+ return postprocessColumnSpec(improvedSpec);
104
+ }
105
+ function postprocessColumnSpec(columnSpec) {
106
+ return columnSpec.map((col) => {
107
+ return {
108
+ ...col,
109
+ filters: postprocessColumnFilters(col),
110
+ actions: col.actions ?? []
111
+ };
112
+ });
113
+ }
114
+ function postprocessColumnFilters(col) {
115
+ const { filterable = true, filters = [] } = col;
116
+ if (!filterable) {
117
+ return void 0;
118
+ }
119
+ return filters.map((f) => enhanceColumnFilter(col, f));
107
120
  }
108
121
  export {
109
122
  generateColumnSpec,
110
- generateDefaultColumnSpec
123
+ generateDefaultColumnSpec,
124
+ postprocessColumnSpec
111
125
  };
112
126
  //# sourceMappingURL=column-spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-spec.js","sources":["../../src/provider/column-spec.ts"],"sourcesContent":["import React from \"react\";\nimport { enhanceColumnFilter, TableFilter } from \"../actions\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | null | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any, ctx?: CellRenderContext) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec: ColumnSpec[] = [];\n for (const key of keys) {\n let width: number | undefined = undefined;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: Partial<ColumnSpecOptions<T>> = {},\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n const improvedSpec = filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n return postprocessColumnSpec(improvedSpec);\n}\n\nexport function postprocessColumnSpec(columnSpec: ColumnSpec[]) {\n /** Postprocess column spec to make sure that, e.g., column filters are\n * properly established, etc.\n */\n return columnSpec.map((col) => {\n return {\n ...col,\n filters: postprocessColumnFilters(col),\n actions: col.actions ?? [],\n };\n });\n}\n\nfunction postprocessColumnFilters(col: ColumnSpec): TableFilter[] | undefined {\n const { filterable = true, filters = [] } = col;\n if (!filterable) {\n return undefined;\n }\n return filters.map((f) => enhanceColumnFilter(col, f));\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const h = require("@macrostrat/hyper");
5
+ const zustand = require("zustand");
6
+ const columnSpec = require("./column-spec.cjs");
7
+ const dataComponents = require("@macrostrat/data-components");
8
+ const types = require("./types.cjs");
9
+ const zustandStore = require("./zustand-store.cjs");
10
+ const jotaiZustand = require("jotai-zustand");
11
+ const notifications = require("../notifications.cjs");
12
+ const jotai = require("jotai");
13
+ const tableData = require("./table-data.cjs");
14
+ const uiComponents = require("@macrostrat/ui-components");
15
+ const interactions = require("./interactions.cjs");
16
+ const atoms = require("../utils/atoms.cjs");
17
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
18
+ const h__default = /* @__PURE__ */ _interopDefault(h);
19
+ const ctx = dataComponents.createScopedStore();
20
+ const storeAPIAtom = jotai.atom();
21
+ const storeWrapperAtom = jotai.atom((get) => {
22
+ const _storeAPIAtom = get(storeAPIAtom);
23
+ if (_storeAPIAtom == null) {
24
+ return void 0;
25
+ }
26
+ return jotaiZustand.atomWithStore(_storeAPIAtom);
27
+ });
28
+ const storeAtom = jotai.atom(
29
+ (get) => {
30
+ const storeWrapper = get(storeWrapperAtom);
31
+ if (storeWrapper == null) {
32
+ return void 0;
33
+ }
34
+ return get(storeWrapper);
35
+ },
36
+ (get, set, action) => {
37
+ const storeWrapper = get(storeWrapperAtom);
38
+ if (storeWrapper == null) {
39
+ throw new Error("Missing DataSheetProvider");
40
+ }
41
+ return set(storeWrapper, action);
42
+ }
43
+ );
44
+ const EMPTY_SPEC = [];
45
+ const initializeStoreAtom = jotai.atom(
46
+ null,
47
+ (get, set, payload) => {
48
+ set(storeAtom, (state) => {
49
+ return {
50
+ ...state,
51
+ ...payload
52
+ };
53
+ });
54
+ }
55
+ );
56
+ const tableActionsAtom = jotai.atom([]);
57
+ const DEFAULT_DATA_PROVIDER = {
58
+ provider: null,
59
+ isLocalProvider: true,
60
+ isExplicitProvider: false,
61
+ localCount: 0
62
+ };
63
+ const dataProviderAtom = jotai.atom(
64
+ DEFAULT_DATA_PROVIDER
65
+ );
66
+ const EMPTY_ARRAY = [];
67
+ function useResolvedProvider(props) {
68
+ const _data = props.data ?? EMPTY_ARRAY;
69
+ const isLocalProvider = props.provider == null && props.fetchData == null;
70
+ const isExplicitProvider = props.provider != null;
71
+ const activeProvider = react.useMemo(() => {
72
+ if (props.provider != null) return props.provider;
73
+ if (props.fetchData != null) {
74
+ return {
75
+ fetchData: props.fetchData,
76
+ identity: props.identity ?? ((r) => r?.id)
77
+ };
78
+ }
79
+ if (_data.length > 0) {
80
+ return tableData.createLocalProvider(
81
+ _data,
82
+ props.identity != null ? { identity: props.identity } : void 0
83
+ );
84
+ }
85
+ return null;
86
+ }, [props.provider, props.fetchData, _data, props.identity]);
87
+ const localCount = isLocalProvider ? _data.length : 0;
88
+ const dataProvider = react.useMemo(
89
+ () => ({
90
+ provider: activeProvider,
91
+ isLocalProvider,
92
+ isExplicitProvider,
93
+ localCount
94
+ }),
95
+ [activeProvider, isLocalProvider, isExplicitProvider, localCount]
96
+ );
97
+ return { data: _data, isLocalProvider, activeProvider, dataProvider };
98
+ }
99
+ function DataSheetStoreWrapper(props) {
100
+ const { toaster, ...rest } = props;
101
+ const [store] = react.useState(() => {
102
+ return zustand.createStore(zustandStore.createZustandStore);
103
+ });
104
+ return h__default.default(
105
+ ctx.Provider,
106
+ {
107
+ atoms: [
108
+ [storeAPIAtom, store],
109
+ [notifications.toasterAtom, toaster]
110
+ ]
111
+ },
112
+ h__default.default(DataSheetProviderInner, rest)
113
+ );
114
+ }
115
+ const tableDataProviderKeys = /* @__PURE__ */ new Set([
116
+ "provider",
117
+ "fetchData",
118
+ "data",
119
+ "identity"
120
+ ]);
121
+ const dataProviderKeys = /* @__PURE__ */ new Set([
122
+ "columnSpec",
123
+ "columnSpecOptions",
124
+ "name",
125
+ "itemLabel",
126
+ "enableColumnReordering",
127
+ "defaultColumnWidth",
128
+ "refreshToken",
129
+ "identity",
130
+ "toaster",
131
+ "viewType",
132
+ "interactionOptions"
133
+ ]);
134
+ function splitDataProviderProps(props) {
135
+ return atoms.splitProps(
136
+ props,
137
+ dataProviderKeys.union(interactions.interactionOptionsKeys).union(tableDataProviderKeys)
138
+ );
139
+ }
140
+ function DataSheetProvider(props) {
141
+ return h__default.default(
142
+ uiComponents.ToasterContext,
143
+ h__default.default(uiComponents.ErrorBoundary, h__default.default(DataSheetStoreWrapper, props))
144
+ );
145
+ }
146
+ function DataSheetProviderInner(props) {
147
+ const tableRef = react.useRef(null);
148
+ const [interactionOptionsProps, providerProps] = atoms.splitProps(props, interactions.interactionOptionsKeys);
149
+ const interactionOptions = interactions.resolveInteractionOptions(
150
+ interactionOptionsProps,
151
+ props.viewType ?? interactions.DataViewRendererType.TABLE
152
+ );
153
+ const {
154
+ children,
155
+ columnSpec: columnSpec$1,
156
+ columnSpecOptions,
157
+ name,
158
+ itemLabel,
159
+ enableColumnReordering,
160
+ defaultColumnWidth = 150,
161
+ refreshToken,
162
+ identity
163
+ } = providerProps;
164
+ const { data, dataProvider } = useResolvedProvider(providerProps);
165
+ const initializeStore = ctx.useSet(initializeStoreAtom);
166
+ const storeAPI = useStoreAPI();
167
+ ctx.useSync(dataProviderAtom, dataProvider ?? DEFAULT_DATA_PROVIDER);
168
+ ctx.useSync(interactions.interactionOptionsAtom, interactionOptions);
169
+ const contentLabels = react.useMemo(() => {
170
+ return { tableName: name, itemLabel };
171
+ }, [name, itemLabel]);
172
+ ctx.useSync(contentLabelsAtom, contentLabels);
173
+ const isFnSpec = typeof columnSpec$1 === "function";
174
+ const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec$1;
175
+ const baseSpec = staticSpec ?? columnSpec.generateColumnSpec(data, columnSpecOptions);
176
+ react.useEffect(() => {
177
+ initializeStore({
178
+ columnSpec: columnSpec.postprocessColumnSpec(baseSpec),
179
+ // A function spec is derived from the loaded rows in `_DataSheet`; tell
180
+ // the loader not to auto-generate a plain spec from the first chunk.
181
+ deferColumnSpec: isFnSpec,
182
+ editable: interactionOptions.enableEditing,
183
+ enableColumnReordering,
184
+ data,
185
+ defaultColumnWidth,
186
+ tableRef
187
+ });
188
+ }, [
189
+ data,
190
+ interactionOptions.enableEditing,
191
+ staticSpec,
192
+ isFnSpec,
193
+ columnSpecOptions,
194
+ enableColumnReordering
195
+ ]);
196
+ const loadedData = useSelector((s) => s.data ?? []);
197
+ const derivedSpecFor = react.useRef(null);
198
+ react.useEffect(() => {
199
+ if (typeof columnSpec$1 !== "function") return;
200
+ if (derivedSpecFor.current === columnSpec$1) return;
201
+ const rows = loadedData.filter((r) => r != null);
202
+ if (rows.length === 0) return;
203
+ derivedSpecFor.current = columnSpec$1;
204
+ storeAPI.setState({ columnSpec: columnSpec$1(rows) });
205
+ }, [columnSpec$1, loadedData, storeAPI]);
206
+ const bumpRefresh = ctx.useSet(tableData.dataRefreshTokenAtom);
207
+ const firstRefreshToken = react.useRef(true);
208
+ react.useEffect(() => {
209
+ if (firstRefreshToken.current) {
210
+ firstRefreshToken.current = false;
211
+ return;
212
+ }
213
+ bumpRefresh((v) => v + 1);
214
+ }, [refreshToken, bumpRefresh]);
215
+ react.useEffect(() => {
216
+ const p = dataProvider?.provider ?? null;
217
+ const refresh = () => bumpRefresh((v) => v + 1);
218
+ const withRefresh = (fn) => fn == null ? void 0 : async (...args) => {
219
+ await fn(...args);
220
+ refresh();
221
+ };
222
+ storeAPI.setState({
223
+ rowEditing: {
224
+ saveRows: withRefresh(p?.saveRows?.bind(p)),
225
+ deleteRows: withRefresh(p?.deleteRows?.bind(p)),
226
+ insertRow: withRefresh(p?.insertRow?.bind(p)),
227
+ refresh
228
+ }
229
+ });
230
+ }, [storeAPI, dataProvider, bumpRefresh]);
231
+ react.useEffect(() => {
232
+ const id = dataProvider?.provider?.identity ?? identity;
233
+ if (id != null) storeAPI.setState({ identity: id });
234
+ }, [storeAPI, dataProvider, identity]);
235
+ react.useEffect(() => {
236
+ const canDeleteRows = !dataProvider?.isExplicitProvider || dataProvider.provider?.deleteRows != null;
237
+ storeAPI.setState({ canDeleteRows });
238
+ }, [storeAPI, dataProvider]);
239
+ return children;
240
+ }
241
+ function useStoreAPI() {
242
+ const store = ctx.useValue(storeAPIAtom);
243
+ if (!store) {
244
+ throw new Error("Missing DataSheetProvider");
245
+ }
246
+ return store;
247
+ }
248
+ function useSelector(selector) {
249
+ const store = useStoreAPI();
250
+ return zustand.useStore(store, selector);
251
+ }
252
+ const columnSpecAtom = jotai.atom((get) => get(storeAtom)?.columnSpec ?? []);
253
+ const tableDataAtom = jotai.atom(
254
+ (get) => {
255
+ return get(storeAtom)?.data ?? [];
256
+ },
257
+ (get, set, newData) => {
258
+ set(storeAtom, (state) => {
259
+ let next = { ...state, data: newData };
260
+ if (state.columnSpec.length == 0 && !state.deferColumnSpec) {
261
+ const sample = newData.filter((row) => row != null);
262
+ if (sample.length > 0) {
263
+ next.columnSpec = columnSpec.generateColumnSpec(sample, state.columnSpecOptions);
264
+ }
265
+ }
266
+ if (!state.controlledOverlay) {
267
+ const remap = remapOverlayByIdentity(state, newData);
268
+ next.data = remap.data;
269
+ next.updatedData = remap.updatedData;
270
+ next.rowStatus = remap.rowStatus;
271
+ next.pendingOverlayById = remap.pending;
272
+ }
273
+ return next;
274
+ });
275
+ }
276
+ );
277
+ function overlayIdentity(state, row) {
278
+ if (row == null) return void 0;
279
+ const added = row[types.DS_ROW_ID];
280
+ if (added != null) return added;
281
+ return state.identity(row);
282
+ }
283
+ function remapOverlayByIdentity(state, newData) {
284
+ const { data: oldData, updatedData, rowStatus } = state;
285
+ const byId = new Map(state.pendingOverlayById);
286
+ const n = Math.max(
287
+ oldData.length,
288
+ updatedData?.length ?? 0,
289
+ rowStatus?.length ?? 0
290
+ );
291
+ for (let i = 0; i < n; i++) {
292
+ const row = oldData[i];
293
+ if (row == null) continue;
294
+ const id = overlayIdentity(state, row);
295
+ if (id == null) continue;
296
+ const edit = updatedData?.[i];
297
+ const status = rowStatus?.[i];
298
+ if (edit != null || status != null) byId.set(id, { edit, status });
299
+ }
300
+ const resultData = newData.slice();
301
+ const nextUpdated = [];
302
+ const nextStatus = [];
303
+ const attached = /* @__PURE__ */ new Set();
304
+ for (let j = 0; j < resultData.length; j++) {
305
+ const row = resultData[j];
306
+ if (row == null) continue;
307
+ const id = overlayIdentity(state, row);
308
+ if (id == null) continue;
309
+ const entry = byId.get(id);
310
+ if (entry == null) continue;
311
+ if (entry.edit != null) nextUpdated[j] = entry.edit;
312
+ if (entry.status != null) nextStatus[j] = entry.status;
313
+ attached.add(id);
314
+ }
315
+ const pending = /* @__PURE__ */ new Map();
316
+ for (const [id, entry] of byId) {
317
+ if (attached.has(id)) continue;
318
+ if (entry.status === types.TableElementStatus.ADDED) {
319
+ const idx = resultData.length;
320
+ resultData.push(entry.edit ?? {});
321
+ nextUpdated[idx] = entry.edit;
322
+ nextStatus[idx] = entry.status;
323
+ } else {
324
+ pending.set(id, entry);
325
+ }
326
+ }
327
+ return {
328
+ data: resultData,
329
+ updatedData: nextUpdated,
330
+ rowStatus: nextStatus,
331
+ pending
332
+ };
333
+ }
334
+ const contentLabelsAtom = jotai.atom({
335
+ tableName: null,
336
+ itemLabel: null
337
+ });
338
+ const itemLabelAtom = jotai.atom((get) => {
339
+ return get(contentLabelsAtom).itemLabel ?? "row";
340
+ });
341
+ const tableNameAtom = jotai.atom((get) => {
342
+ let { tableName, itemLabel } = get(contentLabelsAtom);
343
+ if (tableName != null) return tableName;
344
+ if (itemLabel != null) capitalize(pluralize(itemLabel, 2));
345
+ return "Table";
346
+ });
347
+ function useItemCount(n) {
348
+ const dataKind = ctx.useValue(itemLabelAtom);
349
+ return itemCount(n, dataKind ?? "row");
350
+ }
351
+ function itemCount(n, dataKind) {
352
+ const base = n == 0 ? "No" : `${n}`;
353
+ return base + " " + pluralize(dataKind, n);
354
+ }
355
+ function pluralize(singularForm, n) {
356
+ const pluralForm = singularForm + "s";
357
+ if (n == 0) return `${pluralForm}`;
358
+ if (n == 1) return singularForm;
359
+ return pluralForm;
360
+ }
361
+ function capitalize(s) {
362
+ return s.charAt(0).toUpperCase() + s.slice(1);
363
+ }
364
+ exports.DataSheetProvider = DataSheetProvider;
365
+ exports.DataSheetProviderInner = DataSheetProviderInner;
366
+ exports.capitalize = capitalize;
367
+ exports.columnSpecAtom = columnSpecAtom;
368
+ exports.ctx = ctx;
369
+ exports.dataProviderAtom = dataProviderAtom;
370
+ exports.itemLabelAtom = itemLabelAtom;
371
+ exports.pluralize = pluralize;
372
+ exports.splitDataProviderProps = splitDataProviderProps;
373
+ exports.storeAPIAtom = storeAPIAtom;
374
+ exports.storeAtom = storeAtom;
375
+ exports.tableActionsAtom = tableActionsAtom;
376
+ exports.tableDataAtom = tableDataAtom;
377
+ exports.tableNameAtom = tableNameAtom;
378
+ exports.useItemCount = useItemCount;
379
+ exports.useResolvedProvider = useResolvedProvider;
380
+ exports.useSelector = useSelector;
381
+ exports.useStoreAPI = useStoreAPI;
382
+ //# sourceMappingURL=core.cjs.map