|
1 | 1 | import type { ActiveVariant } from '../../controllers/index.js'; |
2 | 2 | import { UMB_WORKSPACE_SPLIT_VIEW_CONTEXT } from './workspace-split-view.context.js'; |
3 | | -import { |
4 | | - type UUIInputElement, |
5 | | - UUIInputEvent, |
6 | | - type UUIPopoverContainerElement, |
7 | | -} from '@umbraco-cms/backoffice/external/uui'; |
8 | | -import { |
9 | | - css, |
10 | | - html, |
11 | | - nothing, |
12 | | - customElement, |
13 | | - state, |
14 | | - query, |
15 | | - ifDefined, |
16 | | - type TemplateResult, |
17 | | -} from '@umbraco-cms/backoffice/external/lit'; |
18 | | -import { |
19 | | - UmbVariantId, |
20 | | - type UmbEntityVariantModel, |
21 | | - type UmbEntityVariantOptionModel, |
22 | | -} from '@umbraco-cms/backoffice/variant'; |
23 | | -import { UMB_PROPERTY_DATASET_CONTEXT, isNameablePropertyDatasetContext } from '@umbraco-cms/backoffice/property'; |
24 | | -import { UmbLitElement, umbFocus } from '@umbraco-cms/backoffice/lit-element'; |
| 3 | +import { css, customElement, html, ifDefined, nothing, query, ref, state } from '@umbraco-cms/backoffice/external/lit'; |
| 4 | +import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; |
25 | 5 | import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; |
26 | | -import type { UmbVariantState } from '@umbraco-cms/backoffice/utils'; |
| 6 | +import { UmbVariantId } from '@umbraco-cms/backoffice/variant'; |
27 | 7 | import { UmbDataPathVariantQuery, umbBindToValidation } from '@umbraco-cms/backoffice/validation'; |
| 8 | +import { UMB_PROPERTY_DATASET_CONTEXT, isNameablePropertyDatasetContext } from '@umbraco-cms/backoffice/property'; |
| 9 | +import { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui'; |
28 | 10 | import type { UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content'; |
| 11 | +import type { UmbEntityVariantModel, UmbEntityVariantOptionModel } from '@umbraco-cms/backoffice/variant'; |
| 12 | +import type { UmbVariantState } from '@umbraco-cms/backoffice/utils'; |
| 13 | +import type { UUIInputElement, UUIPopoverContainerElement } from '@umbraco-cms/backoffice/external/uui'; |
29 | 14 |
|
30 | | -const elementName = 'umb-workspace-split-view-variant-selector'; |
31 | | -@customElement(elementName) |
| 15 | +@customElement('umb-workspace-split-view-variant-selector') |
32 | 16 | export class UmbWorkspaceSplitViewVariantSelectorElement< |
33 | 17 | VariantOptionModelType extends |
34 | 18 | UmbEntityVariantOptionModel<UmbEntityVariantModel> = UmbEntityVariantOptionModel<UmbEntityVariantModel>, |
@@ -220,66 +204,74 @@ export class UmbWorkspaceSplitViewVariantSelectorElement< |
220 | 204 | this._popoverElement.style.width = `${host.width}px`; |
221 | 205 | } |
222 | 206 |
|
| 207 | + /** |
| 208 | + * Focuses the input element after a short delay to ensure it is rendered. |
| 209 | + * This works better than the {umbFocus()} directive, which does not work in this context. |
| 210 | + */ |
| 211 | + #focusInput(element?: Element) { |
| 212 | + if (!element) return; |
| 213 | + |
| 214 | + setTimeout(async () => { |
| 215 | + await this.updateComplete; |
| 216 | + (element as UUIInputElement)?.focus(); |
| 217 | + }, 200); |
| 218 | + } |
| 219 | + |
223 | 220 | override render() { |
224 | | - return this._variantId |
225 | | - ? html` |
| 221 | + if (!this._variantId) return nothing; |
| 222 | + |
| 223 | + return html` |
226 | 224 | <uui-input |
227 | 225 | id="name-input" |
228 | 226 | data-mark="input:entity-name" |
| 227 | + placeholder=${this.localize.term('placeholders_entername')} |
229 | 228 | label=${this.localize.term('placeholders_entername')} |
230 | 229 | .value=${this._name ?? ''} |
231 | 230 | @input=${this.#handleInput} |
232 | 231 | required |
233 | 232 | ?readonly=${this.#isReadOnly(this._activeVariant?.culture ?? null)} |
234 | 233 | ${umbBindToValidation(this, `$.variants[${UmbDataPathVariantQuery(this._variantId)}].name`, this._name ?? '')} |
235 | | - ${umbFocus()} |
236 | | - > |
237 | | - ${ |
238 | | - this.#hasVariants() |
239 | | - ? html` |
240 | | - <uui-button |
241 | | - id="variant-selector-toggle" |
242 | | - compact |
243 | | - slot="append" |
244 | | - popovertarget="variant-selector-popover" |
245 | | - title=${ifDefined(this._activeVariant?.language.name)} |
246 | | - label="Select a variant"> |
247 | | - ${this._activeVariant?.language.name} ${this.#renderReadOnlyTag(this._activeVariant?.culture)} |
248 | | - <uui-symbol-expand .open=${this._variantSelectorOpen}></uui-symbol-expand> |
249 | | - </uui-button> |
250 | | - ${this._activeVariants.length > 1 |
251 | | - ? html` |
252 | | - <uui-button slot="append" compact id="variant-close" @click=${this.#closeSplitView}> |
253 | | - <uui-icon name="remove"></uui-icon> |
254 | | - </uui-button> |
255 | | - ` |
256 | | - : ''} |
257 | | - ` |
258 | | - : nothing |
259 | | - } |
260 | | - </uui-input> |
261 | | -
|
262 | | - ${ |
263 | | - this.#hasVariants() |
| 234 | + ${ref(this.#focusInput)}> |
| 235 | + ${this.#hasVariants() |
264 | 236 | ? html` |
265 | | - <uui-popover-container |
266 | | - id="variant-selector-popover" |
267 | | - @beforetoggle=${this.#onPopoverToggle} |
268 | | - placement="bottom-end"> |
269 | | - <div id="variant-selector-dropdown"> |
270 | | - <uui-scroll-container> |
271 | | - <ul> |
272 | | - ${this._variantOptions.map((variant) => this.#renderListItem(variant))} |
273 | | - </ul> |
274 | | - </uui-scroll-container> |
275 | | - </div> |
276 | | - </uui-popover-container> |
| 237 | + <uui-button |
| 238 | + id="variant-selector-toggle" |
| 239 | + compact |
| 240 | + slot="append" |
| 241 | + popovertarget="variant-selector-popover" |
| 242 | + title=${ifDefined(this._activeVariant?.language.name)} |
| 243 | + label="Select a variant"> |
| 244 | + ${this._activeVariant?.language.name} ${this.#renderReadOnlyTag(this._activeVariant?.culture)} |
| 245 | + <uui-symbol-expand .open=${this._variantSelectorOpen}></uui-symbol-expand> |
| 246 | + </uui-button> |
| 247 | + ${this._activeVariants.length > 1 |
| 248 | + ? html` |
| 249 | + <uui-button slot="append" compact id="variant-close" @click=${this.#closeSplitView}> |
| 250 | + <uui-icon name="remove"></uui-icon> |
| 251 | + </uui-button> |
| 252 | + ` |
| 253 | + : ''} |
277 | 254 | ` |
278 | | - : nothing |
279 | | - } |
280 | | - </div> |
281 | | - ` |
282 | | - : nothing; |
| 255 | + : nothing} |
| 256 | + </uui-input> |
| 257 | +
|
| 258 | + ${this.#hasVariants() |
| 259 | + ? html` |
| 260 | + <uui-popover-container |
| 261 | + id="variant-selector-popover" |
| 262 | + @beforetoggle=${this.#onPopoverToggle} |
| 263 | + placement="bottom-end"> |
| 264 | + <div id="variant-selector-dropdown"> |
| 265 | + <uui-scroll-container> |
| 266 | + <ul> |
| 267 | + ${this._variantOptions.map((variant) => this.#renderListItem(variant))} |
| 268 | + </ul> |
| 269 | + </uui-scroll-container> |
| 270 | + </div> |
| 271 | + </uui-popover-container> |
| 272 | + ` |
| 273 | + : nothing} |
| 274 | + `; |
283 | 275 | } |
284 | 276 |
|
285 | 277 | #renderListItem(variantOption: VariantOptionModelType) { |
@@ -313,7 +305,7 @@ export class UmbWorkspaceSplitViewVariantSelectorElement< |
313 | 305 | } |
314 | 306 |
|
315 | 307 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
316 | | - protected _renderVariantDetails(variantOption: VariantOptionModelType): TemplateResult { |
| 308 | + protected _renderVariantDetails(variantOption: VariantOptionModelType) { |
317 | 309 | return html``; |
318 | 310 | } |
319 | 311 |
|
@@ -502,6 +494,6 @@ export class UmbWorkspaceSplitViewVariantSelectorElement< |
502 | 494 |
|
503 | 495 | declare global { |
504 | 496 | interface HTMLElementTagNameMap { |
505 | | - [elementName]: UmbWorkspaceSplitViewVariantSelectorElement; |
| 497 | + 'umb-workspace-split-view-variant-selector': UmbWorkspaceSplitViewVariantSelectorElement; |
506 | 498 | } |
507 | 499 | } |
0 commit comments