@yogiswara/honcho-editor-ui 3.4.15 → 3.4.17

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.
@@ -61,6 +61,7 @@ export declare function useHonchoEditorBulk(controller: Controller, eventID: str
61
61
  presets: Preset[];
62
62
  selectedBulkPreset: string;
63
63
  activePreset: Preset | null;
64
+ presetSummary: string;
64
65
  handleSelectBulkPreset: (presetId: string) => void;
65
66
  clearSelection: () => void;
66
67
  selectAllImages: () => void;
@@ -161,39 +161,87 @@ export function useHonchoEditorBulk(controller, eventID, firebaseUid) {
161
161
  const currentAdjustments = useMemo(() => {
162
162
  return getCurrentAdjustmentsForCopy(selectedIds, currentBatch);
163
163
  }, [selectedIds, currentBatch]);
164
+ const areAdjustmentsEqual = (adj1, adj2) => {
165
+ // The fix is to use this more specific type for our keys array
166
+ const keys = [
167
+ 'tempScore', 'tintScore', 'saturationScore', 'vibranceScore',
168
+ 'exposureScore', 'contrastScore', 'highlightsScore', 'shadowsScore',
169
+ 'whitesScore', 'blacksScore', 'clarityScore', 'sharpnessScore'
170
+ ];
171
+ for (const key of keys) {
172
+ // Now, TypeScript knows `key` can't be 'preset_id', so adj1[key] will be a number.
173
+ if (Math.round(adj1[key] || 0) !== Math.round(adj2[key] || 0)) {
174
+ return false;
175
+ }
176
+ }
177
+ return true;
178
+ };
164
179
  // Calculate active preset based on preset_id from history (not value comparison)
165
- const activePreset = useMemo(() => {
180
+ const { activePreset, presetSummary } = useMemo(() => {
166
181
  if (selectedIds.length === 0) {
167
- return null;
182
+ return { activePreset: null, presetSummary: 'NO_SELECTION' };
168
183
  }
169
- // Get preset_id for all selected images from current batch
170
- const selectedPresetIds = selectedIds.map(imageId => {
171
- const adjustment = currentBatch.allImages[imageId];
172
- return adjustment?.preset_id;
184
+ const imageDetails = selectedIds.map(id => {
185
+ const adjustment = currentBatch.allImages[id];
186
+ const presetId = adjustment?.preset_id || null;
187
+ // Check if preset exists in our presets list
188
+ const matchingPreset = presetId ? presets.find(p => p.id === presetId) : null;
189
+ // Check if the adjustment values actually match the preset values
190
+ let hasValidMatchingPreset = false;
191
+ if (matchingPreset && adjustment) {
192
+ const presetAdjustments = presetToAdjustmentState(matchingPreset);
193
+ hasValidMatchingPreset = areAdjustmentsEqual(adjustment, presetAdjustments);
194
+ }
195
+ return {
196
+ imageId: id,
197
+ presetId,
198
+ matchingPreset,
199
+ hasValidMatchingPreset,
200
+ adjustmentValues: adjustment
201
+ };
173
202
  });
174
- // Get the first preset_id to compare against
175
- const firstPresetId = selectedPresetIds[0];
176
- // Check if all selected images have the same preset_id
177
- const allSamePresetId = selectedPresetIds.every(presetId => presetId === firstPresetId);
178
- if (!allSamePresetId || !firstPresetId) {
179
- // Either not all images have the same preset_id, or no preset_id at all
180
- return null;
181
- }
182
- // Find the preset that matches the common preset_id
183
- const matchingPreset = presets.find(preset => preset.id === firstPresetId);
184
- log.debug({
203
+ console.log('Debug preset calculation (with custom check):', {
185
204
  selectedIds,
186
- selectedPresetIds,
187
- firstPresetId,
188
- allSamePresetId,
189
- matchingPreset: matchingPreset?.name || 'none',
190
- selectedImageAdjustments: selectedIds.map(id => ({
191
- imageId: id,
192
- preset_id: currentBatch.allImages[id]?.preset_id,
193
- hasAdjustment: !!currentBatch.allImages[id]
205
+ imageDetails: imageDetails.map(detail => ({
206
+ imageId: detail.imageId,
207
+ presetId: detail.presetId,
208
+ presetName: detail.matchingPreset?.name || 'N/A',
209
+ hasValidMatchingPreset: detail.hasValidMatchingPreset,
210
+ isCustomAdjustment: detail.presetId && !detail.hasValidMatchingPreset
194
211
  }))
195
- }, '[useHonchoEditorBulk] 🎨 Active preset calculation');
196
- return matchingPreset || null;
212
+ });
213
+ // Get images that have ACTUALLY matching presets (not just preset IDs)
214
+ const imagesWithValidPresets = imageDetails.filter(detail => detail.hasValidMatchingPreset);
215
+ const validPresetIds = imagesWithValidPresets.map(detail => detail.presetId);
216
+ const uniqueValidPresetIds = new Set(validPresetIds);
217
+ // Case 1: No images have actually matching presets
218
+ // This includes: no preset_id, non-existent preset_id, or preset_id with modified values
219
+ if (imagesWithValidPresets.length === 0) {
220
+ console.log('Case 1: No images have valid matching presets - showing Select');
221
+ return { activePreset: null, presetSummary: 'NO_SELECTION' };
222
+ }
223
+ // Case 2: Some images have valid matching presets, some don't (mixed state)
224
+ if (imagesWithValidPresets.length > 0 && imagesWithValidPresets.length < selectedIds.length) {
225
+ console.log('Case 2: Mixed preset state (some valid, some custom/none) - showing Multiple presets');
226
+ return { activePreset: null, presetSummary: 'MULTIPLE_PRESETS' };
227
+ }
228
+ // Case 3: All images have valid matching presets, but different ones
229
+ if (uniqueValidPresetIds.size > 1) {
230
+ console.log('Case 3: Multiple different valid presets - showing Multiple presets');
231
+ return { activePreset: null, presetSummary: 'MULTIPLE_PRESETS' };
232
+ }
233
+ // Case 4: All images have the same valid matching preset
234
+ const singleValidPresetId = Array.from(uniqueValidPresetIds)[0];
235
+ const matchingPreset = presets.find(p => p.id === singleValidPresetId);
236
+ if (matchingPreset) {
237
+ console.log('Case 4: All images have the same valid matching preset');
238
+ return { activePreset: matchingPreset, presetSummary: 'SINGLE' };
239
+ }
240
+ else {
241
+ // This shouldn't happen given our filtering above, but safety check
242
+ console.log('Case 4 safety check failed - showing Select');
243
+ return { activePreset: null, presetSummary: 'NO_SELECTION' };
244
+ }
197
245
  }, [selectedIds, currentBatch.allImages, presets]);
198
246
  // Update selectedBulkPreset when activePreset changes
199
247
  useEffect(() => {
@@ -458,6 +506,7 @@ export function useHonchoEditorBulk(controller, eventID, firebaseUid) {
458
506
  presets,
459
507
  selectedBulkPreset,
460
508
  activePreset,
509
+ presetSummary,
461
510
  handleSelectBulkPreset,
462
511
  clearSelection,
463
512
  selectAllImages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "3.4.15",
3
+ "version": "3.4.17",
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",