@yogiswara/honcho-editor-ui 2.10.0 → 2.10.1
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/demo/HonchoEditorBulkDemo.js +2 -1
- package/dist/lib/hooks/useEditor.d.ts +1 -1
- package/dist/lib/hooks/useEditor.js +1 -1
- package/dist/lib/hooks/useEditorHeadless.d.ts +2 -2
- package/dist/lib/hooks/useEditorHeadless.js +1 -1
- package/dist/lib/hooks/useImageProcessor.d.ts +5 -2
- package/dist/lib/hooks/useImageProcessor.js +29 -4
- package/dist/services/type.d.ts +7 -1
- package/package.json +1 -1
|
@@ -264,7 +264,8 @@ const ImageCard = React.memo(({ image, onToggleSelection }) => {
|
|
|
264
264
|
photoSrc: image.src,
|
|
265
265
|
adjustments: image.adjustments,
|
|
266
266
|
enableEditor: shouldLoadImage && isInView, // Only enable when we should load the image AND it's in view
|
|
267
|
-
abortSignal: currentAbortSignalRef.current // Use stable abort signal
|
|
267
|
+
abortSignal: currentAbortSignalRef.current, // Use stable abort signal
|
|
268
|
+
frame: null,
|
|
268
269
|
}), [image.key, image.src, image.adjustments, shouldLoadImage, isInView]);
|
|
269
270
|
// Only call useImageProcessor when the card is visible AND we should load the image AND it's in view
|
|
270
271
|
const { processedImageSrc, isProcessingComplete, cancelProcessing, isProcessing } = useImageProcessor(imageProcessorParams);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
|
-
import { useEditorContext } from '
|
|
3
|
+
import { useEditorContext } from '../../lib/context/EditorContext';
|
|
4
4
|
/**
|
|
5
5
|
* Lightweight hook for components to request image processing
|
|
6
6
|
* Uses the global editor instance via context
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AdjustmentValues } from '
|
|
1
|
+
import type { AdjustmentValues, HonchoEditor } from '../../lib/editor/honcho-editor';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
4
|
HonchoEditor: new () => any;
|
|
@@ -22,7 +22,7 @@ interface UseEditorHeadlessOptions {
|
|
|
22
22
|
wasmUrl?: string;
|
|
23
23
|
}
|
|
24
24
|
export declare function useEditorHeadless(options?: UseEditorHeadlessOptions): {
|
|
25
|
-
editor:
|
|
25
|
+
editor: HonchoEditor | null;
|
|
26
26
|
isReady: boolean;
|
|
27
27
|
error: Error | null;
|
|
28
28
|
processImage: (task: EditorTask) => Promise<EditorResponse>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
3
|
-
import { loadImageAsFile } from '
|
|
3
|
+
import { loadImageAsFile } from '../../utils/imageLoader';
|
|
4
4
|
export function useEditorHeadless(options = {}) {
|
|
5
5
|
const { scriptUrl = '/honcho-photo-editor.js', wasmUrl = '/honcho-photo-editor.wasm' } = options;
|
|
6
6
|
const editorRef = useRef(null);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AdjustmentValues } from '
|
|
1
|
+
import type { AdjustmentValues } from '../../lib/editor/honcho-editor';
|
|
2
2
|
interface UseImageProcessorProps {
|
|
3
3
|
photoId: string;
|
|
4
4
|
photoSrc: string;
|
|
@@ -6,10 +6,13 @@ interface UseImageProcessorProps {
|
|
|
6
6
|
adjustments?: Partial<AdjustmentValues>;
|
|
7
7
|
frame: string | null;
|
|
8
8
|
priority?: 'high' | 'low';
|
|
9
|
+
abortSignal?: AbortSignal;
|
|
9
10
|
}
|
|
10
11
|
interface UseImageProcessorReturn {
|
|
11
12
|
processedImageSrc: string;
|
|
12
13
|
isProcessingComplete: boolean;
|
|
14
|
+
cancelProcessing: () => void;
|
|
15
|
+
isProcessing: boolean;
|
|
13
16
|
}
|
|
14
|
-
export declare function useImageProcessor({ photoId, photoSrc, enableEditor, adjustments, frame, priority, }: UseImageProcessorProps): UseImageProcessorReturn;
|
|
17
|
+
export declare function useImageProcessor({ photoId, photoSrc, enableEditor, adjustments, frame, priority, abortSignal, }: UseImageProcessorProps): UseImageProcessorReturn;
|
|
15
18
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo } from 'react';
|
|
2
|
-
import { useEditorHighPriority, useEditorLowPriority } from '
|
|
1
|
+
import { useState, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useEditorHighPriority, useEditorLowPriority } from '../../lib/hooks/useEditor';
|
|
3
3
|
const initAdjustments = {
|
|
4
4
|
temperature: 0,
|
|
5
5
|
tint: 0,
|
|
@@ -14,13 +14,25 @@ const initAdjustments = {
|
|
|
14
14
|
clarity: 0,
|
|
15
15
|
sharpness: 0
|
|
16
16
|
};
|
|
17
|
-
export function useImageProcessor({ photoId, photoSrc, enableEditor = true, adjustments, frame, priority = 'low', }) {
|
|
17
|
+
export function useImageProcessor({ photoId, photoSrc, enableEditor = true, adjustments, frame, priority = 'low', abortSignal, }) {
|
|
18
18
|
const { processImage, isEditorReady } = priority === 'high'
|
|
19
19
|
? useEditorHighPriority()
|
|
20
20
|
: useEditorLowPriority();
|
|
21
21
|
// State for processed image and processing status
|
|
22
22
|
const [processedImageSrc, setProcessedImageSrc] = useState(photoSrc);
|
|
23
23
|
const [isProcessingComplete, setIsProcessingComplete] = useState(false);
|
|
24
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
25
|
+
// Internal abort controller for this hook
|
|
26
|
+
const abortControllerRef = useRef(null);
|
|
27
|
+
// Function to cancel current processing
|
|
28
|
+
const cancelProcessing = () => {
|
|
29
|
+
if (abortControllerRef.current) {
|
|
30
|
+
abortControllerRef.current.abort();
|
|
31
|
+
abortControllerRef.current = null;
|
|
32
|
+
}
|
|
33
|
+
setIsProcessing(false);
|
|
34
|
+
console.debug(`[useImageProcessor] Cancelled processing for image ${photoId}`);
|
|
35
|
+
};
|
|
24
36
|
// Memoize adjustments to prevent unnecessary effect triggers
|
|
25
37
|
const adjustmentsString = useMemo(() => adjustments ? JSON.stringify(adjustments) : '', [adjustments]);
|
|
26
38
|
const frameMemoized = useMemo(() => frame, [frame]);
|
|
@@ -69,8 +81,21 @@ export function useImageProcessor({ photoId, photoSrc, enableEditor = true, adju
|
|
|
69
81
|
cancelled = true;
|
|
70
82
|
};
|
|
71
83
|
}, [photoSrc, adjustmentsString, frameMemoized, enableEditor, isEditorReady, processImage, photoId]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!abortSignal)
|
|
86
|
+
return;
|
|
87
|
+
const handleAbort = () => {
|
|
88
|
+
cancelProcessing();
|
|
89
|
+
};
|
|
90
|
+
abortSignal.addEventListener('abort', handleAbort);
|
|
91
|
+
return () => {
|
|
92
|
+
abortSignal.removeEventListener('abort', handleAbort);
|
|
93
|
+
};
|
|
94
|
+
}, [abortSignal]);
|
|
72
95
|
return {
|
|
73
96
|
processedImageSrc,
|
|
74
|
-
isProcessingComplete
|
|
97
|
+
isProcessingComplete,
|
|
98
|
+
cancelProcessing,
|
|
99
|
+
isProcessing
|
|
75
100
|
};
|
|
76
101
|
}
|
package/dist/services/type.d.ts
CHANGED