fix overlay sortering, duplicerad esc logik
This commit is contained in:
1 parent
a2e29b89dd
commit
1376169cb0
4 files changed
+22
-23
No files matched your search
+1
-9
@@ -1,4 +1,5 @@
|
||||
import { installListSorting } from "./list_sorting.js";
|
||||
import { escapeHtml } from "./html_escape.js";
|
||||
import { getOverlayModeLabel, buildOverlayPanels, renderOverlaySidePanel, renderOverlayLeaderboard, renderTeamOverlay, renderObsOverlay } from "./overlays.js";
|
||||
|
||||
import { renderSettings } from "./settings.js";
|
||||
@@ -5260,15 +5261,6 @@ function chunkArray(items, size) {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value)
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """)
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
|
||||
function isValidIsoDate(value) {
|
||||
return /^\d{4}-\d{2}-\d{2}$/.test(String(value || ""));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export function escapeHtml(value) {
|
||||
return String(value ?? "")
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """)
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
+4
-1
@@ -1,3 +1,5 @@
|
||||
import { escapeHtml } from "./html_escape.js";
|
||||
|
||||
const storageKey = "racecore.listSorting.v1";
|
||||
const preferences = new Map();
|
||||
let loaded = false;
|
||||
@@ -17,6 +19,7 @@ export function parseSortValue(value) {
|
||||
const text = String(value ?? "").trim();
|
||||
if (!text || /^[\s—–-]+$/.test(text)) return null;
|
||||
const normalized = text.replace(/\u2212/g, "-").replace(/,/g, ".");
|
||||
if (/^0\d/.test(normalized)) return text; // zero-padded identifiers (e.g. car number "09") are names, not quantities - keep as text so "09" and "9" don't collide
|
||||
if (/^[+-]?\d+(?:\.\d+)?\s*(?:%|s|L)?$/.test(normalized)) return parseFloat(normalized);
|
||||
if (/^[+-]?\d+(?::\d+){1,2}(?:\.\d+)?$/.test(normalized)) {
|
||||
const sign = normalized.startsWith("-") ? -1 : 1;
|
||||
@@ -42,7 +45,7 @@ export function compareSortValues(left, right, direction = "asc") {
|
||||
}
|
||||
|
||||
export function sortValuesAttribute(values) {
|
||||
return JSON.stringify(values).replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<").replaceAll(">", ">");
|
||||
return escapeHtml(JSON.stringify(values));
|
||||
}
|
||||
|
||||
export function sortableTable(markup, id) {
|
||||
|
||||
+9
-13
@@ -1,4 +1,5 @@
|
||||
import { sortValuesAttribute } from "./list_sorting.js";
|
||||
import { escapeHtml as escapeHtmlLocal } from "./html_escape.js";
|
||||
export function getOverlayModeLabel(mode, { t }) {
|
||||
return t(`overlay.mode_${String(mode || "leaderboard").toLowerCase()}`);
|
||||
}
|
||||
@@ -55,18 +56,22 @@ export function renderOverlaySidePanel(panel, { t, escapeHtml }) {
|
||||
`;
|
||||
}
|
||||
|
||||
export function renderOverlayLeaderboard(rows, { t, escapeHtml, formatTeamActiveMemberLabel, formatLap, formatPredictedLapDelta }) {
|
||||
export function renderOverlayLeaderboard(rows, { t, escapeHtml, formatTeamActiveMemberLabel, formatLap, formatPredictedLapDelta }, { sortable = true } = {}) {
|
||||
if (!rows.length) {
|
||||
return `<p>${t("timing.no_laps")}</p>`;
|
||||
}
|
||||
|
||||
const sortAttrs = sortable
|
||||
? ` data-sort-id="overlay-leaderboard" data-sort-labels="${sortValuesAttribute([t("table.pos"), t("table.driver"), t("table.laps"), t("table.result"), t("table.gap"), t("table.ahead_gap"), t("table.own_delta"), t("table.best_lap")])}"`
|
||||
: "";
|
||||
return `
|
||||
<div class="overlay-race-list" data-sort-id="overlay-leaderboard" data-sort-labels="${sortValuesAttribute([t("table.pos"), t("table.driver"), t("table.laps"), t("table.result"), t("table.gap"), t("table.ahead_gap"), t("table.own_delta"), t("table.best_lap")])}">
|
||||
<div class="overlay-race-list"${sortAttrs}>
|
||||
${rows
|
||||
.map((row, idx) => {
|
||||
const posClass = idx === 0 ? "pos-1" : idx === 1 ? "pos-2" : idx === 2 ? "pos-3" : "";
|
||||
const rowSortAttr = sortable ? ` data-sort-values="${sortValuesAttribute([idx + 1, row.displayName || row.driverName, row.laps ?? 0, row.resultDisplay, row.gapDisplay || row.gapAhead || null, row.gapAhead || null, row.lapDelta || null, row.bestLapMs || null])}"` : "";
|
||||
return `
|
||||
<article class="overlay-race-row ${idx === 0 ? "overlay-race-row-leader" : ""} ${row.invalidPending ? "overlay-race-row-invalid" : ""}" data-sort-values="${sortValuesAttribute([idx + 1, row.displayName || row.driverName, row.laps ?? 0, row.resultDisplay, row.gapDisplay || row.gapAhead || null, row.gapAhead || null, row.lapDelta || null, row.bestLapMs || null])}" data-overlay-competitor="${escapeHtml(row.key)}">
|
||||
<article class="overlay-race-row ${idx === 0 ? "overlay-race-row-leader" : ""} ${row.invalidPending ? "overlay-race-row-invalid" : ""}"${rowSortAttr} data-overlay-competitor="${escapeHtml(row.key)}">
|
||||
<div class="overlay-race-pos">
|
||||
<span class="pos-pill ${posClass}">${idx + 1}</span>
|
||||
</div>
|
||||
@@ -234,7 +239,7 @@ export function renderObsOverlay(active, leaderboard, result, sessionTiming, bra
|
||||
<h3>${showStartGrid ? t("events.start_grid") : t("overlay.leaderboard_live")}</h3>
|
||||
<span class="pill">${t("overlay.mode_obs")}</span>
|
||||
</div>
|
||||
${showStartGrid ? renderPositionGrid(active) : renderOverlayLeaderboard(compactRows, deps)}
|
||||
${showStartGrid ? renderPositionGrid(active) : renderOverlayLeaderboard(compactRows, deps, { sortable: false })}
|
||||
</section>
|
||||
</section>
|
||||
`;
|
||||
@@ -333,15 +338,6 @@ export function renderObsOverlay(active, leaderboard, result, sessionTiming, bra
|
||||
`;
|
||||
}
|
||||
|
||||
function escapeHtmlLocal(value) {
|
||||
return String(value ?? "")
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """)
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
|
||||
function padClock(value) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user