@lobehub/ui 2.24.1 → 2.24.3

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.
@@ -91,9 +91,10 @@ var Avatar = /*#__PURE__*/memo(function (_ref) {
91
91
  unoptimized: unoptimized,
92
92
  width: size
93
93
  }) : avatar;
94
+ var hasBackground = background && background !== 'transparent' && background !== 'rgba(0,0,0,0)' && background !== null;
94
95
  var customAvatar = emoji ? /*#__PURE__*/_jsx(FluentEmoji, {
95
96
  emoji: emoji,
96
- size: emojiScaleWithBackground ? background ? size * 0.8 : size : size * 0.8,
97
+ size: emojiScaleWithBackground ? hasBackground ? size * 0.8 : size : size * 0.8,
97
98
  type: animation ? 'anim' : '3d',
98
99
  unoptimized: unoptimized
99
100
  }) : sliceText ? text === null || text === void 0 ? void 0 : text.toUpperCase().slice(0, 2) : text === null || text === void 0 ? void 0 : text.toUpperCase();
@@ -1,13 +1,4 @@
1
1
  /// <reference types="react" />
2
- export interface AvatarUploaderProps {
3
- compressSize?: number;
4
- onChange: (avatar: string) => void;
5
- onUpload?: (file: File) => void;
6
- texts?: {
7
- draggerDesc?: string;
8
- fileTypeError?: string;
9
- uploadBtn?: string;
10
- };
11
- }
2
+ import { AvatarUploaderProps } from './type';
12
3
  declare const AvatarUploader: import("react").NamedExoticComponent<AvatarUploaderProps>;
13
4
  export default AvatarUploader;
@@ -13,6 +13,8 @@ import AvatarEditor from 'react-avatar-editor';
13
13
  import { Center, Flexbox } from 'react-layout-kit';
14
14
  import Button from "../Button";
15
15
  import Icon from "../Icon";
16
+ import Tag from "../Tag";
17
+ import Text from "../Text";
16
18
  import { useStyles } from "./style";
17
19
  import { jsx as _jsx } from "react/jsx-runtime";
18
20
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -27,7 +29,8 @@ var createUploadImageHandler = function createUploadImageHandler(onUploadImage)
27
29
  };
28
30
  };
29
31
  var AvatarUploader = /*#__PURE__*/memo(function (_ref) {
30
- var onChange = _ref.onChange,
32
+ var shape = _ref.shape,
33
+ onChange = _ref.onChange,
31
34
  texts = _ref.texts,
32
35
  _ref$compressSize = _ref.compressSize,
33
36
  compressSize = _ref$compressSize === void 0 ? 256 : _ref$compressSize,
@@ -38,11 +41,12 @@ var AvatarUploader = /*#__PURE__*/memo(function (_ref) {
38
41
  previewImage = _useState2[0],
39
42
  setPreviewImage = _useState2[1];
40
43
  var _useStyles = useStyles(),
41
- styles = _useStyles.styles;
44
+ styles = _useStyles.styles,
45
+ theme = _useStyles.theme;
42
46
  var beforeUpload = useCallback(function (file) {
43
- var isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
47
+ var isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif' || file.type === 'image/webp';
44
48
  if (!isJpgOrPng) {
45
- message.error((texts === null || texts === void 0 ? void 0 : texts.fileTypeError) || 'You can only upload JPG/PNG file!');
49
+ message.error((texts === null || texts === void 0 ? void 0 : texts.fileTypeError) || 'You can only upload image file!');
46
50
  return;
47
51
  }
48
52
  return createUploadImageHandler(function (avatar) {
@@ -55,10 +59,16 @@ var AvatarUploader = /*#__PURE__*/memo(function (_ref) {
55
59
  var dataUrl = canvasScaled.toDataURL();
56
60
  onChange(dataUrl);
57
61
  if (!onUpload) return;
58
- var file = new File([dataUrl], 'avatar.webp', {
59
- type: 'image/webp'
60
- });
61
- onUpload === null || onUpload === void 0 || onUpload(file);
62
+
63
+ // 使用 toBlob 直接获取 Blob,然后创建 File 对象
64
+ canvasScaled.toBlob(function (blob) {
65
+ if (blob) {
66
+ var file = new File([blob], 'avatar.webp', {
67
+ type: 'image/webp'
68
+ });
69
+ onUpload(file);
70
+ }
71
+ }, 'image/webp', 0.95); // 0.95 是图片质量
62
72
  };
63
73
  return /*#__PURE__*/_jsxs(Flexbox, {
64
74
  padding: 10,
@@ -79,10 +89,24 @@ var AvatarUploader = /*#__PURE__*/memo(function (_ref) {
79
89
  height: compressSize,
80
90
  width: compressSize,
81
91
  children: [/*#__PURE__*/_jsx(Icon, {
92
+ color: theme.colorTextDescription,
82
93
  icon: ImageUpIcon,
83
94
  size: 48
84
- }), /*#__PURE__*/_jsx("div", {
95
+ }), /*#__PURE__*/_jsx(Text, {
96
+ color: theme.colorTextSecondary,
85
97
  children: (texts === null || texts === void 0 ? void 0 : texts.draggerDesc) || 'Click or Drag image to this area to upload'
98
+ }), /*#__PURE__*/_jsxs(Center, {
99
+ gap: 4,
100
+ horizontal: true,
101
+ children: [/*#__PURE__*/_jsx(Tag, {
102
+ children: "JPG"
103
+ }), /*#__PURE__*/_jsx(Tag, {
104
+ children: "PNG"
105
+ }), /*#__PURE__*/_jsx(Tag, {
106
+ children: "GIF"
107
+ }), /*#__PURE__*/_jsx(Tag, {
108
+ children: "WEBP"
109
+ })]
86
110
  })]
87
111
  })
88
112
  }), previewImage && /*#__PURE__*/_jsxs(Center, {
@@ -93,7 +117,7 @@ var AvatarUploader = /*#__PURE__*/memo(function (_ref) {
93
117
  width: '100%',
94
118
  children: [/*#__PURE__*/_jsx(AvatarEditor, {
95
119
  border: 0,
96
- borderRadius: compressSize / 2,
120
+ borderRadius: shape === 'square' ? undefined : compressSize / 2,
97
121
  className: styles.editor,
98
122
  height: compressSize,
99
123
  image: previewImage,
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
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
- var _excluded = ["value", "defaultAvatar", "onChange", "locale", "allowUpload", "allowDelete", "texts", "onDelete", "compressSize", "customEmojis", "className", "loading", "onUpload", "customTabs", "popupClassName", "popupStyle", "customRender", "open", "defaultOpen", "onOpenChange", "popupProps"];
4
+ var _excluded = ["value", "defaultAvatar", "onChange", "locale", "allowUpload", "allowDelete", "texts", "onDelete", "compressSize", "customEmojis", "className", "loading", "onUpload", "customTabs", "popupClassName", "popupStyle", "customRender", "open", "defaultOpen", "onOpenChange", "popupProps", "shape"];
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
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; }
@@ -67,6 +67,7 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
67
67
  defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
68
68
  onOpenChange = _ref.onOpenChange,
69
69
  popupProps = _ref.popupProps,
70
+ shape = _ref.shape,
70
71
  rest = _objectWithoutProperties(_ref, _excluded);
71
72
  var ref = useRef(null);
72
73
  var _useMergeState = useMergeState(defaultOpen, {
@@ -196,6 +197,7 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
196
197
  compressSize: compressSize,
197
198
  onChange: handleAvatarChange,
198
199
  onUpload: onUpload,
200
+ shape: shape,
199
201
  texts: texts
200
202
  }), customTabs.map(function (item) {
201
203
  return tab === item.value && /*#__PURE__*/_jsx(Flexbox, {
@@ -220,7 +222,8 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
220
222
  children: customRender ? customRender(ava) : /*#__PURE__*/_jsx(Avatar, _objectSpread({
221
223
  avatar: ava,
222
224
  className: cx(styles.root, className),
223
- loading: loading
225
+ loading: loading,
226
+ shape: shape
224
227
  }, rest))
225
228
  }));
226
229
  });
@@ -1,7 +1,17 @@
1
1
  import { PopoverProps } from 'antd';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
3
  import type { AvatarProps } from "../Avatar/type";
4
- import type { AvatarUploaderProps } from "./AvatarUploader";
4
+ export interface AvatarUploaderProps {
5
+ compressSize?: number;
6
+ onChange: (avatar: string) => void;
7
+ onUpload?: (file: File) => void;
8
+ shape?: 'circle' | 'square';
9
+ texts?: {
10
+ draggerDesc?: string;
11
+ fileTypeError?: string;
12
+ uploadBtn?: string;
13
+ };
14
+ }
5
15
  export interface EmojiPickerCustomEmoji {
6
16
  emojis: [
7
17
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "2.24.1",
3
+ "version": "2.24.3",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",