Skip to content

Dependencies

Some widgets rely on third-party libraries that GolemUI deliberately doesn’t bundle — typically because the choice of library is opinionated. The Markdown widget needs a markdown parser; you might want to add others. Dependencies are how you supply those helpers to the engine.

A dependency is a key/value pair in a Dependencies object. The key identifies what kind of helper it is (the widgets know which key to read); the value is the helper implementation.

import { Dependencies } from '@golemui/gui-shared';
const dependencies: Dependencies = {
markdown: {
parse: (md: string) => snarkdown(md),
},
};

Each widget that uses a dependency reads it at render time. If the widget needs a dependency you haven’t provided, it renders gracefully (e.g. the Markdown widget shows the editor but leaves the preview blank).

In the Programmatic API, dependencies go inside formConfig.dependencies.

import snarkdown from 'snarkdown';
import { gui } from '@golemui/gui-shared';
import { GuiForm } from '@golemui/gui-react';
const config = {
formDef: [gui.inputs.markdown('content')],
formConfig: {
dependencies: { markdown: { parse: (md: string) => snarkdown(md) } },
},
};
export function MyForm() {
return <GuiForm config={config} />;
}

In the JSON path, dependencies go into the dependencies property in the config object.

{
"form": [{ "kind": "input", "type": "markdown", "path": "content" }]
}
import snarkdown from 'snarkdown';
import { GuiForm } from '@golemui/gui-react';
import formDef from './my-form.json';
const config = {
formDef,
dependencies: { markdown: { parse: (md: string) => snarkdown(md) } },
};
export function MyForm() {
return <GuiForm config={config} />;
}
KeyUsed byShape
markdownMarkdown, Markdown Text{ parse: (md: string) => string }