fix(editor): support mention user itself (#11133)
This commit is contained in:
@@ -12,7 +12,7 @@ export const MentionInlineSpecExtension =
|
|||||||
schema: z
|
schema: z
|
||||||
.object({
|
.object({
|
||||||
member: z.string(),
|
member: z.string(),
|
||||||
notification: z.string(),
|
notification: z.string().optional(),
|
||||||
})
|
})
|
||||||
.optional()
|
.optional()
|
||||||
.nullable()
|
.nullable()
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export interface AffineTextAttributes {
|
|||||||
footnote?: FootNote | null;
|
footnote?: FootNote | null;
|
||||||
mention?: {
|
mention?: {
|
||||||
member: string;
|
member: string;
|
||||||
notification: string;
|
notification?: string;
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import { Service } from '@toeverything/infra';
|
|||||||
import { cssVarV2 } from '@toeverything/theme/v2';
|
import { cssVarV2 } from '@toeverything/theme/v2';
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
|
|
||||||
import type { WorkspaceServerService } from '../../cloud';
|
import { AuthService, type WorkspaceServerService } from '../../cloud';
|
||||||
import type { WorkspaceDialogService } from '../../dialogs';
|
import type { WorkspaceDialogService } from '../../dialogs';
|
||||||
import type { DocsService } from '../../doc';
|
import type { DocsService } from '../../doc';
|
||||||
import type { DocDisplayMetaService } from '../../doc-display-meta';
|
import type { DocDisplayMetaService } from '../../doc-display-meta';
|
||||||
@@ -352,8 +352,6 @@ export class AtMenuConfigService extends Service {
|
|||||||
name: name ?? 'Unknown',
|
name: name ?? 'Unknown',
|
||||||
icon,
|
icon,
|
||||||
action: () => {
|
action: () => {
|
||||||
close();
|
|
||||||
|
|
||||||
const root = inlineEditor.rootElement;
|
const root = inlineEditor.rootElement;
|
||||||
const block = root?.closest<BlockComponent>(`[${BLOCK_ID_ATTR}]`);
|
const block = root?.closest<BlockComponent>(`[${BLOCK_ID_ATTR}]`);
|
||||||
if (!block) return;
|
if (!block) return;
|
||||||
@@ -365,13 +363,36 @@ export class AtMenuConfigService extends Service {
|
|||||||
const doc = block.doc;
|
const doc = block.doc;
|
||||||
const workspaceId = doc.workspace.id;
|
const workspaceId = doc.workspace.id;
|
||||||
const docId = doc.id;
|
const docId = doc.id;
|
||||||
const docTitle = doc.meta?.title ?? '';
|
|
||||||
const mode = block.std.get(DocModeProvider).getEditorMode() ?? 'page';
|
const mode = block.std.get(DocModeProvider).getEditorMode() ?? 'page';
|
||||||
|
|
||||||
|
const currentUserId =
|
||||||
|
this.workspaceServerService.server?.scope.get(AuthService).session
|
||||||
|
.account$.value?.id;
|
||||||
|
if (!currentUserId) return;
|
||||||
|
|
||||||
|
close();
|
||||||
|
|
||||||
|
if (id === currentUserId) {
|
||||||
|
const inlineRange = inlineEditor.getInlineRange();
|
||||||
|
if (inlineRange && inlineRange.length === 0) {
|
||||||
|
inlineEditor.insertText(inlineRange, ' ', {
|
||||||
|
mention: {
|
||||||
|
member: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
inlineEditor.setInlineRange({
|
||||||
|
index: inlineRange.index + 1,
|
||||||
|
length: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
notificationService
|
notificationService
|
||||||
.mentionUser(id, workspaceId, {
|
.mentionUser(id, workspaceId, {
|
||||||
id: docId,
|
id: docId,
|
||||||
title: docTitle,
|
title: this.docDisplayMetaService.title$(docId).value,
|
||||||
blockId: block.blockId,
|
blockId: block.blockId,
|
||||||
mode: mode as GraphqlDocMode,
|
mode: mode as GraphqlDocMode,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user