yjs / y-prosemirror

ProseMirror editor binding for Yjs
https://demos.yjs.dev/prosemirror/prosemirror.html
MIT License
355 stars 124 forks source link

feat: Added `awarenessStateFilter` option for filtering `awareness.getState()` #140

Closed RubaXa closed 1 year ago

RubaXa commented 1 year ago

This option is needed when we want to remove self "cursor" when opened N-tabs or other logic.

For example, in "GoogleDocs", this is exactly the behavior, they display N-1 "cursors" (N — number of tabs), but in the case of "Notion", they do not display their own "cursor".

yCursorPlugin(provider.awareness, {
  awarenessStateFilter: (_, __, user) => user.id !== getAuthUserId(),
})
dmonad commented 1 year ago

Please explain the usecase first. Have you considered other solutions?

Also, this doesn't really prevent unauthorized users from sending awareness states. Instead, you should filter messages from unauthorized users.

RubaXa commented 1 year ago

@dmonad If I open a document in 2-tabs, I will see "cursor" from myself.

For example, in "GoogleDocs", this is exactly the behavior, they display N-1 "cursors" (N — number of tabs), but in the case of "Notion", they do not display their own "cursor".

Therefore, I want to be able to regulate this behavior, for example, through filtering.

dmonad commented 1 year ago

Okay, makes sense. Will get this into the next release.

RubaXa commented 1 year ago

Thanks a million lot 🔥

eldh commented 1 year ago

Any chance we'll see a new release soon? Just found myself needing this…