Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge display and index #5

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
text-align: center;
font-size: 24px;
}

.page .subtitle {
padding: 10px;
text-align: center;
font-size: 24px;
}

.page .editor {
position: relative;
margin-top: 32px;
Expand All @@ -21,6 +28,14 @@
padding: 0 90px;
min-height: 400px;
}

.page .content {
width: 660px;
margin: 0 auto;
border-style:solid;
border-width: 1px;
border-color: black;
}
</style>
</head>
<body>
Expand All @@ -29,6 +44,8 @@
<div class="editor">
<div class="editor-container" id="container"></div>
</div>
<div class="subtitle">Miks Collaborative Editor Content</div>
<div class="content ql-editor"></div>
</div>
</body>
</html>
46 changes: 46 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import 'quill/dist/quill.snow.css'
import EditorEvents from "../editor-events";
import '../modules/task-list';

import ReconnectingWebSocket from "reconnecting-websocket";
import ShareDB from "sharedb/lib/client";
import Quill from 'quill';
import richText from "rich-text";
ShareDB.types.register(richText.type);

import '../display.styl';


let authors = [
{
id: 1,
Expand Down Expand Up @@ -113,6 +122,43 @@ editor.on(EditorEvents.synchronizationError, (err) => {
console.log(err);
});



let websocketEndpoint = "ws://127.0.0.1:8080";

editor.syncThroughWebsocket(websocketEndpoint, "examples", "test-doc");

let socket = new ReconnectingWebSocket(websocketEndpoint);

let connection = new ShareDB.Connection(socket);

let doc = connection.get("examples", "test-doc");

// Create a hidden quill editor to parse delta to html


let editorContainer = document.createElement('div');
editorContainer.style.display = 'none';

let quill = new Quill(editorContainer);

doc.fetch((err) => {
if(err) {
console.log(err);
return;
}

let delta = doc.data;
quill.setContents(delta);

document.querySelector(".content").innerHTML = quill.root.innerHTML;

doc.destroy();
socket.close();

editor.on(EditorEvents.editorTextChanged, (delta) => {
let del = delta.oldDelta.compose(delta.delta)
quill.setContents(del);
document.querySelector(".content").innerHTML = quill.root.innerHTML;
})
});