turbo_boost-commands 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of turbo_boost-commands might be problematic. Click here for more details.

@@ -12,7 +12,8 @@ function src (element, frame) {
12
12
  }
13
13
 
14
14
  function find (element) {
15
- let frame = elements.findClosestFrame(element)
15
+ let frame = elements.findClosestFrameWithSource(element)
16
+
16
17
  const { turboFrame, turboMethod } = element.dataset
17
18
 
18
19
  if (element.tagName.toLowerCase() === 'form')
@@ -5,8 +5,12 @@ function findClosestCommand (element) {
5
5
  return element.closest(`[${schema.commandAttribute}]`)
6
6
  }
7
7
 
8
- function findClosestFrame (element) {
9
- return element.closest('turbo-frame')
8
+ function findClosestFrameWithSource (element) {
9
+ return (
10
+ element.closest('turbo-frame[src]') ||
11
+ element.closest('turbo-frame[data-turbo-frame-src]') ||
12
+ element.closest('turbo-frame')
13
+ )
10
14
  }
11
15
 
12
16
  function assignElementValueToPayload (element, payload = {}) {
@@ -47,5 +51,5 @@ function buildAttributePayload (element) {
47
51
  export default {
48
52
  buildAttributePayload,
49
53
  findClosestCommand,
50
- findClosestFrame
54
+ findClosestFrameWithSource
51
55
  }
@@ -19,7 +19,7 @@ function buildCommandPayload (id, element) {
19
19
  name: element.getAttribute(schema.commandAttribute),
20
20
  elementId: element.id.length > 0 ? element.id : null,
21
21
  elementAttributes: elements.buildAttributePayload(element),
22
- startedAt: new Date().getTime()
22
+ startedAt: Date.now()
23
23
  }
24
24
  }
25
25
 
@@ -2,7 +2,7 @@ import activity from './activity'
2
2
  import { dispatch, commandEvents } from './events'
3
3
 
4
4
  function finish (event) {
5
- event.detail.endedAt = new Date().getTime()
5
+ event.detail.endedAt = Date.now()
6
6
  event.detail.milliseconds = event.detail.endedAt - event.detail.startedAt
7
7
  setTimeout(
8
8
  () =>
@@ -11,6 +11,7 @@ function finish (event) {
11
11
  )
12
12
  }
13
13
 
14
+ // TODO: forward source event to finish (error or success)
14
15
  addEventListener(commandEvents.serverError, finish)
15
16
  addEventListener(commandEvents.success, finish)
16
17
  addEventListener(
@@ -24,6 +24,12 @@ module TurboBoost::Commands::AttributeHydration
24
24
  value
25
25
  end
26
26
 
27
+ # RULE: If an attribute value is a Hash
28
+ # (not the `aria` or `data` key because those are handled by Rails)
29
+ # and the Hash does not contain an object that implements GlobalID,
30
+ # then the developer must convert the Hash to a JSON string manually.
31
+ #
32
+ # SOLUTION: All data that's not a scalar/primitive value should live in `data` or `aria`.
27
33
  def dehydrate(value)
28
34
  return value unless has_sgid?(value)
29
35
  case value
@@ -92,6 +92,10 @@ module TurboBoost::Commands::CommandCallbacks
92
92
  !!@errored
93
93
  end
94
94
 
95
+ def performing?
96
+ !!@performing_method_name
97
+ end
98
+
95
99
  def performed?
96
100
  !!@performed
97
101
  end
@@ -12,6 +12,7 @@ class TurboBoost::Commands::ControllerPack
12
12
  delegate(
13
13
  :command_aborted?,
14
14
  :command_errored?,
15
+ :command_performing?,
15
16
  :command_performed?,
16
17
  :command_requested?,
17
18
  :command_succeeded?,
@@ -93,6 +93,10 @@ class TurboBoost::Commands::Runner
93
93
  !!command_instance&.errored?
94
94
  end
95
95
 
96
+ def command_performing?
97
+ !!command_instance&.performing?
98
+ end
99
+
96
100
  def command_performed?
97
101
  !!command_instance&.performed?
98
102
  end
@@ -114,6 +118,7 @@ class TurboBoost::Commands::Runner
114
118
  return unless command_valid?
115
119
  return if command_aborted?
116
120
  return if command_errored?
121
+ return if command_performing?
117
122
  return if command_performed?
118
123
  command_instance.perform_with_callbacks command_method_name
119
124
  rescue => error
@@ -236,8 +241,7 @@ class TurboBoost::Commands::Runner
236
241
  end
237
242
 
238
243
  def append_streams_to_response_body
239
- return unless command_instance.turbo_streams.present?
240
- append_to_response_body command_instance.turbo_streams.map(&:to_s).join.html_safe
244
+ command_instance.turbo_streams.each { |stream| append_to_response_body stream }
241
245
  end
242
246
 
243
247
  def append_meta_tag_to_response_body
@@ -267,11 +271,18 @@ class TurboBoost::Commands::Runner
267
271
  append_to_response_body event
268
272
  end
269
273
 
274
+ def appended_content
275
+ @appended_content ||= {}
276
+ end
277
+
270
278
  def append_to_response_body(content)
271
279
  return unless controller.response.media_type == "text/html"
272
- sanitized_content = content_sanitizer.sanitize(content).html_safe
280
+ sanitized_content = content_sanitizer.sanitize(content.to_s).html_safe
273
281
  return if sanitized_content.blank?
274
282
 
283
+ return if appended_content[sanitized_content]
284
+ appended_content[sanitized_content] = true
285
+
275
286
  html = case response_type
276
287
  when :body
277
288
  match = controller.response.body.match(/<\/\s*body/i).to_s
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TurboBoost
4
4
  module Commands
5
- VERSION = "0.0.9"
5
+ VERSION = "0.0.11"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_boost-commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Hopkins (hopsoft)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-18 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.5
47
+ version: 0.0.8
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.5
54
+ version: 0.0.8
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: capybara
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: cuprite
70
+ name: capybara-playwright-driver
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -422,7 +422,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
422
422
  requirements:
423
423
  - - ">="
424
424
  - !ruby/object:Gem::Version
425
- version: '0'
425
+ version: '2.7'
426
426
  required_rubygems_version: !ruby/object:Gem::Requirement
427
427
  requirements:
428
428
  - - ">="