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

Is it possible to create a new Attachment programmatically from an existing editor instance without importing Trix library again? #1044

Open
JamieWritesCode opened this issue Mar 10, 2023 · 1 comment

Comments

@JamieWritesCode
Copy link

Apologies as this is likely more of a question or suggestion rather than a bug report. I'm trying to add some additional functionality to a Trix editor that is imported and initialized in another module.

Using import Trix from "trix" again results in an initialization error as Trix is already initialized on the page. This makes it difficult to create a new Attachment programmatically as I can't call the constructor that is attached to the Trix module with new Trix.Attachment().

I can however get an instance of the editor from the page after load - is there a function accessible on the editor instance that I can use to create a new Attachment?

Specifically, I'm trying to create an insert a new Content Attachment but just using el.editor.insertAttachment({ content: html}) fails with an error t.getType is not a function - I assume the Attachment model has some additional required functions on its prototype?

Details
  • Trix version: ^1.0.0
  • Browser name and version: Chrome
  • Operating system: Windows
@seanpdoyle
Copy link
Contributor

Are you able to upgrade from ^1.0.0 to one of the ^2.0.0 releases? Depending on your build tool, the project's migration from CoffeeScript to ECMAScript Module support might have addressed the underlying cause responsible for the issue you're experiencing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants