1
1
import type { UmbContentPickerSource } from '../../types.js' ;
2
- import { css , html , customElement , property } from '@umbraco-cms/backoffice/external/lit' ;
2
+ import { css , html , customElement , property , state } from '@umbraco-cms/backoffice/external/lit' ;
3
3
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event' ;
4
4
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
5
- import type { UmbInputDocumentElement } from '@umbraco-cms/backoffice/document' ;
6
- import type { UmbInputMediaElement } from '@umbraco-cms/backoffice/media' ;
7
- import type { UmbInputMemberElement } from '@umbraco-cms/backoffice/member' ;
8
5
import type { UmbReferenceByUniqueAndType } from '@umbraco-cms/backoffice/models' ;
9
6
import type { UmbTreeStartNode } from '@umbraco-cms/backoffice/tree' ;
10
7
import { splitStringToArray } from '@umbraco-cms/backoffice/utils' ;
@@ -16,53 +13,62 @@ const elementName = 'umb-input-content';
16
13
export class UmbInputContentElement extends UmbFormControlMixin < string | undefined , typeof UmbLitElement > (
17
14
UmbLitElement ,
18
15
) {
19
- protected override getFormElement ( ) {
20
- return undefined ;
21
- }
22
-
23
- private _type : UmbContentPickerSource [ 'type' ] = 'content' ;
24
16
@property ( { type : Object , attribute : false } )
25
17
public set type ( newType : UmbContentPickerSource [ 'type' ] ) {
26
- const oldType = this . _type ;
27
- if ( newType ?. toLowerCase ( ) !== this . _type ) {
28
- this . _type = newType ?. toLowerCase ( ) as UmbContentPickerSource [ 'type' ] ;
18
+ const oldType = this . #type ;
19
+ if ( newType ?. toLowerCase ( ) !== this . #type ) {
20
+ this . #type = newType ?. toLowerCase ( ) as UmbContentPickerSource [ 'type' ] ;
29
21
this . requestUpdate ( 'type' , oldType ) ;
30
22
}
31
23
}
32
24
public get type ( ) : UmbContentPickerSource [ 'type' ] {
33
- return this . _type ;
25
+ return this . #type ;
34
26
}
27
+ #type: UmbContentPickerSource [ 'type' ] = 'content' ;
35
28
36
29
@property ( { type : Number } )
37
30
min = 0 ;
38
31
32
+ @property ( { type : String , attribute : 'min-message' } )
33
+ minMessage = 'This field need more items' ;
34
+
39
35
@property ( { type : Number } )
40
36
max = 0 ;
41
37
38
+ @property ( { type : String , attribute : 'max-message' } )
39
+ maxMessage = 'This field exceeds the allowed amount of items' ;
40
+
42
41
@property ( { type : Object , attribute : false } )
43
42
startNode ?: UmbTreeStartNode ;
44
43
45
- private _allowedContentTypeIds : Array < string > = [ ] ;
46
44
@property ( )
47
45
public set allowedContentTypeIds ( value : string ) {
48
- this . _allowedContentTypeIds = value ? value . split ( ',' ) : [ ] ;
46
+ this . #allowedContentTypeIds = value ? value . split ( ',' ) : [ ] ;
49
47
}
50
48
public get allowedContentTypeIds ( ) : string {
51
- return this . _allowedContentTypeIds . join ( ',' ) ;
49
+ return this . #allowedContentTypeIds . join ( ',' ) ;
52
50
}
51
+ #allowedContentTypeIds: Array < string > = [ ] ;
53
52
54
53
@property ( { type : Boolean } )
55
54
showOpenButton ?: boolean ;
56
55
57
- #entityTypeLookup = { content : 'document' , media : 'media' , member : 'member' } ;
56
+ @property ( { type : Array } )
57
+ public set selection ( values : Array < UmbReferenceByUniqueAndType > ) {
58
+ this . #selection = values ?. map ( ( item ) => item . unique ) ?? [ ] ;
59
+ }
60
+ public get selection ( ) : Array < UmbReferenceByUniqueAndType > {
61
+ return this . #selection. map ( ( id ) => ( { type : this . #entityTypeLookup[ this . #type] , unique : id } ) ) ;
62
+ }
58
63
59
- // TODO: to be consistent with other pickers, this should be named `selection` [NL]
64
+ /** @deprecated Please use `selection` instead. This property will be removed in Umbraco 15. */
60
65
@property ( { type : Array } )
61
66
public set items ( items : Array < UmbReferenceByUniqueAndType > ) {
62
- this . # selection = items ?. map ( ( item ) => item . unique ) ?? [ ] ;
67
+ this . selection = items ;
63
68
}
69
+ /** @deprecated Please use `selection` instead. This property will be removed in Umbraco 15. */
64
70
public get items ( ) : Array < UmbReferenceByUniqueAndType > {
65
- return this . # selection. map ( ( id ) => ( { type : this . #entityTypeLookup [ this . _type ] , unique : id } ) ) ;
71
+ return this . selection ;
66
72
}
67
73
68
74
@property ( { type : String } )
@@ -73,38 +79,22 @@ export class UmbInputContentElement extends UmbFormControlMixin<string | undefin
73
79
return this . #selection. length > 0 ? this . #selection. join ( ',' ) : undefined ;
74
80
}
75
81
82
+ #entityTypeLookup = { content : 'document' , media : 'media' , member : 'member' } ;
83
+
76
84
#selection: Array < string > = [ ] ;
77
85
78
- #onChange( event : CustomEvent ) {
79
- switch ( this . _type ) {
80
- case 'content' :
81
- {
82
- const input = event . target as UmbInputDocumentElement ;
83
- this . #selection = input . selection ;
84
- this . value = input . selection . join ( ',' ) ;
85
- }
86
- break ;
87
- case 'media' : {
88
- const input = event . target as UmbInputMediaElement ;
89
- this . #selection = input . selection ;
90
- this . value = input . selection . join ( ',' ) ;
91
- break ;
92
- }
93
- case 'member' : {
94
- const input = event . target as UmbInputMemberElement ;
95
- this . #selection = input . selection ;
96
- this . value = input . selection . join ( ',' ) ;
97
- break ;
98
- }
99
- default :
100
- break ;
101
- }
86
+ override firstUpdated ( ) {
87
+ this . addFormControlElement ( this . shadowRoot ! . querySelector ( `umb-input-${ this . #entityTypeLookup[ this . #type] } ` ) ! ) ;
88
+ }
102
89
90
+ #onChange( event : CustomEvent & { target : { selection : string [ ] | undefined } } ) {
91
+ this . #selection = event . target . selection ?? [ ] ;
92
+ this . value = this . #selection. join ( ',' ) ;
103
93
this . dispatchEvent ( new UmbChangeEvent ( ) ) ;
104
94
}
105
95
106
96
override render ( ) {
107
- switch ( this . _type ) {
97
+ switch ( this . #type ) {
108
98
case 'content' :
109
99
return this . #renderDocumentPicker( ) ;
110
100
case 'media' :
@@ -117,34 +107,46 @@ export class UmbInputContentElement extends UmbFormControlMixin<string | undefin
117
107
}
118
108
119
109
#renderDocumentPicker( ) {
120
- return html `<umb- input- document
121
- .selection = ${ this . #selection}
122
- .startNode = ${ this . startNode }
123
- .allowedContentTypeIds = ${ this . _allowedContentTypeIds }
124
- .min = ${ this . min }
125
- .max = ${ this . max }
126
- ?showOpenButto n= ${ this . showOpenButton }
127
- @change = ${ this . #onChange} > </ umb- input- document> ` ;
110
+ return html `
111
+ <umb- input- document
112
+ .selection = ${ this . #selection}
113
+ .startNode = ${ this . startNode }
114
+ .allowedContentTypeIds = ${ this . #allowedContentTypeIds}
115
+ .min = ${ this . min }
116
+ .minMessage = ${ this . minMessage }
117
+ .max = ${ this . max }
118
+ .maxMessage = ${ this . maxMessage }
119
+ ?showOpenButto n= ${ this . showOpenButton }
120
+ @change = ${ this . #onChange} > </ umb- input- document>
121
+ ` ;
128
122
}
129
123
130
124
#renderMediaPicker( ) {
131
- return html `<umb- input- media
132
- .selection = ${ this . #selection}
133
- .allowedContentTypeIds = ${ this . _allowedContentTypeIds }
134
- .min = ${ this . min }
135
- .max = ${ this . max }
136
- ?showOpenButto n= ${ this . showOpenButton }
137
- @change = ${ this . #onChange} > </ umb- input- media> ` ;
125
+ return html `
126
+ <umb- input- media
127
+ .selection = ${ this . #selection}
128
+ .allowedContentTypeIds = ${ this . #allowedContentTypeIds}
129
+ .min = ${ this . min }
130
+ .minMessage = ${ this . minMessage }
131
+ .max = ${ this . max }
132
+ .maxMessage = ${ this . maxMessage }
133
+ ?showOpenButto n= ${ this . showOpenButton }
134
+ @change = ${ this . #onChange} > </ umb- input- media>
135
+ ` ;
138
136
}
139
137
140
138
#renderMemberPicker( ) {
141
- return html `<umb- input- member
142
- .selection = ${ this . #selection}
143
- .allowedContentTypeIds = ${ this . _allowedContentTypeIds }
144
- .min = ${ this . min }
145
- .max = ${ this . max }
146
- ?showOpenButto n= ${ this . showOpenButton }
147
- @change = ${ this . #onChange} > </ umb- input- member> ` ;
139
+ return html `
140
+ <umb- input- member
141
+ .selection = ${ this . #selection}
142
+ .allowedContentTypeIds = ${ this . #allowedContentTypeIds}
143
+ .min = ${ this . min }
144
+ .minMessage = ${ this . minMessage }
145
+ .max = ${ this . max }
146
+ .maxMessage = ${ this . maxMessage }
147
+ ?showOpenButto n= ${ this . showOpenButton }
148
+ @change = ${ this . #onChange} > </ umb- input- member>
149
+ ` ;
148
150
}
149
151
150
152
static override styles = [
0 commit comments