basecamp / basecamp/trix

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

Open
#1,044 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
20k
Forks
1.1k
Avg merge
3d 12h
Merged PRs (30d)
13

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the editor instance and the failing `el.editor.insertAttachment({ content: html })` call described in the issue. Review how `Trix.Attachment` is exposed and determine whether an existing editor can create content attachments without importing and reinitializing Trix. Done means the supported programmatic path is documented or implemented and the reported initialization and `getType` errors are addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.