opal-vite 0.2.6 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19c908ad19445dc3ca95af2873ad94c885fd3546de85a78005cf3d45a10c2b7f
4
- data.tar.gz: 10fd5fb0daf18cf0eeb466079307eb6f47f913c4e7e1e7031c7d7944beff4cb2
3
+ metadata.gz: d647a605d1362c318322a04e13412cb9bb298fff93d9d2892b96afdc7170fc6b
4
+ data.tar.gz: 0a72ac91f6973d02587de1b63ec63052fce19519138ece126e7f9edd40af8c56
5
5
  SHA512:
6
- metadata.gz: 0fca963918760eb442d55982d5de06875ed92293ad58a0d422f095f4e72bf2181ebbdb4ea99bdd978473d860b5f2948d98e92550938df0e7310fd707e94228b2
7
- data.tar.gz: 6016bfab349b9b24af874cdf416bbc2dde40e6e106c30ce18157c609d7de418f1935c79d6fe782d75cb3ff03d49385f1c4b93994baf77e5e45aea90b834e3e1c
6
+ metadata.gz: 508a5e5f69a85c218c2ccf2f451140080860885a00d041909a5da09c9a7d755ba369ba6ecc10f2c4ed84c31a4491103495ec0afa022f9abfb6d2d8d349c16f7b
7
+ data.tar.gz: 4b84a15c0db47b794d0bb50a1eba4e6b78df5683f0fbf281d5e05f7f14ab2fb016ad59591b37b846b62125cc7035541e31772140a8c41e91285c628531e810ed
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Vite
3
- VERSION = "0.2.6"
3
+ VERSION = "0.2.7"
4
4
  end
5
5
  end
@@ -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
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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - stofu1234
@@ -119,6 +119,7 @@ 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/vue_helpers.rb
122
123
  homepage: https://github.com/stofu1234/opal-vite
123
124
  licenses:
124
125
  - MIT