1
1
import type { UmbCodeEditorElement } from '../components/code-editor.element.js' ;
2
2
import type { UmbCodeEditorModalData , UmbCodeEditorModalValue } from './code-editor-modal.token.js' ;
3
- import { css , html , ifDefined , customElement , query } from '@umbraco-cms/backoffice/external/lit' ;
3
+ import { css , customElement , html , ifDefined , query } from '@umbraco-cms/backoffice/external/lit' ;
4
4
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal' ;
5
5
6
- const elementName = 'umb-code-editor-modal' ;
7
-
8
- @customElement ( elementName )
6
+ @customElement ( 'umb-code-editor-modal' )
9
7
export class UmbCodeEditorModalElement extends UmbModalBaseElement < UmbCodeEditorModalData , UmbCodeEditorModalValue > {
10
8
@query ( 'umb-code-editor' )
11
9
_codeEditor ?: UmbCodeEditorElement ;
@@ -18,29 +16,39 @@ export class UmbCodeEditorModalElement extends UmbModalBaseElement<UmbCodeEditor
18
16
#handleCancel( ) {
19
17
this . modalContext ?. reject ( ) ;
20
18
}
19
+
20
+ #onLoaded( ) {
21
+ if ( this . data ?. formatOnLoad ) {
22
+ setTimeout ( ( ) => {
23
+ this . _codeEditor ?. editor ?. monacoEditor ?. getAction ( 'editor.action.formatDocument' ) ?. run ( ) ;
24
+ } , 100 ) ;
25
+ }
26
+ }
27
+
21
28
override render ( ) {
22
29
return html `
23
30
<umb- body- layout .headline = ${ this . data ?. headline ?? 'Code Editor' } >
24
31
<div id= "editor-box" > ${ this . #renderCodeEditor( ) } </ div>
25
- <div slot= "actions" >
26
- <uui- butto n
27
- id= "cancel"
28
- label = ${ this . localize . term ( 'general_cancel' ) }
29
- @click = ${ this . #handleCancel} > </ uui- butto n>
30
- <uui- butto n
31
- id= "confirm"
32
- color = "${ this . data ?. color || 'positive' } "
33
- look = "primary"
34
- label = "${ this . data ?. confirmLabel || this . localize . term ( 'general_submit' ) } "
35
- @click = ${ this . #handleConfirm} > </ uui- butto n>
36
- </ div>
32
+ <uui- butto n
33
+ slot= "actions"
34
+ label = ${ this . localize . term ( 'general_cancel' ) }
35
+ @click = ${ this . #handleCancel} > </ uui- butto n>
36
+ <uui- butto n
37
+ slot= "actions"
38
+ color = ${ this . data ?. color || 'positive' }
39
+ look= "primary"
40
+ label = ${ this . data ?. confirmLabel || this . localize . term ( 'general_submit' ) }
41
+ @click = ${ this . #handleConfirm} > </ uui- butto n>
37
42
</ umb- body- layout>
38
43
` ;
39
44
}
40
45
41
46
#renderCodeEditor( ) {
42
47
return html `
43
- <umb- code-edito r language= ${ ifDefined ( this . data ?. language ) } .code = ${ this . data ?. content ?? '' } > </ umb- code-edito r>
48
+ <umb- code-edito r
49
+ language= ${ ifDefined ( this . data ?. language ) }
50
+ .code = ${ this . data ?. content ?? '' }
51
+ @loaded = ${ this . #onLoaded} > </ umb- code-edito r>
44
52
` ;
45
53
}
46
54
@@ -63,6 +71,6 @@ export default UmbCodeEditorModalElement;
63
71
64
72
declare global {
65
73
interface HTMLElementTagNameMap {
66
- [ elementName ] : UmbCodeEditorModalElement ;
74
+ 'umb-code-editor-modal' : UmbCodeEditorModalElement ;
67
75
}
68
76
}
0 commit comments