@taicode/common-web 1.1.21 → 3.1.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/output/cache-api/cache-api.js +1 -1
- package/output/cache-api/cache-api.test.js +1 -1
- package/output/cache-api/index.d.ts +1 -1
- package/output/cache-api/index.d.ts.map +1 -1
- package/output/cache-api/index.js +1 -1
- package/output/loading-button/LoadingButtonDemo.d.ts +5 -0
- package/output/loading-button/LoadingButtonDemo.d.ts.map +1 -0
- package/output/loading-button/LoadingButtonDemo.js +33 -0
- package/output/loading-button/index.d.ts +31 -13
- package/output/loading-button/index.d.ts.map +1 -1
- package/output/loading-button/index.js +50 -26
- package/output/loading-button/index.test.d.ts +2 -0
- package/output/loading-button/index.test.d.ts.map +1 -0
- package/output/loading-button/index.test.js +203 -0
- package/output/service/index.d.ts +1 -1
- package/output/service/index.d.ts.map +1 -1
- package/output/service/index.js +1 -1
- package/output/service/service.d.ts +1 -1
- package/output/service/service.d.ts.map +1 -1
- package/output/service/service.js +9 -8
- package/output/service/service.test.js +2 -1
- package/output/side-cache/index.d.ts +1 -1
- package/output/side-cache/index.d.ts.map +1 -1
- package/output/side-cache/index.js +1 -1
- package/output/side-cache/side-cache.test.js +1 -1
- package/output/signin/context.d.ts +1 -2
- package/output/signin/context.d.ts.map +1 -1
- package/output/signin/context.js +3 -3
- package/output/signin/index.d.ts +3 -3
- package/output/signin/index.d.ts.map +1 -1
- package/output/signin/index.js +36 -18
- package/output/signin/service.d.ts +1 -1
- package/output/signin/service.d.ts.map +1 -1
- package/output/signin/service.js +6 -6
- package/output/signin/service.test.js +7 -3
- package/output/size-provider/index.d.ts +1 -1
- package/output/size-provider/index.d.ts.map +1 -1
- package/output/size-provider/index.js +1 -1
- package/output/size-provider/size-provider.d.ts +1 -1
- package/output/size-provider/size-provider.d.ts.map +1 -1
- package/output/size-provider/size-provider.js +1 -1
- package/output/toaster/index.d.ts +0 -1
- package/output/toaster/index.d.ts.map +1 -1
- package/output/toaster/index.js +7 -8
- package/output/use-observer/index.d.ts +1 -1
- package/output/use-observer/index.d.ts.map +1 -1
- package/output/use-observer/index.js +1 -1
- package/output/use-observer/use-observer.js +2 -2
- package/output/use-observer/use-observer.test.js +2 -2
- package/package.json +26 -18
- package/output/catalyst/alert.jsx +0 -55
- package/output/catalyst/auth-layout.jsx +0 -7
- package/output/catalyst/avatar.jsx +0 -45
- package/output/catalyst/badge.jsx +0 -53
- package/output/catalyst/button.jsx +0 -187
- package/output/catalyst/checkbox.jsx +0 -105
- package/output/catalyst/combobox.jsx +0 -120
- package/output/catalyst/description-list.jsx +0 -24
- package/output/catalyst/dialog.jsx +0 -55
- package/output/catalyst/divider.jsx +0 -16
- package/output/catalyst/dropdown.jsx +0 -102
- package/output/catalyst/fieldset.jsx +0 -41
- package/output/catalyst/heading.jsx +0 -22
- package/output/catalyst/input.jsx +0 -73
- package/output/catalyst/link.jsx +0 -14
- package/output/catalyst/listbox.jsx +0 -120
- package/output/catalyst/navbar.jsx +0 -67
- package/output/catalyst/pagination.jsx +0 -52
- package/output/catalyst/radio.jsx +0 -103
- package/output/catalyst/select.jsx +0 -59
- package/output/catalyst/sidebar-layout.jsx +0 -58
- package/output/catalyst/sidebar.jsx +0 -85
- package/output/catalyst/stacked-layout.jsx +0 -55
- package/output/catalyst/switch.jsx +0 -161
- package/output/catalyst/table.jsx +0 -68
- package/output/catalyst/text.jsx +0 -29
- package/output/catalyst/textarea.jsx +0 -49
- package/output/helpers/cache-api/cache-api.d.ts +0 -13
- package/output/helpers/cache-api/cache-api.d.ts.map +0 -1
- package/output/helpers/cache-api/cache-api.js +0 -114
- package/output/helpers/cache-api/cache-api.test.d.ts +0 -2
- package/output/helpers/cache-api/cache-api.test.d.ts.map +0 -1
- package/output/helpers/cache-api/cache-api.test.js +0 -348
- package/output/helpers/cache-api/index.d.ts +0 -2
- package/output/helpers/cache-api/index.d.ts.map +0 -1
- package/output/helpers/cache-api/index.js +0 -1
- package/output/helpers/service/index.d.ts +0 -1
- package/output/helpers/service/index.d.ts.map +0 -1
- package/output/helpers/service/index.js +0 -1
- package/output/helpers/service/service.d.ts +0 -5
- package/output/helpers/service/service.d.ts.map +0 -1
- package/output/helpers/service/service.js +0 -2
- package/output/helpers/side-cache/index.d.ts +0 -2
- package/output/helpers/side-cache/index.d.ts.map +0 -1
- package/output/helpers/side-cache/index.js +0 -1
- package/output/helpers/side-cache/side-cache.d.ts +0 -10
- package/output/helpers/side-cache/side-cache.d.ts.map +0 -1
- package/output/helpers/side-cache/side-cache.js +0 -137
- package/output/helpers/side-cache/side-cache.test.d.ts +0 -2
- package/output/helpers/side-cache/side-cache.test.d.ts.map +0 -1
- package/output/helpers/side-cache/side-cache.test.js +0 -179
- package/output/helpers/use-observer/index.d.ts +0 -2
- package/output/helpers/use-observer/index.d.ts.map +0 -1
- package/output/helpers/use-observer/index.js +0 -1
- package/output/helpers/use-observer/use-observer.d.ts +0 -3
- package/output/helpers/use-observer/use-observer.d.ts.map +0 -1
- package/output/helpers/use-observer/use-observer.js +0 -16
- package/output/helpers/use-observer/use-observer.test.d.ts +0 -2
- package/output/helpers/use-observer/use-observer.test.d.ts.map +0 -1
- package/output/helpers/use-observer/use-observer.test.jsx +0 -134
- package/output/service/service.test.jsx +0 -367
- package/output/use-observer/use-observer.test.jsx +0 -134
|
@@ -45,7 +45,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
45
45
|
};
|
|
46
46
|
import { action, computed, observable, when } from 'mobx';
|
|
47
47
|
import { catchIt } from '@taicode/common-base';
|
|
48
|
-
import { SideCache } from '../side-cache';
|
|
48
|
+
import { SideCache } from '../side-cache/index.js';
|
|
49
49
|
let CacheApi = (() => {
|
|
50
50
|
var _a, _CacheApi_pendingRequests_accessor_storage;
|
|
51
51
|
var _b, _c, _d;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { runInAction, configure } from 'mobx';
|
|
3
|
-
import { CacheApi } from './cache-api';
|
|
3
|
+
import { CacheApi } from './cache-api.js';
|
|
4
4
|
// 配置 MobX 在测试环境中的行为
|
|
5
5
|
configure({
|
|
6
6
|
enforceActions: 'never',
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { CacheApi } from './cache-api';
|
|
1
|
+
export { CacheApi } from './cache-api.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/cache-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/cache-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CacheApi } from './cache-api';
|
|
1
|
+
export { CacheApi } from './cache-api.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadingButtonDemo.d.ts","sourceRoot":"","sources":["../../source/loading-button/LoadingButtonDemo.tsx"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,iBAAiB,4CAsKhC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { LoadingButton } from '../loading-button';
|
|
4
|
+
/**
|
|
5
|
+
* LoadingButton 组件演示
|
|
6
|
+
*/
|
|
7
|
+
export function LoadingButtonDemo() {
|
|
8
|
+
const [result, setResult] = useState('');
|
|
9
|
+
// 模拟异步保存操作
|
|
10
|
+
const handleSave = async () => {
|
|
11
|
+
setResult('正在保存...');
|
|
12
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
13
|
+
setResult('保存成功!');
|
|
14
|
+
};
|
|
15
|
+
// 模拟可能失败的操作
|
|
16
|
+
const handleDelete = async () => {
|
|
17
|
+
setResult('正在删除...');
|
|
18
|
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
19
|
+
// 模拟随机失败
|
|
20
|
+
if (Math.random() > 0.5) {
|
|
21
|
+
setResult('删除成功!');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
setResult('删除失败!');
|
|
25
|
+
throw new Error('删除失败');
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// 同步操作
|
|
29
|
+
const handleClick = () => {
|
|
30
|
+
setResult('立即点击!');
|
|
31
|
+
};
|
|
32
|
+
return (_jsxs("div", { className: "space-y-8 p-8", children: [_jsxs("div", { children: [_jsx("h2", { className: "text-2xl font-bold mb-4", children: "LoadingButton \u7EC4\u4EF6\u6F14\u793A" }), _jsx("p", { className: "text-gray-600 mb-4", children: "\u6F14\u793A\u5982\u4F55\u4F7F\u7528 LoadingButton \u7EC4\u4EF6\u5904\u7406\u5F02\u6B65\u64CD\u4F5C" })] }), result && (_jsx("div", { className: "p-4 bg-gray-100 dark:bg-gray-800 rounded-lg", children: _jsx("p", { className: "text-sm font-medium", children: result }) })), _jsxs("section", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: "\u57FA\u7840\u7528\u6CD5" }), _jsxs("div", { className: "flex gap-3 flex-wrap", children: [_jsx(LoadingButton, { color: "blue", onClick: handleSave, children: "\u4FDD\u5B58\u6570\u636E" }), _jsx(LoadingButton, { color: "red", onClick: handleDelete, children: "\u5220\u9664\u6570\u636E" }), _jsx(LoadingButton, { color: "green", onClick: handleClick, children: "\u540C\u6B65\u64CD\u4F5C" })] })] }), _jsxs("section", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: "\u4E0D\u540C\u6837\u5F0F" }), _jsxs("div", { className: "flex gap-3 flex-wrap", children: [_jsx(LoadingButton, { color: "emerald", onClick: handleSave, children: "Solid \u6837\u5F0F" }), _jsx(LoadingButton, { outline: true, onClick: handleSave, children: "Outline \u6837\u5F0F" }), _jsx(LoadingButton, { plain: true, onClick: handleSave, children: "Plain \u6837\u5F0F" })] })] }), _jsxs("section", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: "\u81EA\u5B9A\u4E49\u52A0\u8F7D\u6587\u672C" }), _jsxs("div", { className: "flex gap-3 flex-wrap", children: [_jsx(LoadingButton, { color: "blue", onClick: handleSave, loadingText: "\u6B63\u5728\u4FDD\u5B58\u6570\u636E...", children: "\u81EA\u5B9A\u4E49\u6587\u672C" }), _jsx(LoadingButton, { color: "purple", onClick: handleSave, loadingText: _jsxs("span", { className: "flex items-center gap-2", children: [_jsxs("svg", { className: "animate-spin h-4 w-4", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4", fill: "none" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), "\u5904\u7406\u4E2D"] }), children: "\u81EA\u5B9A\u4E49\u56FE\u6807" })] })] }), _jsxs("section", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: "\u989C\u8272\u9009\u9879" }), _jsxs("div", { className: "flex gap-3 flex-wrap", children: [_jsx(LoadingButton, { color: "red", onClick: handleSave, children: "Red" }), _jsx(LoadingButton, { color: "orange", onClick: handleSave, children: "Orange" }), _jsx(LoadingButton, { color: "amber", onClick: handleSave, children: "Amber" }), _jsx(LoadingButton, { color: "yellow", onClick: handleSave, children: "Yellow" }), _jsx(LoadingButton, { color: "lime", onClick: handleSave, children: "Lime" }), _jsx(LoadingButton, { color: "green", onClick: handleSave, children: "Green" }), _jsx(LoadingButton, { color: "emerald", onClick: handleSave, children: "Emerald" }), _jsx(LoadingButton, { color: "teal", onClick: handleSave, children: "Teal" }), _jsx(LoadingButton, { color: "cyan", onClick: handleSave, children: "Cyan" }), _jsx(LoadingButton, { color: "sky", onClick: handleSave, children: "Sky" }), _jsx(LoadingButton, { color: "blue", onClick: handleSave, children: "Blue" }), _jsx(LoadingButton, { color: "indigo", onClick: handleSave, children: "Indigo" }), _jsx(LoadingButton, { color: "violet", onClick: handleSave, children: "Violet" }), _jsx(LoadingButton, { color: "purple", onClick: handleSave, children: "Purple" }), _jsx(LoadingButton, { color: "fuchsia", onClick: handleSave, children: "Fuchsia" }), _jsx(LoadingButton, { color: "pink", onClick: handleSave, children: "Pink" }), _jsx(LoadingButton, { color: "rose", onClick: handleSave, children: "Rose" })] })] }), _jsxs("section", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: "\u7981\u7528\u72B6\u6001" }), _jsxs("div", { className: "flex gap-3 flex-wrap", children: [_jsx(LoadingButton, { color: "blue", disabled: true, onClick: handleSave, children: "\u7981\u7528\u6309\u94AE" }), _jsx(LoadingButton, { color: "green", onClick: handleSave, disableOnLoading: false, children: "\u52A0\u8F7D\u65F6\u4E0D\u7981\u7528" })] })] })] }));
|
|
33
|
+
}
|
|
@@ -1,26 +1,44 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { type ButtonProps } from '../catalyst/button';
|
|
1
|
+
import React, { type ComponentPropsWithoutRef, type ElementType } from 'react';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* 继承 Button 的所有属性,自动处理 onClick 的异步状态
|
|
3
|
+
* 多态组件的 Props 类型
|
|
6
4
|
*/
|
|
7
|
-
|
|
5
|
+
type PolymorphicProps<T extends ElementType> = {
|
|
6
|
+
as?: T;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
loadingText?: string;
|
|
9
|
+
loadingIcon?: React.ReactNode;
|
|
10
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void | Promise<void>;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
} & Omit<ComponentPropsWithoutRef<T>, 'as' | 'loading' | 'loadingText' | 'loadingIcon' | 'onClick'>;
|
|
8
14
|
/**
|
|
9
15
|
* LoadingButton 组件
|
|
10
16
|
*
|
|
11
|
-
*
|
|
17
|
+
* 支持任意组件作为基础按钮,在异步操作时自动显示 loading 状态
|
|
12
18
|
*
|
|
13
19
|
* @example
|
|
14
20
|
* ```tsx
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
+
* // 使用默认 button
|
|
22
|
+
* <LoadingButton onClick={async () => await save()}>
|
|
23
|
+
* 保存
|
|
24
|
+
* </LoadingButton>
|
|
25
|
+
*
|
|
26
|
+
* // 使用自定义组件
|
|
27
|
+
* <LoadingButton as={MyButton} onClick={async () => await save()}>
|
|
28
|
+
* 保存
|
|
29
|
+
* </LoadingButton>
|
|
30
|
+
*
|
|
31
|
+
* // 自定义 loading 图标
|
|
32
|
+
* <LoadingButton loadingIcon={<MySpinner />} onClick={async () => await save()}>
|
|
33
|
+
* 保存
|
|
34
|
+
* </LoadingButton>
|
|
35
|
+
*
|
|
36
|
+
* // 手动控制 loading 状态
|
|
37
|
+
* <LoadingButton loading={isLoading}>
|
|
21
38
|
* 保存
|
|
22
39
|
* </LoadingButton>
|
|
23
40
|
* ```
|
|
24
41
|
*/
|
|
25
|
-
export declare const LoadingButton: React.ForwardRefExoticComponent<
|
|
42
|
+
export declare const LoadingButton: React.ForwardRefExoticComponent<Omit<PolymorphicProps<React.ElementType>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
43
|
+
export {};
|
|
26
44
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/loading-button/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/loading-button/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAqC,KAAK,wBAAwB,EAAE,KAAK,WAAW,EAAE,MAAM,OAAO,CAAA;AAkCjH;;GAEG;AACH,KAAK,gBAAgB,CAAC,CAAC,SAAS,WAAW,IAAI;IAC7C,EAAE,CAAC,EAAE,CAAC,CAAA;IACN,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,SAAS,GAAG,aAAa,GAAG,aAAa,GAAG,SAAS,CAAC,CAAA;AAEnG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,aAAa,4HAsEzB,CAAA"}
|
|
@@ -9,47 +9,71 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import {
|
|
14
|
-
import { Button } from '../catalyst/button';
|
|
15
|
-
import { catchIt } from '@taicode/common-base';
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import React, { useState, useCallback, forwardRef } from 'react';
|
|
16
14
|
function isPromiseLike(value) {
|
|
17
|
-
return value != null && typeof value.then === 'function';
|
|
15
|
+
return value != null && typeof value === 'object' && 'then' in value && typeof value.then === 'function';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Loading 指示器组件
|
|
19
|
+
*/
|
|
20
|
+
function LoadingSpinner({ className = '' }) {
|
|
21
|
+
return (_jsxs("svg", { className: `animate-spin ${className}`, xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }));
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
20
24
|
* LoadingButton 组件
|
|
21
25
|
*
|
|
22
|
-
*
|
|
26
|
+
* 支持任意组件作为基础按钮,在异步操作时自动显示 loading 状态
|
|
23
27
|
*
|
|
24
28
|
* @example
|
|
25
29
|
* ```tsx
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* // 使用默认 button
|
|
31
|
+
* <LoadingButton onClick={async () => await save()}>
|
|
32
|
+
* 保存
|
|
33
|
+
* </LoadingButton>
|
|
34
|
+
*
|
|
35
|
+
* // 使用自定义组件
|
|
36
|
+
* <LoadingButton as={MyButton} onClick={async () => await save()}>
|
|
37
|
+
* 保存
|
|
38
|
+
* </LoadingButton>
|
|
39
|
+
*
|
|
40
|
+
* // 自定义 loading 图标
|
|
41
|
+
* <LoadingButton loadingIcon={<MySpinner />} onClick={async () => await save()}>
|
|
42
|
+
* 保存
|
|
43
|
+
* </LoadingButton>
|
|
44
|
+
*
|
|
45
|
+
* // 手动控制 loading 状态
|
|
46
|
+
* <LoadingButton loading={isLoading}>
|
|
32
47
|
* 保存
|
|
33
48
|
* </LoadingButton>
|
|
34
49
|
* ```
|
|
35
50
|
*/
|
|
36
51
|
export const LoadingButton = forwardRef(function LoadingButton(_a, ref) {
|
|
37
|
-
var {
|
|
38
|
-
const [
|
|
39
|
-
const
|
|
40
|
-
|
|
52
|
+
var { as, loading: externalLoading, loadingText, loadingIcon, onClick, disabled, children, className = '' } = _a, props = __rest(_a, ["as", "loading", "loadingText", "loadingIcon", "onClick", "disabled", "children", "className"]);
|
|
53
|
+
const [internalLoading, setInternalLoading] = useState(false);
|
|
54
|
+
const loading = externalLoading !== null && externalLoading !== void 0 ? externalLoading : internalLoading;
|
|
55
|
+
const handleClick = useCallback((event) => {
|
|
56
|
+
if (!onClick || loading || disabled)
|
|
41
57
|
return;
|
|
42
58
|
const result = onClick(event);
|
|
43
|
-
//
|
|
59
|
+
// 如果返回 Promise-like,自动管理 loading 状态,但不捕获异常
|
|
60
|
+
// 使用 then 而不是 finally,因为 PromiseLike 不保证有 finally 方法
|
|
61
|
+
// 在 rejected 回调中重新抛出,让异常传播到全局错误处理机制(如 Toaster)
|
|
44
62
|
if (isPromiseLike(result)) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
throw catchResult.error;
|
|
51
|
-
}
|
|
63
|
+
setInternalLoading(true);
|
|
64
|
+
result.then(() => setInternalLoading(false), (error) => {
|
|
65
|
+
setInternalLoading(false);
|
|
66
|
+
throw error;
|
|
67
|
+
});
|
|
52
68
|
}
|
|
53
|
-
};
|
|
54
|
-
|
|
69
|
+
}, [onClick, loading, disabled]);
|
|
70
|
+
// 使用 as prop 或默认 button
|
|
71
|
+
const Component = as || 'button';
|
|
72
|
+
// 默认 button 样式(仅当使用默认 button 时应用)
|
|
73
|
+
const defaultButtonClass = !as
|
|
74
|
+
? 'inline-flex items-center justify-center gap-2 rounded-[var(--radius)] bg-[var(--primary)] px-4 py-2 text-sm font-medium text-[var(--primary-foreground)] shadow-sm transition-opacity hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-[var(--ring)] focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed'
|
|
75
|
+
: '';
|
|
76
|
+
const finalClassName = `${defaultButtonClass} ${className}`.trim();
|
|
77
|
+
return (_jsx(Component, Object.assign({ ref: ref, onClick: handleClick, disabled: disabled || loading, className: finalClassName }, props, { children: loading ? (_jsxs(_Fragment, { children: [loadingIcon || _jsx(LoadingSpinner, { className: "size-4" }), loadingText || children] })) : (children) })));
|
|
55
78
|
});
|
|
79
|
+
LoadingButton.displayName = 'LoadingButton';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../source/loading-button/index.test.tsx"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAA"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import '@testing-library/jest-dom/vitest';
|
|
14
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
15
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
16
|
+
import { LoadingButton } from './index.js';
|
|
17
|
+
describe('LoadingButton', () => {
|
|
18
|
+
describe('基础功能', () => {
|
|
19
|
+
it('应该渲染按钮和子元素', () => {
|
|
20
|
+
render(_jsx(LoadingButton, { children: "\u70B9\u51FB\u6211" }));
|
|
21
|
+
expect(screen.getByRole('button')).toHaveTextContent('点击我');
|
|
22
|
+
});
|
|
23
|
+
it('应该支持 disabled 属性', () => {
|
|
24
|
+
render(_jsx(LoadingButton, { disabled: true, children: "\u70B9\u51FB\u6211" }));
|
|
25
|
+
expect(screen.getByRole('button')).toBeDisabled();
|
|
26
|
+
});
|
|
27
|
+
it('应该应用自定义 className', () => {
|
|
28
|
+
render(_jsx(LoadingButton, { className: "custom-class", children: "\u70B9\u51FB\u6211" }));
|
|
29
|
+
expect(screen.getByRole('button')).toHaveClass('custom-class');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('同步点击', () => {
|
|
33
|
+
it('应该处理同步点击事件', () => {
|
|
34
|
+
const handleClick = vi.fn();
|
|
35
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u70B9\u51FB\u6211" }));
|
|
36
|
+
fireEvent.click(screen.getByRole('button'));
|
|
37
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
38
|
+
});
|
|
39
|
+
it('同步操作不应该显示 loading', () => {
|
|
40
|
+
const handleClick = vi.fn();
|
|
41
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u70B9\u51FB\u6211" }));
|
|
42
|
+
fireEvent.click(screen.getByRole('button'));
|
|
43
|
+
expect(screen.queryByRole('button')).toHaveTextContent('点击我');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('异步点击', () => {
|
|
47
|
+
it('应该在异步操作期间显示 loading', async () => {
|
|
48
|
+
const handleClick = vi.fn(async () => {
|
|
49
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
50
|
+
});
|
|
51
|
+
render(_jsx(LoadingButton, { children: "\u4FDD\u5B58" }));
|
|
52
|
+
const button = screen.getByRole('button');
|
|
53
|
+
fireEvent.click(button);
|
|
54
|
+
// 应该立即显示 loading
|
|
55
|
+
await waitFor(() => {
|
|
56
|
+
expect(button).toBeDisabled();
|
|
57
|
+
});
|
|
58
|
+
// 等待异步操作完成
|
|
59
|
+
await waitFor(() => {
|
|
60
|
+
expect(button).not.toBeDisabled();
|
|
61
|
+
}, { timeout: 200 });
|
|
62
|
+
});
|
|
63
|
+
it('异步操作完成后应该恢复正常状态', async () => {
|
|
64
|
+
let resolve;
|
|
65
|
+
const promise = new Promise(r => { resolve = r; });
|
|
66
|
+
const handleClick = vi.fn(() => promise);
|
|
67
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
68
|
+
const button = screen.getByRole('button');
|
|
69
|
+
fireEvent.click(button);
|
|
70
|
+
// loading 状态
|
|
71
|
+
await waitFor(() => {
|
|
72
|
+
expect(button).toBeDisabled();
|
|
73
|
+
});
|
|
74
|
+
// 完成异步操作
|
|
75
|
+
resolve();
|
|
76
|
+
// 恢复正常
|
|
77
|
+
await waitFor(() => {
|
|
78
|
+
expect(button).not.toBeDisabled();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
it('异步操作失败后应该恢复正常状态', async () => {
|
|
82
|
+
const handleClick = vi.fn(async () => {
|
|
83
|
+
await new Promise((_, reject) => setTimeout(() => reject(new Error('失败')), 50));
|
|
84
|
+
});
|
|
85
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
86
|
+
const button = screen.getByRole('button');
|
|
87
|
+
fireEvent.click(button);
|
|
88
|
+
// loading 状态
|
|
89
|
+
await waitFor(() => {
|
|
90
|
+
expect(button).toBeDisabled();
|
|
91
|
+
});
|
|
92
|
+
// 等待失败并恢复
|
|
93
|
+
await waitFor(() => {
|
|
94
|
+
expect(button).not.toBeDisabled();
|
|
95
|
+
}, { timeout: 100 });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe('手动控制 loading', () => {
|
|
99
|
+
it('应该支持外部控制 loading 状态', () => {
|
|
100
|
+
const { rerender } = render(_jsx(LoadingButton, { loading: false, children: "\u4FDD\u5B58" }));
|
|
101
|
+
expect(screen.getByRole('button')).not.toBeDisabled();
|
|
102
|
+
rerender(_jsx(LoadingButton, { loading: true, children: "\u4FDD\u5B58" }));
|
|
103
|
+
expect(screen.getByRole('button')).toBeDisabled();
|
|
104
|
+
});
|
|
105
|
+
it('外部 loading 状态应该优先于内部状态', async () => {
|
|
106
|
+
const handleClick = vi.fn(async () => {
|
|
107
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
108
|
+
});
|
|
109
|
+
render(_jsx(LoadingButton, { loading: true, onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
110
|
+
const button = screen.getByRole('button');
|
|
111
|
+
// 外部 loading 为 true,应该禁用
|
|
112
|
+
expect(button).toBeDisabled();
|
|
113
|
+
// 点击不应该触发
|
|
114
|
+
fireEvent.click(button);
|
|
115
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe('loading 显示定制', () => {
|
|
119
|
+
it('应该显示自定义 loadingText', async () => {
|
|
120
|
+
const handleClick = vi.fn(async () => {
|
|
121
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
122
|
+
});
|
|
123
|
+
render(_jsx(LoadingButton, { loadingText: "\u5904\u7406\u4E2D...", onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
124
|
+
fireEvent.click(screen.getByRole('button'));
|
|
125
|
+
await waitFor(() => {
|
|
126
|
+
expect(screen.getByText('处理中...')).toBeInTheDocument();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
it('应该显示自定义 loadingIcon', async () => {
|
|
130
|
+
const handleClick = vi.fn(async () => {
|
|
131
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
132
|
+
});
|
|
133
|
+
render(_jsx(LoadingButton, { loadingIcon: _jsx("span", { "data-testid": "custom-icon", children: "\u23F3" }), onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
134
|
+
fireEvent.click(screen.getByRole('button'));
|
|
135
|
+
await waitFor(() => {
|
|
136
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('多态组件 (as prop)', () => {
|
|
141
|
+
it('应该渲染为自定义组件', () => {
|
|
142
|
+
const CustomButton = (_a) => {
|
|
143
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
144
|
+
return (_jsx("button", Object.assign({ "data-testid": "custom-button" }, props, { children: children })));
|
|
145
|
+
};
|
|
146
|
+
render(_jsx(LoadingButton, { as: CustomButton, children: "\u70B9\u51FB\u6211" }));
|
|
147
|
+
expect(screen.getByTestId('custom-button')).toBeInTheDocument();
|
|
148
|
+
});
|
|
149
|
+
it('应该渲染为 anchor 标签', () => {
|
|
150
|
+
render(_jsx(LoadingButton, { as: "a", href: "#", children: "\u94FE\u63A5" }));
|
|
151
|
+
const link = screen.getByText('链接');
|
|
152
|
+
expect(link.tagName).toBe('A');
|
|
153
|
+
});
|
|
154
|
+
it('自定义组件应该保留其 props', () => {
|
|
155
|
+
render(_jsx(LoadingButton, { as: "a", href: "https://example.com", target: "_blank", children: "\u94FE\u63A5" }));
|
|
156
|
+
const link = screen.getByText('链接');
|
|
157
|
+
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
158
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('禁用状态', () => {
|
|
162
|
+
it('禁用时不应该触发点击', () => {
|
|
163
|
+
const handleClick = vi.fn();
|
|
164
|
+
render(_jsx(LoadingButton, { disabled: true, onClick: handleClick, children: "\u70B9\u51FB\u6211" }));
|
|
165
|
+
fireEvent.click(screen.getByRole('button'));
|
|
166
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
it('loading 时不应该触发点击', async () => {
|
|
169
|
+
const handleClick = vi.fn(async () => {
|
|
170
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
171
|
+
});
|
|
172
|
+
render(_jsx(LoadingButton, { onClick: handleClick, children: "\u4FDD\u5B58" }));
|
|
173
|
+
const button = screen.getByRole('button');
|
|
174
|
+
// 第一次点击
|
|
175
|
+
fireEvent.click(button);
|
|
176
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
177
|
+
// loading 期间再次点击
|
|
178
|
+
fireEvent.click(button);
|
|
179
|
+
fireEvent.click(button);
|
|
180
|
+
// 不应该再次触发
|
|
181
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
182
|
+
// 等待完成
|
|
183
|
+
await waitFor(() => {
|
|
184
|
+
expect(button).not.toBeDisabled();
|
|
185
|
+
}, { timeout: 150 });
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe('默认样式', () => {
|
|
189
|
+
it('使用默认 button 时应该应用默认样式', () => {
|
|
190
|
+
render(_jsx(LoadingButton, { children: "\u70B9\u51FB\u6211" }));
|
|
191
|
+
const button = screen.getByRole('button');
|
|
192
|
+
// 检查是否包含默认样式类
|
|
193
|
+
expect(button.className).toContain('inline-flex');
|
|
194
|
+
expect(button.className).toContain('bg-primary');
|
|
195
|
+
});
|
|
196
|
+
it('使用 as prop 时不应该应用默认样式', () => {
|
|
197
|
+
render(_jsx(LoadingButton, { as: "a", children: "\u94FE\u63A5" }));
|
|
198
|
+
const link = screen.getByText('链接');
|
|
199
|
+
// 不应该包含默认 button 样式
|
|
200
|
+
expect(link.className).not.toContain('bg-primary');
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { useService, useLocalService, ServiceProvider } from './service';
|
|
1
|
+
export { useService, useLocalService, ServiceProvider } from './service.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
|
package/output/service/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useService, useLocalService, ServiceProvider } from './service';
|
|
1
|
+
export { useService, useLocalService, ServiceProvider } from './service.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../source/service/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../source/service/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,OAAO,EAAE,KAAK,KAAK,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,KAA0E,MAAM,OAAO,CAAA;AA+D9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AAEH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAClD,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAgDlF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;AAC9E,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAyF9G;;GAEG;AACH,UAAU,oBAAoB;IAC5B;;;;;OAKG;IACH,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAA;IAC7B,UAAU;IACV,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AACH,6CAA6C;AAE7C,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,8EA2B1D"}
|
|
@@ -33,8 +33,9 @@
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
import { reaction, runInAction } from 'mobx';
|
|
36
|
+
import { Service } from '@taicode/common-base';
|
|
36
37
|
import { Container } from '@needle-di/core';
|
|
37
|
-
import React, { useContext, useEffect, useMemo, useState, useRef } from 'react';
|
|
38
|
+
import React, { useContext, useEffect, useMemo, useState, useRef, createElement } from 'react';
|
|
38
39
|
/**
|
|
39
40
|
* React Context 用于传递 DI 容器实例
|
|
40
41
|
* 通过上下文在组件树中共享依赖注入容器
|
|
@@ -88,7 +89,7 @@ export function useService(target, selector) {
|
|
|
88
89
|
const container = useContext(ctx);
|
|
89
90
|
// 使用 useState 强制组件重新渲染
|
|
90
91
|
const [, refresh] = useState({});
|
|
91
|
-
|
|
92
|
+
useEffect(() => {
|
|
92
93
|
if (container == null)
|
|
93
94
|
return;
|
|
94
95
|
// 从容器中获取服务实例
|
|
@@ -141,7 +142,7 @@ export function useLocalService(ServiceClass, selector) {
|
|
|
141
142
|
serviceInstanceRef.current = localContainerRef.current.get(ServiceClass);
|
|
142
143
|
}
|
|
143
144
|
// 模仿 useService 的结构:在 useEffect 中设置 reaction 和初始化
|
|
144
|
-
|
|
145
|
+
useEffect(() => {
|
|
145
146
|
if (parentContainer == null)
|
|
146
147
|
return;
|
|
147
148
|
const service = serviceInstanceRef.current;
|
|
@@ -166,7 +167,7 @@ export function useLocalService(ServiceClass, selector) {
|
|
|
166
167
|
return dispose;
|
|
167
168
|
}, [parentContainer, selector, ServiceClass]);
|
|
168
169
|
// 单独的 useEffect 处理服务初始化,避免与 selector 变化的冲突
|
|
169
|
-
|
|
170
|
+
useEffect(() => {
|
|
170
171
|
if (parentContainer == null)
|
|
171
172
|
return;
|
|
172
173
|
let disposed = false;
|
|
@@ -284,9 +285,9 @@ export function ServiceProvider(props) {
|
|
|
284
285
|
});
|
|
285
286
|
return currentContainer;
|
|
286
287
|
}, [parentContainer, services]);
|
|
287
|
-
// 使用
|
|
288
|
-
const init =
|
|
289
|
-
return
|
|
288
|
+
// 使用 createElement 避免将文件改为 .tsx
|
|
289
|
+
const init = createElement(InitService, { services, children });
|
|
290
|
+
return createElement(ctx.Provider, { value: container, children: container ? init : null });
|
|
290
291
|
}
|
|
291
292
|
/**
|
|
292
293
|
* 服务初始化组件
|
|
@@ -310,7 +311,7 @@ export function ServiceProvider(props) {
|
|
|
310
311
|
function InitService(props) {
|
|
311
312
|
const { services, children } = props;
|
|
312
313
|
const container = useContext(ctx);
|
|
313
|
-
const [initError, setInitError] =
|
|
314
|
+
const [initError, setInitError] = useState(null);
|
|
314
315
|
useEffect(() => {
|
|
315
316
|
if (container == null)
|
|
316
317
|
return;
|
|
@@ -49,7 +49,8 @@ import { Service } from '@taicode/common-base';
|
|
|
49
49
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
50
50
|
import { render, renderHook, waitFor } from '@testing-library/react';
|
|
51
51
|
import { observable, makeObservable, runInAction, action } from 'mobx';
|
|
52
|
-
import {
|
|
52
|
+
import { inject } from '@needle-di/core';
|
|
53
|
+
import { useService, useLocalService, ServiceProvider } from './service.js';
|
|
53
54
|
class TestErrorBoundary extends React.Component {
|
|
54
55
|
constructor() {
|
|
55
56
|
super(...arguments);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { SideCache } from './side-cache';
|
|
1
|
+
export { SideCache } from './side-cache.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/side-cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/side-cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SideCache } from './side-cache';
|
|
1
|
+
export { SideCache } from './side-cache.js';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
/**
|
|
3
2
|
* 登录上下文值
|
|
4
3
|
*/
|
|
5
4
|
interface SigninContextValue {
|
|
6
5
|
signin: () => Promise<void>;
|
|
7
6
|
}
|
|
8
|
-
export declare const SigninContext:
|
|
7
|
+
export declare const SigninContext: import("react").Context<SigninContextValue | null>;
|
|
9
8
|
/**
|
|
10
9
|
* 使用登录上下文
|
|
11
10
|
* 用于在任何子组件中调用登录方法
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../source/signin/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../source/signin/context.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5B;AAED,eAAO,MAAM,aAAa,oDAAiD,CAAA;AAE3E;;;GAGG;AACH,wBAAgB,SAAS,uBAMxB"}
|
package/output/signin/context.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const SigninContext =
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export const SigninContext = createContext(null);
|
|
3
3
|
/**
|
|
4
4
|
* 使用登录上下文
|
|
5
5
|
* 用于在任何子组件中调用登录方法
|
|
6
6
|
*/
|
|
7
7
|
export function useSignin() {
|
|
8
|
-
const context =
|
|
8
|
+
const context = useContext(SigninContext);
|
|
9
9
|
if (!context) {
|
|
10
10
|
throw new Error('useSigninContext must be used within SigninDialogProvider');
|
|
11
11
|
}
|