Commit Graph

3128 Commits

Author SHA1 Message Date
Mike Dalessio 5c8b688fa3 v2.1.16 v2.1.16 2025-12-30 14:37:23 -05:00
Mike Dalessio 73c20cf03a Fix XSS vulnerability in attachment href rendering
Validate attachment href attributes using DOMPurify.isValidAttribute()
before rendering them as anchor tags.

ref: https://hackerone.com/reports/3455133
2025-12-30 14:36:53 -05:00
Mike Dalessio 07a5e47f67 Make "yarn version" commit changes to the ruby gem, too 2025-12-30 14:36:53 -05:00
Mike Dalessio 17715149d5 Merge pull request #1271 from basecamp/flavorjones/ci-sauce-labs
ci: stabilize Sauce Labs with SC5 tunnel
2025-12-19 15:52:16 -05:00
Mike Dalessio 04f803ed4b ci: stabilize Sauce Labs with SC5 tunnel 2025-12-19 15:47:33 -05:00
Mike Dalessio 93f5270c39 Merge pull request #1270 from basecamp/flavorjones/fix-minitest-errors
action_text-trix: pin minitest to < 6
2025-12-19 13:27:03 -05:00
Mike Dalessio 31045c96af action_text-trix: pin minitest to < 6 2025-12-19 13:10:12 -05:00
Mike Dalessio 13eebdad4a yarn build 2025-12-19 10:20:26 -05:00
Mike Dalessio 696643d7c2 Merge pull request #1269 from basecamp/flavorjones/revert-mousedown-click-change
Revert "Toolbar Button: Handle `click` instead of `mousedown`"
2025-12-19 10:18:43 -05:00
Mike Dalessio 42f69dd4c2 Revert "Toolbar Button: Handle click instead of mousedown"
This reverts commit 1f5ee5e8da.

See notes at
https://github.com/basecamp/trix/pull/1201#issuecomment-3658082539 for
more context.
2025-12-15 18:53:10 -05:00
Mike Dalessio 64afb411c9 Merge pull request #1265 from basecamp/rails-8-1-ci-matrix
Add `8-1-stable` branch to CI matrix
2025-12-15 18:39:24 -05:00
Sean Doyle 6f4c3efe09 Add 8-1-stable branch to CI matrix
[Rails 8.1. has been released][], so update the
`.github/workflows/ci.yml` to include entries for the new release.

[rails@8.1]: https://rubyonrails.org/2025/10/22/rails-8-1
2025-12-11 13:41:37 -05:00
Jorge Manrubia 1aa6c54a6a Merge pull request #1263 from seanpdoyle/fix-action_text-trix-assets
Fix stale `app/assets/javascripts/trix.js` file
2025-11-03 06:11:03 +01:00
Sean Doyle 835d7d58b9 Fix stale app/assets/javascripts/trix.js file
The changes proposed to
`action_text-trix/app/assets/javascripts/trix.js` were generated by
executing the following:

```sh
yarn build
```

To reduce the risk of future commits' outputs being excluded from the
commits that introduce them, this commit introduces some `git` commands
to the `.github/workflows/ci.yml` file to fail CI builds when `yarn
build` creates changes that are not already checked into the git commit.
The commands are lifted directly from the [hotwired/turbo-rails][]
version of this file.

[hotwired/turbo-rails]: https://github.com/hotwired/turbo-rails/blob/v2.0.20/.github/workflows/ci.yml#L48-L51
2025-11-01 19:59:10 -04:00
Mike Dalessio 3a09fb9e7f Merge pull request #1262 from basecamp/flavorjones/fix-ci
ci: fix apt-install errors
2025-10-14 14:25:04 -04:00
Mike Dalessio 43849b6d71 ci: Make sure continue-on-error is always valid 2025-10-14 14:21:07 -04:00
Mike Dalessio 00fe52e01b ci: Try to fix the apt-install errors 2025-10-14 14:13:27 -04:00
Mike Dalessio e7fe45eb46 Merge pull request #1258 from seanpdoyle/rails-engine-test-coverage
`action_text-trix`: Add test coverage for Engine
2025-10-14 14:11:13 -04:00
Sean Doyle 4293d34b88 action_text-trix: Add test coverage for Engine
== What?

This commit introduces an `action_text-trix/test/dummy` directory
generated from `rails plugin new`. It serves as a Dummy Rails
application to consume the `action_text-trix` gem in its test suite.

== Why?

Prior to this commit, compliance with downstream gems like `rails/rails`
involved cloning `rails/rails` and execute *its* test suite. This
provides a tremendous amount of value to ensure that changes in this
repository don't have unintended downstream effects.

However, the gem itself does not have any gem-local test coverage. This
can be fairly limiting, since `rails/rails` is more likely to change at
a much slower pace than the gem.

Similarly, there are long-term goals to extract Trix's Action Text
compatibility out of `rails/rails` completely. With a test suite of its
own, the gem can start to roll those changes out in a
backwards-compatible way.

== How?

In addition to the `test/dummy` directory, this commit introduces
rudimentary browser-level coverage in a
`test/system/action_text_test.rb` file. It drives an Action
Text-compatible Trix instance to create rich text content for a
`Message` model.

In the future, this suite will serve as a testbed for new features, and
potentially will serve as the testing grounds for backwards
compatibility as Action Text becomes more editor-agnostic.
2025-10-10 23:16:04 +02:00
Jorge Manrubia 50bac545fe Merge pull request #1210 from seanpdoyle/issue-1154
Customize Attachment Preview URL
2025-10-08 13:46:08 +02:00
Jorge Manrubia 092910bf5d Merge pull request #1198 from seanpdoyle/attachment-preview-alt
Support setting `img[alt]` on `ManagedAttachment`
2025-10-08 13:44:47 +02:00
Jorge Manrubia 512929f1fe Merge pull request #1127 from seanpdoyle/trix-toolbar-editorElement-property
Define `TrixToolbarElement.editorElements` property
2025-10-08 13:42:20 +02:00
Jorge Manrubia 8ef987e465 Merge pull request #1201 from seanpdoyle/toolbar-button-click
Toolbar Button: Handle `click` instead of `mousedown`
2025-10-08 13:41:09 +02:00
Jorge Manrubia 9977bdb817 Merge pull request #1260 from basecamp/document-trix-attachment-edit
Document `trix-attachment-edit` in `README.md`
2025-10-08 13:35:29 +02:00
Sean Doyle 86ab7d0a8f Document trix-attachment-edit in README.md
Like the `trix-attachment-add` and `trix-attachment-remove`, editors
will also dispatch a [trix-attachment-edit][] when editing a
`Trix.Attachment` instance embedded within the document.

[trix-attachment-edit]: https://github.com/basecamp/trix/blob/v2.1.15/src/trix/controllers/editor_controller.js#L156
2025-10-03 13:36:32 -04:00
Mike Dalessio b307451a79 Merge pull request #1162 from MatheusRich/patch-1
Document the `trix-before-paste` event
2025-09-27 11:49:49 -04:00
Sean Doyle b5d39c290c Merge branch 'main' into patch-1 2025-09-26 12:55:06 -04:00
Sean Doyle 088e4f8164 Support setting img[alt] on ManagedAttachment
Extend the `PreviewableAttachmentView` to assign
[HTMLImageElement.alt][] based on the `Attachment` instance's `"alt"`
attribute.

This enables applications to set the [preview image's alt text][4.8.4.4]
while editing inside the `<trix-editor>` element. For example, an
application can modify a `ManagedAttachment` instance through a
`trix-attachment-add` event listener:

```js
addEventListener("trix-attachment-add", ({ attachment }) => {
  attachment.setAttributes({ alt: `Attached file ${attachment.file.name}` })
})
```

[HTMLImageElement.alt]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt
[4.8.4.4]: https://html.spec.whatwg.org/multipage/images.html#alt
2025-09-26 12:54:01 -04:00
Sean Doyle 1f5ee5e8da Toolbar Button: Handle click instead of mousedown
Revert [c4b9d5b][]

Requiring mouse events to trigger `<button>` element event listeners
poses accessibility issues for keyboard users.

The context in the original commit ([c4b9d5b][]) is fairly light, and
there doesn't appear to be a link to a GitHub pull request with more
information. The provided context is:

> Prevents flickering of the placeholder text when clicking block
> formatting buttons on an empty document.

Since the commit is from 2014, there is hope that the underlying flicker
might have been resolved through the natural course of browser
improvements and device enhancements.

The benefit of responding to keyboard events when the `<button>` element
has focus outweighs the potential downsides.

[c4b9d5b]: https://github.com/basecamp/trix/commit/c4b9d5b5f18bc41b6cedcc0ffbadf33db2ab240e
2025-09-26 12:53:47 -04:00
Sean Doyle 2decc52042 Customize Attachment Preview URL
Related to [#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`).

[#1154]: https://github.com/basecamp/trix/issues/1154
[setAttribute]: https://github.com/basecamp/trix/blob/5db0ea49180de97f27b0becf47440690a1eaa39c/src/trix/models/managed_attachment.js#L22
2025-09-26 12:53:35 -04:00
Sean Doyle 552aef65f8 Define TrixToolbarElement.editorElements property
Define properties for accessing all `<trix-editor>` elements that
declare a relationship with a `<trix-toolbar>` element through a
`[toolbar]`-`[id]` attribute relationship.

Since multiple `<trix-editor>` elements can reference a `<trix-toolbar>`
element by name, this commit introduces both an `.editorElements` and
`.editorElement` properties.

The `.editorElement` property returns the first item in
`.editorElements`, if there are any.
2025-09-26 12:53:14 -04:00
Jorge Manrubia fee2e50f19 Merge pull request #1253 from basecamp/editor-preload-content
Read initial editor value from HTML content
2025-09-26 18:24:06 +02:00
Mike Dalessio 50a07243b7 Merge pull request #1256 from basecamp/action_text-trix
Build `action_text-trix` assets with existing tools
2025-09-26 12:00:36 -04:00
Sean Doyle 0403d53fdd Build action_text-trix assets with existing tools
Removes the JavaScript and CSS file `FileUtils.cp` calls from
`action_text-trix/Rakefile` so that the files can be generated by the
existing tooling (`rollup.config.js` for JavaScript, `bin/sass-build`
for CSS).

With this change, the project is free to continue to utilize those tools
to manage the files that will be included in the Gem, without needing to
span the Ruby-NodeJS boundary.
2025-09-26 11:50:14 -04:00
Sean Doyle c02eb604a9 Read initial editor value from HTML content
Prior to this commit, Trix editors used an associated input element to
initially populate their content.

This commit proposes to extend the behavior so that when an associated
input element is absent, Trix will safely sanitize then load any HTML
content inside a `<trix-editor>…</trix-editor>` tag.

```html
<form …>
  <trix-editor>Editor content goes here</trix-editor>
/form>
```

When a `<trix-editor>` element initially connects with both HTML content
*and* an associated input element, Trix will *always* disregard the HTML
content and +> load its initial content from the associated input
element.

Additional considerations
---

This should not break Action Text compatibility, since Rails renders
`<trix-editor>` elements through the [rich_textarea_tag][], which
renders initial content into an `<input type="hidden">`. This change
enables the migration toward rendering content directly *into* the
`<trix-editor>` element as HTML content.

[rich_textarea_tag]: https://edgeapi.rubyonrails.org/classes/ActionText/TagHelper.html#method-i-rich_textarea_tag
2025-09-26 11:49:51 -04:00
Mike Dalessio e3d72b393f Merge pull request #1257 from seanpdoyle/package-json-node-version
Update `.node-version` and `engine` property in `package.json`
2025-09-26 11:48:46 -04:00
Mike Dalessio f39ca75f66 Merge pull request #1255 from seanpdoyle/fix-ci
Pass CI
2025-09-26 11:45:58 -04:00
Sean Doyle cc598f869b Update .node-version and engine property in package.json
When changes are made to the `package.json` file, the CI cache is busted
and the file is re-evaluated by the containers. This causes
[CI failures][] like the following:

```
No VM guests are running outdated hypervisor (qemu) binaries on this host.
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
error @eslint/js@9.24.0: The engine "node" is incompatible with this module. Expected version "^18.18.0 || ^20.9.0 || >=21.1.0". Got "16.20.2"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
```

To resolve this issue, change the `.node-version` file to specify
`18.18.0` (the minimum version mentioned explicitly by the failure
output). There are more recent releases available, but this PR only aims
to resolve the current issues.

[CI failure]: https://github.com/basecamp/trix/actions/runs/18040917809/job/51339260902?pr=1256#step:8:184
2025-09-26 11:20:04 -04:00
Sean Doyle 6d3f1c5e6c Pass CI
CI is currently [failing on `main`][ci]. The failure was introduced in
[#1128][], despite the fact that [CI passed for that PR][pr].

To resolve the error (related to `[disabled]` and focus), this commit
changes the `makeEditable(editorElement)` function so that it
incorporates a check to the `TrixEditorElement.disabled` property into a
call to [toggleAttribute][].

Similarly, it moves the creation of the associated
`TrixEditorElement.inputElement` (that is missing at the time of the
check) into the `connectedCallback()` so that the `.disabled` property
access does not result in the pre-mature creation of the associated
`<input>` element prior to the rest of the `connectedCallback()` logic.

[ci]: https://github.com/basecamp/trix/actions/runs/17895948161/job/50883035420
[#1128]: https://github.com/basecamp/trix/pull/1128
[pr]: https://github.com/basecamp/trix/pull/1128/checks
[toggleAttribute]: https://developer.mozilla.org/en-US/docs/Web/API/Element/toggleAttribute
2025-09-21 23:05:25 -04:00
Jorge Manrubia 62b1483527 Merge pull request #1128 from seanpdoyle/element-internals
Replace hidden `<input>` with `ElementInternals` integration
2025-09-21 18:09:25 +02:00
Jorge Manrubia fc15ab2c82 Merge pull request #1252 from seanpdoyle/editor-render
Dispatch `trix-before-render` event
2025-09-21 18:00:05 +02:00
Sean Doyle 69d8d753ab Dispatch trix-before-render event
Prior to this change, Trix's rendering process was managed internally,
and was not open for extension or customization. While it's critical
that Trix manages its own content (through parsing HTML, scrubbing
attributes and sanitizing content, reifying attachments, etc.), the
"rendering" of that content amounts to the replacement of a collection
of DOM nodes.

Advanced use cases (like integration with "morph" style rendering) can
benefit from customizing the process of rendering Trix's content.

This commit introduces a `trix-before-render` event to with a `render`
property to configure an individual `<trix-editor>` element's rendering
process. By default, the event's `render` property maintains the
existing "replace" behavior. When overridden, the function expects two
arguments: a `<trix-editor>` element along with with a
[DocumentFragment][] instance.

```js
document.addEventListener("trix-before-render", (event) => {
  const defaultRender = event.render

  event.render = function(editorElement, documentFragment) {
    // modify the documentFragment…
    customize(documentFragment)

    // render it with the default rendering function
    defaultRender(editorElement, documentFragment)
  }
})
```

[DocumentFragment]: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
2025-09-21 08:39:06 -04:00
Sean Doyle 85d1ed26f0 ElementInternals: Support without <input> element
The successful migration to utilize [Element Internals][] stopped short
of removing Trix's dependency on an associated `<input type="hidden">`
element to store its state. Prior to integration with
`ElementInternals`, Trix relied on the `<input>` for the sake of having
its value serialized into a form submission. That is no longer
necessary.

When Trix is configured to be compatible with `ElementInternals`, it is
also capable of functioning without an `<input type="hidden">` element.
To configure a `<trix-editor>` element to skip creating its `<input
type="hidden">`, set the element's `willCreateInput = false`:

```js
addEventListener("before-trix-initialize", (event) => {
  const trixEditor = event.target

  trixEditor.willCreateInput = false
})
```

Trix will *always* use an associated `<input type="hidden">` element
when the `[input]` attribute is set, regardless of its `willCreateInput`
property. To migrate to `<input>`-free support, render the
`<trix-editor>` without the `[input]` attribute.

In the absence of an `<input type="hidden">` element, the
`<trix-editor>` element's value will not be included in `<form>` element
submissions unless it is rendered with a `[name]` attribute. Set the
`[name]` attribute to the same value that the `<input type="hidden">`
element would have.

Additional considerations
---

Action Text integration should remain unchanged. At the time of this
submission, Rails automatically renders an `<input type="hidden">`
element that is paired with the `<trix-editor>` element through its
`[input]` attribute.

[Element Internals]: https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals
2025-09-20 23:08:57 -04:00
Mike Dalessio 55ef9be329 Merge pull request #1235 from basecamp/flavorjones/rails-integration-tests
ci: integration test with Action Text
2025-05-13 17:44:32 -04:00
Mike Dalessio 5c8ef0a9f4 ci: integration test with Action Text 2025-05-13 17:41:05 -04:00
Mike Dalessio 84ff7f1673 ci: improve the pipeline 2025-05-13 17:40:03 -04:00
Mike Dalessio 69c6664397 Enable "mfa required" for the ruby gem
which will take effect on the next version published.
2025-05-13 08:52:48 -04:00
Mike Dalessio 2204b69fbc Fix the name of the rake task used to release ruby. 2025-05-13 08:40:13 -04:00
Mike Dalessio 213cb1d0ed Merge pull request #1234 from basecamp/flavorjones/package-in-ruby-gem
Create a ruby gem package "action_text-trix"
2025-05-13 08:37:43 -04:00
Mike Dalessio 899415135d Update build and release tasks to include the Ruby gem 2025-05-13 08:26:01 -04:00