@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/dist/index.mjs CHANGED
@@ -877,10 +877,238 @@ function ActivityFeedRow({
877
877
  ] });
878
878
  }
879
879
 
880
- // src/components/entity-picker.tsx
881
- import { useCallback as useCallback2, useEffect as useEffect3, useId as useId2, useRef as useRef3, useState as useState4 } from "react";
880
+ // src/hooks/use-guarded-action.ts
881
+ import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3, useState as useState4 } from "react";
882
+ var GUARDED_ACTION_FAILURE = "Something went wrong. Please try again.";
883
+ var errorOf = (result) => {
884
+ if (typeof result !== "object" || result === null) return null;
885
+ const error = result.error;
886
+ return typeof error === "string" && error !== "" ? error : null;
887
+ };
888
+ function useGuardedAction(action, options = {}) {
889
+ const [busy, setBusy] = useState4(false);
890
+ const [error, setError] = useState4(null);
891
+ const running = useRef3(false);
892
+ const mounted = useRef3(true);
893
+ const latest = useRef3({ action, options });
894
+ latest.current = { action, options };
895
+ useEffect3(() => {
896
+ mounted.current = true;
897
+ return () => {
898
+ mounted.current = false;
899
+ };
900
+ }, []);
901
+ const run = useCallback2(async (...args) => {
902
+ if (running.current) return;
903
+ running.current = true;
904
+ setBusy(true);
905
+ setError(null);
906
+ try {
907
+ const result = await latest.current.action(...args);
908
+ const refusal = errorOf(result);
909
+ if (refusal) {
910
+ if (mounted.current) setError(refusal);
911
+ } else {
912
+ latest.current.options.onDone?.(result);
913
+ }
914
+ } catch (thrown) {
915
+ try {
916
+ latest.current.options.onFailure?.(thrown);
917
+ } catch {
918
+ }
919
+ if (mounted.current) setError(latest.current.options.failureMessage ?? GUARDED_ACTION_FAILURE);
920
+ } finally {
921
+ running.current = false;
922
+ if (mounted.current) setBusy(false);
923
+ }
924
+ }, []);
925
+ const clearError = useCallback2(() => setError(null), []);
926
+ return { run, busy, error, clearError };
927
+ }
928
+
929
+ // src/components/restore-button.tsx
882
930
  import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
883
931
  var defaults3 = {
932
+ root: { display: "inline-flex", flexDirection: "column", alignItems: "flex-end", gap: "4px" },
933
+ button: { flexShrink: 0, padding: 0, border: "none", backgroundColor: "transparent", fontSize: "14px", color: "#404040", cursor: "pointer" },
934
+ error: { fontSize: "14px", color: "#dc2626" }
935
+ };
936
+ function RestoreButton({ action, onDone, onFailure, labels, failureMessage, classNames }) {
937
+ const { run, busy, error } = useGuardedAction(action, { onDone: () => onDone?.(), onFailure, failureMessage });
938
+ const part = (key, extra) => {
939
+ const className = classNames?.[key];
940
+ return className ? { className } : { style: { ...defaults3[key], ...extra } };
941
+ };
942
+ return /* @__PURE__ */ jsxs6("span", { ...part("root"), children: [
943
+ /* @__PURE__ */ jsx7("button", { type: "button", disabled: busy, onClick: () => void run(), ...part("button", busy ? { opacity: 0.5, cursor: "not-allowed" } : void 0), children: busy ? labels?.busy ?? "Restoring\u2026" : labels?.idle ?? "Restore" }),
944
+ error ? /* @__PURE__ */ jsx7("span", { role: "alert", ...part("error"), children: error }) : null
945
+ ] });
946
+ }
947
+
948
+ // src/components/undo-notice.tsx
949
+ import { useState as useState5 } from "react";
950
+ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
951
+ var defaults4 = {
952
+ root: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: "4px 12px", padding: "8px 12px", fontSize: "14px", borderRadius: "6px", backgroundColor: "#f5f5f5", color: "#262626" },
953
+ message: { minWidth: 0, overflowWrap: "break-word" },
954
+ link: { color: "#be123c" },
955
+ undo: { padding: 0, border: "none", backgroundColor: "transparent", fontSize: "14px", fontWeight: 500, color: "#be123c", cursor: "pointer" },
956
+ dismiss: { marginLeft: "auto", padding: 0, border: "none", backgroundColor: "transparent", color: "#737373", cursor: "pointer" },
957
+ error: { width: "100%", color: "#dc2626" }
958
+ };
959
+ var defaultMoved = (name) => `Moved \u201C${name}\u201D to the Trash.`;
960
+ function UndoNotice({ name, action, onDone, onFailure, trashHref, LinkComponent = "a", labels, failureMessage, classNames }) {
961
+ const [hidden, setHidden] = useState5(false);
962
+ const { run, busy, error } = useGuardedAction(action, {
963
+ onDone: () => {
964
+ onDone?.();
965
+ setHidden(true);
966
+ },
967
+ onFailure,
968
+ failureMessage
969
+ });
970
+ const Link = LinkComponent;
971
+ const part = (key, extra) => {
972
+ const className = classNames?.[key];
973
+ return className ? { className } : { style: { ...defaults4[key], ...extra } };
974
+ };
975
+ if (hidden) return null;
976
+ return /* @__PURE__ */ jsxs7("div", { role: "status", ...part("root"), children: [
977
+ /* @__PURE__ */ jsx8("span", { ...part("message"), children: (labels?.moved ?? defaultMoved)(name) }),
978
+ trashHref ? /* @__PURE__ */ jsx8(Link, { href: trashHref, ...part("link"), children: labels?.viewTrash ?? "View Trash" }) : null,
979
+ /* @__PURE__ */ jsx8("button", { type: "button", disabled: busy, onClick: () => void run(), ...part("undo", busy ? { opacity: 0.5, cursor: "not-allowed" } : void 0), children: busy ? labels?.undoing ?? "Undoing\u2026" : labels?.undo ?? "Undo" }),
980
+ /* @__PURE__ */ jsx8("button", { type: "button", "aria-label": labels?.dismiss ?? "Dismiss", onClick: () => setHidden(true), ...part("dismiss"), children: "\xD7" }),
981
+ error ? /* @__PURE__ */ jsx8("span", { role: "alert", ...part("error"), children: error }) : null
982
+ ] });
983
+ }
984
+
985
+ // src/components/trashed-banner.tsx
986
+ import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
987
+ function formatTrashedDate(date, locale = "en-US", timeZone) {
988
+ return date.toLocaleDateString(locale, { year: "numeric", month: "short", day: "numeric", ...timeZone ? { timeZone } : {} });
989
+ }
990
+ var defaults5 = {
991
+ root: { display: "flex", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: "12px", maxWidth: "28rem", padding: "8px 12px", fontSize: "14px", borderRadius: "6px", backgroundColor: "#fffbeb", color: "#78350f" },
992
+ text: {},
993
+ action: {}
994
+ };
995
+ function TrashedBanner({ since, by, restore, formatDate: formatDate2 = formatTrashedDate, labels, classNames }) {
996
+ const part = (key) => {
997
+ const className = classNames?.[key];
998
+ return className ? { className } : { style: defaults5[key] };
999
+ };
1000
+ const when = since ? formatDate2(since) : labels?.earlier ?? "earlier";
1001
+ const sentence = `${labels?.intro ? `${labels.intro} ` : ""}${labels?.since ?? "In the Trash since"} ${when} ${labels?.by ?? "by"} ${by}.`;
1002
+ return /* @__PURE__ */ jsxs8("div", { role: "status", ...part("root"), children: [
1003
+ /* @__PURE__ */ jsx9("span", { ...part("text"), children: sentence }),
1004
+ restore ? /* @__PURE__ */ jsx9("span", { ...part("action"), children: restore }) : null
1005
+ ] });
1006
+ }
1007
+
1008
+ // src/components/show-once-secret.tsx
1009
+ import { useEffect as useEffect5 } from "react";
1010
+
1011
+ // src/hooks/use-copy-to-clipboard.ts
1012
+ import { useCallback as useCallback3, useEffect as useEffect4, useRef as useRef4, useState as useState6 } from "react";
1013
+ var COPY_NOTE_COPIED = "Copied.";
1014
+ var COPY_NOTE_FAILED = "Could not copy automatically. Select the text and copy it yourself.";
1015
+ function useCopyToClipboard(options = {}) {
1016
+ const [status, setStatus] = useState6(null);
1017
+ const latest = useRef4(options);
1018
+ latest.current = options;
1019
+ const mounted = useRef4(true);
1020
+ const ticket = useRef4(0);
1021
+ const timer = useRef4(null);
1022
+ const clearTimer = () => {
1023
+ if (timer.current !== null) clearTimeout(timer.current);
1024
+ timer.current = null;
1025
+ };
1026
+ useEffect4(() => {
1027
+ mounted.current = true;
1028
+ return () => {
1029
+ mounted.current = false;
1030
+ clearTimer();
1031
+ };
1032
+ }, []);
1033
+ const show = (next) => {
1034
+ clearTimer();
1035
+ setStatus(next);
1036
+ const after = latest.current.resetAfterMs;
1037
+ if (after !== void 0 && after > 0) timer.current = setTimeout(() => setStatus(null), after);
1038
+ };
1039
+ const copy = useCallback3(async (text) => {
1040
+ const mine = ++ticket.current;
1041
+ let ok = false;
1042
+ try {
1043
+ await navigator.clipboard.writeText(text);
1044
+ ok = true;
1045
+ } catch {
1046
+ ok = false;
1047
+ }
1048
+ if (mounted.current && mine === ticket.current) show(ok ? "copied" : "failed");
1049
+ return ok;
1050
+ }, []);
1051
+ const reset = useCallback3(() => {
1052
+ ticket.current += 1;
1053
+ clearTimer();
1054
+ setStatus(null);
1055
+ }, []);
1056
+ const note = status === "copied" ? options.copiedNote ?? COPY_NOTE_COPIED : status === "failed" ? options.failedNote ?? COPY_NOTE_FAILED : null;
1057
+ return { copy, note, status, reset };
1058
+ }
1059
+
1060
+ // src/components/show-once-secret.tsx
1061
+ import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
1062
+ var defaults6 = {
1063
+ root: { display: "flex", flexDirection: "column", gap: "8px", padding: "12px 16px", border: "1px solid #fcd34d", borderRadius: "6px", backgroundColor: "#fffbeb" },
1064
+ title: { margin: 0, fontSize: "14px", fontWeight: 500, color: "#78350f" },
1065
+ warning: { fontWeight: 400 },
1066
+ secret: { display: "block", padding: "4px 8px", fontFamily: "monospace", fontSize: "14px", overflowWrap: "anywhere", borderRadius: "4px", border: "1px solid #e5e5e5", backgroundColor: "#ffffff", color: "#171717", userSelect: "all" },
1067
+ actions: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: "12px" },
1068
+ copy: { padding: "4px 12px", fontSize: "14px", border: "1px solid #d4d4d4", borderRadius: "6px", backgroundColor: "#ffffff", color: "#262626", cursor: "pointer" },
1069
+ done: { padding: "4px 12px", fontSize: "14px", border: "none", backgroundColor: "transparent", color: "#404040", cursor: "pointer" },
1070
+ note: { fontSize: "14px", color: "#404040" }
1071
+ };
1072
+ function ShowOnceSecret({ secret, title, onDone, display = "text", secretTestId, children, labels, classNames }) {
1073
+ const { copy, note, status, reset } = useCopyToClipboard({ copiedNote: labels?.copied, failedNote: labels?.failed });
1074
+ useEffect5(() => {
1075
+ reset();
1076
+ }, [secret, reset]);
1077
+ const part = (key) => {
1078
+ const className = classNames?.[key];
1079
+ return className ? { className } : { style: defaults6[key] };
1080
+ };
1081
+ return /* @__PURE__ */ jsxs9("div", { ...part("root"), children: [
1082
+ /* @__PURE__ */ jsxs9("p", { ...part("title"), children: [
1083
+ title,
1084
+ " ",
1085
+ /* @__PURE__ */ jsx10("span", { ...part("warning"), children: labels?.warning ?? "Copy it now: you will not see it again." })
1086
+ ] }),
1087
+ display === "field" ? /* @__PURE__ */ jsx10("input", { readOnly: true, value: secret, "aria-label": labels?.secret ?? "Secret", "data-testid": secretTestId, onFocus: (event) => event.currentTarget.select(), ...part("secret") }) : /* @__PURE__ */ jsx10("code", { "data-testid": secretTestId, ...part("secret"), children: secret }),
1088
+ /* @__PURE__ */ jsxs9("div", { ...part("actions"), children: [
1089
+ /* @__PURE__ */ jsx10("button", { type: "button", onClick: () => void copy(secret), ...part("copy"), children: labels?.copy ?? "Copy" }),
1090
+ /* @__PURE__ */ jsx10(
1091
+ "button",
1092
+ {
1093
+ type: "button",
1094
+ onClick: () => {
1095
+ reset();
1096
+ onDone();
1097
+ },
1098
+ ...part("done"),
1099
+ children: labels?.done ?? "Done"
1100
+ }
1101
+ ),
1102
+ /* @__PURE__ */ jsx10("span", { role: "status", "data-status": status ?? void 0, ...part("note"), children: note })
1103
+ ] }),
1104
+ children
1105
+ ] });
1106
+ }
1107
+
1108
+ // src/components/entity-picker.tsx
1109
+ import { useCallback as useCallback4, useEffect as useEffect6, useId as useId2, useRef as useRef5, useState as useState7 } from "react";
1110
+ import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
1111
+ var defaults7 = {
884
1112
  root: { position: "relative", display: "inline-flex", alignItems: "center", gap: "4px", width: "100%" },
885
1113
  input: { flex: 1, minWidth: 0, padding: "8px 10px", fontSize: "14px", border: "1px solid #d4d4d4", borderRadius: "6px", backgroundColor: "#ffffff", color: "#171717" },
886
1114
  clear: { padding: "4px 8px", fontSize: "14px", border: "1px solid transparent", borderRadius: "6px", backgroundColor: "transparent", color: "#525252", cursor: "pointer" },
@@ -915,28 +1143,28 @@ function EntityPicker({
915
1143
  style
916
1144
  }) {
917
1145
  const listId = useId2();
918
- const listRef = useRef3(null);
919
- const inputRef = useRef3(null);
920
- const selectAfterRender = useRef3(null);
921
- const [text, setText] = useState4("");
922
- const [editing, setEditing] = useState4(false);
923
- const [open, setOpen] = useState4(false);
924
- const [results, setResults] = useState4([]);
925
- const [status, setStatus] = useState4("idle");
926
- const [searched, setSearched] = useState4(false);
927
- const [activeIndex, setActiveIndex] = useState4(-1);
928
- const timer = useRef3(null);
929
- const controller = useRef3(null);
930
- const latest = useRef3(0);
931
- const cancelSearch = useCallback2(() => {
1146
+ const listRef = useRef5(null);
1147
+ const inputRef = useRef5(null);
1148
+ const selectAfterRender = useRef5(null);
1149
+ const [text, setText] = useState7("");
1150
+ const [editing, setEditing] = useState7(false);
1151
+ const [open, setOpen] = useState7(false);
1152
+ const [results, setResults] = useState7([]);
1153
+ const [status, setStatus] = useState7("idle");
1154
+ const [searched, setSearched] = useState7(false);
1155
+ const [activeIndex, setActiveIndex] = useState7(-1);
1156
+ const timer = useRef5(null);
1157
+ const controller = useRef5(null);
1158
+ const latest = useRef5(0);
1159
+ const cancelSearch = useCallback4(() => {
932
1160
  if (timer.current) clearTimeout(timer.current);
933
1161
  timer.current = null;
934
1162
  controller.current?.abort();
935
1163
  controller.current = null;
936
1164
  latest.current++;
937
1165
  }, []);
938
- useEffect3(() => cancelSearch, [cancelSearch]);
939
- const runSearch = useCallback2(
1166
+ useEffect6(() => cancelSearch, [cancelSearch]);
1167
+ const runSearch = useCallback4(
940
1168
  (query) => {
941
1169
  cancelSearch();
942
1170
  const trimmed = query.trim();
@@ -991,17 +1219,17 @@ function EntityPicker({
991
1219
  const showListbox = showPopup && results.length > 0;
992
1220
  const activeId = showListbox && activeIndex >= 0 ? `${listId}-opt-${activeIndex}` : void 0;
993
1221
  const announcement = !showPopup ? "" : status === "loading" ? loadingText : status === "error" ? errorText : results.length === 0 ? emptyText : "";
994
- useEffect3(() => {
1222
+ useEffect6(() => {
995
1223
  if (showListbox && activeIndex >= 0) listRef.current?.children[activeIndex]?.scrollIntoView?.({ block: "nearest" });
996
1224
  }, [showListbox, activeIndex]);
997
- useEffect3(() => {
1225
+ useEffect6(() => {
998
1226
  const pending = selectAfterRender.current;
999
1227
  if (!pending || editing) return;
1000
1228
  if ((value ? getKey(value) : null) !== pending.key) return;
1001
1229
  selectAfterRender.current = null;
1002
1230
  if (document.activeElement === inputRef.current) inputRef.current?.select();
1003
1231
  }, [value, editing, getKey]);
1004
- useEffect3(() => {
1232
+ useEffect6(() => {
1005
1233
  if (disabled) stopEditing();
1006
1234
  }, [disabled]);
1007
1235
  const onKeyDown = (event) => {
@@ -1027,7 +1255,7 @@ function EntityPicker({
1027
1255
  const partProps = (key) => {
1028
1256
  const className = classNames?.[key];
1029
1257
  if (className) return { className, style: key === "root" ? style : void 0 };
1030
- return { style: key === "root" ? { ...defaults3.root, ...style } : defaults3[key] };
1258
+ return { style: key === "root" ? { ...defaults7.root, ...style } : defaults7[key] };
1031
1259
  };
1032
1260
  const optionProps = (active) => {
1033
1261
  const optionClass = classNames?.option;
@@ -1036,8 +1264,8 @@ function EntityPicker({
1036
1264
  return { className, style: optionClass ? void 0 : { ...optionDefaults.base, ...active && !activeClass ? optionDefaults.active : {} } };
1037
1265
  };
1038
1266
  const shown = editing ? text : value ? getLabel(value) : "";
1039
- return /* @__PURE__ */ jsxs6("div", { ...partProps("root"), children: [
1040
- /* @__PURE__ */ jsx7(
1267
+ return /* @__PURE__ */ jsxs10("div", { ...partProps("root"), children: [
1268
+ /* @__PURE__ */ jsx11(
1041
1269
  "input",
1042
1270
  {
1043
1271
  ...partProps("input"),
@@ -1069,19 +1297,19 @@ function EntityPicker({
1069
1297
  }
1070
1298
  }
1071
1299
  ),
1072
- name !== void 0 ? /* @__PURE__ */ jsx7("input", { type: "hidden", name, value: value ? getKey(value) : "", disabled }) : null,
1073
- clearable && value && !disabled ? /* @__PURE__ */ jsx7("button", { type: "button", "aria-label": clearLabel, ...partProps("clear"), onClick: () => {
1300
+ name !== void 0 ? /* @__PURE__ */ jsx11("input", { type: "hidden", name, value: value ? getKey(value) : "", disabled }) : null,
1301
+ clearable && value && !disabled ? /* @__PURE__ */ jsx11("button", { type: "button", "aria-label": clearLabel, ...partProps("clear"), onClick: () => {
1074
1302
  onChange(null);
1075
1303
  inputRef.current?.focus();
1076
1304
  }, children: "\xD7" }) : null,
1077
- /* @__PURE__ */ jsx7("div", { role: "status", "aria-live": "polite", style: visuallyHidden2, children: announcement }),
1305
+ /* @__PURE__ */ jsx11("div", { role: "status", "aria-live": "polite", style: visuallyHidden2, children: announcement }),
1078
1306
  showPopup ? (
1079
1307
  // mousedown anywhere in the popup (an option, the scrollbar, a message) must not move focus out of the input, or its
1080
1308
  // blur would close the list before the click lands (and make a long list impossible to scroll by dragging)
1081
- /* @__PURE__ */ jsxs6("div", { ...partProps("list"), onMouseDown: (event) => event.preventDefault(), children: [
1082
- showListbox ? /* @__PURE__ */ jsx7("ul", { ref: listRef, id: listId, role: "listbox", "aria-label": ariaLabel, style: { listStyle: "none", margin: 0, padding: 0 }, children: results.map((item, index) => {
1309
+ /* @__PURE__ */ jsxs10("div", { ...partProps("list"), onMouseDown: (event) => event.preventDefault(), children: [
1310
+ showListbox ? /* @__PURE__ */ jsx11("ul", { ref: listRef, id: listId, role: "listbox", "aria-label": ariaLabel, style: { listStyle: "none", margin: 0, padding: 0 }, children: results.map((item, index) => {
1083
1311
  const active = index === activeIndex;
1084
- return /* @__PURE__ */ jsx7(
1312
+ return /* @__PURE__ */ jsx11(
1085
1313
  "li",
1086
1314
  {
1087
1315
  id: `${listId}-opt-${index}`,
@@ -1097,16 +1325,16 @@ function EntityPicker({
1097
1325
  getKey(item)
1098
1326
  );
1099
1327
  }) }) : null,
1100
- status === "loading" ? /* @__PURE__ */ jsx7("div", { "aria-hidden": "true", "data-entity-picker-message": "loading", ...partProps("message"), children: loadingText }) : null,
1101
- status === "error" ? /* @__PURE__ */ jsx7("div", { "aria-hidden": "true", "data-entity-picker-message": "error", ...partProps("message"), children: errorText }) : null,
1102
- status === "idle" && searched && results.length === 0 ? /* @__PURE__ */ jsx7("div", { "aria-hidden": "true", "data-entity-picker-message": "empty", ...partProps("message"), children: emptyText }) : null
1328
+ status === "loading" ? /* @__PURE__ */ jsx11("div", { "aria-hidden": "true", "data-entity-picker-message": "loading", ...partProps("message"), children: loadingText }) : null,
1329
+ status === "error" ? /* @__PURE__ */ jsx11("div", { "aria-hidden": "true", "data-entity-picker-message": "error", ...partProps("message"), children: errorText }) : null,
1330
+ status === "idle" && searched && results.length === 0 ? /* @__PURE__ */ jsx11("div", { "aria-hidden": "true", "data-entity-picker-message": "empty", ...partProps("message"), children: emptyText }) : null
1103
1331
  ] })
1104
1332
  ) : null
1105
1333
  ] });
1106
1334
  }
1107
1335
 
1108
1336
  // src/components/rich-text-editor.tsx
1109
- import { useCallback as useCallback3, useEffect as useEffect4, useRef as useRef4, useState as useState5 } from "react";
1337
+ import { useCallback as useCallback5, useEffect as useEffect7, useRef as useRef6, useState as useState8 } from "react";
1110
1338
 
1111
1339
  // src/components/rich-text-editor-styles.ts
1112
1340
  var containerStyle = {
@@ -1159,7 +1387,7 @@ var editableStyle = {
1159
1387
  };
1160
1388
 
1161
1389
  // src/components/rich-text-editor.tsx
1162
- import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
1390
+ import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
1163
1391
  var TOOLBAR_BUTTONS = [
1164
1392
  { command: "bold", label: "B", ariaLabel: "Bold" },
1165
1393
  { command: "italic", label: "I", ariaLabel: "Italic" },
@@ -1191,26 +1419,26 @@ function RichTextEditor({
1191
1419
  className,
1192
1420
  style
1193
1421
  }) {
1194
- const editorRef = useRef4(null);
1195
- const [isFocused, setIsFocused] = useState5(false);
1196
- const [isEmpty, setIsEmpty] = useState5(isEmptyHtml(content));
1197
- const [linkError, setLinkError] = useState5(null);
1198
- useEffect4(() => {
1422
+ const editorRef = useRef6(null);
1423
+ const [isFocused, setIsFocused] = useState8(false);
1424
+ const [isEmpty, setIsEmpty] = useState8(isEmptyHtml(content));
1425
+ const [linkError, setLinkError] = useState8(null);
1426
+ useEffect7(() => {
1199
1427
  const el = editorRef.current;
1200
1428
  if (el && !isFocused && el.innerHTML !== content) {
1201
1429
  el.innerHTML = content;
1202
1430
  setIsEmpty(isEmptyHtml(content));
1203
1431
  }
1204
1432
  }, [content, isFocused, editable]);
1205
- useEffect4(() => {
1433
+ useEffect7(() => {
1206
1434
  if (autoFocus) editorRef.current?.focus();
1207
1435
  }, []);
1208
- const handleInput = useCallback3(() => {
1436
+ const handleInput = useCallback5(() => {
1209
1437
  const html = editorRef.current?.innerHTML ?? "";
1210
1438
  setIsEmpty(isEmptyHtml(html));
1211
1439
  onChange(html);
1212
1440
  }, [onChange]);
1213
- const runCommand = useCallback3(
1441
+ const runCommand = useCallback5(
1214
1442
  (command, value) => {
1215
1443
  editorRef.current?.focus();
1216
1444
  document.execCommand(command, false, value);
@@ -1218,7 +1446,7 @@ function RichTextEditor({
1218
1446
  },
1219
1447
  [handleInput]
1220
1448
  );
1221
- const handleLink = useCallback3(() => {
1449
+ const handleLink = useCallback5(() => {
1222
1450
  const url = window.prompt("Link URL")?.trim();
1223
1451
  setLinkError(null);
1224
1452
  if (!url) return;
@@ -1229,7 +1457,7 @@ function RichTextEditor({
1229
1457
  runCommand("createLink", url);
1230
1458
  }, [runCommand]);
1231
1459
  if (!editable) {
1232
- return /* @__PURE__ */ jsx8(
1460
+ return /* @__PURE__ */ jsx12(
1233
1461
  "div",
1234
1462
  {
1235
1463
  className: [className, "ordinatio-rte", "ordinatio-rte-readonly"].filter(Boolean).join(" "),
@@ -1238,9 +1466,9 @@ function RichTextEditor({
1238
1466
  }
1239
1467
  );
1240
1468
  }
1241
- return /* @__PURE__ */ jsxs7("div", { className: [className, "ordinatio-rte"].filter(Boolean).join(" "), style: className ? style : { ...containerStyle, ...style }, children: [
1242
- /* @__PURE__ */ jsxs7("div", { className: "ordinatio-rte-toolbar", style: toolbarStyle, children: [
1243
- TOOLBAR_BUTTONS.map((btn) => /* @__PURE__ */ jsx8(
1469
+ return /* @__PURE__ */ jsxs11("div", { className: [className, "ordinatio-rte"].filter(Boolean).join(" "), style: className ? style : { ...containerStyle, ...style }, children: [
1470
+ /* @__PURE__ */ jsxs11("div", { className: "ordinatio-rte-toolbar", style: toolbarStyle, children: [
1471
+ TOOLBAR_BUTTONS.map((btn) => /* @__PURE__ */ jsx12(
1244
1472
  "button",
1245
1473
  {
1246
1474
  type: "button",
@@ -1254,7 +1482,7 @@ function RichTextEditor({
1254
1482
  },
1255
1483
  btn.command
1256
1484
  )),
1257
- /* @__PURE__ */ jsx8(
1485
+ /* @__PURE__ */ jsx12(
1258
1486
  "button",
1259
1487
  {
1260
1488
  type: "button",
@@ -1267,10 +1495,10 @@ function RichTextEditor({
1267
1495
  children: "\u{1F517}"
1268
1496
  }
1269
1497
  ),
1270
- toolbarRight ? /* @__PURE__ */ jsx8("div", { className: "ordinatio-rte-toolbar-right", style: toolbarRightStyle, children: toolbarRight }) : null
1498
+ toolbarRight ? /* @__PURE__ */ jsx12("div", { className: "ordinatio-rte-toolbar-right", style: toolbarRightStyle, children: toolbarRight }) : null
1271
1499
  ] }),
1272
- linkError ? /* @__PURE__ */ jsx8("div", { className: "ordinatio-rte-link-error", role: "alert", style: linkErrorStyle, children: linkError }) : null,
1273
- /* @__PURE__ */ jsxs7("div", { className: "ordinatio-rte-editable-wrap", style: { position: "relative" }, children: [
1500
+ linkError ? /* @__PURE__ */ jsx12("div", { className: "ordinatio-rte-link-error", role: "alert", style: linkErrorStyle, children: linkError }) : null,
1501
+ /* @__PURE__ */ jsxs11("div", { className: "ordinatio-rte-editable-wrap", style: { position: "relative" }, children: [
1274
1502
  isEmpty ? (
1275
1503
  // Shown while empty REGARDLESS of focus — WorldClass cycle 1:
1276
1504
  // the prior `isEmpty && !isFocused` condition hid the
@@ -1279,7 +1507,7 @@ function RichTextEditor({
1279
1507
  // the click landed. Matches native `<textarea placeholder>`
1280
1508
  // behavior (visible while focused-and-empty, removed only once
1281
1509
  // the user types).
1282
- /* @__PURE__ */ jsx8(
1510
+ /* @__PURE__ */ jsx12(
1283
1511
  "div",
1284
1512
  {
1285
1513
  "aria-hidden": "true",
@@ -1289,7 +1517,7 @@ function RichTextEditor({
1289
1517
  }
1290
1518
  )
1291
1519
  ) : null,
1292
- /* @__PURE__ */ jsx8(
1520
+ /* @__PURE__ */ jsx12(
1293
1521
  "div",
1294
1522
  {
1295
1523
  ref: editorRef,
@@ -1311,7 +1539,7 @@ function RichTextEditor({
1311
1539
  }
1312
1540
 
1313
1541
  // src/components/reply-panel.tsx
1314
- import { useEffect as useEffect5, useId as useId3, useRef as useRef5, useState as useState6 } from "react";
1542
+ import { useEffect as useEffect8, useId as useId3, useRef as useRef7, useState as useState9 } from "react";
1315
1543
 
1316
1544
  // src/components/subject-prefix.ts
1317
1545
  function prefixSubject(subject, mode) {
@@ -1401,7 +1629,7 @@ var disabledButtonStyle = {
1401
1629
  };
1402
1630
 
1403
1631
  // src/components/reply-panel.tsx
1404
- import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
1632
+ import { Fragment as Fragment3, jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
1405
1633
  function ReplyPanel({
1406
1634
  mode = "reply",
1407
1635
  subject,
@@ -1425,17 +1653,17 @@ function ReplyPanel({
1425
1653
  const ccId = `${idPrefix}-cc`;
1426
1654
  const bccId = `${idPrefix}-bcc`;
1427
1655
  const subjectId = `${idPrefix}-subject`;
1428
- const [to, setTo] = useState6(defaultTo);
1429
- const [cc, setCc] = useState6(initialCc);
1430
- const [bcc, setBcc] = useState6("");
1431
- const [showCcBcc, setShowCcBcc] = useState6(initialShowCcBcc || !!initialCc);
1432
- const [editedSubject, setEditedSubject] = useState6(defaultSubject);
1433
- const [body, setBody] = useState6(initialBody);
1434
- const [sending, setSending] = useState6(false);
1435
- const [error, setError] = useState6(null);
1436
- const [sent, setSent] = useState6(false);
1437
- const isMountedRef = useRef5(true);
1438
- useEffect5(() => {
1656
+ const [to, setTo] = useState9(defaultTo);
1657
+ const [cc, setCc] = useState9(initialCc);
1658
+ const [bcc, setBcc] = useState9("");
1659
+ const [showCcBcc, setShowCcBcc] = useState9(initialShowCcBcc || !!initialCc);
1660
+ const [editedSubject, setEditedSubject] = useState9(defaultSubject);
1661
+ const [body, setBody] = useState9(initialBody);
1662
+ const [sending, setSending] = useState9(false);
1663
+ const [error, setError] = useState9(null);
1664
+ const [sent, setSent] = useState9(false);
1665
+ const isMountedRef = useRef7(true);
1666
+ useEffect8(() => {
1439
1667
  isMountedRef.current = true;
1440
1668
  return () => {
1441
1669
  isMountedRef.current = false;
@@ -1480,16 +1708,16 @@ function ReplyPanel({
1480
1708
  if (isMountedRef.current) setSending(false);
1481
1709
  }
1482
1710
  };
1483
- return /* @__PURE__ */ jsxs8(
1711
+ return /* @__PURE__ */ jsxs12(
1484
1712
  "div",
1485
1713
  {
1486
1714
  className: [className, "ordinatio-reply-panel"].filter(Boolean).join(" "),
1487
1715
  style: className ? style : { display: "flex", flexDirection: "column", gap: "8px", ...style },
1488
1716
  children: [
1489
- /* @__PURE__ */ jsxs8("div", { className: "ordinatio-reply-fields", style: { display: "flex", flexDirection: "column", gap: "6px" }, children: [
1490
- /* @__PURE__ */ jsxs8("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1491
- /* @__PURE__ */ jsx9("label", { htmlFor: toId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "To" }),
1492
- /* @__PURE__ */ jsx9(
1717
+ /* @__PURE__ */ jsxs12("div", { className: "ordinatio-reply-fields", style: { display: "flex", flexDirection: "column", gap: "6px" }, children: [
1718
+ /* @__PURE__ */ jsxs12("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1719
+ /* @__PURE__ */ jsx13("label", { htmlFor: toId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "To" }),
1720
+ /* @__PURE__ */ jsx13(
1493
1721
  "input",
1494
1722
  {
1495
1723
  id: toId,
@@ -1517,7 +1745,7 @@ function ReplyPanel({
1517
1745
  // and aria-controls referenced ids (ccId/bccId) that don't
1518
1746
  // exist in the DOM until AFTER this button has already
1519
1747
  // unmounted. A one-directional reveal, not a toggle.
1520
- /* @__PURE__ */ jsx9(
1748
+ /* @__PURE__ */ jsx13(
1521
1749
  "button",
1522
1750
  {
1523
1751
  type: "button",
@@ -1530,10 +1758,10 @@ function ReplyPanel({
1530
1758
  )
1531
1759
  ) : null
1532
1760
  ] }),
1533
- showCcBcc ? /* @__PURE__ */ jsxs8(Fragment3, { children: [
1534
- /* @__PURE__ */ jsxs8("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1535
- /* @__PURE__ */ jsx9("label", { htmlFor: ccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Cc" }),
1536
- /* @__PURE__ */ jsx9(
1761
+ showCcBcc ? /* @__PURE__ */ jsxs12(Fragment3, { children: [
1762
+ /* @__PURE__ */ jsxs12("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1763
+ /* @__PURE__ */ jsx13("label", { htmlFor: ccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Cc" }),
1764
+ /* @__PURE__ */ jsx13(
1537
1765
  "input",
1538
1766
  {
1539
1767
  id: ccId,
@@ -1551,9 +1779,9 @@ function ReplyPanel({
1551
1779
  }
1552
1780
  )
1553
1781
  ] }),
1554
- /* @__PURE__ */ jsxs8("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1555
- /* @__PURE__ */ jsx9("label", { htmlFor: bccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Bcc" }),
1556
- /* @__PURE__ */ jsx9(
1782
+ /* @__PURE__ */ jsxs12("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1783
+ /* @__PURE__ */ jsx13("label", { htmlFor: bccId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Bcc" }),
1784
+ /* @__PURE__ */ jsx13(
1557
1785
  "input",
1558
1786
  {
1559
1787
  id: bccId,
@@ -1572,9 +1800,9 @@ function ReplyPanel({
1572
1800
  )
1573
1801
  ] })
1574
1802
  ] }) : null,
1575
- /* @__PURE__ */ jsxs8("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1576
- /* @__PURE__ */ jsx9("label", { htmlFor: subjectId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Subject" }),
1577
- /* @__PURE__ */ jsx9(
1803
+ /* @__PURE__ */ jsxs12("div", { className: "ordinatio-reply-field-row", style: fieldRowStyle, children: [
1804
+ /* @__PURE__ */ jsx13("label", { htmlFor: subjectId, className: "ordinatio-reply-field-label", style: fieldLabelStyle, children: "Subject" }),
1805
+ /* @__PURE__ */ jsx13(
1578
1806
  "input",
1579
1807
  {
1580
1808
  id: subjectId,
@@ -1593,9 +1821,9 @@ function ReplyPanel({
1593
1821
  )
1594
1822
  ] })
1595
1823
  ] }),
1596
- error ? /* @__PURE__ */ jsx9("div", { className: "ordinatio-reply-error", role: "alert", style: errorStyle, children: error }) : null,
1597
- sent && resolvedSuccessMessage ? /* @__PURE__ */ jsx9("div", { className: "ordinatio-reply-success", role: "status", style: successStyle, children: resolvedSuccessMessage }) : null,
1598
- /* @__PURE__ */ jsx9(
1824
+ error ? /* @__PURE__ */ jsx13("div", { className: "ordinatio-reply-error", role: "alert", style: errorStyle, children: error }) : null,
1825
+ sent && resolvedSuccessMessage ? /* @__PURE__ */ jsx13("div", { className: "ordinatio-reply-success", role: "status", style: successStyle, children: resolvedSuccessMessage }) : null,
1826
+ /* @__PURE__ */ jsx13(
1599
1827
  RichTextEditor,
1600
1828
  {
1601
1829
  content: body,
@@ -1609,8 +1837,8 @@ function ReplyPanel({
1609
1837
  locked: sending
1610
1838
  }
1611
1839
  ),
1612
- /* @__PURE__ */ jsxs8("div", { className: "ordinatio-reply-actions", style: actionsRowStyle, children: [
1613
- showCancel && onCancel ? /* @__PURE__ */ jsx9(
1840
+ /* @__PURE__ */ jsxs12("div", { className: "ordinatio-reply-actions", style: actionsRowStyle, children: [
1841
+ showCancel && onCancel ? /* @__PURE__ */ jsx13(
1614
1842
  "button",
1615
1843
  {
1616
1844
  type: "button",
@@ -1621,7 +1849,7 @@ function ReplyPanel({
1621
1849
  children: "Cancel"
1622
1850
  }
1623
1851
  ) : null,
1624
- /* @__PURE__ */ jsx9(
1852
+ /* @__PURE__ */ jsx13(
1625
1853
  "button",
1626
1854
  {
1627
1855
  type: "button",
@@ -1639,7 +1867,7 @@ function ReplyPanel({
1639
1867
  }
1640
1868
 
1641
1869
  // src/hooks/use-keyboard-shortcuts.ts
1642
- import { useEffect as useEffect6, useCallback as useCallback4 } from "react";
1870
+ import { useEffect as useEffect9, useCallback as useCallback6 } from "react";
1643
1871
 
1644
1872
  // src/hooks/is-typing-context.ts
1645
1873
  var TYPING_TAG_RE = /^(INPUT|TEXTAREA|SELECT)$/;
@@ -1664,14 +1892,14 @@ function useKeyboardShortcuts({
1664
1892
  ignoreTags = []
1665
1893
  }) {
1666
1894
  const malformed = !Array.isArray(shortcuts);
1667
- useEffect6(() => {
1895
+ useEffect9(() => {
1668
1896
  if (malformed) {
1669
1897
  console.error(
1670
1898
  "[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."
1671
1899
  );
1672
1900
  }
1673
1901
  }, [malformed]);
1674
- const handleKeyDown = useCallback4(
1902
+ const handleKeyDown = useCallback6(
1675
1903
  (e) => {
1676
1904
  if (!enabled || malformed) return;
1677
1905
  if (e.isComposing || e.keyCode === 229) return;
@@ -1699,7 +1927,7 @@ function useKeyboardShortcuts({
1699
1927
  },
1700
1928
  [shortcuts, enabled, ignoreTags, malformed]
1701
1929
  );
1702
- useEffect6(() => {
1930
+ useEffect9(() => {
1703
1931
  window.addEventListener("keydown", handleKeyDown);
1704
1932
  return () => window.removeEventListener("keydown", handleKeyDown);
1705
1933
  }, [handleKeyDown]);
@@ -1869,13 +2097,13 @@ function getShortcut(context, action) {
1869
2097
  }
1870
2098
 
1871
2099
  // src/components/keyboard-shortcuts-panel.tsx
1872
- import { useEffect as useEffect7, useState as useState7 } from "react";
1873
- import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
2100
+ import { useEffect as useEffect10, useState as useState10 } from "react";
2101
+ import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
1874
2102
  function KeyboardShortcutsPanel({
1875
2103
  contexts = ALL_SHORTCUT_CONTEXTS
1876
2104
  }) {
1877
- const [open, setOpen] = useState7(false);
1878
- useEffect7(() => {
2105
+ const [open, setOpen] = useState10(false);
2106
+ useEffect10(() => {
1879
2107
  function handleKey(e) {
1880
2108
  if (e.key === "?" && !e.metaKey && !e.ctrlKey && !e.altKey) {
1881
2109
  const tag = e.target?.tagName;
@@ -1892,33 +2120,33 @@ function KeyboardShortcutsPanel({
1892
2120
  return () => window.removeEventListener("keydown", handleKey);
1893
2121
  }, [open]);
1894
2122
  if (!open) return null;
1895
- return /* @__PURE__ */ jsxs9(Fragment4, { children: [
1896
- /* @__PURE__ */ jsx10(
2123
+ return /* @__PURE__ */ jsxs13(Fragment4, { children: [
2124
+ /* @__PURE__ */ jsx14(
1897
2125
  "div",
1898
2126
  {
1899
2127
  className: "fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",
1900
2128
  onClick: () => setOpen(false)
1901
2129
  }
1902
2130
  ),
1903
- /* @__PURE__ */ jsx10("div", { className: "fixed inset-x-0 top-[10%] z-50 mx-auto w-full max-w-lg", children: /* @__PURE__ */ jsxs9("div", { className: "rounded-xl border bg-background shadow-2xl overflow-hidden", children: [
1904
- /* @__PURE__ */ jsxs9("div", { className: "px-6 py-4 border-b", children: [
1905
- /* @__PURE__ */ jsx10("h2", { className: "text-lg font-semibold", children: "Keyboard Shortcuts" }),
1906
- /* @__PURE__ */ jsxs9("p", { className: "text-sm text-muted-foreground mt-0.5", children: [
2131
+ /* @__PURE__ */ jsx14("div", { className: "fixed inset-x-0 top-[10%] z-50 mx-auto w-full max-w-lg", children: /* @__PURE__ */ jsxs13("div", { className: "rounded-xl border bg-background shadow-2xl overflow-hidden", children: [
2132
+ /* @__PURE__ */ jsxs13("div", { className: "px-6 py-4 border-b", children: [
2133
+ /* @__PURE__ */ jsx14("h2", { className: "text-lg font-semibold", children: "Keyboard Shortcuts" }),
2134
+ /* @__PURE__ */ jsxs13("p", { className: "text-sm text-muted-foreground mt-0.5", children: [
1907
2135
  "Press ",
1908
- /* @__PURE__ */ jsx10("kbd", { className: "px-1.5 py-0.5 bg-muted rounded text-xs font-mono", children: "?" }),
2136
+ /* @__PURE__ */ jsx14("kbd", { className: "px-1.5 py-0.5 bg-muted rounded text-xs font-mono", children: "?" }),
1909
2137
  " to toggle this panel"
1910
2138
  ] })
1911
2139
  ] }),
1912
- /* @__PURE__ */ jsx10("div", { className: "px-6 py-4 max-h-[60vh] overflow-y-auto space-y-6", children: contexts.map((ctx) => /* @__PURE__ */ jsxs9("div", { children: [
1913
- /* @__PURE__ */ jsx10("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: ctx.label }),
1914
- /* @__PURE__ */ jsx10("div", { className: "space-y-1", children: Object.entries(ctx.shortcuts).map(([key, def]) => /* @__PURE__ */ jsxs9("div", { className: "flex items-center justify-between py-1", children: [
1915
- /* @__PURE__ */ jsx10("span", { className: "text-sm", children: def.description }),
1916
- /* @__PURE__ */ jsx10("kbd", { className: "px-2 py-0.5 bg-muted rounded text-xs font-mono min-w-[2rem] text-center", children: def.display })
2140
+ /* @__PURE__ */ jsx14("div", { className: "px-6 py-4 max-h-[60vh] overflow-y-auto space-y-6", children: contexts.map((ctx) => /* @__PURE__ */ jsxs13("div", { children: [
2141
+ /* @__PURE__ */ jsx14("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: ctx.label }),
2142
+ /* @__PURE__ */ jsx14("div", { className: "space-y-1", children: Object.entries(ctx.shortcuts).map(([key, def]) => /* @__PURE__ */ jsxs13("div", { className: "flex items-center justify-between py-1", children: [
2143
+ /* @__PURE__ */ jsx14("span", { className: "text-sm", children: def.description }),
2144
+ /* @__PURE__ */ jsx14("kbd", { className: "px-2 py-0.5 bg-muted rounded text-xs font-mono min-w-[2rem] text-center", children: def.display })
1917
2145
  ] }, key)) })
1918
2146
  ] }, ctx.name)) }),
1919
- /* @__PURE__ */ jsxs9("div", { className: "px-6 py-3 border-t bg-muted/30 text-xs text-muted-foreground text-center", children: [
2147
+ /* @__PURE__ */ jsxs13("div", { className: "px-6 py-3 border-t bg-muted/30 text-xs text-muted-foreground text-center", children: [
1920
2148
  "Press ",
1921
- /* @__PURE__ */ jsx10("kbd", { className: "px-1 py-0.5 bg-muted rounded", children: "Esc" }),
2149
+ /* @__PURE__ */ jsx14("kbd", { className: "px-1 py-0.5 bg-muted rounded", children: "Esc" }),
1922
2150
  " to close"
1923
2151
  ] })
1924
2152
  ] }) })
@@ -1926,21 +2154,21 @@ function KeyboardShortcutsPanel({
1926
2154
  }
1927
2155
 
1928
2156
  // src/hooks/use-auto-save.ts
1929
- import { useEffect as useEffect8, useRef as useRef6, useCallback as useCallback5, useState as useState8 } from "react";
2157
+ import { useEffect as useEffect11, useRef as useRef8, useCallback as useCallback7, useState as useState11 } from "react";
1930
2158
  function useAutoSave({
1931
2159
  data,
1932
2160
  onSave,
1933
2161
  delay = 5e3,
1934
2162
  enabled = true
1935
2163
  }) {
1936
- const [lastSavedAt, setLastSavedAt] = useState8(null);
1937
- const [isSaving, setIsSaving] = useState8(false);
1938
- const [saveError, setSaveError] = useState8(null);
1939
- const timerRef = useRef6(null);
1940
- const dataRef = useRef6(data);
1941
- const savedDataRef = useRef6(null);
2164
+ const [lastSavedAt, setLastSavedAt] = useState11(null);
2165
+ const [isSaving, setIsSaving] = useState11(false);
2166
+ const [saveError, setSaveError] = useState11(null);
2167
+ const timerRef = useRef8(null);
2168
+ const dataRef = useRef8(data);
2169
+ const savedDataRef = useRef8(null);
1942
2170
  dataRef.current = data;
1943
- const save = useCallback5(async () => {
2171
+ const save = useCallback7(async () => {
1944
2172
  const currentJson = JSON.stringify(dataRef.current);
1945
2173
  if (currentJson === savedDataRef.current) return;
1946
2174
  setIsSaving(true);
@@ -1955,7 +2183,7 @@ function useAutoSave({
1955
2183
  setIsSaving(false);
1956
2184
  }
1957
2185
  }, [onSave]);
1958
- useEffect8(() => {
2186
+ useEffect11(() => {
1959
2187
  if (!enabled) return;
1960
2188
  if (timerRef.current) clearTimeout(timerRef.current);
1961
2189
  timerRef.current = setTimeout(save, delay);
@@ -1967,19 +2195,19 @@ function useAutoSave({
1967
2195
  }
1968
2196
 
1969
2197
  // src/hooks/use-polling.ts
1970
- import { useEffect as useEffect9, useCallback as useCallback6, useRef as useRef7, useState as useState9 } from "react";
2198
+ import { useEffect as useEffect12, useCallback as useCallback8, useRef as useRef9, useState as useState12 } from "react";
1971
2199
  function usePolling({
1972
2200
  fetcher,
1973
2201
  interval = 3e4,
1974
2202
  enabled = true,
1975
2203
  onError
1976
2204
  }) {
1977
- const [data, setData] = useState9(null);
1978
- const [isLoading, setIsLoading] = useState9(true);
1979
- const [isRefreshing, setIsRefreshing] = useState9(false);
1980
- const [error, setError] = useState9(null);
1981
- const mountedRef = useRef7(true);
1982
- const doFetch = useCallback6(async (isInitial = false) => {
2205
+ const [data, setData] = useState12(null);
2206
+ const [isLoading, setIsLoading] = useState12(true);
2207
+ const [isRefreshing, setIsRefreshing] = useState12(false);
2208
+ const [error, setError] = useState12(null);
2209
+ const mountedRef = useRef9(true);
2210
+ const doFetch = useCallback8(async (isInitial = false) => {
1983
2211
  if (isInitial) setIsLoading(true);
1984
2212
  else setIsRefreshing(true);
1985
2213
  try {
@@ -2000,36 +2228,36 @@ function usePolling({
2000
2228
  }
2001
2229
  }
2002
2230
  }, [fetcher, onError]);
2003
- useEffect9(() => {
2231
+ useEffect12(() => {
2004
2232
  mountedRef.current = true;
2005
2233
  if (enabled) doFetch(true);
2006
2234
  return () => {
2007
2235
  mountedRef.current = false;
2008
2236
  };
2009
2237
  }, [doFetch, enabled]);
2010
- useEffect9(() => {
2238
+ useEffect12(() => {
2011
2239
  if (!enabled) return;
2012
2240
  const timer = setInterval(() => doFetch(false), interval);
2013
2241
  return () => clearInterval(timer);
2014
2242
  }, [doFetch, interval, enabled]);
2015
- const refresh = useCallback6(() => doFetch(false), [doFetch]);
2243
+ const refresh = useCallback8(() => doFetch(false), [doFetch]);
2016
2244
  return { data, isLoading, isRefreshing, error, refresh };
2017
2245
  }
2018
2246
 
2019
2247
  // src/hooks/use-server-search.ts
2020
- import { useEffect as useEffect10, useRef as useRef8, useState as useState10, useCallback as useCallback7 } from "react";
2248
+ import { useEffect as useEffect13, useRef as useRef10, useState as useState13, useCallback as useCallback9 } from "react";
2021
2249
  function useServerSearch({
2022
2250
  fetcher,
2023
2251
  debounce = 150,
2024
2252
  minChars = 1,
2025
2253
  enabled = true
2026
2254
  }) {
2027
- const [query, setQuery] = useState10("");
2028
- const [results, setResults] = useState10([]);
2029
- const [isSearching, setIsSearching] = useState10(false);
2030
- const [isOpen, setIsOpen] = useState10(false);
2031
- const timerRef = useRef8(null);
2032
- useEffect10(() => {
2255
+ const [query, setQuery] = useState13("");
2256
+ const [results, setResults] = useState13([]);
2257
+ const [isSearching, setIsSearching] = useState13(false);
2258
+ const [isOpen, setIsOpen] = useState13(false);
2259
+ const timerRef = useRef10(null);
2260
+ useEffect13(() => {
2033
2261
  if (!enabled || query.length < minChars) {
2034
2262
  setResults([]);
2035
2263
  return;
@@ -2050,7 +2278,7 @@ function useServerSearch({
2050
2278
  if (timerRef.current) clearTimeout(timerRef.current);
2051
2279
  };
2052
2280
  }, [query, fetcher, debounce, minChars, enabled]);
2053
- const clear = useCallback7(() => {
2281
+ const clear = useCallback9(() => {
2054
2282
  setQuery("");
2055
2283
  setResults([]);
2056
2284
  setIsOpen(false);
@@ -2059,9 +2287,9 @@ function useServerSearch({
2059
2287
  }
2060
2288
 
2061
2289
  // src/hooks/use-iframe-focus-reclaim.ts
2062
- import { useEffect as useEffect11 } from "react";
2290
+ import { useEffect as useEffect14 } from "react";
2063
2291
  function useIframeFocusReclaim(containerRef, enabled = true, iframeSelector = "iframe") {
2064
- useEffect11(() => {
2292
+ useEffect14(() => {
2065
2293
  if (!enabled) return;
2066
2294
  const el = containerRef.current;
2067
2295
  if (!el) return;
@@ -2188,11 +2416,11 @@ function useIframeFocusReclaim(containerRef, enabled = true, iframeSelector = "i
2188
2416
  }
2189
2417
 
2190
2418
  // src/hooks/use-form-action-keeping-input.ts
2191
- import { useRef as useRef9, useState as useState11, useTransition } from "react";
2419
+ import { useRef as useRef11, useState as useState14, useTransition } from "react";
2192
2420
  function useFormActionKeepingInput(action, initialState) {
2193
- const [state, setState] = useState11(initialState);
2421
+ const [state, setState] = useState14(initialState);
2194
2422
  const [pending, startTransition] = useTransition();
2195
- const inFlight = useRef9(false);
2423
+ const inFlight = useRef11(false);
2196
2424
  const onSubmit = (event) => {
2197
2425
  event.preventDefault();
2198
2426
  if (inFlight.current || pending) return;
@@ -2212,9 +2440,9 @@ function useFormActionKeepingInput(action, initialState) {
2212
2440
  }
2213
2441
 
2214
2442
  // src/hooks/use-synced-select.ts
2215
- import { useLayoutEffect, useRef as useRef10 } from "react";
2443
+ import { useLayoutEffect, useRef as useRef12 } from "react";
2216
2444
  function useSyncedSelect(value, resultKey) {
2217
- const ref = useRef10(null);
2445
+ const ref = useRef12(null);
2218
2446
  useLayoutEffect(() => {
2219
2447
  if (ref.current && ref.current.value !== value) ref.current.value = value;
2220
2448
  }, [value, resultKey]);
@@ -2222,9 +2450,9 @@ function useSyncedSelect(value, resultKey) {
2222
2450
  }
2223
2451
 
2224
2452
  // src/hooks/use-saved-notice.ts
2225
- import { useState as useState12 } from "react";
2453
+ import { useState as useState15 } from "react";
2226
2454
  function useSavedNotice(state) {
2227
- const [editedAfter, setEditedAfter] = useState12(null);
2455
+ const [editedAfter, setEditedAfter] = useState15(null);
2228
2456
  return {
2229
2457
  showSaved: Boolean(state.saved) && editedAfter !== state,
2230
2458
  markEdited: () => setEditedAfter(state)
@@ -2232,13 +2460,13 @@ function useSavedNotice(state) {
2232
2460
  }
2233
2461
 
2234
2462
  // src/hooks/use-arrival.ts
2235
- import { useEffect as useEffect12, useRef as useRef11, useState as useState13 } from "react";
2463
+ import { useEffect as useEffect15, useRef as useRef13, useState as useState16 } from "react";
2236
2464
  var ARRIVAL_FADE_MS = 3e3;
2237
2465
  function useArrival(active) {
2238
- const ref = useRef11(null);
2239
- const done = useRef11(false);
2240
- const [soft, setSoft] = useState13(false);
2241
- useEffect12(() => {
2466
+ const ref = useRef13(null);
2467
+ const done = useRef13(false);
2468
+ const [soft, setSoft] = useState16(false);
2469
+ useEffect15(() => {
2242
2470
  const element = ref.current;
2243
2471
  if (!active || done.current || !element) return;
2244
2472
  done.current = true;
@@ -2250,6 +2478,103 @@ function useArrival(active) {
2250
2478
  return { ref, soft };
2251
2479
  }
2252
2480
 
2481
+ // src/hooks/use-signed-answer.ts
2482
+ import { useEffect as useEffect16, useRef as useRef14, useState as useState17 } from "react";
2483
+ function useSignedAnswer({ signature, load, active = true, delayMs = 0, onError }) {
2484
+ const [answer, setAnswer] = useState17(null);
2485
+ const latest = useRef14({ load, onError });
2486
+ latest.current = { load, onError };
2487
+ useEffect16(() => {
2488
+ setAnswer(null);
2489
+ if (!active) return;
2490
+ let cancelled = false;
2491
+ const timer = setTimeout(async () => {
2492
+ let value;
2493
+ try {
2494
+ value = await latest.current.load();
2495
+ } catch (error) {
2496
+ try {
2497
+ latest.current.onError?.(error);
2498
+ } catch {
2499
+ }
2500
+ value = null;
2501
+ }
2502
+ if (!cancelled) setAnswer({ signature, value });
2503
+ }, delayMs);
2504
+ return () => {
2505
+ cancelled = true;
2506
+ clearTimeout(timer);
2507
+ };
2508
+ }, [active, signature, delayMs]);
2509
+ const current = active && answer !== null && answer.signature === signature;
2510
+ return { value: current ? answer.value : null, ready: current };
2511
+ }
2512
+
2513
+ // src/hooks/use-picker-session.ts
2514
+ import { useCallback as useCallback10, useEffect as useEffect17, useRef as useRef15, useState as useState18 } from "react";
2515
+ var PICKER_SEARCH_FAILURE = "The search could not be run. Check your connection, then try again.";
2516
+ function usePickerSession({ source, failureMessage = PICKER_SEARCH_FAILURE, resetKey, onSourceError }) {
2517
+ const [picking, setPicking] = useState18(false);
2518
+ const [searchError, setSearchError] = useState18(null);
2519
+ const searchSeq = useRef15(0);
2520
+ const rootRef = useRef15(null);
2521
+ const restoreOpener = useRef15(false);
2522
+ const latest = useRef15({ source, failureMessage, onSourceError });
2523
+ latest.current = { source, failureMessage, onSourceError };
2524
+ const [seenKey, setSeenKey] = useState18(resetKey);
2525
+ const [epoch, setEpoch] = useState18(0);
2526
+ if (!Object.is(seenKey, resetKey)) {
2527
+ setSeenKey(resetKey);
2528
+ setPicking(false);
2529
+ setSearchError(null);
2530
+ setEpoch((value) => value + 1);
2531
+ }
2532
+ useEffect17(() => {
2533
+ searchSeq.current += 1;
2534
+ }, [epoch]);
2535
+ useEffect17(() => {
2536
+ if (picking) rootRef.current?.querySelector('input[role="combobox"]')?.focus();
2537
+ else if (restoreOpener.current) {
2538
+ restoreOpener.current = false;
2539
+ rootRef.current?.querySelector("button[data-opener]")?.focus();
2540
+ }
2541
+ }, [picking]);
2542
+ const open = useCallback10(() => setPicking(true), []);
2543
+ const invalidateSearch = useCallback10(() => {
2544
+ searchSeq.current += 1;
2545
+ }, []);
2546
+ const close = useCallback10(() => {
2547
+ searchSeq.current += 1;
2548
+ restoreOpener.current = true;
2549
+ setPicking(false);
2550
+ setSearchError(null);
2551
+ }, []);
2552
+ const search = useCallback10(async (query) => {
2553
+ const seq = ++searchSeq.current;
2554
+ let result;
2555
+ try {
2556
+ result = await latest.current.source(query);
2557
+ } catch (thrown) {
2558
+ try {
2559
+ latest.current.onSourceError?.(thrown);
2560
+ } catch {
2561
+ }
2562
+ result = { ok: false, error: latest.current.failureMessage };
2563
+ }
2564
+ if (seq === searchSeq.current) setSearchError(result.ok ? null : result.error);
2565
+ if (!result.ok) throw new Error(result.error);
2566
+ return result.options;
2567
+ }, []);
2568
+ const onKeyDown = useCallback10(
2569
+ (event) => {
2570
+ if (event.key === "Enter" && picking && event.target.getAttribute("role") === "combobox") event.preventDefault();
2571
+ if (event.key === "Escape" && picking) close();
2572
+ },
2573
+ [picking, close]
2574
+ );
2575
+ return { picking, open, close, search, searchError, invalidateSearch, groupProps: { ref: rootRef, onKeyDown } };
2576
+ }
2577
+
2253
2578
  // src/hooks/use-cached-fetch.ts
2254
2579
  var cache = /* @__PURE__ */ new Map();
2255
2580
  var inflight = /* @__PURE__ */ new Map();
@@ -2305,21 +2630,21 @@ function clearCache() {
2305
2630
  }
2306
2631
 
2307
2632
  // src/hooks/use-preferences.ts
2308
- import { useState as useState14, useEffect as useEffect13, useCallback as useCallback8 } from "react";
2633
+ import { useState as useState19, useEffect as useEffect18, useCallback as useCallback11 } from "react";
2309
2634
  function usePreferences({
2310
2635
  endpoint,
2311
- defaults: defaults4
2636
+ defaults: defaults8
2312
2637
  }) {
2313
- const [preferences, setPreferences] = useState14(defaults4 ?? null);
2314
- const [loading, setLoading] = useState14(true);
2315
- const [error, setError] = useState14(null);
2316
- const fetchPreferences = useCallback8(async () => {
2638
+ const [preferences, setPreferences] = useState19(defaults8 ?? null);
2639
+ const [loading, setLoading] = useState19(true);
2640
+ const [error, setError] = useState19(null);
2641
+ const fetchPreferences = useCallback11(async () => {
2317
2642
  try {
2318
2643
  setError(null);
2319
2644
  const res = await fetch(endpoint);
2320
2645
  if (!res.ok) {
2321
2646
  if (res.status === 401) {
2322
- setPreferences(defaults4 ?? null);
2647
+ setPreferences(defaults8 ?? null);
2323
2648
  return;
2324
2649
  }
2325
2650
  throw new Error("Failed to fetch preferences");
@@ -2331,11 +2656,11 @@ function usePreferences({
2331
2656
  } finally {
2332
2657
  setLoading(false);
2333
2658
  }
2334
- }, [endpoint, defaults4]);
2335
- useEffect13(() => {
2659
+ }, [endpoint, defaults8]);
2660
+ useEffect18(() => {
2336
2661
  fetchPreferences();
2337
2662
  }, [fetchPreferences]);
2338
- const updatePreferences = useCallback8(
2663
+ const updatePreferences = useCallback11(
2339
2664
  async (updates) => {
2340
2665
  setPreferences((prev) => prev ? { ...prev, ...updates } : updates);
2341
2666
  setError(null);
@@ -2693,6 +3018,8 @@ export {
2693
3018
  ActivityFeedRow,
2694
3019
  ArchiveButton,
2695
3020
  CLIENT_PROFILE_SHORTCUTS,
3021
+ COPY_NOTE_COPIED,
3022
+ COPY_NOTE_FAILED,
2696
3023
  ConfirmAction,
2697
3024
  EmailBodyRenderer,
2698
3025
  EmailThreadView,
@@ -2700,12 +3027,18 @@ export {
2700
3027
  ErrorBoundary,
2701
3028
  FORM_SHORTCUTS,
2702
3029
  GLOBAL_SHORTCUTS,
3030
+ GUARDED_ACTION_FAILURE,
2703
3031
  INBOX_SHORTCUTS,
2704
3032
  KeyboardShortcutsPanel,
3033
+ PICKER_SEARCH_FAILURE,
2705
3034
  RENDER_ERRORS,
2706
3035
  REPLY_LAYOUT_OPTIONS,
2707
3036
  ReplyPanel,
3037
+ RestoreButton,
2708
3038
  RichTextEditor,
3039
+ ShowOnceSecret,
3040
+ TrashedBanner,
3041
+ UndoNotice,
2709
3042
  cachedFetch,
2710
3043
  canViewInline,
2711
3044
  clearCache,
@@ -2713,6 +3046,7 @@ export {
2713
3046
  formatFileSize,
2714
3047
  formatPhone,
2715
3048
  formatPhoneInput,
3049
+ formatTrashedDate,
2716
3050
  getNextMondayMorning,
2717
3051
  getNextWeekday,
2718
3052
  getQuickScheduleOptions,
@@ -2744,13 +3078,17 @@ export {
2744
3078
  useArrival,
2745
3079
  useAutoSave,
2746
3080
  useContextShortcuts,
3081
+ useCopyToClipboard,
2747
3082
  useFormActionKeepingInput,
3083
+ useGuardedAction,
2748
3084
  useIframeFocusReclaim,
2749
3085
  useKeyboardShortcuts,
3086
+ usePickerSession,
2750
3087
  usePolling,
2751
3088
  usePreferences,
2752
3089
  useSavedNotice,
2753
3090
  useServerSearch,
3091
+ useSignedAnswer,
2754
3092
  useSyncedSelect,
2755
3093
  withErrorBoundary
2756
3094
  };