From 5e9cecc663e52c8e41a48922f9693d4e7544f01c Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Thu, 3 Oct 2024 18:43:45 -0400 Subject: [PATCH] Re-submit disabled and validations with backwards compatible support --- .github/workflows/ci.yml | 5 + README.md | 12 +- karma.conf.js | 10 +- src/test/system/custom_element_test.js | 47 ++++- .../fixtures/editor_with_labels.js | 8 +- .../fixtures/editors_with_forms.js | 5 +- .../fixtures/form_associated_false.js | 1 + src/trix/config/editor.js | 3 + src/trix/config/index.js | 1 + src/trix/controllers/editor_controller.js | 2 +- src/trix/elements/trix_editor_element.js | 176 +++++++++++++----- 11 files changed, 208 insertions(+), 62 deletions(-) create mode 100644 src/test/test_helpers/fixtures/form_associated_false.js create mode 100644 src/trix/config/editor.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ab86c134..0bd200767 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,11 @@ on: jobs: build: name: Browser tests + strategy: + matrix: + formAssociated: [true, false] + env: + FORM_ASSOCIATED: "${{ matrix.formAssociated }}" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index e99bb7418..e6f404922 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This is the approach that all modern, production ready, WYSIWYG editors now take
Trix supports all evergreen, self-updating desktop and mobile browsers.
-Trix is built with established web standards, notably [Custom Elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements), [Mutation Observer](https://dom.spec.whatwg.org/#mutation-observers), and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). +Trix is built with established web standards, notably [Custom Elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements), [Element Internals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals), [Mutation Observer](https://dom.spec.whatwg.org/#mutation-observers), and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). # Getting Started @@ -88,6 +88,16 @@ If the attribute is defined in `Trix.config.blockAttributes`, Trix will apply th Clicking the quote button toggles whether the block should be rendered with `
`. +## Integrating with Element Internals + +Trix will integrate `` elements with forms depending on the browser's support for [Element Internals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals). By default, Trix will enable support for `ElementInternals` when the feature is enabled in the browser. If there is a need to disable support for `ElementInternals`, set `Trix.config.editor.formAssociated = false`: + +```js +import Trix from "trix" + +Trix.config.editor.formAssociated = false +``` + ## Invoking Internal Trix Actions Internal actions are defined in `controllers/editor_controller.js` and consist of: diff --git a/karma.conf.js b/karma.conf.js index 9fe317624..fc5c6ad82 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -3,7 +3,7 @@ const config = { frameworks: [ "qunit" ], files: [ { pattern: "dist/test.js", watched: false }, - { pattern: "src/test_helpers/fixtures/*.png", watched: false, included: false, served: true } + { pattern: "src/test/test_helpers/fixtures/*.png", watched: false, included: false, served: true } ], proxies: { "/test_helpers/fixtures/": "/base/src/test_helpers/fixtures/" @@ -29,6 +29,14 @@ const config = { /* eslint camelcase: "off", */ +if (process.env.FORM_ASSOCIATED === "false") { + config.files.push({ + pattern: "src/test/test_helpers/fixtures/form_associated_false.js", + watched: false, + included: true + }) +} + if (process.env.SAUCE_ACCESS_KEY) { config.customLaunchers = { sl_chrome_latest: { diff --git a/src/test/system/custom_element_test.js b/src/test/system/custom_element_test.js index a110aff4a..24764dccf 100644 --- a/src/test/system/custom_element_test.js +++ b/src/test/system/custom_element_test.js @@ -1,3 +1,4 @@ +import * as config from "trix/config" import { rangesAreEqual } from "trix/core/helpers" import { @@ -19,6 +20,14 @@ import { } from "test/test_helper" import { delay, nextFrame } from "../test_helpers/timing_helpers" +const testIfFormAssociated = (name, callback) => { + test(name, async () => { + if (config.editor.formAssociated) { + await callback() + } + }) +} + testGroup("Custom element API", { template: "editor_empty" }, () => { test("element triggers trix-initialize on first connect", async () => { const container = document.getElementById("trix-container") @@ -500,7 +509,7 @@ testGroup("Custom element API", { template: "editor_empty" }, () => { testGroup("