@lobehub/ui 1.167.0 → 1.168.0

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,6 +1,6 @@
1
1
  import { type CSSProperties } from 'react';
2
2
  import { type FlexboxProps } from 'react-layout-kit';
3
- export interface HotKeysProps extends Omit<FlexboxProps, 'children'> {
3
+ export interface HotkeyProps extends Omit<FlexboxProps, 'children'> {
4
4
  classNames?: {
5
5
  descClassName?: string;
6
6
  kbdClassName?: string;
@@ -15,5 +15,5 @@ export interface HotKeysProps extends Omit<FlexboxProps, 'children'> {
15
15
  kbdStyle?: CSSProperties;
16
16
  };
17
17
  }
18
- declare const HotKeys: import("react").NamedExoticComponent<HotKeysProps>;
19
- export default HotKeys;
18
+ declare const Hotkey: import("react").NamedExoticComponent<HotkeyProps>;
19
+ export default Hotkey;
@@ -16,15 +16,15 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
  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; }
17
17
  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; }
18
18
  import { isString } from 'lodash-es';
19
- import { Command, Delete, Option } from 'lucide-react';
20
- import { memo, useEffect, useState } from 'react';
19
+ import { ChevronUpIcon, Command, Delete, Option } from 'lucide-react';
20
+ import { memo, useEffect, useMemo, useState } from 'react';
21
21
  import { Flexbox } from 'react-layout-kit';
22
22
  import Icon from "../Icon";
23
- import { ALT_KEY, BACKSPACE_KEY, META_KEY, useStyles } from "./style";
24
- import { splitKeysByPlus, startCase } from "./utils";
23
+ import { useStyles } from "./style";
24
+ import { ALT_KEY, BACKSPACE_KEY, CONTROL_KEY, META_KEY, MOD_KEY, checkIsAppleDevice, splitKeysByPlus, startCase } from "./utils";
25
25
  import { jsx as _jsx } from "react/jsx-runtime";
26
26
  import { jsxs as _jsxs } from "react/jsx-runtime";
27
- var HotKeys = /*#__PURE__*/memo(function (_ref) {
27
+ var Hotkey = /*#__PURE__*/memo(function (_ref) {
28
28
  var classNames = _ref.classNames,
29
29
  styles = _ref.styles,
30
30
  keys = _ref.keys,
@@ -43,14 +43,19 @@ var HotKeys = /*#__PURE__*/memo(function (_ref) {
43
43
  keysGroup = _useState2[0],
44
44
  setKeysGroup = _useState2[1];
45
45
  var visibility = typeof window === 'undefined' ? 'hidden' : 'visible';
46
+ var isAppleDevice = useMemo(function () {
47
+ return checkIsAppleDevice(isApple);
48
+ }, [isApple]);
46
49
  useEffect(function () {
47
- var _navigator;
48
- var isAppleDevice = isApple === undefined ? /(mac|iphone|ipod|ipad)/i.test(typeof navigator === 'undefined' ? '' : (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.platform) : isApple;
49
- var mapping = _defineProperty(_defineProperty(_defineProperty({}, ALT_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
50
+ var mapping = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ALT_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
50
51
  icon: Option
51
52
  }) : 'alt'), BACKSPACE_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
52
53
  icon: Delete
53
- }) : 'backspace'), META_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
54
+ }) : 'backspace'), CONTROL_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
55
+ icon: ChevronUpIcon
56
+ }) : 'ctrl'), META_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
57
+ icon: Command
58
+ }) : 'win'), MOD_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
54
59
  icon: Command
55
60
  }) : 'ctrl');
56
61
  var newValue = splitKeysByPlus(keys).map(function (k) {
@@ -58,7 +63,7 @@ var HotKeys = /*#__PURE__*/memo(function (_ref) {
58
63
  return (_mapping$k = mapping[k]) !== null && _mapping$k !== void 0 ? _mapping$k : k;
59
64
  });
60
65
  setKeysGroup(newValue);
61
- }, [keys, isApple]);
66
+ }, [keys, isAppleDevice]);
62
67
  return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
63
68
  align: 'center',
64
69
  className: cx(s, className),
@@ -95,4 +100,4 @@ var HotKeys = /*#__PURE__*/memo(function (_ref) {
95
100
  })]
96
101
  }));
97
102
  });
98
- export default HotKeys;
103
+ export default Hotkey;
@@ -1,4 +1 @@
1
- export declare const ALT_KEY = "alt";
2
- export declare const META_KEY = "mod";
3
- export declare const BACKSPACE_KEY = "backspace";
4
1
  export declare const useStyles: (props?: boolean | undefined) => import("antd-style").ReturnStyles<import("antd-style").SerializedStyles>;
@@ -2,9 +2,6 @@ var _templateObject;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStyles } from 'antd-style';
4
4
  import { rgba } from 'polished';
5
- export var ALT_KEY = 'alt';
6
- export var META_KEY = 'mod';
7
- export var BACKSPACE_KEY = 'backspace';
8
5
  export var useStyles = createStyles(function (_ref, inverseTheme) {
9
6
  var css = _ref.css,
10
7
  token = _ref.token;
@@ -0,0 +1,8 @@
1
+ export declare const ALT_KEY = "alt";
2
+ export declare const MOD_KEY = "mod";
3
+ export declare const META_KEY = "meta";
4
+ export declare const BACKSPACE_KEY = "backspace";
5
+ export declare const CONTROL_KEY = "ctrl";
6
+ export declare const splitKeysByPlus: (keys: string) => string[];
7
+ export declare const startCase: (str: string) => string;
8
+ export declare const checkIsAppleDevice: (isApple?: boolean) => boolean;
@@ -0,0 +1,28 @@
1
+ export var ALT_KEY = 'alt';
2
+ export var MOD_KEY = 'mod';
3
+ export var META_KEY = 'meta';
4
+ export var BACKSPACE_KEY = 'backspace';
5
+ export var CONTROL_KEY = 'ctrl';
6
+ export var splitKeysByPlus = function splitKeysByPlus(keys) {
7
+ var placeholder = 'PLACEHOLDER';
8
+ var parts = keys.replaceAll('++', "+".concat(placeholder)).split('+');
9
+ return parts.filter(Boolean).map(function (part) {
10
+ if (part === placeholder) return '+';
11
+ return part;
12
+ });
13
+ };
14
+ export var startCase = function startCase(str) {
15
+ return str.replaceAll(/([A-Z])/g, ' $1').replace(/^./, function (s) {
16
+ return s.toUpperCase();
17
+ }).trim();
18
+ };
19
+ export var checkIsAppleDevice = function checkIsAppleDevice(isApple) {
20
+ if (isApple !== undefined) {
21
+ return isApple;
22
+ }
23
+ if (typeof window === 'undefined' || typeof navigator === 'undefined') {
24
+ return false; // 处理 SSR 环境
25
+ }
26
+ var userAgent = navigator.userAgent.toLowerCase();
27
+ return /mac|iphone|ipod|ipad|ios/i.test(userAgent);
28
+ };
@@ -0,0 +1,22 @@
1
+ import { type CSSProperties } from 'react';
2
+ export interface HotkeyInputProps {
3
+ allowReset?: boolean;
4
+ className?: string;
5
+ defaultValue?: string;
6
+ disabled?: boolean;
7
+ hotkeyConflicts?: string[];
8
+ isApple?: boolean;
9
+ onChange?: (value: string) => void;
10
+ onConflict?: (conflictKey: string) => void;
11
+ placeholder?: string;
12
+ style?: CSSProperties;
13
+ texts?: {
14
+ conflicts?: string;
15
+ invalidCombination?: string;
16
+ reset?: string;
17
+ };
18
+ value?: string;
19
+ variant?: 'ghost' | 'block' | 'pure';
20
+ }
21
+ declare const HotkeyInput: import("react").NamedExoticComponent<HotkeyInputProps>;
22
+ export default HotkeyInput;
@@ -0,0 +1,246 @@
1
+ 'use client';
2
+
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
+ 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; }
5
+ 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; }
6
+ 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; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+ 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."); }
12
+ 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); }
13
+ 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; }
14
+ 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; } }
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+ import { isEqual } from 'lodash-es';
17
+ import { Undo2Icon } from 'lucide-react';
18
+ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
+ import { useRecordHotkeys } from 'react-hotkeys-hook';
20
+ import { Flexbox } from 'react-layout-kit';
21
+ import ActionIcon from "../ActionIcon";
22
+ import Hotkey from "../Hotkey";
23
+ import { checkIsAppleDevice, splitKeysByPlus } from "../Hotkey/utils";
24
+ import { useStyles } from "./style";
25
+
26
+ // 修饰键列表
27
+ import { jsx as _jsx } from "react/jsx-runtime";
28
+ import { jsxs as _jsxs } from "react/jsx-runtime";
29
+ var MODIFIER_KEYS = new Set(['alt', 'mod', 'shift', 'meta', 'ctrl', 'control']);
30
+ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
31
+ var _ref$value = _ref.value,
32
+ value = _ref$value === void 0 ? '' : _ref$value,
33
+ _ref$defaultValue = _ref.defaultValue,
34
+ defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
35
+ onChange = _ref.onChange,
36
+ onConflict = _ref.onConflict,
37
+ _ref$placeholder = _ref.placeholder,
38
+ placeholder = _ref$placeholder === void 0 ? 'Press keys to record shortcut' : _ref$placeholder,
39
+ _ref$disabled = _ref.disabled,
40
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
41
+ _ref$allowReset = _ref.allowReset,
42
+ allowReset = _ref$allowReset === void 0 ? true : _ref$allowReset,
43
+ style = _ref.style,
44
+ className = _ref.className,
45
+ _ref$hotkeyConflicts = _ref.hotkeyConflicts,
46
+ hotkeyConflicts = _ref$hotkeyConflicts === void 0 ? [] : _ref$hotkeyConflicts,
47
+ _ref$variant = _ref.variant,
48
+ variant = _ref$variant === void 0 ? 'ghost' : _ref$variant,
49
+ texts = _ref.texts,
50
+ isApple = _ref.isApple;
51
+ var _useState = useState(false),
52
+ _useState2 = _slicedToArray(_useState, 2),
53
+ isFocused = _useState2[0],
54
+ setIsFocused = _useState2[1];
55
+ var _useState3 = useState(false),
56
+ _useState4 = _slicedToArray(_useState3, 2),
57
+ hasConflict = _useState4[0],
58
+ setHasConflict = _useState4[1];
59
+ var _useState5 = useState(false),
60
+ _useState6 = _slicedToArray(_useState5, 2),
61
+ hasInvalidCombination = _useState6[0],
62
+ setHasInvalidCombination = _useState6[1];
63
+ var inputRef = useRef(null);
64
+ var _useStyles = useStyles({
65
+ variant: variant
66
+ }),
67
+ cx = _useStyles.cx,
68
+ styles = _useStyles.styles;
69
+ var isAppleDevice = useMemo(function () {
70
+ return checkIsAppleDevice(isApple);
71
+ }, [isApple]);
72
+
73
+ // 使用 useRecordHotkeys 处理快捷键录入
74
+ var _useRecordHotkeys = useRecordHotkeys(),
75
+ _useRecordHotkeys2 = _slicedToArray(_useRecordHotkeys, 2),
76
+ recordedKeys = _useRecordHotkeys2[0],
77
+ _useRecordHotkeys2$ = _useRecordHotkeys2[1],
78
+ start = _useRecordHotkeys2$.start,
79
+ stop = _useRecordHotkeys2$.stop,
80
+ isRecording = _useRecordHotkeys2$.isRecording;
81
+
82
+ // 处理按键,保证格式正确:修饰键在前,最多一个非修饰键在后
83
+ var formatKeys = useCallback(function (keysSet) {
84
+ var modifiers = [];
85
+ var normalKeys = [];
86
+ var _iterator = _createForOfIteratorHelper(keysSet),
87
+ _step;
88
+ try {
89
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
90
+ var key = _step.value;
91
+ // 处理不同表示的修饰键
92
+ var normalizedKey = key.toLowerCase();
93
+ if (MODIFIER_KEYS.has(normalizedKey)) {
94
+ // 统一修饰键表示
95
+ if (!isAppleDevice && normalizedKey === 'ctrl' || isAppleDevice && normalizedKey === 'meta') {
96
+ if (!modifiers.includes('mod')) modifiers.push('mod');
97
+ } else if (!modifiers.includes(normalizedKey)) {
98
+ modifiers.push(normalizedKey);
99
+ }
100
+ } else {
101
+ normalKeys.push(key);
102
+ }
103
+ }
104
+
105
+ // 至少需要一个修饰键
106
+ } catch (err) {
107
+ _iterator.e(err);
108
+ } finally {
109
+ _iterator.f();
110
+ }
111
+ if (modifiers.length === 0 && normalKeys.length > 0) {
112
+ return {
113
+ isValid: false,
114
+ keys: []
115
+ };
116
+ }
117
+
118
+ // 只允许一个非修饰键,如果有多个,只保留最后一个
119
+ var finalKey = normalKeys.length > 0 ? [normalKeys.at(-1)] : [];
120
+ var validKeys = [].concat(modifiers, finalKey);
121
+
122
+ // 组合必须包含至少一个按键
123
+ return {
124
+ isValid: validKeys.length > 0,
125
+ keys: validKeys
126
+ };
127
+ }, []);
128
+
129
+ // 获取格式化后的按键字符串
130
+ var _formatKeys = formatKeys(recordedKeys),
131
+ isValid = _formatKeys.isValid,
132
+ keys = _formatKeys.keys;
133
+ var keysString = keys.join('+');
134
+
135
+ // 检查快捷键冲突
136
+ var checkHotkeyConflict = useCallback(function (newHotkey) {
137
+ return hotkeyConflicts.some(function (conflictKey) {
138
+ var newKeys = splitKeysByPlus(newHotkey);
139
+ var conflictKeys = splitKeysByPlus(conflictKey);
140
+ return isEqual(newKeys.sort(), conflictKeys.sort());
141
+ });
142
+ }, [hotkeyConflicts]);
143
+
144
+ // 当按键组合完成时处理结果
145
+ useEffect(function () {
146
+ if (recordedKeys.size > 0 && !isRecording) {
147
+ if (!isValid) {
148
+ setHasInvalidCombination(true);
149
+ setHasConflict(false);
150
+ return;
151
+ }
152
+ setHasInvalidCombination(false);
153
+ var newKeysString = keysString;
154
+
155
+ // 检查冲突
156
+ var conflict = checkHotkeyConflict(newKeysString);
157
+ if (conflict) {
158
+ setHasConflict(true);
159
+ onConflict === null || onConflict === void 0 || onConflict(newKeysString);
160
+ } else {
161
+ setHasConflict(false);
162
+ onChange === null || onChange === void 0 || onChange(newKeysString);
163
+ }
164
+ }
165
+ }, [recordedKeys, isRecording, isValid, keysString, checkHotkeyConflict, onChange, onConflict]);
166
+
167
+ // 处理输入框焦点
168
+ var handleFocus = useCallback(function () {
169
+ if (disabled) return;
170
+ setIsFocused(true);
171
+ setHasConflict(false);
172
+ setHasInvalidCombination(false);
173
+ start(); // 开始记录
174
+ }, [disabled, start]);
175
+ var handleBlur = useCallback(function () {
176
+ setIsFocused(false);
177
+ stop(); // 停止记录
178
+ }, [stop]);
179
+
180
+ // 重置功能
181
+ var handleReset = useCallback(function (e) {
182
+ var _inputRef$current;
183
+ e.preventDefault();
184
+ e.stopPropagation();
185
+ onChange === null || onChange === void 0 || onChange(defaultValue);
186
+ setHasConflict(false);
187
+ setHasInvalidCombination(false);
188
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.blur();
189
+ }, [onChange, defaultValue]);
190
+ return /*#__PURE__*/_jsxs(Flexbox, {
191
+ className: className,
192
+ gap: 8,
193
+ style: _objectSpread({
194
+ position: 'relative'
195
+ }, style),
196
+ children: [/*#__PURE__*/_jsxs(Flexbox, {
197
+ align: 'center',
198
+ className: cx(styles.input, isFocused && styles.inputFocused, (hasConflict || hasInvalidCombination) && styles.inputError, disabled && styles.inputDisabled),
199
+ horizontal: true,
200
+ justify: 'space-between',
201
+ onClick: function onClick() {
202
+ var _inputRef$current2;
203
+ return !disabled && !isFocused && ((_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus());
204
+ },
205
+ children: [/*#__PURE__*/_jsx("div", {
206
+ style: {
207
+ pointerEvents: 'none'
208
+ },
209
+ children: isRecording ? /*#__PURE__*/_jsx("span", {
210
+ className: styles.placeholder,
211
+ children: keys.length > 0 ? /*#__PURE__*/_jsx(Hotkey, {
212
+ keys: keysString
213
+ }) : placeholder
214
+ }) : value ? /*#__PURE__*/_jsx(Hotkey, {
215
+ keys: value
216
+ }) : /*#__PURE__*/_jsx("span", {
217
+ className: styles.placeholder,
218
+ children: placeholder
219
+ })
220
+ }), /*#__PURE__*/_jsx("input", {
221
+ className: styles.hiddenInput,
222
+ disabled: disabled,
223
+ onBlur: handleBlur,
224
+ onFocus: handleFocus,
225
+ readOnly: true,
226
+ ref: inputRef,
227
+ style: {
228
+ pointerEvents: 'none'
229
+ }
230
+ }), allowReset && value && value !== defaultValue && !disabled && /*#__PURE__*/_jsx(ActionIcon, {
231
+ active: true,
232
+ icon: Undo2Icon,
233
+ onClick: handleReset,
234
+ size: 'small',
235
+ title: (texts === null || texts === void 0 ? void 0 : texts.reset) || 'Reset to default'
236
+ })]
237
+ }), hasConflict && /*#__PURE__*/_jsx("div", {
238
+ className: styles.errorText,
239
+ children: (texts === null || texts === void 0 ? void 0 : texts.conflicts) || 'This shortcut conflicts with an existing one.'
240
+ }), hasInvalidCombination && /*#__PURE__*/_jsx("div", {
241
+ className: styles.errorText,
242
+ children: (texts === null || texts === void 0 ? void 0 : texts.invalidCombination) || 'Shortcut must include a modifier key (Ctrl, Alt, Shift) and only one regular key.'
243
+ })]
244
+ });
245
+ });
246
+ export default HotkeyInput;
@@ -0,0 +1,11 @@
1
+ export declare const useStyles: (props?: {
2
+ variant: 'ghost' | 'block' | 'pure';
3
+ } | undefined) => import("antd-style").ReturnStyles<{
4
+ errorText: import("antd-style").SerializedStyles;
5
+ hiddenInput: import("antd-style").SerializedStyles;
6
+ input: string;
7
+ inputDisabled: string;
8
+ inputError: import("antd-style").SerializedStyles;
9
+ inputFocused: string;
10
+ placeholder: import("antd-style").SerializedStyles;
11
+ }>;
@@ -0,0 +1,20 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ import { createStyles } from 'antd-style';
4
+ export var useStyles = createStyles(function (_ref, _ref2) {
5
+ var cx = _ref.cx,
6
+ css = _ref.css,
7
+ token = _ref.token,
8
+ prefixCls = _ref.prefixCls;
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);
11
+ return {
12
+ errorText: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n font-size: 12px;\n color: ", ";\n "])), token.colorError),
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 "]))),
14
+ input: cx(variant !== 'pure' && typeStylish, css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n max-width: 100%;\n height: ", ";\n padding: ", ";\n "])), variant === 'pure' ? 'unset' : '36px', variant === 'pure' ? '0' : '0 12px')),
15
+ inputDisabled: cx(css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n cursor: not-allowed;\n opacity: 0.65;\n "]))), variant !== 'pure' && css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n background: ", ";\n "])), token.colorFillTertiary)),
16
+ inputError: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n border: 1px solid ", ";\n "])), token.colorError),
17
+ inputFocused: cx(variant !== 'pure' && css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n border-color: ", ";\n "])), token.colorTextQuaternary)),
18
+ placeholder: css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n color: ", ";\n "])), token.colorTextDescription)
19
+ };
20
+ });
@@ -16,7 +16,7 @@ export var useStyles = createStyles(function (_ref, _ref2) {
16
16
  _ref2$lineHeight = _ref2.lineHeight,
17
17
  lineHeight = _ref2$lineHeight === void 0 ? 1.8 : _ref2$lineHeight;
18
18
  return {
19
- __root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: ", "px;\n --lobe-markdown-header-multiple: ", ";\n --lobe-markdown-margin-multiple: ", ";\n --lobe-markdown-line-height: ", ";\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n width: 100%;\n max-width: 100%;\n padding-inline: 1px;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n\n ", " {\n font-size: ", ";\n line-height: ", ";\n }\n "])), fontSize, headerMultiple, marginMultiple, lineHeight, token.borderRadiusLG, isDarkMode ? token.colorBorderSecondary : rgba(token.colorBorderSecondary, 0.5), IGNORE_CLASSNAME, token.fontSize, token.lineHeight),
19
+ __root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: ", "px;\n --lobe-markdown-header-multiple: ", ";\n --lobe-markdown-margin-multiple: ", ";\n --lobe-markdown-line-height: ", ";\n --lobe-markdown-border-radius: ", ";\n --lobe-markdown-border-color: ", ";\n\n position: relative;\n\n width: 100%;\n max-width: 100%;\n padding-inline: 1px;\n\n font-size: var(--lobe-markdown-font-size);\n line-height: var(--lobe-markdown-line-height);\n word-break: break-word;\n\n ", " {\n font-size: 14px;\n line-height: 1.5;\n }\n "])), fontSize, headerMultiple, marginMultiple, lineHeight, token.borderRadiusLG, isDarkMode ? token.colorBorderSecondary : rgba(token.colorBorderSecondary, 0.5), IGNORE_CLASSNAME),
20
20
  a: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n a:not(", " a) {\n color: ", ";\n\n &:hover {\n color: ", ";\n }\n }\n "])), IGNORE_CLASSNAME, token.colorInfoText, token.colorInfoHover),
21
21
  blockquote: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n blockquote:not(", " blockquote) {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 1em);\n margin-inline: 0;\n padding-block: 0;\n padding-inline: 1em;\n\n color: ", ";\n\n border-inline-start: solid 4px ", ";\n }\n "])), IGNORE_CLASSNAME, token.colorTextSecondary, token.colorBorder),
22
22
  code: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n code:not(", " code) {\n &:not(:has(span)) {\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n\n font-family: ", ";\n font-size: 0.875em;\n line-height: 1;\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n border: 1px solid var(--lobe-markdown-border-color);\n border-radius: 0.25em;\n }\n }\n "])), IGNORE_CLASSNAME, token.fontFamilyCode, token.colorFillSecondary),
@@ -19,7 +19,7 @@ import { LucideLoader2, Search } from 'lucide-react';
19
19
  import { memo, useRef, useState } from 'react';
20
20
  import { useHotkeys } from 'react-hotkeys-hook';
21
21
  import useControlledState from 'use-merge-value';
22
- import HotKeys from "../HotKeys";
22
+ import Hotkey from "../Hotkey";
23
23
  import Icon from "../Icon";
24
24
  import { Input } from "../Input";
25
25
  import Spotlight from "../awesome/Spotlight";
@@ -121,7 +121,7 @@ var SearchBar = /*#__PURE__*/memo(function (_ref) {
121
121
  ref: inputReference,
122
122
  style: inputStyle,
123
123
  value: value
124
- }, rest)), enableShortKey && showTag && !inputValue && /*#__PURE__*/_jsx(HotKeys, {
124
+ }, rest)), enableShortKey && showTag && !inputValue && /*#__PURE__*/_jsx(Hotkey, {
125
125
  className: cx(styles.tag, shortKeyClassName),
126
126
  compact: true,
127
127
  keys: hotKey,
@@ -31,7 +31,8 @@ export { default as Grid, type GridProps } from './Grid';
31
31
  export { default as Header, type HeaderProps } from './Header';
32
32
  export { default as Highlighter, type HighlighterProps, SyntaxHighlighter, type SyntaxHighlighterProps, } from './Highlighter';
33
33
  export { useChatListActionsBar } from './hooks/useChatListActionsBar';
34
- export { default as HotKeys, type HotKeysProps } from './HotKeys';
34
+ export { default as Hotkey, type HotkeyProps } from './Hotkey';
35
+ export { default as HotkeyInput, type HotkeyInputProps } from './HotkeyInput';
35
36
  export { default as Icon, type IconProps, type IconSize } from './Icon';
36
37
  export * from './Icon/icons';
37
38
  export { default as Image, type ImageProps } from './Image';
package/es/components.js CHANGED
@@ -31,7 +31,8 @@ export { default as Grid } from "./Grid";
31
31
  export { default as Header } from "./Header";
32
32
  export { default as Highlighter, SyntaxHighlighter } from "./Highlighter";
33
33
  export { useChatListActionsBar } from "./hooks/useChatListActionsBar";
34
- export { default as HotKeys } from "./HotKeys";
34
+ export { default as Hotkey } from "./Hotkey";
35
+ export { default as HotkeyInput } from "./HotkeyInput";
35
36
  export { default as Icon } from "./Icon";
36
37
  export * from "./Icon/icons";
37
38
  export { default as Image } from "./Image";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.167.0",
3
+ "version": "1.168.0",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -1,2 +0,0 @@
1
- export declare const splitKeysByPlus: (keys: string) => string[];
2
- export declare const startCase: (str: string) => string;
@@ -1,13 +0,0 @@
1
- export var splitKeysByPlus = function splitKeysByPlus(keys) {
2
- var placeholder = 'PLACEHOLDER';
3
- var parts = keys.replaceAll('++', "+".concat(placeholder)).split('+');
4
- return parts.filter(Boolean).map(function (part) {
5
- if (part === placeholder) return '+';
6
- return part;
7
- });
8
- };
9
- export var startCase = function startCase(str) {
10
- return str.replaceAll(/([A-Z])/g, ' $1').replace(/^./, function (s) {
11
- return s.toUpperCase();
12
- }).trim();
13
- };