From 7e48e193107bbcc5fa3145b22b59dfbee7ef9f92 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 17 Aug 2022 17:17:11 +0300 Subject: [PATCH] feat: define enums for isomorphic class --- package-lock.json | 27 +++++++++++++++++++++++++-- src/IdleDetect.ts | 10 +++++++--- src/IdleDetectIsomorph.ts | 18 ++++++++++++++++-- src/global.d.ts | 8 ++++---- src/index.ts | 2 ++ 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 79e5ddb..7cc47e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,31 @@ { "name": "idle-detect", - "version": "0.1.0", - "lockfileVersion": 1, + "version": "0.1.1", + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "idle-detect", + "version": "0.1.1", + "license": "MIT", + "devDependencies": { + "typescript": "~4.5.4" + } + }, + "node_modules/typescript": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", + "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, "dependencies": { "typescript": { "version": "4.5.4", diff --git a/src/IdleDetect.ts b/src/IdleDetect.ts index 08bbddd..26640f0 100644 --- a/src/IdleDetect.ts +++ b/src/IdleDetect.ts @@ -17,12 +17,16 @@ export class IdleDetect { public error: (...messages: any[]) => void = defaultNoLog public log: (...messages: any[]) => void = defaultNoLog + /** + * @param idleSeconds Number of seconds for idle detection, 15 minutes by default + * @param onIdle Event handler when user is idle for specified time + * @param enableLogs + * @param eventTypes + */ constructor( - /** Number of seconds for idle detection, 15 minutes by default */ idleSeconds: number = defaultIdleTime, - /** Event handler when user is idle for specified time */ onIdle: () => void = defaultNoop, - enableLogs = false, + enableLogs: boolean = false, eventTypes: string[] = defaultEventTypes, ) { this.eventTypes = eventTypes diff --git a/src/IdleDetectIsomorph.ts b/src/IdleDetectIsomorph.ts index 193ee61..049a272 100644 --- a/src/IdleDetectIsomorph.ts +++ b/src/IdleDetectIsomorph.ts @@ -2,15 +2,29 @@ import { IdleDetect, defaultEventTypes, defaultIdleTime, defaultNoop } from './I export const isIdleDetectorSupported = () => 'IdleDetector' in window +export enum UserIdleState { + active = 'active', + idle = 'idle', +} + +export enum ScreenIdleState { + locked = 'locked', + unlocked = 'unlocked', +} + export class IdleDetectIsomorph extends IdleDetect { // Native API protected controller?: AbortController = null protected detector?: IdleDetector = null + /** + * @param idleSeconds Number of seconds for idle detection, 15 minutes by default + * @param onIdle Event handler when user is idle for specified time + * @param enableLogs + * @param eventTypes + */ constructor( - /** Number of seconds for idle detection, 15 minutes by default */ idleSeconds: number = defaultIdleTime, - /** Event handler when user is idle for specified time */ onIdle: () => void = defaultNoop, enableLogs = false, eventTypes: string[] = defaultEventTypes, diff --git a/src/global.d.ts b/src/global.d.ts index fcafbca..343423c 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -7,13 +7,13 @@ declare global { enum UserIdleState { - 'active' = 'active', - 'idle' = 'idle', + active = 'active', + idle = 'idle', } enum ScreenIdleState { - 'locked' = 'locked', - 'unlocked' = 'unlocked', + locked = 'locked', + unlocked = 'unlocked', } interface IdleDetector { diff --git a/src/index.ts b/src/index.ts index 278dba5..cd27e24 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ import { IdleDetectIsomorph } from './IdleDetectIsomorph' +export { UserIdleState, ScreenIdleState } from './IdleDetectIsomorph' + export default IdleDetectIsomorph