fix(node-resizer): wait for node to be initialised before enforcing min/max size
This commit is contained in:
@@ -27,41 +27,43 @@ const contextNodeId = inject(NodeIdInjection, null)
|
|||||||
|
|
||||||
const id = computed(() => (typeof props.nodeId === 'string' ? props.nodeId : contextNodeId))
|
const id = computed(() => (typeof props.nodeId === 'string' ? props.nodeId : contextNodeId))
|
||||||
|
|
||||||
watch(
|
const node = computed(() => findNode(id.value))
|
||||||
[() => props.minWidth, () => props.minHeight, () => props.maxWidth, () => props.maxHeight],
|
|
||||||
([minWidth, minHeight, maxWidth, maxHeight]) => {
|
|
||||||
const node = findNode(id.value)
|
|
||||||
|
|
||||||
if (node) {
|
watch(
|
||||||
|
[() => props.minWidth, () => props.minHeight, () => props.maxWidth, () => props.maxHeight, () => node.value?.initialized],
|
||||||
|
([minWidth, minHeight, maxWidth, maxHeight, isInitialized]) => {
|
||||||
|
const n = node.value
|
||||||
|
|
||||||
|
if (n && isInitialized) {
|
||||||
const dimensionChange: NodeDimensionChange = {
|
const dimensionChange: NodeDimensionChange = {
|
||||||
id: node.id,
|
id: n.id,
|
||||||
type: 'dimensions',
|
type: 'dimensions',
|
||||||
updateStyle: true,
|
updateStyle: true,
|
||||||
dimensions: {
|
dimensions: {
|
||||||
width: node.dimensions.width,
|
width: n.dimensions.width,
|
||||||
height: node.dimensions.height,
|
height: n.dimensions.height,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minWidth && node.dimensions.width < minWidth) {
|
if (minWidth && n.dimensions.width < minWidth) {
|
||||||
dimensionChange.dimensions!.width = minWidth
|
dimensionChange.dimensions!.width = minWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minHeight && node.dimensions.height < minHeight) {
|
if (minHeight && n.dimensions.height < minHeight) {
|
||||||
dimensionChange.dimensions!.height = minHeight
|
dimensionChange.dimensions!.height = minHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxWidth && node.dimensions.width > maxWidth) {
|
if (maxWidth && n.dimensions.width > maxWidth) {
|
||||||
dimensionChange.dimensions!.width = maxWidth
|
dimensionChange.dimensions!.width = maxWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxHeight && node.dimensions.height > maxHeight) {
|
if (maxHeight && n.dimensions.height > maxHeight) {
|
||||||
dimensionChange.dimensions!.height = maxHeight
|
dimensionChange.dimensions!.height = maxHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
dimensionChange.dimensions!.width !== node.dimensions.width ||
|
dimensionChange.dimensions!.width !== n.dimensions.width ||
|
||||||
dimensionChange.dimensions!.height !== node.dimensions.height
|
dimensionChange.dimensions!.height !== n.dimensions.height
|
||||||
) {
|
) {
|
||||||
triggerEmits.nodesChange([dimensionChange])
|
triggerEmits.nodesChange([dimensionChange])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user