@flowtomic/logic 0.1.0 → 0.1.2
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/hooks/useAnimatedIndicator/index.d.ts +3 -0
- package/dist/hooks/useAnimatedIndicator/index.d.ts.map +1 -0
- package/dist/hooks/useAnimatedIndicator/index.js +1 -0
- package/dist/hooks/useAnimatedIndicator/useAnimatedIndicator.d.ts +94 -0
- package/dist/hooks/useAnimatedIndicator/useAnimatedIndicator.d.ts.map +1 -0
- package/dist/hooks/useAnimatedIndicator/useAnimatedIndicator.js +228 -0
- package/dist/hooks/useGenealogy/index.d.ts +3 -0
- package/dist/hooks/useGenealogy/index.d.ts.map +1 -0
- package/dist/hooks/useGenealogy/index.js +1 -0
- package/dist/hooks/useGenealogy/useGenealogy.d.ts +96 -0
- package/dist/hooks/useGenealogy/useGenealogy.d.ts.map +1 -0
- package/dist/hooks/useGenealogy/useGenealogy.js +335 -0
- package/dist/hooks/useMoblile/index.js +1 -868
- package/dist/hooks/useProjectProgress/index.d.ts +3 -0
- package/dist/hooks/useProjectProgress/index.d.ts.map +1 -0
- package/dist/hooks/useProjectProgress/index.js +1 -0
- package/dist/hooks/useProjectProgress/useProjectProgress.d.ts +103 -0
- package/dist/hooks/useProjectProgress/useProjectProgress.d.ts.map +1 -0
- package/dist/hooks/useProjectProgress/useProjectProgress.js +124 -0
- package/dist/hooks/useProjectStats/index.d.ts +3 -0
- package/dist/hooks/useProjectStats/index.d.ts.map +1 -0
- package/dist/hooks/useProjectStats/index.js +1 -0
- package/dist/hooks/useProjectStats/useProjectStats.d.ts +130 -0
- package/dist/hooks/useProjectStats/useProjectStats.d.ts.map +1 -0
- package/dist/hooks/useProjectStats/useProjectStats.js +87 -0
- package/dist/hooks/useResizable/index.d.ts +1 -1
- package/dist/hooks/useResizable/index.d.ts.map +1 -1
- package/dist/hooks/useScriptEditor/index.d.ts +3 -0
- package/dist/hooks/useScriptEditor/index.d.ts.map +1 -0
- package/dist/hooks/useScriptEditor/index.js +1 -0
- package/dist/hooks/useScriptEditor/useScriptEditor.d.ts +147 -0
- package/dist/hooks/useScriptEditor/useScriptEditor.d.ts.map +1 -0
- package/dist/hooks/useScriptEditor/useScriptEditor.js +247 -0
- package/dist/hooks/useStatCard/useStatCard.d.ts +44 -5
- package/dist/hooks/useStatCard/useStatCard.d.ts.map +1 -1
- package/dist/hooks/useStatCard/useStatCard.js +81 -20
- package/dist/hooks/useTimeTracker/index.d.ts +3 -0
- package/dist/hooks/useTimeTracker/index.d.ts.map +1 -0
- package/dist/hooks/useTimeTracker/index.js +1 -0
- package/dist/hooks/useTimeTracker/useTimeTracker.d.ts +106 -0
- package/dist/hooks/useTimeTracker/useTimeTracker.d.ts.map +1 -0
- package/dist/hooks/useTimeTracker/useTimeTracker.js +143 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/package.json +2 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useTimeTracker - Headless UI Hook
|
|
3
|
+
*
|
|
4
|
+
* Fornece apenas: lógica, estado, processamento e API
|
|
5
|
+
* NÃO fornece: markup, styles ou implementações pré-construídas
|
|
6
|
+
*
|
|
7
|
+
* Padrão Headless UI: você controla o markup e styles
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function MyTimer() {
|
|
12
|
+
* const { time, formattedTime, isRunning, start, pause, stop, reset } = useTimeTracker({
|
|
13
|
+
* initialTime: 0,
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* return (
|
|
17
|
+
* <div>
|
|
18
|
+
* <span>{formattedTime}</span>
|
|
19
|
+
* <button onClick={start}>Start</button>
|
|
20
|
+
* <button onClick={pause}>Pause</button>
|
|
21
|
+
* <button onClick={stop}>Stop</button>
|
|
22
|
+
* <button onClick={reset}>Reset</button>
|
|
23
|
+
* </div>
|
|
24
|
+
* )
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
29
|
+
/**
|
|
30
|
+
* Hook headless para gerenciar timer
|
|
31
|
+
*/
|
|
32
|
+
export function useTimeTracker(options = {}) {
|
|
33
|
+
const { initialTime = 0, onPause, onStop, onStart, onResume, onReset, format = "HH:mm:ss", } = options;
|
|
34
|
+
const [time, setTime] = useState(initialTime);
|
|
35
|
+
const [isRunning, setIsRunning] = useState(false);
|
|
36
|
+
const [isPaused, setIsPaused] = useState(false);
|
|
37
|
+
const intervalRef = useRef(null);
|
|
38
|
+
const startTimeRef = useRef(null);
|
|
39
|
+
const pausedTimeRef = useRef(0);
|
|
40
|
+
// Limpar intervalo ao desmontar
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
return () => {
|
|
43
|
+
if (intervalRef.current) {
|
|
44
|
+
clearInterval(intervalRef.current);
|
|
45
|
+
intervalRef.current = null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
// Formatar tempo
|
|
50
|
+
const formatTime = useCallback((seconds) => {
|
|
51
|
+
if (typeof format === "function") {
|
|
52
|
+
return format(seconds);
|
|
53
|
+
}
|
|
54
|
+
const hours = Math.floor(seconds / 3600);
|
|
55
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
56
|
+
const secs = seconds % 60;
|
|
57
|
+
switch (format) {
|
|
58
|
+
case "HH:mm:ss":
|
|
59
|
+
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
|
|
60
|
+
case "mm:ss":
|
|
61
|
+
return `${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
|
|
62
|
+
case "ss":
|
|
63
|
+
return String(seconds);
|
|
64
|
+
default:
|
|
65
|
+
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
|
|
66
|
+
}
|
|
67
|
+
}, [format]);
|
|
68
|
+
const formattedTime = formatTime(time);
|
|
69
|
+
// Limpar intervalo
|
|
70
|
+
const clearTimerInterval = useCallback(() => {
|
|
71
|
+
if (intervalRef.current) {
|
|
72
|
+
clearInterval(intervalRef.current);
|
|
73
|
+
intervalRef.current = null;
|
|
74
|
+
}
|
|
75
|
+
}, []);
|
|
76
|
+
// Iniciar timer
|
|
77
|
+
const start = useCallback(() => {
|
|
78
|
+
if (isRunning)
|
|
79
|
+
return;
|
|
80
|
+
clearTimerInterval();
|
|
81
|
+
// Se estava pausado, continuar de onde parou
|
|
82
|
+
const startFrom = isPaused ? time : initialTime;
|
|
83
|
+
setTime(startFrom);
|
|
84
|
+
setIsRunning(true);
|
|
85
|
+
setIsPaused(false);
|
|
86
|
+
pausedTimeRef.current = startFrom;
|
|
87
|
+
startTimeRef.current = Date.now() - startFrom * 1000;
|
|
88
|
+
intervalRef.current = setInterval(() => {
|
|
89
|
+
const elapsed = Math.floor((Date.now() - (startTimeRef.current || 0)) / 1000);
|
|
90
|
+
setTime(elapsed);
|
|
91
|
+
}, 100);
|
|
92
|
+
if (!isPaused) {
|
|
93
|
+
onStart?.(startFrom);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
onResume?.(startFrom);
|
|
97
|
+
}
|
|
98
|
+
}, [isRunning, isPaused, time, initialTime, onStart, onResume, clearTimerInterval]);
|
|
99
|
+
// Pausar timer
|
|
100
|
+
const pause = useCallback(() => {
|
|
101
|
+
if (!isRunning)
|
|
102
|
+
return;
|
|
103
|
+
clearTimerInterval();
|
|
104
|
+
setIsRunning(false);
|
|
105
|
+
setIsPaused(true);
|
|
106
|
+
onPause?.(time);
|
|
107
|
+
}, [isRunning, time, onPause, clearTimerInterval]);
|
|
108
|
+
// Parar timer
|
|
109
|
+
const stop = useCallback(() => {
|
|
110
|
+
clearTimerInterval();
|
|
111
|
+
setIsRunning(false);
|
|
112
|
+
setIsPaused(false);
|
|
113
|
+
onStop?.(time);
|
|
114
|
+
}, [time, onStop, clearTimerInterval]);
|
|
115
|
+
// Retomar timer
|
|
116
|
+
const resume = useCallback(() => {
|
|
117
|
+
if (!isPaused)
|
|
118
|
+
return;
|
|
119
|
+
start();
|
|
120
|
+
}, [isPaused, start]);
|
|
121
|
+
// Resetar timer
|
|
122
|
+
const reset = useCallback(() => {
|
|
123
|
+
clearTimerInterval();
|
|
124
|
+
setTime(initialTime);
|
|
125
|
+
setIsRunning(false);
|
|
126
|
+
setIsPaused(false);
|
|
127
|
+
pausedTimeRef.current = 0;
|
|
128
|
+
startTimeRef.current = null;
|
|
129
|
+
onReset?.();
|
|
130
|
+
}, [initialTime, onReset, clearTimerInterval]);
|
|
131
|
+
return {
|
|
132
|
+
time,
|
|
133
|
+
formattedTime,
|
|
134
|
+
isRunning,
|
|
135
|
+
isPaused,
|
|
136
|
+
isStopped: !isRunning && !isPaused,
|
|
137
|
+
start,
|
|
138
|
+
pause,
|
|
139
|
+
stop,
|
|
140
|
+
resume,
|
|
141
|
+
reset,
|
|
142
|
+
};
|
|
143
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,15 @@
|
|
|
4
4
|
* Biblioteca de hooks headless e lógica reutilizável
|
|
5
5
|
* para projetos React/TypeScript
|
|
6
6
|
*/
|
|
7
|
+
export * from "./hooks/useAnimatedIndicator";
|
|
8
|
+
export * from "./hooks/useGenealogy";
|
|
9
|
+
export * from "./hooks/useMoblile";
|
|
10
|
+
export * from "./hooks/useProjectProgress";
|
|
11
|
+
export * from "./hooks/useProjectStats";
|
|
7
12
|
export * from "./hooks/useReactTableBack";
|
|
8
13
|
export * from "./hooks/useReactTableFront";
|
|
9
|
-
export * from "./hooks/useStatCard/useStatCard";
|
|
10
14
|
export * from "./hooks/useResizable";
|
|
11
|
-
export * from "./hooks/
|
|
15
|
+
export * from "./hooks/useScriptEditor";
|
|
16
|
+
export * from "./hooks/useStatCard";
|
|
17
|
+
export * from "./hooks/useTimeTracker";
|
|
12
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AAErC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC"}
|