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 @@ -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
2 changes: 1 addition & 1 deletion app/controllers/maglev/editor/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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
22 changes: 20 additions & 2 deletions app/services/maglev/content/sort_section_blocks_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,29 @@ def sort_section_blocks!(source)
source.save!
end

# Only the siblings (the blocks sharing the same parent) are re-ordered, in place.
# The other blocks keep their position in the flat list: sorting the whole list
# with a non-stable sort (Array#sort_by!) used to shuffle the blocks outside of
# the sorted scope, like the children of the other blocks in a tree.
def sort_section_blocks(source)
find_blocks(source)&.sort_by! do |block|
block['parent_id'] == parent_id ? block_ids.index(block['id']) || Float::INFINITY : -1
blocks = find_blocks(source)
return if blocks.blank?

indices = blocks.each_index.select { |index| sibling?(blocks[index]) }
sorted_siblings = sort_siblings(blocks.values_at(*indices))

indices.zip(sorted_siblings) { |index, block| blocks[index] = block }
end

def sort_siblings(siblings)
siblings.sort_by.with_index do |block, position|
[block_ids.index(block['id']) || Float::INFINITY, position]
end
end

def sibling?(block)
block['parent_id'].presence == parent_id.presence
end
end
end
end
5 changes: 5 additions & 0 deletions app/services/maglev/content/update_section_block_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def call
private

def unsafe_call
# return the store which has been actually written into, so the caller
# can read its fresh lock version (a site scoped section is listed in
# a layout store but its content is written in the site scoped store)
if site_scoped?
update_section_block_content!(site_scoped_store)
else
Expand All @@ -41,6 +44,8 @@ def update_section_block_content!(source)
source.sections_translations_will_change!
update_section_block_content(source)
source.save!

source
end

def update_section_block_content(source)
Expand Down
5 changes: 5 additions & 0 deletions app/services/maglev/content/update_section_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def call
private

def unsafe_call
# return the store which has been actually written into, so the caller
# can read its fresh lock version (a site scoped section is listed in
# a layout store but its content is written in the site scoped store)
if site_scoped?
add_missing_site_scoped_section # make sure the section is also present in the site scoped store
update_section_content!(site_scoped_store)
Expand All @@ -40,6 +43,8 @@ def update_section_content!(source)
source.sections_translations_will_change!
update_section_content(source)
source.save!

source
end

def update_section_content(source)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<%= turbo_stream.dispatch_event "section-block-#{@section_block.id}:persisted", payload: { lockVersion: source_lock_version }.to_json %>

<%= turbo_stream.dispatch_event "section-block-#{@section_block.id}:persisted", payload: { lockVersion: @updated_store.lock_version }.to_json %>
<%= turbo_stream.update 'page-layout-notification', method: 'morph' do %>
<%= render Maglev::Uikit::BadgeComponent.new(color: :green, icon_name: 'checkbox_circle', disappear_after: 3.seconds).with_content(flash.now[:notice]) %>
<% end %>

<%= turbo_stream.update dom_id(current_maglev_page, 'topbar-page-info'), method: 'morph' do %>
<%= render 'layouts/maglev/editor/topbar/page_info' %>
<% end %>

<%= turbo_stream.update dom_id(current_maglev_page, 'topbar-publish-button'), method: 'morph' do %>
<%= render 'layouts/maglev/editor/topbar/publish_button' %>
<% end %>
<% end %>
7 changes: 2 additions & 5 deletions app/views/maglev/editor/sections/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<%= turbo_stream.dispatch_event "section-#{@section.id}:persisted", payload: { lockVersion: source_lock_version }.to_json %>

<%= turbo_stream.dispatch_event "section-#{@section.id}:persisted", payload: { lockVersion: @updated_store.lock_version }.to_json %>
<%= turbo_stream.update 'page-layout-notification', method: 'morph' do %>
<%= render Maglev::Uikit::BadgeComponent.new(color: :green, icon_name: 'checkbox_circle', disappear_after: 3.seconds).with_content(flash.now[:notice]) %>
<% end %>

<%= turbo_stream.update dom_id(current_maglev_page, 'topbar-page-info'), method: 'morph' do %>
<%= render 'layouts/maglev/editor/topbar/page_info' %>
<% end %>

<%= turbo_stream.update dom_id(current_maglev_page, 'topbar-publish-button'), method: 'morph' do %>
<%= render 'layouts/maglev/editor/topbar/publish_button' %>
<% end %>
<% end %>
6 changes: 5 additions & 1 deletion lib/maglev/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ module ActiveStorage
included do
has_one_attached :file

after_commit :save_metadata_now, on: :create, prepend: true
# Must run *after* Active Storage's own after_commit callback (registered
# by has_one_attached above), which is what actually writes the file:
# upstream prepended it and hits ActiveStorage::FileNotFoundError on any
# Rails version that defers the upload to after_commit (8.1).
after_commit :save_metadata_now, on: :create

delegate :url, :download, to: :file
end
Expand Down
Loading
Loading