mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
refactor(ui): remove the map stack chip DOM builders
The dock renders the chips from the map source controls' published view, so renderMapStackChips, syncMapStackChips and MAP_STACK_CHIP_CLASS have no callers. Their tests now pin the chip models; the dock test keeps the rendered chips' button type and native enablement.
This commit is contained in:
1 parent
1de4f635ca
commit
0b8cb4f33f
6 files changed
+71
-326
No files matched your search
+9
-107
@@ -1,19 +1,18 @@
|
||||
// MAP STACK source chips — the always-visible replacement for the `<select>`
|
||||
// that used to sit in the Map Stack panel. One button per stack, rendered from
|
||||
// `MapStackController.getStacks()`. The approved sources below are
|
||||
// the whole shipped set; keeping the allowlist explicit means a stack added to
|
||||
// `MAP_STACKS` for another purpose cannot reach the tray until someone names it
|
||||
// here.
|
||||
// that used to sit in the Map Stack panel. One chip model per stack, from
|
||||
// `MapStackController.getStacks()`; the dock renders them. The approved sources
|
||||
// below are the whole shipped set; keeping the allowlist explicit means a stack
|
||||
// added to `MAP_STACKS` for another purpose cannot reach the tray until someone
|
||||
// names it here.
|
||||
//
|
||||
// The chips are a control SURFACE only: selecting one calls back into the same
|
||||
// `_setMapStack()` path the dropdown's `change` handler used, and the active
|
||||
// state is re-synced from controller state (never optimistically), so a failed
|
||||
// or superseded switch still leaves the truly-active stack lit.
|
||||
// The chips are a control SURFACE only: selecting one calls
|
||||
// `createMapSourceControls().select()`, the path `_setMapStack()` uses, and the
|
||||
// active state is re-synced from controller state (never optimistically), so a
|
||||
// failed or superseded switch still leaves the truly-active stack lit.
|
||||
|
||||
import { keySetupRequirementEnvVars } from './keySetupCore.mjs';
|
||||
import { t } from './i18n/index.js';
|
||||
|
||||
export const MAP_STACK_CHIP_CLASS = 'map-stack-chip';
|
||||
export const PRESENTED_MAP_STACK_IDS = Object.freeze([
|
||||
'photoreal',
|
||||
'bing-aerial',
|
||||
@@ -78,100 +77,3 @@ export function mapStackChipModels(stacks, activeId) {
|
||||
.filter(Boolean)
|
||||
.map((stack) => mapStackChipModel(stack, activeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the chip row into `container`, replacing any previous chips.
|
||||
* @deprecated Core's dock renders the row from `createMapSourceControls()`'s
|
||||
* published view; this DOM builder is no longer used by Core.
|
||||
* @param {HTMLElement} container - Row element.
|
||||
* @param {Array<object>} stacks - `MapStackController.getStacks()` output.
|
||||
* @param {object} [options]
|
||||
* @param {string|null} [options.activeId] - Currently active stack id.
|
||||
* @param {(stackId: string) => void} [options.onSelect] - Selection callback.
|
||||
* @param {Document} [options.doc] - Document override (tests).
|
||||
* @param {(element: HTMLElement, type: string, listener: Function) => void} [options.bind] - Listener owner override.
|
||||
* @returns {Array<object>} The rendered chip models.
|
||||
*/
|
||||
export function renderMapStackChips(
|
||||
container,
|
||||
stacks,
|
||||
{
|
||||
activeId = null,
|
||||
onSelect = null,
|
||||
doc,
|
||||
bind = (element, type, listener) =>
|
||||
element.addEventListener(type, listener),
|
||||
} = {},
|
||||
) {
|
||||
if (!container) return [];
|
||||
const ownerDoc = doc || container.ownerDocument || globalThis.document;
|
||||
if (!ownerDoc?.createElement) return [];
|
||||
|
||||
container.innerHTML = '';
|
||||
const models = mapStackChipModels(stacks, activeId);
|
||||
|
||||
for (const model of models) {
|
||||
const chip = ownerDoc.createElement('button');
|
||||
chip.type = 'button';
|
||||
chip.className = [
|
||||
MAP_STACK_CHIP_CLASS,
|
||||
model.active ? 'active' : '',
|
||||
model.available ? '' : 'unavailable',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
chip.dataset.stackId = model.id;
|
||||
chip.title = model.title;
|
||||
chip.setAttribute('aria-pressed', String(model.active));
|
||||
chip.setAttribute('aria-disabled', String(!model.available));
|
||||
if (!model.available) {
|
||||
chip.setAttribute(
|
||||
'aria-label',
|
||||
t('{label} unavailable: {hint}', {
|
||||
label: model.label,
|
||||
hint: model.unavailableHint,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const label = ownerDoc.createElement('span');
|
||||
label.className = 'map-stack-chip-label';
|
||||
label.textContent = model.label;
|
||||
chip.appendChild(label);
|
||||
|
||||
if (model.requirement) {
|
||||
const requirement = ownerDoc.createElement('span');
|
||||
requirement.className = 'map-stack-chip-req';
|
||||
requirement.textContent = model.requirement;
|
||||
chip.appendChild(requirement);
|
||||
}
|
||||
|
||||
bind(chip, 'click', () => {
|
||||
if (!model.available) return;
|
||||
onSelect?.(model.id);
|
||||
});
|
||||
container.appendChild(chip);
|
||||
}
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-points the active chip at controller state.
|
||||
* @deprecated Core's dock renders the active chip from the published view. Availability never changes at
|
||||
* runtime (it tracks the ion token), so only the active/pressed pair is synced.
|
||||
* @param {HTMLElement} container - Row element.
|
||||
* @param {string|null} activeId - Currently active stack id.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function syncMapStackChips(container, activeId) {
|
||||
const chips = container?.children;
|
||||
if (!chips) return;
|
||||
for (const chip of Array.from(chips)) {
|
||||
const stackId = chip?.dataset?.stackId;
|
||||
if (!stackId) continue;
|
||||
const active = stackId === activeId;
|
||||
chip.classList?.toggle('active', active);
|
||||
chip.setAttribute?.('aria-pressed', String(active));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user