@dvrd/dvr-controls 1.0.26 → 1.0.27
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/package.json
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import React from "react";
|
|
5
|
+
import React, {useEffect, useRef} from "react";
|
|
6
6
|
import {debug} from "./miscUtil";
|
|
7
7
|
import {getScreenHeight, getScreenWidth} from "./responsiveUtil";
|
|
8
8
|
import {generateUUID} from "./controlUtil";
|
|
9
|
+
import {addCustomEventListener, removeCustomEventListener} from "./eventUtil";
|
|
9
10
|
|
|
10
11
|
export const generateComponentId = (id?: string | null, lettersOnly: boolean = true): string => {
|
|
11
12
|
if (id !== null && id !== undefined) return id;
|
|
@@ -56,4 +57,17 @@ export const getElementTop = (element: string | HTMLElement | null): number => {
|
|
|
56
57
|
return box.top + scrollTop;
|
|
57
58
|
}
|
|
58
59
|
return 0;
|
|
59
|
-
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export function useEvent(eventName: string, handler: Function, ...deps: any): string {
|
|
63
|
+
const id = useRef<string>(generateComponentId());
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
addCustomEventListener(id.current, eventName, handler);
|
|
67
|
+
return function () {
|
|
68
|
+
removeCustomEventListener(id.current, eventName);
|
|
69
|
+
}
|
|
70
|
+
}, [...deps])
|
|
71
|
+
|
|
72
|
+
return id.current;
|
|
73
|
+
}
|
package/src/js/util/eventUtil.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import {DialogActions} from "../dialog/dialogController";
|
|
7
|
-
import {DialogConfig
|
|
7
|
+
import {DialogConfig} from "./interfaces";
|
|
8
8
|
|
|
9
9
|
interface ListenerShape {
|
|
10
10
|
component: string,
|
|
@@ -14,6 +14,10 @@ interface ListenerShape {
|
|
|
14
14
|
|
|
15
15
|
const listeners: ListenerShape[] = [];
|
|
16
16
|
|
|
17
|
+
export function getCurrentListeners(): Array<ListenerShape> {
|
|
18
|
+
return listeners;
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
export const addCustomEventListener = (componentName: string, eventName: string, eventHandler: Function): boolean => {
|
|
18
22
|
if (listenerExists(componentName, eventName)) return false;
|
|
19
23
|
listeners.push({component: componentName, eventName, eventHandler});
|