ObjectStackObjectStack

Widget

Widget protocol schemas

Widget Lifecycle Hooks Schema

Defines lifecycle callbacks for custom widgets inspired by Web Components and React.

These hooks allow widgets to perform initialization, cleanup, and respond to changes.

@see https://developer.mozilla.org/en-US/docs/Web/API/Web_components

@see https://react.dev/reference/react/Component#component-lifecycle

@example


const widget = \{

lifecycle: \{

onMount: "console.log('Widget mounted')",

onUpdate: "if (prevProps.value !== props.value) \{ updateUI() \}",

onUnmount: "cleanup()",

onValidate: "return value.length > 0 ? null : 'Required field'"

\}

\}

Source: packages/spec/src/ui/widget.zod.ts

TypeScript Usage

import { WidgetEvent, WidgetLifecycle, WidgetManifest, WidgetProperty, WidgetSource } from '@objectstack/spec/ui';
import type { WidgetEvent, WidgetLifecycle, WidgetManifest, WidgetProperty, WidgetSource } from '@objectstack/spec/ui';

// Validate data
const result = WidgetEvent.parse(data);

WidgetEvent

Properties

PropertyTypeRequiredDescription
namestringEvent name
labelstringoptionalHuman-readable event label
descriptionstringoptionalEvent description and usage
bubblesbooleanWhether event bubbles
cancelablebooleanWhether event is cancelable
payloadRecord<string, any>optionalEvent payload schema

WidgetLifecycle

Properties

PropertyTypeRequiredDescription
onMountstringoptionalInitialization code when widget mounts
onUpdatestringoptionalCode to run when props change
onUnmountstringoptionalCleanup code when widget unmounts
onValidatestringoptionalCustom validation logic
onFocusstringoptionalCode to run on focus
onBlurstringoptionalCode to run on blur
onErrorstringoptionalError handling code

WidgetManifest

Properties

PropertyTypeRequiredDescription
namestringWidget identifier (snake_case)
labelstringWidget display name
descriptionstringoptionalWidget description
versionstringoptionalWidget version (semver)
authorstringoptionalWidget author
iconstringoptionalWidget icon
fieldTypesstring[]optionalSupported field types
categoryEnum<'input' | 'display' | 'picker' | 'editor' | 'custom'>Widget category
lifecycleObjectoptionalLifecycle hooks
eventsObject[]optionalCustom events
propertiesObject[]optionalConfiguration properties
implementationObject | Object | ObjectoptionalWidget implementation source
dependenciesObject[]optionalWidget dependencies
screenshotsstring[]optionalScreenshot URLs
documentationstringoptionalDocumentation URL
licensestringoptionalLicense (SPDX identifier)
tagsstring[]optionalTags for categorization
ariaObjectoptionalARIA accessibility attributes
performanceObjectoptionalPerformance optimization settings

WidgetProperty

Properties

PropertyTypeRequiredDescription
namestringProperty name (camelCase)
labelstringoptionalHuman-readable label
typeEnum<'string' | 'number' | 'boolean' | 'array' | 'object' | 'function' | 'any'>TypeScript type
requiredbooleanWhether property is required
defaultanyoptionalDefault value
descriptionstringoptionalProperty description
validationRecord<string, any>optionalValidation rules
categorystringoptionalProperty category

WidgetSource

Union Options

This schema accepts one of the following structures:

Option 1

Type: npm

Properties

PropertyTypeRequiredDescription
typestring
packageNamestringNPM package name
versionstring
exportNamestringoptionalNamed export (default: default)

Option 2

Type: remote

Properties

PropertyTypeRequiredDescription
typestring
urlstringRemote entry URL (.js)
moduleNamestringExposed module name
scopestringRemote scope name

Option 3

Type: inline

Properties

PropertyTypeRequiredDescription
typestring
codestringJavaScript code body


On this page