opal-vite 0.3.2 → 0.3.3
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/lib/opal/vite/version.rb +1 -1
- data/opal/opal_vite/concerns/v1/debug_helpers.rb +234 -0
- data/opal/opal_vite/concerns/v1.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '009e15bfd7bc8509c7e6dc12d945c6138bf14c86b50c933c246fea83516fa893'
|
|
4
|
+
data.tar.gz: 2e44cfd7e86f661d3b10c355d08a63303f75fd4ff28c3b63471fb8a7f9252fa5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d0220cc638f3865580bb29cc72a2a40a24c3b0c03ed477f985ac19b229a81d5ae083b58c02aefd4a6ab2a02287af7c80182e85d1d35df6056f6060548743d05
|
|
7
|
+
data.tar.gz: 5ec45efb48c602f941bc104ea94eb464ce9cc2bac24ee24bac7ea4453c5481fedd368418dd8b077a4f1ca424766f2f52b29e7430e9ab56b4621ad70a52fc4b95
|
data/lib/opal/vite/version.rb
CHANGED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# backtick_javascript: true
|
|
2
|
+
|
|
3
|
+
module OpalVite
|
|
4
|
+
module Concerns
|
|
5
|
+
module V1
|
|
6
|
+
# DebugHelpers concern - provides debugging utilities for Opal applications
|
|
7
|
+
# Outputs structured debug information to browser console
|
|
8
|
+
module DebugHelpers
|
|
9
|
+
# Log a debug message with optional data
|
|
10
|
+
# @param message [String] The message to log
|
|
11
|
+
# @param data [Object] Optional data to include
|
|
12
|
+
def debug_log(message, data = nil)
|
|
13
|
+
return unless debug_enabled?
|
|
14
|
+
|
|
15
|
+
if data
|
|
16
|
+
`console.log('[DEBUG] ' + #{message}, #{data.to_n})`
|
|
17
|
+
else
|
|
18
|
+
`console.log('[DEBUG] ' + #{message})`
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Log a warning message
|
|
23
|
+
# @param message [String] The warning message
|
|
24
|
+
# @param data [Object] Optional data to include
|
|
25
|
+
def debug_warn(message, data = nil)
|
|
26
|
+
return unless debug_enabled?
|
|
27
|
+
|
|
28
|
+
if data
|
|
29
|
+
`console.warn('[WARN] ' + #{message}, #{data.to_n})`
|
|
30
|
+
else
|
|
31
|
+
`console.warn('[WARN] ' + #{message})`
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Log an error message
|
|
36
|
+
# @param message [String] The error message
|
|
37
|
+
# @param error [Object] Optional error object or data
|
|
38
|
+
def debug_error(message, error = nil)
|
|
39
|
+
if error
|
|
40
|
+
`console.error('[ERROR] ' + #{message}, #{error.to_n})`
|
|
41
|
+
else
|
|
42
|
+
`console.error('[ERROR] ' + #{message})`
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Log a group of related debug messages
|
|
47
|
+
# @param label [String] Group label
|
|
48
|
+
# @yield Block containing debug_log calls
|
|
49
|
+
def debug_group(label)
|
|
50
|
+
return yield unless debug_enabled?
|
|
51
|
+
|
|
52
|
+
`console.group('[DEBUG] ' + #{label})`
|
|
53
|
+
yield
|
|
54
|
+
`console.groupEnd()`
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Log a collapsed group of related debug messages
|
|
58
|
+
# @param label [String] Group label
|
|
59
|
+
# @yield Block containing debug_log calls
|
|
60
|
+
def debug_group_collapsed(label)
|
|
61
|
+
return yield unless debug_enabled?
|
|
62
|
+
|
|
63
|
+
`console.groupCollapsed('[DEBUG] ' + #{label})`
|
|
64
|
+
yield
|
|
65
|
+
`console.groupEnd()`
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Start a performance timer
|
|
69
|
+
# @param label [String] Timer label
|
|
70
|
+
def debug_time(label)
|
|
71
|
+
return unless debug_enabled?
|
|
72
|
+
`console.time('[TIMER] ' + #{label})`
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# End a performance timer and log the elapsed time
|
|
76
|
+
# @param label [String] Timer label (must match the one used in debug_time)
|
|
77
|
+
def debug_time_end(label)
|
|
78
|
+
return unless debug_enabled?
|
|
79
|
+
`console.timeEnd('[TIMER] ' + #{label})`
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Log a table of data (useful for arrays/objects)
|
|
83
|
+
# @param data [Array, Hash] Data to display as table
|
|
84
|
+
def debug_table(data)
|
|
85
|
+
return unless debug_enabled?
|
|
86
|
+
`console.table(#{data.to_n})`
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Log object inspection with Ruby-style formatting
|
|
90
|
+
# @param obj [Object] Object to inspect
|
|
91
|
+
# @param label [String] Optional label
|
|
92
|
+
def debug_inspect(obj, label = nil)
|
|
93
|
+
return unless debug_enabled?
|
|
94
|
+
|
|
95
|
+
inspected = obj.inspect
|
|
96
|
+
if label
|
|
97
|
+
`console.log('[INSPECT] ' + #{label} + ':', #{inspected})`
|
|
98
|
+
else
|
|
99
|
+
`console.log('[INSPECT]', #{inspected})`
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Log the current call stack
|
|
104
|
+
# @param message [String] Optional message
|
|
105
|
+
def debug_trace(message = nil)
|
|
106
|
+
return unless debug_enabled?
|
|
107
|
+
|
|
108
|
+
if message
|
|
109
|
+
`console.trace('[TRACE] ' + #{message})`
|
|
110
|
+
else
|
|
111
|
+
`console.trace('[TRACE]')`
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Assert a condition and log error if false
|
|
116
|
+
# @param condition [Boolean] Condition to check
|
|
117
|
+
# @param message [String] Message to show if assertion fails
|
|
118
|
+
def debug_assert(condition, message = 'Assertion failed')
|
|
119
|
+
`console.assert(#{condition}, '[ASSERT] ' + #{message})`
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Count and log how many times this is called with the given label
|
|
123
|
+
# @param label [String] Counter label
|
|
124
|
+
def debug_count(label = 'default')
|
|
125
|
+
return unless debug_enabled?
|
|
126
|
+
`console.count('[COUNT] ' + #{label})`
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Reset the counter for the given label
|
|
130
|
+
# @param label [String] Counter label
|
|
131
|
+
def debug_count_reset(label = 'default')
|
|
132
|
+
return unless debug_enabled?
|
|
133
|
+
`console.countReset('[COUNT] ' + #{label})`
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Check if debugging is enabled
|
|
137
|
+
# Override this method to control debug output
|
|
138
|
+
# @return [Boolean] true if debugging is enabled
|
|
139
|
+
def debug_enabled?
|
|
140
|
+
# Check for debug flag in multiple places
|
|
141
|
+
return @debug_enabled unless @debug_enabled.nil?
|
|
142
|
+
|
|
143
|
+
# Check window.OPAL_DEBUG or localStorage debug setting
|
|
144
|
+
@debug_enabled = `
|
|
145
|
+
(typeof window !== 'undefined' &&
|
|
146
|
+
(window.OPAL_DEBUG === true ||
|
|
147
|
+
(typeof localStorage !== 'undefined' &&
|
|
148
|
+
localStorage.getItem('opal_debug') === 'true')))
|
|
149
|
+
`
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Enable debugging
|
|
153
|
+
def debug_enable!
|
|
154
|
+
@debug_enabled = true
|
|
155
|
+
`
|
|
156
|
+
if (typeof window !== 'undefined') {
|
|
157
|
+
window.OPAL_DEBUG = true;
|
|
158
|
+
if (typeof localStorage !== 'undefined') {
|
|
159
|
+
localStorage.setItem('opal_debug', 'true');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
`
|
|
163
|
+
debug_log('Debug mode enabled')
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Disable debugging
|
|
167
|
+
def debug_disable!
|
|
168
|
+
debug_log('Debug mode disabled')
|
|
169
|
+
@debug_enabled = false
|
|
170
|
+
`
|
|
171
|
+
if (typeof window !== 'undefined') {
|
|
172
|
+
window.OPAL_DEBUG = false;
|
|
173
|
+
if (typeof localStorage !== 'undefined') {
|
|
174
|
+
localStorage.removeItem('opal_debug');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
`
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Measure execution time of a block
|
|
181
|
+
# @param label [String] Label for the measurement
|
|
182
|
+
# @yield Block to measure
|
|
183
|
+
# @return [Object] Return value of the block
|
|
184
|
+
def debug_measure(label)
|
|
185
|
+
return yield unless debug_enabled?
|
|
186
|
+
|
|
187
|
+
start_time = `performance.now()`
|
|
188
|
+
result = yield
|
|
189
|
+
end_time = `performance.now()`
|
|
190
|
+
duration = end_time - start_time
|
|
191
|
+
|
|
192
|
+
`console.log('[PERF] ' + #{label} + ': ' + #{duration.round(2)} + 'ms')`
|
|
193
|
+
result
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Log Stimulus controller connection info
|
|
197
|
+
# @param controller [Object] Stimulus controller instance
|
|
198
|
+
def debug_stimulus_connect(controller = nil)
|
|
199
|
+
return unless debug_enabled?
|
|
200
|
+
|
|
201
|
+
ctrl = controller || self
|
|
202
|
+
name = ctrl.class.respond_to?(:stimulus_name) ? ctrl.class.stimulus_name : ctrl.class.name
|
|
203
|
+
`console.log('[STIMULUS] Connected:', #{name})`
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# Log Stimulus controller disconnection info
|
|
207
|
+
# @param controller [Object] Stimulus controller instance
|
|
208
|
+
def debug_stimulus_disconnect(controller = nil)
|
|
209
|
+
return unless debug_enabled?
|
|
210
|
+
|
|
211
|
+
ctrl = controller || self
|
|
212
|
+
name = ctrl.class.respond_to?(:stimulus_name) ? ctrl.class.stimulus_name : ctrl.class.name
|
|
213
|
+
`console.log('[STIMULUS] Disconnected:', #{name})`
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Log Stimulus action info
|
|
217
|
+
# @param action_name [String] Name of the action
|
|
218
|
+
# @param event [Object] Event object
|
|
219
|
+
def debug_stimulus_action(action_name, event = nil)
|
|
220
|
+
return unless debug_enabled?
|
|
221
|
+
|
|
222
|
+
if event
|
|
223
|
+
`console.log('[STIMULUS] Action:', #{action_name}, 'Event:', #{event.to_n})`
|
|
224
|
+
else
|
|
225
|
+
`console.log('[STIMULUS] Action:', #{action_name})`
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Alias for backward compatibility
|
|
234
|
+
DebugHelpers = OpalVite::Concerns::V1::DebugHelpers
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opal-vite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- stofu1234
|
|
@@ -121,6 +121,7 @@ files:
|
|
|
121
121
|
- opal/opal_vite/concerns/toastable.rb
|
|
122
122
|
- opal/opal_vite/concerns/v1.rb
|
|
123
123
|
- opal/opal_vite/concerns/v1/base64_helpers.rb
|
|
124
|
+
- opal/opal_vite/concerns/v1/debug_helpers.rb
|
|
124
125
|
- opal/opal_vite/concerns/v1/dom_helpers.rb
|
|
125
126
|
- opal/opal_vite/concerns/v1/js_proxy_ex.rb
|
|
126
127
|
- opal/opal_vite/concerns/v1/react_helpers.rb
|