avo 2.7.1.pre.1 → 2.8.0

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

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +5 -5
  4. data/app/components/avo/alert_component.rb +6 -0
  5. data/app/components/avo/card_component.html.erb +2 -2
  6. data/app/components/avo/common_field_wrapper_component.html.erb +10 -3
  7. data/app/components/avo/common_field_wrapper_component.rb +27 -1
  8. data/app/components/avo/edit/field_wrapper_component.html.erb +1 -1
  9. data/app/components/avo/fields/badge_field/index_component.html.erb +1 -1
  10. data/app/components/avo/fields/badge_field/show_component.html.erb +1 -1
  11. data/app/components/avo/fields/belongs_to_field/autocomplete_component.html.erb +21 -10
  12. data/app/components/avo/fields/belongs_to_field/autocomplete_component.rb +7 -1
  13. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +27 -15
  14. data/app/components/avo/fields/belongs_to_field/edit_component.rb +4 -0
  15. data/app/components/avo/fields/belongs_to_field/index_component.html.erb +1 -1
  16. data/app/components/avo/fields/belongs_to_field/show_component.html.erb +1 -1
  17. data/app/components/avo/fields/boolean_field/edit_component.html.erb +4 -2
  18. data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
  19. data/app/components/avo/fields/boolean_field/show_component.html.erb +1 -1
  20. data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +7 -1
  21. data/app/components/avo/fields/boolean_group_field/index_component.html.erb +1 -1
  22. data/app/components/avo/fields/boolean_group_field/show_component.html.erb +1 -1
  23. data/app/components/avo/fields/code_field/edit_component.html.erb +7 -5
  24. data/app/components/avo/fields/code_field/show_component.html.erb +2 -2
  25. data/app/components/avo/fields/common/key_value_component.html.erb +10 -4
  26. data/app/components/avo/fields/common/key_value_component.rb +2 -0
  27. data/app/components/avo/fields/country_field/edit_component.html.erb +4 -2
  28. data/app/components/avo/fields/country_field/index_component.html.erb +1 -1
  29. data/app/components/avo/fields/country_field/show_component.html.erb +1 -1
  30. data/app/components/avo/fields/date_field/edit_component.html.erb +6 -4
  31. data/app/components/avo/fields/date_field/index_component.html.erb +1 -1
  32. data/app/components/avo/fields/date_field/show_component.html.erb +1 -1
  33. data/app/components/avo/fields/date_time_field/edit_component.html.erb +6 -4
  34. data/app/components/avo/fields/date_time_field/index_component.html.erb +1 -1
  35. data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -1
  36. data/app/components/avo/fields/edit_component.rb +7 -0
  37. data/app/components/avo/fields/external_image_field/edit_component.html.erb +5 -2
  38. data/app/components/avo/fields/external_image_field/index_component.html.erb +6 -4
  39. data/app/components/avo/fields/external_image_field/show_component.html.erb +1 -1
  40. data/app/components/avo/fields/file_field/edit_component.html.erb +6 -1
  41. data/app/components/avo/fields/file_field/index_component.html.erb +1 -1
  42. data/app/components/avo/fields/file_field/show_component.html.erb +1 -1
  43. data/app/components/avo/fields/files_field/edit_component.html.erb +7 -1
  44. data/app/components/avo/fields/files_field/index_component.html.erb +1 -1
  45. data/app/components/avo/fields/files_field/show_component.html.erb +1 -1
  46. data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
  47. data/app/components/avo/fields/gravatar_field/show_component.html.erb +1 -1
  48. data/app/components/avo/fields/has_one_field/index_component.html.erb +1 -1
  49. data/app/components/avo/fields/hidden_field/edit_component.html.erb +5 -1
  50. data/app/components/avo/fields/id_field/edit_component.html.erb +1 -1
  51. data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
  52. data/app/components/avo/fields/id_field/show_component.html.erb +1 -1
  53. data/app/components/avo/fields/index_component.rb +3 -0
  54. data/app/components/avo/fields/key_value_field/edit_component.html.erb +1 -1
  55. data/app/components/avo/fields/key_value_field/show_component.html.erb +1 -1
  56. data/app/components/avo/fields/markdown_field/edit_component.html.erb +8 -5
  57. data/app/components/avo/fields/markdown_field/show_component.html.erb +1 -1
  58. data/app/components/avo/fields/number_field/edit_component.html.erb +7 -4
  59. data/app/components/avo/fields/number_field/index_component.html.erb +1 -1
  60. data/app/components/avo/fields/number_field/show_component.html.erb +1 -1
  61. data/app/components/avo/fields/password_field/edit_component.html.erb +4 -2
  62. data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +7 -4
  63. data/app/components/avo/fields/progress_bar_field/index_component.html.erb +1 -1
  64. data/app/components/avo/fields/progress_bar_field/show_component.html.erb +1 -1
  65. data/app/components/avo/fields/select_field/edit_component.html.erb +9 -3
  66. data/app/components/avo/fields/select_field/index_component.html.erb +1 -1
  67. data/app/components/avo/fields/select_field/show_component.html.erb +1 -1
  68. data/app/components/avo/fields/show_component.rb +3 -0
  69. data/app/components/avo/fields/status_field/edit_component.html.erb +6 -3
  70. data/app/components/avo/fields/status_field/index_component.html.erb +1 -1
  71. data/app/components/avo/fields/status_field/show_component.html.erb +1 -1
  72. data/app/components/avo/fields/tags_field/edit_component.html.erb +19 -11
  73. data/app/components/avo/fields/tags_field/index_component.html.erb +1 -1
  74. data/app/components/avo/fields/tags_field/show_component.html.erb +1 -1
  75. data/app/components/avo/fields/text_field/edit_component.html.erb +5 -2
  76. data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
  77. data/app/components/avo/fields/text_field/show_component.html.erb +1 -1
  78. data/app/components/avo/fields/textarea_field/edit_component.html.erb +6 -3
  79. data/app/components/avo/fields/textarea_field/show_component.html.erb +1 -1
  80. data/app/components/avo/fields/trix_field/edit_component.html.erb +13 -4
  81. data/app/components/avo/fields/trix_field/edit_component.rb +3 -0
  82. data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
  83. data/app/components/avo/index/field_wrapper_component.html.erb +12 -5
  84. data/app/components/avo/index/field_wrapper_component.rb +27 -3
  85. data/app/components/avo/panel_component.rb +4 -3
  86. data/app/components/avo/resource_component.rb +1 -0
  87. data/app/components/avo/show/field_wrapper_component.html.erb +1 -1
  88. data/app/components/avo/show/field_wrapper_component.rb +2 -1
  89. data/app/components/avo/views/resource_edit_component.html.erb +7 -4
  90. data/app/components/avo/views/resource_edit_component.rb +2 -1
  91. data/app/components/avo/views/resource_index_component.html.erb +6 -3
  92. data/app/components/avo/views/resource_index_component.rb +7 -1
  93. data/app/components/avo/views/resource_new_component.html.erb +7 -2
  94. data/app/components/avo/views/resource_new_component.rb +2 -1
  95. data/app/components/avo/views/resource_show_component.html.erb +9 -7
  96. data/app/components/avo/views/resource_show_component.rb +1 -0
  97. data/app/controllers/avo/actions_controller.rb +4 -1
  98. data/app/controllers/avo/base_controller.rb +14 -8
  99. data/app/controllers/avo/search_controller.rb +7 -1
  100. data/app/javascript/js/controllers/custom/course_resource_controller.js +102 -0
  101. data/app/javascript/js/controllers/fields/code_field_controller.js +7 -1
  102. data/app/javascript/js/controllers/fields/key_value_controller.js +1 -0
  103. data/app/javascript/js/controllers/fields/tags_field_controller.js +0 -1
  104. data/app/javascript/js/controllers/menu_controller.js +4 -3
  105. data/app/javascript/js/controllers/resource_edit_controller.js +72 -0
  106. data/app/javascript/js/controllers/resource_index_controller.js +4 -0
  107. data/app/javascript/js/controllers/resource_show_controller.js +4 -0
  108. data/app/javascript/js/controllers/search_controller.js +28 -5
  109. data/app/javascript/js/controllers.js +10 -0
  110. data/app/views/avo/associations/new.html.erb +2 -1
  111. data/app/views/avo/base/_select_filter.html.erb +1 -1
  112. data/app/views/avo/base/_text_filter.html.erb +1 -0
  113. data/app/views/avo/partials/_logo.html.erb +3 -2
  114. data/app/views/avo/partials/_navbar.html.erb +1 -1
  115. data/config/routes.rb +1 -1
  116. data/db/factories.rb +1 -0
  117. data/lib/avo/base_action.rb +9 -2
  118. data/lib/avo/base_card.rb +0 -23
  119. data/lib/avo/base_resource.rb +17 -15
  120. data/lib/avo/concerns/has_fields.rb +93 -0
  121. data/lib/avo/concerns/has_html_attributes.rb +110 -0
  122. data/lib/avo/concerns/has_stimulus_controllers.rb +42 -0
  123. data/lib/avo/fields/base_field.rb +23 -13
  124. data/lib/avo/fields/select_field.rb +1 -1
  125. data/lib/avo/grid_collector.rb +4 -4
  126. data/lib/avo/html/builder.rb +117 -0
  127. data/lib/avo/licensing/pro_license.rb +1 -0
  128. data/lib/avo/version.rb +1 -1
  129. data/lib/avo.rb +4 -0
  130. data/lib/generators/avo/templates/cards/chartkick_card_sample.tt +11 -1
  131. data/lib/generators/avo/templates/cards/metric_card_sample.tt +11 -1
  132. data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +1 -1
  133. data/lib/generators/avo/templates/field/components/index_component.html.erb.tt +1 -1
  134. data/lib/generators/avo/templates/field/components/show_component.html.erb.tt +1 -1
  135. data/lib/generators/avo/templates/initializer/avo.tt +1 -1
  136. data/lib/generators/avo/templates/locales/avo.en.yml +3 -3
  137. data/public/avo-assets/avo.css +28 -8
  138. data/public/avo-assets/avo.js +148 -148
  139. data/public/avo-assets/avo.js.map +3 -3
  140. data/public/avo-assets/logomark.png +0 -0
  141. metadata +13 -10
  142. data/app/assets/builds/action_cable.js +0 -2
  143. data/app/assets/builds/action_cable.js.map +0 -7
  144. data/app/assets/builds/avo.css +0 -9610
  145. data/app/assets/builds/avo.js +0 -512
  146. data/app/assets/builds/avo.js.map +0 -7
  147. data/lib/avo/fields_collector.rb +0 -70
@@ -1,8 +1,10 @@
1
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true do %>
2
2
  <% if @field.value.present? %>
3
- <%= image_tag @field.value,
4
- height: @field.height,
5
- style: "border-radius: #{@field.radius}px; max-height: #{@field.height}#{@field.height.to_s&.ends_with?('px') ? '' : 'px'};"
3
+ <%= link_to_if @field.link_to_resource.present?,
4
+ image_tag(@field.value,
5
+ height: @field.height,
6
+ style: "border-radius: #{@field.radius}px; max-height: #{@field.height}#{@field.height.to_s&.ends_with?('px') ? '' : 'px'};"),
7
+ resource_path
6
8
  %>
7
9
  <% end %>
8
10
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource do %>
2
2
  <% if @field.value.present? %>
3
3
  <%= image_tag @field.value, style: 'max-width: 340px;' %>
4
4
  <% end %>
@@ -6,6 +6,11 @@
6
6
  <% end %>
7
7
 
8
8
  <% if @resource.authorization.authorize_action(:upload_attachments?, raise_exception: false) %>
9
- <%= @form.file_field @field.id, disabled: @field.readonly, direct_upload: @field.direct_upload %>
9
+ <%= @form.file_field @field.id,
10
+ data: @field.get_html(:data, view: view, element: :input),
11
+ direct_upload: @field.direct_upload,
12
+ disabled: @field.readonly,
13
+ style: @field.get_html(:style, view: view, element: :input)
14
+ %>
10
15
  <% end %>
11
16
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field, flush: flush? do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: flush? do %>
2
2
  <% if @field.value.present? %>
3
3
  <% if @field.value.attached? && @field.value.representable? && @field.is_image %>
4
4
  <%= link_to_if @field.link_to_resource, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'), resource_path, class: 'block' %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= render Avo::Fields::Common::SingleFileViewerComponent.new resource: @resource, field: @field %>
3
3
  <% end %>
@@ -3,7 +3,13 @@
3
3
 
4
4
  <% if @resource.authorization.authorize_action(:upload_attachments?, raise_exception: false) %>
5
5
  <div class="mt-2">
6
- <%= @form.file_field @field.id, disabled: @field.readonly, multiple: true, direct_upload: @field.direct_upload %>
6
+ <%= @form.file_field @field.id,
7
+ data: @field.get_html(:data, view: view, element: :input),
8
+ direct_upload: @field.direct_upload,
9
+ disabled: @field.readonly,
10
+ multiple: true,
11
+ style: @field.get_html(:style, view: view, element: :input)
12
+ %>
7
13
  </div>
8
14
  <% end %>
9
15
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.value.attachments.length %> files
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, full_width: true do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, full_width: true do %>
2
2
  <%= render Avo::Fields::Common::FilesListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true do %>
2
2
  <%= render Avo::Fields::Common::GravatarViewerComponent.new(
3
3
  md5: @field.md5,
4
4
  default: @field.default,
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= render Avo::Fields::Common::GravatarViewerComponent.new(
3
3
  md5: @field.md5,
4
4
  default: @field.default,
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= link_to @field.label, helpers.resource_path(model: @field.value, resource: @field.target_resource) %>
3
3
  <% end %>
@@ -1 +1,5 @@
1
- <%= @form.hidden_field @field.id %>
1
+ <%= @form.hidden_field @field.id,
2
+ class: @field.get_html(:classes, view: view, element: :input),
3
+ data: @field.get_html(:data, view: view, element: :input),
4
+ style: @field.get_html(:style, view: view, element: :input)
5
+ %>
@@ -1,3 +1,3 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
- <%= field.value %>
2
+ <%= @field.value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field, class: 'whitespace-no-wrap w-[1%]' do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, class: 'whitespace-no-wrap w-[1%]' do %>
2
2
  <% link_to_if (@field.link_to_resource or Avo.configuration.id_links_to_resource), @field.value, resource_path, title: t('avo.view_item', item: @resource.name).humanize %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -3,11 +3,14 @@
3
3
  class Avo::Fields::IndexComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
+ attr_reader :view
7
+
6
8
  def initialize(field: nil, resource: nil, index: 0, parent_model: nil)
7
9
  @field = field
8
10
  @resource = resource
9
11
  @index = index
10
12
  @parent_model = parent_model
13
+ @view = :index
11
14
  end
12
15
 
13
16
  def resource_path
@@ -1,3 +1,3 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
2
- <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, form: @form, view: :edit %>
2
+ <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, form: @form, view: @resource.view %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index, full_width: true do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index, full_width: true do %>
2
2
  <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, view: :show %>
3
3
  <% end %>
@@ -1,12 +1,15 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
2
2
  <div data-controller="simple-mde">
3
3
  <%= @form.text_area @field.id,
4
- class: helpers.input_classes('w-full js-has-simple-mde-editor', has_error: @field.model_errors.include?(@field.id)),
5
- placeholder: @field.placeholder,
4
+ class: classes("w-full js-has-simple-mde-editor"),
5
+ data: {
6
+ view: @resource.view,
7
+ 'simple-mde-target': 'element',
8
+ 'component-options': @field.options.to_json,
9
+ },
6
10
  disabled: @field.readonly,
7
- 'data-simple-mde-target': 'element',
8
- 'data-component-options': @field.options.to_json,
9
- 'data-view': :edit
11
+ placeholder: @field.placeholder,
12
+ style: @field.get_html(:style, view: view, element: :input)
10
13
  %>
11
14
  </div>
12
15
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index, full_width: true do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index, full_width: true do %>
2
2
  <div data-controller="simple-mde">
3
3
  <%= text_area_tag @field.id, @field.value,
4
4
  class: helpers.input_classes('w-full js-has-simple-mde-editor'),
@@ -1,9 +1,12 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.number_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
4
- placeholder: @field.placeholder,
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: @field.readonly,
6
- min: @field.min,
7
6
  max: @field.max,
8
- step: @field.step %>
7
+ min: @field.min,
8
+ placeholder: @field.placeholder,
9
+ step: @field.step,
10
+ style: @field.get_html(:style, view: view, element: :input)
11
+ %>
9
12
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -1,7 +1,9 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.password_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
+ disabled: @field.readonly,
4
6
  placeholder: @field.placeholder,
5
- disabled: @field.readonly
7
+ style: @field.get_html(:style, view: view, element: :input)
6
8
  %>
7
9
  <% end %>
@@ -5,12 +5,15 @@
5
5
  </div>
6
6
  <% end %>
7
7
  <%= @form.range_field @field.id,
8
- min: 0,
8
+ class: "w-full #{@field.get_html(:classes, view: view, element: :input)}",
9
+ data: @field.get_html(:data, view: view, element: :input),
10
+ disabled: @field.readonly,
9
11
  max: @field.max,
10
- step: @field.step,
11
- class: 'w-full',
12
+ min: 0,
12
13
  placeholder: @field.placeholder,
13
- disabled: @field.readonly %>
14
+ step: @field.step,
15
+ style: @field.get_html(:style, view: view, element: :input)
16
+ %>
14
17
  <% end %>
15
18
 
16
19
 
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true do %>
2
2
  <% if @field.display_value %>
3
3
  <div class="text-center text-sm font-semibold w-full leading-none mb-1">
4
4
  <%= @field.value %><%= @field.value_suffix if @field.value_suffix.present? %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <% if @field.display_value %>
3
3
  <div class="text-center text-sm font-semibold w-full leading-none mb-1">
4
4
  <%= @field.value %><%= @field.value_suffix if @field.value_suffix.present? %>
@@ -1,6 +1,12 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.select @field.id, @field.options_for_select, { selected: @field.value, prompt: @field.placeholder }, {
3
- class: helpers.input_classes(' w-full', has_error: @field.model_errors.include?(@field.id)),
4
- disabled: @field.readonly,
5
- value: @field.model.present? ? @field.model[@field.id] : @field.value } %>
3
+ aria: {
4
+ placeholder: @field.placeholder
5
+ },
6
+ class: classes("w-full"),
7
+ data: @field.get_html(:data, view: view, element: :input),
8
+ disabled: @field.readonly,
9
+ style: @field.get_html(:style, view: view, element: :input),
10
+ value: @field.model.present? ? @field.model[@field.id] : @field.value
11
+ } %>
6
12
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.label %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.label %>
3
3
  <% end %>
@@ -3,9 +3,12 @@
3
3
  class Avo::Fields::ShowComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
+ attr_reader :view
7
+
6
8
  def initialize(field: nil, resource: nil, index: 0)
7
9
  @field = field
8
10
  @resource = resource
9
11
  @index = index
12
+ @view = :show
10
13
  end
11
14
  end
@@ -1,7 +1,10 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.text_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
4
- placeholder: @field.placeholder,
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: @field.readonly,
6
- value: @resource.model.present? ? @resource.model[@field.id] : @field.value %>
6
+ placeholder: @field.placeholder,
7
+ style: @field.get_html(:style, view: view, element: :input),
8
+ value: @resource.model.present? ? @resource.model[@field.id] : @field.value
9
+ %>
7
10
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= render Avo::Fields::Common::StatusViewerComponent.new label: @field.value, status: @field.status %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= render Avo::Fields::Common::StatusViewerComponent.new label: @field.value, status: @field.status %>
3
3
  <% end %>
@@ -1,20 +1,23 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= edit_field_wrapper field: @field,
2
+ index: @index,
3
+ form: @form,
4
+ resource: @resource,
5
+ displayed_in_modal: @displayed_in_modal do %>
2
6
  <div data-controller="tags-field">
3
7
  <%# dummy field %>
4
8
  <%= text_field_tag "#{@field.id}-dummy", '',
5
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
6
- placeholder: @field.placeholder,
7
- disabled: @field.readonly,
8
- value: '',
9
+ class: classes("w-full"),
9
10
  data: {
10
11
  'tags-field-target': 'fakeInput',
11
- } %>
12
+ },
13
+ disabled: @field.readonly,
14
+ placeholder: @field.placeholder,
15
+ style: @field.get_html(:style, view: view, element: :input),
16
+ value: ''
17
+ %>
12
18
  <%# real field %>
13
19
  <%= @form.text_field @field.id,
14
- class: helpers.input_classes('hidden w-full', has_error: @field.model_errors.include?(@field.id)),
15
- placeholder: @field.placeholder,
16
- disabled: @field.readonly,
17
- value: @field.field_value.to_json,
20
+ class: classes("hidden w-full"),
18
21
  data: {
19
22
  'tags-field-target': 'input',
20
23
  'whitelist-items': @field.suggestions.to_json,
@@ -22,6 +25,11 @@
22
25
  'enforce-suggestions': @field.enforce_suggestions ? 1 : 0,
23
26
  'delimiters': @field.delimiters,
24
27
  'close-on-select': @field.close_on_select ? 1 : 0,
25
- } %>
28
+ },
29
+ disabled: @field.readonly,
30
+ placeholder: @field.placeholder,
31
+ style: @field.get_html(:style, view: view, element: :input),
32
+ value: @field.field_value.to_json
33
+ %>
26
34
  </div>
27
35
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true do %>
2
2
  <div class="flex gap-1 items-center flex-nowrap">
3
3
  <% value.take(3).each do |item| %>
4
4
  <%= render Avo::Fields::TagsField::TagComponent.new(label: label_from_item(item)) %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <div class="flex gap-1 items-center flex-wrap">
3
3
  <% @field.field_value.each do |item| %>
4
4
  <%= render Avo::Fields::TagsField::TagComponent.new(label: label_from_item(item)) %>
@@ -1,6 +1,9 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.text_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
+ disabled: @field.readonly,
4
6
  placeholder: @field.placeholder,
5
- disabled: @field.readonly %>
7
+ style: @field.get_html(:style, view: view, element: :input)
8
+ %>
6
9
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <% if @field.as_html %>
3
3
  <%== @field.value %>
4
4
  <% else %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <% if @field.as_html %>
3
3
  <%== @field.value %>
4
4
  <% else %>
@@ -1,7 +1,10 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.text_area @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
4
- placeholder: @field.placeholder,
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: @field.readonly,
6
- rows: @field.rows %>
6
+ placeholder: @field.placeholder,
7
+ rows: @field.rows,
8
+ style: @field.get_html(:style, view: view, element: :input)
9
+ %>
7
10
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -11,13 +11,22 @@
11
11
  data-hide-attachment-url="<%= @field.hide_attachment_url %>"
12
12
  class="relative block overflow-x-auto max-w-full"
13
13
  >
14
- <% trix_id = "trix_#{@resource.name.underscore}_#{@field.id}" %>
15
- <trix-editor data-trix-field-target="editor" input="<%= trix_id %>" placeholder="<%= @field.placeholder %>"><%== @field.value %></trix-editor>
14
+ <%= content_tag 'trix-editor',
15
+ data: {
16
+ "trix-field-target": "editor",
17
+ **@field.get_html(:data, view: view, element: :input)
18
+ },
19
+ input: trix_id,
20
+ placeholder: @field.placeholder do %>
21
+ <%== @field.value %>
22
+ <% end %>
16
23
  <%= @form.text_area @field.id,
24
+ class: classes("w-full hidden"),
25
+ data: @field.get_html(:data, view: view, element: :input),
26
+ disabled: @field.readonly,
17
27
  id: trix_id,
18
- class: helpers.input_classes('w-full hidden', has_error: (@resource.model.present? and @resource.model.errors.include?(@field.id))),
19
28
  placeholder: @field.placeholder,
20
- disabled: @field.readonly
29
+ style: @field.get_html(:style, view: view, element: :input)
21
30
  %>
22
31
  </div>
23
32
  <% end %>
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::Fields::TrixField::EditComponent < Avo::Fields::EditComponent
4
+ def trix_id
5
+ "trix_#{@resource.name.underscore}_#{@field.id}"
6
+ end
4
7
  end
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%
3
3
  content_classes = 'prose prose-sm'
4
4
  content_classes << ' hidden' unless @field.always_show
@@ -1,13 +1,20 @@
1
- <td class="min-h-[3rem] px-3 leading-tight whitespace-nowrap h-full text-slate-800 text-base <%= classes %>" data-field-id="<%= @field.id %>" data-field-type="<%= @field.type %>">
1
+ <%= content_tag :td,
2
+ class: "min-h-[3rem] px-3 leading-tight whitespace-nowrap h-full text-slate-800 text-base #{classes}",
3
+ data: {
4
+ field_id: @field.id,
5
+ field_type: @field.type,
6
+ **stimulus_attributes
7
+ },
8
+ style: style do %>
2
9
  <% if @field.value.blank? && @dash_if_blank %>
3
10
 
4
11
  <% else %>
5
12
  <% if @center_content %>
6
- <div class="flex items-center justify-center">
7
- <%= content %>
8
- </div>
13
+ <div class="flex items-center justify-center">
14
+ <%= content %>
15
+ </div>
9
16
  <% else %>
10
17
  <%= content %>
11
18
  <% end %>
12
19
  <% end %>
13
- </td>
20
+ <% end %>
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::Index::FieldWrapperComponent < ViewComponent::Base
4
- def initialize(field: nil, dash_if_blank: true, center_content: false, flush: false, **args)
4
+ attr_reader :view
5
+
6
+ def initialize(field: nil, resource: nil, dash_if_blank: true, center_content: false, flush: false, **args)
5
7
  @field = field
8
+ @resource = resource
6
9
  @dash_if_blank = dash_if_blank
7
10
  @center_content = center_content
8
11
  @classes = args[:class].present? ? args[:class] : ""
9
12
  @args = args
10
13
  @flush = flush
14
+ @view = :index
11
15
  end
12
16
 
13
17
  def classes
@@ -18,18 +22,38 @@ class Avo::Index::FieldWrapperComponent < ViewComponent::Base
18
22
  end
19
23
 
20
24
  result += " #{text_align_classes}"
25
+ result += " #{@field.get_html(:classes, view: view, element: :wrapper)}"
21
26
 
22
27
  result
23
28
  end
24
29
 
30
+ def style
31
+ @field.get_html(:style, view: view, element: :wrapper)
32
+ end
33
+
34
+ def stimulus_attributes
35
+ attributes = {}
36
+
37
+ @resource.get_stimulus_controllers.split(" ").each do |controller|
38
+ attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
39
+ end
40
+
41
+ wrapper_data_attributes = @field.get_html :data, view: view, element: :wrapper
42
+ if wrapper_data_attributes.present?
43
+ attributes.merge! wrapper_data_attributes
44
+ end
45
+
46
+ attributes
47
+ end
48
+
25
49
  private
26
50
 
27
51
  def text_align_classes
28
52
  case @field.index_text_align.to_sym
29
53
  when :right
30
- 'text-right'
54
+ "text-right"
31
55
  when :center
32
- 'text-center'
56
+ "text-center"
33
57
  end
34
58
  end
35
59
  end
@@ -25,9 +25,10 @@ class Avo::PanelComponent < ViewComponent::Base
25
25
  end
26
26
 
27
27
  def data_attributes
28
- @data.merge({'panel-index': @index}).map do |key, value|
29
- " data-#{key}=\"#{value}\""
30
- end.join
28
+ @data.merge({"panel-index": @index})
29
+ .map do |key, value|
30
+ " data-#{key}=\"#{value}\""
31
+ end.join
31
32
  end
32
33
 
33
34
  def display_breadcrumbs?
@@ -4,6 +4,7 @@ class Avo::ResourceComponent < Avo::BaseComponent
4
4
  attr_reader :has_many_panels
5
5
  attr_reader :has_as_belongs_to_many_panels
6
6
  attr_reader :resource_tools
7
+ attr_reader :view
7
8
 
8
9
  def can_create?
9
10
  return authorize_association_for(:create) if @reflection.present?
@@ -1,4 +1,4 @@
1
- <%= render Avo::CommonFieldWrapperComponent.new(field: @field, dash_if_blank: @dash_if_blank, full_width: @full_width) do %>
1
+ <%= render Avo::CommonFieldWrapperComponent.new(field: @field, resource: @resource, dash_if_blank: @dash_if_blank, full_width: @full_width, view: :show) do %>
2
2
  <div class="self-center <% if @full_width %> w-full <% else %> w-full md:w-8/12 <% end %>" data-slot="value">
3
3
  <% if @field.value.blank? and @dash_if_blank %>
4
4
 
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::Show::FieldWrapperComponent < ViewComponent::Base
4
- def initialize(field: nil, dash_if_blank: true, full_width: false, **args)
4
+ def initialize(field: nil, resource: nil, dash_if_blank: true, full_width: false, **args)
5
5
  @field = field
6
+ @resource = resource
6
7
  @dash_if_blank = dash_if_blank
7
8
  @classes = args[:class].present? ? args[:class] : ""
8
9
  @args = args