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