Customize Attachment Preview URL#1210
Merged
jorgemanrubia merged 1 commit intobasecamp:mainfrom Oct 8, 2025
Merged
Conversation
30fe30d to
eb299c7
Compare
Related to [basecamp#1154][] First, document the existing Attachment previewing process, including _which_ content types are supported out of the box. Next, resolve some `ManagedAttachment` to `Attachment` proxying issues. The `ManagedAttachment` class is what gets dispatched as part of `trix-attachment-add` events. It does not inherit from `Attachment`, but instead proxies method calls and property access. Prior to this commit, there were some proxy definition gaps. For example, the `ManagedAttachment` [declares a proxy for the `setAttribute` method][setAttribute]. Unfortunately, an `Attachment.setAttribute` method did not exist prior to these changes. This commit remedies that. Next, this commit adds proxy definitions for `Attachment.setPreviewURL` and `Attachment.getPreviewURL` so that event handlers can customize the value from the event-level `ManagedAttachment` instance, without deeply reaching into the `Attachment` instance (via `event.attachment.attachment`). [basecamp#1154]: basecamp#1154 [setAttribute]: https://github.com/basecamp/trix/blob/5db0ea49180de97f27b0becf47440690a1eaa39c/src/trix/models/managed_attachment.js#L22
eb299c7 to
2decc52
Compare
jorgemanrubia
approved these changes
Oct 8, 2025
|
I currently have a stimulus controller like so: Would this PR make that process easier? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #1154
First, document the existing Attachment previewing process, including which content types are supported out of the box.
Next, resolve some
ManagedAttachmenttoAttachmentproxying issues. TheManagedAttachmentclass is what gets dispatched as part oftrix-attachment-addevents. It does not inherit fromAttachment, but instead proxies method calls and property access. Prior to this commit, there were some proxy definition gaps.For example, the
ManagedAttachmentdeclares a proxy for thesetAttributemethod. Unfortunately, anAttachment.setAttributemethod did not exist prior to these changes. This commit remedies that.Next, this commit adds proxy definitions for
Attachment.setPreviewURLandAttachment.getPreviewURLso that event handlers can customize the value from the event-levelManagedAttachmentinstance, without deeply reaching into theAttachmentinstance (viaevent.attachment.attachment).