mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-19 14:53:00 +08:00
Add CollaborationCursor demo for React
This commit is contained in:
parent
c1068aedcf
commit
d1b582cd92
15
demos/src/Extensions/CollaborationCursor/React/index.html
Normal file
15
demos/src/Extensions/CollaborationCursor/React/index.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module">
|
||||
import setup from "../../../../setup/react.ts";
|
||||
import source from "@source";
|
||||
setup("Extensions/CollaborationCursor", source);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
40
demos/src/Extensions/CollaborationCursor/React/index.jsx
Normal file
40
demos/src/Extensions/CollaborationCursor/React/index.jsx
Normal file
@ -0,0 +1,40 @@
|
||||
import React from 'react'
|
||||
import { useEditor, EditorContent } from '@tiptap/react'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import Collaboration from '@tiptap/extension-collaboration'
|
||||
import CollaborationCursor from '@tiptap/extension-collaboration-cursor'
|
||||
import * as Y from 'yjs'
|
||||
import { WebrtcProvider } from 'y-webrtc'
|
||||
import Placeholder from '@tiptap/extension-placeholder'
|
||||
import './styles.scss'
|
||||
|
||||
const ydoc = new Y.Doc()
|
||||
const provider = new WebrtcProvider('tiptap-collaboration-cursor-extension', ydoc)
|
||||
|
||||
export default () => {
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
Document,
|
||||
Paragraph,
|
||||
Text,
|
||||
Collaboration.configure({
|
||||
document: ydoc,
|
||||
}),
|
||||
CollaborationCursor.configure({
|
||||
provider,
|
||||
user: {
|
||||
name: 'Cyndi Lauper',
|
||||
color: '#f783ac',
|
||||
},
|
||||
}),
|
||||
Placeholder.configure({
|
||||
placeholder:
|
||||
'Write something … It’ll be shared with everyone else looking at this example.',
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
return <EditorContent editor={editor} />
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
context('/src/Extensions/CollaborationCursor/React', () => {
|
||||
before(() => {
|
||||
cy.visit('/src/Extensions/CollaborationCursor/React')
|
||||
})
|
||||
|
||||
// TODO: Write tests
|
||||
})
|
42
demos/src/Extensions/CollaborationCursor/React/styles.scss
Normal file
42
demos/src/Extensions/CollaborationCursor/React/styles.scss
Normal file
@ -0,0 +1,42 @@
|
||||
/* Basic editor styles */
|
||||
.ProseMirror {
|
||||
> * + * {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
}
|
||||
|
||||
/* Placeholder (at the top) */
|
||||
.ProseMirror p.is-editor-empty:first-child::before {
|
||||
color: #adb5bd;
|
||||
content: attr(data-placeholder);
|
||||
float: left;
|
||||
height: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Give a remote user a caret */
|
||||
.collaboration-cursor__caret {
|
||||
border-left: 1px solid #0d0d0d;
|
||||
border-right: 1px solid #0d0d0d;
|
||||
margin-left: -1px;
|
||||
margin-right: -1px;
|
||||
pointer-events: none;
|
||||
position: relative;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
/* Render the username above the caret */
|
||||
.collaboration-cursor__label {
|
||||
border-radius: 3px 3px 3px 0;
|
||||
color: #0d0d0d;
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
left: -1px;
|
||||
line-height: normal;
|
||||
padding: 0.1rem 0.3rem;
|
||||
position: absolute;
|
||||
top: -1.4em;
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
context('/src/Extensions/CollaborationCursor', () => {
|
||||
context('/src/Extensions/CollaborationCursor/Vue', () => {
|
||||
before(() => {
|
||||
cy.visit('/src/Extensions/CollaborationCursor')
|
||||
cy.visit('/src/Extensions/CollaborationCursor/Vue')
|
||||
})
|
||||
|
||||
// TODO: Write tests
|
||||
|
Loading…
Reference in New Issue
Block a user