vestrycms 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +383 -2
- package/dist/config/fields.d.ts +30 -0
- package/dist/config/fields.js +75 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +18 -0
- package/dist/config/types.d.ts +412 -0
- package/dist/config/types.js +10 -0
- package/dist/core/api.d.ts +67 -0
- package/dist/core/api.js +543 -0
- package/dist/core/auth.d.ts +1597 -0
- package/dist/core/auth.js +264 -0
- package/dist/core/cache.d.ts +27 -0
- package/dist/core/cache.js +52 -0
- package/dist/core/entries.d.ts +19 -0
- package/dist/core/entries.js +127 -0
- package/dist/core/index-types.d.ts +20 -0
- package/dist/core/index-types.js +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +13 -0
- package/dist/core/mail.d.ts +28 -0
- package/dist/core/mail.js +62 -0
- package/dist/core/paths.d.ts +35 -0
- package/dist/core/paths.js +148 -0
- package/dist/core/roles.d.ts +24 -0
- package/dist/core/roles.js +15 -0
- package/dist/core/service.d.ts +102 -0
- package/dist/core/service.js +478 -0
- package/dist/core/source.d.ts +82 -0
- package/dist/core/source.js +75 -0
- package/dist/core/sources/github-app.d.ts +26 -0
- package/dist/core/sources/github-app.js +161 -0
- package/dist/core/sources/github.d.ts +40 -0
- package/dist/core/sources/github.js +278 -0
- package/dist/core/sources/local.d.ts +16 -0
- package/dist/core/sources/local.js +98 -0
- package/dist/core/values.d.ts +22 -0
- package/dist/core/values.js +123 -0
- package/dist/env.d.ts +19 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +167 -0
- package/dist/integration/build-index.d.ts +8 -0
- package/dist/integration/build-index.js +67 -0
- package/dist/integration/client-deps.d.ts +10 -0
- package/dist/integration/client-deps.js +43 -0
- package/dist/integration/dev-middleware.d.ts +6 -0
- package/dist/integration/dev-middleware.js +48 -0
- package/dist/integration/formatter.d.ts +7 -0
- package/dist/integration/formatter.js +56 -0
- package/dist/mdx/expressions.d.ts +14 -0
- package/dist/mdx/expressions.js +141 -0
- package/dist/mdx/index.d.ts +4 -0
- package/dist/mdx/index.js +4 -0
- package/dist/mdx/parse.d.ts +6 -0
- package/dist/mdx/parse.js +401 -0
- package/dist/mdx/serialize.d.ts +9 -0
- package/dist/mdx/serialize.js +485 -0
- package/dist/mdx/types.d.ts +42 -0
- package/dist/mdx/types.js +6 -0
- package/dist/pages/admin.astro +27 -0
- package/dist/pages/api.d.ts +3 -0
- package/dist/pages/api.js +31 -0
- package/dist/ui/App.d.ts +4 -0
- package/dist/ui/App.js +70 -0
- package/dist/ui/api.d.ts +83 -0
- package/dist/ui/api.js +97 -0
- package/dist/ui/auth-client.d.ts +27 -0
- package/dist/ui/auth-client.js +29 -0
- package/dist/ui/components/AssetPicker.d.ts +27 -0
- package/dist/ui/components/AssetPicker.js +97 -0
- package/dist/ui/components/Icon.d.ts +11 -0
- package/dist/ui/components/Icon.js +46 -0
- package/dist/ui/components/Layout.d.ts +15 -0
- package/dist/ui/components/Layout.js +87 -0
- package/dist/ui/components/editor/EditorContext.d.ts +15 -0
- package/dist/ui/components/editor/EditorContext.js +9 -0
- package/dist/ui/components/editor/NodeViews.d.ts +4 -0
- package/dist/ui/components/editor/NodeViews.js +127 -0
- package/dist/ui/components/editor/RichTextEditor.d.ts +24 -0
- package/dist/ui/components/editor/RichTextEditor.js +230 -0
- package/dist/ui/components/editor/extensions.d.ts +30 -0
- package/dist/ui/components/editor/extensions.js +248 -0
- package/dist/ui/components/editor/schema.d.ts +12 -0
- package/dist/ui/components/editor/schema.js +37 -0
- package/dist/ui/components/fields/CodeInput.d.ts +10 -0
- package/dist/ui/components/fields/CodeInput.js +8 -0
- package/dist/ui/components/fields/CodeMirrorInput.d.ts +2 -0
- package/dist/ui/components/fields/CodeMirrorInput.js +44 -0
- package/dist/ui/components/fields/FieldRenderer.d.ts +41 -0
- package/dist/ui/components/fields/FieldRenderer.js +299 -0
- package/dist/ui/components/fields/ImageTools.d.ts +31 -0
- package/dist/ui/components/fields/ImageTools.js +296 -0
- package/dist/ui/components/fields/MarkdownField.d.ts +7 -0
- package/dist/ui/components/fields/MarkdownField.js +16 -0
- package/dist/ui/components/fields/TreeInput.d.ts +13 -0
- package/dist/ui/components/fields/TreeInput.js +221 -0
- package/dist/ui/components/ui.d.ts +63 -0
- package/dist/ui/components/ui.js +113 -0
- package/dist/ui/context.d.ts +17 -0
- package/dist/ui/context.js +13 -0
- package/dist/ui/lib/format.d.ts +5 -0
- package/dist/ui/lib/format.js +11 -0
- package/dist/ui/lib/utils.d.ts +24 -0
- package/dist/ui/lib/utils.js +255 -0
- package/dist/ui/main.d.ts +1 -0
- package/dist/ui/main.js +11 -0
- package/dist/ui/pages/Assets.d.ts +1 -0
- package/dist/ui/pages/Assets.js +69 -0
- package/dist/ui/pages/CollectionList.d.ts +6 -0
- package/dist/ui/pages/CollectionList.js +115 -0
- package/dist/ui/pages/Dashboard.d.ts +1 -0
- package/dist/ui/pages/Dashboard.js +57 -0
- package/dist/ui/pages/EntryEditor.d.ts +3 -0
- package/dist/ui/pages/EntryEditor.js +313 -0
- package/dist/ui/pages/Login.d.ts +6 -0
- package/dist/ui/pages/Login.js +88 -0
- package/dist/ui/pages/Users.d.ts +1 -0
- package/dist/ui/pages/Users.js +102 -0
- package/dist/ui/styles.css +2554 -0
- package/package.json +123 -3
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { Mail, MoreHorizontal, Plus, Trash2, UserCog } from "lucide-react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { Navigate } from "react-router";
|
|
6
|
+
import { ROLES } from "../../core/roles.js";
|
|
7
|
+
import { TopBar } from "../components/Layout.js";
|
|
8
|
+
import { Alert, Badge, Button, ConfirmDialog, EmptyState, Loading, Menu, Modal, Spinner, useToast, } from "../components/ui.js";
|
|
9
|
+
import { useVestry } from "../context.js";
|
|
10
|
+
import { formatDate, initials } from "../lib/utils.js";
|
|
11
|
+
export function UsersPage() {
|
|
12
|
+
const { api, client, refresh } = useVestry();
|
|
13
|
+
const toast = useToast();
|
|
14
|
+
const queryClient = useQueryClient();
|
|
15
|
+
const me = client.user;
|
|
16
|
+
const [inviting, setInviting] = useState(false);
|
|
17
|
+
const [editing, setEditing] = useState(null);
|
|
18
|
+
const [removing, setRemoving] = useState(null);
|
|
19
|
+
const q = useQuery({
|
|
20
|
+
queryKey: ["users"],
|
|
21
|
+
queryFn: () => api.listUsers(),
|
|
22
|
+
enabled: me.role === "admin" && client.auth,
|
|
23
|
+
});
|
|
24
|
+
const invalidate = () => queryClient.invalidateQueries({ queryKey: ["users"] });
|
|
25
|
+
const resend = useMutation({
|
|
26
|
+
mutationFn: (u) => api.resendInvite(u.id),
|
|
27
|
+
onSuccess: (_r, u) => toast("success", `Invitation re-sent to ${u.email}.`),
|
|
28
|
+
onError: (e) => toast("error", message(e)),
|
|
29
|
+
});
|
|
30
|
+
const remove = useMutation({
|
|
31
|
+
mutationFn: (u) => api.removeUser(u.id),
|
|
32
|
+
onSuccess: (_r, u) => {
|
|
33
|
+
toast("success", `${u.name} was removed.`);
|
|
34
|
+
setRemoving(null);
|
|
35
|
+
invalidate();
|
|
36
|
+
},
|
|
37
|
+
onError: (e) => toast("error", message(e)),
|
|
38
|
+
});
|
|
39
|
+
if (me.role !== "admin")
|
|
40
|
+
return _jsx(Navigate, { to: "/", replace: true });
|
|
41
|
+
const crumbs = [{ label: "Users" }];
|
|
42
|
+
const users = q.data?.users ?? [];
|
|
43
|
+
return (_jsxs(_Fragment, { children: [_jsx(TopBar, { title: "Users", crumbs: crumbs, actions: client.auth && (_jsxs(Button, { variant: "primary", onClick: () => setInviting(true), children: [_jsx(Plus, {}), " Invite user"] })) }), _jsx("div", { className: "v-page", children: !client.auth ? (_jsxs(Alert, { kind: "info", children: ["Sign-in is off in local mode, so there are no users to manage. Start the dev server with ", _jsx("code", { children: "VESTRY_MODE=auth" }), " to work on sign-in and users locally."] })) : q.isLoading ? (_jsx(Loading, { label: "Loading users\u2026" })) : q.error ? (_jsx(Alert, { kind: "error", children: message(q.error) })) : users.length === 0 ? (_jsx("div", { className: "v-card", children: _jsx(EmptyState, { icon: _jsx(UserCog, {}), title: "No users yet", children: _jsx("p", { children: "Invite the people who should be able to edit the site." }) }) })) : (_jsx("div", { className: "v-card", children: _jsx("div", { className: "v-table-wrap", children: _jsxs("table", { className: "v-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Name" }), _jsx("th", { children: "Role" }), _jsx("th", { children: "Status" }), _jsx("th", { children: "Last sign-in" }), _jsx("th", {})] }) }), _jsx("tbody", { children: users.map((u) => (_jsxs("tr", { children: [_jsx("td", { className: "v-table__main", children: _jsxs("span", { className: "v-user", children: [_jsx("span", { className: "v-avatar", "aria-hidden": true, children: initials(u.name || u.email) }), _jsxs("span", { className: "v-user__text", children: [_jsxs("span", { className: "v-table__title", children: [u.name, u.id === me.id && (_jsx("span", { className: "v-muted", children: " (you)" }))] }), _jsx("span", { className: "v-table__sub", children: u.email })] })] }) }), _jsxs("td", { style: { whiteSpace: "nowrap" }, children: [roleLabel(u.role), u.origin === "config" && (_jsxs("span", { className: "v-muted", title: "Listed in auth.admins in vestry.config", children: [" ", "\u00B7 config"] }))] }), _jsx("td", { children: u.status === "active" ? (_jsx(Badge, { status: "published", children: "Active" })) : (_jsx(Badge, { status: "draft", children: "Invited" })) }), _jsx("td", { className: "v-muted", style: { whiteSpace: "nowrap" }, children: u.lastLoginAt ? formatDate(u.lastLoginAt) : "—" }), _jsx("td", { className: "v-table__actions", children: _jsx(Menu, { align: "right", trigger: ({ toggle }) => (_jsx(Button, { variant: "ghost", size: "xs", icon: true, title: "Actions", onClick: toggle, children: _jsx(MoreHorizontal, {}) })), children: (close) => (_jsxs(_Fragment, { children: [_jsxs("button", { className: "v-menu__item", onClick: () => {
|
|
44
|
+
close();
|
|
45
|
+
setEditing(u);
|
|
46
|
+
}, children: [_jsx(UserCog, {}), _jsx("span", { children: "Edit name and role" })] }), u.status === "invited" && (_jsxs("button", { className: "v-menu__item", onClick: () => {
|
|
47
|
+
close();
|
|
48
|
+
resend.mutate(u);
|
|
49
|
+
}, children: [_jsx(Mail, {}), _jsx("span", { children: "Re-send invitation" })] })), u.id !== me.id && u.origin !== "config" && (_jsxs("button", { className: "v-menu__item v-menu__item--danger", onClick: () => {
|
|
50
|
+
close();
|
|
51
|
+
setRemoving(u);
|
|
52
|
+
}, children: [_jsx(Trash2, {}), _jsx("span", { children: "Remove" })] }))] })) }) })] }, u.id))) })] }) }) })) }), inviting && (_jsx(UserForm, { title: "Invite user", submitLabel: "Send invitation", onClose: () => setInviting(false), onSubmit: async (values) => {
|
|
53
|
+
const { user, mailError } = await api.inviteUser(values);
|
|
54
|
+
if (mailError) {
|
|
55
|
+
toast("error", `${user.name} was added, but the invitation email failed: ${mailError}. Use "Re-send invitation" once email is working.`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
toast("success", `Invitation sent to ${user.email}.`);
|
|
59
|
+
}
|
|
60
|
+
setInviting(false);
|
|
61
|
+
invalidate();
|
|
62
|
+
} })), editing && (_jsx(UserForm, { title: `Edit ${editing.name}`, submitLabel: "Save", user: editing, onClose: () => setEditing(null), onSubmit: async (values) => {
|
|
63
|
+
await api.updateUser(editing.id, {
|
|
64
|
+
name: values.name,
|
|
65
|
+
role: values.role,
|
|
66
|
+
});
|
|
67
|
+
toast("success", "User updated.");
|
|
68
|
+
setEditing(null);
|
|
69
|
+
invalidate();
|
|
70
|
+
if (editing.id === me.id)
|
|
71
|
+
await refresh();
|
|
72
|
+
} })), removing && (_jsx(ConfirmDialog, { title: `Remove ${removing.name}?`, message: `${removing.email} will no longer be able to sign in. Content they created stays as it is.`, confirmLabel: "Remove", danger: true, busy: remove.isPending, onCancel: () => setRemoving(null), onConfirm: () => remove.mutate(removing) }))] }));
|
|
73
|
+
}
|
|
74
|
+
function UserForm({ title, submitLabel, user, onClose, onSubmit, }) {
|
|
75
|
+
const [email, setEmail] = useState(user?.email ?? "");
|
|
76
|
+
const [name, setName] = useState(user?.name ?? "");
|
|
77
|
+
const [role, setRole] = useState(user?.role ?? "editor");
|
|
78
|
+
const [busy, setBusy] = useState(false);
|
|
79
|
+
const [error, setError] = useState(null);
|
|
80
|
+
const roleLocked = user?.origin === "config";
|
|
81
|
+
async function submit(e) {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
setBusy(true);
|
|
84
|
+
setError(null);
|
|
85
|
+
try {
|
|
86
|
+
await onSubmit({ email, name, role });
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
setError(message(err));
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
setBusy(false);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return (_jsx(Modal, { title: title, onClose: onClose, footer: _jsxs(_Fragment, { children: [_jsx(Button, { onClick: onClose, disabled: busy, children: "Cancel" }), _jsxs(Button, { variant: "primary", type: "submit", form: "v-user-form", disabled: busy || (!user && !email), children: [busy ? _jsx(Spinner, {}) : null, submitLabel] })] }), children: _jsxs("form", { id: "v-user-form", onSubmit: submit, className: "v-fields", children: [!user && (_jsxs("label", { className: "v-field", children: [_jsx("span", { className: "v-field__label", children: "Email" }), _jsx("input", { className: "v-input", type: "email", autoFocus: true, required: true, value: email, onChange: (e) => setEmail(e.target.value), placeholder: "colleague@example.org" }), _jsx("span", { className: "v-field__hint", children: "They'll get an email with a link to sign in. No password needed: we email a code each time." })] })), _jsxs("label", { className: "v-field", children: [_jsx("span", { className: "v-field__label", children: "Name" }), _jsx("input", { className: "v-input", type: "text", autoFocus: !!user, value: name, onChange: (e) => setName(e.target.value), placeholder: user ? undefined : "Optional" })] }), _jsxs("div", { className: "v-field", children: [_jsx("span", { className: "v-field__label", children: "Role" }), _jsx("div", { className: "v-radio-cards", children: ROLES.map((r) => (_jsxs("label", { className: `v-radio-card${role === r.value ? " is-selected" : ""}${roleLocked ? " is-disabled" : ""}`, children: [_jsx("input", { type: "radio", name: "role", value: r.value, checked: role === r.value, disabled: roleLocked, onChange: () => setRole(r.value) }), _jsxs("span", { className: "v-radio-card__body", children: [_jsx("span", { className: "v-radio-card__label", children: r.label }), _jsx("span", { className: "v-radio-card__desc", children: r.description })] })] }, r.value))) }), roleLocked && (_jsxs("span", { className: "v-field__hint", children: ["This address is listed in ", _jsx("code", { children: "auth.admins" }), " in the Vestry config, so it is always an admin."] }))] }), error && _jsx(Alert, { kind: "error", children: error })] }) }));
|
|
96
|
+
}
|
|
97
|
+
function roleLabel(role) {
|
|
98
|
+
return ROLES.find((r) => r.value === role)?.label ?? role;
|
|
99
|
+
}
|
|
100
|
+
function message(e) {
|
|
101
|
+
return e instanceof Error ? e.message : String(e);
|
|
102
|
+
}
|