@lobehub/ui 1.168.0 → 1.168.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,84 @@ 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 { ALT_KEY, BACKSPACE_KEY, CONTROL_KEY, DOWN_KEY, ENTER_KEY, LEFT_CLICK_KEY, LEFT_KEY, META_KEY, MID_CLICK_KEY, MOD_KEY, RIGHT_CLICK_KEY, RIGHT_KEY, SHIFT_KEY, SPACE_KEY, TAB_KEY, UP_KEY, checkIsAppleDevice, splitKeysByPlus, startCase } from "./utils";
25
26
  import { jsx as _jsx } from "react/jsx-runtime";
26
27
  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);
28
+ var mappingKey = function mappingKey(isAppleDevice) {
29
+ var _ref;
30
+ return _ref = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref, ALT_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
31
+ icon: Option
32
+ }) : 'Alt'), BACKSPACE_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
33
+ icon: Delete
34
+ }) : 'Backspace'), CONTROL_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
35
+ icon: ChevronUpIcon
36
+ }) : 'Ctrl'), DOWN_KEY, /*#__PURE__*/_jsx(Icon, {
37
+ icon: ArrowDownIcon
38
+ })), ENTER_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
39
+ icon: CornerDownLeftIcon
40
+ }) : 'Enter'), LEFT_CLICK_KEY, /*#__PURE__*/_jsx(Icon, {
41
+ icon: LeftClickIcon,
42
+ size: {
43
+ fontSize: '1.15em',
44
+ strokeWidth: 1.75
45
+ }
46
+ })), LEFT_KEY, /*#__PURE__*/_jsx(Icon, {
47
+ icon: ArrowLeftIcon
48
+ })), META_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
49
+ icon: Command
50
+ }) : /*#__PURE__*/_jsx(Icon, {
51
+ icon: Grid2X2Icon
52
+ })), MID_CLICK_KEY, /*#__PURE__*/_jsx(Icon, {
53
+ icon: MouseIcon,
54
+ size: {
55
+ fontSize: '1.15em',
56
+ strokeWidth: 1.75
57
+ }
58
+ })), MOD_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
59
+ icon: Command
60
+ }) : 'Ctrl'), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_ref, RIGHT_CLICK_KEY, /*#__PURE__*/_jsx(Icon, {
61
+ icon: RightClickIcon,
62
+ size: {
63
+ fontSize: '1.15em',
64
+ strokeWidth: 1.75
65
+ }
66
+ })), RIGHT_KEY, /*#__PURE__*/_jsx(Icon, {
67
+ icon: ArrowRightIcon
68
+ })), SHIFT_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
69
+ icon: ArrowBigUpIcon,
70
+ size: {
71
+ fontSize: '1.15em',
72
+ strokeWidth: 1.75
73
+ }
74
+ }) : 'Shift'), SPACE_KEY, /*#__PURE__*/_jsx(Icon, {
75
+ icon: SpaceIcon
76
+ })), TAB_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
77
+ icon: ArrowRightToLineIcon
78
+ }) : 'Tab'), UP_KEY, /*#__PURE__*/_jsx(Icon, {
79
+ icon: ArrowUpIcon
80
+ }));
81
+ };
82
+ var Hotkey = /*#__PURE__*/memo(function (_ref2) {
83
+ var classNames = _ref2.classNames,
84
+ styles = _ref2.styles,
85
+ keys = _ref2.keys,
86
+ desc = _ref2.desc,
87
+ inverseTheme = _ref2.inverseTheme,
88
+ isApple = _ref2.isApple,
89
+ compact = _ref2.compact,
90
+ className = _ref2.className,
91
+ style = _ref2.style,
92
+ rest = _objectWithoutProperties(_ref2, _excluded);
38
93
  var _useStyles = useStyles(inverseTheme),
39
94
  cx = _useStyles.cx,
40
95
  s = _useStyles.styles;
@@ -47,23 +102,12 @@ var Hotkey = /*#__PURE__*/memo(function (_ref) {
47
102
  return checkIsAppleDevice(isApple);
48
103
  }, [isApple]);
49
104
  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
- });
105
+ var newValue = splitKeysByPlus(keys);
65
106
  setKeysGroup(newValue);
66
- }, [keys, isAppleDevice]);
107
+ }, [keys]);
108
+ var mapping = useMemo(function () {
109
+ return mappingKey(isAppleDevice);
110
+ }, [isAppleDevice]);
67
111
  return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
68
112
  align: 'center',
69
113
  className: cx(s, className),
@@ -87,15 +131,17 @@ var Hotkey = /*#__PURE__*/memo(function (_ref) {
87
131
  horizontal: true,
88
132
  style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
89
133
  children: keysGroup.map(function (key, index) {
134
+ var _mapping$key;
90
135
  return /*#__PURE__*/_jsx("div", {
91
- children: isString(key) ? startCase(key) : key
136
+ children: (_mapping$key = mapping[key]) !== null && _mapping$key !== void 0 ? _mapping$key : startCase(key)
92
137
  }, index);
93
138
  })
94
139
  }) : keysGroup.map(function (key, index) {
140
+ var _mapping$key2;
95
141
  return /*#__PURE__*/_jsx("kbd", {
96
142
  className: classNames === null || classNames === void 0 ? void 0 : classNames.descClassName,
97
143
  style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
98
- children: isString(key) ? startCase(key) : key
144
+ children: (_mapping$key2 = mapping[key]) !== null && _mapping$key2 !== void 0 ? _mapping$key2 : startCase(key)
99
145
  }, index);
100
146
  })]
101
147
  }));
@@ -1,8 +1,19 @@
1
1
  export declare const ALT_KEY = "alt";
2
2
  export declare const MOD_KEY = "mod";
3
+ export declare const SHIFT_KEY = "shift";
3
4
  export declare const META_KEY = "meta";
4
5
  export declare const BACKSPACE_KEY = "backspace";
5
6
  export declare const CONTROL_KEY = "ctrl";
7
+ export declare const SPACE_KEY = "space";
8
+ export declare const TAB_KEY = "tab";
9
+ export declare const ENTER_KEY = "enter";
10
+ export declare const LEFT_KEY = "left";
11
+ export declare const RIGHT_KEY = "right";
12
+ export declare const UP_KEY = "up";
13
+ export declare const DOWN_KEY = "down";
14
+ export declare const RIGHT_CLICK_KEY = "right-click";
15
+ export declare const LEFT_CLICK_KEY = "left-click";
16
+ export declare const MID_CLICK_KEY = "mid-click";
6
17
  export declare const splitKeysByPlus: (keys: string) => string[];
7
18
  export declare const startCase: (str: string) => string;
8
19
  export declare const checkIsAppleDevice: (isApple?: boolean) => boolean;
@@ -1,8 +1,19 @@
1
1
  export var ALT_KEY = 'alt';
2
2
  export var MOD_KEY = 'mod';
3
+ export var SHIFT_KEY = 'shift';
3
4
  export var META_KEY = 'meta';
4
5
  export var BACKSPACE_KEY = 'backspace';
5
6
  export var CONTROL_KEY = 'ctrl';
7
+ export var SPACE_KEY = 'space';
8
+ export var TAB_KEY = 'tab';
9
+ export var ENTER_KEY = 'enter';
10
+ export var LEFT_KEY = 'left';
11
+ export var RIGHT_KEY = 'right';
12
+ export var UP_KEY = 'up';
13
+ export var DOWN_KEY = 'down';
14
+ export var RIGHT_CLICK_KEY = 'right-click';
15
+ export var LEFT_CLICK_KEY = 'left-click';
16
+ export var MID_CLICK_KEY = 'mid-click';
6
17
  export var splitKeysByPlus = function splitKeysByPlus(keys) {
7
18
  var placeholder = 'PLACEHOLDER';
8
19
  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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.168.0",
3
+ "version": "1.168.1",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",