@lark-apaas/client-toolkit 1.2.22 → 1.2.24-alpha-test.0
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/ui/badge.d.ts +1 -1
- package/lib/components/ui/button.d.ts +2 -2
- package/lib/components/ui/confirm.d.ts +28 -0
- package/lib/components/ui/confirm.js +82 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -1
- package/lib/logger/intercept-global-error.js +18 -11
- package/lib/utils/axiosConfig.js +20 -0
- package/lib/utils/postMessage.d.ts +0 -1
- package/lib/utils/postMessage.js +1 -6
- package/package.json +6 -5
|
@@ -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" | "outline" | "secondary";
|
|
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" | "outline" | "secondary" | "ghost";
|
|
5
|
+
size?: "default" | "sm" | "lg" | "icon" | "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;
|
|
@@ -0,0 +1,28 @@
|
|
|
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>;
|
|
@@ -0,0 +1,82 @@
|
|
|
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 };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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';
|
|
2
4
|
declare const _default: {
|
|
3
5
|
version: string;
|
|
4
6
|
};
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ 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";
|
|
8
9
|
const _appId = getAppId();
|
|
9
10
|
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";
|
|
10
11
|
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";
|
|
@@ -25,4 +26,4 @@ const capabilityClient = createClient({
|
|
|
25
26
|
const src = {
|
|
26
27
|
version: version
|
|
27
28
|
};
|
|
28
|
-
export { capabilityClient, src as default };
|
|
29
|
+
export { capabilityClient, src as default, showConfirm };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { slardar } from "@lark-apaas/internal-slardar";
|
|
1
2
|
import { getHmrApi } from "../utils/hmr-api.js";
|
|
2
|
-
import { submitPostMessage
|
|
3
|
+
import { submitPostMessage } from "../utils/postMessage.js";
|
|
3
4
|
import { levelSchema } from "./log-types.js";
|
|
4
5
|
import { logger } from "./logger.js";
|
|
5
6
|
let devServerDisconnectInfo = null;
|
|
@@ -19,22 +20,26 @@ function processDevServerLog(log) {
|
|
|
19
20
|
status: 'disconnected'
|
|
20
21
|
}
|
|
21
22
|
});
|
|
22
|
-
|
|
23
|
+
slardar.sendEvent({
|
|
23
24
|
name: 'sandbox-devServer',
|
|
24
|
-
|
|
25
|
-
type: 'disconnected',
|
|
25
|
+
metrics: {
|
|
26
26
|
time
|
|
27
|
+
},
|
|
28
|
+
categories: {
|
|
29
|
+
type: 'disconnected'
|
|
27
30
|
}
|
|
28
31
|
});
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
34
|
if (!devServerDisconnectInfo) return;
|
|
32
35
|
if (devFlag && log.includes('Trying to reconnect')) {
|
|
33
|
-
if (retryCount)
|
|
36
|
+
if (retryCount) slardar.sendEvent({
|
|
34
37
|
name: 'sandbox-devServer',
|
|
35
|
-
|
|
36
|
-
type: 'reconnect-failed',
|
|
38
|
+
metrics: {
|
|
37
39
|
retryCount: retryCount + 1
|
|
40
|
+
},
|
|
41
|
+
categories: {
|
|
42
|
+
type: 'reconnect-failed'
|
|
38
43
|
}
|
|
39
44
|
});
|
|
40
45
|
retryCount++;
|
|
@@ -52,12 +57,14 @@ function processDevServerLog(log) {
|
|
|
52
57
|
const startTime = devServerDisconnectInfo.time;
|
|
53
58
|
const duration = Date.now() - startTime;
|
|
54
59
|
devServerDisconnectInfo = null;
|
|
55
|
-
|
|
60
|
+
slardar.sendEvent({
|
|
56
61
|
name: 'sandbox-devServer',
|
|
57
|
-
|
|
58
|
-
type: 'devServer-reconnected',
|
|
62
|
+
metrics: {
|
|
59
63
|
startTime,
|
|
60
64
|
duration
|
|
65
|
+
},
|
|
66
|
+
categories: {
|
|
67
|
+
type: 'devServer-reconnected'
|
|
61
68
|
}
|
|
62
69
|
});
|
|
63
70
|
}
|
|
@@ -76,7 +83,7 @@ function listenModuleHmr() {
|
|
|
76
83
|
});
|
|
77
84
|
hmr.onError((error)=>{
|
|
78
85
|
console.warn('hmr apply failed', error);
|
|
79
|
-
|
|
86
|
+
slardar.sendEvent({
|
|
80
87
|
name: 'sandbox-devServer',
|
|
81
88
|
categories: {
|
|
82
89
|
type: 'hmr-apply-failed',
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -3,6 +3,7 @@ import { observable } from "@lark-apaas/observable-web";
|
|
|
3
3
|
import { logger } from "../apis/logger.js";
|
|
4
4
|
import { getStacktrace } from "../logger/selected-logs.js";
|
|
5
5
|
import { safeStringify } from "./safeStringify.js";
|
|
6
|
+
import { slardar } from "@lark-apaas/internal-slardar";
|
|
6
7
|
const isValidResponse = (resp)=>null != resp && 'object' == typeof resp && 'config' in resp && null !== resp.config && void 0 !== resp.config && 'object' == typeof resp.config && 'status' in resp && 'number' == typeof resp.status && 'data' in resp;
|
|
7
8
|
async function logResponse(ok, responseOrError) {
|
|
8
9
|
if (isValidResponse(responseOrError)) {
|
|
@@ -193,6 +194,10 @@ AxiosProto.request = function(configOrUrl, config) {
|
|
|
193
194
|
return response;
|
|
194
195
|
}, (error)=>{
|
|
195
196
|
handleSpanEnd(error.config || finalConfig, null, error);
|
|
197
|
+
slardar.captureException(error, {
|
|
198
|
+
source: 'toolkit',
|
|
199
|
+
module: 'axios-request'
|
|
200
|
+
});
|
|
196
201
|
throw error;
|
|
197
202
|
});
|
|
198
203
|
};
|
|
@@ -253,9 +258,24 @@ function initAxiosConfig(axiosInstance) {
|
|
|
253
258
|
],
|
|
254
259
|
meta: {}
|
|
255
260
|
});
|
|
261
|
+
slardar.sendEvent({
|
|
262
|
+
name: 'toolkit_axios_403_downgrade',
|
|
263
|
+
categories: {
|
|
264
|
+
url: String(error.config?.url || ''),
|
|
265
|
+
method: String(error.config?.method || '')
|
|
266
|
+
}
|
|
267
|
+
});
|
|
256
268
|
return error.response;
|
|
257
269
|
}
|
|
258
270
|
} catch (e) {}
|
|
271
|
+
slardar.sendEvent({
|
|
272
|
+
name: 'toolkit_axios_response_error',
|
|
273
|
+
categories: {
|
|
274
|
+
url: String(error.config?.url || ''),
|
|
275
|
+
method: String(error.config?.method || ''),
|
|
276
|
+
status: String(error.response?.status || '')
|
|
277
|
+
}
|
|
278
|
+
});
|
|
259
279
|
return Promise.reject(error);
|
|
260
280
|
});
|
|
261
281
|
'production' !== process.env.NODE_ENV && instance.interceptors.response.use((response)=>{
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { IncomingMessage, OutgoingMessage } from '../types/iframe-events';
|
|
2
2
|
export declare function resolveParentOrigin(): string;
|
|
3
3
|
export declare function submitPostMessage<T extends OutgoingMessage>(message: T, targetOrigin?: string): void;
|
|
4
|
-
export declare function submitSlardarEvent(event: unknown): void;
|
|
5
4
|
export declare function isOutgoingMessage<T extends OutgoingMessage['type']>(msg: OutgoingMessage, type: T): msg is Extract<OutgoingMessage, {
|
|
6
5
|
type: T;
|
|
7
6
|
}>;
|
package/lib/utils/postMessage.js
CHANGED
|
@@ -38,15 +38,10 @@ function submitPostMessage(message, targetOrigin) {
|
|
|
38
38
|
console.error('postMessage error', e);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function submitSlardarEvent(event) {
|
|
42
|
-
const slardar = window.KSlardarWeb;
|
|
43
|
-
if ('function' == typeof slardar) slardar('sendEvent', event);
|
|
44
|
-
else console.warn('hmr listen function not found');
|
|
45
|
-
}
|
|
46
41
|
function isOutgoingMessage(msg, type) {
|
|
47
42
|
return msg.type === type;
|
|
48
43
|
}
|
|
49
44
|
function isIncomingMessage(msg, type) {
|
|
50
45
|
return msg.type === type;
|
|
51
46
|
}
|
|
52
|
-
export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage
|
|
47
|
+
export { isIncomingMessage, isOutgoingMessage, resolveParentOrigin, submitPostMessage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.24-alpha-test.0",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -99,10 +99,11 @@
|
|
|
99
99
|
"@ant-design/colors": "^7.2.1",
|
|
100
100
|
"@ant-design/cssinjs": "^1.24.0",
|
|
101
101
|
"@data-loom/js": "0.4.9",
|
|
102
|
-
"@lark-apaas/aily-web-sdk": "^0.0.
|
|
103
|
-
"@lark-apaas/auth-sdk": "^0.1.
|
|
104
|
-
"@lark-apaas/client-capability": "^0.1.
|
|
105
|
-
"@lark-apaas/
|
|
102
|
+
"@lark-apaas/aily-web-sdk": "^0.0.7",
|
|
103
|
+
"@lark-apaas/auth-sdk": "^0.1.2",
|
|
104
|
+
"@lark-apaas/client-capability": "^0.1.6",
|
|
105
|
+
"@lark-apaas/internal-slardar": "^0.0.3",
|
|
106
|
+
"@lark-apaas/miaoda-inspector": "^1.0.20",
|
|
106
107
|
"@lark-apaas/observable-web": "^1.0.4",
|
|
107
108
|
"@radix-ui/react-avatar": "^1.1.10",
|
|
108
109
|
"@radix-ui/react-popover": "^1.1.15",
|