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