@@ -27,27 +27,28 @@ import { TabsUtilService } from './tabs-util.service';
2727export class DomUtilService {
2828
2929 private editableSelector = '.value-container input, div[contenteditable=true]' ;
30+ // highlight class is defined in json-editor.component.scss
31+ private highlightClass = 'highlight' ;
32+ private highlightedElement : HTMLElement ;
3033
3134 constructor ( public tabsUtilService : TabsUtilService ) { }
3235
33- focusAndSelectFirstEditableChildById ( id : string ) {
36+ focusAndSelectFirstEditableChildById ( id : string , highlight = false ) {
3437 this . tabsUtilService . selectTabIfNeeded ( id ) ;
3538 setTimeout ( ( ) => {
3639 let el = document . getElementById ( id ) ;
3740 if ( el ) {
38- let firstInput = el . querySelector ( this . editableSelector ) as HTMLElement ;
39- if ( firstInput ) {
40- firstInput . focus ( ) ;
41- this . selectAllContent ( firstInput ) ;
41+ let firstEditable = el . querySelector ( this . editableSelector ) as HTMLElement ;
42+ if ( firstEditable ) {
43+ firstEditable . focus ( ) ;
44+ this . selectAllContent ( firstEditable ) ;
45+ if ( highlight ) {
46+ firstEditable . classList . add ( this . highlightClass ) ;
47+ this . highlightedElement = firstEditable ;
48+ }
4249 } else {
4350 // if element doesn't have any input, open add-field-dropdown if it exists.
44- firstInput = el . querySelector ( 'div.btn-group' ) as HTMLInputElement ;
45- if ( firstInput ) {
46- let dropDownButton = el . querySelector ( 'div.btn-group button' ) as HTMLButtonElement ;
47- if ( dropDownButton ) {
48- dropDownButton . click ( ) ;
49- }
50- }
51+ this . openDropdown ( el ) ;
5152 }
5253 }
5354 } ) ;
@@ -80,25 +81,18 @@ export class DomUtilService {
8081 }
8182 }
8283
83- flashElementById ( id : string ) {
84- this . tabsUtilService . selectTabIfNeeded ( id ) ;
85- setTimeout ( ( ) => {
86- let el = document . getElementById ( id ) ;
87- if ( el ) {
88- // .flash is defined json-editor.component.scss, {border: 2px solid yellow;}
89- el . classList . add ( 'flash' ) ;
90- setTimeout ( ( ) => {
91- el . classList . remove ( 'flash' ) ;
92- } , 500 ) ;
93- }
94- } ) ;
95- }
96-
9784 blurFirstEditableChildById ( id : string ) {
9885 let el = document . getElementById ( id ) ;
99- let firstInput = el . querySelector ( this . editableSelector ) as HTMLElement ;
100- if ( firstInput ) {
101- firstInput . blur ( ) ;
86+ let firstEditable = el . querySelector ( this . editableSelector ) as HTMLElement ;
87+ if ( firstEditable ) {
88+ firstEditable . blur ( ) ;
89+ }
90+ }
91+
92+ clearHighlight ( ) {
93+ if ( this . highlightedElement ) {
94+ this . highlightedElement . classList . remove ( this . highlightClass ) ;
95+ this . highlightedElement = undefined ;
10296 }
10397 }
10498
@@ -115,4 +109,14 @@ export class DomUtilService {
115109 }
116110 }
117111
112+ private openDropdown ( el : HTMLElement ) {
113+ let dropdown = el . querySelector ( 'div.btn-group' ) ;
114+ if ( dropdown ) {
115+ let dropDownButton = dropdown . querySelector ( 'button' ) as HTMLButtonElement ;
116+ if ( dropDownButton ) {
117+ dropDownButton . click ( ) ;
118+ }
119+ }
120+ }
121+
118122}
0 commit comments