1
1
import { UMB_MEMBER_TYPE_WORKSPACE_CONTEXT } from './member-type-workspace.context-token.js' ;
2
2
import { css , html , customElement , state , ifDefined } from '@umbraco-cms/backoffice/external/lit' ;
3
3
import { UmbLitElement , umbFocus } from '@umbraco-cms/backoffice/lit-element' ;
4
- import type { UUIInputElement } from '@umbraco-cms/backoffice/external/uui' ;
5
- import { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui' ;
6
4
import { UMB_ICON_PICKER_MODAL , UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal' ;
7
- import { generateAlias } from '@umbraco-cms/backoffice/utils' ;
8
5
9
6
@customElement ( 'umb-member-type-workspace-editor' )
10
7
export class UmbMemberTypeWorkspaceEditorElement extends UmbLitElement {
@@ -14,9 +11,6 @@ export class UmbMemberTypeWorkspaceEditorElement extends UmbLitElement {
14
11
@state ( )
15
12
private _alias ?: string ;
16
13
17
- @state ( )
18
- private _aliasLocked = true ;
19
-
20
14
@state ( )
21
15
private _icon ?: string ;
22
16
@@ -54,43 +48,6 @@ export class UmbMemberTypeWorkspaceEditorElement extends UmbLitElement {
54
48
) ;
55
49
}
56
50
57
- // TODO. find a way where we don't have to do this for all workspaces.
58
- #onNameChange( event : UUIInputEvent ) {
59
- if ( event instanceof UUIInputEvent ) {
60
- const target = event . composedPath ( ) [ 0 ] as UUIInputElement ;
61
-
62
- if ( typeof target ?. value === 'string' ) {
63
- const oldName = this . _name ;
64
- const oldAlias = this . _alias ;
65
- const newName = event . target . value . toString ( ) ;
66
- if ( this . _aliasLocked ) {
67
- const expectedOldAlias = generateAlias ( oldName ?? '' ) ;
68
- // Only update the alias if the alias matches a generated alias of the old name (otherwise the alias is considered one written by the user.)
69
- if ( expectedOldAlias === oldAlias ) {
70
- this . #workspaceContext?. set ( 'alias' , generateAlias ( newName ) ) ;
71
- }
72
- }
73
- this . #workspaceContext?. setName ( target . value ) ;
74
- }
75
- }
76
- }
77
-
78
- // TODO. find a way where we don't have to do this for all workspaces.
79
- #onAliasChange( event : UUIInputEvent ) {
80
- if ( event instanceof UUIInputEvent ) {
81
- const target = event . composedPath ( ) [ 0 ] as UUIInputElement ;
82
-
83
- if ( typeof target ?. value === 'string' ) {
84
- this . #workspaceContext?. set ( 'alias' , target . value ) ;
85
- }
86
- }
87
- event . stopPropagation ( ) ;
88
- }
89
-
90
- #onToggleAliasLock( ) {
91
- this . _aliasLocked = ! this . _aliasLocked ;
92
- }
93
-
94
51
private async _handleIconClick ( ) {
95
52
const [ alias , color ] = this . _icon ?. replace ( 'color-' , '' ) ?. split ( ' ' ) ?? [ ] ;
96
53
const modalManager = await this . getContext ( UMB_MODAL_MANAGER_CONTEXT ) ;
@@ -110,6 +67,11 @@ export class UmbMemberTypeWorkspaceEditorElement extends UmbLitElement {
110
67
} ) ;
111
68
}
112
69
70
+ #onNameAndAliasChange( event : InputEvent & { target : UmbInputWithAliasElement } ) {
71
+ this . #workspaceContext?. setName ( event . target . value ?? '' ) ;
72
+ this . #workspaceContext?. setAlias ( event . target . alias ?? '' ) ;
73
+ }
74
+
113
75
render ( ) {
114
76
return html `
115
77
<umb- wor kspace- edito r alias= "Umb.Workspace.MemberType" >
@@ -118,22 +80,13 @@ export class UmbMemberTypeWorkspaceEditorElement extends UmbLitElement {
118
80
<uui- icon name= "${ ifDefined ( this . _icon ) } " style = "color: ${ this . _iconColorAlias } " > </ uui- icon>
119
81
</ uui- butto n>
120
82
121
- <uui- input id= "name" .value = ${ this . _name } @input = "${ this . #onNameChange} " label = "name" ${ umbFocus ( ) } >
122
- <!- - TODO: should use UUI- LOCK- INPUT, but that does not fire an event when its locked / unlocked - - >
123
- <uui- input
124
- name= "alias"
125
- slot = "append"
126
- label=" alias"
127
- @input=${ this . #onAliasChange}
128
- .value=${ this . _alias }
129
- placeholder=" Enter alias ..."
130
- ?disabled=${ this . _aliasLocked } >
131
- <!-- TODO: validation for bad characters -->
132
- <div @click=${ this . #onToggleAliasLock} @keydown=${ ( ) => '' } id=" alias-lock" slot=" prepend">
133
- <uui-icon name=${ this . _aliasLocked ? 'icon-lock' : 'icon-unlocked' } ></uui-icon>
134
- </div>
135
- </uui-input>
136
- </uui-input>
83
+ <umb- input- with- alias
84
+ id= "name"
85
+ label = "name"
86
+ value = ${ this . _name }
87
+ alias= ${ this . _alias }
88
+ @change = "${ this . #onNameAndAliasChange} "
89
+ ${ umbFocus ( ) } > </ umb- input- with- alias>
137
90
</ div>
138
91
</ umb- wor kspace- edito r>
139
92
` ;
0 commit comments