11function getGlideFormAW ( ) {
2- document . getElementsByTagName ( "sn-workspace-content" ) [ 0 ] . shadowRoot . querySelectorAll ( "now-record-form-connected" ) [ 0 ]
2+ function collectDeepElements ( selector ) {
3+ var results = [ ] ;
4+ var queue = [ document ] ;
5+ var visited = [ ] ;
36
4- var firstContentChild = document . getElementsByTagName ( "sn-workspace-content" ) [ 0 ] . shadowRoot
5- . querySelectorAll ( ".chrome-tab-panel.is-active" ) [ 0 ] . firstChild ;
7+ while ( queue . length > 0 ) {
8+ var node = queue . shift ( ) ;
9+ if ( ! node || visited . indexOf ( node ) >= 0 ) {
10+ continue ;
11+ }
12+ visited . push ( node ) ;
613
7- var snWorkspaceFormEl ;
8- if ( firstContentChild . tagName == "NOW-RECORD-FORM-CONNECTED" ) {
9- snWorkspaceFormEl = firstContentChild . shadowRoot . querySelectorAll ( ".sn-workspace-form" ) [ 0 ] ;
10- } else {
11- snWorkspaceFormEl = firstContentChild . shadowRoot . querySelectorAll ( "now-record-form-connected" ) [ 0 ]
12- . shadowRoot . querySelectorAll ( ".sn-workspace-form" ) [ 0 ] ;
14+ if ( node . querySelectorAll ) {
15+ var matches = node . querySelectorAll ( selector ) ;
16+ for ( var i = 0 ; i < matches . length ; i ++ ) {
17+ results . push ( matches [ i ] ) ;
18+ }
19+ }
20+
21+ var descendants = [ ] ;
22+ if ( node . querySelectorAll ) {
23+ descendants = node . querySelectorAll ( "*" ) ;
24+ } else if ( node . children ) {
25+ descendants = node . children ;
26+ }
27+ for ( var j = 0 ; j < descendants . length ; j ++ ) {
28+ if ( descendants [ j ] && descendants [ j ] . shadowRoot ) {
29+ queue . push ( descendants [ j ] . shadowRoot ) ;
30+ }
31+ }
32+ }
33+
34+ return results ;
35+ }
36+
37+ function fromSnFormDataConnected ( ) {
38+ var connected = collectDeepElements ( "sn-form-data-connected" ) ;
39+ for ( var i = 0 ; i < connected . length ; i ++ ) {
40+ var gForm = connected [ i ] && connected [ i ] . nowRecordFormBlob && connected [ i ] . nowRecordFormBlob . gForm ;
41+ if ( gForm ) {
42+ return gForm ;
43+ }
44+ }
45+ return null ;
1346 }
14- if ( ! snWorkspaceFormEl ) throw "Couldn't find sn-workspace-form" ;
1547
16- var reactInternalInstanceKey = Object . keys ( snWorkspaceFormEl ) . find ( function ( objKey ) {
17- if ( objKey . indexOf ( "__reactInternalInstance$" ) >= 0 ) {
18- return true ;
48+ function fromSnWorkspaceForm ( ) {
49+ var workspaceForms = collectDeepElements ( ".sn-workspace-form" ) ;
50+ for ( var i = 0 ; i < workspaceForms . length ; i ++ ) {
51+ var snWorkspaceFormEl = workspaceForms [ i ] ;
52+ var reactInternalInstanceKey = Object . keys ( snWorkspaceFormEl ) . find ( function ( objKey ) {
53+ return objKey . indexOf ( "__reactInternalInstance$" ) >= 0 ;
54+ } ) ;
55+ var reactNode = reactInternalInstanceKey && snWorkspaceFormEl [ reactInternalInstanceKey ] ;
56+ if ( reactNode && reactNode . return && reactNode . return . stateNode
57+ && reactNode . return . stateNode . props
58+ && reactNode . return . stateNode . props . glideEnvironment
59+ && reactNode . return . stateNode . props . glideEnvironment . _gForm ) {
60+ return reactNode . return . stateNode . props . glideEnvironment . _gForm ;
61+ }
1962 }
20- return false ;
21- } ) ;
22- return snWorkspaceFormEl [ reactInternalInstanceKey ] . return . stateNode . props . glideEnvironment . _gForm ;
23- }
63+ return null ;
64+ }
65+
66+ return fromSnFormDataConnected ( ) || fromSnWorkspaceForm ( ) ;
67+ }
0 commit comments