jy-headless 0.3.16 → 0.3.17
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/Autocomplete/Autocomplete.js +1 -0
- package/dist/Autocomplete/Autocomplete.js.map +1 -0
- package/dist/Input/NumberInput.js +1 -0
- package/dist/Input/NumberInput.js.map +1 -0
- package/dist/Input/TextInput.js +1 -0
- package/dist/Input/TextInput.js.map +1 -0
- package/dist/Select/Select.js +1 -0
- package/dist/Select/Select.js.map +1 -0
- package/dist/Tooltip/Tooltip.js +1 -0
- package/dist/Tooltip/Tooltip.js.map +1 -0
- package/dist/hooks/useDebounce.js +1 -0
- package/dist/hooks/useDebounce.js.map +1 -0
- package/dist/hooks/usePortal.js +1 -0
- package/dist/hooks/usePortal.js.map +1 -0
- package/dist/hooks/useThrottle.js +1 -0
- package/dist/hooks/useThrottle.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +4 -3
- package/dist/cjs/Autocomplete/Autocomplete.d.ts +0 -110
- package/dist/cjs/Autocomplete/Autocomplete.js +0 -404
- package/dist/cjs/Autocomplete/Autocomplete.type.d.ts +0 -37
- package/dist/cjs/Autocomplete/index.d.ts +0 -2
- package/dist/cjs/Input/NumberInput.d.ts +0 -55
- package/dist/cjs/Input/NumberInput.js +0 -93
- package/dist/cjs/Input/NumberInput.type.d.ts +0 -31
- package/dist/cjs/Input/TextInput.d.ts +0 -98
- package/dist/cjs/Input/TextInput.js +0 -174
- package/dist/cjs/Input/TextInput.type.d.ts +0 -95
- package/dist/cjs/Input/index.d.ts +0 -4
- package/dist/cjs/Select/Select.d.ts +0 -51
- package/dist/cjs/Select/Select.js +0 -179
- package/dist/cjs/Select/Select.type.d.ts +0 -52
- package/dist/cjs/Select/index.d.ts +0 -2
- package/dist/cjs/Tooltip/Tooltip.d.ts +0 -10
- package/dist/cjs/Tooltip/Tooltip.js +0 -38
- package/dist/cjs/Tooltip/Tooltip.type.d.ts +0 -20
- package/dist/cjs/Tooltip/index.d.ts +0 -2
- package/dist/cjs/hooks/index.d.ts +0 -3
- package/dist/cjs/hooks/useDebounce.d.ts +0 -1
- package/dist/cjs/hooks/useDebounce.js +0 -24
- package/dist/cjs/hooks/usePortal.d.ts +0 -23
- package/dist/cjs/hooks/usePortal.js +0 -80
- package/dist/cjs/hooks/useThrottle.d.ts +0 -1
- package/dist/cjs/hooks/useThrottle.js +0 -34
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.js +0 -23
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var usePortal = require('../hooks/usePortal.js');
|
|
6
|
-
|
|
7
|
-
const SelectContext = react.createContext(null);
|
|
8
|
-
/**
|
|
9
|
-
* Select Context 접근 훅
|
|
10
|
-
*
|
|
11
|
-
* @throws Select 외부에서 사용할 경우 에러
|
|
12
|
-
*/
|
|
13
|
-
const useSelectContext = () => {
|
|
14
|
-
const ctx = react.useContext(SelectContext);
|
|
15
|
-
if (!ctx)
|
|
16
|
-
throw new Error('Select components must be used within <Select>');
|
|
17
|
-
return ctx;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Select 루트 컨테이너
|
|
21
|
-
*
|
|
22
|
-
* - 상태 관리 담당
|
|
23
|
-
* - Context Provider 역할
|
|
24
|
-
*/
|
|
25
|
-
const SelectContainer = ({ value, onChange, multiple = false, children }) => {
|
|
26
|
-
const [open, setOpen] = react.useState(false);
|
|
27
|
-
const triggerRef = react.useRef(null);
|
|
28
|
-
const optionRefs = react.useRef([]);
|
|
29
|
-
const [focusedIndex, setFocusedIndex] = react.useState(-1);
|
|
30
|
-
const toggleValue = (v) => {
|
|
31
|
-
if (!multiple) {
|
|
32
|
-
onChange([v]);
|
|
33
|
-
setOpen(false);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
onChange(value.includes(v)
|
|
37
|
-
? value.filter(i => i !== v)
|
|
38
|
-
: [...value, v]);
|
|
39
|
-
};
|
|
40
|
-
return (jsxRuntime.jsx(SelectContext.Provider, { value: {
|
|
41
|
-
open,
|
|
42
|
-
setOpen,
|
|
43
|
-
value,
|
|
44
|
-
toggleValue,
|
|
45
|
-
multiple,
|
|
46
|
-
triggerRef,
|
|
47
|
-
optionRefs,
|
|
48
|
-
focusedIndex,
|
|
49
|
-
setFocusedIndex,
|
|
50
|
-
}, children: children }));
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Select 트리거 버튼
|
|
54
|
-
*
|
|
55
|
-
* - 클릭 시 Options 열림
|
|
56
|
-
* - 최초 포커스를 첫 옵션으로 이동
|
|
57
|
-
*/
|
|
58
|
-
const Trigger = (props) => {
|
|
59
|
-
const { open, setOpen, triggerRef, setFocusedIndex } = useSelectContext();
|
|
60
|
-
return (jsxRuntime.jsx("div", { ref: triggerRef, role: 'button', "aria-expanded": open, onClick: (e) => {
|
|
61
|
-
setOpen(!open);
|
|
62
|
-
setFocusedIndex(0);
|
|
63
|
-
props.onClick?.(e);
|
|
64
|
-
}, ...props }));
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Options 드롭다운 영역
|
|
68
|
-
*
|
|
69
|
-
* 기능:
|
|
70
|
-
* - 외부 클릭 시 닫힘
|
|
71
|
-
* - ESC 키 닫기
|
|
72
|
-
* - ↑ ↓ 키 포커스 이동
|
|
73
|
-
* - portal 렌더링
|
|
74
|
-
*/
|
|
75
|
-
const Options = ({ children, ...props }) => {
|
|
76
|
-
const { open, triggerRef, setOpen, setFocusedIndex, optionRefs } = useSelectContext();
|
|
77
|
-
const popoverRef = react.useRef(null);
|
|
78
|
-
const triggerWidth = triggerRef.current?.getBoundingClientRect().width;
|
|
79
|
-
react.useEffect(() => {
|
|
80
|
-
if (!open)
|
|
81
|
-
return;
|
|
82
|
-
const handleOutsideClick = (e) => {
|
|
83
|
-
const target = e.target;
|
|
84
|
-
if (triggerRef.current?.contains(target) ||
|
|
85
|
-
popoverRef.current?.contains(target)) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
setOpen(false);
|
|
89
|
-
};
|
|
90
|
-
document.addEventListener('mousedown', handleOutsideClick);
|
|
91
|
-
return () => {
|
|
92
|
-
document.removeEventListener('mousedown', handleOutsideClick);
|
|
93
|
-
};
|
|
94
|
-
}, [open, setOpen, triggerRef]);
|
|
95
|
-
react.useEffect(() => {
|
|
96
|
-
if (!open)
|
|
97
|
-
return;
|
|
98
|
-
const handleKeyDown = (e) => {
|
|
99
|
-
e.preventDefault();
|
|
100
|
-
if (e.key === 'Escape') {
|
|
101
|
-
setOpen(false);
|
|
102
|
-
setFocusedIndex(-1);
|
|
103
|
-
}
|
|
104
|
-
if (e.key === 'ArrowUp') {
|
|
105
|
-
setFocusedIndex(prev => prev - 1 < 0 ? optionRefs.current.length - 1 : prev - 1);
|
|
106
|
-
}
|
|
107
|
-
if (e.key === 'ArrowDown') {
|
|
108
|
-
setFocusedIndex(prev => prev + 1 >= optionRefs.current.length ? 0 : prev + 1);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
document.addEventListener('keydown', handleKeyDown);
|
|
112
|
-
return () => {
|
|
113
|
-
optionRefs.current = [];
|
|
114
|
-
document.removeEventListener('keydown', handleKeyDown);
|
|
115
|
-
};
|
|
116
|
-
}, [open]);
|
|
117
|
-
const { portal } = usePortal({
|
|
118
|
-
visible: open,
|
|
119
|
-
targetRef: triggerRef,
|
|
120
|
-
popoverRef,
|
|
121
|
-
direction: 'bottom',
|
|
122
|
-
gap: 4,
|
|
123
|
-
content: (jsxRuntime.jsx("div", { ref: popoverRef, style: { width: triggerWidth }, ...props, children: children })),
|
|
124
|
-
});
|
|
125
|
-
return open ? portal : null;
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* 개별 선택 옵션
|
|
129
|
-
*
|
|
130
|
-
* 기능:
|
|
131
|
-
* - 선택 상태 표시
|
|
132
|
-
* - 포커스 관리
|
|
133
|
-
* - disabled 지원
|
|
134
|
-
*/
|
|
135
|
-
const Option = ({ value, disabled, children, ...props }) => {
|
|
136
|
-
const { value: selected, toggleValue, optionRefs, focusedIndex } = useSelectContext();
|
|
137
|
-
const isSelected = selected.includes(value);
|
|
138
|
-
const [index, setIndex] = react.useState(null);
|
|
139
|
-
const isFocused = react.useMemo(() => focusedIndex === index, [focusedIndex, index]);
|
|
140
|
-
const ref = react.useRef(null);
|
|
141
|
-
react.useEffect(() => {
|
|
142
|
-
if (ref.current && index === null) {
|
|
143
|
-
setIndex(optionRefs.current.length);
|
|
144
|
-
optionRefs.current[optionRefs.current.length] = ref.current;
|
|
145
|
-
}
|
|
146
|
-
}, []);
|
|
147
|
-
react.useEffect(() => {
|
|
148
|
-
ref.current?.setAttribute('data-focused', String(focusedIndex === index));
|
|
149
|
-
if (focusedIndex === index) {
|
|
150
|
-
ref.current?.focus();
|
|
151
|
-
}
|
|
152
|
-
}, [focusedIndex, index]);
|
|
153
|
-
return (jsxRuntime.jsx("div", { ref: ref, role: 'option', "aria-selected": isSelected, "aria-disabled": disabled, "data-focused": isFocused, onClick: () => {
|
|
154
|
-
if (!disabled)
|
|
155
|
-
toggleValue(value);
|
|
156
|
-
}, ...props, children: children }));
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Compound Select 컴포넌트
|
|
160
|
-
*
|
|
161
|
-
* 사용 예시:
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* <Select value={value} onChange={setValue}>
|
|
165
|
-
* <Select.Trigger>열기</Select.Trigger>
|
|
166
|
-
* <Select.Options>
|
|
167
|
-
* <Select.Option value="a">A</Select.Option>
|
|
168
|
-
* <Select.Option value="b">B</Select.Option>
|
|
169
|
-
* </Select.Options>
|
|
170
|
-
* </Select>
|
|
171
|
-
*/
|
|
172
|
-
const Select = Object.assign(SelectContainer, {
|
|
173
|
-
Trigger,
|
|
174
|
-
Options,
|
|
175
|
-
Option,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
exports.Select = Select;
|
|
179
|
-
exports.useSelectContext = useSelectContext;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { HTMLProps, ReactNode } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Select 루트 컴포넌트 props
|
|
4
|
-
*/
|
|
5
|
-
export interface SelectProps {
|
|
6
|
-
/**
|
|
7
|
-
* 선택된 값 목록
|
|
8
|
-
*
|
|
9
|
-
* - single 모드에서도 배열로 관리
|
|
10
|
-
*/
|
|
11
|
-
value: string[];
|
|
12
|
-
/**
|
|
13
|
-
* 값 변경 시 호출
|
|
14
|
-
*/
|
|
15
|
-
onChange: (v: string[]) => void;
|
|
16
|
-
/**
|
|
17
|
-
* 다중 선택 여부
|
|
18
|
-
* @default false
|
|
19
|
-
*/
|
|
20
|
-
multiple?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Select.Trigger / Select.Options 등을 포함하는 children
|
|
23
|
-
*/
|
|
24
|
-
children: ReactNode;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Options 컨테이너 props
|
|
28
|
-
*/
|
|
29
|
-
export interface SelectOptionsProps extends HTMLProps<HTMLDivElement> {
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 개별 Option props
|
|
33
|
-
*/
|
|
34
|
-
export interface SelectOptionProps extends HTMLProps<HTMLDivElement> {
|
|
35
|
-
/**
|
|
36
|
-
* 옵션의 실제 값
|
|
37
|
-
*/
|
|
38
|
-
value: string;
|
|
39
|
-
/**
|
|
40
|
-
* 비활성화 여부
|
|
41
|
-
*/
|
|
42
|
-
disabled?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* 표시될 내용
|
|
45
|
-
*/
|
|
46
|
-
children: ReactNode;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Trigger 버튼 props
|
|
50
|
-
*/
|
|
51
|
-
export interface SelectTriggerProps extends HTMLProps<HTMLDivElement> {
|
|
52
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TooltipProps } from './Tooltip.type';
|
|
2
|
-
/**
|
|
3
|
-
* 범용 Tooltip 컴포넌트
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* <Tooltip popover="안녕하세요" direction="top">
|
|
7
|
-
* <button>Hover me</button>
|
|
8
|
-
* </Tooltip>
|
|
9
|
-
*/
|
|
10
|
-
export declare const Tooltip: ({ direction, popover, children, key, gap, autoFlip }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var usePortal = require('../hooks/usePortal.js');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 범용 Tooltip 컴포넌트
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* <Tooltip popover="안녕하세요" direction="top">
|
|
12
|
-
* <button>Hover me</button>
|
|
13
|
-
* </Tooltip>
|
|
14
|
-
*/
|
|
15
|
-
const Tooltip = ({ direction = 'top', popover, children, key, gap = 0, autoFlip = true }) => {
|
|
16
|
-
const [visible, setVisible] = react.useState(false);
|
|
17
|
-
const targetRef = react.useRef(null);
|
|
18
|
-
const popoverRef = react.useRef(null);
|
|
19
|
-
const { portal, rootDom } = usePortal({
|
|
20
|
-
content: popover,
|
|
21
|
-
key,
|
|
22
|
-
visible,
|
|
23
|
-
targetRef,
|
|
24
|
-
popoverRef,
|
|
25
|
-
direction,
|
|
26
|
-
gap,
|
|
27
|
-
autoFlip,
|
|
28
|
-
});
|
|
29
|
-
const handleMouseEnter = () => {
|
|
30
|
-
setVisible(true);
|
|
31
|
-
};
|
|
32
|
-
const handleMouseLeave = () => {
|
|
33
|
-
setVisible(false);
|
|
34
|
-
};
|
|
35
|
-
return (jsxRuntime.jsxs("span", { onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, ref: targetRef, children: [children, rootDom && visible && portal] }));
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
exports.Tooltip = Tooltip;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { Direction } from '../hooks';
|
|
3
|
-
export interface TooltipProps {
|
|
4
|
-
/** 툴팁을 띄울 대상 요소 */
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
/** 툴팁에 표시될 내용 */
|
|
7
|
-
popover: ReactNode;
|
|
8
|
-
/** 툴팁이 나타날 방향 */
|
|
9
|
-
direction: Direction;
|
|
10
|
-
/** 특정 DOM 타겟 ID (선택) */
|
|
11
|
-
targetId?: string;
|
|
12
|
-
/** 포털로 렌더링할 DOM 노드 */
|
|
13
|
-
domNode?: Element;
|
|
14
|
-
/** React key 값 */
|
|
15
|
-
key?: string;
|
|
16
|
-
/** 타겟과 툴팁 사이 간격(px) */
|
|
17
|
-
gap?: number;
|
|
18
|
-
/** 화면 밖으로 나가면 자동 반전 여부 */
|
|
19
|
-
autoFlip?: boolean;
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useDebounce: (callback: (...args: any[]) => void, delay: number) => (...args: any[]) => void;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
const useDebounce = (callback, delay) => {
|
|
6
|
-
const timeoutRef = react.useRef(0);
|
|
7
|
-
react.useEffect(() => {
|
|
8
|
-
return () => {
|
|
9
|
-
if (timeoutRef.current) {
|
|
10
|
-
clearTimeout(timeoutRef.current);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}, []);
|
|
14
|
-
return react.useCallback((...args) => {
|
|
15
|
-
if (timeoutRef.current) {
|
|
16
|
-
clearTimeout(timeoutRef.current);
|
|
17
|
-
}
|
|
18
|
-
timeoutRef.current = setTimeout(() => {
|
|
19
|
-
callback(...args);
|
|
20
|
-
}, delay);
|
|
21
|
-
}, [callback, delay]);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
exports.useDebounce = useDebounce;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Key, ReactNode, RefObject } from 'react';
|
|
2
|
-
type Position = {
|
|
3
|
-
top: number;
|
|
4
|
-
left: number;
|
|
5
|
-
};
|
|
6
|
-
export type Direction = 'top-left' | 'top-center' | 'top' | 'top-right' | 'left' | 'right' | 'bottom-left' | 'bottom' | 'bottom-center' | 'bottom-right';
|
|
7
|
-
type UsePortalProps = {
|
|
8
|
-
content: ReactNode;
|
|
9
|
-
key?: Key | null;
|
|
10
|
-
visible?: boolean;
|
|
11
|
-
targetRef?: RefObject<HTMLElement | null>;
|
|
12
|
-
popoverRef?: RefObject<HTMLElement | null>;
|
|
13
|
-
direction?: Direction;
|
|
14
|
-
gap?: number;
|
|
15
|
-
position?: Position;
|
|
16
|
-
autoFlip?: boolean;
|
|
17
|
-
};
|
|
18
|
-
declare const usePortal: ({ content, key, visible, targetRef, popoverRef, direction, gap, position: customPosition, autoFlip, }: UsePortalProps) => {
|
|
19
|
-
portal: import("react").ReactPortal;
|
|
20
|
-
rootDom: HTMLElement;
|
|
21
|
-
finalDirection: Direction;
|
|
22
|
-
};
|
|
23
|
-
export default usePortal;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var reactDom = require('react-dom');
|
|
6
|
-
|
|
7
|
-
const usePortal = ({ content, key, visible = true, targetRef, popoverRef, direction = 'top', gap = 0, position: customPosition, autoFlip = true, }) => {
|
|
8
|
-
const rootDom = react.useMemo(() => document.body, []);
|
|
9
|
-
const [position, setPosition] = react.useState(customPosition || { top: 0, left: 0 });
|
|
10
|
-
const [finalDirection, setFinalDirection] = react.useState(direction);
|
|
11
|
-
const getOppositeDirection = (dir) => {
|
|
12
|
-
if (dir.startsWith('top'))
|
|
13
|
-
return dir.replace('top', 'bottom');
|
|
14
|
-
if (dir.startsWith('bottom'))
|
|
15
|
-
return dir.replace('bottom', 'top');
|
|
16
|
-
if (dir === 'left')
|
|
17
|
-
return 'right';
|
|
18
|
-
if (dir === 'right')
|
|
19
|
-
return 'left';
|
|
20
|
-
return dir;
|
|
21
|
-
};
|
|
22
|
-
const getPopoverPosition = (targetRect, popoverRect, dir) => {
|
|
23
|
-
let top = (dir.startsWith('top')
|
|
24
|
-
? targetRect.top - popoverRect.height
|
|
25
|
-
: dir.startsWith('bottom')
|
|
26
|
-
? targetRect.top + targetRect.height
|
|
27
|
-
: targetRect.top + targetRect.height / 2 - popoverRect.height / 2) - gap;
|
|
28
|
-
let left = dir.endsWith('left')
|
|
29
|
-
? targetRect.left - popoverRect.width - gap
|
|
30
|
-
: (dir.endsWith('right')
|
|
31
|
-
? targetRect.left + targetRect.width + gap
|
|
32
|
-
: targetRect.left + targetRect.width / 2 - popoverRect.width / 2);
|
|
33
|
-
return { top, left };
|
|
34
|
-
};
|
|
35
|
-
const isOutOfViewport = (pos, popoverRect) => {
|
|
36
|
-
const viewportWidth = window.innerWidth;
|
|
37
|
-
const viewportHeight = window.innerHeight;
|
|
38
|
-
return (pos.top < 0 || // 상단 밖
|
|
39
|
-
pos.left < 0 || // 좌측 밖
|
|
40
|
-
pos.top + popoverRect.height > viewportHeight + window.scrollY || // 하단 밖
|
|
41
|
-
pos.left + popoverRect.width > viewportWidth + window.scrollX // 우측 밖
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
react.useLayoutEffect(() => {
|
|
45
|
-
if (visible && targetRef?.current && popoverRef?.current) {
|
|
46
|
-
const targetRect = targetRef.current.getBoundingClientRect();
|
|
47
|
-
const popoverRect = popoverRef.current.getBoundingClientRect();
|
|
48
|
-
// 원래 방향으로 위치 계산
|
|
49
|
-
let calculatedPosition = getPopoverPosition(targetRect, popoverRect, direction);
|
|
50
|
-
let currentDirection = direction;
|
|
51
|
-
// autoFlip이 활성화되어 있고 화면 밖으로 나가면 반대 방향 시도
|
|
52
|
-
if (autoFlip && isOutOfViewport(calculatedPosition, popoverRect)) {
|
|
53
|
-
const oppositeDir = getOppositeDirection(direction);
|
|
54
|
-
const oppositePosition = getPopoverPosition(targetRect, popoverRect, oppositeDir);
|
|
55
|
-
// 반대 방향이 더 나으면 반대 방향 사용
|
|
56
|
-
if (!isOutOfViewport(oppositePosition, popoverRect)) {
|
|
57
|
-
calculatedPosition = oppositePosition;
|
|
58
|
-
currentDirection = oppositeDir;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
setFinalDirection(currentDirection);
|
|
62
|
-
setPosition({
|
|
63
|
-
top: calculatedPosition.top + window.scrollY,
|
|
64
|
-
left: calculatedPosition.left + window.scrollX,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
else if (customPosition) {
|
|
68
|
-
setPosition(customPosition);
|
|
69
|
-
}
|
|
70
|
-
}, [visible, direction, gap, customPosition, autoFlip]);
|
|
71
|
-
const wrappedContent = targetRef ? (jsxRuntime.jsx("span", { ref: popoverRef, style: {
|
|
72
|
-
position: 'absolute',
|
|
73
|
-
top: `${position.top}px`,
|
|
74
|
-
left: `${position.left}px`,
|
|
75
|
-
}, children: content })) : content;
|
|
76
|
-
const portal = reactDom.createPortal(wrappedContent, rootDom, key);
|
|
77
|
-
return { portal, rootDom, finalDirection };
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
module.exports = usePortal;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useThrottle: (callback: (...args: any[]) => void, delay: number) => (...args: any[]) => void;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
|
-
const useThrottle = (callback, delay) => {
|
|
6
|
-
const lastRun = react.useRef(Date.now());
|
|
7
|
-
const timeoutRef = react.useRef(0);
|
|
8
|
-
react.useEffect(() => {
|
|
9
|
-
return () => {
|
|
10
|
-
if (timeoutRef.current) {
|
|
11
|
-
clearTimeout(timeoutRef.current);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}, []);
|
|
15
|
-
return react.useCallback((...args) => {
|
|
16
|
-
const now = Date.now();
|
|
17
|
-
const timeSinceLastRun = now - lastRun.current;
|
|
18
|
-
if (timeSinceLastRun >= delay) {
|
|
19
|
-
callback(...args);
|
|
20
|
-
lastRun.current = now;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
if (timeoutRef.current) {
|
|
24
|
-
clearTimeout(timeoutRef.current);
|
|
25
|
-
}
|
|
26
|
-
timeoutRef.current = setTimeout(() => {
|
|
27
|
-
callback(...args);
|
|
28
|
-
lastRun.current = Date.now();
|
|
29
|
-
}, delay - timeSinceLastRun);
|
|
30
|
-
}
|
|
31
|
-
}, [callback, delay]);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
exports.useThrottle = useThrottle;
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('react/jsx-runtime');
|
|
4
|
-
require('react');
|
|
5
|
-
require('react-dom');
|
|
6
|
-
var useDebounce = require('./hooks/useDebounce.js');
|
|
7
|
-
var useThrottle = require('./hooks/useThrottle.js');
|
|
8
|
-
var Tooltip = require('./Tooltip/Tooltip.js');
|
|
9
|
-
var NumberInput = require('./Input/NumberInput.js');
|
|
10
|
-
var TextInput = require('./Input/TextInput.js');
|
|
11
|
-
var Select = require('./Select/Select.js');
|
|
12
|
-
var Autocomplete = require('./Autocomplete/Autocomplete.js');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.useDebounce = useDebounce.useDebounce;
|
|
17
|
-
exports.useThrottle = useThrottle.useThrottle;
|
|
18
|
-
exports.Tooltip = Tooltip.Tooltip;
|
|
19
|
-
exports.NumberInput = NumberInput.NumberInput;
|
|
20
|
-
exports.TextInput = TextInput.TextInput;
|
|
21
|
-
exports.Select = Select.Select;
|
|
22
|
-
exports.useSelectContext = Select.useSelectContext;
|
|
23
|
-
exports.Autocomplete = Autocomplete.Autocomplete;
|