@lobehub/editor 1.4.5 → 1.4.7
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/es/react/ChatInputActions/ChatInputActions.js +38 -119
- package/es/react/ChatInputActions/components/ActionItem.d.ts +13 -0
- package/es/react/ChatInputActions/components/ActionItem.js +60 -0
- package/es/react/ChatInputActions/components/ActionRender.d.ts +9 -0
- package/es/react/ChatInputActions/components/ActionRender.js +64 -0
- package/es/react/ChatInputActions/components/CollapsedActions.d.ts +4 -0
- package/es/react/ChatInputActions/components/CollapsedActions.js +82 -0
- package/es/react/ChatInputActions/components/useContainerSize.d.ts +9 -0
- package/es/react/ChatInputActions/components/useContainerSize.js +43 -0
- package/es/react/ChatInputActions/components/useDisplayActionCount.d.ts +13 -0
- package/es/react/ChatInputActions/components/useDisplayActionCount.js +66 -0
- package/es/react/ChatInputActions/style.js +1 -1
- package/es/react/ChatInputActions/type.d.ts +10 -9
- package/package.json +1 -1
- package/es/react/ChatInputActions/components/ChatInputActionsCollapse.d.ts +0 -4
- package/es/react/ChatInputActions/components/ChatInputActionsCollapse.js +0 -97
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
var _excluded = ["gap", "disabled", "items", "onActionClick", "className", "collapseOffset"]
|
|
5
|
-
_excluded2 = ["wrapper", "icon", "key", "label", "onClick", "danger", "loading"];
|
|
4
|
+
var _excluded = ["gap", "disabled", "items", "onActionClick", "className", "collapseOffset", "autoCollapse", "defaultGroupCollapse", "onGroupCollapseChange", "groupCollapse"];
|
|
6
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
7
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -20,12 +19,11 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
20
19
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
20
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
22
21
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
23
|
-
import {
|
|
24
|
-
import { useSize } from 'ahooks';
|
|
25
|
-
import { Divider } from 'antd';
|
|
26
|
-
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
22
|
+
import { memo, useMemo } from 'react';
|
|
27
23
|
import { Flexbox } from 'react-layout-kit';
|
|
28
|
-
import
|
|
24
|
+
import useMergeState from 'use-merge-value';
|
|
25
|
+
import ActionItem from "./components/ActionItem";
|
|
26
|
+
import { useDisplayActionCount } from "./components/useDisplayActionCount";
|
|
29
27
|
import { useStyles } from "./style";
|
|
30
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
29
|
var ChatInputActions = /*#__PURE__*/memo(function (_ref) {
|
|
@@ -38,41 +36,32 @@ var ChatInputActions = /*#__PURE__*/memo(function (_ref) {
|
|
|
38
36
|
className = _ref.className,
|
|
39
37
|
_ref$collapseOffset = _ref.collapseOffset,
|
|
40
38
|
collapseOffset = _ref$collapseOffset === void 0 ? 0 : _ref$collapseOffset,
|
|
39
|
+
_ref$autoCollapse = _ref.autoCollapse,
|
|
40
|
+
autoCollapse = _ref$autoCollapse === void 0 ? true : _ref$autoCollapse,
|
|
41
|
+
_ref$defaultGroupColl = _ref.defaultGroupCollapse,
|
|
42
|
+
defaultGroupCollapse = _ref$defaultGroupColl === void 0 ? false : _ref$defaultGroupColl,
|
|
43
|
+
onGroupCollapseChange = _ref.onGroupCollapseChange,
|
|
44
|
+
groupCollapse = _ref.groupCollapse,
|
|
41
45
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
42
46
|
var _useStyles = useStyles(),
|
|
43
47
|
cx = _useStyles.cx,
|
|
44
48
|
styles = _useStyles.styles;
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}).filter(function (item) {
|
|
62
|
-
return item.type !== 'divider';
|
|
63
|
-
});
|
|
64
|
-
}, [items]);
|
|
65
|
-
useEffect(function () {
|
|
66
|
-
if (!(size !== null && size !== void 0 && size.width)) return;
|
|
67
|
-
var length = flatItems.length + 1;
|
|
68
|
-
var calcMaxCount = Math.floor((size.width - collapseOffset) / 38);
|
|
69
|
-
setMaxCount(calcMaxCount);
|
|
70
|
-
if (calcMaxCount < length) {
|
|
71
|
-
setCollapsed(true);
|
|
72
|
-
} else {
|
|
73
|
-
setCollapsed(false);
|
|
74
|
-
}
|
|
75
|
-
}, [size, flatItems.length, collapseOffset]);
|
|
49
|
+
var _useMergeState = useMergeState(defaultGroupCollapse, {
|
|
50
|
+
defaultValue: defaultGroupCollapse,
|
|
51
|
+
onChange: onGroupCollapseChange,
|
|
52
|
+
value: groupCollapse
|
|
53
|
+
}),
|
|
54
|
+
_useMergeState2 = _slicedToArray(_useMergeState, 2),
|
|
55
|
+
groupCollapsed = _useMergeState2[0],
|
|
56
|
+
setGroupCollapsed = _useMergeState2[1];
|
|
57
|
+
var _useDisplayActionCoun = useDisplayActionCount({
|
|
58
|
+
autoCollapse: autoCollapse,
|
|
59
|
+
collapseOffset: collapseOffset,
|
|
60
|
+
items: items
|
|
61
|
+
}),
|
|
62
|
+
ref = _useDisplayActionCoun.ref,
|
|
63
|
+
maxCount = _useDisplayActionCoun.maxCount,
|
|
64
|
+
collapsed = _useDisplayActionCoun.collapsed;
|
|
76
65
|
var calcItem = useMemo(function () {
|
|
77
66
|
if (!collapsed) return items;
|
|
78
67
|
var alwaysDisplayItems = items.filter(function (item) {
|
|
@@ -93,95 +82,25 @@ var ChatInputActions = /*#__PURE__*/memo(function (_ref) {
|
|
|
93
82
|
return item.type !== 'divider';
|
|
94
83
|
}).slice(sliceCount)), _toConsumableArray(collapseItems.children))
|
|
95
84
|
})], _toConsumableArray(alwaysDisplayItems)).filter(Boolean);
|
|
96
|
-
}, [collapsed, items,
|
|
97
|
-
var mapActions = useCallback(function (item, i) {
|
|
98
|
-
if (item.type === 'divider') {
|
|
99
|
-
return /*#__PURE__*/_jsx(Divider, {
|
|
100
|
-
className: styles.divider,
|
|
101
|
-
style: {
|
|
102
|
-
height: 20
|
|
103
|
-
},
|
|
104
|
-
type: 'vertical'
|
|
105
|
-
}, "divider-".concat(i));
|
|
106
|
-
}
|
|
107
|
-
var wrapper = item.wrapper,
|
|
108
|
-
icon = item.icon,
|
|
109
|
-
key = item.key,
|
|
110
|
-
label = item.label,
|
|
111
|
-
_onClick = item.onClick,
|
|
112
|
-
danger = item.danger,
|
|
113
|
-
loading = item.loading,
|
|
114
|
-
itemRest = _objectWithoutProperties(item, _excluded2);
|
|
115
|
-
var node = item.children || /*#__PURE__*/_jsx(ActionIcon, {
|
|
116
|
-
active: item.active,
|
|
117
|
-
danger: danger,
|
|
118
|
-
disabled: disabled || loading || (itemRest === null || itemRest === void 0 ? void 0 : itemRest.disabled),
|
|
119
|
-
icon: icon,
|
|
120
|
-
loading: loading,
|
|
121
|
-
onClick: function onClick(e) {
|
|
122
|
-
onActionClick === null || onActionClick === void 0 || onActionClick({
|
|
123
|
-
domEvent: e,
|
|
124
|
-
key: String(key),
|
|
125
|
-
keyPath: [String(key)]
|
|
126
|
-
});
|
|
127
|
-
_onClick === null || _onClick === void 0 || _onClick(e);
|
|
128
|
-
},
|
|
129
|
-
size: {
|
|
130
|
-
blockSize: 36,
|
|
131
|
-
size: 20
|
|
132
|
-
},
|
|
133
|
-
title: label,
|
|
134
|
-
tooltipProps: {
|
|
135
|
-
placement: 'top'
|
|
136
|
-
}
|
|
137
|
-
}, key);
|
|
138
|
-
if (!wrapper) return node;
|
|
139
|
-
return wrapper(node, String(key));
|
|
140
|
-
}, [disabled, onActionClick, styles.divider]);
|
|
85
|
+
}, [collapsed, items, maxCount]);
|
|
141
86
|
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
142
87
|
align: 'center',
|
|
143
88
|
className: cx(styles.container, className),
|
|
144
|
-
flex:
|
|
89
|
+
flex: 1,
|
|
145
90
|
gap: gap,
|
|
146
91
|
horizontal: true,
|
|
147
92
|
ref: ref
|
|
148
93
|
}, rest), {}, {
|
|
149
94
|
children: calcItem.map(function (item, index) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
})
|
|
160
|
-
}, "collapse-".concat(index));
|
|
161
|
-
}
|
|
162
|
-
if (item.type === 'dropdown') {
|
|
163
|
-
return /*#__PURE__*/_jsx(Dropdown, {
|
|
164
|
-
menu: {
|
|
165
|
-
items: item.children
|
|
166
|
-
},
|
|
167
|
-
children: /*#__PURE__*/_jsx(ActionIcon, {
|
|
168
|
-
active: item.active,
|
|
169
|
-
danger: item.danger,
|
|
170
|
-
disabled: disabled || item.loading || (item === null || item === void 0 ? void 0 : item.disabled),
|
|
171
|
-
icon: item.icon,
|
|
172
|
-
loading: item.loading,
|
|
173
|
-
size: {
|
|
174
|
-
blockSize: 36,
|
|
175
|
-
size: 20
|
|
176
|
-
},
|
|
177
|
-
title: item.label,
|
|
178
|
-
tooltipProps: {
|
|
179
|
-
placement: 'top'
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
}, item.key);
|
|
183
|
-
}
|
|
184
|
-
return mapActions(item, index);
|
|
95
|
+
return /*#__PURE__*/_jsx(ActionItem, {
|
|
96
|
+
collapsed: collapsed,
|
|
97
|
+
disabled: disabled,
|
|
98
|
+
gap: gap,
|
|
99
|
+
groupCollapsed: groupCollapsed,
|
|
100
|
+
item: item,
|
|
101
|
+
onActionClick: onActionClick,
|
|
102
|
+
setGroupCollapsed: setGroupCollapsed
|
|
103
|
+
}, item.key || index);
|
|
185
104
|
})
|
|
186
105
|
}));
|
|
187
106
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ChatInputActionItem, ChatInputActionsProps } from '../type';
|
|
3
|
+
interface ChatInputActionItemProps {
|
|
4
|
+
collapsed?: boolean;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
gap?: string | number;
|
|
7
|
+
groupCollapsed?: boolean;
|
|
8
|
+
item: ChatInputActionItem;
|
|
9
|
+
onActionClick: ChatInputActionsProps['onActionClick'];
|
|
10
|
+
setGroupCollapsed?: (collapse: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const ActionItem: import("react").NamedExoticComponent<ChatInputActionItemProps>;
|
|
13
|
+
export default ActionItem;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { ActionIcon, Dropdown } from '@lobehub/ui';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import ActionRender from "./ActionRender";
|
|
6
|
+
import CollapsedActions from "./CollapsedActions";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
var ActionItem = /*#__PURE__*/memo(function (_ref) {
|
|
9
|
+
var item = _ref.item,
|
|
10
|
+
disabled = _ref.disabled,
|
|
11
|
+
onActionClick = _ref.onActionClick,
|
|
12
|
+
groupCollapsed = _ref.groupCollapsed,
|
|
13
|
+
collapsed = _ref.collapsed,
|
|
14
|
+
gap = _ref.gap,
|
|
15
|
+
setGroupCollapsed = _ref.setGroupCollapsed;
|
|
16
|
+
if (item.type === 'collapse') {
|
|
17
|
+
return /*#__PURE__*/_jsx(CollapsedActions, {
|
|
18
|
+
gap: gap,
|
|
19
|
+
groupCollapse: groupCollapsed,
|
|
20
|
+
mode: collapsed ? 'popup' : 'default',
|
|
21
|
+
onGroupCollapseChange: setGroupCollapsed,
|
|
22
|
+
children: item.children.map(function (child, childIndex) {
|
|
23
|
+
return /*#__PURE__*/_jsx(ActionRender, {
|
|
24
|
+
disabled: disabled,
|
|
25
|
+
item: child,
|
|
26
|
+
onActionClick: onActionClick
|
|
27
|
+
}, (child === null || child === void 0 ? void 0 : child.key) || "action-".concat(childIndex));
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (item.type === 'dropdown') {
|
|
32
|
+
return /*#__PURE__*/_jsx(Dropdown, {
|
|
33
|
+
menu: {
|
|
34
|
+
items: item.children
|
|
35
|
+
},
|
|
36
|
+
children: /*#__PURE__*/_jsx(ActionIcon, {
|
|
37
|
+
active: item.active,
|
|
38
|
+
danger: item.danger,
|
|
39
|
+
disabled: disabled || item.loading || (item === null || item === void 0 ? void 0 : item.disabled),
|
|
40
|
+
icon: item.icon,
|
|
41
|
+
loading: item.loading,
|
|
42
|
+
size: {
|
|
43
|
+
blockSize: 36,
|
|
44
|
+
size: 20
|
|
45
|
+
},
|
|
46
|
+
title: item.label,
|
|
47
|
+
tooltipProps: {
|
|
48
|
+
placement: 'top'
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
}, item.key);
|
|
52
|
+
}
|
|
53
|
+
return /*#__PURE__*/_jsx(ActionRender, {
|
|
54
|
+
disabled: disabled,
|
|
55
|
+
item: item,
|
|
56
|
+
onActionClick: onActionClick
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
ActionItem.displayName = 'ChatInputActionItem';
|
|
60
|
+
export default ActionItem;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ChatInputActionItem, ChatInputActionsProps } from '../type';
|
|
3
|
+
interface ActionRenderProps {
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
item: ChatInputActionItem;
|
|
6
|
+
onActionClick: ChatInputActionsProps['onActionClick'];
|
|
7
|
+
}
|
|
8
|
+
declare const ActionRender: import("react").NamedExoticComponent<ActionRenderProps>;
|
|
9
|
+
export default ActionRender;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var _excluded = ["wrapper", "icon", "key", "label", "onClick", "danger", "loading", "active"];
|
|
2
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
5
|
+
import { Divider } from 'antd';
|
|
6
|
+
import { isValidElement, memo } from 'react';
|
|
7
|
+
import { useStyles } from "../style";
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
var ActionRender = /*#__PURE__*/memo(function (_ref) {
|
|
10
|
+
var item = _ref.item,
|
|
11
|
+
onActionClick = _ref.onActionClick,
|
|
12
|
+
disabled = _ref.disabled;
|
|
13
|
+
var _useStyles = useStyles(),
|
|
14
|
+
styles = _useStyles.styles;
|
|
15
|
+
if (item.type === 'divider') {
|
|
16
|
+
return /*#__PURE__*/_jsx(Divider, {
|
|
17
|
+
className: styles.divider,
|
|
18
|
+
style: {
|
|
19
|
+
height: 20
|
|
20
|
+
},
|
|
21
|
+
type: 'vertical'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
var _ref2 = item,
|
|
25
|
+
wrapper = _ref2.wrapper,
|
|
26
|
+
icon = _ref2.icon,
|
|
27
|
+
key = _ref2.key,
|
|
28
|
+
label = _ref2.label,
|
|
29
|
+
_onClick = _ref2.onClick,
|
|
30
|
+
danger = _ref2.danger,
|
|
31
|
+
loading = _ref2.loading,
|
|
32
|
+
active = _ref2.active,
|
|
33
|
+
itemRest = _objectWithoutProperties(_ref2, _excluded);
|
|
34
|
+
if (item.children && /*#__PURE__*/isValidElement(item.children)) {
|
|
35
|
+
if (!wrapper) return item.children;
|
|
36
|
+
return wrapper(item.children);
|
|
37
|
+
}
|
|
38
|
+
var action = /*#__PURE__*/_jsx(ActionIcon, {
|
|
39
|
+
active: active,
|
|
40
|
+
danger: danger,
|
|
41
|
+
disabled: disabled || loading || (itemRest === null || itemRest === void 0 ? void 0 : itemRest.disabled),
|
|
42
|
+
icon: icon,
|
|
43
|
+
loading: loading,
|
|
44
|
+
onClick: function onClick(e) {
|
|
45
|
+
onActionClick === null || onActionClick === void 0 || onActionClick({
|
|
46
|
+
domEvent: e,
|
|
47
|
+
key: String(key),
|
|
48
|
+
keyPath: [String(key)]
|
|
49
|
+
});
|
|
50
|
+
_onClick === null || _onClick === void 0 || _onClick(e);
|
|
51
|
+
},
|
|
52
|
+
size: {
|
|
53
|
+
blockSize: 36,
|
|
54
|
+
size: 20
|
|
55
|
+
},
|
|
56
|
+
title: label,
|
|
57
|
+
tooltipProps: {
|
|
58
|
+
placement: 'top'
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (!wrapper) return action;
|
|
62
|
+
return wrapper(action);
|
|
63
|
+
});
|
|
64
|
+
export default ActionRender;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
4
|
+
import { Popover } from 'antd';
|
|
5
|
+
import { motion } from 'framer-motion';
|
|
6
|
+
import { CircleChevronLeftIcon, CircleChevronRightIcon, CircleChevronUpIcon } from 'lucide-react';
|
|
7
|
+
import { memo } from 'react';
|
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
var CollapsedActions = /*#__PURE__*/memo(function (_ref) {
|
|
12
|
+
var children = _ref.children,
|
|
13
|
+
_ref$groupCollapse = _ref.groupCollapse,
|
|
14
|
+
groupCollapse = _ref$groupCollapse === void 0 ? false : _ref$groupCollapse,
|
|
15
|
+
onGroupCollapseChange = _ref.onGroupCollapseChange,
|
|
16
|
+
gap = _ref.gap,
|
|
17
|
+
mode = _ref.mode;
|
|
18
|
+
if (mode === 'popup') {
|
|
19
|
+
return /*#__PURE__*/_jsx(Popover, {
|
|
20
|
+
arrow: false,
|
|
21
|
+
content: /*#__PURE__*/_jsx(Flexbox, {
|
|
22
|
+
align: 'center',
|
|
23
|
+
gap: gap,
|
|
24
|
+
horizontal: true,
|
|
25
|
+
children: children
|
|
26
|
+
}),
|
|
27
|
+
styles: {
|
|
28
|
+
body: {
|
|
29
|
+
padding: 4
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
children: /*#__PURE__*/_jsx(ActionIcon, {
|
|
33
|
+
icon: CircleChevronUpIcon,
|
|
34
|
+
size: {
|
|
35
|
+
blockSize: 36,
|
|
36
|
+
size: 20
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return /*#__PURE__*/_jsxs(Flexbox, {
|
|
42
|
+
align: 'center',
|
|
43
|
+
flex: 'none',
|
|
44
|
+
gap: gap,
|
|
45
|
+
horizontal: true,
|
|
46
|
+
children: [/*#__PURE__*/_jsx(motion.div, {
|
|
47
|
+
animate: groupCollapse ? 'closed' : 'open',
|
|
48
|
+
initial: groupCollapse ? 'closed' : 'open',
|
|
49
|
+
style: {
|
|
50
|
+
alignItems: 'center',
|
|
51
|
+
display: 'flex',
|
|
52
|
+
gap: gap,
|
|
53
|
+
overflow: 'hidden'
|
|
54
|
+
},
|
|
55
|
+
transition: {
|
|
56
|
+
duration: 0.2
|
|
57
|
+
},
|
|
58
|
+
variants: {
|
|
59
|
+
closed: {
|
|
60
|
+
opacity: 0,
|
|
61
|
+
width: 0
|
|
62
|
+
},
|
|
63
|
+
open: {
|
|
64
|
+
opacity: 1,
|
|
65
|
+
width: 'auto'
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
children: children
|
|
69
|
+
}), /*#__PURE__*/_jsx(ActionIcon, {
|
|
70
|
+
icon: groupCollapse ? CircleChevronRightIcon : CircleChevronLeftIcon,
|
|
71
|
+
onClick: function onClick() {
|
|
72
|
+
return onGroupCollapseChange === null || onGroupCollapseChange === void 0 ? void 0 : onGroupCollapseChange(!groupCollapse);
|
|
73
|
+
},
|
|
74
|
+
size: {
|
|
75
|
+
blockSize: 36,
|
|
76
|
+
size: 20
|
|
77
|
+
}
|
|
78
|
+
})]
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
CollapsedActions.displayName = 'ChatInputActionsCollapse';
|
|
82
|
+
export default CollapsedActions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface UseContainerSizeOptions {
|
|
3
|
+
debounceMs?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare const useContainerSize: (options?: UseContainerSizeOptions) => {
|
|
6
|
+
ref: import("react").RefObject<HTMLElement | null>;
|
|
7
|
+
size: number | undefined;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
// hooks/useContainerSize.ts
|
|
8
|
+
import { debounce } from 'lodash-es';
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
export var useContainerSize = function useContainerSize() {
|
|
11
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12
|
+
var _options$debounceMs = options.debounceMs,
|
|
13
|
+
debounceMs = _options$debounceMs === void 0 ? 100 : _options$debounceMs;
|
|
14
|
+
var ref = useRef(null);
|
|
15
|
+
var _useState = useState(),
|
|
16
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
17
|
+
size = _useState2[0],
|
|
18
|
+
setSize = _useState2[1];
|
|
19
|
+
var resizeObserverRef = useRef(null);
|
|
20
|
+
var updateSize = useCallback(debounce(function (entries) {
|
|
21
|
+
if (entries[0]) {
|
|
22
|
+
var width = entries[0].contentRect.width;
|
|
23
|
+
setSize(Math.floor(width));
|
|
24
|
+
}
|
|
25
|
+
}, debounceMs), [debounceMs]);
|
|
26
|
+
useEffect(function () {
|
|
27
|
+
var element = ref.current;
|
|
28
|
+
if (!element) return;
|
|
29
|
+
resizeObserverRef.current = new ResizeObserver(updateSize);
|
|
30
|
+
resizeObserverRef.current.observe(element);
|
|
31
|
+
return function () {
|
|
32
|
+
if (resizeObserverRef.current) {
|
|
33
|
+
var _updateSize$cancel;
|
|
34
|
+
resizeObserverRef.current.disconnect();
|
|
35
|
+
(_updateSize$cancel = updateSize.cancel) === null || _updateSize$cancel === void 0 || _updateSize$cancel.call(updateSize); // 清理防抖
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}, [updateSize]);
|
|
39
|
+
return {
|
|
40
|
+
ref: ref,
|
|
41
|
+
size: size
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ChatInputActionItem } from '../type';
|
|
3
|
+
interface UseDisplayActionCountOptions {
|
|
4
|
+
autoCollapse?: boolean;
|
|
5
|
+
collapseOffset?: number;
|
|
6
|
+
items?: ChatInputActionItem[];
|
|
7
|
+
}
|
|
8
|
+
export declare const useDisplayActionCount: ({ items, collapseOffset, autoCollapse, }?: UseDisplayActionCountOptions) => {
|
|
9
|
+
collapsed: boolean;
|
|
10
|
+
maxCount: number;
|
|
11
|
+
ref: import("react").RefObject<HTMLElement | null>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { useContainerSize } from "./useContainerSize";
|
|
9
|
+
export var useDisplayActionCount = function useDisplayActionCount() {
|
|
10
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
11
|
+
_ref$items = _ref.items,
|
|
12
|
+
items = _ref$items === void 0 ? [] : _ref$items,
|
|
13
|
+
_ref$collapseOffset = _ref.collapseOffset,
|
|
14
|
+
collapseOffset = _ref$collapseOffset === void 0 ? 0 : _ref$collapseOffset,
|
|
15
|
+
autoCollapse = _ref.autoCollapse;
|
|
16
|
+
var _useContainerSize = useContainerSize(),
|
|
17
|
+
ref = _useContainerSize.ref,
|
|
18
|
+
size = _useContainerSize.size;
|
|
19
|
+
var _useState = useState(false),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
collapsed = _useState2[0],
|
|
22
|
+
setCollapsed = _useState2[1];
|
|
23
|
+
var flatItems = useMemo(function () {
|
|
24
|
+
return items.flatMap(function (item) {
|
|
25
|
+
if (item.type === 'collapse' && item.children) {
|
|
26
|
+
return item.children;
|
|
27
|
+
}
|
|
28
|
+
return item;
|
|
29
|
+
}).filter(function (item) {
|
|
30
|
+
return item.type !== 'divider';
|
|
31
|
+
});
|
|
32
|
+
}, [items]);
|
|
33
|
+
var alwaysDisplayCount = useMemo(function () {
|
|
34
|
+
return items.filter(function (item) {
|
|
35
|
+
return item.alwaysDisplay;
|
|
36
|
+
}).length;
|
|
37
|
+
}, [items]);
|
|
38
|
+
var rawMaxCount = useMemo(function () {
|
|
39
|
+
return flatItems.length + 1;
|
|
40
|
+
}, [flatItems.length]);
|
|
41
|
+
var _useState3 = useState(rawMaxCount),
|
|
42
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
43
|
+
maxCount = _useState4[0],
|
|
44
|
+
setMaxCount = _useState4[1];
|
|
45
|
+
useEffect(function () {
|
|
46
|
+
if (!autoCollapse) {
|
|
47
|
+
setCollapsed(false);
|
|
48
|
+
setMaxCount(rawMaxCount);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!size) return;
|
|
52
|
+
var atLeastCount = 1 + alwaysDisplayCount;
|
|
53
|
+
var calcMaxCount = Math.floor((size - collapseOffset) / 38);
|
|
54
|
+
if (calcMaxCount < atLeastCount) calcMaxCount = atLeastCount;
|
|
55
|
+
setCollapsed(calcMaxCount < rawMaxCount);
|
|
56
|
+
if (calcMaxCount >= rawMaxCount) return;
|
|
57
|
+
setMaxCount(calcMaxCount);
|
|
58
|
+
}, [autoCollapse, size, rawMaxCount, collapseOffset, alwaysDisplayCount]);
|
|
59
|
+
return useMemo(function () {
|
|
60
|
+
return {
|
|
61
|
+
collapsed: collapsed,
|
|
62
|
+
maxCount: maxCount,
|
|
63
|
+
ref: ref
|
|
64
|
+
};
|
|
65
|
+
}, [collapsed, maxCount, ref]);
|
|
66
|
+
};
|
|
@@ -4,7 +4,7 @@ import { createStyles } from 'antd-style';
|
|
|
4
4
|
export var useStyles = createStyles(function (_ref) {
|
|
5
5
|
var css = _ref.css;
|
|
6
6
|
return {
|
|
7
|
-
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n
|
|
7
|
+
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n width: 100%;\n "]))),
|
|
8
8
|
divider: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n margin-inline: 4px;\n "])))
|
|
9
9
|
};
|
|
10
10
|
});
|
|
@@ -2,20 +2,17 @@ import type { MenuInfo, MenuItemType } from '@lobehub/ui';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import type { FlexboxProps } from 'react-layout-kit';
|
|
4
4
|
export type ChatInputActionEvent = Pick<MenuInfo, 'key' | 'keyPath' | 'domEvent'>;
|
|
5
|
-
export
|
|
5
|
+
export interface ActionItem extends MenuItemType {
|
|
6
6
|
active?: boolean;
|
|
7
7
|
alwaysDisplay?: boolean;
|
|
8
8
|
children?: ReactNode;
|
|
9
|
-
wrapper?: (dom: ReactNode
|
|
10
|
-
}
|
|
9
|
+
wrapper?: (dom: ReactNode) => ReactNode;
|
|
10
|
+
}
|
|
11
11
|
export type DividerItem = {
|
|
12
12
|
type: 'divider';
|
|
13
13
|
};
|
|
14
14
|
export type CollapseItem = {
|
|
15
15
|
children: (ActionItem | DividerItem)[];
|
|
16
|
-
defaultExpand?: boolean;
|
|
17
|
-
expand?: boolean;
|
|
18
|
-
onChange?: (expand: boolean) => void;
|
|
19
16
|
type: 'collapse';
|
|
20
17
|
};
|
|
21
18
|
export type DropdownItem = Omit<ActionItem, 'children' | 'type'> & {
|
|
@@ -24,16 +21,20 @@ export type DropdownItem = Omit<ActionItem, 'children' | 'type'> & {
|
|
|
24
21
|
};
|
|
25
22
|
export type ChatInputActionItem = ActionItem | DividerItem | CollapseItem | DropdownItem;
|
|
26
23
|
export interface ChatInputActionsProps extends Omit<FlexboxProps, 'children'> {
|
|
24
|
+
autoCollapse?: boolean;
|
|
27
25
|
collapseOffset?: number;
|
|
26
|
+
defaultGroupCollapse?: boolean;
|
|
28
27
|
disabled?: boolean;
|
|
28
|
+
groupCollapse?: boolean;
|
|
29
29
|
items?: ChatInputActionItem[];
|
|
30
30
|
onActionClick?: (action: ChatInputActionEvent) => void;
|
|
31
|
+
onGroupCollapseChange?: (collapse: boolean) => void;
|
|
31
32
|
}
|
|
32
33
|
export interface ChatInputActionsCollapseProps {
|
|
33
34
|
children?: ReactNode;
|
|
34
|
-
|
|
35
|
-
expand?: boolean;
|
|
35
|
+
collapse?: boolean;
|
|
36
36
|
gap?: FlexboxProps['gap'];
|
|
37
|
+
groupCollapse?: boolean;
|
|
37
38
|
mode?: 'default' | 'popup';
|
|
38
|
-
|
|
39
|
+
onGroupCollapseChange?: (collapse: boolean) => void;
|
|
39
40
|
}
|
package/package.json
CHANGED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
-
import { ActionIcon } from '@lobehub/ui';
|
|
10
|
-
import { Popover } from 'antd';
|
|
11
|
-
import { motion } from 'framer-motion';
|
|
12
|
-
import { CircleChevronLeftIcon, CircleChevronRightIcon, CircleChevronUpIcon } from 'lucide-react';
|
|
13
|
-
import { memo } from 'react';
|
|
14
|
-
import { Flexbox } from 'react-layout-kit';
|
|
15
|
-
import useMergeState from 'use-merge-value';
|
|
16
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
-
var ChatInputActionsCollapse = /*#__PURE__*/memo(function (_ref) {
|
|
19
|
-
var children = _ref.children,
|
|
20
|
-
expand = _ref.expand,
|
|
21
|
-
_ref$defaultExpand = _ref.defaultExpand,
|
|
22
|
-
defaultExpand = _ref$defaultExpand === void 0 ? true : _ref$defaultExpand,
|
|
23
|
-
onChange = _ref.onChange,
|
|
24
|
-
gap = _ref.gap,
|
|
25
|
-
mode = _ref.mode;
|
|
26
|
-
var _useMergeState = useMergeState(defaultExpand, {
|
|
27
|
-
defaultValue: defaultExpand,
|
|
28
|
-
onChange: onChange,
|
|
29
|
-
value: expand
|
|
30
|
-
}),
|
|
31
|
-
_useMergeState2 = _slicedToArray(_useMergeState, 2),
|
|
32
|
-
expanded = _useMergeState2[0],
|
|
33
|
-
setExpaned = _useMergeState2[1];
|
|
34
|
-
if (mode === 'popup') {
|
|
35
|
-
return /*#__PURE__*/_jsx(Popover, {
|
|
36
|
-
arrow: false,
|
|
37
|
-
content: /*#__PURE__*/_jsx(Flexbox, {
|
|
38
|
-
align: 'center',
|
|
39
|
-
gap: gap,
|
|
40
|
-
horizontal: true,
|
|
41
|
-
children: children
|
|
42
|
-
}),
|
|
43
|
-
styles: {
|
|
44
|
-
body: {
|
|
45
|
-
padding: 4
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
children: /*#__PURE__*/_jsx(ActionIcon, {
|
|
49
|
-
icon: CircleChevronUpIcon,
|
|
50
|
-
size: {
|
|
51
|
-
blockSize: 36,
|
|
52
|
-
size: 20
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return /*#__PURE__*/_jsxs(Flexbox, {
|
|
58
|
-
align: 'center',
|
|
59
|
-
flex: 'none',
|
|
60
|
-
gap: gap,
|
|
61
|
-
horizontal: true,
|
|
62
|
-
children: [/*#__PURE__*/_jsx(motion.div, {
|
|
63
|
-
animate: expanded ? 'open' : 'closed',
|
|
64
|
-
style: {
|
|
65
|
-
alignItems: 'center',
|
|
66
|
-
display: 'flex',
|
|
67
|
-
gap: gap,
|
|
68
|
-
overflow: 'hidden'
|
|
69
|
-
},
|
|
70
|
-
transition: {
|
|
71
|
-
duration: 0.2
|
|
72
|
-
},
|
|
73
|
-
variants: {
|
|
74
|
-
closed: {
|
|
75
|
-
opacity: 0,
|
|
76
|
-
width: 0
|
|
77
|
-
},
|
|
78
|
-
open: {
|
|
79
|
-
opacity: 1,
|
|
80
|
-
width: 'auto'
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
children: children
|
|
84
|
-
}), /*#__PURE__*/_jsx(ActionIcon, {
|
|
85
|
-
icon: expanded ? CircleChevronLeftIcon : CircleChevronRightIcon,
|
|
86
|
-
onClick: function onClick() {
|
|
87
|
-
return setExpaned(!expanded);
|
|
88
|
-
},
|
|
89
|
-
size: {
|
|
90
|
-
blockSize: 36,
|
|
91
|
-
size: 20
|
|
92
|
-
}
|
|
93
|
-
})]
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
ChatInputActionsCollapse.displayName = 'ChatInputActionsCollapse';
|
|
97
|
-
export default ChatInputActionsCollapse;
|