Sign in

Get started with a SuperDoc DOCX editor using Liveblocks and Vue.js

Liveblocks is a realtime collaboration infrastructure for building performant collaborative experiences. Follow the following steps to start adding collaboration to your Vue.js application using the APIs from the @liveblocks/yjs package, and SuperDoc, a collaborative DOCX editor for the web.

Quickstart

  1. Install Liveblocks, Yjs, and SuperDoc

    Every Liveblocks package should use the same version.

    Terminal
    npm install @liveblocks/client @liveblocks/yjs yjs superdoc
  2. Initialize the liveblocks.config.ts file

    We can use this file later to define types for our application.

    Terminal
    npx create-liveblocks-app@latest --init --framework javascript
  3. Set up your collaborative SuperDoc editor

    SuperDoc relies on browser APIs, so we wait for the provider’s first sync before mounting the editor, and pass the shared ydoc and provider to SuperDoc through modules.collaboration.

    Editor.vue
    <script setup>import { onMounted, onUnmounted } from "vue";import { createClient } from "@liveblocks/client";import { getYjsProviderForRoom } from "@liveblocks/yjs";import { SuperDoc } from "superdoc";import "superdoc/style.css";
    // Set up Liveblocks clientconst client = createClient({ publicApiKey: "",});
    // Enter a multiplayer roomconst { room, leave } = client.enterRoom("my-room");
    // Set up Yjs document and Liveblocks Yjs providerconst yProvider = getYjsProviderForRoom(room);const yDoc = yProvider.getYDoc();
    let superdoc = null;
    function initSuperDoc() { superdoc = new SuperDoc({ selector: "#superdoc", toolbar: "#superdoc-toolbar", documentMode: "editing", user: { name: "User " + Math.floor(Math.random() * 1000), email: "user@example.com", }, modules: { // The collaboration contract is the same for every Yjs provider: // pass the shared `ydoc` and `provider` collaboration: { ydoc: yDoc, provider: yProvider }, }, });}
    onMounted(() => { // Wait for the initial sync so the document isn’t created twice if (yProvider.synced) { initSuperDoc(); } else { yProvider.on("sync", initSuperDoc); }});
    onUnmounted(() => { superdoc?.destroy?.(); leave();});</script>
    <template> <div id="superdoc-toolbar" /> <div id="superdoc" style="height: 700px" /></template>
  4. Next: set up authentication

    By default, Liveblocks is configured to work without an authentication endpoint where everyone automatically has access to rooms. This approach is great for prototyping and marketing pages where setting up your own security isn’t always required. If you want to limit access to a room for certain users, you’ll need to set up an authentication endpoint to enable permissions.

    Set up authentication

What to read next

Congratulations! You now have set up the foundation for your collaborative SuperDoc DOCX editor inside your Vue.js application.