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
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-19 00:03:39 +01:00
1 parent 3e5fada66a
commit 07f3711760
3 files changed
+280 -77

No files matched your search

+103 -36
View File
@@ -38,6 +38,102 @@ const PICKER_ICONS = [
.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__";
// 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.innerHTML = `
<input type="text" class="notes-panel__title" placeholder="Title">
<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 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>
<div class="notes-panel__style-slot"></div>
<textarea class="notes-panel__body" rows="3" placeholder="Details (optional) — **bold**, *italic*, links"></textarea>
<select class="notes-panel__target"></select>
<input type="text" class="notes-panel__new-name" placeholder="Folder name" hidden>
@@ -88,27 +175,12 @@ export class NoteSaveForm {
container.appendChild(this._el);
this._title = this._el.querySelector(".notes-panel__title");
this._iconPicker = this._el.querySelector(".notes-panel__icon-picker");
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._style = new PointStyleFields(this._el.querySelector(".notes-panel__style-slot"), { onIconChange: (icon) => this._onIconChange?.(icon) });
this._body = this._el.querySelector(".notes-panel__body");
this._body.before(formatToolbar(this._body));
this._target = this._el.querySelector(".notes-panel__target");
this._newName = this._el.querySelector(".notes-panel__new-name");
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._newName.hidden = this._target.value !== NEW_FOLDER_VALUE;
if (!this._newName.hidden) this._newName.focus();
@@ -126,17 +198,12 @@ export class NoteSaveForm {
this._el.hidden = false;
this._title.value = "";
this._body.value = "";
this._selectedIcon = "";
this._iconFilter.value = "";
this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((b, i) => {
b.classList.toggle("active", i === 0);
b.hidden = false;
});
this._onIconChange?.(this._selectedIcon);
this._style.set();
this._onIconChange?.("");
// 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
// a badge glyph to sit at.
this._iconPicker.hidden = geometry.type !== "Point";
this._style.iconsVisible = geometry.type === "Point";
this._title.focus();
await this._populateTargets();
}
@@ -192,10 +259,10 @@ export class NoteSaveForm {
category: "Note",
time: new Date().toISOString(),
...(details ? { description: details } : {}),
...(this._selectedIcon ? { icon: this._selectedIcon } : {}),
},
geometry: this._geometry,
};
this._style.applyTo(feature.properties);
const intoLine = folder.startsWith("item:");
const requestBody = new URLSearchParams({ feature: JSON.stringify(feature), ...(intoLine ? {} : { folder }) });