Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 784060b

Browse files
authored
Merge pull request #2145 from umbraco/v14/bugfix/crops-with-label-and-valid
Bugfix: Crops do not show their label and invalid crops are rendered
2 parents 8dca77b + 01966ed commit 784060b

File tree

11 files changed

+59
-62
lines changed

11 files changed

+59
-62
lines changed

src/packages/media/media/components/input-image-cropper/image-cropper-field.element.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
1515
@customElement('umb-image-cropper-field')
1616
export class UmbInputImageCropperFieldElement extends UmbLitElement {
1717
@property({ attribute: false })
18-
get value() {
19-
return this.#value;
20-
}
2118
set value(value) {
2219
if (!value) {
2320
this.crops = [];
@@ -34,6 +31,9 @@ export class UmbInputImageCropperFieldElement extends UmbLitElement {
3431

3532
this.requestUpdate();
3633
}
34+
get value() {
35+
return this.#value;
36+
}
3737
#value?: UmbImageCropperPropertyEditorValue;
3838

3939
@state()

src/packages/media/media/components/input-image-cropper/image-cropper-preview.element.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { UmbImageCropperCrop, UmbImageCropperFocalPoint } from './index.js';
22
import { calculateExtrapolatedValue, clamp } from '@umbraco-cms/backoffice/utils';
3-
import { LitElement, css, html, nothing, customElement, property, query } from '@umbraco-cms/backoffice/external/lit';
3+
import { css, html, nothing, customElement, property, query } from '@umbraco-cms/backoffice/external/lit';
4+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
45

56
@customElement('umb-image-cropper-preview')
6-
export class UmbImageCropperPreviewElement extends LitElement {
7+
export class UmbImageCropperPreviewElement extends UmbLitElement {
78
@query('#image') imageElement!: HTMLImageElement;
89
@query('#container') imageContainerElement!: HTMLImageElement;
910

@@ -150,7 +151,9 @@ export class UmbImageCropperPreviewElement extends LitElement {
150151
<div id="container">
151152
<img id="image" src=${this.src} alt="" />
152153
</div>
153-
<span id="alias">${this.label ?? this.crop.alias}</span>
154+
<span id="alias">
155+
${this.crop.label !== undefined ? this.localize.string(this.crop.label) : (this.label ?? this.crop.alias)}
156+
</span>
154157
<span id="dimensions">${this.crop.width} x ${this.crop.height}</span>
155158
${this.crop.coordinates
156159
? html`<span id="user-defined"><umb-localize key="imagecropper_customCrop">User defined</umb-localize></span>`

src/packages/media/media/components/input-image-cropper/types.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1+
import type { UmbCropModel, UmbFocalPointModel } from '../../types.js';
2+
13
export type UmbImageCropperPropertyEditorValue = {
24
temporaryFileId?: string | null;
3-
crops: Array<{
4-
alias: string;
5-
coordinates?: {
6-
x1: number;
7-
x2: number;
8-
y1: number;
9-
y2: number;
10-
};
11-
height: number;
12-
width: number;
13-
}>;
14-
focalPoint: { left: number; top: number };
5+
crops: Array<UmbCropModel>;
6+
focalPoint: UmbFocalPointModel;
157
src: string;
168
};
179

src/packages/media/media/components/input-rich-media/input-rich-media.element.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UmbInputMediaElement } from '../input-media/index.js';
22
import { UmbMediaItemRepository } from '../../repository/index.js';
33
import { UMB_IMAGE_CROPPER_EDITOR_MODAL, UMB_MEDIA_PICKER_MODAL } from '../../modals/index.js';
4-
import type { UmbCropModel, UmbMediaPickerPropertyValue } from '../../property-editors/index.js';
4+
import type { UmbCropModel, UmbMediaPickerPropertyValue } from '../../types.js';
55
import type { UmbMediaItemModel } from '../../repository/index.js';
66
import type { UmbUploadableFileModel } from '../../dropzone/index.js';
77
import { customElement, html, nothing, property, repeat, state } from '@umbraco-cms/backoffice/external/lit';
@@ -122,13 +122,7 @@ export class UmbInputRichMediaElement extends UUIFormControlMixin(UmbLitElement,
122122
}
123123

124124
@property({ type: Array })
125-
public set preselectedCrops(value: Array<UmbCropModel>) {
126-
this.#preselectedCrops = value;
127-
}
128-
public get preselectedCrops(): Array<UmbCropModel> {
129-
return this.#preselectedCrops;
130-
}
131-
#preselectedCrops: Array<UmbCropModel> = [];
125+
public preselectedCrops?: Array<UmbCropModel>;
132126

133127
@property({ type: Boolean })
134128
public set focalPointEnabled(value: boolean) {

src/packages/media/media/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ export { UMB_MEDIA_PICKER_MODAL } from './modals/media-picker/index.js';
1414

1515
export type { UmbMediaTreeItemModel } from './tree/index.js';
1616
export { UmbMediaAuditLogRepository } from './audit-log/index.js';
17+
18+
export type * from './types.js';

src/packages/media/media/modals/image-cropper-editor/image-cropper-editor-modal.element.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { UmbMediaUrlRepository } from '../../repository/index.js';
22
import { UMB_MEDIA_PICKER_MODAL } from '../media-picker/media-picker-modal.token.js';
3-
import type { UmbCropModel } from '../../property-editors/index.js';
3+
import type { UmbCropModel } from '../../types.js';
44
import type { UmbInputImageCropperFieldElement } from '../../components/input-image-cropper/image-cropper-field.element.js';
55
import type { UmbImageCropperPropertyEditorValue } from '../../components/index.js';
66
import type {
@@ -79,10 +79,21 @@ export class UmbImageCropperEditorModalElement extends UmbModalBaseElement<
7979
const item = data?.[0];
8080

8181
if (!item?.url) return;
82+
83+
/**
84+
* Combine the crops from the property editor with the stored crops and ignore any invalid crops
85+
* (e.g. crops that have been removed from the property editor)
86+
* @remark If a crop is removed from the property editor, it will be ignored and not saved
87+
*/
88+
const crops: Array<UmbCropModel> = this._crops.map((crop) => {
89+
const existingCrop = this.value.crops?.find((c) => c.alias === crop.alias);
90+
return existingCrop ? { ...crop, ...existingCrop } : crop;
91+
});
92+
8293
const value: UmbImageCropperPropertyEditorValue = {
8394
...this.value,
8495
src: item.url,
85-
crops: this.value.crops?.length ? this.value.crops : this._crops,
96+
crops,
8697
focalPoint: this.value.focalPoint ?? { left: 0.5, top: 0.5 },
8798
};
8899
this._imageCropperValue = value;

src/packages/media/media/modals/image-cropper-editor/image-cropper-editor-modal.token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { UmbImageCropperCrop } from '../../components/index.js';
2-
import type { UmbCropModel } from '../../property-editors/index.js';
2+
import type { UmbCropModel } from '../../property-editors/types.js';
33
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
44

55
export interface UmbImageCropperEditorModalData<ItemType> {
Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1 @@
11
export * from './property-editor-ui-media-picker.element.js';
2-
3-
export type UmbMediaPickerPropertyValue = {
4-
key: string;
5-
mediaKey: string;
6-
mediaTypeAlias: string;
7-
focalPoint: UmbFocalPointModel | null;
8-
crops: Array<UmbCropModel>;
9-
};
10-
11-
export type UmbCropModel = {
12-
alias: string;
13-
height: number;
14-
width: number;
15-
coordinates?: {
16-
x1: number;
17-
x2: number;
18-
y1: number;
19-
y2: number;
20-
};
21-
};
22-
23-
export interface UmbConfiguredCropModel {
24-
label: string;
25-
alias: string;
26-
width: number;
27-
height: number;
28-
}
29-
30-
export interface UmbFocalPointModel {
31-
left: number;
32-
top: number;
33-
}

src/packages/media/media/property-editors/media-picker/property-editor-ui-media-picker.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { UmbInputRichMediaElement } from '../../components/input-rich-media/input-rich-media.element.js';
2-
import type { UmbCropModel, UmbMediaPickerPropertyValue } from './index.js';
2+
import type { UmbCropModel, UmbMediaPickerPropertyValue } from '../types.js';
33
import { customElement, html, property, state } from '@umbraco-cms/backoffice/external/lit';
44
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
55
import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export type UmbMediaPickerPropertyValue = {
2+
key: string;
3+
mediaKey: string;
4+
mediaTypeAlias: string;
5+
focalPoint: UmbFocalPointModel | null;
6+
crops: Array<UmbCropModel>;
7+
};
8+
9+
export type UmbCropModel = {
10+
label?: string;
11+
alias: string;
12+
height: number;
13+
width: number;
14+
coordinates?: {
15+
x1: number;
16+
x2: number;
17+
y1: number;
18+
y2: number;
19+
};
20+
};
21+
22+
export interface UmbFocalPointModel {
23+
left: number;
24+
top: number;
25+
}

0 commit comments

Comments
 (0)