@eutobias/serenojs 0.0.0-stage → 0.1.1

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 (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +682 -2
  3. package/admin-dist/assets/index-B3EgqtT6.js +9 -0
  4. package/admin-dist/assets/index-D2m0Eb4k.css +2 -0
  5. package/admin-dist/index.html +17 -0
  6. package/dist/auth/auth.server.d.ts +31 -0
  7. package/dist/auth/auth.server.js +141 -0
  8. package/dist/auth/config.d.ts +32 -0
  9. package/dist/auth/config.js +25 -0
  10. package/dist/auth/cookies.server.d.ts +7 -0
  11. package/dist/auth/cookies.server.js +65 -0
  12. package/dist/auth/http.server.d.ts +8 -0
  13. package/dist/auth/http.server.js +30 -0
  14. package/dist/auth/password.server.d.ts +2 -0
  15. package/dist/auth/password.server.js +21 -0
  16. package/dist/auth/session.server.d.ts +2 -0
  17. package/dist/auth/session.server.js +14 -0
  18. package/dist/auth/users.server.d.ts +16 -0
  19. package/dist/auth/users.server.js +123 -0
  20. package/dist/config.d.ts +91 -0
  21. package/dist/config.js +39 -0
  22. package/dist/core/backup.server.d.ts +52 -0
  23. package/dist/core/backup.server.js +349 -0
  24. package/dist/core/db.server.d.ts +24 -0
  25. package/dist/core/db.server.js +526 -0
  26. package/dist/core/media.d.ts +22 -0
  27. package/dist/core/media.js +76 -0
  28. package/dist/core/media.server.d.ts +18 -0
  29. package/dist/core/media.server.js +102 -0
  30. package/dist/core/schema.d.ts +26 -0
  31. package/dist/core/schema.js +99 -0
  32. package/dist/core/types.d.ts +143 -0
  33. package/dist/core/types.js +1 -0
  34. package/dist/core/validation.d.ts +16 -0
  35. package/dist/core/validation.js +192 -0
  36. package/dist/locale.d.ts +2 -0
  37. package/dist/locale.js +14 -0
  38. package/dist/runtime.d.ts +8 -0
  39. package/dist/runtime.js +37 -0
  40. package/dist/server/app.d.ts +20 -0
  41. package/dist/server/app.js +661 -0
  42. package/dist/ui/admin/admin-shell.d.ts +16 -0
  43. package/dist/ui/admin/admin-shell.js +38 -0
  44. package/dist/ui/admin/backup-manager.d.ts +5 -0
  45. package/dist/ui/admin/backup-manager.js +165 -0
  46. package/dist/ui/admin/collection-icon.d.ts +22 -0
  47. package/dist/ui/admin/collection-icon.js +34 -0
  48. package/dist/ui/admin/collection-manager.d.ts +7 -0
  49. package/dist/ui/admin/collection-manager.js +212 -0
  50. package/dist/ui/admin/display.d.ts +7 -0
  51. package/dist/ui/admin/display.js +65 -0
  52. package/dist/ui/admin/field-control.d.ts +14 -0
  53. package/dist/ui/admin/field-control.js +58 -0
  54. package/dist/ui/admin/i18n.d.ts +27 -0
  55. package/dist/ui/admin/i18n.js +324 -0
  56. package/dist/ui/admin/item-form.d.ts +20 -0
  57. package/dist/ui/admin/item-form.js +60 -0
  58. package/dist/ui/admin/list-control.d.ts +13 -0
  59. package/dist/ui/admin/list-control.js +31 -0
  60. package/dist/ui/admin/locales.d.ts +4 -0
  61. package/dist/ui/admin/locales.js +8 -0
  62. package/dist/ui/admin/login-form.d.ts +3 -0
  63. package/dist/ui/admin/login-form.js +52 -0
  64. package/dist/ui/admin/media-control.d.ts +14 -0
  65. package/dist/ui/admin/media-control.js +74 -0
  66. package/dist/ui/admin/media-list-control.d.ts +14 -0
  67. package/dist/ui/admin/media-list-control.js +91 -0
  68. package/dist/ui/admin/pagination.d.ts +11 -0
  69. package/dist/ui/admin/pagination.js +14 -0
  70. package/dist/ui/admin/relation-control.d.ts +14 -0
  71. package/dist/ui/admin/relation-control.js +33 -0
  72. package/dist/ui/admin/router.d.ts +17 -0
  73. package/dist/ui/admin/router.js +58 -0
  74. package/dist/ui/admin/runtime.d.ts +28 -0
  75. package/dist/ui/admin/runtime.js +29 -0
  76. package/dist/ui/admin/sidebar.d.ts +13 -0
  77. package/dist/ui/admin/sidebar.js +29 -0
  78. package/dist/ui/admin/standalone-manager.d.ts +11 -0
  79. package/dist/ui/admin/standalone-manager.js +51 -0
  80. package/dist/ui/admin/table.d.ts +21 -0
  81. package/dist/ui/admin/table.js +23 -0
  82. package/dist/ui/admin/toast.d.ts +16 -0
  83. package/dist/ui/admin/toast.js +59 -0
  84. package/dist/ui/admin/users-manager.d.ts +6 -0
  85. package/dist/ui/admin/users-manager.js +157 -0
  86. package/dist/ui/badge.d.ts +9 -0
  87. package/dist/ui/badge.js +14 -0
  88. package/dist/ui/box.d.ts +17 -0
  89. package/dist/ui/box.js +14 -0
  90. package/dist/ui/button.d.ts +25 -0
  91. package/dist/ui/button.js +28 -0
  92. package/dist/ui/card.d.ts +45 -0
  93. package/dist/ui/card.js +49 -0
  94. package/dist/ui/container.d.ts +13 -0
  95. package/dist/ui/container.js +13 -0
  96. package/dist/ui/drawer.d.ts +15 -0
  97. package/dist/ui/drawer.js +31 -0
  98. package/dist/ui/field-wrapper.d.ts +15 -0
  99. package/dist/ui/field-wrapper.js +11 -0
  100. package/dist/ui/index.d.ts +8 -0
  101. package/dist/ui/index.js +8 -0
  102. package/dist/ui/text.d.ts +19 -0
  103. package/dist/ui/text.js +40 -0
  104. package/package.json +81 -3
  105. package/src/admin/app.tsx +371 -0
  106. package/src/admin/index.html +16 -0
  107. package/src/admin/main.tsx +42 -0
  108. package/src/admin/styles.css +9 -0
  109. package/src/auth/auth.server.ts +203 -0
  110. package/src/auth/config.ts +46 -0
  111. package/src/auth/cookies.server.ts +84 -0
  112. package/src/auth/http.server.ts +32 -0
  113. package/src/auth/password.server.ts +25 -0
  114. package/src/auth/session.server.ts +16 -0
  115. package/src/auth/users.server.ts +159 -0
  116. package/src/config.ts +120 -0
  117. package/src/core/backup.server.ts +446 -0
  118. package/src/core/db.server.ts +685 -0
  119. package/src/core/media.server.ts +136 -0
  120. package/src/core/media.ts +91 -0
  121. package/src/core/schema.ts +126 -0
  122. package/src/core/types.ts +194 -0
  123. package/src/core/validation.ts +215 -0
  124. package/src/global.d.ts +1 -0
  125. package/src/locale.ts +16 -0
  126. package/src/runtime.ts +54 -0
  127. package/src/server/app.ts +737 -0
  128. package/src/ui/admin/admin-shell.tsx +106 -0
  129. package/src/ui/admin/backup-manager.tsx +327 -0
  130. package/src/ui/admin/collection-icon.tsx +69 -0
  131. package/src/ui/admin/collection-manager.tsx +408 -0
  132. package/src/ui/admin/display.tsx +138 -0
  133. package/src/ui/admin/field-control.tsx +214 -0
  134. package/src/ui/admin/i18n.tsx +401 -0
  135. package/src/ui/admin/item-form.tsx +200 -0
  136. package/src/ui/admin/list-control.tsx +121 -0
  137. package/src/ui/admin/locales.ts +12 -0
  138. package/src/ui/admin/login-form.tsx +98 -0
  139. package/src/ui/admin/media-control.tsx +161 -0
  140. package/src/ui/admin/media-list-control.tsx +242 -0
  141. package/src/ui/admin/pagination.tsx +58 -0
  142. package/src/ui/admin/relation-control.tsx +142 -0
  143. package/src/ui/admin/router.tsx +105 -0
  144. package/src/ui/admin/runtime.tsx +58 -0
  145. package/src/ui/admin/sidebar.tsx +178 -0
  146. package/src/ui/admin/standalone-manager.tsx +103 -0
  147. package/src/ui/admin/table.tsx +129 -0
  148. package/src/ui/admin/toast.tsx +126 -0
  149. package/src/ui/admin/users-manager.tsx +344 -0
  150. package/src/ui/badge.tsx +27 -0
  151. package/src/ui/box.tsx +33 -0
  152. package/src/ui/button.tsx +77 -0
  153. package/src/ui/card.tsx +92 -0
  154. package/src/ui/container.tsx +28 -0
  155. package/src/ui/drawer.tsx +104 -0
  156. package/src/ui/field-wrapper.tsx +54 -0
  157. package/src/ui/index.ts +8 -0
  158. package/src/ui/text.tsx +93 -0
@@ -0,0 +1,14 @@
1
+ import type { FieldDef, MediaItem } from "../../core/types.js";
2
+ export type MediaListControlProps = {
3
+ field: FieldDef;
4
+ collectionSlug: string;
5
+ value: MediaItem[];
6
+ error?: string | undefined;
7
+ disabled?: boolean | undefined;
8
+ onChange: (value: MediaItem[]) => void;
9
+ };
10
+ /**
11
+ * Native `media-list` widget: upload several images, reorder them and pick one
12
+ * as the principal (cover/highlight).
13
+ */
14
+ export declare const MediaListControl: ({ field, collectionSlug, value, error, disabled, onChange, }: MediaListControlProps) => import("react").JSX.Element;
@@ -0,0 +1,91 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useRef, useState } from "react";
4
+ import { FiArrowLeft, FiArrowRight, FiStar, FiTrash2, FiUpload, } from "react-icons/fi";
5
+ import { acceptAttribute, isImageUrl } from "../../core/media.js";
6
+ import { Box } from "../box.js";
7
+ import { Button, IconButton } from "../button.js";
8
+ import { FieldWrapper } from "../field-wrapper.js";
9
+ import { useCmsUrls } from "./runtime.js";
10
+ import { Text } from "../text.js";
11
+ import { useI18n } from "./i18n.js";
12
+ async function uploadFile(file, collectionSlug, fieldName, mediaPath, uploadFailed) {
13
+ const params = new URLSearchParams({
14
+ collection: collectionSlug,
15
+ field: fieldName,
16
+ });
17
+ const form = new FormData();
18
+ form.append("file", file);
19
+ const response = await fetch(`${mediaPath}?${params.toString()}`, {
20
+ method: "POST",
21
+ body: form,
22
+ });
23
+ const json = (await response.json().catch(() => null));
24
+ const url = json?.media?.url;
25
+ if (!response.ok || !url) {
26
+ throw new Error(json?.message ?? uploadFailed);
27
+ }
28
+ return url;
29
+ }
30
+ /**
31
+ * Native `media-list` widget: upload several images, reorder them and pick one
32
+ * as the principal (cover/highlight).
33
+ */
34
+ export const MediaListControl = ({ field, collectionSlug, value, error, disabled, onChange, }) => {
35
+ const { media } = useCmsUrls();
36
+ const { t } = useI18n();
37
+ const inputRef = useRef(null);
38
+ const [uploading, setUploading] = useState(false);
39
+ const [localError, setLocalError] = useState(null);
40
+ const ensurePrimary = (items) => {
41
+ if (items.length === 0 || items.some((item) => item.primary))
42
+ return items;
43
+ const [first, ...rest] = items;
44
+ return first ? [{ ...first, primary: true }, ...rest] : items;
45
+ };
46
+ const setPrimary = (index) => onChange(value.map((item, i) => ({ ...item, primary: i === index })));
47
+ const remove = (index) => onChange(ensurePrimary(value.filter((_, i) => i !== index)));
48
+ const move = (index, direction) => {
49
+ const target = index + direction;
50
+ if (target < 0 || target >= value.length)
51
+ return;
52
+ const next = [...value];
53
+ const current = next[index];
54
+ const swap = next[target];
55
+ if (!current || !swap)
56
+ return;
57
+ next[index] = swap;
58
+ next[target] = current;
59
+ onChange(next);
60
+ };
61
+ const onFiles = async (files) => {
62
+ if (!files || files.length === 0)
63
+ return;
64
+ setUploading(true);
65
+ setLocalError(null);
66
+ try {
67
+ const urls = [];
68
+ for (const file of Array.from(files)) {
69
+ urls.push(await uploadFile(file, collectionSlug, field.name, media(), t("media.uploadFailed")));
70
+ }
71
+ const additions = urls.map((url, index) => ({
72
+ url,
73
+ alt: "",
74
+ primary: value.length === 0 && index === 0,
75
+ }));
76
+ onChange(ensurePrimary([...value, ...additions]));
77
+ }
78
+ catch (uploadError) {
79
+ setLocalError(uploadError instanceof Error ? uploadError.message : t("media.uploadFailed"));
80
+ }
81
+ finally {
82
+ setUploading(false);
83
+ if (inputRef.current)
84
+ inputRef.current.value = "";
85
+ }
86
+ };
87
+ const busy = disabled || uploading;
88
+ return (_jsx(FieldWrapper, { label: field.label, required: field.required, help: field.help, error: error ?? localError ?? undefined, children: _jsxs(Box, { className: "flex-col gap-3", children: [value.length === 0 ? (_jsx(Text, { size: "caption", className: "text-gray-400", children: t("media.noMedia") })) : (_jsx("div", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: value.map((item, index) => (_jsxs(Box, { className: `flex-col overflow-hidden rounded-md border bg-white ${item.primary
89
+ ? "border-gray-900 ring-1 ring-gray-900"
90
+ : "border-gray-200"}`, children: [_jsxs(Box, { className: "relative", children: [isImageUrl(item.url) ? (_jsx("img", { src: item.url, alt: item.alt ?? "", className: "aspect-[4/3] w-full object-cover" })) : (_jsx("a", { href: item.url, target: "_blank", rel: "noreferrer", className: "block truncate p-3 text-xs text-gray-600 underline", children: item.url })), item.primary ? (_jsx("span", { className: "absolute left-2 top-2 rounded bg-gray-900 px-1.5 py-0.5 text-[10px] font-bold uppercase text-white", children: t("media.primary") })) : null] }), _jsxs(Box, { className: "flex-wrap items-center justify-between gap-0.5 border-t border-gray-100 p-1", children: [_jsx(IconButton, { type: "button", label: t("media.moveBack"), disabled: busy || index === 0, onClick: () => move(index, -1), children: _jsx(FiArrowLeft, { "aria-hidden": true }) }), _jsx(IconButton, { type: "button", label: t("media.setPrimary"), disabled: busy || item.primary, className: item.primary ? "text-amber-500" : "", onClick: () => setPrimary(index), children: _jsx(FiStar, { "aria-hidden": true }) }), _jsx(IconButton, { type: "button", label: t("media.moveForward"), disabled: busy || index === value.length - 1, onClick: () => move(index, 1), children: _jsx(FiArrowRight, { "aria-hidden": true }) }), _jsx(IconButton, { type: "button", label: t("common.remove"), className: "text-red-600 hover:bg-red-50 hover:text-red-700", disabled: busy, onClick: () => remove(index), children: _jsx(FiTrash2, { "aria-hidden": true }) })] })] }, `${item.url}-${index}`))) })), _jsxs(Box, { className: "items-center gap-3", children: [_jsxs(Button, { type: "button", variant: "secondary", size: "sm", disabled: busy, onClick: () => inputRef.current?.click(), children: [_jsx(FiUpload, { "aria-hidden": true, className: "mr-1.5" }), uploading ? t("media.uploading") : t("media.addImages")] }), _jsx(Text, { size: "caption", className: "text-gray-400", children: t("media.count", { count: value.length }) })] }), _jsx("input", { ref: inputRef, type: "file", multiple: true, accept: acceptAttribute(field), disabled: busy, className: "hidden", onChange: (event) => void onFiles(event.target.files) })] }) }));
91
+ };
@@ -0,0 +1,11 @@
1
+ export type PaginationProps = {
2
+ page: number;
3
+ totalPages: number;
4
+ total: number;
5
+ limit: number;
6
+ onPage: (page: number) => void;
7
+ };
8
+ /**
9
+ * Simple previous/next pagination with a result summary.
10
+ */
11
+ export declare const Pagination: ({ page, totalPages, total, limit, onPage, }: PaginationProps) => import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box } from "../box.js";
3
+ import { Button } from "../button.js";
4
+ import { Text } from "../text.js";
5
+ import { useI18n } from "./i18n.js";
6
+ /**
7
+ * Simple previous/next pagination with a result summary.
8
+ */
9
+ export const Pagination = ({ page, totalPages, total, limit, onPage, }) => {
10
+ const { t } = useI18n();
11
+ const from = total === 0 ? 0 : (page - 1) * limit + 1;
12
+ const to = Math.min(page * limit, total);
13
+ return (_jsxs(Box, { className: "items-center justify-between gap-4 pt-4", children: [_jsx(Text, { size: "caption", className: "text-gray-500", children: t("pagination.range", { from, to, total }) }), _jsxs(Box, { className: "items-center gap-2", children: [_jsx(Button, { type: "button", variant: "secondary", size: "sm", disabled: page <= 1, onClick: () => onPage(page - 1), children: t("pagination.previous") }), _jsxs(Text, { size: "caption", className: "px-1 text-gray-600", children: [page, " / ", totalPages] }), _jsx(Button, { type: "button", variant: "secondary", size: "sm", disabled: page >= totalPages, onClick: () => onPage(page + 1), children: t("pagination.next") })] })] }));
14
+ };
@@ -0,0 +1,14 @@
1
+ import type { FieldDef, FieldValue, RelationOption } from "../../core/types.js";
2
+ export type RelationControlProps = {
3
+ field: FieldDef;
4
+ value: FieldValue;
5
+ options: RelationOption[];
6
+ error?: string | undefined;
7
+ disabled?: boolean | undefined;
8
+ onChange: (value: FieldValue) => void;
9
+ };
10
+ /**
11
+ * Renders a relation field: a `<select>` for singular relations, a scrollable
12
+ * checkbox list for plural ones.
13
+ */
14
+ export declare const RelationControl: ({ field, value, options, error, disabled, onChange, }: RelationControlProps) => import("react").JSX.Element;
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { relationIsMany } from "../../core/schema.js";
4
+ import { Box } from "../box.js";
5
+ import { FieldWrapper, inputClass } from "../field-wrapper.js";
6
+ import { Text } from "../text.js";
7
+ import { useI18n } from "./i18n.js";
8
+ /**
9
+ * Renders a relation field: a `<select>` for singular relations, a scrollable
10
+ * checkbox list for plural ones.
11
+ */
12
+ export const RelationControl = ({ field, value, options, error, disabled, onChange, }) => {
13
+ const { t } = useI18n();
14
+ const id = `field-${field.name}`;
15
+ const label = `${field.label} (${field.relation?.to ?? ""})`;
16
+ const many = relationIsMany(field);
17
+ return (_jsx(FieldWrapper, { label: label, htmlFor: id, required: field.required, help: field.help, error: error, children: many ? (_jsx(ManyControl, { id: id, disabled: disabled, options: options, selected: Array.isArray(value) ? value : [], onChange: onChange })) : (_jsxs("select", { id: id, disabled: disabled, "aria-invalid": Boolean(error), value: value === null || value === undefined ? "" : String(value), onChange: (event) => onChange(event.target.value === "" ? null : Number(event.target.value)), className: `${inputClass} ${error
18
+ ? "border-red-400 focus:border-red-500 focus:ring-red-500"
19
+ : "border-gray-300"}`, children: [_jsx("option", { value: "", children: t("field.none") }), options.map((option) => (_jsx("option", { value: option.id, children: option.label }, option.id)))] })) }));
20
+ };
21
+ const ManyControl = ({ id, disabled, options, selected, onChange, }) => {
22
+ const { t } = useI18n();
23
+ const toggle = (optionId) => {
24
+ const next = selected.includes(optionId)
25
+ ? selected.filter((entry) => entry !== optionId)
26
+ : [...selected, optionId];
27
+ onChange(next);
28
+ };
29
+ return (_jsx(Box, { id: id, className: `max-h-44 flex-col gap-1 overflow-y-auto rounded-md border bg-white p-1.5 ${disabled ? "opacity-60" : ""}`, children: options.length === 0 ? (_jsx(Text, { size: "caption", className: "px-2 py-3 text-gray-400", children: t("relation.empty") })) : (options.map((option) => {
30
+ const checked = selected.includes(option.id);
31
+ return (_jsxs(Box, { as: "label", className: "cursor-pointer items-center gap-2 rounded px-2 py-1.5 transition-colors hover:bg-gray-50", children: [_jsx("input", { type: "checkbox", checked: checked, disabled: disabled, onChange: () => toggle(option.id), className: "h-4 w-4 cursor-pointer accent-gray-900" }), _jsx(Text, { size: "caption", className: "text-gray-700", children: option.label })] }, option.id));
32
+ })) }));
33
+ };
@@ -0,0 +1,17 @@
1
+ import { type AnchorHTMLAttributes, type ReactNode } from "react";
2
+ type RouterValue = {
3
+ /** Current path relative to the admin mount path (`/`, `/todos`, ...). */
4
+ path: string;
5
+ navigate: (to: string) => void;
6
+ };
7
+ export declare function RouterProvider({ basePath, children, }: {
8
+ basePath: string;
9
+ children: ReactNode;
10
+ }): import("react").JSX.Element;
11
+ export declare function useRouter(): RouterValue;
12
+ type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> & {
13
+ to: string;
14
+ };
15
+ /** Internal link that preserves the SPA history. */
16
+ export declare function Link({ to, onClick, children, ...rest }: LinkProps): import("react").JSX.Element;
17
+ export {};
@@ -0,0 +1,58 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
4
+ import { joinPath, useCms } from "./runtime.js";
5
+ const RouterContext = createContext(null);
6
+ function relativePath(pathname, base) {
7
+ const basePath = base.replace(/\/+$/, "");
8
+ if (pathname === basePath)
9
+ return "/";
10
+ if (pathname.startsWith(`${basePath}/`)) {
11
+ const rest = pathname.slice(basePath.length);
12
+ return rest.startsWith("/") ? rest : `/${rest}`;
13
+ }
14
+ return "/";
15
+ }
16
+ export function RouterProvider({ basePath, children, }) {
17
+ const [path, setPath] = useState(() => typeof window === "undefined" ? "/" : relativePath(window.location.pathname, basePath));
18
+ useEffect(() => {
19
+ const onPop = () => setPath(relativePath(window.location.pathname, basePath));
20
+ window.addEventListener("popstate", onPop);
21
+ return () => window.removeEventListener("popstate", onPop);
22
+ }, [basePath]);
23
+ const navigate = useCallback((to) => {
24
+ const absolute = joinPath(basePath, to);
25
+ if (absolute !== window.location.pathname) {
26
+ window.history.pushState(null, "", absolute);
27
+ }
28
+ setPath(relativePath(absolute, basePath));
29
+ }, [basePath]);
30
+ const value = useMemo(() => ({ path, navigate }), [path, navigate]);
31
+ return _jsx(RouterContext.Provider, { value: value, children: children });
32
+ }
33
+ export function useRouter() {
34
+ const value = useContext(RouterContext);
35
+ if (!value) {
36
+ throw new Error("[serenojs] RouterProvider is missing.");
37
+ }
38
+ return value;
39
+ }
40
+ /** Internal link that preserves the SPA history. */
41
+ export function Link({ to, onClick, children, ...rest }) {
42
+ const { navigate } = useRouter();
43
+ const { adminPath } = useCms();
44
+ const handleClick = (event) => {
45
+ onClick?.(event);
46
+ if (event.defaultPrevented ||
47
+ event.button !== 0 ||
48
+ event.metaKey ||
49
+ event.ctrlKey ||
50
+ event.shiftKey ||
51
+ event.altKey) {
52
+ return;
53
+ }
54
+ event.preventDefault();
55
+ navigate(to);
56
+ };
57
+ return (_jsx("a", { href: joinPath(adminPath, to), onClick: handleClick, ...rest, children: children }));
58
+ }
@@ -0,0 +1,28 @@
1
+ import { type ReactNode } from "react";
2
+ import type { CollectionDef, LocaleDef } from "../../config.js";
3
+ /** Payload injected into the admin shell by the server (no secrets). */
4
+ export type AdminRuntimeConfig = {
5
+ title: string;
6
+ adminPath: string;
7
+ apiPath: string;
8
+ authPath: string;
9
+ mediaPath: string;
10
+ filesPath: string;
11
+ backupPath: string;
12
+ collections: CollectionDef[];
13
+ locales: LocaleDef[];
14
+ defaultLocale: string;
15
+ };
16
+ export declare function AdminRuntimeProvider({ value, children, }: {
17
+ value: AdminRuntimeConfig;
18
+ children: ReactNode;
19
+ }): import("react").JSX.Element;
20
+ export declare function useCms(): AdminRuntimeConfig;
21
+ /** Join a mount path and a relative segment without double slashes. */
22
+ export declare function joinPath(base: string, segment: string): string;
23
+ export declare function useCmsUrls(): {
24
+ api: (path: string) => string;
25
+ auth: (path: string) => string;
26
+ media: (query?: string) => string;
27
+ backup: (query?: string) => string;
28
+ };
@@ -0,0 +1,29 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ const RuntimeContext = createContext(null);
5
+ export function AdminRuntimeProvider({ value, children, }) {
6
+ return _jsx(RuntimeContext.Provider, { value: value, children: children });
7
+ }
8
+ export function useCms() {
9
+ const value = useContext(RuntimeContext);
10
+ if (!value) {
11
+ throw new Error("[serenojs] AdminRuntimeProvider is missing.");
12
+ }
13
+ return value;
14
+ }
15
+ /** Join a mount path and a relative segment without double slashes. */
16
+ export function joinPath(base, segment) {
17
+ if (!segment)
18
+ return base;
19
+ return `${base.replace(/\/+$/, "")}/${segment.replace(/^\/+/, "")}`;
20
+ }
21
+ export function useCmsUrls() {
22
+ const config = useCms();
23
+ return useMemo(() => ({
24
+ api: (path) => joinPath(config.apiPath, path),
25
+ auth: (path) => joinPath(config.authPath, path),
26
+ media: (query = "") => `${config.mediaPath}${query ? `?${query}` : ""}`,
27
+ backup: (query = "") => `${config.backupPath}${query ? `?${query}` : ""}`,
28
+ }), [config.apiPath, config.authPath, config.mediaPath, config.backupPath]);
29
+ }
@@ -0,0 +1,13 @@
1
+ import type { CollectionDef } from "../../core/types.js";
2
+ import type { AuthUser } from "../../auth/config.js";
3
+ export type SidebarProps = {
4
+ title: string;
5
+ collections: CollectionDef[];
6
+ user?: AuthUser;
7
+ onLogout?: () => void;
8
+ onNavigate?: () => void;
9
+ };
10
+ /**
11
+ * Left navigation derived from the schema descriptor.
12
+ */
13
+ export declare const Sidebar: ({ title, collections, user, onLogout, onNavigate, }: SidebarProps) => import("react").JSX.Element;
@@ -0,0 +1,29 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Link, useRouter } from "./router.js";
4
+ import { Box } from "../box.js";
5
+ import { Button } from "../button.js";
6
+ import { Text } from "../text.js";
7
+ import { FiDatabase, FiUsers } from "react-icons/fi";
8
+ import { CollectionIcon } from "./collection-icon.js";
9
+ import { ADMIN_LOCALES, useI18n } from "./i18n.js";
10
+ /**
11
+ * Left navigation derived from the schema descriptor.
12
+ */
13
+ export const Sidebar = ({ title, collections, user, onLogout, onNavigate, }) => {
14
+ const { path } = useRouter();
15
+ const { t, locale, setLocale } = useI18n();
16
+ return (_jsxs(Box, { as: "aside", className: "sticky top-0 h-screen w-64 shrink-0 flex-col border-r border-gray-200 bg-white", children: [_jsxs(Box, { className: "flex-col gap-1 border-b border-gray-200 px-5 py-5", children: [_jsx(Text, { size: "caption", className: "font-semibold uppercase tracking-widest text-gray-400", children: title }), _jsx(Text, { size: "caption", className: "text-gray-400", children: "Admin" })] }), _jsxs(Box, { className: "flex-1 flex-col gap-1 p-3", children: [_jsx(Text, { size: "caption", className: "px-2 pb-1 pt-2 font-semibold uppercase tracking-wide text-gray-400", children: t("sidebar.collections") }), _jsxs(Link, { to: "/", onClick: onNavigate, className: `flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors ${path === "/"
17
+ ? "bg-gray-900 font-medium text-white"
18
+ : "text-gray-700 hover:bg-gray-100"}`, children: [_jsx("span", { "aria-hidden": true, children: "\u25A6" }), _jsx("span", { children: t("sidebar.overview") })] }), collections.map((collection) => {
19
+ const href = `/${collection.slug}`;
20
+ const active = path === href || path.startsWith(`${href}/`);
21
+ return (_jsxs(Link, { to: href, onClick: onNavigate, className: `flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors ${active
22
+ ? "bg-gray-900 font-medium text-white"
23
+ : "text-gray-700 hover:bg-gray-100"}`, children: [_jsx(CollectionIcon, { name: collection.icon, className: "h-4 w-4 shrink-0" }), _jsx("span", { children: collection.label }), collection.standalone ? (_jsx("span", { "aria-hidden": true, title: t("sidebar.singleRecord"), className: `ml-auto h-1.5 w-1.5 rounded-full ${active ? "bg-white/70" : "bg-gray-300"}` })) : null] }, collection.slug));
24
+ }), _jsx(Text, { size: "caption", className: "px-2 pb-1 pt-4 font-semibold uppercase tracking-wide text-gray-400", children: t("sidebar.administration") }), _jsxs(Link, { to: "/users", onClick: onNavigate, className: `flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors ${path === "/users"
25
+ ? "bg-gray-900 font-medium text-white"
26
+ : "text-gray-700 hover:bg-gray-100"}`, children: [_jsx(FiUsers, { "aria-hidden": true, className: "h-4 w-4 shrink-0" }), _jsx("span", { children: t("sidebar.users") })] }), _jsxs(Link, { to: "/backup", onClick: onNavigate, className: `flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors ${path === "/backup"
27
+ ? "bg-gray-900 font-medium text-white"
28
+ : "text-gray-700 hover:bg-gray-100"}`, children: [_jsx(FiDatabase, { "aria-hidden": true, className: "h-4 w-4 shrink-0" }), _jsx("span", { children: t("sidebar.backup") })] })] }), _jsxs(Box, { className: "flex-col gap-1 border-t border-gray-200 p-3", children: [_jsx(Text, { size: "caption", className: "px-2 font-semibold uppercase tracking-wide text-gray-400", children: t("common.language") }), _jsx("select", { value: locale, onChange: (event) => setLocale(event.target.value === "pt" ? "pt" : "en"), className: "rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm text-gray-700 outline-none focus:border-gray-900 focus:ring-1 focus:ring-gray-900", "aria-label": t("common.language"), children: ADMIN_LOCALES.map((option) => (_jsx("option", { value: option.code, children: option.label }, option.code))) })] }), user ? (_jsxs(Box, { className: "flex-col gap-2 border-t border-gray-200 p-3", children: [_jsxs(Box, { className: "flex-col px-2", children: [_jsx(Text, { size: "caption", className: "truncate font-medium text-gray-700", title: user.email, children: user.email }), _jsx(Text, { size: "caption", className: "text-gray-400", children: t("sidebar.sessionActive") })] }), onLogout ? (_jsx(Button, { type: "button", variant: "secondary", size: "sm", onClick: onLogout, children: t("sidebar.signOut") })) : null] })) : null] }));
29
+ };
@@ -0,0 +1,11 @@
1
+ import type { CollectionDef, Item, RelationOptionsMap } from "../../core/types.js";
2
+ export type StandaloneManagerProps = {
3
+ collection: CollectionDef;
4
+ initial: Item;
5
+ relationOptions: RelationOptionsMap;
6
+ };
7
+ /**
8
+ * Editor for a standalone collection: no table, no create/delete — just the
9
+ * single record rendered as a form.
10
+ */
11
+ export declare const StandaloneManager: ({ collection, initial, relationOptions, }: StandaloneManagerProps) => import("react").JSX.Element;
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { Badge } from "../badge.js";
5
+ import { Box } from "../box.js";
6
+ import { Text } from "../text.js";
7
+ import { ItemForm } from "./item-form.js";
8
+ import { useToast } from "./toast.js";
9
+ import { useI18n } from "./i18n.js";
10
+ import { useCmsUrls } from "./runtime.js";
11
+ /**
12
+ * Editor for a standalone collection: no table, no create/delete — just the
13
+ * single record rendered as a form.
14
+ */
15
+ export const StandaloneManager = ({ collection, initial, relationOptions, }) => {
16
+ const toast = useToast();
17
+ const { api } = useCmsUrls();
18
+ const { t } = useI18n();
19
+ const [item, setItem] = useState(initial);
20
+ const [submitting, setSubmitting] = useState(false);
21
+ const [errors, setErrors] = useState({});
22
+ const [formError, setFormError] = useState(null);
23
+ const submit = async (values) => {
24
+ setSubmitting(true);
25
+ setErrors({});
26
+ setFormError(null);
27
+ try {
28
+ const response = await fetch(api(collection.slug), {
29
+ method: "PATCH",
30
+ headers: { "Content-Type": "application/json" },
31
+ body: JSON.stringify(values),
32
+ });
33
+ const json = (await response.json());
34
+ if (!response.ok) {
35
+ setErrors(json.errors ?? {});
36
+ setFormError(json.message ?? t("standalone.saveError"));
37
+ return;
38
+ }
39
+ if (json.item)
40
+ setItem(json.item);
41
+ toast.success(t("standalone.saved"));
42
+ }
43
+ catch {
44
+ setFormError(t("standalone.networkSave"));
45
+ }
46
+ finally {
47
+ setSubmitting(false);
48
+ }
49
+ };
50
+ return (_jsxs(Box, { className: "flex-col gap-6 p-4 sm:p-6 lg:p-8", children: [_jsxs(Box, { className: "flex-col gap-1", children: [_jsxs(Box, { className: "items-center gap-3", children: [_jsx(Text, { size: "title", className: "font-semibold text-gray-900", children: collection.label }), _jsx(Badge, { tone: "purple", children: t("standalone.badge") })] }), collection.description ? (_jsx(Text, { size: "caption", className: "text-gray-500", children: collection.description })) : null] }), _jsx(Box, { className: "max-w-2xl flex-col rounded-lg border border-gray-200 bg-white p-5 sm:p-6", children: _jsx(ItemForm, { collection: collection, item: item, submitting: submitting, errors: errors, formError: formError, relationOptions: relationOptions, onSubmit: submit, hideCancel: true }, collection.slug) })] }));
51
+ };
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from "react";
2
+ export type Column<T> = {
3
+ key: string;
4
+ header: string;
5
+ width?: string;
6
+ align?: "left" | "center" | "right";
7
+ render?: (row: T) => ReactNode;
8
+ };
9
+ export type DataTableProps<T> = {
10
+ columns: Column<T>[];
11
+ rows: T[];
12
+ rowKey: (row: T) => string | number;
13
+ empty?: string;
14
+ loading?: boolean;
15
+ caption?: string;
16
+ };
17
+ /**
18
+ * Real semantic `<table>` rendered inside a horizontally scrollable wrapper so
19
+ * it stays usable on small screens.
20
+ */
21
+ export declare const DataTable: <T>({ columns, rows, rowKey, empty, loading, caption, }: DataTableProps<T>) => import("react").JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box } from "../box.js";
3
+ import { Text } from "../text.js";
4
+ import { useI18n } from "./i18n.js";
5
+ const alignClass = {
6
+ left: "text-left",
7
+ center: "text-center",
8
+ right: "text-right",
9
+ };
10
+ const cellAlign = {
11
+ left: "justify-start",
12
+ center: "justify-center",
13
+ right: "justify-end",
14
+ };
15
+ /**
16
+ * Real semantic `<table>` rendered inside a horizontally scrollable wrapper so
17
+ * it stays usable on small screens.
18
+ */
19
+ export const DataTable = ({ columns, rows, rowKey, empty, loading = false, caption, }) => {
20
+ const { t } = useI18n();
21
+ const columnCount = columns.length;
22
+ return (_jsx(Box, { className: "w-full overflow-x-auto rounded-lg border border-gray-200 bg-white", children: _jsxs("table", { className: "w-full min-w-full border-collapse", children: [caption ? (_jsx("caption", { className: "px-4 py-2 text-left text-xs text-gray-400", children: caption })) : null, _jsx("thead", { className: "bg-gray-50", children: _jsx("tr", { className: "border-b border-gray-200", children: columns.map((column) => (_jsx("th", { scope: "col", style: column.width ? { width: column.width } : undefined, className: `max-w-[240px] whitespace-nowrap px-4 py-2.5 text-xs font-semibold uppercase tracking-wide text-gray-500 ${alignClass[column.align ?? "left"]}`, children: column.header }, column.key))) }) }), _jsx("tbody", { children: loading ? (_jsx("tr", { children: _jsx("td", { colSpan: columnCount, className: "px-4 py-10 text-center", children: _jsx(Text, { size: "caption", className: "text-gray-400", children: t("table.loading") }) }) })) : rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: columnCount, className: "px-4 py-10 text-center", children: _jsx(Text, { size: "caption", className: "text-gray-400", children: empty ?? t("table.empty") }) }) })) : (rows.map((row) => (_jsx("tr", { className: "border-b border-gray-100 transition-colors last:border-0 hover:bg-gray-50", children: columns.map((column) => (_jsx("td", { className: `max-w-[240px] px-4 py-3 align-middle ${alignClass[column.align ?? "left"]}`, children: _jsx(Box, { className: `min-w-0 max-w-full overflow-hidden ${cellAlign[column.align ?? "left"]}`, children: column.render ? (column.render(row)) : (_jsx(Text, { as: "span", size: "caption", className: "block truncate text-gray-700", children: String(row[column.key] ?? "") })) }) }, column.key))) }, rowKey(row))))) })] }) }));
23
+ };
@@ -0,0 +1,16 @@
1
+ import { type ReactNode } from "react";
2
+ export type ToastTone = "success" | "error" | "info";
3
+ type ToastContextValue = {
4
+ show: (message: string, tone?: ToastTone) => void;
5
+ success: (message: string) => void;
6
+ error: (message: string) => void;
7
+ };
8
+ export declare const useToast: () => ToastContextValue;
9
+ /**
10
+ * Toast notifications provider. Renders a fixed viewport (top-right on desktop,
11
+ * full-width on mobile) and exposes `useToast()`.
12
+ */
13
+ export declare const ToastProvider: ({ children }: {
14
+ children: ReactNode;
15
+ }) => import("react").JSX.Element;
16
+ export {};
@@ -0,0 +1,59 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { createContext, useCallback, useContext, useMemo, useRef, useState, } from "react";
4
+ import { Box } from "../box.js";
5
+ import { Text } from "../text.js";
6
+ import { useI18n } from "./i18n.js";
7
+ const ToastContext = createContext(null);
8
+ export const useToast = () => {
9
+ const context = useContext(ToastContext);
10
+ if (!context) {
11
+ throw new Error("useToast precisa estar dentro de <ToastProvider>.");
12
+ }
13
+ return context;
14
+ };
15
+ const toneStyles = {
16
+ success: {
17
+ container: "border-emerald-200 bg-white",
18
+ icon: "bg-emerald-100 text-emerald-700",
19
+ glyph: "✓",
20
+ },
21
+ error: {
22
+ container: "border-red-200 bg-white",
23
+ icon: "bg-red-100 text-red-700",
24
+ glyph: "!",
25
+ },
26
+ info: {
27
+ container: "border-gray-200 bg-white",
28
+ icon: "bg-gray-100 text-gray-700",
29
+ glyph: "i",
30
+ },
31
+ };
32
+ /**
33
+ * Toast notifications provider. Renders a fixed viewport (top-right on desktop,
34
+ * full-width on mobile) and exposes `useToast()`.
35
+ */
36
+ export const ToastProvider = ({ children }) => {
37
+ const { t } = useI18n();
38
+ const [toasts, setToasts] = useState([]);
39
+ const nextId = useRef(0);
40
+ const dismiss = useCallback((id) => {
41
+ setToasts((current) => current.filter((toast) => toast.id !== id));
42
+ }, []);
43
+ const show = useCallback((message, tone = "success") => {
44
+ const id = (nextId.current += 1);
45
+ setToasts((current) => [...current, { id, message, tone }]);
46
+ setTimeout(() => {
47
+ setToasts((current) => current.filter((toast) => toast.id !== id));
48
+ }, 4000);
49
+ }, []);
50
+ const value = useMemo(() => ({
51
+ show,
52
+ success: (message) => show(message, "success"),
53
+ error: (message) => show(message, "error"),
54
+ }), [show]);
55
+ return (_jsxs(ToastContext.Provider, { value: value, children: [children, _jsx(Box, { className: "pointer-events-none fixed inset-x-0 top-0 z-[60] flex-col items-center gap-2 p-4 sm:inset-x-auto sm:right-0 sm:items-end", children: toasts.map((toast) => {
56
+ const tone = toneStyles[toast.tone];
57
+ return (_jsxs(Box, { role: "status", "aria-live": "polite", className: `pointer-events-auto w-full max-w-sm items-start gap-3 rounded-lg border px-4 py-3 shadow-lg ${tone.container}`, children: [_jsx(Box, { className: `mt-0.5 h-6 w-6 shrink-0 items-center justify-center rounded-full text-xs font-bold ${tone.icon}`, children: _jsx("span", { "aria-hidden": true, children: tone.glyph }) }), _jsx(Text, { size: "caption", className: "flex-1 pt-1 text-gray-800", children: toast.message }), _jsx(Box, { as: "button", type: "button", "aria-label": t("common.closeNotification"), onClick: () => dismiss(toast.id), className: "shrink-0 rounded-md px-1.5 py-0.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-700", children: "\u00D7" })] }, toast.id));
58
+ }) })] }));
59
+ };
@@ -0,0 +1,6 @@
1
+ import type { UserSummary } from "../../auth/config.js";
2
+ export type UsersManagerProps = {
3
+ initial: UserSummary[];
4
+ currentUserId: number;
5
+ };
6
+ export declare const UsersManager: ({ initial, currentUserId }: UsersManagerProps) => import("react").JSX.Element;