mirror of
https://github.com/outline/outline.git
synced 2026-06-25 09:14:23 +03:00
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
// @flow
|
|
import {
|
|
ySyncPlugin,
|
|
yCursorPlugin,
|
|
yUndoPlugin,
|
|
undo,
|
|
redo,
|
|
} from "@tommoor/y-prosemirror";
|
|
import { keymap } from "prosemirror-keymap";
|
|
import { Extension } from "rich-markdown-editor";
|
|
// import { IndexeddbPersistence } from "y-indexeddb";
|
|
import * as Y from "yjs";
|
|
|
|
export default class MultiplayerExtension extends Extension {
|
|
get name() {
|
|
return "multiplayer";
|
|
}
|
|
|
|
get plugins() {
|
|
const { user, provider, doc } = this.options;
|
|
const type = doc.get("prosemirror", Y.XmlFragment);
|
|
|
|
provider.on("status", ({ status }) => {
|
|
if (status === "connected") {
|
|
provider.awareness.setLocalStateField("user", {
|
|
color: user.color,
|
|
name: user.name,
|
|
});
|
|
}
|
|
});
|
|
|
|
// const dbProvider = new IndexeddbPersistence(doc.documentId, doc);
|
|
// dbProvider.whenSynced.then(() => {
|
|
// console.log("loaded data from indexed db");
|
|
// });
|
|
|
|
const permanentUserData = new Y.PermanentUserData(doc);
|
|
permanentUserData.setUserMapping(doc, doc.clientID, user.id);
|
|
|
|
return [
|
|
ySyncPlugin(type),
|
|
yCursorPlugin(provider.awareness),
|
|
yUndoPlugin(),
|
|
keymap({
|
|
"Mod-z": undo,
|
|
"Mod-y": redo,
|
|
"Mod-Shift-z": redo,
|
|
}),
|
|
];
|
|
}
|
|
}
|