@yogiswara/honcho-editor-ui 2.6.6 → 2.6.7
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/components/editor/HAccordionPreset.js +30 -30
- package/dist/hooks/demo/HonchoEditorBulkDemo.js +47 -12
- package/dist/hooks/demo/HonchoEditorSingleCleanDemo.js +1 -1
- package/dist/hooks/editor/type.d.ts +1 -1
- package/dist/hooks/editor/useHonchoEditorBulk.d.ts +15 -1
- package/dist/hooks/editor/useHonchoEditorBulk.js +88 -15
- package/dist/hooks/editor/useHonchoEditorSingle.d.ts +2 -1
- package/dist/hooks/editor/useHonchoEditorSingle.js +7 -3
- package/dist/hooks/useAdjustmentHistoryBatch.d.ts +2 -0
- package/dist/hooks/useAdjustmentHistoryBatch.js +478 -206
- package/dist/hooks/usePreset.js +35 -23
- package/package.json +1 -1
package/dist/hooks/usePreset.js
CHANGED
|
@@ -79,9 +79,11 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
79
79
|
try {
|
|
80
80
|
debugLog('Loading presets from backend...');
|
|
81
81
|
const loadedPresets = await stableControllerRef.current.getPresets(stableFirebaseUidRef.current);
|
|
82
|
-
|
|
82
|
+
// Ensure we always have an array
|
|
83
|
+
const presetsArray = Array.isArray(loadedPresets) ? loadedPresets : [];
|
|
84
|
+
setPresets(presetsArray);
|
|
83
85
|
setIsInitialized(true);
|
|
84
|
-
debugLog('Presets loaded successfully', { count:
|
|
86
|
+
debugLog('Presets loaded successfully', { count: presetsArray.length });
|
|
85
87
|
}
|
|
86
88
|
catch (err) {
|
|
87
89
|
handleError('load presets', err);
|
|
@@ -101,11 +103,13 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
101
103
|
// Don't set loading state for background operations
|
|
102
104
|
stableControllerRef.current.getPresets(stableFirebaseUidRef.current)
|
|
103
105
|
.then((loadedPresets) => {
|
|
104
|
-
|
|
106
|
+
// Ensure we always have an array
|
|
107
|
+
const presetsArray = Array.isArray(loadedPresets) ? loadedPresets : [];
|
|
108
|
+
setPresets(presetsArray);
|
|
105
109
|
if (!isInitialized) {
|
|
106
110
|
setIsInitialized(true);
|
|
107
111
|
}
|
|
108
|
-
debugLog('Background presets loaded successfully', { count:
|
|
112
|
+
debugLog('Background presets loaded successfully', { count: presetsArray.length });
|
|
109
113
|
})
|
|
110
114
|
.catch((err) => {
|
|
111
115
|
debugLog('Background load failed:', err);
|
|
@@ -123,11 +127,6 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
123
127
|
setError('Preset name cannot be empty');
|
|
124
128
|
return null;
|
|
125
129
|
}
|
|
126
|
-
// Check for duplicate names
|
|
127
|
-
if (presets.some(p => p.name.toLowerCase() === name.toLowerCase())) {
|
|
128
|
-
setError('A preset with this name already exists');
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
130
|
setIsLoading(true);
|
|
132
131
|
setError(null);
|
|
133
132
|
try {
|
|
@@ -182,13 +181,13 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
182
181
|
setError('Preset name cannot be empty');
|
|
183
182
|
return false;
|
|
184
183
|
}
|
|
185
|
-
const existingPreset = presets.find(p => p.id === presetId);
|
|
184
|
+
const existingPreset = Array.isArray(presets) ? presets.find(p => p.id === presetId) : null;
|
|
186
185
|
if (!existingPreset) {
|
|
187
186
|
setError('Preset not found');
|
|
188
187
|
return false;
|
|
189
188
|
}
|
|
190
189
|
// Check for duplicate names (excluding the current preset)
|
|
191
|
-
if (presets.some(p => p.id !== presetId && p.name.toLowerCase() === newName.toLowerCase())) {
|
|
190
|
+
if (Array.isArray(presets) && presets.some(p => p.id !== presetId && p.name.toLowerCase() === newName.toLowerCase())) {
|
|
192
191
|
setError('A preset with this name already exists');
|
|
193
192
|
return false;
|
|
194
193
|
}
|
|
@@ -218,7 +217,7 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
218
217
|
debugLog('Delete skipped: missing controller or firebaseUid');
|
|
219
218
|
return false;
|
|
220
219
|
}
|
|
221
|
-
const existingPreset = presets.find(p => p.id === presetId);
|
|
220
|
+
const existingPreset = Array.isArray(presets) ? presets.find(p => p.id === presetId) : null;
|
|
222
221
|
if (!existingPreset) {
|
|
223
222
|
setError('Preset not found');
|
|
224
223
|
return false;
|
|
@@ -275,10 +274,10 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
275
274
|
};
|
|
276
275
|
debugLog('Finding preset by adjustments...', adjustments);
|
|
277
276
|
// Find preset that matches the current adjustments
|
|
278
|
-
const matchingPreset = presets.find(preset => {
|
|
277
|
+
const matchingPreset = Array.isArray(presets) ? presets.find(preset => {
|
|
279
278
|
const presetAdjustments = presetToAdjustmentState(preset);
|
|
280
279
|
return adjustmentsMatch(presetAdjustments, adjustments);
|
|
281
|
-
});
|
|
280
|
+
}) : null;
|
|
282
281
|
if (matchingPreset) {
|
|
283
282
|
debugLog('Found matching preset:', matchingPreset);
|
|
284
283
|
return matchingPreset;
|
|
@@ -288,13 +287,23 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
288
287
|
return null;
|
|
289
288
|
}
|
|
290
289
|
}, [presets, debugLog]);
|
|
291
|
-
// Auto-load presets on initialization
|
|
290
|
+
// Auto-load presets on initialization or when firebaseUid becomes available
|
|
292
291
|
useEffect(() => {
|
|
293
|
-
|
|
294
|
-
|
|
292
|
+
const hasValidCredentials = stableControllerRef.current && stableFirebaseUidRef.current;
|
|
293
|
+
const shouldAutoLoad = memoizedOptions.autoLoad && hasValidCredentials;
|
|
294
|
+
if (shouldAutoLoad && !isInitialized) {
|
|
295
|
+
debugLog('Auto-loading presets on initialization...');
|
|
295
296
|
load();
|
|
296
297
|
}
|
|
297
|
-
|
|
298
|
+
else if (shouldAutoLoad && isInitialized) {
|
|
299
|
+
// If we're already initialized but firebaseUid changed to a new valid value, reload
|
|
300
|
+
const firebaseUidChanged = prevStableFirebaseUidRef.current !== stableFirebaseUidRef.current;
|
|
301
|
+
if (firebaseUidChanged && stableFirebaseUidRef.current) {
|
|
302
|
+
debugLog('Auto-loading presets due to firebaseUid change...');
|
|
303
|
+
load();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}, [memoizedOptions.autoLoad, stableControllerRef.current, stableFirebaseUidRef.current, isInitialized, load]);
|
|
298
307
|
// Clear state when controller or firebaseUid changes - but only when they actually change
|
|
299
308
|
useEffect(() => {
|
|
300
309
|
const controllerChanged = prevStableControllerRef.current !== stableControllerRef.current;
|
|
@@ -302,19 +311,22 @@ export function usePreset(controller, firebaseUid, options = {}) {
|
|
|
302
311
|
if ((controllerChanged || firebaseUidChanged) && isInitialized) {
|
|
303
312
|
debugLog('Controller or firebaseUid changed, clearing state');
|
|
304
313
|
setError(null);
|
|
305
|
-
|
|
306
|
-
|
|
314
|
+
// Only reset initialization if firebaseUid became null/empty
|
|
315
|
+
if (firebaseUidChanged && !stableFirebaseUidRef.current) {
|
|
316
|
+
setIsInitialized(false);
|
|
317
|
+
setPresets([]); // Clear presets when user changes
|
|
318
|
+
}
|
|
307
319
|
}
|
|
308
320
|
prevStableControllerRef.current = stableControllerRef.current;
|
|
309
321
|
prevStableFirebaseUidRef.current = stableFirebaseUidRef.current;
|
|
310
|
-
}, [stableControllerRef.current, stableFirebaseUidRef.current, isInitialized]);
|
|
322
|
+
}, [stableControllerRef.current, stableFirebaseUidRef.current, isInitialized, debugLog]);
|
|
311
323
|
// Preset info object - memoized to prevent re-renders
|
|
312
324
|
const info = useMemo(() => ({
|
|
313
325
|
isLoading,
|
|
314
326
|
error,
|
|
315
|
-
count: presets.length,
|
|
327
|
+
count: Array.isArray(presets) ? presets.length : 0,
|
|
316
328
|
isInitialized
|
|
317
|
-
}), [isLoading, error, presets
|
|
329
|
+
}), [isLoading, error, presets, isInitialized]);
|
|
318
330
|
// Actions object - memoized to prevent re-renders when functions don't change
|
|
319
331
|
const actions = useMemo(() => ({
|
|
320
332
|
create,
|