@molecule/app-svelte 3.2.4 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2522 -194
- package/dist/agent-identity.d.ts +31 -0
- package/dist/agent-identity.d.ts.map +1 -0
- package/dist/agent-identity.js +22 -0
- package/dist/context.d.ts +113 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +222 -3
- package/dist/hooks/external-store.d.ts +28 -0
- package/dist/hooks/external-store.d.ts.map +1 -0
- package/dist/hooks/external-store.js +95 -0
- package/dist/hooks/index.d.ts +37 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +36 -0
- package/dist/hooks/live-store.d.ts +68 -0
- package/dist/hooks/live-store.d.ts.map +1 -0
- package/dist/hooks/live-store.js +76 -0
- package/dist/hooks/useAIModels.d.ts +58 -0
- package/dist/hooks/useAIModels.d.ts.map +1 -0
- package/dist/hooks/useAIModels.js +155 -0
- package/dist/hooks/useAsyncState.d.ts +52 -0
- package/dist/hooks/useAsyncState.d.ts.map +1 -0
- package/dist/hooks/useAsyncState.js +80 -0
- package/dist/hooks/useAuth.d.ts +99 -0
- package/dist/hooks/useAuth.d.ts.map +1 -0
- package/dist/hooks/useAuth.js +88 -0
- package/dist/hooks/useCapacitorApp.d.ts +51 -0
- package/dist/hooks/useCapacitorApp.d.ts.map +1 -0
- package/dist/hooks/useCapacitorApp.js +57 -0
- package/dist/hooks/useChangePassword.d.ts +41 -0
- package/dist/hooks/useChangePassword.d.ts.map +1 -0
- package/dist/hooks/useChangePassword.js +40 -0
- package/dist/hooks/useDevice.d.ts +48 -0
- package/dist/hooks/useDevice.d.ts.map +1 -0
- package/dist/hooks/useDevice.js +37 -0
- package/dist/hooks/useEditor.d.ts +65 -0
- package/dist/hooks/useEditor.d.ts.map +1 -0
- package/dist/hooks/useEditor.js +86 -0
- package/dist/hooks/useForm.d.ts +137 -0
- package/dist/hooks/useForm.d.ts.map +1 -0
- package/dist/hooks/useForm.js +221 -0
- package/dist/hooks/useHttp.d.ts +122 -0
- package/dist/hooks/useHttp.d.ts.map +1 -0
- package/dist/hooks/useHttp.js +220 -0
- package/dist/hooks/useLogger.d.ts +52 -0
- package/dist/hooks/useLogger.d.ts.map +1 -0
- package/dist/hooks/useLogger.js +64 -0
- package/dist/hooks/useLogin.d.ts +47 -0
- package/dist/hooks/useLogin.d.ts.map +1 -0
- package/dist/hooks/useLogin.js +44 -0
- package/dist/hooks/useOAuth.d.ts +96 -0
- package/dist/hooks/useOAuth.d.ts.map +1 -0
- package/dist/hooks/useOAuth.js +363 -0
- package/dist/hooks/useOptimisticValue.d.ts +58 -0
- package/dist/hooks/useOptimisticValue.d.ts.map +1 -0
- package/dist/hooks/useOptimisticValue.js +98 -0
- package/dist/hooks/usePasswordReset.d.ts +50 -0
- package/dist/hooks/usePasswordReset.d.ts.map +1 -0
- package/dist/hooks/usePasswordReset.js +50 -0
- package/dist/hooks/usePlatform.d.ts +45 -0
- package/dist/hooks/usePlatform.d.ts.map +1 -0
- package/dist/hooks/usePlatform.js +35 -0
- package/dist/hooks/usePreview.d.ts +54 -0
- package/dist/hooks/usePreview.d.ts.map +1 -0
- package/dist/hooks/usePreview.js +61 -0
- package/dist/hooks/useProfileForm.d.ts +100 -0
- package/dist/hooks/useProfileForm.d.ts.map +1 -0
- package/dist/hooks/useProfileForm.js +267 -0
- package/dist/hooks/usePromise.d.ts +62 -0
- package/dist/hooks/usePromise.d.ts.map +1 -0
- package/dist/hooks/usePromise.js +105 -0
- package/dist/hooks/usePush.d.ts +68 -0
- package/dist/hooks/usePush.d.ts.map +1 -0
- package/dist/hooks/usePush.js +79 -0
- package/dist/hooks/useRouter.d.ts +169 -0
- package/dist/hooks/useRouter.d.ts.map +1 -0
- package/dist/hooks/useRouter.js +212 -0
- package/dist/hooks/useSignup.d.ts +52 -0
- package/dist/hooks/useSignup.d.ts.map +1 -0
- package/dist/hooks/useSignup.js +42 -0
- package/dist/hooks/useStorage.d.ts +133 -0
- package/dist/hooks/useStorage.d.ts.map +1 -0
- package/dist/hooks/useStorage.js +228 -0
- package/dist/hooks/useStore.d.ts +69 -0
- package/dist/hooks/useStore.d.ts.map +1 -0
- package/dist/hooks/useStore.js +82 -0
- package/dist/hooks/useTheme.d.ts +55 -0
- package/dist/hooks/useTheme.d.ts.map +1 -0
- package/dist/hooks/useTheme.js +102 -0
- package/dist/hooks/useTranslation.d.ts +106 -0
- package/dist/hooks/useTranslation.d.ts.map +1 -0
- package/dist/hooks/useTranslation.js +159 -0
- package/dist/hooks/useVerifyPaymentReturn.d.ts +91 -0
- package/dist/hooks/useVerifyPaymentReturn.d.ts.map +1 -0
- package/dist/hooks/useVerifyPaymentReturn.js +189 -0
- package/dist/hooks/useVersion.d.ts +53 -0
- package/dist/hooks/useVersion.d.ts.map +1 -0
- package/dist/hooks/useVersion.js +70 -0
- package/dist/hooks/useWorkspace.d.ts +47 -0
- package/dist/hooks/useWorkspace.d.ts.map +1 -0
- package/dist/hooks/useWorkspace.js +68 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/session-ready/SessionReady.svelte +20 -0
- package/dist/session-ready/SessionReady.svelte.d.ts +5 -0
- package/dist/session-ready/SessionReady.svelte.d.ts.map +1 -0
- package/dist/session-ready/index.d.ts +7 -0
- package/dist/session-ready/index.d.ts.map +1 -0
- package/dist/session-ready/index.js +6 -0
- package/dist/stores/async-state.d.ts.map +1 -1
- package/dist/stores/async-state.js +12 -5
- package/dist/stores/auth.js +0 -1
- package/dist/stores/capacitor-app.js +1 -2
- package/dist/stores/change-password.js +0 -1
- package/dist/stores/chat.d.ts +68 -0
- package/dist/stores/chat.d.ts.map +1 -0
- package/dist/stores/chat.js +86 -0
- package/dist/stores/device.js +0 -1
- package/dist/stores/forms.js +0 -1
- package/dist/stores/http.js +0 -1
- package/dist/stores/i18n.d.ts +3 -2
- package/dist/stores/i18n.d.ts.map +1 -1
- package/dist/stores/i18n.js +2 -3
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.d.ts.map +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/stores/logger.js +0 -1
- package/dist/stores/login.js +0 -1
- package/dist/stores/oauth.d.ts.map +1 -1
- package/dist/stores/oauth.js +6 -3
- package/dist/stores/password-reset.js +0 -1
- package/dist/stores/platform.js +0 -1
- package/dist/stores/promise.js +0 -1
- package/dist/stores/push.js +0 -1
- package/dist/stores/router.js +0 -1
- package/dist/stores/signup.js +0 -1
- package/dist/stores/state.js +0 -1
- package/dist/stores/storage.js +0 -1
- package/dist/stores/theme.js +0 -1
- package/dist/stores/version.js +0 -1
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/package.json +33 -8
- package/dist/context.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/stores/async-state.js.map +0 -1
- package/dist/stores/auth.js.map +0 -1
- package/dist/stores/capacitor-app.js.map +0 -1
- package/dist/stores/change-password.js.map +0 -1
- package/dist/stores/device.js.map +0 -1
- package/dist/stores/forms.js.map +0 -1
- package/dist/stores/http.js.map +0 -1
- package/dist/stores/i18n.js.map +0 -1
- package/dist/stores/index.js.map +0 -1
- package/dist/stores/logger.js.map +0 -1
- package/dist/stores/login.js.map +0 -1
- package/dist/stores/oauth.js.map +0 -1
- package/dist/stores/password-reset.js.map +0 -1
- package/dist/stores/platform.js.map +0 -1
- package/dist/stores/promise.js.map +0 -1
- package/dist/stores/push.js.map +0 -1
- package/dist/stores/router.js.map +0 -1
- package/dist/stores/signup.js.map +0 -1
- package/dist/stores/state.js.map +0 -1
- package/dist/stores/storage.js.map +0 -1
- package/dist/stores/theme.js.map +0 -1
- package/dist/stores/version.js.map +0 -1
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-13T19:22:42.644Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-svelte
|
|
@@ -62,7 +62,7 @@ then consume services anywhere below via store factories
|
|
|
62
62
|
## Installation
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
|
-
npm install @molecule/app-svelte @molecule/app-auth @molecule/app-device @molecule/app-forms @molecule/app-http @molecule/app-i18n @molecule/app-logger @molecule/app-platform @molecule/app-push @molecule/app-routing @molecule/app-state @molecule/app-storage @molecule/app-theme @molecule/app-ui @molecule/app-utilities @molecule/app-version svelte
|
|
65
|
+
npm install @molecule/app-svelte @molecule/app-ai-chat @molecule/app-ai-models @molecule/app-auth @molecule/app-code-editor @molecule/app-device @molecule/app-forms @molecule/app-http @molecule/app-i18n @molecule/app-ide @molecule/app-live-preview @molecule/app-logger @molecule/app-platform @molecule/app-push @molecule/app-routing @molecule/app-state @molecule/app-storage @molecule/app-theme @molecule/app-ui @molecule/app-utilities @molecule/app-version svelte
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
## API
|
|
@@ -303,7 +303,9 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
|
|
|
303
303
|
getFieldState<K extends keyof T>(name: K): FieldState<T[K]>
|
|
304
304
|
|
|
305
305
|
/**
|
|
306
|
-
* Registers a field for form management.
|
|
306
|
+
* Registers a field for form management. A `defaultValue` that fills an
|
|
307
|
+
* empty field is announced to subscribers once, in a microtask, so a field
|
|
308
|
+
* registered during a render does not update other components mid-render.
|
|
307
309
|
*/
|
|
308
310
|
register(nameOrOptions: string | RegisterOptions, options?: RegisterOptions): FieldRegistration
|
|
309
311
|
|
|
@@ -620,11 +622,7 @@ interface I18nProvider {
|
|
|
620
622
|
*
|
|
621
623
|
* @returns The translated string, or the default value / key if not found.
|
|
622
624
|
*/
|
|
623
|
-
t(
|
|
624
|
-
key: string,
|
|
625
|
-
values?: InterpolationValues,
|
|
626
|
-
options?: { defaultValue?: string; count?: number },
|
|
627
|
-
): string
|
|
625
|
+
t(key: string, values?: InterpolationValues, options?: TranslateOptions): string
|
|
628
626
|
|
|
629
627
|
/**
|
|
630
628
|
* Checks if a translation key exists.
|
|
@@ -1219,372 +1217,2603 @@ interface Theme {
|
|
|
1219
1217
|
}
|
|
1220
1218
|
```
|
|
1221
1219
|
|
|
1222
|
-
#### `
|
|
1220
|
+
#### `UseAIModelsResult`
|
|
1223
1221
|
|
|
1224
|
-
|
|
1222
|
+
Result returned by `useAIModels`.
|
|
1225
1223
|
|
|
1226
1224
|
```typescript
|
|
1227
|
-
interface
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1225
|
+
interface UseAIModelsResult {
|
|
1226
|
+
/** Available models, or an empty array while loading, as a readable store. */
|
|
1227
|
+
models: Readable<AppModelDefinition[]>
|
|
1228
|
+
/**
|
|
1229
|
+
* Per-mode server default model ids for the requester's tier, or `undefined`
|
|
1230
|
+
* while loading or on servers that don't provide them.
|
|
1231
|
+
*/
|
|
1232
|
+
defaults: Readable<AppModeModelDefaults | undefined>
|
|
1233
|
+
/** The single model marked `freeTier: true`, or `undefined`. */
|
|
1234
|
+
freeTierModel: Readable<AppModelDefinition | undefined>
|
|
1235
|
+
/** `true` while the initial fetch is in flight. */
|
|
1236
|
+
loading: Readable<boolean>
|
|
1237
|
+
/** Error from the initial fetch, or `null`. */
|
|
1238
|
+
error: Readable<Error | null>
|
|
1233
1239
|
}
|
|
1234
1240
|
```
|
|
1235
1241
|
|
|
1236
|
-
#### `
|
|
1242
|
+
#### `UseAuthOptions`
|
|
1237
1243
|
|
|
1238
|
-
|
|
1244
|
+
Options for {@link useAuth}.
|
|
1239
1245
|
|
|
1240
1246
|
```typescript
|
|
1241
|
-
interface
|
|
1242
|
-
/**
|
|
1247
|
+
interface UseAuthOptions {
|
|
1248
|
+
/** Whether to automatically refresh the token on mount. */
|
|
1249
|
+
autoRefresh?: boolean
|
|
1250
|
+
}
|
|
1251
|
+
```
|
|
1252
|
+
|
|
1253
|
+
#### `UseAuthResult`
|
|
1254
|
+
|
|
1255
|
+
What {@link useAuth} returns: the session's value fields as readable stores
|
|
1256
|
+
(`$status`, `$user`, …) and the client's actions as plain functions.
|
|
1257
|
+
|
|
1258
|
+
```typescript
|
|
1259
|
+
interface UseAuthResult<
|
|
1260
|
+
T = unknown,
|
|
1261
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
1262
|
+
> {
|
|
1263
|
+
/**
|
|
1264
|
+
* The session state as one value — render from this instead of combining
|
|
1265
|
+
* `initialized`/`authenticated`/`loading`. Only `'loading'` means "no
|
|
1266
|
+
* decision yet"; redirect on `'unauthenticated'` alone.
|
|
1267
|
+
*/
|
|
1268
|
+
status: Readable<AuthState<T>['status']>
|
|
1269
|
+
/** The whole session state. */
|
|
1270
|
+
state: Readable<AuthState<T>>
|
|
1271
|
+
/** The client's `login`. */
|
|
1272
|
+
login: AuthClient<T>['login']
|
|
1273
|
+
/** The client's `logout`. */
|
|
1274
|
+
logout: AuthClient<T>['logout']
|
|
1275
|
+
/** The client's `register` (there is no separate `useRegister`). */
|
|
1276
|
+
register: AuthClient<T, TRegister>['register']
|
|
1277
|
+
/** The client's `refresh`. */
|
|
1278
|
+
refresh: AuthClient<T>['refresh']
|
|
1279
|
+
/** Saves through the configured auth transport and publishes the saved user. */
|
|
1280
|
+
updateProfile: AuthClient<T>['updateProfile']
|
|
1281
|
+
/** Caches a user without signing in. */
|
|
1282
|
+
setUser: AuthClient<T>['setUser']
|
|
1283
|
+
/**
|
|
1284
|
+
* Adopts a session an exchange outside the client already established (an
|
|
1285
|
+
* OAuth code→token redirect, the app's own sign-in endpoint) in one update.
|
|
1286
|
+
*/
|
|
1287
|
+
setSession: AuthClient<T>['setSession']
|
|
1288
|
+
/** Whether a session is authenticated locally. */
|
|
1289
|
+
isAuthenticated: Readable<boolean>
|
|
1290
|
+
/** Whether the client is working on a decision. */
|
|
1291
|
+
isLoading: Readable<boolean>
|
|
1292
|
+
/** The cached profile, which can be null while an unavailable candidate is retained. */
|
|
1293
|
+
user: Readable<T | null>
|
|
1294
|
+
}
|
|
1295
|
+
```
|
|
1296
|
+
|
|
1297
|
+
#### `UseChangePasswordResult`
|
|
1298
|
+
|
|
1299
|
+
What {@link useChangePassword} returns.
|
|
1300
|
+
|
|
1301
|
+
```typescript
|
|
1302
|
+
interface UseChangePasswordResult {
|
|
1303
|
+
/** The latest call's status. */
|
|
1304
|
+
status: Readable<UsePromiseState<void>['status']>
|
|
1305
|
+
/** The latest call's rejection. */
|
|
1306
|
+
error: Readable<UsePromiseState<void>['error']>
|
|
1307
|
+
/** Runs the password change. */
|
|
1308
|
+
changePassword: (oldPassword: string, newPassword: string) => Promise<void>
|
|
1309
|
+
/** Returns the tracker to idle. */
|
|
1310
|
+
reset: () => void
|
|
1311
|
+
}
|
|
1312
|
+
```
|
|
1313
|
+
|
|
1314
|
+
#### `UseDeviceResult`
|
|
1315
|
+
|
|
1316
|
+
Hook return type.
|
|
1317
|
+
|
|
1318
|
+
```typescript
|
|
1319
|
+
interface UseDeviceResult {
|
|
1320
|
+
/** The parsed device identity. */
|
|
1321
|
+
deviceInfo: DeviceInfo
|
|
1322
|
+
/** The screen dimensions and mode. */
|
|
1323
|
+
screenInfo: ScreenInfo
|
|
1324
|
+
/** The hardware capabilities. */
|
|
1325
|
+
hardwareInfo: HardwareInfo
|
|
1326
|
+
/** The feature flags. */
|
|
1327
|
+
featureSupport: FeatureSupport
|
|
1328
|
+
/** Whether a feature is supported. */
|
|
1329
|
+
supports: (feature: keyof FeatureSupport) => boolean
|
|
1330
|
+
/** Whether the device is online. */
|
|
1331
|
+
isOnline: () => boolean
|
|
1332
|
+
/** Whether the app runs standalone. */
|
|
1333
|
+
isStandalone: () => boolean
|
|
1334
|
+
/** The preferred language. */
|
|
1335
|
+
language: string
|
|
1336
|
+
/** The preferred languages, best first. */
|
|
1337
|
+
languages: string[]
|
|
1338
|
+
}
|
|
1339
|
+
```
|
|
1340
|
+
|
|
1341
|
+
#### `UseEditorResult`
|
|
1342
|
+
|
|
1343
|
+
Hook result for useEditor: the tab state as readable stores and the editor
|
|
1344
|
+
actions as plain functions.
|
|
1345
|
+
|
|
1346
|
+
```typescript
|
|
1347
|
+
interface UseEditorResult {
|
|
1348
|
+
/** The provider's open tabs. */
|
|
1349
|
+
tabs: Readable<EditorTab[]>
|
|
1350
|
+
/** The path of the tab marked active, or null when none is. */
|
|
1351
|
+
activeFile: Readable<string | null>
|
|
1352
|
+
/** Opens a file in a tab and activates it. */
|
|
1353
|
+
openFile: (file: EditorFile) => void
|
|
1354
|
+
/** Closes a tab. */
|
|
1355
|
+
closeFile: (path: string) => void
|
|
1356
|
+
/** The active tab's content. */
|
|
1357
|
+
getContent: () => string | null
|
|
1358
|
+
/** Writes a tab's content. */
|
|
1359
|
+
setContent: (path: string, content: string) => void
|
|
1360
|
+
/** Activates the tab with the given path. */
|
|
1361
|
+
setActiveTab: (path: string) => void
|
|
1362
|
+
/** Mounts the editor into an element. */
|
|
1363
|
+
mount: EditorProvider['mount']
|
|
1364
|
+
/** Disposes the editor. */
|
|
1365
|
+
dispose: () => void
|
|
1366
|
+
/** Focuses the editor. */
|
|
1367
|
+
focus: () => void
|
|
1368
|
+
/** Opens a diff tab (provider optional method). */
|
|
1369
|
+
openDiff: (file: DiffFile) => void
|
|
1370
|
+
/** Closes the diff tab (provider optional method). */
|
|
1371
|
+
closeDiff: () => void
|
|
1372
|
+
/** Converts a preview tab into a normal one (provider optional method). */
|
|
1373
|
+
pinTab: (path: string) => void
|
|
1374
|
+
/** Adds an extra type library (provider optional method). */
|
|
1375
|
+
addExtraLib: (content: string, filePath: string) => void
|
|
1376
|
+
/** Subscribes a Fix-with-AI request listener; returns its unsubscribe. */
|
|
1377
|
+
onFixWithAI: (callback: (request: FixWithAIRequest) => void) => () => void
|
|
1378
|
+
}
|
|
1379
|
+
```
|
|
1380
|
+
|
|
1381
|
+
#### `UseFormOptions`
|
|
1382
|
+
|
|
1383
|
+
Options for useForm hook.
|
|
1384
|
+
|
|
1385
|
+
Every `FormOptions` field is supported. `createForm` is only an override —
|
|
1386
|
+
omit it and the hook creates the controller through the bonded forms
|
|
1387
|
+
provider (`createForm` from `@molecule/app-forms`), which uses the built-in
|
|
1388
|
+
native provider until the app bonds its own.
|
|
1389
|
+
|
|
1390
|
+
```typescript
|
|
1391
|
+
interface UseFormOptions<T extends FormValuesConstraint<T>> extends FormOptions<T> {
|
|
1392
|
+
/** External values preserve dirty fields by default. Set keepDirtyValues: false to replace them explicitly. */
|
|
1393
|
+
resetOptions?: FormResetOptions
|
|
1394
|
+
/** New record identity. Serialize composite keys; fresh objects/arrays must not reset drafts on each mount. */
|
|
1395
|
+
resetKey?: string | number | boolean | bigint | null
|
|
1396
|
+
/**
|
|
1397
|
+
* Explicit form factory for this one form. Defaults to the bonded forms
|
|
1398
|
+
* provider; pass it only to pin a specific provider instance.
|
|
1399
|
+
*/
|
|
1400
|
+
createForm?: (options: FormOptions<T>) => FormController<T>
|
|
1401
|
+
}
|
|
1402
|
+
```
|
|
1403
|
+
|
|
1404
|
+
#### `UseFormResult`
|
|
1405
|
+
|
|
1406
|
+
Result of useForm hook: the state fields as readable stores, the methods as
|
|
1407
|
+
plain functions.
|
|
1408
|
+
|
|
1409
|
+
```typescript
|
|
1410
|
+
interface UseFormResult<T extends FormValuesConstraint<T>> {
|
|
1411
|
+
/** The whole form state. */
|
|
1412
|
+
formState: Readable<FormState<T>>
|
|
1413
|
+
/** Whether every field passes validation. */
|
|
1414
|
+
isValid: Readable<boolean>
|
|
1415
|
+
/** Whether any field differs from the baseline. */
|
|
1416
|
+
isDirty: Readable<boolean>
|
|
1417
|
+
/** Whether a submit is running. */
|
|
1418
|
+
isSubmitting: Readable<boolean>
|
|
1419
|
+
|
|
1420
|
+
/** Registers a field; returns its native bindings. */
|
|
1421
|
+
register: (
|
|
1422
|
+
name: keyof T,
|
|
1423
|
+
options?: Omit<RegisterOptions, 'name'> & { name?: string },
|
|
1424
|
+
) => FieldRegistration
|
|
1425
|
+
/** Reads one field's value. */
|
|
1426
|
+
getValue: <K extends keyof T>(name: K) => T[K]
|
|
1427
|
+
/** Writes one field's value (marks it touched and dirty). */
|
|
1428
|
+
setValue: <K extends keyof T>(name: K, value: T[K]) => void
|
|
1429
|
+
/** Reads one field's error. */
|
|
1430
|
+
getError: (name: keyof T) => string | undefined
|
|
1431
|
+
/** Sets or clears one field's error. */
|
|
1432
|
+
setError: (name: keyof T, error: string | undefined) => void
|
|
1433
|
+
/** Clears every field error. */
|
|
1434
|
+
clearErrors: () => void
|
|
1435
|
+
|
|
1436
|
+
/** Validates and runs the handler; returns the submit runner. */
|
|
1437
|
+
handleSubmit: (
|
|
1438
|
+
onSubmit: (values: T) => void | Promise<void>,
|
|
1439
|
+
onError?: (errors: Partial<Record<keyof T, string>>) => void,
|
|
1440
|
+
) => (event?: { preventDefault?: () => void }) => Promise<void>
|
|
1441
|
+
/** Restores the baseline (optionally a new one) and clears touched, errors and submit state. */
|
|
1442
|
+
reset: (values?: Partial<T>) => void
|
|
1443
|
+
/** Applies externally loaded values without clearing submission state. */
|
|
1444
|
+
updateValues: (values: Partial<T>, resetOptions?: FormResetOptions) => void
|
|
1445
|
+
/** Whole-form state tuple: edits mark only changed fields dirty; fills preserve them. */
|
|
1446
|
+
asState(): readonly [
|
|
1447
|
+
T,
|
|
1448
|
+
(value: T | ((previous: T) => T)) => void,
|
|
1449
|
+
(value: Partial<T> | ((previous: T) => Partial<T>)) => void,
|
|
1450
|
+
]
|
|
1451
|
+
/** One field as [value, edit, fill]. Fill preserves edits made before data arrives. */
|
|
1452
|
+
asState<K extends keyof T>(
|
|
1453
|
+
name: K,
|
|
1454
|
+
): readonly [
|
|
1455
|
+
T[K],
|
|
1456
|
+
(value: T[K] | ((previous: T[K]) => T[K])) => void,
|
|
1457
|
+
(value: T[K] | ((previous: T[K]) => T[K])) => void,
|
|
1458
|
+
]
|
|
1459
|
+
/** Runs every registered rule and publishes field errors. */
|
|
1460
|
+
validate: () => Promise<boolean>
|
|
1461
|
+
}
|
|
1462
|
+
```
|
|
1463
|
+
|
|
1464
|
+
#### `UseHttpState`
|
|
1465
|
+
|
|
1466
|
+
State for async HTTP operations.
|
|
1467
|
+
|
|
1468
|
+
```typescript
|
|
1469
|
+
interface UseHttpState<T> {
|
|
1470
|
+
data: T | null
|
|
1471
|
+
loading: boolean
|
|
1472
|
+
error: Error | null
|
|
1473
|
+
}
|
|
1474
|
+
```
|
|
1475
|
+
|
|
1476
|
+
#### `UseHttpResult`
|
|
1477
|
+
|
|
1478
|
+
What {@link useHttp} returns: the state fields as stores plus `execute` and `reset`.
|
|
1479
|
+
|
|
1480
|
+
```typescript
|
|
1481
|
+
interface UseHttpResult<T> {
|
|
1482
|
+
/** The newest request's data, or null. */
|
|
1483
|
+
data: Readable<T | null>
|
|
1484
|
+
/** Whether a request is in flight. */
|
|
1485
|
+
loading: Readable<boolean>
|
|
1486
|
+
/** The newest request's failure. */
|
|
1487
|
+
error: Readable<Error | null>
|
|
1488
|
+
/**
|
|
1489
|
+
* Runs the request and resolves with its own data, or `null` on failure,
|
|
1490
|
+
* even when a newer request or `reset` has superseded its displayed state.
|
|
1491
|
+
*
|
|
1492
|
+
* This function keeps ONE identity for the component's life, so it is safe
|
|
1493
|
+
* wherever a stable function matters. Its request options are read when it
|
|
1494
|
+
* is CALLED.
|
|
1495
|
+
*/
|
|
1496
|
+
execute: () => Promise<T | null>
|
|
1497
|
+
/** Clears the state and supersedes any in-flight request. */
|
|
1498
|
+
reset: () => void
|
|
1499
|
+
}
|
|
1500
|
+
```
|
|
1501
|
+
|
|
1502
|
+
#### `UseHttpOptions`
|
|
1503
|
+
|
|
1504
|
+
Options for the {@link useHttp} hooks.
|
|
1505
|
+
|
|
1506
|
+
Every request option — headers, params, body `data`, `signal`, `onSuccess`,
|
|
1507
|
+
`onError` — is read at the moment `execute` runs, not when the hook was
|
|
1508
|
+
called. Only `immediate` is read on mount.
|
|
1509
|
+
|
|
1510
|
+
```typescript
|
|
1511
|
+
interface UseHttpOptions<T> extends RequestConfig {
|
|
1512
|
+
/** Whether to execute the request immediately on mount. */
|
|
1513
|
+
immediate?: boolean
|
|
1514
|
+
/**
|
|
1515
|
+
* Callback for each request that succeeds while mounted, including a request
|
|
1516
|
+
* superseded by another `execute` or `reset`. Read `data` from the hook when
|
|
1517
|
+
* only the newest request's result should drive the UI.
|
|
1518
|
+
*/
|
|
1519
|
+
onSuccess?: (data: T) => void
|
|
1520
|
+
/** Callback for each request that fails while mounted, including a superseded one. */
|
|
1521
|
+
onError?: (error: Error) => void
|
|
1522
|
+
}
|
|
1523
|
+
```
|
|
1524
|
+
|
|
1525
|
+
#### `UseLoginResult`
|
|
1526
|
+
|
|
1527
|
+
What {@link useLogin} returns: the promise state's value fields as stores plus the action.
|
|
1528
|
+
|
|
1529
|
+
```typescript
|
|
1530
|
+
interface UseLoginResult<T = unknown> {
|
|
1531
|
+
/** The latest call's status. */
|
|
1532
|
+
status: Readable<UsePromiseState<AuthResult<T>>['status']>
|
|
1533
|
+
/** The latest call's resolved value. */
|
|
1534
|
+
value: Readable<UsePromiseState<AuthResult<T>>['value']>
|
|
1535
|
+
/** The latest call's rejection. */
|
|
1536
|
+
error: Readable<UsePromiseState<AuthResult<T>>['error']>
|
|
1537
|
+
/** Runs the login. */
|
|
1538
|
+
login: (credentials: LoginCredentials) => Promise<AuthResult<T>>
|
|
1539
|
+
/** Returns the tracker to idle. */
|
|
1540
|
+
reset: () => void
|
|
1541
|
+
}
|
|
1542
|
+
```
|
|
1543
|
+
|
|
1544
|
+
#### `UseOAuthReturn`
|
|
1545
|
+
|
|
1546
|
+
Return type for useOAuth hook.
|
|
1547
|
+
|
|
1548
|
+
```typescript
|
|
1549
|
+
interface UseOAuthReturn {
|
|
1550
|
+
/** The configured provider names. */
|
|
1551
|
+
providers: string[]
|
|
1552
|
+
/** Builds the provider's initiation URL (provider encoded as one path segment). */
|
|
1553
|
+
getOAuthUrl: (provider: string) => string
|
|
1554
|
+
/** Full-page redirect to the provider (default). The opener page navigates away. */
|
|
1555
|
+
redirect: (provider: string) => void
|
|
1556
|
+
/**
|
|
1557
|
+
* Open the provider in a popup so the opener page does NOT navigate. On success
|
|
1558
|
+
* the session is established in the opener in place and `config.onSuccess` fires;
|
|
1559
|
+
* on failure `config.onError` fires. Falls back to a full-page {@link redirect}
|
|
1560
|
+
* when the popup is blocked.
|
|
1561
|
+
*/
|
|
1562
|
+
loginViaPopup: (provider: string) => void
|
|
1563
|
+
}
|
|
1564
|
+
```
|
|
1565
|
+
|
|
1566
|
+
#### `UseOAuthConfig`
|
|
1567
|
+
|
|
1568
|
+
OAuth configuration override options.
|
|
1569
|
+
|
|
1570
|
+
```typescript
|
|
1571
|
+
interface UseOAuthConfig {
|
|
1572
|
+
/** Base URL for the API server (e.g. "https://api.example.com"). */
|
|
1243
1573
|
baseURL?: string
|
|
1244
|
-
/** List of supported OAuth provider names (e.g.
|
|
1574
|
+
/** List of supported OAuth provider names (e.g. ["google", "github"]). */
|
|
1245
1575
|
oauthProviders?: string[]
|
|
1246
|
-
/** Path prefix for OAuth
|
|
1576
|
+
/** Path prefix for OAuth routes (defaults to "/oauth"). */
|
|
1247
1577
|
oauthEndpoint?: string
|
|
1248
|
-
/** Path for the OAuth login POST endpoint
|
|
1578
|
+
/** Path for the OAuth login POST endpoint (defaults to "/users/log-in/oauth"). */
|
|
1249
1579
|
loginEndpoint?: string
|
|
1250
|
-
/** Callback
|
|
1580
|
+
/** Callback after successful OAuth login. */
|
|
1251
1581
|
onSuccess?: () => void
|
|
1252
|
-
/** Callback
|
|
1582
|
+
/** Callback on OAuth login failure. */
|
|
1253
1583
|
onError?: (error: string) => void
|
|
1254
1584
|
/**
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1257
|
-
*
|
|
1258
|
-
*
|
|
1585
|
+
* How the page leaves for the provider: {@link UseOAuthReturn.redirect} and the
|
|
1586
|
+
* blocked-popup fallback call it with the provider URL. Defaults to a full-page
|
|
1587
|
+
* navigation (`window.location.href = url`); pass an in-app browser opener on
|
|
1588
|
+
* native, or a router's external navigation.
|
|
1259
1589
|
*/
|
|
1260
|
-
|
|
1590
|
+
navigate?: (url: string) => void
|
|
1591
|
+
}
|
|
1592
|
+
```
|
|
1593
|
+
|
|
1594
|
+
#### `UseOptimisticValueResult`
|
|
1595
|
+
|
|
1596
|
+
What {@link useOptimisticValue} returns: the state to render as readable
|
|
1597
|
+
stores and the two ways to change it (the same names React returns).
|
|
1598
|
+
|
|
1599
|
+
```typescript
|
|
1600
|
+
interface UseOptimisticValueResult<T> {
|
|
1601
|
+
/** The value to render. */
|
|
1602
|
+
value: Readable<T>
|
|
1603
|
+
/** Whether a save is running or waiting. */
|
|
1604
|
+
pending: Readable<boolean>
|
|
1605
|
+
/** The failure of the newest change. */
|
|
1606
|
+
error: Readable<unknown>
|
|
1607
|
+
/** Shows `next` at once and saves it, after any save already running. */
|
|
1608
|
+
set: (next: T) => void
|
|
1609
|
+
/** Like `set`, computed from the value shown now (`update((on) => !on)`). */
|
|
1610
|
+
update: (change: (current: T) => T) => void
|
|
1611
|
+
}
|
|
1612
|
+
```
|
|
1613
|
+
|
|
1614
|
+
#### `UsePasswordResetResult`
|
|
1615
|
+
|
|
1616
|
+
What {@link usePasswordReset} returns: two independent trackers plus a combined reset.
|
|
1617
|
+
|
|
1618
|
+
```typescript
|
|
1619
|
+
interface UsePasswordResetResult {
|
|
1620
|
+
/** The request step's status. */
|
|
1621
|
+
requestStatus: Readable<UsePromiseState<void>['status']>
|
|
1622
|
+
/** The request step's rejection. */
|
|
1623
|
+
requestError: Readable<UsePromiseState<void>['error']>
|
|
1624
|
+
/** The confirm step's status. */
|
|
1625
|
+
confirmStatus: Readable<UsePromiseState<void>['status']>
|
|
1626
|
+
/** The confirm step's rejection. */
|
|
1627
|
+
confirmError: Readable<UsePromiseState<void>['error']>
|
|
1628
|
+
/** Sends the reset email (step 1). */
|
|
1629
|
+
requestReset: (data: PasswordResetRequest) => Promise<void>
|
|
1630
|
+
/** Sets the new password (step 2). */
|
|
1631
|
+
confirmReset: (data: PasswordResetConfirm) => Promise<void>
|
|
1632
|
+
/** Returns BOTH trackers to idle. */
|
|
1633
|
+
reset: () => void
|
|
1634
|
+
}
|
|
1635
|
+
```
|
|
1636
|
+
|
|
1637
|
+
#### `UsePlatformResult`
|
|
1638
|
+
|
|
1639
|
+
Hook return type.
|
|
1640
|
+
|
|
1641
|
+
```typescript
|
|
1642
|
+
interface UsePlatformResult {
|
|
1643
|
+
/** The detected platform. */
|
|
1644
|
+
platform: Platform
|
|
1645
|
+
/** Whether the app runs in a native shell. */
|
|
1646
|
+
isNative: boolean
|
|
1647
|
+
/** Whether the platform is a phone or tablet. */
|
|
1648
|
+
isMobile: boolean
|
|
1649
|
+
/** Whether the platform is a desktop. */
|
|
1650
|
+
isDesktop: boolean
|
|
1651
|
+
/** Whether the platform is the web. */
|
|
1652
|
+
isWeb: boolean
|
|
1653
|
+
/** Whether the app runs in development. */
|
|
1654
|
+
isDevelopment: boolean
|
|
1655
|
+
/** Whether the app runs in production. */
|
|
1656
|
+
isProduction: boolean
|
|
1657
|
+
/** Whether the current platform is one of the candidates. */
|
|
1658
|
+
isPlatform: (...platforms: Platform[]) => boolean
|
|
1659
|
+
}
|
|
1660
|
+
```
|
|
1661
|
+
|
|
1662
|
+
#### `UsePreviewResult`
|
|
1663
|
+
|
|
1664
|
+
Hook result for usePreview: the preview state as a readable store and the
|
|
1665
|
+
controls as plain functions.
|
|
1666
|
+
|
|
1667
|
+
```typescript
|
|
1668
|
+
interface UsePreviewResult {
|
|
1669
|
+
/** The preview's full state (url, currentUrl, isLoading, device, error, isConnected, canGoBack, canGoForward, loadNonce). */
|
|
1670
|
+
state: Readable<PreviewState>
|
|
1671
|
+
/** Loads a url. */
|
|
1672
|
+
setUrl: (url: string) => void
|
|
1673
|
+
/** Reloads the current document. */
|
|
1674
|
+
refresh: () => void
|
|
1675
|
+
/** Switches the device frame. */
|
|
1676
|
+
setDevice: (device: DeviceFrame) => void
|
|
1677
|
+
/** Opens the current url outside the app. */
|
|
1678
|
+
openExternal: () => void
|
|
1679
|
+
/**
|
|
1680
|
+
* Records a navigation the running preview reported via its `molecule:navigate`
|
|
1681
|
+
* message — updates the displayed current location without reloading the iframe.
|
|
1682
|
+
* Pass `isReplace` when the preview REPLACED its current history entry (a
|
|
1683
|
+
* `replaceState` redirect/canonicalization) so the forward stack is preserved
|
|
1684
|
+
* instead of truncated (a `pushState`, the default, truncates forward).
|
|
1685
|
+
*/
|
|
1686
|
+
recordNavigation: (url: string, isReplace?: boolean) => void
|
|
1687
|
+
/** Navigates the preview to the previous navigation-history entry (Back). */
|
|
1688
|
+
back: () => void
|
|
1689
|
+
/** Navigates the preview to the next navigation-history entry (Forward). */
|
|
1690
|
+
forward: () => void
|
|
1691
|
+
}
|
|
1692
|
+
```
|
|
1693
|
+
|
|
1694
|
+
#### `UseProfileFormOptions`
|
|
1695
|
+
|
|
1696
|
+
Configuration for a profile form; transport stays in the auth bond.
|
|
1697
|
+
|
|
1698
|
+
`TValues` is the page's own controlled-values type, named once as an
|
|
1699
|
+
`interface` or a type alias — both satisfy the shared form-values constraint.
|
|
1700
|
+
|
|
1701
|
+
```typescript
|
|
1702
|
+
interface UseProfileFormOptions<TUser, TValues extends FormValuesConstraint<TValues>> extends Omit<
|
|
1703
|
+
UseFormOptions<TValues>,
|
|
1704
|
+
'defaultValues'
|
|
1705
|
+
> {
|
|
1706
|
+
/** Complete controlled-field defaults, including blank write-only fields. */
|
|
1707
|
+
defaultValues: TValues
|
|
1708
|
+
/**
|
|
1709
|
+
* Optional additional account identity check; changing it discards prior edits.
|
|
1710
|
+
* By default ownership follows the auth client's session revision, so editable
|
|
1711
|
+
* fields can change during a save. Providers without getSessionRevision must
|
|
1712
|
+
* supply this callback with an identity that remains stable across profile edits.
|
|
1713
|
+
*/
|
|
1714
|
+
getIdentity?: (user: TUser) => string
|
|
1715
|
+
/** Maps the current/saved user into controlled values, e.g. nullable text to ''. */
|
|
1716
|
+
toValues: (user: TUser) => TValues
|
|
1717
|
+
/**
|
|
1718
|
+
* Maps ONLY changed fields into an API patch. Omit blank optional credentials
|
|
1719
|
+
* here; preserve undefined/absent fields rather than turning them into null.
|
|
1720
|
+
* The second argument is the complete value snapshot taken at submit time.
|
|
1721
|
+
*/
|
|
1722
|
+
toPatch: (changes: Partial<TValues>, values: Readonly<TValues>) => Partial<TUser>
|
|
1723
|
+
/**
|
|
1724
|
+
* Propagates the server's saved user to other caches, then navigates if needed.
|
|
1725
|
+
* Awaited before submission finishes. The auth client already persists and
|
|
1726
|
+
* publishes the saved user; never seed caches from the submitted patch.
|
|
1727
|
+
*/
|
|
1728
|
+
onSaved?: (user: TUser) => void | Promise<void>
|
|
1729
|
+
}
|
|
1730
|
+
```
|
|
1731
|
+
|
|
1732
|
+
#### `UseProfileFormResult`
|
|
1733
|
+
|
|
1734
|
+
Controlled profile form state and native form bindings.
|
|
1735
|
+
|
|
1736
|
+
```typescript
|
|
1737
|
+
interface UseProfileFormResult<TUser, TValues extends FormValuesConstraint<TValues>> extends Omit<
|
|
1738
|
+
UseFormResult<TValues>,
|
|
1739
|
+
'register' | 'handleSubmit' | 'reset'
|
|
1740
|
+
> {
|
|
1741
|
+
/** The shared auth user's current profile, as a readable store. */
|
|
1742
|
+
user: Readable<TUser | null>
|
|
1743
|
+
/** A user has been loaded; disable submission until this is true. */
|
|
1744
|
+
ready: Readable<boolean>
|
|
1745
|
+
/**
|
|
1746
|
+
* The latest save/propagation failure. Rejected saves retain edits; a failed
|
|
1747
|
+
* onSaved callback can be retried by submit without repeating the mutation.
|
|
1748
|
+
*/
|
|
1749
|
+
error: Readable<unknown>
|
|
1750
|
+
/** Native input/textarea bindings with the field's concrete value type. */
|
|
1751
|
+
register: <K extends keyof TValues>(
|
|
1752
|
+
name: K,
|
|
1753
|
+
options?: Parameters<UseFormResult<TValues>['register']>[1],
|
|
1754
|
+
) => Omit<FieldRegistration, 'value'> & { value: TValues[K] }
|
|
1755
|
+
/** Bind to the native form, with a type="submit" button inside it. */
|
|
1756
|
+
formProps: { onSubmit: (event: { preventDefault: () => void }) => void }
|
|
1757
|
+
/**
|
|
1758
|
+
* Validates and saves one submit-time snapshot. Concurrent submits share the
|
|
1759
|
+
* same promise. Resolves undefined on validation, save or propagation failure.
|
|
1760
|
+
*/
|
|
1761
|
+
submit: () => Promise<TUser | undefined>
|
|
1762
|
+
/** Discards edits and restores the newest loaded/saved profile baseline. */
|
|
1763
|
+
reset: () => void
|
|
1764
|
+
}
|
|
1765
|
+
```
|
|
1766
|
+
|
|
1767
|
+
#### `UsePromiseState`
|
|
1768
|
+
|
|
1769
|
+
Extended promise state with actions, React's `UsePromiseState`.
|
|
1770
|
+
|
|
1771
|
+
```typescript
|
|
1772
|
+
interface UsePromiseState<T> {
|
|
1773
|
+
status: PromiseStatus
|
|
1774
|
+
value: T | null
|
|
1775
|
+
error: Error | null
|
|
1776
|
+
cancel: (message?: string) => void
|
|
1777
|
+
reset: () => void
|
|
1778
|
+
}
|
|
1779
|
+
```
|
|
1780
|
+
|
|
1781
|
+
#### `UsePushResult`
|
|
1782
|
+
|
|
1783
|
+
Hook return type.
|
|
1784
|
+
|
|
1785
|
+
```typescript
|
|
1786
|
+
interface UsePushResult {
|
|
1787
|
+
/** The last permission status a check or request reported, null until one runs. */
|
|
1788
|
+
permission: Readable<PermissionStatus | null>
|
|
1789
|
+
/** The token register() resolved, null until a registration. */
|
|
1790
|
+
token: Readable<PushToken | null>
|
|
1791
|
+
/** Reads the permission status from the provider. */
|
|
1792
|
+
checkPermission: () => Promise<PermissionStatus>
|
|
1793
|
+
/** Asks the user for permission and stores the answer. */
|
|
1794
|
+
requestPermission: () => Promise<PermissionStatus>
|
|
1795
|
+
/** Registers for push and stores the token. */
|
|
1796
|
+
register: (options?: PushRegisterOptions) => Promise<PushToken>
|
|
1797
|
+
/** Unregisters and clears the token. */
|
|
1798
|
+
unregister: () => Promise<void>
|
|
1799
|
+
/** Subscribes a notification listener; returns its unsubscribe. */
|
|
1800
|
+
onNotificationReceived: (listener: NotificationReceivedListener) => () => void
|
|
1801
|
+
/** Subscribes a notification-action listener; returns its unsubscribe. */
|
|
1802
|
+
onNotificationAction: (listener: NotificationActionListener) => () => void
|
|
1803
|
+
/** Subscribes a token-change listener; returns its unsubscribe. */
|
|
1804
|
+
onTokenChange: (listener: TokenChangeListener) => () => void
|
|
1805
|
+
/** Sets the badge count. */
|
|
1806
|
+
setBadge: (count: number) => Promise<void>
|
|
1807
|
+
/** Clears the badge. */
|
|
1808
|
+
clearBadge: () => Promise<void>
|
|
1809
|
+
}
|
|
1810
|
+
```
|
|
1811
|
+
|
|
1812
|
+
#### `UsePushOptions`
|
|
1813
|
+
|
|
1814
|
+
Options for the usePush hook (e.g. check permission on mount).
|
|
1815
|
+
|
|
1816
|
+
```typescript
|
|
1817
|
+
interface UsePushOptions {
|
|
1818
|
+
/**
|
|
1819
|
+
* Whether to check permission status on mount.
|
|
1820
|
+
*/
|
|
1821
|
+
checkOnMount?: boolean
|
|
1822
|
+
}
|
|
1823
|
+
```
|
|
1824
|
+
|
|
1825
|
+
#### `UseRouterResult`
|
|
1826
|
+
|
|
1827
|
+
What {@link useRouter} returns.
|
|
1828
|
+
|
|
1829
|
+
```typescript
|
|
1830
|
+
interface UseRouterResult {
|
|
1831
|
+
/** The current location. */
|
|
1832
|
+
location: Readable<RouteLocation>
|
|
1833
|
+
/** The current route's path parameters. */
|
|
1834
|
+
params: Readable<Record<string, string>>
|
|
1835
|
+
/** The current query parameters. */
|
|
1836
|
+
query: Readable<QueryParams>
|
|
1837
|
+
/** Navigates to a path. */
|
|
1838
|
+
navigate: Router['navigate']
|
|
1839
|
+
/** Navigates to a named route. */
|
|
1840
|
+
navigateTo: Router['navigateTo']
|
|
1841
|
+
/** Goes back one history entry. */
|
|
1842
|
+
back: Router['back']
|
|
1843
|
+
/** Goes forward one history entry. */
|
|
1844
|
+
forward: Router['forward']
|
|
1845
|
+
/** Whether a path is active (prefix, or exact with `exact`). */
|
|
1846
|
+
isActive: Router['isActive']
|
|
1847
|
+
}
|
|
1848
|
+
```
|
|
1849
|
+
|
|
1850
|
+
#### `UseListRouteResult`
|
|
1851
|
+
|
|
1852
|
+
What {@link useListRoute} returns: each list field as a readable store, the actions as plain functions.
|
|
1853
|
+
|
|
1854
|
+
```typescript
|
|
1855
|
+
interface UseListRouteResult<Filter extends string = string, Selection extends string = string> {
|
|
1856
|
+
/** The current 1-indexed page. */
|
|
1857
|
+
page: Readable<number>
|
|
1858
|
+
/** The configured items per page. */
|
|
1859
|
+
pageSize: Readable<number>
|
|
1860
|
+
/** The zero-indexed item offset for an API request. */
|
|
1861
|
+
offset: Readable<number>
|
|
1862
|
+
/** The current URL filter values, including values supplied by path parameters. */
|
|
1863
|
+
filters: Readable<Record<Filter, string | undefined>>
|
|
1864
|
+
/** The matching view, or the configured fallback. */
|
|
1865
|
+
selection: Readable<Selection | undefined>
|
|
1866
|
+
/** The decoded current path parameters, also usable as API-only filters. */
|
|
1867
|
+
params: Readable<RouteParams>
|
|
1868
|
+
/** False while a protected selection is awaiting auth, signed out, or unavailable. */
|
|
1869
|
+
canLoad: Readable<boolean>
|
|
1870
|
+
/** Readiness for the current view; a public view always stays ready. */
|
|
1871
|
+
status: Readable<ListRouteResult<Filter, Selection>['status']>
|
|
1872
|
+
/** The sign-in destination while a signed-out protected view is being redirected. */
|
|
1873
|
+
redirectTo: Readable<string | undefined>
|
|
1874
|
+
/** Builds a real link target, preserving the pathname, unrelated query values and hash. */
|
|
1875
|
+
href: ListRouteResult<Filter, Selection>['href']
|
|
1876
|
+
/** Navigates atomically; location state is preserved unless options replace it. */
|
|
1877
|
+
navigate: ListRouteResult<Filter, Selection>['navigate']
|
|
1878
|
+
/** Changes only the page, retaining the current filters and view. */
|
|
1879
|
+
setPage: ListRouteResult<Filter, Selection>['setPage']
|
|
1880
|
+
/** Patches URL filters and returns to page one. */
|
|
1881
|
+
setFilters: ListRouteResult<Filter, Selection>['setFilters']
|
|
1882
|
+
/** Selects a configured view at page one. */
|
|
1883
|
+
select: ListRouteResult<Filter, Selection>['select']
|
|
1884
|
+
}
|
|
1885
|
+
```
|
|
1886
|
+
|
|
1887
|
+
#### `UseSignupResult`
|
|
1888
|
+
|
|
1889
|
+
What {@link useSignup} returns.
|
|
1890
|
+
|
|
1891
|
+
```typescript
|
|
1892
|
+
interface UseSignupResult<
|
|
1893
|
+
T = unknown,
|
|
1894
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
1895
|
+
> {
|
|
1896
|
+
/** The latest call's status. */
|
|
1897
|
+
status: Readable<UsePromiseState<AuthResult<T>>['status']>
|
|
1898
|
+
/** The latest call's resolved value. */
|
|
1899
|
+
value: Readable<UsePromiseState<AuthResult<T>>['value']>
|
|
1900
|
+
/** The latest call's rejection. */
|
|
1901
|
+
error: Readable<UsePromiseState<AuthResult<T>>['error']>
|
|
1902
|
+
/** Runs the signup. */
|
|
1903
|
+
signup: (data: RegisterData<TRegister>) => Promise<AuthResult<T>>
|
|
1904
|
+
/** Returns the tracker to idle. */
|
|
1905
|
+
reset: () => void
|
|
1906
|
+
}
|
|
1907
|
+
```
|
|
1908
|
+
|
|
1909
|
+
#### `UseStorageValueOptions`
|
|
1910
|
+
|
|
1911
|
+
Options for {@link useStorageValue}.
|
|
1912
|
+
|
|
1913
|
+
```typescript
|
|
1914
|
+
interface UseStorageValueOptions<T> {
|
|
1915
|
+
/**
|
|
1916
|
+
* Default value if key doesn't exist.
|
|
1917
|
+
*/
|
|
1918
|
+
defaultValue?: T
|
|
1919
|
+
/**
|
|
1920
|
+
* Whether to sync across tabs/windows (if supported by storage provider).
|
|
1921
|
+
*/
|
|
1922
|
+
sync?: boolean
|
|
1923
|
+
}
|
|
1924
|
+
```
|
|
1925
|
+
|
|
1926
|
+
#### `UseStorageValueResult`
|
|
1927
|
+
|
|
1928
|
+
Result of {@link useStorageValue}.
|
|
1929
|
+
|
|
1930
|
+
```typescript
|
|
1931
|
+
interface UseStorageValueResult<T> {
|
|
1932
|
+
/** The stored value, or the default while none is stored. */
|
|
1933
|
+
value: Readable<T | undefined>
|
|
1934
|
+
/** Persists the value; rejects when the provider refuses the write. */
|
|
1935
|
+
setValue: (value: T) => Promise<void>
|
|
1936
|
+
/** Removes the key and falls back to the default; rejects on failure. */
|
|
1937
|
+
removeValue: () => Promise<void>
|
|
1938
|
+
/** Whether the first read is still in flight. */
|
|
1939
|
+
loading: Readable<boolean>
|
|
1940
|
+
/** The failing read's or write's error. */
|
|
1941
|
+
error: Readable<Error | null>
|
|
1261
1942
|
}
|
|
1262
1943
|
```
|
|
1263
1944
|
|
|
1264
|
-
#### `
|
|
1945
|
+
#### `UseStoragePreferenceOptions`
|
|
1946
|
+
|
|
1947
|
+
Options for {@link useStoragePreference}.
|
|
1948
|
+
|
|
1949
|
+
```typescript
|
|
1950
|
+
interface UseStoragePreferenceOptions<T> {
|
|
1951
|
+
/**
|
|
1952
|
+
* Value reported until the provider supplies one. It is NEVER written to
|
|
1953
|
+
* storage: a default is a display fallback, not a decision the user made.
|
|
1954
|
+
*/
|
|
1955
|
+
defaultValue?: T
|
|
1956
|
+
}
|
|
1957
|
+
```
|
|
1958
|
+
|
|
1959
|
+
#### `UseStoragePreferenceResult`
|
|
1960
|
+
|
|
1961
|
+
Result of {@link useStoragePreference}.
|
|
1962
|
+
|
|
1963
|
+
```typescript
|
|
1964
|
+
interface UseStoragePreferenceResult<T> {
|
|
1965
|
+
/** The persisted value, or `defaultValue` while none is known. */
|
|
1966
|
+
value: Readable<T | undefined>
|
|
1967
|
+
/**
|
|
1968
|
+
* Writes the value through the preference store: subscribers update
|
|
1969
|
+
* immediately and persistence is best-effort.
|
|
1970
|
+
*/
|
|
1971
|
+
setValue: (next: T | ((previous: T | undefined) => T)) => void
|
|
1972
|
+
/** Removes the key through the preference store. */
|
|
1973
|
+
removeValue: () => void
|
|
1974
|
+
/**
|
|
1975
|
+
* `true` once the store has a definite answer — the synchronous snapshot on
|
|
1976
|
+
* a synchronous provider, or the hydration result on an asynchronous one.
|
|
1977
|
+
*/
|
|
1978
|
+
ready: Readable<boolean>
|
|
1979
|
+
}
|
|
1980
|
+
```
|
|
1981
|
+
|
|
1982
|
+
#### `UseStoreOptions`
|
|
1983
|
+
|
|
1984
|
+
Options for {@link useStore}.
|
|
1985
|
+
|
|
1986
|
+
```typescript
|
|
1987
|
+
interface UseStoreOptions<T, S> {
|
|
1988
|
+
/** Selects part of the state. */
|
|
1989
|
+
selector?: (state: T) => S
|
|
1990
|
+
/** Compares two selected values; equal keeps the previous result. */
|
|
1991
|
+
equalityFn?: (a: S, b: S) => boolean
|
|
1992
|
+
}
|
|
1993
|
+
```
|
|
1994
|
+
|
|
1995
|
+
#### `UseThemeResult`
|
|
1996
|
+
|
|
1997
|
+
What {@link useTheme} returns.
|
|
1998
|
+
|
|
1999
|
+
```typescript
|
|
2000
|
+
interface UseThemeResult {
|
|
2001
|
+
/** The current theme object. */
|
|
2002
|
+
theme: Readable<Theme>
|
|
2003
|
+
/** The current theme's name. */
|
|
2004
|
+
themeName: Readable<string>
|
|
2005
|
+
/** Switches the active theme by name. */
|
|
2006
|
+
setTheme: (name: string) => void
|
|
2007
|
+
/** Toggles light/dark (the provider's `toggleMode`, or an index cycle). */
|
|
2008
|
+
toggleTheme: () => void
|
|
2009
|
+
/** The current mode: 'light' or 'dark'. */
|
|
2010
|
+
mode: Readable<'light' | 'dark'>
|
|
2011
|
+
}
|
|
2012
|
+
```
|
|
2013
|
+
|
|
2014
|
+
#### `UseTranslationResult`
|
|
2015
|
+
|
|
2016
|
+
What {@link useTranslation} returns: the locale-reactive values as readable
|
|
2017
|
+
stores and the provider's functions as plain functions.
|
|
2018
|
+
|
|
2019
|
+
```typescript
|
|
2020
|
+
interface UseTranslationResult {
|
|
2021
|
+
/**
|
|
2022
|
+
* Translates a key in the active locale. A call made while markup, `$derived` or an
|
|
2023
|
+
* effect evaluates re-runs on every locale switch (like React's `t`, which is
|
|
2024
|
+
* rebuilt on every locale change), so `{t('key', {}, { defaultValue })}` needs no
|
|
2025
|
+
* store read beside it.
|
|
2026
|
+
*/
|
|
2027
|
+
t: I18nProvider['t']
|
|
2028
|
+
/** The active locale code. */
|
|
2029
|
+
locale: Readable<string>
|
|
2030
|
+
/** Switches the active locale. */
|
|
2031
|
+
setLocale: I18nProvider['setLocale']
|
|
2032
|
+
/** The registered locales. */
|
|
2033
|
+
locales: Readable<ReturnType<I18nProvider['getLocales']>>
|
|
2034
|
+
/** Formats a number for the active locale. */
|
|
2035
|
+
formatNumber: I18nProvider['formatNumber']
|
|
2036
|
+
/** Formats a date for the active locale. */
|
|
2037
|
+
formatDate: I18nProvider['formatDate']
|
|
2038
|
+
/** The active locale's text direction. */
|
|
2039
|
+
direction: Readable<'ltr' | 'rtl'>
|
|
2040
|
+
}
|
|
2041
|
+
```
|
|
2042
|
+
|
|
2043
|
+
#### `UseVerifyPaymentReturnOptions`
|
|
2044
|
+
|
|
2045
|
+
Options for {@link useVerifyPaymentReturn}.
|
|
2046
|
+
|
|
2047
|
+
```typescript
|
|
2048
|
+
interface UseVerifyPaymentReturnOptions {
|
|
2049
|
+
/**
|
|
2050
|
+
* Provider name to verify with, when the return URL carries no `provider`
|
|
2051
|
+
* query parameter. Leave unset to verify only what the URL names.
|
|
2052
|
+
*/
|
|
2053
|
+
provider?: string
|
|
2054
|
+
|
|
2055
|
+
/** Set `false` to skip verification entirely (e.g. behind a feature flag). */
|
|
2056
|
+
enabled?: boolean
|
|
2057
|
+
|
|
2058
|
+
/**
|
|
2059
|
+
* Remove the provider's query parameters from the address bar once the
|
|
2060
|
+
* purchase is verified, so a reload (or a shared link) cannot replay the
|
|
2061
|
+
* verification. Defaults to `true`.
|
|
2062
|
+
*/
|
|
2063
|
+
cleanUrl?: boolean
|
|
2064
|
+
|
|
2065
|
+
/** Called once, after the purchase verifies. */
|
|
2066
|
+
onVerified?: () => void
|
|
2067
|
+
|
|
2068
|
+
/** Called when verification fails. */
|
|
2069
|
+
onError?: (error: Error) => void
|
|
2070
|
+
}
|
|
2071
|
+
```
|
|
2072
|
+
|
|
2073
|
+
#### `UseVerifyPaymentReturnResult`
|
|
2074
|
+
|
|
2075
|
+
State of the post-checkout verification.
|
|
2076
|
+
|
|
2077
|
+
```typescript
|
|
2078
|
+
interface UseVerifyPaymentReturnResult {
|
|
2079
|
+
/**
|
|
2080
|
+
* `idle` when this page load is not a checkout return (no transaction id in
|
|
2081
|
+
* the URL) or auth is still hydrating; `verifying` while the API call is in
|
|
2082
|
+
* flight; then `verified` or `failed`.
|
|
2083
|
+
*/
|
|
2084
|
+
status: Readable<VerifyPaymentReturnStatus>
|
|
2085
|
+
|
|
2086
|
+
/** `true` when the URL identifies a purchase to verify. */
|
|
2087
|
+
isReturn: Readable<boolean>
|
|
2088
|
+
|
|
2089
|
+
/** The provider named by the URL (or the `provider` option). */
|
|
2090
|
+
provider: Readable<string | null>
|
|
2091
|
+
|
|
2092
|
+
/** The provider transaction/session id read from the URL. */
|
|
2093
|
+
transactionId: Readable<string | null>
|
|
2094
|
+
|
|
2095
|
+
/** Why verification failed, when it did. */
|
|
2096
|
+
error: Readable<Error | null>
|
|
2097
|
+
|
|
2098
|
+
/** Re-run the verification — wire this to a retry button. */
|
|
2099
|
+
retry: () => void
|
|
2100
|
+
}
|
|
2101
|
+
```
|
|
2102
|
+
|
|
2103
|
+
#### `UseVersionResult`
|
|
2104
|
+
|
|
2105
|
+
Hook return type.
|
|
2106
|
+
|
|
2107
|
+
```typescript
|
|
2108
|
+
interface UseVersionResult {
|
|
2109
|
+
/** The provider's full state. */
|
|
2110
|
+
state: Readable<VersionState>
|
|
2111
|
+
/** Whether an update is available. */
|
|
2112
|
+
isUpdateAvailable: Readable<boolean>
|
|
2113
|
+
/** Whether a check is running. */
|
|
2114
|
+
isChecking: Readable<boolean>
|
|
2115
|
+
/** Whether a service worker waits to activate. */
|
|
2116
|
+
isServiceWorkerWaiting: Readable<boolean>
|
|
2117
|
+
/** The version an available update reports. */
|
|
2118
|
+
newVersion: Readable<string | undefined>
|
|
2119
|
+
/** Checks the provider for an update. */
|
|
2120
|
+
checkForUpdates: () => Promise<boolean>
|
|
2121
|
+
/** Applies an available update. */
|
|
2122
|
+
applyUpdate: (options?: { force?: boolean }) => void
|
|
2123
|
+
/** Hides an available update. */
|
|
2124
|
+
dismissUpdate: () => void
|
|
2125
|
+
/** Starts polling the provider for updates. */
|
|
2126
|
+
startPeriodicChecks: (options?: UpdateCheckOptions) => void
|
|
2127
|
+
/** Stops the polling. */
|
|
2128
|
+
stopPeriodicChecks: () => void
|
|
2129
|
+
}
|
|
2130
|
+
```
|
|
2131
|
+
|
|
2132
|
+
#### `UseWorkspaceResult`
|
|
2133
|
+
|
|
2134
|
+
Hook result for useWorkspace: the layout fields as readable stores and the
|
|
2135
|
+
layout actions as plain functions.
|
|
2136
|
+
|
|
2137
|
+
```typescript
|
|
2138
|
+
interface UseWorkspaceResult {
|
|
2139
|
+
/** The panel layout. */
|
|
2140
|
+
layout: Readable<WorkspaceLayout>
|
|
2141
|
+
/** The panel showing the keyboard focus, if any. */
|
|
2142
|
+
activePanel: Readable<PanelId | null>
|
|
2143
|
+
/** The panels collapsed. */
|
|
2144
|
+
collapsedPanels: Readable<Set<PanelId>>
|
|
2145
|
+
/** Shows or hides a panel. */
|
|
2146
|
+
togglePanel: (panelId: PanelId) => void
|
|
2147
|
+
/** Resizes a panel. */
|
|
2148
|
+
resizePanel: (panelId: PanelId, size: number) => void
|
|
2149
|
+
/** Focuses a panel. */
|
|
2150
|
+
setActivePanel: (panelId: PanelId) => void
|
|
2151
|
+
/** Restores the provider's default layout. */
|
|
2152
|
+
resetLayout: () => void
|
|
2153
|
+
}
|
|
2154
|
+
```
|
|
2155
|
+
|
|
2156
|
+
#### `AsyncStateStore`
|
|
2157
|
+
|
|
2158
|
+
Async state store.
|
|
2159
|
+
|
|
2160
|
+
```typescript
|
|
2161
|
+
interface AsyncStateStore<T> extends Writable<T> {
|
|
2162
|
+
setState: (value: T | ((prev: T) => T) | Promise<T | ((prev: T) => T)>) => void
|
|
2163
|
+
extendState: (
|
|
2164
|
+
partial:
|
|
2165
|
+
Partial<T> | ((prev: T) => Partial<T>) | Promise<Partial<T> | ((prev: T) => Partial<T>)>,
|
|
2166
|
+
) => void
|
|
2167
|
+
}
|
|
2168
|
+
```
|
|
2169
|
+
|
|
2170
|
+
#### `OAuthOptions`
|
|
2171
|
+
|
|
2172
|
+
OAuth configuration options.
|
|
2173
|
+
|
|
2174
|
+
```typescript
|
|
2175
|
+
interface OAuthOptions {
|
|
2176
|
+
/** Base URL for the API server (e.g. `https://api.example.com`). */
|
|
2177
|
+
baseURL?: string
|
|
2178
|
+
/** List of supported OAuth provider names (e.g. `['google', 'github']`). */
|
|
2179
|
+
oauthProviders?: string[]
|
|
2180
|
+
/** Path prefix for OAuth initiation routes. Defaults to `/oauth`. */
|
|
2181
|
+
oauthEndpoint?: string
|
|
2182
|
+
/** Path for the OAuth login POST endpoint. Defaults to `/users/log-in/oauth`. */
|
|
2183
|
+
loginEndpoint?: string
|
|
2184
|
+
/** Callback fired after a successful OAuth login. */
|
|
2185
|
+
onSuccess?: () => void
|
|
2186
|
+
/** Callback fired with an error message when the OAuth login fails. */
|
|
2187
|
+
onError?: (error: string) => void
|
|
2188
|
+
/**
|
|
2189
|
+
* Explicit auth client used to establish the session after the callback
|
|
2190
|
+
* exchange. Defaults to the client in Svelte context (only resolvable when
|
|
2191
|
+
* called during component initialization) — pass one explicitly for
|
|
2192
|
+
* callers/tests outside a component/context.
|
|
2193
|
+
*/
|
|
2194
|
+
authClient?: AuthClient<unknown>
|
|
2195
|
+
}
|
|
2196
|
+
```
|
|
2197
|
+
|
|
2198
|
+
#### `OAuthHelpers`
|
|
2199
|
+
|
|
2200
|
+
OAuth helpers returned by {@link createOAuthHelpers}.
|
|
2201
|
+
|
|
2202
|
+
```typescript
|
|
2203
|
+
interface OAuthHelpers {
|
|
2204
|
+
/** Readable store of available OAuth provider names. */
|
|
2205
|
+
providers: Readable<string[]>
|
|
2206
|
+
/** Builds the OAuth initiation URL for a provider. */
|
|
2207
|
+
getOAuthUrl: (provider: string) => string
|
|
2208
|
+
/** Full-page redirect to the provider's OAuth initiation endpoint. */
|
|
2209
|
+
redirect: (provider: string) => void
|
|
2210
|
+
/**
|
|
2211
|
+
* Handles an OAuth callback: when the current URL carries a `code` param and
|
|
2212
|
+
* a provider was stashed by {@link redirect}, exchanges the code for a
|
|
2213
|
+
* session. A guarded no-op otherwise. Runs automatically when
|
|
2214
|
+
* {@link createOAuthHelpers} is called in a browser; exposed for manual
|
|
2215
|
+
* invocation (e.g. tests or custom callback screens).
|
|
2216
|
+
*/
|
|
2217
|
+
handleCallback: () => Promise<void>
|
|
2218
|
+
}
|
|
2219
|
+
```
|
|
2220
|
+
|
|
2221
|
+
#### `PasswordResetStores`
|
|
2222
|
+
|
|
2223
|
+
Password reset stores.
|
|
2224
|
+
|
|
2225
|
+
```typescript
|
|
2226
|
+
interface PasswordResetStores {
|
|
2227
|
+
request: Readable<PromiseState<void>> & {
|
|
2228
|
+
call: (data: PasswordResetRequest) => Promise<void>
|
|
2229
|
+
cancel: (message?: string) => void
|
|
2230
|
+
reset: () => void
|
|
2231
|
+
}
|
|
2232
|
+
confirm: Readable<PromiseState<void>> & {
|
|
2233
|
+
call: (data: PasswordResetConfirm) => Promise<void>
|
|
2234
|
+
cancel: (message?: string) => void
|
|
2235
|
+
reset: () => void
|
|
2236
|
+
}
|
|
2237
|
+
resetAll: () => void
|
|
2238
|
+
}
|
|
2239
|
+
```
|
|
2240
|
+
|
|
2241
|
+
#### `PromiseStore`
|
|
2242
|
+
|
|
2243
|
+
Promise store with action methods.
|
|
2244
|
+
|
|
2245
|
+
```typescript
|
|
2246
|
+
interface PromiseStore<T> extends Readable<PromiseState<T>> {
|
|
2247
|
+
call: (...args: any[]) => Promise<T>
|
|
2248
|
+
cancel: (message?: string) => void
|
|
2249
|
+
reset: () => void
|
|
2250
|
+
}
|
|
2251
|
+
```
|
|
2252
|
+
|
|
2253
|
+
#### `MoleculeConfig`
|
|
2254
|
+
|
|
2255
|
+
Configuration for molecule Svelte context.
|
|
2256
|
+
|
|
2257
|
+
```typescript
|
|
2258
|
+
interface MoleculeConfig {
|
|
2259
|
+
state?: StateProvider
|
|
2260
|
+
auth?: AuthClient<unknown>
|
|
2261
|
+
theme?: ThemeProvider
|
|
2262
|
+
router?: Router
|
|
2263
|
+
i18n?: I18nProvider
|
|
2264
|
+
http?: HttpClient
|
|
2265
|
+
storage?: StorageProvider
|
|
2266
|
+
logger?: LoggerProvider
|
|
2267
|
+
/** The AI chat provider useChat and useChatProvider use. */
|
|
2268
|
+
chat?: ChatProvider
|
|
2269
|
+
/** The IDE workspace provider useWorkspace and useWorkspaceProvider use. */
|
|
2270
|
+
workspace?: WorkspaceProvider
|
|
2271
|
+
/** The code editor provider useEditor and useEditorProvider use. */
|
|
2272
|
+
editor?: EditorProvider
|
|
2273
|
+
/** The live preview provider usePreview and usePreviewProvider use. */
|
|
2274
|
+
preview?: PreviewProvider
|
|
2275
|
+
}
|
|
2276
|
+
```
|
|
2277
|
+
|
|
2278
|
+
#### `SessionReadyProps`
|
|
2279
|
+
|
|
2280
|
+
Props for the `SessionReady` component: its `children` snippet renders once
|
|
2281
|
+
the auth client has decided the session, `fallback` until then.
|
|
2282
|
+
|
|
2283
|
+
```typescript
|
|
2284
|
+
interface SessionReadyProps {
|
|
2285
|
+
/** What renders once the initial restore settles — signed in, signed out, or unavailable. */
|
|
2286
|
+
children?: Snippet
|
|
2287
|
+
/** What renders while the session restore is still undecided; default nothing. */
|
|
2288
|
+
fallback?: Snippet
|
|
2289
|
+
}
|
|
2290
|
+
```
|
|
2291
|
+
|
|
2292
|
+
#### `HttpState`
|
|
2293
|
+
|
|
2294
|
+
State for async HTTP operations.
|
|
2295
|
+
|
|
2296
|
+
```typescript
|
|
2297
|
+
interface HttpState<T> {
|
|
2298
|
+
data: T | null
|
|
2299
|
+
loading: boolean
|
|
2300
|
+
error: Error | null
|
|
2301
|
+
}
|
|
2302
|
+
```
|
|
2303
|
+
|
|
2304
|
+
#### `StorageValueState`
|
|
2305
|
+
|
|
2306
|
+
State for async storage values.
|
|
2307
|
+
|
|
2308
|
+
```typescript
|
|
2309
|
+
interface StorageValueState<T> {
|
|
2310
|
+
value: T | undefined
|
|
2311
|
+
loading: boolean
|
|
2312
|
+
error: Error | null
|
|
2313
|
+
}
|
|
2314
|
+
```
|
|
2315
|
+
|
|
2316
|
+
### Types
|
|
2317
|
+
|
|
2318
|
+
#### `RouteParams`
|
|
2319
|
+
|
|
2320
|
+
URL path parameter key-value map extracted from dynamic route segments (e.g. `{ id: '123' }`).
|
|
2321
|
+
|
|
2322
|
+
```typescript
|
|
2323
|
+
type RouteParams = Record<string, string>
|
|
2324
|
+
```
|
|
2325
|
+
|
|
2326
|
+
#### `QueryParams`
|
|
2327
|
+
|
|
2328
|
+
URL query string parameter map (single values or arrays for repeated keys).
|
|
2329
|
+
|
|
2330
|
+
```typescript
|
|
2331
|
+
type QueryParams = Record<string, string | string[] | undefined>
|
|
2332
|
+
```
|
|
2333
|
+
|
|
2334
|
+
#### `AgentIdentity`
|
|
2335
|
+
|
|
2336
|
+
Display identity for the AI coding agent and the host product, used to
|
|
2337
|
+
interpolate the `{{agentName}}` / `{{productName}}` tokens in shared chat/IDE
|
|
2338
|
+
copy. A consuming app sets these to its own agent + product brand names; the
|
|
2339
|
+
shared packages fall back to {@link DEFAULT_AGENT_IDENTITY} when it does not.
|
|
2340
|
+
|
|
2341
|
+
```typescript
|
|
2342
|
+
type AgentIdentity = ChatAgentIdentity
|
|
2343
|
+
```
|
|
2344
|
+
|
|
2345
|
+
#### `AsyncSetState`
|
|
2346
|
+
|
|
2347
|
+
Async-capable setState function.
|
|
2348
|
+
|
|
2349
|
+
```typescript
|
|
2350
|
+
type AsyncSetState<T> = (
|
|
2351
|
+
value: T | ((prev: T) => T) | Promise<T | ((prev: T) => T)>,
|
|
2352
|
+
) => Promise<void>
|
|
2353
|
+
```
|
|
2354
|
+
|
|
2355
|
+
- `T` — The state type.
|
|
2356
|
+
|
|
2357
|
+
#### `AsyncExtendState`
|
|
2358
|
+
|
|
2359
|
+
Async-capable extendState function for partial updates.
|
|
2360
|
+
|
|
2361
|
+
```typescript
|
|
2362
|
+
type AsyncExtendState<T> = (
|
|
2363
|
+
partial: Partial<T> | ((prev: T) => Partial<T>) | Promise<Partial<T> | ((prev: T) => Partial<T>)>,
|
|
2364
|
+
) => Promise<void>
|
|
2365
|
+
```
|
|
2366
|
+
|
|
2367
|
+
- `T` — The state type.
|
|
2368
|
+
|
|
2369
|
+
#### `UseAsyncStateStore`
|
|
2370
|
+
|
|
2371
|
+
The store {@link useAsyncState} returns: the current
|
|
2372
|
+
`[state, setState, extendState]` tuple.
|
|
2373
|
+
|
|
2374
|
+
```typescript
|
|
2375
|
+
type UseAsyncStateStore<T> = Readable<readonly [T, AsyncSetState<T>, AsyncExtendState<T>]>
|
|
2376
|
+
```
|
|
2377
|
+
|
|
2378
|
+
#### `UseCapacitorAppResult`
|
|
2379
|
+
|
|
2380
|
+
Hook return type.
|
|
2381
|
+
|
|
2382
|
+
```typescript
|
|
2383
|
+
type UseCapacitorAppResult = {
|
|
2384
|
+
/** Whether the app is fully initialized. */
|
|
2385
|
+
ready: Readable<boolean>
|
|
2386
|
+
/** Whether device ready has fired. */
|
|
2387
|
+
deviceReady: Readable<boolean>
|
|
2388
|
+
/** Whether push notifications are initialized. */
|
|
2389
|
+
pushReady: Readable<boolean>
|
|
2390
|
+
/** The initialization error, if any. */
|
|
2391
|
+
error: Readable<Error | null>
|
|
2392
|
+
} & {
|
|
2393
|
+
/** Runs the coordinator's initialization again. */
|
|
2394
|
+
initialize: () => Promise<void>
|
|
2395
|
+
}
|
|
2396
|
+
```
|
|
2397
|
+
|
|
2398
|
+
#### `UsePromiseStore`
|
|
2399
|
+
|
|
2400
|
+
The store {@link usePromise} returns: the current `[state, call]` tuple.
|
|
2401
|
+
|
|
2402
|
+
```typescript
|
|
2403
|
+
type UsePromiseStore<T, A extends unknown[]> = Readable<
|
|
2404
|
+
readonly [UsePromiseState<T>, (...args: A) => Promise<T>]
|
|
2405
|
+
>
|
|
2406
|
+
```
|
|
2407
|
+
|
|
2408
|
+
#### `UseConsumedSearchParamStore`
|
|
2409
|
+
|
|
2410
|
+
The store {@link useConsumedSearchParam} returns: the current `[value, set]` tuple.
|
|
2411
|
+
|
|
2412
|
+
```typescript
|
|
2413
|
+
type UseConsumedSearchParamStore = Readable<readonly [string, (value: string) => void]>
|
|
2414
|
+
```
|
|
2415
|
+
|
|
2416
|
+
#### `UseTShorthandOptions`
|
|
2417
|
+
|
|
2418
|
+
Options for the shorthand form of {@link UseTFunction}: the fallback text
|
|
2419
|
+
is passed positionally, so only `count` remains here.
|
|
2420
|
+
|
|
2421
|
+
```typescript
|
|
2422
|
+
type UseTShorthandOptions = Omit<TranslateOptions, 'defaultValue'>
|
|
2423
|
+
```
|
|
2424
|
+
|
|
2425
|
+
#### `UseTFunction`
|
|
2426
|
+
|
|
2427
|
+
Translation function returned by `useT()`.
|
|
2428
|
+
|
|
2429
|
+
Two compatible call forms:
|
|
2430
|
+
|
|
2431
|
+
- `t(key, values?, options?)` — the provider's signature.
|
|
2432
|
+
- `t(key, fallback, options?)` — a string second argument is the inline
|
|
2433
|
+
English `defaultValue`, with optional `count` for pluralization.
|
|
2434
|
+
|
|
2435
|
+
```typescript
|
|
2436
|
+
type UseTFunction = I18nProvider['t'] & {
|
|
2437
|
+
(key: string, fallback: string, options?: UseTShorthandOptions): string
|
|
2438
|
+
}
|
|
2439
|
+
```
|
|
2440
|
+
|
|
2441
|
+
#### `VerifyPaymentReturnStatus`
|
|
2442
|
+
|
|
2443
|
+
How far the return-page verification has got.
|
|
2444
|
+
|
|
2445
|
+
```typescript
|
|
2446
|
+
type VerifyPaymentReturnStatus = 'idle' | 'verifying' | 'verified' | 'failed'
|
|
2447
|
+
```
|
|
2448
|
+
|
|
2449
|
+
#### `CapacitorAppStore`
|
|
2450
|
+
|
|
2451
|
+
Return type for the Capacitor app store.
|
|
2452
|
+
|
|
2453
|
+
```typescript
|
|
2454
|
+
type CapacitorAppStore = Readable<CapacitorAppState> & {
|
|
2455
|
+
initialize: () => Promise<void>
|
|
2456
|
+
}
|
|
2457
|
+
```
|
|
2458
|
+
|
|
2459
|
+
#### `ChangePasswordStore`
|
|
2460
|
+
|
|
2461
|
+
Change password store type.
|
|
2462
|
+
|
|
2463
|
+
```typescript
|
|
2464
|
+
type ChangePasswordStore = PromiseStore<void>
|
|
2465
|
+
```
|
|
2466
|
+
|
|
2467
|
+
#### `UseChatOptions`
|
|
2468
|
+
|
|
2469
|
+
Options for {@link useChat} (the shared chat session's options).
|
|
2470
|
+
|
|
2471
|
+
```typescript
|
|
2472
|
+
type UseChatOptions = ChatSessionOptions
|
|
2473
|
+
```
|
|
2474
|
+
|
|
2475
|
+
#### `SendMessageOptions`
|
|
2476
|
+
|
|
2477
|
+
Options for one `sendMessage` call.
|
|
2478
|
+
|
|
2479
|
+
```typescript
|
|
2480
|
+
type SendMessageOptions = ChatSendOptions
|
|
2481
|
+
```
|
|
2482
|
+
|
|
2483
|
+
#### `UseChatResult`
|
|
2484
|
+
|
|
2485
|
+
What {@link useChat} returns: each chat state field as a readable store,
|
|
2486
|
+
and the session's controls as plain functions (stable for the component's life).
|
|
2487
|
+
|
|
2488
|
+
```typescript
|
|
2489
|
+
type UseChatResult = {
|
|
2490
|
+
readonly [K in keyof ChatSessionState]: Readable<ChatSessionState[K]>
|
|
2491
|
+
} & ChatSessionControls
|
|
2492
|
+
```
|
|
2493
|
+
|
|
2494
|
+
#### `LoginStore`
|
|
2495
|
+
|
|
2496
|
+
Login store type.
|
|
2497
|
+
|
|
2498
|
+
```typescript
|
|
2499
|
+
type LoginStore<T = unknown> = PromiseStore<AuthResult<T>>
|
|
2500
|
+
```
|
|
2501
|
+
|
|
2502
|
+
#### `SignupStore`
|
|
2503
|
+
|
|
2504
|
+
Signup store type.
|
|
2505
|
+
|
|
2506
|
+
```typescript
|
|
2507
|
+
type SignupStore<T = unknown> = PromiseStore<AuthResult<T>>
|
|
2508
|
+
```
|
|
2509
|
+
|
|
2510
|
+
### Functions
|
|
2511
|
+
|
|
2512
|
+
#### `setMoleculeContext(config)`
|
|
2513
|
+
|
|
2514
|
+
Set all molecule providers in Svelte context.
|
|
2515
|
+
|
|
2516
|
+
Call this in your root layout/component.
|
|
2517
|
+
|
|
2518
|
+
```typescript
|
|
2519
|
+
function setMoleculeContext(config: MoleculeConfig): void
|
|
2520
|
+
```
|
|
2521
|
+
|
|
2522
|
+
- `config` — Provider instances to register (state, auth, theme, router, i18n, http, storage, logger, chat, workspace, editor, preview).
|
|
2523
|
+
|
|
2524
|
+
#### `setStateContext(provider)`
|
|
2525
|
+
|
|
2526
|
+
Sets the state context.
|
|
2527
|
+
|
|
2528
|
+
```typescript
|
|
2529
|
+
function setStateContext(provider: StateProvider): void
|
|
2530
|
+
```
|
|
2531
|
+
|
|
2532
|
+
- `provider` — The state provider to store in Svelte context.
|
|
2533
|
+
|
|
2534
|
+
#### `setAuthContext(client)`
|
|
2535
|
+
|
|
2536
|
+
Sets the auth context.
|
|
2537
|
+
|
|
2538
|
+
```typescript
|
|
2539
|
+
function setAuthContext<T>(client: AuthClient<T>): void
|
|
2540
|
+
```
|
|
2541
|
+
|
|
2542
|
+
- `client` — The auth client to store in Svelte context.
|
|
2543
|
+
|
|
2544
|
+
#### `setThemeContext(provider)`
|
|
2545
|
+
|
|
2546
|
+
Sets the theme context.
|
|
2547
|
+
|
|
2548
|
+
```typescript
|
|
2549
|
+
function setThemeContext(provider: ThemeProvider): void
|
|
2550
|
+
```
|
|
2551
|
+
|
|
2552
|
+
- `provider` — The theme provider to store in Svelte context.
|
|
2553
|
+
|
|
2554
|
+
#### `setRouterContext(router)`
|
|
2555
|
+
|
|
2556
|
+
Sets the router context.
|
|
2557
|
+
|
|
2558
|
+
```typescript
|
|
2559
|
+
function setRouterContext(router: Router): void
|
|
2560
|
+
```
|
|
2561
|
+
|
|
2562
|
+
- `router` — The router instance to store in Svelte context.
|
|
2563
|
+
|
|
2564
|
+
#### `setI18nContext(provider)`
|
|
2565
|
+
|
|
2566
|
+
Sets the i18n context.
|
|
2567
|
+
|
|
2568
|
+
```typescript
|
|
2569
|
+
function setI18nContext(provider: I18nProvider): void
|
|
2570
|
+
```
|
|
2571
|
+
|
|
2572
|
+
- `provider` — The i18n provider to store in Svelte context.
|
|
2573
|
+
|
|
2574
|
+
#### `setHttpContext(client)`
|
|
2575
|
+
|
|
2576
|
+
Sets the HTTP context.
|
|
2577
|
+
|
|
2578
|
+
```typescript
|
|
2579
|
+
function setHttpContext(client: HttpClient): void
|
|
2580
|
+
```
|
|
2581
|
+
|
|
2582
|
+
- `client` — The HTTP client to store in Svelte context.
|
|
2583
|
+
|
|
2584
|
+
#### `setStorageContext(provider)`
|
|
2585
|
+
|
|
2586
|
+
Sets the storage context.
|
|
2587
|
+
|
|
2588
|
+
```typescript
|
|
2589
|
+
function setStorageContext(provider: StorageProvider): void
|
|
2590
|
+
```
|
|
2591
|
+
|
|
2592
|
+
- `provider` — The storage provider to store in Svelte context.
|
|
2593
|
+
|
|
2594
|
+
#### `setLoggerContext(provider)`
|
|
2595
|
+
|
|
2596
|
+
Sets the logger context.
|
|
2597
|
+
|
|
2598
|
+
```typescript
|
|
2599
|
+
function setLoggerContext(provider: LoggerProvider): void
|
|
2600
|
+
```
|
|
2601
|
+
|
|
2602
|
+
- `provider` — The logger provider to store in Svelte context.
|
|
2603
|
+
|
|
2604
|
+
#### `setChatContext(provider)`
|
|
2605
|
+
|
|
2606
|
+
Sets the AI chat context.
|
|
2607
|
+
|
|
2608
|
+
```typescript
|
|
2609
|
+
function setChatContext(provider: ChatProvider): void
|
|
2610
|
+
```
|
|
2611
|
+
|
|
2612
|
+
- `provider` — The chat provider to store in Svelte context.
|
|
2613
|
+
|
|
2614
|
+
#### `setWorkspaceContext(provider)`
|
|
2615
|
+
|
|
2616
|
+
Sets the IDE workspace context.
|
|
2617
|
+
|
|
2618
|
+
```typescript
|
|
2619
|
+
function setWorkspaceContext(provider: WorkspaceProvider): void
|
|
2620
|
+
```
|
|
2621
|
+
|
|
2622
|
+
- `provider` — The workspace provider to store in Svelte context.
|
|
2623
|
+
|
|
2624
|
+
#### `setEditorContext(provider)`
|
|
2625
|
+
|
|
2626
|
+
Sets the code editor context.
|
|
2627
|
+
|
|
2628
|
+
```typescript
|
|
2629
|
+
function setEditorContext(provider: EditorProvider): void
|
|
2630
|
+
```
|
|
2631
|
+
|
|
2632
|
+
- `provider` — The editor provider to store in Svelte context.
|
|
2633
|
+
|
|
2634
|
+
#### `setPreviewContext(provider)`
|
|
2635
|
+
|
|
2636
|
+
Sets the live preview context.
|
|
2637
|
+
|
|
2638
|
+
```typescript
|
|
2639
|
+
function setPreviewContext(provider: PreviewProvider): void
|
|
2640
|
+
```
|
|
2641
|
+
|
|
2642
|
+
- `provider` — The preview provider to store in Svelte context.
|
|
2643
|
+
|
|
2644
|
+
#### `getStateProvider()`
|
|
2645
|
+
|
|
2646
|
+
Gets the state provider from Svelte context.
|
|
2647
|
+
|
|
2648
|
+
```typescript
|
|
2649
|
+
function getStateProvider(): StateProvider
|
|
2650
|
+
```
|
|
2651
|
+
|
|
2652
|
+
**Returns:** The state provider instance.
|
|
2653
|
+
|
|
2654
|
+
#### `getAuthClient()`
|
|
2655
|
+
|
|
2656
|
+
Gets the auth client from Svelte context.
|
|
2657
|
+
|
|
2658
|
+
```typescript
|
|
2659
|
+
function getAuthClient<
|
|
2660
|
+
T = unknown,
|
|
2661
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
2662
|
+
>(): AuthClient<T, TRegister>
|
|
2663
|
+
```
|
|
2664
|
+
|
|
2665
|
+
**Returns:** The auth client instance.
|
|
2666
|
+
|
|
2667
|
+
#### `getThemeProvider()`
|
|
2668
|
+
|
|
2669
|
+
Gets the theme provider from Svelte context.
|
|
2670
|
+
|
|
2671
|
+
```typescript
|
|
2672
|
+
function getThemeProvider(): ThemeProvider
|
|
2673
|
+
```
|
|
2674
|
+
|
|
2675
|
+
**Returns:** The theme provider instance.
|
|
2676
|
+
|
|
2677
|
+
#### `getRouter()`
|
|
2678
|
+
|
|
2679
|
+
Gets the router from Svelte context.
|
|
2680
|
+
|
|
2681
|
+
```typescript
|
|
2682
|
+
function getRouter(): Router
|
|
2683
|
+
```
|
|
2684
|
+
|
|
2685
|
+
**Returns:** The router instance.
|
|
2686
|
+
|
|
2687
|
+
#### `getI18nProvider()`
|
|
2688
|
+
|
|
2689
|
+
Gets the i18n provider from Svelte context.
|
|
2690
|
+
|
|
2691
|
+
```typescript
|
|
2692
|
+
function getI18nProvider(): I18nProvider
|
|
2693
|
+
```
|
|
2694
|
+
|
|
2695
|
+
**Returns:** The i18n provider instance.
|
|
2696
|
+
|
|
2697
|
+
#### `getHttpClient()`
|
|
2698
|
+
|
|
2699
|
+
Gets the HTTP client from Svelte context.
|
|
2700
|
+
|
|
2701
|
+
```typescript
|
|
2702
|
+
function getHttpClient(): HttpClient
|
|
2703
|
+
```
|
|
2704
|
+
|
|
2705
|
+
**Returns:** The HTTP client instance.
|
|
2706
|
+
|
|
2707
|
+
#### `getStorageProvider()`
|
|
2708
|
+
|
|
2709
|
+
Gets the storage provider from Svelte context.
|
|
2710
|
+
|
|
2711
|
+
```typescript
|
|
2712
|
+
function getStorageProvider(): StorageProvider
|
|
2713
|
+
```
|
|
2714
|
+
|
|
2715
|
+
**Returns:** The storage provider instance.
|
|
2716
|
+
|
|
2717
|
+
#### `getLoggerProvider()`
|
|
2718
|
+
|
|
2719
|
+
Gets the logger provider from Svelte context.
|
|
2720
|
+
|
|
2721
|
+
```typescript
|
|
2722
|
+
function getLoggerProvider(): LoggerProvider
|
|
2723
|
+
```
|
|
2724
|
+
|
|
2725
|
+
**Returns:** The logger provider instance.
|
|
2726
|
+
|
|
2727
|
+
#### `useChatProvider()`
|
|
2728
|
+
|
|
2729
|
+
Gets the AI chat provider from Svelte context (`setMoleculeContext({ chat })`).
|
|
2730
|
+
|
|
2731
|
+
```typescript
|
|
2732
|
+
function useChatProvider(): ChatProvider
|
|
2733
|
+
```
|
|
2734
|
+
|
|
2735
|
+
**Returns:** The chat provider instance.
|
|
2736
|
+
|
|
2737
|
+
#### `useWorkspaceProvider()`
|
|
2738
|
+
|
|
2739
|
+
Gets the IDE workspace provider from Svelte context
|
|
2740
|
+
(`setMoleculeContext({ workspace })`).
|
|
2741
|
+
|
|
2742
|
+
```typescript
|
|
2743
|
+
function useWorkspaceProvider(): WorkspaceProvider
|
|
2744
|
+
```
|
|
2745
|
+
|
|
2746
|
+
**Returns:** The workspace provider instance.
|
|
2747
|
+
|
|
2748
|
+
#### `useEditorProvider()`
|
|
2749
|
+
|
|
2750
|
+
Gets the code editor provider from Svelte context
|
|
2751
|
+
(`setMoleculeContext({ editor })`).
|
|
2752
|
+
|
|
2753
|
+
```typescript
|
|
2754
|
+
function useEditorProvider(): EditorProvider
|
|
2755
|
+
```
|
|
2756
|
+
|
|
2757
|
+
**Returns:** The editor provider instance.
|
|
2758
|
+
|
|
2759
|
+
#### `usePreviewProvider()`
|
|
2760
|
+
|
|
2761
|
+
Gets the live preview provider from Svelte context
|
|
2762
|
+
(`setMoleculeContext({ preview })`).
|
|
2763
|
+
|
|
2764
|
+
```typescript
|
|
2765
|
+
function usePreviewProvider(): PreviewProvider
|
|
2766
|
+
```
|
|
2767
|
+
|
|
2768
|
+
**Returns:** The preview provider instance.
|
|
2769
|
+
|
|
2770
|
+
#### `useAuthClient(T, TRegister)`
|
|
2771
|
+
|
|
2772
|
+
Gets the auth client from Svelte context under the React hook's name
|
|
2773
|
+
(`setMoleculeContext({ auth })`).
|
|
2774
|
+
|
|
2775
|
+
```typescript
|
|
2776
|
+
function useAuthClient<
|
|
2777
|
+
T = unknown,
|
|
2778
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
2779
|
+
>(): AuthClient<T, TRegister>
|
|
2780
|
+
```
|
|
2781
|
+
|
|
2782
|
+
- `T` — The user profile the API returns.
|
|
2783
|
+
- `TRegister` — The app's own registration fields.
|
|
2784
|
+
|
|
2785
|
+
**Returns:** The auth client instance.
|
|
2786
|
+
|
|
2787
|
+
#### `useI18nProvider()`
|
|
2788
|
+
|
|
2789
|
+
Gets the i18n provider: the one the nearest `setMoleculeContext({ i18n })`
|
|
2790
|
+
supplies, otherwise the bonded `@molecule/app-i18n` provider, which is the
|
|
2791
|
+
one the static `t` reads — React's `useI18nProvider` contract. A component
|
|
2792
|
+
can therefore translate through {@link useTranslation} wherever the static
|
|
2793
|
+
`t` works, and it re-renders when the locale changes.
|
|
2794
|
+
|
|
2795
|
+
```typescript
|
|
2796
|
+
function useI18nProvider(): I18nProvider
|
|
2797
|
+
```
|
|
2798
|
+
|
|
2799
|
+
**Returns:** The i18n provider from context, or the bonded provider.
|
|
2800
|
+
|
|
2801
|
+
#### `useThemeProvider()`
|
|
2802
|
+
|
|
2803
|
+
Gets the theme provider from Svelte context under the React hook's name.
|
|
2804
|
+
|
|
2805
|
+
```typescript
|
|
2806
|
+
function useThemeProvider(): ThemeProvider
|
|
2807
|
+
```
|
|
2808
|
+
|
|
2809
|
+
**Returns:** The theme provider instance.
|
|
2810
|
+
|
|
2811
|
+
#### `useRouterInstance()`
|
|
2812
|
+
|
|
2813
|
+
Gets the router from Svelte context under the React hook's name.
|
|
2814
|
+
|
|
2815
|
+
```typescript
|
|
2816
|
+
function useRouterInstance(): Router
|
|
2817
|
+
```
|
|
2818
|
+
|
|
2819
|
+
**Returns:** The router instance.
|
|
2820
|
+
|
|
2821
|
+
#### `useHttpClient()`
|
|
2822
|
+
|
|
2823
|
+
Gets the HTTP client from Svelte context under the React hook's name.
|
|
2824
|
+
|
|
2825
|
+
```typescript
|
|
2826
|
+
function useHttpClient(): HttpClient
|
|
2827
|
+
```
|
|
2828
|
+
|
|
2829
|
+
**Returns:** The HTTP client instance.
|
|
2830
|
+
|
|
2831
|
+
#### `useStorageProvider()`
|
|
2832
|
+
|
|
2833
|
+
Gets the storage provider from Svelte context under the React hook's name.
|
|
2834
|
+
|
|
2835
|
+
```typescript
|
|
2836
|
+
function useStorageProvider(): StorageProvider
|
|
2837
|
+
```
|
|
2838
|
+
|
|
2839
|
+
**Returns:** The storage provider instance.
|
|
2840
|
+
|
|
2841
|
+
#### `useLoggerProvider()`
|
|
2842
|
+
|
|
2843
|
+
Gets the logger provider from Svelte context under the React hook's name.
|
|
2844
|
+
|
|
2845
|
+
```typescript
|
|
2846
|
+
function useLoggerProvider(): LoggerProvider
|
|
2847
|
+
```
|
|
2848
|
+
|
|
2849
|
+
**Returns:** The logger provider instance.
|
|
2850
|
+
|
|
2851
|
+
#### `useStateProvider()`
|
|
2852
|
+
|
|
2853
|
+
Gets the state provider from Svelte context under the React hook's name.
|
|
2854
|
+
|
|
2855
|
+
Only hooks that read the context call this; `useStore(store)` takes its
|
|
2856
|
+
store as an argument and works with no provider at all.
|
|
2857
|
+
|
|
2858
|
+
```typescript
|
|
2859
|
+
function useStateProvider(): StateProvider
|
|
2860
|
+
```
|
|
2861
|
+
|
|
2862
|
+
**Returns:** The state provider instance.
|
|
2863
|
+
|
|
2864
|
+
#### `resetAIModelsCache()`
|
|
2865
|
+
|
|
2866
|
+
Test-only: drops every cached model list so the next `useAIModels` call
|
|
2867
|
+
refetches. Exposed for unit tests; do not call from production code.
|
|
2868
|
+
|
|
2869
|
+
```typescript
|
|
2870
|
+
function resetAIModelsCache(): void
|
|
2871
|
+
```
|
|
2872
|
+
|
|
2873
|
+
#### `useAIModels(projectId)`
|
|
2874
|
+
|
|
2875
|
+
Subscribes to the cached AI model catalog, React's `useAIModels` in Svelte's
|
|
2876
|
+
idiom: call it during component init under `setMoleculeContext({ http })`.
|
|
2877
|
+
The first mount of a scope triggers a single `GET /ai/models` fetch;
|
|
2878
|
+
subsequent mounts return the cached result, and a scope whose fetch failed
|
|
2879
|
+
does not refetch on a later mount.
|
|
2880
|
+
|
|
2881
|
+
```typescript
|
|
2882
|
+
function useAIModels(projectId?: string): UseAIModelsResult
|
|
2883
|
+
```
|
|
2884
|
+
|
|
2885
|
+
- `projectId` — Optional project scope: includes that project's custom ("bring your own AI") models on servers that support them.
|
|
2886
|
+
|
|
2887
|
+
**Returns:** Models, free-tier model, loading flag, and error, as stores.
|
|
2888
|
+
|
|
2889
|
+
#### `useAsyncState(initialState)`
|
|
2890
|
+
|
|
2891
|
+
State that accepts Promises and partial updates, React's `useAsyncState` in
|
|
2892
|
+
Svelte's idiom: a readable store of the `[state, setState, extendState]`
|
|
2893
|
+
tuple.
|
|
2894
|
+
|
|
2895
|
+
Like React's, this has NO latest-wins guard: a promise that settles after a
|
|
2896
|
+
newer synchronous set overwrites it — whatever settles last wins. Rejections
|
|
2897
|
+
of resolved promises are silently swallowed (React's deliberate behavior),
|
|
2898
|
+
leaving the previous state in place.
|
|
2899
|
+
|
|
2900
|
+
```typescript
|
|
2901
|
+
function useAsyncState<T>(initialState: T): UseAsyncStateStore<T>
|
|
2902
|
+
```
|
|
2903
|
+
|
|
2904
|
+
- `initialState` — Initial state value.
|
|
2905
|
+
|
|
2906
|
+
**Returns:** A readable store of the [state, setState, extendState] tuple.
|
|
2907
|
+
|
|
2908
|
+
#### `useAuth(options)`
|
|
2909
|
+
|
|
2910
|
+
Authentication state and actions, React's `useAuth` in Svelte's idiom: call
|
|
2911
|
+
it during component init under `setMoleculeContext({ auth })`.
|
|
2912
|
+
|
|
2913
|
+
`status === 'loading'` is undecided: wait for it and redirect only on
|
|
2914
|
+
`status === 'unauthenticated'`. `'unavailable'` keeps the session candidate
|
|
2915
|
+
(and may keep a cached user) for retry; a restore failure other than 401/403
|
|
2916
|
+
never signs out. Save profile edits with `updateProfile(patch)`; an
|
|
2917
|
+
app-owned mutation instead passes its canonical response to `setUser`. For
|
|
2918
|
+
a sign-in the app itself runs, call `setSession({ accessToken, user })`.
|
|
2919
|
+
|
|
2920
|
+
```typescript
|
|
2921
|
+
function useAuth<
|
|
2922
|
+
T = unknown,
|
|
2923
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
2924
|
+
>(options?: UseAuthOptions): UseAuthResult<T, TRegister>
|
|
2925
|
+
```
|
|
2926
|
+
|
|
2927
|
+
- `options` — Hook options (`autoRefresh`).
|
|
2928
|
+
|
|
2929
|
+
**Returns:** Auth state as stores and the actions as functions.
|
|
2930
|
+
|
|
2931
|
+
#### `useUser(T)`
|
|
2932
|
+
|
|
2933
|
+
The authenticated user, React's `useUser` in Svelte's idiom: a readable
|
|
2934
|
+
store of the cached profile (or null).
|
|
2935
|
+
|
|
2936
|
+
```typescript
|
|
2937
|
+
function useUser<T = unknown>(): Readable<T | null>
|
|
2938
|
+
```
|
|
2939
|
+
|
|
2940
|
+
- `T` — The user profile the API returns.
|
|
2941
|
+
|
|
2942
|
+
**Returns:** A readable store of the authenticated user or null.
|
|
2943
|
+
|
|
2944
|
+
#### `useIsAuthenticated()`
|
|
2945
|
+
|
|
2946
|
+
Whether a session is authenticated, React's `useIsAuthenticated` in
|
|
2947
|
+
Svelte's idiom.
|
|
2948
|
+
|
|
2949
|
+
```typescript
|
|
2950
|
+
function useIsAuthenticated(): Readable<boolean>
|
|
2951
|
+
```
|
|
2952
|
+
|
|
2953
|
+
**Returns:** A readable store of whether a session exists.
|
|
2954
|
+
|
|
2955
|
+
#### `useCapacitorApp(options)`
|
|
2956
|
+
|
|
2957
|
+
Capacitor app initialization state and actions, React's `useCapacitorApp` in
|
|
2958
|
+
Svelte's idiom: called during component init, one coordinator per hook
|
|
2959
|
+
instance whose state fields are readable stores and whose `initialize` is a
|
|
2960
|
+
plain function.
|
|
2961
|
+
|
|
2962
|
+
Creates the `CapacitorApp` coordinator during init, subscribes its state and
|
|
2963
|
+
auto-initializes (the way React's mount effect does); the component's
|
|
2964
|
+
destroy unsubscribes and calls `destroy()`, releasing the coordinator's
|
|
2965
|
+
deep-link subscription. Init errors land in the `error` store through the
|
|
2966
|
+
coordinator's own state, so the auto-init rejection is swallowed there.
|
|
2967
|
+
|
|
2968
|
+
```typescript
|
|
2969
|
+
function useCapacitorApp(options?: CapacitorAppOptions): UseCapacitorAppResult
|
|
2970
|
+
```
|
|
2971
|
+
|
|
2972
|
+
- `options` — Capacitor app configuration options
|
|
2973
|
+
|
|
2974
|
+
**Returns:** Current app state stores and an `initialize` function for manual re-initialization
|
|
2975
|
+
|
|
2976
|
+
#### `useChangePassword()`
|
|
2977
|
+
|
|
2978
|
+
Password change with async state tracking, React's `useChangePassword` in
|
|
2979
|
+
Svelte's idiom: call it during component init under
|
|
2980
|
+
`setMoleculeContext({ auth })`. There is no `value` field — the call
|
|
2981
|
+
resolves `void`.
|
|
2982
|
+
|
|
2983
|
+
```typescript
|
|
2984
|
+
function useChangePassword(): UseChangePasswordResult
|
|
2985
|
+
```
|
|
2986
|
+
|
|
2987
|
+
**Returns:** Change-password state as stores and the action.
|
|
2988
|
+
|
|
2989
|
+
#### `useDevice()`
|
|
2990
|
+
|
|
2991
|
+
Device information and utility methods, React's `useDevice` in Svelte's
|
|
2992
|
+
idiom: called during component init; device info is static, so the result is
|
|
2993
|
+
a plain object (nothing reactive).
|
|
2994
|
+
|
|
2995
|
+
Uses module-level `getProvider()` — device info is a singleton, not
|
|
2996
|
+
context-provided.
|
|
2997
|
+
|
|
2998
|
+
```typescript
|
|
2999
|
+
function useDevice(): UseDeviceResult
|
|
3000
|
+
```
|
|
3001
|
+
|
|
3002
|
+
**Returns:** Device information and utility methods.
|
|
3003
|
+
|
|
3004
|
+
#### `useEditor()`
|
|
3005
|
+
|
|
3006
|
+
Code editor management, React's `useEditor` in Svelte's idiom: call it
|
|
3007
|
+
during component init under `setMoleculeContext({ editor })`.
|
|
3008
|
+
|
|
3009
|
+
`tabs` and `activeFile` always come from the provider's own tab list:
|
|
3010
|
+
`activeFile` is the path of the tab marked `isActive`, or `null` when no
|
|
3011
|
+
tab is. They are read at mount (tabs opened before the component mounted
|
|
3012
|
+
show at once), on every provider change event, and after each action that
|
|
3013
|
+
changes the tab list (`openFile`, `closeFile`, `setActiveTab`, `openDiff`,
|
|
3014
|
+
`closeDiff`, `pinTab`).
|
|
3015
|
+
|
|
3016
|
+
```typescript
|
|
3017
|
+
function useEditor(): UseEditorResult
|
|
3018
|
+
```
|
|
3019
|
+
|
|
3020
|
+
**Returns:** Editor state stores and controls.
|
|
3021
|
+
|
|
3022
|
+
#### `useForm(options)`
|
|
3023
|
+
|
|
3024
|
+
Hook for form state management, React's `useForm` in Svelte's idiom: call it
|
|
3025
|
+
during component init (no provider needed — the controller comes from the
|
|
3026
|
+
bonded forms provider).
|
|
3027
|
+
|
|
3028
|
+
Creates its controller through the bonded forms provider, so an app wires a
|
|
3029
|
+
form library once (`setProvider` from `@molecule/app-forms`) and every form
|
|
3030
|
+
picks it up. Passing `createForm` overrides that for one form. When the
|
|
3031
|
+
`values` option changes by content, it becomes the new baseline;
|
|
3032
|
+
`resetOptions.keepDirtyValues` retains edited fields while pristine fields
|
|
3033
|
+
take the loaded values. A changed `resetKey` starts a fresh form; fresh
|
|
3034
|
+
`defaultValues` without one leave the drafts alone.
|
|
3035
|
+
|
|
3036
|
+
```typescript
|
|
3037
|
+
function useForm<T extends FormValuesConstraint<T> = Record<string, unknown>>(
|
|
3038
|
+
options?: UseFormOptions<T>,
|
|
3039
|
+
): UseFormResult<T>
|
|
3040
|
+
```
|
|
3041
|
+
|
|
3042
|
+
- `options` — Form options. `defaultValues`, `mode` and the form-level `validate` are forwarded to the provider.
|
|
3043
|
+
|
|
3044
|
+
**Returns:** Form state stores and methods
|
|
3045
|
+
|
|
3046
|
+
#### `useWatch(form, name)`
|
|
3047
|
+
|
|
3048
|
+
Hook to watch a specific field value, React's `useWatch` in Svelte's idiom:
|
|
3049
|
+
a readable store of the field's current value.
|
|
3050
|
+
|
|
3051
|
+
```typescript
|
|
3052
|
+
function useWatch<T extends FormValuesConstraint<T>, K extends keyof T>(
|
|
3053
|
+
form: FormController<T>,
|
|
3054
|
+
name: K,
|
|
3055
|
+
): Readable<T[K]>
|
|
3056
|
+
```
|
|
3057
|
+
|
|
3058
|
+
- `form` — Form controller
|
|
3059
|
+
- `name` — Field name to watch
|
|
3060
|
+
|
|
3061
|
+
**Returns:** A readable store of the current field value
|
|
3062
|
+
|
|
3063
|
+
#### `useFieldState(form, name)`
|
|
3064
|
+
|
|
3065
|
+
Hook to get field-level state, React's `useFieldState` in Svelte's idiom: a
|
|
3066
|
+
readable store of the field's state.
|
|
3067
|
+
|
|
3068
|
+
```typescript
|
|
3069
|
+
function useFieldState<T extends FormValuesConstraint<T>>(
|
|
3070
|
+
form: FormController<T>,
|
|
3071
|
+
name: keyof T,
|
|
3072
|
+
): Readable<FieldState<T[keyof T]>>
|
|
3073
|
+
```
|
|
3074
|
+
|
|
3075
|
+
- `form` — Form controller
|
|
3076
|
+
- `name` — Field name
|
|
3077
|
+
|
|
3078
|
+
**Returns:** A readable store of the field state (value, error, touched, dirty, valid, validating)
|
|
3079
|
+
|
|
3080
|
+
#### `useHttp(method, url, options)`
|
|
3081
|
+
|
|
3082
|
+
HTTP requests with state management, React's `useHttp` in Svelte's idiom:
|
|
3083
|
+
call it during component init under `setMoleculeContext({ http })`.
|
|
3084
|
+
|
|
3085
|
+
The newest request owns the displayed state: an older response answering
|
|
3086
|
+
after a newer `execute` or `reset` cannot touch it (callbacks still report
|
|
3087
|
+
every request's own outcome). A failure resolves `null` — it never rejects
|
|
3088
|
+
to the caller. `reset` takes ownership too, so a request it superseded
|
|
3089
|
+
cannot repopulate the state. `execute` keeps one identity per mount, and its
|
|
3090
|
+
options are read at call time. `immediate` runs its request once per host,
|
|
3091
|
+
on mount only, even when the host re-mounts the hook with new arguments.
|
|
3092
|
+
|
|
3093
|
+
```typescript
|
|
3094
|
+
function useHttp<T>(
|
|
3095
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
|
|
3096
|
+
url: string,
|
|
3097
|
+
options?: UseHttpOptions<T>,
|
|
3098
|
+
): UseHttpResult<T>
|
|
3099
|
+
```
|
|
3100
|
+
|
|
3101
|
+
- `method` — HTTP method.
|
|
3102
|
+
- `url` — Request URL.
|
|
3103
|
+
- `options` — Request options, read at call time.
|
|
3104
|
+
|
|
3105
|
+
**Returns:** Request state as stores and the controls.
|
|
3106
|
+
|
|
3107
|
+
#### `useGet(url, options)`
|
|
3108
|
+
|
|
3109
|
+
GET requests, React's `useGet` in Svelte's idiom.
|
|
3110
|
+
|
|
3111
|
+
```typescript
|
|
3112
|
+
function useGet<T>(url: string, options?: UseHttpOptions<T>): UseHttpResult<T>
|
|
3113
|
+
```
|
|
3114
|
+
|
|
3115
|
+
- `url` — Request URL to fetch from.
|
|
3116
|
+
- `options` — HTTP request options including callbacks and request config.
|
|
3117
|
+
|
|
3118
|
+
**Returns:** Request state as stores and the controls.
|
|
3119
|
+
|
|
3120
|
+
#### `usePost(url, options)`
|
|
3121
|
+
|
|
3122
|
+
POST requests, React's `usePost` in Svelte's idiom.
|
|
3123
|
+
|
|
3124
|
+
```typescript
|
|
3125
|
+
function usePost<T>(url: string, options?: UseHttpOptions<T>): UseHttpResult<T>
|
|
3126
|
+
```
|
|
3127
|
+
|
|
3128
|
+
- `url` — Request URL to post to.
|
|
3129
|
+
- `options` — HTTP request options including body data and callbacks.
|
|
3130
|
+
|
|
3131
|
+
**Returns:** Request state as stores and the controls.
|
|
3132
|
+
|
|
3133
|
+
#### `usePut(url, options)`
|
|
3134
|
+
|
|
3135
|
+
PUT requests, React's `usePut` in Svelte's idiom.
|
|
3136
|
+
|
|
3137
|
+
```typescript
|
|
3138
|
+
function usePut<T>(url: string, options?: UseHttpOptions<T>): UseHttpResult<T>
|
|
3139
|
+
```
|
|
3140
|
+
|
|
3141
|
+
- `url` — Request URL to send the PUT request to.
|
|
3142
|
+
- `options` — HTTP request options including body data and callbacks.
|
|
3143
|
+
|
|
3144
|
+
**Returns:** Request state as stores and the controls.
|
|
3145
|
+
|
|
3146
|
+
#### `usePatch(url, options)`
|
|
3147
|
+
|
|
3148
|
+
PATCH requests, React's `usePatch` in Svelte's idiom.
|
|
3149
|
+
|
|
3150
|
+
```typescript
|
|
3151
|
+
function usePatch<T>(url: string, options?: UseHttpOptions<T>): UseHttpResult<T>
|
|
3152
|
+
```
|
|
3153
|
+
|
|
3154
|
+
- `url` — Request URL to send the PATCH request to.
|
|
3155
|
+
- `options` — HTTP request options including partial body data and callbacks.
|
|
3156
|
+
|
|
3157
|
+
**Returns:** Request state as stores and the controls.
|
|
3158
|
+
|
|
3159
|
+
#### `useDelete(url, options)`
|
|
3160
|
+
|
|
3161
|
+
DELETE requests, React's `useDelete` in Svelte's idiom.
|
|
3162
|
+
|
|
3163
|
+
```typescript
|
|
3164
|
+
function useDelete<T>(url: string, options?: UseHttpOptions<T>): UseHttpResult<T>
|
|
3165
|
+
```
|
|
3166
|
+
|
|
3167
|
+
- `url` — Request URL of the resource to delete.
|
|
3168
|
+
- `options` — HTTP request options including callbacks.
|
|
3169
|
+
|
|
3170
|
+
**Returns:** Request state as stores and the controls.
|
|
3171
|
+
|
|
3172
|
+
#### `useLogger(name, config)`
|
|
3173
|
+
|
|
3174
|
+
Gets a logger instance, React's `useLogger` in Svelte's idiom: called during
|
|
3175
|
+
component init under `setMoleculeContext`, it returns the logger itself (a
|
|
3176
|
+
plain object — there is nothing reactive in a logger).
|
|
3177
|
+
|
|
3178
|
+
```typescript
|
|
3179
|
+
function useLogger(name: string, config?: Partial<LoggerConfig>): Logger
|
|
3180
|
+
```
|
|
3181
|
+
|
|
3182
|
+
- `name` — Logger name (usually component or module name).
|
|
3183
|
+
- `config` — Optional logger configuration.
|
|
3184
|
+
|
|
3185
|
+
**Returns:** Logger instance.
|
|
3186
|
+
|
|
3187
|
+
#### `useRootLogger()`
|
|
3188
|
+
|
|
3189
|
+
Gets the root logger, React's `useRootLogger` in Svelte's idiom: called
|
|
3190
|
+
during component init under `setMoleculeContext`.
|
|
3191
|
+
|
|
3192
|
+
```typescript
|
|
3193
|
+
function useRootLogger(): Logger
|
|
3194
|
+
```
|
|
3195
|
+
|
|
3196
|
+
**Returns:** Root logger instance.
|
|
3197
|
+
|
|
3198
|
+
#### `useChildLogger(parentName, context)`
|
|
3199
|
+
|
|
3200
|
+
Creates a child logger with additional context, React's `useChildLogger` in
|
|
3201
|
+
Svelte's idiom: called during component init under `setMoleculeContext`.
|
|
3202
|
+
|
|
3203
|
+
```typescript
|
|
3204
|
+
function useChildLogger(parentName: string, context: Record<string, unknown>): Logger
|
|
3205
|
+
```
|
|
3206
|
+
|
|
3207
|
+
- `parentName` — Parent logger name.
|
|
3208
|
+
- `context` — Additional context to include in logs.
|
|
3209
|
+
|
|
3210
|
+
**Returns:** Child logger instance.
|
|
3211
|
+
|
|
3212
|
+
#### `useLogin(T)`
|
|
3213
|
+
|
|
3214
|
+
Login with async state tracking, React's `useLogin` in Svelte's idiom:
|
|
3215
|
+
call it during component init under `setMoleculeContext({ auth })`.
|
|
3216
|
+
|
|
3217
|
+
Registration is available through `const { register } = useAuth()`;
|
|
3218
|
+
call `register({ email, password, name })` to create an account. There is
|
|
3219
|
+
no separate `useRegister` hook; use `usePromise(register)` when a form
|
|
3220
|
+
needs the same pending/error tracking as this login hook.
|
|
3221
|
+
|
|
3222
|
+
```typescript
|
|
3223
|
+
function useLogin<T = unknown>(): UseLoginResult<T>
|
|
3224
|
+
```
|
|
3225
|
+
|
|
3226
|
+
- `T` — The user profile the API returns.
|
|
3227
|
+
|
|
3228
|
+
**Returns:** Login state as stores and the action.
|
|
3229
|
+
|
|
3230
|
+
#### `useOAuth(config)`
|
|
3231
|
+
|
|
3232
|
+
OAuth authentication, React's `useOAuth` in Svelte's idiom: call it during
|
|
3233
|
+
component init under `setMoleculeContext({ auth })`. Reads OAuth
|
|
3234
|
+
configuration and provides helpers to build OAuth URLs and start a login
|
|
3235
|
+
(full-page or popup). Automatically handles OAuth callbacks by detecting
|
|
3236
|
+
`code` and `state` URL parameters and exchanging them for a session — and,
|
|
3237
|
+
when the callback is running inside a popup we opened, relaying the result
|
|
3238
|
+
to the opener instead.
|
|
3239
|
+
|
|
3240
|
+
```typescript
|
|
3241
|
+
function useOAuth(config?: UseOAuthConfig): UseOAuthReturn
|
|
3242
|
+
```
|
|
3243
|
+
|
|
3244
|
+
- `config` — Optional OAuth configuration override.
|
|
3245
|
+
|
|
3246
|
+
**Returns:** OAuth helpers: providers, getOAuthUrl, redirect, and loginViaPopup.
|
|
3247
|
+
|
|
3248
|
+
#### `useOptimisticValue(options)`
|
|
3249
|
+
|
|
3250
|
+
A server-backed value — a favorite, follow, like or bookmark button, a
|
|
3251
|
+
rating, a quantity, a setting switch — that changes on the first render
|
|
3252
|
+
after a tap and is saved one change at a time, in order. See
|
|
3253
|
+
`createOptimisticValue` in `@molecule/app-state`, under React's hook name.
|
|
3254
|
+
|
|
3255
|
+
A new server `value` is taken only when it differs (by `equals`) from the
|
|
3256
|
+
one the hook last received, and only while nothing is being saved, so a
|
|
3257
|
+
refetch of older data never flips the button mid-save. The latest `commit`
|
|
3258
|
+
and `onError` are always used. Give the component a `key` per record, so one
|
|
3259
|
+
record's pending change never shows on another. Keep related fields, such as
|
|
3260
|
+
a favorite flag and its count, in the SAME value. Let commit reject on
|
|
3261
|
+
failure: a catch that returns old data hides the failure.
|
|
3262
|
+
|
|
3263
|
+
```typescript
|
|
3264
|
+
function useOptimisticValue<T>(options: OptimisticValueOptions<T>): UseOptimisticValueResult<T>
|
|
3265
|
+
```
|
|
3266
|
+
|
|
3267
|
+
- `options` — The server's current value and how to save a change.
|
|
3268
|
+
|
|
3269
|
+
**Returns:** The value to render, whether a save is pending, the newest failure, and `set`/`update`.
|
|
3270
|
+
|
|
3271
|
+
#### `usePasswordReset()`
|
|
3272
|
+
|
|
3273
|
+
The password-reset flow with separate tracking for the request and confirm
|
|
3274
|
+
steps, React's `usePasswordReset` in Svelte's idiom: call it during
|
|
3275
|
+
component init under `setMoleculeContext({ auth })`.
|
|
3276
|
+
|
|
3277
|
+
```typescript
|
|
3278
|
+
function usePasswordReset(): UsePasswordResetResult
|
|
3279
|
+
```
|
|
3280
|
+
|
|
3281
|
+
**Returns:** Both steps' state as stores and their actions.
|
|
3282
|
+
|
|
3283
|
+
#### `usePlatform()`
|
|
3284
|
+
|
|
3285
|
+
Detected platform info plus the `isPlatform` helper, React's `usePlatform`
|
|
3286
|
+
in Svelte's idiom: called during component init; platform info is static, so
|
|
3287
|
+
the result is a plain object (nothing reactive).
|
|
3288
|
+
|
|
3289
|
+
Uses module-level functions — platform is a singleton, not context-provided.
|
|
3290
|
+
|
|
3291
|
+
```typescript
|
|
3292
|
+
function usePlatform(): UsePlatformResult
|
|
3293
|
+
```
|
|
3294
|
+
|
|
3295
|
+
**Returns:** Platform information and utility methods.
|
|
3296
|
+
|
|
3297
|
+
#### `usePreview()`
|
|
3298
|
+
|
|
3299
|
+
Live preview management, React's `usePreview` in Svelte's idiom: call it
|
|
3300
|
+
during component init under `setMoleculeContext({ preview })`.
|
|
3301
|
+
|
|
3302
|
+
The state is a snapshot store over `provider.subscribe`, cached field-wise
|
|
3303
|
+
the way React's `useSyncExternalStore` snapshot is, so a provider that
|
|
3304
|
+
answers fresh objects does not publish a new snapshot per read.
|
|
3305
|
+
|
|
3306
|
+
```typescript
|
|
3307
|
+
function usePreview(): UsePreviewResult
|
|
3308
|
+
```
|
|
3309
|
+
|
|
3310
|
+
**Returns:** Preview state store and controls.
|
|
3311
|
+
|
|
3312
|
+
#### `useProfileForm(options)`
|
|
3313
|
+
|
|
3314
|
+
Owns load → edit → submit → publish for the signed-in user's profile,
|
|
3315
|
+
React's `useProfileForm` in Svelte's idiom: call it during component init
|
|
3316
|
+
under `setMoleculeContext({ auth })`.
|
|
3317
|
+
|
|
3318
|
+
Same-account background updates refresh untouched fields but preserve dirty
|
|
3319
|
+
controls. Session ownership comes from the auth client, independently of
|
|
3320
|
+
mutable profile fields; an explicit getIdentity adds the caller's identity
|
|
3321
|
+
check. Submission snapshots the registered values before asynchronous
|
|
3322
|
+
validation, sends only changed fields through `toPatch`, and uses the auth
|
|
3323
|
+
client's configured updateProfile transport. The saved server response
|
|
3324
|
+
becomes the clean baseline; edits made while saving remain dirty. No request
|
|
3325
|
+
is made for a patch with no fields. A failed request retains the edits and
|
|
3326
|
+
shared user.
|
|
3327
|
+
|
|
3328
|
+
```typescript
|
|
3329
|
+
function useProfileForm<TUser, TValues extends FormValuesConstraint<TValues>>(
|
|
3330
|
+
options: UseProfileFormOptions<TUser, TValues>,
|
|
3331
|
+
): UseProfileFormResult<TUser, TValues>
|
|
3332
|
+
```
|
|
3333
|
+
|
|
3334
|
+
- `options` — Controlled defaults, identity and wire adapters, optional cache/navigation callback.
|
|
3335
|
+
|
|
3336
|
+
**Returns:** Form state stores, typed control bindings, native submit binding and save error store.
|
|
1265
3337
|
|
|
1266
|
-
|
|
3338
|
+
#### `usePromise(asyncFn)`
|
|
3339
|
+
|
|
3340
|
+
Wraps an async function with state tracking, React's `usePromise` in
|
|
3341
|
+
Svelte's idiom.
|
|
3342
|
+
|
|
3343
|
+
For one UI action, pass `$store[0].status === 'pending'` to `Button loading`
|
|
3344
|
+
from `@molecule/app-ui-svelte` (or disable a native control). The control
|
|
3345
|
+
then refuses input while the request is pending and re-enables when the
|
|
3346
|
+
tracked call settles. Handle the returned promise's rejection; the hook
|
|
3347
|
+
also records the failure in `state.error`.
|
|
3348
|
+
|
|
3349
|
+
This hook tracks the latest call: it does not serialize invocations or
|
|
3350
|
+
cancel their network requests. An explicit reset/cancel changes the tracked
|
|
3351
|
+
state, so it is not proof that an outstanding request has stopped. Use an
|
|
3352
|
+
app-owned queue when every click must be accepted in order.
|
|
3353
|
+
|
|
3354
|
+
The result is a readable store of the `[state, call]` tuple (React's tuple
|
|
3355
|
+
shape): `$store[0]` is the current state, `$store[1]` the tracked function.
|
|
3356
|
+
A pending call keeps the PREVIOUS `value`; a rejection records the error
|
|
3357
|
+
(keeping the previous `value`) and rethrows to its caller; `cancel(message?)`
|
|
3358
|
+
marks the state `rejected` with `new Error(message)` — or no error when no
|
|
3359
|
+
message is given; `reset()` returns to idle.
|
|
1267
3360
|
|
|
1268
3361
|
```typescript
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
/** Builds the OAuth initiation URL for a provider. */
|
|
1273
|
-
getOAuthUrl: (provider: string) => string
|
|
1274
|
-
/** Full-page redirect to the provider's OAuth initiation endpoint. */
|
|
1275
|
-
redirect: (provider: string) => void
|
|
1276
|
-
/**
|
|
1277
|
-
* Handles an OAuth callback: when the current URL carries a `code` param and
|
|
1278
|
-
* a provider was stashed by {@link redirect}, exchanges the code for a
|
|
1279
|
-
* session. A guarded no-op otherwise. Runs automatically when
|
|
1280
|
-
* {@link createOAuthHelpers} is called in a browser; exposed for manual
|
|
1281
|
-
* invocation (e.g. tests or custom callback screens).
|
|
1282
|
-
*/
|
|
1283
|
-
handleCallback: () => Promise<void>
|
|
1284
|
-
}
|
|
3362
|
+
function usePromise<T, A extends unknown[]>(
|
|
3363
|
+
asyncFn: (...args: A) => Promise<T>,
|
|
3364
|
+
): UsePromiseStore<T, A>
|
|
1285
3365
|
```
|
|
1286
3366
|
|
|
1287
|
-
|
|
3367
|
+
- `asyncFn` — The async function to wrap.
|
|
1288
3368
|
|
|
1289
|
-
|
|
3369
|
+
**Returns:** A readable store of the [state, wrappedFunction] tuple.
|
|
3370
|
+
|
|
3371
|
+
#### `usePush(options)`
|
|
3372
|
+
|
|
3373
|
+
Push notification state and actions, React's `usePush` in Svelte's idiom:
|
|
3374
|
+
called during component init, `permission` and `token` are readable stores
|
|
3375
|
+
the hook's own actions update, and the rest are plain functions.
|
|
3376
|
+
|
|
3377
|
+
Uses module-level `getProvider()` — push is a singleton, not
|
|
3378
|
+
context-provided. The provider's listeners are caller-managed: the returned
|
|
3379
|
+
`on*` unsubscribes are the caller's to call, like React's.
|
|
1290
3380
|
|
|
1291
3381
|
```typescript
|
|
1292
|
-
|
|
1293
|
-
request: Readable<PromiseState<void>> & {
|
|
1294
|
-
call: (data: PasswordResetRequest) => Promise<void>
|
|
1295
|
-
cancel: (message?: string) => void
|
|
1296
|
-
reset: () => void
|
|
1297
|
-
}
|
|
1298
|
-
confirm: Readable<PromiseState<void>> & {
|
|
1299
|
-
call: (data: PasswordResetConfirm) => Promise<void>
|
|
1300
|
-
cancel: (message?: string) => void
|
|
1301
|
-
reset: () => void
|
|
1302
|
-
}
|
|
1303
|
-
resetAll: () => void
|
|
1304
|
-
}
|
|
3382
|
+
function usePush(options?: UsePushOptions): UsePushResult
|
|
1305
3383
|
```
|
|
1306
3384
|
|
|
1307
|
-
|
|
3385
|
+
- `options` — Hook options
|
|
1308
3386
|
|
|
1309
|
-
|
|
3387
|
+
**Returns:** Push notification state and action methods
|
|
3388
|
+
|
|
3389
|
+
#### `useRouter()`
|
|
3390
|
+
|
|
3391
|
+
Routing state and navigation, React's `useRouter` in Svelte's idiom: call it
|
|
3392
|
+
during component init under `setMoleculeContext({ router })`.
|
|
1310
3393
|
|
|
1311
3394
|
```typescript
|
|
1312
|
-
|
|
1313
|
-
call: (...args: any[]) => Promise<T>
|
|
1314
|
-
cancel: (message?: string) => void
|
|
1315
|
-
reset: () => void
|
|
1316
|
-
}
|
|
3395
|
+
function useRouter(): UseRouterResult
|
|
1317
3396
|
```
|
|
1318
3397
|
|
|
1319
|
-
|
|
3398
|
+
**Returns:** Router state as stores and the navigation methods.
|
|
1320
3399
|
|
|
1321
|
-
|
|
3400
|
+
#### `useLocation()`
|
|
3401
|
+
|
|
3402
|
+
The current location, React's `useLocation` in Svelte's idiom.
|
|
1322
3403
|
|
|
1323
3404
|
```typescript
|
|
1324
|
-
|
|
1325
|
-
state?: StateProvider
|
|
1326
|
-
auth?: AuthClient<unknown>
|
|
1327
|
-
theme?: ThemeProvider
|
|
1328
|
-
router?: Router
|
|
1329
|
-
i18n?: I18nProvider
|
|
1330
|
-
http?: HttpClient
|
|
1331
|
-
storage?: StorageProvider
|
|
1332
|
-
logger?: LoggerProvider
|
|
1333
|
-
}
|
|
3405
|
+
function useLocation(): Readable<RouteLocation>
|
|
1334
3406
|
```
|
|
1335
3407
|
|
|
1336
|
-
|
|
3408
|
+
**Returns:** A readable store of the current route location.
|
|
1337
3409
|
|
|
1338
|
-
|
|
3410
|
+
#### `useParams(T)`
|
|
3411
|
+
|
|
3412
|
+
The current route's path parameters, React's `useParams` in Svelte's idiom.
|
|
1339
3413
|
|
|
1340
3414
|
```typescript
|
|
1341
|
-
|
|
1342
|
-
data: T | null
|
|
1343
|
-
loading: boolean
|
|
1344
|
-
error: Error | null
|
|
1345
|
-
}
|
|
3415
|
+
function useParams<T extends Record<string, string> = RouteParams>(): Readable<T>
|
|
1346
3416
|
```
|
|
1347
3417
|
|
|
1348
|
-
|
|
3418
|
+
- `T` — The params record type.
|
|
1349
3419
|
|
|
1350
|
-
|
|
3420
|
+
**Returns:** A readable store of the route parameters.
|
|
3421
|
+
|
|
3422
|
+
#### `useQuery(T)`
|
|
3423
|
+
|
|
3424
|
+
The current query parameters, React's `useQuery` in Svelte's idiom.
|
|
1351
3425
|
|
|
1352
3426
|
```typescript
|
|
1353
|
-
|
|
1354
|
-
value: T | undefined
|
|
1355
|
-
loading: boolean
|
|
1356
|
-
error: Error | null
|
|
1357
|
-
}
|
|
3427
|
+
function useQuery<T extends QueryParams = QueryParams>(): Readable<T>
|
|
1358
3428
|
```
|
|
1359
3429
|
|
|
1360
|
-
|
|
3430
|
+
- `T` — The query record type.
|
|
1361
3431
|
|
|
1362
|
-
|
|
3432
|
+
**Returns:** A readable store of the query parameters.
|
|
1363
3433
|
|
|
1364
|
-
|
|
3434
|
+
#### `useNavigate()`
|
|
3435
|
+
|
|
3436
|
+
The navigate function, React's `useNavigate` in Svelte's idiom.
|
|
1365
3437
|
|
|
1366
3438
|
```typescript
|
|
1367
|
-
|
|
3439
|
+
function useNavigate(): (path: string, options?: NavigateOptions) => void
|
|
1368
3440
|
```
|
|
1369
3441
|
|
|
1370
|
-
|
|
3442
|
+
**Returns:** A function that navigates to a path.
|
|
1371
3443
|
|
|
1372
|
-
|
|
3444
|
+
#### `useIsActive(path, exact)`
|
|
3445
|
+
|
|
3446
|
+
Whether a path is active, React's `useIsActive` in Svelte's idiom: a
|
|
3447
|
+
readable store that re-evaluates on every route change.
|
|
1373
3448
|
|
|
1374
3449
|
```typescript
|
|
1375
|
-
|
|
3450
|
+
function useIsActive(path: string, exact?: boolean): Readable<boolean>
|
|
1376
3451
|
```
|
|
1377
3452
|
|
|
1378
|
-
|
|
3453
|
+
- `path` — The path to check.
|
|
3454
|
+
- `exact` — Whether to match exactly (default: false).
|
|
1379
3455
|
|
|
1380
|
-
|
|
3456
|
+
**Returns:** A readable store of whether the path is active.
|
|
3457
|
+
|
|
3458
|
+
#### `useListRoute(options)`
|
|
3459
|
+
|
|
3460
|
+
URL-backed pagination, filters and selected views, React's `useListRoute` in
|
|
3461
|
+
Svelte's idiom: the page, the filters and the view live in the URL only, so a
|
|
3462
|
+
reload, a shared link and Back all show the same list. Each list field is a
|
|
3463
|
+
readable store that follows the location, and the actions are plain
|
|
3464
|
+
functions, through whichever routing bond the app wired. Built on
|
|
3465
|
+
`resolveListRoute` from `@molecule/app-routing`, so every framework binding
|
|
3466
|
+
returns the same result.
|
|
3467
|
+
|
|
3468
|
+
A signed-out visit to a view with `requiresAuth` replaces the entry with
|
|
3469
|
+
`options.auth.redirectTo`, carrying `state.returnTo`; until auth is confirmed
|
|
3470
|
+
`canLoad` is `false`.
|
|
3471
|
+
|
|
3472
|
+
The options may be a readable store: an auth status moving from `loading` to
|
|
3473
|
+
`unauthenticated` re-resolves the list — and performs the sign-in redirect —
|
|
3474
|
+
on the same component, the way React re-renders `useListRoute`.
|
|
1381
3475
|
|
|
1382
3476
|
```typescript
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
3477
|
+
function useListRoute<Filter extends string = string, Selection extends string = string>(
|
|
3478
|
+
options?: ListRouteOptions<Filter, Selection> | Readable<ListRouteOptions<Filter, Selection>>,
|
|
3479
|
+
): UseListRouteResult<Filter, Selection>
|
|
1386
3480
|
```
|
|
1387
3481
|
|
|
1388
|
-
|
|
3482
|
+
- `options` — Filter sources, view paths, pagination and optional auth readiness (or a store of them).
|
|
1389
3483
|
|
|
1390
|
-
|
|
3484
|
+
**Returns:** Each list field as a readable store, and its link builder and navigation actions.
|
|
3485
|
+
|
|
3486
|
+
#### `useConsumedSearchParam(name)`
|
|
3487
|
+
|
|
3488
|
+
Takes a one-time credential (a reset `token`, an OAuth `code`) out of the URL
|
|
3489
|
+
and keeps it in memory, React's `useConsumedSearchParam` in Svelte's idiom: a
|
|
3490
|
+
readable store of the `[value, set]` tuple, through whichever routing bond
|
|
3491
|
+
the app wired. The parameter is removed with a replace navigation that keeps
|
|
3492
|
+
the path, the hash, the other query values and the location state; the value
|
|
3493
|
+
survives re-renders and later query-only navigation, Back to an entry
|
|
3494
|
+
restores the value consumed there, and a new value arriving on the same
|
|
3495
|
+
mounted route is consumed too.
|
|
1391
3496
|
|
|
1392
3497
|
```typescript
|
|
1393
|
-
|
|
3498
|
+
function useConsumedSearchParam(name: string): UseConsumedSearchParamStore
|
|
1394
3499
|
```
|
|
1395
3500
|
|
|
1396
|
-
|
|
3501
|
+
- `name` — The query key to consume, for example `token` or `code`.
|
|
1397
3502
|
|
|
1398
|
-
|
|
3503
|
+
**Returns:** A readable store of the consumed value (`''` before the parameter was ever present) and a setter (a form clears it after a successful submit).
|
|
3504
|
+
|
|
3505
|
+
#### `useSignup(T, TRegister)`
|
|
3506
|
+
|
|
3507
|
+
User registration with async state tracking, React's `useSignup` in
|
|
3508
|
+
Svelte's idiom: call it during component init under
|
|
3509
|
+
`setMoleculeContext({ auth })`.
|
|
1399
3510
|
|
|
1400
3511
|
```typescript
|
|
1401
|
-
|
|
3512
|
+
function useSignup<
|
|
3513
|
+
T = unknown,
|
|
3514
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
3515
|
+
>(): UseSignupResult<T, TRegister>
|
|
1402
3516
|
```
|
|
1403
3517
|
|
|
1404
|
-
|
|
3518
|
+
- `T` — The user profile the API returns.
|
|
3519
|
+
- `TRegister` — The app's own registration fields.
|
|
1405
3520
|
|
|
1406
|
-
Signup
|
|
3521
|
+
**Returns:** Signup state as stores and the action.
|
|
3522
|
+
|
|
3523
|
+
#### `useStorageValue(key, options)`
|
|
3524
|
+
|
|
3525
|
+
One storage key as Svelte stores, React's `useStorageValue` in Svelte's
|
|
3526
|
+
idiom: call it during component init under `setMoleculeContext({ storage })`.
|
|
3527
|
+
|
|
3528
|
+
A read that started before a newer local write keeps that write's value (it
|
|
3529
|
+
still ends `loading`), and with `sync` an outside write reaches the hook
|
|
3530
|
+
through the provider's own subscription — so a non-browser backend
|
|
3531
|
+
(native, encrypted, memory) propagates the same way, not just the browser
|
|
3532
|
+
`storage` event.
|
|
1407
3533
|
|
|
1408
3534
|
```typescript
|
|
1409
|
-
|
|
3535
|
+
function useStorageValue<T>(
|
|
3536
|
+
key: string,
|
|
3537
|
+
options?: UseStorageValueOptions<T>,
|
|
3538
|
+
): UseStorageValueResult<T>
|
|
1410
3539
|
```
|
|
1411
3540
|
|
|
1412
|
-
|
|
3541
|
+
- `key` — Storage key
|
|
3542
|
+
- `options` — Hook options
|
|
1413
3543
|
|
|
1414
|
-
|
|
3544
|
+
**Returns:** Storage value state (value, loading, error) and mutators (setValue, removeValue).
|
|
1415
3545
|
|
|
1416
|
-
|
|
3546
|
+
#### `useStoragePreference(key, options)`
|
|
1417
3547
|
|
|
1418
|
-
|
|
3548
|
+
Subscribes Svelte stores to ONE persisted preference, React's
|
|
3549
|
+
`useStoragePreference` in Svelte's idiom.
|
|
3550
|
+
|
|
3551
|
+
This is the component-side half of `getPreferenceStore()`: an init-time
|
|
3552
|
+
value is available immediately when the bonded provider can answer
|
|
3553
|
+
synchronously, and an asynchronous provider's hydration CONVERGES onto the
|
|
3554
|
+
same component without a remount. Ordering is the store's: a read that
|
|
3555
|
+
started before a newer write, remove or external change is discarded, so a
|
|
3556
|
+
slow hydration never overwrites an edit the user already made.
|
|
3557
|
+
|
|
3558
|
+
Pass `null` for `key` while the real key is unknown (no project selected
|
|
3559
|
+
yet): the hook then behaves as local state around `defaultValue` and
|
|
3560
|
+
persists nothing.
|
|
1419
3561
|
|
|
1420
3562
|
```typescript
|
|
1421
|
-
function
|
|
3563
|
+
function useStoragePreference<T = unknown>(
|
|
3564
|
+
key: string | null | undefined,
|
|
3565
|
+
options?: UseStoragePreferenceOptions<T>,
|
|
3566
|
+
): UseStoragePreferenceResult<T>
|
|
1422
3567
|
```
|
|
1423
3568
|
|
|
1424
|
-
- `
|
|
3569
|
+
- `key` — The storage key, or `null` when there is nothing to persist.
|
|
3570
|
+
- `options` — `defaultValue`, reported until the provider supplies one.
|
|
1425
3571
|
|
|
1426
|
-
|
|
3572
|
+
**Returns:** The current value, its mutators, and whether it is definite yet.
|
|
1427
3573
|
|
|
1428
|
-
|
|
3574
|
+
#### `useStorage()`
|
|
3575
|
+
|
|
3576
|
+
Storage operations without local state sync, React's `useStorage` in
|
|
3577
|
+
Svelte's idiom: plain passthroughs of the context provider.
|
|
1429
3578
|
|
|
1430
3579
|
```typescript
|
|
1431
|
-
function
|
|
3580
|
+
function useStorage(): {
|
|
3581
|
+
get: <T>(key: string) => Promise<T | null>
|
|
3582
|
+
set: <T>(key: string, value: T) => Promise<void>
|
|
3583
|
+
remove: (key: string) => Promise<void>
|
|
3584
|
+
clear: () => Promise<void>
|
|
3585
|
+
keys: () => Promise<string[]>
|
|
3586
|
+
}
|
|
1432
3587
|
```
|
|
1433
3588
|
|
|
1434
|
-
|
|
3589
|
+
**Returns:** Storage operation methods
|
|
1435
3590
|
|
|
1436
|
-
#### `
|
|
3591
|
+
#### `useStore(store, options)`
|
|
1437
3592
|
|
|
1438
|
-
|
|
3593
|
+
Subscribes a store with an optional selector and equality function, React's
|
|
3594
|
+
`useStore` in Svelte's idiom: a readable store of the selected value.
|
|
3595
|
+
|
|
3596
|
+
The store is the argument, so this hook needs NO state provider: it reads
|
|
3597
|
+
`store.getState()` and subscribes with `store.subscribe()`. When
|
|
3598
|
+
`equalityFn` says a new selected value equals the previous one, the previous
|
|
3599
|
+
result is kept (the same value, not a fresh object).
|
|
3600
|
+
|
|
3601
|
+
The selector and equality function run with the same cadence as React's
|
|
3602
|
+
`useSyncExternalStore` binding, because React re-reads its snapshot around
|
|
3603
|
+
every render; {@link useSyncExternalStore} documents the cadence.
|
|
1439
3604
|
|
|
1440
3605
|
```typescript
|
|
1441
|
-
function
|
|
3606
|
+
function useStore<T, S = T>(store: Store<T>, options?: UseStoreOptions<T, S>): Readable<S>
|
|
1442
3607
|
```
|
|
1443
3608
|
|
|
1444
|
-
- `
|
|
3609
|
+
- `store` — The store to subscribe to.
|
|
3610
|
+
- `options` — Hook options (selector, equalityFn).
|
|
1445
3611
|
|
|
1446
|
-
|
|
3612
|
+
**Returns:** A readable store of the selected state.
|
|
1447
3613
|
|
|
1448
|
-
|
|
3614
|
+
#### `useSetStore(store)`
|
|
3615
|
+
|
|
3616
|
+
The store's setState function, React's `useSetStore` in Svelte's idiom.
|
|
1449
3617
|
|
|
1450
3618
|
```typescript
|
|
1451
|
-
function
|
|
3619
|
+
function useSetStore<T>(store: Store<T>): Store<T>['setState']
|
|
1452
3620
|
```
|
|
1453
3621
|
|
|
1454
|
-
- `
|
|
3622
|
+
- `store` — The store to get setState from.
|
|
1455
3623
|
|
|
1456
|
-
|
|
3624
|
+
**Returns:** The store's setState function.
|
|
1457
3625
|
|
|
1458
|
-
|
|
3626
|
+
#### `useStoreAction(store, action)`
|
|
3627
|
+
|
|
3628
|
+
A bound action for a store, React's `useStoreAction` in Svelte's idiom.
|
|
1459
3629
|
|
|
1460
3630
|
```typescript
|
|
1461
|
-
function
|
|
3631
|
+
function useStoreAction<T, Args extends unknown[], R>(
|
|
3632
|
+
store: Store<T>,
|
|
3633
|
+
action: (setState: Store<T>['setState'], getState: Store<T>['getState']) => (...args: Args) => R,
|
|
3634
|
+
): (...args: Args) => R
|
|
1462
3635
|
```
|
|
1463
3636
|
|
|
1464
|
-
- `
|
|
3637
|
+
- `store` — The store to bind to.
|
|
3638
|
+
- `action` — The action function that receives setState and getState.
|
|
1465
3639
|
|
|
1466
|
-
|
|
3640
|
+
**Returns:** A bound action function.
|
|
1467
3641
|
|
|
1468
|
-
|
|
3642
|
+
#### `useTheme()`
|
|
3643
|
+
|
|
3644
|
+
Theme state and actions, React's `useTheme` in Svelte's idiom: call it
|
|
3645
|
+
during component init under `setMoleculeContext({ theme })`.
|
|
1469
3646
|
|
|
1470
3647
|
```typescript
|
|
1471
|
-
function
|
|
3648
|
+
function useTheme(): UseThemeResult
|
|
1472
3649
|
```
|
|
1473
3650
|
|
|
1474
|
-
|
|
3651
|
+
**Returns:** Theme state as stores and the actions as functions.
|
|
1475
3652
|
|
|
1476
|
-
#### `
|
|
3653
|
+
#### `useCurrentTheme()`
|
|
1477
3654
|
|
|
1478
|
-
|
|
3655
|
+
The current theme object, React's `useCurrentTheme` in Svelte's idiom.
|
|
1479
3656
|
|
|
1480
3657
|
```typescript
|
|
1481
|
-
function
|
|
3658
|
+
function useCurrentTheme(): Readable<Theme>
|
|
1482
3659
|
```
|
|
1483
3660
|
|
|
1484
|
-
|
|
3661
|
+
**Returns:** A readable store of the current theme.
|
|
1485
3662
|
|
|
1486
|
-
#### `
|
|
3663
|
+
#### `useThemeMode()`
|
|
1487
3664
|
|
|
1488
|
-
|
|
3665
|
+
The current theme mode, React's `useThemeMode` in Svelte's idiom.
|
|
1489
3666
|
|
|
1490
3667
|
```typescript
|
|
1491
|
-
function
|
|
3668
|
+
function useThemeMode(): Readable<'light' | 'dark'>
|
|
1492
3669
|
```
|
|
1493
3670
|
|
|
1494
|
-
|
|
3671
|
+
**Returns:** A readable store of 'light' or 'dark'.
|
|
1495
3672
|
|
|
1496
|
-
#### `
|
|
3673
|
+
#### `useThemeColors()`
|
|
1497
3674
|
|
|
1498
|
-
|
|
3675
|
+
The current theme's colors, React's `useThemeColors` in Svelte's idiom.
|
|
1499
3676
|
|
|
1500
3677
|
```typescript
|
|
1501
|
-
function
|
|
3678
|
+
function useThemeColors(): Readable<Theme['colors']>
|
|
1502
3679
|
```
|
|
1503
3680
|
|
|
1504
|
-
|
|
3681
|
+
**Returns:** A readable store of the current theme's colors.
|
|
1505
3682
|
|
|
1506
|
-
#### `
|
|
3683
|
+
#### `useTranslation()`
|
|
1507
3684
|
|
|
1508
|
-
|
|
3685
|
+
Internationalization, React's `useTranslation` in Svelte's idiom: call it
|
|
3686
|
+
during component init under `setMoleculeContext({ i18n })`.
|
|
1509
3687
|
|
|
1510
3688
|
```typescript
|
|
1511
|
-
function
|
|
3689
|
+
function useTranslation(): UseTranslationResult
|
|
1512
3690
|
```
|
|
1513
3691
|
|
|
1514
|
-
**Returns:** The
|
|
3692
|
+
**Returns:** The translation function and the locale values as stores.
|
|
1515
3693
|
|
|
1516
|
-
#### `
|
|
3694
|
+
#### `useT()`
|
|
1517
3695
|
|
|
1518
|
-
|
|
3696
|
+
The translation function alone, React's `useT` in Svelte's idiom.
|
|
3697
|
+
|
|
3698
|
+
Call it in either of two compatible forms:
|
|
3699
|
+
|
|
3700
|
+
- `t(key, values?, options?)` — the provider signature.
|
|
3701
|
+
- `t(key, fallback, options?)` — a string second argument is the inline
|
|
3702
|
+
English `defaultValue`.
|
|
1519
3703
|
|
|
1520
3704
|
```typescript
|
|
1521
|
-
function
|
|
1522
|
-
T = unknown,
|
|
1523
|
-
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
1524
|
-
>(): AuthClient<T, TRegister>
|
|
3705
|
+
function useT(): UseTFunction
|
|
1525
3706
|
```
|
|
1526
3707
|
|
|
1527
|
-
**Returns:** The
|
|
3708
|
+
**Returns:** The translation function.
|
|
1528
3709
|
|
|
1529
|
-
#### `
|
|
3710
|
+
#### `useLocale()`
|
|
1530
3711
|
|
|
1531
|
-
|
|
3712
|
+
The current locale, React's `useLocale` in Svelte's idiom.
|
|
1532
3713
|
|
|
1533
3714
|
```typescript
|
|
1534
|
-
function
|
|
3715
|
+
function useLocale(): Readable<string>
|
|
1535
3716
|
```
|
|
1536
3717
|
|
|
1537
|
-
**Returns:**
|
|
3718
|
+
**Returns:** A readable store of the locale code.
|
|
1538
3719
|
|
|
1539
|
-
#### `
|
|
3720
|
+
#### `useDirection()`
|
|
1540
3721
|
|
|
1541
|
-
|
|
3722
|
+
The text direction, React's `useDirection` in Svelte's idiom.
|
|
1542
3723
|
|
|
1543
3724
|
```typescript
|
|
1544
|
-
function
|
|
3725
|
+
function useDirection(): Readable<'ltr' | 'rtl'>
|
|
1545
3726
|
```
|
|
1546
3727
|
|
|
1547
|
-
**Returns:**
|
|
3728
|
+
**Returns:** A readable store of 'ltr' or 'rtl'.
|
|
1548
3729
|
|
|
1549
|
-
#### `
|
|
3730
|
+
#### `useI18nError(error)`
|
|
1550
3731
|
|
|
1551
|
-
|
|
3732
|
+
Translates an error at render time so the displayed message updates
|
|
3733
|
+
automatically when the locale changes, React's `useI18nError` in Svelte's
|
|
3734
|
+
idiom: a readable store of the translated message.
|
|
3735
|
+
|
|
3736
|
+
**Always use this hook to display errors** — reading `error.message`
|
|
3737
|
+
directly leaves stale text after a locale switch. If `error` is an
|
|
3738
|
+
`I18nError` (thrown via `throw new I18nError(key)`), its key is translated
|
|
3739
|
+
using the current locale. For plain `Error` instances, `error.message` is
|
|
3740
|
+
returned unchanged.
|
|
1552
3741
|
|
|
1553
3742
|
```typescript
|
|
1554
|
-
function
|
|
3743
|
+
function useI18nError(error: Error | null | undefined): Readable<string | null>
|
|
1555
3744
|
```
|
|
1556
3745
|
|
|
1557
|
-
|
|
3746
|
+
- `error` — The error to translate, or `null`/`undefined`.
|
|
1558
3747
|
|
|
1559
|
-
|
|
3748
|
+
**Returns:** A readable store of the translated error string, or null.
|
|
1560
3749
|
|
|
1561
|
-
|
|
3750
|
+
#### `useVerifyPaymentReturn(options)`
|
|
3751
|
+
|
|
3752
|
+
Reads the payment id a provider put in the return URL and confirms the
|
|
3753
|
+
purchase server-side with `POST /users/:id/verify-payment/:provider`,
|
|
3754
|
+
React's `useVerifyPaymentReturn` in Svelte's idiom: call it during component
|
|
3755
|
+
init under `setMoleculeContext({ auth, http })`.
|
|
3756
|
+
|
|
3757
|
+
**This is why a hosted checkout returns the buyer to the APP and not the
|
|
3758
|
+
API.** Session cookies are host-only on the app's origin, so a top-level
|
|
3759
|
+
redirect from the provider straight to an authenticated API callback on a
|
|
3760
|
+
different host arrives with NO credentials — it answers 401 and the paid plan
|
|
3761
|
+
is never granted. The request this hook makes is a same-origin call from a
|
|
3762
|
+
loaded app page, so the credentials apply. It waits for auth to hydrate
|
|
3763
|
+
first: after the redirect the page is a cold load, and the session is
|
|
3764
|
+
restored from the httpOnly cookie via `GET /users/me`.
|
|
3765
|
+
|
|
3766
|
+
Verification is idempotent server-side (first-claim-wins on the transaction),
|
|
3767
|
+
and this hook additionally runs at most once per transaction id per page.
|
|
3768
|
+
Safe on pages that are also reached normally: with no id in the URL it stays
|
|
3769
|
+
`idle` and issues no request.
|
|
3770
|
+
|
|
3771
|
+
If the component unmounts while the request is in flight, a verified
|
|
3772
|
+
purchase still refreshes the cached profile (the plan is paid for), but the
|
|
3773
|
+
hook calls neither `onVerified` nor `onError` and leaves the URL alone: by
|
|
3774
|
+
then the address may belong to another page. A failure after unmount is
|
|
3775
|
+
logged instead.
|
|
1562
3776
|
|
|
1563
3777
|
```typescript
|
|
1564
|
-
function
|
|
3778
|
+
function useVerifyPaymentReturn(
|
|
3779
|
+
options?: UseVerifyPaymentReturnOptions,
|
|
3780
|
+
): UseVerifyPaymentReturnResult
|
|
1565
3781
|
```
|
|
1566
3782
|
|
|
1567
|
-
|
|
3783
|
+
- `options` — Provider fallback + lifecycle callbacks (see {@link UseVerifyPaymentReturnOptions}).
|
|
1568
3784
|
|
|
1569
|
-
|
|
3785
|
+
**Returns:** The verification state (see {@link UseVerifyPaymentReturnResult}).
|
|
1570
3786
|
|
|
1571
|
-
|
|
3787
|
+
#### `useVersion()`
|
|
3788
|
+
|
|
3789
|
+
Version state and update actions, React's `useVersion` in Svelte's idiom: a
|
|
3790
|
+
readable store per value field and plain functions for the actions, created
|
|
3791
|
+
during component init.
|
|
3792
|
+
|
|
3793
|
+
Uses module-level `getProvider()` — version is a singleton, not
|
|
3794
|
+
context-provided.
|
|
1572
3795
|
|
|
1573
3796
|
```typescript
|
|
1574
|
-
function
|
|
3797
|
+
function useVersion(): UseVersionResult
|
|
1575
3798
|
```
|
|
1576
3799
|
|
|
1577
|
-
**Returns:**
|
|
3800
|
+
**Returns:** Version state and action methods.
|
|
1578
3801
|
|
|
1579
|
-
#### `
|
|
3802
|
+
#### `useWorkspace()`
|
|
1580
3803
|
|
|
1581
|
-
|
|
3804
|
+
IDE workspace layout management, React's `useWorkspace` in Svelte's idiom:
|
|
3805
|
+
call it during component init under `setMoleculeContext({ workspace })`.
|
|
3806
|
+
|
|
3807
|
+
The state is a snapshot store over `provider.subscribe`, cached the way
|
|
3808
|
+
React's `useSyncExternalStore` snapshot is (a provider without `getState`
|
|
3809
|
+
fabricates the non-layout fields from `getLayout()` until its first
|
|
3810
|
+
emission supplies the real ones).
|
|
1582
3811
|
|
|
1583
3812
|
```typescript
|
|
1584
|
-
function
|
|
3813
|
+
function useWorkspace(): UseWorkspaceResult
|
|
1585
3814
|
```
|
|
1586
3815
|
|
|
1587
|
-
**Returns:** The
|
|
3816
|
+
**Returns:** The workspace state stores and management methods.
|
|
1588
3817
|
|
|
1589
3818
|
#### `createAsyncState(initialValue)`
|
|
1590
3819
|
|
|
@@ -1656,6 +3885,24 @@ function createChangePasswordStore(): ChangePasswordStore
|
|
|
1656
3885
|
|
|
1657
3886
|
**Returns:** Change password promise store
|
|
1658
3887
|
|
|
3888
|
+
#### `useChat(options)`
|
|
3889
|
+
|
|
3890
|
+
AI chat with streaming: the transcript, loading and error state, mode, and
|
|
3891
|
+
the controls (send, abort, queue edits, history). Call it during component
|
|
3892
|
+
init.
|
|
3893
|
+
|
|
3894
|
+
The options may be a readable store: a new `endpoint` switches conversation
|
|
3895
|
+
and a new `projectId` moves to that project's transcript, on the same
|
|
3896
|
+
component, the way React re-renders `useChat`.
|
|
3897
|
+
|
|
3898
|
+
```typescript
|
|
3899
|
+
function useChat(options: UseChatOptions | Readable<UseChatOptions>): UseChatResult
|
|
3900
|
+
```
|
|
3901
|
+
|
|
3902
|
+
- `options` — Chat options (or a store of them): endpoint, project id, history loading, callbacks.
|
|
3903
|
+
|
|
3904
|
+
**Returns:** Each state field as a readable store, and the chat controls.
|
|
3905
|
+
|
|
1659
3906
|
#### `createDeviceStores()`
|
|
1660
3907
|
|
|
1661
3908
|
Create device stores from the module-level device provider.
|
|
@@ -2218,23 +4465,99 @@ function createVersionStores(): {
|
|
|
2218
4465
|
|
|
2219
4466
|
**Returns:** Version stores and actions
|
|
2220
4467
|
|
|
4468
|
+
### Constants
|
|
4469
|
+
|
|
4470
|
+
#### `SessionReady`
|
|
4471
|
+
|
|
4472
|
+
```typescript
|
|
4473
|
+
const SessionReady: LegacyComponentType
|
|
4474
|
+
```
|
|
4475
|
+
|
|
4476
|
+
#### `DEFAULT_AGENT_NAME`
|
|
4477
|
+
|
|
4478
|
+
Neutral, product-agnostic agent name used when the host supplies none.
|
|
4479
|
+
|
|
4480
|
+
```typescript
|
|
4481
|
+
const DEFAULT_AGENT_NAME: typeof CHAT_DEFAULT_AGENT_NAME
|
|
4482
|
+
```
|
|
4483
|
+
|
|
4484
|
+
#### `DEFAULT_PRODUCT_NAME`
|
|
4485
|
+
|
|
4486
|
+
Neutral, product-agnostic product/IDE name used when the host supplies none.
|
|
4487
|
+
|
|
4488
|
+
```typescript
|
|
4489
|
+
const DEFAULT_PRODUCT_NAME: typeof CHAT_DEFAULT_PRODUCT_NAME
|
|
4490
|
+
```
|
|
4491
|
+
|
|
4492
|
+
#### `DEFAULT_AGENT_IDENTITY`
|
|
4493
|
+
|
|
4494
|
+
The neutral default identity ({@link DEFAULT_AGENT_NAME} +
|
|
4495
|
+
{@link DEFAULT_PRODUCT_NAME}) the shared packages use until a consuming app
|
|
4496
|
+
passes its own.
|
|
4497
|
+
|
|
4498
|
+
```typescript
|
|
4499
|
+
const DEFAULT_AGENT_IDENTITY: AgentIdentity
|
|
4500
|
+
```
|
|
4501
|
+
|
|
4502
|
+
#### `convergeHistory`
|
|
4503
|
+
|
|
4504
|
+
Converges the local transcript with authoritative server history. See
|
|
4505
|
+
`convergeHistory` in `@molecule/app-ai-chat`.
|
|
4506
|
+
|
|
4507
|
+
```typescript
|
|
4508
|
+
const convergeHistory: typeof coreConvergeHistory
|
|
4509
|
+
```
|
|
4510
|
+
|
|
4511
|
+
- `prev` — The local transcript.
|
|
4512
|
+
- `history` — The server's history.
|
|
4513
|
+
|
|
4514
|
+
**Returns:** The converged transcript.
|
|
4515
|
+
|
|
4516
|
+
#### `localOnlyMessages`
|
|
4517
|
+
|
|
4518
|
+
The local messages server history does not carry yet. See
|
|
4519
|
+
`localOnlyMessages` in `@molecule/app-ai-chat`.
|
|
4520
|
+
|
|
4521
|
+
```typescript
|
|
4522
|
+
const localOnlyMessages: typeof coreLocalOnlyMessages
|
|
4523
|
+
```
|
|
4524
|
+
|
|
4525
|
+
- `prev` — The local transcript.
|
|
4526
|
+
- `history` — The server's history.
|
|
4527
|
+
|
|
4528
|
+
**Returns:** The local-only messages.
|
|
4529
|
+
|
|
4530
|
+
#### `resetChatStoresForTests`
|
|
4531
|
+
|
|
4532
|
+
Clears every chat session store. Tests only: each test starts with no
|
|
4533
|
+
transcript, queue or stream left by the previous one.
|
|
4534
|
+
|
|
4535
|
+
```typescript
|
|
4536
|
+
const resetChatStoresForTests: typeof coreResetChatStoresForTests
|
|
4537
|
+
```
|
|
4538
|
+
|
|
2221
4539
|
## Injection Notes
|
|
2222
4540
|
|
|
2223
4541
|
### Requirements
|
|
2224
4542
|
|
|
2225
4543
|
Peer dependencies:
|
|
2226
4544
|
|
|
4545
|
+
- `@molecule/app-ai-chat` ^1.8.0
|
|
4546
|
+
- `@molecule/app-ai-models` ^1.0.1
|
|
2227
4547
|
- `@molecule/app-auth` ^3.0.0
|
|
4548
|
+
- `@molecule/app-code-editor` ^1.0.1
|
|
2228
4549
|
- `@molecule/app-device` ^1.0.1
|
|
2229
|
-
- `@molecule/app-forms` ^2.
|
|
4550
|
+
- `@molecule/app-forms` ^2.3.1
|
|
2230
4551
|
- `@molecule/app-http` ^1.0.1
|
|
2231
4552
|
- `@molecule/app-i18n` ^1.0.1
|
|
4553
|
+
- `@molecule/app-ide` ^1.0.1
|
|
4554
|
+
- `@molecule/app-live-preview` ^1.0.1
|
|
2232
4555
|
- `@molecule/app-logger` ^1.0.1
|
|
2233
4556
|
- `@molecule/app-platform` ^1.0.1
|
|
2234
4557
|
- `@molecule/app-push` ^1.0.1
|
|
2235
|
-
- `@molecule/app-routing` ^1.0
|
|
2236
|
-
- `@molecule/app-state` ^1.0
|
|
2237
|
-
- `@molecule/app-storage` ^1.
|
|
4558
|
+
- `@molecule/app-routing` ^1.1.0
|
|
4559
|
+
- `@molecule/app-state` ^1.2.0
|
|
4560
|
+
- `@molecule/app-storage` ^1.1.1
|
|
2238
4561
|
- `@molecule/app-theme` ^1.0.1
|
|
2239
4562
|
- `@molecule/app-ui` ^1.0.1
|
|
2240
4563
|
- `@molecule/app-utilities` ^1.0.1
|
|
@@ -2243,11 +4566,16 @@ Peer dependencies:
|
|
|
2243
4566
|
|
|
2244
4567
|
### Runtime Dependencies
|
|
2245
4568
|
|
|
4569
|
+
- `@molecule/app-ai-chat`
|
|
4570
|
+
- `@molecule/app-ai-models`
|
|
2246
4571
|
- `@molecule/app-auth`
|
|
4572
|
+
- `@molecule/app-code-editor`
|
|
2247
4573
|
- `@molecule/app-device`
|
|
2248
4574
|
- `@molecule/app-forms`
|
|
2249
4575
|
- `@molecule/app-http`
|
|
2250
4576
|
- `@molecule/app-i18n`
|
|
4577
|
+
- `@molecule/app-ide`
|
|
4578
|
+
- `@molecule/app-live-preview`
|
|
2251
4579
|
- `@molecule/app-logger`
|
|
2252
4580
|
- `@molecule/app-platform`
|
|
2253
4581
|
- `@molecule/app-push`
|