streamator-react 0.1.0 → 0.1.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 +93 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# streamator-react
|
|
2
|
+
|
|
3
|
+
Frontend primitives for displaying live log streams in React. Handles SSE connection,
|
|
4
|
+
entry formatting, auto-scroll, and rendering.
|
|
5
|
+
|
|
6
|
+
Pairs with [`streamator`](https://pypi.org/project/streamator/) on the backend.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install streamator-react
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```jsx
|
|
17
|
+
import { useLogStream, LogPanel } from "streamator-react"
|
|
18
|
+
import "streamator-react/log.css"
|
|
19
|
+
|
|
20
|
+
const { logs, active } = useLogStream(`/api/log/${jobId}/stream`)
|
|
21
|
+
|
|
22
|
+
<LogPanel logs={logs} active={active} />
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## `useLogStream(url, options)`
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
const { logs, active } = useLogStream(url, {
|
|
29
|
+
mode: "sse", // "sse" (default) | "poll"
|
|
30
|
+
interval: 3000, // poll interval ms — poll mode only
|
|
31
|
+
formatEvent: fn, // (rawEvent) => string | null
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- `logs` — `Array<{ text, t, level }>` — ready to render
|
|
36
|
+
- `active` — `true` while stream is open / polling
|
|
37
|
+
- Passing `null` or `undefined` as `url` is a no-op
|
|
38
|
+
|
|
39
|
+
## `LogPanel` props
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
<LogPanel
|
|
43
|
+
logs={logs}
|
|
44
|
+
active={active}
|
|
45
|
+
waitingText="⏳ Starting…" // shown while active but no logs yet
|
|
46
|
+
maxHeight="200px" // default: 160px
|
|
47
|
+
className="my-log" // appended to root class
|
|
48
|
+
style={{}}
|
|
49
|
+
renderEntry={(entry, i) => <div />} // fully custom row renderer
|
|
50
|
+
/>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Returns `null` when not active and no logs. Auto-scrolls to latest entry.
|
|
54
|
+
|
|
55
|
+
## `makeFormatEvent(overrides)`
|
|
56
|
+
|
|
57
|
+
Map structured backend events to display strings:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { makeFormatEvent } from "streamator-react"
|
|
61
|
+
|
|
62
|
+
const formatEvent = makeFormatEvent({
|
|
63
|
+
scraping: e => `🔍 Scraping ${e.url}`,
|
|
64
|
+
done: () => `✅ Finished`,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const { logs } = useLogStream(url, { formatEvent })
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Return `null` from a handler to suppress that entry entirely.
|
|
71
|
+
|
|
72
|
+
## Styling
|
|
73
|
+
|
|
74
|
+
Default styles via CSS custom properties — override any of them:
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
--streamator-bg: #f8f8f8;
|
|
78
|
+
--streamator-border: #e0e0e0;
|
|
79
|
+
--streamator-color: #444;
|
|
80
|
+
--streamator-time-color: #aaa;
|
|
81
|
+
--streamator-radius: 6px;
|
|
82
|
+
--streamator-font-size: 0.8rem;
|
|
83
|
+
--streamator-max-height: 160px;
|
|
84
|
+
--streamator-success-color: #2e7d32;
|
|
85
|
+
--streamator-warning-color: #f59e0b;
|
|
86
|
+
--streamator-error-color: #c62828;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Migrating from old `.log` / `.log-time` / `.log-waiting` class names?
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
import "streamator-react/log-compat.css"
|
|
93
|
+
```
|