From 7dcbaa9c5cfdf3e74833e879e6fbe81021ca4875 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 15 Oct 2020 22:10:30 -0700 Subject: [PATCH] cursors --- app/components/Editor.js | 42 ++++++++++++++++------ app/scenes/Document/components/Document.js | 21 +++++++++-- shared/styles/animations.js | 5 +++ 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/app/components/Editor.js b/app/components/Editor.js index 5f3c4844ef..7fd2948877 100644 --- a/app/components/Editor.js +++ b/app/components/Editor.js @@ -99,27 +99,47 @@ const StyledEditor = styled(RichMarkdownEditor)` .ProseMirror { .ProseMirror-yjs-cursor { - position: absolute; - border-left: black; - border-left-style: solid; - border-left-width: 2px; - border-color: orange; + position: relative; + margin-left: -1px; + margin-right: -1px; + border-left: 1px solid black; + border-right: 1px solid black; height: 1em; word-break: normal; - pointer-events: none; + + &:after { + content: ""; + display: block; + position: absolute; + left: -8px; + right: -8px; + top: 0; + bottom: 0; + } > div { - position: relative; - top: -1.05em; + opacity: 0; + position: absolute; + top: -1.8em; font-size: 13px; background-color: rgb(250, 129, 0); font-style: normal; - font-weight: normal; line-height: normal; user-select: none; + white-space: nowrap; color: white; - padding-left: 2px; - padding-right: 2px; + padding: 2px 6px; + font-weight: 500; + border-radius: 4px; + pointer-events: none; + left: -1px; + } + + &:hover { + > div { + opacity: 1; + transition: opacity 100ms ease-in-out; + } } } } diff --git a/app/scenes/Document/components/Document.js b/app/scenes/Document/components/Document.js index c6118bf945..af67d7a21d 100644 --- a/app/scenes/Document/components/Document.js +++ b/app/scenes/Document/components/Document.js @@ -82,11 +82,20 @@ class Multiplayer extends Extension { } get plugins() { - const type = this.options.doc.get("prosemirror", Y.XmlFragment); + const { user, provider, doc } = this.options; + const type = doc.get("prosemirror", Y.XmlFragment); + + provider.awareness.setLocalStateField("user", { + color: "#008833", + name: user.name, + }); + + const permanentUserData = new Y.PermanentUserData(doc); + permanentUserData.setUserMapping(doc, doc.clientID, user.id); return [ ySyncPlugin(type), - yCursorPlugin(this.options.provider.awareness), + yCursorPlugin(provider.awareness), yUndoPlugin(), keymap({ "Mod-z": undo, @@ -352,6 +361,7 @@ class DocumentScene extends React.Component { match, } = this.props; const team = auth.team; + const user = auth.user; const isShare = !!match.params.shareId; const value = revision ? revision.text : document.text; @@ -477,7 +487,12 @@ class DocumentScene extends React.Component { readOnly={readOnly} readOnlyWriteCheckboxes={readOnly && abilities.update} ui={this.props.ui} - extensions={[new Multiplayer(this.props.multiplayer)]} + extensions={[ + new Multiplayer({ + user, + ...this.props.multiplayer, + }), + ]} /> {readOnly && !isShare && !revision && ( diff --git a/shared/styles/animations.js b/shared/styles/animations.js index d09a3d2a1f..77dc1b117d 100644 --- a/shared/styles/animations.js +++ b/shared/styles/animations.js @@ -6,6 +6,11 @@ export const fadeIn = keyframes` to { opacity: 1; } `; +export const fadeOut = keyframes` + from { opacity: 0; } + to { opacity: 1; } +`; + export const fadeAndScaleIn = keyframes` from { opacity: 0;