@opentui/react 0.0.0-20250908-4906ddad
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/LICENSE +21 -0
- package/README.md +531 -0
- package/index.js +455 -0
- package/jsx-dev-runtime.d.ts +2 -0
- package/jsx-dev-runtime.js +1 -0
- package/jsx-namespace.d.ts +38 -0
- package/jsx-runtime.d.ts +2 -0
- package/jsx-runtime.js +1 -0
- package/package.json +49 -0
- package/src/components/app.d.ts +8 -0
- package/src/components/index.d.ts +28 -0
- package/src/hooks/use-event.d.ts +9 -0
- package/src/hooks/use-keyboard.d.ts +2 -0
- package/src/hooks/use-renderer.d.ts +1 -0
- package/src/hooks/use-resize.d.ts +1 -0
- package/src/hooks/use-terminal-dimensions.d.ts +4 -0
- package/src/index.d.ts +8 -0
- package/src/reconciler/host-config.d.ts +9 -0
- package/src/reconciler/reconciler.d.ts +5 -0
- package/src/reconciler/renderer.d.ts +3 -0
- package/src/reconciler/renderer.js +380 -0
- package/src/types/components.d.ts +68 -0
- package/src/types/host.d.ts +9 -0
- package/src/utils/id.d.ts +2 -0
- package/src/utils/index.d.ts +3 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/reconciler/renderer.ts
|
|
3
|
+
import { createCliRenderer, getKeyHandler } from "@opentui/core";
|
|
4
|
+
import React from "react";
|
|
5
|
+
|
|
6
|
+
// src/components/app.tsx
|
|
7
|
+
import { createContext, useContext } from "react";
|
|
8
|
+
var AppContext = createContext({
|
|
9
|
+
keyHandler: null,
|
|
10
|
+
renderer: null
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// src/reconciler/reconciler.ts
|
|
14
|
+
import ReactReconciler from "react-reconciler";
|
|
15
|
+
import { ConcurrentRoot } from "react-reconciler/constants";
|
|
16
|
+
|
|
17
|
+
// src/reconciler/host-config.ts
|
|
18
|
+
import { createContext as createContext2 } from "react";
|
|
19
|
+
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants";
|
|
20
|
+
|
|
21
|
+
// src/components/index.ts
|
|
22
|
+
import {
|
|
23
|
+
ASCIIFontRenderable,
|
|
24
|
+
BoxRenderable,
|
|
25
|
+
InputRenderable,
|
|
26
|
+
ScrollBoxRenderable,
|
|
27
|
+
SelectRenderable,
|
|
28
|
+
TabSelectRenderable,
|
|
29
|
+
TextRenderable
|
|
30
|
+
} from "@opentui/core";
|
|
31
|
+
var baseComponents = {
|
|
32
|
+
box: BoxRenderable,
|
|
33
|
+
text: TextRenderable,
|
|
34
|
+
input: InputRenderable,
|
|
35
|
+
select: SelectRenderable,
|
|
36
|
+
scrollbox: ScrollBoxRenderable,
|
|
37
|
+
"ascii-font": ASCIIFontRenderable,
|
|
38
|
+
"tab-select": TabSelectRenderable
|
|
39
|
+
};
|
|
40
|
+
var componentCatalogue = { ...baseComponents };
|
|
41
|
+
function getComponentCatalogue() {
|
|
42
|
+
return componentCatalogue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/utils/id.ts
|
|
46
|
+
var idCounter = new Map;
|
|
47
|
+
function getNextId(type) {
|
|
48
|
+
if (!idCounter.has(type)) {
|
|
49
|
+
idCounter.set(type, 0);
|
|
50
|
+
}
|
|
51
|
+
const value = idCounter.get(type) + 1;
|
|
52
|
+
idCounter.set(type, value);
|
|
53
|
+
return `${type}-${value}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/utils/index.ts
|
|
57
|
+
import {
|
|
58
|
+
InputRenderable as InputRenderable2,
|
|
59
|
+
InputRenderableEvents,
|
|
60
|
+
SelectRenderable as SelectRenderable2,
|
|
61
|
+
SelectRenderableEvents,
|
|
62
|
+
StyledText,
|
|
63
|
+
TabSelectRenderable as TabSelectRenderable2,
|
|
64
|
+
TabSelectRenderableEvents,
|
|
65
|
+
TextRenderable as TextRenderable2,
|
|
66
|
+
stringToStyledText
|
|
67
|
+
} from "@opentui/core";
|
|
68
|
+
function initEventListeners(instance, eventName, listener, previousListener) {
|
|
69
|
+
if (previousListener) {
|
|
70
|
+
instance.off(eventName, previousListener);
|
|
71
|
+
}
|
|
72
|
+
if (listener) {
|
|
73
|
+
instance.on(eventName, listener);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function handleTextChildren(textInstance, children) {
|
|
77
|
+
if (children == null) {
|
|
78
|
+
textInstance.content = stringToStyledText("");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (Array.isArray(children)) {
|
|
82
|
+
const chunks = [];
|
|
83
|
+
for (const child of children) {
|
|
84
|
+
if (typeof child === "string") {
|
|
85
|
+
chunks.push({
|
|
86
|
+
__isChunk: true,
|
|
87
|
+
text: new TextEncoder().encode(child),
|
|
88
|
+
plainText: child
|
|
89
|
+
});
|
|
90
|
+
} else if (child && typeof child === "object" && "__isChunk" in child) {
|
|
91
|
+
chunks.push(child);
|
|
92
|
+
} else if (child instanceof StyledText) {
|
|
93
|
+
chunks.push(...child.chunks);
|
|
94
|
+
} else if (child != null) {
|
|
95
|
+
const stringValue = String(child);
|
|
96
|
+
chunks.push({
|
|
97
|
+
__isChunk: true,
|
|
98
|
+
text: new TextEncoder().encode(stringValue),
|
|
99
|
+
plainText: stringValue
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
textInstance.content = new StyledText(chunks);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (typeof children === "string") {
|
|
107
|
+
textInstance.content = stringToStyledText(children);
|
|
108
|
+
} else if (children && typeof children === "object" && "__isChunk" in children) {
|
|
109
|
+
textInstance.content = new StyledText([children]);
|
|
110
|
+
} else if (children instanceof StyledText) {
|
|
111
|
+
textInstance.content = children;
|
|
112
|
+
} else {
|
|
113
|
+
textInstance.content = stringToStyledText(String(children));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function setStyle(instance, styles, oldStyles) {
|
|
117
|
+
if (styles && typeof styles === "object") {
|
|
118
|
+
if (oldStyles != null) {
|
|
119
|
+
for (const styleName in styles) {
|
|
120
|
+
const value = styles[styleName];
|
|
121
|
+
if (styles.hasOwnProperty(styleName) && oldStyles[styleName] !== value) {
|
|
122
|
+
instance[styleName] = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
for (const styleName in styles) {
|
|
127
|
+
if (styles.hasOwnProperty(styleName)) {
|
|
128
|
+
const value = styles[styleName];
|
|
129
|
+
instance[styleName] = value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function setProperty(instance, type, propKey, propValue, oldPropValue) {
|
|
136
|
+
switch (propKey) {
|
|
137
|
+
case "onChange":
|
|
138
|
+
if (instance instanceof InputRenderable2) {
|
|
139
|
+
initEventListeners(instance, InputRenderableEvents.CHANGE, propValue, oldPropValue);
|
|
140
|
+
} else if (instance instanceof SelectRenderable2) {
|
|
141
|
+
initEventListeners(instance, SelectRenderableEvents.SELECTION_CHANGED, propValue, oldPropValue);
|
|
142
|
+
} else if (instance instanceof TabSelectRenderable2) {
|
|
143
|
+
initEventListeners(instance, TabSelectRenderableEvents.SELECTION_CHANGED, propValue, oldPropValue);
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
case "onInput":
|
|
147
|
+
if (instance instanceof InputRenderable2) {
|
|
148
|
+
initEventListeners(instance, InputRenderableEvents.INPUT, propValue, oldPropValue);
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
case "onSubmit":
|
|
152
|
+
if (instance instanceof InputRenderable2) {
|
|
153
|
+
initEventListeners(instance, InputRenderableEvents.ENTER, propValue, oldPropValue);
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case "onSelect":
|
|
157
|
+
if (instance instanceof SelectRenderable2) {
|
|
158
|
+
initEventListeners(instance, SelectRenderableEvents.ITEM_SELECTED, propValue, oldPropValue);
|
|
159
|
+
} else if (instance instanceof TabSelectRenderable2) {
|
|
160
|
+
initEventListeners(instance, TabSelectRenderableEvents.ITEM_SELECTED, propValue, oldPropValue);
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
case "focused":
|
|
164
|
+
if (!!propValue) {
|
|
165
|
+
instance.focus();
|
|
166
|
+
} else {
|
|
167
|
+
instance.blur();
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case "style":
|
|
171
|
+
setStyle(instance, propValue, oldPropValue);
|
|
172
|
+
break;
|
|
173
|
+
case "children":
|
|
174
|
+
if (type === "text" && instance instanceof TextRenderable2) {
|
|
175
|
+
handleTextChildren(instance, propValue);
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
default:
|
|
179
|
+
instance[propKey] = propValue;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function setInitialProperties(instance, type, props) {
|
|
183
|
+
for (const propKey in props) {
|
|
184
|
+
if (!props.hasOwnProperty(propKey)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const propValue = props[propKey];
|
|
188
|
+
if (propValue == null) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
setProperty(instance, type, propKey, propValue);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function updateProperties(instance, type, oldProps, newProps) {
|
|
195
|
+
for (const propKey in oldProps) {
|
|
196
|
+
const oldProp = oldProps[propKey];
|
|
197
|
+
if (oldProps.hasOwnProperty(propKey) && oldProp != null && !newProps.hasOwnProperty(propKey)) {
|
|
198
|
+
setProperty(instance, type, propKey, null, oldProp);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const propKey in newProps) {
|
|
202
|
+
const newProp = newProps[propKey];
|
|
203
|
+
const oldProp = oldProps[propKey];
|
|
204
|
+
if (newProps.hasOwnProperty(propKey) && newProp !== oldProp && (newProp != null || oldProp != null)) {
|
|
205
|
+
setProperty(instance, type, propKey, newProp, oldProp);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/reconciler/host-config.ts
|
|
211
|
+
var currentUpdatePriority = NoEventPriority;
|
|
212
|
+
var hostConfig = {
|
|
213
|
+
supportsMutation: true,
|
|
214
|
+
supportsPersistence: false,
|
|
215
|
+
supportsHydration: false,
|
|
216
|
+
createInstance(type, props, rootContainerInstance, hostContext) {
|
|
217
|
+
const id = getNextId(type);
|
|
218
|
+
const components = getComponentCatalogue();
|
|
219
|
+
if (!components[type]) {
|
|
220
|
+
throw new Error(`[Reconciler] Unknown component type: ${type}`);
|
|
221
|
+
}
|
|
222
|
+
return new components[type](rootContainerInstance.ctx, {
|
|
223
|
+
id,
|
|
224
|
+
...props
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
appendChild(parent, child) {
|
|
228
|
+
parent.add(child);
|
|
229
|
+
},
|
|
230
|
+
removeChild(parent, child) {
|
|
231
|
+
parent.remove(child.id);
|
|
232
|
+
},
|
|
233
|
+
insertBefore(parent, child, beforeChild) {
|
|
234
|
+
parent.insertBefore(child, beforeChild);
|
|
235
|
+
},
|
|
236
|
+
insertInContainerBefore(parent, child, beforeChild) {
|
|
237
|
+
parent.insertBefore(child, beforeChild);
|
|
238
|
+
},
|
|
239
|
+
removeChildFromContainer(parent, child) {
|
|
240
|
+
parent.remove(child.id);
|
|
241
|
+
},
|
|
242
|
+
prepareForCommit(containerInfo) {
|
|
243
|
+
return null;
|
|
244
|
+
},
|
|
245
|
+
resetAfterCommit(containerInfo) {
|
|
246
|
+
containerInfo.requestRender();
|
|
247
|
+
},
|
|
248
|
+
getRootHostContext(rootContainerInstance) {
|
|
249
|
+
return {};
|
|
250
|
+
},
|
|
251
|
+
getChildHostContext(parentHostContext, type, rootContainerInstance) {
|
|
252
|
+
return parentHostContext;
|
|
253
|
+
},
|
|
254
|
+
shouldSetTextContent(type, props) {
|
|
255
|
+
if (type === "text") {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
},
|
|
260
|
+
createTextInstance(text, rootContainerInstance, hostContext) {
|
|
261
|
+
const components = getComponentCatalogue();
|
|
262
|
+
return new components["text"](rootContainerInstance.ctx, {
|
|
263
|
+
id: getNextId("text"),
|
|
264
|
+
content: text
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
scheduleTimeout: setTimeout,
|
|
268
|
+
cancelTimeout: clearTimeout,
|
|
269
|
+
noTimeout: -1,
|
|
270
|
+
shouldAttemptEagerTransition() {
|
|
271
|
+
return false;
|
|
272
|
+
},
|
|
273
|
+
finalizeInitialChildren(instance, type, props, rootContainerInstance, hostContext) {
|
|
274
|
+
setInitialProperties(instance, type, props);
|
|
275
|
+
return false;
|
|
276
|
+
},
|
|
277
|
+
commitMount(instance, type, props, internalInstanceHandle) {},
|
|
278
|
+
commitUpdate(instance, type, oldProps, newProps, internalInstanceHandle) {
|
|
279
|
+
updateProperties(instance, type, oldProps, newProps);
|
|
280
|
+
instance.requestRender();
|
|
281
|
+
},
|
|
282
|
+
commitTextUpdate(textInstance, oldText, newText) {
|
|
283
|
+
textInstance.content = newText;
|
|
284
|
+
textInstance.requestRender();
|
|
285
|
+
},
|
|
286
|
+
appendChildToContainer(container, child) {
|
|
287
|
+
container.add(child);
|
|
288
|
+
},
|
|
289
|
+
appendInitialChild(parent, child) {
|
|
290
|
+
parent.add(child);
|
|
291
|
+
},
|
|
292
|
+
hideInstance(instance) {
|
|
293
|
+
instance.visible = false;
|
|
294
|
+
instance.requestRender();
|
|
295
|
+
},
|
|
296
|
+
unhideInstance(instance, props) {
|
|
297
|
+
instance.visible = true;
|
|
298
|
+
instance.requestRender();
|
|
299
|
+
},
|
|
300
|
+
hideTextInstance(textInstance) {
|
|
301
|
+
textInstance.visible = false;
|
|
302
|
+
textInstance.requestRender();
|
|
303
|
+
},
|
|
304
|
+
unhideTextInstance(textInstance, text) {
|
|
305
|
+
textInstance.visible = true;
|
|
306
|
+
textInstance.requestRender();
|
|
307
|
+
},
|
|
308
|
+
clearContainer(container) {
|
|
309
|
+
const children = container.getChildren();
|
|
310
|
+
children.forEach((child) => container.remove(child.id));
|
|
311
|
+
},
|
|
312
|
+
setCurrentUpdatePriority(newPriority) {
|
|
313
|
+
currentUpdatePriority = newPriority;
|
|
314
|
+
},
|
|
315
|
+
getCurrentUpdatePriority: () => currentUpdatePriority,
|
|
316
|
+
resolveUpdatePriority() {
|
|
317
|
+
if (currentUpdatePriority !== NoEventPriority) {
|
|
318
|
+
return currentUpdatePriority;
|
|
319
|
+
}
|
|
320
|
+
return DefaultEventPriority;
|
|
321
|
+
},
|
|
322
|
+
maySuspendCommit() {
|
|
323
|
+
return false;
|
|
324
|
+
},
|
|
325
|
+
NotPendingTransition: null,
|
|
326
|
+
HostTransitionContext: createContext2(null),
|
|
327
|
+
resetFormInstance() {},
|
|
328
|
+
requestPostPaintCallback() {},
|
|
329
|
+
trackSchedulerEvent() {},
|
|
330
|
+
resolveEventType() {
|
|
331
|
+
return null;
|
|
332
|
+
},
|
|
333
|
+
resolveEventTimeStamp() {
|
|
334
|
+
return -1.1;
|
|
335
|
+
},
|
|
336
|
+
preloadInstance() {
|
|
337
|
+
return true;
|
|
338
|
+
},
|
|
339
|
+
startSuspendingCommit() {},
|
|
340
|
+
suspendInstance() {},
|
|
341
|
+
waitForCommitToBeReady() {
|
|
342
|
+
return null;
|
|
343
|
+
},
|
|
344
|
+
detachDeletedInstance(instance) {
|
|
345
|
+
if (!instance.parent) {
|
|
346
|
+
instance.destroy();
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
getPublicInstance(instance) {
|
|
350
|
+
return instance;
|
|
351
|
+
},
|
|
352
|
+
preparePortalMount(containerInfo) {},
|
|
353
|
+
isPrimaryRenderer: true,
|
|
354
|
+
getInstanceFromNode() {
|
|
355
|
+
return null;
|
|
356
|
+
},
|
|
357
|
+
beforeActiveInstanceBlur() {},
|
|
358
|
+
afterActiveInstanceBlur() {},
|
|
359
|
+
prepareScopeUpdate() {},
|
|
360
|
+
getInstanceFromScope() {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// src/reconciler/reconciler.ts
|
|
366
|
+
var reconciler = ReactReconciler(hostConfig);
|
|
367
|
+
function _render(element, root) {
|
|
368
|
+
const container = reconciler.createContainer(root, ConcurrentRoot, null, false, null, "", console.error, console.error, console.error, console.error, null);
|
|
369
|
+
reconciler.updateContainer(element, container, null, () => {});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/reconciler/renderer.ts
|
|
373
|
+
var keyHandler = getKeyHandler();
|
|
374
|
+
async function render(node, rendererConfig = {}) {
|
|
375
|
+
const renderer = await createCliRenderer(rendererConfig);
|
|
376
|
+
_render(React.createElement(AppContext.Provider, { value: { keyHandler, renderer } }, node), renderer.root);
|
|
377
|
+
}
|
|
378
|
+
export {
|
|
379
|
+
render
|
|
380
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ASCIIFontOptions, ASCIIFontRenderable, BoxOptions, BoxRenderable, InputRenderable, InputRenderableOptions, Renderable, RenderableOptions, RenderContext, ScrollBoxOptions, ScrollBoxRenderable, SelectOption, SelectRenderable, SelectRenderableOptions, StyledText, TabSelectOption, TabSelectRenderable, TabSelectRenderableOptions, TextChunk, TextOptions, TextRenderable } from "@opentui/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
/** Properties that should not be included in the style prop */
|
|
4
|
+
export type NonStyledProps = "id" | "buffered" | "live" | "enableLayout" | "selectable" | "renderAfter" | "renderBefore" | `on${string}`;
|
|
5
|
+
/** React-specific props for all components */
|
|
6
|
+
export type ReactProps<TRenderable = unknown> = {
|
|
7
|
+
key?: React.Key;
|
|
8
|
+
ref?: React.Ref<TRenderable>;
|
|
9
|
+
};
|
|
10
|
+
/** Base type for any renderable constructor */
|
|
11
|
+
export type RenderableConstructor<TRenderable extends Renderable = Renderable> = new (ctx: RenderContext, options: any) => TRenderable;
|
|
12
|
+
/** Extract the options type from a renderable constructor */
|
|
13
|
+
type ExtractRenderableOptions<TConstructor> = TConstructor extends new (ctx: RenderContext, options: infer TOptions) => any ? TOptions : never;
|
|
14
|
+
/** Extract the renderable type from a constructor */
|
|
15
|
+
type ExtractRenderable<TConstructor> = TConstructor extends new (ctx: RenderContext, options: any) => infer TRenderable ? TRenderable : never;
|
|
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" : TConstructor extends RenderableConstructor<InputRenderable> ? NonStyledProps | "placeholder" | "value" : NonStyledProps;
|
|
18
|
+
/** Base props for container components that accept children */
|
|
19
|
+
type ContainerProps<TOptions> = TOptions & {
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
};
|
|
22
|
+
/** Smart component props that automatically determine excluded properties */
|
|
23
|
+
type ComponentProps<TOptions extends RenderableOptions<TRenderable>, TRenderable extends Renderable> = TOptions & {
|
|
24
|
+
style?: Partial<Omit<TOptions, GetNonStyledProperties<RenderableConstructor<TRenderable>>>>;
|
|
25
|
+
} & ReactProps<TRenderable>;
|
|
26
|
+
/** Valid text content types for Text component children */
|
|
27
|
+
type TextChildren = string | number | boolean | null | undefined;
|
|
28
|
+
export type TextProps = ComponentProps<TextOptions, TextRenderable> & {
|
|
29
|
+
children?: TextChildren | StyledText | TextChunk | Array<TextChildren | StyledText | TextChunk>;
|
|
30
|
+
};
|
|
31
|
+
export type BoxProps = ComponentProps<ContainerProps<BoxOptions>, BoxRenderable>;
|
|
32
|
+
export type InputProps = ComponentProps<InputRenderableOptions, InputRenderable> & {
|
|
33
|
+
focused?: boolean;
|
|
34
|
+
onInput?: (value: string) => void;
|
|
35
|
+
onChange?: (value: string) => void;
|
|
36
|
+
onSubmit?: (value: string) => void;
|
|
37
|
+
};
|
|
38
|
+
export type SelectProps = ComponentProps<SelectRenderableOptions, SelectRenderable> & {
|
|
39
|
+
focused?: boolean;
|
|
40
|
+
onChange?: (index: number, option: SelectOption | null) => void;
|
|
41
|
+
onSelect?: (index: number, option: SelectOption | null) => void;
|
|
42
|
+
};
|
|
43
|
+
export type ScrollBoxProps = ComponentProps<ContainerProps<ScrollBoxOptions>, ScrollBoxRenderable> & {
|
|
44
|
+
focused?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type AsciiFontProps = ComponentProps<ASCIIFontOptions, ASCIIFontRenderable>;
|
|
47
|
+
export type TabSelectProps = ComponentProps<TabSelectRenderableOptions, TabSelectRenderable> & {
|
|
48
|
+
focused?: boolean;
|
|
49
|
+
onChange?: (index: number, option: TabSelectOption | null) => void;
|
|
50
|
+
onSelect?: (index: number, option: TabSelectOption | null) => void;
|
|
51
|
+
};
|
|
52
|
+
/** Convert renderable constructor to component props with proper style exclusions */
|
|
53
|
+
export type ExtendedComponentProps<TConstructor extends RenderableConstructor, TOptions = ExtractRenderableOptions<TConstructor>> = TOptions & {
|
|
54
|
+
children?: React.ReactNode;
|
|
55
|
+
style?: Partial<Omit<TOptions, GetNonStyledProperties<TConstructor>>>;
|
|
56
|
+
} & ReactProps<ExtractRenderable<TConstructor>>;
|
|
57
|
+
/** Helper type to create JSX element properties from a component catalogue */
|
|
58
|
+
export type ExtendedIntrinsicElements<TComponentCatalogue extends Record<string, RenderableConstructor>> = {
|
|
59
|
+
[TComponentName in keyof TComponentCatalogue]: ExtendedComponentProps<TComponentCatalogue[TComponentName]>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Global augmentation interface for extended components
|
|
63
|
+
* This will be augmented by user code using module augmentation
|
|
64
|
+
*/
|
|
65
|
+
export interface OpenTUIComponents {
|
|
66
|
+
[componentName: string]: RenderableConstructor;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Renderable, RootRenderable, TextRenderable } from "@opentui/core";
|
|
2
|
+
import { baseComponents } from "../components";
|
|
3
|
+
export type Type = keyof typeof baseComponents;
|
|
4
|
+
export type Props = Record<string, any>;
|
|
5
|
+
export type Container = RootRenderable;
|
|
6
|
+
export type Instance = Renderable;
|
|
7
|
+
export type TextInstance = TextRenderable;
|
|
8
|
+
export type PublicInstance = Instance;
|
|
9
|
+
export type HostContext = Record<string, any>;
|