Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ export { YRange, yRemoteSelections, yRemoteSelectionsTheme, ySync, ySyncFacet, Y
* @param {any} awareness
* @param {Object} [opts]
* @param {Y.UndoManager | false} [opts.undoManager] Set undoManager to false to disable the undo-redo plugin
* @param {((u: any) => { name: String, colorLight: String, color: String }) | false} [opts.getUserInfo] Optional fn to take user awareness state info and transform into name + color(s)
* @return {cmState.Extension}
*/
export const yCollab = (ytext, awareness, { undoManager = new Y.UndoManager(ytext) } = {}) => {
const ySyncConfig = new YSyncConfig(ytext, awareness)
export const yCollab = (ytext, awareness, { undoManager = new Y.UndoManager(ytext), getUserInfo = false } = {}) => {
const ySyncConfig = new YSyncConfig(ytext, awareness, getUserInfo)
const plugins = [
ySyncFacet.of(ySyncConfig),
ySync
]

if (awareness) {
plugins.push(
yRemoteSelectionsTheme,
Expand Down
7 changes: 5 additions & 2 deletions src/y-remote-selections.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ export class YRemoteSelectionsPluginValue {
if (anchor == null || head == null || anchor.type !== ytext || head.type !== ytext) {
return
}
const { color = '#30bced', name = 'Anonymous' } = state.user || {}
const colorLight = (state.user && state.user.colorLight) || color + '33'

const userColorAndName = this.conf.getUserInfo ? this.conf.getUserInfo(state.user) : state.user
const color = userColorAndName?.color || '#30bced'
const name = userColorAndName?.name || 'Anonymous'
const colorLight = userColorAndName.colorLight || color + '33'
const start = math.min(anchor.index, head.index)
const end = math.max(anchor.index, head.index)
const startLine = update.view.state.doc.lineAt(start)
Expand Down
3 changes: 2 additions & 1 deletion src/y-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import * as cmView from '@codemirror/view' // eslint-disable-line
import { YRange } from './y-range.js'

export class YSyncConfig {
constructor (ytext, awareness) {
constructor (ytext, awareness, getUserInfo) {
this.ytext = ytext
this.awareness = awareness
this.undoManager = new Y.UndoManager(ytext)
this.getUserInfo = getUserInfo
}

/**
Expand Down