@lobehub/ui 1.168.0 → 1.168.2

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.
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const RightClickIcon: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
3
+ export default RightClickIcon;
@@ -0,0 +1,9 @@
1
+ import { createLucideIcon } from 'lucide-react';
2
+ var RightClickIcon = createLucideIcon('right-click', [['path', {
3
+ d: 'M19 10a7 7 0 10-14 0v4a7 7 0 1014 0v-4zM2 9.333C2 6.36 3.491 3.71 5.814 2',
4
+ key: '1'
5
+ }], ['path', {
6
+ d: 'M12 4v7H6',
7
+ key: '2'
8
+ }]]);
9
+ export default RightClickIcon;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const RightClickIcon: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
3
+ export default RightClickIcon;
@@ -0,0 +1,9 @@
1
+ import { createLucideIcon } from 'lucide-react';
2
+ var RightClickIcon = createLucideIcon('right-click', [['path', {
3
+ d: 'M19 10a7 7 0 10-14 0v4a7 7 0 1014 0v-4zM22 9.333C22 6.36 20.509 3.71 18.186 2',
4
+ key: '1'
5
+ }], ['path', {
6
+ d: 'M12 4v7h6',
7
+ key: '2'
8
+ }]]);
9
+ export default RightClickIcon;
@@ -1,12 +1,9 @@
1
1
  'use client';
2
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
3
  var _excluded = ["classNames", "styles", "keys", "desc", "inverseTheme", "isApple", "compact", "className", "style"];
4
+ 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); }
5
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; }
6
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; }
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; }
8
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
- 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); }
10
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
8
  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
9
  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); }
@@ -15,26 +12,85 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
15
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
13
  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
14
  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
- import { isString } from 'lodash-es';
19
- import { ChevronUpIcon, Command, Delete, Option } from 'lucide-react';
15
+ 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; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
+ 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); }
18
+ import { ArrowBigUpIcon, ArrowDownIcon, ArrowLeftIcon, ArrowRightIcon, ArrowRightToLineIcon, ArrowUpIcon, ChevronUpIcon, Command, CornerDownLeftIcon, Delete, Grid2X2Icon, MouseIcon, Option, SpaceIcon } from 'lucide-react';
20
19
  import { memo, useEffect, useMemo, useState } from 'react';
21
20
  import { Flexbox } from 'react-layout-kit';
22
21
  import Icon from "../Icon";
22
+ import LeftClickIcon from "./components/LeftClickIcon";
23
+ import RightClickIcon from "./components/RightClickIcon";
23
24
  import { useStyles } from "./style";
24
- import { ALT_KEY, BACKSPACE_KEY, CONTROL_KEY, META_KEY, MOD_KEY, checkIsAppleDevice, splitKeysByPlus, startCase } from "./utils";
25
+ import { KeyMap } from "./type";
26
+ import { checkIsAppleDevice, splitKeysByPlus, startCase } from "./utils";
25
27
  import { jsx as _jsx } from "react/jsx-runtime";
26
28
  import { jsxs as _jsxs } from "react/jsx-runtime";
27
- var Hotkey = /*#__PURE__*/memo(function (_ref) {
28
- var classNames = _ref.classNames,
29
- styles = _ref.styles,
30
- keys = _ref.keys,
31
- desc = _ref.desc,
32
- inverseTheme = _ref.inverseTheme,
33
- isApple = _ref.isApple,
34
- compact = _ref.compact,
35
- className = _ref.className,
36
- style = _ref.style,
37
- rest = _objectWithoutProperties(_ref, _excluded);
29
+ var mappingKey = function mappingKey(isAppleDevice) {
30
+ var _ref;
31
+ return _ref = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref, KeyMap.Alt, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
32
+ icon: Option
33
+ }) : 'Alt'), KeyMap.Backspace, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
34
+ icon: Delete
35
+ }) : 'Backspace'), KeyMap.Ctrl, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
36
+ icon: ChevronUpIcon
37
+ }) : 'Ctrl'), KeyMap.Down, /*#__PURE__*/_jsx(Icon, {
38
+ icon: ArrowDownIcon
39
+ })), KeyMap.Enter, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
40
+ icon: CornerDownLeftIcon
41
+ }) : 'Enter'), KeyMap.LeftClick, /*#__PURE__*/_jsx(Icon, {
42
+ icon: LeftClickIcon,
43
+ size: {
44
+ fontSize: '1.15em',
45
+ strokeWidth: 1.75
46
+ }
47
+ })), KeyMap.Left, /*#__PURE__*/_jsx(Icon, {
48
+ icon: ArrowLeftIcon
49
+ })), KeyMap.Meta, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
50
+ icon: Command
51
+ }) : /*#__PURE__*/_jsx(Icon, {
52
+ icon: Grid2X2Icon
53
+ })), KeyMap.MiddleClick, /*#__PURE__*/_jsx(Icon, {
54
+ icon: MouseIcon,
55
+ size: {
56
+ fontSize: '1.15em',
57
+ strokeWidth: 1.75
58
+ }
59
+ })), KeyMap.Mod, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
60
+ icon: Command
61
+ }) : 'Ctrl'), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref, KeyMap.RightClick, /*#__PURE__*/_jsx(Icon, {
62
+ icon: RightClickIcon,
63
+ size: {
64
+ fontSize: '1.15em',
65
+ strokeWidth: 1.75
66
+ }
67
+ })), KeyMap.Right, /*#__PURE__*/_jsx(Icon, {
68
+ icon: ArrowRightIcon
69
+ })), KeyMap.Shift, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
70
+ icon: ArrowBigUpIcon,
71
+ size: {
72
+ fontSize: '1.15em',
73
+ strokeWidth: 1.75
74
+ }
75
+ }) : 'Shift'), KeyMap.Space, /*#__PURE__*/_jsx(Icon, {
76
+ icon: SpaceIcon
77
+ })), KeyMap.Tab, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
78
+ icon: ArrowRightToLineIcon
79
+ }) : 'Tab'), KeyMap.Up, /*#__PURE__*/_jsx(Icon, {
80
+ icon: ArrowUpIcon
81
+ }));
82
+ };
83
+ var Hotkey = /*#__PURE__*/memo(function (_ref2) {
84
+ var classNames = _ref2.classNames,
85
+ styles = _ref2.styles,
86
+ keys = _ref2.keys,
87
+ desc = _ref2.desc,
88
+ inverseTheme = _ref2.inverseTheme,
89
+ isApple = _ref2.isApple,
90
+ compact = _ref2.compact,
91
+ className = _ref2.className,
92
+ style = _ref2.style,
93
+ rest = _objectWithoutProperties(_ref2, _excluded);
38
94
  var _useStyles = useStyles(inverseTheme),
39
95
  cx = _useStyles.cx,
40
96
  s = _useStyles.styles;
@@ -47,23 +103,12 @@ var Hotkey = /*#__PURE__*/memo(function (_ref) {
47
103
  return checkIsAppleDevice(isApple);
48
104
  }, [isApple]);
49
105
  useEffect(function () {
50
- var mapping = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ALT_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
51
- icon: Option
52
- }) : 'alt'), BACKSPACE_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
53
- icon: Delete
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, {
59
- icon: Command
60
- }) : 'ctrl');
61
- var newValue = splitKeysByPlus(keys).map(function (k) {
62
- var _mapping$k;
63
- return (_mapping$k = mapping[k]) !== null && _mapping$k !== void 0 ? _mapping$k : k;
64
- });
106
+ var newValue = splitKeysByPlus(keys);
65
107
  setKeysGroup(newValue);
66
- }, [keys, isAppleDevice]);
108
+ }, [keys]);
109
+ var mapping = useMemo(function () {
110
+ return mappingKey(isAppleDevice);
111
+ }, [isAppleDevice]);
67
112
  return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
68
113
  align: 'center',
69
114
  className: cx(s, className),
@@ -87,15 +132,17 @@ var Hotkey = /*#__PURE__*/memo(function (_ref) {
87
132
  horizontal: true,
88
133
  style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
89
134
  children: keysGroup.map(function (key, index) {
135
+ var _mapping$key;
90
136
  return /*#__PURE__*/_jsx("div", {
91
- children: isString(key) ? startCase(key) : key
137
+ children: (_mapping$key = mapping[key]) !== null && _mapping$key !== void 0 ? _mapping$key : startCase(key)
92
138
  }, index);
93
139
  })
94
140
  }) : keysGroup.map(function (key, index) {
141
+ var _mapping$key2;
95
142
  return /*#__PURE__*/_jsx("kbd", {
96
143
  className: classNames === null || classNames === void 0 ? void 0 : classNames.descClassName,
97
144
  style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
98
- children: isString(key) ? startCase(key) : key
145
+ children: (_mapping$key2 = mapping[key]) !== null && _mapping$key2 !== void 0 ? _mapping$key2 : startCase(key)
99
146
  }, index);
100
147
  })]
101
148
  }));
@@ -0,0 +1,18 @@
1
+ export declare const enum KeyMap {
2
+ Alt = "alt",
3
+ Backspace = "backspace",
4
+ Ctrl = "ctrl",
5
+ Down = "down",
6
+ Enter = "enter",
7
+ Left = "left",
8
+ LeftClick = "left-click",
9
+ Meta = "meta",
10
+ MiddleClick = "middle-click",
11
+ Mod = "mod",
12
+ Right = "right",
13
+ RightClick = "right-click",
14
+ Shift = "shift",
15
+ Space = "space",
16
+ Tab = "tab",
17
+ Up = "up"
18
+ }
@@ -0,0 +1,18 @@
1
+ export var KeyMap = {
2
+ Alt: "alt",
3
+ Backspace: "backspace",
4
+ Ctrl: "ctrl",
5
+ Down: "down",
6
+ Enter: "enter",
7
+ Left: "left",
8
+ LeftClick: "left-click",
9
+ Meta: "meta",
10
+ MiddleClick: "middle-click",
11
+ Mod: "mod",
12
+ Right: "right",
13
+ RightClick: "right-click",
14
+ Shift: "shift",
15
+ Space: "space",
16
+ Tab: "tab",
17
+ Up: "up"
18
+ };
@@ -1,8 +1,3 @@
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
1
  export declare const splitKeysByPlus: (keys: string) => string[];
7
2
  export declare const startCase: (str: string) => string;
8
3
  export declare const checkIsAppleDevice: (isApple?: boolean) => boolean;
@@ -1,8 +1,3 @@
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
1
  export var splitKeysByPlus = function splitKeysByPlus(keys) {
7
2
  var placeholder = 'PLACEHOLDER';
8
3
  var parts = keys.replaceAll('++', "+".concat(placeholder)).split('+');
@@ -16,7 +16,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
16
  import { isEqual } from 'lodash-es';
17
17
  import { Undo2Icon } from 'lucide-react';
18
18
  import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
- import { useRecordHotkeys } from 'react-hotkeys-hook';
19
+ import { useHotkeys, useRecordHotkeys } from 'react-hotkeys-hook';
20
20
  import { Flexbox } from 'react-layout-kit';
21
21
  import ActionIcon from "../ActionIcon";
22
22
  import Hotkey from "../Hotkey";
@@ -77,7 +77,18 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
77
77
  _useRecordHotkeys2$ = _useRecordHotkeys2[1],
78
78
  start = _useRecordHotkeys2$.start,
79
79
  stop = _useRecordHotkeys2$.stop,
80
- isRecording = _useRecordHotkeys2$.isRecording;
80
+ isRecording = _useRecordHotkeys2$.isRecording,
81
+ resetKeys = _useRecordHotkeys2$.resetKeys;
82
+ useHotkeys('*', function () {
83
+ var _inputRef$current;
84
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.blur();
85
+ }, {
86
+ enableOnContentEditable: true,
87
+ enableOnFormTags: true,
88
+ enabled: isRecording && !disabled,
89
+ keydown: false,
90
+ keyup: true
91
+ });
81
92
 
82
93
  // 处理按键,保证格式正确:修饰键在前,最多一个非修饰键在后
83
94
  var formatKeys = useCallback(function (keysSet) {
@@ -155,6 +166,7 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
155
166
  // 检查冲突
156
167
  var conflict = checkHotkeyConflict(newKeysString);
157
168
  if (conflict) {
169
+ console.log('conflict');
158
170
  setHasConflict(true);
159
171
  onConflict === null || onConflict === void 0 || onConflict(newKeysString);
160
172
  } else {
@@ -165,28 +177,28 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
165
177
  }, [recordedKeys, isRecording, isValid, keysString, checkHotkeyConflict, onChange, onConflict]);
166
178
 
167
179
  // 处理输入框焦点
168
- var handleFocus = useCallback(function () {
180
+ var handleFocus = function handleFocus() {
169
181
  if (disabled) return;
170
182
  setIsFocused(true);
171
183
  setHasConflict(false);
172
184
  setHasInvalidCombination(false);
173
185
  start(); // 开始记录
174
- }, [disabled, start]);
175
- var handleBlur = useCallback(function () {
186
+ };
187
+ var handleBlur = function handleBlur() {
176
188
  setIsFocused(false);
177
189
  stop(); // 停止记录
178
- }, [stop]);
190
+ };
179
191
 
180
192
  // 重置功能
181
- var handleReset = useCallback(function (e) {
182
- var _inputRef$current;
193
+ var handleReset = function handleReset(e) {
183
194
  e.preventDefault();
184
195
  e.stopPropagation();
185
196
  onChange === null || onChange === void 0 || onChange(defaultValue);
197
+ resetKeys();
186
198
  setHasConflict(false);
187
199
  setHasInvalidCombination(false);
188
- (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.blur();
189
- }, [onChange, defaultValue]);
200
+ handleBlur();
201
+ };
190
202
  return /*#__PURE__*/_jsxs(Flexbox, {
191
203
  className: className,
192
204
  gap: 8,
@@ -32,6 +32,7 @@ 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
34
  export { default as Hotkey, type HotkeyProps } from './Hotkey';
35
+ export { KeyMap } from './Hotkey/type';
35
36
  export { default as HotkeyInput, type HotkeyInputProps } from './HotkeyInput';
36
37
  export { default as Icon, type IconProps, type IconSize } from './Icon';
37
38
  export * from './Icon/icons';
package/es/components.js CHANGED
@@ -32,6 +32,7 @@ export { default as Header } from "./Header";
32
32
  export { default as Highlighter, SyntaxHighlighter } from "./Highlighter";
33
33
  export { useChatListActionsBar } from "./hooks/useChatListActionsBar";
34
34
  export { default as Hotkey } from "./Hotkey";
35
+ export { KeyMap } from "./Hotkey/type";
35
36
  export { default as HotkeyInput } from "./HotkeyInput";
36
37
  export { default as Icon } from "./Icon";
37
38
  export * from "./Icon/icons";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.168.0",
3
+ "version": "1.168.2",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",