Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(md/channels): support group mentions + @here in channels (#914)
teoc2b9d0605fce
diff --git a/js/app/packages/block-channel/component/BaseInput.tsx b/js/app/packages/block-channel/component/BaseInput.tsxindex d9cefa2178..29b2d89ad4 100644--- a/js/app/packages/block-channel/component/BaseInput.tsx+++ b/js/app/packages/block-channel/component/BaseInput.tsx@@ -4,6 +4,10 @@ import {} from '@block-channel/signal/attachment';import type { SendMessageArgs } from '@block-channel/signal/channel';import { handleFileUpload } from '@block-channel/utils/inputAttachments';+import {+ expandGroupParticipants,+ toSimpleMention,+} from '@block-channel/utils/mentionExpansion';import { isInBlock } from '@core/block';import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';import { FileDropOverlay } from '@core/component/FileDropOverlay';@@ -199,11 +203,22 @@ export function BaseInput(props: BaseInputProps) {if (currentRef) props.domRef?.(currentRef);});- const allMentions: Accessor<SimpleMention[]> = () =>- mentions().map((m) => ({- entity_type: m.itemType,- entity_id: m.itemId,- }));+ const allMentions: Accessor<SimpleMention[]> = () => {+ const result: SimpleMention[] = [];+ const seenUserIds = new Set<string>();+ const channelUserIds = props.channelUsers?.().map((u) => u.id) ?? [];++ for (const m of mentions()) {+ if (m.itemType === 'group') {+ result.push(...expandGroupParticipants(channelUserIds, seenUserIds));+ } else {+ const mention = toSimpleMention(m, seenUserIds);+ if (mention) result.push(mention);+ }+ }++ return result;+ };const [attachFn, scopeId] = useHotkeyDOMScope('channel.baseInput');diff --git a/js/app/packages/block-channel/tests/mentionExpansion.test.ts b/js/app/packages/block-channel/tests/mentionExpansion.test.tsnew file mode 100644index 0000000000..4fd98d9549--- /dev/null+++ b/js/app/packages/block-channel/tests/mentionExpansion.test.ts@@ -0,0 +1,45 @@+import { describe, expect, it } from 'vitest';+import {+ expandGroupParticipants,+ toSimpleMention,+} from '../utils/mentionExpansion';++describe('expandGroupParticipants', () => {+ it('converts participant IDs to SimpleMentions', () => {+ const seen = new Set<string>();+ const result = expandGroupParticipants(['u1', 'u2'], seen);+ expect(result).toEqual([+ { entity_type: 'user', entity_id: 'u1' },+ { entity_type: 'user', entity_id: 'u2' },+ ]);+ });++ it('deduplicates against seen set', () => {+ const seen = new Set(['u1']);+ const result = expandGroupParticipants(['u1', 'u2'], seen);+ expect(result).toEqual([{ entity_type: 'user', entity_id: 'u2' }]);+ });+});++describe('toSimpleMention', () => {+ it('converts user mention to SimpleMention', () => {+ const seen = new Set<string>();+ const result = toSimpleMention({ itemType: 'user', itemId: 'u1' }, seen);+ expect(result).toEqual({ entity_type: 'user', entity_id: 'u1' });+ });++ it('returns null for duplicate user mentions', () => {+ const seen = new Set(['u1']);+ const result = toSimpleMention({ itemType: 'user', itemId: 'u1' }, seen);+ expect(result).toBeNull();+ });++ it('passes through non-user types', () => {+ const seen = new Set<string>();+ const result = toSimpleMention(+ { itemType: 'document', itemId: 'd1' },+ seen+ );+ expect(result).toEqual({ entity_type: 'document', entity_id: 'd1' });+ });+});diff --git a/js/app/packages/block-channel/utils/mentionExpansion.ts b/js/app/packages/block-channel/utils/mentionExpansion.tsnew file mode 100644index 0000000000..946ea6f58d--- /dev/null+++ b/js/app/packages/block-channel/utils/mentionExpansion.ts@@ -0,0 +1,38 @@+import type { SimpleMention } from '@service-comms/generated/models/simpleMention';++export type MentionItem = {+ itemType: string;+ itemId: string;+};++/**+ * Expands group participants to individual user mentions, deduplicating against seen users.+ */+export function expandGroupParticipants(+ participants: string[],+ seenUserIds: Set<string>+): SimpleMention[] {+ const result: SimpleMention[] = [];+ for (const userId of participants) {+ if (!seenUserIds.has(userId)) {+ seenUserIds.add(userId);+ result.push({ entity_type: 'user', entity_id: userId });+ }+ }+ return result;+}++/**+ * Converts a mention to SimpleMention format, deduplicating user mentions against seen users.+ * Returns null if the mention is a duplicate user.+ */+export function toSimpleMention(+ mention: MentionItem,+ seenUserIds: Set<string>+): SimpleMention | null {+ if (mention.itemType === 'user') {+ if (seenUserIds.has(mention.itemId)) return null;+ seenUserIds.add(mention.itemId);+ }+ return { entity_type: mention.itemType, entity_id: mention.itemId };+}diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsxindex 0976fee23e..e454c11eea 100644--- a/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx@@ -17,6 +17,7 @@ import {DEFAULT_LANGUAGE,type DocumentMentionNode,type EquationNode,+ type GroupMentionNode,type HorizontalRuleNode,type ImageNode,isSupportedLanguage,@@ -62,6 +63,7 @@ import { StaticCodeBoxAccessory } from '../accessory/CodeBoxAccessory';import { ContactMention as ContactMentionDecorator } from '../decorator/ContactMention';import { DateMention as DateMentionDecorator } from '../decorator/DateMention';import { DocumentMention as DocumentMentionDecorator } from '../decorator/DocumentMention';+import { GroupMention as GroupMentionDecorator } from '../decorator/GroupMention';import { Equation as EquationDecorator } from '../decorator/Equation';import { MarkdownImage as ImageDecorator } from '../decorator/MarkdownImage';import { MarkdownVideo as VideoDecorator } from '../decorator/MarkdownVideo';@@ -310,6 +312,20 @@ const DateMention: RenderableEntity<DateMentionNode> = {),};+const GroupMention: RenderableEntity<GroupMentionNode> = {+ guard: (node: LexicalNode): node is GroupMentionNode =>+ node.__type === 'group-mention',+ render: (props) => (+ <span>+ {GroupMentionDecorator({+ ...props.node.exportComponentProps(),+ key: props.node.getKey(),+ theme: props.theme,+ })}+ </span>+ ),+};+const Image: RenderableEntity<ImageNode> = {guard: (node: LexicalNode): node is ImageNode => node.__type === 'image',render: (props) => ImageDecorator(props.node.exportComponentProps()),@@ -596,6 +612,7 @@ const InlineEntities: Array<RenderableEntity> = [DocumentMention,ContactMention,DateMention,+ GroupMention,Image,Video,HorizontalRule,diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/GroupMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/GroupMention.tsxnew file mode 100644index 0000000000..5f8d640bd3--- /dev/null+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/GroupMention.tsx@@ -0,0 +1,27 @@+import type { GroupMentionDecoratorProps } from '@lexical-core';+import { useContext } from 'solid-js';+import { LexicalWrapperContext } from '../../context/LexicalWrapperContext';++export function GroupMention(props: GroupMentionDecoratorProps) {+ const lexicalWrapper = useContext(LexicalWrapperContext);+ const selection = () => lexicalWrapper?.selection;++ const isSelectedAsNode = () => {+ const sel = selection();+ if (!sel) return false;+ return sel.type === 'node' && sel.nodeKeys.has(props.key);+ };++ return (+ <span+ class={`relative py-0.5 px-0.5 cursor-default rounded-xs bg-accent/8 hover:bg-accent/20 focus:bg-accent/20 text-accent-ink`}+ classList={{+ 'bracket-offset-2': isSelectedAsNode(),+ }}+ >+ <span data-group-alias={props.groupAlias} data-group-mention="true">+ @{props.groupAlias}+ </span>+ </span>+ );+}diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsxindex fb30a9ed1b..7ea82c3253 100644--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsx+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsx@@ -20,6 +20,7 @@ import { getDateSuggestions } from '@core/util/dateParser';import { createFreshSearch } from '@core/util/freshSort';import ClockIcon from '@icon/regular/clock.svg';import EmailIcon from '@icon/regular/envelope.svg';+import UsersIcon from '@icon/regular/users.svg';import type { EntityData, WithSearch } from '@macro-entity';import {createUnifiedSearchInfiniteQuery,@@ -57,6 +58,7 @@ import {import type { MenuOperations } from '../../shared/inlineMenu';import {type CombinedEntity,+ createGroupAlias,type Entity,type EntityMap,entityMapper,@@ -67,6 +69,7 @@ import {handleChannelMention,handleDateMention,handleEmailMention,+ handleGroupMention,handleUserMention,type UserMentionRecord,} from '../../utils/mentionsUtils';@@ -101,6 +104,8 @@ const getItemSearchText = (item: CombinedEntity): string => {return item.data.displayFormat;case 'email':return item.data.name ?? 'No Subject';+ case 'group':+ return item.data.groupAlias;}};@@ -148,6 +153,8 @@ function createItemHandler(dependencies: HandlerDependencies) {return await handleChannelMention(item.data, dependencies);case 'email':return await handleEmailMention(item.data, dependencies);+ case 'group':+ return await handleGroupMention(item.data, dependencies);}};}@@ -327,6 +334,9 @@ export function MentionsMenuItem(props: {case 'user':return <UserIcon id={props.item.id} size="sm" isDeleted={false} />;+ case 'group':+ return <UsersIcon class="size-4 text-ink-muted" />;+case 'date':return <ClockIcon class="size-4 text-ink-muted" />;@@ -637,10 +647,30 @@ function MentionsMenuInner(props: {{ timeWeight: 0, brevityWeight: 0.3 },getItemSearchText);++ // Group aliases available in channel context+ const specialGroups = createMemo((): Entity<'group'>[] => {+ if (props.block !== 'channel') return [];+ if (!useMaybeBlockId()) return [];++ const term = searchTerm().toLowerCase();++ const availableGroups = [+ { alias: 'here', match: (t: string) => t === '' || 'here'.startsWith(t) },+ ];++ return availableGroups+ .filter((g) => g.match(term))+ .map((g) => createGroupAlias(g.alias));+ });+const filteredUsers = createMemo(() => {- return userSearch(users(), searchTerm()).map((result) => {+ const searchedUsers = userSearch(users(), searchTerm()).map((result) => {return result.item;});+ return [...specialGroups(), ...searchedUsers] as CombinedEntity<+ 'user' | 'group'+ >[];});const emailSearch = createFreshSearch<Entity<'email'>>(diff --git a/js/app/packages/core/component/LexicalMarkdown/init.ts b/js/app/packages/core/component/LexicalMarkdown/init.tsindex bc59920710..b04b79e3bd 100644--- a/js/app/packages/core/component/LexicalMarkdown/init.ts+++ b/js/app/packages/core/component/LexicalMarkdown/init.ts@@ -5,6 +5,7 @@ import {DocumentCardNode,DocumentMentionNode,EquationNode,+ GroupMentionNode,HorizontalRuleNode,HtmlRenderNode,ImageNode,@@ -19,6 +20,7 @@ import { DiffInsert } from './component/decorator/DiffInsert';import { DocumentCard } from './component/decorator/DocumentCard';import { DocumentMention } from './component/decorator/DocumentMention';import { Equation } from './component/decorator/Equation';+import { GroupMention } from './component/decorator/GroupMention';import { HorizontalRule } from './component/decorator/HorizontalRule';import { HtmlRender } from './component/decorator/HtmlRender';import { MarkdownImage } from './component/decorator/MarkdownImage';@@ -34,6 +36,7 @@ export function initializeLexical() {clearDecorators();setDecorator(HorizontalRuleNode, HorizontalRule);setDecorator(UserMentionNode, UserMention);+ setDecorator(GroupMentionNode, GroupMention);setDecorator(DocumentMentionNode, DocumentMention);setDecorator(DocumentCardNode, DocumentCard);setDecorator(ContactMentionNode, ContactMention);diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.tsindex 7097544ac0..14f0464479 100644--- a/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts@@ -7,6 +7,7 @@ import {$createContactMentionNode,$createDateMentionNode,$createDocumentMentionNode,+ $createGroupMentionNode,$createInlineSearchNode,$createUserMentionNode,$handleInlineSearchNodeMutation,@@ -14,6 +15,7 @@ import {$isContactMentionNode,$isDateMentionNode,$isDocumentMentionNode,+ $isGroupMentionNode,$isUserMentionNode,$removeInlineSearch,type ContactMentionInfo,@@ -22,6 +24,8 @@ import {DateMentionNode,type DocumentMentionInfo,DocumentMentionNode,+ type GroupMentionInfo,+ GroupMentionNode,InlineSearchNode,InlineSearchNodesType,type UserMentionInfo,@@ -90,6 +94,9 @@ export const UPDATE_DOCUMENT_NAME_COMMAND: LexicalCommand<export const INSERT_USER_MENTION_COMMAND: LexicalCommand<UserMentionInfo> =createCommand('INSERT_USER_MENTION_COMMAND');+export const INSERT_GROUP_MENTION_COMMAND: LexicalCommand<GroupMentionInfo> =+ createCommand('INSERT_GROUP_MENTION_COMMAND');+export type ItemMention = {itemType:| 'document'@@ -102,11 +109,13 @@ export type ItemMention = {| 'date'| 'email'| 'unknown'- | 'color';+ | 'color'+ | 'group';itemId: string;fileType?: string;documentName?: string;channelType?: string;+ groupAlias?: string;};export function $isMentionNode(@@ -115,12 +124,14 @@ export function $isMentionNode(| UserMentionNode| DocumentMentionNode| ContactMentionNode- | DateMentionNode {+ | DateMentionNode+ | GroupMentionNode {return ($isUserMentionNode(node) ||$isDocumentMentionNode(node) ||$isContactMentionNode(node) ||- $isDateMentionNode(node)+ $isDateMentionNode(node) ||+ $isGroupMentionNode(node));}export function $mentionItemFromNode(node: MentionNode): ItemMention {@@ -169,6 +180,12 @@ export function $mentionItemFromNode(node: MentionNode): ItemMention {itemType: 'contact',itemId: node.getContactId(),};+ } else if ($isGroupMentionNode(node)) {+ return {+ itemType: 'group',+ itemId: node.getGroupAlias(),+ groupAlias: node.getGroupAlias(),+ };} else {return {itemType: 'date',@@ -193,9 +210,11 @@ function $deleteSelectedMentions(sourceDocumentId?: string) {const nodes = sel.getNodes();for (const node of nodes) {if ($isMentionNode(node) && node.isKeyboardSelectable()) {- const mentionUuid = node.getMentionUuid();- if (mentionUuid && sourceDocumentId) {- untrackMention(sourceDocumentId, mentionUuid);+ if (!$isGroupMentionNode(node)) {+ const mentionUuid = node.getMentionUuid();+ if (mentionUuid && sourceDocumentId) {+ untrackMention(sourceDocumentId, mentionUuid);+ }}node.remove();foundNodesToBeDeleted = true;@@ -246,6 +265,7 @@ function registerMentionsPlugin(!editor.hasNodes([DocumentMentionNode,UserMentionNode,+ GroupMentionNode,ContactMentionNode,DateMentionNode,InlineSearchNode,@@ -390,6 +410,23 @@ function registerMentionsPlugin(COMMAND_PRIORITY_NORMAL),+ editor.registerCommand(+ INSERT_GROUP_MENTION_COMMAND,+ (payload) => {+ editor.update(() => {+ const mentionNode = $createGroupMentionNode(payload);++ $insertNodes([mentionNode]);+ if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) {+ $wrapNodeInElement(mentionNode, $createParagraphNode);+ }+ mentionNode.selectEnd();+ });+ return true;+ },+ COMMAND_PRIORITY_NORMAL+ ),+registerSymbolListener(),editor.registerCommand(@@ -681,6 +718,34 @@ function registerMentionsPlugin(}updateMentionsSignal();}+ ),++ editor.registerMutationListener(+ GroupMentionNode,+ (mutatedNodes, { prevEditorState }) => {+ for (const [nodeKey, mutation] of mutatedNodes) {+ const node = nodeByKey(prevEditorState, nodeKey) as GroupMentionNode;+ if (node && mutation === 'destroyed') {+ if (onRemoveMention) {+ onRemoveMention({+ itemType: 'group',+ itemId: node.getGroupAlias(),+ groupAlias: node.getGroupAlias(),+ });+ }+ }+ if (node && mutation === 'created') {+ if (onCreateMention) {+ onCreateMention({+ itemType: 'group',+ itemId: node.getGroupAlias(),+ groupAlias: node.getGroupAlias(),+ });+ }+ }+ }+ updateMentionsSignal();+ }));}diff --git a/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.ts b/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.tsindex 7e280b6b9b..0ad10daab5 100644--- a/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.ts+++ b/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.ts@@ -16,15 +16,37 @@ import { v7 } from 'uuid';import {INSERT_DATE_MENTION_COMMAND,INSERT_DOCUMENT_MENTION_COMMAND,+ INSERT_GROUP_MENTION_COMMAND,INSERT_USER_MENTION_COMMAND,} from '../plugins/mentions';+export type GroupItem = {+ id: string;+ groupAlias: string;+};++/**+ * Creates a group mention entity from an alias.+ * Use this to define new group aliases (e.g., @here, @team, @online).+ */+export function createGroupAlias(alias: string): Entity<'group'> {+ return {+ kind: 'group',+ id: alias,+ data: {+ id: alias,+ groupAlias: alias,+ },+ };+}+export type EntityMap = {item: Item;user: IUser;channel: ChannelWithParticipants;date: DateItem;email: EmailEntity;+ group: GroupItem;};export type Entity<T extends keyof EntityMap> = {@@ -100,6 +122,8 @@ export const getItemName = (item: CombinedEntity): string => {return item.data.name ?? 'No Subject';case 'date':return item.data.displayFormat;+ case 'group':+ return `@${item.data.groupAlias}`;}};@@ -174,6 +198,16 @@ export async function handleDateMention(});}+export async function handleGroupMention(+ group: GroupItem,+ dependencies: HandlerDependencies+) {+ const { editor } = dependencies;+ editor.dispatchCommand(INSERT_GROUP_MENTION_COMMAND, {+ groupAlias: group.groupAlias,+ });+}+export async function handleEmailMention(email: EmailEntity,dependencies: HandlerDependenciesdiff --git a/js/app/packages/core/vitest.config.ts b/js/app/packages/core/vitest.config.tsindex 6657df289e..7d9d45027c 100644--- a/js/app/packages/core/vitest.config.ts+++ b/js/app/packages/core/vitest.config.ts@@ -1,4 +1,5 @@import tsconfigPaths from 'vite-tsconfig-paths';+import wasm from 'vite-plugin-wasm';import { defineConfig } from 'vitest/config';export default defineConfig({@@ -6,6 +7,7 @@ export default defineConfig({tsconfigPaths({root: '../../',}),+ wasm(),],test: {environment: 'jsdom',diff --git a/js/app/packages/lexical-core/decoratorRegistry.ts b/js/app/packages/lexical-core/decoratorRegistry.tsindex 146cfb52b0..a0e5288833 100644--- a/js/app/packages/lexical-core/decoratorRegistry.ts+++ b/js/app/packages/lexical-core/decoratorRegistry.ts@@ -23,6 +23,10 @@ import type {EquationDecoratorProps,EquationNode,} from './nodes/EquationNode';+import type {+ GroupMentionDecoratorProps,+ GroupMentionNode,+} from './nodes/GroupMentionNode';import type {HorizontalRuleDecoratorProps,HorizontalRuleNode,@@ -59,6 +63,10 @@ export interface NodeDecoratorMap {klass: typeof UserMentionNode;props: UserMentionDecoratorProps;};+ GroupMentionNode: {+ klass: typeof GroupMentionNode;+ props: GroupMentionDecoratorProps;+ };DocumentMentionNode: {klass: typeof DocumentMentionNode;props: DocumentMentionDecoratorProps;diff --git a/js/app/packages/lexical-core/index.ts b/js/app/packages/lexical-core/index.tsindex a1b7694654..2a620d63f7 100644--- a/js/app/packages/lexical-core/index.ts+++ b/js/app/packages/lexical-core/index.ts@@ -15,6 +15,7 @@ export * from './nodes/DiffNode';export * from './nodes/DocumentCardNode';export * from './nodes/DocumentMentionNode';export * from './nodes/EquationNode';+export * from './nodes/GroupMentionNode';export * from './nodes/HorizontalRuleNode';export * from './nodes/HtmlRenderNode';export * from './nodes/ImageNode';diff --git a/js/app/packages/lexical-core/node-list.ts b/js/app/packages/lexical-core/node-list.tsindex 158ed24a54..186403d1ba 100644--- a/js/app/packages/lexical-core/node-list.ts+++ b/js/app/packages/lexical-core/node-list.ts@@ -20,6 +20,7 @@ import { ContactMentionNode } from './nodes/ContactMentionNode';import { CustomCodeNode } from './nodes/CustomCodeNode';import { DateMentionNode } from './nodes/DateMentionNode';import { DiffDeleteNode } from './nodes/DiffDeleteNode';+import { GroupMentionNode } from './nodes/GroupMentionNode';import { DiffInsertNode } from './nodes/DiffInsertNode';import { DiffNode } from './nodes/DiffNode';import { DocumentCardNode } from './nodes/DocumentCardNode';@@ -68,6 +69,7 @@ export const SupportedNodeTypes = [UserMentionNode,ContactMentionNode,DateMentionNode,+ GroupMentionNode,InlineSearchNode,UnlinkedTextNode,CodeHighlightNode,diff --git a/js/app/packages/lexical-core/nodes/GroupMentionNode.ts b/js/app/packages/lexical-core/nodes/GroupMentionNode.tsnew file mode 100644index 0000000000..aa519333a5--- /dev/null+++ b/js/app/packages/lexical-core/nodes/GroupMentionNode.ts@@ -0,0 +1,166 @@+import {+ $applyNodeReplacement,+ DecoratorNode,+ type DOMConversionMap,+ type EditorConfig,+ type EditorThemeClasses,+ type LexicalEditor,+ type LexicalNode,+ type NodeKey,+ type SerializedLexicalNode,+ type Spread,+} from 'lexical';+import { type DecoratorComponent, getDecorator } from '../decoratorRegistry';+import { $applyIdFromSerialized } from '../plugins/nodeIdPlugin';++export type GroupMentionInfo = {+ groupAlias: string;+};++export type SerializedGroupMentionNode = Spread<+ GroupMentionInfo,+ SerializedLexicalNode+>;++export type GroupMentionDecoratorProps = {+ groupAlias: string;+ key: NodeKey;+ theme: EditorThemeClasses;+};++export class GroupMentionNode extends DecoratorNode<+ DecoratorComponent<GroupMentionDecoratorProps> | undefined+> {+ __groupAlias: string;++ static getType() {+ return 'group-mention';+ }++ isInline(): boolean {+ return true;+ }++ isKeyboardSelectable(): boolean {+ return true;+ }++ static clone(node: GroupMentionNode) {+ return new GroupMentionNode(node.__groupAlias, node.__key);+ }++ constructor(groupAlias: string, key?: NodeKey) {+ super(key);+ this.__groupAlias = groupAlias;+ }++ static importJSON(serializedNode: SerializedGroupMentionNode) {+ const node = $createGroupMentionNode({+ groupAlias: serializedNode.groupAlias,+ });+ $applyIdFromSerialized(node, serializedNode);+ return node;+ }++ exportJSON(): SerializedGroupMentionNode {+ return {+ ...super.exportJSON(),+ groupAlias: this.__groupAlias,+ type: GroupMentionNode.getType(),+ version: 1,+ };+ }++ exportComponentProps(): GroupMentionInfo {+ return {+ groupAlias: this.__groupAlias,+ };+ }++ createDOM(_config: EditorConfig): HTMLElement {+ const container = document.createElement('span');+ return container;+ }++ updateDOM(): boolean {+ return false;+ }++ getDataAttrs(): Record<string, string | boolean> {+ return {+ 'data-group-mention': true,+ 'data-group-alias': this.__groupAlias,+ };+ }++ static importDOM(): DOMConversionMap<HTMLSpanElement> | null {+ return {+ span: (domNode: HTMLSpanElement) => {+ if (!domNode.hasAttribute('data-group-mention')) {+ return null;+ }+ return {+ conversion: (domNode: HTMLElement) => {+ const groupAlias = domNode.getAttribute('data-group-alias');++ if (groupAlias) {+ const node = $createGroupMentionNode({ groupAlias });+ return { node };+ }+ return null;+ },+ priority: 1,+ };+ },+ };+ }++ exportDOM() {+ const element = document.createElement('span');+ for (const [k, v] of Object.entries(this.getDataAttrs())) {+ element.setAttribute(k, v.toString());+ }+ element.textContent = `@${this.__groupAlias}`;+ return { element };+ }++ getTextContent(): string {+ return `@${this.__groupAlias}`;+ }++ getSearchText(): string {+ return '';+ }++ getGroupAlias(): string {+ return this.__groupAlias;+ }++ setGroupAlias(groupAlias: string) {+ const writable = this.getWritable();+ writable.__groupAlias = groupAlias;+ }++ decorate(_: LexicalEditor, config: EditorConfig) {+ const decorator = getDecorator<GroupMentionNode>(GroupMentionNode);+ if (decorator) {+ return () =>+ decorator({+ ...this.exportComponentProps(),+ key: this.getKey(),+ theme: config.theme,+ });+ }+ }+}++export function $createGroupMentionNode(params: { groupAlias: string }) {+ const node = new GroupMentionNode(params.groupAlias);+ return $applyNodeReplacement(node);+}++export function $isGroupMentionNode(+ node: GroupMentionNode | LexicalNode | null | undefined+): node is GroupMentionNode {+ return node instanceof GroupMentionNode;+}diff --git a/js/app/packages/lexical-core/tests/classedBlock.test.ts b/js/app/packages/lexical-core/tests/classedBlock.test.tsindex 16e44f2432..5cf99671aa 100644--- a/js/app/packages/lexical-core/tests/classedBlock.test.ts+++ b/js/app/packages/lexical-core/tests/classedBlock.test.ts@@ -47,9 +47,9 @@ describe('ClassedBlockNode - macro_quote transformer', () => {markdown = $convertToMarkdownString(INTERNAL_TRANSFORMERS);});- // Verify the markdown contains the macro-quote tag and metadata- expect(markdown).toContain('<macro-quote>');- expect(markdown).toContain('</macro-quote>');+ // Verify the markdown contains the email-thread-embed tag and metadata+ expect(markdown).toContain('<m-email-thread-embed>');+ expect(markdown).toContain('</m-email-thread-embed>');expect(markdown).toContain('"tag":"div"');expect(markdown).toContain('"classes":["macro_quote","gmail_quote"]');expect(markdown).toContain('This is a quoted email');diff --git a/js/app/packages/lexical-core/tests/mentions.test.ts b/js/app/packages/lexical-core/tests/mentions.test.tsindex bf27c7537c..869b9c1024 100644--- a/js/app/packages/lexical-core/tests/mentions.test.ts+++ b/js/app/packages/lexical-core/tests/mentions.test.ts@@ -4,6 +4,7 @@ import {parseContactMentions,parseDateMentions,parseDocumentMentions,+ parseGroupMentions,parseLinks,parseUserMentions,} from '../utils/parsers';@@ -127,6 +128,34 @@ describe('parseLinks', () => {});});+describe('parseGroupMentions', () => {+ it('extracts @alias from group mention', () => {+ const input = '<m-group-mention>{"groupAlias":"here"}</m-group-mention>';+ expect(parseGroupMentions(input)).toBe('@here');+ });++ it('handles missing groupAlias', () => {+ const input = '<m-group-mention>{}</m-group-mention>';+ expect(parseGroupMentions(input)).toBe('@');+ });++ it('handles invalid JSON', () => {+ const input = '<m-group-mention>invalid</m-group-mention>';+ expect(parseGroupMentions(input)).toBe('');+ });++ it('handles multiple group mentions', () => {+ const input =+ '<m-group-mention>{"groupAlias":"here"}</m-group-mention> and <m-group-mention>{"groupAlias":"team"}</m-group-mention>';+ expect(parseGroupMentions(input)).toBe('@here and @team');+ });++ it('passes through text without mentions', () => {+ const input = 'Hello world';+ expect(parseGroupMentions(input)).toBe('Hello world');+ });+});+describe('markdownToPlainText', () => {it('converts mixed content to plain text', () => {const input =@@ -146,6 +175,12 @@ describe('markdownToPlainText', () => {);});+ it('handles text with group mentions', () => {+ const input =+ 'Hey <m-group-mention>{"groupAlias":"here"}</m-group-mention>, check this out!';+ expect(markdownToPlainText(input)).toBe('Hey @here, check this out!');+ });+it('returns original text when no mentions present', () => {const input = 'Just plain text here.';expect(markdownToPlainText(input)).toBe('Just plain text here.');diff --git a/js/app/packages/lexical-core/transformers/index.ts b/js/app/packages/lexical-core/transformers/index.tsindex b87e897c2a..bc758a6465 100644--- a/js/app/packages/lexical-core/transformers/index.ts+++ b/js/app/packages/lexical-core/transformers/index.ts@@ -12,10 +12,12 @@ import {E_CONTACT_MENTION,E_DATE_MENTION,E_DOCUMENT_MENTION,+ E_GROUP_MENTION,E_USER_MENTION,I_CONTACT_MENTION,I_DATE_MENTION,I_DOCUMENT_MENTION,+ I_GROUP_MENTION,I_USER_MENTION,} from './mentions';import { E_TABLE_NODE, I_TABLE_NODE } from './tables';@@ -44,6 +46,7 @@ export const INTERNAL_TRANSFORMERS: Transformer[] = [I_IMAGE_CONSTRAINED,IMAGE, // Standard markdown images (fallback)I_USER_MENTION,+ I_GROUP_MENTION,I_DOCUMENT_MENTION,I_CONTACT_MENTION,I_DATE_MENTION,@@ -64,6 +67,7 @@ export const EXTERNAL_TRANSFORMERS: Transformer[] = [BR_TAG_TO_LINE_BREAK,E_TABLE_NODE,E_USER_MENTION,+ E_GROUP_MENTION,I_DOCUMENT_MENTION, // for chat attachmentsE_DOCUMENT_MENTION,E_CONTACT_MENTION,@@ -93,6 +97,8 @@ export const ALL_TRANSFORMERS: Transformer[] = [E_TABLE_NODE,I_USER_MENTION,E_USER_MENTION,+ I_GROUP_MENTION,+ E_GROUP_MENTION,I_DOCUMENT_MENTION,E_DOCUMENT_MENTION,I_CONTACT_MENTION,diff --git a/js/app/packages/lexical-core/transformers/mentions.ts b/js/app/packages/lexical-core/transformers/mentions.tsindex 243dcd9de4..4b8bbe9fb0 100644--- a/js/app/packages/lexical-core/transformers/mentions.ts+++ b/js/app/packages/lexical-core/transformers/mentions.ts@@ -6,6 +6,7 @@ import type { ElementNode, LexicalNode, TextNode } from 'lexical';import { ContactMentionNode } from '../nodes/ContactMentionNode';import { DateMentionNode } from '../nodes/DateMentionNode';import { DocumentMentionNode } from '../nodes/DocumentMentionNode';+import { GroupMentionNode } from '../nodes/GroupMentionNode';import { UserMentionNode } from '../nodes/UserMentionNode';// NOTE: If you are changing this file, you may need to update the `mention_utils` crate in `macro-api` as well. Please notify @hutch should you update this file.@@ -262,3 +263,53 @@ export const E_DOCUMENT_MENTION: ElementTransformer = {return false;},};++// Internal Group Mentions (e.g., @here)+export const I_GROUP_MENTION: TextMatchTransformer = {+ dependencies: [GroupMentionNode],+ type: 'text-match',+ regExp: /<m-group-mention>(.*?)<\/m-group-mention>/,+ importRegExp: /<m-group-mention>(.*?)<\/m-group-mention>/,+ export: (node) => {+ if (!(node instanceof GroupMentionNode)) return null;+ const data = JSON.stringify({+ groupAlias: node.getGroupAlias(),+ });+ return `<m-group-mention>${data}</m-group-mention>`;+ },+ replace: (node: TextNode, match: RegExpMatchArray) => {+ try {+ const data = JSON.parse(match[1]);+ if (!('groupAlias' in data)) throw new Error('Missing field groupAlias');+ const groupMentionNode = new GroupMentionNode(data.groupAlias);+ node.replace(groupMentionNode);+ } catch (e) {+ console.error('Error in I_GROUP_MENTION replace:', e);+ }+ },+};++// External Group Mentions+export const E_GROUP_MENTION: ElementTransformer = {+ dependencies: [GroupMentionNode],+ type: 'element',+ regExp: /$^/,+ export: (node) => {+ if (!(node instanceof GroupMentionNode)) return null;++ const groupAlias = node.getGroupAlias();+ if (!groupAlias) {+ return null;+ }++ return `@${groupAlias}`;+ },+ replace: (+ _parentNode: ElementNode,+ _children: Array<LexicalNode>,+ _match: Array<string>,+ _isImport: boolean+ ) => {+ return false;+ },+};diff --git a/js/app/packages/lexical-core/utils/mentions.ts b/js/app/packages/lexical-core/utils/mentions.tsindex b705691aef..a66808f00d 100644--- a/js/app/packages/lexical-core/utils/mentions.ts+++ b/js/app/packages/lexical-core/utils/mentions.ts@@ -14,6 +14,10 @@ import {type DocumentMentionInfo,type DocumentMentionNode,} from '@lexical-core/nodes/DocumentMentionNode';+import {+ $isGroupMentionNode,+ type GroupMentionNode,+} from '@lexical-core/nodes/GroupMentionNode';import {$isUserMentionNode,type UserMentionInfo,@@ -34,14 +38,16 @@ export type MentionNode =| UserMentionNode| DocumentMentionNode| ContactMentionNode- | DateMentionNode;+ | DateMentionNode+ | GroupMentionNode;export function $isMentionNode(node: LexicalNode): node is MentionNode {return ($isUserMentionNode(node) ||$isDocumentMentionNode(node) ||$isContactMentionNode(node) ||- $isDateMentionNode(node)+ $isDateMentionNode(node) ||+ $isGroupMentionNode(node));}@@ -80,6 +86,7 @@ export {parseContactMentions,parseDateMentions,parseDocumentMentions,+ parseGroupMentions,parseLinks,parseUserMentions,} from './parsers';diff --git a/js/app/packages/lexical-core/utils/parsers.ts b/js/app/packages/lexical-core/utils/parsers.tsindex f4a5938b3f..73b971fdff 100644--- a/js/app/packages/lexical-core/utils/parsers.ts+++ b/js/app/packages/lexical-core/utils/parsers.ts@@ -59,6 +59,20 @@ export function parseLinks(text: string): string {});}+export function parseGroupMentions(text: string): string {+ return text.replace(+ /<m-group-mention>(.*?)<\/m-group-mention>/g,+ (_, json) => {+ try {+ const data = JSON.parse(json);+ return `@${data.groupAlias || ''}`;+ } catch {+ return '';+ }+ }+ );+}+/*** Converts markdown text with XML mention tags to plain text.* Extracts the readable text from mention nodes:@@ -66,12 +80,15 @@ export function parseLinks(text: string): string {* - Contact mentions: name (fallback to emailOrDomain)* - Date mentions: displayFormat* - Document mentions: documentName+ * - Group mentions: @groupAlias (e.g., @here)* - Links: text (fallback to url)*/export function markdownToPlainText(markdown: string): string {return parseLinks(parseDocumentMentions(- parseDateMentions(parseContactMentions(parseUserMentions(markdown)))+ parseGroupMentions(+ parseDateMentions(parseContactMentions(parseUserMentions(markdown)))+ )));}diff --git a/js/app/vitest.config.ts b/js/app/vitest.config.tsindex e60f589164..30e535fd8f 100644--- a/js/app/vitest.config.ts+++ b/js/app/vitest.config.ts@@ -44,6 +44,20 @@ export default defineConfig({name: 'scripts',},},+ {+ extends: './packages/lexical-core/vitest.config.ts',+ test: {+ include: ['packages/lexical-core/**/*.{test,spec}.{ts,tsx}'],+ name: 'lexical-core',+ },+ },+ {+ extends: './packages/core/vitest.config.ts',+ test: {+ include: ['packages/block-channel/**/*.{test,spec}.{ts,tsx}'],+ name: 'block-channel',+ },+ },],},});