Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Page builder improvements (#12736)

Damian Kaczmarczyk75960e1609e0
diff --git a/admin/app/views/spree/admin/page_blocks/forms/_image.html.erb b/admin/app/views/spree/admin/page_blocks/forms/_image.html.erb
index b6b4d41346..2e9b43dd25 100644
--- a/admin/app/views/spree/admin/page_blocks/forms/_image.html.erb
+++ b/admin/app/views/spree/admin/page_blocks/forms/_image.html.erb
@@ -1 +1,10 @@
<%= render 'active_storage/upload_form', form: f, field_name: :asset, width: 512, height: 512, auto_submit: true %>
+
+<% content_for(:design_tab) do %>
+ <%= render 'spree/admin/page_builder/labeled_range_input',
+ f: f, field: :preferred_height, min: 1, max: 1024, unit: 'px', _label: 'Max image height on desktop'
+ %>
+ <%= render 'spree/admin/page_builder/labeled_range_input',
+ f: f, field: :preferred_mobile_height, min: 1, max: 512, unit: 'px', _label: 'Max image height on mobile'
+ %>
+<% end %>
diff --git a/admin/app/views/spree/admin/page_builder/_sidebar_sections_toolbar.html.erb b/admin/app/views/spree/admin/page_builder/_sidebar_sections_toolbar.html.erb
index 76a67099a1..2e3b26aae9 100644
--- a/admin/app/views/spree/admin/page_builder/_sidebar_sections_toolbar.html.erb
+++ b/admin/app/views/spree/admin/page_builder/_sidebar_sections_toolbar.html.erb
@@ -1,64 +1,177 @@
<%= turbo_frame_tag :page_sidebar_toolbar do %>
<div class="d-none">
- <% @page_preview.sections.includes(:blocks).each do |section| %>
+ <% sections =
+ @page_preview.sections.includes(:blocks).map { |s| [@page_preview, s] } %>
+
+ <% sections +=
+ @theme_preview.sections.includes(:blocks).map { |s| [@theme_preview, s] } %>
+
+ <% sections.each do |parent, section| %>
<% next if section.new_record? %>
- <div id="editor-toolbar-section-<%= section.id %>">
- <button class="editor-toolbar-lower">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16">
- <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
- </svg>
- </button>
- <button class="editor-toolbar-higher">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-up" viewBox="0 0 16 16">
- <path fill-rule="evenodd" d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"/>
- </svg>
- </button>
- <button class="editor-toolbar-edit">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil" viewBox="0 0 16 16">
- <path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
- </svg>
- </button>
- <button class="editor-toolbar-delete">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
- <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6Z"/>
- <path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1ZM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118ZM2.5 3h11V2h-11v1Z"/>
- </svg>
- </button>
- </div>
+ <% unless parent.is_a?(Spree::Theme) %>
+ <div id="editor-toolbar-section-<%= section.id %>">
+ <button class="editor-toolbar-lower">
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-arrow-down"
+ viewBox="0 0 16 16"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"
+ />
+ </svg>
+ </button>
+ <button class="editor-toolbar-higher">
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-arrow-up"
+ viewBox="0 0 16 16"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"
+ />
+ </svg>
+ </button>
+ <button class="editor-toolbar-edit">
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-pencil"
+ viewBox="0 0 16 16"
+ >
+ <path
+ d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"
+ />
+ </svg>
+ </button>
+ <button class="editor-toolbar-delete">
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-trash"
+ viewBox="0 0 16 16"
+ >
+ <path
+ d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6Z"
+ />
+ <path
+ d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1ZM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118ZM2.5 3h11V2h-11v1Z"
+ />
+ </svg>
+ </button>
+ </div>
- <%= button_to Spree.t(:move_up), spree.move_higher_admin_page_section_path(@page_preview, section), method: :patch, id: "editor-toolbar-higher-section-#{section.id}" %>
- <%= button_to Spree.t(:move_down), spree.move_lower_admin_page_section_path(@page_preview, section), method: :patch, id: "editor-toolbar-lower-section-#{section.id}" %>
- <%= link_to Spree.t(:destroy), spree.admin_page_section_path(section), data: { turbo_confirm: Spree.t(:are_you_sure), turbo_method: :delete }, id: "editor-toolbar-delete-section-#{section.id}" %>
+ <%= button_to Spree.t(:move_up),
+ spree.move_higher_admin_page_section_path(parent, section),
+ method: :patch,
+ id: "editor-toolbar-higher-section-#{section.id}" %>
+ <%= button_to Spree.t(:move_down),
+ spree.move_lower_admin_page_section_path(parent, section),
+ method: :patch,
+ id: "editor-toolbar-lower-section-#{section.id}" %>
+ <%= link_to Spree.t(:destroy),
+ spree.admin_page_section_path(section),
+ data: {
+ turbo_confirm: Spree.t(:are_you_sure),
+ turbo_method: :delete,
+ },
+ id: "editor-toolbar-delete-section-#{section.id}" %>
+
+ <% end %>
<% section.blocks.each do |block| %>
<div id="editor-toolbar-block-<%= block.id %>">
<button class="editor-toolbar-lower">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16">
- <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-arrow-down"
+ viewBox="0 0 16 16"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"
+ />
</svg>
</button>
<button class="editor-toolbar-higher">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-up" viewBox="0 0 16 16">
- <path fill-rule="evenodd" d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"/>
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-arrow-up"
+ viewBox="0 0 16 16"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"
+ />
</svg>
</button>
<button class="editor-toolbar-edit">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil" viewBox="0 0 16 16">
- <path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-pencil"
+ viewBox="0 0 16 16"
+ >
+ <path
+ d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"
+ />
</svg>
</button>
<button class="editor-toolbar-delete">
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
- <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6Z"/>
- <path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1ZM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118ZM2.5 3h11V2h-11v1Z"/>
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="16"
+ height="16"
+ fill="currentColor"
+ class="bi bi-trash"
+ viewBox="0 0 16 16"
+ >
+ <path
+ d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5Zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6Z"
+ />
+ <path
+ d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1ZM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118ZM2.5 3h11V2h-11v1Z"
+ />
</svg>
</button>
</div>
- <%= button_to Spree.t(:move_up), spree.move_higher_admin_page_section_block_path(section, block), method: :patch, id: "editor-toolbar-higher-block-#{block.id}" %>
- <%= button_to Spree.t(:move_down), spree.move_lower_admin_page_section_block_path(section, block), method: :patch, id: "editor-toolbar-lower-block-#{block.id}" %>
- <%= link_to Spree.t(:destroy), spree.admin_page_section_block_path(section, block), data: { turbo_confirm: Spree.t(:are_you_sure), turbo_method: :delete }, id: "editor-toolbar-delete-block-#{block.id}" %>
+ <%= button_to Spree.t(:move_up),
+ spree.move_higher_admin_page_section_block_path(section, block),
+ method: :patch,
+ id: "editor-toolbar-higher-block-#{block.id}" %>
+ <%= button_to Spree.t(:move_down),
+ spree.move_lower_admin_page_section_block_path(section, block),
+ method: :patch,
+ id: "editor-toolbar-lower-block-#{block.id}" %>
+ <%= link_to Spree.t(:destroy),
+ spree.admin_page_section_block_path(section, block),
+ data: {
+ turbo_confirm: Spree.t(:are_you_sure),
+ turbo_method: :delete,
+ },
+ id: "editor-toolbar-delete-block-#{block.id}" %>
<% end %>
<% end %>
</div>
diff --git a/core/app/models/spree/page_sections/newsletter.rb b/core/app/models/spree/page_sections/newsletter.rb
index d69da5812a..6d00e8a0ed 100644
--- a/core/app/models/spree/page_sections/newsletter.rb
+++ b/core/app/models/spree/page_sections/newsletter.rb
@@ -32,7 +32,7 @@ module Spree
end
def available_blocks_to_add
- [Spree::PageBlocks::Image]
+ [Spree::PageBlocks::Image, Spree::PageBlocks::Heading, Spree::PageBlocks::Text, Spree::PageBlocks::NewsletterForm]
end
def can_sort_blocks?
diff --git a/storefront/app/assets/stylesheets/storefront_page_builder.css b/storefront/app/assets/stylesheets/storefront_page_builder.css
index 0d2f6307db..91276f3ee6 100644
--- a/storefront/app/assets/stylesheets/storefront_page_builder.css
+++ b/storefront/app/assets/stylesheets/storefront_page_builder.css
@@ -1,22 +1,18 @@
.editor-overlay {
z-index: 1089;
width: 100%;
+ container-type: inline-size;
+ container-name: editor-overlay;
}
.editor-overlay-toolbar {
position: absolute;
- top: -26px;
- left: -1px;
+ min-width: max-content;
background-color: #0081f1;
color: #fff;
- padding: 4px 8px;
font-size: 12px;
font-weight: bold;
- border-radius: 4px 4px 0 0;
- cursor: pointer;
display: none;
-}
-.editor-overlay-toolbar {
right: 2px;
top: 2px;
left: auto;
@@ -25,6 +21,15 @@
padding: 2px 2px;
border-radius: 4px;
}
+
+/* If the editor overlay is really small, move the toolbar to the bottom so it doesn't cover the content */
+@container editor-overlay (max-width: 200px) {
+ .editor-overlay-toolbar {
+ top: 100%;
+ right: 0px;
+ }
+}
+
.editor-overlay-toolbar button {
padding: 8px;
border-radius: 4px;
diff --git a/storefront/app/views/themes/default/spree/page_sections/_newsletter.html.erb b/storefront/app/views/themes/default/spree/page_sections/_newsletter.html.erb
index 69bd17daa7..f74f0ef851 100644
--- a/storefront/app/views/themes/default/spree/page_sections/_newsletter.html.erb
+++ b/storefront/app/views/themes/default/spree/page_sections/_newsletter.html.erb
@@ -38,7 +38,7 @@
<div <%= block_attributes(block) %> class="flex justify-center w-full">
<% if block.image.attached? && block.image.variable? %>
<% image_style = "aspect-ratio: #{spree_asset_aspect_ratio(block.image)}; --desktop-height: #{block.preferred_height}px; --mobile-height: #{block.preferred_mobile_height}px;" %>
- <%= image_tag spree_image_url(block.image, width: 1000, height: 1000), height: block.preferred_height, width: block.preferred_width, class: "custom-desktop-height custom-mobile-height", style: image_style %>
+ <%= image_tag spree_image_url(block.image, width: 1000, height: 1000), height: block.preferred_height, class: "custom-desktop-height custom-mobile-height", style: image_style %>
<% end %>
</div>
<% end %>