@gridsuite/commons-ui 0.232.0 → 0.233.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.
@@ -10,6 +10,15 @@ import { hasNonEmptyRows } from "../../../utils/functions.js";
10
10
  import "@mui/icons-material";
11
11
  import { CustomAGGrid } from "../customAGGrid/customAggrid.js";
12
12
  import "react-intl";
13
+ const getDropIndicatorPosition = ({ overNode, y }) => {
14
+ if (!overNode) {
15
+ return null;
16
+ }
17
+ const overNodeTop = overNode.rowTop ?? 0;
18
+ const overNodeHeight = overNode.rowHeight ?? 0;
19
+ const overNodeMiddle = overNodeTop + overNodeHeight / 2;
20
+ return y < overNodeMiddle ? "above" : "below";
21
+ };
13
22
  const style = (customProps) => ({
14
23
  grid: (theme) => ({
15
24
  height: "100%",
@@ -137,6 +146,42 @@ const CustomAgGridTable = forwardRef(
137
146
  const isAnycolumnhasSort = event.api.getColumnState().some((col) => col.sort);
138
147
  setIsSortApplied(isAnycolumnhasSort);
139
148
  }, []);
149
+ const onRowDragMove = useCallback((event) => {
150
+ const { api, overNode } = event;
151
+ const dropIndicatorPosition = getDropIndicatorPosition(event);
152
+ if (!overNode || !dropIndicatorPosition) {
153
+ api.setRowDropPositionIndicator(null);
154
+ return;
155
+ }
156
+ api.setRowDropPositionIndicator({
157
+ row: overNode,
158
+ dropIndicatorPosition
159
+ });
160
+ }, []);
161
+ const onRowDragEnd = useCallback(
162
+ (event) => {
163
+ const { api, node, overNode } = event;
164
+ api.setRowDropPositionIndicator(null);
165
+ const dropIndicatorPosition = getDropIndicatorPosition(event);
166
+ if (!overNode || !dropIndicatorPosition) {
167
+ return;
168
+ }
169
+ const rowIndex = getIndex(node.data);
170
+ const overIndex = getIndex(overNode.data);
171
+ if (rowIndex === -1 || overIndex === -1 || rowIndex === overIndex) {
172
+ return;
173
+ }
174
+ const insertionIndex = dropIndicatorPosition === "above" ? overIndex : overIndex + 1;
175
+ const targetIndex = rowIndex < insertionIndex ? insertionIndex - 1 : insertionIndex;
176
+ if (rowIndex !== targetIndex) {
177
+ move(rowIndex, targetIndex);
178
+ }
179
+ },
180
+ [getIndex, move]
181
+ );
182
+ const clearRowDropPositionIndicator = useCallback(({ api }) => {
183
+ api.setRowDropPositionIndicator(null);
184
+ }, []);
140
185
  return /* @__PURE__ */ jsxs(Fragment, { children: [
141
186
  /* @__PURE__ */ jsx(Box, { className: theme.aggrid.theme, sx: style(cssProps).grid, children: /* @__PURE__ */ jsx(
142
187
  CustomAGGrid,
@@ -146,7 +191,10 @@ const CustomAgGridTable = forwardRef(
146
191
  cacheOverflowSize: 10,
147
192
  rowSelection: rowSelection ?? { mode: "multiRow" },
148
193
  selectionColumnDef: { rowDrag: true, width: 80, pinned: "left" },
149
- onRowDragMove: (event) => move(getIndex(event.node.data), event.overIndex),
194
+ onRowDragMove,
195
+ onRowDragEnd,
196
+ onRowDragLeave: clearRowDropPositionIndicator,
197
+ onRowDragCancel: clearRowDropPositionIndicator,
150
198
  detailRowAutoHeight: true,
151
199
  onSelectionChanged: (event) => {
152
200
  setSelectedRows(event.api.getSelectedRows());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.232.0",
3
+ "version": "0.233.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",