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

react-use-presentation

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-presentation - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [1.3.0](https://github.com/olavoparno/react-use-presentation/compare/v1.2.0...v1.3.0) (2021-02-26)
### Features
* **project:** add trigger and callback option + ([91fd304](https://github.com/olavoparno/react-use-presentation/commit/91fd3049e03098e6947fac2861f528726ecfdae5))
## [1.2.0](https://github.com/olavoparno/react-use-presentation/compare/v1.1.0...v1.2.0) (2021-02-14)

@@ -7,0 +14,0 @@

4

dist/index.d.ts

@@ -8,6 +8,8 @@ import { Component, ReactElement } from 'react';

framesOptions: TFrameOptions[];
startTrigger: boolean;
startDelay?: number;
isLoop?: boolean;
callback?: () => void;
};
declare function usePresentation({ framesOptions, startDelay, isLoop, }: TUsePresentation): (number | Component)[];
declare function usePresentation({ framesOptions, startTrigger, startDelay, isLoop, callback, }: TUsePresentation): (number | Component)[];
export default usePresentation;

@@ -15,2 +15,2 @@ import{useState as n,useRef as e,useCallback as t,useEffect as r,cloneElement as o,useMemo as u}from"react";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var i=function(){return(i=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n}).apply(this,arguments)};function a(n,e,t,r){return new(t||(t=Promise))((function(o,u){function i(n){try{c(r.next(n))}catch(n){u(n)}}function a(n){try{c(r.throw(n))}catch(n){u(n)}}function c(n){var e;n.done?o(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(i,a)}c((r=r.apply(n,e||[])).next())}))}function c(n,e){var t,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;i;)try{if(t=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=e.call(n,i)}catch(n){u=[6,n],r=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}export default function(l){var s=this,f=l.framesOptions,p=l.startDelay,h=void 0===p?void 0:p,v=l.isLoop,b=void 0!==v&&v,d=n(null),y=d[0],m=d[1],w=f.length||0,g=e(f),x=t((function(n){return a(s,void 0,void 0,(function(){var e,t,r;return c(this,(function(o){switch(o.label){case 0:return e=n[0],t=n.slice(1),r=g.current.indexOf(e)+1,m(i(i({},e),{currentFrame:r})),[4,new Promise((function(n){return setTimeout(n,e.time)}))];case 1:return o.sent(),t.length?[4,x(t)]:[3,3];case 2:o.sent(),o.label=3;case 3:return[2]}}))}))}),[]),O=t((function(){return a(s,void 0,void 0,(function(){var n;return c(this,(function(e){switch(e.label){case 0:return n=g.current,h?[4,new Promise((function(n){return setTimeout(n,h)}))]:[3,2];case 1:e.sent(),e.label=2;case 2:return[4,x(n)];case 3:return e.sent(),b&&O(),[2]}}))}))}),[h,b,x]);r((function(){O()}),[O]);var k=t((function(n){var e=n.children,t=(null==y?void 0:y.component)||null;return e?t?o(t,void 0,e):null:t}),[y]);return u((function(){var n=(null!=y?y:{currentFrame:0}).currentFrame;return[k,n,w]}),[k,y,w])}
***************************************************************************** */var i=function(){return(i=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n}).apply(this,arguments)};function a(n,e,t,r){return new(t||(t=Promise))((function(o,u){function i(n){try{c(r.next(n))}catch(n){u(n)}}function a(n){try{c(r.throw(n))}catch(n){u(n)}}function c(n){var e;n.done?o(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(i,a)}c((r=r.apply(n,e||[])).next())}))}function c(n,e){var t,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;i;)try{if(t=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=e.call(n,i)}catch(n){u=[6,n],r=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}export default function(l){var s=this,f=l.framesOptions,v=l.startTrigger,p=void 0!==v&&v,h=l.startDelay,d=void 0===h?void 0:h,b=l.isLoop,y=void 0!==b&&b,m=l.callback,w=void 0===m?void 0:m,g=n(null),x=g[0],k=g[1],O=(null==f?void 0:f.length)||0,P=e(f),T=e(w),F=t((function(n){return a(s,void 0,void 0,(function(){var e,t,r,o;return c(this,(function(u){switch(u.label){case 0:return e=n[0],t=n.slice(1),r=(null===(o=P.current)||void 0===o?void 0:o.indexOf(e))+1,k(i(i({},e),{currentFrame:r})),[4,new Promise((function(n){return setTimeout(n,e.time)}))];case 1:return u.sent(),t.length?[4,F(t)]:[3,3];case 2:u.sent(),u.label=3;case 3:return T.current&&T.current(),[2]}}))}))}),[]),j=t((function(){return a(s,void 0,void 0,(function(){var n;return c(this,(function(e){switch(e.label){case 0:return n=P.current,d?[4,new Promise((function(n){return setTimeout(n,d)}))]:[3,2];case 1:e.sent(),e.label=2;case 2:return[4,F(n)];case 3:return e.sent(),y&&j(),[2]}}))}))}),[d,y,F]);r((function(){O>0&&p&&j()}),[O,p,j]);var S=t((function(n){var e=n.children,t=(null==x?void 0:x.component)||null;return e?t?o(t,void 0,e):null:t}),[x]);return u((function(){var n=(null!=x?x:{currentFrame:0}).currentFrame;return[S,n,O]}),[S,x,O])}

@@ -15,2 +15,2 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),n=function(){return(n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var u in n=arguments[t])Object.prototype.hasOwnProperty.call(n,u)&&(e[u]=n[u]);return e}).apply(this,arguments)};

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function t(e,n,t,r){return new(t||(t=Promise))((function(u,o){function a(e){try{c(r.next(e))}catch(e){o(e)}}function i(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var n;e.done?u(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,i)}c((r=r.apply(e,n||[])).next())}))}function r(e,n){var t,r,u,o,a={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(u=a.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){a.label=o[1];break}if(6===o[0]&&a.label<u[1]){a.label=u[1],u=o;break}if(u&&a.label<u[2]){a.label=u[2],a.ops.push(o);break}u[2]&&a.ops.pop(),a.trys.pop();continue}o=n.call(e,a)}catch(e){o=[6,e],r=0}finally{t=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}exports.default=function(u){var o=this,a=u.framesOptions,i=u.startDelay,c=void 0===i?void 0:i,l=u.isLoop,s=void 0!==l&&l,f=e.useState(null),p=f[0],v=f[1],h=a.length||0,b=e.useRef(a),d=e.useCallback((function(e){return t(o,void 0,void 0,(function(){var t,u,o;return r(this,(function(r){switch(r.label){case 0:return t=e[0],u=e.slice(1),o=b.current.indexOf(t)+1,v(n(n({},t),{currentFrame:o})),[4,new Promise((function(e){return setTimeout(e,t.time)}))];case 1:return r.sent(),u.length?[4,d(u)]:[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))}),[]),y=e.useCallback((function(){return t(o,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return e=b.current,c?[4,new Promise((function(e){return setTimeout(e,c)}))]:[3,2];case 1:n.sent(),n.label=2;case 2:return[4,d(e)];case 3:return n.sent(),s&&y(),[2]}}))}))}),[c,s,d]);e.useEffect((function(){y()}),[y]);var m=e.useCallback((function(n){var t=n.children,r=(null==p?void 0:p.component)||null;return t?r?e.cloneElement(r,void 0,t):null:r}),[p]);return e.useMemo((function(){var e=(null!=p?p:{currentFrame:0}).currentFrame;return[m,e,h]}),[m,p,h])};
***************************************************************************** */function t(e,n,t,r){return new(t||(t=Promise))((function(u,o){function i(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var n;e.done?u(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(i,a)}c((r=r.apply(e,n||[])).next())}))}function r(e,n){var t,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;i;)try{if(t=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=i.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=n.call(e,i)}catch(e){o=[6,e],r=0}finally{t=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}exports.default=function(u){var o=this,i=u.framesOptions,a=u.startTrigger,c=void 0!==a&&a,l=u.startDelay,s=void 0===l?void 0:l,f=u.isLoop,v=void 0!==f&&f,p=u.callback,d=void 0===p?void 0:p,h=e.useState(null),b=h[0],y=h[1],m=(null==i?void 0:i.length)||0,w=e.useRef(i),g=e.useRef(d),k=e.useCallback((function(e){return t(o,void 0,void 0,(function(){var t,u,o,i;return r(this,(function(r){switch(r.label){case 0:return t=e[0],u=e.slice(1),o=(null===(i=w.current)||void 0===i?void 0:i.indexOf(t))+1,y(n(n({},t),{currentFrame:o})),[4,new Promise((function(e){return setTimeout(e,t.time)}))];case 1:return r.sent(),u.length?[4,k(u)]:[3,3];case 2:r.sent(),r.label=3;case 3:return g.current&&g.current(),[2]}}))}))}),[]),x=e.useCallback((function(){return t(o,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return e=w.current,s?[4,new Promise((function(e){return setTimeout(e,s)}))]:[3,2];case 1:n.sent(),n.label=2;case 2:return[4,k(e)];case 3:return n.sent(),v&&x(),[2]}}))}))}),[s,v,k]);e.useEffect((function(){m>0&&c&&x()}),[m,c,x]);var O=e.useCallback((function(n){var t=n.children,r=(null==b?void 0:b.component)||null;return t?r?e.cloneElement(r,void 0,t):null:r}),[b]);return e.useMemo((function(){var e=(null!=b?b:{currentFrame:0}).currentFrame;return[O,e,m]}),[O,b,m])};
{
"name": "react-use-presentation",
"version": "1.2.0",
"version": "1.3.0",
"description": "Create pure HTML (React enriched if you will) presentations.",

@@ -5,0 +5,0 @@ "author": "Olavo Parno",

@@ -23,6 +23,6 @@ <img align="right" alt="traffic" src="https://pv-badge.herokuapp.com/total.svg?repo_id=olavoparno-react-use-presentation"/>

| Plain | Video BG |
| ------------------------------- | ---------------------------------- |
| ![Example](./assets/readme.gif) | ![Example](./assets/readme-bg.gif) |
| [Preview!](https://codesandbox.io/s/react-use-presentation-1c2du) | [Preview with BG video!](https://codesandbox.io/s/react-use-presentation-with-bg-d7f7j) |
| Plain | Video BG |
| ----------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| ![Example](./assets/readme.gif) | ![Example](./assets/readme-bg.gif) |
| [Preview!](https://codesandbox.io/s/react-use-presentation-1c2du) | [Preview with BG video!](https://codesandbox.io/s/react-use-presentation-with-bg-d7f7j) |

@@ -65,14 +65,15 @@ ---

import usePresentation from 'react-use-presentation';
import { myFramesArray1 } from './myFramesArray'
import { myFramesArray1 } from './myFramesArray';
export default function App() {
const [Presentation] = usePresentation({ framesOptions: myFramesArray1 });
const [Presentation] = usePresentation({
framesOptions: myFramesArray1,
startTrigger: false,
});
return (
<Presentation />
)
return <Presentation />;
}
```
- To initialize a __delayed__ (in milliseconds) Presentation component:
- To initialize a **delayed** (in milliseconds) Presentation component:

@@ -82,3 +83,3 @@ ```tsx

import usePresentation from 'react-use-presentation';
import { myFramesArray2 } from './myFramesArray'
import { myFramesArray2 } from './myFramesArray';

@@ -88,12 +89,11 @@ export default function App() {

framesOptions: myFramesArray2,
startDelay: 1000
startTrigger: true,
startDelay: 1000,
});
return (
<DelayedPresentation />
)
return <DelayedPresentation />;
}
```
- To initialize a __delayed__ (in milliseconds) and also in __loop__ Presentation component:
- To initialize a **delayed** (in milliseconds) and also in **loop** Presentation component:

@@ -103,3 +103,3 @@ ```tsx

import usePresentation from 'react-use-presentation';
import { myFramesArray3 } from './myFramesArray'
import { myFramesArray3 } from './myFramesArray';

@@ -109,9 +109,8 @@ export default function App() {

framesOptions: myFramesArray3,
startTrigger: true,
startDelay: 1000,
isLoop: true
isLoop: true,
});
return (
<DelayedAndLoopedPresentation />
)
return <DelayedAndLoopedPresentation />;
}

@@ -125,14 +124,27 @@ ```

import usePresentation from 'react-use-presentation';
import { myFramesArray1, myFramesArray2, myFramesArray3 } from './myFramesArray';
import {
myFramesArray1,
myFramesArray2,
myFramesArray3,
} from './myFramesArray';
export default function App() {
const [Presentation] = usePresentation({ framesOptions: myFramesArray1 });
const [Presentation] = usePresentation({
framesOptions: myFramesArray1,
startTrigger: false,
});
const [DelayedPresentation] = usePresentation({
framesOptions: myFramesArray2,
startDelay: 1000
startTrigger: true,
startDelay: 1000,
});
const [DelayedAndLoopedPresentation, currentLoopFrame, loopFramesLength] = usePresentation({
const [
DelayedAndLoopedPresentation,
currentLoopFrame,
loopFramesLength,
] = usePresentation({
framesOptions: myFramesArray3,
startTrigger: true,
startDelay: 1000,
isLoop: true
isLoop: true,
});

@@ -145,11 +157,13 @@

<div>
<p>Current frame: {currentLoopFrame}/{loopFramesLength}</p>
<p>
Current frame: {currentLoopFrame}/{loopFramesLength}
</p>
<DelayedAndLoopedPresentation />
</div>
</>
)
);
}
```
- You can also render elements as children:
- You can also render elements as children (note that the component passed via array must support children):

@@ -162,4 +176,9 @@ ```tsx

export default function App() {
const [PresentationWithChildren, currentFrame, framesLength] = usePresentation({
framesOptions: myFramesArray1
const [
PresentationWithChildren,
currentFrame,
framesLength,
] = usePresentation({
framesOptions: myFramesArray1,
startTrigger: true,
});

@@ -169,8 +188,36 @@

<PresentationWithChildren>
<p>Current frame: {currentFrame}/{framesLength}</p>
<p>
Current frame: {currentFrame}/{framesLength}
</p>
</PresentationWithChildren>
)
);
}
```
- You can control when to start the presentation using `startTrigger` as a control. You can also specify a callback to when it finishes:
```tsx
import * as react from 'react';
import usePresentation from 'react-use-presentation';
import { myFramesArray1 } from './myFramesArray';
export default function App() {
const [startTrigger, setStartTrigger] = React.useState(false);
const [PresentationTriggered] = usePresentation({
framesOptions: myFramesArray1,
startTrigger,
callback: () => setStartTrigger(false),
});
return (
<>
<button type="button" onClick={() => setStartTrigger(true)}>
Click to start presenting!
</button>
<PresentationTriggered />
</>
);
}
```
---

@@ -184,11 +231,12 @@

type TFrameOptions = {
component: Component | null,
time?: number
}
component: Component | null;
time?: number;
};
type TUsePresentation = {
framesOptions: Array<TFrameOptions>,
startDelay?: number,
isLoop?: boolean
}
framesOptions: TFrameOptions[];
startTrigger: boolean;
startDelay?: number;
isLoop?: boolean;
};

@@ -209,3 +257,7 @@ usePresentation(TUsePresentation);

```tsx
const [MyLittleComponent, currentFrameLittle, totalLengthLittle] = usePresentation();
const [
MyLittleComponent,
currentFrameLittle,
totalLengthLittle,
] = usePresentation();
```

@@ -212,0 +264,0 @@

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