thecore_ui_commons 2.1.5 → 2.1.6
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/trix/LICENSE +20 -0
- data/app/assets/config/trix/README.md +395 -0
- data/app/assets/config/trix/dist/trix-core.js +12 -0
- data/app/assets/config/trix/dist/trix.css +374 -0
- data/app/assets/config/trix/dist/trix.js +21 -0
- data/app/assets/config/trix/package.json +29 -0
- data/app/assets/images/android-chrome-192x192.png +0 -0
- data/app/assets/images/android-chrome-512x512.png +0 -0
- data/app/assets/images/apple-touch-icon.png +0 -0
- data/app/assets/images/favicon-16x16.png +0 -0
- data/app/assets/images/favicon-32x32.png +0 -0
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/images/logo.png +0 -0
- data/app/assets/images/mstile-150x150.png +0 -0
- data/app/assets/images/safari-pinned-tab.svg +1042 -0
- data/app/assets/images/up-arrow.png +0 -0
- data/app/assets/javascripts/browserconfig.xml +9 -0
- data/app/assets/javascripts/ie.js +19 -0
- data/app/assets/javascripts/manifest.json +20 -0
- data/app/assets/javascripts/pages.coffee +3 -0
- data/app/assets/javascripts/thecore.js +20 -0
- data/app/assets/javascripts/timer.js +135 -0
- data/app/assets/stylesheets/{thecore_ui_commons/actiontext.scss → actiontext.scss} +19 -20
- data/app/assets/stylesheets/thecore.scss +18 -0
- data/app/views/contact_mailer/contact_message.html.erb +5 -0
- data/app/views/devise/confirmations/new.html.erb +16 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/password_change.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/menu/_login_items.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +25 -0
- data/app/views/devise/passwords/new.html.erb +18 -0
- data/app/views/devise/registrations/edit.html.erb +45 -0
- data/app/views/devise/registrations/new.html.erb +29 -0
- data/app/views/devise/sessions/new.html.erb +28 -0
- data/app/views/devise/shared/_links.html.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +16 -0
- data/app/views/kaminari/_first_page.html.erb +3 -0
- data/app/views/kaminari/_gap.html.erb +3 -0
- data/app/views/kaminari/_last_page.html.erb +3 -0
- data/app/views/kaminari/_next_page.html.erb +3 -0
- data/app/views/kaminari/_page.html.erb +9 -0
- data/app/views/kaminari/_paginator.html.erb +15 -0
- data/app/views/kaminari/_prev_page.html.erb +3 -0
- data/app/views/layouts/_footer.html.erb +3 -0
- data/app/views/layouts/_messages.html.erb +9 -0
- data/app/views/layouts/_navigation.html.erb +20 -0
- data/app/views/layouts/_navigation_links.html.erb +7 -0
- data/app/views/layouts/mailer.html.erb +6 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/views/layouts/thecore.html.erb +42 -0
- data/app/views/shared/_flash.html.erb +10 -0
- data/config/initializers/thecore_ui_commons_application_config.rb +4 -3
- data/db/migrate/20200515070620_add_username_to_user.rb +11 -0
- data/db/migrate/20200515132932_add_rememberable_to_user.rb +5 -0
- data/lib/concerns/thecore_ui_commons_user.rb +10 -0
- data/lib/thecore_ui_commons/version.rb +1 -1
- data/lib/thecore_ui_commons.rb +4 -2
- metadata +58 -4
- data/app/controllers/pages_controller.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d71a88aedf5e29fd308b9fc96059e6ba86920276f15e4598cf022227aadaaa10
|
4
|
+
data.tar.gz: 4beab2991ffdb24463709959e9fc63a600cb978e61dd4fa4b2a79c8bc7007a75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 281cbf4a31a5b0cb7482d8c31da18c26737548a72fb5625a65c73ab51c8cdedcfaf4367e6b1557b6329dee01c62daab2d9ea45513c160d89b381e46028d7b9de
|
7
|
+
data.tar.gz: 055dc5d18c7ef103bdc07f56d9035d2b7db7df31af825accf913b748dea77b868bd862e8e372852cbd470f6761fe3c8827e86cdd8e6dd7ce70478e01e0f244a5
|
@@ -0,0 +1,20 @@
|
|
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.
|
@@ -0,0 +1,395 @@
|
|
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.
|