@yogiswara/honcho-editor-ui 1.0.9 → 1.0.11
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,76 @@
|
|
|
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 ColorAdjustment {
|
|
13
|
+
temperature: number;
|
|
14
|
+
tint: number;
|
|
15
|
+
saturation: number;
|
|
16
|
+
vibrance: number;
|
|
17
|
+
exposure: number;
|
|
18
|
+
contrast: number;
|
|
19
|
+
highlights: number;
|
|
20
|
+
shadows: number;
|
|
21
|
+
whites: number;
|
|
22
|
+
blacks: number;
|
|
23
|
+
clarity: number;
|
|
24
|
+
sharpness: number;
|
|
25
|
+
}
|
|
26
|
+
export interface TransformationAdjustment {
|
|
27
|
+
angle_score?: number;
|
|
28
|
+
direction?: "cw" | "ccw";
|
|
29
|
+
scale_score?: number;
|
|
30
|
+
keep_dimension?: boolean;
|
|
31
|
+
flip_mode?: "horizontal" | "vertical" | "mix";
|
|
32
|
+
aspect_ratio?: string;
|
|
33
|
+
width?: number;
|
|
34
|
+
height?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface Watermark {
|
|
37
|
+
path: string;
|
|
38
|
+
max_pct: [number, number];
|
|
39
|
+
anchor: [string, number | null, number[] | null];
|
|
40
|
+
rotate_deg: [number, "cw" | "ccw"];
|
|
41
|
+
}
|
|
42
|
+
export interface EditorConfig {
|
|
43
|
+
color_adjustment: ColorAdjustment;
|
|
44
|
+
transformation_adjustment: TransformationAdjustment[];
|
|
45
|
+
watermarks: Watermark[];
|
|
46
|
+
}
|
|
47
|
+
export interface Gallery {
|
|
48
|
+
id: string;
|
|
49
|
+
uid: string;
|
|
50
|
+
event_id: string;
|
|
51
|
+
download: Content;
|
|
52
|
+
download_edited: Content | null;
|
|
53
|
+
raw?: Content;
|
|
54
|
+
raw_edited?: Content;
|
|
55
|
+
raw_preview?: Content;
|
|
56
|
+
raw_thumbnail?: Content;
|
|
57
|
+
original?: Content;
|
|
58
|
+
original_edited?: Content | null;
|
|
59
|
+
large?: Content;
|
|
60
|
+
large_edited?: Content | null;
|
|
61
|
+
medium?: Content | null;
|
|
62
|
+
medium_edited?: Content | null;
|
|
63
|
+
small?: Content | null;
|
|
64
|
+
small_edited?: Content | null;
|
|
65
|
+
mini?: Content | null;
|
|
66
|
+
mini_edited?: Content | null;
|
|
67
|
+
create_from?: string[];
|
|
68
|
+
thumbnail: Content;
|
|
69
|
+
thumbnail_edited: Content | null;
|
|
70
|
+
is_original: boolean;
|
|
71
|
+
available: boolean;
|
|
72
|
+
show_gallery: boolean;
|
|
73
|
+
editor_config?: EditorConfig;
|
|
74
|
+
log: Log;
|
|
75
|
+
}
|
|
76
|
+
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>;
|
|
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>;
|
|
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
|
|
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>;
|
|
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>;
|
|
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,20 @@ 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
|
-
|
|
268
|
-
|
|
267
|
+
const gallery = await controller.onGetImage(firebaseUid, imageId);
|
|
268
|
+
const imagePath = gallery?.raw_edited?.path
|
|
269
|
+
? gallery.raw_edited.path
|
|
270
|
+
: gallery?.download?.path;
|
|
271
|
+
if (imagePath) {
|
|
272
|
+
await loadImageFromUrl(imagePath);
|
|
269
273
|
}
|
|
270
274
|
else {
|
|
271
|
-
throw new Error("Controller did not return
|
|
275
|
+
throw new Error("Controller did not return a valid image object with path.");
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
278
|
catch (error) {
|
|
@@ -276,26 +280,22 @@ export function useHonchoEditor(controller) {
|
|
|
276
280
|
setEditorStatus("Error: Could not fetch the image.");
|
|
277
281
|
}
|
|
278
282
|
}, [controller, loadImageFromUrl]);
|
|
283
|
+
const handlePrev = useCallback(async (firebaseUid) => {
|
|
284
|
+
const prevImageId = imageList[imageList.length - 2]?.id;
|
|
285
|
+
if (prevImageId) {
|
|
286
|
+
setCurrentImageId(prevImageId);
|
|
287
|
+
}
|
|
288
|
+
}, [imageList]);
|
|
289
|
+
const handleNext = useCallback(async (firebaseUid) => {
|
|
290
|
+
const nextImageId = imageList[1]?.id;
|
|
291
|
+
if (nextImageId) {
|
|
292
|
+
setCurrentImageId(nextImageId);
|
|
293
|
+
}
|
|
294
|
+
}, [imageList]);
|
|
279
295
|
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]);
|
|
296
|
+
loadImageFromId(firebaseUid, currentImageId); // initImageId became state
|
|
297
|
+
// so when next prev changes only setCurrentImageId
|
|
298
|
+
}, [currentImageId, firebaseUid, loadImageFromId]);
|
|
299
299
|
const handleFileChange = (event) => {
|
|
300
300
|
const files = event.target?.files;
|
|
301
301
|
if (!files || files.length === 0)
|
|
@@ -704,7 +704,7 @@ export function useHonchoEditor(controller) {
|
|
|
704
704
|
if (!controller)
|
|
705
705
|
return;
|
|
706
706
|
try {
|
|
707
|
-
const fetchedPresets = await controller.getPresets();
|
|
707
|
+
const fetchedPresets = await controller.getPresets(firebaseUid);
|
|
708
708
|
setPresets(fetchedPresets);
|
|
709
709
|
}
|
|
710
710
|
catch (error) {
|
|
@@ -724,7 +724,7 @@ export function useHonchoEditor(controller) {
|
|
|
724
724
|
if (!controller || !activePresetMenuId)
|
|
725
725
|
return;
|
|
726
726
|
try {
|
|
727
|
-
await controller.renamePreset(activePresetMenuId, newName);
|
|
727
|
+
await controller.renamePreset(firebaseUid, activePresetMenuId, newName);
|
|
728
728
|
// On success, update the preset in local state
|
|
729
729
|
setPresets(prev => prev.map(p => p.id === activePresetMenuId ? { ...p, name: newName } : p));
|
|
730
730
|
}
|
|
@@ -737,7 +737,7 @@ export function useHonchoEditor(controller) {
|
|
|
737
737
|
if (!controller || !activePresetMenuId)
|
|
738
738
|
return;
|
|
739
739
|
try {
|
|
740
|
-
await controller.deletePreset(activePresetMenuId);
|
|
740
|
+
await controller.deletePreset(firebaseUid, activePresetMenuId);
|
|
741
741
|
// On success, remove the preset from local state
|
|
742
742
|
setPresets(prevPresets => prevPresets.filter(p => p.id !== activePresetMenuId));
|
|
743
743
|
}
|
|
@@ -754,7 +754,7 @@ export function useHonchoEditor(controller) {
|
|
|
754
754
|
return;
|
|
755
755
|
const currentAdjustments = { tempScore, tintScore, vibranceScore, exposureScore, highlightsScore, shadowsScore, whitesScore, blacksScore, saturationScore, contrastScore, clarityScore, sharpnessScore };
|
|
756
756
|
try {
|
|
757
|
-
const newPreset = await controller.createPreset(presetName, currentAdjustments);
|
|
757
|
+
const newPreset = await controller.createPreset(firebaseUid, presetName, currentAdjustments);
|
|
758
758
|
if (newPreset) {
|
|
759
759
|
// Add the new preset returned from the API to our local state
|
|
760
760
|
setPresets(prevPresets => [...prevPresets, newPreset]);
|
|
@@ -805,7 +805,7 @@ export function useHonchoEditor(controller) {
|
|
|
805
805
|
if (!presetToRename || !newPresetName)
|
|
806
806
|
return;
|
|
807
807
|
try {
|
|
808
|
-
await controller.renamePreset(presetToRename.id, newPresetName);
|
|
808
|
+
await controller.renamePreset(firebaseUid, presetToRename.id, newPresetName);
|
|
809
809
|
// On success, update the preset in local state
|
|
810
810
|
setPresets(prev => prev.map(p => p.id === presetToRename.id ? { ...p, name: newPresetName } : p));
|
|
811
811
|
}
|
|
@@ -999,6 +999,8 @@ export function useHonchoEditor(controller) {
|
|
|
999
999
|
};
|
|
1000
1000
|
}, []);
|
|
1001
1001
|
return {
|
|
1002
|
+
handlePrev,
|
|
1003
|
+
handleNext,
|
|
1002
1004
|
// Refs
|
|
1003
1005
|
canvasRef,
|
|
1004
1006
|
canvasContainerRef,
|
|
@@ -1012,8 +1014,6 @@ export function useHonchoEditor(controller) {
|
|
|
1012
1014
|
createPreset: controller.createPreset,
|
|
1013
1015
|
deletePreset: controller.deletePreset,
|
|
1014
1016
|
renamePreset: controller.renamePreset,
|
|
1015
|
-
handleNext: controller.handleNext,
|
|
1016
|
-
handlePrev: controller.handlePrev,
|
|
1017
1017
|
// Refs for mobile panel
|
|
1018
1018
|
panelRef,
|
|
1019
1019
|
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';
|