turbo_boost-elements 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/builds/@turbo-boost/elements.js +7 -7
- data/app/assets/builds/@turbo-boost/elements.js.map +4 -4
- data/app/javascript/elements/toggle_target_element.js +2 -3
- data/app/javascript/elements/toggle_target_focus.js +78 -0
- data/lib/turbo_boost/elements/version.rb +1 -1
- metadata +5 -4
@@ -1,4 +1,5 @@
|
|
1
1
|
import TurboBoostElement from './turbo_boost_element'
|
2
|
+
import './toggle_target_focus'
|
2
3
|
|
3
4
|
export default class ToggleTargetElement extends TurboBoostElement {
|
4
5
|
connectedCallback () {
|
@@ -55,9 +56,7 @@ export default class ToggleTargetElement extends TurboBoostElement {
|
|
55
56
|
focus () {
|
56
57
|
clearTimeout(this.focusTimeout)
|
57
58
|
this.focusTimeout = setTimeout(() => {
|
58
|
-
if (
|
59
|
-
this.focusElement.focus()
|
60
|
-
this.focusElement.scrollIntoView({ block: 'center', behavior: 'smooth' })
|
59
|
+
if (this.focusElement) this.focusElement.focus()
|
61
60
|
}, 50)
|
62
61
|
}
|
63
62
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
function deactivateTrixAttributes (editor) {
|
2
|
+
const attributes = [
|
3
|
+
'bold',
|
4
|
+
'bullet',
|
5
|
+
'code',
|
6
|
+
'heading1',
|
7
|
+
'href',
|
8
|
+
'italic',
|
9
|
+
'number',
|
10
|
+
'quote',
|
11
|
+
'strike'
|
12
|
+
]
|
13
|
+
attributes.forEach(name => editor.deactivateAttribute(name))
|
14
|
+
}
|
15
|
+
|
16
|
+
function focusTrixEditorElement (element) {
|
17
|
+
if (element.value.length === 0) return
|
18
|
+
|
19
|
+
const editor = element.editor
|
20
|
+
|
21
|
+
// move cursor to the end
|
22
|
+
let lastRange = []
|
23
|
+
while (
|
24
|
+
lastRange[0] !== editor.getSelectedRange()[0] &&
|
25
|
+
lastRange[1] !== editor.getSelectedRange()[1]
|
26
|
+
) {
|
27
|
+
lastRange = editor.getSelectedRange()
|
28
|
+
editor.moveCursorInDirection('forward')
|
29
|
+
}
|
30
|
+
|
31
|
+
// insert an empty char and select it
|
32
|
+
editor.insertString(' ')
|
33
|
+
editor.moveCursorInDirection('forward')
|
34
|
+
editor.setSelectedRange([lastRange[1], editor.getSelectedRange()[1]])
|
35
|
+
|
36
|
+
// deactivate all trix features for the selection
|
37
|
+
deactivateTrixAttributes(editor)
|
38
|
+
|
39
|
+
// move cursor to end and collapse the selection
|
40
|
+
editor.setSelectedRange([
|
41
|
+
editor.getSelectedRange()[1],
|
42
|
+
editor.getSelectedRange()[1]
|
43
|
+
])
|
44
|
+
}
|
45
|
+
|
46
|
+
function shouldEnhanceFocus (element) {
|
47
|
+
return (
|
48
|
+
element.closest('turbo-boost-toggle-target') &&
|
49
|
+
element.tagName.match(/^input|textarea|trix-editor$/i)
|
50
|
+
)
|
51
|
+
}
|
52
|
+
|
53
|
+
function enhanceFocus (element) {
|
54
|
+
const trixEditorElement = element.closest('trix-editor')
|
55
|
+
|
56
|
+
try {
|
57
|
+
if (trixEditorElement) {
|
58
|
+
focusTrixEditorElement(trixEditorElement)
|
59
|
+
} else {
|
60
|
+
element.selectionStart = element.selectionEnd = element.value.length
|
61
|
+
}
|
62
|
+
} catch (_) {
|
63
|
+
} finally {
|
64
|
+
setTimeout(
|
65
|
+
() => element.scrollIntoView({ block: 'center', behavior: 'smooth' }),
|
66
|
+
100
|
67
|
+
)
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
addEventListener(
|
72
|
+
'focus',
|
73
|
+
event => {
|
74
|
+
if (shouldEnhanceFocus(document.activeElement))
|
75
|
+
enhanceFocus(document.activeElement)
|
76
|
+
},
|
77
|
+
true
|
78
|
+
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo_boost-elements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Hopkins (hopsoft)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0.
|
47
|
+
version: 0.0.7
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0.
|
54
|
+
version: 0.0.7
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: magic_frozen_string_literal
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- app/javascript/devtools/toggle.js
|
147
147
|
- app/javascript/elements/index.js
|
148
148
|
- app/javascript/elements/toggle_target_element.js
|
149
|
+
- app/javascript/elements/toggle_target_focus.js
|
149
150
|
- app/javascript/elements/toggle_trigger_element.js
|
150
151
|
- app/javascript/elements/turbo_boost_element.js
|
151
152
|
- app/javascript/index.js
|