@opentui/react 0.8.4 → 0.9.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/{chunk-dr4znwcm.js → chunk-gx97g0rc.js} +21 -104
- package/index.js +27 -26
- package/package.json +2 -2
- package/src/types/components.d.ts +1 -1
- package/test-utils.js +1 -1
|
@@ -131,8 +131,8 @@ import React2 from "react";
|
|
|
131
131
|
// src/components/error-boundary.tsx
|
|
132
132
|
import React from "react";
|
|
133
133
|
|
|
134
|
-
// jsx-
|
|
135
|
-
import { Fragment,
|
|
134
|
+
// jsx-runtime.js
|
|
135
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
136
136
|
|
|
137
137
|
// src/components/error-boundary.tsx
|
|
138
138
|
class ErrorBoundary extends React.Component {
|
|
@@ -145,13 +145,13 @@ class ErrorBoundary extends React.Component {
|
|
|
145
145
|
}
|
|
146
146
|
render() {
|
|
147
147
|
if (this.state.error) {
|
|
148
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ jsx("box", {
|
|
149
149
|
style: { flexDirection: "column", padding: 2 },
|
|
150
|
-
children: /* @__PURE__ */
|
|
150
|
+
children: /* @__PURE__ */ jsx("text", {
|
|
151
151
|
fg: "red",
|
|
152
152
|
children: this.state.error.stack || this.state.error.message
|
|
153
|
-
}
|
|
154
|
-
}
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
155
|
}
|
|
156
156
|
return this.props.children;
|
|
157
157
|
}
|
|
@@ -166,7 +166,7 @@ import { ImageRenderable as ImageRenderable2, TextNodeRenderable as TextNodeRend
|
|
|
166
166
|
// package.json
|
|
167
167
|
var package_default = {
|
|
168
168
|
name: "@opentui/react",
|
|
169
|
-
version: "0.
|
|
169
|
+
version: "0.9.0",
|
|
170
170
|
description: "React renderer for building terminal user interfaces using OpenTUI core",
|
|
171
171
|
license: "MIT",
|
|
172
172
|
repository: {
|
|
@@ -258,118 +258,33 @@ function getNextId(type) {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
// src/utils/index.ts
|
|
261
|
-
import {
|
|
262
|
-
InputRenderable as InputRenderable2,
|
|
263
|
-
InputRenderableEvents,
|
|
264
|
-
isRenderable,
|
|
265
|
-
SelectRenderable as SelectRenderable2,
|
|
266
|
-
SelectRenderableEvents,
|
|
267
|
-
TabSelectRenderable as TabSelectRenderable2,
|
|
268
|
-
TabSelectRenderableEvents,
|
|
269
|
-
TextareaRenderable as TextareaRenderable2
|
|
270
|
-
} from "@opentui/core";
|
|
271
|
-
function initEventListeners(instance, eventName, listener, previousListener) {
|
|
272
|
-
if (previousListener) {
|
|
273
|
-
instance.off(eventName, previousListener);
|
|
274
|
-
}
|
|
275
|
-
if (listener) {
|
|
276
|
-
instance.on(eventName, listener);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
function setStyle(instance, styles, oldStyles) {
|
|
280
|
-
if (oldStyles != null && typeof oldStyles === "object") {
|
|
281
|
-
for (const styleName in oldStyles) {
|
|
282
|
-
if (oldStyles.hasOwnProperty(styleName)) {
|
|
283
|
-
if (styles == null || !styles.hasOwnProperty(styleName)) {
|
|
284
|
-
instance[styleName] = null;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
if (styles != null && typeof styles === "object") {
|
|
290
|
-
for (const styleName in styles) {
|
|
291
|
-
if (styles.hasOwnProperty(styleName)) {
|
|
292
|
-
const value = styles[styleName];
|
|
293
|
-
const oldValue = oldStyles?.[styleName];
|
|
294
|
-
if (value !== oldValue) {
|
|
295
|
-
instance[styleName] = value;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
function setProperty(instance, type, propKey, propValue, oldPropValue) {
|
|
302
|
-
switch (propKey) {
|
|
303
|
-
case "onChange":
|
|
304
|
-
if (instance instanceof InputRenderable2) {
|
|
305
|
-
initEventListeners(instance, InputRenderableEvents.CHANGE, propValue, oldPropValue);
|
|
306
|
-
} else if (instance instanceof SelectRenderable2) {
|
|
307
|
-
initEventListeners(instance, SelectRenderableEvents.SELECTION_CHANGED, propValue, oldPropValue);
|
|
308
|
-
} else if (instance instanceof TabSelectRenderable2) {
|
|
309
|
-
initEventListeners(instance, TabSelectRenderableEvents.SELECTION_CHANGED, propValue, oldPropValue);
|
|
310
|
-
}
|
|
311
|
-
break;
|
|
312
|
-
case "onInput":
|
|
313
|
-
if (instance instanceof InputRenderable2) {
|
|
314
|
-
initEventListeners(instance, InputRenderableEvents.INPUT, propValue, oldPropValue);
|
|
315
|
-
}
|
|
316
|
-
break;
|
|
317
|
-
case "onSubmit":
|
|
318
|
-
if (instance instanceof InputRenderable2) {
|
|
319
|
-
initEventListeners(instance, InputRenderableEvents.ENTER, propValue, oldPropValue);
|
|
320
|
-
} else if (instance instanceof TextareaRenderable2) {
|
|
321
|
-
instance.onSubmit = propValue;
|
|
322
|
-
}
|
|
323
|
-
break;
|
|
324
|
-
case "onSelect":
|
|
325
|
-
if (instance instanceof SelectRenderable2) {
|
|
326
|
-
initEventListeners(instance, SelectRenderableEvents.ITEM_SELECTED, propValue, oldPropValue);
|
|
327
|
-
} else if (instance instanceof TabSelectRenderable2) {
|
|
328
|
-
initEventListeners(instance, TabSelectRenderableEvents.ITEM_SELECTED, propValue, oldPropValue);
|
|
329
|
-
}
|
|
330
|
-
break;
|
|
331
|
-
case "focused":
|
|
332
|
-
if (isRenderable(instance)) {
|
|
333
|
-
if (!!propValue) {
|
|
334
|
-
instance.focus();
|
|
335
|
-
} else {
|
|
336
|
-
instance.blur();
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
break;
|
|
340
|
-
case "style":
|
|
341
|
-
setStyle(instance, propValue, oldPropValue);
|
|
342
|
-
break;
|
|
343
|
-
case "children":
|
|
344
|
-
break;
|
|
345
|
-
default:
|
|
346
|
-
instance[propKey] = propValue;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
261
|
+
import { setRenderableProp } from "@opentui/core";
|
|
349
262
|
function setInitialProperties(instance, type, props) {
|
|
350
263
|
for (const propKey in props) {
|
|
351
|
-
if (!props.hasOwnProperty(propKey)) {
|
|
264
|
+
if (!props.hasOwnProperty(propKey) || propKey === "children") {
|
|
352
265
|
continue;
|
|
353
266
|
}
|
|
354
267
|
const propValue = props[propKey];
|
|
355
268
|
if (propValue == null) {
|
|
356
269
|
continue;
|
|
357
270
|
}
|
|
358
|
-
|
|
271
|
+
setRenderableProp(instance, propKey, propValue, undefined);
|
|
359
272
|
}
|
|
360
273
|
}
|
|
361
274
|
function updateProperties(instance, type, oldProps, newProps) {
|
|
362
275
|
for (const propKey in oldProps) {
|
|
363
276
|
const oldProp = oldProps[propKey];
|
|
364
|
-
if (oldProps.hasOwnProperty(propKey) && oldProp
|
|
365
|
-
|
|
277
|
+
if (oldProps.hasOwnProperty(propKey) && oldProp !== undefined && !newProps.hasOwnProperty(propKey)) {
|
|
278
|
+
if (propKey !== "children")
|
|
279
|
+
setRenderableProp(instance, propKey, undefined, oldProp);
|
|
366
280
|
}
|
|
367
281
|
}
|
|
368
282
|
for (const propKey in newProps) {
|
|
369
283
|
const newProp = newProps[propKey];
|
|
370
284
|
const oldProp = oldProps[propKey];
|
|
371
|
-
if (newProps.hasOwnProperty(propKey) && newProp !== oldProp
|
|
372
|
-
|
|
285
|
+
if (newProps.hasOwnProperty(propKey) && newProp !== oldProp) {
|
|
286
|
+
if (propKey !== "children")
|
|
287
|
+
setRenderableProp(instance, propKey, newProp, oldProp);
|
|
373
288
|
}
|
|
374
289
|
}
|
|
375
290
|
}
|
|
@@ -414,7 +329,8 @@ var hostConfig = {
|
|
|
414
329
|
parent.insertBefore(child, beforeChild);
|
|
415
330
|
},
|
|
416
331
|
insertInContainerBefore(parent, child, beforeChild) {
|
|
417
|
-
parent
|
|
332
|
+
const target = parent;
|
|
333
|
+
target.insertBefore(child, beforeChild);
|
|
418
334
|
},
|
|
419
335
|
removeChildFromContainer(parent, child) {
|
|
420
336
|
if (!child.parent)
|
|
@@ -464,7 +380,8 @@ var hostConfig = {
|
|
|
464
380
|
textInstance.children = [newText];
|
|
465
381
|
},
|
|
466
382
|
appendChildToContainer(container, child) {
|
|
467
|
-
container
|
|
383
|
+
const target = container;
|
|
384
|
+
target.add(child);
|
|
468
385
|
},
|
|
469
386
|
appendInitialChild(parent, child) {
|
|
470
387
|
parent.add(child);
|
|
@@ -605,4 +522,4 @@ function createRoot2(renderer) {
|
|
|
605
522
|
};
|
|
606
523
|
}
|
|
607
524
|
|
|
608
|
-
export { baseComponents2, componentCatalogue2, extend2, getComponentCatalogue2, AppContext2, useAppContext2, Fragment,
|
|
525
|
+
export { baseComponents2, componentCatalogue2, extend2, getComponentCatalogue2, AppContext2, useAppContext2, Fragment, jsx, jsxs, flushSync2, createPortal2, createRoot2 };
|
package/index.js
CHANGED
|
@@ -7,11 +7,12 @@ import {
|
|
|
7
7
|
AppContext2,
|
|
8
8
|
useAppContext2,
|
|
9
9
|
Fragment,
|
|
10
|
-
|
|
10
|
+
jsx,
|
|
11
|
+
jsxs,
|
|
11
12
|
flushSync2,
|
|
12
13
|
createPortal2,
|
|
13
14
|
createRoot2
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-gx97g0rc.js";
|
|
15
16
|
// src/hooks/use-animation-tick.ts
|
|
16
17
|
import { useEffect } from "react";
|
|
17
18
|
|
|
@@ -234,11 +235,11 @@ function getSlotProps(props) {
|
|
|
234
235
|
}
|
|
235
236
|
function createSlot(registry, options = {}) {
|
|
236
237
|
return function BoundSlot(props) {
|
|
237
|
-
return /* @__PURE__ */
|
|
238
|
+
return /* @__PURE__ */ jsx(Slot, {
|
|
238
239
|
...props,
|
|
239
240
|
registry,
|
|
240
241
|
pluginFailurePlaceholder: options.pluginFailurePlaceholder
|
|
241
|
-
}
|
|
242
|
+
});
|
|
242
243
|
};
|
|
243
244
|
}
|
|
244
245
|
function Slot(props) {
|
|
@@ -278,7 +279,7 @@ function Slot(props) {
|
|
|
278
279
|
const rendered = entry.renderer(registry.context, slotProps);
|
|
279
280
|
renderFailuresByPluginRef.current.delete(failureKey);
|
|
280
281
|
pendingRenderReportsRef.current.delete(failureKey);
|
|
281
|
-
return /* @__PURE__ */
|
|
282
|
+
return /* @__PURE__ */ jsx(PluginErrorBoundary, {
|
|
282
283
|
registry,
|
|
283
284
|
pluginFailurePlaceholder: props.pluginFailurePlaceholder,
|
|
284
285
|
pluginId: entry.id,
|
|
@@ -286,7 +287,7 @@ function Slot(props) {
|
|
|
286
287
|
resetToken: version,
|
|
287
288
|
fallbackOnFailure,
|
|
288
289
|
children: rendered
|
|
289
|
-
}, key
|
|
290
|
+
}, key);
|
|
290
291
|
} catch (error) {
|
|
291
292
|
const normalizedError = error instanceof Error ? error : typeof error === "string" ? new Error(error) : new Error(String(error));
|
|
292
293
|
const lastFailure = renderFailuresByPluginRef.current.get(failureKey);
|
|
@@ -314,62 +315,62 @@ function Slot(props) {
|
|
|
314
315
|
if (placeholder === null || placeholder === undefined || placeholder === false) {
|
|
315
316
|
return fallbackOnFailure ?? null;
|
|
316
317
|
}
|
|
317
|
-
return /* @__PURE__ */
|
|
318
|
+
return /* @__PURE__ */ jsx(Fragment2, {
|
|
318
319
|
children: placeholder
|
|
319
|
-
}, key
|
|
320
|
+
}, key);
|
|
320
321
|
}
|
|
321
322
|
};
|
|
322
323
|
if (entries.length === 0) {
|
|
323
|
-
return /* @__PURE__ */
|
|
324
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
324
325
|
children: props.children
|
|
325
|
-
}
|
|
326
|
+
});
|
|
326
327
|
}
|
|
327
328
|
if (props.mode === "single_winner") {
|
|
328
329
|
const winner = entries[0];
|
|
329
330
|
if (!winner) {
|
|
330
|
-
return /* @__PURE__ */
|
|
331
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
331
332
|
children: props.children
|
|
332
|
-
}
|
|
333
|
+
});
|
|
333
334
|
}
|
|
334
335
|
const rendered = renderEntry(winner, props.children);
|
|
335
336
|
if (rendered === null || rendered === undefined || rendered === false) {
|
|
336
|
-
return /* @__PURE__ */
|
|
337
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
337
338
|
children: props.children
|
|
338
|
-
}
|
|
339
|
+
});
|
|
339
340
|
}
|
|
340
|
-
return /* @__PURE__ */
|
|
341
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
341
342
|
children: rendered
|
|
342
|
-
}
|
|
343
|
+
});
|
|
343
344
|
}
|
|
344
345
|
if (props.mode === "replace") {
|
|
345
346
|
if (entries.length === 1) {
|
|
346
347
|
const rendered = renderEntry(entries[0], props.children);
|
|
347
348
|
if (rendered === null || rendered === undefined || rendered === false) {
|
|
348
|
-
return /* @__PURE__ */
|
|
349
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
349
350
|
children: props.children
|
|
350
|
-
}
|
|
351
|
+
});
|
|
351
352
|
}
|
|
352
|
-
return /* @__PURE__ */
|
|
353
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
353
354
|
children: rendered
|
|
354
|
-
}
|
|
355
|
+
});
|
|
355
356
|
}
|
|
356
357
|
const renderedEntries = entries.map((entry) => renderEntry(entry));
|
|
357
358
|
const hasPluginOutput = renderedEntries.some((node) => node !== null && node !== undefined && node !== false);
|
|
358
359
|
if (!hasPluginOutput) {
|
|
359
|
-
return /* @__PURE__ */
|
|
360
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
360
361
|
children: props.children
|
|
361
|
-
}
|
|
362
|
+
});
|
|
362
363
|
}
|
|
363
|
-
return /* @__PURE__ */
|
|
364
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
364
365
|
children: renderedEntries
|
|
365
|
-
}
|
|
366
|
+
});
|
|
366
367
|
}
|
|
367
|
-
return /* @__PURE__ */
|
|
368
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
368
369
|
children: [
|
|
369
370
|
props.children,
|
|
370
371
|
entries.map((entry) => renderEntry(entry))
|
|
371
372
|
]
|
|
372
|
-
}
|
|
373
|
+
});
|
|
373
374
|
}
|
|
374
375
|
// src/time-to-first-draw.tsx
|
|
375
376
|
import { TimeToFirstDrawRenderable } from "@opentui/core";
|
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.
|
|
7
|
+
"version": "0.9.0",
|
|
8
8
|
"description": "React renderer for building terminal user interfaces using OpenTUI core",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@opentui/core": "0.
|
|
55
|
+
"@opentui/core": "0.9.0",
|
|
56
56
|
"react-reconciler": "^0.33.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
@@ -14,7 +14,7 @@ type ExtractRenderableOptions<TConstructor> = TConstructor extends new (ctx: Ren
|
|
|
14
14
|
/** Extract the renderable type from a constructor */
|
|
15
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" | "bottomTitle" : TConstructor extends RenderableConstructor<ASCIIFontRenderable> ? NonStyledProps | "text" | "selectable" : TConstructor extends RenderableConstructor<InputRenderable> ? NonStyledProps | "placeholder" | "value" : TConstructor extends RenderableConstructor<TextareaRenderable> ? NonStyledProps | "placeholder" | "initialValue" : TConstructor extends RenderableConstructor<CodeRenderable> ? NonStyledProps | "content" | "filetype" | "syntaxStyle" | "treeSitterClient" | "conceal" | "drawUnstyledText" : TConstructor extends RenderableConstructor<MarkdownRenderable> ? NonStyledProps | "content" | "syntaxStyle" | "treeSitterClient" | "conceal" | "
|
|
17
|
+
export type GetNonStyledProperties<TConstructor> = TConstructor extends RenderableConstructor<TextRenderable> ? NonStyledProps | "content" : TConstructor extends RenderableConstructor<BoxRenderable> ? NonStyledProps | "title" | "bottomTitle" : TConstructor extends RenderableConstructor<ASCIIFontRenderable> ? NonStyledProps | "text" | "selectable" : TConstructor extends RenderableConstructor<InputRenderable> ? NonStyledProps | "placeholder" | "value" : TConstructor extends RenderableConstructor<TextareaRenderable> ? NonStyledProps | "placeholder" | "initialValue" : TConstructor extends RenderableConstructor<CodeRenderable> ? NonStyledProps | "content" | "filetype" | "syntaxStyle" | "treeSitterClient" | "conceal" | "drawUnstyledText" : TConstructor extends RenderableConstructor<MarkdownRenderable> ? NonStyledProps | "content" | "syntaxStyle" | "treeSitterClient" | "conceal" | "renderBlock" : TConstructor extends RenderableConstructor<ImageRenderable> ? NonStyledProps | "source" : TConstructor extends RenderableConstructor<VideoRenderable> ? NonStyledProps | "source" | "autoplay" | "loop" | "audio" | "muted" | "volume" | "avSyncOffsetMs" | "maxFps" : NonStyledProps;
|
|
18
18
|
/** Base props for container components that accept children */
|
|
19
19
|
type ContainerProps<TOptions> = TOptions & {
|
|
20
20
|
children?: React.ReactNode;
|