feat(places): Places replaces Collections, with All places, place sheets and a calmer list

- Collections is Places now: /places opens "All places", every place of the
  trips and lists with where it comes from, the same filter row (where from,
  status, category, order), map bar (search, lock, list toggle) and place sheet
  as a list; /places/saved and /places/:id are the lists, and the old
  /collections links still land there. On the phone the same, with its own
  sheet. A place sheet shows each trip (planned day or trip dates, stay,
  booking, notes) and each list (status, labels, rating, notes) as one row
  that opens it.
- The rail: a calm "New list" with its plus tile, All places and All saved as
  views, a "My lists" heading, every name on one edge. Lists can carry one of
  24 symbols, shown in their colour in the rail and the editor.
- A saved place's row keeps to two lines: its category as an icon before the
  name, its average vote as a star on the picture. Map pins wear the same star.
- The place forms put the category in front of the name as a tile that opens
  the category list, instead of a row of chips.
- All saved gets a subtitle; the import dialog opens centred.
- Fixes: a pasted coordinate pair splits from either field of the place form;
  "more" in All places frees itself when a filter changes mid-load; place
  names on the trip map and the rating badge follow the reading direction.
This commit is contained in:
Maurice
2026-11-29 15:49:35 +01:00
parent 0ecca2b46c
commit 01d327b502
179 changed files with 6206 additions and 541 deletions
@@ -3,17 +3,16 @@ import { afterEach, describe, expect, it } from 'vitest';
import { controlBoxes, layoutPlaceNames, tagPlaceName } from './placeNameLabels';
type Rect = { left: number; top: number; width: number; height: number };
type Rect = { x: number; y: number; w: number; h: number };
/** jsdom lays nothing out, so every element answers the box it was given. */
function place(el: Element, r: Rect): void {
el.getBoundingClientRect = () =>
({ ...r, right: r.left + r.width, bottom: r.top + r.height, x: r.left, y: r.top, toJSON: () => ({}) }) as DOMRect;
el.getBoundingClientRect = () => ({ x: r.x, y: r.y, width: r.w, height: r.h, toJSON: () => ({}) }) as DOMRect;
}
function mapWith(pins: { name: string; priority: 0 | 1 | 2; at: Rect; label: Rect }[]): HTMLElement {
const container = document.createElement('div');
place(container, { left: 0, top: 0, width: 800, height: 600 });
place(container, { x: 0, y: 0, w: 800, h: 600 });
document.body.appendChild(container);
for (const pin of pins) {
const el = document.createElement('div');
@@ -42,8 +41,8 @@ describe('place names on the map', () => {
{
name: '<b>Senso-ji</b>',
priority: 0,
at: { left: 10, top: 10, width: 20, height: 20 },
label: { left: 36, top: 12, width: 80, height: 16 },
at: { x: 10, y: 10, w: 20, h: 20 },
label: { x: 36, y: 12, w: 80, h: 16 },
},
]);
layoutPlaceNames(c, true);
@@ -57,14 +56,14 @@ describe('place names on the map', () => {
{
name: 'Plain',
priority: 0,
at: { left: 10, top: 10, width: 20, height: 20 },
label: { left: 36, top: 12, width: 80, height: 16 },
at: { x: 10, y: 10, w: 20, h: 20 },
label: { x: 36, y: 12, w: 80, h: 16 },
},
{
name: 'Picked',
priority: 2,
at: { left: 10, top: 60, width: 20, height: 20 },
label: { left: 40, top: 14, width: 80, height: 16 },
at: { x: 10, y: 60, w: 20, h: 20 },
label: { x: 40, y: 14, w: 80, h: 16 },
},
]);
layoutPlaceNames(c, true);
@@ -78,29 +77,29 @@ describe('place names on the map', () => {
{
name: 'Covers a pin',
priority: 0,
at: { left: 10, top: 10, width: 20, height: 20 },
label: { left: 36, top: 12, width: 80, height: 16 },
at: { x: 10, y: 10, w: 20, h: 20 },
label: { x: 36, y: 12, w: 80, h: 16 },
},
{
name: 'Neighbour',
priority: 0,
at: { left: 60, top: 8, width: 20, height: 20 },
label: { left: 300, top: 300, width: 40, height: 16 },
at: { x: 60, y: 8, w: 20, h: 20 },
label: { x: 300, y: 300, w: 40, h: 16 },
},
{
name: 'Edge',
priority: 0,
at: { left: 760, top: 200, width: 20, height: 20 },
label: { left: 786, top: 202, width: 80, height: 16 },
at: { x: 760, y: 200, w: 20, h: 20 },
label: { x: 786, y: 202, w: 80, h: 16 },
},
{
name: 'Under control',
priority: 0,
at: { left: 400, top: 500, width: 20, height: 20 },
label: { left: 426, top: 502, width: 80, height: 16 },
at: { x: 400, y: 500, w: 20, h: 20 },
label: { x: 426, y: 502, w: 80, h: 16 },
},
]);
layoutPlaceNames(c, true, [{ left: 450, top: 490, right: 520, bottom: 530 }]);
layoutPlaceNames(c, true, [{ x0: 450, y0: 490, x1: 520, y1: 530 }]);
const hidden = labels(c).map((l) => l.hasAttribute('data-hidden'));
expect(hidden).toEqual([true, false, true, true]);
});
@@ -110,8 +109,8 @@ describe('place names on the map', () => {
{
name: 'Senso-ji',
priority: 0,
at: { left: 10, top: 10, width: 20, height: 20 },
label: { left: 36, top: 12, width: 80, height: 16 },
at: { x: 10, y: 10, w: 20, h: 20 },
label: { x: 36, y: 12, w: 80, h: 16 },
},
]);
layoutPlaceNames(c, true);
@@ -123,9 +122,9 @@ describe('place names on the map', () => {
it('FE-MAP-PLACENAMES-005: control boxes are read off the elements the selector finds', () => {
const c = document.createElement('div');
const btn = document.createElement('button');
place(btn, { left: 5, top: 6, width: 30, height: 30 });
place(btn, { x: 5, y: 6, w: 30, h: 30 });
c.appendChild(btn);
expect(controlBoxes(c, 'button')).toEqual([{ left: 5, top: 6, right: 35, bottom: 36 }]);
expect(controlBoxes(c, 'button')).toEqual([{ x0: 5, y0: 6, x1: 35, y1: 36 }]);
expect(controlBoxes(null, 'button')).toEqual([]);
});
});
+17 -19
View File
@@ -25,18 +25,24 @@ export function tagPlaceName(el: HTMLElement | null | undefined, name: string, p
el.setAttribute(PRIORITY_ATTR, String(priority));
}
/** A screen box: x0/y0 the top corner the reading starts at on screen, x1/y1 the opposite one. Plain geometry. */
interface Box {
left: number;
top: number;
right: number;
bottom: number;
x0: number;
y0: number;
x1: number;
y1: number;
}
const boxOf = (el: Element): Box => {
const r = el.getBoundingClientRect();
return { x0: r.x, y0: r.y, x1: r.x + r.width, y1: r.y + r.height };
};
// Overlaps nothing: a marker that was not measured cannot push a label away.
const NO_BOX: Box = { left: Infinity, top: Infinity, right: -Infinity, bottom: -Infinity };
const NO_BOX: Box = { x0: Infinity, y0: Infinity, x1: -Infinity, y1: -Infinity };
const overlaps = (a: Box, b: Box, gap = 2): boolean =>
a.left < b.right + gap && b.left < a.right + gap && a.top < b.bottom + gap && b.top < a.bottom + gap;
a.x0 < b.x1 + gap && b.x0 < a.x1 + gap && a.y0 < b.y1 + gap && b.y0 < a.y1 + gap;
function ensureLabel(marker: HTMLElement): HTMLElement {
const name = marker.getAttribute(PLACE_NAME_ATTR) ?? '';
@@ -64,12 +70,9 @@ export function layoutPlaceNames(container: HTMLElement | null, enabled: boolean
container.querySelectorAll(`.${LABEL_CLASS}`).forEach((label) => label.remove());
return;
}
const frame = container.getBoundingClientRect();
const frame = boxOf(container);
const markerBoxes = new Map<HTMLElement, Box>();
for (const marker of markers) {
const r = marker.getBoundingClientRect();
markerBoxes.set(marker, { left: r.left, top: r.top, right: r.right, bottom: r.bottom });
}
for (const marker of markers) markerBoxes.set(marker, boxOf(marker));
const ordered = markers
.map((marker, index) => ({ marker, index, priority: Number(marker.getAttribute(PRIORITY_ATTR) ?? 0) }))
.sort((a, b) => b.priority - a.priority || a.index - b.index);
@@ -78,10 +81,8 @@ export function layoutPlaceNames(container: HTMLElement | null, enabled: boolean
for (const { marker } of ordered) {
const label = ensureLabel(marker);
label.removeAttribute(HIDDEN_ATTR);
const r = label.getBoundingClientRect();
const box: Box = { left: r.left, top: r.top, right: r.right, bottom: r.bottom };
const offFrame =
box.left < frame.left || box.right > frame.right || box.top < frame.top || box.bottom > frame.bottom;
const box = boxOf(label);
const offFrame = box.x0 < frame.x0 || box.x1 > frame.x1 || box.y0 < frame.y0 || box.y1 > frame.y1;
const coversMarker = markers.some(
(other) => other !== marker && overlaps(box, markerBoxes.get(other) ?? NO_BOX, 0)
);
@@ -95,10 +96,7 @@ export function layoutPlaceNames(container: HTMLElement | null, enabled: boolean
/** The boxes of the map controls inside `container` that a label must leave free. */
export function controlBoxes(container: HTMLElement | null, selector: string): Box[] {
if (!container) return [];
return Array.from(container.querySelectorAll<HTMLElement>(selector)).map((el) => {
const r = el.getBoundingClientRect();
return { left: r.left, top: r.top, right: r.right, bottom: r.bottom };
});
return Array.from(container.querySelectorAll<HTMLElement>(selector)).map(boxOf);
}
/** What no label may cover: the controls drawn over the map beside it. */
+2 -1
View File
@@ -2,7 +2,8 @@
element, so it pans with it; placeNameLabels.ts decides which ones stay visible. */
.trek-place-name {
position: absolute;
left: calc(100% + 6px); /* rtl-lint-disable: map geometry, the label sits beside the pin on screen */
/* After the pin in the reading direction, so an Arabic map reads the name from the pin outward. */
inset-inline-start: calc(100% + 6px);
top: 50%;
transform: translateY(-50%);
max-width: 13em;
@@ -26,12 +26,12 @@ describe('cornerBadgeHtml', () => {
it('FE-MAP-RATINGBADGE-101: day numbers win the corner over the rating', () => {
const html = cornerBadgeHtml([2, 5], 4.5, true, -4);
expect(html).toContain('2 · 5');
expect(html).toContain('bottom:-4px;right:-4px');
expect(html).not.toContain('#f59e0b');
expect(html).toContain('bottom:-4px;inset-inline-end:-4px');
expect(html).not.toContain('#fbbf24');
});
it('FE-MAP-RATINGBADGE-102: without numbers the rating shows when asked for, else nothing', () => {
expect(cornerBadgeHtml(null, 4, true, -2)).toContain('#f59e0b');
expect(cornerBadgeHtml(null, 4, true, -2)).toContain('#fbbf24');
expect(cornerBadgeHtml([], 4, false, -2)).toBe('');
expect(cornerBadgeHtml([3], null, true, -2)).toContain('height:18px');
});
+17 -14
View File
@@ -1,29 +1,32 @@
/** Lucide's star, the one the lists wear. */
const STAR_PATH =
'M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z';
/**
* The rating a place carries, as a disc on the corner of its marker.
* The rating a place carries, as a star on the corner of its marker.
*
* Bottom right, where a trip's day numbers sit — the two never appear together, since
* a numbered stop is one you have already planned and this answers the question you
* ask before that: of all these photos, which did I like. Amber rather than the number
* badge's white, so a glance tells them apart without reading either.
*
* A rounded value and no star: at eighteen pixels a star is a smudge, and "4.5" is
* already the whole sentence.
* A star like the one the lists put on a place's picture, so the vote reads the same on
* the map and beside it; the figure inside is rounded to one decimal.
*/
export function ratingBadgeHtml(rating: number | null | undefined): string {
if (typeof rating !== 'number' || !(rating > 0)) return '';
const label = Number.isInteger(rating) ? String(rating) : rating.toFixed(1);
// A star rather than a disc, as in the lists; its box a little over the old disc,
// since a star fills less of it. Leaflet lifts every svg in a marker to z-index 200,
// so both layers name theirs, or the star covers its own figure.
return `<span style="
position:absolute;bottom:-4px;right:-4px;
min-width:18px;height:18px;border-radius:9px;
padding:0 4px;
background:#f59e0b;
border:1.5px solid rgba(255,255,255,0.92);
box-shadow:0 1px 4px rgba(0,0,0,0.25);
position:absolute;bottom:-6px;right:-6px;
width:22px;height:22px;
display:flex;align-items:center;justify-content:center;
font-size:9px;font-weight:800;color:#fff;
font-family:var(--font-system);line-height:1;
box-sizing:border-box;white-space:nowrap;
">${label}</span>`;
"><svg viewBox="0 0 24 24" width="22" height="22" style="position:absolute;inset:0;z-index:0;overflow:visible"
fill="#fbbf24" stroke="rgba(255,255,255,0.92)" stroke-width="1.3" stroke-linejoin="round"><path d="${STAR_PATH}"/></svg>
<span style="position:relative;z-index:1;margin-top:2px;font-size:${label.length > 1 ? 6.5 : 8.5}px;font-weight:800;line-height:1;
color:#111;font-family:var(--font-system);white-space:nowrap;">${label}</span></span>`;
}
/**
@@ -40,7 +43,7 @@ export function cornerBadgeHtml(
if (!orderNumbers || orderNumbers.length === 0) return showRating ? ratingBadgeHtml(rating) : '';
const many = orderNumbers.length > 1;
return `<span style="
position:absolute;bottom:${inset}px;right:${inset}px;
position:absolute;bottom:${inset}px;inset-inline-end:${inset}px;
min-width:18px;height:${many ? 16 : 18}px;border-radius:${many ? 8 : 9}px;
padding:0 ${many ? 4 : 3}px;
background:rgba(255,255,255,0.94);
@@ -28,7 +28,7 @@ export function usePlaceNameLayout(
cancelAnimationFrame(frame);
frame = requestAnimationFrame(() => {
const scope = container.parentElement ?? container;
const controls = enabled ? controlBoxes(scope, PLACE_NAMES_CONTROLS).filter((b) => b.right > b.left) : [];
const controls = enabled ? controlBoxes(scope, PLACE_NAMES_CONTROLS).filter((b) => b.x1 > b.x0) : [];
layoutPlaceNames(container, enabled, controls);
});
};