Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
Alun Turner committed Jun 15, 2023
1 parent a224b68 commit eeabf03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Autocomplete from "../../Autocomplete";
import { ICompletion } from "../../../../../autocomplete/Autocompleter";
import { useMatrixClientContext } from "../../../../../contexts/MatrixClientContext";
import { getMentionDisplayText, getMentionAttributes, buildQuery } from "../utils/autocomplete";
import { isNotUndefined } from "../../../../../Typeguards";

interface WysiwygAutocompleteProps {
/**
Expand Down Expand Up @@ -72,25 +73,23 @@ const WysiwygAutocomplete = forwardRef(
return;
}
case "at-room": {
// TODO improve handling of at-room to either become a span or use a placeholder href
// We have an issue in that we can't use a placeholder because the rust model is always
// applying a prefix to the href, so an href of "#" becomes https://# and also we can not
// represent a plain span in rust
handleMention(
window.location.href,
getMentionDisplayText(completion, client),
getMentionAttributes(completion, client, room),
);
const { style } = getMentionAttributes(completion, client, room);
const attributesMap = new Map();
if (isNotUndefined(style)) {
attributesMap.set("style", style);
}
handleMention("#", getMentionDisplayText(completion, client), attributesMap);
return;
}
case "room":
case "user": {
if (typeof completion.href === "string") {
handleMention(
completion.href,
getMentionDisplayText(completion, client),
getMentionAttributes(completion, client, room),
);
const { style } = getMentionAttributes(completion, client, room);
const attributesMap = new Map();
if (isNotUndefined(style)) {
attributesMap.set("style", style);
}
handleMention(completion.href, getMentionDisplayText(completion, client), attributesMap);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -91,7 +91,11 @@ 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,
): { "data-mention-type"?: string; "style"?: string } {
// 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.

Expand Down

0 comments on commit eeabf03

Please sign in to comment.