@ruiapp/designer-hud
Advanced tools
@@ -127,2 +127,3 @@ 'use strict'; | ||
const styleIfActive = isActive ? styleActiveItem : {}; | ||
let shiftPressed = false; | ||
const onMouseMove = react.useCallback((event) => { | ||
@@ -193,2 +194,5 @@ if (!dragStartState) { | ||
}, | ||
drag: { | ||
key: "Shift", | ||
}, | ||
}; | ||
@@ -256,3 +260,12 @@ if (event.type !== "keydown") | ||
} | ||
// drag | ||
if (event.key === eventType.drag.key) { | ||
shiftPressed = true; | ||
} | ||
}; | ||
const onKeyUp = (event) => { | ||
if (event.key === "Shift") { | ||
shiftPressed = false; | ||
} | ||
}; | ||
const onResizeHandlerDragStart = react.useCallback((event) => { }, []); | ||
@@ -263,5 +276,5 @@ const onTopLeftHandlerDragging = react.useCallback((event) => { | ||
left: left + event.deltaX, | ||
top: top + event.deltaY, | ||
top: shiftPressed ? top - ((width - event.deltaX) / width - 1) * height : top + event.deltaY, | ||
width: Math.max(width - event.deltaX, 0), | ||
height: Math.max(height - event.deltaY, 0), | ||
height: Math.max(shiftPressed ? ((width - event.deltaX) / width) * height : height - event.deltaY, 0), | ||
}); | ||
@@ -273,5 +286,5 @@ }, [onWidgetRectChange, widgetId, left, top, width, height]); | ||
left: left, | ||
top: top + event.deltaY, | ||
top: shiftPressed ? top - ((width + event.deltaX) / width - 1) * height : top + event.deltaY, | ||
width: Math.max(width + event.deltaX, 0), | ||
height: Math.max(height - event.deltaY, 0), | ||
height: Math.max(shiftPressed ? ((width + event.deltaX) / width) * height : height - event.deltaY, 0), | ||
}); | ||
@@ -285,3 +298,3 @@ }, [onWidgetRectChange, widgetId, left, top, width, height]); | ||
width: Math.max(width + event.deltaX, 0), | ||
height: Math.max(height + event.deltaY, 0), | ||
height: Math.max(shiftPressed ? ((width + event.deltaX) / width) * height : height + event.deltaY, 0), | ||
}); | ||
@@ -295,3 +308,3 @@ }, [onWidgetRectChange, widgetId, left, top, width, height]); | ||
width: Math.max(width - event.deltaX, 0), | ||
height: Math.max(height + event.deltaY, 0), | ||
height: Math.max(shiftPressed ? ((width - event.deltaX) / width) * height : height + event.deltaY, 0), | ||
}); | ||
@@ -304,3 +317,3 @@ }, [onWidgetRectChange, widgetId, left, top, width, height]); | ||
top: top + event.deltaY, | ||
width: Math.max(width, 0), | ||
width: Math.max(shiftPressed ? ((height - event.deltaY) * width) / height : width, 0), | ||
height: Math.max(height - event.deltaY, 0), | ||
@@ -315,3 +328,3 @@ }); | ||
width: Math.max(width + event.deltaX, 0), | ||
height: Math.max(height, 0), | ||
height: Math.max(shiftPressed ? ((width + event.deltaX) * height) / width : height, 0), | ||
}); | ||
@@ -324,3 +337,3 @@ }, [onWidgetRectChange, widgetId, left, top, width, height]); | ||
top: top, | ||
width: Math.max(width, 0), | ||
width: Math.max(shiftPressed ? ((height + event.deltaY) * width) / height : width, 0), | ||
height: Math.max(height + event.deltaY, 0), | ||
@@ -335,3 +348,3 @@ }); | ||
width: Math.max(width - event.deltaX, 0), | ||
height: Math.max(height, 0), | ||
height: Math.max(shiftPressed ? ((width - event.deltaX) * height) / width : height, 0), | ||
}); | ||
@@ -349,3 +362,3 @@ }, [onWidgetRectChange, widgetId, left, top, width, height]); | ||
zIndex: isActive ? 100 : 1, | ||
}, onMouseDown: onMouseDown, onKeyDown: onKeyDown, children: isActive && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "topLeft", left: -4, top: -4, onDragStart: onResizeHandlerDragStart, onDragging: onTopLeftHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "topRight", left: width - 5, top: -4, onDragStart: onResizeHandlerDragStart, onDragging: onTopRightHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "bottomRight", left: width - 5, top: height - 5, onDragStart: onResizeHandlerDragStart, onDragging: onBottomRightHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "bottomLeft", left: -4, top: height - 5, onDragStart: onResizeHandlerDragStart, onDragging: onBottomLeftHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "top", left: width / 2 - 3, top: -4, onDragStart: onResizeHandlerDragStart, onDragging: onTopHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "right", top: height / 2 - 3, left: width - 5, onDragStart: onResizeHandlerDragStart, onDragging: onRightHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "bottom", left: width / 2 - 3, top: height - 5, onDragStart: onResizeHandlerDragStart, onDragging: onBottomHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "left", top: height / 2 - 3, left: -4, onDragStart: onResizeHandlerDragStart, onDragging: onLeftHandlerDragging })] })) })); | ||
}, onMouseDown: onMouseDown, onKeyDown: onKeyDown, onKeyUp: onKeyUp, children: isActive && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "topLeft", left: -4, top: -4, onDragStart: onResizeHandlerDragStart, onDragging: onTopLeftHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "topRight", left: width - 5, top: -4, onDragStart: onResizeHandlerDragStart, onDragging: onTopRightHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "bottomRight", left: width - 5, top: height - 5, onDragStart: onResizeHandlerDragStart, onDragging: onBottomRightHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "bottomLeft", left: -4, top: height - 5, onDragStart: onResizeHandlerDragStart, onDragging: onBottomLeftHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "top", left: width / 2 - 3, top: -4, onDragStart: onResizeHandlerDragStart, onDragging: onTopHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "right", top: height / 2 - 3, left: width - 5, onDragStart: onResizeHandlerDragStart, onDragging: onRightHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "bottom", left: width / 2 - 3, top: height - 5, onDragStart: onResizeHandlerDragStart, onDragging: onBottomHandlerDragging }), jsxRuntime.jsx(DesignerHudWidgetResizeHandler, { type: "left", top: height / 2 - 3, left: -4, onDragStart: onResizeHandlerDragStart, onDragging: onLeftHandlerDragging })] })) })); | ||
} | ||
@@ -352,0 +365,0 @@ const primaryColor = `#C038FF`; |
{ | ||
"name": "@ruiapp/designer-hud", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "dist/mod.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/mod.d.ts", |
26219
3.77%623
2.13%