Skip to content

Commit

Permalink
Merge pull request #5 from fireJera/master
Browse files Browse the repository at this point in the history
merge display and index
  • Loading branch information
lencyforce authored Nov 9, 2020
2 parents dc493c4 + 3e2516d commit fa2fd0e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
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;
})
});

0 comments on commit fa2fd0e

Please sign in to comment.