import type { UiNode, UiNodeAnchorAttributes, UiNodeAttributes, UiNodeGroupEnum, UiNodeImageAttributes, UiNodeInputAttributes, UiNodeInputAttributesTypeEnum, UiNodeScriptAttributes, UiNodeTextAttributes, } from "@ory/client" /** * Returns the node's label. * * @param node * @return label */ export const getNodeLabel = (node: UiNode): string => { const attributes = node.attributes if (isUiNodeAnchorAttributes(attributes)) { return attributes.title.text } if (isUiNodeImageAttributes(attributes)) { return node.meta.label?.text || "" } if (isUiNodeInputAttributes(attributes)) { if (attributes.label?.text) { return attributes.label.text } } return node.meta.label?.text || "" } /** * A TypeScript type guard for nodes of the type * * @param attrs */ export function isUiNodeAnchorAttributes( attrs: UiNodeAttributes, ): attrs is UiNodeAnchorAttributes & { node_type: "a" } { return attrs.node_type === "a" } /** * A TypeScript type guard for nodes of the type * * @param attrs */ export function isUiNodeImageAttributes( attrs: UiNodeAttributes, ): attrs is UiNodeImageAttributes & { node_type: "img" } { return attrs.node_type === "img" } /** * A TypeScript type guard for nodes of the type * * @param attrs */ export function isUiNodeInputAttributes( attrs: UiNodeAttributes, ): attrs is UiNodeInputAttributes & { node_type: "input" } { return attrs.node_type === "input" } /** * A TypeScript type guard for nodes of the type {text} * * @param attrs */ export function isUiNodeTextAttributes( attrs: UiNodeAttributes, ): attrs is UiNodeTextAttributes & { node_type: "text" } { return attrs.node_type === "text" } /** * A TypeScript type guard for nodes of the type