Highlight mentions of self in documents and comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* global File Promise */
|
/* global File Promise */
|
||||||
import { PluginSimple } from "markdown-it";
|
import { PluginSimple } from "markdown-it";
|
||||||
import { transparentize } from "polished";
|
import { darken, transparentize } from "polished";
|
||||||
import { baseKeymap } from "prosemirror-commands";
|
import { baseKeymap } from "prosemirror-commands";
|
||||||
import { dropCursor } from "prosemirror-dropcursor";
|
import { dropCursor } from "prosemirror-dropcursor";
|
||||||
import { gapCursor } from "prosemirror-gapcursor";
|
import { gapCursor } from "prosemirror-gapcursor";
|
||||||
@@ -56,7 +56,7 @@ import WithTheme from "./components/WithTheme";
|
|||||||
export type Props = {
|
export type Props = {
|
||||||
/** An optional identifier for the editor context. It is used to persist local settings */
|
/** An optional identifier for the editor context. It is used to persist local settings */
|
||||||
id?: string;
|
id?: string;
|
||||||
/** The current userId, if any */
|
/** The user id of the current user */
|
||||||
userId?: string;
|
userId?: string;
|
||||||
/** The editor content, should only be changed if you wish to reset the content */
|
/** The editor content, should only be changed if you wish to reset the content */
|
||||||
value?: string;
|
value?: string;
|
||||||
@@ -753,6 +753,7 @@ export class Editor extends React.PureComponent<
|
|||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
readOnlyWriteCheckboxes={canUpdate}
|
readOnlyWriteCheckboxes={canUpdate}
|
||||||
focusedCommentId={this.props.focusedCommentId}
|
focusedCommentId={this.props.focusedCommentId}
|
||||||
|
userId={this.props.userId}
|
||||||
editorStyle={this.props.editorStyle}
|
editorStyle={this.props.editorStyle}
|
||||||
ref={this.elementRef}
|
ref={this.elementRef}
|
||||||
lang=""
|
lang=""
|
||||||
@@ -791,7 +792,10 @@ export class Editor extends React.PureComponent<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditorContainer = styled(Styles)<{ focusedCommentId?: string }>`
|
const EditorContainer = styled(Styles)<{
|
||||||
|
userId?: string;
|
||||||
|
focusedCommentId?: string;
|
||||||
|
}>`
|
||||||
${(props) =>
|
${(props) =>
|
||||||
props.focusedCommentId &&
|
props.focusedCommentId &&
|
||||||
css`
|
css`
|
||||||
@@ -799,6 +803,21 @@ const EditorContainer = styled(Styles)<{ focusedCommentId?: string }>`
|
|||||||
background: ${transparentize(0.5, props.theme.brand.marine)};
|
background: ${transparentize(0.5, props.theme.brand.marine)};
|
||||||
}
|
}
|
||||||
`}
|
`}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.userId &&
|
||||||
|
css`
|
||||||
|
.mention[data-id=${props.userId}] {
|
||||||
|
color: ${props.theme.textHighlightForeground};
|
||||||
|
background: ${props.theme.textHighlight};
|
||||||
|
|
||||||
|
&.ProseMirror-selectednode {
|
||||||
|
outline-color: ${props.readOnly
|
||||||
|
? "transparent"
|
||||||
|
: darken(0.2, props.theme.textHighlight)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const LazyLoadedEditor = React.forwardRef<Editor, Props>(
|
const LazyLoadedEditor = React.forwardRef<Editor, Props>(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import MentionMenuExtension from "~/editor/extensions/MentionMenu";
|
|||||||
import PasteHandler from "~/editor/extensions/PasteHandler";
|
import PasteHandler from "~/editor/extensions/PasteHandler";
|
||||||
import PreventTab from "~/editor/extensions/PreventTab";
|
import PreventTab from "~/editor/extensions/PreventTab";
|
||||||
import SmartText from "~/editor/extensions/SmartText";
|
import SmartText from "~/editor/extensions/SmartText";
|
||||||
|
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||||
|
|
||||||
const extensions = [
|
const extensions = [
|
||||||
...withComments(basicExtensions),
|
...withComments(basicExtensions),
|
||||||
@@ -25,6 +26,12 @@ const extensions = [
|
|||||||
const CommentEditor = (
|
const CommentEditor = (
|
||||||
props: EditorProps,
|
props: EditorProps,
|
||||||
ref: React.RefObject<SharedEditor>
|
ref: React.RefObject<SharedEditor>
|
||||||
) => <Editor extensions={extensions} {...props} ref={ref} />;
|
) => {
|
||||||
|
const user = useCurrentUser({ rejectOnEmpty: false });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Editor extensions={extensions} userId={user?.id} {...props} ref={ref} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default React.forwardRef(CommentEditor);
|
export default React.forwardRef(CommentEditor);
|
||||||
|
|||||||
Reference in New Issue
Block a user