Skip to content

Svelte bindings

./svelte needs the optional svelte peer (5 or later). The stores already satisfy Svelte’s store contract, so a component reads them as $store; the adapter adds the context and the onDestroy wiring:

<script lang="ts">
import { layersQuery } from "@archont561/qgis-sdk";
import { form, getQgisSdk, hostQuery, operation, stream } from "@archont561/qgis-sdk/svelte";
// The root component called setQgisSdk(QgisSdk.fromBridgeSchema(schema)).
const qgis = getQgisSdk<Operations, Streams>();
const summary = operation(qgis.sites.summary); // aborted on destroy
const watch = stream(qgis.sites.watch, { onEvent }); // watch.setInput(...)
const buffer = form(qgis, "buffer", { initial: { distance_metres: 500 } });
const layers = hostQuery(layersQuery(qgis)); // refreshed once, closed on destroy
</script>
{#if $layers.status === "refused"}<p>{$layers.message}</p>{/if}
{#each buffer.fields as field}<label>{field.label} <input on:input={(e) => buffer.set(field.name, e.currentTarget.value)} /></label>{/each}
<p>{$buffer.valid ? "" : Object.values($buffer.errors).join(", ")}</p>

toRune(store) returns { current } backed by $state for a runes-mode component that prefers it to $store. setQgisSdk/getQgisSdk outside component initialisation raise QgisSdkBridgeSvelteError ("svelte_binding"); QGIS_SDK_CONTEXT is the context key.