Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions web/src/lib/components/asset-viewer/asset-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@

const closeEditor = async () => {
if (editManager.hasAppliedEdits) {
console.log(asset);
const refreshedAsset = await getAssetInfo({ id: asset.id });
console.log(refreshedAsset);
onAssetChange?.(refreshedAsset);
assetViewingStore.setAsset(refreshedAsset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<Button
variant="outline"
onclick={() => editManager.resetAllChanges()}
disabled={!editManager.hasChanges}
disabled={!editManager.canReset}
class="self-start"
shape="round"
size="small"
Expand Down
8 changes: 6 additions & 2 deletions web/src/lib/managers/edit/edit-manager.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface EditToolManager {
onDeactivate: () => void;
resetAllChanges: () => Promise<void>;
hasChanges: boolean;
canReset: boolean;
edits: EditAction[];
}

Expand All @@ -41,19 +42,22 @@ export class EditManager {

currentAsset = $state<AssetResponseDto | null>(null);
selectedTool = $state<EditTool | null>(null);
hasChanges = $derived(this.tools.some((t) => t.manager.hasChanges));

// used to disable multiple confirm dialogs and mouse events while one is open
isShowingConfirmDialog = $state(false);
isApplyingEdits = $state(false);
hasAppliedEdits = $state(false);

hasUnsavedChanges = $derived(this.tools.some((t) => t.manager.hasChanges) && !this.hasAppliedEdits);
canReset = $derived(this.tools.some((t) => t.manager.canReset));

async closeConfirm(): Promise<boolean> {
// Prevent multiple dialogs (usually happens with rapid escape key presses)
if (this.isShowingConfirmDialog) {
return false;
}
if (!this.hasChanges || this.hasAppliedEdits) {

if (!this.hasUnsavedChanges) {
return true;
}

Expand Down
21 changes: 15 additions & 6 deletions web/src/lib/managers/edit/transform-manager.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type RegionConvertParams = {
};

class TransformManager implements EditToolManager {
hasChanges: boolean = $derived.by(() => this.checkEdits());
canReset: boolean = $derived.by(() => this.checkEdits());
hasChanges: boolean = $state(false);

darkenLevel = $state(0.65);
isInteracting = $state(false);
Expand All @@ -56,7 +57,7 @@ class TransformManager implements EditToolManager {
cropAspectRatio = $state('free');
originalImageSize = $state<ImageDimensions>({ width: 1000, height: 1000 });
region = $state({ x: 0, y: 0, width: 100, height: 100 });
preveiwImgSize = $derived({
previewImageSize = $derived({
width: this.cropImageSize.width * this.cropImageScale,
height: this.cropImageSize.height * this.cropImageScale,
});
Expand All @@ -73,6 +74,7 @@ class TransformManager implements EditToolManager {
edits = $derived.by(() => this.getEdits());

setAspectRatio(aspectRatio: string) {
this.hasChanges = true;
this.cropAspectRatio = aspectRatio;

if (!this.imgElement || !this.cropAreaEl) {
Expand All @@ -88,8 +90,8 @@ class TransformManager implements EditToolManager {

checkEdits() {
return (
Math.abs(this.preveiwImgSize.width - this.region.width) > 2 ||
Math.abs(this.preveiwImgSize.height - this.region.height) > 2 ||
Math.abs(this.previewImageSize.width - this.region.width) > 2 ||
Math.abs(this.previewImageSize.height - this.region.height) > 2 ||
this.mirrorHorizontal ||
this.mirrorVertical ||
this.normalizedRotation !== 0
Expand All @@ -98,8 +100,8 @@ class TransformManager implements EditToolManager {

checkCropEdits() {
return (
Math.abs(this.preveiwImgSize.width - this.region.width) > 2 ||
Math.abs(this.preveiwImgSize.height - this.region.height) > 2
Math.abs(this.previewImageSize.width - this.region.width) > 2 ||
Math.abs(this.previewImageSize.height - this.region.height) > 2
);
}

Expand Down Expand Up @@ -232,9 +234,12 @@ class TransformManager implements EditToolManager {
this.originalImageSize = { width: 1000, height: 1000 };
this.cropImageScale = 1;
this.cropAspectRatio = 'free';
this.hasChanges = false;
}

mirror(axis: 'horizontal' | 'vertical') {
this.hasChanges = true;

if (this.imageRotation % 180 !== 0) {
axis = axis === 'horizontal' ? 'vertical' : 'horizontal';
}
Expand All @@ -247,6 +252,8 @@ class TransformManager implements EditToolManager {
}

async rotate(angle: number) {
this.hasChanges = true;

this.imageRotation += angle;
await tick();
this.onImageLoad();
Expand Down Expand Up @@ -760,6 +767,7 @@ class TransformManager implements EditToolManager {
return;
}

this.hasChanges = true;
const newX = Math.max(0, Math.min(mouseX - this.dragOffset.x, cropArea.clientWidth - this.region.width));
const newY = Math.max(0, Math.min(mouseY - this.dragOffset.y, cropArea.clientHeight - this.region.height));

Expand All @@ -781,6 +789,7 @@ class TransformManager implements EditToolManager {
}
this.fadeOverlay(false);

this.hasChanges = true;
const { x, y, width, height } = crop;
const minSize = 50;
let newRegion = { ...crop };
Expand Down
Loading