@classic-homes/theme-react 0.5.1 → 0.6.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.d.mts CHANGED
@@ -69,6 +69,15 @@ interface InputProps extends React$1.InputHTMLAttributes<HTMLInputElement> {
69
69
  * @example aria-describedby="email-error email-hint"
70
70
  */
71
71
  'aria-describedby'?: string;
72
+ /**
73
+ * Saved value to offer a revert to. While the value differs from it, a
74
+ * small revert button shows at the end of the field; the revert goes onto
75
+ * the browser's undo stack, so Ctrl/Cmd+Z brings the edit back. The wrapper
76
+ * fills its container: size the container, not the input.
77
+ */
78
+ revertTo?: string;
79
+ /** Accessible label / tooltip of the revert button (default "Revert to saved") */
80
+ revertLabel?: string;
72
81
  }
73
82
  declare const Input: React$1.ForwardRefExoticComponent<InputProps & React$1.RefAttributes<HTMLInputElement>>;
74
83
 
@@ -1441,4 +1450,35 @@ declare function useClickOutside<T extends HTMLElement>(ref: React$1.RefObject<T
1441
1450
  */
1442
1451
  declare function cn(...inputs: ClassValue[]): string;
1443
1452
 
1444
- export { type ArrowNavigationOrientation, Avatar, AvatarFallback, AvatarImage, type AvatarImageProps, type AvatarProps, Badge, type BadgeProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, type CardTitleProps, DataPanel, DataPanelContent, type DataPanelContentProps, DataPanelFooter, type DataPanelFooterProps, DataPanelHeader, type DataPanelHeaderProps, type DataPanelProps, DataPanelTab, type DataPanelTabProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, type DialogSize, DialogTitle, DialogTrigger, Input, type InputProps, InsertPalette, type InsertPaletteGroup, type InsertPaletteItem, type InsertPaletteProps, IssuesButton, type IssuesButtonProps, Label, LiveRegion, type LiveRegionProps, LoadingLogo, type LoadingLogoProps, LoadingOverlay, type LoadingOverlayProps, LoadingPage, type LoadingPageProps, LoadingSection, type LoadingSectionProps, PageHeader, type PageHeaderProps, PasswordInput, type PasswordInputProps, ProgressBar, type ProgressBarProps, type SaveState, SaveStatus, type SaveStatusProps, Separator, type SeparatorProps, Sheet, type SheetProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, type SortableHandleProps, type SortableItemContext, SortableList, type SortableListProps, Spinner, type SpinnerProps, Studio, StudioBar, type StudioBarProps, StudioCanvas, StudioCanvasItem, type StudioCanvasItemProps, type StudioCanvasProps, type StudioContextValue, StudioInspector, type StudioInspectorProps, StudioInspectorSection, type StudioInspectorSectionProps, type StudioInspectorTab, type StudioIssue, type StudioLayout, type StudioMenuItem, type StudioMode, StudioOutline, type StudioOutlineEntry, type StudioOutlineProps, StudioPage, type StudioPageProps, type StudioProps, Switch, type SwitchProps, type UseAnnounceOptions, type UseAnnounceReturn, type UseArrowNavigationOptions, type UseClickOutsideOptions, type UseDataPanelOptions, type UseEscapeKeyOptions, type UseFocusRefOptions, type UseFocusTrapOptions, type UseRovingTabindexOptions, badgeVariants, buttonVariants, cn, labelVariants, pageHeaderActionsVariants, pageHeaderContainerVariants, pageHeaderSubtitleVariants, pageHeaderTitleVariants, progressBarVariants, skeletonVariants, spinnerVariants, useAnnounce, useArrowNavigation, useClickOutside, useDataPanel, useEscapeKey, useFocusRef, useFocusTrap, useReducedMotion, useRovingTabindex, useStudio };
1453
+ /**
1454
+ * Mirror of packages/svelte/src/lib/utils/undoable-text.ts — keep in sync.
1455
+ *
1456
+ * Write text into a native text field so the change lands on the browser's
1457
+ * own undo stack: Ctrl/Cmd+Z restores what was there before, and
1458
+ * Ctrl/Cmd+Shift+Z (or Ctrl+Y) re-applies it.
1459
+ *
1460
+ * Assigning `el.value` (or changing a bound `value` prop) wipes the native undo
1461
+ * history, so text written for the user (AI drafts, snippet inserts, reverts)
1462
+ * could never be undone. Routing the write through `execCommand('insertText')`
1463
+ * keeps it in the history and fires a real `input` event, so components'
1464
+ * `oninput` / `onValueChange` handlers run exactly as for typing.
1465
+ *
1466
+ * Where the editing pipeline is unavailable (no `execCommand`, a field type it
1467
+ * refuses such as `number` or `date`, or a test DOM) it falls back to
1468
+ * `setRangeText` / `value` plus a synthetic bubbling `input` event: the value
1469
+ * still updates and handlers still run, but the change is not undoable.
1470
+ */
1471
+ type TextField = HTMLInputElement | HTMLTextAreaElement;
1472
+ interface SetTextOptions {
1473
+ /** Start of the range to replace (default 0, i.e. the whole value). */
1474
+ start?: number;
1475
+ /** End of the range to replace (default the end of the value). */
1476
+ end?: number;
1477
+ }
1478
+ /**
1479
+ * Replace `[start, end)` of the field's value with `text` (the whole value by
1480
+ * default). Returns `true` when the change went onto the native undo stack.
1481
+ */
1482
+ declare function setTextUndoable(el: TextField, text: string, options?: SetTextOptions): boolean;
1483
+
1484
+ export { type ArrowNavigationOrientation, Avatar, AvatarFallback, AvatarImage, type AvatarImageProps, type AvatarProps, Badge, type BadgeProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, type CardTitleProps, DataPanel, DataPanelContent, type DataPanelContentProps, DataPanelFooter, type DataPanelFooterProps, DataPanelHeader, type DataPanelHeaderProps, type DataPanelProps, DataPanelTab, type DataPanelTabProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, type DialogSize, DialogTitle, DialogTrigger, Input, type InputProps, InsertPalette, type InsertPaletteGroup, type InsertPaletteItem, type InsertPaletteProps, IssuesButton, type IssuesButtonProps, Label, LiveRegion, type LiveRegionProps, LoadingLogo, type LoadingLogoProps, LoadingOverlay, type LoadingOverlayProps, LoadingPage, type LoadingPageProps, LoadingSection, type LoadingSectionProps, PageHeader, type PageHeaderProps, PasswordInput, type PasswordInputProps, ProgressBar, type ProgressBarProps, type SaveState, SaveStatus, type SaveStatusProps, Separator, type SeparatorProps, type SetTextOptions, Sheet, type SheetProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, type SortableHandleProps, type SortableItemContext, SortableList, type SortableListProps, Spinner, type SpinnerProps, Studio, StudioBar, type StudioBarProps, StudioCanvas, StudioCanvasItem, type StudioCanvasItemProps, type StudioCanvasProps, type StudioContextValue, StudioInspector, type StudioInspectorProps, StudioInspectorSection, type StudioInspectorSectionProps, type StudioInspectorTab, type StudioIssue, type StudioLayout, type StudioMenuItem, type StudioMode, StudioOutline, type StudioOutlineEntry, type StudioOutlineProps, StudioPage, type StudioPageProps, type StudioProps, Switch, type SwitchProps, type TextField, type UseAnnounceOptions, type UseAnnounceReturn, type UseArrowNavigationOptions, type UseClickOutsideOptions, type UseDataPanelOptions, type UseEscapeKeyOptions, type UseFocusRefOptions, type UseFocusTrapOptions, type UseRovingTabindexOptions, badgeVariants, buttonVariants, cn, labelVariants, pageHeaderActionsVariants, pageHeaderContainerVariants, pageHeaderSubtitleVariants, pageHeaderTitleVariants, progressBarVariants, setTextUndoable, skeletonVariants, spinnerVariants, useAnnounce, useArrowNavigation, useClickOutside, useDataPanel, useEscapeKey, useFocusRef, useFocusTrap, useReducedMotion, useRovingTabindex, useStudio };
package/dist/index.d.ts CHANGED
@@ -69,6 +69,15 @@ interface InputProps extends React$1.InputHTMLAttributes<HTMLInputElement> {
69
69
  * @example aria-describedby="email-error email-hint"
70
70
  */
71
71
  'aria-describedby'?: string;
72
+ /**
73
+ * Saved value to offer a revert to. While the value differs from it, a
74
+ * small revert button shows at the end of the field; the revert goes onto
75
+ * the browser's undo stack, so Ctrl/Cmd+Z brings the edit back. The wrapper
76
+ * fills its container: size the container, not the input.
77
+ */
78
+ revertTo?: string;
79
+ /** Accessible label / tooltip of the revert button (default "Revert to saved") */
80
+ revertLabel?: string;
72
81
  }
73
82
  declare const Input: React$1.ForwardRefExoticComponent<InputProps & React$1.RefAttributes<HTMLInputElement>>;
74
83
 
@@ -1441,4 +1450,35 @@ declare function useClickOutside<T extends HTMLElement>(ref: React$1.RefObject<T
1441
1450
  */
1442
1451
  declare function cn(...inputs: ClassValue[]): string;
1443
1452
 
1444
- export { type ArrowNavigationOrientation, Avatar, AvatarFallback, AvatarImage, type AvatarImageProps, type AvatarProps, Badge, type BadgeProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, type CardTitleProps, DataPanel, DataPanelContent, type DataPanelContentProps, DataPanelFooter, type DataPanelFooterProps, DataPanelHeader, type DataPanelHeaderProps, type DataPanelProps, DataPanelTab, type DataPanelTabProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, type DialogSize, DialogTitle, DialogTrigger, Input, type InputProps, InsertPalette, type InsertPaletteGroup, type InsertPaletteItem, type InsertPaletteProps, IssuesButton, type IssuesButtonProps, Label, LiveRegion, type LiveRegionProps, LoadingLogo, type LoadingLogoProps, LoadingOverlay, type LoadingOverlayProps, LoadingPage, type LoadingPageProps, LoadingSection, type LoadingSectionProps, PageHeader, type PageHeaderProps, PasswordInput, type PasswordInputProps, ProgressBar, type ProgressBarProps, type SaveState, SaveStatus, type SaveStatusProps, Separator, type SeparatorProps, Sheet, type SheetProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, type SortableHandleProps, type SortableItemContext, SortableList, type SortableListProps, Spinner, type SpinnerProps, Studio, StudioBar, type StudioBarProps, StudioCanvas, StudioCanvasItem, type StudioCanvasItemProps, type StudioCanvasProps, type StudioContextValue, StudioInspector, type StudioInspectorProps, StudioInspectorSection, type StudioInspectorSectionProps, type StudioInspectorTab, type StudioIssue, type StudioLayout, type StudioMenuItem, type StudioMode, StudioOutline, type StudioOutlineEntry, type StudioOutlineProps, StudioPage, type StudioPageProps, type StudioProps, Switch, type SwitchProps, type UseAnnounceOptions, type UseAnnounceReturn, type UseArrowNavigationOptions, type UseClickOutsideOptions, type UseDataPanelOptions, type UseEscapeKeyOptions, type UseFocusRefOptions, type UseFocusTrapOptions, type UseRovingTabindexOptions, badgeVariants, buttonVariants, cn, labelVariants, pageHeaderActionsVariants, pageHeaderContainerVariants, pageHeaderSubtitleVariants, pageHeaderTitleVariants, progressBarVariants, skeletonVariants, spinnerVariants, useAnnounce, useArrowNavigation, useClickOutside, useDataPanel, useEscapeKey, useFocusRef, useFocusTrap, useReducedMotion, useRovingTabindex, useStudio };
1453
+ /**
1454
+ * Mirror of packages/svelte/src/lib/utils/undoable-text.ts — keep in sync.
1455
+ *
1456
+ * Write text into a native text field so the change lands on the browser's
1457
+ * own undo stack: Ctrl/Cmd+Z restores what was there before, and
1458
+ * Ctrl/Cmd+Shift+Z (or Ctrl+Y) re-applies it.
1459
+ *
1460
+ * Assigning `el.value` (or changing a bound `value` prop) wipes the native undo
1461
+ * history, so text written for the user (AI drafts, snippet inserts, reverts)
1462
+ * could never be undone. Routing the write through `execCommand('insertText')`
1463
+ * keeps it in the history and fires a real `input` event, so components'
1464
+ * `oninput` / `onValueChange` handlers run exactly as for typing.
1465
+ *
1466
+ * Where the editing pipeline is unavailable (no `execCommand`, a field type it
1467
+ * refuses such as `number` or `date`, or a test DOM) it falls back to
1468
+ * `setRangeText` / `value` plus a synthetic bubbling `input` event: the value
1469
+ * still updates and handlers still run, but the change is not undoable.
1470
+ */
1471
+ type TextField = HTMLInputElement | HTMLTextAreaElement;
1472
+ interface SetTextOptions {
1473
+ /** Start of the range to replace (default 0, i.e. the whole value). */
1474
+ start?: number;
1475
+ /** End of the range to replace (default the end of the value). */
1476
+ end?: number;
1477
+ }
1478
+ /**
1479
+ * Replace `[start, end)` of the field's value with `text` (the whole value by
1480
+ * default). Returns `true` when the change went onto the native undo stack.
1481
+ */
1482
+ declare function setTextUndoable(el: TextField, text: string, options?: SetTextOptions): boolean;
1483
+
1484
+ export { type ArrowNavigationOrientation, Avatar, AvatarFallback, AvatarImage, type AvatarImageProps, type AvatarProps, Badge, type BadgeProps, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, type CardTitleProps, DataPanel, DataPanelContent, type DataPanelContentProps, DataPanelFooter, type DataPanelFooterProps, DataPanelHeader, type DataPanelHeaderProps, type DataPanelProps, DataPanelTab, type DataPanelTabProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, type DialogSize, DialogTitle, DialogTrigger, Input, type InputProps, InsertPalette, type InsertPaletteGroup, type InsertPaletteItem, type InsertPaletteProps, IssuesButton, type IssuesButtonProps, Label, LiveRegion, type LiveRegionProps, LoadingLogo, type LoadingLogoProps, LoadingOverlay, type LoadingOverlayProps, LoadingPage, type LoadingPageProps, LoadingSection, type LoadingSectionProps, PageHeader, type PageHeaderProps, PasswordInput, type PasswordInputProps, ProgressBar, type ProgressBarProps, type SaveState, SaveStatus, type SaveStatusProps, Separator, type SeparatorProps, type SetTextOptions, Sheet, type SheetProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, type SortableHandleProps, type SortableItemContext, SortableList, type SortableListProps, Spinner, type SpinnerProps, Studio, StudioBar, type StudioBarProps, StudioCanvas, StudioCanvasItem, type StudioCanvasItemProps, type StudioCanvasProps, type StudioContextValue, StudioInspector, type StudioInspectorProps, StudioInspectorSection, type StudioInspectorSectionProps, type StudioInspectorTab, type StudioIssue, type StudioLayout, type StudioMenuItem, type StudioMode, StudioOutline, type StudioOutlineEntry, type StudioOutlineProps, StudioPage, type StudioPageProps, type StudioProps, Switch, type SwitchProps, type TextField, type UseAnnounceOptions, type UseAnnounceReturn, type UseArrowNavigationOptions, type UseClickOutsideOptions, type UseDataPanelOptions, type UseEscapeKeyOptions, type UseFocusRefOptions, type UseFocusTrapOptions, type UseRovingTabindexOptions, badgeVariants, buttonVariants, cn, labelVariants, pageHeaderActionsVariants, pageHeaderContainerVariants, pageHeaderSubtitleVariants, pageHeaderTitleVariants, progressBarVariants, setTextUndoable, skeletonVariants, spinnerVariants, useAnnounce, useArrowNavigation, useClickOutside, useDataPanel, useEscapeKey, useFocusRef, useFocusTrap, useReducedMotion, useRovingTabindex, useStudio };
package/dist/index.js CHANGED
@@ -93,6 +93,7 @@ __export(index_exports, {
93
93
  pageHeaderSubtitleVariants: () => pageHeaderSubtitleVariants,
94
94
  pageHeaderTitleVariants: () => pageHeaderTitleVariants,
95
95
  progressBarVariants: () => progressBarVariants,
96
+ setTextUndoable: () => setTextUndoable,
96
97
  skeletonVariants: () => skeletonVariants,
97
98
  spinnerVariants: () => spinnerVariants,
98
99
  useAnnounce: () => useAnnounce,
@@ -224,8 +225,57 @@ function useDevWarning(condition, message, once = false) {
224
225
  }, [condition, message, once]);
225
226
  }
226
227
 
228
+ // src/lib/undoable-text.ts
229
+ var RANGE_TYPES = /* @__PURE__ */ new Set(["text", "search", "url", "tel", "password"]);
230
+ function supportsRange(el) {
231
+ return el instanceof HTMLTextAreaElement || RANGE_TYPES.has(el.type);
232
+ }
233
+ function setNativeValue(el, text) {
234
+ const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement : HTMLInputElement;
235
+ const setter = Object.getOwnPropertyDescriptor(proto.prototype, "value")?.set;
236
+ if (setter) setter.call(el, text);
237
+ else el.value = text;
238
+ }
239
+ function setTextUndoable(el, text, options = {}) {
240
+ const current = el.value;
241
+ const ranged = supportsRange(el);
242
+ const start = ranged ? Math.max(0, Math.min(options.start ?? 0, current.length)) : 0;
243
+ const end = ranged ? Math.max(start, Math.min(options.end ?? current.length, current.length)) : current.length;
244
+ if (current.slice(start, end) === text) return true;
245
+ if (ranged && typeof document !== "undefined" && typeof document.execCommand === "function") {
246
+ if (document.activeElement !== el) el.focus({ preventScroll: true });
247
+ el.setSelectionRange(start, end);
248
+ let applied = false;
249
+ try {
250
+ applied = text === "" ? document.execCommand("delete", false) : document.execCommand("insertText", false, text);
251
+ } catch {
252
+ applied = false;
253
+ }
254
+ if (applied && el.value !== current) return true;
255
+ }
256
+ if (ranged) el.setRangeText(text, start, end, "end");
257
+ else setNativeValue(el, text);
258
+ el.dispatchEvent(new Event("input", { bubbles: true }));
259
+ return false;
260
+ }
261
+
227
262
  // src/components/Input.tsx
228
263
  var import_jsx_runtime3 = require("react/jsx-runtime");
264
+ var UndoIcon = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
265
+ "svg",
266
+ {
267
+ width: 14,
268
+ height: 14,
269
+ viewBox: "0 0 24 24",
270
+ fill: "none",
271
+ stroke: "currentColor",
272
+ strokeWidth: 2,
273
+ strokeLinecap: "round",
274
+ strokeLinejoin: "round",
275
+ "aria-hidden": "true",
276
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 7v6h6M3 13a9 9 0 1 0 2.64-6.36L3 9" })
277
+ }
278
+ );
229
279
  var Input = React4.forwardRef(
230
280
  ({
231
281
  className,
@@ -233,13 +283,29 @@ var Input = React4.forwardRef(
233
283
  "aria-invalid": ariaInvalid,
234
284
  required,
235
285
  "aria-describedby": ariaDescribedBy,
286
+ revertTo,
287
+ revertLabel = "Revert to saved",
236
288
  ...props
237
289
  }, ref) => {
290
+ const innerRef = React4.useRef(null);
291
+ const setRefs = React4.useCallback(
292
+ (el) => {
293
+ innerRef.current = el;
294
+ if (typeof ref === "function") ref(el);
295
+ else if (ref) ref.current = el;
296
+ },
297
+ [ref]
298
+ );
299
+ const [liveValue, setLiveValue] = React4.useState(
300
+ () => String(props.value ?? props.defaultValue ?? "")
301
+ );
302
+ const shown = props.value !== void 0 ? String(props.value) : liveValue;
303
+ const canRevert = revertTo !== void 0 && !props.disabled && !props.readOnly && shown !== revertTo;
238
304
  useDevWarning(
239
305
  !props["aria-label"] && !props["aria-labelledby"] && !props.id,
240
306
  "Input: Missing accessible label. Provide aria-label, aria-labelledby, or associate with a Label using id/htmlFor for WCAG compliance."
241
307
  );
242
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
308
+ const input = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
243
309
  "input",
244
310
  {
245
311
  type,
@@ -250,12 +316,34 @@ var Input = React4.forwardRef(
250
316
  className: cn(
251
317
  "flex h-10 w-full rounded-md border border-input bg-background text-foreground px-3 py-2 text-sm max-sm:text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
252
318
  ariaInvalid === true || ariaInvalid === "true" ? "border-destructive focus-visible:ring-destructive" : "",
319
+ revertTo !== void 0 && "pr-9",
253
320
  className
254
321
  ),
255
- ref,
256
- ...props
322
+ ref: setRefs,
323
+ ...props,
324
+ onChange: (e) => {
325
+ setLiveValue(e.currentTarget.value);
326
+ props.onChange?.(e);
327
+ }
257
328
  }
258
329
  );
330
+ if (revertTo === void 0) return input;
331
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "relative w-full", children: [
332
+ input,
333
+ canRevert && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
334
+ "button",
335
+ {
336
+ type: "button",
337
+ className: "absolute right-1.5 top-1/2 inline-flex h-7 w-7 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
338
+ "aria-label": revertLabel,
339
+ title: revertLabel,
340
+ onClick: () => {
341
+ if (innerRef.current) setTextUndoable(innerRef.current, revertTo);
342
+ },
343
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UndoIcon, {})
344
+ }
345
+ )
346
+ ] });
259
347
  }
260
348
  );
261
349
  Input.displayName = "Input";
@@ -2393,15 +2481,18 @@ var FOCUSABLE_SELECTOR = [
2393
2481
  "iframe",
2394
2482
  "object",
2395
2483
  "embed",
2396
- "[contenteditable]",
2484
+ '[contenteditable]:not([contenteditable="false"])',
2397
2485
  '[tabindex]:not([tabindex="-1"])'
2398
2486
  ].join(",");
2399
2487
  function getFocusableElements(container) {
2400
2488
  const elements = container.querySelectorAll(FOCUSABLE_SELECTOR);
2401
2489
  return Array.from(elements).filter(
2402
- (el) => el.offsetParent !== null && getComputedStyle(el).visibility !== "hidden"
2490
+ (el) => el.tabIndex >= 0 && !el.matches(":disabled") && !el.closest("[inert],[hidden]") && el.offsetParent !== null && getComputedStyle(el).visibility !== "hidden"
2403
2491
  );
2404
2492
  }
2493
+ function precedes(a, b) {
2494
+ return Boolean(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING);
2495
+ }
2405
2496
  function useFocusTrap(options = {}) {
2406
2497
  const { active = true, returnFocusTo, initialFocus, preventScroll = false } = options;
2407
2498
  const containerRef = (0, import_react.useRef)(null);
@@ -2411,17 +2502,28 @@ function useFocusTrap(options = {}) {
2411
2502
  if (!active || event.key !== "Tab") return;
2412
2503
  const container = containerRef.current;
2413
2504
  if (!container) return;
2505
+ const current = document.activeElement;
2506
+ if (!current || !container.contains(current)) return;
2414
2507
  const focusableElements = getFocusableElements(container);
2415
- if (focusableElements.length === 0) return;
2508
+ if (focusableElements.length === 0) {
2509
+ event.preventDefault();
2510
+ container.focus({ preventScroll });
2511
+ return;
2512
+ }
2416
2513
  const firstElement = focusableElements[0];
2417
2514
  const lastElement = focusableElements[focusableElements.length - 1];
2515
+ if (current === container) {
2516
+ event.preventDefault();
2517
+ (event.shiftKey ? lastElement : firstElement).focus({ preventScroll });
2518
+ return;
2519
+ }
2418
2520
  if (event.shiftKey) {
2419
- if (document.activeElement === firstElement) {
2521
+ if (current === firstElement || precedes(current, firstElement)) {
2420
2522
  event.preventDefault();
2421
2523
  lastElement.focus({ preventScroll });
2422
2524
  }
2423
2525
  } else {
2424
- if (document.activeElement === lastElement) {
2526
+ if (current === lastElement || precedes(lastElement, current)) {
2425
2527
  event.preventDefault();
2426
2528
  firstElement.focus({ preventScroll });
2427
2529
  }
@@ -2434,24 +2536,30 @@ function useFocusTrap(options = {}) {
2434
2536
  const container = containerRef.current;
2435
2537
  if (!container) return;
2436
2538
  previousActiveElementRef.current = document.activeElement;
2539
+ let addedTabIndex = false;
2437
2540
  const focusableElements = getFocusableElements(container);
2438
- let focusFrame = 0;
2439
- if (focusableElements.length > 0) {
2440
- let elementToFocus = null;
2441
- if (initialFocus) {
2442
- elementToFocus = container.querySelector(initialFocus);
2443
- }
2444
- if (!elementToFocus) {
2445
- elementToFocus = focusableElements[0];
2541
+ let elementToFocus = null;
2542
+ if (initialFocus) {
2543
+ elementToFocus = container.querySelector(initialFocus);
2544
+ }
2545
+ if (!elementToFocus) {
2546
+ elementToFocus = focusableElements[0] ?? null;
2547
+ }
2548
+ if (!elementToFocus) {
2549
+ if (!container.hasAttribute("tabindex")) {
2550
+ container.setAttribute("tabindex", "-1");
2551
+ addedTabIndex = true;
2446
2552
  }
2447
- focusFrame = requestAnimationFrame(() => {
2448
- elementToFocus?.focus({ preventScroll });
2449
- });
2553
+ elementToFocus = container;
2450
2554
  }
2555
+ const focusFrame = requestAnimationFrame(() => {
2556
+ elementToFocus?.focus({ preventScroll });
2557
+ });
2451
2558
  document.addEventListener("keydown", handleKeyDown);
2452
2559
  return () => {
2453
2560
  cancelAnimationFrame(focusFrame);
2454
2561
  document.removeEventListener("keydown", handleKeyDown);
2562
+ if (addedTabIndex) container.removeAttribute("tabindex");
2455
2563
  const elementToReturn = returnFocusTo ?? previousActiveElementRef.current;
2456
2564
  if (elementToReturn && typeof elementToReturn.focus === "function") {
2457
2565
  elementToReturn.focus({ preventScroll });
@@ -5293,6 +5401,7 @@ function useClickOutside(ref, callback, options) {
5293
5401
  pageHeaderSubtitleVariants,
5294
5402
  pageHeaderTitleVariants,
5295
5403
  progressBarVariants,
5404
+ setTextUndoable,
5296
5405
  skeletonVariants,
5297
5406
  spinnerVariants,
5298
5407
  useAnnounce,