@ploykit/ui 0.0.0-stage → 0.1.1
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/README.md +40 -2
- package/dist/components/ConfirmDialog.d.ts +13 -0
- package/dist/components/ConfirmDialog.js +29 -0
- package/dist/components/CronInput.d.ts +15 -0
- package/dist/components/CronInput.js +112 -0
- package/dist/components/DataTable.d.ts +22 -0
- package/dist/components/DataTable.js +13 -0
- package/dist/components/ErrorBoundary.d.ts +16 -0
- package/dist/components/ErrorBoundary.js +24 -0
- package/dist/components/FormField.d.ts +10 -0
- package/dist/components/FormField.js +22 -0
- package/dist/components/ImpersonationBanner.d.ts +3 -0
- package/dist/components/ImpersonationBanner.js +10 -0
- package/dist/components/NotificationBell.d.ts +3 -0
- package/dist/components/NotificationBell.js +47 -0
- package/dist/components/OnboardingChecklist.d.ts +12 -0
- package/dist/components/OnboardingChecklist.js +43 -0
- package/dist/components/Page.d.ts +17 -0
- package/dist/components/Page.js +16 -0
- package/dist/components/SecretModal.d.ts +16 -0
- package/dist/components/SecretModal.js +45 -0
- package/dist/components/SettingsCard.d.ts +10 -0
- package/dist/components/SettingsCard.js +6 -0
- package/dist/components/SiteBanner.d.ts +6 -0
- package/dist/components/SiteBanner.js +11 -0
- package/dist/components/SiteBannerLayer.d.ts +4 -0
- package/dist/components/SiteBannerLayer.js +9 -0
- package/dist/components/UserMenu.d.ts +13 -0
- package/dist/components/UserMenu.js +30 -0
- package/dist/components/WorkspaceSwitcher.d.ts +1 -0
- package/dist/components/WorkspaceSwitcher.js +53 -0
- package/dist/components/toast.d.ts +7 -0
- package/dist/components/toast.js +11 -0
- package/dist/components/ui/Badge.d.ts +13 -0
- package/dist/components/ui/Badge.js +21 -0
- package/dist/components/ui/Button.d.ts +10 -0
- package/dist/components/ui/Button.js +33 -0
- package/dist/components/ui/Input.d.ts +3 -0
- package/dist/components/ui/Input.js +10 -0
- package/dist/components/ui/alert-dialog.d.ts +18 -0
- package/dist/components/ui/alert-dialog.js +41 -0
- package/dist/components/ui/avatar.d.ts +11 -0
- package/dist/components/ui/avatar.js +22 -0
- package/dist/components/ui/breadcrumb.d.ts +10 -0
- package/dist/components/ui/breadcrumb.js +36 -0
- package/dist/components/ui/card.d.ts +13 -0
- package/dist/components/ui/card.js +24 -0
- package/dist/components/ui/checkbox.d.ts +3 -0
- package/dist/components/ui/checkbox.js +8 -0
- package/dist/components/ui/dialog.d.ts +15 -0
- package/dist/components/ui/dialog.js +26 -0
- package/dist/components/ui/empty.d.ts +13 -0
- package/dist/components/ui/empty.js +36 -0
- package/dist/components/ui/field.d.ts +24 -0
- package/dist/components/ui/field.js +67 -0
- package/dist/components/ui/label.d.ts +3 -0
- package/dist/components/ui/label.js +6 -0
- package/dist/components/ui/menu.d.ts +29 -0
- package/dist/components/ui/menu.js +50 -0
- package/dist/components/ui/popover.d.ts +9 -0
- package/dist/components/ui/popover.js +22 -0
- package/dist/components/ui/progress.d.ts +7 -0
- package/dist/components/ui/progress.js +19 -0
- package/dist/components/ui/select.d.ts +15 -0
- package/dist/components/ui/select.js +33 -0
- package/dist/components/ui/separator.d.ts +3 -0
- package/dist/components/ui/separator.js +7 -0
- package/dist/components/ui/sheet.d.ts +14 -0
- package/dist/components/ui/sheet.js +36 -0
- package/dist/components/ui/sidebar.d.ts +63 -0
- package/dist/components/ui/sidebar.js +265 -0
- package/dist/components/ui/skeleton.d.ts +3 -0
- package/dist/components/ui/skeleton.js +6 -0
- package/dist/components/ui/switch.d.ts +5 -0
- package/dist/components/ui/switch.js +7 -0
- package/dist/components/ui/tabs.d.ts +10 -0
- package/dist/components/ui/tabs.js +28 -0
- package/dist/components/ui/tooltip.d.ts +6 -0
- package/dist/components/ui/tooltip.js +16 -0
- package/dist/hooks/use-mobile.d.ts +1 -0
- package/dist/hooks/use-mobile.js +15 -0
- package/dist/hooks/useApi.d.ts +10 -0
- package/dist/hooks/useApi.js +11 -0
- package/dist/hooks/useAudit.d.ts +39 -0
- package/dist/hooks/useAudit.js +55 -0
- package/dist/hooks/useAuth.d.ts +1 -0
- package/dist/hooks/useAuth.js +4 -0
- package/dist/hooks/useBilling.d.ts +44 -0
- package/dist/hooks/useBilling.js +64 -0
- package/dist/hooks/useLogin.d.ts +10 -0
- package/dist/hooks/useLogin.js +39 -0
- package/dist/hooks/useMembers.d.ts +125 -0
- package/dist/hooks/useMembers.js +127 -0
- package/dist/hooks/useNotificationPrefs.d.ts +20 -0
- package/dist/hooks/useNotificationPrefs.js +42 -0
- package/dist/hooks/usePasswordReset.d.ts +5 -0
- package/dist/hooks/usePasswordReset.js +12 -0
- package/dist/hooks/useSEO.d.ts +6 -0
- package/dist/hooks/useSEO.js +14 -0
- package/dist/hooks/useSessions.d.ts +20 -0
- package/dist/hooks/useSessions.js +38 -0
- package/dist/hooks/useSiteConfig.d.ts +12 -0
- package/dist/hooks/useSiteConfig.js +11 -0
- package/dist/hooks/useTokens.d.ts +36 -0
- package/dist/hooks/useTokens.js +35 -0
- package/dist/hooks/useUsage.d.ts +20 -0
- package/dist/hooks/useUsage.js +21 -0
- package/dist/hooks/useWorkspace.d.ts +26 -0
- package/dist/hooks/useWorkspace.js +32 -0
- package/dist/hooks/useZodForm.d.ts +6 -0
- package/dist/hooks/useZodForm.js +6 -0
- package/dist/hooks/ws.d.ts +4 -0
- package/dist/hooks/ws.js +21 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +94 -0
- package/dist/layouts/AppShell.d.ts +20 -0
- package/dist/layouts/AppShell.js +21 -0
- package/dist/layouts/AuthShell.d.ts +7 -0
- package/dist/layouts/AuthShell.js +4 -0
- package/dist/layouts/SettingsShell.d.ts +19 -0
- package/dist/layouts/SettingsShell.js +21 -0
- package/dist/lib/api-error.d.ts +1 -0
- package/dist/lib/api-error.js +74 -0
- package/dist/lib/perm.d.ts +2 -0
- package/dist/lib/perm.js +7 -0
- package/dist/lib/utils.d.ts +12 -0
- package/dist/lib/utils.js +84 -0
- package/dist/lib/ws-query-bridge.d.ts +7 -0
- package/dist/lib/ws-query-bridge.js +35 -0
- package/dist/pages/LandingPage.d.ts +22 -0
- package/dist/pages/LandingPage.js +5 -0
- package/dist/pages/LoginPage.d.ts +15 -0
- package/dist/pages/LoginPage.js +87 -0
- package/dist/pages/account/NotificationPreferencesPage.d.ts +13 -0
- package/dist/pages/account/NotificationPreferencesPage.js +41 -0
- package/dist/pages/account/ProfileSettingsPage.d.ts +4 -0
- package/dist/pages/account/ProfileSettingsPage.js +96 -0
- package/dist/pages/account/SecuritySettingsPage.d.ts +1 -0
- package/dist/pages/account/SecuritySettingsPage.js +134 -0
- package/dist/pages/account/TokensPage.d.ts +1 -0
- package/dist/pages/account/TokensPage.js +117 -0
- package/dist/pages/admin/AdminSettingsPage.d.ts +1 -0
- package/dist/pages/admin/AdminSettingsPage.js +210 -0
- package/dist/pages/admin/AdminShell.d.ts +7 -0
- package/dist/pages/admin/AdminShell.js +79 -0
- package/dist/pages/admin/AuditPage.d.ts +1 -0
- package/dist/pages/admin/AuditPage.js +164 -0
- package/dist/pages/admin/OrdersPage.d.ts +1 -0
- package/dist/pages/admin/OrdersPage.js +236 -0
- package/dist/pages/admin/OverviewPage.d.ts +1 -0
- package/dist/pages/admin/OverviewPage.js +200 -0
- package/dist/pages/admin/SSOPage.d.ts +1 -0
- package/dist/pages/admin/SSOPage.js +53 -0
- package/dist/pages/admin/UserDetailPage.d.ts +1 -0
- package/dist/pages/admin/UserDetailPage.js +266 -0
- package/dist/pages/admin/UsersPage.d.ts +4 -0
- package/dist/pages/admin/UsersPage.js +201 -0
- package/dist/pages/admin/WebhookDeliveriesPage.d.ts +1 -0
- package/dist/pages/admin/WebhookDeliveriesPage.js +128 -0
- package/dist/pages/admin/WorkspaceDetailPage.d.ts +1 -0
- package/dist/pages/admin/WorkspaceDetailPage.js +202 -0
- package/dist/pages/admin/WorkspacesPage.d.ts +1 -0
- package/dist/pages/admin/WorkspacesPage.js +133 -0
- package/dist/pages/admin/shared.d.ts +8 -0
- package/dist/pages/admin/shared.js +23 -0
- package/dist/pages/auth/ForgotPasswordPage.d.ts +6 -0
- package/dist/pages/auth/ForgotPasswordPage.js +32 -0
- package/dist/pages/auth/InviteAcceptPage.d.ts +5 -0
- package/dist/pages/auth/InviteAcceptPage.js +40 -0
- package/dist/pages/auth/RegisterPage.d.ts +15 -0
- package/dist/pages/auth/RegisterPage.js +80 -0
- package/dist/pages/auth/ResetPasswordPage.d.ts +4 -0
- package/dist/pages/auth/ResetPasswordPage.js +71 -0
- package/dist/pages/auth/VerifyEmailPage.d.ts +1 -0
- package/dist/pages/auth/VerifyEmailPage.js +45 -0
- package/dist/pages/workspace/BillingPage.d.ts +4 -0
- package/dist/pages/workspace/BillingPage.js +183 -0
- package/dist/pages/workspace/BillingSuccessPage.d.ts +4 -0
- package/dist/pages/workspace/BillingSuccessPage.js +72 -0
- package/dist/pages/workspace/MembersPage.d.ts +3 -0
- package/dist/pages/workspace/MembersPage.js +262 -0
- package/dist/pages/workspace/SchedulesPage.d.ts +4 -0
- package/dist/pages/workspace/SchedulesPage.js +177 -0
- package/dist/pages/workspace/UsagePage.d.ts +15 -0
- package/dist/pages/workspace/UsagePage.js +74 -0
- package/dist/pages/workspace/WebhooksPage.d.ts +3 -0
- package/dist/pages/workspace/WebhooksPage.js +242 -0
- package/dist/pages/workspace/WorkspaceAuditPage.d.ts +3 -0
- package/dist/pages/workspace/WorkspaceAuditPage.js +109 -0
- package/dist/pages/workspace/WorkspaceGeneralPage.d.ts +4 -0
- package/dist/pages/workspace/WorkspaceGeneralPage.js +101 -0
- package/dist/provider/PloykitProvider.d.ts +50 -0
- package/dist/provider/PloykitProvider.js +240 -0
- package/dist/realtime.d.ts +3 -0
- package/dist/realtime.js +11 -0
- package/package.json +61 -4
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { QueryClient, QueryClientProvider, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { api, ApiError, setWorkspaceIdProvider } from '@ploykit/client';
|
|
5
|
+
export const queryKeys = {
|
|
6
|
+
auth: ['auth'],
|
|
7
|
+
me: ['auth', 'me'],
|
|
8
|
+
sessions: ['auth', 'sessions'],
|
|
9
|
+
tokens: ['auth', 'tokens'],
|
|
10
|
+
workspace: ['workspace'],
|
|
11
|
+
workspaceList: ['workspace', 'list'],
|
|
12
|
+
members: (wsId) => ['workspace', wsId, 'members'],
|
|
13
|
+
invitations: (wsId) => ['workspace', wsId, 'invitations'],
|
|
14
|
+
shareLinks: (wsId) => ['workspace', wsId, 'share-links'],
|
|
15
|
+
myInvitations: ['workspace', 'my-invitations'],
|
|
16
|
+
audit: (wsId, q) => ['audit', wsId, q],
|
|
17
|
+
usage: (wsId) => ['usage', wsId],
|
|
18
|
+
billing: ['billing'],
|
|
19
|
+
billingSubscription: (workspaceId) => ['billing', 'subscription', workspaceId],
|
|
20
|
+
billingPlans: ['billing', 'plans'],
|
|
21
|
+
notifications: ['notifications'], // 元组:可作前缀失效(原为裸字符串)
|
|
22
|
+
notificationPrefs: ['notifications', 'preferences'],
|
|
23
|
+
webhooks: (wsId) => ['webhooks', wsId],
|
|
24
|
+
admin: ['admin'],
|
|
25
|
+
};
|
|
26
|
+
function createDefaultQueryClient() {
|
|
27
|
+
return new QueryClient({
|
|
28
|
+
defaultOptions: {
|
|
29
|
+
queries: {
|
|
30
|
+
staleTime: 30_000,
|
|
31
|
+
retry: (failureCount, error) => {
|
|
32
|
+
if (error instanceof ApiError && error.status >= 400 && error.status < 500)
|
|
33
|
+
return false;
|
|
34
|
+
return failureCount < 1;
|
|
35
|
+
},
|
|
36
|
+
refetchOnWindowFocus: false,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const WS_URL_PARAM = 'ws';
|
|
42
|
+
const wsStorageKey = (userId) => `pk.ws.${userId}`;
|
|
43
|
+
function readWsIdFromUrl() {
|
|
44
|
+
if (typeof window === 'undefined')
|
|
45
|
+
return null;
|
|
46
|
+
try {
|
|
47
|
+
return new URLSearchParams(window.location.search).get(WS_URL_PARAM) || null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function writeWsIdToUrl(id) {
|
|
54
|
+
if (typeof window === 'undefined')
|
|
55
|
+
return;
|
|
56
|
+
try {
|
|
57
|
+
const url = new URL(window.location.href);
|
|
58
|
+
url.searchParams.set(WS_URL_PARAM, id);
|
|
59
|
+
window.history.replaceState(window.history.state, '', url.href);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* 受限环境降级:仅不写 URL,上下文本体不受影响 */
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function removeWsIdFromUrl() {
|
|
66
|
+
if (typeof window === 'undefined')
|
|
67
|
+
return;
|
|
68
|
+
try {
|
|
69
|
+
const url = new URL(window.location.href);
|
|
70
|
+
if (!url.searchParams.has(WS_URL_PARAM))
|
|
71
|
+
return;
|
|
72
|
+
url.searchParams.delete(WS_URL_PARAM);
|
|
73
|
+
window.history.replaceState(window.history.state, '', url.href);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
/* 同上:静默降级 */
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function readStoredWsId(userId) {
|
|
80
|
+
if (typeof window === 'undefined')
|
|
81
|
+
return null;
|
|
82
|
+
try {
|
|
83
|
+
return window.localStorage.getItem(wsStorageKey(userId)) || null;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function writeStoredWsId(userId, id) {
|
|
90
|
+
if (typeof window === 'undefined')
|
|
91
|
+
return;
|
|
92
|
+
try {
|
|
93
|
+
window.localStorage.setItem(wsStorageKey(userId), id);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
/* localStorage 不可用(隐私模式/配额):降级为内存 + URL 两层 */
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function removeStoredWsId(userId) {
|
|
100
|
+
if (typeof window === 'undefined')
|
|
101
|
+
return;
|
|
102
|
+
try {
|
|
103
|
+
window.localStorage.removeItem(wsStorageKey(userId));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
/* 静默降级 */
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export const AuthContext = createContext(null);
|
|
110
|
+
export const WorkspaceContext = createContext(null);
|
|
111
|
+
export function useAuthCtx() {
|
|
112
|
+
const ctx = useContext(AuthContext);
|
|
113
|
+
if (!ctx)
|
|
114
|
+
throw new Error('must be used within PloykitProvider');
|
|
115
|
+
return ctx;
|
|
116
|
+
}
|
|
117
|
+
export function useWorkspaceCtx() {
|
|
118
|
+
const ctx = useContext(WorkspaceContext);
|
|
119
|
+
if (!ctx)
|
|
120
|
+
throw new Error('must be used within PloykitProvider');
|
|
121
|
+
return ctx;
|
|
122
|
+
}
|
|
123
|
+
export function PloykitProvider({ children, queryClient }) {
|
|
124
|
+
const [qc] = useState(() => queryClient ?? createDefaultQueryClient());
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
qc.setQueryDefaults(queryKeys.admin, { staleTime: 0 });
|
|
127
|
+
}, [qc]);
|
|
128
|
+
return (_jsx(QueryClientProvider, { client: qc, children: _jsx(AuthLayer, { children: _jsx(WorkspaceLayer, { children: children }) }) }));
|
|
129
|
+
}
|
|
130
|
+
function AuthLayer({ children }) {
|
|
131
|
+
const qc = useQueryClient();
|
|
132
|
+
const meQ = useQuery({
|
|
133
|
+
queryKey: queryKeys.me,
|
|
134
|
+
queryFn: () => api.get('/auth/me').catch((err) => {
|
|
135
|
+
if (err instanceof ApiError && err.status === 401)
|
|
136
|
+
return null;
|
|
137
|
+
throw err;
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
const wsQ = useQuery({
|
|
141
|
+
queryKey: queryKeys.workspaceList,
|
|
142
|
+
queryFn: () => api.get('/api/workspaces').catch((err) => {
|
|
143
|
+
if (err instanceof ApiError && err.status === 401)
|
|
144
|
+
return [];
|
|
145
|
+
throw err;
|
|
146
|
+
}),
|
|
147
|
+
});
|
|
148
|
+
const user = meQ.data ?? null;
|
|
149
|
+
const workspaces = Array.isArray(wsQ.data) ? wsQ.data : [];
|
|
150
|
+
const refresh = useCallback(async () => {
|
|
151
|
+
await Promise.all([
|
|
152
|
+
qc.invalidateQueries({ queryKey: queryKeys.auth }),
|
|
153
|
+
qc.invalidateQueries({ queryKey: queryKeys.workspace }),
|
|
154
|
+
]);
|
|
155
|
+
}, [qc]);
|
|
156
|
+
const logout = useCallback(async () => {
|
|
157
|
+
const me = qc.getQueryData(queryKeys.me);
|
|
158
|
+
if (me?.id)
|
|
159
|
+
removeStoredWsId(me.id);
|
|
160
|
+
await api.post('/auth/logout').catch(() => { });
|
|
161
|
+
qc.setQueryData(queryKeys.me, null);
|
|
162
|
+
qc.setQueryData(queryKeys.workspaceList, []);
|
|
163
|
+
qc.removeQueries();
|
|
164
|
+
}, [qc]);
|
|
165
|
+
const value = useMemo(() => ({
|
|
166
|
+
user,
|
|
167
|
+
workspaces,
|
|
168
|
+
loading: meQ.isPending || wsQ.isPending,
|
|
169
|
+
error: meQ.error ?? wsQ.error ?? null,
|
|
170
|
+
refresh,
|
|
171
|
+
logout,
|
|
172
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
173
|
+
}), [user, workspaces, meQ.isPending, wsQ.isPending, meQ.error, wsQ.error, refresh, logout]);
|
|
174
|
+
return _jsx(AuthContext.Provider, { value: value, children: children });
|
|
175
|
+
}
|
|
176
|
+
function WorkspaceLayer({ children }) {
|
|
177
|
+
const { user, workspaces } = useAuthCtx();
|
|
178
|
+
const [currentId, setCurrentId] = useState(null);
|
|
179
|
+
const userId = user?.id;
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!user || workspaces.length === 0 || currentId)
|
|
182
|
+
return;
|
|
183
|
+
const uid = user.id;
|
|
184
|
+
const candidate = readWsIdFromUrl() ?? (uid ? readStoredWsId(uid) : null);
|
|
185
|
+
if (candidate && workspaces.some((ws) => ws.id === candidate)) {
|
|
186
|
+
setCurrentId(candidate);
|
|
187
|
+
if (uid)
|
|
188
|
+
writeStoredWsId(uid, candidate);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (candidate) {
|
|
192
|
+
if (uid)
|
|
193
|
+
removeStoredWsId(uid);
|
|
194
|
+
removeWsIdFromUrl();
|
|
195
|
+
}
|
|
196
|
+
setCurrentId(workspaces[0].id);
|
|
197
|
+
}, [user, workspaces, currentId]);
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (currentId && !workspaces.some((ws) => ws.id === currentId)) {
|
|
200
|
+
setCurrentId(workspaces[0]?.id ?? null);
|
|
201
|
+
if (userId)
|
|
202
|
+
removeStoredWsId(userId);
|
|
203
|
+
removeWsIdFromUrl();
|
|
204
|
+
}
|
|
205
|
+
}, [workspaces, currentId, userId]);
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
if (typeof window === 'undefined')
|
|
208
|
+
return;
|
|
209
|
+
const onPopState = () => {
|
|
210
|
+
const urlId = readWsIdFromUrl();
|
|
211
|
+
if (!urlId)
|
|
212
|
+
return;
|
|
213
|
+
setCurrentId((prev) => (prev === urlId ? prev : urlId));
|
|
214
|
+
if (userId)
|
|
215
|
+
writeStoredWsId(userId, urlId);
|
|
216
|
+
};
|
|
217
|
+
window.addEventListener('popstate', onPopState);
|
|
218
|
+
return () => window.removeEventListener('popstate', onPopState);
|
|
219
|
+
}, [userId]);
|
|
220
|
+
const current = workspaces.find((ws) => ws.id === currentId) ?? null;
|
|
221
|
+
setWorkspaceIdProvider(() => current?.id ?? null);
|
|
222
|
+
const switchTo = useCallback((id) => {
|
|
223
|
+
setCurrentId(id);
|
|
224
|
+
if (userId)
|
|
225
|
+
writeStoredWsId(userId, id);
|
|
226
|
+
writeWsIdToUrl(id);
|
|
227
|
+
}, [userId]);
|
|
228
|
+
const clear = useCallback(() => {
|
|
229
|
+
setCurrentId(null);
|
|
230
|
+
if (userId)
|
|
231
|
+
removeStoredWsId(userId);
|
|
232
|
+
removeWsIdFromUrl();
|
|
233
|
+
}, [userId]);
|
|
234
|
+
const value = useMemo(() => ({
|
|
235
|
+
current,
|
|
236
|
+
switchTo,
|
|
237
|
+
clear,
|
|
238
|
+
}), [current, switchTo, clear]);
|
|
239
|
+
return _jsx(WorkspaceContext.Provider, { value: value, children: children });
|
|
240
|
+
}
|
package/dist/realtime.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WsClient } from '@ploykit/client';
|
|
2
|
+
export function defaultWsUrl(workspaceId) {
|
|
3
|
+
const proto = typeof location === 'undefined' ? 'ws' : location.protocol === 'https:' ? 'wss' : 'ws';
|
|
4
|
+
const host = typeof location === 'undefined' ? 'localhost' : location.host;
|
|
5
|
+
return workspaceId
|
|
6
|
+
? `${proto}://${host}/ws?workspace_id=${encodeURIComponent(workspaceId)}`
|
|
7
|
+
: `${proto}://${host}/ws`;
|
|
8
|
+
}
|
|
9
|
+
export function createWsClient(url, options) {
|
|
10
|
+
return new WsClient({ ...options, url });
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ploykit/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"development": "./src/index.ts",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@tanstack/react-query": "^5.0.0",
|
|
20
|
+
"react": "^19.0.0",
|
|
21
|
+
"react-dom": "^19.0.0",
|
|
22
|
+
"react-router": "^7.0.0",
|
|
23
|
+
"tailwindcss": "^4.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@base-ui/react": "^1.8.0",
|
|
27
|
+
"@hookform/resolvers": "^5.9.1",
|
|
28
|
+
"@ploykit/client": "^0.2.0",
|
|
29
|
+
"@ploykit/runtime": "^0.1.0",
|
|
30
|
+
"class-variance-authority": "^0.7.1",
|
|
31
|
+
"clsx": "^2.1.1",
|
|
32
|
+
"lucide-react": "^1.52.0",
|
|
33
|
+
"react-hook-form": "^7.0.0",
|
|
34
|
+
"sonner": "^2.0.8",
|
|
35
|
+
"tailwind-merge": "^3.7.0",
|
|
36
|
+
"zod": "^4.0.0"
|
|
37
|
+
},
|
|
38
|
+
"description": "React 前端壳:登录/工作区/计费的 Headless Hook + 默认页面。产物为 ESM(相对导入无扩展名,消费方需经 vite/esbuild 等打包器解析);exports 的 development 条件指向源码,供 monorepo 开发期直出消费。",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"prepublishOnly": "npm run build"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [],
|
|
45
|
+
"author": "",
|
|
46
|
+
"license": "ISC",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
49
|
+
"@testing-library/dom": "^10.4.2",
|
|
50
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
51
|
+
"@testing-library/react": "^16.3.3",
|
|
52
|
+
"jsdom": "^29.1.1",
|
|
53
|
+
"react-router": "7.18.4",
|
|
54
|
+
"tailwindcss": "^4.3.3",
|
|
55
|
+
"typescript": "^5.9.3",
|
|
56
|
+
"vitest": "^5.0.3"
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/haozing/ploykit.git",
|
|
61
|
+
"directory": "packages/ui"
|
|
62
|
+
}
|
|
63
|
+
}
|