@promptctl/rich-js 0.28.0 → 0.29.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/README.md +7 -7
- package/dist/core/animation.d.ts +37 -37
- package/dist/core/animation.js +61 -61
- package/dist/core/ansi.d.ts +4 -4
- package/dist/core/ansi.js +9 -9
- package/dist/core/bidi.js +6 -6
- package/dist/core/cells.d.ts +1 -1
- package/dist/core/cells.js +5 -5
- package/dist/core/clock.d.ts +1 -1
- package/dist/core/color.d.ts +50 -50
- package/dist/core/color.js +69 -69
- package/dist/core/console.d.ts +8 -8
- package/dist/core/console.js +5 -5
- package/dist/core/control-codes.d.ts +3 -3
- package/dist/core/control-codes.js +7 -7
- package/dist/core/easing.d.ts +40 -40
- package/dist/core/easing.js +40 -40
- package/dist/core/env.d.ts +1 -1
- package/dist/core/env.js +1 -1
- package/dist/core/export-html.js +1 -1
- package/dist/core/export-lines.d.ts +11 -11
- package/dist/core/export-lines.js +12 -12
- package/dist/core/export-svg.d.ts +3 -3
- package/dist/core/export-svg.js +4 -4
- package/dist/core/markup.js +1 -1
- package/dist/core/memo.d.ts +1 -1
- package/dist/core/memo.js +1 -1
- package/dist/core/oklch.d.ts +14 -14
- package/dist/core/oklch.js +10 -10
- package/dist/core/orient.d.ts +3 -3
- package/dist/core/orient.js +3 -3
- package/dist/core/paint.d.ts +9 -9
- package/dist/core/paint.js +3 -3
- package/dist/core/pretty.d.ts +1 -1
- package/dist/core/pretty.js +3 -3
- package/dist/core/protocol.d.ts +26 -26
- package/dist/core/protocol.js +22 -22
- package/dist/core/render.d.ts +11 -11
- package/dist/core/render.js +12 -12
- package/dist/core/segment.d.ts +3 -3
- package/dist/core/segment.js +5 -5
- package/dist/core/strip.d.ts +83 -83
- package/dist/core/strip.js +70 -70
- package/dist/core/style.d.ts +20 -20
- package/dist/core/style.js +55 -55
- package/dist/core/text.d.ts +2 -2
- package/dist/core/text.js +5 -5
- package/dist/core/timeline.d.ts +5 -5
- package/dist/core/timeline.js +9 -9
- package/dist/core/tween.d.ts +6 -6
- package/dist/core/tween.js +10 -10
- package/dist/core/view.d.ts +4 -4
- package/dist/core/view.js +12 -12
- package/dist/host/app.d.ts +9 -9
- package/dist/host/app.js +12 -12
- package/dist/host/host-environment.d.ts +2 -2
- package/dist/host/host-environment.js +2 -2
- package/dist/host/index.d.ts +2 -2
- package/dist/host/input.d.ts +7 -7
- package/dist/host/input.js +4 -4
- package/dist/host/terminal-colors.d.ts +2 -2
- package/dist/host/terminal-colors.js +4 -4
- package/dist/host/terminal-host.d.ts +2 -2
- package/dist/host/terminal-host.js +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +10 -10
- package/dist/node/prompt.d.ts +1 -1
- package/dist/node/prompt.js +1 -1
- package/dist/node/terminal-host.d.ts +1 -1
- package/dist/node/traceback.js +2 -2
- package/dist/renderables/change.js +2 -2
- package/dist/renderables/effect.d.ts +39 -39
- package/dist/renderables/effect.js +45 -45
- package/dist/renderables/effects.d.ts +81 -81
- package/dist/renderables/effects.js +157 -157
- package/dist/renderables/embed.d.ts +1 -1
- package/dist/renderables/embed.js +2 -2
- package/dist/renderables/flexStrip.d.ts +7 -7
- package/dist/renderables/flexStrip.js +15 -15
- package/dist/renderables/frames.d.ts +6 -6
- package/dist/renderables/frames.js +11 -11
- package/dist/renderables/glyph-effect.d.ts +15 -15
- package/dist/renderables/glyph-effect.js +17 -17
- package/dist/renderables/glyph-effects.d.ts +7 -7
- package/dist/renderables/glyph-effects.js +16 -16
- package/dist/renderables/html-entities.d.ts +1 -1
- package/dist/renderables/html-entities.js +1 -1
- package/dist/renderables/lifecycle.d.ts +4 -4
- package/dist/renderables/lifecycle.js +12 -12
- package/dist/renderables/live.d.ts +2 -2
- package/dist/renderables/live.js +7 -7
- package/dist/renderables/markdown-parse.js +3 -3
- package/dist/renderables/panel.js +3 -3
- package/dist/renderables/progress.d.ts +1 -1
- package/dist/renderables/progress.js +1 -1
- package/dist/renderables/progressBar.d.ts +1 -1
- package/dist/renderables/progressBar.js +6 -6
- package/dist/renderables/prompt.d.ts +1 -1
- package/dist/renderables/scroll.d.ts +1 -1
- package/dist/renderables/scroll.js +3 -3
- package/dist/renderables/spinner.d.ts +4 -4
- package/dist/renderables/spinner.js +10 -10
- package/dist/renderables/syntax.d.ts +2 -2
- package/dist/renderables/syntax.js +2 -2
- package/dist/renderables/table.js +3 -3
- package/dist/renderables/traceback.d.ts +1 -1
- package/dist/renderables/traceback.js +1 -1
- package/dist/renderables/tree.js +3 -3
- package/dist/template-bindings/animation-funcs.d.ts +14 -14
- package/dist/template-bindings/animation-funcs.js +27 -27
- package/dist/template-bindings/color-funcs.d.ts +14 -14
- package/dist/template-bindings/color-funcs.js +25 -25
- package/dist/template-bindings/index.d.ts +9 -9
- package/dist/template-bindings/index.js +9 -9
- package/dist/template-bindings/palette-funcs.d.ts +1 -1
- package/dist/template-bindings/palette-funcs.js +3 -3
- package/dist/template-bindings/style-funcs.d.ts +5 -5
- package/dist/template-bindings/style-funcs.js +16 -16
- package/dist/themes/{transpose.d.ts → adjust.d.ts} +23 -23
- package/dist/themes/{transpose.js → adjust.js} +28 -28
- package/dist/themes/buildPalette.d.ts +3 -3
- package/dist/themes/buildPalette.js +20 -20
- package/dist/themes/colorMath.d.ts +16 -16
- package/dist/themes/colorMath.js +32 -32
- package/dist/themes/data/ansi-tables.d.ts +2 -2
- package/dist/themes/data/ansi-tables.js +2 -2
- package/dist/themes/data/types.d.ts +4 -4
- package/dist/themes/data/types.js +2 -2
- package/dist/themes/palette.d.ts +12 -12
- package/dist/themes/palette.js +16 -16
- package/dist/themes/ramp.d.ts +17 -17
- package/dist/themes/ramp.js +12 -12
- package/dist/themes/registry.js +4 -4
- package/dist/themes/terminalThemes.d.ts +1 -1
- package/dist/themes/terminalThemes.js +1 -1
- package/dist/widgets/button.d.ts +2 -2
- package/dist/widgets/button.js +4 -4
- package/dist/widgets/checkbox.d.ts +2 -2
- package/dist/widgets/checkbox.js +2 -2
- package/dist/widgets/dropdown.d.ts +2 -2
- package/dist/widgets/dropdown.js +3 -3
- package/dist/widgets/event-router.d.ts +6 -6
- package/dist/widgets/event-router.js +2 -2
- package/dist/widgets/focus-manager.d.ts +3 -3
- package/dist/widgets/focus-manager.js +3 -3
- package/dist/widgets/index.d.ts +2 -2
- package/dist/widgets/index.js +1 -1
- package/dist/widgets/ink.d.ts +3 -3
- package/dist/widgets/ink.js +4 -4
- package/dist/widgets/slider.d.ts +2 -2
- package/dist/widgets/static-item.d.ts +2 -2
- package/dist/widgets/text-input.d.ts +2 -2
- package/dist/widgets/text-input.js +5 -5
- package/dist/widgets/themed-widget.js +1 -1
- package/dist/widgets/toggle.d.ts +3 -3
- package/dist/widgets/toggle.js +3 -3
- package/dist/widgets/types.d.ts +6 -6
- package/dist/widgets/types.js +2 -2
- package/dist/widgets/widget-app.d.ts +10 -10
- package/dist/widgets/widget-app.js +8 -8
- package/dist/widgets/widget-base.d.ts +2 -2
- package/package.json +1 -1
package/dist/widgets/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type { KeyHandlerPriority, KeyHandlerOptions, WidgetMouseEvent, WidgetFocusEvent, InteractiveWidget, OverlayRenderable, FocusManager, } from "./types.js";
|
|
2
|
-
export { hasOverlay,
|
|
2
|
+
export { hasOverlay, WidgetKeyEvent } from "./types.js";
|
|
3
3
|
export { StaticItem } from "./static-item.js";
|
|
4
4
|
export type { StaticItemOptions } from "./static-item.js";
|
|
5
5
|
export { WidgetBase } from "./widget-base.js";
|
|
6
6
|
export { WidgetApp } from "./widget-app.js";
|
|
7
|
-
export type { WidgetAppOptions,
|
|
7
|
+
export type { WidgetAppOptions, WidgetVisibility } from "./widget-app.js";
|
|
8
8
|
export { Button } from "./button.js";
|
|
9
9
|
export type { ButtonVariant, ButtonOptions } from "./button.js";
|
|
10
10
|
export { Checkbox } from "./checkbox.js";
|
package/dist/widgets/index.js
CHANGED
package/dist/widgets/ink.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ink — the
|
|
2
|
+
* ink — the color pair a widget cell is drawn in: a foreground and the ground
|
|
3
3
|
* it stands on, both from one theme's palette.
|
|
4
4
|
*
|
|
5
|
-
* A palette's
|
|
5
|
+
* A palette's colors are chosen against that palette's own background. A
|
|
6
6
|
* foreground drawn over whatever the terminal shows is readable only when the
|
|
7
7
|
* terminal happens to match the theme — the default theme's white text
|
|
8
8
|
* vanished into a light terminal. With both halves taken from the palette, a
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* [LAW:types-are-the-program] There is no call that takes a foreground alone,
|
|
13
13
|
* so a widget cannot draw half a pair.
|
|
14
14
|
* [LAW:single-enforcer] Every widget resolves palette roles here, and this is
|
|
15
|
-
* where one that draws no
|
|
15
|
+
* where one that draws no color (a theme's fully transparent "no background")
|
|
16
16
|
* is reported.
|
|
17
17
|
*/
|
|
18
18
|
import { ColorSpec, type TerminalTheme } from "../core/color.js";
|
package/dist/widgets/ink.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ink — the
|
|
2
|
+
* ink — the color pair a widget cell is drawn in: a foreground and the ground
|
|
3
3
|
* it stands on, both from one theme's palette.
|
|
4
4
|
*
|
|
5
|
-
* A palette's
|
|
5
|
+
* A palette's colors are chosen against that palette's own background. A
|
|
6
6
|
* foreground drawn over whatever the terminal shows is readable only when the
|
|
7
7
|
* terminal happens to match the theme — the default theme's white text
|
|
8
8
|
* vanished into a light terminal. With both halves taken from the palette, a
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* [LAW:types-are-the-program] There is no call that takes a foreground alone,
|
|
13
13
|
* so a widget cannot draw half a pair.
|
|
14
14
|
* [LAW:single-enforcer] Every widget resolves palette roles here, and this is
|
|
15
|
-
* where one that draws no
|
|
15
|
+
* where one that draws no color (a theme's fully transparent "no background")
|
|
16
16
|
* is reported.
|
|
17
17
|
*/
|
|
18
18
|
import { ColorSpec } from "../core/color.js";
|
|
@@ -22,7 +22,7 @@ export function ink(theme, fg, bg) {
|
|
|
22
22
|
function paletteColor(theme, role) {
|
|
23
23
|
const rgba = theme.palette.get(role);
|
|
24
24
|
if (rgba.alpha === 0) {
|
|
25
|
-
throw new RangeError(`palette ${JSON.stringify(theme.palette.name)}: ${JSON.stringify(role)} is fully transparent, so it cannot be half of a widget's
|
|
25
|
+
throw new RangeError(`palette ${JSON.stringify(theme.palette.name)}: ${JSON.stringify(role)} is fully transparent, so it cannot be half of a widget's color pair`);
|
|
26
26
|
}
|
|
27
27
|
return ColorSpec.fromRgba(rgba);
|
|
28
28
|
}
|
package/dist/widgets/slider.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { Segment } from "../core/segment.js";
|
|
|
21
21
|
import { type RenderOptions } from "../core/protocol.js";
|
|
22
22
|
import type { TerminalTheme } from "../core/color.js";
|
|
23
23
|
import { ThemedWidget } from "./themed-widget.js";
|
|
24
|
-
import type {
|
|
24
|
+
import type { WidgetKeyEvent, WidgetMouseEvent } from "./types.js";
|
|
25
25
|
export interface SliderOptions {
|
|
26
26
|
value?: number;
|
|
27
27
|
min?: number;
|
|
@@ -42,7 +42,7 @@ export declare class Slider extends ThemedWidget {
|
|
|
42
42
|
accessor width: number;
|
|
43
43
|
private accessor _dragging;
|
|
44
44
|
constructor(options?: SliderOptions);
|
|
45
|
-
handleKey(event:
|
|
45
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
46
46
|
handleMouse(event: WidgetMouseEvent): void;
|
|
47
47
|
private setValue;
|
|
48
48
|
private setValueFromMouseX;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { Segment } from "../core/segment.js";
|
|
14
14
|
import type { Measurable, Renderable, RenderOptions } from "../core/protocol.js";
|
|
15
15
|
import { WidgetBase } from "./widget-base.js";
|
|
16
|
-
import type {
|
|
16
|
+
import type { WidgetKeyEvent } from "./types.js";
|
|
17
17
|
export interface StaticItemOptions {
|
|
18
18
|
id: string;
|
|
19
19
|
render: Renderable | ((options: RenderOptions) => Iterable<Segment>);
|
|
@@ -25,7 +25,7 @@ export declare class StaticItem extends WidgetBase {
|
|
|
25
25
|
private readonly body;
|
|
26
26
|
private readonly measureFn;
|
|
27
27
|
constructor(options: StaticItemOptions);
|
|
28
|
-
handleKey(_event:
|
|
28
|
+
handleKey(_event: WidgetKeyEvent): void;
|
|
29
29
|
protected draw(options: RenderOptions): Iterable<Segment>;
|
|
30
30
|
measure(options: RenderOptions): {
|
|
31
31
|
minimum: number;
|
|
@@ -68,7 +68,7 @@ import { type CellCol, type CodePoint, type CodeUnit } from "../core/cells.js";
|
|
|
68
68
|
import { type RenderOptions } from "../core/protocol.js";
|
|
69
69
|
import type { TerminalTheme } from "../core/color.js";
|
|
70
70
|
import { ThemedWidget } from "./themed-widget.js";
|
|
71
|
-
import type {
|
|
71
|
+
import type { WidgetKeyEvent, WidgetFocusEvent, WidgetMouseEvent } from "./types.js";
|
|
72
72
|
/**
|
|
73
73
|
* A soft-wrap strategy. Given one logical line of text and cell-width budgets,
|
|
74
74
|
* return the visual sub-rows that line wraps into. The line arrives as the
|
|
@@ -222,7 +222,7 @@ export declare class TextInput extends ThemedWidget {
|
|
|
222
222
|
private readonly _viewport;
|
|
223
223
|
readonly multiline: boolean;
|
|
224
224
|
constructor(options?: TextInputOptions);
|
|
225
|
-
handleKey(event:
|
|
225
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
226
226
|
handleFocus(event: WidgetFocusEvent): void;
|
|
227
227
|
private _edit;
|
|
228
228
|
handleMouse(event: WidgetMouseEvent): void;
|
|
@@ -105,7 +105,7 @@ import { afterPass, drawable, render } from "../core/protocol.js";
|
|
|
105
105
|
import { State } from "../core/state.js";
|
|
106
106
|
import { Viewport } from "../renderables/viewport.js";
|
|
107
107
|
import { Animation } from "../core/animation.js";
|
|
108
|
-
import {
|
|
108
|
+
import { stepSequence } from "../core/easing.js";
|
|
109
109
|
import { Timeline } from "../core/timeline.js";
|
|
110
110
|
import { placed } from "../core/animation.js";
|
|
111
111
|
import { levelOf } from "../core/anchor.js";
|
|
@@ -243,7 +243,7 @@ function wordSpan(clusters, skipped, taken) {
|
|
|
243
243
|
* second, so the caret is solid the moment the field is touched, then dark
|
|
244
244
|
* for the next, on a `beat`. A loop, so with its motion taken out it holds lit.
|
|
245
245
|
*/
|
|
246
|
-
const CARET_BLINK = Animation.map(
|
|
246
|
+
const CARET_BLINK = Animation.map(stepSequence([0.5, 0.5]), (validity) => validity === 0);
|
|
247
247
|
/**
|
|
248
248
|
* The caret's blink restarted at `from`, as one animation of the frame's
|
|
249
249
|
* time: `CARET_BLINK` run forward from `from` at and after it, and backward
|
|
@@ -257,8 +257,8 @@ function caretBlink(from) {
|
|
|
257
257
|
const backward = Timeline.run(Timeline.play(from, -1), CARET_BLINK);
|
|
258
258
|
return Animation.of({
|
|
259
259
|
at: (t) => (t >= from ? forward : backward).at(t),
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
validUntil: (t) => (t >= from ? forward.validUntil(t) : Math.min(backward.validUntil(t), from)),
|
|
261
|
+
validFrom: (t) => (t >= from ? Math.max(forward.validFrom(t), from) : backward.validFrom(t)),
|
|
262
262
|
reduced: () => CARET_BLINK.reduced(),
|
|
263
263
|
});
|
|
264
264
|
}
|
|
@@ -1111,7 +1111,7 @@ let TextInput = (() => {
|
|
|
1111
1111
|
// next flips, which is when a host draws again. A print, drawn for no
|
|
1112
1112
|
// moment, draws it at 0 like any placed animation. Lit, the cell is the
|
|
1113
1113
|
// cursor's; dark, it is drawn as the text around it, since the cursor is a
|
|
1114
|
-
//
|
|
1114
|
+
// color pair and no attribute hides it.
|
|
1115
1115
|
_caret(at, cursorStyle, contentStyle, options) {
|
|
1116
1116
|
return placed(this._blink, options, (lit) => [new Segment(at, lit ? cursorStyle : contentStyle)]);
|
|
1117
1117
|
}
|
|
@@ -65,7 +65,7 @@ let ThemedWidget = (() => {
|
|
|
65
65
|
}
|
|
66
66
|
#theme_accessor_storage = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _theme_initializers, void 0));
|
|
67
67
|
// [LAW:types-are-the-program] @observableRef so setTheme() triggers a
|
|
68
|
-
// re-render: every draw reads its
|
|
68
|
+
// re-render: every draw reads its colors through this reference.
|
|
69
69
|
get theme() { return this.#theme_accessor_storage; }
|
|
70
70
|
set theme(value) { this.#theme_accessor_storage = value; }
|
|
71
71
|
constructor(theme) {
|
package/dist/widgets/toggle.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Toggle widget — on/off switch with label and variant
|
|
2
|
+
* Toggle widget — on/off switch with label and variant color.
|
|
3
3
|
* [LAW:dataflow-not-control-flow] one Segment of fixed width every render;
|
|
4
4
|
* indicator and palette keys come from observable state via lookup tables.
|
|
5
5
|
* [LAW:one-type-per-behavior] shared infrastructure inherited from WidgetBase.
|
|
@@ -14,7 +14,7 @@ import { Segment } from "../core/segment.js";
|
|
|
14
14
|
import type { RenderOptions } from "../core/protocol.js";
|
|
15
15
|
import type { TerminalTheme } from "../core/color.js";
|
|
16
16
|
import { ThemedWidget } from "./themed-widget.js";
|
|
17
|
-
import type {
|
|
17
|
+
import type { WidgetKeyEvent, WidgetMouseEvent } from "./types.js";
|
|
18
18
|
export type ToggleVariant = "default" | "primary" | "success" | "warning" | "danger";
|
|
19
19
|
export interface ToggleOptions {
|
|
20
20
|
label: string;
|
|
@@ -31,7 +31,7 @@ export declare class Toggle extends ThemedWidget {
|
|
|
31
31
|
accessor on: boolean;
|
|
32
32
|
accessor variant: ToggleVariant;
|
|
33
33
|
constructor(options: ToggleOptions);
|
|
34
|
-
handleKey(event:
|
|
34
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
35
35
|
handleMouse(event: WidgetMouseEvent): void;
|
|
36
36
|
protected draw(options: RenderOptions): Iterable<Segment>;
|
|
37
37
|
measure(_options: RenderOptions): {
|
package/dist/widgets/toggle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Toggle widget — on/off switch with label and variant
|
|
2
|
+
* Toggle widget — on/off switch with label and variant color.
|
|
3
3
|
* [LAW:dataflow-not-control-flow] one Segment of fixed width every render;
|
|
4
4
|
* indicator and palette keys come from observable state via lookup tables.
|
|
5
5
|
* [LAW:one-type-per-behavior] shared infrastructure inherited from WidgetBase.
|
|
@@ -44,7 +44,7 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
44
44
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
45
45
|
done = true;
|
|
46
46
|
};
|
|
47
|
-
import {
|
|
47
|
+
import { labeled } from "../core/orient.js";
|
|
48
48
|
import { action } from "mobx";
|
|
49
49
|
import { observableRef } from "./observable.js";
|
|
50
50
|
import { Style } from "../core/style.js";
|
|
@@ -140,7 +140,7 @@ let Toggle = (() => {
|
|
|
140
140
|
draw(options) {
|
|
141
141
|
// Both indicators are exactly 5 cells: "[ON] " and "[OFF]".
|
|
142
142
|
const indicator = this.on ? "[ON] " : "[OFF]";
|
|
143
|
-
const drawn = (style) =>
|
|
143
|
+
const drawn = (style) => labeled(`${indicator} `, this.label, "", style, options.textOrder);
|
|
144
144
|
if (this.disabled) {
|
|
145
145
|
return drawn(new Style(this.disabledInk));
|
|
146
146
|
}
|
package/dist/widgets/types.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ import type { HostFrame, Renderable, Measurable, RenderOptions } from "../core/p
|
|
|
9
9
|
import type { Segment } from "../core/segment.js";
|
|
10
10
|
import type { Anchor } from "../core/anchor.js";
|
|
11
11
|
import type { Unsubscribe } from "../core/subscription.js";
|
|
12
|
-
import type {
|
|
13
|
-
export declare class
|
|
12
|
+
import type { KeyEvent, TerminalMouseEvent } from "../host/input.js";
|
|
13
|
+
export declare class WidgetKeyEvent implements KeyEvent {
|
|
14
14
|
readonly key: string;
|
|
15
15
|
readonly character: string;
|
|
16
16
|
readonly shift: boolean;
|
|
@@ -18,7 +18,7 @@ export declare class KeyEvent implements KeyPress {
|
|
|
18
18
|
readonly meta: boolean;
|
|
19
19
|
readonly time: number;
|
|
20
20
|
private _stopped;
|
|
21
|
-
constructor(init:
|
|
21
|
+
constructor(init: KeyEvent, time: number);
|
|
22
22
|
get stopped(): boolean;
|
|
23
23
|
stop(): void;
|
|
24
24
|
}
|
|
@@ -26,7 +26,7 @@ export type KeyHandlerPriority = "high" | "normal";
|
|
|
26
26
|
export interface KeyHandlerOptions {
|
|
27
27
|
priority?: KeyHandlerPriority;
|
|
28
28
|
}
|
|
29
|
-
export type WidgetMouseEvent = Extract<
|
|
29
|
+
export type WidgetMouseEvent = Extract<TerminalMouseEvent, {
|
|
30
30
|
type: "mouse_down" | "mouse_up" | "mouse_move";
|
|
31
31
|
}> & {
|
|
32
32
|
readonly over: boolean;
|
|
@@ -44,7 +44,7 @@ export interface InteractiveWidget extends Renderable, Measurable {
|
|
|
44
44
|
hovered: boolean;
|
|
45
45
|
active: boolean;
|
|
46
46
|
disabled: boolean;
|
|
47
|
-
handleKey(event:
|
|
47
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
48
48
|
handleMouse(event: WidgetMouseEvent): void;
|
|
49
49
|
handleFocus(event: WidgetFocusEvent): void;
|
|
50
50
|
focus(time: number): void;
|
|
@@ -65,7 +65,7 @@ export interface FocusManager {
|
|
|
65
65
|
next(): void;
|
|
66
66
|
prev(): void;
|
|
67
67
|
focus(widget: InteractiveWidget): void;
|
|
68
|
-
handleKey(event:
|
|
68
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
69
69
|
onChange(handler: (current: InteractiveWidget | null) => void): Unsubscribe;
|
|
70
70
|
}
|
|
71
71
|
export interface FrameSource {
|
package/dist/widgets/types.js
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
// the frame's cells are read on (`RenderOptions.frame`), so a widget
|
|
11
11
|
// keeping the moment of its last interaction — a caret's blink restarting —
|
|
12
12
|
// compares it with the frame it draws and never reads a clock.
|
|
13
|
-
// [LAW:types-are-the-program]
|
|
13
|
+
// [LAW:types-are-the-program] WidgetKeyEvent is a `KeyEvent` the app heard, plus
|
|
14
14
|
// when it was heard and the say over who else hears it. It carries a single mutable signal
|
|
15
15
|
// (`stopped`) that participants in the dispatch chain set by calling
|
|
16
16
|
// `stop()`. Treating it as an interface would force every handler to
|
|
17
17
|
// shuttle a return value upward and the router to interpret it — the
|
|
18
18
|
// class collapses that into one self-describing value flowing through
|
|
19
19
|
// the chain.
|
|
20
|
-
export class
|
|
20
|
+
export class WidgetKeyEvent {
|
|
21
21
|
key;
|
|
22
22
|
character;
|
|
23
23
|
shift;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* reads the frame the view drew:
|
|
9
9
|
*
|
|
10
10
|
* - Focus moves in document order: the order the view reports its widgets in
|
|
11
|
-
* (`RenderOptions.
|
|
11
|
+
* (`RenderOptions.onVisibility`), among those with a cell on the frame on screen.
|
|
12
12
|
* A widget its container hands no column is reported held, not drawn: it is
|
|
13
13
|
* in the view, so it keeps focus, and it has no cell, so Tab passes it.
|
|
14
14
|
* Not reading order — in a `Layout` split into columns, reading order
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
* hear the input.
|
|
27
27
|
*/
|
|
28
28
|
import { Segment } from "../core/segment.js";
|
|
29
|
-
import type { HostFrame, FrameHost,
|
|
29
|
+
import type { HostFrame, FrameHost, Visibility } from "../core/protocol.js";
|
|
30
30
|
import type { Unsubscribe } from "../core/subscription.js";
|
|
31
31
|
import type { Clock, FrameRate } from "../core/clock.js";
|
|
32
32
|
import type { Timeline } from "../core/timeline.js";
|
|
33
|
-
import { type AppOptions, type AppPhase, type
|
|
34
|
-
import type { FocusManager, FrameSource,
|
|
33
|
+
import { type AppOptions, type AppPhase, type WheelEvent } from "../host/app.js";
|
|
34
|
+
import type { FocusManager, FrameSource, WidgetKeyEvent, KeyHandlerOptions } from "./types.js";
|
|
35
35
|
import type { AppMouseEvent } from "../host/app.js";
|
|
36
36
|
import { WidgetBase } from "./widget-base.js";
|
|
37
37
|
export interface WidgetAppOptions extends AppOptions {
|
|
@@ -42,9 +42,9 @@ export interface WidgetAppOptions extends AppOptions {
|
|
|
42
42
|
readonly focusOnClick?: boolean;
|
|
43
43
|
}
|
|
44
44
|
/** A widget the view reported for a frame, and whether it was drawn or held. */
|
|
45
|
-
export interface
|
|
45
|
+
export interface WidgetVisibility {
|
|
46
46
|
readonly widget: WidgetBase;
|
|
47
|
-
readonly
|
|
47
|
+
readonly visibility: Visibility;
|
|
48
48
|
}
|
|
49
49
|
export declare class WidgetApp implements FrameSource, FrameHost {
|
|
50
50
|
readonly focusManager: FocusManager;
|
|
@@ -65,10 +65,10 @@ export declare class WidgetApp implements FrameSource, FrameHost {
|
|
|
65
65
|
set rate(rate: FrameRate);
|
|
66
66
|
/**
|
|
67
67
|
* The widgets the view reported for the frame on screen, in document order,
|
|
68
|
-
* each drawn or held (`RenderOptions.
|
|
68
|
+
* each drawn or held (`RenderOptions.onVisibility`). A held widget is one its
|
|
69
69
|
* container handed no column: in the view, with no cell on the frame.
|
|
70
70
|
*/
|
|
71
|
-
get
|
|
71
|
+
get mounted(): readonly WidgetVisibility[];
|
|
72
72
|
private get widgets();
|
|
73
73
|
/** The rows on screen now, as painted: what a pointer event lands on. */
|
|
74
74
|
get frame(): readonly (readonly Segment[])[];
|
|
@@ -93,7 +93,7 @@ export declare class WidgetApp implements FrameSource, FrameHost {
|
|
|
93
93
|
* `normal` one after it — and after Tab has moved focus — and a handler
|
|
94
94
|
* that calls `event.stop()` ends the key there.
|
|
95
95
|
*/
|
|
96
|
-
onKey(handler: (event:
|
|
96
|
+
onKey(handler: (event: WidgetKeyEvent) => void, options?: KeyHandlerOptions): Unsubscribe;
|
|
97
97
|
/** Hear every pointer event but the vertical wheel, in terminal cells, before any widget does. */
|
|
98
98
|
onMouse(handler: (event: AppMouseEvent) => void): Unsubscribe;
|
|
99
99
|
/**
|
|
@@ -101,6 +101,6 @@ export declare class WidgetApp implements FrameSource, FrameHost {
|
|
|
101
101
|
* `handler`, as `App.onWheel` does: it returns whether it moved something,
|
|
102
102
|
* and a turn nothing moved with is passed outward.
|
|
103
103
|
*/
|
|
104
|
-
onWheel(handler: (wheel:
|
|
104
|
+
onWheel(handler: (wheel: WheelEvent) => boolean): Unsubscribe;
|
|
105
105
|
private compose;
|
|
106
106
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* reads the frame the view drew:
|
|
9
9
|
*
|
|
10
10
|
* - Focus moves in document order: the order the view reports its widgets in
|
|
11
|
-
* (`RenderOptions.
|
|
11
|
+
* (`RenderOptions.onVisibility`), among those with a cell on the frame on screen.
|
|
12
12
|
* A widget its container hands no column is reported held, not drawn: it is
|
|
13
13
|
* in the view, so it keeps focus, and it has no cell, so Tab passes it.
|
|
14
14
|
* Not reading order — in a `Layout` split into columns, reading order
|
|
@@ -60,7 +60,7 @@ export class WidgetApp {
|
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
62
|
this.focus = new DefaultFocusManager({
|
|
63
|
-
|
|
63
|
+
mounted: () => this.widgets,
|
|
64
64
|
onScreen: () => {
|
|
65
65
|
const owners = ownersOn(this.app.frame);
|
|
66
66
|
return this.widgets.filter((widget) => owners.has(widget));
|
|
@@ -105,10 +105,10 @@ export class WidgetApp {
|
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* The widgets the view reported for the frame on screen, in document order,
|
|
108
|
-
* each drawn or held (`RenderOptions.
|
|
108
|
+
* each drawn or held (`RenderOptions.onVisibility`). A held widget is one its
|
|
109
109
|
* container handed no column: in the view, with no cell on the frame.
|
|
110
110
|
*/
|
|
111
|
-
get
|
|
111
|
+
get mounted() {
|
|
112
112
|
return this._present;
|
|
113
113
|
}
|
|
114
114
|
get widgets() {
|
|
@@ -180,9 +180,9 @@ export class WidgetApp {
|
|
|
180
180
|
const present = new Map();
|
|
181
181
|
// [LAW:parse-dont-validate] What the view reports is any renderable; only
|
|
182
182
|
// a `WidgetBase` is a widget, so this is where a renderable becomes one.
|
|
183
|
-
const
|
|
183
|
+
const onVisibility = (renderable, visibility) => {
|
|
184
184
|
if (renderable instanceof WidgetBase)
|
|
185
|
-
present.set(renderable, present.get(renderable) === "
|
|
185
|
+
present.set(renderable, present.get(renderable) === "visible" ? "visible" : visibility);
|
|
186
186
|
};
|
|
187
187
|
// The view, its render and the overlays are all tracked, so an observable
|
|
188
188
|
// any of them reads — a label, `focused`, the state that picks what the
|
|
@@ -190,14 +190,14 @@ export class WidgetApp {
|
|
|
190
190
|
// An overlay reports what it draws too: a widget in it is in the view,
|
|
191
191
|
// and visiting `present` in report order paints its overlay in turn. A
|
|
192
192
|
// held widget has no footprint on the frame, and so paints none.
|
|
193
|
-
const drawing = { ...options,
|
|
193
|
+
const drawing = { ...options, onVisibility };
|
|
194
194
|
const lines = tracked(this.reaction, () => {
|
|
195
195
|
const base = Segment.splitLines(render(view, drawing));
|
|
196
196
|
for (const widget of present.keys())
|
|
197
197
|
paintOverlay(base, widget, drawing);
|
|
198
198
|
return base;
|
|
199
199
|
});
|
|
200
|
-
this._present = [...present].map(([widget,
|
|
200
|
+
this._present = [...present].map(([widget, visibility]) => ({ widget, visibility }));
|
|
201
201
|
return lines.flatMap((line) => [...line, Segment.line()]);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { Segment } from "../core/segment.js";
|
|
11
11
|
import { type Style } from "../core/style.js";
|
|
12
12
|
import type { RenderOptions } from "../core/protocol.js";
|
|
13
|
-
import type { InteractiveWidget,
|
|
13
|
+
import type { InteractiveWidget, WidgetKeyEvent, WidgetMouseEvent, WidgetFocusEvent } from "./types.js";
|
|
14
14
|
import type { Unsubscribe } from "../core/subscription.js";
|
|
15
15
|
export declare abstract class WidgetBase implements InteractiveWidget {
|
|
16
16
|
abstract readonly id: string;
|
|
@@ -21,7 +21,7 @@ export declare abstract class WidgetBase implements InteractiveWidget {
|
|
|
21
21
|
accessor disabled: boolean;
|
|
22
22
|
private readonly changeHandlers;
|
|
23
23
|
private readonly submitHandlers;
|
|
24
|
-
abstract handleKey(event:
|
|
24
|
+
abstract handleKey(event: WidgetKeyEvent): void;
|
|
25
25
|
handleMouse(_event: WidgetMouseEvent): void;
|
|
26
26
|
handleFocus(event: WidgetFocusEvent): void;
|
|
27
27
|
focus(time: number): void;
|