From 081bdadc4ede06c1c405d234713aef5a3e63ead4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilyas=20T=C3=BCrkben?= Date: Mon, 23 Dec 2024 18:10:37 +0100 Subject: [PATCH] MWPW-161354: toggle used/unused fields MWPW-162449: convert size field to dropdown --- studio/src/editors/merch-card-editor.js | 219 +++++++++++++++--------- studio/src/rte/rte-field.js | 1 - 2 files changed, 136 insertions(+), 84 deletions(-) diff --git a/studio/src/editors/merch-card-editor.js b/studio/src/editors/merch-card-editor.js index bdc8231..65a656e 100644 --- a/studio/src/editors/merch-card-editor.js +++ b/studio/src/editors/merch-card-editor.js @@ -12,12 +12,15 @@ import { Fragment } from '../aem/fragment.js'; const MODEL_PATH = '/conf/mas/settings/dam/cfm/models/card'; +const merchCardCustomElementPromise = customElements.whenDefined('merch-card'); + class MerchCardEditor extends LitElement { static properties = { refreshing: { state: true, attribute: true }, disabled: { state: true, attribute: true }, hasChanges: { state: true, attribute: true }, loading: { state: true, attribute: true }, + superWide: { type: Boolean, state: true }, }; createRenderRoot() { @@ -30,6 +33,7 @@ class MerchCardEditor extends LitElement { this.refreshing = false; this.hasChanges = false; this.loading = false; + this.superWide = false; this.handleKeyDown = this.handleKeyDown.bind(this); this.close = this.close.bind(this); this.discardChanges = this.discardChanges.bind(this); @@ -167,6 +171,28 @@ class MerchCardEditor extends LitElement { ); } + updated() { + this.toggleFields(); + } + + async toggleFields() { + if (!this.fragment) return; + const merchCardCustomElement = await merchCardCustomElementPromise; + if (!merchCardCustomElement) return; + this.querySelectorAll('sp-field-group.toggle').forEach((field) => { + field.style.display = 'none'; + }); + const variant = merchCardCustomElement.getFragmentMapping( + this.fragment.variant, + ); + if (!variant) return; + Object.keys(variant).forEach((key) => { + const field = this.querySelector(`sp-field-group.toggle#${key}`); + if (field) field.style.display = 'block'; + }); + this.superWide = variant.size?.includes('super-wide'); + } + render() { if (this.loading) return html`
@@ -184,85 +210,107 @@ class MerchCardEditor extends LitElement { return html`
${this.toolbar}

${this.fragment.path}

- Variant - - Title - - Subtitle - - Size - - Badge - - Mnemonics - - - - Background Image - - Background Image Alt Text - - Prices - + + Variant + + + + Size + + Normal + Wide + ${this.superWide + ? html`Super wide` + : nothing} + + + + Title + + + + Subtitle + + + + Badge + + + + Mnemonics + + + + + + Background Image + + Background Image Alt Text + + + + Prices ${unsafeHTML(form.prices.values[0])} - Description - + + Description ${unsafeHTML(form.description.values[0])} - Footer - + + Footer `; } + #handleVariantChange(e) { + this.#updateFragment(e); + this.toggleFields(); + } + #handeTagsChange(e) { const value = e.target.getAttribute('value'); const newTags = value ? value.split(',') : []; // do not overwrite the tags array diff --git a/studio/src/rte/rte-field.js b/studio/src/rte/rte-field.js index 559a83c..e69054a 100644 --- a/studio/src/rte/rte-field.js +++ b/studio/src/rte/rte-field.js @@ -93,7 +93,6 @@ class RteField extends LitElement { gap: 8px; flex-direction: column; font-size: var(--spectrum-font-size-200); - padding: 6px; } :host([focused]) #editor {