vident 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/vident/base.rb +6 -1
- data/lib/vident/root_component.rb +15 -3
- data/lib/vident/stable_id.rb +12 -3
- data/lib/vident/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a56c925065ab67c7c41493cd5ab9a1c19fedde171ebc2fcc60477359318ef258
|
4
|
+
data.tar.gz: 595d0ae7292a2548aece9749cbd7dc4e8f177faa6ea49aebfe90a1864c0014ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0ee94c716fee4aa83d496beac7f2d7053e82742006ca1483dbd6ba38ba5ec32fc6f8c8b9f0ca691b05ff2c42947f52aa7937a35c5aef6cfd1bacc6454a7d90c
|
7
|
+
data.tar.gz: 399b0db4d117ee191f871eb5bb23d5419065ca083a58ba778e9a871839e9de1950837868b4b4043a8d72b7e97f18138678f41ef12813905543bc4c4a1619428a
|
data/CHANGELOG.md
CHANGED
@@ -14,6 +14,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
14
14
|
|
15
15
|
### Fixed
|
16
16
|
|
17
|
+
## [0.10.1] - 2024-02-21
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
- `outlets` option now accepts either a string stimulus controller identifier, a component instance, or a tuple of
|
22
|
+
identifier and CSS selector for the outlet.
|
23
|
+
|
24
|
+
|
17
25
|
## [0.10.0] - 2024-02-21
|
18
26
|
|
19
27
|
### Added
|
data/lib/vident/base.rb
CHANGED
@@ -80,6 +80,11 @@ module Vident
|
|
80
80
|
@id.presence || random_id
|
81
81
|
end
|
82
82
|
|
83
|
+
# If connecting an outlet to this specific component instance, use this ID
|
84
|
+
def outlet_id
|
85
|
+
@outlet_id ||= [stimulus_identifier, "##{id}"]
|
86
|
+
end
|
87
|
+
|
83
88
|
# Methods to use in component views
|
84
89
|
# ---------------------------------
|
85
90
|
|
@@ -185,7 +190,7 @@ module Vident
|
|
185
190
|
end
|
186
191
|
|
187
192
|
def random_id
|
188
|
-
@random_id ||= "#{
|
193
|
+
@random_id ||= "#{component_class_name}-#{StableId.next_id_in_sequence}"
|
189
194
|
end
|
190
195
|
|
191
196
|
CLASSNAME_SEPARATOR = " "
|
@@ -133,7 +133,19 @@ module Vident
|
|
133
133
|
|
134
134
|
def outlet_list
|
135
135
|
return {} unless @outlets&.size&.positive?
|
136
|
-
|
136
|
+
|
137
|
+
@outlets.each_with_object({}) do |outlet_config, obj|
|
138
|
+
identifier, css_selector = if outlet_config.is_a?(String)
|
139
|
+
[outlet_config, "[data-controller~=#{outlet_config}]"]
|
140
|
+
elsif outlet_config.is_a?(Array)
|
141
|
+
outlet_config[..1]
|
142
|
+
elsif respond_to?(:stimulus_identifier)
|
143
|
+
[outlet_config.stimulus_identifier, "[data-controller~=#{outlet_config.stimulus_identifier}]"]
|
144
|
+
else
|
145
|
+
raise ArgumentError, "Invalid outlet config: #{outlet_config}"
|
146
|
+
end
|
147
|
+
obj[:"#{implied_controller_name}-#{identifier}-outlet"] = css_selector
|
148
|
+
end
|
137
149
|
end
|
138
150
|
|
139
151
|
# Actions can be specified as a symbol, in which case they imply an action on the primary
|
@@ -189,7 +201,7 @@ module Vident
|
|
189
201
|
end
|
190
202
|
|
191
203
|
def parse_attributes(attrs, controller = nil)
|
192
|
-
attrs.transform_keys { |k| "#{controller || implied_controller_name}-#{k}" }
|
204
|
+
attrs.transform_keys { |k| :"#{controller || implied_controller_name}-#{k}" }
|
193
205
|
end
|
194
206
|
|
195
207
|
def data_map_attributes
|
@@ -219,7 +231,7 @@ module Vident
|
|
219
231
|
|
220
232
|
def build_named_classes_data_attributes(named_classes)
|
221
233
|
parse_named_classes_hash(named_classes)
|
222
|
-
.map { |c| ["#{c[:controller]}-#{c[:name]}-class", c[:classes]] }
|
234
|
+
.map { |c| [:"#{c[:controller]}-#{c[:name]}-class", c[:classes]] }
|
223
235
|
.to_h
|
224
236
|
end
|
225
237
|
|
data/lib/vident/stable_id.rb
CHANGED
@@ -1,23 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "random/formatter"
|
4
|
+
|
3
5
|
module Vident
|
4
6
|
class StableId
|
5
7
|
class << self
|
6
8
|
def set_current_sequence_generator
|
7
9
|
::Thread.current[:vident_number_sequence_generator] = id_sequence_generator
|
8
10
|
end
|
11
|
+
alias_method :new_current_sequence_generator, :set_current_sequence_generator
|
12
|
+
|
13
|
+
def clear_current_sequence_generator
|
14
|
+
::Thread.current[:vident_number_sequence_generator] = nil
|
15
|
+
end
|
9
16
|
|
10
17
|
def next_id_in_sequence
|
11
18
|
generator = ::Thread.current[:vident_number_sequence_generator]
|
12
|
-
|
19
|
+
# When no generator exists, use a random value. This means we loose the stability of the ID sequence but
|
20
|
+
# at least generate unique IDs for the current render.
|
21
|
+
return Random.hex(16) unless generator
|
13
22
|
generator.next.join("-")
|
14
23
|
end
|
15
24
|
|
16
25
|
private
|
17
26
|
|
18
27
|
def id_sequence_generator
|
19
|
-
number_generator = Random.new(
|
20
|
-
Enumerator.produce { number_generator.
|
28
|
+
number_generator = Random.new(42)
|
29
|
+
Enumerator.produce { number_generator.hex(16) }.with_index
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
data/lib/vident/version.rb
CHANGED