react-losen
Advanced tools
Comparing version 2.0.0-7 to 2.0.0-8
@@ -112,2 +112,6 @@ 'use strict'; | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
@@ -114,0 +118,0 @@ var _n = true; |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React);const ControlsContext=React.createContext(null),Controls=({render:e})=>{const t=React.useContext(ControlsContext);return e(t.onNext,t.onPrevious,t.isFirst,t.isLast,t.isLoading)},StepContext=React.createContext(null),Step=({children:e,name:t,validator:n,autoSkip:r})=>{const o=React.useContext(StepContext),a=o.registerStep,i=o.activeStep,s=o.updateStep,l=o.initialized,c={name:t,validator:n,autoSkip:r};return React.useEffect(()=>{l||a(c)},[t]),React.useEffect(()=>{l&&s(c)},[r,n]),i.name!==t?null:e};function asyncGeneratorStep(e,t,n,r,o,a,i){try{var s=e[a](i),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,o)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function i(e){asyncGeneratorStep(a,r,o,i,s,"next",e)}function s(e){asyncGeneratorStep(a,r,o,i,s,"throw",e)}i(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,o=!1,a=void 0;try{for(var i,s=e[Symbol.iterator]();!(r=(i=s.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw a}}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)}Step.defaultProps={validator:null,autoSkip:!1};class ValidationError extends Error{}const Wizard=({children:e,onComplete:t,debug:n})=>{const r=_slicedToArray(React.useState(0),2),o=r[0],a=r[1],i=_slicedToArray(React.useState([]),2),s=i[0],l=i[1],c=_slicedToArray(React.useState(!1),2),u=c[0],d=c[1];function f(){return(f=_asyncToGenerator(function*(){const e=s[o].validator,n=findNextValid(s,o),r=n===o?()=>t(s[o].name):()=>a(n);if(e)try{d(!0),yield e(),r()}catch(e){if(!(e instanceof ValidationError))throw e;console.error("ReactLosen",e)}finally{d(!1)}else r()})).apply(this,arguments)}return React.useEffect(()=>{n&&console.debug("steps updated",s)},[s]),React__default.createElement(ControlsContext.Provider,{value:{onNext:function(){return f.apply(this,arguments)},onPrevious:function(){const e=findPreviousValid(s,o);a(e)},isLoading:u,isFirst:findPreviousValid(s,o)===o,isLast:findNextValid(s,o)===o}},React__default.createElement(StepContext.Provider,{value:{registerStep:function(e){s.map(e=>e.name).includes(e.name)||l(t=>[...t,e])},activeStep:s[o]||{},initialized:!!s[o],updateStep:function(e){const t=s.findIndex(t=>t.name===e.name);l(n=>[...n.slice(0,t),e,...n.slice(t+1)])}}},e))};Wizard.defaultProps={debug:!1},exports.Controls=Controls,exports.ControlsContext=ControlsContext,exports.Step=Step,exports.StepContext=StepContext,exports.ValidationError=ValidationError,exports.Wizard=Wizard; | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React);const ControlsContext=React.createContext(null),Controls=({render:t})=>{const e=React.useContext(ControlsContext);return t(e.onNext,e.onPrevious,e.isFirst,e.isLast,e.isLoading)},StepContext=React.createContext(null),Step=({children:t,name:e,validator:n,autoSkip:r})=>{const o=React.useContext(StepContext),a=o.registerStep,i=o.activeStep,s=o.updateStep,l=o.initialized,c={name:e,validator:n,autoSkip:r};return React.useEffect(()=>{l||a(c)},[e]),React.useEffect(()=>{l&&s(c)},[r,n]),i.name!==e?null:t};function asyncGeneratorStep(t,e,n,r,o,a,i){try{var s=t[a](i),l=s.value}catch(t){return void n(t)}s.done?e(l):Promise.resolve(l).then(r,o)}function _asyncToGenerator(t){return function(){var e=this,n=arguments;return new Promise(function(r,o){var a=t.apply(e,n);function i(t){asyncGeneratorStep(a,r,o,i,s,"next",t)}function s(t){asyncGeneratorStep(a,r,o,i,s,"throw",t)}i(void 0)})}}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArrayLimit(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var n=[],r=!0,o=!1,a=void 0;try{for(var i,s=t[Symbol.iterator]();!(r=(i=s.next()).done)&&(n.push(i.value),!e||n.length!==e);r=!0);}catch(t){o=!0,a=t}finally{try{r||null==s.return||s.return()}finally{if(o)throw a}}return n}}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function findNextValid(t,e){const n=e+t.slice(e+1).findIndex(t=>!t.autoSkip);return t.length>n?n+1:n}function findPreviousValid(t,e){return e-1-[...t].reverse().slice(t.length-e).findIndex(t=>!t.autoSkip)}Step.defaultProps={validator:null,autoSkip:!1};class ValidationError extends Error{}const Wizard=({children:t,onComplete:e,debug:n})=>{const r=_slicedToArray(React.useState(0),2),o=r[0],a=r[1],i=_slicedToArray(React.useState([]),2),s=i[0],l=i[1],c=_slicedToArray(React.useState(!1),2),u=c[0],d=c[1];function f(){return(f=_asyncToGenerator(function*(){const t=s[o].validator,n=findNextValid(s,o),r=n===o?()=>e(s[o].name):()=>a(n);if(t)try{d(!0),yield t(),r()}catch(t){if(!(t instanceof ValidationError))throw t;console.error("ReactLosen",t)}finally{d(!1)}else r()})).apply(this,arguments)}return React.useEffect(()=>{n&&console.debug("steps updated",s)},[s]),React__default.createElement(ControlsContext.Provider,{value:{onNext:function(){return f.apply(this,arguments)},onPrevious:function(){const t=findPreviousValid(s,o);a(t)},isLoading:u,isFirst:findPreviousValid(s,o)===o,isLast:findNextValid(s,o)===o}},React__default.createElement(StepContext.Provider,{value:{registerStep:function(t){s.map(t=>t.name).includes(t.name)||l(e=>[...e,t])},activeStep:s[o]||{},initialized:!!s[o],updateStep:function(t){const e=s.findIndex(e=>e.name===t.name);l(n=>[...n.slice(0,e),t,...n.slice(e+1)])}}},t))};Wizard.defaultProps={debug:!1},exports.Controls=Controls,exports.ControlsContext=ControlsContext,exports.Step=Step,exports.StepContext=StepContext,exports.ValidationError=ValidationError,exports.Wizard=Wizard; | ||
//# sourceMappingURL=index.min.js.map |
import React, { createContext, useContext, useEffect, useState } from 'react'; | ||
const ControlsContext = createContext(null); | ||
var ControlsContext = createContext(null); | ||
const Controls = (_ref) => { | ||
let render = _ref.render; | ||
const _useContext = useContext(ControlsContext), | ||
onNext = _useContext.onNext, | ||
onPrevious = _useContext.onPrevious, | ||
isFirst = _useContext.isFirst, | ||
isLast = _useContext.isLast, | ||
isLoading = _useContext.isLoading; | ||
var Controls = (_ref) => { | ||
var { | ||
render | ||
} = _ref; | ||
var { | ||
onNext, | ||
onPrevious, | ||
isFirst, | ||
isLast, | ||
isLoading | ||
} = useContext(ControlsContext); | ||
return render(onNext, onPrevious, isFirst, isLast, isLoading); | ||
}; | ||
const StepContext = createContext(null); | ||
var StepContext = createContext(null); | ||
const Step = (_ref) => { | ||
let children = _ref.children, | ||
name = _ref.name, | ||
validator = _ref.validator, | ||
autoSkip = _ref.autoSkip; | ||
const _useContext = useContext(StepContext), | ||
registerStep = _useContext.registerStep, | ||
activeStep = _useContext.activeStep, | ||
updateStep = _useContext.updateStep, | ||
initialized = _useContext.initialized; | ||
const stepInfo = { | ||
var Step = (_ref) => { | ||
var { | ||
children, | ||
name, | ||
validator, | ||
autoSkip | ||
} = _ref; | ||
var { | ||
registerStep, | ||
activeStep, | ||
updateStep, | ||
initialized | ||
} = useContext(StepContext); | ||
var stepInfo = { | ||
name, | ||
validator, | ||
autoSkip | ||
}; | ||
@@ -96,47 +98,9 @@ useEffect(() => { | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
// flow | ||
function findNextValid(steps, currentIndex) { | ||
const nextValid = currentIndex + steps.slice(currentIndex + 1).findIndex(el => !el.autoSkip); | ||
var nextValid = currentIndex + steps.slice(currentIndex + 1).findIndex(el => !el.autoSkip); | ||
return steps.length > nextValid ? nextValid + 1 : nextValid; | ||
} | ||
function findPreviousValid(steps, currentIndex) { | ||
const previousValid = [...steps].reverse().slice(steps.length - currentIndex).findIndex(el => !el.autoSkip); | ||
var previousValid = [...steps].reverse().slice(steps.length - currentIndex).findIndex(el => !el.autoSkip); | ||
return currentIndex - 1 - previousValid; | ||
@@ -147,24 +111,14 @@ } | ||
const Wizard = (_ref) => { | ||
let children = _ref.children, | ||
onComplete = _ref.onComplete, | ||
debug = _ref.debug; | ||
var Wizard = (_ref) => { | ||
var { | ||
children, | ||
onComplete, | ||
debug | ||
} = _ref; | ||
var [index, setIndex] = useState(0); | ||
var [steps, setSteps] = useState([]); | ||
var [isLoading, setLoadingState] = useState(false); | ||
const _useState = useState(0), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
index = _useState2[0], | ||
setIndex = _useState2[1]; | ||
const _useState3 = useState([]), | ||
_useState4 = _slicedToArray(_useState3, 2), | ||
steps = _useState4[0], | ||
setSteps = _useState4[1]; | ||
const _useState5 = useState(false), | ||
_useState6 = _slicedToArray(_useState5, 2), | ||
isLoading = _useState6[0], | ||
setLoadingState = _useState6[1]; | ||
function registerStep(step) { | ||
const alreadyRegistered = steps.map(el => el.name).includes(step.name); | ||
var alreadyRegistered = steps.map(el => el.name).includes(step.name); | ||
@@ -177,3 +131,3 @@ if (!alreadyRegistered) { | ||
function updateStep(step) { | ||
const stepIndex = steps.findIndex(el => el.name === step.name); | ||
var stepIndex = steps.findIndex(el => el.name === step.name); | ||
setSteps(prevSteps => [...prevSteps.slice(0, stepIndex), step, ...prevSteps.slice(stepIndex + 1)]); | ||
@@ -188,5 +142,7 @@ } | ||
_onNext = _asyncToGenerator(function* () { | ||
const validator = steps[index].validator; | ||
const next = findNextValid(steps, index); | ||
const nextAction = next === index ? () => onComplete(steps[index].name) : () => setIndex(next); | ||
var { | ||
validator | ||
} = steps[index]; | ||
var next = findNextValid(steps, index); | ||
var nextAction = next === index ? () => onComplete(steps[index].name) : () => setIndex(next); | ||
@@ -215,3 +171,3 @@ if (validator) { | ||
function onPrevious() { | ||
const prev = findPreviousValid(steps, index); | ||
var prev = findPreviousValid(steps, index); | ||
setIndex(prev); | ||
@@ -218,0 +174,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import React,{createContext,useContext,useEffect,useState}from"react";const ControlsContext=createContext(null),Controls=e=>{let t=e.render;const n=useContext(ControlsContext);return t(n.onNext,n.onPrevious,n.isFirst,n.isLast,n.isLoading)},StepContext=createContext(null),Step=e=>{let t=e.children,n=e.name,r=e.validator,o=e.autoSkip;const i=useContext(StepContext),a=i.registerStep,s=i.activeStep,l=i.updateStep,u=i.initialized,c={name:n,validator:r,autoSkip:o};return useEffect(()=>{u||a(c)},[n]),useEffect(()=>{u&&l(c)},[o,r]),s.name!==n?null:t};function asyncGeneratorStep(e,t,n,r,o,i,a){try{var s=e[i](a),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,o)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){asyncGeneratorStep(i,r,o,a,s,"next",e)}function s(e){asyncGeneratorStep(i,r,o,a,s,"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,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw i}}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)}Step.defaultProps={validator:null,autoSkip:!1};class ValidationError extends Error{}const Wizard=e=>{let t=e.children,n=e.onComplete,r=e.debug;const o=_slicedToArray(useState(0),2),i=o[0],a=o[1],s=_slicedToArray(useState([]),2),l=s[0],u=s[1],c=_slicedToArray(useState(!1),2),d=c[0],f=c[1];function p(){return(p=_asyncToGenerator(function*(){const e=l[i].validator,t=findNextValid(l,i),r=t===i?()=>n(l[i].name):()=>a(t);if(e)try{f(!0),yield 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",l)},[l]),React.createElement(ControlsContext.Provider,{value:{onNext:function(){return p.apply(this,arguments)},onPrevious:function(){const e=findPreviousValid(l,i);a(e)},isLoading:d,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)||u(t=>[...t,e])},activeStep:l[i]||{},initialized:!!l[i],updateStep:function(e){const t=l.findIndex(t=>t.name===e.name);u(n=>[...n.slice(0,t),e,...n.slice(t+1)])}}},t))};Wizard.defaultProps={debug:!1};export{Controls,ControlsContext,Step,StepContext,ValidationError,Wizard}; | ||
import React,{createContext,useContext,useEffect,useState}from"react";var ControlsContext=createContext(null),Controls=e=>{var{render:t}=e,{onNext:n,onPrevious:r,isFirst:o,isLast:a,isLoading:i}=useContext(ControlsContext);return t(n,r,o,a,i)},StepContext=createContext(null),Step=e=>{var{children:t,name:n,validator:r,autoSkip:o}=e,{registerStep:a,activeStep:i,updateStep:s,initialized:u}=useContext(StepContext),l={name:n,validator:r,autoSkip:o};return useEffect(()=>{u||a(l)},[n]),useEffect(()=>{u&&s(l)},[o,r]),i.name!==n?null:t};function asyncGeneratorStep(e,t,n,r,o,a,i){try{var s=e[a](i),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,o)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function i(e){asyncGeneratorStep(a,r,o,i,s,"next",e)}function s(e){asyncGeneratorStep(a,r,o,i,s,"throw",e)}i(void 0)})}}function findNextValid(e,t){var 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)}Step.defaultProps={validator:null,autoSkip:!1};class ValidationError extends Error{}var Wizard=e=>{var{children:t,onComplete:n,debug:r}=e,[o,a]=useState(0),[i,s]=useState([]),[u,l]=useState(!1);function d(){return(d=_asyncToGenerator(function*(){var{validator:e}=i[o],t=findNextValid(i,o),r=t===o?()=>n(i[o].name):()=>a(t);if(e)try{l(!0),yield e(),r()}catch(e){if(!(e instanceof ValidationError))throw e;console.error("ReactLosen",e)}finally{l(!1)}else r()})).apply(this,arguments)}return useEffect(()=>{r&&console.debug("steps updated",i)},[i]),React.createElement(ControlsContext.Provider,{value:{onNext:function(){return d.apply(this,arguments)},onPrevious:function(){var e=findPreviousValid(i,o);a(e)},isLoading:u,isFirst:findPreviousValid(i,o)===o,isLast:findNextValid(i,o)===o}},React.createElement(StepContext.Provider,{value:{registerStep:function(e){i.map(e=>e.name).includes(e.name)||s(t=>[...t,e])},activeStep:i[o]||{},initialized:!!i[o],updateStep:function(e){var t=i.findIndex(t=>t.name===e.name);s(n=>[...n.slice(0,t),e,...n.slice(t+1)])}}},t))};Wizard.defaultProps={debug:!1};export{Controls,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-7", | ||
"version": "2.0.0-8", | ||
"license": "MIT", | ||
"files": [ | ||
"dist-*/", | ||
"bin/" | ||
], | ||
"esnext": "dist-src/index.js", | ||
@@ -15,7 +19,2 @@ "module": "dist-web/index.js", | ||
], | ||
"files": [ | ||
"dist-*/", | ||
"assets/", | ||
"bin/" | ||
], | ||
"homepage": "https://docs-geycgwirqi.now.sh/", | ||
@@ -27,3 +26,5 @@ "repository": { | ||
"dependencies": { | ||
"prop-types": "^15.7.1", | ||
"prop-types": "^15.7.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.1" | ||
@@ -30,0 +31,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
35436
554
- Removedreact@^16.8.1