@lobehub/ui 1.168.3 → 1.168.5
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InputProps } from 'antd';
|
|
1
2
|
import { type CSSProperties } from 'react';
|
|
2
3
|
export interface HotkeyInputProps {
|
|
3
4
|
allowReset?: boolean;
|
|
@@ -6,9 +7,13 @@ export interface HotkeyInputProps {
|
|
|
6
7
|
disabled?: boolean;
|
|
7
8
|
hotkeyConflicts?: string[];
|
|
8
9
|
isApple?: boolean;
|
|
10
|
+
onBlur?: InputProps['onBlur'];
|
|
9
11
|
onChange?: (value: string) => void;
|
|
10
12
|
onConflict?: (conflictKey: string) => void;
|
|
13
|
+
onFocus?: InputProps['onFocus'];
|
|
14
|
+
onReset?: (currentValue: string, resetValue: string) => void;
|
|
11
15
|
placeholder?: string;
|
|
16
|
+
resetValue?: string;
|
|
12
17
|
style?: CSSProperties;
|
|
13
18
|
texts?: {
|
|
14
19
|
conflicts?: string;
|
|
@@ -16,7 +21,7 @@ export interface HotkeyInputProps {
|
|
|
16
21
|
reset?: string;
|
|
17
22
|
};
|
|
18
23
|
value?: string;
|
|
19
|
-
variant?: 'ghost' | 'block' | 'pure';
|
|
24
|
+
variant?: 'default' | 'ghost' | 'block' | 'pure';
|
|
20
25
|
}
|
|
21
26
|
declare const HotkeyInput: import("react").NamedExoticComponent<HotkeyInputProps>;
|
|
22
27
|
export default HotkeyInput;
|
package/es/HotkeyInput/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { Undo2Icon } from 'lucide-react';
|
|
|
18
18
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
19
19
|
import { useHotkeys, useRecordHotkeys } from 'react-hotkeys-hook';
|
|
20
20
|
import { Flexbox } from 'react-layout-kit';
|
|
21
|
+
import useControlledState from 'use-merge-value';
|
|
21
22
|
import ActionIcon from "../ActionIcon";
|
|
22
23
|
import Hotkey from "../Hotkey";
|
|
23
24
|
import { checkIsAppleDevice, splitKeysByPlus } from "../Hotkey/utils";
|
|
@@ -32,6 +33,8 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
32
33
|
value = _ref$value === void 0 ? '' : _ref$value,
|
|
33
34
|
_ref$defaultValue = _ref.defaultValue,
|
|
34
35
|
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
|
36
|
+
_ref$resetValue = _ref.resetValue,
|
|
37
|
+
resetValue = _ref$resetValue === void 0 ? '' : _ref$resetValue,
|
|
35
38
|
onChange = _ref.onChange,
|
|
36
39
|
onConflict = _ref.onConflict,
|
|
37
40
|
_ref$placeholder = _ref.placeholder,
|
|
@@ -45,9 +48,12 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
45
48
|
_ref$hotkeyConflicts = _ref.hotkeyConflicts,
|
|
46
49
|
hotkeyConflicts = _ref$hotkeyConflicts === void 0 ? [] : _ref$hotkeyConflicts,
|
|
47
50
|
_ref$variant = _ref.variant,
|
|
48
|
-
variant = _ref$variant === void 0 ? '
|
|
51
|
+
variant = _ref$variant === void 0 ? 'default' : _ref$variant,
|
|
49
52
|
texts = _ref.texts,
|
|
50
|
-
isApple = _ref.isApple
|
|
53
|
+
isApple = _ref.isApple,
|
|
54
|
+
onBlur = _ref.onBlur,
|
|
55
|
+
onReset = _ref.onReset,
|
|
56
|
+
onFocus = _ref.onFocus;
|
|
51
57
|
var _useState = useState(false),
|
|
52
58
|
_useState2 = _slicedToArray(_useState, 2),
|
|
53
59
|
isFocused = _useState2[0],
|
|
@@ -69,6 +75,14 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
69
75
|
var isAppleDevice = useMemo(function () {
|
|
70
76
|
return checkIsAppleDevice(isApple);
|
|
71
77
|
}, [isApple]);
|
|
78
|
+
var _useControlledState = useControlledState(defaultValue, {
|
|
79
|
+
defaultValue: defaultValue,
|
|
80
|
+
onChange: onChange,
|
|
81
|
+
value: value
|
|
82
|
+
}),
|
|
83
|
+
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
84
|
+
hotkeyValue = _useControlledState2[0],
|
|
85
|
+
setHotkeyValue = _useControlledState2[1];
|
|
72
86
|
|
|
73
87
|
// 使用 useRecordHotkeys 处理快捷键录入
|
|
74
88
|
var _useRecordHotkeys = useRecordHotkeys(),
|
|
@@ -87,7 +101,8 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
87
101
|
enableOnFormTags: true,
|
|
88
102
|
enabled: isRecording && !disabled,
|
|
89
103
|
keydown: false,
|
|
90
|
-
keyup: true
|
|
104
|
+
keyup: true,
|
|
105
|
+
preventDefault: true
|
|
91
106
|
});
|
|
92
107
|
|
|
93
108
|
// 处理按键,保证格式正确:修饰键在前,最多一个非修饰键在后
|
|
@@ -145,7 +160,9 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
145
160
|
|
|
146
161
|
// 检查快捷键冲突
|
|
147
162
|
var checkHotkeyConflict = useCallback(function (newHotkey) {
|
|
148
|
-
return hotkeyConflicts.
|
|
163
|
+
return hotkeyConflicts.filter(function (conflictKey) {
|
|
164
|
+
return conflictKey !== resetValue;
|
|
165
|
+
}).some(function (conflictKey) {
|
|
149
166
|
var newKeys = splitKeysByPlus(newHotkey);
|
|
150
167
|
var conflictKeys = splitKeysByPlus(conflictKey);
|
|
151
168
|
return isEqual(newKeys.sort(), conflictKeys.sort());
|
|
@@ -166,38 +183,48 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
166
183
|
// 检查冲突
|
|
167
184
|
var conflict = checkHotkeyConflict(newKeysString);
|
|
168
185
|
if (conflict) {
|
|
169
|
-
console.log('conflict');
|
|
170
186
|
setHasConflict(true);
|
|
171
187
|
onConflict === null || onConflict === void 0 || onConflict(newKeysString);
|
|
172
188
|
} else {
|
|
173
189
|
setHasConflict(false);
|
|
174
|
-
|
|
190
|
+
setHotkeyValue === null || setHotkeyValue === void 0 || setHotkeyValue(newKeysString);
|
|
175
191
|
}
|
|
176
192
|
}
|
|
177
|
-
}, [recordedKeys, isRecording, isValid, keysString, checkHotkeyConflict,
|
|
193
|
+
}, [recordedKeys, isRecording, isValid, keysString, checkHotkeyConflict, setHotkeyValue, onConflict]);
|
|
178
194
|
|
|
179
195
|
// 处理输入框焦点
|
|
180
|
-
var handleFocus = function handleFocus() {
|
|
196
|
+
var handleFocus = function handleFocus(e) {
|
|
181
197
|
if (disabled) return;
|
|
182
198
|
setIsFocused(true);
|
|
183
199
|
setHasConflict(false);
|
|
184
200
|
setHasInvalidCombination(false);
|
|
185
201
|
start(); // 开始记录
|
|
202
|
+
onFocus === null || onFocus === void 0 || onFocus(e);
|
|
186
203
|
};
|
|
187
|
-
var handleBlur = function handleBlur() {
|
|
204
|
+
var handleBlur = function handleBlur(e) {
|
|
188
205
|
setIsFocused(false);
|
|
189
206
|
stop(); // 停止记录
|
|
207
|
+
onBlur === null || onBlur === void 0 || onBlur(e);
|
|
190
208
|
};
|
|
191
209
|
|
|
192
210
|
// 重置功能
|
|
193
211
|
var handleReset = function handleReset(e) {
|
|
194
212
|
e.preventDefault();
|
|
195
213
|
e.stopPropagation();
|
|
196
|
-
|
|
214
|
+
setHotkeyValue === null || setHotkeyValue === void 0 || setHotkeyValue(resetValue);
|
|
197
215
|
resetKeys();
|
|
198
216
|
setHasConflict(false);
|
|
199
217
|
setHasInvalidCombination(false);
|
|
200
|
-
|
|
218
|
+
setIsFocused(false);
|
|
219
|
+
stop(); // 停止记录
|
|
220
|
+
onReset === null || onReset === void 0 || onReset(hotkeyValue, resetValue);
|
|
221
|
+
};
|
|
222
|
+
var handleClick = function handleClick(e) {
|
|
223
|
+
var _inputRef$current2;
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
e.stopPropagation();
|
|
226
|
+
if (disabled || isFocused) return;
|
|
227
|
+
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.focus();
|
|
201
228
|
};
|
|
202
229
|
return /*#__PURE__*/_jsxs(Flexbox, {
|
|
203
230
|
className: className,
|
|
@@ -210,10 +237,7 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
210
237
|
className: cx(styles.input, isFocused && styles.inputFocused, (hasConflict || hasInvalidCombination) && styles.inputError, disabled && styles.inputDisabled),
|
|
211
238
|
horizontal: true,
|
|
212
239
|
justify: 'space-between',
|
|
213
|
-
onClick:
|
|
214
|
-
var _inputRef$current2;
|
|
215
|
-
return !disabled && !isFocused && ((_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus());
|
|
216
|
-
},
|
|
240
|
+
onClick: handleClick,
|
|
217
241
|
children: [/*#__PURE__*/_jsx("div", {
|
|
218
242
|
style: {
|
|
219
243
|
pointerEvents: 'none'
|
|
@@ -223,8 +247,8 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
223
247
|
children: keys.length > 0 ? /*#__PURE__*/_jsx(Hotkey, {
|
|
224
248
|
keys: keysString
|
|
225
249
|
}) : placeholder
|
|
226
|
-
}) :
|
|
227
|
-
keys:
|
|
250
|
+
}) : hotkeyValue ? /*#__PURE__*/_jsx(Hotkey, {
|
|
251
|
+
keys: hotkeyValue
|
|
228
252
|
}) : /*#__PURE__*/_jsx("span", {
|
|
229
253
|
className: styles.placeholder,
|
|
230
254
|
children: placeholder
|
|
@@ -239,7 +263,7 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
239
263
|
style: {
|
|
240
264
|
pointerEvents: 'none'
|
|
241
265
|
}
|
|
242
|
-
}), allowReset &&
|
|
266
|
+
}), allowReset && hotkeyValue && hotkeyValue !== resetValue && !disabled && /*#__PURE__*/_jsx(ActionIcon, {
|
|
243
267
|
active: true,
|
|
244
268
|
icon: Undo2Icon,
|
|
245
269
|
onClick: handleReset,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const useStyles: (props?: {
|
|
2
|
-
variant: 'ghost' | 'block' | 'pure';
|
|
2
|
+
variant: 'default' | 'ghost' | 'block' | 'pure';
|
|
3
3
|
} | undefined) => import("antd-style").ReturnStyles<{
|
|
4
4
|
errorText: import("antd-style").SerializedStyles;
|
|
5
5
|
hiddenInput: import("antd-style").SerializedStyles;
|
package/es/HotkeyInput/style.js
CHANGED
|
@@ -7,7 +7,7 @@ export var useStyles = createStyles(function (_ref, _ref2) {
|
|
|
7
7
|
token = _ref.token,
|
|
8
8
|
prefixCls = _ref.prefixCls;
|
|
9
9
|
var variant = _ref2.variant;
|
|
10
|
-
var typeStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n transition:\n background-color 100ms ", ",\n border-color 200ms ", ";\n\n &:hover {\n background-color: ", ";\n }\n\n &:focus {\n border-color: ", ";\n }\n\n &.", "-input-affix-wrapper-focused {\n border-color: ", ";\n }\n "])), variant === 'block' ? token.colorFillTertiary : 'transparent', variant === 'block' ? 'transparent' : token.colorBorder, token.borderRadius, token.motionEaseOut, token.motionEaseOut, token.colorFillTertiary, token.colorTextQuaternary, prefixCls, token.colorTextQuaternary);
|
|
10
|
+
var typeStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n transition:\n background-color 100ms ", ",\n border-color 200ms ", ";\n\n &:hover {\n background-color: ", ";\n }\n\n &:focus {\n border-color: ", ";\n }\n\n &.", "-input-affix-wrapper-focused {\n border-color: ", ";\n }\n "])), variant === 'block' || variant === 'default' ? token.colorFillTertiary : 'transparent', variant === 'block' ? 'transparent' : token.colorBorder, token.borderRadius, token.motionEaseOut, token.motionEaseOut, token.colorFillTertiary, token.colorTextQuaternary, prefixCls, token.colorTextQuaternary);
|
|
11
11
|
return {
|
|
12
12
|
errorText: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n font-size: 12px;\n color: ", ";\n "])), token.colorError),
|
|
13
13
|
hiddenInput: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n cursor: text;\n\n position: absolute;\n z-index: -1;\n inset-block-start: 0;\n inset-inline-start: 0;\n\n width: 100%;\n height: 100%;\n\n opacity: 0;\n "]))),
|