katalyst-content 3.0.0.alpha.1 → 3.0.0.alpha.3

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -5
  3. data/app/assets/builds/katalyst/content.esm.js +9 -4
  4. data/app/assets/builds/katalyst/content.js +9 -4
  5. data/app/assets/builds/katalyst/content.min.js +1 -1
  6. data/app/assets/builds/katalyst/content.min.js.map +1 -1
  7. data/app/assets/stylesheets/katalyst/content/_editor.scss +4 -0
  8. data/app/assets/stylesheets/katalyst/content/_frontend.scss +1 -0
  9. data/app/assets/stylesheets/katalyst/content/editor/editor.css +200 -0
  10. data/app/assets/stylesheets/katalyst/content/editor.css +4 -196
  11. data/app/assets/stylesheets/katalyst/content/frontend/frontend.css +46 -0
  12. data/app/assets/stylesheets/katalyst/content/frontend.css +1 -0
  13. data/app/components/katalyst/content/editor/item_component.html.erb +6 -4
  14. data/app/components/katalyst/content/editor/new_items_component.html.erb +10 -8
  15. data/app/components/katalyst/content/editor/new_items_component.rb +26 -2
  16. data/app/components/katalyst/content/editor_component.html.erb +2 -1
  17. data/app/components/katalyst/content/editor_component.rb +4 -6
  18. data/app/helpers/katalyst/content/frontend_helper.rb +40 -24
  19. data/app/javascript/content/editor/item_editor_controller.js +4 -2
  20. data/app/javascript/content/editor/new_items_controller.js +7 -2
  21. data/app/models/concerns/katalyst/content/has_tree.rb +16 -3
  22. data/app/models/katalyst/content/item.rb +15 -7
  23. data/app/views/katalyst/content/asides/_aside.html+form.erb +2 -2
  24. data/app/views/katalyst/content/asides/_aside.html.erb +5 -7
  25. data/app/views/katalyst/content/columns/_column.html+form.erb +2 -2
  26. data/app/views/katalyst/content/columns/_column.html.erb +3 -3
  27. data/app/views/katalyst/content/contents/_content.html+form.erb +2 -2
  28. data/app/views/katalyst/content/contents/_content.html.erb +2 -2
  29. data/app/views/katalyst/content/figures/_figure.html+form.erb +2 -2
  30. data/app/views/katalyst/content/figures/_figure.html.erb +1 -1
  31. data/app/views/katalyst/content/groups/_group.html+form.erb +2 -2
  32. data/app/views/katalyst/content/groups/_group.html.erb +1 -3
  33. data/app/views/katalyst/content/items/_item.html+form.erb +2 -2
  34. data/app/views/katalyst/content/items/edit.html.erb +6 -11
  35. data/app/views/katalyst/content/sections/_section.html+form.erb +2 -2
  36. data/app/views/katalyst/content/sections/_section.html.erb +3 -5
  37. data/app/views/katalyst/content/tables/_table.html+form.erb +2 -2
  38. data/config/locales/en.yml +11 -0
  39. data/db/migrate/20250321045027_rename_background_to_theme.rb +7 -0
  40. data/lib/katalyst/content/config.rb +4 -1
  41. data/spec/factories/katalyst/content/items.rb +1 -1
  42. metadata +11 -7
  43. data/app/assets/stylesheets/katalyst/_content.scss +0 -4
  44. data/app/assets/stylesheets/katalyst/content.css +0 -4
  45. /data/app/assets/stylesheets/katalyst/content/{icons.css → editor/icons.css} +0 -0
  46. /data/app/assets/stylesheets/katalyst/content/{status-bar.css → editor/status-bar.css} +0 -0
  47. /data/app/assets/stylesheets/katalyst/content/{table.css → editor/table.css} +0 -0
@@ -12,6 +12,10 @@ export default class ItemEditorController extends Controller {
12
12
  this.element.removeEventListener("turbo:submit-end", this.onSubmit);
13
13
  }
14
14
 
15
+ click(e) {
16
+ if (e.target.tagName === "DIALOG") this.dismiss();
17
+ }
18
+
15
19
  dismiss() {
16
20
  if (!this.dialogTarget) return;
17
21
  if (!this.dialogTarget.open) this.dialogTarget.close();
@@ -39,8 +43,6 @@ export default class ItemEditorController extends Controller {
39
43
  }
40
44
  };
41
45
 
42
- noop() {}
43
-
44
46
  #removeTargetItem() {
45
47
  const el = document.getElementById(this.dialogTarget.dataset.itemId);
46
48
  const item = new Item(el.closest("[data-content-item]"));
@@ -1,5 +1,7 @@
1
1
  import { Controller } from "@hotwired/stimulus";
2
2
 
3
+ import Item from "./item";
4
+
3
5
  const EDGE_AREA = 24;
4
6
 
5
7
  export default class NewItemsController extends Controller {
@@ -14,6 +16,10 @@ export default class NewItemsController extends Controller {
14
16
  delete this.currentItem;
15
17
  }
16
18
 
19
+ click(e) {
20
+ if (e.target.tagName === "DIALOG") this.close(e);
21
+ }
22
+
17
23
  open(e) {
18
24
  e.preventDefault();
19
25
  this.dialog.showModal();
@@ -24,8 +30,6 @@ export default class NewItemsController extends Controller {
24
30
  this.dialog.close();
25
31
  }
26
32
 
27
- noop(e) {}
28
-
29
33
  /**
30
34
  * Add the selected item to the DOM at the current position or the end of the list.
31
35
  */
@@ -38,6 +42,7 @@ export default class NewItemsController extends Controller {
38
42
 
39
43
  if (target) {
40
44
  target.insertAdjacentElement("beforebegin", item);
45
+ new Item(item).depth = new Item(target).depth;
41
46
  } else {
42
47
  this.list.insertAdjacentElement("beforeend", item);
43
48
  }
@@ -20,9 +20,7 @@ module Katalyst
20
20
 
21
21
  def add(node)
22
22
  if node.depth == depth
23
- node.parent = current
24
- children << node
25
- self
23
+ add_sibling(node)
26
24
  elsif node.depth > depth
27
25
  push(children.last)
28
26
  add(node)
@@ -32,6 +30,21 @@ module Katalyst
32
30
  end
33
31
  end
34
32
 
33
+ def add_sibling(node)
34
+ node.parent = current
35
+
36
+ previous = children.last
37
+
38
+ children << node
39
+
40
+ if previous
41
+ previous.next_sibling = node
42
+ node.previous_sibling = previous
43
+ end
44
+
45
+ self
46
+ end
47
+
35
48
  private
36
49
 
37
50
  attr_writer :current, :depth, :children
@@ -16,12 +16,12 @@ module Katalyst
16
16
 
17
17
  validates :heading, presence: true
18
18
  validates :heading_style, inclusion: { in: config.heading_styles }
19
- validates :background, presence: true, inclusion: { in: config.backgrounds }, if: :validate_background?
19
+ validates :theme, inclusion: { in: config.themes, allow_blank: true }
20
20
 
21
21
  after_initialize :initialize_tree
22
22
  before_validation :set_defaults
23
23
 
24
- attr_accessor :parent, :children, :index, :depth
24
+ attr_accessor :parent, :children, :index, :depth, :previous_sibling, :next_sibling
25
25
 
26
26
  def self.permitted_params
27
27
  %i[
@@ -30,7 +30,7 @@ module Katalyst
30
30
  type
31
31
  heading
32
32
  heading_style
33
- background
33
+ theme
34
34
  visible
35
35
  ]
36
36
  end
@@ -51,6 +51,18 @@ module Katalyst
51
51
  is_a? Layout
52
52
  end
53
53
 
54
+ def dom_id
55
+ heading&.parameterize
56
+ end
57
+
58
+ def item_type
59
+ model_name.param_key
60
+ end
61
+
62
+ def theme
63
+ super.presence || parent&.theme
64
+ end
65
+
54
66
  private
55
67
 
56
68
  def initialize_tree
@@ -61,10 +73,6 @@ module Katalyst
61
73
  def set_defaults
62
74
  self.heading_style = "none" if heading_style.blank?
63
75
  end
64
-
65
- def validate_background?
66
- true
67
- end
68
76
  end
69
77
  end
70
78
  end
@@ -13,8 +13,8 @@
13
13
  </div>
14
14
 
15
15
  <div class="field">
16
- <%= form.label :background %>
17
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
16
+ <%= form.label :theme %>
17
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
18
18
  </div>
19
19
 
20
20
  <div class="field">
@@ -1,16 +1,14 @@
1
- <%= content_item_tag aside do %>
1
+ <%= content_item_tag(aside, data: { aside_reverse: ("" if aside.reverse) }) do %>
2
2
  <%= tag.h3 aside.heading, class: aside.heading_style_class if aside.show_heading? %>
3
3
 
4
4
  <% if aside.children.any? %>
5
5
  <% items = aside.children.select(&:visible?) %>
6
6
  <% last = items.pop %>
7
- <div role="aside-container" <%= "class=reverse" if aside.reverse %>>
8
- <div>
9
- <%= render_content_items items %>
7
+ <div class="sidebar">
8
+ <div class="aside--main">
9
+ <%= render_content_items(*items, theme: aside.theme, class: "flow") %>
10
10
  </div>
11
- <aside>
12
- <%= render_content_items [last] %>
13
- </aside>
11
+ <%= render_content_items(last, tag: :aside, class: "aside--sidebar", theme: aside.theme) %>
14
12
  </div>
15
13
  <% end %>
16
14
  <% end %>
@@ -13,8 +13,8 @@
13
13
  </div>
14
14
 
15
15
  <div class="field">
16
- <%= form.label :background %>
17
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
16
+ <%= form.label :theme %>
17
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
18
18
  </div>
19
19
 
20
20
  <div class="field">
@@ -6,13 +6,13 @@
6
6
  <div class="columns-container">
7
7
  <div class="column">
8
8
  <% if items.any? %>
9
- <%= render_content_items items %>
9
+ <%= render_content_items(*items, theme: column.theme, class: "flow") %>
10
10
  <% elsif last %>
11
- <%= render_content_items [last] %>
11
+ <%= render_content_items(last, theme: column.theme) %>
12
12
  <% end %>
13
13
  </div>
14
14
  <div class="column">
15
- <%= render_content_items [last] if last && items.any? %>
15
+ <%= render_content_items(last, theme: column.theme) if last && items.any? %>
16
16
  </div>
17
17
  </div>
18
18
  <% end %>
@@ -13,8 +13,8 @@
13
13
  </div>
14
14
 
15
15
  <div class="field">
16
- <%= form.label :background %>
17
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
16
+ <%= form.label :theme %>
17
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
18
18
  </div>
19
19
 
20
20
  <div class="field">
@@ -1,5 +1,5 @@
1
- <%= content_item_tag content do %>
2
- <%= tag.h3 content.heading, class: content.heading_style_class if content.show_heading? %>
1
+ <%= content_item_tag(content, class: "flow") do %>
2
+ <%= tag.h3(content.heading, class: content.heading_style_class) if content.show_heading? %>
3
3
 
4
4
  <%= content.content %>
5
5
  <% end %>
@@ -18,8 +18,8 @@
18
18
  </div>
19
19
 
20
20
  <div class="field">
21
- <%= form.label :background %>
22
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
21
+ <%= form.label :theme %>
22
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
23
23
  </div>
24
24
 
25
25
  <div class="field">
@@ -1,4 +1,4 @@
1
- <%= content_item_tag figure do %>
1
+ <%= content_item_tag(figure, tag: :figure) do %>
2
2
  <%= image_tag figure.image, alt: figure.alt %>
3
3
  <%= tag.figcaption figure.caption if figure.caption.present? %>
4
4
  <% end %>
@@ -13,8 +13,8 @@
13
13
  </div>
14
14
 
15
15
  <div class="field">
16
- <%= form.label :background %>
17
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
16
+ <%= form.label :theme %>
17
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
18
18
  </div>
19
19
 
20
20
  <div class="field">
@@ -1,7 +1,5 @@
1
1
  <%= content_item_tag group do %>
2
2
  <%= tag.h3 group.heading, class: group.heading_style_class if group.show_heading? %>
3
3
 
4
- <div>
5
- <%= render_content_items group.children %>
6
- </div>
4
+ <%= render_content_items(*group.children, theme: group.theme, class: "flow") %>
7
5
  <% end %>
@@ -13,8 +13,8 @@
13
13
  </div>
14
14
 
15
15
  <div class="field">
16
- <%= form.label :background %>
17
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
16
+ <%= form.label :theme %>
17
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
18
18
  </div>
19
19
 
20
20
  <div class="field">
@@ -10,17 +10,16 @@
10
10
  <dialog class="modal"
11
11
  data-content--editor--item-editor-target="dialog"
12
12
  data-action="
13
- click->content--editor--item-editor#dismiss
13
+ click->content--editor--item-editor#click
14
14
  close->content--editor--item-editor#dismiss
15
15
  "
16
16
  data-item-id="<%= dom_id(item_editor.item) %>"
17
17
  <%= "data-item-persisted" if item_editor.item.persisted? %>>
18
- <article class="flow" data-action="click->content--editor--item-editor#noop:stop">
18
+ <article class="flow">
19
19
  <header class="repel" data-nowrap>
20
20
  <h2><%= item_editor.title %></h2>
21
- <button form="<%= item_editor.id %>"
22
- formmethod="dialog"
23
- class="button"
21
+ <button class="button"
22
+ data-action="content--editor--item-editor#dismiss"
24
23
  data-button-padding="tight"
25
24
  data-text-button>
26
25
  <icon aria-hidden="true" class="icon" data-icon="close">&nbsp;</icon>
@@ -31,15 +30,11 @@
31
30
  <%= render item_editor %>
32
31
  </main>
33
32
  <footer class="actions" data-reverse>
34
- <button form="<%= item_editor.id %>" class="button" data-close-dialog>
35
- Done
36
- </button>
33
+ <button form="<%= item_editor.id %>" class="button" data-close-dialog><%= t(".submit") %></button>
37
34
  <button form="<%= item_editor.id %>"
38
35
  formmethod="dialog"
39
36
  class="button"
40
- data-ghost-button>
41
- Discard
42
- </button>
37
+ data-ghost-button><%= t(".cancel") %></button>
43
38
  </footer>
44
39
  </article>
45
40
  </dialog>
@@ -13,8 +13,8 @@
13
13
  </div>
14
14
 
15
15
  <div class="field">
16
- <%= form.label :background %>
17
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
16
+ <%= form.label :theme %>
17
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
18
18
  </div>
19
19
 
20
20
  <div class="field">
@@ -1,7 +1,5 @@
1
- <%= content_item_tag section do %>
2
- <%= tag.h2 section.heading, class: section.heading_style_class if section.show_heading? %>
1
+ <%= content_item_tag(section, tag: :section, class: "flow") do %>
2
+ <%= tag.h2(section.heading, class: section.heading_style_class) if section.show_heading? %>
3
3
 
4
- <div>
5
- <%= render_content_items section.children %>
6
- </div>
4
+ <%= render_content_items(*section.children, theme: section.theme, class: "flow") %>
7
5
  <% end %>
@@ -14,8 +14,8 @@
14
14
  </div>
15
15
 
16
16
  <div class="field">
17
- <%= form.label :background %>
18
- <%= form.select :background, Katalyst::Content.config.backgrounds %>
17
+ <%= form.label :theme %>
18
+ <%= form.select :theme, Katalyst::Content.config.themes, include_blank: true %>
19
19
  </div>
20
20
 
21
21
  <div class="field">
@@ -12,6 +12,17 @@ en:
12
12
  file_size_out_of_range: must be less than %{max_size}
13
13
  katalyst/content/table:
14
14
  table_missing: Table is missing or invalid
15
+ katalyst:
16
+ content:
17
+ editor:
18
+ new_items_component:
19
+ add_item: "Add item"
20
+ add_item_inline: "Add item here"
21
+ close: "Close"
22
+ items:
23
+ edit:
24
+ cancel: "Cancel"
25
+ submit: "Done"
15
26
  views:
16
27
  katalyst:
17
28
  content:
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameBackgroundToTheme < ActiveRecord::Migration[8.0]
4
+ def change
5
+ rename_column :katalyst_content_items, :background, :theme
6
+ end
7
+ end
@@ -7,7 +7,10 @@ module Katalyst
7
7
  class Config
8
8
  include ActiveSupport::Configurable
9
9
 
10
- config_accessor(:backgrounds) { %w[light dark] }
10
+ config_accessor(:themes) { %w[light dark] }
11
+ alias_method :backgrounds, :themes
12
+ alias_method :backgrounds=, :themes=
13
+
11
14
  config_accessor(:heading_styles) { %w[none default] }
12
15
  config_accessor(:items) do
13
16
  %w[
@@ -4,7 +4,7 @@ FactoryBot.define do
4
4
  trait :content_item_defaults do
5
5
  heading { Faker::Lorem.word }
6
6
  heading_style { "default" }
7
- background { Katalyst::Content.config.backgrounds.sample }
7
+ theme { Katalyst::Content.config.themes.sample }
8
8
  depth { 0 }
9
9
  end
10
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha.1
4
+ version: 3.0.0.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-18 00:00:00.000000000 Z
10
+ date: 2025-04-11 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activerecord
@@ -93,12 +93,15 @@ files:
93
93
  - app/assets/images/katalyst/content/icons/section.svg
94
94
  - app/assets/images/katalyst/content/icons/table.svg
95
95
  - app/assets/images/katalyst/content/icons/theme.svg
96
- - app/assets/stylesheets/katalyst/_content.scss
97
- - app/assets/stylesheets/katalyst/content.css
96
+ - app/assets/stylesheets/katalyst/content/_editor.scss
97
+ - app/assets/stylesheets/katalyst/content/_frontend.scss
98
98
  - app/assets/stylesheets/katalyst/content/editor.css
99
- - app/assets/stylesheets/katalyst/content/icons.css
100
- - app/assets/stylesheets/katalyst/content/status-bar.css
101
- - app/assets/stylesheets/katalyst/content/table.css
99
+ - app/assets/stylesheets/katalyst/content/editor/editor.css
100
+ - app/assets/stylesheets/katalyst/content/editor/icons.css
101
+ - app/assets/stylesheets/katalyst/content/editor/status-bar.css
102
+ - app/assets/stylesheets/katalyst/content/editor/table.css
103
+ - app/assets/stylesheets/katalyst/content/frontend.css
104
+ - app/assets/stylesheets/katalyst/content/frontend/frontend.css
102
105
  - app/components/katalyst/content/editor/base_component.rb
103
106
  - app/components/katalyst/content/editor/errors_component.html.erb
104
107
  - app/components/katalyst/content/editor/errors_component.rb
@@ -185,6 +188,7 @@ files:
185
188
  - db/migrate/20220926061535_add_fields_for_figure_to_katalyst_content_items.rb
186
189
  - db/migrate/20230515151440_change_katalyst_content_items_show_heading_column.rb
187
190
  - db/migrate/20240826042004_add_style_to_content_items.rb
191
+ - db/migrate/20250321045027_rename_background_to_theme.rb
188
192
  - lib/katalyst/content.rb
189
193
  - lib/katalyst/content/config.rb
190
194
  - lib/katalyst/content/engine.rb
@@ -1,4 +0,0 @@
1
- @use "content/editor";
2
- @use "content/icons";
3
- @use "content/status-bar";
4
- @use "content/table";
@@ -1,4 +0,0 @@
1
- @import url("content/editor.css");
2
- @import url("content/icons.css");
3
- @import url("content/status-bar.css");
4
- @import url("content/table.css");