katalyst-content 2.0.1 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d83d4599fc11b8b7b4dec904defe637176d35349af678d4f2329616239563fde
4
- data.tar.gz: 66b0f23f5cc84c62f6f99a5f5718c369381a646c819628958017070941efbb91
3
+ metadata.gz: 8972c901b7463acaafc585438ac770f56a3636d6a82685bc875f20363b831089
4
+ data.tar.gz: 850d22ee22e8c82158fd655460c8e6eab91c6f03d13542392a18be38756b6543
5
5
  SHA512:
6
- metadata.gz: f9410bff8a37d6b180a196641112a1013acf37c292d2873ed50a3a1a082e9dd7b1e0b7c8df079fc5a914be7b8a2908487914410ce4db593706230670a5ecf175
7
- data.tar.gz: 8d6feaf626296faa82e4b2549426a44ad0cd258071f132d1e004dfb3383eef6bb2cd6bd06aa1d8d65006006388d5678007518b3ef9eecab9000b56ee6b3959a5
6
+ metadata.gz: 8a11515dafad3e8c39c5fc1734d520612927c91ebdea98eeed913d1fdf4a5cbfbea8ecc993ae60175c068d89c4ac0f917f5918b05bfd5ca1ee2448c3fa734a2c
7
+ data.tar.gz: 41faa7d49f39de485e3372963ea472fd67e2a85b751d5021320705b3dbddccc6462fb75b78f5a57dfc733e5bc5d892f87cabd853c4ffb1773735d62afeb21ec4
@@ -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,27 @@ 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
+ store_attachments(item)
29
+
30
+ render_editor status: :unprocessable_entity
27
31
  end
28
32
  end
29
33
 
@@ -33,11 +37,12 @@ module Katalyst
33
37
  if @item.valid?
34
38
  previous = @item
35
39
  @item = @item.dup.tap(&:save!)
36
- editor = Katalyst::Content::EditorComponent.new(container: @item.container, item: @item)
37
40
 
38
- render locals: { editor:, item: @item, previous: }
41
+ render locals: { editor:, item:, previous: }
39
42
  else
40
- render :edit, status: :unprocessable_entity, locals: { item: @item }
43
+ store_attachments(item)
44
+
45
+ render_editor status: :unprocessable_entity
41
46
  end
42
47
  end
43
48
 
@@ -59,15 +64,42 @@ module Katalyst
59
64
  def set_container
60
65
  @container = Item.new(item_params).container
61
66
  raise ActiveRecord::RecordNotFound unless @container
67
+
68
+ @item = @container.items.build(item_params)
69
+ @editor = Katalyst::Content::EditorComponent.new(container:, item:)
62
70
  end
63
71
 
64
72
  def set_item
65
- @item = Item.find(params[:id])
73
+ @item = Item.find(params[:id])
74
+ @container = @item.container
75
+ @editor = Katalyst::Content::EditorComponent.new(container:, item:)
66
76
  end
67
77
 
68
78
  def set_editor_variant
69
79
  request.variant << :form
70
80
  end
81
+
82
+ def render_editor(**)
83
+ render(:edit, locals: { item_editor: editor.item_editor(item:) }, **)
84
+ end
85
+
86
+ # Ensure that any attachments are stored before the item is returned to
87
+ # the editor, so that uploads are not lost if the item is invalid.
88
+ #
89
+ # This mimics the behaviour of direct uploads without requiring the JS
90
+ # integration.
91
+ def store_attachments(item)
92
+ item.attachment_changes.each_value do |change|
93
+ case change
94
+ when ActiveStorage::Attached::Changes::CreateOne
95
+ change.upload
96
+ change.blob.save!
97
+ when ActiveStorage::Attached::Changes::CreateMany
98
+ change.upload
99
+ change.blobs.each(&:save!)
100
+ end
101
+ end
102
+ end
71
103
  end
72
104
  end
73
105
  end
@@ -4,6 +4,11 @@
4
4
 
5
5
  <div class="field">
6
6
  <%= form.label :image %>
7
+ <% if (image = form.object.image).attached? %>
8
+ <%= image.filename %>
9
+ <br>
10
+ <%= form.hidden_field :image, value: form.object.image.signed_id %>
11
+ <% end %>
7
12
  <%= form.file_field :image %>
8
13
  </div>
9
14
 
@@ -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.1
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 %>