@lobehub/ui 2.0.7 → 2.0.9
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.
- package/es/Hotkey/const.d.ts +1 -0
- package/es/Hotkey/const.js +1 -1
- package/es/Hotkey/utils.d.ts +1 -0
- package/es/Hotkey/utils.js +20 -1
- package/es/HotkeyInput/HotkeyInput.js +9 -10
- package/es/Tag/utils.js +3 -2
- package/package.json +1 -1
package/es/Hotkey/const.d.ts
CHANGED
package/es/Hotkey/const.js
CHANGED
package/es/Hotkey/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const NORMATIVE_MODIFIER: ("shift" | "alt" | "control" | "ctrl" | "meta" | "mod")[];
|
|
1
2
|
export declare const splitKeysByPlus: (keys: string) => string[];
|
|
2
3
|
export declare const startCase: (str: string) => string;
|
|
3
4
|
export declare const checkIsAppleDevice: (isApple?: boolean) => boolean;
|
package/es/Hotkey/utils.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { KeyMapEnum } from "./const";
|
|
2
|
+
|
|
3
|
+
// https://superuser.com/questions/1238058/key-combination-order
|
|
4
|
+
export var NORMATIVE_MODIFIER = [
|
|
5
|
+
// win: Ctrl ,mac: Control
|
|
6
|
+
KeyMapEnum.Ctrl, KeyMapEnum.Control,
|
|
7
|
+
// win: Alt ,mac: Option
|
|
8
|
+
KeyMapEnum.Alt,
|
|
9
|
+
// win: Shift ,mac: Shift
|
|
10
|
+
KeyMapEnum.Shift,
|
|
11
|
+
// win: Win ,mac: Command
|
|
12
|
+
KeyMapEnum.Meta, KeyMapEnum.Mod];
|
|
13
|
+
var orderMap = Object.fromEntries(NORMATIVE_MODIFIER.map(function (key, index) {
|
|
14
|
+
return [key, index];
|
|
15
|
+
}));
|
|
2
16
|
export var splitKeysByPlus = function splitKeysByPlus(keys) {
|
|
3
|
-
return keys.replaceAll('++', "+".concat(KeyMapEnum.Equal)).split('+')
|
|
17
|
+
return keys.replaceAll('++', "+".concat(KeyMapEnum.Equal)).split('+').sort(function (x, y) {
|
|
18
|
+
var _orderMap$x$toLowerCa, _orderMap$y$toLowerCa;
|
|
19
|
+
var idxX = (_orderMap$x$toLowerCa = orderMap[x.toLowerCase()]) !== null && _orderMap$x$toLowerCa !== void 0 ? _orderMap$x$toLowerCa : orderMap.length;
|
|
20
|
+
var idxY = (_orderMap$y$toLowerCa = orderMap[y.toLowerCase()]) !== null && _orderMap$y$toLowerCa !== void 0 ? _orderMap$y$toLowerCa : orderMap.length;
|
|
21
|
+
return idxX - idxY;
|
|
22
|
+
});
|
|
4
23
|
};
|
|
5
24
|
export var startCase = function startCase(str) {
|
|
6
25
|
return str.replaceAll(/([A-Z])/g, ' $1').replace(/^./, function (s) {
|
|
@@ -22,12 +22,10 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
22
22
|
import useControlledState from 'use-merge-value';
|
|
23
23
|
import ActionIcon from "../ActionIcon";
|
|
24
24
|
import Hotkey from "../Hotkey";
|
|
25
|
-
import { checkIsAppleDevice, splitKeysByPlus } from "../Hotkey/utils";
|
|
25
|
+
import { NORMATIVE_MODIFIER, checkIsAppleDevice, splitKeysByPlus } from "../Hotkey/utils";
|
|
26
26
|
import { useStyles } from "./style";
|
|
27
27
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
28
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
|
-
// 修饰键列表
|
|
30
|
-
var MODIFIER_KEYS = new Set(['alt', 'mod', 'shift', 'meta', 'ctrl', 'control']);
|
|
31
29
|
var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
32
30
|
var _ref$value = _ref.value,
|
|
33
31
|
value = _ref$value === void 0 ? '' : _ref$value,
|
|
@@ -149,7 +147,7 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
149
147
|
var key = _step.value;
|
|
150
148
|
// 处理不同表示的修饰键
|
|
151
149
|
var normalizedKey = key.toLowerCase();
|
|
152
|
-
if (
|
|
150
|
+
if (NORMATIVE_MODIFIER.includes(normalizedKey)) {
|
|
153
151
|
// 统一修饰键表示
|
|
154
152
|
if (!isAppleDevice && normalizedKey === 'ctrl' || isAppleDevice && normalizedKey === 'meta') {
|
|
155
153
|
if (!modifiers.includes('mod')) modifiers.push('mod');
|
|
@@ -176,12 +174,13 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
176
174
|
|
|
177
175
|
// 只允许一个非修饰键,如果有多个,只保留最后一个
|
|
178
176
|
var finalKey = normalKeys.length > 0 ? [normalKeys.at(-1)] : [];
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
// 组合必须包含至少一个按键
|
|
177
|
+
var shortcuts = [modifiers, finalKey];
|
|
182
178
|
return {
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
// 组合必须包含至少一个按键
|
|
180
|
+
isValid: shortcuts.every(function (k) {
|
|
181
|
+
return k.length > 0;
|
|
182
|
+
}),
|
|
183
|
+
keys: shortcuts.flat()
|
|
185
184
|
};
|
|
186
185
|
}, []);
|
|
187
186
|
|
|
@@ -198,7 +197,7 @@ var HotkeyInput = /*#__PURE__*/memo(function (_ref) {
|
|
|
198
197
|
}).some(function (conflictKey) {
|
|
199
198
|
var newKeys = splitKeysByPlus(newHotkey);
|
|
200
199
|
var conflictKeys = splitKeysByPlus(conflictKey);
|
|
201
|
-
return isEqual(newKeys
|
|
200
|
+
return isEqual(newKeys, conflictKeys);
|
|
202
201
|
});
|
|
203
202
|
}, [hotkeyConflicts]);
|
|
204
203
|
|
package/es/Tag/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { camelCase } from 'lodash-es';
|
|
2
2
|
export var presetColors = ['red', 'volcano', 'orange', 'gold', 'yellow', 'lime', 'green', 'cyan', 'blue', 'geekblue', 'purple', 'magenta', 'gray'];
|
|
3
|
-
export var presetSystemColors = new Set(['error', 'warning', 'success', 'info']);
|
|
3
|
+
export var presetSystemColors = new Set(['error', 'warning', 'success', 'info', 'processing']);
|
|
4
4
|
export var colorsPreset = function colorsPreset(theme, type) {
|
|
5
5
|
for (var _len = arguments.length, keys = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
6
6
|
keys[_key - 2] = arguments[_key];
|
|
@@ -8,8 +8,9 @@ export var colorsPreset = function colorsPreset(theme, type) {
|
|
|
8
8
|
return theme[camelCase([type].concat(keys).join('-'))];
|
|
9
9
|
};
|
|
10
10
|
export var colorsPresetSystem = function colorsPresetSystem(theme, type) {
|
|
11
|
+
var t = type === 'processing' ? 'info' : type;
|
|
11
12
|
for (var _len2 = arguments.length, keys = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
12
13
|
keys[_key2 - 2] = arguments[_key2];
|
|
13
14
|
}
|
|
14
|
-
return theme[camelCase(['color',
|
|
15
|
+
return theme[camelCase(['color', t].concat(keys).join('-'))];
|
|
15
16
|
};
|