@alifd/chat 0.0.1

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.
Files changed (106) hide show
  1. package/README.md +1 -0
  2. package/es/button/index.d.ts +1 -0
  3. package/es/button/index.js +1 -0
  4. package/es/button/main.scss +0 -0
  5. package/es/button/style.d.ts +1 -0
  6. package/es/button/style.js +1 -0
  7. package/es/button/types.d.ts +123 -0
  8. package/es/button/types.js +1 -0
  9. package/es/button/view/button.d.ts +23 -0
  10. package/es/button/view/button.js +26 -0
  11. package/es/float-button/hooks/useAutoAlign.d.ts +11 -0
  12. package/es/float-button/hooks/useAutoAlign.js +45 -0
  13. package/es/float-button/hooks/useAutoHide.d.ts +15 -0
  14. package/es/float-button/hooks/useAutoHide.js +157 -0
  15. package/es/float-button/hooks/useDragable.d.ts +9 -0
  16. package/es/float-button/hooks/useDragable.js +128 -0
  17. package/es/float-button/hooks/useNestleEdge.d.ts +13 -0
  18. package/es/float-button/hooks/useNestleEdge.js +77 -0
  19. package/es/float-button/index.d.ts +6 -0
  20. package/es/float-button/index.js +5 -0
  21. package/es/float-button/main.scss +16 -0
  22. package/es/float-button/style.d.ts +2 -0
  23. package/es/float-button/style.js +2 -0
  24. package/es/float-button/types.d.ts +225 -0
  25. package/es/float-button/types.js +1 -0
  26. package/es/float-button/util.d.ts +8 -0
  27. package/es/float-button/util.js +67 -0
  28. package/es/float-button/view/backtop.d.ts +4 -0
  29. package/es/float-button/view/backtop.js +73 -0
  30. package/es/float-button/view/balloon.d.ts +8 -0
  31. package/es/float-button/view/balloon.js +12 -0
  32. package/es/float-button/view/drawer.d.ts +2 -0
  33. package/es/float-button/view/drawer.js +4 -0
  34. package/es/float-button/view/float-button.d.ts +4 -0
  35. package/es/float-button/view/float-button.js +117 -0
  36. package/es/float-button/view/inner-drawer.d.ts +2 -0
  37. package/es/float-button/view/inner-drawer.js +4 -0
  38. package/es/index.d.ts +2 -0
  39. package/es/index.js +2 -0
  40. package/es/utils/common.d.ts +2 -0
  41. package/es/utils/common.js +8 -0
  42. package/es/utils/func.d.ts +3 -0
  43. package/es/utils/func.js +30 -0
  44. package/es/utils/hooks/useControlable.d.ts +6 -0
  45. package/es/utils/hooks/useControlable.js +27 -0
  46. package/es/utils/hooks/useDebounce.d.ts +2 -0
  47. package/es/utils/hooks/useDebounce.js +9 -0
  48. package/es/utils/hooks/useThrottle.d.ts +2 -0
  49. package/es/utils/hooks/useThrottle.js +9 -0
  50. package/es/utils/index.d.ts +6 -0
  51. package/es/utils/index.js +6 -0
  52. package/es/utils/types.d.ts +2 -0
  53. package/es/utils/types.js +1 -0
  54. package/lib/button/index.d.ts +1 -0
  55. package/lib/button/index.js +8 -0
  56. package/lib/button/main.scss +0 -0
  57. package/lib/button/style.d.ts +1 -0
  58. package/lib/button/style.js +3 -0
  59. package/lib/button/types.d.ts +123 -0
  60. package/lib/button/types.js +2 -0
  61. package/lib/button/view/button.d.ts +23 -0
  62. package/lib/button/view/button.js +29 -0
  63. package/lib/float-button/hooks/useAutoAlign.d.ts +11 -0
  64. package/lib/float-button/hooks/useAutoAlign.js +49 -0
  65. package/lib/float-button/hooks/useAutoHide.d.ts +15 -0
  66. package/lib/float-button/hooks/useAutoHide.js +161 -0
  67. package/lib/float-button/hooks/useDragable.d.ts +9 -0
  68. package/lib/float-button/hooks/useDragable.js +132 -0
  69. package/lib/float-button/hooks/useNestleEdge.d.ts +13 -0
  70. package/lib/float-button/hooks/useNestleEdge.js +81 -0
  71. package/lib/float-button/index.d.ts +6 -0
  72. package/lib/float-button/index.js +8 -0
  73. package/lib/float-button/main.scss +16 -0
  74. package/lib/float-button/style.d.ts +2 -0
  75. package/lib/float-button/style.js +4 -0
  76. package/lib/float-button/types.d.ts +225 -0
  77. package/lib/float-button/types.js +2 -0
  78. package/lib/float-button/util.d.ts +8 -0
  79. package/lib/float-button/util.js +74 -0
  80. package/lib/float-button/view/backtop.d.ts +4 -0
  81. package/lib/float-button/view/backtop.js +76 -0
  82. package/lib/float-button/view/balloon.d.ts +8 -0
  83. package/lib/float-button/view/balloon.js +16 -0
  84. package/lib/float-button/view/drawer.d.ts +2 -0
  85. package/lib/float-button/view/drawer.js +9 -0
  86. package/lib/float-button/view/float-button.d.ts +4 -0
  87. package/lib/float-button/view/float-button.js +119 -0
  88. package/lib/float-button/view/inner-drawer.d.ts +2 -0
  89. package/lib/float-button/view/inner-drawer.js +9 -0
  90. package/lib/index.d.ts +2 -0
  91. package/lib/index.js +9 -0
  92. package/lib/utils/common.d.ts +2 -0
  93. package/lib/utils/common.js +12 -0
  94. package/lib/utils/func.d.ts +3 -0
  95. package/lib/utils/func.js +35 -0
  96. package/lib/utils/hooks/useControlable.d.ts +6 -0
  97. package/lib/utils/hooks/useControlable.js +31 -0
  98. package/lib/utils/hooks/useDebounce.d.ts +2 -0
  99. package/lib/utils/hooks/useDebounce.js +13 -0
  100. package/lib/utils/hooks/useThrottle.d.ts +2 -0
  101. package/lib/utils/hooks/useThrottle.js +13 -0
  102. package/lib/utils/index.d.ts +6 -0
  103. package/lib/utils/index.js +13 -0
  104. package/lib/utils/types.d.ts +2 -0
  105. package/lib/utils/types.js +2 -0
  106. package/package.json +103 -0
@@ -0,0 +1,16 @@
1
+ @import '~@alifd/next/variables.scss';
2
+
3
+ .#{$css-prefix}float-button {
4
+ position: fixed;
5
+ z-index: 1001;
6
+
7
+ &-backtop {
8
+ transition: opacity 0.2s, transform 0.2s;
9
+ cursor: pointer;
10
+
11
+ &--hidden {
12
+ opacity: 0;
13
+ transform: scale(0);
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ import '@alifd/next/lib/balloon/style';
2
+ import './main.scss';
@@ -0,0 +1,2 @@
1
+ import '@alifd/next/lib/balloon/style';
2
+ import './main.scss';
@@ -0,0 +1,225 @@
1
+ import type React from 'react';
2
+ import { type CommonProps } from '@alifd/next';
3
+ import { type BalloonProps } from '@alifd/next/lib/balloon';
4
+ export type { BalloonProps };
5
+ /**
6
+ * @api
7
+ */
8
+ export type ScreenRatioPosition = [widthRatio: number, heightRatio: number];
9
+ /**
10
+ * @api
11
+ */
12
+ export type Edge = 'top' | 'right' | 'bottom' | 'left';
13
+ /**
14
+ * @api
15
+ */
16
+ export type Position = {
17
+ left: number;
18
+ top: number;
19
+ };
20
+ /**
21
+ * @api
22
+ */
23
+ export type Size = {
24
+ width: number;
25
+ height: number;
26
+ };
27
+ /**
28
+ * @api
29
+ */
30
+ export type Margin = [top: number, right: number, bottom: number, left: number];
31
+ /**
32
+ * 回到顶部组件 ref 对象
33
+ * @api
34
+ * @order 4
35
+ */
36
+ export interface BacktopRef {
37
+ /**
38
+ * 滚动到顶部
39
+ */
40
+ backToTop(): void;
41
+ /**
42
+ * 设置是否隐藏
43
+ * @param isHide - 是否隐藏
44
+ * @param force - 强制设置,忽略此时的滚动位置
45
+ */
46
+ setHide(isHide: boolean, force?: boolean): void;
47
+ }
48
+ /**
49
+ * 回到顶部组件
50
+ * @api FloatButton.Backtop
51
+ * @order 3
52
+ */
53
+ export interface BacktopProps extends CommonProps {
54
+ /**
55
+ * 滚动到顶部自动隐藏
56
+ * @defaultValue true
57
+ */
58
+ autoHide?: boolean;
59
+ /**
60
+ * 内容
61
+ */
62
+ children: React.ReactNode;
63
+ /**
64
+ * 可触发隐藏的偏移距离 px
65
+ * @defaultValue 10
66
+ */
67
+ offset?: number;
68
+ /**
69
+ * 滚动节点
70
+ * @defaultValue window
71
+ */
72
+ scroller?: string | HTMLElement;
73
+ /**
74
+ * 采用平滑滚动
75
+ * @defaultValue true
76
+ */
77
+ smooth?: boolean;
78
+ }
79
+ /**
80
+ * 悬浮球组件 ref 对象
81
+ * @api
82
+ * @order 2
83
+ */
84
+ export interface FloatButtonRef {
85
+ /**
86
+ * 设置是否展示弹窗
87
+ */
88
+ setVisible(visible: boolean): void;
89
+ /**
90
+ * 根据当前位置更新弹窗的 align 位置
91
+ */
92
+ updateAlign(): void;
93
+ /**
94
+ * 设置是否隐藏悬浮球
95
+ */
96
+ setHide(isHide: boolean): void;
97
+ /**
98
+ * 是悬浮球吸附到最近的屏幕边缘
99
+ * @param animation - 是否开启动画,默认为 true
100
+ */
101
+ updateNestleEdge(animation?: boolean): void;
102
+ }
103
+ /**
104
+ * @api FloatButton
105
+ * @order 1
106
+ */
107
+ export interface FloatButtonProps extends CommonProps {
108
+ className?: string;
109
+ style?: React.CSSProperties;
110
+ /**
111
+ * 面板展示类型
112
+ * @defaultValue 'balloon'
113
+ * @example
114
+ * - `balloon`: 悬浮面板
115
+ * - `drawer`: 悬浮侧边抽屉
116
+ * - `inner-drawer`: 文档内部抽屉
117
+ */
118
+ type?: 'balloon' | 'drawer' | 'inner-drawer';
119
+ /**
120
+ * 弹层位置,适用 `type`: 'balloon'
121
+ */
122
+ align?: BalloonProps['align'];
123
+ /**
124
+ * 自动设置弹层位置,适用 `type`: 'balloon'
125
+ */
126
+ autoAlign?: boolean;
127
+ /**
128
+ * 抽屉位置,适用 `type`: 'drawer' | 'inner-drawer'
129
+ */
130
+ placement?: 'top' | 'right' | 'bottom' | 'left';
131
+ /**
132
+ * 是否显示弹层(受控模式)
133
+ */
134
+ visible?: boolean;
135
+ /**
136
+ * 是否默认展示弹层(非受控模式)
137
+ */
138
+ defaultVisible?: boolean;
139
+ /**
140
+ * 弹层展示状态变化事件
141
+ */
142
+ onVisibleChange?: BalloonProps['onVisibleChange'];
143
+ /**
144
+ * 前置添加内容
145
+ */
146
+ addonBefore?: React.ReactNode;
147
+ /**
148
+ * 后置添加内容
149
+ */
150
+ addonAfter?: React.ReactNode;
151
+ /**
152
+ * 是否可拖拽
153
+ */
154
+ dragable?: boolean;
155
+ /**
156
+ * 拖拽安全区边距
157
+ * @defaultValue [10, 10, 10, 10]
158
+ */
159
+ safeAreaMargin?: Margin;
160
+ /**
161
+ * 默认位置
162
+ */
163
+ defaultPosition?: {
164
+ top?: number | string;
165
+ right?: number | string;
166
+ bottom?: number | string;
167
+ left?: number | string;
168
+ } | ScreenRatioPosition;
169
+ /**
170
+ * 是否自动吸附屏幕边缘
171
+ * @defaultValue true
172
+ */
173
+ autoNestleEdge?: boolean;
174
+ /**
175
+ * 在屏幕边缘时是否自动隐藏
176
+ */
177
+ autoHide?: boolean;
178
+ /**
179
+ * 隐藏时留在屏幕内的尺寸
180
+ */
181
+ leftSizeOfHidden?: number;
182
+ /**
183
+ * 可交互的边缘,适用于 autoNestleEdge、autoHide
184
+ * @defaultValue ['left', 'right']
185
+ */
186
+ interactiveEdges?: Edge[];
187
+ /**
188
+ * 触发节点
189
+ */
190
+ trigger: NonNullable<BalloonProps['trigger']>;
191
+ /**
192
+ * 隐藏时的触发节点,默认为 trigger
193
+ */
194
+ hiddenTrigger?: BalloonProps['trigger'];
195
+ /**
196
+ * 触发方式
197
+ * @defaultValue 'click'
198
+ */
199
+ triggerType?: BalloonProps['triggerType'];
200
+ /**
201
+ * 展示关闭按钮
202
+ * @defaultValue false
203
+ */
204
+ showClose?: boolean;
205
+ /**
206
+ * 弹层组件其它参数
207
+ */
208
+ balloonProps?: BalloonProps;
209
+ /**
210
+ * 弹层内容
211
+ */
212
+ children?: React.ReactNode;
213
+ }
214
+ /**
215
+ * @api
216
+ * @order 5
217
+ */
218
+ export interface DragableOption {
219
+ enable?: boolean;
220
+ defaultPosition?: FloatButtonProps['defaultPosition'];
221
+ safeAreaMargin?: Margin;
222
+ onDragBefore?: (dom: HTMLElement) => void;
223
+ onDraging?: (dom: HTMLElement, event: MouseEvent) => void | false;
224
+ onDragend?: (dom: HTMLElement) => void;
225
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Edge, Margin, Position } from './types';
2
+ export declare function getScreenSize(): {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export declare function getNearlyEdge(el: HTMLElement, interactiveEdges?: Edge[], rect?: DOMRect): [] | [nearestEdge: Edge, subNearestEdge?: Edge];
7
+ export declare function isInScreen(dom: HTMLElement): boolean;
8
+ export declare function adjustBySafeAreaMargin(position: Position | undefined, rect: DOMRect | null, safeAreaMargin?: Margin): Position | undefined;
@@ -0,0 +1,67 @@
1
+ export function getScreenSize() {
2
+ return {
3
+ width: document.documentElement.clientWidth,
4
+ height: document.documentElement.clientHeight,
5
+ };
6
+ }
7
+ export function getNearlyEdge(el, interactiveEdges, rect = el.getBoundingClientRect()) {
8
+ if (!(interactiveEdges === null || interactiveEdges === void 0 ? void 0 : interactiveEdges.length)) {
9
+ return [];
10
+ }
11
+ const edgeSet = new Set(interactiveEdges);
12
+ if (edgeSet.size === 1) {
13
+ return [interactiveEdges[0]];
14
+ }
15
+ const { left, top, width, height } = rect;
16
+ const { width: screenWidth, height: screenHeight } = getScreenSize();
17
+ const edgeItems = [
18
+ {
19
+ edge: 'left',
20
+ size: left + width / 2,
21
+ },
22
+ {
23
+ edge: 'top',
24
+ size: top + height / 2,
25
+ },
26
+ {
27
+ edge: 'right',
28
+ size: screenWidth - left - width / 2,
29
+ },
30
+ {
31
+ edge: 'bottom',
32
+ size: screenHeight - top - height / 2,
33
+ },
34
+ ];
35
+ const [closest, subClosest] = edgeItems
36
+ .filter(t => edgeSet.has(t.edge))
37
+ .sort((a, b) => (a.size > b.size ? 1 : -1));
38
+ return [closest.edge, subClosest === null || subClosest === void 0 ? void 0 : subClosest.edge];
39
+ }
40
+ export function isInScreen(dom) {
41
+ const rect = dom.getBoundingClientRect();
42
+ const { width, height } = getScreenSize();
43
+ const { left, top } = rect;
44
+ const right = width - rect.left - rect.width;
45
+ const bottom = height - rect.top - rect.height;
46
+ return [left, top, right, bottom].every(n => n >= 0);
47
+ }
48
+ export function adjustBySafeAreaMargin(position, rect, safeAreaMargin) {
49
+ if (!position || !rect || !safeAreaMargin) {
50
+ return undefined;
51
+ }
52
+ const [top, right, bottom, left] = safeAreaMargin;
53
+ const { width, height } = getScreenSize();
54
+ const makeInRange = (num, min, max) => {
55
+ if (num < min) {
56
+ return min;
57
+ }
58
+ if (num > max) {
59
+ return max;
60
+ }
61
+ return num;
62
+ };
63
+ return {
64
+ left: makeInRange(position.left, Math.max(0, left), Math.min(width, width - rect.width - right)),
65
+ top: makeInRange(position.top, Math.max(0, top), Math.min(height, height - rect.height - bottom)),
66
+ };
67
+ }
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { BacktopProps, BacktopRef } from '../types';
3
+ declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<BacktopProps & React.RefAttributes<BacktopRef>, "key" | keyof BacktopProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, BacktopRef, {}>;
4
+ export default _default;
@@ -0,0 +1,73 @@
1
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
2
+ import { ConfigProvider } from '@alifd/next';
3
+ import cs from 'classnames';
4
+ import { debounce } from '../../utils';
5
+ function getScroller(scroller) {
6
+ if (!scroller) {
7
+ return window;
8
+ }
9
+ if (typeof scroller === 'string') {
10
+ return document.getElementById(scroller);
11
+ }
12
+ return scroller;
13
+ }
14
+ const Backtop = forwardRef(({ prefix = 'next-', autoHide = true, scroller, offset = 10, smooth = true, children }, ref) => {
15
+ const [visible, setVisible] = useState(true);
16
+ const cls = `${prefix}float-button-backtop`;
17
+ const visibleRef = useRef(visible);
18
+ visibleRef.current = visible;
19
+ const handleBackToTop = () => {
20
+ var _a;
21
+ if (!visible) {
22
+ return;
23
+ }
24
+ (_a = getScroller(scroller)) === null || _a === void 0 ? void 0 : _a.scrollTo({ top: 0, behavior: smooth ? 'smooth' : 'auto' });
25
+ };
26
+ const isAtTop = (el = window) => {
27
+ if (el === window) {
28
+ return el.scrollY <= offset;
29
+ }
30
+ if (el instanceof HTMLElement) {
31
+ return el.scrollTop <= offset;
32
+ }
33
+ return false;
34
+ };
35
+ useImperativeHandle(ref, () => ({
36
+ backToTop: handleBackToTop,
37
+ setHide(isHide, force) {
38
+ let vis = !isHide;
39
+ if (!force && vis && isAtTop(getScroller(scroller))) {
40
+ vis = false;
41
+ }
42
+ if (vis !== visible) {
43
+ setVisible(vis);
44
+ }
45
+ },
46
+ }));
47
+ useEffect(() => {
48
+ if (!autoHide) {
49
+ if (!visible) {
50
+ setVisible(true);
51
+ }
52
+ return;
53
+ }
54
+ const target = getScroller(scroller);
55
+ if (!target) {
56
+ return;
57
+ }
58
+ const onScroll = debounce(() => {
59
+ if (isAtTop(target)) {
60
+ visibleRef.current && setVisible(false);
61
+ }
62
+ else {
63
+ !visibleRef.current && setVisible(true);
64
+ }
65
+ }, 100);
66
+ window.addEventListener('scroll', onScroll);
67
+ return () => {
68
+ target.removeEventListener('scroll', onScroll);
69
+ };
70
+ }, [scroller, autoHide, offset]);
71
+ return (React.createElement("button", { className: cs(cls, { [`${cls}--hidden`]: !visible }), onClick: handleBackToTop }, children));
72
+ });
73
+ export default ConfigProvider.config(Backtop);
@@ -0,0 +1,8 @@
1
+ import React, { type ComponentProps } from 'react';
2
+ import { Balloon as NextBalloon } from '@alifd/next';
3
+ export declare function Balloon(props: ComponentProps<typeof NextBalloon> & {
4
+ cls: string;
5
+ triggerEl: HTMLElement | null;
6
+ el: HTMLElement | null;
7
+ autoAlign?: boolean;
8
+ }): React.JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { __rest } from "tslib";
2
+ import React from 'react';
3
+ import { Balloon as NextBalloon } from '@alifd/next';
4
+ import { useAutoAlign } from '../hooks/useAutoAlign';
5
+ export function Balloon(props) {
6
+ const { triggerEl, el, autoAlign, align, cls } = props, rests = __rest(props, ["triggerEl", "el", "autoAlign", "align", "cls"]);
7
+ const { align: currentAlign } = useAutoAlign(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`), triggerEl, {
8
+ enable: autoAlign,
9
+ defaultAlign: align,
10
+ });
11
+ return React.createElement(NextBalloon, Object.assign({}, rests, { align: currentAlign }));
12
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function Drawer(): React.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export function Drawer() {
3
+ return (React.createElement("div", null, "drawer"));
4
+ }
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { FloatButtonProps, FloatButtonRef } from '../types';
3
+ declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<FloatButtonProps & React.RefAttributes<FloatButtonRef>, keyof FloatButtonProps | "key"> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, FloatButtonRef, {}>;
4
+ export default _default;
@@ -0,0 +1,117 @@
1
+ import { __rest } from "tslib";
2
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
3
+ import cs from 'classnames';
4
+ import { Balloon, ConfigProvider } from '@alifd/next';
5
+ import { useControlable } from '../../utils/index';
6
+ import { useAutoHide } from '../hooks/useAutoHide';
7
+ import { useAutoAlign } from '../hooks/useAutoAlign';
8
+ import { useNestleEdge } from '../hooks/useNestleEdge';
9
+ import { useDragable } from '../hooks/useDragable';
10
+ const FloatButton = forwardRef((_a, ref) => {
11
+ var { className, style, prefix = 'next-', type = 'balloon', addonAfter, addonBefore, dragable, safeAreaMargin = [10, 10, 10, 10], autoNestleEdge = true, interactiveEdges = ['left', 'right'], autoHide, autoAlign, leftSizeOfHidden, defaultPosition, trigger, triggerType = 'click', showClose = false, align, balloonProps, children } = _a, others = __rest(_a, ["className", "style", "prefix", "type", "addonAfter", "addonBefore", "dragable", "safeAreaMargin", "autoNestleEdge", "interactiveEdges", "autoHide", "autoAlign", "leftSizeOfHidden", "defaultPosition", "trigger", "triggerType", "showClose", "align", "balloonProps", "children"]);
12
+ const elRef = useRef(null);
13
+ const triggerRef = useRef(null);
14
+ const [el, setEl] = useState(null);
15
+ const [triggerEl, setTriggerEl] = useState(null);
16
+ const draggedRef = useRef(false);
17
+ const cls = `${prefix}float-button`;
18
+ const [visible, onVisibleChange] = useControlable(others, {
19
+ valueName: 'visible',
20
+ changeName: 'onVisibleChange',
21
+ });
22
+ useEffect(() => {
23
+ setEl(elRef.current);
24
+ setTriggerEl(triggerRef.current);
25
+ }, []);
26
+ const { align: currentAlign, update: updateAlign } = useAutoAlign(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`), triggerEl, {
27
+ enable: type === 'balloon' && autoAlign,
28
+ defaultAlign: align,
29
+ });
30
+ const { isHideRef, setHide, handleMove, saveRestorePosition } = useAutoHide(el, {
31
+ enable: !visible && autoHide,
32
+ interactiveEdges,
33
+ leftSize: leftSizeOfHidden,
34
+ });
35
+ useEffect(() => {
36
+ if (visible) {
37
+ setHide(false);
38
+ updateAlign();
39
+ }
40
+ }, [visible]);
41
+ const { update: updateNestleEdge } = useNestleEdge(el, {
42
+ enable: !!autoNestleEdge,
43
+ safeAreaMargin,
44
+ interactiveEdges,
45
+ onUpdate(position) {
46
+ if (isHideRef.current) {
47
+ saveRestorePosition(position);
48
+ return false;
49
+ }
50
+ },
51
+ });
52
+ useImperativeHandle(ref, () => ({
53
+ setVisible(value) {
54
+ onVisibleChange(value, 'api');
55
+ },
56
+ setHide(isHide) {
57
+ setHide(isHide);
58
+ },
59
+ updateAlign,
60
+ updateNestleEdge,
61
+ }));
62
+ const { className: dragClassName, style: dragStyle } = useDragable(el, {
63
+ enable: dragable,
64
+ safeAreaMargin,
65
+ defaultPosition,
66
+ onDragBefore() {
67
+ draggedRef.current = false;
68
+ },
69
+ onDraging(_, e) {
70
+ draggedRef.current = true;
71
+ updateAlign();
72
+ handleMove(e);
73
+ if (isHideRef.current) {
74
+ return false;
75
+ }
76
+ },
77
+ onDragend() {
78
+ if (!isHideRef.current) {
79
+ Promise.resolve().then(() => updateNestleEdge());
80
+ }
81
+ },
82
+ });
83
+ const classNames = cs(cls, className, dragClassName);
84
+ const renderBalloon = () => {
85
+ return (React.createElement(Balloon, Object.assign({ visible: visible, onVisibleChange: (...args) => {
86
+ if (draggedRef.current) {
87
+ return;
88
+ }
89
+ onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(...args);
90
+ }, popupClassName: `${cls}-popup`, trigger: trigger, popupContainer: () => el, triggerType: triggerType, align: currentAlign, v2: true, closable: showClose, autoAdjust: false }, balloonProps), children));
91
+ };
92
+ const renderDrawer = () => {
93
+ return React.createElement("div", null);
94
+ };
95
+ const renderInnerDrawer = () => {
96
+ return React.createElement("div", null);
97
+ };
98
+ const renderView = () => {
99
+ switch (type) {
100
+ case 'drawer': {
101
+ return renderDrawer();
102
+ }
103
+ case 'inner-drawer': {
104
+ return renderInnerDrawer();
105
+ }
106
+ default: {
107
+ return renderBalloon();
108
+ }
109
+ }
110
+ };
111
+ return (React.createElement("div", { className: classNames, style: Object.assign(Object.assign({}, style), dragStyle), ref: elRef },
112
+ !!addonBefore && (React.createElement("div", { className: cs(`${cls}-addon`, `${cls}-addon--before`) }, addonBefore)),
113
+ React.createElement("div", { className: cs(`${cls}-trigger`), ref: triggerRef }, renderView()),
114
+ !!addonAfter && (React.createElement("div", { className: cs(`${cls}-addon`, `${cls}-addon--after`) }, addonAfter))));
115
+ });
116
+ FloatButton.displayName = 'FloatButton';
117
+ export default ConfigProvider.config(FloatButton);
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function InnerDrawer(): React.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export function InnerDrawer() {
3
+ return React.createElement("div", null, "inner-drawer");
4
+ }
package/es/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default as Button } from './button';
2
+ export declare const version: string;
package/es/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as Button } from './button';
2
+ export const version = '0.0.1';
@@ -0,0 +1,2 @@
1
+ import { type ComponentType } from 'react';
2
+ export declare function assignSubComponent<T extends ComponentType, P extends Record<string, unknown>>(Component: T, SubComponents: P): T & P;
@@ -0,0 +1,8 @@
1
+ export function assignSubComponent(Component, SubComponents) {
2
+ for (const key in SubComponents) {
3
+ if (Object.prototype.hasOwnProperty.call(SubComponents, key)) {
4
+ Component[key] = SubComponents[key];
5
+ }
6
+ }
7
+ return Component;
8
+ }
@@ -0,0 +1,3 @@
1
+ import { type AnyFunction } from './types';
2
+ export declare function debounce<Callback extends AnyFunction>(callback: Callback, delay: number, leading?: boolean): (...args: Parameters<Callback>) => void;
3
+ export declare function throttle<Callback extends AnyFunction>(callback: Callback, delay: number): (...args: Parameters<Callback>) => void;
@@ -0,0 +1,30 @@
1
+ export function debounce(callback, delay, leading = false) {
2
+ let timer;
3
+ let isFirstRun = true;
4
+ const fn = (...args) => {
5
+ if (isFirstRun && leading) {
6
+ isFirstRun = false;
7
+ timer = setTimeout(() => {
8
+ callback(...args);
9
+ });
10
+ return;
11
+ }
12
+ isFirstRun = false;
13
+ clearTimeout(timer);
14
+ timer = setTimeout(() => {
15
+ callback(...args);
16
+ }, delay);
17
+ };
18
+ return fn;
19
+ }
20
+ export function throttle(callback, delay) {
21
+ let lastTime;
22
+ const fn = (...args) => {
23
+ const time = Date.now();
24
+ if (!lastTime || time - lastTime > delay) {
25
+ Promise.resolve().then(() => callback(...args));
26
+ lastTime = time;
27
+ }
28
+ };
29
+ return fn;
30
+ }
@@ -0,0 +1,6 @@
1
+ export interface ControlableOptions {
2
+ valueName?: string;
3
+ defaultValueName?: string;
4
+ changeName?: string;
5
+ }
6
+ export declare function useControlable<Value = unknown, OnChange extends (nextValue: Value, ...rest: unknown[]) => unknown = (nextValue: Value, ...rest: unknown[]) => unknown>(props: Record<string, unknown>, { valueName, defaultValueName, changeName, }?: ControlableOptions): readonly [Value, OnChange];
@@ -0,0 +1,27 @@
1
+ import { useEffect, useState } from 'react';
2
+ function upperFirst(str) {
3
+ return `${str.slice(0, 1).toUpperCase()}${str.slice(1)}`;
4
+ }
5
+ function getDefaultValueName(valueName) {
6
+ return `default${upperFirst(valueName)}`;
7
+ }
8
+ export function useControlable(props, { valueName = 'value', defaultValueName = getDefaultValueName(valueName), changeName = 'onChange', } = {}) {
9
+ const isControl = valueName in props;
10
+ const propValue = (isControl ? props[valueName] : props[defaultValueName]);
11
+ const propOnChange = props[changeName];
12
+ const [value, setValue] = useState(() => propValue);
13
+ const handleChange = (nextValue, ...rest) => {
14
+ if (!isControl) {
15
+ setValue(() => nextValue);
16
+ }
17
+ if (typeof propOnChange === 'function') {
18
+ propOnChange(nextValue, ...rest);
19
+ }
20
+ };
21
+ useEffect(() => {
22
+ if (value !== propValue) {
23
+ setValue(() => propValue);
24
+ }
25
+ }, [propValue]);
26
+ return [value, handleChange];
27
+ }
@@ -0,0 +1,2 @@
1
+ import { type AnyFunction } from '../types';
2
+ export declare function useDebounce<Callback extends AnyFunction>(callback: Callback, delay?: number, leading?: boolean): (...args: Parameters<Callback>) => void;