@opentui/react 0.1.13 → 0.1.14

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 CHANGED
@@ -18,7 +18,7 @@ function App() {
18
18
  <box>
19
19
  <text fg="#00FF00">Hello, Terminal!</text>
20
20
  <box title="Welcome" padding={2}>
21
- <text>Welcome to OpenTUI with React!"</text>
21
+ <text>Welcome to OpenTUI with React!</text>
22
22
  </box>
23
23
  </box>
24
24
  )
@@ -484,7 +484,7 @@ class ButtonRenderable extends BoxRenderable {
484
484
 
485
485
  set label(value: string) {
486
486
  this._label = value
487
- this.needsUpdate()
487
+ this.requestRender()
488
488
  }
489
489
  }
490
490
 
package/index.js CHANGED
@@ -34,14 +34,30 @@ var useAppContext = () => {
34
34
  };
35
35
  // src/hooks/use-keyboard.tsx
36
36
  import { useEffect } from "react";
37
+
38
+ // src/hooks/use-event.tsx
39
+ import { useCallback, useLayoutEffect, useRef } from "react";
40
+ function useEvent(handler) {
41
+ const handlerRef = useRef(handler);
42
+ useLayoutEffect(() => {
43
+ handlerRef.current = handler;
44
+ });
45
+ return useCallback((...args) => {
46
+ const fn = handlerRef.current;
47
+ return fn(...args);
48
+ }, []);
49
+ }
50
+
51
+ // src/hooks/use-keyboard.tsx
37
52
  var useKeyboard = (handler) => {
38
53
  const { keyHandler } = useAppContext();
54
+ const stableHandler = useEvent(handler);
39
55
  useEffect(() => {
40
- keyHandler?.on("keypress", handler);
56
+ keyHandler?.on("keypress", stableHandler);
41
57
  return () => {
42
- keyHandler?.off("keypress", handler);
58
+ keyHandler?.off("keypress", stableHandler);
43
59
  };
44
- }, [keyHandler, handler]);
60
+ }, [keyHandler, stableHandler]);
45
61
  };
46
62
  // src/hooks/use-renderer.tsx
47
63
  var useRenderer = () => {
@@ -68,8 +84,8 @@ import { useState } from "react";
68
84
  var useTerminalDimensions = () => {
69
85
  const renderer = useRenderer();
70
86
  const [dimensions, setDimensions] = useState({
71
- width: renderer.terminalWidth,
72
- height: renderer.terminalHeight
87
+ width: renderer.width,
88
+ height: renderer.height
73
89
  });
74
90
  const cb = (width, height) => {
75
91
  setDimensions({ width, height });
@@ -287,7 +303,7 @@ var hostConfig = {
287
303
  return null;
288
304
  },
289
305
  resetAfterCommit(containerInfo) {
290
- containerInfo.needsUpdate();
306
+ containerInfo.requestRender();
291
307
  },
292
308
  getRootHostContext(rootContainerInstance) {
293
309
  return {};
@@ -321,11 +337,11 @@ var hostConfig = {
321
337
  commitMount(instance, type, props, internalInstanceHandle) {},
322
338
  commitUpdate(instance, type, oldProps, newProps, internalInstanceHandle) {
323
339
  updateProperties(instance, type, oldProps, newProps);
324
- instance.needsUpdate();
340
+ instance.requestRender();
325
341
  },
326
342
  commitTextUpdate(textInstance, oldText, newText) {
327
343
  textInstance.content = newText;
328
- textInstance.needsUpdate();
344
+ textInstance.requestRender();
329
345
  },
330
346
  appendChildToContainer(container, child) {
331
347
  container.add(child);
@@ -335,19 +351,19 @@ var hostConfig = {
335
351
  },
336
352
  hideInstance(instance) {
337
353
  instance.visible = false;
338
- instance.needsUpdate();
354
+ instance.requestRender();
339
355
  },
340
356
  unhideInstance(instance, props) {
341
357
  instance.visible = true;
342
- instance.needsUpdate();
358
+ instance.requestRender();
343
359
  },
344
360
  hideTextInstance(textInstance) {
345
361
  textInstance.visible = false;
346
- textInstance.needsUpdate();
362
+ textInstance.requestRender();
347
363
  },
348
364
  unhideTextInstance(textInstance, text) {
349
365
  textInstance.visible = true;
350
- textInstance.needsUpdate();
366
+ textInstance.requestRender();
351
367
  },
352
368
  clearContainer(container) {
353
369
  const children = container.getChildren();
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.13",
7
+ "version": "0.1.14",
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.13",
38
+ "@opentui/core": "0.1.14",
39
39
  "react-reconciler": "^0.32.0"
40
40
  },
41
41
  "devDependencies": {
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns a stable callback that always calls the latest version of the provided handler.
3
+ * This prevents unnecessary re-renders and effect re-runs while ensuring the callback
4
+ * always has access to the latest props and state.
5
+ *
6
+ * Useful for event handlers that need to be passed to effects with empty dependency arrays
7
+ * or memoized child components.
8
+ */
9
+ export declare function useEvent<T extends (...args: any[]) => any>(handler: T): T;
@@ -238,7 +238,7 @@ var hostConfig = {
238
238
  return null;
239
239
  },
240
240
  resetAfterCommit(containerInfo) {
241
- containerInfo.needsUpdate();
241
+ containerInfo.requestRender();
242
242
  },
243
243
  getRootHostContext(rootContainerInstance) {
244
244
  return {};
@@ -272,11 +272,11 @@ var hostConfig = {
272
272
  commitMount(instance, type, props, internalInstanceHandle) {},
273
273
  commitUpdate(instance, type, oldProps, newProps, internalInstanceHandle) {
274
274
  updateProperties(instance, type, oldProps, newProps);
275
- instance.needsUpdate();
275
+ instance.requestRender();
276
276
  },
277
277
  commitTextUpdate(textInstance, oldText, newText) {
278
278
  textInstance.content = newText;
279
- textInstance.needsUpdate();
279
+ textInstance.requestRender();
280
280
  },
281
281
  appendChildToContainer(container, child) {
282
282
  container.add(child);
@@ -286,19 +286,19 @@ var hostConfig = {
286
286
  },
287
287
  hideInstance(instance) {
288
288
  instance.visible = false;
289
- instance.needsUpdate();
289
+ instance.requestRender();
290
290
  },
291
291
  unhideInstance(instance, props) {
292
292
  instance.visible = true;
293
- instance.needsUpdate();
293
+ instance.requestRender();
294
294
  },
295
295
  hideTextInstance(textInstance) {
296
296
  textInstance.visible = false;
297
- textInstance.needsUpdate();
297
+ textInstance.requestRender();
298
298
  },
299
299
  unhideTextInstance(textInstance, text) {
300
300
  textInstance.visible = true;
301
- textInstance.needsUpdate();
301
+ textInstance.requestRender();
302
302
  },
303
303
  clearContainer(container) {
304
304
  const children = container.getChildren();