@zikojs/console 0.2.0 → 0.3.0
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 +1 -1
- package/src/components/ConsoleFeed.js +9 -11
- package/src/components/index.js +0 -2
- package/src/index.css +4 -117
- package/src/index.js +3 -44
- package/src/components/ConsolePrompt.js +0 -42
- package/src/components/ConsoleToolbar.js +0 -48
package/package.json
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { tags } from 'ziko/dom'
|
|
2
|
+
|
|
3
|
+
const { div } = tags;
|
|
3
4
|
|
|
4
5
|
import { isProps } from "../utils/index.js";
|
|
5
6
|
import { Hook } from "../hook/index.js";
|
|
6
7
|
import { createFeed } from "../feed/index.js";
|
|
7
8
|
import { nodeEntry } from "./nodeEntry.js";
|
|
8
9
|
import { cache } from "./Row.js";
|
|
9
|
-
import { ConsoleToolbar } from "./ConsoleToolbar.js";
|
|
10
10
|
import { ConsoleBody } from "./ConsoleBody.js";
|
|
11
|
-
import { ConsolePrompt } from "./ConsolePrompt.js";
|
|
12
11
|
|
|
13
12
|
export function ConsoleFeed(...args) {
|
|
14
13
|
const [props, ...kids] = isProps(args[0]) ? args : [{}, ...args];
|
|
15
14
|
const feed = props.feed || createFeed(1000, cache);
|
|
16
15
|
const {
|
|
17
16
|
variant = "dark",
|
|
18
|
-
repl = true,
|
|
19
17
|
hook = false,
|
|
20
18
|
} = props;
|
|
21
19
|
|
|
@@ -28,16 +26,16 @@ export function ConsoleFeed(...args) {
|
|
|
28
26
|
const initialTheme = typeof variant === "string" ? variant : (variant.val || "dark");
|
|
29
27
|
feed.setTheme(initialTheme);
|
|
30
28
|
|
|
31
|
-
const bar = ConsoleToolbar(feed);
|
|
32
29
|
const body = ConsoleBody(feed);
|
|
33
|
-
const prompt = repl ? ConsolePrompt(feed) : "";
|
|
34
30
|
|
|
35
31
|
const container = div(
|
|
36
|
-
{ class:
|
|
37
|
-
bar,
|
|
32
|
+
{ class: "cf " + feed.theme },
|
|
33
|
+
// bar,
|
|
38
34
|
body,
|
|
39
|
-
prompt,
|
|
40
|
-
)
|
|
35
|
+
// prompt,
|
|
36
|
+
).style({
|
|
37
|
+
flex : 1
|
|
38
|
+
});
|
|
41
39
|
|
|
42
40
|
feed.addEventListener("theme-change", (e) => {
|
|
43
41
|
container.className = "cf " + e.detail + " flex:1";
|
package/src/components/index.js
CHANGED
package/src/index.css
CHANGED
|
@@ -15,67 +15,15 @@ body {
|
|
|
15
15
|
display: flex;
|
|
16
16
|
flex-direction: column;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
padding: 14px 20px 4px;
|
|
20
|
-
}
|
|
21
|
-
header h1 {
|
|
22
|
-
margin: 0;
|
|
23
|
-
font-size: 17px;
|
|
24
|
-
font-weight: 650;
|
|
25
|
-
}
|
|
26
|
-
header p {
|
|
27
|
-
margin: 2px 0 0;
|
|
28
|
-
color: #5c6578;
|
|
29
|
-
font-size: 13px;
|
|
30
|
-
}
|
|
31
|
-
main {
|
|
32
|
-
flex: 1;
|
|
33
|
-
min-height: 0;
|
|
34
|
-
display: grid;
|
|
35
|
-
grid-template-columns: 230px 1fr;
|
|
36
|
-
gap: 14px;
|
|
37
|
-
padding: 12px 20px 20px;
|
|
38
|
-
}
|
|
18
|
+
|
|
39
19
|
@media (max-width: 720px) {
|
|
40
20
|
main {
|
|
41
21
|
grid-template-columns: 1fr;
|
|
42
22
|
grid-template-rows: auto 1fr;
|
|
43
23
|
}
|
|
44
24
|
}
|
|
45
|
-
aside {
|
|
46
|
-
display: flex;
|
|
47
|
-
flex-wrap: wrap;
|
|
48
|
-
align-content: flex-start;
|
|
49
|
-
gap: 6px;
|
|
50
|
-
}
|
|
51
|
-
aside h2 {
|
|
52
|
-
width: 100%;
|
|
53
|
-
margin: 6px 0 0;
|
|
54
|
-
font-size: 12px;
|
|
55
|
-
font-weight: 600;
|
|
56
|
-
color: #5c6578;
|
|
57
|
-
}
|
|
58
|
-
aside button {
|
|
59
|
-
font: inherit;
|
|
60
|
-
font-size: 13px;
|
|
61
|
-
padding: 5px 10px;
|
|
62
|
-
border: 1px solid #c9cedb;
|
|
63
|
-
background: #f6f7fa;
|
|
64
|
-
color: inherit;
|
|
65
|
-
border-radius: 5px;
|
|
66
|
-
cursor: pointer;
|
|
67
|
-
}
|
|
68
|
-
aside button:hover {
|
|
69
|
-
background: #fff;
|
|
70
|
-
border-color: #8a93a8;
|
|
71
|
-
}
|
|
72
|
-
button:focus-visible,
|
|
73
|
-
input:focus-visible {
|
|
74
|
-
outline: 2px solid #3b82f6;
|
|
75
|
-
outline-offset: 1px;
|
|
76
|
-
}
|
|
77
25
|
|
|
78
|
-
/* ---------- Console
|
|
26
|
+
/* ---------- Console feed ---------- */
|
|
79
27
|
.cf {
|
|
80
28
|
--bg: #171b24;
|
|
81
29
|
--bar: #1e2330;
|
|
@@ -119,49 +67,7 @@ input:focus-visible {
|
|
|
119
67
|
--err-fg: #b3261e;
|
|
120
68
|
--hover: #f3f5f9;
|
|
121
69
|
}
|
|
122
|
-
|
|
123
|
-
display: flex;
|
|
124
|
-
gap: 6px;
|
|
125
|
-
align-items: center;
|
|
126
|
-
padding: 6px 8px;
|
|
127
|
-
background: var(--bar);
|
|
128
|
-
border-bottom: 1px solid var(--line);
|
|
129
|
-
flex-wrap: wrap;
|
|
130
|
-
}
|
|
131
|
-
.cf-bar input {
|
|
132
|
-
flex: 1;
|
|
133
|
-
min-width: 120px;
|
|
134
|
-
font: inherit;
|
|
135
|
-
background: var(--bg);
|
|
136
|
-
color: var(--fg);
|
|
137
|
-
border: 1px solid var(--line);
|
|
138
|
-
border-radius: 4px;
|
|
139
|
-
padding: 3px 8px;
|
|
140
|
-
}
|
|
141
|
-
.cf-bar button {
|
|
142
|
-
font: inherit;
|
|
143
|
-
background: none;
|
|
144
|
-
color: var(--dim);
|
|
145
|
-
border: 1px solid transparent;
|
|
146
|
-
border-radius: 4px;
|
|
147
|
-
padding: 2px 8px;
|
|
148
|
-
cursor: pointer;
|
|
149
|
-
}
|
|
150
|
-
.cf-bar button:hover {
|
|
151
|
-
color: var(--fg);
|
|
152
|
-
border-color: var(--line);
|
|
153
|
-
}
|
|
154
|
-
.cf-bar button.cf-chip.on {
|
|
155
|
-
color: var(--fg);
|
|
156
|
-
border-color: var(--line);
|
|
157
|
-
background: var(--bg);
|
|
158
|
-
}
|
|
159
|
-
.cf-chip.warn.on {
|
|
160
|
-
color: var(--warn-fg) !important;
|
|
161
|
-
}
|
|
162
|
-
.cf-chip.error.on {
|
|
163
|
-
color: var(--err-fg) !important;
|
|
164
|
-
}
|
|
70
|
+
|
|
165
71
|
.cf-body {
|
|
166
72
|
flex: 1;
|
|
167
73
|
overflow: auto;
|
|
@@ -288,23 +194,4 @@ input:focus-visible {
|
|
|
288
194
|
.cf-table th {
|
|
289
195
|
background: var(--bar);
|
|
290
196
|
font-weight: 600;
|
|
291
|
-
}
|
|
292
|
-
.cf-prompt {
|
|
293
|
-
display: flex;
|
|
294
|
-
align-items: center;
|
|
295
|
-
gap: 8px;
|
|
296
|
-
padding: 5px 10px;
|
|
297
|
-
border-top: 1px solid var(--line);
|
|
298
|
-
background: var(--bar);
|
|
299
|
-
}
|
|
300
|
-
.cf-prompt span {
|
|
301
|
-
color: var(--key);
|
|
302
|
-
}
|
|
303
|
-
.cf-prompt input {
|
|
304
|
-
flex: 1;
|
|
305
|
-
font: inherit;
|
|
306
|
-
background: none;
|
|
307
|
-
border: 0;
|
|
308
|
-
color: var(--fg);
|
|
309
|
-
outline: 0;
|
|
310
|
-
}
|
|
197
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,45 +1,4 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.assign(window, {
|
|
7
|
-
ConsoleFeed: { Hook, createFeed, ConsoleFeed, Console },
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
/* =====================================================================
|
|
11
|
-
Demo
|
|
12
|
-
===================================================================== */
|
|
13
|
-
|
|
14
|
-
Console.theme = 'light';
|
|
15
|
-
|
|
16
|
-
// 1) Declarative
|
|
17
|
-
// document.body.append(
|
|
18
|
-
// ConsoleFeed(
|
|
19
|
-
// { variant: theme.val, repl: false },
|
|
20
|
-
// Console.log("Hello from VanJS", 42, true, null, undefined),
|
|
21
|
-
// Console.info("Server listening on :3000"),
|
|
22
|
-
// Console.group("Request"),
|
|
23
|
-
// Console.log("parsing"),
|
|
24
|
-
// Console.warn("token expires soon"),
|
|
25
|
-
// Console.groupEnd(),
|
|
26
|
-
// Console.error(new Error("Something broke")),
|
|
27
|
-
// Console.table([
|
|
28
|
-
// { id: 1, name: "Ada" },
|
|
29
|
-
// { id: 2, name: "Linus" },
|
|
30
|
-
// ]),
|
|
31
|
-
// ),
|
|
32
|
-
// );
|
|
33
|
-
|
|
34
|
-
// 2) Standalone
|
|
35
|
-
document.body.append(Console.log("Just one line", { a: 1, b: 1 }));
|
|
36
|
-
document.body.append(Console.warn("Standalone warning"));
|
|
37
|
-
document.body.append(Console.table([1, 2, 3]));
|
|
38
|
-
|
|
39
|
-
// 3) Live
|
|
40
|
-
// const feed = createFeed();
|
|
41
|
-
// Hook(console, (e) => feed.push(e));
|
|
42
|
-
// globalThis.c = ConsoleFeed({ feed, variant: theme.val });
|
|
43
|
-
// document.body.append(c);
|
|
44
|
-
|
|
45
|
-
// console.log("Hello from VanJS", 42, true, null, undefined);
|
|
2
|
+
export { Hook } from "./hook/index.js";
|
|
3
|
+
export { createFeed } from "./feed/index.js";
|
|
4
|
+
export { ConsoleFeed, Console } from "./components/index.js";
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import van from "https://cdn.jsdelivr.net/npm/vanjs-core@1.5.3/src/van.js";
|
|
2
|
-
const { div, span, input } = van.tags;
|
|
3
|
-
|
|
4
|
-
export function ConsolePrompt(feed) {
|
|
5
|
-
const hist = [];
|
|
6
|
-
let hi = 0;
|
|
7
|
-
|
|
8
|
-
const run = (code) => {
|
|
9
|
-
feed.push({ method: "command", args: [code] });
|
|
10
|
-
try {
|
|
11
|
-
feed.push({ method: "result", args: [(0, eval)(code)] });
|
|
12
|
-
} catch (err) {
|
|
13
|
-
feed.push({ method: "error", args: [err] });
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return div(
|
|
18
|
-
{ class: "cf-prompt" },
|
|
19
|
-
span("\u203A"),
|
|
20
|
-
input({
|
|
21
|
-
placeholder: "Run JavaScript",
|
|
22
|
-
"aria-label": "Run JavaScript",
|
|
23
|
-
spellcheck: false,
|
|
24
|
-
autocomplete: "off",
|
|
25
|
-
onkeydown: (e) => {
|
|
26
|
-
const el = e.target;
|
|
27
|
-
if (e.key === "Enter" && el.value.trim()) {
|
|
28
|
-
hist.push(el.value);
|
|
29
|
-
hi = hist.length;
|
|
30
|
-
run(el.value);
|
|
31
|
-
el.value = "";
|
|
32
|
-
} else if (e.key === "ArrowUp" && hi > 0) {
|
|
33
|
-
el.value = hist[--hi];
|
|
34
|
-
e.preventDefault();
|
|
35
|
-
} else if (e.key === "ArrowDown") {
|
|
36
|
-
el.value =
|
|
37
|
-
hi < hist.length - 1 ? hist[++hi] : ((hi = hist.length), "");
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
}),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import van from "https://cdn.jsdelivr.net/npm/vanjs-core@1.5.3/src/van.js";
|
|
2
|
-
const { div, span, input, button } = van.tags;
|
|
3
|
-
import { LEVELS } from "../utils/index.js";
|
|
4
|
-
|
|
5
|
-
export function ConsoleToolbar(feed) {
|
|
6
|
-
const chipButtons = {};
|
|
7
|
-
const countSpans = {};
|
|
8
|
-
|
|
9
|
-
const updateToolbar = () => {
|
|
10
|
-
LEVELS.forEach((l) => {
|
|
11
|
-
if (chipButtons[l]) {
|
|
12
|
-
const isOn = feed.levels[l];
|
|
13
|
-
chipButtons[l].className = `cf-chip ${l}` + (isOn ? " on" : "");
|
|
14
|
-
chipButtons[l].setAttribute("aria-pressed", isOn);
|
|
15
|
-
}
|
|
16
|
-
if (countSpans[l]) {
|
|
17
|
-
countSpans[l].textContent = feed.getCount(l);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
feed.addEventListener("filter-change", updateToolbar);
|
|
23
|
-
|
|
24
|
-
return div(
|
|
25
|
-
{ class: "cf-bar" },
|
|
26
|
-
LEVELS.map((l) => {
|
|
27
|
-
countSpans[l] = span(feed.getCount(l));
|
|
28
|
-
chipButtons[l] = button(
|
|
29
|
-
{
|
|
30
|
-
class: `cf-chip ${l}` + (feed.levels[l] ? " on" : ""),
|
|
31
|
-
"aria-pressed": feed.levels[l],
|
|
32
|
-
onclick: () => feed.toggleLevel(l),
|
|
33
|
-
},
|
|
34
|
-
l,
|
|
35
|
-
" ",
|
|
36
|
-
countSpans[l],
|
|
37
|
-
);
|
|
38
|
-
return chipButtons[l];
|
|
39
|
-
}),
|
|
40
|
-
input({
|
|
41
|
-
type: "search",
|
|
42
|
-
placeholder: "Filter messages",
|
|
43
|
-
"aria-label": "Filter messages",
|
|
44
|
-
oninput: (e) => feed.setQuery(e.target.value),
|
|
45
|
-
}),
|
|
46
|
-
button({ onclick: () => feed.clear() }, "Clear"),
|
|
47
|
-
);
|
|
48
|
-
}
|