yjs / y-prosemirror

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

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

Closed RubaXa closed 11 months ago

RubaXa commented 11 months 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 11 months 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 11 months 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 11 months ago

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

RubaXa commented 11 months ago

Thanks a million lot 🔥

eldh commented 8 months ago

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