1
1
import { UMB_DOCUMENT_TYPE_WORKSPACE_CONTEXT } from './document-type-workspace.context-token.js' ;
2
+ import type { UmbInputWithAliasElement } from '@umbraco-cms/backoffice/components' ;
2
3
import { umbFocus , UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
3
- import type { UUIInputElement } from '@umbraco-cms/backoffice/external/uui' ;
4
- import { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui' ;
5
4
import { css , html , customElement , state , ifDefined } from '@umbraco-cms/backoffice/external/lit' ;
6
5
import { UMB_MODAL_MANAGER_CONTEXT , UMB_ICON_PICKER_MODAL } from '@umbraco-cms/backoffice/modal' ;
7
- import { generateAlias } from '@umbraco-cms/backoffice/utils' ;
6
+
8
7
@customElement ( 'umb-document-type-workspace-editor' )
9
8
export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
10
9
@state ( )
@@ -14,10 +13,10 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
14
13
private _alias ?: string ;
15
14
16
15
@state ( )
17
- private _aliasLocked = true ;
16
+ private _icon ?: string ;
18
17
19
18
@state ( )
20
- private _icon ?: string ;
19
+ private _isNew ?: boolean ;
21
20
22
21
#workspaceContext?: typeof UMB_DOCUMENT_TYPE_WORKSPACE_CONTEXT . TYPE ;
23
22
@@ -35,42 +34,7 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
35
34
this . observe ( this . #workspaceContext. name , ( name ) => ( this . _name = name ) , '_observeName' ) ;
36
35
this . observe ( this . #workspaceContext. alias , ( alias ) => ( this . _alias = alias ) , '_observeAlias' ) ;
37
36
this . observe ( this . #workspaceContext. icon , ( icon ) => ( this . _icon = icon ) , '_observeIcon' ) ;
38
- }
39
-
40
- // TODO. find a way where we don't have to do this for all workspaces.
41
- #onNameChange( event : UUIInputEvent ) {
42
- if ( event instanceof UUIInputEvent ) {
43
- const target = event . composedPath ( ) [ 0 ] as UUIInputElement ;
44
-
45
- if ( typeof target ?. value === 'string' ) {
46
- const oldName = this . _name ;
47
- const oldAlias = this . _alias ;
48
- const newName = event . target . value . toString ( ) ;
49
- if ( this . _aliasLocked ) {
50
- const expectedOldAlias = generateAlias ( oldName ?? '' ) ;
51
- // 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.)
52
- if ( expectedOldAlias === oldAlias ) {
53
- this . #workspaceContext?. setAlias ( generateAlias ( newName ) ) ;
54
- }
55
- }
56
- this . #workspaceContext?. setName ( target . value ) ;
57
- }
58
- }
59
- }
60
-
61
- // TODO. find a way where we don't have to do this for all workspaces.
62
- #onAliasChange( event : UUIInputEvent ) {
63
- if ( event instanceof UUIInputEvent ) {
64
- const target = event . composedPath ( ) [ 0 ] as UUIInputElement ;
65
- if ( typeof target ?. value === 'string' ) {
66
- this . #workspaceContext?. setAlias ( target . value ) ;
67
- }
68
- }
69
- event . stopPropagation ( ) ;
70
- }
71
-
72
- #onToggleAliasLock( ) {
73
- this . _aliasLocked = ! this . _aliasLocked ;
37
+ this . observe ( this . #workspaceContext. isNew , ( isNew ) => ( this . _isNew = isNew ) , '_observeIsNew' ) ;
74
38
}
75
39
76
40
private async _handleIconClick ( ) {
@@ -92,6 +56,11 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
92
56
} ) ;
93
57
}
94
58
59
+ #onNameAndAliasChange( event : InputEvent & { target : UmbInputWithAliasElement } ) {
60
+ this . #workspaceContext?. setName ( event . target . value ?? '' ) ;
61
+ this . #workspaceContext?. setAlias ( event . target . alias ?? '' ) ;
62
+ }
63
+
95
64
render ( ) {
96
65
return html `
97
66
<umb- wor kspace- edito r alias= "Umb.Workspace.DocumentType" >
@@ -100,22 +69,14 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
100
69
<umb- icon name= ${ ifDefined ( this . _icon ) } > </ umb- icon>
101
70
</ uui- butto n>
102
71
103
- <uui- input id= "name" label = "name" .value = ${ this . _name } @input = "${ this . #onNameChange} " ${ umbFocus ( ) } >
104
- <!- - TODO: should use UUI- LOCK- INPUT, but that does not fire an event when its locked / unlocked - - >
105
- <uui- input
106
- name= "alias"
107
- slot = "append"
108
- label=" alias"
109
- @input=${ this . #onAliasChange}
110
- .value=${ this . _alias }
111
- placeholder=" Enter alias ..."
112
- ?disabled=${ this . _aliasLocked } >
113
- <!-- TODO: validation for bad characters -->
114
- <div @click=${ this . #onToggleAliasLock} @keydown=${ ( ) => '' } id=" alias-lock" slot=" prepend">
115
- <uui-icon name=${ this . _aliasLocked ? 'icon-lock' : 'icon-unlocked' } ></uui-icon>
116
- </div>
117
- </uui-input>
118
- </uui-input>
72
+ <umb- input- with- alias
73
+ id= "name"
74
+ label = "name"
75
+ value = ${ this . _name }
76
+ alias= ${ this . _alias }
77
+ ?auto - generate-alias= ${ this . _isNew }
78
+ @change = "${ this . #onNameAndAliasChange} "
79
+ ${ umbFocus ( ) } > </ umb- input- with- alias>
119
80
</ div>
120
81
</ umb- wor kspace- edito r>
121
82
` ;
@@ -136,18 +97,6 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
136
97
137
98
# name {
138
99
width : 100% ;
139
- flex: 1 1 auto;
140
- align-items: center;
141
- }
142
-
143
- #alias-lock {
144
- display: flex;
145
- align-items: center;
146
- justify-content: center;
147
- cursor: pointer;
148
- }
149
- #alias-lock uui-icon {
150
- margin-bottom: 2px;
151
100
}
152
101
153
102
# icon {
0 commit comments