gnata-sqlite
Reference

React Widget API

Complete API reference for @gnata-sqlite/react — hooks, components, theme, and utilities

React Widget API

npm install @gnata-sqlite/react
npx @gnata-sqlite/react setup ./public

Hooks

useJsonataLsp(options?)

Loads the LSP WASM module for editor features (diagnostics, autocomplete, hover). Works with zero configuration after running the setup command above.

const lsp = useJsonataLsp()
// or with custom URLs:
const lsp = useJsonataLsp({ lspWasmUrl: '/custom/gnata-lsp.wasm', lspExecUrl: '/custom/lsp-wasm_exec.js' })
OptionTypeDefaultDescription
lspWasmUrlstring'/gnata-lsp.wasm'URL to gnata-lsp.wasm
lspExecUrlstring'/lsp-wasm_exec.js'URL to lsp-wasm_exec.js

Returns WasmState (see below).


useJsonataWasm(options?)

Full WASM loader — loads LSP by default, plus the optional eval engine. Use useJsonataLsp for the common case; use this hook only when client-side evaluation is needed.

OptionTypeDefaultDescription
evalWasmUrlstringURL to gnata.wasm (opt-in, ~5.3MB)
evalExecUrlstringURL to wasm_exec.js (required with evalWasmUrl)
lspWasmUrlstring'/gnata-lsp.wasm'URL to gnata-lsp.wasm
lspExecUrlstring'/lsp-wasm_exec.js'URL to lsp-wasm_exec.js

Returns WasmState:

FieldTypeDescription
isReadybooleanEval module loaded
isLspReadybooleanLSP module loaded
errorError | nullLoading error
gnataEval(expr, json) => stringEvaluate expression
gnataCompile(expr) => stringCompile to AST JSON
gnataDiagnostics(doc) => stringGet parse diagnostics
gnataCompletions(doc, pos, schema) => stringGet completions
gnataHover(doc, pos, schema) => string | nullGet hover info

useJsonataEval(expression, inputJson, gnataEval, debounceMs?)

Evaluates an expression with debouncing (default 300ms).

ArgumentTypeDescription
expressionstringJSONata expression to evaluate
inputJsonstringJSON input data
gnataEval((expr, data) => string) | nullThe gnataEval function from useJsonataWasm, or null if not yet loaded
debounceMsnumberOptional debounce delay in ms (default 300)
// Requires the eval engine (opt-in, build from source)
const wasm = useJsonataWasm({ evalWasmUrl: '/gnata.wasm', evalExecUrl: '/wasm_exec.js' })
const { result, error, isSuccess, timing, timingMs, evaluate } =
  useJsonataEval(expression, inputJson, wasm.gnataEval)

Returns JsonataEvalResult:

FieldTypeDescription
resultstringFormatted result
errorstring | nullError message
isSuccessbooleanWhether evaluation succeeded
timingstringHuman-readable evaluation time (e.g. "12ms")
timingMsnumberEvaluation time in ms
evaluate() => voidManually trigger evaluation

useJsonataSchema(inputJson)

Builds autocomplete schema from JSON data. Memoized.

Returns: Schema object for autocomplete.


useJsonataEditor(options)

Low-level hook creating a CodeMirror 6 EditorView.

OptionTypeRequiredDescription
containerRefRefObject<HTMLElement>yesRef to the container element
initialDocstringnoInitial editor content
placeholderstringnoPlaceholder text
onChange(value: string) => voidnoContent change callback
onRun() => voidnoCmd+Enter callback
theme'dark' | 'light'noColor theme
themeOverridesobjectnoOverride specific theme tokens
themeExtensionsExtension[]noReplace built-in theme with custom extensions
gnataEval(expr, json) => stringnoEval function from WASM
gnataDiagnostics(doc) => stringnoDiagnostics function from WASM
gnataCompletions(doc, pos, schema) => stringnoCompletions function from WASM
gnataHover(doc, pos, schema) => string | nullnoHover function from WASM
getInputJson() => stringnoCurrent input JSON for autocomplete
schemaSchemanoSchema object for autocomplete
lineNumbersbooleannoShow line numbers

Returns: { view: EditorView | null, getValue: () => string, setValue: (value: string) => void, setTheme: (theme: 'dark' | 'light') => void }


useJsonataLsp(options?)

Documented above — this is the recommended hook for most use cases.


Components

<JsonataPlayground>

Full three-panel widget: expression + input + result.

PropTypeDefaultDescription
defaultExpressionstring''Initial expression
defaultInputstring'{}'Initial JSON input
wasmOptionsUseJsonataWasmOptionsOptions passed to useJsonataWasm internally
theme'dark' | 'light''dark'Color theme
heightnumber400Panel height in px
classNamestringCSS class for the container
styleCSSPropertiesInline styles for the container

<JsonataEditor>

Expression editor with optional WASM features.

PropTypeDefaultDescription
valuestringControlled value
onChange(value: string) => voidChange callback
schemaSchemaSchema object for autocomplete
gnataEval(expr, json) => stringEval function from WASM
gnataDiagnostics(doc) => stringDiagnostics function from WASM
gnataCompletions(doc, pos, schema) => stringCompletions function from WASM
gnataHover(doc, pos, schema) => string | nullHover function from WASM
themeExtensionsExtension[]Replace built-in theme with custom extensions
theme'dark' | 'light''dark'Color theme
placeholderstringPlaceholder text
getInputJson() => stringFor introspective autocomplete
onRun() => voidCmd+Enter callback

<JsonataInput>

JSON input editor.

PropTypeDefaultDescription
valuestringControlled value
onChange(value: string) => voidChange callback
theme'dark' | 'light''dark'Color theme

<JsonataResult>

Read-only result display.

PropTypeDefaultDescription
valuestring | nullResult (green)
errorstring | nullError (red)
timingstringHuman-readable eval time
theme'dark' | 'light''dark'Color theme

Theme

tokyoNightTheme(mode)

Returns CodeMirror extensions for the Tokyo Night theme.

import { tokyoNightTheme } from '@gnata-sqlite/react'
const extensions = [tokyoNightTheme('dark')]

tooltipTheme(mode)

Returns a standalone tooltip styling extension. Useful for applying consistent tooltip styles outside the main theme.

import { tooltipTheme } from '@gnata-sqlite/react'
const extensions = [tooltipTheme('dark')]

Color exports

import { darkColors, lightColors, darkTokenColors, lightTokenColors } from '@gnata-sqlite/react'
  • darkColors / lightColors — UI colors (bg, surface, text, accent, green, error, border, etc.)
  • darkTokenColors / lightTokenColors — Syntax token colors (keyword, string, number, function, property, operator, etc.)

Utilities

ExportDescription
jsonataStreamLanguageCodeMirror StreamLanguage for JSONata
buildSchema(json)Build autocomplete schema from JSON
collectKeys(obj, map, depth)Recursively collect object keys
allKeysFromJson(json, partial)Get completion items from JSON string
formatHoverMarkdown(md)Convert LSP hover markdown to HTML
formatTiming(ms)Format milliseconds to readable string

On this page