@dataverse-kit/grid-kit 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2254,13 +2254,29 @@ const GROUP_CHEVRON_WIDTH = 36;
2254
2254
  * groups + count badges), reusing the same columns/registry as `<DataGrid>`.
2255
2255
  */
2256
2256
  function GroupedGrid(props) {
2257
- const { items, columns, group, selectionMode = 'none', isLoading, pagination, onPageChange, aggregateItems, toolbar, compact, alternateRowColors, fill, height, rowCommands } = props;
2257
+ const { items, columns, group, selectionMode = 'none', onSelectionChanged, isLoading, pagination, onPageChange, aggregateItems, toolbar, compact, alternateRowColors, fill, height, rowCommands } = props;
2258
2258
  const edit = useEditState();
2259
- const { ctx } = useGridContext(props, edit);
2259
+ const { ctx, getKeyFn } = useGridContext(props, edit);
2260
2260
  const dlColumns = React.useMemo(() => toDetailsListColumns(columns, ctx), [columns, ctx]);
2261
2261
  // Per-row right-click menu (DetailsList path, same as DataGrid/NestedInline). No-op when
2262
2262
  // rowCommands is unset (onItemContextMenu is undefined → no handler attached).
2263
2263
  const { onItemContextMenu, contextMenuElement } = useRowContextMenu(rowCommands);
2264
+ // Fluent Selection so a toolbar's selection-gated commands can read the checked rows via
2265
+ // onSelectionChanged. Ported verbatim from <DataGrid> (the grouped DetailsList supports
2266
+ // selection + groups together: the Selection is over the flattened `orderedItems`, and
2267
+ // group headers select-all per group). `getKey` (= the consumer's getKey via getKeyFn) keys
2268
+ // the selection per row; null-safe for enableShimmer placeholder rows. selectionMode='none'
2269
+ // (the default) passes no selection → display-only / per-row-menu-only grids are unchanged.
2270
+ const safeRowKey = (it, index) => it == null ? `__gridkit_shimmer_${index ?? 0}` : getKeyFn(it);
2271
+ const onSelectionChangedRef = React.useRef(onSelectionChanged);
2272
+ onSelectionChangedRef.current = onSelectionChanged;
2273
+ const selectionRef = React.useRef();
2274
+ if (!selectionRef.current) {
2275
+ selectionRef.current = new react.Selection({
2276
+ getKey: (it, index) => safeRowKey(it, index),
2277
+ onSelectionChanged: () => onSelectionChangedRef.current?.(selectionRef.current.getSelection()),
2278
+ });
2279
+ }
2264
2280
  // Bucket by groupBy → ordered items + IGroup[] (DetailsList needs contiguous
2265
2281
  // group ranges). See buildGroups (pure + unit-tested).
2266
2282
  const { orderedItems, groups } = React.useMemo(() => buildGroups(items, group), [items, group]);
@@ -2292,7 +2308,7 @@ function GroupedGrid(props) {
2292
2308
  });
2293
2309
  }
2294
2310
  : undefined, [alternateRowColors]);
2295
- return (jsxRuntime.jsxs(react.Stack, { styles: fillStackStyles(fill, height), children: [toolbar && jsxRuntime.jsx(GridToolbar, { config: toolbar }), jsxRuntime.jsx(FillRegion, { fill: fill, children: jsxRuntime.jsx(react.ShimmeredDetailsList, { items: orderedItems, columns: dlColumns, groups: groups, selectionMode: mapSelectionMode$1(selectionMode), layoutMode: react.DetailsListLayoutMode.justified, compact: compact, setKey: "grid-kit-grouped", onRenderRow: onRenderRow, onItemContextMenu: onItemContextMenu, styles: dynamicsCellRenderers.getDetailsListStyles(), ariaLabelForGrid: "Grouped grid", groupProps: {
2311
+ return (jsxRuntime.jsxs(react.Stack, { styles: fillStackStyles(fill, height), children: [toolbar && jsxRuntime.jsx(GridToolbar, { config: toolbar }), jsxRuntime.jsx(FillRegion, { fill: fill, children: jsxRuntime.jsx(react.ShimmeredDetailsList, { items: orderedItems, columns: dlColumns, groups: groups, selectionMode: mapSelectionMode$1(selectionMode), selection: selectionMode !== 'none' ? selectionRef.current : undefined, getKey: (it, index) => safeRowKey(it, index), layoutMode: react.DetailsListLayoutMode.justified, compact: compact, setKey: "grid-kit-grouped", onRenderRow: onRenderRow, onItemContextMenu: onItemContextMenu, styles: dynamicsCellRenderers.getDetailsListStyles(), ariaLabelForGrid: "Grouped grid", groupProps: {
2296
2312
  showEmptyGroups: false,
2297
2313
  // Render a subtotal under each EXPANDED group. Fluent v8 calls the group
2298
2314
  // footer renderer even for collapsed groups, so guard on isCollapsed —