mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-30 09:34:29 +00:00
extension api v2, ref #395
This commit is contained in:
1 parent
7474f892ce
commit
4050420b3c
8 files changed
+989
-58
No files matched your search
@@ -12,6 +12,7 @@
|
||||
let {
|
||||
name,
|
||||
node,
|
||||
parent = '',
|
||||
selected = '',
|
||||
onselect = () => {},
|
||||
multiple = false,
|
||||
@@ -19,6 +20,7 @@
|
||||
}: {
|
||||
name: string;
|
||||
node: LayerTreeType;
|
||||
parent?: string;
|
||||
selected?: string;
|
||||
onselect?: (value: string) => void;
|
||||
multiple: boolean;
|
||||
@@ -26,7 +28,21 @@
|
||||
} = $props();
|
||||
|
||||
const { customLayers } = settings;
|
||||
const { isLayerFromExtension, getLayerName } = extensionAPI;
|
||||
const { isLayerFromExtension, getLayerName, isExtensionGroup } = extensionAPI;
|
||||
|
||||
/** The groups of extensions are right below the overlays, with the name they were given. */
|
||||
function getGroupLabel(id: string) {
|
||||
return parent === 'overlays' && $isExtensionGroup(id)
|
||||
? id
|
||||
: i18n._(`layers.label.${id}`, id);
|
||||
}
|
||||
|
||||
function getLabel(id: string) {
|
||||
if (Object.hasOwn($customLayers, id)) {
|
||||
return $customLayers[id].name;
|
||||
}
|
||||
return $isLayerFromExtension(id) ? $getLayerName(id) : i18n._(`layers.label.${id}`);
|
||||
}
|
||||
|
||||
$effect.pre(() => {
|
||||
if (checked !== undefined) {
|
||||
@@ -57,7 +73,7 @@
|
||||
() => checked[id] === true, (value) => (checked[id] = value)
|
||||
}
|
||||
class="scale-90"
|
||||
aria-label={i18n._(`layers.label.${id}`)}
|
||||
aria-label={getLabel(id)}
|
||||
/>
|
||||
{:else}
|
||||
<input
|
||||
@@ -74,25 +90,20 @@
|
||||
/>
|
||||
{/if}
|
||||
<Label for="{name}-{id}" class="flex flex-row items-center gap-1">
|
||||
{#if Object.hasOwn($customLayers, id)}
|
||||
{$customLayers[id].name}
|
||||
{:else if $isLayerFromExtension(id)}
|
||||
{$getLayerName(id)}
|
||||
{:else}
|
||||
{i18n._(`layers.label.${id}`)}
|
||||
{/if}
|
||||
{getLabel(id)}
|
||||
</Label>
|
||||
</div>
|
||||
{/if}
|
||||
{:else if anySelectedLayer(node[id])}
|
||||
<CollapsibleTreeNode {id}>
|
||||
{#snippet trigger()}
|
||||
<span>{i18n._(`layers.label.${id}`, id)}</span>
|
||||
<span>{getGroupLabel(id)}</span>
|
||||
{/snippet}
|
||||
{#snippet content()}
|
||||
<div class="ml-2">
|
||||
<Self
|
||||
node={node[id] as LayerTreeType}
|
||||
parent={id}
|
||||
{name}
|
||||
{selected}
|
||||
{onselect}
|
||||
|
||||
Reference in new issue
Block a user