@expcat/tigercat-react 2.0.0 → 2.0.19
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/{chunk-JTFNGXOC.mjs → chunk-2ENQZECC.mjs} +53 -31
- package/dist/{chunk-O5RAMCBV.mjs → chunk-2JYJPNW3.mjs} +1 -1
- package/dist/{chunk-NBQ3Q6DD.mjs → chunk-2WGEHH5A.mjs} +1 -1
- package/dist/{chunk-K7MYQISG.mjs → chunk-54HN5BXW.mjs} +10 -4
- package/dist/{chunk-C6QK5MJT.mjs → chunk-5CKMYMTS.mjs} +1 -1
- package/dist/{chunk-Y7K27DVV.mjs → chunk-6H5Y7Y6E.mjs} +42 -28
- package/dist/chunk-6MGQAJ62.mjs +203 -0
- package/dist/{chunk-TO2URY7X.mjs → chunk-7AFRHC7P.mjs} +90 -61
- package/dist/{chunk-MGQWVJHX.mjs → chunk-ALSOPYM5.mjs} +69 -62
- package/dist/{chunk-YCKY72BW.mjs → chunk-BOGOQ44C.mjs} +1 -1
- package/dist/{chunk-Q327ESD2.mjs → chunk-BUXHI6UK.mjs} +17 -38
- package/dist/{chunk-TORX7SG4.mjs → chunk-CC7IOSNI.mjs} +10 -4
- package/dist/{chunk-OVE2ZUJJ.mjs → chunk-D33BIMGK.mjs} +1 -1
- package/dist/{chunk-PYDWF4ED.mjs → chunk-D3KP72UC.mjs} +34 -9
- package/dist/{chunk-ZEP7I6WB.mjs → chunk-DPWRXXXW.mjs} +16 -8
- package/dist/chunk-HKAZXG74.mjs +308 -0
- package/dist/{chunk-QWUDJC6K.mjs → chunk-HOYBHB7B.mjs} +38 -17
- package/dist/{chunk-3RY6M4AK.mjs → chunk-HS6KUPTI.mjs} +1 -1
- package/dist/{chunk-EKESN747.mjs → chunk-HSBN5MLS.mjs} +1 -1
- package/dist/{chunk-AJJJ6HWC.mjs → chunk-K4GIKSZE.mjs} +1 -1
- package/dist/{chunk-2UOGBS3C.mjs → chunk-KP6DEYWB.mjs} +27 -6
- package/dist/{chunk-PAN256RW.mjs → chunk-KVCI2346.mjs} +59 -55
- package/dist/{chunk-LBXNMCXN.mjs → chunk-OZ5XLR22.mjs} +6 -1
- package/dist/{chunk-5RVLBNLI.mjs → chunk-RJPNBYK5.mjs} +4 -4
- package/dist/{chunk-HELLYIX2.mjs → chunk-V6P7ZK6O.mjs} +3 -3
- package/dist/{chunk-4XGO3OSE.mjs → chunk-XE4YFBOZ.mjs} +12 -17
- package/dist/{chunk-YI7NQWUV.mjs → chunk-YI6YWH66.mjs} +14 -30
- package/dist/{chunk-SHCBCM2W.mjs → chunk-YIB6ZXZF.mjs} +142 -105
- package/dist/{chunk-SZBYEGKU.mjs → chunk-ZCGIZOMT.mjs} +1 -1
- package/dist/{chunk-S7IB6YST.mjs → chunk-ZG56T75O.mjs} +25 -40
- package/dist/{chunk-44BPUG24.mjs → chunk-ZH5ZBLAN.mjs} +38 -16
- package/dist/components/ActivityFeed.mjs +3 -3
- package/dist/components/AutoComplete.mjs +2 -1
- package/dist/components/Cascader.mjs +2 -1
- package/dist/components/CodeEditor.mjs +1 -1
- package/dist/components/ColorPicker.mjs +2 -1
- package/dist/components/CropUpload.mjs +3 -3
- package/dist/components/DataExport.mjs +3 -3
- package/dist/components/DataTableWithToolbar.mjs +6 -6
- package/dist/components/DatePicker.mjs +2 -1
- package/dist/components/Drawer.mjs +2 -2
- package/dist/components/Dropdown.mjs +2 -2
- package/dist/components/FormItem.mjs +2 -1
- package/dist/components/Image.mjs +5 -5
- package/dist/components/ImageGroup.mjs +3 -3
- package/dist/components/ImagePreview.mjs +2 -2
- package/dist/components/Loading.mjs +2 -2
- package/dist/components/Mentions.mjs +2 -1
- package/dist/components/Menu.mjs +2 -2
- package/dist/components/Modal.mjs +2 -2
- package/dist/components/NotificationCenter.mjs +3 -3
- package/dist/components/Popconfirm.mjs +3 -3
- package/dist/components/Popover.mjs +3 -3
- package/dist/components/Select.mjs +2 -1
- package/dist/components/Spotlight.mjs +2 -2
- package/dist/components/Table.mjs +3 -2
- package/dist/components/TimePicker.mjs +2 -1
- package/dist/components/Tooltip.mjs +3 -3
- package/dist/components/Tour.mjs +2 -2
- package/dist/components/TreeSelect.mjs +2 -1
- package/dist/index.mjs +5 -2
- package/package.json +2 -2
- package/dist/chunk-KVARQQAG.mjs +0 -181
- package/dist/chunk-SEWNVIHH.mjs +0 -153
package/dist/chunk-SEWNVIHH.mjs
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// src/utils/overlay.ts
|
|
2
|
-
import { useEffect, useRef, useState, useCallback } from "react";
|
|
3
|
-
import { createPortal } from "react-dom";
|
|
4
|
-
import {
|
|
5
|
-
getFocusTrapNavigation,
|
|
6
|
-
getFocusableElements,
|
|
7
|
-
isEscapeKey,
|
|
8
|
-
isEventOutside,
|
|
9
|
-
lockBodyScroll,
|
|
10
|
-
isBrowser,
|
|
11
|
-
computeFloatingPosition,
|
|
12
|
-
autoUpdateFloating
|
|
13
|
-
} from "@expcat/tigercat-core";
|
|
14
|
-
function useClickOutside({
|
|
15
|
-
enabled,
|
|
16
|
-
refs,
|
|
17
|
-
onOutsideClick,
|
|
18
|
-
defer = false
|
|
19
|
-
}) {
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (!enabled) return;
|
|
22
|
-
const handler = (event) => {
|
|
23
|
-
const elements = refs.map((ref) => ref?.current);
|
|
24
|
-
if (isEventOutside(event, elements)) {
|
|
25
|
-
onOutsideClick();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const attach = () => document.addEventListener("click", handler);
|
|
29
|
-
const detach = () => document.removeEventListener("click", handler);
|
|
30
|
-
if (!defer) {
|
|
31
|
-
attach();
|
|
32
|
-
return () => detach();
|
|
33
|
-
}
|
|
34
|
-
const timer = window.setTimeout(() => attach(), 0);
|
|
35
|
-
return () => {
|
|
36
|
-
window.clearTimeout(timer);
|
|
37
|
-
detach();
|
|
38
|
-
};
|
|
39
|
-
}, [enabled, refs, onOutsideClick, defer]);
|
|
40
|
-
}
|
|
41
|
-
function useEscapeKey({ enabled, onEscape }) {
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
if (!enabled) return;
|
|
44
|
-
const handler = (event) => {
|
|
45
|
-
if (event.defaultPrevented) return;
|
|
46
|
-
if (!isEscapeKey(event)) return;
|
|
47
|
-
onEscape();
|
|
48
|
-
};
|
|
49
|
-
document.addEventListener("keydown", handler);
|
|
50
|
-
return () => document.removeEventListener("keydown", handler);
|
|
51
|
-
}, [enabled, onEscape]);
|
|
52
|
-
}
|
|
53
|
-
function useBodyScrollLock({ enabled }) {
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (!enabled) return;
|
|
56
|
-
return lockBodyScroll();
|
|
57
|
-
}, [enabled]);
|
|
58
|
-
}
|
|
59
|
-
function renderBodyPortal(node) {
|
|
60
|
-
if (!isBrowser()) return null;
|
|
61
|
-
return createPortal(node, document.body);
|
|
62
|
-
}
|
|
63
|
-
function useFocusTrap({ enabled, containerRef }) {
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
const container = containerRef.current;
|
|
66
|
-
if (!enabled || !container) return;
|
|
67
|
-
const handler = (event) => {
|
|
68
|
-
const focusables = getFocusableElements(container);
|
|
69
|
-
const activeElement = container.ownerDocument?.activeElement ?? document.activeElement;
|
|
70
|
-
const nav = getFocusTrapNavigation(event, focusables, activeElement);
|
|
71
|
-
if (!nav.shouldHandle || !nav.next) return;
|
|
72
|
-
event.preventDefault();
|
|
73
|
-
nav.next.focus();
|
|
74
|
-
};
|
|
75
|
-
container.addEventListener("keydown", handler);
|
|
76
|
-
return () => container.removeEventListener("keydown", handler);
|
|
77
|
-
}, [enabled, containerRef]);
|
|
78
|
-
}
|
|
79
|
-
function useFloating(options) {
|
|
80
|
-
const {
|
|
81
|
-
referenceRef,
|
|
82
|
-
floatingRef,
|
|
83
|
-
enabled,
|
|
84
|
-
placement: initialPlacement = "bottom",
|
|
85
|
-
offset: offsetDistance = 8,
|
|
86
|
-
arrowRef,
|
|
87
|
-
onPlacementChange
|
|
88
|
-
} = options;
|
|
89
|
-
const [x, setX] = useState(0);
|
|
90
|
-
const [y, setY] = useState(0);
|
|
91
|
-
const [placement, setPlacement] = useState(initialPlacement);
|
|
92
|
-
const [arrowX, setArrowX] = useState(void 0);
|
|
93
|
-
const [arrowY, setArrowY] = useState(void 0);
|
|
94
|
-
const onPlacementChangeRef = useRef(onPlacementChange);
|
|
95
|
-
onPlacementChangeRef.current = onPlacementChange;
|
|
96
|
-
const update = useCallback(async () => {
|
|
97
|
-
const reference = referenceRef.current;
|
|
98
|
-
const floating = floatingRef.current;
|
|
99
|
-
if (!reference || !floating) return;
|
|
100
|
-
const floatingOptions = {
|
|
101
|
-
placement: initialPlacement,
|
|
102
|
-
offset: offsetDistance,
|
|
103
|
-
flip: true,
|
|
104
|
-
shift: true,
|
|
105
|
-
arrowElement: arrowRef?.current
|
|
106
|
-
};
|
|
107
|
-
const result = await computeFloatingPosition(
|
|
108
|
-
reference,
|
|
109
|
-
floating,
|
|
110
|
-
floatingOptions
|
|
111
|
-
);
|
|
112
|
-
setX(result.x);
|
|
113
|
-
setY(result.y);
|
|
114
|
-
setPlacement((prev) => {
|
|
115
|
-
if (prev !== result.placement) {
|
|
116
|
-
onPlacementChangeRef.current?.(result.placement);
|
|
117
|
-
return result.placement;
|
|
118
|
-
}
|
|
119
|
-
return prev;
|
|
120
|
-
});
|
|
121
|
-
if (result.arrow) {
|
|
122
|
-
setArrowX(result.arrow.x);
|
|
123
|
-
setArrowY(result.arrow.y);
|
|
124
|
-
}
|
|
125
|
-
}, [referenceRef, floatingRef, initialPlacement, offsetDistance, arrowRef]);
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
const reference = referenceRef.current;
|
|
128
|
-
const floating = floatingRef.current;
|
|
129
|
-
if (!enabled || !reference || !floating) return;
|
|
130
|
-
update();
|
|
131
|
-
const cleanup = autoUpdateFloating(reference, floating, update);
|
|
132
|
-
return () => {
|
|
133
|
-
cleanup();
|
|
134
|
-
};
|
|
135
|
-
}, [enabled, referenceRef, floatingRef, update]);
|
|
136
|
-
return {
|
|
137
|
-
x,
|
|
138
|
-
y,
|
|
139
|
-
placement,
|
|
140
|
-
arrowX,
|
|
141
|
-
arrowY,
|
|
142
|
-
update
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export {
|
|
147
|
-
useClickOutside,
|
|
148
|
-
useEscapeKey,
|
|
149
|
-
useBodyScrollLock,
|
|
150
|
-
renderBodyPortal,
|
|
151
|
-
useFocusTrap,
|
|
152
|
-
useFloating
|
|
153
|
-
};
|