mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
1727732841
A new manifest capability poiCategories (up to 4, icon from an allow-list, strict #rrggbb color) and the hook poiCategoryProvider.getPois behind the hook:poi-category-provider permission. GET /api/plugin-pois in the plugin contributions module answers them in the /api/maps/pois shape, with search_plugin_pois as the MCP twin. plugin: ids no longer count as Google place ids. SDK 1.8.0 carries the types, validation and docs. On the map, one hook merges the built-in categories with the ones active plugins declare, and the pill shows the plugin chips after a divider on desktop and phone, scrolling sideways instead of shrinking a chip below its touch target. A plugin chip searches through a repo that refuses offline and parses the answer strictly. Its pins, on Leaflet and GL, use the category's own icon and color, both checked again before they reach any markup, and the hover card lists the plugin's details as escaped text. A plugin POI can be added as a place like any other. The admin panels on desktop and phone show a chip for the new permission and the categories a plugin would add, from one shared module. Addresses discussion #1781.
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
import { createElement } from 'react'
|
|
import { PLUGIN_POI_DETAILS_MAX, isPluginPoiIcon, parsePluginPoiCategoryKey, type PluginPoiDetail } from '@trek/shared'
|
|
import { renderIconMarkup } from '../../utils/iconMarkup'
|
|
import { poiAppearance, type Poi } from './poiCategories'
|
|
import { pluginPoiColor } from './pluginPoiIcons'
|
|
|
|
/**
|
|
* What an explore POI pin is drawn with, for both map renderers (the Leaflet divIcon
|
|
* and the GL marker element), so the two cannot draw one POI two ways.
|
|
*
|
|
* Each renderer keeps its own disc markup around these parts, because the two have
|
|
* always differed by a style or two and a core pin has to come out exactly as it did.
|
|
*/
|
|
|
|
type PoiLook = Pick<Poi, 'category' | 'icon' | 'color'>
|
|
|
|
/**
|
|
* The disc colour and the white glyph inside it. The colour has been through
|
|
* poiAppearance, so a plugin value that is not `#rrggbb` never reaches the markup it is
|
|
* written into; an unknown category has no glyph.
|
|
*/
|
|
export function poiPinParts(poi: PoiLook): { color: string; svg: string } {
|
|
const { color, Icon } = poiAppearance(poi)
|
|
const svg = Icon ? renderIconMarkup(createElement(Icon, { size: 13, color: 'white', strokeWidth: 2.5 })) : ''
|
|
return { color, svg }
|
|
}
|
|
|
|
/**
|
|
* What a cached pin is looked up by. A core category is drawn the same way every time,
|
|
* so its key alone is enough. A plugin category is drawn from what its POI carries, and
|
|
* the plugin can change that with an update, so its key adds the checked colour and
|
|
* icon: a pin cached before the update is never handed out after it.
|
|
*/
|
|
export function poiPinCacheKey(poi: PoiLook): string {
|
|
if (!parsePluginPoiCategoryKey(poi.category)) return poi.category
|
|
const icon = isPluginPoiIcon(poi.icon) ? poi.icon : ''
|
|
return `${poi.category}|${pluginPoiColor(poi.color)}|${icon}`
|
|
}
|
|
|
|
/** One detail row told apart from the others, for a React key. */
|
|
export function poiDetailRowKey(row: PluginPoiDetail): string {
|
|
return `${row.label}\n${row.value}`
|
|
}
|
|
|
|
/**
|
|
* The plugin's detail rows to show on the hover card, at most as many as the contract
|
|
* allows and each one once. Plugin text, so every renderer writes it as text (React or
|
|
* escapeHtml), never as markup. Empty for a core POI, which has none.
|
|
*/
|
|
export function poiDetailRows(poi: Pick<Poi, 'details'>): PluginPoiDetail[] {
|
|
if (!Array.isArray(poi.details)) return []
|
|
const seen = new Set<string>()
|
|
return poi.details.slice(0, PLUGIN_POI_DETAILS_MAX).filter(row => {
|
|
const key = poiDetailRowKey(row)
|
|
if (seen.has(key)) return false
|
|
seen.add(key)
|
|
return true
|
|
})
|
|
}
|