@yogiswara/honcho-editor-ui 1.0.9 → 1.0.10
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.
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
interface Log {
|
|
2
|
+
created_at: string;
|
|
3
|
+
updated_at: string;
|
|
4
|
+
}
|
|
5
|
+
export interface Content {
|
|
6
|
+
key: string;
|
|
7
|
+
path: string;
|
|
8
|
+
size: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Gallery {
|
|
13
|
+
id: string;
|
|
14
|
+
uid: string;
|
|
15
|
+
event_id: string;
|
|
16
|
+
download: Content;
|
|
17
|
+
download_edited: Content;
|
|
18
|
+
raw?: Content;
|
|
19
|
+
raw_edited?: Content;
|
|
20
|
+
original?: Content;
|
|
21
|
+
original_edited?: Content;
|
|
22
|
+
large?: Content;
|
|
23
|
+
large_edited?: Content;
|
|
24
|
+
medium?: Content;
|
|
25
|
+
medium_edited?: Content;
|
|
26
|
+
small?: Content;
|
|
27
|
+
small_edited?: Content;
|
|
28
|
+
mini?: Content;
|
|
29
|
+
mini_edited?: Content;
|
|
30
|
+
create_from?: string[];
|
|
31
|
+
thumbnail: Content;
|
|
32
|
+
thumbnail_edited: Content;
|
|
33
|
+
is_original: boolean;
|
|
34
|
+
available: boolean;
|
|
35
|
+
show_gallery: boolean;
|
|
36
|
+
log: Log;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { SelectChangeEvent } from "@mui/material";
|
|
2
|
+
import { Gallery } from '../../hooks/editor/type';
|
|
2
3
|
declare global {
|
|
3
4
|
interface Window {
|
|
4
5
|
Module: any;
|
|
5
6
|
}
|
|
6
7
|
}
|
|
7
8
|
export interface Controller {
|
|
8
|
-
onGetImage(imageID: string): Promise<
|
|
9
|
-
getImageList(): Promise<
|
|
10
|
-
syncConfig(): Promise<void>;
|
|
11
|
-
handleBack(): void;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
deletePreset(presetId: string): Promise<void>;
|
|
17
|
-
renamePreset(presetId: string, newName: string): Promise<void>;
|
|
9
|
+
onGetImage(firebaseUid: string, imageID: string): Promise<Gallery | null>;
|
|
10
|
+
getImageList(firebaseUid: string): Promise<Gallery[]>;
|
|
11
|
+
syncConfig(firebaseUid: string): Promise<void>;
|
|
12
|
+
handleBack(firebaseUid: string): void;
|
|
13
|
+
getPresets(firebaseUid: string): Promise<Preset[]>;
|
|
14
|
+
createPreset(firebaseUid: string, name: string, settings: AdjustmentState): Promise<Preset | null>;
|
|
15
|
+
deletePreset(firebaseUid: string, presetId: string): Promise<void>;
|
|
16
|
+
renamePreset(firebaseUid: string, presetId: string, newName: string): Promise<void>;
|
|
18
17
|
}
|
|
19
18
|
export type AdjustmentState = {
|
|
20
19
|
tempScore: number;
|
|
@@ -40,21 +39,21 @@ export type ImageItem = {
|
|
|
40
39
|
name: string;
|
|
41
40
|
file: File;
|
|
42
41
|
};
|
|
43
|
-
export declare function useHonchoEditor(controller: Controller): {
|
|
42
|
+
export declare function useHonchoEditor(controller: Controller, initImageId: string, firebaseUid: string): {
|
|
43
|
+
handlePrev: (firebaseUid: string) => Promise<void>;
|
|
44
|
+
handleNext: (firebaseUid: string) => Promise<void>;
|
|
44
45
|
canvasRef: import("react").MutableRefObject<HTMLCanvasElement | null>;
|
|
45
46
|
canvasContainerRef: import("react").MutableRefObject<HTMLDivElement | null>;
|
|
46
47
|
fileInputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
47
48
|
displayedToken: string | null;
|
|
48
|
-
handleBack: () => void;
|
|
49
|
-
onGetImage: (imageID: string) => Promise<
|
|
50
|
-
getImageList: () => Promise<
|
|
51
|
-
syncConfig: () => Promise<void>;
|
|
52
|
-
getPresets: () => Promise<Preset[]>;
|
|
53
|
-
createPreset: (name: string, settings: AdjustmentState) => Promise<Preset | null>;
|
|
54
|
-
deletePreset: (presetId: string) => Promise<void>;
|
|
55
|
-
renamePreset: (presetId: string, newName: string) => Promise<void>;
|
|
56
|
-
handleNext: () => void;
|
|
57
|
-
handlePrev: () => void;
|
|
49
|
+
handleBack: (firebaseUid: string) => void;
|
|
50
|
+
onGetImage: (firebaseUid: string, imageID: string) => Promise<Gallery | null>;
|
|
51
|
+
getImageList: (firebaseUid: string) => Promise<Gallery[]>;
|
|
52
|
+
syncConfig: (firebaseUid: string) => Promise<void>;
|
|
53
|
+
getPresets: (firebaseUid: string) => Promise<Preset[]>;
|
|
54
|
+
createPreset: (firebaseUid: string, name: string, settings: AdjustmentState) => Promise<Preset | null>;
|
|
55
|
+
deletePreset: (firebaseUid: string, presetId: string) => Promise<void>;
|
|
56
|
+
renamePreset: (firebaseUid: string, presetId: string, newName: string) => Promise<void>;
|
|
58
57
|
panelRef: import("react").MutableRefObject<HTMLDivElement | null>;
|
|
59
58
|
contentRef: import("react").MutableRefObject<HTMLDivElement | null>;
|
|
60
59
|
panelHeight: number;
|
|
@@ -105,7 +104,7 @@ export declare function useHonchoEditor(controller: Controller): {
|
|
|
105
104
|
handleScriptReady: () => Promise<void>;
|
|
106
105
|
handleFileChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
107
106
|
handleAlertClose: () => void;
|
|
108
|
-
loadImageFromId: (imageId: string) => Promise<void>;
|
|
107
|
+
loadImageFromId: (firebaseUid: string, imageId: string) => Promise<void>;
|
|
109
108
|
loadImageFromUrl: (url: string) => Promise<void>;
|
|
110
109
|
handleRevert: () => void;
|
|
111
110
|
handleUndo: () => void;
|
|
@@ -6,7 +6,8 @@ const initialAdjustments = {
|
|
|
6
6
|
whitesScore: 0, blacksScore: 0, saturationScore: 0, contrastScore: 0, clarityScore: 0, sharpnessScore: 0,
|
|
7
7
|
};
|
|
8
8
|
const clamp = (value) => Math.max(-100, Math.min(100, value));
|
|
9
|
-
export function useHonchoEditor(controller) {
|
|
9
|
+
export function useHonchoEditor(controller, initImageId, firebaseUid) {
|
|
10
|
+
const [currentImageId, setCurrentImageId] = useState(initImageId);
|
|
10
11
|
// MARK: - Core Editor State & Refs
|
|
11
12
|
const editorRef = useRef(null);
|
|
12
13
|
const canvasRef = useRef(null);
|
|
@@ -258,17 +259,17 @@ export function useHonchoEditor(controller) {
|
|
|
258
259
|
setEditorStatus("Error: Could not load image from URL.");
|
|
259
260
|
}
|
|
260
261
|
}, [loadImage]);
|
|
261
|
-
const loadImageFromId = useCallback(async (imageId) => {
|
|
262
|
+
const loadImageFromId = useCallback(async (firebaseUid, imageId) => {
|
|
262
263
|
if (!controller)
|
|
263
264
|
return;
|
|
264
|
-
setEditorStatus("Fetching image
|
|
265
|
+
setEditorStatus("Fetching image...");
|
|
265
266
|
try {
|
|
266
|
-
const
|
|
267
|
-
if (
|
|
268
|
-
await loadImageFromUrl(
|
|
267
|
+
const gallery = await controller.onGetImage(firebaseUid, imageId);
|
|
268
|
+
if (gallery && gallery.original && gallery.original.path) {
|
|
269
|
+
await loadImageFromUrl(gallery.original.path);
|
|
269
270
|
}
|
|
270
271
|
else {
|
|
271
|
-
throw new Error("Controller did not return
|
|
272
|
+
throw new Error("Controller did not return a valid image object with path.");
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
275
|
catch (error) {
|
|
@@ -276,26 +277,22 @@ export function useHonchoEditor(controller) {
|
|
|
276
277
|
setEditorStatus("Error: Could not fetch the image.");
|
|
277
278
|
}
|
|
278
279
|
}, [controller, loadImageFromUrl]);
|
|
280
|
+
const handlePrev = useCallback(async (firebaseUid) => {
|
|
281
|
+
const prevImageId = imageList[imageList.length - 2]?.id;
|
|
282
|
+
if (prevImageId) {
|
|
283
|
+
setCurrentImageId(prevImageId);
|
|
284
|
+
}
|
|
285
|
+
}, [imageList]);
|
|
286
|
+
const handleNext = useCallback(async (firebaseUid) => {
|
|
287
|
+
const nextImageId = imageList[1]?.id;
|
|
288
|
+
if (nextImageId) {
|
|
289
|
+
setCurrentImageId(nextImageId);
|
|
290
|
+
}
|
|
291
|
+
}, [imageList]);
|
|
279
292
|
useEffect(() => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
console.log(`[WebView Bridge] Received command to load imageId: ${imageId}`);
|
|
284
|
-
// Use the loadImageFromId function directly from the hook's scope
|
|
285
|
-
loadImageFromId(imageId);
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
console.error(`[WebView Bridge] Invalid imageId received from native:`, imageId);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
// Expose both functions on the window object for native code to access
|
|
292
|
-
window.loadInitialImageFromNative = loadInitialImageFromNative;
|
|
293
|
-
// Cleanup function to remove the global handlers when the component unmounts
|
|
294
|
-
return () => {
|
|
295
|
-
delete window.loadInitialImageFromNative;
|
|
296
|
-
delete window.setAuthToken;
|
|
297
|
-
};
|
|
298
|
-
}, [loadImageFromId]);
|
|
293
|
+
loadImageFromId(firebaseUid, currentImageId); // initImageId became state
|
|
294
|
+
// so when next prev changes only setCurrentImageId
|
|
295
|
+
}, [currentImageId, firebaseUid, loadImageFromId]);
|
|
299
296
|
const handleFileChange = (event) => {
|
|
300
297
|
const files = event.target?.files;
|
|
301
298
|
if (!files || files.length === 0)
|
|
@@ -704,7 +701,7 @@ export function useHonchoEditor(controller) {
|
|
|
704
701
|
if (!controller)
|
|
705
702
|
return;
|
|
706
703
|
try {
|
|
707
|
-
const fetchedPresets = await controller.getPresets();
|
|
704
|
+
const fetchedPresets = await controller.getPresets(firebaseUid);
|
|
708
705
|
setPresets(fetchedPresets);
|
|
709
706
|
}
|
|
710
707
|
catch (error) {
|
|
@@ -724,7 +721,7 @@ export function useHonchoEditor(controller) {
|
|
|
724
721
|
if (!controller || !activePresetMenuId)
|
|
725
722
|
return;
|
|
726
723
|
try {
|
|
727
|
-
await controller.renamePreset(activePresetMenuId, newName);
|
|
724
|
+
await controller.renamePreset(firebaseUid, activePresetMenuId, newName);
|
|
728
725
|
// On success, update the preset in local state
|
|
729
726
|
setPresets(prev => prev.map(p => p.id === activePresetMenuId ? { ...p, name: newName } : p));
|
|
730
727
|
}
|
|
@@ -737,7 +734,7 @@ export function useHonchoEditor(controller) {
|
|
|
737
734
|
if (!controller || !activePresetMenuId)
|
|
738
735
|
return;
|
|
739
736
|
try {
|
|
740
|
-
await controller.deletePreset(activePresetMenuId);
|
|
737
|
+
await controller.deletePreset(firebaseUid, activePresetMenuId);
|
|
741
738
|
// On success, remove the preset from local state
|
|
742
739
|
setPresets(prevPresets => prevPresets.filter(p => p.id !== activePresetMenuId));
|
|
743
740
|
}
|
|
@@ -754,7 +751,7 @@ export function useHonchoEditor(controller) {
|
|
|
754
751
|
return;
|
|
755
752
|
const currentAdjustments = { tempScore, tintScore, vibranceScore, exposureScore, highlightsScore, shadowsScore, whitesScore, blacksScore, saturationScore, contrastScore, clarityScore, sharpnessScore };
|
|
756
753
|
try {
|
|
757
|
-
const newPreset = await controller.createPreset(presetName, currentAdjustments);
|
|
754
|
+
const newPreset = await controller.createPreset(firebaseUid, presetName, currentAdjustments);
|
|
758
755
|
if (newPreset) {
|
|
759
756
|
// Add the new preset returned from the API to our local state
|
|
760
757
|
setPresets(prevPresets => [...prevPresets, newPreset]);
|
|
@@ -805,7 +802,7 @@ export function useHonchoEditor(controller) {
|
|
|
805
802
|
if (!presetToRename || !newPresetName)
|
|
806
803
|
return;
|
|
807
804
|
try {
|
|
808
|
-
await controller.renamePreset(presetToRename.id, newPresetName);
|
|
805
|
+
await controller.renamePreset(firebaseUid, presetToRename.id, newPresetName);
|
|
809
806
|
// On success, update the preset in local state
|
|
810
807
|
setPresets(prev => prev.map(p => p.id === presetToRename.id ? { ...p, name: newPresetName } : p));
|
|
811
808
|
}
|
|
@@ -999,6 +996,8 @@ export function useHonchoEditor(controller) {
|
|
|
999
996
|
};
|
|
1000
997
|
}, []);
|
|
1001
998
|
return {
|
|
999
|
+
handlePrev,
|
|
1000
|
+
handleNext,
|
|
1002
1001
|
// Refs
|
|
1003
1002
|
canvasRef,
|
|
1004
1003
|
canvasContainerRef,
|
|
@@ -1012,8 +1011,6 @@ export function useHonchoEditor(controller) {
|
|
|
1012
1011
|
createPreset: controller.createPreset,
|
|
1013
1012
|
deletePreset: controller.deletePreset,
|
|
1014
1013
|
renamePreset: controller.renamePreset,
|
|
1015
|
-
handleNext: controller.handleNext,
|
|
1016
|
-
handlePrev: controller.handlePrev,
|
|
1017
1014
|
// Refs for mobile panel
|
|
1018
1015
|
panelRef,
|
|
1019
1016
|
contentRef,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useHonchoEditor } from './hooks/editor/useHonchoEditor';
|
|
2
2
|
export type { Controller, AdjustmentState, Preset, ImageItem, } from './hooks/editor/useHonchoEditor';
|
|
3
|
+
export type { Gallery, Content } from './hooks/editor/type';
|
|
3
4
|
export { default as HHeaderEditor } from './components/editor/HHeaderEditor';
|
|
4
5
|
export { default as HFooter } from './components/editor/HFooter';
|
|
5
6
|
export { default as HAccordionColorAdjustment } from './components/editor/HAccordionColorAdjustment';
|