-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Support adding custom class names #16
base: master
Are you sure you want to change the base?
Conversation
In yjs#15 introduced the ability was introduced to generate class names based based on a client ID. This is useful, but I prefer to use predefined classes instead of generating stylesheets at runtime.
This is based on yjs#16.
We already have the |
The Also we use TailwindCSS. In order to use that at all we need to use predefined classes. In the mean time I figured out I need to color the cursors based on the user who has connected. I think this means my solution proposed here isn’t even flexible enough. I suggest to make the class name I proposed earlier a function that gets called with the both the selection and the client ID. const classNames = [
'border-orange-400',
'border-green-400',
'border-sky-400',
'border-violet-400',
'border-rose-400',
'border-amber-400',
'border-lime-400',
'border-fuchsia-400'
]
function getClassName(clientId, state) {
return classNames[state.userId % classNames.length]
}
const awareness = new Awareness(ydoc)
awareness.setLocalStateField('userId', userId)
const binding = new MonacoBinding(ytext, model, new Set([editor]), awareness, getClassName) |
export class MonacoBinding { | ||
/** | ||
* @param {Y.Text} ytext | ||
* @param {monaco.editor.ITextModel} monacoModel | ||
* @param {Set<monaco.editor.IStandaloneCodeEditor>} [editors] | ||
* @param {Awareness?} [awareness] | ||
* @param {ClassNameGetter?} [getClassName] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This results in a parameter type of getClassName: ClassNameGetter | null | undefined
, so we get "Object is possibly null" errors when it is invoked.
Dropping the ?
produces the correct parameter type getClassName: ClassNameGetter | undefined
.
* @param {ClassNameGetter?} [getClassName] | |
* @param {ClassNameGetter} [getClassName] |
In #15 introduced the ability was introduced to generate class names based based on a client ID. This is useful, but I prefer to use predefined classes instead of generating stylesheets at runtime.