Path: blob/master/src/packages/frontend/editors/slate/elements/mention/index.tsx
1702 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/* We want mentions to be represented in the markdown like this:67<span class="user-mention" account-id=47d0393e-4814-4452-bb6c-35bac4cbd314 >@Bella Welski</span>89because then they will be compatible with all mentions already used with chat and tasks.10*/1112import React from "react";13import { SlateElement, register, RenderElementProps } from "../register";1415export interface Mention extends SlateElement {16type: "mention";17account_id: string;18name: string;19isInline: true;20isVoid: true;21}2223const STYLE = {24color: "#0958d9",25background: "white",26borderRadius: "3px",27padding: "3px",28margin: "-3px 0",29} as React.CSSProperties;3031const StaticElement: React.FC<RenderElementProps> = ({32attributes,33element,34}) => {35if (element.type != "mention") {36throw Error("bug");37}38return (39<span {...attributes} style={STYLE}>40@{element.name}41</span>42);43};4445export function createMentionStatic(account_id: string, name?: string) {46if (name == null) {47name = "User";48}49return {50type: "mention" as "mention",51isVoid: true as true,52isInline: true as true,53account_id,54name: name as string,55children: [{ text: "" }],56};57}5859register({60slateType: "mention",6162toSlate: ({ token }) => {63const { account_id, name } = token;64return createMentionStatic(account_id, name);65},6667StaticElement,68});697071