coupdoeil 1.1.1 → 1.2.1
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/CHANGELOG.md +24 -2
- data/README.md +2 -2
- data/app/assets/javascripts/coupdoeil.js +143 -57
- data/app/assets/javascripts/coupdoeil.min.js +1 -1
- data/app/assets/javascripts/coupdoeil.min.js.map +1 -1
- data/app/controllers/coupdoeil/popovers_controller.rb +4 -15
- data/app/helpers/coupdoeil/application_helper.rb +13 -0
- data/app/javascript/coupdoeil/elements/coupdoeil_element.js +41 -1
- data/app/javascript/coupdoeil/events/onclick.js +4 -2
- data/app/javascript/coupdoeil/events/onmouseover.js +24 -14
- data/app/javascript/coupdoeil/popover/attributes.js +6 -2
- data/app/javascript/coupdoeil/popover/closing.js +23 -16
- data/app/javascript/coupdoeil/popover/config.js +1 -1
- data/app/javascript/coupdoeil/popover/lazy_loading.js +36 -0
- data/app/javascript/coupdoeil/popover/opening.js +32 -48
- data/app/javascript/coupdoeil/popover/options_parser.js +9 -5
- data/app/javascript/coupdoeil/popover/utils.js +46 -0
- data/app/javascript/coupdoeil/popover.js +11 -0
- data/app/models/coupdoeil/popover/lazy_loading.rb +57 -0
- data/app/models/coupdoeil/popover/option/loading.rb +1 -1
- data/app/models/coupdoeil/popover/option/placement.rb +25 -4
- data/app/models/coupdoeil/popover.rb +27 -12
- data/app/models/coupdoeil/tag.rb +11 -10
- data/lib/coupdoeil/config.rb +7 -0
- data/lib/coupdoeil/engine.rb +2 -1
- data/lib/coupdoeil/version.rb +1 -1
- metadata +4 -6
- data/app/javascript/coupdoeil/popover/actions.js +0 -0
- data/app/javascript/coupdoeil/popover/state_check.js +0 -12
|
@@ -17,22 +17,43 @@ module Coupdoeil
|
|
|
17
17
|
|
|
18
18
|
class << self
|
|
19
19
|
def parse(value)
|
|
20
|
-
values = value
|
|
20
|
+
values = extract_values(value)
|
|
21
21
|
4.times.sum do |index|
|
|
22
22
|
next 0 unless (placement = values[index])
|
|
23
23
|
|
|
24
|
-
placement.strip!
|
|
25
24
|
placement_index = INDEX_BY_VALUES[placement]
|
|
26
25
|
placement_index << (index * 4)
|
|
27
26
|
end
|
|
28
27
|
end
|
|
28
|
+
|
|
29
|
+
def extract_values(value, validate: false)
|
|
30
|
+
case value
|
|
31
|
+
when Array
|
|
32
|
+
raise_invalid_option("You can provide maximum 4 placement options.") if validate && value.length > 4
|
|
33
|
+
raise_invalid_option("You must provide at least one option.") if validate && value.empty?
|
|
34
|
+
value
|
|
35
|
+
when Symbol
|
|
36
|
+
[value.name]
|
|
37
|
+
when String
|
|
38
|
+
value.split(",").each(&:strip!).tap do |values|
|
|
39
|
+
if values.many?
|
|
40
|
+
locations = caller_locations
|
|
41
|
+
start_index = (locations.find_index { |s| s.path.include?(Rails.root.to_s) } || 0) + 1
|
|
42
|
+
Coupdoeil.deprecator.warn(
|
|
43
|
+
"Use array of string instead to provide several placement options",
|
|
44
|
+
caller_locations(start_index),
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
29
50
|
end
|
|
30
51
|
|
|
31
52
|
def validate!
|
|
32
|
-
values =
|
|
53
|
+
values = Placement.extract_values(value, validate: true)
|
|
33
54
|
|
|
34
55
|
values.each do |placement_value|
|
|
35
|
-
next if placement_value.
|
|
56
|
+
next if placement_value.in?(VALUES)
|
|
36
57
|
|
|
37
58
|
values_sentence = VALUES.to_sentence(last_word_connector: " or ")
|
|
38
59
|
raise_invalid_option("Value must be one of: #{values_sentence}")
|
|
@@ -17,6 +17,8 @@ module Coupdoeil
|
|
|
17
17
|
include ActionController::Cookies
|
|
18
18
|
include ActionController::Helpers
|
|
19
19
|
|
|
20
|
+
prepend LazyLoading
|
|
21
|
+
|
|
20
22
|
# For forgery protection
|
|
21
23
|
forgery_protection_methods = [
|
|
22
24
|
:form_authenticity_token,
|
|
@@ -104,17 +106,15 @@ module Coupdoeil
|
|
|
104
106
|
end
|
|
105
107
|
end
|
|
106
108
|
|
|
107
|
-
attr_reader :
|
|
108
|
-
|
|
109
|
-
helper_method :params
|
|
109
|
+
attr_reader :context_controller
|
|
110
110
|
|
|
111
111
|
delegate :request, :session, to: :context_controller
|
|
112
112
|
|
|
113
|
-
# @
|
|
113
|
+
# @raw_param [HashWithIndifferentAccess] raw_params the popover params to deserialize
|
|
114
114
|
# @param [ActionController::Base] context_controller an instance of Coupdoeil::PopoversController or the current controller if the popover is rendered inline because of `loading: :preload` option.
|
|
115
|
-
def initialize(
|
|
115
|
+
def initialize(raw_params, context_controller)
|
|
116
116
|
super()
|
|
117
|
-
@
|
|
117
|
+
@raw_params = raw_params
|
|
118
118
|
@context_controller = context_controller
|
|
119
119
|
end
|
|
120
120
|
|
|
@@ -141,13 +141,28 @@ See documentation on helpers at https://coupdoeil.org/guides/controller-api.html
|
|
|
141
141
|
Also note that render does not terminate execution of the action."
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
-
def
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
def instrument_render(method_name, &block)
|
|
145
|
+
ActiveSupport::Notifications.instrument("render_popover.coupdoeil", &block)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def process(method_name, ...)
|
|
149
|
+
instrument_render(method_name) do
|
|
150
|
+
super
|
|
151
|
+
response_body || render(action_name)
|
|
150
152
|
end
|
|
151
153
|
end
|
|
154
|
+
|
|
155
|
+
# @return [HashWithIndifferentAccess] the deserialized popover params that were given to `.with`
|
|
156
|
+
def params
|
|
157
|
+
@params ||=
|
|
158
|
+
if @raw_params&.is_a?(String)
|
|
159
|
+
parsed_params = JSON.parse(@raw_params)
|
|
160
|
+
parsed_params = Coupdoeil::Params.deserialize(parsed_params).sole
|
|
161
|
+
parsed_params.with_indifferent_access
|
|
162
|
+
else
|
|
163
|
+
@raw_params.with_indifferent_access
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
helper_method :params
|
|
152
167
|
end
|
|
153
168
|
end
|
data/app/models/coupdoeil/tag.rb
CHANGED
|
@@ -24,30 +24,31 @@ module Coupdoeil
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
attr_reader :popover_setup
|
|
30
|
-
|
|
31
|
-
def popover_attributes
|
|
32
|
-
attributes = { "popover-options": popover_options.to_base36 }
|
|
27
|
+
def popover_attributes(prefixed: false)
|
|
28
|
+
attributes = { popover_options: popover_options.to_base36 }
|
|
33
29
|
|
|
34
30
|
unless popover_options.preload?
|
|
35
31
|
params = Params.serialize(popover_setup.params).sole.presence&.to_json
|
|
36
|
-
attributes.merge!(
|
|
32
|
+
attributes.merge!(popover_type: popover_setup.identifier, popover_params: params)
|
|
37
33
|
end
|
|
38
34
|
|
|
39
35
|
if Coupdoeil.config.options_html_attributes
|
|
40
|
-
attributes.merge!(popover_options.to_h.transform_keys { "
|
|
36
|
+
attributes.merge!(popover_options.to_h.transform_keys { "popover_#{_1}".to_sym })
|
|
41
37
|
end
|
|
42
38
|
|
|
39
|
+
attributes.transform_keys! { "data-#{_1.name.tr("_", "-")}" } if prefixed
|
|
43
40
|
attributes
|
|
44
41
|
end
|
|
45
42
|
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
attr_reader :popover_setup
|
|
46
|
+
|
|
46
47
|
def tag_attributes
|
|
47
48
|
if @attributes
|
|
48
|
-
@attributes.merge(popover_attributes)
|
|
49
|
+
@attributes.merge(popover_attributes(prefixed: true))
|
|
49
50
|
else
|
|
50
|
-
popover_attributes
|
|
51
|
+
popover_attributes(prefixed: true)
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
end
|
data/lib/coupdoeil/config.rb
CHANGED
|
@@ -9,6 +9,7 @@ module Coupdoeil
|
|
|
9
9
|
options_html_attributes: Rails.env.local?,
|
|
10
10
|
include_all_helpers: true,
|
|
11
11
|
delegate_helper_methods: true,
|
|
12
|
+
default_dataset_format: :html,
|
|
12
13
|
})
|
|
13
14
|
end
|
|
14
15
|
|
|
@@ -41,6 +42,12 @@ module Coupdoeil
|
|
|
41
42
|
# therefore be delegated to the context controller.
|
|
42
43
|
# If this behavior causes unexpected behavior you can disable it with this configuration option, and/or [submit an issue](https://gitlab.com/Pagehey/coupdoeil/-/issues) so it can be investigated.
|
|
43
44
|
# However, in absence of problem, it is still recommended to let it `true` by default.
|
|
45
|
+
|
|
46
|
+
# @!attribute default_dataset_format
|
|
47
|
+
# @return [Symbol]
|
|
48
|
+
# Default returned format of the coupdoeil_popover_dataset view helper.
|
|
49
|
+
# See the helper documentation for available formats and their behavior.
|
|
50
|
+
# Defaults to `:html`.
|
|
44
51
|
end
|
|
45
52
|
# @!attribute current
|
|
46
53
|
# @return [Coupdoeil::Config]
|
data/lib/coupdoeil/engine.rb
CHANGED
|
@@ -63,9 +63,10 @@ module Coupdoeil
|
|
|
63
63
|
|
|
64
64
|
initializer "coupdoeil.view_paths" do
|
|
65
65
|
config.to_prepare do
|
|
66
|
-
views =
|
|
66
|
+
views = []
|
|
67
67
|
views += Rails.application.config.paths.add("app/popovers").existent
|
|
68
68
|
views += Rails.application.config.paths.add("app/popovers/layouts").existent
|
|
69
|
+
views += Rails.application.config.paths["app/views"].existent
|
|
69
70
|
Coupdoeil::Popover.prepend_view_path(views)
|
|
70
71
|
end
|
|
71
72
|
end
|
data/lib/coupdoeil/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: coupdoeil
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- PageHey
|
|
@@ -154,19 +154,20 @@ files:
|
|
|
154
154
|
- app/javascript/coupdoeil/events/onmouseover.js
|
|
155
155
|
- app/javascript/coupdoeil/index.js
|
|
156
156
|
- app/javascript/coupdoeil/popover.js
|
|
157
|
-
- app/javascript/coupdoeil/popover/actions.js
|
|
158
157
|
- app/javascript/coupdoeil/popover/attributes.js
|
|
159
158
|
- app/javascript/coupdoeil/popover/cache.js
|
|
160
159
|
- app/javascript/coupdoeil/popover/closing.js
|
|
161
160
|
- app/javascript/coupdoeil/popover/config.js
|
|
162
161
|
- app/javascript/coupdoeil/popover/controller.js
|
|
163
162
|
- app/javascript/coupdoeil/popover/current.js
|
|
163
|
+
- app/javascript/coupdoeil/popover/lazy_loading.js
|
|
164
164
|
- app/javascript/coupdoeil/popover/opening.js
|
|
165
165
|
- app/javascript/coupdoeil/popover/options_parser.js
|
|
166
166
|
- app/javascript/coupdoeil/popover/positioning.js
|
|
167
|
-
- app/javascript/coupdoeil/popover/
|
|
167
|
+
- app/javascript/coupdoeil/popover/utils.js
|
|
168
168
|
- app/models/coupdoeil/params.rb
|
|
169
169
|
- app/models/coupdoeil/popover.rb
|
|
170
|
+
- app/models/coupdoeil/popover/lazy_loading.rb
|
|
170
171
|
- app/models/coupdoeil/popover/option.rb
|
|
171
172
|
- app/models/coupdoeil/popover/option/animation.rb
|
|
172
173
|
- app/models/coupdoeil/popover/option/cache.rb
|
|
@@ -201,9 +202,6 @@ metadata:
|
|
|
201
202
|
homepage_uri: https://coupdoeil.org
|
|
202
203
|
source_code_uri: https://gitlab.com/Pagehey/coupdoeil
|
|
203
204
|
changelog_uri: https://gitlab.com/Pagehey/coupdoeil/-/blob/main/CHANGELOG.md
|
|
204
|
-
post_install_message: |
|
|
205
|
-
Coupdoeil v.1.1.0 fixed the helper usage in popovers and should allow some refactoring.
|
|
206
|
-
See CHANGELOG for details: https://gitlab.com/Pagehey/coupdoeil/-/blob/main/CHANGELOG.md?ref_type=heads#v110
|
|
207
205
|
rdoc_options: []
|
|
208
206
|
require_paths:
|
|
209
207
|
- lib
|
|
File without changes
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {POPOVER_CLOSE_BTN_SELECTOR} from "./config";
|
|
2
|
-
|
|
3
|
-
import {currentPopoversById} from "./current";
|
|
4
|
-
|
|
5
|
-
export function isElementClosePopoverButton(element) {
|
|
6
|
-
return element.closest(POPOVER_CLOSE_BTN_SELECTOR) ||
|
|
7
|
-
element.dataset.hasOwnProperty("popoverClose")
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isAnyPopoverOpened() {
|
|
11
|
-
return currentPopoversById().size > 0
|
|
12
|
-
}
|