Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Image Cropper, focal point reset #1951

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
UmbImageCropperFocalPoint,
UmbImageCropperPropertyEditorValue,
} from './index.js';
import { css, html, customElement, property, state, repeat, nothing } from '@umbraco-cms/backoffice/external/lit';
import { css, customElement, html, property, repeat, state, when } from '@umbraco-cms/backoffice/external/lit';
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';

Expand Down Expand Up @@ -151,11 +151,13 @@ export class UmbInputImageCropperFieldElement extends UmbLitElement {
</umb-image-cropper-focus-setter>
<div id="actions">
<slot name="actions"></slot>
${!this.hideFocalPoint
? html`<uui-button
${when(
!this.hideFocalPoint,
() =>
html`<uui-button
label=${this.localize.term('content_resetFocalPoint')}
@click=${this.#onResetFocalPoint}></uui-button>`
: nothing}
@click=${this.#onResetFocalPoint}></uui-button>`,
)}
</div>
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class UmbImageCropperFocusSetterElement extends LitElement {
protected updated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
super.updated(_changedProperties);

if (!this.hideFocalPoint) return;
if (this.hideFocalPoint) return;

if (_changedProperties.has('focalPoint') && this.focalPointElement) {
this.focalPointElement.style.left = `calc(${this.focalPoint.left * 100}% - ${this.#DOT_RADIUS}px)`;
Expand Down Expand Up @@ -142,14 +142,14 @@ export class UmbImageCropperFocusSetterElement extends LitElement {

render() {
if (!this.src) return nothing;

return html`
<div id="wrapper">
<img id="image" @click=${this.#onSetFocalPoint} @keydown=${() => nothing} src=${this.src} alt="" />
<div id="focal-point" class=${this.hideFocalPoint ? 'hidden' : ''}></div>
</div>
`;
}

static styles = css`
:host {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ export class UmbImageCropperEditorModalElement extends UmbModalBaseElement<
this.#getSrc();
}

#onChange(e: CustomEvent) {
const value = (e.target as UmbInputImageCropperFieldElement).value;
#onChange(e: CustomEvent & { target: UmbInputImageCropperFieldElement }) {
const value = e.target.value;
if (!value) return;

if (this._imageCropperValue) {
this._imageCropperValue.crops = value.crops;
this._imageCropperValue.focalPoint = value.focalPoint;
}

this.value = { key: this._key, unique: this._unique, crops: value.crops, focalPoint: value.focalPoint };
}

Expand All @@ -124,22 +129,24 @@ export class UmbImageCropperEditorModalElement extends UmbModalBaseElement<
}

#renderBody() {
return html`<div id="layout">
<umb-image-cropper-field
.value=${this._imageCropperValue}
?hideFocalPoint=${this._hideFocalPoint}
@change=${this.#onChange}></umb-image-cropper-field>
<div id="options">
<uui-menu-item @click=${this.#openMediaPicker} label=${this.localize.term('mediaPicker_changeMedia')}>
<umb-icon slot="icon" name="icon-search"></umb-icon>
</uui-menu-item>
<uui-menu-item
href=${this._editMediaPath + 'edit/' + this._unique}
label=${this.localize.term('mediaPicker_openMedia')}>
<umb-icon slot="icon" name="icon-out"></umb-icon>
</uui-menu-item>
return html`
<div id="layout">
<umb-image-cropper-field
.value=${this._imageCropperValue}
?hideFocalPoint=${this._hideFocalPoint}
@change=${this.#onChange}></umb-image-cropper-field>
<div id="options">
<uui-menu-item @click=${this.#openMediaPicker} label=${this.localize.term('mediaPicker_changeMedia')}>
<umb-icon slot="icon" name="icon-search"></umb-icon>
</uui-menu-item>
<uui-menu-item
href=${this._editMediaPath + 'edit/' + this._unique}
label=${this.localize.term('mediaPicker_openMedia')}>
<umb-icon slot="icon" name="icon-out"></umb-icon>
</uui-menu-item>
</div>
</div>
</div>`;
`;
}

static styles = [
Expand Down