@yogiswara/honcho-editor-ui 1.0.13 → 1.0.15

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.
@@ -39,19 +39,13 @@ export type ImageItem = {
39
39
  file: File;
40
40
  };
41
41
  export declare function useHonchoEditor(controller: Controller, initImageId: string, firebaseUid: string): {
42
- handlePrev: (firebaseUid: string) => Promise<void>;
43
- handleNext: (firebaseUid: string) => Promise<void>;
44
42
  canvasRef: import("react").MutableRefObject<HTMLCanvasElement | null>;
45
43
  canvasContainerRef: import("react").MutableRefObject<HTMLDivElement | null>;
46
44
  fileInputRef: import("react").MutableRefObject<HTMLInputElement | null>;
47
45
  displayedToken: string | null;
48
- handleBack: (firebaseUid: string) => void;
49
- onGetImage: (firebaseUid: string, imageID: string) => Promise<Gallery>;
50
- getImageList: (firebaseUid: string) => Promise<Gallery[]>;
51
- syncConfig: (firebaseUid: string) => Promise<void>;
52
- getPresets: (firebaseUid: string) => Promise<Preset[]>;
53
- createPreset: (firebaseUid: string, name: string, settings: AdjustmentState) => Promise<Preset>;
54
- deletePreset: (firebaseUid: string, presetId: string) => Promise<void>;
46
+ handleBackCallback: () => void;
47
+ handlePrev: (firebaseUid: string) => Promise<void>;
48
+ handleNext: (firebaseUid: string) => Promise<void>;
55
49
  panelRef: import("react").MutableRefObject<HTMLDivElement | null>;
56
50
  contentRef: import("react").MutableRefObject<HTMLDivElement | null>;
57
51
  panelHeight: number;
@@ -157,6 +157,11 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
157
157
  handleOpenCopyDialog(); // Assumes handleOpenCopyDialog is defined in the hook
158
158
  }
159
159
  }, [ /* handleOpenCopyDialog dependency */]);
160
+ useEffect(() => {
161
+ if (editorRef.current?.getInitialized() === false) {
162
+ editorRef.current?.initialize();
163
+ }
164
+ }, [editorRef]);
160
165
  // Effect for measuring mobile panel content
161
166
  useEffect(() => {
162
167
  const timeoutId = setTimeout(() => {
@@ -227,6 +232,7 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
227
232
  try {
228
233
  await editorRef.current.loadImageFromFile(file);
229
234
  setIsImageLoaded(true);
235
+ updateCanvas();
230
236
  }
231
237
  catch (e) {
232
238
  console.error("Error loading image:", e);
@@ -281,20 +287,31 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
281
287
  }
282
288
  }, [controller, loadImageFromUrl]);
283
289
  const handlePrev = useCallback(async (firebaseUid) => {
284
- const prevImageId = imageList[imageList.length - 2]?.id;
285
- if (prevImageId) {
286
- setCurrentImageId(prevImageId);
290
+ // Find the current image index
291
+ const currentIndex = imageList.findIndex(img => img.id === currentImageId);
292
+ // If not the first image, go to previous
293
+ if (currentIndex > 0) {
294
+ const prevImageId = imageList[currentIndex - 1]?.id;
295
+ if (prevImageId) {
296
+ setCurrentImageId(prevImageId);
297
+ }
287
298
  }
288
- }, [imageList]);
299
+ }, [imageList, currentImageId]);
289
300
  const handleNext = useCallback(async (firebaseUid) => {
290
- const nextImageId = imageList[1]?.id;
291
- if (nextImageId) {
292
- setCurrentImageId(nextImageId);
301
+ // Find the current image index
302
+ const currentIndex = imageList.findIndex(img => img.id === currentImageId);
303
+ // If not the last image, go to next
304
+ if (currentIndex < imageList.length - 1 && currentIndex !== -1) {
305
+ const nextImageId = imageList[currentIndex + 1]?.id;
306
+ if (nextImageId) {
307
+ setCurrentImageId(nextImageId);
308
+ }
293
309
  }
294
- }, [imageList]);
310
+ }, [imageList, currentImageId]);
295
311
  useEffect(() => {
296
- loadImageFromId(firebaseUid, currentImageId); // initImageId became state
297
- // so when next prev changes only setCurrentImageId
312
+ if (currentImageId && firebaseUid) {
313
+ loadImageFromId(firebaseUid, currentImageId);
314
+ }
298
315
  }, [currentImageId, firebaseUid, loadImageFromId]);
299
316
  const handleFileChange = (event) => {
300
317
  const files = event.target?.files;
@@ -369,91 +386,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
369
386
  setHistoryIndex(nextIndex);
370
387
  }
371
388
  }, [history, historyIndex, applyAdjustmentState]);
372
- // MARK: - Bulk Editor Functions For Desktop and Mobile
373
- // const adjustTempBulk = useCallback((uiAmount: number) => {
374
- // setTempScore(prevScore => {
375
- // const newScore = clamp(prevScore + uiAmount);
376
- // console.log("Adjusting temperature. New score:", newScore);
377
- // return newScore;
378
- // });
379
- // }, []);
380
- // const adjustTintBulk = useCallback((uiAmount: number) => {
381
- // setTintScore(prevScore => {
382
- // const newScore = clamp(prevScore + uiAmount);
383
- // console.log("Adjusting tint. New score:", newScore);
384
- // return newScore;
385
- // });
386
- // }, []);
387
- // const adjustVibranceBulk = useCallback((uiAmount: number) => {
388
- // setVibranceScore(prevScore => {
389
- // const newScore = clamp(prevScore + uiAmount);
390
- // console.log("Adjusting vibrance. New score:", newScore);
391
- // return newScore;
392
- // });
393
- // }, []);
394
- // const adjustSaturationBulk = useCallback((uiAmount: number) => {
395
- // setSaturationScore(prevScore => {
396
- // const newScore = clamp(prevScore + uiAmount);
397
- // console.log("Adjusting saturation. New score:", newScore);
398
- // return newScore;
399
- // });
400
- // }, []);
401
- // const adjustExposureBulk = useCallback((uiAmount: number) => {
402
- // setExposureScore(prevScore => {
403
- // const newScore = clamp(prevScore + uiAmount);
404
- // console.log("Adjusting exposure. New score:", newScore);
405
- // return newScore;
406
- // });
407
- // }, []);
408
- // const adjustContrastBulk = useCallback((uiAmount: number) => {
409
- // setContrastScore(prevScore => {
410
- // const newScore = clamp(prevScore + uiAmount);
411
- // console.log("Adjusting contrast. New score:", newScore);
412
- // return newScore;
413
- // });
414
- // }, []);
415
- // const adjustHighlightsBulk = useCallback((uiAmount: number) => {
416
- // setHighlightsScore(prevScore => {
417
- // const newScore = clamp(prevScore + uiAmount);
418
- // console.log("Adjusting highlights. New score:", newScore);
419
- // return newScore;
420
- // });
421
- // }, []);
422
- // const adjustShadowsBulk = useCallback((uiAmount: number) => {
423
- // setShadowsScore(prevScore => {
424
- // const newScore = clamp(prevScore + uiAmount);
425
- // console.log("Adjusting shadows. New score:", newScore);
426
- // return newScore;
427
- // });
428
- // }, []);
429
- // const adjustWhitesBulk = useCallback((uiAmount: number) => {
430
- // setWhitesScore(prevScore => {
431
- // const newScore = clamp(prevScore + uiAmount);
432
- // console.log("Adjusting whites. New score:", newScore);
433
- // return newScore;
434
- // });
435
- // }, []);
436
- // const adjustBlacksBulk = useCallback((uiAmount: number) => {
437
- // setBlacksScore(prevScore => {
438
- // const newScore = clamp(prevScore + uiAmount);
439
- // console.log("Adjusting blacks. New score:", newScore);
440
- // return newScore;
441
- // });
442
- // }, []);
443
- // const adjustClarityBulk = useCallback((uiAmount: number) => {
444
- // setClarityScore(prevScore => {
445
- // const newScore = clamp(prevScore + uiAmount);
446
- // console.log("Adjusting clarity. New score:", newScore);
447
- // return newScore;
448
- // });
449
- // }, []);
450
- // const adjustSharpnessBulk = useCallback((uiAmount: number) => {
451
- // setSharpnessScore(prevScore => {
452
- // const newScore = clamp(prevScore + uiAmount);
453
- // console.log("Adjusting sharpness. New score:", newScore);
454
- // return newScore;
455
- // });
456
- // }, []);
457
389
  const handleToggleImageSelection = useCallback((imageId) => {
458
390
  const newSelectedIds = new Set(selectedImageIds);
459
391
  const isCurrentlySelected = newSelectedIds.has(imageId);
@@ -593,6 +525,9 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
593
525
  });
594
526
  }
595
527
  }, []);
528
+ const handleBackCallback = useCallback(() => {
529
+ controller.handleBack(firebaseUid);
530
+ }, [controller]);
596
531
  // MARK: - UI Handlers (Moved from page.tsx)
597
532
  // Header and Dialog Handlers
598
533
  const handleHeaderMenuClick = (event) => setHeaderMenuAnchorEl(event.currentTarget);
@@ -973,20 +908,14 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
973
908
  };
974
909
  }, []);
975
910
  return {
976
- handlePrev,
977
- handleNext,
978
911
  // Refs
979
912
  canvasRef,
980
913
  canvasContainerRef,
981
914
  fileInputRef,
982
915
  displayedToken,
983
- handleBack: controller.handleBack,
984
- onGetImage: controller.onGetImage,
985
- getImageList: controller.getImageList,
986
- syncConfig: controller.syncConfig,
987
- getPresets: controller.getPresets,
988
- createPreset: controller.createPreset,
989
- deletePreset: controller.deletePreset,
916
+ handleBackCallback,
917
+ handlePrev,
918
+ handleNext,
990
919
  // Refs for mobile panel
991
920
  panelRef,
992
921
  contentRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "A complete UI component library for the Honcho photo editor.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",