katalyst-content 2.0.1 → 2.1.0

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: d83d4599fc11b8b7b4dec904defe637176d35349af678d4f2329616239563fde
4
- data.tar.gz: 66b0f23f5cc84c62f6f99a5f5718c369381a646c819628958017070941efbb91
3
+ metadata.gz: ccae8b137b15ca5142051b2de2e58f75c379ac79cf087d728c06bd8105e14ad3
4
+ data.tar.gz: c4b2a9cb31491c6416c5dbf6d5b3fb6ca207cc9371f74f4c2ec7b594fc2ea699
5
5
  SHA512:
6
- metadata.gz: f9410bff8a37d6b180a196641112a1013acf37c292d2873ed50a3a1a082e9dd7b1e0b7c8df079fc5a914be7b8a2908487914410ce4db593706230670a5ecf175
7
- data.tar.gz: 8d6feaf626296faa82e4b2549426a44ad0cd258071f132d1e004dfb3383eef6bb2cd6bd06aa1d8d65006006388d5678007518b3ef9eecab9000b56ee6b3959a5
6
+ metadata.gz: 8d678570d5099c8ab0536d50e4acf307b7bacf0d2c7daca2f70ab5342d718cbf2ace4cdfa22ce8500854139cbf4735ea074b653d2e69f729ce993ebf3a5a3df3
7
+ data.tar.gz: d029ef1cd3e03e3ca064691e38f3768c7140fcbdc0e6778986d0657abe8c4c0e12277db82e55ddd06bef74cb2c65b5f8caf3eae9ca4a964c56fe660a1eaab6bb
@@ -1,10 +1,5 @@
1
1
  @use "icon" as *;
2
2
 
3
- // provide size for container queries
4
- #content--editor--item-frame {
5
- container-type: inline-size;
6
- }
7
-
8
3
  .content--editor--new-items {
9
4
  display: grid;
10
5
  grid-template-columns: repeat(3, calc((100% - 1rem) / 3));
@@ -12,8 +12,6 @@ module Katalyst
12
12
  STATUS_BAR_CONTROLLER = "content--editor--status-bar"
13
13
  NEW_ITEM_CONTROLLER = "content--editor--new-item"
14
14
 
15
- TURBO_FRAME = "content--editor--item-frame"
16
-
17
15
  attr_accessor :container, :item
18
16
 
19
17
  delegate :config, to: ::Katalyst::Content
@@ -15,7 +15,7 @@
15
15
  <div role="toolbar" data-tree-controls>
16
16
  <span role="button" value="de-nest" data-action="click-><%= CONTAINER_CONTROLLER %>#deNest" title="Outdent"></span>
17
17
  <span role="button" value="nest" data-action="click-><%= CONTAINER_CONTROLLER %>#nest" title="Indent"></span>
18
- <%= link_to("", edit_item_link, role: "button", title: "Edit", value: "edit", data: { turbo_frame: TURBO_FRAME }) %>
18
+ <%= kpop_link_to("", edit_item_link, role: "button", title: "Edit", value: "edit") %>
19
19
  <span role="button" value="remove" data-action="click-><%= CONTAINER_CONTROLLER %>#remove" title="Remove"></span>
20
20
  </div>
21
21
 
@@ -4,6 +4,8 @@ module Katalyst
4
4
  module Content
5
5
  module Editor
6
6
  class ItemComponent < BaseComponent
7
+ include KpopHelper
8
+
7
9
  def edit_item_link
8
10
  if item.persisted?
9
11
  helpers.katalyst_content.edit_item_path(item)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Katalyst
4
+ module Content
5
+ module Editor
6
+ class ItemEditorComponent < BaseComponent
7
+ include ::Turbo::FramesHelper
8
+
9
+ module Helpers
10
+ def prefix_partial_path_with_controller_namespace
11
+ false
12
+ end
13
+ end
14
+
15
+ def call
16
+ tag.div(**html_attributes) do
17
+ helpers.extend(Helpers)
18
+ helpers.render(item, path:)
19
+ end
20
+ end
21
+
22
+ def id
23
+ "item-editor-#{item.id}"
24
+ end
25
+
26
+ def title
27
+ if item.persisted?
28
+ "Edit #{item.model_name.human.downcase}"
29
+ else
30
+ "New #{item.model_name.human.downcase}"
31
+ end
32
+ end
33
+
34
+ def path
35
+ if item.persisted?
36
+ view_context.katalyst_content.item_path(item)
37
+ else
38
+ view_context.katalyst_content.items_path
39
+ end
40
+ end
41
+
42
+ def default_html_attributes
43
+ {
44
+ id:,
45
+ class: "content--item-editor",
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -40,9 +40,8 @@ module Katalyst
40
40
  role: "listitem",
41
41
  data: {
42
42
  item_type:,
43
- turbo_frame: TURBO_FRAME,
44
- controller: NEW_ITEM_CONTROLLER,
45
- action: ACTIONS,
43
+ controller: NEW_ITEM_CONTROLLER,
44
+ action: ACTIONS,
46
45
  },
47
46
  }
48
47
  end
@@ -1,5 +1,3 @@
1
- <%= turbo_frame_tag "content--editor--item-frame" do %>
2
- <div class="content--editor--new-items" role="listbox">
3
- <%= render Katalyst::Content::Editor::NewItemComponent.with_collection(items) %>
4
- </div>
5
- <% end %>
1
+ <div class="content--editor--new-items" role="listbox">
2
+ <%= render Katalyst::Content::Editor::NewItemComponent.with_collection(items) %>
3
+ </div>
@@ -27,6 +27,10 @@ module Katalyst
27
27
  Editor::NewItemsComponent.new(container:)
28
28
  end
29
29
 
30
+ def item_editor(item:)
31
+ Editor::ItemEditorComponent.new(container:, item:)
32
+ end
33
+
30
34
  def item(item:)
31
35
  Editor::ItemComponent.new(container:, item:)
32
36
  end
@@ -7,23 +7,25 @@ module Katalyst
7
7
  before_action :set_item, except: %i[new create]
8
8
  before_action :set_editor_variant
9
9
 
10
+ attr_reader :container, :item, :editor
11
+
10
12
  helper EditorHelper
11
13
 
14
+ layout nil
15
+
12
16
  def new
13
- render locals: { item: @container.items.build(item_params) }
17
+ render_editor
14
18
  end
15
19
 
16
20
  def edit
17
- render locals: { item: @item }
21
+ render_editor
18
22
  end
19
23
 
20
24
  def create
21
- @item = item = @container.items.build(item_params)
22
25
  if item.save
23
- editor = Katalyst::Content::EditorComponent.new(container: @item.container, item: @item)
24
26
  render :update, locals: { editor:, item:, previous: @container.items.build(type: item.type) }
25
27
  else
26
- render :new, status: :unprocessable_entity, locals: { item: }
28
+ render_editor status: :unprocessable_entity
27
29
  end
28
30
  end
29
31
 
@@ -33,11 +35,10 @@ module Katalyst
33
35
  if @item.valid?
34
36
  previous = @item
35
37
  @item = @item.dup.tap(&:save!)
36
- editor = Katalyst::Content::EditorComponent.new(container: @item.container, item: @item)
37
38
 
38
- render locals: { editor:, item: @item, previous: }
39
+ render locals: { editor:, item:, previous: }
39
40
  else
40
- render :edit, status: :unprocessable_entity, locals: { item: @item }
41
+ render_editor status: :unprocessable_entity
41
42
  end
42
43
  end
43
44
 
@@ -59,15 +60,24 @@ module Katalyst
59
60
  def set_container
60
61
  @container = Item.new(item_params).container
61
62
  raise ActiveRecord::RecordNotFound unless @container
63
+
64
+ @item = @container.items.build(item_params)
65
+ @editor = Katalyst::Content::EditorComponent.new(container:, item:)
62
66
  end
63
67
 
64
68
  def set_item
65
- @item = Item.find(params[:id])
69
+ @item = Item.find(params[:id])
70
+ @container = @item.container
71
+ @editor = Katalyst::Content::EditorComponent.new(container:, item:)
66
72
  end
67
73
 
68
74
  def set_editor_variant
69
75
  request.variant << :form
70
76
  end
77
+
78
+ def render_editor(**)
79
+ render(:edit, locals: { item_editor: editor.item_editor(item:) }, **)
80
+ end
71
81
  end
72
82
  end
73
83
  end
@@ -1,4 +1,5 @@
1
- <%= turbo_frame_tag "content--editor--item-frame" do %>
2
- <h3 class="heading-three">Edit <%= item.model_name.human.downcase %></h3>
3
- <%= render item, path: katalyst_content.item_path(item) %>
1
+ <%= render Kpop::FrameComponent.new do %>
2
+ <%= render Kpop::ModalComponent.new(title: item_editor.title) do %>
3
+ <%= render item_editor %>
4
+ <% end %>
4
5
  <% end %>
@@ -0,0 +1,3 @@
1
+ <%= turbo_stream.replace item_editor.id do %>
2
+ <%= render item_editor %>
3
+ <% end %>
@@ -1,7 +1,4 @@
1
- <%= turbo_stream.replace "content--editor--item-frame" do %>
2
- <%= render editor.new_items %>
3
- <% end %>
4
-
1
+ <%= turbo_stream.kpop.dismiss %>
5
2
  <%= turbo_stream.replace dom_id(previous) do %>
6
3
  <%= render editor.item(item:) %>
7
4
  <% end %>
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support"
4
+ require "katalyst/html_attributes"
5
+ require "katalyst/kpop"
6
+
3
7
  require "katalyst/content/config"
4
8
  require "katalyst/content/engine"
5
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
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-12-06 00:00:00.000000000 Z
11
+ date: 2023-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_storage_validations
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: katalyst-kpop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: view_component
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,7 @@ files:
80
94
  - app/components/katalyst/content/editor/errors_component.rb
81
95
  - app/components/katalyst/content/editor/item_component.html.erb
82
96
  - app/components/katalyst/content/editor/item_component.rb
97
+ - app/components/katalyst/content/editor/item_editor_component.rb
83
98
  - app/components/katalyst/content/editor/new_item_component.html.erb
84
99
  - app/components/katalyst/content/editor/new_item_component.rb
85
100
  - app/components/katalyst/content/editor/new_items_component.html.erb
@@ -136,7 +151,7 @@ files:
136
151
  - app/views/katalyst/content/items/_item.html+form.erb
137
152
  - app/views/katalyst/content/items/_item.html.erb
138
153
  - app/views/katalyst/content/items/edit.html.erb
139
- - app/views/katalyst/content/items/new.html.erb
154
+ - app/views/katalyst/content/items/edit.turbo_stream.erb
140
155
  - app/views/katalyst/content/items/update.turbo_stream.erb
141
156
  - app/views/katalyst/content/sections/_section.html+form.erb
142
157
  - app/views/katalyst/content/sections/_section.html.erb
@@ -171,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
186
  - !ruby/object:Gem::Version
172
187
  version: '0'
173
188
  requirements: []
174
- rubygems_version: 3.4.20
189
+ rubygems_version: 3.4.10
175
190
  signing_key:
176
191
  specification_version: 4
177
192
  summary: Rich content page builder and editor
@@ -1,4 +0,0 @@
1
- <%= turbo_frame_tag "content--editor--item-frame" do %>
2
- <h3 class="heading-three">New <%= item.model_name.human.downcase %></h3>
3
- <%= render item, path: katalyst_content.items_path %>
4
- <% end %>