@ordinatio/ui 1.3.0 → 1.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 CHANGED
@@ -141,6 +141,77 @@ const messages: ThreadMessage[] = [...];
141
141
 
142
142
  ---
143
143
 
144
+ ### `<EntityPicker>`
145
+
146
+ A searchable single-select for a collection too large to list (people, companies, products): type, search through an async callback, choose by mouse or keyboard, clear. It knows nothing about what the items are.
147
+
148
+ ```tsx
149
+ import { EntityPicker } from '@ordinatio/ui';
150
+
151
+ <EntityPicker<Person>
152
+ value={selected} // controlled: the picker calls onChange, it never changes the value itself
153
+ onChange={setSelected} // the chosen item, or null when cleared
154
+ search={(query, signal) => findPeople(query, { signal })} // reject to show errorText; honour `signal` when you can
155
+ getKey={(person) => person.id}
156
+ getLabel={(person) => person.name || person.email}
157
+ ariaLabel="Person" // names the input AND its list; or pass `id` and use an external <label> (which names only the input)
158
+ name="contactId" // optional: a hidden input with the selected key, for plain forms / Server Actions
159
+ renderOption={(person, { active }) => <PersonRow person={person} active={active} />} // optional
160
+ />
161
+ ```
162
+
163
+ **Searching**
164
+ - Debounced (`debounceMs`, default 200); needs `minChars` typed (default 1; whitespace does not count, and the search receives the trimmed text).
165
+ - A superseded search is aborted, so a slow early answer can never overwrite a newer one.
166
+ - A failed search shows `errorText` (never silent: a `search` that rejects, throws, or resolves to something other than an array all count as failed); typing again retries.
167
+
168
+ **Keyboard, mouse and focus**
169
+ - The input shows the selected label until you type; leaving the field reverts a half-typed query to the selection (switching to another window does not). Focusing, choosing an option and Escape all leave the label selected, so typing replaces it instead of appending.
170
+ - Enter chooses the highlighted option and never submits an enclosing form while the popup (results or a status message) is showing. Arrow keys wrap and keep the highlight scrolled into view.
171
+ - While a new search is loading nothing is highlighted (hover included) and Enter and the arrow keys do nothing, so a result of an older query cannot be chosen by accident; clicking an option that is drawn still chooses it.
172
+ - Escape reverts typed text and closes the popup, and is not passed on to an enclosing dialog while there is either. Keys pressed while an IME is composing are ignored (`keyCode` 229 included; a few Android soft keyboards report 229 for every key, where Enter is then ignored but clicking still works).
173
+ - Options are chosen by click (so it works on touch); pressing anywhere in the popup, including its scrollbar, keeps focus in the input. Clearing returns focus to the input.
174
+
175
+ **Accessibility**
176
+ - Follows the WAI-ARIA 1.2 combobox pattern (role `combobox`, a `listbox` of `option`s that exists only when there are results; the loading, empty and error messages sit beside it, not inside). Those messages are announced through one always-mounted, visually hidden `role="status"` live region; the visible copies are `aria-hidden`.
177
+
178
+ **Forms, disabling and styling**
179
+ - `name` renders a hidden input with the selected key (`''` when none), for plain forms and Server Actions. `disabled` disables the input and the hidden input and removes the clear button; disabling while the user is typing reverts the text.
180
+ - Styling: plain elements with default inline styles. `classNames.<part>` (`root`, `input`, `clear`, `list`, `option`, `optionActive`, `message`) REPLACES that part's defaults entirely, so Tailwind or shadcn consumers can restyle everything; `style` layers onto the root defaults. Text props: `placeholder`, `clearLabel`, `loadingText`, `emptyText`, `errorText`. `clearable` (default true) shows a clear button while an item is selected.
181
+ - Nothing outlives the component: an unmounted picker cancels its timer and aborts its request.
182
+
183
+ ### `<ConfirmAction>`
184
+
185
+ An "Are you sure?" that stays **inside the page**: no browser pop-up (`confirm()`, `alert()`, `prompt()`), so it can be styled, tested and driven by automation. One button opens a question with two buttons; the safe one is focused.
186
+
187
+ ```tsx
188
+ import { ConfirmAction } from '@ordinatio/ui';
189
+
190
+ <ConfirmAction
191
+ triggerLabel="Delete"
192
+ question={'Delete this note?\n\nThis cannot be undone.'} // line breaks are kept; any React content works
193
+ confirmLabel="Delete this note"
194
+ pendingLabel="Deleting…"
195
+ keepLabel="Keep it" // optional, the default
196
+ onConfirm={async () => { // must return a Promise (use an async function)
197
+ const result = await deleteNote(id); // RETURN errors: { error: 'Could not delete.' } stays open with the message
198
+ return result.ok ? undefined : { error: result.message }; // any object without `error` (for example { ok: true }) counts as success
199
+ }}
200
+ />
201
+ ```
202
+
203
+ **Behaviour**
204
+ - Nothing runs until the confirm button is pressed. The question opens in place (`role="group"`), focus goes to the **safe** button, and again after a failed confirm (a disabled button loses focus, so Escape would otherwise be dead).
205
+ - Escape and the safe button close it, call nothing and give focus back to the trigger. Escape is never passed on to an enclosing dialog (one key closes only this question; while the action runs it closes nothing but still does not reach the dialog).
206
+ - While the action runs, focus is held on the group itself, so Escape is still caught here even if the browser drops focus from the disabled buttons.
207
+ - Results: return nothing, or an object. Only an object whose `error` is a non-empty string is a failure (anything else, such as `{ ok: true }` or a non-text `error`, is success). Use a type alias or an object literal for the result type: a TypeScript `interface` does not satisfy the open index signature.
208
+ - On success it closes, and focus goes back to the trigger only if nothing has taken it (the row is usually removed or the caller moves focus): focus the caller moved is left alone.
209
+ - The confirm button is disabled and shows `pendingLabel` while the action runs; two clicks in the same batch run it **once** (an in-flight ref, since React has not re-rendered between them).
210
+ - `{ error }` keeps the question open with the message in a `role="alert"`. A thrown rejection shows `errorFallback` (default "Something went wrong. Please try again.") instead of hanging open. Success closes it.
211
+ - `disabled` disables the trigger only (an open question stays answerable). `groupLabel` names the open group (default: the question itself, through `aria-labelledby`, whatever React content it is). A state update after the component unmounted (the row was removed) is harmless on React 18 and later, the package's peer range.
212
+
213
+ **Styling**: plain elements with default inline styles. `classNames.<part>` (`trigger`, `group`, `question`, `confirm`, `keep`, `error`) REPLACES that part's defaults entirely, so Tailwind or shadcn consumers restyle everything (including the pending look of the buttons: style `:disabled`).
214
+
144
215
  ## Hooks
145
216
 
146
217
  ### `useKeyboardShortcuts()`
package/dist/index.d.mts CHANGED
@@ -156,6 +156,95 @@ interface ArchiveButtonProps {
156
156
  */
157
157
  declare function ArchiveButton({ onArchive, archiving, disabled, label, archivingLabel, className, style, }: ArchiveButtonProps): react_jsx_runtime.JSX.Element;
158
158
 
159
+ /** What the action returns: nothing or any object WITHOUT an `error` (success), or an object with an `error` message (a failure a person can cause, shown in the open question). Extra properties are allowed, so `{ ok: true }` or a Server Action's own result type fits. */
160
+ type ConfirmActionResult = {
161
+ error?: string;
162
+ [extra: string]: unknown;
163
+ } | void;
164
+ interface ConfirmActionClassNames {
165
+ /** The button that opens the question. */
166
+ trigger?: string;
167
+ /** The wrapper (role="group") around the open question. */
168
+ group?: string;
169
+ /** The question text. */
170
+ question?: string;
171
+ /** The confirm (destructive) button. */
172
+ confirm?: string;
173
+ /** The safe ("Keep it") button. */
174
+ keep?: string;
175
+ /** The error message. */
176
+ error?: string;
177
+ }
178
+ interface ConfirmActionProps {
179
+ /** Label of the button that opens the question. */
180
+ triggerLabel: string;
181
+ /** The question; line breaks are kept. */
182
+ question: ReactNode;
183
+ /** Label of the confirm button. */
184
+ confirmLabel: string;
185
+ /** Label of the confirm button while the action runs. */
186
+ pendingLabel: string;
187
+ /** Label of the safe button. Default: "Keep it". */
188
+ keepLabel?: string;
189
+ /** Runs when the person confirms. Return `{ error }` for a failure; success returns nothing. */
190
+ onConfirm: () => Promise<ConfirmActionResult>;
191
+ /** Shown when `onConfirm` throws. Default: "Something went wrong. Please try again." */
192
+ errorFallback?: string;
193
+ /** Disables the trigger (the question cannot be opened). */
194
+ disabled?: boolean;
195
+ /** Accessible name of the open group. Default: the question itself (aria-labelledby), whatever React content it is. */
196
+ groupLabel?: string;
197
+ classNames?: ConfirmActionClassNames;
198
+ }
199
+ declare function ConfirmAction({ triggerLabel, question, confirmLabel, pendingLabel, keepLabel, onConfirm, errorFallback, disabled, groupLabel, classNames, }: ConfirmActionProps): react_jsx_runtime.JSX.Element;
200
+
201
+ interface EntityPickerClassNames {
202
+ root?: string;
203
+ input?: string;
204
+ clear?: string;
205
+ list?: string;
206
+ option?: string;
207
+ optionActive?: string;
208
+ message?: string;
209
+ }
210
+ interface EntityPickerProps<T> {
211
+ /** The selected item, or null. Controlled: the picker never changes it by itself, it calls `onChange`. */
212
+ value: T | null;
213
+ /** Called with the chosen item, or null when the selection is cleared. */
214
+ onChange: (item: T | null) => void;
215
+ /** Finds items for a query. Must honour `signal` when it can (a superseded search is aborted). Reject (or throw) to show `errorText`. */
216
+ search: (query: string, signal: AbortSignal) => Promise<T[]>;
217
+ /** A stable unique key for an item (used for list keys, the hidden input and ids). */
218
+ getKey: (item: T) => string;
219
+ /** The text for an item: shown in the input when selected, and the default option text. */
220
+ getLabel: (item: T) => string;
221
+ /** Draws an option row. Default: the label. */
222
+ renderOption?: (item: T, state: {
223
+ active: boolean;
224
+ }) => ReactNode;
225
+ /** Accessible name of the input AND its listbox. Pass this, or pass `id` and use an external <label> (which then names only the input). */
226
+ ariaLabel?: string;
227
+ id?: string;
228
+ /** When set, a hidden input with this name carries the selected key ('' when none), for plain forms. */
229
+ name?: string;
230
+ placeholder?: string;
231
+ disabled?: boolean;
232
+ /** Characters typed before a search runs (default 1). Typing fewer closes the list; nothing is searched on focus alone. */
233
+ minChars?: number;
234
+ /** Debounce in ms (default 200). */
235
+ debounceMs?: number;
236
+ /** Show a clear (×) button while an item is selected (default true). */
237
+ clearable?: boolean;
238
+ clearLabel?: string;
239
+ loadingText?: string;
240
+ emptyText?: string;
241
+ errorText?: string;
242
+ classNames?: EntityPickerClassNames;
243
+ /** Layered onto the ROOT's default styles only (to size or place the picker); other parts take `classNames`. */
244
+ style?: CSSProperties;
245
+ }
246
+ declare function EntityPicker<T>({ value, onChange, search, getKey, getLabel, renderOption, ariaLabel, id, name, placeholder, disabled, minChars, debounceMs, clearable, clearLabel, loadingText, emptyText, errorText, classNames, style, }: EntityPickerProps<T>): react_jsx_runtime.JSX.Element;
247
+
159
248
  interface RichTextEditorProps {
160
249
  /**
161
250
  * Current HTML content. NOT sanitized by this component — see this
@@ -827,4 +916,4 @@ declare const ACTIVITY_ICONS: Record<string, IconComponent>;
827
916
  /** Return the icon component for a given icon name, or Activity as fallback. */
828
917
  declare function resolveActivityIcon(name: string): IconComponent;
829
918
 
830
- export { ACTIVITY_ICONS, ALL_SHORTCUT_CONTEXTS, ArchiveButton, type ArchiveButtonProps, CLIENT_PROFILE_SHORTCUTS, type CachedFetchOptions, type ComposeMode, EmailBodyRenderer, type EmailBodyRendererProps, EmailThreadView, type EmailThreadViewProps, 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, useAutoSave, useContextShortcuts, useIframeFocusReclaim, useKeyboardShortcuts, usePolling, usePreferences, useServerSearch, withErrorBoundary };
919
+ export { ACTIVITY_ICONS, ALL_SHORTCUT_CONTEXTS, 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, useAutoSave, useContextShortcuts, useIframeFocusReclaim, useKeyboardShortcuts, usePolling, usePreferences, useServerSearch, withErrorBoundary };
package/dist/index.mjs CHANGED
@@ -693,8 +693,330 @@ function ArchiveButton({
693
693
  );
694
694
  }
695
695
 
696
+ // src/components/confirm-action.tsx
697
+ import { useEffect as useEffect2, useId, useRef as useRef2, useState as useState3 } from "react";
698
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
699
+ var defaults = {
700
+ trigger: { padding: "4px 8px", fontSize: "14px", border: "1px solid transparent", borderRadius: "6px", backgroundColor: "transparent", color: "#b91c1c", cursor: "pointer" },
701
+ group: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: "8px", fontSize: "14px", outline: "none" },
702
+ question: { color: "#171717", whiteSpace: "pre-line" },
703
+ confirm: { padding: "4px 10px", fontSize: "14px", border: "1px solid #b91c1c", borderRadius: "6px", backgroundColor: "#b91c1c", color: "#ffffff", cursor: "pointer" },
704
+ keep: { padding: "4px 10px", fontSize: "14px", border: "1px solid #d4d4d4", borderRadius: "6px", backgroundColor: "#ffffff", color: "#404040", cursor: "pointer" },
705
+ error: { width: "100%", margin: 0, color: "#b91c1c" }
706
+ };
707
+ var disabledStyle2 = { opacity: 0.6, cursor: "not-allowed" };
708
+ function ConfirmAction({
709
+ triggerLabel,
710
+ question,
711
+ confirmLabel,
712
+ pendingLabel,
713
+ keepLabel = "Keep it",
714
+ onConfirm,
715
+ errorFallback = "Something went wrong. Please try again.",
716
+ disabled = false,
717
+ groupLabel,
718
+ classNames
719
+ }) {
720
+ const [open, setOpen] = useState3(false);
721
+ const [pending, setPending] = useState3(false);
722
+ const [error, setError] = useState3();
723
+ const triggerRef = useRef2(null);
724
+ const keepRef = useRef2(null);
725
+ const groupRef = useRef2(null);
726
+ const inFlight = useRef2(false);
727
+ const questionId = useId();
728
+ const restoreFocus = useRef2(null);
729
+ useEffect2(() => {
730
+ if (!open) return;
731
+ if (!pending) {
732
+ keepRef.current?.focus();
733
+ return;
734
+ }
735
+ const active = document.activeElement;
736
+ if (!active || active === document.body || groupRef.current?.contains(active)) groupRef.current?.focus();
737
+ }, [open, pending]);
738
+ const part = (key, isDisabled = false) => {
739
+ const className = classNames?.[key];
740
+ return className ? { className } : { style: isDisabled ? { ...defaults[key], ...disabledStyle2 } : defaults[key] };
741
+ };
742
+ useEffect2(() => {
743
+ if (open || restoreFocus.current === null) return;
744
+ const mode = restoreFocus.current;
745
+ restoreFocus.current = null;
746
+ const active = document.activeElement;
747
+ if (mode === "always" || !active || active === document.body) triggerRef.current?.focus();
748
+ }, [open]);
749
+ const close = () => {
750
+ restoreFocus.current = "always";
751
+ setOpen(false);
752
+ setError(void 0);
753
+ };
754
+ const confirm = async () => {
755
+ if (inFlight.current) return;
756
+ inFlight.current = true;
757
+ setPending(true);
758
+ setError(void 0);
759
+ try {
760
+ const result = await onConfirm();
761
+ if (result && typeof result.error === "string" && result.error !== "") {
762
+ setError(result.error);
763
+ } else {
764
+ restoreFocus.current = "ifLost";
765
+ setOpen(false);
766
+ }
767
+ } catch {
768
+ setError(errorFallback);
769
+ } finally {
770
+ inFlight.current = false;
771
+ setPending(false);
772
+ }
773
+ };
774
+ if (!open) {
775
+ return /* @__PURE__ */ jsx5("button", { ref: triggerRef, type: "button", disabled, onClick: () => setOpen(true), ...part("trigger", disabled), children: triggerLabel });
776
+ }
777
+ const onKeyDown = (event) => {
778
+ if (event.key !== "Escape") return;
779
+ event.stopPropagation();
780
+ if (!pending) close();
781
+ };
782
+ return /* @__PURE__ */ jsxs4("div", { ref: groupRef, tabIndex: -1, role: "group", "aria-label": groupLabel, "aria-labelledby": groupLabel ? void 0 : questionId, onKeyDown, ...part("group"), children: [
783
+ /* @__PURE__ */ jsx5("span", { id: questionId, ...part("question"), children: question }),
784
+ /* @__PURE__ */ jsx5("button", { type: "button", disabled: pending, onClick: confirm, ...part("confirm", pending), children: pending ? pendingLabel : confirmLabel }),
785
+ /* @__PURE__ */ jsx5("button", { ref: keepRef, type: "button", disabled: pending, onClick: close, ...part("keep", pending), children: keepLabel }),
786
+ error ? /* @__PURE__ */ jsx5("p", { role: "alert", ...part("error"), children: error }) : null
787
+ ] });
788
+ }
789
+
790
+ // src/components/entity-picker.tsx
791
+ import { useCallback as useCallback2, useEffect as useEffect3, useId as useId2, useRef as useRef3, useState as useState4 } from "react";
792
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
793
+ var defaults2 = {
794
+ root: { position: "relative", display: "inline-flex", alignItems: "center", gap: "4px", width: "100%" },
795
+ input: { flex: 1, minWidth: 0, padding: "8px 10px", fontSize: "14px", border: "1px solid #d4d4d4", borderRadius: "6px", backgroundColor: "#ffffff", color: "#171717" },
796
+ clear: { padding: "4px 8px", fontSize: "14px", border: "1px solid transparent", borderRadius: "6px", backgroundColor: "transparent", color: "#525252", cursor: "pointer" },
797
+ list: { position: "absolute", top: "100%", left: 0, right: 0, zIndex: 20, margin: "4px 0 0", padding: "4px", maxHeight: "240px", overflowY: "auto", border: "1px solid #d4d4d4", borderRadius: "6px", backgroundColor: "#ffffff", boxShadow: "0 4px 12px rgba(0,0,0,0.12)" },
798
+ message: { padding: "6px 8px", fontSize: "13px", color: "#525252" }
799
+ };
800
+ var optionDefaults = {
801
+ base: { padding: "6px 8px", fontSize: "14px", borderRadius: "4px", cursor: "pointer", color: "#171717" },
802
+ active: { backgroundColor: "#f5f5f5" }
803
+ };
804
+ var visuallyHidden = { position: "absolute", width: "1px", height: "1px", margin: "-1px", padding: 0, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 };
805
+ function EntityPicker({
806
+ value,
807
+ onChange,
808
+ search,
809
+ getKey,
810
+ getLabel,
811
+ renderOption,
812
+ ariaLabel,
813
+ id,
814
+ name,
815
+ placeholder,
816
+ disabled = false,
817
+ minChars = 1,
818
+ debounceMs = 200,
819
+ clearable = true,
820
+ clearLabel = "Clear selection",
821
+ loadingText = "Searching\u2026",
822
+ emptyText = "No matches",
823
+ errorText = "Search failed. Keep typing to try again.",
824
+ classNames,
825
+ style
826
+ }) {
827
+ const listId = useId2();
828
+ const listRef = useRef3(null);
829
+ const inputRef = useRef3(null);
830
+ const selectAfterRender = useRef3(null);
831
+ const [text, setText] = useState4("");
832
+ const [editing, setEditing] = useState4(false);
833
+ const [open, setOpen] = useState4(false);
834
+ const [results, setResults] = useState4([]);
835
+ const [status, setStatus] = useState4("idle");
836
+ const [searched, setSearched] = useState4(false);
837
+ const [activeIndex, setActiveIndex] = useState4(-1);
838
+ const timer = useRef3(null);
839
+ const controller = useRef3(null);
840
+ const latest = useRef3(0);
841
+ const cancelSearch = useCallback2(() => {
842
+ if (timer.current) clearTimeout(timer.current);
843
+ timer.current = null;
844
+ controller.current?.abort();
845
+ controller.current = null;
846
+ latest.current++;
847
+ }, []);
848
+ useEffect3(() => cancelSearch, [cancelSearch]);
849
+ const runSearch = useCallback2(
850
+ (query) => {
851
+ cancelSearch();
852
+ const trimmed = query.trim();
853
+ if (trimmed.length < minChars) {
854
+ setResults([]);
855
+ setStatus("idle");
856
+ setSearched(false);
857
+ setActiveIndex(-1);
858
+ return;
859
+ }
860
+ const ticket = latest.current;
861
+ setStatus("loading");
862
+ setActiveIndex(-1);
863
+ timer.current = setTimeout(() => {
864
+ const abort = new AbortController();
865
+ controller.current = abort;
866
+ const fail = () => {
867
+ if (ticket !== latest.current) return;
868
+ setResults([]);
869
+ setSearched(false);
870
+ setStatus("error");
871
+ setActiveIndex(-1);
872
+ };
873
+ Promise.resolve().then(() => search(trimmed, abort.signal)).then((items) => {
874
+ if (ticket !== latest.current) return;
875
+ if (!Array.isArray(items)) return fail();
876
+ setResults(items);
877
+ setSearched(true);
878
+ setStatus("idle");
879
+ setActiveIndex(items.length > 0 ? 0 : -1);
880
+ }).catch(fail);
881
+ }, debounceMs);
882
+ },
883
+ [cancelSearch, debounceMs, minChars, search]
884
+ );
885
+ const stopEditing = () => {
886
+ cancelSearch();
887
+ setEditing(false);
888
+ setOpen(false);
889
+ setText("");
890
+ setResults([]);
891
+ setStatus("idle");
892
+ setSearched(false);
893
+ setActiveIndex(-1);
894
+ };
895
+ const choose = (item) => {
896
+ selectAfterRender.current = { key: getKey(item) };
897
+ stopEditing();
898
+ onChange(item);
899
+ };
900
+ const showPopup = open && !disabled && (status !== "idle" || searched);
901
+ const showListbox = showPopup && results.length > 0;
902
+ const activeId = showListbox && activeIndex >= 0 ? `${listId}-opt-${activeIndex}` : void 0;
903
+ const announcement = !showPopup ? "" : status === "loading" ? loadingText : status === "error" ? errorText : results.length === 0 ? emptyText : "";
904
+ useEffect3(() => {
905
+ if (showListbox && activeIndex >= 0) listRef.current?.children[activeIndex]?.scrollIntoView?.({ block: "nearest" });
906
+ }, [showListbox, activeIndex]);
907
+ useEffect3(() => {
908
+ const pending = selectAfterRender.current;
909
+ if (!pending || editing) return;
910
+ if ((value ? getKey(value) : null) !== pending.key) return;
911
+ selectAfterRender.current = null;
912
+ if (document.activeElement === inputRef.current) inputRef.current?.select();
913
+ }, [value, editing, getKey]);
914
+ useEffect3(() => {
915
+ if (disabled) stopEditing();
916
+ }, [disabled]);
917
+ const onKeyDown = (event) => {
918
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
919
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
920
+ if (!showListbox || status === "loading") return;
921
+ event.preventDefault();
922
+ const step = event.key === "ArrowDown" ? 1 : -1;
923
+ setActiveIndex((index) => (index + step + results.length) % results.length);
924
+ } else if (event.key === "Enter") {
925
+ if (!showPopup) return;
926
+ event.preventDefault();
927
+ if (status !== "loading" && activeIndex >= 0 && results[activeIndex]) choose(results[activeIndex]);
928
+ } else if (event.key === "Escape") {
929
+ if (open) {
930
+ event.preventDefault();
931
+ event.stopPropagation();
932
+ selectAfterRender.current = { key: value ? getKey(value) : null };
933
+ stopEditing();
934
+ }
935
+ }
936
+ };
937
+ const partProps = (key) => {
938
+ const className = classNames?.[key];
939
+ if (className) return { className, style: key === "root" ? style : void 0 };
940
+ return { style: key === "root" ? { ...defaults2.root, ...style } : defaults2[key] };
941
+ };
942
+ const optionProps = (active) => {
943
+ const optionClass = classNames?.option;
944
+ const activeClass = classNames?.optionActive;
945
+ const className = [optionClass, active ? activeClass : void 0].filter(Boolean).join(" ") || void 0;
946
+ return { className, style: optionClass ? void 0 : { ...optionDefaults.base, ...active && !activeClass ? optionDefaults.active : {} } };
947
+ };
948
+ const shown = editing ? text : value ? getLabel(value) : "";
949
+ return /* @__PURE__ */ jsxs5("div", { ...partProps("root"), children: [
950
+ /* @__PURE__ */ jsx6(
951
+ "input",
952
+ {
953
+ ...partProps("input"),
954
+ ref: inputRef,
955
+ id,
956
+ type: "text",
957
+ role: "combobox",
958
+ "aria-label": ariaLabel,
959
+ "aria-expanded": showListbox,
960
+ "aria-controls": showListbox ? listId : void 0,
961
+ "aria-autocomplete": "list",
962
+ "aria-activedescendant": activeId,
963
+ autoComplete: "off",
964
+ placeholder,
965
+ disabled,
966
+ value: shown,
967
+ onChange: (event) => {
968
+ setEditing(true);
969
+ setText(event.target.value);
970
+ setOpen(true);
971
+ runSearch(event.target.value);
972
+ },
973
+ onKeyDown,
974
+ onFocus: (event) => {
975
+ if (!editing && value) event.target.select();
976
+ },
977
+ onBlur: () => {
978
+ if (document.hasFocus()) stopEditing();
979
+ }
980
+ }
981
+ ),
982
+ name !== void 0 ? /* @__PURE__ */ jsx6("input", { type: "hidden", name, value: value ? getKey(value) : "", disabled }) : null,
983
+ clearable && value && !disabled ? /* @__PURE__ */ jsx6("button", { type: "button", "aria-label": clearLabel, ...partProps("clear"), onClick: () => {
984
+ onChange(null);
985
+ inputRef.current?.focus();
986
+ }, children: "\xD7" }) : null,
987
+ /* @__PURE__ */ jsx6("div", { role: "status", "aria-live": "polite", style: visuallyHidden, children: announcement }),
988
+ showPopup ? (
989
+ // mousedown anywhere in the popup (an option, the scrollbar, a message) must not move focus out of the input, or its
990
+ // blur would close the list before the click lands (and make a long list impossible to scroll by dragging)
991
+ /* @__PURE__ */ jsxs5("div", { ...partProps("list"), onMouseDown: (event) => event.preventDefault(), children: [
992
+ showListbox ? /* @__PURE__ */ jsx6("ul", { ref: listRef, id: listId, role: "listbox", "aria-label": ariaLabel, style: { listStyle: "none", margin: 0, padding: 0 }, children: results.map((item, index) => {
993
+ const active = index === activeIndex;
994
+ return /* @__PURE__ */ jsx6(
995
+ "li",
996
+ {
997
+ id: `${listId}-opt-${index}`,
998
+ role: "option",
999
+ "aria-selected": active,
1000
+ ...optionProps(active),
1001
+ onClick: () => choose(item),
1002
+ onMouseMove: () => {
1003
+ if (status !== "loading" && index !== activeIndex) setActiveIndex(index);
1004
+ },
1005
+ children: renderOption ? renderOption(item, { active }) : getLabel(item)
1006
+ },
1007
+ getKey(item)
1008
+ );
1009
+ }) }) : null,
1010
+ status === "loading" ? /* @__PURE__ */ jsx6("div", { "aria-hidden": "true", "data-entity-picker-message": "loading", ...partProps("message"), children: loadingText }) : null,
1011
+ status === "error" ? /* @__PURE__ */ jsx6("div", { "aria-hidden": "true", "data-entity-picker-message": "error", ...partProps("message"), children: errorText }) : null,
1012
+ status === "idle" && searched && results.length === 0 ? /* @__PURE__ */ jsx6("div", { "aria-hidden": "true", "data-entity-picker-message": "empty", ...partProps("message"), children: emptyText }) : null
1013
+ ] })
1014
+ ) : null
1015
+ ] });
1016
+ }
1017
+
696
1018
  // src/components/rich-text-editor.tsx
697
- import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
1019
+ import { useCallback as useCallback3, useEffect as useEffect4, useRef as useRef4, useState as useState5 } from "react";
698
1020
 
699
1021
  // src/components/rich-text-editor-styles.ts
700
1022
  var containerStyle = {
@@ -747,7 +1069,7 @@ var editableStyle = {
747
1069
  };
748
1070
 
749
1071
  // src/components/rich-text-editor.tsx
750
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1072
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
751
1073
  var TOOLBAR_BUTTONS = [
752
1074
  { command: "bold", label: "B", ariaLabel: "Bold" },
753
1075
  { command: "italic", label: "I", ariaLabel: "Italic" },
@@ -779,26 +1101,26 @@ function RichTextEditor({
779
1101
  className,
780
1102
  style
781
1103
  }) {
782
- const editorRef = useRef2(null);
783
- const [isFocused, setIsFocused] = useState3(false);
784
- const [isEmpty, setIsEmpty] = useState3(isEmptyHtml(content));
785
- const [linkError, setLinkError] = useState3(null);
786
- useEffect2(() => {
1104
+ const editorRef = useRef4(null);
1105
+ const [isFocused, setIsFocused] = useState5(false);
1106
+ const [isEmpty, setIsEmpty] = useState5(isEmptyHtml(content));
1107
+ const [linkError, setLinkError] = useState5(null);
1108
+ useEffect4(() => {
787
1109
  const el = editorRef.current;
788
1110
  if (el && !isFocused && el.innerHTML !== content) {
789
1111
  el.innerHTML = content;
790
1112
  setIsEmpty(isEmptyHtml(content));
791
1113
  }
792
1114
  }, [content, isFocused, editable]);
793
- useEffect2(() => {
1115
+ useEffect4(() => {
794
1116
  if (autoFocus) editorRef.current?.focus();
795
1117
  }, []);
796
- const handleInput = useCallback2(() => {
1118
+ const handleInput = useCallback3(() => {
797
1119
  const html = editorRef.current?.innerHTML ?? "";
798
1120
  setIsEmpty(isEmptyHtml(html));
799
1121
  onChange(html);
800
1122
  }, [onChange]);
801
- const runCommand = useCallback2(
1123
+ const runCommand = useCallback3(
802
1124
  (command, value) => {
803
1125
  editorRef.current?.focus();
804
1126
  document.execCommand(command, false, value);
@@ -806,7 +1128,7 @@ function RichTextEditor({
806
1128
  },
807
1129
  [handleInput]
808
1130
  );
809
- const handleLink = useCallback2(() => {
1131
+ const handleLink = useCallback3(() => {
810
1132
  const url = window.prompt("Link URL")?.trim();
811
1133
  setLinkError(null);
812
1134
  if (!url) return;
@@ -817,7 +1139,7 @@ function RichTextEditor({
817
1139
  runCommand("createLink", url);
818
1140
  }, [runCommand]);
819
1141
  if (!editable) {
820
- return /* @__PURE__ */ jsx5(
1142
+ return /* @__PURE__ */ jsx7(
821
1143
  "div",
822
1144
  {
823
1145
  className: [className, "ordinatio-rte", "ordinatio-rte-readonly"].filter(Boolean).join(" "),
@@ -826,9 +1148,9 @@ function RichTextEditor({
826
1148
  }
827
1149
  );
828
1150
  }
829
- return /* @__PURE__ */ jsxs4("div", { className: [className, "ordinatio-rte"].filter(Boolean).join(" "), style: className ? style : { ...containerStyle, ...style }, children: [
830
- /* @__PURE__ */ jsxs4("div", { className: "ordinatio-rte-toolbar", style: toolbarStyle, children: [
831
- TOOLBAR_BUTTONS.map((btn) => /* @__PURE__ */ jsx5(
1151
+ return /* @__PURE__ */ jsxs6("div", { className: [className, "ordinatio-rte"].filter(Boolean).join(" "), style: className ? style : { ...containerStyle, ...style }, children: [
1152
+ /* @__PURE__ */ jsxs6("div", { className: "ordinatio-rte-toolbar", style: toolbarStyle, children: [
1153
+ TOOLBAR_BUTTONS.map((btn) => /* @__PURE__ */ jsx7(
832
1154
  "button",
833
1155
  {
834
1156
  type: "button",
@@ -842,7 +1164,7 @@ function RichTextEditor({
842
1164
  },
843
1165
  btn.command
844
1166
  )),
845
- /* @__PURE__ */ jsx5(
1167
+ /* @__PURE__ */ jsx7(
846
1168
  "button",
847
1169
  {
848
1170
  type: "button",
@@ -855,10 +1177,10 @@ function RichTextEditor({
855
1177
  children: "\u{1F517}"
856
1178
  }
857
1179
  ),
858
- toolbarRight ? /* @__PURE__ */ jsx5("div", { className: "ordinatio-rte-toolbar-right", style: toolbarRightStyle, children: toolbarRight }) : null
1180
+ toolbarRight ? /* @__PURE__ */ jsx7("div", { className: "ordinatio-rte-toolbar-right", style: toolbarRightStyle, children: toolbarRight }) : null
859
1181
  ] }),
860
- linkError ? /* @__PURE__ */ jsx5("div", { className: "ordinatio-rte-link-error", role: "alert", style: linkErrorStyle, children: linkError }) : null,
861
- /* @__PURE__ */ jsxs4("div", { className: "ordinatio-rte-editable-wrap", style: { position: "relative" }, children: [
1182
+ linkError ? /* @__PURE__ */ jsx7("div", { className: "ordinatio-rte-link-error", role: "alert", style: linkErrorStyle, children: linkError }) : null,
1183
+ /* @__PURE__ */ jsxs6("div", { className: "ordinatio-rte-editable-wrap", style: { position: "relative" }, children: [
862
1184
  isEmpty ? (
863
1185
  // Shown while empty REGARDLESS of focus — WorldClass cycle 1:
864
1186
  // the prior `isEmpty && !isFocused` condition hid the
@@ -867,7 +1189,7 @@ function RichTextEditor({
867
1189
  // the click landed. Matches native `<textarea placeholder>`
868
1190
  // behavior (visible while focused-and-empty, removed only once
869
1191
  // the user types).
870
- /* @__PURE__ */ jsx5(
1192
+ /* @__PURE__ */ jsx7(
871
1193
  "div",
872
1194
  {
873
1195
  "aria-hidden": "true",
@@ -877,7 +1199,7 @@ function RichTextEditor({
877
1199
  }
878
1200
  )
879
1201
  ) : null,
880
- /* @__PURE__ */ jsx5(
1202
+ /* @__PURE__ */ jsx7(
881
1203
  "div",
882
1204
  {
883
1205
  ref: editorRef,
@@ -899,7 +1221,7 @@ function RichTextEditor({
899
1221
  }
900
1222
 
901
1223
  // src/components/reply-panel.tsx
902
- import { useEffect as useEffect3, useId, useRef as useRef3, useState as useState4 } from "react";
1224
+ import { useEffect as useEffect5, useId as useId3, useRef as useRef5, useState as useState6 } from "react";
903
1225
 
904
1226
  // src/components/subject-prefix.ts
905
1227
  function prefixSubject(subject, mode) {
@@ -989,7 +1311,7 @@ var disabledButtonStyle = {
989
1311
  };
990
1312
 
991
1313
  // src/components/reply-panel.tsx
992
- import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1314
+ import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
993
1315
  function ReplyPanel({
994
1316
  mode = "reply",
995
1317
  subject,
@@ -1008,22 +1330,22 @@ function ReplyPanel({
1008
1330
  }) {
1009
1331
  const defaultTo = mode === "reply" ? toEmail || toName : "";
1010
1332
  const defaultSubject = prefixSubject(subject, mode);
1011
- const idPrefix = useId();
1333
+ const idPrefix = useId3();
1012
1334
  const toId = `${idPrefix}-to`;
1013
1335
  const ccId = `${idPrefix}-cc`;
1014
1336
  const bccId = `${idPrefix}-bcc`;
1015
1337
  const subjectId = `${idPrefix}-subject`;
1016
- const [to, setTo] = useState4(defaultTo);
1017
- const [cc, setCc] = useState4(initialCc);
1018
- const [bcc, setBcc] = useState4("");
1019
- const [showCcBcc, setShowCcBcc] = useState4(initialShowCcBcc || !!initialCc);
1020
- const [editedSubject, setEditedSubject] = useState4(defaultSubject);
1021
- const [body, setBody] = useState4(initialBody);
1022
- const [sending, setSending] = useState4(false);
1023
- const [error, setError] = useState4(null);
1024
- const [sent, setSent] = useState4(false);
1025
- const isMountedRef = useRef3(true);
1026
- useEffect3(() => {
1338
+ const [to, setTo] = useState6(defaultTo);
1339
+ const [cc, setCc] = useState6(initialCc);
1340
+ const [bcc, setBcc] = useState6("");
1341
+ const [showCcBcc, setShowCcBcc] = useState6(initialShowCcBcc || !!initialCc);
1342
+ const [editedSubject, setEditedSubject] = useState6(defaultSubject);
1343
+ const [body, setBody] = useState6(initialBody);
1344
+ const [sending, setSending] = useState6(false);
1345
+ const [error, setError] = useState6(null);
1346
+ const [sent, setSent] = useState6(false);
1347
+ const isMountedRef = useRef5(true);
1348
+ useEffect5(() => {
1027
1349
  isMountedRef.current = true;
1028
1350
  return () => {
1029
1351
  isMountedRef.current = false;
@@ -1068,16 +1390,16 @@ function ReplyPanel({
1068
1390
  if (isMountedRef.current) setSending(false);
1069
1391
  }
1070
1392
  };
1071
- return /* @__PURE__ */ jsxs5(
1393
+ return /* @__PURE__ */ jsxs7(
1072
1394
  "div",
1073
1395
  {
1074
1396
  className: [className, "ordinatio-reply-panel"].filter(Boolean).join(" "),
1075
1397
  style: className ? style : { display: "flex", flexDirection: "column", gap: "8px", ...style },
1076
1398
  children: [
1077
- /* @__PURE__ */ jsxs5("div", { className: "ordinatio-reply-fields", style: { display: "flex", flexDirection: "column", gap: "6px" }, children: [
1078
- /* @__PURE__ */ jsxs5("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1079
- /* @__PURE__ */ jsx6("label", { htmlFor: toId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "To" }),
1080
- /* @__PURE__ */ jsx6(
1399
+ /* @__PURE__ */ jsxs7("div", { className: "ordinatio-reply-fields", style: { display: "flex", flexDirection: "column", gap: "6px" }, children: [
1400
+ /* @__PURE__ */ jsxs7("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1401
+ /* @__PURE__ */ jsx8("label", { htmlFor: toId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "To" }),
1402
+ /* @__PURE__ */ jsx8(
1081
1403
  "input",
1082
1404
  {
1083
1405
  id: toId,
@@ -1105,7 +1427,7 @@ function ReplyPanel({
1105
1427
  // and aria-controls referenced ids (ccId/bccId) that don't
1106
1428
  // exist in the DOM until AFTER this button has already
1107
1429
  // unmounted. A one-directional reveal, not a toggle.
1108
- /* @__PURE__ */ jsx6(
1430
+ /* @__PURE__ */ jsx8(
1109
1431
  "button",
1110
1432
  {
1111
1433
  type: "button",
@@ -1118,10 +1440,10 @@ function ReplyPanel({
1118
1440
  )
1119
1441
  ) : null
1120
1442
  ] }),
1121
- showCcBcc ? /* @__PURE__ */ jsxs5(Fragment2, { children: [
1122
- /* @__PURE__ */ jsxs5("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1123
- /* @__PURE__ */ jsx6("label", { htmlFor: ccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Cc" }),
1124
- /* @__PURE__ */ jsx6(
1443
+ showCcBcc ? /* @__PURE__ */ jsxs7(Fragment2, { children: [
1444
+ /* @__PURE__ */ jsxs7("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1445
+ /* @__PURE__ */ jsx8("label", { htmlFor: ccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Cc" }),
1446
+ /* @__PURE__ */ jsx8(
1125
1447
  "input",
1126
1448
  {
1127
1449
  id: ccId,
@@ -1139,9 +1461,9 @@ function ReplyPanel({
1139
1461
  }
1140
1462
  )
1141
1463
  ] }),
1142
- /* @__PURE__ */ jsxs5("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1143
- /* @__PURE__ */ jsx6("label", { htmlFor: bccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Bcc" }),
1144
- /* @__PURE__ */ jsx6(
1464
+ /* @__PURE__ */ jsxs7("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1465
+ /* @__PURE__ */ jsx8("label", { htmlFor: bccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Bcc" }),
1466
+ /* @__PURE__ */ jsx8(
1145
1467
  "input",
1146
1468
  {
1147
1469
  id: bccId,
@@ -1160,9 +1482,9 @@ function ReplyPanel({
1160
1482
  )
1161
1483
  ] })
1162
1484
  ] }) : null,
1163
- /* @__PURE__ */ jsxs5("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1164
- /* @__PURE__ */ jsx6("label", { htmlFor: subjectId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Subject" }),
1165
- /* @__PURE__ */ jsx6(
1485
+ /* @__PURE__ */ jsxs7("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1486
+ /* @__PURE__ */ jsx8("label", { htmlFor: subjectId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Subject" }),
1487
+ /* @__PURE__ */ jsx8(
1166
1488
  "input",
1167
1489
  {
1168
1490
  id: subjectId,
@@ -1181,9 +1503,9 @@ function ReplyPanel({
1181
1503
  )
1182
1504
  ] })
1183
1505
  ] }),
1184
- error ? /* @__PURE__ */ jsx6("div", { className: "ordinatio-reply-error", role: "alert", style: errorStyle, children: error }) : null,
1185
- sent && resolvedSuccessMessage ? /* @__PURE__ */ jsx6("div", { className: "ordinatio-reply-success", role: "status", style: successStyle, children: resolvedSuccessMessage }) : null,
1186
- /* @__PURE__ */ jsx6(
1506
+ error ? /* @__PURE__ */ jsx8("div", { className: "ordinatio-reply-error", role: "alert", style: errorStyle, children: error }) : null,
1507
+ sent && resolvedSuccessMessage ? /* @__PURE__ */ jsx8("div", { className: "ordinatio-reply-success", role: "status", style: successStyle, children: resolvedSuccessMessage }) : null,
1508
+ /* @__PURE__ */ jsx8(
1187
1509
  RichTextEditor,
1188
1510
  {
1189
1511
  content: body,
@@ -1197,8 +1519,8 @@ function ReplyPanel({
1197
1519
  locked: sending
1198
1520
  }
1199
1521
  ),
1200
- /* @__PURE__ */ jsxs5("div", { className: "ordinatio-reply-actions", style: actionsRowStyle, children: [
1201
- showCancel && onCancel ? /* @__PURE__ */ jsx6(
1522
+ /* @__PURE__ */ jsxs7("div", { className: "ordinatio-reply-actions", style: actionsRowStyle, children: [
1523
+ showCancel && onCancel ? /* @__PURE__ */ jsx8(
1202
1524
  "button",
1203
1525
  {
1204
1526
  type: "button",
@@ -1209,7 +1531,7 @@ function ReplyPanel({
1209
1531
  children: "Cancel"
1210
1532
  }
1211
1533
  ) : null,
1212
- /* @__PURE__ */ jsx6(
1534
+ /* @__PURE__ */ jsx8(
1213
1535
  "button",
1214
1536
  {
1215
1537
  type: "button",
@@ -1227,7 +1549,7 @@ function ReplyPanel({
1227
1549
  }
1228
1550
 
1229
1551
  // src/hooks/use-keyboard-shortcuts.ts
1230
- import { useEffect as useEffect4, useCallback as useCallback3 } from "react";
1552
+ import { useEffect as useEffect6, useCallback as useCallback4 } from "react";
1231
1553
 
1232
1554
  // src/hooks/is-typing-context.ts
1233
1555
  var TYPING_TAG_RE = /^(INPUT|TEXTAREA|SELECT)$/;
@@ -1252,14 +1574,14 @@ function useKeyboardShortcuts({
1252
1574
  ignoreTags = []
1253
1575
  }) {
1254
1576
  const malformed = !Array.isArray(shortcuts);
1255
- useEffect4(() => {
1577
+ useEffect6(() => {
1256
1578
  if (malformed) {
1257
1579
  console.error(
1258
1580
  "[useKeyboardShortcuts] expected { shortcuts: KeyboardShortcut[] } \u2014 got a non-array `shortcuts` (legacy array call form?). All shortcuts for this caller are disabled until the call is fixed."
1259
1581
  );
1260
1582
  }
1261
1583
  }, [malformed]);
1262
- const handleKeyDown = useCallback3(
1584
+ const handleKeyDown = useCallback4(
1263
1585
  (e) => {
1264
1586
  if (!enabled || malformed) return;
1265
1587
  if (e.isComposing || e.keyCode === 229) return;
@@ -1287,7 +1609,7 @@ function useKeyboardShortcuts({
1287
1609
  },
1288
1610
  [shortcuts, enabled, ignoreTags, malformed]
1289
1611
  );
1290
- useEffect4(() => {
1612
+ useEffect6(() => {
1291
1613
  window.addEventListener("keydown", handleKeyDown);
1292
1614
  return () => window.removeEventListener("keydown", handleKeyDown);
1293
1615
  }, [handleKeyDown]);
@@ -1457,13 +1779,13 @@ function getShortcut(context, action) {
1457
1779
  }
1458
1780
 
1459
1781
  // src/components/keyboard-shortcuts-panel.tsx
1460
- import { useEffect as useEffect5, useState as useState5 } from "react";
1461
- import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
1782
+ import { useEffect as useEffect7, useState as useState7 } from "react";
1783
+ import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
1462
1784
  function KeyboardShortcutsPanel({
1463
1785
  contexts = ALL_SHORTCUT_CONTEXTS
1464
1786
  }) {
1465
- const [open, setOpen] = useState5(false);
1466
- useEffect5(() => {
1787
+ const [open, setOpen] = useState7(false);
1788
+ useEffect7(() => {
1467
1789
  function handleKey(e) {
1468
1790
  if (e.key === "?" && !e.metaKey && !e.ctrlKey && !e.altKey) {
1469
1791
  const tag = e.target?.tagName;
@@ -1480,33 +1802,33 @@ function KeyboardShortcutsPanel({
1480
1802
  return () => window.removeEventListener("keydown", handleKey);
1481
1803
  }, [open]);
1482
1804
  if (!open) return null;
1483
- return /* @__PURE__ */ jsxs6(Fragment3, { children: [
1484
- /* @__PURE__ */ jsx7(
1805
+ return /* @__PURE__ */ jsxs8(Fragment3, { children: [
1806
+ /* @__PURE__ */ jsx9(
1485
1807
  "div",
1486
1808
  {
1487
1809
  className: "fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",
1488
1810
  onClick: () => setOpen(false)
1489
1811
  }
1490
1812
  ),
1491
- /* @__PURE__ */ jsx7("div", { className: "fixed inset-x-0 top-[10%] z-50 mx-auto w-full max-w-lg", children: /* @__PURE__ */ jsxs6("div", { className: "rounded-xl border bg-background shadow-2xl overflow-hidden", children: [
1492
- /* @__PURE__ */ jsxs6("div", { className: "px-6 py-4 border-b", children: [
1493
- /* @__PURE__ */ jsx7("h2", { className: "text-lg font-semibold", children: "Keyboard Shortcuts" }),
1494
- /* @__PURE__ */ jsxs6("p", { className: "text-sm text-muted-foreground mt-0.5", children: [
1813
+ /* @__PURE__ */ jsx9("div", { className: "fixed inset-x-0 top-[10%] z-50 mx-auto w-full max-w-lg", children: /* @__PURE__ */ jsxs8("div", { className: "rounded-xl border bg-background shadow-2xl overflow-hidden", children: [
1814
+ /* @__PURE__ */ jsxs8("div", { className: "px-6 py-4 border-b", children: [
1815
+ /* @__PURE__ */ jsx9("h2", { className: "text-lg font-semibold", children: "Keyboard Shortcuts" }),
1816
+ /* @__PURE__ */ jsxs8("p", { className: "text-sm text-muted-foreground mt-0.5", children: [
1495
1817
  "Press ",
1496
- /* @__PURE__ */ jsx7("kbd", { className: "px-1.5 py-0.5 bg-muted rounded text-xs font-mono", children: "?" }),
1818
+ /* @__PURE__ */ jsx9("kbd", { className: "px-1.5 py-0.5 bg-muted rounded text-xs font-mono", children: "?" }),
1497
1819
  " to toggle this panel"
1498
1820
  ] })
1499
1821
  ] }),
1500
- /* @__PURE__ */ jsx7("div", { className: "px-6 py-4 max-h-[60vh] overflow-y-auto space-y-6", children: contexts.map((ctx) => /* @__PURE__ */ jsxs6("div", { children: [
1501
- /* @__PURE__ */ jsx7("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: ctx.label }),
1502
- /* @__PURE__ */ jsx7("div", { className: "space-y-1", children: Object.entries(ctx.shortcuts).map(([key, def]) => /* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between py-1", children: [
1503
- /* @__PURE__ */ jsx7("span", { className: "text-sm", children: def.description }),
1504
- /* @__PURE__ */ jsx7("kbd", { className: "px-2 py-0.5 bg-muted rounded text-xs font-mono min-w-[2rem] text-center", children: def.display })
1822
+ /* @__PURE__ */ jsx9("div", { className: "px-6 py-4 max-h-[60vh] overflow-y-auto space-y-6", children: contexts.map((ctx) => /* @__PURE__ */ jsxs8("div", { children: [
1823
+ /* @__PURE__ */ jsx9("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: ctx.label }),
1824
+ /* @__PURE__ */ jsx9("div", { className: "space-y-1", children: Object.entries(ctx.shortcuts).map(([key, def]) => /* @__PURE__ */ jsxs8("div", { className: "flex items-center justify-between py-1", children: [
1825
+ /* @__PURE__ */ jsx9("span", { className: "text-sm", children: def.description }),
1826
+ /* @__PURE__ */ jsx9("kbd", { className: "px-2 py-0.5 bg-muted rounded text-xs font-mono min-w-[2rem] text-center", children: def.display })
1505
1827
  ] }, key)) })
1506
1828
  ] }, ctx.name)) }),
1507
- /* @__PURE__ */ jsxs6("div", { className: "px-6 py-3 border-t bg-muted/30 text-xs text-muted-foreground text-center", children: [
1829
+ /* @__PURE__ */ jsxs8("div", { className: "px-6 py-3 border-t bg-muted/30 text-xs text-muted-foreground text-center", children: [
1508
1830
  "Press ",
1509
- /* @__PURE__ */ jsx7("kbd", { className: "px-1 py-0.5 bg-muted rounded", children: "Esc" }),
1831
+ /* @__PURE__ */ jsx9("kbd", { className: "px-1 py-0.5 bg-muted rounded", children: "Esc" }),
1510
1832
  " to close"
1511
1833
  ] })
1512
1834
  ] }) })
@@ -1514,21 +1836,21 @@ function KeyboardShortcutsPanel({
1514
1836
  }
1515
1837
 
1516
1838
  // src/hooks/use-auto-save.ts
1517
- import { useEffect as useEffect6, useRef as useRef4, useCallback as useCallback4, useState as useState6 } from "react";
1839
+ import { useEffect as useEffect8, useRef as useRef6, useCallback as useCallback5, useState as useState8 } from "react";
1518
1840
  function useAutoSave({
1519
1841
  data,
1520
1842
  onSave,
1521
1843
  delay = 5e3,
1522
1844
  enabled = true
1523
1845
  }) {
1524
- const [lastSavedAt, setLastSavedAt] = useState6(null);
1525
- const [isSaving, setIsSaving] = useState6(false);
1526
- const [saveError, setSaveError] = useState6(null);
1527
- const timerRef = useRef4(null);
1528
- const dataRef = useRef4(data);
1529
- const savedDataRef = useRef4(null);
1846
+ const [lastSavedAt, setLastSavedAt] = useState8(null);
1847
+ const [isSaving, setIsSaving] = useState8(false);
1848
+ const [saveError, setSaveError] = useState8(null);
1849
+ const timerRef = useRef6(null);
1850
+ const dataRef = useRef6(data);
1851
+ const savedDataRef = useRef6(null);
1530
1852
  dataRef.current = data;
1531
- const save = useCallback4(async () => {
1853
+ const save = useCallback5(async () => {
1532
1854
  const currentJson = JSON.stringify(dataRef.current);
1533
1855
  if (currentJson === savedDataRef.current) return;
1534
1856
  setIsSaving(true);
@@ -1543,7 +1865,7 @@ function useAutoSave({
1543
1865
  setIsSaving(false);
1544
1866
  }
1545
1867
  }, [onSave]);
1546
- useEffect6(() => {
1868
+ useEffect8(() => {
1547
1869
  if (!enabled) return;
1548
1870
  if (timerRef.current) clearTimeout(timerRef.current);
1549
1871
  timerRef.current = setTimeout(save, delay);
@@ -1555,19 +1877,19 @@ function useAutoSave({
1555
1877
  }
1556
1878
 
1557
1879
  // src/hooks/use-polling.ts
1558
- import { useEffect as useEffect7, useCallback as useCallback5, useRef as useRef5, useState as useState7 } from "react";
1880
+ import { useEffect as useEffect9, useCallback as useCallback6, useRef as useRef7, useState as useState9 } from "react";
1559
1881
  function usePolling({
1560
1882
  fetcher,
1561
1883
  interval = 3e4,
1562
1884
  enabled = true,
1563
1885
  onError
1564
1886
  }) {
1565
- const [data, setData] = useState7(null);
1566
- const [isLoading, setIsLoading] = useState7(true);
1567
- const [isRefreshing, setIsRefreshing] = useState7(false);
1568
- const [error, setError] = useState7(null);
1569
- const mountedRef = useRef5(true);
1570
- const doFetch = useCallback5(async (isInitial = false) => {
1887
+ const [data, setData] = useState9(null);
1888
+ const [isLoading, setIsLoading] = useState9(true);
1889
+ const [isRefreshing, setIsRefreshing] = useState9(false);
1890
+ const [error, setError] = useState9(null);
1891
+ const mountedRef = useRef7(true);
1892
+ const doFetch = useCallback6(async (isInitial = false) => {
1571
1893
  if (isInitial) setIsLoading(true);
1572
1894
  else setIsRefreshing(true);
1573
1895
  try {
@@ -1588,36 +1910,36 @@ function usePolling({
1588
1910
  }
1589
1911
  }
1590
1912
  }, [fetcher, onError]);
1591
- useEffect7(() => {
1913
+ useEffect9(() => {
1592
1914
  mountedRef.current = true;
1593
1915
  if (enabled) doFetch(true);
1594
1916
  return () => {
1595
1917
  mountedRef.current = false;
1596
1918
  };
1597
1919
  }, [doFetch, enabled]);
1598
- useEffect7(() => {
1920
+ useEffect9(() => {
1599
1921
  if (!enabled) return;
1600
1922
  const timer = setInterval(() => doFetch(false), interval);
1601
1923
  return () => clearInterval(timer);
1602
1924
  }, [doFetch, interval, enabled]);
1603
- const refresh = useCallback5(() => doFetch(false), [doFetch]);
1925
+ const refresh = useCallback6(() => doFetch(false), [doFetch]);
1604
1926
  return { data, isLoading, isRefreshing, error, refresh };
1605
1927
  }
1606
1928
 
1607
1929
  // src/hooks/use-server-search.ts
1608
- import { useEffect as useEffect8, useRef as useRef6, useState as useState8, useCallback as useCallback6 } from "react";
1930
+ import { useEffect as useEffect10, useRef as useRef8, useState as useState10, useCallback as useCallback7 } from "react";
1609
1931
  function useServerSearch({
1610
1932
  fetcher,
1611
1933
  debounce = 150,
1612
1934
  minChars = 1,
1613
1935
  enabled = true
1614
1936
  }) {
1615
- const [query, setQuery] = useState8("");
1616
- const [results, setResults] = useState8([]);
1617
- const [isSearching, setIsSearching] = useState8(false);
1618
- const [isOpen, setIsOpen] = useState8(false);
1619
- const timerRef = useRef6(null);
1620
- useEffect8(() => {
1937
+ const [query, setQuery] = useState10("");
1938
+ const [results, setResults] = useState10([]);
1939
+ const [isSearching, setIsSearching] = useState10(false);
1940
+ const [isOpen, setIsOpen] = useState10(false);
1941
+ const timerRef = useRef8(null);
1942
+ useEffect10(() => {
1621
1943
  if (!enabled || query.length < minChars) {
1622
1944
  setResults([]);
1623
1945
  return;
@@ -1638,7 +1960,7 @@ function useServerSearch({
1638
1960
  if (timerRef.current) clearTimeout(timerRef.current);
1639
1961
  };
1640
1962
  }, [query, fetcher, debounce, minChars, enabled]);
1641
- const clear = useCallback6(() => {
1963
+ const clear = useCallback7(() => {
1642
1964
  setQuery("");
1643
1965
  setResults([]);
1644
1966
  setIsOpen(false);
@@ -1647,9 +1969,9 @@ function useServerSearch({
1647
1969
  }
1648
1970
 
1649
1971
  // src/hooks/use-iframe-focus-reclaim.ts
1650
- import { useEffect as useEffect9 } from "react";
1972
+ import { useEffect as useEffect11 } from "react";
1651
1973
  function useIframeFocusReclaim(containerRef, enabled = true, iframeSelector = "iframe") {
1652
- useEffect9(() => {
1974
+ useEffect11(() => {
1653
1975
  if (!enabled) return;
1654
1976
  const el = containerRef.current;
1655
1977
  if (!el) return;
@@ -1830,21 +2152,21 @@ function clearCache() {
1830
2152
  }
1831
2153
 
1832
2154
  // src/hooks/use-preferences.ts
1833
- import { useState as useState9, useEffect as useEffect10, useCallback as useCallback7 } from "react";
2155
+ import { useState as useState11, useEffect as useEffect12, useCallback as useCallback8 } from "react";
1834
2156
  function usePreferences({
1835
2157
  endpoint,
1836
- defaults
2158
+ defaults: defaults3
1837
2159
  }) {
1838
- const [preferences, setPreferences] = useState9(defaults ?? null);
1839
- const [loading, setLoading] = useState9(true);
1840
- const [error, setError] = useState9(null);
1841
- const fetchPreferences = useCallback7(async () => {
2160
+ const [preferences, setPreferences] = useState11(defaults3 ?? null);
2161
+ const [loading, setLoading] = useState11(true);
2162
+ const [error, setError] = useState11(null);
2163
+ const fetchPreferences = useCallback8(async () => {
1842
2164
  try {
1843
2165
  setError(null);
1844
2166
  const res = await fetch(endpoint);
1845
2167
  if (!res.ok) {
1846
2168
  if (res.status === 401) {
1847
- setPreferences(defaults ?? null);
2169
+ setPreferences(defaults3 ?? null);
1848
2170
  return;
1849
2171
  }
1850
2172
  throw new Error("Failed to fetch preferences");
@@ -1856,11 +2178,11 @@ function usePreferences({
1856
2178
  } finally {
1857
2179
  setLoading(false);
1858
2180
  }
1859
- }, [endpoint, defaults]);
1860
- useEffect10(() => {
2181
+ }, [endpoint, defaults3]);
2182
+ useEffect12(() => {
1861
2183
  fetchPreferences();
1862
2184
  }, [fetchPreferences]);
1863
- const updatePreferences = useCallback7(
2185
+ const updatePreferences = useCallback8(
1864
2186
  async (updates) => {
1865
2187
  setPreferences((prev) => prev ? { ...prev, ...updates } : updates);
1866
2188
  setError(null);
@@ -2216,8 +2538,10 @@ export {
2216
2538
  ALL_SHORTCUT_CONTEXTS,
2217
2539
  ArchiveButton,
2218
2540
  CLIENT_PROFILE_SHORTCUTS,
2541
+ ConfirmAction,
2219
2542
  EmailBodyRenderer,
2220
2543
  EmailThreadView,
2544
+ EntityPicker,
2221
2545
  ErrorBoundary,
2222
2546
  FORM_SHORTCUTS,
2223
2547
  GLOBAL_SHORTCUTS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordinatio/ui",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Reusable React components and hooks for Ordinatio applications",