mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): remove nodeExclusivelySelected action
This commit is contained in:
parent
a51142674a
commit
0b5696c5d4
@ -1,14 +1,15 @@
|
|||||||
import type { ChakraProps } from '@invoke-ai/ui-library';
|
import type { ChakraProps } from '@invoke-ai/ui-library';
|
||||||
import { Box, useGlobalMenuClose, useToken } from '@invoke-ai/ui-library';
|
import { Box, useGlobalMenuClose, useToken } from '@invoke-ai/ui-library';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector, useAppStore } from 'app/store/storeHooks';
|
||||||
import NodeSelectionOverlay from 'common/components/NodeSelectionOverlay';
|
import NodeSelectionOverlay from 'common/components/NodeSelectionOverlay';
|
||||||
import { useExecutionState } from 'features/nodes/hooks/useExecutionState';
|
import { useExecutionState } from 'features/nodes/hooks/useExecutionState';
|
||||||
import { useMouseOverNode } from 'features/nodes/hooks/useMouseOverNode';
|
import { useMouseOverNode } from 'features/nodes/hooks/useMouseOverNode';
|
||||||
import { nodeExclusivelySelected } from 'features/nodes/store/nodesSlice';
|
import { nodesChanged } from 'features/nodes/store/nodesSlice';
|
||||||
import { DRAG_HANDLE_CLASSNAME, NODE_WIDTH } from 'features/nodes/types/constants';
|
import { DRAG_HANDLE_CLASSNAME, NODE_WIDTH } from 'features/nodes/types/constants';
|
||||||
import { zNodeStatus } from 'features/nodes/types/invocation';
|
import { zNodeStatus } from 'features/nodes/types/invocation';
|
||||||
import type { MouseEvent, PropsWithChildren } from 'react';
|
import type { MouseEvent, PropsWithChildren } from 'react';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
|
import type { NodeChange } from 'reactflow';
|
||||||
|
|
||||||
type NodeWrapperProps = PropsWithChildren & {
|
type NodeWrapperProps = PropsWithChildren & {
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
@ -18,6 +19,7 @@ type NodeWrapperProps = PropsWithChildren & {
|
|||||||
|
|
||||||
const NodeWrapper = (props: NodeWrapperProps) => {
|
const NodeWrapper = (props: NodeWrapperProps) => {
|
||||||
const { nodeId, width, children, selected } = props;
|
const { nodeId, width, children, selected } = props;
|
||||||
|
const store = useAppStore();
|
||||||
const { isMouseOverNode, handleMouseOut, handleMouseOver } = useMouseOverNode(nodeId);
|
const { isMouseOverNode, handleMouseOut, handleMouseOver } = useMouseOverNode(nodeId);
|
||||||
|
|
||||||
const executionState = useExecutionState(nodeId);
|
const executionState = useExecutionState(nodeId);
|
||||||
@ -37,11 +39,13 @@ const NodeWrapper = (props: NodeWrapperProps) => {
|
|||||||
const handleClick = useCallback(
|
const handleClick = useCallback(
|
||||||
(e: MouseEvent<HTMLDivElement>) => {
|
(e: MouseEvent<HTMLDivElement>) => {
|
||||||
if (!e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
|
if (!e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
|
||||||
dispatch(nodeExclusivelySelected(nodeId));
|
const { nodes } = store.getState().nodes.present;
|
||||||
|
const nodeChanges: NodeChange[] = nodes.map(({ id }) => ({ type: 'select', id, selected: id === nodeId }));
|
||||||
|
dispatch(nodesChanged(nodeChanges));
|
||||||
}
|
}
|
||||||
onCloseGlobal();
|
onCloseGlobal();
|
||||||
},
|
},
|
||||||
[dispatch, onCloseGlobal, nodeId]
|
[onCloseGlobal, store, dispatch, nodeId]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -272,17 +272,6 @@ export const nodesSlice = createSlice({
|
|||||||
}
|
}
|
||||||
node.data.notes = notes;
|
node.data.notes = notes;
|
||||||
},
|
},
|
||||||
nodeExclusivelySelected: (state, action: PayloadAction<string>) => {
|
|
||||||
const nodeId = action.payload;
|
|
||||||
state.nodes = applyNodeChanges(
|
|
||||||
state.nodes.map(({ id }) => ({
|
|
||||||
type: 'select',
|
|
||||||
id,
|
|
||||||
selected: id === nodeId ? true : false,
|
|
||||||
})),
|
|
||||||
state.nodes
|
|
||||||
);
|
|
||||||
},
|
|
||||||
fieldValueReset: (state, action: FieldValueAction<StatefulFieldValue>) => {
|
fieldValueReset: (state, action: FieldValueAction<StatefulFieldValue>) => {
|
||||||
fieldValueReducer(state, action, zStatefulFieldValue);
|
fieldValueReducer(state, action, zStatefulFieldValue);
|
||||||
},
|
},
|
||||||
@ -389,7 +378,6 @@ export const {
|
|||||||
fieldStringValueChanged,
|
fieldStringValueChanged,
|
||||||
fieldVaeModelValueChanged,
|
fieldVaeModelValueChanged,
|
||||||
nodeEditorReset,
|
nodeEditorReset,
|
||||||
nodeExclusivelySelected,
|
|
||||||
nodeIsIntermediateChanged,
|
nodeIsIntermediateChanged,
|
||||||
nodeIsOpenChanged,
|
nodeIsOpenChanged,
|
||||||
nodeLabelChanged,
|
nodeLabelChanged,
|
||||||
@ -438,12 +426,7 @@ export const nodesPersistConfig: PersistConfig<NodesState> = {
|
|||||||
persistDenylist: [],
|
persistDenylist: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectionMatcher = isAnyOf(nodeExclusivelySelected);
|
|
||||||
|
|
||||||
const isSelectionAction = (action: UnknownAction) => {
|
const isSelectionAction = (action: UnknownAction) => {
|
||||||
if (selectionMatcher(action)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (nodesChanged.match(action)) {
|
if (nodesChanged.match(action)) {
|
||||||
if (action.payload.every((change) => change.type === 'select')) {
|
if (action.payload.every((change) => change.type === 'select')) {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user