@yogiswara/honcho-editor-ui 1.3.7 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/__tests__/useGallerySwipe.test.d.ts +0 -0
- package/dist/hooks/__tests__/useGallerySwipe.test.js +619 -0
- package/dist/hooks/editor/useHonchoEditor.d.ts +15 -83
- package/dist/hooks/editor/useHonchoEditor.js +362 -316
- package/dist/hooks/useAdjustmentHistory.d.ts +91 -0
- package/dist/hooks/useAdjustmentHistory.demo.d.ts +8 -0
- package/dist/hooks/useAdjustmentHistory.demo.js +106 -0
- package/dist/hooks/useAdjustmentHistory.example.d.ts +33 -0
- package/dist/hooks/useAdjustmentHistory.example.js +150 -0
- package/dist/hooks/useAdjustmentHistory.js +277 -0
- package/dist/hooks/useGallerySwipe.d.ts +36 -0
- package/dist/hooks/useGallerySwipe.example.d.ts +24 -0
- package/dist/hooks/useGallerySwipe.example.js +184 -0
- package/dist/hooks/useGallerySwipe.js +321 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/setupTests.js +1 -0
- package/dist/utils/adjustment.d.ts +5 -0
- package/dist/utils/adjustment.js +32 -0
- package/package.json +11 -2
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
3
3
|
import { HonchoEditor } from '../../lib/editor/honcho-editor';
|
|
4
|
+
import { mapAdjustmentStateToAdjustmentEditor, mapColorAdjustmentToAdjustmentState } from '../../utils/adjustment';
|
|
5
|
+
import { useAdjustmentHistory } from '../useAdjustmentHistory';
|
|
6
|
+
import { useGallerySwipe } from '../useGallerySwipe';
|
|
4
7
|
const initialAdjustments = {
|
|
5
8
|
tempScore: 0, tintScore: 0, vibranceScore: 0, exposureScore: 0, highlightsScore: 0, shadowsScore: 0,
|
|
6
9
|
whitesScore: 0, blacksScore: 0, saturationScore: 0, contrastScore: 0, clarityScore: 0, sharpnessScore: 0,
|
|
@@ -8,6 +11,11 @@ const initialAdjustments = {
|
|
|
8
11
|
const clamp = (value) => Math.max(-100, Math.min(100, value));
|
|
9
12
|
export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
10
13
|
const [currentImageId, setCurrentImageId] = useState(initImageId);
|
|
14
|
+
const [currentImageData, setCurrentImageData] = useState(null);
|
|
15
|
+
const [currentAdjustmentsState, setCurrentAdjustmentsState] = useState(initialAdjustments);
|
|
16
|
+
const { onSwipeNext, onSwipePrev, isNextAvailable, isPrevAvailable, isLoading: isGalleryLoading, error: galleryError, } = useGallerySwipe(firebaseUid, initImageId, controller);
|
|
17
|
+
// The useAdjustmentHistory hook now manages all undo/redo and adjustment state logic.
|
|
18
|
+
const { currentState: currentAdjustmentState, actions: historyActions, historyInfo, config: historyConfig, } = useAdjustmentHistory(initialAdjustments);
|
|
11
19
|
const [currentPage, setCurrentPage] = useState(1);
|
|
12
20
|
const [hasNextPage, setHasNextPage] = useState(true);
|
|
13
21
|
const [isFetchingNextPage, setIsFetchingNextPage] = useState(false);
|
|
@@ -33,18 +41,18 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
33
41
|
const [copyDialogExpanded, setCopyDialogExpanded] = useState({ color: true, light: true, details: true });
|
|
34
42
|
const [adjustmentsMap, setAdjustmentsMap] = useState(new Map());
|
|
35
43
|
// Individual Adjustment State
|
|
36
|
-
const [tempScore, setTempScore] = useState(0);
|
|
37
|
-
const [tintScore, setTintScore] = useState(0);
|
|
38
|
-
const [vibranceScore, setVibranceScore] = useState(0);
|
|
39
|
-
const [saturationScore, setSaturationScore] = useState(0);
|
|
40
|
-
const [exposureScore, setExposureScore] = useState(0);
|
|
41
|
-
const [highlightsScore, setHighlightsScore] = useState(0);
|
|
42
|
-
const [shadowsScore, setShadowsScore] = useState(0);
|
|
43
|
-
const [whitesScore, setWhitesScore] = useState(0);
|
|
44
|
-
const [blacksScore, setBlacksScore] = useState(0);
|
|
45
|
-
const [contrastScore, setContrastScore] = useState(0);
|
|
46
|
-
const [clarityScore, setClarityScore] = useState(0);
|
|
47
|
-
const [sharpnessScore, setSharpnessScore] = useState(0);
|
|
44
|
+
// const [tempScore, setTempScore] = useState(0);
|
|
45
|
+
// const [tintScore, setTintScore] = useState(0);
|
|
46
|
+
// const [vibranceScore, setVibranceScore] = useState(0);
|
|
47
|
+
// const [saturationScore, setSaturationScore] = useState(0);
|
|
48
|
+
// const [exposureScore, setExposureScore] = useState(0);
|
|
49
|
+
// const [highlightsScore, setHighlightsScore] = useState(0);
|
|
50
|
+
// const [shadowsScore, setShadowsScore] = useState(0);
|
|
51
|
+
// const [whitesScore, setWhitesScore] = useState(0);
|
|
52
|
+
// const [blacksScore, setBlacksScore] = useState(0);
|
|
53
|
+
// const [contrastScore, setContrastScore] = useState(0);
|
|
54
|
+
// const [clarityScore, setClarityScore] = useState(0);
|
|
55
|
+
// const [sharpnessScore, setSharpnessScore] = useState(0);
|
|
48
56
|
// MARK: - UI & App State (Moved from page.tsx)
|
|
49
57
|
// General UI State
|
|
50
58
|
const [isOnline, setIsOnline] = useState(true);
|
|
@@ -162,9 +170,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
162
170
|
}
|
|
163
171
|
}, [ /* handleOpenCopyDialog dependency */]);
|
|
164
172
|
useEffect(() => {
|
|
165
|
-
if (editorRef.current?.getInitialized() === false) {
|
|
166
|
-
editorRef.current?.initialize();
|
|
167
|
-
}
|
|
168
173
|
}, [editorRef]);
|
|
169
174
|
// Effect for measuring mobile panel content
|
|
170
175
|
useEffect(() => {
|
|
@@ -221,22 +226,24 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
221
226
|
};
|
|
222
227
|
}, []);
|
|
223
228
|
// MARK: - Core Editor Logic
|
|
224
|
-
const
|
|
225
|
-
|
|
229
|
+
const { tempScore, tintScore, vibranceScore, saturationScore, exposureScore, highlightsScore, shadowsScore, whitesScore, blacksScore, contrastScore, clarityScore, sharpnessScore } = currentAdjustmentsState;
|
|
230
|
+
const updateCanvasEditor = useCallback(() => {
|
|
231
|
+
if ((editorRef.current?.getInitialized() === true) && canvasRef.current) {
|
|
226
232
|
editorRef.current.processImage();
|
|
227
233
|
editorRef.current.renderToCanvas(canvasRef.current);
|
|
228
234
|
}
|
|
229
|
-
}, []);
|
|
235
|
+
}, [canvasRef.current, editorRef.current]);
|
|
230
236
|
const loadImage = useCallback(async (file) => {
|
|
231
237
|
if (!editorRef.current) {
|
|
232
238
|
setEditorStatus("Editor not ready.");
|
|
233
239
|
return;
|
|
234
240
|
}
|
|
235
241
|
setEditorStatus("Loading image...");
|
|
242
|
+
// TODO move
|
|
236
243
|
try {
|
|
237
244
|
await editorRef.current.loadImageFromFile(file);
|
|
238
245
|
setIsImageLoaded(true);
|
|
239
|
-
|
|
246
|
+
updateCanvasEditor();
|
|
240
247
|
}
|
|
241
248
|
catch (e) {
|
|
242
249
|
console.error("Error loading image:", e);
|
|
@@ -293,6 +300,62 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
293
300
|
setEditorStatus("Error: Could not fetch the image.");
|
|
294
301
|
}
|
|
295
302
|
}, [controller, loadImageFromUrl]);
|
|
303
|
+
const updateAdjustments = useCallback((newValues) => {
|
|
304
|
+
// In batch mode (like dragging a slider), this only updates the UI.
|
|
305
|
+
// When not in batch mode (or when the slider drag ends), it creates a history entry.
|
|
306
|
+
const newState = { ...currentAdjustmentsState, ...newValues };
|
|
307
|
+
historyActions.pushState(newState);
|
|
308
|
+
}, [currentAdjustmentsState, historyActions]);
|
|
309
|
+
const getImageFromId = useCallback(async (firebaseUid, imageId) => {
|
|
310
|
+
if (!controller)
|
|
311
|
+
return;
|
|
312
|
+
setEditorStatus("Fetching image...");
|
|
313
|
+
try {
|
|
314
|
+
const gallery = await controller.onGetImage(firebaseUid, imageId);
|
|
315
|
+
const imagePath = gallery?.raw_edited?.path
|
|
316
|
+
? gallery.raw_edited.path
|
|
317
|
+
: gallery?.download?.path;
|
|
318
|
+
console.log("[DEBUG] Extracted imagePath to load:", imagePath);
|
|
319
|
+
if (imagePath) {
|
|
320
|
+
return gallery; // ✅ RETURN the gallery object on success
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
throw new Error("Controller did not return a valid image object with path.");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
console.error("Failed to fetch or load image via controller:", error);
|
|
328
|
+
setEditorStatus("Error: Could not fetch the image.");
|
|
329
|
+
}
|
|
330
|
+
}, [controller]);
|
|
331
|
+
const extractPathFromGallery = useCallback((data) => {
|
|
332
|
+
const imagePath = data?.raw_edited?.path
|
|
333
|
+
? data.raw_edited.path
|
|
334
|
+
: data?.download?.path;
|
|
335
|
+
console.log("[DEBUG] Extracted imagePath to load:", imagePath);
|
|
336
|
+
return imagePath;
|
|
337
|
+
}, []);
|
|
338
|
+
const loadImageEditorFromUrl = useCallback(async (url) => {
|
|
339
|
+
try {
|
|
340
|
+
if (!editorRef.current)
|
|
341
|
+
return;
|
|
342
|
+
setEditorStatus("Downloading image...");
|
|
343
|
+
console.log(`[DEBUG] Attempting to fetch image from URL: ${url}`);
|
|
344
|
+
const response = await fetch(url);
|
|
345
|
+
if (!response.ok)
|
|
346
|
+
throw new Error(`Failed to fetch image from URL: ${url}`);
|
|
347
|
+
const blob = await response.blob();
|
|
348
|
+
const filename = url.substring(url.lastIndexOf('/') + 1) || 'image.jpg';
|
|
349
|
+
const file = new File([blob], filename, { type: blob.type });
|
|
350
|
+
await editorRef.current.loadImageFromFile(file);
|
|
351
|
+
setIsImageLoaded(true);
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
console.error(error);
|
|
355
|
+
setEditorStatus("Error: Could not load image from URL.");
|
|
356
|
+
setIsImageLoaded(false);
|
|
357
|
+
}
|
|
358
|
+
}, [editorRef.current]);
|
|
296
359
|
const handlePrev = useCallback(async (firebaseUid) => {
|
|
297
360
|
console.log("[DEBUG] handlePrev function was called.");
|
|
298
361
|
// Find the current image index
|
|
@@ -356,31 +419,11 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
356
419
|
imageList, currentImageId, hasNextPage,
|
|
357
420
|
isFetchingNextPage, currentPage, controller, firebaseUid, eventId
|
|
358
421
|
]);
|
|
359
|
-
useEffect(() => {
|
|
360
|
-
// This is now the single point of control for loading an image based on the initial props.
|
|
361
|
-
// 1. First, check if all conditions are met to even attempt loading.
|
|
362
|
-
// We ensure the editor itself is ready before doing anything.
|
|
363
|
-
const canLoad = initImageId && firebaseUid && controller && isEditorReady;
|
|
364
|
-
if (!canLoad) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
// 2. Define the loading sequence as an async function inside the effect.
|
|
368
|
-
const loadInitialImage = async () => {
|
|
369
|
-
console.log(`[EFFECT] Starting to load initial image ID: ${initImageId}`);
|
|
370
|
-
// This directly calls the loading function. We don't need to set
|
|
371
|
-
// an intermediate 'currentImageId' state, which avoids an extra re-render and potential loop.
|
|
372
|
-
await loadImageFromId(firebaseUid, initImageId);
|
|
373
|
-
};
|
|
374
|
-
// 3. Execute the loading sequence.
|
|
375
|
-
loadInitialImage();
|
|
376
|
-
// Dependencies: The external props and readiness flags that trigger this logic.
|
|
377
|
-
// Whenever any of these change, this effect will re-evaluate.
|
|
378
|
-
}, [initImageId, firebaseUid, controller, isEditorReady, loadImageFromId]);
|
|
379
422
|
useEffect(() => {
|
|
380
423
|
const initialize = async () => {
|
|
381
|
-
if (
|
|
382
|
-
console.log(`[INIT] Starting sequence for image: ${
|
|
383
|
-
const initialGallery = await loadImageFromId(firebaseUid,
|
|
424
|
+
if (currentImageId && firebaseUid && controller && isEditorReady) {
|
|
425
|
+
console.log(`[INIT] Starting sequence for image: ${currentImageId}`);
|
|
426
|
+
const initialGallery = await loadImageFromId(firebaseUid, currentImageId);
|
|
384
427
|
// ✅ ADD THIS BLOCK TO CHECK THE DATA
|
|
385
428
|
console.group("[DEBUG] Checking Initial Gallery Data");
|
|
386
429
|
if (initialGallery) {
|
|
@@ -414,20 +457,19 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
414
457
|
}
|
|
415
458
|
};
|
|
416
459
|
initialize();
|
|
417
|
-
}, [
|
|
418
|
-
useEffect(() => {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}, [currentImageId, isEditorReady]);
|
|
460
|
+
}, [currentImageId, firebaseUid, controller, isEditorReady, loadImageFromId]);
|
|
461
|
+
// useEffect(() => {
|
|
462
|
+
// // Ensure we have everything needed before trying to load.
|
|
463
|
+
// if (currentImageId && firebaseUid && controller && isEditorReady) {
|
|
464
|
+
// console.log(`[EFFECT] currentImageId changed to: ${currentImageId}. Loading new image into canvas.`);
|
|
465
|
+
// // Load the new image specified by the updated currentImageId
|
|
466
|
+
// loadImageFromId(firebaseUid, currentImageId);
|
|
467
|
+
// }
|
|
468
|
+
// }, [currentImageId, isEditorReady]);
|
|
426
469
|
const handleFileChange = (event) => {
|
|
427
470
|
const files = event.target?.files;
|
|
428
471
|
if (!files || files.length === 0)
|
|
429
472
|
return;
|
|
430
|
-
applyAdjustmentState(initialAdjustments);
|
|
431
473
|
setHistory([initialAdjustments]);
|
|
432
474
|
setHistoryIndex(0);
|
|
433
475
|
if (files.length === 1) {
|
|
@@ -455,47 +497,47 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
455
497
|
setSelectedImageIds(new Set(newImageList.map(img => img.id)));
|
|
456
498
|
}
|
|
457
499
|
};
|
|
458
|
-
const applyAdjustmentState = useCallback((state) => {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}, [isBulkEditing, applyUiStateToSelectedImages]);
|
|
477
|
-
const handleRevert = useCallback(() => {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}, [applyAdjustmentState, isBulkEditing]);
|
|
485
|
-
const handleUndo = useCallback(() => {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
}, [history, historyIndex, applyAdjustmentState]);
|
|
492
|
-
const handleRedo = useCallback(() => {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}, [history, historyIndex, applyAdjustmentState]);
|
|
500
|
+
// const applyAdjustmentState = useCallback((state: AdjustmentState) => {
|
|
501
|
+
// // Always update the UI controls
|
|
502
|
+
// setTempScore(state.tempScore);
|
|
503
|
+
// setTintScore(state.tintScore);
|
|
504
|
+
// setVibranceScore(state.vibranceScore);
|
|
505
|
+
// setExposureScore(state.exposureScore);
|
|
506
|
+
// setHighlightsScore(state.highlightsScore);
|
|
507
|
+
// setShadowsScore(state.shadowsScore);
|
|
508
|
+
// setWhitesScore(state.whitesScore);
|
|
509
|
+
// setBlacksScore(state.blacksScore);
|
|
510
|
+
// setSaturationScore(state.saturationScore);
|
|
511
|
+
// setContrastScore(state.contrastScore);
|
|
512
|
+
// setClarityScore(state.clarityScore);
|
|
513
|
+
// setSharpnessScore(state.sharpnessScore);
|
|
514
|
+
// // If in bulk mode, apply this state to all selected images
|
|
515
|
+
// if (isBulkEditing) {
|
|
516
|
+
// applyUiStateToSelectedImages(state);
|
|
517
|
+
// }
|
|
518
|
+
// }, [isBulkEditing, applyUiStateToSelectedImages]);
|
|
519
|
+
// const handleRevert = useCallback(() => {
|
|
520
|
+
// // This will reset the UI controls and, if in bulk mode, the selected images
|
|
521
|
+
// applyAdjustmentState(initialAdjustments);
|
|
522
|
+
// // For single image mode, also reset the underlying canvas engine
|
|
523
|
+
// if (!isBulkEditing && editorRef.current) {
|
|
524
|
+
// editorRef.current.resetAdjustments();
|
|
525
|
+
// }
|
|
526
|
+
// }, [applyAdjustmentState, isBulkEditing]);
|
|
527
|
+
// const handleUndo = useCallback(() => {
|
|
528
|
+
// if (historyIndex > 0) {
|
|
529
|
+
// const prevIndex = historyIndex - 1;
|
|
530
|
+
// applyAdjustmentState(history[prevIndex]);
|
|
531
|
+
// setHistoryIndex(prevIndex);
|
|
532
|
+
// }
|
|
533
|
+
// }, [history, historyIndex, applyAdjustmentState]);
|
|
534
|
+
// const handleRedo = useCallback(() => {
|
|
535
|
+
// if (historyIndex < history.length - 1) {
|
|
536
|
+
// const nextIndex = historyIndex + 1;
|
|
537
|
+
// applyAdjustmentState(history[nextIndex]);
|
|
538
|
+
// setHistoryIndex(nextIndex);
|
|
539
|
+
// }
|
|
540
|
+
// }, [history, historyIndex, applyAdjustmentState]);
|
|
499
541
|
const handleToggleImageSelection = useCallback((imageId) => {
|
|
500
542
|
const newSelectedIds = new Set(selectedImageIds);
|
|
501
543
|
const isCurrentlySelected = newSelectedIds.has(imageId);
|
|
@@ -549,67 +591,67 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
549
591
|
});
|
|
550
592
|
}
|
|
551
593
|
};
|
|
552
|
-
const setTempScoreAbs = createAbsoluteSetter('tempScore', setTempScore);
|
|
553
|
-
const setTintScoreAbs = createAbsoluteSetter('tintScore', setTintScore);
|
|
554
|
-
const setVibranceScoreAbs = createAbsoluteSetter('vibranceScore', setVibranceScore);
|
|
555
|
-
const setSaturationScoreAbs = createAbsoluteSetter('saturationScore', setSaturationScore);
|
|
556
|
-
const setExposureScoreAbs = createAbsoluteSetter('exposureScore', setExposureScore);
|
|
557
|
-
const setHighlightsScoreAbs = createAbsoluteSetter('highlightsScore', setHighlightsScore);
|
|
558
|
-
const setShadowsScoreAbs = createAbsoluteSetter('shadowsScore', setShadowsScore);
|
|
559
|
-
const setWhitesScoreAbs = createAbsoluteSetter('whitesScore', setWhitesScore);
|
|
560
|
-
const setBlacksScoreAbs = createAbsoluteSetter('blacksScore', setBlacksScore);
|
|
561
|
-
const setContrastScoreAbs = createAbsoluteSetter('contrastScore', setContrastScore);
|
|
562
|
-
const setClarityScoreAbs = createAbsoluteSetter('clarityScore', setClarityScore);
|
|
563
|
-
const setSharpnessScoreAbs = createAbsoluteSetter('sharpnessScore', setSharpnessScore);
|
|
564
|
-
// MARK: - Bulk Editor Handlers
|
|
565
|
-
const handleBulkTempDecreaseMax = createRelativeAdjuster('tempScore', setTempScore, -20);
|
|
566
|
-
const handleBulkTempDecrease = createRelativeAdjuster('tempScore', setTempScore, -5);
|
|
567
|
-
const handleBulkTempIncrease = createRelativeAdjuster('tempScore', setTempScore, 5);
|
|
568
|
-
const handleBulkTempIncreaseMax = createRelativeAdjuster('tempScore', setTempScore, 20);
|
|
569
|
-
const handleBulkTintDecreaseMax = createRelativeAdjuster('tintScore', setTintScore, -20);
|
|
570
|
-
const handleBulkTintDecrease = createRelativeAdjuster('tintScore', setTintScore, -5);
|
|
571
|
-
const handleBulkTintIncrease = createRelativeAdjuster('tintScore', setTintScore, 5);
|
|
572
|
-
const handleBulkTintIncreaseMax = createRelativeAdjuster('tintScore', setTintScore, 20);
|
|
573
|
-
const handleBulkVibranceDecreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, -20);
|
|
574
|
-
const handleBulkVibranceDecrease = createRelativeAdjuster('vibranceScore', setVibranceScore, -5);
|
|
575
|
-
const handleBulkVibranceIncrease = createRelativeAdjuster('vibranceScore', setVibranceScore, 5);
|
|
576
|
-
const handleBulkVibranceIncreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, 20);
|
|
577
|
-
const handleBulkSaturationDecreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, -20);
|
|
578
|
-
const handleBulkSaturationDecrease = createRelativeAdjuster('saturationScore', setSaturationScore, -5);
|
|
579
|
-
const handleBulkSaturationIncrease = createRelativeAdjuster('saturationScore', setSaturationScore, 5);
|
|
580
|
-
const handleBulkSaturationIncreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, 20);
|
|
581
|
-
const handleBulkExposureDecreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, -20);
|
|
582
|
-
const handleBulkExposureDecrease = createRelativeAdjuster('exposureScore', setExposureScore, -5);
|
|
583
|
-
const handleBulkExposureIncrease = createRelativeAdjuster('exposureScore', setExposureScore, 5);
|
|
584
|
-
const handleBulkExposureIncreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, 20);
|
|
585
|
-
const handleBulkContrastDecreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, -20);
|
|
586
|
-
const handleBulkContrastDecrease = createRelativeAdjuster('contrastScore', setContrastScore, -5);
|
|
587
|
-
const handleBulkContrastIncrease = createRelativeAdjuster('contrastScore', setContrastScore, 5);
|
|
588
|
-
const handleBulkContrastIncreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, 20);
|
|
589
|
-
const handleBulkHighlightsDecreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, -20);
|
|
590
|
-
const handleBulkHighlightsDecrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, -5);
|
|
591
|
-
const handleBulkHighlightsIncrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, 5);
|
|
592
|
-
const handleBulkHighlightsIncreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, 20);
|
|
593
|
-
const handleBulkShadowsDecreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, -20);
|
|
594
|
-
const handleBulkShadowsDecrease = createRelativeAdjuster('shadowsScore', setShadowsScore, -5);
|
|
595
|
-
const handleBulkShadowsIncrease = createRelativeAdjuster('shadowsScore', setShadowsScore, 5);
|
|
596
|
-
const handleBulkShadowsIncreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, 20);
|
|
597
|
-
const handleBulkWhitesDecreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, -20);
|
|
598
|
-
const handleBulkWhitesDecrease = createRelativeAdjuster('whitesScore', setWhitesScore, -5);
|
|
599
|
-
const handleBulkWhitesIncrease = createRelativeAdjuster('whitesScore', setWhitesScore, 5);
|
|
600
|
-
const handleBulkWhitesIncreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, 20);
|
|
601
|
-
const handleBulkBlacksDecreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, -20);
|
|
602
|
-
const handleBulkBlacksDecrease = createRelativeAdjuster('blacksScore', setBlacksScore, -5);
|
|
603
|
-
const handleBulkBlacksIncrease = createRelativeAdjuster('blacksScore', setBlacksScore, 5);
|
|
604
|
-
const handleBulkBlacksIncreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, 20);
|
|
605
|
-
const handleBulkClarityDecreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, -20);
|
|
606
|
-
const handleBulkClarityDecrease = createRelativeAdjuster('clarityScore', setClarityScore, -5);
|
|
607
|
-
const handleBulkClarityIncrease = createRelativeAdjuster('clarityScore', setClarityScore, 5);
|
|
608
|
-
const handleBulkClarityIncreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, 20);
|
|
609
|
-
const handleBulkSharpnessDecreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -20);
|
|
610
|
-
const handleBulkSharpnessDecrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -5);
|
|
611
|
-
const handleBulkSharpnessIncrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 5);
|
|
612
|
-
const handleBulkSharpnessIncreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 20);
|
|
594
|
+
// const setTempScoreAbs = createAbsoluteSetter('tempScore', setTempScore);
|
|
595
|
+
// const setTintScoreAbs = createAbsoluteSetter('tintScore', setTintScore);
|
|
596
|
+
// const setVibranceScoreAbs = createAbsoluteSetter('vibranceScore', setVibranceScore);
|
|
597
|
+
// const setSaturationScoreAbs = createAbsoluteSetter('saturationScore', setSaturationScore);
|
|
598
|
+
// const setExposureScoreAbs = createAbsoluteSetter('exposureScore', setExposureScore);
|
|
599
|
+
// const setHighlightsScoreAbs = createAbsoluteSetter('highlightsScore', setHighlightsScore);
|
|
600
|
+
// const setShadowsScoreAbs = createAbsoluteSetter('shadowsScore', setShadowsScore);
|
|
601
|
+
// const setWhitesScoreAbs = createAbsoluteSetter('whitesScore', setWhitesScore);
|
|
602
|
+
// const setBlacksScoreAbs = createAbsoluteSetter('blacksScore', setBlacksScore);
|
|
603
|
+
// const setContrastScoreAbs = createAbsoluteSetter('contrastScore', setContrastScore);
|
|
604
|
+
// const setClarityScoreAbs = createAbsoluteSetter('clarityScore', setClarityScore);
|
|
605
|
+
// const setSharpnessScoreAbs = createAbsoluteSetter('sharpnessScore', setSharpnessScore);
|
|
606
|
+
// // MARK: - Bulk Editor Handlers
|
|
607
|
+
// const handleBulkTempDecreaseMax = createRelativeAdjuster('tempScore', setTempScore, -20);
|
|
608
|
+
// const handleBulkTempDecrease = createRelativeAdjuster('tempScore', setTempScore, -5);
|
|
609
|
+
// const handleBulkTempIncrease = createRelativeAdjuster('tempScore', setTempScore, 5);
|
|
610
|
+
// const handleBulkTempIncreaseMax = createRelativeAdjuster('tempScore', setTempScore, 20);
|
|
611
|
+
// const handleBulkTintDecreaseMax = createRelativeAdjuster('tintScore', setTintScore, -20);
|
|
612
|
+
// const handleBulkTintDecrease = createRelativeAdjuster('tintScore', setTintScore, -5);
|
|
613
|
+
// const handleBulkTintIncrease = createRelativeAdjuster('tintScore', setTintScore, 5);
|
|
614
|
+
// const handleBulkTintIncreaseMax = createRelativeAdjuster('tintScore', setTintScore, 20);
|
|
615
|
+
// const handleBulkVibranceDecreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, -20);
|
|
616
|
+
// const handleBulkVibranceDecrease = createRelativeAdjuster('vibranceScore', setVibranceScore, -5);
|
|
617
|
+
// const handleBulkVibranceIncrease = createRelativeAdjuster('vibranceScore', setVibranceScore, 5);
|
|
618
|
+
// const handleBulkVibranceIncreaseMax = createRelativeAdjuster('vibranceScore', setVibranceScore, 20);
|
|
619
|
+
// const handleBulkSaturationDecreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, -20);
|
|
620
|
+
// const handleBulkSaturationDecrease = createRelativeAdjuster('saturationScore', setSaturationScore, -5);
|
|
621
|
+
// const handleBulkSaturationIncrease = createRelativeAdjuster('saturationScore', setSaturationScore, 5);
|
|
622
|
+
// const handleBulkSaturationIncreaseMax = createRelativeAdjuster('saturationScore', setSaturationScore, 20);
|
|
623
|
+
// const handleBulkExposureDecreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, -20);
|
|
624
|
+
// const handleBulkExposureDecrease = createRelativeAdjuster('exposureScore', setExposureScore, -5);
|
|
625
|
+
// const handleBulkExposureIncrease = createRelativeAdjuster('exposureScore', setExposureScore, 5);
|
|
626
|
+
// const handleBulkExposureIncreaseMax = createRelativeAdjuster('exposureScore', setExposureScore, 20);
|
|
627
|
+
// const handleBulkContrastDecreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, -20);
|
|
628
|
+
// const handleBulkContrastDecrease = createRelativeAdjuster('contrastScore', setContrastScore, -5);
|
|
629
|
+
// const handleBulkContrastIncrease = createRelativeAdjuster('contrastScore', setContrastScore, 5);
|
|
630
|
+
// const handleBulkContrastIncreaseMax = createRelativeAdjuster('contrastScore', setContrastScore, 20);
|
|
631
|
+
// const handleBulkHighlightsDecreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, -20);
|
|
632
|
+
// const handleBulkHighlightsDecrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, -5);
|
|
633
|
+
// const handleBulkHighlightsIncrease = createRelativeAdjuster('highlightsScore', setHighlightsScore, 5);
|
|
634
|
+
// const handleBulkHighlightsIncreaseMax = createRelativeAdjuster('highlightsScore', setHighlightsScore, 20);
|
|
635
|
+
// const handleBulkShadowsDecreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, -20);
|
|
636
|
+
// const handleBulkShadowsDecrease = createRelativeAdjuster('shadowsScore', setShadowsScore, -5);
|
|
637
|
+
// const handleBulkShadowsIncrease = createRelativeAdjuster('shadowsScore', setShadowsScore, 5);
|
|
638
|
+
// const handleBulkShadowsIncreaseMax = createRelativeAdjuster('shadowsScore', setShadowsScore, 20);
|
|
639
|
+
// const handleBulkWhitesDecreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, -20);
|
|
640
|
+
// const handleBulkWhitesDecrease = createRelativeAdjuster('whitesScore', setWhitesScore, -5);
|
|
641
|
+
// const handleBulkWhitesIncrease = createRelativeAdjuster('whitesScore', setWhitesScore, 5);
|
|
642
|
+
// const handleBulkWhitesIncreaseMax = createRelativeAdjuster('whitesScore', setWhitesScore, 20);
|
|
643
|
+
// const handleBulkBlacksDecreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, -20);
|
|
644
|
+
// const handleBulkBlacksDecrease = createRelativeAdjuster('blacksScore', setBlacksScore, -5);
|
|
645
|
+
// const handleBulkBlacksIncrease = createRelativeAdjuster('blacksScore', setBlacksScore, 5);
|
|
646
|
+
// const handleBulkBlacksIncreaseMax = createRelativeAdjuster('blacksScore', setBlacksScore, 20);
|
|
647
|
+
// const handleBulkClarityDecreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, -20);
|
|
648
|
+
// const handleBulkClarityDecrease = createRelativeAdjuster('clarityScore', setClarityScore, -5);
|
|
649
|
+
// const handleBulkClarityIncrease = createRelativeAdjuster('clarityScore', setClarityScore, 5);
|
|
650
|
+
// const handleBulkClarityIncreaseMax = createRelativeAdjuster('clarityScore', setClarityScore, 20);
|
|
651
|
+
// const handleBulkSharpnessDecreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -20);
|
|
652
|
+
// const handleBulkSharpnessDecrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, -5);
|
|
653
|
+
// const handleBulkSharpnessIncrease = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 5);
|
|
654
|
+
// const handleBulkSharpnessIncreaseMax = createRelativeAdjuster('sharpnessScore', setSharpnessScore, 20);
|
|
613
655
|
const handleScriptReady = useCallback(async () => {
|
|
614
656
|
console.log("[Editor] Script tag is ready."); // Log entry
|
|
615
657
|
if (typeof window.Module === 'function' && !editorRef.current) {
|
|
@@ -731,11 +773,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
731
773
|
highlightsScore, shadowsScore, whitesScore, blacksScore, clarityScore, sharpnessScore
|
|
732
774
|
]);
|
|
733
775
|
const handleConfirmCopy = () => { handleCopyEdit(); handleCloseCopyDialog(); setShowCopyAlert(true); };
|
|
734
|
-
const handlePasteEdit = useCallback(() => {
|
|
735
|
-
if (copiedAdjustments) {
|
|
736
|
-
applyAdjustmentState(copiedAdjustments);
|
|
737
|
-
}
|
|
738
|
-
}, [copiedAdjustments, applyAdjustmentState]);
|
|
739
776
|
// Panel Handlers
|
|
740
777
|
const handleColorAccordionChange = (panel) => (_, isExpanded) => {
|
|
741
778
|
setColorAdjustmentExpandedPanels(prev => isExpanded ? [...new Set([...prev, panel])] : prev.filter(p => p !== panel));
|
|
@@ -745,17 +782,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
745
782
|
};
|
|
746
783
|
// MARK: - Preset Handlers
|
|
747
784
|
// Also it calls for the backend endpoint
|
|
748
|
-
const fetchPresets = useCallback(async () => {
|
|
749
|
-
if (!controller)
|
|
750
|
-
return;
|
|
751
|
-
try {
|
|
752
|
-
const fetchedPresets = await controller.getPresets(firebaseUid);
|
|
753
|
-
setPresets(fetchedPresets);
|
|
754
|
-
}
|
|
755
|
-
catch (error) {
|
|
756
|
-
console.error("Failed to fetch presets:", error);
|
|
757
|
-
}
|
|
758
|
-
}, [controller]);
|
|
759
785
|
const handleSelectMobilePreset = (presetId) => setSelectedMobilePreset(presetId);
|
|
760
786
|
const handleSelectDesktopPreset = (presetId) => setSelectedDesktopPreset(presetId);
|
|
761
787
|
const handlePresetMenuClick = (event, presetId) => {
|
|
@@ -850,8 +876,8 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
850
876
|
// 1. Set the flag to true to pause history recording
|
|
851
877
|
setIsViewingOriginal(true);
|
|
852
878
|
// 2. Apply the initial state to the view
|
|
853
|
-
applyAdjustmentState(initialAdjustments);
|
|
854
|
-
}, [isImageLoaded
|
|
879
|
+
// applyAdjustmentState(initialAdjustments);
|
|
880
|
+
}, [isImageLoaded]);
|
|
855
881
|
const handleShowEdited = useCallback(() => {
|
|
856
882
|
if (!editorRef.current || !isImageLoaded)
|
|
857
883
|
return;
|
|
@@ -859,12 +885,12 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
859
885
|
const latestState = history[historyIndex];
|
|
860
886
|
if (latestState) {
|
|
861
887
|
// 3. Re-apply the latest state from history
|
|
862
|
-
applyAdjustmentState(latestState);
|
|
888
|
+
// applyAdjustmentState(latestState);
|
|
863
889
|
}
|
|
864
890
|
// 4. Set the flag back to false AFTER the state has been restored.
|
|
865
891
|
// A small timeout ensures this runs after the re-render.
|
|
866
892
|
setTimeout(() => setIsViewingOriginal(false), 0);
|
|
867
|
-
}, [isImageLoaded, history, historyIndex
|
|
893
|
+
}, [isImageLoaded, history, historyIndex]);
|
|
868
894
|
// MARK: - Zoom Handlers
|
|
869
895
|
const handleZoomAction = useCallback((action) => {
|
|
870
896
|
let newZoom = zoomLevel;
|
|
@@ -905,76 +931,19 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
905
931
|
}
|
|
906
932
|
setZoomLevel(Math.max(0.1, Math.min(newZoom, 8)));
|
|
907
933
|
}, [zoomLevel, isImageLoaded]);
|
|
908
|
-
useEffect(() => {
|
|
909
|
-
if (canvasRef.current) {
|
|
910
|
-
canvasRef.current.style.transition = 'transform 0.1s ease-out';
|
|
911
|
-
canvasRef.current.style.transform = `scale(${zoomLevel})`;
|
|
912
|
-
}
|
|
913
|
-
}, [zoomLevel]);
|
|
914
|
-
// MARK: - Effects
|
|
915
|
-
// Preset Image List
|
|
916
|
-
useEffect(() => {
|
|
917
|
-
fetchPresets();
|
|
918
|
-
}, [controller, fetchPresets]);
|
|
919
|
-
// Image Load
|
|
920
|
-
useEffect(() => {
|
|
921
|
-
if (isImageLoaded && editorRef.current && canvasRef.current) {
|
|
922
|
-
const { width, height } = editorRef.current.getImageSize();
|
|
923
|
-
canvasRef.current.width = width;
|
|
924
|
-
canvasRef.current.height = height;
|
|
925
|
-
updateCanvas();
|
|
926
|
-
setEditorStatus("Image loaded successfully!");
|
|
927
|
-
}
|
|
928
|
-
}, [isImageLoaded, updateCanvas]);
|
|
929
934
|
// Adjustment USE EFFECTS
|
|
930
|
-
useEffect(() => { if (isImageLoaded) {
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
} }, [
|
|
934
|
-
useEffect(() => { if (isImageLoaded) {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
} }, [
|
|
938
|
-
useEffect(() => { if (isImageLoaded) {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
} }, [
|
|
942
|
-
useEffect(() => { if (isImageLoaded) {
|
|
943
|
-
editorRef.current?.setHighlights(highlightsScore);
|
|
944
|
-
updateCanvas();
|
|
945
|
-
} }, [highlightsScore, isImageLoaded, updateCanvas]);
|
|
946
|
-
useEffect(() => { if (isImageLoaded) {
|
|
947
|
-
editorRef.current?.setShadows(shadowsScore);
|
|
948
|
-
updateCanvas();
|
|
949
|
-
} }, [shadowsScore, isImageLoaded, updateCanvas]);
|
|
950
|
-
useEffect(() => { if (isImageLoaded) {
|
|
951
|
-
editorRef.current?.setSaturation(saturationScore);
|
|
952
|
-
updateCanvas();
|
|
953
|
-
} }, [saturationScore, isImageLoaded, updateCanvas]);
|
|
954
|
-
useEffect(() => { if (isImageLoaded) {
|
|
955
|
-
editorRef.current?.setTemperature(tempScore);
|
|
956
|
-
updateCanvas();
|
|
957
|
-
} }, [tempScore, isImageLoaded, updateCanvas]);
|
|
958
|
-
useEffect(() => { if (isImageLoaded) {
|
|
959
|
-
editorRef.current?.setTint(tintScore);
|
|
960
|
-
updateCanvas();
|
|
961
|
-
} }, [tintScore, isImageLoaded, updateCanvas]);
|
|
962
|
-
useEffect(() => { if (isImageLoaded) {
|
|
963
|
-
editorRef.current?.setBlacks(blacksScore);
|
|
964
|
-
updateCanvas();
|
|
965
|
-
} }, [blacksScore, isImageLoaded, updateCanvas]);
|
|
966
|
-
useEffect(() => { if (isImageLoaded) {
|
|
967
|
-
editorRef.current?.setWhites(whitesScore);
|
|
968
|
-
updateCanvas();
|
|
969
|
-
} }, [whitesScore, isImageLoaded, updateCanvas]);
|
|
970
|
-
useEffect(() => { if (isImageLoaded) {
|
|
971
|
-
editorRef.current?.setClarity(clarityScore);
|
|
972
|
-
updateCanvas();
|
|
973
|
-
} }, [clarityScore, isImageLoaded, updateCanvas]);
|
|
974
|
-
useEffect(() => { if (isImageLoaded) {
|
|
975
|
-
editorRef.current?.setSharpness(sharpnessScore);
|
|
976
|
-
updateCanvas();
|
|
977
|
-
} }, [sharpnessScore, isImageLoaded, updateCanvas]);
|
|
935
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setExposure(exposureScore); updateCanvas(); } }, [exposureScore, isImageLoaded, updateCanvas]);
|
|
936
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setVibrance(vibranceScore); updateCanvas(); } }, [vibranceScore, isImageLoaded, updateCanvas]);
|
|
937
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setContrast(contrastScore); updateCanvas(); } }, [contrastScore, isImageLoaded, updateCanvas]);
|
|
938
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setHighlights(highlightsScore); updateCanvas(); } }, [highlightsScore, isImageLoaded, updateCanvas]);
|
|
939
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setShadows(shadowsScore); updateCanvas(); } }, [shadowsScore, isImageLoaded, updateCanvas]);
|
|
940
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setSaturation(saturationScore); updateCanvas(); } }, [saturationScore, isImageLoaded, updateCanvas]);
|
|
941
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setTemperature(tempScore); updateCanvas(); } }, [tempScore, isImageLoaded, updateCanvas]);
|
|
942
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setTint(tintScore); updateCanvas(); } }, [tintScore, isImageLoaded, updateCanvas]);
|
|
943
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setBlacks(blacksScore); updateCanvas(); } }, [blacksScore, isImageLoaded, updateCanvas]);
|
|
944
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setWhites(whitesScore); updateCanvas(); } }, [whitesScore, isImageLoaded, updateCanvas]);
|
|
945
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setClarity(clarityScore); updateCanvas(); } }, [clarityScore, isImageLoaded, updateCanvas]);
|
|
946
|
+
// useEffect(() => { if (isImageLoaded) { editorRef.current?.setSharpness(sharpnessScore); updateCanvas(); } }, [sharpnessScore, isImageLoaded, updateCanvas]);
|
|
978
947
|
useEffect(() => {
|
|
979
948
|
// 5. Add a check to ignore state changes while viewing the original
|
|
980
949
|
if (!isImageLoaded || isViewingOriginal)
|
|
@@ -1017,15 +986,109 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1017
986
|
}
|
|
1018
987
|
};
|
|
1019
988
|
}, []);
|
|
989
|
+
// MARK: DEBUG (NEW LOGIC)
|
|
990
|
+
// const { width, height } = editorRef.current.getImageSize();
|
|
991
|
+
// canvasRef.current.width = width;
|
|
992
|
+
// canvasRef.current.height = height;
|
|
993
|
+
useEffect(() => {
|
|
994
|
+
if (canvasRef.current) {
|
|
995
|
+
canvasRef.current.style.transition = 'transform 0.1s ease-out';
|
|
996
|
+
canvasRef.current.style.transform = `scale(${zoomLevel})`;
|
|
997
|
+
}
|
|
998
|
+
}, [zoomLevel]);
|
|
999
|
+
// Undo, Redo, Revert
|
|
1000
|
+
const handleRevert = useCallback(() => {
|
|
1001
|
+
setCurrentAdjustmentsState(initialAdjustments);
|
|
1002
|
+
}, [updateCanvasEditor]);
|
|
1003
|
+
const handleUndo = useCallback(() => {
|
|
1004
|
+
if (historyIndex > 0) {
|
|
1005
|
+
const prevIndex = historyIndex - 1;
|
|
1006
|
+
setCurrentAdjustmentsState(history[prevIndex]);
|
|
1007
|
+
setHistoryIndex(prevIndex);
|
|
1008
|
+
}
|
|
1009
|
+
}, [history, historyIndex, updateCanvasEditor]);
|
|
1010
|
+
const handleRedo = useCallback(() => {
|
|
1011
|
+
if (historyIndex < history.length - 1) {
|
|
1012
|
+
const nextIndex = historyIndex + 1;
|
|
1013
|
+
setCurrentAdjustmentsState(history[nextIndex]);
|
|
1014
|
+
setHistoryIndex(nextIndex);
|
|
1015
|
+
}
|
|
1016
|
+
}, [history, historyIndex, updateCanvasEditor]);
|
|
1017
|
+
// Undo, Redo, Revert [END]
|
|
1018
|
+
// Swipe
|
|
1019
|
+
const swipeNext = useCallback(() => {
|
|
1020
|
+
// find next imageId
|
|
1021
|
+
// setCurrentImageId()
|
|
1022
|
+
}, []);
|
|
1023
|
+
const swipePrev = useCallback(() => {
|
|
1024
|
+
// find next imageId
|
|
1025
|
+
// setCurrentImageId()
|
|
1026
|
+
}, []);
|
|
1027
|
+
// Swipe [END]
|
|
1028
|
+
useEffect(() => {
|
|
1029
|
+
// will trigger when currentImageId change
|
|
1030
|
+
if (!currentImageId)
|
|
1031
|
+
return;
|
|
1032
|
+
const init = async () => {
|
|
1033
|
+
if (editorRef.current?.getInitialized() === false) {
|
|
1034
|
+
await editorRef.current?.initialize();
|
|
1035
|
+
}
|
|
1036
|
+
const imageData = await getImageFromId(firebaseUid, currentImageId);
|
|
1037
|
+
if (!imageData) {
|
|
1038
|
+
// TODO please check to make sure not crash
|
|
1039
|
+
throw new Error("can't load image data");
|
|
1040
|
+
}
|
|
1041
|
+
setCurrentImageData(imageData);
|
|
1042
|
+
const adjustmentData = imageData.editor_config?.color_adjustment;
|
|
1043
|
+
// set event
|
|
1044
|
+
setEventId(imageData.event_id);
|
|
1045
|
+
// TODO get slideshow image list
|
|
1046
|
+
// set to imageList
|
|
1047
|
+
const pathGallery = extractPathFromGallery(imageData);
|
|
1048
|
+
// load image to editor
|
|
1049
|
+
await loadImageEditorFromUrl(pathGallery);
|
|
1050
|
+
console.log("Image loaded to editor");
|
|
1051
|
+
// adjustment setup
|
|
1052
|
+
if (adjustmentData) {
|
|
1053
|
+
const adjustmentState = mapColorAdjustmentToAdjustmentState(adjustmentData);
|
|
1054
|
+
// set adjustment to editor to make adjustmentState change
|
|
1055
|
+
setCurrentAdjustmentsState(adjustmentState);
|
|
1056
|
+
}
|
|
1057
|
+
else {
|
|
1058
|
+
console.log("no adjustment found, use default");
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
init();
|
|
1062
|
+
}, [currentImageId, editorRef.current]);
|
|
1063
|
+
useEffect(() => {
|
|
1064
|
+
// Render photo if adjustmentState change;
|
|
1065
|
+
if (!editorRef.current)
|
|
1066
|
+
return;
|
|
1067
|
+
editorRef.current.setAdjustments(mapAdjustmentStateToAdjustmentEditor(currentAdjustmentsState));
|
|
1068
|
+
updateCanvasEditor();
|
|
1069
|
+
}, [editorRef.current, currentAdjustmentsState]);
|
|
1070
|
+
//
|
|
1020
1071
|
return {
|
|
1021
1072
|
// Refs
|
|
1022
1073
|
canvasRef,
|
|
1023
1074
|
canvasContainerRef,
|
|
1024
1075
|
fileInputRef,
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1076
|
+
// Status & State
|
|
1077
|
+
editorStatus,
|
|
1078
|
+
isEditorReady,
|
|
1079
|
+
isImageLoaded: isImageLoaded && !isGalleryLoading, // Combine loading states
|
|
1080
|
+
galleryError,
|
|
1081
|
+
// Gallery Swipe functions and state
|
|
1082
|
+
handlePrev: onSwipePrev,
|
|
1083
|
+
handleNext: onSwipeNext,
|
|
1084
|
+
isPrevAvailable,
|
|
1085
|
+
isNextAvailable,
|
|
1086
|
+
// History functions and state
|
|
1087
|
+
handleUndo: historyActions.undo,
|
|
1088
|
+
handleRedo: historyActions.redo,
|
|
1089
|
+
handleRevert: () => historyActions.reset(initialAdjustments),
|
|
1090
|
+
canUndo: historyInfo.canUndo,
|
|
1091
|
+
canRedo: historyInfo.canRedo,
|
|
1029
1092
|
// Refs for mobile panel
|
|
1030
1093
|
panelRef,
|
|
1031
1094
|
contentRef,
|
|
@@ -1035,9 +1098,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1035
1098
|
handleDragStart,
|
|
1036
1099
|
handleContentHeightChange,
|
|
1037
1100
|
// Status & State
|
|
1038
|
-
editorStatus,
|
|
1039
|
-
isEditorReady,
|
|
1040
|
-
isImageLoaded,
|
|
1041
1101
|
isPasteAvailable: copiedAdjustments !== null,
|
|
1042
1102
|
isOnline,
|
|
1043
1103
|
isConnectionSlow,
|
|
@@ -1083,9 +1143,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1083
1143
|
handleAlertClose,
|
|
1084
1144
|
loadImageFromId,
|
|
1085
1145
|
loadImageFromUrl,
|
|
1086
|
-
handleRevert,
|
|
1087
|
-
handleUndo,
|
|
1088
|
-
handleRedo,
|
|
1089
1146
|
handleOpenCopyDialog,
|
|
1090
1147
|
handleCloseCopyDialog,
|
|
1091
1148
|
copyColorChecks,
|
|
@@ -1100,7 +1157,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1100
1157
|
handleToggleCopyDialogExpand,
|
|
1101
1158
|
handleConfirmCopy,
|
|
1102
1159
|
handleCopyEdit,
|
|
1103
|
-
handlePasteEdit,
|
|
1104
1160
|
// adjustClarityBulk,
|
|
1105
1161
|
// adjustSharpnessBulk,
|
|
1106
1162
|
// Setters & Handlers
|
|
@@ -1141,18 +1197,8 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1141
1197
|
toggleBulkEditing,
|
|
1142
1198
|
handleSelectBulkPreset,
|
|
1143
1199
|
// Adjustment State & Setters
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
vibranceScore, setVibranceScore: setVibranceScoreAbs,
|
|
1147
|
-
saturationScore, setSaturationScore: setSaturationScoreAbs,
|
|
1148
|
-
exposureScore, setExposureScore: setExposureScoreAbs,
|
|
1149
|
-
highlightsScore, setHighlightsScore: setHighlightsScoreAbs,
|
|
1150
|
-
shadowsScore, setShadowsScore: setShadowsScoreAbs,
|
|
1151
|
-
whitesScore, setWhitesScore: setWhitesScoreAbs,
|
|
1152
|
-
blacksScore, setBlacksScore: setBlacksScoreAbs,
|
|
1153
|
-
contrastScore, setContrastScore: setContrastScoreAbs,
|
|
1154
|
-
clarityScore, setClarityScore: setClarityScoreAbs,
|
|
1155
|
-
sharpnessScore, setSharpnessScore: setSharpnessScoreAbs,
|
|
1200
|
+
currentAdjustmentsState,
|
|
1201
|
+
setCurrentAdjustmentsState,
|
|
1156
1202
|
// Bulk Adjustment Handlers
|
|
1157
1203
|
// Note: These handlers are for image list
|
|
1158
1204
|
imageList,
|
|
@@ -1161,55 +1207,55 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
|
1161
1207
|
handleToggleImageSelection,
|
|
1162
1208
|
// Note: These handlers are for bulk adjustments
|
|
1163
1209
|
// Adjustment Colors
|
|
1164
|
-
handleBulkTempDecreaseMax,
|
|
1165
|
-
handleBulkTempDecrease,
|
|
1166
|
-
handleBulkTempIncrease,
|
|
1167
|
-
handleBulkTempIncreaseMax,
|
|
1168
|
-
handleBulkTintDecreaseMax,
|
|
1169
|
-
handleBulkTintDecrease,
|
|
1170
|
-
handleBulkTintIncrease,
|
|
1171
|
-
handleBulkTintIncreaseMax,
|
|
1172
|
-
handleBulkVibranceDecreaseMax,
|
|
1173
|
-
handleBulkVibranceDecrease,
|
|
1174
|
-
handleBulkVibranceIncrease,
|
|
1175
|
-
handleBulkVibranceIncreaseMax,
|
|
1176
|
-
handleBulkSaturationDecreaseMax,
|
|
1177
|
-
handleBulkSaturationDecrease,
|
|
1178
|
-
handleBulkSaturationIncrease,
|
|
1179
|
-
handleBulkSaturationIncreaseMax,
|
|
1180
|
-
// Adjustment Light
|
|
1181
|
-
handleBulkExposureDecreaseMax,
|
|
1182
|
-
handleBulkExposureDecrease,
|
|
1183
|
-
handleBulkExposureIncrease,
|
|
1184
|
-
handleBulkExposureIncreaseMax,
|
|
1185
|
-
handleBulkContrastDecreaseMax,
|
|
1186
|
-
handleBulkContrastDecrease,
|
|
1187
|
-
handleBulkContrastIncrease,
|
|
1188
|
-
handleBulkContrastIncreaseMax,
|
|
1189
|
-
handleBulkHighlightsDecreaseMax,
|
|
1190
|
-
handleBulkHighlightsDecrease,
|
|
1191
|
-
handleBulkHighlightsIncrease,
|
|
1192
|
-
handleBulkHighlightsIncreaseMax,
|
|
1193
|
-
handleBulkShadowsDecreaseMax,
|
|
1194
|
-
handleBulkShadowsDecrease,
|
|
1195
|
-
handleBulkShadowsIncrease,
|
|
1196
|
-
handleBulkShadowsIncreaseMax,
|
|
1197
|
-
handleBulkWhitesDecreaseMax,
|
|
1198
|
-
handleBulkWhitesDecrease,
|
|
1199
|
-
handleBulkWhitesIncrease,
|
|
1200
|
-
handleBulkWhitesIncreaseMax,
|
|
1201
|
-
handleBulkBlacksDecreaseMax,
|
|
1202
|
-
handleBulkBlacksDecrease,
|
|
1203
|
-
handleBulkBlacksIncrease,
|
|
1204
|
-
handleBulkBlacksIncreaseMax,
|
|
1205
|
-
// Adjustment Details
|
|
1206
|
-
handleBulkClarityDecreaseMax,
|
|
1207
|
-
handleBulkClarityDecrease,
|
|
1208
|
-
handleBulkClarityIncrease,
|
|
1209
|
-
handleBulkClarityIncreaseMax,
|
|
1210
|
-
handleBulkSharpnessDecreaseMax,
|
|
1211
|
-
handleBulkSharpnessDecrease,
|
|
1212
|
-
handleBulkSharpnessIncrease,
|
|
1213
|
-
handleBulkSharpnessIncreaseMax,
|
|
1210
|
+
// handleBulkTempDecreaseMax,
|
|
1211
|
+
// handleBulkTempDecrease,
|
|
1212
|
+
// handleBulkTempIncrease,
|
|
1213
|
+
// handleBulkTempIncreaseMax,
|
|
1214
|
+
// handleBulkTintDecreaseMax,
|
|
1215
|
+
// handleBulkTintDecrease,
|
|
1216
|
+
// handleBulkTintIncrease,
|
|
1217
|
+
// handleBulkTintIncreaseMax,
|
|
1218
|
+
// handleBulkVibranceDecreaseMax,
|
|
1219
|
+
// handleBulkVibranceDecrease,
|
|
1220
|
+
// handleBulkVibranceIncrease,
|
|
1221
|
+
// handleBulkVibranceIncreaseMax,
|
|
1222
|
+
// handleBulkSaturationDecreaseMax,
|
|
1223
|
+
// handleBulkSaturationDecrease,
|
|
1224
|
+
// handleBulkSaturationIncrease,
|
|
1225
|
+
// handleBulkSaturationIncreaseMax,
|
|
1226
|
+
// // Adjustment Light
|
|
1227
|
+
// handleBulkExposureDecreaseMax,
|
|
1228
|
+
// handleBulkExposureDecrease,
|
|
1229
|
+
// handleBulkExposureIncrease,
|
|
1230
|
+
// handleBulkExposureIncreaseMax,
|
|
1231
|
+
// handleBulkContrastDecreaseMax,
|
|
1232
|
+
// handleBulkContrastDecrease,
|
|
1233
|
+
// handleBulkContrastIncrease,
|
|
1234
|
+
// handleBulkContrastIncreaseMax,
|
|
1235
|
+
// handleBulkHighlightsDecreaseMax,
|
|
1236
|
+
// handleBulkHighlightsDecrease,
|
|
1237
|
+
// handleBulkHighlightsIncrease,
|
|
1238
|
+
// handleBulkHighlightsIncreaseMax,
|
|
1239
|
+
// handleBulkShadowsDecreaseMax,
|
|
1240
|
+
// handleBulkShadowsDecrease,
|
|
1241
|
+
// handleBulkShadowsIncrease,
|
|
1242
|
+
// handleBulkShadowsIncreaseMax,
|
|
1243
|
+
// handleBulkWhitesDecreaseMax,
|
|
1244
|
+
// handleBulkWhitesDecrease,
|
|
1245
|
+
// handleBulkWhitesIncrease,
|
|
1246
|
+
// handleBulkWhitesIncreaseMax,
|
|
1247
|
+
// handleBulkBlacksDecreaseMax,
|
|
1248
|
+
// handleBulkBlacksDecrease,
|
|
1249
|
+
// handleBulkBlacksIncrease,
|
|
1250
|
+
// handleBulkBlacksIncreaseMax,
|
|
1251
|
+
// // Adjustment Details
|
|
1252
|
+
// handleBulkClarityDecreaseMax,
|
|
1253
|
+
// handleBulkClarityDecrease,
|
|
1254
|
+
// handleBulkClarityIncrease,
|
|
1255
|
+
// handleBulkClarityIncreaseMax,
|
|
1256
|
+
// handleBulkSharpnessDecreaseMax,
|
|
1257
|
+
// handleBulkSharpnessDecrease,
|
|
1258
|
+
// handleBulkSharpnessIncrease,
|
|
1259
|
+
// handleBulkSharpnessIncreaseMax,
|
|
1214
1260
|
};
|
|
1215
1261
|
}
|