Rework MentionNode to take a whole Mention entity

environments/review-html-parse-ic2vy5/deployments/4174
Alex Gleason 2023-10-13 22:14:55 -05:00
rodzic 70dc4caeb9
commit e0c11fbfd1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 14 dodań i 16 usunięć

Wyświetl plik

@ -16,28 +16,29 @@ import type {
SerializedLexicalNode,
Spread,
} from 'lexical';
import type { Mention as MentionEntity } from 'soapbox/schemas';
type SerializedMentionNode = Spread<{
acct: string;
mention: MentionEntity;
type: 'mention';
version: 1;
}, SerializedLexicalNode>;
class MentionNode extends DecoratorNode<JSX.Element> {
__acct: string;
__mention: MentionEntity;
static getType(): string {
return 'mention';
}
static clone(node: MentionNode): MentionNode {
return new MentionNode(node.__acct, node.__key);
return new MentionNode(node.__mention, node.__key);
}
constructor(acct: string, key?: NodeKey) {
constructor(mention: MentionEntity, key?: NodeKey) {
super(key);
this.__acct = acct;
this.__mention = mention;
}
createDOM(config: EditorConfig): HTMLElement {
@ -49,20 +50,20 @@ class MentionNode extends DecoratorNode<JSX.Element> {
}
static importJSON(serializedNode: SerializedMentionNode): MentionNode {
const node = $createMentionNode(serializedNode.acct);
const node = $createMentionNode(serializedNode.mention);
return node;
}
exportJSON(): SerializedMentionNode {
return {
type: 'mention',
acct: this.__acct,
mention: this.__mention,
version: 1,
};
}
getTextContent(): string {
return `@${this.__acct}`;
return `@${this.__mention.acct}`;
}
canInsertTextBefore(): boolean {
@ -74,18 +75,15 @@ class MentionNode extends DecoratorNode<JSX.Element> {
}
decorate(): JSX.Element {
const acct = this.__acct;
const username = acct.split('@')[0];
return (
<Mention mention={{ acct, username }} disabled />
<Mention mention={this.__mention} disabled />
);
}
}
function $createMentionNode(acct: string): MentionNode {
const node = new MentionNode(acct);
function $createMentionNode(mention: MentionEntity): MentionNode {
const node = new MentionNode(mention);
return $applyNodeReplacement(node);
}

Wyświetl plik

@ -327,8 +327,8 @@ const AutosuggestPlugin = ({
node.setTextContent(`${suggestion} `);
node.select();
} else {
const acct = selectAccount(getState(), suggestion)!.acct;
replaceMatch($createMentionNode(acct));
const account = selectAccount(getState(), suggestion)!;
replaceMatch($createMentionNode(account));
}
dispatch(clearComposeSuggestions(composeId));