reflex_behaviors 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,15 +46,21 @@ export default class ToggleDevtool {
46
46
  if (name === this.name) removeHighlight(this.trigger)
47
47
  })
48
48
 
49
+ let hideTimeout
50
+ const debouncedHide = () => {
51
+ clearTimeout(hideTimeout)
52
+ hideTimeout = setTimeout(this.hide(true), 25)
53
+ }
54
+
49
55
  addEventListener('click', event => {
50
56
  if (event.target.closest('reflex-behaviors-devools-tooltip')) return
51
- this.hide(true)
57
+ debouncedHide()
52
58
  })
53
59
 
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))
60
+ addEventListener('turbo:load', debouncedHide)
61
+ addEventListener('turbo-frame:load', debouncedHide)
62
+ addEventListener('turbo-reflex:success', debouncedHide)
63
+ addEventListener('turbo-reflex:finish', debouncedHide)
58
64
  }
59
65
 
60
66
  get enabled () {
@@ -72,7 +78,7 @@ export default class ToggleDevtool {
72
78
  outlineOffset: '-2px'
73
79
  })
74
80
 
75
- addHighlight(this.renderingElement, {
81
+ addHighlight(this.trigger.renderingElement, {
76
82
  outline: '3px dashed chocolate',
77
83
  outlineOffset: '3px'
78
84
  })
@@ -86,21 +92,28 @@ export default class ToggleDevtool {
86
92
  .forEach(el => (el.style.zIndex = 100000))
87
93
 
88
94
  const data = {
89
- rendering: { partial: null, id: null },
90
- trigger: { partial: null, id: null },
91
- target: { partial: null, id: null }
95
+ rendering: {
96
+ partial: this.trigger.renderingPartial,
97
+ id: this.trigger.renderingInfo.id,
98
+ status: this.trigger.renderingElement ? 'OK' : 'Not Found'
99
+ },
100
+ trigger: { partial: null, id: null, status: 'Not Found' },
101
+ target: { partial: null, id: null, status: 'Not Found' }
92
102
  }
93
103
 
94
- if (this.renderingPartial) data.rendering.partial = this.renderingPartial
95
- if (this.renderingElement) data.rendering.id = this.renderingElement.id
96
-
97
104
  if (this.trigger)
98
- data.trigger = { partial: this.trigger.partial, id: this.trigger.id }
105
+ data.trigger = {
106
+ partial: this.trigger.partial,
107
+ id: this.trigger.id,
108
+ status: 'OK'
109
+ }
99
110
 
100
111
  if (this.target)
101
- data.target = { partial: this.target.partial, id: this.target.id }
102
- else if (this.trigger)
103
- data.target.id = `No element matches the targeted DOM id: ${this.trigger.controls}`
112
+ data.target = {
113
+ partial: this.target.partial,
114
+ id: this.target.id,
115
+ status: 'OK'
116
+ }
104
117
 
105
118
  console.table(data)
106
119
  }
@@ -121,15 +134,20 @@ export default class ToggleDevtool {
121
134
  }
122
135
 
123
136
  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>`
137
+ if (!this.trigger.renderingElement)
138
+ return console.debug(
139
+ `Unable to create the rendering tooltip! No element matches the DOM id: '${this.trigger.renderingInfo.id}'`
140
+ )
141
+
142
+ const title = `RENDERING (id: ${this.trigger.renderingElement.id ||
143
+ 'unknown'})`
144
+ const content = `<div slot="content">partial: ${this.trigger.renderingPartial}</div>`
127
145
  const tooltip = appendTooltip(title, content, {
128
146
  backgroundColor: 'lightyellow',
129
147
  color: 'chocolate'
130
148
  })
131
149
 
132
- const coords = coordinates(this.renderingElement)
150
+ const coords = coordinates(this.trigger.renderingElement)
133
151
  const top = Math.ceil(
134
152
  coords.top + coords.height / 2 - tooltip.offsetHeight / 2
135
153
  )
@@ -137,7 +155,7 @@ export default class ToggleDevtool {
137
155
  tooltip.style.top = `${top}px`
138
156
  tooltip.style.left = `${left}px`
139
157
 
140
- tooltip.line = new LeaderLine(tooltip, this.renderingElement, {
158
+ tooltip.line = new LeaderLine(tooltip, this.trigger.renderingElement, {
141
159
  ...this.leaderLineOptions,
142
160
  color: 'chocolate'
143
161
  })
@@ -147,8 +165,10 @@ export default class ToggleDevtool {
147
165
  }
148
166
 
149
167
  createTargetTooltip () {
150
- if (!this.target) return
151
- if (!this.target.viewStack) return
168
+ if (!this.target)
169
+ return console.debug(
170
+ `Unable to create the target tooltip! No element matches the DOM id: '${this.trigger.controls}'`
171
+ )
152
172
 
153
173
  const title = `TARGET (id: ${this.target.id})`
154
174
  const content = this.target.viewStack
@@ -209,49 +229,44 @@ export default class ToggleDevtool {
209
229
  color: 'blueviolet'
210
230
  })
211
231
 
212
- tooltip.lineToTarget = new LeaderLine(tooltip, targetTooltip, {
213
- ...this.leaderLineOptions,
214
- color: 'blueviolet',
215
- middleLabel: 'toggles',
216
- size: 2.1
217
- })
232
+ if (targetTooltip) {
233
+ tooltip.lineToTarget = new LeaderLine(tooltip, targetTooltip, {
234
+ ...this.leaderLineOptions,
235
+ color: 'blueviolet',
236
+ middleLabel: 'toggles',
237
+ size: 2.1
238
+ })
218
239
 
219
- tooltip.lineToRendering = new LeaderLine(tooltip, renderingTooltip, {
220
- ...this.leaderLineOptions,
221
- color: 'blueviolet',
222
- middleLabel: 'renders',
223
- size: 2.1
224
- })
240
+ targetTooltip.drag.onMove = () => {
241
+ targetTooltip.line.position()
242
+ tooltip.lineToTarget.position()
243
+ tooltip.lineToRendering.position()
244
+ }
245
+ }
246
+
247
+ if (renderingTooltip) {
248
+ tooltip.lineToRendering = new LeaderLine(tooltip, renderingTooltip, {
249
+ ...this.leaderLineOptions,
250
+ color: 'blueviolet',
251
+ middleLabel: 'renders',
252
+ size: 2.1
253
+ })
254
+
255
+ renderingTooltip.drag.onMove = () => {
256
+ renderingTooltip.line.position()
257
+ if (tooltip.lineToTarget) tooltip.lineToTarget.position()
258
+ tooltip.lineToRendering.position()
259
+ }
260
+ }
225
261
 
226
262
  tooltip.drag = new PlainDraggable(tooltip)
227
263
  tooltip.drag.onMove = () => {
228
264
  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()
265
+ if (tooltip.lineToTarget) tooltip.lineToTarget.position()
266
+ if (tooltip.lineToRendering) tooltip.lineToRendering.position()
236
267
  }
237
- renderingTooltip.drag.onMove = () => {
238
- renderingTooltip.line.position()
239
- tooltip.lineToTarget.position()
240
- tooltip.lineToRendering.position()
241
- }
242
- return tooltip
243
- }
244
268
 
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
269
+ return tooltip
255
270
  }
256
271
 
257
272
  get leaderLineOptions () {
@@ -52,6 +52,7 @@ export function removeHighlight (element) {
52
52
  }
53
53
 
54
54
  export function coordinates (element) {
55
+ if (!element) return {}
55
56
  const rect = element.getBoundingClientRect()
56
57
  return {
57
58
  left: rect.left + window.scrollX,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReflexBehaviors
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.8"
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reflex_behaviors",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Pre-built easy to use reactive TurboReflex behaviors for Rails/Hotwire apps.",
5
5
  "main": "app/javascript/index.js",
6
6
  "repository": "https://github.com/hopsoft/reflex_behaviors",