opal-vite 0.2.6 → 0.2.8
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/dom_helpers.rb +4 -86
- data/opal/opal_vite/concerns/js_proxy_ex.rb +4 -411
- data/opal/opal_vite/concerns/react_helpers.rb +4 -312
- data/opal/opal_vite/concerns/stimulus_helpers.rb +4 -1303
- data/opal/opal_vite/concerns/storable.rb +4 -28
- data/opal/opal_vite/concerns/toastable.rb +4 -33
- data/opal/opal_vite/concerns/v1/dom_helpers.rb +89 -0
- data/opal/opal_vite/concerns/v1/js_proxy_ex.rb +414 -0
- data/opal/opal_vite/concerns/v1/react_helpers.rb +315 -0
- data/opal/opal_vite/concerns/v1/stimulus_helpers.rb +1306 -0
- data/opal/opal_vite/concerns/v1/storable.rb +31 -0
- data/opal/opal_vite/concerns/v1/toastable.rb +36 -0
- data/opal/opal_vite/concerns/v1/vue_helpers.rb +249 -0
- data/opal/opal_vite/concerns/v1.rb +8 -0
- data/opal/opal_vite/concerns/vue_helpers.rb +7 -0
- data/opal/opal_vite/concerns.rb +6 -6
- metadata +10 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# backtick_javascript: true
|
|
2
|
+
|
|
3
|
+
module OpalVite
|
|
4
|
+
module Concerns
|
|
5
|
+
# Storable concern - provides LocalStorage functionality
|
|
6
|
+
module Storable
|
|
7
|
+
def storage_get(key)
|
|
8
|
+
stored = `localStorage.getItem(#{key})`
|
|
9
|
+
return nil unless stored
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
`JSON.parse(stored)`
|
|
13
|
+
rescue
|
|
14
|
+
nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def storage_set(key, data)
|
|
19
|
+
json = `JSON.stringify(#{data.to_n})`
|
|
20
|
+
`localStorage.setItem(#{key}, json)`
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def storage_remove(key)
|
|
24
|
+
`localStorage.removeItem(#{key})`
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Alias for backward compatibility
|
|
31
|
+
Storable = OpalVite::Concerns::Storable
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# backtick_javascript: true
|
|
2
|
+
|
|
3
|
+
module OpalVite
|
|
4
|
+
module Concerns
|
|
5
|
+
# Toastable concern - provides toast notification functionality
|
|
6
|
+
module Toastable
|
|
7
|
+
def dispatch_toast(message, type = 'info')
|
|
8
|
+
`
|
|
9
|
+
const event = new CustomEvent('show-toast', {
|
|
10
|
+
detail: { message: #{message}, type: #{type} }
|
|
11
|
+
});
|
|
12
|
+
window.dispatchEvent(event);
|
|
13
|
+
`
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def show_success(message)
|
|
17
|
+
dispatch_toast(message, 'success')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def show_error(message)
|
|
21
|
+
dispatch_toast(message, 'error')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def show_warning(message)
|
|
25
|
+
dispatch_toast(message, 'warning')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def show_info(message)
|
|
29
|
+
dispatch_toast(message, 'info')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Alias for backward compatibility
|
|
36
|
+
Toastable = OpalVite::Concerns::Toastable
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# backtick_javascript: true
|
|
2
|
+
|
|
3
|
+
# VueHelpers - DSL helpers for Vue.js 3 applications with Opal
|
|
4
|
+
# Reduces backtick JavaScript usage in Vue components
|
|
5
|
+
module VueHelpers
|
|
6
|
+
extend self # Makes all methods available as module methods
|
|
7
|
+
# ===================
|
|
8
|
+
# Vue Access
|
|
9
|
+
# ===================
|
|
10
|
+
|
|
11
|
+
# Get Vue from window
|
|
12
|
+
def vue
|
|
13
|
+
`window.Vue`
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Create a Vue application
|
|
17
|
+
# @param options [Hash] Vue component options (data, methods, computed, template, etc.)
|
|
18
|
+
# @return [Native] Vue app instance
|
|
19
|
+
def create_app(options = {})
|
|
20
|
+
Native(`window.Vue.createApp(#{options.to_n})`)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Create a reactive ref
|
|
24
|
+
# @param initial_value [Object] Initial value
|
|
25
|
+
# @return [Native] Vue ref
|
|
26
|
+
def vue_ref(initial_value)
|
|
27
|
+
Native(`window.Vue.ref(#{initial_value})`)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Create a reactive object
|
|
31
|
+
# @param object [Hash] Object to make reactive
|
|
32
|
+
# @return [Native] Vue reactive object
|
|
33
|
+
def vue_reactive(object)
|
|
34
|
+
Native(`window.Vue.reactive(#{object.to_n})`)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Create a computed property
|
|
38
|
+
# @param getter [Proc] Getter function
|
|
39
|
+
# @return [Native] Vue computed ref
|
|
40
|
+
def vue_computed(&getter)
|
|
41
|
+
Native(`window.Vue.computed(#{getter})`)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Watch a reactive source
|
|
45
|
+
# @param source [Native] Reactive source to watch
|
|
46
|
+
# @param callback [Proc] Callback function
|
|
47
|
+
def vue_watch(source, &callback)
|
|
48
|
+
`window.Vue.watch(#{source}, #{callback})`
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# ===================
|
|
52
|
+
# Component Definition Helpers
|
|
53
|
+
# ===================
|
|
54
|
+
|
|
55
|
+
# Define component data as a function
|
|
56
|
+
# @param data_hash [Hash] Initial data
|
|
57
|
+
# @return [Proc] Data function for Vue component
|
|
58
|
+
def data_fn(data_hash)
|
|
59
|
+
-> { data_hash.to_n }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Define methods hash for Vue component
|
|
63
|
+
# @param methods_hash [Hash] Methods with name => proc
|
|
64
|
+
# @return [Hash] Methods object for Vue component
|
|
65
|
+
def methods_obj(methods_hash)
|
|
66
|
+
result = {}
|
|
67
|
+
methods_hash.each do |name, proc|
|
|
68
|
+
result[name] = proc
|
|
69
|
+
end
|
|
70
|
+
result.to_n
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Define computed properties hash
|
|
74
|
+
# @param computed_hash [Hash] Computed properties with name => proc
|
|
75
|
+
# @return [Hash] Computed object for Vue component
|
|
76
|
+
def computed_obj(computed_hash)
|
|
77
|
+
result = {}
|
|
78
|
+
computed_hash.each do |name, proc|
|
|
79
|
+
result[name] = proc
|
|
80
|
+
end
|
|
81
|
+
result.to_n
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# ===================
|
|
85
|
+
# Lifecycle Hooks
|
|
86
|
+
# ===================
|
|
87
|
+
|
|
88
|
+
# onMounted hook
|
|
89
|
+
def on_mounted(&block)
|
|
90
|
+
`window.Vue.onMounted(#{block})`
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# onUnmounted hook
|
|
94
|
+
def on_unmounted(&block)
|
|
95
|
+
`window.Vue.onUnmounted(#{block})`
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# onUpdated hook
|
|
99
|
+
def on_updated(&block)
|
|
100
|
+
`window.Vue.onUpdated(#{block})`
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# onBeforeMount hook
|
|
104
|
+
def on_before_mount(&block)
|
|
105
|
+
`window.Vue.onBeforeMount(#{block})`
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# onBeforeUnmount hook
|
|
109
|
+
def on_before_unmount(&block)
|
|
110
|
+
`window.Vue.onBeforeUnmount(#{block})`
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# ===================
|
|
114
|
+
# Window/Global Access
|
|
115
|
+
# ===================
|
|
116
|
+
|
|
117
|
+
# Get a property from window
|
|
118
|
+
def window_get(key)
|
|
119
|
+
`window[#{key}]`
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Set a property on window
|
|
123
|
+
def window_set(key, value)
|
|
124
|
+
`window[#{key}] = #{value}`
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# ===================
|
|
128
|
+
# Console
|
|
129
|
+
# ===================
|
|
130
|
+
|
|
131
|
+
# Console log
|
|
132
|
+
def console_log(*args)
|
|
133
|
+
`console.log(...#{args})`
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Console warn
|
|
137
|
+
def console_warn(*args)
|
|
138
|
+
`console.warn(...#{args})`
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Console error
|
|
142
|
+
def console_error(*args)
|
|
143
|
+
`console.error(...#{args})`
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# ===================
|
|
147
|
+
# DOM Events
|
|
148
|
+
# ===================
|
|
149
|
+
|
|
150
|
+
# Execute block when DOM is ready
|
|
151
|
+
def on_dom_ready(&block)
|
|
152
|
+
`document.addEventListener('DOMContentLoaded', #{block})`
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# ===================
|
|
156
|
+
# DOM Query
|
|
157
|
+
# ===================
|
|
158
|
+
|
|
159
|
+
# Query single element
|
|
160
|
+
def query(selector)
|
|
161
|
+
`document.querySelector(#{selector})`
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Query all elements
|
|
165
|
+
def query_all(selector)
|
|
166
|
+
`Array.from(document.querySelectorAll(#{selector}))`
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Get element by ID
|
|
170
|
+
def get_element_by_id(id)
|
|
171
|
+
`document.getElementById(#{id})`
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# ===================
|
|
175
|
+
# Timing
|
|
176
|
+
# ===================
|
|
177
|
+
|
|
178
|
+
# Set timeout
|
|
179
|
+
def set_timeout(delay_ms, &block)
|
|
180
|
+
`setTimeout(#{block}, #{delay_ms})`
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Set interval
|
|
184
|
+
def set_interval(interval_ms, &block)
|
|
185
|
+
`setInterval(#{block}, #{interval_ms})`
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Clear timeout
|
|
189
|
+
def clear_timeout(timeout_id)
|
|
190
|
+
`clearTimeout(#{timeout_id})`
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Clear interval
|
|
194
|
+
def clear_interval(interval_id)
|
|
195
|
+
`clearInterval(#{interval_id})`
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# ===================
|
|
199
|
+
# LocalStorage
|
|
200
|
+
# ===================
|
|
201
|
+
|
|
202
|
+
# Get from localStorage
|
|
203
|
+
def storage_get(key)
|
|
204
|
+
`localStorage.getItem(#{key})`
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Set to localStorage
|
|
208
|
+
def storage_set(key, value)
|
|
209
|
+
`localStorage.setItem(#{key}, #{value})`
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Remove from localStorage
|
|
213
|
+
def storage_remove(key)
|
|
214
|
+
`localStorage.removeItem(#{key})`
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# ===================
|
|
218
|
+
# JSON
|
|
219
|
+
# ===================
|
|
220
|
+
|
|
221
|
+
# Parse JSON string
|
|
222
|
+
def parse_json(json_string)
|
|
223
|
+
`JSON.parse(#{json_string})`
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# Stringify to JSON
|
|
227
|
+
def to_json_string(object)
|
|
228
|
+
`JSON.stringify(#{object})`
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# ===================
|
|
232
|
+
# Type Conversion
|
|
233
|
+
# ===================
|
|
234
|
+
|
|
235
|
+
# Parse string to integer
|
|
236
|
+
def parse_int(value, radix = 10)
|
|
237
|
+
`parseInt(#{value}, #{radix})`
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# Parse string to float
|
|
241
|
+
def parse_float(value)
|
|
242
|
+
`parseFloat(#{value})`
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# Check if value is NaN
|
|
246
|
+
def is_nan?(value)
|
|
247
|
+
`Number.isNaN(#{value})`
|
|
248
|
+
end
|
|
249
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Load all OpalVite concerns (v1)
|
|
2
|
+
require 'opal_vite/concerns/v1/js_proxy_ex'
|
|
3
|
+
require 'opal_vite/concerns/v1/dom_helpers'
|
|
4
|
+
require 'opal_vite/concerns/v1/toastable'
|
|
5
|
+
require 'opal_vite/concerns/v1/storable'
|
|
6
|
+
require 'opal_vite/concerns/v1/stimulus_helpers'
|
|
7
|
+
require 'opal_vite/concerns/v1/vue_helpers'
|
|
8
|
+
require 'opal_vite/concerns/v1/react_helpers'
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# backtick_javascript: true
|
|
2
|
+
# Backward compatibility wrapper - delegates to v1
|
|
3
|
+
require 'opal_vite/concerns/v1/vue_helpers'
|
|
4
|
+
|
|
5
|
+
`console.warn("[DEPRECATION] require 'opal_vite/concerns/vue_helpers' is deprecated. Please use require 'opal_vite/concerns/v1/vue_helpers' instead.")`
|
|
6
|
+
|
|
7
|
+
# Module is already defined by v1, re-exported for backward compatibility
|
data/opal/opal_vite/concerns.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require 'opal_vite/concerns/
|
|
5
|
-
|
|
6
|
-
require 'opal_vite/concerns/
|
|
1
|
+
# backtick_javascript: true
|
|
2
|
+
# Backward compatibility wrapper - delegates to v1
|
|
3
|
+
# Load all OpalVite concerns (deprecated - use opal_vite/concerns/v1 instead)
|
|
4
|
+
require 'opal_vite/concerns/v1'
|
|
5
|
+
|
|
6
|
+
`console.warn("[DEPRECATION] require 'opal_vite/concerns' is deprecated. Please use require 'opal_vite/concerns/v1' instead.")`
|
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.2.
|
|
4
|
+
version: 0.2.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- stofu1234
|
|
@@ -119,6 +119,15 @@ files:
|
|
|
119
119
|
- opal/opal_vite/concerns/stimulus_helpers.rb
|
|
120
120
|
- opal/opal_vite/concerns/storable.rb
|
|
121
121
|
- opal/opal_vite/concerns/toastable.rb
|
|
122
|
+
- opal/opal_vite/concerns/v1.rb
|
|
123
|
+
- opal/opal_vite/concerns/v1/dom_helpers.rb
|
|
124
|
+
- opal/opal_vite/concerns/v1/js_proxy_ex.rb
|
|
125
|
+
- opal/opal_vite/concerns/v1/react_helpers.rb
|
|
126
|
+
- opal/opal_vite/concerns/v1/stimulus_helpers.rb
|
|
127
|
+
- opal/opal_vite/concerns/v1/storable.rb
|
|
128
|
+
- opal/opal_vite/concerns/v1/toastable.rb
|
|
129
|
+
- opal/opal_vite/concerns/v1/vue_helpers.rb
|
|
130
|
+
- opal/opal_vite/concerns/vue_helpers.rb
|
|
122
131
|
homepage: https://github.com/stofu1234/opal-vite
|
|
123
132
|
licenses:
|
|
124
133
|
- MIT
|