A simple, versatile, and quick debug UI.
npm i dbgui
script src="https://cdn.jsdelivr.net/npm/dbgui/dist/dbgui.min.js">gt;script>gt; dbgui() and associated functions are automatically injected into window, so no other setup is required.
// The UI automatically gets created and appended to DOM,
// and dbgui() returns a singleton interface to it
// dbgui operates on a simple key-value system,
// sort of like a hashmap.
dbgui()
// .add creates a new entry in the UI.
// $button creates a widget, which is an interactive input that may be used to interface with your code.
.add("Key", $button("Widget"))
// Keys are unique and are automatically sorted in the UI
.add("Key", $input()) // This replaces the button created above with a text input widget.
.add("J", null) // This creates a new entry in the UI before Key, since J is less than K in ASCII/Unicode
.add("Key", null) // a null widget simply removes the entry from the UI (if it exists). The UI is now empty.
// To interface with your code, widgets have event listeners that can accept callbacks:
.add(
"Button",
$button("Click me!")
.onClick(() =>gt; {
alert("Hi!");
})
);
// Note how everything is chainable, which means you can do this:
.add(
"Button",
$button("Click me!")
.onClick(() =>gt; { alert("Hi!") })
.onClick(() =>gt; { alert("Hey!") })
.onClick(() =>gt; { alert("Hello!") })
// clicking this would now spawn 3 alerts
)
// similarly, text inputs also have events:
.add("Text Input", $text()/* $text is an alias of $input */
// onChange callback gets called when the text content changes (from typing, deleting, pasting, etc.)
.onChange((value) =>gt; {
console.log("User changed the text input's value to be: " + value);
})
// onInput callback gets called when Enter key gets pressed
.onInput((value) =>gt; {
console.log("User submitted: " + value);
})
)
// To help with grouping and organization, there are also categories:
dbgui().in("Example Category")
// and the API is still the exact same!
.add("Key", $button("Widget").onClick(() =>gt; {
// category names are also unique, so you can
// freely replace components in categories as well
dbgui().in("Example Category").add("Key", $text());
}));
// $slider/$range creates a slider input
// which accepts a min, max, and step value.
// Also has .onInput() and .onChange() events
.add("Abc", $slider(0, 100, 1));
.add("Remove Abc", $button("Remove")
.onClick(() =>gt; {
// dbgui().addIn(category, key, widget)
// is shorthand for
// dbgui().in(category).add(key, widget)
dbgui().addIn("Example Category", "Abc", null); // removes Abc
})
)
// note that sub-categories are not supported: `dbgui().in("A").in("B")` does not work
// There's a bit more widgets that we offer, but that's it!Visit the website for more live demonstrations.
All methods are chainable and return this.
| Widget | Parameters | Methods | Info |
|---|---|---|---|
$button |
(buttonText: string) |
.onClick(() => void)id) |
|
$input, $text |
(textGetter: (() => string) | undefined)ed) |
.onChange((newValue: string) => void)id), .onInput((value: string) => void)id) |
Accepts a text getter that is automatically polled to be set as the input value. |
$range, $slider |
(numGetter: (() => number) | undefined)ed) |
.onChange((newValue: number) => void)id), .onInput((value: number) => void)id) |
Accepts a number getter that is automatically polled to be set as the input value. |
$valueDisplay |
|
withPollInterval(pollInterval: number | "manual"),withStringifyFunction(stringifyFunction: (val: T) => string)ng) |
Displays a single value that can either be automatically or manually polled. The default stringify function is Object.toString() |
$group |
(...childrenWidgets: Widgets[]) |
withDir(direction: "row" | "column") |
Allows you to have multiple widgets in one UI entry. |