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.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +383 -2
  3. package/dist/config/fields.d.ts +30 -0
  4. package/dist/config/fields.js +75 -0
  5. package/dist/config/index.d.ts +9 -0
  6. package/dist/config/index.js +18 -0
  7. package/dist/config/types.d.ts +412 -0
  8. package/dist/config/types.js +10 -0
  9. package/dist/core/api.d.ts +67 -0
  10. package/dist/core/api.js +543 -0
  11. package/dist/core/auth.d.ts +1597 -0
  12. package/dist/core/auth.js +264 -0
  13. package/dist/core/cache.d.ts +27 -0
  14. package/dist/core/cache.js +52 -0
  15. package/dist/core/entries.d.ts +19 -0
  16. package/dist/core/entries.js +127 -0
  17. package/dist/core/index-types.d.ts +20 -0
  18. package/dist/core/index-types.js +1 -0
  19. package/dist/core/index.d.ts +13 -0
  20. package/dist/core/index.js +13 -0
  21. package/dist/core/mail.d.ts +28 -0
  22. package/dist/core/mail.js +62 -0
  23. package/dist/core/paths.d.ts +35 -0
  24. package/dist/core/paths.js +148 -0
  25. package/dist/core/roles.d.ts +24 -0
  26. package/dist/core/roles.js +15 -0
  27. package/dist/core/service.d.ts +102 -0
  28. package/dist/core/service.js +478 -0
  29. package/dist/core/source.d.ts +82 -0
  30. package/dist/core/source.js +75 -0
  31. package/dist/core/sources/github-app.d.ts +26 -0
  32. package/dist/core/sources/github-app.js +161 -0
  33. package/dist/core/sources/github.d.ts +40 -0
  34. package/dist/core/sources/github.js +278 -0
  35. package/dist/core/sources/local.d.ts +16 -0
  36. package/dist/core/sources/local.js +98 -0
  37. package/dist/core/values.d.ts +22 -0
  38. package/dist/core/values.js +123 -0
  39. package/dist/env.d.ts +19 -0
  40. package/dist/index.d.ts +18 -0
  41. package/dist/index.js +167 -0
  42. package/dist/integration/build-index.d.ts +8 -0
  43. package/dist/integration/build-index.js +67 -0
  44. package/dist/integration/client-deps.d.ts +10 -0
  45. package/dist/integration/client-deps.js +43 -0
  46. package/dist/integration/dev-middleware.d.ts +6 -0
  47. package/dist/integration/dev-middleware.js +48 -0
  48. package/dist/integration/formatter.d.ts +7 -0
  49. package/dist/integration/formatter.js +56 -0
  50. package/dist/mdx/expressions.d.ts +14 -0
  51. package/dist/mdx/expressions.js +141 -0
  52. package/dist/mdx/index.d.ts +4 -0
  53. package/dist/mdx/index.js +4 -0
  54. package/dist/mdx/parse.d.ts +6 -0
  55. package/dist/mdx/parse.js +401 -0
  56. package/dist/mdx/serialize.d.ts +9 -0
  57. package/dist/mdx/serialize.js +485 -0
  58. package/dist/mdx/types.d.ts +42 -0
  59. package/dist/mdx/types.js +6 -0
  60. package/dist/pages/admin.astro +27 -0
  61. package/dist/pages/api.d.ts +3 -0
  62. package/dist/pages/api.js +31 -0
  63. package/dist/ui/App.d.ts +4 -0
  64. package/dist/ui/App.js +70 -0
  65. package/dist/ui/api.d.ts +83 -0
  66. package/dist/ui/api.js +97 -0
  67. package/dist/ui/auth-client.d.ts +27 -0
  68. package/dist/ui/auth-client.js +29 -0
  69. package/dist/ui/components/AssetPicker.d.ts +27 -0
  70. package/dist/ui/components/AssetPicker.js +97 -0
  71. package/dist/ui/components/Icon.d.ts +11 -0
  72. package/dist/ui/components/Icon.js +46 -0
  73. package/dist/ui/components/Layout.d.ts +15 -0
  74. package/dist/ui/components/Layout.js +87 -0
  75. package/dist/ui/components/editor/EditorContext.d.ts +15 -0
  76. package/dist/ui/components/editor/EditorContext.js +9 -0
  77. package/dist/ui/components/editor/NodeViews.d.ts +4 -0
  78. package/dist/ui/components/editor/NodeViews.js +127 -0
  79. package/dist/ui/components/editor/RichTextEditor.d.ts +24 -0
  80. package/dist/ui/components/editor/RichTextEditor.js +230 -0
  81. package/dist/ui/components/editor/extensions.d.ts +30 -0
  82. package/dist/ui/components/editor/extensions.js +248 -0
  83. package/dist/ui/components/editor/schema.d.ts +12 -0
  84. package/dist/ui/components/editor/schema.js +37 -0
  85. package/dist/ui/components/fields/CodeInput.d.ts +10 -0
  86. package/dist/ui/components/fields/CodeInput.js +8 -0
  87. package/dist/ui/components/fields/CodeMirrorInput.d.ts +2 -0
  88. package/dist/ui/components/fields/CodeMirrorInput.js +44 -0
  89. package/dist/ui/components/fields/FieldRenderer.d.ts +41 -0
  90. package/dist/ui/components/fields/FieldRenderer.js +299 -0
  91. package/dist/ui/components/fields/ImageTools.d.ts +31 -0
  92. package/dist/ui/components/fields/ImageTools.js +296 -0
  93. package/dist/ui/components/fields/MarkdownField.d.ts +7 -0
  94. package/dist/ui/components/fields/MarkdownField.js +16 -0
  95. package/dist/ui/components/fields/TreeInput.d.ts +13 -0
  96. package/dist/ui/components/fields/TreeInput.js +221 -0
  97. package/dist/ui/components/ui.d.ts +63 -0
  98. package/dist/ui/components/ui.js +113 -0
  99. package/dist/ui/context.d.ts +17 -0
  100. package/dist/ui/context.js +13 -0
  101. package/dist/ui/lib/format.d.ts +5 -0
  102. package/dist/ui/lib/format.js +11 -0
  103. package/dist/ui/lib/utils.d.ts +24 -0
  104. package/dist/ui/lib/utils.js +255 -0
  105. package/dist/ui/main.d.ts +1 -0
  106. package/dist/ui/main.js +11 -0
  107. package/dist/ui/pages/Assets.d.ts +1 -0
  108. package/dist/ui/pages/Assets.js +69 -0
  109. package/dist/ui/pages/CollectionList.d.ts +6 -0
  110. package/dist/ui/pages/CollectionList.js +115 -0
  111. package/dist/ui/pages/Dashboard.d.ts +1 -0
  112. package/dist/ui/pages/Dashboard.js +57 -0
  113. package/dist/ui/pages/EntryEditor.d.ts +3 -0
  114. package/dist/ui/pages/EntryEditor.js +313 -0
  115. package/dist/ui/pages/Login.d.ts +6 -0
  116. package/dist/ui/pages/Login.js +88 -0
  117. package/dist/ui/pages/Users.d.ts +1 -0
  118. package/dist/ui/pages/Users.js +102 -0
  119. package/dist/ui/styles.css +2554 -0
  120. 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
+ }