Skip to content

Commit c916284

Browse files
committed
refactor(core): allow using expandParent with parent extent
1 parent 92649ef commit c916284

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/core/src/types/changes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface NodeDragItem {
1212
from: XYPosition
1313
extent?: Node['extent']
1414
parentNode?: string
15+
expandParent?: boolean
1516
}
1617

1718
export interface NodeDimensionChange {

packages/core/src/utils/drag.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function getDragItems(
5353
extent: n.extent,
5454
parentNode: n.parentNode,
5555
dimensions: n.dimensions,
56+
expandParent: n.expandParent,
5657
}),
5758
)
5859
}
@@ -132,7 +133,10 @@ export function getExtent<T extends NodeDragItem | GraphNode>(
132133
) {
133134
let currentExtent = item.extent || extent
134135

135-
if (currentExtent === 'parent' || (!Array.isArray(currentExtent) && currentExtent?.range === 'parent')) {
136+
if (
137+
(currentExtent === 'parent' || (!Array.isArray(currentExtent) && currentExtent?.range === 'parent')) &&
138+
!item.expandParent
139+
) {
136140
if (item.parentNode && parent && item.dimensions.width && item.dimensions.height) {
137141
const parentExtent = getParentExtent(currentExtent, item, parent)
138142

@@ -152,7 +156,7 @@ export function getExtent<T extends NodeDragItem | GraphNode>(
152156
[currentExtent[0][0] + parentX, currentExtent[0][1] + parentY],
153157
[currentExtent[1][0] + parentX, currentExtent[1][1] + parentY],
154158
]
155-
} else if (currentExtent?.range && Array.isArray(currentExtent.range)) {
159+
} else if (currentExtent !== 'parent' && currentExtent?.range && Array.isArray(currentExtent.range)) {
156160
const [top, right, bottom, left] = getExtentPadding(currentExtent.padding)
157161

158162
const parentX = parent?.computedPosition.x || 0
@@ -164,7 +168,14 @@ export function getExtent<T extends NodeDragItem | GraphNode>(
164168
]
165169
}
166170

167-
return currentExtent as CoordinateExtent
171+
return (
172+
currentExtent === 'parent'
173+
? [
174+
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
175+
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
176+
]
177+
: currentExtent
178+
) as CoordinateExtent
168179
}
169180

170181
function clampNodeExtent({ width, height }: Dimensions, extent: CoordinateExtent): CoordinateExtent {

0 commit comments

Comments
 (0)