chore(ui): lint

This commit is contained in:
psychedelicious 2024-04-12 19:08:44 +10:00 committed by Kent Keirsey
parent 52e7daffe7
commit 944fa1a847
7 changed files with 10 additions and 32 deletions

View File

@ -26,7 +26,7 @@ i18n.use(initReactI18next).init({
}); });
const store = createStore(undefined, false); const store = createStore(undefined, false);
$store.set(store) $store.set(store);
$baseUrl.set('http://localhost:9090'); $baseUrl.set('http://localhost:9090');
const preview: Preview = { const preview: Preview = {

View File

@ -6,7 +6,7 @@ import { LineComponent } from 'features/regionalPrompts/components/LineComponent
import { RectComponent } from 'features/regionalPrompts/components/RectComponent'; import { RectComponent } from 'features/regionalPrompts/components/RectComponent';
import { useLayer } from 'features/regionalPrompts/hooks/layerStateHooks'; import { useLayer } from 'features/regionalPrompts/hooks/layerStateHooks';
import { import {
$stage, getStage,
layerBboxChanged, layerBboxChanged,
layerTranslated, layerTranslated,
REGIONAL_PROMPT_LAYER_NAME, REGIONAL_PROMPT_LAYER_NAME,
@ -54,10 +54,7 @@ export const LayerComponent: React.FC<Props> = ({ id }) => {
); );
const dragBoundFunc = useCallback(function (this: KonvaNodeType<KonvaNodeConfigType>, pos: Vector2d) { const dragBoundFunc = useCallback(function (this: KonvaNodeType<KonvaNodeConfigType>, pos: Vector2d) {
const stage = $stage.get(); const stage = getStage();
if (!stage) {
return this.getAbsolutePosition();
}
const cursorPos = getScaledCursorPosition(stage); const cursorPos = getScaledCursorPosition(stage);
if (!cursorPos) { if (!cursorPos) {
return this.getAbsolutePosition(); return this.getAbsolutePosition();

View File

@ -13,7 +13,7 @@ import type { KonvaEventObject } from 'konva/lib/Node';
import type { MutableRefObject } from 'react'; import type { MutableRefObject } from 'react';
import { useCallback } from 'react'; import { useCallback } from 'react';
export const getTool = () => getStore().getState().regionalPrompts.tool; const getTool = () => getStore().getState().regionalPrompts.tool;
const getIsFocused = (stage: Konva.Stage) => { const getIsFocused = (stage: Konva.Stage) => {
return stage.container().contains(document.activeElement); return stage.container().contains(document.activeElement);

View File

@ -1,18 +0,0 @@
import type { Group as KonvaGroupType } from 'konva/lib/Group';
import type { Transformer as KonvaTransformerType } from 'konva/lib/shapes/Transformer';
import { useEffect, useRef } from 'react';
export const useTransform = () => {
const shapeRef = useRef<KonvaGroupType>(null);
const transformerRef = useRef<KonvaTransformerType>(null);
useEffect(() => {
if (!transformerRef.current || !shapeRef.current) {
return;
}
transformerRef.current.nodes([shapeRef.current]);
transformerRef.current.getLayer()?.batchDraw();
}, []);
return { shapeRef, transformerRef };
};

View File

@ -9,7 +9,7 @@ import type { RgbColor } from 'react-colorful';
import { assert } from 'tsafe'; import { assert } from 'tsafe';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
export type Tool = 'brush' | 'eraser' | 'move'; type Tool = 'brush' | 'eraser' | 'move';
type LayerObjectBase = { type LayerObjectBase = {
id: string; id: string;
@ -39,7 +39,7 @@ export type FillRectObject = LayerObjectBase & {
height: number; height: number;
}; };
export type LayerObject = ImageObject | LineObject | FillRectObject; type LayerObject = ImageObject | LineObject | FillRectObject;
type LayerBase = { type LayerBase = {
id: string; id: string;
@ -56,7 +56,7 @@ type PromptRegionLayer = LayerBase & {
color: RgbColor; color: RgbColor;
}; };
export type Layer = PromptRegionLayer; type Layer = PromptRegionLayer;
type RegionalPromptsState = { type RegionalPromptsState = {
_version: 1; _version: 1;

View File

@ -11,7 +11,7 @@ import { assert } from 'tsafe';
* @param imageData The ImageData object to get the bounding box of. * @param imageData The ImageData object to get the bounding box of.
* @returns The minimum and maximum x and y values of the image's bounding box. * @returns The minimum and maximum x and y values of the image's bounding box.
*/ */
export const getImageDataBbox = (imageData: ImageData) => { const getImageDataBbox = (imageData: ImageData) => {
const { data, width, height } = imageData; const { data, width, height } = imageData;
let minX = width; let minX = width;
let minY = height; let minY = height;

View File

@ -2,7 +2,7 @@ import { getStore } from 'app/store/nanostores/store';
import openBase64ImageInTab from 'common/util/openBase64ImageInTab'; import openBase64ImageInTab from 'common/util/openBase64ImageInTab';
import { blobToDataURL } from 'features/canvas/util/blobToDataURL'; import { blobToDataURL } from 'features/canvas/util/blobToDataURL';
import { selectPromptLayerObjectGroup } from 'features/regionalPrompts/components/LayerComponent'; import { selectPromptLayerObjectGroup } from 'features/regionalPrompts/components/LayerComponent';
import { $stage, REGIONAL_PROMPT_LAYER_NAME } from 'features/regionalPrompts/store/regionalPromptsSlice'; import { getStage, REGIONAL_PROMPT_LAYER_NAME } from 'features/regionalPrompts/store/regionalPromptsSlice';
import Konva from 'konva'; import Konva from 'konva';
import { assert } from 'tsafe'; import { assert } from 'tsafe';
@ -13,8 +13,7 @@ import { assert } from 'tsafe';
*/ */
export const getRegionalPromptLayerBlobs = async (preview: boolean = false): Promise<Record<string, Blob>> => { export const getRegionalPromptLayerBlobs = async (preview: boolean = false): Promise<Record<string, Blob>> => {
const state = getStore().getState(); const state = getStore().getState();
const stage = $stage.get(); const stage = getStage();
assert(stage !== null, 'Stage is null');
// This automatically omits layers that are not rendered. Rendering is controlled by the layer's `isVisible` flag in redux. // This automatically omits layers that are not rendered. Rendering is controlled by the layer's `isVisible` flag in redux.
const regionalPromptLayers = stage.getLayers().filter((l) => l.name() === REGIONAL_PROMPT_LAYER_NAME); const regionalPromptLayers = stage.getLayers().filter((l) => l.name() === REGIONAL_PROMPT_LAYER_NAME);