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

react-losen

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-losen - npm Package Compare versions

Comparing version 2.0.0-5 to 2.0.0-6

dist-node/index.js

19

dist-src/Controls.js

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

import { createContext } from 'react';
export const ControlsContext = createContext(null);
import { createContext, useContext } from 'react';
export const ControlsContext = createContext(null);
const Controls = ({
render
}) => {
const {
onNext,
onPrevious,
isFirst,
isLast,
isLoading
} = useContext(ControlsContext);
return render(onNext, onPrevious, isFirst, isLast, isLoading);
};
export default Controls;

6

dist-src/index.js

@@ -0,4 +1,4 @@

import Controls, { ControlsContext } from "./Controls.js";
import Step, { StepContext } from "./Step.js";
import Wizard, { ValidationError } from "./Wizard.js";
import Step, { StepContext } from "./Step.js";
import { ControlsContext } from "./Controls.js";
export { Wizard, Step, StepContext, ValidationError, ControlsContext };
export { Controls, ControlsContext, Step, StepContext, ValidationError, Wizard };

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

import Wizard,{ValidationError}from"./Wizard.js";import Step,{StepContext}from"./Step.js";import{ControlsContext}from"./Controls.js";export{Wizard,Step,StepContext,ValidationError,ControlsContext};
import Controls,{ControlsContext}from"./Controls.js";import Step,{StepContext}from"./Step.js";import Wizard,{ValidationError}from"./Wizard.js";export{Controls,ControlsContext,Step,StepContext,ValidationError,Wizard};
//# sourceMappingURL=index.min.js.map
import React, { createContext, useContext, useEffect, useState } from 'react';
const 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;
return render(onNext, onPrevious, isFirst, isLast, isLoading);
};
const 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 = {
name,
validator,
autoSkip
};
useEffect(() => {
if (!initialized) {
registerStep(stepInfo);
}
}, [name]);
useEffect(() => {
if (initialized) {
updateStep(stepInfo);
}
}, [autoSkip]);
if (activeStep.name !== name) {
return null;
}
return children;
};
Step.defaultProps = {
validator: null,
autoSkip: false
};
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {

@@ -87,46 +144,2 @@ try {

const ControlsContext = createContext(null);
const 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 = {
name,
validator,
autoSkip
};
useEffect(() => {
if (!initialized) {
registerStep(stepInfo);
}
}, [name]);
useEffect(() => {
if (initialized) {
updateStep(stepInfo);
}
}, [autoSkip]);
if (activeStep.name !== name) {
return null;
}
return children;
};
Step.defaultProps = {
validator: null,
autoSkip: false
};
class ValidationError extends Error {}

@@ -231,2 +244,2 @@

export { ControlsContext, Step, StepContext, ValidationError, Wizard };
export { Controls, 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,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};
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]),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=findNextValid(l,i)===i?()=>n(l[i].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",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};
//# sourceMappingURL=index.min.js.map
{
"name": "react-losen",
"description": "A super customisable Wizard for React and React Native",
"version": "2.0.0-5",
"version": "2.0.0-6",
"license": "MIT",
"esnext": "dist-src/index.js",
"module": "dist-web/index.js",
"main": "dist-node/index.js",
"pika": true,

@@ -35,2 +36,3 @@ "sideEffects": false,

"@pika/pack": "^0.3.6",
"@pika/plugin-build-node": "^0.3.14",
"@pika/plugin-build-web": "^0.3.14",

@@ -37,0 +39,0 @@ "@pika/plugin-standard-pkg": "^0.3.14",

@@ -67,3 +67,3 @@ ---

```
yarn build
yarn run build
```

@@ -75,8 +75,10 @@

Publish new versions with `yarn pack:publish`. Pika guides you through the Through a wizard, this helps you bump the version number and publish to npm.
Publish new versions with `yarn run publish`. `Pack` guides you through the Through a wizard, this helps you bump the version number and publish to npm. **Note:** It's importaint to use the `run` argument, as `yarn publish` is a built in command and won't use `Pack`
### Deloying docs
### Building docs
The documentation is built by running `yarn build:docs`. This generates a static site in `./docs/`. Currently the site is deployed and hosted with [Zeit's Now](https://zeit.co/blog/now-static).
The documentation is built by running `yarn docs:build`. This generates a static site in `./docs/`. Currently the site is deployed and hosted with [Zeit's Now](https://zeit.co/blog/now-static).
Todo: Add information on how to deploy docs with Now.
## Versioning

@@ -88,7 +90,11 @@

TODO: Add jest.
Testing is done using the [Jest](https://facebook.github.io/jest/) test
framework. Assertions is done [with Jest's `Expect`
matchers](https://facebook.github.io/jest/docs/en/expect.html).
Todo: Add CI.
## Style guide
At react-losen, we use the following tools:
For code quality, react-losen use the following tools:

@@ -101,11 +107,7 @@ - [Flow](https://flow.org/) for static type checking

- `Wizard`, the main orchestrator. It has 2 required props
- render: This takes a set of `Step` as children. Minumum 2. Start and end
- onComplete: What to do when the Wizard is complete.
- onStepChange is called each time the step changes. This function is not called on initial load.
- `Step`, a wrapper for what you want to show as a step. It registers the step on mount to the Wizard context
- `Controls`, the controller for which step to show next. Has 2 directions: next and previous. It also knows if you are on the last or first step.
See [documentation](https://docs-geycgwirqi.now.sh/)
## Licensing
[MIT](https://github.com/otovo/react-losen/blob/master/LICENSE)

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