From 7e341a05a17a0d26d79f9436b4b325946214b38f Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 5 Aug 2024 20:09:28 +1000 Subject: [PATCH] tidy(ui): rename union CanvasEntity -> CanvasEntityState --- .../src/common/hooks/useIsReadyToEnqueue.ts | 4 ++-- .../controlLayers/konva/CanvasManager.ts | 4 ++-- .../controlLayers/konva/CanvasStateApi.ts | 24 +++++++++---------- .../controlLayers/konva/entityBbox.ts | 6 ++--- .../src/features/controlLayers/store/types.ts | 8 +++---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/invokeai/frontend/web/src/common/hooks/useIsReadyToEnqueue.ts b/invokeai/frontend/web/src/common/hooks/useIsReadyToEnqueue.ts index 289132c717..bf8bf22d08 100644 --- a/invokeai/frontend/web/src/common/hooks/useIsReadyToEnqueue.ts +++ b/invokeai/frontend/web/src/common/hooks/useIsReadyToEnqueue.ts @@ -2,7 +2,7 @@ import { useStore } from '@nanostores/react'; import { createMemoizedSelector } from 'app/store/createMemoizedSelector'; import { useAppSelector } from 'app/store/storeHooks'; import { selectCanvasV2Slice } from 'features/controlLayers/store/canvasV2Slice'; -import type { CanvasEntity } from 'features/controlLayers/store/types'; +import type { CanvasEntityState } from 'features/controlLayers/store/types'; import { selectDynamicPromptsSlice } from 'features/dynamicPrompts/store/dynamicPromptsSlice'; import { getShouldProcessPrompt } from 'features/dynamicPrompts/util/getShouldProcessPrompt'; import { $templates, selectNodesSlice } from 'features/nodes/store/nodesSlice'; @@ -18,7 +18,7 @@ import { forEach, upperFirst } from 'lodash-es'; import { useMemo } from 'react'; import { getConnectedEdges } from 'reactflow'; -const LAYER_TYPE_TO_TKEY: Record = { +const LAYER_TYPE_TO_TKEY: Record = { control_adapter: 'controlLayers.globalControlAdapter', ip_adapter: 'controlLayers.globalIPAdapter', regional_guidance: 'controlLayers.regionalGuidance', diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts index 176455ea03..c9924ce383 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts @@ -25,8 +25,8 @@ import type { Extents, ExtentsResult, GetBboxTask, WorkerLogMessage } from 'feat import { $lastProgressEvent, $shouldShowStagedImage } from 'features/controlLayers/store/canvasV2Slice'; import type { CanvasControlAdapterState, - CanvasEntity, CanvasEntityIdentifier, + CanvasEntityState, CanvasInpaintMaskState, CanvasLayerState, CanvasRegionalGuidanceState, @@ -334,7 +334,7 @@ export class CanvasManager { getEntity(identifier: CanvasEntityIdentifier): EntityStateAndAdapter | null { const state = this.stateApi.getState(); - let entityState: CanvasEntity | null = null; + let entityState: CanvasEntityState | null = null; let entityAdapter: CanvasLayer | CanvasRegion | CanvasControlAdapter | CanvasInpaintMask | null = null; if (identifier.type === 'layer') { diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApi.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApi.ts index 6b4be9ac6d..581d0f9a5a 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApi.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApi.ts @@ -47,7 +47,7 @@ import { import type { BboxChangedArg, CanvasBrushLineState, - CanvasEntity, + CanvasEntityState, CanvasEraserLineState, CanvasRectState, PositionChangedArg, @@ -59,29 +59,26 @@ import type { ImageDTO } from 'services/api/types'; const log = logger('canvas'); - export class CanvasStateApi { _store: Store; manager: CanvasManager; - constructor(store: Store, manager: CanvasManager) { this._store = store; this.manager = manager; - } // Reminder - use arrow functions to avoid binding issues getState = () => { return this._store.getState().canvasV2; }; - onEntityReset = (arg: { id: string }, entityType: CanvasEntity['type']) => { + onEntityReset = (arg: { id: string }, entityType: CanvasEntityState['type']) => { log.debug('onEntityReset'); if (entityType === 'layer') { this._store.dispatch(layerReset(arg)); } }; - onPosChanged = (arg: PositionChangedArg, entityType: CanvasEntity['type']) => { + onPosChanged = (arg: PositionChangedArg, entityType: CanvasEntityState['type']) => { log.debug('onPosChanged'); if (entityType === 'layer') { this._store.dispatch(layerTranslated(arg)); @@ -93,7 +90,7 @@ export class CanvasStateApi { this._store.dispatch(caTranslated(arg)); } }; - onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntity['type']) => { + onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntityState['type']) => { log.debug('onScaleChanged'); if (entityType === 'inpaint_mask') { this._store.dispatch(imScaled(arg)); @@ -103,7 +100,7 @@ export class CanvasStateApi { this._store.dispatch(caScaled(arg)); } }; - onBboxChanged = (arg: BboxChangedArg, entityType: CanvasEntity['type']) => { + onBboxChanged = (arg: BboxChangedArg, entityType: CanvasEntityState['type']) => { log.debug('Entity bbox changed'); if (entityType === 'layer') { this._store.dispatch(layerBboxChanged(arg)); @@ -115,7 +112,7 @@ export class CanvasStateApi { this._store.dispatch(imBboxChanged(arg)); } }; - onBrushLineAdded = (arg: { id: string; brushLine: CanvasBrushLineState }, entityType: CanvasEntity['type']) => { + onBrushLineAdded = (arg: { id: string; brushLine: CanvasBrushLineState }, entityType: CanvasEntityState['type']) => { log.debug('Brush line added'); if (entityType === 'layer') { this._store.dispatch(layerBrushLineAdded(arg)); @@ -125,7 +122,10 @@ export class CanvasStateApi { this._store.dispatch(imBrushLineAdded(arg)); } }; - onEraserLineAdded = (arg: { id: string; eraserLine: CanvasEraserLineState }, entityType: CanvasEntity['type']) => { + onEraserLineAdded = ( + arg: { id: string; eraserLine: CanvasEraserLineState }, + entityType: CanvasEntityState['type'] + ) => { log.debug('Eraser line added'); if (entityType === 'layer') { this._store.dispatch(layerEraserLineAdded(arg)); @@ -135,7 +135,7 @@ export class CanvasStateApi { this._store.dispatch(imEraserLineAdded(arg)); } }; - onRectShapeAdded = (arg: { id: string; rectShape: CanvasRectState }, entityType: CanvasEntity['type']) => { + onRectShapeAdded = (arg: { id: string; rectShape: CanvasRectState }, entityType: CanvasEntityState['type']) => { log.debug('Rect shape added'); if (entityType === 'layer') { this._store.dispatch(layerRectShapeAdded(arg)); @@ -145,7 +145,7 @@ export class CanvasStateApi { this._store.dispatch(imRectShapeAdded(arg)); } }; - onEntitySelected = (arg: { id: string; type: CanvasEntity['type'] }) => { + onEntitySelected = (arg: { id: string; type: CanvasEntityState['type'] }) => { log.debug('Entity selected'); this._store.dispatch(entitySelected(arg)); }; diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/entityBbox.ts b/invokeai/frontend/web/src/features/controlLayers/konva/entityBbox.ts index c4e8bfe9df..8e8763460b 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/entityBbox.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/entityBbox.ts @@ -3,8 +3,8 @@ import { getLayerBboxId } from 'features/controlLayers/konva/naming'; import { imageDataToDataURL } from 'features/controlLayers/konva/util'; import type { BboxChangedArg, - CanvasEntity, CanvasControlAdapterState, + CanvasEntityState, CanvasLayerState, CanvasRegionalGuidanceState, } from 'features/controlLayers/store/types'; @@ -17,7 +17,7 @@ import { assert } from 'tsafe'; * @param entity The layer state for the layer to create the bounding box for * @param konvaLayer The konva layer to attach the bounding box to */ -export const createBboxRect = (entity: CanvasEntity, konvaLayer: Konva.Layer): Konva.Rect => { +export const createBboxRect = (entity: CanvasEntityState, konvaLayer: Konva.Layer): Konva.Rect => { const rect = new Konva.Rect({ id: getLayerBboxId(entity.id), name: 'bbox', @@ -201,7 +201,7 @@ export const updateBboxes = ( layers: CanvasLayerState[], controlAdapters: CanvasControlAdapterState[], regions: CanvasRegionalGuidanceState[], - onBboxChanged: (arg: BboxChangedArg, entityType: CanvasEntity['type']) => void + onBboxChanged: (arg: BboxChangedArg, entityType: CanvasEntityState['type']) => void ): void => { for (const entityState of [...layers, ...controlAdapters, ...regions]) { const konvaLayer = stage.findOne(`#${entityState.id}`); diff --git a/invokeai/frontend/web/src/features/controlLayers/store/types.ts b/invokeai/frontend/web/src/features/controlLayers/store/types.ts index a77e6255cd..00a1bbaf6a 100644 --- a/invokeai/frontend/web/src/features/controlLayers/store/types.ts +++ b/invokeai/frontend/web/src/features/controlLayers/store/types.ts @@ -819,14 +819,14 @@ export type BoundingBoxScaleMethod = z.infer; export const isBoundingBoxScaleMethod = (v: unknown): v is BoundingBoxScaleMethod => zBoundingBoxScaleMethod.safeParse(v).success; -export type CanvasEntity = +export type CanvasEntityState = | CanvasLayerState | CanvasControlAdapterState | CanvasRegionalGuidanceState | CanvasInpaintMaskState | CanvasIPAdapterState | InitialImageEntity; -export type CanvasEntityIdentifier = Pick; +export type CanvasEntityIdentifier = Pick; export type LoRA = { id: string; @@ -967,7 +967,7 @@ export type RemoveIndexString = { export type GenerationMode = 'txt2img' | 'img2img' | 'inpaint' | 'outpaint'; export function isDrawableEntity( - entity: CanvasEntity + entity: CanvasEntityState ): entity is CanvasLayerState | CanvasRegionalGuidanceState | CanvasInpaintMaskState { return entity.type === 'layer' || entity.type === 'regional_guidance' || entity.type === 'inpaint_mask'; } @@ -979,7 +979,7 @@ export function isDrawableEntityAdapter( } export function isDrawableEntityType( - entityType: CanvasEntity['type'] + entityType: CanvasEntityState['type'] ): entityType is 'layer' | 'regional_guidance' | 'inpaint_mask' { return entityType === 'layer' || entityType === 'regional_guidance' || entityType === 'inpaint_mask'; }