ugly but works
This commit is contained in:
@@ -10,7 +10,9 @@
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./tool": "./src/tool.ts"
|
||||
"./tool": "./src/tool.ts",
|
||||
"./jsx-runtime": "./src/jsx-runtime.ts",
|
||||
"./jsx-dev-runtime": "./src/jsx-dev-runtime.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -18,6 +18,7 @@ import type { BunShell } from "./shell"
|
||||
import { type ToolDefinition } from "./tool"
|
||||
|
||||
export * from "./tool"
|
||||
export { getTuiJSXRuntime, setTuiJSXRuntime, type TuiJSXRuntime } from "./jsx"
|
||||
export type { CliRenderer, SlotMode } from "@opentui/core"
|
||||
|
||||
export type ProviderContext = {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { getTuiJSXRuntime } from "./jsx"
|
||||
|
||||
const runtime = getTuiJSXRuntime()
|
||||
|
||||
export const Fragment = runtime.Fragment
|
||||
export const jsx = runtime.jsx
|
||||
export const jsxs = runtime.jsxs
|
||||
export const jsxDEV = runtime.jsxDEV ?? runtime.jsx
|
||||
@@ -0,0 +1,7 @@
|
||||
import { getTuiJSXRuntime } from "./jsx"
|
||||
|
||||
const runtime = getTuiJSXRuntime()
|
||||
|
||||
export const Fragment = runtime.Fragment
|
||||
export const jsx = runtime.jsx
|
||||
export const jsxs = runtime.jsxs
|
||||
@@ -0,0 +1,27 @@
|
||||
type TuiJSXFactory = (...args: unknown[]) => unknown
|
||||
|
||||
export type TuiJSXRuntime = {
|
||||
Fragment: unknown
|
||||
jsx: TuiJSXFactory
|
||||
jsxs: TuiJSXFactory
|
||||
jsxDEV?: TuiJSXFactory
|
||||
}
|
||||
|
||||
const key = Symbol.for("opencode.tui.jsx-runtime")
|
||||
|
||||
export function setTuiJSXRuntime(runtime: TuiJSXRuntime) {
|
||||
;(globalThis as Record<PropertyKey, unknown>)[key] = runtime
|
||||
}
|
||||
|
||||
export function getTuiJSXRuntime() {
|
||||
const runtime = (globalThis as Record<PropertyKey, unknown>)[key]
|
||||
if (!runtime || typeof runtime !== "object") {
|
||||
throw new Error("OpenCode TUI JSX runtime has not been initialized")
|
||||
}
|
||||
const jsx = (runtime as Record<string, unknown>).jsx
|
||||
const jsxs = (runtime as Record<string, unknown>).jsxs
|
||||
if (typeof jsx !== "function" || typeof jsxs !== "function") {
|
||||
throw new Error("OpenCode TUI JSX runtime has invalid factories")
|
||||
}
|
||||
return runtime as TuiJSXRuntime
|
||||
}
|
||||
Reference in New Issue
Block a user