@@ -14,6 +14,8 @@ import {
1414 Navigation ,
1515 Dot ,
1616 SvgMask ,
17+ ResizeObserver as ReactourResizeObserver ,
18+ MutationObserver as ReactourMutationObserver ,
1719} from './components/index'
1820import Portal from './Portal'
1921import * as hx from './helpers'
@@ -153,20 +155,15 @@ class Tour extends Component {
153155 ) {
154156 const cb = ( ) => stepCallback ( mutation . addedNodes [ 0 ] )
155157 setTimeout (
156- ( ) =>
157- this . calculateNode (
158- mutation . addedNodes [ 0 ] ,
159- step . position ,
160- cb
161- ) ,
158+ ( ) => this . calculateNode ( mutation . addedNodes [ 0 ] , step , cb ) ,
162159 100
163160 )
164161 } else if (
165162 mutation . type === 'childList' &&
166163 mutation . removedNodes . length > 0
167164 ) {
168165 const cb = ( ) => stepCallback ( node )
169- this . calculateNode ( node , step . position , cb )
166+ this . calculateNode ( node , step , cb )
170167 }
171168 } )
172169 } ) ,
@@ -185,12 +182,9 @@ class Tour extends Component {
185182
186183 if ( node ) {
187184 const cb = ( ) => stepCallback ( node )
188- this . calculateNode ( node , step . position , cb )
185+ this . calculateNode ( node , step , cb )
189186 } else {
190- this . setState (
191- setNodeState ( null , this . helper . current , step . position ) ,
192- stepCallback
193- )
187+ this . setState ( setNodeState ( null , step , this . helper . current ) , stepCallback )
194188
195189 step . selector &&
196190 console . warn (
@@ -199,9 +193,9 @@ class Tour extends Component {
199193 }
200194 }
201195
202- calculateNode = ( node , stepPosition , cb ) => {
196+ calculateNode = ( node , step , cb ) => {
203197 const { scrollDuration, inViewThreshold, scrollOffset } = this . props
204- const attrs = hx . getNodeRect ( node )
198+ const attrs = hx . getHighlightedRect ( node , step )
205199 const w = Math . max (
206200 document . documentElement . clientWidth ,
207201 window . innerWidth || 0
@@ -222,14 +216,25 @@ class Tour extends Component {
222216 duration : scrollDuration ,
223217 offset,
224218 callback : nd => {
225- this . setState ( setNodeState ( nd , this . helper . current , stepPosition ) , cb )
219+ this . setState ( setNodeState ( nd , step , this . helper . current ) , cb )
226220 } ,
227221 } )
228222 } else {
229- this . setState ( setNodeState ( node , this . helper . current , stepPosition ) , cb )
223+ this . setState ( setNodeState ( node , step , this . helper . current ) , cb )
230224 }
231225 }
232226
227+ recalculateNode = step => {
228+ const node = document . querySelector ( step . selector )
229+ const stepCallback = o => {
230+ if ( step . action && typeof step . action === 'function' ) {
231+ this . unlockFocus ( ( ) => step . action ( o ) )
232+ }
233+ }
234+
235+ this . calculateNode ( node , step , ( ) => stepCallback ( node ) )
236+ }
237+
233238 close ( ) {
234239 this . setState ( prevState => {
235240 if ( prevState . observer ) {
@@ -401,6 +406,14 @@ class Tour extends Component {
401406 return (
402407 < Portal >
403408 < GlobalStyle />
409+ < ReactourResizeObserver
410+ step = { steps [ current ] }
411+ refresh = { ( ) => this . recalculateNode ( steps [ current ] ) }
412+ />
413+ < ReactourMutationObserver
414+ step = { steps [ current ] }
415+ refresh = { ( ) => this . recalculateNode ( steps [ current ] ) }
416+ />
404417 < SvgMask
405418 onClick = { this . maskClickHandler }
406419 forwardRef = { c => ( this . mask = c ) }
@@ -567,7 +580,7 @@ class Tour extends Component {
567580 }
568581}
569582
570- const setNodeState = ( node , helper , position ) => {
583+ const setNodeState = ( node , step , helper ) => {
571584 const w = Math . max (
572585 document . documentElement . clientWidth ,
573586 window . innerWidth || 0
@@ -578,26 +591,29 @@ const setNodeState = (node, helper, position) => {
578591 )
579592 const { width : helperWidth , height : helperHeight } = hx . getNodeRect ( helper )
580593
581- const attrs = node
582- ? hx . getNodeRect ( node )
583- : {
584- top : h + 10 ,
585- right : w / 2 + 9 ,
586- bottom : h / 2 + 9 ,
587- left : w / 2 - helperWidth / 2 ,
588- width : 0 ,
589- height : 0 ,
590- w,
591- h,
592- helperPosition : 'center' ,
593- }
594+ let attrs = {
595+ top : h + 10 ,
596+ right : w / 2 + 9 ,
597+ bottom : h / 2 + 9 ,
598+ left : w / 2 - helperWidth / 2 ,
599+ width : 0 ,
600+ height : 0 ,
601+ w,
602+ h,
603+ helperPosition : 'center' ,
604+ }
605+
606+ if ( node ) {
607+ attrs = hx . getHighlightedRect ( node , step )
608+ }
609+
594610 return function update ( ) {
595611 return {
596612 w,
597613 h,
598614 helperWidth,
599615 helperHeight,
600- helperPosition : position ,
616+ helperPosition : step . position ,
601617 ...attrs ,
602618 inDOM : node ? true : false ,
603619 }
0 commit comments