From 1a6e97b4e9df3c97dc71a2eea7b07f0587710a55 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 4 Apr 2024 11:23:47 +0100 Subject: [PATCH] Package Builder: Stylesheet Picker --- .../workspace-package-builder.element.ts | 29 +++++++++++++++---- .../stylesheet-input.context.ts | 2 +- .../stylesheet-input.element.ts | 9 +++--- ...y-mce-stylesheets-configuration.element.ts | 2 +- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/packages/package-builder/workspace/workspace-package-builder.element.ts b/src/Umbraco.Web.UI.Client/src/packages/packages/package-builder/workspace/workspace-package-builder.element.ts index 2db1e739f7..f8f920335c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/packages/package-builder/workspace/workspace-package-builder.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/packages/package-builder/workspace/workspace-package-builder.element.ts @@ -1,6 +1,7 @@ import { UmbDictionaryPickerContext } from '../../../dictionary/components/input-dictionary/input-dictionary.context.js'; import { UmbMediaPickerContext } from '../../../media/media/components/input-media/input-media.context.js'; import { UmbPackageRepository } from '../../package/repository/index.js'; +import { UmbStylesheetPickerContext } from '../../../templating/stylesheets/components/stylesheet-input/stylesheet-input.context.js'; import { UmbTemplatePickerContext } from '../../../templating/templates/components/input-template/input-template.context.js'; import type { UmbCreatedPackageDefinition } from '../../types.js'; import type { UmbDataTypeInputElement } from '../../../data-type/components/data-type-input/data-type-input.element.js'; @@ -185,10 +186,7 @@ export class UmbWorkspacePackageBuilderElement extends UmbLitElement { ${this.#renderDictionarySection()} ${this.#renderDataTypeSection()} ${this.#renderTemplateSection()} - - ${this.#renderStylesheetsSection()} - ${this.#renderScriptsSection()} @@ -370,10 +368,29 @@ export class UmbWorkspacePackageBuilderElement extends UmbLitElement { `; } + #onStylesheetsChange(event: { target: UmbInputEntityElement }) { + if (!this._package) return; + + this._package.stylesheets = + event.target.selection?.map((path) => this.#serverFilePathUniqueSerializer.toServerPath(path) as string) ?? []; + this.requestUpdate('_package'); + } + #renderStylesheetsSection() { - return html`
- -
`; + if (!this._package) return nothing; + return html` + +
+ 'icon-brush-alt'} + .pickerContext=${UmbStylesheetPickerContext} + .selection=${this._package.stylesheets.map((path) => this.#serverFilePathUniqueSerializer.toUnique(path)) ?? + []} + @change=${this.#onStylesheetsChange}> + +
+
+ `; } #renderScriptsSection() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.context.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.context.ts index 939cc969ca..06b93a6bca 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.context.ts @@ -9,6 +9,6 @@ export class UmbStylesheetPickerContext extends UmbPickerInputContext item.unique); + super(host, UMB_STYLESHEET_ITEM_REPOSITORY_ALIAS, UMB_STYLESHEET_PICKER_MODAL); } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.element.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.element.ts index 3d3784132c..dc6c8babf3 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/components/stylesheet-input/stylesheet-input.element.ts @@ -53,11 +53,12 @@ export class UmbStylesheetInputElement extends FormControlMixin(UmbLitElement) { @property({ type: String, attribute: 'min-message' }) maxMessage = 'This field exceeds the allowed amount of items'; - public get selection(): Array { - return this.#pickerContext.getSelection(); + @property({ type: Array }) + public set selection(ids: Array | undefined) { + this.#pickerContext.setSelection(ids ?? []); } - public set selection(ids: Array) { - this.#pickerContext.setSelection(ids); + public get selection(): Array | undefined { + return this.#pickerContext.getSelection(); } @property() diff --git a/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/stylesheets/property-editor-ui-tiny-mce-stylesheets-configuration.element.ts b/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/stylesheets/property-editor-ui-tiny-mce-stylesheets-configuration.element.ts index 062837d269..2b83720faf 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/stylesheets/property-editor-ui-tiny-mce-stylesheets-configuration.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/tiny-mce/property-editors/stylesheets/property-editor-ui-tiny-mce-stylesheets-configuration.element.ts @@ -32,7 +32,7 @@ export class UmbPropertyEditorUITinyMceStylesheetsConfigurationElement #onChange(event: CustomEvent) { const target = event.target as UmbStylesheetInputElement; - this._value = target.selection; + this._value = target.selection ?? []; this.dispatchEvent(new UmbPropertyValueChangeEvent()); }