@ploykit/ui 0.1.1 → 0.4.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.
Files changed (145) hide show
  1. package/README.md +183 -23
  2. package/dist/AppProviders.d.ts +15 -0
  3. package/dist/AppProviders.js +15 -0
  4. package/dist/components/ConfirmDialog.js +8 -2
  5. package/dist/components/CronInput.js +2 -2
  6. package/dist/components/DataTable.d.ts +12 -3
  7. package/dist/components/DataTable.js +7 -3
  8. package/dist/components/ErrorBoundary.js +1 -1
  9. package/dist/components/ImpersonationBanner.js +1 -1
  10. package/dist/components/NotificationBell.js +5 -5
  11. package/dist/components/OnboardingChecklist.js +3 -3
  12. package/dist/components/Page.js +1 -1
  13. package/dist/components/ReauthDialog.d.ts +15 -0
  14. package/dist/components/ReauthDialog.js +42 -0
  15. package/dist/components/SecretModal.d.ts +8 -1
  16. package/dist/components/SecretModal.js +6 -3
  17. package/dist/components/SettingsCard.js +2 -2
  18. package/dist/components/SiteBannerLayer.js +1 -1
  19. package/dist/components/StatusBadge.d.ts +4 -0
  20. package/dist/components/StatusBadge.js +7 -0
  21. package/dist/components/UserMenu.js +2 -2
  22. package/dist/components/WorkspaceSwitcher.js +4 -4
  23. package/dist/components/ui/alert-dialog.d.ts +2 -2
  24. package/dist/components/ui/alert-dialog.js +10 -9
  25. package/dist/components/ui/avatar.js +3 -2
  26. package/dist/components/ui/badge.d.ts +7 -0
  27. package/dist/components/ui/badge.js +33 -0
  28. package/dist/components/ui/breadcrumb.js +7 -7
  29. package/dist/components/ui/button.d.ts +8 -0
  30. package/dist/components/ui/button.js +34 -0
  31. package/dist/components/ui/card.d.ts +2 -4
  32. package/dist/components/ui/card.js +7 -7
  33. package/dist/components/ui/checkbox.js +3 -2
  34. package/dist/components/ui/dialog.d.ts +22 -14
  35. package/dist/components/ui/dialog.js +40 -25
  36. package/dist/components/ui/dropdown-menu.js +50 -0
  37. package/dist/components/ui/empty.d.ts +7 -9
  38. package/dist/components/ui/empty.js +6 -9
  39. package/dist/components/ui/field.js +10 -9
  40. package/dist/components/ui/input.d.ts +3 -0
  41. package/dist/components/ui/input.js +7 -0
  42. package/dist/components/ui/popover.js +3 -2
  43. package/dist/components/ui/progress.js +2 -1
  44. package/dist/components/ui/select.d.ts +20 -1
  45. package/dist/components/ui/select.js +28 -7
  46. package/dist/components/ui/separator.js +1 -0
  47. package/dist/components/ui/sheet.d.ts +9 -1
  48. package/dist/components/ui/sheet.js +11 -4
  49. package/dist/components/ui/sidebar.d.ts +2 -2
  50. package/dist/components/ui/sidebar.js +25 -34
  51. package/dist/components/ui/skeleton.d.ts +1 -2
  52. package/dist/components/ui/switch.js +1 -1
  53. package/dist/components/ui/tabs.js +3 -3
  54. package/dist/components/ui/textarea.d.ts +9 -0
  55. package/dist/components/ui/textarea.js +12 -0
  56. package/dist/components/ui/tooltip.js +1 -1
  57. package/dist/index.d.ts +10 -40
  58. package/dist/index.js +10 -26
  59. package/dist/layouts/AppShell.d.ts +1 -1
  60. package/dist/layouts/AppShell.js +23 -1
  61. package/dist/layouts/SettingsShell.d.ts +1 -1
  62. package/dist/layouts/SettingsShell.js +3 -3
  63. package/dist/pages/LandingPage.js +1 -1
  64. package/dist/pages/LoginPage.js +7 -7
  65. package/dist/pages/account/NotificationPreferencesPage.js +2 -2
  66. package/dist/pages/account/ProfileSettingsPage.js +7 -7
  67. package/dist/pages/account/SecuritySettingsPage.js +8 -8
  68. package/dist/pages/account/TokensPage.js +4 -4
  69. package/dist/pages/admin/AdminSettingsPage.js +5 -5
  70. package/dist/pages/admin/AdminShell.js +2 -2
  71. package/dist/pages/admin/AuditPage.js +3 -3
  72. package/dist/pages/admin/OrdersPage.js +4 -3
  73. package/dist/pages/admin/OverviewPage.js +4 -4
  74. package/dist/pages/admin/SSOPage.js +3 -3
  75. package/dist/pages/admin/UserDetailPage.js +6 -5
  76. package/dist/pages/admin/UsersPage.js +7 -6
  77. package/dist/pages/admin/WebhookDeliveriesPage.js +4 -3
  78. package/dist/pages/admin/WorkspaceDetailPage.js +5 -5
  79. package/dist/pages/admin/WorkspacesPage.js +4 -4
  80. package/dist/pages/admin/shared.js +1 -1
  81. package/dist/pages/auth/ForgotPasswordPage.js +3 -3
  82. package/dist/pages/auth/InviteAcceptPage.js +4 -4
  83. package/dist/pages/auth/RegisterPage.js +6 -6
  84. package/dist/pages/auth/ResetPasswordPage.js +4 -4
  85. package/dist/pages/auth/VerifyEmailPage.js +4 -4
  86. package/dist/pages/workspace/BillingPage.js +8 -7
  87. package/dist/pages/workspace/BillingSuccessPage.js +3 -3
  88. package/dist/pages/workspace/MembersPage.js +7 -6
  89. package/dist/pages/workspace/RolePermissionsPage.d.ts +3 -0
  90. package/dist/pages/workspace/RolePermissionsPage.js +118 -0
  91. package/dist/pages/workspace/SchedulesPage.js +5 -5
  92. package/dist/pages/workspace/UsagePage.d.ts +1 -1
  93. package/dist/pages/workspace/UsagePage.js +2 -2
  94. package/dist/pages/workspace/WebhooksPage.js +9 -9
  95. package/dist/pages/workspace/WorkspaceAuditPage.js +3 -3
  96. package/dist/pages/workspace/WorkspaceGeneralPage.js +7 -7
  97. package/package.json +9 -5
  98. package/dist/components/ui/Badge.d.ts +0 -13
  99. package/dist/components/ui/Badge.js +0 -21
  100. package/dist/components/ui/Button.d.ts +0 -10
  101. package/dist/components/ui/Button.js +0 -33
  102. package/dist/components/ui/Input.d.ts +0 -3
  103. package/dist/components/ui/Input.js +0 -10
  104. package/dist/components/ui/menu.js +0 -50
  105. package/dist/hooks/useApi.d.ts +0 -10
  106. package/dist/hooks/useApi.js +0 -11
  107. package/dist/hooks/useAudit.d.ts +0 -39
  108. package/dist/hooks/useAudit.js +0 -55
  109. package/dist/hooks/useAuth.d.ts +0 -1
  110. package/dist/hooks/useAuth.js +0 -4
  111. package/dist/hooks/useBilling.d.ts +0 -44
  112. package/dist/hooks/useBilling.js +0 -64
  113. package/dist/hooks/useLogin.d.ts +0 -10
  114. package/dist/hooks/useLogin.js +0 -39
  115. package/dist/hooks/useMembers.d.ts +0 -125
  116. package/dist/hooks/useMembers.js +0 -127
  117. package/dist/hooks/useNotificationPrefs.d.ts +0 -20
  118. package/dist/hooks/useNotificationPrefs.js +0 -42
  119. package/dist/hooks/usePasswordReset.d.ts +0 -5
  120. package/dist/hooks/usePasswordReset.js +0 -12
  121. package/dist/hooks/useSEO.d.ts +0 -6
  122. package/dist/hooks/useSEO.js +0 -14
  123. package/dist/hooks/useSessions.d.ts +0 -20
  124. package/dist/hooks/useSessions.js +0 -38
  125. package/dist/hooks/useSiteConfig.d.ts +0 -12
  126. package/dist/hooks/useSiteConfig.js +0 -11
  127. package/dist/hooks/useTokens.d.ts +0 -36
  128. package/dist/hooks/useTokens.js +0 -35
  129. package/dist/hooks/useUsage.d.ts +0 -20
  130. package/dist/hooks/useUsage.js +0 -21
  131. package/dist/hooks/useWorkspace.d.ts +0 -26
  132. package/dist/hooks/useWorkspace.js +0 -32
  133. package/dist/hooks/useZodForm.d.ts +0 -6
  134. package/dist/hooks/useZodForm.js +0 -6
  135. package/dist/hooks/ws.d.ts +0 -4
  136. package/dist/hooks/ws.js +0 -21
  137. package/dist/lib/perm.d.ts +0 -2
  138. package/dist/lib/perm.js +0 -7
  139. package/dist/lib/ws-query-bridge.d.ts +0 -7
  140. package/dist/lib/ws-query-bridge.js +0 -35
  141. package/dist/provider/PloykitProvider.d.ts +0 -50
  142. package/dist/provider/PloykitProvider.js +0 -240
  143. package/dist/realtime.d.ts +0 -3
  144. package/dist/realtime.js +0 -11
  145. /package/dist/components/ui/{menu.d.ts → dropdown-menu.d.ts} +0 -0
@@ -1,240 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- import { WsClient, type WsClientOptions } from '@ploykit/client';
2
- export declare function defaultWsUrl(workspaceId?: string | null): string;
3
- export declare function createWsClient(url: () => string, options?: Omit<WsClientOptions, 'url'>): WsClient;
package/dist/realtime.js DELETED
@@ -1,11 +0,0 @@
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
- }