thecore_ui_commons 2.1.6 → 2.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/thecore_ui_commons_manifest.js +0 -2
- data/app/assets/javascripts/thecore_ui_commons/thecore.js +9 -0
- data/app/assets/{config/trix/dist → javascripts}/trix-core.js +0 -0
- data/app/assets/{config/trix/dist → javascripts}/trix.js +0 -0
- data/app/assets/stylesheets/{actiontext.scss → thecore_ui_commons/actiontext.scss} +1 -1
- data/app/assets/stylesheets/{thecore.scss → thecore_ui_commons/thecore.scss} +0 -0
- data/app/assets/{config/trix/dist → stylesheets}/trix.css +0 -0
- data/app/views/devise/sessions/new.html.erb +2 -2
- data/app/views/layouts/thecore.html.erb +8 -2
- data/config/initializers/thecore_ui_commons_application_config.rb +8 -7
- data/db/migrate/20200515070620_add_username_to_user.rb +3 -0
- data/lib/concerns/thecore_ui_commons_user.rb +20 -2
- data/lib/thecore_ui_commons/version.rb +1 -1
- metadata +8 -12
- data/app/assets/config/trix/LICENSE +0 -20
- data/app/assets/config/trix/README.md +0 -395
- data/app/assets/config/trix/package.json +0 -29
- data/app/assets/javascripts/thecore.js +0 -20
- data/app/views/shared/_flash.html.erb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4143e4e7f04c0e8f7c20087478451c3d21a23159f9a46c7d1538a9116fdca4a
|
4
|
+
data.tar.gz: d87ab5529a8abc0289a51fb72cd0989e3ef13678e24acfcd4d9b1a46fec08474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3a89897b04d5c57d7c441b8e374e5995f9e9cc97ec361d0d87f3328f2900905d6d2e746e3bcee42bbca815d8702ba70104ed353d14189382059f3bd982d2afe
|
7
|
+
data.tar.gz: ecd1c9c5c3040ec9c30b26174ecd8b1dd9ba6a6b95bfac301f837ef548b1ccd409a78e318c60cac3e2fb24be63570c7e276ea6235cd053597ca53ff60b894b3d
|
File without changes
|
File without changes
|
@@ -3,7 +3,7 @@
|
|
3
3
|
// the trix-editor content (whether displayed or under editing). Feel free to incorporate this
|
4
4
|
// inclusion directly in any other asset bundle and remove this file.
|
5
5
|
//
|
6
|
-
//= require trix
|
6
|
+
//= require trix
|
7
7
|
|
8
8
|
// We need to override trix.css’s image gallery styles to accommodate the
|
9
9
|
// <action-text-attachment> element we wrap around attachments. Otherwise,
|
File without changes
|
File without changes
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<div class="col-md-4 col-md-offset-4">
|
2
2
|
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
3
3
|
<div class="field">
|
4
|
-
<%= f.label :
|
5
|
-
<%= f.text_field :
|
4
|
+
<%= f.label :login %><br />
|
5
|
+
<%= f.text_field :login, autofocus: true, :class => "form-control" %>
|
6
6
|
</div>
|
7
7
|
|
8
8
|
<div class="field">
|
@@ -9,9 +9,15 @@
|
|
9
9
|
|
10
10
|
<%= tag("link", rel: "manifest", href: asset_path("manifest.json", skip_pipeline: true)) %>
|
11
11
|
<meta name="turbolinks-cache-control" content="no-cache">
|
12
|
-
<%= stylesheet_link_tag 'thecore', media: 'all', 'data-turbolinks-track' => true %>
|
13
|
-
<%= javascript_include_tag 'thecore', 'data-turbolinks-track' => true %>
|
14
12
|
|
13
|
+
<%-Rails.application.config.assets.paths.each do |p| %>
|
14
|
+
<%# Getting all the assets needed by thecore from all the gems %>
|
15
|
+
<%= stylesheet_link_tag("#{p.to_s.split("/").last}/thecore", media: 'all', 'data-turbolinks-track' => true) if File.exists?("#{p}/thecore.scss") %>
|
16
|
+
<%= javascript_include_tag("#{Dir["#{p}/**/thecore.js"].first.split("/")[-2]}/thecore", 'data-turbolinks-track' => true) if Dir["#{p}/**/thecore.js"].any? %>
|
17
|
+
<%-end%>
|
18
|
+
<%= stylesheet_link_tag('application', media: 'all', 'data-turbolinks-track' => true) if ::Rails.application.assets.find_asset("application.css")%>
|
19
|
+
<%= javascript_include_tag('application', 'data-turbolinks-track' => true) if ::Rails.application.assets.find_asset("application.js") %>
|
20
|
+
|
15
21
|
<%= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', sizes: "180x180" %>
|
16
22
|
<%= favicon_link_tag 'favicon-32x32.png', rel: 'icon', sizes: "32x32" %>
|
17
23
|
<%= favicon_link_tag 'favicon-16x16.png', rel: 'icon', sizes: "16x16" %>
|
@@ -1,5 +1,4 @@
|
|
1
1
|
Rails.application.configure do
|
2
|
-
config.assets.precompile += %w( thecore_ui_commons/index.js thecore_ui_commons/index.css )
|
3
2
|
config.assets.precompile += %w( favicon.ico )
|
4
3
|
config.assets.precompile += %w( apple-touch-icon.png )
|
5
4
|
config.assets.precompile += %w( favicon-32x32.png )
|
@@ -15,22 +14,24 @@ Rails.application.configure do
|
|
15
14
|
config.assets.precompile += %w( ie.js )
|
16
15
|
config.assets.precompile += %w( manifest.json )
|
17
16
|
config.assets.precompile += %w( browserconfig.xml )
|
18
|
-
|
17
|
+
config.assets.precompile += %w( thecore_ui_commons/thecore.js )
|
18
|
+
config.assets.precompile += %w( thecore_ui_commons/thecore.css )
|
19
|
+
config.assets.paths << Rails.root.join('node_modules')
|
19
20
|
# config.action_controller.asset_host = if ENV['RAILS_URL'].blank? || ENV['RAILS_RELATIVE_URL_ROOT'].blank?
|
20
21
|
# "http://localhost:3000"
|
21
22
|
# else
|
22
23
|
# "#{ENV['RAILS_URL']}#{ENV['RAILS_RELATIVE_URL_ROOT']}"
|
23
24
|
# end
|
24
|
-
|
25
|
+
|
25
26
|
config.filter_parameters += [:password]
|
26
|
-
|
27
|
+
|
27
28
|
config.active_record.raise_in_transactional_callbacks = true
|
28
|
-
|
29
|
+
|
29
30
|
config.serviceworker.routes.draw do
|
30
31
|
match "/manifest.json"
|
31
32
|
end
|
32
|
-
|
33
|
+
|
33
34
|
config.after_initialize do
|
34
35
|
User.send(:include, ThecoreUiCommonsUser)
|
35
|
-
end
|
36
|
+
end
|
36
37
|
end
|
@@ -3,7 +3,10 @@ class AddUsernameToUser < ActiveRecord::Migration[6.0]
|
|
3
3
|
add_column :users, :username, :string
|
4
4
|
add_index :users, :username
|
5
5
|
|
6
|
+
puts "Computing username for existing emails"
|
7
|
+
User.reset_column_information
|
6
8
|
User.all.each do |u|
|
9
|
+
puts "User: #{u.email} into #{u.email.split("@").first}"
|
7
10
|
u.username = u.email.split("@").first
|
8
11
|
u.save!
|
9
12
|
end
|
@@ -4,7 +4,25 @@ module ThecoreUiCommonsUser
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
devise :rememberable
|
8
|
-
|
7
|
+
devise :database_authenticatable, :trackable, :validatable, :rememberable, :timeoutable, timeout_in: 30.minutes, authentication_keys: [:login]
|
8
|
+
|
9
|
+
attr_writer :login
|
10
|
+
|
11
|
+
def login
|
12
|
+
@login || self.username || self.email
|
13
|
+
end
|
14
|
+
# Use login
|
15
|
+
def self.find_first_by_auth_conditions(warden_conditions)
|
16
|
+
puts "################################ VIENE USATO? #####################################################"
|
17
|
+
conditions = warden_conditions.dup
|
18
|
+
if login = conditions.delete(:login)
|
19
|
+
where(conditions.to_h).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
|
20
|
+
elsif conditions.has_key?(:username) || conditions.has_key?(:email)
|
21
|
+
# Case insensitive login
|
22
|
+
conditions[:email].downcase! if conditions[:email]
|
23
|
+
conditions[:username].downcase! if conditions[:username]
|
24
|
+
where(conditions.to_h).first
|
25
|
+
end
|
26
|
+
end
|
9
27
|
end
|
10
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecore_ui_commons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thecore_backend_commons
|
@@ -49,12 +49,6 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- app/assets/config/thecore_ui_commons_manifest.js
|
52
|
-
- app/assets/config/trix/LICENSE
|
53
|
-
- app/assets/config/trix/README.md
|
54
|
-
- app/assets/config/trix/dist/trix-core.js
|
55
|
-
- app/assets/config/trix/dist/trix.css
|
56
|
-
- app/assets/config/trix/dist/trix.js
|
57
|
-
- app/assets/config/trix/package.json
|
58
52
|
- app/assets/images/android-chrome-192x192.png
|
59
53
|
- app/assets/images/android-chrome-512x512.png
|
60
54
|
- app/assets/images/apple-touch-icon.png
|
@@ -69,10 +63,13 @@ files:
|
|
69
63
|
- app/assets/javascripts/ie.js
|
70
64
|
- app/assets/javascripts/manifest.json
|
71
65
|
- app/assets/javascripts/pages.coffee
|
72
|
-
- app/assets/javascripts/thecore.js
|
66
|
+
- app/assets/javascripts/thecore_ui_commons/thecore.js
|
73
67
|
- app/assets/javascripts/timer.js
|
74
|
-
- app/assets/
|
75
|
-
- app/assets/
|
68
|
+
- app/assets/javascripts/trix-core.js
|
69
|
+
- app/assets/javascripts/trix.js
|
70
|
+
- app/assets/stylesheets/thecore_ui_commons/actiontext.scss
|
71
|
+
- app/assets/stylesheets/thecore_ui_commons/thecore.scss
|
72
|
+
- app/assets/stylesheets/trix.css
|
76
73
|
- app/controllers/application_controller.rb
|
77
74
|
- app/views/active_storage/blobs/_blob.html.erb
|
78
75
|
- app/views/contact_mailer/contact_message.html.erb
|
@@ -103,7 +100,6 @@ files:
|
|
103
100
|
- app/views/layouts/mailer.html.erb
|
104
101
|
- app/views/layouts/mailer.text.erb
|
105
102
|
- app/views/layouts/thecore.html.erb
|
106
|
-
- app/views/shared/_flash.html.erb
|
107
103
|
- config/initializers/thecore_ui_commons_application_config.rb
|
108
104
|
- config/locales/en.simple_form.yml
|
109
105
|
- config/locales/it.simple_form.yml
|
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2020 Basecamp, LLC
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,395 +0,0 @@
|
|
1
|
-
# Trix
|
2
|
-
### A Rich Text Editor for Everyday Writing
|
3
|
-
|
4
|
-
**Compose beautifully formatted text in your web application.** Trix is a WYSIWYG editor for writing messages, comments, articles, and lists—the simple documents most web apps are made of. It features a sophisticated document model, support for embedded attachments, and outputs terse and consistent HTML.
|
5
|
-
|
6
|
-
Trix is an open-source project from [Basecamp](https://basecamp.com/), the creators of [Ruby on Rails](http://rubyonrails.org/). Millions of people trust their text to Basecamp, and we built Trix to give them the best possible editing experience. See Trix in action in the [all-new Basecamp 3](https://basecamp.com/3-is-coming).
|
7
|
-
|
8
|
-
### Different By Design
|
9
|
-
|
10
|
-
Most WYSIWYG editors are wrappers around HTML’s `contenteditable` and `execCommand` APIs, designed by Microsoft to support live editing of web pages in Internet Explorer 5.5, and [eventually reverse-engineered](https://blog.whatwg.org/the-road-to-html-5-contenteditable#history) and copied by other browsers.
|
11
|
-
|
12
|
-
Because these APIs were never fully specified or documented, and because WYSIWYG HTML editors are enormous in scope, each browser’s implementation has its own set of bugs and quirks, and JavaScript developers are left to resolve the inconsistencies.
|
13
|
-
|
14
|
-
Trix sidesteps these inconsistencies by treating `contenteditable` as an I/O device: when input makes its way to the editor, Trix converts that input into an editing operation on its internal document model, then re-renders that document back into the editor. This gives Trix complete control over what happens after every keystroke, and avoids the need to use `execCommand` at all.
|
15
|
-
|
16
|
-
### Built for the Modern Web
|
17
|
-
|
18
|
-
<details><summary>Trix supports all evergreen, self-updating desktop and mobile browsers.</summary><img src="https://app.saucelabs.com/browser-matrix/basecamp_trix.svg"></details>
|
19
|
-
|
20
|
-
Trix is built with emerging 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). Eventually we expect all browsers to implement these standards. In the meantime, Trix includes [polyfills](https://en.wikipedia.org/wiki/Polyfill_(programming)) for missing functionality.
|
21
|
-
|
22
|
-
# Getting Started
|
23
|
-
|
24
|
-
Include the bundled `trix.css` and `trix.js` files in the `<head>` of your page.
|
25
|
-
|
26
|
-
```html
|
27
|
-
<head>
|
28
|
-
…
|
29
|
-
<link rel="stylesheet" type="text/css" href="trix.css">
|
30
|
-
<script type="text/javascript" src="trix.js"></script>
|
31
|
-
</head>
|
32
|
-
```
|
33
|
-
|
34
|
-
`trix.css` includes default styles for the Trix toolbar, editor, and attachments. Skip this file if you prefer to define these styles yourself.
|
35
|
-
|
36
|
-
To use your own polyfills, or to target only browsers that support all of the required standards, include `trix-core.js` instead.
|
37
|
-
|
38
|
-
## Creating an Editor
|
39
|
-
|
40
|
-
Place an empty `<trix-editor></trix-editor>` tag on the page. Trix will automatically insert a separate `<trix-toolbar>` before the editor.
|
41
|
-
|
42
|
-
Like an HTML `<textarea>`, `<trix-editor>` accepts `autofocus` and `placeholder` attributes. Unlike a `<textarea>`, `<trix-editor>` automatically expands vertically to fit its contents.
|
43
|
-
|
44
|
-
## Integrating With Forms
|
45
|
-
|
46
|
-
To submit the contents of a `<trix-editor>` with a form, first define a hidden input field in the form and assign it an `id`. Then reference that `id` in the editor’s `input` attribute.
|
47
|
-
|
48
|
-
```html
|
49
|
-
<form …>
|
50
|
-
<input id="x" type="hidden" name="content">
|
51
|
-
<trix-editor input="x"></trix-editor>
|
52
|
-
</form>
|
53
|
-
```
|
54
|
-
|
55
|
-
Trix will automatically update the value of the hidden input field with each change to the editor.
|
56
|
-
|
57
|
-
## Populating With Stored Content
|
58
|
-
|
59
|
-
To populate a `<trix-editor>` with stored content, include that content in the associated input element’s `value` attribute.
|
60
|
-
|
61
|
-
```html
|
62
|
-
<form …>
|
63
|
-
<input id="x" value="Editor content goes here" type="hidden" name="content">
|
64
|
-
<trix-editor input="x"></trix-editor>
|
65
|
-
</form>
|
66
|
-
```
|
67
|
-
|
68
|
-
Always use an associated input element to safely populate an editor. Trix won’t load any HTML content inside a `<trix-editor>…</trix-editor>` tag.
|
69
|
-
|
70
|
-
## Styling Formatted Content
|
71
|
-
|
72
|
-
To ensure what you see when you edit is what you see when you save, use a CSS class name to scope styles for Trix formatted content. Apply this class name to your `<trix-editor>` element, and to a containing element when you render stored Trix content for display in your application.
|
73
|
-
|
74
|
-
```html
|
75
|
-
<trix-editor class="trix-content"></trix-editor>
|
76
|
-
```
|
77
|
-
|
78
|
-
```html
|
79
|
-
<div class="trix-content">Stored content here</div>
|
80
|
-
```
|
81
|
-
|
82
|
-
The default `trix.css` file includes styles for basic formatted content—including bulleted and numbered lists, code blocks, and block quotes—under the class name `trix-content`. We encourage you to use these styles as a starting point by copying them into your application’s CSS with a different class name.
|
83
|
-
|
84
|
-
## Storing Attached Files
|
85
|
-
|
86
|
-
Trix automatically accepts files dragged or pasted into an editor and inserts them as attachments in the document. Each attachment is considered _pending_ until you store it remotely and provide Trix with a permanent URL.
|
87
|
-
|
88
|
-
To store attachments, listen for the `trix-attachment-add` event. Upload the attached files with XMLHttpRequest yourself and set the attachment’s URL attribute upon completion. See the [attachment example](https://trix-editor.org/js/attachments.js) for detailed information.
|
89
|
-
|
90
|
-
If you don’t want to accept dropped or pasted files, call `preventDefault()` on the `trix-file-accept` event, which Trix dispatches just before the `trix-attachment-add` event.
|
91
|
-
|
92
|
-
# Editing Text Programmatically
|
93
|
-
|
94
|
-
You can manipulate a Trix editor programmatically through the `Trix.Editor` interface, available on each `<trix-editor>` element through its `editor` property.
|
95
|
-
|
96
|
-
```js
|
97
|
-
var element = document.querySelector("trix-editor")
|
98
|
-
element.editor // is a Trix.Editor instance
|
99
|
-
```
|
100
|
-
|
101
|
-
## Understanding the Document Model
|
102
|
-
|
103
|
-
The formatted content of a Trix editor is known as a _document_, and is represented as an instance of the `Trix.Document` class. To get the editor’s current document, use the `editor.getDocument` method.
|
104
|
-
|
105
|
-
```js
|
106
|
-
element.editor.getDocument() // is a Trix.Document instance
|
107
|
-
```
|
108
|
-
|
109
|
-
You can convert a document to an unformatted JavaScript string with the `document.toString` method.
|
110
|
-
|
111
|
-
```js
|
112
|
-
var document = element.editor.getDocument()
|
113
|
-
document.toString() // is a JavaScript string
|
114
|
-
```
|
115
|
-
|
116
|
-
### Immutability and Equality
|
117
|
-
|
118
|
-
Documents are immutable values. Each change you make in an editor replaces the previous document with a new document. Capturing a snapshot of the editor’s content is as simple as keeping a reference to its document, since that document will never change over time. (This is how Trix implements undo.)
|
119
|
-
|
120
|
-
To compare two documents for equality, use the `document.isEqualTo` method.
|
121
|
-
|
122
|
-
```js
|
123
|
-
var document = element.editor.getDocument()
|
124
|
-
document.isEqualTo(element.editor.getDocument()) // true
|
125
|
-
```
|
126
|
-
|
127
|
-
## Getting and Setting the Selection
|
128
|
-
|
129
|
-
Trix documents are structured as sequences of individually addressable characters. The index of one character in a document is called a _position_, and a start and end position together make up a _range_.
|
130
|
-
|
131
|
-
To get the editor’s current selection, use the `editor.getSelectedRange` method, which returns a two-element array containing the start and end positions.
|
132
|
-
|
133
|
-
```js
|
134
|
-
element.editor.getSelectedRange() // [0, 0]
|
135
|
-
```
|
136
|
-
|
137
|
-
You can set the editor’s current selection by passing a range array to the `editor.setSelectedRange` method.
|
138
|
-
|
139
|
-
```js
|
140
|
-
// Select the first character in the document
|
141
|
-
element.editor.setSelectedRange([0, 1])
|
142
|
-
```
|
143
|
-
|
144
|
-
### Collapsed Selections
|
145
|
-
|
146
|
-
When the start and end positions of a range are equal, the range is said to be _collapsed_. In the editor, a collapsed selection appears as a blinking cursor rather than a highlighted span of text.
|
147
|
-
|
148
|
-
For convenience, the following calls to `setSelectedRange` are equivalent when working with collapsed selections:
|
149
|
-
|
150
|
-
```js
|
151
|
-
element.editor.setSelectedRange(1)
|
152
|
-
element.editor.setSelectedRange([1])
|
153
|
-
element.editor.setSelectedRange([1, 1])
|
154
|
-
```
|
155
|
-
|
156
|
-
### Directional Movement
|
157
|
-
|
158
|
-
To programmatically move the cursor or selection through the document, call the `editor.moveCursorInDirection` or `editor.expandSelectionInDirection` methods with a _direction_ argument. The direction can be either `"forward"` or `"backward"`.
|
159
|
-
|
160
|
-
```js
|
161
|
-
// Move the cursor backward one character
|
162
|
-
element.editor.moveCursorInDirection("backward")
|
163
|
-
|
164
|
-
// Expand the end of the selection forward by one character
|
165
|
-
element.editor.expandSelectionInDirection("forward")
|
166
|
-
```
|
167
|
-
|
168
|
-
### Converting Positions to Pixel Offsets
|
169
|
-
|
170
|
-
Sometimes you need to know the _x_ and _y_ coordinates of a character at a given position in the editor. For example, you might want to absolutely position a pop-up menu element below the editor’s cursor.
|
171
|
-
|
172
|
-
Call the `editor.getClientRectAtPosition` method with a position argument to get a [`DOMRect`](https://drafts.fxtf.org/geometry/#DOMRect) instance representing the left and top offsets, width, and height of the character at the given position.
|
173
|
-
|
174
|
-
```js
|
175
|
-
var rect = element.editor.getClientRectAtPosition(0)
|
176
|
-
[rect.left, rect.top] // [17, 49]
|
177
|
-
```
|
178
|
-
|
179
|
-
## Inserting and Deleting Text
|
180
|
-
|
181
|
-
The editor interface provides methods for inserting, replacing, and deleting text at the current selection.
|
182
|
-
|
183
|
-
To insert or replace text, begin by setting the selected range, then call one of the insertion methods below. Trix will first remove any selected text, then insert the new text at the start position of the selected range.
|
184
|
-
|
185
|
-
### Inserting Plain Text
|
186
|
-
|
187
|
-
To insert unformatted text into the document, call the `editor.insertString` method.
|
188
|
-
|
189
|
-
```js
|
190
|
-
// Insert “Hello” at the beginning of the document
|
191
|
-
element.editor.setSelectedRange([0, 0])
|
192
|
-
element.editor.insertString("Hello")
|
193
|
-
```
|
194
|
-
|
195
|
-
### Inserting HTML
|
196
|
-
|
197
|
-
To insert HTML into the document, call the `editor.insertHTML` method. Trix will first convert the HTML into its internal document model. During this conversion, any formatting that cannot be represented in a Trix document will be lost.
|
198
|
-
|
199
|
-
```js
|
200
|
-
// Insert a bold “Hello” at the beginning of the document
|
201
|
-
element.editor.setSelectedRange([0, 0])
|
202
|
-
element.editor.insertHTML("<strong>Hello</strong>")
|
203
|
-
```
|
204
|
-
|
205
|
-
### Inserting a File
|
206
|
-
|
207
|
-
To insert a DOM [`File`](http://www.w3.org/TR/FileAPI/#file) object into the document, call the `editor.insertFile` method. Trix will insert a pending attachment for the file as if you had dragged and dropped it onto the editor.
|
208
|
-
|
209
|
-
```js
|
210
|
-
// Insert the selected file from the first file input element
|
211
|
-
var file = document.querySelector("input[type=file]").file
|
212
|
-
element.editor.insertFile(file)
|
213
|
-
```
|
214
|
-
|
215
|
-
### Inserting a Content Attachment
|
216
|
-
|
217
|
-
Content attachments are self-contained units of HTML that behave like files in the editor. They can be moved or removed, but not edited directly, and are represented by a single character position in the document model.
|
218
|
-
|
219
|
-
To insert HTML as an attachment, create a `Trix.Attachment` with a `content` attribute and call the `editor.insertAttachment` method. The HTML inside a content attachment is not subject to Trix’s document conversion rules and will be rendered as-is.
|
220
|
-
|
221
|
-
```js
|
222
|
-
var attachment = new Trix.Attachment({ content: '<span class="mention">@trix</span>' })
|
223
|
-
element.editor.insertAttachment(attachment)
|
224
|
-
```
|
225
|
-
|
226
|
-
### Inserting a Line Break
|
227
|
-
|
228
|
-
To insert a line break, call the `editor.insertLineBreak` method, which is functionally equivalent to pressing the return key.
|
229
|
-
|
230
|
-
```js
|
231
|
-
// Insert “Hello\n”
|
232
|
-
element.editor.insertString("Hello")
|
233
|
-
element.editor.insertLineBreak()
|
234
|
-
```
|
235
|
-
|
236
|
-
### Deleting Text
|
237
|
-
|
238
|
-
If the current selection is collapsed, you can simulate deleting text before or after the cursor with the `editor.deleteInDirection` method.
|
239
|
-
|
240
|
-
```js
|
241
|
-
// “Backspace” the first character in the document
|
242
|
-
element.editor.setSelectedRange([1, 1])
|
243
|
-
element.editor.deleteInDirection("backward")
|
244
|
-
|
245
|
-
// Delete the second character in the document
|
246
|
-
element.editor.setSelectedRange([1, 1])
|
247
|
-
element.editor.deleteInDirection("forward")
|
248
|
-
```
|
249
|
-
|
250
|
-
To delete a range of text, first set the selected range, then call `editor.deleteInDirection` with either direction as the argument.
|
251
|
-
|
252
|
-
```js
|
253
|
-
// Delete the first five characters
|
254
|
-
element.editor.setSelectedRange([0, 4])
|
255
|
-
element.editor.deleteInDirection("forward")
|
256
|
-
```
|
257
|
-
|
258
|
-
## Working With Attributes and Nesting
|
259
|
-
|
260
|
-
Trix represents formatting as sets of _attributes_ applied across ranges of a document.
|
261
|
-
|
262
|
-
By default, Trix supports the inline attributes `bold`, `italic`, `href`, and `strike`, and the block-level attributes `heading1`, `quote`, `code`, `bullet`, and `number`.
|
263
|
-
|
264
|
-
### Applying Formatting
|
265
|
-
|
266
|
-
To apply formatting to the current selection, use the `editor.activateAttribute` method.
|
267
|
-
|
268
|
-
```js
|
269
|
-
element.editor.insertString("Hello")
|
270
|
-
element.editor.setSelectedRange([0, 5])
|
271
|
-
element.editor.activateAttribute("bold")
|
272
|
-
```
|
273
|
-
|
274
|
-
To set the `href` attribute, pass a URL as the second argument to `editor.activateAttribute`.
|
275
|
-
|
276
|
-
```js
|
277
|
-
element.editor.insertString("Trix")
|
278
|
-
element.editor.setSelectedRange([0, 4])
|
279
|
-
element.editor.activateAttribute("href", "https://trix-editor.org/")
|
280
|
-
```
|
281
|
-
|
282
|
-
### Removing Formatting
|
283
|
-
|
284
|
-
Use the `editor.deactivateAttribute` method to remove formatting from a selection.
|
285
|
-
|
286
|
-
```js
|
287
|
-
element.editor.setSelectedRange([2, 4])
|
288
|
-
element.editor.deactivateAttribute("bold")
|
289
|
-
```
|
290
|
-
|
291
|
-
### Formatting With a Collapsed Selection
|
292
|
-
|
293
|
-
If you activate or deactivate attributes when the selection is collapsed, your formatting changes will apply to the text inserted by any subsequent calls to `editor.insertString`.
|
294
|
-
|
295
|
-
```js
|
296
|
-
element.editor.activateAttribute("italic")
|
297
|
-
element.editor.insertString("This is italic")
|
298
|
-
```
|
299
|
-
|
300
|
-
### Adjusting the Nesting Level
|
301
|
-
|
302
|
-
To adjust the nesting level of quotes, bulleted lists, or numbered lists, call the `editor.increaseNestingLevel` and `editor.decreaseNestingLevel` methods.
|
303
|
-
|
304
|
-
```js
|
305
|
-
element.editor.activateAttribute("quote")
|
306
|
-
element.editor.increaseNestingLevel()
|
307
|
-
element.editor.decreaseNestingLevel()
|
308
|
-
```
|
309
|
-
|
310
|
-
## Using Undo and Redo
|
311
|
-
|
312
|
-
Trix editors support unlimited undo and redo. Successive typing and formatting changes are consolidated together at five-second intervals; all other input changes are recorded individually in undo history.
|
313
|
-
|
314
|
-
Call the `editor.undo` and `editor.redo` methods to perform an undo or redo operation.
|
315
|
-
|
316
|
-
```js
|
317
|
-
element.editor.undo()
|
318
|
-
element.editor.redo()
|
319
|
-
```
|
320
|
-
|
321
|
-
Changes you make through the editor interface will not automatically record undo entries. You can save your own undo entries by calling the `editor.recordUndoEntry` method with a description argument.
|
322
|
-
|
323
|
-
```js
|
324
|
-
element.editor.recordUndoEntry("Insert Text")
|
325
|
-
element.editor.insertString("Hello")
|
326
|
-
```
|
327
|
-
|
328
|
-
## Loading and Saving Editor State
|
329
|
-
|
330
|
-
Serialize an editor’s state with `JSON.stringify` and restore saved state with the `editor.loadJSON` method. The serialized state includes the document and current selection, but does not include undo history.
|
331
|
-
|
332
|
-
```js
|
333
|
-
// Save editor state to local storage
|
334
|
-
localStorage["editorState"] = JSON.stringify(element.editor)
|
335
|
-
|
336
|
-
// Restore editor state from local storage
|
337
|
-
element.editor.loadJSON(JSON.parse(localStorage["editorState"]))
|
338
|
-
```
|
339
|
-
|
340
|
-
## Observing Editor Changes
|
341
|
-
|
342
|
-
The `<trix-editor>` element emits several events which you can use to observe and respond to changes in editor state.
|
343
|
-
|
344
|
-
* `trix-before-initialize` fires when the `<trix-editor>` element is attached to the DOM just before Trix installs its `editor` object.
|
345
|
-
|
346
|
-
* `trix-initialize` fires when the `<trix-editor>` element is attached to the DOM and its `editor` object is ready for use.
|
347
|
-
|
348
|
-
* `trix-change` fires whenever the editor’s contents have changed.
|
349
|
-
|
350
|
-
* `trix-selection-change` fires any time the selected range changes in the editor.
|
351
|
-
|
352
|
-
* `trix-focus` and `trix-blur` fire when the editor gains or loses focus, respectively.
|
353
|
-
|
354
|
-
* `trix-file-accept` fires when a file is dropped or inserted into the editor. You can access the DOM `File` object through the `file` property on the event. Call `preventDefault` on the event to prevent attaching the file to the document.
|
355
|
-
|
356
|
-
* `trix-attachment-add` fires after an attachment is added to the document. You can access the Trix attachment object through the `attachment` property on the event. If the `attachment` object has a `file` property, you should store this file remotely and set the attachment’s URL attribute. See the [attachment example](http://trix-editor.org/js/attachments.js) for detailed information.
|
357
|
-
|
358
|
-
* `trix-attachment-remove` fires when an attachment is removed from the document. You can access the Trix attachment object through the `attachment` property on the event. You may wish to use this event to clean up remotely stored files.
|
359
|
-
|
360
|
-
# Contributing to Trix
|
361
|
-
|
362
|
-
Trix is open-source software, freely distributable under the terms of an [MIT-style license](LICENSE). The [source code is hosted on GitHub](https://github.com/basecamp/trix).
|
363
|
-
|
364
|
-
We welcome contributions in the form of bug reports, pull requests, or thoughtful discussions in the [GitHub issue tracker](https://github.com/basecamp/trix/issues). Please see the [Code of Conduct](CODE_OF_CONDUCT.md) for our pledge to contributors.
|
365
|
-
|
366
|
-
Trix was created by [Javan Makhmali](https://twitter.com/javan) and [Sam Stephenson](https://twitter.com/sstephenson), with development sponsored by [Basecamp](https://basecamp.com/).
|
367
|
-
|
368
|
-
### Building From Source
|
369
|
-
|
370
|
-
Trix is written in [CoffeeScript](https://github.com/jashkenas/coffeescript) and compiled to JavaScript with [Blade](https://github.com/javan/blade).
|
371
|
-
|
372
|
-
From inside a checkout of the Trix Git repository, issue the following commands to build the distributable files in `dist/`:
|
373
|
-
|
374
|
-
```
|
375
|
-
$ bin/setup
|
376
|
-
$ bin/blade build
|
377
|
-
```
|
378
|
-
|
379
|
-
### Developing In-Browser
|
380
|
-
|
381
|
-
You can spawn a development web server to work on Trix in a more convenient fashion. Instead of manually rebuilding the source each time, just reload a page in your browser to see your changes.
|
382
|
-
|
383
|
-
To develop in-browser, run `bin/setup` and follow the displayed instructions.
|
384
|
-
|
385
|
-
### Running Tests
|
386
|
-
|
387
|
-
Make sure you’re set up to build from source using the instructions above. Then run `bin/blade runner` and visit the displayed URL to run the Trix test suite.
|
388
|
-
|
389
|
-
### Pull Requests
|
390
|
-
|
391
|
-
Only commit changes to Trix’s source (everything except the compiled files in `/dist`) and leave the [VERSION](src/trix/VERSION) unchanged. We update both when publishing new [releases](https://github.com/basecamp/trix/releases). :heart:
|
392
|
-
|
393
|
-
---
|
394
|
-
|
395
|
-
© 2020 Basecamp, LLC.
|
@@ -1,29 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "trix",
|
3
|
-
"version": "1.2.3",
|
4
|
-
"description": "A rich text editor for everyday writing",
|
5
|
-
"main": "dist/trix.js",
|
6
|
-
"style": "dist/trix.css",
|
7
|
-
"files": [
|
8
|
-
"dist/*.css",
|
9
|
-
"dist/*.js"
|
10
|
-
],
|
11
|
-
"repository": {
|
12
|
-
"type": "git",
|
13
|
-
"url": "git+https://github.com/basecamp/trix.git"
|
14
|
-
},
|
15
|
-
"keywords": [
|
16
|
-
"rich text",
|
17
|
-
"wysiwyg",
|
18
|
-
"editor"
|
19
|
-
],
|
20
|
-
"author": "Basecamp, LLC",
|
21
|
-
"license": "MIT",
|
22
|
-
"bugs": {
|
23
|
-
"url": "https://github.com/basecamp/trix/issues"
|
24
|
-
},
|
25
|
-
"homepage": "https://trix-editor.org/",
|
26
|
-
"devDependencies": {
|
27
|
-
"svgo": "^0.6.1"
|
28
|
-
}
|
29
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require jquery
|
14
|
-
//= require jquery-ui
|
15
|
-
//= require jquery-ui/widgets/dialog
|
16
|
-
//= require jquery_ujs
|
17
|
-
//= require bootstrap
|
18
|
-
//= require ie
|
19
|
-
//= require timer
|
20
|
-
//= require_tree .
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<% flash.each do |type, message| %>
|
2
|
-
<%-unless [true, "true", :true].include? message%>
|
3
|
-
<div class="alert <%= bootstrap_class_for(type) %> fade in" role='alert'>
|
4
|
-
<button class="close" data-dismiss="alert">×</button>
|
5
|
-
<span class="glyphicon <%= bootstrap_glyphs_icon(type)%>" aria-hidden="true"></span>
|
6
|
-
<span class="sr-only"><%= type.capitalize%>:</span>
|
7
|
-
<%= message %>
|
8
|
-
</div>
|
9
|
-
<%-end%>
|
10
|
-
<% end %>
|