@rails/actiontext 7.0.0-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +13 -0
- package/app/javascript/actiontext/attachment_upload.js +45 -0
- package/app/javascript/actiontext/index.js +10 -0
- package/package.json +39 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
## Rails 7.0.0.alpha1 (September 15, 2021) ##
|
|
2
|
+
|
|
3
|
+
* Make the Action Text + Trix JavaScript and CSS available through the asset pipeline.
|
|
4
|
+
|
|
5
|
+
*DHH*
|
|
6
|
+
|
|
7
|
+
* OpenSSL constants are now used for Digest computations.
|
|
8
|
+
|
|
9
|
+
*Dirkjan Bussink*
|
|
10
|
+
|
|
11
|
+
* Add support for passing `form:` option to `rich_text_area_tag` and
|
|
12
|
+
`rich_text_area` helpers to specify the `<input type="hidden" form="...">`
|
|
13
|
+
value.
|
|
14
|
+
|
|
15
|
+
*Sean Doyle*
|
|
16
|
+
|
|
17
|
+
* Add `config.action_text.attachment_tag_name`, to specify the HTML tag that contains attachments.
|
|
18
|
+
|
|
19
|
+
*Mark VanLandingham*
|
|
20
|
+
|
|
21
|
+
* Expose how we render the HTML _surrounding_ rich text content as an
|
|
22
|
+
extensible `layouts/action_view/contents/_content.html.erb` template to
|
|
23
|
+
encourage user-land customizations, while retaining private API control over how
|
|
24
|
+
the rich text itself is rendered by `action_text/contents/_content.html.erb`
|
|
25
|
+
partial.
|
|
26
|
+
|
|
27
|
+
*Sean Doyle*
|
|
28
|
+
|
|
29
|
+
* Add `with_all_rich_text` method to eager load all rich text associations on a model at once.
|
|
30
|
+
|
|
31
|
+
*Matt Swanson*, *DHH*
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/actiontext/CHANGELOG.md) for previous changes.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Action Text
|
|
2
|
+
|
|
3
|
+
Action Text brings rich text content and editing to Rails. It includes the [Trix editor](https://trix-editor.org) that handles everything from formatting to links to quotes to lists to embedded images and galleries. The rich text content generated by the Trix editor is saved in its own RichText model that's associated with any existing Active Record model in the application. Any embedded images (or other attachments) are automatically stored using Active Storage and associated with the included RichText model.
|
|
4
|
+
|
|
5
|
+
You can read more about Action Text in the [Action Text Overview](https://edgeguides.rubyonrails.org/action_text_overview.html) guide.
|
|
6
|
+
|
|
7
|
+
## Development
|
|
8
|
+
|
|
9
|
+
The JavaScript for Action Text is distributed both as a npm module under @rails/actiontext and via the asset pipeline as actiontext.js (and we mirror Trix as trix.js). To ensure that the latter remains in sync, you must run `yarn build` and checkin the artifacts whenever the JavaScript source or the Trix dependency is bumped. CSS changes must be brought over manually to app/assets/stylesheets/trix.css
|
|
10
|
+
|
|
11
|
+
## License
|
|
12
|
+
|
|
13
|
+
Action Text is released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DirectUpload } from "@rails/activestorage"
|
|
2
|
+
|
|
3
|
+
export class AttachmentUpload {
|
|
4
|
+
constructor(attachment, element) {
|
|
5
|
+
this.attachment = attachment
|
|
6
|
+
this.element = element
|
|
7
|
+
this.directUpload = new DirectUpload(attachment.file, this.directUploadUrl, this)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
start() {
|
|
11
|
+
this.directUpload.create(this.directUploadDidComplete.bind(this))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
directUploadWillStoreFileWithXHR(xhr) {
|
|
15
|
+
xhr.upload.addEventListener("progress", event => {
|
|
16
|
+
const progress = event.loaded / event.total * 100
|
|
17
|
+
this.attachment.setUploadProgress(progress)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
directUploadDidComplete(error, attributes) {
|
|
22
|
+
if (error) {
|
|
23
|
+
throw new Error(`Direct upload failed: ${error}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.attachment.setAttributes({
|
|
27
|
+
sgid: attributes.attachable_sgid,
|
|
28
|
+
url: this.createBlobUrl(attributes.signed_id, attributes.filename)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
createBlobUrl(signedId, filename) {
|
|
33
|
+
return this.blobUrlTemplate
|
|
34
|
+
.replace(":signed_id", signedId)
|
|
35
|
+
.replace(":filename", encodeURIComponent(filename))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get directUploadUrl() {
|
|
39
|
+
return this.element.dataset.directUploadUrl
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get blobUrlTemplate() {
|
|
43
|
+
return this.element.dataset.blobUrlTemplate
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rails/actiontext",
|
|
3
|
+
"version": "7.0.0-alpha1",
|
|
4
|
+
"description": "Edit and display rich text in Rails applications",
|
|
5
|
+
"main": "app/javascript/actiontext/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"app/javascript/actiontext/*.js"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://rubyonrails.org/",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/rails/rails.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/rails/rails/issues"
|
|
17
|
+
},
|
|
18
|
+
"author": "Basecamp, LLC",
|
|
19
|
+
"contributors": [
|
|
20
|
+
"Javan Makhmali <javan@javan.us>",
|
|
21
|
+
"Sam Stephenson <sstephenson@gmail.com>"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@rails/activestorage": "7.0.0-alpha"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"trix": "^1.3.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@rollup/plugin-node-resolve": "^11.0.1",
|
|
32
|
+
"@rollup/plugin-commonjs": "^19.0.1",
|
|
33
|
+
"rollup": "^2.35.1",
|
|
34
|
+
"trix": "^1.3.1"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "rollup --config rollup.config.js"
|
|
38
|
+
}
|
|
39
|
+
}
|