Comparing version 0.2.0 to 0.2.1
@@ -1,2 +0,29 @@ | ||
var j=Object.create;var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var R=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},P=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of B(e))!V.call(o,s)&&s!==t&&c(o,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return o};var y=(o,e,t)=>(t=o!=null?j(M(o)):{},P(e||!o||!o.__esModule?c(t,"default",{value:o,enumerable:!0}):t,o)),q=o=>P(c({},"__esModule",{value:!0}),o);var H={};R(H,{Tour:()=>S,TourProvider:()=>m,useTourControls:()=>i,useTourState:()=>C});module.exports=q(H);var u=y(require("react")),l=(0,u.createContext)(null),z=({children:o})=>{var v;let[e,t]=(0,u.useState)(!1),[r,s]=(0,u.useState)(null),[p,a]=(0,u.useState)(0),d=(0,u.useRef)([]).current,f=(v=r==null?void 0:r.steps.length)!=null?v:0,w=(0,u.useCallback)(n=>{d.push(n)},[]),k=(0,u.useCallback)(n=>{let h=d.find(N=>N.id===n);h&&(s(h),t(!0),a(1))},[d]),E=(0,u.useCallback)(()=>{t(!1),s(null),a(0)},[]),I=(0,u.useCallback)(()=>{a(n=>Math.min(f,n+1))},[f]),O=(0,u.useCallback)(()=>{a(n=>Math.max(1,n-1))},[]),_=(0,u.useCallback)(n=>{a(n)},[]);return u.default.createElement(l.Provider,{value:{isTourOpen:e,activeTour:r,activeStep:p,totalSteps:f,tours:d,addTour:w,startTour:k,endTour:E,goToStep:_,nextStep:I,prevStep:O}},o)},m=z;function x(o,{insertAt:e}={}){if(!o||typeof document=="undefined")return;let t=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",e==="top"&&t.firstChild?t.insertBefore(r,t.firstChild):t.appendChild(r),r.styleSheet?r.styleSheet.cssText=o:r.appendChild(document.createTextNode(o))}x(`.tour__container{border:1px solid #ccc;border-radius:5px;margin:10px;background-color:#000} | ||
`);var T=y(require("react"));var b=require("react");var D=()=>{let o=(0,b.useContext)(l);if(!o)throw new Error("Oops! It looks like useTourControls was called outside of a TourProvider context. Please ensure that your component is wrapped in a <TourProvider> to use the tour controls.");let{startTour:e,endTour:t,goToStep:r,nextStep:s,prevStep:p,addTour:a}=o;return{startTour:e,endTour:t,goToStep:r,nextStep:s,prevStep:p,addTour:a}},i=D;var g=require("react");var F=()=>{let o=(0,g.useContext)(l);if(!o)throw new Error("Oops! It looks like useTour was called outside of a TourProvider context. Please ensure that your component is wrapped in a <TourProvider>");let{tours:e,activeStep:t,activeTour:r,isTourOpen:s,totalSteps:p}=o;return{tours:e,activeStep:t,activeTour:r,isTourOpen:s,totalSteps:p}},C=F;var G=({children:o,...e})=>{let{addTour:t}=i();return(0,T.useEffect)(()=>{t(e)},[t,e]),T.default.createElement("div",{className:"tour__container"},o)},S=G;0&&(module.exports={Tour,TourProvider,useTourControls,useTourState}); | ||
'use strict'; | ||
var m = require('react'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
var m__default = /*#__PURE__*/_interopDefault(m); | ||
var p=m.createContext(null),U=({children:e})=>{var y;let[t,o]=m.useState(!1),[r,i]=m.useState(null),[s,n]=m.useState(0),u=m.useRef([]).current,l=(y=r==null?void 0:r.steps.length)!=null?y:0,f=m.useCallback(c=>{u.push(c);},[]),b=m.useCallback(c=>{let L=u.find(K=>K.id===c);L&&(i(L),o(!0),n(1));},[u]),T=m.useCallback(()=>{o(!1),i(null),n(0);},[]),v=m.useCallback(()=>{n(c=>Math.min(l,c+1));},[l]),P=m.useCallback(()=>{n(c=>Math.max(1,c-1));},[]),B=m.useCallback(c=>{n(c);},[]);return m__default.default.createElement(p.Provider,{value:{isTourOpen:t,activeTour:r,activeStep:s,totalSteps:l,tours:u,addTour:f,startTour:b,endTour:T,goToStep:B,nextStep:v,prevStep:P}},e)},O=U;var $=()=>{let e=m.useContext(p);if(!e)throw new Error("Oops! It looks like useTourControls was called outside of a TourProvider context. Please ensure that your component is wrapped in a <TourProvider> to use the tour controls.");let{startTour:t,endTour:o,goToStep:r,nextStep:i,prevStep:s,addTour:n}=e;return {startTour:t,endTour:o,goToStep:r,nextStep:i,prevStep:s,addTour:n}},h=$;var z=()=>{let e=m.useContext(p);if(!e)throw new Error("Oops! It looks like useTour was called outside of a TourProvider context. Please ensure that your component is wrapped in a <TourProvider>");let{tours:t,activeStep:o,activeTour:r,isTourOpen:i,totalSteps:s}=e;return {tours:t,activeStep:o,activeTour:r,isTourOpen:i,totalSteps:s}},R=z;var Q=e=>{let t=m.useRef(null);return m.useEffect(()=>{let o=r=>{t.current&&!t.current.contains(r.target)&&e();};return document.addEventListener("pointerdown",o),()=>{document.removeEventListener("pointerdown",o);}},[e]),t},C=Q;var g=` | ||
a[href]:not([tabindex^="-"]), | ||
area[href]:not([tabindex^="-"]), | ||
input:not([disabled]):not([tabindex^="-"]), | ||
select:not([disabled]):not([tabindex^="-"]), | ||
textarea:not([disabled]):not([tabindex^="-"]), | ||
button:not([disabled]):not([tabindex^="-"]), | ||
iframe:not([tabindex^="-"]), | ||
[tabindex]:not([tabindex^="-"]), | ||
[contenteditable]:not([tabindex^="-"]), | ||
audio[controls]:not([tabindex^="-"]), | ||
video[controls]:not([tabindex^="-"]), | ||
[role="button"]:not([tabindex^="-"]), | ||
[role="link"]:not([tabindex^="-"]), | ||
object[usemap]:not([tabindex^="-"]) | ||
`;var Z=()=>{let e=m.useRef(document.activeElement),t=m.useRef(null),o=m.useCallback(r=>{if(r.key!=="Tab"||!t.current)return;let i=Array.from(t.current.querySelectorAll(g));if(i.length===0)return;let s=i[0],n=i[i.length-1],{activeElement:u}=document;r.shiftKey&&u===s?(n.focus(),r.preventDefault()):!r.shiftKey&&u===n&&(s.focus(),r.preventDefault());},[]);return m.useEffect(()=>{let r=t.current;if(!r)return;let i=Array.from(r.querySelectorAll(g));return i[0]&&(i[0].focus(),console.log("Focusing first focusable element within the container.")),document.addEventListener("keydown",o),()=>{document.removeEventListener("keydown",o),e.current&&(document.activeElement===document.body||r.contains(document.activeElement))&&e.current.focus();}},[o]),t},S=Z;var ee=(...e)=>t=>{e.forEach(o=>{o!=null&&(typeof o=="function"?o(t):o.current=t);});},I=ee;var F=(e,t,o)=>{let s=0,n=0;switch(o){case"top-center":s=e.top-t.height-10,n=e.left+e.width/2-t.width/2;break;case"bottom-center":s=e.top+e.height+10,n=e.left+e.width/2-t.width/2;break;case"left-center":s=e.top+e.height/2-t.height/2,n=e.left-t.width-10;break;case"right-center":s=e.top+e.height/2-t.height/2,n=e.left+e.width+10;break}return s=Math.max(10,Math.min(s,window.innerHeight-t.height-10)),n=Math.max(10,Math.min(n,window.innerWidth-t.width-10)),{top:s,left:n}};var D={left:0,top:0,width:0,height:0},x=m.createContext({isShow:!1,setIsShow:()=>{throw new Error("PopoverContext setIsShow should be used under provider")},preferredPosition:"bottom-center",triggerRect:D,setTriggerRect:()=>{throw new Error("PopoverContext setTriggerRect should be used under provider")}});function a({children:e,preferredPosition:t="bottom-center"}){let[o,r]=m.useState(!1),[i,s]=m.useState(D),n={isShow:o,setIsShow:r,preferredPosition:t,triggerRect:i,setTriggerRect:s};return m__default.default.createElement(x.Provider,{value:n},e)}function se({children:e}){let{setIsShow:t,setTriggerRect:o}=m.useContext(x),r=m.useRef(null);return m.cloneElement(e,{onClick:n=>{let u=r.current;if(u==null)return;let l=u.getBoundingClientRect();o(l),t(f=>!f);},ref:r})}function ie({children:e}){let{isShow:t}=m.useContext(x);return t?m__default.default.createElement(ue,null,e):null}function ue({children:e}){let{triggerRect:t,preferredPosition:o,setIsShow:r}=m.useContext(x),i=m.useRef(null),[s,n]=m.useState({left:0,top:0});m.useLayoutEffect(()=>{let T=i.current;if(T==null)return;let v=T.getBoundingClientRect(),P=F(t,v,o);n(P);},[]);let u=S(),l=m.useCallback(()=>{r(!1);},[]),f=C(l),b=I(i,u,f);return m__default.default.createElement("dialog",{open:!0,ref:b,style:{position:"fixed",left:`${s.left}px`,top:`${s.top}px`,margin:0}},e)}a.Trigger=se;a.Content=ie;var le=({children:e,...t})=>{let{addTour:o}=h();return m.useEffect(()=>{o(t);},[o,t]),m__default.default.createElement(a,{preferredPosition:"top-center"},m__default.default.createElement(a.Trigger,null,m__default.default.createElement("button",null,"hello")),m__default.default.createElement(a.Content,null,"This is the content",m__default.default.createElement("input",{type:"text"})))},N=le; | ||
exports.Tour = N; | ||
exports.TourProvider = O; | ||
exports.useTourControls = h; | ||
exports.useTourState = R; |
{ | ||
"name": "next-tour", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Guided tours and walkthroughs for Next.js", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
15672
125