@@ -19,14 +19,14 @@ import {
19
19
getValue ,
20
20
identity ,
21
21
isPublic ,
22
- newActionEvent ,
23
22
newSubWizardEvent ,
24
- newWizardEvent ,
25
23
Replace ,
26
24
selector ,
27
25
Wizard ,
26
+ WizardAction ,
28
27
WizardActor ,
29
28
WizardInput ,
29
+ WizardMenuActor ,
30
30
} from '../../foundation.js' ;
31
31
import { createDaWizard , editDAWizard } from '../../wizards/da.js' ;
32
32
import { patterns } from '../../wizards/foundation/limits.js' ;
@@ -39,6 +39,12 @@ import {
39
39
WizardOptions ,
40
40
} from './foundation.js' ;
41
41
42
+ function remove ( element : Element ) : WizardMenuActor {
43
+ return ( ) : EditorAction [ ] => {
44
+ return [ { old : { parent : element . parentElement ! , element } } ] ;
45
+ } ;
46
+ }
47
+
42
48
function updateSDoAction ( element : Element ) : WizardActor {
43
49
return ( inputs : WizardInput [ ] ) : EditorAction [ ] => {
44
50
const name = getValue ( inputs . find ( i => i . label === 'name' ) ! ) ! ;
@@ -96,37 +102,20 @@ function sDOWizard(options: WizardOptions): Wizard | undefined {
96
102
)
97
103
) . find ( isPublic ) ?? null ;
98
104
99
- const [ title , action , type , deleteButton , name , desc ] = sdo
105
+ const [ title , action , type , menuActions , name , desc ] = sdo
100
106
? [
101
107
get ( 'sdo.wizard.title.edit' ) ,
102
108
updateSDoAction ( sdo ) ,
103
109
sdo . getAttribute ( 'type' ) ,
104
- html `< mwc-button
105
- icon ="delete "
106
- trailingIcon
107
- label ="${ translate ( 'remove' ) } "
108
- @click =${ ( e : MouseEvent ) => {
109
- e . target ! . dispatchEvent ( newWizardEvent ( ) ) ;
110
- e . target ! . dispatchEvent (
111
- newActionEvent ( {
112
- old : {
113
- parent : sdo . parentElement ! ,
114
- element : sdo ,
115
- reference : sdo . nextSibling ,
116
- } ,
117
- } )
118
- ) ;
119
- } }
120
- fullwidth
121
- > </ mwc-button > ` ,
110
+ [ { icon : 'delete' , label : get ( 'remove' ) , action : remove ( sdo ) } ] ,
122
111
sdo . getAttribute ( 'name' ) ,
123
112
sdo . getAttribute ( 'desc' ) ,
124
113
]
125
114
: [
126
115
get ( 'sdo.wizard.title.add' ) ,
127
116
createSDoAction ( ( < CreateOptions > options ) . parent ) ,
128
117
null ,
129
- html `` ,
118
+ undefined ,
130
119
'' ,
131
120
null ,
132
121
] ;
@@ -140,8 +129,8 @@ function sDOWizard(options: WizardOptions): Wizard | undefined {
140
129
title,
141
130
element : sdo ?? undefined ,
142
131
primary : { icon : '' , label : get ( 'save' ) , action } ,
132
+ menuActions,
143
133
content : [
144
- deleteButton ,
145
134
html `< wizard-textfield
146
135
label ="name "
147
136
.maybeValue =${ name }
@@ -306,6 +295,18 @@ export function createDOTypeWizard(
306
295
] ;
307
296
}
308
297
298
+ function openAddSdo ( parent : Element ) : WizardMenuActor {
299
+ return ( ) : WizardAction [ ] => {
300
+ return [ ( ) => sDOWizard ( { parent } ) ! ] ;
301
+ } ;
302
+ }
303
+
304
+ function openAddDa ( parent : Element ) : WizardMenuActor {
305
+ return ( ) : WizardAction [ ] => {
306
+ return [ ( ) => createDaWizard ( parent ) ! ] ;
307
+ } ;
308
+ }
309
+
309
310
function updateDOTypeAction ( element : Element ) : WizardActor {
310
311
return ( inputs : WizardInput [ ] ) : EditorAction [ ] => {
311
312
const id = getValue ( inputs . find ( i => i . label === 'id' ) ! ) ! ;
@@ -358,25 +359,24 @@ export function dOTypeWizard(
358
359
label : get ( 'save' ) ,
359
360
action : updateDOTypeAction ( dotype ) ,
360
361
} ,
362
+ menuActions : [
363
+ {
364
+ label : get ( 'remove' ) ,
365
+ icon : 'delete' ,
366
+ action : remove ( dotype ) ,
367
+ } ,
368
+ {
369
+ label : get ( 'scl.DO' ) ,
370
+ icon : 'playlist_add' ,
371
+ action : openAddSdo ( dotype ) ,
372
+ } ,
373
+ {
374
+ label : get ( 'scl.DA' ) ,
375
+ icon : 'playlist_add' ,
376
+ action : openAddDa ( dotype ) ,
377
+ } ,
378
+ ] ,
361
379
content : [
362
- html `< mwc-button
363
- icon ="delete "
364
- trailingIcon
365
- label ="${ translate ( 'remove' ) } "
366
- @click =${ ( e : MouseEvent ) => {
367
- e . target ! . dispatchEvent ( newWizardEvent ( ) ) ;
368
- e . target ! . dispatchEvent (
369
- newActionEvent ( {
370
- old : {
371
- parent : dotype . parentElement ! ,
372
- element : dotype ,
373
- reference : dotype . nextSibling ,
374
- } ,
375
- } )
376
- ) ;
377
- } }
378
- fullwidth
379
- > </ mwc-button > ` ,
380
380
html `< wizard-textfield
381
381
label ="id "
382
382
helper ="${ translate ( 'scl.id' ) } "
@@ -400,32 +400,6 @@ export function dOTypeWizard(
400
400
.maybeValue =${ dotype . getAttribute ( 'cdc' ) }
401
401
pattern ="${ patterns . normalizedString } "
402
402
> </ wizard-textfield > ` ,
403
- html `< section >
404
- < mwc-button
405
- slot ="graphic "
406
- icon ="playlist_add "
407
- trailingIcon
408
- label ="${ translate ( 'scl.DO' ) } "
409
- @click =${ ( e : Event ) => {
410
- const wizard = sDOWizard ( {
411
- parent : dotype ,
412
- } ) ;
413
- if ( wizard ) e . target ! . dispatchEvent ( newSubWizardEvent ( wizard ) ) ;
414
- } }
415
- > </ mwc-button >
416
- < mwc-button
417
- slot ="graphic "
418
- icon ="playlist_add "
419
- trailingIcon
420
- label ="${ translate ( 'scl.DA' ) } "
421
- @click =${ ( e : Event ) => {
422
- if ( dotype )
423
- e . target ! . dispatchEvent (
424
- newSubWizardEvent ( createDaWizard ( dotype ) )
425
- ) ;
426
- } }
427
- > </ mwc-button >
428
- </ section > ` ,
429
403
html `
430
404
< mwc-list
431
405
style ="margin-top: 0px; "
0 commit comments