@opentui/react 0.2.0 → 0.2.2

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.
@@ -166,7 +166,7 @@ import { TextNodeRenderable as TextNodeRenderable2 } from "@opentui/core";
166
166
  // package.json
167
167
  var package_default = {
168
168
  name: "@opentui/react",
169
- version: "0.2.0",
169
+ version: "0.2.2",
170
170
  description: "React renderer for building terminal user interfaces using OpenTUI core",
171
171
  license: "MIT",
172
172
  repository: {
@@ -191,6 +191,10 @@ var package_default = {
191
191
  import: "./scripts/runtime-plugin-support.ts",
192
192
  types: "./scripts/runtime-plugin-support.ts"
193
193
  },
194
+ "./runtime-plugin-support/configure": {
195
+ import: "./scripts/runtime-plugin-support-configure.ts",
196
+ types: "./scripts/runtime-plugin-support-configure.ts"
197
+ },
194
198
  "./jsx-runtime": {
195
199
  import: "./jsx-runtime.js",
196
200
  types: "./jsx-runtime.d.ts"
package/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  getComponentCatalogue,
12
12
  jsxDEV,
13
13
  useAppContext
14
- } from "./chunk-81sn2skb.js";
14
+ } from "./chunk-42jvgte5.js";
15
15
  import"./chunk-2mx7fq49.js";
16
16
  // src/hooks/use-keyboard.ts
17
17
  import { useEffect } from "react";
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.2.0",
7
+ "version": "0.2.2",
8
8
  "description": "React renderer for building terminal user interfaces using OpenTUI core",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -32,6 +32,10 @@
32
32
  "types": "./scripts/runtime-plugin-support.d.ts",
33
33
  "import": "./scripts/runtime-plugin-support.ts"
34
34
  },
35
+ "./runtime-plugin-support/configure": {
36
+ "types": "./scripts/runtime-plugin-support-configure.d.ts",
37
+ "import": "./scripts/runtime-plugin-support-configure.ts"
38
+ },
35
39
  "./jsx-runtime": {
36
40
  "types": "./jsx-runtime.d.ts",
37
41
  "import": "./jsx-runtime.js",
@@ -44,7 +48,7 @@
44
48
  }
45
49
  },
46
50
  "dependencies": {
47
- "@opentui/core": "0.2.0",
51
+ "@opentui/core": "0.2.2",
48
52
  "react-reconciler": "^0.32.0"
49
53
  },
50
54
  "devDependencies": {
@@ -0,0 +1,7 @@
1
+ import { type RuntimeModuleEntry, type RuntimePluginRewriteOptions } from "@opentui/core/runtime-plugin";
2
+ export interface ReactRuntimePluginSupportOptions {
3
+ additional?: Record<string, RuntimeModuleEntry>;
4
+ core?: RuntimeModuleEntry;
5
+ rewrite?: RuntimePluginRewriteOptions;
6
+ }
7
+ export declare function ensureRuntimePluginSupport(options?: ReactRuntimePluginSupportOptions): boolean;
@@ -0,0 +1,99 @@
1
+ import { plugin as registerBunPlugin } from "bun"
2
+ import * as coreRuntime from "@opentui/core"
3
+ import {
4
+ createRuntimePlugin,
5
+ type RuntimeModuleEntry,
6
+ type RuntimePluginRewriteOptions,
7
+ } from "@opentui/core/runtime-plugin"
8
+ import * as reactRuntime from "react"
9
+ import * as reactJsxRuntime from "react/jsx-runtime"
10
+ import * as reactJsxDevRuntime from "react/jsx-dev-runtime"
11
+ import * as opentuiReactRuntime from "../index.js"
12
+
13
+ const runtimePluginSupportInstalledKey = "__opentuiReactRuntimePluginSupportInstalled__"
14
+
15
+ export interface ReactRuntimePluginSupportOptions {
16
+ additional?: Record<string, RuntimeModuleEntry>
17
+ core?: RuntimeModuleEntry
18
+ rewrite?: RuntimePluginRewriteOptions
19
+ }
20
+
21
+ interface RuntimePluginSupportInstall {
22
+ specifiers: ReadonlySet<string>
23
+ core: RuntimeModuleEntry
24
+ rewriteKey: string
25
+ }
26
+
27
+ type RuntimePluginSupportState = typeof globalThis & {
28
+ [runtimePluginSupportInstalledKey]?: RuntimePluginSupportInstall
29
+ }
30
+
31
+ const defaultRuntimeModules: Record<string, RuntimeModuleEntry> = {
32
+ "@opentui/react": opentuiReactRuntime as Record<string, unknown>,
33
+ "@opentui/react/jsx-runtime": reactJsxRuntime as Record<string, unknown>,
34
+ "@opentui/react/jsx-dev-runtime": reactJsxDevRuntime as Record<string, unknown>,
35
+ react: reactRuntime as Record<string, unknown>,
36
+ "react/jsx-runtime": reactJsxRuntime as Record<string, unknown>,
37
+ "react/jsx-dev-runtime": reactJsxDevRuntime as Record<string, unknown>,
38
+ }
39
+
40
+ function normalizeRewriteKey(rewrite: RuntimePluginRewriteOptions | undefined): string {
41
+ return `${rewrite?.nodeModulesRuntimeSpecifiers ?? true}:${rewrite?.nodeModulesBareSpecifiers ?? false}`
42
+ }
43
+
44
+ function createRuntimeModules(options?: ReactRuntimePluginSupportOptions): Record<string, RuntimeModuleEntry> {
45
+ return {
46
+ ...defaultRuntimeModules,
47
+ ...(options?.additional ?? {}),
48
+ }
49
+ }
50
+
51
+ function assertCompatibleInstall(
52
+ install: RuntimePluginSupportInstall,
53
+ modules: Record<string, RuntimeModuleEntry>,
54
+ options?: ReactRuntimePluginSupportOptions,
55
+ ): void {
56
+ for (const specifier of Object.keys(modules)) {
57
+ if (!install.specifiers.has(specifier)) {
58
+ throw new Error(
59
+ `OpenTUI React runtime plugin support is already installed without ${specifier}. Call ensureRuntimePluginSupport({ additional }) from @opentui/react/runtime-plugin-support/configure before importing @opentui/react/runtime-plugin-support.`,
60
+ )
61
+ }
62
+ }
63
+
64
+ if (options?.core && options.core !== install.core) {
65
+ throw new Error("OpenTUI React runtime plugin support is already installed with a different core runtime module.")
66
+ }
67
+
68
+ if (options?.rewrite && normalizeRewriteKey(options.rewrite) !== install.rewriteKey) {
69
+ throw new Error("OpenTUI React runtime plugin support is already installed with different rewrite options.")
70
+ }
71
+ }
72
+
73
+ export function ensureRuntimePluginSupport(options: ReactRuntimePluginSupportOptions = {}): boolean {
74
+ const state = globalThis as RuntimePluginSupportState
75
+ const modules = createRuntimeModules(options)
76
+ const core = options.core ?? (coreRuntime as Record<string, unknown>)
77
+ const rewriteKey = normalizeRewriteKey(options.rewrite)
78
+
79
+ const install = state[runtimePluginSupportInstalledKey]
80
+ if (install) {
81
+ assertCompatibleInstall(install, modules, options)
82
+ return false
83
+ }
84
+
85
+ registerBunPlugin(
86
+ createRuntimePlugin({
87
+ core,
88
+ additional: modules,
89
+ rewrite: options.rewrite,
90
+ }),
91
+ )
92
+
93
+ state[runtimePluginSupportInstalledKey] = {
94
+ specifiers: new Set(Object.keys(modules)),
95
+ core,
96
+ rewriteKey,
97
+ }
98
+ return true
99
+ }
@@ -1 +1,3 @@
1
- export declare function ensureRuntimePluginSupport(): boolean;
1
+ import { ensureRuntimePluginSupport } from "./runtime-plugin-support-configure.js";
2
+ export { ensureRuntimePluginSupport };
3
+ export type { ReactRuntimePluginSupportOptions } from "./runtime-plugin-support-configure.js";
@@ -1,42 +1,6 @@
1
- import { plugin as registerBunPlugin } from "bun"
2
- import * as coreRuntime from "@opentui/core"
3
- import { createRuntimePlugin, type RuntimeModuleEntry } from "@opentui/core/runtime-plugin"
4
- import * as reactRuntime from "react"
5
- import * as reactJsxRuntime from "react/jsx-runtime"
6
- import * as reactJsxDevRuntime from "react/jsx-dev-runtime"
7
- import * as opentuiReactRuntime from "../index.js"
1
+ import { ensureRuntimePluginSupport } from "./runtime-plugin-support-configure.js"
8
2
 
9
- const runtimePluginSupportInstalledKey = "__opentuiReactRuntimePluginSupportInstalled__"
10
-
11
- type RuntimePluginSupportState = typeof globalThis & {
12
- [runtimePluginSupportInstalledKey]?: boolean
13
- }
14
-
15
- const additionalRuntimeModules: Record<string, RuntimeModuleEntry> = {
16
- "@opentui/react": opentuiReactRuntime as Record<string, unknown>,
17
- "@opentui/react/jsx-runtime": reactJsxRuntime as Record<string, unknown>,
18
- "@opentui/react/jsx-dev-runtime": reactJsxDevRuntime as Record<string, unknown>,
19
- react: reactRuntime as Record<string, unknown>,
20
- "react/jsx-runtime": reactJsxRuntime as Record<string, unknown>,
21
- "react/jsx-dev-runtime": reactJsxDevRuntime as Record<string, unknown>,
22
- }
23
-
24
- export function ensureRuntimePluginSupport(): boolean {
25
- const state = globalThis as RuntimePluginSupportState
26
-
27
- if (state[runtimePluginSupportInstalledKey]) {
28
- return false
29
- }
30
-
31
- registerBunPlugin(
32
- createRuntimePlugin({
33
- core: coreRuntime as Record<string, unknown>,
34
- additional: additionalRuntimeModules,
35
- }),
36
- )
37
-
38
- state[runtimePluginSupportInstalledKey] = true
39
- return true
40
- }
3
+ export { ensureRuntimePluginSupport }
4
+ export type { ReactRuntimePluginSupportOptions } from "./runtime-plugin-support-configure.js"
41
5
 
42
6
  ensureRuntimePluginSupport()
package/test-utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  createRoot
4
- } from "./chunk-81sn2skb.js";
4
+ } from "./chunk-42jvgte5.js";
5
5
  import"./chunk-2mx7fq49.js";
6
6
 
7
7
  // src/test-utils.ts