* Sort an array of grid nodes by position (y first, then x). * * @param nodes array of nodes to sort * @param dir sort direction: 1 for ascending (top-left first), -1 for descending * @returns the sorted array (modifies original) * * @example * const sorted = Utils.sort(nodes);
(nodes: GridStackNode[], dir: 1 | -1 = 1)
| 310 | * const reverse = Utils.sort(nodes, -1); // Sort bottom-right to top-left |
| 311 | */ |
| 312 | static sort(nodes: GridStackNode[], dir: 1 | -1 = 1): GridStackNode[] { |
| 313 | const und = 10000; |
| 314 | return nodes.sort((a, b) => { |
| 315 | const diffY = dir * ((a.y ?? und) - (b.y ?? und)); |
| 316 | if (diffY === 0) return dir * ((a.x ?? und) - (b.x ?? und)); |
| 317 | return diffY; |
| 318 | }); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Find a grid node by its ID. |
no outgoing calls
no test coverage detected