mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
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:
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
MAX_BOOK_LAYOUTS,
|
||||
MAX_SPREAD_ELEMENTS,
|
||||
bookLayoutSchema,
|
||||
bookBadgeElementSchema,
|
||||
bookIconElementSchema,
|
||||
bookSpreadSchema,
|
||||
@@ -153,6 +155,39 @@ describe('the figures a stats element carries', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('the layouts a book keeps (#2316)', () => {
|
||||
const layout = (over: Record<string, unknown> = {}) => ({
|
||||
id: 'l1', name: 'Two up', pageWidth: 210, pageHeight: 210, elements: [text({ id: 'a' })], ...over,
|
||||
});
|
||||
|
||||
it('is optional, so a document from before reads unchanged', () => {
|
||||
expect(normalizeBookDocument(doc([text()])).layouts).toBeUndefined();
|
||||
});
|
||||
|
||||
it('reads a layout back with its defaults', () => {
|
||||
const out = normalizeBookDocument({ ...doc([]), layouts: [layout()] });
|
||||
expect(out.layouts).toEqual([
|
||||
expect.objectContaining({ id: 'l1', name: 'Two up', role: 'inner', background: null }),
|
||||
]);
|
||||
});
|
||||
|
||||
it('drops a layout it cannot read and keeps the book and the others', () => {
|
||||
const out = normalizeBookDocument({
|
||||
...doc([text({ id: 'kept' })]),
|
||||
layouts: [layout({ id: 'bad', name: '' }), layout({ id: 'good' })],
|
||||
});
|
||||
expect(out.spreads[0]!.elements.map((el) => el.id)).toEqual(['kept']);
|
||||
expect(out.layouts!.map((l) => l.id)).toEqual(['good']);
|
||||
});
|
||||
|
||||
it('refuses more layouts than the cap in one parse, and keeps the first ones on salvage', () => {
|
||||
const many = Array.from({ length: MAX_BOOK_LAYOUTS + 2 }, (_, i) => layout({ id: `l${i}` }));
|
||||
expect(bookLayoutSchema.array().max(MAX_BOOK_LAYOUTS).safeParse(many).success).toBe(false);
|
||||
const out = normalizeBookDocument({ ...doc([unreadable]), layouts: many });
|
||||
expect(out.layouts).toHaveLength(MAX_BOOK_LAYOUTS);
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalizeBookDocument', () => {
|
||||
it('keeps the nine elements it can read when the tenth is from another version', () => {
|
||||
const nine = Array.from({ length: 9 }, (_, i) => text({ id: `t${i + 1}`, text: `line ${i + 1}` }));
|
||||
|
||||
@@ -812,12 +812,38 @@ export const bookPageSetupSchema = z.object({
|
||||
});
|
||||
export type BookPageSetup = z.infer<typeof bookPageSetupSchema>;
|
||||
|
||||
/** How many layouts a book keeps for reuse (#2316). */
|
||||
export const MAX_BOOK_LAYOUTS = 24;
|
||||
|
||||
/**
|
||||
* A spread's arrangement, kept to lay other pages out with (#2316).
|
||||
*
|
||||
* The design as drawn, in the millimetres of the page it was drawn on, with the
|
||||
* pictures taken out: applying it to another page pours that page's photos and
|
||||
* words into it, and the page size it came from scales it onto a book whose
|
||||
* trim changed since. Stored in the book rather than per person, so everyone
|
||||
* editing the book sees and uses the same set.
|
||||
*/
|
||||
export const bookLayoutSchema = z.object({
|
||||
id: z.string().min(1).max(40),
|
||||
name: z.string().trim().min(1).max(60),
|
||||
/** Double spread or single page: a layout only fits the kind it was drawn on. */
|
||||
role: z.enum(['inner', 'single']).default('inner'),
|
||||
pageWidth: z.number().positive().max(2000),
|
||||
pageHeight: z.number().positive().max(2000),
|
||||
background: hex.nullable().default(null),
|
||||
elements: z.array(bookElementSchema).max(MAX_SPREAD_ELEMENTS).default([]),
|
||||
});
|
||||
export type BookLayout = z.infer<typeof bookLayoutSchema>;
|
||||
|
||||
export const bookDocumentSchema = z.object({
|
||||
/** In the document, not in a column: a format bump must not need a migration. */
|
||||
version: z.literal(1).catch(1).default(1),
|
||||
title: z.string().max(MAX_BOOK_TITLE).default(''),
|
||||
page: bookPageSetupSchema.default(() => bookPageSetupSchema.parse({})),
|
||||
spreads: z.array(bookSpreadSchema).max(MAX_SPREADS).default([]),
|
||||
/** The book's own layouts (#2316). Optional so a document from before still reads. */
|
||||
layouts: z.array(bookLayoutSchema).max(MAX_BOOK_LAYOUTS).optional(),
|
||||
});
|
||||
export type BookDocument = z.infer<typeof bookDocumentSchema>;
|
||||
|
||||
@@ -866,8 +892,11 @@ function withoutUnreadableElements(raw: unknown): unknown {
|
||||
? list.filter(el => bookElementSchema.safeParse(el).success).slice(0, MAX_SPREAD_ELEMENTS)
|
||||
: list);
|
||||
|
||||
const layouts = (doc as { layouts?: unknown }).layouts;
|
||||
return {
|
||||
...doc,
|
||||
// A saved layout is a convenience: one that no longer reads is dropped, not the book.
|
||||
...(Array.isArray(layouts) ? { layouts: layouts.filter(l => bookLayoutSchema.safeParse(l).success).slice(0, MAX_BOOK_LAYOUTS) } : {}),
|
||||
spreads: doc.spreads.map(sp => {
|
||||
if (!sp || typeof sp !== 'object') return sp;
|
||||
const spread = sp as { elements?: unknown; parked?: unknown };
|
||||
|
||||
Reference in New Issue
Block a user