feat: quality of life sweep from the feature discussions

Small requests from the discussions, each built end to end: planner and
map (cycling mode, date first headings, clear a day, stay times per day,
off-route stops, map lock, compact unplanned markers, pending stays,
cable car, transit quick picks), places (location filter, category from
OSM, open in maps, geo: link, image from an attachment, enrichment on
file import, places near a pin, place name language, Amap first in
China), lists and costs (packed counter, inherited sharing, Markdown
to-dos, payment notes, bookings CSV, my plan PDF), sharing (unplanned
places, travel only, without photos), journey (photo zoom, drafts,
photo order, trip suggestion, day jump), atlas (region counter, region
bucket list, places per country), vacay half company holidays, studio
copy and paste plus the book's own layouts, and RESTORE_FROM_BACKUP for
a first start restore.
This commit is contained in:
Maurice
2026-09-30 23:00:12 +02:00
parent 91dfab3f4b
commit 8fd46c4c18
691 changed files with 9491 additions and 927 deletions
+56 -1
View File
@@ -1,5 +1,8 @@
import { create } from 'zustand'
import type { BookDocument, BookElement, BookFrame, BookSpread } from '@trek/shared'
import type { BookDocument, BookElement, BookFrame, BookLayout, BookSpread } from '@trek/shared'
import { MAX_BOOK_LAYOUTS, MAX_SPREAD_ELEMENTS } from '@trek/shared'
import { pastedElements, type StudioClipboard } from '../components/Studio/studioClipboard'
import { applySavedLayout, layoutFromSpread } from '../components/Studio/savedLayouts'
/**
* The book being edited.
@@ -25,6 +28,8 @@ interface StudioState {
future: BookDocument[]
/** The document as it was when the current gesture started. */
gestureBase: BookDocument | null
/** Elements copied for pasting onto any page of the book (#2316). Kept across page switches. */
clipboard: StudioClipboard | null
load: (doc: BookDocument) => void
setActiveSpread: (i: number) => void
@@ -51,6 +56,16 @@ interface StudioState {
removeElements: (spreadIndex: number, ids: string[]) => void
duplicate: (spreadIndex: number, ids: string[]) => void
raise: (spreadIndex: number, id: string, to: 'front' | 'back' | 'up' | 'down') => void
/** Copy elements of a spread to the clipboard (#2316). */
copy: (spreadIndex: number, ids: string[]) => void
/** Put the clipboard onto a spread, as one undo step, and select what arrived. */
paste: (spreadIndex: number) => void
/** Keep a spread's arrangement as one of the book's layouts (#2316). Returns false when the book is full. */
saveLayout: (spreadIndex: number, name: string) => boolean
removeLayout: (id: string) => void
/** Lay a spread out on a saved layout, keeping its pictures and words. */
applyLayout: (spreadIndex: number, id: string) => void
/** Insert an empty spread after `index`, and select it. */
addSpread: (index: number) => void
@@ -119,6 +134,7 @@ export const useStudioStore = create<StudioState>((set, get) => ({
past: [],
future: [],
gestureBase: null,
clipboard: null,
load: doc => set({ doc, selection: [], activeSpread: 0, past: [], future: [], gestureBase: null }),
setActiveSpread: i => set({ activeSpread: i, selection: [] }),
@@ -220,6 +236,45 @@ export const useStudioStore = create<StudioState>((set, get) => ({
return { ...sp, elements: els }
})),
copy: (spreadIndex, ids) => {
const sp = get().doc?.spreads[spreadIndex]
if (!sp) return
const elements = sp.elements.filter(e => ids.includes(e.id))
if (elements.length) set({ clipboard: { fromSpreadId: sp.id, elements } })
},
paste: spreadIndex => {
const { clipboard, doc } = get()
const target = doc?.spreads[spreadIndex]
if (!clipboard || !doc || !target) return
// The spread's own cap: a paste that would push it past what the contract
// accepts takes what fits rather than making the book unsaveable.
const room = Math.max(0, MAX_SPREAD_ELEMENTS - target.elements.length)
const copies = pastedElements(clipboard, target, doc.page).slice(0, room)
if (!copies.length) return
get().commit(d => replaceSpread(d, spreadIndex, sp => ({ ...sp, elements: [...sp.elements, ...copies] })))
set({ selection: copies.map(e => e.id) })
},
saveLayout: (spreadIndex, name) => {
const doc = get().doc
const sp = doc?.spreads[spreadIndex]
if (!doc || !sp || !sp.elements.length) return false
if ((doc.layouts ?? []).length >= MAX_BOOK_LAYOUTS) return false
const layout: BookLayout = layoutFromSpread(sp, doc.page, name)
get().commit(d => ({ ...d, layouts: [...(d.layouts ?? []), layout] }))
return true
},
removeLayout: id => get().commit(d => ({ ...d, layouts: (d.layouts ?? []).filter(l => l.id !== id) })),
applyLayout: (spreadIndex, id) => {
const layout = get().doc?.layouts?.find(l => l.id === id)
if (!layout) return
get().commit(d => replaceSpread(d, spreadIndex, sp => applySavedLayout(sp, layout, d.page)))
set({ selection: [] })
},
/*
* ── Spread management ────────────────────────────────────────────────
*