Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions app/assets/builds/maglev/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@
.-mr-1 {
margin-right: calc(var(--spacing) * -1);
}
.mr-4 {
margin-right: calc(var(--spacing) * 4);
}
.-mb-5 {
margin-bottom: calc(var(--spacing) * -5);
}
Expand Down Expand Up @@ -544,6 +547,9 @@
.block {
display: block;
}
.contents {
display: contents;
}
.flex {
display: flex;
}
Expand All @@ -556,6 +562,9 @@
.inline {
display: inline;
}
.inline\! {
display: inline !important;
}
.inline-block {
display: inline-block;
}
Expand Down Expand Up @@ -860,6 +869,12 @@
.cursor-pointer {
cursor: pointer;
}
.resize {
resize: both;
}
.resize-y {
resize: vertical;
}
.appearance-none {
appearance: none;
}
Expand Down Expand Up @@ -1669,12 +1684,18 @@
text-transform: uppercase;
}
}
.lowercase {
text-transform: lowercase;
}
.uppercase {
text-transform: uppercase;
}
.italic {
font-style: italic;
}
.line-through {
text-decoration-line: line-through;
}
.underline {
text-decoration-line: underline;
}
Expand Down Expand Up @@ -1762,6 +1783,16 @@
.outline-editor-primary {
outline-color: var(--color-editor-primary);
}
.blur {
--tw-blur: blur(8px);
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
}
.filter {
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
}
.filter\! {
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,) !important;
}
.backdrop-blur-sm {
--tw-backdrop-blur: blur(var(--blur-sm));
-webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
Expand Down Expand Up @@ -2999,6 +3030,7 @@
--tw-ring-inset: inset;
}
height: calc(var(--number-of-rows) * var(--spacing) * 8);
resize: vertical;
overflow: auto;
--tw-leading: calc(var(--spacing) * 6);
line-height: calc(var(--spacing) * 6);
Expand Down Expand Up @@ -3334,6 +3366,59 @@
inherits: false;
initial-value: solid;
}
@property --tw-blur {
syntax: "*";
inherits: false;
}
@property --tw-brightness {
syntax: "*";
inherits: false;
}
@property --tw-contrast {
syntax: "*";
inherits: false;
}
@property --tw-grayscale {
syntax: "*";
inherits: false;
}
@property --tw-hue-rotate {
syntax: "*";
inherits: false;
}
@property --tw-invert {
syntax: "*";
inherits: false;
}
@property --tw-opacity {
syntax: "*";
inherits: false;
}
@property --tw-saturate {
syntax: "*";
inherits: false;
}
@property --tw-sepia {
syntax: "*";
inherits: false;
}
@property --tw-drop-shadow {
syntax: "*";
inherits: false;
}
@property --tw-drop-shadow-color {
syntax: "*";
inherits: false;
}
@property --tw-drop-shadow-alpha {
syntax: "<percentage>";
inherits: false;
initial-value: 100%;
}
@property --tw-drop-shadow-size {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-blur {
syntax: "*";
inherits: false;
Expand Down Expand Up @@ -3439,6 +3524,19 @@
--tw-ring-offset-color: #fff;
--tw-ring-offset-shadow: 0 0 #0000;
--tw-outline-style: solid;
--tw-blur: initial;
--tw-brightness: initial;
--tw-contrast: initial;
--tw-grayscale: initial;
--tw-hue-rotate: initial;
--tw-invert: initial;
--tw-opacity: initial;
--tw-saturate: initial;
--tw-sepia: initial;
--tw-drop-shadow: initial;
--tw-drop-shadow-color: initial;
--tw-drop-shadow-alpha: 100%;
--tw-drop-shadow-size: initial;
--tw-backdrop-blur: initial;
--tw-backdrop-brightness: initial;
--tw-backdrop-contrast: initial;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/maglev/tailwind.css.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
.ProseMirror {
@apply block py-2 px-3 rounded bg-gray-100 text-gray-800 focus:outline-none focus:ring focus:ring-inset focus:ring-2 focus:ring-editor-primary/50 placeholder-gray-500;

@apply h-[calc(var(--number-of-rows)*var(--spacing)*8)] overflow-auto leading-6;
@apply h-[calc(var(--number-of-rows)*var(--spacing)*8)] overflow-auto resize-y leading-6;

overflow-wrap: break-word;
word-wrap: break-word;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
options: {
value: value,
line_break: definition.options[:line_break],
rows: definition.options[:nb_rows],
edit_link_path: fetch_path(:edit_link_path)
}
) %>
Expand Down
12 changes: 5 additions & 7 deletions app/components/maglev/section_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# we need to move it along with the PageComponent and BlockComponent
# to a separate folder (content?)

# rubocop:disable Metrics/ClassLength
module Maglev
class SectionComponent < BaseComponent
include TagHelper

extend Forwardable

def_delegators :parent, :site, :page, :config

attr_reader :parent, :id, :type, :settings, :attributes, :definition, :templates_root_path,
Expand All @@ -35,8 +35,11 @@ def dom_id
@dom_id ||= "section-#{id}"
end

# the lock version of the store the section content comes from
# (stamped by the sections content fetcher, even for site scoped sections
# whose content lives in the global site scoped store)
def lock_version
@lock_version ||= lock_source&.lock_version || '0'
attributes[:lock_version] || '0'
end

def dom_data
Expand Down Expand Up @@ -68,10 +71,6 @@ def render

private

def lock_source
definition&.site_scoped? ? site : page
end

def build_block_list
build_blocks(attributes[:blocks])
end
Expand Down Expand Up @@ -140,4 +139,3 @@ def inspect_fields
end
end
end
# rubocop:enable Metrics/ClassLength
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<%= render Maglev::Uikit::IconComponent.new(name: 'settings') %>
<% end if blocks? %>

<% section = helpers.current_maglev_page_content.find_section(id) %>
<% store = helpers.current_maglev_page_content.find_store(section.store_handle) %>
<% if store.addable_sections.include?(section.definition) %>
<%= render 'maglev/editor/sections/clone_button', section: section, button_classes: button_classes %>
<% end %>

<%= button_to paths[:delete], method: :delete, class: button_classes,
data: { turbo_method: :delete, turbo_confirm: t('maglev.editor.sections.index.confirm_delete') },
form: {
Expand All @@ -25,4 +31,4 @@
} do %>
<%= render Maglev::Uikit::IconComponent.new(name: 'delete_bin') %>
<% end %>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ module LockVersionConcern

private

# NOTE: we can't always rely on the lock version of the store the section was fetched
# from: a site scoped section is listed in a layout store (its "slot") but its content
# lives in the global site scoped store, which is what the content services update.
# Fortunately, the sections content fetcher stamps each section with the lock version
# of the store its content actually comes from, so we use it whenever possible.
def source_lock_version
sections_store.lock_version || 0
@section ? @section.lock_version : (sections_store.lock_version || 0)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/maglev/editor/section_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def sections_store
end

def update_section_block
services.update_section_block.call(
@updated_store = services.update_section_block.call(
store: sections_store,
section_id: @section.id,
block_id: @section_block.id,
Expand Down
24 changes: 22 additions & 2 deletions app/controllers/maglev/editor/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SectionsController < Maglev::Editor::BaseController
helper_method :source_lock_version, :addable_section_categories

before_action :ensure_turbo_frame_request, only: [:new]
before_action :set_section, only: %i[edit update destroy]
before_action :set_section, only: %i[edit update destroy clone]
before_action :set_sections_store_content, only: %i[new create]

def show
Expand Down Expand Up @@ -54,6 +54,26 @@ def destroy
redirect_to_sections_path
end

def clone
store = services.fetch_sections_store.call(page: current_maglev_page, handle: @section.store_handle)
@section = services.clone_section.call(
store: store, section_id: @section.id, theme: maglev_theme, layout_id: current_maglev_page.layout_id
)
preceding_sections = store.sections.take(store.position_of_section(@section['id']))
position = preceding_sections.count { |section| !section['deleted'] }

redirect_to edit_editor_section_path(@section['id'], maglev_editing_route_context),
flash: {
store_id: maglev_theme.store_view_id_of(current_maglev_page.layout_id, store.handle),
section_id: @section['id'], position: position.to_s
},
notice: flash_t(:success), status: :see_other
rescue Maglev::CloneSection::NotCloneable
head :unprocessable_entity
rescue ActiveRecord::RecordNotFound
head :not_found
end

def sort
services.sort_sections.call(store: sections_store, section_ids: params[:item_ids],
lock_version: params[:lock_version])
Expand Down Expand Up @@ -89,7 +109,7 @@ def create_section
end

def update_section
services.update_section.call(
@updated_store = services.update_section.call(
store: sections_store,
section_id: @section.id,
content: params[:section].to_unsafe_h,
Expand Down
8 changes: 7 additions & 1 deletion app/models/maglev/content/section_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ def block_definitions
end

def root_blocks
blocks.select(&:root?)
# NOTE: a block whose type is root-eligible (root: true, the default) can still be
# nested under another block when its type is also accepted as a child
# (e.g. a navbar menu_item inside another menu_item). Selecting blocks by their
# definition's root? flag would return those nested blocks as well, rendering them
# twice in the editor tree. So we filter on the parent_id instead, like the
# front-end block tree builder does.
blocks.select { |block| block.parent_id.blank? }
end

# return the definitions of root blocks that can be added
Expand Down
4 changes: 2 additions & 2 deletions app/models/maglev/page_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def clean_value!
def clean_value
value
.strip
.gsub(%r{(^/|/$)}, '')
.gsub(%r{//+/}, '/')
.gsub(%r{\A/+|/+\z}, '')
.gsub(%r{/{2,}}, '/')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ def get_fullpath_from_link(link)
# since the static pages don't have a preview version, we need the raw url
if is_static_page
page = fetch_static_pages.call.find { |static_page| static_page.id == page_id }
page&.path
normalize_static_page_path(page.path) if page
else
get_page_fullpath.call(page: page_id, locale: locale)
end
end

def normalize_static_page_path(path)
return path if path.blank? || path.match?(%r{\A[a-z][a-z0-9+.-]*://}i) # absolute url, leave it as is

Maglev::GetPageFullpath.join(nil, path)
end
end
# rubocop:enable Style/ClassAndModuleChildren
1 change: 1 addition & 0 deletions app/services/maglev/app_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AppContainer

dependency :add_section, class: Maglev::Content::AddSectionService,
depends_on: %i[fetch_site fetch_theme]
dependency :clone_section, class: Maglev::CloneSection
dependency :update_section, class: Maglev::Content::UpdateSectionService,
depends_on: %i[fetch_site fetch_theme]
dependency :delete_section, class: Maglev::Content::DeleteSectionService,
Expand Down
Loading