Page editor: save in place, unsaved-changes guard, safer block list
- Saving no longer reloads the page: a validation error (empty title, duplicate slug) used to re-render from the server and silently discard every unsaved block edit. Shows saving/saved/error feedback like the email editor, an "Unsaved changes" badge, and warns before leaving. - Status shown in the header; on a published page "Save draft" was misleading (changes go live immediately), so it now says so and the button reads "Save". Publish is a named submit (no DOM mutation). - Block list: selected block is visible again (Tailwind v4's default border colour is currentColor, so every item had a heavy black border); drag & drop works in Firefox (needs dataTransfer data) with a drop indicator; Alt+↑/↓ keyboard reorder; hold-to-delete works from the keyboard, is cancelled on pointercancel/unmount, and no longer selects the wrong neighbour afterwards. - Shared warnOnUnsavedChanges helper; the email editor uses it too (confirm() is ignored on tab close — cancel() triggers the browser prompt). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
parent
1eb58c71ba
commit
cfe4e2062d
4 changed files with 303 additions and 188 deletions
15
app-admin/src/lib/admin/unsaved.svelte.ts
Normal file
15
app-admin/src/lib/admin/unsaved.svelte.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { beforeNavigate } from '$app/navigation';
|
||||
|
||||
/**
|
||||
* Warn before leaving a page with unsaved edits. Call during component init.
|
||||
* Form submissions are allowed through (they are the save).
|
||||
*/
|
||||
export function warnOnUnsavedChanges(isDirty: () => boolean) {
|
||||
beforeNavigate(({ cancel, type }) => {
|
||||
if (!isDirty() || type === 'form') return;
|
||||
// Closing the tab/reloading: browsers only allow their own prompt,
|
||||
// which `cancel()` triggers. confirm() is ignored there.
|
||||
if (type === 'leave') return cancel();
|
||||
if (!confirm('You have unsaved changes. Leave anyway?')) cancel();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue