-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite react package to make it compatible with async react, add utilities for custom cursor rendering on specific nodes, and add cursor decorations
- Loading branch information
Showing
38 changed files
with
986 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@slate-yjs/core': patch | ||
--- | ||
|
||
Loosen `CursorEditor.isCursorEditor` to not check awareness instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
'@slate-yjs/react': minor | ||
--- | ||
|
||
Changed: | ||
|
||
- Rewrite of `useRemoteCursorOverlayPositions` to provide stricter typings, make it react 18 safe and add new `shouldGenerateOverlay` option. | ||
|
||
Added: | ||
|
||
- Remote cursor decorations using the new `useDecorateRemoteCursors` hook | ||
- Remote cursor data hooks `useRemoteCursorStatesSelector` and `useRemoteCursorStates` | ||
- Utility hooks to un-send the current cursor position on window/editor blur: `useUnsetCursorPositionOnBlur` | ||
- `getCursorRange` helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Cursor Decorations | ||
|
||
## useDecorateRemoteCursors | ||
|
||
`useDecorateRemoteCursors` provides a simple way to implement an editor overlay displaying remote cursors using [slate decorations](https://docs.slatejs.org/concepts/09-rendering#decorations). Displaying remote cursors using decorations has a few tradeoffs to keep in mind: | ||
|
||
Pros: | ||
|
||
- They are part of the actual editor content which makes them easier to keep in sync leading to them never visually lagging behind. | ||
- It's easier to customize node rendering/behavior based on remote selection since changes of them cause node re-renders. | ||
|
||
Cons: | ||
|
||
- Since cursors overlays are part of the by slate rendered content, they change the underlying dom structure causing e.g. different line breaks when a remote user changes his selection. | ||
- They potentially mess with autocorrect | ||
- Animating them is harder | ||
- They potentially provide worse performance since they require re-rendering of parts of the editor content on remote cursor change | ||
|
||
<br/> | ||
|
||
**`useDecorateRemoteCursors`** takes an optional options parameter with the following options: | ||
|
||
**`carets`** | ||
|
||
If set to true, useDecorateRemoteCursors will provide explicit decorations for remote carets. Defaults to true. Carets will be decorated | ||
as `` { [`remote-cursor-${id}`]: CursorState<TCursorData> } `` | ||
|
||
<br/> | ||
|
||
and returns a decorate function meant to be passed to `Editable.decorate`. Cursor ranges will be decorated as `` { [`remote-cursor-${id}`]: CursorState<TCursorData> } `` and carets (if not disabled) as `` { [`remote-caret-${id}`]: CursorState<TCursorData> & { isBackward: boolean } } ``. | ||
Both decoration types can be received on a leaf-level using the `getRemoteCursorsOnLeaf` and `getRemoteCaretsOnLeaf` helpers. | ||
|
||
<br/> | ||
|
||
`useDecorateRemoteCursors` should be used inside the context of a [CursorEditor](../slate-yjs-core/cursor-plugin.md): | ||
|
||
## getRemoteCursorsOnLeaf | ||
|
||
Get remote cursor decorations on the given `Leaf`. | ||
|
||
## getRemoteCaretsOnLeaf | ||
|
||
Get remote caret decorations on the given `Leaf`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Cursor selectors | ||
|
||
`@slate-yjs/react` provides various helper hooks to allow for custom rendering of remote selections on/inside editor elements. All these | ||
helper hooks are based upon a per-editor unique store to allow for good performance even when rendering 100s of elements reacting to | ||
remote changes. | ||
|
||
## useRemoteCursorStatesSelector | ||
|
||
Hook to react to all cursor changes inside a component using a selector. | ||
|
||
## useRemoteCursorStates | ||
|
||
Hook to react to all cursor changes inside a component. Returns a `Record<string, CursorState<TCursorData>>` containing all remote cursor states. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Utilities | ||
|
||
## useUnsetCursorPositionOnBlur | ||
|
||
Unset the `selectionStateField` while the editor/window is blurred. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Contributing | ||
|
||
Want to contribute to slate-yjs? That would be awesome! | ||
|
||
- [Reporting Bugs](contributing.md#reporting-bugs) | ||
- [Asking Questions](contributing.md#asking-questions) | ||
- [Submitting Pull Requests](contributing.md#submitting-pull-requests) | ||
- [Repository Setup](contributing.md#repository-setup) | ||
- [Running Examples](contributing.md#running-examples) | ||
- [Running Tests](contributing.md#running-tests) | ||
|
||
## Reporting Bugs | ||
|
||
If you run into any weird behavior while using slate-yjs, feel free to open a new issue in this repository! Please run a **search before opening** a new issue, to make sure that someone else hasn't already reported or solved the bug you've found. | ||
|
||
Any issue you open must include: | ||
|
||
- A [JSFiddle](https://jsfiddle.net/) (or similar) that reproduces the bug with a minimal setup. | ||
- A GIF showing the issue in action. \(Using something like [Loom](https://loom.com).\) | ||
- A clear explanation of what the issue is. | ||
|
||
## Asking Questions | ||
|
||
For questions around yjs, head over to the [Yjs Community](https://discuss.yjs.dev/). Trying to build a backend with [hocuspocus](https://www.hocuspocus.dev/) and have questions? Take a look at the #hocuspocus channel in the [TipTap Discord](https://discord.com/invite/WtJ49jGshW). Having issues with slate? There's a there's a [Slack](https://slate-slack.herokuapp.com/) for that as well. | ||
|
||
Any questions about slate-yjs itself? Thead over to the #slate-yjs channel inside the [Slate Slack](https://slate-slack.herokuapp.com/) or post something in the [Discussions](https://github.com/BitPhinix/slate-yjs/discussions) | ||
|
||
Please use the Slack instead of asking questions in issues, since we want to reserve issues for keeping track of bugs and features. We close questions in issues so that maintaining the project isn't overwhelming. | ||
|
||
## Submitting Pull Requests | ||
|
||
All pull requests are super welcomed and greatly appreciated! Issues in need of a solution are marked with a [`help wanted`](https://github.com/BitPhinix/slate-yjs/labels/help%20wanted) label if you're looking for somewhere to start. | ||
|
||
Please include tests and docs with every pull request! | ||
|
||
## Repository Setup | ||
|
||
The slate-yjs repository is a monorepo that is managed with [yarn workspaces](https://yarnpkg.com/features/workspaces). Unlike more traditional repositories, this means that the repository must be built in order for common development activities to function as expected. | ||
|
||
To run the build, you need to have the slate-yjs repository cloned to your computer. After that, you need to `cd` into the directory where you cloned it, and install the dependencies with `yarn` and build the monorepo: | ||
|
||
```text | ||
yarn install | ||
yarn build | ||
``` | ||
|
||
## Running Examples | ||
|
||
To run the examples, start by building the monorepo as described in the [Repository Setup](contributing.md#repository-setup) section. | ||
|
||
Then you can start the examples server with: | ||
|
||
```text | ||
yarn dev | ||
``` | ||
|
||
## Running Tests | ||
|
||
To run the tests, start by building the monorepo as described in the [Repository Setup](contributing.md#repository-setup) section. | ||
|
||
Then you can rerun the tests with: | ||
|
||
```text | ||
yarn test | ||
``` | ||
|
||
For instructions on how to debug something, head over to the [vitest docs](https://vitest.dev/guide/debugging.html). | ||
|
||
In addition to tests you should also run the linter: | ||
|
||
```text | ||
yarn lint | ||
``` | ||
|
||
This will catch TypeScript, Prettier, and Eslint errors. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.