@qitplus/guijson
v1.0.0
Published
A package for using the guijson format
Readme
GuiJson
TypeScript types for a GUI JSON schema inspired by GeoJSON.
guijson provides a typed way to describe UI trees as JSON objects. Like GeoJSON, every object is identified by a type field, which makes the schema easy to serialize, inspect, validate, and render in your own runtime.
Installation
npm install guijsonWhat It Includes
- A
GuiJsonunion for all supported GUI JSON nodes - Component types for
Container,Image,Text,Button,TextInput,Switch,Column,Row, andStack - Reference types for normalized schemas:
ReferenceandReferenceCollection - A
ComponentCollectiontype for storing reusable component definitions - Generic parameters for custom
id,style, andpropertiesshapes - Tuple-based
Actiontypes for events such asonPressandonChange
Quick Example
import type { GuiJson } from 'guijson';
type Style = {
padding?: number;
gap?: number;
fontSize?: number;
};
type Props = {
testId?: string;
};
const screen: GuiJson<string, Style, Props> = {
type: 'Column',
id: 'home',
style: { padding: 24, gap: 12 },
properties: { testId: 'home-screen' },
children: [
{
type: 'Text',
text: 'Hello, GuiJson',
style: { fontSize: 20 },
},
{
type: 'TextInput',
value: '',
placeholder: 'Search',
onChange: ['setSearch'],
},
{
type: 'Button',
onPress: ['navigate', 'details'],
child: {
type: 'Text',
text: 'Open details',
},
},
],
};Core Shape
Every GUI JSON object includes:
type: the node discriminatorid?: an optional string or number identifier
Every component may also include:
class?: a class-like labelstyle?: any style shape you define through genericsproperties?: any custom metadata shape you define through generics
Supported Types
Components
ContainerImageTextButtonTextInputSwitchColumnRowStack
Collections and References
ComponentCollectionReferenceReferenceCollection
Events
Interactive components use the Action tuple type:
type Action<K extends string = string, A extends Array<any> = Array<any>> =
[call: K, ...arguments: A];That means event handlers can stay fully serializable:
const action = ['navigate', 'settings'] as const;References Example
Use references if you want reusable or normalized component definitions.
import type { ComponentCollection, Reference } from 'guijson';
const components: ComponentCollection = {
type: 'ComponentCollection',
components: [
{ id: 'title', type: 'Text', text: 'Dashboard' },
{ id: 'hero', type: 'Image', src: '/hero.png', alt: 'Hero image' },
],
};
const titleRef: Reference = {
type: 'Reference',
reference: 'title',
};Notes
- This package currently ships TypeScript declarations only.
- It does not include a renderer, parser, or runtime validator.
- It also exposes a global
GuiJSONnamespace for non-module usage.
License
MIT
