@lark-apaas/client-toolkit 1.2.24-alpha.6 → 1.2.24-alpha.7
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/lib/components/AppContainer/safety.js +22 -6
- package/lib/components/ui/badge.d.ts +1 -1
- package/lib/components/ui/button.d.ts +2 -2
- package/lib/index.d.ts +0 -2
- package/lib/index.js +1 -2
- package/lib/integrations/services/ChatService.d.ts +12 -0
- package/lib/integrations/services/ChatService.js +67 -0
- package/lib/integrations/services/index.d.ts +1 -0
- package/lib/integrations/services/index.js +1 -0
- package/lib/integrations/services/types.d.ts +34 -0
- package/package.json +3 -3
- package/lib/components/ui/confirm.d.ts +0 -28
- package/lib/components/ui/confirm.js +0 -82
|
@@ -14,17 +14,31 @@ const Component = ()=>{
|
|
|
14
14
|
const isMobile = useIsMobile();
|
|
15
15
|
const [userinfo, setUserinfo] = useState(null);
|
|
16
16
|
const [isInternetVisible, setIsInternetVisible] = useState(false);
|
|
17
|
+
const [showBadge, setShowBadge] = useState(true);
|
|
18
|
+
const [badgeLoaded, setBadgeLoaded] = useState(false);
|
|
17
19
|
const timeoutRef = useRef(null);
|
|
18
20
|
useEffect(()=>{
|
|
19
21
|
const appId = getAppId();
|
|
22
|
+
const csrfHeaders = {
|
|
23
|
+
'X-Suda-Csrf-Token': getCsrfToken()
|
|
24
|
+
};
|
|
20
25
|
const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
|
|
21
26
|
fetch(tenantInfoUrl, {
|
|
22
|
-
headers:
|
|
23
|
-
'X-Suda-Csrf-Token': getCsrfToken()
|
|
24
|
-
}
|
|
27
|
+
headers: csrfHeaders
|
|
25
28
|
}).then((res)=>res.json()).then((data)=>{
|
|
26
29
|
setUserinfo(data?.data?.tenant_info);
|
|
27
30
|
setIsInternetVisible(data?.data?.is_internet_visible);
|
|
31
|
+
}).catch(()=>{});
|
|
32
|
+
const getPublishedUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/get_published` : `/spark/b/${appId}/get_published`;
|
|
33
|
+
fetch(getPublishedUrl, {
|
|
34
|
+
headers: csrfHeaders
|
|
35
|
+
}).then((res)=>res.json()).then((data)=>{
|
|
36
|
+
const badge = data?.data?.app_info?.show_badge;
|
|
37
|
+
setShowBadge(false !== badge);
|
|
38
|
+
}).catch(()=>{
|
|
39
|
+
setShowBadge(true);
|
|
40
|
+
}).finally(()=>{
|
|
41
|
+
setBadgeLoaded(true);
|
|
28
42
|
});
|
|
29
43
|
}, []);
|
|
30
44
|
useEffect(()=>{
|
|
@@ -39,6 +53,8 @@ const Component = ()=>{
|
|
|
39
53
|
isMobile
|
|
40
54
|
]);
|
|
41
55
|
if ('production' !== process.env.NODE_ENV) return null;
|
|
56
|
+
if (!badgeLoaded) return null;
|
|
57
|
+
if (!showBadge) return null;
|
|
42
58
|
if (!visible) return null;
|
|
43
59
|
if (isMobile) return /*#__PURE__*/ jsxs(Sheet, {
|
|
44
60
|
open: open,
|
|
@@ -47,7 +63,7 @@ const Component = ()=>{
|
|
|
47
63
|
/*#__PURE__*/ jsx(SheetTrigger, {
|
|
48
64
|
asChild: true,
|
|
49
65
|
children: /*#__PURE__*/ jsxs("div", {
|
|
50
|
-
className: "fixed right-[12px] bottom-[80px] inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-[10px] py-[6px] bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-
|
|
66
|
+
className: "fixed right-[12px] bottom-[80px] inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-[10px] py-[6px] bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-[6px] text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000]",
|
|
51
67
|
onClick: ()=>{
|
|
52
68
|
setOpen(true);
|
|
53
69
|
},
|
|
@@ -242,7 +258,7 @@ const Component = ()=>{
|
|
|
242
258
|
className: "w-full self-stretch shrink-0 flex items-start gap-x-[8px]",
|
|
243
259
|
children: [
|
|
244
260
|
/*#__PURE__*/ jsx("div", {
|
|
245
|
-
className: "flex-1 flex rounded-
|
|
261
|
+
className: "flex-1 flex rounded-[8px] items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
|
|
246
262
|
"data-custom-element": "safety-close",
|
|
247
263
|
onClick: (e)=>{
|
|
248
264
|
e.stopPropagation();
|
|
@@ -253,7 +269,7 @@ const Component = ()=>{
|
|
|
253
269
|
children: "不再展示"
|
|
254
270
|
}),
|
|
255
271
|
/*#__PURE__*/ jsx("div", {
|
|
256
|
-
className: "flex-1 flex rounded-
|
|
272
|
+
className: "flex-1 flex rounded-[8px] items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
|
|
257
273
|
"data-custom-element": "safety-more",
|
|
258
274
|
onClick: ()=>{
|
|
259
275
|
window.open('https://miaoda.feishu.cn/landing', '_blank');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type VariantProps } from "class-variance-authority";
|
|
3
3
|
declare const badgeVariants: (props?: {
|
|
4
|
-
variant?: "default" | "destructive" | "
|
|
4
|
+
variant?: "default" | "destructive" | "secondary" | "outline";
|
|
5
5
|
} & import("class-variance-authority/dist/types").ClassProp) => string;
|
|
6
6
|
declare function Badge({ className, variant, asChild, ...props }: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
|
|
7
7
|
asChild?: boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type VariantProps } from "class-variance-authority";
|
|
3
3
|
declare const buttonVariants: (props?: {
|
|
4
|
-
variant?: "default" | "link" | "destructive" | "
|
|
5
|
-
size?: "default" | "
|
|
4
|
+
variant?: "default" | "link" | "destructive" | "secondary" | "outline" | "ghost";
|
|
5
|
+
size?: "default" | "icon" | "sm" | "lg" | "icon-sm" | "icon-lg";
|
|
6
6
|
} & import("class-variance-authority/dist/types").ClassProp) => string;
|
|
7
7
|
declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
|
|
8
8
|
asChild?: boolean;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export declare const capabilityClient: import("@lark-apaas/client-capability").CapabilityClient;
|
|
2
|
-
export { showConfirm } from './components/ui/confirm';
|
|
3
|
-
export type { ConfirmOptions } from './components/ui/confirm';
|
|
4
2
|
declare const _default: {
|
|
5
3
|
version: string;
|
|
6
4
|
};
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { isNewPathEnabled } from "./utils/apiPath.js";
|
|
|
5
5
|
import { logger } from "./logger/index.js";
|
|
6
6
|
import { showToast } from "./components/ui/toast.js";
|
|
7
7
|
import { version } from "../package.json";
|
|
8
|
-
import { showConfirm } from "./components/ui/confirm.js";
|
|
9
8
|
const _appId = getAppId();
|
|
10
9
|
const _acquireUploadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_upload_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_upload_url";
|
|
11
10
|
const _acquireDownloadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_download_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_download_url";
|
|
@@ -26,4 +25,4 @@ const capabilityClient = createClient({
|
|
|
26
25
|
const src = {
|
|
27
26
|
version: version
|
|
28
27
|
};
|
|
29
|
-
export { capabilityClient, src as default
|
|
28
|
+
export { capabilityClient, src as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BatchGetChatsResponse, SearchChatsParams, SearchChatsResponse } from './types';
|
|
2
|
+
export type ChatServiceConfig = {
|
|
3
|
+
getAppId?: () => string | null | undefined;
|
|
4
|
+
searchChatsUrl?: (appId: string) => string;
|
|
5
|
+
listChatsUrl?: (appId: string) => string;
|
|
6
|
+
};
|
|
7
|
+
export declare class ChatService {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(config?: ChatServiceConfig);
|
|
10
|
+
searchChats(params: SearchChatsParams): Promise<SearchChatsResponse>;
|
|
11
|
+
listChatsByIds(chatIds: string[]): Promise<BatchGetChatsResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getAppId } from "../../utils/getAppId.js";
|
|
2
|
+
const DEFAULT_CONFIG = {
|
|
3
|
+
getAppId: ()=>getAppId(),
|
|
4
|
+
searchChatsUrl: (appId)=>`/app/${appId}/__runtime__/api/v1/account/search`,
|
|
5
|
+
listChatsUrl: (appId)=>`/app/${appId}/__runtime__/api/v1/account/chat/list_chats`
|
|
6
|
+
};
|
|
7
|
+
class ChatService {
|
|
8
|
+
config;
|
|
9
|
+
constructor(config = {}){
|
|
10
|
+
this.config = {
|
|
11
|
+
...DEFAULT_CONFIG,
|
|
12
|
+
...config
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async searchChats(params) {
|
|
16
|
+
const appId = this.config.getAppId();
|
|
17
|
+
if (!appId) throw new Error('Failed to get appId');
|
|
18
|
+
const response = await fetch(this.config.searchChatsUrl(appId), {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json'
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
query: params.query,
|
|
25
|
+
filters: {
|
|
26
|
+
userParam: {
|
|
27
|
+
commonParam: {
|
|
28
|
+
searchable: false
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
departmentParam: {
|
|
32
|
+
commonParam: {
|
|
33
|
+
searchable: false
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
chatParam: {
|
|
37
|
+
commonParam: {
|
|
38
|
+
searchable: true,
|
|
39
|
+
pageSize: params.pageSize ?? 100,
|
|
40
|
+
offset: params.offset ?? 0
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
credentials: 'include'
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) throw new Error('Failed to search chats');
|
|
48
|
+
return response.json();
|
|
49
|
+
}
|
|
50
|
+
async listChatsByIds(chatIds) {
|
|
51
|
+
const appId = this.config.getAppId();
|
|
52
|
+
if (!appId) throw new Error('Failed to get appId');
|
|
53
|
+
const response = await fetch(this.config.listChatsUrl(appId), {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/json'
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify({
|
|
59
|
+
chatIDList: chatIds
|
|
60
|
+
}),
|
|
61
|
+
credentials: 'include'
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) throw new Error('Failed to fetch chats by ids');
|
|
64
|
+
return response.json();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export { ChatService };
|
|
@@ -62,6 +62,40 @@ export type SearchDepartmentsResponse = {
|
|
|
62
62
|
};
|
|
63
63
|
status_code: string;
|
|
64
64
|
};
|
|
65
|
+
export type ChatInfo = {
|
|
66
|
+
/** 群组 ID */
|
|
67
|
+
chatID: string;
|
|
68
|
+
/** 群组名称(国际化文本) */
|
|
69
|
+
name: I18nText;
|
|
70
|
+
/** 头像:URL 或 16 进制 RGB 颜色 */
|
|
71
|
+
avatar: string;
|
|
72
|
+
/** 是否是外部群 */
|
|
73
|
+
isExternal?: boolean;
|
|
74
|
+
/** 群成员数量(不包括机器人),搜索接口返回,批量查询接口不返回 */
|
|
75
|
+
userCount?: number;
|
|
76
|
+
};
|
|
77
|
+
export type SearchChatsParams = {
|
|
78
|
+
query?: string;
|
|
79
|
+
offset?: number;
|
|
80
|
+
pageSize?: number;
|
|
81
|
+
};
|
|
82
|
+
export type SearchChatsResponse = {
|
|
83
|
+
data: {
|
|
84
|
+
result: {
|
|
85
|
+
chatResult?: {
|
|
86
|
+
total: number;
|
|
87
|
+
items: ChatInfo[];
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
status_code: string;
|
|
92
|
+
};
|
|
93
|
+
export type BatchGetChatsResponse = {
|
|
94
|
+
data: {
|
|
95
|
+
chatInfoMap: Record<string, ChatInfo>;
|
|
96
|
+
};
|
|
97
|
+
status_code: string;
|
|
98
|
+
};
|
|
65
99
|
export type UserProfileAccountStatus = 0 | 1 | 2 | 3 | 4;
|
|
66
100
|
export type SimpleUserProfileInfo = {
|
|
67
101
|
name?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.24-alpha.
|
|
3
|
+
"version": "1.2.24-alpha.7",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -98,13 +98,13 @@
|
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@ant-design/colors": "^7.2.1",
|
|
100
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
101
|
-
"@data-loom/js": "0.4.
|
|
101
|
+
"@data-loom/js": "0.4.11",
|
|
102
102
|
"@lark-apaas/aily-web-sdk": "^0.0.7",
|
|
103
103
|
"@lark-apaas/auth-sdk": "^0.1.2",
|
|
104
104
|
"@lark-apaas/client-capability": "^0.1.6",
|
|
105
105
|
"@lark-apaas/internal-slardar": "^0.0.3",
|
|
106
106
|
"@lark-apaas/miaoda-inspector": "^1.0.20",
|
|
107
|
-
"@lark-apaas/observable-web": "^1.0.
|
|
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",
|
|
110
110
|
"@radix-ui/react-slot": "^1.2.3",
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export interface ConfirmOptions {
|
|
2
|
-
/** 标题,默认 "提示" */
|
|
3
|
-
title?: string;
|
|
4
|
-
/** 内容描述 */
|
|
5
|
-
message: string;
|
|
6
|
-
/** 确认按钮文案,默认 "确认" */
|
|
7
|
-
confirmText?: string;
|
|
8
|
-
/** 取消按钮文案,默认 "取消" */
|
|
9
|
-
cancelText?: string;
|
|
10
|
-
/** 确认按钮样式变体 */
|
|
11
|
-
variant?: 'default' | 'destructive';
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 函数式确认弹窗,作为 window.confirm 的直接平替。
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* // 简单用法(兼容 window.confirm 传参)
|
|
18
|
-
* const ok = await showConfirm('确定删除吗?');
|
|
19
|
-
*
|
|
20
|
-
* // 完整用法
|
|
21
|
-
* const ok = await showConfirm({
|
|
22
|
-
* title: '确认删除',
|
|
23
|
-
* message: '删除后不可恢复',
|
|
24
|
-
* confirmText: '删除',
|
|
25
|
-
* variant: 'destructive',
|
|
26
|
-
* });
|
|
27
|
-
*/
|
|
28
|
-
export declare function showConfirm(options: string | ConfirmOptions): Promise<boolean>;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import "react";
|
|
3
|
-
import { createRoot } from "react-dom/client";
|
|
4
|
-
import { Content, Description, Overlay, Portal, Root, Title } from "@radix-ui/react-dialog";
|
|
5
|
-
import { Button } from "./button.js";
|
|
6
|
-
import { clsxWithTw } from "../../utils/utils.js";
|
|
7
|
-
function showConfirm(options) {
|
|
8
|
-
const opts = 'string' == typeof options ? {
|
|
9
|
-
message: options
|
|
10
|
-
} : options;
|
|
11
|
-
const { title = '提示', message, confirmText = '确认', cancelText = '取消', variant = 'default' } = opts;
|
|
12
|
-
return new Promise((resolve)=>{
|
|
13
|
-
const container = document.createElement('div');
|
|
14
|
-
document.body.appendChild(container);
|
|
15
|
-
const root = createRoot(container);
|
|
16
|
-
function cleanup() {
|
|
17
|
-
root.unmount();
|
|
18
|
-
container.remove();
|
|
19
|
-
}
|
|
20
|
-
function handleConfirm() {
|
|
21
|
-
cleanup();
|
|
22
|
-
resolve(true);
|
|
23
|
-
}
|
|
24
|
-
function handleCancel() {
|
|
25
|
-
cleanup();
|
|
26
|
-
resolve(false);
|
|
27
|
-
}
|
|
28
|
-
root.render(/*#__PURE__*/ jsx(ConfirmDialog, {
|
|
29
|
-
title: title,
|
|
30
|
-
message: message,
|
|
31
|
-
confirmText: confirmText,
|
|
32
|
-
cancelText: cancelText,
|
|
33
|
-
variant: variant,
|
|
34
|
-
onConfirm: handleConfirm,
|
|
35
|
-
onCancel: handleCancel
|
|
36
|
-
}));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function ConfirmDialog({ title, message, confirmText, cancelText, variant, onConfirm, onCancel }) {
|
|
40
|
-
return /*#__PURE__*/ jsx(Root, {
|
|
41
|
-
defaultOpen: true,
|
|
42
|
-
onOpenChange: (open)=>{
|
|
43
|
-
if (!open) onCancel();
|
|
44
|
-
},
|
|
45
|
-
children: /*#__PURE__*/ jsxs(Portal, {
|
|
46
|
-
children: [
|
|
47
|
-
/*#__PURE__*/ jsx(Overlay, {
|
|
48
|
-
className: clsxWithTw('fixed inset-0 z-[99999] bg-black/40', 'data-[state=open]:animate-in data-[state=open]:fade-in-0', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0')
|
|
49
|
-
}),
|
|
50
|
-
/*#__PURE__*/ jsxs(Content, {
|
|
51
|
-
className: clsxWithTw('fixed left-1/2 top-1/2 z-[99999] -translate-x-1/2 -translate-y-1/2', 'w-[90vw] max-w-[400px] rounded-lg', 'bg-[var(--color-neutral-00,#fff)] text-[var(--color-neutral-950,#1f2329)]', 'border border-[var(--color-neutral-300,#dee0e3)]', 'shadow-lg p-6', 'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95'),
|
|
52
|
-
children: [
|
|
53
|
-
/*#__PURE__*/ jsx(Title, {
|
|
54
|
-
className: clsxWithTw('text-base font-medium leading-6', 'text-[var(--color-neutral-950,#1f2329)]'),
|
|
55
|
-
children: title
|
|
56
|
-
}),
|
|
57
|
-
/*#__PURE__*/ jsx(Description, {
|
|
58
|
-
className: clsxWithTw('mt-2 text-sm leading-5', 'text-[var(--color-neutral-700,#646a73)]'),
|
|
59
|
-
children: message
|
|
60
|
-
}),
|
|
61
|
-
/*#__PURE__*/ jsxs("div", {
|
|
62
|
-
className: clsxWithTw('mt-6 flex justify-end gap-2'),
|
|
63
|
-
children: [
|
|
64
|
-
/*#__PURE__*/ jsx(Button, {
|
|
65
|
-
variant: "outline",
|
|
66
|
-
onClick: onCancel,
|
|
67
|
-
children: cancelText
|
|
68
|
-
}),
|
|
69
|
-
/*#__PURE__*/ jsx(Button, {
|
|
70
|
-
variant: variant,
|
|
71
|
-
onClick: onConfirm,
|
|
72
|
-
children: confirmText
|
|
73
|
-
})
|
|
74
|
-
]
|
|
75
|
-
})
|
|
76
|
-
]
|
|
77
|
-
})
|
|
78
|
-
]
|
|
79
|
-
})
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
export { showConfirm };
|