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

Can't update editorProps after initialization. #1518

Closed
robertvanhoesel opened this issue Jun 28, 2021 · 3 comments · Fixed by #1540
Closed

Can't update editorProps after initialization. #1518

robertvanhoesel opened this issue Jun 28, 2021 · 3 comments · Fixed by #1540
Labels
sponsor 💖 This issue or pull request was created by a Tiptap sponsor Type: Bug The issue or pullrequest is related to a bug

Comments

@robertvanhoesel
Copy link
Contributor

Description
I haven't found a way to add or modify editorProps after initialization – calling editor.setOptions({ editorProps: { ... } does not work, neither does modifying editor.options.editorProps.* directly.

Steps to reproduce the bug

const transformPastedHTML = (html: string) => {
    window.alert('transformPastedHTML called')
	return html
};

// A. Constructing the editor with editorProps works
const editor = new Editor({
	extensions: [ StarterKit ]
	editorProps: { transformPastedHTML },
});

// B. Constructing the editor and setting editorProps later does not work
const editor = new Editor({
	extensions: [ StarterKit ]
});

// Either of the below options do not have any effect
editor.setOptions({ editorProps: { transformPastedHTML } });
editor.options.editorProps.transformPastedHTML = transformPastedHTML;

CodeSandbox
I created a CodeSandbox to help you debug the issue.

Expected behavior
EditorProps are modified, i.e. in the example my custom transformPastedHTML is being called

Environment?

  • operating system: Mac OS X
  • browser: Chrome
  • mobile/desktop: Both
  • tiptap version: 2.0.0-beta.85

Additional context
I've tried several, but not all, other editorProps to validate is present on more than one prop.

@robertvanhoesel robertvanhoesel added Type: Bug The issue or pullrequest is related to a bug v2 labels Jun 28, 2021
@github-actions github-actions bot added the sponsor 💖 This issue or pull request was created by a Tiptap sponsor label Jun 28, 2021
@tanishqkancharla
Copy link

I agree, this is a pretty big problem. This is setOptions:

public setOptions(options: Partial<EditorOptions> = {}): void {
    this.options = { ...this.options, ...options }
}

I'm not sure what the problem is, this should work? Unless this.options is set to be a const...?

@robertvanhoesel
Copy link
Contributor Author

The problem is that options.editorProps is not an actual reference to ProseMirror view.props. On creation the editorProps are destructured onto the ProseMirror view, and in setOptions it just updates the TipTap Editor' options, not actually setting the props on proseMirror.

private createView(): void {
this.view = new EditorView(this.options.element, {
...this.options.editorProps,
dispatchTransaction: this.dispatchTransaction.bind(this),
state: EditorState.create({
doc: createDocument(this.options.content, this.schema, this.options.parseOptions),
}),
})

I've created a fix and creating a PR (waiting for all tests to run...)

@tanishqkancharla
Copy link

Beautiful! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sponsor 💖 This issue or pull request was created by a Tiptap sponsor Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants