From 57ebbefac7d7cedba6efe0585799686c83c798c8 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 18 Apr 2024 11:02:43 +0100 Subject: [PATCH] DocumentPicker: added configuration options min/max, start node, show open button + code tidyup --- ...perty-editor-ui-document-picker.element.ts | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-editors/document-picker/property-editor-ui-document-picker.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-editors/document-picker/property-editor-ui-document-picker.element.ts index bb8cd1c0f7..816770d679 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-editors/document-picker/property-editor-ui-document-picker.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-editors/document-picker/property-editor-ui-document-picker.element.ts @@ -1,11 +1,10 @@ import type { UmbInputDocumentElement } from '../../components/input-document/input-document.element.js'; import { html, customElement, property, state } from '@umbraco-cms/backoffice/external/lit'; -import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; -import { - UmbPropertyValueChangeEvent, - type UmbPropertyEditorConfigCollection, -} from '@umbraco-cms/backoffice/property-editor'; +import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor'; +import type { NumberRangeValueType } from '@umbraco-cms/backoffice/models'; +import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor'; +import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry'; @customElement('umb-property-editor-ui-document-picker') export class UmbPropertyEditorUIDocumentPickerElement extends UmbLitElement implements UmbPropertyEditorUiElement { @@ -13,34 +12,47 @@ export class UmbPropertyEditorUIDocumentPickerElement extends UmbLitElement impl public value?: string; public set config(config: UmbPropertyEditorConfigCollection | undefined) { - const validationLimit = config?.find((x) => x.alias === 'validationLimit'); + if (!config) return; - this._limitMin = (validationLimit?.value as any)?.min; - this._limitMax = (validationLimit?.value as any)?.max; - } - public get config() { - return undefined; + const minMax = config?.getValueByAlias('validationLimit'); + this.min = minMax?.min ?? 0; + this.max = minMax?.max ?? Infinity; + + this.ignoreUserStartNodes = config?.getValueByAlias('ignoreUserStartNodes'); + this.startNodeId = config?.getValueByAlias('startNodeId'); + this.showOpenButton = config?.getValueByAlias('showOpenButton'); } @state() - private _limitMin?: number; - @state() - private _limitMax?: number; + min = 0; - private _onChange(event: CustomEvent) { - this.value = (event.target as UmbInputDocumentElement).selection.join(','); + @state() + max = Infinity; + + @state() + startNodeId?: string; + + @state() + showOpenButton?: boolean; + + @state() + ignoreUserStartNodes?: boolean; + + #onChange(event: CustomEvent & { target: UmbInputDocumentElement }) { + this.value = event.target.selection.join(','); this.dispatchEvent(new UmbPropertyValueChangeEvent()); } - // TODO: Implement mandatory? render() { return html` - Add + ?showOpenButton=${this.showOpenButton} + ?ignoreUserStartNodes=${this.ignoreUserStartNodes} + @change=${this.#onChange}> `; }