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

feat: realtime collaborative editing #319

Merged
merged 25 commits into from
Jun 29, 2020
Merged

feat: realtime collaborative editing #319

merged 25 commits into from
Jun 29, 2020

Conversation

benjie
Copy link
Member

@benjie benjie commented Jun 25, 2020

Description

This PR replaces #238; adding yjs support for the new Remirror. This can be demonstrated with the following code in the playground (advanced mode):

import React, { FC } from "react";
import { YjsExtension } from "remirror/extension/yjs";
import { RemirrorProvider, useManager, useRemirror } from "remirror/react";

const EXTENSIONS = [new YjsExtension()];

/**
 * This component contains the editor and any toolbars/chrome it requires.
 */
const SmallEditor: FC = () => {
  const { getRootProps } = useRemirror();

  return (
    <div>
      <div {...getRootProps()} />
    </div>
  );
};

const SmallEditorWrapper = () => {
  const extensionManager = useManager(EXTENSIONS);

  return (
    <RemirrorProvider
      manager={extensionManager}
    >
      <SmallEditor />
    </RemirrorProvider>
  );
};

export default SmallEditorWrapper;

As recommended by @dmonad in #238 we've switched over to y-webrtc so that the editing Just Works ™️ rather than requiring an external server.

Checklist

  • I have read the contributing document.
  • My code follows the code style of this project and pnpm run fix completed successfully.
  • I have updated the documentation where necessary.
  • New code is unit tested and all current tests pass when running pnpm run test .

Screenshots

Peek 2020-06-25 15-14

Future tasks

  • Make work as controlled component
  • Allow configuring the provider (e.g. to use different channels)
  • In playground, allow setting the channel as part of the URL/config so can copy URL and send to a collaborator.

benjie added 12 commits June 25, 2020 11:05
We did this by:

1. Copying `support/templates/extension-template` to `extension-yjs`
2. Renaming `template`, `Template` and `TEMPLATE` in the new package to
   `yjs`, `Yjs` and `YJS`
3. Renaming the files from `template-` to `yjs-`
4. Adding `packages/remirror/extension/yjs/package.json`
5. Adding `packages/remirror/src/extension/yjs.ts`
6. Edit `packages/remirror/package.json` to add dependency and
   entrypoint
7. Run `pnpm i` in root
@changeset-bot
Copy link

changeset-bot bot commented Jun 25, 2020

💥 No Changeset

Latest commit: a883ece

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@benjie benjie marked this pull request as draft June 25, 2020 14:14
@github-actions
Copy link
Contributor

github-actions bot commented Jun 25, 2020

@benjie
Copy link
Member Author

benjie commented Jun 25, 2020

We have it working with other extensions too!!

Peek 2020-06-25 17-05

@benjie benjie mentioned this pull request Jun 25, 2020
4 tasks
@ifiokjr ifiokjr self-requested a review June 26, 2020 01:41
function forceTermination() {
const timeout = global.setTimeout(() => {
console.log(
"Look, I'm just a script, and far be it for me to tell you your job, dear human, but it seems to me that something has been keeping me alive for the last 5,000,000 nanoseconds (which feels like an eternity to me) since I completed my task. Maybe something opened a network connection? Who knows. Either way, it doesn't seem right, so I'm going to go ahead and exit.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

import { css } from 'linaria';

/**
* yjs typings are very rough; so we define here the interface that we require
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed in y-webrtc@10.1.5 - I forgot to publish the tsc files.

It might be a good idea to remove the Observable import from lib0. Just because of this import, this extension won't run in node<12 because lib0 is an esm module. The modules in the Yjs repo are not affected because their bundle points to lib0/dist/[module].cjs which is a commonjs module.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.. let me know if it is not fixed 😉 Trying to keep the typescript definitions up to date.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome; Ifi was planning to contribute back some improved typings, but good to know they’re available soon! We need a “provider” type that all providers implement (webrtc, websockets), is there such a thing, @dmonad?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. No there is not at the moment, but I'll add one in the next release yjs/yjs#215

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🙌

@ifiokjr ifiokjr merged commit a883ece into next Jun 29, 2020
@ifiokjr ifiokjr deleted the next-yjs branch June 29, 2020 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants