diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media/property-editors/image-crops/property-editor-ui-image-crops.element.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media/property-editors/image-crops/property-editor-ui-image-crops.element.ts index 54ff9f9b0f..74728a089b 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media/property-editors/image-crops/property-editor-ui-image-crops.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media/property-editors/image-crops/property-editor-ui-image-crops.element.ts @@ -4,6 +4,7 @@ import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/propert import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor'; import { generateAlias } from '@umbraco-cms/backoffice/utils'; +import { UmbSorterController } from '@umbraco-cms/backoffice/sorter'; export type UmbCrop = { label: string; @@ -20,14 +21,42 @@ export class UmbPropertyEditorUIImageCropsElement extends UmbLitElement implemen @query('#label') private _labelInput!: HTMLInputElement; - @property({ attribute: false }) - value: UmbCrop[] = []; + @state() + private _value: Array = []; + + @property({ type: Array }) + public set value(value: Array) { + this._value = value ?? []; + this.#sorter.setModel(this.value); + } + public get value(): Array { + return this._value; + } @state() editCropAlias = ''; #oldInputValue = ''; + #sorter = new UmbSorterController(this, { + getUniqueOfElement: (element: HTMLElement) => { + const unique = element.dataset["alias"]; + return unique; + }, + getUniqueOfModel: (modelEntry: UmbCrop) => { + return modelEntry.alias; + }, + identifier: 'Umb.SorterIdentifier.ImageCrops', + itemSelector: '.crop', + containerSelector: '.crops', + onChange: ({ model }) => { + const oldValue = this._value; + this._value = model; + this.requestUpdate('_value', oldValue); + this.dispatchEvent(new UmbPropertyValueChangeEvent()); + }, + }); + #onRemove(alias: string) { this.value = [...this.value.filter((item) => item.alias !== alias)]; this.dispatchEvent(new UmbPropertyValueChangeEvent()); @@ -163,7 +192,7 @@ export class UmbPropertyEditorUIImageCropsElement extends UmbLitElement implemen this.value, (item) => item.alias, (item) => html` -
+
+ ${item.label} (${item.alias}) (${item.width} x ${item.height}px)