add Site context with social links editor and site-wide settings
Some checks failed
deploy / deploy (push) Has been cancelled

- Add Site context for managing site-wide content (social links, nav items,
  announcement bar, footer content)
- Add SocialLink schema with URL normalization and platform auto-detection
  supporting 40+ platforms via host and 25+ via URI scheme
- Add NavItem schema for header/footer navigation (editor UI coming next)
- Add SiteEditor component with collapsible sections for each content type
- Wire social links card block and footer to use database data
- Filter empty URLs from display in shop components
- Add DetailsPreserver hook to preserve collapsible section state
- Add comprehensive tests for Site context and SocialLink functions
- Remove unused helper functions from onboarding to fix compiler warnings
- Move sync_edit_url_param helper to group handle_editor_event clauses

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-03-28 10:09:33 +00:00
parent 0b86cd66ce
commit 638bb4fb70
24 changed files with 3121 additions and 195 deletions

View File

@@ -679,7 +679,7 @@ const DirtyGuard = {
}
}
// EditorSheet: handles click-outside, Escape, and mobile drag-to-resize
// EditorSheet: handles click-outside, Escape, navigation guard, and mobile drag-to-resize
const EditorSheet = {
mounted() {
// Close on Escape key
@@ -691,6 +691,37 @@ const EditorSheet = {
}
document.addEventListener("keydown", this._onKeydown)
// Navigation guard: warn on browser close/refresh
this._beforeUnload = (e) => {
if (this.el.dataset.dirty === "true") {
e.preventDefault()
e.returnValue = ""
}
}
window.addEventListener("beforeunload", this._beforeUnload)
// Navigation guard: intercept LiveView link clicks
this._clickGuard = (e) => {
if (this.el.dataset.dirty !== "true") return
const link = e.target.closest("a[data-phx-link]")
if (!link) return
// Don't block clicks inside the editor itself
if (this.el.contains(link)) return
// Block navigation and show custom modal
e.preventDefault()
e.stopImmediatePropagation()
this.pushEvent("editor_nav_blocked", { href: link.getAttribute("href") })
}
document.addEventListener("click", this._clickGuard, true)
// Handle navigation after save/discard
this.handleEvent("editor_navigate", ({ href }) => {
window.location.href = href
})
// Restore saved height on mobile and mark as already opened
this._restoreSavedHeight()
this._hasDragged = !!localStorage.getItem("editor-panel-height")
@@ -712,6 +743,8 @@ const EditorSheet = {
destroyed() {
document.removeEventListener("keydown", this._onKeydown)
window.removeEventListener("beforeunload", this._beforeUnload)
document.removeEventListener("click", this._clickGuard, true)
this._cleanupDragHandle()
},
@@ -882,35 +915,33 @@ const Clipboard = {
}
}
// DirtyGuard + Ctrl+Z / Ctrl+Shift+Z undo/redo for page editors
// Preserve <details> open state across LiveView re-renders
// Morphdom removes the open attribute when server doesn't send it,
// so we store the state locally and restore it after each update.
const DetailsPreserver = {
mounted() {
this._saveState()
},
beforeUpdate() {
this._saveState()
},
updated() {
this._restoreState()
},
_saveState() {
this._wasOpen = this.el.open
},
_restoreState() {
if (this._wasOpen !== undefined) {
this.el.open = this._wasOpen
}
}
}
// Ctrl+Z / Ctrl+Shift+Z undo/redo for page editors
// Note: Navigation guards are now handled by EditorSheet hook
const EditorKeyboard = {
mounted() {
this._beforeUnload = (e) => {
if (this.el.dataset.dirty === "true") {
e.preventDefault()
e.returnValue = ""
}
}
window.addEventListener("beforeunload", this._beforeUnload)
// Intercept LiveView navigation clicks when editor has unsaved changes.
// Uses capture phase to fire before LiveView's own click handler.
this._clickGuard = (e) => {
if (this.el.dataset.dirty !== "true") return
const link = e.target.closest("a[data-phx-link]")
if (!link) return
// Don't block clicks inside the editor itself (e.g. block controls)
if (this.el.contains(link)) return
if (!window.confirm("You have unsaved changes that will be lost. Leave anyway?")) {
e.preventDefault()
e.stopImmediatePropagation()
}
}
document.addEventListener("click", this._clickGuard, true)
const prefix = this.el.dataset.eventPrefix || ""
this._keydown = (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === "z") {
@@ -926,8 +957,6 @@ const EditorKeyboard = {
},
destroyed() {
window.removeEventListener("beforeunload", this._beforeUnload)
document.removeEventListener("click", this._clickGuard, true)
document.removeEventListener("keydown", this._keydown)
}
}
@@ -950,7 +979,7 @@ const Download = {
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
const liveSocket = new LiveSocket("/live", Socket, {
params: {_csrf_token: csrfToken, screen_width: window.innerWidth},
hooks: {...colocatedHooks, ColorSync, Lightbox, CartPersist, CartDrawer, ProductImageScroll, SearchModal, MobileNavDrawer, CollectionFilters, AnalyticsInit, AnalyticsExport, ChartTooltip, Clipboard, DirtyGuard, EditorKeyboard, EditorSheet, Download},
hooks: {...colocatedHooks, ColorSync, Lightbox, CartPersist, CartDrawer, ProductImageScroll, SearchModal, MobileNavDrawer, CollectionFilters, AnalyticsInit, AnalyticsExport, ChartTooltip, Clipboard, DetailsPreserver, DirtyGuard, EditorKeyboard, EditorSheet, Download},
})
// Show progress bar on live navigation and form submits