@dataverse-kit/grid-kit 0.1.0 → 0.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.
@@ -6,7 +6,8 @@ import type { CardGridProps } from '../types';
6
6
  * ratings, etc. look identical). Mirrors the Grid Customizer's "Card List" type.
7
7
  *
8
8
  * Selection is checkbox-based (manual Set), independent of Fluent's DetailsList
9
- * Selection.
9
+ * Selection. `rowCommands` adds a per-card right-click context menu (parity with
10
+ * `DataGrid` / `NestedCardParent`), suppressing the native browser menu.
10
11
  */
11
12
  export declare function CardGrid<T extends Record<string, unknown>>(props: CardGridProps<T>): JSX.Element;
12
13
  //# sourceMappingURL=CardGrid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CardGrid.d.ts","sourceRoot":"","sources":["../../src/hosts/CardGrid.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,UAAU,CAAC;AASzD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CA6GhG"}
1
+ {"version":3,"file":"CardGrid.d.ts","sourceRoot":"","sources":["../../src/hosts/CardGrid.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,UAAU,CAAC;AAUzD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAoIhG"}
package/dist/index.esm.js CHANGED
@@ -2134,10 +2134,18 @@ function resolveCardLayout(columns, card) {
2134
2134
  * ratings, etc. look identical). Mirrors the Grid Customizer's "Card List" type.
2135
2135
  *
2136
2136
  * Selection is checkbox-based (manual Set), independent of Fluent's DetailsList
2137
- * Selection.
2137
+ * Selection. `rowCommands` adds a per-card right-click context menu (parity with
2138
+ * `DataGrid` / `NestedCardParent`), suppressing the native browser menu.
2138
2139
  */
2139
2140
  function CardGrid(props) {
2140
- const { items, columns, card, selectionMode = 'none', onSelectionChanged, toolbar, pagination, onPageChange, onActiveItemChanged, fill, height, } = props;
2141
+ const { items, columns, card, selectionMode = 'none', onSelectionChanged, toolbar, pagination, onPageChange, onActiveItemChanged, fill, height, rowCommands, } = props;
2142
+ // Per-row right-click menu (parity with DataGrid / NestedCardParent). For these
2143
+ // raw-div cards we invoke the hook fn from a native onContextMenu and suppress the
2144
+ // browser menu with e.preventDefault() ourselves (the hook's `return false` only
2145
+ // matters to Fluent's DetailsList onItemContextMenu contract). CardGrid is FLAT — no
2146
+ // nested child region — so (unlike NestedCardParent) nothing needs contextmenu
2147
+ // stopPropagation.
2148
+ const { onItemContextMenu, contextMenuElement } = useRowContextMenu(rowCommands);
2141
2149
  const edit = useEditState();
2142
2150
  const { getKeyFn, ctx } = useGridContext(props, edit);
2143
2151
  // Card layout derivation is shared (and unit-tested) via resolveCardLayout —
@@ -2176,10 +2184,21 @@ function CardGrid(props) {
2176
2184
  paddingTop: 4,
2177
2185
  }, children: items.map((item) => {
2178
2186
  const key = getKeyFn(item);
2179
- return (jsxs("div", { className: cardClass, style: cardHeight ? { height: cardHeight } : undefined, onClick: () => onActiveItemChanged?.(item), children: [jsxs(Stack, { horizontal: true, horizontalAlign: "space-between", verticalAlign: "start", children: [jsx(Text, { variant: "mediumPlus", styles: { root: { fontWeight: 600 } }, children: renderField(byField.get(titleField ?? ''), item) ?? rawValue(item, titleField) }), selectionMode !== 'none' && (
2187
+ return (jsxs("div", { className: cardClass, style: cardHeight ? { height: cardHeight } : undefined, onClick: () => onActiveItemChanged?.(item),
2188
+ // Right-click anywhere on the card opens its row menu. The card is the
2189
+ // row-equivalent target: the title/body cells have no handler to intercept
2190
+ // it, and the selection checkbox below only stops LEFT-click (its onClick
2191
+ // stopPropagation), so a right-click on any of them bubbles here
2192
+ // (preventDefault suppresses the browser menu).
2193
+ onContextMenu: onItemContextMenu
2194
+ ? (e) => {
2195
+ e.preventDefault();
2196
+ onItemContextMenu(item, undefined, e.nativeEvent);
2197
+ }
2198
+ : undefined, children: [jsxs(Stack, { horizontal: true, horizontalAlign: "space-between", verticalAlign: "start", children: [jsx(Text, { variant: "mediumPlus", styles: { root: { fontWeight: 600 } }, children: renderField(byField.get(titleField ?? ''), item) ?? rawValue(item, titleField) }), selectionMode !== 'none' && (
2180
2199
  // Stop the click from bubbling to the card's onActiveItemChanged.
2181
2200
  jsx("span", { onClick: (e) => e.stopPropagation(), children: jsx(Checkbox, { checked: selected.has(key), onChange: (_, checked) => toggleSelect(item, checked), ariaLabel: "Select card" }) }))] }), imageField && rawValue(item, imageField) && (jsx("img", { className: cardImageClass, src: rawValue(item, imageField), alt: "" })), subtitleField && (jsx(Text, { variant: "small", styles: { root: { color: '#605e5c' } }, children: rawValue(item, subtitleField) })), bodyColumns.map((col) => (jsxs("div", { className: bodyRowClass, children: [jsx(Text, { variant: "small", styles: { root: { color: '#605e5c' } }, children: col.name }), jsx("span", { children: renderField(col, item) })] }, col.key)))] }, key));
2182
- }) }) }), pagination && jsx(GridPaginationFooter, { pagination: pagination, onPageChange: onPageChange })] }));
2201
+ }) }) }), pagination && jsx(GridPaginationFooter, { pagination: pagination, onPageChange: onPageChange }), contextMenuElement] }));
2183
2202
  }
2184
2203
 
2185
2204
  /**