Skip to content

Commit 751b7f6

Browse files
authored
Merge pull request #7 from sitegeist/fix/forceCropNoLocked
FIX - Force crop no locked
2 parents 4ec1789 + b4cbfbc commit 751b7f6

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

Neos.Ui/asset-with-metadata-editor/src/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ export function registerAssetWithMetadataEditor(globalRegistry: IGlobalRegistry)
2929
component: (props: any) => {
3030
const { value, ...rest } = props
3131

32-
return <Editor {...rest} value={(!value || Object.keys(value).length === 0) ? undefined : value} />
32+
return <Editor {...rest} value={!value || Object.keys(value).length === 0 ? undefined : value} />
3333
},
3434
})
3535

3636
editorsRegistry.set('Sitegeist.Kaleidoscope.ValueObjects/Inspector/Editors/AssetWithMetadataCollectionEditor', {
3737
component: (props: any) => {
3838
const { value, ...rest } = props
39-
console.log('CollectionEditor Props', props)
4039

41-
return <CollectionEditor {...props} />
40+
return <CollectionEditor {...rest} value={!value || !Array.isArray(value) ? [] : value} />
4241
},
4342
})
4443

Neos.Ui/asset-with-metadata-editor/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ export type EditorOptions = {
4343
}
4444
crop?: {
4545
aspectRatio: {
46-
options?: any
46+
options?: Record<string, { width?: number; height?: number; label: string }>
4747
forceCrop?: boolean
4848
locked?: {
4949
width?: number
5050
height?: number
5151
}
52+
defaultOption?: string
5253
}
5354
}
5455
}

Neos.Ui/asset-with-metadata-editor/src/utils/getForceCrop.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import { EditorOptions, ImageMetadata } from '../types'
22
import { getCropAdjustments } from './getCropAdjustments'
33

4+
const getForcedAspectRatio = (cropOptions: EditorOptions['crop']) => {
5+
if (cropOptions?.aspectRatio.locked?.width && cropOptions?.aspectRatio.locked?.height) {
6+
return (cropOptions?.aspectRatio.locked?.width ?? 0) / (cropOptions?.aspectRatio.locked?.height ?? 0)
7+
}
8+
9+
if (cropOptions?.aspectRatio.defaultOption && cropOptions?.aspectRatio.options) {
10+
const defaultOption = cropOptions?.aspectRatio.options[cropOptions?.aspectRatio.defaultOption]
11+
return (defaultOption.width ?? 0) / (defaultOption.height ?? 0)
12+
}
13+
14+
if (cropOptions?.aspectRatio.options) {
15+
const keys = Object.keys(cropOptions?.aspectRatio.options)
16+
const firstOption = cropOptions?.aspectRatio.options[keys[0]]
17+
return (firstOption.width ?? 0) / (firstOption.height ?? 0)
18+
}
19+
20+
return 0
21+
}
22+
423
export const getForceCrop = (imageMetadata: ImageMetadata, cropOptions: EditorOptions['crop']) => {
5-
const forcedAspectRatio =
6-
(cropOptions?.aspectRatio.locked?.width ?? 0) / (cropOptions?.aspectRatio.locked?.height ?? 0)
24+
const forcedAspectRatio = getForcedAspectRatio(cropOptions)
725

26+
console.log('forcedAspectRatio', forcedAspectRatio)
827
const imageAspectRatio = imageMetadata.originalDimensions.width / imageMetadata.originalDimensions.height
928

1029
if (imageAspectRatio === forcedAspectRatio) return

Resources/Public/JavaScript/Plugin.js

Lines changed: 25 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/Public/JavaScript/Plugin.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)