@molecule/app-settings-panel-svelte
Feature · settings-panel · App (browser) · v2.0.3 · Apache-2.0
Composable settings panel — a SettingsContainer + family of section sub-components (Account, Auth, Notifications, Billing, Devices, ThisDevice, LogOutDelete). Apps compose via the children snippet, picking which sections to include and what order.
npm install @molecule/app-settings-panel-svelteHow it works
@molecule/app-settings-panel-svelte is a ready-made settings-panel feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import {
AccountSection,
AppearanceSection,
AuthSection,
BillingSection,
DevicesSection,
LogOutDeleteSection,
NotificationsSection,
SettingsContainer,
ThisDeviceSection,
TiersUpgradeSection,
} from '@molecule/app-settings-panel-svelte'
// The sections read the app's services through the binding's hooks (see
// the wiring prereqs below).
let { onClose }: { onClose: () => void } = $props()
</script>
<SettingsContainer {onClose}>
<AccountSection />
<AppearanceSection />
<AuthSection />
<NotificationsSection />
<TiersUpgradeSection />
<DevicesSection />
<ThisDeviceSection />
<LogOutDeleteSection />
</SettingsContainer>Works with: @molecule/app-auth, @molecule/app-http, @molecule/app-push, @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte, @molecule/app-utilities
Reference
@molecule/app-settings-panel-svelte — the Svelte counterpart of
@molecule/app-settings-panel-react: composable, batteries-included
settings panel, with the same prop names, the same rendered DOM and the
same behavior for the same input.
<SettingsContainer onClose={…}> owns the layout and publishes onClose
through Svelte context; each section component is independent and loads
its own data through the @molecule/app-svelte hooks:
<AccountSection>— name/email edit (PATCH /api/users/:id).<AppearanceSection>— dark-mode toggle (useTheme()).<AuthSection>— password change + TOTP two-factor (POST /api/users/:id/verify-two-factor).<NotificationsSection>— web-push toggle (see the exportedenablePushOnCurrentDevice/disablePushOnCurrentDevicehelpers and their documented device-row contract).<BillingSection>— read-only plan display (GET /api/billing/status), or<TiersUpgradeSection>— full Stripe upgrade/cancel flow (/api/billing/tiers|checkout|cancel). Use one or the other, not both.<DevicesSection>/<ThisDeviceSection>— device list + current device (GET/DELETE /api/devices).<LogOutDeleteSection>— sign out + delete account (DELETE /api/users/:id).
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import {
AccountSection,
AppearanceSection,
AuthSection,
BillingSection,
DevicesSection,
LogOutDeleteSection,
NotificationsSection,
SettingsContainer,
ThisDeviceSection,
TiersUpgradeSection,
} from '@molecule/app-settings-panel-svelte'
// The sections read the app's services through the binding's hooks (see
// the wiring prereqs below).
let { onClose }: { onClose: () => void } = $props()
</script>
<SettingsContainer {onClose}>
<AccountSection />
<AppearanceSection />
<AuthSection />
<NotificationsSection />
<TiersUpgradeSection />
<DevicesSection />
<ThisDeviceSection />
<LogOutDeleteSection />
</SettingsContainer>
Type
feature
Installation
npm install @molecule/app-settings-panel-svelte @molecule/app-auth @molecule/app-http @molecule/app-push @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte @molecule/app-utilities svelte
API
Interfaces
SettingsPanelContextValue
What the nearest SettingsContainer provides through context.
interface SettingsPanelContextValue {
/** Dismisses the settings panel. */
onClose: () => void
}
Device
A user's registered device (subset rendered in the settings list).
Same shape as @molecule/app-settings-panel-react's Device.
interface Device {
/** The device row's id. */
id: string
/** The device's display name. */
name: string
/** The device's platform (`ios`, `android`, `linux`, …). */
platform: string
/** When the device was last seen, as the API reports it. */
lastSeen?: string
/** `true` for the device making the current request (the API marks it). */
isCurrent?: boolean
}
SettingsContainerProps
Props for the SettingsContainer component.
interface SettingsContainerProps {
/** Dismiss-the-panel handler, published to every section through context. */
onClose: () => void
/** The section sub-components to host. */
children?: Snippet
}
AuthSectionProps
Props for AuthSection. Same name and meaning as the React component's.
interface AuthSectionProps {
/**
* Show the two-factor row. Set false when the API has no two-factor provider
* (no `POST /users/:id/verify-two-factor` route). Default true.
*/
twoFactor?: boolean
}
DevicesSectionProps
Props for the DevicesSection component.
interface DevicesSectionProps {
/**
* Custom trailing element per device row, replacing the built-in revoke
* control. Render nothing to suppress the control entirely.
*/
renderRowIcon?: Snippet<[Device]>
}
TiersUpgradeSectionProps
Props for the TiersUpgradeSection component.
interface TiersUpgradeSectionProps {
/**
* How the page leaves for the checkout URL the server returns. Defaults to a
* full-page navigation (`openUrl` from `@molecule/app-utilities`).
*/
redirectToCheckout?: (checkoutUrl: string) => void
}
AccountValues
The profile values AccountSection edits (its controlled form fields).
Same shape the React component keeps.
interface AccountValues {
/** The user's display name. */
name: string
/** The user's email address (blank for phone/handle accounts). */
email: string
}
TwoFactorSetup
The two-factor enrollment payload POST /users/:id/verify-two-factor
answers with (action: 'setup').
interface TwoFactorSetup {
/** The QR code image URL to scan into an authenticator app. */
QRImageUrl?: string
/** The `otpauth://` key URL behind the QR code. */
keyUrl?: string
/** The base32 secret, shown for manual entry. */
secret?: string
}
TierPrice
One price of a billing tier, mapped from /api/billing/tiers.
interface TierPrice {
/** The Stripe price id, when the price is purchasable. */
stripePriceId?: string
/** The billing interval (`month`, `year`). */
interval: string
/** The formatted price label (`$9`). */
priceLabel: string
}
Tier
One paid tier, mapped from /api/billing/tiers.
interface Tier {
/** The tier's plan key (`free`, `pro`, …). */
planKey: string
/** The tier's display name. */
name: string
/** The tier's prices. */
prices: TierPrice[]
}
PushToggleHttp
Minimal structural slice of @molecule/app-http's HttpClient used here.
interface PushToggleHttp {
get<T = unknown>(url: string): Promise<{ data: T }>
patch<T = unknown>(url: string, data?: unknown): Promise<{ data: T }>
}
PushToggleDevice
Device row slice returned by GET /api/devices.
interface PushToggleDevice {
id: string
isCurrent?: boolean
hasPushSubscription?: boolean
}
PushToggleToken
Push token slice returned by @molecule/app-push register().
interface PushToggleToken {
value: string
platform: 'web' | 'ios' | 'android'
}
Types
PushToggleFailureReason
Why an enable/disable attempt failed (mapped to i18n by the component).
type PushToggleFailureReason =
'permission-denied' | 'server-unconfigured' | 'register-failed' | 'persist-failed'
PushToggleResult
Result of an enable/disable attempt.
type PushToggleResult =
{ ok: true } | { ok: false; reason: PushToggleFailureReason; message?: string }
Functions
useSettingsPanelContext()
Reads the onClose handler exposed by the parent SettingsContainer.
Throws if used outside the container so component misuse is loud. Reads
Svelte context, so it is only legal during component initialization.
function useSettingsPanelContext(): SettingsPanelContextValue
Returns: The container's context value.
findCurrentDevice(devices)
Picks the caller's own device row: the api flags the session device
isCurrent; fall back to the first row for sessions predating the flag.
function findCurrentDevice(devices: PushToggleDevice[] | undefined): PushToggleDevice | undefined
devices— Rows fromGET /api/devices.
Returns: The current device row, or undefined when the user has none.
subscriptionFromToken(token)
Converts an @molecule/app-push token into the device resource's
pushSubscription shape (web PushSubscription JSON, FCM registration for
Android, APNs registration for iOS).
function subscriptionFromToken(token: PushToggleToken): unknown
token— The push token returned byregister().
Returns: The pushSubscription value to PATCH onto the device row.
enablePushOnCurrentDevice(deps)
Runs the full enable chain: browser permission → runtime VAPID public key
(GET /api/devices/push/public-key) → register({ vapidPublicKey }) →
persist the subscription on the current device row.
Every failure is returned as a typed reason (never thrown) so the UI can show an honest, specific message instead of hanging or silently reverting.
function enablePushOnCurrentDevice(deps: {
http: PushToggleHttp
requestPermission: () => Promise<string>
register: (options?: { vapidPublicKey?: string }) => Promise<PushToggleToken>
}): Promise<PushToggleResult>
deps— The http client + push actions fromusePush().deps.http— Authenticated http client (useHttpClient()).deps.requestPermission—usePush().requestPermission.deps.register—usePush().register.
Returns: { ok: true } or a typed failure.
disablePushOnCurrentDevice(deps)
Disables push: unsubscribes the browser (best-effort — a dev build without a service worker has nothing to unsubscribe) and ALWAYS clears the server state so no further pushes target this device.
function disablePushOnCurrentDevice(deps: {
http: PushToggleHttp
unregister: () => Promise<void>
}): Promise<PushToggleResult>
deps— The http client + push action fromusePush().deps.http— Authenticated http client (useHttpClient()).deps.unregister—usePush().unregister.
Returns: { ok: true } or a typed failure (server state not cleared).
readCurrentDevicePushEnabled(http)
Reads whether push is currently enabled for THIS device (server truth:
the current device row's hasPushSubscription).
function readCurrentDevicePushEnabled(http: PushToggleHttp): Promise<boolean>
http— Authenticated http client (useHttpClient()).
Returns: true when the current device has a stored subscription.
Constants
AccountSection
const AccountSection: LegacyComponentType
AppearanceSection
const AppearanceSection: LegacyComponentType
AuthSection
const AuthSection: LegacyComponentType
BillingSection
const BillingSection: LegacyComponentType
DevicesSection
const DevicesSection: LegacyComponentType
LogOutDeleteSection
const LogOutDeleteSection: LegacyComponentType
NotificationsSection
const NotificationsSection: LegacyComponentType
SettingsContainer
const SettingsContainer: LegacyComponentType
ThisDeviceSection
const ThisDeviceSection: LegacyComponentType
TiersUpgradeSection
const TiersUpgradeSection: LegacyComponentType
SettingsPanelContext
The Svelte context key for the settings-panel context. SettingsContainer
provides the value with setContext(SettingsPanelContext, …) during its
initialization.
const SettingsPanelContext: symbol
Injection Notes
Requirements
Peer dependencies:
@molecule/app-auth^3.0.0@molecule/app-http^1.8.0@molecule/app-push^1.1.0@molecule/app-svelte^3.17.0 || ^4.0.0@molecule/app-ui^1.3.11@molecule/app-ui-svelte^1.1.0@molecule/app-utilities^1.0.6svelte^5.0.0
Runtime Dependencies
-
@molecule/app-auth -
@molecule/app-http -
@molecule/app-push -
@molecule/app-svelte -
@molecule/app-ui -
@molecule/app-ui-svelte -
@molecule/app-utilities -
svelte -
Wiring prereqs: sections need the standard composition root in the root layout — the routing bond's
MoleculeRouterProvideraround aMoleculeProviderfrom@molecule/app-sveltegiveni18n,http,authandtheme, as the Svelte scaffold'ssrc/routes/+layout.sveltedoes — plus a bonded ClassMap, device provider and push provider.<BillingSection>and<LogOutDeleteSection>also call the router and throw outside a composition root that carries one. -
Section components throw if rendered outside
<SettingsContainer>(they read its context foronClose). -
Server contract: the molecule API surface from
@molecule/api-resource-user,@molecule/api-resource-device,@molecule/api-two-factor, and the billing endpoints (/api/billing/*) wired by the payments stack. Missing read endpoints degrade gracefully (sections render empty); the mutating actions do not. -
Translations:
@molecule/app-locales-settings-panelcompanion bond.
Translations
Translation strings are provided by @molecule/app-locales-settings-panel.