extension api v2, ref #395

This commit is contained in:
vcoppe committed 2026-11-08 17:23:22 +01:00
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}