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 { 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<CanvasEntity['type'], string> = {
const LAYER_TYPE_TO_TKEY: Record<CanvasEntityState['type'], string> = {
control_adapter: 'controlLayers.globalControlAdapter',
ip_adapter: 'controlLayers.globalIPAdapter',
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 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') {

View File

@ -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<RootState>;
manager: CanvasManager;
constructor(store: Store<RootState>, 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));
};

View File

@ -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<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 =>
zBoundingBoxScaleMethod.safeParse(v).success;
export type CanvasEntity =
export type CanvasEntityState =
| CanvasLayerState
| CanvasControlAdapterState
| CanvasRegionalGuidanceState
| CanvasInpaintMaskState
| CanvasIPAdapterState
| InitialImageEntity;
export type CanvasEntityIdentifier = Pick<CanvasEntity, 'id' | 'type'>;
export type CanvasEntityIdentifier = Pick<CanvasEntityState, 'id' | 'type'>;
export type LoRA = {
id: string;
@ -967,7 +967,7 @@ export type RemoveIndexString<T> = {
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';
}