@lobehub/ui 1.167.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,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;
@@ -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 { Command, Delete, Option } from 'lucide-react';
20
- import { memo, useEffect, useState } from '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';
19
+ import { memo, useEffect, useMemo, useState } from 'react';
21
20
  import { Flexbox } from 'react-layout-kit';
22
21
  import Icon from "../Icon";
23
- import { ALT_KEY, BACKSPACE_KEY, META_KEY, useStyles } from "./style";
24
- import { splitKeysByPlus, startCase } from "./utils";
22
+ import LeftClickIcon from "./components/LeftClickIcon";
23
+ import RightClickIcon from "./components/RightClickIcon";
24
+ import { useStyles } from "./style";
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 HotKeys = /*#__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;
@@ -43,22 +98,16 @@ var HotKeys = /*#__PURE__*/memo(function (_ref) {
43
98
  keysGroup = _useState2[0],
44
99
  setKeysGroup = _useState2[1];
45
100
  var visibility = typeof window === 'undefined' ? 'hidden' : 'visible';
101
+ var isAppleDevice = useMemo(function () {
102
+ return checkIsAppleDevice(isApple);
103
+ }, [isApple]);
46
104
  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
- icon: Option
51
- }) : 'alt'), BACKSPACE_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
52
- icon: Delete
53
- }) : 'backspace'), META_KEY, isAppleDevice ? /*#__PURE__*/_jsx(Icon, {
54
- icon: Command
55
- }) : 'ctrl');
56
- var newValue = splitKeysByPlus(keys).map(function (k) {
57
- var _mapping$k;
58
- return (_mapping$k = mapping[k]) !== null && _mapping$k !== void 0 ? _mapping$k : k;
59
- });
105
+ var newValue = splitKeysByPlus(keys);
60
106
  setKeysGroup(newValue);
61
- }, [keys, isApple]);
107
+ }, [keys]);
108
+ var mapping = useMemo(function () {
109
+ return mappingKey(isAppleDevice);
110
+ }, [isAppleDevice]);
62
111
  return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
63
112
  align: 'center',
64
113
  className: cx(s, className),
@@ -82,17 +131,19 @@ var HotKeys = /*#__PURE__*/memo(function (_ref) {
82
131
  horizontal: true,
83
132
  style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
84
133
  children: keysGroup.map(function (key, index) {
134
+ var _mapping$key;
85
135
  return /*#__PURE__*/_jsx("div", {
86
- children: isString(key) ? startCase(key) : key
136
+ children: (_mapping$key = mapping[key]) !== null && _mapping$key !== void 0 ? _mapping$key : startCase(key)
87
137
  }, index);
88
138
  })
89
139
  }) : keysGroup.map(function (key, index) {
140
+ var _mapping$key2;
90
141
  return /*#__PURE__*/_jsx("kbd", {
91
142
  className: classNames === null || classNames === void 0 ? void 0 : classNames.descClassName,
92
143
  style: styles === null || styles === void 0 ? void 0 : styles.kbdStyle,
93
- children: isString(key) ? startCase(key) : key
144
+ children: (_mapping$key2 = mapping[key]) !== null && _mapping$key2 !== void 0 ? _mapping$key2 : startCase(key)
94
145
  }, index);
95
146
  })]
96
147
  }));
97
148
  });
98
- export default HotKeys;
149
+ 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,19 @@
1
+ export declare const ALT_KEY = "alt";
2
+ export declare const MOD_KEY = "mod";
3
+ export declare const SHIFT_KEY = "shift";
4
+ export declare const META_KEY = "meta";
5
+ export declare const BACKSPACE_KEY = "backspace";
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";
17
+ export declare const splitKeysByPlus: (keys: string) => string[];
18
+ export declare const startCase: (str: string) => string;
19
+ export declare const checkIsAppleDevice: (isApple?: boolean) => boolean;
@@ -0,0 +1,39 @@
1
+ export var ALT_KEY = 'alt';
2
+ export var MOD_KEY = 'mod';
3
+ export var SHIFT_KEY = 'shift';
4
+ export var META_KEY = 'meta';
5
+ export var BACKSPACE_KEY = 'backspace';
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';
17
+ export var splitKeysByPlus = function splitKeysByPlus(keys) {
18
+ var placeholder = 'PLACEHOLDER';
19
+ var parts = keys.replaceAll('++', "+".concat(placeholder)).split('+');
20
+ return parts.filter(Boolean).map(function (part) {
21
+ if (part === placeholder) return '+';
22
+ return part;
23
+ });
24
+ };
25
+ export var startCase = function startCase(str) {
26
+ return str.replaceAll(/([A-Z])/g, ' $1').replace(/^./, function (s) {
27
+ return s.toUpperCase();
28
+ }).trim();
29
+ };
30
+ export var checkIsAppleDevice = function checkIsAppleDevice(isApple) {
31
+ if (isApple !== undefined) {
32
+ return isApple;
33
+ }
34
+ if (typeof window === 'undefined' || typeof navigator === 'undefined') {
35
+ return false; // 处理 SSR 环境
36
+ }
37
+ var userAgent = navigator.userAgent.toLowerCase();
38
+ return /mac|iphone|ipod|ipad|ios/i.test(userAgent);
39
+ };
@@ -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,258 @@
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 { useHotkeys, 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
+ 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
+ });
92
+
93
+ // 处理按键,保证格式正确:修饰键在前,最多一个非修饰键在后
94
+ var formatKeys = useCallback(function (keysSet) {
95
+ var modifiers = [];
96
+ var normalKeys = [];
97
+ var _iterator = _createForOfIteratorHelper(keysSet),
98
+ _step;
99
+ try {
100
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
101
+ var key = _step.value;
102
+ // 处理不同表示的修饰键
103
+ var normalizedKey = key.toLowerCase();
104
+ if (MODIFIER_KEYS.has(normalizedKey)) {
105
+ // 统一修饰键表示
106
+ if (!isAppleDevice && normalizedKey === 'ctrl' || isAppleDevice && normalizedKey === 'meta') {
107
+ if (!modifiers.includes('mod')) modifiers.push('mod');
108
+ } else if (!modifiers.includes(normalizedKey)) {
109
+ modifiers.push(normalizedKey);
110
+ }
111
+ } else {
112
+ normalKeys.push(key);
113
+ }
114
+ }
115
+
116
+ // 至少需要一个修饰键
117
+ } catch (err) {
118
+ _iterator.e(err);
119
+ } finally {
120
+ _iterator.f();
121
+ }
122
+ if (modifiers.length === 0 && normalKeys.length > 0) {
123
+ return {
124
+ isValid: false,
125
+ keys: []
126
+ };
127
+ }
128
+
129
+ // 只允许一个非修饰键,如果有多个,只保留最后一个
130
+ var finalKey = normalKeys.length > 0 ? [normalKeys.at(-1)] : [];
131
+ var validKeys = [].concat(modifiers, finalKey);
132
+
133
+ // 组合必须包含至少一个按键
134
+ return {
135
+ isValid: validKeys.length > 0,
136
+ keys: validKeys
137
+ };
138
+ }, []);
139
+
140
+ // 获取格式化后的按键字符串
141
+ var _formatKeys = formatKeys(recordedKeys),
142
+ isValid = _formatKeys.isValid,
143
+ keys = _formatKeys.keys;
144
+ var keysString = keys.join('+');
145
+
146
+ // 检查快捷键冲突
147
+ var checkHotkeyConflict = useCallback(function (newHotkey) {
148
+ return hotkeyConflicts.some(function (conflictKey) {
149
+ var newKeys = splitKeysByPlus(newHotkey);
150
+ var conflictKeys = splitKeysByPlus(conflictKey);
151
+ return isEqual(newKeys.sort(), conflictKeys.sort());
152
+ });
153
+ }, [hotkeyConflicts]);
154
+
155
+ // 当按键组合完成时处理结果
156
+ useEffect(function () {
157
+ if (recordedKeys.size > 0 && !isRecording) {
158
+ if (!isValid) {
159
+ setHasInvalidCombination(true);
160
+ setHasConflict(false);
161
+ return;
162
+ }
163
+ setHasInvalidCombination(false);
164
+ var newKeysString = keysString;
165
+
166
+ // 检查冲突
167
+ var conflict = checkHotkeyConflict(newKeysString);
168
+ if (conflict) {
169
+ console.log('conflict');
170
+ setHasConflict(true);
171
+ onConflict === null || onConflict === void 0 || onConflict(newKeysString);
172
+ } else {
173
+ setHasConflict(false);
174
+ onChange === null || onChange === void 0 || onChange(newKeysString);
175
+ }
176
+ }
177
+ }, [recordedKeys, isRecording, isValid, keysString, checkHotkeyConflict, onChange, onConflict]);
178
+
179
+ // 处理输入框焦点
180
+ var handleFocus = function handleFocus() {
181
+ if (disabled) return;
182
+ setIsFocused(true);
183
+ setHasConflict(false);
184
+ setHasInvalidCombination(false);
185
+ start(); // 开始记录
186
+ };
187
+ var handleBlur = function handleBlur() {
188
+ setIsFocused(false);
189
+ stop(); // 停止记录
190
+ };
191
+
192
+ // 重置功能
193
+ var handleReset = function handleReset(e) {
194
+ e.preventDefault();
195
+ e.stopPropagation();
196
+ onChange === null || onChange === void 0 || onChange(defaultValue);
197
+ resetKeys();
198
+ setHasConflict(false);
199
+ setHasInvalidCombination(false);
200
+ handleBlur();
201
+ };
202
+ return /*#__PURE__*/_jsxs(Flexbox, {
203
+ className: className,
204
+ gap: 8,
205
+ style: _objectSpread({
206
+ position: 'relative'
207
+ }, style),
208
+ children: [/*#__PURE__*/_jsxs(Flexbox, {
209
+ align: 'center',
210
+ className: cx(styles.input, isFocused && styles.inputFocused, (hasConflict || hasInvalidCombination) && styles.inputError, disabled && styles.inputDisabled),
211
+ horizontal: true,
212
+ justify: 'space-between',
213
+ onClick: function onClick() {
214
+ var _inputRef$current2;
215
+ return !disabled && !isFocused && ((_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus());
216
+ },
217
+ children: [/*#__PURE__*/_jsx("div", {
218
+ style: {
219
+ pointerEvents: 'none'
220
+ },
221
+ children: isRecording ? /*#__PURE__*/_jsx("span", {
222
+ className: styles.placeholder,
223
+ children: keys.length > 0 ? /*#__PURE__*/_jsx(Hotkey, {
224
+ keys: keysString
225
+ }) : placeholder
226
+ }) : value ? /*#__PURE__*/_jsx(Hotkey, {
227
+ keys: value
228
+ }) : /*#__PURE__*/_jsx("span", {
229
+ className: styles.placeholder,
230
+ children: placeholder
231
+ })
232
+ }), /*#__PURE__*/_jsx("input", {
233
+ className: styles.hiddenInput,
234
+ disabled: disabled,
235
+ onBlur: handleBlur,
236
+ onFocus: handleFocus,
237
+ readOnly: true,
238
+ ref: inputRef,
239
+ style: {
240
+ pointerEvents: 'none'
241
+ }
242
+ }), allowReset && value && value !== defaultValue && !disabled && /*#__PURE__*/_jsx(ActionIcon, {
243
+ active: true,
244
+ icon: Undo2Icon,
245
+ onClick: handleReset,
246
+ size: 'small',
247
+ title: (texts === null || texts === void 0 ? void 0 : texts.reset) || 'Reset to default'
248
+ })]
249
+ }), hasConflict && /*#__PURE__*/_jsx("div", {
250
+ className: styles.errorText,
251
+ children: (texts === null || texts === void 0 ? void 0 : texts.conflicts) || 'This shortcut conflicts with an existing one.'
252
+ }), hasInvalidCombination && /*#__PURE__*/_jsx("div", {
253
+ className: styles.errorText,
254
+ children: (texts === null || texts === void 0 ? void 0 : texts.invalidCombination) || 'Shortcut must include a modifier key (Ctrl, Alt, Shift) and only one regular key.'
255
+ })]
256
+ });
257
+ });
258
+ 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.1",
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
- };