Files
upstream-rocketchat/apps/meteor/client/lib/messageBoxFormatting.ts
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

107 lines
2.6 KiB
TypeScript

import type { Keys as IconName } from '@rocket.chat/icons';
import { imperativeModal } from '@rocket.chat/ui-client';
import type { TranslationKey } from '@rocket.chat/ui-contexts';
import { flushSync } from 'react-dom';
import type { ComposerAPI } from './chats/ChatAPI';
import { settings } from './settings';
import AddLinkComposerActionModal from '../views/composer/AddLinkComposerActionModal';
type FormattingButtonDefault = { label: TranslationKey; condition?: () => boolean };
type TextButton = {
text: () => string | undefined;
link: string;
} & FormattingButtonDefault;
type PatternButton = {
icon: IconName;
pattern: string;
// text?: () => string | undefined;
command?: string;
link?: string;
} & FormattingButtonDefault;
type PromptButton = {
prompt: (composer: ComposerAPI) => void;
icon: IconName;
} & FormattingButtonDefault;
export type FormattingButton = PatternButton | PromptButton | TextButton;
export const isPromptButton = (button: FormattingButton): button is PromptButton => 'prompt' in button;
export const formattingButtons: ReadonlyArray<FormattingButton> = [
{
label: 'Bold',
icon: 'bold',
pattern: '*{{text}}*',
command: 'b',
},
{
label: 'Italic',
icon: 'italic',
pattern: '_{{text}}_',
command: 'i',
},
{
label: 'Strikethrough',
icon: 'strike',
pattern: '~{{text}}~',
},
{
label: 'Inline_code',
icon: 'code',
pattern: '`{{text}}`',
},
{
label: 'Multi_line_code',
icon: 'multiline',
pattern: '```\n{{text}}\n``` ',
},
{
label: 'Link',
icon: 'link',
prompt: (composerApi: ComposerAPI) => {
const { selection } = composerApi;
const selectedText = composerApi.substring(selection.start, selection.end);
const onClose = () => {
imperativeModal.close();
composerApi.focus();
};
const onConfirm = (url: string, text: string) => {
// Composer API can't handle the selection of the text while the modal is open
flushSync(() => {
onClose();
});
flushSync(() => {
composerApi.replaceText(`[${text}](${url})`, selection);
composerApi.setCursorToEnd();
});
};
imperativeModal.open({ component: AddLinkComposerActionModal, props: { onConfirm, selectedText, onClose } });
},
},
{
label: 'KaTeX' as TranslationKey,
icon: 'katex',
text: () => {
if (!settings.peek('Katex_Enabled')) {
return;
}
if (settings.peek('Katex_Dollar_Syntax')) {
return '$$KaTeX$$';
}
if (settings.peek('Katex_Parenthesis_Syntax')) {
return '\\[KaTeX\\]';
}
},
link: 'https://khan.github.io/KaTeX/function-support.html',
condition: () => settings.peek('Katex_Enabled') ?? true,
},
] as const;