@zjazj/web 0.0.9 → 0.0.10
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/dist/index.d.ts +60 -1
- package/dist/index.js +391 -7
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -342,6 +342,65 @@ declare function permissionMatches(granted: ReadonlySet<string>, code: string):
|
|
|
342
342
|
/** True when every required code is covered. An empty requirement is always satisfied. */
|
|
343
343
|
declare function hasPermissions(granted: Iterable<string>, required: readonly string[]): boolean;
|
|
344
344
|
|
|
345
|
+
/** Who sees an object besides its owner and those it is granted to. */
|
|
346
|
+
type ObjectVisibility = 'private' | 'tenant';
|
|
347
|
+
/** What a grant lets its user or role do: see, change as well, or share as well. */
|
|
348
|
+
type GrantLevel = 'viewer' | 'editor' | 'manager';
|
|
349
|
+
/** One grant, as the platform's routes answer it. */
|
|
350
|
+
interface ObjectGrant {
|
|
351
|
+
principal_type: 'user' | 'role';
|
|
352
|
+
principal_id: string;
|
|
353
|
+
level: GrantLevel;
|
|
354
|
+
}
|
|
355
|
+
/** Who one object is shared with, and the caller's own access to it. */
|
|
356
|
+
interface ObjectSharing {
|
|
357
|
+
owner_id: string | null;
|
|
358
|
+
visibility: ObjectVisibility;
|
|
359
|
+
grants: ObjectGrant[];
|
|
360
|
+
level: 'override' | 'owner' | GrantLevel;
|
|
361
|
+
}
|
|
362
|
+
/** A member of the tenant, as the directory lists one. No email. */
|
|
363
|
+
interface DirectoryMember {
|
|
364
|
+
id: string;
|
|
365
|
+
name: string;
|
|
366
|
+
avatar: string | null;
|
|
367
|
+
}
|
|
368
|
+
/** A role of the tenant. A grant to a role names its code. */
|
|
369
|
+
interface DirectoryRole {
|
|
370
|
+
code: string;
|
|
371
|
+
name: string;
|
|
372
|
+
}
|
|
373
|
+
interface ShareDialogProps {
|
|
374
|
+
/** The object kind, as the backend's `defineObjects` names it. */
|
|
375
|
+
type: string;
|
|
376
|
+
/** The object's id. */
|
|
377
|
+
id: string;
|
|
378
|
+
/** The object's name, shown in the title. */
|
|
379
|
+
name?: string;
|
|
380
|
+
/** The button that opens the dialog. Leave it out and pass `open` to open it yourself. */
|
|
381
|
+
children?: ReactNode;
|
|
382
|
+
open?: boolean;
|
|
383
|
+
onOpenChange?: (open: boolean) => void;
|
|
384
|
+
/** Called with the sharing once a change is saved. */
|
|
385
|
+
onSaved?: (sharing: ObjectSharing) => void;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The Share dialog of an object: who owns it, whether the whole tenant sees it, and which
|
|
389
|
+
* members and roles may see, change or share it. Everyone who may see the object sees the
|
|
390
|
+
* dialog. Its owner, a manager and the app's override change it; its owner and the
|
|
391
|
+
* override pass ownership on.
|
|
392
|
+
*
|
|
393
|
+
* ```tsx
|
|
394
|
+
* <ShareDialog type='report' id={report.id} name={report.name}>
|
|
395
|
+
* <Button variant='outline'>Share</Button>
|
|
396
|
+
* </ShareDialog>
|
|
397
|
+
* ```
|
|
398
|
+
*
|
|
399
|
+
* The backend declares the kind with `defineObjects`. The platform serves the routes this
|
|
400
|
+
* dialog calls, and the tenant's members and roles come from the control plane.
|
|
401
|
+
*/
|
|
402
|
+
declare function ShareDialog(props: ShareDialogProps): react.JSX.Element;
|
|
403
|
+
|
|
345
404
|
/**
|
|
346
405
|
* The current tenant of this browser. One browser profile has one current tenant, and every
|
|
347
406
|
* tab of every app reads the same value. The header of every app
|
|
@@ -375,4 +434,4 @@ declare function getPinnedTenant(): string | undefined;
|
|
|
375
434
|
/** True once another tab switched tenant. The tab must reload before it sends anything. */
|
|
376
435
|
declare function isTenantChanged(): boolean;
|
|
377
436
|
|
|
378
|
-
export { AUTH_CALLBACK_PATH, AUTH_CONFIG_PATH, type ApiClient, ApiError, AppShell, type AuthConfig, Can, type CanProps, type CreateAppOptions, type CurrentUser, type DevSession, ErrorScreen, Forbidden, type IdentityClaims, type IdentityClient, type MenuGroup, type MenuItem, type MenuMeta, NotFound, type PlatformConfig, PlatformProvider, type PlatformSessionOptions, RETURN_TO_KEY, type RouteMeta, type Session, type SessionStatus, type StoredTenant, TENANT_STORAGE_KEY, type Tenant, type WebApp, apiBaseUrl, buildMenu, createApp, createClient, createDevSession, createPlatformSession, encodeDevToken, getPinnedTenant, getPlatformConfig, getSession, hasPermissions, isTenantChanged, permissionMatches, pinTenant, platformFetch, readStoredTenant, setSession, useAppConfig, useCan, useOptionalUser, useSession, useSessionStatus, useTenant, useUser };
|
|
437
|
+
export { AUTH_CALLBACK_PATH, AUTH_CONFIG_PATH, type ApiClient, ApiError, AppShell, type AuthConfig, Can, type CanProps, type CreateAppOptions, type CurrentUser, type DevSession, type DirectoryMember, type DirectoryRole, ErrorScreen, Forbidden, type GrantLevel, type IdentityClaims, type IdentityClient, type MenuGroup, type MenuItem, type MenuMeta, NotFound, type ObjectGrant, type ObjectSharing, type ObjectVisibility, type PlatformConfig, PlatformProvider, type PlatformSessionOptions, RETURN_TO_KEY, type RouteMeta, type Session, type SessionStatus, ShareDialog, type ShareDialogProps, type StoredTenant, TENANT_STORAGE_KEY, type Tenant, type WebApp, apiBaseUrl, buildMenu, createApp, createClient, createDevSession, createPlatformSession, encodeDevToken, getPinnedTenant, getPlatformConfig, getSession, hasPermissions, isTenantChanged, permissionMatches, pinTenant, platformFetch, readStoredTenant, setSession, useAppConfig, useCan, useOptionalUser, useSession, useSessionStatus, useTenant, useUser };
|
package/dist/index.js
CHANGED
|
@@ -48,7 +48,32 @@ var en_US_default = {
|
|
|
48
48
|
supportEndedTitle: "Support session ended",
|
|
49
49
|
supportEndedBody: "Your time in this tenant is over. Continue in your own tenant.",
|
|
50
50
|
continue: "Continue",
|
|
51
|
-
enterTenantNoSignIn: "No sign-in set up"
|
|
51
|
+
enterTenantNoSignIn: "No sign-in set up",
|
|
52
|
+
shareTitle: "Share",
|
|
53
|
+
shareTitleNamed: "Share {{name}}",
|
|
54
|
+
shareBody: "Choose who may see it, change it, or share it further.",
|
|
55
|
+
shareLoading: "Loading\u2026",
|
|
56
|
+
shareOwner: "Owner",
|
|
57
|
+
shareNoOwner: "Nobody",
|
|
58
|
+
shareFormerMember: "A former member",
|
|
59
|
+
shareVisibility: "Who sees it",
|
|
60
|
+
shareVisibilityPrivate: "Only the people and roles below",
|
|
61
|
+
shareVisibilityTenant: "Everyone in the tenant",
|
|
62
|
+
shareSearch: "Add people or roles",
|
|
63
|
+
shareNoneFound: "Nobody found.",
|
|
64
|
+
sharePeople: "People",
|
|
65
|
+
shareRoles: "Roles",
|
|
66
|
+
shareRole: "Role",
|
|
67
|
+
shareWith: "Shared with",
|
|
68
|
+
shareNobody: "Not shared with anyone.",
|
|
69
|
+
shareLevel: "Access",
|
|
70
|
+
shareLevel_viewer: "Can view",
|
|
71
|
+
shareLevel_editor: "Can edit",
|
|
72
|
+
shareLevel_manager: "Can share",
|
|
73
|
+
shareMakeOwner: "Make owner",
|
|
74
|
+
shareRemove: "Remove",
|
|
75
|
+
shareSave: "Save",
|
|
76
|
+
shareClose: "Close"
|
|
52
77
|
};
|
|
53
78
|
|
|
54
79
|
// src/locales/zh-CN.json
|
|
@@ -98,7 +123,32 @@ var zh_CN_default = {
|
|
|
98
123
|
supportEndedTitle: "\u652F\u6301\u4F1A\u8BDD\u5DF2\u7ED3\u675F",
|
|
99
124
|
supportEndedBody: "\u4F60\u5728\u8FD9\u4E2A\u79DF\u6237\u7684\u65F6\u95F4\u5DF2\u5230\u3002\u7EE7\u7EED\u4F1A\u56DE\u5230\u4F60\u81EA\u5DF1\u7684\u79DF\u6237\u3002",
|
|
100
125
|
continue: "\u7EE7\u7EED",
|
|
101
|
-
enterTenantNoSignIn: "\u672A\u5F00\u901A\u767B\u5F55"
|
|
126
|
+
enterTenantNoSignIn: "\u672A\u5F00\u901A\u767B\u5F55",
|
|
127
|
+
shareTitle: "\u5171\u4EAB",
|
|
128
|
+
shareTitleNamed: "\u5171\u4EAB\u201C{{name}}\u201D",
|
|
129
|
+
shareBody: "\u9009\u62E9\u8C01\u53EF\u4EE5\u67E5\u770B\u3001\u4FEE\u6539\u6216\u7EE7\u7EED\u5171\u4EAB\u5B83\u3002",
|
|
130
|
+
shareLoading: "\u6B63\u5728\u52A0\u8F7D\u2026",
|
|
131
|
+
shareOwner: "\u6240\u6709\u8005",
|
|
132
|
+
shareNoOwner: "\u65E0",
|
|
133
|
+
shareFormerMember: "\u5DF2\u79BB\u5F00\u7684\u6210\u5458",
|
|
134
|
+
shareVisibility: "\u8C01\u80FD\u770B\u5230",
|
|
135
|
+
shareVisibilityPrivate: "\u4EC5\u4E0B\u65B9\u7684\u4EBA\u5458\u548C\u89D2\u8272",
|
|
136
|
+
shareVisibilityTenant: "\u79DF\u6237\u5185\u6240\u6709\u4EBA",
|
|
137
|
+
shareSearch: "\u6DFB\u52A0\u4EBA\u5458\u6216\u89D2\u8272",
|
|
138
|
+
shareNoneFound: "\u6CA1\u6709\u627E\u5230\u3002",
|
|
139
|
+
sharePeople: "\u4EBA\u5458",
|
|
140
|
+
shareRoles: "\u89D2\u8272",
|
|
141
|
+
shareRole: "\u89D2\u8272",
|
|
142
|
+
shareWith: "\u5DF2\u5171\u4EAB\u7ED9",
|
|
143
|
+
shareNobody: "\u5C1A\u672A\u5171\u4EAB\u7ED9\u4EFB\u4F55\u4EBA\u3002",
|
|
144
|
+
shareLevel: "\u6743\u9650",
|
|
145
|
+
shareLevel_viewer: "\u53EF\u67E5\u770B",
|
|
146
|
+
shareLevel_editor: "\u53EF\u7F16\u8F91",
|
|
147
|
+
shareLevel_manager: "\u53EF\u5171\u4EAB",
|
|
148
|
+
shareMakeOwner: "\u8BBE\u4E3A\u6240\u6709\u8005",
|
|
149
|
+
shareRemove: "\u79FB\u9664",
|
|
150
|
+
shareSave: "\u4FDD\u5B58",
|
|
151
|
+
shareClose: "\u5173\u95ED"
|
|
102
152
|
};
|
|
103
153
|
|
|
104
154
|
// src/app.tsx
|
|
@@ -557,13 +607,13 @@ function readStoredPatch() {
|
|
|
557
607
|
return {};
|
|
558
608
|
}
|
|
559
609
|
}
|
|
560
|
-
function createDevSession(
|
|
610
|
+
function createDevSession(base2) {
|
|
561
611
|
const listeners2 = /* @__PURE__ */ new Set();
|
|
562
612
|
let patch = readStoredPatch();
|
|
563
|
-
let current = { ...
|
|
613
|
+
let current = { ...base2, ...patch, isDev: true };
|
|
564
614
|
const update = (next) => {
|
|
565
615
|
patch = next;
|
|
566
|
-
current = { ...
|
|
616
|
+
current = { ...base2, ...patch, isDev: true };
|
|
567
617
|
try {
|
|
568
618
|
if (Object.keys(patch).length === 0) globalThis.localStorage?.removeItem(DEV_USER_STORAGE_KEY);
|
|
569
619
|
else globalThis.localStorage?.setItem(DEV_USER_STORAGE_KEY, JSON.stringify(patch));
|
|
@@ -1064,10 +1114,10 @@ function AccountMenu() {
|
|
|
1064
1114
|
const config = useAppConfig();
|
|
1065
1115
|
const { theme, setTheme } = useTheme();
|
|
1066
1116
|
const [locale, setLocale] = useLocale();
|
|
1067
|
-
const
|
|
1117
|
+
const initials2 = user.username.trim().slice(0, 2).toUpperCase() || "?";
|
|
1068
1118
|
const profile = user.isDev ? void 0 : profileLink(config.portalUrl, config.basePath);
|
|
1069
1119
|
return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
1070
|
-
/* @__PURE__ */ jsx2(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx2(Button, { variant: "ghost", size: "icon", className: "rounded-full", "aria-label": t("account"), children: /* @__PURE__ */ jsx2(Avatar, { className: "size-8", children: /* @__PURE__ */ jsx2(AvatarFallback, { children:
|
|
1120
|
+
/* @__PURE__ */ jsx2(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx2(Button, { variant: "ghost", size: "icon", className: "rounded-full", "aria-label": t("account"), children: /* @__PURE__ */ jsx2(Avatar, { className: "size-8", children: /* @__PURE__ */ jsx2(AvatarFallback, { children: initials2 }) }) }) }),
|
|
1071
1121
|
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-56", children: [
|
|
1072
1122
|
/* @__PURE__ */ jsxs(DropdownMenuLabel, { className: "flex flex-col gap-1", children: [
|
|
1073
1123
|
/* @__PURE__ */ jsx2("span", { className: "truncate", children: user.username }),
|
|
@@ -1262,6 +1312,339 @@ function createApp(options) {
|
|
|
1262
1312
|
};
|
|
1263
1313
|
}
|
|
1264
1314
|
|
|
1315
|
+
// src/share.tsx
|
|
1316
|
+
import { useT as useT2 } from "@zjazj/i18n/react";
|
|
1317
|
+
import {
|
|
1318
|
+
Avatar as Avatar2,
|
|
1319
|
+
AvatarFallback as AvatarFallback2,
|
|
1320
|
+
AvatarImage,
|
|
1321
|
+
Badge as Badge2,
|
|
1322
|
+
Button as Button2,
|
|
1323
|
+
Command as Command2,
|
|
1324
|
+
CommandEmpty as CommandEmpty2,
|
|
1325
|
+
CommandGroup,
|
|
1326
|
+
CommandInput as CommandInput2,
|
|
1327
|
+
CommandItem as CommandItem2,
|
|
1328
|
+
CommandList as CommandList2,
|
|
1329
|
+
Dialog as Dialog2,
|
|
1330
|
+
DialogContent as DialogContent2,
|
|
1331
|
+
DialogDescription as DialogDescription2,
|
|
1332
|
+
DialogFooter as DialogFooter2,
|
|
1333
|
+
DialogHeader as DialogHeader2,
|
|
1334
|
+
DialogTitle as DialogTitle2,
|
|
1335
|
+
DialogTrigger as DialogTrigger2,
|
|
1336
|
+
Select,
|
|
1337
|
+
SelectContent,
|
|
1338
|
+
SelectItem,
|
|
1339
|
+
SelectTrigger,
|
|
1340
|
+
SelectValue
|
|
1341
|
+
} from "@zjazj/ui";
|
|
1342
|
+
import { Crown, Users, X } from "lucide-react";
|
|
1343
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
1344
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1345
|
+
var LEVELS = ["viewer", "editor", "manager"];
|
|
1346
|
+
function base() {
|
|
1347
|
+
return `${apiBaseUrl()}/_platform`;
|
|
1348
|
+
}
|
|
1349
|
+
async function readJson(url, init) {
|
|
1350
|
+
const response = await platformFetch(url, init);
|
|
1351
|
+
return await response.json();
|
|
1352
|
+
}
|
|
1353
|
+
function initials(name) {
|
|
1354
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
1355
|
+
return (parts.length > 1 ? `${parts[0]?.[0]}${parts[1]?.[0]}` : name.slice(0, 2)).toUpperCase();
|
|
1356
|
+
}
|
|
1357
|
+
function messageOf3(error) {
|
|
1358
|
+
return error instanceof Error ? error.message : String(error);
|
|
1359
|
+
}
|
|
1360
|
+
function ShareDialog(props) {
|
|
1361
|
+
const t = useT2("web");
|
|
1362
|
+
const [ownOpen, setOwnOpen] = useState2(false);
|
|
1363
|
+
const open = props.open ?? ownOpen;
|
|
1364
|
+
const setOpen = (value) => {
|
|
1365
|
+
setOwnOpen(value);
|
|
1366
|
+
props.onOpenChange?.(value);
|
|
1367
|
+
};
|
|
1368
|
+
const [sharing, setSharing] = useState2();
|
|
1369
|
+
const [visibility, setVisibility] = useState2("private");
|
|
1370
|
+
const [grants, setGrants] = useState2([]);
|
|
1371
|
+
const [people, setPeople] = useState2({});
|
|
1372
|
+
const [roles, setRoles] = useState2([]);
|
|
1373
|
+
const [query, setQuery] = useState2("");
|
|
1374
|
+
const [found, setFound] = useState2([]);
|
|
1375
|
+
const [busy, setBusy] = useState2(false);
|
|
1376
|
+
const [failure, setFailure] = useState2();
|
|
1377
|
+
const sharingUrl = `${base()}/objects/${encodeURIComponent(props.type)}/${encodeURIComponent(props.id)}`;
|
|
1378
|
+
useEffect2(() => {
|
|
1379
|
+
if (!open) return;
|
|
1380
|
+
let stale = false;
|
|
1381
|
+
setSharing(void 0);
|
|
1382
|
+
setFailure(void 0);
|
|
1383
|
+
setQuery("");
|
|
1384
|
+
const load = async () => {
|
|
1385
|
+
const [answer, tenantRoles] = await Promise.all([
|
|
1386
|
+
readJson(`${sharingUrl}/sharing`),
|
|
1387
|
+
readJson(`${base()}/directory/roles`).catch(() => [])
|
|
1388
|
+
]);
|
|
1389
|
+
const ids = [
|
|
1390
|
+
.../* @__PURE__ */ new Set([
|
|
1391
|
+
...answer.owner_id ? [answer.owner_id] : [],
|
|
1392
|
+
...answer.grants.filter((g) => g.principal_type === "user").map((g) => g.principal_id)
|
|
1393
|
+
])
|
|
1394
|
+
];
|
|
1395
|
+
const named = ids.length > 0 ? await readJson(
|
|
1396
|
+
`${base()}/directory/members?ids=${encodeURIComponent(ids.join(","))}`
|
|
1397
|
+
).catch(() => ({ items: [] })) : { items: [] };
|
|
1398
|
+
if (stale) return;
|
|
1399
|
+
setSharing(answer);
|
|
1400
|
+
setVisibility(answer.visibility);
|
|
1401
|
+
setGrants(answer.grants);
|
|
1402
|
+
setRoles(Array.isArray(tenantRoles) ? tenantRoles : []);
|
|
1403
|
+
setPeople(Object.fromEntries((named.items ?? []).map((member) => [member.id, member])));
|
|
1404
|
+
};
|
|
1405
|
+
load().catch((error) => {
|
|
1406
|
+
if (!stale) setFailure(messageOf3(error));
|
|
1407
|
+
});
|
|
1408
|
+
return () => {
|
|
1409
|
+
stale = true;
|
|
1410
|
+
};
|
|
1411
|
+
}, [open, sharingUrl]);
|
|
1412
|
+
useEffect2(() => {
|
|
1413
|
+
if (!open || query.trim() === "") {
|
|
1414
|
+
setFound([]);
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
let stale = false;
|
|
1418
|
+
const timer = window.setTimeout(() => {
|
|
1419
|
+
readJson(
|
|
1420
|
+
`${base()}/directory/members?page_size=20&q=${encodeURIComponent(query.trim())}`
|
|
1421
|
+
).then((page) => {
|
|
1422
|
+
if (!stale) setFound(page.items ?? []);
|
|
1423
|
+
}).catch(() => {
|
|
1424
|
+
if (!stale) setFound([]);
|
|
1425
|
+
});
|
|
1426
|
+
}, 250);
|
|
1427
|
+
return () => {
|
|
1428
|
+
stale = true;
|
|
1429
|
+
window.clearTimeout(timer);
|
|
1430
|
+
};
|
|
1431
|
+
}, [open, query]);
|
|
1432
|
+
const canShare = sharing ? ["override", "owner", "manager"].includes(sharing.level) : false;
|
|
1433
|
+
const canTransfer = sharing ? ["override", "owner"].includes(sharing.level) : false;
|
|
1434
|
+
const changed2 = useMemo2(
|
|
1435
|
+
() => sharing !== void 0 && (visibility !== sharing.visibility || JSON.stringify(grants) !== JSON.stringify(sharing.grants)),
|
|
1436
|
+
[sharing, visibility, grants]
|
|
1437
|
+
);
|
|
1438
|
+
const has = (type, id) => grants.some((grant) => grant.principal_type === type && grant.principal_id === id);
|
|
1439
|
+
const add = (type, id, member) => {
|
|
1440
|
+
if (member) setPeople((known) => ({ ...known, [member.id]: member }));
|
|
1441
|
+
if (!has(type, id) && !(type === "user" && id === sharing?.owner_id)) {
|
|
1442
|
+
setGrants((list) => [...list, { principal_type: type, principal_id: id, level: "viewer" }]);
|
|
1443
|
+
}
|
|
1444
|
+
setQuery("");
|
|
1445
|
+
};
|
|
1446
|
+
const setLevel = (grant, level) => setGrants((list) => list.map((item) => item === grant ? { ...item, level } : item));
|
|
1447
|
+
const remove = (grant) => setGrants((list) => list.filter((item) => item !== grant));
|
|
1448
|
+
const run = async (work) => {
|
|
1449
|
+
setBusy(true);
|
|
1450
|
+
setFailure(void 0);
|
|
1451
|
+
try {
|
|
1452
|
+
const answer = await work();
|
|
1453
|
+
if (answer) {
|
|
1454
|
+
setSharing(answer);
|
|
1455
|
+
setVisibility(answer.visibility);
|
|
1456
|
+
setGrants(answer.grants);
|
|
1457
|
+
props.onSaved?.(answer);
|
|
1458
|
+
}
|
|
1459
|
+
return true;
|
|
1460
|
+
} catch (error) {
|
|
1461
|
+
setFailure(messageOf3(error));
|
|
1462
|
+
return false;
|
|
1463
|
+
} finally {
|
|
1464
|
+
setBusy(false);
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
const save = () => run(
|
|
1468
|
+
() => readJson(`${sharingUrl}/sharing`, {
|
|
1469
|
+
method: "PUT",
|
|
1470
|
+
headers: { "Content-Type": "application/json" },
|
|
1471
|
+
body: JSON.stringify({ visibility, grants })
|
|
1472
|
+
})
|
|
1473
|
+
).then((done) => {
|
|
1474
|
+
if (done) setOpen(false);
|
|
1475
|
+
});
|
|
1476
|
+
const makeOwner = (id) => run(async () => {
|
|
1477
|
+
const answer = await readJson(`${sharingUrl}/owner`, {
|
|
1478
|
+
method: "PUT",
|
|
1479
|
+
headers: { "Content-Type": "application/json" },
|
|
1480
|
+
body: JSON.stringify({ owner_id: id })
|
|
1481
|
+
});
|
|
1482
|
+
return answer.level ? answer : void 0;
|
|
1483
|
+
}).then((done) => {
|
|
1484
|
+
if (done && sharing?.level === "owner") setOpen(false);
|
|
1485
|
+
});
|
|
1486
|
+
const nameOf = (id) => people[id]?.name ?? t("shareFormerMember");
|
|
1487
|
+
const roleName = (code) => roles.find((role) => role.code === code)?.name ?? code;
|
|
1488
|
+
const owner = sharing?.owner_id ?? null;
|
|
1489
|
+
const matchingRoles = roles.filter(
|
|
1490
|
+
(role) => query.trim() !== "" && `${role.name} ${role.code}`.toLowerCase().includes(query.trim().toLowerCase())
|
|
1491
|
+
);
|
|
1492
|
+
return /* @__PURE__ */ jsxs3(Dialog2, { open, onOpenChange: setOpen, children: [
|
|
1493
|
+
props.children ? /* @__PURE__ */ jsx4(DialogTrigger2, { asChild: true, children: props.children }) : null,
|
|
1494
|
+
/* @__PURE__ */ jsxs3(DialogContent2, { className: "sm:max-w-lg", children: [
|
|
1495
|
+
/* @__PURE__ */ jsxs3(DialogHeader2, { children: [
|
|
1496
|
+
/* @__PURE__ */ jsx4(DialogTitle2, { children: props.name ? t("shareTitleNamed", { name: props.name }) : t("shareTitle") }),
|
|
1497
|
+
/* @__PURE__ */ jsx4(DialogDescription2, { children: t("shareBody") })
|
|
1498
|
+
] }),
|
|
1499
|
+
sharing === void 0 && !failure ? /* @__PURE__ */ jsx4("p", { className: "text-muted-foreground text-sm", children: t("shareLoading") }) : null,
|
|
1500
|
+
sharing ? /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-4", children: [
|
|
1501
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
1502
|
+
/* @__PURE__ */ jsx4(Crown, { className: "text-muted-foreground size-4" }),
|
|
1503
|
+
/* @__PURE__ */ jsx4("span", { className: "text-muted-foreground", children: t("shareOwner") }),
|
|
1504
|
+
/* @__PURE__ */ jsx4("span", { className: "truncate font-medium", children: owner ? nameOf(owner) : t("shareNoOwner") })
|
|
1505
|
+
] }),
|
|
1506
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-1.5 text-sm", children: [
|
|
1507
|
+
/* @__PURE__ */ jsx4("span", { className: "font-medium", children: t("shareVisibility") }),
|
|
1508
|
+
/* @__PURE__ */ jsxs3(
|
|
1509
|
+
Select,
|
|
1510
|
+
{
|
|
1511
|
+
value: visibility,
|
|
1512
|
+
disabled: !canShare || busy,
|
|
1513
|
+
onValueChange: (value) => setVisibility(value),
|
|
1514
|
+
children: [
|
|
1515
|
+
/* @__PURE__ */ jsx4(SelectTrigger, { "aria-label": t("shareVisibility"), children: /* @__PURE__ */ jsx4(SelectValue, {}) }),
|
|
1516
|
+
/* @__PURE__ */ jsxs3(SelectContent, { children: [
|
|
1517
|
+
/* @__PURE__ */ jsx4(SelectItem, { value: "private", children: t("shareVisibilityPrivate") }),
|
|
1518
|
+
/* @__PURE__ */ jsx4(SelectItem, { value: "tenant", children: t("shareVisibilityTenant") })
|
|
1519
|
+
] })
|
|
1520
|
+
]
|
|
1521
|
+
}
|
|
1522
|
+
)
|
|
1523
|
+
] }),
|
|
1524
|
+
canShare ? /* @__PURE__ */ jsxs3(Command2, { shouldFilter: false, className: "rounded-md border", children: [
|
|
1525
|
+
/* @__PURE__ */ jsx4(
|
|
1526
|
+
CommandInput2,
|
|
1527
|
+
{
|
|
1528
|
+
placeholder: t("shareSearch"),
|
|
1529
|
+
value: query,
|
|
1530
|
+
onValueChange: setQuery
|
|
1531
|
+
}
|
|
1532
|
+
),
|
|
1533
|
+
query.trim() !== "" ? /* @__PURE__ */ jsxs3(CommandList2, { children: [
|
|
1534
|
+
/* @__PURE__ */ jsx4(CommandEmpty2, { children: t("shareNoneFound") }),
|
|
1535
|
+
found.length > 0 ? /* @__PURE__ */ jsx4(CommandGroup, { heading: t("sharePeople"), children: found.map((member) => /* @__PURE__ */ jsx4(
|
|
1536
|
+
CommandItem2,
|
|
1537
|
+
{
|
|
1538
|
+
value: `user:${member.id}`,
|
|
1539
|
+
disabled: has("user", member.id) || member.id === owner,
|
|
1540
|
+
onSelect: () => add("user", member.id, member),
|
|
1541
|
+
children: /* @__PURE__ */ jsx4(Person, { member })
|
|
1542
|
+
},
|
|
1543
|
+
`user:${member.id}`
|
|
1544
|
+
)) }) : null,
|
|
1545
|
+
matchingRoles.length > 0 ? /* @__PURE__ */ jsx4(CommandGroup, { heading: t("shareRoles"), children: matchingRoles.map((role) => /* @__PURE__ */ jsxs3(
|
|
1546
|
+
CommandItem2,
|
|
1547
|
+
{
|
|
1548
|
+
value: `role:${role.code}`,
|
|
1549
|
+
disabled: has("role", role.code),
|
|
1550
|
+
onSelect: () => add("role", role.code),
|
|
1551
|
+
children: [
|
|
1552
|
+
/* @__PURE__ */ jsx4(Users, { className: "size-4" }),
|
|
1553
|
+
/* @__PURE__ */ jsx4("span", { className: "truncate", children: role.name })
|
|
1554
|
+
]
|
|
1555
|
+
},
|
|
1556
|
+
`role:${role.code}`
|
|
1557
|
+
)) }) : null
|
|
1558
|
+
] }) : null
|
|
1559
|
+
] }) : null,
|
|
1560
|
+
/* @__PURE__ */ jsxs3(
|
|
1561
|
+
"ul",
|
|
1562
|
+
{
|
|
1563
|
+
className: "flex max-h-72 flex-col gap-2 overflow-y-auto",
|
|
1564
|
+
"aria-label": t("shareWith"),
|
|
1565
|
+
children: [
|
|
1566
|
+
grants.length === 0 ? /* @__PURE__ */ jsx4("li", { className: "text-muted-foreground text-sm", children: t("shareNobody") }) : null,
|
|
1567
|
+
grants.map((grant) => /* @__PURE__ */ jsxs3(
|
|
1568
|
+
"li",
|
|
1569
|
+
{
|
|
1570
|
+
className: "flex items-center gap-2",
|
|
1571
|
+
children: [
|
|
1572
|
+
/* @__PURE__ */ jsx4("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: grant.principal_type === "user" ? /* @__PURE__ */ jsx4(
|
|
1573
|
+
Person,
|
|
1574
|
+
{
|
|
1575
|
+
member: people[grant.principal_id] ?? {
|
|
1576
|
+
id: grant.principal_id,
|
|
1577
|
+
name: nameOf(grant.principal_id),
|
|
1578
|
+
avatar: null
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
) : /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1582
|
+
/* @__PURE__ */ jsx4(Users, { className: "size-4 shrink-0" }),
|
|
1583
|
+
/* @__PURE__ */ jsx4("span", { className: "truncate text-sm", children: roleName(grant.principal_id) }),
|
|
1584
|
+
/* @__PURE__ */ jsx4(Badge2, { variant: "secondary", children: t("shareRole") })
|
|
1585
|
+
] }) }),
|
|
1586
|
+
/* @__PURE__ */ jsxs3(
|
|
1587
|
+
Select,
|
|
1588
|
+
{
|
|
1589
|
+
value: grant.level,
|
|
1590
|
+
disabled: !canShare || busy,
|
|
1591
|
+
onValueChange: (value) => setLevel(grant, value),
|
|
1592
|
+
children: [
|
|
1593
|
+
/* @__PURE__ */ jsx4(SelectTrigger, { className: "w-32", "aria-label": t("shareLevel"), children: /* @__PURE__ */ jsx4(SelectValue, {}) }),
|
|
1594
|
+
/* @__PURE__ */ jsx4(SelectContent, { children: LEVELS.map((level) => /* @__PURE__ */ jsx4(SelectItem, { value: level, children: t(`shareLevel_${level}`) }, level)) })
|
|
1595
|
+
]
|
|
1596
|
+
}
|
|
1597
|
+
),
|
|
1598
|
+
canTransfer && grant.principal_type === "user" && people[grant.principal_id] ? /* @__PURE__ */ jsx4(
|
|
1599
|
+
Button2,
|
|
1600
|
+
{
|
|
1601
|
+
variant: "ghost",
|
|
1602
|
+
size: "icon",
|
|
1603
|
+
disabled: busy || changed2,
|
|
1604
|
+
title: t("shareMakeOwner"),
|
|
1605
|
+
"aria-label": t("shareMakeOwner"),
|
|
1606
|
+
onClick: () => void makeOwner(grant.principal_id),
|
|
1607
|
+
children: /* @__PURE__ */ jsx4(Crown, {})
|
|
1608
|
+
}
|
|
1609
|
+
) : null,
|
|
1610
|
+
canShare ? /* @__PURE__ */ jsx4(
|
|
1611
|
+
Button2,
|
|
1612
|
+
{
|
|
1613
|
+
variant: "ghost",
|
|
1614
|
+
size: "icon",
|
|
1615
|
+
disabled: busy,
|
|
1616
|
+
"aria-label": t("shareRemove"),
|
|
1617
|
+
onClick: () => remove(grant),
|
|
1618
|
+
children: /* @__PURE__ */ jsx4(X, {})
|
|
1619
|
+
}
|
|
1620
|
+
) : null
|
|
1621
|
+
]
|
|
1622
|
+
},
|
|
1623
|
+
`${grant.principal_type}:${grant.principal_id}`
|
|
1624
|
+
))
|
|
1625
|
+
]
|
|
1626
|
+
}
|
|
1627
|
+
)
|
|
1628
|
+
] }) : null,
|
|
1629
|
+
failure ? /* @__PURE__ */ jsx4("p", { className: "text-destructive text-sm", children: failure }) : null,
|
|
1630
|
+
/* @__PURE__ */ jsxs3(DialogFooter2, { children: [
|
|
1631
|
+
/* @__PURE__ */ jsx4(Button2, { variant: "outline", onClick: () => setOpen(false), children: canShare ? t("cancel") : t("shareClose") }),
|
|
1632
|
+
canShare ? /* @__PURE__ */ jsx4(Button2, { disabled: !changed2 || busy, onClick: () => void save(), children: t("shareSave") }) : null
|
|
1633
|
+
] })
|
|
1634
|
+
] })
|
|
1635
|
+
] });
|
|
1636
|
+
}
|
|
1637
|
+
function Person(props) {
|
|
1638
|
+
const { member } = props;
|
|
1639
|
+
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1640
|
+
/* @__PURE__ */ jsxs3(Avatar2, { className: "size-6", children: [
|
|
1641
|
+
member.avatar ? /* @__PURE__ */ jsx4(AvatarImage, { src: member.avatar, alt: "" }) : null,
|
|
1642
|
+
/* @__PURE__ */ jsx4(AvatarFallback2, { className: "text-[10px]", children: initials(member.name) })
|
|
1643
|
+
] }),
|
|
1644
|
+
/* @__PURE__ */ jsx4("span", { className: "truncate text-sm", children: member.name })
|
|
1645
|
+
] });
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1265
1648
|
// src/index.ts
|
|
1266
1649
|
registerMessages2("web", { "en-US": en_US_default, "zh-CN": zh_CN_default });
|
|
1267
1650
|
export {
|
|
@@ -1275,6 +1658,7 @@ export {
|
|
|
1275
1658
|
NotFound,
|
|
1276
1659
|
PlatformProvider,
|
|
1277
1660
|
RETURN_TO_KEY,
|
|
1661
|
+
ShareDialog,
|
|
1278
1662
|
TENANT_STORAGE_KEY,
|
|
1279
1663
|
apiBaseUrl,
|
|
1280
1664
|
buildMenu,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zjazj/web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Browser runtime for platform apps: session, typed API client, layout shell, guards and hooks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@logto/browser": "^3.1.2",
|
|
28
28
|
"hono": "^4.13.17",
|
|
29
29
|
"lucide-react": "^0.545.0",
|
|
30
|
-
"@zjazj/
|
|
31
|
-
"@zjazj/
|
|
30
|
+
"@zjazj/ui": "^0.0.10",
|
|
31
|
+
"@zjazj/i18n": "^0.0.10"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@tanstack/react-query": "^5.90.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"jsdom": "^26.1.0",
|
|
46
46
|
"react": "^19.2.0",
|
|
47
47
|
"react-dom": "^19.2.0",
|
|
48
|
-
"@zjazj/server": "^0.0.
|
|
48
|
+
"@zjazj/server": "^0.0.10"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public",
|