@linzjs/step-ag-grid 31.1.1 → 31.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.
- package/dist/GridTheme.scss +4 -0
- package/dist/src/components/gridDragUtil.d.ts +10 -0
- package/dist/src/components/gridDragUtil.test.d.ts +1 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/types.d.ts +4 -0
- package/dist/step-ag-grid.cjs +92 -4
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +92 -5
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +69 -5
- package/src/components/gridDragUtil.test.ts +115 -0
- package/src/components/gridDragUtil.ts +32 -0
- package/src/components/index.ts +1 -0
- package/src/components/types.ts +4 -0
- package/src/stories/grid/GridDragRow.stories.tsx +61 -8
- package/src/styles/GridTheme.scss +4 -0
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -61746,10 +61746,36 @@ maxInitialWidth,
|
|
|
61746
61746
|
el.classList.remove('ag-row-highlight-below');
|
|
61747
61747
|
});
|
|
61748
61748
|
}, []);
|
|
61749
|
+
const clearDragRowClasses = useCallback(() => {
|
|
61750
|
+
document.querySelectorAll(`.ag-row-dragging`)?.forEach((el) => {
|
|
61751
|
+
el.classList.remove('ag-row-dragging');
|
|
61752
|
+
});
|
|
61753
|
+
}, []);
|
|
61749
61754
|
const gridElementRef = useRef(undefined);
|
|
61755
|
+
const multiDragAppliedRef = useRef(false);
|
|
61756
|
+
const multiDragCountRef = useRef(0);
|
|
61750
61757
|
const onRowDragMove = useCallback((event) => {
|
|
61751
61758
|
if (startDragYRef.current === null) {
|
|
61752
61759
|
startDragYRef.current = event.y;
|
|
61760
|
+
// On first move event, apply ag-row-dragging class to all selected rows for multi-drag
|
|
61761
|
+
if (rowSelection === 'multiple' && event.node.isSelected()) {
|
|
61762
|
+
const selectedNodes = event.api.getSelectedNodes().filter((n) => n.displayed && n.data != null);
|
|
61763
|
+
if (selectedNodes.length > 1) {
|
|
61764
|
+
multiDragAppliedRef.current = true;
|
|
61765
|
+
multiDragCountRef.current = selectedNodes.length;
|
|
61766
|
+
// Find the grid body element for scoped queries
|
|
61767
|
+
const targetEl = event.event.target;
|
|
61768
|
+
const gridElement = targetEl?.closest('.ag-body');
|
|
61769
|
+
if (gridElement) {
|
|
61770
|
+
gridElementRef.current = gridElement;
|
|
61771
|
+
for (const node of selectedNodes) {
|
|
61772
|
+
gridElement.querySelectorAll(`[row-id='${node.data.id}']`)?.forEach((el) => {
|
|
61773
|
+
el.classList.add('ag-row-dragging');
|
|
61774
|
+
});
|
|
61775
|
+
}
|
|
61776
|
+
}
|
|
61777
|
+
}
|
|
61778
|
+
}
|
|
61753
61779
|
}
|
|
61754
61780
|
const yDiff = event.y - startDragYRef.current;
|
|
61755
61781
|
const data = event.overNode?.data;
|
|
@@ -61768,7 +61794,7 @@ maxInitialWidth,
|
|
|
61768
61794
|
el.classList.add(yDiff < 0 ? 'ag-row-highlight-above' : 'ag-row-highlight-below');
|
|
61769
61795
|
});
|
|
61770
61796
|
}
|
|
61771
|
-
}, [clearHighlightRowClasses]);
|
|
61797
|
+
}, [clearHighlightRowClasses, rowSelection]);
|
|
61772
61798
|
const onCellFocused = useCallback((event) => {
|
|
61773
61799
|
if (event.rowIndex == null) {
|
|
61774
61800
|
return;
|
|
@@ -61797,6 +61823,9 @@ maxInitialWidth,
|
|
|
61797
61823
|
}, [paramsOnCellFocused]);
|
|
61798
61824
|
const onRowDragEnd = useCallback((event) => {
|
|
61799
61825
|
clearHighlightRowClasses();
|
|
61826
|
+
clearDragRowClasses();
|
|
61827
|
+
multiDragAppliedRef.current = false;
|
|
61828
|
+
multiDragCountRef.current = 0;
|
|
61800
61829
|
gridElementRef.current = undefined;
|
|
61801
61830
|
if (!params.onRowDragEnd || startDragYRef.current === null) {
|
|
61802
61831
|
return;
|
|
@@ -61809,9 +61838,26 @@ maxInitialWidth,
|
|
|
61809
61838
|
if (!movedRow || !targetRow || movedRow === targetRow || yDiff === 0) {
|
|
61810
61839
|
return;
|
|
61811
61840
|
}
|
|
61812
|
-
|
|
61841
|
+
// Determine movedRows: if dragged row is part of a multi-selection, include all selected & displayed rows
|
|
61842
|
+
let movedRows;
|
|
61843
|
+
if (rowSelection === 'multiple' && event.node.isSelected()) {
|
|
61844
|
+
movedRows = event.api
|
|
61845
|
+
.getSelectedNodes()
|
|
61846
|
+
.filter((n) => n.displayed && n.data != null)
|
|
61847
|
+
.sort((a, b) => (a.rowIndex ?? 0) - (b.rowIndex ?? 0))
|
|
61848
|
+
.map((n) => n.data);
|
|
61849
|
+
}
|
|
61850
|
+
else {
|
|
61851
|
+
movedRows = [movedRow];
|
|
61852
|
+
}
|
|
61853
|
+
// If targetRow is one of the moved rows, no-op
|
|
61854
|
+
if (movedRows.some((r) => r.id === targetRow.id)) {
|
|
61855
|
+
return;
|
|
61856
|
+
}
|
|
61857
|
+
const direction = yDiff > 0 ? 1 : -1;
|
|
61858
|
+
void params.onRowDragEnd({ movedRow, movedRows, targetRow, direction });
|
|
61813
61859
|
}
|
|
61814
|
-
}, [params, clearHighlightRowClasses]);
|
|
61860
|
+
}, [params, clearHighlightRowClasses, clearDragRowClasses, rowSelection]);
|
|
61815
61861
|
useEffect(() => {
|
|
61816
61862
|
if ((setExternalSelectedItems || setExternalSelectedIds) && selectable == null) {
|
|
61817
61863
|
console.warn('<Grid/> has setExternalSelectedItems/setExternalSelectedIds parameter, but is missing selectable parameter,' +
|
|
@@ -61881,7 +61927,20 @@ maxInitialWidth,
|
|
|
61881
61927
|
event.api.sizeColumnsToFit();
|
|
61882
61928
|
}
|
|
61883
61929
|
}, [sizeColumns]);
|
|
61884
|
-
return (jsxs("div", { "data-testid": dataTestId, className: clsx('Grid-container', theme, 'theme-specific', staleGrid && 'Grid-sortIsStale', gridReady && rowData && autoSized && 'Grid-ready', params.hideSelectedRow && 'Grid-hideSelectedRow'), children: [contextMenuComponent, rangeSelectContextMenuComponent, jsx("div", { style: { flex: 1 }, ref: gridDivRef, onCopy: onCopyEvent, children: jsx(AgGridReact, { theme: 'legacy', domLayout: params.domLayout, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, getRowId: getRowId, rowData: rowData, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, animateRows: params.animateRows ?? false, doesExternalFilterPass: doesExternalFilterPass, isExternalFilterPresent: isExternalFilterPresent, maintainColumnOrder: true, noRowsOverlayComponent: noRowsOverlayComponent, onCellClicked: onCellClicked, onCellContextMenu: rangeSelectInterceptContextMenu, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellMouseDown: onCellMouseDown, onCellMouseOver: onCellMouseOver, onColumnMoved: columnMoved, onColumnResized: onColumnResized, onColumnVisible: () => void setInitialContentSize(), onGridReady: onGridReady, onGridSizeChanged: onGridSizeChanged, onModelUpdated: onModelUpdated, onRowClicked: params.onRowClicked, onRowDataUpdated: onRowDataUpdated, onRowDoubleClicked: params.onRowDoubleClicked, onRowDragCancel:
|
|
61930
|
+
return (jsxs("div", { "data-testid": dataTestId, className: clsx('Grid-container', theme, 'theme-specific', staleGrid && 'Grid-sortIsStale', gridReady && rowData && autoSized && 'Grid-ready', params.hideSelectedRow && 'Grid-hideSelectedRow'), children: [contextMenuComponent, rangeSelectContextMenuComponent, jsx("div", { style: { flex: 1 }, ref: gridDivRef, onCopy: onCopyEvent, children: jsx(AgGridReact, { theme: 'legacy', domLayout: params.domLayout, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, getRowId: getRowId, rowData: rowData, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, animateRows: params.animateRows ?? false, doesExternalFilterPass: doesExternalFilterPass, isExternalFilterPresent: isExternalFilterPresent, maintainColumnOrder: true, noRowsOverlayComponent: noRowsOverlayComponent, onCellClicked: onCellClicked, onCellContextMenu: rangeSelectInterceptContextMenu, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellMouseDown: onCellMouseDown, onCellMouseOver: onCellMouseOver, onColumnMoved: columnMoved, onColumnResized: onColumnResized, onColumnVisible: () => void setInitialContentSize(), onGridReady: onGridReady, onGridSizeChanged: onGridSizeChanged, onModelUpdated: onModelUpdated, onRowClicked: params.onRowClicked, onRowDataUpdated: onRowDataUpdated, onRowDoubleClicked: params.onRowDoubleClicked, onRowDragCancel: () => {
|
|
61931
|
+
clearHighlightRowClasses();
|
|
61932
|
+
clearDragRowClasses();
|
|
61933
|
+
multiDragAppliedRef.current = false;
|
|
61934
|
+
multiDragCountRef.current = 0;
|
|
61935
|
+
}, onRowDragEnd: onRowDragEnd, onRowDragMove: onRowDragMove, onSelectionChanged: synchroniseExternalStateToGridSelection, onSortChanged: onSortChanged, pinnedBottomRowData: params.pinnedBottomRowData, pinnedTopRowData: params.pinnedTopRowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, preventDefaultOnContextMenu: true, quickFilterParser: quickFilterParser, rowClassRules: params.rowClassRules, rowDragText: params.rowDragText ??
|
|
61936
|
+
(rowSelection === 'multiple'
|
|
61937
|
+
? (dragItem) => {
|
|
61938
|
+
const count = multiDragCountRef.current;
|
|
61939
|
+
if (count > 1)
|
|
61940
|
+
return `Moving ${count} rows`;
|
|
61941
|
+
return `${dragItem.rowNode?.data?.id ?? ''}`;
|
|
61942
|
+
}
|
|
61943
|
+
: undefined), rowHeight: rowHeight, rowSelection: selectable
|
|
61885
61944
|
? {
|
|
61886
61945
|
enableSelectionWithoutKeys: params.enableSelectionWithoutKeys ?? false,
|
|
61887
61946
|
enableClickSelection: params.enableClickSelection ?? false,
|
|
@@ -62113,6 +62172,34 @@ const GridCellMultiEditor = (props, cellEditorSelector) => GridCell({
|
|
|
62113
62172
|
...props,
|
|
62114
62173
|
});
|
|
62115
62174
|
|
|
62175
|
+
/**
|
|
62176
|
+
* Reorders rows by removing movedRows from the array and inserting them at the target position.
|
|
62177
|
+
* @param rows - The current row array.
|
|
62178
|
+
* @param movedRows - Rows to move, in desired insertion order (typically display order).
|
|
62179
|
+
* @param targetRow - The row to insert relative to.
|
|
62180
|
+
* @param direction - -1 inserts above targetRow, 1 inserts below targetRow.
|
|
62181
|
+
* @returns A new array with the rows reordered, or the original array if the operation is a no-op.
|
|
62182
|
+
*/
|
|
62183
|
+
function reorderRows(rows, movedRows, targetRow, direction) {
|
|
62184
|
+
if (movedRows.length === 0)
|
|
62185
|
+
return rows;
|
|
62186
|
+
const movedIds = new Set(movedRows.map((r) => r.id));
|
|
62187
|
+
// If targetRow is one of the moved rows, no-op
|
|
62188
|
+
if (movedIds.has(targetRow.id))
|
|
62189
|
+
return rows;
|
|
62190
|
+
// Remove moved rows from the array
|
|
62191
|
+
const remaining = rows.filter((r) => !movedIds.has(r.id));
|
|
62192
|
+
// Find where to insert relative to the target
|
|
62193
|
+
const targetIndex = remaining.findIndex((r) => r.id === targetRow.id);
|
|
62194
|
+
if (targetIndex === -1)
|
|
62195
|
+
return rows;
|
|
62196
|
+
const insertIndex = direction === 1 ? targetIndex + 1 : targetIndex;
|
|
62197
|
+
// Insert movedRows at the calculated position
|
|
62198
|
+
const result = [...remaining];
|
|
62199
|
+
result.splice(insertIndex, 0, ...movedRows);
|
|
62200
|
+
return result;
|
|
62201
|
+
}
|
|
62202
|
+
|
|
62116
62203
|
const useGridFilter = (filter) => {
|
|
62117
62204
|
const { addExternalFilter, removeExternalFilter } = useGridContext();
|
|
62118
62205
|
useEffect(() => {
|
|
@@ -64854,5 +64941,5 @@ const useDeferredPromise = () => {
|
|
|
64854
64941
|
};
|
|
64855
64942
|
};
|
|
64856
64943
|
|
|
64857
|
-
export { ActionButton, CancelPromise, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellBearingValueFormatter, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormInlineTextInput, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridInlineTextInput, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, agGridSelectRowColId, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, colStateFlexed, colStateId, colStateNotFlexed, compareNaturalInsensitive, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
|
|
64944
|
+
export { ActionButton, CancelPromise, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellBearingValueFormatter, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormInlineTextInput, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridInlineTextInput, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, agGridSelectRowColId, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, colStateFlexed, colStateId, colStateNotFlexed, compareNaturalInsensitive, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, reorderRows, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
|
|
64858
64945
|
//# sourceMappingURL=step-ag-grid.esm.js.map
|