@@ -53,9 +53,12 @@ import "./hat-graph-node";
53
53
import "./hat-graph-spacer" ;
54
54
import { ACTION_ICONS } from "../../data/action" ;
55
55
56
+ type NodeType = "trigger" | "condition" | "action" | "chooseOption" | undefined ;
57
+
56
58
export interface NodeInfo {
57
59
path : string ;
58
60
config : any ;
61
+ type ?: NodeType ;
59
62
}
60
63
61
64
declare global {
@@ -76,24 +79,24 @@ export class HatScriptGraph extends LitElement {
76
79
77
80
public trackedNodes : Record < string , NodeInfo > = { } ;
78
81
79
- private _selectNode ( config , path ) {
82
+ private _selectNode ( config , path , type ? ) {
80
83
return ( ) => {
81
- fireEvent ( this , "graph-node-selected" , { config, path } ) ;
84
+ fireEvent ( this , "graph-node-selected" , { config, path, type } ) ;
82
85
} ;
83
86
}
84
87
85
88
private _renderTrigger ( config : Trigger , i : number ) {
86
89
const path = `trigger/${ i } ` ;
87
90
const track = this . trace && path in this . trace . trace ;
88
- this . renderedNodes [ path ] = { config, path } ;
91
+ this . renderedNodes [ path ] = { config, path, type : "trigger" } ;
89
92
if ( track ) {
90
93
this . trackedNodes [ path ] = this . renderedNodes [ path ] ;
91
94
}
92
95
return html `
93
96
<hat- graph- node
94
97
graph- start
95
98
?track= ${ track }
96
- @focus = ${ this . _selectNode ( config , path ) }
99
+ @focus = ${ this . _selectNode ( config , path , "trigger" ) }
97
100
?active= ${ this . selected === path }
98
101
.iconPath = ${ mdiAsterisk }
99
102
.notEnabled = ${ "enabled" in config && config . enabled === false }
@@ -105,7 +108,7 @@ export class HatScriptGraph extends LitElement {
105
108
106
109
private _renderCondition ( config : Condition , i : number ) {
107
110
const path = `condition/${ i } ` ;
108
- this . renderedNodes [ path ] = { config, path } ;
111
+ this . renderedNodes [ path ] = { config, path, type : "condition" } ;
109
112
if ( this . trace && path in this . trace . trace ) {
110
113
this . trackedNodes [ path ] = this . renderedNodes [ path ] ;
111
114
}
@@ -136,7 +139,7 @@ export class HatScriptGraph extends LitElement {
136
139
) {
137
140
const type =
138
141
Object . keys ( this . _typeRenderers ) . find ( ( key ) => key in node ) || "other" ;
139
- this . renderedNodes [ path ] = { config : node , path } ;
142
+ this . renderedNodes [ path ] = { config : node , path, type : "action" } ;
140
143
if ( this . trace && path in this . trace . trace ) {
141
144
this . trackedNodes [ path ] = this . renderedNodes [ path ] ;
142
145
}
@@ -166,7 +169,7 @@ export class HatScriptGraph extends LitElement {
166
169
return html `
167
170
<hat- graph- branch
168
171
tabindex= ${ trace === undefined ? "-1" : "0" }
169
- @focus = ${ this . _selectNode ( config , path ) }
172
+ @focus = ${ this . _selectNode ( config , path , "action" ) }
170
173
?track= ${ trace !== undefined }
171
174
?active= ${ this . selected === path }
172
175
.notEnabled = ${ disabled || config . enabled === false }
@@ -189,6 +192,7 @@ export class HatScriptGraph extends LitElement {
189
192
this . renderedNodes [ branchPath ] = {
190
193
config : branch ,
191
194
path : branchPath ,
195
+ type : "chooseOption" ,
192
196
} ;
193
197
if ( trackThis ) {
194
198
this . trackedNodes [ branchPath ] = this . renderedNodes [ branchPath ] ;
@@ -199,7 +203,11 @@ export class HatScriptGraph extends LitElement {
199
203
.iconPath = ${ ! trace || trackThis
200
204
? mdiCheckboxMarkedOutline
201
205
: mdiCheckboxBlankOutline }
202
- @focus = ${ this . _selectNode ( branch , branchPath ) }
206
+ @focus = ${ this . _selectNode (
207
+ branch ,
208
+ branchPath ,
209
+ "chooseOption"
210
+ ) }
203
211
?track= ${ trackThis }
204
212
?active= ${ this . selected === branchPath }
205
213
.notEnabled = ${ disabled || config . enabled === false }
@@ -259,7 +267,7 @@ export class HatScriptGraph extends LitElement {
259
267
return html `
260
268
<hat- graph- branch
261
269
tabindex= ${ trace === undefined ? "-1" : "0" }
262
- @focus = ${ this . _selectNode ( config , path ) }
270
+ @focus = ${ this . _selectNode ( config , path , "action" ) }
263
271
?track= ${ trace !== undefined }
264
272
?active= ${ this . selected === path }
265
273
.notEnabled = ${ disabled || config . enabled === false }
@@ -340,7 +348,7 @@ export class HatScriptGraph extends LitElement {
340
348
}
341
349
return html `
342
350
<hat- graph- branch
343
- @focus = ${ this . _selectNode ( node , path ) }
351
+ @focus = ${ this . _selectNode ( node , path , "condition" ) }
344
352
?track= ${ track }
345
353
?active= ${ this . selected === path }
346
354
.notEnabled = ${ disabled || node . enabled === false }
@@ -384,7 +392,7 @@ export class HatScriptGraph extends LitElement {
384
392
return html `
385
393
<hat- graph- branch
386
394
tabindex= ${ trace === undefined ? "-1" : "0" }
387
- @focus = ${ this . _selectNode ( node , path ) }
395
+ @focus = ${ this . _selectNode ( node , path , "action" ) }
388
396
?track= ${ path in this . trace . trace }
389
397
?active= ${ this . selected === path }
390
398
.notEnabled = ${ disabled || node . enabled === false }
@@ -430,7 +438,7 @@ export class HatScriptGraph extends LitElement {
430
438
<hat- graph- node
431
439
.graphStart = ${ graphStart }
432
440
.iconPath = ${ node . action ? undefined : mdiRoomService }
433
- @focus = ${ this . _selectNode ( node , path ) }
441
+ @focus = ${ this . _selectNode ( node , path , "action" ) }
434
442
?track= ${ path in this . trace . trace }
435
443
?active= ${ this . selected === path }
436
444
.notEnabled = ${ disabled || node . enabled === false }
@@ -458,7 +466,7 @@ export class HatScriptGraph extends LitElement {
458
466
<hat- graph- node
459
467
.graphStart = ${ graphStart }
460
468
.iconPath = ${ mdiCodeBraces }
461
- @focus = ${ this . _selectNode ( node , path ) }
469
+ @focus = ${ this . _selectNode ( node , path , "action" ) }
462
470
?track= ${ path in this . trace . trace }
463
471
?active= ${ this . selected === path }
464
472
.notEnabled = ${ disabled || node . enabled === false }
@@ -478,7 +486,7 @@ export class HatScriptGraph extends LitElement {
478
486
return html `
479
487
<hat- graph- branch
480
488
tabindex= ${ trace === undefined ? "-1" : "0" }
481
- @focus = ${ this . _selectNode ( node , path ) }
489
+ @focus = ${ this . _selectNode ( node , path , "action" ) }
482
490
?track= ${ path in this . trace . trace }
483
491
?active= ${ this . selected === path }
484
492
.notEnabled = ${ disabled || node . enabled === false }
@@ -516,7 +524,7 @@ export class HatScriptGraph extends LitElement {
516
524
return html `
517
525
<hat- graph- branch
518
526
tabindex= ${ trace === undefined ? "-1" : "0" }
519
- @focus = ${ this . _selectNode ( node , path ) }
527
+ @focus = ${ this . _selectNode ( node , path , "action" ) }
520
528
?track= ${ path in this . trace . trace }
521
529
?active= ${ this . selected === path }
522
530
.notEnabled = ${ disabled || node . enabled === false }
@@ -565,7 +573,7 @@ export class HatScriptGraph extends LitElement {
565
573
<hat- graph- node
566
574
.graphStart = ${ graphStart }
567
575
.iconPath = ${ ACTION_ICONS [ getActionType ( node ) ] || mdiCodeBrackets }
568
- @focus = ${ this . _selectNode ( node , path ) }
576
+ @focus = ${ this . _selectNode ( node , path , "action" ) }
569
577
?track= ${ path in this . trace . trace }
570
578
?active= ${ this . selected === path }
571
579
.error = ${ this . trace . trace [ path ] ?. some ( ( tr ) => tr . error ) }
0 commit comments