mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
refactored dndsortable to be its own component
This commit is contained in:
parent
2071972a8c
commit
a948bd1310
@ -32,7 +32,6 @@ const AppDndContext = (props: PropsWithChildren) => {
|
|||||||
|
|
||||||
const handleDragEnd = useCallback(
|
const handleDragEnd = useCallback(
|
||||||
(event: DragEndEvent) => {
|
(event: DragEndEvent) => {
|
||||||
console.log('handling drag end', event.active.data.current);
|
|
||||||
log.trace({ dragData: parseify(event.active.data.current) }, 'Drag ended');
|
log.trace({ dragData: parseify(event.active.data.current) }, 'Drag ended');
|
||||||
const overData = event.over?.data.current;
|
const overData = event.over?.data.current;
|
||||||
if (!activeDragData || !overData) {
|
if (!activeDragData || !overData) {
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
import type { DragEndEvent } from '@dnd-kit/core';
|
||||||
|
import { MouseSensor, TouchSensor, useSensor, useSensors } from '@dnd-kit/core';
|
||||||
|
import { SortableContext } from '@dnd-kit/sortable';
|
||||||
|
import type { PropsWithChildren } from 'react';
|
||||||
|
import { memo } from 'react';
|
||||||
|
|
||||||
|
import { DndContextTypesafe } from './DndContextTypesafe';
|
||||||
|
|
||||||
|
type Props = PropsWithChildren & {
|
||||||
|
items: string[];
|
||||||
|
onDragEnd(event: DragEndEvent): void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const DndSortable = (props: Props) => {
|
||||||
|
const mouseSensor = useSensor(MouseSensor, {
|
||||||
|
activationConstraint: { distance: 10 },
|
||||||
|
});
|
||||||
|
|
||||||
|
const touchSensor = useSensor(TouchSensor, {
|
||||||
|
activationConstraint: { distance: 10 },
|
||||||
|
});
|
||||||
|
|
||||||
|
const sensors = useSensors(mouseSensor, touchSensor);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DndContextTypesafe sensors={sensors}>
|
||||||
|
<SortableContext items={props.items}>{props.children}</SortableContext>
|
||||||
|
</DndContextTypesafe>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(DndSortable);
|
@ -31,7 +31,7 @@ const LinearViewField = ({ nodeId, fieldName }: Props) => {
|
|||||||
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: `${nodeId}.${fieldName}` });
|
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: `${nodeId}.${fieldName}` });
|
||||||
|
|
||||||
const style = {
|
const style = {
|
||||||
transform: CSS.Transform.toString(transform),
|
transform: CSS.Translate.toString(transform),
|
||||||
transition,
|
transition,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { DndContext } from '@dnd-kit/core';
|
import { arrayMove } from '@dnd-kit/sortable';
|
||||||
import { arrayMove, SortableContext } from '@dnd-kit/sortable';
|
|
||||||
import { Box, Flex } from '@invoke-ai/ui-library';
|
import { Box, Flex } from '@invoke-ai/ui-library';
|
||||||
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { IAINoContentFallback } from 'common/components/IAIImageFallback';
|
import { IAINoContentFallback } from 'common/components/IAIImageFallback';
|
||||||
import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent';
|
import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent';
|
||||||
|
import DndSortable from 'features/dnd/components/DndSortable';
|
||||||
import type { DragEndEvent } from 'features/dnd/types';
|
import type { DragEndEvent } from 'features/dnd/types';
|
||||||
import LinearViewField from 'features/nodes/components/flow/nodes/Invocation/fields/LinearViewField';
|
import LinearViewField from 'features/nodes/components/flow/nodes/Invocation/fields/LinearViewField';
|
||||||
import { selectWorkflowSlice, workflowExposedFieldsReordered } from 'features/nodes/store/workflowSlice';
|
import { selectWorkflowSlice, workflowExposedFieldsReordered } from 'features/nodes/store/workflowSlice';
|
||||||
import { FieldIdentifier } from 'features/nodes/types/field';
|
import type { FieldIdentifier } from 'features/nodes/types/field';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo';
|
import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo';
|
||||||
@ -24,7 +24,6 @@ const WorkflowLinearTab = () => {
|
|||||||
const handleDragEnd = useCallback(
|
const handleDragEnd = useCallback(
|
||||||
(event: DragEndEvent) => {
|
(event: DragEndEvent) => {
|
||||||
const { active, over } = event;
|
const { active, over } = event;
|
||||||
console.log({ active, over });
|
|
||||||
const fieldsStrings = fields.map((field) => `${field.nodeId}.${field.fieldName}`);
|
const fieldsStrings = fields.map((field) => `${field.nodeId}.${field.fieldName}`);
|
||||||
|
|
||||||
if (over && active.id !== over.id) {
|
if (over && active.id !== over.id) {
|
||||||
@ -44,8 +43,7 @@ const WorkflowLinearTab = () => {
|
|||||||
return (
|
return (
|
||||||
<Box position="relative" w="full" h="full">
|
<Box position="relative" w="full" h="full">
|
||||||
<ScrollableContent>
|
<ScrollableContent>
|
||||||
<DndContext onDragEnd={handleDragEnd}>
|
<DndSortable onDragEnd={handleDragEnd} items={fields.map((field) => `${field.nodeId}.${field.fieldName}`)}>
|
||||||
<SortableContext items={fields.map((field) => `${field.nodeId}.${field.fieldName}`)}>
|
|
||||||
<Flex position="relative" flexDir="column" alignItems="flex-start" p={1} gap={2} h="full" w="full">
|
<Flex position="relative" flexDir="column" alignItems="flex-start" p={1} gap={2} h="full" w="full">
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<IAINoContentFallback label={t('nodes.loadingNodes')} icon={null} />
|
<IAINoContentFallback label={t('nodes.loadingNodes')} icon={null} />
|
||||||
@ -57,8 +55,7 @@ const WorkflowLinearTab = () => {
|
|||||||
<IAINoContentFallback label={t('nodes.noFieldsLinearview')} icon={null} />
|
<IAINoContentFallback label={t('nodes.noFieldsLinearview')} icon={null} />
|
||||||
)}
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
</SortableContext>
|
</DndSortable>
|
||||||
</DndContext>
|
|
||||||
</ScrollableContent>
|
</ScrollableContent>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user