tidy(ui): remove unused state & actions

This commit is contained in:
psychedelicious 2024-08-06 16:06:17 +10:00
parent 6c1139340c
commit 56350ff5dc
5 changed files with 30 additions and 120 deletions

View File

@ -21,8 +21,8 @@ import {
imBrushLineAdded, imBrushLineAdded,
imEraserLineAdded, imEraserLineAdded,
imImageCacheChanged, imImageCacheChanged,
imMoved,
imRectAdded, imRectAdded,
imTranslated,
inpaintMaskRasterized, inpaintMaskRasterized,
layerBrushLineAdded, layerBrushLineAdded,
layerEraserLineAdded, layerEraserLineAdded,
@ -31,12 +31,12 @@ import {
layerRectAdded, layerRectAdded,
layerReset, layerReset,
layerTranslated, layerTranslated,
regionMaskRasterized,
rgBrushLineAdded, rgBrushLineAdded,
rgEraserLineAdded, rgEraserLineAdded,
rgImageCacheChanged, rgImageCacheChanged,
rgMoved,
rgRasterized,
rgRectAdded, rgRectAdded,
rgTranslated,
toolBufferChanged, toolBufferChanged,
toolChanged, toolChanged,
} from 'features/controlLayers/store/canvasV2Slice'; } from 'features/controlLayers/store/canvasV2Slice';
@ -80,9 +80,9 @@ export class CanvasStateApi {
if (entityType === 'layer') { if (entityType === 'layer') {
this._store.dispatch(layerTranslated(arg)); this._store.dispatch(layerTranslated(arg));
} else if (entityType === 'regional_guidance') { } else if (entityType === 'regional_guidance') {
this._store.dispatch(rgTranslated(arg)); this._store.dispatch(rgMoved(arg));
} else if (entityType === 'inpaint_mask') { } else if (entityType === 'inpaint_mask') {
this._store.dispatch(imTranslated(arg)); this._store.dispatch(imMoved(arg));
} else if (entityType === 'control_adapter') { } else if (entityType === 'control_adapter') {
this._store.dispatch(caTranslated(arg)); this._store.dispatch(caTranslated(arg));
} }
@ -124,7 +124,7 @@ export class CanvasStateApi {
} else if (entityType === 'inpaint_mask') { } else if (entityType === 'inpaint_mask') {
this._store.dispatch(inpaintMaskRasterized(arg)); this._store.dispatch(inpaintMaskRasterized(arg));
} else if (entityType === 'regional_guidance') { } else if (entityType === 'regional_guidance') {
this._store.dispatch(regionMaskRasterized(arg)); this._store.dispatch(rgRasterized(arg));
} else { } else {
assert(false, 'Rasterizing not supported for this entity type'); assert(false, 'Rasterizing not supported for this entity type');
} }

View File

@ -44,8 +44,6 @@ const initialState: CanvasV2State = {
inpaintMask: { inpaintMask: {
id: 'inpaint_mask', id: 'inpaint_mask',
type: 'inpaint_mask', type: 'inpaint_mask',
bbox: null,
bboxNeedsUpdate: false,
fill: RGBA_RED, fill: RGBA_RED,
imageCache: null, imageCache: null,
isEnabled: true, isEnabled: true,
@ -264,8 +262,7 @@ export const {
rgRecalled, rgRecalled,
rgReset, rgReset,
rgIsEnabledToggled, rgIsEnabledToggled,
rgTranslated, rgMoved,
rgBboxChanged,
rgDeleted, rgDeleted,
rgAllDeleted, rgAllDeleted,
rgMovedForwardOne, rgMovedForwardOne,
@ -285,11 +282,10 @@ export const {
rgIPAdapterMethodChanged, rgIPAdapterMethodChanged,
rgIPAdapterModelChanged, rgIPAdapterModelChanged,
rgIPAdapterCLIPVisionModelChanged, rgIPAdapterCLIPVisionModelChanged,
rgScaled,
rgBrushLineAdded, rgBrushLineAdded,
rgEraserLineAdded, rgEraserLineAdded,
rgRectAdded, rgRectAdded,
regionMaskRasterized, rgRasterized,
// Compositing // Compositing
setInfillMethod, setInfillMethod,
setInfillTileSize, setInfillTileSize,
@ -338,11 +334,9 @@ export const {
imReset, imReset,
imRecalled, imRecalled,
imIsEnabledToggled, imIsEnabledToggled,
imTranslated, imMoved,
imBboxChanged,
imFillChanged, imFillChanged,
imImageCacheChanged, imImageCacheChanged,
imScaled,
imBrushLineAdded, imBrushLineAdded,
imEraserLineAdded, imEraserLineAdded,
imRectAdded, imRectAdded,

View File

@ -7,10 +7,8 @@ import type {
CanvasV2State, CanvasV2State,
Coordinate, Coordinate,
EntityRasterizedArg, EntityRasterizedArg,
ScaleChangedArg,
} from 'features/controlLayers/store/types'; } from 'features/controlLayers/store/types';
import { imageDTOToImageWithDims } from 'features/controlLayers/store/types'; import { imageDTOToImageWithDims } from 'features/controlLayers/store/types';
import type { IRect } from 'konva/lib/types';
import type { ImageDTO } from 'services/api/types'; import type { ImageDTO } from 'services/api/types';
import type { RgbColor } from './types'; import type { RgbColor } from './types';
@ -18,8 +16,6 @@ import type { RgbColor } from './types';
export const inpaintMaskReducers = { export const inpaintMaskReducers = {
imReset: (state) => { imReset: (state) => {
state.inpaintMask.objects = []; state.inpaintMask.objects = [];
state.inpaintMask.bbox = null;
state.inpaintMask.bboxNeedsUpdate = false;
state.inpaintMask.imageCache = null; state.inpaintMask.imageCache = null;
}, },
imRecalled: (state, action: PayloadAction<{ data: CanvasInpaintMaskState }>) => { imRecalled: (state, action: PayloadAction<{ data: CanvasInpaintMaskState }>) => {
@ -30,35 +26,10 @@ export const inpaintMaskReducers = {
imIsEnabledToggled: (state) => { imIsEnabledToggled: (state) => {
state.inpaintMask.isEnabled = !state.inpaintMask.isEnabled; state.inpaintMask.isEnabled = !state.inpaintMask.isEnabled;
}, },
imTranslated: (state, action: PayloadAction<{ position: Coordinate }>) => { imMoved: (state, action: PayloadAction<{ position: Coordinate }>) => {
const { position } = action.payload; const { position } = action.payload;
state.inpaintMask.position = position; state.inpaintMask.position = position;
}, },
imScaled: (state, action: PayloadAction<ScaleChangedArg>) => {
const { scale, position } = action.payload;
for (const obj of state.inpaintMask.objects) {
if (obj.type === 'brush_line') {
obj.points = obj.points.map((point) => point * scale);
obj.strokeWidth *= scale;
} else if (obj.type === 'eraser_line') {
obj.points = obj.points.map((point) => point * scale);
obj.strokeWidth *= scale;
} else if (obj.type === 'rect') {
obj.x *= scale;
obj.y *= scale;
obj.height *= scale;
obj.width *= scale;
}
}
state.inpaintMask.position = position;
state.inpaintMask.bboxNeedsUpdate = true;
state.inpaintMask.imageCache = null;
},
imBboxChanged: (state, action: PayloadAction<{ bbox: IRect | null }>) => {
const { bbox } = action.payload;
state.inpaintMask.bbox = bbox;
state.inpaintMask.bboxNeedsUpdate = false;
},
imFillChanged: (state, action: PayloadAction<{ fill: RgbColor }>) => { imFillChanged: (state, action: PayloadAction<{ fill: RgbColor }>) => {
const { fill } = action.payload; const { fill } = action.payload;
state.inpaintMask.fill = fill; state.inpaintMask.fill = fill;
@ -70,19 +41,16 @@ export const inpaintMaskReducers = {
imBrushLineAdded: (state, action: PayloadAction<{ brushLine: CanvasBrushLineState }>) => { imBrushLineAdded: (state, action: PayloadAction<{ brushLine: CanvasBrushLineState }>) => {
const { brushLine } = action.payload; const { brushLine } = action.payload;
state.inpaintMask.objects.push(brushLine); state.inpaintMask.objects.push(brushLine);
state.inpaintMask.bboxNeedsUpdate = true;
state.layers.imageCache = null; state.layers.imageCache = null;
}, },
imEraserLineAdded: (state, action: PayloadAction<{ eraserLine: CanvasEraserLineState }>) => { imEraserLineAdded: (state, action: PayloadAction<{ eraserLine: CanvasEraserLineState }>) => {
const { eraserLine } = action.payload; const { eraserLine } = action.payload;
state.inpaintMask.objects.push(eraserLine); state.inpaintMask.objects.push(eraserLine);
state.inpaintMask.bboxNeedsUpdate = true;
state.layers.imageCache = null; state.layers.imageCache = null;
}, },
imRectAdded: (state, action: PayloadAction<{ rect: CanvasRectState }>) => { imRectAdded: (state, action: PayloadAction<{ rect: CanvasRectState }>) => {
const { rect } = action.payload; const { rect } = action.payload;
state.inpaintMask.objects.push(rect); state.inpaintMask.objects.push(rect);
state.inpaintMask.bboxNeedsUpdate = true;
state.layers.imageCache = null; state.layers.imageCache = null;
}, },
inpaintMaskRasterized: (state, action: PayloadAction<EntityRasterizedArg>) => { inpaintMaskRasterized: (state, action: PayloadAction<EntityRasterizedArg>) => {

View File

@ -1,5 +1,6 @@
import type { PayloadAction, SliceCaseReducers } from '@reduxjs/toolkit'; import type { PayloadAction, SliceCaseReducers } from '@reduxjs/toolkit';
import { moveOneToEnd, moveOneToStart, moveToEnd, moveToStart } from 'common/util/arrayUtils'; import { moveOneToEnd, moveOneToStart, moveToEnd, moveToStart } from 'common/util/arrayUtils';
import { getPrefixedId } from 'features/controlLayers/konva/util';
import type { import type {
CanvasBrushLineState, CanvasBrushLineState,
CanvasEraserLineState, CanvasEraserLineState,
@ -9,16 +10,13 @@ import type {
EntityRasterizedArg, EntityRasterizedArg,
IPMethodV2, IPMethodV2,
PositionChangedArg, PositionChangedArg,
ScaleChangedArg,
} from 'features/controlLayers/store/types'; } from 'features/controlLayers/store/types';
import { imageDTOToImageObject, imageDTOToImageWithDims } from 'features/controlLayers/store/types'; import { imageDTOToImageObject, imageDTOToImageWithDims } from 'features/controlLayers/store/types';
import { zModelIdentifierField } from 'features/nodes/types/common'; import { zModelIdentifierField } from 'features/nodes/types/common';
import type { ParameterAutoNegative } from 'features/parameters/types/parameterSchemas'; import type { ParameterAutoNegative } from 'features/parameters/types/parameterSchemas';
import type { IRect } from 'konva/lib/types';
import { isEqual } from 'lodash-es'; import { isEqual } from 'lodash-es';
import type { ImageDTO, IPAdapterModelConfig } from 'services/api/types'; import type { ImageDTO, IPAdapterModelConfig } from 'services/api/types';
import { assert } from 'tsafe'; import { assert } from 'tsafe';
import { v4 as uuidv4 } from 'uuid';
import type { CanvasIPAdapterState, CanvasRegionalGuidanceState, RgbColor } from './types'; import type { CanvasIPAdapterState, CanvasRegionalGuidanceState, RgbColor } from './types';
@ -59,8 +57,6 @@ export const regionsReducers = {
id, id,
type: 'regional_guidance', type: 'regional_guidance',
isEnabled: true, isEnabled: true,
bbox: null,
bboxNeedsUpdate: false,
objects: [], objects: [],
fill: getRGMaskFill(state), fill: getRGMaskFill(state),
position: { x: 0, y: 0 }, position: { x: 0, y: 0 },
@ -73,7 +69,7 @@ export const regionsReducers = {
state.regions.entities.push(rg); state.regions.entities.push(rg);
state.selectedEntityIdentifier = { type: 'regional_guidance', id }; state.selectedEntityIdentifier = { type: 'regional_guidance', id };
}, },
prepare: () => ({ payload: { id: uuidv4() } }), prepare: () => ({ payload: { id: getPrefixedId('regional_guidance') } }),
}, },
rgReset: (state, action: PayloadAction<{ id: string }>) => { rgReset: (state, action: PayloadAction<{ id: string }>) => {
const { id } = action.payload; const { id } = action.payload;
@ -82,8 +78,6 @@ export const regionsReducers = {
return; return;
} }
rg.objects = []; rg.objects = [];
rg.bbox = null;
rg.bboxNeedsUpdate = false;
rg.imageCache = null; rg.imageCache = null;
}, },
rgRecalled: (state, action: PayloadAction<{ data: CanvasRegionalGuidanceState }>) => { rgRecalled: (state, action: PayloadAction<{ data: CanvasRegionalGuidanceState }>) => {
@ -98,45 +92,13 @@ export const regionsReducers = {
rg.isEnabled = !rg.isEnabled; rg.isEnabled = !rg.isEnabled;
} }
}, },
rgTranslated: (state, action: PayloadAction<PositionChangedArg>) => { rgMoved: (state, action: PayloadAction<PositionChangedArg>) => {
const { id, position } = action.payload; const { id, position } = action.payload;
const rg = selectRG(state, id); const rg = selectRG(state, id);
if (rg) { if (rg) {
rg.position = position; rg.position = position;
} }
}, },
rgScaled: (state, action: PayloadAction<ScaleChangedArg>) => {
const { id, scale, position } = action.payload;
const rg = selectRG(state, id);
if (!rg) {
return;
}
for (const obj of rg.objects) {
if (obj.type === 'brush_line') {
obj.points = obj.points.map((point) => point * scale);
obj.strokeWidth *= scale;
} else if (obj.type === 'eraser_line') {
obj.points = obj.points.map((point) => point * scale);
obj.strokeWidth *= scale;
} else if (obj.type === 'rect') {
obj.x *= scale;
obj.y *= scale;
obj.height *= scale;
obj.width *= scale;
}
}
rg.position = position;
rg.bboxNeedsUpdate = true;
state.layers.imageCache = null;
},
rgBboxChanged: (state, action: PayloadAction<{ id: string; bbox: IRect | null }>) => {
const { id, bbox } = action.payload;
const rg = selectRG(state, id);
if (rg) {
rg.bbox = bbox;
rg.bboxNeedsUpdate = false;
}
},
rgDeleted: (state, action: PayloadAction<{ id: string }>) => { rgDeleted: (state, action: PayloadAction<{ id: string }>) => {
const { id } = action.payload; const { id } = action.payload;
state.regions.entities = state.regions.entities.filter((ca) => ca.id !== id); state.regions.entities = state.regions.entities.filter((ca) => ca.id !== id);
@ -232,12 +194,11 @@ export const regionsReducers = {
} }
rg.ipAdapters = rg.ipAdapters.filter((ipAdapter) => ipAdapter.id !== ipAdapterId); rg.ipAdapters = rg.ipAdapters.filter((ipAdapter) => ipAdapter.id !== ipAdapterId);
}, },
rgIPAdapterImageChanged: { rgIPAdapterImageChanged: (
reducer: (
state, state,
action: PayloadAction<{ id: string; ipAdapterId: string; imageDTO: ImageDTO | null; objectId: string }> action: PayloadAction<{ id: string; ipAdapterId: string; imageDTO: ImageDTO | null; objectId: string }>
) => { ) => {
const { id, ipAdapterId, imageDTO, objectId } = action.payload; const { id, ipAdapterId, imageDTO } = action.payload;
const rg = selectRG(state, id); const rg = selectRG(state, id);
if (!rg) { if (!rg) {
return; return;
@ -246,11 +207,7 @@ export const regionsReducers = {
if (!ipa) { if (!ipa) {
return; return;
} }
ipa.imageObject = imageDTO ? imageDTOToImageObject(id, objectId, imageDTO) : null; ipa.imageObject = imageDTO ? imageDTOToImageObject(imageDTO) : null;
},
prepare: (payload: { id: string; ipAdapterId: string; imageDTO: ImageDTO | null }) => ({
payload: { ...payload, objectId: uuidv4() },
}),
}, },
rgIPAdapterWeightChanged: (state, action: PayloadAction<{ id: string; ipAdapterId: string; weight: number }>) => { rgIPAdapterWeightChanged: (state, action: PayloadAction<{ id: string; ipAdapterId: string; weight: number }>) => {
const { id, ipAdapterId, weight } = action.payload; const { id, ipAdapterId, weight } = action.payload;
@ -337,7 +294,6 @@ export const regionsReducers = {
} }
rg.objects.push(brushLine); rg.objects.push(brushLine);
rg.bboxNeedsUpdate = true;
state.layers.imageCache = null; state.layers.imageCache = null;
}, },
rgEraserLineAdded: (state, action: PayloadAction<{ id: string; eraserLine: CanvasEraserLineState }>) => { rgEraserLineAdded: (state, action: PayloadAction<{ id: string; eraserLine: CanvasEraserLineState }>) => {
@ -348,7 +304,6 @@ export const regionsReducers = {
} }
rg.objects.push(eraserLine); rg.objects.push(eraserLine);
rg.bboxNeedsUpdate = true;
state.layers.imageCache = null; state.layers.imageCache = null;
}, },
rgRectAdded: (state, action: PayloadAction<{ id: string; rect: CanvasRectState }>) => { rgRectAdded: (state, action: PayloadAction<{ id: string; rect: CanvasRectState }>) => {
@ -359,10 +314,9 @@ export const regionsReducers = {
} }
rg.objects.push(rect); rg.objects.push(rect);
rg.bboxNeedsUpdate = true;
state.layers.imageCache = null; state.layers.imageCache = null;
}, },
regionMaskRasterized: (state, action: PayloadAction<EntityRasterizedArg>) => { rgRasterized: (state, action: PayloadAction<EntityRasterizedArg>) => {
const { id, imageObject, position } = action.payload; const { id, imageObject, position } = action.payload;
const rg = selectRG(state, id); const rg = selectRG(state, id);
if (!rg) { if (!rg) {

View File

@ -656,13 +656,11 @@ export const zCanvasRegionalGuidanceState = z.object({
type: z.literal('regional_guidance'), type: z.literal('regional_guidance'),
isEnabled: z.boolean(), isEnabled: z.boolean(),
position: zCoordinate, position: zCoordinate,
bbox: zRect.nullable(),
bboxNeedsUpdate: z.boolean(),
objects: z.array(zCanvasObjectState), objects: z.array(zCanvasObjectState),
fill: zRgbColor,
positivePrompt: zParameterPositivePrompt.nullable(), positivePrompt: zParameterPositivePrompt.nullable(),
negativePrompt: zParameterNegativePrompt.nullable(), negativePrompt: zParameterNegativePrompt.nullable(),
ipAdapters: z.array(zCanvasIPAdapterState), ipAdapters: z.array(zCanvasIPAdapterState),
fill: zRgbColor,
autoNegative: zAutoNegative, autoNegative: zAutoNegative,
imageCache: zImageWithDims.nullable(), imageCache: zImageWithDims.nullable(),
}); });
@ -682,10 +680,8 @@ const zCanvasInpaintMaskState = z.object({
type: z.literal('inpaint_mask'), type: z.literal('inpaint_mask'),
isEnabled: z.boolean(), isEnabled: z.boolean(),
position: zCoordinate, position: zCoordinate,
bbox: zRect.nullable(),
bboxNeedsUpdate: z.boolean(),
objects: z.array(zCanvasObjectState),
fill: zRgbColor, fill: zRgbColor,
objects: z.array(zCanvasObjectState),
imageCache: zImageWithDims.nullable(), imageCache: zImageWithDims.nullable(),
}); });
export type CanvasInpaintMaskState = z.infer<typeof zCanvasInpaintMaskState>; export type CanvasInpaintMaskState = z.infer<typeof zCanvasInpaintMaskState>;
@ -705,8 +701,6 @@ const zCanvasControlAdapterStateBase = z.object({
type: z.literal('control_adapter'), type: z.literal('control_adapter'),
isEnabled: z.boolean(), isEnabled: z.boolean(),
position: zCoordinate, position: zCoordinate,
bbox: zRect.nullable(),
bboxNeedsUpdate: z.boolean(),
opacity: zOpacity, opacity: zOpacity,
filters: z.array(zFilter), filters: z.array(zFilter),
weight: z.number().gte(-1).lte(2), weight: z.number().gte(-1).lte(2),