mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): Make Nodes always spawn in center of work area
This commit is contained in:
parent
ad41afe65e
commit
94a07a8da7
@ -1,7 +1,7 @@
|
|||||||
import { RootState } from 'app/store';
|
import { RootState } from 'app/store';
|
||||||
import { useAppSelector } from 'app/storeHooks';
|
import { useAppSelector } from 'app/storeHooks';
|
||||||
import { reduce } from 'lodash';
|
import { reduce } from 'lodash';
|
||||||
import { Node } from 'reactflow';
|
import { Node, useReactFlow } from 'reactflow';
|
||||||
import { AnyInvocationType } from 'services/events/types';
|
import { AnyInvocationType } from 'services/events/types';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import {
|
import {
|
||||||
@ -16,6 +16,8 @@ export const useBuildInvocation = () => {
|
|||||||
(state: RootState) => state.nodes.invocationTemplates
|
(state: RootState) => state.nodes.invocationTemplates
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const reactflow = useReactFlow();
|
||||||
|
|
||||||
return (type: AnyInvocationType) => {
|
return (type: AnyInvocationType) => {
|
||||||
const template = invocationTemplates[type];
|
const template = invocationTemplates[type];
|
||||||
|
|
||||||
@ -61,10 +63,15 @@ export const useBuildInvocation = () => {
|
|||||||
{} as Record<string, OutputFieldValue>
|
{} as Record<string, OutputFieldValue>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { x, y } = reactflow.project({
|
||||||
|
x: window.innerWidth / 2.5,
|
||||||
|
y: window.innerHeight / 8,
|
||||||
|
});
|
||||||
|
|
||||||
const invocation: Node<InvocationValue> = {
|
const invocation: Node<InvocationValue> = {
|
||||||
id: nodeId,
|
id: nodeId,
|
||||||
type: 'invocation',
|
type: 'invocation',
|
||||||
position: { x: 0, y: 0 },
|
position: { x: x, y: y },
|
||||||
data: {
|
data: {
|
||||||
id: nodeId,
|
id: nodeId,
|
||||||
type,
|
type,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user