@timekeeper-countdown/react 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +27 -0
- package/package.json +4 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var react=require('react'),core=require('@timekeeper-countdown/core');var M=(a,p)=>{let u=core.CountdownEngine(a,{tickIntervalMs:p.tickIntervalMs,timeProvider:p.timeProvider}),i=u.getSnapshot();return u.destroy(),i};function P(a,p={}){let{autoStart:u=false,tickIntervalMs:i,timeProvider:c,onSnapshot:l,onStateChange:C,onError:S}=p,d=react.useRef({onSnapshot:l,onStateChange:C,onError:S}),g=react.useRef(null),[r,m]=react.useState(()=>M(a,{tickIntervalMs:i,timeProvider:c}));react.useEffect(()=>{d.current={onSnapshot:l,onStateChange:C,onError:S};},[S,l,C]);let w=react.useMemo(()=>({tickIntervalMs:i,timeProvider:c}),[i,c]);react.useEffect(()=>{let n=true,e=core.CountdownEngine(a,{...w,onSnapshot:o=>{n&&m(o),d.current.onSnapshot?.(o);},onStateChange:(o,y)=>{d.current.onStateChange?.(o,y);},onError:o=>{d.current.onError?.(o);}});return g.current=e,m(e.getSnapshot()),u&&e.start(),()=>{n=false,e.destroy(),g.current=null;}},[u,w,a]);let t=react.useCallback((n,e)=>{let o=g.current;return o?n(o):e},[]),E=react.useCallback(()=>t(n=>n.start(),false),[t]),v=react.useCallback(()=>t(n=>n.pause(),false),[t]),O=react.useCallback(()=>t(n=>n.resume(),false),[t]),U=react.useCallback(()=>t(n=>n.stop(),false),[t]),I=react.useCallback(n=>t(e=>e.setSeconds(n),void 0),[t]),R=react.useCallback(n=>t(e=>e.reset(n),false),[t]);return {snapshot:r,state:r.state,totalSeconds:r.totalSeconds,parts:r.parts,isRunning:r.isRunning,isCompleted:r.isCompleted,start:E,pause:v,resume:O,reset:R,stop:U,setSeconds:I}}exports.useCountdown=P;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CountdownEngineOptions, CountdownSnapshot, TimerState } from '@timekeeper-countdown/core';
|
|
2
|
+
|
|
3
|
+
interface UseCountdownOptions extends Omit<CountdownEngineOptions, 'onSnapshot' | 'onStateChange' | 'onError'> {
|
|
4
|
+
autoStart?: boolean;
|
|
5
|
+
onSnapshot?: CountdownEngineOptions['onSnapshot'];
|
|
6
|
+
onStateChange?: CountdownEngineOptions['onStateChange'];
|
|
7
|
+
onError?: CountdownEngineOptions['onError'];
|
|
8
|
+
}
|
|
9
|
+
interface UseCountdownControls {
|
|
10
|
+
start: () => boolean;
|
|
11
|
+
pause: () => boolean;
|
|
12
|
+
resume: () => boolean;
|
|
13
|
+
reset: (nextInitialSeconds?: number) => boolean;
|
|
14
|
+
stop: () => boolean;
|
|
15
|
+
setSeconds: (value: number) => void;
|
|
16
|
+
}
|
|
17
|
+
interface UseCountdownResult extends UseCountdownControls {
|
|
18
|
+
snapshot: CountdownSnapshot;
|
|
19
|
+
state: TimerState;
|
|
20
|
+
totalSeconds: number;
|
|
21
|
+
parts: CountdownSnapshot['parts'];
|
|
22
|
+
isRunning: boolean;
|
|
23
|
+
isCompleted: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare function useCountdown(initialSeconds: number, options?: UseCountdownOptions): UseCountdownResult;
|
|
26
|
+
|
|
27
|
+
export { type UseCountdownControls, type UseCountdownOptions, type UseCountdownResult, useCountdown };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timekeeper-countdown/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "React adapter for the Timekeeper Countdown engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"react": ">=17.0.0"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@timekeeper-countdown/core": "^0.1.
|
|
37
|
+
"@timekeeper-countdown/core": "^0.1.4"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@testing-library/jest-dom": "^6.4.2",
|