opal-vite 0.2.8 → 0.2.9

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