svelte-log-view 6.4.1 → 7.0.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/package.json +2 -2
- package/src/LogView.svelte +65 -45
- package/src/log.css +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-log-view",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"playwright": "^1.57.0",
|
|
52
52
|
"reader-line-iterator": "^1.2.3",
|
|
53
53
|
"semantic-release": "^25.0.2",
|
|
54
|
-
"svelte": "^5.46.
|
|
54
|
+
"svelte": "^5.46.1",
|
|
55
55
|
"vite": "^7.3.0",
|
|
56
56
|
"vite-plugin-compression2": "^2.4.0"
|
|
57
57
|
},
|
package/src/LogView.svelte
CHANGED
|
@@ -2,29 +2,40 @@
|
|
|
2
2
|
import { onDestroy } from "svelte";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* line 1 |
|
|
6
|
-
* line 2 | ->
|
|
7
|
-
* ----------
|
|
8
|
-
* | line 4 | |
|
|
9
|
-
* | line 5 | | ->
|
|
10
|
-
* | line 5 | |
|
|
11
|
-
* ----------
|
|
12
|
-
* line 6
|
|
5
|
+
* line 1 | \
|
|
6
|
+
* line 2 | -> offsetEntries. |
|
|
7
|
+
* ---------- |
|
|
8
|
+
* | line 4 | | |
|
|
9
|
+
* | line 5 | | -> numberOfVisibleEntries. | -> maxBufferedEntries
|
|
10
|
+
* | line 5 | | |
|
|
11
|
+
* ---------- |
|
|
12
|
+
* line 6 /
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
let {
|
|
16
|
-
source
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
source /** data source */,
|
|
17
|
+
entries = $bindable([]),
|
|
18
|
+
offsetEntries = $bindable(
|
|
19
|
+
0
|
|
20
|
+
) /** number of entries from the top to the 1st. visible */,
|
|
19
21
|
follow = $bindable(true),
|
|
20
22
|
selected = $bindable(0),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
numberOfEntriesToFetch = 10 /** number of entries to fetch if we reach outside of the buffered area */,
|
|
24
|
+
maxBufferedEntries = 1024,
|
|
25
|
+
entryElement
|
|
23
26
|
} = $props();
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
+
let contentHeight = $state();
|
|
29
|
+
let numberOfVisibleEntries = $derived.by(() => {
|
|
30
|
+
console.log("contentHeight",contentHeight);
|
|
31
|
+
const n = Math.ceil(contentHeight / entryHeight);
|
|
32
|
+
return n;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
let visibleEntries = $derived.by(() => {
|
|
36
|
+
return entries.slice(offsetEntries, offsetEntries + numberOfVisibleEntries);
|
|
37
|
+
});
|
|
38
|
+
let entryHeight = 19.13;
|
|
28
39
|
|
|
29
40
|
onDestroy(() => source.abort());
|
|
30
41
|
|
|
@@ -43,14 +54,9 @@
|
|
|
43
54
|
for await (const entry of source.fetch(current)) {
|
|
44
55
|
entries.push(entry);
|
|
45
56
|
|
|
46
|
-
if (entries.
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
if (!follow) {
|
|
50
|
-
visible = entries.slice(offsetRows, visibleRows);
|
|
51
|
-
}
|
|
57
|
+
if (entries.lenght >= maxBufferedEntries) {
|
|
58
|
+
entries.shift();
|
|
52
59
|
}
|
|
53
|
-
|
|
54
60
|
if (follow) {
|
|
55
61
|
setSelected(entries.length - 1);
|
|
56
62
|
current = entries[entries.length - 1];
|
|
@@ -64,31 +70,42 @@
|
|
|
64
70
|
|
|
65
71
|
if (selected > entries.length - 1) {
|
|
66
72
|
selected = entries.length - 1;
|
|
67
|
-
|
|
73
|
+
offsetEntries = entries.length - numberOfVisibleEntries;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
if (selected < 0) {
|
|
71
77
|
const additionalEntries = [];
|
|
72
78
|
|
|
73
|
-
for await (const entry of source.fetch(
|
|
79
|
+
for await (const entry of source.fetch(
|
|
80
|
+
entries[0],
|
|
81
|
+
-numberOfEntriesToFetch,
|
|
82
|
+
numberOfEntriesToFetch
|
|
83
|
+
)) {
|
|
74
84
|
additionalEntries.push(entry);
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
entries.unshift(...additionalEntries);
|
|
78
88
|
|
|
89
|
+
if (entries.lenght >= maxBufferedEntries) {
|
|
90
|
+
entries.length = maxBufferedEntries;
|
|
91
|
+
}
|
|
92
|
+
|
|
79
93
|
selected += additionalEntries.length;
|
|
80
|
-
|
|
94
|
+
offsetEntries += additionalEntries.length;
|
|
81
95
|
}
|
|
82
96
|
|
|
83
|
-
if (selected <
|
|
84
|
-
|
|
97
|
+
if (selected < offsetEntries) {
|
|
98
|
+
offsetEntries = selected;
|
|
85
99
|
}
|
|
86
100
|
|
|
87
|
-
if (selected >=
|
|
88
|
-
|
|
101
|
+
if (selected >= offsetEntries + numberOfVisibleEntries) {
|
|
102
|
+
offsetEntries = selected - numberOfVisibleEntries + 1;
|
|
89
103
|
}
|
|
90
104
|
|
|
91
|
-
|
|
105
|
+
visibleEntries = entries.slice(
|
|
106
|
+
offsetEntries,
|
|
107
|
+
offsetEntries + numberOfVisibleEntries
|
|
108
|
+
);
|
|
92
109
|
}
|
|
93
110
|
|
|
94
111
|
function setFollow(flag) {
|
|
@@ -114,21 +131,21 @@
|
|
|
114
131
|
break;
|
|
115
132
|
case "PageUp":
|
|
116
133
|
setFollow(false);
|
|
117
|
-
setSelected(selected -
|
|
134
|
+
setSelected(selected - numberOfVisibleEntries);
|
|
118
135
|
break;
|
|
119
136
|
case "PageDown":
|
|
120
137
|
setFollow(false);
|
|
121
|
-
setSelected(selected +
|
|
122
|
-
break;
|
|
123
|
-
case "End":
|
|
124
|
-
case "G":
|
|
125
|
-
setFollow(false);
|
|
126
|
-
setSelected(entries.length - 1);
|
|
138
|
+
setSelected(selected + numberOfVisibleEntries);
|
|
127
139
|
break;
|
|
128
140
|
case "Home":
|
|
129
141
|
case "g":
|
|
130
142
|
setFollow(false);
|
|
131
|
-
setSelected(
|
|
143
|
+
setSelected(Number.MIN_SAFE_INTEGER + 1);
|
|
144
|
+
break;
|
|
145
|
+
case "End":
|
|
146
|
+
case "G":
|
|
147
|
+
setFollow(false);
|
|
148
|
+
setSelected(Number.MAX_SAFE_INTEGER - 1);
|
|
132
149
|
break;
|
|
133
150
|
case "f":
|
|
134
151
|
setFollow(!follow);
|
|
@@ -138,15 +155,18 @@
|
|
|
138
155
|
|
|
139
156
|
function onclick(event) {
|
|
140
157
|
setFollow(false);
|
|
141
|
-
|
|
142
|
-
const rowHeight = totalHeight / visibleRows;
|
|
143
|
-
setSelected(offsetRows + Math.floor(event.clientY / rowHeight));
|
|
158
|
+
setSelected(offsetEntries + Math.floor(event.clientY / entryHeight));
|
|
144
159
|
}
|
|
145
160
|
</script>
|
|
146
161
|
|
|
147
162
|
<svelte:window {onkeydown} />
|
|
148
|
-
<log-content
|
|
149
|
-
{
|
|
150
|
-
|
|
163
|
+
<log-content
|
|
164
|
+
{onclick}
|
|
165
|
+
{onkeydown}
|
|
166
|
+
bind:clientHeight={contentHeight}
|
|
167
|
+
role="presentation"
|
|
168
|
+
>
|
|
169
|
+
{#each visibleEntries as entry, i (i)}
|
|
170
|
+
{@render entryElement(entry, selected, offsetEntries + i, follow)}
|
|
151
171
|
{/each}
|
|
152
172
|
</log-content>
|