Skip to content

Commit 54b813c

Browse files
fix(ui): fix mouse interactions (#3764)
2 parents 5aade31 + c4a6f25 commit 54b813c

File tree

8 files changed

+72
-20
lines changed

8 files changed

+72
-20
lines changed

invokeai/frontend/web/src/common/components/IAINumberInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
useState,
2929
} from 'react';
3030

31-
const numberStringRegex = /^-?(0\.)?\.?$/;
31+
export const numberStringRegex = /^-?(0\.)?\.?$/;
3232

3333
interface Props extends Omit<NumberInputProps, 'onChange'> {
3434
label?: string;

invokeai/frontend/web/src/features/nodes/components/IAINode/IAINodeHeader.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Flex, Heading, Icon, Tooltip } from '@chakra-ui/react';
2+
import { DRAG_HANDLE_CLASSNAME } from 'features/nodes/hooks/useBuildInvocation';
23
import { memo } from 'react';
34
import { FaInfoCircle } from 'react-icons/fa';
45

@@ -12,6 +13,7 @@ const IAINodeHeader = (props: IAINodeHeaderProps) => {
1213
const { nodeId, title, description } = props;
1314
return (
1415
<Flex
16+
className={DRAG_HANDLE_CLASSNAME}
1517
sx={{
1618
borderTopRadius: 'md',
1719
alignItems: 'center',

invokeai/frontend/web/src/features/nodes/components/IAINode/IAINodeInputs.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import {
2-
InputFieldTemplate,
3-
InputFieldValue,
4-
InvocationTemplate,
5-
} from 'features/nodes/types/types';
6-
import { memo, ReactNode, useCallback } from 'react';
7-
import { map } from 'lodash-es';
8-
import { useAppSelector } from 'app/store/storeHooks';
9-
import { RootState } from 'app/store/store';
101
import {
112
Box,
3+
Divider,
124
Flex,
135
FormControl,
146
FormLabel,
157
HStack,
168
Tooltip,
17-
Divider,
189
} from '@chakra-ui/react';
19-
import FieldHandle from '../FieldHandle';
10+
import { RootState } from 'app/store/store';
11+
import { useAppSelector } from 'app/store/storeHooks';
2012
import { useIsValidConnection } from 'features/nodes/hooks/useIsValidConnection';
21-
import InputFieldComponent from '../InputFieldComponent';
2213
import { HANDLE_TOOLTIP_OPEN_DELAY } from 'features/nodes/types/constants';
14+
import {
15+
InputFieldTemplate,
16+
InputFieldValue,
17+
InvocationTemplate,
18+
} from 'features/nodes/types/types';
19+
import { map } from 'lodash-es';
20+
import { ReactNode, memo, useCallback } from 'react';
21+
import FieldHandle from '../FieldHandle';
22+
import InputFieldComponent from '../InputFieldComponent';
2323

2424
interface IAINodeInputProps {
2525
nodeId: string;
@@ -35,6 +35,7 @@ function IAINodeInput(props: IAINodeInputProps) {
3535

3636
return (
3737
<Box
38+
className="nopan"
3839
position="relative"
3940
borderColor={
4041
!template
@@ -136,7 +137,7 @@ const IAINodeInputs = (props: IAINodeInputsProps) => {
136137
});
137138

138139
return (
139-
<Flex flexDir="column" gap={2} p={2}>
140+
<Flex className="nopan" flexDir="column" gap={2} p={2}>
140141
{IAINodeInputsToRender}
141142
</Flex>
142143
);

invokeai/frontend/web/src/features/nodes/components/InvocationComponent.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ export const InvocationComponent = memo((props: NodeProps<InvocationValue>) => {
2323
if (!template) {
2424
return (
2525
<NodeWrapper selected={selected}>
26-
<Flex sx={{ alignItems: 'center', justifyContent: 'center' }}>
26+
<Flex
27+
className="nopan"
28+
sx={{
29+
alignItems: 'center',
30+
justifyContent: 'center',
31+
cursor: 'auto',
32+
}}
33+
>
2734
<Icon
2835
as={FaExclamationCircle}
2936
sx={{
@@ -46,7 +53,9 @@ export const InvocationComponent = memo((props: NodeProps<InvocationValue>) => {
4653
description={template.description}
4754
/>
4855
<Flex
56+
className={'nopan'}
4957
sx={{
58+
cursor: 'auto',
5059
flexDirection: 'column',
5160
borderBottomRadius: 'md',
5261
py: 2,

invokeai/frontend/web/src/features/nodes/components/NodeWrapper.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Box, useToken } from '@chakra-ui/react';
22
import { NODE_MIN_WIDTH } from 'app/constants';
33

44
import { PropsWithChildren } from 'react';
5+
import { DRAG_HANDLE_CLASSNAME } from '../hooks/useBuildInvocation';
6+
import { useAppSelector } from 'app/store/storeHooks';
57

68
type NodeWrapperProps = PropsWithChildren & {
79
selected: boolean;
@@ -13,8 +15,11 @@ const NodeWrapper = (props: NodeWrapperProps) => {
1315
'dark-lg',
1416
]);
1517

18+
const shift = useAppSelector((state) => state.hotkeys.shift);
19+
1620
return (
1721
<Box
22+
className={shift ? DRAG_HANDLE_CLASSNAME : 'nopan'}
1823
sx={{
1924
position: 'relative',
2025
borderRadius: 'md',

invokeai/frontend/web/src/features/nodes/components/ProgressImageNode.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const ProgressImageNode = (props: NodeProps<InvocationValue>) => {
2121
/>
2222

2323
<Flex
24+
className="nopan"
2425
sx={{
2526
flexDirection: 'column',
2627
borderBottomRadius: 'md',

invokeai/frontend/web/src/features/nodes/components/fields/NumberInputFieldComponent.tsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import {
66
NumberInputStepper,
77
} from '@chakra-ui/react';
88
import { useAppDispatch } from 'app/store/storeHooks';
9+
import { numberStringRegex } from 'common/components/IAINumberInput';
910
import { fieldValueChanged } from 'features/nodes/store/nodesSlice';
1011
import {
1112
FloatInputFieldTemplate,
1213
FloatInputFieldValue,
1314
IntegerInputFieldTemplate,
1415
IntegerInputFieldValue,
1516
} from 'features/nodes/types/types';
16-
import { memo } from 'react';
17+
import { memo, useEffect, useState } from 'react';
1718
import { FieldComponentProps } from './types';
1819

1920
const NumberInputFieldComponent = (
@@ -23,17 +24,42 @@ const NumberInputFieldComponent = (
2324
>
2425
) => {
2526
const { nodeId, field } = props;
26-
2727
const dispatch = useAppDispatch();
28+
const [valueAsString, setValueAsString] = useState<string>(
29+
String(field.value)
30+
);
2831

29-
const handleValueChanged = (_: string, value: number) => {
30-
dispatch(fieldValueChanged({ nodeId, fieldName: field.name, value }));
32+
const handleValueChanged = (v: string) => {
33+
setValueAsString(v);
34+
// This allows negatives and decimals e.g. '-123', `.5`, `-0.2`, etc.
35+
if (!v.match(numberStringRegex)) {
36+
// Cast the value to number. Floor it if it should be an integer.
37+
dispatch(
38+
fieldValueChanged({
39+
nodeId,
40+
fieldName: field.name,
41+
value:
42+
props.template.type === 'integer'
43+
? Math.floor(Number(v))
44+
: Number(v),
45+
})
46+
);
47+
}
3148
};
3249

50+
useEffect(() => {
51+
if (
52+
!valueAsString.match(numberStringRegex) &&
53+
field.value !== Number(valueAsString)
54+
) {
55+
setValueAsString(String(field.value));
56+
}
57+
}, [field.value, valueAsString]);
58+
3359
return (
3460
<NumberInput
3561
onChange={handleValueChanged}
36-
value={field.value}
62+
value={valueAsString}
3763
step={props.template.type === 'integer' ? 1 : 0.1}
3864
precision={props.template.type === 'integer' ? 0 : 3}
3965
>

invokeai/frontend/web/src/features/nodes/hooks/useBuildInvocation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const templatesSelector = createSelector(
1818
(nodes) => nodes.invocationTemplates
1919
);
2020

21+
export const DRAG_HANDLE_CLASSNAME = 'node-drag-handle';
22+
23+
export const SHARED_NODE_PROPERTIES: Partial<Node> = {
24+
dragHandle: `.${DRAG_HANDLE_CLASSNAME}`,
25+
};
26+
2127
export const useBuildInvocation = () => {
2228
const invocationTemplates = useAppSelector(templatesSelector);
2329

@@ -32,6 +38,7 @@ export const useBuildInvocation = () => {
3238
});
3339

3440
const node: Node = {
41+
...SHARED_NODE_PROPERTIES,
3542
id: 'progress_image',
3643
type: 'progress_image',
3744
position: { x: x, y: y },
@@ -91,6 +98,7 @@ export const useBuildInvocation = () => {
9198
});
9299

93100
const invocation: Node<InvocationValue> = {
101+
...SHARED_NODE_PROPERTIES,
94102
id: nodeId,
95103
type: 'invocation',
96104
position: { x: x, y: y },

0 commit comments

Comments
 (0)