Skip to main content

๐Ÿšง User Preferences

The SDK has no dedicated user-preferences store, but it does distinguish which scene settings are user-local and which belong to the document. Each viewport setting has a persistence scope (SettingScope):

  • export โ€” saved into the document (grid enabled, grid style, snap-to-grid).
  • browser โ€” kept locally only, e.g. in localStorage (pan, zoom, rotation).
  • ephemeral โ€” session only, never persisted (viewport size).
import { dehydrateScene, hydrateScene, VIEWPORT_SCOPE } from "@oh-just-another/scene";

VIEWPORT_SCOPE is the source of truth for these scopes. dehydrateScene prepares a scene for storage by resetting ephemeral settings to their defaults; hydrateScene layers saved data and host-supplied overrides back over the defaults. This is how you persist per-user viewport state (pan/zoom) separately from the shared document.

Several user-facing toggles live on the viewport and persist with it rather than in undo history โ€” for example show/hide grid and snap-to-grid, set via the editor.

Theme persistence exists only in the drop-in editor: <Editor persistTheme> (@oh-just-another/editor) stores the choice in localStorage (default key "diagram-theme", or pass a custom key string). @oh-just-another/react-ui itself does not persist a theme โ€” it exports light and dark palettes (ELEMENT_PALETTE_LIGHT / _DARK, CANVAS_PALETTE_LIGHT / _DARK) and resolvePaletteTheme; store the preference yourself when composing chrome directly.

Planned โ€” not yet available: a unified, namespaced user-preferences API (default tool, grid defaults, theme in one store) that the editor reads on startup. Today, assemble preferences from the scoped viewport settings above, persistTheme, and your own storage.