katalyst-tables 2.6.0.beta → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +1 -23
- data/app/assets/stylesheets/katalyst/tables/_index.scss +1 -0
- data/app/assets/stylesheets/katalyst/tables/_ordinal.scss +38 -0
- data/app/assets/stylesheets/katalyst/tables/_table.scss +123 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_boolean.scss +4 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_currency.scss +5 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_date.scss +4 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_datetime.scss +4 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_index.scss +5 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_number.scss +5 -0
- data/app/components/concerns/katalyst/tables/body/typed_columns.rb +132 -0
- data/app/components/concerns/katalyst/tables/has_table_content.rb +1 -1
- data/app/components/concerns/katalyst/tables/header/typed_columns.rb +179 -0
- data/app/components/concerns/katalyst/tables/orderable.rb +1 -1
- data/app/components/concerns/katalyst/tables/selectable.rb +2 -1
- data/app/components/katalyst/table_component.rb +13 -1
- data/app/components/katalyst/tables/body/attachment_component.rb +58 -0
- data/app/components/katalyst/tables/body/boolean_component.rb +14 -0
- data/app/components/katalyst/tables/body/currency_component.rb +29 -0
- data/app/components/katalyst/tables/body/date_component.rb +64 -0
- data/app/components/katalyst/tables/body/date_time_component.rb +57 -0
- data/app/components/katalyst/tables/body/link_component.rb +40 -0
- data/app/components/katalyst/tables/body/number_component.rb +22 -0
- data/app/components/katalyst/tables/body/rich_text_component.rb +18 -0
- data/app/components/katalyst/tables/body_cell_component.rb +9 -1
- data/app/components/katalyst/tables/body_row_component.rb +9 -2
- data/app/components/katalyst/tables/empty_caption_component.rb +1 -1
- data/app/components/katalyst/tables/header/attachment_component.rb +15 -0
- data/app/components/katalyst/tables/header/boolean_component.rb +15 -0
- data/app/components/katalyst/tables/header/currency_component.rb +15 -0
- data/app/components/katalyst/tables/header/date_component.rb +15 -0
- data/app/components/katalyst/tables/header/date_time_component.rb +15 -0
- data/app/components/katalyst/tables/header/link_component.rb +15 -0
- data/app/components/katalyst/tables/header/number_component.rb +15 -0
- data/app/components/katalyst/tables/header/rich_text_component.rb +15 -0
- data/app/components/katalyst/tables/header_cell_component.rb +35 -3
- data/app/components/katalyst/tables/header_row_component.rb +3 -2
- data/app/components/katalyst/tables/selectable/form_component.html.erb +4 -2
- data/app/controllers/concerns/katalyst/tables/backend.rb +2 -2
- data/app/helpers/katalyst/tables/frontend.rb +2 -2
- data/app/models/concerns/katalyst/tables/collection/pagination.rb +8 -1
- data/app/models/concerns/katalyst/tables/collection/sorting.rb +3 -3
- data/app/models/katalyst/tables/collection/sort_form.rb +26 -8
- data/config/locales/tables.en.yml +6 -0
- metadata +33 -9
- data/app/components/concerns/katalyst/tables/turbo_replaceable.rb +0 -79
- data/app/components/katalyst/turbo/pagy_nav_component.rb +0 -23
- data/app/components/katalyst/turbo/table_component.rb +0 -45
@@ -10,25 +10,43 @@ module Katalyst
|
|
10
10
|
|
11
11
|
attr_accessor :column, :direction, :default
|
12
12
|
|
13
|
-
def self.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
default = SortForm.parse(default).to_param if default.present?
|
13
|
+
def self.normalize(param)
|
14
|
+
new(param:).to_param
|
15
|
+
end
|
18
16
|
|
19
|
-
|
17
|
+
def self.parse(param, **args)
|
18
|
+
new(param:, **args)
|
20
19
|
end
|
21
20
|
|
22
|
-
def initialize(column: nil, direction: nil, default: nil)
|
21
|
+
def initialize(param: nil, column: nil, direction: nil, default: nil)
|
22
|
+
if param.present?
|
23
|
+
column, direction = param.to_s.split
|
24
|
+
direction = "asc" unless DIRECTIONS.include?(direction)
|
25
|
+
end
|
26
|
+
|
23
27
|
self.column = column
|
24
28
|
self.direction = direction
|
25
|
-
self.default = default
|
29
|
+
self.default = SortForm.normalize(default) if default
|
26
30
|
end
|
27
31
|
|
28
32
|
def to_param
|
29
33
|
"#{column} #{direction}"
|
30
34
|
end
|
31
35
|
|
36
|
+
def default?
|
37
|
+
to_param == default.to_param
|
38
|
+
end
|
39
|
+
|
40
|
+
def hash
|
41
|
+
to_param.hash
|
42
|
+
end
|
43
|
+
|
44
|
+
def eql?(other)
|
45
|
+
to_param == other.to_param
|
46
|
+
end
|
47
|
+
|
48
|
+
alias to_s to_param
|
49
|
+
|
32
50
|
# Returns true if the given collection supports sorting on the given
|
33
51
|
# column. A column supports sorting if it is a database column or if
|
34
52
|
# the collection responds to `order_by_#{column}(direction)`.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katalyst-html-attributes
|
@@ -54,26 +54,50 @@ files:
|
|
54
54
|
- app/assets/builds/katalyst/tables.min.js
|
55
55
|
- app/assets/builds/katalyst/tables.min.js.map
|
56
56
|
- app/assets/config/katalyst-tables.js
|
57
|
+
- app/assets/stylesheets/katalyst/tables/_index.scss
|
58
|
+
- app/assets/stylesheets/katalyst/tables/_ordinal.scss
|
59
|
+
- app/assets/stylesheets/katalyst/tables/_table.scss
|
60
|
+
- app/assets/stylesheets/katalyst/tables/typed-columns/_boolean.scss
|
61
|
+
- app/assets/stylesheets/katalyst/tables/typed-columns/_currency.scss
|
62
|
+
- app/assets/stylesheets/katalyst/tables/typed-columns/_date.scss
|
63
|
+
- app/assets/stylesheets/katalyst/tables/typed-columns/_datetime.scss
|
64
|
+
- app/assets/stylesheets/katalyst/tables/typed-columns/_index.scss
|
65
|
+
- app/assets/stylesheets/katalyst/tables/typed-columns/_number.scss
|
66
|
+
- app/components/concerns/katalyst/tables/body/typed_columns.rb
|
57
67
|
- app/components/concerns/katalyst/tables/configurable_component.rb
|
58
68
|
- app/components/concerns/katalyst/tables/has_table_content.rb
|
69
|
+
- app/components/concerns/katalyst/tables/header/typed_columns.rb
|
59
70
|
- app/components/concerns/katalyst/tables/orderable.rb
|
60
71
|
- app/components/concerns/katalyst/tables/row_renderer.rb
|
61
72
|
- app/components/concerns/katalyst/tables/selectable.rb
|
62
73
|
- app/components/concerns/katalyst/tables/sortable.rb
|
63
|
-
- app/components/concerns/katalyst/tables/turbo_replaceable.rb
|
64
74
|
- app/components/katalyst/table_component.html.erb
|
65
75
|
- app/components/katalyst/table_component.rb
|
76
|
+
- app/components/katalyst/tables/body/attachment_component.rb
|
77
|
+
- app/components/katalyst/tables/body/boolean_component.rb
|
78
|
+
- app/components/katalyst/tables/body/currency_component.rb
|
79
|
+
- app/components/katalyst/tables/body/date_component.rb
|
80
|
+
- app/components/katalyst/tables/body/date_time_component.rb
|
81
|
+
- app/components/katalyst/tables/body/link_component.rb
|
82
|
+
- app/components/katalyst/tables/body/number_component.rb
|
83
|
+
- app/components/katalyst/tables/body/rich_text_component.rb
|
66
84
|
- app/components/katalyst/tables/body_cell_component.rb
|
67
85
|
- app/components/katalyst/tables/body_row_component.rb
|
68
86
|
- app/components/katalyst/tables/empty_caption_component.html.erb
|
69
87
|
- app/components/katalyst/tables/empty_caption_component.rb
|
88
|
+
- app/components/katalyst/tables/header/attachment_component.rb
|
89
|
+
- app/components/katalyst/tables/header/boolean_component.rb
|
90
|
+
- app/components/katalyst/tables/header/currency_component.rb
|
91
|
+
- app/components/katalyst/tables/header/date_component.rb
|
92
|
+
- app/components/katalyst/tables/header/date_time_component.rb
|
93
|
+
- app/components/katalyst/tables/header/link_component.rb
|
94
|
+
- app/components/katalyst/tables/header/number_component.rb
|
95
|
+
- app/components/katalyst/tables/header/rich_text_component.rb
|
70
96
|
- app/components/katalyst/tables/header_cell_component.rb
|
71
97
|
- app/components/katalyst/tables/header_row_component.rb
|
72
98
|
- app/components/katalyst/tables/pagy_nav_component.rb
|
73
99
|
- app/components/katalyst/tables/selectable/form_component.html.erb
|
74
100
|
- app/components/katalyst/tables/selectable/form_component.rb
|
75
|
-
- app/components/katalyst/turbo/pagy_nav_component.rb
|
76
|
-
- app/components/katalyst/turbo/table_component.rb
|
77
101
|
- app/controllers/concerns/katalyst/tables/backend.rb
|
78
102
|
- app/helpers/katalyst/tables/frontend.rb
|
79
103
|
- app/helpers/katalyst/tables/frontend/helper.rb
|
@@ -114,14 +138,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
138
|
requirements:
|
115
139
|
- - ">="
|
116
140
|
- !ruby/object:Gem::Version
|
117
|
-
version: 3.
|
141
|
+
version: 3.2.0
|
118
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
143
|
requirements:
|
120
|
-
- - "
|
144
|
+
- - ">="
|
121
145
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
146
|
+
version: '0'
|
123
147
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
148
|
+
rubygems_version: 3.5.9
|
125
149
|
signing_key:
|
126
150
|
specification_version: 4
|
127
151
|
summary: HTML table generator for Rails views
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Katalyst
|
4
|
-
module Tables
|
5
|
-
# Adds support for turbo stream replacement to ViewComponents. Components
|
6
|
-
# that are rendered from a turbo-stream-compatible response will be rendered
|
7
|
-
# using turbo stream replacement. Components must define `id`.
|
8
|
-
#
|
9
|
-
# Turbo stream replacement rendering will only be enabled if the component
|
10
|
-
# passes `turbo: true` as a constructor option.
|
11
|
-
module TurboReplaceable
|
12
|
-
extend ActiveSupport::Concern
|
13
|
-
|
14
|
-
include ::Turbo::StreamsHelper
|
15
|
-
|
16
|
-
# Is turbo rendering enabled for this component?
|
17
|
-
def turbo?
|
18
|
-
@turbo
|
19
|
-
end
|
20
|
-
|
21
|
-
# Are we rendering a turbo stream response?
|
22
|
-
def turbo_stream_response?
|
23
|
-
response.media_type.eql?("text/vnd.turbo-stream.html")
|
24
|
-
end
|
25
|
-
|
26
|
-
def initialize(turbo: true, **options)
|
27
|
-
super(**options)
|
28
|
-
|
29
|
-
@turbo = turbo
|
30
|
-
end
|
31
|
-
|
32
|
-
class_methods do
|
33
|
-
# Redefine the compiler to use our custom compiler.
|
34
|
-
# Compiler is set on `inherited` so we need to re-set it if it's not the expected type.
|
35
|
-
def compiler
|
36
|
-
@vc_compiler = @vc_compiler.is_a?(TurboCompiler) ? @vc_compiler : TurboCompiler.new(self)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
included do
|
41
|
-
# ensure that our custom compiler is used, as `inherited` calls `compile` before our module is included.
|
42
|
-
compile(force: true) if compiled?
|
43
|
-
end
|
44
|
-
|
45
|
-
# Wraps the default compiler provided by ViewComponent to add turbo support.
|
46
|
-
class TurboCompiler < ViewComponent::Compiler
|
47
|
-
private
|
48
|
-
|
49
|
-
def define_render_template_for # rubocop:disable Metrics/MethodLength
|
50
|
-
super
|
51
|
-
|
52
|
-
redefinition_lock.synchronize do
|
53
|
-
# Capture the instance method added by the default compiler and
|
54
|
-
# wrap it in a turbo stream replacement. Take care to ensure that
|
55
|
-
# subclasses of this component don't break delegation, as each
|
56
|
-
# subclass of ViewComponent::Base defines its own version of this
|
57
|
-
# method.
|
58
|
-
vc_render_template = component_class.instance_method(:render_template_for)
|
59
|
-
component_class.define_method(:render_template_for) do |variant = nil|
|
60
|
-
# VC discards the output from this method and uses the buffer
|
61
|
-
# if both are set. Capture and wrap the output.
|
62
|
-
content = capture { vc_render_template.bind_call(self, variant) }
|
63
|
-
# In turbo mode, replace the inner-most element using a turbo
|
64
|
-
# stream. Note that we only want one turbo stream per component
|
65
|
-
# from this mechanism, as subclasses may want to concat their
|
66
|
-
# own additional streams.
|
67
|
-
if turbo? && turbo_stream_response? && !@streamed
|
68
|
-
@streamed = true
|
69
|
-
concat(turbo_stream.replace(id, content))
|
70
|
-
else
|
71
|
-
concat(content)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Katalyst
|
4
|
-
module Turbo
|
5
|
-
class PagyNavComponent < Tables::PagyNavComponent # :nodoc:
|
6
|
-
include Tables::TurboReplaceable
|
7
|
-
|
8
|
-
def initialize(id:, **options)
|
9
|
-
super(pagy_id: id, **options)
|
10
|
-
end
|
11
|
-
|
12
|
-
def id
|
13
|
-
pagy_options[:pagy_id]
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def pagy_options
|
19
|
-
super.merge(link_extra: "data-turbo-stream")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Katalyst
|
4
|
-
module Turbo
|
5
|
-
# Renders a table that uses turbo stream replacement when sorting or
|
6
|
-
# paginating.
|
7
|
-
class TableComponent < ::Katalyst::TableComponent
|
8
|
-
include Tables::TurboReplaceable
|
9
|
-
|
10
|
-
attr_reader :id
|
11
|
-
|
12
|
-
def initialize(collection:, id:, header: true, **options)
|
13
|
-
header = if header.is_a?(Hash)
|
14
|
-
default_header_options.merge(header)
|
15
|
-
elsif header
|
16
|
-
default_header_options
|
17
|
-
end
|
18
|
-
|
19
|
-
@id = id
|
20
|
-
|
21
|
-
super(collection: collection, header: header, id: id, **options)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def default_html_attributes
|
27
|
-
{
|
28
|
-
data: {
|
29
|
-
controller: "tables--turbo--collection",
|
30
|
-
tables__turbo__collection_query_value: current_query,
|
31
|
-
tables__turbo__collection_sort_value: collection.sort,
|
32
|
-
},
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
def current_query
|
37
|
-
Rack::Utils.build_nested_query(collection.to_params)
|
38
|
-
end
|
39
|
-
|
40
|
-
def default_header_options
|
41
|
-
{ link: { data: { turbo_stream: "" } } }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|