Skip to content
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

[Bug]: Collaborationcursor does not use the user info #6098

Open
1 task done
TBenTiCon opened this issue Feb 12, 2025 · 1 comment
Open
1 task done

[Bug]: Collaborationcursor does not use the user info #6098

TBenTiCon opened this issue Feb 12, 2025 · 1 comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@TBenTiCon
Copy link

Affected Packages

extension-collaboration-cursor

Version(s)

2.9.1

Bug Description

When setting up the editor with the collaboration cursor plugin, and setting a user object {name, color}, this information is ignored and instead the default values are used.

//define user object
let user = {
	name: properties.user.name,
	color: getRandomHexForUser()
};

//@ts-ignore
let editor = createEditor({
	onTransaction({ transaction }) {
		//@ts-ignore
		handleTransactions(transaction);
	},
	onSelectionUpdate({ editor }) {
		if (onSelectionUpdate) onSelectionUpdate(editor.state.selection);
	},
	extensions: [
		...defaultExtensions,
		Collaboration.configure({
			document: yDoc
		}),
		CollaborationCursor.configure({
			provider: yProvider,
			user,
			render: ({ name, color }) => {
				console.log(name, color);
				const cursor = document.createElement('span');
				cursor.classList.add('collaboration-cursor__caret');
				cursor.setAttribute('style', `border-color: ${color}`);
				const label = document.createElement('div');
				label.classList.add('collaboration-cursor__label');
				label.setAttribute('style', `background-color: ${color}`);
				label.insertBefore(document.createTextNode(name), null);
				cursor.insertBefore(label, null);
				return cursor;
			}
		}),
		TableOfContents.configure({
			getIndex: getHierarchicalIndexes,
			onUpdate(content) {
				if (onTocUpdate) onTocUpdate(content);
			}
		})
	],
	content: 'Hello World!',
	autofocus: true,
	injectCSS: false,
	editorProps: properties
});

Browser Used

Chrome

Code Example URL

No response

Expected Behavior

The set information for name and color are prased into the "render" function correctly.

Additional Context (Optional)

No response

Dependency Updates

  • Yes, I've updated all my dependencies.
@TBenTiCon TBenTiCon added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Feb 12, 2025
@TBenTiCon
Copy link
Author

It works, when setting it after initialization. But then, it wont update until a new selection is made:

yProvider.on('sync', (isSynced: boolean) => {
	if (isSynced === true) {
		isLoading = false;

		const instance = get(editor);
		if (!instance) return;

		instance.commands.updateUser({
			name: 'bubbleMenu',
			color: '#f2f2f2'
		});
	}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

1 participant