Update rich text editor dependency and associated changes (#11098)
* fix logic error * update types * extract message content to variable * use the new messageContent property * sort out mention types to make them a map * update getMentionAttributes to use AllowedMentionAttributes * add plain text handling * change type and handling for attributes when creating a mention in plain text * tidy, add comment * revert TS config change * fix broken types in test * update tests * bump rte * fix import and ts errors * fix broken tests
This commit is contained in:
parent
97765613bc
commit
fa31ed55d2
12 changed files with 108 additions and 77 deletions
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { Attributes, MappedSuggestion } from "@matrix-org/matrix-wysiwyg";
|
||||
import { AllowedMentionAttributes, MappedSuggestion } from "@matrix-org/matrix-wysiwyg";
|
||||
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { ICompletion } from "../../../../../autocomplete/Autocompleter";
|
||||
|
@ -91,18 +91,22 @@ export function getMentionDisplayText(completion: ICompletion, client: MatrixCli
|
|||
* @param client - the MatrixClient is required for us to look up the correct room mention text
|
||||
* @returns an object of attributes containing HTMLAnchor attributes or data-* attributes
|
||||
*/
|
||||
export function getMentionAttributes(completion: ICompletion, client: MatrixClient, room: Room): Attributes {
|
||||
export function getMentionAttributes(
|
||||
completion: ICompletion,
|
||||
client: MatrixClient,
|
||||
room: Room,
|
||||
): AllowedMentionAttributes {
|
||||
// To ensure that we always have something set in the --avatar-letter CSS variable
|
||||
// as otherwise alignment varies depending on whether the content is empty or not.
|
||||
|
||||
// Use a zero width space so that it counts as content, but does not display anything.
|
||||
const defaultLetterContent = "\u200b";
|
||||
const attributes: AllowedMentionAttributes = new Map();
|
||||
|
||||
if (completion.type === "user") {
|
||||
// logic as used in UserPillPart.setAvatar in parts.ts
|
||||
const mentionedMember = room.getMember(completion.completionId || "");
|
||||
|
||||
if (!mentionedMember) return {};
|
||||
if (!mentionedMember) return attributes;
|
||||
|
||||
const name = mentionedMember.name || mentionedMember.userId;
|
||||
const defaultAvatarUrl = Avatar.defaultAvatarUrlForString(mentionedMember.userId);
|
||||
|
@ -112,10 +116,8 @@ export function getMentionAttributes(completion: ICompletion, client: MatrixClie
|
|||
initialLetter = Avatar.getInitialLetter(name) ?? defaultLetterContent;
|
||||
}
|
||||
|
||||
return {
|
||||
"data-mention-type": completion.type,
|
||||
"style": `--avatar-background: url(${avatarUrl}); --avatar-letter: '${initialLetter}'`,
|
||||
};
|
||||
attributes.set("data-mention-type", completion.type);
|
||||
attributes.set("style", `--avatar-background: url(${avatarUrl}); --avatar-letter: '${initialLetter}'`);
|
||||
} else if (completion.type === "room") {
|
||||
// logic as used in RoomPillPart.setAvatar in parts.ts
|
||||
const mentionedRoom = getRoomFromCompletion(completion, client);
|
||||
|
@ -128,12 +130,12 @@ export function getMentionAttributes(completion: ICompletion, client: MatrixClie
|
|||
avatarUrl = Avatar.defaultAvatarUrlForString(mentionedRoom?.roomId ?? aliasFromCompletion);
|
||||
}
|
||||
|
||||
return {
|
||||
"data-mention-type": completion.type,
|
||||
"style": `--avatar-background: url(${avatarUrl}); --avatar-letter: '${initialLetter}'`,
|
||||
};
|
||||
attributes.set("data-mention-type", completion.type);
|
||||
attributes.set("style", `--avatar-background: url(${avatarUrl}); --avatar-letter: '${initialLetter}'`);
|
||||
} else if (completion.type === "at-room") {
|
||||
return { "data-mention-type": completion.type };
|
||||
// TODO add avatar logic for at-room
|
||||
attributes.set("data-mention-type", completion.type);
|
||||
}
|
||||
return {};
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue