1
- import type { ManifestTiptapToolbarExtension } from '../../extensions/tiptap-toolbar-extension.js' ;
2
- import { css , customElement , html , property } from '@umbraco-cms/backoffice/external/lit' ;
1
+ import type { UmbTiptapToolbarValue } from '../../extensions/types.js' ;
2
+ import { css , customElement , html , map , property , state } from '@umbraco-cms/backoffice/external/lit' ;
3
+ import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry' ;
4
+ import { UmbExtensionsElementAndApiInitializer } from '@umbraco-cms/backoffice/extension-api' ;
3
5
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
4
6
import type { Editor } from '@umbraco-cms/backoffice/external/tiptap' ;
5
7
import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor' ;
@@ -10,6 +12,12 @@ const elementName = 'umb-tiptap-fixed-menu';
10
12
11
13
@customElement ( elementName )
12
14
export class UmbTiptapFixedMenuElement extends UmbLitElement {
15
+ #attached = false ;
16
+ #extensionsController?: UmbExtensionsElementAndApiInitializer ;
17
+
18
+ @state ( )
19
+ private _lookup ?: Map < string , unknown > ;
20
+
13
21
@property ( { type : Boolean , reflect : true } )
14
22
readonly = false ;
15
23
@@ -20,21 +28,61 @@ export class UmbTiptapFixedMenuElement extends UmbLitElement {
20
28
configuration ?: UmbPropertyEditorConfigCollection ;
21
29
22
30
@property ( { attribute : false } )
23
- toolbar : string [ ] [ ] [ ] = [ [ [ ] ] ] ;
31
+ toolbar : UmbTiptapToolbarValue = [ [ [ ] ] ] ;
32
+
33
+ override connectedCallback ( ) : void {
34
+ super . connectedCallback ( ) ;
35
+ this . #attached = true ;
36
+ this . #observeExtensions( ) ;
37
+ }
38
+ override disconnectedCallback ( ) : void {
39
+ this . #attached = false ;
40
+ this . #extensionsController?. destroy ( ) ;
41
+ this . #extensionsController = undefined ;
42
+ super . disconnectedCallback ( ) ;
43
+ }
44
+
45
+ #observeExtensions( ) : void {
46
+ if ( ! this . #attached) return ;
47
+ this . #extensionsController?. destroy ( ) ;
48
+
49
+ this . #extensionsController = new UmbExtensionsElementAndApiInitializer (
50
+ this ,
51
+ umbExtensionsRegistry ,
52
+ 'tiptapToolbarExtension' ,
53
+ [ ] ,
54
+ ( manifest ) => this . toolbar . flat ( 2 ) . includes ( manifest . alias ) ,
55
+ ( extensionControllers ) => {
56
+ this . _lookup = new Map ( extensionControllers . map ( ( ext ) => [ ext . alias , ext . component ] ) ) ;
57
+ } ,
58
+ ) ;
59
+
60
+ this . #extensionsController. apiProperties = { configuration : this . configuration } ;
61
+ this . #extensionsController. elementProperties = { editor : this . editor , configuration : this . configuration } ;
62
+ }
24
63
25
64
override render ( ) {
26
- return html `
27
- <umb- extension- with- api- slot
28
- type= "tiptapToolbarExtension"
29
- .filter = ${ ( ext : ManifestTiptapToolbarExtension ) =>
30
- this . toolbar . flat ( 2 ) . includes ( ext . alias ) && ( ! ! ext . kind || ! ! ext . element ) }
31
- .elementProps = ${ { editor : this . editor , configuration : this . configuration } }
32
- .apiProps = ${ { configuration : this . configuration } } >
33
- </ umb- extension- with- api- slot>
34
- ` ;
65
+ return html `${ map ( this . toolbar , ( row , rowIndex ) =>
66
+ map (
67
+ row ,
68
+ ( group , groupIndex ) =>
69
+ html `${ map ( group , ( alias , aliasIndex ) => {
70
+ const newRow = rowIndex !== 0 && groupIndex === 0 && aliasIndex === 0 ;
71
+ return html `<div class= "item" ?data- new- row= ${ newRow } style= "${ newRow ? 'grid-column: 1 / span 3' : '' } " >
72
+ ${ this . _lookup ?. get ( alias ) }
73
+ </ div> ` ;
74
+ } ) }
75
+ <div class= "separator" > </ div> ` ,
76
+ ) ,
77
+ ) } `;
35
78
}
36
79
37
80
static override readonly styles = css `
81
+ : host ([readonly ]) {
82
+ pointer-events : none;
83
+ background-color : var (--uui-color-surface-alt );
84
+ }
85
+
38
86
: host {
39
87
bor der- radius: var(--uui-border-radius );
40
88
bor der: 1px solid var(- - uui- color - bor der);
@@ -43,20 +91,29 @@ export class UmbTiptapFixedMenuElement extends UmbLitElement {
43
91
background- color : var(- - uui- color - surface);
44
92
color : var(- - color - text);
45
93
dis play: grid;
46
- grid-template-columns : repeat (auto-fill, minmax (24 px , 1fr ));
47
- gap : var ( --uui-size-space-1 ) ;
94
+ grid- template-columns: repeat(auto - fill, minmax (10px , 1fr));
95
+ grid - au to - flow : row ;
48
96
position: sticky;
49
97
to p: -25px;
50
98
left: 0px;
51
99
right: 0px;
52
100
padding: var(- - uui- size-space-3);
53
- align-items : center;
54
101
z- index: 9999999;
55
102
}
56
103
57
- : host ([readonly ]) {
58
- pointer-events : none;
59
- background-color : var (--uui-color-surface-alt );
104
+ .item {
105
+ grid-column : span 3 ;
106
+ }
107
+
108
+ .separator {
109
+ background-color : var (--uui-color-border );
110
+ width : 1px ;
111
+ place-self : center;
112
+ height : 22px ;
113
+ }
114
+ .separator : last-child ,
115
+ .separator : has (+ [data-new-row ]) {
116
+ display : none;
60
117
}
61
118
` ;
62
119
}
0 commit comments