UNPKG

@liveblocks/react-ui

Version:

A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.

1 lines 2.02 kB
{"version":3,"file":"utils.cjs","sources":["../../../src/primitives/Comment/utils.ts"],"sourcesContent":["import type {\n CommentBodyElement,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyText,\n} from \"@liveblocks/core\";\n\nexport function isCommentBodyText(\n element: CommentBodyElement\n): element is CommentBodyText {\n return (\n !(\"type\" in element) &&\n \"text\" in element &&\n typeof element.text === \"string\"\n );\n}\n\nexport function isCommentBodyMention(\n element: CommentBodyElement\n): element is CommentBodyMention {\n return \"type\" in element && element.type === \"mention\";\n}\n\nexport function isCommentBodyLink(\n element: CommentBodyElement\n): element is CommentBodyLink {\n return \"type\" in element && element.type === \"link\";\n}\n\n/**\n * Helper function to convert a URL (relative or absolute) to an absolute URL.\n *\n * @param url The URL to convert to an absolute URL (relative or absolute).\n * @returns The absolute URL or undefined if the URL is invalid.\n */\nexport function toAbsoluteUrl(url: string): string | undefined {\n // Check if the URL already contains a scheme\n if (url.startsWith(\"http://\") || url.startsWith(\"https://\")) {\n return url;\n } else if (url.startsWith(\"www.\")) {\n // If the URL starts with \"www.\", prepend \"https://\"\n return \"https://\" + url;\n }\n\n return;\n}\n"],"names":[],"mappings":";;AAOO,SAAS,kBACd,OAC4B,EAAA;AAC5B,EAAA,OACE,EAAE,MAAU,IAAA,OAAA,CAAA,IACZ,UAAU,OACV,IAAA,OAAO,QAAQ,IAAS,KAAA,QAAA,CAAA;AAE5B,CAAA;AAEO,SAAS,qBACd,OAC+B,EAAA;AAC/B,EAAO,OAAA,MAAA,IAAU,OAAW,IAAA,OAAA,CAAQ,IAAS,KAAA,SAAA,CAAA;AAC/C,CAAA;AAEO,SAAS,kBACd,OAC4B,EAAA;AAC5B,EAAO,OAAA,MAAA,IAAU,OAAW,IAAA,OAAA,CAAQ,IAAS,KAAA,MAAA,CAAA;AAC/C,CAAA;AAQO,SAAS,cAAc,GAAiC,EAAA;AAE7D,EAAA,IAAI,IAAI,UAAW,CAAA,SAAS,KAAK,GAAI,CAAA,UAAA,CAAW,UAAU,CAAG,EAAA;AAC3D,IAAO,OAAA,GAAA,CAAA;AAAA,GACE,MAAA,IAAA,GAAA,CAAI,UAAW,CAAA,MAAM,CAAG,EAAA;AAEjC,IAAA,OAAO,UAAa,GAAA,GAAA,CAAA;AAAA,GACtB;AAEA,EAAA,OAAA;AACF;;;;;;;"}