@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.
224 lines (220 loc) • 8.14 kB
JavaScript
"use client";
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { assertNever } from '@liveblocks/core';
import { createContext, useContext, useMemo } from 'react';
import { Emoji } from './components/internal/Emoji.js';
import { getDuration, Duration } from './primitives/Duration.js';
import { pluralize } from './utils/pluralize.js';
const MINIMUM_VISIBLE_DURATION = 3 * 1e3;
function isDurationVisible(from, to) {
return getDuration(from, to ?? Date.now()) >= MINIMUM_VISIBLE_DURATION;
}
const defaultOverrides = {
locale: "en",
dir: "ltr",
USER_SELF: "you",
USER_UNKNOWN: "Anonymous",
COPY_TO_CLIPBOARD: "Copy",
LIST_REMAINING: (count) => `${count} more`,
LIST_REMAINING_USERS: (count) => `${count} ${pluralize(count, "other")}`,
LIST_REMAINING_COMMENTS: (count) => `${count} more ${pluralize(count, "comment")}`,
EMOJI_PICKER_SEARCH_PLACEHOLDER: "Search\u2026",
EMOJI_PICKER_EMPTY: "No emoji found.",
EMOJI_PICKER_ERROR: () => "There was an error while getting the list of emoji.",
EMOJI_PICKER_CHANGE_SKIN_TONE: "Change skin tone",
ATTACHMENT_TOO_LARGE: (maxSize) => maxSize ? `The file is larger than ${maxSize}` : "The file is too large",
ATTACHMENT_ERROR: () => "The file couldn\u2019t be uploaded.",
COMPOSER_INSERT_MENTION: "Mention someone",
COMPOSER_INSERT_EMOJI: "Add emoji",
COMPOSER_ATTACH_FILES: "Attach files",
COMPOSER_REMOVE_ATTACHMENT: "Remove attachment",
COMPOSER_PLACEHOLDER: "Write a comment\u2026",
COMPOSER_SEND: "Send",
COMPOSER_TOGGLE_MARK: (format) => {
switch (format) {
case "bold":
return "Bold";
case "italic":
return "Italic";
case "strikethrough":
return "Strikethrough";
case "code":
return "Inline code";
default:
return assertNever(format, "Unexpected mark");
}
},
COMMENT_EDITED: "(edited)",
COMMENT_DELETED: "This comment has been deleted.",
COMMENT_MORE: "More",
COMMENT_EDIT: "Edit comment",
COMMENT_EDIT_COMPOSER_PLACEHOLDER: "Edit comment\u2026",
COMMENT_EDIT_COMPOSER_CANCEL: "Cancel",
COMMENT_EDIT_COMPOSER_SAVE: "Save",
COMMENT_DELETE: "Delete comment",
COMMENT_DELETE_ATTACHMENT: "Delete attachment",
COMMENT_ADD_REACTION: "Add reaction",
COMMENT_REACTION_LIST: (list, emoji) => /* @__PURE__ */ jsxs(Fragment, { children: [
list,
" reacted with ",
/* @__PURE__ */ jsx(Emoji, { emoji })
] }),
COMMENT_REACTION_DESCRIPTION: (emoji, count) => `${count} ${pluralize(count, "reaction")}, react with ${emoji}`,
THREAD_RESOLVE: "Resolve thread",
THREAD_UNRESOLVE: "Re-open thread",
THREAD_SUBSCRIBE: "Subscribe to thread",
THREAD_UNSUBSCRIBE: "Unsubscribe from thread",
THREAD_NEW_INDICATOR: "New",
THREAD_NEW_INDICATOR_DESCRIPTION: "New comments",
THREAD_SHOW_MORE_COMMENTS: (count) => `Show ${count} more ${pluralize(count, "reply", "replies")}`,
THREAD_COMPOSER_PLACEHOLDER: "Reply to thread\u2026",
THREAD_COMPOSER_SEND: "Reply",
INBOX_NOTIFICATION_MORE: "More",
INBOX_NOTIFICATION_MARK_AS_READ: "Mark as read",
INBOX_NOTIFICATION_DELETE: "Delete notification",
INBOX_NOTIFICATION_THREAD_COMMENTS_LIST: (list, room) => /* @__PURE__ */ jsxs(Fragment, { children: [
list,
" commented",
room ? /* @__PURE__ */ jsxs(Fragment, { children: [
" in ",
room
] }) : /* @__PURE__ */ jsx(Fragment, { children: " in a thread" })
] }),
INBOX_NOTIFICATION_THREAD_MENTION: (user, room) => /* @__PURE__ */ jsxs(Fragment, { children: [
user,
" mentioned you",
room ? /* @__PURE__ */ jsxs(Fragment, { children: [
" in ",
room
] }) : null
] }),
INBOX_NOTIFICATION_TEXT_MENTION: (user, room) => /* @__PURE__ */ jsxs(Fragment, { children: [
user,
" mentioned you",
room ? /* @__PURE__ */ jsxs(Fragment, { children: [
" in ",
room
] }) : null
] }),
HISTORY_VERSION_PREVIEW_AUTHORS_LIST: (list) => /* @__PURE__ */ jsxs(Fragment, { children: [
"Edits from ",
list
] }),
HISTORY_VERSION_PREVIEW_RESTORE: "Restore",
HISTORY_VERSION_PREVIEW_EMPTY: "No content.",
HISTORY_VERSION_PREVIEW_ERROR: () => "There was an error while getting this version.",
AI_COMPOSER_PLACEHOLDER: "Ask anything\u2026",
AI_COMPOSER_SEND: "Send",
AI_COMPOSER_ABORT: "Abort response",
AI_CHAT_MESSAGE_DELETED: "This message has been deleted.",
AI_CHAT_MESSAGE_THINKING: "Thinking\u2026",
AI_CHAT_MESSAGE_REASONING: (isStreaming, part) => isStreaming ? /* @__PURE__ */ jsx(Fragment, { children: "Reasoning\u2026" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
"Reasoned",
isDurationVisible(part.startedAt, part.endedAt) ? /* @__PURE__ */ jsxs(Fragment, { children: [
" ",
"for",
" ",
/* @__PURE__ */ jsx(
Duration,
{
className: "lb-duration lb-ai-chat-message-reasoning-duration",
from: part.startedAt,
to: part.endedAt
}
)
] }) : null
] }),
AI_CHAT_MESSAGE_RETRIEVAL: (isStreaming, part) => {
if (part.kind === "knowledge") {
return isStreaming ? /* @__PURE__ */ jsxs(Fragment, { children: [
"Searching",
" ",
/* @__PURE__ */ jsx("span", { className: "lb-ai-chat-message-retrieval-query", children: part.query }),
"\u2026"
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
"Searched",
" ",
/* @__PURE__ */ jsx("span", { className: "lb-ai-chat-message-retrieval-query", children: part.query }),
isDurationVisible(part.startedAt, part.endedAt) ? /* @__PURE__ */ jsxs(Fragment, { children: [
" ",
"for",
" ",
/* @__PURE__ */ jsx(
Duration,
{
className: "lb-duration lb-ai-chat-message-retrieval-duration",
from: part.startedAt,
to: part.endedAt
}
)
] }) : null
] });
} else if (part.kind === "web") {
return isStreaming ? /* @__PURE__ */ jsxs(Fragment, { children: [
"Searching the web",
part.query ? /* @__PURE__ */ jsxs(Fragment, { children: [
" ",
"for",
" ",
/* @__PURE__ */ jsx("span", { className: "lb-ai-chat-message-retrieval-query", children: part.query })
] }) : null,
"\u2026"
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
"Searched the web",
part.query ? /* @__PURE__ */ jsxs(Fragment, { children: [
" ",
"for",
" ",
/* @__PURE__ */ jsx("span", { className: "lb-ai-chat-message-retrieval-query", children: part.query })
] }) : null,
isDurationVisible(part.startedAt, part.endedAt) ? /* @__PURE__ */ jsxs(Fragment, { children: [
" ",
"for",
" ",
/* @__PURE__ */ jsx(
Duration,
{
className: "lb-duration lb-ai-chat-message-retrieval-duration",
from: part.startedAt,
to: part.endedAt
}
)
] }) : null
] });
} else {
return assertNever(part, "Unexpected retrieval kind");
}
},
AI_CHAT_MESSAGES_ERROR: () => "There was an error while getting the messages.",
AI_TOOL_CONFIRMATION_CONFIRM: "Confirm",
AI_TOOL_CONFIRMATION_CANCEL: "Cancel"
};
const OverridesContext = createContext(void 0);
function useOverrides(overrides) {
const contextOverrides = useContext(OverridesContext);
return useMemo(
() => ({
...defaultOverrides,
...contextOverrides,
...overrides
}),
[contextOverrides, overrides]
);
}
function OverridesProvider({
children,
overrides: providerOverrides
}) {
const contextOverrides = useContext(OverridesContext);
const overrides = useMemo(
() => ({
...defaultOverrides,
...contextOverrides,
...providerOverrides
}),
[contextOverrides, providerOverrides]
);
return /* @__PURE__ */ jsx(OverridesContext.Provider, { value: overrides, children });
}
export { OverridesContext, OverridesProvider, defaultOverrides, useOverrides };
//# sourceMappingURL=overrides.js.map