satis 2.4.0 → 2.4.2

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: d24982732d14eac101cca9cfa2d3cc5e3307b6858b59e2bfeb542a8f487d651a
4
- data.tar.gz: decd649c7dadbb2206236d9cf0e452a0e39fe09abbed919daa15f808ac762079
3
+ metadata.gz: 2c8b8f688d732d57a4df263b47f48f1b072f709c1d9ae5b224cc1e7197e5fc08
4
+ data.tar.gz: 42d9edfb45401ad6cb797ffa95195acceff18b3a1aa8b8931c95d29afacba49f
5
5
  SHA512:
6
- metadata.gz: 97ea139e33af026ab3125936279fd5f3f14791b86ce10fe126ee6381b0a9edbf05d6d4eb83cd951a4176474f0190fe761ba4c4c3459792064cb3afb8e14536d6
7
- data.tar.gz: fa5477988669b89a1cc0b1ed439d31a3667af430061139447df29543fac809ae9c7d7cecc6d3b0dfd25b48cdc8351476c364979c987f93ebd433030032238b4d
6
+ metadata.gz: 4bbf1820f21de79035eb8c5285de9ac084f7609a1b33ba57dc8261592d65d122e79d73d808d772aa40b55d1dddc60962b218e7803bb2798c51b506d057186b38
7
+ data.tar.gz: ac095ab29b95766986c70e2f15322a4f1e16cfc8014ee365b56fc58e628ced330392eddb6b5f67479b3637d8e0004153b58329bbe2c9a7ea7dc3d13038ee86ee
@@ -21,6 +21,15 @@ module Satis
21
21
  super()
22
22
  end
23
23
 
24
+ def render_in(view_context, &)
25
+ self.original_view_context ||= view_context
26
+ self.original_virtual_path ||= Satis.current_original_virtual_path.presence || view_context.instance_variable_get(:@virtual_path)
27
+
28
+ Satis.with_original_virtual_path(original_virtual_path) do
29
+ super
30
+ end
31
+ end
32
+
24
33
  def component_name
25
34
  self.class.name.sub(/::Component$/, "").sub(/^Satis::/, "").underscore
26
35
  end
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # FIXME:
4
- # translation scope seems wrong:
5
- # old/okay) title="translation missing: en.users.edit.card.profile.tab.about"
6
- # new/broken) title="translation missing: en.users.edit.tabs.main.tab.about"
7
-
8
3
  module Satis
9
4
  module Tabs
10
5
  class Component < Satis::ApplicationComponent
@@ -1,4 +1,4 @@
1
- import ApplicationController from "satis/controllers/application_controller"
1
+ import ApplicationController from "satis/controllers/application_controller";
2
2
 
3
3
  /*
4
4
  Usage:
@@ -26,20 +26,20 @@ import ApplicationController from "satis/controllers/application_controller"
26
26
  = address_form.input :company_name
27
27
  */
28
28
  export default class extends ApplicationController {
29
- static targets = ["toggleable", "insertion", "input"]
29
+ static targets = ["toggleable", "insertion", "input"];
30
30
 
31
31
  connect() {
32
- this.boundUpdate = this.update.bind(this)
32
+ this.boundUpdate = this.update.bind(this);
33
33
  this.inputTargets.forEach((input) => {
34
- input.addEventListener("change", this.boundUpdate)
35
- })
36
- this.update()
34
+ input.addEventListener("change", this.boundUpdate);
35
+ });
36
+ this.update();
37
37
  }
38
38
 
39
39
  disconnect() {
40
40
  this.inputTargets.forEach((input) => {
41
- input.removeEventListener("change", this.boundUpdate)
42
- })
41
+ input.removeEventListener("change", this.boundUpdate);
42
+ });
43
43
  }
44
44
 
45
45
  update(event) {
@@ -48,61 +48,72 @@ export default class extends ApplicationController {
48
48
  * process before we overwrite the template nodes that are possibly updated and reinsert new nodes.
49
49
  */
50
50
  setTimeout(() => {
51
- this.toggle(this.currentValue)
52
- })
51
+ this.toggle(this.currentValue);
52
+ });
53
53
  }
54
54
 
55
55
  toggle(value) {
56
56
  // Update template nodes before we swap
57
57
  this.toggleableTargets.forEach((target) => {
58
- target.content.childNodes.forEach(child => {
59
- let targetNodeId = child.getAttribute("data-toggleable-node-id")
58
+ target.content.childNodes.forEach((child) => {
59
+ if (typeof child.getAttribute != "function") return;
60
+ let targetNodeId = child.getAttribute("data-toggleable-node-id");
60
61
  if (!targetNodeId) return true;
61
62
 
62
- this.insertionTarget.childNodes.forEach(iNode => {
63
+ this.insertionTarget.childNodes.forEach((iNode) => {
63
64
  if (iNode.getAttribute("data-toggleable-node-id") == targetNodeId) {
64
65
  if (child.parentElement) {
65
- child.outerHTML = iNode.outerHTML
66
- iNode.remove()
66
+ child.outerHTML = iNode.outerHTML;
67
+ iNode.remove();
67
68
  }
68
69
  }
69
- })
70
- })
71
- })
70
+ });
71
+ });
72
+ });
72
73
 
73
74
  // Clear the insertion target
74
- this.insertionTarget.innerHTML = ""
75
+ this.insertionTarget.innerHTML = "";
75
76
 
76
77
  // Reinsert elements
77
78
  this.toggleableTargets.forEach((element) => {
78
- if (element.getAttribute("data-toggle-value") == value || (element.getAttribute("data-toggle-not-value") != null && element.getAttribute("data-toggle-not-value") != value)) {
79
- element.content.childNodes.forEach(node => this.setUniqueId(node))
79
+ if (
80
+ element.getAttribute("data-toggle-value") == value ||
81
+ (element.getAttribute("data-toggle-not-value") != null &&
82
+ element.getAttribute("data-toggle-not-value") != value)
83
+ ) {
84
+ element.content.childNodes.forEach((node) => this.setUniqueId(node));
80
85
 
81
- let toggleContent = document.importNode(element.content, true)
86
+ let toggleContent = document.importNode(element.content, true);
82
87
  toggleContent.childNodes.forEach((child) => {
83
- this.insertionTarget.insertAdjacentHTML("beforeend", child.outerHTML)
84
- })
88
+ if (typeof child.outerHTML != "undefined") {
89
+ this.insertionTarget.insertAdjacentHTML(
90
+ "beforeend",
91
+ child.outerHTML,
92
+ );
93
+ }
94
+ });
85
95
  }
86
- })
96
+ });
87
97
  }
88
98
 
89
99
  get currentValue() {
90
100
  if (this.inputTargets.length >= 1 && this.inputTargets[0].type == "radio") {
91
- return this.inputTargets.find((input) => input.checked)?.value
101
+ return this.inputTargets.find((input) => input.checked)?.value;
92
102
  } else if (this.inputTarget.type == "checkbox") {
93
- return this.inputTarget.checked ? "true" : "false"
103
+ return this.inputTarget.checked ? "true" : "false";
94
104
  } else if (this.inputTarget.tagName == "SELECT" && this.data.get("attr")) {
95
- let option = this.inputTarget.options[this.inputTarget.selectedIndex]
96
- return option?.getAttribute(this.data.get("attr"))
105
+ let option = this.inputTarget.options[this.inputTarget.selectedIndex];
106
+ return option?.getAttribute(this.data.get("attr"));
97
107
  } else {
98
- return this.inputTarget.value
108
+ return this.inputTarget.value;
99
109
  }
100
110
  }
101
111
 
102
112
  setUniqueId(node) {
113
+ if (typeof node.getAttribute != "function") return;
103
114
  if (node.getAttribute("data-toggleable-node-id")) return;
104
115
  const dateString = Date.now().toString(36);
105
116
  const randomness = Math.random().toString(36).substring(2);
106
- node.setAttribute("data-toggleable-node-id", dateString + randomness)
117
+ node.setAttribute("data-toggleable-node-id", dateString + randomness);
107
118
  }
108
119
  }
@@ -8,6 +8,8 @@ module Satis
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
+ attr_accessor :original_virtual_path
12
+
11
13
  #
12
14
  # This provides us with a translation helper which scopes into the original view
13
15
  # and thereby conveniently scopes the translations.
@@ -24,8 +26,7 @@ module Satis
24
26
  #
25
27
  def ct(key = nil, **options)
26
28
  key = "#{full_i18n_scope(options).join('.')}#{key}" if key.start_with?('.')
27
-
28
- original_view_context.t(key, **options)
29
+ original_view_context.controller.t(key, **options)
29
30
  end
30
31
 
31
32
  def full_i18n_scope(options = {})
@@ -41,12 +42,24 @@ module Satis
41
42
  @full_i18n_scope
42
43
  end
43
44
 
44
- def original_virtual_path
45
- original_view_context.instance_variable_get(:@virtual_path)
45
+ def original_i18n_scope
46
+ virtual_path = original_virtual_path.presence || original_view_context_virtual_path
47
+
48
+ return virtual_path.gsub(%r{/_?}, ".").split(".") if virtual_path.present? && !satis_component_virtual_path?(virtual_path)
49
+
50
+ [original_view_context.controller_path.tr("/", "."), original_view_context.action_name]
51
+ end
52
+
53
+ def satis_component_virtual_path?(virtual_path)
54
+ virtual_path.start_with?("satis/")
46
55
  end
47
56
 
48
- def original_i18n_scope
49
- original_virtual_path.sub(%r{^/}, '').gsub(%r{/_?}, '.').split('.')
57
+ def original_view_context_virtual_path
58
+ if original_view_context.respond_to?(:virtual_path)
59
+ original_view_context.virtual_path
60
+ elsif original_view_context.instance_variable_defined?(:@virtual_path)
61
+ original_view_context.instance_variable_get(:@virtual_path)
62
+ end
50
63
  end
51
64
 
52
65
  def i18n_scope
@@ -55,4 +68,4 @@ module Satis
55
68
  end
56
69
  end
57
70
  end
58
- end
71
+ end
@@ -78,7 +78,6 @@ module Satis
78
78
  else
79
79
  component.new(*original_args, **kwargs)
80
80
  end
81
- instance.original_view_context = action_view
82
81
  action_view.render(instance, &block)
83
82
  end
84
83
  end
data/lib/satis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Satis
2
- VERSION = "2.4.0"
2
+ VERSION = "2.4.2"
3
3
  end
data/lib/satis.rb CHANGED
@@ -27,6 +27,21 @@ module Satis
27
27
  Satis::Helpers::Container.add_helper(name, component)
28
28
  end
29
29
 
30
+ def current_original_virtual_path
31
+ original_virtual_path_stack.last
32
+ end
33
+
34
+ def with_original_virtual_path(virtual_path)
35
+ original_virtual_path_stack.push(virtual_path)
36
+ yield
37
+ ensure
38
+ original_virtual_path_stack.pop
39
+ end
40
+
41
+ def original_virtual_path_stack
42
+ Thread.current[:satis_original_virtual_path_stack] ||= []
43
+ end
44
+
30
45
  def add_component_helper(component_name, name, component)
31
46
  klass = "Satis::#{component_name.to_s.classify}::Component".safe_constantize
32
47
  return if klass.blank?
data/mise.toml ADDED
@@ -0,0 +1,4 @@
1
+ [tools]
2
+ node = "24"
3
+ ruby = "3.4.7"
4
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: satis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-15 00:00:00.000000000 Z
11
+ date: 2026-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: browser
@@ -934,6 +934,7 @@ files:
934
934
  - lib/satis/satisfied.rb
935
935
  - lib/satis/version.rb
936
936
  - lib/tasks/satis_tasks.rake
937
+ - mise.toml
937
938
  - package.json
938
939
  - satis.gemspec
939
940
  - vendor/javascript/@codemirror--autocomplete.js