@ordinatio/ui 1.7.0 → 1.8.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 +32 -1
- package/dist/index.d.mts +280 -2
- package/dist/index.mjs +500 -162
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -243,14 +243,45 @@ Structure (each point is a test):
|
|
|
243
243
|
- Tags: at most `maxTags` (default 3) then a plain "+N"; the "Tags now" label (`tagsLabel`) shows only when a tag chip shows.
|
|
244
244
|
- `classNames.<part>` REPLACES that part's look (the structural positioning and stacking stay inline). Inline styles cannot express `:hover` or `:focus-visible`: pass them through `classNames` (sentence, chip, tag).
|
|
245
245
|
|
|
246
|
+
### Trash kit: `RestoreButton`, `UndoNotice`, `TrashedBanner`
|
|
247
|
+
|
|
248
|
+
Presentation for a soft-delete flow. None of them knows a route, a router or a database: the app passes the server action (`action`) and what to do afterwards (`onDone`: refresh, `router.push`), and a `LinkComponent` where a link is drawn.
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
<RestoreButton action={() => restorePersonAction(id)} onDone={() => router.refresh()} />
|
|
252
|
+
<UndoNotice name={title} action={() => restoreTaskAction(id)} onDone={() => router.refresh()} trashHref="/trash" LinkComponent={Link} />
|
|
253
|
+
<TrashedBanner since={deletedAt} by="Max" restore={<RestoreButton action={...} />} labels={{ intro: 'This person is in the Trash.' }} />
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
- `RestoreButton`: runs the action once (a second click while it runs is ignored); a returned `{ error }` shows in a `role="alert"` and keeps the button; a THROWN error shows `failureMessage` (default "Something went wrong. Please try again."), never the thrown text (`onFailure` gets it for logging); success calls `onDone`. `type="button"`, so it is safe inside a form. `labels` `{ idle, busy }`.
|
|
257
|
+
- `UndoNotice`: the "Moved “name” to the Trash. View Trash, Undo, ×" note. The name is rendered as TEXT. Undo has the same error rules as `RestoreButton`; success calls `onDone` and removes the note; × hides it and runs nothing. `labels` `{ moved(name), viewTrash, undo, undoing, dismiss }`; no `trashHref` means no link. Hiding is local state: to show a NEW notice (another `name`) the app must remount it, for example with `key={id}`; a reused instance that was hidden stays hidden.
|
|
258
|
+
- `TrashedBanner`: amber "In the Trash since DATE by NAME." strip with a `restore` slot. `since` null reads "earlier". Dates use `formatTrashedDate(date, locale = 'en-US', timeZone?)` or your `formatDate`. `labels` `{ intro, since, by, earlier }`.
|
|
259
|
+
- Styling: plain elements with inline defaults; `classNames.<part>` REPLACES that part's look. Parts: RestoreButton `root, button, error`; UndoNotice `root, message, link, undo, dismiss, error`; TrashedBanner `root, text, action`.
|
|
260
|
+
|
|
261
|
+
### `ShowOnceSecret` and `useCopyToClipboard`
|
|
262
|
+
|
|
263
|
+
A box for something that is readable only right now (an API key, a signing secret, an invite link).
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
{created ? <ShowOnceSecret secret={created.rawKey} title={`Your new key “${created.name}”.`} onDone={() => setCreated(null)} /> : null}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
- Shows the title, the warning ("Copy it now: you will not see it again."), the secret as selectable text (`display="text"`, a `code`, or `display="field"`, a read-only input that selects on focus), Copy with a spoken result ("Copied." or the could-not-copy note) and Done. Screen readers: only the copy-result note is a live region (`role="status"`, always present, empty until Copy is pressed), so "Copied." is announced but the secret and warning are not announced on mount; the secret is plain text read only when navigated to. Done calls `onDone`: the PARENT stops rendering the box. The secret is only a prop: it goes to the DOM and, on Copy, the clipboard; no storage, no log. A new `secret` clears the old note. `children` render under the buttons; `secretTestId` sets `data-testid`.
|
|
270
|
+
- `labels`: `warning, copy, done, copied, failed, secret`. `classNames`: `root, title, warning, secret, actions, copy, done, note`.
|
|
271
|
+
- `useCopyToClipboard({ copiedNote, failedNote, resetAfterMs })` returns `{ copy, note, status, reset }`. `copy(text)` resolves true or false and never throws (a refused or missing clipboard gives the failed note). The last of overlapping copies decides the note; `resetAfterMs` fades it; nothing is set after unmount.
|
|
272
|
+
|
|
246
273
|
## Hooks
|
|
247
274
|
|
|
248
|
-
### Form and screen hooks (1.7.0)
|
|
275
|
+
### Form and screen hooks (1.7.0, 1.8.0)
|
|
249
276
|
|
|
250
277
|
- `useFormActionKeepingInput(action, initialState)` returns `[state, onSubmit, pending]`: submits a form to an async action and keeps what the person typed when the action answers with an error. Needs React 19. The action must RETURN its errors (a thrown error goes to the error boundary). Put `onSubmit` on the form and give the form no `action` prop.
|
|
251
278
|
- `useSyncedSelect(value, resultKey)` returns a ref for a controlled `<select>`: keeps it showing `value` after a form reset. Pass the action's result as `resultKey`; every result must be a NEW object, never `null` or a shared constant.
|
|
252
279
|
- `useSavedNotice(state)` returns `{ showSaved, markEdited }`: a "Saved" notice that hides on the next edit. Every action result must be a new object.
|
|
253
280
|
- `useArrival<E extends HTMLElement>(active)` returns `{ ref, soft }`: scrolls a newly arrived row into view, focuses it and softens its highlight after `ARRIVAL_FADE_MS`, once per mount. The type argument is required; give the element `tabIndex={-1}`.
|
|
281
|
+
- `useGuardedAction(action, { onDone, onFailure, failureMessage })` returns `{ run, busy, error, clearError }`: runs an async action one at a time (a second `run` while busy is ignored). A returned `{ error }` is shown and skips `onDone`; a thrown error shows only the fixed `failureMessage` (its own text never reaches the screen; `onFailure` gets it for logging).
|
|
282
|
+
- `useSignedAnswer({ signature, load, active, delayMs, onError })` returns `{ value, ready }`: loads an async answer after a pause and shows it only for the signature it was loaded for. Put every input the answer depends on in `signature`; a thrown `load` gives `value: null` with `ready: true`. While `active` is false the stored answer is dropped (`ready` false, `value` null), so turning it back on never shows an old answer as current; it asks again whenever `signature`, `active` or `delayMs` changes. Every new run drops the stored answer first, so going from signature A to B and back to A is not ready until A is read again; a changed `load` closure alone does not ask again.
|
|
283
|
+
- `useCopyToClipboard({ copiedNote, failedNote, resetAfterMs })` returns `{ copy, note, status, reset }`: see `ShowOnceSecret` above.
|
|
284
|
+
- `usePickerSession({ source, failureMessage, resetKey, onSourceError })` returns `{ picking, open, close, search, searchError, invalidateSearch, groupProps }`: open and close state, focus (into the search box on open, back to the `data-opener` button on close), Enter never submits the form, Escape closes, and only the latest search may set `searchError`. Spread `groupProps` on ONE wrapper. REQUIRED structure, or focus handling silently does nothing: the `input[role="combobox"]` is inside that wrapper while `picking`, and a `button[data-opener]` is rendered inside it while NOT picking. `resetKey`: when it changes the session closes without moving focus, clears `searchError` and ignores a running search (use the baseline id for a field that reloads under the picker). `onSourceError(error)` is called when `source` throws (not for a returned `{ ok: false }`); the screen still shows `failureMessage`, and a throw inside the callback is swallowed. Fits a picker row that owns only open/close state (a rule's person field; a task's person field with `resetKey`). A picker whose `picking` lives in a reducer beside other state (an inbox message's person control with its own `busy`) should use only `invalidateSearch` and the shared pieces, or stay local.
|
|
254
285
|
|
|
255
286
|
### `useKeyboardShortcuts()`
|
|
256
287
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import { Component, ReactNode, ErrorInfo, ComponentType, CSSProperties, ElementType, RefObject, FormEvent } from 'react';
|
|
3
|
+
import { Component, ReactNode, ErrorInfo, ComponentType, CSSProperties, ElementType, RefObject, FormEvent, KeyboardEvent as KeyboardEvent$1 } from 'react';
|
|
4
4
|
|
|
5
5
|
interface ErrorBoundaryProps {
|
|
6
6
|
children: ReactNode;
|
|
@@ -251,6 +251,166 @@ interface ActivityFeedRowProps {
|
|
|
251
251
|
}
|
|
252
252
|
declare function ActivityFeedRow({ sentence, time, timeText, href, gone, chips, tags, maxTags, tagsLabel, actions, LinkComponent, classNames, }: ActivityFeedRowProps): react_jsx_runtime.JSX.Element;
|
|
253
253
|
|
|
254
|
+
interface RestoreButtonClassNames {
|
|
255
|
+
/** The wrapper around the button and its error. */
|
|
256
|
+
root?: string;
|
|
257
|
+
/** The button. */
|
|
258
|
+
button?: string;
|
|
259
|
+
/** The error message (role="alert"). */
|
|
260
|
+
error?: string;
|
|
261
|
+
}
|
|
262
|
+
interface RestoreButtonLabels {
|
|
263
|
+
/** Button text at rest. Default "Restore". */
|
|
264
|
+
idle?: string;
|
|
265
|
+
/** Button text while the action runs. Default "Restoring…". */
|
|
266
|
+
busy?: string;
|
|
267
|
+
}
|
|
268
|
+
interface RestoreButtonProps {
|
|
269
|
+
/** Runs the restore. Return `{ error }` for a failure a person can cause; success returns nothing or an object without `error`. */
|
|
270
|
+
action: () => Promise<{
|
|
271
|
+
error?: string;
|
|
272
|
+
} | void>;
|
|
273
|
+
/** Called after a successful restore (refresh, redirect). Not called on an error. */
|
|
274
|
+
onDone?: () => void;
|
|
275
|
+
/** Called with a thrown value, for logging. Its message is never shown. */
|
|
276
|
+
onFailure?: (error: unknown) => void;
|
|
277
|
+
labels?: RestoreButtonLabels;
|
|
278
|
+
/** Shown when the action throws. Default "Something went wrong. Please try again." */
|
|
279
|
+
failureMessage?: string;
|
|
280
|
+
classNames?: RestoreButtonClassNames;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* A "Restore" button that runs one server action once. Props: `action`, `onDone`, `onFailure`, `labels`, `failureMessage`, `classNames`.
|
|
284
|
+
*/
|
|
285
|
+
declare function RestoreButton({ action, onDone, onFailure, labels, failureMessage, classNames }: RestoreButtonProps): react_jsx_runtime.JSX.Element;
|
|
286
|
+
|
|
287
|
+
interface UndoNoticeClassNames {
|
|
288
|
+
root?: string;
|
|
289
|
+
message?: string;
|
|
290
|
+
link?: string;
|
|
291
|
+
undo?: string;
|
|
292
|
+
dismiss?: string;
|
|
293
|
+
error?: string;
|
|
294
|
+
}
|
|
295
|
+
interface UndoNoticeLabels {
|
|
296
|
+
/** The sentence for a name. Must return plain text. Default: Moved “name” to the Trash. */
|
|
297
|
+
moved?: (name: string) => string;
|
|
298
|
+
/** Default "View Trash". */
|
|
299
|
+
viewTrash?: string;
|
|
300
|
+
/** Default "Undo". */
|
|
301
|
+
undo?: string;
|
|
302
|
+
/** Default "Undoing…". */
|
|
303
|
+
undoing?: string;
|
|
304
|
+
/** Accessible name of the dismiss button. Default "Dismiss". */
|
|
305
|
+
dismiss?: string;
|
|
306
|
+
}
|
|
307
|
+
interface UndoNoticeProps {
|
|
308
|
+
/** What was moved. Rendered as text. */
|
|
309
|
+
name: string;
|
|
310
|
+
/** Restores it. Return `{ error }` for a failure a person can cause. */
|
|
311
|
+
action: () => Promise<{
|
|
312
|
+
error?: string;
|
|
313
|
+
} | void>;
|
|
314
|
+
/** Called after a successful undo (refresh the list). */
|
|
315
|
+
onDone?: () => void;
|
|
316
|
+
/** Called with a thrown value, for logging. Its message is never shown. */
|
|
317
|
+
onFailure?: (error: unknown) => void;
|
|
318
|
+
/** Where the Trash is. Without it there is no link. */
|
|
319
|
+
trashHref?: string;
|
|
320
|
+
/** Link component for `trashHref`, for example Next's Link. Default 'a'. */
|
|
321
|
+
LinkComponent?: ElementType;
|
|
322
|
+
labels?: UndoNoticeLabels;
|
|
323
|
+
/** Shown when the action throws. Default "Something went wrong. Please try again." */
|
|
324
|
+
failureMessage?: string;
|
|
325
|
+
classNames?: UndoNoticeClassNames;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The note shown after a move to the Trash, with Undo. Props: `name`, `action`, `onDone`, `onFailure`, `trashHref`, `LinkComponent`, `labels`, `failureMessage`, `classNames`.
|
|
329
|
+
*/
|
|
330
|
+
declare function UndoNotice({ name, action, onDone, onFailure, trashHref, LinkComponent, labels, failureMessage, classNames }: UndoNoticeProps): react_jsx_runtime.JSX.Element | null;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* A calendar date written as short month, day, year. Fixed `locale` (default en-US) so server and browser agree; `timeZone` (an IANA name) pins the day, default the renderer's own zone.
|
|
334
|
+
*/
|
|
335
|
+
declare function formatTrashedDate(date: Date, locale?: string, timeZone?: string): string;
|
|
336
|
+
interface TrashedBannerClassNames {
|
|
337
|
+
root?: string;
|
|
338
|
+
text?: string;
|
|
339
|
+
/** The wrapper around the `restore` slot. */
|
|
340
|
+
action?: string;
|
|
341
|
+
}
|
|
342
|
+
interface TrashedBannerLabels {
|
|
343
|
+
/** A first sentence, for example "This person is in the Trash." Default none. */
|
|
344
|
+
intro?: string;
|
|
345
|
+
/** Default "In the Trash since". */
|
|
346
|
+
since?: string;
|
|
347
|
+
/** Default "by". */
|
|
348
|
+
by?: string;
|
|
349
|
+
/** Shown instead of a date when `since` is null. Default "earlier". */
|
|
350
|
+
earlier?: string;
|
|
351
|
+
}
|
|
352
|
+
interface TrashedBannerProps {
|
|
353
|
+
/** When it was trashed; null reads as `labels.earlier`. */
|
|
354
|
+
since: Date | null;
|
|
355
|
+
/** Who trashed it. Rendered as text. */
|
|
356
|
+
by: string;
|
|
357
|
+
/** The Restore control. */
|
|
358
|
+
restore?: ReactNode;
|
|
359
|
+
/** Formats the date. Default `formatTrashedDate`. */
|
|
360
|
+
formatDate?: (date: Date) => string;
|
|
361
|
+
labels?: TrashedBannerLabels;
|
|
362
|
+
classNames?: TrashedBannerClassNames;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* The amber "in the Trash since" banner. Props: `since`, `by`, `restore`, `formatDate`, `labels`, `classNames`.
|
|
366
|
+
*/
|
|
367
|
+
declare function TrashedBanner({ since, by, restore, formatDate, labels, classNames }: TrashedBannerProps): react_jsx_runtime.JSX.Element;
|
|
368
|
+
|
|
369
|
+
interface ShowOnceSecretClassNames {
|
|
370
|
+
root?: string;
|
|
371
|
+
title?: string;
|
|
372
|
+
warning?: string;
|
|
373
|
+
secret?: string;
|
|
374
|
+
actions?: string;
|
|
375
|
+
copy?: string;
|
|
376
|
+
done?: string;
|
|
377
|
+
note?: string;
|
|
378
|
+
}
|
|
379
|
+
interface ShowOnceSecretLabels {
|
|
380
|
+
/** Default "Copy it now: you will not see it again." */
|
|
381
|
+
warning?: string;
|
|
382
|
+
/** Default "Copy". */
|
|
383
|
+
copy?: string;
|
|
384
|
+
/** Default "Done". */
|
|
385
|
+
done?: string;
|
|
386
|
+
/** Default "Copied." */
|
|
387
|
+
copied?: string;
|
|
388
|
+
/** Default "Could not copy automatically. Select the text and copy it yourself." */
|
|
389
|
+
failed?: string;
|
|
390
|
+
/** Accessible name of the secret field when `display="field"`. Default "Secret". */
|
|
391
|
+
secret?: string;
|
|
392
|
+
}
|
|
393
|
+
interface ShowOnceSecretProps {
|
|
394
|
+
/** The secret itself. Shown in the DOM and copied on request; kept nowhere else. */
|
|
395
|
+
secret: string;
|
|
396
|
+
/** What it is: "Your new key “Zapier”." */
|
|
397
|
+
title: ReactNode;
|
|
398
|
+
/** Called when Done is pressed. The parent should stop rendering the box. */
|
|
399
|
+
onDone: () => void;
|
|
400
|
+
/** 'text' (default): a code element. 'field': a read-only input that selects its text on focus. */
|
|
401
|
+
display?: 'text' | 'field';
|
|
402
|
+
/** Sets `data-testid` on the secret element, for the app's own tests. */
|
|
403
|
+
secretTestId?: string;
|
|
404
|
+
/** Extra content under the buttons (for example "give this only to the person it was made for"). */
|
|
405
|
+
children?: ReactNode;
|
|
406
|
+
labels?: ShowOnceSecretLabels;
|
|
407
|
+
classNames?: ShowOnceSecretClassNames;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* A show-once secret box. Props: `secret`, `title`, `onDone`, `display`, `secretTestId`, `children`, `labels`, `classNames`.
|
|
411
|
+
*/
|
|
412
|
+
declare function ShowOnceSecret({ secret, title, onDone, display, secretTestId, children, labels, classNames }: ShowOnceSecretProps): react_jsx_runtime.JSX.Element;
|
|
413
|
+
|
|
254
414
|
interface EntityPickerClassNames {
|
|
255
415
|
root?: string;
|
|
256
416
|
input?: string;
|
|
@@ -788,6 +948,124 @@ declare function useArrival<E extends HTMLElement>(active: boolean): {
|
|
|
788
948
|
soft: boolean;
|
|
789
949
|
};
|
|
790
950
|
|
|
951
|
+
declare const GUARDED_ACTION_FAILURE = "Something went wrong. Please try again.";
|
|
952
|
+
interface UseGuardedActionOptions<R> {
|
|
953
|
+
/** Called with the action's result when it returned no `error`. */
|
|
954
|
+
onDone?: (result: R) => void;
|
|
955
|
+
/** Called with the thrown value (for logging). Its message is never shown. */
|
|
956
|
+
onFailure?: (error: unknown) => void;
|
|
957
|
+
/** Shown when the action throws. Defaults to GUARDED_ACTION_FAILURE. */
|
|
958
|
+
failureMessage?: string;
|
|
959
|
+
}
|
|
960
|
+
interface UseGuardedActionResult<A extends unknown[]> {
|
|
961
|
+
/** Starts the action; ignored while one is running. Never rejects. */
|
|
962
|
+
run: (...args: A) => Promise<void>;
|
|
963
|
+
busy: boolean;
|
|
964
|
+
error: string | null;
|
|
965
|
+
clearError: () => void;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Runs an async action once at a time. Returns `{ run, busy, error, clearError }`.
|
|
969
|
+
* A returned `{ error }` is shown; a thrown error shows `failureMessage` only; success calls `onDone(result)`.
|
|
970
|
+
*/
|
|
971
|
+
declare function useGuardedAction<A extends unknown[], R>(action: (...args: A) => Promise<R>, options?: UseGuardedActionOptions<R>): UseGuardedActionResult<A>;
|
|
972
|
+
|
|
973
|
+
interface UseSignedAnswerOptions<T> {
|
|
974
|
+
/** Names every input the answer depends on. A new signature asks again. */
|
|
975
|
+
signature: string;
|
|
976
|
+
/** Reads the answer. Called after `delayMs`, with whatever it closes over at that moment. */
|
|
977
|
+
load: () => Promise<T>;
|
|
978
|
+
/** When false nothing is loaded and `ready` is false. Defaults to true. */
|
|
979
|
+
active?: boolean;
|
|
980
|
+
/** Pause before loading, in ms. Defaults to 0 (load at once). */
|
|
981
|
+
delayMs?: number;
|
|
982
|
+
/** Called with the thrown value when `load` throws (for logging). */
|
|
983
|
+
onError?: (error: unknown) => void;
|
|
984
|
+
}
|
|
985
|
+
interface UseSignedAnswerResult<T> {
|
|
986
|
+
/** The answer for the current signature, or null while unanswered or when it could not be read. */
|
|
987
|
+
value: T | null;
|
|
988
|
+
/** True once the CURRENT signature has answered (also when it could not be read). */
|
|
989
|
+
ready: boolean;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Loads an answer keyed by `signature`, after an optional pause, and returns `{ value, ready }` for the current signature only.
|
|
993
|
+
*/
|
|
994
|
+
declare function useSignedAnswer<T>({ signature, load, active, delayMs, onError }: UseSignedAnswerOptions<T>): UseSignedAnswerResult<T>;
|
|
995
|
+
|
|
996
|
+
declare const COPY_NOTE_COPIED = "Copied.";
|
|
997
|
+
declare const COPY_NOTE_FAILED = "Could not copy automatically. Select the text and copy it yourself.";
|
|
998
|
+
interface UseCopyToClipboardOptions {
|
|
999
|
+
/** Note after a successful copy. Default COPY_NOTE_COPIED. */
|
|
1000
|
+
copiedNote?: string;
|
|
1001
|
+
/** Note after a failed copy. Default COPY_NOTE_FAILED. */
|
|
1002
|
+
failedNote?: string;
|
|
1003
|
+
/** Clear the note this many milliseconds after it was set. Default: never. */
|
|
1004
|
+
resetAfterMs?: number;
|
|
1005
|
+
}
|
|
1006
|
+
interface UseCopyToClipboardResult {
|
|
1007
|
+
/** Copies `text`. Resolves true when the clipboard took it, false otherwise; never rejects. */
|
|
1008
|
+
copy: (text: string) => Promise<boolean>;
|
|
1009
|
+
/** The sentence to show, or null before any copy (and after `reset`). */
|
|
1010
|
+
note: string | null;
|
|
1011
|
+
/** 'copied', 'failed' or null: for a caller that styles the two differently. */
|
|
1012
|
+
status: 'copied' | 'failed' | null;
|
|
1013
|
+
/** Clears the note (call it when the thing that was copied changes or goes away). */
|
|
1014
|
+
reset: () => void;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Copy to the clipboard with a spoken result. Returns `{ copy, note, status, reset }`; `copy` never throws.
|
|
1018
|
+
*/
|
|
1019
|
+
declare function useCopyToClipboard(options?: UseCopyToClipboardOptions): UseCopyToClipboardResult;
|
|
1020
|
+
|
|
1021
|
+
declare const PICKER_SEARCH_FAILURE = "The search could not be run. Check your connection, then try again.";
|
|
1022
|
+
type PickerSearchResult<O> = {
|
|
1023
|
+
ok: true;
|
|
1024
|
+
options: O[];
|
|
1025
|
+
} | {
|
|
1026
|
+
ok: false;
|
|
1027
|
+
error: string;
|
|
1028
|
+
};
|
|
1029
|
+
interface UsePickerSessionOptions<O> {
|
|
1030
|
+
/** The caller's search. It may return a refusal or throw. */
|
|
1031
|
+
source: (query: string) => Promise<PickerSearchResult<O>>;
|
|
1032
|
+
/** Shown as `searchError` when `source` throws. Defaults to PICKER_SEARCH_FAILURE. */
|
|
1033
|
+
failureMessage?: string;
|
|
1034
|
+
/** When this value changes (compared with Object.is) the session closes WITHOUT moving focus, clears `searchError` and drops a running search. Use it for "the page loaded something new", for example the id of the baseline the picker edits. */
|
|
1035
|
+
resetKey?: unknown;
|
|
1036
|
+
/** Called with the thrown value when `source` throws (not for a returned `{ ok: false }`). The UI text stays `failureMessage`. An error thrown by this callback is swallowed. */
|
|
1037
|
+
onSourceError?: (error: unknown) => void;
|
|
1038
|
+
}
|
|
1039
|
+
interface UsePickerSessionResult<O> {
|
|
1040
|
+
picking: boolean;
|
|
1041
|
+
open: () => void;
|
|
1042
|
+
/** Closes, returns focus to the opener, invalidates a running search and clears `searchError`. */
|
|
1043
|
+
close: () => void;
|
|
1044
|
+
/** Pass to the picker's `search`. Resolves with the options; rejects on a refusal or failure (the picker shows none). */
|
|
1045
|
+
search: (query: string) => Promise<O[]>;
|
|
1046
|
+
searchError: string | null;
|
|
1047
|
+
/** Makes any running search ignored from now on (it can no longer set `searchError`). */
|
|
1048
|
+
invalidateSearch: () => void;
|
|
1049
|
+
/** Spread on the wrapping element. */
|
|
1050
|
+
groupProps: {
|
|
1051
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
1052
|
+
onKeyDown: (event: KeyboardEvent$1<HTMLDivElement>) => void;
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* State, focus handling and key handling for an inline search picker. Returns
|
|
1057
|
+
* `{ picking, open, close, search, searchError, invalidateSearch, groupProps }`.
|
|
1058
|
+
*
|
|
1059
|
+
* Structure the markup must have (otherwise focus handling silently does nothing): ONE element receives `groupProps`;
|
|
1060
|
+
* inside it, `input[role="combobox"]` exists while `picking`, and `button[data-opener]` exists while NOT picking.
|
|
1061
|
+
*
|
|
1062
|
+
* Fits: a picker row that owns only open/close state (for example a rule's person field, or a task's person field with
|
|
1063
|
+
* `resetKey` set to the baseline id). Does not fit as-is: a picker whose `picking` lives in a reducer next to other
|
|
1064
|
+
* state (for example an inbox message's person control with its own `busy` state): use only `invalidateSearch` and the
|
|
1065
|
+
* shared pieces, or keep it local.
|
|
1066
|
+
*/
|
|
1067
|
+
declare function usePickerSession<O>({ source, failureMessage, resetKey, onSourceError }: UsePickerSessionOptions<O>): UsePickerSessionResult<O>;
|
|
1068
|
+
|
|
791
1069
|
interface CachedFetchOptions {
|
|
792
1070
|
/** fetch RequestInit options */
|
|
793
1071
|
fetchOptions?: RequestInit;
|
|
@@ -1005,4 +1283,4 @@ declare const ACTIVITY_ICONS: Record<string, IconComponent>;
|
|
|
1005
1283
|
/** Return the icon component for a given icon name, or Activity as fallback. */
|
|
1006
1284
|
declare function resolveActivityIcon(name: string): IconComponent;
|
|
1007
1285
|
|
|
1008
|
-
export { ACTIVITY_ICONS, ALL_SHORTCUT_CONTEXTS, ARRIVAL_FADE_MS, type ActivityFeedChip, ActivityFeedRow, type ActivityFeedRowClassNames, type ActivityFeedRowProps, ArchiveButton, type ArchiveButtonProps, CLIENT_PROFILE_SHORTCUTS, type CachedFetchOptions, type ComposeMode, ConfirmAction, type ConfirmActionClassNames, type ConfirmActionProps, type ConfirmActionResult, EmailBodyRenderer, type EmailBodyRendererProps, EmailThreadView, type EmailThreadViewProps, EntityPicker, type EntityPickerClassNames, type EntityPickerProps, ErrorBoundary, type ErrorBoundaryProps, FORM_SHORTCUTS, GLOBAL_SHORTCUTS, INBOX_SHORTCUTS, type KeyboardShortcut, KeyboardShortcutsPanel, RENDER_ERRORS, REPLY_LAYOUT_OPTIONS, type RenderErrorResult, type ReplyLayout, ReplyPanel, type ReplyPanelProps, type ReplySendOverrides, RichTextEditor, type RichTextEditorProps, type SchedulePreset, type ShortcutContext, type ShortcutDefinition, type ThreadMessage, type UseAutoSaveOptions, type UseAutoSaveResult, type UseKeyboardShortcutsOptions, type UsePollingOptions, type UsePollingResult, type UsePreferencesOptions, type UsePreferencesResult, type UseServerSearchOptions, type UseServerSearchResult, cachedFetch, canViewInline, clearCache, formatDateGroup, formatFileSize, formatPhone, formatPhoneInput, getNextMondayMorning, getNextWeekday, getQuickScheduleOptions, getShortcut, getTomorrowMorning, groupByDate, invalidateCache, isAudio, isDocument, isEmptyHtml, isImage, isInlineLayout, isModalLayout, isPdf, isPopoutLayout, isSpreadsheet, isTypingContext, isValidScheduleDate, isVideo, opensInNewTab, parseCustomSchedule, prefetch, renderError, resolveActivityIcon, resolveContentType, stripHtml, stripPhone, truncatePreview, useArrival, useAutoSave, useContextShortcuts, useFormActionKeepingInput, useIframeFocusReclaim, useKeyboardShortcuts, usePolling, usePreferences, useSavedNotice, useServerSearch, useSyncedSelect, withErrorBoundary };
|
|
1286
|
+
export { ACTIVITY_ICONS, ALL_SHORTCUT_CONTEXTS, ARRIVAL_FADE_MS, type ActivityFeedChip, ActivityFeedRow, type ActivityFeedRowClassNames, type ActivityFeedRowProps, ArchiveButton, type ArchiveButtonProps, CLIENT_PROFILE_SHORTCUTS, COPY_NOTE_COPIED, COPY_NOTE_FAILED, type CachedFetchOptions, type ComposeMode, ConfirmAction, type ConfirmActionClassNames, type ConfirmActionProps, type ConfirmActionResult, EmailBodyRenderer, type EmailBodyRendererProps, EmailThreadView, type EmailThreadViewProps, EntityPicker, type EntityPickerClassNames, type EntityPickerProps, ErrorBoundary, type ErrorBoundaryProps, FORM_SHORTCUTS, GLOBAL_SHORTCUTS, GUARDED_ACTION_FAILURE, INBOX_SHORTCUTS, type KeyboardShortcut, KeyboardShortcutsPanel, PICKER_SEARCH_FAILURE, type PickerSearchResult, RENDER_ERRORS, REPLY_LAYOUT_OPTIONS, type RenderErrorResult, type ReplyLayout, ReplyPanel, type ReplyPanelProps, type ReplySendOverrides, RestoreButton, type RestoreButtonClassNames, type RestoreButtonLabels, type RestoreButtonProps, RichTextEditor, type RichTextEditorProps, type SchedulePreset, type ShortcutContext, type ShortcutDefinition, ShowOnceSecret, type ShowOnceSecretClassNames, type ShowOnceSecretLabels, type ShowOnceSecretProps, type ThreadMessage, TrashedBanner, type TrashedBannerClassNames, type TrashedBannerLabels, type TrashedBannerProps, UndoNotice, type UndoNoticeClassNames, type UndoNoticeLabels, type UndoNoticeProps, type UseAutoSaveOptions, type UseAutoSaveResult, type UseCopyToClipboardOptions, type UseCopyToClipboardResult, type UseGuardedActionOptions, type UseGuardedActionResult, type UseKeyboardShortcutsOptions, type UsePickerSessionOptions, type UsePickerSessionResult, type UsePollingOptions, type UsePollingResult, type UsePreferencesOptions, type UsePreferencesResult, type UseServerSearchOptions, type UseServerSearchResult, type UseSignedAnswerOptions, type UseSignedAnswerResult, cachedFetch, canViewInline, clearCache, formatDateGroup, formatFileSize, formatPhone, formatPhoneInput, formatTrashedDate, getNextMondayMorning, getNextWeekday, getQuickScheduleOptions, getShortcut, getTomorrowMorning, groupByDate, invalidateCache, isAudio, isDocument, isEmptyHtml, isImage, isInlineLayout, isModalLayout, isPdf, isPopoutLayout, isSpreadsheet, isTypingContext, isValidScheduleDate, isVideo, opensInNewTab, parseCustomSchedule, prefetch, renderError, resolveActivityIcon, resolveContentType, stripHtml, stripPhone, truncatePreview, useArrival, useAutoSave, useContextShortcuts, useCopyToClipboard, useFormActionKeepingInput, useGuardedAction, useIframeFocusReclaim, useKeyboardShortcuts, usePickerSession, usePolling, usePreferences, useSavedNotice, useServerSearch, useSignedAnswer, useSyncedSelect, withErrorBoundary };
|