reflex_behaviors 0.0.5 → 0.0.7
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +11 -9
- data/README.md +1 -1
- data/app/assets/builds/reflex_behaviors.js +45 -48
- data/app/assets/builds/reflex_behaviors.js.map +4 -4
- data/app/javascript/devtools/dependencies.js +53 -0
- data/app/javascript/devtools/elements/supervisor_element.js +15 -13
- data/app/javascript/devtools/elements/tooltip_element.js +27 -41
- data/app/javascript/devtools/supervisor.js +17 -5
- data/app/javascript/devtools/toggle.js +174 -84
- data/app/javascript/elements/reflex_element.js +0 -10
- data/app/javascript/index.js +0 -3
- data/app/javascript/utils/dom.js +62 -0
- data/lib/reflex_behaviors/version.rb +1 -1
- data/package.json +4 -5
- data/reflex_behaviors.gemspec +2 -2
- data/tags +3653 -2921
- data/yarn.lock +148 -146
- metadata +8 -7
- data/app/javascript/devtools/dom.js +0 -36
@@ -0,0 +1,53 @@
|
|
1
|
+
const added = []
|
2
|
+
|
3
|
+
const dependencies = {
|
4
|
+
LeaderLine: {
|
5
|
+
src:
|
6
|
+
'https://cdnjs.cloudflare.com/ajax/libs/leader-line/1.0.7/leader-line.min.js',
|
7
|
+
integrity:
|
8
|
+
'sha512-0dNdzMjpT6pJdFGF1DwybFCfm3K/lzHhxaMXC/92J9/DZujHlqYFqmhTOAoD0o+LkeEsVK2ar/ESs7/Q2B6wJg==',
|
9
|
+
global: 'LeaderLine'
|
10
|
+
},
|
11
|
+
|
12
|
+
PlainDraggable: {
|
13
|
+
src:
|
14
|
+
'https://cdn.jsdelivr.net/npm/plain-draggable@2.5.14/plain-draggable.min.js',
|
15
|
+
global: 'PlainDraggable'
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
function exists (dependency) {
|
20
|
+
if (dependency.global && self[dependency.global]) return true
|
21
|
+
if (document.querySelector(`[src='${dependency.src}']`)) return true
|
22
|
+
return added.includes(dependency)
|
23
|
+
}
|
24
|
+
|
25
|
+
function add (dependency) {
|
26
|
+
if (exists(dependency)) return
|
27
|
+
added.push(dependency)
|
28
|
+
|
29
|
+
const { src, integrity } = dependency
|
30
|
+
const script = document.createElement('script')
|
31
|
+
script.setAttribute('src', src)
|
32
|
+
script.setAttribute('crossorigin', 'anonymous')
|
33
|
+
script.setAttribute('referrerpolicy', 'no-referrer')
|
34
|
+
if (integrity) script.setAttribute('integrity', integrity)
|
35
|
+
document.head.appendChild(script)
|
36
|
+
}
|
37
|
+
|
38
|
+
function remove (dependency) {
|
39
|
+
if (!added.includes(dependency)) return
|
40
|
+
added.splice(added.indexOf(dependency), 1)
|
41
|
+
|
42
|
+
const { src } = dependency
|
43
|
+
const el = document.querySelector(`script[src='${src}']`)
|
44
|
+
if (el) el.remove()
|
45
|
+
if (dependency.global && self[dependency.global])
|
46
|
+
self[dependency.global] = null
|
47
|
+
}
|
48
|
+
|
49
|
+
function removeAll () {
|
50
|
+
;[...added].forEach(dependency => remove(dependency))
|
51
|
+
}
|
52
|
+
|
53
|
+
export default { ...dependencies, add, remove, removeAll }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { appendHTML } from '
|
1
|
+
import { appendHTML } from '../../utils/dom'
|
2
2
|
|
3
3
|
export default class SupervisorElement extends HTMLElement {
|
4
4
|
constructor () {
|
@@ -6,9 +6,13 @@ export default class SupervisorElement extends HTMLElement {
|
|
6
6
|
this.enabledDevtools = {}
|
7
7
|
this.attachShadow({ mode: 'open' })
|
8
8
|
this.shadowRoot.innerHTML = this.html
|
9
|
-
this.shadowRoot
|
10
|
-
.
|
11
|
-
|
9
|
+
this.shadowRoot.querySelector('button').addEventListener('click', () =>
|
10
|
+
this.dispatchEvent(
|
11
|
+
new CustomEvent('reflex-behaviors:devtools-close', {
|
12
|
+
bubbles: true
|
13
|
+
})
|
14
|
+
)
|
15
|
+
)
|
12
16
|
|
13
17
|
this.addEventListener('change', event => {
|
14
18
|
const devtoolElement = event.target
|
@@ -60,7 +64,7 @@ export default class SupervisorElement extends HTMLElement {
|
|
60
64
|
<div>
|
61
65
|
<label>ReflexBehaviors</label>
|
62
66
|
<slot name="devtool"></slot>
|
63
|
-
<button
|
67
|
+
<button>✕</button>
|
64
68
|
</div>
|
65
69
|
`
|
66
70
|
}
|
@@ -79,22 +83,19 @@ export default class SupervisorElement extends HTMLElement {
|
|
79
83
|
padding: 5px 10px;
|
80
84
|
position: fixed;
|
81
85
|
transform: translateX(-50%);
|
82
|
-
z-index:
|
86
|
+
z-index: 8999;
|
83
87
|
}
|
84
88
|
|
85
|
-
|
89
|
+
* {
|
86
90
|
-webkit-user-select: none;
|
87
91
|
font-family: helvetica, sans-serif;
|
92
|
+
font-size: 1rem;
|
88
93
|
user-select: none;
|
89
94
|
}
|
90
95
|
|
91
|
-
:host:has( input) {
|
92
|
-
outline-color: red;
|
93
|
-
outline-width: 2px;
|
94
|
-
}
|
95
|
-
|
96
96
|
label {
|
97
97
|
color: indigo;
|
98
|
+
cursor: grab;
|
98
99
|
opacity: 0.5;
|
99
100
|
}
|
100
101
|
|
@@ -119,10 +120,11 @@ export default class SupervisorElement extends HTMLElement {
|
|
119
120
|
position: relative;
|
120
121
|
top: 1px;
|
121
122
|
width: 18px;
|
123
|
+
opacity: 0.5;
|
122
124
|
}
|
123
125
|
|
124
126
|
button:hover {
|
125
|
-
|
127
|
+
opacity: 1;
|
126
128
|
}
|
127
129
|
`
|
128
130
|
}
|
@@ -9,10 +9,6 @@ export default class TooltipElement extends HTMLElement {
|
|
9
9
|
return this.getAttribute('color') || 'darkslategray'
|
10
10
|
}
|
11
11
|
|
12
|
-
get emphasisColor () {
|
13
|
-
return this.getAttribute('emphasis-color') || 'black'
|
14
|
-
}
|
15
|
-
|
16
12
|
get backgroundColor () {
|
17
13
|
return this.getAttribute('background-color') || 'gainsboro'
|
18
14
|
}
|
@@ -21,23 +17,14 @@ export default class TooltipElement extends HTMLElement {
|
|
21
17
|
return this.getAttribute('position') || 'top'
|
22
18
|
}
|
23
19
|
|
24
|
-
get cssArrow () {
|
25
|
-
switch (this.position) {
|
26
|
-
case 'bottom':
|
27
|
-
return `transparent transparent ${this.emphasisColor} transparent`
|
28
|
-
default:
|
29
|
-
return `${this.emphasisColor} transparent transparent transparent;`
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
20
|
get html () {
|
34
21
|
return `
|
35
22
|
<style>${this.stylesheet}</style>
|
36
|
-
<div
|
23
|
+
<div>
|
37
24
|
<slot name="title"></slot>
|
38
|
-
<
|
39
|
-
<slot name="
|
40
|
-
<slot name="
|
25
|
+
<slot name="content-top"></slot>
|
26
|
+
<slot name="content"></slot>
|
27
|
+
<slot name="content-bottom"></slot>
|
41
28
|
</div>
|
42
29
|
`
|
43
30
|
}
|
@@ -47,56 +34,55 @@ export default class TooltipElement extends HTMLElement {
|
|
47
34
|
:host {
|
48
35
|
display: block;
|
49
36
|
position: absolute;
|
50
|
-
z-index:
|
37
|
+
z-index: 8999;
|
51
38
|
}
|
52
39
|
|
53
40
|
* {
|
54
41
|
color: ${this.color}
|
42
|
+
font-size: 1rem;
|
55
43
|
}
|
56
44
|
|
57
|
-
|
45
|
+
div {
|
58
46
|
background-color: ${this.backgroundColor};
|
59
47
|
border-radius: 15px;
|
60
48
|
filter: drop-shadow(3px 3px 3px rgba(0,0,0,0.3));
|
61
49
|
font-family: monospace;
|
62
|
-
left: 50px;
|
63
50
|
min-height: 30px;
|
64
51
|
min-width: 100px;
|
65
52
|
opacity: 0.9;
|
66
53
|
outline-offset: 1px;
|
67
|
-
outline:
|
54
|
+
outline: dashed 3px ${this.color};
|
68
55
|
padding: 8px 12px 8px 12px;
|
56
|
+
position: relative;
|
69
57
|
white-space: nowrap;
|
70
58
|
}
|
71
59
|
|
72
|
-
[role="tooltip"]::after {
|
73
|
-
border-color: ${this.cssArrow};
|
74
|
-
border-style: solid;
|
75
|
-
border-width: 10px;
|
76
|
-
content: "";
|
77
|
-
margin-left: -7px;
|
78
|
-
position: absolute;
|
79
|
-
top: ${this.position === 'bottom' ? '-21px' : 'calc(100% + 1px)'};
|
80
|
-
}
|
81
|
-
|
82
60
|
slot[name="title"] {
|
83
|
-
|
61
|
+
border-bottom: dotted 1px ${this.color};
|
62
|
+
color: ${this.color};
|
63
|
+
display: inline-block;
|
84
64
|
font-weight: bold;
|
65
|
+
margin-bottom: 8px;
|
66
|
+
padding-bottom: 8px;
|
67
|
+
width: 100%;
|
85
68
|
}
|
86
69
|
|
87
|
-
slot[name="
|
88
|
-
color: ${this.
|
70
|
+
slot[name="content-top"] {
|
71
|
+
color: ${this.color};
|
89
72
|
font-weight: normal;
|
90
73
|
opacity: 0.7;
|
91
74
|
}
|
92
75
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
76
|
+
slot[name="content"] {
|
77
|
+
color: ${this.color};
|
78
|
+
font-weight: normal;
|
79
|
+
opacity: 0.7;
|
80
|
+
}
|
81
|
+
|
82
|
+
slot[name="content-bottom"] {
|
83
|
+
color: red;
|
84
|
+
font-weight: normal;
|
85
|
+
opacity: 0.7;
|
100
86
|
}
|
101
87
|
`
|
102
88
|
}
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import { appendHTML } from '
|
1
|
+
import { appendHTML } from '../utils/dom'
|
2
2
|
import DevtoolElement from './elements/devtool_element'
|
3
3
|
import SupervisorElement from './elements/supervisor_element'
|
4
4
|
import TooltipElement from './elements/tooltip_element'
|
5
|
+
import dependencies from './dependencies'
|
5
6
|
|
6
7
|
customElements.define('reflex-behaviors-devtool', DevtoolElement)
|
7
8
|
customElements.define('reflex-behaviors-devtool-supervisor', SupervisorElement)
|
@@ -9,6 +10,15 @@ customElements.define('reflex-behaviors-devools-tooltip', TooltipElement)
|
|
9
10
|
|
10
11
|
let supervisorElement
|
11
12
|
|
13
|
+
function makeDraggable () {
|
14
|
+
if (!supervisorElement) return
|
15
|
+
try {
|
16
|
+
new PlainDraggable(supervisorElement)
|
17
|
+
} catch {
|
18
|
+
setTimeout(makeDraggable, 200)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
12
22
|
function stop () {
|
13
23
|
if (stopped()) return
|
14
24
|
supervisorElement.close()
|
@@ -18,16 +28,17 @@ function stop () {
|
|
18
28
|
})
|
19
29
|
)
|
20
30
|
supervisorElement = null
|
31
|
+
dependencies.removeAll()
|
21
32
|
}
|
22
33
|
|
23
34
|
function start () {
|
24
35
|
if (started()) return
|
25
|
-
|
36
|
+
dependencies.add(dependencies.LeaderLine)
|
37
|
+
dependencies.add(dependencies.PlainDraggable)
|
38
|
+
supervisorElement = appendHTML(
|
26
39
|
'<reflex-behaviors-devtool-supervisor></reflex-behaviors-devtool-supervisor>'
|
27
40
|
)
|
28
|
-
|
29
|
-
'reflex-behaviors-devtool-supervisor'
|
30
|
-
)
|
41
|
+
setTimeout(makeDraggable, 200)
|
31
42
|
supervisorElement.dispatchEvent(
|
32
43
|
new CustomEvent('reflex-behaviors:devtools-start', {
|
33
44
|
bubbles: true
|
@@ -70,6 +81,7 @@ addEventListener('turbo:load', autoRestart)
|
|
70
81
|
addEventListener('turbo-frame:load', autoRestart)
|
71
82
|
addEventListener('turbo-reflex:success', autoRestart)
|
72
83
|
addEventListener('turbo-reflex:finish', autoRestart)
|
84
|
+
addEventListener('reflex-behaviors:devtools-close', stop)
|
73
85
|
|
74
86
|
function register (name, label) {
|
75
87
|
if (!supervisorElement) return
|
@@ -1,25 +1,27 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
appendHTML,
|
3
|
+
addHighlight,
|
4
|
+
coordinates,
|
5
|
+
removeHighlight
|
6
|
+
} from '../utils/dom'
|
2
7
|
import supervisor from './supervisor'
|
3
8
|
|
9
|
+
let activeToggle
|
10
|
+
|
4
11
|
document.addEventListener('reflex-behaviors:devtools-start', () =>
|
5
12
|
supervisor.register('toggle', 'toggles<small>(trigger/target)</small>')
|
6
13
|
)
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
function appendTooltip (id, title, content, options = {}) {
|
12
|
-
let { backgroundColor, color, emphaisColor, position } = options
|
15
|
+
function appendTooltip (title, content, options = {}) {
|
16
|
+
let { backgroundColor, color, position } = options
|
13
17
|
color = color || 'white'
|
14
18
|
position = position || 'top'
|
15
|
-
|
16
|
-
|
17
|
-
<reflex-behaviors-devools-tooltip id="${id}" position="${position}" background-color="${backgroundColor}" color="${color}" emphasis-color="${emphaisColor}">
|
19
|
+
return appendHTML(`
|
20
|
+
<reflex-behaviors-devools-tooltip position="${position}" background-color="${backgroundColor}" color="${color}">
|
18
21
|
<div slot='title'>${title}</div>
|
19
22
|
${content}
|
20
23
|
</reflex-behaviors-devools-tooltip>
|
21
24
|
`)
|
22
|
-
return document.getElementById(id)
|
23
25
|
}
|
24
26
|
|
25
27
|
export default class ToggleDevtool {
|
@@ -31,8 +33,12 @@ export default class ToggleDevtool {
|
|
31
33
|
|
32
34
|
document.addEventListener('reflex-behaviors:devtool-enable', event => {
|
33
35
|
const { name } = event.detail
|
34
|
-
if (name === this.name)
|
35
|
-
addHighlight(this.trigger, {
|
36
|
+
if (name === this.name) {
|
37
|
+
addHighlight(this.trigger, {
|
38
|
+
outline: '3px dashed blueviolet',
|
39
|
+
outlineOffset: '2px'
|
40
|
+
})
|
41
|
+
}
|
36
42
|
})
|
37
43
|
|
38
44
|
document.addEventListener('reflex-behaviors:devtool-disable', event => {
|
@@ -40,10 +46,15 @@ export default class ToggleDevtool {
|
|
40
46
|
if (name === this.name) removeHighlight(this.trigger)
|
41
47
|
})
|
42
48
|
|
43
|
-
|
49
|
+
addEventListener('click', event => {
|
44
50
|
if (event.target.closest('reflex-behaviors-devools-tooltip')) return
|
45
|
-
this.hide()
|
51
|
+
this.hide(true)
|
46
52
|
})
|
53
|
+
|
54
|
+
addEventListener('turbo:load', () => this.hide(true))
|
55
|
+
addEventListener('turbo-frame:load', () => this.hide(true))
|
56
|
+
addEventListener('turbo-reflex:success', () => this.hide(true))
|
57
|
+
addEventListener('turbo-reflex:finish', () => this.hide(true))
|
47
58
|
}
|
48
59
|
|
49
60
|
get enabled () {
|
@@ -52,33 +63,36 @@ export default class ToggleDevtool {
|
|
52
63
|
|
53
64
|
show () {
|
54
65
|
if (!this.enabled) return
|
66
|
+
if (activeToggle === this) return
|
67
|
+
activeToggle = this
|
55
68
|
this.hide()
|
56
|
-
|
57
|
-
this.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
renderingElement =
|
66
|
-
renderingElement || (this.target ? this.target.renderingElement : null)
|
67
|
-
|
68
|
-
addHighlight(renderingElement, {
|
69
|
-
color: 'turquoise',
|
70
|
-
offset: '4px',
|
71
|
-
width: '4px'
|
69
|
+
|
70
|
+
addHighlight(this.target, {
|
71
|
+
outline: '3px dashed darkcyan',
|
72
|
+
outlineOffset: '-2px'
|
73
|
+
})
|
74
|
+
|
75
|
+
addHighlight(this.renderingElement, {
|
76
|
+
outline: '3px dashed chocolate',
|
77
|
+
outlineOffset: '3px'
|
72
78
|
})
|
73
79
|
|
80
|
+
const renderingTooltip = this.createRenderingTooltip()
|
81
|
+
const targetTooltip = this.createTargetTooltip()
|
82
|
+
this.createTriggerTooltip(targetTooltip, renderingTooltip)
|
83
|
+
|
84
|
+
document
|
85
|
+
.querySelectorAll('.leader-line')
|
86
|
+
.forEach(el => (el.style.zIndex = 100000))
|
87
|
+
|
74
88
|
const data = {
|
75
89
|
rendering: { partial: null, id: null },
|
76
90
|
trigger: { partial: null, id: null },
|
77
91
|
target: { partial: null, id: null }
|
78
92
|
}
|
79
93
|
|
80
|
-
if (renderingPartial) data.rendering.partial = renderingPartial
|
81
|
-
if (renderingElement) data.rendering.id = renderingElement.id
|
94
|
+
if (this.renderingPartial) data.rendering.partial = this.renderingPartial
|
95
|
+
if (this.renderingElement) data.rendering.id = this.renderingElement.id
|
82
96
|
|
83
97
|
if (this.trigger)
|
84
98
|
data.trigger = { partial: this.trigger.partial, id: this.trigger.id }
|
@@ -91,19 +105,8 @@ export default class ToggleDevtool {
|
|
91
105
|
console.table(data)
|
92
106
|
}
|
93
107
|
|
94
|
-
hide () {
|
95
|
-
|
96
|
-
renderingElement =
|
97
|
-
renderingElement || (this.target ? this.target.renderingElement : null)
|
98
|
-
|
99
|
-
this.destroyTriggerTooltip()
|
100
|
-
this.destroyTargetTooltip()
|
101
|
-
removeHighlight(this.target)
|
102
|
-
removeHighlight(renderingElement)
|
103
|
-
this.cleanup()
|
104
|
-
}
|
105
|
-
|
106
|
-
cleanup () {
|
108
|
+
hide (clearActiveToggle) {
|
109
|
+
document.querySelectorAll('.leader-line').forEach(el => el.remove())
|
107
110
|
document
|
108
111
|
.querySelectorAll('reflex-behaviors-devools-tooltip')
|
109
112
|
.forEach(el => el.remove())
|
@@ -113,35 +116,34 @@ export default class ToggleDevtool {
|
|
113
116
|
.forEach(el => {
|
114
117
|
if (!el.tagName.match(/toggle-trigger/i)) removeHighlight(el)
|
115
118
|
})
|
116
|
-
}
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
const title = `TRIGGER (targets: ${this.trigger.controls})`
|
121
|
-
const content = this.trigger.viewStack
|
122
|
-
.map(view => {
|
123
|
-
return this.trigger.sharedViews.includes(view)
|
124
|
-
? `<div slot="emphasis">${view}</div>`
|
125
|
-
: `<div slot="normal">${view}</div>`
|
126
|
-
}, this)
|
127
|
-
.join('')
|
120
|
+
if (clearActiveToggle) activeToggle = null
|
121
|
+
}
|
128
122
|
|
129
|
-
|
130
|
-
|
131
|
-
|
123
|
+
createRenderingTooltip () {
|
124
|
+
if (!this.renderingElement) return
|
125
|
+
const title = `RENDERING (id: ${this.renderingElement.id || 'unknown'})`
|
126
|
+
const content = `<div slot="content">partial: ${this.renderingPartial}</div>`
|
127
|
+
const tooltip = appendTooltip(title, content, {
|
128
|
+
backgroundColor: 'lightyellow',
|
129
|
+
color: 'chocolate'
|
132
130
|
})
|
133
131
|
|
134
|
-
const coords = this.
|
135
|
-
const top = Math.ceil(
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
132
|
+
const coords = coordinates(this.renderingElement)
|
133
|
+
const top = Math.ceil(
|
134
|
+
coords.top + coords.height / 2 - tooltip.offsetHeight / 2
|
135
|
+
)
|
136
|
+
const left = Math.ceil(coords.left + coords.width + 100)
|
137
|
+
tooltip.style.top = `${top}px`
|
138
|
+
tooltip.style.left = `${left}px`
|
139
|
+
|
140
|
+
tooltip.line = new LeaderLine(tooltip, this.renderingElement, {
|
141
|
+
...this.leaderLineOptions,
|
142
|
+
color: 'chocolate'
|
143
|
+
})
|
140
144
|
|
141
|
-
|
142
|
-
|
143
|
-
this.triggerTooltip.remove()
|
144
|
-
delete this.triggerTooltip
|
145
|
+
tooltip.drag = new PlainDraggable(tooltip)
|
146
|
+
return tooltip
|
145
147
|
}
|
146
148
|
|
147
149
|
createTargetTooltip () {
|
@@ -150,29 +152,117 @@ export default class ToggleDevtool {
|
|
150
152
|
|
151
153
|
const title = `TARGET (id: ${this.target.id})`
|
152
154
|
const content = this.target.viewStack
|
153
|
-
.
|
155
|
+
.reverse()
|
156
|
+
.map((view, index) => {
|
154
157
|
return this.trigger.sharedViews.includes(view)
|
155
|
-
? `<div slot="
|
156
|
-
: `<div slot="
|
158
|
+
? `<div slot="content-top">${index + 1}. ${view}</div>`
|
159
|
+
: `<div slot="content-bottom">${index + 1}. ${view}</div>`
|
157
160
|
}, this)
|
158
161
|
.join('')
|
159
162
|
|
160
|
-
|
161
|
-
backgroundColor: '
|
162
|
-
|
163
|
+
const tooltip = appendTooltip(title, content, {
|
164
|
+
backgroundColor: 'lightcyan',
|
165
|
+
color: 'darkcyan',
|
163
166
|
position: 'bottom'
|
164
167
|
})
|
165
168
|
|
166
|
-
const coords = this.target
|
167
|
-
const top = Math.ceil(coords.top +
|
168
|
-
const left = Math.ceil(coords.left
|
169
|
-
|
170
|
-
|
169
|
+
const coords = coordinates(this.target)
|
170
|
+
const top = Math.ceil(coords.top + tooltip.offsetHeight)
|
171
|
+
const left = Math.ceil(coords.left + coords.width + tooltip.offsetWidth / 3)
|
172
|
+
tooltip.style.top = `${top}px`
|
173
|
+
tooltip.style.left = `${left}px`
|
174
|
+
|
175
|
+
tooltip.line = new LeaderLine(tooltip, this.target, {
|
176
|
+
...this.leaderLineOptions,
|
177
|
+
color: 'darkcyan'
|
178
|
+
})
|
179
|
+
|
180
|
+
tooltip.drag = new PlainDraggable(tooltip)
|
181
|
+
return tooltip
|
171
182
|
}
|
172
183
|
|
173
|
-
|
174
|
-
if (!this.
|
175
|
-
this.
|
176
|
-
|
184
|
+
createTriggerTooltip (targetTooltip, renderingTooltip) {
|
185
|
+
if (!this.trigger) return
|
186
|
+
const title = `TRIGGER (controls: ${this.trigger.controls})`
|
187
|
+
const content = this.trigger.viewStack
|
188
|
+
.reverse()
|
189
|
+
.map((view, index) => {
|
190
|
+
return this.trigger.sharedViews.includes(view)
|
191
|
+
? `<div slot="content-top">${index + 1}. ${view}</div>`
|
192
|
+
: `<div slot="content-bottom">${index + 1}. ${view}</div>`
|
193
|
+
}, this)
|
194
|
+
.join('')
|
195
|
+
|
196
|
+
const tooltip = appendTooltip(title, content, {
|
197
|
+
backgroundColor: 'lavender',
|
198
|
+
color: 'blueviolet'
|
199
|
+
})
|
200
|
+
|
201
|
+
const coords = coordinates(this.trigger)
|
202
|
+
const top = Math.ceil(coords.top - tooltip.offsetHeight * 2)
|
203
|
+
const left = Math.ceil(coords.left + coords.width + tooltip.offsetWidth / 3)
|
204
|
+
tooltip.style.top = `${top}px`
|
205
|
+
tooltip.style.left = `${left}px`
|
206
|
+
|
207
|
+
tooltip.line = new LeaderLine(this.trigger, tooltip, {
|
208
|
+
...this.leaderLineOptions,
|
209
|
+
color: 'blueviolet'
|
210
|
+
})
|
211
|
+
|
212
|
+
tooltip.lineToTarget = new LeaderLine(tooltip, targetTooltip, {
|
213
|
+
...this.leaderLineOptions,
|
214
|
+
color: 'blueviolet',
|
215
|
+
middleLabel: 'toggles',
|
216
|
+
size: 2.1
|
217
|
+
})
|
218
|
+
|
219
|
+
tooltip.lineToRendering = new LeaderLine(tooltip, renderingTooltip, {
|
220
|
+
...this.leaderLineOptions,
|
221
|
+
color: 'blueviolet',
|
222
|
+
middleLabel: 'renders',
|
223
|
+
size: 2.1
|
224
|
+
})
|
225
|
+
|
226
|
+
tooltip.drag = new PlainDraggable(tooltip)
|
227
|
+
tooltip.drag.onMove = () => {
|
228
|
+
tooltip.line.position()
|
229
|
+
tooltip.lineToTarget.position()
|
230
|
+
tooltip.lineToRendering.position()
|
231
|
+
}
|
232
|
+
targetTooltip.drag.onMove = () => {
|
233
|
+
targetTooltip.line.position()
|
234
|
+
tooltip.lineToTarget.position()
|
235
|
+
tooltip.lineToRendering.position()
|
236
|
+
}
|
237
|
+
renderingTooltip.drag.onMove = () => {
|
238
|
+
renderingTooltip.line.position()
|
239
|
+
tooltip.lineToTarget.position()
|
240
|
+
tooltip.lineToRendering.position()
|
241
|
+
}
|
242
|
+
return tooltip
|
243
|
+
}
|
244
|
+
|
245
|
+
get renderingPartial () {
|
246
|
+
let partial = this.trigger ? this.trigger.renderingPartial : null
|
247
|
+
partial = partial || (this.target ? this.target.renderingPartial : null)
|
248
|
+
return partial
|
249
|
+
}
|
250
|
+
|
251
|
+
get renderingElement () {
|
252
|
+
let element = this.trigger ? this.trigger.renderingElement : null
|
253
|
+
element = element || (this.target ? this.target.renderingElement : null)
|
254
|
+
return element
|
255
|
+
}
|
256
|
+
|
257
|
+
get leaderLineOptions () {
|
258
|
+
return {
|
259
|
+
dash: { animation: true },
|
260
|
+
dropShadow: { opacity: 0.3 },
|
261
|
+
endPlug: 'arrow3',
|
262
|
+
endPlugSize: 1.7,
|
263
|
+
size: 3,
|
264
|
+
startPlug: 'disc',
|
265
|
+
startPlugSize: 1
|
266
|
+
}
|
177
267
|
}
|
178
268
|
}
|
@@ -34,14 +34,4 @@ export default class ReflexElement extends HTMLElement {
|
|
34
34
|
get partial () {
|
35
35
|
return this.viewStack[0]
|
36
36
|
}
|
37
|
-
|
38
|
-
get coordinates () {
|
39
|
-
const rect = this.getBoundingClientRect()
|
40
|
-
return {
|
41
|
-
left: rect.left + window.scrollX,
|
42
|
-
top: rect.top + window.scrollY,
|
43
|
-
width: this.offsetWidth,
|
44
|
-
height: this.offsetHeight
|
45
|
-
}
|
46
|
-
}
|
47
37
|
}
|