@taicode/common-web 3.7.4 → 3.7.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/LICENSE +21 -0
- package/package.json +12 -13
- package/styles.css +2 -0
- package/output/components/alert-dialog.d.ts +0 -20
- package/output/components/alert-dialog.d.ts.map +0 -1
- package/output/components/alert-dialog.js +0 -65
- package/output/components/alert.d.ts +0 -11
- package/output/components/alert.d.ts.map +0 -1
- package/output/components/alert.js +0 -38
- package/output/components/avatar.d.ts +0 -13
- package/output/components/avatar.d.ts.map +0 -1
- package/output/components/avatar.js +0 -40
- package/output/components/badge.d.ts +0 -11
- package/output/components/badge.d.ts.map +0 -1
- package/output/components/badge.js +0 -39
- package/output/components/button.d.ts +0 -12
- package/output/components/button.d.ts.map +0 -1
- package/output/components/button.js +0 -48
- package/output/components/calendar.d.ts +0 -13
- package/output/components/calendar.d.ts.map +0 -1
- package/output/components/calendar.js +0 -57
- package/output/components/card.d.ts +0 -13
- package/output/components/card.d.ts.map +0 -1
- package/output/components/card.js +0 -43
- package/output/components/chart.d.ts +0 -56
- package/output/components/chart.d.ts.map +0 -1
- package/output/components/chart.js +0 -127
- package/output/components/checkbox.d.ts +0 -5
- package/output/components/checkbox.d.ts.map +0 -1
- package/output/components/checkbox.js +0 -21
- package/output/components/command.d.ts +0 -20
- package/output/components/command.d.ts.map +0 -1
- package/output/components/command.js +0 -55
- package/output/components/dialog.d.ts +0 -20
- package/output/components/dialog.d.ts.map +0 -1
- package/output/components/dialog.js +0 -58
- package/output/components/direction.d.ts +0 -9
- package/output/components/direction.d.ts.map +0 -1
- package/output/components/direction.js +0 -10
- package/output/components/drawer.d.ts +0 -14
- package/output/components/drawer.d.ts.map +0 -1
- package/output/components/drawer.js +0 -56
- package/output/components/dropdown-menu.d.ts +0 -29
- package/output/components/dropdown-menu.d.ts.map +0 -1
- package/output/components/dropdown-menu.js +0 -78
- package/output/components/field.d.ts +0 -39
- package/output/components/field.d.ts.map +0 -1
- package/output/components/field.js +0 -102
- package/output/components/footer/index.d.ts +0 -27
- package/output/components/footer/index.d.ts.map +0 -1
- package/output/components/footer/index.js +0 -17
- package/output/components/form.d.ts +0 -26
- package/output/components/form.d.ts.map +0 -1
- package/output/components/form.js +0 -69
- package/output/components/index.d.ts +0 -46
- package/output/components/index.d.ts.map +0 -1
- package/output/components/index.js +0 -45
- package/output/components/input-group.d.ts +0 -17
- package/output/components/input-group.d.ts.map +0 -1
- package/output/components/input-group.js +0 -75
- package/output/components/input.d.ts +0 -4
- package/output/components/input.d.ts.map +0 -1
- package/output/components/input.js +0 -19
- package/output/components/item.d.ts +0 -25
- package/output/components/item.d.ts.map +0 -1
- package/output/components/item.js +0 -89
- package/output/components/json-view/index.d.ts +0 -11
- package/output/components/json-view/index.d.ts.map +0 -1
- package/output/components/json-view/index.js +0 -52
- package/output/components/json-view/lazy/index.d.ts +0 -18
- package/output/components/json-view/lazy/index.d.ts.map +0 -1
- package/output/components/json-view/lazy/index.js +0 -22
- package/output/components/kbd.d.ts +0 -4
- package/output/components/kbd.d.ts.map +0 -1
- package/output/components/kbd.js +0 -22
- package/output/components/label.d.ts +0 -5
- package/output/components/label.d.ts.map +0 -1
- package/output/components/label.js +0 -20
- package/output/components/list-actions/index.d.ts +0 -23
- package/output/components/list-actions/index.d.ts.map +0 -1
- package/output/components/list-actions/index.js +0 -15
- package/output/components/loading-button/index.d.ts +0 -44
- package/output/components/loading-button/index.d.ts.map +0 -1
- package/output/components/loading-button/index.js +0 -75
- package/output/components/loading-button/index.test.d.ts +0 -2
- package/output/components/loading-button/index.test.d.ts.map +0 -1
- package/output/components/loading-button/index.test.js +0 -203
- package/output/components/native-select.d.ts +0 -9
- package/output/components/native-select.d.ts.map +0 -1
- package/output/components/native-select.js +0 -28
- package/output/components/page-back-button/index.d.ts +0 -8
- package/output/components/page-back-button/index.d.ts.map +0 -1
- package/output/components/page-back-button/index.js +0 -7
- package/output/components/page-state.d.ts +0 -19
- package/output/components/page-state.d.ts.map +0 -1
- package/output/components/page-state.js +0 -13
- package/output/components/pagination/index.d.ts +0 -34
- package/output/components/pagination/index.d.ts.map +0 -1
- package/output/components/pagination/index.js +0 -75
- package/output/components/popover.d.ts +0 -11
- package/output/components/popover.d.ts.map +0 -1
- package/output/components/popover.js +0 -44
- package/output/components/progress.d.ts +0 -5
- package/output/components/progress.d.ts.map +0 -1
- package/output/components/progress.js +0 -21
- package/output/components/radio-group.d.ts +0 -6
- package/output/components/radio-group.d.ts.map +0 -1
- package/output/components/radio-group.js +0 -25
- package/output/components/route-pending-indicator/index.d.ts +0 -20
- package/output/components/route-pending-indicator/index.d.ts.map +0 -1
- package/output/components/route-pending-indicator/index.js +0 -17
- package/output/components/scroll-area.d.ts +0 -6
- package/output/components/scroll-area.d.ts.map +0 -1
- package/output/components/scroll-area.js +0 -24
- package/output/components/searchable-select/index.d.ts +0 -41
- package/output/components/searchable-select/index.d.ts.map +0 -1
- package/output/components/searchable-select/index.js +0 -46
- package/output/components/select.d.ts +0 -17
- package/output/components/select.d.ts.map +0 -1
- package/output/components/select.js +0 -58
- package/output/components/separator.d.ts +0 -5
- package/output/components/separator.d.ts.map +0 -1
- package/output/components/separator.js +0 -20
- package/output/components/sheet.d.ts +0 -16
- package/output/components/sheet.d.ts.map +0 -1
- package/output/components/sheet.js +0 -58
- package/output/components/sidebar.d.ts +0 -78
- package/output/components/sidebar.d.ts.map +0 -1
- package/output/components/sidebar.js +0 -233
- package/output/components/size-provider/index.d.ts +0 -2
- package/output/components/size-provider/index.d.ts.map +0 -1
- package/output/components/size-provider/index.js +0 -1
- package/output/components/size-provider/size-provider.d.ts +0 -9
- package/output/components/size-provider/size-provider.d.ts.map +0 -1
- package/output/components/size-provider/size-provider.js +0 -29
- package/output/components/skeleton.d.ts +0 -3
- package/output/components/skeleton.d.ts.map +0 -1
- package/output/components/skeleton.js +0 -18
- package/output/components/sonner.d.ts +0 -8
- package/output/components/sonner.d.ts.map +0 -1
- package/output/components/sonner.js +0 -34
- package/output/components/spinner.d.ts +0 -3
- package/output/components/spinner.d.ts.map +0 -1
- package/output/components/spinner.js +0 -19
- package/output/components/switch.d.ts +0 -8
- package/output/components/switch.d.ts.map +0 -1
- package/output/components/switch.js +0 -20
- package/output/components/table.d.ts +0 -11
- package/output/components/table.d.ts.map +0 -1
- package/output/components/table.js +0 -47
- package/output/components/tabs.d.ts +0 -12
- package/output/components/tabs.d.ts.map +0 -1
- package/output/components/tabs.js +0 -45
- package/output/components/textarea.d.ts +0 -4
- package/output/components/textarea.d.ts.map +0 -1
- package/output/components/textarea.js +0 -19
- package/output/components/theme-switcher.d.ts +0 -6
- package/output/components/theme-switcher.d.ts.map +0 -1
- package/output/components/theme-switcher.js +0 -19
- package/output/components/toaster/index.d.ts +0 -16
- package/output/components/toaster/index.d.ts.map +0 -1
- package/output/components/toaster/index.js +0 -70
- package/output/components/toggle-group.d.ts +0 -12
- package/output/components/toggle-group.d.ts.map +0 -1
- package/output/components/toggle-group.js +0 -38
- package/output/components/toggle.d.ts +0 -10
- package/output/components/toggle.d.ts.map +0 -1
- package/output/components/toggle.js +0 -38
- package/output/components/tooltip.d.ts +0 -8
- package/output/components/tooltip.d.ts.map +0 -1
- package/output/components/tooltip.js +0 -33
- package/output/features/confirm-dialog/index.d.ts +0 -41
- package/output/features/confirm-dialog/index.d.ts.map +0 -1
- package/output/features/confirm-dialog/index.js +0 -19
- package/output/features/input-confirm/index.d.ts +0 -26
- package/output/features/input-confirm/index.d.ts.map +0 -1
- package/output/features/input-confirm/index.js +0 -59
- package/output/features/signin/context.d.ts +0 -14
- package/output/features/signin/context.d.ts.map +0 -1
- package/output/features/signin/context.js +0 -13
- package/output/features/signin/index.d.ts +0 -58
- package/output/features/signin/index.d.ts.map +0 -1
- package/output/features/signin/index.js +0 -137
- package/output/features/signin/service.d.ts +0 -92
- package/output/features/signin/service.d.ts.map +0 -1
- package/output/features/signin/service.js +0 -519
- package/output/features/signin/service.test.d.ts +0 -2
- package/output/features/signin/service.test.d.ts.map +0 -1
- package/output/features/signin/service.test.js +0 -211
- package/output/features/signin/types.d.ts +0 -63
- package/output/features/signin/types.d.ts.map +0 -1
- package/output/features/signin/types.js +0 -1
- package/output/hooks/use-loading/index.d.ts +0 -6
- package/output/hooks/use-loading/index.d.ts.map +0 -1
- package/output/hooks/use-loading/index.js +0 -14
- package/output/hooks/use-loading/index.test.d.ts +0 -2
- package/output/hooks/use-loading/index.test.d.ts.map +0 -1
- package/output/hooks/use-loading/index.test.js +0 -24
- package/output/hooks/use-mobile/index.d.ts +0 -2
- package/output/hooks/use-mobile/index.d.ts.map +0 -1
- package/output/hooks/use-mobile/index.js +0 -16
- package/output/hooks/use-observer/index.d.ts +0 -2
- package/output/hooks/use-observer/index.d.ts.map +0 -1
- package/output/hooks/use-observer/index.js +0 -1
- package/output/hooks/use-observer/use-observer.d.ts +0 -3
- package/output/hooks/use-observer/use-observer.d.ts.map +0 -1
- package/output/hooks/use-observer/use-observer.js +0 -16
- package/output/hooks/use-observer/use-observer.test.d.ts +0 -2
- package/output/hooks/use-observer/use-observer.test.d.ts.map +0 -1
- package/output/hooks/use-observer/use-observer.test.js +0 -134
- package/output/hooks/use-offline/index.d.ts +0 -6
- package/output/hooks/use-offline/index.d.ts.map +0 -1
- package/output/hooks/use-offline/index.js +0 -19
- package/output/layout/app/index.d.ts +0 -34
- package/output/layout/app/index.d.ts.map +0 -1
- package/output/layout/app/index.js +0 -34
- package/output/layout/dashboard/index.d.ts +0 -76
- package/output/layout/dashboard/index.d.ts.map +0 -1
- package/output/layout/dashboard/index.js +0 -84
- package/output/layout/index.d.ts +0 -3
- package/output/layout/index.d.ts.map +0 -1
- package/output/layout/index.js +0 -2
- package/output/services/cache-api/cache-api.d.ts +0 -23
- package/output/services/cache-api/cache-api.d.ts.map +0 -1
- package/output/services/cache-api/cache-api.js +0 -145
- package/output/services/cache-api/cache-api.test.d.ts +0 -2
- package/output/services/cache-api/cache-api.test.d.ts.map +0 -1
- package/output/services/cache-api/cache-api.test.js +0 -610
- package/output/services/cache-api/index.d.ts +0 -2
- package/output/services/cache-api/index.d.ts.map +0 -1
- package/output/services/cache-api/index.js +0 -1
- package/output/services/cached-fetch/index.d.ts +0 -50
- package/output/services/cached-fetch/index.d.ts.map +0 -1
- package/output/services/cached-fetch/index.js +0 -196
- package/output/services/service/index.d.ts +0 -2
- package/output/services/service/index.d.ts.map +0 -1
- package/output/services/service/index.js +0 -1
- package/output/services/service/service.d.ts +0 -135
- package/output/services/service/service.d.ts.map +0 -1
- package/output/services/service/service.js +0 -276
- package/output/services/service/service.test.d.ts +0 -2
- package/output/services/service/service.test.d.ts.map +0 -1
- package/output/services/service/service.test.js +0 -1399
- package/output/services/side-cache/index.d.ts +0 -2
- package/output/services/side-cache/index.d.ts.map +0 -1
- package/output/services/side-cache/index.js +0 -1
- package/output/services/side-cache/side-cache.d.ts +0 -11
- package/output/services/side-cache/side-cache.d.ts.map +0 -1
- package/output/services/side-cache/side-cache.js +0 -161
- package/output/services/side-cache/side-cache.test.d.ts +0 -2
- package/output/services/side-cache/side-cache.test.d.ts.map +0 -1
- package/output/services/side-cache/side-cache.test.js +0 -271
- package/output/utils/avatar/index.d.ts +0 -28
- package/output/utils/avatar/index.d.ts.map +0 -1
- package/output/utils/avatar/index.js +0 -35
- package/output/utils/delay/index.d.ts +0 -2
- package/output/utils/delay/index.d.ts.map +0 -1
- package/output/utils/delay/index.js +0 -5
- package/output/utils/form/index.d.ts +0 -3
- package/output/utils/form/index.d.ts.map +0 -1
- package/output/utils/form/index.js +0 -1
- package/output/utils/merge-class-names/index.d.ts +0 -3
- package/output/utils/merge-class-names/index.d.ts.map +0 -1
- package/output/utils/merge-class-names/index.js +0 -5
- package/output/utils/merge-class-names/index.test.d.ts +0 -2
- package/output/utils/merge-class-names/index.test.d.ts.map +0 -1
- package/output/utils/merge-class-names/index.test.js +0 -7
- package/output/utils/performance/index.d.ts +0 -82
- package/output/utils/performance/index.d.ts.map +0 -1
- package/output/utils/performance/index.js +0 -129
- package/output/utils/redirect/index.d.ts +0 -6
- package/output/utils/redirect/index.d.ts.map +0 -1
- package/output/utils/redirect/index.js +0 -32
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
-
import { SigninService } from './service.js';
|
|
3
|
-
// Mock localStorage
|
|
4
|
-
const localStorageMock = (() => {
|
|
5
|
-
let store = {};
|
|
6
|
-
return {
|
|
7
|
-
getItem: (key) => store[key] || null,
|
|
8
|
-
setItem: (key, value) => {
|
|
9
|
-
store[key] = value;
|
|
10
|
-
},
|
|
11
|
-
removeItem: (key) => {
|
|
12
|
-
delete store[key];
|
|
13
|
-
},
|
|
14
|
-
clear: () => {
|
|
15
|
-
store = {};
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
})();
|
|
19
|
-
Object.defineProperty(window, 'localStorage', {
|
|
20
|
-
value: localStorageMock,
|
|
21
|
-
writable: true
|
|
22
|
-
});
|
|
23
|
-
describe('SigninService', () => {
|
|
24
|
-
let service;
|
|
25
|
-
let mockApi;
|
|
26
|
-
const mockTicket = {
|
|
27
|
-
ticket: 'test-ticket-123',
|
|
28
|
-
signinUrl: 'https://example.com/signin',
|
|
29
|
-
expiredTime: new Date(Date.now() + 10 * 60 * 1000).toISOString() // 10 分钟后过期
|
|
30
|
-
};
|
|
31
|
-
const mockPendingCheck = {
|
|
32
|
-
status: 'Pending'
|
|
33
|
-
};
|
|
34
|
-
const mockFinishedCheck = {
|
|
35
|
-
status: 'Finished',
|
|
36
|
-
token: 'test-token-456'
|
|
37
|
-
};
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
localStorageMock.clear();
|
|
40
|
-
vi.clearAllTimers();
|
|
41
|
-
mockApi = {
|
|
42
|
-
applySignin: vi.fn().mockResolvedValue({
|
|
43
|
-
isError: () => false,
|
|
44
|
-
value: mockTicket
|
|
45
|
-
}),
|
|
46
|
-
checkStatus: vi.fn().mockResolvedValue({
|
|
47
|
-
isError: () => false,
|
|
48
|
-
value: mockPendingCheck
|
|
49
|
-
}),
|
|
50
|
-
onSuccess: vi.fn(),
|
|
51
|
-
onCancel: vi.fn()
|
|
52
|
-
};
|
|
53
|
-
service = new SigninService(mockApi, {
|
|
54
|
-
pollInterval: 100,
|
|
55
|
-
errorAutoCloseDelay: 1000,
|
|
56
|
-
successDisplayDuration: 500
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
afterEach(() => {
|
|
60
|
-
service.dispose();
|
|
61
|
-
});
|
|
62
|
-
describe('状态持久化', () => {
|
|
63
|
-
it('应该在状态变化时自动保存到 localStorage', async () => {
|
|
64
|
-
await service.init();
|
|
65
|
-
// 开始登录流程
|
|
66
|
-
await service.start();
|
|
67
|
-
// 等待状态保存 (reaction 有 100ms delay)
|
|
68
|
-
await new Promise(resolve => setTimeout(resolve, 150));
|
|
69
|
-
// 验证 localStorage 中有保存的状态
|
|
70
|
-
const saved = localStorageMock.getItem('__signin_service_state__');
|
|
71
|
-
expect(saved).toBeTruthy();
|
|
72
|
-
const state = JSON.parse(saved);
|
|
73
|
-
expect(state.ticket).toEqual(mockTicket);
|
|
74
|
-
expect(state.dialogStatus).toBe('waiting');
|
|
75
|
-
});
|
|
76
|
-
it('应该在初始化时恢复之前保存的状态', async () => {
|
|
77
|
-
// 模拟已保存的状态
|
|
78
|
-
const savedState = {
|
|
79
|
-
ticket: mockTicket,
|
|
80
|
-
dialogStatus: 'waiting',
|
|
81
|
-
errorMessage: '',
|
|
82
|
-
timestamp: Date.now()
|
|
83
|
-
};
|
|
84
|
-
localStorageMock.setItem('__signin_service_state__', JSON.stringify(savedState));
|
|
85
|
-
// 创建新的服务实例
|
|
86
|
-
const newService = new SigninService(mockApi);
|
|
87
|
-
await newService.init();
|
|
88
|
-
// 验证状态已恢复
|
|
89
|
-
expect(newService.hasActiveTicket).toBe(true);
|
|
90
|
-
expect(newService.dialogStatus).toBe('waiting');
|
|
91
|
-
expect(newService.signinUrl).toBe(mockTicket.signinUrl);
|
|
92
|
-
newService.dispose();
|
|
93
|
-
});
|
|
94
|
-
it('应该在票据过期时不恢复状态', async () => {
|
|
95
|
-
// 模拟已过期的票据
|
|
96
|
-
const expiredTicket = Object.assign(Object.assign({}, mockTicket), { expiredTime: new Date(Date.now() - 1000).toISOString() // 已过期
|
|
97
|
-
});
|
|
98
|
-
const savedState = {
|
|
99
|
-
ticket: expiredTicket,
|
|
100
|
-
dialogStatus: 'waiting',
|
|
101
|
-
errorMessage: '',
|
|
102
|
-
timestamp: Date.now()
|
|
103
|
-
};
|
|
104
|
-
localStorageMock.setItem('__signin_service_state__', JSON.stringify(savedState));
|
|
105
|
-
// 创建新的服务实例
|
|
106
|
-
const newService = new SigninService(mockApi);
|
|
107
|
-
await newService.init();
|
|
108
|
-
// 验证状态未恢复
|
|
109
|
-
expect(newService.hasActiveTicket).toBe(false);
|
|
110
|
-
expect(newService.dialogStatus).toBe('idle');
|
|
111
|
-
// 验证 localStorage 已清理
|
|
112
|
-
expect(localStorageMock.getItem('__signin_service_state__')).toBeNull();
|
|
113
|
-
newService.dispose();
|
|
114
|
-
});
|
|
115
|
-
it('应该在登录成功后清理持久化状态', async () => {
|
|
116
|
-
await service.init();
|
|
117
|
-
await service.start();
|
|
118
|
-
// 等待状态保存
|
|
119
|
-
await new Promise(resolve => setTimeout(resolve, 150));
|
|
120
|
-
expect(localStorageMock.getItem('__signin_service_state__')).toBeTruthy();
|
|
121
|
-
// 模拟登录成功
|
|
122
|
-
mockApi.checkStatus = vi.fn().mockResolvedValue({
|
|
123
|
-
isError: () => false,
|
|
124
|
-
value: mockFinishedCheck
|
|
125
|
-
});
|
|
126
|
-
// 等待轮询检测到成功状态
|
|
127
|
-
await new Promise(resolve => setTimeout(resolve, 200));
|
|
128
|
-
// 等待成功处理完成
|
|
129
|
-
await new Promise(resolve => setTimeout(resolve, 600));
|
|
130
|
-
// 验证状态已清理
|
|
131
|
-
expect(localStorageMock.getItem('__signin_service_state__')).toBeNull();
|
|
132
|
-
});
|
|
133
|
-
it('应该在取消登录后清理持久化状态', async () => {
|
|
134
|
-
await service.init();
|
|
135
|
-
await service.start();
|
|
136
|
-
// 等待状态保存
|
|
137
|
-
await new Promise(resolve => setTimeout(resolve, 150));
|
|
138
|
-
expect(localStorageMock.getItem('__signin_service_state__')).toBeTruthy();
|
|
139
|
-
// 取消登录
|
|
140
|
-
await service.cancel();
|
|
141
|
-
// 验证状态已清理
|
|
142
|
-
expect(localStorageMock.getItem('__signin_service_state__')).toBeNull();
|
|
143
|
-
expect(service.dialogStatus).toBe('idle');
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
describe('页面刷新场景', () => {
|
|
147
|
-
it('应该在页面刷新后继续轮询检查登录状态', async () => {
|
|
148
|
-
// 第一次会话:开始登录
|
|
149
|
-
await service.init();
|
|
150
|
-
await service.start();
|
|
151
|
-
// 等待状态保存
|
|
152
|
-
await new Promise(resolve => setTimeout(resolve, 150));
|
|
153
|
-
// 模拟页面刷新 - 保存 localStorage(浏览器刷新时不会调用 dispose,但会保留 localStorage)
|
|
154
|
-
const savedData = localStorageMock.getItem('__signin_service_state__');
|
|
155
|
-
service.dispose();
|
|
156
|
-
localStorageMock.setItem('__signin_service_state__', savedData);
|
|
157
|
-
// 创建新服务实例(模拟页面重新加载)
|
|
158
|
-
const newService = new SigninService(mockApi, {
|
|
159
|
-
pollInterval: 100,
|
|
160
|
-
errorAutoCloseDelay: 1000,
|
|
161
|
-
successDisplayDuration: 500
|
|
162
|
-
});
|
|
163
|
-
await newService.init();
|
|
164
|
-
// 验证状态已恢复且开始轮询
|
|
165
|
-
expect(newService.dialogStatus).toBe('waiting');
|
|
166
|
-
expect(newService.hasActiveTicket).toBe(true);
|
|
167
|
-
// 验证轮询正在进行
|
|
168
|
-
expect(mockApi.checkStatus).toHaveBeenCalled();
|
|
169
|
-
newService.dispose();
|
|
170
|
-
});
|
|
171
|
-
it('应该在页面刷新后显示登录弹窗', async () => {
|
|
172
|
-
// 第一次会话:开始登录
|
|
173
|
-
await service.init();
|
|
174
|
-
await service.start();
|
|
175
|
-
// 等待状态保存
|
|
176
|
-
await new Promise(resolve => setTimeout(resolve, 150));
|
|
177
|
-
expect(service.isDialogOpen).toBe(true);
|
|
178
|
-
// 模拟页面刷新 - 保存 localStorage(浏览器刷新时不会调用 dispose,但会保留 localStorage)
|
|
179
|
-
const savedData = localStorageMock.getItem('__signin_service_state__');
|
|
180
|
-
service.dispose();
|
|
181
|
-
localStorageMock.setItem('__signin_service_state__', savedData);
|
|
182
|
-
// 创建新服务实例
|
|
183
|
-
const newService = new SigninService(mockApi);
|
|
184
|
-
await newService.init();
|
|
185
|
-
// 验证弹窗仍然显示
|
|
186
|
-
expect(newService.isDialogOpen).toBe(true);
|
|
187
|
-
expect(newService.dialogStatus).toBe('waiting');
|
|
188
|
-
newService.dispose();
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
describe('错误处理', () => {
|
|
192
|
-
it('应该处理 localStorage 损坏的数据', async () => {
|
|
193
|
-
// 保存无效的 JSON
|
|
194
|
-
localStorageMock.setItem('__signin_service_state__', 'invalid json');
|
|
195
|
-
const newService = new SigninService(mockApi);
|
|
196
|
-
await newService.init();
|
|
197
|
-
// 应该优雅处理并从 idle 状态开始
|
|
198
|
-
expect(newService.dialogStatus).toBe('idle');
|
|
199
|
-
expect(newService.hasActiveTicket).toBe(false);
|
|
200
|
-
newService.dispose();
|
|
201
|
-
});
|
|
202
|
-
it('应该在恢复状态失败时清理 localStorage', async () => {
|
|
203
|
-
localStorageMock.setItem('__signin_service_state__', 'invalid json');
|
|
204
|
-
const newService = new SigninService(mockApi);
|
|
205
|
-
await newService.init();
|
|
206
|
-
// 验证已清理
|
|
207
|
-
expect(localStorageMock.getItem('__signin_service_state__')).toBeNull();
|
|
208
|
-
newService.dispose();
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { CatchResult } from '@taicode/common-base';
|
|
2
|
-
/**
|
|
3
|
-
* 登录状态
|
|
4
|
-
*/
|
|
5
|
-
export type SigninStatus = 'Pending' | 'Finished' | 'Expired' | 'Cancelled';
|
|
6
|
-
/**
|
|
7
|
-
* 登录票据信息
|
|
8
|
-
*/
|
|
9
|
-
export interface ApplySigninResult {
|
|
10
|
-
/** 票据 ID */
|
|
11
|
-
ticket: string;
|
|
12
|
-
/** 登录页 URL */
|
|
13
|
-
signinUrl: string;
|
|
14
|
-
/** 过期时间 */
|
|
15
|
-
expiredTime: string | Date;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 登录状态检查结果
|
|
19
|
-
*/
|
|
20
|
-
export interface CheckStatusResult {
|
|
21
|
-
/** 当前状态 */
|
|
22
|
-
status: SigninStatus;
|
|
23
|
-
/** 认证成功后的令牌(仅在 status 为 Finished 时存在) */
|
|
24
|
-
token?: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* API 错误类型
|
|
28
|
-
*/
|
|
29
|
-
export interface SigninApiError {
|
|
30
|
-
/** 错误消息 */
|
|
31
|
-
message: string;
|
|
32
|
-
/** 错误代码(可选) */
|
|
33
|
-
code?: string;
|
|
34
|
-
/** 原始错误(可选) */
|
|
35
|
-
cause?: unknown;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 登录 API 配置
|
|
39
|
-
* 应用需要实现这些方法来适配自己的认证系统
|
|
40
|
-
*/
|
|
41
|
-
export interface SigninApi {
|
|
42
|
-
/**
|
|
43
|
-
* 用户取消登录时的回调
|
|
44
|
-
*/
|
|
45
|
-
onCancel?: () => Promise<void> | void;
|
|
46
|
-
/**
|
|
47
|
-
* 认证成功后的回调
|
|
48
|
-
* @param token 认证令牌
|
|
49
|
-
*/
|
|
50
|
-
onSuccess?: (token: string) => Promise<void> | void;
|
|
51
|
-
/**
|
|
52
|
-
* 申请跨域认证票据
|
|
53
|
-
* @returns 返回票据信息或错误
|
|
54
|
-
*/
|
|
55
|
-
applySignin: () => Promise<CatchResult<ApplySigninResult, SigninApiError>>;
|
|
56
|
-
/**
|
|
57
|
-
* 检查票据状态
|
|
58
|
-
* @param ticket 票据 ID
|
|
59
|
-
* @returns 返回票据状态信息或错误
|
|
60
|
-
*/
|
|
61
|
-
checkStatus: (ticket: string) => Promise<CatchResult<CheckStatusResult, SigninApiError>>;
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../source/features/signin/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAA;AAE3E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,YAAY;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,cAAc;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,WAAW;IACX,MAAM,EAAE,YAAY,CAAA;IACpB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW;IACX,OAAO,EAAE,MAAM,CAAA;IACf,eAAe;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,eAAe;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB;;KAEC;IACD,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAErC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAEnD;;;OAGG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAA;IAE1E;;;;OAIG;IACH,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAA;CACzF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/hooks/use-loading/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,YAAY,UAAQ;;;kBAGN,CAAC,aAAc,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAAC;EAUpF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react';
|
|
2
|
-
export function useLoading(initialState = false) {
|
|
3
|
-
const [loading, setLoading] = useState(initialState);
|
|
4
|
-
const withLoading = useCallback(async (operation) => {
|
|
5
|
-
setLoading(true);
|
|
6
|
-
try {
|
|
7
|
-
return await operation();
|
|
8
|
-
}
|
|
9
|
-
finally {
|
|
10
|
-
setLoading(false);
|
|
11
|
-
}
|
|
12
|
-
}, []);
|
|
13
|
-
return { loading, setLoading, withLoading };
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../source/hooks/use-loading/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { renderHook, act } from '@testing-library/react';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import { useLoading } from './index.js';
|
|
5
|
-
describe('useLoading', () => {
|
|
6
|
-
it('tracks an async operation until it settles', async () => {
|
|
7
|
-
let resolveOperation;
|
|
8
|
-
const operation = new Promise((resolve) => {
|
|
9
|
-
resolveOperation = resolve;
|
|
10
|
-
});
|
|
11
|
-
const { result } = renderHook(() => useLoading());
|
|
12
|
-
let pendingResult;
|
|
13
|
-
act(() => {
|
|
14
|
-
pendingResult = result.current.withLoading(() => operation);
|
|
15
|
-
});
|
|
16
|
-
expect(result.current.loading).toBe(true);
|
|
17
|
-
await act(async () => {
|
|
18
|
-
resolveOperation('done');
|
|
19
|
-
await pendingResult;
|
|
20
|
-
});
|
|
21
|
-
expect(result.current.loading).toBe(false);
|
|
22
|
-
await expect(pendingResult).resolves.toBe('done');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/hooks/use-mobile/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,YAgB1B"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from 'react';
|
|
2
|
-
const MOBILE_BREAKPOINT = 768;
|
|
3
|
-
export function useIsMobile() {
|
|
4
|
-
const subscribe = (callback) => {
|
|
5
|
-
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
6
|
-
mql.addEventListener('change', callback);
|
|
7
|
-
return () => mql.removeEventListener('change', callback);
|
|
8
|
-
};
|
|
9
|
-
const getSnapshot = () => {
|
|
10
|
-
return window.innerWidth < MOBILE_BREAKPOINT;
|
|
11
|
-
};
|
|
12
|
-
const getServerSnapshot = () => {
|
|
13
|
-
return false;
|
|
14
|
-
};
|
|
15
|
-
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/hooks/use-observer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useObserver } from './use-observer.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-observer.d.ts","sourceRoot":"","sources":["../../../source/hooks/use-observer/use-observer.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAA;AAClD,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { reaction } from 'mobx';
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
3
|
-
export function useObserver(initialValue, selector) {
|
|
4
|
-
const [, refresh] = useState({});
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
if (initialValue == null)
|
|
7
|
-
return;
|
|
8
|
-
if (selector == null)
|
|
9
|
-
return;
|
|
10
|
-
return reaction(() => selector(initialValue), () => refresh({}));
|
|
11
|
-
}, [selector, initialValue]);
|
|
12
|
-
if (selector == null) {
|
|
13
|
-
return initialValue;
|
|
14
|
-
}
|
|
15
|
-
return selector(initialValue);
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-observer.test.d.ts","sourceRoot":"","sources":["../../../source/hooks/use-observer/use-observer.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { renderHook, act } from '@testing-library/react';
|
|
3
|
-
import { observable, action } from 'mobx';
|
|
4
|
-
import { useObserver } from './use-observer.js';
|
|
5
|
-
describe('useObserver', () => {
|
|
6
|
-
it('应该返回初始值当没有selector时', () => {
|
|
7
|
-
const initialValue = '初始值';
|
|
8
|
-
const { result } = renderHook(() => useObserver(initialValue));
|
|
9
|
-
expect(result.current).toBe(initialValue);
|
|
10
|
-
});
|
|
11
|
-
it('应该使用selector转换值', () => {
|
|
12
|
-
const initialValue = { count: 5 };
|
|
13
|
-
const selector = (value) => value.count * 2;
|
|
14
|
-
const { result } = renderHook(() => useObserver(initialValue, selector));
|
|
15
|
-
expect(result.current).toBe(10);
|
|
16
|
-
});
|
|
17
|
-
it('应该在观察对象变化时重新渲染', async () => {
|
|
18
|
-
const observableStore = observable({
|
|
19
|
-
count: 0,
|
|
20
|
-
increment: action(() => {
|
|
21
|
-
observableStore.count++;
|
|
22
|
-
})
|
|
23
|
-
});
|
|
24
|
-
const { result } = renderHook(() => useObserver(observableStore, (store) => store.count));
|
|
25
|
-
expect(result.current).toBe(0);
|
|
26
|
-
// 改变observable的值
|
|
27
|
-
act(() => {
|
|
28
|
-
observableStore.increment();
|
|
29
|
-
});
|
|
30
|
-
// 等待React更新
|
|
31
|
-
await new Promise(resolve => setTimeout(resolve, 0));
|
|
32
|
-
expect(result.current).toBe(1);
|
|
33
|
-
});
|
|
34
|
-
it('应该处理复杂的selector函数', () => {
|
|
35
|
-
const store = observable({
|
|
36
|
-
users: [
|
|
37
|
-
{ id: 1, name: '张三', active: true },
|
|
38
|
-
{ id: 2, name: '李四', active: false },
|
|
39
|
-
{ id: 3, name: '王五', active: true }
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
const selector = (store) => store.users.filter((user) => user.active).map((user) => user.name);
|
|
43
|
-
const { result } = renderHook(() => useObserver(store, selector));
|
|
44
|
-
expect(result.current).toEqual(['张三', '王五']);
|
|
45
|
-
});
|
|
46
|
-
it('应该在observable数组变化时重新渲染', async () => {
|
|
47
|
-
const store = observable({
|
|
48
|
-
items: ['项目1', '项目2'],
|
|
49
|
-
addItem: action((item) => {
|
|
50
|
-
store.items.push(item);
|
|
51
|
-
})
|
|
52
|
-
});
|
|
53
|
-
const { result } = renderHook(() => useObserver(store, (store) => store.items.length));
|
|
54
|
-
expect(result.current).toBe(2);
|
|
55
|
-
act(() => {
|
|
56
|
-
store.addItem('项目3');
|
|
57
|
-
});
|
|
58
|
-
await new Promise(resolve => setTimeout(resolve, 0));
|
|
59
|
-
expect(result.current).toBe(3);
|
|
60
|
-
});
|
|
61
|
-
it('应该处理null值的初始值', () => {
|
|
62
|
-
const { result } = renderHook(() => useObserver(null));
|
|
63
|
-
expect(result.current).toBeNull();
|
|
64
|
-
});
|
|
65
|
-
it('应该处理undefined值的初始值', () => {
|
|
66
|
-
const { result } = renderHook(() => useObserver(undefined));
|
|
67
|
-
expect(result.current).toBeUndefined();
|
|
68
|
-
});
|
|
69
|
-
it('应该在selector为null时返回原值', () => {
|
|
70
|
-
const initialValue = { data: '测试数据' };
|
|
71
|
-
const { result } = renderHook(() => useObserver(initialValue, null));
|
|
72
|
-
expect(result.current).toBe(initialValue);
|
|
73
|
-
});
|
|
74
|
-
it('应该处理嵌套observable对象', async () => {
|
|
75
|
-
const store = observable({
|
|
76
|
-
user: {
|
|
77
|
-
profile: {
|
|
78
|
-
name: '测试用户',
|
|
79
|
-
email: 'test@example.com'
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
updateName: action((name) => {
|
|
83
|
-
store.user.profile.name = name;
|
|
84
|
-
})
|
|
85
|
-
});
|
|
86
|
-
const { result } = renderHook(() => useObserver(store, (store) => store.user.profile.name));
|
|
87
|
-
expect(result.current).toBe('测试用户');
|
|
88
|
-
act(() => {
|
|
89
|
-
store.updateName('新用户名');
|
|
90
|
-
});
|
|
91
|
-
await new Promise(resolve => setTimeout(resolve, 0));
|
|
92
|
-
expect(result.current).toBe('新用户名');
|
|
93
|
-
});
|
|
94
|
-
it('应该处理多个observable属性的变化', async () => {
|
|
95
|
-
const store = observable({
|
|
96
|
-
firstName: '张',
|
|
97
|
-
lastName: '三',
|
|
98
|
-
updateFirstName: action((name) => {
|
|
99
|
-
store.firstName = name;
|
|
100
|
-
}),
|
|
101
|
-
updateLastName: action((name) => {
|
|
102
|
-
store.lastName = name;
|
|
103
|
-
})
|
|
104
|
-
});
|
|
105
|
-
const { result } = renderHook(() => useObserver(store, (store) => `${store.firstName}${store.lastName}`));
|
|
106
|
-
expect(result.current).toBe('张三');
|
|
107
|
-
act(() => {
|
|
108
|
-
store.updateFirstName('李');
|
|
109
|
-
});
|
|
110
|
-
await new Promise(resolve => setTimeout(resolve, 0));
|
|
111
|
-
expect(result.current).toBe('李三');
|
|
112
|
-
act(() => {
|
|
113
|
-
store.updateLastName('四');
|
|
114
|
-
});
|
|
115
|
-
await new Promise(resolve => setTimeout(resolve, 0));
|
|
116
|
-
expect(result.current).toBe('李四');
|
|
117
|
-
});
|
|
118
|
-
it('应该在组件卸载时清理reaction', () => {
|
|
119
|
-
const store = observable({ count: 0 });
|
|
120
|
-
const { unmount } = renderHook(() => useObserver(store, (store) => store.count));
|
|
121
|
-
// 卸载组件应该不会抛出错误
|
|
122
|
-
expect(() => unmount()).not.toThrow();
|
|
123
|
-
});
|
|
124
|
-
it('应该处理boolean类型的返回值', () => {
|
|
125
|
-
const store = observable({ isActive: true });
|
|
126
|
-
const { result } = renderHook(() => useObserver(store, (store) => store.isActive));
|
|
127
|
-
expect(result.current).toBe(true);
|
|
128
|
-
});
|
|
129
|
-
it('应该处理数字类型的返回值', () => {
|
|
130
|
-
const store = observable({ count: 42 });
|
|
131
|
-
const { result } = renderHook(() => useObserver(store, (store) => store.count));
|
|
132
|
-
expect(result.current).toBe(42);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/hooks/use-offline/index.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAiBpC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook to detect offline status
|
|
4
|
-
* @returns {boolean} Whether the app is offline
|
|
5
|
-
*/
|
|
6
|
-
export function useOffline() {
|
|
7
|
-
const [isOffline, setIsOffline] = useState(!navigator.onLine);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
const handleOnline = () => setIsOffline(false);
|
|
10
|
-
const handleOffline = () => setIsOffline(true);
|
|
11
|
-
window.addEventListener('online', handleOnline);
|
|
12
|
-
window.addEventListener('offline', handleOffline);
|
|
13
|
-
return () => {
|
|
14
|
-
window.removeEventListener('online', handleOnline);
|
|
15
|
-
window.removeEventListener('offline', handleOffline);
|
|
16
|
-
};
|
|
17
|
-
}, []);
|
|
18
|
-
return isOffline;
|
|
19
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
export interface AppLayoutProps {
|
|
3
|
-
header?: ReactNode;
|
|
4
|
-
footer?: ReactNode;
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
mobileNavigation?: ReactNode;
|
|
7
|
-
contentClassName?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function AppLayout(props: AppLayoutProps): import("react").JSX.Element;
|
|
10
|
-
export interface AppNavigationProps {
|
|
11
|
-
variant?: 'standard' | 'floating';
|
|
12
|
-
brand?: ReactNode;
|
|
13
|
-
navigation?: ReactNode;
|
|
14
|
-
actions?: ReactNode;
|
|
15
|
-
mobileBrand?: ReactNode;
|
|
16
|
-
mobileActions?: ReactNode;
|
|
17
|
-
}
|
|
18
|
-
export declare function AppNavigation(props: AppNavigationProps): import("react").JSX.Element;
|
|
19
|
-
export interface AppMobileNavigationProps {
|
|
20
|
-
label: string;
|
|
21
|
-
children: ReactNode;
|
|
22
|
-
className?: string;
|
|
23
|
-
}
|
|
24
|
-
export declare function AppMobileNavigation(props: AppMobileNavigationProps): import("react").JSX.Element;
|
|
25
|
-
export interface AppContentProps {
|
|
26
|
-
title?: ReactNode;
|
|
27
|
-
description?: ReactNode;
|
|
28
|
-
back?: ReactNode;
|
|
29
|
-
toolbar?: ReactNode;
|
|
30
|
-
children: ReactNode;
|
|
31
|
-
className?: string;
|
|
32
|
-
}
|
|
33
|
-
export declare function AppContent(props: AppContentProps): import("react").JSX.Element;
|
|
34
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/layout/app/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;IACnB,gBAAgB,CAAC,EAAE,SAAS,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,+BAW9C;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,CAAA;IACjC,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,UAAU,CAAC,EAAE,SAAS,CAAA;IACtB,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,aAAa,CAAC,EAAE,SAAS,CAAA;CAC1B;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BA4DtD;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,+BAalE;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BAoBhD"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
import { mergeClassNames } from '../../utils/merge-class-names/index.js';
|
|
4
|
-
export function AppLayout(props) {
|
|
5
|
-
const { header, footer, mobileNavigation, children, contentClassName } = props;
|
|
6
|
-
return (_jsxs("div", { className: "flex min-h-dvh min-w-0 flex-col bg-background", children: [header, _jsx("main", { className: mergeClassNames('min-w-0 flex-1', contentClassName), children: children }), footer && _jsx("div", { className: "border-t border-border bg-transparent", children: footer }), mobileNavigation] }));
|
|
7
|
-
}
|
|
8
|
-
export function AppNavigation(props) {
|
|
9
|
-
const { variant = 'standard', brand, navigation, actions, mobileBrand = brand, mobileActions = actions, } = props;
|
|
10
|
-
const [isScrolled, setIsScrolled] = useState(false);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (variant !== 'floating')
|
|
13
|
-
return;
|
|
14
|
-
const handleScroll = () => setIsScrolled(window.scrollY > 20);
|
|
15
|
-
handleScroll();
|
|
16
|
-
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
17
|
-
return () => window.removeEventListener('scroll', handleScroll);
|
|
18
|
-
}, [variant]);
|
|
19
|
-
return (_jsx("header", { className: mergeClassNames('sticky top-0 z-50 transition-all duration-300', variant === 'standard' ? 'border-b border-border/70 bg-background/90 backdrop-blur-xl' : 'py-3 md:py-4'), children: _jsxs("div", { className: mergeClassNames('w-full px-4 sm:px-6 lg:px-8', variant === 'standard' && 'mx-auto max-w-6xl'), children: [_jsxs("nav", { "aria-label": "Global", className: mergeClassNames('hidden items-center justify-between gap-5 transition-all duration-300 lg:flex', variant === 'standard'
|
|
20
|
-
? 'h-16'
|
|
21
|
-
: mergeClassNames('rounded-full border px-6 py-3 shadow-sm backdrop-blur', isScrolled
|
|
22
|
-
? 'border-border/10 bg-background/60 shadow-xl backdrop-blur-2xl'
|
|
23
|
-
: 'border-border/70 bg-background/80')), children: [_jsx("div", { className: "flex h-8 items-center gap-1 lg:flex-1", children: brand }), navigation, _jsx("div", { className: "hidden lg:flex lg:flex-1 lg:items-center lg:justify-end lg:gap-3", children: actions })] }), _jsxs("div", { className: mergeClassNames('flex items-center justify-between gap-4 lg:hidden', variant === 'standard'
|
|
24
|
-
? 'h-14'
|
|
25
|
-
: 'rounded-full border border-border bg-background/80 px-4 py-3 shadow-sm backdrop-blur'), children: [mobileBrand, _jsx("div", { className: "ml-auto flex items-center gap-1", children: mobileActions })] })] }) }));
|
|
26
|
-
}
|
|
27
|
-
export function AppMobileNavigation(props) {
|
|
28
|
-
const { label, children, className } = props;
|
|
29
|
-
return (_jsx("nav", { className: "fixed inset-x-0 bottom-0 z-50 border-t border-border/70 bg-background/90 backdrop-blur-xl lg:hidden", "aria-label": label, children: _jsx("div", { className: mergeClassNames('mx-auto grid max-w-lg grid-cols-4 px-2 pb-[max(0.375rem,env(safe-area-inset-bottom))] pt-1.5', className), children: children }) }));
|
|
30
|
-
}
|
|
31
|
-
export function AppContent(props) {
|
|
32
|
-
const { title, description, back, toolbar, children, className } = props;
|
|
33
|
-
return (_jsxs("div", { className: mergeClassNames('mx-auto w-full max-w-6xl min-w-0 px-4 py-6 sm:px-6 md:py-10 lg:px-8', className), children: [(back || title || description || toolbar) && (_jsxs("div", { className: "mb-8 space-y-3 border-b pb-5", children: [back, _jsxs("div", { className: "flex min-w-0 items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [title && _jsx("h1", { className: "text-2xl font-semibold md:text-3xl", children: title }), description && _jsx("p", { className: "mt-1 text-sm text-muted-foreground md:text-base", children: description })] }), toolbar && _jsx("div", { className: "flex min-h-9 shrink-0 items-center gap-2", children: toolbar })] })] })), children] }));
|
|
34
|
-
}
|