mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 06:16:59 +08:00
fix(editor): add member node before mention (#11197)
This commit is contained in:
@@ -29,6 +29,10 @@ import { computed, Signal, signal } from '@preact/signals-core';
|
|||||||
import { Service } from '@toeverything/infra';
|
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 {
|
||||||
|
createAbsolutePositionFromRelativePosition,
|
||||||
|
createRelativePositionFromTypeIndex,
|
||||||
|
} from 'yjs';
|
||||||
|
|
||||||
import { AuthService, type WorkspaceServerService } from '../../cloud';
|
import { AuthService, type WorkspaceServerService } from '../../cloud';
|
||||||
import type { WorkspaceDialogService } from '../../dialogs';
|
import type { WorkspaceDialogService } from '../../dialogs';
|
||||||
@@ -369,62 +373,80 @@ export class AtMenuConfigService extends Service {
|
|||||||
|
|
||||||
close();
|
close();
|
||||||
|
|
||||||
if (id === currentUserId) {
|
const inlineRange = inlineEditor.getInlineRange();
|
||||||
const inlineRange = inlineEditor.getInlineRange();
|
if (!inlineRange || inlineRange.length !== 0) return;
|
||||||
if (inlineRange && inlineRange.length === 0) {
|
|
||||||
inlineEditor.insertText(inlineRange, ' ', {
|
|
||||||
mention: {
|
|
||||||
member: id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
inlineEditor.setInlineRange({
|
|
||||||
index: inlineRange.index + 1,
|
|
||||||
length: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
inlineEditor.insertText(inlineRange, ' ', {
|
||||||
}
|
mention: {
|
||||||
|
member: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
inlineEditor.setInlineRange({
|
||||||
|
index: inlineRange.index + 1,
|
||||||
|
length: 0,
|
||||||
|
});
|
||||||
|
|
||||||
notificationService
|
const relativePosition = createRelativePositionFromTypeIndex(
|
||||||
.mentionUser(id, workspaceId, {
|
inlineEditor.yText,
|
||||||
id: docId,
|
inlineRange.index + 1
|
||||||
title: this.docDisplayMetaService.title$(docId).value,
|
);
|
||||||
blockId: block.blockId,
|
|
||||||
mode: mode as GraphqlDocMode,
|
if (id !== currentUserId) {
|
||||||
})
|
notificationService
|
||||||
.then(notificationId => {
|
.mentionUser(id, workspaceId, {
|
||||||
const inlineRange = inlineEditor.getInlineRange();
|
id: docId,
|
||||||
if (inlineRange && inlineRange.length === 0) {
|
title: this.docDisplayMetaService.title$(docId).value,
|
||||||
inlineEditor.insertText(inlineRange, ' ', {
|
blockId: block.blockId,
|
||||||
mention: {
|
mode: mode as GraphqlDocMode,
|
||||||
member: id,
|
})
|
||||||
notification: notificationId,
|
.then(notificationId => {
|
||||||
|
const doc = inlineEditor.yText.doc;
|
||||||
|
if (!doc) return;
|
||||||
|
const absolutePosition =
|
||||||
|
createAbsolutePositionFromRelativePosition(
|
||||||
|
relativePosition,
|
||||||
|
doc
|
||||||
|
);
|
||||||
|
if (!absolutePosition) return;
|
||||||
|
const index = absolutePosition.index;
|
||||||
|
|
||||||
|
const delta = inlineEditor.getDeltaByRangeIndex(index);
|
||||||
|
if (
|
||||||
|
!delta ||
|
||||||
|
delta.insert !== ' ' ||
|
||||||
|
!delta.attributes?.mention ||
|
||||||
|
delta.attributes.mention.notification ||
|
||||||
|
delta.attributes.mention.member !== id
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
|
inlineEditor.formatText(
|
||||||
|
{
|
||||||
|
index: index - 1,
|
||||||
|
length: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
mention: {
|
||||||
|
member: id,
|
||||||
|
notification: notificationId,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
const err = UserFriendlyError.fromAny(error);
|
||||||
|
notify.error({
|
||||||
|
title: I18n[`error.${err.name}`](err.data),
|
||||||
});
|
});
|
||||||
inlineEditor.setInlineRange({
|
|
||||||
index: inlineRange.index + 1,
|
|
||||||
length: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
notify.success({
|
|
||||||
title: I18n.t('com.affine.editor.at-menu.mention-success'),
|
|
||||||
});
|
});
|
||||||
})
|
}
|
||||||
.catch(error => {
|
|
||||||
const err = UserFriendlyError.fromAny(error);
|
|
||||||
notify.error({
|
|
||||||
title: I18n[`error.${err.name}`](err.data),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (query.length === 0) {
|
if (query.length === 0) {
|
||||||
return {
|
return {
|
||||||
name: I18n.t('com.affine.editor.at-menu.mention-member'),
|
name: I18n.t('com.affine.editor.at-menu.mention-members'),
|
||||||
items: [
|
items: [
|
||||||
...this.memberSearchService.result$.value
|
...this.memberSearchService.result$.value
|
||||||
.slice(0, 3)
|
.slice(0, 3)
|
||||||
@@ -446,7 +468,7 @@ export class AtMenuConfigService extends Service {
|
|||||||
this.memberSearchService.search(query);
|
this.memberSearchService.search(query);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: I18n.t('com.affine.editor.at-menu.mention-member'),
|
name: I18n.t('com.affine.editor.at-menu.mention-members'),
|
||||||
items,
|
items,
|
||||||
loading,
|
loading,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6928,13 +6928,9 @@ export function useAFFiNEI18N(): {
|
|||||||
*/
|
*/
|
||||||
["com.affine.editor.at-menu.date-picker"](): string;
|
["com.affine.editor.at-menu.date-picker"](): string;
|
||||||
/**
|
/**
|
||||||
* `Mention Member`
|
* `Mention Members`
|
||||||
*/
|
*/
|
||||||
["com.affine.editor.at-menu.mention-member"](): string;
|
["com.affine.editor.at-menu.mention-members"](): string;
|
||||||
/**
|
|
||||||
* `Successfully mentioned the member`
|
|
||||||
*/
|
|
||||||
["com.affine.editor.at-menu.mention-success"](): string;
|
|
||||||
/**
|
/**
|
||||||
* `Show`
|
* `Show`
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1720,8 +1720,7 @@
|
|||||||
"com.affine.editor.at-menu.more-docs-hint": "{{count}} more docs",
|
"com.affine.editor.at-menu.more-docs-hint": "{{count}} more docs",
|
||||||
"com.affine.editor.at-menu.journal": "Journal",
|
"com.affine.editor.at-menu.journal": "Journal",
|
||||||
"com.affine.editor.at-menu.date-picker": "Select a specific date",
|
"com.affine.editor.at-menu.date-picker": "Select a specific date",
|
||||||
"com.affine.editor.at-menu.mention-member": "Mention Member",
|
"com.affine.editor.at-menu.mention-members": "Mention Members",
|
||||||
"com.affine.editor.at-menu.mention-success": "Successfully mentioned the member",
|
|
||||||
"com.affine.editor.bi-directional-link-panel.show": "Show",
|
"com.affine.editor.bi-directional-link-panel.show": "Show",
|
||||||
"com.affine.editor.bi-directional-link-panel.hide": "Hide",
|
"com.affine.editor.bi-directional-link-panel.hide": "Hide",
|
||||||
"com.affine.editor.edgeless-note-header.fold-page-block": "Fold page block",
|
"com.affine.editor.edgeless-note-header.fold-page-block": "Fold page block",
|
||||||
|
|||||||
Reference in New Issue
Block a user