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