Skip to content

Commit eddcee4

Browse files
Copilothuangyiirene
andcommitted
Fix TypeScript error in CanvasDesigner ResizeHandles usage
Co-authored-by: huangyiirene <[email protected]>
1 parent d45eaf6 commit eddcee4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

packages/designer/src/components/CanvasDesigner.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useKeyboardShortcuts } from '../hooks/useKeyboardShortcuts';
1818
import type { SchemaNode } from '@object-ui/core';
1919
import type { CanvasDesignerConfig } from '../types/designer-modes';
2020
import { SchemaRenderer } from '@object-ui/react';
21-
import { ResizeHandles } from './ResizeHandle';
21+
import { ResizeHandles, type ResizeDirection } from './ResizeHandle';
2222
import { ComponentRegistry } from '@object-ui/core';
2323
import { cn } from '@object-ui/components';
2424

@@ -158,7 +158,22 @@ const FreeFormCanvas: React.FC<{ showGrid?: boolean; gridSize?: number }> = ({
158158

159159
return nodes.map((node) => {
160160
const isSelected = node.id === selectedNodeId;
161-
const isResizable = ComponentRegistry.getConfig(node.type)?.resizable || false;
161+
const config = ComponentRegistry.getConfig(node.type);
162+
const isResizable = config?.resizable || false;
163+
164+
// Determine which directions to show based on constraints
165+
const constraints = config?.resizeConstraints || {};
166+
const directions: ResizeDirection[] = [];
167+
168+
if (constraints.width !== false) {
169+
directions.push('e', 'w');
170+
}
171+
if (constraints.height !== false) {
172+
directions.push('n', 's');
173+
}
174+
if (constraints.width !== false && constraints.height !== false) {
175+
directions.push('ne', 'nw', 'se', 'sw');
176+
}
162177

163178
return (
164179
<div
@@ -186,8 +201,8 @@ const FreeFormCanvas: React.FC<{ showGrid?: boolean; gridSize?: number }> = ({
186201
{/* Resize handles for selected node */}
187202
{isSelected && isResizable && (
188203
<ResizeHandles
189-
nodeId={node.id || ''}
190-
onResizeStart={(direction) => {
204+
directions={directions}
205+
onResizeStart={(direction, e) => {
191206
const element = document.querySelector(`[data-obj-id="${node.id}"]`) as HTMLElement;
192207
if (element) {
193208
setResizingNode({

0 commit comments

Comments
 (0)