Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-interactive-guide

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-interactive-guide - npm Package Compare versions

Comparing version 2.2.2 to 2.2.3

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [2.2.3](https://github.com/dominictwlee/react-interactive-guide/compare/v2.2.2...v2.2.3) (2020-05-01)
### Bug Fixes
* hide Control and Overlay when tourguide is not showing ([6bbf1e7](https://github.com/dominictwlee/react-interactive-guide/commit/6bbf1e7003362faa023209d07a7e355c338885a8))
## [2.2.2](https://github.com/dominictwlee/react-interactive-guide/compare/v2.2.1...v2.2.2) (2020-04-30)

@@ -2,0 +9,0 @@

2

dist/index.js

@@ -1,2 +0,2 @@

function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("react-dom")),n=e(require("lodash.throttle")),r=require("@popperjs/core"),o=e(require("styled-components")),i=require("react-spring"),s=require("react"),u=e(s),a=s.createContext(null);function l(){var e=s.useContext(a);if(!e)throw new Error("useGuide must be used within TourguideProvider");return e}var c=i.animated(o.div(function(e){var t=e.isIdle;return{position:"fixed",bottom:0,left:0,right:0,top:0,overflow:"hidden",visibility:t?"hidden":"visible",zIndex:t?-1:2300,backgroundColor:"rgba(26, 29, 52, 0.5)",mixBlendMode:"hard-light"}}));function d(e,t){"function"==typeof e?e(t):e&&(e.current=t)}function f(e){var t,n,o=e.anchorEl,i=e.popperOptions,u=e.ref,a=e.show,l=e.animated,c=s.useRef(null),f=s.useMemo(function(){return null==t&&null==n?null:function(e){d(t,e),d(n,e)}},[t=c,n=u]),h=s.useRef(null),m=s.useCallback(function(){o&&i&&c.current&&a&&(h.current=r.createPopper(o,c.current,i))},[o,i,a]),p=s.useCallback(function(){null!=h.current&&(h.current.destroy(),h.current=null)},[]);return s.useEffect(function(){return m(),function(){l||p()}},[m,p,l]),s.useEffect(function(){return function(){p()}},[p]),{selfRef:f,tooltipRef:c,destroy:p}}function h(e){var t=e.show,n=e.curPos,r=e.pos,o=e.destroy,i=s.useState("idle"),u=i[1];return{handleAnimStart:function(){t&&n===r&&u("active")},handleAnimRest:function(){t?n!==r&&u("standby"):(o(),u("idle"))},animLifecycle:i[0]}}var m=i.animated(function(e){var t=e.dimensions,n=e.style;return void 0===n&&(n={}),u.createElement("div",{style:Object.assign({},n,{borderRadius:4,backgroundColor:"gray",width:t[0],height:t[1]})})}),p=s.forwardRef(function(e,t){var n,r,o=e.anchorEl,a=e.show,l=e.curPos,c=e.pos,d=e.animated,p=e.positionStyles,g=e.styles,y=s.useState(null),v=y[0],b=y[1],E=p&&p[c]?p[c]:{},w=E.width,P=E.height,S=E.offsetX,k=E.offsetY,C=g||{},R=C.width,x=C.height,A=C.offsetX,j=C.offsetY,L=s.useMemo(function(){if(!v)return v;var e=v[0],t=v[1];return[null!=w?"function"==typeof w?w(e):w:null!=R?"function"==typeof R?R(e):R:e,null!=P?"function"==typeof P?P(t):P:null!=x?"function"==typeof x?x(t):x:t]},[v,w,R,P,x]),q=v&&L?{modifiers:[{name:"offset",options:{offset:[0+(S||A||0),(n=v,r=L,(r[1]<n[1]?-(Math.abs(r[1]-n[1])/2+r[1]):-(Math.abs(r[1]-n[1])/2+n[1]))-(k||j||0))]}}]}:null,M=f({anchorEl:o,show:a,popperOptions:q,ref:t,animated:d}),O=M.selfRef,I=h({show:a,curPos:l,pos:c,destroy:M.destroy}),z=I.handleAnimStart,Y=I.handleAnimRest,B=I.animLifecycle;s.useEffect(function(){if(o){var e=o.getBoundingClientRect();b([e.width,e.height])}},[o]);var F=i.useSpring({opacity:a&&l===c?1:0,onStart:z,onRest:Y,config:g&&g.spring});return L&&(a||d&&"idle"!==B)?u.createElement("div",{ref:O,style:{visibility:"standby"===B?"hidden":"visible"}},u.createElement(m,{style:d?F:void 0,dimensions:L})):null}),g={modifiers:[{name:"offset",options:{offset:[0,24]}}]},y=s.forwardRef(function(e,t){var n=e.show,r=e.children,o=e.curPos,s=e.pos,a=e.animated,l=f({anchorEl:e.anchorEl,show:n,popperOptions:g,ref:t,animated:a}),c=l.selfRef,d=h({show:n,curPos:o,pos:s,destroy:l.destroy}),m=d.animLifecycle,p=i.useSpring({to:{opacity:n&&o===s?1:0,transform:n&&o===s?"scaleY(1)":"scaleY(0)"},onStart:d.handleAnimStart,onRest:d.handleAnimRest});return n||a&&"idle"!==m?u.createElement("div",{ref:c,style:{visibility:"standby"===m?"hidden":"visible"}},r?u.createElement(i.animated.div,{style:a?p:void 0},r):null):null}),v=i.animated(o.div(function(e){return Object.assign({},{position:"absolute",zIndex:2600},function(e,t,n){var r={};return"center"===t?r.top="50vh":"top"===t?r.top="2vw":"bottom"===t&&(r.bottom="7vh"),"left"===e?r.left="2vw":"right"===e?r.right="2vw":"center"===e&&(r.left=n?"calc(50vw - "+n/2+"px)":"50vw"),r}(e.justify,e.align,e.measuredWidth))})),b=i.animated(o.div({width:24,height:24,border:"1.5px solid white",borderRadius:666})),E=function(e){var t=i.useSpring({backgroundColor:e.focused?"rgba(255, 255, 255, 1)":"rgba(255, 255, 255, 0)"});return u.createElement(b,Object.assign({},e,{style:t}))},w=o.div({display:"flex","& div:not(:first-child)":{marginLeft:24}}),P=function(e){var t=e.curPos;return u.createElement(w,null,Array(e.steps).fill(null).map(function(e,n){return u.createElement(E,{key:"dot-"+n,focused:t===n})}))},S=o.div({zIndex:2400,position:"absolute"});exports.useGuide=l,exports.Tourguide=function(e){var r=e.tooltip,o=e.animated;void 0===o&&(o=!0);var a=e.precondition;void 0===a&&(a=!0);var d=e.content,f=e.node,h=e.leftControl,m=e.rightControl,g=e.closeControl,b=e.positionStyles,E=e.styles,w=s.useState(0),k=w[0],C=w[1],R=s.useState(!0),x=R[0],A=R[1],j=l(),L=j.anchorEls,q=j.curPos,M=j.show,O=j.close,I=j.setStatus,z=j.prev,Y=j.next,B=s.useCallback(function(e){null!==e&&C(e.getBoundingClientRect().width)},[]),F=L[q],N=s.useCallback(n(function(e){switch(e.key){case"Escape":O();break;case"ArrowLeft":z();break;case"ArrowRight":Y()}},400),[O,Y,z]);s.useEffect(function(){return M&&document.addEventListener("keydown",N),function(){document.removeEventListener("keydown",N)}},[N,M]),s.useEffect(function(){a&&L.length&&I("ready")},[L.length,a,I]);var T=i.useSpring({opacity:M?1:0,onStart:function(){M&&A(!1)},onRest:function(){M||A(!0)}});return t.createPortal(o?u.createElement(u.Fragment,null,h&&u.createElement(v,{align:"center",justify:"left",style:T},h),m&&u.createElement(v,{align:"center",justify:"right",style:T},m),g&&u.createElement(v,{align:"top",justify:"right",style:T},g),u.createElement(v,{align:"bottom",justify:"center",ref:B,measuredWidth:k,style:T},u.createElement(P,{steps:L.length,curPos:q})),u.createElement(c,{style:T,isIdle:x},L.map(function(e){return u.createElement(p,{key:"spotlight-"+e.dataset.tourguidePosition,anchorEl:e,pos:Number(e.dataset.tourguidePosition),animated:!0,show:M,curPos:q,positionStyles:b&&b.spotlight,styles:E&&E.spotlight})})),u.createElement(S,null,L.map(function(e,t){return u.createElement(s.Fragment,{key:"tourguideEl-"+t},r&&u.createElement(y,{show:M,anchorEl:e,pos:Number(e.dataset.tourguidePosition),curPos:q,animated:!0,index:t},Array.isArray(r)?r[t]:s.isValidElement(r)?r:u.createElement(r,null,d&&d[t])))}))):u.createElement(u.Fragment,null,u.createElement(p,{anchorEl:F,show:M,pos:q,curPos:q,positionStyles:b&&b.spotlight,styles:E&&E.spotlight}),r&&u.createElement(y,{anchorEl:F,show:M,pos:q,curPos:q},r)),f)},exports.TourguideProvider=function(e){var t=e.children,n=function(){var e=s.useState([]),t=e[0],n=e[1],r=s.useState(!1),o=r[0],i=r[1],u=s.useState(0),a=u[0],l=u[1],c=s.useState("idle"),d=c[0],f=c[1],h=s.useCallback(function(e){null!==e&&e.dataset.tourguidePosition&&(n(function(t){var n=[].concat(t);return n[Number(e.dataset.tourguidePosition)]=e,n}),"idle"===d&&f("initializing"))},[d]),m=s.useCallback(function(e){return{ref:h,"data-tourguide-position":e}},[h]),p=s.useCallback(function(){i(function(e){return!e})},[]),g=s.useCallback(function(){i(!1),l(0)},[]),y=s.useCallback(function(){l(function(e){return e>=t.length-1?e:e+1})},[t.length]),v=s.useCallback(function(){l(function(e){return 0===e?e:e-1})},[]),b=s.useCallback(function(){i(!1),n([]),l(0),f("idle")},[]);return s.useMemo(function(){return{show:o,next:y,prev:v,anchorEls:t,curPos:a,getAnchorElProps:m,setShow:i,setCurPos:l,toggle:p,handleRef:h,reset:b,close:g,setStatus:f,status:d}},[t,a,m,h,y,v,b,o,p,g,d])}();return u.createElement(a.Provider,{value:n},t)};
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("react-dom")),n=e(require("lodash.throttle")),o=require("@popperjs/core"),r=e(require("styled-components")),i=require("react-spring"),s=require("react"),u=e(s),l=s.createContext(null);function a(){var e=s.useContext(l);if(!e)throw new Error("useGuide must be used within TourguideProvider");return e}var c=i.animated(r.div(function(e){return{position:"fixed",bottom:0,left:0,right:0,top:0,overflow:"hidden",visibility:e.isIdle&&!e.show?"hidden":"visible",backgroundColor:"rgba(26, 29, 52, 0.5)",mixBlendMode:"hard-light"}}));function d(e,t){"function"==typeof e?e(t):e&&(e.current=t)}function f(e){var t,n,r=e.anchorEl,i=e.popperOptions,u=e.ref,l=e.show,a=e.animated,c=s.useRef(null),f=s.useMemo(function(){return null==t&&null==n?null:function(e){d(t,e),d(n,e)}},[t=c,n=u]),h=s.useRef(null),m=s.useCallback(function(){r&&i&&c.current&&l&&(h.current=o.createPopper(r,c.current,i))},[r,i,l]),p=s.useCallback(function(){null!=h.current&&(h.current.destroy(),h.current=null)},[]);return s.useEffect(function(){return m(),function(){a||p()}},[m,p,a]),s.useEffect(function(){return function(){p()}},[p]),{selfRef:f,tooltipRef:c,destroy:p}}function h(e){var t=e.show,n=e.curPos,o=e.pos,r=e.destroy,i=s.useState("idle"),u=i[1];return{handleAnimStart:function(){t&&n===o&&u("active")},handleAnimRest:function(){t?n!==o&&u("standby"):(r(),u("idle"))},animLifecycle:i[0]}}var m=i.animated(function(e){var t=e.dimensions,n=e.style;return void 0===n&&(n={}),u.createElement("div",{style:Object.assign({},n,{borderRadius:4,backgroundColor:"gray",width:t[0],height:t[1]})})}),p=s.forwardRef(function(e,t){var n,o,r=e.anchorEl,l=e.show,a=e.curPos,c=e.pos,d=e.animated,p=e.positionStyles,g=e.styles,y=s.useState(null),v=y[0],b=y[1],E=p&&p[c]?p[c]:{},w=E.width,P=E.height,S=E.offsetX,k=E.offsetY,C=g||{},R=C.width,x=C.height,A=C.offsetX,j=C.offsetY,I=s.useMemo(function(){if(!v)return v;var e=v[0],t=v[1];return[null!=w?"function"==typeof w?w(e):w:null!=R?"function"==typeof R?R(e):R:e,null!=P?"function"==typeof P?P(t):P:null!=x?"function"==typeof x?x(t):x:t]},[v,w,R,P,x]),L=v&&I?{modifiers:[{name:"offset",options:{offset:[0+(S||A||0),(n=v,o=I,(o[1]<n[1]?-(Math.abs(o[1]-n[1])/2+o[1]):-(Math.abs(o[1]-n[1])/2+n[1]))-(k||j||0))]}}]}:null,q=f({anchorEl:r,show:l,popperOptions:L,ref:t,animated:d}),M=q.selfRef,O=h({show:l,curPos:a,pos:c,destroy:q.destroy}),Y=O.handleAnimStart,z=O.handleAnimRest,B=O.animLifecycle;s.useEffect(function(){if(r){var e=r.getBoundingClientRect();b([e.width,e.height])}},[r]);var F=i.useSpring({opacity:l&&a===c?1:0,onStart:Y,onRest:z,config:g&&g.spring});return I&&(l||d&&"idle"!==B)?u.createElement("div",{ref:M,style:{visibility:"standby"===B?"hidden":"visible"}},u.createElement(m,{style:d?F:void 0,dimensions:I})):null}),g={modifiers:[{name:"offset",options:{offset:[0,24]}}]},y=s.forwardRef(function(e,t){var n=e.show,o=e.children,r=e.curPos,s=e.pos,l=e.animated,a=f({anchorEl:e.anchorEl,show:n,popperOptions:g,ref:t,animated:l}),c=a.selfRef,d=h({show:n,curPos:r,pos:s,destroy:a.destroy}),m=d.animLifecycle,p=i.useSpring({to:{opacity:n&&r===s?1:0,transform:n&&r===s?"scaleY(1)":"scaleY(0)"},onStart:d.handleAnimStart,onRest:d.handleAnimRest});return n||l&&"idle"!==m?u.createElement("div",{ref:c,style:{visibility:"standby"===m?"hidden":"visible"}},o?u.createElement(i.animated.div,{style:l?p:void 0},o):null):null}),v=i.animated(r.div(function(e){return Object.assign({},{position:"absolute",zIndex:2600,visibility:e.isIdle&&!e.show?"hidden":"visible"},function(e,t,n){var o={};return"center"===t?o.top="50vh":"top"===t?o.top="2vw":"bottom"===t&&(o.bottom="7vh"),"left"===e?o.left="2vw":"right"===e?o.right="2vw":"center"===e&&(o.left=n?"calc(50vw - "+n/2+"px)":"50vw"),o}(e.justify,e.align,e.measuredWidth))})),b=i.animated(r.div({width:24,height:24,border:"1.5px solid white",borderRadius:666})),E=function(e){var t=i.useSpring({backgroundColor:e.focused?"rgba(255, 255, 255, 1)":"rgba(255, 255, 255, 0)"});return u.createElement(b,Object.assign({},e,{style:t}))},w=r.div({display:"flex","& div:not(:first-child)":{marginLeft:24}}),P=function(e){var t=e.curPos;return u.createElement(w,null,Array(e.steps).fill(null).map(function(e,n){return u.createElement(E,{key:"dot-"+n,focused:t===n})}))},S=r.div({zIndex:2400,position:"absolute"});exports.useGuide=a,exports.Tourguide=function(e){var o=e.tooltip,r=e.animated;void 0===r&&(r=!0);var l=e.precondition;void 0===l&&(l=!0);var d=e.content,f=e.node,h=e.leftControl,m=e.rightControl,g=e.closeControl,b=e.positionStyles,E=e.styles,w=s.useState(0),k=w[0],C=w[1],R=s.useState(!0),x=R[0],A=R[1],j=a(),I=j.anchorEls,L=j.curPos,q=j.show,M=j.close,O=j.setStatus,Y=j.prev,z=j.next,B=s.useCallback(function(e){null!==e&&C(e.getBoundingClientRect().width)},[]),F=I[L],N=s.useCallback(n(function(e){switch(e.key){case"Escape":M();break;case"ArrowLeft":Y();break;case"ArrowRight":z()}},400),[M,z,Y]);s.useEffect(function(){return q&&document.addEventListener("keydown",N),function(){document.removeEventListener("keydown",N)}},[N,q]),s.useEffect(function(){l&&I.length&&O("ready")},[I.length,l,O]);var T=i.useSpring({opacity:q?1:0,onStart:function(){q&&A(!1)},onRest:function(){q||A(!0)}});return t.createPortal(r?u.createElement(u.Fragment,null,h&&u.createElement(v,{align:"center",justify:"left",style:T,isIdle:x,show:q},h),m&&u.createElement(v,{align:"center",justify:"right",style:T,isIdle:x,show:q},m),g&&u.createElement(v,{align:"top",justify:"right",style:T,isIdle:x,show:q},g),u.createElement(v,{align:"bottom",justify:"center",ref:B,measuredWidth:k,style:T,isIdle:x,show:q},u.createElement(P,{steps:I.length,curPos:L})),"}",u.createElement(c,{style:T,isIdle:x,show:q},I.map(function(e){return u.createElement(p,{key:"spotlight-"+e.dataset.tourguidePosition,anchorEl:e,pos:Number(e.dataset.tourguidePosition),animated:!0,show:q,curPos:L,positionStyles:b&&b.spotlight,styles:E&&E.spotlight})})),u.createElement(S,null,I.map(function(e,t){return u.createElement(s.Fragment,{key:"tourguideEl-"+t},o&&u.createElement(y,{show:q,anchorEl:e,pos:Number(e.dataset.tourguidePosition),curPos:L,animated:!0,index:t},Array.isArray(o)?o[t]:s.isValidElement(o)?o:u.createElement(o,null,d&&d[t])))}))):u.createElement(u.Fragment,null,u.createElement(p,{anchorEl:F,show:q,pos:L,curPos:L,positionStyles:b&&b.spotlight,styles:E&&E.spotlight}),o&&u.createElement(y,{anchorEl:F,show:q,pos:L,curPos:L},o)),f)},exports.TourguideProvider=function(e){var t=e.children,n=function(){var e=s.useState([]),t=e[0],n=e[1],o=s.useState(!1),r=o[0],i=o[1],u=s.useState(0),l=u[0],a=u[1],c=s.useState("idle"),d=c[0],f=c[1],h=s.useCallback(function(e){null!==e&&e.dataset.tourguidePosition&&(n(function(t){var n=[].concat(t);return n[Number(e.dataset.tourguidePosition)]=e,n}),"idle"===d&&f("initializing"))},[d]),m=s.useCallback(function(e){return{ref:h,"data-tourguide-position":e}},[h]),p=s.useCallback(function(){i(function(e){return!e})},[]),g=s.useCallback(function(){i(!1),a(0)},[]),y=s.useCallback(function(){a(function(e){return e>=t.length-1?e:e+1})},[t.length]),v=s.useCallback(function(){a(function(e){return 0===e?e:e-1})},[]),b=s.useCallback(function(){i(!1),n([]),a(0),f("idle")},[]);return s.useMemo(function(){return{show:r,next:y,prev:v,anchorEls:t,curPos:l,getAnchorElProps:m,setShow:i,setCurPos:a,toggle:p,handleRef:h,reset:b,close:g,setStatus:f,status:d}},[t,l,m,h,y,v,b,r,p,g,d])}();return u.createElement(l.Provider,{value:n},t)};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import t from"react-dom";import e from"lodash.throttle";import{createPopper as n}from"@popperjs/core";import o from"styled-components";import{animated as r,useSpring as i}from"react-spring";import s,{createContext as l,useContext as u,useMemo as a,useRef as c,useCallback as d,useEffect as f,useState as h,forwardRef as m,isValidElement as p,Fragment as y}from"react";var v=l(null);function g(){var t=u(v);if(!t)throw new Error("useGuide must be used within TourguideProvider");return t}var E=r(o.div(function(t){var e=t.isIdle;return{position:"fixed",bottom:0,left:0,right:0,top:0,overflow:"hidden",visibility:e?"hidden":"visible",zIndex:e?-1:2300,backgroundColor:"rgba(26, 29, 52, 0.5)",mixBlendMode:"hard-light"}}));function w(t,e){"function"==typeof t?t(e):t&&(t.current=e)}function b(t){var e,o,r=t.anchorEl,i=t.popperOptions,s=t.ref,l=t.show,u=t.animated,h=c(null),m=a(function(){return null==e&&null==o?null:function(t){w(e,t),w(o,t)}},[e=h,o=s]),p=c(null),y=d(function(){r&&i&&h.current&&l&&(p.current=n(r,h.current,i))},[r,i,l]),v=d(function(){null!=p.current&&(p.current.destroy(),p.current=null)},[]);return f(function(){return y(),function(){u||v()}},[y,v,u]),f(function(){return function(){v()}},[v]),{selfRef:m,tooltipRef:h,destroy:v}}function P(t){var e=t.show,n=t.curPos,o=t.pos,r=t.destroy,i=h("idle"),s=i[1];return{handleAnimStart:function(){e&&n===o&&s("active")},handleAnimRest:function(){e?n!==o&&s("standby"):(r(),s("idle"))},animLifecycle:i[0]}}var R=r(function(t){var e=t.dimensions,n=t.style;return void 0===n&&(n={}),s.createElement("div",{style:Object.assign({},n,{borderRadius:4,backgroundColor:"gray",width:e[0],height:e[1]})})}),S=m(function(t,e){var n,o,r=t.anchorEl,l=t.show,u=t.curPos,c=t.pos,d=t.animated,m=t.positionStyles,p=t.styles,y=h(null),v=y[0],g=y[1],E=m&&m[c]?m[c]:{},w=E.width,S=E.height,x=E.offsetX,A=E.offsetY,k=p||{},j=k.width,C=k.height,L=k.offsetX,O=k.offsetY,I=a(function(){if(!v)return v;var t=v[0],e=v[1];return[null!=w?"function"==typeof w?w(t):w:null!=j?"function"==typeof j?j(t):j:t,null!=S?"function"==typeof S?S(e):S:null!=C?"function"==typeof C?C(e):C:e]},[v,w,j,S,C]),z=v&&I?{modifiers:[{name:"offset",options:{offset:[0+(x||L||0),(n=v,o=I,(o[1]<n[1]?-(Math.abs(o[1]-n[1])/2+o[1]):-(Math.abs(o[1]-n[1])/2+n[1]))-(A||O||0))]}}]}:null,Y=b({anchorEl:r,show:l,popperOptions:z,ref:e,animated:d}),B=Y.selfRef,M=P({show:l,curPos:u,pos:c,destroy:Y.destroy}),N=M.handleAnimStart,F=M.handleAnimRest,W=M.animLifecycle;f(function(){if(r){var t=r.getBoundingClientRect();g([t.width,t.height])}},[r]);var X=i({opacity:l&&u===c?1:0,onStart:N,onRest:F,config:p&&p.spring});return I&&(l||d&&"idle"!==W)?s.createElement("div",{ref:B,style:{visibility:"standby"===W?"hidden":"visible"}},s.createElement(R,{style:d?X:void 0,dimensions:I})):null}),x={modifiers:[{name:"offset",options:{offset:[0,24]}}]},A=m(function(t,e){var n=t.show,o=t.children,l=t.curPos,u=t.pos,a=t.animated,c=b({anchorEl:t.anchorEl,show:n,popperOptions:x,ref:e,animated:a}),d=c.selfRef,f=P({show:n,curPos:l,pos:u,destroy:c.destroy}),h=f.animLifecycle,m=i({to:{opacity:n&&l===u?1:0,transform:n&&l===u?"scaleY(1)":"scaleY(0)"},onStart:f.handleAnimStart,onRest:f.handleAnimRest});return n||a&&"idle"!==h?s.createElement("div",{ref:d,style:{visibility:"standby"===h?"hidden":"visible"}},o?s.createElement(r.div,{style:a?m:void 0},o):null):null}),k=r(o.div(function(t){return Object.assign({},{position:"absolute",zIndex:2600},function(t,e,n){var o={};return"center"===e?o.top="50vh":"top"===e?o.top="2vw":"bottom"===e&&(o.bottom="7vh"),"left"===t?o.left="2vw":"right"===t?o.right="2vw":"center"===t&&(o.left=n?"calc(50vw - "+n/2+"px)":"50vw"),o}(t.justify,t.align,t.measuredWidth))})),j=r(o.div({width:24,height:24,border:"1.5px solid white",borderRadius:666})),C=function(t){var e=i({backgroundColor:t.focused?"rgba(255, 255, 255, 1)":"rgba(255, 255, 255, 0)"});return s.createElement(j,Object.assign({},t,{style:e}))},L=o.div({display:"flex","& div:not(:first-child)":{marginLeft:24}}),O=function(t){var e=t.curPos;return s.createElement(L,null,Array(t.steps).fill(null).map(function(t,n){return s.createElement(C,{key:"dot-"+n,focused:e===n})}))},I=o.div({zIndex:2400,position:"absolute"}),z=function(n){var o=n.tooltip,r=n.animated;void 0===r&&(r=!0);var l=n.precondition;void 0===l&&(l=!0);var u=n.content,a=n.node,c=n.leftControl,m=n.rightControl,v=n.closeControl,w=n.positionStyles,b=n.styles,P=h(0),R=P[0],x=P[1],j=h(!0),C=j[0],L=j[1],z=g(),Y=z.anchorEls,B=z.curPos,M=z.show,N=z.close,F=z.setStatus,W=z.prev,X=z.next,G=d(function(t){null!==t&&x(t.getBoundingClientRect().width)},[]),T=Y[B],q=d(e(function(t){switch(t.key){case"Escape":N();break;case"ArrowLeft":W();break;case"ArrowRight":X()}},400),[N,X,W]);f(function(){return M&&document.addEventListener("keydown",q),function(){document.removeEventListener("keydown",q)}},[q,M]),f(function(){l&&Y.length&&F("ready")},[Y.length,l,F]);var D=i({opacity:M?1:0,onStart:function(){M&&L(!1)},onRest:function(){M||L(!0)}});return t.createPortal(r?s.createElement(s.Fragment,null,c&&s.createElement(k,{align:"center",justify:"left",style:D},c),m&&s.createElement(k,{align:"center",justify:"right",style:D},m),v&&s.createElement(k,{align:"top",justify:"right",style:D},v),s.createElement(k,{align:"bottom",justify:"center",ref:G,measuredWidth:R,style:D},s.createElement(O,{steps:Y.length,curPos:B})),s.createElement(E,{style:D,isIdle:C},Y.map(function(t){return s.createElement(S,{key:"spotlight-"+t.dataset.tourguidePosition,anchorEl:t,pos:Number(t.dataset.tourguidePosition),animated:!0,show:M,curPos:B,positionStyles:w&&w.spotlight,styles:b&&b.spotlight})})),s.createElement(I,null,Y.map(function(t,e){return s.createElement(y,{key:"tourguideEl-"+e},o&&s.createElement(A,{show:M,anchorEl:t,pos:Number(t.dataset.tourguidePosition),curPos:B,animated:!0,index:e},Array.isArray(o)?o[e]:p(o)?o:s.createElement(o,null,u&&u[e])))}))):s.createElement(s.Fragment,null,s.createElement(S,{anchorEl:T,show:M,pos:B,curPos:B,positionStyles:w&&w.spotlight,styles:b&&b.spotlight}),o&&s.createElement(A,{anchorEl:T,show:M,pos:B,curPos:B},o)),a)},Y=function(t){var e=t.children,n=function(){var t=h([]),e=t[0],n=t[1],o=h(!1),r=o[0],i=o[1],s=h(0),l=s[0],u=s[1],c=h("idle"),f=c[0],m=c[1],p=d(function(t){null!==t&&t.dataset.tourguidePosition&&(n(function(e){var n=[].concat(e);return n[Number(t.dataset.tourguidePosition)]=t,n}),"idle"===f&&m("initializing"))},[f]),y=d(function(t){return{ref:p,"data-tourguide-position":t}},[p]),v=d(function(){i(function(t){return!t})},[]),g=d(function(){i(!1),u(0)},[]),E=d(function(){u(function(t){return t>=e.length-1?t:t+1})},[e.length]),w=d(function(){u(function(t){return 0===t?t:t-1})},[]),b=d(function(){i(!1),n([]),u(0),m("idle")},[]);return a(function(){return{show:r,next:E,prev:w,anchorEls:e,curPos:l,getAnchorElProps:y,setShow:i,setCurPos:u,toggle:v,handleRef:p,reset:b,close:g,setStatus:m,status:f}},[e,l,y,p,E,w,b,r,v,g,f])}();return s.createElement(v.Provider,{value:n},e)};export{g as useGuide,z as Tourguide,Y as TourguideProvider};
import t from"react-dom";import e from"lodash.throttle";import{createPopper as n}from"@popperjs/core";import o from"styled-components";import{animated as r,useSpring as i}from"react-spring";import s,{createContext as l,useContext as u,useMemo as a,useRef as c,useCallback as d,useEffect as f,useState as h,forwardRef as m,isValidElement as p,Fragment as y}from"react";var v=l(null);function g(){var t=u(v);if(!t)throw new Error("useGuide must be used within TourguideProvider");return t}var w=r(o.div(function(t){return{position:"fixed",bottom:0,left:0,right:0,top:0,overflow:"hidden",visibility:t.isIdle&&!t.show?"hidden":"visible",backgroundColor:"rgba(26, 29, 52, 0.5)",mixBlendMode:"hard-light"}}));function E(t,e){"function"==typeof t?t(e):t&&(t.current=e)}function b(t){var e,o,r=t.anchorEl,i=t.popperOptions,s=t.ref,l=t.show,u=t.animated,h=c(null),m=a(function(){return null==e&&null==o?null:function(t){E(e,t),E(o,t)}},[e=h,o=s]),p=c(null),y=d(function(){r&&i&&h.current&&l&&(p.current=n(r,h.current,i))},[r,i,l]),v=d(function(){null!=p.current&&(p.current.destroy(),p.current=null)},[]);return f(function(){return y(),function(){u||v()}},[y,v,u]),f(function(){return function(){v()}},[v]),{selfRef:m,tooltipRef:h,destroy:v}}function P(t){var e=t.show,n=t.curPos,o=t.pos,r=t.destroy,i=h("idle"),s=i[1];return{handleAnimStart:function(){e&&n===o&&s("active")},handleAnimRest:function(){e?n!==o&&s("standby"):(r(),s("idle"))},animLifecycle:i[0]}}var R=r(function(t){var e=t.dimensions,n=t.style;return void 0===n&&(n={}),s.createElement("div",{style:Object.assign({},n,{borderRadius:4,backgroundColor:"gray",width:e[0],height:e[1]})})}),S=m(function(t,e){var n,o,r=t.anchorEl,l=t.show,u=t.curPos,c=t.pos,d=t.animated,m=t.positionStyles,p=t.styles,y=h(null),v=y[0],g=y[1],w=m&&m[c]?m[c]:{},E=w.width,S=w.height,A=w.offsetX,k=w.offsetY,x=p||{},j=x.width,C=x.height,I=x.offsetX,L=x.offsetY,O=a(function(){if(!v)return v;var t=v[0],e=v[1];return[null!=E?"function"==typeof E?E(t):E:null!=j?"function"==typeof j?j(t):j:t,null!=S?"function"==typeof S?S(e):S:null!=C?"function"==typeof C?C(e):C:e]},[v,E,j,S,C]),Y=v&&O?{modifiers:[{name:"offset",options:{offset:[0+(A||I||0),(n=v,o=O,(o[1]<n[1]?-(Math.abs(o[1]-n[1])/2+o[1]):-(Math.abs(o[1]-n[1])/2+n[1]))-(k||L||0))]}}]}:null,z=b({anchorEl:r,show:l,popperOptions:Y,ref:e,animated:d}),B=z.selfRef,M=P({show:l,curPos:u,pos:c,destroy:z.destroy}),N=M.handleAnimStart,F=M.handleAnimRest,W=M.animLifecycle;f(function(){if(r){var t=r.getBoundingClientRect();g([t.width,t.height])}},[r]);var X=i({opacity:l&&u===c?1:0,onStart:N,onRest:F,config:p&&p.spring});return O&&(l||d&&"idle"!==W)?s.createElement("div",{ref:B,style:{visibility:"standby"===W?"hidden":"visible"}},s.createElement(R,{style:d?X:void 0,dimensions:O})):null}),A={modifiers:[{name:"offset",options:{offset:[0,24]}}]},k=m(function(t,e){var n=t.show,o=t.children,l=t.curPos,u=t.pos,a=t.animated,c=b({anchorEl:t.anchorEl,show:n,popperOptions:A,ref:e,animated:a}),d=c.selfRef,f=P({show:n,curPos:l,pos:u,destroy:c.destroy}),h=f.animLifecycle,m=i({to:{opacity:n&&l===u?1:0,transform:n&&l===u?"scaleY(1)":"scaleY(0)"},onStart:f.handleAnimStart,onRest:f.handleAnimRest});return n||a&&"idle"!==h?s.createElement("div",{ref:d,style:{visibility:"standby"===h?"hidden":"visible"}},o?s.createElement(r.div,{style:a?m:void 0},o):null):null}),x=r(o.div(function(t){return Object.assign({},{position:"absolute",zIndex:2600,visibility:t.isIdle&&!t.show?"hidden":"visible"},function(t,e,n){var o={};return"center"===e?o.top="50vh":"top"===e?o.top="2vw":"bottom"===e&&(o.bottom="7vh"),"left"===t?o.left="2vw":"right"===t?o.right="2vw":"center"===t&&(o.left=n?"calc(50vw - "+n/2+"px)":"50vw"),o}(t.justify,t.align,t.measuredWidth))})),j=r(o.div({width:24,height:24,border:"1.5px solid white",borderRadius:666})),C=function(t){var e=i({backgroundColor:t.focused?"rgba(255, 255, 255, 1)":"rgba(255, 255, 255, 0)"});return s.createElement(j,Object.assign({},t,{style:e}))},I=o.div({display:"flex","& div:not(:first-child)":{marginLeft:24}}),L=function(t){var e=t.curPos;return s.createElement(I,null,Array(t.steps).fill(null).map(function(t,n){return s.createElement(C,{key:"dot-"+n,focused:e===n})}))},O=o.div({zIndex:2400,position:"absolute"}),Y=function(n){var o=n.tooltip,r=n.animated;void 0===r&&(r=!0);var l=n.precondition;void 0===l&&(l=!0);var u=n.content,a=n.node,c=n.leftControl,m=n.rightControl,v=n.closeControl,E=n.positionStyles,b=n.styles,P=h(0),R=P[0],A=P[1],j=h(!0),C=j[0],I=j[1],Y=g(),z=Y.anchorEls,B=Y.curPos,M=Y.show,N=Y.close,F=Y.setStatus,W=Y.prev,X=Y.next,G=d(function(t){null!==t&&A(t.getBoundingClientRect().width)},[]),T=z[B],q=d(e(function(t){switch(t.key){case"Escape":N();break;case"ArrowLeft":W();break;case"ArrowRight":X()}},400),[N,X,W]);f(function(){return M&&document.addEventListener("keydown",q),function(){document.removeEventListener("keydown",q)}},[q,M]),f(function(){l&&z.length&&F("ready")},[z.length,l,F]);var D=i({opacity:M?1:0,onStart:function(){M&&I(!1)},onRest:function(){M||I(!0)}});return t.createPortal(r?s.createElement(s.Fragment,null,c&&s.createElement(x,{align:"center",justify:"left",style:D,isIdle:C,show:M},c),m&&s.createElement(x,{align:"center",justify:"right",style:D,isIdle:C,show:M},m),v&&s.createElement(x,{align:"top",justify:"right",style:D,isIdle:C,show:M},v),s.createElement(x,{align:"bottom",justify:"center",ref:G,measuredWidth:R,style:D,isIdle:C,show:M},s.createElement(L,{steps:z.length,curPos:B})),"}",s.createElement(w,{style:D,isIdle:C,show:M},z.map(function(t){return s.createElement(S,{key:"spotlight-"+t.dataset.tourguidePosition,anchorEl:t,pos:Number(t.dataset.tourguidePosition),animated:!0,show:M,curPos:B,positionStyles:E&&E.spotlight,styles:b&&b.spotlight})})),s.createElement(O,null,z.map(function(t,e){return s.createElement(y,{key:"tourguideEl-"+e},o&&s.createElement(k,{show:M,anchorEl:t,pos:Number(t.dataset.tourguidePosition),curPos:B,animated:!0,index:e},Array.isArray(o)?o[e]:p(o)?o:s.createElement(o,null,u&&u[e])))}))):s.createElement(s.Fragment,null,s.createElement(S,{anchorEl:T,show:M,pos:B,curPos:B,positionStyles:E&&E.spotlight,styles:b&&b.spotlight}),o&&s.createElement(k,{anchorEl:T,show:M,pos:B,curPos:B},o)),a)},z=function(t){var e=t.children,n=function(){var t=h([]),e=t[0],n=t[1],o=h(!1),r=o[0],i=o[1],s=h(0),l=s[0],u=s[1],c=h("idle"),f=c[0],m=c[1],p=d(function(t){null!==t&&t.dataset.tourguidePosition&&(n(function(e){var n=[].concat(e);return n[Number(t.dataset.tourguidePosition)]=t,n}),"idle"===f&&m("initializing"))},[f]),y=d(function(t){return{ref:p,"data-tourguide-position":t}},[p]),v=d(function(){i(function(t){return!t})},[]),g=d(function(){i(!1),u(0)},[]),w=d(function(){u(function(t){return t>=e.length-1?t:t+1})},[e.length]),E=d(function(){u(function(t){return 0===t?t:t-1})},[]),b=d(function(){i(!1),n([]),u(0),m("idle")},[]);return a(function(){return{show:r,next:w,prev:E,anchorEls:e,curPos:l,getAnchorElProps:y,setShow:i,setCurPos:u,toggle:v,handleRef:p,reset:b,close:g,setStatus:m,status:f}},[e,l,y,p,w,E,b,r,v,g,f])}();return s.createElement(v.Provider,{value:n},e)};export{g as useGuide,Y as Tourguide,z as TourguideProvider};
//# sourceMappingURL=index.module.js.map
{
"name": "react-interactive-guide",
"version": "2.2.2",
"version": "2.2.3",
"description": "Interactive tour guide for your react app",

@@ -5,0 +5,0 @@ "source": "src/index.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc