smoodly 0.0.23 → 0.0.25

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 (135) hide show
  1. package/README.md +192 -43
  2. package/bin/smoodly.js +6 -0
  3. package/dist/admin/auth.d.ts +10 -5
  4. package/dist/admin/auth.js +14 -13
  5. package/dist/admin/client-ops.js +2 -1
  6. package/dist/admin/editor/EditorView.js +20 -6
  7. package/dist/admin/editor/InsertPicker.d.ts +14 -0
  8. package/dist/admin/editor/InsertPicker.js +37 -7
  9. package/dist/admin/editor/InspectorFields.js +1 -1
  10. package/dist/admin/editor/Outline.js +2 -2
  11. package/dist/admin/editor/PageSettings.js +6 -0
  12. package/dist/admin/editor/SeoSettings.js +1 -1
  13. package/dist/admin/editor/locale-url.d.ts +7 -4
  14. package/dist/admin/editor/locale-url.js +14 -7
  15. package/dist/admin/editor/usePageLocale.js +9 -1
  16. package/dist/admin/forms/CropEditor.d.ts +4 -2
  17. package/dist/admin/forms/CropEditor.js +6 -3
  18. package/dist/admin/forms/DatePicker.d.ts +9 -0
  19. package/dist/admin/forms/DatePicker.js +133 -0
  20. package/dist/admin/forms/FieldWidget.js +11 -5
  21. package/dist/admin/forms/ImagePreview.d.ts +9 -0
  22. package/dist/admin/forms/ImagePreview.js +11 -0
  23. package/dist/admin/forms/MediaWidget.d.ts +8 -2
  24. package/dist/admin/forms/MediaWidget.js +13 -13
  25. package/dist/admin/forms/RichtextElementCard.js +1 -1
  26. package/dist/admin/forms/RichtextImageCard.js +14 -9
  27. package/dist/admin/forms/date-picker.d.ts +44 -0
  28. package/dist/admin/forms/date-picker.js +117 -0
  29. package/dist/admin/forms/elements-context.d.ts +3 -0
  30. package/dist/admin/forms/elements-context.js +7 -2
  31. package/dist/admin/forms/time-zone-context.d.ts +7 -0
  32. package/dist/admin/forms/time-zone-context.js +15 -0
  33. package/dist/admin/forms/useRichtextEditor.js +10 -1
  34. package/dist/admin/index.d.ts +2 -0
  35. package/dist/admin/next/bridge.d.ts +2 -1
  36. package/dist/admin/next/bridge.js +35 -5
  37. package/dist/admin/next/index.d.ts +2 -0
  38. package/dist/admin/ops-impl.js +73 -1
  39. package/dist/admin/ops.d.ts +22 -2
  40. package/dist/admin/serialize.d.ts +2 -0
  41. package/dist/admin/serialize.js +1 -0
  42. package/dist/admin/shell/AdminApp.js +48 -3
  43. package/dist/admin/shell/EntriesList.js +12 -21
  44. package/dist/admin/shell/EntryForm.js +63 -5
  45. package/dist/admin/shell/GlobalForm.js +22 -2
  46. package/dist/admin/shell/GlobalList.js +4 -18
  47. package/dist/admin/shell/IconRail.d.ts +3 -1
  48. package/dist/admin/shell/IconRail.js +17 -7
  49. package/dist/admin/shell/InviteModal.d.ts +6 -0
  50. package/dist/admin/shell/InviteModal.js +28 -0
  51. package/dist/admin/shell/ListView.js +2 -2
  52. package/dist/admin/shell/LoginView.js +34 -5
  53. package/dist/admin/shell/MediaScreen.js +11 -1
  54. package/dist/admin/shell/MembersPage.d.ts +2 -1
  55. package/dist/admin/shell/MembersPage.js +90 -25
  56. package/dist/admin/shell/PageDialogs.d.ts +26 -0
  57. package/dist/admin/shell/PageDialogs.js +38 -0
  58. package/dist/admin/shell/PagesList.js +100 -70
  59. package/dist/admin/shell/RouteLink.js +1 -1
  60. package/dist/admin/shell/SchemaNotice.d.ts +4 -0
  61. package/dist/admin/shell/SchemaNotice.js +4 -0
  62. package/dist/admin/shell/SetPasswordView.d.ts +7 -0
  63. package/dist/admin/shell/SetPasswordView.js +41 -0
  64. package/dist/admin/shell/SettingsView.d.ts +5 -1
  65. package/dist/admin/shell/SettingsView.js +17 -11
  66. package/dist/admin/shell/live-url.d.ts +10 -0
  67. package/dist/admin/shell/live-url.js +19 -0
  68. package/dist/admin/shell/locale-memory.d.ts +8 -0
  69. package/dist/admin/shell/locale-memory.js +23 -0
  70. package/dist/admin/shell/members-list.d.ts +15 -1
  71. package/dist/admin/shell/members-list.js +24 -7
  72. package/dist/admin/shell/page-dialogs.d.ts +9 -0
  73. package/dist/admin/shell/page-dialogs.js +19 -0
  74. package/dist/admin/shell/router.d.ts +10 -7
  75. package/dist/admin/shell/router.js +18 -9
  76. package/dist/admin/shell/session.d.ts +6 -0
  77. package/dist/admin/shell/session.js +17 -2
  78. package/dist/admin/shell/settings.d.ts +0 -6
  79. package/dist/admin/shell/settings.js +4 -5
  80. package/dist/admin/supabase-auth.js +6 -5
  81. package/dist/admin/tree-ops.js +3 -0
  82. package/dist/admin/ui/ActionMenu.js +26 -6
  83. package/dist/admin/ui/Combobox.d.ts +5 -0
  84. package/dist/admin/ui/Combobox.js +1 -1
  85. package/dist/admin/ui/ConfirmDialog.d.ts +8 -0
  86. package/dist/admin/ui/ConfirmDialog.js +30 -0
  87. package/dist/admin/ui/Dialog.d.ts +13 -0
  88. package/dist/admin/ui/Dialog.js +54 -0
  89. package/dist/admin/ui/HistoryModal.d.ts +2 -1
  90. package/dist/admin/ui/HistoryModal.js +7 -2
  91. package/dist/admin/ui/ResizeHandle.js +4 -4
  92. package/dist/admin/ui/confirm.d.ts +35 -0
  93. package/dist/admin/ui/confirm.js +57 -0
  94. package/dist/admin/ui/primitives.d.ts +19 -4
  95. package/dist/admin/ui/primitives.js +11 -5
  96. package/dist/admin/ui/resize.d.ts +7 -4
  97. package/dist/admin/ui/resize.js +7 -4
  98. package/dist/admin/ui/theme.d.ts +1 -1
  99. package/dist/admin/ui/theme.js +368 -203
  100. package/dist/admin/validate.d.ts +4 -0
  101. package/dist/admin/validate.js +28 -0
  102. package/dist/cli/load-collections.d.ts +2 -0
  103. package/dist/cli/load-collections.js +26 -0
  104. package/dist/cli/main.d.ts +13 -0
  105. package/dist/cli/main.js +62 -0
  106. package/dist/cli/migrate.d.ts +23 -0
  107. package/dist/cli/migrate.js +64 -0
  108. package/dist/config.d.ts +4 -0
  109. package/dist/config.js +9 -0
  110. package/dist/fields.d.ts +2 -0
  111. package/dist/fields.js +2 -0
  112. package/dist/index.d.ts +6 -3
  113. package/dist/index.js +4 -2
  114. package/dist/marks.d.ts +3 -0
  115. package/dist/marks.js +3 -0
  116. package/dist/member-store.d.ts +30 -1
  117. package/dist/member-store.js +37 -6
  118. package/dist/migrations.d.ts +37 -0
  119. package/dist/migrations.js +73 -0
  120. package/dist/permissions.d.ts +7 -0
  121. package/dist/permissions.js +19 -0
  122. package/dist/schema-version.d.ts +17 -0
  123. package/dist/schema-version.js +32 -0
  124. package/dist/sql-space.js +6 -0
  125. package/dist/sql.js +10 -0
  126. package/dist/store.d.ts +3 -0
  127. package/dist/store.js +4 -0
  128. package/dist/supabase-member-store.d.ts +8 -1
  129. package/dist/supabase-member-store.js +62 -2
  130. package/dist/supabase-store.d.ts +3 -0
  131. package/dist/supabase-store.js +23 -0
  132. package/dist/time-zone.d.ts +6 -0
  133. package/dist/time-zone.js +27 -0
  134. package/migrations/20260926120000_smoodly_v1.sql +535 -0
  135. package/package.json +13 -3
@@ -1,36 +1,101 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  // packages/smoodly/src/admin/shell/MembersPage.tsx
4
- // The Members page (spec 2026-09-25 §7): the admission table, read-only
5
- // in this cut — Email and Role, no actions, no row click. A console URL
6
- // from the op means smoodly.io manages the rows, and a banner under the
7
- // top bar says so.
4
+ // The Members page (spec 2026-09-25 §7; management §4): the admission
5
+ // table with Invite, the role as a badge and a row menu with Change role
6
+ // (to the other role, after a confirm) and Remove member (2026-09-26; the
7
+ // in-place pills before) — all off when the control plane manages the
8
+ // space (the console URL banner stays). Own row and the last admin render
9
+ // their menu disabled with the guard's reason, so the rule is visible
10
+ // before it is hit.
8
11
  import { useEffect, useState } from "react";
9
- import { Banner, StatusBadge } from "../ui/primitives.js";
12
+ import { ActionMenu } from "../ui/ActionMenu.js";
13
+ import { Banner, Button, StatusBadge } from "../ui/primitives.js";
14
+ import { confirm } from "../ui/confirm.js";
10
15
  import { ErrorPane } from "./ErrorPane.js";
16
+ import { InviteModal } from "./InviteModal.js";
11
17
  import { ListView } from "./ListView.js";
12
- import { memberRows } from "./members-list.js";
13
- export function MembersPage({ ops, initial = null }) {
18
+ import { GUARD_TITLE, ROLE_DESCRIPTION, memberRows, roleLabel } from "./members-list.js";
19
+ export function MembersPage({ ops, userId, initial = null }) {
14
20
  const [data, setData] = useState(initial);
15
21
  const [error, setError] = useState(null);
16
- useEffect(() => {
17
- if (initial)
22
+ const [notice, setNotice] = useState(null);
23
+ const [inviting, setInviting] = useState(false);
24
+ const load = () => ops.members.list()
25
+ .then((r) => (r.ok ? setData(r.data) : setError(r.message)))
26
+ .catch(() => setError("Couldn't reach the server."));
27
+ useEffect(() => { if (!initial)
28
+ void load(); }, [ops, initial]); // eslint-disable-line react-hooks/exhaustive-deps
29
+ const invite = async (input) => {
30
+ // The admin's own origin and mount: /settings/… stripped, so the invite lands on the shell.
31
+ const redirectTo = window.location.origin + window.location.pathname.replace(/\/settings(\/.*)?$/, "");
32
+ const r = await ops.members.invite({ ...input, redirectTo });
33
+ if (!r.ok)
34
+ return r.message;
35
+ setInviting(false);
36
+ setNotice({
37
+ tone: "ok",
38
+ text: r.data.invited ? `Invite sent to ${input.email}.` : `${input.email} added — they can sign in with their existing account.`,
39
+ });
40
+ void load();
41
+ return null;
42
+ };
43
+ /** Two roles: the change is to the other one, confirmed with what it may do. */
44
+ const changeRole = async (row) => {
45
+ const role = row.value === "admin" ? "editor" : "admin";
46
+ const ok = await confirm({
47
+ title: `Change role to ${roleLabel(role).toLowerCase()}?`,
48
+ body: `${roleLabel(role)}: ${ROLE_DESCRIPTION[role]}`,
49
+ confirmLabel: "Change role",
50
+ subject: { name: row.email },
51
+ });
52
+ if (!ok)
18
53
  return;
19
- ops.members.list()
20
- .then((r) => (r.ok ? setData(r.data) : setError(r.message)))
21
- .catch(() => setError("Couldn't reach the server."));
22
- }, [ops, initial]);
54
+ const r = await ops.members.setRole(row.key, role);
55
+ if (!r.ok) {
56
+ setNotice({ tone: "error", text: r.message });
57
+ return;
58
+ }
59
+ setData((d) => d && { ...d, members: d.members.map((m) => (m.userId === row.key ? r.data : m)) });
60
+ };
61
+ const remove = async (row) => {
62
+ const ok = await confirm({
63
+ title: "Remove this member?",
64
+ body: "They keep their account and lose access to this site's admin. You can invite them again later.",
65
+ confirmLabel: "Remove member",
66
+ destructive: true,
67
+ subject: { name: row.email },
68
+ });
69
+ if (!ok)
70
+ return;
71
+ const r = await ops.members.remove(row.key);
72
+ if (!r.ok) {
73
+ setNotice({ tone: "error", text: r.message });
74
+ return;
75
+ }
76
+ void load();
77
+ };
23
78
  if (error)
24
79
  return _jsx(ErrorPane, { message: error });
25
- const rows = data ? memberRows(data.members) : [];
26
- return (_jsx(ListView, { title: "Members", notice: data?.consoleUrl && (_jsxs(Banner, { tone: "ok", children: ["Members are managed at smoodly.io.", " ", _jsx("a", { href: data.consoleUrl, target: "_blank", rel: "noreferrer", children: "Open the console" })] })), columns: [
27
- { label: "Email", width: "minmax(200px,1fr)" },
28
- { label: "Role", width: "120px" },
29
- ], rows: rows.map((r) => ({
30
- key: r.key,
31
- cells: [
32
- r.fallback ? _jsx("span", { style: { color: "var(--text-muted)" }, children: r.email }) : r.email,
33
- _jsx(StatusBadge, { status: r.role }),
34
- ],
35
- })), empty: "No members yet" }));
80
+ const managed = Boolean(data?.consoleUrl);
81
+ const rows = data ? memberRows(data.members, { me: userId }) : [];
82
+ const guardTitle = (r) => (r.own ? GUARD_TITLE.own : r.lastAdmin ? GUARD_TITLE.lastAdmin : undefined);
83
+ return (_jsxs(_Fragment, { children: [_jsx(ListView, { title: "Members", actions: !managed && data && _jsx(Button, { onClick: () => setInviting(true), children: "Invite" }), notice: _jsxs(_Fragment, { children: [data?.consoleUrl && (_jsxs(Banner, { tone: "ok", children: ["Members are managed at smoodly.io.", " ", _jsx("a", { href: data.consoleUrl, target: "_blank", rel: "noreferrer", children: "Open the console" })] })), notice && _jsx(Banner, { tone: notice.tone, onDismiss: () => setNotice(null), children: notice.text })] }), columns: [
84
+ { label: "Email", width: "minmax(200px,1fr)" },
85
+ { label: "Role", width: "120px" },
86
+ ...(managed ? [] : [{ label: "", width: "48px" }]),
87
+ ], rows: rows.map((r) => ({
88
+ key: r.key,
89
+ cells: [
90
+ r.fallback ? _jsx("span", { style: { color: "var(--text-muted)" }, children: r.email }) : r.email,
91
+ _jsx(StatusBadge, { status: r.role }),
92
+ ...(managed ? [] : [
93
+ // ActionMenu has no title of its own when disabled: the span carries the guard's reason.
94
+ _jsx("span", { title: guardTitle(r), children: _jsx(ActionMenu, { label: "Member actions", small: true, disabled: r.own || r.lastAdmin, items: [
95
+ { label: "Change role", run: () => void changeRole(r) },
96
+ { label: "Remove member", danger: true, run: () => void remove(r) },
97
+ ] }) }),
98
+ ]),
99
+ ],
100
+ })), empty: "No members yet" }), inviting && _jsx(InviteModal, { onClose: () => setInviting(false), onInvite: invite })] }));
36
101
  }
@@ -0,0 +1,26 @@
1
+ import { type ReactElement } from "react";
2
+ import type { AdminPageTemplate } from "../serialize.ts";
3
+ export type PageFormValues = {
4
+ title: string;
5
+ slug: string;
6
+ template: string | null;
7
+ };
8
+ export declare function PageFormDialog({ title: heading, submitLabel, fields, templates, parentPath, initial, onClose, onSubmit }: {
9
+ /** The dialog's heading ("New page", "Rename page"). */
10
+ title: string;
11
+ submitLabel: string;
12
+ /** Which fields the dialog shows. */
13
+ fields: {
14
+ title?: boolean;
15
+ slug?: boolean;
16
+ template?: boolean;
17
+ };
18
+ /** The open page registrations, for the page-type select (shown when `fields.template` and there is more than one). */
19
+ templates?: AdminPageTemplate[];
20
+ /** The parent's path, shown before the slug ("/company/"); the root's is "/". */
21
+ parentPath?: string;
22
+ initial?: Partial<PageFormValues>;
23
+ onClose(): void;
24
+ /** Resolves to an error message, or null when the op landed (the caller closes). */
25
+ onSubmit(values: PageFormValues): Promise<string | null>;
26
+ }): ReactElement;
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ // The Pages list's form dialogs on the dialog card (ui/Dialog.tsx), in
4
+ // place of window.prompt (2026-09-25): New page / New path / New subpage
5
+ // / New subpath (a title, a slug that follows the title until edited, the
6
+ // page type when more than one open registration exists), Add page here
7
+ // (the page type alone) and Rename (title and slug; the home page's title
8
+ // alone, its slug being the config's). Enter submits; the op's error
9
+ // shows inside; success closes it from the caller.
10
+ import { useId, useState } from "react";
11
+ import { DialogCard } from "../ui/Dialog.js";
12
+ import { Banner, Button, Field } from "../ui/primitives.js";
13
+ import { followsTitle, slugify } from "./page-dialogs.js";
14
+ export function PageFormDialog({ title: heading, submitLabel, fields, templates = [], parentPath, initial, onClose, onSubmit }) {
15
+ const [values, setValues] = useState({
16
+ title: initial?.title ?? "",
17
+ slug: initial?.slug ?? "",
18
+ template: initial?.template ?? (templates[0]?.name ?? null),
19
+ });
20
+ const [error, setError] = useState(null);
21
+ const [busy, setBusy] = useState(false);
22
+ const chooseTemplate = fields.template && templates.length > 1;
23
+ const prefix = parentPath === undefined ? undefined : parentPath === "/" ? "/" : `${parentPath}/`;
24
+ const setTitle = (title) => setValues((v) => ({ ...v, title, slug: fields.slug && followsTitle(v.slug, v.title) ? slugify(title) : v.slug }));
25
+ const submit = async (e) => {
26
+ e.preventDefault();
27
+ if (busy)
28
+ return;
29
+ setError(null);
30
+ setBusy(true);
31
+ setError(await onSubmit({ ...values, title: values.title.trim(), slug: values.slug.trim() }));
32
+ setBusy(false);
33
+ };
34
+ const formId = `sm-page-form${useId()}`;
35
+ return (_jsx(DialogCard, { title: heading, onClose: onClose, actions: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "secondary", onClick: onClose, children: "Cancel" }), _jsx("button", { type: "submit", form: formId, className: "sm-btn sm-btn--primary", disabled: busy, children: busy ? "Saving…" : submitLabel })] }), children: _jsxs("form", { id: formId, className: "sm-dialog__form", onSubmit: submit, children: [fields.title && (_jsx(Field, { label: "Title", children: _jsx("input", { className: "sm-input", required: true, autoFocus: true, value: values.title, onChange: (e) => setTitle(e.target.value) }) })), fields.slug && (_jsx(Field, { label: "Slug", hint: "The URL segment: lowercase letters, digits and hyphens.", children: prefix
36
+ ? (_jsxs("span", { className: "sm-inputwrap", children: [_jsx("span", { className: "sm-prefix", children: prefix }), _jsx("input", { className: "sm-input sm-input--mono", required: true, autoFocus: !fields.title, value: values.slug, onChange: (e) => setValues((v) => ({ ...v, slug: e.target.value })) })] }))
37
+ : (_jsx("input", { className: "sm-input sm-input--mono", required: true, autoFocus: !fields.title, value: values.slug, onChange: (e) => setValues((v) => ({ ...v, slug: e.target.value })) })) })), chooseTemplate && (_jsx(Field, { label: "Page type", children: _jsx("select", { className: "sm-select", autoFocus: !fields.title && !fields.slug, value: values.template ?? "", onChange: (e) => setValues((v) => ({ ...v, template: e.target.value })), children: templates.map((t) => _jsx("option", { value: t.name, children: t.title }, t.name)) }) })), error && _jsx(Banner, { tone: "error", children: error })] }) }));
38
+ }
@@ -17,34 +17,22 @@ import { useSortable } from "../ui/useSortable.js";
17
17
  import { useAdminHref } from "./base.js";
18
18
  import { navigate } from "./router.js";
19
19
  import { ErrorPane } from "./ErrorPane.js";
20
- const LOCALE_KEY = "smoodly.pages.locale";
21
- /** The selected locale survives a reload within the session; a stored
22
- * value that is no longer supported falls back to the default. */
23
- function rememberedLocale(registry) {
24
- try {
25
- const stored = window.sessionStorage.getItem(LOCALE_KEY);
26
- if (stored && registry.locales.supported.includes(stored))
27
- return stored;
28
- }
29
- catch {
30
- // storage unavailable (private mode, no window) — the default is fine
31
- }
32
- return registry.locales.default;
33
- }
20
+ import { rememberLocale, rememberedLocale } from "./locale-memory.js";
21
+ import { confirmLiveUrl } from "./live-url.js";
22
+ import { confirm } from "../ui/confirm.js";
23
+ import { PageFormDialog } from "./PageDialogs.js";
34
24
  export function PagesList({ ops, registry }) {
35
25
  const adminHref = useAdminHref();
36
26
  const [pages, setPages] = useState(null);
37
27
  const [error, setError] = useState(null);
38
28
  const [collapsed, setCollapsed] = useState(() => new Set());
39
29
  const [menu, setMenu] = useState(null);
40
- const [locale, setLocale] = useState(() => rememberedLocale(registry));
30
+ const [dialog, setDialog] = useState(null);
31
+ const [locale, setLocale] = useState(() => rememberedLocale(registry.locales));
41
32
  const multilingual = registry.locales.supported.length > 1;
42
33
  const pickLocale = (next) => {
43
34
  setLocale(next);
44
- try {
45
- window.sessionStorage.setItem(LOCALE_KEY, next);
46
- }
47
- catch { /* see rememberedLocale */ }
35
+ rememberLocale(next);
48
36
  };
49
37
  const load = useCallback(() => ops.pages.list()
50
38
  .then((r) => (r.ok ? setPages(r.data) : setError(r.message)))
@@ -74,6 +62,10 @@ export function PagesList({ ops, registry }) {
74
62
  return;
75
63
  if (projection.parentId === row.parentId && projection.index === row.index)
76
64
  return;
65
+ // A published page under a new parent is a new live URL (members management §5).
66
+ const current = row.record.locales[locale];
67
+ if (!(await confirmLiveUrl({ status: current?.status, from: row.parentId ?? "", to: projection.parentId ?? "" }, { name: row.title, path: row.path })))
68
+ return;
77
69
  const ok = await run(() => ops.pages.move(row.id, { parentId: projection.parentId, index: projection.index }));
78
70
  if (!ok)
79
71
  throw new Error("move refused");
@@ -81,10 +73,10 @@ export function PagesList({ ops, registry }) {
81
73
  });
82
74
  /** The editor opens in the locale selected here. */
83
75
  const openEditor = (id) => {
84
- navigate(adminHref(`/pages/${encodeURIComponent(id)}?locale=${encodeURIComponent(locale)}`));
76
+ void navigate(adminHref(`/pages/${encodeURIComponent(id)}?locale=${encodeURIComponent(locale)}`));
85
77
  };
86
- /** Run an op; on success reload the list (and maybe navigate), else show the op's message. Resolves to whether it succeeded. */
87
- const run = async (work, then) => {
78
+ /** Run an op; on success reload the list (and maybe navigate). Resolves to the op's message, or null when it landed. */
79
+ const attempt = async (work, then) => {
88
80
  let result;
89
81
  try {
90
82
  result = await work();
@@ -92,72 +84,107 @@ export function PagesList({ ops, registry }) {
92
84
  catch {
93
85
  result = { ok: false, code: "internal", message: "Couldn't reach the server." };
94
86
  }
95
- if (!result.ok) {
96
- window.alert(result.message);
97
- return false;
98
- }
87
+ if (!result.ok)
88
+ return result.message;
99
89
  then?.(result.data);
100
90
  await load();
101
- return true;
91
+ return null;
102
92
  };
103
- const pickTemplate = () => {
104
- if (noOpen)
105
- return null;
106
- if (creatable.length === 1)
107
- return creatable[0].name;
108
- return window.prompt(`Page type? (${creatable.map((p) => p.name).join(", ")})`) || null;
93
+ /** `attempt` for an action outside a dialog: the message goes to an alert. Resolves to whether it succeeded. */
94
+ const run = async (work, then) => {
95
+ const message = await attempt(work, then);
96
+ if (message)
97
+ window.alert(message);
98
+ return message === null;
109
99
  };
110
- /** New page and New path (a folder in the tree) create in the SELECTED locale (spec §6). */
100
+ /** New page and New path (a folder in the tree) create in the SELECTED locale (spec §6),
101
+ * Add page here gives a folder a template, Rename edits the title and slug — all in a dialog (PageDialogs). */
111
102
  const newNode = (parentId, kind) => {
112
103
  if (kind === "page" && noOpen)
113
104
  return;
114
- const slug = window.prompt(`Slug for the new ${kind === "folder" ? "path" : "page"} (e.g. about):`);
115
- if (!slug)
116
- return;
117
- const template = kind === "page" ? pickTemplate() : null;
118
- if (kind === "page" && !template)
119
- return;
120
- void run(() => ops.pages.create({ parentId, locale, slug, template }), (page) => { if (template)
121
- openEditor(page.id); });
105
+ setDialog({ kind: "new", parentId, node: kind });
122
106
  };
123
107
  const addPageHere = (row) => {
124
- const template = pickTemplate();
125
- if (!template)
108
+ if (noOpen)
109
+ return;
110
+ if (creatable.length === 1) {
111
+ void run(() => ops.pages.setTemplate(row.id, creatable[0].name), (page) => openEditor(page.id));
126
112
  return;
127
- void run(() => ops.pages.setTemplate(row.id, template), (page) => openEditor(page.id));
113
+ }
114
+ setDialog({ kind: "template", row });
115
+ };
116
+ const rename = (row) => { if (row.record.locales[locale])
117
+ setDialog({ kind: "rename", row }); };
118
+ const closeDialog = () => setDialog(null);
119
+ /** The parent's path from a row's own: "/company/about-us" → "/company", "/about" → "/". */
120
+ const parentPathOf = (path) => {
121
+ if (!path)
122
+ return "/";
123
+ const cut = path.lastIndexOf("/");
124
+ return cut <= 0 ? "/" : path.slice(0, cut);
128
125
  };
129
- const addLocale = (row) => {
126
+ /** What the open dialog submits. Resolves to the op's message, or null and the caller closes. */
127
+ const submitDialog = async (values) => {
128
+ if (!dialog)
129
+ return null;
130
+ if (dialog.kind === "new") {
131
+ const template = dialog.node === "page" ? values.template : null;
132
+ if (dialog.node === "page" && !template)
133
+ return "Choose a page type.";
134
+ return attempt(() => ops.pages.create({ parentId: dialog.parentId, locale, slug: values.slug, title: values.title, template }), (page) => { if (template)
135
+ openEditor(page.id); });
136
+ }
137
+ if (dialog.kind === "template") {
138
+ if (!values.template)
139
+ return "Choose a page type.";
140
+ return attempt(() => ops.pages.setTemplate(dialog.row.id, values.template), (page) => openEditor(page.id));
141
+ }
142
+ const { row } = dialog;
143
+ const current = row.record.locales[locale];
144
+ if (!current)
145
+ return null;
146
+ // The site root's slug is the config's homePageSlug — title only there.
147
+ if (row.isHome)
148
+ return attempt(() => ops.pages.rename(row.id, { locale, title: values.title }));
149
+ if (!(await confirmLiveUrl({ status: current.status, from: current.slug, to: values.slug }, { name: row.title, path: row.path })))
150
+ return null;
151
+ return attempt(() => ops.pages.rename(row.id, { locale, title: values.title, slug: values.slug }));
152
+ };
153
+ const addLocale = async (row) => {
130
154
  const from = sourceLocaleOf(row.record, registry);
131
- if (!window.confirm(`Add "${row.title}" to ${locale}? Its ${from} content is copied as the first ${locale} draft.`))
155
+ const ok = await confirm({
156
+ title: `Add this page to ${locale}?`,
157
+ body: `Its ${from} content is copied as the first ${locale} draft. Nothing is published until you publish it.`,
158
+ confirmLabel: `Add to ${locale}`,
159
+ subject: { name: row.title, path: row.record.locales[from] ? row.path : null },
160
+ });
161
+ if (!ok)
132
162
  return;
133
163
  void run(() => ops.pages.addLocale(row.id, locale, { from }), (page) => { if (page.template !== null)
134
164
  openEditor(page.id); });
135
165
  };
136
- const removeLocale = (row) => {
137
- if (!window.confirm(`Remove "${row.title}" from ${locale}? Its ${locale} content and history are deleted.`))
166
+ const removeLocale = async (row) => {
167
+ const ok = await confirm({
168
+ title: `Remove this page from ${locale}?`,
169
+ body: `Its ${locale} content and history are deleted. Other languages are not affected.`,
170
+ confirmLabel: `Remove from ${locale}`,
171
+ destructive: true,
172
+ subject: { name: row.title, path: row.path },
173
+ });
174
+ if (!ok)
138
175
  return;
139
176
  void run(() => ops.pages.removeLocale(row.id, locale));
140
177
  };
141
- const rename = (row) => {
142
- const current = row.record.locales[locale];
143
- if (!current)
144
- return;
145
- const title = window.prompt("Title:", current.title);
146
- if (title === null)
147
- return;
148
- // The site root's slug is the config's homePageSlug — title only here.
149
- if (row.isHome) {
150
- void run(() => ops.pages.rename(row.id, { locale, title }));
151
- return;
152
- }
153
- const slug = window.prompt("Slug (the URL segment):", current.slug);
154
- if (slug === null)
155
- return;
156
- void run(() => ops.pages.rename(row.id, { locale, title, slug }));
157
- };
158
- const destroy = (row) => {
178
+ const destroy = async (row) => {
159
179
  const scope = row.locales.length > 1 ? ` in every language (${row.locales.join(", ")})` : "";
160
- if (!window.confirm(`Delete "${row.title}"${scope}?`))
180
+ const ok = await confirm({
181
+ title: row.hasChildren ? "Delete this page and everything under it?" : "Delete this page?",
182
+ body: `The page${scope} and its history are removed. Links pointing to it stop working. This cannot be undone.`,
183
+ confirmLabel: "Delete page",
184
+ destructive: true,
185
+ subject: { name: row.title, path: row.path },
186
+ });
187
+ if (!ok)
161
188
  return;
162
189
  void run(() => ops.pages.delete(row.id));
163
190
  };
@@ -193,7 +220,7 @@ export function PagesList({ ops, registry }) {
193
220
  else if (row.template !== null)
194
221
  openEditor(row.id);
195
222
  else if (row.kind === "mount" && row.collection)
196
- navigate(adminHref(`/${row.collection}`));
223
+ void navigate(adminHref(`/${row.collection}`));
197
224
  else if (row.hasChildren)
198
225
  toggle(row.id);
199
226
  };
@@ -231,5 +258,8 @@ export function PagesList({ ops, registry }) {
231
258
  position: "absolute",
232
259
  left: Math.max(12, Math.min(menu.x - 280, window.innerWidth - 312)),
233
260
  top: Math.min(menu.y + 8, Math.max(12, window.innerHeight - 300)),
234
- }, children: [items.map((item) => (_jsx("button", { type: "button", className: "sm-picker__item", onClick: () => { setMenu(null); item.run(); }, children: item.label }, item.label))), items.length === 0 && (_jsx("p", { style: { color: "var(--text-muted)", padding: 10 }, children: "Owned by code \u2014 nothing to change here." }))] }) }))] }));
261
+ }, children: [items.map((item) => (_jsx("button", { type: "button", className: "sm-picker__item", onClick: () => { setMenu(null); item.run(); }, children: item.label }, item.label))), items.length === 0 && (_jsx("p", { style: { color: "var(--text-muted)", padding: 10 }, children: "Owned by code \u2014 nothing to change here." }))] }) })), dialog?.kind === "new" && (_jsx(PageFormDialog, { title: dialog.node === "page" ? (dialog.parentId ? "New subpage" : "New page") : (dialog.parentId ? "New subpath" : "New path"), submitLabel: dialog.node === "page" ? "Create page" : "Create path", fields: { title: true, slug: true, template: dialog.node === "page" }, templates: creatable, parentPath: dialog.parentId ? (rows.find((r) => r.id === dialog.parentId)?.path ?? "/") : "/", onClose: closeDialog, onSubmit: (values) => submitDialog(values).then((message) => { if (message === null)
262
+ closeDialog(); return message; }) })), dialog?.kind === "template" && (_jsx(PageFormDialog, { title: "Add page here", submitLabel: "Add page", fields: { template: true }, templates: creatable, onClose: closeDialog, onSubmit: (values) => submitDialog(values).then((message) => { if (message === null)
263
+ closeDialog(); return message; }) })), dialog?.kind === "rename" && (_jsx(PageFormDialog, { title: "Rename page", submitLabel: "Rename", fields: { title: true, slug: !dialog.row.isHome }, initial: { title: dialog.row.record.locales[locale]?.title ?? "", slug: dialog.row.record.locales[locale]?.slug ?? "" }, parentPath: dialog.row.isHome ? undefined : parentPathOf(dialog.row.path), onClose: closeDialog, onSubmit: (values) => submitDialog(values).then((message) => { if (message === null)
264
+ closeDialog(); return message; }) }))] }));
235
265
  }
@@ -6,7 +6,7 @@ export function RouteLink({ href, onClick, ...rest }) {
6
6
  onClick?.(e);
7
7
  if (isPlainLeftClick(e, rest.target)) {
8
8
  e.preventDefault();
9
- navigate(href);
9
+ void navigate(href);
10
10
  }
11
11
  } }));
12
12
  }
@@ -0,0 +1,4 @@
1
+ import type { SchemaStatus } from "../ops.ts";
2
+ export declare function SchemaNotice({ status }: {
3
+ status: SchemaStatus;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export function SchemaNotice({ status }) {
3
+ return (_jsx("div", { style: { height: "100vh", display: "grid", placeItems: "center", padding: 24, color: "var(--text)" }, children: _jsxs("div", { style: { maxWidth: 520, display: "grid", gap: 12 }, children: [_jsx("h1", { className: "sm-title", style: { fontSize: 22, margin: 0 }, children: "The database needs an update" }), _jsxs("p", { style: { margin: 0 }, children: ["The database schema is at version ", status.database ?? "none", ". This version of Smoodly needs version ", status.required, "."] }), _jsx("p", { style: { margin: 0 }, children: "From the site's folder:" }), _jsx("pre", { className: "sm-code", children: _jsx("code", { children: "npx smoodly migrate" }) }), _jsx("p", { style: { margin: 0 }, children: "then apply it:" }), _jsx("pre", { className: "sm-code", children: _jsx("code", { children: "supabase db push" }) }), _jsxs("p", { style: { margin: 0, color: "var(--text-muted)" }, children: ["That is for a hosted project; for the local stack run ", _jsx("code", { children: "supabase db reset" }), ". Reload this page afterwards."] })] }) }));
4
+ }
@@ -0,0 +1,7 @@
1
+ import type { SupabaseClient } from "@supabase/supabase-js";
2
+ import type { Arrival } from "./session.ts";
3
+ export declare function SetPasswordView({ client, mode, onDone }: {
4
+ client: SupabaseClient;
5
+ mode: Arrival;
6
+ onDone(): void;
7
+ }): import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // packages/smoodly/src/admin/shell/SetPasswordView.tsx
4
+ // The arrival screen (spec 2026-09-25 members management §6): an invite
5
+ // link or a reset link signed the person in; now they choose a password.
6
+ // An invite cannot skip it (the account has none yet); a recovery may.
7
+ import { useState } from "react";
8
+ import { Banner, Button, Field, Logo } from "../ui/primitives.js";
9
+ export function SetPasswordView({ client, mode, onDone }) {
10
+ const [password, setPassword] = useState("");
11
+ const [again, setAgain] = useState("");
12
+ const [error, setError] = useState(null);
13
+ const [busy, setBusy] = useState(false);
14
+ const submit = async (e) => {
15
+ e.preventDefault();
16
+ if (password !== again) {
17
+ setError("The two passwords differ.");
18
+ return;
19
+ }
20
+ setBusy(true);
21
+ setError(null);
22
+ try {
23
+ const res = await client.auth.updateUser({ password });
24
+ if (res.error)
25
+ setError(res.error.message);
26
+ else
27
+ onDone();
28
+ }
29
+ catch (e) {
30
+ setError(e instanceof Error ? e.message : String(e));
31
+ }
32
+ finally {
33
+ setBusy(false);
34
+ }
35
+ };
36
+ return (_jsx("div", { style: { minHeight: "100vh", display: "grid", placeItems: "center", background: "var(--bg)" }, children: _jsxs("form", { onSubmit: submit, style: {
37
+ width: 320, display: "flex", flexDirection: "column", gap: 14,
38
+ background: "var(--surface)", padding: 28, borderRadius: "var(--radius-card-lg)",
39
+ border: "var(--menu-border)", boxShadow: "var(--shadow-page)",
40
+ }, children: [_jsx(Logo, { height: 20 }), _jsx("span", { className: "sm-title", children: mode === "invite" ? "Set your password" : "Choose a new password" }), _jsx(Field, { label: "Password", children: _jsx("input", { className: "sm-input", type: "password", required: true, minLength: 8, autoComplete: "new-password", value: password, onChange: (e) => setPassword(e.target.value) }) }), _jsx(Field, { label: "Again", children: _jsx("input", { className: "sm-input", type: "password", required: true, autoComplete: "new-password", value: again, onChange: (e) => setAgain(e.target.value) }) }), error && _jsx(Banner, { tone: "error", children: error }), _jsx("button", { type: "submit", disabled: busy, className: "sm-btn sm-btn--primary sm-btn--lg", children: busy ? "Saving…" : "Save" }), mode === "recovery" && _jsx(Button, { variant: "secondary", size: "lg", onClick: onDone, children: "Skip" })] }) }));
41
+ }
@@ -1,5 +1,9 @@
1
+ import { type MemberRole } from "../../permissions.ts";
1
2
  import type { AdminOps } from "../ops.ts";
2
- export declare function SettingsView({ ops, tail }: {
3
+ export declare function SettingsView({ ops, tail, role, userId }: {
3
4
  ops: AdminOps;
4
5
  tail: string | undefined;
6
+ /** The caller's role from `members.me`; null while it loads. */
7
+ role: MemberRole | null;
8
+ userId: string;
5
9
  }): import("react").JSX.Element;
@@ -1,28 +1,34 @@
1
1
  "use client";
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // packages/smoodly/src/admin/shell/SettingsView.tsx
4
4
  // The Settings area (spec 2026-09-25 §5): a 200px secondary nav at the
5
- // left of the main column, then the page with its own top bar. The head
6
- // segment alone replaces itself with the default page, so Back skips the
7
- // empty URL. An unknown page is the shell's Not found pane.
5
+ // left of the main column, its card starting where the page's card starts (no heading since 2026-09-26) —
6
+ // then the page with its own top bar. The head segment alone replaces
7
+ // itself with the default page, so Back skips the empty URL. An unknown
8
+ // page is the shell's Not found pane. Admins only (members management
9
+ // §2): an editor gets the error pane, and until the role is known the
10
+ // area is loading. Members is the only page (the Roles table moved into
11
+ // the invite modal's role descriptions; API Keys never had contents).
8
12
  import { useEffect } from "react";
9
- import { TopBar } from "../ui/primitives.js";
13
+ import { can } from "../../permissions.js";
10
14
  import { useAdminHref } from "./base.js";
11
15
  import { ErrorPane } from "./ErrorPane.js";
12
16
  import { MembersPage } from "./MembersPage.js";
13
17
  import { RouteLink } from "./RouteLink.js";
14
18
  import { navigate } from "./router.js";
15
- import { DEFAULT_SETTINGS_PAGE, SETTINGS_PAGES, settingsPage, settingsTitle } from "./settings.js";
16
- export function SettingsView({ ops, tail }) {
19
+ import { DEFAULT_SETTINGS_PAGE, SETTINGS_PAGES, settingsPage } from "./settings.js";
20
+ export function SettingsView({ ops, tail, role, userId }) {
17
21
  const adminHref = useAdminHref();
18
22
  const page = settingsPage(tail);
19
23
  useEffect(() => {
20
24
  if (tail === undefined)
21
- navigate(adminHref(`/settings/${DEFAULT_SETTINGS_PAGE}`), { replace: true });
25
+ void navigate(adminHref(`/settings/${DEFAULT_SETTINGS_PAGE}`), { replace: true });
22
26
  }, [tail, adminHref]);
27
+ if (role === null)
28
+ return _jsx("div", { className: "sm-empty", children: "Loading\u2026" });
29
+ if (!can(role, "settings"))
30
+ return _jsx(ErrorPane, { message: "Settings are for admins." });
23
31
  if (!page)
24
32
  return _jsx(ErrorPane, { message: "Not found." });
25
- return (_jsxs("div", { className: "sm-settings", children: [_jsx("nav", { className: "sm-settings__nav", "aria-label": "Settings", children: SETTINGS_PAGES.map((p) => (_jsx(RouteLink, { className: "sm-settings__link", href: adminHref(`/settings/${p.id}`), "aria-current": p.id === page ? "page" : undefined, children: p.title }, p.id))) }), _jsx("section", { className: "sm-settings__page", children: page === "members"
26
- ? _jsx(MembersPage, { ops: ops })
27
- : _jsxs(_Fragment, { children: [_jsx(TopBar, { left: _jsx("span", { className: "sm-title", children: settingsTitle(page) }) }), _jsx("div", { className: "sm-listwrap" })] }) })] }));
33
+ return (_jsxs("div", { className: "sm-settings", children: [_jsx("nav", { className: "sm-settings__nav", "aria-label": "Settings", children: SETTINGS_PAGES.map((p) => (_jsx(RouteLink, { className: "sm-settings__link", href: adminHref(`/settings/${p.id}`), "aria-current": p.id === page ? "page" : undefined, children: p.title }, p.id))) }), _jsx("section", { className: "sm-settings__page", children: _jsx(MembersPage, { ops: ops, userId: userId }) })] }));
28
34
  }
@@ -0,0 +1,10 @@
1
+ import { type ConfirmOptions, type ConfirmSubject } from "../ui/confirm.ts";
2
+ export declare const LIVE_URL_CONFIRM: Omit<ConfirmOptions, "subject">;
3
+ /** `from` null = there was no URL part to change (a new row, a collection without a path). */
4
+ export declare function liveUrlChanges(input: {
5
+ status: "draft" | "published" | undefined;
6
+ from: string | null;
7
+ to: string | null;
8
+ }): boolean;
9
+ /** Resolves true when the change may go ahead: not a live change, or confirmed. */
10
+ export declare function confirmLiveUrl(input: Parameters<typeof liveUrlChanges>[0], subject?: ConfirmSubject): Promise<boolean>;
@@ -0,0 +1,19 @@
1
+ // The one confirm on anything that changes a live URL (spec 2026-09-25
2
+ // members management §5): a published page's or entry's slug, or a
3
+ // published page's parent. Whoever the role — the mistake is the same.
4
+ // Asked in the admin's own dialog (ui/confirm.ts); the subject chip names
5
+ // the record and the URL part that is about to change.
6
+ import { confirm } from "../ui/confirm.js";
7
+ export const LIVE_URL_CONFIRM = {
8
+ title: "Change the live URL?",
9
+ body: "This is published. Old links to it stop working until a redirect exists, and Smoodly has none yet.",
10
+ confirmLabel: "Change URL",
11
+ };
12
+ /** `from` null = there was no URL part to change (a new row, a collection without a path). */
13
+ export function liveUrlChanges(input) {
14
+ return input.status === "published" && input.from !== null && input.to !== input.from;
15
+ }
16
+ /** Resolves true when the change may go ahead: not a live change, or confirmed. */
17
+ export async function confirmLiveUrl(input, subject) {
18
+ return !liveUrlChanges(input) || confirm({ ...LIVE_URL_CONFIRM, subject });
19
+ }
@@ -0,0 +1,8 @@
1
+ import type { AdminRegistry } from "../serialize.ts";
2
+ export declare const LOCALE_KEY = "smoodly-locale";
3
+ type Locales = AdminRegistry["locales"];
4
+ /** The stored locale when the config supports it, else the default. */
5
+ export declare function resolveLocale(stored: string | null | undefined, locales: Locales): string;
6
+ export declare function rememberedLocale(locales: Locales): string;
7
+ export declare function rememberLocale(locale: string): void;
8
+ export {};