@opentui/react 0.1.11 → 0.1.13
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 +17 -37
- package/index.js +3 -4
- package/jsx-namespace.d.ts +0 -2
- package/package.json +2 -2
- package/src/components/index.d.ts +1 -2
- package/src/reconciler/renderer.js +3 -4
- package/src/types/components.d.ts +7 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @opentui/react
|
|
2
2
|
|
|
3
|
-
A React renderer for building terminal user interfaces using OpenTUI core. Create rich, interactive console applications with familiar React patterns and components.
|
|
3
|
+
A React renderer for building terminal user interfaces using [OpenTUI core](https://github.com/sst/opentui). Create rich, interactive console applications with familiar React patterns and components.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -15,12 +15,12 @@ import { render } from "@opentui/react"
|
|
|
15
15
|
|
|
16
16
|
function App() {
|
|
17
17
|
return (
|
|
18
|
-
<
|
|
18
|
+
<box>
|
|
19
19
|
<text fg="#00FF00">Hello, Terminal!</text>
|
|
20
20
|
<box title="Welcome" padding={2}>
|
|
21
21
|
<text>Welcome to OpenTUI with React!"</text>
|
|
22
22
|
</box>
|
|
23
|
-
</
|
|
23
|
+
</box>
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -35,7 +35,6 @@ OpenTUI React provides several built-in components that map to OpenTUI core rend
|
|
|
35
35
|
|
|
36
36
|
- **`<text>`** - Display text with styling
|
|
37
37
|
- **`<box>`** - Container with borders and layout
|
|
38
|
-
- **`<group>`** - Layout container for organizing components
|
|
39
38
|
- **`<input>`** - Text input field
|
|
40
39
|
- **`<select>`** - Selection dropdown
|
|
41
40
|
- **`<tab-select>`** - Tab-based selection
|
|
@@ -147,14 +146,14 @@ function MyComponent() {
|
|
|
147
146
|
const { width, height } = useTerminalDimensions()
|
|
148
147
|
|
|
149
148
|
return (
|
|
150
|
-
<
|
|
149
|
+
<box>
|
|
151
150
|
<text>
|
|
152
151
|
Terminal dimensions: {width}x{height}
|
|
153
152
|
</text>
|
|
154
153
|
<box style={{ width: Math.floor(width / 2), height: Math.floor(height / 3) }}>
|
|
155
154
|
<text>Half-width, third-height box</text>
|
|
156
155
|
</box>
|
|
157
|
-
</
|
|
156
|
+
</box>
|
|
158
157
|
)
|
|
159
158
|
}
|
|
160
159
|
```
|
|
@@ -172,7 +171,7 @@ import { bold, fg, t } from "@opentui/core"
|
|
|
172
171
|
|
|
173
172
|
function TextExample() {
|
|
174
173
|
return (
|
|
175
|
-
<
|
|
174
|
+
<box>
|
|
176
175
|
{/* Simple text */}
|
|
177
176
|
<text>Hello World</text>
|
|
178
177
|
|
|
@@ -181,7 +180,7 @@ function TextExample() {
|
|
|
181
180
|
|
|
182
181
|
{/* Template literals */}
|
|
183
182
|
<text>{t`${bold("Bold")} and ${fg("blue")("Blue")}`}</text>
|
|
184
|
-
</
|
|
183
|
+
</box>
|
|
185
184
|
)
|
|
186
185
|
}
|
|
187
186
|
```
|
|
@@ -193,7 +192,7 @@ Container with borders and layout capabilities.
|
|
|
193
192
|
```tsx
|
|
194
193
|
function BoxExample() {
|
|
195
194
|
return (
|
|
196
|
-
<
|
|
195
|
+
<box flexDirection="column">
|
|
197
196
|
{/* Basic box */}
|
|
198
197
|
<box>
|
|
199
198
|
<text>Simple box</text>
|
|
@@ -216,26 +215,7 @@ function BoxExample() {
|
|
|
216
215
|
>
|
|
217
216
|
<text>Centered content</text>
|
|
218
217
|
</box>
|
|
219
|
-
</
|
|
220
|
-
)
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
### Group Component
|
|
225
|
-
|
|
226
|
-
Layout container for organizing multiple components.
|
|
227
|
-
|
|
228
|
-
```tsx
|
|
229
|
-
function GroupExample() {
|
|
230
|
-
return (
|
|
231
|
-
<group flexDirection="row">
|
|
232
|
-
<box>
|
|
233
|
-
<text>Left</text>
|
|
234
|
-
</box>
|
|
235
|
-
<box>
|
|
236
|
-
<text>Right</text>
|
|
237
|
-
</box>
|
|
238
|
-
</group>
|
|
218
|
+
</box>
|
|
239
219
|
)
|
|
240
220
|
}
|
|
241
221
|
```
|
|
@@ -318,7 +298,7 @@ function ASCIIFontExample() {
|
|
|
318
298
|
})
|
|
319
299
|
|
|
320
300
|
return (
|
|
321
|
-
<
|
|
301
|
+
<box style={{ paddingLeft: 1, paddingRight: 1 }}>
|
|
322
302
|
<box
|
|
323
303
|
style={{
|
|
324
304
|
height: 8,
|
|
@@ -356,7 +336,7 @@ function ASCIIFontExample() {
|
|
|
356
336
|
</box>
|
|
357
337
|
|
|
358
338
|
<ascii-font style={{ width, height }} text={text} font={font} />
|
|
359
|
-
</
|
|
339
|
+
</box>
|
|
360
340
|
)
|
|
361
341
|
}
|
|
362
342
|
```
|
|
@@ -390,7 +370,7 @@ function LoginForm() {
|
|
|
390
370
|
}, [username, password])
|
|
391
371
|
|
|
392
372
|
return (
|
|
393
|
-
<
|
|
373
|
+
<box style={{ padding: 2, flexDirection: "column" }}>
|
|
394
374
|
<text fg="#FFFF00">Login Form</text>
|
|
395
375
|
|
|
396
376
|
<box title="Username" style={{ width: 40, height: 3, marginTop: 1 }}>
|
|
@@ -418,7 +398,7 @@ function LoginForm() {
|
|
|
418
398
|
>
|
|
419
399
|
{status.toUpperCase()}
|
|
420
400
|
</text>
|
|
421
|
-
</
|
|
401
|
+
</box>
|
|
422
402
|
)
|
|
423
403
|
}
|
|
424
404
|
|
|
@@ -460,7 +440,7 @@ import { render } from "@opentui/react"
|
|
|
460
440
|
|
|
461
441
|
function StyledTextShowcase() {
|
|
462
442
|
return (
|
|
463
|
-
<
|
|
443
|
+
<box style={{ flexDirection: "column" }}>
|
|
464
444
|
<text>Simple text</text>
|
|
465
445
|
<text>{bold("Bold text")}</text>
|
|
466
446
|
<text>{underline("Underlined text")}</text>
|
|
@@ -468,7 +448,7 @@ function StyledTextShowcase() {
|
|
|
468
448
|
<text>{blue("Blue text")}</text>
|
|
469
449
|
<text>{bold(red("Bold red text"))}</text>
|
|
470
450
|
<text>{t`${bold("Bold")} and ${blue("blue")} combined`}</text>
|
|
471
|
-
</
|
|
451
|
+
</box>
|
|
472
452
|
)
|
|
473
453
|
}
|
|
474
454
|
|
|
@@ -521,10 +501,10 @@ extend({ button: ButtonRenderable })
|
|
|
521
501
|
// Use in JSX
|
|
522
502
|
function App() {
|
|
523
503
|
return (
|
|
524
|
-
<
|
|
504
|
+
<box>
|
|
525
505
|
<button label="Click me!" style={{ backgroundColor: "blue" }} />
|
|
526
506
|
<button label="Another button" style={{ backgroundColor: "green" }} />
|
|
527
|
-
</
|
|
507
|
+
</box>
|
|
528
508
|
)
|
|
529
509
|
}
|
|
530
510
|
|
package/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import {
|
|
4
4
|
ASCIIFontRenderable,
|
|
5
5
|
BoxRenderable,
|
|
6
|
-
GroupRenderable,
|
|
7
6
|
InputRenderable,
|
|
8
7
|
SelectRenderable,
|
|
9
8
|
TabSelectRenderable,
|
|
@@ -12,7 +11,6 @@ import {
|
|
|
12
11
|
var baseComponents = {
|
|
13
12
|
box: BoxRenderable,
|
|
14
13
|
text: TextRenderable,
|
|
15
|
-
group: GroupRenderable,
|
|
16
14
|
input: InputRenderable,
|
|
17
15
|
select: SelectRenderable,
|
|
18
16
|
"ascii-font": ASCIIFontRenderable,
|
|
@@ -268,7 +266,7 @@ var hostConfig = {
|
|
|
268
266
|
if (!components[type]) {
|
|
269
267
|
throw new Error(`[Reconciler] Unknown component type: ${type}`);
|
|
270
268
|
}
|
|
271
|
-
return new components[type](
|
|
269
|
+
return new components[type](rootContainerInstance.ctx, {});
|
|
272
270
|
},
|
|
273
271
|
appendChild(parent, child) {
|
|
274
272
|
parent.add(child);
|
|
@@ -305,7 +303,8 @@ var hostConfig = {
|
|
|
305
303
|
},
|
|
306
304
|
createTextInstance(text, rootContainerInstance, hostContext) {
|
|
307
305
|
const components = getComponentCatalogue();
|
|
308
|
-
return new components["text"](
|
|
306
|
+
return new components["text"](rootContainerInstance.ctx, {
|
|
307
|
+
id: getNextId("text"),
|
|
309
308
|
content: text
|
|
310
309
|
});
|
|
311
310
|
},
|
package/jsx-namespace.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type * as React from "react"
|
|
|
2
2
|
import type {
|
|
3
3
|
AsciiFontProps,
|
|
4
4
|
BoxProps,
|
|
5
|
-
GroupProps,
|
|
6
5
|
InputProps,
|
|
7
6
|
SelectProps,
|
|
8
7
|
TabSelectProps,
|
|
@@ -28,7 +27,6 @@ export namespace JSX {
|
|
|
28
27
|
interface IntrinsicElements extends React.JSX.IntrinsicElements, ExtendedIntrinsicElements<OpenTUIComponents> {
|
|
29
28
|
box: BoxProps
|
|
30
29
|
text: TextProps
|
|
31
|
-
group: GroupProps
|
|
32
30
|
input: InputProps
|
|
33
31
|
select: SelectProps
|
|
34
32
|
"ascii-font": AsciiFontProps
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.13",
|
|
8
8
|
"description": "React renderer for building terminal user interfaces using OpenTUI core",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@opentui/core": "0.1.
|
|
38
|
+
"@opentui/core": "0.1.13",
|
|
39
39
|
"react-reconciler": "^0.32.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { ASCIIFontRenderable, BoxRenderable,
|
|
1
|
+
import { ASCIIFontRenderable, BoxRenderable, InputRenderable, SelectRenderable, TabSelectRenderable, TextRenderable } from "@opentui/core";
|
|
2
2
|
import type { RenderableConstructor } from "../types/components";
|
|
3
3
|
export declare const baseComponents: {
|
|
4
4
|
box: typeof BoxRenderable;
|
|
5
5
|
text: typeof TextRenderable;
|
|
6
|
-
group: typeof GroupRenderable;
|
|
7
6
|
input: typeof InputRenderable;
|
|
8
7
|
select: typeof SelectRenderable;
|
|
9
8
|
"ascii-font": typeof ASCIIFontRenderable;
|
|
@@ -22,7 +22,6 @@ import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constant
|
|
|
22
22
|
import {
|
|
23
23
|
ASCIIFontRenderable,
|
|
24
24
|
BoxRenderable,
|
|
25
|
-
GroupRenderable,
|
|
26
25
|
InputRenderable,
|
|
27
26
|
SelectRenderable,
|
|
28
27
|
TabSelectRenderable,
|
|
@@ -31,7 +30,6 @@ import {
|
|
|
31
30
|
var baseComponents = {
|
|
32
31
|
box: BoxRenderable,
|
|
33
32
|
text: TextRenderable,
|
|
34
|
-
group: GroupRenderable,
|
|
35
33
|
input: InputRenderable,
|
|
36
34
|
select: SelectRenderable,
|
|
37
35
|
"ascii-font": ASCIIFontRenderable,
|
|
@@ -219,7 +217,7 @@ var hostConfig = {
|
|
|
219
217
|
if (!components[type]) {
|
|
220
218
|
throw new Error(`[Reconciler] Unknown component type: ${type}`);
|
|
221
219
|
}
|
|
222
|
-
return new components[type](
|
|
220
|
+
return new components[type](rootContainerInstance.ctx, {});
|
|
223
221
|
},
|
|
224
222
|
appendChild(parent, child) {
|
|
225
223
|
parent.add(child);
|
|
@@ -256,7 +254,8 @@ var hostConfig = {
|
|
|
256
254
|
},
|
|
257
255
|
createTextInstance(text, rootContainerInstance, hostContext) {
|
|
258
256
|
const components = getComponentCatalogue();
|
|
259
|
-
return new components["text"](
|
|
257
|
+
return new components["text"](rootContainerInstance.ctx, {
|
|
258
|
+
id: getNextId("text"),
|
|
260
259
|
content: text
|
|
261
260
|
});
|
|
262
261
|
},
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type { ASCIIFontOptions, ASCIIFontRenderable, BoxOptions, BoxRenderable,
|
|
1
|
+
import type { ASCIIFontOptions, ASCIIFontRenderable, BoxOptions, BoxRenderable, InputRenderable, InputRenderableOptions, Renderable, RenderableOptions, RenderContext, SelectOption, SelectRenderable, SelectRenderableOptions, StyledText, TabSelectOption, TabSelectRenderable, TabSelectRenderableOptions, TextChunk, TextOptions, TextRenderable } from "@opentui/core";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
/** Properties that should not be included in the style prop */
|
|
4
|
-
export type NonStyledProps = "buffered" | "live" | "enableLayout" | "selectable"
|
|
4
|
+
export type NonStyledProps = "id" | "buffered" | "live" | "enableLayout" | "selectable" | "renderAfter" | "renderBefore" | `on${string}`;
|
|
5
5
|
/** React-specific props for all components */
|
|
6
6
|
export type ReactProps<TRenderable = unknown> = {
|
|
7
7
|
key?: React.Key;
|
|
8
8
|
ref?: React.Ref<TRenderable>;
|
|
9
9
|
};
|
|
10
10
|
/** Base type for any renderable constructor */
|
|
11
|
-
export type RenderableConstructor<TRenderable extends Renderable = Renderable> = new (
|
|
11
|
+
export type RenderableConstructor<TRenderable extends Renderable = Renderable> = new (ctx: RenderContext, options: any) => TRenderable;
|
|
12
12
|
/** Extract the options type from a renderable constructor */
|
|
13
|
-
type ExtractRenderableOptions<TConstructor> = TConstructor extends new (
|
|
13
|
+
type ExtractRenderableOptions<TConstructor> = TConstructor extends new (ctx: RenderContext, options: infer TOptions) => any ? TOptions : never;
|
|
14
14
|
/** Extract the renderable type from a constructor */
|
|
15
|
-
type ExtractRenderable<TConstructor> = TConstructor extends new (
|
|
15
|
+
type ExtractRenderable<TConstructor> = TConstructor extends new (ctx: RenderContext, options: any) => infer TRenderable ? TRenderable : never;
|
|
16
16
|
/** Determine which properties should be excluded from styling for different renderable types */
|
|
17
|
-
export type GetNonStyledProperties<TConstructor> = TConstructor extends RenderableConstructor<TextRenderable> ? NonStyledProps | "content" : TConstructor extends RenderableConstructor<BoxRenderable> ? NonStyledProps | "title" : TConstructor extends RenderableConstructor<ASCIIFontRenderable> ? NonStyledProps | "text" | "selectable" : NonStyledProps;
|
|
17
|
+
export type GetNonStyledProperties<TConstructor> = TConstructor extends RenderableConstructor<TextRenderable> ? NonStyledProps | "content" : TConstructor extends RenderableConstructor<BoxRenderable> ? NonStyledProps | "title" : TConstructor extends RenderableConstructor<ASCIIFontRenderable> ? NonStyledProps | "text" | "selectable" : TConstructor extends RenderableConstructor<InputRenderable> ? NonStyledProps | "placeholder" | "value" : NonStyledProps;
|
|
18
18
|
/** Base props for container components that accept children */
|
|
19
19
|
type ContainerProps<TOptions> = TOptions & {
|
|
20
20
|
children?: React.ReactNode;
|
|
21
21
|
};
|
|
22
22
|
/** Smart component props that automatically determine excluded properties */
|
|
23
|
-
type ComponentProps<TOptions extends RenderableOptions
|
|
23
|
+
type ComponentProps<TOptions extends RenderableOptions<TRenderable>, TRenderable extends Renderable> = TOptions & {
|
|
24
24
|
style?: Partial<Omit<TOptions, GetNonStyledProperties<RenderableConstructor<TRenderable>>>>;
|
|
25
25
|
} & ReactProps<TRenderable>;
|
|
26
26
|
/** Valid text content types for Text component children */
|
|
@@ -29,7 +29,6 @@ export type TextProps = ComponentProps<TextOptions, TextRenderable> & {
|
|
|
29
29
|
children?: TextChildren | StyledText | TextChunk | Array<TextChildren | StyledText | TextChunk>;
|
|
30
30
|
};
|
|
31
31
|
export type BoxProps = ComponentProps<ContainerProps<BoxOptions>, BoxRenderable>;
|
|
32
|
-
export type GroupProps = ComponentProps<ContainerProps<RenderableOptions>, GroupRenderable>;
|
|
33
32
|
export type InputProps = ComponentProps<InputRenderableOptions, InputRenderable> & {
|
|
34
33
|
focused?: boolean;
|
|
35
34
|
onInput?: (value: string) => void;
|