config element update

This commit is contained in:
Niels Lyngsø
2024-05-26 09:50:42 +02:00
parent e4f279c341
commit 4901f6840b

View File

@@ -1,5 +1,4 @@
import type { UmbBlockTypeBaseModel } from '@umbraco-cms/backoffice/block-type';
import { UmbInputBlockTypeElement } from '@umbraco-cms/backoffice/block-type';
import type { UmbBlockTypeBaseModel, UmbInputBlockTypeElement } from '@umbraco-cms/backoffice/block-type';
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
import { html, customElement, property, state } from '@umbraco-cms/backoffice/external/lit';
import {
@@ -7,6 +6,9 @@ import {
type UmbPropertyEditorConfigCollection,
} from '@umbraco-cms/backoffice/property-editor';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
import { UMB_WORKSPACE_MODAL } from '@umbraco-cms/backoffice/modal';
import { UMB_BLOCK_RTE_TYPE } from '@umbraco-cms/backoffice/block-rte';
/**
* @element umb-property-editor-ui-block-rte-type-configuration
@@ -16,39 +18,54 @@ export class UmbPropertyEditorUIBlockRteBlockConfigurationElement
extends UmbLitElement
implements UmbPropertyEditorUiElement
{
@property({ attribute: false })
public set value(value: UmbBlockTypeBaseModel[]) {
this._value = value ?? [];
}
public get value() {
return this._value;
}
#blockTypeWorkspaceModalRegistration?: UmbModalRouteRegistrationController<
typeof UMB_WORKSPACE_MODAL.DATA,
typeof UMB_WORKSPACE_MODAL.VALUE
>;
@state()
private _value: UmbBlockTypeBaseModel[] = [];
private _workspacePath?: string;
constructor() {
super();
this.#blockTypeWorkspaceModalRegistration?.destroy();
this.#blockTypeWorkspaceModalRegistration = new UmbModalRouteRegistrationController(this, UMB_WORKSPACE_MODAL)
.addAdditionalPath(UMB_BLOCK_RTE_TYPE)
.onSetup(() => {
return { data: { entityType: UMB_BLOCK_RTE_TYPE, preset: {} }, modal: { size: 'large' } };
})
.observeRouteBuilder((routeBuilder) => {
const newpath = routeBuilder({});
this._workspacePath = newpath;
});
}
@property({ attribute: false })
value: UmbBlockTypeBaseModel[] = [];
@property({ type: Object, attribute: false })
public config?: UmbPropertyEditorConfigCollection;
#onCreate(e: CustomEvent) {
const key = e.detail.contentElementTypeKey;
this.value = [...this._value, { contentElementTypeKey: key, forceHideContentEditorInOverlay: false }];
this.dispatchEvent(new UmbPropertyValueChangeEvent());
const selectedElementType = e.detail.contentElementTypeKey;
if (selectedElementType) {
this.#blockTypeWorkspaceModalRegistration?.open({}, 'create/' + selectedElementType + '/null');
}
}
#onChange(e: CustomEvent) {
e.stopPropagation();
this.value = (e.target as UmbInputBlockTypeElement).value;
this.dispatchEvent(new UmbPropertyValueChangeEvent());
}
render() {
return UmbInputBlockTypeElement
? html`<umb-input-block-type
entity-type="block-rte-type"
.value=${this.value}
@create=${this.#onCreate}
@change=${this.#onChange}
@delete=${this.#onChange}></umb-input-block-type>`
: '';
return html`<umb-input-block-type
entity-type="block-rte-type"
.value=${this.value}
@create=${this.#onCreate}
@change=${this.#onChange}
@delete=${this.#onChange}></umb-input-block-type>`;
}
}