@basictech/react 0.12.0-beta.0 → 0.12.0-beta.2

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, ReactElement } from 'react';
3
- import { BasicSchema, BasicConfig, BasicClient, BasicAccount, BasicProfile, AuthStatus, BasicError, AuthUser, BasicSyncStatus, BasicRejection, BasicConflict, SourceRef, SchemaStatus, BasicDb, Repo, FileRecord, MountFileInfo, StorageInfo, FileListQuery, MountInfo, MountHandle, OutgoingShareInfo, CreateOutgoingShareInput, MountsQuery, JsonObject, BasicRecord, Query, MountViewerFiles, OwnerFiles, TableNames, Collection, InferValue, KeyValueStorage, TokenStore, AuthMessageChannel, ReplicaStoreFactory, StoragePartition, ReplicaStore, UploadTransportAdapter } from '@basictech/core';
2
+ import { ReactNode, ReactElement, RefObject, ButtonHTMLAttributes, HTMLAttributes } from 'react';
3
+ import { BasicSchema, BasicConfig, BasicClient, BasicAccount, BasicProfile, ReadOnlyReason, AuthStatus as AuthStatus$1, BasicError, AuthUser, BasicSyncStatus, BasicRejection, BasicConflict, SourceRef, SchemaStatus, BasicDb, Repo, FileRecord, MountFileInfo, StorageInfo, FileListQuery, MountInfo, MountHandle, OutgoingShareInfo, CreateOutgoingShareInput, MountsQuery, JsonObject, BasicRecord, Query, ProjectProfile, ProjectProfilePatch, MountViewerFiles, OwnerFiles, TableNames, Collection, InferValue, KeyValueStorage, TokenStore, AuthChannelContext, AuthMessageChannel, ReplicaStoreFactory, StoragePartition, ReplicaStore, UploadTransportAdapter } from '@basictech/core';
4
4
 
5
5
  type BrowserBasicConfig<S extends BasicSchema = BasicSchema> = BasicConfig<S>;
6
6
  /** Create a core client with the complete browser adapter set installed. */
@@ -8,9 +8,11 @@ declare function createBasicClient<S extends BasicSchema>(config: BrowserBasicCo
8
8
 
9
9
  interface UseAccountsResult {
10
10
  accounts: BasicAccount[];
11
- active: BasicAccount | null;
11
+ activeAccount: BasicAccount | null;
12
12
  switchAccount(id: string): Promise<void>;
13
- addAccount(): Promise<BasicProfile>;
13
+ addAccount(options?: {
14
+ signIn?: boolean;
15
+ }): Promise<BasicProfile>;
14
16
  removeAccount(id: string): Promise<void>;
15
17
  }
16
18
  declare function useAccounts(): UseAccountsResult;
@@ -20,8 +22,9 @@ interface UseAuthResult {
20
22
  isSignedIn: boolean;
21
23
  isAnonymous: boolean;
22
24
  canWrite: boolean;
23
- readOnlyReason: string | null;
24
- status: AuthStatus;
25
+ readOnlyReason: ReadOnlyReason | null;
26
+ status: AuthStatus$1;
27
+ /** Raw auth diagnostic; stable identity while its code and expired state are unchanged. */
25
28
  error: BasicError | null;
26
29
  user: AuthUser | null;
27
30
  did: string | null;
@@ -64,6 +67,7 @@ declare function useFiles(query?: FileListQuery, options?: {
64
67
  interface UseStorageInfoResult {
65
68
  data: StorageInfo | null;
66
69
  isLoading: boolean;
70
+ /** Load failure, or the sign-in requirement while no account is signed in. */
67
71
  error: BasicError | null;
68
72
  refresh(): void;
69
73
  }
@@ -71,8 +75,8 @@ declare function useStorageInfo(): UseStorageInfoResult;
71
75
 
72
76
  interface UseMountsResult<S extends BasicSchema = BasicSchema> {
73
77
  data: MountInfo[];
74
- mounts: MountInfo[];
75
78
  isLoading: boolean;
79
+ /** Load failure, or the sign-in requirement while no account is signed in. */
76
80
  error: BasicError | null;
77
81
  refresh(): void;
78
82
  open(mountId: string): Promise<MountHandle<S>>;
@@ -81,8 +85,8 @@ interface UseMountsResult<S extends BasicSchema = BasicSchema> {
81
85
  declare function useMounts(query?: MountsQuery): UseMountsResult;
82
86
  interface UseOutgoingSharesResult {
83
87
  data: OutgoingShareInfo[];
84
- outgoingShares: OutgoingShareInfo[];
85
88
  isLoading: boolean;
89
+ /** Load failure, or the sign-in requirement while no account is signed in. */
86
90
  error: BasicError | null;
87
91
  refresh(): void;
88
92
  create(input: CreateOutgoingShareInput): Promise<OutgoingShareInfo>;
@@ -116,6 +120,19 @@ interface UseReposResult {
116
120
  }
117
121
  declare function useRepos(): UseReposResult;
118
122
 
123
+ interface AsyncResult<T> {
124
+ data: T;
125
+ isLoading: boolean;
126
+ error: BasicError | null;
127
+ refresh(): void;
128
+ }
129
+
130
+ interface UseProjectProfileResult extends AsyncResult<ProjectProfile | null> {
131
+ update(patch: ProjectProfilePatch): Promise<ProjectProfile>;
132
+ reset(): Promise<ProjectProfile>;
133
+ }
134
+ declare function useProjectProfile(enabled?: boolean): UseProjectProfileResult;
135
+
119
136
  type CreateBasicConfig<S extends BasicSchema> = BrowserBasicConfig<S> & {
120
137
  schema: S;
121
138
  };
@@ -145,6 +162,7 @@ interface CreatedBasic<S extends BasicSchema> {
145
162
  useSyncStatus(source?: SourceRef): UseSyncStatusResult;
146
163
  useSchemaStatus(source?: SourceRef): SchemaStatus;
147
164
  useRepos(): UseReposResult;
165
+ useProjectProfile(enabled?: boolean): UseProjectProfileResult;
148
166
  useFiles(query?: FileListQuery, options?: {
149
167
  source?: SourceRef;
150
168
  }): UseFilesResult;
@@ -178,6 +196,93 @@ declare function useCollection<V extends JsonObject = JsonObject>(name: string,
178
196
  source?: SourceRef;
179
197
  }): Collection<V>;
180
198
 
199
+ interface BasicAppearance {
200
+ theme?: 'light' | 'dark';
201
+ accent?: string;
202
+ radius?: string;
203
+ density?: 'compact' | 'comfortable';
204
+ }
205
+ /** Optional styling provider. CSS is opt-in via @basictech/react/styles.css. */
206
+ declare function BasicUIProvider({ appearance, children, }: {
207
+ appearance?: BasicAppearance;
208
+ children: ReactNode;
209
+ }): react.JSX.Element;
210
+ interface BasicButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
211
+ variant?: 'solid' | 'outline' | 'ghost';
212
+ }
213
+ declare const BasicButton: react.ForwardRefExoticComponent<BasicButtonProps & react.RefAttributes<HTMLButtonElement>>;
214
+ interface AuthButtonProps extends BasicButtonProps {
215
+ auth?: UseAuthResult;
216
+ input?: string;
217
+ }
218
+ declare function SignInButton(props: AuthButtonProps): react.JSX.Element;
219
+ declare function SignOutButton(props: AuthButtonProps): react.JSX.Element;
220
+ interface UserAvatarProps extends HTMLAttributes<HTMLSpanElement> {
221
+ profile?: (Pick<BasicProfile, 'name' | 'handle' | 'email' | 'picture'> & Partial<Pick<BasicProfile, 'kind'>>) | null;
222
+ size?: number;
223
+ showSyncBadge?: boolean;
224
+ sync?: UseSyncStatusResult;
225
+ accounts?: UseAccountsResult;
226
+ auth?: UseAuthResult;
227
+ projectProfile?: UseProjectProfileResult;
228
+ allowAddAccount?: boolean;
229
+ }
230
+ declare function UserAvatar({ accounts, auth, projectProfile, allowAddAccount, ...avatarProps }: UserAvatarProps): react.JSX.Element;
231
+ declare function AuthStatus({ auth: supplied, className, ...props }: HTMLAttributes<HTMLSpanElement> & {
232
+ auth?: UseAuthResult;
233
+ }): react.JSX.Element;
234
+ declare function SyncStatus({ sync: supplied, source, className, ...props }: HTMLAttributes<HTMLSpanElement> & {
235
+ sync?: UseSyncStatusResult;
236
+ source?: SourceRef;
237
+ }): react.JSX.Element | null;
238
+ interface UserButtonProps {
239
+ accounts?: UseAccountsResult;
240
+ auth?: UseAuthResult;
241
+ sync?: UseSyncStatusResult;
242
+ /** Show synchronization status in the account menu. Defaults to true. */
243
+ showSyncStatus?: boolean;
244
+ /** Defaults to enabled in sync mode. */
245
+ showSyncBadge?: boolean;
246
+ shape?: 'rounded' | 'square';
247
+ projectProfile?: UseProjectProfileResult;
248
+ /** Show the action to sign in to another account. Defaults to true. */
249
+ allowAddAccount?: boolean;
250
+ className?: string;
251
+ accountSettingsUrl?: string;
252
+ }
253
+ declare function UserButton(props: UserButtonProps): react.JSX.Element;
254
+ interface UserMenuProps extends UserButtonProps {
255
+ trigger?: 'avatar' | 'button';
256
+ avatarProps?: UserAvatarProps;
257
+ }
258
+ declare function UserMenu({ accounts: supplied, auth: suppliedAuth, sync, showSyncStatus, showSyncBadge, shape, trigger, avatarProps, projectProfile, allowAddAccount, className, accountSettingsUrl, }: UserMenuProps): react.JSX.Element;
259
+ interface BasicModalProps {
260
+ open?: boolean;
261
+ onOpenChange?: (open: boolean) => void;
262
+ finalFocus?: RefObject<HTMLElement>;
263
+ /** Supply a button element; null omits the trigger for controlled use. */
264
+ trigger?: ReactNode;
265
+ }
266
+ interface AccountSettingsModalProps extends BasicModalProps {
267
+ auth?: UseAuthResult;
268
+ accounts?: UseAccountsResult;
269
+ projectProfile?: UseProjectProfileResult;
270
+ sync?: UseSyncStatusResult;
271
+ accountSettingsUrl?: string;
272
+ children?: ReactNode;
273
+ }
274
+ declare function AccountSettingsModal({ auth: suppliedAuth, accounts: suppliedAccounts, accountSettingsUrl, projectProfile, sync, children, ...props }: AccountSettingsModalProps): react.JSX.Element;
275
+ interface SharesModalProps extends BasicModalProps {
276
+ auth?: UseAuthResult;
277
+ accounts?: UseAccountsResult;
278
+ sync?: UseSyncStatusResult;
279
+ shares?: UseOutgoingSharesResult;
280
+ /** Explicit least-privilege scope; the component never infers all tables. */
281
+ scope: CreateOutgoingShareInput['scope'];
282
+ repo?: CreateOutgoingShareInput['repo'];
283
+ }
284
+ declare function SharesModal({ auth: supplied, accounts: suppliedAccounts, sync, shares, scope, repo, ...props }: SharesModalProps): react.JSX.Element;
285
+
181
286
  /** Synchronous browser Storage adapted to core's key-value contract. */
182
287
  declare class BrowserKeyValueStorage implements KeyValueStorage {
183
288
  private readonly storage;
@@ -211,6 +316,8 @@ declare class BrowserTokenStore implements TokenStore {
211
316
  private waitForAccessToken;
212
317
  }
213
318
 
319
+ /** The subset of BrowserTokenStore the auth channel needs; any token store providing it works. */
320
+ type AccessTokenAdopter = Pick<BrowserTokenStore, 'accessToken' | 'adoptAccessToken'>;
214
321
  interface BrowserMessageChannel {
215
322
  postMessage(message: unknown): void;
216
323
  close(): void;
@@ -223,9 +330,11 @@ declare function createBrowserMessageChannel(name: string): BrowserMessageChanne
223
330
  /**
224
331
  * Access tokens may cross tabs transiently but are never written to browser
225
332
  * storage. The receiving adapter adopts the token before core handles the
226
- * ordinary token-rotation notification.
333
+ * ordinary token-rotation notification. Core supplies the token key for the
334
+ * profile's auth channel; channels without a context (the accounts channel)
335
+ * are plain BroadcastChannels.
227
336
  */
228
- declare function createBrowserAuthChannelFactory(clientId: string, tokenStore: BrowserTokenStore): (name: string) => AuthMessageChannel;
337
+ declare function createBrowserAuthChannelFactory(tokenStore: AccessTokenAdopter): (name: string, context?: AuthChannelContext) => AuthMessageChannel;
229
338
 
230
339
  declare function browserNavigate(url: string): void;
231
340
  declare function browserCurrentUrl(): string;
@@ -269,4 +378,4 @@ declare class PersistenceStore implements ReplicaStoreFactory {
269
378
  /** Browser multipart transport with upload progress, adapted from the Drive UI. */
270
379
  declare const browserUploadTransport: UploadTransportAdapter;
271
380
 
272
- export { BasicProvider, type BasicProviderProps, type BoundBasicProviderProps, type BrowserBasicConfig, BrowserKeyValueStorage, type BrowserLockManager, type BrowserMessageChannel, BrowserTokenStore, type CreateBasicConfig, type CreatedBasic, PersistenceStore, type PersistenceStoreOptions, type UseAccountsResult, type UseAuthResult, type UseBasicResult, type UseFilesResult, type UseMountsResult, type UseOutgoingSharesResult, type UseQueryResult, type UseReposResult, type UseStorageInfoResult, type UseSyncStatusResult, browserCurrentUrl, browserNavigate, browserReplaceUrl, browserStorage, browserUploadTransport, createBasic, createBasicClient, createBrowserAuthChannelFactory, createBrowserMessageChannel, useAccounts, useAuth, useBasic, useCollection, useDb, useFiles, useMounts, useOutgoingShares, useQuery, useRepos, useSchemaStatus, useStorageInfo, useSyncStatus };
381
+ export { type AccessTokenAdopter, AccountSettingsModal, type AccountSettingsModalProps, type AuthButtonProps, AuthStatus, type BasicAppearance, BasicButton, type BasicButtonProps, type BasicModalProps, BasicProvider, type BasicProviderProps, BasicUIProvider, type BoundBasicProviderProps, type BrowserBasicConfig, BrowserKeyValueStorage, type BrowserLockManager, type BrowserMessageChannel, BrowserTokenStore, type CreateBasicConfig, type CreatedBasic, PersistenceStore, type PersistenceStoreOptions, SharesModal, type SharesModalProps, SignInButton, SignOutButton, SyncStatus, type UseAccountsResult, type UseAuthResult, type UseBasicResult, type UseFilesResult, type UseMountsResult, type UseOutgoingSharesResult, type UseProjectProfileResult, type UseQueryResult, type UseReposResult, type UseStorageInfoResult, type UseSyncStatusResult, UserAvatar, type UserAvatarProps, UserButton, type UserButtonProps, UserMenu, type UserMenuProps, browserCurrentUrl, browserNavigate, browserReplaceUrl, browserStorage, browserUploadTransport, createBasic, createBasicClient, createBrowserAuthChannelFactory, createBrowserMessageChannel, useAccounts, useAuth, useBasic, useCollection, useDb, useFiles, useMounts, useOutgoingShares, useProjectProfile, useQuery, useRepos, useSchemaStatus, useStorageInfo, useSyncStatus };