This is a collection of common UI components used by RoamJS extensions and services made available to make development easier for other Roam developers.
This package takes a modular approach - each function exposed in its own file in an effort to limit the bundle sizes of consumers. It has the following directories:
components- React components used in Roamdate- Utilities made to make interacting with Roam dates easierdom- Utilities that interact with Roam's DOM structureevents- Utilities that interact with Roam's event systemhooks- React hooks commonly used in Roam extensionsmarked- RoamJS' official Roam-flavored markdown to HTML processorqueries- Helpers that abstract datalog into common, easy-to-invoke, typed queriestypes- Common typescript types used when interacting with these methodsutil- All other utilities not found in the other directorieswrites- Helpers that abstract Roam's write API into common, easy-to-invoke, typed actions
We recommend using modular imports for using any methods found in these libraries. For example,
import getTextByBlockUid from "roam-client/queries/getTextByBlockUid";
instead of
import { getTextByBlockUid } from "roam-client/queries";
though, the latter is still available for convenience.
The rest of this README is not exhaustive, and will soon live in https://roamjs.com/extensions/developer.
The following are a list of methods used to help interface with the RoamJS Components found in this library.
This is an observer that will render the ConfigPage UI on the page of your choosing.
title: stringName of the page to render the Configuration page ui. If this page doesn't already exist in the user's Roam database, one will be created with specified default values filled in.config: objectThe metadata specifying which fields your configuration supportstabs: object[]The first level tabs grouping your fields. They map to first level blocks on the Roam Page.id: stringThe name of the tab to use in both the Roam UI and in the tab label. Thehomeid inserts blocks at the top level of Roam.toggleable: booleanWhether this tab should be able to turn on and off. Turning a tab off disables the rest of the nested fields.fields: object[]The set of field metadata grouped in this tab. If fields is empty, it will be assumed that this tab is a state container for the extension not meant to be interacted with by the user.title: stringThe name of the field, displayed on the nested tag and in the Roam block.description: stringThe description of the field with renders next to each field label as a tooltip.type: stringThe field type, with only the following valid values:textRenders a text input.numberRenders a number input.flagRenders a boolean checkbox.multitextRenders a text input that could have multiple child values. Used for an array of string values.pagesSimilar to multitext, but all values are Roam pages.oauthRenders a login button based on the service providerselectRenders a dropdown with the configured options
defaultValueThe default value filled in on page creation. Field is optional and type based on type aboveoptionsAn extra object of options for configuring a field, based on the type above.textNonenumberNoneflagNonemultitextNonepagesNoneoauthservice: stringThe name of the service provider, used on the login buttongetPopoutUrl: () => Promise<string>A getter retrieving the url needed to begin the oauth processgetAuthData: (d: string) => Promise<Record<string, string>>A getter that takes in a stringified JSON object from the oauth popout window and retrieves the auth related data.ServiceIcon: React.FunctionComponent<React.SVGAttributes<SVGElement>>The SVG Icon to render next to the login button.
selectitems: string[]The set of valid options for this dopdown
Creates a render function for the component FC rendered inside of a ComponentContainer component. A ComponentContainer simulates standard Roam {{components}} in that they are meant to be rendered in a block with an edit pencil icon to edit the block if necessary.
FC: ReactElementThe component rendered with ablockUidprop that references the block the component is rendered in.classNameAn optional class name to pass to the surroundingComponentContainer.
Creates a render function for the component Overlay mounted on a parent from the id passed to getRenderRoot, unmounting when the overlay closes.
id: stringThe id passed to the parent element rendering the Overlay, interpolated inside ofroamjs-${id}-root.Overlay: ({onClose: () => void}) => ReactElementThe React component rendered with aonCloseprop to handle unmounting.
This creates a div appended to Roam's natural react root, most commonly used as its own root element for overlay components.
id: stringThe id of the parent element, interpolated inside ofroamjs-${id}-root.
This is a utility method for grabbing the integer value of a node from a tree by a given key.
tree: TextNode[]The array ofTextNodeto search through.key: stringThe key used to find the desired nodedefaultValue?: numberThe default value the getter should have if there are no nodes with the specified key, defaulted to 0.
This is a utility method for grabbing the string value of a node from a tree by a given key.
tree: TextNode[]The array ofTextNodeto search through.key: stringThe key used to find the desired nodedefaultValue?: numberThe default value the getter should have if there are no nodes with the specified key, defaulted to an empty string.
This is a utility method for grabbing the string value of a node from a tree by a given key.
tree: TextNode[]The array ofTextNodeto search through.key: stringThe key used to find the desired nodedefaultValue?: numberThe default value the getter should have if there are no nodes with the specified key, defaulted to an empty string.
This is a utility method for adding a value as part of multiple to a key by making it a descendant of node in the tree.
blockUid: stringThe uid of the root block housing all of settings.value: stringThe value to add to the settingkey: stringThe setting nameindex?: numberThe index where the setting should be created if new, defaulted to 0
This is a utility method for setting a value to a key by making it a descendant of node in the tree.
blockUid: stringThe uid of the root block housing all of settings.value: stringThe value to assign to the settingkey: stringThe setting nameindex?: numberThe index where the setting should be created if new, defaulted to 0
This is a utility method for setting multiple values to a key by making it a descendant of node in the tree.
blockUid: stringThe uid of the root block housing all of settings.values: stringThe set of values to assign to the settingkey: stringThe setting nameindex?: numberThe index where the setting should be created if new, defaulted to 0
The following are a list of React components commonly used across RoamJS extensions.
An Error Boundary to wrap around components meant to live within blocks to catch any React Errors. The error message will interpolate inside of a {ERROR} placeholder within the message prop and output as a child block.
An info icon with a tooltip, used to give help text to UI components.
A standard Select using blueprint's MenuItem component as the item rendered.
Renders a yellow warning message, then unmounts itself upon dismissing.