dev-classes 1.4.39 → 1.5.1
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/README.md +133 -1
- package/dist/classes/BrowserUtils/BrowserUtils.d.ts +5 -0
- package/dist/classes/BrowserUtils/index.d.ts +1 -0
- package/dist/classes/NetworkStatusTracker/NetworkStatusTracker.d.ts +4 -3
- package/dist/classes/NetworkStatusTracker/NetworkStatusTracker.types.d.ts +1 -1
- package/dist/classes/NetworkStatusTracker/index.d.ts +0 -1
- package/dist/classes/Timer/Timer.d.ts +43 -0
- package/dist/classes/Timer/index.d.ts +1 -0
- package/dist/classes/Utils/NetworkInformation/index.d.ts +0 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1134 -984
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ HTTPSApi.request({keyAction: 'action1', request: {url: '...'}})
|
|
|
15
15
|
<h3 align="center">NetworkInformation</h3>
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import { NetworkInformation, NetworkInformationCordova, NetworkInformationPC } from 'dev-classes';
|
|
18
|
+
import { NetworkInformation, NetworkInformationCordova, NetworkInformationPC, NetworkStatusTracker } from 'dev-classes';
|
|
19
19
|
|
|
20
20
|
const internet = new NetworkInformation([new NetworkInformationPC(), new NetworkInformationCordova()]);
|
|
21
21
|
|
|
@@ -23,6 +23,138 @@ internet.run((status, textStatus) => {
|
|
|
23
23
|
status ? online() : offline();
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
// или
|
|
27
|
+
const listUrl = ['https://www.google.com'];// для проверки можно опираться на адреса иначе используеться listeners online/ofline или change
|
|
28
|
+
const networkTicker = new NetworkStatusTracker(listUrl);//или []
|
|
29
|
+
|
|
30
|
+
await networkTicker.startEvents((info) => {
|
|
31
|
+
console.dir(info);
|
|
32
|
+
console.dir('А');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.dir('Б');
|
|
36
|
+
|
|
37
|
+
//Продолжаем инициализацию приложения после установки иментов
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
<h3 align="center">Timer</h3>
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { Timer } from 'dev-classes';
|
|
44
|
+
|
|
45
|
+
//Рабочий hook
|
|
46
|
+
|
|
47
|
+
interface UseShowPanelProps {
|
|
48
|
+
timeoutShowPanel?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface UseShowPanelState {
|
|
52
|
+
showPanel: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const useShowPanel = (props: UseShowPanelProps = { timeoutShowPanel: 5000 }) => {
|
|
56
|
+
const [state, setState] = useState<UseShowPanelState>({
|
|
57
|
+
showPanel: true,
|
|
58
|
+
});
|
|
59
|
+
const setStateHelpers = setStateDecorator(state, setState);
|
|
60
|
+
|
|
61
|
+
const timerRef = useRef<Timer | null>(null);
|
|
62
|
+
|
|
63
|
+
// Инициализация таймера
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
timerRef.current = new Timer(props.timeoutShowPanel, () => {
|
|
66
|
+
console.log("Время истекло, скрываем панель");
|
|
67
|
+
setStateHelpers({ showPanel: false });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
timerRef.current.startTime();
|
|
71
|
+
return () => {
|
|
72
|
+
if (timerRef.current) {
|
|
73
|
+
timerRef.current.resetTime();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}, [props.timeoutShowPanel]);
|
|
77
|
+
|
|
78
|
+
// Показать панель и запустить таймер
|
|
79
|
+
const handleShowPanel = useCallback(() => {
|
|
80
|
+
if (!state.showPanel) {
|
|
81
|
+
setStateHelpers({ showPanel: true });
|
|
82
|
+
|
|
83
|
+
// Важно: сбрасываем и запускаем таймер заново
|
|
84
|
+
if (timerRef.current) {
|
|
85
|
+
timerRef.current.resetTime();
|
|
86
|
+
timerRef.current.startTime();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, [state.showPanel]);
|
|
90
|
+
|
|
91
|
+
// Сбросить время (продлить показ панели)
|
|
92
|
+
const handleResetTimePanel = useCallback(() => {
|
|
93
|
+
if (timerRef.current && state.showPanel) {
|
|
94
|
+
timerRef.current.resetTime();
|
|
95
|
+
timerRef.current.startTime();
|
|
96
|
+
}
|
|
97
|
+
}, [state.showPanel]);
|
|
98
|
+
|
|
99
|
+
// Поставить на паузу (например, при открытии select)
|
|
100
|
+
const handlePauseTimer = useCallback(() => {
|
|
101
|
+
if (timerRef.current && state.showPanel) {
|
|
102
|
+
timerRef.current.pauseTime();
|
|
103
|
+
}
|
|
104
|
+
}, [state.showPanel]);
|
|
105
|
+
|
|
106
|
+
// Возобновить таймер (например, при закрытии select)
|
|
107
|
+
const handleResumeTimer = useCallback(() => {
|
|
108
|
+
if (timerRef.current && state.showPanel) {
|
|
109
|
+
timerRef.current.startTime();
|
|
110
|
+
}
|
|
111
|
+
}, [state.showPanel]);
|
|
112
|
+
|
|
113
|
+
// Скрыть панель принудительно
|
|
114
|
+
const handleHidePanel = useCallback(() => {
|
|
115
|
+
setStateHelpers({ showPanel: false });
|
|
116
|
+
if (timerRef.current) {
|
|
117
|
+
timerRef.current.resetTime();
|
|
118
|
+
}
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
showPanel: state.showPanel,
|
|
123
|
+
handleShowPanel,
|
|
124
|
+
handleResetTimePanel,
|
|
125
|
+
handlePauseTimer,
|
|
126
|
+
handleResumeTimer,
|
|
127
|
+
handleHidePanel,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
//Где-то
|
|
133
|
+
const { showPanel, handleShowPanel, handleResetTimePanel, handlePauseTimer, handleResumeTimer } = useShowPanel({ timeoutShowPanel: 8000 });
|
|
134
|
+
|
|
135
|
+
<ContentPage onClick={() => {
|
|
136
|
+
handleResetTimePanel();
|
|
137
|
+
handleShowPanel();
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
//...
|
|
141
|
+
//При открытии на панели окон и селекторов можно остановить таймер скрытия
|
|
142
|
+
//handlePauseTimer, handleResumeTimer
|
|
143
|
+
</ContentPage>
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
<h3 align="center">BrowserUtils</h3>
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { BrowserUtils, BrowserPlatforms_OR } from 'dev-classes';
|
|
151
|
+
|
|
152
|
+
BrowserUtils.initEventsPauseResume((statusString) => {
|
|
153
|
+
console.log(statusString)// => on/off
|
|
154
|
+
})
|
|
155
|
+
//Универсальный метод для браузеров и webKit. Ориентируеться на userAgent
|
|
156
|
+
const platform:BrowserPlatforms_OR = BrowserUtils.getWebPlatform();
|
|
157
|
+
|
|
26
158
|
```
|
|
27
159
|
<h3 align="center">Color</h3>
|
|
28
160
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type BrowserPlatforms_OR = 'iOS/Mac' | 'iOS' | 'Android' | 'Windows' | 'Mac' | 'Linux' | 'unknown';
|
|
2
|
+
export declare class BrowserUtils {
|
|
3
|
+
static getWebPlatform: () => BrowserPlatforms_OR;
|
|
4
|
+
static initEventsPauseResume(cbInfo: (status: "on" | "off") => void): void;
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BrowserUtils';
|
|
@@ -5,15 +5,15 @@ export declare class NetworkStatusTracker {
|
|
|
5
5
|
private state;
|
|
6
6
|
private setState;
|
|
7
7
|
private getState;
|
|
8
|
-
constructor(listUrls
|
|
8
|
+
constructor(listUrls?: string[]);
|
|
9
9
|
private getConnection;
|
|
10
|
-
private getIsNetwork;
|
|
11
10
|
private getTypeNetwork;
|
|
12
11
|
private updateState;
|
|
13
12
|
private controllersEvents;
|
|
14
13
|
private getControllersEvents;
|
|
15
14
|
private setControllersEvents;
|
|
16
|
-
|
|
15
|
+
private initialize;
|
|
16
|
+
startEvents(onStatusChange: OnStatusChange): Promise<void>;
|
|
17
17
|
stopEvents(): void;
|
|
18
18
|
private requestByUrls;
|
|
19
19
|
private checkConnection;
|
|
@@ -27,4 +27,5 @@ export declare class NetworkStatusTracker {
|
|
|
27
27
|
stop: () => void;
|
|
28
28
|
};
|
|
29
29
|
getCurrentState(): NetworkStatusInfoTracker;
|
|
30
|
+
destroy(): void;
|
|
30
31
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type TimerCallback = () => void;
|
|
2
|
+
export declare class Timer {
|
|
3
|
+
private duration;
|
|
4
|
+
private onComplete;
|
|
5
|
+
private timerId;
|
|
6
|
+
private startTimeCount;
|
|
7
|
+
private remainingTime;
|
|
8
|
+
private isPaused;
|
|
9
|
+
/**
|
|
10
|
+
* @param duration - Время в миллисекундах
|
|
11
|
+
* @param onComplete - Колбэк, вызываемый по истечении времени
|
|
12
|
+
*/
|
|
13
|
+
constructor(duration: number, onComplete: TimerCallback);
|
|
14
|
+
/**
|
|
15
|
+
* Запускает или возобновляет таймер
|
|
16
|
+
*/
|
|
17
|
+
startTime(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Ставит таймер на паузу
|
|
20
|
+
*/
|
|
21
|
+
pauseTime(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Сбрасывает таймер к начальному состоянию
|
|
24
|
+
*/
|
|
25
|
+
resetTime(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Завершает таймер и вызывает колбэк
|
|
28
|
+
*/
|
|
29
|
+
private complete;
|
|
30
|
+
/**
|
|
31
|
+
* Проверяет, запущен ли таймер
|
|
32
|
+
*/
|
|
33
|
+
isRunning(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Проверяет, находится ли таймер на паузе
|
|
36
|
+
*/
|
|
37
|
+
isPausedState(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Возвращает оставшееся время в миллисекундах
|
|
40
|
+
*/
|
|
41
|
+
getRemainingTime(): number;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Timer';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { NetworkInformation } from './NetworkInformation';
|
|
2
2
|
export { NetworkInformationPC } from './classes/NetworkInformationPC';
|
|
3
|
-
export { NetworkInformationAbstract } from './classes/types/types.abscruct';
|
|
4
3
|
export { NetworkInformationCordova, type CordovaNetworkStatus } from './classes/NetworkInformationCordova';
|
package/dist/index.d.ts
CHANGED