> ## Documentation Index
> Fetch the complete documentation index at: https://docs.widgetic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# UI Components

> Put Widgetic's File Browser, Composition Editor, Embed Editor, Widget Creator and Workflows in your own page

The UI SDK (`@widgetic/ui-sdk`) puts Widgetic's ready-made pieces in your own web page with a few lines of code. Your customers use them without leaving your product and without a Widgetic account.

## The pieces

| Module | What your customer can do | The session needs |
| - | - | - |
| [`file-browser`](https://docs.widgetic.com/docs/partners/ui-components/file-browser) | Browse, upload and pick files, from Widgetic's media library (files kept in your own storage) or from your own | `files` (nothing, with your own [media library](https://docs.widgetic.com/docs/partners/ui-components/file-browser.md#show-your-own-media-library)) |
| [`composition-editor`](https://docs.widgetic.com/docs/partners/ui-components/composition-editor) | Change the texts, pictures, colours and fonts of a widget beside a live preview, and save | `editor` and `files` |
| [`embed-editor`](https://docs.widgetic.com/docs/partners/ui-components/embed-editor) | Decide how and where a widget shows on a page, get the embed code to paste, and have an assistant set the options from a sentence | `editor` |
| [`widget-creator`](https://docs.widgetic.com/docs/partners/ui-components/widget-creator) | The whole Widgetic canvas with its agentic chat: draw, describe a widget in the chat, watch the AI agent plan and build it, change it and publish it | `creator`, `editor` and `files` |
| [`workflows`](https://docs.widgetic.com/docs/partners/ui-components/workflows) | Where a customer builds workflows: compositions chained together, with filters between them that decide which one a visitor sees next. The list of their workflows and, one click away, the editor of one: blocks and lines on a canvas, a draft that is saved while you work, and versions you publish | `workflows` |

Each piece has a page of its own, with its options, its events and what is special about it: the [File Browser](https://docs.widgetic.com/docs/partners/ui-components/file-browser.md), the [Composition Editor](https://docs.widgetic.com/docs/partners/ui-components/composition-editor.md), the [Embed Editor](https://docs.widgetic.com/docs/partners/ui-components/embed-editor.md), the [Widget Creator](https://docs.widgetic.com/docs/partners/ui-components/widget-creator.md) and [Workflows](https://docs.widgetic.com/docs/partners/ui-components/workflows.md). This page covers what they have in common: installing the SDK, mounting a piece, tokens, how the pieces look, their language, the Content Security Policy and their versions.

> [tab] File Browser
>
> ![The File Browser, with folders and files, filters by kind of file, a search box and a place to drop files to upload](https://mintcdn.com/widgetic/gAk6INxovACBcdI7/images/ui-components/file-browser.webp?fit=max\&auto=format\&n=gAk6INxovACBcdI7\&q=85\&s=2275ef33314692886d3859bff4f7f646)
>
> The File Browser: a customer's folders and files, filters by kind of file, search and sorting, and a place to drop files to upload.
>
> Its options, events and your own media library: [File Browser](https://docs.widgetic.com/docs/partners/ui-components/file-browser.md).

> [tab] Composition Editor
>
> ![The Composition Editor's settings panel, with Design and Content tabs and controls for a number, a text, a colour, sliders, a picture, a drop-down, a switch and dates](https://mintcdn.com/widgetic/gAk6INxovACBcdI7/images/ui-components/composition-editor.webp?fit=max\&auto=format\&n=gAk6INxovACBcdI7\&q=85\&s=0a066e26acdbe2fa8fc565630f1ababf)
>
> The Composition Editor: the settings panel of a widget, here with a few of its controls (numbers, text, colours, sliders, pictures, drop-downs, switches and dates). A live preview of the widget is drawn beside it.
>
> Its options, events and saving: [Composition Editor](https://docs.widgetic.com/docs/partners/ui-components/composition-editor.md).

> [tab] Embed Editor
>
> ![The Embed panel over the preview of a composition. It shows the embed code with a copy button and a Learn more link, the options Use iframe, Resize mode, Height and Autoscale, and under Layout and overlay the Embed target and a nine-square Overlay position. Beside it the Embed assistant asks 'Show it on mobile too?' with the answers 'Yes' and 'No, desktop only', above a box that says 'Describe how it should appear'.](https://mintcdn.com/widgetic/8U2zv4tj1bQpIFGs/images/ui-components/embed-editor.webp?fit=max\&auto=format\&n=8U2zv4tj1bQpIFGs\&q=85\&s=be01c22cc19c7fb80c4ebf3f4fdfcdb3)
>
> The Embed Editor: the embed code and the options of how a widget shows on a page, with the assistant's column beside them. It is the Embed panel of Widgetic's own site, drawn in your page.
>
> Its options, events, saving and the assistant: [Embed Editor](https://docs.widgetic.com/docs/partners/ui-components/embed-editor.md).

> [tab] Widget Creator
>
> ![The Widget Creator, with a countdown widget on the canvas and the agentic chat beside it, where the customer asks for changes and attaches pictures and documents](https://mintcdn.com/widgetic/gAk6INxovACBcdI7/images/ui-components/widget-creator.webp?fit=max\&auto=format\&n=gAk6INxovACBcdI7\&q=85\&s=835cc7a26566329514cb10cc1fe6aea0)
>
> The Widget Creator: the canvas with a widget on it, and the agentic chat beside it. The customer describes what they want and attaches pictures and documents, and the AI agent builds the widget and changes it on request.
>
> Its options, events, where it starts and the Upgrade button: [Widget Creator](https://docs.widgetic.com/docs/partners/ui-components/widget-creator.md).

> [tab] Workflows
>
> ![Workflows, with a path of compositions and a condition on a canvas and the Workflow assistant beside it](https://mintcdn.com/widgetic/gAk6INxovACBcdI7/images/ui-components/workflows.webp?fit=max\&auto=format\&n=gAk6INxovACBcdI7\&q=85\&s=41ac3418ef405da235a0e266cd9abded)
>
> Workflows: compositions chained on a canvas, with filters between them that decide which one a visitor sees next, and the Workflow assistant beside it.
>
> Its options, events and starting points: [Workflows](https://docs.widgetic.com/docs/partners/ui-components/workflows.md).

Four things hold for every piece:

* **They work only for a partner in good standing, with storage.** A session is made only while your account is active and your own [storage](https://docs.widgetic.com/docs/partners/storage.md) works (see [Every session needs your own storage](https://docs.widgetic.com/docs/partners/editor-sessions.md#every-session-needs-your-own-storage)). While your account is paused or stopped by an unpaid invoice, the pieces already on your customers' pages are refused too (see [Account Status](https://docs.widgetic.com/docs/partners/account-status.md)), and so they are once your partnership has ended, from the day after its last day (see [Ending a Partnership](https://docs.widgetic.com/docs/partners/ending-a-partnership.md)).
* **No API key in the browser.** Your server keeps the key and makes a short-lived [editor session](https://docs.widgetic.com/docs/partners/editor-sessions.md) for the customer who is on the page. The page only ever holds that session's token, and it can reach only that customer's content.
* **Your page stays yours.** A piece is drawn inside a shadow root: your CSS cannot restyle it and its CSS cannot touch your page. The SDK writes nothing to `<html>` or `<body>`, sends no `postMessage` and never clears your container.
* **Small.** The SDK is a loader of about 30 KB. A piece is downloaded from Widgetic's CDN when you mount it, and only then.

## How it works

**1. Your server makes an editor session**

When the page opens, your server asks Widgetic for a session for the signed-in customer (`POST /v1/managed-users/{id}/editor-sessions`, with your API key) and returns the token. See [Editor Sessions](https://docs.widgetic.com/docs/partners/editor-sessions.md).

**2. Your page gives the SDK a getToken function**

`getToken` fetches that token from your server. The SDK calls it when the piece starts and again shortly before the token runs out.

**3. The SDK mounts the piece**

It downloads the piece, draws it in your container, and the piece talks to the Widgetic API with the token and nothing else.

## Install

```bash theme={"theme":"css-variables"}
npm install @widgetic/ui-sdk
```

Or with a script tag. Pin the exact version you have tested and do not use `@latest`. Replace `<version>` with it; `npm view @widgetic/ui-sdk version` prints the newest one:

```html theme={"theme":"css-variables"}
<script src="https://unpkg.com/@widgetic/ui-sdk@<version>/dist/umd/ui-sdk.js"></script>
<script>
  WidgeticUISDK.mountModule('file-browser', {
    container: '#media-library',
    getToken: () => fetch('/widgetic-session', { method: 'POST' }).then((response) => response.json()),
    on: { select: ({ files }) => console.log(files) },
  });
</script>
```

## Mount a piece

Give the container a height: the piece fills it.

```javascript theme={"theme":"css-variables"}
import { mountModule } from '@widgetic/ui-sdk';

const fileBrowser = await mountModule('file-browser', {
  container: document.querySelector('#media-library'), // an element, or a CSS selector
  getToken: async () => (await fetch('/widgetic-session', { method: 'POST' })).json(), // { token, expiresAt }
  maxSelections: 1,
  on: {
    select: ({ files }) => useFiles(files), // [{ id, name, url, mimeType?, size?, thumbnail? }]
  },
});

// later:
await fileBrowser.unmount();
```

`/widgetic-session` is the endpoint of yours that makes the session (see [A server endpoint for your page](https://docs.widgetic.com/docs/partners/editor-sessions.md#a-server-endpoint-for-your-page)). It returns `{ token, expiresAt }`.

### Options

| Option | Type | |
| - | - | - |
| `container` | element or CSS selector | **Required.** Where the piece is drawn. |
| `getToken` | `({ reason }) => Promise<string \| { token, expiresAt }>` | Required to show the customer's Widgetic data. Not needed for the File Browser with your own `mediaLibrary`. See [Tokens](#tokens). |
| `version` | `string` | Pin an exact version of the piece, such as `0.1.0`. Default: the newest. Pin it in production, and read [what changed](https://docs.widgetic.com/docs/partners/module-versions.md) before you move. |
| `theme` | `'light'`, `'dark'`, `'system'`, or `{ preset, mode, colors, radius, font }` | Default `light`. `system` follows the customer's setting. An object gives the piece your colours, corner radius and font. See [Make the pieces look like your product](#make-the-pieces-look-like-your-product). |
| `locale` | `string` | A BCP 47 tag such as `en` or `de`. Every piece uses it for plural forms and for how numbers, dates and file sizes are written, and for the `lang` of its elements. For 65 languages it also brings the words (every piece but the Embed Editor, which has none yet), and a language written right to left turns each piece around. See [Show the pieces in the language of your customers](#show-the-pieces-in-the-language-of-your-customers). |
| `messages` | `{ [key]: string }` | The words you want to change, in the File Browser, the Composition Editor, the Embed Editor, the Widget Creator and Workflows. They win over the built-in words of the `locale`, and a key you leave out keeps those words (English when the `locale` has none). See [Show the pieces in the language of your customers](#show-the-pieces-in-the-language-of-your-customers). |
| `apiUrl` | `string` | The Widgetic API. Default `https://api.widgetic.com`. |
| `moduleBaseUrl` | `string` | Where pieces are served from. Default `https://cdn.widgetic.com/modules`. See [Versions and self-hosting](#versions-and-self-hosting). |
| `on` | `{ [event]: handler }` | Event handlers, connected before the piece starts so you see `ready`. |
| `signal` | `AbortSignal` | Cancels the mount, for components that can go away before the piece is up. |
| `placeholder` | `boolean` | `false` skips the loading spinner shown while the piece downloads. |
| anything else | | Handed to the piece: its own options, which are on its page ([File Browser](https://docs.widgetic.com/docs/partners/ui-components/file-browser.md), [Composition Editor](https://docs.widgetic.com/docs/partners/ui-components/composition-editor.md), [Embed Editor](https://docs.widgetic.com/docs/partners/ui-components/embed-editor.md), [Widget Creator](https://docs.widgetic.com/docs/partners/ui-components/widget-creator.md), [Workflows](https://docs.widgetic.com/docs/partners/ui-components/workflows.md)). |

`mountModule` resolves with a handle once the piece is on screen:

```typescript theme={"theme":"css-variables"}
{
  id: string; type: string; version: string;     // version is the one that was actually loaded
  container: HTMLElement;
  module: UIModule;                              // the piece itself, for its own methods
  on(event, handler): () => void;                // returns a function that unsubscribes
  off(event, handler): void;
  setTheme(theme): void;                         // this piece's look alone
  setLanguage({ locale?, messages? }): void;     // this piece's language alone
  unmount(): Promise<void>;                      // takes the piece and its listeners down
}
```

### Events

| Event | Payload | |
| - | - | - |
| `ready` | | The piece is on screen. |
| `error` | `{ message, code?, fatal }` | `fatal: true`: the piece has stopped. `false`: it carries on, for example after a failed token refresh that will be retried. |

Every piece adds events of its own, and some say more in `ready` and `error`: `select` for the [File Browser](https://docs.widgetic.com/docs/partners/ui-components/file-browser.md#events), `dirty` and `saved` for the [Composition Editor](https://docs.widgetic.com/docs/partners/ui-components/composition-editor.md#events) and the [Embed Editor](https://docs.widgetic.com/docs/partners/ui-components/embed-editor.md#events), `canvasChanged`, `widgetPublished` and `limitReached` for the [Widget Creator](https://docs.widgetic.com/docs/partners/ui-components/widget-creator.md#events-and-methods), `openWorkflow` and `showEmbedCode` for [Workflows](https://docs.widgetic.com/docs/partners/ui-components/workflows.md#mount-the-screen). They are on the page of each piece.

### Several pieces on one page

`mountModule` creates a `WidgeticUI`, mounts one piece with it and destroys it again when you `unmount()`. To mount several pieces, or to download one ahead of time, make the `WidgeticUI` yourself:

```javascript theme={"theme":"css-variables"}
import { WidgeticUI } from '@widgetic/ui-sdk';

const ui = new WidgeticUI({ getToken, theme: 'system' });      // touches nothing until you mount
await ui.preload('widget-creator');                            // optional: download it ahead of time
const files = await ui.mount('file-browser', { container: '#files' });

ui.updateTheme('dark');                                        // every mounted piece, and later ones (colours, radius and font stay)
await files.unmount();
await ui.destroy();                                            // unmounts whatever is left
```

## Make the pieces look like your product

A piece can wear your colours, the roundness of your corners and your typeface. The components and the layout stay Widgetic's: only the look follows your design system. The words can follow your language too (see [below](#show-the-pieces-in-the-language-of-your-customers)). Each piece has a theme of its own, so the pieces can look the same or different.

```javascript theme={"theme":"css-variables"}
const ui = new WidgeticUI({
  getToken,
  // The look of every piece of this page
  theme: {
    preset: 'ocean',
    radius: 'medium',
    font: { family: 'Poppins', stylesheetUrl: 'https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap' },
  },
});

const files = await ui.mount('file-browser', { container: '#files' });   // takes the page's look
const editor = await ui.mount('composition-editor', {
  container: '#editor',
  compositionId,
  theme: { preset: 'violet', mode: 'dark', colors: { primary: '#e0541b' } },   // a look of its own
});

ui.updateTheme('dark');                 // the mode of every piece; each keeps its colours, radius and font
ui.updateTheme({ preset: 'sunset' });   // new page-wide settings, for the pieces that have none of their own
editor.setTheme({ radius: 'none' });    // one piece alone
```

### The settings

| Setting | |
| - | - |
| `preset` | A built-in look to start from: `'widgetic'` (the default), `'graphite'`, `'ocean'`, `'violet'` or `'sunset'`. Each has a light and a dark look. A preset sets colours only. |
| `mode` | `'light'` or `'dark'`. On the `WidgeticUI` you can also write `'system'`, which follows the customer's own setting. |
| `colors` | Any of `primary`, `primaryForeground` (the text on the primary colour), `background`, `foreground` (the text), `muted` (quiet surfaces), `mutedForeground` (secondary text), `border`, `accent` (the soft highlight) and `destructive` (errors). Name only the ones you want to decide: the rest follows from them. A `primary` on its own changes the brand colours and leaves the greys alone. |
| `radius` | `'none'` (square), `'small'` (4 px), `'medium'` (8 px) or `'large'` (12 px), or a number of pixels from 0 to 32. Without it the corners are as they were. |
| `font` | `{ family, stylesheetUrl? }`. `family` is a CSS font-family value: one name gets system fonts behind it, a list is used as written. It applies to the piece's text, not to your page. |

| Preset | Brand colour, light | Brand colour, dark | |
| - | - | - | - |
| `widgetic` | Deep forest green (unchanged) | A lighter green on near-black | The Widgetic look. |
| `graphite` | `#1f2328` | `#6b7683` | Neutral and quiet. The content carries the colour. |
| `ocean` | `#0b69c7` | `#3b82f0` | Clear blue. |
| `violet` | `#6d3fd9` | `#8b5cf6` | A saturated purple. |
| `sunset` | `#e0541b` | `#e8602a` | Warm orange. |

Your own `colors` win over the preset's. A `primary` of yours without a `primaryForeground` gets the white or the dark ink that reads better on it.

### Writing a colour

`#rrggbb`, `#rgb`, `rgb(11 107 203)` and `hsl(210 90% 41%)` always work. A colour name or `oklch()` works in a browser that understands it. `var(--brand)` and `currentColor` are refused: the piece reads the colour when you give it and cannot look at your page's variables from there, so read the value in your page and pass it in. Transparency is ignored. The piece warns in the console about a combination that is hard to read: your text under 4.5:1 against your background, or your primary colour (or the text on it) under 3:1.

### A font your page does not load yet

A font can only be defined by the page itself, never from inside a piece. Give the `https` address of its stylesheet as `stylesheetUrl` and the piece adds one `<link rel="stylesheet" data-widgetic-ui-font>` to your `<head>`, once however many pieces use it. It stays after `unmount()`, like the font rules every piece adds. A font your page already loads needs no `stylesheetUrl`. Under a strict Content-Security-Policy, `style-src` has to allow the stylesheet's host and `font-src` the font files (for Google Fonts, `https://fonts.googleapis.com` and `https://fonts.gstatic.com`).

### Changing a look later

* A bare mode (`'dark'`, `{ mode: 'dark' }`) changes the mode and keeps the rest of the look. Settings replace the whole look.
* Settings given in a mount call, or to `setTheme` on a piece, are that piece's own. `ui.updateTheme(settings)` does not take them away, and a page that changes a preset does not turn a dark piece light. A call that names a mode reaches every piece.
* `ui.getTheme()` tells you the page's mode and settings. `'system'` stays `'system'`.
* A theme that cannot be used is refused with the code `INVALID_THEME`. The message names the setting and what to write instead, and nothing changes. When only the piece can tell (an unknown preset name, a colour it cannot read), `ui.updateTheme` reports it in the console and the piece keeps its look, while `setTheme` and a mount call throw (the mount fails with `MOUNT_FAILED` and leaves its container empty).

### What a theme cannot do yet

* **The Widget Creator takes a theme's mode, neutral colours, brand colour and font, but not yet its corners.** A dark `mode`, or colours of your own for `background`, `foreground`, `muted`, `mutedForeground` and `border`, restyle its panels, toolbar, menus, dialogs and chat, and the `font` applies to all of its text. Every text of it stays readable in a dark look, for each built-in preset and for neutral colours of your own. Your `primary` colour is the creator's accent: the selected tool, the sliders, the buttons that act, the chat's Send button and what is on them, darker under the pointer (lighter on a dark surface). The text and icons on an accent are your `primaryForeground` when you give one, else white or a dark ink, whichever reads on your colour, so a light yellow gets dark text. Without a `primary` the accents are Widgetic's own green and blue. The canvas board and the live widget previews stay light on purpose (they show the widget as your customers will see it), and the chat's message bubbles keep their own light colours. The handles the canvas draws on its board, a few accents the creator sets in script and the colours of a status (the green of a published widget, the red of an error) do not take your brand colour, and most of its corners are Widgetic's own, so `radius` changes very little of it. The console says what stays light when a creator gets a dark theme. The File Browser and the Composition Editor follow a dark theme.
* **No layout or icons.** The components are Widgetic's. The words of the File Browser, the Composition Editor, the Embed Editor, the Widget Creator and Workflows can be changed (see the next section).
* **Colours the piece can read as they are.** No CSS variables, gradients or images.

## Show the pieces in the language of your customers

The File Browser, the Composition Editor, the Embed Editor, the Widget Creator and Workflows speak your customers' language. 65 languages come with the File Browser, the Composition Editor, the Widget Creator and Workflows, so `locale: 'pl'` is enough to get their words in Polish. For a language that is not among them, and for the Embed Editor, which has no built-in words yet, you hand over the words yourself. Every word a piece shows is a message with a key. You hand over the words you want to say differently, and every key you leave out keeps the built-in words of the `locale` (English when it has none), so you can also add a language one screen at a time. The examples are the File Browser's; [The Composition Editor](#the-composition-editor), [The Embed Editor](#the-embed-editor), [The Widget Creator](#the-widget-creator) and [The Workflows screen](#the-workflows-screen) say what is different.

```javascript theme={"theme":"css-variables"}
const fileBrowser = await mountModule('file-browser', {
  container: document.querySelector('#media-library'),
  getToken,
  locale: 'pl', // the built-in Polish words, plural forms, numbers, dates and file sizes
  messages: {
    // only what you want to say differently from the built-in words
    'action.cancel': 'Anuluj',
    'action.addToEditor': 'Wybierz', // the button that hands the pick to your page
    'toolbar.deleteMany': '{count, plural, one {Usuń # plik} few {Usuń # pliki} many {Usuń # plików} other {Usuń # pliku}}',
  },
});

// later, while the piece is on screen, without mounting it again (the built-in German words, and yours over them):
fileBrowser.setLanguage({ locale: 'de', messages: germanMessages });
```

| Setting | |
| - | - |
| `locale` | A BCP 47 tag (`de`, `pt-BR`). It decides the plural forms and how numbers, dates ("2 days ago") and file sizes are written. For the 65 languages the pieces ship it also brings the words (see [Languages that come with the pieces](#languages-that-come-with-the-pieces)); for any other it translates nothing. Blank or left out is English. It is also the `lang` of the piece's elements, so a screen reader says the words in that language, and a language written right to left (`ar`, `he`, `fa`, `ur` and others) turns the whole screen of a piece around: see [Right to left](#right-to-left). `new WidgeticUI({ locale })` hands it to every piece of the page. |
| `messages` | The words you want to change, as `{ 'action.cancel': 'Anuluj', ... }`. They win over the built-in words of the `locale`. |
| `selectLabel` | The text of the button that hands the pick to your page, for a page that only wants to rename that button (default `Select`). `messages['action.addToEditor']` does the same and wins when both are given. |
| `setLanguage({ locale?, messages? })` | Changes the language at once, with no new mount. A value you leave out keeps what it was. The `messages` you give **replace** all the earlier ones: a page that switches from German to French passes the French only, and `setLanguage({ locale: '', messages: {} })` goes back to English. |

### Languages that come with the pieces

65 languages are built in, for the File Browser, the Composition Editor, the Widget Creator and Workflows. When your `locale` is one of them, or a regional form of one, the piece downloads that language's words as one small file from the same folder of the CDN as the piece itself, and its first paint is already in that language. Any other `locale` (`en`, `af`, a tag nobody wrote words for) downloads nothing and the words stay English: plural forms, dates and direction still follow `locale`. The Embed Editor has no built-in words yet, so its words stay English whatever the `locale` is, unless your `messages` say otherwise.

> [accordion] The 65 languages
>
> | Language | `locale` |
> | - | - |
> | Albanian | `sq` |
> | Arabic (written right to left) | `ar` |
> | Armenian | `hy` |
> | Basque | `eu` |
> | Bengali | `bn` |
> | Bosnian | `bs` |
> | Brazilian Portuguese | `pt-BR` |
> | Bulgarian | `bg` |
> | Canadian French | `fr-CA` |
> | Catalan | `ca` |
> | Chinese, Simplified | `zh-CN` |
> | Chinese, Traditional (Hong Kong) | `zh-HK` |
> | Chinese, Traditional (Taiwan) | `zh-TW` |
> | Croatian | `hr` |
> | Czech | `cs` |
> | Danish | `da` |
> | Dutch | `nl` |
> | Estonian | `et` |
> | European Portuguese | `pt-PT` |
> | European Spanish | `es-ES` |
> | Filipino | `fil` |
> | Finnish | `fi` |
> | French | `fr` |
> | Galician | `gl` |
> | Georgian | `ka` |
> | German | `de` |
> | Greek | `el` |
> | Gujarati | `gu` |
> | Hebrew (written right to left) | `he` |
> | Hindi | `hi` |
> | Hungarian | `hu` |
> | Indonesian | `id` |
> | Irish | `ga` |
> | Italian | `it` |
> | Japanese | `ja` |
> | Kannada | `kn` |
> | Korean | `ko` |
> | Latin American Spanish | `es-419` |
> | Latvian | `lv` |
> | Lithuanian | `lt` |
> | Malay | `ms` |
> | Malayalam | `ml` |
> | Maltese | `mt` |
> | Marathi | `mr` |
> | Montenegrin | `cnr` |
> | Norwegian | `no` |
> | Occitan | `oc` |
> | Persian (written right to left) | `fa` |
> | Polish | `pl` |
> | Punjabi | `pa` |
> | Romanian | `ro` |
> | Russian | `ru` |
> | Serbian (Latin script) | `sr-Latn` |
> | Slovak | `sk` |
> | Slovenian | `sl` |
> | Spanish | `es` |
> | Swahili | `sw` |
> | Swedish | `sv` |
> | Tamil | `ta` |
> | Telugu | `te` |
> | Thai | `th` |
> | Turkish | `tr` |
> | Ukrainian | `uk` |
> | Urdu (written right to left) | `ur` |
> | Vietnamese | `vi` |

You do not have to pass one of these tags exactly. The piece reads the closest language it has, so the language of a visitor's browser can go straight into `locale`:

| You pass | The piece reads |
| - | - |
| `pt` | Brazilian Portuguese (`pt-BR`) |
| `pt-PT`, `pt-AO` | European Portuguese (`pt-PT`) |
| `fr`, `fr-FR`, `fr-BE`, `fr-CH` | French (`fr`) |
| `fr-CA` | Canadian French (`fr-CA`) |
| `es`, and a Spanish-speaking region with no words of its own (`es-GQ`) | Spanish (`es`) |
| `es-ES` | European Spanish (`es-ES`) |
| `es-MX`, `es-AR`, `es-US`, `es-419` | Latin American Spanish (`es-419`) |
| `zh`, `zh-Hans`, `zh-SG` | Simplified Chinese (`zh-CN`) |
| `zh-TW`, `zh-Hant` | Traditional Chinese for Taiwan (`zh-TW`) |
| `zh-HK`, `zh-MO`, `yue` | Traditional Chinese for Hong Kong (`zh-HK`); Simplified is never used for them |
| `nb`, `nn` | Norwegian (`no`) |
| `sr`, `sr-Cyrl` | Serbian (`sr-Latn`): the one Serbian set of words is written in Latin script |
| `ar-EG`, `ar-SA`, `he-IL`, `iw`, `fa-IR`, `ur-PK` | Arabic (`ar`), Hebrew (`he`; `iw` is its old tag), Persian (`fa`), Urdu (`ur`) |
| `in`, `tl` | Indonesian (`id`), Filipino (`fil`) |
| `de-AT`, `nl-BE`, `ro-MD` and the other regions of a language in the list | that language (the rows above are the exceptions) |
| `en`, `en-GB`, `af`, a tag nobody wrote words for | no words are downloaded: English |

* **Your `messages` win.** The built-in words come first and yours replace them, key by key.
* **They are provisional.** The built-in words are machine translations that no native speaker has read yet. `module.localePackStatus('de')` says `'provisional'` (it says `'reviewed'` for a language a native speaker has read, and `null` for a tag with no words), and `module.supportedLocales` lists the 65 tags. Tell [the support team](https://docs.widgetic.com/docs/introduction.md#need-help) about a word that is wrong, with the piece, the `locale` and the message key.
* **How a number or a date is written comes from the browser.** The words come with the piece, but the browser knows how a language writes numbers, dates and file sizes and which plural forms it has. A browser that has no data for a language writes them the English way, chooses only "one" and "other" for a plural, and the piece says so once in the console; the words are still the language's. Chrome 158 has no data for Irish, Maltese, Albanian, Georgian, Armenian, Galician, Basque and Occitan; Safari and Firefox have not been checked.
* **A file that cannot be downloaded** is said once in the console, and the piece goes on in English.

### Which keys there are

`fileBrowser.module.defaultMessages` is an object of every key and its English text: a few hundred messages, grouped by where the words appear (`action.`, `upload.`, `dialog.`, `preview.` and so on). It always matches the version of the piece you load, and it is the list to hand to a translator.

```javascript theme={"theme":"css-variables"}
console.log(JSON.stringify(fileBrowser.module.defaultMessages, null, 2));
```

### Writing a message

A message is text. `{name}` is a value the File Browser puts in; a number is written the way the locale writes numbers. `{count, plural, one {# file} other {# files}}` picks the form that fits the number in your customer's language: `other` is required, `=0 {none}` matches exactly 0, `#` is the number, and a language with more forms says so (Polish has `one`, `few`, `many` and `other`). `\{`, `\}`, `\#` and `\\` write the character itself. A translation keeps the `{names}` of the English message, in any order, and cannot ask for a value the message is never given.

### Checking your words

`fileBrowser.module.checkMessages(messages)` says what is wrong without showing anything: one sentence for each key that does not exist (with the nearest real one), value that is not text, message that does not parse, or `{name}` the message is never given. An empty list means every message will be used. Put it in a test of your page.

A message that cannot be used never breaks the screen: the English text of that key is shown and the console says so once. A value of the wrong shape (`messages: 'Anuluj'`, `locale: 5`) is a mistake in your code and is refused where you wrote it: `setLanguage` throws a `TypeError` that names the option and changes nothing, and a mount call fails with `MOUNT_FAILED` and the `TypeError` as its `cause`.

### Pop-ups

The File Browser answers a rename, a delete, a new folder and a pick with a small pop-up in the bottom corner of the box you gave it (the right one, or the left one for a language written right to left), in the piece's theme and in your language. Their words are messages like the rest: the `toast.` keys, with `toast.regionLabel` (the name of the region a screen reader announces them in) and `toast.closeLabel` (the name of the close button). After a pick the piece says "Files selected", not the Widgetic site's "Added 2 files to the editor". The sentence under "Rename failed" or "Failed to delete" is your library's own and is shown as it arrives.

Two habits come with the pop-up library. It moves focus to the newest pop-up when someone presses Alt+T anywhere on the page while one is shown, and a pop-up goes away by itself after about three seconds. You cannot move the pop-ups or switch them off yet.

### The Composition Editor

The Composition Editor takes the same `locale`, `messages` and `setLanguage`, and its `module.defaultMessages` and `module.checkMessages(messages)` work as above. One thing is different: **one `messages` object covers the whole editor.** The editor is made of three parts with words of their own, and it splits what you give between them, so you never need to know which part says a word:

* the editor's own words, the `editor.` keys: the Design and Content tabs, every control, the save button, the dates and the failures it explains;
* the file picker that opens from its file fields, which is the File Browser: the keys above (`action.`, `upload.`, `dialog.` and so on), with the same `locale` and `messages`;
* the rich text editor of its text fields, the `shadEditor.` keys. The editor draws its own text toolbar, so these words are not on screen today and a translation can leave them out.

`editor.module.defaultMessages` lists them all, with their English text: more than 500. A key that is in none of the three is said once in the console as `[Editor] ...`, with the nearest real key, and ignored.

```javascript theme={"theme":"css-variables"}
const editor = await mountModule('composition-editor', {
  container: document.querySelector('#editor'),
  compositionId,
  getToken,
  locale: 'de',
  messages: {
    'editor.props.save': 'Speichern', // a word of the editor
    'action.cancel': 'Abbrechen', // a word of its file picker
  },
});

// labels and buttons change at once, and what the customer typed stays
editor.setLanguage({ locale: 'pl', messages: polishMessages });
```

* **Dates follow `locale` without your help.** The names of the months and weekdays in its calendars, and the way a date is written, come from the browser. Only the names of the calendars and of their buttons (what a screen reader says) are messages. The date range control shows dates the way the language writes them: 7 October 2026 reads `10/07/26` with `en` (and with no `locale`), `07/10/26` with `en-GB`, `07.10.26` with `de` and `pl`, and `26/10/07` with `ja`, so give `en-GB` when you want the day first in English. A weekday heading in a calendar is the language's own short name, not cut to two letters. In a language written right to left it is the one-letter name instead (Arabic `ح ن ث ر خ ج س`), because the short names of Arabic are whole words that do not fit a column, and the whole name is the label of the heading for a screen reader. Where the browser has no one-letter names for a language (Urdu), the short names stay. Values saved in the composition stay structured dates, the same in every language.
* **A change of language reaches what is on screen.** Labels and buttons change at once, and so do the banners of a composition that could not be opened and of a save that failed. A sentence the editor said once, such as why there is no preview, keeps its language until the editor says something new.
* **Pop-ups from its file picker.** A rename, a delete, a new folder and a pick raise a small pop-up inside the module's box, in your language (`toast.` keys, including `toast.regionLabel` and `toast.closeLabel`). After a pick the module says "Files selected", not "Added … to the editor".

### The Embed Editor

The Embed Editor takes the same `locale`, `messages` and `setLanguage`, and its `module.defaultMessages` and `module.checkMessages(messages)` work as above. **One `messages` object covers the whole editor**: its own words (the `editor.embed.` keys: the code box, the copy button, the status line, the banners of a failed load or save), the assistant's (`editor.embedAssistant.`) and the words of the controls the options are made of (the other `editor.` keys). It speaks from the same catalog as the Composition Editor, so a page that translated the Composition Editor's words has translated these too. `embed.module.defaultMessages` lists them all, with their English text. A key that is in none of them is said once in the console as `[Editor] ...`, with the nearest real key, and ignored.

```javascript theme={"theme":"css-variables"}
const embed = await mountModule('embed-editor', {
  container: document.querySelector('#embed'),
  compositionId,
  getToken,
  locale: 'de',
  messages: {
    'editor.embed.copy': 'In die Zwischenablage kopieren', // the button that copies the code
    'editor.embedAssistant.composerPlaceholder': 'Beschreibe, wie es erscheinen soll', // the assistant's text box
  },
});

// labels and buttons change at once, and what the customer typed stays
embed.setLanguage({ locale: 'pl', messages: polishMessages });
```

* **There are no built-in languages yet.** `locale` decides the plural forms, how numbers and dates are written and which way the screen reads, and the words stay English unless your `messages` say otherwise.
* **The options keep their English names.** The name of each option, its group, its hint and the choices of its menus come from the widget's embed options, not from the editor, so `messages` does not reach them. The assistant answers in the language the customer writes in.
* **The embed code is read left to right in every language**, and the editor's own `error` events keep their English `message` (use `code`).

### The Widget Creator

The Widget Creator takes the same `locale`, `messages` and `setLanguage`, and its `module.defaultMessages` and `module.checkMessages(messages)` work as above. Like the Composition Editor, **one `messages` object covers the whole creator.** It is made of parts with words of their own, and it splits what you give between them, so you never need to know which part says a word:

* the creator's own words, the `creator.` keys: the widget's panel, publishing and versions, the chat's generation options (the language and, in debug mode, custom libraries), the limits it explains, the lines of its status bar; the preset **Libraries** toggle and its add-library control appear only in creator debug mode, which the Widget Creator module does not turn on, but their messages stay in the catalog for hosts that do;
* the chat's words (`chat.` keys) and the canvas's (`canvas.` keys: the toolbar, the zoom controls, the context menu, the properties panel, the words the shapes draw on the canvas);
* the two words of the region its pop-ups are announced in, `toast.regionLabel` and `toast.closeLabel`, which are the File Browser's keys of the same names, so one translation serves both;
* the Composition Editor with its file picker and its rich text editor (the `editor.` keys, the File Browser's and `shadEditor.`). The creator's composition steps are off in a session, so these are on no screen today and a translation can leave them out.

`creator.module.defaultMessages` lists them all, with their English text: more than 1,300.

```javascript theme={"theme":"css-variables"}
const creator = await mountModule('widget-creator', {
  container: document.querySelector('#creator'),
  getToken,
  locale: 'pl',
  messages: {
    'canvas.tool.select': 'Zaznacz', // a word of the canvas
    'chat.input.placeholder': 'Wpisz wiadomość...', // a word of the chat
    'creator.common.setLive': 'Ustaw jako aktywną', // a word of the creator
  },
});

// everything that is open changes at once, and what the customer made stays
creator.setLanguage({ locale: 'de', messages: germanMessages });
```

* **Dates follow `locale` without your help.** The date and time of a version are written the way the language writes them (`10/01/2026 14:05` in English, `01.10.2026 14:05` in Polish, `2026/10/01 14:05` in Japanese). Only the words around them are messages.
* **A change of language reaches what is on screen.** The canvas, the chat, the panels, the menus and the pop-ups change at once, with no new mount. As for the other pieces, `setLanguage` keeps what you leave out and replaces the messages.
* **A mistake never breaks the screen.** A key that none of the parts has is said once in the console as `[Creator] ...`, with the nearest real key. A text that cannot be used is said once by the part that owns the key (`[Creator]`, `[Chat]`, `[Canvas]`, `[Editor]`, `[FileBrowser]`, `[ShadEditor]`, or `[WidgetCreatorModule]` for the pop-up region), and the English text of that message is shown.

### The Workflows screen

Workflows takes the same `locale`, `messages` and `setLanguage`, and its `module.defaultMessages` and `module.checkMessages(messages)` work as above. It has **one** `messages` object for all of it: a few hundred messages whose keys start with `workflows.`, for the list, the editor and its panels, the names of blocks, operators and units, what is wrong with a workflow that cannot be published, what a failed request means, and the words of the screen that says a part could not be drawn. The words of a block are made of parts the screen puts together (`{field} {value}`, `{count, plural, ...}`), so a language that puts them in another order can say so in its own message. All 65 [built-in languages](#languages-that-come-with-the-pieces) come with these words. A key you leave out keeps them (English when your `locale` has none).

### Right to left

The File Browser, the Composition Editor, the Embed Editor, the Widget Creator and Workflows are read the way your customer's language is written. For Arabic, Hebrew, Persian, Urdu and the other languages written from right to left, the whole screen turns around and a line starts on the right. `setLanguage({ locale: 'ar' })` turns a piece that is on screen around, and `setLanguage({ locale: 'de' })` turns it back, with no new mount.

```javascript theme={"theme":"css-variables"}
const fileBrowser = await ui.mount('file-browser', { container: '#media', getToken, locale: 'ar' }); // read right to left from the first paint
```

* **The File Browser.** The list starts on the right, the search box, the sort and filter controls, the selection bar, the upload panel and the windows are laid out from the right, the close button of a window is in the corner where a line starts, menus open toward the end of the line, the pop-ups come up in the bottom left corner, and the arrows that mean back and forward are mirrored. In the preview, the arrow key that points toward the end of the line goes on to the next file.
* **The Composition Editor.** The settings panel is docked at the start of the line, on the right, and the preview on the other side, the same distance from the middle as in English. The Design and Content tabs run from the start of the line, the label of a control is at the start of its row, the calendars start their week at the start of the line, and sliders and switches run from the start. The file picker that opens from a file field is the File Browser above.
* **The Embed Editor.** With the assistant on (the default), the options panel is docked at the start of the line, on the right, and the assistant's column on the other side; with `assistant: false` only the options panel is shown. The label of an option is at the start of its row, and menus open toward the end of the line. **The embed code is the exception**: it is code, so it is read from left to right in every language, and a right to left screen keeps the `<` of its first tag at the left.
* **The Widget Creator.** The tools of the toolbar run from the start of the line, the properties panel is docked at the end of it, the menus, the list of shapes and the publish history are laid out from the start. The Composition Editor and the File Browser inside it are turned around the same way.
* **Workflows.** The list, the top bar of the editor, the tabs, the side panel, the menus and the dialogs are laid out from the start of the line, as a whole. **The canvas is the exception**: a workflow is read from its first block forward, so it is drawn from left to right in every language, and its lines run from a block on the left to the next one on its right.
* **What a customer types.** A text field, the tags of the editor, the chat and the text fields of the quick edit are read by their own first letter: a sentence in Latin letters is set from the left and one in Arabic from the right, side by side. A field with nothing in it yet takes the direction of the screen. An email, a link and a colour code stay left to right on every screen.
* **Only `locale` decides.** The direction of your page does not: a page written right to left (`<html dir="rtl">`) leaves an English piece alone, and a page written left to right does not stop an Arabic one. Changing `messages` alone changes nothing about it.
* **Names.** File and folder names are read by their own first letter, so a Latin name next to Arabic ones is not put in the wrong order. In a language written right to left, a name inside a sentence ("Failed to delete 2024 report.pdf") sits between two invisible marks (Unicode isolates U+2068 and U+2069), so the words around it cannot turn it around. A screen reader does not say them; leave them out when a test compares the text of a pop-up.
* **The video time line** stays left to right, because time runs that way in every language.
* **Drawings stay left to right.** The drawing board of the Widget Creator, the live previews of widgets and the code are left to right in every language, and so are the drawings that mean "left" and "right" in the Composition Editor (the saturation and hue of the colour picker, the grid that places a box, the corners of a rounded box). A drawing is not a line of text, and a widget's own preview must look the way its author made it.
* **Two small things are open.** The weekday names of an Urdu calendar are the short ones, which are whole words because the browser has no one-letter names for Urdu, so that row is tight. And the panel of a widget in the creator opens on the side of its shape that has more room, as it does in English, without knowing where the properties panel is: for a shape near the middle of the board it can open over that panel.

### What stays as it is

* **Words that belong to someone else.** What your own media library says (the message of an error you throw), your file names and your library's `label`, the names of folders a customer made, and a sentence Widgetic's API sends back are shown as they arrive.
* **`error` events.** Their `message` is English: it is for your logs.
* **What is saved with a composition.** The title of a new item ("Item 03"), "Untitled Composition" and the names a font weight or a position is saved under ("ExtraBold", "top-left") are written into the composition when they are made, so they stay English. The editor shows the weights and the positions in your language.
* **The widget author's words.** The names, labels, descriptions and placeholders of a widget's settings, its default texts and the names of typefaces are shown as the author wrote them.
* **Your customers' words in Workflows.** The names of workflows and of compositions, the event names a customer types into a trigger, and the names of the tables, columns and actions of a widget are shown as they were written.
* **What the customer and the AI write.** The prompts, the answers, the names of widgets and the code are the customer's and the AI's. In the Widget Creator, lines the creator saved into the chat stay English in the API; on screen it translates known lines (a failed generation, a restore) at display time. The `message` of its `limitReached` event stays English (use `code`).
* **What a session never draws.** The Widget Creator's sign-in screen, its standalone header, its debug panels, the preset **Libraries** section of the chat's generation options, its list of keyboard shortcuts and its composition steps are not shown in a session, so they are not translated.

## Tokens

`getToken` is the only credential the SDK takes. It is called with `{ reason }`:

* `'initial'`: the piece is starting.
* `'expiring'`: the current token runs out in about a minute. Return its replacement now.
* `'expired'`: the current token has already run out (the page was asleep, or an earlier refresh failed).

Return the token itself, or `{ token, expiresAt }` (an ISO string, epoch milliseconds or a `Date`). With `expiresAt` the piece renews the token in time and the customer is never interrupted. The answer of your own endpoint can pass on what Widgetic gave you.

When your `getToken` answers an `'expired'` call with the very token the API had refused, the piece takes it that you have no better one. It does not ask again for five seconds, whatever asks, so a session that was ended is reported once and not once per request.

An `apiKey` option is refused with `API_KEY_NOT_ALLOWED`. The key must stay on your server.

Every piece asks for its token in this way: it is always the token of the editor session of the customer who is on the page.

## Content Security Policy

If your page sends a Content-Security-Policy, the File Browser works with this and nothing more. The build tests load it under the same policy, list, pick and upload images and preview a PDF; each source below is needed.

```text theme={"theme":"css-variables"}
default-src 'none';
script-src  'self' https://cdn.widgetic.com;           # plus whatever your own page needs
connect-src https://cdn.widgetic.com https://api.widgetic.com;
style-src   'unsafe-inline';                           # the piece's styles are <style> elements in its shadow root
font-src    data:;                                     # its fonts are embedded
img-src     https://cdn.widgetic.com data: blob:;      # data: for its icons, blob: for an upload's preview
worker-src  blob:;                                     # only to preview a PDF: pdf.js reads it in a worker made from a blob
```

`img-src` also needs the address your customers' files are served from (the `url` of a picked file). To preview a PDF, that address also goes in `connect-src` (the PDF is downloaded with a request, so the file server has to allow your page's origin with CORS) and the policy needs the `worker-src blob:` above; without it the preview says "Failed to load PDF" and everything else works. No `data:` in `script-src` and no `'unsafe-eval'` are needed. The PDF viewer is downloaded when the first PDF is previewed, from the same folder of the CDN as the piece itself, so `script-src` needs nothing more.

* The **Composition Editor** works under the same policy plus `frame-src https://cdn.widgetic.com` (the live preview is the widget's published page). Its font picker also needs `style-src https://fonts.googleapis.com` and `font-src https://fonts.gstatic.com`.
* A **font of your own** (`theme.font.stylesheetUrl`) needs its stylesheet's host in `style-src` and its font files' host in `font-src`. See [A font your page does not load yet](#a-font-your-page-does-not-load-yet).
* The **Widget Creator** needs what the Composition Editor needs plus `frame-src https://wbuilder.widgetic.com` and `connect-src https://wbuilder.widgetic.com` (the live previews of widgets are served from there).
* **Workflows** needs less than the File Browser: `script-src`, `style-src 'unsafe-inline'` and `font-src data:`, plus two sources of its own. `connect-src` has to allow the API (your `apiUrl`, `https://api.widgetic.com` unless you run your own), and `img-src https://cdn.widgetic.com` is for the pictures of compositions in the list and on the canvas. It needs no `frame-src`, no `worker-src`, no inline script and no `eval`. Together: `default-src 'none'; script-src 'self' https://cdn.widgetic.com; connect-src https://cdn.widgetic.com https://api.widgetic.com; style-src 'unsafe-inline'; font-src data:; img-src https://cdn.widgetic.com`. The `connect-src https://cdn.widgetic.com` is the SDK's request for the manifest, as for every piece, and it is not made when you pin a `version`.
* The **Embed Editor** needs the least: `script-src`, `style-src 'unsafe-inline'`, `font-src data:` and `connect-src` for the API (your `apiUrl`, `https://api.widgetic.com` unless you run your own), where the options are read and saved and where the assistant answers as a stream. It needs no `img-src`, no `frame-src`, no `worker-src`, no inline script and no `eval`. Together: `default-src 'none'; script-src 'self' https://cdn.widgetic.com; connect-src https://cdn.widgetic.com https://api.widgetic.com; style-src 'unsafe-inline'; font-src data:`. The `connect-src https://cdn.widgetic.com` is the SDK's request for the manifest, as for every piece, and it is not made when you pin a `version`. The Widgetic build tests open the editor under a policy with exactly these sources, edit and save the options and talk to the assistant under it, and fail on any violation.

You do not have to ask Widgetic for anything to allow your page (CORS): the API accepts a session token from any origin (see [Editor Sessions](https://docs.widgetic.com/docs/partners/editor-sessions.md#browsers)). Bind the session to your page with `allowedOrigin` instead.

## What the SDK puts on your page

* On import: nothing.
* While a piece downloads: one `div[data-widgetic-ui-loading]` in your container, removed when the piece is up.
* A mounted piece: one `<widgetic-ui-module>` element in your container, holding a shadow root. The pieces also add one `<style data-widgetic-ui-document-rules>` to `<head>` with `@font-face` rules for fonts named `Widgetic UI …`, so they cannot collide with yours. That `<style>` is shared by every piece on the page and never added twice, so it stays when a piece is unmounted. The Composition Editor also adds Google's stylesheet for each font the customer looks at in its font picker; those `<link>`s go when the editor is unmounted. Your own `<link>`s and `<meta>`s are never touched.
* Never: global CSS or CSS variables, changes to `<html>` or `<body>`, `postMessage`, or removing your own elements.

## React

```jsx theme={"theme":"css-variables"}
import { useEffect, useRef } from 'react';
import { mountModule } from '@widgetic/ui-sdk';

export function MediaLibrary({ getToken, onPick }) {
  const containerRef = useRef(null);
  const onPickRef = useRef(onPick);
  onPickRef.current = onPick;

  useEffect(() => {
    const controller = new AbortController();
    let mounted = null;

    mountModule('file-browser', {
      container: containerRef.current,
      getToken,
      signal: controller.signal,
      on: { select: ({ files }) => onPickRef.current(files) },
    }).then(
      (handle) => { mounted = handle; },
      (error) => { if (error.name !== 'AbortError') console.error(error); },
    );

    return () => {
      controller.abort();   // before the piece is running: it never appears
      mounted?.unmount();   // after: it is taken down
    };
  }, []); // StrictMode runs this twice; the first run is cancelled cleanly

  return <div ref={containerRef} style={{ height: 600 }} />;
}
```

The same component mounts the other pieces: give `mountModule` the piece's name (`'composition-editor'`, `'embed-editor'`, `'widget-creator'` or `'workflows'`) and its options. The Widgetic build tests run it in a React 18 page, with and without `<React.StrictMode>`, for all five pieces. The same pattern works in Vue and Svelte: mount in the component's mount hook with an `AbortController`, and abort and unmount when it goes away. Mounting needs a page, so start it from an effect or an event handler: calling `mountModule` while rendering on a server rejects with `NOT_IN_BROWSER`.

## Versions and self-hosting

Pieces are static files, so nothing can change under your feet when you pin a version:

```text theme={"theme":"css-variables"}
https://cdn.widgetic.com/modules/<name>/manifest.json            { "name": "file-browser", "version": "0.1.0", "entry": "0.1.0/index.js" }
https://cdn.widgetic.com/modules/<name>/changelog.json           what changed in each version, up to the one the manifest names, newest first
https://cdn.widgetic.com/modules/<name>/<version>/index.js       never changes once published
https://cdn.widgetic.com/modules/<name>/<version>/chunks/<file>.js    the parts a piece fetches later (the PDF viewer); never change either
```

* Without `version` the SDK reads the manifest and loads the newest version. With `version: '0.1.0'` it loads that file directly. **Pin the version in production** and upgrade when you have looked at the release.
* **Read what changed before you move.** Every version has an entry in the changelog, and a version that can break your page is marked `breaking`. See [Versions & Changelog](https://docs.widgetic.com/docs/partners/module-versions.md).
* To serve the pieces yourself, copy that layout to your own origin (the whole `<version>` folder: `index.js` fetches its `chunks/` files from the folder it was loaded from) and set `moduleBaseUrl`. The manifest's `entry` must be a `.js` file inside the piece's own folder on the same origin.
* Failed downloads are retried twice (network errors and server errors, not 404). A piece also asks twice more, the same way, when a file it fetches later fails. Requests to the CDN carry no cookies.

## Errors

Every error carries a `code`.

| Code | Meaning |
| - | - |
| `API_KEY_NOT_ALLOWED` | An `apiKey` option was given. Make an editor session on your server instead. |
| `INVALID_GET_TOKEN` | `getToken` was given but is not a function. |
| `NOT_IN_BROWSER` | Mounting on a server. |
| `MISSING_CONTAINER`, `CONTAINER_NOT_FOUND`, `INVALID_CONTAINER` | `container` is missing, matches nothing, or is not an element. |
| `INVALID_MODULE_NAME`, `INVALID_VERSION`, `INVALID_MODULE_BASE_URL` | The name, the pinned version or the module address is not valid. |
| `MODULE_NOT_FOUND` | The CDN has no such piece. |
| `MANIFEST_UNAVAILABLE`, `MANIFEST_INVALID` | The manifest could not be fetched, or it is not valid. |
| `MODULE_LOAD_FAILED`, `MODULE_INVALID` | The file could not be imported, or it does not export a piece. |
| `MOUNT_FAILED` | The piece loaded but failed to start. Nothing is left in the container. |
| `MOUNT_ABORTED` | The mount was cancelled through `signal`. |
| `INVALID_THEME` | A theme cannot be used: `updateTheme` was given something that is not a mode or settings, or a piece refused the settings (`setTheme`, a mount call). The message names the setting. |

## Next Steps

> [card] [Editor Sessions](https://docs.widgetic.com/docs/partners/editor-sessions.md)
>
> Make the token on your server

> [card] [Widget Creator](https://docs.widgetic.com/docs/partners/ui-components/widget-creator.md)
>
> The canvas and the agentic chat

> [card] [Composition Editor](https://docs.widgetic.com/docs/partners/ui-components/composition-editor.md)
>
> Change the texts, pictures and colours of a widget

> [card] [Workflows](https://docs.widgetic.com/docs/partners/ui-components/workflows.md)
>
> Let your customers chain compositions

> [card] [Managed Users](https://docs.widgetic.com/docs/partners/managed-users.md)
>
> File your customers' content under them

> [card] [Credits & Billing](https://docs.widgetic.com/docs/partners/credits-billing.md)
>
> How the AI is paid for


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.