1
- import { LitElement , html } from '../../../deps/lit/lit-core.min.js' ;
1
+ import { LitElement , html , nothing } from '../../../deps/lit/lit-core.min.js' ;
2
2
import { saveToDa , saveToAem } from '../utils/helpers.js' ;
3
+ import inlinesvg from '../../shared/inlinesvg.js' ;
3
4
import getSheet from '../../shared/sheet.js' ;
4
5
5
6
const sheet = await getSheet ( '/blocks/edit/da-title/da-title.css' ) ;
6
7
8
+ const ICONS = [
9
+ '/blocks/edit/img/Smock_Cloud_18_N.svg' ,
10
+ '/blocks/edit/img/Smock_CloudDisconnected_18_N.svg' ,
11
+ '/blocks/edit/img/Smock_CloudError_18_N.svg' ,
12
+ ] ;
13
+
14
+ const CLOUD_ICONS = {
15
+ connected : 'spectrum-Cloud-connected' ,
16
+ offline : 'spectrum-Cloud-offline' ,
17
+ connecting : 'spectrum-Cloud-error' ,
18
+ error : 'spectrum-Cloud-error' ,
19
+ } ;
20
+
7
21
export default class DaTitle extends LitElement {
8
22
static properties = {
9
23
details : { attribute : false } ,
24
+ collabStatus : { attribute : false } ,
25
+ collabUsers : { attribute : false } ,
10
26
_actionsVis : { } ,
11
27
} ;
12
28
13
29
connectedCallback ( ) {
14
30
super . connectedCallback ( ) ;
15
31
this . shadowRoot . adoptedStyleSheets = [ sheet ] ;
16
32
this . _actionsVis = false ;
33
+ inlinesvg ( { parent : this . shadowRoot , paths : ICONS } ) ;
17
34
}
18
35
19
36
async handleAction ( action ) {
@@ -48,6 +65,35 @@ export default class DaTitle extends LitElement {
48
65
this . _actionsVis = ! this . _actionsVis ;
49
66
}
50
67
68
+ popover ( { target } ) {
69
+ // If toggling off, simply remove;
70
+ if ( target . classList . contains ( 'collab-popup' ) ) {
71
+ target . classList . remove ( 'collab-popup' ) ;
72
+ return ;
73
+ }
74
+ // Find all open popups and close them
75
+ const openPopups = this . shadowRoot . querySelectorAll ( '.collab-popup' ) ;
76
+ openPopups . forEach ( ( pop ) => { pop . classList . remove ( 'collab-popup' ) ; } ) ;
77
+ target . classList . add ( 'collab-popup' ) ;
78
+ }
79
+
80
+ renderCollabUsers ( ) {
81
+ return html `${ this . collabUsers . map ( ( user ) => {
82
+ const initials = user . split ( ' ' ) . map ( ( name ) => name . toString ( ) . substring ( 0 , 1 ) ) ;
83
+ return html `< div class ="collab-icon collab-icon-user " data-popup-content ="${ user } " @click =${ this . popover } > ${ initials . join ( '' ) } </ div > ` ;
84
+ } ) } `;
85
+ }
86
+
87
+ renderCollab ( ) {
88
+ return html `
89
+ < div class ="collab-status ">
90
+ ${ this . collabUsers && this . collabUsers . length > 1 ? this . renderCollabUsers ( ) : nothing }
91
+ < div class ="collab-icon collab-status-cloud collab-status- ${ this . collabStatus } " data-popup-content ="${ this . collabStatus } " @click =${ this . popover } >
92
+ < svg class ="icon "> < use href ="# ${ CLOUD_ICONS [ this . collabStatus ] } "/> </ svg >
93
+ </ div >
94
+ </ div > ` ;
95
+ }
96
+
51
97
render ( ) {
52
98
return html `
53
99
< div class ="da-title-inner ">
@@ -58,25 +104,28 @@ export default class DaTitle extends LitElement {
58
104
class ="da-title-name-label "> ${ this . details . parentName } </ a >
59
105
< h1 > ${ this . details . name } </ h1 >
60
106
</ div >
61
- < div class ="da-title-actions ${ this . _actionsVis ? ' is-open' : '' } ">
62
- < button
63
- @click =${ this . handlePreview }
64
- class ="con-button blue da-title-action"
65
- aria-label="Send">
66
- Preview
67
- </ button >
68
- < button
69
- @click =${ this . handlePublish }
70
- class ="con-button blue da-title-action"
71
- aria-label="Send">
72
- Publish
73
- </ button >
74
- < button
75
- @click =${ this . toggleActions }
76
- class ="con-button blue da-title-action-send"
77
- aria-label="Send">
78
- < span class ="da-title-action-send-icon "> </ span >
79
- </ button >
107
+ < div class ="da-title-collab-actions-wrapper ">
108
+ ${ this . collabStatus ? this . renderCollab ( ) : nothing }
109
+ < div class ="da-title-actions ${ this . _actionsVis ? ' is-open' : '' } ">
110
+ < button
111
+ @click =${ this . handlePreview }
112
+ class ="con-button blue da-title-action"
113
+ aria-label="Send">
114
+ Preview
115
+ </ button >
116
+ < button
117
+ @click =${ this . handlePublish }
118
+ class ="con-button blue da-title-action"
119
+ aria-label="Send">
120
+ Publish
121
+ </ button >
122
+ < button
123
+ @click =${ this . toggleActions }
124
+ class ="con-button blue da-title-action-send"
125
+ aria-label="Send">
126
+ < span class ="da-title-action-send-icon "> </ span >
127
+ </ button >
128
+ </ div >
80
129
</ div >
81
130
</ div >
82
131
` ;
0 commit comments