react-losen
Advanced tools
Comparing version 2.0.0-4 to 2.0.0-5
@@ -30,3 +30,3 @@ import { useEffect, createContext, useContext } from 'react'; | ||
} | ||
}, [autoSkip, validator]); | ||
}, [autoSkip]); | ||
@@ -33,0 +33,0 @@ if (activeStep.name !== name) { |
@@ -9,3 +9,4 @@ import React, { useState, useEffect } from 'react'; | ||
children, | ||
onComplete | ||
onComplete, | ||
debug | ||
}) => { | ||
@@ -62,3 +63,5 @@ const [index, setIndex] = useState(0); | ||
// for debugging purposes only | ||
console.debug('steps updated', steps); // eslint-disable-line | ||
if (debug) { | ||
console.debug('steps updated', steps); // eslint-disable-line | ||
} | ||
}, [steps]); | ||
@@ -83,2 +86,5 @@ return React.createElement(ControlsContext.Provider, { | ||
Wizard.defaultProps = { | ||
debug: false | ||
}; | ||
export default Wizard; |
@@ -117,3 +117,3 @@ import React, { createContext, useContext, useEffect, useState } from 'react'; | ||
} | ||
}, [autoSkip, validator]); | ||
}, [autoSkip]); | ||
@@ -136,3 +136,4 @@ if (activeStep.name !== name) { | ||
let children = _ref.children, | ||
onComplete = _ref.onComplete; | ||
onComplete = _ref.onComplete, | ||
debug = _ref.debug; | ||
@@ -205,3 +206,5 @@ const _useState = useState(0), | ||
// for debugging purposes only | ||
console.debug('steps updated', steps); // eslint-disable-line | ||
if (debug) { | ||
console.debug('steps updated', steps); // eslint-disable-line | ||
} | ||
}, [steps]); | ||
@@ -226,2 +229,6 @@ return React.createElement(ControlsContext.Provider, { | ||
Wizard.defaultProps = { | ||
debug: false | ||
}; | ||
export { ControlsContext, Step, StepContext, ValidationError, Wizard }; |
@@ -1,2 +0,2 @@ | ||
import React,{createContext,useContext,useEffect,useState}from"react";function asyncGeneratorStep(e,t,n,r,i,o,a){try{var l=e[o](a),s=l.value}catch(e){return void n(e)}l.done?t(s):Promise.resolve(s).then(r,i)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var o=e.apply(t,n);function a(e){asyncGeneratorStep(o,r,i,a,l,"next",e)}function l(e){asyncGeneratorStep(o,r,i,a,l,"throw",e)}a(void 0)})}}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArrayLimit(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,l=e[Symbol.iterator]();!(r=(a=l.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==l.return||l.return()}finally{if(i)throw o}}return n}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function findNextValid(e,t){const n=t+e.slice(t+1).findIndex(e=>!e.autoSkip);return e.length>n?n+1:n}function findPreviousValid(e,t){return t-1-[...e].reverse().slice(e.length-t).findIndex(e=>!e.autoSkip)}const ControlsContext=createContext(null),StepContext=createContext(null),Step=e=>{let t=e.children,n=e.name,r=e.validator,i=e.autoSkip;const o=useContext(StepContext),a=o.registerStep,l=o.activeStep,s=o.updateStep,c=o.initialized,u={name:n,validator:r,autoSkip:i};return useEffect(()=>{c||a(u)},[n]),useEffect(()=>{c&&s(u)},[i,r]),l.name!==n?null:t};Step.defaultProps={validator:null,autoSkip:!1};class ValidationError extends Error{}const Wizard=e=>{let t=e.children,n=e.onComplete;const r=_slicedToArray(useState(0),2),i=r[0],o=r[1],a=_slicedToArray(useState([]),2),l=a[0],s=a[1],c=_slicedToArray(useState(!1),2),u=c[0],d=c[1];function f(){return(f=_asyncToGenerator(function*(){const e=l[i].validator,t=findNextValid(l,i),r=findNextValid(l,i)===i?()=>n(l[i].name):()=>o(t);if(e)try{d(!0),yield new Promise(e),r()}catch(e){if(!(e instanceof ValidationError))throw e;console.error("ReactLosen",e)}finally{d(!1)}else r()})).apply(this,arguments)}return useEffect(()=>{console.debug("steps updated",l)},[l]),React.createElement(ControlsContext.Provider,{value:{onNext:function(){return f.apply(this,arguments)},onPrevious:function(){const e=findPreviousValid(l,i);o(e)},isLoading:u,isFirst:findPreviousValid(l,i)===i,isLast:findNextValid(l,i)===i}},React.createElement(StepContext.Provider,{value:{registerStep:function(e){l.map(e=>e.name).includes(e.name)||s(t=>[...t,e])},activeStep:l[i]||{},initialized:!!l[i],updateStep:function(e){const t=l.findIndex(t=>t.name===e.name);s(n=>[...n.slice(0,t),e,...n.slice(t+1)])}}},t))};export{ControlsContext,Step,StepContext,ValidationError,Wizard}; | ||
import React,{createContext,useContext,useEffect,useState}from"react";function asyncGeneratorStep(e,t,n,r,i,o,a){try{var l=e[o](a),s=l.value}catch(e){return void n(e)}l.done?t(s):Promise.resolve(s).then(r,i)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var o=e.apply(t,n);function a(e){asyncGeneratorStep(o,r,i,a,l,"next",e)}function l(e){asyncGeneratorStep(o,r,i,a,l,"throw",e)}a(void 0)})}}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArrayLimit(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,l=e[Symbol.iterator]();!(r=(a=l.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==l.return||l.return()}finally{if(i)throw o}}return n}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function findNextValid(e,t){const n=t+e.slice(t+1).findIndex(e=>!e.autoSkip);return e.length>n?n+1:n}function findPreviousValid(e,t){return t-1-[...e].reverse().slice(e.length-t).findIndex(e=>!e.autoSkip)}const ControlsContext=createContext(null),StepContext=createContext(null),Step=e=>{let t=e.children,n=e.name,r=e.validator,i=e.autoSkip;const o=useContext(StepContext),a=o.registerStep,l=o.activeStep,s=o.updateStep,u=o.initialized,c={name:n,validator:r,autoSkip:i};return useEffect(()=>{u||a(c)},[n]),useEffect(()=>{u&&s(c)},[i]),l.name!==n?null:t};Step.defaultProps={validator:null,autoSkip:!1};class ValidationError extends Error{}const Wizard=e=>{let t=e.children,n=e.onComplete,r=e.debug;const i=_slicedToArray(useState(0),2),o=i[0],a=i[1],l=_slicedToArray(useState([]),2),s=l[0],u=l[1],c=_slicedToArray(useState(!1),2),d=c[0],f=c[1];function p(){return(p=_asyncToGenerator(function*(){const e=s[o].validator,t=findNextValid(s,o),r=findNextValid(s,o)===o?()=>n(s[o].name):()=>a(t);if(e)try{f(!0),yield new Promise(e),r()}catch(e){if(!(e instanceof ValidationError))throw e;console.error("ReactLosen",e)}finally{f(!1)}else r()})).apply(this,arguments)}return useEffect(()=>{r&&console.debug("steps updated",s)},[s]),React.createElement(ControlsContext.Provider,{value:{onNext:function(){return p.apply(this,arguments)},onPrevious:function(){const e=findPreviousValid(s,o);a(e)},isLoading:d,isFirst:findPreviousValid(s,o)===o,isLast:findNextValid(s,o)===o}},React.createElement(StepContext.Provider,{value:{registerStep:function(e){s.map(e=>e.name).includes(e.name)||u(t=>[...t,e])},activeStep:s[o]||{},initialized:!!s[o],updateStep:function(e){const t=s.findIndex(t=>t.name===e.name);u(n=>[...n.slice(0,t),e,...n.slice(t+1)])}}},t))};Wizard.defaultProps={debug:!1};export{ControlsContext,Step,StepContext,ValidationError,Wizard}; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "react-losen", | ||
"description": "A super customisable Wizard for React and React Native", | ||
"version": "2.0.0-4", | ||
"version": "2.0.0-5", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "esnext": "dist-src/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
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
23130
332