Localess
SvelteKit

Reference

Assets, rich text, links, error handling, and the full export reference for Localess in SvelteKit.

Assets

@localess/svelte doesn't export a standalone asset-resolving helper (unlike @localess/react's resolveAsset or @localess/angular's llAsset pipe). Use the client's own assetLink() method, which builds a fully qualified URL from the configured origin and spaceId — never construct asset URLs by hand:

<script lang="ts">
  import { getLocaless } from '@localess/svelte';
  import type { LocalessSchemaProps } from '@localess/svelte';

  import type { HeroSection } from '../.localess/localess';

  let { data }: LocalessSchemaProps<HeroSection> = $props();
  const client = getLocaless();
</script>

<img src={client.assetLink(data.image)} alt={data.imageAlt} />

<!-- With transform parameters -->
<img src={client.assetLink(data.image, { w: 800, h: 600, q: 70, f: 'webp' })} alt="" />

ContentAsset isn't re-exported from @localess/svelte — import it from @localess/client if you need the type by name, alongside findLink (see Links below).

See Image Transforms for the query-string parameters the endpoint accepts (w, h, q, f, download, thumbnail).

Rich Text

<LocalessRichText />

Renders a Tiptap JSON rich-text field. The markup is derived with $derived, so it updates on its own when the field changes under Visual Editor live sync:

<script lang="ts">
  import { LocalessRichText } from '@localess/svelte';
  import type { LocalessSchemaProps } from '@localess/svelte';

  let { data }: LocalessSchemaProps<Article> = $props();
</script>

<LocalessRichText content={data.body} />
PropTypeDescription
contentLocalessRichTextInputThe rich text field value. Accepts a full document, a single node, an array of nodes, or null/undefined, so a field value passes through without casting
renderersLocalessRichTextRenderers<string>Optional per-node/per-mark overrides, keyed by element name

Supported elements: doc, paragraph, heading (levels 1–6), bulletList, orderedList, listItem, codeBlock, text; marks bold, italic, strike, underline, code, link. An unknown node is skipped and an unknown mark renders its children unwrapped, each with a one-time console.warn outside production.

Rendering is shared across every Localess SDK by @localess/richtext, so one document renders identically in Svelte, React, Angular, Vue, and Astro.

@localess/svelte doesn't re-export findLink yet — import it directly from @localess/client, which works fine in a Svelte <script> block (it's a pure function, no client instance needed):

<script lang="ts">
  import { findLink } from '@localess/client';

  let { data, links }: { data: { label: string; link: any }; links: any } = $props();
</script>

<a href={findLink(links, data.link)}>{data.label}</a>
ContentLink.typeResult
"content"Looks up link.uri in the links map and returns /<fullSlug>
"url"Returns link.uri as-is

Error handling

getContentBySlug/getContentById throw LocalessApiError on a non-2xx API response — check error.status to distinguish a missing slug (404) from other failures:

import { LocalessApiError, localessClient } from '@localess/svelte';

async function fetchPageData(slug: string) {
  const client = localessClient({ origin, spaceId, token });
  try {
    return await client.getContentBySlug(slug);
  } catch (error) {
    if (error instanceof LocalessApiError && error.status === 404) {
      return undefined;
    }
    throw error;
  }
}

API Reference

ExportKindDescription
localessInit(options)FunctionInitializes the client + component registry, sets Svelte context
getLocaless()FunctionReturns the client from Svelte context
localessClient(options)FunctionRaw client factory, re-exported from @localess/client, for standalone SSR data-loading outside localessInit (e.g. a +page.server.ts load())
LocalessComponentComponentDynamic schema-to-component renderer
LocalessDocumentComponentWraps LocalessComponent with automatic Visual Editor live sync
localessEditableActionuse:localessEditable={data} — applies data-ll-id/data-ll-schema
localessEditableField(name)FunctionApplies data-ll-field, spread onto an element
localessSync(event)FunctionVisual Editor bridge event subscription, returns a Readable
LocalessRichTextComponentRenders a rich text field
LocalessApiErrorClassRe-exported from @localess/client
LocalessSchemaProps<T>TypeProp shape your registered components accept — the one to type $props() with
LocalessComponentProps<T> / LocalessDocumentProps<T>TypeProp shapes of the built-in LocalessComponent / LocalessDocument renderers
LocalessRichTextDocument / LocalessRichTextInput / LocalessRichTextNode / LocalessRichTextMarkTypeRich text model types, re-exported from @localess/richtext
Assets / Content / ContentData / ContentDataSchema / Links / ReferencesTypeDomain-model types, re-exported from @localess/model

On this page