@classic-homes/theme-react 0.1.54 → 0.1.56
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.js +230 -213
- package/dist/index.mjs +242 -225
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -654,8 +654,116 @@ var PageHeader = React12.forwardRef(
|
|
|
654
654
|
PageHeader.displayName = "PageHeader";
|
|
655
655
|
|
|
656
656
|
// src/components/DataPanel.tsx
|
|
657
|
-
import * as
|
|
657
|
+
import * as React14 from "react";
|
|
658
658
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
659
|
+
|
|
660
|
+
// src/hooks/useFocusTrap.ts
|
|
661
|
+
import { useEffect as useEffect2, useRef as useRef2, useCallback as useCallback2 } from "react";
|
|
662
|
+
var FOCUSABLE_SELECTOR = [
|
|
663
|
+
"a[href]",
|
|
664
|
+
"area[href]",
|
|
665
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
666
|
+
"select:not([disabled])",
|
|
667
|
+
"textarea:not([disabled])",
|
|
668
|
+
"button:not([disabled])",
|
|
669
|
+
"iframe",
|
|
670
|
+
"object",
|
|
671
|
+
"embed",
|
|
672
|
+
"[contenteditable]",
|
|
673
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
674
|
+
].join(",");
|
|
675
|
+
function getFocusableElements(container) {
|
|
676
|
+
const elements = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
677
|
+
return Array.from(elements).filter(
|
|
678
|
+
(el) => el.offsetParent !== null && getComputedStyle(el).visibility !== "hidden"
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
function useFocusTrap(options = {}) {
|
|
682
|
+
const { active = true, returnFocusTo, initialFocus, preventScroll = false } = options;
|
|
683
|
+
const containerRef = useRef2(null);
|
|
684
|
+
const previousActiveElementRef = useRef2(null);
|
|
685
|
+
const handleKeyDown = useCallback2(
|
|
686
|
+
(event) => {
|
|
687
|
+
if (!active || event.key !== "Tab") return;
|
|
688
|
+
const container = containerRef.current;
|
|
689
|
+
if (!container) return;
|
|
690
|
+
const focusableElements = getFocusableElements(container);
|
|
691
|
+
if (focusableElements.length === 0) return;
|
|
692
|
+
const firstElement = focusableElements[0];
|
|
693
|
+
const lastElement = focusableElements[focusableElements.length - 1];
|
|
694
|
+
if (event.shiftKey) {
|
|
695
|
+
if (document.activeElement === firstElement) {
|
|
696
|
+
event.preventDefault();
|
|
697
|
+
lastElement.focus({ preventScroll });
|
|
698
|
+
}
|
|
699
|
+
} else {
|
|
700
|
+
if (document.activeElement === lastElement) {
|
|
701
|
+
event.preventDefault();
|
|
702
|
+
firstElement.focus({ preventScroll });
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
[active, preventScroll]
|
|
707
|
+
);
|
|
708
|
+
useEffect2(() => {
|
|
709
|
+
if (!active) return;
|
|
710
|
+
const container = containerRef.current;
|
|
711
|
+
if (!container) return;
|
|
712
|
+
previousActiveElementRef.current = document.activeElement;
|
|
713
|
+
const focusableElements = getFocusableElements(container);
|
|
714
|
+
if (focusableElements.length > 0) {
|
|
715
|
+
let elementToFocus = null;
|
|
716
|
+
if (initialFocus) {
|
|
717
|
+
elementToFocus = container.querySelector(initialFocus);
|
|
718
|
+
}
|
|
719
|
+
if (!elementToFocus) {
|
|
720
|
+
elementToFocus = focusableElements[0];
|
|
721
|
+
}
|
|
722
|
+
requestAnimationFrame(() => {
|
|
723
|
+
elementToFocus?.focus({ preventScroll });
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
727
|
+
return () => {
|
|
728
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
729
|
+
const elementToReturn = returnFocusTo ?? previousActiveElementRef.current;
|
|
730
|
+
if (elementToReturn && typeof elementToReturn.focus === "function") {
|
|
731
|
+
elementToReturn.focus({ preventScroll });
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
}, [active, initialFocus, returnFocusTo, handleKeyDown, preventScroll]);
|
|
735
|
+
return containerRef;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// src/hooks/useEscapeKey.ts
|
|
739
|
+
import * as React13 from "react";
|
|
740
|
+
function useEscapeKey(callback, options) {
|
|
741
|
+
const { enabled = true, preventDefault = true, stopPropagation = false } = options ?? {};
|
|
742
|
+
const callbackRef = React13.useRef(callback);
|
|
743
|
+
React13.useEffect(() => {
|
|
744
|
+
callbackRef.current = callback;
|
|
745
|
+
}, [callback]);
|
|
746
|
+
React13.useEffect(() => {
|
|
747
|
+
if (!enabled) return;
|
|
748
|
+
const handleKeyDown = (event) => {
|
|
749
|
+
if (event.key === "Escape") {
|
|
750
|
+
if (preventDefault) {
|
|
751
|
+
event.preventDefault();
|
|
752
|
+
}
|
|
753
|
+
if (stopPropagation) {
|
|
754
|
+
event.stopPropagation();
|
|
755
|
+
}
|
|
756
|
+
callbackRef.current(event);
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
760
|
+
return () => {
|
|
761
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
762
|
+
};
|
|
763
|
+
}, [enabled, preventDefault, stopPropagation]);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// src/components/DataPanel.tsx
|
|
659
767
|
import {
|
|
660
768
|
DEFAULT_PANEL_STATE,
|
|
661
769
|
DEFAULT_CONSTRAINTS,
|
|
@@ -695,28 +803,28 @@ function useDataPanel(options = {}) {
|
|
|
695
803
|
constraints = {}
|
|
696
804
|
} = options;
|
|
697
805
|
const resolvedConstraints = { ...DEFAULT_CONSTRAINTS, ...constraints };
|
|
698
|
-
const [persistedState] =
|
|
806
|
+
const [persistedState] = React14.useState(() => {
|
|
699
807
|
if (persistKey && typeof window !== "undefined") {
|
|
700
808
|
return loadPanelState(persistKey);
|
|
701
809
|
}
|
|
702
810
|
return null;
|
|
703
811
|
});
|
|
704
|
-
const [mode, setMode] =
|
|
705
|
-
const [edge, setEdge] =
|
|
706
|
-
const [isExpanded, setIsExpanded] =
|
|
812
|
+
const [mode, setMode] = React14.useState(persistedState?.mode ?? initialMode);
|
|
813
|
+
const [edge, setEdge] = React14.useState(persistedState?.edge ?? initialEdge);
|
|
814
|
+
const [isExpanded, setIsExpanded] = React14.useState(
|
|
707
815
|
persistedState?.isExpanded ?? initialExpanded
|
|
708
816
|
);
|
|
709
|
-
const [detachedPosition, setDetachedPosition] =
|
|
817
|
+
const [detachedPosition, setDetachedPosition] = React14.useState(
|
|
710
818
|
persistedState?.detachedPosition ?? DEFAULT_PANEL_STATE.detachedPosition
|
|
711
819
|
);
|
|
712
|
-
const [detachedSize, setDetachedSize] =
|
|
820
|
+
const [detachedSize, setDetachedSize] = React14.useState(
|
|
713
821
|
persistedState?.detachedSize ?? DEFAULT_PANEL_STATE.detachedSize
|
|
714
822
|
);
|
|
715
|
-
const [pinnedSize, setPinnedSize] =
|
|
823
|
+
const [pinnedSize, setPinnedSize] = React14.useState(
|
|
716
824
|
persistedState?.pinnedSize ?? DEFAULT_PANEL_STATE.pinnedSize
|
|
717
825
|
);
|
|
718
|
-
const saveTimeoutRef =
|
|
719
|
-
const debouncedSave =
|
|
826
|
+
const saveTimeoutRef = React14.useRef(null);
|
|
827
|
+
const debouncedSave = React14.useCallback(() => {
|
|
720
828
|
if (!persistKey) return;
|
|
721
829
|
if (saveTimeoutRef.current) {
|
|
722
830
|
clearTimeout(saveTimeoutRef.current);
|
|
@@ -734,7 +842,7 @@ function useDataPanel(options = {}) {
|
|
|
734
842
|
});
|
|
735
843
|
}, 300);
|
|
736
844
|
}, [persistKey, mode, edge, isExpanded, detachedPosition, detachedSize, pinnedSize]);
|
|
737
|
-
const handleSetMode =
|
|
845
|
+
const handleSetMode = React14.useCallback(
|
|
738
846
|
(newMode) => {
|
|
739
847
|
setMode(newMode);
|
|
740
848
|
if (newMode === "detached" && typeof window !== "undefined" && detachedPosition.x === DEFAULT_PANEL_STATE.detachedPosition.x && detachedPosition.y === DEFAULT_PANEL_STATE.detachedPosition.y) {
|
|
@@ -745,7 +853,7 @@ function useDataPanel(options = {}) {
|
|
|
745
853
|
},
|
|
746
854
|
[detachedPosition, detachedSize]
|
|
747
855
|
);
|
|
748
|
-
const handleSetDetachedPosition =
|
|
856
|
+
const handleSetDetachedPosition = React14.useCallback(
|
|
749
857
|
(position) => {
|
|
750
858
|
if (typeof window === "undefined") {
|
|
751
859
|
setDetachedPosition(position);
|
|
@@ -757,13 +865,13 @@ function useDataPanel(options = {}) {
|
|
|
757
865
|
},
|
|
758
866
|
[detachedSize]
|
|
759
867
|
);
|
|
760
|
-
const handleSetDetachedSize =
|
|
868
|
+
const handleSetDetachedSize = React14.useCallback(
|
|
761
869
|
(size) => {
|
|
762
870
|
setDetachedSize(constrainSize(size, resolvedConstraints));
|
|
763
871
|
},
|
|
764
872
|
[resolvedConstraints]
|
|
765
873
|
);
|
|
766
|
-
const handleSetPinnedSize =
|
|
874
|
+
const handleSetPinnedSize = React14.useCallback(
|
|
767
875
|
(size) => {
|
|
768
876
|
if (typeof window === "undefined") {
|
|
769
877
|
setPinnedSize(size);
|
|
@@ -777,7 +885,7 @@ function useDataPanel(options = {}) {
|
|
|
777
885
|
},
|
|
778
886
|
[edge, resolvedConstraints]
|
|
779
887
|
);
|
|
780
|
-
|
|
888
|
+
React14.useEffect(() => {
|
|
781
889
|
debouncedSave();
|
|
782
890
|
}, [debouncedSave]);
|
|
783
891
|
return {
|
|
@@ -853,7 +961,7 @@ var edgeLabels = {
|
|
|
853
961
|
top: "Pin to top",
|
|
854
962
|
bottom: "Pin to bottom"
|
|
855
963
|
};
|
|
856
|
-
var DataPanelHeader =
|
|
964
|
+
var DataPanelHeader = React14.forwardRef(
|
|
857
965
|
({
|
|
858
966
|
title,
|
|
859
967
|
subtitle,
|
|
@@ -966,7 +1074,7 @@ var DataPanelHeader = React13.forwardRef(
|
|
|
966
1074
|
}
|
|
967
1075
|
);
|
|
968
1076
|
DataPanelHeader.displayName = "DataPanelHeader";
|
|
969
|
-
var DataPanelContent =
|
|
1077
|
+
var DataPanelContent = React14.forwardRef(
|
|
970
1078
|
({ children, className, "aria-label": ariaLabel = "Panel content" }, ref) => {
|
|
971
1079
|
return /* @__PURE__ */ jsx12(
|
|
972
1080
|
"div",
|
|
@@ -981,7 +1089,7 @@ var DataPanelContent = React13.forwardRef(
|
|
|
981
1089
|
}
|
|
982
1090
|
);
|
|
983
1091
|
DataPanelContent.displayName = "DataPanelContent";
|
|
984
|
-
var DataPanelFooter =
|
|
1092
|
+
var DataPanelFooter = React14.forwardRef(
|
|
985
1093
|
({ actions = [], footerContent, footerActions, className }, ref) => {
|
|
986
1094
|
if (!footerContent && actions.length === 0 && !footerActions) {
|
|
987
1095
|
return null;
|
|
@@ -1017,7 +1125,7 @@ var DataPanelFooter = React13.forwardRef(
|
|
|
1017
1125
|
}
|
|
1018
1126
|
);
|
|
1019
1127
|
DataPanelFooter.displayName = "DataPanelFooter";
|
|
1020
|
-
var DataPanelTab =
|
|
1128
|
+
var DataPanelTab = React14.forwardRef(
|
|
1021
1129
|
({ title = "Panel", edge, onClick, className }, ref) => {
|
|
1022
1130
|
const positionClasses = {
|
|
1023
1131
|
left: "left-0 top-1/2 -translate-y-1/2 rounded-r-md border-l-0",
|
|
@@ -1066,7 +1174,7 @@ function ResizeHandles({
|
|
|
1066
1174
|
onPinnedSizeChange,
|
|
1067
1175
|
constraints
|
|
1068
1176
|
}) {
|
|
1069
|
-
const handleDetachedKeyDown =
|
|
1177
|
+
const handleDetachedKeyDown = React14.useCallback(
|
|
1070
1178
|
(e, handle) => {
|
|
1071
1179
|
const step = e.shiftKey ? KEYBOARD_RESIZE_STEP_LARGE : KEYBOARD_RESIZE_STEP;
|
|
1072
1180
|
let newSize = { ...detachedSize };
|
|
@@ -1116,7 +1224,7 @@ function ResizeHandles({
|
|
|
1116
1224
|
},
|
|
1117
1225
|
[detachedSize, constraints, onSizeChange]
|
|
1118
1226
|
);
|
|
1119
|
-
const handlePinnedKeyDown =
|
|
1227
|
+
const handlePinnedKeyDown = React14.useCallback(
|
|
1120
1228
|
(e) => {
|
|
1121
1229
|
const step = e.shiftKey ? KEYBOARD_RESIZE_STEP_LARGE : KEYBOARD_RESIZE_STEP;
|
|
1122
1230
|
let newSize = pinnedSize;
|
|
@@ -1233,7 +1341,7 @@ function ResizeHandles({
|
|
|
1233
1341
|
}
|
|
1234
1342
|
);
|
|
1235
1343
|
}
|
|
1236
|
-
var DataPanel =
|
|
1344
|
+
var DataPanel = React14.forwardRef(
|
|
1237
1345
|
({
|
|
1238
1346
|
open: controlledOpen,
|
|
1239
1347
|
onOpenChange,
|
|
@@ -1262,33 +1370,33 @@ var DataPanel = React13.forwardRef(
|
|
|
1262
1370
|
className
|
|
1263
1371
|
}, ref) => {
|
|
1264
1372
|
const resolvedConstraints = { ...DEFAULT_CONSTRAINTS, ...constraints };
|
|
1265
|
-
const panelId =
|
|
1373
|
+
const panelId = React14.useId();
|
|
1266
1374
|
const titleId = `${panelId}-title`;
|
|
1267
|
-
const [internalOpen, setInternalOpen] =
|
|
1268
|
-
const [internalMode, setInternalMode] =
|
|
1269
|
-
const [internalEdge, setInternalEdge] =
|
|
1270
|
-
const [internalExpanded, setInternalExpanded] =
|
|
1375
|
+
const [internalOpen, setInternalOpen] = React14.useState(true);
|
|
1376
|
+
const [internalMode, setInternalMode] = React14.useState(DEFAULT_PANEL_STATE.mode);
|
|
1377
|
+
const [internalEdge, setInternalEdge] = React14.useState(DEFAULT_PANEL_STATE.edge);
|
|
1378
|
+
const [internalExpanded, setInternalExpanded] = React14.useState(
|
|
1271
1379
|
DEFAULT_PANEL_STATE.isExpanded
|
|
1272
1380
|
);
|
|
1273
|
-
const [detachedPosition, setDetachedPosition] =
|
|
1381
|
+
const [detachedPosition, setDetachedPosition] = React14.useState(
|
|
1274
1382
|
DEFAULT_PANEL_STATE.detachedPosition
|
|
1275
1383
|
);
|
|
1276
|
-
const [detachedSize, setDetachedSize] =
|
|
1277
|
-
const [pinnedSize, setPinnedSize] =
|
|
1278
|
-
const [isDragging, setIsDragging] =
|
|
1279
|
-
const [isResizing, setIsResizing] =
|
|
1280
|
-
const [snapPreview, setSnapPreview] =
|
|
1281
|
-
const [isPinnedDragging, setIsPinnedDragging] =
|
|
1282
|
-
const [pullOffset, setPullOffset] =
|
|
1283
|
-
const dragStateRef =
|
|
1384
|
+
const [detachedSize, setDetachedSize] = React14.useState(DEFAULT_PANEL_STATE.detachedSize);
|
|
1385
|
+
const [pinnedSize, setPinnedSize] = React14.useState(DEFAULT_PANEL_STATE.pinnedSize);
|
|
1386
|
+
const [isDragging, setIsDragging] = React14.useState(false);
|
|
1387
|
+
const [isResizing, setIsResizing] = React14.useState(false);
|
|
1388
|
+
const [snapPreview, setSnapPreview] = React14.useState(null);
|
|
1389
|
+
const [isPinnedDragging, setIsPinnedDragging] = React14.useState(false);
|
|
1390
|
+
const [pullOffset, setPullOffset] = React14.useState(0);
|
|
1391
|
+
const dragStateRef = React14.useRef({
|
|
1284
1392
|
startPosition: { x: 0, y: 0 },
|
|
1285
1393
|
startPanelPosition: { x: 0, y: 0 }
|
|
1286
1394
|
});
|
|
1287
|
-
const pinnedDragStateRef =
|
|
1395
|
+
const pinnedDragStateRef = React14.useRef({
|
|
1288
1396
|
startPosition: { x: 0, y: 0 },
|
|
1289
1397
|
hasDetached: false
|
|
1290
1398
|
});
|
|
1291
|
-
const resizeStateRef =
|
|
1399
|
+
const resizeStateRef = React14.useRef({
|
|
1292
1400
|
handle: null,
|
|
1293
1401
|
startPosition: { x: 0, y: 0 },
|
|
1294
1402
|
startSize: { width: 0, height: 0 },
|
|
@@ -1298,34 +1406,29 @@ var DataPanel = React13.forwardRef(
|
|
|
1298
1406
|
const mode = controlledMode ?? internalMode;
|
|
1299
1407
|
const edge = controlledEdge ?? internalEdge;
|
|
1300
1408
|
const isExpanded = controlledExpanded ?? internalExpanded;
|
|
1301
|
-
const saveTimeoutRef =
|
|
1302
|
-
const debouncedSave =
|
|
1409
|
+
const saveTimeoutRef = React14.useRef(null);
|
|
1410
|
+
const debouncedSave = React14.useCallback(() => {
|
|
1303
1411
|
if (!persistKey) return;
|
|
1304
1412
|
if (saveTimeoutRef.current) {
|
|
1305
1413
|
clearTimeout(saveTimeoutRef.current);
|
|
1306
1414
|
}
|
|
1307
1415
|
saveTimeoutRef.current = setTimeout(() => {
|
|
1308
1416
|
savePanelState(persistKey, {
|
|
1309
|
-
mode
|
|
1417
|
+
mode,
|
|
1310
1418
|
variant: "full",
|
|
1311
|
-
edge
|
|
1312
|
-
isExpanded
|
|
1419
|
+
edge,
|
|
1420
|
+
isExpanded,
|
|
1313
1421
|
detachedPosition,
|
|
1314
1422
|
detachedSize,
|
|
1315
1423
|
pinnedSize,
|
|
1316
1424
|
cardSnapIndex: 0
|
|
1317
1425
|
});
|
|
1318
1426
|
}, 300);
|
|
1319
|
-
}, [
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
detachedPosition,
|
|
1325
|
-
detachedSize,
|
|
1326
|
-
pinnedSize
|
|
1327
|
-
]);
|
|
1328
|
-
React13.useEffect(() => {
|
|
1427
|
+
}, [persistKey, mode, edge, isExpanded, detachedPosition, detachedSize, pinnedSize]);
|
|
1428
|
+
React14.useEffect(() => {
|
|
1429
|
+
debouncedSave();
|
|
1430
|
+
}, [debouncedSave]);
|
|
1431
|
+
React14.useEffect(() => {
|
|
1329
1432
|
if (!persistKey) return;
|
|
1330
1433
|
const persisted = loadPanelState(persistKey);
|
|
1331
1434
|
if (persisted) {
|
|
@@ -1338,7 +1441,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1338
1441
|
if (persisted.pinnedSize) setPinnedSize(persisted.pinnedSize);
|
|
1339
1442
|
}
|
|
1340
1443
|
}, [persistKey, controlledMode, controlledEdge, controlledExpanded]);
|
|
1341
|
-
|
|
1444
|
+
React14.useEffect(() => {
|
|
1342
1445
|
if (mode === "detached" && detachedPosition.x === DEFAULT_PANEL_STATE.detachedPosition.x && detachedPosition.y === DEFAULT_PANEL_STATE.detachedPosition.y) {
|
|
1343
1446
|
setDetachedPosition(
|
|
1344
1447
|
getInitialDetachedPosition(detachedSize, window.innerWidth, window.innerHeight)
|
|
@@ -1351,26 +1454,39 @@ var DataPanel = React13.forwardRef(
|
|
|
1351
1454
|
}
|
|
1352
1455
|
onOpenChange?.(newOpen);
|
|
1353
1456
|
};
|
|
1457
|
+
const isDetachedDialog = open && mode === "detached";
|
|
1458
|
+
const focusTrapRef = useFocusTrap({ active: isDetachedDialog });
|
|
1459
|
+
useEscapeKey(
|
|
1460
|
+
() => {
|
|
1461
|
+
if (!disableClose) handleOpenChange(false);
|
|
1462
|
+
},
|
|
1463
|
+
{ enabled: isDetachedDialog }
|
|
1464
|
+
);
|
|
1465
|
+
const setPanelRef = (node) => {
|
|
1466
|
+
focusTrapRef.current = node;
|
|
1467
|
+
if (typeof ref === "function") {
|
|
1468
|
+
ref(node);
|
|
1469
|
+
} else if (ref) {
|
|
1470
|
+
ref.current = node;
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1354
1473
|
const handleModeChange = (newMode) => {
|
|
1355
1474
|
if (controlledMode === void 0) {
|
|
1356
1475
|
setInternalMode(newMode);
|
|
1357
1476
|
}
|
|
1358
1477
|
onModeChange?.(newMode);
|
|
1359
|
-
debouncedSave();
|
|
1360
1478
|
};
|
|
1361
1479
|
const handleEdgeChange = (newEdge) => {
|
|
1362
1480
|
if (controlledEdge === void 0) {
|
|
1363
1481
|
setInternalEdge(newEdge);
|
|
1364
1482
|
}
|
|
1365
1483
|
onEdgeChange?.(newEdge);
|
|
1366
|
-
debouncedSave();
|
|
1367
1484
|
};
|
|
1368
1485
|
const handleExpandedChange = (newExpanded) => {
|
|
1369
1486
|
if (controlledExpanded === void 0) {
|
|
1370
1487
|
setInternalExpanded(newExpanded);
|
|
1371
1488
|
}
|
|
1372
1489
|
onExpandedChange?.(newExpanded);
|
|
1373
|
-
debouncedSave();
|
|
1374
1490
|
};
|
|
1375
1491
|
const handleDragStart = (e) => {
|
|
1376
1492
|
if (disableDrag) return;
|
|
@@ -1396,7 +1512,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1396
1512
|
document.body.style.userSelect = "none";
|
|
1397
1513
|
}
|
|
1398
1514
|
};
|
|
1399
|
-
const handleDragMove =
|
|
1515
|
+
const handleDragMove = React14.useCallback(
|
|
1400
1516
|
(e) => {
|
|
1401
1517
|
if (!isDragging) return;
|
|
1402
1518
|
const currentPos = getPointerPosition(e);
|
|
@@ -1423,7 +1539,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1423
1539
|
},
|
|
1424
1540
|
[isDragging, detachedSize, snapThreshold]
|
|
1425
1541
|
);
|
|
1426
|
-
const handleDragEnd =
|
|
1542
|
+
const handleDragEnd = React14.useCallback(() => {
|
|
1427
1543
|
if (!isDragging) return;
|
|
1428
1544
|
setIsDragging(false);
|
|
1429
1545
|
document.body.style.cursor = "";
|
|
@@ -1432,11 +1548,9 @@ var DataPanel = React13.forwardRef(
|
|
|
1432
1548
|
handleModeChange("pinned");
|
|
1433
1549
|
handleEdgeChange(snapPreview);
|
|
1434
1550
|
setSnapPreview(null);
|
|
1435
|
-
} else {
|
|
1436
|
-
debouncedSave();
|
|
1437
1551
|
}
|
|
1438
|
-
}, [isDragging, snapPreview, handleModeChange, handleEdgeChange
|
|
1439
|
-
const handlePinnedDragMove =
|
|
1552
|
+
}, [isDragging, snapPreview, handleModeChange, handleEdgeChange]);
|
|
1553
|
+
const handlePinnedDragMove = React14.useCallback(
|
|
1440
1554
|
(e) => {
|
|
1441
1555
|
if (!isPinnedDragging) return;
|
|
1442
1556
|
const currentPos = getPointerPosition(e);
|
|
@@ -1472,7 +1586,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1472
1586
|
},
|
|
1473
1587
|
[isPinnedDragging, edge, detachThreshold, pinnedSize, detachedSize, handleModeChange]
|
|
1474
1588
|
);
|
|
1475
|
-
const handlePinnedDragEnd =
|
|
1589
|
+
const handlePinnedDragEnd = React14.useCallback(() => {
|
|
1476
1590
|
if (!isPinnedDragging) return;
|
|
1477
1591
|
setIsPinnedDragging(false);
|
|
1478
1592
|
setPullOffset(0);
|
|
@@ -1494,7 +1608,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1494
1608
|
document.body.style.cursor = getResizeCursor(handle);
|
|
1495
1609
|
document.body.style.userSelect = "none";
|
|
1496
1610
|
};
|
|
1497
|
-
const handleResizeMove =
|
|
1611
|
+
const handleResizeMove = React14.useCallback(
|
|
1498
1612
|
(e) => {
|
|
1499
1613
|
if (!isResizing || !resizeStateRef.current.handle) return;
|
|
1500
1614
|
const currentPos = getPointerPosition(e);
|
|
@@ -1532,15 +1646,14 @@ var DataPanel = React13.forwardRef(
|
|
|
1532
1646
|
},
|
|
1533
1647
|
[isResizing, mode, edge, resolvedConstraints]
|
|
1534
1648
|
);
|
|
1535
|
-
const handleResizeEnd =
|
|
1649
|
+
const handleResizeEnd = React14.useCallback(() => {
|
|
1536
1650
|
if (!isResizing) return;
|
|
1537
1651
|
setIsResizing(false);
|
|
1538
1652
|
resizeStateRef.current.handle = null;
|
|
1539
1653
|
document.body.style.cursor = "";
|
|
1540
1654
|
document.body.style.userSelect = "";
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
React13.useEffect(() => {
|
|
1655
|
+
}, [isResizing]);
|
|
1656
|
+
React14.useEffect(() => {
|
|
1544
1657
|
if (isDragging) {
|
|
1545
1658
|
window.addEventListener("pointermove", handleDragMove);
|
|
1546
1659
|
window.addEventListener("pointerup", handleDragEnd);
|
|
@@ -1550,7 +1663,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1550
1663
|
};
|
|
1551
1664
|
}
|
|
1552
1665
|
}, [isDragging, handleDragMove, handleDragEnd]);
|
|
1553
|
-
|
|
1666
|
+
React14.useEffect(() => {
|
|
1554
1667
|
if (isPinnedDragging) {
|
|
1555
1668
|
window.addEventListener("pointermove", handlePinnedDragMove);
|
|
1556
1669
|
window.addEventListener("pointerup", handlePinnedDragEnd);
|
|
@@ -1560,7 +1673,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1560
1673
|
};
|
|
1561
1674
|
}
|
|
1562
1675
|
}, [isPinnedDragging, handlePinnedDragMove, handlePinnedDragEnd]);
|
|
1563
|
-
|
|
1676
|
+
React14.useEffect(() => {
|
|
1564
1677
|
if (isResizing) {
|
|
1565
1678
|
window.addEventListener("pointermove", handleResizeMove);
|
|
1566
1679
|
window.addEventListener("pointerup", handleResizeEnd);
|
|
@@ -1570,7 +1683,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1570
1683
|
};
|
|
1571
1684
|
}
|
|
1572
1685
|
}, [isResizing, handleResizeMove, handleResizeEnd]);
|
|
1573
|
-
const panelStyles =
|
|
1686
|
+
const panelStyles = React14.useMemo(() => {
|
|
1574
1687
|
if (mode === "pinned") {
|
|
1575
1688
|
const baseStyles = getPinnedPositionStyles(edge, pinnedSize);
|
|
1576
1689
|
if (pullOffset > 0) {
|
|
@@ -1613,7 +1726,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1613
1726
|
/* @__PURE__ */ jsxs5(
|
|
1614
1727
|
"div",
|
|
1615
1728
|
{
|
|
1616
|
-
ref,
|
|
1729
|
+
ref: setPanelRef,
|
|
1617
1730
|
className: cn(
|
|
1618
1731
|
"fixed z-50 flex flex-col bg-background border border-border shadow-lg overflow-hidden",
|
|
1619
1732
|
mode === "pinned" && pinnedClasses,
|
|
@@ -1692,7 +1805,7 @@ var DataPanel = React13.forwardRef(
|
|
|
1692
1805
|
DataPanel.displayName = "DataPanel";
|
|
1693
1806
|
|
|
1694
1807
|
// src/components/Skeleton.tsx
|
|
1695
|
-
import * as
|
|
1808
|
+
import * as React15 from "react";
|
|
1696
1809
|
import { cva as cva5 } from "class-variance-authority";
|
|
1697
1810
|
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
1698
1811
|
var skeletonVariants = cva5("rounded-md bg-muted", {
|
|
@@ -1710,7 +1823,7 @@ var skeletonVariants = cva5("rounded-md bg-muted", {
|
|
|
1710
1823
|
variant: "default"
|
|
1711
1824
|
}
|
|
1712
1825
|
});
|
|
1713
|
-
var Skeleton =
|
|
1826
|
+
var Skeleton = React15.forwardRef(
|
|
1714
1827
|
({ className, variant, animation = "pulse", ...props }, ref) => {
|
|
1715
1828
|
const animationClass = animation === "pulse" ? "animate-pulse" : animation === "shimmer" ? "animate-shimmer" : "";
|
|
1716
1829
|
return /* @__PURE__ */ jsx13(
|
|
@@ -1726,7 +1839,7 @@ var Skeleton = React14.forwardRef(
|
|
|
1726
1839
|
Skeleton.displayName = "Skeleton";
|
|
1727
1840
|
|
|
1728
1841
|
// src/components/Spinner.tsx
|
|
1729
|
-
import * as
|
|
1842
|
+
import * as React16 from "react";
|
|
1730
1843
|
import { cva as cva6 } from "class-variance-authority";
|
|
1731
1844
|
import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1732
1845
|
var spinnerVariants = cva6("animate-spin text-current", {
|
|
@@ -1742,7 +1855,7 @@ var spinnerVariants = cva6("animate-spin text-current", {
|
|
|
1742
1855
|
size: "md"
|
|
1743
1856
|
}
|
|
1744
1857
|
});
|
|
1745
|
-
var Spinner =
|
|
1858
|
+
var Spinner = React16.forwardRef(
|
|
1746
1859
|
({ className, size, label = "Loading...", ...props }, ref) => {
|
|
1747
1860
|
return /* @__PURE__ */ jsxs6(
|
|
1748
1861
|
"svg",
|
|
@@ -1784,7 +1897,7 @@ var Spinner = React15.forwardRef(
|
|
|
1784
1897
|
Spinner.displayName = "Spinner";
|
|
1785
1898
|
|
|
1786
1899
|
// src/components/LoadingLogo.tsx
|
|
1787
|
-
import * as
|
|
1900
|
+
import * as React17 from "react";
|
|
1788
1901
|
import { jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1789
1902
|
var logoPaths = [
|
|
1790
1903
|
"M9.902 16.6c.3.7 1.7.8 1-.6-.6-1.4-2.3-5.1-6.1-6.3-1.7-.5-3.7.4-4.3 1.6-.4.7-1.1 2.9.5 4.3.8.7 1.9 1.2 3.6 1 .4-.1.9-.5.6-.8-.5-.4-1.9-1.7-1.1-2.7.7-.8 1.4-.6 2-.3.4.2 2.1 1 3.7 3.6l.1.2z",
|
|
@@ -1807,7 +1920,7 @@ var colors = {
|
|
|
1807
1920
|
stroke: "#ffffff"
|
|
1808
1921
|
}
|
|
1809
1922
|
};
|
|
1810
|
-
var LoadingLogo =
|
|
1923
|
+
var LoadingLogo = React17.forwardRef(
|
|
1811
1924
|
({ width = 40, height = 40, loading = false, variant = "dark", className, ...props }, ref) => {
|
|
1812
1925
|
const currentColors = colors[variant];
|
|
1813
1926
|
const fillColor = loading ? currentColors.fillLoading : currentColors.fill;
|
|
@@ -1856,7 +1969,7 @@ var LoadingLogo = React16.forwardRef(
|
|
|
1856
1969
|
LoadingLogo.displayName = "LoadingLogo";
|
|
1857
1970
|
|
|
1858
1971
|
// src/components/ProgressBar.tsx
|
|
1859
|
-
import * as
|
|
1972
|
+
import * as React18 from "react";
|
|
1860
1973
|
import { cva as cva7 } from "class-variance-authority";
|
|
1861
1974
|
import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1862
1975
|
var progressBarVariants = cva7("w-full overflow-hidden rounded-full bg-muted", {
|
|
@@ -1884,7 +1997,7 @@ var progressFillVariants = cva7("h-full rounded-full transition-all duration-300
|
|
|
1884
1997
|
variant: "default"
|
|
1885
1998
|
}
|
|
1886
1999
|
});
|
|
1887
|
-
var ProgressBar =
|
|
2000
|
+
var ProgressBar = React18.forwardRef(
|
|
1888
2001
|
({ className, size, variant, value, max = 100, label = "Progress", showValue = false, ...props }, ref) => {
|
|
1889
2002
|
const isIndeterminate = value === void 0;
|
|
1890
2003
|
const clampedValue = isIndeterminate ? 0 : Math.min(Math.max(0, value), max);
|
|
@@ -1923,11 +2036,11 @@ var ProgressBar = React17.forwardRef(
|
|
|
1923
2036
|
ProgressBar.displayName = "ProgressBar";
|
|
1924
2037
|
|
|
1925
2038
|
// src/components/LoadingOverlay.tsx
|
|
1926
|
-
import * as
|
|
2039
|
+
import * as React19 from "react";
|
|
1927
2040
|
import { Fragment as Fragment2, jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1928
2041
|
var spinnerSizeMap = { sm: "sm", md: "md", lg: "lg", xl: "xl" };
|
|
1929
2042
|
var logoSizeMap = { sm: 32, md: 40, lg: 56, xl: 80 };
|
|
1930
|
-
var LoadingOverlay =
|
|
2043
|
+
var LoadingOverlay = React19.forwardRef(
|
|
1931
2044
|
({
|
|
1932
2045
|
loading = true,
|
|
1933
2046
|
variant = "spinner",
|
|
@@ -1942,8 +2055,8 @@ var LoadingOverlay = React18.forwardRef(
|
|
|
1942
2055
|
children,
|
|
1943
2056
|
...props
|
|
1944
2057
|
}, ref) => {
|
|
1945
|
-
const [visible, setVisible] =
|
|
1946
|
-
|
|
2058
|
+
const [visible, setVisible] = React19.useState(delay === 0 && loading);
|
|
2059
|
+
React19.useEffect(() => {
|
|
1947
2060
|
if (!loading) {
|
|
1948
2061
|
setVisible(false);
|
|
1949
2062
|
return;
|
|
@@ -2011,9 +2124,9 @@ var LoadingOverlay = React18.forwardRef(
|
|
|
2011
2124
|
LoadingOverlay.displayName = "LoadingOverlay";
|
|
2012
2125
|
|
|
2013
2126
|
// src/components/LoadingPage.tsx
|
|
2014
|
-
import * as
|
|
2127
|
+
import * as React20 from "react";
|
|
2015
2128
|
import { jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2016
|
-
var LoadingPage =
|
|
2129
|
+
var LoadingPage = React20.forwardRef(
|
|
2017
2130
|
({
|
|
2018
2131
|
loading = true,
|
|
2019
2132
|
message,
|
|
@@ -2024,8 +2137,8 @@ var LoadingPage = React19.forwardRef(
|
|
|
2024
2137
|
className,
|
|
2025
2138
|
...props
|
|
2026
2139
|
}, ref) => {
|
|
2027
|
-
const [visible, setVisible] =
|
|
2028
|
-
|
|
2140
|
+
const [visible, setVisible] = React20.useState(delay === 0 && loading);
|
|
2141
|
+
React20.useEffect(() => {
|
|
2029
2142
|
if (!loading) {
|
|
2030
2143
|
setVisible(false);
|
|
2031
2144
|
return;
|
|
@@ -2065,9 +2178,9 @@ var LoadingPage = React19.forwardRef(
|
|
|
2065
2178
|
LoadingPage.displayName = "LoadingPage";
|
|
2066
2179
|
|
|
2067
2180
|
// src/components/LoadingSection.tsx
|
|
2068
|
-
import * as
|
|
2181
|
+
import * as React21 from "react";
|
|
2069
2182
|
import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2070
|
-
var LoadingSection =
|
|
2183
|
+
var LoadingSection = React21.forwardRef(
|
|
2071
2184
|
({
|
|
2072
2185
|
loading = false,
|
|
2073
2186
|
variant = "spinner",
|
|
@@ -2109,9 +2222,9 @@ var LoadingSection = React20.forwardRef(
|
|
|
2109
2222
|
LoadingSection.displayName = "LoadingSection";
|
|
2110
2223
|
|
|
2111
2224
|
// src/components/LiveRegion.tsx
|
|
2112
|
-
import * as
|
|
2225
|
+
import * as React22 from "react";
|
|
2113
2226
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
2114
|
-
var LiveRegion =
|
|
2227
|
+
var LiveRegion = React22.forwardRef(
|
|
2115
2228
|
({ message, politeness = "polite", atomic = true, visuallyHidden = true, className, children }, ref) => {
|
|
2116
2229
|
return /* @__PURE__ */ jsx20(
|
|
2117
2230
|
"div",
|
|
@@ -2132,9 +2245,9 @@ var LiveRegion = React21.forwardRef(
|
|
|
2132
2245
|
LiveRegion.displayName = "LiveRegion";
|
|
2133
2246
|
|
|
2134
2247
|
// src/components/SkipLink.tsx
|
|
2135
|
-
import * as
|
|
2248
|
+
import * as React23 from "react";
|
|
2136
2249
|
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
2137
|
-
var SkipLink =
|
|
2250
|
+
var SkipLink = React23.forwardRef(
|
|
2138
2251
|
({ targetId, className, children = "Skip to main content", ...props }, ref) => {
|
|
2139
2252
|
const handleClick = (e) => {
|
|
2140
2253
|
e.preventDefault();
|
|
@@ -2167,90 +2280,12 @@ var SkipLink = React22.forwardRef(
|
|
|
2167
2280
|
);
|
|
2168
2281
|
SkipLink.displayName = "SkipLink";
|
|
2169
2282
|
|
|
2170
|
-
// src/hooks/useFocusTrap.ts
|
|
2171
|
-
import { useEffect as useEffect5, useRef as useRef3, useCallback as useCallback3 } from "react";
|
|
2172
|
-
var FOCUSABLE_SELECTOR = [
|
|
2173
|
-
"a[href]",
|
|
2174
|
-
"area[href]",
|
|
2175
|
-
'input:not([disabled]):not([type="hidden"])',
|
|
2176
|
-
"select:not([disabled])",
|
|
2177
|
-
"textarea:not([disabled])",
|
|
2178
|
-
"button:not([disabled])",
|
|
2179
|
-
"iframe",
|
|
2180
|
-
"object",
|
|
2181
|
-
"embed",
|
|
2182
|
-
"[contenteditable]",
|
|
2183
|
-
'[tabindex]:not([tabindex="-1"])'
|
|
2184
|
-
].join(",");
|
|
2185
|
-
function getFocusableElements(container) {
|
|
2186
|
-
const elements = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
2187
|
-
return Array.from(elements).filter(
|
|
2188
|
-
(el) => el.offsetParent !== null && getComputedStyle(el).visibility !== "hidden"
|
|
2189
|
-
);
|
|
2190
|
-
}
|
|
2191
|
-
function useFocusTrap(options = {}) {
|
|
2192
|
-
const { active = true, returnFocusTo, initialFocus, preventScroll = false } = options;
|
|
2193
|
-
const containerRef = useRef3(null);
|
|
2194
|
-
const previousActiveElementRef = useRef3(null);
|
|
2195
|
-
const handleKeyDown = useCallback3(
|
|
2196
|
-
(event) => {
|
|
2197
|
-
if (!active || event.key !== "Tab") return;
|
|
2198
|
-
const container = containerRef.current;
|
|
2199
|
-
if (!container) return;
|
|
2200
|
-
const focusableElements = getFocusableElements(container);
|
|
2201
|
-
if (focusableElements.length === 0) return;
|
|
2202
|
-
const firstElement = focusableElements[0];
|
|
2203
|
-
const lastElement = focusableElements[focusableElements.length - 1];
|
|
2204
|
-
if (event.shiftKey) {
|
|
2205
|
-
if (document.activeElement === firstElement) {
|
|
2206
|
-
event.preventDefault();
|
|
2207
|
-
lastElement.focus({ preventScroll });
|
|
2208
|
-
}
|
|
2209
|
-
} else {
|
|
2210
|
-
if (document.activeElement === lastElement) {
|
|
2211
|
-
event.preventDefault();
|
|
2212
|
-
firstElement.focus({ preventScroll });
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
},
|
|
2216
|
-
[active, preventScroll]
|
|
2217
|
-
);
|
|
2218
|
-
useEffect5(() => {
|
|
2219
|
-
if (!active) return;
|
|
2220
|
-
const container = containerRef.current;
|
|
2221
|
-
if (!container) return;
|
|
2222
|
-
previousActiveElementRef.current = document.activeElement;
|
|
2223
|
-
const focusableElements = getFocusableElements(container);
|
|
2224
|
-
if (focusableElements.length > 0) {
|
|
2225
|
-
let elementToFocus = null;
|
|
2226
|
-
if (initialFocus) {
|
|
2227
|
-
elementToFocus = container.querySelector(initialFocus);
|
|
2228
|
-
}
|
|
2229
|
-
if (!elementToFocus) {
|
|
2230
|
-
elementToFocus = focusableElements[0];
|
|
2231
|
-
}
|
|
2232
|
-
requestAnimationFrame(() => {
|
|
2233
|
-
elementToFocus?.focus({ preventScroll });
|
|
2234
|
-
});
|
|
2235
|
-
}
|
|
2236
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
2237
|
-
return () => {
|
|
2238
|
-
document.removeEventListener("keydown", handleKeyDown);
|
|
2239
|
-
const elementToReturn = returnFocusTo ?? previousActiveElementRef.current;
|
|
2240
|
-
if (elementToReturn && typeof elementToReturn.focus === "function") {
|
|
2241
|
-
elementToReturn.focus({ preventScroll });
|
|
2242
|
-
}
|
|
2243
|
-
};
|
|
2244
|
-
}, [active, initialFocus, returnFocusTo, handleKeyDown, preventScroll]);
|
|
2245
|
-
return containerRef;
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2248
2283
|
// src/hooks/useFocusRef.ts
|
|
2249
|
-
import { useRef as
|
|
2284
|
+
import { useRef as useRef5, useEffect as useEffect7 } from "react";
|
|
2250
2285
|
function useFocusRef(options = {}) {
|
|
2251
2286
|
const { focusOnMount = false, preventScroll = false, delay = 0 } = options;
|
|
2252
|
-
const ref =
|
|
2253
|
-
|
|
2287
|
+
const ref = useRef5(null);
|
|
2288
|
+
useEffect7(() => {
|
|
2254
2289
|
if (!focusOnMount) return;
|
|
2255
2290
|
const focus = () => {
|
|
2256
2291
|
if (ref.current && typeof ref.current.focus === "function") {
|
|
@@ -2269,10 +2304,10 @@ function useFocusRef(options = {}) {
|
|
|
2269
2304
|
}
|
|
2270
2305
|
|
|
2271
2306
|
// src/hooks/useReducedMotion.ts
|
|
2272
|
-
import { useState as useState6, useEffect as
|
|
2307
|
+
import { useState as useState6, useEffect as useEffect8 } from "react";
|
|
2273
2308
|
function useReducedMotion() {
|
|
2274
2309
|
const [reducedMotion, setReducedMotion] = useState6(false);
|
|
2275
|
-
|
|
2310
|
+
useEffect8(() => {
|
|
2276
2311
|
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
2277
2312
|
setReducedMotion(mediaQuery.matches);
|
|
2278
2313
|
const handleChange = (event) => {
|
|
@@ -2287,7 +2322,7 @@ function useReducedMotion() {
|
|
|
2287
2322
|
}
|
|
2288
2323
|
|
|
2289
2324
|
// src/hooks/useArrowNavigation.ts
|
|
2290
|
-
import { useCallback as useCallback4, useRef as
|
|
2325
|
+
import { useCallback as useCallback4, useRef as useRef6, useState as useState7 } from "react";
|
|
2291
2326
|
var DEFAULT_SELECTOR = '[role="menuitem"], [role="option"], [role="tab"], button, a, [tabindex]:not([tabindex="-1"])';
|
|
2292
2327
|
function useArrowNavigation(options = {}) {
|
|
2293
2328
|
const {
|
|
@@ -2296,8 +2331,13 @@ function useArrowNavigation(options = {}) {
|
|
|
2296
2331
|
itemSelector = DEFAULT_SELECTOR,
|
|
2297
2332
|
onFocusChange
|
|
2298
2333
|
} = options;
|
|
2299
|
-
const containerRef =
|
|
2300
|
-
const focusedIndexRef =
|
|
2334
|
+
const containerRef = useRef6(null);
|
|
2335
|
+
const focusedIndexRef = useRef6(-1);
|
|
2336
|
+
const [focusedIndex, setFocusedIndexState] = useState7(-1);
|
|
2337
|
+
const setFocusedIndex = useCallback4((index) => {
|
|
2338
|
+
focusedIndexRef.current = index;
|
|
2339
|
+
setFocusedIndexState(index);
|
|
2340
|
+
}, []);
|
|
2301
2341
|
const getFocusableItems = useCallback4(() => {
|
|
2302
2342
|
if (!containerRef.current) return [];
|
|
2303
2343
|
return Array.from(containerRef.current.querySelectorAll(itemSelector));
|
|
@@ -2316,11 +2356,11 @@ function useArrowNavigation(options = {}) {
|
|
|
2316
2356
|
const element = items[targetIndex];
|
|
2317
2357
|
if (element) {
|
|
2318
2358
|
element.focus();
|
|
2319
|
-
|
|
2359
|
+
setFocusedIndex(targetIndex);
|
|
2320
2360
|
onFocusChange?.(targetIndex, element);
|
|
2321
2361
|
}
|
|
2322
2362
|
},
|
|
2323
|
-
[getFocusableItems, loop, onFocusChange]
|
|
2363
|
+
[getFocusableItems, loop, onFocusChange, setFocusedIndex]
|
|
2324
2364
|
);
|
|
2325
2365
|
const handleKeyDown = useCallback4(
|
|
2326
2366
|
(event) => {
|
|
@@ -2374,10 +2414,10 @@ function useArrowNavigation(options = {}) {
|
|
|
2374
2414
|
const items = getFocusableItems();
|
|
2375
2415
|
const index = items.indexOf(event.target);
|
|
2376
2416
|
if (index !== -1) {
|
|
2377
|
-
|
|
2417
|
+
setFocusedIndex(index);
|
|
2378
2418
|
}
|
|
2379
2419
|
},
|
|
2380
|
-
[getFocusableItems]
|
|
2420
|
+
[getFocusableItems, setFocusedIndex]
|
|
2381
2421
|
);
|
|
2382
2422
|
const containerProps = {
|
|
2383
2423
|
ref: (node) => {
|
|
@@ -2386,14 +2426,15 @@ function useArrowNavigation(options = {}) {
|
|
|
2386
2426
|
onKeyDown: handleKeyDown,
|
|
2387
2427
|
onFocus: handleFocus
|
|
2388
2428
|
};
|
|
2429
|
+
const tabStopIndex = focusedIndex === -1 ? 0 : focusedIndex;
|
|
2389
2430
|
const getItemProps = useCallback4(
|
|
2390
2431
|
(index) => ({
|
|
2391
|
-
tabIndex: index ===
|
|
2432
|
+
tabIndex: index === tabStopIndex ? 0 : -1,
|
|
2392
2433
|
onFocus: () => {
|
|
2393
|
-
|
|
2434
|
+
setFocusedIndex(index);
|
|
2394
2435
|
}
|
|
2395
2436
|
}),
|
|
2396
|
-
[]
|
|
2437
|
+
[tabStopIndex, setFocusedIndex]
|
|
2397
2438
|
);
|
|
2398
2439
|
return {
|
|
2399
2440
|
containerProps,
|
|
@@ -2404,13 +2445,13 @@ function useArrowNavigation(options = {}) {
|
|
|
2404
2445
|
}
|
|
2405
2446
|
|
|
2406
2447
|
// src/hooks/useRovingTabindex.ts
|
|
2407
|
-
import { useState as
|
|
2448
|
+
import { useState as useState8, useCallback as useCallback5, useRef as useRef7 } from "react";
|
|
2408
2449
|
var DEFAULT_SELECTOR2 = "[data-roving-tabindex-item]";
|
|
2409
2450
|
function useRovingTabindex(options = {}) {
|
|
2410
2451
|
const { loop = true, itemSelector = DEFAULT_SELECTOR2, initialIndex = 0, onIndexChange } = options;
|
|
2411
|
-
const [activeIndex, setActiveIndex] =
|
|
2412
|
-
const containerRef =
|
|
2413
|
-
const itemsRef =
|
|
2452
|
+
const [activeIndex, setActiveIndex] = useState8(initialIndex);
|
|
2453
|
+
const containerRef = useRef7(null);
|
|
2454
|
+
const itemsRef = useRef7(/* @__PURE__ */ new Map());
|
|
2414
2455
|
const getItems = useCallback5(() => {
|
|
2415
2456
|
if (!containerRef.current) {
|
|
2416
2457
|
return Array.from(itemsRef.current.values());
|
|
@@ -2511,34 +2552,6 @@ function useRovingTabindex(options = {}) {
|
|
|
2511
2552
|
};
|
|
2512
2553
|
}
|
|
2513
2554
|
|
|
2514
|
-
// src/hooks/useEscapeKey.ts
|
|
2515
|
-
import * as React23 from "react";
|
|
2516
|
-
function useEscapeKey(callback, options) {
|
|
2517
|
-
const { enabled = true, preventDefault = true, stopPropagation = false } = options ?? {};
|
|
2518
|
-
const callbackRef = React23.useRef(callback);
|
|
2519
|
-
React23.useEffect(() => {
|
|
2520
|
-
callbackRef.current = callback;
|
|
2521
|
-
}, [callback]);
|
|
2522
|
-
React23.useEffect(() => {
|
|
2523
|
-
if (!enabled) return;
|
|
2524
|
-
const handleKeyDown = (event) => {
|
|
2525
|
-
if (event.key === "Escape") {
|
|
2526
|
-
if (preventDefault) {
|
|
2527
|
-
event.preventDefault();
|
|
2528
|
-
}
|
|
2529
|
-
if (stopPropagation) {
|
|
2530
|
-
event.stopPropagation();
|
|
2531
|
-
}
|
|
2532
|
-
callbackRef.current(event);
|
|
2533
|
-
}
|
|
2534
|
-
};
|
|
2535
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
2536
|
-
return () => {
|
|
2537
|
-
document.removeEventListener("keydown", handleKeyDown);
|
|
2538
|
-
};
|
|
2539
|
-
}, [enabled, preventDefault, stopPropagation]);
|
|
2540
|
-
}
|
|
2541
|
-
|
|
2542
2555
|
// src/hooks/useClickOutside.ts
|
|
2543
2556
|
import * as React24 from "react";
|
|
2544
2557
|
function useClickOutside(ref, callback, options) {
|
|
@@ -2548,9 +2561,12 @@ function useClickOutside(ref, callback, options) {
|
|
|
2548
2561
|
ignoreElements = []
|
|
2549
2562
|
} = options ?? {};
|
|
2550
2563
|
const callbackRef = React24.useRef(callback);
|
|
2564
|
+
const ignoreElementsRef = React24.useRef(ignoreElements);
|
|
2551
2565
|
React24.useEffect(() => {
|
|
2552
2566
|
callbackRef.current = callback;
|
|
2553
|
-
|
|
2567
|
+
ignoreElementsRef.current = ignoreElements;
|
|
2568
|
+
}, [callback, ignoreElements]);
|
|
2569
|
+
const eventsKey = events.join(",");
|
|
2554
2570
|
React24.useEffect(() => {
|
|
2555
2571
|
if (!enabled) return;
|
|
2556
2572
|
const handleEvent = (event) => {
|
|
@@ -2558,22 +2574,23 @@ function useClickOutside(ref, callback, options) {
|
|
|
2558
2574
|
if (ref.current?.contains(target)) {
|
|
2559
2575
|
return;
|
|
2560
2576
|
}
|
|
2561
|
-
for (const ignoreRef of
|
|
2577
|
+
for (const ignoreRef of ignoreElementsRef.current) {
|
|
2562
2578
|
if (ignoreRef.current?.contains(target)) {
|
|
2563
2579
|
return;
|
|
2564
2580
|
}
|
|
2565
2581
|
}
|
|
2566
2582
|
callbackRef.current(event);
|
|
2567
2583
|
};
|
|
2568
|
-
|
|
2584
|
+
const eventTypes = eventsKey.split(",");
|
|
2585
|
+
eventTypes.forEach((eventType) => {
|
|
2569
2586
|
document.addEventListener(eventType, handleEvent);
|
|
2570
2587
|
});
|
|
2571
2588
|
return () => {
|
|
2572
|
-
|
|
2589
|
+
eventTypes.forEach((eventType) => {
|
|
2573
2590
|
document.removeEventListener(eventType, handleEvent);
|
|
2574
2591
|
});
|
|
2575
2592
|
};
|
|
2576
|
-
}, [enabled,
|
|
2593
|
+
}, [enabled, eventsKey, ref]);
|
|
2577
2594
|
}
|
|
2578
2595
|
export {
|
|
2579
2596
|
Avatar,
|