11import {
22 mdiClose ,
33 mdiContentDuplicate ,
4+ mdiDragHorizontalVariant ,
45 mdiPencil ,
56 mdiPlaylistPlus ,
67} from "@mdi/js" ;
@@ -13,6 +14,7 @@ import "../../../components/ha-dropdown";
1314import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown" ;
1415import "../../../components/ha-dropdown-item" ;
1516import "../../../components/ha-icon-button" ;
17+ import "../../../components/ha-sortable" ;
1618import "../../../components/ha-svg-icon" ;
1719import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box" ;
1820import type { HomeAssistant } from "../../../types" ;
@@ -64,49 +66,61 @@ export class HuiPictureElementsCardRowEditor extends LitElement {
6466 ) }
6567 </ h3>
6668 <div class= "elements" >
67- ${ this . elements . map (
68- ( element , index ) => html `
69- <div class= "element" >
70- ${ element . type
71- ? html `
72- <div class= "element-row" >
73- <div>
74- <span>
75- ${ this . hass ?. localize (
76- `ui.panel.lovelace.editor.card.picture-elements.element_types.${ element . type } `
77- ) || element . type }
78- </ span>
79- <span class= "secondary"
80- > ${ this . _getSecondaryDescription ( element ) } </ span
81- >
82- </ div>
83- </ div>
84- `
85- : nothing }
86- <ha- icon- butto n
87- .label = ${ this . hass ! . localize ( "ui.common.delete" ) }
88- .path = ${ mdiClose }
89- class= "remove-icon"
90- .index = ${ index }
91- @click = ${ this . _removeRow }
92- > </ ha- icon- butto n>
93- <ha- icon- butto n
94- .label = ${ this . hass ! . localize ( "ui.common.edit" ) }
95- .path = ${ mdiPencil }
96- class= "edit- icon"
97- .index = ${ index }
98- @click = ${ this . _editRow }
99- > </ ha- icon- butto n>
100- <ha- icon- butto n
101- .label = ${ this . hass ! . localize ( "ui.common.duplicate" ) }
102- .path = ${ mdiContentDuplicate }
103- class= "duplicate-icon"
104- .index = ${ index }
105- @click = ${ this . _duplicateRow }
106- > </ ha- icon- butto n>
107- </ div>
108- `
109- ) }
69+ <ha- sor table
70+ handle-selector= ".handle"
71+ @item-moved = ${ this . _elementMoved }
72+ >
73+ <div>
74+ ${ this . elements . map (
75+ ( element , index ) => html `
76+ <div class= "element" >
77+ <div class= "handle" >
78+ <ha- svg- icon
79+ .path = ${ mdiDragHorizontalVariant }
80+ > </ ha- svg- icon>
81+ </ div>
82+ ${ element . type
83+ ? html `
84+ <div class= "element-row" >
85+ <div>
86+ <span>
87+ ${ this . hass ?. localize (
88+ `ui.panel.lovelace.editor.card.picture-elements.element_types.${ element . type } `
89+ ) || element . type }
90+ </ span>
91+ <span class= "secondary"
92+ > ${ this . _getSecondaryDescription ( element ) } </ span
93+ >
94+ </ div>
95+ </ div>
96+ `
97+ : nothing }
98+ <ha- icon- butto n
99+ .label = ${ this . hass ! . localize ( "ui.common.delete" ) }
100+ .path = ${ mdiClose }
101+ class= "remove-icon"
102+ .index = ${ index }
103+ @click = ${ this . _removeRow }
104+ > </ ha- icon- butto n>
105+ <ha- icon- butto n
106+ .label = ${ this . hass ! . localize ( "ui.common.edit" ) }
107+ .path = ${ mdiPencil }
108+ class= "edit- icon"
109+ .index = ${ index }
110+ @click = ${ this . _editRow }
111+ > </ ha- icon- butto n>
112+ <ha- icon- butto n
113+ .label = ${ this . hass ! . localize ( "ui.common.duplicate" ) }
114+ .path = ${ mdiContentDuplicate }
115+ class= "duplicate-icon"
116+ .index = ${ index }
117+ @click = ${ this . _duplicateRow }
118+ > </ ha- icon- butto n>
119+ </ div>
120+ `
121+ ) }
122+ </ div>
123+ </ ha- sor table>
110124 <ha- dropdown @wa-select = ${ this . _addElement } >
111125 <ha- butto n size= "small" slot = "trigger" appearance= "filled">
112126 <ha- svg- icon slot= "start" .path = ${ mdiPlaylistPlus } > </ ha- svg- icon>
@@ -193,6 +207,17 @@ export class HuiPictureElementsCardRowEditor extends LitElement {
193207 fireEvent ( this , "elements-changed" , { elements : newElements } ) ;
194208 }
195209
210+ private _elementMoved ( ev : CustomEvent ) : void {
211+ ev . stopPropagation ( ) ;
212+ const { oldIndex, newIndex } = ev . detail ;
213+
214+ const newElements = this . elements ! . concat ( ) ;
215+
216+ newElements . splice ( newIndex , 0 , newElements . splice ( oldIndex , 1 ) [ 0 ] ) ;
217+
218+ fireEvent ( this , "elements-changed" , { elements : newElements } ) ;
219+ }
220+
196221 private _removeRow ( ev : CustomEvent ) : void {
197222 const index = ( ev . currentTarget as any ) . index ;
198223 const element = this . elements ?. [ index ] ;
@@ -242,6 +267,17 @@ export class HuiPictureElementsCardRowEditor extends LitElement {
242267 display : flex;
243268 align-items : center;
244269 }
270+ .handle {
271+ padding-right : var (--ha-space-2 );
272+ cursor : move;
273+ cursor : grab;
274+ padding-inline-end : var (--ha-space-2 );
275+ padding-inline-start : initial;
276+ direction : var (--direction );
277+ }
278+ .handle > * {
279+ pointer-events : none;
280+ }
245281
246282 .element-row {
247283 height : 60px ;
0 commit comments