Tablet-friendlier points: route markers get a 48px grab area, notes can be moved (Move in the popup: drag or tap the new spot), new and edited points pick an icon and a color with B/I buttons for their text, and the Tracks & Points open/close arrows get a real hit area
This commit is contained in:
1 parent
3e5fada66a
commit
07f3711760
3 files changed
+274
-71
No files matched your search
+114
-24
@@ -975,9 +975,43 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
.gpx-tree summary {
|
.gpx-tree summary {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gpx-tree summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The open/close arrow for folders and tracks with points: a real hit area
|
||||||
|
(the browser's own marker, or a 12px glyph, was a fingertip miss). */
|
||||||
|
.gpx-tree summary::before {
|
||||||
|
content: "▸";
|
||||||
|
flex: none;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 24px;
|
||||||
|
height: 28px;
|
||||||
|
color: #888;
|
||||||
|
font-size: 13px;
|
||||||
|
transition: transform 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gpx-tree details[open] > summary::before {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (pointer: coarse) {
|
||||||
|
.gpx-tree summary::before {
|
||||||
|
width: 36px;
|
||||||
|
height: 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.gpx-tree__folder-row {
|
.gpx-tree__folder-row {
|
||||||
@@ -985,7 +1019,8 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
width: calc(100% - 18px);
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gpx-tree__folder-row > :first-child {
|
.gpx-tree__folder-row > :first-child {
|
||||||
@@ -997,34 +1032,13 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
|||||||
outline: 1px dashed #4a90d9;
|
outline: 1px dashed #4a90d9;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A track/route holding points: its row is the summary, a small
|
/* A track/route holding points: its row is the summary, the shared
|
||||||
triangle (not the browser's marker, gone with display:flex) opens the
|
.gpx-tree summary::before arrow opens the point list. */
|
||||||
point list. */
|
|
||||||
.gpx-tree__track > summary {
|
.gpx-tree__track > summary {
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
list-style: none;
|
|
||||||
margin-left: -12px;
|
margin-left: -12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gpx-tree__track > summary::-webkit-details-marker {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gpx-tree__track > summary::before {
|
|
||||||
content: "▸";
|
|
||||||
width: 12px;
|
|
||||||
flex: none;
|
|
||||||
color: #888;
|
|
||||||
font-size: 10px;
|
|
||||||
transition: transform 0.15s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gpx-tree__track[open] > summary::before {
|
|
||||||
transform: rotate(90deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.gpx-tree__track > summary > .gpx-tree__file {
|
.gpx-tree__track > summary > .gpx-tree__file {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
@@ -1697,6 +1711,73 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
|||||||
background: var(--accent-bg);
|
background: var(--accent-bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Point color swatches (PointStyleFields, notes.js); the first is "default". */
|
||||||
|
.notes-panel__colors {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 4px;
|
||||||
|
margin: 4px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notes-panel__color {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
padding: 0;
|
||||||
|
border: 2px solid #fff;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--swatch, repeating-linear-gradient(45deg, #fff 0 3px, #ccc 3px 6px));
|
||||||
|
box-shadow: 0 0 0 1px #bbb;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notes-panel__color.active {
|
||||||
|
box-shadow: 0 0 0 2px var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* B / I above a note's text (formatToolbar, notes.js). */
|
||||||
|
.notes-panel__format {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
margin: 4px 0 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notes-panel__format button {
|
||||||
|
min-width: 32px;
|
||||||
|
height: 28px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #fff;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notes-panel__format button:hover {
|
||||||
|
background: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Moving a note: the marker takes the accent color, the hint + Save/Cancel
|
||||||
|
ride in a popup above it. */
|
||||||
|
.note-move-marker {
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gpx-popup__move-bar p {
|
||||||
|
margin: 0 0 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (pointer: coarse) {
|
||||||
|
.notes-panel__color {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notes-panel__format button {
|
||||||
|
min-width: 44px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* The pending-note marker shown on the map while the save form is open —
|
/* The pending-note marker shown on the map while the save form is open —
|
||||||
updates live to whatever icon is picked (see notes.js's onIconChange). A
|
updates live to whatever icon is picked (see notes.js's onIconChange). A
|
||||||
plain round badge (not a drop-pin shape) since MapLibre anchors a custom
|
plain round badge (not a drop-pin shape) since MapLibre anchors a custom
|
||||||
@@ -2644,6 +2725,15 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
|||||||
cursor: grab;
|
cursor: grab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* An invisible 48px grab area around the 26px dot: a finger missed the dot
|
||||||
|
itself and panned the map instead (the marker is already absolutely
|
||||||
|
positioned by MapLibre, so this needs no position of its own). */
|
||||||
|
.route-marker::after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
inset: -11px;
|
||||||
|
}
|
||||||
|
|
||||||
.route-panel__remove:disabled {
|
.route-panel__remove:disabled {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-11
@@ -1,4 +1,5 @@
|
|||||||
import { Popup, LngLatBounds } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
import { Popup, LngLatBounds, Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||||
|
import { PointStyleFields, formatToolbar } from "/js/notes.js";
|
||||||
import {
|
import {
|
||||||
GPX_ICON,
|
GPX_ICON,
|
||||||
NEW_FOLDER_ICON,
|
NEW_FOLDER_ICON,
|
||||||
@@ -874,7 +875,7 @@ export class GpxPanelControl {
|
|||||||
const editable = feature.properties.category === "Note" && !!feature.properties.id && isLoggedIn();
|
const editable = feature.properties.category === "Note" && !!feature.properties.id && isLoggedIn();
|
||||||
const popup = new Popup({ closeButton: true, maxWidth: "260px" })
|
const popup = new Popup({ closeButton: true, maxWidth: "260px" })
|
||||||
.setLngLat(lngLat)
|
.setLngLat(lngLat)
|
||||||
.setHTML(popupHtml(feature.properties, { editable }))
|
.setHTML(popupHtml(feature.properties, { editable, movable: feature.geometry.type === "Point" }))
|
||||||
.addTo(this._map);
|
.addTo(this._map);
|
||||||
if (editable) this._wireNoteActions(popup, path, feature);
|
if (editable) this._wireNoteActions(popup, path, feature);
|
||||||
if (feature.geometry.type === "Point") {
|
if (feature.geometry.type === "Point") {
|
||||||
@@ -946,6 +947,7 @@ export class GpxPanelControl {
|
|||||||
content.innerHTML = `
|
content.innerHTML = `
|
||||||
<div class="gpx-popup__edit-form">
|
<div class="gpx-popup__edit-form">
|
||||||
<input type="text" class="gpx-popup__edit-title" value="${escapeHtml(feature.properties.name || "")}">
|
<input type="text" class="gpx-popup__edit-title" value="${escapeHtml(feature.properties.name || "")}">
|
||||||
|
<div class="gpx-popup__edit-style"></div>
|
||||||
<textarea class="gpx-popup__edit-body" rows="3" placeholder="Details (optional) — **bold**, *italic*, links">${escapeHtml(feature.properties.description || "")}</textarea>
|
<textarea class="gpx-popup__edit-body" rows="3" placeholder="Details (optional) — **bold**, *italic*, links">${escapeHtml(feature.properties.description || "")}</textarea>
|
||||||
<div class="gpx-popup__edit-actions">
|
<div class="gpx-popup__edit-actions">
|
||||||
<button type="button" class="gpx-popup__edit-save">Save</button>
|
<button type="button" class="gpx-popup__edit-save">Save</button>
|
||||||
@@ -955,31 +957,75 @@ export class GpxPanelControl {
|
|||||||
`;
|
`;
|
||||||
const titleInput = content.querySelector(".gpx-popup__edit-title");
|
const titleInput = content.querySelector(".gpx-popup__edit-title");
|
||||||
const bodyInput = content.querySelector(".gpx-popup__edit-body");
|
const bodyInput = content.querySelector(".gpx-popup__edit-body");
|
||||||
|
bodyInput.before(formatToolbar(bodyInput));
|
||||||
|
const style = new PointStyleFields(content.querySelector(".gpx-popup__edit-style"));
|
||||||
|
style.set(feature.properties.icon || "", feature.properties.color === TRACK_COLOR ? "" : feature.properties.color || "");
|
||||||
|
style.iconsVisible = feature.geometry.type === "Point";
|
||||||
titleInput.focus();
|
titleInput.focus();
|
||||||
content.querySelector(".gpx-popup__edit-cancel").addEventListener("click", () => {
|
content.querySelector(".gpx-popup__edit-cancel").addEventListener("click", () => {
|
||||||
content.innerHTML = popupHtml(feature.properties, { editable: true });
|
content.innerHTML = popupHtml(feature.properties, { editable: true, movable: feature.geometry.type === "Point" });
|
||||||
this._wireNoteActions(popup, path, feature);
|
this._wireNoteActions(popup, path, feature);
|
||||||
});
|
});
|
||||||
content.querySelector(".gpx-popup__edit-save").addEventListener("click", async () => {
|
content.querySelector(".gpx-popup__edit-save").addEventListener("click", async () => {
|
||||||
const title = titleInput.value.trim();
|
const title = titleInput.value.trim();
|
||||||
if (!title) return;
|
if (!title) return;
|
||||||
const details = bodyInput.value.trim();
|
const details = bodyInput.value.trim();
|
||||||
const properties = { ...feature.properties, name: title };
|
const properties = style.applyTo({ ...feature.properties, name: title });
|
||||||
if (details) properties.description = details;
|
if (details) properties.description = details;
|
||||||
else delete properties.description;
|
else delete properties.description;
|
||||||
const updated = { ...feature, properties };
|
if (await this._saveNote(path, { ...feature, properties })) popup.remove();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Move: a draggable marker at the point — drag it, or tap the new spot —
|
||||||
|
// with Save/Cancel in a popup that follows it.
|
||||||
|
element.querySelector(".gpx-popup__move")?.addEventListener("click", () => {
|
||||||
|
popup.remove();
|
||||||
|
this._moveNote(path, feature);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_moveNote(path, feature) {
|
||||||
|
this._cancelMove?.();
|
||||||
|
const markerEl = document.createElement("div");
|
||||||
|
markerEl.className = "route-marker note-move-marker";
|
||||||
|
const marker = new Marker({ element: markerEl, draggable: true }).setLngLat(feature.geometry.coordinates).addTo(this._map);
|
||||||
|
const bar = document.createElement("div");
|
||||||
|
bar.className = "gpx-popup__move-bar";
|
||||||
|
bar.innerHTML = `<p>Drag the point or tap its new spot</p><div class="gpx-popup__edit-actions"><button type="button" class="gpx-popup__edit-save">Save</button><button type="button" class="gpx-popup__edit-cancel">Cancel</button></div>`;
|
||||||
|
const barPopup = new Popup({ closeButton: false, closeOnClick: false, offset: 22, maxWidth: "240px" }).setDOMContent(bar);
|
||||||
|
marker.setPopup(barPopup).togglePopup();
|
||||||
|
const onMapClick = (event) => {
|
||||||
|
marker.setLngLat(event.lngLat);
|
||||||
|
if (!barPopup.isOpen()) marker.togglePopup();
|
||||||
|
};
|
||||||
|
this._map.on("click", onMapClick);
|
||||||
|
const end = () => {
|
||||||
|
this._map.off("click", onMapClick);
|
||||||
|
marker.remove();
|
||||||
|
this._cancelMove = null;
|
||||||
|
};
|
||||||
|
this._cancelMove = end;
|
||||||
|
bar.querySelector(".gpx-popup__edit-cancel").addEventListener("click", end);
|
||||||
|
bar.querySelector(".gpx-popup__edit-save").addEventListener("click", async () => {
|
||||||
|
const { lng, lat } = marker.getLngLat();
|
||||||
|
if (await this._saveNote(path, { ...feature, geometry: { ...feature.geometry, coordinates: [lng, lat] } })) end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUTs the edited note and reloads its file's layers; false on failure.
|
||||||
|
async _saveNote(path, updated) {
|
||||||
try {
|
try {
|
||||||
const body = new URLSearchParams({ path, id, feature: JSON.stringify(updated) });
|
const body = new URLSearchParams({ path, id: updated.properties.id, feature: JSON.stringify(updated) });
|
||||||
const response = await fetch("/api/library/notes", { method: "PUT", body });
|
const response = await fetch("/api/library/notes", { method: "PUT", body });
|
||||||
if (!response.ok) throw new Error(`save failed: ${response.status}`);
|
if (!response.ok) throw new Error(`save failed: ${response.status}`);
|
||||||
popup.remove();
|
|
||||||
notifyGpxStoreChanged();
|
notifyGpxStoreChanged();
|
||||||
await this._reloadFile(path);
|
await this._reloadFile(path);
|
||||||
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
window.alert("Could not save the note — check your connection and try again.");
|
window.alert("Could not save the note — check your connection and try again.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _reloadFile(path) {
|
async _reloadFile(path) {
|
||||||
@@ -1459,7 +1505,7 @@ function nodeKeys(node) {
|
|||||||
// for — see _registerPointInteractivity) adds Edit/Delete buttons; the
|
// for — see _registerPointInteractivity) adds Edit/Delete buttons; the
|
||||||
// click handling for them lives in _wireNoteActions, not here, since this
|
// click handling for them lives in _wireNoteActions, not here, since this
|
||||||
// only builds markup, it has no map/store access of its own.
|
// only builds markup, it has no map/store access of its own.
|
||||||
function popupHtml({ name, description, time, category, photos, icon }, { editable = false } = {}) {
|
function popupHtml({ name, description, time, category, photos, icon }, { editable = false, movable = false } = {}) {
|
||||||
const parts = [];
|
const parts = [];
|
||||||
if (name) {
|
if (name) {
|
||||||
const glyph = icon && POI_ICONS[icon] ? `<span class="gpx-popup__header-icon">${POI_ICONS[icon]}</span>` : "";
|
const glyph = icon && POI_ICONS[icon] ? `<span class="gpx-popup__header-icon">${POI_ICONS[icon]}</span>` : "";
|
||||||
@@ -1482,7 +1528,7 @@ function popupHtml({ name, description, time, category, photos, icon }, { editab
|
|||||||
}
|
}
|
||||||
if (editable) {
|
if (editable) {
|
||||||
parts.push(
|
parts.push(
|
||||||
`<div class="gpx-popup__note-actions"><button type="button" class="gpx-popup__edit">Edit</button><button type="button" class="gpx-popup__delete">Delete</button></div>`,
|
`<div class="gpx-popup__note-actions"><button type="button" class="gpx-popup__edit">Edit</button>${movable ? `<button type="button" class="gpx-popup__move">Move</button>` : ""}<button type="button" class="gpx-popup__delete">Delete</button></div>`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return parts.length > 0 ? parts.join("") : "<em>No details</em>";
|
return parts.length > 0 ? parts.join("") : "<em>No details</em>";
|
||||||
|
|||||||
+103
-36
@@ -38,6 +38,102 @@ const PICKER_ICONS = [
|
|||||||
.map((name) => [name, name.replace(/-/g, " ")]),
|
.map((name) => [name, name.replace(/-/g, " ")]),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Badge colors a point can take: the track palette plus NPS olive, brown and
|
||||||
|
// black. "" = no color of its own (the layer's default badge color).
|
||||||
|
const POINT_COLORS = ["#e63946", "#e0a32e", "#7cc957", "#2aa7a0", "#5a55e0", "#9058d6", "#546619", "#5e4b3c", "#1a1a1a"];
|
||||||
|
|
||||||
|
// Icon + color for a point — shared by the new-note form and the Edit form
|
||||||
|
// in a point's popup (gpx.js), so both offer the same choices.
|
||||||
|
export class PointStyleFields {
|
||||||
|
constructor(container, { onIconChange } = {}) {
|
||||||
|
this._onIconChange = onIconChange;
|
||||||
|
this.el = document.createElement("div");
|
||||||
|
this.el.className = "notes-panel__style";
|
||||||
|
this.el.innerHTML = `
|
||||||
|
<div class="notes-panel__colors" role="radiogroup" aria-label="Color">
|
||||||
|
<button type="button" class="notes-panel__color" data-color="" title="Default color" aria-label="Default color"></button>
|
||||||
|
${POINT_COLORS.map((c) => `<button type="button" class="notes-panel__color" data-color="${c}" style="--swatch:${c}" title="${c}" aria-label="${c}"></button>`).join("")}
|
||||||
|
</div>
|
||||||
|
<div class="notes-panel__icon-picker">
|
||||||
|
<input type="search" class="notes-panel__icon-filter" placeholder="Find an icon (${PICKER_ICONS.length})">
|
||||||
|
<div class="notes-panel__icons">
|
||||||
|
<button type="button" class="notes-panel__icon-option" data-icon="" title="No icon">${NOTE_PIN_ICON}</button>
|
||||||
|
${PICKER_ICONS.map(
|
||||||
|
([key, label]) =>
|
||||||
|
`<button type="button" class="notes-panel__icon-option" data-icon="${key}" title="${escapeAttr(label)}">${POI_ICONS[key]}</button>`,
|
||||||
|
).join("")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
container.appendChild(this.el);
|
||||||
|
this._filter = this.el.querySelector(".notes-panel__icon-filter");
|
||||||
|
this._filter.addEventListener("input", () => {
|
||||||
|
const query = this._filter.value.trim().toLowerCase();
|
||||||
|
this.el.querySelectorAll(".notes-panel__icon-option").forEach((b) => {
|
||||||
|
b.hidden = query !== "" && !`${b.title} ${b.dataset.icon}`.toLowerCase().includes(query);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.el.querySelectorAll(".notes-panel__icon-option").forEach((button) =>
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
this._setIcon(button.dataset.icon);
|
||||||
|
this._onIconChange?.(this.icon);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
this.el.querySelectorAll(".notes-panel__color").forEach((button) => button.addEventListener("click", () => this._setColor(button.dataset.color)));
|
||||||
|
this.set();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resets the filter too; an unknown color/icon just leaves none selected.
|
||||||
|
set(icon = "", color = "") {
|
||||||
|
this._filter.value = "";
|
||||||
|
this.el.querySelectorAll(".notes-panel__icon-option").forEach((b) => (b.hidden = false));
|
||||||
|
this._setIcon(icon);
|
||||||
|
this._setColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// An icon only makes sense on a single point (not a measured line/area).
|
||||||
|
set iconsVisible(visible) {
|
||||||
|
this.el.querySelector(".notes-panel__icon-picker").hidden = !visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
_setIcon(icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
this.el.querySelectorAll(".notes-panel__icon-option").forEach((b) => b.classList.toggle("active", b.dataset.icon === icon));
|
||||||
|
}
|
||||||
|
|
||||||
|
_setColor(color) {
|
||||||
|
this.color = color;
|
||||||
|
this.el.querySelectorAll(".notes-panel__color").forEach((b) => b.classList.toggle("active", b.dataset.color === color));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writes icon/color into a feature's properties (removing the ones unset).
|
||||||
|
applyTo(properties) {
|
||||||
|
for (const [key, value] of [["icon", this.icon], ["color", this.color]]) {
|
||||||
|
if (value) properties[key] = value;
|
||||||
|
else delete properties[key];
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// B / I buttons above a note's textarea: wrap the selection in the light
|
||||||
|
// markdown formatNoteBody renders (**bold**, *italic*), or insert an empty
|
||||||
|
// pair with the cursor in between.
|
||||||
|
export function formatToolbar(textarea) {
|
||||||
|
const bar = document.createElement("div");
|
||||||
|
bar.className = "notes-panel__format";
|
||||||
|
bar.innerHTML = `<button type="button" data-mark="**" title="Bold" aria-label="Bold"><b>B</b></button><button type="button" data-mark="*" title="Italic" aria-label="Italic"><i>I</i></button>`;
|
||||||
|
bar.addEventListener("click", (event) => {
|
||||||
|
const mark = event.target.closest("button")?.dataset.mark;
|
||||||
|
if (!mark) return;
|
||||||
|
const { selectionStart: start, selectionEnd: end, value } = textarea;
|
||||||
|
textarea.value = value.slice(0, start) + mark + value.slice(start, end) + mark + value.slice(end);
|
||||||
|
textarea.focus();
|
||||||
|
textarea.setSelectionRange(start + mark.length, end + mark.length);
|
||||||
|
});
|
||||||
|
return bar;
|
||||||
|
}
|
||||||
|
|
||||||
const NEW_FOLDER_VALUE = "__new__";
|
const NEW_FOLDER_VALUE = "__new__";
|
||||||
|
|
||||||
// Every hand-drawn note (from here or measure.js's "Save as note") gets one
|
// Every hand-drawn note (from here or measure.js's "Save as note") gets one
|
||||||
@@ -67,16 +163,7 @@ export class NoteSaveForm {
|
|||||||
this._el.hidden = true;
|
this._el.hidden = true;
|
||||||
this._el.innerHTML = `
|
this._el.innerHTML = `
|
||||||
<input type="text" class="notes-panel__title" placeholder="Title">
|
<input type="text" class="notes-panel__title" placeholder="Title">
|
||||||
<div class="notes-panel__icon-picker">
|
<div class="notes-panel__style-slot"></div>
|
||||||
<input type="search" class="notes-panel__icon-filter" placeholder="Find an icon (${PICKER_ICONS.length})">
|
|
||||||
<div class="notes-panel__icons">
|
|
||||||
<button type="button" class="notes-panel__icon-option active" data-icon="" title="No icon">${NOTE_PIN_ICON}</button>
|
|
||||||
${PICKER_ICONS.map(
|
|
||||||
([key, label]) =>
|
|
||||||
`<button type="button" class="notes-panel__icon-option" data-icon="${key}" title="${escapeAttr(label)}">${POI_ICONS[key]}</button>`,
|
|
||||||
).join("")}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<textarea class="notes-panel__body" rows="3" placeholder="Details (optional) — **bold**, *italic*, links"></textarea>
|
<textarea class="notes-panel__body" rows="3" placeholder="Details (optional) — **bold**, *italic*, links"></textarea>
|
||||||
<select class="notes-panel__target"></select>
|
<select class="notes-panel__target"></select>
|
||||||
<input type="text" class="notes-panel__new-name" placeholder="Folder name" hidden>
|
<input type="text" class="notes-panel__new-name" placeholder="Folder name" hidden>
|
||||||
@@ -88,27 +175,12 @@ export class NoteSaveForm {
|
|||||||
container.appendChild(this._el);
|
container.appendChild(this._el);
|
||||||
|
|
||||||
this._title = this._el.querySelector(".notes-panel__title");
|
this._title = this._el.querySelector(".notes-panel__title");
|
||||||
this._iconPicker = this._el.querySelector(".notes-panel__icon-picker");
|
this._style = new PointStyleFields(this._el.querySelector(".notes-panel__style-slot"), { onIconChange: (icon) => this._onIconChange?.(icon) });
|
||||||
this._iconFilter = this._el.querySelector(".notes-panel__icon-filter");
|
|
||||||
this._iconFilter.addEventListener("input", () => {
|
|
||||||
const query = this._iconFilter.value.trim().toLowerCase();
|
|
||||||
this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((b) => {
|
|
||||||
b.hidden = query !== "" && !`${b.title} ${b.dataset.icon}`.toLowerCase().includes(query);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this._body = this._el.querySelector(".notes-panel__body");
|
this._body = this._el.querySelector(".notes-panel__body");
|
||||||
|
this._body.before(formatToolbar(this._body));
|
||||||
this._target = this._el.querySelector(".notes-panel__target");
|
this._target = this._el.querySelector(".notes-panel__target");
|
||||||
this._newName = this._el.querySelector(".notes-panel__new-name");
|
this._newName = this._el.querySelector(".notes-panel__new-name");
|
||||||
this._saveButton = this._el.querySelector(".notes-panel__save");
|
this._saveButton = this._el.querySelector(".notes-panel__save");
|
||||||
this._selectedIcon = "";
|
|
||||||
|
|
||||||
this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((button) => {
|
|
||||||
button.addEventListener("click", () => {
|
|
||||||
this._selectedIcon = button.dataset.icon;
|
|
||||||
this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((b) => b.classList.toggle("active", b === button));
|
|
||||||
this._onIconChange?.(this._selectedIcon);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this._target.addEventListener("change", () => {
|
this._target.addEventListener("change", () => {
|
||||||
this._newName.hidden = this._target.value !== NEW_FOLDER_VALUE;
|
this._newName.hidden = this._target.value !== NEW_FOLDER_VALUE;
|
||||||
if (!this._newName.hidden) this._newName.focus();
|
if (!this._newName.hidden) this._newName.focus();
|
||||||
@@ -126,17 +198,12 @@ export class NoteSaveForm {
|
|||||||
this._el.hidden = false;
|
this._el.hidden = false;
|
||||||
this._title.value = "";
|
this._title.value = "";
|
||||||
this._body.value = "";
|
this._body.value = "";
|
||||||
this._selectedIcon = "";
|
this._style.set();
|
||||||
this._iconFilter.value = "";
|
this._onIconChange?.("");
|
||||||
this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((b, i) => {
|
|
||||||
b.classList.toggle("active", i === 0);
|
|
||||||
b.hidden = false;
|
|
||||||
});
|
|
||||||
this._onIconChange?.(this._selectedIcon);
|
|
||||||
// An icon only makes sense on a single point — Measure's "Save as
|
// An icon only makes sense on a single point — Measure's "Save as
|
||||||
// note" can hand this a LineString/Polygon, which has no one spot for
|
// note" can hand this a LineString/Polygon, which has no one spot for
|
||||||
// a badge glyph to sit at.
|
// a badge glyph to sit at.
|
||||||
this._iconPicker.hidden = geometry.type !== "Point";
|
this._style.iconsVisible = geometry.type === "Point";
|
||||||
this._title.focus();
|
this._title.focus();
|
||||||
await this._populateTargets();
|
await this._populateTargets();
|
||||||
}
|
}
|
||||||
@@ -192,10 +259,10 @@ export class NoteSaveForm {
|
|||||||
category: "Note",
|
category: "Note",
|
||||||
time: new Date().toISOString(),
|
time: new Date().toISOString(),
|
||||||
...(details ? { description: details } : {}),
|
...(details ? { description: details } : {}),
|
||||||
...(this._selectedIcon ? { icon: this._selectedIcon } : {}),
|
|
||||||
},
|
},
|
||||||
geometry: this._geometry,
|
geometry: this._geometry,
|
||||||
};
|
};
|
||||||
|
this._style.applyTo(feature.properties);
|
||||||
|
|
||||||
const intoLine = folder.startsWith("item:");
|
const intoLine = folder.startsWith("item:");
|
||||||
const requestBody = new URLSearchParams({ feature: JSON.stringify(feature), ...(intoLine ? {} : { folder }) });
|
const requestBody = new URLSearchParams({ feature: JSON.stringify(feature), ...(intoLine ? {} : { folder }) });
|
||||||
|
|||||||
Reference in new issue
Block a user