diff --git a/public/css/style.css b/public/css/style.css index 104ac7c..6999efe 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -4370,3 +4370,242 @@ html.follow-3d .maplibregl-ctrl-overview-map { display: none; } padding: 0; min-height: 0; } + +/* ---- Library, as on the artboard (gpx.js): find on top, one level of + folders or a flat list, an eye per row, totals and Hide all at the foot. */ +.lib-find { + display: flex; + flex-direction: column; + gap: 10px; + padding: 12px 16px 10px; + border-bottom: 1px solid var(--ui-line); +} + +.lib-find__input { + height: 40px; + padding: 0 12px; + border: 2px solid var(--accent); + border-radius: 8px; + background: var(--ui-bg); + color: var(--ui-fg); + font-family: inherit; + font-size: 15px; +} + +.lib-find__kinds, +.lib-find__bar { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 6px; +} + +.gpx-panel .lib-chip { + min-height: 30px; + height: 30px; + padding: 0 10px; + border: 1px solid var(--ui-line); + border-radius: 15px; + background: var(--ui-bg); + color: var(--ui-fg); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; +} + +.gpx-panel .lib-chip[aria-pressed="true"] { + border-color: var(--accent); + background: var(--accent-bg); + color: var(--accent); +} + +.lib-chip small { + opacity: 0.7; +} + +.lib-seg { + display: flex; + margin-left: auto; + border: 1px solid var(--ui-line); + border-radius: 6px; + overflow: hidden; +} + +.gpx-panel .lib-seg button { + min-height: 30px; + height: 30px; + padding: 0 12px; + border: none; + background: none; + color: var(--ui-fg); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; +} + +.gpx-panel .lib-seg button[aria-pressed="true"] { + background: var(--accent); + color: #fff; +} + +.lib-crumb { + display: flex; + align-items: center; + gap: 8px; + padding: 8px 16px; + border-bottom: 1px solid var(--ui-line); + font-size: 14px; +} + +.lib-crumb[hidden] { + display: none; +} + +.gpx-panel .lib-crumb__up { + min-height: 32px; + width: 32px; + border: 1px solid var(--ui-line); + border-radius: 6px; + background: none; + color: var(--ui-fg); + font-size: 16px; + cursor: pointer; +} + +.lib-crumb__path { + color: var(--ui-muted); +} + +.lib-crumb b { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.lib-crumb small { + margin-left: auto; + color: var(--ui-muted); + font-size: 12px; + white-space: nowrap; +} + +.gpx-panel .gpx-tree { + padding: 0; +} + +.lib-list { + list-style: none; + margin: 0; + padding: 0; +} + +.lib-row { + display: flex; + align-items: center; + gap: 10px; + min-height: 52px; + padding: 0 8px 0 16px; + border-bottom: 1px solid var(--ui-line); +} + +.lib-row:hover { + background: var(--ui-bg-2); +} + +.lib-row.gpx-drop-hover { + background: var(--accent-bg); +} + +.lib-row__icon { + width: 26px; + flex: none; + text-align: center; + font-size: 18px; + color: var(--ui-muted); +} + +.lib-row__text { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + cursor: pointer; +} + +.lib-row__name { + font-size: 15px; + font-weight: 600; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.lib-row__name--folder { + font-weight: 700; +} + +.lib-row__meta { + font-size: 12px; + color: var(--ui-muted); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.lib-row__aside { + color: var(--ui-muted); + font-size: 16px; + cursor: pointer; +} + +.gpx-panel .lib-eye { + width: 36px; + min-height: 36px; + flex: none; + border: none; + background: none; + color: var(--accent); + font-size: 18px; + cursor: pointer; +} + +.gpx-panel .lib-eye--none { + color: var(--ui-muted); +} + +.lib-foot { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + margin-top: auto; + padding: 8px 16px; + border-top: 1px solid var(--ui-line); + font-size: 13px; + color: var(--ui-muted); +} + +.gpx-panel .lib-foot button { + min-height: 32px; + padding: 0 12px; + border: 1px solid var(--ui-line); + border-radius: 6px; + background: none; + color: var(--ui-fg); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; +} + +/* the profile docked under the map: the map ends above it (track_profile.js) */ +#map { + margin-bottom: var(--profile-h, 0px); +} + +html.driving #map { + margin-bottom: 0; +} diff --git a/public/js/gpx.js b/public/js/gpx.js index 0f3a861..5112b64 100644 --- a/public/js/gpx.js +++ b/public/js/gpx.js @@ -4,9 +4,6 @@ import { GPX_ICON, NEW_FOLDER_ICON, UPLOAD_ICON, - WAYPOINT_ICON, - TRACK_ICON, - ROUTE_ICON, DOWNLOAD_ICON, SYNC_ICON, MAP_MARKER_ICON, @@ -38,7 +35,15 @@ const BADGE_IMAGE_PREFIX = "badge-"; // one registered image per distinct badge // one — both land on the same drop targets, told apart by this. const MOVE_MIME = "application/x-gpx-path"; const GPX_VISIBLE_KEY = "gpxVisible"; -const FOLDER_DRAG_PREFIX = "folder:"; // a dragged folder's MOVE_MIME payload, vs. a node key +// The kinds the Library filters by: chip label, a row's word for one, glyph and colour. +const KINDS = { + waypoint: { label: "Points", one: "points", glyph: "●", color: "#12bedf" }, + track: { label: "Tracks", one: "track", glyph: "〰", color: "#c2410c" }, + route: { label: "Routes", one: "route", glyph: "↝", color: "#1d6fdc" }, + layer: { label: "Layers", one: "layer", glyph: "▤", color: "#6b6b66" }, +}; +const FOLDER_DRAG_PREFIX = "folder:"; +const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`; // a dragged folder's MOVE_MIME payload, vs. a node key // A sidebar icon that opens a side panel for uploading GPX files (via // drag & drop, stored server-side in a folder hierarchy the user can add to @@ -119,7 +124,7 @@ export class GpxPanelControl { mount(sidebar) { this._container = document.createElement("div"); this._container.className = "sidebar-item"; - this._container.innerHTML = ``; + this._container.innerHTML = ``; this._icon = this._container.querySelector(".sidebar-icon"); this._icon.addEventListener("click", () => this._togglePanel()); @@ -162,6 +167,7 @@ export class GpxPanelControl { // panels. document.addEventListener("click", () => this._closeDownloadMenu()); + this._setupFind(); this._setupToolbarActions(); this._setupRootDropTarget(); this._setupMapDropTarget(); @@ -184,13 +190,13 @@ export class GpxPanelControl { _setupToolbarActions() { const fileInput = this._panel.querySelector(".gpx-file-input"); fileInput.addEventListener("change", () => { - this._uploadFiles(fileInput.files, ""); + this._uploadFiles(fileInput.files, this._cwd); fileInput.value = ""; }); this._panel.querySelector('[data-action="upload"]').addEventListener("click", () => fileInput.click()); this._panel.querySelector('[data-action="new-folder"]').addEventListener("click", async () => { - const path = window.prompt("New folder name (e.g. Hiking/2026):"); + const path = window.prompt("New folder name (e.g. Hiking/2026):", this._cwd ? `${this._cwd}/` : ""); if (!path || !path.trim()) return; const response = await fetch(FOLDER_URL, { @@ -223,11 +229,11 @@ export class GpxPanelControl { event.preventDefault(); this._treeContainer.classList.remove("gpx-drop-hover"); if (event.dataTransfer.files?.length > 0) { - this._uploadFiles(event.dataTransfer.files, ""); + this._uploadFiles(event.dataTransfer.files, this._cwd); return; } const from = event.dataTransfer.getData(MOVE_MIME); - if (from) this._moveFile(from, ""); + if (from) this._moveFile(from, this._cwd); }); } @@ -258,67 +264,266 @@ export class GpxPanelControl { this._renderTree(tree); } + // The Design canvas' Library (after Locus Map): find on top — the text, + // what kinds, only the shown ones — then one folder level at a time (← up, + // the path), or, while searching or in List view, every match flat with + // the folder it lives in. An eye per row: ● shown, ◐ some (a folder), ○ not. _renderTree(node) { + this._root = node; this._files = new Map(); - const index = (n) => (n.children || []).forEach((c) => (c.type === "folder" ? index(c) : this._files.set(c.path, c))); - index(node); - this._treeContainer.innerHTML = ""; - this._treeContainer.appendChild(this._renderChildren(node.children)); - } - - _renderChildren(children) { - const ul = document.createElement("ul"); - if (children.length === 0) { - const li = document.createElement("li"); - li.className = "gpx-tree__empty"; - li.textContent = "No files yet"; - ul.appendChild(li); - return ul; - } - - children.forEach((child) => { - const li = document.createElement("li"); - if (child.type === "folder") { - li.appendChild(this._renderFolder(child)); - } else if (child.points) { - li.appendChild(this._renderTrackWithPoints(child)); + this._folders = new Map([["", node]]); + const index = (n) => (n.children || []).forEach((c) => { + if (c.type === "folder") { + this._folders.set(c.path, c); + index(c); } else { - li.appendChild(this._renderFile(child)); + c.folder = n.path; + this._files.set(c.path, c); } - ul.appendChild(li); }); - - return ul; + index(node); + if (!this._folders.has(this._cwd ?? "")) this._cwd = ""; + if (this._openTrack && !this._files.has(this._openTrack)) this._openTrack = null; + this._renderView(); } - // A track/route holding points: collapsed by default (there can be many), - // each point zooms to itself and can be taken out again. - _renderTrackWithPoints(file) { - this._openTracks ||= new Set(); - const details = document.createElement("details"); - details.className = "gpx-tree__track"; - details.open = this._openTracks.has(file.path); - details.addEventListener("toggle", () => (details.open ? this._openTracks.add(file.path) : this._openTracks.delete(file.path))); - const summary = document.createElement("summary"); - summary.appendChild(this._renderFile(file)); - details.appendChild(summary); + _setupFind() { + this._cwd = ""; + this._query = ""; + this._mode = "folders"; + this._kindsOn = new Set(Object.keys(KINDS)); + this._shownOnly = false; + const find = this._panel.querySelector(".lib-find"); + const input = find.querySelector(".lib-find__input"); + input.addEventListener("input", () => { + this._query = input.value.trim().toLowerCase(); + this._renderView(); + }); + find.querySelector(".lib-find__kinds").addEventListener("click", (event) => { + const chip = event.target.closest("[data-kind]"); + if (!chip) return; + const kind = chip.dataset.kind; + if (this._kindsOn.has(kind) && this._kindsOn.size > 1) this._kindsOn.delete(kind); + else this._kindsOn.add(kind); + this._renderView(); + }); + find.querySelector('[data-find="shown"]').addEventListener("click", () => { + this._shownOnly = !this._shownOnly; + this._renderView(); + }); + find.querySelectorAll("[data-mode]").forEach((button) => button.addEventListener("click", () => { + this._mode = button.dataset.mode; + this._renderView(); + })); + this._crumb = this._panel.querySelector(".lib-crumb"); + this._footer = this._panel.querySelector(".lib-foot__text"); + this._panel.querySelector('[data-action="hide-all"]').addEventListener("click", () => { + [...this._visible].forEach((path) => this._toggleFileOnly(path, false)); + this._saveVisible(); + this._renderView(); + }); + } + + _kindOf(file) { + if (file.layer) return "layer"; + if (file.kinds?.includes("route")) return "route"; + if (file.kinds?.includes("track")) return "track"; + return "waypoint"; + } + + _matches(file) { + if (!this._kindsOn.has(this._kindOf(file))) return false; + if (this._shownOnly && !this._visible.has(file.path)) return false; + return !this._query || `${file.folder} ${file.name}`.toLowerCase().includes(this._query); + } + + // Every file under a folder (all levels). + _filesUnder(path) { + return [...this._files.values()].filter((f) => f.folder === path || f.folder.startsWith(`${path}/`) || path === ""); + } + + _renderView() { + if (!this._root) return; + const find = this._panel.querySelector(".lib-find"); + const counts = {}; + this._files.forEach((f) => (counts[this._kindOf(f)] = (counts[this._kindOf(f)] || 0) + 1)); + find.querySelector(".lib-find__kinds").innerHTML = Object.entries(KINDS) + .map(([kind, { label, color }]) => ``) + .join(""); + find.querySelector('[data-find="shown"]').setAttribute("aria-pressed", this._shownOnly); + const flat = this._mode === "list" || this._query; + find.querySelectorAll("[data-mode]").forEach((button) => button.setAttribute("aria-pressed", (button.dataset.mode === "list") === Boolean(flat))); const ul = document.createElement("ul"); - ul.className = "gpx-tree__points"; - file.points.forEach((point) => { - const li = document.createElement("li"); - li.className = "gpx-tree__point"; - const name = document.createElement("button"); - name.type = "button"; - name.className = "gpx-tree__point-name"; - name.textContent = point.name; - name.addEventListener("click", () => this._goToPoint(file.path, point)); - li.appendChild(name); - if (isLoggedIn()) li.appendChild(this._deleteButton(() => this._removePoint(file, point))); - ul.appendChild(li); + ul.className = "lib-list"; + if (flat) { + this._crumb.hidden = true; + if (this._query) { + [...this._folders.values()] + .filter((f) => f.path && f.name.toLowerCase().includes(this._query)) + .forEach((f) => ul.appendChild(this._folderRow(f, true))); + } + [...this._files.values()].filter((f) => this._matches(f)).forEach((f) => ul.appendChild(this._fileRow(f, true))); + } else if (this._openTrack) { + const track = this._files.get(this._openTrack); + this._renderCrumb(track.folder, track.name, plural(track.points.length, "point"), () => (this._openTrack = null)); + track.points.forEach((point) => ul.appendChild(this._pointRow(track, point))); + } else { + const folder = this._folders.get(this._cwd); + const subfolders = folder.children.filter((c) => c.type === "folder"); + const files = folder.children.filter((c) => c.type !== "folder" && this._matches(c)); + if (this._cwd) { + const parent = this._cwd.includes("/") ? this._cwd.slice(0, this._cwd.lastIndexOf("/")) : ""; + this._renderCrumb(parent, folder.name, `${plural(subfolders.length, "folder")} · ${plural(files.length, "item")}`, () => (this._cwd = parent), parent); + } else { + this._crumb.hidden = true; + } + subfolders.forEach((f) => ul.appendChild(this._folderRow(f))); + files.forEach((f) => ul.appendChild(this._fileRow(f))); + } + if (!ul.children.length) { + ul.innerHTML = `