@lark-apaas/client-toolkit 1.2.28-alpha.44 → 1.2.28-alpha.45

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,15 @@
1
+ import * as React from 'react';
2
+ export type GroupType = 'chat_group' | 'custom_group';
3
+ export interface IGroupInfo {
4
+ id: string;
5
+ name: string;
6
+ type?: GroupType;
7
+ avatarUrl?: string;
8
+ }
9
+ export interface IGroupDisplayProps {
10
+ groups: IGroupInfo | IGroupInfo[];
11
+ size?: 'small' | 'medium' | 'large';
12
+ className?: string;
13
+ style?: React.CSSProperties;
14
+ }
15
+ export declare const GroupDisplay: React.FC<IGroupDisplayProps>;
@@ -0,0 +1,88 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import "react";
3
+ import { clsxWithTw } from "../../utils/utils.js";
4
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip.js";
5
+ const sizeConfig = {
6
+ small: {
7
+ icon: 16,
8
+ text: 'text-xs'
9
+ },
10
+ medium: {
11
+ icon: 20,
12
+ text: 'text-sm'
13
+ },
14
+ large: {
15
+ icon: 24,
16
+ text: 'text-base'
17
+ }
18
+ };
19
+ const GroupIcon = ({ type = 'chat_group', size })=>{
20
+ if ('chat_group' === type) return /*#__PURE__*/ jsx("svg", {
21
+ width: size,
22
+ height: size,
23
+ viewBox: "0 0 24 24",
24
+ fill: "none",
25
+ xmlns: "http://www.w3.org/2000/svg",
26
+ children: /*#__PURE__*/ jsx("path", {
27
+ d: "M17 20H22V18C22 16.3431 20.6569 15 19 15C18.0444 15 17.1931 15.4468 16.6438 16.1429M17 20H7M17 20V18C17 17.3438 16.8736 16.717 16.6438 16.1429M7 20H2V18C2 16.3431 3.34315 15 5 15C5.95561 15 6.80686 15.4468 7.35625 16.1429M7 20V18C7 17.3438 7.12642 16.717 7.35625 16.1429M7.35625 16.1429C8.0935 14.301 9.89482 13 12 13C14.1052 13 15.9065 14.301 16.6438 16.1429M15 7C15 8.65685 13.6569 10 12 10C10.3431 10 9 8.65685 9 7C9 5.34315 10.3431 4 12 4C13.6569 4 15 5.34315 15 7ZM21 10C21 11.1046 20.1046 12 19 12C17.8954 12 17 11.1046 17 10C17 8.89543 17.8954 8 19 8C20.1046 8 21 8.89543 21 10ZM7 10C7 11.1046 6.10457 12 5 12C3.89543 12 3 11.1046 3 10C3 8.89543 3.89543 8 5 8C6.10457 8 7 8.89543 7 10Z",
28
+ stroke: "currentColor",
29
+ strokeWidth: "2",
30
+ strokeLinecap: "round",
31
+ strokeLinejoin: "round"
32
+ })
33
+ });
34
+ return /*#__PURE__*/ jsx("svg", {
35
+ width: size,
36
+ height: size,
37
+ viewBox: "0 0 24 24",
38
+ fill: "none",
39
+ xmlns: "http://www.w3.org/2000/svg",
40
+ children: /*#__PURE__*/ jsx("path", {
41
+ d: "M18 18.72a9.094 9.094 0 003.741-.479 3 3 0 00-4.682-2.72m.94 3.198l.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0112 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 016 18.719m12 0a5.971 5.971 0 00-.941-3.197m0 0A5.995 5.995 0 0012 12.75a5.995 5.995 0 00-5.058 2.772m0 0a3 3 0 00-4.681 2.72 8.986 8.986 0 003.74.477m.94-3.197a5.971 5.971 0 00-.94 3.197M15 6.75a3 3 0 11-6 0 3 3 0 016 0zm6 3a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0zm-13.5 0a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0z",
42
+ stroke: "currentColor",
43
+ strokeWidth: "2",
44
+ strokeLinecap: "round",
45
+ strokeLinejoin: "round"
46
+ })
47
+ });
48
+ };
49
+ const GroupDisplay = ({ groups, size = 'medium', className, style })=>{
50
+ const groupList = Array.isArray(groups) ? groups : [
51
+ groups
52
+ ];
53
+ const config = sizeConfig[size];
54
+ if (!groupList.length) return null;
55
+ return /*#__PURE__*/ jsx("div", {
56
+ className: clsxWithTw('flex flex-wrap gap-1', className),
57
+ style: style,
58
+ children: /*#__PURE__*/ jsx(TooltipProvider, {
59
+ children: groupList.map((group)=>/*#__PURE__*/ jsxs(Tooltip, {
60
+ children: [
61
+ /*#__PURE__*/ jsx(TooltipTrigger, {
62
+ asChild: true,
63
+ children: /*#__PURE__*/ jsxs("div", {
64
+ className: clsxWithTw('inline-flex items-center gap-1 rounded px-1.5 py-0.5', 'bg-[rgba(31,35,41,0.06)] text-[rgba(31,35,41,0.7)]', 'max-w-[200px]'),
65
+ children: [
66
+ /*#__PURE__*/ jsx("span", {
67
+ className: "flex-shrink-0 text-[rgba(31,35,41,0.5)]",
68
+ children: /*#__PURE__*/ jsx(GroupIcon, {
69
+ type: group.type,
70
+ size: config.icon
71
+ })
72
+ }),
73
+ /*#__PURE__*/ jsx("span", {
74
+ className: clsxWithTw(config.text, 'truncate leading-tight'),
75
+ children: group.name
76
+ })
77
+ ]
78
+ })
79
+ }),
80
+ /*#__PURE__*/ jsx(TooltipContent, {
81
+ children: group.name
82
+ })
83
+ ]
84
+ }, group.id))
85
+ })
86
+ });
87
+ };
88
+ export { GroupDisplay };
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import type { IGroupInfo } from './GroupDisplay';
3
+ export interface GroupSelectProps {
4
+ value?: IGroupInfo[];
5
+ onChange?: (value: IGroupInfo[]) => void;
6
+ onSearch: (keyword: string) => Promise<IGroupInfo[]>;
7
+ placeholder?: string;
8
+ disabled?: boolean;
9
+ }
10
+ export declare const GroupSelect: React.FC<GroupSelectProps>;
@@ -0,0 +1,133 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { clsxWithTw } from "../../utils/utils.js";
4
+ const GroupSelect = ({ value = [], onChange, onSearch, placeholder = '搜索群组', disabled = false })=>{
5
+ const [keyword, setKeyword] = useState('');
6
+ const [searchResults, setSearchResults] = useState([]);
7
+ const [isLoading, setIsLoading] = useState(false);
8
+ const [isOpen, setIsOpen] = useState(false);
9
+ const inputRef = useRef(null);
10
+ const containerRef = useRef(null);
11
+ const debounceRef = useRef(null);
12
+ useEffect(()=>{
13
+ if (!keyword.trim()) {
14
+ setSearchResults([]);
15
+ setIsLoading(false);
16
+ return;
17
+ }
18
+ setIsLoading(true);
19
+ if (debounceRef.current) clearTimeout(debounceRef.current);
20
+ debounceRef.current = setTimeout(async ()=>{
21
+ try {
22
+ const results = await onSearch(keyword.trim());
23
+ setSearchResults(results);
24
+ } catch (error) {
25
+ console.error('Failed to search groups:', error);
26
+ setSearchResults([]);
27
+ } finally{
28
+ setIsLoading(false);
29
+ }
30
+ }, 300);
31
+ return ()=>{
32
+ if (debounceRef.current) clearTimeout(debounceRef.current);
33
+ };
34
+ }, [
35
+ keyword,
36
+ onSearch
37
+ ]);
38
+ useEffect(()=>{
39
+ const handleClickOutside = (e)=>{
40
+ if (containerRef.current && !containerRef.current.contains(e.target)) setIsOpen(false);
41
+ };
42
+ document.addEventListener('mousedown', handleClickOutside);
43
+ return ()=>document.removeEventListener('mousedown', handleClickOutside);
44
+ }, []);
45
+ const selectedIds = new Set(value.map((g)=>g.id));
46
+ const handleSelect = (group)=>{
47
+ if (selectedIds.has(group.id)) return;
48
+ onChange?.([
49
+ ...value,
50
+ group
51
+ ]);
52
+ setKeyword('');
53
+ setSearchResults([]);
54
+ };
55
+ const handleRemove = (groupId)=>{
56
+ onChange?.(value.filter((g)=>g.id !== groupId));
57
+ };
58
+ return /*#__PURE__*/ jsxs("div", {
59
+ ref: containerRef,
60
+ className: "relative w-full",
61
+ children: [
62
+ /*#__PURE__*/ jsxs("div", {
63
+ className: clsxWithTw('flex flex-wrap items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 min-h-[36px]', disabled && 'opacity-50 cursor-not-allowed', isOpen && 'ring-2 ring-ring ring-offset-1'),
64
+ onClick: ()=>{
65
+ if (!disabled) {
66
+ setIsOpen(true);
67
+ inputRef.current?.focus();
68
+ }
69
+ },
70
+ children: [
71
+ value.map((group)=>/*#__PURE__*/ jsxs("span", {
72
+ className: "inline-flex items-center gap-1 rounded bg-[rgba(31,35,41,0.06)] px-1.5 py-0.5 text-xs",
73
+ children: [
74
+ group.name,
75
+ !disabled && /*#__PURE__*/ jsx("button", {
76
+ type: "button",
77
+ className: "ml-0.5 text-[rgba(31,35,41,0.4)] hover:text-[rgba(31,35,41,0.8)]",
78
+ onClick: (e)=>{
79
+ e.stopPropagation();
80
+ handleRemove(group.id);
81
+ },
82
+ children: "\xd7"
83
+ })
84
+ ]
85
+ }, group.id)),
86
+ /*#__PURE__*/ jsx("input", {
87
+ ref: inputRef,
88
+ type: "text",
89
+ className: "flex-1 min-w-[80px] border-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground",
90
+ placeholder: 0 === value.length ? placeholder : '',
91
+ value: keyword,
92
+ disabled: disabled,
93
+ onChange: (e)=>{
94
+ setKeyword(e.target.value);
95
+ setIsOpen(true);
96
+ },
97
+ onFocus: ()=>setIsOpen(true)
98
+ })
99
+ ]
100
+ }),
101
+ isOpen && keyword.trim() && /*#__PURE__*/ jsx("div", {
102
+ className: "absolute z-50 mt-1 w-full rounded-md border border-border bg-popover shadow-md",
103
+ children: isLoading ? /*#__PURE__*/ jsx("div", {
104
+ className: "flex items-center justify-center py-4 text-sm text-muted-foreground",
105
+ children: "搜索中..."
106
+ }) : 0 === searchResults.length ? /*#__PURE__*/ jsx("div", {
107
+ className: "flex items-center justify-center py-4 text-sm text-muted-foreground",
108
+ children: "未找到匹配的群组"
109
+ }) : /*#__PURE__*/ jsx("ul", {
110
+ className: "max-h-[200px] overflow-y-auto py-1",
111
+ children: searchResults.map((group)=>{
112
+ const isSelected = selectedIds.has(group.id);
113
+ return /*#__PURE__*/ jsxs("li", {
114
+ className: clsxWithTw('flex items-center gap-2 px-3 py-2 text-sm cursor-pointer', isSelected ? 'bg-[rgba(31,35,41,0.06)] text-muted-foreground cursor-default' : 'hover:bg-[rgba(31,35,41,0.06)]'),
115
+ onClick: ()=>!isSelected && handleSelect(group),
116
+ children: [
117
+ /*#__PURE__*/ jsx("span", {
118
+ className: "truncate",
119
+ children: group.name
120
+ }),
121
+ isSelected && /*#__PURE__*/ jsx("span", {
122
+ className: "ml-auto text-xs text-muted-foreground",
123
+ children: "已选"
124
+ })
125
+ ]
126
+ }, group.id);
127
+ })
128
+ })
129
+ })
130
+ ]
131
+ });
132
+ };
133
+ export { GroupSelect };
@@ -0,0 +1,4 @@
1
+ export { GroupDisplay } from './GroupDisplay';
2
+ export type { IGroupDisplayProps, IGroupInfo, GroupType } from './GroupDisplay';
3
+ export { GroupSelect } from './GroupSelect';
4
+ export type { GroupSelectProps } from './GroupSelect';
@@ -0,0 +1,3 @@
1
+ import { GroupDisplay } from "./GroupDisplay.js";
2
+ import { GroupSelect } from "./GroupSelect.js";
3
+ export { GroupDisplay, GroupSelect };
@@ -3,3 +3,4 @@ export * from './ErrorRender';
3
3
  export * from './NotFoundRender';
4
4
  export * from './theme';
5
5
  export * from './User';
6
+ export * from './Group';
@@ -3,3 +3,4 @@ export * from "./ErrorRender/index.js";
3
3
  export * from "./NotFoundRender/index.js";
4
4
  export * from "./theme/index.js";
5
5
  export * from "./User/index.js";
6
+ export * from "./Group/index.js";
@@ -1,11 +1,5 @@
1
1
  import { IUserProfile } from '../apis/udt-types';
2
- /**
3
- * useCurrentUserProfile 的返回类型。
4
- * 初始状态为空对象 `{}`(所有字段均为 undefined),异步获取用户信息后字段才会被填充。
5
- * 使用时必须通过可选链或空值合并进行安全访问,如 `userInfo?.user_id`。
6
- * 判断是否已加载完成应使用 `if (!userInfo?.user_id)` 而非 `if (!userInfo)`(因为空对象是 truthy)。
7
- */
8
- export type ICompatibilityUserProfile = Partial<IUserProfile & {
2
+ export interface ICompatibilityUserProfile extends IUserProfile {
9
3
  /**
10
4
  * @deprecated please use `name`
11
5
  */
@@ -14,14 +8,5 @@ export type ICompatibilityUserProfile = Partial<IUserProfile & {
14
8
  * @deprecated please use `avatar`
15
9
  */
16
10
  userAvatar: string;
17
- }>;
18
- export declare const useCurrentUserProfile: () => Partial<IUserProfile & {
19
- /**
20
- * @deprecated please use `name`
21
- */
22
- userName: string;
23
- /**
24
- * @deprecated please use `avatar`
25
- */
26
- userAvatar: string;
27
- }>;
11
+ }
12
+ export declare const useCurrentUserProfile: () => ICompatibilityUserProfile;
@@ -1,11 +1,5 @@
1
1
  import { IUserProfile } from '../apis/udt-types';
2
- /**
3
- * 获取当前用户信息。
4
- * 返回 Partial<IUserProfile>,因为初始值来自 window._userInfo,
5
- * 该值在运行时始终为空对象 {},所有字段均为 undefined。
6
- * 异步获取用户信息后才会被填充为完整的 IUserProfile。
7
- */
8
- export declare function getCurrentUserProfile(): Partial<IUserProfile>;
2
+ export declare function getCurrentUserProfile(): IUserProfile;
9
3
  /**
10
4
  * @deprecated 请使用 getCurrentUserProfile 代替
11
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.28-alpha.44",
3
+ "version": "1.2.28-alpha.45",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -100,10 +100,10 @@
100
100
  "@ant-design/cssinjs": "^1.24.0",
101
101
  "@data-loom/js": "0.4.12",
102
102
  "@lark-apaas/aily-web-sdk": "^0.0.7",
103
- "@lark-apaas/auth-sdk": "^0.1.2",
103
+ "@lark-apaas/auth-sdk": "0.1.0-alpha.74",
104
104
  "@lark-apaas/client-capability": "^0.1.6",
105
105
  "@lark-apaas/internal-slardar": "^0.0.3",
106
- "@lark-apaas/miaoda-inspector": "1.0.14-alpha.48",
106
+ "@lark-apaas/miaoda-inspector": "^1.0.21",
107
107
  "@lark-apaas/observable-web": "^1.0.5",
108
108
  "@radix-ui/react-avatar": "^1.1.10",
109
109
  "@radix-ui/react-popover": "^1.1.15",