katalyst-tables 2.2.9 → 2.2.11

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: baf08d43e92a19b9ada1834020d34cffd41eae9c2621ecf8c5d2909186c180f2
4
- data.tar.gz: ea9f5d9a8acbe840c03096e38eef0b6cd2ee6d71fdc95d18e1ac0908883347fd
3
+ metadata.gz: 93183f42b6a85c9ec376968ac1afd2c4481c16dc69d36bc0c42fc533ff73cb23
4
+ data.tar.gz: db5e89db2a8b56280a64c9183c51c984905d364e141d410e1f3718fad1353cc2
5
5
  SHA512:
6
- metadata.gz: 922f28f297e834b1584275236524de22dbc94e56850fb575557ffcc7ad8061242fc96886bf128e55681f2b7f664c44c0aac8fe9adfeb26e043adba14f20b78c4
7
- data.tar.gz: 0f3bcaed4e1c140fe2f3707df1979535ba2f394c0e0986b3e6320c194589daeb019397574c5d6eb0092955e95e1bb5f86e67b1f445df87f4daae1bb07cc4dc04
6
+ metadata.gz: 0b6354580e9abae55ab47491d4ac201a8f282c3fb13fc51bf8747e421eaa6aee7ff736cfcf2012ef4561f88f71a3f1acc66842e77a944cd3b582f17ee553c9cb
7
+ data.tar.gz: b87903d4dc31840d8c69fb7f9176bd597da008e297c18e045e2243bb85059281f818e275b8b2e874a56916035c729b04497afd309a6e82512cc21612376c5bee
@@ -3,12 +3,12 @@ import { Turbo } from "@hotwired/turbo-rails";
3
3
 
4
4
  export default class TurboCollectionController extends Controller {
5
5
  static values = {
6
- url: String,
6
+ query: String,
7
7
  sort: String,
8
8
  };
9
9
 
10
- urlValueChanged(url) {
11
- Turbo.navigator.history.replace(this.#url(url));
10
+ queryValueChanged(query) {
11
+ Turbo.navigator.history.replace(this.#url(query));
12
12
  }
13
13
 
14
14
  sortValueChanged(sort) {
@@ -21,13 +21,18 @@ export default class TurboCollectionController extends Controller {
21
21
  return "input[name='sort']";
22
22
  }
23
23
 
24
- #url(relativeUrl) {
24
+ #url(query) {
25
25
  const frame = this.element.closest("turbo-frame");
26
+ let url;
26
27
 
27
28
  if (frame) {
28
- return new URL(relativeUrl, frame.baseURI);
29
+ url = new URL(frame.baseURI);
29
30
  } else {
30
- return new URL(relativeUrl, window.location.href);
31
+ url = new URL(window.location.href);
31
32
  }
33
+
34
+ url.search = query;
35
+
36
+ return url;
32
37
  }
33
38
  }
@@ -11,7 +11,7 @@ module Katalyst
11
11
  ITEM_CONTROLLER = "tables--orderable--item"
12
12
  LIST_CONTROLLER = "tables--orderable--list"
13
13
 
14
- using HasHtmlAttributes
14
+ using Katalyst::HtmlAttributes
15
15
 
16
16
  # Support for inclusion in a table component class
17
17
  # Adds an `orderable` slot and component configuration
@@ -11,8 +11,8 @@ module Katalyst
11
11
  # <% end %>
12
12
  # ```
13
13
  class TableComponent < ViewComponent::Base
14
+ include Katalyst::HtmlAttributes
14
15
  include Tables::ConfigurableComponent
15
- include Tables::HasHtmlAttributes
16
16
  include Tables::HasTableContent
17
17
 
18
18
  attr_reader :collection, :object_name
@@ -86,5 +86,8 @@ module Katalyst
86
86
 
87
87
  define_html_attribute_methods(:thead_attributes)
88
88
  define_html_attribute_methods(:tbody_attributes)
89
+
90
+ # Backwards compatibility with tables 1.0
91
+ alias_method :options, :html_attributes=
89
92
  end
90
93
  end
@@ -3,7 +3,7 @@
3
3
  module Katalyst
4
4
  module Tables
5
5
  class BodyCellComponent < ViewComponent::Base # :nodoc:
6
- include HasHtmlAttributes
6
+ include Katalyst::HtmlAttributes
7
7
 
8
8
  attr_reader :record
9
9
 
@@ -39,6 +39,9 @@ module Katalyst
39
39
  def inspect
40
40
  "#<#{self.class.name} attribute: #{@attribute.inspect}, value: #{value.inspect}>"
41
41
  end
42
+
43
+ # Backwards compatibility with tables 1.0
44
+ alias_method :options, :html_attributes=
42
45
  end
43
46
  end
44
47
  end
@@ -3,7 +3,7 @@
3
3
  module Katalyst
4
4
  module Tables
5
5
  class BodyRowComponent < ViewComponent::Base # :nodoc:
6
- include HasHtmlAttributes
6
+ include Katalyst::HtmlAttributes
7
7
 
8
8
  renders_many :columns, ->(component) { component }
9
9
 
@@ -39,6 +39,9 @@ module Katalyst
39
39
  def inspect
40
40
  "#<#{self.class.name} record: #{record.inspect}>"
41
41
  end
42
+
43
+ # Backwards compatibility with tables 1.0
44
+ alias_method :options, :html_attributes=
42
45
  end
43
46
  end
44
47
  end
@@ -3,7 +3,7 @@
3
3
  module Katalyst
4
4
  module Tables
5
5
  class EmptyCaptionComponent < ViewComponent::Base # :nodoc:
6
- include HasHtmlAttributes
6
+ include Katalyst::HtmlAttributes
7
7
 
8
8
  def initialize(table, **html_attributes)
9
9
  super(**html_attributes)
@@ -4,7 +4,7 @@ module Katalyst
4
4
  module Tables
5
5
  class HeaderCellComponent < ViewComponent::Base # :nodoc:
6
6
  include Frontend::Helper
7
- include HasHtmlAttributes
7
+ include Katalyst::HtmlAttributes
8
8
  include Sortable
9
9
 
10
10
  delegate :object_name, :collection, :sorting, to: :@table
@@ -50,6 +50,9 @@ module Katalyst
50
50
  "#<#{self.class.name} attribute: #{@attribute.inspect}, value: #{value.inspect}>"
51
51
  end
52
52
 
53
+ # Backwards compatibility with tables 1.0
54
+ alias_method :options, :html_attributes=
55
+
53
56
  private
54
57
 
55
58
  def default_html_attributes
@@ -3,7 +3,7 @@
3
3
  module Katalyst
4
4
  module Tables
5
5
  class HeaderRowComponent < ViewComponent::Base # :nodoc:
6
- include HasHtmlAttributes
6
+ include Katalyst::HtmlAttributes
7
7
 
8
8
  renders_many :columns, ->(component) { component }
9
9
 
@@ -39,6 +39,9 @@ module Katalyst
39
39
  def inspect
40
40
  "#<#{self.class.name} link_attributes: #{@link_attributes.inspect}>"
41
41
  end
42
+
43
+ # Backwards compatibility with tables 1.0
44
+ alias_method :options, :html_attributes=
42
45
  end
43
46
  end
44
47
  end
@@ -26,16 +26,15 @@ module Katalyst
26
26
  def default_html_attributes
27
27
  {
28
28
  data: {
29
- controller: "tables--turbo-collection",
30
- tables__turbo_collection_url_value: current_path,
31
- tables__turbo_collection_sort_value: collection.sort,
29
+ controller: "tables--turbo-collection",
30
+ tables__turbo_collection_query_value: current_query,
31
+ tables__turbo_collection_sort_value: collection.sort,
32
32
  },
33
33
  }
34
34
  end
35
35
 
36
- def current_path
37
- params = collection.to_params
38
- params.empty? ? "" : "?#{Rack::Utils.build_nested_query(params)}"
36
+ def current_query
37
+ Rack::Utils.build_nested_query(collection.to_params)
39
38
  end
40
39
 
41
40
  def default_header_options
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "view_component"
4
+ require "katalyst/html_attributes"
4
5
 
5
6
  require_relative "tables/backend"
6
7
  require_relative "tables/engine"
7
8
  require_relative "tables/frontend"
8
- require_relative "tables/version"
9
9
 
10
10
  require_relative "tables/engine" if Object.const_defined?(:Rails)
11
11
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.9
4
+ version: 2.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: html-attributes-utils
14
+ name: katalyst-html-attributes
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -55,7 +55,6 @@ files:
55
55
  - app/assets/javascripts/controllers/tables/orderable/list_controller.js
56
56
  - app/assets/javascripts/controllers/tables/turbo_collection_controller.js
57
57
  - app/components/concerns/katalyst/tables/configurable_component.rb
58
- - app/components/concerns/katalyst/tables/has_html_attributes.rb
59
58
  - app/components/concerns/katalyst/tables/has_table_content.rb
60
59
  - app/components/concerns/katalyst/tables/orderable.rb
61
60
  - app/components/concerns/katalyst/tables/sortable.rb
@@ -84,7 +83,6 @@ files:
84
83
  - lib/katalyst/tables/engine.rb
85
84
  - lib/katalyst/tables/frontend.rb
86
85
  - lib/katalyst/tables/frontend/helper.rb
87
- - lib/katalyst/tables/version.rb
88
86
  homepage: https://github.com/katalyst/katalyst-tables
89
87
  licenses:
90
88
  - MIT
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "html_attributes_utils"
4
-
5
- module Katalyst
6
- module Tables
7
- # Adds HTML attributes to a component.
8
- # Accepts HTML attributes from the constructor or via `html_attributes=`.
9
- # These are merged with the default attributes defined in the component.
10
- # Adds support for custom html attributes for other tags, e.g.:
11
- # define_html_attribute_methods :table_attributes, default: {}
12
- # tag.table(**table_attributes)
13
- module HasHtmlAttributes
14
- extend ActiveSupport::Concern
15
-
16
- using HTMLAttributesUtils
17
-
18
- MERGEABLE_ATTRIBUTES = [
19
- *HTMLAttributesUtils::DEFAULT_MERGEABLE_ATTRIBUTES,
20
- %i[data controller],
21
- %i[data action],
22
- ].freeze
23
-
24
- FLATTENABLE_ATTRIBUTES = [
25
- %i[data controller],
26
- %i[data action],
27
- ].freeze
28
-
29
- refine NilClass do
30
- def flatten_html(*)
31
- self
32
- end
33
- end
34
-
35
- refine Hash do
36
- def merge_html(attributes)
37
- result = deep_merge_html_attributes(attributes, mergeable_attributes: MERGEABLE_ATTRIBUTES)
38
- FLATTENABLE_ATTRIBUTES.each_with_object(result) do |path, flattened|
39
- flattened.flatten_html(*path)
40
- end
41
- end
42
-
43
- def flatten_html(key, *path)
44
- if path.empty?
45
- self[key] = self[key].join(" ") if self[key].is_a?(Array)
46
- else
47
- self[key].flatten_html(*path)
48
- end
49
- end
50
- end
51
-
52
- class_methods do
53
- using HasHtmlAttributes
54
-
55
- def define_html_attribute_methods(name, default: {})
56
- define_method("default_#{name}") { default }
57
- private("default_#{name}")
58
-
59
- define_method(name) do
60
- send("default_#{name}").merge_html(instance_variable_get("@#{name}") || {})
61
- end
62
-
63
- define_method("#{name}=") do |options|
64
- instance_variable_set("@#{name}", options.slice(:id, :aria, :class, :data).merge(options.fetch(:html, {})))
65
- end
66
- end
67
- end
68
-
69
- included do
70
- define_html_attribute_methods :html_attributes, default: {}
71
-
72
- # Backwards compatibility with tables 1.0
73
- alias_method :options, :html_attributes=
74
- end
75
-
76
- def initialize(**options)
77
- super(**options.except(:id, :aria, :class, :data, :html))
78
-
79
- self.html_attributes = options
80
- end
81
- end
82
- end
83
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Katalyst
4
- module Tables
5
- VERSION = "2.2.9"
6
- end
7
- end