tidy(ui): rename union CanvasEntity -> CanvasEntityState

This commit is contained in:
psychedelicious 2024-08-05 20:09:28 +10:00
parent e665d08ee1
commit 7e341a05a1
5 changed files with 23 additions and 23 deletions

View File

@ -2,7 +2,7 @@ import { useStore } from '@nanostores/react';
import { createMemoizedSelector } from 'app/store/createMemoizedSelector'; import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
import { useAppSelector } from 'app/store/storeHooks'; import { useAppSelector } from 'app/store/storeHooks';
import { selectCanvasV2Slice } from 'features/controlLayers/store/canvasV2Slice'; 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 { selectDynamicPromptsSlice } from 'features/dynamicPrompts/store/dynamicPromptsSlice';
import { getShouldProcessPrompt } from 'features/dynamicPrompts/util/getShouldProcessPrompt'; import { getShouldProcessPrompt } from 'features/dynamicPrompts/util/getShouldProcessPrompt';
import { $templates, selectNodesSlice } from 'features/nodes/store/nodesSlice'; import { $templates, selectNodesSlice } from 'features/nodes/store/nodesSlice';
@ -18,7 +18,7 @@ import { forEach, upperFirst } from 'lodash-es';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { getConnectedEdges } from 'reactflow'; import { getConnectedEdges } from 'reactflow';
const LAYER_TYPE_TO_TKEY: Record<CanvasEntity['type'], string> = { const LAYER_TYPE_TO_TKEY: Record<CanvasEntityState['type'], string> = {
control_adapter: 'controlLayers.globalControlAdapter', control_adapter: 'controlLayers.globalControlAdapter',
ip_adapter: 'controlLayers.globalIPAdapter', ip_adapter: 'controlLayers.globalIPAdapter',
regional_guidance: 'controlLayers.regionalGuidance', regional_guidance: 'controlLayers.regionalGuidance',

View File

@ -25,8 +25,8 @@ import type { Extents, ExtentsResult, GetBboxTask, WorkerLogMessage } from 'feat
import { $lastProgressEvent, $shouldShowStagedImage } from 'features/controlLayers/store/canvasV2Slice'; import { $lastProgressEvent, $shouldShowStagedImage } from 'features/controlLayers/store/canvasV2Slice';
import type { import type {
CanvasControlAdapterState, CanvasControlAdapterState,
CanvasEntity,
CanvasEntityIdentifier, CanvasEntityIdentifier,
CanvasEntityState,
CanvasInpaintMaskState, CanvasInpaintMaskState,
CanvasLayerState, CanvasLayerState,
CanvasRegionalGuidanceState, CanvasRegionalGuidanceState,
@ -334,7 +334,7 @@ export class CanvasManager {
getEntity(identifier: CanvasEntityIdentifier): EntityStateAndAdapter | null { getEntity(identifier: CanvasEntityIdentifier): EntityStateAndAdapter | null {
const state = this.stateApi.getState(); const state = this.stateApi.getState();
let entityState: CanvasEntity | null = null; let entityState: CanvasEntityState | null = null;
let entityAdapter: CanvasLayer | CanvasRegion | CanvasControlAdapter | CanvasInpaintMask | null = null; let entityAdapter: CanvasLayer | CanvasRegion | CanvasControlAdapter | CanvasInpaintMask | null = null;
if (identifier.type === 'layer') { if (identifier.type === 'layer') {

View File

@ -47,7 +47,7 @@ import {
import type { import type {
BboxChangedArg, BboxChangedArg,
CanvasBrushLineState, CanvasBrushLineState,
CanvasEntity, CanvasEntityState,
CanvasEraserLineState, CanvasEraserLineState,
CanvasRectState, CanvasRectState,
PositionChangedArg, PositionChangedArg,
@ -59,29 +59,26 @@ import type { ImageDTO } from 'services/api/types';
const log = logger('canvas'); const log = logger('canvas');
export class CanvasStateApi { export class CanvasStateApi {
_store: Store<RootState>; _store: Store<RootState>;
manager: CanvasManager; manager: CanvasManager;
constructor(store: Store<RootState>, manager: CanvasManager) { constructor(store: Store<RootState>, manager: CanvasManager) {
this._store = store; this._store = store;
this.manager = manager; this.manager = manager;
} }
// Reminder - use arrow functions to avoid binding issues // Reminder - use arrow functions to avoid binding issues
getState = () => { getState = () => {
return this._store.getState().canvasV2; return this._store.getState().canvasV2;
}; };
onEntityReset = (arg: { id: string }, entityType: CanvasEntity['type']) => { onEntityReset = (arg: { id: string }, entityType: CanvasEntityState['type']) => {
log.debug('onEntityReset'); log.debug('onEntityReset');
if (entityType === 'layer') { if (entityType === 'layer') {
this._store.dispatch(layerReset(arg)); this._store.dispatch(layerReset(arg));
} }
}; };
onPosChanged = (arg: PositionChangedArg, entityType: CanvasEntity['type']) => { onPosChanged = (arg: PositionChangedArg, entityType: CanvasEntityState['type']) => {
log.debug('onPosChanged'); log.debug('onPosChanged');
if (entityType === 'layer') { if (entityType === 'layer') {
this._store.dispatch(layerTranslated(arg)); this._store.dispatch(layerTranslated(arg));
@ -93,7 +90,7 @@ export class CanvasStateApi {
this._store.dispatch(caTranslated(arg)); this._store.dispatch(caTranslated(arg));
} }
}; };
onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntity['type']) => { onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntityState['type']) => {
log.debug('onScaleChanged'); log.debug('onScaleChanged');
if (entityType === 'inpaint_mask') { if (entityType === 'inpaint_mask') {
this._store.dispatch(imScaled(arg)); this._store.dispatch(imScaled(arg));
@ -103,7 +100,7 @@ export class CanvasStateApi {
this._store.dispatch(caScaled(arg)); this._store.dispatch(caScaled(arg));
} }
}; };
onBboxChanged = (arg: BboxChangedArg, entityType: CanvasEntity['type']) => { onBboxChanged = (arg: BboxChangedArg, entityType: CanvasEntityState['type']) => {
log.debug('Entity bbox changed'); log.debug('Entity bbox changed');
if (entityType === 'layer') { if (entityType === 'layer') {
this._store.dispatch(layerBboxChanged(arg)); this._store.dispatch(layerBboxChanged(arg));
@ -115,7 +112,7 @@ export class CanvasStateApi {
this._store.dispatch(imBboxChanged(arg)); 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'); log.debug('Brush line added');
if (entityType === 'layer') { if (entityType === 'layer') {
this._store.dispatch(layerBrushLineAdded(arg)); this._store.dispatch(layerBrushLineAdded(arg));
@ -125,7 +122,10 @@ export class CanvasStateApi {
this._store.dispatch(imBrushLineAdded(arg)); 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'); log.debug('Eraser line added');
if (entityType === 'layer') { if (entityType === 'layer') {
this._store.dispatch(layerEraserLineAdded(arg)); this._store.dispatch(layerEraserLineAdded(arg));
@ -135,7 +135,7 @@ export class CanvasStateApi {
this._store.dispatch(imEraserLineAdded(arg)); 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'); log.debug('Rect shape added');
if (entityType === 'layer') { if (entityType === 'layer') {
this._store.dispatch(layerRectShapeAdded(arg)); this._store.dispatch(layerRectShapeAdded(arg));
@ -145,7 +145,7 @@ export class CanvasStateApi {
this._store.dispatch(imRectShapeAdded(arg)); this._store.dispatch(imRectShapeAdded(arg));
} }
}; };
onEntitySelected = (arg: { id: string; type: CanvasEntity['type'] }) => { onEntitySelected = (arg: { id: string; type: CanvasEntityState['type'] }) => {
log.debug('Entity selected'); log.debug('Entity selected');
this._store.dispatch(entitySelected(arg)); this._store.dispatch(entitySelected(arg));
}; };

View File

@ -3,8 +3,8 @@ import { getLayerBboxId } from 'features/controlLayers/konva/naming';
import { imageDataToDataURL } from 'features/controlLayers/konva/util'; import { imageDataToDataURL } from 'features/controlLayers/konva/util';
import type { import type {
BboxChangedArg, BboxChangedArg,
CanvasEntity,
CanvasControlAdapterState, CanvasControlAdapterState,
CanvasEntityState,
CanvasLayerState, CanvasLayerState,
CanvasRegionalGuidanceState, CanvasRegionalGuidanceState,
} from 'features/controlLayers/store/types'; } 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 entity The layer state for the layer to create the bounding box for
* @param konvaLayer The konva layer to attach the bounding box to * @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({ const rect = new Konva.Rect({
id: getLayerBboxId(entity.id), id: getLayerBboxId(entity.id),
name: 'bbox', name: 'bbox',
@ -201,7 +201,7 @@ export const updateBboxes = (
layers: CanvasLayerState[], layers: CanvasLayerState[],
controlAdapters: CanvasControlAdapterState[], controlAdapters: CanvasControlAdapterState[],
regions: CanvasRegionalGuidanceState[], regions: CanvasRegionalGuidanceState[],
onBboxChanged: (arg: BboxChangedArg, entityType: CanvasEntity['type']) => void onBboxChanged: (arg: BboxChangedArg, entityType: CanvasEntityState['type']) => void
): void => { ): void => {
for (const entityState of [...layers, ...controlAdapters, ...regions]) { for (const entityState of [...layers, ...controlAdapters, ...regions]) {
const konvaLayer = stage.findOne<Konva.Layer>(`#${entityState.id}`); const konvaLayer = stage.findOne<Konva.Layer>(`#${entityState.id}`);

View File

@ -819,14 +819,14 @@ export type BoundingBoxScaleMethod = z.infer<typeof zBoundingBoxScaleMethod>;
export const isBoundingBoxScaleMethod = (v: unknown): v is BoundingBoxScaleMethod => export const isBoundingBoxScaleMethod = (v: unknown): v is BoundingBoxScaleMethod =>
zBoundingBoxScaleMethod.safeParse(v).success; zBoundingBoxScaleMethod.safeParse(v).success;
export type CanvasEntity = export type CanvasEntityState =
| CanvasLayerState | CanvasLayerState
| CanvasControlAdapterState | CanvasControlAdapterState
| CanvasRegionalGuidanceState | CanvasRegionalGuidanceState
| CanvasInpaintMaskState | CanvasInpaintMaskState
| CanvasIPAdapterState | CanvasIPAdapterState
| InitialImageEntity; | InitialImageEntity;
export type CanvasEntityIdentifier = Pick<CanvasEntity, 'id' | 'type'>; export type CanvasEntityIdentifier = Pick<CanvasEntityState, 'id' | 'type'>;
export type LoRA = { export type LoRA = {
id: string; id: string;
@ -967,7 +967,7 @@ export type RemoveIndexString<T> = {
export type GenerationMode = 'txt2img' | 'img2img' | 'inpaint' | 'outpaint'; export type GenerationMode = 'txt2img' | 'img2img' | 'inpaint' | 'outpaint';
export function isDrawableEntity( export function isDrawableEntity(
entity: CanvasEntity entity: CanvasEntityState
): entity is CanvasLayerState | CanvasRegionalGuidanceState | CanvasInpaintMaskState { ): entity is CanvasLayerState | CanvasRegionalGuidanceState | CanvasInpaintMaskState {
return entity.type === 'layer' || entity.type === 'regional_guidance' || entity.type === 'inpaint_mask'; return entity.type === 'layer' || entity.type === 'regional_guidance' || entity.type === 'inpaint_mask';
} }
@ -979,7 +979,7 @@ export function isDrawableEntityAdapter(
} }
export function isDrawableEntityType( export function isDrawableEntityType(
entityType: CanvasEntity['type'] entityType: CanvasEntityState['type']
): entityType is 'layer' | 'regional_guidance' | 'inpaint_mask' { ): entityType is 'layer' | 'regional_guidance' | 'inpaint_mask' {
return entityType === 'layer' || entityType === 'regional_guidance' || entityType === 'inpaint_mask'; return entityType === 'layer' || entityType === 'regional_guidance' || entityType === 'inpaint_mask';
} }