@@ -5,12 +5,15 @@ import type {
5
5
UmbTiptapToolbarRowViewModel ,
6
6
} from '../types.js' ;
7
7
import type { UmbTiptapToolbarValue } from '../../../components/types.js' ;
8
+ import type { UmbTiptapToolbarGroupConfigurationElement } from './tiptap-toolbar-group-configuration.element.js' ;
8
9
import { customElement , css , html , property , repeat , state , when , nothing } from '@umbraco-cms/backoffice/external/lit' ;
9
10
import { debounce } from '@umbraco-cms/backoffice/utils' ;
10
11
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
11
12
import { UMB_PROPERTY_CONTEXT } from '@umbraco-cms/backoffice/property' ;
12
13
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/property-editor' ;
13
14
15
+ import './tiptap-toolbar-group-configuration.element.js' ;
16
+
14
17
@customElement ( 'umb-property-editor-ui-tiptap-toolbar-configuration' )
15
18
export class UmbPropertyEditorUiTiptapToolbarConfigurationElement
16
19
extends UmbLitElement
@@ -74,7 +77,14 @@ export class UmbPropertyEditorUiTiptapToolbarConfigurationElement
74
77
this . #initialized = true ;
75
78
}
76
79
77
- #onClick( item : UmbTiptapToolbarExtension ) {
80
+ #onChangeToolbarGroup( event : CustomEvent & { target : UmbTiptapToolbarGroupConfigurationElement } ) {
81
+ event . stopPropagation ( ) ;
82
+ const element = event . target ;
83
+ const aliases = element . items . map ( ( item ) => item . alias ) ;
84
+ this . #context. updateToolbarItem ( aliases , [ element . rowIndex , element . groupIndex ] ) ;
85
+ }
86
+
87
+ #onClickAvailableItem( item : UmbTiptapToolbarExtension ) {
78
88
const lastRow = ( this . #value?. length ?? 1 ) - 1 ;
79
89
const lastGroup = ( this . #value?. [ lastRow ] . length ?? 1 ) - 1 ;
80
90
const lastItem = this . #value?. [ lastRow ] [ lastGroup ] . length ?? 0 ;
@@ -128,6 +138,11 @@ export class UmbPropertyEditorUiTiptapToolbarConfigurationElement
128
138
this . #debouncedFilter( query ) ;
129
139
}
130
140
141
+ #onRemoveToolbarItem( event : CustomEvent ) {
142
+ const { groupIndex, index, rowIndex } = event . detail ;
143
+ this . #context?. removeToolbarItem ( [ rowIndex , groupIndex , index ] ) ;
144
+ }
145
+
131
146
override render ( ) {
132
147
return html `${ this . #renderDesigner( ) } ${ this . #renderAvailableItems( ) } ` ;
133
148
}
@@ -173,7 +188,7 @@ export class UmbPropertyEditorUiTiptapToolbarConfigurationElement
173
188
label= ${ label }
174
189
look= ${ forbidden ? 'placeholder' : 'outline' }
175
190
?dis abled= ${ forbidden || inUse }
176
- @click = ${ ( ) => this . #onClick ( item ) }
191
+ @click = ${ ( ) => this . #onClickAvailableItem ( item ) }
177
192
@dragstart = ${ ( e : DragEvent ) => this . #onDragStart( e , item . alias ) }
178
193
@dragend = ${ this . #onDragEnd} >
179
194
<div class= "inner" >
@@ -242,19 +257,22 @@ export class UmbPropertyEditorUiTiptapToolbarConfigurationElement
242
257
#renderGroup( group ?: UmbTiptapToolbarGroupViewModel , rowIndex = 0 , groupIndex = 0 ) {
243
258
if ( ! group ) return nothing ;
244
259
const showActionBar = this . _toolbar [ rowIndex ] . data . length > 1 && group . data . length === 0 ;
260
+ const items : UmbTiptapToolbarExtension [ ] = group ! . data
261
+ . map ( ( alias ) => this . #context?. getExtensionByAlias ( alias ) )
262
+ . filter ( ( item ) : item is UmbTiptapToolbarExtension => ! ! item ) ;
245
263
return html `
246
264
<div
247
265
class= "group"
248
266
dropzone = "move"
249
267
@dragover = ${ this . #onDragOver}
250
268
@drop = ${ ( e : DragEvent ) => this . #onDrop( e , [ rowIndex , groupIndex , group . data . length - 1 ] ) } >
251
- <div class = "items" >
252
- ${ when (
253
- group ?. data . length === 0 ,
254
- ( ) => html `<em > <umb - localize key = "tiptap_toolbar_emptyGroup" > Empty < / umb - localize > < / em > ` ,
255
- ( ) => html ` ${ group ! . data . map ( ( alias , idx ) => this . #renderItem ( alias , rowIndex , groupIndex , idx ) ) } ` ,
256
- ) }
257
- </ div >
269
+ <umb - tiptap - to olbar - group - configuration
270
+ . items = ${ items }
271
+ . rowIndex = ${ rowIndex }
272
+ . groupIndex = ${ groupIndex }
273
+ @change = ${ this . #onChangeToolbarGroup }
274
+ @remove = ${ this . #onRemoveToolbarItem } >
275
+ </ umb - tiptap - to olbar - group - configuration >
258
276
${ when (
259
277
showActionBar ,
260
278
( ) => html `
@@ -276,62 +294,6 @@ export class UmbPropertyEditorUiTiptapToolbarConfigurationElement
276
294
` ;
277
295
}
278
296
279
- #renderItem( alias : string , rowIndex = 0 , groupIndex = 0 , itemIndex = 0 ) {
280
- const item = this . #context?. getExtensionByAlias ( alias ) ;
281
- if ( ! item ) return nothing ;
282
-
283
- const forbidden = ! this . #context?. isExtensionEnabled ( item . alias ) ;
284
- const label = this . localize . string ( item . label ) ;
285
-
286
- switch ( item . kind ) {
287
- case 'styleMenu' :
288
- case 'menu' :
289
- return html `
290
- <uui- butto n
291
- compact
292
- class= ${ forbidden ? 'forbidden' : '' }
293
- draggable= "true"
294
- label = ${ label }
295
- look= ${ forbidden ? 'placeholder' : 'outline' }
296
- title= ${ label }
297
- ?dis abled= ${ forbidden }
298
- @click = ${ ( ) => this . #context. removeToolbarItem ( [ rowIndex , groupIndex , itemIndex ] ) }
299
- @dragend = ${ this . #onDragEnd}
300
- @dragstart = ${ ( e : DragEvent ) => this . #onDragStart( e , alias , [ rowIndex , groupIndex , itemIndex ] ) } >
301
- <div class= "inner" >
302
- <span> ${ label } </ span>
303
- </ div>
304
- <uui- symbol- expand slot= "extra" open > </ uui- symbol- expand >
305
- </ uui- butto n>
306
- ` ;
307
-
308
- case 'button' :
309
- default :
310
- return html `
311
- <uui- butto n
312
- compact
313
- class= ${ forbidden ? 'forbidden' : '' }
314
- data- mark= "tiptap-toolbar-item:${ item . alias } "
315
- draggable = "true"
316
- look= ${ forbidden ? 'placeholder' : 'outline' }
317
- label= ${ label }
318
- title= ${ label }
319
- ?dis abled= ${ forbidden }
320
- @click = ${ ( ) => this . #context. removeToolbarItem ( [ rowIndex , groupIndex , itemIndex ] ) }
321
- @dragend = ${ this . #onDragEnd}
322
- @dragstart = ${ ( e : DragEvent ) => this . #onDragStart( e , alias , [ rowIndex , groupIndex , itemIndex ] ) } >
323
- <div class= "inner" >
324
- ${ when (
325
- item . icon ,
326
- ( ) => html `<umb- icon .name = ${ item . icon } > </ umb- icon> ` ,
327
- ( ) => html `<span> ${ label } </ span> ` ,
328
- ) }
329
- </ div>
330
- </ uui- butto n>
331
- ` ;
332
- }
333
- }
334
-
335
297
static override readonly styles = [
336
298
css `
337
299
: host {
@@ -468,45 +430,6 @@ export class UmbPropertyEditorUiTiptapToolbarConfigurationElement
468
430
opacity : 1 ;
469
431
}
470
432
}
471
-
472
- .items {
473
- display : flex;
474
- flex-direction : row;
475
- flex-wrap : wrap;
476
- gap : var (--uui-size-1 );
477
-
478
- uui-button {
479
- --uui-button-font-weight : normal;
480
-
481
- & [draggable = 'true' ],
482
- & [draggable = 'true' ] > .inner {
483
- cursor : move;
484
- }
485
-
486
- & [disabled ],
487
- & [disabled ] > .inner {
488
- cursor : not-allowed;
489
- }
490
-
491
- & .forbidden {
492
- --color : var (--uui-color-danger );
493
- --color-standalone : var (--uui-color-danger-standalone );
494
- --color-emphasis : var (--uui-color-danger-emphasis );
495
- --color-contrast : var (--uui-color-danger );
496
- --uui-button-contrast-disabled : var (--uui-color-danger );
497
- --uui-button-border-color-disabled : var (--uui-color-danger );
498
- }
499
-
500
- div {
501
- display : flex;
502
- gap : var (--uui-size-1 );
503
- }
504
-
505
- uui-symbol-expand {
506
- margin-left : var (--uui-size-space-2 );
507
- }
508
- }
509
- }
510
433
}
511
434
}
512
435
}
0 commit comments