Skip to main content
Glama
deleonio
by deleonio
toolbar-items.ts1.13 kB
import type { Generic } from 'adopted-style-sheets'; import type { ButtonProps, LinkProps } from '../../schema'; import { emptyStringByArrayHandler, objectObjectHandler, parseJson, setState } from '../utils'; /* types */ export type ToolbarItemPropType = | ({ type: 'button'; } & ButtonProps) | ({ type: 'link'; } & LinkProps); export type ToolbarItemsPropType = ToolbarItemPropType[]; /** * Defines the primary toolbar items. */ export type PropToolbarItems = { items: ToolbarItemsPropType; }; /* validator */ export const validateToolbarItems = (component: Generic.Element.Component, value?: ToolbarItemsPropType): void => { emptyStringByArrayHandler(value, () => { objectObjectHandler(value, () => { if (typeof value === 'undefined') { value = []; } try { value = parseJson<ToolbarItemPropType[]>(value); // eslint-disable-next-line no-empty } catch (e) { // value keeps the original items } if (Array.isArray(value) && value.every((items: ToolbarItemPropType) => typeof items === 'object' && items !== null)) { setState(component, '_items', value); } }); }); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deleonio/public-ui-kolibri'

If you have feedback or need assistance with the MCP directory API, please join our Discord server